After the merge the tree held this branch's older states of files main maintains. Run against main's code,
tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have
been built from two generations of its sources. So that the merge cannot break what main builds and tests:
- runtime/ is main's, file for file (68 files only this branch had are not carried over);
- every file under tools/, tests/ and docs/ that both sides have is main's (80 files);
- ten translator tests only this branch has, which test rules main's translator does not have, and their
fixtures are left out.
What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1,
play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven
notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and
the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia.
Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the
line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own.
Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the
branch's), CI.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With --wave64-emulate, rdna2spirv.compute_halves now runs tools/wave64_halves.py
on every wave64 CS/MS and keeps the workgroup-memory emulation for tier C. Tiers
A and B run natively, one console half per subgroup:
- the thread index is relabelled from the subgroup (SubgroupId * SubgroupSize +
SubgroupLocalInvocationId), so a subgroup holds threads 32k..32k+31 whatever
order the host gives; it feeds v0..v2, a mesh shader's v5 / s3, the lane and
the mesh export slot;
- an LDS access after a conflicting one of the wave (RAW / WAR / WAW, which the
console's lockstep ordered with no barrier) and a scalar load after a store
get a workgroup barrier in front, in blocks every invocation runs;
- with no memory write at all, s_barrier is left out;
- the index entry gets wave64_compute (+ reasons / idioms) and subgroup_size 32.
--wave64-emulate-all keeps the old behaviour (module flag WAVE64_TIERS).
The analysis learns the compute rules (exact lane id, the first lane's wave base
of D + lane, one-half EXEC regions, barrier and memory-order checks, group
size) and, for every stage, forms after VIctory's exact idioms: loads from
uniform addresses, all-or-none masks (s_cselect_b64 exec / 0 and their mixes),
uniform compares under a narrowed EXEC where no running half has it empty,
stale scalars only across a vote edge the read does not depend on, the
s_andn2_wrexec waterfall and loads through the waterfall descriptor.
tests/semantic: test_wave64_compute_tiers.py (fixtures cs_w64_half_local,
cs_w64_lds_swap, ms_w64_skeleton; native modules at 32 and 64 lanes, shuffled
placement, subgroups run one after another; negative controls) and
test_wave64_halves_victory.py; spirv_mini_interp gains OpUDiv / OpUMod and
run_workgroup(subgroup_order=...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
run_workgroup runs one generator per invocation over the same SPIR-V text, and each one split and regex-matched every line again. The parsed lines are now cached by text (a line that does not parse still raises where it is reached). test_saveexec_b64 40.9 s -> 24.5 s, test_wave64_scmp_masks 38.2 s -> 19.9 s; the 366 semantic test files give the same results.
Both interpreters accept OpTypeInt 64 but treated a 64-bit operand of
OpBitCount, SMin, SMax, SClamp, SAbs, FindILsb, FindUMsb and FindSMsb as
32-bit: OpBitCount of 0xFFFFFFFF00000000 gave 0, and SMin(2^31, 1) on a
64-bit type gave 2^31.
OpBitCount now counts every bit of its operand's type, and SMin, SMax,
SClamp and SAbs read their operands as signed at the width of their type.
FindILsb, FindUMsb and FindSMsb raise UnsupportedConstruct for a type that
is not 32-bit, since GLSL.std.450 limits them to 32-bit components. Results
for 32-bit types are unchanged.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
test_float_ordered_unordered_and_classify only used (2, NaN) and (2, 3), so an
interpreter that dropped the equality part of OpFUnordEqual (or of any
*Equal / *LessThanEqual / *GreaterThanEqual compare) still passed, as noted in
review on #262. Add 2 vs 2 for all twelve ordered/unordered compares, and
-0.0 vs +0.0 for the equality ones.
spirv_mini_interp keeps PhysicalStorageBuffer memory as a flat {byte address: 32-bit word} map, but OpLoad and
OpStore on a PSB pointer used it for any type and address: an OpLoad %ulong gave only the low word, a float or
64-bit store wrote one non-word entry, and a load at an address that is not 4-byte aligned (undefined under the
translator's Aligned 4) read 0, or whatever a test seeded at that byte key. They now raise UnsupportedConstruct,
as the atomics on the same memory already did for non-32-bit types. The translator emits only %uint PSB accesses
on dword-aligned pointers, so no current result changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bits_f32/f32_bits went through struct's binary32 <-> double conversion,
which quiets a signalling NaN (sets bit 22). Any word in
0x7f800001..0x7fbfffff or 0xff800001..0xffbfffff that passed through a
float (an OpBitcast round trip, or an integer exported through a float
output) came back changed, although OpBitcast is bit-exact in SPIR-V.
About 0.4% of random words hit it, so seeded tests failed by chance:
test_alu_shift_b64's v_ashrrev_i64 case and test_mem_diff's s_load
family both fail on main.
A float made by OpBitcast is now a float subclass that keeps its exact
pattern; copies, composites, selects, variables and outputs pass it on,
and arithmetic returns a plain float, which drops it (SPIR-V leaves NaN
result bits open). Tests cover four sNaN words through every pass-through
path, OpIsNan/OpFOrdEqual on one, and that arithmetic still gives a NaN.
Fixes#509.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Floor/Ceil/Trunc/RoundEven on a vector operand (the translator emits a
%v2float Floor/Ceil) went to math.isfinite with a tuple and raised TypeError;
map them over the components instead (review on #392).
The guard added in #346 checked the operand's value against the 32-bit
mask. 64-bit integers are stored unsigned, so a signed 64-bit 2**31 (or an
unsigned 64-bit 1) passed it, and OpConvertSToF then gave 2147483648 the
wrong sign through _s32(). Check the operand's type through id_type/types,
as sval() does, and keep the value check for operands with no known type.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/mem_diff.py runs seeded s_load, s_buffer_load, buffer load/store/atomic and global load/store programs through a small reference model written from the RDNA2 addressing rules and through the translation in spirv_mini_interp, and compares the exported words and the whole final memory. Accesses are generated in bounds; OOB, OOB_SELECT, swizzle and the s_buffer_load truncation are left for GPU-confirmed rules.
spirv_mini_interp gains OpSConvert and 32-bit PhysicalStorageBuffer atomics (spec semantics, one invocation), with tests.
The fuzzer found the global_* negative-offset bug that #421 fixes; its global family and tests/test_mem_diff.py's regression test pass once #421 is in.
AI-assisted.
spirv_mini_interp.py had no GLSL.std.450 Floor, Ceil or Trunc, so v_floor,
v_ceil and v_trunc (f32 and f16) stopped with UnsupportedConstruct. Add them
next to RoundEven. An integral result now keeps the operand's sign (IEEE 754
roundToIntegral): RoundEven(-0.4) used to give +0.0.
tests/semantic/test_alu_rounding.py checks the four ops in f32 and f16
against a plain-Python reference (edge values, seeded values, the kept f16
high half, op_sel). test_interp.py tests the ExtInsts directly.
The live OpConvertUToF/OpConvertSToF branch masked operands wider than 32 bits, and the branch with the strict check was unreachable because it came after it. Move the guard into the live branch and delete the dead one. Also delete a dead FMax branch shadowed by the earlier FMax/FClamp branch.
Add test_interp.test_wide_integer_conversion_is_rejected using synthetic 64-bit constants; it fails on unmodified main and passes with the fix.
New TEST item claimed in #156. AI-assisted (OpenCode).
spirv_mini_interp.py had the ordered float compares and OpFUnordNotEqual only,
so v_cmp_lg/nlt/ngt/nle/nge could not run, and neither could the
OpIsNan/OpIsInf checks in v_cvt_pkrtz. It now has OpFOrdNotEqual, every
OpFUnord* compare, OpIsNan and OpIsInf: an ordered compare is false and an
unordered one true when either operand is NaN.
test_float_compares.py checks v_cmp_{lt,le,gt,ge,eq,lg,neq,nlt,ngt,nle,nge} for
f32 (e32 and e64) and f16 (with high-half noise) on 0, -0, +-1, 2.5, +-inf and
NaN against Python's own comparison, plus e64 neg/abs source modifiers.
test_interp.py tests the new ops directly.
spirv_mini_interp.py had neither, so the translations of v_bfrev_b32,
s_brev_b32 and s_abs_i32 could not run. OpBitReverse reverses the bits at the
result's width. SAbs wraps the most negative value to itself, as s_abs_i32
does on the hardware.
test_alu_bitrev_abs.py checks v_bfrev_b32 and s_brev_b32 (and that two
reverses give the input back), and s_abs_i32 with its SCC, including
0x80000000. test_interp.py tests both ops directly.
spirv_mini_interp.py had OpISubBorrow but no OpIAddCarry, so no carry-out add
(v_add_co_u32, v_add_co_ci_u32, s_add_u32, s_addc_u32) could be run.
test_carry_chain.py checks the result and carry-out of v_add_co_u32,
v_sub_co_u32, v_subrev_co_u32 and their _co_ci forms (e32 through VCC, e64
through SGPRs), and of s_add_u32/s_addc_u32 and s_sub_u32/s_subb_u32 through
SCC, at the carry and borrow boundaries. It also checks the 64-bit add and
subtract built from each pair. test_interp.py tests OpIAddCarry directly.
spirv_mini_interp.py had OpULessThan, OpUGreaterThanEqual and a 32-bit
OpSLessThan only, so most v_cmp_* and s_cmp_* translations could not run. It
now has OpULessThanEqual, OpUGreaterThan and the four signed orderings, and
reads a signed operand at the width of its type, so a 64-bit compare is not
cut to 32 bits.
test_int_compares.py checks v_cmp_{eq,ne,lt,le,gt,ge} for u16/i16/u32/i32
(e32 and e64) and u64/i64, s_cmp_{eq,lg,lt,le,gt,ge} for u32/i32, and
s_cmp_{eq,lg}_u64 at sign and width boundaries against Python's own
comparison. test_interp.py tests the new ops directly.
GFX10 format names list the channel widths from the top bit, so 2_10_10_10
(50) is R10G10B10A2 and 10_10_10_2 (44) has a 2-bit x. FORMATS read them
from bit 0, which swapped the two for typed buffer loads and stores.
cs_store now writes its R10G10B10A2 word through 50. cs_fmt_1010102 covers
both formats; to run it, buffer_load_format masks a shift that was 32 for
aligned elements, and the test interpreter gains the conversions it needs.
v_perm_b32 returned 0x00 for selectors 8-11. Per the RDNA ISa BYTE_PERMUTE
they give 0xff when bit 7 of byte 1, 3, 5 or 7 of {src0, src1} is set. Each
byte pick also shifted both sources by up to 56 bits (undefined in SPIR-V,
the select kept the right one); the shift is now (sel & 3) * 8 on the source
chosen by sel < 4.
New test shaders, checked on the GPU (check.py, run_gpu_tests.py) and in
tests/semantic with expected words derived from the ISA:
- ps_ops7: v_perm_b32 (byte picks, 0x00/0xff, sign selectors), v_alignbit_b32
with a shift of 36, v_med3_i32 vs v_med3_u32.
- ps_ops8: v_mul_hi_u32/i32, v_bcnt_u32_b32, v_ffbl_b32, v_ffbh_u32 (of 0),
v_xad_u32, v_add3_u32.
The semantic interpreter gains OpUMulExtended/OpSMulExtended,
OpUGreaterThanEqual and GLSL FindILsb, FindUMsb, UMax, SMin, UClamp, SClamp,
with direct tests; the unsupported-ext example moves from FindUMsb to Ldexp.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port the #78 value-level cases (ps_ops5, ps_ops6, ps_vcc_x2, ps_flat,
cs_bounds) onto main's semantic suite. Keep main's ps_ops4/ps_legacy_mul
coverage and forward-only execution contract, and extend the mini
interpreter with 64-bit integers, Input/PushConstant seeding, physical
storage buffer memory, OpBranch/OpPhi at forward merges, and the opcodes
the new fixtures use.
Add tests/semantic: translate two hand-written, branch-free pixel shaders
(ps_sdwa, ps_ops) and execute the resulting SPIR-V with a small strict
interpreter, asserting every mrt0 word against hand-derived expectations.
Catches wrong-value regressions (SDWA selects/sext, min3/max3, bfe_i32,
packed f16 FMA) that spirv-val cannot.
- Standard library only; no LLVM, SPIRV-Tools, GPU or game files.
- Interpreter rejects unmodelled constructs instead of approximating.
- Negative controls sabotage translated output; mutation tests sabotage a
temporary copy of tools/ and require the matching test to fail.
- Fixtures are generated from runtime/test/shaders/*.asm.
- CI job semantic-tests (Windows + Ubuntu, Python 3.12), discovery limited
to tests/semantic.