Commit Graph

46 Commits

Author SHA1 Message Date
00131bb85e main keeps its own runtime, tools and tests; the branch's variants stay on port/d3d12-nvidia
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>
2026-11-27 17:58:38 -05:00
2269728203 translator: emulate only tier C wave64 compute and mesh shaders (SHADER-10)
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>
2026-11-25 22:14:29 -05:00
b8956e4f3b tests: execute a mesh shader's exp prim and GS_ALLOC_REQ translation in the interpreter
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.
2026-11-24 01:06:22 +03:00
ea2cf30165 tests/semantic: pin the interpreter's created NaN so a regression shows on x86 hosts too (#4100)
Squash-merged after review of PR #4100 - tests/semantic: pin the interpreter's created NaN so a regression shows on x86 hosts too
2026-11-23 08:12:25 -06:00
5769573cec Merge pull request #4513 from tedin7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:26 -05:00
332efe1a94 Merge pull request #4172 from leather147
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:12:00 -05:00
b595ca11bb Merge pull request #4122 from leather147
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:11:30 -05:00
b6a1a6a7ca Merge pull request #3891 from lumenpearson
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:09:16 -05:00
005ba67c55 Merge pull request #3508 from shdann
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:07:36 -05:00
49431d4519 Merge pull request #3444 from shdann
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:07:29 -05:00
0600822f83 Check operand widths for signed and bit-search GLSL operations
AI-assisted.
2026-11-23 05:30:53 +03:00
26a0911f25 Reject duplicate OpPhi results and identify the incoming edge
AI-assisted.
2026-11-23 05:30:46 +03:00
aa8a986867 tests/semantic: the mini interpreter parses a module once, not once per invocation
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.
2026-11-23 02:57:11 +01:00
ea291b12b2 tests: preserve binary64 for SPIR-V negate and absolute value 2026-11-23 02:45:13 +03:00
5fbadea3a0 tests: preserve binary64 in SPIR-V int-to-float conversions 2026-11-23 02:30:13 +03:00
81a428ecd0 tests: preserve SPIR-V aggregate value copies (TEST-851) 2026-11-23 01:18:22 +03:00
b168216aba Merge pull request #3508 from shdann 2026-11-22 17:02:24 -05:00
829af7fd6a tests/semantic: the interpreters run OpBitCount and the signed GLSL ops at the width of a 64-bit type
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>
2026-11-22 23:44:12 +03:00
0312e4df3e tests/semantic: the mini interpreter gives the OpPhi of a block their values together
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>
2026-11-22 23:32:44 +03:00
db22624418 tests/semantic: float compares with equal operands
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.
2026-11-22 00:15:38 -03:00
2e8101baa5 tests/semantic: PSB loads and stores in the mini interpreter are one aligned 32-bit word
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>
2026-11-21 22:41:59 -03:00
014e6e05ca Merge pull request #533 from bbareth 2026-11-21 19:53:10 -05:00
97fda697a6 Merge pull request #515 from VictorJulianiR 2026-11-21 19:53:06 -05:00
a7d325b6e6 Merge pull request #392 from Luiz Neves 2026-11-21 19:43:26 -05:00
3fe9203fc6 tests/semantic: OpBitcast keeps signalling-NaN bits in the mini interpreter (TEST-67)
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>
2026-11-22 01:31:20 +01:00
796a317aac Merge origin/main into interp-floor-ceil-trunc; round vector operands per component
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).
2026-11-21 21:17:34 -03:00
119d3084fd Merge pull request #442 from Spaghetih
# Conflicts:
#	docs/shader_validation.md
2026-11-21 19:14:05 -05:00
42ef9ff0ac tests/semantic: reject 64-bit operands of OpConvertUToF/SToF by type width
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>
2026-11-21 21:13:34 -03:00
d9e629288a FUZZ-5: memory differential fuzzer (tools/mem_diff.py)
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.
2026-11-22 00:52:32 +01:00
18e10d95f2 Merge pull request #346 from Rayhan Robin 2026-11-21 18:37:57 -05:00
8af93abab3 tests/semantic: run Floor/Ceil/Trunc in the interpreter, and test v_floor/ceil/trunc/rndne
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.
2026-11-21 20:30:29 -03:00
3c2f2455d3 Merge origin/main into interp-float-compares 2026-11-21 20:24:44 -03:00
1956790d84 Tests: enforce strict integer width in mini SPIR-V interpreter
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).
2026-11-21 17:09:17 -06:00
63ae33a3cf Merge pull request #252 from Luiz Neves
# Conflicts:
#	tests/semantic/spirv_mini_interp.py
#	tests/semantic/test_interp.py
2026-11-21 17:08:47 -05:00
78bac0ead5 Merge pull request #235 from shuv-amp
# Conflicts:
#	tests/semantic/regen_fixtures.py
#	tests/semantic/spirv_mini_interp.py
2026-11-21 17:08:27 -05:00
f2fead895a tests/semantic: run unordered float compares in the interpreter, and test v_cmp_*_f32/f16
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.
2026-11-21 19:08:00 -03:00
919599b17c Merge pull request #256 from Luiz Neves 2026-11-21 17:07:37 -05:00
5a3aa74e3e Merge pull request #250 from Luiz Neves 2026-11-21 17:07:37 -05:00
6440281767 tests/semantic: run OpBitReverse and SAbs in the interpreter, and test bfrev/brev/abs
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.
2026-11-21 19:06:11 -03:00
73c99273a8 tests/semantic: run OpIAddCarry in the interpreter, and test the carry chain
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.
2026-11-21 19:02:04 -03:00
058170f6e0 tests/semantic: run integer compares in the interpreter, and test v_cmp/s_cmp
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.
2026-11-21 19:00:46 -03:00
0532026c35 Translator: 10:10:10:2 buffer formats had x and w swapped
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.
2026-11-22 03:28:27 +05:45
48adc7b9a5 Translator: v_perm_b32 sign selectors 8-11; integer ALU tests ps_ops7/ps_ops8
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>
2026-11-21 22:33:25 +01:00
af08a9e696 tests: rebase semantic value coverage onto current main
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.
2026-11-21 19:56:24 +00:00
5f3007f393 tests/semantic: cover ps_ops2, ps_ops3, ps_ops4 and ps_legacy_mul (+ check.py) 2026-11-21 15:05:54 -03:00
695ae01d21 tests: value-level regression tests for RDNA2 -> SPIR-V pixel shaders
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.
2026-11-21 18:27:51 +02:00