Skip to content

Fix local_invocation_id and local_invocation_index handling#9099

Merged
Wumpf merged 4 commits intogfx-rs:trunkfrom
inner-daemons:8820-fix
Mar 15, 2026
Merged

Fix local_invocation_id and local_invocation_index handling#9099
Wumpf merged 4 commits intogfx-rs:trunkfrom
inner-daemons:8820-fix

Conversation

@inner-daemons
Copy link
Collaborator

@inner-daemons inner-daemons commented Feb 23, 2026

Connections
Closes #8820

This is blocking #8752 and #8739, which I would rather not keep having to maintain. So speed would be appreciated here.

Description
Solves issue with builtins possibly being written multiple times in HLSL and MSL, and with naming conflicts when users name variables __local_invocation_id or __local_invocation_index.

Testing
Snapshots

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.

@inner-daemons inner-daemons marked this pull request as ready for review February 23, 2026 18:36
@inner-daemons inner-daemons mentioned this pull request Feb 23, 2026
6 tasks
@jimblandy jimblandy self-assigned this Feb 25, 2026
@inner-daemons inner-daemons requested a review from Wumpf March 1, 2026 21:08
@inner-daemons inner-daemons mentioned this pull request Mar 7, 2026
6 tasks
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

some hygenie/maintainability things that need addressing, otherwise lgtm

ep_input.arg_name
"{}.{} / WaveGetLaneCount()",
ep_input.arg_name,
ep_input.local_invocation_index_name.as_ref().unwrap()
Copy link
Member

Choose a reason for hiding this comment

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

don't like the unwrap here at all. Yes the invariant of (waaaay) above change is right now that if there's a subgroupid, then invocation index name will be Some but it's too easy to violate that via future iterations.

Why not just always set the invocation index name and overwrite only if a user specified one is there? The question of whether we expect it to be in use is a separate one then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm gonna add a comment. The problem there is that we always get this unused variable, even where it doesn't make sense (like in vertex shaders).

self.write_workgroup_variables_initialization(
func_ctx,
module,
local_invocation_id_name.unwrap(),
Copy link
Member

Choose a reason for hiding this comment

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

as above, it's too hard to reason through these unwraps outside of this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same comment as above.

@inner-daemons inner-daemons requested a review from Wumpf March 9, 2026 19:05
@inner-daemons
Copy link
Collaborator Author

@Wumpf Can you take another look

Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

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

Approving for the same reasons as the msl writer PR #8739 (review) which uses this code.

I've read through the code, ported bevy and a series of examples to use it, and it is working as expected.

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

still very much unhappy about the unwrapping :/. Testing looks much nicer
But lgtm overall, so let's ship this.

Fixed changelog entry a bit though.

@Wumpf Wumpf enabled auto-merge (squash) March 15, 2026 19:35
@Wumpf
Copy link
Member

Wumpf commented Mar 15, 2026

@ChristopherBiscardi thank you so much for giving those changes a spin here and on the other PRs!

@Wumpf Wumpf merged commit 96b7872 into gfx-rs:trunk Mar 15, 2026
59 checks passed
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 HLSL writer treats thread index/thread id weirdly

4 participants