rdna2spirv: check high 32 bits for buffer offset fit to avoid NVVM crash (SHADER-NVVM-MUBUF-OFFSET-FIT) #2438
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2438"
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 timbot103 on 2026-11-27T07:58:04Z.
Claimed in the coordination issue as: SHADER-NVVM-MUBUF-OFFSET-FIT
Summary
Avoids an NVIDIA 580.82.07 NVVM pipeline-creation failure (
NVVM compilation failed: 3,VkResult -13) inGen.buffer_address(tools/rdna2spirv.py:4455) by rewriting the 64-bit unsigned 32-bit offset-fit predicate from:to the mathematically equivalent high-32-bits zero test:
Root cause, minimal reproducer, and NVIDIA L4 (
580.82.07) A/B verification are credited to@kevincommitsin #1608 (comment 7208330785), who left the fix unclaimed.Changes
tools/rdna2spirv.py: EmitOpShiftRightLogical %ulong {wide} %c64_32+OpIEqual %bool {hi_w} {self.cl(0)}inGen.buffer_addressinstead ofOpULessThanEqual %bool {wide} {self.cl(0xFFFFFFFF)}. Overuint64,(wide >> 32) == 0is identical towide <= 0xFFFFFFFFfor all values[0, 2^64 - 1].%ulongand%c64_32are already emitted withuses_psb, anduses_long = Trueis preserved.tests/semantic/test_buffer_offset_wrap.py:disabled literalcoverage totest_index_inside_the_buffer_is_stored_and_read.test_32bit_boundary_fits_and_first_overflow_is_rejectedchecking the exact 32-bit edge:0xFFFFFFFC(dword) and0xFFFFFFFF(byte) fit, while0x1_0000_0000is rejected, acrossidxen(dynamic + literalV#) andsoffset.test_fit_predicate_checks_high_32_bits_without_u64_max_comparepinning the emitted SPIR-V predicate (both raw translator output and afterspirv_opt.optimize) so neitherOpULessThanEqual ... %clffffffffnorOpULessThan ... %cl100000000regresses back in.Verification
@kevincommits, #1608#issuecomment-7208330785): On NVIDIA L4 (580.82.07, Vulkan1.4.312),valu_fuzz.py --family memhit 5NVVM compilation failed: 3(VkResult -13) pipeline-creation errors across seeds20261126and1on pristined1dff7949; switching line 4455 to(wide >> 32) == 0resolved all 5 and passed240/240on both seeds.1.4.363.0, WSLllvm-mc 21.1.8, NVIDIA GeForce RTX 5080616.64+ AMD Radeon25.10.30.02):python -I -B tests/semantic/test_buffer_offset_wrap.py -vfailed4/4predicate subtests on pristineorigin/main(d1dff7949) and passed 6/6 patched.spirv-as+spirv-val --target-env vulkan1.3passed 18/18 modules (9 buffer-offset cases including the reported L4 reproducer and byte-exact0xFFFFFFFFedge, both raw andspirv_opt.optimize), 0 errors.test_buffer_bounds_shared.py,test_buffer_oob_select.py,test_buffer_swizzle.py(9/9),test_buffer_sub_dword.py,test_buffer_store_format.py, andtest_value_semantics.py(41/41) all passed.valu_fuzz.py --family mem --wave both --emulate --programs 120:--seed 20261126: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--seed 1: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--seed 20261126: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)--seed 1: 240/240 match (0 mismatched, 0 skipped, 0 harness errors)run_gpu_tests.py --require-pass,LEONIDA_VK_VALIDATION=1):cs_bounds,cs_oob_select,cs_oob_tail,cs_buf_fmt8,cs_buf_load_sub,cs_buf_swizzle,cs_buf_tailpassed 7/7 on RTX 5080 and 7/7 on AMD Radeon with 0 validation diagnostics (cs_buf_counterandcs_buf_typedskipped as expected).scripts/check_no_game_data.pypassed;git diff --checkclean; LF line endings preserved.616.64) and AMD Radeon (25.10.30.02), not L4580.82.07, so local runs verify semantic equivalence, SPIR-V validity, and dual-GPU execution parity while citing@kevincommits's L4 driver before/after (@kevincommitsis welcome to re-confirm on580.82.07if convenient). Retail boot impact was not measured. No game files were used. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by GrahamboJangles on 2026-11-27T08:25:17Z.
Reviewed head
192f3c740against PR based1dff7949on Windows 11,python3= CPython 3.13.14 andpython= 3.14.9, no GPU, no game data. Coordination re-checked: both #1608 entries readdone: … -> #2438, no other PR carries the item tag, and this PR had no comments or reviews when I started.Local runs (exact commands, at PR head branch):
python3 -I tests/semantic/test_buffer_offset_wrap.py -v: 6/6 OK, 1.06 s; same file on 3.14.9: 6/6 OK, 1.11 s.tools/copied into a scratch tree viaLEONIDA_TOOLS_DIR(main ata73a57e13): 4 failures, 6 tests ran — all four subtest variants oftest_fit_predicate_checks_high_32_bits_without_u64_max_comparefail on main's output (OpULessThanEqual %bool %t14 %clffffffffmatches the forbidden regex in both raw andspirv_opt.optimized text), while the boundary tests pass on both. So the new predicate pin genuinely catches the old emit, and the boundary behavior is identical between old and new — exactly what an equivalence-preserving rewrite should show.python3 -I tests/semantic/test_active_cache.py: 9 OK.python3 -m py_compile tools/rdna2spirv.py tests/semantic/test_buffer_offset_wrap.py: clean.Code read: the rewrite sits in
Gen.buffer_address(thewide = base + soff + idx*stridechain). Overuint64there is no wraparound case:(wide >> 32) == 0⟺wide ≤ 0xFFFFFFFFfor all[0, 2^64−1], so the predicate is exact, not just almost-always-equal. Typing checks out in the emitted module:%c64_32 = OpConstant %ulong 32already exists on theuses_psbpath (used for the V# base rebuild), the shift isOpShiftRightLogical %ulong(shift operand same width as base — valid), andself.cl(0)emits the%ulongzero theOpIEqualneeds.uses_long = Trueis preserved because the emitted ops themselves keep it true even where the old compare did.What I could not check here: the NVVM half. The crash repro (NVIDIA L4, driver 580.82.07,
valu_fuzz.py --family mem, 5 ×NVVM compilation failed: 3→ all resolved by the swap) is credited to @kevincommits in #1608 (comment 7208330785); I have no NVIDIA GPU on this machine, so the driver-side claim is his, verified by the two contributors who have one. What I verified is the translator-side contract: the predicate emitted, its equivalence, its typing, and that the test pins fail on the old emit and pass on the new one (raw and post-opt).Merge state at read time:
mergeable=true,mergeStateStatus=unstable(12 check jobs still settling, none failed).No findings on the change itself. AI-assisted (Hermes agent); verification commands above are reproducible on any machine with CPython.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-27T11:31:23Z.
Review: COMMENTED
Windows x64 / RTX 3090 GPU and semantic check of #2438 (
192f3c740).Environment: Windows 11 x64, NVIDIA GeForce RTX 3090 (driver
610.88, Vulkan1.4.341),VK_LAYER_KHRONOS_validation1.4.363, SPIRV-Tools1.4.363.1.Code & equivalence check
Gen.buffer_address(tools/rdna2spirv.py:4455),wideis an unsigned 64-bit (%ulong) sum of zero-extended 32-bit unsigned offsets andu64(idx) * u64(stride). Over alluint64values,(wide >> 32) == 0(OpShiftRightLogical %ulong %wide %c64_32+OpIEqual %bool %hi_w %cl0) is bit-for-bit equivalent towide <= 0xFFFFFFFF(OpULessThanEqual %bool %wide %clffffffff),%c64_32is already unconditionally emitted wheneverpsb(self.uses_psb = True) is set, andself.uses_long = Trueremains set forself.cl(0).spirv_opt.optimizepreserves bothOpShiftRightLogicalandOpIEqual %bool ... %cl0without folding them back into anOpULessThanEqual/OpULessThan64-bit range compare.Semantic tests & negative control
python -I tests/semantic/test_buffer_offset_wrap.py -v: 6/6 OK (idxen0x3fffffff * 4 = 0xfffffffcfits vs0x40000000 * 4 = 0x100000000rejected across dynamic and literal V#s;soffset-8 + 4 = 0xfffffffcfits vs-4 + 4 = 0x100000000rejected; byte-4 + 3 = 0xfffffffffits vs-4 + 4 = 0x100000000rejected; SPIR-V predicate check on both raw andspirv_optoutput).tools/rdna2spirv.pytoOpULessThanEqual %bool %wide %clffffffffwhile keeping the updated test file fails immediately (FAILED (failures=4)). Restored.python -I scripts/check_no_game_data.pyon both changed files: clean.GPU verification on RTX 3090 (
vk_compute_test+VK_LAYER_KHRONOS_validation)Translated and validated (
spirv-val --target-env vulkan1.2) a synthetic 32-thread compute shader constructing literal-word3RAW(0x10000000) andDISABLED(0x30000000) V#s (stride = 4,records = 32,voffset = 0, foldingwideto0 + idx * 4) overs[0:3]'s buffer:RAWliteral V#:idx = 1stores77;idx = 0x40000001(0x1_0000_0004, which wraps modulo2^32to the same+4 Bslot) attempts to overwrite999and loads back.DISABLEDliteral V#:idx = 2stores88;idx = 0x80000002(0x2_0000_0008, wrapping modulo2^32to the same+8 Bslot) attempts to overwrite999and loads back.Ran
vk_compute_test cs_nvvm_fit_gpu32.spv 1 dumponNVIDIA GeForce RTX 3090withVK_LAYER_KHRONOS_validation1.4.363:0validation errors.out[0..3] = 77 0 88 0(and underlying scratch slots+20 B/+24 Bremained77/88), confirming both in-bounds accesses succeeded while both 32-bit-wrapping> 0xFFFFFFFFproducts were suppressed on hardware.No game data. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-27T17:05:53Z.
Independent NVIDIA Linux verification on driver
580.82.07(where theNVVM compilation failed: 3crash reproduces onmain; all runs on Google Colab Linux NVIDIA runtimes, applying the same(wide >> 32) == 0change totools/rdna2spirv.pyon top ofmainwithout checking out the PR branch directly):580.82.07,maind1dff7949):tools/valu_fuzz.py --family mem --wave both --emulate --programs 120(plain) —480/480matched (0 NVVM failures, 0 mismatches), including the 2 seeds that reliably failed withNVVM compilation failed: 3on unmodifiedmain.580.82.07,mainec91d695c&c0201a806, LunarG Vulkan SDK1.4.363GPU-AV + SyncVal,LEONIDA_VK_VALIDATION=1):--programs 30 --seed 20261126:60/60matched (0PhysicalStorageBuffer64OOB, 0 mismatches, 0 validation/sync errors).--programs 60 --seed 20261127:120/120matched (0PhysicalStorageBuffer64OOB, 0 mismatches, 0 validation/sync errors).Total:
660/660valu_fuzz --family memruns passing on NVIDIA580.82.07across Ada (L4) and Turing (T4), including180/180under SDK1.4.363GPU-AV + SyncVal.No game files used. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-27T21:21:50Z.
Pascal confirmation, MEASURED (one run per seed and arm): GTX 1050 Ti 4 GB desktop (profile S), NVIDIA 582.66, Windows 10 19045, llvm-mc 21.1.8.
python -I tools/valu_fuzz.py --family mem --wave both --emulate --programs 120 --seed S:39f52f39cNVVM compilation failed: 3)192f3c740All five failures are wave32 programs, the same as on the L4. With the PR, both seeds also run in about half the time (139 s against 307 s), since no program waits on a failed pipeline. Thanks @kevincommits for the reproducer.
Nit: the commit subject starts with a UTF-8 BOM (
EF BB BFbeforerdna2spirv:), which would land in main's history.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T00:22:07Z.
Thanks @qhukz13, @kevincommits, @zmasi, and @GrahamboJangles for the thorough cross-architecture verification (Pascal, Turing, Ada, Ampere, plus CPython 3.13/3.14)!
Good catch on the commit-subject UTF-8 BOM — stripped it and pushed "
ac3fb1b43" (identical treeef7105f9e, zero code changes).Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:46:37Z.
Native Windows 11 + NVIDIA GeForce RTX 3090 Verification (
PASS)Verified commit
ac3fb1b43cmerged ontomain(a9e247cd69) on Windows 11 (10.0.26200,x86_64-pc-windows-msvc, Python3.12.10) with physical NVIDIA GeForce RTX 3090 (driver610.88, NVVM, Vulkan1.4+VK_LAYER_KHRONOS_validation1.4.363.1,spirv-as/spirv-val1.4.363.1):maintools/rdna2spirv.py+ PRtest_buffer_offset_wrap.py):python -I tests/semantic/test_buffer_offset_wrap.py -v->FAILED (failures=4)intest_fit_predicate_checks_high_32_bits_without_u64_max_compare(OpULessThanEqual %bool %t14 %clffffffffemitted acrossdisabled literalandraw literalraw/opt modules).ac3fb1b43c+main):python -I tests/semantic/test_buffer_offset_wrap.py -v->6/6OK(1.308s, including 32-bit exact-fit0xFFFFFFFC/0xFFFFFFFFand first-overflow0x100000000checks acrossidxenand byte/dwordsoffset, plusOpShiftRightLogical %ulong ... %c64_32+OpIEqual %bool ... %cl0predicate checks).vk_compute_testwithLEONIDA_VK_VALIDATION=1on literal-V#idxencompute shaders):idx = 2, stride = 64):spirv-valclean, NVVMvkCreateComputePipelines+ dispatchrc=0,out[0] = 0x77770001(0mismatches,0validation errors).idx = 0x40000000, stride = 4->wide = 0x1_0000_0000):spirv-valclean, NVVMvkCreateComputePipelines+ dispatchrc=0, store dropped and load returnsout[0] = 0(0mismatches,0validation errors).python -I scripts/check_no_game_data.pyclean (0issues) and merges cleanly with#2164,#1803,#1352, and#1271.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T19:17:55Z.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, spirv-tools + llvm-mc, main
7c330c76d(also merges cleanly on current maindd87aa405; does not force a rebase of #2566), PR headac3fb1b43: green FAILStest_buffer_offset_wrap2/6. Green: also 2/6 — the 4 subtests oftest_fit_predicate_checks_high_32_bits_without_u64_max_comparefail with "expected 64-bit right shift by 32" (MEASURED n=3, alone).d1dff7949) predates main's4f2628f83(SHADER-423), which adds alower_addr64pass that rewrites 64-bit ops into 32-bit pairs, so theOpShiftRightLogical %ulong … %c64_32the test looks for no longer exists in the final SPIR-V. The code change still applies; the test expectation needs updating after a rebase.test_buffer_offset_wrap(4 cases) on top of main's 2 known ones; translator-tests identical to main.Verdict: FAILS (rebase + adapt the test to the 32-bit-pair lowering).
AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T23:19:18Z.
Thanks @OreoFR for catching this. The PR base predated
4f2628f83(SHADER-423,lower_addr64), so by default the 64-bitOpShiftRightLogical %ulong … %c64_32the old test looked for is lowered to 32-bit pairs and is no longer in the final module.New head
f0703cdef: one commit, rebased onorigin/main452d1d1b6. Thetools/rdna2spirv.pyhunk is unchanged (the same two instructions). Onlytests/semantic/test_buffer_offset_wrap.pywas updated.Does the fix still matter after
lower_addr64? Read in code and checked in the emitted SPIR-V (literal V#,wide=0 + idx * stride):origin/mainfit predicate--int64-addressesOpULessThanEqual %bool %wide %clffffffff(the NVVM-failing compare)OpShiftRightLogical %ulong %wide %c64_32+OpIEqual %bool %hi %cl0lower_addr64returns the text unchanged on any other 64-bit int use, e.g. ans_lshl_b64elsewhere)OpULessThanEqual … %clffffffff== 0hi < 0 || (hi == 0 && lo <= 0xFFFFFFFF);OpULessThanEqual %bool %lo %a64c_ffffffffsurvivesspirv_opt(0 == 0) && (hi == 0), onlyOpIEqual %bool %hi %a64c_0afterspirv_optSo on main the 64-bit compare still reaches the driver in the first two rows, including default builds of shaders with any other 64-bit integer op. In the lowered row, main's form is valid and I have no evidence it trips NVVM; there the change only removes a redundant term.
Test changes
0xFFFFFFFF * stridewrap, the 32-bit boundary dword/byte cases, structured modes, soffset) now runs in all three configurations:BufferOffsetWrapTests,…Int64AddressesTestsand…KeptInt64Tests. Each class also asserts that its modules really have, or lack,OpCapability Int64.FitPredicateTests:%clffffffff,%cl100000000, lowered%a64c_ffffffff), raw and afterspirv_opt.optimize(wide >> 32) == 0spirv-as/spirv-val --target-env vulkan1.2(the test is skipped if they are not on PATH)MEASURED on Windows 11 Pro 10.0.26200, Python 3.14.7, Vulkan SDK 1.4.363.0 spirv-tools, llvm-mc 21 (WSL, through
LLVM_MC). CPU-only (interpreter and spirv-val), no GPU run for this update:origin/main452d1d1b6,python -I tests/semantic/test_buffer_offset_wrap.py, gives 19 tests,FAILED (failures=20). Two tests fail:test_no_compare_with_the_32_bit_limit(12/12 subtests) andtest_int64_form_tests_the_high_word(8/8). The 15 semantic tests pass on main, as expected, because the two predicates are equivalent. n=3, identical.f0703cdef: 19/19 OK, with the spirv-val test run (not skipped). n=3.python -I scripts/run_semantic_tests.py tests/semantic:test_interp_computed_ij_fallback, 2 f16 rounding asserts (pre-existing, unrelated). No new failures.tests/test_translate.py(pytest, llvm-mc + spirv-tools): head 730 passed, main 730 passed.test_addr64_lowering.py8/8,test_text_encoding.py2/2,test_text_write_line_endings.py3/3 OK.check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_buffer_offset_wrap.py: clean.git diff --check: clean.git merge-tree --write-tree origin/main HEAD: clean.git merge-treewith its head22e1349d7is clean, so it still doesn't need a rebase, and the new test passes on that merged tree.@OreoFR could you re-run your gate on
f0703cdefwhen you have a moment?AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T06:05:56Z.
Independent verification on this machine (Windows 11, Python 3.13.14), and the negative control bites hard: 20 failures.
1. It applies.
merge-treeclean;f0703cdefcherry-picks ontomain0ae217cebwithout a conflict. Two files,180 insertions(+), 17 deletions(-):tools/rdna2spirv.pyand its semantic test.2. With the change:
3. With
main's tool and the PR's test:Twenty checks fail with the same assertion: the old tool tests only the low 32 bits for a buffer offset fit, and this commit is exactly that - check the high 32 bits, so a value that overflows 32 bits is refused rather than handed to NVVM truncated.
What I did not test: the translator run that would have crashed. The test asserts on the emitted pattern; whether NVVM actually rejects the wide offset is the failure this avoids and cannot be staged here without the shader corpus and a NVIDIA compile.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by ammonium231 on 2026-11-30T07:05:28Z.
RTX 3090 / 621.40, validation on,
f0703cdefmerged onto mainbbd45f5cc: test_buffer_offset_wrap.py 19/19 pass; against main's tools it fails the FitPredicateTests as expected. valu_fuzz --family mem --wave both --emulate --programs 120 (NVVM): 240/240 match.Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:25:03Z.
Independent check on Windows (not the author), at
f0703cdef.tests/semantic/test_buffer_offset_wrap.py: 19 tests passed.Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:31:07Z.
Full-suite follow-up on
f0703cdef(branch is 459 commits behind currentmain):test_interp_computed_ij_fallback(2 f16-rounding failures:17407 != 17408,0.07745361328125 != 0.0775146484375).main08e42a516: the same file 9/9 OK.f0703cdefonto currentmainlocally (clean, no conflicts) and re-ran it: 9/9 OK.So the failures come from the old base, not from this change. A rebase on current
mainbefore merge clears them. The targetedtest_buffer_offset_wrap.pywas already green (19 tests).AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:43:53Z.
Review: APPROVED
Reviewed the diff against
main:tools/rdna2spirv.py:4530-4537cleanly replacesOpULessThanEqual %bool wide 0xFFFFFFFFwith(wide >> 32) == 0(OpShiftRightLogical+OpIEqual) to avoid the NVIDIA 580.82.07 NVVM crash, with thorough semantic, lowered/Int64, andspirv-valtests intests/semantic/test_buffer_offset_wrap.py. Clean-room verified. Approving; please merge/rebase currentmainso CI runs green before merge.(AI-assisted review.)