fix(agc): read 1D-array T#s through DIM 1D from their base slice #23688

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/23688 into main 2026-11-27 04:09:44 +00:00
MichonGoddijn231849 commented 2026-11-19 13:10:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-19T13:10:53Z.


What

A DIM 1D image_sample* or image_load through a 1D-array T# compiles to the plain 1D mode the recompiler already offers for 1D arrays. At binding it then failed with AGC graphics: guest texture dimension disagrees with the shader's declared image shape (shape 0, dimension 5). Only 2D reads of 2D arrays were narrowed to their base slice (the 2D reads of 2D arrays debt entry).

Measured on gfx1036, a DIM 1D access through a 1D-array T# reads slice BASE_ARRAY and ignores any further address VGPR. Such a binding is now narrowed the same way:

  • GuestTextureResource.cpp (FirstLayerDescriptor): narrows a 1D array as well as a 2D array.
  • ShaderResources.cpp:
    • firstLayerWords narrows a 1D shape over a 1D array and a 2D shape over a 2D array, and nothing else. A 1D array read through a 2D shape keeps its existing rows binding (layerRowsBinding).
    • the stage B binding and the image-table path mark a 1D shape over a 1D array as a first-layer read;
    • the narrowing log line names the dimension.
  • Texture.cpp: createFirstLayerView makes a 1D view of the base slice for a 1D array, and the first-layer sRGB view does the same.
  • Debt: a 1D reads of 1D arrays entry next to the 2D one.

Measurement: tools/hw-oracle on gfx1036. The source was a 64-texel 32_FLOAT 1D-array T# with six slices whose texels encode slice·100 + x, at BASE_ARRAY 0, 1 and 3. There were 32 rows per case, with u in [-0.2, 1.2], second VGPRs of 0, 0.5, 1, 2, 5 and -1, and integer x and y for the loads:

DIM 1D access hardware main, NVIDIA / AMD this branch, NVIDIA / AMD
image_sample_lz, image_sample, image_sample_l slice BASE_ARRAY, second VGPR ignored throws 32/32 each, at every BASE_ARRAY
image_load slice BASE_ARRAY, y ignored throws 32/32 at every BASE_ARRAY

DIM 1D_ARRAY through the same T# matched before and still does.

Tested

Windows 11 Pro 10.0.26200, MinGW Release build. ctest --test-dir build -R '^agc_driver_image|^agc_shader_memory$' -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 111/114 114/114 111/114 114/114
Insert instance layer "VK_LAYER_KHRONOS_validation" 112 112 112 112
was not found but was requested 0 0 0 0
VUID- 0 0 0 0

The three NVIDIA failures are the same on both sides: agc_driver_image_plane_address_on_line, agc_driver_image_sample_lod_clamp and agc_driver_image_sample_lod_clamp_shader_lane, known on this machine. agc_driver_graphics (which includes the FirstLayerDescriptor unit checks) passes.

  • agc_driver_image_one_dimensional_array covers:
    • its existing DIM 1D_ARRAY program;
    • the same program with DIM 1D at BASE_ARRAY 0 and 2: image_sample_lz and image_load must read slice BASE_ARRAY whatever the layer VGPR holds;
    • passes on both GPUs.
  • Negative check: against main's three driver files the test fails on both GPUs with the refusal above.
  • An earlier version of this change also narrowed 1D arrays bound through a 2D shape. That broke agc_driver_image_array_rows_past_layer_limit and agc_driver_image_array_window_past_layer_limit (a 1D array within maxImageArrayLayers was bound as rows of a 2D image). Pairing the shape with the array dimension in firstLayerWords fixed both, and the run above is with that fix.

tools/pr_overlap.py could not compare these files with 65 PRs that conflict with main. Of those, only #10193, #13928 and #13929 add a firstLayer line, in new device-image-key code for 2D arrays; none changes the paths edited here. #21944 (PS4 tile modes on 1D arrays) touches 1D arrays but not their narrowing. 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:5395536172 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23688). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-19T13:10:53Z. --- ### What A DIM 1D `image_sample*` or `image_load` through a 1D-array T# compiles to the plain 1D mode the recompiler already offers for 1D arrays. At binding it then failed with `AGC graphics: guest texture dimension disagrees with the shader's declared image shape (shape 0, dimension 5)`. Only 2D reads of 2D arrays were narrowed to their base slice (the `2D reads of 2D arrays` debt entry). Measured on gfx1036, a DIM 1D access through a 1D-array T# reads slice `BASE_ARRAY` and ignores any further address VGPR. Such a binding is now narrowed the same way: - **`GuestTextureResource.cpp` (`FirstLayerDescriptor`):** narrows a 1D array as well as a 2D array. - **`ShaderResources.cpp`:** - `firstLayerWords` narrows a 1D shape over a 1D array and a 2D shape over a 2D array, and nothing else. A 1D array read through a 2D shape keeps its existing rows binding (`layerRowsBinding`). - the stage B binding and the image-table path mark a 1D shape over a 1D array as a first-layer read; - the narrowing log line names the dimension. - **`Texture.cpp`:** `createFirstLayerView` makes a 1D view of the base slice for a 1D array, and the first-layer sRGB view does the same. - **Debt:** a `1D reads of 1D arrays` entry next to the 2D one. **Measurement:** `tools/hw-oracle` on gfx1036. The source was a 64-texel 32_FLOAT 1D-array T# with six slices whose texels encode slice·100 + x, at `BASE_ARRAY` 0, 1 and 3. There were 32 rows per case, with u in [-0.2, 1.2], second VGPRs of 0, 0.5, 1, 2, 5 and -1, and integer x and y for the loads: | DIM 1D access | hardware | `main`, NVIDIA / AMD | this branch, NVIDIA / AMD | | --- | --- | --- | --- | | `image_sample_lz`, `image_sample`, `image_sample_l` | slice `BASE_ARRAY`, second VGPR ignored | throws | 32/32 each, at every `BASE_ARRAY` | | `image_load` | slice `BASE_ARRAY`, y ignored | throws | 32/32 at every `BASE_ARRAY` | DIM 1D_ARRAY through the same T# matched before and still does. ### Tested Windows 11 Pro 10.0.26200, MinGW Release build. `ctest --test-dir build -R '^agc_driver_image|^agc_shader_memory$' -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 | 111/114 | 114/114 | 111/114 | 114/114 | | `Insert instance layer "VK_LAYER_KHRONOS_validation"` | 112 | 112 | 112 | 112 | | `was not found but was requested` | 0 | 0 | 0 | 0 | | `VUID-` | 0 | 0 | 0 | 0 | The three NVIDIA failures are the same on both sides: `agc_driver_image_plane_address_on_line`, `agc_driver_image_sample_lod_clamp` and `agc_driver_image_sample_lod_clamp_shader_lane`, known on this machine. `agc_driver_graphics` (which includes the `FirstLayerDescriptor` unit checks) passes. - `agc_driver_image_one_dimensional_array` covers: - its existing DIM 1D_ARRAY program; - the same program with DIM 1D at `BASE_ARRAY` 0 and 2: `image_sample_lz` and `image_load` must read slice `BASE_ARRAY` whatever the layer VGPR holds; - passes on both GPUs. - Negative check: against `main`'s three driver files the test fails on both GPUs with the refusal above. - An earlier version of this change also narrowed 1D arrays bound through a 2D shape. That broke `agc_driver_image_array_rows_past_layer_limit` and `agc_driver_image_array_window_past_layer_limit` (`a 1D array within maxImageArrayLayers was bound as rows of a 2D image`). Pairing the shape with the array dimension in `firstLayerWords` fixed both, and the run above is with that fix. `tools/pr_overlap.py` could not compare these files with 65 PRs that conflict with `main`. Of those, only #10193, #13928 and #13929 add a `firstLayer` line, in new device-image-key code for 2D arrays; none changes the paths edited here. #21944 (PS4 tile modes on 1D arrays) touches 1D arrays but not their narrowing. 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:46:54 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed — looks good

The reviewed code adds first-slice handling for sampled 1D reads of 1D-array textures; the inspected paths and test changes support the stated behavior.

What I ran

No build or tests were run in this review. The author reports hardware tests on Windows 11 with NVIDIA and AMD GPUs; those results were not independently verified.

Results

Check Result Note
Changed code review passed Inspected all five changed files
Build and tests not run Author reports passing targeted tests on both GPUs

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands or tests were run. The author-reported test results and hardware measurements were not independently verified. The full text of ShaderResources.cpp and Texture.cpp was excluded from the review folder; I read the changed hunks and relevant surrounding ranges through the pinned-head reader. I read the changed lines in all five files listed as reviewed in the manifest. No other files were excluded by files.json; that file was not available through the review reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003935558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23688#pullrequestreview-6003935558). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T07:46:54Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed code adds first-slice handling for sampled 1D reads of 1D-array textures; the inspected paths and test changes support the stated behavior. ## What I ran No build or tests were run in this review. The author reports hardware tests on Windows 11 with NVIDIA and AMD GPUs; those results were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Inspected all five changed files | | Build and tests | not run | Author reports passing targeted tests on both GPUs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No commands or tests were run. The author-reported test results and hardware measurements were not independently verified. The full text of `ShaderResources.cpp` and `Texture.cpp` was excluded from the review folder; I read the changed hunks and relevant surrounding ranges through the pinned-head reader. I read the changed lines in all five files listed as reviewed in the manifest. No other files were excluded by `files.json`; that file was not available through the review 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!23688
No description provided.