Description:
There is a bug in the D3D11 renderer implementation (render_context_d3d_impl.cpp) inside makeImageTexture that causes a hard crash or E_INVALIDARG failure from the GPU driver when attempting to dynamically inject image textures.
The function attempts to initialize a texture using the D3D11_RESOURCE_MISC_GENERATE_MIPS flag while simultaneously passing a single D3D11_SUBRESOURCE_DATA struct to CreateTexture2D.
D3D11_TEXTURE2D_DESC desc = {};
desc.MipLevels = 0;
desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
D3D11_SUBRESOURCE_DATA initialData = {};
initialData.pSysMem = pixels;
m_device->CreateTexture2D(&desc, &initialData, &texture);
The Issue:
According to Microsoft's D3D11 specifications, you cannot supply initial data to CreateTexture2D when using GENERATE_MIPS unless you provide an array of SUBRESOURCE_DATA covering every single mip level. Because the current implementation only supplies the base image at Mip Level 0, the driver reads out of bounds and crashes.
Proposed Fix:
The correct DirectX 11 staging pattern for mipmap generation is to:
- Call
CreateTexture2D with nullptr for the initial data.
- Use
UpdateSubresource on the device context to push the base image pixels specifically into Mip Level 0.
- Call
GenerateMips on the resulting ID3D11ShaderResourceView.
Description:
There is a bug in the D3D11 renderer implementation (
render_context_d3d_impl.cpp) insidemakeImageTexturethat causes a hard crash orE_INVALIDARGfailure from the GPU driver when attempting to dynamically inject image textures.The function attempts to initialize a texture using the
D3D11_RESOURCE_MISC_GENERATE_MIPSflag while simultaneously passing a singleD3D11_SUBRESOURCE_DATAstruct toCreateTexture2D.D3D11_TEXTURE2D_DESC desc = {}; desc.MipLevels = 0; desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; D3D11_SUBRESOURCE_DATA initialData = {}; initialData.pSysMem = pixels; m_device->CreateTexture2D(&desc, &initialData, &texture);The Issue:
According to Microsoft's D3D11 specifications, you cannot supply initial data to
CreateTexture2Dwhen usingGENERATE_MIPSunless you provide an array ofSUBRESOURCE_DATAcovering every single mip level. Because the current implementation only supplies the base image at Mip Level 0, the driver reads out of bounds and crashes.Proposed Fix:
The correct DirectX 11 staging pattern for mipmap generation is to:
CreateTexture2Dwithnullptrfor the initial data.UpdateSubresourceon the device context to push the base image pixels specifically into Mip Level 0.GenerateMipson the resultingID3D11ShaderResourceView.