perf(recompiler): back compute scratch with a device buffer slot pool #12764

Merged
Pipodi merged 8 commits from upstream-pr/12764 into main 2026-11-02 22:35:13 +00:00
Pipodi commented 2026-10-29 08:33:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-29T08:33:26Z.


What

Every compute FLAT load, store and atomic in a program with scratch tests its address against the shared and the private aperture (c35f29b6be). The private path reaches the per-lane scratch, held in Function scratch_dwords arrays indexed dynamically at every FLAT site. On NVIDIA that indexing is what makes large compute programs slow to compile: the SPIR-V front end (nvoglv64) spends about a third of the compile on it.

This PR keeps the FLAT routing exactly as on main, for every access, and changes only where scratch lives. A compute program that uses scratch (scratch_*, or a FLAT access routed to the private aperture) now keeps it in a storage buffer, so no Function array is declared or indexed:

  • The driver allocates one buffer per compute pipeline at its first dispatch and binds it in descriptor set 2 (the layout of the device-memory LDS buffer). The buffer holds a lock word and an invocation counter per slot, then the slots. It is capped by APS5_SCRATCH_POOL_MIB (default 64, never below one slot), by maxStorageBufferRange and by 2 GiB: on the RTX 4090 a larger buffer returned wrong values (2049 MiB fails, 2047 MiB passes). All pools together stay under APS5_SCRATCH_POOL_TOTAL_MIB (default 256); a new pool evicts the least recently used ones first. The shader takes the slot count from the array length.
  • Invocation 0 of each workgroup claims a slot with a scan that reads each lock word and tries a compare-exchange only on a free one, starting at its linear workgroup id; a barrier publishes the slot. Every invocation decrements the slot counter at every compute exit and the last one frees the lock, so divergent exits and concurrent dispatches of one pipeline share the buffer safely. The emitter fails the compile if a compute return lacks the release.
  • Programs without scratch keep their SPIR-V and pipeline layout. Graphics stages are unchanged.
  • tests/GuardedMemoryLoads.cpp changes too: that fixture runs the emitted code in its interpreter, which now skips the slot claim and offsets scratch indexes by the 2-dword slot header. It also gains checks for the new layout.

The buffer is decorated Coherent. Without it, on an RTX 4090, an unaligned 32-bit FLAT store to scratch (emitted as four byte read-modify-writes) loses the first byte of each pair sharing a dword: flat_apertures_2, flat_apertures_5 and flat_aperture_sources fail, always with the same value. It is not lane overlap (4× lane spacing gives the same result), not spirv-opt (same with it off) and Aliased doesn't help. The SPIR-V is a plain load, mask and store in program order, so this looks like a driver ordering issue, but I haven't read the GPU assembly to prove it. The debt entry in docs/dev/debt/shader.md says so.

On the review of the first version: the provenance rule, formsPrivateAperture, APS5_FLAT_PRIVATE_ALWAYS and the edit to FlatApertures.cpp are gone. main's FlatApertures.cpp is unchanged and passes. Callees reached through s_swappc_b64 are linked into the caller's graph (GraphBuilder LinkCalls), so they are translated with it and use the same buffer; the new test covers that case.

On the second review (discarded batch): the slot headers were zeroed inside the first dispatch's batch and the pool was marked zeroed before submit, so a discarded batch left a cached pool marked zeroed with garbage headers. Now the headers are zeroed once when the pool is created, in a batch submitted and waited on under the GPU lock; the zeroed flag and the in-batch fill are gone, and the pool lookup runs before the recorder opens the dispatch's commands. The debt entry "Compute scratch pool header clear" in docs/dev/debt/libSceAgcDriver.md covers the blocking submit.

On the AMD report: the test seam Recorder::FailNextSubmitsForTest threw before vkEndCommandBuffer, so the discarded batch went back to the spare list while still recording, and the next vkBeginCommandBuffer on it failed on RDNA 4 (VUID-vkBeginCommandBuffer-commandBuffer-00049, result -13). The injected failure now comes after the end and stands for a failed vkQueueSubmit.

The PR has six commits, meant to be read in order (squash on merge is fine):

  1. a46f050af8 perf(recompiler): back compute scratch with a device buffer slot pool — the change described above.
  2. f369273365 fix(agc): zero the scratch pool header when the pool is created — the fix for the discarded-batch review.
  3. d9668fdbee fix(agc): end the command buffer before the injected submit failure — the fix for the AMD report; it touches only the test seam.
  4. cc61c3ae31 perf(agc): hold all compute scratch pools under one memory budget — APS5_SCRATCH_POOL_TOTAL_MIB with LRU eviction (review point 3).
  5. ce38162aa1 fix(agc): hold one compute scratch pool under 2 GiB and the total budget.
  6. 28a30ed35d perf(shader): read a scratch pool slot lock before trying to take it (review point 4).
Why the dynamic indexing is the cost (offline replay, cold driver cache, one compile thread, PPSA26344 program 0x1994ed, 1.52M SPIR-V words)
Variant compile thread CPU nvoglv64 share
as emitted on main 141-145 s 36-37 %
scratch indices made constant 92-100 s 1.45 %
scratch arrays as Workgroup 101 s 1.34 %
scratch arrays as a storage buffer 100 s 1.38 %

Workgroup memory can't hold it: 56 dwords per lane × 512 lanes is 114 KB.

The runtime side (third review) has a cost. A local bench, not in this PR: one compute program with 448 scratch dwords per lane, median of repeated dispatches, RTX 4090, driver 617.42. It is listed in the debt file as "Compute scratch runtime cost".

Dispatch time of a scratch-heavy program, `main` against this PR
groups main (Function arrays) PR, 64 MiB pool (~580 slots) PR, Coherent dropped PR, 1 MiB pool (~9 slots) PR, 4096 MiB asked (held at 256)
256 1.56 ms 3.8 ms 3.6 ms 10.6 ms 3.7 ms
4096 22.1 ms 49 ms 48 ms 172 ms 54 ms
32768 183 ms 389 ms 379 ms 1377 ms (1308 ms with the lock read) 425 ms

About 2.4× slower at the default size; Coherent is not the cost. With fewer slots than resident groups the groups wait for a slot: reading the lock before the compare-exchange gains about 5 % at 9 slots and nothing at 580.

Tested

Windows 11, MinGW GCC 15.2, RTX 4090 (driver 617.42), i9-13900K.

  • New agc_driver_scratch_pool (tests/execution/ScratchPool.cpp), wave32 and wave64:
    • private-aperture pointers from a table load, a literal and a computed address, through FLAT store and atomic, and both ways through scratch_*;
    • a callee reached through s_swappc_b64;
    • isolation of 64 workgroups over one or two slots;
    • divergent wave exits, then a second dispatch reusing the slots;
    • module shape: no Function scratch array, and no extra binding in a program without scratch.
  • Focused run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 45/45 pass (FLAT apertures, LDS, scratch, guarded memory loads), no VUID-. Rerun of the 16 FLAT aperture and scratch pool tests with VK_LOADER_DEBUG=layer to confirm the layer loads: 16/16, no VUID-.
  • Negative control: with the release ignoring the counter, agc_driver_scratch_pool fails (isolation: "round 0 lane 0 dword 0 read 0x00002200, expected 0x00000000"; divergent exit: "round 0 lane 160 dword 0 read 0x00003180, expected 0x00000280").
  • RunDiscardedInitialization in agc_driver_scratch_pool (test seam Recorder::FailNextSubmitsForTest): discards the first dispatch's batch, then dispatches again on the cached pool. Fails before the header fix ("header word 0 reads 0xffffffff"), passes after.
  • Full ctest after rebasing onto main f7f03daf52: 3107/3107. The focused run above, repeated on the rebased branch: 43/43 FLAT aperture, scratch pool, LDS and guarded memory load tests, no VUID-. The rebase conflicted only where main's meshWindowBuffer field (#12233) sits next to scratchPoolSlotDwords (kept both, same order in the disk cache writer and reader) and in the debt file.
  • After the third commit, rebased onto main f2d874c1fd: full ctest 3286/3286; focused run with the same environment 56/56 (FLAT apertures, scratch pool, LDS, guarded memory loads, recorder), agc_driver_scratch_pool included, no VUID-. The rebase conflicted only where main's compute pipeline binary key (0c572f1c25) is built: the key's first word now also sets bit 1 when the scratch pool set is bound, so keys of pipelines without scratch are unchanged.
  • After the review commits, rebased onto main be24202363: full ctest 3283/3283. Focused run with the same environment (flat|scratch|lds|guarded|recorder): 64/64 on the PR, 63/63 on main, no VUID- in either.
  • The game measurements below were taken on main aaccd0ba39 and the first commit on top of it.

PPSA26344 (Ghost of Yōtei 01.008.000), 3840x2160, fresh save, shader cache warmed by a previous run of the same build, frames 250-280 (loading). main aaccd0ba39 and this PR alternate, three runs each. The PR build compiled about 13 compute programs with the slot pool before frame 350 (26 shader cache entries bind descriptor set 2; none on main); Those 13 are compiled, not dispatched: a local build that logs every pool creation, run warm with APS5_PROFILE_GPU=1 for 1500 s, created no pool up to frame 517 (main) and 530 (PR). So no scratch program dispatches in the window, and the trace pair below can only show compile-side effects. GPU time over frames 250-280 was 2.08 s on main and 2.20 s on the PR (noise; 50.9 s against 52.5 s over the whole run).

main:

{"commit":"aaccd0ba39b7","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":16996.075},"presents":30,"frame_ms":{"p50":308.640,"p90":1276.579,"p99":1890.406,"max":1890.406},"gpu_busy_ms_per_present":111.751,"worker_busy_pct":{"queue worker 0x0":75.642,"queue worker 0x52":1.078,"queue worker 0x53":0.000,"queue worker 0x20":27.602,"queue worker 0x30":62.036,"queue worker 0x38":59.136,"queue worker 0x48":24.100},"top_phases_ms_per_frame":{"Driver.Packet":1410.773,"Driver.Packet.memory_wait":757.111,"Driver.Packet.dispatch":422.516,"Driver.Dispatch":407.334,"GpuMutex.wait.other":160.332,"Vulkan.Dispatch":144.609,"Vulkan.Dispatch.shader_resources":130.486,"Driver.Packet.prepare_memory":110.346},"trace_dropped":false,"trace":"aps5-trace-aaccd0ba39b7-2756.json.gz"}

This PR:

{"commit":"659d07bbc8c0","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":13989.698},"presents":30,"frame_ms":{"p50":263.902,"p90":1098.961,"p99":1768.352,"max":1768.352},"gpu_busy_ms_per_present":102.834,"worker_busy_pct":{"queue worker 0x0":83.139,"queue worker 0x52":0.717,"queue worker 0x53":0.000,"queue worker 0x20":26.429,"queue worker 0x30":69.186,"queue worker 0x38":66.501,"queue worker 0x48":26.299},"top_phases_ms_per_frame":{"Driver.Packet":1266.947,"Driver.Packet.memory_wait":702.545,"Driver.Packet.dispatch":377.420,"Driver.Dispatch":362.764,"Vulkan.Dispatch":132.113,"Vulkan.Dispatch.shader_resources":119.352,"GpuMutex.wait.other":110.325,"Driver.Packet.prepare_memory":87.509},"trace_dropped":false,"trace":"aps5-trace-659d07bbc8c0-15012.json.gz"}
pair main (window, frame, GPU per present) this PR
1 14.5 s, p50 283 / p99 1604 ms, GPU 102.2 ms 16.5 s, p50 349 / p99 2658 ms, GPU 113.9 ms
2 16.5 s, p50 346 / p99 1939 ms, GPU 100.2 ms 15.9 s, p50 264 / p99 2134 ms, GPU 110.0 ms
3 17.0 s, p50 309 / p99 1890 ms, GPU 111.8 ms 14.0 s, p50 264 / p99 1768 ms, GPU 102.8 ms

The spread between runs of the same build (14.5-17.0 s) is larger than any difference between the two; no frame cost from the device-memory scratch shows in this scene. APS5_NO_SNAPSHOT_CHECK reads 1APS5_SPANNED_WAVE=1 because of a missing comma in my launcher, so APS5_SPANNED_WAVE is off in all six runs, as on main by default.

trace_digest, `main` (last pair)

frames 250:30 from present 250: 30 presents, frame p50 308.6 / p90 1276.6 / p99 1890.4 / max 1890.4 ms, GPU busy 111.8 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit aaccd0ba39, dropped: no

{"commit":"aaccd0ba39b7","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":16996.075},"presents":30,"frame_ms":{"p50":308.64,"p90":1276.579,"p99":1890.406,"max":1890.406},"gpu_busy_ms_per_present":111.751,"worker_busy_pct":{"queue worker 0x0":75.642,"queue worker 0x52":1.078,"queue worker 0x53":0.0,"queue worker 0x20":27.602,"queue worker 0x30":62.036,"queue worker 0x38":59.136,"queue worker 0x48":24.1},"top_phases_ms_per_frame":{"Driver.Packet":1410.773,"Driver.Packet.memory_wait":757.111,"Driver.Packet.dispatch":422.516,"Driver.Dispatch":407.334,"GpuMutex.wait.other":160.332,"Vulkan.Dispatch":144.609,"Vulkan.Dispatch.shader_resources":130.486,"Driver.Packet.prepare_memory":110.346},"trace_dropped":false,"trace":"aps5-trace-aaccd0ba39b7-2756.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 273: 1890.4 ms at 8317 ms: Driver.WorkerWait (queue worker 0x20) 1812.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1812.0, Driver.WorkerWait (queue worker 0x48) 1469.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1469.0
  • present 277: 1312.8 ms at 13271 ms: Driver.WorkerWait (queue worker 0x48) 1114.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1114.1, Driver.WorkerWait (queue worker 0x20) 788.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 788.8
  • present 275: 1276.6 ms at 10986 ms: Driver.WorkerWait (queue worker 0x48) 905.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 905.0, Driver.Packet (queue worker 0x0) 744.6, Driver.Packet (queue worker 0x30) 711.7
  • present 279: 1215.3 ms at 15781 ms: GpuMutex.wait.other (title) 750.5, Driver.Packet (queue worker 0x0) 607.9, Driver.WorkerWait (queue worker 0x0) 605.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 605.0
  • present 278: 1196.5 ms at 14584 ms: Driver.WorkerWait (queue worker 0x20) 1171.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1171.1, Driver.WorkerWait (queue worker 0x48) 1022.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1022.8

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 8.6 (2 %) 160.0 (28 %) 397.9 0.5 Shader.Register 6.8, Shader.ResolveAbi 1.8
shader prepare 3.5 (1 %) 0.0 (0 %) 563.0 0.0 Shader.PrepareArtifact 3.5
shader prepare 3.3 (1 %) 0.0 (0 %) 563.2 0.0 Shader.PrepareArtifact 3.3
shader prepare 3.4 (1 %) 0.0 (0 %) 563.1 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.7 (1 %) 0.0 (0 %) 562.9 0.0 Shader.PrepareArtifact 3.7
shader prepare 3.2 (1 %) 0.0 (0 %) 563.3 0.0 Shader.PrepareArtifact 3.2
shader prepare 3.6 (1 %) 0.0 (0 %) 562.9 0.0 Shader.PrepareArtifact 3.6
shader prepare 3.4 (1 %) 0.0 (0 %) 563.2 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.4 (1 %) 0.0 (0 %) 563.1 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.4 (1 %) 0.0 (0 %) 563.2 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.5 (1 %) 0.0 (0 %) 563.1 0.0 Shader.PrepareArtifact 3.5
shader prepare 3.1 (1 %) 0.0 (0 %) 563.4 0.0 Shader.PrepareArtifact 3.1
shader prepare 3.8 (1 %) 0.0 (0 %) 562.7 0.0 Shader.PrepareArtifact 3.8
shader prepare 3.3 (1 %) 0.0 (0 %) 563.3 0.0 Shader.PrepareArtifact 3.3
shader prepare 3.9 (1 %) 0.0 (0 %) 562.7 0.0 Shader.PrepareArtifact 3.9
shader prepare 3.6 (1 %) 0.0 (0 %) 562.9 0.0 Shader.PrepareArtifact 3.6
shader prepare 3.4 (1 %) 0.0 (0 %) 563.1 0.0 Shader.PrepareArtifact 3.4
shader prepare 11.1 (2 %) 0.0 (0 %) 555.4 0.0 Vulkan.ComputePipeline 10.4, Vulkan.GraphicsPipelinePrebuild 0.7
shader prepare 9.4 (2 %) 0.0 (0 %) 557.1 0.0 Vulkan.ComputePipeline 8.6, Vulkan.GraphicsPipelinePrebuild 0.8
queue worker 0x0 312.0 (55 %) 251.3 (44 %) 3.3 13.7 Driver.Packet 426.0, Driver.Completion 0.0
queue worker 0x52 1.6 (0 %) 174.2 (31 %) 390.7 0.1 Driver.Packet 5.7, Driver.EndSubmission 0.4
queue worker 0x20 13.8 (2 %) 532.2 (94 %) 20.5 0.2 Driver.Packet 155.8, Driver.EndSubmission 0.5
title 1.9 (0 %) 0.0 (0 %) 564.6 0.0 Shader.ResolveAbi 1.9, Shader.ResolveGraphicsStagesAbi 0.1
title 1.6 (0 %) 0.0 (0 %) 564.9 0.0 Shader.ResolveAbi 1.5, Shader.ResolveGraphicsStagesAbi 0.1
title 0.3 (0 %) 0.0 (0 %) 566.2 0.0 Shader.ResolveAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.0
queue worker 0x30 23.5 (4 %) 538.4 (95 %) 4.6 0.8 Driver.Packet 351.1, Driver.EndSubmission 0.3
queue worker 0x38 120.2 (21 %) 440.0 (78 %) 6.3 4.6 Driver.Packet 333.6, Driver.EndSubmission 0.7
queue worker 0x48 37.7 (7 %) 516.1 (91 %) 12.8 1.7 Driver.Packet 135.1, Driver.EndSubmission 1.3
draw committer 87.8 (15 %) 27.5 (5 %) 451.2 0.8 Graphics.Draw 90.2, Recorder.Sync 1.7
presenter 6.1 (1 %) 0.0 (0 %) 560.4 0.1 VideoOut.Flip 5.9, Driver.Present 0.2
title 0.9 (0 %) 0.0 (0 %) 565.6 0.0 Shader.ResolveAbi 0.9, Shader.ResolveGraphicsStagesAbi 0.0
title 1.5 (0 %) 0.0 (0 %) 565.0 0.0 Shader.ResolveAbi 1.4, Shader.ResolveGraphicsStagesAbi 0.0
title 3.8 (1 %) 0.0 (0 %) 562.8 0.0 Shader.ResolveAbi 3.7, Shader.ResolveGraphicsStagesAbi 0.1
title 1.4 (0 %) 0.0 (0 %) 565.1 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.1
title 1.4 (0 %) 0.0 (0 %) 565.2 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0
title 0.1 (0 %) 0.0 (0 %) 566.4 0.0 Shader.ResolveAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.0
title 1.3 (0 %) 0.0 (0 %) 565.2 0.0 Shader.ResolveAbi 1.2, Shader.ResolveGraphicsStagesAbi 0.0
gpu 112.1 (20 %) 0.0 (0 %) 454.5 0.0 batch 112.1

Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1550.5, Driver.WorkerWait.idle_and_completion_poll 1550.5, Driver.Packet 1407.2, Driver.Packet.memory_wait 757.1, Driver.Packet.dispatch 421.3, Driver.Dispatch 405.4, GpuMutex.wait.other 160.2, Vulkan.Dispatch 143.7

Longest waits

  • Driver.WorkerWait (queue worker 0x20) 1637.3 ms at 7592 ms, present 271
  • Driver.WorkerWait (queue worker 0x48) 1427.7 ms at 7878 ms, present 272
  • Driver.WorkerWait (queue worker 0x20) 1281.9 ms at 13907 ms, present 277
  • Driver.WorkerWait (queue worker 0x48) 1275.1 ms at 12633 ms, present 276
  • Driver.WorkerWait (queue worker 0x20) 1204.3 ms at 12179 ms, present 275
  • Driver.WorkerWait (queue worker 0x38) 1175.3 ms at 8130 ms, present 272
  • Driver.WorkerWait (queue worker 0x20) 1158.9 ms at 15215 ms, present 278
  • Driver.WorkerWait (queue worker 0x30) 1153.5 ms at 8152 ms, present 272

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 3891: 93.2 ms at 13076 ms, present 276: GPU no ranges; recorded by Recorder.Sync (queue worker 0x30) 93.6, Driver.Packet (queue worker 0x30) 23.0, Driver.Packet.dispatch (queue worker 0x30) 23.0, Driver.Dispatch (queue worker 0x30) 23.0
  • batch 450: 50.0 ms at 3280 ms, present 256: GPU no ranges; recorded by Driver.Packet (queue worker 0x30) 207.8, Driver.Packet.dispatch (queue worker 0x30) 207.8, Recorder.Sync (queue worker 0x30) 50.2, Driver.Dispatch (queue worker 0x30) 45.9
  • batch 3875: 40.9 ms at 12860 ms, present 276: GPU no ranges; recorded by Recorder.Sync (queue worker 0x38) 41.6, Driver.Packet (queue worker 0x38) 41.5, Driver.Packet.dispatch (queue worker 0x38) 41.5, Driver.Dispatch (queue worker 0x38) 41.5
  • batch 2948: 29.0 ms at 9835 ms, present 273: GPU no ranges; recorded by Driver.Packet (queue worker 0x38) 110.7, Driver.Packet.memory_wait (queue worker 0x38) 82.6, Driver.Dispatch (queue worker 0x38) 28.1, Driver.Packet.dispatch (queue worker 0x38) 28.1
  • batch 361: 28.5 ms at 2637 ms, present 255: GPU no ranges; recorded by Recorder.Sync (queue worker 0x38) 28.9, Driver.Packet (queue worker 0x38) 9.6, Driver.Packet.dispatch (queue worker 0x38) 9.6, Driver.Dispatch (queue worker 0x38) 9.6
trace_digest, this PR (last pair)

frames 250:30 from present 250: 30 presents, frame p50 263.9 / p90 1099.0 / p99 1768.4 / max 1768.4 ms, GPU busy 102.8 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit 659d07bbc8c0, dropped: no

{"commit":"659d07bbc8c0","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":13989.698},"presents":30,"frame_ms":{"p50":263.902,"p90":1098.961,"p99":1768.352,"max":1768.352},"gpu_busy_ms_per_present":102.834,"worker_busy_pct":{"queue worker 0x0":83.139,"queue worker 0x52":0.717,"queue worker 0x53":0.0,"queue worker 0x20":26.429,"queue worker 0x30":69.186,"queue worker 0x38":66.501,"queue worker 0x48":26.299},"top_phases_ms_per_frame":{"Driver.Packet":1266.947,"Driver.Packet.memory_wait":702.545,"Driver.Packet.dispatch":377.42,"Driver.Dispatch":362.764,"Vulkan.Dispatch":132.113,"Vulkan.Dispatch.shader_resources":119.352,"GpuMutex.wait.other":110.325,"Driver.Packet.prepare_memory":87.509},"trace_dropped":false,"trace":"aps5-trace-659d07bbc8c0-15012.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 274: 1768.4 ms at 7705 ms: Driver.WorkerWait (queue worker 0x20) 1676.9, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1676.9, Driver.WorkerWait (queue worker 0x48) 1336.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1336.1
  • present 278: 1159.4 ms at 11731 ms: Driver.WorkerWait (queue worker 0x48) 971.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 971.2, Driver.WorkerWait (queue worker 0x38) 696.6, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x38) 696.6
  • present 279: 1099.0 ms at 12891 ms: Driver.WorkerWait (queue worker 0x20) 992.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 992.4, Driver.WorkerWait (queue worker 0x0) 626.3, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 626.3
  • present 257: 1086.3 ms at 2263 ms: Driver.WorkerWait (queue worker 0x52) 1081.9, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x52) 1081.9, Driver.Packet (queue worker 0x0) 1081.7, Driver.WorkerWait (queue worker 0x48) 935.8
  • present 277: 768.1 ms at 10963 ms: Driver.WorkerWait (queue worker 0x20) 768.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 768.1, Driver.Packet (queue worker 0x0) 754.4, Driver.Packet (queue worker 0x30) 684.8

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 8.2 (2 %) 110.1 (24 %) 348.0 0.5 Shader.Register 5.4, Shader.ResolveAbi 2.8
shader prepare 3.3 (1 %) 0.0 (0 %) 463.0 0.0 Shader.PrepareArtifact 3.3
shader prepare 3.4 (1 %) 0.0 (0 %) 463.0 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.8 (1 %) 0.0 (0 %) 462.5 0.0 Shader.PrepareArtifact 3.8
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.3 (1 %) 0.0 (0 %) 463.0 0.0 Shader.PrepareArtifact 3.3
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.0 (1 %) 0.0 (0 %) 463.3 0.0 Shader.PrepareArtifact 3.0
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.3 (1 %) 0.0 (0 %) 463.0 0.0 Shader.PrepareArtifact 3.3
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.2 (1 %) 0.0 (0 %) 463.1 0.0 Shader.PrepareArtifact 3.2
shader prepare 3.7 (1 %) 0.0 (0 %) 462.7 0.0 Shader.PrepareArtifact 3.7
shader prepare 3.4 (1 %) 0.0 (0 %) 462.9 0.0 Shader.PrepareArtifact 3.4
shader prepare 3.6 (1 %) 0.0 (0 %) 462.7 0.0 Shader.PrepareArtifact 3.6
shader prepare 8.0 (2 %) 0.0 (0 %) 458.3 0.0 Vulkan.ComputePipeline 7.3, Vulkan.GraphicsPipelinePrebuild 0.8
shader prepare 11.0 (2 %) 0.0 (0 %) 455.3 0.0 Vulkan.ComputePipeline 10.3, Vulkan.GraphicsPipelinePrebuild 0.7
queue worker 0x0 276.8 (59 %) 186.4 (40 %) 3.2 13.2 Driver.Packet 385.2, Driver.Completion 0.0
queue worker 0x52 1.4 (0 %) 170.9 (37 %) 294.1 0.1 Driver.Packet 3.0, Driver.EndSubmission 0.3
queue worker 0x20 9.7 (2 %) 447.0 (96 %) 9.6 0.2 Driver.Packet 123.0, Driver.EndSubmission 0.2
title 0.3 (0 %) 0.0 (0 %) 466.1 0.0 Shader.ResolveAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.0
title 1.3 (0 %) 0.0 (0 %) 465.0 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0
title 1.3 (0 %) 0.0 (0 %) 465.1 0.0 Shader.ResolveAbi 1.2, Shader.ResolveGraphicsStagesAbi 0.0
queue worker 0x30 19.6 (4 %) 444.8 (95 %) 1.9 0.8 Driver.Packet 322.3, Driver.EndSubmission 0.2
queue worker 0x38 111.6 (24 %) 351.8 (75 %) 3.0 4.6 Driver.Packet 308.5, Driver.EndSubmission 0.9
queue worker 0x48 35.5 (8 %) 421.7 (90 %) 9.1 1.8 Driver.Packet 121.5, Driver.EndSubmission 1.0
draw committer 76.9 (16 %) 23.1 (5 %) 366.3 0.8 Graphics.Draw 77.5, Vulkan.DrawFromRecipe 1.5
presenter 6.3 (1 %) 0.0 (0 %) 460.0 0.1 VideoOut.Flip 6.0, Driver.Present 0.2
title 1.4 (0 %) 0.0 (0 %) 465.0 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0
title 0.9 (0 %) 0.0 (0 %) 465.4 0.0 Shader.ResolveAbi 0.9, Shader.ResolveGraphicsStagesAbi 0.0
title 0.8 (0 %) 0.0 (0 %) 465.5 0.0 Shader.ResolveAbi 0.7, Shader.ResolveGraphicsStagesAbi 0.0
title 1.6 (0 %) 0.0 (0 %) 464.8 0.0 Shader.ResolveAbi 1.5, Shader.ResolveGraphicsStagesAbi 0.0
title 1.3 (0 %) 0.0 (0 %) 465.0 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0
title 2.0 (0 %) 0.0 (0 %) 464.3 0.0 Shader.ResolveAbi 1.9, Shader.ResolveGraphicsStagesAbi 0.0
title 1.3 (0 %) 0.0 (0 %) 465.0 0.0 Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.1
gpu 99.8 (21 %) 0.0 (0 %) 366.6 0.0 batch 99.8

Largest slices (ms per frame, inclusive, all threads): Driver.Packet 1263.4, Driver.WorkerWait 1211.0, Driver.WorkerWait.idle_and_completion_poll 1211.0, Driver.Packet.memory_wait 702.5, Driver.Packet.dispatch 376.2, Driver.Dispatch 360.8, Vulkan.Dispatch 131.1, Vulkan.Dispatch.shader_resources 118.4

Longest waits

  • Driver.WorkerWait (queue worker 0x20) 1598.9 ms at 6995 ms, present 272
  • Driver.WorkerWait (queue worker 0x48) 1420.1 ms at 7238 ms, present 273
  • Driver.WorkerWait (queue worker 0x20) 1213.3 ms at 12289 ms, present 278
  • Driver.WorkerWait (queue worker 0x38) 1160.9 ms at 7497 ms, present 273
  • Driver.WorkerWait (queue worker 0x30) 1141.5 ms at 7516 ms, present 273
  • Driver.WorkerWait (queue worker 0x52) 1122.8 ms at 2287 ms, present 257
  • Driver.WorkerWait (queue worker 0x48) 1039.0 ms at 12478 ms, present 278
  • Driver.WorkerWait (queue worker 0x48) 964.4 ms at 11325 ms, present 277

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 3981: 77.5 ms at 11579 ms, present 277: GPU no ranges; recorded by Recorder.Sync (queue worker 0x30) 77.8, Driver.Packet (queue worker 0x30) 21.3, Driver.Packet.dispatch (queue worker 0x30) 21.3, Driver.Dispatch (queue worker 0x30) 21.3
  • batch 505: 57.1 ms at 2702 ms, present 257: GPU no ranges; recorded by Driver.Packet (queue worker 0x30) 171.0, Driver.Packet.dispatch (queue worker 0x30) 171.0, Recorder.Sync (queue worker 0x30) 57.5, Driver.Dispatch (queue worker 0x30) 45.1
  • batch 581: 18.7 ms at 3680 ms, present 258: GPU no ranges; recorded by Driver.Packet (queue worker 0x38) 19.2, Driver.Packet.prepare_memory (queue worker 0x38) 19.0, Vulkan.Dispatch.shader_resources (queue worker 0x38) 0.4, Driver.Dispatch (queue worker 0x38) 0.2
  • batch 648: 18.1 ms at 3945 ms, present 259: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 18.6, Driver.Packet.prepare_memory (queue worker 0x0) 18.4, Resources.Prepare (queue worker 0x0) 0.8, Recorder.Sync (queue worker 0x0) 0.3
  • batch 717: 18.0 ms at 4178 ms, present 260: GPU no ranges; recorded by GpuMutex.wait.end (queue worker 0x20) 0.2, Driver.Packet (queue worker 0x20) 0.1, Driver.Packet.dispatch (queue worker 0x20) 0.1, Driver.Dispatch (queue worker 0x20) 0.1
Downstream only (Celegans12's yotei/best plus local changes, not main): PPSA26344 all cold to frame 1200

Same downstream build and environment in each row; only the scratch handling differs. Cold shader cache, NVIDIA driver cache moved aside, fresh save.

run scratch frame 700 frame 1000 frame 1200 compile s: 0x8000173b00 / 117800 / 14e300 / 167500
run570 Function arrays (as on main) 363 s 758 s 1,012 s 199 / 217 / 162 / 176
run575 this PR 322 s 664 s 905 s 146 / 168 / 117 / 114

run570 also lacks one other local change (#6867), so its frame times are not a pure A/B; the compile times of the four programs are. Offline, from captures of the same programs (one compile thread, cold driver cache): 1.69M and 1.57M words compile in 100 s each with this PR, against 135-137 s for 1.45-1.52M words with the arrays.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 4090, driver 617.42, Windows 11
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5064841120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12764). Originally posted by [Pipodi](https://github.com/Pipodi) on 2026-10-29T08:33:26Z. --- ### What Every compute FLAT load, store and atomic in a program with scratch tests its address against the shared and the private aperture (c35f29b6be). The private path reaches the per-lane scratch, held in Function `scratch_dwords` arrays indexed dynamically at every FLAT site. On NVIDIA that indexing is what makes large compute programs slow to compile: the SPIR-V front end (nvoglv64) spends about a third of the compile on it. This PR keeps the FLAT routing exactly as on `main`, for every access, and changes only where scratch lives. A compute program that uses scratch (`scratch_*`, or a FLAT access routed to the private aperture) now keeps it in a storage buffer, so no Function array is declared or indexed: - The driver allocates one buffer per compute pipeline at its first dispatch and binds it in descriptor set 2 (the layout of the device-memory LDS buffer). The buffer holds a lock word and an invocation counter per slot, then the slots. It is capped by `APS5_SCRATCH_POOL_MIB` (default 64, never below one slot), by `maxStorageBufferRange` and by 2 GiB: on the RTX 4090 a larger buffer returned wrong values (2049 MiB fails, 2047 MiB passes). All pools together stay under `APS5_SCRATCH_POOL_TOTAL_MIB` (default 256); a new pool evicts the least recently used ones first. The shader takes the slot count from the array length. - Invocation 0 of each workgroup claims a slot with a scan that reads each lock word and tries a compare-exchange only on a free one, starting at its linear workgroup id; a barrier publishes the slot. Every invocation decrements the slot counter at every compute exit and the last one frees the lock, so divergent exits and concurrent dispatches of one pipeline share the buffer safely. The emitter fails the compile if a compute return lacks the release. - Programs without scratch keep their SPIR-V and pipeline layout. Graphics stages are unchanged. - `tests/GuardedMemoryLoads.cpp` changes too: that fixture runs the emitted code in its interpreter, which now skips the slot claim and offsets scratch indexes by the 2-dword slot header. It also gains checks for the new layout. The buffer is decorated `Coherent`. Without it, on an RTX 4090, an unaligned 32-bit FLAT store to scratch (emitted as four byte read-modify-writes) loses the first byte of each pair sharing a dword: `flat_apertures_2`, `flat_apertures_5` and `flat_aperture_sources` fail, always with the same value. It is not lane overlap (4× lane spacing gives the same result), not spirv-opt (same with it off) and `Aliased` doesn't help. The SPIR-V is a plain load, mask and store in program order, so this looks like a driver ordering issue, but I haven't read the GPU assembly to prove it. The debt entry in `docs/dev/debt/shader.md` says so. On the review of the first version: the provenance rule, `formsPrivateAperture`, `APS5_FLAT_PRIVATE_ALWAYS` and the edit to `FlatApertures.cpp` are gone. `main`'s `FlatApertures.cpp` is unchanged and passes. Callees reached through `s_swappc_b64` are linked into the caller's graph (`GraphBuilder` `LinkCalls`), so they are translated with it and use the same buffer; the new test covers that case. On the second review (discarded batch): the slot headers were zeroed inside the first dispatch's batch and the pool was marked zeroed before submit, so a discarded batch left a cached pool marked zeroed with garbage headers. Now the headers are zeroed once when the pool is created, in a batch submitted and waited on under the GPU lock; the `zeroed` flag and the in-batch fill are gone, and the pool lookup runs before the recorder opens the dispatch's commands. The debt entry "Compute scratch pool header clear" in `docs/dev/debt/libSceAgcDriver.md` covers the blocking submit. On the AMD report: the test seam `Recorder::FailNextSubmitsForTest` threw before `vkEndCommandBuffer`, so the discarded batch went back to the spare list while still recording, and the next `vkBeginCommandBuffer` on it failed on RDNA 4 (`VUID-vkBeginCommandBuffer-commandBuffer-00049`, result -13). The injected failure now comes after the end and stands for a failed `vkQueueSubmit`. The PR has six commits, meant to be read in order (squash on merge is fine): 1. `a46f050af8` perf(recompiler): back compute scratch with a device buffer slot pool — the change described above. 2. `f369273365` fix(agc): zero the scratch pool header when the pool is created — the fix for the discarded-batch review. 3. `d9668fdbee` fix(agc): end the command buffer before the injected submit failure — the fix for the AMD report; it touches only the test seam. 4. `cc61c3ae31` perf(agc): hold all compute scratch pools under one memory budget — `APS5_SCRATCH_POOL_TOTAL_MIB` with LRU eviction (review point 3). 5. `ce38162aa1` fix(agc): hold one compute scratch pool under 2 GiB and the total budget. 6. `28a30ed35d` perf(shader): read a scratch pool slot lock before trying to take it (review point 4). <details><summary>Why the dynamic indexing is the cost (offline replay, cold driver cache, one compile thread, PPSA26344 program 0x1994ed, 1.52M SPIR-V words)</summary> | Variant | compile thread CPU | nvoglv64 share | |---|---|---| | as emitted on `main` | 141-145 s | 36-37 % | | scratch indices made constant | 92-100 s | 1.45 % | | scratch arrays as Workgroup | 101 s | 1.34 % | | scratch arrays as a storage buffer | 100 s | 1.38 % | Workgroup memory can't hold it: 56 dwords per lane × 512 lanes is 114 KB. </details> The runtime side (third review) has a cost. A local bench, not in this PR: one compute program with 448 scratch dwords per lane, median of repeated dispatches, RTX 4090, driver 617.42. It is listed in the debt file as "Compute scratch runtime cost". <details><summary>Dispatch time of a scratch-heavy program, `main` against this PR</summary> | groups | `main` (Function arrays) | PR, 64 MiB pool (~580 slots) | PR, `Coherent` dropped | PR, 1 MiB pool (~9 slots) | PR, 4096 MiB asked (held at 256) | |---|---|---|---|---|---| | 256 | 1.56 ms | 3.8 ms | 3.6 ms | 10.6 ms | 3.7 ms | | 4096 | 22.1 ms | 49 ms | 48 ms | 172 ms | 54 ms | | 32768 | 183 ms | 389 ms | 379 ms | 1377 ms (1308 ms with the lock read) | 425 ms | About 2.4× slower at the default size; `Coherent` is not the cost. With fewer slots than resident groups the groups wait for a slot: reading the lock before the compare-exchange gains about 5 % at 9 slots and nothing at 580. </details> ### Tested Windows 11, MinGW GCC 15.2, RTX 4090 (driver 617.42), i9-13900K. - New `agc_driver_scratch_pool` (`tests/execution/ScratchPool.cpp`), wave32 and wave64: - private-aperture pointers from a table load, a literal and a computed address, through FLAT store and atomic, and both ways through `scratch_*`; - a callee reached through `s_swappc_b64`; - isolation of 64 workgroups over one or two slots; - divergent wave exits, then a second dispatch reusing the slots; - module shape: no Function scratch array, and no extra binding in a program without scratch. - Focused run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: 45/45 pass (FLAT apertures, LDS, scratch, guarded memory loads), no `VUID-`. Rerun of the 16 FLAT aperture and scratch pool tests with `VK_LOADER_DEBUG=layer` to confirm the layer loads: 16/16, no `VUID-`. - Negative control: with the release ignoring the counter, `agc_driver_scratch_pool` fails (isolation: "round 0 lane 0 dword 0 read 0x00002200, expected 0x00000000"; divergent exit: "round 0 lane 160 dword 0 read 0x00003180, expected 0x00000280"). - `RunDiscardedInitialization` in `agc_driver_scratch_pool` (test seam `Recorder::FailNextSubmitsForTest`): discards the first dispatch's batch, then dispatches again on the cached pool. Fails before the header fix ("header word 0 reads 0xffffffff"), passes after. - Full ctest after rebasing onto `main` f7f03daf52: 3107/3107. The focused run above, repeated on the rebased branch: 43/43 FLAT aperture, scratch pool, LDS and guarded memory load tests, no `VUID-`. The rebase conflicted only where `main`'s `meshWindowBuffer` field (#12233) sits next to `scratchPoolSlotDwords` (kept both, same order in the disk cache writer and reader) and in the debt file. - After the third commit, rebased onto `main` f2d874c1fd: full ctest 3286/3286; focused run with the same environment 56/56 (FLAT apertures, scratch pool, LDS, guarded memory loads, recorder), `agc_driver_scratch_pool` included, no `VUID-`. The rebase conflicted only where `main`'s compute pipeline binary key (0c572f1c25) is built: the key's first word now also sets bit 1 when the scratch pool set is bound, so keys of pipelines without scratch are unchanged. - After the review commits, rebased onto `main` be24202363: full ctest 3283/3283. Focused run with the same environment (`flat|scratch|lds|guarded|recorder`): 64/64 on the PR, 63/63 on `main`, no `VUID-` in either. - The game measurements below were taken on `main` aaccd0ba39 and the first commit on top of it. PPSA26344 (Ghost of Yōtei 01.008.000), 3840x2160, fresh save, shader cache warmed by a previous run of the same build, frames 250-280 (loading). `main` aaccd0ba39 and this PR alternate, three runs each. The PR build compiled about 13 compute programs with the slot pool before frame 350 (26 shader cache entries bind descriptor set 2; none on `main`); Those 13 are compiled, not dispatched: a local build that logs every pool creation, run warm with `APS5_PROFILE_GPU=1` for 1500 s, created no pool up to frame 517 (`main`) and 530 (PR). So no scratch program dispatches in the window, and the trace pair below can only show compile-side effects. GPU time over frames 250-280 was 2.08 s on `main` and 2.20 s on the PR (noise; 50.9 s against 52.5 s over the whole run). `main`: ```json {"commit":"aaccd0ba39b7","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":16996.075},"presents":30,"frame_ms":{"p50":308.640,"p90":1276.579,"p99":1890.406,"max":1890.406},"gpu_busy_ms_per_present":111.751,"worker_busy_pct":{"queue worker 0x0":75.642,"queue worker 0x52":1.078,"queue worker 0x53":0.000,"queue worker 0x20":27.602,"queue worker 0x30":62.036,"queue worker 0x38":59.136,"queue worker 0x48":24.100},"top_phases_ms_per_frame":{"Driver.Packet":1410.773,"Driver.Packet.memory_wait":757.111,"Driver.Packet.dispatch":422.516,"Driver.Dispatch":407.334,"GpuMutex.wait.other":160.332,"Vulkan.Dispatch":144.609,"Vulkan.Dispatch.shader_resources":130.486,"Driver.Packet.prepare_memory":110.346},"trace_dropped":false,"trace":"aps5-trace-aaccd0ba39b7-2756.json.gz"} ``` This PR: ```json {"commit":"659d07bbc8c0","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":13989.698},"presents":30,"frame_ms":{"p50":263.902,"p90":1098.961,"p99":1768.352,"max":1768.352},"gpu_busy_ms_per_present":102.834,"worker_busy_pct":{"queue worker 0x0":83.139,"queue worker 0x52":0.717,"queue worker 0x53":0.000,"queue worker 0x20":26.429,"queue worker 0x30":69.186,"queue worker 0x38":66.501,"queue worker 0x48":26.299},"top_phases_ms_per_frame":{"Driver.Packet":1266.947,"Driver.Packet.memory_wait":702.545,"Driver.Packet.dispatch":377.420,"Driver.Dispatch":362.764,"Vulkan.Dispatch":132.113,"Vulkan.Dispatch.shader_resources":119.352,"GpuMutex.wait.other":110.325,"Driver.Packet.prepare_memory":87.509},"trace_dropped":false,"trace":"aps5-trace-659d07bbc8c0-15012.json.gz"} ``` | pair | `main` (window, frame, GPU per present) | this PR | |---|---|---| | 1 | 14.5 s, p50 283 / p99 1604 ms, GPU 102.2 ms | 16.5 s, p50 349 / p99 2658 ms, GPU 113.9 ms | | 2 | 16.5 s, p50 346 / p99 1939 ms, GPU 100.2 ms | 15.9 s, p50 264 / p99 2134 ms, GPU 110.0 ms | | 3 | 17.0 s, p50 309 / p99 1890 ms, GPU 111.8 ms | 14.0 s, p50 264 / p99 1768 ms, GPU 102.8 ms | The spread between runs of the same build (14.5-17.0 s) is larger than any difference between the two; no frame cost from the device-memory scratch shows in this scene. `APS5_NO_SNAPSHOT_CHECK` reads `1APS5_SPANNED_WAVE=1` because of a missing comma in my launcher, so `APS5_SPANNED_WAVE` is off in all six runs, as on `main` by default. <details><summary>trace_digest, `main` (last pair)</summary> **frames 250:30** from present 250: 30 presents, frame p50 308.6 / p90 1276.6 / p99 1890.4 / max 1890.4 ms, GPU busy 111.8 ms per present NVIDIA GeForce RTX 4090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit aaccd0ba39b7, dropped: no ```json {"commit":"aaccd0ba39b7","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":16996.075},"presents":30,"frame_ms":{"p50":308.64,"p90":1276.579,"p99":1890.406,"max":1890.406},"gpu_busy_ms_per_present":111.751,"worker_busy_pct":{"queue worker 0x0":75.642,"queue worker 0x52":1.078,"queue worker 0x53":0.0,"queue worker 0x20":27.602,"queue worker 0x30":62.036,"queue worker 0x38":59.136,"queue worker 0x48":24.1},"top_phases_ms_per_frame":{"Driver.Packet":1410.773,"Driver.Packet.memory_wait":757.111,"Driver.Packet.dispatch":422.516,"Driver.Dispatch":407.334,"GpuMutex.wait.other":160.332,"Vulkan.Dispatch":144.609,"Vulkan.Dispatch.shader_resources":130.486,"Driver.Packet.prepare_memory":110.346},"trace_dropped":false,"trace":"aps5-trace-aaccd0ba39b7-2756.json.gz"} ``` **Slowest frames** (largest slices inside each, inclusive) - present 273: 1890.4 ms at 8317 ms: Driver.WorkerWait (queue worker 0x20) 1812.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1812.0, Driver.WorkerWait (queue worker 0x48) 1469.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1469.0 - present 277: 1312.8 ms at 13271 ms: Driver.WorkerWait (queue worker 0x48) 1114.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1114.1, Driver.WorkerWait (queue worker 0x20) 788.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 788.8 - present 275: 1276.6 ms at 10986 ms: Driver.WorkerWait (queue worker 0x48) 905.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 905.0, Driver.Packet (queue worker 0x0) 744.6, Driver.Packet (queue worker 0x30) 711.7 - present 279: 1215.3 ms at 15781 ms: GpuMutex.wait.other (title) 750.5, Driver.Packet (queue worker 0x0) 607.9, Driver.WorkerWait (queue worker 0x0) 605.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 605.0 - present 278: 1196.5 ms at 14584 ms: Driver.WorkerWait (queue worker 0x20) 1171.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1171.1, Driver.WorkerWait (queue worker 0x48) 1022.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1022.8 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | title | 8.6 (2 %) | 160.0 (28 %) | 397.9 | 0.5 | Shader.Register 6.8, Shader.ResolveAbi 1.8 | | shader prepare | 3.5 (1 %) | 0.0 (0 %) | 563.0 | 0.0 | Shader.PrepareArtifact 3.5 | | shader prepare | 3.3 (1 %) | 0.0 (0 %) | 563.2 | 0.0 | Shader.PrepareArtifact 3.3 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 563.1 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.7 (1 %) | 0.0 (0 %) | 562.9 | 0.0 | Shader.PrepareArtifact 3.7 | | shader prepare | 3.2 (1 %) | 0.0 (0 %) | 563.3 | 0.0 | Shader.PrepareArtifact 3.2 | | shader prepare | 3.6 (1 %) | 0.0 (0 %) | 562.9 | 0.0 | Shader.PrepareArtifact 3.6 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 563.2 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 563.1 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 563.2 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.5 (1 %) | 0.0 (0 %) | 563.1 | 0.0 | Shader.PrepareArtifact 3.5 | | shader prepare | 3.1 (1 %) | 0.0 (0 %) | 563.4 | 0.0 | Shader.PrepareArtifact 3.1 | | shader prepare | 3.8 (1 %) | 0.0 (0 %) | 562.7 | 0.0 | Shader.PrepareArtifact 3.8 | | shader prepare | 3.3 (1 %) | 0.0 (0 %) | 563.3 | 0.0 | Shader.PrepareArtifact 3.3 | | shader prepare | 3.9 (1 %) | 0.0 (0 %) | 562.7 | 0.0 | Shader.PrepareArtifact 3.9 | | shader prepare | 3.6 (1 %) | 0.0 (0 %) | 562.9 | 0.0 | Shader.PrepareArtifact 3.6 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 563.1 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 11.1 (2 %) | 0.0 (0 %) | 555.4 | 0.0 | Vulkan.ComputePipeline 10.4, Vulkan.GraphicsPipelinePrebuild 0.7 | | shader prepare | 9.4 (2 %) | 0.0 (0 %) | 557.1 | 0.0 | Vulkan.ComputePipeline 8.6, Vulkan.GraphicsPipelinePrebuild 0.8 | | queue worker 0x0 | 312.0 (55 %) | 251.3 (44 %) | 3.3 | 13.7 | Driver.Packet 426.0, Driver.Completion 0.0 | | queue worker 0x52 | 1.6 (0 %) | 174.2 (31 %) | 390.7 | 0.1 | Driver.Packet 5.7, Driver.EndSubmission 0.4 | | queue worker 0x20 | 13.8 (2 %) | 532.2 (94 %) | 20.5 | 0.2 | Driver.Packet 155.8, Driver.EndSubmission 0.5 | | title | 1.9 (0 %) | 0.0 (0 %) | 564.6 | 0.0 | Shader.ResolveAbi 1.9, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 1.6 (0 %) | 0.0 (0 %) | 564.9 | 0.0 | Shader.ResolveAbi 1.5, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 0.3 (0 %) | 0.0 (0 %) | 566.2 | 0.0 | Shader.ResolveAbi 0.3, Shader.ResolveGraphicsStagesAbi 0.0 | | queue worker 0x30 | 23.5 (4 %) | 538.4 (95 %) | 4.6 | 0.8 | Driver.Packet 351.1, Driver.EndSubmission 0.3 | | queue worker 0x38 | 120.2 (21 %) | 440.0 (78 %) | 6.3 | 4.6 | Driver.Packet 333.6, Driver.EndSubmission 0.7 | | queue worker 0x48 | 37.7 (7 %) | 516.1 (91 %) | 12.8 | 1.7 | Driver.Packet 135.1, Driver.EndSubmission 1.3 | | draw committer | 87.8 (15 %) | 27.5 (5 %) | 451.2 | 0.8 | Graphics.Draw 90.2, Recorder.Sync 1.7 | | presenter | 6.1 (1 %) | 0.0 (0 %) | 560.4 | 0.1 | VideoOut.Flip 5.9, Driver.Present 0.2 | | title | 0.9 (0 %) | 0.0 (0 %) | 565.6 | 0.0 | Shader.ResolveAbi 0.9, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.5 (0 %) | 0.0 (0 %) | 565.0 | 0.0 | Shader.ResolveAbi 1.4, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 3.8 (1 %) | 0.0 (0 %) | 562.8 | 0.0 | Shader.ResolveAbi 3.7, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 1.4 (0 %) | 0.0 (0 %) | 565.1 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.1 | | title | 1.4 (0 %) | 0.0 (0 %) | 565.2 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 0.1 (0 %) | 0.0 (0 %) | 566.4 | 0.0 | Shader.ResolveAbi 0.1, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.3 (0 %) | 0.0 (0 %) | 565.2 | 0.0 | Shader.ResolveAbi 1.2, Shader.ResolveGraphicsStagesAbi 0.0 | | gpu | 112.1 (20 %) | 0.0 (0 %) | 454.5 | 0.0 | batch 112.1 | **Largest slices** (ms per frame, inclusive, all threads): Driver.WorkerWait 1550.5, Driver.WorkerWait.idle_and_completion_poll 1550.5, Driver.Packet 1407.2, Driver.Packet.memory_wait 757.1, Driver.Packet.dispatch 421.3, Driver.Dispatch 405.4, GpuMutex.wait.other 160.2, Vulkan.Dispatch 143.7 **Longest waits** - Driver.WorkerWait (queue worker 0x20) 1637.3 ms at 7592 ms, present 271 - Driver.WorkerWait (queue worker 0x48) 1427.7 ms at 7878 ms, present 272 - Driver.WorkerWait (queue worker 0x20) 1281.9 ms at 13907 ms, present 277 - Driver.WorkerWait (queue worker 0x48) 1275.1 ms at 12633 ms, present 276 - Driver.WorkerWait (queue worker 0x20) 1204.3 ms at 12179 ms, present 275 - Driver.WorkerWait (queue worker 0x38) 1175.3 ms at 8130 ms, present 272 - Driver.WorkerWait (queue worker 0x20) 1158.9 ms at 15215 ms, present 278 - Driver.WorkerWait (queue worker 0x30) 1153.5 ms at 8152 ms, present 272 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 3891: 93.2 ms at 13076 ms, present 276: GPU no ranges; recorded by Recorder.Sync (queue worker 0x30) 93.6, Driver.Packet (queue worker 0x30) 23.0, Driver.Packet.dispatch (queue worker 0x30) 23.0, Driver.Dispatch (queue worker 0x30) 23.0 - batch 450: 50.0 ms at 3280 ms, present 256: GPU no ranges; recorded by Driver.Packet (queue worker 0x30) 207.8, Driver.Packet.dispatch (queue worker 0x30) 207.8, Recorder.Sync (queue worker 0x30) 50.2, Driver.Dispatch (queue worker 0x30) 45.9 - batch 3875: 40.9 ms at 12860 ms, present 276: GPU no ranges; recorded by Recorder.Sync (queue worker 0x38) 41.6, Driver.Packet (queue worker 0x38) 41.5, Driver.Packet.dispatch (queue worker 0x38) 41.5, Driver.Dispatch (queue worker 0x38) 41.5 - batch 2948: 29.0 ms at 9835 ms, present 273: GPU no ranges; recorded by Driver.Packet (queue worker 0x38) 110.7, Driver.Packet.memory_wait (queue worker 0x38) 82.6, Driver.Dispatch (queue worker 0x38) 28.1, Driver.Packet.dispatch (queue worker 0x38) 28.1 - batch 361: 28.5 ms at 2637 ms, present 255: GPU no ranges; recorded by Recorder.Sync (queue worker 0x38) 28.9, Driver.Packet (queue worker 0x38) 9.6, Driver.Packet.dispatch (queue worker 0x38) 9.6, Driver.Dispatch (queue worker 0x38) 9.6 </details> <details><summary>trace_digest, this PR (last pair)</summary> **frames 250:30** from present 250: 30 presents, frame p50 263.9 / p90 1099.0 / p99 1768.4 / max 1768.4 ms, GPU busy 102.8 ms per present NVIDIA GeForce RTX 4090, NVIDIA 617.42, Windows 10.0.26200, 3840x2160, commit 659d07bbc8c0, dropped: no ```json {"commit":"659d07bbc8c0","dirty":false,"env":{"APS5_GPU_CHECKPOINTS":"1","APS5_HOST_IMPORT_MIB":"16384","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESULT_MEMO":"1","APS5_NO_SNAPSHOT_CHECK":"1APS5_SPANNED_WAVE=1","APS5_PIPELINE_DISPATCH":"1","APS5_PREBUILD_THREADS":"2","APS5_PREPARED_SPIRV_MIB":"6144","APS5_PROFILE_DRAW":"1","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_STAGING_POOL_MIB":"2048","APS5_TRACE_FRAMES":"250:30"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"13th Gen Intel(R) Core(TM) i9-13900K","cpu_threads":32,"memory_mib":32476,"title_id":"PPSA26344","title":"Ghost of Y\u014dtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 250:30","first_present":250,"ms":13989.698},"presents":30,"frame_ms":{"p50":263.902,"p90":1098.961,"p99":1768.352,"max":1768.352},"gpu_busy_ms_per_present":102.834,"worker_busy_pct":{"queue worker 0x0":83.139,"queue worker 0x52":0.717,"queue worker 0x53":0.0,"queue worker 0x20":26.429,"queue worker 0x30":69.186,"queue worker 0x38":66.501,"queue worker 0x48":26.299},"top_phases_ms_per_frame":{"Driver.Packet":1266.947,"Driver.Packet.memory_wait":702.545,"Driver.Packet.dispatch":377.42,"Driver.Dispatch":362.764,"Vulkan.Dispatch":132.113,"Vulkan.Dispatch.shader_resources":119.352,"GpuMutex.wait.other":110.325,"Driver.Packet.prepare_memory":87.509},"trace_dropped":false,"trace":"aps5-trace-659d07bbc8c0-15012.json.gz"} ``` **Slowest frames** (largest slices inside each, inclusive) - present 274: 1768.4 ms at 7705 ms: Driver.WorkerWait (queue worker 0x20) 1676.9, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 1676.9, Driver.WorkerWait (queue worker 0x48) 1336.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 1336.1 - present 278: 1159.4 ms at 11731 ms: Driver.WorkerWait (queue worker 0x48) 971.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x48) 971.2, Driver.WorkerWait (queue worker 0x38) 696.6, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x38) 696.6 - present 279: 1099.0 ms at 12891 ms: Driver.WorkerWait (queue worker 0x20) 992.4, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 992.4, Driver.WorkerWait (queue worker 0x0) 626.3, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 626.3 - present 257: 1086.3 ms at 2263 ms: Driver.WorkerWait (queue worker 0x52) 1081.9, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x52) 1081.9, Driver.Packet (queue worker 0x0) 1081.7, Driver.WorkerWait (queue worker 0x48) 935.8 - present 277: 768.1 ms at 10963 ms: Driver.WorkerWait (queue worker 0x20) 768.1, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x20) 768.1, Driver.Packet (queue worker 0x0) 754.4, Driver.Packet (queue worker 0x30) 684.8 **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | title | 8.2 (2 %) | 110.1 (24 %) | 348.0 | 0.5 | Shader.Register 5.4, Shader.ResolveAbi 2.8 | | shader prepare | 3.3 (1 %) | 0.0 (0 %) | 463.0 | 0.0 | Shader.PrepareArtifact 3.3 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 463.0 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.8 (1 %) | 0.0 (0 %) | 462.5 | 0.0 | Shader.PrepareArtifact 3.8 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.3 (1 %) | 0.0 (0 %) | 463.0 | 0.0 | Shader.PrepareArtifact 3.3 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.0 (1 %) | 0.0 (0 %) | 463.3 | 0.0 | Shader.PrepareArtifact 3.0 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.3 (1 %) | 0.0 (0 %) | 463.0 | 0.0 | Shader.PrepareArtifact 3.3 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.2 (1 %) | 0.0 (0 %) | 463.1 | 0.0 | Shader.PrepareArtifact 3.2 | | shader prepare | 3.7 (1 %) | 0.0 (0 %) | 462.7 | 0.0 | Shader.PrepareArtifact 3.7 | | shader prepare | 3.4 (1 %) | 0.0 (0 %) | 462.9 | 0.0 | Shader.PrepareArtifact 3.4 | | shader prepare | 3.6 (1 %) | 0.0 (0 %) | 462.7 | 0.0 | Shader.PrepareArtifact 3.6 | | shader prepare | 8.0 (2 %) | 0.0 (0 %) | 458.3 | 0.0 | Vulkan.ComputePipeline 7.3, Vulkan.GraphicsPipelinePrebuild 0.8 | | shader prepare | 11.0 (2 %) | 0.0 (0 %) | 455.3 | 0.0 | Vulkan.ComputePipeline 10.3, Vulkan.GraphicsPipelinePrebuild 0.7 | | queue worker 0x0 | 276.8 (59 %) | 186.4 (40 %) | 3.2 | 13.2 | Driver.Packet 385.2, Driver.Completion 0.0 | | queue worker 0x52 | 1.4 (0 %) | 170.9 (37 %) | 294.1 | 0.1 | Driver.Packet 3.0, Driver.EndSubmission 0.3 | | queue worker 0x20 | 9.7 (2 %) | 447.0 (96 %) | 9.6 | 0.2 | Driver.Packet 123.0, Driver.EndSubmission 0.2 | | title | 0.3 (0 %) | 0.0 (0 %) | 466.1 | 0.0 | Shader.ResolveAbi 0.2, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.3 (0 %) | 0.0 (0 %) | 465.0 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.3 (0 %) | 0.0 (0 %) | 465.1 | 0.0 | Shader.ResolveAbi 1.2, Shader.ResolveGraphicsStagesAbi 0.0 | | queue worker 0x30 | 19.6 (4 %) | 444.8 (95 %) | 1.9 | 0.8 | Driver.Packet 322.3, Driver.EndSubmission 0.2 | | queue worker 0x38 | 111.6 (24 %) | 351.8 (75 %) | 3.0 | 4.6 | Driver.Packet 308.5, Driver.EndSubmission 0.9 | | queue worker 0x48 | 35.5 (8 %) | 421.7 (90 %) | 9.1 | 1.8 | Driver.Packet 121.5, Driver.EndSubmission 1.0 | | draw committer | 76.9 (16 %) | 23.1 (5 %) | 366.3 | 0.8 | Graphics.Draw 77.5, Vulkan.DrawFromRecipe 1.5 | | presenter | 6.3 (1 %) | 0.0 (0 %) | 460.0 | 0.1 | VideoOut.Flip 6.0, Driver.Present 0.2 | | title | 1.4 (0 %) | 0.0 (0 %) | 465.0 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 0.9 (0 %) | 0.0 (0 %) | 465.4 | 0.0 | Shader.ResolveAbi 0.9, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 0.8 (0 %) | 0.0 (0 %) | 465.5 | 0.0 | Shader.ResolveAbi 0.7, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.6 (0 %) | 0.0 (0 %) | 464.8 | 0.0 | Shader.ResolveAbi 1.5, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.3 (0 %) | 0.0 (0 %) | 465.0 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 2.0 (0 %) | 0.0 (0 %) | 464.3 | 0.0 | Shader.ResolveAbi 1.9, Shader.ResolveGraphicsStagesAbi 0.0 | | title | 1.3 (0 %) | 0.0 (0 %) | 465.0 | 0.0 | Shader.ResolveAbi 1.3, Shader.ResolveGraphicsStagesAbi 0.1 | | gpu | 99.8 (21 %) | 0.0 (0 %) | 366.6 | 0.0 | batch 99.8 | **Largest slices** (ms per frame, inclusive, all threads): Driver.Packet 1263.4, Driver.WorkerWait 1211.0, Driver.WorkerWait.idle_and_completion_poll 1211.0, Driver.Packet.memory_wait 702.5, Driver.Packet.dispatch 376.2, Driver.Dispatch 360.8, Vulkan.Dispatch 131.1, Vulkan.Dispatch.shader_resources 118.4 **Longest waits** - Driver.WorkerWait (queue worker 0x20) 1598.9 ms at 6995 ms, present 272 - Driver.WorkerWait (queue worker 0x48) 1420.1 ms at 7238 ms, present 273 - Driver.WorkerWait (queue worker 0x20) 1213.3 ms at 12289 ms, present 278 - Driver.WorkerWait (queue worker 0x38) 1160.9 ms at 7497 ms, present 273 - Driver.WorkerWait (queue worker 0x30) 1141.5 ms at 7516 ms, present 273 - Driver.WorkerWait (queue worker 0x52) 1122.8 ms at 2287 ms, present 257 - Driver.WorkerWait (queue worker 0x48) 1039.0 ms at 12478 ms, present 278 - Driver.WorkerWait (queue worker 0x48) 964.4 ms at 11325 ms, present 277 **Largest GPU batches** (GPU ranges inside, and the CPU slices that recorded each, inclusive) - batch 3981: 77.5 ms at 11579 ms, present 277: GPU no ranges; recorded by Recorder.Sync (queue worker 0x30) 77.8, Driver.Packet (queue worker 0x30) 21.3, Driver.Packet.dispatch (queue worker 0x30) 21.3, Driver.Dispatch (queue worker 0x30) 21.3 - batch 505: 57.1 ms at 2702 ms, present 257: GPU no ranges; recorded by Driver.Packet (queue worker 0x30) 171.0, Driver.Packet.dispatch (queue worker 0x30) 171.0, Recorder.Sync (queue worker 0x30) 57.5, Driver.Dispatch (queue worker 0x30) 45.1 - batch 581: 18.7 ms at 3680 ms, present 258: GPU no ranges; recorded by Driver.Packet (queue worker 0x38) 19.2, Driver.Packet.prepare_memory (queue worker 0x38) 19.0, Vulkan.Dispatch.shader_resources (queue worker 0x38) 0.4, Driver.Dispatch (queue worker 0x38) 0.2 - batch 648: 18.1 ms at 3945 ms, present 259: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 18.6, Driver.Packet.prepare_memory (queue worker 0x0) 18.4, Resources.Prepare (queue worker 0x0) 0.8, Recorder.Sync (queue worker 0x0) 0.3 - batch 717: 18.0 ms at 4178 ms, present 260: GPU no ranges; recorded by GpuMutex.wait.end (queue worker 0x20) 0.2, Driver.Packet (queue worker 0x20) 0.1, Driver.Packet.dispatch (queue worker 0x20) 0.1, Driver.Dispatch (queue worker 0x20) 0.1 </details> <details><summary>Downstream only (Celegans12's yotei/best plus local changes, not main): PPSA26344 all cold to frame 1200</summary> Same downstream build and environment in each row; only the scratch handling differs. Cold shader cache, NVIDIA driver cache moved aside, fresh save. | run | scratch | frame 700 | frame 1000 | frame 1200 | compile s: 0x8000173b00 / 117800 / 14e300 / 167500 | |---|---|---|---|---|---| | run570 | Function arrays (as on `main`) | 363 s | 758 s | 1,012 s | 199 / 217 / 162 / 176 | | run575 | this PR | 322 s | 664 s | 905 s | 146 / 168 / 117 / 114 | run570 also lacks one other local change (#6867), so its frame times are not a pure A/B; the compile times of the four programs are. Offline, from captures of the same programs (one compile thread, cold driver cache): 1.69M and 1.57M words compile in 100 s each with this PR, against 135-137 s for 1.45-1.52M words with the arrays. </details> ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA RTX 4090, driver 617.42, Windows 11 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CnRJay commented 2026-11-01 19:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:50:59Z.

Review: COMMENTED


The compile-time measurement is solid (141-145 s down to about 100 s on program 0x1994ed, nvoglv64 share 36% to 1.4%). My questions are about the runtime side, which the evidence does not cover.

  1. The scratch buffer is Coherent in global memory. Scratch used to be Function-scope memory the driver can keep close to the SIMD; it is now a device-scope coherent storage buffer, and every scratch_* and private-aperture FLAT access, including the four byte read-modify-writes for an unaligned 32-bit store, becomes a coherent global access. The PR says the cost of the Coherent decoration is unexplained ("looks like a driver ordering issue"). Please show the dispatch time of a scratch-heavy compute program before and after, not only compile time.
  2. The game measurement does not reach the changed path. The Ghost of Yotei window is frames 250-280 (loading), and the body says "I haven't checked which of them dispatch inside the window". The trace_digest.py pair therefore shows no runtime change by construction. Please state which of the 13 pool programs dispatch in the window, or pick a scene where they run every frame.
  3. Unbounded per-pipeline pool. "One buffer per compute pipeline at its first dispatch", capped at APS5_SCRATCH_POOL_MIB (default 64) each, never evicted. 13 pool programs by frame 350 is up to 832 MiB of VRAM held for the life of the process, per title, to save compile time. A shared pool keyed by slot size, or a pool released with the pipeline, would bound it.
  4. Slot claim spins. EmitScratchPoolAcquire runs a CompareExchange loop from linear % slots with no back-off, so when the dispatch has more resident workgroups than slots the waiting workgroups burn atomics on the same cache lines the holders are using. With 114 KB slots (56 dwords x 512 lanes) 64 MiB gives about 580 slots; what does a 4K dispatch with thousands of workgroups do? A test with slots < resident groups and a timing would answer it; agc_driver_scratch_pool isolates 64 workgroups over one or two slots for correctness only.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729927352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12764#pullrequestreview-5729927352). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:50:59Z. **Review:** COMMENTED --- The compile-time measurement is solid (141-145 s down to about 100 s on program 0x1994ed, nvoglv64 share 36% to 1.4%). My questions are about the runtime side, which the evidence does not cover. 1. **The scratch buffer is `Coherent` in global memory.** Scratch used to be Function-scope memory the driver can keep close to the SIMD; it is now a device-scope coherent storage buffer, and every `scratch_*` and private-aperture FLAT access, including the four byte read-modify-writes for an unaligned 32-bit store, becomes a coherent global access. The PR says the cost of the `Coherent` decoration is unexplained ("looks like a driver ordering issue"). Please show the dispatch time of a scratch-heavy compute program before and after, not only compile time. 2. **The game measurement does not reach the changed path.** The Ghost of Yotei window is frames 250-280 (loading), and the body says "I haven't checked which of them dispatch inside the window". The `trace_digest.py` pair therefore shows no runtime change by construction. Please state which of the 13 pool programs dispatch in the window, or pick a scene where they run every frame. 3. **Unbounded per-pipeline pool.** "One buffer per compute pipeline at its first dispatch", capped at `APS5_SCRATCH_POOL_MIB` (default 64) each, never evicted. 13 pool programs by frame 350 is up to 832 MiB of VRAM held for the life of the process, per title, to save compile time. A shared pool keyed by slot size, or a pool released with the pipeline, would bound it. 4. **Slot claim spins.** `EmitScratchPoolAcquire` runs a `CompareExchange` loop from `linear % slots` with no back-off, so when the dispatch has more resident workgroups than slots the waiting workgroups burn atomics on the same cache lines the holders are using. With 114 KB slots (56 dwords x 512 lanes) 64 MiB gives about 580 slots; what does a 4K dispatch with thousands of workgroups do? A test with `slots < resident groups` and a timing would answer it; `agc_driver_scratch_pool` isolates 64 workgroups over one or two slots for correctness only.
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!12764
No description provided.