Repository navigation
perf(agc): skip the held-read walk while no queued draw holds a read range - #10689
johandavidcm wants to merge 6 commits into
Conversation
…check DrawPipeline::HeldReads called std::getenv on every call. It runs for each StorageTexture::FlushPending, which InPlaceDrawInput calls while the draw committer records a draw. On Windows, UCRT's getenv takes the environment lock and scans the block on each call: on the title screen of Spirit of the Island (PPSA13934), 375 of the draw committer's 5124 steady-state samples (7.3 %) were in ucrtbase under HeldReads, against under 0.3 % for the range scan itself. The variable is now read once into a static, as WaitMemory.cpp already does for the same variable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…range DrawPipeline::HeldReads took the pipeline mutex and walked every queued item's read ranges on each call. StorageTexture::FlushPending asks it for every in-place draw input, so with in-place inputs the committer took that lock once per draw, against the worker's enqueues, and found a held range about once in a thousand calls. The pipeline now counts the queued items that carry read ranges. HeldReads answers false without the lock while that count is zero; the count moves under the lock where items are enqueued, retired and when the running item's reads are released, so it can only be stale towards the walk. APS5_NO_HELD_READ_PREFILTER=1 walks as before. HeldReadQueries counts the walks for the test.
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed head 156b9b11d498ca9b7f8af26e325acb572036ffca. The counter is updated while holding the same mutex that protects items; retirement and ReleaseRunningReads decrement it under that mutex. Therefore a zero observed by the lock-free prefilter cannot hide a queued read range, while a positive observation falls back to the existing locked range scan. The focused test covers the empty, overlapping, disjoint, and drained cases, and the report includes paired Windows validation-layer and title measurements. Local AGC execution is unavailable on this host because the CPU feature gate aborts before the tests; I have not counted those tests as locally passing. Hosted intake, conventions, and labels checks pass; product build jobs were skipped by policy.
|
@johandavidcm Please make HeldReadsPrefilter.cpp clean up its parked commit on every exit. The lambda captures Parked by reference, but a failed Require before Release destroys that local while the commit can still read parked.release for up to ten seconds; the missing-prefilter negative control takes this path. Keep the state alive until the commit ends, release and drain it during exception cleanup, and exercise a planted assertion failure and a startup timeout with bounded cleanup. |
|
I read head Two test gaps, separate from Dean's point about the parked commit:
AI-assisted: yes (Claude Code) |
|
Linux run of this head
Edited: the first version of this comment reported 23 failures and called them lavapipe-only AGC tests that also fail on AI-assisted: yes (Claude Code) |
…ort the walks HeldReadQueries counts every query, as main's QueuedIndexReadOrder test expects since boykopovar#8911; behind the prefilter it missed the queries the prefilter answered. HeldReadWalks counts the locked walks, and the [draw] pipelined line prints both per report.
… every exit The commit owns its state through a shared pointer and a guard releases and drains it during unwinding, so a failed check no longer leaves a commit reading a destroyed local. The test also checks that queries are counted ahead of the prefilter, that the walk stops after the holding item retires and after ReleaseRunningReads, and that a planted failure and a startup timeout both clean up within a bound.
|
Head is now @oneandonlydean, done in @thuanquang, both points, in
Mutations, each rebuilt and run on its own, the test restored in between:
@babyhuey, thank you for the Linux run. Overlap bot: #9898 and #10677 touch neighbouring lines of A correction to the description's measurements, which I am redoing: the four pairs compared a base that carried the port of #6192 ( AI-assisted: yes |
|
@johandavidcm the shared ownership, cleanup guard and query/walk checks address my source asks. I still need the performance comparison corrected before carrying its result. Your proposed new baseline is main plus #8098, while the candidate also adds #9490; main 9f386f3 still does the per-call getenv that #9490 removes. Please include the same #9490 change in both arms, or compare this head with and without APS5_NO_HELD_READ_PREFILTER=1, so the game pair isolates the prefilter. Keep the other code and settings matched, replace the withdrawn table in the description, and distinguish queries, queue walks and the cumulative enqueued-range count. The 2.2% figure from the old pair cannot carry. |
|
@oneandonlydean, re-measured as you asked, with this head on both arms: one build ( The prefilter no longer does anything measurable in this title, because #8911 already removed the calls it targeted. The
On Frame pairs, p50 and presents in 60 s, off then on: 197.6 / 195.8 ms (303 / 305), 212.9 / 207.6 (280 / 288), 209.1 / 201.8 (285 / 296), 209.8 / 200.5 (284 / 298). All four favour the prefilter by 0.9-4.4 %, but So the cost that motivated this PR is gone on AI-assisted: yes |
|
Closing: #8911 removed the calls this prefilter was for, and the same-binary pairs above show no measurable change left in the title. Thank you for the reviews; the parked-commit cleanup carries over to the next test that parks a commit. |
What
DrawPipeline::HeldReadstook the draw pipeline's mutex and walked every queued item's read ranges on each call.StorageTexture::FlushPendingasks it once for every in-place draw input (InPlaceDrawInput,Draw.cpp:1215), so with in-place inputs the draw committer took that lock on every draw, against the worker'sEnqueue, and found a held range about once in a thousand calls.In Yakuza 0 Director's Cut (PPSA31327) with
APS5_DRAW_INPUTS_IN_PLACE=1andAPS5_DRAW_PIPELINE=1, a gameplay-only sample of the committer putHeldReadsat 9.3 % of its time, 8.2 % of it waiting for that mutex; the[draw] pipelinedline showed counted about 360 thousand held reads found per 10 s.itemsWithReads).HeldReadsanswersfalsewithout the lock while the count is zero.ReleaseRunningReadsclears the running item's ranges, so it can only be stale towards the walk: a reader that sees a non-zero count takes the lock and walks as before.APS5_NO_HELD_READ_PREFILTER=1walks on every call as before.docs/dev/ENVIRONMENT.mdgets the row.DrawPipeline::HeldReadQueriesexposes the existing walk counter for the test.Depends on #9490, which caches the
APS5_NO_QUEUED_DRAW_READ_ORDERlookup in the same function; this branch has it merged, and the diff above it is the change here.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, onmain6cd36e6 + #9490 (head 156b9b1).New test
agc_driver_held_reads_prefilter(tests/execution/HeldReadsPrefilter.cpp): parks a commit on the committer and checks, through the public API, that a queue holding no read ranges reports nothing and does not take the lock (HeldReadQueriesstays flat), that a queued range is reported for an overlapping query and not for a disjoint one, and that a drained queue reports nothing.return falseline replaced by a no-op) it fails witha query against a queue holding no read ranges took the pipeline lock.--repeat until-fail:20.Pass with the change:
agc_driver_queued_index_read_order,agc_driver_vertex_table_read_order,agc_driver_draw_pipeline_trace,agc_driver_draw_pipeline_trace_disabled,agc_driver_draw_finisher_trace,agc_driver_draw_finisher_trace_disabled.With
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0; the loader log shows the layer inserted),ctest -R <those tests> -Vpasses onmain'sDrawPipeline.cppand with this change, and neither log has aVUID-line or a missing-layer message.PPSA31327 01.015.000, gameplay in Kamurocho, character standing still, 1920x1080, warm caches, scripted boot through the first dialogue (
APS5_PAD_INPUT_FILE,APS5_NO_PAD_INPUT=1),APS5_TRACE_SECONDS=140:60, both builds withAPS5_DRAW_PIPELINE=1 APS5_DRAW_INPUTS_IN_PLACE=1, runs alternated.main6cd36e6 + fix(audioout2): keep each port's grain when ports share a buffer #8098 (the title's audio) + the port of perf(agc): fast revalidation over untracked memory proves a surface by its stamp until the next ordering point #6192. Change: the same plus this commit.The frame moves less than the committer because the worker, which waits on the committer for room, takes part of the slack. The committer-side counters (
APS5_PROFILE_DRAW, medians of the last gameplay intervals of 10 s, one profile run of each build):[draw] pipelined)vertexphase of[draws](holdsInPlaceDrawInput→FlushPending→HeldReads)GPU busy per present is unchanged (72-77 ms both ways). The counters are the mechanism; the title's frame is the result.
Summary lines (pair 3: base, then this change)
{"commit":"5f4ff174e827","dirty":false,"env":{"APS5_DRAW_INPUTS_IN_PLACE":"1","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"140:60"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31892,"title_id":"PPSA31327","title":"Yakuza 0 Director's Cut","content_version":"01.015.000","resolution":"1920x1080","window":{"spec":"seconds 140:60","first_present":3007,"ms":60060.227},"presents":260,"frame_ms":{"p50":228.977,"p90":238.270,"p99":272.747,"max":328.078},"gpu_busy_ms_per_present":77.251,"worker_busy_pct":{"queue worker 0x0":98.180},"top_phases_ms_per_frame":{"Driver.Packet":226.715,"Graphics.Draw":196.089,"Driver.Packet.draw":193.767,"Driver.Draw":192.199,"Driver.DrawFinish":166.756,"Driver.Draw.prepare":158.977,"Graphics.Draw.draw_and_resource_release":150.126,"Driver.DrawFinish.shader_compile_and_link":116.339},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.163,"events_lost":3542234,"totals_full":false},"draw finisher":{"events_full_after_s":8.160,"events_lost":1698727,"totals_full":false},"draw committer":{"events_full_after_s":12.636,"events_lost":991325,"totals_full":false}},"trace":"aps5-trace-5f4ff174e827-84060.json.gz"}{"commit":"156b9b11d498","dirty":false,"env":{"APS5_DRAW_INPUTS_IN_PLACE":"1","APS5_DRAW_PIPELINE":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"140:60"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 621.01","os":"Windows 10.0.26200","cpu":"AMD Ryzen 7 7800X3D 8-Core Processor","cpu_threads":16,"memory_mib":31892,"title_id":"PPSA31327","title":"Yakuza 0 Director's Cut","content_version":"01.015.000","resolution":"1920x1080","window":{"spec":"seconds 140:60","first_present":3026,"ms":60063.155},"presents":273,"frame_ms":{"p50":219.289,"p90":226.611,"p99":235.173,"max":327.792},"gpu_busy_ms_per_present":76.967,"worker_busy_pct":{"queue worker 0x0":98.113},"top_phases_ms_per_frame":{"Driver.Packet":215.791,"Driver.Packet.draw":183.004,"Driver.Draw":181.571,"Graphics.Draw":177.628,"Driver.DrawFinish":156.106,"Driver.Draw.prepare":149.026,"Graphics.Draw.draw_and_resource_release":146.527,"Driver.DrawFinish.shader_compile_and_link":114.131},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.211,"events_lost":3487719,"totals_full":false},"draw finisher":{"events_full_after_s":8.266,"events_lost":1672678,"totals_full":false},"draw committer":{"events_full_after_s":13.393,"events_lost":919577,"totals_full":false}},"trace":"aps5-trace-156b9b11d498-93240.json.gz"}tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)