Skip to content

Title: D3D11 Access Violation / E_INVALIDARG when calling makeImageTexture (GENERATE_MIPS violation) #99

@unspokenlanguage

Description

@unspokenlanguage

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:

  1. Call CreateTexture2D with nullptr for the initial data.
  2. Use UpdateSubresource on the device context to push the base image pixels specifically into Mip Level 0.
  3. Call GenerateMips on the resulting ID3D11ShaderResourceView.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions