Skip to content

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

Open
opit80 wants to merge 6 commits into
ItsNotRexed:mainfrom
opit80:shader-mubuf-invalid-format
Open

opit80 wants to merge 6 commits into
ItsNotRexed: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. 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); buffer_atomic_* → not measured on hardware and not touched by this PR. The claim text also listed buffer_atomic_* under the zero-on-read / no-write rule, but that part was dropped because AMD ISA §8.1.4 does not separate the atomic memory effect from the GLC return value for a partially filled FORMAT=0 V#, and the local fuzzer only exercised atomics with valid descriptors.
Where #1367, #580 and #1116 touch the same shared test/design tables: whoever merges first, the other rebases.

The buffer_load_dwordx2/x3/x4 and buffer_store_dwordx2/x3/x4 forms and the other raw formats were not measured directly; they follow from the x1 measurements by the same per-dword rule. Descriptor-selected constants on the formatted path (FORMAT=0 with DST_SEL) are out of scope for this PR.

Tested

  • 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 <scratch>/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 (<scratch>/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. The measurements above were run on this machine.

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.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6f42872 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested 6f428728 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Clean merge (12 files, +141/-35). The PR has no C++/CMake changes, so the GPU test programs are the d0835dd9 build.
  • scripts/run_gpu_tests.py: 215 shaders, 215 translated, 215 pass spirv-val (d0835dd9 alone: 214/214). Native: 197/211 passed, 14 skipped, 0 failed. With LEONIDA_W64_EMULATE=1: 197/211 passed, 14 skipped, 0 failed. All 14 skips in both modes are fixtures run by the d3d12 tests.
  • Per-test comparison with d0835dd9 without the PR (196/210, 14 skipped in each mode): every PASS/FAIL/SKIP line is the same. The only difference is the new fixture, PASS cs_mubuf_fmt0 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678 0x0 0xeeeeeeee 0xeeeeeeee 0x12345678, in both modes. This shows the translated SPIR-V gives the expected words on RADV. It is not a native FORMAT=0 measurement on gfx1103.
  • python -m unittest discover -s tests/semantic: 7457 tests with the PR, 7456 on d0835dd9. Both have 7 failures and 2 errors, and the 9 failing entries are the same in each tree (loop_ballot_barrier 5, mutations 2, cmp_class_f64 2). The extra test, RawBufferInvalidFormat.test_loads_and_stores, passes.
  • Touched modules on their own: test_value_semantics 40 OK, test_vector_mem_mubuf 53 OK, test_fspx_rules 9 OK, test_wave64_emulate_opt 22 OK. Standalone: tests/test_mem_diff.py 16 OK, tests/test_run_gpu_tests.py 40 OK, tests/test_shader_checks.py 75 OK. regen_fixtures.py --check, compileall and make_game.py --help all exit 0.
  • tools/mem_diff.py (CPU differential), seed 20261122, 200 programs: --max-ops 12 gave 200 pass, 0 mismatch, and --family buffer_format gave 200 pass, 0 mismatch. Both results are the same on the PR and on d0835dd9.

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

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.
@opit80
opit80 force-pushed the shader-mubuf-invalid-format branch from 6f42872 to c8fa560 Compare November 23, 2026 09:28
@opit80

opit80 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@AlxcBTW @markankamaransheogarat-sys: a heads-up from the SHADER-221 rebase onto main 3faac55. The pixel-shader environment that ps_w64_b_ballot_atomic runs in under TEST-722 (fixture from ce305ec, run from d7d9a8e) builds its V# with FORMAT=0 (INVALID). This PR suppresses raw MUBUF dword accesses at FORMAT=0, following the gfx1035 measurements in #1218, so that case failed on this branch. In c8fa560 I changed only that descriptor's FORMAT to 32_FLOAT (22); the fixture's ballot/atomic subject and expected words are unchanged. If you know of hardware where raw accesses ignore FORMAT, please say so.

AI-assisted.

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.

@Hiiva Hiiva 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.

Independently checked current head d220806df20ca55aaabf7703b2e7c69b8c5ed953 on Windows 11 with MSVC 19.44.35228, AMDGPU LLVM 21.1.8, and Vulkan SDK 1.4.363.0. Synthetic inputs only. No actionable finding in this bounded review.

At d220806, after confirming the two-file fixture delta from c8fa560:

  • Reran RawBufferInvalidFormat.test_loads_and_stores: pass. Substituting unchanged main's translator makes the same test fail on the INVALID load/store words.
  • Built the revised cs_mubuf_fmt0 through the repository's normal assembly, header, translation, and validation pipeline: 1/1 translated and spirv-val-valid. Its emitted runtime FORMAT gates remain present after the new s_or_b32 construction.
  • RTX 4080, driver 610.62 / 32.0.16.1062, and AMD Radeon(TM) Graphics, driver 32.0.21043.5001: both runs return exactly [0, 0xeeeeeeee, 0xeeeeeeee, 0x12345678] twice. Forced Khronos standard and synchronization validation logging captures no VUIDs or validation errors.
  • The revised fixture built with main's translator also validates and executes, but returns [0xeeeeeeee, 0xeeeeeeee, 0x12345678, 0x12345678] twice on RTX. This is the expected negative control.

Evidence carried from the separately tested c8fa560 revision: the four affected semantic modules passed 124 tests; both GPUs passed the repository's ps_w64_b_ballot_atomic pixel/heap oracle (4,096 pixel records, counter 1,024, every intended pixel number once). Restoring only its old FORMAT=0 descriptor keeps the counter at 1,024 but fails the slot oracle on both GPUs. RTX confirmed required fragment subgroup size 32; Radeon coverage used the default fragment subgroup size because that harness could not confirm a forced size. The graphics fixture, graphics checker, translator, and both Vulkan harness sources are unchanged by d220806, so I did not repeat that matrix. A known-invalid interface pairing and corrected control had also confirmed this harness's validation logging at c8fa560.

The worktree remains clean at the verified current head. This checks translated behavior, not native ISA FORMAT semantics. AI-assisted.

@TheMrBeez

Copy link
Copy Markdown

Measured the raw-MUBUF FORMAT rule on native RDNA2 across every FORMAT code. The "by extension, not measured directly" cases in the new row hold. Two gaps remain against d220806d: the reserved codes 78–127, and the sub-dword forms.

Setup. gfx1036 (Ryzen 9 9950X3D iGPU), AMD driver 32.0.21030.2001, raw tools/hw_oracle kernels, lane 0, wave32 and wave64.

  • V# word3 = 0x01000fac | FORMAT << 12 | OOB_SELECT << 28, stride 0, num_records 128.
  • Sweep: all 128 FORMAT codes × OOB_SELECT 0–3 × both wave sizes, 1,024 kernels.
  • Each kernel fills its own data words, then runs:
    • loads: buffer_load_dword/x2/x3/x4, buffer_load_ubyte/ushort (destinations preset to 0xa5a5a5a5);
    • stores: buffer_store_dword/x2/x3/x4, buffer_store_byte/short;
    • atomics: buffer_atomic_add with and without glc, buffer_atomic_swap glc.
  • Every access is inside the buffer.

Result: two classes, the same in all four modes and both wave sizes.

FORMAT loads stores and atomics
1–77 the data write; the glc atomics return the old value
0 and 78–127 0, every width, ubyte/ushort included memory untouched; the glc atomics return 0
  • OOB_SELECT 0 with stride 0 puts every access out of bounds for every format: all loads 0, nothing written. So mode 0 can't separate FORMAT unless the V# has a stride. With stride 128 and num_records 1, mode 0 gives the same split, checked for FORMAT 0, 1, 22, 77, 78, 100 and 127 in both wave sizes.
  • So the hardware directly confirms x2/x3/x4 and OOB_SELECT 2, which the row lists as not measured directly.

Gap 1: codes 78–127. The hardware treats every reserved code like 0. The PR gates only FORMAT == 0: OpINotEqual %bool {fmt} {self.cu(0)} for a run-time word3, and (lit3 >> 12 & 0x7F) == 0 for a literal one.

The Out-of-bounds typed buffer loads row already groups INVALID (0) with the reserved codes (78..127) for DST_SEL=1. The raw gate could use the same range, valid iff 1 <= FORMAT <= 77, for example one unsigned FORMAT - 1 < 77 compare. I doubt the game's descriptors use a reserved code, so this is about matching the hardware rather than a known shader.

Gap 2: sub-dword raw loads. buffer_load_ubyte/ushort are suppressed too, at FORMAT 0 as well as 78–127. buffer_load_sub calls buffer_address(a, mods, elem=nbytes) without parts=True, so the PR leaves them ungated. buffer_store_byte/short are suppressed on hardware as well, but the translator doesn't handle them yet, so they'd need the same gate only once they're added.

For atomics, @Vonsek's gfx1036 measurement above (ADD and CMPSWAP) matches mine (ADD with and without glc, SWAP): memory untouched, 0 from glc, and the same at 78–127. That's the follow-up the description already plans.

Translated at d220806d. A lane-0 compute fixture with literal OOB_SELECT 3 descriptors at byte 64, num_records 32, on the RTX 5080 (621.01) and on the gfx1036 through Vulkan. Both GPUs give the same words, spirv-val is clean.

access translated native rule above
buffer_load_dword, FORMAT 78 / 127 0xeeeeeeee / 0xeeeeeeee (heap fill) 0 / 0
buffer_store_dword 0x12345678, FORMAT 78 / 127 written / written untouched
buffer_load_ubyte, FORMAT 0 0xee 0
buffer_atomic_add 5 glc, FORMAT 0 returns 0xeeeeeeee, memory 0xeeeeeef3 returns 0, memory untouched
control: buffer_atomic_add 5 glc, FORMAT 22 returns 0xeeeeeeee, memory 0xeeeeeef3 the same

I ran that fixture only through the translator. The native column comes from the sweep, which covers the same instructions and descriptor modes. cs_mubuf_fmt0 itself still gives 0 eeeeeeee eeeeeeee 12345678 0 eeeeeeee eeeeeeee 12345678 on the 5080 at this head.

Gap 1 is the one I'd fold into this PR, since it changes the condition the PR adds. Gap 2 and the atomics could share the follow-up.

Windows 11, Vulkan SDK 1.4.363, llvm-mc AMD LLVM 23.0.0git. Synthetic descriptors and data only, no game files. The probe scripts are local. AI-assisted (Claude Code).

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.