Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ pub(super) fn inherit_for_split(from: *mut c_void, to: *mut c_void, allocator: u
console_list::hold_until_reset(old, blocks);
}

/// A submit is about to wait for the pipeline `this` has bound.
pub(super) fn want_bound(this: *mut c_void) {
super::pso_async::want(with(this, |s| s.pso));
}

/// A put-off dispatch that could not be recorded.
pub(super) fn dispatch_dropped() {
count(DISPATCHES_SKIPPED);
Expand Down
8 changes: 1 addition & 7 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2661,20 +2661,14 @@ pub(super) unsafe fn defer(list: *mut c_void, what: Deferred) -> bool {
true
}

/// Builds of a submit's put-off calls that go on without the commit headroom, as a title thread's own do: about what the title's threads had in the driver at once before.
const WANTED_AT_ONCE: usize = 4;

/// Records the deferred dispatches of `wrapper`'s recording, waiting for their pipelines as a bind did.
pub(super) unsafe fn record_deferred(wrapper: *mut c_void) {
let mut segs = Vec::new();
super::title_list::push_segments(wrapper, &mut segs);
let Some(&first) = segs.first() else { return };
segs.retain(|&seg| seg == first || LISTS.lock().unwrap().as_ref().and_then(|m| m.get(&(seg as usize))).is_some_and(|s| s.deferred.is_some()));
let mut last: Option<*mut c_void> = None;
for (i, &seg) in segs.iter().enumerate().skip(1) {
for &ahead in segs[i..].iter().take(WANTED_AT_ONCE) {
super::bind::want_bound(ahead);
}
for &seg in segs.iter().skip(1) {
let Some((what, ty, heaps)) = LISTS.lock().unwrap().as_mut().and_then(|m| m.get_mut(&(seg as usize))).and_then(|s| Some((s.deferred.take()?, s.list_type?, s.bindings.heaps.clone()))) else {
continue;
};
Expand Down
33 changes: 25 additions & 8 deletions crates/xcl/src/hle/d3d12x/pso_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,28 @@ mod used_tests {
let _ = released(standin);
}

#[test]
fn a_build_a_submit_needs_is_wanted() {
let standin = 0x7E57_B006usize;
let (started_tx, started) = mpsc::channel();
submit(standin, true, Box::new(move || {
started_tx.send(()).unwrap();
let t = std::time::Instant::now();
while !build_is_wanted() && t.elapsed() < std::time::Duration::from_secs(10) {
std::thread::sleep(std::time::Duration::from_millis(1));
}
if build_is_wanted() { 0x5757 } else { 0 }
}));
started.recv().unwrap();
need_by_submit(standin);
let t = std::time::Instant::now();
while is_pending(standin) && t.elapsed() < std::time::Duration::from_secs(15) {
std::thread::sleep(std::time::Duration::from_millis(5));
}
assert_eq!(resolve(standin), 0x5757, "the build did not hear that a submit waits for it");
let _ = released(standin);
}

/// A worker's build hears that a bind waits for it (and only its own build does).
#[test]
fn a_waiting_bind_makes_the_build_wanted() {
Expand Down Expand Up @@ -1212,17 +1234,12 @@ pub fn is_pending(pso: usize) -> bool {
entry(pso).is_some_and(|p| !*p.done.lock().unwrap())
}

/// One of the title's threads is about to wait for `pso`.
pub fn want(pso: usize) {
if let Some(p) = entry(pso) {
p.want();
}
}

/// A call with `pso` was put off to the submit: its build goes before the workers' queue.
/// A call with `pso` was put off to the submit, which will wait for it: its build goes before the
/// workers' queue, as a wanted one.
pub fn need_by_submit(pso: usize) {
let Some(p) = entry(pso) else { return };
if !std::mem::replace(&mut p.demand.lock().unwrap().by_submit, true) {
p.want();
NEEDED.lock().unwrap().push_back(p);
let _ = queue().lock().unwrap().send(Box::new(|| ()));
}
Expand Down
Loading