fix(agc): recognise the copy kernel as Demon's Souls 01.007.000 compiles it #8552

Merged
Sam-mon7 merged 1 commit from upstream-pr/8552 into main 2026-10-23 21:40:38 +00:00
Sam-mon7 commented 2026-10-20 16:23:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Sam-mon7 on 2026-10-20T16:23:36Z.


What

The buffer copy HLE (Driver::matchesCopyKernel) recognises its copy kernel, dst[i] = src[i % period] for i < count with count and period read from a parameter buffer, by an FNV hash of its first 38 instruction words (0x6ec00fe8aa95f99a, added with #5 for PPSA01342). Demon's Souls PPSA01341 01.007.000 ships the same kernel compiled to a different instruction sequence: same descriptors (0x00014004 source and destination, 0x0004dfac parameters, strides 4/4/16), same parameter layout, 64x1x1 threads, the group id in s12, hash 0xc771c42e4d069d62. None of its copies matched (copy HLE 0 on every queue), so each one ran as a GPU dispatch. That hash is now accepted too: in the first 55 s of a run (boot to the debug menu) 5,187 copy kernels then match, 2,617 copied on the CPU (20.1 MiB) and 2,570 as GPU transfers (2,239 MiB).

The kernel as this version ships it, decoded: the global index from the group id and lane, s_buffer_load of count and period from the parameter buffer, an early exit for i >= count, i % period through the usual reciprocal sequence, then buffer_load_format_x from the source and buffer_store_format_x to the destination (idxen).

Question

Matching by a hash of the raw words breaks whenever a title or patch recompiles the kernel, as here. Would you prefer the matcher to recognise this kernel by its decoded shape instead (the two buffer instructions, the parameter loads and the bounds check), so that recompiled forms keep matching? That is a larger change, and I would do it as a separate PR if you want it.

Tested

Windows 11 (10.0.26200), winlibs GCC 15.2, Release. Tests run on this branch rebased onto main at 6bef96df7 (the validation and game runs used main at 054852a76; nothing in the copy path changed in between).

  • New agc_driver_period_copy: the kernel as Demon's Souls 01.007.000 ships it, run through the driver. With the HLE the linear cases (one group, a period above the count, a partial last group) must take a copy path; a period below the count and a launch with more groups than the count needs must not; every case must produce dst[i] = src[i % period]. agc_driver_period_copy_no_hle runs the same cases as shader dispatches (APS5_NO_COPY_HLE=1), so the HLE and the shader are checked against the same results. Both pass with this change; with main's BufferCopy.cpp, agc_driver_period_copy fails with the copy did not take the HLE path (one full group).
  • Validation layer: agc_driver_period_copy, agc_driver_period_copy_no_hle and agc_driver_stream_copy with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (ctest -V), on main's BufferCopy.cpp and on this change: no VUID- line and no was not found but was requested by env var VK_INSTANCE_LAYERS in either log.
  • Demon's Souls (PPSA01341 01.007.000), +r_Wants4K=WantsPerf, debug start menu to the Nexus, warm caches, no APS5_PROFILE_* switches, APS5_TRACE_SUMMARY_EVERY=10. Both sides include #8394, which this title needs to start on main. No speed claim: the Nexus frame rate did not change measurably (alternating runs, 0.23 and 0.33 fps without the change, 0.18 with it; the scene is bound by queue waits and GPU time).

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 (the Demon's Souls measurement also uses #8394)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 (10.0.26200)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4938894161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8552). Originally posted by [Sam-mon7](https://github.com/Sam-mon7) on 2026-10-20T16:23:36Z. --- ### What The buffer copy HLE (`Driver::matchesCopyKernel`) recognises its copy kernel, `dst[i] = src[i % period]` for `i < count` with count and period read from a parameter buffer, by an FNV hash of its first 38 instruction words (`0x6ec00fe8aa95f99a`, added with #5 for PPSA01342). Demon's Souls PPSA01341 01.007.000 ships the same kernel compiled to a different instruction sequence: same descriptors (`0x00014004` source and destination, `0x0004dfac` parameters, strides 4/4/16), same parameter layout, 64x1x1 threads, the group id in s12, hash `0xc771c42e4d069d62`. None of its copies matched (`copy HLE 0` on every queue), so each one ran as a GPU dispatch. That hash is now accepted too: in the first 55 s of a run (boot to the debug menu) 5,187 copy kernels then match, 2,617 copied on the CPU (20.1 MiB) and 2,570 as GPU transfers (2,239 MiB). The kernel as this version ships it, decoded: the global index from the group id and lane, `s_buffer_load` of count and period from the parameter buffer, an early exit for `i >= count`, `i % period` through the usual reciprocal sequence, then `buffer_load_format_x` from the source and `buffer_store_format_x` to the destination (`idxen`). ### Question Matching by a hash of the raw words breaks whenever a title or patch recompiles the kernel, as here. Would you prefer the matcher to recognise this kernel by its decoded shape instead (the two buffer instructions, the parameter loads and the bounds check), so that recompiled forms keep matching? That is a larger change, and I would do it as a separate PR if you want it. ### Tested Windows 11 (10.0.26200), winlibs GCC 15.2, Release. Tests run on this branch rebased onto `main` at 6bef96df7 (the validation and game runs used `main` at 054852a76; nothing in the copy path changed in between). - New `agc_driver_period_copy`: the kernel as Demon's Souls 01.007.000 ships it, run through the driver. With the HLE the linear cases (one group, a period above the count, a partial last group) must take a copy path; a period below the count and a launch with more groups than the count needs must not; every case must produce `dst[i] = src[i % period]`. `agc_driver_period_copy_no_hle` runs the same cases as shader dispatches (`APS5_NO_COPY_HLE=1`), so the HLE and the shader are checked against the same results. Both pass with this change; with `main`'s `BufferCopy.cpp`, `agc_driver_period_copy` fails with `the copy did not take the HLE path (one full group)`. - Validation layer: `agc_driver_period_copy`, `agc_driver_period_copy_no_hle` and `agc_driver_stream_copy` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` (`ctest -V`), on `main`'s `BufferCopy.cpp` and on this change: no `VUID-` line and no `was not found but was requested by env var VK_INSTANCE_LAYERS` in either log. - Demon's Souls (PPSA01341 01.007.000), `+r_Wants4K=WantsPerf`, debug start menu to the Nexus, warm caches, no `APS5_PROFILE_*` switches, `APS5_TRACE_SUMMARY_EVERY=10`. Both sides include #8394, which this title needs to start on `main`. No speed claim: the Nexus frame rate did not change measurably (alternating runs, 0.23 and 0.33 fps without the change, 0.18 with it; the scene is bound by queue waits and GPU time). ### Checklist - [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 (the Demon's Souls measurement also uses #8394) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 (10.0.26200) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!8552
No description provided.