Question

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),
            }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top