gpu: keep placed views out of HOST_WRITTEN_AT and clear host-written ranges on remap #4464

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

@⁠nidea1 on GitHub · 2026-11-30 20:38 UTC · original
nidea1:fix/host-written-placed-lifecycle → main · +557 −44 · 4 files · 2 commits · closed without merging

What it changes

Fixes two lifecycle bugs in HOST_WRITTEN_AT / HOST_WRITTEN that strand stale host-written records at recycled streaming addresses, cause false HERO LEAD warnings (8–50 per 40 s run), can alias/seed newly streamed textures from dead GPU copies, and pin recycled placed views in VRAM:

  1. Placed views (PLACED_TEXTURES) overwrote HOST_WRITTEN_AT (texture.rs, list.rs, resource.rs)

    • texture::seed_later(view, source) and the placed_twins copy loops in CopyResource / CopyTextureRegion (list.rs) called texture::host_written(view/twin).
    • That overwrote HOST_WRITTEN_AT[address] with the cached PLACED_TEXTURES pointer, which the title never releases (texture::forget is never called on it).
    • When the title later released the real source / dst resource, forget(source) checked d.5 != source and left HOST_WRITTEN_AT[address] stranded for the rest of the run.
    • Any texture subsequently streamed into that memory range then either fired WARN HERO LEAD, falsely matched host_written_like / host_written_block_like (aliasing or seeding from the dead view), or hit a cached PLACED_TEXTURES view still stuck in HOST_WRITTEN.
    • resource::texture_at also called placed_in_host_written(address, desc) unconditionally right after seed_later, emitting a self-warning on views that seed_later had already wired up to copy from source.
    • Fix: add texture::host_written_view(resource) for PLACED_TEXTURES views (marks HOST_WRITTEN and tracks (address, resource) -> bytes in HOST_WRITTEN_PLACED without touching HOST_WRITTEN_AT), use it in seed_later and list.rs's placed_twins paths, and only call placed_in_host_written when seed_later did not handle the view.
  2. Title memory unmap / remap / free never notified texture.rs (watch.rs, texture.rs)

    • watch::title_memory_changed (title_memory_remapped / title_memory_unmapping) and watch::title_memory_freed notified texback, descriptor::host, inplace, and hwrt, but never invalidated HOST_WRITTEN_AT or HOST_WRITTEN_PLACED.
    • When a streaming region was unmapped/remapped/freed and later reused at the same (address, desc), a cached PLACED_TEXTURES view stayed in HOST_WRITTEN / WRITE_SUBMITTED, skipping upload_from of the new title-memory texture and refusing idle/slot VRAM eviction indefinitely.
    • Fix:
      • Add texture::remapped(at, len) (with a lock-free AtomicUsize fast path and read-first RwLock checks + max_bytes-bounded range scan for exact nested-interval overlap) called from watch::title_memory_changed and watch::title_memory_freed (resolving len == 0 via allocation_end only when host-written ranges exist).
      • Keep HOST_WRITTEN and HOST_WRITTEN_AT/HOST_WRITTEN_PLACED atomically consistent under strict lock order (HOST_WRITTEN -> HOST_WRITTEN_AT -> HOST_WRITTEN_PLACED), clearing both overlapping stale_sources and stale_views from HOST_WRITTEN, WRITE_SUBMITTED, STAGING, and SEEDS (so still-live resources over remapped memory can also re-register on a later host copy).
      • Guard host_write_listed's deferred WRITE_SUBMITTED insert under HOST_WRITTEN.read() so a command list submitted after remapped/forget cannot re-insert an invalidated resource into WRITE_SUBMITTED.
      • Add read-first fast paths in texture::forget so non-host-written resource releases avoid write-locking the host-written tables and SEEDS.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Windows 11 x64, RTX 3060 Ti 8 GB, 32 GB RAM, Series S profile (720p -> 1080p), DLSS Quality, FSR 3 FG, RT off; matched 40 s world runs.
  • Before (4 baseline runs on origin/main): 25, 42, 50, and 8 HERO LEAD warnings per 40 s run (100% caused by 1024x1024 9-mip placed views left behind in HOST_WRITTEN_AT), plus false seed_later matches against stale entries.
  • After (2 standalone runs on 6ba5def7 + 2 combined runs with #4433 on latest commit 7f7cb8ec, both VICTORY_SAMPLED_EVICT=0 and =1): 0, 0, 0, and 0 HERO LEAD warnings, 0 UPLOAD OVER HOST WRITE, character faces/skin/textures inspected clean on captured frames.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A.
  • cargo test passed for the crates it touches: yes (cargo test -j 4 -p victory-gpu --locked --lib -- texture:: resource::tests:: watch::: 160 passed, 0 failed, 5 pre-existing ignored, including 3 host_written_lifecycle_tests covering seed_later/placed_twins ownership preservation, multi-view coexistence, nested/boundary/overflow remap ranges, source re-registration after remap, stale deferred WRITE_SUBMITTED suppression, forget fast path, and title_memory_freed(base, 0); cargo clippy -j 4 -p victory-gpu --all-targets --locked --no-deps: 0 warnings in touched files; cargo run -p xtask -- policy --staged: ok).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2334 (includes an opt-in VICTORY_HOST_WRITTEN_REUSE=1 heuristic that drops HOST_WRITTEN_AT on a different-layout view; does not prevent seed_later/placed_twins from overwriting HOST_WRITTEN_AT with immortal PLACED_TEXTURES views or invalidate HOST_WRITTEN/HOST_WRITTEN_AT on memory remap/unmap/free).
**@⁠nidea1** on GitHub · 2026-11-30 20:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4463) `nidea1:fix/host-written-placed-lifecycle` → `main` · +557 −44 · 4 files · 2 commits · closed without merging ## What it changes Fixes two lifecycle bugs in `HOST_WRITTEN_AT` / `HOST_WRITTEN` that strand stale host-written records at recycled streaming addresses, cause false `HERO LEAD` warnings (8–50 per 40 s run), can alias/seed newly streamed textures from dead GPU copies, and pin recycled placed views in VRAM: 1. **Placed views (`PLACED_TEXTURES`) overwrote `HOST_WRITTEN_AT` (`texture.rs`, `list.rs`, `resource.rs`)** - `texture::seed_later(view, source)` and the `placed_twins` copy loops in `CopyResource` / `CopyTextureRegion` (`list.rs`) called `texture::host_written(view/twin)`. - That overwrote `HOST_WRITTEN_AT[address]` with the cached `PLACED_TEXTURES` pointer, which the title never releases (`texture::forget` is never called on it). - When the title later released the real `source` / `dst` resource, `forget(source)` checked `d.5 != source` and left `HOST_WRITTEN_AT[address]` stranded for the rest of the run. - Any texture subsequently streamed into that memory range then either fired `WARN HERO LEAD`, falsely matched `host_written_like` / `host_written_block_like` (aliasing or seeding from the dead view), or hit a cached `PLACED_TEXTURES` view still stuck in `HOST_WRITTEN`. - `resource::texture_at` also called `placed_in_host_written(address, desc)` unconditionally right after `seed_later`, emitting a self-warning on views that `seed_later` had already wired up to copy from `source`. - **Fix**: add `texture::host_written_view(resource)` for `PLACED_TEXTURES` views (marks `HOST_WRITTEN` and tracks `(address, resource) -> bytes` in `HOST_WRITTEN_PLACED` without touching `HOST_WRITTEN_AT`), use it in `seed_later` and `list.rs`'s `placed_twins` paths, and only call `placed_in_host_written` when `seed_later` did not handle the view. 2. **Title memory unmap / remap / free never notified `texture.rs` (`watch.rs`, `texture.rs`)** - `watch::title_memory_changed` (`title_memory_remapped` / `title_memory_unmapping`) and `watch::title_memory_freed` notified `texback`, `descriptor::host`, `inplace`, and `hwrt`, but never invalidated `HOST_WRITTEN_AT` or `HOST_WRITTEN_PLACED`. - When a streaming region was unmapped/remapped/freed and later reused at the same `(address, desc)`, a cached `PLACED_TEXTURES` view stayed in `HOST_WRITTEN` / `WRITE_SUBMITTED`, skipping `upload_from` of the new title-memory texture and refusing idle/slot VRAM eviction indefinitely. - **Fix**: - Add `texture::remapped(at, len)` (with a lock-free `AtomicUsize` fast path and read-first `RwLock` checks + `max_bytes`-bounded range scan for exact nested-interval overlap) called from `watch::title_memory_changed` and `watch::title_memory_freed` (resolving `len == 0` via `allocation_end` only when host-written ranges exist). - Keep `HOST_WRITTEN` and `HOST_WRITTEN_AT`/`HOST_WRITTEN_PLACED` atomically consistent under strict lock order (`HOST_WRITTEN` -> `HOST_WRITTEN_AT` -> `HOST_WRITTEN_PLACED`), clearing both overlapping `stale_sources` and `stale_views` from `HOST_WRITTEN`, `WRITE_SUBMITTED`, `STAGING`, and `SEEDS` (so still-live resources over remapped memory can also re-register on a later host copy). - Guard `host_write_listed`'s deferred `WRITE_SUBMITTED` insert under `HOST_WRITTEN.read()` so a command list submitted after `remapped`/`forget` cannot re-insert an invalidated resource into `WRITE_SUBMITTED`. - Add read-first fast paths in `texture::forget` so non-host-written resource releases avoid write-locking the host-written tables and `SEEDS`. ## How it was tested - GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): Windows 11 x64, RTX 3060 Ti 8 GB, 32 GB RAM, Series S profile (720p -> 1080p), DLSS Quality, FSR 3 FG, RT off; matched 40 s world runs. - Before (4 baseline runs on `origin/main`): **25, 42, 50, and 8** `HERO LEAD` warnings per 40 s run (100% caused by `1024x1024` 9-mip placed views left behind in `HOST_WRITTEN_AT`), plus false `seed_later` matches against stale entries. - After (2 standalone runs on `6ba5def7` + 2 combined runs with #4433 on latest commit `7f7cb8ec`, both `VICTORY_SAMPLED_EVICT=0` and `=1`): **0, 0, 0, and 0** `HERO LEAD` warnings, **0** `UPLOAD OVER HOST WRITE`, character faces/skin/textures inspected clean on captured frames. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A. - `cargo test` passed for the crates it touches: yes (`cargo test -j 4 -p victory-gpu --locked --lib -- texture:: resource::tests:: watch::`: 160 passed, 0 failed, 5 pre-existing ignored, including 3 `host_written_lifecycle_tests` covering `seed_later`/`placed_twins` ownership preservation, multi-view coexistence, nested/boundary/overflow remap ranges, source re-registration after remap, stale deferred `WRITE_SUBMITTED` suppression, `forget` fast path, and `title_memory_freed(base, 0)`; `cargo clippy -j 4 -p victory-gpu --all-targets --locked --no-deps`: 0 warnings in touched files; `cargo run -p xtask -- policy --staged`: ok). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2334 (includes an opt-in `VICTORY_HOST_WRITTEN_REUSE=1` heuristic that drops `HOST_WRITTEN_AT` on a different-layout view; does not prevent `seed_later`/`placed_twins` from overwriting `HOST_WRITTEN_AT` with immortal `PLACED_TEXTURES` views or invalidate `HOST_WRITTEN`/`HOST_WRITTEN_AT` on memory remap/unmap/free).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 20:41:25 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-30 20:51 UTC · original

Tested headlessly on origin/main (e1251c31, Windows 11, no game run):

  • Merge check: clean against origin/main.
  • cargo test -p victory-gpu --lib -- watch::tests: 43 passed, 0 failed (1159 filtered).
  • cargo test -p victory-gpu --lib -- texture::: 26 passed, 0 failed, 4 ignored (1172 filtered), including all 3 new texture::host_written_lifecycle_tests. No new warnings.

(AI-assisted build/unit-test check; game runtime not launched.)

**@⁠tikD1337** on GitHub · 2026-11-30 20:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4463#issuecomment-7291561189) Tested headlessly on `origin/main` (`e1251c31`, Windows 11, no game run): - Merge check: clean against `origin/main`. - `cargo test -p victory-gpu --lib -- watch::tests`: **43 passed, 0 failed** (1159 filtered). - `cargo test -p victory-gpu --lib -- texture::`: **26 passed, 0 failed, 4 ignored** (1172 filtered), including all 3 new `texture::host_written_lifecycle_tests`. No new warnings. *(AI-assisted build/unit-test check; game runtime not launched.)*
github-bot force-pushed github-bot/gh-4463 from 7f7cb8ec3a to 02c8ca5ac5 2026-12-01 03:10:35 +00:00 Compare
github-bot closed this pull request 2026-12-01 18:43:32 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:41 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:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4463#issuecomment-7321343632) 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!4464
No description provided.