Skip to content

GPU D3D12 - Update to use typeless formats for depth buffer #12701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025

Conversation

gyxos-logan
Copy link
Contributor

@gyxos-logan gyxos-logan commented Apr 1, 2025

Description

For a depth buffer in D3D12 that is also going to be used in a texture sampler, the creation (on an Intel HD 5500 igpu) fails. e.g. SDL_GPUTextureCreateInfo type = TEXTURE_2D, format = D32_FLOAT, usage = DEPTH_STENCIL_TARGET | SAMPLER

The error messages are:

  • D32_FLOAT
    D3D12 ERROR: ID3D12Device::CreateShaderResourceView: The Format (0x29, R32_FLOAT) is invalid when creating a View; the
    Resource was already created with a fully qualified Format, which is not castable (0x28, D32_FLOAT).

  • D24_UNORM
    D3D12 ERROR: ID3D12Device::CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, when making a D3D view, the format name for the view can't be R24_UNORM_X8_TYPELESS.

Fix

I found this is because the texture format needs to be created as _TYPELESS, then the views (depth stencil view, shader resource view) should then be created as their respective types - e.g. texture = R32_TYPELESS, dsv = D32_FLOAT, srv = R32_FLOAT

Tested and working on:
NVidia RTX 3050 (D3D12 feature set 12_2)
Intel HD 5500 (D3D12 feature set 11_1)

Further changes/improvements?

Happy to any changes as needed.

@slouken slouken requested a review from thatcosmonaut April 1, 2025 20:54
@slouken slouken added this to the 3.2.12 milestone Apr 1, 2025
@thatcosmonaut
Copy link
Collaborator

This seems generally fine but I think we should only create the sampler views if the sampler bit is set.

@gyxos-logan
Copy link
Contributor Author

I've made a change to make it more clear when the SRV view is created and only use the typeless format when that is being created. Hopefully this is what you were meaning.

@slouken
Copy link
Collaborator

slouken commented Apr 23, 2025

@thatcosmonaut, does this look good?

@thatcosmonaut
Copy link
Collaborator

Yes!

@slouken slouken merged commit c81b622 into libsdl-org:main Apr 23, 2025
39 checks passed
@slouken
Copy link
Collaborator

slouken commented Apr 23, 2025

Merged, thanks!

slouken pushed a commit that referenced this pull request Apr 23, 2025
For a depth buffer in D3D12 that is also going to be used in a texture sampler, the creation (on an Intel HD 5500 igpu) fails. e.g. SDL_GPUTextureCreateInfo type = TEXTURE_2D, format = D32_FLOAT, usage = DEPTH_STENCIL_TARGET | SAMPLER

The error messages are:

D32_FLOAT
D3D12 ERROR: ID3D12Device::CreateShaderResourceView: The Format (0x29, R32_FLOAT) is invalid when creating a View; the
Resource was already created with a fully qualified Format, which is not castable (0x28, D32_FLOAT).

D24_UNORM
D3D12 ERROR: ID3D12Device::CreateShaderResourceView: For the resource format D24_UNORM_S8_UINT, when making a D3D view, the format name for the view can't be R24_UNORM_X8_TYPELESS.

I found this is because the texture format needs to be created as _TYPELESS, then the views (depth stencil view, shader resource view) should then be created as their respective types - e.g. texture = R32_TYPELESS, dsv = D32_FLOAT, srv = R32_FLOAT

Tested and working on:
NVidia RTX 3050 (D3D12 feature set 12_2)
Intel HD 5500 (D3D12 feature set 11_1)

(cherry picked from commit c81b622)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants