fix(shader): bind 2D textures to 3D samples with an LOD, bias or offset #23644

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/23644 into main 2026-11-27 04:08:22 +00:00
MichonGoddijn231849 commented 2026-11-19 11:38:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-19T11:38:04Z.


What

A DIM 3D image_sample, image_sample_l, image_sample_b or offset sample through a 2D or 2D-array T# threw image descriptor is incompatible with the static runtime image interface. The 2D and 2D-array modes for such accesses (#2023, 70d190cdd5) took only image_sample_lz, image_load and image_get_resinfo, because nothing else was measured.

  • ResourceTracker.cpp: flatVolumeSample accepts samples whose flags combine only level-zero, LOD, bias and offset. Samples with derivatives, comparison or an LOD clamp still keep the image out of these modes, and so do gathers, which a DIM 3D gather sends to the 3D gather emulation.
  • Debt: the 3D image accesses bound to a 2D or 2D-array T# entry gains these samples. It is rewritten gap-first to stay under 1000 characters, with the same facts.

No cache format change: flatVolumeCompatible is an existing field.

Measurement: tools/hw-oracle on gfx1036, 64 rows per case:

  • u and v in [-0.2, 1.2];
  • r from 0, 0.3, 0.5, 0.9, 1, -0.4, 1.7 and 7;
  • LOD and bias from -1 to 5;
  • offsets from -3 to 3 on every axis.

On a 2D T# (8x8 32_FLOAT, four levels, texel = level·1000 + row·10 + column):

access hardware DIM 3D = DIM 2D translated DIM 3D = translated DIM 2D, NVIDIA / AMD
image_sample_l, point / trilinear 64/64, 64/64 64/64, 64/64
image_sample, point / trilinear 64/64, 64/64 64/64, 64/64
image_sample_b, point / trilinear 64/64, 64/64 64/64, 64/64
image_sample_lz_o, point / trilinear 64/64, 64/64 64/64, 64/64
image_gather4_lz, image_gather4_l, image_gather4 64/64 each not changed

Against the hardware, the translated DIM 3D samples differ only where the translated DIM 2D ones already do:

  • trilinear image_sample_l on NVIDIA, 58/64 (NVIDIA's mip blend weights, already recorded in docs/dev/debt/shader.md);
  • trilinear image_sample and image_sample_b in compute, 0/64 on both GPUs (implicit LOD in compute shaders).

On a 2D-array T# (64x64 32_FLOAT, three layers, BASE_ARRAY 0 and 1, point and bilinear), image_sample_l, image_sample_b, image_sample, image_sample_lz and image_sample_lz_o with DIM 3D equal DIM 2D-array on hardware on 64/64 rows each. The translation matches the hardware on 64/64 on both GPUs in all 20 cases.

Tested

Windows 11 Pro 10.0.26200, MinGW Release build. ctest --test-dir build -R '^agc_driver_image_volume|^agc_driver_image_sample|^agc_driver_image_gather|^agc_shader_memory$|disk_cache' -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, on main and on this branch. The GPUs were an NVIDIA GeForce RTX 5080 (610.74) and an AMD Radeon(TM) Graphics iGPU (gfx1036, 32.0.21045.16010).

main NVIDIA main AMD branch NVIDIA branch AMD
Result 25/27 27/27 25/27 27/27
Insert instance layer "VK_LAYER_KHRONOS_validation" 21 21 21 21
was not found but was requested 0 0 0 0
VUID- 0 0 0 0

The two NVIDIA failures on both sides are agc_driver_image_sample_lod_clamp and agc_driver_image_sample_lod_clamp_shader_lane, the image_sample_d_cl MIN_LOD failure of #23232.

  • agc_driver_image_volume_address_on_plane:
    • It used to require the DIM 3D image_sample_l refusal. It now samples a two-level 16x16 2D texture through that instruction.
    • With r from 0 to 3 and LOD 0 it must read level 0's marker; with LOD 1 it must read level 1's. Reading r as the LOD would therefore fail.
    • Passes on both GPUs.
  • Negative check: with main's ResourceTracker.cpp, the test fails on both GPUs with image descriptor is incompatible with the static runtime image interface.

tools/pr_overlap.py could not compare ResourceTracker.cpp with 19 PRs that conflict with main. Of those, #10193, #13928, #13929, #20519 and #22424 only hash flatVolumeCompatible, and none changes the conditions. #20792 (3D stores on 2D T#s) changes stores, not samples. Not tested on a PS5.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5394146758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23644). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-19T11:38:04Z. --- ### What A DIM 3D `image_sample`, `image_sample_l`, `image_sample_b` or offset sample through a 2D or 2D-array T# threw `image descriptor is incompatible with the static runtime image interface`. The 2D and 2D-array modes for such accesses (#2023, `70d190cdd5`) took only `image_sample_lz`, `image_load` and `image_get_resinfo`, because nothing else was measured. - **`ResourceTracker.cpp`:** `flatVolumeSample` accepts samples whose flags combine only level-zero, LOD, bias and offset. Samples with derivatives, comparison or an LOD clamp still keep the image out of these modes, and so do gathers, which a DIM 3D gather sends to the 3D gather emulation. - **Debt:** the `3D image accesses bound to a 2D or 2D-array T#` entry gains these samples. It is rewritten gap-first to stay under 1000 characters, with the same facts. No cache format change: `flatVolumeCompatible` is an existing field. **Measurement:** `tools/hw-oracle` on gfx1036, 64 rows per case: - u and v in [-0.2, 1.2]; - r from 0, 0.3, 0.5, 0.9, 1, -0.4, 1.7 and 7; - LOD and bias from -1 to 5; - offsets from -3 to 3 on every axis. On a 2D T# (8x8 32_FLOAT, four levels, texel = level·1000 + row·10 + column): | access | hardware DIM 3D = DIM 2D | translated DIM 3D = translated DIM 2D, NVIDIA / AMD | | --- | --- | --- | | `image_sample_l`, point / trilinear | 64/64, 64/64 | 64/64, 64/64 | | `image_sample`, point / trilinear | 64/64, 64/64 | 64/64, 64/64 | | `image_sample_b`, point / trilinear | 64/64, 64/64 | 64/64, 64/64 | | `image_sample_lz_o`, point / trilinear | 64/64, 64/64 | 64/64, 64/64 | | `image_gather4_lz`, `image_gather4_l`, `image_gather4` | 64/64 each | not changed | Against the hardware, the translated DIM 3D samples differ only where the translated DIM 2D ones already do: - trilinear `image_sample_l` on NVIDIA, 58/64 (NVIDIA's mip blend weights, already recorded in `docs/dev/debt/shader.md`); - trilinear `image_sample` and `image_sample_b` in compute, 0/64 on both GPUs (implicit LOD in compute shaders). On a 2D-array T# (64x64 32_FLOAT, three layers, `BASE_ARRAY` 0 and 1, point and bilinear), `image_sample_l`, `image_sample_b`, `image_sample`, `image_sample_lz` and `image_sample_lz_o` with DIM 3D equal DIM 2D-array on hardware on 64/64 rows each. The translation matches the hardware on 64/64 on both GPUs in all 20 cases. ### Tested Windows 11 Pro 10.0.26200, MinGW Release build. `ctest --test-dir build -R '^agc_driver_image_volume|^agc_driver_image_sample|^agc_driver_image_gather|^agc_shader_memory$|disk_cache' -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`, on `main` and on this branch. The GPUs were an NVIDIA GeForce RTX 5080 (610.74) and an AMD Radeon(TM) Graphics iGPU (gfx1036, 32.0.21045.16010). | | `main` NVIDIA | `main` AMD | branch NVIDIA | branch AMD | | --- | --- | --- | --- | --- | | Result | 25/27 | 27/27 | 25/27 | 27/27 | | `Insert instance layer "VK_LAYER_KHRONOS_validation"` | 21 | 21 | 21 | 21 | | `was not found but was requested` | 0 | 0 | 0 | 0 | | `VUID-` | 0 | 0 | 0 | 0 | The two NVIDIA failures on both sides are `agc_driver_image_sample_lod_clamp` and `agc_driver_image_sample_lod_clamp_shader_lane`, the `image_sample_d_cl` MIN_LOD failure of #23232. - `agc_driver_image_volume_address_on_plane`: - It used to require the DIM 3D `image_sample_l` refusal. It now samples a two-level 16x16 2D texture through that instruction. - With r from 0 to 3 and LOD 0 it must read level 0's marker; with LOD 1 it must read level 1's. Reading r as the LOD would therefore fail. - Passes on both GPUs. - Negative check: with `main`'s `ResourceTracker.cpp`, the test fails on both GPUs with `image descriptor is incompatible with the static runtime image interface`. `tools/pr_overlap.py` could not compare `ResourceTracker.cpp` with 19 PRs that conflict with `main`. Of those, #10193, #13928, #13929, #20519 and #22424 only hash `flatVolumeCompatible`, and none changes the conditions. #20792 (3D stores on 2D T#s) changes stores, not samples. Not tested on a PS5. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-21 07:47:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:47:36Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and its targeted regression test support merging.

What I ran

Reviewed head 61dbcdfc9e1d3f8f085e1ca4595d9eddd8dcd61a. Read the prepared diff and changed lines, then inspected the relevant resource mode selection and texture descriptor setup using repo_read.py. No build or test command was run in this review.

Results

Check Result Note
Changed code review passed Three changed files reviewed
Build and tests not run Author reports Windows GPU runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

No build, automated test, or console run was performed. The author reports Windows 11 tests on NVIDIA RTX 5080 and AMD gfx1036; those results were not independently confirmed. Read: ImageVolumeAddressOnPlane.cpp, ResourceTracker.cpp, and fix-volume-samples-on-2d-tsharp.md. No changed files were excluded; files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003940982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23644#pullrequestreview-6003940982). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T07:47:36Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and its targeted regression test support merging. ## What I ran Reviewed head `61dbcdfc9e1d3f8f085e1ca4595d9eddd8dcd61a`. Read the prepared diff and changed lines, then inspected the relevant resource mode selection and texture descriptor setup using `repo_read.py`. No build or test command was run in this review. ## Results | Check | Result | Note | | --- | --- | --- | | Changed code review | passed | Three changed files reviewed | | Build and tests | not run | Author reports Windows GPU runs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No build, automated test, or console run was performed. The author reports Windows 11 tests on NVIDIA RTX 5080 and AMD gfx1036; those results were not independently confirmed. Read: `ImageVolumeAddressOnPlane.cpp`, `ResourceTracker.cpp`, and `fix-volume-samples-on-2d-tsharp.md`. No changed files were excluded; `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!23644
No description provided.