[pr-performance][memory] Reduce texture heap granularity and reclaim more under host pressure #345

Open
MuoM1ng wants to merge 1 commit from MuoM1ng/Darner:codex/darner-texture-pressure into main
First-time contributor

Contributor role (optional)

What it changes

On v2026.12.03.02, the device-local texture pools allocate 64 MiB heaps. A heap can only be returned after its last piece leaves. This means a few long-lived allocations can retain mostly empty heaps.

This ports the texture heap and host pressure changes from VIctory-NVIDIA #4890. On PCs with under 24 GiB of RAM, the general device-local texture pool prefers 16 MiB heaps. The separate small-placement pool prefers at most 8 MiB heaps. Larger textures retain the original on-card size range, so shrinking the preferred heap does not send those textures to shared memory. Parking limits and diagnostics charge the actual heap size. Texture eviction starts earlier under host pressure and the staging pools retain fewer idle buffers. The sampled-slot check can pick up evicted textures sooner when they come back into use. Existing loose-window hits can return under the shared lock.

DARNER_TEXTURE_BLOCK_MB sets the preferred device-local heap size from 4 to 64 MiB. DARNER_SAMPLED_IDLE_MS sets the sampled-eviction idle floor outside emergency trimming.

How it was tested

  • Revision 2714164 on v2026.12.03.02 and main f3840d7.
  • Windows check passed with cargo check --offline --locked --profile diag -p darner --features diagnostics. cargo xtask policy checked 555 files.
  • In the integration checkout, which includes both ports and existing local changes, the filtered cargo test --offline --locked --profile diag -p darner-gpu --features diagnostics --lib run passed 79 tests with 3 ignored benchmarks. The filters covered pools, texture sampling and eviction, and frame generation.
  • The matching test binary's second run covered the menu, panel, overlay shader, packed present, and shadow windows. It passed 98 tests with 3 ignored benchmarks.
  • The GPU tests cover large-texture fallback, actual heap bytes, card headroom, pressure watermarks, spare budgets and sampled-slot cadence.
  • The preferred heap size and some pressure defaults change. Live gameplay A/B, hitch rate and peak memory have not been measured.
  • Full workspace gates were not run.

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.
  • Merged #151 already provides NVIDIA's 4 KiB placement. Its placement rule remains in use. #194 addresses free-range alignment and #332 concerns page-buffer heaps in system memory.
  • No equivalent open PR found.
## Contributor role (optional) ## What it changes On v2026.12.03.02, the device-local texture pools allocate 64 MiB heaps. A heap can only be returned after its last piece leaves. This means a few long-lived allocations can retain mostly empty heaps. This ports the texture heap and host pressure changes from VIctory-NVIDIA `#4890`. On PCs with under 24 GiB of RAM, the general device-local texture pool prefers 16 MiB heaps. The separate small-placement pool prefers at most 8 MiB heaps. Larger textures retain the original on-card size range, so shrinking the preferred heap does not send those textures to shared memory. Parking limits and diagnostics charge the actual heap size. Texture eviction starts earlier under host pressure and the staging pools retain fewer idle buffers. The sampled-slot check can pick up evicted textures sooner when they come back into use. Existing loose-window hits can return under the shared lock. `DARNER_TEXTURE_BLOCK_MB` sets the preferred device-local heap size from 4 to 64 MiB. `DARNER_SAMPLED_IDLE_MS` sets the sampled-eviction idle floor outside emergency trimming. ## How it was tested - Revision `2714164` on `v2026.12.03.02` and main `f3840d7`. - Windows check passed with `cargo check --offline --locked --profile diag -p darner --features diagnostics`. `cargo xtask policy` checked 555 files. - In the integration checkout, which includes both ports and existing local changes, the filtered `cargo test --offline --locked --profile diag -p darner-gpu --features diagnostics --lib` run passed 79 tests with 3 ignored benchmarks. The filters covered pools, texture sampling and eviction, and frame generation. - The matching test binary's second run covered the menu, panel, overlay shader, packed present, and shadow windows. It passed 98 tests with 3 ignored benchmarks. - The GPU tests cover large-texture fallback, actual heap bytes, card headroom, pressure watermarks, spare budgets and sampled-slot cadence. - The preferred heap size and some pressure defaults change. Live gameplay A/B, hitch rate and peak memory have not been measured. - Full workspace gates were not run. ## Checklist - [ ] 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. - Merged #151 already provides NVIDIA's 4 KiB placement. Its placement rule remains in use. #194 addresses free-range alignment and #332 concerns page-buffer heaps in system memory. - No equivalent open PR found.
First-time contributor

Independent Windows build, gate, and code-read review of e1d5be8af011 (full head e1d5be8af011b511c66d591468a8c8728839e666), based on main f3840d73d3504c30218debfbc8795b9225447317. Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS.
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS.
  • cargo xtask policy: PASS (asset policy: 555 files ok).
  • cargo test --locked -p darner-gpu --lib pool::: PASS (60 passed; 0 failed; 3 ignored).
  • cargo test --locked -p darner-gpu --lib sampled::: PASS (7 passed; 0 failed; 0 ignored).
  • cargo test --locked -p darner-gpu --lib texture_eviction_marks_follow_host_pressure: PASS (1 passed; 0 failed; 0 ignored).
  • cargo test --locked -p darner-gpu --lib shadow::: PASS (110 passed; 0 failed; 10 ignored).
  • Full workspace test gate (cargo test --workspace --locked) and gameplay were not run in this review.

Code-read audit

  • texture_block_size caches the 4–64 MiB setting once, uses the small-host default only when no valid override is supplied, and caps the separate placement pool at 8 MiB. Ripe::card_texture_block keeps allocations outside the chosen block's supported range on the original 64 MiB path (crates/darner-gpu/src/pool.rs:34-44, 406-417).
  • Card heap creation, headroom charging, pool byte totals, and park reporting now use actual heap sizes; take_headroom subtracts the requested size atomically, and parked heaps remain 64 MiB (pool.rs:1218-1228, 1491-1516, 2630-2650, 2942-2966).
  • Host pressure trims texture/staging spares and lowers slot-eviction watermarks; critical pressure shortens idle eligibility, while the sampled-eviction floor is bounded and bypassed for over-budget/critical trimming (pool.rs:67-80, 288-300; crates/darner-gpu/src/resource.rs:5701-5745, 5814-5825).
  • Sampled marks use the quicker cadence while slots are held or evicted, and the loose-window read path selects exact, longest-tail, or covering windows under the shared lock; the DARNER_WINDOW_TAKE=1 path skips the preliminary read lock so it can choose the longer existing window under the write lock (crates/darner-gpu/src/sampled.rs:233-246; crates/darner-gpu/src/shadow.rs:12891-12933).

CHANGES NEEDED — P2: With DARNER_TEX_PARK=1, first-upload admission calls park_has_room(reserve) (crates/darner-gpu/src/draw.rs:4936). The new allocation path can create a smaller card heap and charges its actual size (pool.rs:2634-2650), but park_has_room still requires CARD_HEADROOM >= BLOCK (64 MiB) before considering card growth (pool.rs:1426-1433). If only the selected 4–16 MiB heap's headroom is available and parked/shared memory and existing holes cannot fit the texture, admission rejects the upload even though the card allocation path can accept it. Please make the admission check account for the selected heap size and cover the less-than-64-MiB headroom case with a test.

The PR also changes default heap and host-pressure behavior, but its description says live gameplay A/B was not measured. CONTRIBUTING.md requires an A/B result for default behavior changes; that evidence is still needed before this can pass review. No runtime/gameplay evidence was collected here.

AI-assisted: yes (GitHub Copilot, Auto mode).

Independent Windows build, gate, and code-read review of `e1d5be8af011` (full head `e1d5be8af011b511c66d591468a8c8728839e666`), based on `main` `f3840d73d3504c30218debfbc8795b9225447317`. Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS**. - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS**. - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`). - `cargo test --locked -p darner-gpu --lib pool::`: **PASS** (`60 passed; 0 failed; 3 ignored`). - `cargo test --locked -p darner-gpu --lib sampled::`: **PASS** (`7 passed; 0 failed; 0 ignored`). - `cargo test --locked -p darner-gpu --lib texture_eviction_marks_follow_host_pressure`: **PASS** (`1 passed; 0 failed; 0 ignored`). - `cargo test --locked -p darner-gpu --lib shadow::`: **PASS** (`110 passed; 0 failed; 10 ignored`). - Full workspace test gate (`cargo test --workspace --locked`) and gameplay were not run in this review. ### Code-read audit - `texture_block_size` caches the 4–64 MiB setting once, uses the small-host default only when no valid override is supplied, and caps the separate placement pool at 8 MiB. `Ripe::card_texture_block` keeps allocations outside the chosen block's supported range on the original 64 MiB path (`crates/darner-gpu/src/pool.rs:34-44, 406-417`). - Card heap creation, headroom charging, pool byte totals, and park reporting now use actual heap sizes; `take_headroom` subtracts the requested size atomically, and parked heaps remain 64 MiB (`pool.rs:1218-1228, 1491-1516, 2630-2650, 2942-2966`). - Host pressure trims texture/staging spares and lowers slot-eviction watermarks; critical pressure shortens idle eligibility, while the sampled-eviction floor is bounded and bypassed for over-budget/critical trimming (`pool.rs:67-80, 288-300; crates/darner-gpu/src/resource.rs:5701-5745, 5814-5825`). - Sampled marks use the quicker cadence while slots are held or evicted, and the loose-window read path selects exact, longest-tail, or covering windows under the shared lock; the `DARNER_WINDOW_TAKE=1` path skips the preliminary read lock so it can choose the longer existing window under the write lock (`crates/darner-gpu/src/sampled.rs:233-246; crates/darner-gpu/src/shadow.rs:12891-12933`). **CHANGES NEEDED — P2:** With `DARNER_TEX_PARK=1`, first-upload admission calls `park_has_room(reserve)` (`crates/darner-gpu/src/draw.rs:4936`). The new allocation path can create a smaller card heap and charges its actual size (`pool.rs:2634-2650`), but `park_has_room` still requires `CARD_HEADROOM >= BLOCK` (64 MiB) before considering card growth (`pool.rs:1426-1433`). If only the selected 4–16 MiB heap's headroom is available and parked/shared memory and existing holes cannot fit the texture, admission rejects the upload even though the card allocation path can accept it. Please make the admission check account for the selected heap size and cover the less-than-64-MiB headroom case with a test. The PR also changes default heap and host-pressure behavior, but its description says live gameplay A/B was not measured. `CONTRIBUTING.md` requires an A/B result for default behavior changes; that evidence is still needed before this can pass review. No runtime/gameplay evidence was collected here. AI-assisted: yes (GitHub Copilot, Auto mode).
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 'codex/darner-texture-pressure:MuoM1ng-codex/darner-texture-pressure'
git switch 'MuoM1ng-codex/darner-texture-pressure'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'MuoM1ng-codex/darner-texture-pressure'
git switch 'MuoM1ng-codex/darner-texture-pressure'
git rebase 'main'
git switch 'main'
git merge --ff-only 'MuoM1ng-codex/darner-texture-pressure'
git switch 'MuoM1ng-codex/darner-texture-pressure'
git rebase 'main'
git switch 'main'
git merge --no-ff 'MuoM1ng-codex/darner-texture-pressure'
git switch 'main'
git merge --squash 'MuoM1ng-codex/darner-texture-pressure'
git switch 'main'
git merge --ff-only 'MuoM1ng-codex/darner-texture-pressure'
git switch 'main'
git merge 'MuoM1ng-codex/darner-texture-pressure'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 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!345
No description provided.