Skip to content

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

Open
AndyLatimer wants to merge 1 commit into
trustno1-coder:mainfrom
AndyLatimer:fix/alias-rt-barriers-and-alignment
Open

AndyLatimer wants to merge 1 commit into
trustno1-coder:mainfrom
AndyLatimer:fix/alias-rt-barriers-and-alignment

Conversation

@AndyLatimer

Copy link
Copy Markdown
Contributor

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

…alignment

Addresses the barrier ordering, tile alignment, and hardware compression
hazards introduced by physical-page transient RT aliasing (trustno1-coder#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 <noreply@google.com>
@MagroDaniel

Copy link
Copy Markdown

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.

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.

Transient RT aliasing leaves warm memory visible (bright image, coloured sparkle on reflections)

2 participants