Jump to content

  • Log In with Google      Sign In   
  • Create Account


Generate mipmaps for DDS cubemaps in DirectX 11

  • You cannot reply to this topic
5 replies to this topic

#1 ErnstH   Members   -  Reputation: 102

Like
0Likes
Like

Posted Yesterday, 02:47 AM

I'm loading my DDS cubemaps with this function:

 

HRESULT hr = CreateDDSTextureFromFile(mDevice, inPath, &Texture, &mShaderResourceView);

 

This works fine, except it has no mipmaps.

According to this page:

https://directxtk.codeplex.com/wikipage?title=DDSTextureLoader

I have to use the Ex version:

 

unsigned int bindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
unsigned int miscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;

HRESULT hr=CreateDDSTextureFromFileEx(mDevice, mContext, inPath, 0, D3D11_USAGE_DEFAULT, bindFlags, 0, miscFlags, false, &Texture, &mShaderResourceView);

 

However, no matter what I try I get a:

E_INVALIDARG One or more arguments are invalid

 

When stepping through the code I found out that the format is DXGI_FORMAT_BC1_UNORM (71) and this format is not supported for auto-gen mipmaps for my feature level and it finally fails at the CreateD3DResources function.

 

DirectX 9 has no problems generating mipmaps for this very same DDS file. Does this mean I have to convert the DDS file to another format, like uncompressed? Or is there a way to make it work in DirectX 11?

 

Any hints will be much appreciated!



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7866

Like
0Likes
Like

Posted Yesterday, 05:34 AM

Why not just include the mipmap levels in the DDS file itself?  That way you don't need to generate them.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 ErnstH   Members   -  Reputation: 102

Like
0Likes
Like

Posted Yesterday, 05:56 AM

I understand that this is the idea of DDS files.

 

We however need this functionality to stay compatible with the DirectX 9 version of our software.

 

Our users are expecting their projects (with their own DDS files) to render better in a DirectX 11 version. Not worse.



#4 Matias Goldberg   Crossbones+   -  Reputation: 3213

Like
1Likes
Like

Posted Yesterday, 09:28 AM

For what I can see it is failing because what DX9 did was to decompress, generate mips, compress again. Which is a lossy operation (theoretically it can be done as a lossless conversion by replacing binary data of mip 0 of the recompressed stream with the one from the original bc1, however the generated mips from bc1 sources should be of lower quality than generating mips from original sources).

Most likely D3D11 forces you to greater quality by first generating the mips from the source material, then compress. If the dds is already compressed and you want to pay the price, decompress it first.

Edited by Matias Goldberg, Yesterday, 09:29 AM.


#5 MJP   Moderators   -  Reputation: 11034

Like
2Likes
Like

Posted Yesterday, 12:25 PM

You can't use a BC1 texture as a render target, which means that you can't use the GPU to generate mipmaps. Generating mipmaps would require uncompressing the texture data (either on the CPU or GPU), generating the mips, and then optionally re-compressing at the end. The simple DDS loader that you're using doesn't include this functionality, since it's meant to be simple and bare-bones. 

One option for you would be to link to the full version of DirectXTex, and use it to perform the necessary conversions and operations. It has a full suite of texture functionality, and can certainly handle the process that I outlined above. If you prefer it also includes a command-line texture conversion utility, which has most of the same functionality that's available in the library. 

Another option would be to do the conversion yourself on the GPU. This actually fairly straightforward: just create an equivalent-sized uncompressed version of the texture, and then use a compute shader or a pixel shader on a full-screen quad to copy the texture data to your uncompressed texture. Then you can use the GPU to auto-generate the mips, and just render with the uncompressed version. Or if you would prefer to have the memory savings of the compressed version, you can re-compress at this point using DirectXTex or the compression library of your choice.



#6 ErnstH   Members   -  Reputation: 102

Like
0Likes
Like

Posted Today, 03:11 AM

Thank you for the info.

 

I think I'try the latter option first. I'll let you know how it goes.







PARTNERS