rdna2spirv: skip the load of a typed buffer format with no decoder (SHADER-TYPED-RESERVED-FORMATS) #1276

Closed
github-bot wants to merge 1 commit from gh-pr/1276/head into gh-pr/1276/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 21:12 UTC · original
split/shader-typed-reserved-formats → main · +5 −1 · 2 files · 1 commits · closed without merging

Rebased onto bfef489c at cb009ce6. Main already skips the backing load for reserved and invalid typed formats. This diff strengthens the test's positive control to require a read from the expected address. All six focused CPU tests passed.

Claimed in the coordination issue as: SHADER-TYPED-RESERVED-FORMATS (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #811 (open, demand-driven decode for 1/2/3-component loads) edits the decode and swizzle part of the same function, Gen.buffer_load_format; it does not touch the load condition changed here, its current diff applies cleanly on this branch, and with it applied tests/semantic/test_buffer_oob_dst_sel.py still passes (6 tests). #829 and #858 (open) are about typed stores and the d16_hi forms, and #925 (open) edits other rows of docs/design.md; their diffs apply cleanly too, as does #1068. No open or merged pull request found for the load of an INVALID or reserved format (searched buffer_load_format, DST_SEL, typed buffer, reserved format, INVALID format).

What and why

A MUBUF buffer_load_format_* takes its format from the V# (word3 bits 12-18) at run time. A FORMAT without a decoder, INVALID (0) or a reserved code (78..127), has no data channels in the translator: such a load already returned zeros and the DST_SEL constants (the row "Out-of-bounds typed buffer loads and DST_SEL=1" has the hardware measurement of those constants for all 128 codes).

The translated shader still dereferenced such a V#. When its span was non-empty and the offset in range, the load block ran, read one dword at the V# address (five OpLoads of it) and discarded the value. A FORMAT of INVALID marks a V# that is not a view of any buffer (the translator says so itself where it handles an explicit MTBUF format), so its base and NUM_RECORDS say nothing about mapped memory, and a load through a physical storage buffer pointer outside every buffer is undefined in Vulkan. The explicit-format path, tbuffer_load_format_*, already refuses the load of an unbound V#.

The change makes the run-time path do the same: the condition that lets a load touch memory now also needs a format with an element size. Such a load is treated like an out-of-bounds one: no memory access, data channels 0, DST_SEL 0/1 as before. One OpLogicalAnd replaces one OpSelect per load, so the modules do not grow.

The loaded values do not change for any of the 128 codes; only the memory access goes away.

What this does not do

  • It says nothing new about the console. What the hardware does with such a V# beyond the values it returns cannot be observed from a shader and was not measured.
  • It is CPU-checked only. No GPU fixture has an INVALID or reserved format over a mapped span, so no GPU run shows the skipped load itself; the GPU runs below show that loads of real formats are unaffected.

Tested

CachyOS (kernel 7.3.5), Python 3.14, LLVM llvm-mc 23.1.5 and SPIRV-Tools v2026.4. GPU fixtures on an NVIDIA GeForce RTX 4070, driver 620.73.04.

  • python3 -I tests/semantic/test_buffer_oob_dst_sel.py: 6 tests pass. The new test_format_without_a_decoder_skips_the_backing_load runs the fixture tests/semantic/fixtures/buffer_format_unreadable.asm with a read log over a 16-byte in-range span. With the base commit's translator (LEONIDA_TOOLS_DIR=<export of the base's tools>) it fails in 3 of its 4 subtests, codes 0, 78 and 127: five reads of the span's first dword where none is expected. The control, 32_UINT, passes on both.
  • Results before and after: one compute program with four load forms (xyzw, d16_xyzw, x with offen, xy at byte offset 1), every FORMAT code 0..127, three DST_SEL sets and OOB_SELECT 0..3, run through spirv_mini_interp with each translator: 1,536 runs, the nine output words are the same in every one. The number of memory reads differs only for the 51 codes without a decoder: in 459 of their 612 runs the base read memory (20 loads) and this branch reads none; in the other 153, all with OOB_SELECT 0, neither reads any. The module is 2,686 assembly lines on both. This sweep is a local script, not part of the pull request.
  • python3 -I scripts/run_semantic_tests.py tests/semantic -p <file> for the 17 test files that load or decode typed buffers (test_buffer_*, test_format_decode_table.py, test_norm_decode.py, test_tbuffer_load_format.py, test_value_semantics.py, test_wave64_halves*.py): 334 tests, 0 files failed.
  • python3 -I scripts/run_gpu_tests.py --filter fmt and --filter oob: 9 shaders translate and pass spirv-val; cs_buf_fmt8, cs_fmt_1010102, cs_fmt_d16_xyz, cs_fmt_int_narrow, cs_fmt_sint32, cs_fmt_xy_xyz, cs_oob_select and cs_oob_tail pass, 8 of 8, with the base commit's translator and with this one. The harness programs are from a native Linux build of 2026-11-23 on this machine and were not rebuilt.
  • python3 -I scripts/run_semantic_tests.py tests/semantic -j 2: 470 files, 6,169 tests, 0 files failed (the base: 470 files, 6,168 tests, 0 failed).
  • The standard-library and pytest files under tests/ the way ci.yml runs them, and python3 -I -m compileall -q make_game.py tools tests: 520 files, 519 pass. tests/test_imhex_patterns.py fails (6 of its 9 tests) and fails the same way on the base commit, so it is not from this change. compileall passes.
  • python3 -I scripts/check_no_game_data.py: passes.

Not run: native Windows, macOS, an AMD or Intel GPU, the full GPU suite, a GPU run of the new fixture (it needs a harness case that binds a V# with an unreadable format, which does not exist), the tools/hw_oracle probe, the runtime build and a game boot.

GPUs tested: NVIDIA GeForce RTX 4070, driver 620.73.04, Linux (the eight typed-format and out-of-bounds fixtures above; none of them exercises the new skip).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: one load condition, its test with a hand-written fixture, and its contract row.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • The rule is in the contract row "Out-of-bounds typed buffer loads and DST_SEL=1" of docs/design.md, with how it was confirmed (CPU read log) and that it is not GPU-verified.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 21:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1276) `split/shader-typed-reserved-formats` → `main` · +5 −1 · 2 files · 1 commits · closed without merging **Rebased onto `bfef489c` at `cb009ce6`.** Main already skips the backing load for reserved and invalid typed formats. This diff strengthens the test's positive control to require a read from the expected address. All six focused CPU tests passed. Claimed in the coordination issue as: SHADER-TYPED-RESERVED-FORMATS ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #811 (open, demand-driven decode for 1/2/3-component loads) edits the decode and swizzle part of the same function, `Gen.buffer_load_format`; it does not touch the load condition changed here, its current diff applies cleanly on this branch, and with it applied `tests/semantic/test_buffer_oob_dst_sel.py` still passes (6 tests). #829 and #858 (open) are about typed stores and the `d16_hi` forms, and #925 (open) edits other rows of `docs/design.md`; their diffs apply cleanly too, as does #1068. No open or merged pull request found for the load of an `INVALID` or reserved format (searched `buffer_load_format`, `DST_SEL`, `typed buffer`, `reserved format`, `INVALID format`). ### What and why A MUBUF `buffer_load_format_*` takes its format from the V# (word3 bits 12-18) at run time. A FORMAT without a decoder, `INVALID` (0) or a reserved code (78..127), has no data channels in the translator: such a load already returned zeros and the `DST_SEL` constants (the row "Out-of-bounds typed buffer loads and `DST_SEL=1`" has the hardware measurement of those constants for all 128 codes). The translated shader still dereferenced such a V#. When its span was non-empty and the offset in range, the load block ran, read one dword at the V# address (five `OpLoad`s of it) and discarded the value. A FORMAT of `INVALID` marks a V# that is not a view of any buffer (the translator says so itself where it handles an explicit MTBUF format), so its base and `NUM_RECORDS` say nothing about mapped memory, and a load through a physical storage buffer pointer outside every buffer is undefined in Vulkan. The explicit-format path, `tbuffer_load_format_*`, already refuses the load of an unbound V#. The change makes the run-time path do the same: the condition that lets a load touch memory now also needs a format with an element size. Such a load is treated like an out-of-bounds one: no memory access, data channels 0, `DST_SEL` 0/1 as before. One `OpLogicalAnd` replaces one `OpSelect` per load, so the modules do not grow. **The loaded values do not change** for any of the 128 codes; only the memory access goes away. ### What this does not do - It says nothing new about the console. What the hardware does with such a V# beyond the values it returns cannot be observed from a shader and was not measured. - It is CPU-checked only. No GPU fixture has an `INVALID` or reserved format over a mapped span, so no GPU run shows the skipped load itself; the GPU runs below show that loads of real formats are unaffected. ### Tested CachyOS (kernel 7.3.5), Python 3.14, LLVM `llvm-mc` 23.1.5 and SPIRV-Tools v2026.4. GPU fixtures on an NVIDIA GeForce RTX 4070, driver 620.73.04. - `python3 -I tests/semantic/test_buffer_oob_dst_sel.py`: 6 tests pass. The new `test_format_without_a_decoder_skips_the_backing_load` runs the fixture `tests/semantic/fixtures/buffer_format_unreadable.asm` with a read log over a 16-byte in-range span. With the base commit's translator (`LEONIDA_TOOLS_DIR=<export of the base's tools>`) it fails in 3 of its 4 subtests, codes 0, 78 and 127: five reads of the span's first dword where none is expected. The control, `32_UINT`, passes on both. - Results before and after: one compute program with four load forms (`xyzw`, `d16_xyzw`, `x` with `offen`, `xy` at byte offset 1), every FORMAT code 0..127, three `DST_SEL` sets and `OOB_SELECT` 0..3, run through `spirv_mini_interp` with each translator: 1,536 runs, the nine output words are the same in every one. The number of memory reads differs only for the 51 codes without a decoder: in 459 of their 612 runs the base read memory (20 loads) and this branch reads none; in the other 153, all with `OOB_SELECT` 0, neither reads any. The module is 2,686 assembly lines on both. This sweep is a local script, not part of the pull request. - `python3 -I scripts/run_semantic_tests.py tests/semantic -p <file>` for the 17 test files that load or decode typed buffers (`test_buffer_*`, `test_format_decode_table.py`, `test_norm_decode.py`, `test_tbuffer_load_format.py`, `test_value_semantics.py`, `test_wave64_halves*.py`): 334 tests, 0 files failed. - `python3 -I scripts/run_gpu_tests.py --filter fmt` and `--filter oob`: 9 shaders translate and pass `spirv-val`; `cs_buf_fmt8`, `cs_fmt_1010102`, `cs_fmt_d16_xyz`, `cs_fmt_int_narrow`, `cs_fmt_sint32`, `cs_fmt_xy_xyz`, `cs_oob_select` and `cs_oob_tail` pass, 8 of 8, with the base commit's translator and with this one. The harness programs are from a native Linux build of 2026-11-23 on this machine and were not rebuilt. - `python3 -I scripts/run_semantic_tests.py tests/semantic -j 2`: 470 files, 6,169 tests, 0 files failed (the base: 470 files, 6,168 tests, 0 failed). - The standard-library and pytest files under `tests/` the way `ci.yml` runs them, and `python3 -I -m compileall -q make_game.py tools tests`: 520 files, 519 pass. `tests/test_imhex_patterns.py` fails (6 of its 9 tests) and fails the same way on the base commit, so it is not from this change. `compileall` passes. - `python3 -I scripts/check_no_game_data.py`: passes. Not run: native Windows, macOS, an AMD or Intel GPU, the full GPU suite, a GPU run of the new fixture (it needs a harness case that binds a V# with an unreadable format, which does not exist), the `tools/hw_oracle` probe, the runtime build and a game boot. GPUs tested: NVIDIA GeForce RTX 4070, driver 620.73.04, Linux (the eight typed-format and out-of-bounds fixtures above; none of them exercises the new skip). AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named. ### Checklist - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: one load condition, its test with a hand-written fixture, and its contract row. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [x] The rule is in the contract row "Out-of-bounds typed buffer loads and `DST_SEL=1`" of `docs/design.md`, with how it was confirmed (CPU read log) and that it is not GPU-verified. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A buffer_load_format_* whose format comes from the V# read one dword at
the V# address when the FORMAT was INVALID or a reserved code, and
discarded it: such a format has no data channels. An INVALID format
marks a V# that is not a view of any buffer, so that address need not be
mapped. The explicit-format MTBUF path already refuses the load of an
INVALID V#.

Treat a run-time format without a decoder like an out-of-bounds load: no
memory access, data channels 0, DST_SEL 0/1 as before. The loaded values
do not change for any of the 128 codes.

The new read-log test fails on main for codes 0, 78 and 127 (five reads
of the span) and passes here. A sweep of all 128 codes, three DST_SEL
sets and OOB_SELECT 0..3 over four load forms gives the same words in
all 1,536 runs. The typed-format and out-of-bounds GPU fixtures pass on
an RTX 4070 with both translators; none of them reaches the new skip,
which is CPU-checked only. The translator suite ran 470 files and 6,169
tests with 0 failing files, and of the other Python test files only
tests/test_imhex_patterns.py fails, as on main.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:45:27 +00:00
github-bot closed this pull request 2026-11-26 09:45:27 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-24 21:14 UTC · original

Tested 4e98025c on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 66d4f5aa3:

  • tests/semantic/test_buffer_oob_dst_sel.py (with its buffer_format_unreadable.asm fixture): OK at this head; against main's translator it fails 3 times, so the no-decoder path is covered.
  • GPU regression, --filter cs_fmt: 5/5 passed on MoltenVK 1.4.2 and 5/5 on KosmicKrisp (Mesa 26.3.1), every case "dumped words exact".

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-24 21:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1276#issuecomment-7144669129) Tested `4e98025c` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `66d4f5aa3`: - `tests/semantic/test_buffer_oob_dst_sel.py` (with its `buffer_format_unreadable.asm` fixture): OK at this head; against `main`'s translator it fails 3 times, so the no-decoder path is covered. - GPU regression, `--filter cs_fmt`: 5/5 passed on **MoltenVK 1.4.2** and 5/5 on **KosmicKrisp** (Mesa 26.3.1), every case "dumped words exact". AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠Moriz82 on GitHub · 2026-11-25 03:41 UTC · original

Thanks for the MoltenVK and KosmicKrisp runs. #984 already brought the no-decoder path into main. The rebased head cb009ce6 keeps the stronger read assertion, including the control that must read from the expected address. All six focused CPU tests passed. The GPU runs above cover the earlier head.

AI-assisted.

**@⁠Moriz82** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1276#issuecomment-7152147261) Thanks for the MoltenVK and KosmicKrisp runs. #984 already brought the no-decoder path into main. The rebased head `cb009ce6` keeps the stronger read assertion, including the control that must read from the expected address. All six focused CPU tests passed. The GPU runs above cover the earlier head. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.