d3d12: eliminate quadratic Refresh scans and allocations in card_steps (D3D12-CARD-STEPS-PLAN-SCRATCH) #3069
Open
github-bot
wants to merge 2 commits from
github-bot/gh-3069 into main
AGit
pull from: github-bot/gh-3069
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
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
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3069
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3069"
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?
@piyonchu on GitHub · 2026-12-02 08:26 UTC · original
piyonchu:perf/d3d12-card-steps-plan-scratch→main· +1323 −293 · 2 files · 2 commits · openClaimed in the coordination issue as: D3D12-CARD-STEPS-PLAN-SCRATCH (#2570)
What and why
Relates to #2940 (
"title bytes under flights' writes"/"steps on the card"submitting-thread CPU overhead).This replaces quadratic per-submission scans and per-frame heap allocations in
host::card_stepsand itsblocked_by/copied_readgate inhost.rswith zero-behavior-change algorithmic improvements:blocked_by_intoacrossruns(host.rs,card_steps.rs): Fusesblocked_byandcopied_readinto one walk overrunsacrossHost::card_steps,late_blocked, andrelay_wait(preserving exactWHY_RUN/WHY_READanddiagnosticsblameprecedence while stopping as soon as needed).Does::Refreshfiltering (does_of_into,plan_indices): RoutesStep::Refreshentries straight toRefreshIndexinstead of appending ~20,000Does::Refreshitems todoes, so seeding, dependency wave propagation,Placedbarrier checks, and CPU-reader conflict checks only inspect active copy/fill/read/placed entries (O(W * |active|)instead ofO(W * N)). ReplacesBox<dyn Iterator>heap allocations and indirect indexing in level assignment with directout_rw/copy_writesreverse scan andmax_copy_levelearly break (preserving zero-lengthDoes::Copyoverlap checks). Also makeshost::join_rangescompact in-place instead of allocating a freshVecper merge.elsewhere(RefreshIndex): Stays linear for small spans/early queries (queries < 16 || spans.len() < 128) and lazily sorts, deduplicates, and builds an in-place midpointmax_tointerval tree whenelsewhereis queried heavily underLEONIDA_CARD_STEPS=2(including when a 174 MiB heap refresh spans sub-allocations).FillToexpansion (CardStepsScratch,ScratchGuard,RecordScratch): Reuses persistentdoes,active,run_steps,list_ptrs,RefreshIndex,PlanScratch,writers,ops,places,held,room,spans,op_buckets(O(ops)bucketed level recording), andRecordScratchacrosscut_forandtake_steps_with_scratchwhileclear_retained()drops allArc/ID3D12Resourcehandles and borrowed transition barriers immediately on every return or unwind. ResolvesFillTodirectly by(run_idx, step_idx)inO(1)without linear pointer searches or intermediateVec<To>allocations.Tested
All commands run on
perf/d3d12-card-steps-plan-scratch(aef892880) ind:\GTAVI\Leonida\d3d12(with no game files):python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host.rs d3d12/crates/leonida-gpu/src/host/card_steps.rs— passed (exit 0)cargo check --lib -p leonida-gpu --locked— passed (0 warnings in touched files)cargo check --lib -p leonida-gpu --features diagnostics --locked— passed (0 warnings in touched files)cargo clippy -p leonida-gpu --lib --tests --locked— passed (0 warnings in touched files)cargo test --locked -j 4 -p leonida-gpu --lib -- --skip depth_bounds_pipeline_loads_and_filters_draws --test-threads=1—693 passed; 0 failed; 61 ignored; 1 filtered out(includes new equivalence testsrefresh_index_matches_linear_elsewhere,plan_scratch_and_active_filter_match_reference, andsingle_pass_blocked_by_into_matches_legacy_precedence)LEONIDA_RELAY=2 LEONIDA_CARD_STEPS=2 cargo test --locked -p leonida-gpu --lib -- a_copy_behind_a_flight_reads_what_the_flight_wrote --ignored --nocapture --test-threads=1—1 passed; 0 failed(48 of 48 copies were done on the card, 0 submissions waited)cargo test -p leonida-gpu --features diagnostics --test replay --locked—1 passed; 0 failed(a_frame_is_recorded_and_replayed)cargo test --release --locked -j 4 -p leonida-gpu --lib -- bench_card_steps --ignored --nocapture --test-threads=1(2 passed; 0 failed):card_steps elsewhere: 4 queries / 20k refreshesbefore=27.6 us/iter, after=28.9 us/iter (0.96x); 120 queries / 20k refreshesbefore=813.2 us/iter, after=594.0 us/iter (1.37x)card_steps plan(20k refreshes + 4k fills + 118 copies):before=289.9 us/iter, after=134.4 us/iter (2.16x)GPUs tested: NVIDIA GeForce RTX 4060 Laptop GPU (driver
32.0.16.1656) / Intel(R) UHD Graphics (driver32.0.101.6790), Microsoft Windows NT10.0.26200.0(unit,replay, andLEONIDA_RELAY=2 LEONIDA_CARD_STEPS=2card-steps tests ran; no retail game data).AI-assisted: yes (Antigravity + independent read-only reviewer subagent audited the diff against
cont/mainbefore committing and verified review fixes).Checklist
main(a917c54d6) and merges cleanly.host::card_stepsplanning/scratch and single-passblocked_by_into); follow-up work goes in a new pull request.docs/design.mdnot applicable).@Kal0s-design on GitHub · 2026-12-02 08:33 UTC · original
Windows 11, MSVC toolchain 1.98.1, head
aef892880(onmaina917c54d6). These are the configurations the description didn't run: the lib in parallel, withdiagnostics, on WARP and with the debug layer.cargo test -p leonida-gpu --lib, in parallel: 694 passed, 0 failed, 61 ignored.cargo test -p leonida-gpu --features diagnostics --lib, in parallel:LEONIDA_D3D12_WARP=1)LEONIDA_D3D12_DEBUG=1descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync. I've seen that test fail once before on WARP on another branch that doesn't touchcard_steps, so I take it for a flake outside this change.a_copy_behind_a_flight_reads_what_the_flight_wrote(ignored), withLEONIDA_RELAY=2 LEONIDA_CARD_STEPS=2: "48 of 48 copies were done on the card, 0 submissions waited". It passed on hardware, on WARP, and on hardware with the debug layer.--features diagnostics --test replay: 1 passed.cargo clippy -p leonida-gpu --features diagnostics --lib --tests: no warning in the changed lines. The one hit inhost.rs(mem_replace_with_defaultat theBLAMEDtake) is on a line this PR doesn't change.Not run: the release bench, and the game.
GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
@ecox982745 on GitHub · 2026-12-02 08:40 UTC · original
CPU-only source review at
aef892880. One diagnostics change in the relay path is worth separating from the preserved wait decisions. On main, therelay_waitpredicate callscopied_readwheneverblocked_by(..., false)finds no remaining shader-write blocker.copied_readstill records its matching range viablame. If the initial shader-write blocker lands first and a card-copy destination still has a reader,blamedat the end of the wait reports that copy reader and its range.The new predicate passes
count=falsetoblocked_by_intoinhost.rs:8194. That drops the copy hit's metadata and can leave the initial shader-write attribution in the frame line even when the copy reader kept the wait going. The boolean settle decision is the same. It would help the #2940 measurements to preserve the copy-only attribution on relay polls, or describe the change explicitly. The new boolean equivalence test does not checkBLAMED.AI-assisted static review. No game files or GPU use.
@lixonik on GitHub · 2026-12-02 10:02 UTC · original
Live in-game 4-leg ABBA verification on Windows 10 22H2 + NVIDIA GeForce RTX 5070 12 GB (driver
621.40, 16C/32T desktop CPU), PR headaef892880merged ontomaina917c54d6(diagbuild,diagnostics,dlss,mimalloc, Series S,-NoFrameGen -NoPrecompile, same save snapshot restored before every leg, 85 s in-world per leg):cargo test -p leonida-gpu --locked --lib card_steps-- 15 passed, 0 failed, 3 ignored.python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host.rs d3d12/crates/leonida-gpu/src/host/card_steps.rs-- exit0.ERRORlines across all 4 legs;card_stepsactive throughout (513-562card-step log lines per leg).A = main a917c54d6,B = #3069 aef892880):main)#3069)#3069)main)Both ABBA half-pairs (
Leg 2 vs Leg 1andLeg 3 vs Leg 4) favor#3069in the steady-world slice (+0.75 fps/-1.20 msand+1.60 fps/-3.05 ms, compensating for run-order drift across legs 1->4).Result: PASS on live gameplay stability and performance (no regression; small positive steady-world margin).
@ecox982745's diagnosticsBLAMEDattribution note onhost.rsremains a separate diagnostics-only point.AI-assisted: yes (Antigravity).
@piyonchu on GitHub · 2026-12-02 11:44 UTC · original
Thanks @ecox982745 for catching the diagnostics attribution difference, and @Kal0s-design / @lixonik for the WARP, debug-layer, and live 4-leg ABBA testing.
Updated in
311d33a40:blame_copied: booltoblocked_by_into(host.rs) so bothrelay_wait(count=false, blame_copied=true) andlate_blocked(count=true, blame_copied=true) preserve legacycopied_readBLAMEDattribution under--features diagnosticswhenever no shader-write blocker takes precedence, while keeping release builds zero-cost (cfg!(feature = "diagnostics")).single_pass_blocked_by_into_matches_legacy_precedence(card_steps.rs) to assert exactBLAMEDparity against legacyblocked_by+copied_readunder--features diagnostics.python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host.rs d3d12/crates/leonida-gpu/src/host/card_steps.rs— exit0cargo check --lib -p leonida-gpu --locked&cargo clippy -p leonida-gpu --features diagnostics --lib --tests --locked— passed (0warnings in touched files)cargo test --locked -j 4 -p leonida-gpu --features diagnostics --lib -- card_steps --test-threads=1—15 passed; 0 failed; 3 ignoredcargo test --locked -j 4 -p leonida-gpu --lib -- --skip depth_bounds_pipeline_loads_and_filters_draws --test-threads=1—693 passed; 0 failed; 61 ignored; 1 filtered outcargo test -p leonida-gpu --features diagnostics --test replay --locked—1 passed; 0 failed@MoonEyes on GitHub · 2026-12-02 18:02 UTC · original
Code review of the new commit only, not built (Windows-only
leonida-gpu). Ready, with one note on the in-game evidence.311d33a40, merge basea917c54d6, 184 behind currentmain45dc41f95. A trial merge is clean. CI on the head: all 6 checks pass.aef892880:main).311d33a40came after both. The author reportscard_steps15/15 under--features diagnostics, the whole lib 693 passed, and the replay test.Review of
aef892880..311d33a40(host.rs,host/card_steps.rs):blame_copiedflag restores thecopied_readBLAMED attribution that ecox982745 found missing forrelay_waitandlate_blocked.record_copied_blame = cfg!(feature = "diagnostics") && blame_copiedkeeps the early return!need_copied_if_blocked && !count && !record_copied_blameidentical to before in release builds. Release behaviour of this commit is therefore unchanged, and the in-game ABBA onaef892880still describes what ships.emit_copied_blameruns only whenblocked.is_none(), which matches the legacy precedence where a shader-write blocker wins.single_pass_blocked_by_into_matches_legacy_precedencecompares(blk, copied, BLAMED)against the legacy pair under diagnostics. That is the right oracle.BLAMEDmutex. Under a parallelcargo test --features diagnostics --lib, any other test that callsblamecan interleave and flake it. The author ran with--test-threads=1. It would be worth one parallel run, or reading the attribution through a returned value instead of the global.Verdict: ready. The render-path in-game gate was met on
aef892880, and the follow-up is diagnostics-only.AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@icdmkg2 on GitHub · 2026-12-02 20:22 UTC · original
Third-party Windows verification of #3069 (
D3D12-CARD-STEPS-PLAN-SCRATCH) on head311d33a40Follow-up Windows build/test verification for the post-review commit
311d33a40(blame_copied/BLAMEDattribution parity under--features diagnostics).311d33a4038a95af56c34925e32bace4f9d5849dmerged cleanly (git merge --no-ff) ontoorigin/mainb41763227.621.24(32.0.16.2124), AMD Ryzen 7 H 260 w/ Radeon 780M, 32 GB RAM, Windows 1110.0.26300.9974,rustc 1.98.1.Results (MEASURED)
python -I scripts/check_no_game_data.py(host.rs,host/card_steps.rs)0python -I scripts/red_green.py 3069 --mutate(LEONIDA_ADAPTER=5060)767passed,0failed inleonida-gpu; red:red does not build(cannot find function copied_read in module card_steps, expected for refactored internal helpers)LEONIDA_ADAPTER=5060cargo test -p leonida-gpu --features diagnostics --locked --lib -- card_steps --test-threads=115 passed, 0 failed, 3 ignored(includessingle_pass_blocked_by_into_matches_legacy_precedencewithBLAMEDparity)LEONIDA_D3D12_WARP=1+LEONIDA_D3D12_DEBUG=1(samecard_stepscommand,--features diagnostics)15 passed, 0 failed, 3 ignoredLEONIDA_ADAPTER=5060cargo test -p leonida-gpu --features diagnostics --test replay --locked1 passed, 0 failedbench_card_steps(--ignored, unoptimized debug build, Ryzen 7 H 260)plan:3963.5 -> 1092.7 us/iter(3.63x);elsewhere(4 queries):357.4 -> 291.9 us/iter(1.22x);elsewhere(120 queries):10849.4 -> 10926.8 us/iter(0.99xin debug)AI-assisted: Gemini 4 Neon (High) via Antigravity (test execution, diff review, and write-up).
@EdenBendheim on GitHub · 2026-12-02 21:02 UTC · original
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
311d33a4038a95af56c34925e32bace4f9d5849d.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; standalone Windows red/green unit tests also passed694default /775diagnostics inleonida-gpu --lib, with compile-time red onRefreshSpan).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,LEONIDA_RELAY=2,LEONIDA_CARD_STEPS=2(card-step planning active),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
311d33a40(withLEONIDA_RELAY=2&LEONIDA_CARD_STEPS=2active). (Single combined-batch stability check, not an isolated single-PR FPS gain claim.)(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)@fiestorra on GitHub · 2026-12-02 22:39 UTC · original
VERIFY-3069 — Windows nativo: 15 pruebas del planificador de pasos pasan y el control muerde la compartición
(this PR)a917c54d6(behindmainb41763227)main—merge-treeclean,git merge --no-ffclean (auto-mergedhost.rs)Ran
Negative control (synthetic): a fill with several slots should point every one at its bytes; I made it take only the first (
take(1)), rebuilt and ran:Two bite.
What the change is: the step planner's
Refreshbecomes linear — a fill that several slots show is remembered and every one of them is pointed at its bytes once, instead of each slot re-scanning; a single slot expands in order only when its fill is shared. The comment keeps the measurement that motivates it (3,100–11,600 fills a frame, nearly all out of one host copy of the title's 174 MB heap, each aCopyBufferRegionthe card runs serially).Three ignored tests, named so nobody wonders: two benchmarks (
bench_card_steps_elsewhere_before_vs_after,bench_card_steps_plan_before_vs_after) and one that wantsLEONIDA_RELAXED…set.What I could not test
FillTo::Slots; the 3,100–11,600 a frame are quoted.card_steps.rs: read around the tests and the changed function, not line by line.Written with an AI assistant.
@x2Tweek on GitHub · 2026-12-03 12:01 UTC · original
RUN (in game, RTX 5090 32 GB, hardware RT on): PASS, 0 device losses. No frame-rate or submitting-thread change I can measure in this scenario.
311d33a40, merged--no-ffonto mainba9e65cec. Base: mainba9e65cecalone, built the same way.build-nvidia.ps1).-HardwareRT -SmoothMotion -PrecompileAll -Dlss quality, Series X profile, 4K output, the same save each run. A key driver presses Enter only while the log shows the menu. In the world the character walks and the camera turns all the time (look keys, 20 s each way). 330 s in the world per run. Order: PR, main, PR, main.LEONIDA_D3D12_DRED=1.AI-assisted: runs, key driver and log reading done with Claude Opus 5.5 (Claude Code); the numbers are the runtime's own log lines.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.