Repository navigation
Translator: constants assemble asks for late are defined too - #3902
Conversation
assemble writes the uint constants before the format tables, and those ask gen.cu for constants of their own. A shader whose only typed access is a d16 store used no 128 anywhere else, so fmt_size_arr's length (aa2988c) was an id with no definition and the module failed spirv-val (tests/test_u16_high_half.py on main). Constants asked for after the others were written now go in right after them.
|
Independent native Windows check of Full |
|
Tested c225f85 on real corpus shaders (CPU only, Windows 11, SPIRV-Tools from Vulkan SDK 1.4.363.0): pass. The 4 shaders of my own 1.0.2.1 copy that the TEST-305 watch found newly invalid at
Both PRs fix all four. This one also covers later |
Kam471
left a comment
There was a problem hiding this comment.
Tested c225f859 on Windows 11: tests/test_u16_high_half.py -> 33 passed (including the previously failing test_d16_buffer_store_no_redundant_extract_after_shr16); tests/test_d16_format_probe.py -> 21 passed, 2 skipped; compileall and git diff --check clean.
The generic late-constant insertion is the better fix than my closed #3921: it covers fmt_size_arr (128 and its entries), fmt_mask_arr, and any future prologue/stage array that first asks gen.cu() after the constant block. Inserting after the highest written constant keeps every use after its definition; the new test_translate.py case pins the d16-only shape. No blocking issue.
Flyander
left a comment
There was a problem hiding this comment.
Reviewed at c225f85. The late constants are inserted before all type and instruction uses, and the regression covers the d16-only shape that previously emitted an undefined array-length ID. Local compileall and diff --check pass; pytest/llvm-mc/SPIRV-Tools are unavailable here, and independent Windows verification reports the focused suites passing. No blocking finding.
|
Follow-up to my test above, same head c225f85: the 3,000-shader TEST-305 coverage sample of my own 1.0.2.1 copy ( |
|
Tested This fixes the one test that current
Where it came from, in case it helps: on this machine the file is green on the thirteen commits before GPU side (RTX 3080, driver 615.71.09):
The RTX 5080 was not run in this pass: it is holding ~15.6 GB for another job on this box, and I would rather Machine: Linux Mint 22 (Ubuntu 24.04 base), |
|
Tested at the head on Windows 11 / Python 3.13.0: The constant scan is the strong part: over 229 translated Minor, latent only: Approve. AI-assisted review, no game files, no GPU. |
|
Tested
AI-assisted (Claude Code). Synthetic test shaders only, no game files. |
|
Independent compatibility test at On Windows 11 with uv CPython 3.12.13, pytest 9.2.0, Vulkan SDK 1.4.363.0, and WSL LLVM 21 for assembly, the combined targeted run gave 709 passed, 99 subtests passed, and 4 skipped. It included |
|
Tested
AI-assisted (Claude Code). CPU only, no game files. |
|
Store-side coverage for this fix, if you want it in the branch. The regression only shows on a format store. A This is the test from my #4071, which I have just closed in favour of yours. It passes unchanged on your head class TestRuntimeFormatSizeTable(unittest.TestCase):
"""`%fmt_size_tab` holds one byte size per V# FORMAT code (a buffer_load/store_format at a run-time format), so it
declares a constant for each size plus the array length. Those have to be emitted with the rest of the constant
section: the table block asked for them after that section was written, so a module that needed the length (128)
nowhere else referenced an id it never declared, and spirv-val rejects it with
`Operand '<id>' requires a previous definition`. A format load also decodes the format, which registers 128 on
its own; a format store does not, which is the case pinned here."""
def test_runtime_format_store_declares_every_table_constant(self) -> None:
spv = support.translate_lines("ps_fmt_store_runtime", [
"s_mov_b32 s4, 0x1000",
"s_mov_b32 s5, 0",
"s_mov_b32 s6, 0x100",
"v_mov_b32 v1, 0",
"v_mov_b32 v2, 0x11223344",
# s7 is never written, so the V# FORMAT field is run-time data and the element size comes from the table
"buffer_store_format_xyzw v[2:5], v1, s[4:7], 0 offen",
"s_endpgm",
])
self.assertIn("%fmt_size_arr", spv)
self.assertIn("%c80 = OpConstant %uint 128", spv) # the array length nothing else asks for
declared = {line.split()[0] for line in spv.splitlines() if " = OpConstant " in line}
referenced = set(re.findall(r"%c[0-9a-f]+\b", spv))
self.assertEqual(sorted(referenced - declared), [], "the module references a constant it never declares")Only the |
|
Tested
AI-assisted (Claude Code). |
|
Tested c225f85 on RTX 5070, driver 621.01, Windows 11 Pro 26300, MSVC 14.44 (build_runtime.ps1), Vulkan SDK 1.4.363, Python 3.11, llvm-mc 23.1.6 (conda-forge
Baseline on No game files. AI-assisted (Claude Code). |
|
Corpus check on my own copy (Xbox Series 1.0.2.1), Windows 11, Python 3.14.2, llvm-mc 21.1.8, On Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
|
Tested c225f85 on NVIDIA GeForce RTX 3070, driver 620.70.06, Linux (Bazzite, Fedora 45 base, kernel 7.3.3): pass
AI-assisted run (Claude Code); counts only, no game data. |
|
Follow-up: the full corpus run on this head has finished.
Counts only, no shader data. AI-assisted (Devin). |
|
Tested
06b47de has no regression test, so your
|
|
Tested CachyOS (Arch-derived), Ryzen 7 7700X, --jobs 8 (8 shards + --merge), Python 3.14.10 (-I), llvm-mc 23.1.5, SPIRV-Tools v2026.4 (rc2). Run from the PR head against a copy of the main-run work folder ("no matching translator fingerprint": saved disassembly reused, translation rerun):
81 -> 0 on the native-wave64 path, no regressions. AI-assisted. |
Claimed in #3796 as:
#3796 (comment)
What and why
tests/test_u16_high_half.py::test_d16_buffer_store_no_redundant_extract_after_shr16fails on main. The moduleit translates doesn't validate:
%fmt_size_arr = OpTypeArray %uint %c80, and%c80is never defined.assemblewrites the uint constants (OpConstant %uintfor everything ingen.consts) and only then builds theformat tables, which ask
gen.cufor constants of their own:fmt_size_arr, from aa2988c, needs its length 128 and its entries;fmt_mask_arrneeds 16 and its mask words;A constant first asked for there gets a name and no definition. The mask table only works because translation
already happens to ask for its constants. In a shader whose only typed access is a d16 store, nothing else uses
128, so
fmt_size_arrbroke.The fix is generic rather than one more pre-registration.
assembleremembers which constants it wrote, andinsert_late_constantsadds any asked for later right after them, so before every type and instruction.Commits:
insert_late_constantsintools/rdna2spirv.pytest_constants_asked_for_late_are_definedintests/test_translate.py: that d16 store defines%c80once,before
%fmt_size_arr, and the module passesspirv-valTested
Linux, llvm-mc 23.1.5, SPIRV-Tools from the Vulkan SDK 1.4.363, on main aa2988c.
tests/test_u16_high_half.py+tests/test_translate.py%c80runtime/test/shaders/build.pyspirv-val.spv, byte for byteThe 234 GPU fixtures don't change at all, so this only touches modules that were invalid.
python -m unittest discover -s tests/semantic: 7,456 tests, the same 7 failures and 2 errors as on main aa2988c (test_loop_ballot_barrier3 + 2,test_cmp_class_f642 (TEST-853),test_mutations2), none new.Checklist