docs/design.md narrowed the f16 of a typed d16 buffer load from the f32 decode with round to nearest even, and called that rounding inferred, not measured. tools/d16_format_probe.py measures it through tools/hw_oracle: every UNORM8, SNORM8, UNORM10, UNORM16 and SNORM16 value through buffer_load_format_d16_x, tbuffer_load_format_d16_x and buffer_load_format_x, in wave32 and wave64, against several candidate rules, with a 16_FLOAT load, the kept high half of d16_x and the staged inputs as controls. On an RX 6700 (gfx1031) the hardware rounds the exact quotient once, straight to f16. Rounding to f32 first is 1 ulp high on exactly four values (UNORM16 0xffaf and 0xffef, SNORM16 0x7ff7 and 0x8009); over every width up to 16 bits only two f32 quotients land on an f16 halfway point (0x3f7ff000, 0x3f7fb000). Gen.d16_norm_f16 takes the f16 below for those two, for normalized formats only. The f32 (non-d16) result was already right. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Translator regression tests
Standard library only; no GPU, no LLVM, no SPIRV-Tools, no game files.
python -m unittest discover -s tests/semantic -v
What they check (tools/rdna2spirv.py, pixel shaders plus one compute shader):
test_ps_semantics.pytranslatesps_sdwa,ps_ops,ps_ops2,ps_ops3,ps_ops4andps_legacy_muland executes the SPIR-V withspirv_mini_interp.py, then compares everymrt0word with the expected value. Each shader exports four 32-bit words, so six shaders give 24 asserted values. The expected words are written down by hand, with the ISA rules in the module docstring, and are cross-checked against plain-Python reference calculations.test_value_semantics.pydoes the same for the recent value-level fixes: scalar b16 shifts, packed b16 shifts withop_sel,v_add_nc_u16,v_sin_f16/v_cos_f16,s_buffer_load_dwordx2into VCC and flatv_interp_movinput next to an interpolated one.ps_ops5,ps_ops6,ps_vcc_x2andps_flatgive 16 more asserted values, andps_fma_literal4 more: which operand the literal K multiplies inv_fmamk/fmaak/madmk/madak_f32, andps_f16_vop2(f16 VOP2 partial writes andv_fmac_f16, words measured on RDNA2 hardware) four more. The otherps_f16_*shaders use GLSL functions this interpreter does not model;tests/test_f16_hw_words.pyruns all of them withtests/spirv_interp.py.cs_boundsruns as compute and asserts the four dwords in its buffer after in-bounds load/store and out-of-bounds load/store attempts (the V# has num_records 16).ps_ops4andps_legacy_mulare also asserted there, duplicating the matchingtest_ps_semantics.pycases. As above, constants are written by hand and recomputed by plain-Python references checked against each other.cs_fmt_1010102runs as compute too and asserts 16 dwords: 10:10:10:2 words read through formats 50 and 44 (from the V# and from tbuffer's own format) and stored in both.ps_scc_minmaxasserts SCC afters_min/s_max_i32/_u32: 0 on a tie, and 1 on a pair (-1 against 1) that only the right signedness orders that way.RawBufferTailBoundsruns one-thread compute programs written in the test around onebuffer_loadand asserts the words and the exact addresses loaded for the raw-buffer rule measured on an RX 6800 (per-dwordnum_recordscheck on the exact byte offset);MeasuredBoundsShadersruns the four GPU tests of the SMEM and raw MUBUF rules (cs_smem_bounds,cs_smem_stride_align,cs_smem_sload_neg,cs_buf_tail).test_buffer_oob_select.pyruns 33 hand-tabulated MUBUF cases through the translator and the interpreter, loads and stores, each with a literal and a run-time V#: the first-byte bound of every OOB_SELECT mode (the RDNA2 rules of docs/buffer_bounds.md, docs/design.md Buffer bounds checking).test_buffer_swizzle.pyruns hand-worked MUBUF cases for swizzled V#s (SWIZZLE_ENABLE) and ADD_TID_ENABLE, the RDNA2 ISA's swizzled buffer_offset and its OOB_SELECT 3 rule (docs/design.md Swizzled buffer addressing): the exact addresses loaded and stored for dword, multi-dword and typed accesses, each with a literal and a run-time V#, and the GPU fixturecs_buf_swizzleon 64 threads.test_scalar_mem_smem.pyruns the codeGen.scalar_loademits with its own small evaluator (64-bit addresses, forward selection constructs) and asserts the SGPR values and the addresses read, including the measured SMEM truncation,s_buffer_loadNUM_RECORDSbound and signeds_loadimmediate.test_alu_movrel.pyruns hand-written listings forv_movrels_b32,v_movreld_b32andv_movrelsd_b32(10 cases): sentinels in v1..v8, M0 set bys_mov_b32, then the indexed register and its neighbours are exported, so a write must land only inVGPR[D.addr + M0]. A plain-Python register-file model checks the hand-written constants.v_movrelsd_2_b32is covered bytest_alu_movrelsd_2.py.test_andn2_exec_b64.pyrunss_andn2_saveexec_b64ands_andn2_wrexec_b64on all 64 lanes of a wave64 (12 pairs of S0 and EXEC for each): every lane stores whether the instruction left it on, and lane 0 stores SCC and the population count and lowest lane of D, against the ISA's two lines written as integers. Results in the low half only, the high half only, both and neither are all in the table. It also runs the GPU testcs_w64x_andn2_exec.test_saveexec_b64.pydoes the same fors_and_saveexec_b64,s_or_saveexec_b64,s_andn2_saveexec_b64ands_andn2_wrexec_b64with S0 a compare result in VCC or in an SGPR pair (13 pairs of S0 and EXEC for each op and source), and runs the GPU testcs_w64x_saveexec_b64.spirv_wave_interp.pyruns every invocation of one subgroup at once through structured control flow (split at a selection, rejoin at its merge, loops until no invocation is left) with the subgroup operations the translator emits. It is the SPIR-V side oftools/cf_diff.py(FUZZ-8);test_spirv_wave_interp.pypins its convergence rules on hand-written modules.test_global_mem_offset.pyruns the address arithmeticglobal_load*/global_store*emit (its own small evaluator, since the interpreter refuses 64-bit integers and PhysicalStorageBuffer) and asserts the address accessed for the signed 12-bit instruction offset (-4, -2048, 2047, 0) in both addressing modes.test_float_nan_fract.pyruns float min/max/min3/max3/med3 with a quiet NaN andv_fractnext to 1.0 (f32 and f16) with inputs from memory, and the GPU fixturesps_fnan_med3andps_fnan_fract; the expected words were measured on an AMD Radeon RX 6800 (gfx1030). A NaN result is asserted as "a NaN", not by its bits.test_rule_gpu_fixtures.pyruns the GPU fixtures for thedocs/design.mdrules that used to be CPU-only (TEST-175:v_cmp(x)_nlg,v_cvt_off_f32_i4, thev_fmac_f16/v_interp_p2/mov_f32output modifiers and VOP3 modifiers on constants) through the interpreter, and checks that the words each.asmheader derives are the onescheck.pyandscripts/run_gpu_tests.pyexpect. The two interp fixtures get the constants their vertex shader,vs_interp_consts, exports.test_vcmpx_forms.pyruns the 14v_cmpxforms that had no test (eq/gt/le/lt/ngt/nle_f32,f_i32,t_u32,eq/gt/le_i64,ge/lt/ne_u64) in both encodings: each on a table of operands (NaN, signed zeros, infinities; 64-bit values that only one word or the sign tells apart), where the pixel must survive exactly when Python's comparison of the operands holds, and on a 16-lane wave with one lane switched off beforehand, where the lanes left running and an untouched VCC are checked. It also runs the GPU testps_vcmpx_formsand re-derives its four words.test_image_bvh_tri.pyrunsimage_bvh64_intersect_rayon hand-built triangle nodes. It checks the vertex slots of each node type (TRI0–TRI3) and every selector of the barycentric remap byte at +60, against weights written by hand and a plain-Python solve (docs/design.md, Ray tracing row).test_interp.pytests the interpreter against the SPIR-V / GLSL.std.450 definitions. The interpreter raisesUnsupportedConstructfor anything it does not model instead of approximating it. It can seed Input variables, PushConstant words and a flat physical-address memory map for the tests above.test_wave64_cross_half.pytranslates the GPU testscs_w64x_readlane,cs_w64x_writelaneandcs_w64x_bpermute(no--wave64-emulate) and runs all 64 lanes in lockstep withspirv_mini_interp.run_workgroup. On one 64-wide subgroup the 24 words must equal the GPU check's values (runtime/test/shaders/check.py). On two 32-wide subgroups (NVIDIA without emulation)ds_bpermutestays exact,v_writelanewrites stay exact, and av_readlanefrom the other half is a shuffle from lane >= 32, undefined in SPIR-V (UndefinedResult); a "lane mod 32" model of issue #94 gives the words a 32-wide GPU shows (all 24 matched on an RTX 4070 SUPER, driver 610.88, without--wave64-emulate). Two SPIR-V sabotages (readlane lane & 31, bpermute without its half base) must change the 64-wide result.test_wave64_subgroup_ops.pyruns eight more wave64 GPU tests the same way (cs_w64x_ballot,_readfirstlane,_load_ballot_load,_partial,cs_wave64_ballot,cs_wm_bfm64,cs_wm_half_cmp,cs_wavemask): on one 64-wide subgroup every word equals the GPU check; on two 32-wide subgroups the words pinned there are the ones an RTX 4070 SUPER (driver 610.88) wrote without--wave64-emulate. The cs_w64x tests with branches need llvm-mc encodings and are not covered.test_alu_int_misc.pytranslates one-instruction synthetic listings forv_bfm_b32,v_and_or_b32,v_add_lshl_u32,v_lshl_or_b32,v_mad_i32_i24andv_mul_lo_u32and checks the mrt0 word against hand-computed ISA values (masked shift counts, wrapping adds/products, 24-bit sign extension).test_negative_controls.pysabotages the translated SPIR-V text and requires the result to change.test_mutations.pysabotages a temporary copy oftools/(13 regressions across SDWA, min3/max3,v_bfe_i32,v_pk_fma_f16,v_fma_f16 op_sel,v_subrev_co_ci_u32,v_cmpx_eq_u64,v_mul_i32_i24,v_ffbh_i32,v_pk_lshlrev_b16,v_sin_f16andv_mul_legacy_f32) and requirestest_ps_semantics.pyto fail for the matching shader.test_f32_valu.pyrunsps_f32_mods(v_mac_f32rounds the product before the add; VOP3 clamp and output modifiers onv_cvt_f32_ubyte*/u32/f16andv_rcp_iflag_f32), found bytools/f32_fuzz.py(FUZZ-3), and tests the interpreter's float operations against GLSL.std.450 (signed zeros, undefined inputs, a single-roundingFma).test_fixtures.pycheckstests/semantic/fixtures/disasm/*.sequals whatregen_fixtures.pymakes fromruntime/test/shaders/*.asm(python tests/semantic/regen_fixtures.pyrewrites them).
Limits: single lane (or lanes in lockstep, one instruction per lane per round, that exchange values only through
OpGroupNonUniformShuffle, Ballot, Any, All and BitwiseOr Reduce), forward-only structured control flow (the fragment-exit discard test and the compute
dynamic-bounds merge; no backward branches, loops, calls or switches), no texture access. PushConstant words,
Input variables and a flat physical-address {address: word} map can be supplied per run. A shift by at least the bit width is an undefined value: arithmetic on it stays
undefined and any other use (store, branch or select condition, shuffle, output) raises. Values that pass
through a float op lose NaN payloads (Python floats), so expected output words avoid NaN bit patterns; a
signalling NaN read back through OpBitcast comes out quieted. Fma and OpFmaKHR (SPV_KHR_fma, --fma khr) are exact: the product and sum are rationals,
rounded once to binary32. Exp2/Log2/Sqrt/InverseSqrt are correctly rounded (Vulkan allows a few ULP), and
inputs GLSL.std.450 or SPIR-V leave undefined (Log2 of x <= 0, OpFDiv by zero, FMax of NaN...) raise
UnsupportedConstruct. Fract is
computed exactly and rounded once to binary32. NMin/NMax give the other operand for a NaN, and they and
FMin/FMax/FClamp order -0 below +0 (the order RDNA2 hardware uses). The .asm
sources are written for llvm-mc -mcpu=gfx1013; these tests do not assemble them, so assembler syntax is not
checked here.
To add a shader: put the .asm in runtime/test/shaders/, add it to SHADERS in regen_fixtures.py, regenerate,
and add its expected words (with derivation) to the matching test file.