microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.48k stars 393 forks source link

Silently disable DDS_LOADER_MIP_AUTOGEN/WIC_LOADER_MIP_AUTOGEN when format not supported #50

Closed walbourn closed 5 years ago

walbourn commented 5 years ago

The silent failure of the ID3D11DeviceContext::GenerateMips was a problem in DX11 because it left the mipchain uninitialized which rendered garbage. The DX11 DDSTextureLoader/WICTextureLoader explicitly checks the format for support via CheckFormatSupport and the D3D11_FORMAT_SUPPORT_MIP_AUTOGEN bit. If it is not supported it creates the texture without any mipchain so you get poor filtering, but at least not garbage.

While I think having ResourceUploadBatch::GenerateMips throw on unsupported formats is a better design decision, I could add logic to the DX12 DDSTextureLoader/WICTextureLoader to silently disable the DDS_/WIC_LOADER_MIP_AUTOGEN flag if it was going to result in an exception in ResoruceUploadBatch due to being an unsupported format so you get the old behavior. I’d probably add a ResourceUploadBatch::IsSupportedForAutoGen method which would be exposed as well.

walbourn commented 5 years ago

Fixed in this commit