design.md had no measured rule for the no-format-conversion image loads.
Measured natively on an RDNA2 iGPU (gfx1036) through tools/hw_oracle: the
texel's bytes form little-endian dwords selected by dmask (0 past the last),
a texel under 4 bytes is zero-extended (pck) or sign-extended from its top
bit (pck_sgn), and the FORMAT's numeric type does not matter.
image_fuzz.py gets --op image_load_pck|image_load_pck_sgn for the hw oracle,
the pck_oracle CPU model, sub-4-byte texel formats, a pck_sgn_zero_extend
perturbation and a wrong-FORMAT control that changes the texel size;
tests/test_image_fuzz_hw.py pins the measured words. The translator does not
translate these ops yet; this is the measured model it needs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RAL8MMXUuNpQAVa1iiyAMP
Oliwettoo's Linux check of #342 caught test_is_msvc_recognizes_cl_variants
failing off Windows: os.path.basename does not split on backslash there.
Normalize separators in _is_msvc so a Windows-style path is recognized on
every host.
GFX12 dropped v_cmp_{t,f}_{i32,u32,i64,u64} and their v_cmpx_ forms: AMD LLVM 23
(rocm-sdk-core 10.0.0) assembles all sixteen for gfx1036, gfx1100 and gfx1150 and rejects
every one for gfx1201. wint_diff emits v_cmp_t_u32 and v_cmp_f_i32 (and the v_cmpx_ forms),
so on an RX 9070 XT those programs were counted as "assembler rejected", and the whole batch
carried the first error's text: on main all 69 skips of seed 1 read "... v_cmp_t_u32",
including the programs that only use v_cmp_f_i32.
- tools/hw_oracle/asm.py: GFX12_VALU_REMOVED lists the sixteen. valu_skip_reason() names
them on gfx12xx (and ignores an _e32/_e64 suffix); program_skip_reason() returns the
first such reason of a program's lines. The GFX10.1-only mads are unchanged.
- tools/wint_diff.py: hw_results() sends only the programs the GPU can run; the others get
their reason and are never assembled. The run and the shrinker both use it.
- Tests: the sixteen, the suffixes, gfx1013/1036/1100/1150 unchanged, and hw_results with a
fake oracle (gfx1201 assembles only the program it can run; gfx1036/1150 run all four).
RX 9070 XT, `wint_diff.py --oracle hw --programs 500 --wave both`: seeds 1 and 2 give the
same 431 / 426 passes and 69 / 74 skips as main, 0 mismatch; the skips now read v_cmp_f_i32
29, v_cmp_t_u32 25, v_cmpx_f_i32 8, v_cmpx_t_u32 7 (seed 1) and 25 / 25 / 12 / 12 (seed 2).
gfx1036: 500/500 on both seeds, as on main.
AI-assisted (Claude Code).
(cherry picked from commit 32a9427ba4)
DrmOracle.__init__ and Oracle.__init__ create a temporary workdir and then
can raise Unavailable (a skipped probe, exit 77). close() is never reached
for an object whose constructor raised, so every skipped run left a
leonida-hw-oracle-* directory in the temp dir.
Remove the directory when the constructor made it and then fails. A
caller-supplied workdir is left alone. tests/test_hw_oracle_workdir_leak.py
covers the early, late and caller-supplied cases with no GPU or libdrm.
Why merged: indented SALU lines are now parsed for literals and removed opcodes.
Why it's good: security-reviewed; tested on Windows 11 merged onto main c023a36: the new regression test fails on main and passes here; test_hw_oracle's 59 tests still pass.
AI-assisted (Claude Code, Claude Opus 5.5).
asm.rdna23_skip_reason refused every family of valu_fuzz.py and lds_fuzz.py
on gfx1170+ with "the kernels here do not assemble for it" (fef61b247), which
is false for most of what they emit. Checked by assembling what the
generators produce with AMD clang 23 (300 programs per wave size each):
- lds_fuzz assembles clean for gfx1150, gfx1170 and gfx1201 and runs there:
on an RX 9070 (gfx1201, RADV/Mesa 26.2.6, the Linux DRM launcher) the
default --oracle hw run gives wave32 500/500 match, wave64 250 match plus
250 skipped for the committed wave64 bpermute reason, 0 mismatch,
0 rejected. The blanket gate is gone; the per-program hw_skip_reason is
the mechanism.
- valu_fuzz --family f16 assembles clean for gfx1150, gfx1170 and gfx1201
(its op_sel lines are respelled by the runner's asm.opsel16_spelling
there, which the assemble test now applies as well): 500 programs (1,000
kernels, both wave sizes) 1,000/1,000 match, 0 rejected, and the negative
control catches all six wrong models.
- valu_fuzz --family mem assembles clean for gfx1150 AND gfx1170 (every op
kind, 0 of 600 kernels rejected per arch) but genuinely cannot on gfx12xx:
GFX12 has no s_waitcnt_vscnt ("instruction not supported on this GPU")
and rejects every buffer_load/store_b32/b64/b96/b128 form the generator
writes ("operands are not valid for this GPU or mode"). The new
hw_family_skip_reason refuses exactly that, naming both rejects, and
--family mem --oracle hw exits 77 with them on gfx1201.
Running the lds hardware suite un-skipped on gfx1201 found one more
difference: a wave64 ds_permute_b32 reaches all 64 lanes on GFX12, like
ds_bpermute_b32. Measured on the RX 9070: every lane sending to lane
(l + 32) & 63 delivers its value to lane l ^ 32, all 64 lanes, with
lane-to-itself sending as the control; a masked wave64 ds_swizzle keeps
its halves there (0 mismatches in a 40-program --swizzle-exec run). Those
programs are skipped on gfx12xx now too, and the new perturbation
permute_wave64_cross models the crossing: under it every wave64 program
that runs in the --extended seed-1 run matches (23 of 40, 0 mismatch). The
lds negative control on gfx1201 reports the two wave64_cross perturbations
as not detected -- on GFX12 they are the measured behaviour, so the canary
cannot trip there; every other perturbation is caught.
asm.rdna23_skip_reason stays for the OnHardware guards of f32_fuzz and
f16_trans_sweep, whose MODE probes set IEEE and DX10_CLAMP, which gfx1170+
cannot encode (FUZZ-43); its docstring now says that instead of claiming
the fuzzers use it.
CPU: tests/test_valu_fuzz.py 88 OK, tests/test_lds_fuzz.py 37 OK,
tests/test_lds_fuzz_hw.py 44 OK (its OnHardware class runs on the RX 9070:
44 OK), tests/test_lds_fuzz_cli.py 8 OK, tests/test_hw_oracle.py 59 OK
(3 skips), tests/test_f32_fuzz.py 28 OK (1 skip), compileall clean,
scripts/check_no_game_data.py clean. The AMD-clang tests ran with
LEONIDA_AMD_CLANG=/opt/rocm/llvm/bin/clang. The semantic suite is
unchanged: its 47 failures (test_image_atomics_guard,
test_image_store_d16) are on the base commit too; nothing here touches
the translator.
AI-assisted (GLM-5.3).
hw_oracle_drm.c refused every compute engine but version 10, so on an
RX 9070 (gfx1201, engine 12.0) `f32_fuzz.py --oracle hw` could not run
at all: 'hardware oracle unavailable: compute engine 12.0: only version
10 (GFX10, RDNA1 and RDNA2) is supported'.
The registers the launcher writes sit at the same SH offsets on GFX10,
GFX11 and GFX12 — Mesa's register JSON and AMD's PAL offset headers
(gfx9_plus_merged_offset.h, gfx12_merged_offset.h) agree on them, and
PAL's gfx12CmdUtil.cpp still builds plain SET_SH_REG — so only the
preamble and the cu-mask writes branch:
- Engines 11 and 12 take the gfx11 init of libdrm's own dispatch test
(tests/amdgpu/shader_test_util.c, 2.4.115): REQ_CTRL on its own, the
four COMPUTE_USER_ACCUM registers, no CP_COHER_START_DELAY. The
checksum stays in the SH space, as PAL writes it on GFX11
(gfx9PipelineChunkCs.cpp): libdrm's gfx11 path sends it as UCONFIG
0x22a, which does not reach the register.
- The indexed COMPUTE_STATIC_THREAD_MGMT_SE0..3 writes stop at engine 11:
GFX12's SE masks reset to 0xffffffff (AMD's gfx12_merged_default.h) and
neither PAL nor RADV touches them there.
- arch_name covers the GC 11 and GC 12 families with Mesa's
ac_identify_chip and amdgpu_asic_addr.h ranges (NV4 also needs the IP
minor, for gfx1210; amd_family.c names GFX1156 gfx1153 too); a chip
only labelable by generation gets a representative, which drm.py maps
the way it already mapped gfx10xx. The engine-version check takes 10,
11 and 12; the gfx10 stream itself is unchanged.
drm.py's ELF and descriptor parsing needed nothing: the code-object-v5
layout it reads is generation-independent, and COMPUTE_PGM_RSRC2's
LDS_SIZE is bits 15..23 in 512-byte units on all three generations
(Mesa ac_binary.c). asm.py already documents GFX12 (b94733a04).
tests/test_hw_oracle.py: the device-line-to-arch mapping with the new
fallbacks, and a launcher build test that compiles hw_oracle_drm.c
exactly as drm.py does, wherever gcc and the libdrm_amdgpu headers are
installed and without a GPU.
Verified on hardware: the author's RX 9070 (gfx1201, engine 12.0,
Linux/RADV) ran --oracle hw over the five min/max/med3 ops, 583 f32
programs: 451 match, 0 mismatch, 2 known deviation, 0 assembler
rejections; a curated 39-program run before it matched on all 14 judged.
No RDNA3 hardware was dispatched — the gfx11 stream mirrors libdrm's
hw-proven gfx11 test. CPU: tests/test_hw_oracle.py 59 OK (3 skips),
tests/test_f32_fuzz.py 29 OK (1 skip), tests/test_f32_fuzz_gfx12.py
7 OK, compileall clean.
AI-assisted (GLM-5.3).
On an RX 9070 XT (gfx1201) `lds_fuzz.py --oracle hw` stopped with "the assembler rejected
every program in a chunk: ... s_barrier", and programs with a ds_cmpst were skipped because
ds_cmpstore's operand order was only measured on gfx1150.
- asm.sync_lines: GFX12 has no s_barrier, so a barrier is `s_barrier_signal -1` then
`s_barrier_wait -1`, and the LDS wait is `s_wait_dscnt 0` instead of the legacy
`s_waitcnt lgkmcnt(0)` encoding. lds_fuzz's hardware kernels go through it.
- asm.ds_line swaps ds_cmpstore[_rtn]_b32's data operands on GFX12 as on GFX11. Measured on
gfx1201: with 7 in the dword, data v1 = 9, v2 = 7 stores 9 and v1 = 7, v2 = 9 keeps 7, for
the rtn and the non-returning form (gfx1036's ds_cmpst does the opposite).
- Measured on the way: a wave64 ds_bpermute_b32 reaches all 64 lanes on GFX12, where RDNA2
and gfx1150 keep each 32-lane half separate (every lane asking for lane (l + 32) mod 64:
gfx1201 returns lane l ^ 32, gfx1036 lane l). The model describes RDNA2, so on gfx12xx a
wave64 program with a ds_bpermute is skipped with that reason; under
--perturb bpermute_wave64_cross all of them match.
RX 9070 XT, AMD 26.11.2, --programs 1000, seeds 1 and 2: wave32 1000/1000; wave64 537 and 506
match, 0 mismatch, the rest skipped for the bpermute reason. --perturb bpermute_wave64_cross:
wave64 1000/1000. --perturb cmpst_swap: 275 of 1000 wave32 programs mismatch. gfx1036
unchanged: 1000/1000 in both wave sizes and both seeds.
AI-assisted (Claude Code).
AMD LLVM 23 (rocm-sdk-core 10.0.0) rejects `v_max_u16_e64 v14, s12, v5 op_sel:[1,0,0]`
on gfx1100, gfx1150 and gfx1201 ("operands are not valid for this GPU or mode") and takes
`v_max_u16_e64 v14.l, s12, v5.l op_sel:[1,0,0]`. So `pk16_diff --oracle hw` skipped every
op_sel form of v_lshlrev/lshrrev/ashrrev_b16/i16, v_min/max_u16/i16 and v_mul_lo_u16 there:
80 of 200 programs on an RX 9070 XT.
asm.opsel16_spelling() writes each VGPR operand of those lines as the half its op_sel bit
picks and keeps the op_sel list for SGPR and constant sources. The runner applies it on
every non-gfx10 architecture, apart from the true16 probe: this assembler takes a bare
`v_cvt_f16_f32 v8, v1` on GFX11/12, so that probe says no.
All 2,551 distinct op_sel lines pk16_diff generates for the eight ops now assemble for
gfx1100, gfx1150 and gfx1201, with the same op_sel bits and operands as gfx1036's bare form.
RX 9070 XT: pk16_diff --oracle hw 200 programs 120 pass / 80 skipped -> 200 pass, 0 skipped;
2000 programs 2000 pass, 0 mismatch. gfx1036 unchanged (200/200, 2000/2000).
AI-assisted (Claude Code).
The libdrm launcher refused a kernel whose descriptor has a group segment
and capped its output at 4096 words, so lds_fuzz --oracle hw was exit 77
on Linux and no LDS program ran on RDNA2 outside Windows. Both are now
gone; docs/shader_validation.md records the gfx1036 counts.
- drm.py: program COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte
units) from the descriptor's group segment instead of refusing it. The
assembler leaves that field 0 (measured: 4096 bytes of LDS give group
4096 and rsrc2 0x84), so the launcher fills it as the HIP runtime does.
Only scratch memory (private) and COMPUTE_PGM_RSRC3 stay unsupported.
- hw_oracle_drm.c: the output buffer takes 1..16384 words, matching the
Windows launcher, so a 64x64 image_fuzz case (16384 words) fits.
- asm.py: a wrapped (non-raw) kernel's LDS goes into its descriptor too,
so the Linux launcher has a group segment to read.
- lds_fuzz.py: the "more than 4096 words" wording no longer applies.
Tests: test_hw_oracle.py gains a descriptor unit test (group segment to
LDS_SIZE, 65536 ceiling) and two OnHardware tests (a kernel that writes,
barriers and reads back LDS; 8192 words from 1024 threads), plus a check
that LDS reaches the descriptor and metadata of a wrapped kernel. Verified
on the integrated Radeon of a Ryzen 7 7700X (gfx1036, RDNA2, Linux
7.3.5-zen1-1-zen, libdrm 2.4.134, AMD clang 23.1.5): lds_fuzz --oracle hw
--programs 500 --seed 1 matches 0 of 1000 (wave32+wave64) mismatches,
image_fuzz --oracle hw --programs 120 --seed 1 0 of 120.
AI-assisted (OpenCode).
The rocm-sdk wheels put `amdclang` in the Python environment's Scripts (bin)
folder. find_clang() takes it first, because it is on PATH and lists the amdgcn
target, but ld.lld and amdgpu-arch sit beside the real clang, in the folder the
launcher reports as InstalledDir. With the wheels in a Python outside the
checkout the oracle then stopped with "no ld.lld next to the AMD clang", also
when HIP_PATH named a complete toolchain, and LEONIDA_AMD_CLANG was the only
way around it.
find_clang() now returns the clang in InstalledDir when the one it found has no
ld.lld beside it. A clang that has its linker is used where it was found, and a
launcher that names a folder without a clang is kept, so every setup that
worked resolves to the same compiler as before.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
build_command() returned `cmd.exe /d /c <full path of build_hw_oracle.cmd>`
for the vcvars toolchain. cmd.exe loses a full path's quotes when it holds
& or ^ (and list2cmdline adds none when there is no space), so from a work
folder such as `a & b`, `a&b` or `x^y` the script never ran and the oracle
reported that hw_oracle.c did not build. The only caller already runs the
command with cwd=self.workdir, the folder the script is written to, so it
now starts `.\build_hw_oracle.cmd`, which NoDefaultCurrentDirectoryInExePath
does not block either.
tests/test_hw_oracle.py runs the returned command on a stub vcvars from
plain, `sp (x)`, `a & b`, `a&b`, `x^y` and Turkish-named work folders with
that variable set, and the tests that read the script open it from the work
folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ds_line already converts ds_cmpst_rtn_b32 to ds_cmpstore_rtn_b32 and swaps the two data
operands, but the non-returning ds_cmpst_b32 was left as-is, and GFX11 has no such mnemonic.
Measured on gfx1100 that ds_cmpstore_b32 takes the value to store before the compare value.
amdgpu-arch prints 'gfx1010:xnack-' on some GPUs; detect_arch handed that to
asm.family(), which rejects it, so the oracle was skipped unless
LEONIDA_HW_ARCH was set.
kernel_text() wrote a fixed descriptor: 16 VGPRs, 32 SGPRs, wave32. On
gfx1036 v16 and up read back 0, and Kernel(wave=64) ran as wave32 (lane
40 of a full EXEC's lane ids read 8), so wave64 results of wrapped
kernels were wave32 runs.
The descriptor now follows the Kernel's wave, vgprs and sgprs, and every
descriptor is raised to the highest register its lines name. Callers and
defaults are unchanged. Tests in tests/test_hw_oracle.py, including one on
hardware for the wave size and v16 / v200.
AI-assisted.
Without gcc or cl on PATH, the host launcher is built through a .cmd that calls vcvars64.bat. It was written as
ASCII, and it holds the checkout, %TEMP% and Visual Studio paths, so a character outside ASCII in any of them
(a Windows user name, the Turkish default folder name "Yeni klasör") raised UnicodeEncodeError: a traceback
instead of a build, and not the Unavailable that callers turn into exit code 77. The script is now UTF-8 with
`chcp 65001`, as scripts/build_runtime.ps1 writes its own, and the compiler's output is decoded leniently.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
tools/texoff_probe.py samples a linear R32_SFLOAT texture whose texel holds its index (2D 64x64 for y, 3D 64x1x64
for z) with image_sample_lz_o through tools/hw_oracle on gfx1036, wave32 and wave64. All 15 rows fit the
translator's rule. tests/test_texoff_probe.py checks that each row with a negative field tells signed from unsigned.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.
AI-assisted (Claude), on behalf of dev-ewann.
AMD clang rejects .amdhsa_ieee_mode and .amdhsa_dx10_clamp on gfx1170+
(GFX11.7 and GFX12, where the behaviour is fixed). A kernel asking for
either reached the assembler, and when a chunk held only such kernels the
run died with 'the assembler rejected every program in a chunk'.
asm.mode_skip_reason names the field and the architecture; Oracle.run
returns that reason for those kernels and never assembles them, so the
others still run and the MODE probes fail with a clear message. The
denormal and rounding fields are unaffected.
tests/test_hw_oracle.py covers the reason per architecture, a mixed run
and a run where every kernel is skipped. docs/shader_validation.md notes
it.
AMD clang rejects .amdhsa_ieee_mode and .amdhsa_dx10_clamp on gfx1170 and later, but the oracle emitted both whenever a fuzz run asked for them. The assembler then rejected every kernel in a chunk and the caller only saw a generic rejection.
Raise ModeUnavailable before emitting those directives, and have Oracle.run turn it into Unavailable so the existing exit-77 path reports the requested fields as unavailable. The denormal and rounding fields are still emitted. Add text tests for gfx1170/gfx1200/gfx1201, a gfx1150 control and the runner's skip conversion.
The focused tests pass (33 tests, one hardware skip). No RDNA4 GPU was available to confirm the hardware side; this is the directive-level fix. No game files.
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Runs the same texel fetches as raw compute kernels on the AMD GPU through tools/hw_oracle/: a linear texture the
kernel carries in its own code (256-byte aligned, found with s_getpc_b64), a T# built in s[8:15] for the GPU's family
(hw_oracle/tsharp.py: GFX11 on gfx11xx, GFX10 on gfx103x/gfx10xx), image_load with every dmask for one texel per lane,
all four result registers stored and compared word for word with the CPU model. --oracle translator,hw runs both on
the same textures; --negative-control checks seven wrong models and a wrong T# FORMAT are caught. Exit 77 without the
tools. gfx1150 is RDNA3.5, not RDNA2: the docs say so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>