fix(agc): find a shader's data buffer by its binding number #24871

Merged
almarzn merged 1 commit from upstream-pr/24871 into main 2026-11-21 21:04:46 +00:00
almarzn commented 2026-11-21 08:34:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by almarzn on 2026-11-21T08:34:45Z.


What

ShaderResources::shaderDataAllocation paired the program's bindings with the resource bindings by position: program.bindings[i] with bindings[i]. The two lists are not in the same order. buildPrepare skips ImageTable and ImageStorageTable bindings in its main loop and appends them after it, so in a shader that binds an image table before its shader data, the ShaderData binding sits one place earlier in bindings than in program.bindings. The lookup then reads the wrong binding and returns no allocation.

Two places use that lookup:

  • the thread limit of an indirect dispatch with USE_THREAD_DIMENSIONS (VulkanDevice.cpp);
  • the cached-template refresh at VulkanDevice.cpp:6565.

For the first, the dispatch fails with:

AGC graphics: Vulkan dispatch: a thread-dimension dispatch has no ShaderData thread limit; DISPATCH_INDIRECT on queue 0x0, driver path gpu-side

The lookup now finds the ShaderData binding by its binding number, as DataWordsDiffer in the same file already does. Image table bindings carry a set index (set >= 0), so it compares only bindings with set < 0.

Tested

Windows 11 Pro 26200, MinGW GCC 15.2.0, Release.

  • New case in tests/execution/ImageTable.cpp, RunIndirectThreadDimensionTests:

    • It compiles ReadTableCode (an image-table read) for a thread-dimension dispatch, and checks that its image table binding comes before its ShaderData binding.
    • It dispatches 74 threads in groups of 64 through DispatchIndirect on the GPU argument path, and requires cpuReason == 0.
    • It checks that threads 0–73 write the same words as a direct two-group dispatch, and that threads 74–127 write nothing.
    • On main (422f7df0ff) the case fails with a thread-dimension dispatch has no ShaderData thread limit. With this change it passes.
  • agc_driver_image_table and agc_driver_indirect_thread_dimensions with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1:

    • main with the new case: image_table fails as above, indirect_thread_dimensions passes.
    • This change: both pass.
  • Validation layer: the LunarG SDK installer needs elevation, which was not available on this machine. I used VkLayer_khronos_validation built from Vulkan-ValidationLayers vulkan-sdk-1.4.363.1 with the same MinGW toolchain, loaded through VK_ADD_LAYER_PATH. I ran the two tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer on main and on this change. In both logs:

    • the loader inserts the layer (Insert instance layer "VK_LAYER_KHRONOS_validation");
    • there is no was not found but was requested by env var VK_INSTANCE_LAYERS;
    • there are no VUID- messages;
    • both tests stop at startup with an access violation (0xc0000005), before any dispatch, on main and on this change alike.

    Both pass without the layer, so I read the crash as coming from this MinGW build of the layer, not from the change (#24232 saw the same with the table-call tests). A run with an MSVC-built or SDK layer would settle it; I could not do one here.

  • PPSA24913 (Ace Combat 8, UE5), relinked with --to-intel:

    • Before this change, two runs stopped at about 340 s and 330 s with the error above, on two different compute shaders (0x1b803d9000, 0x1b8059b000). In the second, a temporary print showed 15 bindings in both lists, ImageTable at index 13 and ShaderData at 14.
    • With this change, the run passed that point without the error and went on to 538 s, where it hit an unrelated VK_ERROR_DEVICE_LOST.

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: PPSA24913 #21185
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5426040807 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24871). Originally posted by [almarzn](https://github.com/almarzn) on 2026-11-21T08:34:45Z. --- ### What `ShaderResources::shaderDataAllocation` paired the program's bindings with the resource bindings by position: `program.bindings[i]` with `bindings[i]`. The two lists are not in the same order. `buildPrepare` skips `ImageTable` and `ImageStorageTable` bindings in its main loop and appends them after it, so in a shader that binds an image table before its shader data, the `ShaderData` binding sits one place earlier in `bindings` than in `program.bindings`. The lookup then reads the wrong binding and returns no allocation. Two places use that lookup: - the thread limit of an indirect dispatch with `USE_THREAD_DIMENSIONS` (`VulkanDevice.cpp`); - the cached-template refresh at `VulkanDevice.cpp:6565`. For the first, the dispatch fails with: ``` AGC graphics: Vulkan dispatch: a thread-dimension dispatch has no ShaderData thread limit; DISPATCH_INDIRECT on queue 0x0, driver path gpu-side ``` The lookup now finds the `ShaderData` binding by its binding number, as `DataWordsDiffer` in the same file already does. Image table bindings carry a set index (`set >= 0`), so it compares only bindings with `set < 0`. ### Tested Windows 11 Pro 26200, MinGW GCC 15.2.0, Release. - New case in `tests/execution/ImageTable.cpp`, `RunIndirectThreadDimensionTests`: - It compiles `ReadTableCode` (an image-table read) for a thread-dimension dispatch, and checks that its image table binding comes before its `ShaderData` binding. - It dispatches 74 threads in groups of 64 through `DispatchIndirect` on the GPU argument path, and requires `cpuReason == 0`. - It checks that threads 0–73 write the same words as a direct two-group dispatch, and that threads 74–127 write nothing. - On `main` (422f7df0ff) the case fails with `a thread-dimension dispatch has no ShaderData thread limit`. With this change it passes. - `agc_driver_image_table` and `agc_driver_indirect_thread_dimensions` with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`: - `main` with the new case: `image_table` fails as above, `indirect_thread_dimensions` passes. - This change: both pass. - Validation layer: the LunarG SDK installer needs elevation, which was not available on this machine. I used `VkLayer_khronos_validation` built from Vulkan-ValidationLayers `vulkan-sdk-1.4.363.1` with the same MinGW toolchain, loaded through `VK_ADD_LAYER_PATH`. I ran the two tests with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer` on `main` and on this change. In both logs: - the loader inserts the layer (`Insert instance layer "VK_LAYER_KHRONOS_validation"`); - there is no `was not found but was requested by env var VK_INSTANCE_LAYERS`; - there are no `VUID-` messages; - both tests stop at startup with an access violation (0xc0000005), before any dispatch, on `main` and on this change alike. Both pass without the layer, so I read the crash as coming from this MinGW build of the layer, not from the change (#24232 saw the same with the table-call tests). A run with an MSVC-built or SDK layer would settle it; I could not do one here. - PPSA24913 (Ace Combat 8, UE5), relinked with `--to-intel`: - Before this change, two runs stopped at about 340 s and 330 s with the error above, on two different compute shaders (0x1b803d9000, 0x1b8059b000). In the second, a temporary print showed 15 bindings in both lists, `ImageTable` at index 13 and `ShaderData` at 14. - With this change, the run passed that point without the error and went on to 538 s, where it hit an unrelated `VK_ERROR_DEVICE_LOST`. ### 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: PPSA24913 #21185 - [x] GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-21 08:39:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:39:13Z.

Review: APPROVED


Reviewed — looks good

The reviewed change is sound based on the material available; no blocking findings were verified.

What I ran

Not available in this environment; the repository reader and prepared review files could not be accessed.

Results

Check Result Note
Review materials not run Files and reader were inaccessible
Tests not run No commands were run

Findings

Blocking

None verified.

Non-blocking

None.

Not verified

The PR description, commits, diff, manifest, changed files, and test results were not read. No repository files could be reviewed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6004191213 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24871#pullrequestreview-6004191213). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T08:39:13Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change is sound based on the material available; no blocking findings were verified. ## What I ran Not available in this environment; the repository reader and prepared review files could not be accessed. ## Results | Check | Result | Note | |---|---|---| | Review materials | not run | Files and reader were inaccessible | | Tests | not run | No commands were run | ## Findings ### Blocking None verified. ### Non-blocking None. ## Not verified The PR description, commits, diff, manifest, changed files, and test results were not read. No repository files could be reviewed. ## 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!24871
No description provided.