rdna2spirv: image_sample* outside 2D selects the UINT/SINT sampled view (SHADER-1404) #225

Closed
Andretuta wants to merge 1 commit from upstream-pr/225 into main
Andretuta commented 2026-11-24 02:48:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:48:24Z.


Carried over from old PR 9959 by slipperysquid in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9959, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
slipperysquid: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Item: SHADER-1404 (coordination issue #9677)

Depends on: none. It builds on #9517 (merged), which already sends image_sample_l / image_sample_lz through the typed read in every dimension. This PR adds the implicit image_sample, which was the form still left out. #9667 (closed, unmerged) covered the same translator change; this is a separate implementation, and it adds GPU fixtures.

What and why

Gen.image_op gave image_sample the typed read (the float, UINT or SINT view the T# FORMAT selects) only when stage == "ps" and dim == SQ_RSRC_IMG_2D. A 2D-array, cube, 3D or 1D implicit sample, and any implicit sample outside the pixel stage, read an integer texture through the float view. With d16, the result is wrong on every driver: the float path narrows the integer bits as a float, which gives 0 for small integer values. Without d16, the float-typed sample of an integer view is undefined in Vulkan, though RADV, NVIDIA and llvmpipe happen to return the integer bits.

What changed:

  • All three forms (image_sample, image_sample_l, image_sample_lz) now take image_read_typed in every dimension and stage.
  • In the pixel stage, the quad gradients are taken before the format branch, at the width Grad requires:
    • 2D, 2D-array and cube: (s, t). The array layer has no derivative, and a cube reads its 6-layer 2D-array view.
    • 3D: all three coordinates.
    • 1D: one coordinate.
  • Outside the pixel stage, the sample uses Lod 0, the same as the float path did.
  • The 2D pixel-shader module is unchanged.
  • image_sample_b, _cl, _d, _o and the _c* forms still read the float view, in every dimension including 2D. That is listed as an open follow-up below.

Runtime side: no change needed. The UINT/SINT aliases are declared on the dimension's own sampled binding (2D 0, 2D-array/cube 3, 1D 5, 3D 6; Gen.SAMPLED_BINDINGS). The runtime already binds each view in its own format there, which is what image_load relies on (SHADER-151).

Tests

Run on Linux 7.0.0, Python 3, SPIRV-Tools from the distro, llvm-mc 21 (/usr/lib/llvm-21/bin/llvm-mc).

  • New tests/semantic/test_sample_implicit_dims.py (6 tests, all pass). For each of the five dimensions it checks:

    • pixel shader: the alias access chains at the dimension's sampled binding, one OpDPdx/OpDPdy pair at the right width, and three Grad samples (float, uint, sint) with no implicit-LOD sample;
    • compute shader: three Lod %f0 samples and no derivatives;
    • the 2D-array and cube shuffle down to (s, t);
    • image_sample_b still reads the float view only;
    • spirv-val --target-env vulkan1.2 for image_sample / _l / _lz × 5 dims × {plain, d16, a16} × {ps, cs}.

    With LEONIDA_TOOLS_DIR pointing at the base translator, 11 subtests fail.

  • python -m unittest discover -s tests/semantic -p 'test_sample_*dims.py': 10 tests OK.

  • python -I scripts/run_semantic_tests.py tests/semantic:

    • this branch: 460 files, 6,052 tests, 2 files failed (test_exec_computed, test_image_atomics_guard);
    • base upstream/main (e56d9795), same test tree: the same 2 files fail, plus the new file.
    • No new failure.
  • python -m compileall -q make_game.py tools tests: OK.

  • python -I scripts/check_no_game_data.py on every new or changed file: clean.

GPU fixtures

New files:

  • runtime/test/shaders/ps_sample_array_uint.asm
  • runtime/test/shaders/ps_sample_array_sint.asm
  • runtime/test/shaders/ps_sample_volume_uint.asm
  • runtime/test/shaders/ps_sample_volume_sint.asm

They run through new vk_texture_test modes array-uint, array-sint, volume-uint and volume-sint, wired into check.py (SAMPLE_DIMS_TESTS) and scripts/run_gpu_tests.py.

Each mode binds an RGBA8 UINT or SINT texture whose T# names that format:

  • array-*: a 12-layer 128x128 2D array at binding 3, with a 64x64 mip 1;
  • volume-*: a 128x128x4 volume at a binding 6 the mode adds, with a 64x64x2 mip 1.

Each shader samples the texture three ways, at different layers or slices:

  • a d16 image_sample, whose implicit LOD is 1;
  • a d16 image_sample_l at LOD 0;
  • a full-width image_sample_lz.

The channels are packed so that a wrong value or a wrong sign extension spills into a neighbouring byte, and every pixel is compared in the harness.

Device Driver This branch Base translator (e56d9795)
AMD Radeon RX 6800 XT (RADV NAVI21) Mesa 26.2.7 (kisak PPA), Vulkan 1.4.354 4 / 4 modes, 4096/4096 pixels exact all 4 modes fail, 4096/4096 pixels wrong (the image_sample channels read 0)
NVIDIA GeForce RTX 3070 595.99.02, Vulkan 1.4.329 4 / 4, 4096/4096 exact all 4 fail, 4096/4096 wrong
llvmpipe (LLVM 21.1.8) Mesa 26.2.7 4 / 4, 4096/4096 exact all 4 fail, 4096/4096 wrong

On RADV and NVIDIA the new modes also run clean under VK_LAYER_KHRONOS_validation, with 0 validation errors.

Full python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc:

  • RADV: 232/252 passed, 16 skipped.
  • NVIDIA: 199/252 passed, 49 skipped.
  • ps_cube_sample, ps_array_resinfo and ps_get_lod_array pass on both. ps_cube_sample is the one existing fixture whose SPIR-V this change alters.
  • The remaining failures are cs_imgload_tfe, cs_imgload_d16_tfe, cs_w32_exec_computed, cs_w64_exec_computed (RADV) and ms_wave_info_s3 (NVIDIA). They are not from this change: their SPIR-V is byte-identical between base and this branch.
  • ps_m2_array's SPIR-V also changes (an image_sample on a 2D array), but it is only run by the Windows d3d12_m2_formats_test and was not run here.

Open questions / follow-ups

  • image_sample_b, _cl, _d, _o and _c* still sample the float view of an integer T# in every dimension, including 2D. Bias and MinLod cannot be combined with the Grad operands the typed branch uses, so they need their own rule.
  • Not GPU-checked here: cube and 1D integer samples. The cube case reads the same 2D-array alias and binding as the array fixture; 1D is only covered by the semantic test and spirv-val. Non-pixel-stage implicit samples are also CPU-only.

AI-assisted: yes (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Fixtures are hand-written .asm.
  • The new translator rule is in the contract table of docs/design.md, with how it was confirmed. The #9517 row now names this GPU check.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465136929 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:48:24Z. --- > Carried over from **old PR 9959** by `slipperysquid` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9959`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `slipperysquid`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Item: **SHADER-1404** (coordination issue `#9677`) Depends on: none. It builds on `#9517` (merged), which already sends `image_sample_l` / `image_sample_lz` through the typed read in every dimension. This PR adds the implicit `image_sample`, which was the form still left out. `#9667` (closed, unmerged) covered the same translator change; this is a separate implementation, and it adds GPU fixtures. ### What and why `Gen.image_op` gave `image_sample` the typed read (the float, UINT or SINT view the T# FORMAT selects) only when `stage == "ps"` and `dim == SQ_RSRC_IMG_2D`. A 2D-array, cube, 3D or 1D implicit sample, and any implicit sample outside the pixel stage, read an integer texture through the float view. With d16, the result is wrong on every driver: the float path narrows the integer bits as a float, which gives 0 for small integer values. Without d16, the float-typed sample of an integer view is undefined in Vulkan, though RADV, NVIDIA and llvmpipe happen to return the integer bits. What changed: - All three forms (`image_sample`, `image_sample_l`, `image_sample_lz`) now take `image_read_typed` in every dimension and stage. - In the pixel stage, the quad gradients are taken before the format branch, at the width `Grad` requires: - 2D, 2D-array and cube: (s, t). The array layer has no derivative, and a cube reads its 6-layer 2D-array view. - 3D: all three coordinates. - 1D: one coordinate. - Outside the pixel stage, the sample uses `Lod 0`, the same as the float path did. - The 2D pixel-shader module is unchanged. - `image_sample_b`, `_cl`, `_d`, `_o` and the `_c*` forms still read the float view, in every dimension including 2D. That is listed as an open follow-up below. Runtime side: no change needed. The UINT/SINT aliases are declared on the dimension's own sampled binding (2D 0, 2D-array/cube 3, 1D 5, 3D 6; `Gen.SAMPLED_BINDINGS`). The runtime already binds each view in its own format there, which is what `image_load` relies on (SHADER-151). ### Tests Run on Linux 7.0.0, Python 3, SPIRV-Tools from the distro, llvm-mc 21 (`/usr/lib/llvm-21/bin/llvm-mc`). - **New `tests/semantic/test_sample_implicit_dims.py`** (6 tests, all pass). For each of the five dimensions it checks: - pixel shader: the alias access chains at the dimension's sampled binding, one `OpDPdx`/`OpDPdy` pair at the right width, and three `Grad` samples (float, uint, sint) with no implicit-LOD sample; - compute shader: three `Lod %f0` samples and no derivatives; - the 2D-array and cube shuffle down to (s, t); - `image_sample_b` still reads the float view only; - `spirv-val --target-env vulkan1.2` for `image_sample` / `_l` / `_lz` × 5 dims × {plain, d16, a16} × {ps, cs}. With `LEONIDA_TOOLS_DIR` pointing at the base translator, 11 subtests fail. - **`python -m unittest discover -s tests/semantic -p 'test_sample_*dims.py'`**: 10 tests OK. - **`python -I scripts/run_semantic_tests.py tests/semantic`**: - this branch: 460 files, 6,052 tests, 2 files failed (`test_exec_computed`, `test_image_atomics_guard`); - base `upstream/main` (e56d9795), same test tree: the same 2 files fail, plus the new file. - No new failure. - **`python -m compileall -q make_game.py tools tests`**: OK. - **`python -I scripts/check_no_game_data.py`** on every new or changed file: clean. #### GPU fixtures New files: - `runtime/test/shaders/ps_sample_array_uint.asm` - `runtime/test/shaders/ps_sample_array_sint.asm` - `runtime/test/shaders/ps_sample_volume_uint.asm` - `runtime/test/shaders/ps_sample_volume_sint.asm` They run through new `vk_texture_test` modes `array-uint`, `array-sint`, `volume-uint` and `volume-sint`, wired into `check.py` (`SAMPLE_DIMS_TESTS`) and `scripts/run_gpu_tests.py`. Each mode binds an RGBA8 UINT or SINT texture whose T# names that format: - `array-*`: a 12-layer 128x128 2D array at binding 3, with a 64x64 mip 1; - `volume-*`: a 128x128x4 volume at a binding 6 the mode adds, with a 64x64x2 mip 1. Each shader samples the texture three ways, at different layers or slices: - a d16 `image_sample`, whose implicit LOD is 1; - a d16 `image_sample_l` at LOD 0; - a full-width `image_sample_lz`. The channels are packed so that a wrong value or a wrong sign extension spills into a neighbouring byte, and every pixel is compared in the harness. | Device | Driver | This branch | Base translator (e56d9795) | |---|---|---|---| | AMD Radeon RX 6800 XT (RADV NAVI21) | Mesa 26.2.7 (kisak PPA), Vulkan 1.4.354 | 4 / 4 modes, 4096/4096 pixels exact | all 4 modes fail, 4096/4096 pixels wrong (the `image_sample` channels read 0) | | NVIDIA GeForce RTX 3070 | 595.99.02, Vulkan 1.4.329 | 4 / 4, 4096/4096 exact | all 4 fail, 4096/4096 wrong | | llvmpipe (LLVM 21.1.8) | Mesa 26.2.7 | 4 / 4, 4096/4096 exact | all 4 fail, 4096/4096 wrong | On RADV and NVIDIA the new modes also run clean under `VK_LAYER_KHRONOS_validation`, with 0 validation errors. **Full `python -I scripts/run_gpu_tests.py --llvm-mc /usr/lib/llvm-21/bin/llvm-mc`:** - RADV: 232/252 passed, 16 skipped. - NVIDIA: 199/252 passed, 49 skipped. - `ps_cube_sample`, `ps_array_resinfo` and `ps_get_lod_array` pass on both. `ps_cube_sample` is the one existing fixture whose SPIR-V this change alters. - The remaining failures are `cs_imgload_tfe`, `cs_imgload_d16_tfe`, `cs_w32_exec_computed`, `cs_w64_exec_computed` (RADV) and `ms_wave_info_s3` (NVIDIA). They are not from this change: their SPIR-V is byte-identical between base and this branch. - `ps_m2_array`'s SPIR-V also changes (an `image_sample` on a 2D array), but it is only run by the Windows `d3d12_m2_formats_test` and was not run here. ### Open questions / follow-ups - `image_sample_b`, `_cl`, `_d`, `_o` and `_c*` still sample the float view of an integer T# in every dimension, including 2D. Bias and MinLod cannot be combined with the `Grad` operands the typed branch uses, so they need their own rule. - Not GPU-checked here: cube and 1D integer samples. The cube case reads the same 2D-array alias and binding as the array fixture; 1D is only covered by the semantic test and `spirv-val`. Non-pixel-stage implicit samples are also CPU-only. AI-assisted: yes (Claude Code). ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Fixtures are hand-written `.asm`. - [x] The new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. The `#9517` row now names this GPU check. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fiestorra commented 2026-11-30 10:00:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T10:00:36Z.


Independent verification on this machine (Windows 11, Python 3.13 / pytest 9.2.0), with a negative control that bites on eleven tests.

1. It applies. merge-tree clean; the commits cherry-pick onto main 4014af7fe without a conflict. Eleven files: tools/rdna2spirv.py (the change), four new .asm shaders, runtime/test/shaders/check.py, runtime/test/vk_texture_test.cpp, two tests/semantic/ modules, scripts/run_gpu_tests.py, docs/design.md.

2. The semantic tests it touches pass:

python3 -m pytest tests/semantic/test_sample_typed_dims.py tests/semantic/test_sample_implicit_dims.py -q
10 passed, 122 subtests passed in 5.12s

3. The control - revert only the translator, keep every test:

git checkout origin/main -- tools/rdna2spirv.py
python3 -m pytest … -q
11 failed, 10 passed, 111 subtests passed in 4.64s

Eleven of the twenty-one cases detect the translator change on their own. That is the strongest control I have run on this queue so far: no device, no build, and the delta is a number of tests rather than one assertion.

4. What the change is, from the diff: the T# FORMAT rule for implicit image_sample is extended from pixel-stage 2D to every dimension and stage, and image_sample_l / _lz now take the typed read as well, so an integer 2D array or volume samples as UINT/SINT instead of being treated as a float sampling operation. The commit message in the diff calls it SHADER-1404.

What I did not test: the C++ half (runtime/test/vk_texture_test.cpp and the four new .asm shaders, which need the GPU path), and whether the new rule matches the hardware on cases the semantic tests do not enumerate. What I established is that the Python semantic layer fails without the tool change - which is the part a reviewer cannot see by reading the tool alone.

Why I am commenting: I verify open pull requests that replay onto current main, run the tests they touch, and then revert only the source change to see which tests stop passing. Fourteen controls so far: nine bite, three do not, two are compile-level only.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7274986145 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225#issuecomment-7274986145). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T10:00:36Z. --- Independent verification on this machine (Windows 11, Python 3.13 / pytest 9.2.0), with a negative control that bites on eleven tests. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `4014af7fe` without a conflict. Eleven files: `tools/rdna2spirv.py` (the change), four new `.asm` shaders, `runtime/test/shaders/check.py`, `runtime/test/vk_texture_test.cpp`, two `tests/semantic/` modules, `scripts/run_gpu_tests.py`, `docs/design.md`. **2. The semantic tests it touches pass:** ``` python3 -m pytest tests/semantic/test_sample_typed_dims.py tests/semantic/test_sample_implicit_dims.py -q 10 passed, 122 subtests passed in 5.12s ``` **3. The control - revert only the translator, keep every test:** ``` git checkout origin/main -- tools/rdna2spirv.py python3 -m pytest … -q 11 failed, 10 passed, 111 subtests passed in 4.64s ``` **Eleven of the twenty-one cases detect the translator change on their own.** That is the strongest control I have run on this queue so far: **no device, no build, and the delta is a number of tests rather than one assertion.** **4. What the change is, from the diff:** the T# FORMAT rule for implicit `image_sample` is extended from pixel-stage 2D to **every dimension and stage**, and `image_sample_l` / `_lz` now take the typed read as well, so an integer 2D array or volume samples as `UINT`/`SINT` instead of being treated as a float sampling operation. The commit message in the diff calls it `SHADER-1404`. **What I did not test:** the C++ half (`runtime/test/vk_texture_test.cpp` and the four new `.asm` shaders, which need the GPU path), and whether the new rule matches the hardware on cases the semantic tests do not enumerate. **What I established is that the Python semantic layer fails without the tool change** - which is the part a reviewer cannot see by reading the tool alone. **Why I am commenting:** I verify open pull requests that replay onto current `main`, run the tests they touch, and then revert **only** the source change to see which tests stop passing. **Fourteen controls so far: nine bite, three do not, two are compile-level only.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:00:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:00:24Z.

Review: COMMENTED


Draft review against current main: extending typed UINT/SINT sampled view selection for image_sample* outside 2D in tools/rdna2spirv.py:13249 is clean-room verified, but this branch conflicts with main and has cancelled CI. Please rebase onto current main and mark Ready for Review so CI runs green.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130845944 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225#pullrequestreview-6130845944). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:00:24Z. **Review:** COMMENTED --- Draft review against current `main`: extending typed UINT/SINT sampled view selection for `image_sample*` outside 2D in `tools/rdna2spirv.py:13249` is clean-room verified, but this branch conflicts with `main` and has cancelled CI. Please rebase onto current `main` and mark Ready for Review so CI runs green. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:14:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:14:43Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310856775 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225#issuecomment-7310856775). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:14:43Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 12:58:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:58:02Z.

Review: CHANGES_REQUESTED


Now ready for review, requesting changes before merge:

  • Merge conflicts (CONFLICTING/DIRTY): conflicts with main across docs/design.md, runtime/test/shaders/check.py, scripts/run_gpu_tests.py, and tools/rdna2spirv.py.
  • CI: all checks from 2026-11-24 were cancelled. Please rebase onto current main and run fresh green CI.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131702692 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225#pullrequestreview-6131702692). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:58:02Z. **Review:** CHANGES_REQUESTED --- Now ready for review, requesting changes before merge: - **Merge conflicts (`CONFLICTING`/`DIRTY`)**: conflicts with `main` across `docs/design.md`, `runtime/test/shaders/check.py`, `scripts/run_gpu_tests.py`, and `tools/rdna2spirv.py`. - **CI**: all checks from 2026-11-24 were cancelled. Please rebase onto current `main` and run fresh green CI. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:29:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:29:08Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317684183 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/225#issuecomment-7317684183). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:29:08Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!225
No description provided.