fix(agc): refresh a block-copied texture the fast lookup would reuse #5654

Merged
milescoviello merged 1 commit from upstream-pr/5654 into main 2026-10-14 06:05:12 +00:00
milescoviello commented 2026-10-14 04:19:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T04:19:40Z.


What

agc_driver_bc_block_copy, added with #4747, fails on main on Linux with an NVIDIA GPU:

AGC graphics: BC7 through 32x4 uint blocks: sample of blocks stored again: thread 0 component 0 read 1064168942, expected 1058905502

The test stores blocks with a compute pass, samples the BC view while they are pending, stores the first pattern again and samples once more. The last sample reads the blocks of the previous copy.

That sample never reaches cachedTexture. The build takes the stage-A record's texture through fastTexture, which declines only depth surfaces (DepthSurfaceAt) and textures remade per use (RefreshedPerUse). The block copy is a copy refreshed on reuse (PerUseCopy::RefreshedOnReuse, IsDepthCopy()), like the depth copy, but its surface is not a depth surface. So the fast path hands it back without RefreshDepthCopy, although its storage image's version moved.

fastTexture now also declines copies refreshed on reuse. The lookup then takes cachedTexture, whose cache hit calls RefreshDepthCopy, and that copies the image again when its version moved. IsDepthCopy() is true for the depth copy as well as the block copy, so both now take that lookup.

This is the path #4747 added for Minecraft Dungeons II (PPSA16064), where a compute pass writes block-compressed surfaces that are then sampled. With the fast path, such a surface can be sampled with the blocks of an earlier pass.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, RTX 4070 Ti (NVIDIA 580.142), on main f40b6930f:

  • On main, agc_driver_bc_block_copy fails 3 of 3 runs with the line above; it also fails at #4747's merge commit af991ac40. With the change it passes 10 of 10.

  • With temporary prints (not part of this PR): on main the failing sample calls neither cachedTexture nor Revalidate, and RefreshDepthCopy is not called for it. With the change it is called and copies the image at version 8 (copied at 7 before), for both the BC7 and BC1 cases.

  • All 508 tests in libSceAgcDriver pass; agc_driver_stencil_ref_export is skipped, as on main, because the device lacks VK_EXT_shader_stencil_export.

  • A MinGW-w64 GCC 13 -fsyntax-only compile of ShaderResources.cpp has no errors.

  • tools/check_conventions.py --base upstream/main passes, and tools/pr_overlap.py --branch finds no overlap.

  • @simonbbby validated it independently at this head on main f40b6930f, Release, GCC 13.3: agc_driver_bc_block_copy and agc_driver_graphics pass 3/3 on an RTX 3090 (NVIDIA 595.99.02) and on RDNA2 gfx1036 (RADV, Mesa 25.2.8). With only ShaderResources.cpp restored to main, the block-copy test fails 3/3 on NVIDIA at the same sample.

Not checked on Windows, on a console or with a title.

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
  • 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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4852893976 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5654). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T04:19:40Z. --- ### What `agc_driver_bc_block_copy`, added with #4747, fails on `main` on Linux with an NVIDIA GPU: ``` AGC graphics: BC7 through 32x4 uint blocks: sample of blocks stored again: thread 0 component 0 read 1064168942, expected 1058905502 ``` The test stores blocks with a compute pass, samples the BC view while they are pending, stores the first pattern again and samples once more. The last sample reads the blocks of the previous copy. That sample never reaches `cachedTexture`. The build takes the stage-A record's texture through `fastTexture`, which declines only depth surfaces (`DepthSurfaceAt`) and textures remade per use (`RefreshedPerUse`). The block copy is a copy refreshed on reuse (`PerUseCopy::RefreshedOnReuse`, `IsDepthCopy()`), like the depth copy, but its surface is not a depth surface. So the fast path hands it back without `RefreshDepthCopy`, although its storage image's version moved. `fastTexture` now also declines copies refreshed on reuse. The lookup then takes `cachedTexture`, whose cache hit calls `RefreshDepthCopy`, and that copies the image again when its version moved. `IsDepthCopy()` is true for the depth copy as well as the block copy, so both now take that lookup. This is the path #4747 added for Minecraft Dungeons II (PPSA16064), where a compute pass writes block-compressed surfaces that are then sampled. With the fast path, such a surface can be sampled with the blocks of an earlier pass. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, RTX 4070 Ti (NVIDIA 580.142), on `main` f40b6930f: - On `main`, `agc_driver_bc_block_copy` fails 3 of 3 runs with the line above; it also fails at #4747's merge commit af991ac40. With the change it passes 10 of 10. - With temporary prints (not part of this PR): on `main` the failing sample calls neither `cachedTexture` nor `Revalidate`, and `RefreshDepthCopy` is not called for it. With the change it is called and copies the image at version 8 (copied at 7 before), for both the BC7 and BC1 cases. - All 508 tests in `libSceAgcDriver` pass; `agc_driver_stencil_ref_export` is skipped, as on `main`, because the device lacks `VK_EXT_shader_stencil_export`. - A MinGW-w64 GCC 13 `-fsyntax-only` compile of `ShaderResources.cpp` has no errors. - `tools/check_conventions.py --base upstream/main` passes, and `tools/pr_overlap.py --branch` finds no overlap. - @simonbbby [validated it independently](https://github.com/boykopovar/AnyPS5/pull/5654#issuecomment-6160890183) at this head on `main` f40b6930f, Release, GCC 13.3: `agc_driver_bc_block_copy` and `agc_driver_graphics` pass 3/3 on an RTX 3090 (NVIDIA 595.99.02) and on RDNA2 gfx1036 (RADV, Mesa 25.2.8). With only `ShaderResources.cpp` restored to `main`, the block-copy test fails 3/3 on NVIDIA at the same sample. Not checked on Windows, on a console or with a title. ### 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) - [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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
simonbbby commented 2026-10-14 04:27:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T04:27:38Z.


Independent Linux validation at exact head cf9dd4f181c8274858167f253f4f2a14a8a8038f, standalone on parent f40b6930ff156834b786730771518b3bd7fe8648, no extra source changes.

GPU agc_driver_bc_block_copy agc_driver_graphics
RTX 3090, NVIDIA 595.99.02 3/3 pass 3/3 pass
RDNA2 gfx1036 (1002:13c0), RADV Mesa 25.2.8 3/3 pass 3/3 pass

Release, GCC 13.3, bundled dependencies, SPIRV-Tools ON. Pinned each ICD, explicitly selected its GPU, required Vulkan execution, and disabled the application shader cache. Serial CTest, unchanged 30-second limit. The BC fixture completes both BC7 and BC1 on both GPUs. Matrix totals: NVIDIA 10.14 s, RADV 9.50 s; these are test totals, not performance comparisons.

Matched negative control: restored only ShaderResources.cpp from this head's exact parent, retaining the same test and build. NVIDIA fails 3/3, at the original third BC7 sample with read 1064168942, expected 1058905502. Restored the PR source byte-for-byte, rebuilt, and the BC fixture passes another 3/3 on NVIDIA. The checkout is clean at the tested PR head.

This also agrees with our diagnostic on the earlier reported main cd90ca50b: NVIDIA's failing third sample never entered RefreshDepthCopy, whereas RADV refreshed the reused BC copy. The negative control here verifies the fix against its own current parent rather than relying on that older tree.

Coverage limit: agc_driver_graphics reports its heap-mirror and imported-range heap-mirror subcases untested because the guest arena is unavailable/not write-watched; no BC-fixture skips were printed. No Windows, console, title run, or frame-time measurement here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160890183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5654#issuecomment-6160890183). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-14T04:27:38Z. --- Independent Linux validation at exact head **`cf9dd4f181c8274858167f253f4f2a14a8a8038f`**, standalone on parent `f40b6930ff156834b786730771518b3bd7fe8648`, no extra source changes. | GPU | `agc_driver_bc_block_copy` | `agc_driver_graphics` | |---|---|---| | RTX 3090, NVIDIA 595.99.02 | 3/3 pass | 3/3 pass | | RDNA2 gfx1036 (`1002:13c0`), RADV Mesa 25.2.8 | 3/3 pass | 3/3 pass | Release, GCC 13.3, bundled dependencies, SPIRV-Tools ON. Pinned each ICD, explicitly selected its GPU, required Vulkan execution, and disabled the application shader cache. Serial CTest, unchanged 30-second limit. The BC fixture completes both BC7 and BC1 on both GPUs. Matrix totals: NVIDIA 10.14 s, RADV 9.50 s; these are test totals, not performance comparisons. **Matched negative control:** restored only `ShaderResources.cpp` from this head's exact parent, retaining the same test and build. NVIDIA fails **3/3**, at the original third BC7 sample with `read 1064168942, expected 1058905502`. Restored the PR source byte-for-byte, rebuilt, and the BC fixture passes another **3/3** on NVIDIA. The checkout is clean at the tested PR head. This also agrees with our diagnostic on the earlier reported main `cd90ca50b`: NVIDIA's failing third sample never entered `RefreshDepthCopy`, whereas RADV refreshed the reused BC copy. The negative control here verifies the fix against its own current parent rather than relying on that older tree. Coverage limit: `agc_driver_graphics` reports its heap-mirror and imported-range heap-mirror subcases untested because the guest arena is unavailable/not write-watched; no BC-fixture skips were printed. No Windows, console, title run, or frame-time measurement here.
milescoviello commented 2026-10-14 04:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T04:29:02Z.


Thanks, @simonbbby. The negative control and the RADV run cover what I couldn't test here. I've added them to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160905864 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5654#issuecomment-6160905864). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T04:29:02Z. --- Thanks, @simonbbby. The negative control and the RADV run cover what I couldn't test here. I've added them to the description. AI-assisted: yes
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!5654
No description provided.