GPU: keep the remap history for every view heap, coalesced and bounded (port of Kamiloj9/victory-dlss 2023d5c8b) #843

Merged
CwWwWwW merged 1 commit from upstream-pr/843 into main 2026-11-29 08:16:58 +00:00
CwWwWwW commented 2026-11-28 07:34:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CwWwWwW on 2026-11-28T07:34:58Z.


Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1333 (head 6affb2ea2c, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f.

Problem

The ranges of title memory the runtime mapped, unmapped or wrote were kept in one unbounded static REMAPPED: Mutex<Vec<(u64, u64)>> and the first texture pass took all of them with std::mem::take. Two consequences:

  • A second view heap misses remap notifications. The heap whose pass runs first consumes the ranges; the other heap's placed textures stay stale until their slots are written again, so a texture that arrived or changed under it can be drawn as old contents. (The old code even says "a title has one view heap" - it does now, but nothing enforces it.)
  • The history is unbounded when nothing takes it. If no shader that picks textures by index is bound, no pass runs and the Vec grows for the life of the run; a long session leaks memory in proportion to remapping activity.

Found by comparing the other forks: Kamiloj9/victory-dlss commit 2023d5c8b (Kamil Ojdana), which adapts PastiiJay/klbf-lab commit 74315e7. It is not in this fork, upstream/main, the #653 batch, or any open PR (checked by the fork comparison). This is that fix ported.

Change

  • RemapQueue: sequence-numbered ranges, coalescing consecutive pages, REMAP_LIMIT = 1 << 15 entries, the oldest evicted.
  • HostHeap::remap_cursor: each heap takes the ranges recorded after its last pass; texture_slots_remapped is now refresh_remapped(&REMAPPED, frame).
  • A heap whose cursor is behind the evicted range gets None from snapshot and rescans all its placed slots once, instead of silently missing the range.
  • remapped() records and counts evictions; the metrics line says "evicted from history" rather than "dropped".
  • texture_slots_page_written still runs first and is unchanged; slots a draw read through a table still wait for their draw.

Tests

  • New remap_history_delivers_extended_ranges_and_detects_eviction: coalescing a page sequence, snapshots after a cursor, an evicted range returning None, and the empty latest snapshot.
  • remapped_memory_makes_its_texture_slots_due extended to a second view heap: both heaps make their own slots due from the shared ranges, each cursor advances once, and an evicted history makes both rescan and still leave the draw-table-owned slot for its draw.
  • cargo test -p victory-gpu --lib --locked: 218 passed, 0 failed, 6 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.
  • No game or GPU needed (the WARP test uses the host device when present).

Coordination

This touches descriptor/host.rs, which open #1324 also changes (Heap::drop/dynamic slots, an independent area). Both are needed; whichever lands second should be rebased. It does not depend on #1324.

(CI note: the check job on main is currently red on the asset-policy violation; #1322 fixes that, after which this can be rebased.)

Rebased onto the VIctory-NVIDIA tree (origin/main 3e573d2)

The fork's main was replaced by the tree of trustno1-coder/VIctory-NVIDIA (5dbf5ce); this PR was rebased onto 3e573d2 and the feature adapted to the new tree's structures (now commit 88efd7e):

  • REMAPPED is a Mutex<RemapQueue> with REMAP_LIMIT = 1<<15: a VecDeque<(sequence, (start, end))>, latest, evicted, published; consecutive pages are coalesced into the last entry (unless already snapshotted), the oldest entry is evicted at the limit and the metric says so.
  • Each HostHeap has its own remap_cursor, initialised at heap creation to the history's latest so a late heap does not replay old ranges; refresh_remapped serialises that heap's passes, takes the ranges after the cursor (or, after an eviction, rescans that heap's placed slots once), and advances the cursor.
  • texture_news reports noted pages from the per-heap cursor; the new tree's PAGE_WRITTEN/BAKE_PAGE_WRITTEN handling is untouched.
  • Tests carried/adapted: remap_history_delivers_extended_ranges_and_detects_eviction, and remapped_memory_makes_its_texture_slots_due extended to two view heaps with per-heap cursors and an evicted history that forces the rescan.

Verification on this host: cargo check -p victory-gpu --all-targets --locked clean; cargo test -p victory-gpu --lib remap 5 passed; under --features diagnostics with VICTORY_D3D12_WARP=1, descriptor::host::tests 48 passed; cargo clippy clean (--all-targets and --all-features). No game run; correctness on real hardware with multiple live title heaps remains to be sanity-checked. rustfmt --check is not meaningful here: origin/main's own files are not rustfmt-clean under the repo config.

Verification on this tree (base 63b902f, 2026-11-27)

  • cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml)
  • cargo check --workspace --all-targets --all-features --locked: pass
  • cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change.
  • cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm.

Hardware verification suggested

  • This one changes default behaviour (per-heap remap history, bounded with eviction; a lagging heap rescans its placed slots once). Please run a long/multi-heap session before merging.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5537940100 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/843). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-28T07:34:58Z. --- Ported to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1333 (head 6affb2ea2cbea3889b6c0bdf596fda90c073ebd1, author CwWwWwW). The fork's own line was dropped when it rebased onto 959dcaf (5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main 63b902f. ## Problem The ranges of title memory the runtime mapped, unmapped or wrote were kept in one unbounded `static REMAPPED: Mutex<Vec<(u64, u64)>>` and the first texture pass took all of them with `std::mem::take`. Two consequences: - **A second view heap misses remap notifications.** The heap whose pass runs first consumes the ranges; the other heap's placed textures stay stale until their slots are written again, so a texture that arrived or changed under it can be drawn as old contents. (The old code even says "a title has one view heap" - it does now, but nothing enforces it.) - **The history is unbounded when nothing takes it.** If no shader that picks textures by index is bound, no pass runs and the Vec grows for the life of the run; a long session leaks memory in proportion to remapping activity. Found by comparing the other forks: **Kamiloj9/victory-dlss** commit [`2023d5c8b`](https://github.com/Kamiloj9/victory-dlss/commit/2023d5c8b) (Kamil Ojdana), which adapts PastiiJay/klbf-lab commit `74315e7`. It is not in this fork, `upstream/main`, the #653 batch, or any open PR (checked by the fork comparison). This is that fix ported. ## Change - `RemapQueue`: sequence-numbered ranges, coalescing consecutive pages, `REMAP_LIMIT = 1 << 15` entries, the oldest evicted. - `HostHeap::remap_cursor`: each heap takes the ranges recorded after its last pass; `texture_slots_remapped` is now `refresh_remapped(&REMAPPED, frame)`. - A heap whose cursor is behind the evicted range gets `None` from `snapshot` and rescans all its placed slots once, instead of silently missing the range. - `remapped()` records and counts evictions; the metrics line says "evicted from history" rather than "dropped". - `texture_slots_page_written` still runs first and is unchanged; slots a draw read through a table still wait for their draw. ## Tests - New `remap_history_delivers_extended_ranges_and_detects_eviction`: coalescing a page sequence, snapshots after a cursor, an evicted range returning `None`, and the empty latest snapshot. - `remapped_memory_makes_its_texture_slots_due` extended to a second view heap: both heaps make their own slots due from the shared ranges, each cursor advances once, and an evicted history makes both rescan and still leave the draw-table-owned slot for its draw. - `cargo test -p victory-gpu --lib --locked`: **218 passed, 0 failed, 6 ignored**. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean. - No game or GPU needed (the WARP test uses the host device when present). ## Coordination This touches `descriptor/host.rs`, which open #1324 also changes (`Heap::drop`/dynamic slots, an independent area). Both are needed; whichever lands second should be rebased. It does not depend on #1324. (CI note: the `check` job on main is currently red on the asset-policy violation; #1322 fixes that, after which this can be rebased.) ## Rebased onto the VIctory-NVIDIA tree (origin/main 3e573d2) The fork's main was replaced by the tree of trustno1-coder/VIctory-NVIDIA (5dbf5ce); this PR was rebased onto 3e573d2 and the feature adapted to the new tree's structures (now commit 88efd7e): - `REMAPPED` is a `Mutex<RemapQueue>` with `REMAP_LIMIT = 1<<15`: a `VecDeque<(sequence, (start, end))>`, `latest`, `evicted`, `published`; consecutive pages are coalesced into the last entry (unless already snapshotted), the oldest entry is evicted at the limit and the metric says so. - Each `HostHeap` has its own `remap_cursor`, initialised at heap creation to the history's `latest` so a late heap does not replay old ranges; `refresh_remapped` serialises that heap's passes, takes the ranges after the cursor (or, after an eviction, rescans that heap's placed slots once), and advances the cursor. - `texture_news` reports noted pages from the per-heap cursor; the new tree's `PAGE_WRITTEN`/`BAKE_PAGE_WRITTEN` handling is untouched. - Tests carried/adapted: `remap_history_delivers_extended_ranges_and_detects_eviction`, and `remapped_memory_makes_its_texture_slots_due` extended to two view heaps with per-heap cursors and an evicted history that forces the rescan. Verification on this host: `cargo check -p victory-gpu --all-targets --locked` clean; `cargo test -p victory-gpu --lib remap` 5 passed; under `--features diagnostics` with `VICTORY_D3D12_WARP=1`, `descriptor::host::tests` 48 passed; `cargo clippy` clean (`--all-targets` and `--all-features`). No game run; correctness on real hardware with multiple live title heaps remains to be sanity-checked. `rustfmt --check` is not meaningful here: origin/main's own files are not rustfmt-clean under the repo config. ## Verification on this tree (base 63b902f, 2026-11-27) - cargo check --workspace --all-targets --locked: pass (Rust 1.98.1, the version pinned in rust-toolchain.toml) - cargo check --workspace --all-targets --all-features --locked: pass - cargo clippy --workspace --all-targets --locked -- -D warnings (and --all-features): this change adds no clippy finding. The only failures are on unmodified lines of main (clippy::manual_is_multiple_of at crates/victory-gpu/src/shadow.rs:1708 and crates/victory-gpu/src/descriptor.rs:1234, clippy::let_and_return at crates/victory-shader/src/emit/mod.rs:2768); CI run 46104876336 on 63b902f failed on those before this change. - cargo test was not run in the author's environment (Windows VM without an MSVC toolchain; test binaries could not be linked there). CI on Windows and a run on the card should confirm. ## Hardware verification suggested - This one changes default behaviour (per-heap remap history, bounded with eviction; a lagging heap rescans its placed slots once). Please run a long/multi-heap session before merging.
Aniseto commented 2026-11-28 08:07:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-28T08:07:35Z.


Ran the remap-history tests at 6affb2e on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.

cargo test -p victory-gpu --lib -- remap_history remapped_memory --test-threads=1
3 passed; 0 failed; 0 ignored; 0 measured; 487 filtered out      (exit 0)

All three tests pass, including remap_history_delivers_extended_ranges_and_detects_eviction and remapped_memory_makes_its_texture_slots_due. They are CPU-side tests of the per-heap queue; no second view heap was driven on the adapter. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti.

Not tested: a session with two view heaps, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7236379709 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/843#issuecomment-7236379709). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-28T08:07:35Z. --- Ran the remap-history tests at `6affb2e` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build. ``` cargo test -p victory-gpu --lib -- remap_history remapped_memory --test-threads=1 3 passed; 0 failed; 0 ignored; 0 measured; 487 filtered out (exit 0) ``` All three tests pass, including `remap_history_delivers_extended_ranges_and_detects_eviction` and `remapped_memory_makes_its_texture_slots_due`. They are CPU-side tests of the per-heap queue; no second view heap was driven on the adapter. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti. Not tested: a session with two view heaps, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!843
No description provided.