Skip to content

naga: fix panic parsing SPIR-V subgroup reduce/scan/ballot ops - #9957

Merged
jimblandy merged 1 commit into
gfx-rs:trunkfrom
nazar-pc:naga-spirv-parsing-fix
Jul 30, 2026
Merged

naga: fix panic parsing SPIR-V subgroup reduce/scan/ballot ops#9957
jimblandy merged 1 commit into
gfx-rs:trunkfrom
nazar-pc:naga-spirv-parsing-fix

Conversation

@nazar-pc

@nazar-pc nazar-pc commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Connections

Fixes #8389.

Description

Disclaimer: this PR was mostly done using a clanker and I do not fully understand the code changes, but I have reasonably high confidence in their correctness.

Several OpGroupNonUniform* handlers in the SPIR-V frontend called emitter.finish() before reading their argument operand via get_expr_handle!. When the argument's defining expression came from a control-flow body that had already closed (e.g. a value computed inside a loop and used after it), get_expr_handle needs to spill the value through a temporary local variable, which requires calling emitter.finish() itself. Since the emitter had already been finished, this second call unwrapped a None and panicked.

Move the emitter.finish() call to after the argument expression handle(s) are obtained for OpGroupNonUniformBallot, the arithmetic/logical reduce-scan ops, the broadcast/shuffle ops, and OpGroupNonUniformQuadSwap.

Testing

Existing CI tests pass, new regression test was added and original SPIR-V file from #8389 no longer crashes naga CLI. The project where I originally hit this issue also passes all tests with this fix applied (Linux, AMDGPU, Vulkan).

Checklist

  • I self-reviewed this PR.
  • I fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

@jimblandy jimblandy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks fine, but please trim the snapshot output languages.

Comment thread naga/tests/in/spv/subgroup-reduce-issue-8389.toml
@nazar-pc
nazar-pc force-pushed the naga-spirv-parsing-fix branch from 05cfd9b to 604bb60 Compare July 29, 2026 15:59
@nazar-pc
nazar-pc requested a review from jimblandy July 29, 2026 15:59

@jimblandy jimblandy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@jimblandy
jimblandy merged commit fb1c777 into gfx-rs:trunk Jul 30, 2026
60 checks passed
@nazar-pc
nazar-pc deleted the naga-spirv-parsing-fix branch July 30, 2026 01:02
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 SPIR-V panic in proc/emitter.rs:26

2 participants