test(agc): require a repeated draw to reuse the cached draw #2980

Merged
JAB-dev merged 1 commit from upstream-pr/2980 into main 2026-10-10 23:46:53 +00:00
JAB-dev commented 2026-10-10 19:25:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-10T19:25:15Z.


What

Follow-up to #2900: a test that catches that draw-cache regression. The same draw submitted twice must reuse the cached draw the second time; with the #2900 fix removed, it fails.

The test registers a vertex and a pixel shader and submits one DCB that issues two identical DRAW_INDEX_AUTO draws, then reads the driver's draw-cache counters. It requires 2 lookups, 1 hit and no misses on the push-offset layout. It runs twice: agc_driver_draw_cache_reuse (pipeline libraries on, so the pixel stage uses the fixed push slot) and agc_driver_draw_cache_reuse_off (APS5_NO_GPL=1, registered like agc_driver_flip_compute). It skips with 77 when there is no Vulkan device, and the first one also skips when the device has no pipeline libraries, since it would not test the fixed slot there.

It checks the cache through its counters, the way the other cache tests do: ShaderDiskCache.cpp asserts on ShaderDiskCache::Totals() hits and misses, Recorder.cpp on Recorder::ReadCounts() and PipelineLibraryCountersOf, and BdaResources.cpp on MirrorCounters(). For that the driver gets one small read-only accessor, Driver::DrawCacheCounters(), which returns a copy of the counters under drawCacheMutex. The device setup and AgcDriverShutdown_nid_postfix follow DwordPatternFill.cpp.

Tested

Windows 11, WinLibs GCC 15.2.0, RTX 4070 SUPER.

  • Both new tests pass on this branch.
  • With the one-line #2900 fix in DrawLookup.cpp removed: agc_driver_draw_cache_reuse fails ("the repeated draw missed the draw cache on its push offset (1 layout misses)"); agc_driver_draw_cache_reuse_off still passes, as expected, since the bug needs fixed push slots.
  • agc_pipeline_library, agc_pipeline_library_off, agc_pipeline_library_fast_only, agc_recorder_kept_bytes, agc_driver, agc_driver_graphics pass.
  • tools/check_conventions.py --base origin/main passes. Rebased on main 4a747c487.
  • Linux not tested.

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 in TechnicalDebt
  • 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: N/A, no third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813834377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-10T19:25:15Z. --- ### What Follow-up to #2900: a test that catches that draw-cache regression. The same draw submitted twice must reuse the cached draw the second time; with the #2900 fix removed, it fails. The test registers a vertex and a pixel shader and submits one DCB that issues two identical `DRAW_INDEX_AUTO` draws, then reads the driver's draw-cache counters. It requires 2 lookups, 1 hit and no misses on the push-offset layout. It runs twice: `agc_driver_draw_cache_reuse` (pipeline libraries on, so the pixel stage uses the fixed push slot) and `agc_driver_draw_cache_reuse_off` (`APS5_NO_GPL=1`, registered like `agc_driver_flip_compute`). It skips with 77 when there is no Vulkan device, and the first one also skips when the device has no pipeline libraries, since it would not test the fixed slot there. It checks the cache through its counters, the way the other cache tests do: `ShaderDiskCache.cpp` asserts on `ShaderDiskCache::Totals()` hits and misses, `Recorder.cpp` on `Recorder::ReadCounts()` and `PipelineLibraryCountersOf`, and `BdaResources.cpp` on `MirrorCounters()`. For that the driver gets one small read-only accessor, `Driver::DrawCacheCounters()`, which returns a copy of the counters under `drawCacheMutex`. The device setup and `AgcDriverShutdown_nid_postfix` follow `DwordPatternFill.cpp`. ### Tested Windows 11, WinLibs GCC 15.2.0, RTX 4070 SUPER. - Both new tests pass on this branch. - With the one-line #2900 fix in `DrawLookup.cpp` removed: `agc_driver_draw_cache_reuse` fails ("the repeated draw missed the draw cache on its push offset (1 layout misses)"); `agc_driver_draw_cache_reuse_off` still passes, as expected, since the bug needs fixed push slots. - `agc_pipeline_library`, `agc_pipeline_library_off`, `agc_pipeline_library_fast_only`, `agc_recorder_kept_bytes`, `agc_driver`, `agc_driver_graphics` pass. - `tools/check_conventions.py --base origin/main` passes. Rebased on `main` 4a747c487. - Linux not tested. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: N/A, no third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
AlxcBTW commented 2026-10-10 21:54:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T21:54:29Z.


@JAB-dev sorry, I hadn't seen this one when I offered a test on #2900. Yours came first and covers what matters, the repeated draw actually hitting the cache on a real device.

The only thing mine (AlxcBTW/AnyPS5#29) adds is a device-free check of the lookup walk: it moves the stage walk into Driver::MatchDrawEntry and tests the fixed-slot and packed layouts without Vulkan, so it also runs on CI runners where yours skips (no device on the Windows runner, and no pipeline libraries on some others). If that's useful I can rebase it on top of yours as a small follow-up; if not, I'll close it. Your call.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102579921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980#issuecomment-6102579921). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-10T21:54:29Z. --- @JAB-dev sorry, I hadn't seen this one when I offered a test on #2900. Yours came first and covers what matters, the repeated draw actually hitting the cache on a real device. The only thing mine (AlxcBTW/AnyPS5#29) adds is a device-free check of the lookup walk: it moves the stage walk into `Driver::MatchDrawEntry` and tests the fixed-slot and packed layouts without Vulkan, so it also runs on CI runners where yours skips (no device on the Windows runner, and no pipeline libraries on some others). If that's useful I can rebase it on top of yours as a small follow-up; if not, I'll close it. Your call. AI-assisted: yes (Claude Code)
fma-rc commented 2026-10-10 22:38:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T22:38:12Z.


Linux run, since the description says it wasn't tested there: bddcc71e, GCC 16.2.1, ANYPS5_REQUIRE_VULKAN=1 ctest -R agc_driver_draw_cache_reuse --repeat until-fail:100. Both agc_driver_draw_cache_reuse and agc_driver_draw_cache_reuse_off pass 100 of 100 on an RTX 5080 (NVIDIA 615.78.08) and on a Radeon 610M (RADV).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102933762 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980#issuecomment-6102933762). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T22:38:12Z. --- Linux run, since the description says it wasn't tested there: bddcc71e, GCC 16.2.1, `ANYPS5_REQUIRE_VULKAN=1 ctest -R agc_driver_draw_cache_reuse --repeat until-fail:100`. Both `agc_driver_draw_cache_reuse` and `agc_driver_draw_cache_reuse_off` pass 100 of 100 on an RTX 5080 (NVIDIA 615.78.08) and on a Radeon 610M (RADV).
adriadam10 commented 2026-10-10 23:46:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:46:48Z.


Checked on the PR merged onto main: both new tests pass, and with the StagePushOffset line removed from DrawLookup.cpp agc_driver_draw_cache_reuse fails with "1 layout misses" while the _off variant still passes, as described. The accessor is read-only under drawCacheMutex. Also confirmed on Linux by @fma-rc (RTX 5080 and RADV). Merging once the full Linux/Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103449134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980#issuecomment-6103449134). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:46:48Z. --- Checked on the PR merged onto main: both new tests pass, and with the `StagePushOffset` line removed from `DrawLookup.cpp` `agc_driver_draw_cache_reuse` fails with "1 layout misses" while the `_off` variant still passes, as described. The accessor is read-only under `drawCacheMutex`. Also confirmed on Linux by @fma-rc (RTX 5080 and RADV). Merging once the full Linux/Windows build is green.
orishamir commented 2026-10-11 09:39:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T09:39:22Z.


Windows + NVIDIA data point for the new test, since CI skips it without a GPU: on Windows 11 Pro 26300, RTX 4080 driver 616.56, WinLibs GCC 15.2.0 r7, main 09bd4aa1 (+#1482), agc_driver_draw_cache_reuse crashed in 2 of 17 runs and passed the other 15 (and agc_driver_draw_cache_reuse_off 3/3):

  • in the full suite (ctest --parallel 4), after 6.39 s: FATAL: unhandled exception 0xc0000005, rip nvgpucomp64.dll+0x1a580f, write of 0x0000000000000000;
  • in a serial rerun, after 0.34 s: exit 0xc0000374 (heap corruption), no AnyPS5 frame reported.

Both are inside or right after NVIDIA's shader compiler DLL, so either a driver fault on what the test's pipelines feed it or a corruption on our side that the driver trips over; 10 further serial runs passed, so it is intermittent, not a layout or format gap.

AI-assisted: yes (Claude Code Fable 5.1 xhigh)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107669862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980#issuecomment-6107669862). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-11T09:39:22Z. --- Windows + NVIDIA data point for the new test, since CI skips it without a GPU: on Windows 11 Pro 26300, RTX 4080 driver 616.56, WinLibs GCC 15.2.0 r7, `main` 09bd4aa1 (+#1482), `agc_driver_draw_cache_reuse` crashed in 2 of 17 runs and passed the other 15 (and `agc_driver_draw_cache_reuse_off` 3/3): - in the full suite (`ctest --parallel 4`), after 6.39 s: `FATAL: unhandled exception 0xc0000005`, `rip nvgpucomp64.dll+0x1a580f`, `write of 0x0000000000000000`; - in a serial rerun, after 0.34 s: exit `0xc0000374` (heap corruption), no AnyPS5 frame reported. Both are inside or right after NVIDIA's shader compiler DLL, so either a driver fault on what the test's pipelines feed it or a corruption on our side that the driver trips over; 10 further serial runs passed, so it is intermittent, not a layout or format gap. AI-assisted: yes (Claude Code Fable 5.1 xhigh)
AlxcBTW commented 2026-10-11 13:09:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T13:09:04Z.


@orishamir reproduced here (Windows 11, RTX 5070 Laptop, 616.92), and it's ours, not the driver.

With MinGW's emulated TLS, winpthread frees a thread's thread_local storage before the module's thread-detach runs the thread_local destructors. So when Driver::stop joins the queue worker, the driver's thread_local map, vectors and image memo are destroyed on freed memory.

  • Under cdb (debug heap), agc_driver_draw_cache_reuse stopped there in 127 of 127 runs, also with APS5_NO_PIPELINE_LTO=1 and APS5_NO_GPL=1.
  • In normal runs it showed up as 0xc0000374 in 2 of 143 runs with a cold NVIDIA shader cache.
  • The nvgpucomp64 write is most likely the next allocation landing on the damaged heap.

It's the teardown bug on #3171; details, and a branch that fixes it with a test, are there.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109358075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2980#issuecomment-6109358075). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-11T13:09:04Z. --- @orishamir reproduced here (Windows 11, RTX 5070 Laptop, 616.92), and it's ours, not the driver. With MinGW's emulated TLS, winpthread frees a thread's `thread_local` storage before the module's thread-detach runs the `thread_local` destructors. So when `Driver::stop` joins the queue worker, the driver's `thread_local` map, vectors and image memo are destroyed on freed memory. - **Under cdb** (debug heap), `agc_driver_draw_cache_reuse` stopped there in 127 of 127 runs, also with `APS5_NO_PIPELINE_LTO=1` and `APS5_NO_GPL=1`. - **In normal runs** it showed up as `0xc0000374` in 2 of 143 runs with a cold NVIDIA shader cache. - **The `nvgpucomp64` write** is most likely the next allocation landing on the damaged heap. It's the teardown bug on #3171; details, and a branch that fixes it with a test, are there. AI-assisted: yes (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!2980
No description provided.