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
Owner

@⁠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 · open

Claimed 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.

  • Look up each written range with one reverse span-map walk and append slots directly into one batch vector. Preserve the exact-start exception for the preceding texture, the view's mip end and both callers' sorted deduplication.
  • Compact joined ranges in place. Compute the final width of the existing pairwise policy up front. A full bake history avoids a second join. The range cap and union of bytes covered are unchanged. Retaining the allocation can keep the buffer's high-water capacity until it is drained.

Tested

  • The overlap regression checks an exhaustive grid around overlapping spans, an exact start, a short mip view, empty and inverted intervals, repeated writes, and addresses through u64::MAX. It compares the selected slot set with the old lookup.
  • The compaction regression compares exact range contents with the old pairwise implementation across lengths and caps and checks the buffer is reused. Restoring only the old compact() implementation made the capacity assertion fail (capacity 160 became 1). The patch passes.
  • Full leonida-gpu library suite on Windows: 705 passed, 0 failed, 61 ignored, no test filter. Command: cargo test -p leonida-gpu --lib --locked -- --test-threads=1.
  • Applied the repository's rustfmt configuration to the new tests and benchmarks.
  • The independent read-only review and the changed-file clean-room check passed.

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.

CPU operation Before After Throughput
Resolve 32 writes against 24,000 placed spans 6.66 µs 2.54 µs 2.62×
Resolve 5,000 writes against 24,000 placed spans 1,688.89 µs 795.77 µs 2.12×
Retain a full bake history plus 5,000 disjoint writes 416.45 µs 372.07 µs 1.12×

From d3d12/:

cargo test -p leonida-gpu --lib --release --locked bench_descriptor_write_ranges -- --ignored --nocapture --test-threads=1

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.

CPU duration (µs) Before p50 / p95 After p50 / p95
Lookup while holding the mutex 1,597.30 / 1,709.70 656.80 / 698.90
Writer signal to mutex acquisition 1,602.30 / 1,714.90 661.40 / 704.10

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/

cargo test -p leonida-gpu --lib --release --locked bench_descriptor_write_lock_contention -- --ignored --nocapture --test-threads=1

The PR diff against main at 45dc41f9 covers only descriptor/host.rs. A comparison with 5b1fff82 includes 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.

**@⁠lgtlgt0015-code** on GitHub · 2026-12-02 17:48 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191) `lgtlgt0015-code:codex/descriptor-write-range-batch` → `main` · +349 −26 · 1 files · 3 commits · open Claimed in the coordination issue as: [D3D12-DESCRIPTOR-WRITE-RANGE-BATCH](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570) ### 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. - Look up each written range with one reverse span-map walk and append slots directly into one batch vector. Preserve the exact-start exception for the preceding texture, the view's mip end and both callers' sorted deduplication. - Compact joined ranges in place. Compute the final width of the existing pairwise policy up front. A full bake history avoids a second join. The range cap and union of bytes covered are unchanged. Retaining the allocation can keep the buffer's high-water capacity until it is drained. ### Tested - The overlap regression checks an exhaustive grid around overlapping spans, an exact start, a short mip view, empty and inverted intervals, repeated writes, and addresses through `u64::MAX`. It compares the selected slot set with the old lookup. - The compaction regression compares exact range contents with the old pairwise implementation across lengths and caps and checks the buffer is reused. Restoring only the old `compact()` implementation made the capacity assertion fail (capacity 160 became 1). The patch passes. - Full `leonida-gpu` library suite on Windows: 705 passed, 0 failed, 61 ignored, no test filter. Command: `cargo test -p leonida-gpu --lib --locked -- --test-threads=1`. - Applied the repository's rustfmt configuration to the new tests and benchmarks. - The independent read-only review and the changed-file clean-room check passed. #### 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. | CPU operation | Before | After | Throughput | | --- | ---: | ---: | ---: | | Resolve 32 writes against 24,000 placed spans | 6.66 µs | 2.54 µs | 2.62× | | Resolve 5,000 writes against 24,000 placed spans | 1,688.89 µs | 795.77 µs | 2.12× | | Retain a full bake history plus 5,000 disjoint writes | 416.45 µs | 372.07 µs | 1.12× | From `d3d12/`: ```sh cargo test -p leonida-gpu --lib --release --locked bench_descriptor_write_ranges -- --ignored --nocapture --test-threads=1 ``` 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. | CPU duration (µs) | Before p50 / p95 | After p50 / p95 | | --- | ---: | ---: | | Lookup while holding the mutex | 1,597.30 / 1,709.70 | 656.80 / 698.90 | | Writer signal to mutex acquisition | 1,602.30 / 1,714.90 | 661.40 / 704.10 | 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/` ```sh cargo test -p leonida-gpu --lib --release --locked bench_descriptor_write_lock_contention -- --ignored --nocapture --test-threads=1 ``` The PR diff against `main` at `45dc41f9` covers only `descriptor/host.rs`. A comparison with `5b1fff82` includes 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:14:15 +00:00
Author
Owner

@⁠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.

merge base 5b1fff821 (= current origin/main), head b071a0a7a
git apply on main   (10 files)

cargo test -p leonida-gpu --lib -- batched_writes_find_the_same_texture_slots
  test result: ok. 1 passed
cargo test -p leonida-gpu --lib -- compact_reuses_the_range_buffer
  test result: ok. 1 passed

cargo test -p leonida-gpu --lib -- descriptor::host
  test result: FAILED. 59 passed; 1 failed; 6 ignored

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 with D3D12CreateDevice(None, ..) and this machine's None is the integrated Radeon (#2995 fixes that; #3188 documents the verdict it produces in red_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_slots asserts, 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/-26 change in one file).

AI-assisted: yes - DeepSeek v4.1 (flash).

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-12-02 18:01 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7353869826) **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.** ``` merge base 5b1fff821 (= current origin/main), head b071a0a7a git apply on main (10 files) cargo test -p leonida-gpu --lib -- batched_writes_find_the_same_texture_slots test result: ok. 1 passed cargo test -p leonida-gpu --lib -- compact_reuses_the_range_buffer test result: ok. 1 passed cargo test -p leonida-gpu --lib -- descriptor::host test result: FAILED. 59 passed; 1 failed; 6 ignored ``` **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 with `D3D12CreateDevice(None, ..)` and this machine's `None` is the integrated Radeon (#2995 fixes that; #3188 documents the verdict it produces in `red_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_slots` asserts**, **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/-26` change in one file). **AI-assisted:** yes - DeepSeek v4.1 (flash). Written with an AI assistant.
Author
Owner

@⁠MoonEyes on GitHub · 2026-12-02 18:04 UTC · original

Third-party verification of #3191 (D3D12-DESCRIPTOR-WRITE-RANGE-BATCH)

  • Head: b071a0a7a2338467b9abebd2c478feef5ee5016e, merge base 45dc41f95 (= current origin/main). git merge-tree --write-tree origin/main pr/3191 merges cleanly. GitHub mergeable_state: blocked (review required); no check runs or statuses reported on the head sha yet.
  • Claim: claiming: D3D12-DESCRIPTOR-WRITE-RANGE-BATCH by the author in #2570 (comment 7353537441), done: ... -> #3191 (7353671082). Claimed: yes.
  • No open duplicate found. No earlier comments or reviews on the pull request.

Not built: leonida-gpu is 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.rs

  • Spans::slots_holding_ranges (host.rs:1176): the reverse walk over by_start.range(..end) takes every span starting in [start, end), then the first key <= start. It includes that key if at == start (old: in range(start..end)) or if span_end > start (old: the before predecessor), and stops there. So the old exact-start rule (a span at start hides its predecessor) still holds. The reaches(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 > 1 with pairwise chunks(2) produces aligned groups of 2^k original ranges. The smallest k with ceil(len/2^k) <= max(most/2, 1) is next_power_of_two(ceil(len/limit)), which is what it computes. The in-place write is safe: write index w is below the read index w*group once group >= 2, and group == 1 returns early. retain_bake_writes (host.rs:1465) calls it right after join, so skipping the second join is correct.
  • The new tests compare against verbatim copies of the old code. batched_writes_find_the_same_texture_slots checks an exhaustive 122x124 grid including u64::MAX, and compact_reuses_the_range_buffer_and_matches_pairwise_widening checks 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 old compact). I did not reproduce either side (Windows-only).

Defects / nits

  1. AI disclosure missing (CONTRIBUTING.md, "AI-assisted contributions"). The body mentions "the independent read-only review" but does not say whether the change was AI-assisted or name the implementation and reviewer models. The commit has no trailer either. Blocker under the maintainer quick guide ("Forget to say you used AI").
  2. Nit: host.rs:7207-7209 has three blank lines between compact_reuses_... and bench_descriptor_write_ranges. The benchmark closures (host.rs:7252-7282) are not rustfmt-shaped. cargo fmt --check is not enforced for d3d12/, so this is cosmetic.
  3. Note: the in-game frame-time effect is unmeasured. The PR says so.

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

**@⁠MoonEyes** on GitHub · 2026-12-02 18:04 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7353915985) **Third-party verification of #3191 (D3D12-DESCRIPTOR-WRITE-RANGE-BATCH)** - Head: `b071a0a7a2338467b9abebd2c478feef5ee5016e`, merge base `45dc41f95` (= current `origin/main`). `git merge-tree --write-tree origin/main pr/3191` merges cleanly. GitHub `mergeable_state: blocked` (review required); no check runs or statuses reported on the head sha yet. - Claim: `claiming: D3D12-DESCRIPTOR-WRITE-RANGE-BATCH` by the author in #2570 (comment 7353537441), `done: ... -> #3191` (7353671082). Claimed: yes. - No open duplicate found. No earlier comments or reviews on the pull request. **Not built: `leonida-gpu` is 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.rs`** - `Spans::slots_holding_ranges` (host.rs:1176): the reverse walk over `by_start.range(..end)` takes every span starting in `[start, end)`, then the first key `<= start`. It includes that key if `at == start` (old: in `range(start..end)`) or if `span_end > start` (old: the `before` predecessor), and stops there. So the old exact-start rule (a span at `start` hides its predecessor) still holds. The `reaches(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 > 1` with pairwise `chunks(2)` produces aligned groups of `2^k` original ranges. The smallest k with `ceil(len/2^k) <= max(most/2, 1)` is `next_power_of_two(ceil(len/limit))`, which is what it computes. The in-place write is safe: write index `w` is below the read index `w*group` once `group >= 2`, and `group == 1` returns early. `retain_bake_writes` (host.rs:1465) calls it right after `join`, so skipping the second `join` is correct. - The new tests compare against verbatim copies of the old code. `batched_writes_find_the_same_texture_slots` checks an exhaustive 122x124 grid including `u64::MAX`, and `compact_reuses_the_range_buffer_and_matches_pairwise_widening` checks 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 old `compact`). I did not reproduce either side (Windows-only). **Defects / nits** 1. AI disclosure missing (CONTRIBUTING.md, "AI-assisted contributions"). The body mentions "the independent read-only review" but does not say whether the change was AI-assisted or name the implementation and reviewer models. The commit has no trailer either. Blocker under the maintainer quick guide ("Forget to say you used AI"). 2. Nit: host.rs:7207-7209 has three blank lines between `compact_reuses_...` and `bench_descriptor_write_ranges`. The benchmark closures (host.rs:7252-7282) are not rustfmt-shaped. `cargo fmt --check` is not enforced for `d3d12/`, so this is cosmetic. 3. Note: the in-game frame-time effect is unmeasured. The PR says so. **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](https://claude.ai/code)_
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-02 20:23 UTC · original

Ran natively on Windows 11, head 93b47ac9d merged into current main (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)

passed failed ignored
main 703 0 59
merge 705 0 61

The difference is exactly the two new tests and the two new ignored benchmarks. With --features diagnostics, descriptor::host also 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 old compact body on the merge. compact_reuses_the_range_buffer... then fails at len=2 most=0 with capacity 160 -> 1, as the body says. The slot test is green both ways by design (measured).

clippy --all-targets on leonida-gpu gives 0 warnings on main and 0 on the merge.

No new switch (read). page_written is fed on every page write and on finished reads with the default LEONIDA_PAGE_WRITES (1|2|8), so the batched lookup in slots_written_under runs 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, so retain_bake_writes only matters with bit 2 off. The in-place compact also runs by default, but only when a heap's PAGE_WRITTEN list 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 direct by_start inserts and half through note() under all three Rules, with random forget. Addresses come from a small pool (small values, page boundaries +-1, the u64::MAX neighbourhood) so the edges really collide. The cases include zero-size spans, spans to u64::MAX, page-straddling spans, random shows mip 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.

compact matched the old pairwise loop over 3,000 random cases (unsorted input, touching and non-touching ranges, caps from 0 up to 2*BAKE_MOST). retain_bake_writes matched the old version over 400 cases of 16k to 64k ranges, and its compaction branch was taken in 380 of them. So dropping the second join there is fine.

To check that the harness catches mistakes, I ran it against one mutation at a time.

mutation caught
at >= start -> at > start yes, case 31
*span_end > start -> >= yes, case 13
at <= start -> at < start (the break) yes, case 29
range(..end) -> range(..=end) yes, case 5
compact_joined group +1 before rounding yes, in both the compact and retain checks

Concurrency. Both callers still do the whole batch under one placed lock, as before (read). What a write sees is unchanged and only the hold time is shorter. I also ran two writer threads doing note/forget/shows while 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)

before after
PR bench, 32 writes / 24k spans 4.69 µs 1.61 µs
PR bench, 5,000 writes / 24k spans 1,396.70 µs 611.81 µs
PR bench, bake history + 5,000 writes 282.18 µs 259.23 µs
PR contention bench, lookup under lock p50/p95 1,289 / 1,886 µs 521 / 759 µs
mine, 200k spans / 50k random writes up to 128 KiB 64.4 ms 46.1 ms

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-tree against every open PR whose file list includes descriptor/host.rs)

  • #3016 conflicts with this one in descriptor/host.rs. Both add tests at the top of mod tests, so keeping both sides fixes it. #3016 alone merges cleanly on main.
  • #3039 already conflicts with main (src/host.rs, switches.md), not because of this PR.
  • #3029, #2975, #2834 and #2661 merge cleanly on top of this one.

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).

**@⁠Kal0s-design** on GitHub · 2026-12-02 20:23 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7357670410) Ran natively on Windows 11, head `93b47ac9d` merged into current `main` (`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`) | | passed | failed | ignored | | --- | ---: | ---: | ---: | | main | 703 | 0 | 59 | | merge | 705 | 0 | 61 | The difference is exactly the two new tests and the two new ignored benchmarks. With `--features diagnostics`, `descriptor::host` also 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 old `compact` body on the merge. `compact_reuses_the_range_buffer...` then fails at `len=2 most=0` with capacity 160 -> 1, as the body says. The slot test is green both ways by design (measured). clippy `--all-targets` on `leonida-gpu` gives 0 warnings on main and 0 on the merge. No new switch (read). `page_written` is fed on every page write and on finished reads with the default `LEONIDA_PAGE_WRITES` (`1|2|8`), so the batched lookup in `slots_written_under` runs 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, so `retain_bake_writes` only matters with bit 2 off. The in-place `compact` also runs by default, but only when a heap's `PAGE_WRITTEN` list 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 direct `by_start` inserts and half through `note()` under all three `Rule`s, with random `forget`. Addresses come from a small pool (small values, page boundaries +-1, the `u64::MAX` neighbourhood) so the edges really collide. The cases include zero-size spans, spans to `u64::MAX`, page-straddling spans, random `shows` mip 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. `compact` matched the old pairwise loop over 3,000 random cases (unsorted input, touching and non-touching ranges, caps from 0 up to `2*BAKE_MOST`). `retain_bake_writes` matched the old version over 400 cases of 16k to 64k ranges, and its compaction branch was taken in 380 of them. So dropping the second `join` there is fine. To check that the harness catches mistakes, I ran it against one mutation at a time. | mutation | caught | | --- | --- | | `at >= start` -> `at > start` | yes, case 31 | | `*span_end > start` -> `>=` | yes, case 13 | | `at <= start` -> `at < start` (the break) | yes, case 29 | | `range(..end)` -> `range(..=end)` | yes, case 5 | | `compact_joined` group +1 before rounding | yes, in both the `compact` and `retain` checks | **Concurrency.** Both callers still do the whole batch under one `placed` lock, as before (read). What a write sees is unchanged and only the hold time is shorter. I also ran two writer threads doing `note`/`forget`/`shows` while 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) | | before | after | | --- | ---: | ---: | | PR bench, 32 writes / 24k spans | 4.69 µs | 1.61 µs | | PR bench, 5,000 writes / 24k spans | 1,396.70 µs | 611.81 µs | | PR bench, bake history + 5,000 writes | 282.18 µs | 259.23 µs | | PR contention bench, lookup under lock p50/p95 | 1,289 / 1,886 µs | 521 / 759 µs | | mine, 200k spans / 50k random writes up to 128 KiB | 64.4 ms | 46.1 ms | 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-tree` against every open PR whose file list includes `descriptor/host.rs`) - #3016 conflicts with this one in `descriptor/host.rs`. Both add tests at the top of `mod tests`, so keeping both sides fixes it. #3016 alone merges cleanly on main. - #3039 already conflicts with main (`src/host.rs`, `switches.md`), not because of this PR. - #3029, #2975, #2834 and #2661 merge cleanly on top of this one. 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).
Author
Owner

@⁠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
0d7a451ab plus #3113, #3182 and #3204, diag build. Candidate: the same plus this PR at 93b47ac9d. Series X
profile, 3840x2160 output, render scale 0.6667, hardware ray tracing (-HardwareRT -SmoothMotion -PrecompileAll -Log), fullscreen.

Tests: cargo test -p leonida-gpu --lib descriptor gives 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.

run fps median frame median / p95 / p99 (ms) preparing (ms) write-tracker guard waits a frame
base 1 15.9 58.9 / 78.9 / 84.2 25.5 37 (6.6 ms)
PR 1 16.9 55.4 / 85.8 / 1316.6 26.6 76 (9.3 ms)
base 2 14.2 66.2 / 86.5 / 90.8 25.6 29 (5.8 ms)
PR 2 18.8 51.6 / 119.4 / 417.5 26.6 84 (10.3 ms)
  • Median: the PR runs were faster in both pairs, 17.9 against 15.1 fps on average.
  • Worst frames: worse with the PR, a 1.3 s frame in one run and 0.4 s in the other. The guard-lock waits on
    the write trackers also doubled (copystat's "waits for the write trackers' locks").
  • Caveat: the scene was not stable between runs. The card's time per frame ranged from 0.2 to 38 ms, and the
    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.

**@⁠x2Tweek** on GitHub · 2026-12-02 20:46 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7358282851) 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 `0d7a451ab` plus #3113, #3182 and #3204, diag build. Candidate: the same plus this PR at `93b47ac9d`. Series X profile, 3840x2160 output, render scale 0.6667, hardware ray tracing (`-HardwareRT -SmoothMotion -PrecompileAll -Log`), fullscreen. **Tests:** `cargo test -p leonida-gpu --lib descriptor` gives 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. | run | fps median | frame median / p95 / p99 (ms) | preparing (ms) | write-tracker guard waits a frame | |---|---|---|---|---| | base 1 | 15.9 | 58.9 / 78.9 / 84.2 | 25.5 | 37 (6.6 ms) | | PR 1 | 16.9 | 55.4 / 85.8 / **1316.6** | 26.6 | 76 (9.3 ms) | | base 2 | 14.2 | 66.2 / 86.5 / 90.8 | 25.6 | 29 (5.8 ms) | | PR 2 | 18.8 | 51.6 / 119.4 / **417.5** | 26.6 | 84 (10.3 ms) | - **Median:** the PR runs were faster in both pairs, 17.9 against 15.1 fps on average. - **Worst frames:** worse with the PR, a 1.3 s frame in one run and 0.4 s in the other. The guard-lock waits on the write trackers also doubled (`copystat`'s "waits for the write trackers' locks"). - **Caveat:** the scene was not stable between runs. The card's time per frame ranged from 0.2 to 38 ms, and the 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.
Author
Owner

@⁠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

Head (this PR)
Merge base 45dc41f95 (behind main b41763227)
Merged onto main — merge-tree clean, git merge --no-ff clean

Ran

cargo test -p leonida-gpu --lib descriptor::host
  batched_writes_find_the_same_texture_slots ... ok
  compact_reuses_the_range_buffer_and_matches_pairwise_widening ... ok
  bench_descriptor_write_ranges ... ignored (CPU benchmark)
  bench_descriptor_write_lock_contention ... ignored (CPU contention benchmark)
  views_are_made_beside_the_heap_and_copied_in ... FAILED
cargo test -p leonida-gpu --lib          704 passed; 1 failed; 61 ignored

The failure is this machine's, unchanged all day: views_are_made_beside_the_heap_and_copied_in fails identically on clean main (the iGPU artefact of D3D12CreateDevice(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_ranges return 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_slots compares the new batched lookup against the pairwise answer the old code produced over the same spans, and compact_reuses_the_range_buffer_and_matches_pairwise_widening does 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

  • The speed-up the PR is for: that needs a game run and a profile; bench_descriptor_write_ranges is #[ignore]d and I did not run it.
  • The GPU paths the fixture imitates: the tests use synthetic spans, not a real heap written by the title.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-12-02 20:59 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7358633959) ## VERIFY-3191 — Windows nativo: los dos tests nuevos muerden, y la suite no se rompe | | | |---|---| | Head | `(this PR)` | | Merge base | `45dc41f95` (behind `main` `b41763227`) | | Merged onto | `main` — `merge-tree` clean, `git merge --no-ff` clean | **Ran** ``` cargo test -p leonida-gpu --lib descriptor::host batched_writes_find_the_same_texture_slots ... ok compact_reuses_the_range_buffer_and_matches_pairwise_widening ... ok bench_descriptor_write_ranges ... ignored (CPU benchmark) bench_descriptor_write_lock_contention ... ignored (CPU contention benchmark) views_are_made_beside_the_heap_and_copied_in ... FAILED cargo test -p leonida-gpu --lib 704 passed; 1 failed; 61 ignored ``` **The failure is this machine's, unchanged all day**: `views_are_made_beside_the_heap_and_copied_in` fails identically on clean `main` (the iGPU artefact of `D3D12CreateDevice(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_ranges` return 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_slots` compares the new batched lookup against the **pairwise** answer the old code produced over the same spans, and `compact_reuses_the_range_buffer_and_matches_pairwise_widening` does 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 - **The speed-up the PR is for**: that needs a game run and a profile; `bench_descriptor_write_ranges` is `#[ignore]`d and I did not run it. - **The GPU paths the fixture imitates**: the tests use synthetic spans, not a real heap written by the title. Written with an AI assistant.
Author
Owner

@⁠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.

  • Base & build: Merged cleanly via git merge --no-ff onto main b41763227 (diagnostics,dlss,mimalloc, exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit 0; workspace test targets compiled). Standalone leonida-gpu build (exe_sha16 = bd5e08c6aab43fe8) also compiled and passed targeted crate checks cleanly.
  • Batch heads (14 PRs): #3200 d1a91afd1, #3198 80a627bb1, #3191 93b47ac9d, #3189 c182fc392, #3176 ae0075d9a, #3168 337388052, #3164 1065952da, #3146 ebc0253ff, #3124 64600ef0c, #3069 311d33a40, #3031 8df1bfce7, #3029 e49404808, #3054 ff53fd8b9, #3010 d645712a3.
  • Hardware & setup: Windows 11, Ryzen 9 5900X (32 GB RAM), NVIDIA GeForce RTX 3090 24 GB, driver 610.88, Series X profile, 2560x1440, -NoFrameGen, scripts/game-gate.ps1 (301.3 s in 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).
Metric 14-PR Batch (c47eeb717f761d9d) main b41763227 baseline (cf499737bf684f6a)
Gate verdict / exit PASS (clean, 0 reasons, 0 warnings) PASS (clean, 0 reasons, 0 warnings)
World time 301.3 s (4,504 frames) 305.6 s
Device lost / crashes / missed pipeline waits 0 / 0 / 0 0 / 0 / 0
Rendered FPS (median) / p95 frame time 20.10 FPS / 69.76 ms 19.13 FPS / 74.01 ms
Median draws/frame / longest present gap 8,048 / 5.222 s 7,983 / 2.358 s
Peak private commit / peak VRAM 35,619 MB / 15,251 MB 37,803 MB / 16,220 MB

Verdict: 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.)

**@⁠EdenBendheim** on GitHub · 2026-12-02 21:01 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7358673927) **RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch)** — **PASS** covering exact head `93b47ac9d715396491a7da023fe53faa7be1e9af`. - **Base & build:** Merged cleanly via `git merge --no-ff` onto `main` `b41763227` (`diagnostics,dlss,mimalloc`, `exe_sha16 = c47eeb717f761d9d`; changed-file clean-room scan exit `0`; workspace test targets compiled). Standalone `leonida-gpu` build (`exe_sha16 = bd5e08c6aab43fe8`) also compiled and passed targeted crate checks cleanly. - **Batch heads (`14` PRs):** `#3200` `d1a91afd1`, `#3198` `80a627bb1`, `#3191` `93b47ac9d`, `#3189` `c182fc392`, `#3176` `ae0075d9a`, `#3168` `337388052`, `#3164` `1065952da`, `#3146` `ebc0253ff`, `#3124` `64600ef0c`, `#3069` `311d33a40`, `#3031` `8df1bfce7`, `#3029` `e49404808`, `#3054` `ff53fd8b9`, `#3010` `d645712a3`. - **Hardware & setup:** Windows 11, Ryzen 9 5900X (32 GB RAM), NVIDIA GeForce RTX 3090 24 GB, driver `610.88`, Series X profile, `2560x1440`, `-NoFrameGen`, `scripts/game-gate.ps1` (`301.3 s` in 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`). | Metric | 14-PR Batch (`c47eeb717f761d9d`) | `main` `b41763227` baseline (`cf499737bf684f6a`) | |---|---:|---:| | Gate verdict / exit | **PASS** (`clean`, `0` reasons, `0` warnings) | **PASS** (`clean`, `0` reasons, `0` warnings) | | World time | `301.3 s` (`4,504` frames) | `305.6 s` | | Device lost / crashes / missed pipeline waits | `0` / `0` / `0` | `0` / `0` / `0` | | Rendered FPS (median) / p95 frame time | `20.10 FPS` / `69.76 ms` | `19.13 FPS` / `74.01 ms` | | Median draws/frame / longest present gap | `8,048` / `5.222 s` | `7,983` / `2.358 s` | | Peak private commit / peak VRAM | `35,619 MB` / `15,251 MB` | `37,803 MB` / `16,220 MB` | **Verdict:** **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`.)*
Author
Owner

@⁠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.

  • Builds: A is main d9b618f1. B is the same main with this PR's head 93b47ac9d merged (git merge --no-ff, clean). Both are diag builds (diagnostics,dlss) made by d3d12/scripts/build-nvidia.ps1.
  • Machine: NVIDIA GeForce RTX 5060 Ti 16 GB, Intel i5-12400F (6 cores), 32 GB, Windows 11 Pro 26200.
  • Setup: d3d12/scripts/play-nvidia.ps1 -NoFrameGen with 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.
  • Unattended runs: the menus were passed by pressing A through LEONIDA_KEYS_FILE, and each run ended with WM_SYSCOMMAND/SC_CLOSE, as scripts/game-gate.ps1 does. Every run reached the world and ended cleanly.

python -I tools/d3d12_ab_compare.py abba, world median frame time:

run 1 A 2 B 3 B 4 A 5 A 6 B 7 B 8 A
median, ms 41.50 39.20 41.50 38.95 38.50 38.50 39.60 40.00
  • mean A 39.74 ms, mean B 39.70 ms
  • B − A: −0.04 ms (−0.1 %), standard error 1.00, 95 % [−3.21, +3.14], 4 pairs, 2 of 4 agree in sign
  • verdict: no clear difference

What this does and does not say:

  • On this PC, the change neither gains nor loses more than about 3 ms on a ~40 ms frame, standing.
  • Worst frames are not judged here. The runtime's 5 s frame-time lines came 1 to 4 times per run in the world, which is too few to compare p99 or the longest frame. So this neither confirms nor rules out the longer worst frames @⁠x2Tweek saw.
  • Walking or driving were not run. There the page writes this PR batches may be more frequent.

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.

**@⁠Lanworm** on GitHub · 2026-12-03 12:10 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3191#issuecomment-7377751294) · 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.** - **Builds:** A is `main` `d9b618f1`. B is the same `main` with this PR's head `93b47ac9d` merged (`git merge --no-ff`, clean). Both are `diag` builds (`diagnostics,dlss`) made by `d3d12/scripts/build-nvidia.ps1`. - **Machine:** NVIDIA GeForce RTX 5060 Ti 16 GB, Intel i5-12400F (6 cores), 32 GB, Windows 11 Pro 26200. - **Setup:** `d3d12/scripts/play-nvidia.ps1 -NoFrameGen` with 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. - **Unattended runs:** the menus were passed by pressing A through `LEONIDA_KEYS_FILE`, and each run ended with `WM_SYSCOMMAND`/`SC_CLOSE`, as `scripts/game-gate.ps1` does. Every run reached the world and ended cleanly. `python -I tools/d3d12_ab_compare.py abba`, world median frame time: | run | 1 A | 2 B | 3 B | 4 A | 5 A | 6 B | 7 B | 8 A | |---|---|---|---|---|---|---|---|---| | median, ms | 41.50 | 39.20 | 41.50 | 38.95 | 38.50 | 38.50 | 39.60 | 40.00 | - mean A 39.74 ms, mean B 39.70 ms - B − A: **−0.04 ms** (−0.1 %), standard error 1.00, 95 % [−3.21, +3.14], 4 pairs, 2 of 4 agree in sign - verdict: **no clear difference** **What this does and does not say:** - On this PC, the change neither gains nor loses more than about 3 ms on a ~40 ms frame, standing. - **Worst frames are not judged here.** The runtime's 5 s frame-time lines came 1 to 4 times per run in the world, which is too few to compare p99 or the longest frame. So this neither confirms nor rules out the longer worst frames @⁠x2Tweek saw. - **Walking or driving were not run.** There the page writes this PR batches may be more frequent. 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._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3191/head:github-bot/gh-3191'
git switch 'github-bot/gh-3191'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3191'
git switch 'github-bot/gh-3191'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3191'
git switch 'github-bot/gh-3191'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3191'
git switch 'main'
git merge --squash 'github-bot/gh-3191'
git switch 'main'
git merge --ff-only 'github-bot/gh-3191'
git switch 'main'
git merge 'github-bot/gh-3191'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
No description provided.