Skip to content
Open
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
33 changes: 24 additions & 9 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ const WAIT_TIMEOUT: Duration = Duration::from_secs(2);
/// hang, while giving heavy initial 3D frames (>1 s of dispatches) plenty of room to finish
/// cleanly without prematurely breaking synchronization.
const GPU_WAIT_WATCHDOG_TIMEOUT: Duration = Duration::from_millis(5000);
/// Cap on tracked per-list written UMA ranges (for same-list write-then-wait detection).
const MAX_WRITTEN_RANGES: usize = 256;

fn wait_timeout() -> Duration {
static T: OnceLock<Duration> = OnceLock::new();
Expand Down Expand Up @@ -565,7 +563,7 @@ struct ListState {
/// Last `OMSetDepthBounds` values, restored after `KickoffX`
depth_bounds: Option<(f32, f32)>,
occlusion: Occlusion,
/// UMA address ranges written by this list since last Reset/KickoffX
/// Sorted, disjoint UMA ranges written by this list since last Reset/KickoffX
written_ranges: Vec<(u64, u64)>,
/// Sparse-window `(va, bytes)` ranges written by memory ops (`Write32/64`, `Fill*`,
/// `CopyMemoryToMemoryX`, timestamps) to copy back to the CPU view after execution.
Expand Down Expand Up @@ -594,11 +592,14 @@ impl ListState {
return;
}
let end = va.saturating_add(size);
if self.written_ranges.len() < MAX_WRITTEN_RANGES {
self.written_ranges.push((va, end));
} else if let Some(last) = self.written_ranges.last_mut() {
last.0 = last.0.min(va);
last.1 = last.1.max(end);
let ranges = &mut self.written_ranges;
let first = ranges.partition_point(|&(_, stop)| stop < va);
let count = ranges[first..].partition_point(|&(start, _)| start <= end);
if count == 0 {
ranges.insert(first, (va, end));
} else {
ranges[first] = (va.min(ranges[first].0), end.max(ranges[first + count - 1].1));
ranges.drain(first + 1..first + count);
}
if crate::gpu::uma::get().is_some_and(|u| u.is_sparse(va as usize)) {
if self.sparse_writes.is_empty() {
Expand Down Expand Up @@ -633,7 +634,8 @@ impl ListState {

fn has_prior_write(&self, va: u64, size: u64) -> bool {
let end = va.saturating_add(size);
self.written_ranges.iter().any(|&(s, e)| va < e && s < end)
let first = self.written_ranges.partition_point(|&(_, stop)| stop <= va);
self.written_ranges.get(first).is_some_and(|&(start, _)| start < end)
}

fn clear_waits(&mut self) {
Expand Down Expand Up @@ -4314,6 +4316,19 @@ mod tests {
assert!(!s.has_prior_write(0x0FF8, 8));
}

#[test]
fn scattered_writes_preserve_unwritten_gaps() {
let mut s = ListState::default();
for i in 0..300 {
s.note_write(0x1000 + i * 16, 8);
}
let a = 0x1000 + 260 * 16;
assert!(!s.has_prior_write(a + 8, 8));
s.note_write(a + 8, 8);
assert!(s.has_prior_write(a + 8, 8));
assert!(!s.has_prior_write(a - 8, 8));
}

#[test]
fn execute_with_waits_splits_batches_before_unsatisfied_list() {
// Use synthetic non-zero list pointers distinct from real COM objects.
Expand Down
Loading