d3d12: texture frame ceiling follow-ups from #3291's review (D3D12-TEXTURE-FRAME-FOLLOWUPS) #3482

Merged
leonida/mandy
MoonEyes merged 1 commit from oreofr/texture-frame-followups into main 2026-12-04 17:02:22 +00:00 AGit

Pull request successfully merged and closed

Member

Item: D3D12-TEXTURE-FRAME-FOLLOWUPS (claimed in #3312: https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-26254)
Depends on: none (#3291 is merged, 00e245be5)

The four follow-ups the review of #3291 asked for, all in d3d12/crates/leonida-gpu/src/draw.rs.

Off by default, no change for players: every change sits inside LEONIDA_TEXTURE_FRAME_MS. With it unset (the default) the code paths are the same as before. LAST_ON_TIME is read only when the ceiling is on, so the change to its writer only matters then.

What each fix does

  1. A lone pass gets the whole ceiling. A pass still asks for half the ceiling at most (pass_ask_us), so passes running at once share it. Once its slice is spent, at a slot boundary, it asks again for what the frame has left (FrameTime::extend, through FrameTimeGuard::more), bounded by its own time (LEONIDA_TEXTURE_STAGE_MS) in all. Before, a frame with one texture pass got 4 ms of an 8 ms ceiling. A pass whose frame has ended gets nothing more.
  2. A slice too small to use counts as a spent ceiling. If less than 1/8 of the ceiling is left (slice_floor_us), reserve and extend give nothing, unless the pass asked for less than that. The pass then skips the queue's scan and sort instead of sorting the whole queue for a few µs. A refusal takes nothing from the frame.
  3. Bakes and early runs no longer set the backlog. LAST_ON_TIME picks the catch-up ceiling (3x). It is now written only when PASS_BUDGET is None (note_on_time). Before, a bake pass that looked at up to 1 << 16 slots could give the ordinary passes after it three times the ceiling.
  4. Docs.
    • FrameTime's comment no longer says "at most one slot". A pass past its slice is charged for the slot it was in and for its queue's preparation: that time counts from the reservation on but is not checked against the slice.
    • texture_frame_ms's comment covers the re-ask and the floor. It no longer names LEONIDA_TEXTURE_STAGE_MS, which now has its own comment where it is read.
    • d3d12/docs/switches.md is regenerated. LEONIDA_TEXTURE_STAGE_MS's line now gives that switch's own text instead of the frame ceiling's.

Tests (RTX 4070 Laptop, Windows 11; unit tests only, no game run)

Three new tests in draw::texture_frame_tests. To get red/green, the helpers (pass_ask_us, slice_floor_us, note_on_time, FrameTime::extend, the reserve floor argument) were first added with main's behaviour (no re-ask, no floor, an unconditional store), then fixed:

test main's behaviour this PR
a_lone_pass_asks_again_for_the_rest_of_the_frame (1) FAILED ok
a_crumb_of_the_ceiling_counts_as_spent (2) FAILED ok
only_plain_passes_note_the_backlog (3) FAILED ok
the 5 existing tests of the module ok ok
  • cargo test -p leonida-gpu: 790 passed, 0 failed, 60 ignored
  • cargo clippy -p leonida-gpu --all-targets -- -D warnings: clean
  • python -I tools/d3d12_switches.py --out d3d12/docs/switches.md, then --check d3d12/docs/switches.md: exit 0. The only change is the LEONIDA_TEXTURE_STAGE_MS line.
  • python -I tests/test_d3d12_switches.py: 22 tests OK
  • python -I scripts/check_no_game_data.py on both changed files: exit 0

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

**Item:** D3D12-TEXTURE-FRAME-FOLLOWUPS (claimed in #3312: https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-26254) **Depends on:** none (#3291 is merged, `00e245be5`) The four follow-ups the review of #3291 asked for, all in `d3d12/crates/leonida-gpu/src/draw.rs`. **Off by default, no change for players:** every change sits inside `LEONIDA_TEXTURE_FRAME_MS`. With it unset (the default) the code paths are the same as before. `LAST_ON_TIME` is read only when the ceiling is on, so the change to its writer only matters then. ### What each fix does 1. **A lone pass gets the whole ceiling.** A pass still asks for half the ceiling at most (`pass_ask_us`), so passes running at once share it. Once its slice is spent, at a slot boundary, it asks again for what the frame has left (`FrameTime::extend`, through `FrameTimeGuard::more`), bounded by its own time (`LEONIDA_TEXTURE_STAGE_MS`) in all. Before, a frame with one texture pass got 4 ms of an 8 ms ceiling. A pass whose frame has ended gets nothing more. 2. **A slice too small to use counts as a spent ceiling.** If less than 1/8 of the ceiling is left (`slice_floor_us`), `reserve` and `extend` give nothing, unless the pass asked for less than that. The pass then skips the queue's scan and sort instead of sorting the whole queue for a few µs. A refusal takes nothing from the frame. 3. **Bakes and early runs no longer set the backlog.** `LAST_ON_TIME` picks the catch-up ceiling (3x). It is now written only when `PASS_BUDGET` is `None` (`note_on_time`). Before, a bake pass that looked at up to `1 << 16` slots could give the ordinary passes after it three times the ceiling. 4. **Docs.** - `FrameTime`'s comment no longer says "at most one slot". A pass past its slice is charged for the slot it was in and for its queue's preparation: that time counts from the reservation on but is not checked against the slice. - `texture_frame_ms`'s comment covers the re-ask and the floor. It no longer names `LEONIDA_TEXTURE_STAGE_MS`, which now has its own comment where it is read. - `d3d12/docs/switches.md` is regenerated. `LEONIDA_TEXTURE_STAGE_MS`'s line now gives that switch's own text instead of the frame ceiling's. ### Tests (RTX 4070 Laptop, Windows 11; unit tests only, no game run) Three new tests in `draw::texture_frame_tests`. To get red/green, the helpers (`pass_ask_us`, `slice_floor_us`, `note_on_time`, `FrameTime::extend`, the `reserve` floor argument) were first added with main's behaviour (no re-ask, no floor, an unconditional store), then fixed: | test | main's behaviour | this PR | |---|---|---| | `a_lone_pass_asks_again_for_the_rest_of_the_frame` (1) | FAILED | ok | | `a_crumb_of_the_ceiling_counts_as_spent` (2) | FAILED | ok | | `only_plain_passes_note_the_backlog` (3) | FAILED | ok | | the 5 existing tests of the module | ok | ok | - `cargo test -p leonida-gpu`: 790 passed, 0 failed, 60 ignored - `cargo clippy -p leonida-gpu --all-targets -- -D warnings`: clean - `python -I tools/d3d12_switches.py --out d3d12/docs/switches.md`, then `--check d3d12/docs/switches.md`: exit 0. The only change is the `LEONIDA_TEXTURE_STAGE_MS` line. - `python -I tests/test_d3d12_switches.py`: 22 tests OK - `python -I scripts/check_no_game_data.py` on both changed files: exit 0 AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- A pass whose slice (half the ceiling at most) is spent asks again for
  what is left of the frame's ceiling (FrameTime::extend), so a frame with
  one texture pass gets the whole ceiling, not half of it.
- Less than an eighth of the ceiling left counts as a spent ceiling: no
  queue scan and sort for a few microseconds of uploads.
- Only plain passes note the slots on time that pick the catch-up ceiling:
  an early run or a bake (PASS_BUDGET, up to 1 << 16 slots) no longer gives
  the passes after it three times the ceiling.
- Docs: FrameTime says what a pass is charged past its slice (its slot and
  its queue's preparation); LEONIDA_TEXTURE_STAGE_MS gets its own comment
  where it is read, and switches.md is regenerated.

All inside LEONIDA_TEXTURE_FRAME_MS: unset, nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
First-time contributor

RUN — In-game (LEONIDA_TEXTURE_FRAME_MS=2) & Unit Test Gate (NVIDIA RTX 5070 12 GB, Windows 11)

Tested PR head fe9a7e7ce6 fast-forwarded cleanly onto main (00e245be5), diagnostic release build (-SeriesS, no frame generation, LEONIDA_TEXTURE_FRAME_MS=2 to exercise all four follow-up code paths live, 315 s automated run from the same save), compared against our recent main (30c683055) baseline:

Metric main baseline (30c683055, default) PR #3482 (fe9a7e7ce6, LEONIDA_TEXTURE_FRAME_MS=2)
World samples (>=1000 draws) 36 (max_draws=5187) 38 (max_draws=5322)
Median FPS / frame time 23.0 fps (43.5 ms) 23.5 fps (42.6 ms)
Slowest 10% / fastest 10% 13.7 / 25.0 fps 13.6 / 24.1 fps
3000-4999 draws/frame median 23.2 fps (28 samples) 23.5 fps (27 samples)
Errors / warnings / device lost 0 / 0 / 0 0 / 0 / 0

Unit & Repo Checks

  • cargo test -p leonida-gpu --lib --locked draw:: — 36/36 PASS (3 ignored; all draw::texture_frame_tests:: pass including a_lone_pass_asks_again_for_the_rest_of_the_frame and only_plain_passes_note_the_backlog)
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings — 0 warnings
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md — PASS
  • python -I scripts/check_no_game_data.py — PASS

Verdict

PASS — clean fast-forward on 00e245be5, all 36/36 draw:: tests and clippy/switch checks pass, and the 315 s live run with LEONIDA_TEXTURE_FRAME_MS=2 completed cleanly with zero errors and no FPS regression. Ready for merge.

AI-assisted.

### RUN — In-game (`LEONIDA_TEXTURE_FRAME_MS=2`) & Unit Test Gate (NVIDIA RTX 5070 12 GB, Windows 11) Tested PR head `fe9a7e7ce6` fast-forwarded cleanly onto `main` (`00e245be5`), diagnostic release build (`-SeriesS`, no frame generation, **`LEONIDA_TEXTURE_FRAME_MS=2`** to exercise all four follow-up code paths live, 315 s automated run from the same save), compared against our recent `main` (`30c683055`) baseline: | Metric | `main` baseline (`30c683055`, default) | PR `#3482` (`fe9a7e7ce6`, `LEONIDA_TEXTURE_FRAME_MS=2`) | | --- | --- | --- | | World samples (`>=1000` draws) | `36` (`max_draws=5187`) | `38` (`max_draws=5322`) | | Median FPS / frame time | `23.0 fps` (`43.5 ms`) | `23.5 fps` (`42.6 ms`) | | Slowest 10% / fastest 10% | `13.7` / `25.0 fps` | `13.6` / `24.1 fps` | | `3000-4999` draws/frame median | `23.2 fps` (`28` samples) | `23.5 fps` (`27` samples) | | Errors / warnings / device lost | `0` / `0` / `0` | `0` / `0` / `0` | ### Unit & Repo Checks - `cargo test -p leonida-gpu --lib --locked draw::` — **`36/36` PASS** (`3` ignored; all `draw::texture_frame_tests::` pass including `a_lone_pass_asks_again_for_the_rest_of_the_frame` and `only_plain_passes_note_the_backlog`) - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings` — `0` warnings - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` — PASS - `python -I scripts/check_no_game_data.py` — PASS ### Verdict **PASS** — clean fast-forward on `00e245be5`, all `36/36` `draw::` tests and `clippy`/switch checks pass, and the 315 s live run with `LEONIDA_TEXTURE_FRAME_MS=2` completed cleanly with zero errors and no FPS regression. Ready for merge. AI-assisted.
Member

Merged by Moon's agent on Moon's written authorization. A separate reviewer (Claude Opus 5.5) ACCEPTED the four follow-ups of #3291: re-ask for the rest of the ceiling, 1/8 floor, LAST_ON_TIME only without PASS_BUDGET, docs fixed; cargo test -p leonida-gpu --locked 790 passed at fe9a7e7ce. Off by default.

Merged by Moon's agent on Moon's written authorization. A separate reviewer (Claude Opus 5.5) ACCEPTED the four follow-ups of #3291: re-ask for the rest of the ceiling, 1/8 floor, LAST_ON_TIME only without PASS_BUDGET, docs fixed; `cargo test -p leonida-gpu --locked` 790 passed at fe9a7e7ce. Off by default.
OreoFR referenced this pull request from a commit 2026-12-04 17:21:34 +00:00
Sign in to join this conversation.
No description provided.