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
42 changes: 38 additions & 4 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn signature_dispatches(sig: usize) -> bool {
pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: usize, max: u32, args: usize, args_off: u64, count_buf: usize, count_off: u64) {
type F = unsafe extern "system" fn(*mut c_void, usize, u32, usize, u64, usize, u64);
let pc: F = std::mem::transmute(super::real::orig_fn(this, 59));
let pso = super::pso_async::resolve_wait(with(this, |s| s.pso));
let pso = pso_for_draw(with(this, |s| s.pso));
let (gfx, compute) = (super::real::is_translated_graphics(pso), super::real::is_translated_compute(pso));
let (args_off, count_off) = (args_off + super::real::buffer_delta(args), count_off + super::real::buffer_delta(count_buf));
if !gfx && !compute {
Expand Down Expand Up @@ -489,22 +489,31 @@ pub(super) unsafe fn emit_prepared_indexed_draw(
list.DrawIndexedInstanced(indices, instances, first_index, base_vertex, first_instance);
}

/// The pipeline a draw (or an ExecuteIndirect) uses now: a graphics pipeline still being built
/// is not waited for – its build goes to the workers and its stand-in, which draws nothing, is
/// used until it is built (`pso_async`). A compute one is waited for. Waiting held a retail
/// title's threads 1 – 5 s per draw in the driver's compiler (33 s in all as its world loaded,
/// on an NVIDIA GPU), and its hang watchdog ended it.
fn pso_for_draw(pso: usize) -> usize {
super::pso_async::resolve_for_bind(pso)
}

/// Before a draw: with a translated pipeline its ABI root signature and the kept graphics
/// arguments are bound (None: the draw is skipped – a console pipeline without a
/// translation, or no unified memory).
unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList> {
let list = ID3D12GraphicsCommandList::from_raw_borrowed(&this)?.clone();
let pso = with(this, |s| s.pso);
// a pipeline still being built in the background is waited for (its stand-in draws nothing)
if !super::real::is_translated_graphics(super::pso_async::resolve_wait(pso)) {
// a pipeline still being built in the background is not waited for (`pso_for_draw`)
if !super::real::is_translated_graphics(pso_for_draw(pso)) {
count(DRAWS_PC);
if super::present::trace_frame() {
// which pipelines draw without a translation (first 12 distinct)
static SEEN: Mutex<Vec<usize>> = Mutex::new(Vec::new());
let mut g = SEEN.lock().unwrap();
if !g.contains(&pso) && g.len() < 12 {
g.push(pso);
let real = super::pso_async::resolve_wait(pso);
let real = super::pso_async::resolve(pso);
crate::xlog_info!(
"frame trace: draw with an untranslated pipeline {pso:#x} (resolves to {real:#x}; pending {}, two-pass {}, RT0 {:?})",
super::pso_async::is_pending(pso),
Expand Down Expand Up @@ -1178,6 +1187,31 @@ void main(uint t : SV_GroupIndex) {
}
}

/// A draw does not wait for a graphics pipeline still being built: its build goes to the
/// workers and the draw gets the stand-in at once; once built, the real one. A compute
/// pipeline is still waited for.
#[test]
fn a_draw_does_not_wait_for_a_graphics_pipeline_still_being_built() {
let (graphics, compute) = (0x7E57_6101usize, 0x7E57_6102usize);
pso_async::submit_lazy(graphics, false, Box::new(|| {
std::thread::sleep(std::time::Duration::from_millis(1500));
0x1301
}), 0);
pso_async::submit_lazy(compute, true, Box::new(|| 0x1302), 0);
let t = std::time::Instant::now();
assert_eq!(pso_for_draw(graphics), graphics, "the stand-in, not the real one");
assert!(t.elapsed() < std::time::Duration::from_millis(500), "a draw waited {:?}", t.elapsed());
// the draw sent it to the workers: it is built with no further draw
let start = std::time::Instant::now();
while pso_async::is_pending(graphics) && start.elapsed() < std::time::Duration::from_secs(10) {
std::thread::sleep(std::time::Duration::from_millis(5));
}
assert_eq!(pso_for_draw(graphics), 0x1301, "built by a worker");
assert_eq!(pso_for_draw(compute), 0x1302, "a compute pipeline is waited for");
pso_async::released(graphics);
pso_async::released(compute);
}

/// Minimal RTS0 v2 root signature blob with one 4-constant parameter.
fn test_rts0_blob() -> Vec<u8> {
let words: [u32; 12] = [
Expand Down
Loading