mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:25:53 +01:00
[PR #1877] perf(runtime): reuse rendering scopes across compatible draws #1889
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1889
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1877
Author: @cheltyi
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:perf/replay-draw-scopes📝 Commits (7)
5b6f721perf(runtime): reuse rendering scopes for compatible draws47e177dtest(runtime): avoid Windows far macro in rendering test44c65f0Merge #1877 rendering-scope reuse for diagnostics follow-up0355263runtime: measure rendering-scope reuse and benchmark mixed draws12b3386Merge current main for rendering-scope metrics follow-up5d58ddeMerge current main before completing rendering-scope PR5009beaMerge branch 'main' into perf/replay-draw-scopes📊 Changes
7 files changed (+1429 additions, -50 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+49 -4)📝
runtime/CMakeLists.txt(+12 -2)📝
runtime/README.md(+1 -0)➕
runtime/src/rendering_scope_stats.h(+87 -0)📝
runtime/src/vulkan_replay.h(+143 -44)➕
runtime/test/replay_rendering_scope_test.cpp(+594 -0)➕
runtime/test/vk_rendering_scope_test.cpp(+543 -0)📄 Description
Claimed in the coordination issue as: D3D-REPLAY-DRAW-SCOPE-RUNS — claim; D3D-REPLAY-SCOPE-METRICS — claim.
Depends on: #1062 — the documentation edits overlap in section 4.3; the runtime code has no dependency on its render-pass API implementation.
What and why
The Vulkan replay currently starts and ends dynamic rendering for every resolved draw, with attachment dependencies between those scopes. For 10,000 consecutive draws sharing a color/depth target, this emits 10,000 begins, 10,000 ends and 20,000 attachment barriers.
Keep one scope across consecutive compatible direct draws. Compatibility requires the same prepared graphics pipeline, attachment slots/images/views/subresource ranges/layouts, render area and layer count. Close before all other commands, skipped or indirect draws, statistics endpoints and GPU helpers, and before list cleanup. Each draw still emits its own state, descriptors, push constants and arguments. Fixed-function depth/stencil/blend ordering remains Vulkan rasterization order within the scope. The compatible 10,000-draw case now has one begin/end and two attachment dependencies.
The scope-lifetime optimization is independent of #1062's COM render-pass API; its section 4.3 documentation overlap is declared above.
LEONIDA_RENDERING_SCOPE_STATS=1now reports aggregate emitted/eligible/indirect/skipped draw commands, application scopes, shared draws, maximum run, a run-length histogram and scope-end reasons. The cached opt-in selects a template once per list; the default specialization has no per-draw counter updates. The instrumented path collects locally and merges once per list, including with device-fault checkpoints enabled. Reports contain fixed labels and totals only, at powers of two emitted lists and normal exit. Counts describe CPU replay attempts, including repeated lists or work that may not complete on the GPU.The existing GPU fixture gains
--bench-mixed: runs of 2/3 draws separated by UAV barriers, actual pipeline changes, target changes or single indirect draws, plus a repeating mixed sequence. Every pass checks both targets' pixels/depth and rendering scope counts. The default correctness run includes the mixed sequence. The renderer implementation is not duplicated.Measured frame cost
Ryzen 5 5600 + Radeon RX 6700 XT, RADV Mesa 26.2.5-arch3.1, Arch Linux. The new hand-authored fixture draws 10,000 scissored triangles into a 32×32 RGBA32F/D32 target, with changing push constants, depth testing/writes and alpha blending. Global UAV barriers split the compatible runs. Every color/depth texel is independently calculated on the CPU and checked after every frame.
These are medians of two alternating before/after process medians, each with three warmups and seven measured frames, without validation. In the full compatible case, CPU emit was 10.97 → 3.29 ms and the GPU replay interval 31.62 → 4.53 ms. Pipeline creation and preparation are outside timing; serialized frame cost includes command recording, submission, readback and waiting for completion. This is synthetic runtime frame time; retail-game FPS and the distribution of compatible run lengths have not been measured.
The singleton control (a UAV barrier between every draw) used a longer check: CPU affinity, 30 warmups + 30 samples, five quiet alternating pairs. Median 10,000-draw frame time was 48.72 → 48.86 ms (+0.29%); CPU emit 13.043 → 13.023 ms. A separate cheap-stub CPU benchmark found about 5% added untracked singleton overhead (roughly 0.10 ms/10,000 draws), without reproducing a frame regression on the GPU. This optimization benefits compatible runs; it retains the existing work at boundaries.
Additional mixed-workload measurements
GCC 16.2.1,
-O3 -DNDEBUG, RADV NAVI22, Mesa 26.2.5. Five alternating before/after process pairs pinned to CPU 4; each process uses three warm-up and seven measured passes per case. Validation and scope diagnostics are disabled for timings. Values below are medians of the five process medians at 10,000 draw commands. The baseline uses themainreplay header atdb1a22d29; all other runtime sources and the synthetic workload match. Its only fixture change is the expected per-draw scope count. Both versions pass pixel/depth/blend checks.These are serialized synthetic frame costs, including recording/submission/readback/waiting. They do not establish a retail FPS gain or fix the black screen. The unsuccessful retail FPS comparison is recorded below.
A separate five alternating process pairs compare #1877 without this follow-up against this follow-up with diagnostics disabled. The 10,000-command mixed case changes from 32.5534 to 32.7262 ms frame (+0.53%), and 8.7039 to 8.7131 ms CPU emit (+0.11%). Across the nine 10,000-command cases, frame medians range from -3.44% to +7.12%, CPU emit from -5.98% to +6.00%; these runs do not establish zero overhead in every workload.
Tested
vk_rendering_scope,vk_sync_validation,replay_rendering_scope,replay_rendering_scope_statsall pass. The sync-validation self-test detects its deliberately missing barrier; rendering-scope fixture reports zero validation errors. Baseline fixture also passes validation.compileall,make_game.py --help, text line-ending tests, no-game-data check andgit diff --checkpass.GPUs tested: AMD Radeon RX 6700 XT (RADV NAVI22), Mesa/vulkan-radeon 26.2.5, CachyOS kernel 7.3.1-1-cachyos. Vulkan validation layer 1.4.363. Windows/MSVC was not run locally for the added diagnostics/mixed cases. Independent Windows reviews in this PR apply to the original
47e177df6revision.AI-assisted: yes.
After merging current
main(a224b5d14) for final HEAD5d58dde1c, CMake confirms the portable build is up to date, and the seven focused rendering/query/indirect tests pass with validation and scope diagnostics enabled. Runtime replay sources and semantic tests are unchanged by that final main merge.Retail boot limit (2026-11-25)
Two offline, network-isolated retail boot checks on CachyOS 7.3.1, RADV/Mesa 26.2.5 did not yield a verified first world frame. HEAD
47e177df6ran for 12 minutes through setup/loading before its time limit. Baseline77baf9062ran for 6 minutes 43 seconds before an AMD GPU fault and successful GPU reset.The baseline used a copy of the completed first-run settings from the HEAD run, so these are not a matched frame-time/FPS pair. No retail FPS gain is established. The baseline fault shows that a GPU reset can occur without this optimization; it does not establish the cause of the earlier desktop freeze or show that this PR fixes it. The synthetic results above remain synthetic frame costs.
Checklist
main(a224b5d14) and merges cleanly.docs/d3d12_vulkan.md.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.