Skip to content

SHADER-221: Suppress raw MUBUF accesses through FORMAT=0 (INVALID) V# descriptors - #1435

Open
opit80 wants to merge 7 commits into
ProjectLeonida:mainfrom
opit80:shader-mubuf-invalid-format
Open

opit80 wants to merge 7 commits into
ProjectLeonida:mainfrom
opit80:shader-mubuf-invalid-format

Conversation

@opit80

@opit80 opit80 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-221 (claim, listed in #1380)

What and why

@ezwinxdlmao found the bug and measured it on gfx1035 (Radeon 680M, driver 22.40.84.06): a V# with FORMAT=0 (INVALID) suppresses raw buffer_load_dword[xN] / buffer_store_dword[xN] accesses even when they fit the buffer bounds; at FORMAT=0 the loads return zero and the stores write nothing for OOB_SELECT 0, 1 and 3, while FORMAT=22 returns data and writes. gfx1035 measurements @Vonsek verified on gfx1036 that descriptor-selected constants can survive a formatted MUBUF read that returns no memory data (0, 1, 0, 1 for FORMAT=0), which is why the zeroing rule is attached only to the raw path. gfx1036 measurements Before this change the translator applied only the existing OOB_SELECT / NUM_RECORDS / lane-mask / dword-bound logic to raw dword accesses, so a FORMAT=0 V# still read and wrote memory. Now FORMAT = (word3 >> 12) & 0x7f is folded for literal word3 and added as an extra predicate beside the bounds predicate for run-time word3: active load lanes get zero without a read, and stores issue no write. A later sweep by @TheMrBeez extended this to the full 7-bit FORMAT field: only codes 1-77 fetch and store, while INVALID 0 and the reserved codes 78-127 suppress raw accesses, so the gate is now 1 <= FORMAT <= 77 (details below). The memory differential fuzzer's two synthetic descriptor sites now carry a valid FORMAT for their in-bounds controls. AMD RDNA 2 ISA §8.1.4, Table 31

Scope

Out of scope and tracked separately: MTBUF loads → @Vonsek (SHADER-215, the follow-up to the merged #1302; MTBUF load measurements); MTBUF stores → @ezwinxdlmao (#1371 / SHADER-217). Where #1367, #580 and #1116 touch the same shared test/design tables: whoever merges first, the other rebases.

Earlier revisions of this description said buffer_atomic_* was not measured on hardware; that is no longer accurate — @TheMrBeez's sweep measured ADD (with and without glc) and SWAP (glc) atomics on gfx1036. They are still not touched by this PR and are listed under Follow-up below, together with the sub-dword raw loads and byte/short stores. Descriptor-selected constants on the formatted path (FORMAT=0 with DST_SEL) are out of scope for this PR.

What changed since last review

Rebased onto main dde82f27, head 0f94ff5a. Thanks to @TheMrBeez for the native RDNA2 sweep (PR #1435 comment 7097323541): all 128 FORMAT codes were measured on gfx1036 across OOB_SELECT modes 0-3 and wave32/64. FORMAT 1-77 fetch and store normally, while INVALID 0 and the reserved codes 78-127 suppress raw loads (return 0) and leave stores and glc atomic writes untouched (glc atomics return 0). The new commit therefore gates raw MUBUF access on 1 <= FORMAT <= 77 instead of FORMAT != 0 — one unsigned FORMAT - 1 < 77 compare for a run-time V# and the same range for a literal one — and adds FORMAT 77/78/100/127 boundary tests plus the docs/design.md row update. The previously marked "by extension, not measured directly" x2/x3/x4 forms and OOB_SELECT mode 2 are now directly covered by that sweep.

Follow-up (out of scope here)

The same measurement found two gaps that this PR does not change: sub-dword raw loads (buffer_load_ubyte / buffer_load_ushort) are still ungated because buffer_load_sub does not pass parts=True, and byte/short stores need the same gate when they are implemented. Raw buffer atomics are also suppressed by INVALID 0 and the reserved codes 78-127 on hardware, where they return 0 and write nothing; the translator currently returns a value and issues a write for them. Both belong in a follow-up; this PR's gate covers only buffer_load_dword[xN] and buffer_store_dword[xN].

Tested

  • Current rebase — onto main dde82f27, head 0f94ff5a7f5495d664f6f9a44069685e3c9f5742: Windows 11 (10.0.26200), MSVC 19.44.35229, NVIDIA GeForce RTX 5070 Ti (driver 617.42), Vulkan SDK 1.4.363.0, Python 3.14.
    • python -I scripts/run_semantic_tests.py tests/semantic -j 4 -v — 447 files, 5959 tests; the only three failing files (test_image_atomics_guard, test_image_cube_store_glc, test_image_store_d16) fail identically on the base commit dde82f27 in this environment. No test passes on base and fails on this branch; three tests are new and pass (RawBufferInvalidFormat.test_loads_and_stores and the two TestRawFormatGateRange cases).
    • Mutation check: running the new gate tests against the base translator fails 16 subtests (FORMAT 78/100/127, literal and run-time, loads and stores), so the new cases do discriminate the change.
    • cmake -S runtime -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo; cmake --build build -j 4 — clean.
    • python -I scripts/run_gpu_tests.py --build build --work <native> — 193/242 passed, 48 skipped; cs_mubuf_fmt0 gives 0 eeeeeeee eeeeeeee 12345678 / 0 eeeeeeee eeeeeeee 12345678. The single failure, ms_wave_info_s3, also fails on the base commit here.
    • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build build --work <emu> — 224/242 passed, 17 skipped; cs_mubuf_fmt0 passes with the same words; the same ms_wave_info_s3 failure.
    • LEONIDA_VK_VALIDATION=1 ctest --test-dir build -C RelWithDebInfo --output-on-failure -j 4 — 97% tests passed, 9 failed out of 272. Five of those (vk_queue, d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_depth_resolve, d3d12_mesh) are the known failures of the base commit in this environment; the other four (api_ref_state timeout, d3d12_m4_compute, d3d12_buffer_uav, d3d12_bindless_churn_validated) are also environment/concurrency failures: eight of the nine still fail with -j 1, bindless_churn_validated passes alone. This branch changes no C++ runtime code (only translator Python and shader fixture files).
  • Rebased onto main 3faac55 (head c8fa560d): docs/design.md and scripts/run_gpu_tests.py conflicted (both sides kept); one more upstream fixture needed a valid FORMAT (item 4 above). Windows 11, RTX 5070 Ti, MSVC 19.44 RelWithDebInfo: full tests/semantic 6246 tests with 3 failures + 2 errors, the same list as main 3faac55 on its own (6245 tests, test_loop_ballot_barrier); scripts/run_gpu_tests.py 171/218 passed, 47 skipped, 0 failed (main: 170/217, the difference is cs_mubuf_fmt0, PASS); regen_fixtures.py --check clean (independently re-run).
  • cs_mubuf_fmt0 run-time group now really run-time (d220806d): its second descriptor pair used to derive word3 with s_xor_b32 of two literals, which the translator folds to a constant, so the run-time FORMAT check was never emitted for those four accesses and the GPU only ran the literal path. Word3 is now built with s_or_b32 (the pattern tests/semantic/test_buffer_oob_select.py already uses for run-time descriptors); the descriptor values (0x11000fac, 0x11016fac) and the expected words are unchanged. The translated module now has 10 run-time format checks instead of 6. run_gpu_tests.py --filter cs_mubuf_fmt0 passes natively and with LEONIDA_W64_EMULATE=1 (same words); the full GPU run is still 0 failed. If the translator ever folds s_or_b32 of literals too, this case would silently become literal again.

GPU: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 Pro 25H2. Synthetic shaders and buffers only.

Re-run after rebasing onto current main (base aa2988cc, branch head 6f428728): python -m unittest discover -s tests/semantic — 7457 tests, 0 PR-specific failures/errors after the descriptor adjustments; the remaining 7 failures + 2 errors are identical (same 9 test names) on clean main at 7456 tests (loop_ballot_barrier 5, cmp_class_f64 2, mutations 2; the extra test is the PR's cs_mubuf_fmt0 CPU fixture). python tests/semantic/regen_fixtures.py --check exits 0 on both the PR and clean main. python -I scripts/run_gpu_tests.py: PR 165/211 passed, 46 skipped, 0 failures; with LEONIDA_W64_EMULATE=1 196/211 passed, 15 skipped, 0 failures; cs_mubuf_fmt0 passes in both modes. Clean main with the same runtime: 164/210 passed, 46 skipped, 0 failures normal and 195/210 passed, 15 skipped, 0 failures emulated — the only delta is this PR's one new GPU test. The detailed list below is from the original branch point.

Upstream tests adjusted after the rebase. While rebasing onto current main, upstream test additions turned out to build their V# descriptors with an INVALID format (FORMAT=0), which this PR makes suppress raw buffer_load/store_dword[xN] — measured on a Radeon 680M (gfx1035) in OOB_SELECT modes 0, 1 and 3, with 32_FLOAT (FORMAT=22) as the working control (the #1218 measurements linked above; the cs_mubuf_fmt0 GPU fixture checks the same rule for literal and run-time descriptors). The tests are adapted so they still test what they were written for, with valid-format descriptors:

  1. tests/semantic/test_fspx_rules.py::VccTupleSmemTests::test_slist_as_vsharp_and_tsharp — upstream commit bda17759 by SweatierKey. It loaded a V# into [s104,s105,vcc_lo,vcc_hi] and fed the same descriptor to s_buffer_load and a raw buffer_load_dword, with word3 0x30000000 (mode 3, FORMAT=0). Our commit 86a06d77 ("tests: give the VCCTuple V# a valid FORMAT") changes only V# word3 to 0x30016000 (FORMAT=32_FLOAT) and adds an explanatory comment; the VCCTuple-as-V# and 8-dword T# subject, the load/store sequence and the expected data are unchanged, so the raw load reads the stored words again.

  2. tests/semantic/test_vector_mem_mubuf.py (TestSpirvTranslationLoads / TestSpirvTranslationStores) — upstream commit 61bd71ef ("test(semantic): add reference oracle for untyped MUBUF buffer loads and stores") by slopgobblercobbler. Its raw V# words were built with word3 0x30000000 (mode 3, 10 places) or 0 (mode 0, 9 places), both FORMAT=0, expecting data through the raw opcodes. Our commit 6f428728 ("tests: valid formats in the untyped MUBUF oracle descriptors") changes only those 19 descriptor words to 0x30016000 / 0x16000 (FORMAT=32_FLOAT); every test's address, bounds, masking, offsets and multi-dword subject is unchanged.

  3. tests/semantic/test_wave64_emulate_opt.py::StructuredEmulationTests::test_monotone_dirty_transfer_no_phantom_clear_after_x_round — not a FORMAT case: its structure scan looked for the blk3 buffer OpLoad within 15 lines of the preceding OpConvertUToPtr, and the run-time V# format check this PR emits adds three instructions between them. The same commit 6f428728 widens that single scan window to 18; the emulated words it checks are unchanged.

  4. runtime/test/shaders/ps_w64_b_ballot_atomic.asm + its w64_graphics.py pixel-shader environment (fixture from ce305ec, SHADER-10; run as a pixel shader by TEST-722, d7d9a8e): the PS environment's V# carried FORMAT=0, so on this branch the fixture's raw buffer accesses were suppressed and TEST-722's ps_w64_b_ballot_atomic case failed. The descriptor now carries FORMAT=32_FLOAT; the fixture's ballot/atomic subject and expected words are unchanged. (Commit "tests: give the ballot-atomic fixture V# a valid FORMAT".)

If a reviewer has hardware evidence that raw MUBUF accesses ignore FORMAT, that contradicts the #1218 measurements and we'd like to hear it — the rule this PR implements is backed by the gfx1035/gfx1036 runs linked above.

  • New hand-written shader: before the fix the new CPU fixture failed (1 error — the INVALID load read the memory fill and the INVALID store changed its target) and the new GPU fixture failed (0/1: translation and spirv-val succeeded but four output words were wrong). After the fix the CPU fixture passed (1 passed, expected eight dwords and read addresses matched) and all eight output words matched in both GPU modes.
  • python -m compileall -q make_game.py tools tests — exit 0.
  • python -m unittest discover -s tests/semantic — 1179 passed (the new test was checked as a filtered negative control before the fix).
  • python -I tests/test_*.py on the selected standalone files — 30 files passed, mem_diff 13/13 (applying the translator fix alone had made four subcases fail).
  • Selected pytest files — before descriptor adaptation: 4 failed, 753 passed, 3 skipped; after: 754 passed, 3 skipped, 17 subtests passed.
  • tools/mem_diff.py --programs 200 --seed 20261122 --max-ops 12 — 200/200 before and after, 0 mismatch.
  • python -I scripts/run_gpu_tests.py --work <work>/gpu — 106/134 passed, 28 wave64 skipped, 0 failures; 138/138 shaders translated and passed spirv-val.
  • Same GPU package with LEONIDA_W64_EMULATE=1 (<work>/gpu-emulate) — 134/134 passed; 138/138 shaders translated and passed spirv-val.
  • CMake + Ninja runtime build — RelWithDebInfo, MSVC 19.44.35229.0, 239/239 steps. python -I make_game.py --help and python tests/semantic/regen_fixtures.py --check — both exit 0.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@dcastell1 dcastell1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally (CPU): python -I tests/test_shader_checks.py → 40 tests OK; full semantic suite → 1195 tests OK (1 skip). Worth noting the fixture was updated with the PR (tests/semantic/fixtures/disasm/cs_mubuf_fmt0.s + regen_fixtures.py), which is exactly what #1394 is missing.

Reading the change: gating inside check_end() (and the %false shortcut for a literal V# with FORMAT=0) keeps one predicate path, so a suppressed multi-dword load or store cannot partially write. Scoping it to parts=True leaves the typed/fixed_fmt loads alone, which is right — their format is the instruction's, not the V#.

The description is honest about which cases are measured on gfx1036 and which the rule extends to (mode 0 per-dword, stores); I have no AMD hardware to add to that. No GPU rerun here: the 5090 is compiling one of the two giant ScreenProbes modules.

@evilclanker9000

Copy link
Copy Markdown
Contributor

@opit80, I measured the atomic/GLC question you left open in the PR description on native gfx1036 (Windows). Both wave32 and wave64 gave the same results in 24 source-built kernels. I kept base, byte range and source constant; the only descriptor change was FORMAT=0 versus 32_UINT.

Memory started at 11, and the input VGPR held 7. With INVALID, neither ADD nor CMPSWAP changed memory. GLC returned 0 in the first data VGPR; without GLC, that VGPR stayed 7. CMPSWAP preserved its compare VGPR for both matching (11) and mismatching (12) comparands. With the bound control, ADD wrote 18, matching CMPSWAP wrote 7, and mismatching CMPSWAP kept 11. All three returned the old memory value 11 with GLC. A separate global load and host readback agreed on memory in all cases.

These measurements cover ADD and CMPSWAP on this chip. Can you use them for the atomic follow-up you described?

AI-assisted.

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested f13857c (118 behind main) on Windows 11 Home 10.0.26300, with the GPU suite on two GPUs. Python 3.14.7, llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~.

run result
scripts/run_gpu_tests.py, AMD Radeon RDNA2 iGPU (Ryzen 7 9800X3D, 32.0.21042.62), native wave64 136/136; cs_mubuf_fmt0 PASS
same, RTX 5070 (617.42), LEONIDA_W64_EMULATE=1 136/136; cs_mubuf_fmt0 PASS
pytest tests/semantic/test_value_semantics.py 26 passed, 75 subtests passed

Both GPUs read cs_mubuf_fmt0 as 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 twice. No validation messages. (Main is at 139 tests now; the branch predates the newest three.)

AI-assisted (Claude Code). No game files.

@opit80

opit80 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 99f99890; published head is 6df06e23. Re-verified on this head: semantic suite 1248 OK, tests/test_mem_diff.py 15 OK, and same-seed A/B fuzz (buffer_format, seed 20261122, n=200) with 0 mismatches on both main and PR. cs_mubuf_fmt0 PASS on RTX 5070 Ti / driver 617.42. The three full-suite image/gather failures (cs_imgload_d16, cs_sample_lz_int_d16, ps_gather_wrap) are unchanged between baseline and PR, so no new GPU regression. Measurements are limited to this NVIDIA GPU: no AMD hardware or general driver root-cause check was done, and CI checks for this head are still queued (mergeStateStatus UNSTABLE, nothing reported yet), so nothing is claimed beyond the measured scope.

AI-assisted.

@opit80
opit80 force-pushed the shader-mubuf-invalid-format branch 2 times, most recently from 64f6b03 to 2d6b072 Compare November 22, 2026 13:14
@dcastell1

dcastell1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Re-ran on the rebased head 2d6b0725, RTX 5090 (621.24, Windows 11), programs rebuilt from this tree, LEONIDA_W64_EMULATE=1: 156/164 passed, 8 skipped, 0 failed. The new fixture on hardware:

PASS  cs_mubuf_fmt0   0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678

so the FORMAT=0 suppression now has a measured GPU result on NVIDIA as well as the AMD numbers in the description. The 8 skips are the M1/M2/M3 shaders the D3D12 tests run. My earlier "no GPU rerun" note is superseded.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 64f6b03 merged into main 41f44826 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test pass natively: cs_mubuf_fmt0 (0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678).
  • Whole run_gpu_tests.py: 146/146 native, 146/146 with LEONIDA_W64_EMULATE=1 (main alone: 145).
  • tests/semantic/test_value_semantics.py: 30 passed, 85 subtests passed.

No game files. AI-assisted (Claude Code).

@Impre-visible

Copy link
Copy Markdown

Tested 2d6b072 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • spirv-val on the modules the PR's semantic tests translate (test_value_semantics.py): distinct modules: 37, pass spirv-val: 37, rejected: 0
  • tests/semantic: 1399 OK
  • build.py: 176 shaders, 176 translated, 176 pass spirv-val; check.py: 115 of 148 pass, 33 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 169 shaders: 169 translated, 169 pass spirv-val; 126/164 passed, 38 skipped (fixtures run by the d3d12 tests), 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 156/164 passed, 8 skipped (fixtures run by the d3d12 tests), 0 failed
  • New fixture cs_mubuf_fmt0: PASS natively and with LEONIDA_W64_EMULATE=1 (same eight leading words in both runs); check.py ok

AI-assisted run (Claude). Synthetic programs only, no game files involved.

@esteban-dcp

Copy link
Copy Markdown

Tested 2d6b0725 (the PR head as is, built from its own runtime/, not rebased on current main). Linux 7.3.5, scripts/run_gpu_tests.py, 0 failures in all three runs:

GPU Driver Result
NVIDIA GeForce RTX 4050 Laptop (Ada, subgroup 32) 620.73.04 126/164 passed, 38 skipped
same GPU, LEONIDA_W64_EMULATE=1 620.73.04 156/164 passed, 8 skipped
AMD Radeon 740M (RDNA3, RADV, subgroup 32..64) Mesa 26.3.1 156/164 passed, 8 skipped

The new cs_mubuf_fmt0 passes in all three, with the same eight dumped words each time (0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 twice). 169 shaders translate and pass spirv-val. tests/semantic: 1399 tests OK. No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@sarveshgamers

Copy link
Copy Markdown
Contributor

Tested f13857c9 on dual-GPU setup: AMD Radeon 780M Graphics (driver 32.0.32015.7029, Vulkan 1.4.359, subgroup 32..64) and NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.2101 / 572.16, subgroup 32..32), Windows 11. AI-assisted.

All five harnesses (vk_compute_test, vk_store_test, vk_harness, vk_texture_test, vk_bindless_test) built with MinGW GCC 16.2.0, llvm-mc 23.0.0git (amdgcn, gfx1013), SPIRV-Tools v2026.4.

AMD Radeon 780M (subgroups 32..64)

  • scripts/run_gpu_tests.py: 136/136 passed (0 failures, 0 skipped)
    • cs_mubuf_fmt0: PASS (0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678)
    • Both OOB_SELECT 3 (literal) and OOB_SELECT 1 (run-time) verify that INVALID (FORMAT=0) suppresses reads (returning 0) and suppresses writes (target remains unmutated), while the FORMAT=22 control reads heap fill and performs in-bounds writes.

NVIDIA GeForce RTX 5060 Laptop GPU (subgroup 32..32)

  • Native (run_gpu_tests.py): 107/136 passed, 29 skipped (wave64 requirements skipped cleanly, 0 failures)
    • cs_mubuf_fmt0: PASS (0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678)
  • Emulated (LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py): 136/136 passed (0 failures, 0 skipped)
    • cs_mubuf_fmt0: PASS

Unit & Semantic Verification

  • python -m unittest discover -s tests/semantic -p "test_value_semantics.py": 26 passed (including RawBufferInvalidFormat.test_loads_and_stores)
  • python -I tests/test_shader_checks.py: 40/40 passed
  • python -I tests/test_run_gpu_tests.py: 27/27 passed

No game data or proprietary assets used.

The raw buffer_load_dword in test_slist_as_vsharp_and_tsharp ran with
V# word3 0x30000000: OOB_SELECT 3 with FORMAT=0 (INVALID). A raw MUBUF
access is suppressed for an INVALID format, measured on gfx1035 in
OOB_SELECT modes 0, 1 and 3 (ItsNotRexed#1218), so the load reads zero there.
Give the descriptor FORMAT=32_FLOAT (22), the valid control of the same
measurement, so the test keeps exercising the VCCTuple-as-V# plumbing
it was written for.
The reference-oracle suite (61bd71e) built its raw and structured V#s
with word3 0x30000000 or 0: OOB_SELECT modes 0 and 3 with FORMAT=0
(INVALID). A raw MUBUF access is suppressed for an INVALID format,
measured on a Radeon 680M (gfx1035) in modes 0, 1 and 3 (ItsNotRexed#1218), so
those loads read 0 and the stores never wrote. Give those descriptors
FORMAT=32_FLOAT (22), the valid control of the same measurement; the
address, bounds, masking and multi-dword subjects stay unchanged.

test_wave64_emulate_opt's monotone dirty-transfer scan looked for the
blk3 buffer OpLoad within 15 lines of the preceding OpConvertUToPtr;
the run-time V# format check adds three instructions between them, so
widen that one window to 18.
TEST-722 (d7d9a8e) runs the ps_w64_* pixel fixtures on the wave
interpreter with the V# that w64_graphics.py passes in VKH_SGPRS.
ps_w64_b_ballot_atomic's word3 was 0x30000000: OOB_SELECT 3 with
FORMAT=0 (INVALID). A raw MUBUF access is suppressed for an INVALID
format, measured on gfx1035 in OOB_SELECT modes 0, 1 and 3 (ItsNotRexed#1218),
so the fixture's buffer_atomic_add and its slot stores did nothing
and the test failed with an empty heap. Give the descriptor
FORMAT=32_FLOAT (22), the valid control of the same measurement;
the compaction idiom the fixture tests is unchanged, and main,
which has no suppression rule, translates both descriptors alike.
The second descriptor group derived word3 with s_xor_b32 from two literals, which the translator folds into sgpr_imm: the FORMAT=0 gate became a constant and the run-time path was never exercised. Building word3 with s_or_b32 keeps the same descriptor values but leaves them run-time, so the interpreter and the GPU both execute the format gate.
RDNA2 measured INVALID 0 and reserved 78..127 as suppressing raw loads and stores alike. Use an unsigned FORMAT - 1 < 77 check for run-time descriptors and the 1..77 range for literals; add 77/78/127 boundary tests and update the design.md row.
@alvaroolt

Copy link
Copy Markdown

Tested 0f94ff5a7 merged onto main 867d922f0 (clean merge) on Windows 11 26300, two GPUs in one machine, picked with VK_LOADER_DRIVERS_SELECT: NVIDIA GeForce RTX 5080 (621.24, 32-wide subgroups) and AMD Radeon iGPU (24.10.34, native wave64). LLVM 23.1.6 llvm-mc, Vulkan SDK 1.4.363, test programs built from main (this PR changes no C++). The rule and its fixture pass, but the wave64 graphics fixtures regress: 5 of them write nothing on this head, on both GPUs.

What passes

  • cs_mubuf_fmt0 passes on both GPUs, AMD native, RTX 5080 native and with LEONIDA_W64_EMULATE=1: 0 eeeeeeee eeeeeeee 12345678 twice.
  • scripts/run_gpu_tests.py, against a main control run on the same machine and binaries. The only difference is the new fixture.
this PR main
AMD native 220/242, 20 skipped 219/241, 20 skipped
RTX 5080 native 193/242, 48 skipped 192/241, 48 skipped
RTX 5080, LEONIDA_W64_EMULATE=1 224/242, 17 skipped 223/241, 17 skipped

The failures are the same on both sides: ms_wave_info_s3 everywhere and ms_clip on AMD. 248/248 translated and spirv-val valid.

  • tests/semantic: test_vector_mem_mubuf (55), test_value_semantics (42), test_fspx_rules, test_wave64_emulate_opt and test_buffer_oob_select are OK. Negative control: with main's tools/rdna2spirv.py, 16 TestRawFormatGateRange subtests (FORMAT 0/78/100/127) and RawBufferInvalidFormat.test_loads_and_stores fail.
  • Code read: buffer_address(parts=True) returns in_b = check(0), which already includes format_ok. So single-dword run-time stores, which take in_b rather than per(0), are gated too.

The regression: runtime/test/shaders/w64_graphics.py, after a full build.py, ran on each GPU.

this PR main
AMD native 12 ok, exit 1 17 ok, exit 0
RTX 5080 12 ok, exit 1 17 ok, exit 0

On this head, these fixtures fail on both GPUs and every output pixel reads (0, 0, 0, 0):

  • gs_w64_a_ring: 320 of 320 pixels differ.
  • vs_w64_a_skip: 960 of 960 differ.
  • vs_w64_b_ballot_atomic: 240 of 960 differ.
  • vs_w64_b_readlane_uniform: 960 of 960 differ.
  • vs_w64_b_waterfall: 956 of 960 differ.

The cause is the same one this PR fixes for the PS environment in d74a676. VS_ENV and GS_ENV (w64_graphics.py:176 and :179) still pass V# word3 0x30000000, which is FORMAT 0. The fixtures' raw buffer_store_dwordx4 to the output buffer is now suppressed. This is the expected effect of the rule, and the fix belongs in the test environment:

-VS_ENV = {"VKH_SGPRS": "0,0,65536,0x30000000", "VKH_HEAP": "0=0"}
+VS_ENV = {"VKH_SGPRS": "0,0,65536,0x30016000", "VKH_HEAP": "0=0"}
-GS_ENV = {"VKH_SGPRS": "0,0,0,0,0,0,65536,0x30000000", "VKH_HEAP": "0=0"}   # V# in s[4:7]: the GS entry sets s3
+GS_ENV = {"VKH_SGPRS": "0,0,0,0,0,0,65536,0x30016000", "VKH_HEAP": "0=0"}   # V# in s[4:7]: the GS entry sets s3

With only these two lines changed, w64_graphics.py is 17 ok, exit 0, on both GPUs. The remaining 12 lines are tier-C SKIPs, the same as on main. run_gpu_tests.py doesn't run these fixtures, which is probably why the PR's runs didn't catch it.

No game files. AI-assisted (Claude Code); results reviewed by me.

@KubickNubick

Copy link
Copy Markdown

Tested 0f94ff5a merged onto main 867d922 (clean merge), with the runtime built from that main: run_gpu_tests.py passes, but w64_graphics.py fails five VS/GS fixtures that pass on main.

  • AMD Radeon(TM) Graphics iGPU (gfx1036): Windows driver 32.0.21042.62, native wave64.
  • NVIDIA GeForce RTX 4080: driver 621.01.
  • Environment: Windows 11 Pro 26300, MSVC 14.51, Vulkan SDK 1.4.363, llvm-mc 23.1.6, Python 3.13.6.

runtime/test/shaders/w64_graphics.py (after build.py)

The result is the same on both GPUs. main gives 17 ok and 14 skipped. The merge gives 12 ok, 14 skipped and 5 failed, with exit 1. Every failing fixture reads back all zeros:

  • gs_w64_a_ring: 320 of 320 pixels differ, first (0,0): got (0, 0, 0, 0), want (0, 1, 77, 0)
  • vs_w64_a_skip: 960 of 960 differ
  • vs_w64_b_ballot_atomic: 240 of 960 differ
  • vs_w64_b_readlane_uniform: 960 of 960 differ
  • vs_w64_b_waterfall: 956 of 960 differ

The cause is the V# the test passes in:

  • VS_ENV and GS_ENV (w64_graphics.py:176 and :179) still build it with word3 0x30000000, FORMAT=0.
  • So with this PR, the fixtures' raw buffer_store_dwordx4 to their heap records is suppressed. It is the same case c8fa560 fixed for ps_w64_b_ballot_atomic.
  • With word3 0x30016000 (FORMAT=22) in both envs, as in that commit, all five pass on gfx1036. I checked this with a local edit and did not push it.
  • The ; Run: headers of the nine vs_w64_* and gs_w64_* fixtures carry the same 0x30000000.
  • run_gpu_tests.py doesn't run w64_graphics.py, which is probably why the earlier checks didn't catch this.

scripts/run_gpu_tests.py, with LEONIDA_VK_DEVICE per GPU

Per-test results are identical to main apart from the new cs_mubuf_fmt0, which passes on both GPUs and in both modes:

Device and mode main merge
gfx1036, native 224/241, 17 skipped 225/242, 17 skipped
RTX 4080, native 192/241, 48 skipped, 1 failed 193/242, 48 skipped, 1 failed
RTX 4080, LEONIDA_W64_EMULATE=1 223/241, 17 skipped, 1 failed 224/242, 17 skipped, 1 failed
  • Translated and spirv-val-valid: 247/247 on main, 248/248 on the merge.
  • The one RTX 4080 failure is ms_wave_info_s3. It fails the same way on main.

Semantic suite, scripts/run_semantic_tests.py tests/semantic -j 8

No game files. AI-assisted (Claude Code).

@adrianmjim

Copy link
Copy Markdown

Tested 0f94ff5a applied onto main 867d922f (clean apply) on AMD Radeon RX 7900 XT (RDNA3, Navi 31), AMD Windows driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359. Windows 11 Pro 26300, MSVC 14.44, Vulkan SDK 1.4.363, llvm-mc 23.1.5, Python 3.14. As far as I can see, this is the first run of this head on RDNA3 with the Windows driver.

The fixture passes. The w64_graphics.py regression that alvaroolt and KubickNubick found reproduces here too. Two runtime D3D12 ctests also regress, and nobody has reported those yet. Unlike w64_graphics.py, that failure is in the runtime's own descriptors, not in a test environment.

What passes

  • build.py: 271/271 translated and spirv-val-valid (270 on main). check.py: 209 of 212, 3 mesh skips (208 of 211 on main). cs_mubuf_fmt0: ok.
  • run_gpu_tests.py --filter cs_mubuf_fmt0, native and with LEONIDA_W64_EMULATE=1: PASS, 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 twice.
  • tests/semantic: test_value_semantics (42), test_vector_mem_mubuf (55), test_fspx_rules, test_wave64_emulate_opt, test_buffer_oob_select, test_buffer_swizzle and test_buffer_load_sub are OK.

w64_graphics.py: same as the two reports above

gs_w64_a_ring, vs_w64_a_skip, vs_w64_b_ballot_atomic, vs_w64_b_readlane_uniform and vs_w64_b_waterfall read back all zeros on the PR and are ok on main. With word3 0x30016000 in VS_ENV/GS_ENV (a local edit, not pushed), all five are ok again on the 7900 XT.

New: d3d12_buffer_uav and d3d12_m4_compute fail

I built both test targets twice with -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON, once from main and once from the PR tree. The C++ is identical in the two trees; only the translator that the CMake custom commands use for cs_buf_*/cs_m4_* differs. I ran ctest -R "^(d3d12_buffer_uav|d3d12_m4_compute)$" three times on each side, with the same result each time:

main this PR
d3d12_m4_compute Passed Failed: structured buffer, dispatch arguments, image and indirect output words all 00000000
d3d12_buffer_uav Passed Failed: appended records { 2779096485, 2779096485 } (= 0xA5A5A5A5 fill, never written), want { i, 3i+1 }

Cause: write_buffer_uav (runtime/shims/d3d12_vulkan_device.cpp:6357, :6404) builds the V# for raw (R32_TYPELESS + RAW) and structured (UNKNOWN) UAVs with format = 0, and the UAV counter V# (:6411-6414) also keeps FORMAT 0. With this PR, every raw buffer_load/store_dword[xN] through those descriptors is suppressed. Buffer SRVs are not affected: raw and structured SRVs already use 32_UINT (:6205, :6217). So this is not only a test-environment issue: the game's raw and structured UAV accesses through the runtime would read 0 and write nothing.

A local experiment (not pushed) with buffer.format = typed ? format_code : 32_UINT in write_buffer_uav, plus 32_UINT on the counter V#:

  • d3d12_m4_compute passes again.
  • d3d12_buffer_uav then fails on its own descriptor check: d3d12_buffer_uav_test.cpp:254-257 requires v.format == 0 for the structured UAV and c.format == 0 for its counter.

So FORMAT 0 for raw/structured UAVs is an explicit runtime contract. d3d12_com.cpp:1138 also relies on it, because buffer.format != 0 selects the typed path when the descriptor is decoded for UAV clears. Fixing the runtime side therefore means changing write_buffer_uav, that decode in d3d12_com.cpp (raw vs typed would need another discriminator, such as oob_select, or the stride plus a format check) and the test's expectations together. Alternatively, the rule could leave raw/structured accesses ungated for those descriptors. It is the maintainer's call, but as it stands, merging this PR breaks D3D12 raw/structured UAVs in the runtime.

No game files. AI-assisted (Claude Code).

@SquishyGithub

Copy link
Copy Markdown

Tested 0f94ff5a7 merged into main 867d922f0 on NVIDIA GeForce RTX 3070 (Ampere), driver 620.70.06, Vulkan 1.4.357, subgroup 32..32, Linux (Bazzite 45; Fedora 45 distrobox, GCC 16.2.1, LLVM 23.1.5, SPIRV-Tools 2026.2, Python 3.15.2): pass

  • scripts/run_gpu_tests.py full suite: 193/242 passed, 48 skipped; with LEONIDA_W64_EMULATE=1: 224/242 passed, 17 skipped. The new fixture passes in both modes:
    PASS  cs_mubuf_fmt0         0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678
    

Every other test gives the same result as main at 867d922f0 (the only failure in both is the known ms_wave_info_s3).

  • ctest: 64/64 passed.
  • pytest on the 4 changed test files: 136 passed, 383 subtests passed.

This covers the 32-wide half only (NVIDIA, 32..32 subgroups); the AMD half of this PR's check still needs an AMD GPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.