Repository navigation
perf(agc): prebuild compute pipelines and prewarm dispatch shaders ahead of execution - #8735
Conversation
7d0176f to
9e47ecc
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Review note on the new dispatch look-ahead: in the first scan loop, the / branch reads to derive without validating that the packet has at least five DWORDs. allows shorter packets and this loop only checks that the declared count fits in the submission, so malformed/truncated dispatch packets can cause an out-of-bounds span access before normal validation runs. Could you gate the preview path on the opcode-specific minimum packet length (and skip/fall back safely when it is shorter)?
MarcZX10
left a comment
There was a problem hiding this comment.
Review note on the new dispatch look-ahead: in the first scan loop, the 0x15/0x16 branch reads packet[4] to derive wave without validating that the packet has at least five DWORDs. PacketWords(header) allows shorter packets and this loop only checks that the declared count fits in the submission, so malformed/truncated dispatch packets can cause an out-of-bounds span access before normal dispatch validation runs. Could you gate the preview path on the opcode-specific minimum packet length (and skip/fall back safely when it is shorter)?
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
9e47ecc to
6aab4ed
Compare
…rom packet.back()
|
Addressed the review note in
Line-by-line
|
|
@hamb3r thanks for the length gating; both scan loops look right to us now. Before this goes further, a few things change behaviour in the default configuration and aren't in the description:
|
|
@oneandonlydean Thanks for the thorough review! Addressed all four items in 1.
|
|
@hamb3r thanks, One default change is still in: the |
|
@oneandonlydean Restored the default Why
|
Metric (frames 0:5, cold pipeline cache) |
main (ca74ef2177ee) |
1 thread without !cached (839cabd6c7ba) |
1 thread default + !cached (0070aeafce7d) |
APS5_PREBUILD_THREADS=8 (320a4b6a1946) |
|---|---|---|---|---|
Driver.Dispatch (ms/frame) |
1736.797 |
1753.363 (+0.95%) |
1533.562 (-203.235 ms, -11.70%) |
1514.524 (-222.273 ms, -12.80%) |
Driver.Dispatch.materialize (ms/frame) |
581.184 |
561.787 (-3.34%) |
542.662 (-38.522 ms, -6.63%) |
601.088 (+3.42%) |
GpuMutex.wait.dispatch (ms/frame) |
336.444 (max 1211.4 ms) |
314.950 (max 1227.3 ms) |
out of top phases & top 10 waits | out of top phases & top 10 waits |
Updated the PR description with the full tools/trace_digest.py summaries for both the default 1-thread configuration (0070aeafce7d) and APS5_PREBUILD_THREADS=8 (320a4b6a1946).
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the fixes to the earlier notes. Remaining points:
- The default configuration doesn't show a gain in your own traces. With the default 1-thread pool (
0070aeafce7d), warm cache vsmain:Driver.Dispatch1258 → 1574 ms/frame,Driver.Packet8075 → 8941 ms/frame,frame_ms.p905066 → 5574 ms; cold:frame_ms.max6360 → 6804 ms. The warm improvements in the description are fromAPS5_PREBUILD_THREADS=8, which is not the default. Please either show repeated runs (medians, same scene) where the default build is better, or scope the claim to what is measured. A single 5-frame window dominated by the first-frame stall (4.9 smemory_wait) is too noisy to separate a 10 % change. DispatchAhead.cpp:150-194,:195-202andDispatch.cpp:419: newcatch (...) {}blocks swallow every exception, including emulator invariants (mainhas none inDispatchAhead.cpp). Catch the specific exceptions the preview/prebuild can legitimately throw, or let the rest propagate.docs/dev/ARCHITECTURE.md: the new compute prebuild on the library prebuild pool and the dispatch look-ahead that prioritizes/prepares registrations change the pipeline description; please add it next to thePrebuildStageLibraryparagraph.tests/execution/PreparedShaders.cpp:1447-1448:DispatchAheadPrewarm()is hooked into the--registered-workgroupmode anddeviceis reset there; please give it its own mode/test entry instead of piggybacking on an unrelated one.
|
@adriadam10 Addressed all four review points in
|
6315714 to
cb29f63
Compare
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the scoping and the length gating; the correctness points from MarcZX10 and oneandonlydean are resolved on cb29f63d43, and the merge with current main is clean.
Requesting changes on the performance claim:
- In the default configuration, your own warm-cache traces are worse than
main:Driver.Dispatch1258.0 → 1574.6 ms/frame,Driver.Packet8075 → 8941 ms/frame,frame_ms.p905066.4 → 5574.6 ms (aps5-trace-ca74ef2177ee-42280.json.gzvsaps5-trace-0070aeafce7d-42312.json.gz). - The only improvement shown in the default configuration is one cold 5-frame run (
Driver.Dispatch1736.8 → 1533.6 ms/frame), with no repetitions.
Please provide at least 3 runs per side (main and this branch, same machine, same scene, default environment), with medians for cold and warm cache. If warm stays slower in the default configuration, either make the prebuild and group-ahead preview opt-in or drop the default-on claim from the description.
|
@adriadam10 Good catch on In
We re-ran 3 cold-pipeline-cache + 3 warm-cache 20-frame traces ( Summary of 3-run medians (
|
|
Re-checked |
…ound program AwaitReferencedPreparations waited on a bound snapshot's settled condition whenever it was pending. A preparation marked pending with no pool task (as agc_driver_prepared_shaders_dispatch_ahead_prewarm does since boykopovar#8735) is never settled by anyone, so the submission hung. The pool now records which preparation owns each queued or running task; the submit wait moves that task to the front and waits for it to finish, as main's wait does for every queued task, and does not wait for a preparation the pool does not hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ound program AwaitReferencedPreparations waited on a bound snapshot's settled condition whenever it was pending. A preparation marked pending with no pool task (as agc_driver_prepared_shaders_dispatch_ahead_prewarm does since boykopovar#8735) is never settled by anyone, so the submission hung. The pool now records which preparation owns each queued or running task; the submit wait moves that task to the front and waits for it to finish, as main's wait does for every queued task, and does not wait for a preparation the pool does not hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
ShaderManager::QueuePrebuildandPrebuildEntrywith acomputeflag so compute shaders queued byGetPreparedShaders(..., /*compute=*/true)pre-create both thevk::ShaderModuleand the computevk::Pipelineon the background shader prepare thread (GetOrCreateComputePipeline), avoiding synchronous pipeline compilation stalls duringDriver::dispatch.Driver::resolveGroupAheadby scanning the upcoming packet segment up to the next wait/sync boundary (PreviewedUntil()) when the segment contains at least one subsequent dispatch (hasFurtherDispatch), trackingSetShReg/SetContextRegupdates on a lightweight preview state and callingRegisteredProgram(GetPreparedShaders(..., true)) for upcoming dispatches (scan > from) before the preceding dispatches finish executing. Single-dispatch segments (!hasFurtherDispatch) skip the preview pass with zero state copies or lookups.Tested
ctest --test-dir build-portable -R "^(agc_driver_prepared_shaders_compute_prebuild|agc_driver_prepared_shaders_dispatch_ahead_prewarm|agc_driver_compute_basic_dispatch|agc_driver_compute_multi_dispatch)$" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon bothmain(522e32e3b618) and this branch (dcb04d0aa14d) — all 4 tests pass with 0VUID-validation errors.PPSA01341v1.07), Windows 11, same machine and boot/intro scene (APS5_TRACE_FRAMES=0:20, default flags, 3 cold-pipeline-cache runs + 3 warm-cache runs per branch). All 12.json.gztraces are attached below.Attached Traces (12 runs: 3 Cold + 3 Warm per branch)
main(522e32e3b618) Cold 1..3:window.ms=7911.797,p50=71.790,p90=899.812,max=5652.293,Driver.Packet=2711.103,Packet.dispatch=471.154,Driver.Dispatch=438.601,materialize=121.787)window.ms=8543.938,p50=69.237,p90=893.505,max=5998.794,Driver.Packet=2855.925,Packet.dispatch=562.523,Driver.Dispatch=473.093,materialize=127.010)window.ms=8480.218,p50=85.598,p90=1030.123,max=6032.006,Driver.Packet=2950.152,Packet.dispatch=497.480,Driver.Dispatch=460.815,materialize=127.731)perf/agc-compute-prewarm(dcb04d0aa14d) Cold 1..3:window.ms=8765.408,p50=85.279,p90=568.491,max=6661.114,Driver.Packet=3035.776,Packet.dispatch=512.372,Driver.Dispatch=482.331,materialize=130.607)window.ms=8992.743,p50=85.367,p90=584.385,max=6463.900,Driver.Packet=3064.032,Packet.dispatch=549.805,Driver.Dispatch=515.185,materialize=128.516)window.ms=8145.822,p50=81.976,p90=163.222,max=6580.297,Driver.Packet=3031.801,Packet.dispatch=543.130,Driver.Dispatch=452.018,materialize=127.940)main(522e32e3b618) Warm 1..3:window.ms=6870.411,p50=78.791,p90=799.413,max=4727.829,Driver.Packet=2287.577,Packet.dispatch=416.237,Driver.Dispatch=383.796,materialize=124.635)window.ms=6792.077,p50=75.507,p90=800.919,max=4787.418,Driver.Packet=2293.844,Packet.dispatch=408.587,Driver.Dispatch=373.319,materialize=124.379)window.ms=6612.875,p50=70.261,p90=755.799,max=4599.907,Driver.Packet=2234.188,Packet.dispatch=424.879,Driver.Dispatch=388.964,materialize=120.988)perf/agc-compute-prewarm(dcb04d0aa14d) Warm 1..3:window.ms=6863.060,p50=68.699,p90=447.956,max=4802.256,Driver.Packet=2303.209,Packet.dispatch=484.234,Driver.Dispatch=439.233,materialize=120.444)window.ms=6862.217,p50=85.842,p90=778.916,max=4746.500,Driver.Packet=2333.684,Packet.dispatch=420.290,Driver.Dispatch=388.508,materialize=122.702)window.ms=6639.422,p50=71.507,p90=503.585,max=4767.308,Driver.Packet=2218.187,Packet.dispatch=425.453,Driver.Dispatch=391.083,materialize=109.963)3-Run Median Comparison (
APS5_TRACE_FRAMES=0:20, default flags)mainCold MedianmainWarm Medianwindow.ms8480.2188765.408+3.4%6792.0776862.217+1.0%frame_ms.p5071.79085.279+18.8%75.50771.507-5.3%frame_ms.p90899.812568.491-36.8%799.413503.585-37.0%frame_ms.max5998.7946580.297+9.7%4727.8294767.308+0.8%Driver.Packet(ms/f)2855.9253035.776+6.3%2287.5772303.209+0.7%Driver.Packet.dispatch(ms/f)497.480543.130+9.2%416.237425.453+2.2%Driver.Dispatch(ms/f)460.815482.331+4.7%383.796391.083+1.9%Driver.Dispatch.materialize(ms/f)127.010128.516+1.2%124.379120.444-3.2%0x20..0x50) syncVulkan.ComputePipelinecount301-96.7%000shader prepareprebuiltVulkan.ComputePipelinecount029+29000tools/trace_digest.py— Cold Median Run (mainaps5-trace-522e32e3b618-20240.json.gzvs PRaps5-trace-dcb04d0aa14d-31308.json.gz)maincold median digest (aps5-trace-522e32e3b618-20240.json.gz)Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 2947.5, Driver.Packet.memory_wait 2432.4, Driver.Packet.dispatch 496.8, Driver.Dispatch 459.8, Driver.WorkerWait 323.4, Driver.WorkerWait.idle_and_completion_poll 323.3, Driver.Dispatch.materialize 126.7, Vulkan.Dispatch 117.1, Vulkan.Dispatch.shader_resources 112.9, Shader.PrepareArtifact 96.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 3033.1, Driver.Packet.memory_wait 2496.9, Driver.Packet.dispatch 511.7, Driver.Dispatch 481.3, Driver.WorkerWait 324.5, Driver.WorkerWait.idle_and_completion_poll 324.4, Driver.Dispatch.materialize 129.6, Vulkan.Dispatch 115.1, Vulkan.Dispatch.shader_resources 110.4, Vulkan.ComputePipeline 72.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 2291.3, Driver.Packet.memory_wait 1870.7, Driver.Packet.dispatch 408.0, Driver.Dispatch 372.3, Driver.WorkerWait 324.1, Driver.WorkerWait.idle_and_completion_poll 324.0, Driver.Dispatch.materialize 123.4, Vulkan.Dispatch 120.0, Vulkan.Dispatch.shader_resources 116.2, Shader.PrepareArtifact 100.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 2215.5, Driver.Packet.memory_wait 1763.5, Driver.Packet.dispatch 424.7, Driver.Dispatch 390.0, Driver.WorkerWait 340.0, Driver.WorkerWait.idle_and_completion_poll 340.0, Vulkan.Dispatch 117.3, Vulkan.Dispatch.shader_resources 113.0, Driver.Dispatch.materialize 109.0, Resources.Prepare 83.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)