fix(shader): read an image the same shader stores to through its storage binding #26593

Merged
Jazeupoi merged 3 commits from upstream-pr/26593 into main 2026-11-29 02:09:47 +00:00
Jazeupoi commented 2026-11-24 08:37:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-24T08:37:07Z.


What

An image_load of a T# that the same shader also image_stores to reads a separate sampled binding (the debt recorded in #22719), so a load after a store of the same texel returns the value from before the dispatch. RDNA2 hardware returns the stored value.

When the load and the store use the same descriptor, the load now reads the storage binding with OpImageRead. A per-image specialization constant chooses it at pipeline creation, so the SPIR-V has the redirected read and the original fetch side by side.

  • The driver asks for VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT per guest format through VK_KHR_format_feature_flags2; the mask goes into SpirvTarget and the cache key.
  • Signed 8-, 16- and 32-bit integer and 16-bit float formats are written through their unsigned storage view, so the read sign-extends them or unpacks the halves (Inf and NaN keep their sign and payload).
  • The packed 32-bit formats (11_11_10, 10_11_11, 2_10_10_10) already read and write the same R32_UINT view, and the shader's existing unpack applies.
  • It stays off for registration modules, multisampled, cube, mipmapped, sRGB-decoded, depth and emulated-compare reads, image tables, a descriptor swizzle that is not identity, the 16-bit packed formats, and an atomic storage image or one merged with a render target. The debt entry lists these.

New test agc_driver_image_load_after_store: one dispatch stores to a texel and loads it back, for 32_UINT, 32_32_32_32_UINT, 8_8_8_8_SINT, 16_16_16_16_SINT, 16_16_16_16_FLOAT and 2_10_10_10_UINT, and checks that the other texels keep their pre-fill.

No known game or homebrew is affected: 22 homebrew titles never hit the case. PS5SX2's ROV mode would (tfx.glsl loads and stores the same color and depth images), but its PS2 side stops on Windows at an SA_SIGINFO handler (libkernel debt) before it draws, so it could not be used.

Tested

Windows 11 Pro (build 26300), NVIDIA GeForce RTX 2060.

  • New test: passes (3 of 3 with the Khronos validation layer, 0 VUID- / SYNC-). It runs a case only when the device can read that format through a storage image without a format (StorageImageReadWithoutFormat and the format's VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT), the same condition as the redirected read, and is skipped when no case can run.
  • A temporary sweep, not part of this PR: one process per guest format 1-77, store then load in one dispatch, compared with a later dispatch that only loads. Three data sets: markers, negative integers, and signed fractional floats with NaN.
Formats that accept storage on this GPU Load returns the stored value
main 41 0
This PR 41 41 (all three data sets)
  • The 131 image execution tests: all pass (agc_driver_image_memory with the APS5_IMAGE_SLABS=1 that CTest sets for it).

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 2060, driver 621.24, Windows 11 Pro build 26300
  • AI-assisted: yes (Claude Code)

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5468805606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26593). Originally posted by [Jazeupoi](https://github.com/Jazeupoi) on 2026-11-24T08:37:07Z. --- ### What An `image_load` of a T# that the same shader also `image_store`s to reads a separate sampled binding (the debt recorded in #22719), so a load after a store of the same texel returns the value from before the dispatch. RDNA2 hardware returns the stored value. When the load and the store use the same descriptor, the load now reads the storage binding with `OpImageRead`. A per-image specialization constant chooses it at pipeline creation, so the SPIR-V has the redirected read and the original fetch side by side. - The driver asks for `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT` per guest format through `VK_KHR_format_feature_flags2`; the mask goes into `SpirvTarget` and the cache key. - Signed 8-, 16- and 32-bit integer and 16-bit float formats are written through their unsigned storage view, so the read sign-extends them or unpacks the halves (Inf and NaN keep their sign and payload). - The packed 32-bit formats (11_11_10, 10_11_11, 2_10_10_10) already read and write the same `R32_UINT` view, and the shader's existing unpack applies. - It stays off for registration modules, multisampled, cube, mipmapped, sRGB-decoded, depth and emulated-compare reads, image tables, a descriptor swizzle that is not identity, the 16-bit packed formats, and an atomic storage image or one merged with a render target. The debt entry lists these. New test `agc_driver_image_load_after_store`: one dispatch stores to a texel and loads it back, for 32_UINT, 32_32_32_32_UINT, 8_8_8_8_SINT, 16_16_16_16_SINT, 16_16_16_16_FLOAT and 2_10_10_10_UINT, and checks that the other texels keep their pre-fill. No known game or homebrew is affected: 22 homebrew titles never hit the case. PS5SX2's ROV mode would (`tfx.glsl` loads and stores the same color and depth images), but its PS2 side stops on Windows at an `SA_SIGINFO` handler (libkernel debt) before it draws, so it could not be used. ### Tested Windows 11 Pro (build 26300), NVIDIA GeForce RTX 2060. - New test: passes (3 of 3 with the Khronos validation layer, 0 `VUID-` / `SYNC-`). It runs a case only when the device can read that format through a storage image without a format (`StorageImageReadWithoutFormat` and the format's `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`), the same condition as the redirected read, and is skipped when no case can run. - A temporary sweep, not part of this PR: one process per guest format 1-77, store then load in one dispatch, compared with a later dispatch that only loads. Three data sets: markers, negative integers, and signed fractional floats with NaN. | | Formats that accept storage on this GPU | Load returns the stored value | |---|---|---| | `main` | 41 | 0 | | This PR | 41 | 41 (all three data sets) | - The 131 image execution tests: all pass (`agc_driver_image_memory` with the `APS5_IMAGE_SLABS=1` that CTest sets for it). ### 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 2060, driver 621.24, Windows 11 Pro build 26300 - [x] AI-assisted: yes (Claude Code) AI-assisted: yes (Claude Code)
mihiii1337 commented 2026-11-24 19:14:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T19:14:13Z.

Review: CHANGES_REQUESTED


Requesting changes only for the new execution test's portability; the production storage-read selection correctly stays off on this device.

I reproduced the test on the physical Intel adapter in this Windows notebook at head 5bed290d2388b984805f48679991a5d23fe78d52. Before rebuilding, I applied every AGC/shader source delta through current main 271179178780e9fcb5cd0754a1cf5186c6e491ef to both comparison arms (the remaining newer main deltas are tools-only), and verified that both used byte-identical ImageLoadAfterStore.cpp fixtures.

Device capability is the relevant difference:

  • Intel RaptorLake-S Mobile Graphics Controller (8086:a78b), driver 101.6127, Vulkan 1.3.295
  • shaderStorageImageExtendedFormats = true
  • shaderStorageImageReadWithoutFormat = false
  • shaderStorageImageWriteWithoutFormat = true
  • VK_KHR_format_feature_flags2 present

I explicitly configured and built the real target with -DANYPS5_AGC_EXECUTION_TESTS=ImageLoadAfterStore; this was not the ExecutionTestNotBuilt.cpp placeholder. With the Intel ICD pinned, ANYPS5_REQUIRE_VULKAN=1, shader cache and pipeline journal disabled, and Khronos validation 1.4.369 with synchronization validation enabled:

  • PR head plus current AGC/shader main deltas: 0/3 passes
  • current main AGC/shader sources plus the identical new fixture: 0/3 passes
  • every run fails first at AGC graphics: 32_UINT: thread 0 channel 0 loaded 0xabababab after storing 0x5a000003
  • 0 VUID- / SYNC- messages

That A/B says this is not a production regression introduced by the PR: the new behavior is unavailable by design on this valid Vulkan device, but the fixture unconditionally expects it. The implementation first requires the global read-without-format feature and then the per-format VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT; the fixture should skip or constrain its cases using that same effective capability contract while retaining coverage on capable GPUs.

The green hosted Windows job does not cover this case: it configured only F16ToF32Unpack;F64FmaSubnormals;RegistrationPrepareShutdown, built agc_driver_image_load_after_store_tests from ExecutionTestNotBuilt.cpp, and reported agc_driver_image_load_after_store as skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6045709223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26593#pullrequestreview-6045709223). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-24T19:14:13Z. **Review:** CHANGES_REQUESTED --- Requesting changes only for the new execution test's portability; the production storage-read selection correctly stays off on this device. I reproduced the test on the physical Intel adapter in this Windows notebook at head `5bed290d2388b984805f48679991a5d23fe78d52`. Before rebuilding, I applied every AGC/shader source delta through current `main` `271179178780e9fcb5cd0754a1cf5186c6e491ef` to both comparison arms (the remaining newer main deltas are tools-only), and verified that both used byte-identical `ImageLoadAfterStore.cpp` fixtures. Device capability is the relevant difference: - Intel RaptorLake-S Mobile Graphics Controller (`8086:a78b`), driver 101.6127, Vulkan 1.3.295 - `shaderStorageImageExtendedFormats = true` - `shaderStorageImageReadWithoutFormat = false` - `shaderStorageImageWriteWithoutFormat = true` - `VK_KHR_format_feature_flags2` present I explicitly configured and built the real target with `-DANYPS5_AGC_EXECUTION_TESTS=ImageLoadAfterStore`; this was not the `ExecutionTestNotBuilt.cpp` placeholder. With the Intel ICD pinned, `ANYPS5_REQUIRE_VULKAN=1`, shader cache and pipeline journal disabled, and Khronos validation 1.4.369 with synchronization validation enabled: - PR head plus current AGC/shader main deltas: 0/3 passes - current main AGC/shader sources plus the identical new fixture: 0/3 passes - every run fails first at `AGC graphics: 32_UINT: thread 0 channel 0 loaded 0xabababab after storing 0x5a000003` - 0 `VUID-` / `SYNC-` messages That A/B says this is not a production regression introduced by the PR: the new behavior is unavailable by design on this valid Vulkan device, but the fixture unconditionally expects it. The implementation first requires the global read-without-format feature and then the per-format `VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT`; the fixture should skip or constrain its cases using that same effective capability contract while retaining coverage on capable GPUs. The green hosted Windows job does not cover this case: it configured only `F16ToF32Unpack;F64FmaSubnormals;RegistrationPrepareShutdown`, built `agc_driver_image_load_after_store_tests` from `ExecutionTestNotBuilt.cpp`, and reported `agc_driver_image_load_after_store` as skipped.
mihiii1337 commented 2026-11-24 19:39:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T19:39:53Z.

Review: APPROVED


The new head resolves my fixture-portability change request. I verified the exact new fixture blob at head 81862ab3e668b0e671c8253e3fa085af2c9ec258 with all relevant AGC/shader source deltas through current main 5f04682cef1e1c7f46162773b6a92a6fa49dd59a.

I rebuilt the real agc_driver_image_load_after_store_tests target with -DANYPS5_AGC_EXECUTION_TESTS=ImageLoadAfterStore and ran separate processes on both physical notebook adapters:

  • Intel RaptorLake-S Mobile A78B, driver 101.6127: 3/3 CTest invocations correctly reported Skipped. Every run printed the six unsupported-format skip lines and no success line.
  • NVIDIA RTX 4070 Laptop, driver 621.01: 3/3 CTest invocations passed. All six positive cases ran; there were no skip lines.

The runs used Khronos validation 1.4.369 with synchronization validation and produced 0 VUID/SYNC diagnostics. This preserves the positive assertions on a capable device while making the valid unsupported Intel device a real test skip, matching the implementation contract.

Approved. AI-assisted: yes (Codex assisted with review and testing).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6046100384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26593#pullrequestreview-6046100384). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-24T19:39:53Z. **Review:** APPROVED --- The new head resolves my fixture-portability change request. I verified the exact new fixture blob at head `81862ab3e668b0e671c8253e3fa085af2c9ec258` with all relevant AGC/shader source deltas through current `main` `5f04682cef1e1c7f46162773b6a92a6fa49dd59a`. I rebuilt the real `agc_driver_image_load_after_store_tests` target with `-DANYPS5_AGC_EXECUTION_TESTS=ImageLoadAfterStore` and ran separate processes on both physical notebook adapters: - Intel RaptorLake-S Mobile A78B, driver 101.6127: 3/3 CTest invocations correctly reported `Skipped`. Every run printed the six unsupported-format skip lines and no success line. - NVIDIA RTX 4070 Laptop, driver 621.01: 3/3 CTest invocations passed. All six positive cases ran; there were no skip lines. The runs used Khronos validation 1.4.369 with synchronization validation and produced 0 VUID/SYNC diagnostics. This preserves the positive assertions on a capable device while making the valid unsupported Intel device a real test skip, matching the implementation contract. Approved. AI-assisted: yes (Codex assisted with review and testing).
MarcZX10 commented 2026-11-25 07:40:36 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

This review covers head 81862ab3e668b0e671c8253e3fa085af2c9ec258; no verified blocking defect was found in the code read. The new test was not run during this review.

What I ran

  • Read the prepared description, commit list, manifest, and diff; inspected targeted code using repo_read.py's pinned-head reader.
  • No build or tests were run.

Results

Check Result Note
Patch and targeted code review passed No verified blocker found
Build and tests not run Author reports tests; not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The build, new execution test, and reported test results were not run independently.
  • The full text for VulkanDevice.cpp and Texture.cpp was excluded by the review folder size limit; only relevant ranges were read. Other changed-file full texts marked included in the manifest were not all read, so this is not a complete file-by-file verification.
  • files.json was not available through the reader; the manifest identifies the two excluded files noted above.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6053595025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26593#pullrequestreview-6053595025). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T07:40:36Z. **Review:** COMMENTED --- # Reviewed — no blocking findings This review covers head `81862ab3e668b0e671c8253e3fa085af2c9ec258`; no verified blocking defect was found in the code read. The new test was not run during this review. ## What I ran - Read the prepared description, commit list, manifest, and diff; inspected targeted code using `repo_read.py`'s pinned-head reader. - No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Patch and targeted code review | passed | No verified blocker found | | Build and tests | not run | Author reports tests; not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - The build, new execution test, and reported test results were not run independently. - The full text for `VulkanDevice.cpp` and `Texture.cpp` was excluded by the review folder size limit; only relevant ranges were read. Other changed-file full texts marked included in the manifest were not all read, so this is not a complete file-by-file verification. - `files.json` was not available through the reader; the manifest identifies the two excluded files noted above. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 19:20:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T19:20:47Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected shader redirection and descriptor gating appear consistent with the stated constraints; the review is incomplete because several changed files and the full test/build evidence were not inspected.

What I ran

  • Read the prepared description, commits, manifest, and diff for head 65bb7731f9c9eeb52212852a2ea31d45892c71ff.
  • Used repo_read.py to search and read targeted code ranges. No tests or builds were run.

Results

Check Result Note
Targeted code inspection passed Redirection guards reviewed
Tests and build not run Author-reported results only
Full changed-file review not run Several changed files remain unread

Findings

Blocking

None identified in the inspected code.

Non-blocking

None.

Not verified

Read: VulkanDevice.cpp (targeted range), Texture.cpp (targeted range), ResourceMaterializer.cpp (targeted range), DescriptorBindingBuilder.cpp (targeted range), and SpirvImageEmitter.cpp (targeted range). Also read the description, commits, manifest, and diff.

The remaining changed files were not read: Texture.hpp, ImageLoadAfterStore.cpp, CacheKey.hpp, DescriptorBindingBuilder.hpp, ResourceMaterializer.hpp, PipelineSpecialization.hpp, Recompiler.cpp, Recompiler.hpp, and docs/dev/debt/changes/docs-image-load-after-store-same-shader.md. The full contents outside the targeted ranges of the five code files above were not reviewed. Tests, build results, hardware behavior, and CI were not verified; the description reports those results.

To get this to a good state

Nothing is required. Optional: complete inspection of the unread changed files and run the relevant checks before making a formal approval decision.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6063610320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26593#pullrequestreview-6063610320). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T19:20:47Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected shader redirection and descriptor gating appear consistent with the stated constraints; the review is incomplete because several changed files and the full test/build evidence were not inspected. ## What I ran - Read the prepared description, commits, manifest, and diff for head `65bb7731f9c9eeb52212852a2ea31d45892c71ff`. - Used `repo_read.py` to search and read targeted code ranges. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Targeted code inspection | passed | Redirection guards reviewed | | Tests and build | not run | Author-reported results only | | Full changed-file review | not run | Several changed files remain unread | ## Findings ### Blocking None identified in the inspected code. ### Non-blocking None. ## Not verified Read: `VulkanDevice.cpp` (targeted range), `Texture.cpp` (targeted range), `ResourceMaterializer.cpp` (targeted range), `DescriptorBindingBuilder.cpp` (targeted range), and `SpirvImageEmitter.cpp` (targeted range). Also read the description, commits, manifest, and diff. The remaining changed files were not read: `Texture.hpp`, `ImageLoadAfterStore.cpp`, `CacheKey.hpp`, `DescriptorBindingBuilder.hpp`, `ResourceMaterializer.hpp`, `PipelineSpecialization.hpp`, `Recompiler.cpp`, `Recompiler.hpp`, and `docs/dev/debt/changes/docs-image-load-after-store-same-shader.md`. The full contents outside the targeted ranges of the five code files above were not reviewed. Tests, build results, hardware behavior, and CI were not verified; the description reports those results. ## To get this to a good state Nothing is required. Optional: complete inspection of the unread changed files and run the relevant checks before making a formal approval decision.
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!26593
No description provided.