Skip to content

Proper loops - #9329

Closed
JMS55 wants to merge 2 commits into
gfx-rs:trunkfrom
JMS55:proper-loops
Closed

Proper loops#9329
JMS55 wants to merge 2 commits into
gfx-rs:trunkfrom
JMS55:proper-loops

Conversation

@JMS55

@JMS55 JMS55 commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

Connections
Closes #6521 and #4499

Description
Naga used to translate all for/while loops into while(true) loops, which hurt performance. This PR fixes that.

Disclaimer: Heavily LLM generated. I've done my best to review line-by-line, and I'm mostly confident in everything except the code that actually writes for/while loops for each backend.

Testing
Ran all existing naga tests, and eyeballed the generated shader diffs.

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.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Comment thread naga/src/back/mod.rs Outdated
@inner-daemons
inner-daemons self-requested a review April 1, 2026 15:49
@inner-daemons inner-daemons self-assigned this Apr 1, 2026
@JMS55

JMS55 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

I tested in a Bevy scene on Windows+Nvidia. Was not any faster.

Would love if more people could test on other platforms and shaders.

@mate-h

mate-h commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

GPU profiling data for mac reveals no conclusive results

Scenario main for-loops-test
1 frame many lights 15.95 15.60
1 frame many lights 16.08 15.58
1 frame many lights 16.17 15.83
1 frame many lights 15.89 15.84
1 frame many lights 15.84 15.85
5 frames many lights 79.43 78.63
5 frames many lights 79.00 79.00
5 frames many lights 79.17 82.40
5 frames many lights 79.33 81.66
5 frames many lights 79.15 79.07
SSR linear steps 128, bisection steps 32 48.92 48.98

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.

[naga]Naga does not generate for loops

6 participants