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

Open
opened 2026-11-26 20:17:21 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/225
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9959


📝 Commits (1)

  • 0b416ec rdna2spirv: image_sample* outside 2D selects the UINT/SINT sampled view (SHADER-1404)

📊 Changes

11 files changed (+558 additions, -37 deletions)

View changed files

📝 docs/design.md (+2 -1)
📝 runtime/test/shaders/check.py (+21 -0)
➕ runtime/test/shaders/ps_sample_array_sint.asm (+71 -0)
➕ runtime/test/shaders/ps_sample_array_uint.asm (+58 -0)
➕ runtime/test/shaders/ps_sample_volume_sint.asm (+71 -0)
➕ runtime/test/shaders/ps_sample_volume_uint.asm (+58 -0)
📝 runtime/test/vk_texture_test.cpp (+113 -27)
📝 scripts/run_gpu_tests.py (+6 -0)
➕ tests/semantic/test_sample_implicit_dims.py (+139 -0)
📝 tests/semantic/test_sample_typed_dims.py (+2 -2)
📝 tools/rdna2spirv.py (+17 -7)

📄 Description

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


🔄 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/225 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9959` --- ### 📝 Commits (1) - [`0b416ec`](https://github.com/ubiquitarianism/leonida/commit/0b416ec925ced03ba16dc9cc97b30c3991c9bb47) rdna2spirv: image_sample* outside 2D selects the UINT/SINT sampled view (SHADER-1404) ### 📊 Changes **11 files changed** (+558 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+2 -1) 📝 `runtime/test/shaders/check.py` (+21 -0) ➕ `runtime/test/shaders/ps_sample_array_sint.asm` (+71 -0) ➕ `runtime/test/shaders/ps_sample_array_uint.asm` (+58 -0) ➕ `runtime/test/shaders/ps_sample_volume_sint.asm` (+71 -0) ➕ `runtime/test/shaders/ps_sample_volume_uint.asm` (+58 -0) 📝 `runtime/test/vk_texture_test.cpp` (+113 -27) 📝 `scripts/run_gpu_tests.py` (+6 -0) ➕ `tests/semantic/test_sample_implicit_dims.py` (+139 -0) 📝 `tests/semantic/test_sample_typed_dims.py` (+2 -2) 📝 `tools/rdna2spirv.py` (+17 -7) </details> ### 📄 Description > 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#277
No description provided.