Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3736,15 +3736,26 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
}
// the states uploads into textures kept in step start from once this list has run
if super::title_textures::any() {
let t: Vec<(usize, u32, D3D12_RESOURCE_STATES)> =
out.iter().filter(|b| b[0] == 0).map(|b| ((b[2] as u64 | (b[3] as u64) << 32) as usize, b[4], D3D12_RESOURCE_STATES(b[6] as i32))).collect();
let t = completed_transitions(&out);
super::title_textures::note_transitions(this as usize, &t);
}
if !out.is_empty() {
pc::<unsafe extern "system" fn(*mut c_void, u32, *const [u32; 8])>(this, PC_RESOURCE_BARRIER)(this, out.len() as u32, out.as_ptr());
}
}

/// The transitions of `barriers` (console words) that leave a resource in their `StateAfter`:
/// a split barrier's BEGIN_ONLY (flag 1) only starts its transition – the resource is not in
/// the new state – and the END_ONLY (flag 2) completes it, so the state is taken from there.
fn completed_transitions(barriers: &[[u32; 8]]) -> Vec<(usize, u32, D3D12_RESOURCE_STATES)> {
const BEGIN_ONLY: u32 = 1;
barriers
.iter()
.filter(|b| b[0] == 0 && b[1] != BEGIN_ONLY)
.map(|b| ((b[2] as u64 | (b[3] as u64) << 32) as usize, b[4], D3D12_RESOURCE_STATES(b[6] as i32)))
.collect()
}

/// D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER | INDEX_BUFFER: valid for buffers only
const BUFFER_ONLY_STATES: u32 = 0x1 | 0x2;

Expand Down Expand Up @@ -4397,6 +4408,23 @@ mod tests {
on_release(l2 as usize);
}

/// A split barrier's BEGIN_ONLY only starts its transition: the resource is not in the new
/// state (it must not be read or written) until the END_ONLY completes it, so the state
/// uploads start from is the one the end barrier names, not the begin's.
#[test]
fn a_split_barriers_begin_is_not_a_completed_transition() {
let res = 0x1234_5000usize;
let words = |flags: u32, after: u32| [0u32, flags, res as u32, (res >> 32) as u32, 0, 0x1, after, 0];
let none = words(0, 0x8); // COMMON → UNORDERED_ACCESS
let begin = words(1, 0x8);
let end = words(2, 0x8);
let t = completed_transitions(&[none, begin, end]);
assert_eq!(t.len(), 2, "the begin-only barrier is not one: {t:?}");
assert!(t.iter().all(|&(r, sub, st)| r == res && sub == 0 && st == D3D12_RESOURCE_STATES(0x8)));
// a UAV barrier (type 2) is no transition at all
assert!(completed_transitions(&[[2, 0, 0, 0, 0, 0, 0, 0], begin]).is_empty());
}

#[test]
fn queue_picking_prefers_last_queue_and_respects_release() {
let dev = 0x8000_0001usize;
Expand Down
Loading