Repository navigation
perf(agc): move per-draw thread-locals to TEB slots - #6615
Conversation
|
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.
|
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
ed20b75 to
2f4643e
Compare
|
Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
Within the run-to-run spread (about ±1.5 % here), no regression, 0 fatal. AI-assisted: yes (Claude Code) |
|
Evidence from Stellar Blade on Windows (MinGW build): this stack gives about +7% presents in gameplay over two pairs. What was measured. This PR's stack (#6615 including #6292; #6522 was already in our tree) ported onto a downstream perf branch: origin/main 4ffb0cd plus local AGC performance changes. The port keeps the PR's mechanism (atomic mutexes, explicit GPU-lock recursion, TEB slots) adapted to our tree. Base is the same tree without the port. It is not a clean main-vs-PR comparison.
Before the port, a queue-0 sample profile of steady gameplay had about 4.9% of queue-0 time in winpthreads lock and TLS calls (
Traces and summary files are available on request. trace_digest, run 1 (base)1912 frames over 149995.1 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 134.8, Driver.Packet.memory_wait 65.6, batch 35.4, Driver.Packet.dispatch 30.0, Graphics.Draw 27.7, Driver.Commit.draw 27.6, GpuMutex.hold.draw 27.3, Graphics.Draw.draw_and_resource_release 23.4, Driver.Dispatch 20.9, Driver.Packet.draw 15.6 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest, run 2 (port)2103 frames over 149914.4 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 123.2, Driver.Packet.memory_wait 59.8, batch 33.3, Driver.Packet.dispatch 26.8, Graphics.Draw 24.4, Driver.Commit.draw 24.3, GpuMutex.hold.draw 24.1, Graphics.Draw.draw_and_resource_release 20.8, Driver.Dispatch 18.2, Driver.Packet.draw 14.6 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest, run 3 (base)1888 frames over 149975.6 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 136.7, Driver.Packet.memory_wait 66.7, batch 35.6, Driver.Packet.dispatch 30.7, Graphics.Draw 27.2, Driver.Commit.draw 27.2, GpuMutex.hold.draw 26.9, Graphics.Draw.draw_and_resource_release 23.5, Driver.Dispatch 21.6, Driver.Packet.draw 15.2 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest, run 4 (port)2059 frames over 149945.3 ms (no summary line found) Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 124.8, Driver.Packet.memory_wait 60.8, batch 35.0, Driver.Packet.dispatch 26.6, Graphics.Draw 25.9, Driver.Commit.draw 25.8, GpuMutex.hold.draw 25.6, Graphics.Draw.draw_and_resource_release 22.1, Driver.Dispatch 17.9, Driver.Packet.draw 14.8 Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
|
Ports boykopovar#6292 and boykopovar#6615 (boykopovar#6522 is already present). Draw-path mutexes and the GPU-lock gate become atomic locks with explicit recursion, and per-draw thread-locals move to native TLS slots (TEB slots on Windows) instead of emutls. The same conversion also covers the newer sb5 paths: guest allocation registry, trace thread binding, own-stack checks, collect counters, recorder sync attribution, held-read scratch, packet profile, draw keys, supplied shader-memory blocks and the changed-block scratch. There is no runtime switch; compare builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2f4643e to
8310d3d
Compare
|
This pull request is labeled |
|
Two notes from GTA V (PPSA04264) on Windows (RTX 4090, i9-13900K, GCC 15.2). Numbers are from our older POC base (gtav-next11, Oct 16).
We measured with AI-assisted: yes (Claude Code) |
93ae204 to
21a8583
Compare
|
@Meh7an #7919 was merged into #7919 moves the When you rebase, could you:
Git will not flag the header, so taking either side of the conflict alone builds fine, but it leaves the snapshot cache on After the push CI runs again on the new head, and I will do a short delta review. |
21a8583 to
07bb9f6
Compare
|
@oneandonlydean Thanks, done as you suggested. Both PRs are rebased onto main 72fe76f:
|
|
Windows / AMD data from ASTRO BOT's Crash Site hub, with the APS5 samplers on the queue 0 worker and on the draw committer. On this title the change makes no measurable difference, because its thread-local accesses are spread over call sites this PR does not touch.
AI-assisted: yes (Claude Code). The runs were made on my machine. |
❌ NVIDIA GPU test: build failedPR head
build: first errorsReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
should-fix Findings
Freshness Envelope
|
jotitadev
left a comment
There was a problem hiding this comment.
On the NVIDIA CI build failure at 07bb9f628 ('refreshing' was not declared in this scope, Texture.cpp): this is a merge skew with #8911, not a toolchain issue.
#8911 (68f51b5a0b, merged 25/10, after this head) added a new reader of the old thread_local refreshing in the nothingToStore lambda at the top of StorageTexture::FlushPending. This PR replaces that variable with the Refreshing HostThreadSlot, and git merges the two cleanly, so the new line keeps naming a variable that no longer exists. It is the only error: a -k 0 build of libSceAgcDriver on the merge with main f91137142 reports just this line.
Fix, one line in the merged FlushPending:
std::lock_guard lock(pending.mutex);
- const auto* exempt = refreshing;
+ const auto* exempt = Refreshing::Get();With it, libSceAgcDriver builds (Linux, GCC 15.2, Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON). On an RTX 3070 (NVIDIA 595.99.02), agc_driver_queued_index_read_order (#8911's test) and the 39 tests in agc_driver_graphics_tests pass, 40/40 in each of 3 runs. I did not run the full suite.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
|
Hi Thanks for moving the per-draw thread-locals to TEB slots. One thing changed on your branch so it can land, on top of |
✅ NVIDIA GPU test: passedPR head
Failing on main too (3, not counted against this PR)Validation IDs already present on main (9 IDs in 550 tests)Skipped (55)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
✅ AMD GPU test: passedPR head
Unstable on main (4, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (8, not counted against this PR)Passed on retry (3, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validated but not compared (1, not in the main baseline's validation pass)Validation IDs already present on main (4 IDs in 557 tests)Skipped (67)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
What
With MinGW, every
thread_localaccess goes through__emutls_get_address, a winpthreads key lookup. #6292 moved the draw path's locks and its hottest thread-locals to TEB slots (HostThreadSlot). This moves the ones left on the revalidation path, which every draw and dispatch that reuses cached resources takes:ShaderResources::fastRevalidate's five scratch vectors andRevalidate's four (overlapping,refreshed,versions,regions) now go throughThreadScratch<T, Tag>(): the thread's object in aHostThreadSlot, created on first use and destroyed with the thread byThreadOwned, as before;Texture.cpp'srefreshingexemption, read byStorageTexture::FlushPendingand two other pending-store scans, is aHostThreadSlot<const StorageTexture*, RefreshingTag>;Driver::sampledReadis aHostThreadSlot<bool, SampledReadTag>, throughsampledRead()andsetSampledRead().On the S2 page of Sonic Origins Plus's main menu, the queue worker spent, per frame (APS5 sampler, 15 s):
__emutls_get_address: 1.24 to 1.51 in six runs without this change, 0.92 and 1.17 in two runs with it;SampledReadScope: 0.15 to 0.24 without, 0.07 and 0.13 with;fastRevalidate: 0.66 to 0.72 without, 0.56 and 0.63 with.That is about 1% of the worker's frame (34 to 37 samples), so the frame times below move within run-to-run noise. Thread-locals elsewhere stay as they are.
Tested
Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.
agc_driver_image_array_window_past_layer_limitis not run: MinGW does not build itsalignas(65536).agc_driver_pipelined_dispatchfailed once under--parallel 4. It passed 8 of 8 runs alone.Driver.hppkeeps main's indirect-source declarations next tosampledReadandsetSampledRead, andTexture.cppkeeps main'sBufferPool.hppinclude.StorageTexture::WaitForFlushing(5937ef0) reads the refreshing texture throughRefreshing::Get().agc_driver_image_array_window_past_layer_limitis not run: main does not compileImageArrayWindowPastLayerLimit.cppwith MinGW (alignas(65536)).agc_driver_pass_input_hazard(added in ba4571a) fails on plain main 1d41645 as well, 0 of 4 runs alone.agc_driver_gpu_indirect_arguments_misaligned_writer_aheadis not run: main itself does not compile it with MinGW (alignas(65536)).agc_driver_multisample_fill_host_onlycan fail ("the sentinel fill did not land"): that is main's own race, agc_driver_multisample_fill_host_only fails intermittently: the sentinel fill after an absorbed multisampled clear does not land #6512, which fix(agc): record a multisampled target's commands on its own device #6522 fixes, and perf(agc): replace winpthreads locks and TLS on the draw path #6292 already depends on fix(agc): record a multisampled target's commands on its own device #6522 for it. It passed in this run, and with fix(agc): record a multisampled target's commands on its own device #6522's line added it failed 0 of 200 runs (8 at a time) on main 72c5eed.guest_shader_linktimed out once. It returns frommainwith the driver's threads still running, the exit hang of Windows: agc_shader_helpers intermittently hangs at exit in Driver::stop() under ctest #6791 (test(agc): shut libc down before agc_shader_helpers returns #6925 fixes it foragc_shader_helpers):Driver::stop, run atDLL_PROCESS_DETACH, waits on threads thatExitProcessalready ended. Run alone 400 times, 8 at a time, it hangs in 55 and 58 runs on plain main c842491, 74 with perf(agc): replace winpthreads locks and TLS on the draw path #6292 and 97 with this change.APS5_TRACE_SECONDS=200:15on the same machine in one session, caches warm. Traces attached.The four windows of the moving background I captured in that session read 112.3 to 119.3 ms at the median, so this pair's gap is mostly noise. The FPS shown in the title went from 9.58 to 9.74 (median of six readings), and a sampled pair taken an hour earlier went from 9.07 to 9.21.
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)Traces and summary lines (baseline 4e46e7e, whose summary says a0dd42c; this change 99bf270, whose summary says 4e46e7e):
teb-traces.zip
The two summary lines, with
tools/trace_digest.pyfor each trace:Baseline (summary commit a0dd42c)
seconds 200:15 from present 2708: 124 presents, frame p50 119.3 / p90 133.3 / p99 151.6 / max 172.5 ms, GPU busy 84.7 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit a0dd42c (dirty), dropped: yes
{"commit":"a0dd42cf9b44","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":2708,"ms":15078.201},"presents":124,"frame_ms":{"p50":119.277,"p90":133.323,"p99":151.553,"max":172.525},"gpu_busy_ms_per_present":84.702,"worker_busy_pct":{"queue worker 0x0":98.081},"top_phases_ms_per_frame":{"Driver.Packet":119.228,"Driver.Packet.draw":107.057,"Driver.Draw":106.006,"Driver.Draw.draw_and_resource_release":50.358,"Graphics.Draw":49.2,"Graphics.Draw.draw_and_resource_release":40.064,"Driver.Draw.shader_compile_and_link":37.71,"Driver.Present":32.538},"trace_dropped":true,"trace":"aps5-trace-a0dd42cf9b44-40532.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 84.7, Driver.Present 32.5, Driver.Present.render_fence_wait 32.0, Vulkan.Retire 32.0, Vulkan.Retire.wait 32.0, Driver.Packet 21.3, Driver.Packet.draw 20.4, Driver.Draw 20.2, Driver.Draw.draw_and_resource_release 5.0, Graphics.Draw 4.9
Longest waits
This change (summary commit 4e46e7e)
seconds 200:15 from present 3226: 130 presents, frame p50 113.5 / p90 128.9 / p99 143.9 / max 144.3 ms, GPU busy 83.3 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 4e46e7e (dirty), dropped: yes
{"commit":"4e46e7ebac25","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"200:15"},"gpu":"NVIDIA GeForce RTX 2080 Ti","driver":"NVIDIA 617.14","os":"Windows 10.0.26300","resolution":"3840x2160","window":{"spec":"seconds 200:15","first_present":3226,"ms":15060.793},"presents":130,"frame_ms":{"p50":113.494,"p90":128.928,"p99":143.934,"max":144.322},"gpu_busy_ms_per_present":83.305,"worker_busy_pct":{"queue worker 0x0":98.211},"top_phases_ms_per_frame":{"Driver.Packet":113.745,"Driver.Packet.draw":102.51,"Driver.Draw":101.488,"Driver.Draw.draw_and_resource_release":49.35,"Graphics.Draw":48.323,"Graphics.Draw.draw_and_resource_release":39.351,"Driver.Draw.shader_compile_and_link":35.574,"Driver.Present":32.978},"trace_dropped":true,"trace":"aps5-trace-4e46e7ebac25-37480.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 83.2, Driver.Present 33.0, Driver.Present.render_fence_wait 32.5, Vulkan.Retire 32.5, Vulkan.Retire.wait 32.5, Driver.Packet 19.4, Driver.Packet.draw 18.6, Driver.Draw 18.5, Driver.Draw.draw_and_resource_release 4.1, Graphics.Draw 4.0
Longest waits