d3d12: batch placed-texture lookups on page writes (D3D12-DESCRIPTOR-WRITE-RANGE-BATCH) #3191
Open
github-bot
wants to merge 3 commits from
github-bot/gh-3191 into main
AGit
pull from: github-bot/gh-3191
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!3191
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3191"
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?
@lgtlgt0015-code on GitHub · 2026-12-02 17:48 UTC · original
lgtlgt0015-code:codex/descriptor-write-range-batch→main· +349 −26 · 1 files · 3 commits · openClaimed in the coordination issue as: D3D12-DESCRIPTOR-WRITE-RANGE-BATCH
What and why
Physical-page writes and one-shot bakes find placed textures while holding the descriptor span lock. The previous lookup seeks through the span map several times and collects a separate vector for every write.
Tested
u64::MAX. It compares the selected slot set with the old lookup.compact()implementation made the capacity assertion fail (capacity 160 became 1). The patch passes.leonida-gpulibrary suite on Windows: 705 passed, 0 failed, 61 ignored, no test filter. Command:cargo test -p leonida-gpu --lib --locked -- --test-threads=1.Release benchmark with synthetic ranges
Ryzen 7 5700X, Windows build 22631, Rust 1.98.1. Median of 14 rounds with 96 operations per round. The two paths run in alternating order with identical input and compare outputs outside timing.
From
d3d12/:GPUs tested: The benchmark is CPU-only. Library tests ran on a Windows host with an NVIDIA GeForce RTX 5070 Ti (driver 610.62). In-game frame time still needs measurement.
Concurrent write benchmark
The follow-up exercises the descriptor span mutex with a synthetic reader and writer. The reader looks up 5,000 writes against 24,000 spans while the writer signals that it is about to acquire the same lock. The writer alternates a mip end across a queried address. Each update changes the next slot set, and every old/new result matches exactly. The runs interleave the two implementations and collect 640 samples per version on the same Windows host.
The lookup measurement excludes the rendezvous and the output sort. The writer interval includes scheduling between its signal and the lock acquisition. In-game frame time still needs measurement.
From
d3d12/The PR diff against
mainat45dc41f9covers onlydescriptor/host.rs. A comparison with5b1fff82includes the nine files from the upstream precompile change (#3172).AI-assisted: yes. Implementation, benchmarks, and follow-up edits used OpenAI Codex with GPT-6.2 Sol. A separate GPT-6.2 Sol agent independently reviewed the diffs and regressions read-only.
@fiestorra on GitHub · 2026-12-02 18:01 UTC · original
Verified here: it applies on the current
main, and both tests it adds pass. The one failure in the module is this machine's, and it is already documented.The one failure is
descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, the byte-comparison test that fails because main's device tests still make their device withD3D12CreateDevice(None, ..)and this machine'sNoneis the integrated Radeon (#2995 fixes that; #3188 documents the verdict it produces inred_green.py). 59 of the module's 60 pass, and the two new ones are among them.What the change does, and the property its tests pin: physical-page writes and one-shot bakes find placed textures while holding the descriptor span lock, and the batched form has to find the same slots the pairwise one did - that is what
batched_writes_find_the_same_texture_slotsasserts, and it is the right test for a lookup rewrite (the risk is not speed, it is a texture landing in the wrong slot).compact_reuses_the_range_buffer...pins the other half: the buffer is reused and the widening still matches pairwise.Not covered: the contention it removes. Holding a lock less is only visible under concurrent writers and a title driving them; the tests establish that the answer did not change, not that the time did.
For the merge: the branch carries drift (10 files for a
+190/-26change in one file).AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
@MoonEyes on GitHub · 2026-12-02 18:04 UTC · original
Third-party verification of #3191 (D3D12-DESCRIPTOR-WRITE-RANGE-BATCH)
b071a0a7a2338467b9abebd2c478feef5ee5016e, merge base45dc41f95(= currentorigin/main).git merge-tree --write-tree origin/main pr/3191merges cleanly. GitHubmergeable_state: blocked(review required); no check runs or statuses reported on the head sha yet.claiming: D3D12-DESCRIPTOR-WRITE-RANGE-BATCHby the author in #2570 (comment 7353537441),done: ... -> #3191(7353671082). Claimed: yes.Not built:
leonida-gpuis Windows-only (D3D12). I did a code review only on Linux; none of the tests or the benchmark were run here.Review of
d3d12/crates/leonida-gpu/src/descriptor/host.rsSpans::slots_holding_ranges(host.rs:1176): the reverse walk overby_start.range(..end)takes every span starting in[start, end), then the first key<= start. It includes that key ifat == start(old: inrange(start..end)) or ifspan_end > start(old: thebeforepredecessor), and stops there. So the old exact-start rule (a span atstarthides its predecessor) still holds. Thereaches(slot, start)filter is unchanged. Equivalent to the old per-range lookup. Both callers (host.rs:3171, 3194) still sort and dedup.compact_joined(host.rs:1437):while len > most/2 && len > 1with pairwisechunks(2)produces aligned groups of2^koriginal ranges. The smallest k withceil(len/2^k) <= max(most/2, 1)isnext_power_of_two(ceil(len/limit)), which is what it computes. The in-place write is safe: write indexwis below the read indexw*grouponcegroup >= 2, andgroup == 1returns early.retain_bake_writes(host.rs:1465) calls it right afterjoin, so skipping the secondjoinis correct.batched_writes_find_the_same_texture_slotschecks an exhaustive 122x124 grid includingu64::MAX, andcompact_reuses_the_range_buffer_and_matches_pairwise_wideningchecks 129 lengths x 11 caps. That is good evidence of equivalence.Red/green: this is a CPU-time refactor with no behaviour change, so the slot test is green on both sides by design. Only the capacity assertion is red on
main(the author reports capacity 160 -> 1 with the oldcompact). I did not reproduce either side (Windows-only).Defects / nits
compact_reuses_...andbench_descriptor_write_ranges. The benchmark closures (host.rs:7252-7282) are not rustfmt-shaped.cargo fmt --checkis not enforced ford3d12/, so this is cosmetic.Verdict: defects. The code looks correct and the equivalence tests are thorough. Before merge, the author should add the AI/model disclosure (or state no AI was used), and a Windows maintainer should run
cargo test -p leonida-gpu --lib --locked.AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@Kal0s-design on GitHub · 2026-12-02 20:23 UTC · original
Ran natively on Windows 11, head
93b47ac9dmerged into currentmain(b41763227, clean merge).The two earlier comments were on
b071a0a7a. The head now also has the lock-contention benchmark and a fmt commit, and the body has the AI disclosure MoonEyes asked for.Suite (measured,
cargo test -p leonida-gpu --lib --locked -- --test-threads=4)The difference is exactly the two new tests and the two new ignored benchmarks. With
--features diagnostics,descriptor::hostalso passes on WARP (LEONIDA_D3D12_WARP=1) and with the debug layer (LEONIDA_D3D12_DEBUG=1), 60 passed and 7 ignored both times. A throwaway probe confirmed the device was WARP in one run and had the debug layer in the other.The new tests call
slots_holding_ranges, so they can't compile on main. To get a red I put back only the oldcompactbody on the merge.compact_reuses_the_range_buffer...then fails atlen=2 most=0with capacity 160 -> 1, as the body says. The slot test is green both ways by design (measured).clippy
--all-targetsonleonida-gpugives 0 warnings on main and 0 on the merge.No new switch (read).
page_writtenis fed on every page write and on finished reads with the defaultLEONIDA_PAGE_WRITES(1|2|8), so the batched lookup inslots_written_underruns by default whatever bit 2 says. Bit 2 only decides whether slots are made due or the ranges are kept for the bake. With the default, the bake list stays empty, soretain_bake_writesonly matters with bit 2 off. The in-placecompactalso runs by default, but only when a heap'sPAGE_WRITTENlist hits 2^18 ranges.Lookup equivalence (measured, throwaway tests, not pushed)
I wrote a randomized differential test against the old per-range
slots_holding, copied from main. It ran 200k cases. Half were built with directby_startinserts and half throughnote()under all threeRules, with randomforget. Addresses come from a small pool (small values, page boundaries +-1, theu64::MAXneighbourhood) so the edges really collide. The cases include zero-size spans, spans tou64::MAX, page-straddling spans, randomshowsmip ends including ones at or before the write start, and empty or inverted writes. I compared per range (sorted, no dedup) and per batch (multiset, and sorted plus dedup). Everything matched, and about 216k of the single-range lookups returned something.compactmatched the old pairwise loop over 3,000 random cases (unsorted input, touching and non-touching ranges, caps from 0 up to2*BAKE_MOST).retain_bake_writesmatched the old version over 400 cases of 16k to 64k ranges, and its compaction branch was taken in 380 of them. So dropping the secondjointhere is fine.To check that the harness catches mistakes, I ran it against one mutation at a time.
at >= start->at > start*span_end > start->>=at <= start->at < start(the break)range(..end)->range(..=end)compact_joinedgroup +1 before roundingcompactandretainchecksConcurrency. Both callers still do the whole batch under one
placedlock, as before (read). What a write sees is unchanged and only the hold time is shorter. I also ran two writer threads doingnote/forget/showswhile a reader computed old and new under the same guard, and all 200k lookups matched (measured). That only shows they agree on whatever state is there. It isn't a race detector.Timing (measured, one release run)
With wide random writes the gain is smaller (1.4x), since those walk many spans either way. It is still faster.
Conflicts (measured,
git merge-treeagainst every open PR whose file list includesdescriptor/host.rs)descriptor/host.rs. Both add tests at the top ofmod tests, so keeping both sides fixes it. #3016 alone merges cleanly on main.src/host.rs,switches.md), not because of this PR.Not checked: in-game frame time, the full suite under WARP or the debug layer (only
descriptor::host), debug-layer message output (only pass/fail), Loom-style interleavings, Linux.GPUs tested: one NVIDIA desktop card + WARP
AI-assisted: yes (Claude Code).
@x2Tweek on GitHub · 2026-12-02 20:46 UTC · original
Game run, standing still: the median frame looks shorter, but with longer worst frames. Not conclusive yet.
Setup: RTX 5090 32 GB, driver 621.40, i9-14900KS, 64 GB DDR5, Windows 11 (26300). Base: upstream main
0d7a451abplus #3113, #3182 and #3204, diag build. Candidate: the same plus this PR at93b47ac9d. Series Xprofile, 3840x2160 output, render scale 0.6667, hardware ray tracing (
-HardwareRT -SmoothMotion -PrecompileAll -Log), fullscreen.Tests:
cargo test -p leonida-gpu --lib descriptorgives 96 passed, 0 failed and 8 ignored.Method: four automated runs in the order base, PR, base, PR. Each one loads the same save with scripted Enter
presses, then stands still with no input. The figures cover 90 s from 30 s after the world is drawn, taken from the
frame log's 5 s lines.
the write trackers also doubled (
copystat's "waits for the write trackers' locks").two base runs differ by 10 %. So these four runs cannot tell the PR's effect from the title's own state. A longer
A/B inside one run would settle it, if the batching could sit behind a switch.
AI-assisted: the build, the automated runs, the log reading and the write-up were done with Claude Opus 5.5
(Claude Code); the numbers are the runtime's own log lines from the runs above.
@fiestorra on GitHub · 2026-12-02 20:59 UTC · original
VERIFY-3191 — Windows nativo: los dos tests nuevos muerden, y la suite no se rompe
(this PR)45dc41f95(behindmainb41763227)main—merge-treeclean,git merge --no-ffcleanRan
The failure is this machine's, unchanged all day:
views_are_made_beside_the_heap_and_copied_infails identically on cleanmain(the iGPU artefact ofD3D12CreateDevice(None, ..)that #2995 addresses). The two new benchmarks are correctly#[ignore]d, so they do not run in the suite.The PR ships its tests in the same file, so the red side was built synthetically: I made
slots_holding_rangesreturn an empty vector under a test variable, rebuilt and ran →FAILED: batched_writes_find_the_same_texture_slots,assertion left == right failed: 0..0. The test bites.The oracle is the right one:
batched_writes_find_the_same_texture_slotscompares the new batched lookup against the pairwise answer the old code produced over the same spans, andcompact_reuses_the_range_buffer_and_matches_pairwise_wideningdoes the same for the compacted ranges. A batching change that agrees with the old path on a fixture of real slot ranges is exactly what can be checked without a GPU.What I could not test
bench_descriptor_write_rangesis#[ignore]d and I did not run it.Written with an AI assistant.
@EdenBendheim on GitHub · 2026-12-02 21:01 UTC · original
RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
93b47ac9d715396491a7da023fe53faa7be1e9af.git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0; workspace test targets compiled). Standaloneleonida-gpubuild (exe_sha16 = bd5e08c6aab43fe8) also compiled and passed targeted crate checks cleanly.14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,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 s35,619 MB/15,251 MB37,803 MB/16,220 MBVerdict: PASS for the 300 s in-game stability gate on
93b47ac9d. (Single combined-batch stability check, not an isolated single-PR FPS gain measurement; if the head changes, this run no longer covers it.)(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)@Lanworm on GitHub · 2026-12-03 12:10 UTC · original · edited 2026-12-03 12:42 UTC
RUN (in game, 8 alternating runs A B B A A B B A): no clear difference in the median frame time on a 6-core desktop.
maind9b618f1. B is the samemainwith this PR's head93b47ac9dmerged (git merge --no-ff, clean). Both arediagbuilds (diagnostics,dlss) made byd3d12/scripts/build-nvidia.ps1.d3d12/scripts/play-nvidia.ps1 -NoFrameGenwith the F1 menu's saved choices: Series X, the title's own upscaler from a render scale of 0.6667 (no DLSS), a 60 fps cap no run reached. The same save was loaded each time. The player stood still with the title's idle camera going round its views, for 330 s in the world per run.LEONIDA_KEYS_FILE, and each run ended withWM_SYSCOMMAND/SC_CLOSE, asscripts/game-gate.ps1does. Every run reached the world and ended cleanly.python -I tools/d3d12_ab_compare.py abba, world median frame time:What this does and does not say:
Only numbers are quoted here: no logs, captures or game data.
AI-assisted: yes (Claude Code, Claude Opus 5.5). The runs were driven and analysed by the assistant on the submitter's machine.
Edited 2026-12-03: the setup corrected. Every run's settings line shows the F1 menu's saved Series X (render scale 0.6667, the title's own upscaler, no DLSS) and its 60 fps cap, which no run reached; not the script's Series S defaults as first written. Both sides ran the same; the numbers are unchanged.
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.