gpu: fix transient RT aliasing barriers, DiscardResource, and 64 KiB alignment #1994

Open
github-bot wants to merge 1 commit from github-bot/gh-1994 into main AGit
Owner

@⁠AndyLatimer on GitHub · 2026-11-29 06:17 UTC · original
AndyLatimer:fix/alias-rt-barriers-and-alignment → main · +844 −121 · 6 files · 1 commits · open

Fixes #1976

Summary

Fixes the physical-page transient RT aliasing hazards introduced in 6ba7fa8 (stale tile compression/warm memory bleeding across passes, premature barriers in prelude(), and sub-64 KiB overlap):

  1. Enforce 64 KiB start alignment (inplace::aliased_section_pages)
    • Reject allocations with start & 0xffff != 0 instead of rounding start down, preventing tile 0 from aliasing onto an adjacent live resource's tail page.
  2. Preserve D3D12 aliasing barrier + DiscardResource ordering (host.rs, alias_rt.rs, resource.rs)
    • Keep all aliased reserved textures in D3D12_RESOURCE_STATE_COMMON at creation (try_create) and across command list boundaries (HostList::aliased_rts_common at HostList::close).
    • Remove the blanket if copy.aliased_rt aliasing & initial-transition loop from HostList::prelude(), which previously activated overlapping later-pass targets before earlier passes finished reading the active alias.
    • Track per-list order (ListAliases) and physical (section, [start, end)) tile extents (AliasExtent), retiring only genuinely overlapping active aliases to COMMON before emitting Aliasing(None -> tex) + DiscardResource (for ALLOW_RENDER_TARGET / ALLOW_DEPTH_STENCIL) on takeover. Disjoint MRTs and same-alias RT -> SRV -> RT transitions do not trigger false retirement/discard.
    • Track global submission-time tile owners (OWNERS) in prelude() so cross-list takeovers emit Aliasing + DiscardResource in exact queue submission order while incremental multi-list rendering of the same RT is preserved untouched.
    • Preserve HostList::transition_and_record's prior-state return contract for texture::alias and update two_queues::probe for StateBook.
  3. Harden reserved tile mapping & heap lifetime (alias_rt.rs)
    • Query texture.GetDesc() after CreateReservedResource (handles MipLevels == 0), verify num_sub == subresource_count, NumStandardMips + NumPackedMips == mips, and full subresource tile coverage before mapping, retain strong Tier-2 ID3D12Heap refs inside AliasExtent, and retire removed section heaps asynchronously in section_gone.

Verification

  • cargo test --release -p victory-gpu --locked --lib -- alias_rt inplace: 14 passed, 0 failed (unit tests for 64 KiB start alignment, ExtentRanges coalescing/overlap, intra-list ListAliases MRT/takeover tracking, cross-list OwnerTable tracking, and a real D3D12 Tier-2 reserved RT aliasing + DiscardResource readback test on RTX 3060 Ti).
  • cargo clippy -p victory-gpu --all-targets --locked and --all-features: 0 warnings/errors in all 6 modified files.
  • cargo build --release -p victory --locked: passed (exit code 0).
  • cargo test -p xtask --locked: 0 asset-policy issues in all 6 modified files (pre-existing lower.rs size violation on main untouched).
**@⁠AndyLatimer** on GitHub · 2026-11-29 06:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994) `AndyLatimer:fix/alias-rt-barriers-and-alignment` → `main` · +844 −121 · 6 files · 1 commits · open Fixes #1976 ### Summary Fixes the physical-page transient RT aliasing hazards introduced in `6ba7fa8` (stale tile compression/warm memory bleeding across passes, premature barriers in `prelude()`, and sub-64 KiB overlap): 1. **Enforce 64 KiB start alignment (`inplace::aliased_section_pages`)** - Reject allocations with `start & 0xffff != 0` instead of rounding `start` down, preventing tile 0 from aliasing onto an adjacent live resource's tail page. 2. **Preserve D3D12 aliasing barrier + `DiscardResource` ordering (`host.rs`, `alias_rt.rs`, `resource.rs`)** - Keep all aliased reserved textures in `D3D12_RESOURCE_STATE_COMMON` at creation (`try_create`) and across command list boundaries (`HostList::aliased_rts_common` at `HostList::close`). - Remove the blanket `if copy.aliased_rt` aliasing & initial-transition loop from `HostList::prelude()`, which previously activated overlapping later-pass targets before earlier passes finished reading the active alias. - Track per-list order (`ListAliases`) and physical `(section, [start, end))` tile extents (`AliasExtent`), retiring only genuinely overlapping active aliases to `COMMON` before emitting `Aliasing(None -> tex)` + `DiscardResource` (for `ALLOW_RENDER_TARGET` / `ALLOW_DEPTH_STENCIL`) on takeover. Disjoint MRTs and same-alias `RT -> SRV -> RT` transitions do not trigger false retirement/discard. - Track global submission-time tile owners (`OWNERS`) in `prelude()` so cross-list takeovers emit `Aliasing` + `DiscardResource` in exact queue submission order while incremental multi-list rendering of the same RT is preserved untouched. - Preserve `HostList::transition_and_record`'s prior-state return contract for `texture::alias` and update `two_queues::probe` for `StateBook`. 3. **Harden reserved tile mapping & heap lifetime (`alias_rt.rs`)** - Query `texture.GetDesc()` after `CreateReservedResource` (handles `MipLevels == 0`), verify `num_sub == subresource_count`, `NumStandardMips + NumPackedMips == mips`, and full subresource tile coverage before mapping, retain strong Tier-2 `ID3D12Heap` refs inside `AliasExtent`, and retire removed section heaps asynchronously in `section_gone`. ### Verification - `cargo test --release -p victory-gpu --locked --lib -- alias_rt inplace`: **14 passed, 0 failed** (unit tests for 64 KiB start alignment, `ExtentRanges` coalescing/overlap, intra-list `ListAliases` MRT/takeover tracking, cross-list `OwnerTable` tracking, and a real D3D12 Tier-2 reserved RT aliasing + `DiscardResource` readback test on RTX 3060 Ti). - `cargo clippy -p victory-gpu --all-targets --locked` and `--all-features`: **0 warnings/errors** in all 6 modified files. - `cargo build --release -p victory --locked`: **passed** (exit code 0). - `cargo test -p xtask --locked`: 0 asset-policy issues in all 6 modified files (pre-existing `lower.rs` size violation on `main` untouched).
Addresses the barrier ordering, tile alignment, and hardware compression
hazards introduced by physical-page transient RT aliasing (#1976):

- Enforce 64 KiB start alignment in `inplace::aliased_section_pages` so
  sub-64 KiB allocations never alias onto a live neighbor's final tile.
- Track physical `(section, [start, end))` tile extents and retain Tier-2
  heap refs on `AliasExtent`; verify resolved `GetDesc()` mip count and
  full `GetResourceTiling` subresource coverage before mapping, returning
  all aliased resources in `D3D12_RESOURCE_STATE_COMMON`.
- Remove the blanket `prelude()` aliasing/transition batch that activated
  overlapping later-pass RTs before earlier passes finished.
- Retire only genuinely overlapping active aliases to `COMMON` before
  emitting `Aliasing(None -> tex)` + `DiscardResource` on takeover,
  transitioning all aliased RTs back to `COMMON` at `HostList::close` and
  resolving cross-list takeovers (without discarding incremental
  continuation of the same RT) via submission-time `OWNERS` in `prelude()`.
- Preserve the `transition_and_record` prior-state contract for
  `texture::alias` and update `two_queues::probe` for `StateBook`.

Co-Authored-By: Antigravity <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 06:18:12 +00:00
Author
Owner

@⁠MagroDaniel on GitHub · 2026-11-29 14:17 UTC · original

Tested this PR on hardware: the coloured blocky glass corruption from #2233 is still there with it.

Build: v2026.11.29.01 (829188e9) plus this PR, cherry-picked. It conflicted with the release's ListAliasTracker/OwnerTable rework (4d98ca87). I took this PR's whole alias_rt.rs, removed the old alias_tracker field from HostList, and moved let detiles = self.deferred().detiles.clone(); back to the top of prelude(). Built with #2392, #2261, #2265 and #2421 too. cargo test -p victory-gpu alias passes 10/10, and victory-shader passes 468/468.

System: RTX 3070 8 GB, driver 610.88, Windows 11 26200. Series S, DLSS Ultra Performance, FG off, RT off, warm cache.

Result in the prologue window shot (the same frame every time):

Coloured blocks saved_mb
release, aliasing on yes 139–226
release + this PR, aliasing on yes, same place 0 (aliased_rts=100 virtual_mb=39 physical_mb=248)
either, VICTORY_ALIAS_TARGETS=0 gone —

So with this PR only about 100 targets alias, presumably because the 64 KiB start alignment rejects the rest. The pool then costs more than it saves on Series S, and the corruption remains. It seems to come from something other than the barrier/Discard ordering, such as reading another alias's pages with a different format through the undefined swizzle.

For Series S, an opt-in default as in #2042 looks safer until this is understood.

**@⁠MagroDaniel** on GitHub · 2026-11-29 14:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7257188088) Tested this PR on hardware: the coloured blocky glass corruption from #2233 is **still there** with it. **Build:** v2026.11.29.01 (`829188e9`) plus this PR, cherry-picked. It conflicted with the release's `ListAliasTracker`/`OwnerTable` rework (`4d98ca87`). I took this PR's whole `alias_rt.rs`, removed the old `alias_tracker` field from `HostList`, and moved `let detiles = self.deferred().detiles.clone();` back to the top of `prelude()`. Built with #2392, #2261, #2265 and #2421 too. `cargo test -p victory-gpu alias` passes 10/10, and `victory-shader` passes 468/468. **System:** RTX 3070 8 GB, driver 610.88, Windows 11 26200. Series S, DLSS Ultra Performance, FG off, RT off, warm cache. **Result in the prologue window shot (the same frame every time):** | | Coloured blocks | `saved_mb` | |---|---|---| | release, aliasing on | yes | 139–226 | | release + this PR, aliasing on | **yes**, same place | **0** (`aliased_rts=100 virtual_mb=39 physical_mb=248`) | | either, `VICTORY_ALIAS_TARGETS=0` | gone | — | So with this PR only about 100 targets alias, presumably because the 64 KiB start alignment rejects the rest. The pool then costs more than it saves on Series S, and the corruption remains. It seems to come from something other than the barrier/Discard ordering, such as reading another alias's pages with a different format through the undefined swizzle. For Series S, an opt-in default as in #2042 looks safer until this is understood.
Author
Owner

@⁠xteral67 on GitHub · 2026-12-01 08:59 UTC · original

Tested a smaller take on the same problem on current main (5fabb46e): commit 37afe344 on xteral67/VIctory-NVIDIA, branch alias-discard (alias_rt.rs and host.rs only).

  • On a takeover of every page of an aliased texture: aliasing barrier, then DiscardResource in its RT/DS/UAV state, then back. A partial takeover gets the barrier only.
  • A first write over never-written pages counts as a takeover.
  • A resource's own writes, not its reads, decide whether it already holds its pages.

RTX 3080 Ti 12 GB, driver 621.40, Series X profile, 1440p, DLSS quality, FSR 3 FG 2x, VICTORY_ALIAS_TARGETS=1, ~8 min of town driving plus walking at night: render targets 2,030 → 1,345 MB (log saved_mb=524), card use in town 10.1–10.6 → 9.4–10.8 GB, no artifacts seen. Not checked on Series S, where the coloured glass blocks above were seen. cargo test was not run.

**@⁠xteral67** on GitHub · 2026-12-01 08:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7306051654) Tested a smaller take on the same problem on current main (5fabb46e): commit 37afe344 on xteral67/VIctory-NVIDIA, branch `alias-discard` (`alias_rt.rs` and `host.rs` only). - On a takeover of every page of an aliased texture: aliasing barrier, then `DiscardResource` in its RT/DS/UAV state, then back. A partial takeover gets the barrier only. - A first write over never-written pages counts as a takeover. - A resource's own writes, not its reads, decide whether it already holds its pages. RTX 3080 Ti 12 GB, driver 621.40, Series X profile, 1440p, DLSS quality, FSR 3 FG 2x, `VICTORY_ALIAS_TARGETS=1`, ~8 min of town driving plus walking at night: render targets 2,030 → 1,345 MB (log `saved_mb=524`), card use in town 10.1–10.6 → 9.4–10.8 GB, no artifacts seen. Not checked on Series S, where the coloured glass blocks above were seen. `cargo test` was not run.
Author
Owner

@⁠xteral67 on GitHub · 2026-12-01 13:59 UTC · original

Correction to my earlier comment: the discard fix is not enough. On a night scene over water and in shadows under street lights, aliased targets still show coloured noise and dark blocks, with or without the discards. A census of the aliased targets shows the title reads, every frame, pages that another target of a different size or format wrote last (for example a 853x480 target over a 1706x960 one of the same format). The console reads those bytes in its own layout; the host's 64 KiB undefined-swizzle layouts differ, so the reader gets garbage. Giving such readers their own memory made it worse, because some of those reads are deliberate reinterpretations. With VICTORY_ALIAS_TARGETS=0 the same scenes are clean. So aliasing needs a layout-aware copy for cross-shape reads, not only barriers and discards.

**@⁠xteral67** on GitHub · 2026-12-01 13:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7313512038) Correction to my earlier comment: the discard fix is not enough. On a night scene over water and in shadows under street lights, aliased targets still show coloured noise and dark blocks, with or without the discards. A census of the aliased targets shows the title reads, every frame, pages that another target of a different size or format wrote last (for example a 853x480 target over a 1706x960 one of the same format). The console reads those bytes in its own layout; the host's 64 KiB undefined-swizzle layouts differ, so the reader gets garbage. Giving such readers their own memory made it worse, because some of those reads are deliberate reinterpretations. With VICTORY_ALIAS_TARGETS=0 the same scenes are clean. So aliasing needs a layout-aware copy for cross-shape reads, not only barriers and discards.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/alias_rt.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/inplace.rs
  • crates/victory-gpu/src/resource.rs
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1994/head:github-bot/gh-1994'
git switch 'github-bot/gh-1994'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1994'
git switch 'github-bot/gh-1994'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1994'
git switch 'github-bot/gh-1994'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1994'
git switch 'main'
git merge --squash 'github-bot/gh-1994'
git switch 'main'
git merge --ff-only 'github-bot/gh-1994'
git switch 'main'
git merge 'github-bot/gh-1994'
git push origin 'main'
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!1994
No description provided.