Skip to content

Render-target reserve expires once the targets settle (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, off by default) - #2589

Open
MoonEyes wants to merge 12 commits into
ProjectLeonida:mainfrom
MoonEyes:port/nv-vram-target-reserve-settle
Open

MoonEyes wants to merge 12 commits into
ProjectLeonida:mainfrom
MoonEyes:port/nv-vram-target-reserve-settle

Conversation

@MoonEyes

Copy link
Copy Markdown
Collaborator

Item: PORT-NV-VRAM-TARGET-RESERVE-SETTLE
Claim: #2570 (comment)
Source: trustno1-coder/VIctory-NVIDIA 21b040da (GPL-3.0), author readmet3xt-lab (credited in the commit with Co-authored-by and in the d3d12/README.md table).

The texture queue makes no new host copies while in use + kept for buffer copies + kept for render targets reaches 90 % of the card's budget. The target reserve (LEONIDA_CARD_ROOM_FOR_TARGETS_MB, 3,072 MB less the targets made) never expires: at 1440p the targets level off at 2.1-2.9 GB, so 160-990 MB stay kept for targets that never come while thousands of textures wait.

With LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS set, once the targets hold half the reserve or more and have not grown by 64 MiB for that many ms, nothing is kept; a growth of 64 MiB brings the reserve back. Upstream defaults to 20,000 ms. Here the default is 0 (reserve kept for the run, as before), because the behaviour would change for everyone. With the default, the code path is the one on main.

Only the reserve change is taken. The same upstream commit's room-test log line and pass timing counters (draw.rs, host.rs) are a separate subject and are left out.

Test: room_for_targets_is_given_up_once_they_settle (cargo test -p leonida-gpu --lib room_for_targets), no game files. It does not compile on main (the functions do not exist), and fails when the settle branch is cut. Passes on this branch merged with main 5cb4592. Crate-wide, the same 4 tests fail with and without the change (descriptor::host views_off_their_elements_get_a_copy_of_their_bytes, indirect batch_tables, host_list_budget_starts_empty_at_each_submission, warp_batch_charges_every_execution). Not run in the title or on a GPU: the 20,000 ms value is upstream's measurement, not ours. May touch the same lines of text as #2569 (resource.rs) and #2557 (README table).

AI-assisted (Claude Code, Claude Opus 5.5 and Sonnet 5.5); reviewed by a separate agent before opening.

🤖 Generated with Claude Code

MoonEyes and others added 2 commits November 28, 2026 20:42
…OOM_FOR_TARGETS_SETTLE_MS, 0 = off by default)

PORT-NV-VRAM-TARGET-RESERVE-SETTLE. The texture queue makes no new host
copies while in use + kept for buffer copies + kept for render targets
reaches 90 % of the card's budget. The target reserve
(LEONIDA_CARD_ROOM_FOR_TARGETS_MB, 3,072 MB less the targets made) never
expired: at 1440p targets level off at 2.1-2.9 GB, so 160-990 MB stayed
kept for targets that never came while thousands of textures waited.

With LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS set, once targets hold half
the reserve or more and have not grown by 64 MiB for that many ms, nothing
is kept; growth of 64 MiB brings the reserve back. Upstream defaults to
20,000 ms; here it is 0 (kept for the run, as before) because the
behaviour would change for everyone.

Ported from trustno1-coder/VIctory-NVIDIA 21b040da (readmet3xt-lab), GPL-3.0.
Only the reserve change is taken; the same commit's room-test log line and
pass timing counters (draw.rs, host.rs) are a separate subject and are left.

Co-authored-by: readmet3xt-lab <238408149+readmet3xt-lab@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MoonEyes

Copy link
Copy Markdown
Collaborator Author

@DadaCap could you review this one when you have a moment? It merges cleanly with main. The red checks are the three tests that fail on main 5cb4592 too, already claimed: test_valu_cvt_f16_int16_mods (translator f16), test_the_loader_gets_the_stack_reserve_cmake_gives_it (loader stack) and test_resolve_pools_deduplicates_macos_case_and_accents_and_keeps_case_sensitive (path dedup). None of them touches this diff. The ERROR: lines in those logs come from tests that pass.

AI-assisted (Claude Code, Claude Opus 5.5), posted for MoonEyes.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 0c5dbc424 (d3d12/crates/leonida-gpu/src/resource.rs).

The new opt-in LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS knob defaults to 0 (off, preserving existing behavior), and the pure targets_seen / targets_kept helpers use saturating arithmetic with clean boundary handling around the settle window.

Local verification:

  • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib room_for_targets: 1/1 passed (resource::tests::room_for_targets_is_given_up_once_they_settle).
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

Only with LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS set; the default path
returns before it. Lets a run show when the reserve expires and how many
MB go to textures, for the A/B test of this setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MoonEyes

Copy link
Copy Markdown
Collaborator Author
TEST-WANTED | 2026-11-28 UTC | from: MoonEyes | to: any | AI-assisted: Claude Code (Claude Opus 5.5)
NEEDS:      NVIDIA card with 8-12 GB, leonida.exe (d3d12/) | ~30 min (2 runs x 900 s) | game files: yes
BUILD:      same executable for A and B: #2589 at 2058ecb5b, merged onto main
VARIABLE:   LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS | A = 0 | B = 20000
FIXED:      d3d12/README.md recipe (no running.md section for leonida.exe yet) + DEVIATIONS: none
CACHES:     keep (same warm caches for A and B)
SEND BACK:  B: every "render-target reserve (...)" line (time, targets MB, MB freed or kept); A and B: dedicated video memory used at 300 s and 900 s; how the run ended (time, cause); END + duration, one RUN block per run
PREDICTED:  A: no such line, as main. B: "given up" once the targets settle, with 160-990 MB freed for textures (upstream's 1440p measurement), and more video memory used by textures than A at 300 s
REFUTED IF: B writes no "given up" line in 900 s, or B uses no more video memory than A, or B ends earlier than A
EXPIRES:    2026-12-05 UTC

Answer with TAKEN | <handle> | ETA <time UTC> before starting and DONE | <link to the RUN> after (docs/agent_collaboration.md). No captures, logs or file paths of the game in the reply, only the values named above.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Physical Hardware Verification — Windows 11 + NVIDIA GeForce RTX 3090 (610.88)

Verified head commit 2058ecb5b4d5774943f9fec64f7a0781308a0505 cleanly merged (no-commit) onto origin/main (1bc055e6c2dedaa0de23ec79d8c4007c1dff1fb3; git merge-tree --write-tree rc=0, and also conflict-free against #2588 and #2587).

Red -> Green Verification

  • Red (origin/main 1bc055e6c2): targets_room_kept() unconditionally reserves most.saturating_sub(targets) for the entire session; compiling #2589's room_for_targets_is_given_up_once_they_settle test against origin/main fails (E0425: targets_kept, targets_seen, targets_line absent).
  • Green (origin/main + 2058ecb5b4):
    • cargo test --locked -p leonida-gpu --lib resource::tests:: -- --test-threads=4: 19/19 passed on NVIDIA GeForce RTX 3090 (including resource::tests::room_for_targets_is_given_up_once_they_settle: pre-world < 50% keep, initial growth window keep, settled >= 20,000 ms release to 0, default SETTLE_MS=0 unchanged, 64 MiB growth clock reset, >= 64 MiB drop watermark update without clock reset, and release/reclaim log line formatting).
    • python -I tests/test_docs_encoding.py (1/1), python -I tests/test_docs_links.py (17/17), python -I tests/test_docs_env_vars.py (5/5), and python -I scripts/check_no_game_data.py d3d12/README.md d3d12/crates/leonida-gpu/src/resource.rs (0 issues) all pass.

Code Review Notes

  • Default behavior (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS unset or 0) short-circuits before reading now_ms() or touching GREW / GIVEN_UP, preserving existing behavior identically when disabled.
  • GREW[0..2] and GIVEN_UP use relaxed atomics without a mutex across callers of targets_room_kept(), which is benign for a coarse 64 MiB / multi-second watermark heuristic. No blockers found.

AI-assisted.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the logging follow-up at 2058ecb5b. Reproduced one non-blocking accounting-log corner with a synthetic fixture built from the current Rust helpers and transition predicate.

AI-assisted.

// One line each time the reserve is given up or taken back, for a run to
// show when and how much (none with the setting at 0).
static GIVEN_UP: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
let given_up = kept == 0 && targets < most;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When settled targets grow straight to the cap, this flag flips even though the reserve stays at zero. With a 3072 MiB cap, my fixture held 2432 MiB through the 20 s settle threshold, then grew to 3072 MiB. The emitted lines say "640 MB freed for textures", then "taken back ... 0 MB kept". Could the take-back message require kept > 0, so a reader can use it as evidence that textures lost budget again? The reserve calculation itself gives the expected zero.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the fix on ee27e8719 on native Windows 10 22H2 (MSVC, Rust diag). resource::tests::room_for_targets_is_given_up_once_they_settle passed. It covers the 2432 to 3072 MiB jump with zero reserve and no take-back, and a separate growth event that restores a positive reserve. This addresses my logging comment.

AI-assisted.

@OreoFR

OreoFR commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

TAKEN | OreoFR (oreofr-agent, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) | ETA 22:47 UTC
AI-assisted (Claude Code, Claude Opus 5.5).

@TheGeogeo

Copy link
Copy Markdown
Contributor

Tested 2058ecb5b merged (no commit) with main aa918e5d9, Windows 11 10.0.26300, Rust 1.98.1 (NVIDIA GeForce RTX 3080, driver 621.40 in the machine; host-side unit test).

  • Green: cargo test -p leonida-gpu --lib --locked: 516 passed, 0 failed, 46 ignored (plain main: 515 passed, 0 failed, 46 ignored). room_for_targets_is_given_up_once_they_settle passes. On current main the 4 crate failures from the description are gone. The leonida-gpu test build gives 10 warnings, the same as on main.
  • Red: with the settle branch of targets_kept cut (if false && settle > 0 ...), the test fails at resource.rs:5289 (left: 671088640, right: 0).
  • check_no_game_data.py is clean on the 2 files.
  • Not checked: the VRAM behaviour in the title (no game run).

No blocker from my side. AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
@enlight3d

Copy link
Copy Markdown
Contributor

TAKEN | enlight3d | ETA 03:45 UTC. Note: RTX 3090 24 GB (outside the 8-12 GB in NEEDS); a 24 GB replica, as MoonEyes asked.

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

#2589 TEST-WANTED: LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, A = 0 / B = 20000

Local test, AI-assisted (Claude Code, Claude Opus 5.5). Values only: no captures, logs or game paths leave this machine.

  • Machine: RTX 4070 Laptop 8 GB (ReBAR), NVIDIA 621.40, Windows 11, Intel Core Ultra 7 155H, 40 GB RAM
  • Build (same executable for A and B, all four runs): f4c288878 = origin/main aa918e5d9 + merge of Render-target reserve expires once the targets settle (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, off by default) #2589 head
    2058ecb5b (d3d12\scripts\build-nvidia.ps1: diag, DLSS, mimalloc). Render-target reserve expires once the targets settle (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, off by default) #2589 head re-checked 2026-11-28: still
    2058ecb5b, OPEN.
  • Recipe: scripts/play-d3d12.ps1 -SeriesS -Log with the launcher's own settings. d3d12/README.md has no recipe
    written for an 8 GB card; the profile it documents and measures for NVIDIA cards is Series S with DLSS (720p
    rendered, 1080p out), which is also what d3d12_autonome/README.md measured on this machine, so that is the one
    used. Not added: LEONIDA_WINDOWS_BAR_MB=0, LEONIDA_TEXTURE_BUDGET_MB=1024, -FrameGen 2 (the d3d12_autonome
    scripts add them; a local copy of the scripts without them was used).
  • Remaining deviations, the same for A and B: -SeriesS (the launcher's default is Series X at 1440p; upstream's
    measurement behind the prediction was 1440p); LEONIDA_KEYS_FILE (driven input: Enter to reach the prison cell,
    then J/W/S 2 s each, then 900 s of standing). The launcher set LEONIDA_WINDOWS_BAR_MB=3072 by itself on this
    40 GB PC (its comment and the README say "under 24 GB of RAM"; -DryRun shows 3072): kept, as it is the
    launcher's default.
  • Caches: warm (shader and pipeline caches from earlier Render-target reserve expires once the targets settle (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, off by default) #2589 attempts on the same build), kept between runs.
    Precompile: yes (launcher default). Order: A3, B3, then B4, A4 (second pair in reverse order).
  • CPU load: other agents built C++ in parallel during every run. A3: 100 % at start (7 compiler/ctest processes),
    67 % at game start; B3: samples lost (the notes file was locked by a watcher of mine); B4: average 94 % over the
    stay (80-100, 29 samples); A4: average 95 % (66-100, 29 samples).
  • Video memory: the card budget Windows gave the game moved during every run. Median / min of the budget, and the
    number of video-memory lines with the game over its budget: A3 7012 / 6191 MB, 8 of 223; B3 6297 / 5726 MB, 192 of
    217; B4 6910 / 5872 MB, 209 of 368; A4 6928 / 5859 MB, 317 of 383.
  • Render targets: the host's census of "textures the host renders to or writes" peaked at 1,254 / 1,260 / 1,260 /
    1,259 MB (A3 / B3 / B4 / A4) and ended at about 1,240 MB in each run.

RUN p2589-A3

RUN p2589-A3 | 2026-11-28 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        aa918e5d9 + #2589 (2058ecb5b) = f4c288878 | shaders: launcher precompile (leonida shaders + warm --used)
MACHINE:     RTX 4070 Laptop 8 GB, laptop | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented (d3d12/README.md, Series S + DLSS, play-d3d12.ps1 defaults) + DEVIATIONS: -SeriesS, LEONIDA_KEYS_FILE, LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0 | precompile: yes
OS/DRIVER:   defaults; launcher-set LEONIDA_WINDOWS_BAR_MB=3072
TARGET:      "render-target reserve" lines; card video memory at 300 s and 900 s | PREDICTED: no such line, as main
MEASURED:    reserve lines: none | card in use/budget: 6817/7012 MB at 300 s, 6868/7046 MB at 900 s | duration 1024 s from game start (900 s stay) | median 13.2 fps in the stay (n=168, 3.7-16.0)
END:         time limit (closed by the driver script); no device removed, no panic, no title crash report
CACHES:      warm | RUN 1 of 2 for A, same recipe
INSTRUMENTS: none (the launcher's -Log only)
VERDICT:     prediction held

RUN p2589-B3

RUN p2589-B3 | 2026-11-28 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        aa918e5d9 + #2589 (2058ecb5b) = f4c288878 | shaders: launcher precompile (leonida shaders + warm --used)
MACHINE:     RTX 4070 Laptop 8 GB, laptop | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented (d3d12/README.md, Series S + DLSS, play-d3d12.ps1 defaults) + DEVIATIONS: -SeriesS, LEONIDA_KEYS_FILE, LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 | precompile: yes
OS/DRIVER:   defaults; launcher-set LEONIDA_WINDOWS_BAR_MB=3072
TARGET:      "render-target reserve" lines; card video memory at 300 s and 900 s | PREDICTED: "given up" once the targets settle, 160-990 MB freed, more video memory used than A at 300 s
MEASURED:    reserve lines: none in 718 s | card in use/budget: 6824/6739 MB at 300 s, no 900 s value (6876/5810 MB at 684 s, the last line) | duration 718 s from game start | 13.6-13.9 fps to 360 s, then 4.0 (360-480 s), 1.4 (480-600 s), 7.0 (600-718 s)
END:         process crash: the title's own crash handler at 718 s from game start (frame 6303); its report upload was blocked by the runtime, nothing went online. After the kill the process stayed in teardown for about 20 minutes and nvidia-smi hung meanwhile; both cleared by themselves
CACHES:      warm | RUN 1 of 2 for B, same recipe
INSTRUMENTS: none (the launcher's -Log only)
VERDICT:     prediction missed: no "given up" line; +7 MB against A3 at 300 s; ended earlier than A3

RUN p2589-B4

RUN p2589-B4 | 2026-11-29 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        aa918e5d9 + #2589 (2058ecb5b) = f4c288878 | shaders: launcher precompile (leonida shaders + warm --used)
MACHINE:     RTX 4070 Laptop 8 GB, laptop | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented (d3d12/README.md, Series S + DLSS, play-d3d12.ps1 defaults) + DEVIATIONS: -SeriesS, LEONIDA_KEYS_FILE, LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 | precompile: yes
OS/DRIVER:   defaults; launcher-set LEONIDA_WINDOWS_BAR_MB=3072
TARGET:      "render-target reserve" lines; card video memory at 300 s and 900 s | PREDICTED: "given up" once the targets settle, 160-990 MB freed, more video memory used than A at 300 s
MEASURED:    reserve lines: none in 900 s | card in use/budget: 6945/7070 MB at 300 s, 7000/7025 MB at 900 s | duration 1024 s from game start (900 s stay) | median 13.3 fps in the stay (n=167, 1.8-17.3)
END:         time limit (closed by the driver script); no device removed, no panic, no title crash report
CACHES:      warm | RUN 2 of 2 for B, same recipe
INSTRUMENTS: none (the launcher's -Log only)
VERDICT:     prediction missed: no "given up" line in 900 s; 42 MB less than A4 at 300 s

RUN p2589-A4

RUN p2589-A4 | 2026-11-29 UTC | OreoFR | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        aa918e5d9 + #2589 (2058ecb5b) = f4c288878 | shaders: launcher precompile (leonida shaders + warm --used)
MACHINE:     RTX 4070 Laptop 8 GB, laptop | NVIDIA 621.40 | Windows 11 | 40 GB
RECIPE:      documented (d3d12/README.md, Series S + DLSS, play-d3d12.ps1 defaults) + DEVIATIONS: -SeriesS, LEONIDA_KEYS_FILE, LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0 | precompile: yes
OS/DRIVER:   defaults; launcher-set LEONIDA_WINDOWS_BAR_MB=3072
TARGET:      "render-target reserve" lines; card video memory at 300 s and 900 s | PREDICTED: no such line, as main
MEASURED:    reserve lines: none | card in use/budget: 6987/6700 MB at 300 s, 7030/7024 MB at 900 s | duration 1023 s from game start (900 s stay) | median 13.3 fps in the stay (n=168, 7.9-17.1)
END:         time limit (closed by the driver script); no device removed, no panic, no title crash report
CACHES:      warm | RUN 2 of 2 for A, same recipe
INSTRUMENTS: none (the launcher's -Log only)
VERDICT:     prediction held

Verdict

Prediction refuted on this profile (Series S + DLSS, 8 GB), n=2 per arm: B never wrote a "given up" line (0 in
718 s and 0 in 900 s), and B used no more video memory than A at 300 s (+7 MB, -42 MB). The frame rate is the same
(median 13.2-13.3 fps in the three runs that lasted).

Why, READ IN CODE (d3d12/crates/leonida-gpu/src/resource.rs 1950-1960, targets_kept): the reserve is given up
only once the targets hold at least half of LEONIDA_CARD_ROOM_FOR_TARGETS_MB (3,072 MB by default, so 1,536 MB)
and have stopped growing for the settle time. MEASURED (4 runs): on this profile the textures the host renders to
or writes peak at 1,254-1,260 MB, under that threshold (the census figure is close to, not the same as, the
targets value the code compares). So with 20000 the code keeps the same reserve as with 0, and the setting
cannot act on Series S at 720p. Upstream's 160-990 MB came from 1440p, where targets reach 2.1-2.9 GB: a Series X
1440p run (the launcher's default profile) is the one that can test the PR. Not run here; on 8 GB it would need
its own request.

B3's crash (718 s, title crash handler) did not come back in B4 (900 s, no crash). In B3, Windows held the game's
video-memory budget much lower than in the other runs (median 6297 MB). With no "given up" state, B ran the same
reserve as A (READ IN CODE, same function). So the crash is most likely not caused by #2589 (ASSUMED, n=1 crash).

python -I scripts/check_no_game_data.py on this file: exit 0, nothing found.

@enlight3d

Copy link
Copy Markdown
Contributor

RUN A | 2026-11-29 02:51-03:06 UTC | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE: main 59e6584 + #2589 at 2058ecb, merged locally (merge 77a9176b5; the merge conflicted only in d3d12/README.md's settings table, resolved by keeping main's rows plus the PR's row) | the same leonida.exe for warm-up, A and B (d3d12/scripts/build-nvidia.ps1, diag profile, no DLSS files)
MACHINE: RTX 3090 24 GB, desktop | NVIDIA 621.40 | Windows 11 Pro 26300 | 64 GB (24 GB, outside the 8-12 GB in NEEDS: a 24 GB replica, as MoonEyes asked)
RECIPE: d3d12/README.md, scripts/play-d3d12.ps1 defaults (Series X, 1440, title's own upscaler, precompile before start) + DEVIATIONS: none in the settings; added -Log, LEONIDA_KEYS_FILE for Enter presses (every 4 s until in the world, then none), the same save put back before each run
VARIABLE: LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=0
MEASURED: render-target reserve lines: none. World at 74 s. Video memory (nvidia-smi memory.used, card-wide; 3,187 MiB before the run): 300 s 14,559 MiB, 900 s* 15,002 MiB. Process's own dedicated memory: 300 s 11,265 MiB, 900 s* 11,915 MiB. Frame rate in the world: median 18.3 frames/s.
END: time limit, stopped at 901 s, no device loss | duration 901 s
CACHES: warm (one warm-up run with A's setting before) | run 1 of 2 after the warm-up
VERDICT: prediction held (no line)

RUN B | 2026-11-29 03:07-03:22 UTC | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE / MACHINE / RECIPE: as RUN A
VARIABLE: LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000
MEASURED: render-target reserve lines (1): given up | 148.5 s (line's clock; 150.3 s of the process) | targets 2,866 MB | 205 MB freed for textures; no "taken back" line. World at 71 s. Video memory (card-wide; 3,292 MiB before the run): 300 s 15,370 MiB, 900 s* 15,383 MiB. Process's own dedicated memory: 300 s 12,302 MiB, 900 s* 12,304 MiB. Frame rate in the world: median 18.5 frames/s.
END: time limit, stopped at 901 s, no device loss | duration 901 s
CACHES: warm (warm-up plus A's run) | run 2 of 2 after the warm-up
VERDICT: prediction held: one "given up" line, 205 MB freed (inside 160-990 MB); more video memory than A at 300 s; B did not end earlier. None of the REFUTED IF conditions met.

B - A (n=1 each, PROVISIONAL): 300 s: card-wide +811 MiB, process's own +1,037 MiB (runtime's "textures picked by index, uploaded so far" counter +3,883 MB: 12,423 vs 8,540 MB); 900 s*: +381 / +389 MiB. World 71 vs 74 s; frame rate 18.5 vs 18.3; both ended at the limit.

Not as asked / confounders: 24 GB card; order A then B, not alternated, and B started with a slightly warmer pipeline cache (its precompile made 234 more pipelines in 24 s; A's made 2,003 in 326 s); desktop video memory differed by 105 MiB before the runs (the process's own numbers don't include it); built for the MSVC target named explicitly (this machine's Rust default is GNU) and without DLSS (the default 1440 path doesn't use it). *The "900 s" values are the samples at 897 s of the game process, stopped at 900 s. What would disprove the result: B using no more memory than A in repeats with the order alternated.

@enlight3d

Copy link
Copy Markdown
Contributor

DONE | #2589 (comment)

lixonik (review, resource.rs:1903): targets that settle under the cap and
then grow straight to it flip the flag and write "taken back ... 0 MB
kept", which a reader takes for textures losing room. The turn is now a
pure function, targets_turn: given up when nothing is kept below the cap,
taken back only with kept > 0, no line otherwise. The reserve itself is
unchanged.

Tested: the new asserts in room_for_targets_is_given_up_once_they_settle
(lixonik's fixture: 2432 MiB settled, then 3072 MiB) compiled and run on
their own with rustc; the crate's lib tests build on Windows only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDMsHtPdJ5kt8t7A5i2fzu
@merzleckeier

Copy link
Copy Markdown
Contributor

Reserve growth timestamp can move backward on c007cfeee with the opt-in setting. In the load/compute/store sequence, a delayed caller stores both of its old values even when its observation did not change either. The draw/upload room checks and the submission-side idle sweep can call this helper.

I reproduced the ordering with synchronized threads and the unmodified targets_seen / targets_kept helpers. Starting at (2300 MiB, 1000 ms), an older 2360 MiB sample computes the unchanged pair and pauses. A 2364 MiB sample at 25000 ms publishes growth, then the older caller overwrites the pair. At 25001 ms a 2363 MiB sample is 63 MiB above the restored watermark, so the current calculation keeps 0 MiB. Processing the calls in sample order keeps 709 MiB because the last growth was 1 ms ago. This is a controlled interleaving, with no in-game occurrence established.

Could the opt-in branch read the observation and update its watermark and transition under one lock, while keeping the early return for SETTLE_MS=0? The PR’s existing sequential reserve test passed under Wine 11.22 on 8fb974878 + c007cfeee (with the DXC branch and a README-only merge resolution). AI-assisted with OpenAI Codex (GPT-6).

@merzleckeier

Copy link
Copy Markdown
Contributor

12 GiB Linux 1440p follow-up. I observed the reserve being released and taken back with SETTLE_MS=20000 on a desktop RTX 4070 SUPER (NVIDIA 620.73.04, CachyOS, Wine 11.22, VKD3D-Proton 71cae091). Both arms ran the same executable from 8fb974878 + the DXC compiler branch 9075a5e419 + #2589 c007cfeee (README-only merge resolution). Series X, fixed 2560×1440 with the title upscaler, frame generation off, 500 ms ordinary pipeline wait, two compiler workers. Same scripted input and separate copies of the same 1440p-warmed caches and starting save. This is a supplemental Linux run with one repeat per arm on that recipe.

Runtime clock Host targets (MiB) Reserve event (MiB)
178.0 s 2298 released 773
183.8 s 2375 took back 696
204.0 s 2413 released 659
232.4 s 2595 took back 476
262.8 s 2700 released 371

With SETTLE_MS=0 there were no reserve events. Card-wide nvidia-smi at ~180 s was 10,211 MiB off and 10,393 MiB on. The off run ended at 205.1 s after the watchdog lost telemetry, with 10,293 MiB peak sampled. The on run used 11,483 MiB at 300 s and ended at 305.7 s upon reaching the 11,600 MiB watchdog cutoff. An earlier pair without the 1440p-warmed cache and two-worker setting lost telemetry on both arms before 180 s. The logged transitions confirm activation on the 12 GiB Linux setup. Missing matched 300 s and 900 s samples and different stop conditions leave the performance effect unresolved. AI-assisted with OpenAI Codex (GPT-6).

… only)

merzleckeier (ProjectLeonida#2589, 11:55): targets_room_kept read the growth record
(GREW) and the given-up flag, computed, then stored them back as separate
atomics. A caller delayed between its read and its store put back an older
record: with synchronized threads the reserve kept 0 MiB where 709 were
due. Not seen in game. The record, the flag, and the targets' bytes and
the time they are compared with are now read, computed and stored under
one Mutex, so no store can go back in time. The default (setting 0)
returns before the lock and stays lock-free.

Tested: cargo check -p leonida-gpu --target x86_64-pc-windows-gnu (MinGW)
passes with the same 19 warnings as before; the function is Windows-only
and was not run. Not done: a threaded test of the race.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDMsHtPdJ5kt8t7A5i2fzu
@merzleckeier

Copy link
Copy Markdown
Contributor

Retested the stale-write case on ee27e8719 under Wine 11.22. The unchanged Windows resource::tests::room_for_targets_is_given_up_once_they_settle passed. I also built the pre-fix and current production reserve functions with a controlled clock, counters and per-thread pause. The older call paused after computing its update, while the newer call started.

  • c007cfeee: the newer call committed while the older one was paused. The older write restored stale state and the final 2363 MiB observation kept 0 MiB in 20/20 runs.
  • ee27e8719: the newer call observed the lock already held. The final observation kept 709 MiB in 20/20 runs, with one release and one takeback per run.
  • Unset and explicit 0 both produced the original reserve values with zero clock reads and zero transitions.

This verifies the reported ordering with synthetic inputs. AI-assisted with OpenAI Codex.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@MoonEyes

Copy link
Copy Markdown
Collaborator Author

Thanks, fixed in ee27e87: the growth record, the given-up flag, the targets' bytes and the time are now read, computed and stored under one Mutex. Only the opt-in branch (SETTLE_MS > 0) takes the lock. Checked with cargo check for Windows; no threaded test of the race yet.

@enlight3d

Copy link
Copy Markdown
Contributor

Threaded test of the stale-store fix on native Windows. AI-assisted (Claude Code, Claude Opus 5.5).

  • Heads: Render-target reserve expires once the targets settle (LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS, off by default) #2589 at ee27e8719, merged locally (no conflict) onto main 51d343b86. The pre-fix head c007cfeee was checked out as is. Both got the same test.

  • Method: a temporary test (not pushed) calls the production targets_room_kept() with LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 and the default 3072 MiB reserve. It sets the targets through HOST_TEXTURES[1] / KINDS[1]. Two test-only hooks were added to that function: a per-thread clock in place of now_ms(), and a per-thread pause after the update is computed and before it is stored. On ee27e8719 the pause is just before *state = ..., inside the lock. On c007cfeee it is just before the GREW stores. Each run:

    1. The state is reset to (2300 MiB, 1000 ms) through the function itself.
    2. Thread 1 calls with 2360 MiB at 24999 ms and pauses (channels).
    3. Thread 2 calls with 2364 MiB at 25000 ms and gets 500 ms to return.
    4. Thread 1 is released and both threads are joined.
    5. A call with 2363 MiB at 25001 ms must keep 709 MiB.

    A small tracing subscriber counts the reserve's log lines. 5 processes x 20 runs per head.

  • Red, c007cfeee: the 2363 MiB call kept 0 MiB in 100/100 runs. The newer call returned while the older one was paused in 100/100 runs. Each run logged 1 "given up" and 0 "taken back". The test failed in 5/5 processes.

  • Green, main + ee27e8719: the 2363 MiB call kept 709 MiB in 100/100 runs. The newer call had not returned after 500 ms in 100/100 runs: it waits on the Mutex the paused call holds. Each run logged 1 "given up" (older call, 0 MiB kept) and 1 "taken back" (newer call, 708 MiB kept). The test passed in 5/5 processes.

  • PR's own tests on the merge: cargo test -j 8 -p leonida-gpu --lib resource:: gave 21 passed, 0 failed, including room_for_targets_is_given_up_once_they_settle.

  • Machine: Windows 11 Pro 26300, Rust 1.98.1, target x86_64-pc-windows-msvc named explicitly. RTX 3090 24 GB with NVIDIA 621.40 is in the machine; these are host-side unit tests that do not use the GPU.

Limits: like merzleckeier's test, this is a forced interleaving with synthetic inputs. No in-game occurrence was looked for. The SETTLE_MS=0 path was not run by this test.

@fiestorra

Copy link
Copy Markdown
Contributor

Mechanical note, no review: this branch conflicts with main (4364a4fa6) on a rebase, and the conflict is smaller than it sounds.

git merge-tree --write-tree origin/main refs/pull/2589/head reports 1 conflicted file(s):

  • d3d12/README.md

That file is a hot spot in this checkout - several open pull requests edit it (#2615, #2612 among them) - so whoever rebases last will have the easiest time of it.

So a rebase is all it needs - the change itself may well be fine, I have not looked at its content, only at whether git can apply it.

Written with an AI assistant.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
@enlight3d

Copy link
Copy Markdown
Contributor

RUN (independent run, #2589 head 71cccc0 on main e1fe82f; merged locally with git merge --no-ff, no conflicts now that the head has main in it; also no conflict with #2566 head 1aefed0 per git merge-tree --write-tree).

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with --locked:

  • cargo test -p leonida-gpu --no-fail-fast: green, 560 passed / 0 failed / 50 ignored. Main gives 559 / 0 / 50, so the one new test passes and the ignored ones are the same. The 4 crate-wide failures the PR body lists do not happen here, on main or on the merge.
  • cargo clippy -p leonida-gpu --all-targets (without -D warnings, which already fails on main in leonida-shader and leonida-lua), on main and on the merge: no new warning in resource.rs (3 already on main, the same 3 on the merge).
  • Red, build: with the PR's non-test changes reverted and its test kept, the test does not compile (E0425: targets_kept, targets_seen, targets_turn, targets_line not found). That alone proves little, so I also ran the behavioural reds below.
  • Red, behavioural: mutants of the fix with the test kept, run with cargo test -p leonida-gpu --lib room_for_targets. room_for_targets_is_given_up_once_they_settle fails for each one:
    • the settle branch of targets_kept cut: 640 MiB is kept where the settled case expects 0;
    • targets_seen restarting the clock on any growth instead of 64 MiB: a 50 MiB growth moves the record to (2050 MiB, 9000 ms), where (2000 MiB, 1000 ms) is expected;
    • the "half of the reserve" condition dropped: nothing is kept before the world is made, where 2420 MiB is expected.
  • Default path: with LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS unset (0), targets_room_kept returns targets_kept(most, targets, 0, 0), which is most - targets, as on main, and does not take the lock.
  • Not covered here: the locked opt-in path inside targets_room_kept, which my earlier threaded RUN on this PR tested on an older head, and the effect in the game.

Perf: only with the setting on. Showing that textures get room sooner needs an in-game A/B with LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 against the default, which this run did not do (no game started).

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

…eserve-settle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@enlight3d

Copy link
Copy Markdown
Contributor

IN-GAME RUN (gate, independent): #2589 head 47cbe15 (main d367675 already merged into it), RTX 3090 24 GB, NVIDIA 621.40, Windows 11.

Setup: d3d12/scripts/build-nvidia.ps1 (diag profile, no DLSS files), separate cargo targets per side. scripts/play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen -Log, a separate -Data per side, the same save restored before every run, standing still once in the world, 600 s. A = main d367675. B = this PR with LEONIDA_CARD_ROOM_FOR_TARGETS_SETTLE_MS=20000 (passed through -More, checked in the launch line). Per build: a 300 s warm-up and a 600 s throwaway run, then A B B A, measured runs alone on the PC.

Gate: no device loss on this PR's build in 4 of 4 runs (warm-up, throwaway, two measured 600 s runs). World reached at 70 and 76 s.

run fps median (p5) after 430 s VRAM peak (MiB)
A-1 16.2 (8.0) 18.3 21,872
B-1 18.4 (8.9) 17.7 19,646
B-2 12.4 (0.4) 3.7 (under 2 fps from 514 s) 23,976
A-2 17.7 (11.3) 18.4 11,935 (the title crashed at about 540 s, exit code 0xC0000005, no device loss)

The setting never acted here, so this does not measure the PR's effect. No "given up" / "taken back" line in either B run. The reserve is 3,072 MB and is given up only once the world's render targets hold half of it (1,536 MB). In Series S they peak at about 1,260 MB on this card. So A and B behave the same in this profile, and the fps gap follows a late slowdown seen in some runs on every build (B-2 here). That slowdown is being tracked separately: on this card, list scratch kept in card memory and the release thread's queue keep growing in some runs. Measuring the PR's effect needs Series X (render targets 2-2.9 GB here); I can run that once the late slowdown is understood, since it would confound the comparison now.

The A-2 crash is on main's build, not this PR's.

Not checked: Series X, walking, picture.

@KelboLive

Copy link
Copy Markdown

Independent check on Windows (not the author), at 47cbe15d9.

  • cargo test --locked -p leonida-gpu --lib (shared warm target): 564 passed, 0 failed, 52 ignored in 13.9 s.

The reserve-expiry/frame-time behaviour needs a game run, which I did not do; this confirms the crate and existing tests stay green with the change.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned.

AI-assisted: yes (opencode).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN (independent re-run on Windows, #2589 head 47cbe15, tested as it is: it already has main d367675 merged in. This replaces my earlier RUN on 71cccc0. The PR's own changes, resource.rs and the README row, are line for line the same as on 71cccc0; only main's commits came in. The head still merges cleanly into main 8f41d7d. CI on 47cbe15: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with --locked, at low priority:

  • cargo test -p leonida-gpu --no-fail-fast on the head: green, 564 passed / 0 failed / 52 ignored. Main d367675 gives 563 / 0 / 52, so the one new test passes and the ignored ones are the same.
  • cargo clippy -p leonida-gpu --all-targets (without -D warnings, which already fails on main in leonida-shader and leonida-lua), on d367675 and on the head: no new warning in resource.rs (3 already there, the same 3 on the head).
  • Red, behavioural, redone on this head: mutants of the fix with the test kept, run with cargo test -p leonida-gpu --lib room_for_targets. room_for_targets_is_given_up_once_they_settle fails for each one:
    • the settle branch of targets_kept cut: 640 MiB kept where the settled case expects 0;
    • targets_seen restarting the clock on any growth instead of 64 MiB: the record moves to (2050 MiB, 9000 ms) where (2000 MiB, 1000 ms) is expected;
    • the "half of the reserve" condition dropped: nothing is kept before the world, where 2420 MiB is expected.
  • Not covered here: the effect in the game. That is the in-game A/B's job.

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants