Skip to content

GPU: Validate shader bytecode #12707

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 1 commit into from
Apr 22, 2025
Merged

Conversation

lmurray
Copy link
Contributor

@lmurray lmurray commented Apr 2, 2025

Multiple users have attempted to pass uncompiled shader code into SDL_CreateGPUShader() and SDL_CreateGPUComputePipeline() and have gotten confused by the resulting error messages (e.g. #12522). This is a bigger deal for the D3D12 backend than the others as parsing the shader code is done lazily in that backend so the errors appear unrelated to shader compilation.

This PR adds a small sanity check to all backends that detects obviously-invalid shader code by checking for a magic number in the blob and returns a more helpful error message if hit. It is not possible to detect MSL via this method so the existing error handling is kept for that format.

@lmurray lmurray force-pushed the gpu_validate_shaders branch from 3a38e99 to dde4b21 Compare April 2, 2025 09:10
@lmurray lmurray force-pushed the gpu_validate_shaders branch from dde4b21 to 7745f30 Compare April 2, 2025 10:32
@lmurray lmurray force-pushed the gpu_validate_shaders branch from 7745f30 to 48baf4b Compare April 2, 2025 10:47
@lmurray lmurray force-pushed the gpu_validate_shaders branch from 48baf4b to 0eee6ae Compare April 7, 2025 06:21
@slouken
Copy link
Collaborator

slouken commented Apr 7, 2025

@thatcosmonaut, @TheSpydog, does this look good to you?

@thatcosmonaut
Copy link
Collaborator

Looks good to me.

@slouken slouken merged commit 6e4ace3 into libsdl-org:main Apr 22, 2025
39 checks passed
@slouken slouken modified the milestones: 3.2.12, 3.4.0 Apr 22, 2025
@slouken
Copy link
Collaborator

slouken commented Apr 22, 2025

Merged, thanks!

@lmurray lmurray deleted the gpu_validate_shaders branch April 22, 2025 20:09
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.

4 participants