fix(shader): ignore texel offsets of samples and gathers through a cube T# #23498

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/23498 into main 2026-11-27 03:26:48 +00:00
MichonGoddijn231849 commented 2026-11-19 05:29:38 +00:00 (Migrated from github.com)

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


What

RDNA2 ignores the texel offset of a sample or gather through a cube T#, whatever the instruction's DIM. The recompiler applied it: an image_sample_lz_o or image_gather4_lz_o on a cube read the texel offset texels away, on both host GPUs.

MakeSampleSetup (SpirvImageEmitter.cpp) now drops the offset of every access whose image takes the cube mode (image.cube). The offset VGPR stays in the address layout, so the bias, compare, coordinate and LOD components after it keep their positions.

Measurement: tools/hw-oracle on gfx1036 (PC RDNA2). A 64x64 32_FLOAT cube T# held distinct values per texel and face. 32 coordinates were tried for each of eleven offsets, from (0, 0, 0) through (1, 0, 0), (2, -3, 0), (31, -32, 0), (-32, 31, 0), (0, 0, 1) and (1, 1, 5). Each offset instruction was compared with the same instruction without an offset:

instructions DIM filters rows equal to no offset
image_sample_o, _lz_o, _l_o, _b_o, _c_lz_o, image_gather4_o, _lz_o, _c_lz_o CUBE, 2D, 2D_ARRAY point, bilinear 32/32 for every offset
image_sample_cl_o, _b_cl_o, _c_o, _c_l_o, _c_b_o, image_gather4_l_o, _b_o, _cl_o, _c_o CUBE point 32/32 for every offset
control: all of the above on a 2D-array T# 2D_ARRAY point, bilinear 32/32 only at offsets (0, 0, 0) and (0, 0, 1) (a z offset doesn't move a 2D-array sample); 0-1/32 otherwise, except compare results, which saturate

An earlier run of the same comparison through the driver (agc_oracle_runner) matched hardware on 2/32 rows for image_gather4_lz_o and 0/32 for image_sample_lz_o on a cube, on both GPUs. Offsets of derivative samples (image_sample_d_o) are not measured; the debt entry says so.

Tested

Windows 11 Pro 10.0.26200, MinGW Release build. ctest --test-dir build -R <pattern> -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, on an NVIDIA GeForce RTX 5080 (610.74) and an AMD Radeon(TM) Graphics iGPU (gfx1036, 32.0.21045.16010). Each log shows the loader inserting the validation layer, none reports it missing, and there are no VUID- messages.

  • New agc_driver_image_sample_cube_offset test: 32 threads sample a 16x16 8_8_8_8_UNORM cube with offsets from (-2, -1) to (2, 1). Each thread runs image_sample_lz_o with DIM CUBE, image_gather4_lz_o with DIM CUBE, and image_sample_lz_o with DIM 2D_ARRAY through the same cube T#. Every result must be the un-offset texel or footprint. Passes on both GPUs.
  • Negative check: the same test against main's SpirvImageEmitter.cpp fails on both GPUs with image_sample_lz_o on a cube applied its texel offset: thread 0 (face 0, texel 2,2, offset -2,-1) component 0 is 0.
  • 29 related tests (agc_driver_image_sample*, image_gather*, cube, offset, color-compare, depth-plane sampling, resinfo dimension):
    • AMD: 29/29 pass.
    • NVIDIA: 27/29. The two failures are the known NVIDIA baseline failures on main (agc_driver_image_sample_lod_clamp, agc_driver_image_sample_lod_clamp_shader_lane).

tools/pr_overlap.py --branch could not compare SpirvImageEmitter.cpp against the PRs that conflict with main. No open PR I found changes MakeSampleSetup or cube offsets. 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:5389397362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23498). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-19T05:29:38Z. --- ### What RDNA2 ignores the texel offset of a sample or gather through a cube T#, whatever the instruction's DIM. The recompiler applied it: an `image_sample_lz_o` or `image_gather4_lz_o` on a cube read the texel `offset` texels away, on both host GPUs. `MakeSampleSetup` (`SpirvImageEmitter.cpp`) now drops the offset of every access whose image takes the cube mode (`image.cube`). The offset VGPR stays in the address layout, so the bias, compare, coordinate and LOD components after it keep their positions. **Measurement:** `tools/hw-oracle` on gfx1036 (PC RDNA2). A 64x64 32_FLOAT cube T# held distinct values per texel and face. 32 coordinates were tried for each of eleven offsets, from (0, 0, 0) through (1, 0, 0), (2, -3, 0), (31, -32, 0), (-32, 31, 0), (0, 0, 1) and (1, 1, 5). Each offset instruction was compared with the same instruction without an offset: | instructions | DIM | filters | rows equal to no offset | | --- | --- | --- | --- | | `image_sample_o`, `_lz_o`, `_l_o`, `_b_o`, `_c_lz_o`, `image_gather4_o`, `_lz_o`, `_c_lz_o` | CUBE, 2D, 2D_ARRAY | point, bilinear | 32/32 for every offset | | `image_sample_cl_o`, `_b_cl_o`, `_c_o`, `_c_l_o`, `_c_b_o`, `image_gather4_l_o`, `_b_o`, `_cl_o`, `_c_o` | CUBE | point | 32/32 for every offset | | control: all of the above on a 2D-array T# | 2D_ARRAY | point, bilinear | 32/32 only at offsets (0, 0, 0) and (0, 0, 1) (a z offset doesn't move a 2D-array sample); 0-1/32 otherwise, except compare results, which saturate | An earlier run of the same comparison through the driver (`agc_oracle_runner`) matched hardware on 2/32 rows for `image_gather4_lz_o` and 0/32 for `image_sample_lz_o` on a cube, on both GPUs. Offsets of derivative samples (`image_sample_d_o`) are not measured; the debt entry says so. ### Tested Windows 11 Pro 10.0.26200, MinGW Release build. `ctest --test-dir build -R <pattern> -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`, on an NVIDIA GeForce RTX 5080 (610.74) and an AMD Radeon(TM) Graphics iGPU (gfx1036, 32.0.21045.16010). Each log shows the loader inserting the validation layer, none reports it missing, and there are no `VUID-` messages. - New `agc_driver_image_sample_cube_offset` test: 32 threads sample a 16x16 8_8_8_8_UNORM cube with offsets from (-2, -1) to (2, 1). Each thread runs `image_sample_lz_o` with DIM CUBE, `image_gather4_lz_o` with DIM CUBE, and `image_sample_lz_o` with DIM 2D_ARRAY through the same cube T#. Every result must be the un-offset texel or footprint. Passes on both GPUs. - Negative check: the same test against `main`'s `SpirvImageEmitter.cpp` fails on both GPUs with `image_sample_lz_o on a cube applied its texel offset: thread 0 (face 0, texel 2,2, offset -2,-1) component 0 is 0`. - 29 related tests (`agc_driver_image_sample*`, `image_gather*`, cube, offset, color-compare, depth-plane sampling, resinfo dimension): - AMD: 29/29 pass. - NVIDIA: 27/29. The two failures are the known NVIDIA baseline failures on `main` (`agc_driver_image_sample_lod_clamp`, `agc_driver_image_sample_lod_clamp_shader_lane`). `tools/pr_overlap.py --branch` could not compare `SpirvImageEmitter.cpp` against the PRs that conflict with `main`. No open PR I found changes `MakeSampleSetup` or cube offsets. 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:52:20 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

The offset handling change is supported by the inspected emitter code; I did not run the reported GPU checks, so I cannot make a formal approval decision.

What I ran

  • Reviewed head b93370000645e2f4655740d43ad49824e8e21d25 in the prepared review materials.
  • Read description.md, commits.md, manifest.json, diff.patch, the new execution test, the changed emitter function and its relevant callers, and the added debt entry. All three changed files were included and read.
  • No repository tests or build commands were run. The author's reported GPU checks were not independently verified.

Results

Check Result Note
Source review passed Changed behavior and test inspected
Build and tests not run GPU results are author-reported

Findings

Blocking

None.

Non-blocking

  • ImageSampleCubeOffset.cpp directly exercises image_sample_lz_o and image_gather4_lz_o; the description reports hardware measurements for a broader range of sampling and gather instructions. Consider expanding the regression test to cover representative bias, compare, and explicit LOD variants, since preserving those address components is part of the change's stated goal. The emitter retains the offset slot in Layout and only disables its use for cube images. Changed test · Emitter change

Not verified

  • The described Windows GPU runs, negative check, validation-layer output, and PS5 behavior were not independently verified.
  • files.json was not available in the review folder; the manifest and directory listing show three changed files, each included and read. No additional excluded files were listed in the available materials.

To get this to a good state

Nothing is required. Optional: add regression coverage for additional sample variants that carry bias, compare, or LOD operands.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003968314 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23498#pullrequestreview-6003968314). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T07:52:20Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The offset handling change is supported by the inspected emitter code; I did not run the reported GPU checks, so I cannot make a formal approval decision. ## What I ran - Reviewed head `b93370000645e2f4655740d43ad49824e8e21d25` in the prepared review materials. - Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, the new execution test, the changed emitter function and its relevant callers, and the added debt entry. All three changed files were included and read. - No repository tests or build commands were run. The author's reported GPU checks were not independently verified. ## Results | Check | Result | Note | | --- | --- | --- | | Source review | passed | Changed behavior and test inspected | | Build and tests | not run | GPU results are author-reported | ## Findings ### Blocking None. ### Non-blocking - `ImageSampleCubeOffset.cpp` directly exercises `image_sample_lz_o` and `image_gather4_lz_o`; the description reports hardware measurements for a broader range of sampling and gather instructions. Consider expanding the regression test to cover representative bias, compare, and explicit LOD variants, since preserving those address components is part of the change's stated goal. The emitter retains the offset slot in `Layout` and only disables its use for cube images. [Changed test](https://github.com/boykopovar/AnyPS5/blob/b93370000645e2f4655740d43ad49824e8e21d25/core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleCubeOffset.cpp#L77-L80) · [Emitter change](https://github.com/boykopovar/AnyPS5/blob/b93370000645e2f4655740d43ad49824e8e21d25/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1538-L1542) ## Not verified - The described Windows GPU runs, negative check, validation-layer output, and PS5 behavior were not independently verified. - `files.json` was not available in the review folder; the manifest and directory listing show three changed files, each included and read. No additional excluded files were listed in the available materials. ## To get this to a good state Nothing is required. Optional: add regression coverage for additional sample variants that carry bias, compare, or LOD operands.
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!23498
No description provided.