Skip to content

Translator: typed image_load fetches UINT/SINT formats from the sampled arrays (SHADER-151) - #1153

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ICUMADETHIS:shader-151-image-load-sampled
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
ICUMADETHIS:shader-151-image-load-sampled

Conversation

@ICUMADETHIS

@ICUMADETHIS ICUMADETHIS commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-151 (claim)

What and why

Every translated image_load on 1D/2D/2D-array/3D declared StorageImageReadWithoutFormat (and StorageImageWriteWithoutFormat, and Image1D for 1D), because its UINT/SINT branch, picked from the T# FORMAT at run time, read the uint/sint storage arrays (bindings 8–19) with OpImageRead. Intel Xe-LP has no shaderStorageImageReadWithoutFormat, so none of these shaders could run there (#619, found testing #863).

The storage path was also wrong in the real runtime, not only on Intel. bind_image in runtime/shims/d3d12_vulkan_device.cpp gives a read-only texture (an SRV) a sampled view only, in its own format, and prefers an index of 256 or more for it. The storage arrays hold only unordered-access views and 256 entries. So an image_load of an integer SRV read the fallback, or indexed past the end of a 256-entry array. Stencil-plane SRVs (8_UINT, D3D-75) can't have a storage view at all.

Now every typed image_load fetches (OpImageFetch) from the sampled array of its dimension (bindings 0, 3, 6, 5), where the runtime already binds each image's view in its own format. UINT/SINT formats go through uint/sint aliases of that array: the same set and binding, an OpTypeImage of %uint/%int. Vulkan allows several variables on one binding when the descriptor type fits, and requires the view's numeric format to match the image type that accesses it. Everything else goes through the float array, as before. A lookup miss (index 0, the RGBA8_UNORM fallback) takes the float path, so an integer alias never reads the float fallback; it returns zeros. No runtime change is needed.

Effect: shaders that only load declare neither without-format feature, and shaders that also store declare only the write one. In the hand-written GPU tests, cs_imgload was the only module declaring StorageImageReadWithoutFormat; with this change no module does.

Like the float path, the fetch goes through the texture path: it sees writes made before the dispatch, not ones made earlier in the same dispatch. This is written down in the docs/design.md row.

Also in this PR:

  • cs_imgload.asm / vk_store_test load: the uint and sint images are filled by a copy before the dispatch. The shader loads both texels and stores their sum (expected 100 - (8y + x)), so the test no longer reads back a texel it wrote earlier in the same dispatch. The harness gives each image its own index (1–3, with 0 as the fallback, as in the runtime) and its own-format view in binding 0. Its device is created without shaderStorageImageReadWithoutFormat, and it fails any module that declares StorageImageReadWithoutFormat.

  • vk_image_fuzz: no longer requires either without-format feature, so Xe-LP runs its cases instead of skipping all of them. Its R8G8B8A8_UINT/SINT cases (Tests: fuzz UINT/SINT image loads #1087) are now bound as sampled images, the way the runtime binds a read-only texture. Tests: fuzz UINT/SINT image loads #1087 had bound them as storage-only images, which a typed load no longer reads. The tools/image_fuzz.py docstring and docs/shader_validation.md are updated to match.

  • docs/design.md ("Typed image loads" row) and docs/shader_validation.md updated.

  • d16 loads (rdna2spirv: d16 image_load reads integer images through their uint/sint views #1136, now on main) keep rdna2spirv: d16 image_load reads integer images through their uint/sint views #1136's packing (two 16-bit results per VGPR, f16 RTE from the float view, the low 16 bits from the integer ones) and now read integer formats through the same aliases. So a Texture2D<min16uint> SRV, which only exists in the sampled arrays, is read too. tests/test_image_load_d16_typed.py now asserts the alias fetches (and no OpImageRead or StorageImageReadWithoutFormat) instead of the storage reads. cs_imgload_d16.asm follows the new vk_store_test load protocol: both pre-filled texels are read with d16 loads, the sint one is sign-extended from bit 15, and the sum is stored, with the same expected values as cs_imgload.

Related:

Tested

Windows 11 (build 26300), NVIDIA GeForce RTX 2080 Ti (Turing), driver 621.14, Vulkan SDK 1.4.363.0, MSVC 17.14, llvm-mc 21.1.8. Rebased on main 0d61c35; all numbers below are from the rebased commit.

  • tests/test_image_load_typed.py (new, stdlib; spirv-val when SPIRV-Tools is on PATH): capabilities, bindings and component types for every dimension, and the branch taken for all 512 FORMAT values, with a hit and with a miss. 6/6 pass; on main, 10 of its checks fail.
  • tests/test_image_load_d16_typed.py: 3/3; with main's translator, 3/3 fail.
  • runtime/test/shaders/build.py: 112 translated, 112 pass spirv-val, both on main and with this change. Modules declaring StorageImageReadWithoutFormat: 2 on main (cs_imgload, cs_imgload_d16), 0 with this change.
  • vk_store_test (cs_imgstore; cs_imgload and cs_imgload_d16 with load) with the validation layer and GPU-assisted validation: every texel correct, 0 validation errors. main's cs_imgload.spv and cs_imgload_d16.spv are both rejected by the new load mode.
  • A wave64 copy of cs_imgload (not committed), translated with and without --wave64-emulate: every texel correct.
  • check.py: 79 of 108 pass, 29 skipped (wave64 and mesh on NVIDIA), 0 failures. scripts/run_gpu_tests.py: 89/116 passed, 27 skipped; with LEONIDA_W64_EMULATE=1 --filter cs_: 58/58.
  • tools/image_fuzz.py: 90/90 over the six default formats, UINT/SINT included (seed 1); 200/200 (seed 2080); 60/60 with only R8G8B8A8_UINT/SINT and the validation layer on (seed 7).
  • ctest: 59/59 (gameinput disabled, no SDL3).
  • python -m unittest discover -s tests/semantic: OK. The stdlib test files: 137/137. The pytest set the CI translator job runs: 927 passed, 1 skipped.

Not run: the full shader corpus. I don't have the package on this PC, so translated and spirv-val counts over the 26,503 shaders before and after would help from someone who has it. Not checked on AMD or Intel hardware.

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.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@kapitche

Copy link
Copy Markdown
Contributor

Tested a8c9d93 on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6). This one is a big improvement for devices without shaderStorageImageReadWithoutFormat:

  • pytest tests/test_image_load_typed.py: 6 passed, 12 subtests. With main's tools/rdna2spirv.py, 10 fail. ctest: 54/54 on NVIDIA.
Intel UHD 770 (32.0.101.6129) RTX 4080 SUPER (32.0.16.1714)
--filter cs_img cs_imgload PASS, cs_imgstore PASS both PASS
image_fuzz.py --programs 30 --seed 1 30/30 match 30/30 match

On main this Intel GPU skipped every image_fuzz program ("lacks shaderStorageImageReadWithoutFormat"), and cs_imgload exited 77. Both now run and match.

Interaction with my #1144 (vk_store_test exit 77 → SKIP): still useful as a guard for cs_imgstore and for devices missing other features. But with this PR, cs_imgload no longer hits 77 here at all. #1136's cs_imgload_d16 may want the same typed path.

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested a8c9d93 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass.

  • Build: 0 warnings. ctest: 55/55 passed.
  • python -I tests/test_image_load_typed.py: 6 tests OK (1 skipped).
  • run_gpu_tests.py --filter cs_img: cs_imgload and cs_imgstore PASS (2/2).
  • Full GPU suite: 112/112 shaders translated and spirv-val valid, 83/110 passed, 27 skipped (the wave64-native tests on NVIDIA), 0 failed.
  • tools/image_fuzz.py: 8/8 programs that ran match.
  • GitHub shows this PR conflicting with main; I tested the PR head as it is.

AI-assisted. No game files.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

On 17d67dee7d7eb4e26470a104525790bff4e1f741 I checked a typed SRV at sampled binding 0, index 257, with a valid, distinguishable descriptor at index 1. The stock image fuzzer already allocates in the high range; this control distinguishes keeping the full index from an accidental 8-bit truncation. Both indices had the same numeric format and referenced the same texels. The low view exchanged R and B, and the high view used identity mapping. The pixel shader and its descriptor key were held fixed.

On both RTX 5080 and Radeon Graphics, an 8×8 R8G8B8A8_UINT pattern and a separate R8G8B8A8_SINT pattern each rendered all 4,096 RGBA32F pixels exactly. As a negative control I changed only the hash-table result from 257 to 257 & 255. All 4,096 pixels then exchanged just R/B in both formats on both GPUs. For example, SINT pixel (0,0) changed from (-1,60,64,-128) to (64,60,-1,-128). No Vulkan validation errors. Both shaders and textures were source-built. AI-assisted.

…ed arrays (SHADER-151)

UINT/SINT image_load read the uint/sint storage arrays with OpImageRead, so
every typed load declared StorageImageReadWithoutFormat (missing on Intel
Xe-LP, ItsNotRexed#619), and read-only integer textures, which the runtime binds only in
the sampled arrays, read the fallback or past the 256-entry storage arrays.
They now fetch through uint/sint aliases of the dimension's sampled array;
a lookup miss takes the float path.

vk_store_test load fills the images before the dispatch, runs without
shaderStorageImageReadWithoutFormat and fails a module that declares it.
vk_image_fuzz no longer requires the without-format features, and binds
its UINT/SINT cases (ItsNotRexed#1087) as sampled images, as the runtime binds a
read-only texture, instead of storage-only images.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ICUMADETHIS
ICUMADETHIS force-pushed the shader-151-image-load-sampled branch from 17d67de to fd17f11 Compare November 22, 2026 08:51

@whattheflop whattheflop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted independent verification of fd17f11a5c6e67fca1b8ff9e1e784f90c404197f on Windows 11 Pro (build 26200), Ryzen 7 9800X3D Radeon iGPU (1002:13c0), AMD proprietary Vulkan driver 25.10.30.02 (Windows driver 32.0.21030.2001).

I built only vk_store_test and assembled and translated the stock source fixtures cs_imgload and cs_imgload_d16. Both passed spirv-val --target-env vulkan1.2 and exited 0 in the head harness's load mode. Vulkan was restricted to the single AMD ICD in-process, with an empty implicit-layer directory. The loader showed Khronos core validation (SDK 1.4.363.0) on the instance and device for both runs, with zero validation errors or warnings.

  • Each fixture checked 192 texels across three 8×8 images. All 64 R32_UINT texels exactly matched 100 + (8y + x), all 64 R32_SINT texels exactly matched 100 - (8y + x), and all 64 RGBA8_UNORM texels passed the harness's tolerance. At (5,3), UINT was 129 and SINT was 71 in both runs. The d16 fixture exercises the low-16-bit integer loads and sign-extension of the negative SINT input.
  • Both head modules use typed sampled OpImageFetch at binding 0, with zero OpImageRead instructions and no StorageImageReadWithoutFormat capability. The device left shaderStorageImageReadWithoutFormat disabled. Both fixtures retain the write-without-format capability for their stores.
  • I also built the two stock modules from direct parent 0d61c357656d92334eef97facec1ae4f7b2b60b1 for static comparison. Both validated and both declare StorageImageReadWithoutFormat and contain two integer OpImageRead instructions each. The parent comparison was static only.
  • Focused Python checks passed 6/6 in test_image_load_typed.py and 3/3 in test_image_load_d16_typed.py (dmask 0x1, 0x3, 0x7) using uv-managed native CPython 3.12.13, WSL LLVM 21.1.8, and SDK SPIRV-Tools. All inputs were source-built fixtures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU test cs_imgload: typed image load fails on Intel Xe iGPU

6 participants