Repository navigation
TEST-638: static check that no subgroup result reaches a short-circuiting && / || / ?: (SPIRV-Cross) - #3302
TEST-638: static check that no subgroup result reaches a short-circuiting && / || / ?: (SPIRV-Cross)#3302tomgamer22 wants to merge 8 commits into
Conversation
…quirable (MoltenVK) MoltenVK reports subgroups 4..32 and requiredSubgroupSizeStages 0, so VKC_SUBGROUP_SIZE=32 printed "not available" and the 32-lane compute tests skipped. The translator emits SPIR-V 1.5, where varying subgroup sizes are not allowed, so Vulkan fixes SubgroupSize at the device's subgroupSize (32 there). vk_compute_test now runs a probe shader (cs_wave_probe.comp, embedded) with the test's local size and flags first, checks every invocation's lane, subgroup number and ballot width, and runs the test if they match. If they don't, the test fails (exit 1) instead of being skipped. Full subgroups are requested where local size X is a multiple of maxSubgroupSize. Devices whose default isn't the requested size keep printing "not available".
…ross's short-circuit && / ?: (MoltenVK) SPIRV-Cross forwards a value read once into the expression that reads it and writes OpLogicalAnd / OpLogicalOr / OpSelect as the short-circuiting && / || / ?:, so a subgroup operation forwarded into their right side runs only in some invocations. On MoltenVK 1.4.2 cs_dpp_ops read 100 instead of 10 in lane 1 (the DPP source check in_row && ballot_bit(src)); SPIRV-Cross head still moves a ballot into &&. With the flag every OpGroupNonUniform* result is followed by a dead OpCopyObject of it, a second read, so SPIRV-Cross binds it to a temporary where it is computed. make_game.py and run_gpu_tests.py turn it on for driver id 14 (MoltenVK); LEONIDA_SUBGROUP_TEMPS=1/0 overrides, and build.py and the fuzzers take the variable. Without the flag the output is byte-identical.
…idth apart from lane order Review of ItsNotRexed#2886: the probe needs subgroup operations in compute (supportedStages) with basic and ballot (supportedOperations), or the size stays "not available". LocalSize is the one of the GLCompute entry point "main" the pipeline is made from, not the last in the module. The width is checked from each subgroup's own lane numbers and ballot (a wrong width fails the test); 32-lane subgroups that aren't in invocation order, which Vulkan doesn't promise and the translator assumes, print "not available" and the runners skip.
…ross's short-circuit && / ?: (MoltenVK) SPIRV-Cross forwards a value read once into the expression that reads it and writes OpLogicalAnd / OpLogicalOr / OpSelect as the short-circuiting && / || / ?:, so a subgroup operation forwarded into their right side runs only in some invocations. On MoltenVK 1.4.2 cs_dpp_ops read 100 instead of 10 in lane 1 (the DPP source check in_row && ballot_bit(src)); SPIRV-Cross head still moves a ballot into &&. With the flag every OpGroupNonUniform* result is followed by a dead OpCopyObject of it, a second read, so SPIRV-Cross binds it to a temporary where it is computed. make_game.py and run_gpu_tests.py turn it on for driver id 14 (MoltenVK); LEONIDA_SUBGROUP_TEMPS=1/0 overrides, and build.py and the fuzzers take the variable. Without the flag the output is byte-identical.
…ting && / || / ?: SPIRV-Cross (MoltenVK) forwards a single-use value into the expression that reads it and writes OpLogicalAnd / OpLogicalOr / OpSelect as short-circuiting && / || / ?:, so a forwarded subgroup operation runs only in some invocations (SHADER-529). ItsNotRexed#3086's --subgroup-temps prevents it generically; this test keeps it that way. tests/semantic/test_subgroup_select_hazard.py uses the detector of ItsNotRexed#3021 (@SweatierKey) unchanged and translates, with SUBGROUP_TEMPS on, every disasm fixture in the default, --wave64-emulate and --dispatch-loop modes plus hand-written listings for each other lowering that emits OpGroupNonUniform* (ds_swizzle, permlane16/x16, readfirstlane, readlane, mbcnt, s_cmp_*_u64, s_wqm, s_bcnt1, s_ff1, s_bitcmp, SCC from a lane mask). Self-tests show the detector flags hand-written hazards and not legitimate uses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ice); check.py catches stale builds Review of ItsNotRexed#3086: make_game.py ignored LEONIDA_SUBGROUP_TEMPS while run_gpu_tests.py honoured it, and build.py and the fuzzers took only the variable. tools/translator_modes.py now decides for all of them (make_game.py, run_gpu_tests.py, build.py, check.py, crosslane_fuzz.py, valu_fuzz.py): the flag on the entry point's own command line, then LEONIDA_SUBGROUP_TEMPS=1/0, then tools/vk_subgroup_info.py's driver id 14 (MoltenVK). A module the flag changed records subgroup_temps in index.json, and check.py lists a translator_modes failure when the build doesn't match what this device takes.
Conflicts were ItsNotRexed#3086's --subgroup-temps next to main's --pc-tail-ubo (rdna2spirv.py, make_game.py, build.py, valu_fuzz.py, the make_game tests, docs/design.md) and vk_compute_test.cpp (ItsNotRexed#3086's probe include and observed subgroup size next to main's vk_pc_tail.h include and Float64 check, reusing ItsNotRexed#3086's earlier read of the module). Both sides kept in each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p-hazard-check ItsNotRexed#3086 now picks --subgroup-temps through tools/translator_modes.py. Conflicts with main's --pc-tail-ubo (make_game.py, build.py, valu_fuzz.py, rdna2spirv.py, the make_game tests, docs) keep both modes; crosslane_fuzz.py, run_gpu_tests.py and docs/testing.md take ItsNotRexed#3086's side. make_game.py drops runtime_gpu_spirv_cross(), which ItsNotRexed#3086 removed. test_valu_fuzz's pc-tail test sets LEONIDA_SUBGROUP_TEMPS=0 so translate() doesn't query the device through its fake subprocess.run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested b34aed4 on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
No game files. AI-assisted. |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested on Windows 11 with two GPUs on one machine (head, which carries #3086, merged with main f847748, MSVC 14.51, Python 3.13.1):
Not covered: neither GPU runs MoltenVK, so the short-circuit hazard the check guards against is only checked statically. |
|
Tested b34aed4 on Apple M2 with MoltenVK 1.4.2 (macOS 26.4 (25E246), subgroup 4..32, device Vulkan 1.4.357): static hazard check 7/7 OK, subgroup-temps test 4/4 OK, GPU suite 138/199 passed, 56 skipped, 5 failed vs base f847748 120/199, 74 skipped, 5 failed A/B; no regression. Code read: Tests here (llvm-mc 21.1.8, Python 3.13.18):
Build caveat: like #1845's base, this PR's base does not fully build with AppleClang 17 — No game data; synthetic fixtures and counts only. AI-assisted. |
Claimed in #3047 (TEST-638).
Depends on: #3086 (this branch contains #3086's head, 34d4f60, merged with current
main; only the TEST-638 test file and onetest_valu_fuzzline, which setsLEONIDA_SUBGROUP_TEMPS=0for the pc-tail test, are new here).What it checks and why
SPIRV-Cross (MoltenVK) forwards a value read once into the expression that reads it, and writes
OpLogicalAnd/OpLogicalOr/OpSelectas the short-circuiting&&/||/?:. A subgroup operation forwarded into the right side then runs only in the invocations that evaluate it (SHADER-529,cs_dpp_opson MoltenVK). #3086 fixes it with--subgroup-temps, which MoltenVK gets, but nothing failed if a new lowering or a change to that pass let a forwardable subgroup result reach one of those operands again.tests/semantic/test_subgroup_select_hazard.pytranslates withSUBGROUP_TEMPSon and fails if any module has a single-useOpGroupNonUniform*result, or a single-use value computed from one in the same block, as the right side ofOpLogicalAnd/OpLogicalOror an arm ofOpSelect(except when the condition is anOpGroupNonUniformAny/Allresult, which can't diverge). Inputs:tests/semantic/fixtures/disasm(DPP,ds_permute/ds_bpermute, ballots, wave masks, wave64 and its emulation), in the default,--wave64-emulateand--dispatch-loopmodes;ds_swizzle,v_permlane16/v_permlanex16,ds_bpermute,ds_permute,v_readfirstlane,v_readlane,v_mbcnt_lo/hion a lane mask,s_cmp_eq/lg_u64,s_wqm_b32/b64,s_bcnt1,s_ff1,s_bitcmp1, and SCC from a lane mask. Each must still emit a subgroup operation, so the check can't pass vacuously.Self-tests on hand-written modules show the detector flags
in_row && ballotBitExtract(...), a shuffle in a?:arm and a value derived from a ballot bit right of||, that #3086'ssubgroup_temps()clears them, and that it doesn't flag legitimate uses (left side of&&, select condition, vote-guarded select, results read twice, results from another block).Credit
The detector is @SweatierKey's static check from #3021, with its rule unchanged. Thanks!
Testing
No GPU or game files needed.
python -I -m unittest discover -s tests/semantic -p test_subgroup_select_hazard.py: 7 tests pass on this branch.tools/rdna2spirv.pychange reverted locally: it fails, with 19 failures (cs_dpp_ops,cs_w32_permute,cs_w64x_permute,cs_w64x_ballot,cs_wavemaskand the DPP, swizzle, permlane, permute,v_mbcntands_cmp_eq_u64listings) and 1 error (nosubgroup_temps). With the change restored, it passes.test_subgroup_temps.py,tests/test_ci_registration.pyandtests/test_text_write_line_endings.pypass. Fulltests/semantic/run: 4153 tests OK (4 skipped).git diff --checkis clean.AI-assisted (Claude Code).
🤖 Generated with Claude Code