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

Closed
github-bot wants to merge 1 commit from gh-pr/1333/head into gh-pr/1333/base
Owner

@⁠CwWwWwW on GitHub · 2026-11-26 15:53 UTC · original
CwWwWwW:port/remap-history-queue → main · +125 −28 · 2 files · 1 commits · closed without merging

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.)

**@⁠CwWwWwW** on GitHub · 2026-11-26 15:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/1333) `CwWwWwW:port/remap-history-queue` → `main` · +125 −28 · 2 files · 1 commits · closed without merging ## 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.)
Ported from Kamiloj9/victory-dlss commit 2023d5c8b (Kamil Ojdana), which
adapts PastiiJay/klbf-lab commit 74315e7: the ranges of title memory the
runtime mapped, unmapped or wrote lived in one unbounded Vec that the
first texture pass std::mem::take()d. A second view heap then saw none of
the notifications (its placed textures stayed stale until its slots were
written again), and a long run grew the Vec without bound since nothing
takes it unless a shader that picks textures by index is bound.

The ranges now live in a RemapQueue: sequential numbers, coalescing of
consecutive pages, and REMAP_LIMIT (1 << 15) entries with the oldest
evicted. Each heap has a cursor: it takes what was recorded after its last
pass, and a heap that finds its cursor behind the evicted range rescans
all its placed slots once instead of silently missing the range. Both
heaps still catch up on their own turns, and a slot a draw read through a
table still waits for its draw.

The metric text says "evicted from history" instead of "dropped".

Tests: a unit test of snapshots, coalescing and eviction detection, plus
the WARP test extended to two view heaps, per-heap cursors and an evicted
history that forces the rescan. cargo test -p victory-gpu --lib: 218
passed, 0 failed, 6 ignored; cargo clippy -p victory-gpu --all-targets --
-D warnings: clean.

Not in the fork, upstream/main, the #653 batch or any open PR (checked by
the fork comparison); this pull request touches descriptor/host.rs, which
#1324 also changes in an independent area - rebase whichever lands second.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:57:20 +00:00
github-bot closed this pull request 2026-11-26 15:57:20 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.