perf(runtime): reuse rendering scopes across compatible draws #1877
Closed
leonida/mandy
cheltyi wants to merge 0 commits from
perf/replay-draw-scopes into main
pull from: perf/replay-draw-scopes
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!1877
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/replay-draw-scopes"
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 closed
This pull request cannot be reopened because the branch was deleted.
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.Independently reviewed and reproduced at
47e177df6on NVIDIA GeForce RTX 3060 (driver 615.78.08, Vulkan 1.4.363, Omarchy/Arch Linux).Correctness
shader_library_corpus).Independent performance measurements
Exact merge-base
77baf9062versus PR HEAD47e177df6, identical workload and Release build configurations, GCC 16.2.1. Validation disabled for timing. Medians of five CPU-pinned alternating pairs, each with three warmups and seven measured samples.10,000 draws:
The singleton control showed a 1.4% increase in CPU emit time but essentially unchanged total frame time.
These results independently corroborate the author's AMD RADV measurements on NVIDIA hardware. Synthetic benchmark only; retail-game performance was not measured.
No actionable defects found. Advisory approval.
AI-assisted review.
Independent verification — Turing and Blackwell
77baf906275d7b695664adbf0b33f3c2b306a1dc47e177df6a6f07ea036c60c36aace6ba489e47f9Environment
NVIDIA 621.14, Vulkan SDK 1.4.363.0,
MSVC 19.44.35230, Ninja RelWithDebInfo.
Three repetitions per GPU, revision and validation mode.
Results
d3d12_drawd3d12_depth24_drawd3d12_bundled3d12_graphics_direct_heapsreplay_rendering_scopevk_rendering_scope120 executions: 120 passed, 0 failed, 0 CTest skips.
Findings
The new GPU fixture consistently reported:
All 24 workload executions passed pixel, depth and
blending checks across both GPUs and validation modes.
The synthetic CPU recording test also passed every run.
No VUID diagnostics were found in the captured logs.
Validation-layer feature-adjustment warnings were present.
Six internal native D24 depthBiasClamp cases were skipped
per depth24_draw execution on both revisions.
No regressions observed. Rendering-scope reuse is
independently verified on Turing and Blackwell under
native Windows/MSVC.
The dedicated --bench mode and comparative BASE/HEAD
performance measurements were not included.
Synthetic tests only. No game files used.
AI-assisted: yes.
Windows 11 + RTX 3090 Vulkan Verification (
5009bea2e8merged withorigin/main02944d4ca1)10.0.26200), MSVC19.44.35228(Release), physical NVIDIA GeForce RTX 3090 + Khronos Vulkan Validation Layer (VK_LAYER_KHRONOS_validation1.4.363.1), clean merge ontoorigin/main(0conflicts).origin/mainruntime/src/vulkan_replay.h+ PRvk_rendering_scope_teston RTX 3090): failed (rc=1) withexpected 1 rendering scope(s), got 4096/4096,expected 2 rendering scope(s), got 4096/4096, andexpected 2048 rendering scope(s), got 4096/4096.origin/main + #1877):replay_rendering_scope_test:PASS (synthetic CPU recording)(rc=0,0.53s), and withLEONIDA_RENDERING_SCOPE_STATS=1(rc=0,0.29s) verified power-of-twolists=1/2/4/8/16+ exitlists=20 draws=54 eligible=54 scopes=35 shared_draws=19 max_run=2aggregate telemetry.vk_rendering_scope_test(LEONIDA_VK_VALIDATION=1on RTX 3090):rc=0(1.41s,0validation errors) —draws=4096single-scope (1/1), barrier-split (2/2), and 12-drawmixedindirect/target/pipeline workload (2048/2048) allpixel-depth-blend=PASS.--bench&--bench-mixedmedians (validation off, 3 warmups + 7 samples):draws=10000(barrier):run_length=1(10000scopes):emit_ms=25.8214, frame_ms=42.7186, gpu_ms=16.0254->run_length=4(2500scopes):emit_ms=9.8339, frame_ms=14.2064, gpu_ms=3.6905->run_length=16(625scopes):emit_ms=6.0863, frame_ms=7.4283, gpu_ms=0.9838->run_length=64(157scopes):emit_ms=5.7012, frame_ms=6.4327, gpu_ms=0.3806->run_length=10000(1scope):emit_ms=4.8558,frame_ms=5.3046,gpu_ms=0.1881.--bench-mixed(1000&10000draws acrossbarrier,pipeline,target,indirectrun lengths2/3+ 12-drawmixed): all18/18configurationspixel-depth-blend=PASS(rc=0,3.15s).vk_command_replay_test(LEONIDA_VK_VALIDATION=1,rc=0,0.69s,0validation errors) &tests/test_ctest_registration.py(7/7OK).AI-assisted.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.