tests/semantic/test_valu_div_fixup.py compared a hand-written Python model of the
fixup against itself and never imported tools/rdna2spirv.py, so it passed whatever
the translator did, and its rules had drifted from native RDNA2 (gfx1036) on six
points (NaN priority, the sign of 0/0 and inf/inf, inf(S2), the copysign of the
pass-through, NaN(S0), and the exponent-difference cutoff).
It now translates hand-written listings and asserts what the translator emits: the
pure-integer lowering's op order and classification constants, NaN(S2) above
NaN(S1) read off the dataflow, one word per measured rule through
spirv_mini_interp, and the EXEC-masked and null-destination cases. The f16 model
is gone rather than ported: the translator has no v_div_fixup_f16 lowering yet
(#2477 adds it with its own translator tests).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Gen.ds_permute lets each destination lane scan the 32 source lanes of its half: per source
lane a shuffle of the published target, a shuffle of the data and an OpSelect that keeps the
data when the target is this lane. Each shuffle was used once and so was every link of that
chain, so SPIRV-Cross (MoltenVK) wrote the 32 steps as one nested ternary under the EXEC
ternary of the register write. A lane that takes an outer arm, or is off in EXEC, then runs
none of the shuffles inside it (the SHADER-529 mechanism).
On an Apple M5 (MoltenVK 1.4.2) tools/lds_fuzz.py --wave 32 --permute had 17 of the 100
programs of seed 31002 differ from the model, every one in a ds_permute_b32 result, mostly 0
where a source lane's data belongs. Both shuffles are now stored to Function variables
(Gen.eager), as the DPP rule stores its ballot bit and its shuffle.
tests/semantic/test_ds_permute_eager.py checks the three native forms with
test_dpp_eager_subgroup.py's model of SPIRV-Cross's single-use forwarding, and the values
against test_ds_permute.py's ISA model.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The fixture reads the operands of its f32 multiply-adds from s4..s7 so that a driver has to
compute them at run time. The three operands of its v_fma_f16 were literals, which made the
whole f16 multiply-add a compile-time constant. MoltenVK 1.4.2 gives the wrong constant: word
7 read 0x0000 on an Apple M5 (0x3c00 in the docs' row) where 0x7351 is expected, the
cs_fma_fused failure listed in docs/testing.md and in the macOS job's EXPECTED_FAILURES. The
same translation with any one of the three operands taken at run time gives 0x7351.
The triple is now the s4 word XOR a literal each, so the test checks the translator's
round-to-odd sequence as the GPU runs it. The translator is not changed.
tests/semantic/test_fma_fused_fixture.py runs the fixture in the interpreter against the eight
words of its header and checks that no multiply-add in it reads a register only literals fed.
The Known problems row says what is left: an f16 multiply-add with only constant operands.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A register holds this lane's bit of a lane mask; v_mbcnt, s_bcnt1 and
s_ff1 gather the other lanes' bits with a subgroup operation
(Gen.wave_mask). v_mbcnt writes a VGPR, so its result is selected on the
lane's EXEC, and MoltenVK's SPIRV-Cross inlined the single-use gather
into the taken arm of that ternary:
v6 = active ? popcount(simd_or(mine ? bit : 0) & below) + acc : v6;
A lane that is off never ran the gather, so its bit was missing from
every other lane's count. Gen.wave_mask now stores the gather to a
variable of its own with Gen.eager, as SHADER-529 did for DPP's ballot
and shuffle.
On an Apple M5 (MoltenVK 1.4.2), tools/crosslane_fuzz.py with wave 32,
native and no maskdata goes from 92 of 100 programs matching to 100 of
100, and from 193 to 200 of 200 with DPP at seed 7.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A .pyc does not help ast.parse. test_runtime_paths.py, test_isa_coverage.py,
test_shader_stage_resume.py, test_cmake_translator_deps.py and
test_resource_hygiene.py read the syntax tree of tools/rdna2spirv.py, seven
whole-file parses of 7 s each on CPython 3.12, 3.13.0 to 3.13.15 and 3.14.0
to 3.14.7. They now call tests/semantic/piecewise_parse.parse, which gives
the same tree (tests/test_piecewise_parse.py) in about 1 s.
tools/isa_coverage.py parses inside scan_translator and accepted_names;
its test patches ast.parse around those two calls on the real translator
instead of changing the tool.
Python 3.14.7, valid .pyc of the translator, two runs each:
test_runtime_paths 16.0 -> 3.7 s, test_isa_coverage 15.0 -> 2.5 s,
test_shader_stage_resume 14.2 -> 8.2 s, test_cmake_translator_deps
7.6 -> 1.4 s, test_resource_hygiene 7.6 -> 1.3 s.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
v3.13.16 and v3.13.17 no longer copy the source at an f-string field
(Parser/lexer/lexer.c keeps last_expr_start); v3.12.16 still does. needed()
is now true on 3.12, 3.13.0 to 3.13.15 and 3.14.0 to 3.14.7.
The README paragraph moves below the one about calling the translator, so
it no longer touches the lines #2114 adds.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
On CPython 3.12.0 to 3.14.7 the tokenizer copies the rest of its input at
every f-string field (update_fstring_expr: strlen, PyMem_Malloc, strncpy),
and import hands a module over as one string, so compiling the 1.2 MB
tools/rdna2spirv.py takes 7 s, 0.1 s of it code generation. CPython fixed it
in 3.14.8 and 3.15.0 (gh-155525); 3.12, which CI pins, keeps it.
tests/semantic/piecewise_parse.py finds statement starts with tokenize,
parses top-level statements in pieces of 300 lines (a longer class is cut
between the statements of its body) with one newline in front for every line
before the piece, and joins them into the tree a whole-file parse gives.
Whatever does not fit returns None and the source is compiled the usual way.
tests/semantic/support.py loads the modules of TOOLS_DIR through a
SourceFileLoader subclass that compiles that tree, by a sys.meta_path finder
placed just before PathFinder, only on the interpreters above. A valid .pyc
is still used first.
tests/test_piecewise_parse.py compares the trees for every Python file of
the repository, hand-written boundary cases, the exceptions and warnings
against compile(), and code objects against compile(bytes).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AGENTS.md said 433 files and 5 821 tests in 224 s on 16 cores.
tests/semantic/README.md said 26 s, or 253 s one file at a time, on 16
cores. The two disagree, and both count an older suite.
Measured on main 3d3770c (the suite is unchanged at a289278), Windows 11,
Ryzen 7 7435HS with 16 threads: 465 files and 6 108 tests, 0 failed, in
297 s with the default 16 jobs and 2 401 s with -j 1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README said the test runs 33 formats. The ADDED table in
test_buffer_formats_all.py has 45 entries (counted with ast), and the
load and store loops iterate all of it. Only the number changes.
Seven more test files that fail on main at d083a2c, after #9896:
- test_docs_repeated_lines: tests/semantic/README.md's command block is a fenced block, which the check skips;
its indented form put two lines with the same 40-character opening three lines apart
- test_docs_repo_paths: docs/retail_boot_intel_host.md names #8554's frame-loop notes instead of a path that
is not in the tree
- test_docs_env_vars: runtime/README.md documents LEONIDA_RNG_SEED (runtime/shims/bcrypt_rng.cpp)
- test_docs_design_rows: docs/README.md gets one row each for strand_grooms.md and ped_catalogues.md (two
rows each were merged in), and design.md escapes the pipe in `prim_cnt << 12 \| vtx_cnt`
- test_docs_cli_flags: docs/testing.md passes llvm-mc through LLVM_MC, so `brew --prefix` is no longer read as
a bench_wave64.py flag; pt-PT's quickstart points to the web checker that replaced tools/pc_checker.py
(5125a01), as README.md does; the spirv-opt passes docs/embedded_shaders.md quotes join FOREIGN
- test_bvh_slot_check: bvh_match.model_geometries() yields six fields since the render bucket was added;
unpack the two it needs
- test_joaat_agreement (find_hash_lookup's half): hash over the Latin-1 bytes like hashdict.joaat, as #6254 and
#7820 proposed
Still red, for a separate change: test_joaat_agreement's leonida_mods half (it hashes UTF-8 bytes like
runtime/src/mods.h, so both sides change together), test_f64_conversion and test_f64_output_modifiers (they
expect the output scaling #6314 gated by MODE) and test_bvh_shaders_stage.
fixtures/ms_prim_export.asm (72 threads, two wave64 waves) runs as a mesh shader and with --mesh-compute: m0 = prims << 12 | verts gives the counts, the three 9-bit index fields exclude the edge flags, bit 31 sets CullPrimitiveEXT, and threads at or past a count write nothing. spirv_mini_interp learns OpSetMeshOutputsEXT, struct zero values, aggregate outputs and OpAtomicStore.
Squash-merged after diff review of PR #6898 - rdna2spirv: a wave32 pixel shader reads its descriptor index from a running lane of its half, not lane 0 (SHADER-1016, the #4225 RDNA1 regression)
Since 70e739fd7 (coalesce hoisted spine guards) the tail program is one tail scheduler, so
test_tail_scheduler_after_a_mini_scheduler and the interpreter check of the mini scheduler's clears fail after the
merge, though they pass on the branch (based on aa2988cc).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/semantic/test_image_bvh_tri_hw.py holds every single-lane row of the triangle measurement on an RX 6800
(308 rows of 12 kernels: slots, both windings, misses, the remap byte, t max and t sign, zero area, NaN and inf in
the node and the ray, shared edges and vertices) and lanes 0, 15, 16, 31, 32 and 63 of the two 64-thread kernels
(84 results). Each runs through the translator in both forms, with contiguous or NSA address operands as measured,
and must give the hardware's four words bit for bit. All are asserted; main's translator gets 129 of the 308 rows
(14 more raise on undefined SPIR-V). The data block is written from the raw outputs by a script, not by hand.
Co-Authored-By: Claude Opus <noreply@anthropic.com>
Conflicts: tools/rdna2spirv.py (main's x_round state next to this branch's fmt_enc_fn, and the
function types of both: both kept), docs/design.md (main's rows, our Typed buffer loads sentence
re-applied), tests/test_shader_checks.py (TOTAL: main's 13 plus cs_fmt_all = 14, and both mock
branches kept; 75 tests pass).
Main's typed-buffer work that overlaps (aa2988cc: byte size of the format from one table, SHADER-429:
DST_SEL=1 on out-of-bounds typed loads) merged without conflict and takes this branch's formats from
Gen.FORMATS. Ten tests in test_mutations, test_cmp_class_f64, test_loop_ballot_barrier and
test_vcmp16_opsel fail on origin/main itself, with and without this branch.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
test_w64x_clear_single_writer.py gains a mesh shader and whole-workgroup runs of
programs that take the inline helpers (one wave and several), two local round
loops, and a round loop after a local one. The lockstep interpreter of
test_wave64_emulate_opt.py also fails when one invocation plain-stores a %x_buf
word that another loads or updates between two barriers. With any one of the
four places put back, both files fail. The design.md row has the numbers
measured on main aa2988cc.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main split x_scheduler into x_prologue and x_round_loop_head and added structured
emulation (x_mini_scheduler, the x_pre_* helper functions). The one-writer clears
are ported to all four places that stored to the sink word. The helper functions
now have a selection, so the inliner of tests/semantic/test_wave64_emulate_opt.py
keeps their labels, and its lockstep interpreter fails when two invocations store
to one %x_buf word between two barriers.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Under --wave64-emulate the scheduler cleared parts of %x_buf (Workgroup memory)
with plain stores that several invocations aimed at one word: the zeroing before
the first barrier clamped its index with UMin, so every invocation past the end
of a range stored to its last word, and at the top of each round every
invocation with nothing to free stored 0 to a shared sink word. All stores wrote
0, so results did not depend on it, but it is a data race, and GPU-assisted
validation reports SharedMemoryDataRace-RaceOnStore on every emulated compute
shader.
Invocation i now clears word i of each row, a short last row is stored only by
the invocations that have a word in it, and in a round only lane 0 of a wave
(mask words) and invocation 0 (counts) store, each behind a selection that ends
before the barrier. The last word of %x_buf is no longer written; it stays
allocated so the buffer size does not change. No module changes without
--wave64-emulate.
tests/semantic/test_w64x_clear_single_writer.py runs the scheduler's head for
every invocation at nine workgroup sizes.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ps_fnan_med3 puts its NaN in S0 only, so no GPU test reached the cases
ps_fnan_med3_s2 (f32) and ps_f16_fnan_med3 (f16), with inputs read from
memory at run time and words derived from the measured rule in
docs/design.md (with any NaN operand, med3 is min3 with the NaNs
ignored). The all-NaN case is left out: its payload is not modelled.
Registered in check.py and run_gpu_tests.py; the semantic fixtures and
GpuFixtures tests run them through the interpreter, where the
translator before #2029 fails them (undefined FClamp on a NaN).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that
uses it. The DPP lowering put the source-EXEC ballot on the right of an
OpLogicalAnd (a short-circuiting && in MSL) and the shuffle in the arm of a
scalar OpSelect (a ternary), so lanes out of their row skipped the ballot and
the shuffle read from lanes that never ran it: row_shr:1's lane 1 found lane 0
inactive and kept its old value (cs_dpp_ops on MoltenVK).
Both results are now stored to a Function variable of their own (Gen.eager)
and loaded back; a store is a statement every lane runs. Only the DPP path
changes: of the 217 GPU test shaders that assemble here, exactly the nine
cs_dpp* ones translate differently, all still pass spirv-val, and SPIRV-Cross
1.3.239's MSL now computes the ballot and the shuffle as their own statements.
tests/semantic/test_dpp_eager_subgroup.py models SPIRV-Cross's single-use
forwarding and fails on the old lowering for all 11 DPP16/DPP8 forms tested;
it also checks the values in spirv_wave_interp.py against a DPP reference.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GN11jbD4AeqgwR5C5Z5Xs9
spirv_mini_interp.py evaluated the OpPhi of a block one after another and
wrote each result at once, so a later OpPhi that names an earlier one of the
same block read its new value. A loop header that swaps two values
(%a = OpPhi ... %b %cont, %b = OpPhi ... %a %cont) gave (2, 2) after three
iterations from (1, 2); SPIR-V and spirv_wave_interp.py give (2, 1). The
first OpPhi of a block now evaluates the whole run against the values from
before the block, and each one then takes its own.
The module docstring and the README's Limits said backward branches, loops
and calls are rejected; the interpreter runs them (10000 backward branches
at most), and only rejects switches.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Two wave32 GPU tests, cs_w32_lds_subdword (ds_write_b8/_b16 and their
_d16_hi forms, ds_read_u8/_i8/_u16/_i16) and cs_w32_lds_wide
(ds_write/ds_read _b64/_b96/_b128, ds_read2st64_b32), and a semantic
test that runs them in the SPIR-V interpreter against a byte-level LDS
model of the ISA rules, with three SPIR-V sabotages as negative
controls. These ops were checked only by lds_fuzz.py, which needs a GPU.
No translator change. RTX 4070 SUPER, driver 610.88: both dumps match.
AI-assisted (Claude Code).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/semantic is the translator regression suite, but a file there can reimplement the instruction in Python and pass whatever the translator does. Add an ast-based guard: direct import, a helper that reaches the translator, or a subprocess naming rdna2spirv.py. The interpreter self-tests, the hand-written-SPIR-V files and the three pre-existing offenders are listed with a reason, and a second test rejects stale entries.
store_inputs() gave y and w the same value for two-component formats, so run_stores could not
tell the translator's (x, y) from the Radeon 880M's (x, w) for buffer_store_format_*; the zero
mismatches did not validate the second component. The probe now uses a different value in every
register and also runs _xy stores. The hardware model routes a two-component
buffer_store_format_* to (x, w) (_xy: (x, 0)); tbuffer_store_format_* takes (x, y) like the
translator. Those stores are counted as known-difference elements, outside the validated count:
1,330,469 validated elements, 0 mismatches, plus 26,523 known-difference elements.
The translator is unchanged (RDNA2 unmeasured); the difference is pinned as an expectedFailure
in test_buffer_formats_all.py. docs/buffer_formats.md and the design.md row say so.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Gen.FORMATS now holds 65 of the 77 codes a V# or MTBUF can carry. Added: 8/16-bit UINT and SINT,
every USCALED and SSCALED, SINT of the wider families, 10_11_11_FLOAT and 11_11_10_FLOAT
(unsigned 5-bit-exponent floats), and the SNORM / SCALED / UINT / SINT members of the 10_10_10_2
and 2_10_10_10 families. The twelve non-FLOAT 10_11_11 / 11_11_10 codes stay unsupported: GFX11 has
none, so nothing measures them.
Stores follow what the Radeon 880M did (RDNA3.5, not RDNA2): SINT and UINT saturate, NORM stores
round the exact product (Gen.norm_encode_exact), a SCALED store converts as its NORM format, the
small floats round toward zero and saturate to the largest finite value (Gen.ufloat_encode_bits),
and a half rounds away from zero in a 2-bit SNORM field. Existing formats keep their emission:
with the table cut back to its old 32 codes the output for all 182 runtime/test/shaders is
byte-identical to before.
tests/semantic/test_buffer_formats_all.py holds the translation to the hardware model for every
added format (loads through the V# and tbuffer, stores, hand-worked values) and pins two older
stores that differ from the hardware as expected failures. cs_fmt_all.asm is the GPU fixture (28
loads, 15 stores; AMD Radeon 880M and NVIDIA RTX 5070). docs/design.md gets the contract row.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>