Skip to content

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

Open
CwWwWwW wants to merge 1 commit into
fxceless:mainfrom
CwWwWwW:port/remap-history-queue
Open

CwWwWwW wants to merge 1 commit into
fxceless:mainfrom
CwWwWwW:port/remap-history-queue

Conversation

@CwWwWwW

@CwWwWwW CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 CwWwWwW closed this Nov 26, 2026
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
… measuring

Staged the same evening, compiled and passing the tests, none measured:
the original's fxceless#1002 (exact cascade shadows on 32 lanes), fxceless#1324 and
fxceless#1333 (descriptor heaps), three more ray-only skips with a count of such
programs, fxceless#1341 (VICTORY_ALT_FLIP) and VICTORY_RAM_TRIM.

Why nothing of it has a figure: the process holds about 16.5 GB private
in the first room (the layer's own account of one session), the lab's
runner waits for 20 GiB free, and six readings between 18:47 and 19:11
local time gave 16.1 to 18.0 GiB free. The switches that make the layer
hold less (VICTORY_WINDOW_KB, VICTORY_WINDOW_TAILS, VICTORY_INPLACE,
all in main and off) go first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
…mended, heap identity, and the switches brought from other projects

Forty-one commits, compiled and tested as 9ef09c2 (victory-shader 267,
victory-gpu 325, victory-loader 51, victory-hle 128, no warnings; build
9ef09c2-diagnostics).

On by default:
- the original's two commits up to 58de9bf: fxceless#927
  (half-precision values through 16-bit buffer views keep their bits) and
  the sign extension of the original project's #3124; the translator
  changes, so shaders are translated anew once;
- the leak of placed-view shapes mended (TaynanGT/Vice-Tay PR fxceless#27);
- fxceless#1324 (VICTORY_HEAP_IDENTITY, =0 goes back),
  fxceless#1333 (VICTORY_REMAP_PER_HEAP, =0 goes back) and fxceless#1336.

Off by default: VICTORY_NAN_SCRUB, VICTORY_SHADER_LOOP_LIMIT_CS,
VICTORY_SHADER_EARLY_DEPTH, VICTORY_UNMAKE_QUIET, VICTORY_PATCH_WAITS,
VICTORY_PATCH_CLZERO, VICTORY_PATCH_CLWB, VICTORY_BVH_NAMED_WRITES,
VICTORY_BVH_BOUNDS, VICTORY_BVH_FENCES, VICTORY_PIPELINE_COMPUTE_WAIT,
VICTORY_CARD_AWAKE, VICTORY_GUARD_OUTSIDE, VICTORY_HEAP_RESCAN_SPREAD,
VICTORY_LAND_ASIDE, VICTORY_GUARD_RUNS, VICTORY_RT_SKIN_SKIP,
VICTORY_WINDOW_SKIP_SAME, VICTORY_MERGE_SUBMISSIONS, VICTORY_MESH_LAUNCH
and the capture switches; =alt for four of them.

Measured by Codex on build 9ef09c2, the ten switches of Status, the
scripted manoeuvre, a quiet machine, one session: 1,819 frames in 274.0 s,
6.64 fps, median frame 144 ms (95th percentile 197), against 6.69 fps and
141 ms on the code of main before it (-0.7 %, one session each). Private
memory in the room 16.8 GiB against 16.1 to 16.7 in six sessions of main
that day; the layer's windows 3,252 MB against 2,844 to 3,336.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@CwWwWwW CwWwWwW reopened this Nov 26, 2026
Ported from Kamiloj9/victory-dlss commit 2023d5c (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 fxceless#653 batch or any open PR (checked by
the fork comparison); this pull request touches descriptor/host.rs, which
@CwWwWwW
CwWwWwW force-pushed the port/remap-history-queue branch from f513c17 to 42be495 Compare November 26, 2026 22:17
@CwWwWwW

CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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

CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown

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.

@CwWwWwW

CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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.

@CwWwWwW CwWwWwW left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants