Skip to content

d3d12: attribute residency pressure using active thresholds - #2951

Open
NetZlash wants to merge 3 commits into
ProjectLeonida:mainfrom
NetZlash:fix/d3d12-residency-pressure-attribution
Open

NetZlash wants to merge 3 commits into
ProjectLeonida:mainfrom
NetZlash:fix/d3d12-residency-pressure-attribution

Conversation

@NetZlash

@NetZlash NetZlash commented Dec 1, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: D3D12-RESIDENCY-PRESSURE-ATTRIBUTION

What and why

The physical-only counter used the fixed 4 GiB commit entry threshold to attribute every pressured sample. A host that is already under pressure and has 6 GiB free physical memory and 5 GiB commit headroom stays under pressure due to commit. The old diagnostic counted that sample as physical-only.

Derive the pressure decision and the three diagnostic counts from the same physical and commit constraints. Entry still uses inclusive 3 GiB physical and 4 GiB commit thresholds. Retention still applies below 5 GiB physical or below 6 GiB commit. Each pressured sample now records one of three categories under the active thresholds: physical only, commit only, or both. For example, 1 GiB of free physical memory and 5.9 GiB of commit headroom counts as physical only at entry and as both during retention, making the physical constraint visible in both samples. The change is limited to attribution and its log wording. Admission decisions and memory budgets retain their original behavior.

Counts describe successful samples taken roughly once per second. Shorter spikes can fall between samples. The sweep reads commit headroom directly, and the separate critical-commit query uses a 32 ms cache and also considers recent allocation failures.

Tested

  • Red. Ran cargo test -p leonida-gpu --lib --locked residency::tests::physical_only_pressure_uses_the_active_thresholds -- --exact after a behavior-preserving extraction of the original predicate. Exit 101. The assertion for 6 GiB free RAM and 5 GiB commit headroom saw physical_only=true, with false expected.

  • Green. All four residency tests passed with default features and with diagnostics. The regression covers entry and retention, both constraints, physical-only and commit-only pressure, recovery, and single-byte boundaries. Existing admission and prefetch tests also pass.

  • cargo build --workspace --all-targets --locked passed. The original workspace regression run used --no-fail-fast, excluded xtask, and applied the documented depth_bounds_pipeline_loads_and_filters_draws skip. The leonida-gpu unit suite passed 644 tests.

  • On the synchronized branch, leonida-gpu passed 644 unit tests with the same depth-bounds skip (59 ignored). The four residency tests also passed again with diagnostics.

  • Five pre-existing workspace failures. All reproduced on clean upstream 1e3e316c5e7b072bc26a3e3ce78950b9fde84a43, the base of the original workspace run.

    • settings_line::a_run_logs_the_settings_it_starts_with failed with inherited RUST_LOG=warn. It passed on both revisions with RUST_LOG unset for the test process.
    • emit::barycentric_tests::a_masked_pixel_program_reads_the_position_where_the_vertex_program_writes_it
    • emit::barycentric_tests::first_half_values_render_on_hardware_and_warp
    • emit::rect::tests::rectangles_are_drawn_whole
    • emit::rect::tests::the_rectangle_stage_is_a_geometry_shader

    The four leonida-shader tests failed DXIL validation on both revisions with Container part 'Pipeline State Validation' does not match expected for module.

  • cargo test -p leonida-gpu --features diagnostics --test replay --locked -- --nocapture passed again on the synchronized branch. The synthetic D3D12 fixture recorded and replayed a frame with identical picture hashes.

  • All 24 game-gate Python tests passed. git diff --check and the repository-wide python -I scripts/check_no_game_data.py passed. An independent read-only review found no blocking issues.

  • Review follow-up 26da88e8 tested the counter update used by refresh() on a synthetic sample sequence. A mutation that recorded a physical-only sample as mixed made the new test fail. All four targeted tests passed with and without diagnostics after restoring the counter. This includes the reported low-RAM example, both hysteresis states and recovery.

  • The follow-up replay passed, and the 644-test GPU suite passed in both parallel and serial reruns with the same depth-bounds skip. The initial parallel follow-up run had two intermittent failures in unrelated descriptor and alias-cast tests. The reruns and a parallel run of the previously published head passed both cases.

GPUs tested: Windows 11 Pro x64 build 26200 host with an NVIDIA GeForce RTX 4070 SUPER and driver 621.40. Synthetic replay uses the default D3D12 adapter. The residency regression runs on the CPU. The tested scope is diagnostic attribution.

AI-assisted: Yes. GPT-6.2 Sol (gpt-6.2-sol) implemented and tested the change. GPT-6.2 Astra (gpt-6.2-astra) performed the independent read-only review.

Checklist

  • Based on upstream main at 1fff69129529c2f45d2e8f7524278ecefe291e0c and merges cleanly.
  • One topic. Follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in the quoted test output.

Use the active entry or retention thresholds for both the pressure decision and its physical-only diagnostic. Cover commit-only retention and exact boundaries with synthetic regression tests.
@andrew-ai

Copy link
Copy Markdown

Verified the physical-only counter on native Windows across full pressure transitions on base 1fff69129 and head 89d7808a3. A temporary test supplied synthetic values at the OS memory-status boundary and called the crate's actual refresh(). For each physical/commit pair, I tested entry from a recovered state and retention from a primed state. The grid includes the exact thresholds and their one-byte neighbors.

Replay result Base PR Expected
Successful samples 1,944 1,944 1,944
Under pressure 866 866 866
Physical memory alone 506 416 416
Critical commit 108 108 108

The base overcounted physical-only pressure by 90 in this synthetic sequence. Both trees matched the expected pressure flag, instantaneous headroom, low-water marks, and pressure/critical counts after every successful sample. After each of 648 injected failed reads, the pressure flag, sample count and physical-only count stayed unchanged. I found the old wording in historical findings but no other tracked literal consumer of that wording.

This verifies attribution without inducing real memory pressure. Claim in #2570. AI-assisted with OpenAI Codex (GPT-6).

@NetZlash

NetZlash commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks for running the Windows replay through refresh(). The matching pressure and critical-commit totals across 1,944 samples, together with the failed-read checks, extend the regression coverage to the refresh path. The head's physical-only count matches the expected 416, which supports the diagnostic attribution change. I appreciate the check for other consumers of the log wording.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Direction is right: next_pressure (residency.rs:180-190) fixes the 6 GiB free / 5 GiB commit mislabel, and using only .0 at :198 leaves admission behaviour unchanged — the boolean itself is the same expression, so this is attribution only.

Two things to adjust:

  1. The retention thresholds undercount severe physical pressure. Because physical_only uses the retention pair, physical = 1 GiB with commit = 5.9 GiB is labelled not physical-only — which is exactly the low-RAM shape in docs/findings.md:716 ("360–390 MB free … while 5.9 to 7.0 GB are left to commit"). It also means identical (physical, commit) samples are labelled differently on the entry sample vs later ones, and the label flips at exactly 6 GiB. Consider reporting physical-only / commit-only / both, or attributing against the entry thresholds, so the severe-physical case is not hidden.
  2. The counter wiring is untested. Changing if physical_only to if false && physical_only (:202) leaves all four residency tests green — the new test covers only the pure predicate. A refresh()-level assertion (or a seam for the sample) would pin it.

Sampling note: 1 Hz is fine for prevalence over minutes, but these counts are sample-seconds, not pressure episodes, and sub-second spikes are invisible; refresh() also samples commit directly while critical_commit() uses the 32 ms cache, so the two readings can disagree slightly. Worth a sentence in the body.

pipeline::/crate suite is 645/0/59 (the two diagnostics failures under --features diagnostics are the known parallel flakes, green alone). Merge with current main is clean, and #2929/#2658/#2765 are file-disjoint — host RAM/commit attribution vs adapter VRAM budgets, so no double counting.

@NetZlash

NetZlash commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks for pointing out the 1 GiB / 5.9 GiB case and the unchecked counter write. Commit 26da88e8 reports physical-only, commit-only and mixed samples. The severe physical case is visible at entry and during retention. A new test exercises the same counter update as refresh(), and redirecting the physical-only count to the mixed counter makes it fail. The PR description now covers sample cadence and the separate critical-commit cache.

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.

3 participants