Skip to content

Naga shouldn't evaluate overrides unless they're used by the entry point #5885

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

Open
jimblandy opened this issue Jun 26, 2024 · 3 comments · May be fixed by #7652
Open

Naga shouldn't evaluate overrides unless they're used by the entry point #5885

jimblandy opened this issue Jun 26, 2024 · 3 comments · May be fixed by #7652
Assignees
Labels
area: naga back-end Outputs of naga shader conversion naga Shader Translator type: bug Something isn't working

Comments

@jimblandy
Copy link
Member

When generating code for a naga::Module, Naga currently evaluates every override-expression it can, regardless of whether that expression is statically used by the entry point(s) for which we are generating code. The WGSL committee's recent discussions clarified that errors should only be reported from override-expressions that are actually statically used.

@ErichDonGubler
Copy link
Member

Firefox downstream tracking: bug 1953930

@jimblandy
Copy link
Member Author

This is P1 for Firefox because it prevents this WebGPU Sample from running:

https://webgpu.github.io/webgpu-samples/?sample=samplerParameters

@andyleiserson andyleiserson moved this from Todo to In Progress in WebGPU for Firefox Apr 24, 2025
andyleiserson added a commit to andyleiserson/wgpu that referenced this issue 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.

This is working towards a fix for gfx-rs#5885.
andyleiserson added a commit to andyleiserson/wgpu that referenced this issue Apr 29, 2025
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.
teoxoy pushed a commit that referenced this issue Apr 30, 2025
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 #5885.

* Increase the limit in test_stack_size
@jimblandy
Copy link
Member Author

Yesterday @andyleiserson and I talked about this. #7652 follows an approach that I'd suggested, and while his implementation of the idea was reasonable, the strategy wasn't playing out in a very encouraging way. In particular, it seemed to require spot checks in a lot of different places; if you have to check something in five places, there's sure to be a sixth that you've forgotten, and a seventh you'll add by mistake.

Andy had originally suggested that compaction could be adapted to simply remove everything from the module not needed by the selected entry point, including functions. This would let us leave the existing override evaluation pretty much unchanged. At the time I was concerned about the performance impact of using compaction in this way, but after seeing the code in #7652, I'm coming around to the merits of an approach that allows backends to remain innocent, and be concerned simply with generating code for the module they're given.

So the strategy we're planning to pursue at the moment is:

  1. Adapt compaction to remove unused functions, rather than considering them used by definition. This will become the default behavior for all compaction. This will probably create a lot of turmoil in the snapshots, and the compactor's algorithm is a little delicate, so this will be handled in its own PR.

  2. Fix this bug by simply deleting all other entry points from the module, running compaction, and then letting overload resolution proceed as usual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion naga Shader Translator type: bug Something isn't working
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants