rdna2spirv: image_sample reads integer textures through the typed view in every dimension and stage (SHADER-1404) #132

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

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

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

SHADER-1404 (up for grabs in #9677; I could not claim it there because comments are limited to collaborators).

image_sample (implicit LOD) took the typed UINT/SINT read only in a 2D pixel shader. A UINT/SINT 2D-array, 3D, cube or 1D texture, or any integer texture sampled outside a pixel shader, went through the float view, so the VGPRs held a converted float instead of the integer texel. image_sample_l / image_sample_lz already used image_read_typed in every dimension.

Now image_sample uses image_read_typed in every dimension and stage:

  • In a pixel shader the implicit LOD becomes OpImageSampleExplicitLod ... Grad with OpDPdx/OpDPdy taken before the per-format branch, over the coordinates that have a derivative (grad_width): s for 1D; s, t for 2D, 2D-array and cube (its 6-layer 2D-array view, as the float path samples it); s, t, r for 3D. The array layer has no derivative.
  • Outside a pixel shader there are no derivatives, so the LOD is 0, as on the float path.

docs/design.md: the "in every dimension" contract row now covers image_sample and says how the implicit LOD is lowered.

Tested:

  • tests/semantic/test_sample_typed_dims.py: extended to image_sample (alias and sampled-image type per dimension, gradient width and the OpVectorShuffle for array/cube, LOD 0 in a vertex shader). The new cases fail on main (13 failures) and pass with this change.
  • Full translator suite, python -I scripts/run_semantic_tests.py tests/semantic: 459 files, 6048 tests. Four files fail identically with and without this change (test_exec_computed, test_image_atomics_guard, test_sopc_validation, test_unary_f16_validation); two of them need spirv-as/spirv-val, which are not installed here.
  • tests/test_docs_links.py, python -m compileall.
  • Not run: spirv-val on the new modules (the test has a spirv-val case, skipped here) and a GPU readback on a non-2D integer texture. GPU available for a fixture: NVIDIA RTX 3060 (Windows).

No game files. AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠Andretuta** on GitHub · 2026-11-24 02:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/132) `ubiquitarianism:old-pr/9863` → `main` · +163 −30 · 7 files · 2 commits · closed without merging > Carried over from **old PR 9863** by `raulmesa96` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9863`, 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. > `raulmesa96`: 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): SHADER-1404 (up for grabs in `#9677`; I could not claim it there because comments are limited to collaborators). `image_sample` (implicit LOD) took the typed UINT/SINT read only in a 2D pixel shader. A UINT/SINT 2D-array, 3D, cube or 1D texture, or any integer texture sampled outside a pixel shader, went through the float view, so the VGPRs held a converted float instead of the integer texel. `image_sample_l` / `image_sample_lz` already used `image_read_typed` in every dimension. Now `image_sample` uses `image_read_typed` in every dimension and stage: - In a pixel shader the implicit LOD becomes `OpImageSampleExplicitLod ... Grad` with `OpDPdx`/`OpDPdy` taken before the per-format branch, over the coordinates that have a derivative (`grad_width`): s for 1D; s, t for 2D, 2D-array and cube (its 6-layer 2D-array view, as the float path samples it); s, t, r for 3D. The array layer has no derivative. - Outside a pixel shader there are no derivatives, so the LOD is 0, as on the float path. `docs/design.md`: the "in every dimension" contract row now covers `image_sample` and says how the implicit LOD is lowered. Tested: - `tests/semantic/test_sample_typed_dims.py`: extended to `image_sample` (alias and sampled-image type per dimension, gradient width and the `OpVectorShuffle` for array/cube, LOD 0 in a vertex shader). The new cases fail on main (13 failures) and pass with this change. - Full translator suite, `python -I scripts/run_semantic_tests.py tests/semantic`: 459 files, 6048 tests. Four files fail identically with and without this change (`test_exec_computed`, `test_image_atomics_guard`, `test_sopc_validation`, `test_unary_f16_validation`); two of them need `spirv-as`/`spirv-val`, which are not installed here. - `tests/test_docs_links.py`, `python -m compileall`. - Not run: `spirv-val` on the new modules (the test has a `spirv-val` case, skipped here) and a GPU readback on a non-2D integer texture. GPU available for a fixture: NVIDIA RTX 3060 (Windows). No game files. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
image_sample (implicit LOD) took the typed UINT/SINT read only in a 2D pixel
shader, so an integer 2D-array, 3D, cube or 1D texture, or any integer texture
sampled outside a pixel shader, was read through the float view.

It now uses image_read_typed everywhere, like image_sample_l / _lz. In a pixel
shader the implicit LOD becomes explicit quad gradients over the coordinates
that have a derivative (1D: s; 2D, 2D-array, cube: s, t; 3D: s, t, r);
elsewhere the LOD is 0, as on the float path.

tests/semantic/test_sample_typed_dims.py covers the new forms; docs/design.md
contract row updated. No game files. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
New modes array-uint / array-sint bind vk_texture_test's 12-layer 8x8 array at
binding 3 as R8G8B8A8_UINT / _SINT, with the T# FORMAT to match, and check
every pixel of ps_sample_array_uint / ps_sample_array_sint: an implicit
image_sample of layer 3 must return the integer texel (32x, 32y, 60, 255),
each byte signed for SINT. run_gpu_tests.py runs both.

On an RTX 3060 (Windows) both pass (4096 exact pixels each), and so do the
existing cube and default modes. The pre-fix float path also passes there:
reading an integer view through a float-typed image is undefined in Vulkan and
that driver returned the same bits, so the fixtures check the typed path on
hardware but do not tell the paths apart on NVIDIA. docs/design.md says so.

No game files. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:45:46 +00:00
github-bot closed this pull request 2026-11-26 08:45:46 +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/132#issuecomment-7142646097) 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.