rdna2spirv: implicit samples read the T# FORMAT view in every dimension (SHADER-1404) #154

Closed
github-bot wants to merge 2 commits from gh-pr/154/head into gh-pr/154/base
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:30 UTC · original
ubiquitarianism:old-pr/9886 → main · +188 −16 · 7 files · 2 commits · closed without merging

Carried over from old PR 9886 by ruipedro-pinheiro in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9886, 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.
ruipedro-pinheiro: 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):

Claimed in the coordination issue as: SHADER-1404 — https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116603786

Depends on: none

What and why

image_sample chose the UINT/SINT sampled view the T# FORMAT selects only when the stage was ps and the dimension 2D (tools/rdna2spirv.py). An integer 2D-array, cube, 3D or 1D texture, and any implicit sample outside the pixel stage, was sampled through the float view: the result VGPRs held a converted float instead of the integer texel the measured T# FORMAT rule in docs/design.md returns.

Every image_sample form now takes the typed read that image_load, image_sample_l and image_sample_lz already take. The pixel stage keeps the implicit LOD as the quad derivatives, as Grad, at the width the dimension samples — two components for 2D, 2D-array and cube (the array layer is not differentiated), three for 3D, scalar for 1D — which is the vector OpDPdx differentiates. Outside the pixel stage there are no derivatives, so the sample is Lod 0. image_sample_c* stays on the float view (a depth compare takes a Dref view); the bias (_b) and offset (_o) forms are out of this change.

docs/design.md: the row "Implicit 2D pixel-shader integer samples" becomes "Implicit integer samples", with the dimension/stage rule and what is checked where.

Note: #9667 proposed the same fix on a base from before #9517 merged and was closed unmerged; main still had the 2D/ps-only condition.

Tested

Linux (CachyOS), Intel UHD Graphics 620 (CML GT2) through Mesa 26.2.5 (ANV), no game files. Python 3.14.8, SPIRV-Tools v2026.4 (spirv-as/spirv-val), LLVM 23.1.4 (llvm-mc).

  • python -I tests/semantic/test_sample_implicit_dims.py -v: 3 tests OK — every dimension in the pixel stage (the alias each dimension loads, the three sample types, the OpDPdx/OpDPdy width), the float view still sampled for a float format, and the compute stage as Lod %f0; spirv-as and spirv-val --target-env vulkan1.2 on every module.
  • python -I scripts/run_semantic_tests.py tests/semantic: 460 files, 6,049 tests, 2 files failed (test_exec_computed, test_image_atomics_guard). Both fail with the same counts on main at 2d53a80 without this change.
  • python -I -m unittest discover -s tests/semantic -p 'test_sample*.py' and -p 'test_image_gather4_variants.py': 31 and 13 tests OK.
  • No corpus run: no game files here, so no translate / spirv-val counts over the 26,503 shaders.
  • GPU (Mesa ANV, Intel UHD 620): python -I scripts/run_gpu_tests.py --build runtime/build --work /tmp/opencode/gputest --filter ps_sample_implicit — 3/3 pass. ps_sample_implicit_sint and ps_sample_implicit_uint keep the 2D path; the new ps_sample_implicit_uint_array samples the unsigned two-mip image through a one-layer 2D_ARRAY view (non-2D implicit sample), 4096/4096 pixels exact in each pass. With the translator at 2d53a80 the array fixture fails ((0,0): RGBA32F bits (0, 0, 0, 0) != (1065353216, 0, 0, 1065353216)), so the fixture catches the regression.

AI-assisted: yes (opencode, deepseek-v4.1-flash-free).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠Andretuta** on GitHub · 2026-11-24 02:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/154) `ubiquitarianism:old-pr/9886` → `main` · +188 −16 · 7 files · 2 commits · closed without merging > Carried over from **old PR 9886** by `ruipedro-pinheiro` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9886`, 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. > `ruipedro-pinheiro`: 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): Claimed in the coordination issue as: SHADER-1404 — https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116603786 Depends on: none ### What and why `image_sample` chose the UINT/SINT sampled view the T# FORMAT selects only when the stage was `ps` and the dimension 2D (`tools/rdna2spirv.py`). An integer 2D-array, cube, 3D or 1D texture, and any implicit sample outside the pixel stage, was sampled through the float view: the result VGPRs held a converted float instead of the integer texel the measured T# FORMAT rule in `docs/design.md` returns. Every `image_sample` form now takes the typed read that `image_load`, `image_sample_l` and `image_sample_lz` already take. The pixel stage keeps the implicit LOD as the quad derivatives, as `Grad`, at the width the dimension samples — two components for 2D, 2D-array and cube (the array layer is not differentiated), three for 3D, scalar for 1D — which is the vector `OpDPdx` differentiates. Outside the pixel stage there are no derivatives, so the sample is `Lod 0`. `image_sample_c*` stays on the float view (a depth compare takes a `Dref` view); the bias (`_b`) and offset (`_o`) forms are out of this change. `docs/design.md`: the row "Implicit 2D pixel-shader integer samples" becomes "Implicit integer samples", with the dimension/stage rule and what is checked where. Note: `#9667` proposed the same fix on a base from before `#9517` merged and was closed unmerged; `main` still had the 2D/`ps`-only condition. ### Tested Linux (CachyOS), Intel UHD Graphics 620 (CML GT2) through Mesa 26.2.5 (ANV), no game files. Python 3.14.8, SPIRV-Tools v2026.4 (`spirv-as`/`spirv-val`), LLVM 23.1.4 (`llvm-mc`). - `python -I tests/semantic/test_sample_implicit_dims.py -v`: 3 tests OK — every dimension in the pixel stage (the alias each dimension loads, the three sample types, the `OpDPdx`/`OpDPdy` width), the float view still sampled for a float format, and the compute stage as `Lod %f0`; `spirv-as` and `spirv-val --target-env vulkan1.2` on every module. - `python -I scripts/run_semantic_tests.py tests/semantic`: 460 files, 6,049 tests, 2 files failed (`test_exec_computed`, `test_image_atomics_guard`). Both fail with the same counts on `main` at `2d53a80` without this change. - `python -I -m unittest discover -s tests/semantic -p 'test_sample*.py'` and `-p 'test_image_gather4_variants.py'`: 31 and 13 tests OK. - No corpus run: no game files here, so no translate / `spirv-val` counts over the 26,503 shaders. - GPU (Mesa ANV, Intel UHD 620): `python -I scripts/run_gpu_tests.py --build runtime/build --work /tmp/opencode/gputest --filter ps_sample_implicit` — 3/3 pass. `ps_sample_implicit_sint` and `ps_sample_implicit_uint` keep the 2D path; the new `ps_sample_implicit_uint_array` samples the unsigned two-mip image through a one-layer 2D_ARRAY view (non-2D implicit sample), 4096/4096 pixels exact in each pass. With the translator at `2d53a80` the array fixture fails (`(0,0): RGBA32F bits (0, 0, 0, 0) != (1065353216, 0, 0, 1065353216)`), so the fixture catches the regression. AI-assisted: yes (opencode, deepseek-v4.1-flash-free). ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
image_sample took the UINT/SINT sampled view only in a 2D pixel shader, so an
integer 2D-array, cube, 3D or 1D texture, and any implicit sample outside the
pixel stage, was read through the float view: the result VGPRs held a
converted float instead of the integer texel the measured T# FORMAT rule
returns. Every image_sample form now takes the typed read image_load and the
explicit-LOD forms take. The pixel stage keeps the implicit LOD as Grad, at
the width the dimension takes (two components for 2D, 2D-array and cube,
three for 3D, scalar for 1D); outside it there are no derivatives and the
sample is Lod 0.

tests/semantic/test_sample_implicit_dims.py covers every dimension and the
compute stage on the CPU (the alias each dimension loads, the three sample
types, the Grad width, Lod 0 and spirv-val). Full semantic suite: 460 files,
6049 tests; test_exec_computed and test_image_atomics_guard fail with the same
counts on main (2d53a80) without this change.

AI-assisted: yes.
ps_sample_implicit_uint_array samples the two-mip unsigned image through a
one-layer 2D_ARRAY view, the non-2D typed implicit path: the gradients come
from (s, t) and the layer is rounded. vk_texture_test --two-mip-array-uint
binds that view at binding 3, check.py and run_gpu_tests.py register the
fixture. Passes on Intel UHD 620 (Mesa 26.2.5, ANV), 4096/4096 pixels in
both S# passes; with the pre-fix translator it reads zeros.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:38 +00:00
github-bot closed this pull request 2026-11-26 08:46:38 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:49 UTC · original

Thanks for this work on SHADER-1404. Closing this carried-over draft in favour of #225, which makes the same
translator change.

  • The image_sample lowering here is the same as #225's (typed read in every dimension, Grad in the PS,
    Lod 0 elsewhere).
  • #225 also adds UINT and SINT GPU fixtures on a 2D array and a 3D volume, and they fail on every pixel without
    the fix.
  • If you think something here is missing from #225, please say so on #225.

The old-pr/* branch stays; see #17 for the list of carried-over PRs.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/154#issuecomment-7142649152) Thanks for this work on SHADER-1404. Closing this carried-over draft in favour of #225, which makes the same translator change. - The `image_sample` lowering here is the same as #225's (typed read in every dimension, `Grad` in the PS, `Lod 0` elsewhere). - #225 also adds UINT and SINT GPU fixtures on a 2D array and a 3D volume, and they fail on every pixel without the fix. - If you think something here is missing from #225, please say so on #225. The `old-pr/*` branch stays; see #17 for the list of carried-over PRs. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

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