Repository navigation
Conversation
aa2988c built %fmt_size_arr from gen.cu(128) after assemble() had already dumped the OpConstant %uint list, so a dynamic-format buffer store referenced %c80 that no line defined. tests/test_u16_high_half.py assembles and validates the module, but returns early when the tools are not on PATH, so a tool-less run passed while the module was invalid. Check the module text instead, which needs no external tool: every %name a line references must be defined, and types/constants must be declared before their use. The check is generic over all ids (not only %cXX) and allows the legal forward references (labels, branches, OpPhi, OpEntryPoint's %main).
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 464635c1b on Windows 11: pytest tests/test_spirv_undefined_ids.py -q -> 12 passed; git diff --check clean.
The new test walks the translator's emitted ids (definitions, uses, OpPhi/label forms) and reports an id that is used without a definition, so the %c80-style late-constant bug (#3902/#4466) and any future dangling id are caught without needing spirv-as/spirv-val. The positive/negative cases and a synthetic dangling module are covered. No blocking issue; this is complementary to #3902/#4466, not a duplicate.
|
Tested
No game files. AI-assisted (Devin). |
|
Verified on Linux, CPU-only. Merged with current main: compileall clean, pytest tests/test_spirv_undefined_ids.py 12/12 (re-run here), and python -I on the file fails loudly (ModuleNotFoundError: pytest) rather than silently running nothing. The story checks out at the quoted commits: at aa2988c the two dynamic-format store cases fail on the dangling %c80, while the pre-registration fix 06b47de already predates this PR head — so the suite passes, and the guard earns its place as the SPIRV-Tools-free floor. Closest existing coverage test_u16_high_half also passes (33, real spirv-as/spirv-val on PATH). No game data; fixtures hand-written/synthetic. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested
|
Problem
aa2988ccbuilt%fmt_size_arrat assembly time fromgen.cu(128)and the format-size constants afterassemble()had already dumped theOpConstant %uintlist, so a shader using the dynamic-format table declared its array from an id that was never defined. The text assembled butspirv-valrejected the binary withOperand 'N[%N]' requires a previous definition.That specific defect is fixed on
main(registering the table constants in the typed-load path; e.g.06b47de1, andfmt_int_flags()registers the format-mask constants at use time), andtests/test_u16_high_half.pypasses there. This PR does not change the translator: it adds the regression guard that would have caught the defect without the external tools.Why a guard is still needed
tests/test_u16_high_half.pyassembles and validates the translator output, but returns early whenspirv-as/spirv-valare not onPATH(conftest.HAVE_SPIRVfalse). In that configuration the module is never checked: on the parent commitpytest tests/test_u16_high_half.py -qreported33 passedwhile the module was invalid. Any CI job or contributor machine without the optional tools has the same hole, and the same class of bug (agen.cu()call placed afterassemble()dumps the constants) can come back.What the test does
tests/test_spirv_undefined_ids.pychecks the module text thatrdna2spirv.translate()already returns. It never invokesllvm-mc,spirv-asorspirv-val, so it runs everywhere.undefined_ids(): every%namereferenced by a line must be defined by some%name = Op...line. The check is generic over every id, not only%cXX: a missing definition is invalid for any id, so no forward-reference exception is needed.used_before_definition(): a type or constant used by another type or constant declaration before its definition line. Forward references are legal only for labels, branches and switches, merge operands,OpPhiand function ids, so the order check is deliberately limited to type/constant declaration operands (and skipsOpTypeForwardPointer, which the translator does not emit).Twelve cases: two store-only dynamic-format listings (one is the minimized sequence from
tests/test_u16_high_half.py), one dynamic-format load, two controls (a plain pixel shader and a fixed-format MTBUF store), two existingtests/semantic/fixtures/disasmcompute fixtures, and checker self-tests (legal forward references accepted; undefined%c80,%fmt_size_lenand%t9000reported; a constant defined after the type that uses it caught by the order check).Evidence
The test fails on the parent of the upstream fix and passes now:
Cross-check with a local SPIRV-Tools v2026.4 build: on
03b09a08the module assembles andspirv-valfails withOperand '135[%135]' requires a previous definition; on current main bothspirv-asandspirv-valpass.Related files on current main:
69 passed, 585 skipped, 8 subtests passed(the skips are the tool-gated tests in this tool-less environment),python -I tests/test_ci_registration.py->Ran 8 tests ... OK, so the existingtranslator-testspytest glob picks the new file up and no workflow change is needed.Limits
The checks verify id existence and type/constant declaration order only, not operand types, dominance, duplicate definitions or instruction form; a module without dangling ids can still be rejected by a real validator. This is the tool-less floor for jobs and machines without
spirv-as/spirv-val, not a replacement for validating where the tools are installed.AI-assisted.