[pr-fix][pr-performance][vram] Settle speculative +50% render-target peak reserve once targets stabilize #564

Closed
MasterWolf wants to merge 1 commit from (deleted):pr/targets-room-peak-settle into Main
First-time contributor

Contributor role (optional)

  • Fluxer ID: 1577824307575267331

What it changes

  • The problem on main:
    In crates/darner-gpu/src/resource.rs (targets_room_kept), DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS (default 20,000 ms) and targets_seen growth tracking are computed unconditionally, but settle is only passed to targets_kept when DARNER_CARD_ROOM_FOR_TARGETS_MB is explicitly set (FLAT path). On the default targets_kept_from_peak path (targets_kept_from_peak(most, targets, peak)), settle is never consulted. As a result, once world render targets stabilize below most (e.g. ~1.8 GB at 1080to1440 DLSS Quality or 390 MB on Series S), the speculative +50% growth margin (peak + peak/2 - targets) stays permanently reserved (966–971 MB on RTX 5070 Ti) even minutes later, prematurely tripping the texture queue's room (no room, new textures wait).

  • What this does:
    Adds targets_kept_from_peak_settled(most, targets, peak, still_ms, settle) and wires it into targets_room_kept: once a real set of render targets (>= 256 MiB) has not grown by 64 MiB for settle ms, drop the speculative +50% growth margin and keep peak.min(most).saturating_sub(targets) (0 at steady state, while still preserving peak protection if targets transiently drop in a menu or cutscene). Whenever targets_seen observes >= 64 MiB growth again, the full +50% growth margin returns immediately; DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0 preserves legacy behavior.

How it was tested

  • Tested revision: c8258f9 + f43bed1 (pr/targets-room-peak-settle)

  • Commands and results:

    • Isolated A/B benchmark via scripts/bench.ps1 (cargo build --profile diag --locked -p darner --features diagnostics), comparing DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0 (A, legacy main) vs default 20,000 ms (B, this PR) from the same binary, save seed, and input route (30 s warmup + 90 s window, 1 run each):
  • Changes a default: yes — default DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 now applies to the default peak-based render-target reserve path on all setups (=0 disables it).

  • A/B result:

    Metric (RTX 5070 Ti 16 GB, Series X, 1080to1440, DLSS Quality, FG 3, High textures, DARNER_SAMPLED_MARKS=0, DARNER_RDNA_FLOAT=2) A (off, settle=0) B (on, default 20s)
    Steady-state kept for render targets 966–971 MB 0 MB
    Queue room checks (no_room / room) 23 / 10 11 / 22
    End-of-run texture copies on card 1,855 MB (1,667–1,922 MB) 2,512 MB (2,470–2,652 MB)
    neutral shown / written 127,589 / 2,611,264 (4.89%) 119,762 / 3,161,036 (3.79%)
    4500–7000 draws band FPS (matched scenes) 25.1 fps (39.8 ms, IQR 35.3–41.7 ms; 7 lines) 29.7 fps (33.7 ms, IQR 33.3–35.3 ms; 17 lines)
    Peak private memory 30.3 GB 29.9 GB
    Crashes / refused pipelines 0 / 0 0 / 0

    (Transparency note: overall window median was 32.0 fps in A vs 29.5 fps in B only because Run A happened to spend 8 frame lines in a 500–2000 draws view whereas Run B spent 17 frame lines in 4500–7000 draws; the matched 4500–7000 draws band gives the apples-to-apples performance comparison.)

  • Gates run on that revision:

    • cargo xtask policy: 576 files ok
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings: 0 warnings (default & --all-features)
    • cargo test --locked -p darner-gpu -- --skip oracle64: 1,806 passed, 0 failed (81 ignored), including new unit test resource::tests::room_for_targets_from_peak_settles_speculative_margin.
  • Gameplay: NVIDIA GeForce RTX 5070 Ti 16 GB, Intel Core Ultra 7 265KF, 64 GB DDR5-6400, Series X profile, 1080to1440, DLSS Quality, MFG 3, RT default (off).

  • Shader wave sizes tested: 32 and 64 lanes (DARNER_EXACT64=71883e40620a567a+7168dd781ca7efb9, DARNER_SAMPLED_MARKS=0).

  • Hardware dependence: likely general across GPUs/profiles where targets < DARNER_CARD_ROOM_FOR_TARGETS_MB (unit tests cover 390 MB Series S / 8 GB and 1,800 MB 1440p scales); runtime A/B tested on RTX 5070 Ti 16 GB.

  • Coverage gaps: Runtime A/B measured 1 run each on RTX 5070 Ti (16 GB); 8–12 GB GPUs and AMD cards covered by unit tests only.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #528
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: 1577824307575267331 ## What it changes - The problem on main: In `crates/darner-gpu/src/resource.rs` (`targets_room_kept`), `DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS` (default `20,000 ms`) and `targets_seen` growth tracking are computed unconditionally, but `settle` is only passed to `targets_kept` when `DARNER_CARD_ROOM_FOR_TARGETS_MB` is explicitly set (`FLAT` path). On the default `targets_kept_from_peak` path (`targets_kept_from_peak(most, targets, peak)`), `settle` is never consulted. As a result, once world render targets stabilize below `most` (e.g. `~1.8 GB` at `1080to1440` DLSS Quality or `390 MB` on Series S), the speculative `+50%` growth margin (`peak + peak/2 - targets`) stays permanently reserved (`966–971 MB` on RTX 5070 Ti) even minutes later, prematurely tripping `the texture queue's room` (`no room, new textures wait`). - What this does: Adds `targets_kept_from_peak_settled(most, targets, peak, still_ms, settle)` and wires it into `targets_room_kept`: once a real set of render targets (`>= 256 MiB`) has not grown by `64 MiB` for `settle` ms, drop the speculative `+50%` growth margin and keep `peak.min(most).saturating_sub(targets)` (`0` at steady state, while still preserving `peak` protection if targets transiently drop in a menu or cutscene). Whenever `targets_seen` observes `>= 64 MiB` growth again, the full `+50%` growth margin returns immediately; `DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0` preserves legacy behavior. ## How it was tested - Tested revision: `c8258f9` + `f43bed1` (`pr/targets-room-peak-settle`) - Commands and results: - Isolated A/B benchmark via `scripts/bench.ps1` (`cargo build --profile diag --locked -p darner --features diagnostics`), comparing `DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0` (A, legacy `main`) vs default `20,000 ms` (B, this PR) from the same binary, save seed, and input route (30 s warmup + 90 s window, 1 run each): - Changes a default: yes — default `DARNER_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000` now applies to the default peak-based render-target reserve path on all setups (`=0` disables it). - A/B result: | Metric (RTX 5070 Ti 16 GB, Series X, `1080to1440`, DLSS Quality, FG 3, High textures, `DARNER_SAMPLED_MARKS=0`, `DARNER_RDNA_FLOAT=2`) | A (`off`, `settle=0`) | B (`on`, default `20s`) | |---|---|---| | Steady-state `kept for render targets` | `966–971 MB` | `0 MB` | | Queue room checks (`no_room` / `room`) | `23 / 10` | `11 / 22` | | End-of-run `texture copies` on card | `1,855 MB` (`1,667–1,922 MB`) | `2,512 MB` (`2,470–2,652 MB`) | | `neutral shown / written` | `127,589 / 2,611,264` (`4.89%`) | `119,762 / 3,161,036` (`3.79%`) | | `4500–7000 draws` band FPS (matched scenes) | `25.1 fps` (`39.8 ms`, IQR `35.3–41.7 ms`; 7 lines) | `29.7 fps` (`33.7 ms`, IQR `33.3–35.3 ms`; 17 lines) | | Peak private memory | `30.3 GB` | `29.9 GB` | | Crashes / refused pipelines | `0 / 0` | `0 / 0` | *(Transparency note: overall window median was `32.0` fps in A vs `29.5` fps in B only because Run A happened to spend 8 frame lines in a `500–2000 draws` view whereas Run B spent 17 frame lines in `4500–7000 draws`; the matched `4500–7000 draws` band gives the apples-to-apples performance comparison.)* - Gates run on that revision: - `cargo xtask policy`: `576 files ok` - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings`: 0 warnings (default & `--all-features`) - `cargo test --locked -p darner-gpu -- --skip oracle64`: `1,806 passed, 0 failed` (`81 ignored`), including new unit test `resource::tests::room_for_targets_from_peak_settles_speculative_margin`. - Gameplay: NVIDIA GeForce RTX 5070 Ti 16 GB, Intel Core Ultra 7 265KF, 64 GB DDR5-6400, Series X profile, `1080to1440`, DLSS Quality, MFG 3, RT default (off). - Shader wave sizes tested: 32 and 64 lanes (`DARNER_EXACT64=71883e40620a567a+7168dd781ca7efb9`, `DARNER_SAMPLED_MARKS=0`). - Hardware dependence: likely general across GPUs/profiles where `targets < DARNER_CARD_ROOM_FOR_TARGETS_MB` (unit tests cover 390 MB Series S / 8 GB and 1,800 MB 1440p scales); runtime A/B tested on RTX 5070 Ti 16 GB. - Coverage gaps: Runtime A/B measured 1 run each on RTX 5070 Ti (16 GB); 8–12 GB GPUs and AMD cards covered by unit tests only. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #528 - Replaces or overlaps: none found
Contributor

I checked the post-growth re-arm on 1d27f243. This PR makes the default peak-reserve path use the existing GREW pair. The texture pass and darner-texture-sweep can both update it, and targets_room_kept reads and writes the size and timestamp separately (resource.rs:3742–3754).

One possible ordering starts with (1800 MiB, 1000 ms) after settling. The texture pass samples 1800 MiB and writes back the unchanged size. The sweep observes 1900 MiB at 25000 ms and writes both fields. The texture pass resumes and writes its old timestamp. On the next 1900 MiB sample at 25001 ms, the pair now looks settled and the growth is missed. With a 3072 MiB limit and 20 s settle, my CPU model gives 0 MiB of reserve in that ordering and 950 MiB with a coherent update.

I would sample and update the two fields together, for example with a small lock around the atomic counter reads and the state transition. A regression for re-arming after growth would complement the existing reserve-formula test. This is a source review and CPU model. I have not observed the interleaving in a GPU run.

Reviewed with Codex and Claude Code.

I checked the post-growth re-arm on `1d27f243`. This PR makes the default peak-reserve path use the existing `GREW` pair. The texture pass and `darner-texture-sweep` can both update it, and `targets_room_kept` reads and writes the size and timestamp separately (`resource.rs:3742–3754`). One possible ordering starts with `(1800 MiB, 1000 ms)` after settling. The texture pass samples 1800 MiB and writes back the unchanged size. The sweep observes 1900 MiB at 25000 ms and writes both fields. The texture pass resumes and writes its old timestamp. On the next 1900 MiB sample at 25001 ms, the pair now looks settled and the growth is missed. With a 3072 MiB limit and 20 s settle, my CPU model gives **0 MiB** of reserve in that ordering and **950 MiB** with a coherent update. I would sample and update the two fields together, for example with a small lock around the atomic counter reads and the state transition. A regression for re-arming after growth would complement the existing reserve-formula test. This is a source review and CPU model. I have not observed the interleaving in a GPU run. Reviewed with Codex and Claude Code.
Author
First-time contributor

Thanks @tyr0nsur — great catch on the torn GREW / PEAK update between the texture pass and darner-texture-sweep. Implemented and verified locally on pr/targets-room-peak-settle (f55fef5; will push when back at the keyboard for push/upload confirmation):

  • Replaced the separate PEAK: AtomicU64 + GREW: [AtomicU64; 2] with a single Mutex<(u64, u64, u64)> (STATE) in targets_room_kept (crates/darner-gpu/src/resource.rs) guarding the target byte sample, timestamp read, (peak, last, since) transition (targets_room_step), and reserve calculation together.
  • Added targets_room_step_rearms_coherently_after_growth covering the 1,800 MiB @ 1,000 ms -> settled 0 MiB @ 25,000 ms -> 1,900 MiB @ 25,000 ms / 25,001 ms sequence (asserts 950 MiB re-arm holds and re-settles cleanly at 45,000 ms).

Local checks on f55fef5: cargo xtask policy (576 files ok), clippy --all-targets -- -D warnings (0 warnings), cargo test --locked -p darner-gpu resource::tests -- --skip oracle64 (79 passed, 0 failed, 1 device-specific ignored).

Thanks `@tyr0nsur` — great catch on the torn `GREW` / `PEAK` update between the texture pass and `darner-texture-sweep`. Implemented and verified locally on `pr/targets-room-peak-settle` (`f55fef5`; will push when back at the keyboard for push/upload confirmation): - Replaced the separate `PEAK: AtomicU64` + `GREW: [AtomicU64; 2]` with a single `Mutex<(u64, u64, u64)>` (`STATE`) in `targets_room_kept` (`crates/darner-gpu/src/resource.rs`) guarding the target byte sample, timestamp read, `(peak, last, since)` transition (`targets_room_step`), and reserve calculation together. - Added `targets_room_step_rearms_coherently_after_growth` covering the `1,800 MiB @ 1,000 ms` -> settled `0 MiB @ 25,000 ms` -> `1,900 MiB @ 25,000 ms` / `25,001 ms` sequence (asserts `950 MiB` re-arm holds and re-settles cleanly at `45,000 ms`). Local checks on `f55fef5`: `cargo xtask policy` (576 files ok), `clippy --all-targets -- -D warnings` (0 warnings), `cargo test --locked -p darner-gpu resource::tests -- --skip oracle64` (`79 passed, 0 failed`, `1` device-specific ignored).
Contributor

1d27f243 on an RTX 4070 Ti 12 GB with hardware RT: the reserve is given back and the queue opens as described, but here it comes out about 1 fps slower than plain, not faster.

PC and method: RTX 4070 Ti 12 GB, driver 621.24, Ryzen 7 7800X3D, Windows 11. Own release builds: A is plain 9b288a70 (v2026.12.04.01), S is the same with this PR's commit on top. 1440p output, DLSS Quality, hardware RT, frame generation off, no cap. One save, standing with scripted camera turns, 10 min a run, counted from 120 s. Order A S S S S A, same shader cache, DARNER_QUEUE_GAPS=1 on all six.

Run fps, seconds with 7,000+ draws fps, lighter seconds Card ms Kept for targets at the end "no room" lines Card memory, most Least card room
A 27.3 31.0 30.8 953 MB 654 9,440 MB 1,505 MB
S 24.9 22.9 32.6 5 MB 1 9,823 MB 1,073 MB
S 25.8 30.4 32.2 8 MB 1 9,926 MB 1,034 MB
S 27.4 31.5 31.4 8 MB 1 9,992 MB 964 MB
S 26.3 31.1 31.9 8 MB 15 9,985 MB 947 MB
A 27.8 30.9 30.9 907 MB 325 9,430 MB 1,515 MB
  • It does what it says. Kept room goes from 900 to 950 MB down to 5 to 8 MB once targets settle, the queue stops saying "no room", and the card holds about 400 to 550 MB more.
  • The re-arm worked in every run. Each S run had one rise of 64 MB or more after the give-back (targets 249 to 411 MB at 38 to 41 s), and the kept room came back at the next look each time (11 to 42 MB up to 277 MB). So I did not see the torn update from @tyr0nsur's review in four runs. That is four events, all early, so it says little about how rare it is.
  • Speed: means on heavy seconds are 27.55 fps for A and 26.1 for S (26.5 without the first S run, which looks like an outlier). Card time is 1.0 to 1.2 ms higher with the PR. The card's idle time behind the submit thread is the same in both (1.5 to 1.9 ms), so the difference is on the card. I don't know why more textures on the card cost card time here; least room going from 1.5 GB to about 1.0 GB may be part of it.
  • No device loss in any of the six.

Two A runs against four S, and the S runs spread over 2.5 fps on heavy seconds, so I'd call it "no gain on this 12 GB card with RT, possibly a 1 ms cost" and not more. Your 5070 Ti numbers were with RT off, frame generation on and 16 GB, so both can be true. If it stays on by default it may be worth a second 12 GB run from someone else.

`1d27f243` on an RTX 4070 Ti 12 GB with hardware RT: the reserve is given back and the queue opens as described, but here it comes out about 1 fps slower than plain, not faster. **PC and method:** RTX 4070 Ti 12 GB, driver 621.24, Ryzen 7 7800X3D, Windows 11. Own release builds: A is plain `9b288a70` (v2026.12.04.01), S is the same with this PR's commit on top. 1440p output, DLSS Quality, hardware RT, frame generation off, no cap. One save, standing with scripted camera turns, 10 min a run, counted from 120 s. Order A S S S S A, same shader cache, `DARNER_QUEUE_GAPS=1` on all six. | Run | fps, seconds with 7,000+ draws | fps, lighter seconds | Card ms | Kept for targets at the end | "no room" lines | Card memory, most | Least card room | |---|---|---|---|---|---|---|---| | A | 27.3 | 31.0 | 30.8 | 953 MB | 654 | 9,440 MB | 1,505 MB | | S | 24.9 | 22.9 | 32.6 | 5 MB | 1 | 9,823 MB | 1,073 MB | | S | 25.8 | 30.4 | 32.2 | 8 MB | 1 | 9,926 MB | 1,034 MB | | S | 27.4 | 31.5 | 31.4 | 8 MB | 1 | 9,992 MB | 964 MB | | S | 26.3 | 31.1 | 31.9 | 8 MB | 15 | 9,985 MB | 947 MB | | A | 27.8 | 30.9 | 30.9 | 907 MB | 325 | 9,430 MB | 1,515 MB | - **It does what it says.** Kept room goes from 900 to 950 MB down to 5 to 8 MB once targets settle, the queue stops saying "no room", and the card holds about 400 to 550 MB more. - **The re-arm worked in every run.** Each S run had one rise of 64 MB or more after the give-back (targets 249 to 411 MB at 38 to 41 s), and the kept room came back at the next look each time (11 to 42 MB up to 277 MB). So I did not see the torn update from @tyr0nsur's review in four runs. That is four events, all early, so it says little about how rare it is. - **Speed:** means on heavy seconds are 27.55 fps for A and 26.1 for S (26.5 without the first S run, which looks like an outlier). Card time is 1.0 to 1.2 ms higher with the PR. The card's idle time behind the submit thread is the same in both (1.5 to 1.9 ms), so the difference is on the card. I don't know why more textures on the card cost card time here; least room going from 1.5 GB to about 1.0 GB may be part of it. - **No device loss** in any of the six. Two A runs against four S, and the S runs spread over 2.5 fps on heavy seconds, so I'd call it "no gain on this 12 GB card with RT, possibly a 1 ms cost" and not more. Your 5070 Ti numbers were with RT off, frame generation on and 16 GB, so both can be true. If it stays on by default it may be worth a second 12 GB run from someone else.
First-time contributor

Tested merged onto c8258f95 (release), head 1d27f243. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11.

One unattended run, 60 s in the world, frame generation off. The texture queue line in the log, at the end of the run:

  • main: 535 MB kept for render targets
  • this PR: 8 MB kept for render targets

Exit code 0, no new kind of WARN or ERROR line. This was not an fps A/B (one run each, and this CPU is the limit here), so it says nothing about speed.

AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me.

Tested merged onto `c8258f95` (release), head `1d27f243`. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11. One unattended run, 60 s in the world, frame generation off. The texture queue line in the log, at the end of the run: - `main`: `535 MB kept for render targets` - this PR: `8 MB kept for render targets` Exit code 0, no new kind of WARN or ERROR line. This was not an fps A/B (one run each, and this CPU is the limit here), so it says nothing about speed. _AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me._
Author
First-time contributor

Closing as obsolete: this PR targeted the old pre-merge renderer and is no longer needed on post-merge.

Closing as obsolete: this PR targeted the old pre-merge renderer and is no longer needed on post-merge.
MasterWolf closed this pull request 2026-12-06 00:20:16 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
TrustNo1/Darner!564
No description provided.