-1

I'm using the 11.2 compatible build of SharpDX and have rendering going up well so far, however i'm starting to test things out with large textures and would need mipmaping to avoid the ugly artifacts of higher than screen resolution textures.

From what i understand if i want the full set of mipmap levels i need to set MipLevels to 0 in my texture creation, however, changing the MipLevels parameter from 1 (what it was and works) to 0 (my goal) causes an exception with invalid parameter on the texture instantiation line.

The error has to be at that point or before (crashed before it reaches any rendering and at the step of declaration).

Here's how i'm declaring my texture state :

new SharpDX.Direct3D11.Texture2DDescription()
            {
                Width = bitmapSource.Size.Width,
                Height = bitmapSource.Size.Height,
                ArraySize = 1,
                BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource,
                Usage = SharpDX.Direct3D11.ResourceUsage.Immutable,
                CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
                MipLevels = 1, // This works, but if i change it to 0, i get an argument invalid exception
                OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
            }
Ronan Thibaudau
  • 3,413
  • 3
  • 29
  • 78
  • If you follow http://sharpdx.com/forum/4-general/1774-how-to-debug-a-sharpdxexception, you should be able to diagnostic this yourself – xoofx Jan 04 '14 at 02:43
  • I just followed those steps (turning on native debugging & creating the device with the debug flag). I still get the same result, a SharpDXException stating i have an incorrect parameter. – Ronan Thibaudau Jan 04 '14 at 03:09
  • And i'm not getting anything in the output window either even after following those steps (i'm using VS 2013 if that matters) – Ronan Thibaudau Jan 04 '14 at 03:15
  • Ok not sure what happened but native debugging got unchecked again, re checked it but it's complaining about missing nvumdshimx.dll so i assume i'm missing something to be able to debug this correctly? – Ronan Thibaudau Jan 04 '14 at 03:17
  • Managed to skip over the missing pdb by going in disasembly view & skipping that line (it was before the error) however all i got from the additional output was useless : D3D11 ERROR: ID3D11Device::CreateTexture2D: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #104: CREATETEXTURE2D_INVALIDARG_RETURN] – Ronan Thibaudau Jan 04 '14 at 03:22

1 Answers1

1

Since the texture is immutable and being created with a full MIP chain you need to provide initial data for every mip in the chain. I assume you are only providing data for mip 0?

EDIT:

A similar question is asked here: http://www.gamedev.net/topic/605521-mipmap-dx11/

You have a few different options:

1) Generate the mips offline (perhaps store your textures in a DDS, which supports mips) and provide an array of DataRectangles, one for each mip.

2) Remove the Immutable usage flag, use Default instead, don't provide any initial data but instead use something like Map or UpdateSubresource to fill in Mip 0 after it has been created. Once mip 0 is populated, you can call GenerateMips on the DeviceContext so long as the texture was created with the D3D11_RESOURCE_MISC_GENERATE_MIPS MiscFlag, this will populate all other mips with the correct downsampled data.

3) A third approach would be to do something similar to Option 2, but instead you could provide a dummy set of data for all but the first mip and thus avoid the need to call Map or UpdateSubresource. However you will still have to call GenerateMips on the DeviceContext.

Adam Miles
  • 3,504
  • 17
  • 15
  • I couldn't find much by googling on DX11 mipmaps but i assume by your answer getting mipmaps requirs more than setting mipmap level. Yes i'm only loading a plain regular texture, what is the appropriate way to get it mipmapped when starting from a flat texture? (i don't want to update it at runtime so i'd like to stick to immutable) – Ronan Thibaudau Jan 04 '14 at 16:08
  • I've added some extra information in an edit to the original answer, let me know if you need any more. – Adam Miles Jan 04 '14 at 22:51
  • Yes that was helpful thanks. Is it possible to "convert" a texture to immutable or create a texture from a texture? (could i use solution 2 and then somehow get rid of that texture in favor of an immutable one with mips pregenerated?). Thanks! – Ronan Thibaudau Jan 05 '14 at 02:25
  • I wouldn't get too hung up on whether it's Immutable or not. Although it's always good practice to use the most restrictive usage type you can, I've not seen anything to suggest Immutable will be any worse/slower than Default. – Adam Miles Jan 05 '14 at 19:55
  • You're right i shouldn't really worry about this, if it matters i guess i'll just generate those offline. Is there an API to work with DDS files (so i could generate those things as batch), ideally from .net, or no such thing? – Ronan Thibaudau Jan 05 '14 at 23:34
  • DirectXTex (C++) is an open source Microsoft toolkit for dealing with textures as it relates to DirectX. It includes a tool called TexConv that can take textures in many formats, generate the mips and then write them out as a DDS file (with mips). I don't believe it has a .Net wrapper right now (it's possible someone else has written one). Could your tool/pipeline for textures simply invoke a binary version of TexConv? http://directxtex.codeplex.com/wikipage?title=Texconv&referringTitle=Documentation – Adam Miles Jan 05 '14 at 23:59
  • Aye sounds like a good compromise, that or writing a simple wrapper around it, thanks for pointing it out to me, i'll look into this and probably switch over to DDS. Thanks! – Ronan Thibaudau Jan 06 '14 at 00:03