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

Open
CwWwWwW wants to merge 1 commit from upstream-pr/1333 into main
CwWwWwW commented 2026-11-26 15:53:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T15:53:55Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5513169145 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T15:53:55Z. --- ## 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.
upstream-sync closed this pull request 2026-11-26 16:06:36 +00:00
CwWwWwW commented 2026-11-26 22:18:12 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T22:18:12Z.


Rebased onto current main 52ac4ec (which now includes #1324 and #1336). The one conflict, in crates/victory-gpu/src/descriptor/host.rs, is resolved by keeping both the new heap identity field id (#1324) and this PR's remap_cursor; the rest applied cleanly.

New head: 42be495 (one commit). Local verification after the rebase: cargo test -p victory-gpu --lib --locked -- --test-threads=1 -> 224 passed, 0 failed, 6 ignored; cargo clippy -p victory-gpu --all-targets --locked -- -D warnings clean; git diff --check clean. CI is running.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7204552885 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333#issuecomment-7204552885). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T22:18:12Z. --- Rebased onto current main `52ac4ec` (which now includes #1324 and #1336). The one conflict, in `crates/victory-gpu/src/descriptor/host.rs`, is resolved by keeping both the new heap identity field `id` (#1324) and this PR's `remap_cursor`; the rest applied cleanly. New head: `42be495` (one commit). Local verification after the rebase: `cargo test -p victory-gpu --lib --locked -- --test-threads=1` -> **224 passed, 0 failed, 6 ignored**; `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` clean; `git diff --check` clean. CI is running.
CwWwWwW commented 2026-11-26 22:23:50 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T22:23:50Z.


The CI Tests failure is not caused by this PR - it is the asset-policy check on current main: crates/victory-gpu/src/host.rs (528,953 bytes) and crates/victory-shader/src/emit/lower.rs (535,587 bytes) exceed the 524,288-byte limit. The same failure is known on main (#1342), and the PR's only change to host.rs is +13 bytes of diagnostic text.

Two open PRs already fix the cause: #1357 (maintainer branch, mergeable=clean, moves both test modules out) and #1361 (raises the Rust-source ceiling). I am not duplicating that unrelated policy fix inside #1333. Once #1357 lands, this branch can be rebased once more and the check should be green.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7204640071 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333#issuecomment-7204640071). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T22:23:50Z. --- The CI `Tests` failure is **not caused by this PR** - it is the asset-policy check on current `main`: `crates/victory-gpu/src/host.rs` (528,953 bytes) and `crates/victory-shader/src/emit/lower.rs` (535,587 bytes) exceed the 524,288-byte limit. The same failure is known on main (#1342), and the PR's only change to `host.rs` is +13 bytes of diagnostic text. Two open PRs already fix the cause: #1357 (maintainer branch, `mergeable=clean`, moves both test modules out) and #1361 (raises the Rust-source ceiling). I am not duplicating that unrelated policy fix inside #1333. Once #1357 lands, this branch can be rebased once more and the check should be green.
akimfomin commented 2026-11-26 23:39:00 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by akimfomin on 2026-11-26T23:39:00Z.


The rebased #1333 still merges cleanly with main a42b627e78476d691042a2a12e8cd5fcf5e49d77. I merged exact head 42be495e772530b6904f850453562ae02c45bcff locally into tree 621ef4d4fd9b6f707399cd14d2eaa9b537e50dd3 and ran cargo test --locked -p victory-gpu --lib remap -- --test-threads=1 --nocapture on Windows with WARP requested. Five tests reported passes, including range coalescing/eviction and the two-heap remap fixture. Pinned fixtures.

Keep this small test group on the next rebase: it gives a behavior signal even if the unrelated main file-size gate still fails. This is an isolated remap suite without a title or a full CI run. PortBridge · AI-assisted test report.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7205727397 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333#issuecomment-7205727397). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-26T23:39:00Z. --- The rebased #1333 still merges cleanly with main `a42b627e78476d691042a2a12e8cd5fcf5e49d77`. I merged exact head `42be495e772530b6904f850453562ae02c45bcff` locally into tree `621ef4d4fd9b6f707399cd14d2eaa9b537e50dd3` and ran `cargo test --locked -p victory-gpu --lib remap -- --test-threads=1 --nocapture` on Windows with WARP requested. Five tests reported passes, including range coalescing/eviction and the two-heap remap fixture. [Pinned fixtures](https://github.com/fxceless/victory-fork/blob/42be495e772530b6904f850453562ae02c45bcff/crates/victory-gpu/src/descriptor/host.rs#L4824-L4901). Keep this small test group on the next rebase: it gives a behavior signal even if the unrelated main file-size gate still fails. This is an isolated remap suite without a title or a full CI run. [PortBridge](https://github.com/akimfomin/PortBridge/issues/98) · AI-assisted test report.
CwWwWwW commented 2026-11-26 23:45:45 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-26T23:45:45Z.


The rebased #1333 still merges cleanly with main a42b627e78476d691042a2a12e8cd5fcf5e49d77. I merged exact head 42be495e772530b6904f850453562ae02c45bcff locally into tree 621ef4d4fd9b6f707399cd14d2eaa9b537e50dd3 and ran cargo test --locked -p victory-gpu --lib remap -- --test-threads=1 --nocapture on Windows with WARP requested. Five tests reported passes, including range coalescing/eviction and the two-heap remap fixture. Pinned fixtures.

Keep this small test group on the next rebase: it gives a behavior signal even if the unrelated main file-size gate still fails. This is an isolated remap suite without a title or a full CI run. PortBridge · AI-assisted test report.

Yes, the failure is due to irrelevant causes from the main branch itself. Also lots of repos are also suffering this. However,it's just a test bug.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7205834214 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333#issuecomment-7205834214). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-26T23:45:45Z. --- > The rebased #1333 still merges cleanly with main `a42b627e78476d691042a2a12e8cd5fcf5e49d77`. I merged exact head `42be495e772530b6904f850453562ae02c45bcff` locally into tree `621ef4d4fd9b6f707399cd14d2eaa9b537e50dd3` and ran `cargo test --locked -p victory-gpu --lib remap -- --test-threads=1 --nocapture` on Windows with WARP requested. Five tests reported passes, including range coalescing/eviction and the two-heap remap fixture. [Pinned fixtures](https://github.com/fxceless/victory-fork/blob/42be495e772530b6904f850453562ae02c45bcff/crates/victory-gpu/src/descriptor/host.rs#L4824-L4901). > > Keep this small test group on the next rebase: it gives a behavior signal even if the unrelated main file-size gate still fails. This is an isolated remap suite without a title or a full CI run. [PortBridge](https://github.com/akimfomin/PortBridge/issues/98) · AI-assisted test report. Yes, the failure is due to irrelevant causes from the main branch itself. Also lots of repos are also suffering this. However,it's just a test bug.
CwWwWwW commented 2026-11-27 01:01:57 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T01:01:57Z.

Review: COMMENTED


This commit comes with the other fours, urgent and important, please review ASAP. Thanks

<!-- greyfinch-sync:fxceless/victory-fork:review:6082136790 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1333#pullrequestreview-6082136790). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T01:01:57Z. **Review:** COMMENTED --- This commit comes with the other fours, urgent and important, please review ASAP. Thanks
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1333:upstream-pr/1333'
git switch 'upstream-pr/1333'

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 'upstream-pr/1333'
git switch 'upstream-pr/1333'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1333'
git switch 'upstream-pr/1333'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1333'
git switch 'main'
git merge --squash 'upstream-pr/1333'
git switch 'main'
git merge --ff-only 'upstream-pr/1333'
git switch 'main'
git merge 'upstream-pr/1333'
git push origin 'main'
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
fxceless/victory-fork!1330
No description provided.