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

Open
github-bot wants to merge 1 commit from github-bot/gh-225 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:48 UTC · original
ubiquitarianism:old-pr/9959 → main · +558 −37 · 11 files · 1 commits · draft

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

**@⁠Andretuta** on GitHub · 2026-11-24 02:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/225) `ubiquitarianism:old-pr/9959` → `main` · +558 −37 · 11 files · 1 commits · draft > 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)
image_sample took the typed read (the float, UINT or SINT view the T# FORMAT
selects) only in a 2D pixel shader. 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; a d16 sample then narrowed the integer bits as
a float. image_sample_l / _lz already take the typed read in every dimension
(#9517); image_sample now does too. In the pixel stage the quad gradients are
taken before the format branch at the width Grad takes ((s, t) for 2D, 2D
array and cube, all three for 3D, one for 1D); elsewhere the sample is Lod 0.

Tests: tests/semantic/test_sample_implicit_dims.py (11 of its checks fail on
the translator before this change), and GPU fixtures ps_sample_array_uint/sint
and ps_sample_volume_uint/sint run by new vk_texture_test modes array-uint,
array-sint, volume-uint and volume-sint (an integer 12-layer 2D array at
binding 3 and a 128x128x4 volume at binding 6, each with a mip 1), wired into
check.py and scripts/run_gpu_tests.py. 4096/4096 pixels exact on RX 6800 XT
(RADV Mesa 26.2.7), RTX 3070 (NVIDIA 595.99.02) and llvmpipe; every pixel
fails with the translator before this change. Contract row in docs/design.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:49:21 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/225/head:github-bot/gh-225'
git switch 'github-bot/gh-225'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-225'
git switch 'github-bot/gh-225'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-225'
git switch 'github-bot/gh-225'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-225'
git switch 'main'
git merge --squash 'github-bot/gh-225'
git switch 'main'
git merge --ff-only 'github-bot/gh-225'
git switch 'main'
git merge 'github-bot/gh-225'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.