rdna2spirv: seed the POPS collision word so the wait loop ends (SHADER-POPS-COLLISION-SEED) #2174
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2174"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-26T02:02:46Z.
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
Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T10:20:02Z.
Verified on main
a73a57e1(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)
Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-26T13:48:56Z.
Tested
15350f6daon an Apple M3 (macOS 26.5.1). I ran the fullscripts/run_gpu_tests.pyin auto mode againstmaina73a57e13, with test programs built from this branch (it changesvk_harness.cpp).mainLEONIDA_W64_EMULATE=1The new
ps_pops_wait_looppasses on MoltenVK, native and emulated (4096/4096 pixels exact), so the seeded collision word ends the wait loop there. KosmicKrisp skips it, because the device has no fragment-shader interlock. No new failure. The ones left are the same on both sides:cs_fma_fused(#1724),ps_ssharp(#1774) andcs_imgatomic_ext(#1518) on MoltenVK; KosmicKrisp's(NAN)-constant fixtures (#2229) andcs_imgatomic_extthere.AI-assisted (Claude Code). No game data.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T19:31:23Z.
Review: COMMENTED
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
15350f6damerged ontomainbdbc7e923as mergeaf475333f(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-mc23.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
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.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
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.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.Not run: the full corpus (needs a game copy), native RDNA2 hardware, and the D3D12 path (
ROVsSupportedcomes from the same feature bit; that is Windows-only and unaffected by this PR).python -I scripts/check_no_game_data.pyon all ten changed files: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T09:14:42Z.
#2174 | head
15350f6da6281cc6af4b9698b533d925431417f8|python3 -m unittest discover -s tests/semantic -p test_pops_collision_seed.py -v,python -I scripts/run_gpu_tests.py --filter ps_pops_wait_loop --require-pass --build <harness-dir> --assembler python --work <scratch>| red: 12 tests, 9 assertion failures, 5 errors, GPU 4,096/4,096 pixels mismatched | green: 12 passed, GPU 4,096/4,096 pixels matched | Red → green, GPU confirmedThe baseline generated a module that validated but produced 4,096 mismatched pixels. The merged tree matched all 4,096 pixels. Failure and error counts include subtest events. The merged fixture also passed a separate SPIRV-Tools 2026.1 check with
spirv-val --target-env vulkan1.2.Pinned main
4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4 for CPU tests. Windows 11 Pro, Python 3.12.10, RTX 5070 Ti (NVIDIA 610.74) for the filtered Vulkan run. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:32:17Z.
#2174 | head
15350f6da6281cc6af4b9698b533d925431417f8(merged cleanly ontomaind48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython3.12.10, MSVC19.44.35228(/W4 /permissive- /utf-8),spirv-val(1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan1.4.341, driver610.88,subgroup 32..32,VK_EXT_fragment_shader_interlock,LEONIDA_VK_VALIDATION=1)main(d48a957bb9988afce424552a3c0c8d01ef12320f): Assemblingps_pops_wait_loop.asmwithllvm-mc(-triple=amdgcn--amdpal -mcpu=gfx1013), translating withmain'stools/rdna2spirv.py, and running on RTX 3090 viavk_harness(VK_EXT_fragment_shader_interlockenabled) returns(0x00010000, 0x00000000, 0x3f800000, 0x3f800000)across all4096/4096pixels (65,536loop-guard rounds withEXEC = 0instead of1).PR + main:vk_harnessrebuilds cleanly (0MSVC warnings).python -m unittest discover -s tests/semantic -p "test_pops_collision_seed.py" -v:12/12tests pass (OK).python -I scripts/run_gpu_tests.py --filter ps_pops_wait_loop --require-pass(LEONIDA_VK_VALIDATION=1on RTX 3090):PASS ps_pops_wait_loop(4096/4096pixels exact(0x00000001, 0x00000000, 0x3f800000, 0x3f800000),spirv-valclean,0Khronos validation errors).scripts/check_no_game_data.py,test_docs_encoding.py, andtest_text_write_line_endings.py: pass (0CRLF).tests/semantic/test_pops_collision_seed.pyimportssupportwithout insertingos.path.dirname(os.path.abspath(__file__))intosys.pathfirst, so directpython -I tests/semantic/test_pops_collision_seed.pyraisesModuleNotFoundError: No module named 'support'(whereasunittest discover -s tests/semanticpasses).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T12:42:24Z.
@QemmHD this PR now conflicts with
main(runtime/test/vk_harness.cpp). Could you mergemaininto your branch (no force-push needed)? It was verified before the conflict: https://github.com/ProjectLeonida/mandy/pull/2174#issuecomment-7239295605. If there's no update within 24 h, OreoFR may carry it in a new PR that keeps you as co-author (per the maintainers' plan). — OreoFR's agent (AI-assisted)Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:40:25Z.
Carried as #2731 because of the conflict with main after #2566; @QemmHD, if you come back, say so and the carry is dropped.