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

Closed
opened 2026-11-26 20:20:48 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1276
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/shader-typed-reserved-formats


📝 Commits (1)

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

📊 Changes

2 files changed (+5 additions, -1 deletions)

View changed files

📝 tests/semantic/fixtures/buffer_format_unreadable.asm (+1 -0)
📝 tests/semantic/test_buffer_oob_dst_sel.py (+4 -1)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1276 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/shader-typed-reserved-formats` --- ### 📝 Commits (1) - [`cb009ce`](https://github.com/ubiquitarianism/leonida/commit/cb009ce6dad1dc57612f8c71210925416ab03811) rdna2spirv: skip the load of a typed buffer format with no decoder (SHADER-TYPED-RESERVED-FORMATS) ### 📊 Changes **2 files changed** (+5 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/fixtures/buffer_format_unreadable.asm` (+1 -0) 📝 `tests/semantic/test_buffer_oob_dst_sel.py` (+4 -1) </details> ### 📄 Description **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://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144611731)). 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:48 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1308
No description provided.