Skip to content

[naga] Write only the current entrypoint #7626

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 5 commits into from
Apr 30, 2025

Conversation

andyleiserson
Copy link
Contributor

@andyleiserson andyleiserson commented Apr 24, 2025

Changes the MSL and HLSL backends to support writing only a single entry point, and uses them that way in wgpu-hal. (The GLSL and SPIR-V backends already provide an entry point selector.)

This is working towards a fix for #5885, but this change doesn't alter override processing or validation, so we will still reject shaders for missing overrides whether or not they are used.

Testing
Both the write-one-entrypoint and write-all-entrypoints cases are exercised either by existing or changed code. Existing tests cover the change in behavior, in that the tests still work, even when no longer writing all entrypoints to the output. Additional partial-output test cases will be added with the complete fix for #5885.

Squash or Rebase? Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • Added a changelog entry.

@andyleiserson andyleiserson requested a review from a team as a code owner April 24, 2025 18:23
@cwfitzgerald
Copy link
Member

+1 this for a different reason - it's less code to hand to the driver (for it to just throw out) and less for people looking in shader debuggers to wade through.

@teoxoy teoxoy self-assigned this Apr 25, 2025
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entry points are uniquely identified by (name, stage), that's what the SPIR-V & GLSL backends use as well, I think the MSL & HLSL backends should follow that model to ensure only a single entry point is written.

@andyleiserson
Copy link
Contributor Author

@teoxoy Currently I have entry_point: Option<String> for Metal and HLSL to provide backwards compatibility with the current behavior. Thoughts on how important backwards compatibility is? If adding the stage I could have shader_stage and entry_point as separate optional values, separate non-optional values, or as a single Option<(ShaderStage, String)> which seems cleaner than two separate options but would be inconsistent with GLSL and SPIR-V.

@teoxoy
Copy link
Member

teoxoy commented Apr 28, 2025

I think we should go with Option<(ShaderStage, String)> (or something like Option<EntryPointIdent> where EntryPointIdent is a struct that contains the name and stage). SPIR-V already uses this model by making its PipelineOptions optional in write_vec. GLSL is the only target that doesn't support multiple entry points per file and requires passing the name and stage.

Changes the MSL and HLSL backends to support writing only a single entry
point, and uses them that way in wgpu-hal.

This is working towards a fix for gfx-rs#5885.
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@teoxoy
Copy link
Member

teoxoy commented Apr 29, 2025

Looks like the msl test needs a bump in stack space?

@andyleiserson
Copy link
Contributor Author

Looks like the msl test needs a bump in stack space?

Yes, I assume this is because of the increase in the size of back::msl::Error, because the new EntryPointNotFound variant has two members. I also had to increase the target in test_error_size from 32 to 40.

Although in the case of test_stack_size, I think it was already on the edge of failing -- it has been failing for me locally since the rust version was set to 1.84. But only rust 1.84 seems to have that issue, so I figured I could live with the local failures until we bump the rust version again.

@teoxoy teoxoy merged commit 850c3d4 into gfx-rs:trunk Apr 30, 2025
37 checks passed
@andyleiserson andyleiserson deleted the entrypoints branch April 30, 2025 17:12
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