pool, ahead: route reused pooled textures through DIRECT aliasing barrier and fence-gate piece rest #4714

Closed
github-bot wants to merge 2 commits from github-bot/gh-4713 into main AGit
Owner

@⁠nidea1 on GitHub · 2026-12-01 03:10 UTC · original
nidea1:fix/pool-reuse-aliasing-barrier → main · +281 −31 · 2 files · 2 commits · closed without merging

What it changes

Fixes two D3D12 placement-reuse hazards in crates/victory-gpu/src/pool.rs and crates/victory-gpu/src/texture/ahead.rs (keeping VICTORY_POOL_SMALL opt-in / unchanged by default):

  1. Reused pooled textures bypassed the DIRECT aliasing barrier via COPY-queue upload-ahead:

    • Reused pooled texture placements (again == true) previously took the VICTORY_UPLOAD_AHEAD COPY-queue upload path (texture/ahead.rs), which cannot emit D3D12_RESOURCE_BARRIER_TYPE_ALIASING and still marked staging.uploaded = true / copy.ahead = DONE. As a result, neither the COPY queue nor the subsequent DIRECT queue emitted an aliasing barrier before shader sampling (unlike DIRECT uploads in host.rs and texture.rs, which do emit aliasing barriers).
    • Tracks the reused flag on Reclaim COM private data (reused: AtomicBool, populated from again in give_back_to) and exposes pool::reused(&ID3D12Resource) (with balanced GetPrivateData AddRef/drop handling). texture::ahead::claim now checks pool_allows_ahead(pool::fresh, || pool::reused) so virgin placements keep using COPY-queue upload-ahead while reused placements fall back to DIRECT uploads where the aliasing barrier is emitted.
  2. Wall-clock-only REST cooldown could recycle in-flight ranges across long stalls:

    • Pool::reclaim() previously gated recycled pieces solely on wall-clock REST = 2500 ms without checking GPU submission retirement. During >2.5 s stalls (e.g., shader compilation), an in-flight range could become eligible for reuse before the GPU retired its submission.
    • Records host::submissions().0 when a piece is returned (give_at) and requires both ready <= now and submission <= host::submissions().1 in reclaim_at before recycling the range.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (--fg-type fsr --framegen 3), ray tracing off, VICTORY_SAMPLED_EVICT=1, VICTORY_WINDOW_GROW=1, VICTORY_AMBIENT=0.8, VICTORY_AMBIENT_SPECULAR=1.
  • Before: Reused pooled textures could be uploaded on the COPY queue with no aliasing barrier before sampling, and resting pieces could be reclaimed on wall-clock time alone before GPU submission retirement.
  • After:
    • Unit tests verify virgin vs reused tracking (including balanced COM private-data refcounting on D3D12), submission-retirement gating holding reuse past REST until retired, and texture::ahead skipping reused pooled textures while still claiming virgin placements.
    • Live visual checks with VICTORY_POOL_SMALL=1 + VICTORY_SAMPLED_EVICT=1 showed zero aliasing/foliage flicker across inspected frames (VICTORY_POOL_SMALL remains opt-in, as separate historical 4 KiB placement GPU fault risk on NVIDIA is out of scope here).
    • Full 12-minute (720.7 s in-world, 16,447 frames) uncontested live soak with VICTORY_POOL_SMALL=0 + VICTORY_RIPE_BLOCKS=12 (as part of our 14-branch local stack on 7d93ee0759) completed with 0 crashes, 0 device losses, 0 Victory errors, HERO LEAD = 0, UPLOAD OVER HOST WRITE = 0, and 0 >100 ms hitches in the final 8.7 minutes.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes)
  • cargo test passed for the crates it touches: yes (on 4512766c, base 7d93ee0759)
    • cargo test -j 2 -p victory-gpu --locked --lib pool::tests: 33 passed, 0 failed, 3 ignored (new: reused_flag_tracks_virgin_and_recycled_placements, resting_pieces_wait_for_submission_retirement_even_after_rest, reused_private_data_tracks_again_without_leaking_references)
    • cargo test -j 2 -p victory-gpu --locked --lib texture::ahead::tests: 9 passed, 0 failed (new: reused_pooled_textures_are_not_eligible_for_ahead_copy, reused_pooled_texture_is_skipped_by_ahead_claim)
    • cargo clippy -j 2 -p victory-gpu --all-targets --locked -- -D warnings and --all-features: 0 warnings on 7d93ee0759 (note: current main 5fabb46e has 5 pre-existing clippy errors in font.rs/menu.rs/panel.rs from #4634, tracked in #4679 / #4707).
    • cargo xtask policy: 464 files ok (--staged: 2 files ok).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4655, #3069, #4582
    • Checked #4654, #3069, #4581, #3711, #3766, #4636, and #4698; none route reused pooled textures off texture::ahead for the DIRECT aliasing barrier or fence-gate Pool::reclaim() on submission retirement. Hunks in pool.rs and texture/ahead.rs were kept minimal and disjoint from #4581 / #4654.
**@⁠nidea1** on GitHub · 2026-12-01 03:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713) `nidea1:fix/pool-reuse-aliasing-barrier` → `main` · +281 −31 · 2 files · 2 commits · closed without merging ## What it changes Fixes two D3D12 placement-reuse hazards in `crates/victory-gpu/src/pool.rs` and `crates/victory-gpu/src/texture/ahead.rs` (keeping `VICTORY_POOL_SMALL` opt-in / unchanged by default): 1. **Reused pooled textures bypassed the DIRECT aliasing barrier via COPY-queue upload-ahead:** - Reused pooled texture placements (`again == true`) previously took the `VICTORY_UPLOAD_AHEAD` COPY-queue upload path (`texture/ahead.rs`), which cannot emit `D3D12_RESOURCE_BARRIER_TYPE_ALIASING` and still marked `staging.uploaded = true` / `copy.ahead = DONE`. As a result, neither the COPY queue nor the subsequent DIRECT queue emitted an aliasing barrier before shader sampling (unlike DIRECT uploads in `host.rs` and `texture.rs`, which do emit aliasing barriers). - Tracks the reused flag on `Reclaim` COM private data (`reused: AtomicBool`, populated from `again` in `give_back_to`) and exposes `pool::reused(&ID3D12Resource)` (with balanced `GetPrivateData` AddRef/drop handling). `texture::ahead::claim` now checks `pool_allows_ahead(pool::fresh, || pool::reused)` so virgin placements keep using COPY-queue upload-ahead while reused placements fall back to DIRECT uploads where the aliasing barrier is emitted. 2. **Wall-clock-only `REST` cooldown could recycle in-flight ranges across long stalls:** - `Pool::reclaim()` previously gated recycled pieces solely on wall-clock `REST = 2500 ms` without checking GPU submission retirement. During >2.5 s stalls (e.g., shader compilation), an in-flight range could become eligible for reuse before the GPU retired its submission. - Records `host::submissions().0` when a piece is returned (`give_at`) and requires both `ready <= now` and `submission <= host::submissions().1` in `reclaim_at` before recycling the range. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): RTX 3060 Ti 8 GB / 32 GB RAM, Series S profile, DLSS Quality, FSR 3 frame generation (`--fg-type fsr --framegen 3`), ray tracing off, `VICTORY_SAMPLED_EVICT=1`, `VICTORY_WINDOW_GROW=1`, `VICTORY_AMBIENT=0.8`, `VICTORY_AMBIENT_SPECULAR=1`. - Before: Reused pooled textures could be uploaded on the COPY queue with no aliasing barrier before sampling, and resting pieces could be reclaimed on wall-clock time alone before GPU submission retirement. - After: - Unit tests verify virgin vs reused tracking (including balanced COM private-data refcounting on D3D12), submission-retirement gating holding reuse past `REST` until retired, and `texture::ahead` skipping reused pooled textures while still claiming virgin placements. - Live visual checks with `VICTORY_POOL_SMALL=1` + `VICTORY_SAMPLED_EVICT=1` showed zero aliasing/foliage flicker across inspected frames (`VICTORY_POOL_SMALL` remains opt-in, as separate historical 4 KiB placement GPU fault risk on NVIDIA is out of scope here). - Full 12-minute (`720.7 s` in-world, `16,447` frames) uncontested live soak with `VICTORY_POOL_SMALL=0` + `VICTORY_RIPE_BLOCKS=12` (as part of our 14-branch local stack on `7d93ee0759`) completed with `0` crashes, `0` device losses, `0` Victory errors, `HERO LEAD = 0`, `UPLOAD OVER HOST WRITE = 0`, and `0` `>100 ms` hitches in the final `8.7` minutes. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes) - `cargo test` passed for the crates it touches: yes (on `4512766c`, base `7d93ee0759`) - `cargo test -j 2 -p victory-gpu --locked --lib pool::tests`: 33 passed, 0 failed, 3 ignored (new: `reused_flag_tracks_virgin_and_recycled_placements`, `resting_pieces_wait_for_submission_retirement_even_after_rest`, `reused_private_data_tracks_again_without_leaking_references`) - `cargo test -j 2 -p victory-gpu --locked --lib texture::ahead::tests`: 9 passed, 0 failed (new: `reused_pooled_textures_are_not_eligible_for_ahead_copy`, `reused_pooled_texture_is_skipped_by_ahead_claim`) - `cargo clippy -j 2 -p victory-gpu --all-targets --locked -- -D warnings` and `--all-features`: 0 warnings on `7d93ee0759` (note: current `main` `5fabb46e` has 5 pre-existing clippy errors in `font.rs`/`menu.rs`/`panel.rs` from `#4634`, tracked in `#4679` / `#4707`). - `cargo xtask policy`: 464 files ok (`--staged`: 2 files ok). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4655, #3069, #4582 - Checked `#4654`, `#3069`, `#4581`, `#3711`, `#3766`, `#4636`, and `#4698`; none route reused pooled textures off `texture::ahead` for the DIRECT aliasing barrier or fence-gate `Pool::reclaim()` on submission retirement. Hunks in `pool.rs` and `texture/ahead.rs` were kept minimal and disjoint from `#4581` / `#4654`.
Reused pooled texture placements (again == true) previously took the
VICTORY_UPLOAD_AHEAD COPY-queue upload path, which emits no
D3D12_RESOURCE_BARRIER_TYPE_ALIASING and sets uploaded=true / ahead=DONE,
causing neither COPY nor DIRECT to emit an aliasing barrier before shader
sampling (unlike DIRECT uploads in host.rs and texture.rs).

Track the reused flag on Reclaim private data via pool::reused() so
texture::ahead skips reused placements and lets the DIRECT upload path
emit the aliasing barrier while virgin placements keep using COPY-queue
uploads. Also gate Pool::reclaim() on GPU submission retirement
(host::submissions().1 >= submission_at_give) alongside the 2500 ms REST
cooldown so long shader-compile stalls cannot recycle in-flight ranges.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 03:16:21 +00:00
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-12-01 04:27 UTC · original

@⁠nidea1 the new test resting_pieces_wait_for_submission_retirement_even_after_rest depends on test order. It passes alone and with cargo test -p victory-gpu --lib pool::, but fails in the full cargo test --locked -p victory-gpu --lib, also with --test-threads=1:

pool.rs: assertion `left == right` failed
  left: 33554432

That is the assert_eq!(pool.free_bytes, 0) right after the take that should reuse first: second (submission 6) was reclaimed too.

Cause, from reading the code: take → cut → rested(now) (pool.rs:391 and 487 on your head 4512766c9) reclaims with crate::host::submissions().1, the process-wide finished counter, not with the finished the test passes to reclaim_at. Other tests in the same run move that counter past 6, so the take frees second early.

A way out: give the test a take path that takes finished explicitly (as reclaim_at does), or keep the test's submission numbers above anything the counter can reach in a test run.

Tested on our fork's port of this PR (same code path), RTX 2070 SUPER 8 GB, Windows 11; only cargo test, no game run for this.

Drafted with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-12-01 04:27 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#issuecomment-7300756964) @⁠nidea1 the new test `resting_pieces_wait_for_submission_retirement_even_after_rest` depends on test order. It passes alone and with `cargo test -p victory-gpu --lib pool::`, but fails in the full `cargo test --locked -p victory-gpu --lib`, also with `--test-threads=1`: ``` pool.rs: assertion `left == right` failed left: 33554432 ``` That is the `assert_eq!(pool.free_bytes, 0)` right after the `take` that should reuse `first`: `second` (submission 6) was reclaimed too. Cause, from reading the code: `take` → `cut` → `rested(now)` (pool.rs:391 and 487 on your head 4512766c9) reclaims with `crate::host::submissions().1`, the process-wide finished counter, not with the `finished` the test passes to `reclaim_at`. Other tests in the same run move that counter past 6, so the `take` frees `second` early. A way out: give the test a `take` path that takes `finished` explicitly (as `reclaim_at` does), or keep the test's submission numbers above anything the counter can reach in a test run. Tested on our fork's port of this PR (same code path), RTX 2070 SUPER 8 GB, Windows 11; only `cargo test`, no game run for this. Drafted with AI assistance (Claude Code).
Author
Owner

@⁠nidea1 on GitHub · 2026-12-01 09:55 UTC · original

@⁠Jesper-Andersson Thanks for catching this and pinning down the exact cause!

Reproduced the exact failure (left: 33554432, right: 0) in full cargo test --locked -p victory-gpu --lib -- --test-threads=1 and fixed it in 04f1c6b8:

  • Added Pool::cut_at / Pool::rested_at and #[cfg(test)] Pool::take_at / Pool::take_sized_at accepting an explicit finished: u64 (with cut, rested, and take_sized delegating to crate::host::submissions().1).
  • Updated resting_pieces_wait_for_submission_retirement_even_after_rest (and reused_flag_tracks_virgin_and_recycled_placements) to use take_at where explicit submission counters are tested, while still exercising the live cut -> rested_at(now, host::submissions().1) path via pool.take (with u64::MAX) and checking pool.give against host::submissions().0.
  • Also switched the existing pure Pool<u32> unit tests from pool.give(..., t) to pool.give_at(..., t, 0) so they cannot flake under parallel cargo test if another GPU test is concurrently mid-submission (STARTED > FINISHED).

Verification on 04f1c6b8:

  • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 1138 passed, 0 failed, 66 ignored
  • cargo test --locked -p victory-gpu --lib: 1138 passed, 0 failed, 66 ignored
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings and --all-features: 0 warnings (keeping base 7d93ee07 while #4707 is still open; PR remains MERGEABLE on main 5fabb46e)
  • cargo xtask policy: 464 files ok
**@⁠nidea1** on GitHub · 2026-12-01 09:55 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#issuecomment-7307414964) @⁠Jesper-Andersson Thanks for catching this and pinning down the exact cause! Reproduced the exact failure (`left: 33554432`, `right: 0`) in full `cargo test --locked -p victory-gpu --lib -- --test-threads=1` and fixed it in `04f1c6b8`: - Added `Pool::cut_at` / `Pool::rested_at` and `#[cfg(test)]` `Pool::take_at` / `Pool::take_sized_at` accepting an explicit `finished: u64` (with `cut`, `rested`, and `take_sized` delegating to `crate::host::submissions().1`). - Updated `resting_pieces_wait_for_submission_retirement_even_after_rest` (and `reused_flag_tracks_virgin_and_recycled_placements`) to use `take_at` where explicit submission counters are tested, while still exercising the live `cut -> rested_at(now, host::submissions().1)` path via `pool.take` (with `u64::MAX`) and checking `pool.give` against `host::submissions().0`. - Also switched the existing pure `Pool<u32>` unit tests from `pool.give(..., t)` to `pool.give_at(..., t, 0)` so they cannot flake under parallel `cargo test` if another GPU test is concurrently mid-submission (`STARTED > FINISHED`). Verification on `04f1c6b8`: - `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: **1138 passed, 0 failed, 66 ignored** - `cargo test --locked -p victory-gpu --lib`: **1138 passed, 0 failed, 66 ignored** - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` and `--all-features`: **0 warnings** (keeping base `7d93ee07` while `#4707` is still open; PR remains `MERGEABLE` on `main` `5fabb46e`) - `cargo xtask policy`: **464 files ok**
Author
Owner

@⁠Dukestar69 on GitHub · 2026-12-01 12:05 UTC · original · approved these changes

Reviewed crates/victory-gpu/src/pool.rs and crates/victory-gpu/src/texture/ahead.rs: fence-gating resting pieces with (ready_ms, submission, piece) (submission <= finished) prevents premature reuse while in-flight submissions may still reference the range, and tracking
eused (gain) on Reclaim (with proper IUnknown::from_raw release of the temporary GetPrivateData AddRef) cleanly excludes reused placed textures from COPY-queue exture::ahead uploads so they take the DIRECT-queue aliasing barrier path. Verified on Windows (RTX 5090): pool::tests (33 passed, 0 failed) and exture::ahead::tests (9 passed, 0 failed).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-12-01 12:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#pullrequestreview-6130935582) · **approved these changes** Reviewed crates/victory-gpu/src/pool.rs and crates/victory-gpu/src/texture/ahead.rs: fence-gating resting pieces with (ready_ms, submission, piece) (submission <= finished) prevents premature reuse while in-flight submissions may still reference the range, and tracking eused (gain) on Reclaim (with proper IUnknown::from_raw release of the temporary GetPrivateData AddRef) cleanly excludes reused placed textures from COPY-queue exture::ahead uploads so they take the DIRECT-queue aliasing barrier path. Verified on Windows (RTX 5090): pool::tests (33 passed, 0 failed) and exture::ahead::tests (9 passed, 0 failed). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠nidea1 on GitHub · 2026-12-01 12:33 UTC · original

Live runtime verification on updated head 04f1c6b8 (RTX 3060 Ti 8 GB (ReBAR off, driver 621.40), 32 GB RAM, Windows 11, Series S, DLSS Quality, FSR 3 FG, RT off, VICTORY_SAMPLED_EVICT=1, VICTORY_WINDOW_GROW=1, VICTORY_POOL_SMALL=0, VICTORY_RIPE_BLOCKS=12 — 5-minute (300 s in-world, 357 s total) live validation on a combined 15-PR release build over origin/main (5fabb46eaf).):

  • Completed full 300 s in-world (357 s total) with 0 nvlddmkm events (id153=0), 0 0x887A device hangs, 0 HERO LEAD, 0 UPLOAD OVER HOST WRITE, and 0 Victory errors.
  • Pool and memory stayed flat in steady state (52 texture blocks, 6,559 / 6,770 MB VRAM, 5,980 MB Shared GPU RAM, 22.27 GB PrivateBytes).
  • Visual check across 3 captured frames (+31 s, +151 s, +285 s): clean rendering with 0 aliasing/corruption artifacts.

Caveat: combined 15-PR release build over a 5-minute opening/cell sequence with VICTORY_POOL_SMALL=0 (not an isolated A/B or VICTORY_POOL_SMALL=1 soak).

**@⁠nidea1** on GitHub · 2026-12-01 12:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#issuecomment-7311321977) Live runtime verification on updated head `04f1c6b8` (RTX 3060 Ti 8 GB (ReBAR off, driver `621.40`), 32 GB RAM, Windows 11, Series S, DLSS Quality, FSR 3 FG, RT off, `VICTORY_SAMPLED_EVICT=1`, `VICTORY_WINDOW_GROW=1`, `VICTORY_POOL_SMALL=0`, `VICTORY_RIPE_BLOCKS=12` — 5-minute (`300 s` in-world, `357 s` total) live validation on a combined 15-PR release build over `origin/main` (`5fabb46eaf`).): - Completed full `300 s` in-world (`357 s` total) with **`0` `nvlddmkm` events (`id153=0`)**, **`0` `0x887A` device hangs**, **`0` `HERO LEAD`**, **`0` `UPLOAD OVER HOST WRITE`**, and **`0` Victory errors**. - Pool and memory stayed flat in steady state (`52` texture blocks, `6,559 / 6,770 MB` VRAM, `5,980 MB` Shared GPU RAM, `22.27 GB` PrivateBytes). - Visual check across 3 captured frames (`+31 s`, `+151 s`, `+285 s`): clean rendering with `0` aliasing/corruption artifacts. *Caveat:* combined 15-PR release build over a 5-minute opening/cell sequence with `VICTORY_POOL_SMALL=0` (not an isolated A/B or `VICTORY_POOL_SMALL=1` soak).
Author
Owner

@⁠nidea1 on GitHub · 2026-12-01 14:39 UTC · original

Thanks @⁠Dukestar69 for the review and RTX 5090 test verification (pool::tests and texture::ahead::tests) on 04f1c6b8!

**@⁠nidea1** on GitHub · 2026-12-01 14:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#issuecomment-7314611809) Thanks @⁠Dukestar69 for the review and RTX 5090 test verification (`pool::tests` and `texture::ahead::tests`) on `04f1c6b8`!
github-bot closed this pull request 2026-12-01 18:36:52 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:34 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4713#issuecomment-7321159755) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/trustno1-coder--VIctory-NVIDIA!4714
No description provided.