Skip to content

rdna2spirv: a POPS shader without a branch begins the interlock too (SHADER-350) - #2020

Closed
Dom-in wants to merge 1 commit into
ItsNotRexed:mainfrom
Dom-in:shader-350-pops-begin
Closed

Dom-in wants to merge 1 commit into
ItsNotRexed:mainfrom
Dom-in:shader-350-pops-begin

Conversation

@Dom-in

@Dom-in Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed on #1902: #1902 (comment)

What and why

A pixel shader that reads src_pops_exiting_wave_id (POPS, primitive-ordered pixel shading) is translated with fragment-shader interlock around the whole shader:

  • PixelInterlockOrderedEXT;
  • OpBeginInvocationInterlockEXT once, at the end of the entry block;
  • OpEndInvocationInterlockEXT once, before the return.

The Begin was appended only inside if gen.blocks:, the path that lays out branch blocks, while the End is added for every POPS shader. So a POPS shader without a branch got an End with no Begin, which is invalid for the interlock. 10 of the game's pixel shaders need ROVs (docs/d3d12_vulkan.md question 10).

The change

In assemble, the straight-line path now appends OpBeginInvocationInterlockEXT at the same point: the end of the entry prologue, before the body. One elif pops: branch; the branched path is unchanged.

Tests (tests/test_pops_interlock.py, new)

  • Straight-line and branched POPS shaders each get exactly [Begin, End], Begin after the entry label and before End, with FragmentShaderPixelInterlockEXT and PixelInterlockOrderedEXT, and pass spirv-val. Before the fix, the straight-line case gave ['End'].
  • A shader without POPS gets neither instruction nor the capability.

tests/test_translate.py + tests/test_shader_checks.py: 560 passed, 2 skipped.

Not GPU-run: AMD's Windows driver (RX 9070) doesn't expose VK_EXT_fragment_shader_interlock. A fixture run needs a GPU with fragmentShaderPixelInterlock (NVIDIA, Intel).

Disclosure: written with an AI assistant (Claude Code). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

…SHADER-350)

A pixel shader that reads src_pops_exiting_wave_id is ordered by fragment-
shader interlock around the whole shader: OpBeginInvocationInterlockEXT at
the end of the entry block, OpEndInvocationInterlockEXT before the return.
The Begin was appended only on the path that lays out branch blocks, so a
straight-line POPS shader got the End without a Begin, which is invalid for
the interlock. The straight-line path now appends it in the same place.

tests/test_pops_interlock.py: straight-line and branched POPS shaders get
exactly Begin then End, after the entry label, and pass spirv-val; a shader
without POPS gets neither. The straight-line case gave ['End'] before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@YaBulochka YaBulochka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the diff and ran the new tests on a clean worktree of 6a3778d6: python3 -m pytest -q tests/test_pops_interlock.py -> 3 passed. The fix is the right shape: the straight-line path now appends OpBeginInvocationInterlockEXT to the same prologue list (fn) that the if gen.blocks path already used, so both shapes put Begin at the end of the entry block and End before the return, and a shader without POPS still gets neither.

One small thing about the test, not the fix: the comment on the entry-block assertion says "before the first instruction that reads or writes anything the shader stores", but the assertion only compares the positions of Begin and End. On the straight-line fixture the store is the OpStore/export after the Begin anyway, so the property you describe holds; if you want the comment to be literal, assert that every OpStore / OpImageWrite / export call sits after the Begin index.

No GPU run from me: this is a translation-shape change and the new tests are CPU-side; a POPS shader on hardware would need a fixture that the suite does not have yet.

@borislisandro

borislisandro commented Nov 22, 2026 •

Copy link
Copy Markdown

Tested 6a3778d6 (CPU only): pass. pytest tests/test_pops_interlock.py tests/test_rdna2spirv_cli.py: 18 passed, 22 subtests.

Cross-check of the three PRs for SHADER-350 (#2012, #2017, #2020), all CPU, Linux x86_64, Python 3.x: each change makes a straight-line POPS shader begin its interlock at the end of the entry block, and the three translator changes are equivalent for it. I ran #2020's test_pops_interlock.py (3 cases: Begin/End order and spirv-val) against the translator of #2012 and of #2017 and both pass. #2017's parametrised test_pops_interlock_begins_and_ends_once (straight-line and branching, one Begin and one End, Begin first, spirv-val) passes on its own branch. Only one of the three needs to merge.

This adds a 5-line elif pops: branch (like #2017's, but without the design.md row update). Its test file is a new file where #2017 adds to tests/test_translate.py; either is fine.

Differential check: I translated three hand-written shaders (a straight-line POPS shader, a POPS shader with a branch, a non-POPS shader with a branch) on main and on the branches of #2012, #2017 and #2020 and compared the full SPIR-V text. The branching POPS and the non-POPS output is byte-identical to main on all three; the straight-line POPS output differs from main and is byte-identical across the three PRs. So they are interchangeable for these shapes.

AI-assisted review.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #2017: @fearkov claimed this finding at 15:20 (#1902 (comment)), before it had an ID and before my claim, and #2017 is the same one-line change. @borislisandro ran this PR's tests/test_pops_interlock.py against #2017's translator and it passes there. @fearkov, feel free to take that file into #2017 if the straight-line + branched + no-POPS cases and the spirv-val check are useful.

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