Skip to content
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

GPU: Integer Color Target Clears #11343

Open
rabbit-ecl opened this issue Oct 27, 2024 · 2 comments
Open

GPU: Integer Color Target Clears #11343

rabbit-ecl opened this issue Oct 27, 2024 · 2 comments
Assignees

Comments

@rabbit-ecl
Copy link
Contributor

rabbit-ecl commented Oct 27, 2024

Clearing of integer color targets is currently underspecified in SDL_GPU and has diverging behavior between backends.
D3D will take float and convert it to the closest representable integer for clearing, this means that some 32-bit integer values can't be represented!
Metal does the same, but uses double instead and thus should be able to represent all 32-bit integer values.
Vulkan will currently just bitcast the floats.
Clearing an R8_UINT with r=255.0 will result in integer 255 on Metal and D3D, but bitcasted garbage on Vulkan.

Somewhat relevant from WebGPU: gpuweb/gpuweb#1085 gpuweb/gpuweb#965
WebGPU chose to mandate full 32-bit clears and implementations have to emulate the out-of-range clears on D3D.

@TheSpydog
Copy link
Collaborator

Microsoft's docs recommend drawing a full-screen quad to clear integer render targets rather than using ClearRenderTargetView: https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-clearrendertargetview#remarks

We should document this workaround for GPU as well.

@rabbit-ecl
Copy link
Contributor Author

We should document this workaround for GPU as well.

As in user code or backend? Vulkan/Metal can support this for all values (32-bit ones anyway) but D3D would need a shader path for values >2**24. There's some precedence for this already in SDL_GPU's emulated blits.
I think we might want to replace SDL_FColor clear_color with a union or go the Metal way and use SDL_DColor (which currently doesn't exist).

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

No branches or pull requests

3 participants