Repository navigation
Conversation
…R-POPS-COLLISION-SEED) A pixel shader with an ordered section (POPS) reads the hardware's collision word, which sits in the SGPR after the user SGPRs and the primitive mask: collision wave id in bits 0-9, this wave's id in bits 16-25, overlap in bit 31. The program waits until wave_id + ~collision_id is below src_pops_exiting_wave_id + ~collision_id (unsigned). The translator orders the section with fragment-shader interlock and reads the exiting id as 0, and the word was whatever the push constants held at that dword, usually 0. With wave id == collision id the test is 0xffffffff < 0xffffffff, never true, so a wave that reached the loop ran it until the loop guard (65,536 rounds). The overlap test before the loop skips it whenever a lane is on in EXEC, so it is a wave (a host subgroup) with EXEC all off there; on 32-wide subgroups that is either half of a wave64 program whose lanes are all off. The SGPR is now the source of the program's wave-id extract (s_bfe_u32 with field 0x000a0010) when the program reads that SGPR's entry value (shader_meta's user_sgpr_reads), and it is set at entry to 0x00010000 (no overlap, wave id 1, collision id 0): the loop leaves after one round. A program without that extract keeps the old behaviour. - tools/rdna2spirv.py: pops_collision_sgpr and the entry store. - tests/semantic/test_pops_collision_seed.py: subgroups of 64 and 32 lanes, with and without the seed, and the SGPR search; the GPU fixture runtime/test/shaders/ps_pops_wait_loop.asm (check.py, run_gpu_tests.py) and its llvm-mc listing. - tests/semantic/spirv_wave_interp.py: the interlock instructions run as no-ops (a run has no other primitive). - runtime/test/vk_harness.cpp: a fragment shader that needs pixel interlock on a device without it is unsupported (77), as for barycentrics. - docs/design.md, docs/d3d12_vulkan.md: the POPS rows. GPU: on an RTX 4070 SUPER the fixture gives 4096 of 4096 pixels as expected; with the seed taken out every pixel's round count is 0x00010000. Idea from Marvisak/VIctory 7ac1f54, written anew. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
|
Verified on main a73a57e (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly. python -m unittest discover -s tests/semantic -p test_pops_collision_seed.py: 12 tests OK with this PR; the same file against main's translator: 1 failure and 16 errors, so it fails on main and passes with the change. compileall clean. Not run: the whole semantic suite and the translated / spirv-val counts over a corpus (no game data here). AI-assisted: yes (Claude Code) |
|
Tested
The new AI-assisted (Claude Code). No game data. |
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 / GPU check of #2174 (SHADER-POPS-COLLISION-SEED). A translator rule, a GPU fixture and a harness capability gate; all three run here.
Tested head 15350f6da merged onto main bdbc7e923 as merge af475333f (clean, no conflicts).
Environment: Apple M3 Pro, arm64, macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, CPython 3.15.2, llvm-mc 23.1.5, SPIRV-Tools v2026.4, MoltenVK 1.4.0, KosmicKrisp = Mesa 26.3.0.
The fixture runs, and it needed the harness change to be a fair test
-
ps_pops_wait_loopon the merge with the rebuiltvk_harness, MoltenVK:PASS 4096/4096 pixels exact-x = 1round,y = 0, and the 1.0 outputs, exactly the.asmheader's derivation from the seeded0x00010000. -
KosmicKrisp:
SKIP (unsupported: ... uses fragment-shader interlock and the device has no fragmentShaderPixelInterlock). That is the new gate atruntime/test/vk_harness.cpp:329-341doing its job. Before I rebuilt the harness (the checked-invk_harnessin my build dir predated this PR), the same fixture on the same driver failed atvkCreateGraphicsPipelineswithVK_ERROR_INVALID_SHADER_NVafter SPIRV-Cross emittedUnknown intrinsic end_invocation_interlockin the MSL. Those are the two sides of the gate: without it, a device that does not expose the feature fails the suite instead of skipping, and the failure message blames the shader. -
Full suite on the merge, MoltenVK:
279 shaders: 278 translated, 278 pass spirv-val,196 / 3 / 70of 269. The three failures are main's on this driver (cs_fma_fused,cs_imgatomic_ext,ps_ssharp); the one added pass over the baseline (195 / 3 / 70of 268) is the new fixture.ps_ij_computedis still the expected refusal under the f16 fallback in this tree (#2239), and it is in the 70 skips. -
Semantic:
tests/semantic/test_pops_collision_seed.py12 tests OK; whole suite501 files, 6379 tests, 0 files failed(main 500 / 6367, so one file and twelve cases). -
NC 1 (translator reverted to main, fixture and tests kept): the new semantic file reports
FAILED (failures=9, errors=4)and the GPU run becomesFAIL ps_pops_wait_loop 4096/4096 mismatches; first at (0,0): got ['0x10000', ...], want ['0x1', ...]- the loop runs to its guard when the collision word arrives as 0. -
NC 2 (keep everything, set
POPS_COLLISION_SEED = 0, i.e. the old push-constant behaviour): 8 semantic failures and the same0x10000GPU mismatch. Both the seed's value and its placement are pinned.
Assessment of the rule
- The wait-loop condition is handled correctly: with
src_pops_exiting_wave_idread as 0 and the seed's collision id 0, the loop'ss5 = wave_id + ~collision_idis 1 + 0xffffffff = 0, which is below0 + 0xffffffff, so a wave that enters the loop leaves after one round. A word with wave id == collision id (0) gives 0xffffffff < 0xffffffff, false, and the loop runs to the guard - which is exactly what NC 1/NC 2 measure, so the choice of 1 rather than 0 is load-bearing and not an accident. - The seeding is emitted after the user-data copy (
tools/rdna2spirv.py:16844-16850), so it wins over push constants, and it only runs when the shader also readssrc_pops_exiting_wave_id(uses_pops) and ans_bfe_u32with field0x000A0010reads an entry SGPR (pops_collision_sgpr,:379-394). Both call sites run aftershader_meta.collect(:18833,:18904), souser_sgpr_readsis populated when this is decided.
Nits, not defects
- The detector recognises one extraction shape only:
s_bfe_u32 sX, sY, 0x000A0010on a register whose entry value is read. A compiler that gets the wave id withs_and/s_lshr, or that reads the collision word through a copy, is not seeded and keeps the old behaviour (loop to the guard). Over the corpus that may be empty; I cannot count it without a game copy, so the row should say which shape is recognised and that anything else still runs the loop, so a later reader does not assume the seed is universal. - Seeding writes
0x00010000over whatever the push constants held at that SGPR. The collision word is hardware-supplied on the console, so that is right, but if a title's user-SGPR count is below the translator's 16 the slot is also inside the copied user-data range: a shader that uses that dword as ordinary user data would now see0x00010000. The field match plususes_popsmakes a false positive unlikely; a comment saying so would be cheaper than rediscovering it. - The wave-id field is now 1, not 0 (the old runtime put 0 in the whole word). Anything that reads "this wave's id" as an identity gets 1 for every wave. The ordering itself comes from the interlock, so this is fine, but it is a visible change and the row should name it.
Not run: the full corpus (needs a game copy), native RDNA2 hardware, and the D3D12 path (ROVsSupported comes from the same feature bit; that is Windows-only and unaffected by this PR).
python -I scripts/check_no_game_data.py on all ten changed files: clean.
No game files. AI-assisted.
Claimed in the coordination issue as: SHADER-POPS-COLLISION-SEED
What and why
A pixel shader with an ordered section (POPS) reads the hardware's collision word from the SGPR after its user SGPRs
and the primitive mask. The word holds the collision wave id in bits 0-9, this wave's id in bits 16-25 and the
overlap flag in bit 31. The program waits until
wave_id + ~collision_idis belowsrc_pops_exiting_wave_id + ~collision_id(unsigned). The translator orders the section with fragment-shaderinterlock and reads the exiting id as 0, so it relied on that word holding no collision. The word was whatever the
push constants held at that dword, usually 0. With wave id == collision id the test becomes
0xffffffff < 0xffffffff, which is never true, so a wave that reached the wait loop ran it until the loop guard(65,536 rounds).
The overlap test before the loop skips it whenever a lane is on in EXEC. The case that spins is therefore a host
subgroup that reaches the branch with EXEC all off. On 32-wide subgroups that is either half of a wave64 program whose
lanes in that half are all off.
The translator now finds the SGPR as the source of the program's wave-id extract (
s_bfe_u32with field0x000a0010), when the program reads that SGPR's entry value (shader_meta'suser_sgpr_reads). It sets that SGPRat entry to
0x00010000(no overlap, wave id 1, collision id 0), and the loop then leaves after one round. A programwithout that extract is translated as before.
tools/rdna2spirv.py:pops_collision_sgprand the entry store.tests/semantic/test_pops_collision_seed.py: whole subgroups of 64 and 32 lanes, with and without the seed (EXECall on, a lane on in each half, all off, the low half off), plus the SGPR search.
runtime/test/shaders/ps_pops_wait_loop.asm, run by check.py and run_gpu_tests.py, with its llvm-mclisting for the branch encodings.
tests/semantic/spirv_wave_interp.py: the interlock instructions run as no-ops, since one run has no otherprimitive.
runtime/test/vk_harness.cpp: on a device without pixel interlock, a fragment shader that needs it is reported asunsupported (77), as is already done for barycentrics.
docs/design.mdanddocs/d3d12_vulkan.md: the POPS rows.Idea from Marvisak/VIctory 7ac1f54, written anew.
Tested
tests/semantic/test_pops_collision_seed.py: 12 passed (8 subtests).scripts/run_semantic_tests.py tests/semantic -j 4): 493 files, 6327 tests, 0 files failed.tests/test_translate.pyplus the related semantic files: 795 passed and 2 failed. Both failures arecs_dpp_cmp.asm, which llvm-mc 23.1.6 does not assemble for gfx1013 ("dpp variant of this instruction is notsupported"). That fixture fails at the llvm-mc step, before the translator runs, so it fails the same way without this change.
tests/semantic/regen_fixtures.py --check: clean.(
test_every_tool_the_jobs_read_triggers_the_workflow), nothing new.spirv-val before and after: 100/100 both times. The 90 others are byte-identical. The 10 POPS shaders differ only
in the entry store of the seed.
ps_pops_wait_loopthrough check.py's pixel test gives 4096 of 4096 pixels as expected. With the seed takenout of the translator, every pixel's round count is
0x00010000(the loop guard).GPUs tested: NVIDIA GeForce RTX 4070 SUPER, Windows 11 (Vulkan)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf