D3D12-AHEAD-OF-FRAME-CUT: skip the texture pass the previous list already did #3029
Closed
leonida/mandy
bobcatchris wants to merge 0 commits from
fix/d3d12-ahead-of-frame-cut into main
pull from: fix/d3d12-ahead-of-frame-cut
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!3029
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/d3d12-ahead-of-frame-cut"
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: D3D12-AHEAD-OF-FRAME-CUT
What and why
docs/findings.mdmeasures the submitting thread waiting ~12 ms of an ~80 ms frame inqueue::ahead_of_frame, while the helper pools that record the list ahead of the frame stand 95–99% idle. Most of that recording isState::heap_textures, which walks due texture slots and uploads them every frame even when the previous ahead-of-frame pass already covered the next frame.This change records the texture queue's write counter before each textures pass. If the heap is unchanged, no pages were written, remapped or baked, no view was made again or cast flipped, and no slot is held back or due by the next frame, the following list-ahead recording skips
heap_texturesand returns no list when there is nothing else to record.AHEAD_DIDstill advances, so asking lists keep skipping the pass that was already done. All invalidation signals come from the heap's existing bookkeeping; a write arriving during a pass is stamped as unserved by sampling the counter before it.The heap lock is held while the served state is stored, in the same order as
done_ahead, so a concurrent heap switch cannot leave stale state.Tested
draw::tests::ahead_textures_skip_only_when_nothing_is_pendingcovers every invalidation signal and theframe + 1boundary. Red/green: dropping the dirty-page signal makes the test fail; restoring it passes.cargo test -p leonida-gpu --locked(659 passed, 59 ignored) and the fullcargo test --workspace --exclude xtask --lockedwith the documented skip — green.python -I scripts/check_no_game_data.pyon both changed files andgit diff --check— clean.No in-game FPS measurement was made for this pull request. The 12 ms wait is from the existing profile in
docs/findings.md; this change removes work on quiet frames by construction.GPUs tested: n/a (offline Rust unit tests)
AI-assisted: yes — Gemini 4 Neon (architecture direction and independent review).
Checklist
mainand merges cleanly.CPU-only source review at
e49404808:texture_ahead_cleancan skip the routine path that publishes completed deferred descriptor flips.texture_slot_show_aheadpushes a ready entry intoFLIPSfrom its upload completion callback (descriptor/host.rs:3461) without bumpingTextureQueue::writes. Once that slot is retired or its next recheck is later thanframe + 1, the heap can look clean even thoughtexture_slots_flip(:3636, called byheap_texturesatdraw.rs:4242) still needs to replace the neutral descriptor. Each subsequent skip refreshesAHEAD_DID, so ordinary draws can keep deferring their own pass.I’d make a ready flip for this heap veto the skip and add a regression with unchanged writes and a completed flip. The immediate
RESHOWNqueue filled bylevels_changed(descriptor/host.rs:417) is also consumed by that pass and is separate fromRESHOWN_AFTER, which the predicate already checks.AI-assisted source review. No game data or GPU used.
RUN by OreoFR (oreofr-agent, AI-assisted): two in-game ABBAs, main against main + this PR (head
e49404808784af77c5804c848174aa7c04ac19d6, merged into main8422def759cda12c89f918438eeb8d53dd5972a6with no conflicts).Setup: RTX 4070 Laptop 8 GB, driver 621.40, Core Ultra 7 155H. Series S, no DLSS, no frame generation, the same warm data. Each run is 450 s walking (lift at 340 s). Frame rate comes from the 5-second
recording per frame (N frames)windows.Numbers are fps.
Verdict: no gain measured on this card, possibly a loss. I am not putting it in the merge queue. This is PROVISIONAL (one card, two ABBAs). A paired in-run A/B behind a switch (
LEONIDA_AB) would settle it with much less noise, if the change can be turned off at run time.RUN
Independent verification of
#3029(e49404808) merged cleanly ontomain(f37c4a87d) on Windows 10 Pro 22H2 (build 19045), AMD Ryzen 9 5950X, 64 GiB RAM, NVIDIA GeForce RTX 5070 12 GB (driver621.40), MSVC toolchain (1.98.1).Offline checks & code review
python -I scripts/check_no_game_data.pyon both changed files: PASS.cargo test -p leonida-gpu --locked --lib -- --skip depth_bounds_pipeline_loads_and_filters_draws(includingdraw::tests::ahead_textures_skip_only_when_nothing_is_pending): PASS.@ecox982745's finding:HostHeap::texture_ahead_clean(descriptor/host.rs:2898) checksRESHOWN_AFTER(host.rs:428), but does not checkRESHOWN(host.rs:413) or pending ready flips inFLIPS(host.rs:863) /PENDING_LIST_FLIPS(host.rs:889).In-game 4-leg ABBA (
mainf37c4a87dvsmain + e49404808)Setup: Series S, DLSS Quality,
-NoFrameGen, warm cache (0pipeline waits across all 4 legs), same save snapshot restored before every leg, 75 s in world per leg (17world samples each,0errors /0device removals).main 1PR 1PR 2main 2mainavgPRavgObservations
@OreoFR's RTX 4070 Laptop ABBA, no frame-rate gain was measured on RTX 5070 (20.10vs20.35fps,-1.2%, within run-to-run noise), and ahead-of-frame recording/wait time changed by only~0.25-0.55 msmedian (1.00ahead lists/frame sent in every leg).~220-240guard faults/frame,~0.1 MBwatched & changed,~0.8-1.7 MBhashed per frame) appear to keeptexture_ahead_cleanfalse almost every frame; noteHEAP_TEXTURES_SKIPPED(draw.rs:508,1529) is currently never printed in any stats line, so exposing it (alongside aLEONIDA_ABswitch and theFLIPS/RESHOWNfix) would directly show the actual skip rate in the world.Verdict: No measurable FPS improvement on RTX 5070 (flat vs
main, matching@OreoFR's result);@ecox982745'sFLIPS/RESHOWNskip hazard is confirmed in source.AI-assisted: yes (Antigravity).
Ran natively on Windows 11, head
e49404808merged into currentmain(128648cfe, no conflicts),leonida-gpuwith--features diagnostics,--locked, toolchain 1.98.1. I ran the tests on the hardware card and again on WARP, with the same results.The source review above already names
FLIPSandRESHOWN. Two more queues are missing fromtexture_ahead_clean, and I ran a probe that shows the skipped pass leaving them waiting whilemainclears them.Suite
cargo test -p leonida-gpu --lib(merge)draw::tests::ahead_textures_skip_only_when_nothing_is_pendingcargo clippy -p leonida-gpu --all-targetstoo_many_arguments(8/7) onahead_textures_clean(draw.rs:566)The predicate against queued work (throwaway test in
descriptor/host.rs, not committed). The setup is aHostHeapof 8 slots with placed spans noted for slots 2 to 4. I settled the remap cursor and cast, emptied the queue, tookserved = texture_news().0and queued one item at a time.texture_ahead_clean(served, frame)read_short(start)(SHORT)texture_slots_shortmade 1 slot dueWAITINGentry for the start, back-dated 2 frames and waited 1.2 s (whatlevels_waitingleaves)texture_slots_waitingmade 1 slot duelevels_changed(start)(RESHOWN)texture_views_remadedrained itFlipfor this heap pushed intoFLIPStexture_slots_fliptakes itNeither
read_shortnorlevels_waitingincrementsTextureQueue::writesor sets any flag thattexture_newsreads. Only the pass itself turns them into queue entries.End to end through
test_record_passes_ahead(same heap made withcreate_heap,frame::test_advance()before each list,SHORTandWAITINGfilled as above after list 2, queue otherwise empty):SHORTpending /WAITINGpending / duemain: recorded /SHORT/WAITING/ dueOn
mainthe next list's pass turns both into due slots. On the PR they stay queued until something else makes the heap not clean. Each skip also storesAHEAD_DID[1] = frame + 1(read in code), sodone_ahead(1)stays true and draws that are not baking also leave out their own textures' pass.This probe's queue is empty, so it shows the worst case. In a live heap, the slot whose filling queued the item was just uploaded, and by default it keeps a look on the queue (
frame + 1when uploaded in part, otherwiseRECHECK_FRAMES4, 12, 40, 120, 400). That look makesnext_due <= frame + 1and forces a pass, which drains both queues. So in a live heap, I expect a delay until the next due look in the heap, not a permanent stall. The delay grows as a slot's looks spread out, and has no bound withLEONIDA_HEAP_RECHECK=0. I did not measure it.A possible fix: count a non-empty
SHORT, an eligibleWAITINGentry, a non-emptyRESHOWN, or a readyFLIPS/pending flip for this heap as "not clean". Each needs a regression test like the one in the second table.Not checked: how often these queues are non-empty on a quiet heap in game. An earlier in-game run in this thread found
texture_ahead_cleanfalse almost every world frame anyway, so menus and still scenes are where this would show. I made no in-game run. Themaincolumn of the end-to-end probe ran on WARP only.GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
Verification of #3029 (third party, code review on Linux; not built: Windows-only
leonida-gpu)e49404808784af77c5804c848174aa7c04ac19d6(2 files:draw.rs+72/-7,descriptor/host.rs+23).393901a5b.git merge-tree --write-tree origin/main pr/3029againstmain45dc41f95is clean(210 commits behind). CI on the head: 6/6 success.
python -I scripts/check_no_game_data.pyon both files: exit 0.Review
The skip (
draw.rs:503-509) is gated bytexture_ahead_clean(descriptor/host.rs:2890-2911). It treats theheap as clean when
TextureQueue::writesis unchanged and nothing intexture_news,by_due,held,RESHOWN_AFTERor the cast has moved. Theheap_texturespass it skips does more than that predicate looks at:FLIPS(descriptor/host.rs:863, pushed at:3469from anupload completion callback without bumping
writes) are only published bytexture_slots_flipinside thepass. ecox982745 raised this.
RESHOWN(filled bylevels_changed),SHORT(read_short) andWAITING(
levels_waiting) are also consumed only by the pass, and none of them bumpswrites. Kal0s-design's probeshows
SHORTandWAITINGstaying pending for lists 3 to 7 on the PR, wheremainmakes those slots due atthe next list.
AHEAD_DIDfor the frame (the comment atdraw.rs:506-507), so the frame's owndraws keep deferring to a pass that did not run. Items 1 and 2 can then wait indefinitely while the heap is
otherwise quiet. That is a texture that never flips from its neutral descriptor, not just one late frame.
Root-cause fix, not a workaround: the predicate should be derived from the same queues the pass drains. One
option is a single "pass has work" query on
HostHeapthat includesFLIPSfor this heap,RESHOWN,SHORTand
WAITING. Another is to bumpTextureQueue::writeswherever those queues are pushed. A regression testshould keep
writesunchanged and leave one item in each queue.Smaller points:
ahead_textures_cleantakes 8 arguments, so clippy reportstoo_many_arguments(draw.rs:566, perKal0s-design). A struct, or the query above, would remove it.
record_passes_ahead_partnow returnsrecordedinstead oftrue(draw.rs:545), soAHEAD_STATS[0..2]stop counting skipped lists. That is fine, but
findings.mdfigures based on those counters change meaning.Process
Verdict: defects. The skip can leave queued flips and slot work undone (items 1-3). Fix the predicate and add
the regression test before merge. The OreoFR and lixonik in-game ABBAs on this head do not cover these queues.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
e49404808784af77c5804c848174aa7c04ac19d6.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; standalone Windows unit checks also passed default & diagnostics with compile-time red onahead_textures_clean).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,LEONIDA_UPLOAD_AHEAD=1,scripts/game-gate.ps1(301.3 sin world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (GATE CONTROL moved=2.51 m,max_from_ctrl=5,053.9 m).c47eeb717f761d9d)mainb41763227baseline (cf499737bf684f6a)clean,0reasons,0warnings)clean,0reasons,0warnings)301.3 s(4,504frames)305.6 s0/0/00/0/020.10 FPS/69.76 ms19.13 FPS/74.01 ms8,048/5.222 s7,983/2.358 sVerdict: PASS for the 300 s in-game stability gate on
e49404808. (Single combined-batch stability check, not an isolated single-PR FPS gain claim.)(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)Closing this optimization attempt as net-negative.
Thank you
@ecox982745,@Kal0s-design,@OreoFR,@lixonik, and@MoonEyesfor the thorough source reviews and in-game ABBA measurements:@OreoFRon RTX 4070 Laptop and@lixonikon RTX 5070) measured zero gain / slight regression (-1.2%to-15%) because active frames mark nearly every frame (1.00ahead lists/frame).@ecox982745and@Kal0s-designshowed,texture_ahead_cleanwould also need to checkFLIPS/PENDING_LIST_FLIPS,RESHOWN,SHORT, andWAITING(reducing skips even further) and avoid refreshingAHEAD_DIDon skip.AI-assisted: Gemini 4 Neon