Skip to content

gpu: track physical-page ownership for alias_rt D3D12 aliasing barriers - #1887

Open
steven-seagull27 wants to merge 1 commit into
trustno1-coder:mainfrom
steven-seagull27:fix/alias-rt-barriers
Open

steven-seagull27 wants to merge 1 commit into
trustno1-coder:mainfrom
steven-seagull27:fix/alias-rt-barriers

Conversation

@steven-seagull27

Copy link
Copy Markdown

What it changes

Fixes D3D12 aliasing-barrier over-emission (and missing intra-list handoffs) for physical-page aliased transient render targets introduced in 6ba7fa8 (VICTORY_ALIAS_TARGETS=1):

  1. Read-only command lists no longer receive prelude aliasing barriers (host.rs): HostList::prelude() previously pushed a D3D12_RESOURCE_BARRIER_TYPE_ALIASING (NULL -> resource) for every aliased RT in states, even when the list only read the RT (PIXEL_SHADER_RESOURCE, NON_PIXEL_SHADER_RESOURCE, COPY_SOURCE, DEPTH_READ). Under D3D12 aliasing rules, an aliasing barrier targeting an RT/DSV invalidates its prior contents and compression metadata until re-initialized via Clear*/DiscardResource/Copy*, causing read-after-write corruption across command lists.
  2. Same-resource read-modify-write no longer receives spurious aliasing barriers (host.rs, alias_rt.rs): HostList::transition() previously emitted ALIASING(NULL -> resource) on every intra-list transition of an aliased RT into a write state even when no other aliased resource touched its physical pages in between (e.g., RTV -> SRV -> RTV or cross-list multi-pass blending).
  3. Exact physical-page write-ownership tracking (alias_rt.rs, resource.rs, host.rs):
    • Each aliased HostTexture now carries its coalesced physical AliasFootprint (section + sorted (start_page, count) runs) instead of a bare bool.
    • ListAliasTracker (per HostList, cleared on HostList::reset()) tracks touched physical page spans during recording:
      • Read-only touches never emit an aliasing barrier, and record the read span so a later write to a different overlapping alias in the same list emits an intra-list aliasing barrier after the read (rather than in the prelude, which would invalidate the earlier read).
      • Writes that overlap a prior touch by a different alias in the same list emit an intra-list ALIASING(NULL -> resource) barrier immediately (including when the new alias is Vacant in states or re-enters the same write state).
      • First-touch writes with no prior conflicting touch in the list are recorded as prelude candidates.
    • At submission time in HostList::prelude(), alias_rt::resolve_prelude() checks prelude candidates against the global per-section OwnerTable (cleared on section_gone()), emitting a prelude aliasing barrier only when any page is currently owned by a different resource, and advances global ownership with the list's writes. Read-only lists skip locking global alias_rt state altogether.

How it was tested

  • GPU / environment: Windows 11 x64, NVIDIA RTX 5080 (D3D12 Resource Heap Tier 2, Tiled Resources Tier 4), Rust MSVC (--locked). Synthetic unit and D3D12 hardware tests only (no game files or assets).
  • Before: Every command list touching an aliased RT emitted a prelude ALIASING(NULL -> resource) barrier regardless of read/write state or active page owner, and every intra-list write transition on the same resource emitted another aliasing barrier while first-use intra-list alias handoffs (Vacant in states) emitted none inside the list.
  • After:
    • cargo test --locked -p victory-gpu --lib -- alias_rt --nocapture: 6 passed, 0 failed, including 4 new ownership/handoff unit tests (read_only_list_emits_no_aliasing_barrier, same_resource_rmw_emits_no_spurious_aliasing_barrier, cross_list_and_partial_overlap_handoffs_emit_prelude_barrier, intra_list_read_then_alias_write_defers_barrier_past_read) and a synthetic D3D12 hardware test (aliased_rt_read_after_write_and_handoff_on_d3d12) exercising two 64x64 R8G8B8A8_UNORM reserved RTs aliased onto the same 64 KiB Tier-2 heap tile across read-after-write, cross-list handoff, and intra-list read-then-alias-write command lists with pixel readback verification.
    • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 594 passed, 0 failed, 44 ignored.
    • cargo clippy --locked -p victory-gpu --lib --tests: zero warnings in touched code (alias_rt.rs, modified hunks in host.rs and resource.rs).
  • Wave sizes tested: N/A (GPU barrier/resource tracking only; no shader changes).
  • cargo test passed for the crates it touches: yes (victory-gpu).

Checked for overlap

@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix] gpu: track physical-page ownership for alias_rt D3D12 aliasing barriers gpu: track physical-page ownership for alias_rt D3D12 aliasing barriers Nov 29, 2026
@upipibi

upipibi commented Nov 29, 2026

Copy link
Copy Markdown

Test report for #1887 (head bf8a6d6), merged --no-ff onto main 568c5e5. Synthetic tests only: no title run, no
game files.

Setup: RTX 3070, driver 616.56, Windows 11 (10.0.26100), rustc 1.98.1. Every run logged the GPU and driver from
nvidia-smi before it started.

alias_rt:: tests (-- alias_rt::, 6 tests): all pass, 3/3 runs. That covers the four new ownership/handoff
tests, coalesce_runs_merges_contiguous_tile_ranges and the D3D12 test.

  • The four ownership/handoff tests and coalesce_runs_merges_contiguous_tile_ranges are CPU-only.
  • aliased_rt_read_after_write_and_handoff_on_d3d12 reaches the device.
    • It makes its own device on the system default adapter (D3D12CreateDevice(None, ...)).
    • It returns early, and so counts as passed, if there is no device or the resource heap or tiled resources tier
      is below 2.
    • I added temporary prints (not committed). In every run the device was on "NVIDIA GeForce RTX 3070", with
      resource heap tier 2 and tiled resources tier 4, and every pixel check ran and passed. So these passes are real
      runs, not skips.
  • I also ran the module three more times with VICTORY_D3D12_WARP=1 --features diagnostics. The D3D12 test does
    not read that switch: it ran on the RTX 3070 each time and passed. There is no WARP coverage of this test as
    written.

Negative control: ListAliasTracker::resolve_prelude no longer asks for any prelude aliasing barrier. 3 of the 6
tests fail, the same with and without the switch above:

  • cross_list_and_partial_overlap_handoffs_emit_prelude_barrier (alias_rt.rs:827): [] instead of [2];
  • intra_list_read_then_alias_write_defers_barrier_past_read (alias_rt.rs:864): [] instead of [100];
  • aliased_rt_read_after_write_and_handoff_on_d3d12 (alias_rt.rs:1119): [] instead of [1]. That is the test's
    own check of the tracker's output for the cross-list handoff, before list 3 is recorded. So it stops there and
    does not show what the missing barrier would do to pixels on this card.

The other three (read-only list, same-resource read-modify-write, coalescing) still pass, as expected: none of them
needs a prelude barrier.

cargo test -p victory-gpu --lib --locked

Run PR Main 568c5e5
default 594 passed, 0 failed, 44 ignored 589 passed, 0 failed, 44 ignored
--features diagnostics 648 passed, 0 failed, 44 ignored 643 passed, 0 failed, 44 ignored

The five extra tests are the PR's own.

Not tested: the effect in a title.

Tested with the help of Claude Code (Claude Opus 5.5).

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

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants