Skip to content

D3D12.X: translate list #146 enhanced barrier groups into legacy texture transitions - #3287

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
Kalmarv:fix/enhanced-barrier-groups
Nov 29, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
Kalmarv:fix/enhanced-barrier-groups

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What is in it
Ports crates/xcl/src/hle/d3d12x/barrier_groups.rs from amd-dev (a68f609f + fdd1ac2d, raylitebull) onto main, translating command list slot #146 (Barrier(groups)) texture enhanced barriers into legacy D3D12_RESOURCE_BARRIER transitions routed through list_x::resource_barrier_x:

  • Maps console D3D12_BARRIER_LAYOUT_* + D3D12_BARRIER_ACCESS_* to PC D3D12_RESOURCE_STATES (including DEPTH_READ 0x20 on depth-read layouts and independent depth/stencil plane state tracking).
  • Filters transitions that PC D3D12 would reject on Close() (E_INVALIDARG), handles split BEGIN_ONLY/END_ONLY barriers, keeps partial subresource ranges exact instead of widening large ranges to ALL_SUBRESOURCES, and tracks UNDEFINED layout transitions from the last known state.
  • Updates list_x::resource_barrier_x to keep legacy barrier state in sync via barrier_groups::note_legacy_state, clears per-resource state on release in real.rs, and exposes depth_uav::kept for depth-twin PARK coordination.
  • Opt-out via XCL_BARRIER_GROUPS=0 (keeps the global UAV barrier).

Tested

  • cargo test -p xcl --lib barrier_groups passed (8 passed; 0 failed).
  • 150 s xcl-smoke regression run below on NVIDIA GeForce RTX 5070 Ti (XCL_PREPARE=0, 0 device removals, 0 crashes, 0 E_INVALIDARG/Close failures; live log confirmed 8192+ title texture barriers translated into 7250+ legacy transitions).

Regression run
Baseline (main ancestor f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

PR branch (bd5ee498d4805c3263b264d497ddfc482f704bfe):

xcl-smoke v1
commit: bd5ee498d4805c3263b264d497ddfc482f704bfe
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1574 (PresentX 1574)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34133 MB

Not tested

  • Live 3D in-world visual A/B beyond the 150 s title smoke sequence (the 150 s smoke verifies stability, zero removals, and barrier translation counts).
  • AMD GPU hardware (verified on NVIDIA GeForce RTX 5070 Ti; original amd-dev commits were tested on RX 9070 XT).
  • Titles other than ea3b5e4d.

AI use
Ported from amd-dev (a68f609f + fdd1ac2d), wired onto main, and verified with an AI coding agent; reviewed by hand against unit tests, 150 s smoke logs, and list_x::resource_barrier_x / depth_uav integration.

…cy texture transitions

Port barrier_groups.rs from amd-dev (a68f609 + fdd1ac2, raylitebull) onto main:

- Translates command list xcl-dev#146 Barrier(groups) texture barriers into legacy
  D3D12_RESOURCE_BARRIER transitions routed through list_x::resource_barrier_x,
  including DEPTH_READ (0x20) on depth-read layouts and independent depth/stencil
  plane tracking.
- Tracks legacy ResourceBarrier state updates via note_legacy_state and clears
  per-resource state on resource release (real.rs).
- Exposes depth_uav::kept for depth-twin PARK state coordination.
- Opt-out via XCL_BARRIER_GROUPS=0 (the global UAV barrier remains).
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
@andrewDoing

Copy link
Copy Markdown
Contributor

Two exact CPU translation controls on 2b75212 show distinct ways a legal partial range can affect an independent mip. I compiled the production transitions_of, state_of, range and plane functions with a fixed shape callback and the same per-plane state representation. The resource was a two-mip, 66-slice, single-plane texture (132 subresources).

  1. Explicit COMMON → COPY_SOURCE on mip 0 of 64 slices emitted indices 0,2,…,126 as expected. Increasing NumArraySlices to 65 emitted a single ALL_SUBRESOURCES barrier instead of 0,2,…,128. That changes 67 extra subresources. Asking for both mips of all 66 slices correctly emitted ALL. The existing 100-slice unit assertion intentionally encodes the widening, but on a partially transitioned texture it also changes the legacy StateBefore contract for untouched siblings. Chunk exact indices if a bounded batch is needed; reserve ALL for a genuinely full range.
  2. Independently of the 64 threshold, start all 132 in COPY_SOURCE, then explicitly transition just subresource 0 to COPY_DEST. An UNDEFINED → COPY_SOURCE request for subresource 1 emitted a COPY_DEST → COPY_SOURCE transition for 1. Its actual legacy state was still COPY_SOURCE, so it required no transition. The per-plane callback remembered subresource 0's change for the entire plane. A uniform per-plane default plus per-subresource overrides (including legacy transition updates) would distinguish these cases.

These checks inspected the emitted barrier words without submitting inconsistent transitions to a driver. No device fault, title test or frame-performance claim. OpenAI Codex wrote and ran the bounded harness and drafted this comment.

@andrewDoing

Copy link
Copy Markdown
Contributor

The small range-only patch below passed six production transitions_of CPU controls on 2b75212: 64 and 65 even indices, 66 odd indices, 128 consecutive interior indices, one final index, and a genuine full range. Each assertion compared the entire index sequence in order. Expanding a partial range costs one 32-byte legacy record per selected subresource plus the temporary 4-byte index; the complete range stays one record. For bounded peak memory across very large groups, stream exact batches to the caller instead of broadening the barrier.

There is a separate integration constraint on the proposed per-subresource state fix: transitions_of currently calls moved before transitions filters/refines states in out.retain_mut. Moving to sparse state storage alone would still cache an after-state for a transition later refused or rewritten. A small isolated default-state-plus-overrides model passed mixed siblings, adjacent ranges, unknown prior state, return-to-default, and full-reset controls. I'd wire updates to accepted effective transitions, preserve unknown when no transition can be established, and account for split barriers and reset/discarded recordings before treating that model as authoritative. The diff here fixes range widening only.

--- a/crates/xcl/src/hle/d3d12x/barrier_groups.rs
+++ b/crates/xcl/src/hle/d3d12x/barrier_groups.rs
@@ -47,9 +47,6 @@
 /// D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY, END_ONLY
 const BEGIN_ONLY: u32 = 1;
 const END_ONLY: u32 = 2;
-/// subresources of one barrier's range named one by one at most (more: all of the texture)
-const RANGE_MOST: usize = 64;
-
 /// Whether the title's barrier groups become transitions (`XCL_BARRIER_GROUPS`, on unless "0").
 pub(super) fn enabled() -> bool {
     static ON: OnceLock<bool> = OnceLock::new();
@@ -103,7 +100,7 @@
     let s = first_slice.min(array)..first_slice.saturating_add(n_slices.max(1)).min(array);
     let p = first_plane.min(planes)..first_plane.saturating_add(n_planes.max(1)).min(planes);
     let count = m.len() * s.len() * p.len();
-    if count == (mips * array * planes) as usize || count > RANGE_MOST {
+    if count == (mips * array * planes) as usize {
         return None;
     }
     let mut out = Vec::with_capacity(count);
@@ -522,7 +519,7 @@
         // past the texture: what there is of it
         assert_eq!(subresources([2, 8, 0, 1, 0, 1], 4, 1, 1), Some(vec![2, 3]));
         // more than are named one by one: all
-        assert_eq!(subresources([0, 1, 0, 100, 0, 1], 2, 100, 1), None);
+        assert_eq!(subresources([0, 1, 0, 100, 0, 1], 2, 100, 1), Some((0..200).step_by(2).collect()));
     }
 
     fn t(res: usize, layout: (u32, u32), access: (u32, u32)) -> Texture {

OpenAI Codex prepared and tested the range change and state model. CPU translation controls only.

@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, thank you! Applied the exact-index range fix in �d5ee498 (removed RANGE_MOST = 64 so partial ranges never widen to ALL_SUBRESOURCES, and added unit assertions for 65- and 100-slice partial ranges alongside the full-range case; cargo test -p xcl --lib barrier_groups 8/8 passing).

Agreed on keeping per-subresource post-filter state tracking (wired after out.retain_mut with split-barrier and command-list reset semantics) as a separate follow-up.

@Foniass

Foniass commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Note: my #3299 is a port of the same amd-dev commit (#146 barrier groups), opened about 2 hours after this one; I missed this PR when I checked for duplicates. The two are nearly identical. Differences (from git diff between them):

Only one of the two should be merged; the maintainer can pick. If this one goes in, the alignment check from #3299 would be worth adding here, and I'll close #3299.

(Written with 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

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants