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

Open
AndyLatimer wants to merge 1 commit from upstream-pr/1994 into main
AndyLatimer commented 2026-11-29 06:17:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AndyLatimer on 2026-11-29T06:17:28Z.


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).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5548202774 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994). Originally posted by [AndyLatimer](https://github.com/AndyLatimer) on 2026-11-29T06:17:28Z. --- 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).
MagroDaniel commented 2026-11-29 14:17:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by MagroDaniel on 2026-11-29T14:17:26Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7257188088 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7257188088). Originally posted by [MagroDaniel](https://github.com/MagroDaniel) on 2026-11-29T14:17:26Z. --- 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.
xteral67 commented 2026-12-01 08:59:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xteral67 on 2026-12-01T08:59:10Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7306051654 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7306051654). Originally posted by [xteral67](https://github.com/xteral67) on 2026-12-01T08:59:10Z. --- 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 commented 2026-12-01 13:59:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by xteral67 on 2026-12-01T13:59:19Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7313512038 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1994#issuecomment-7313512038). Originally posted by [xteral67](https://github.com/xteral67) on 2026-12-01T13:59:19Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1994:upstream-pr/1994'
git switch 'upstream-pr/1994'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1994'
git switch 'upstream-pr/1994'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1994'
git switch 'upstream-pr/1994'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1994'
git switch 'main'
git merge --squash 'upstream-pr/1994'
git switch 'main'
git merge --ff-only 'upstream-pr/1994'
git switch 'main'
git merge 'upstream-pr/1994'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!1994
No description provided.