From 73c8e740170d8f8412e6971c2252e12f46227607 Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Mon, 23 Nov 2026 19:01:20 +0100 Subject: [PATCH 1/3] D3D12.X: build console pipelines at their first use; urgent compiles for waiting title threads GTA VI (retail, GDK) creates ~51 000 distinct pipelines in its first 30 s. Each one built at creation stays in AMD's driver heap (~400 KB): commit went past 45 GB and the system ran out. Pipelines with console shaders now get their stand-in at creation and are built the first time they are bound (pso_async::submit_lazy, sent to the workers on the first `resolve`; compute is waited for as before). XCL_LAZY_PSO=0 builds them all at creation as before. A title thread with no stand-in waits in its own call for the translation: its DXC compiles now run at once on a thread of their own (dxc::urgent) instead of queueing behind thousands of background jobs held by the memory gate. GTA VI's watchdog killed the game when one of its threads stayed silent ~30 s. resolve_wait builds a pipeline nobody sent yet on the spot. Stand-ins also get the PC topology type (pc_topology_type): the console's rect list / none were refused (0x80070057) and the title waited in the call instead. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B --- crates/xcl/src/gpu/recomp/dxc.rs | 38 +++++++ crates/xcl/src/hle/d3d12x/pso_async.rs | 139 +++++++++++++++++++------ crates/xcl/src/hle/d3d12x/real.rs | 88 +++++++++++++--- 3 files changed, 218 insertions(+), 47 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/dxc.rs b/crates/xcl/src/gpu/recomp/dxc.rs index 894a96758..532910d6f 100644 --- a/crates/xcl/src/gpu/recomp/dxc.rs +++ b/crates/xcl/src/gpu/recomp/dxc.rs @@ -194,12 +194,50 @@ fn pool() -> &'static std::sync::Mutex> { /// Compile HLSL to signed DXIL. `profile` e.g. "cs_6_6"; `extra` are dxc arguments. pub fn compile(src: &str, entry: &str, profile: &str, extra: &[&str]) -> Result, String> { + if URGENT.with(|u| u.get()) { + return compile_now(src, entry, profile, extra); + } let (reply, rx) = std::sync::mpsc::channel(); let job = Job { src: src.into(), entry: entry.into(), profile: profile.into(), extra: extra.iter().map(|s| s.to_string()).collect(), reply }; pool().lock().unwrap().send(job).map_err(|_| "DXC: no compile threads".to_string())?; rx.recv().map_err(|_| "DXC: the compile thread exited".to_string())? } +thread_local! { + /// inside `urgent` + static URGENT: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// Run `f` with its DXC compiles done at once, on a thread of their own: not queued behind the +/// background pipelines on the workers, not held by `wait_for_memory`. For a title thread that +/// waits in its pipeline creation (no stand-in): GTA VI's watchdog kills the game when one of +/// its threads stays silent ~30 s, and with commit short most workers sat in `wait_for_memory` +/// holding queued jobs while five title threads waited behind them. +pub fn urgent(f: impl FnOnce() -> R) -> R { + let prev = URGENT.with(|u| u.replace(true)); + let r = f(); + URGENT.with(|u| u.set(prev)); + r +} + +/// `compile` on a fresh `DXC_STACK` thread, waited for (counted in `WORKING`, so the workers' +/// `wait_for_memory` sees it). +fn compile_now(src: &str, entry: &str, profile: &str, extra: &[&str]) -> Result, String> { + WORKING.fetch_add(1, std::sync::atomic::Ordering::AcqRel); + let _slot = MemorySlot; + std::thread::scope(|s| { + let t = std::thread::Builder::new() + .name("xcl-dxc-urgent".into()) + .stack_size(DXC_STACK) + .spawn_scoped(s, || { + std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| compile_here(src, entry, profile, extra))) + .unwrap_or_else(|_| Err("DXC: panic in the compile thread".into())) + }) + .map_err(|e| format!("DXC: cannot start a compile thread: {e}"))?; + t.join().unwrap_or_else(|_| Err("DXC: the compile thread panicked".into())) + }) +} + fn compile_here(src: &str, entry: &str, profile: &str, extra: &[&str]) -> Result, String> { let c = compiler()?; let mut args: Vec> = ["-E", entry, "-T", profile, "-HV", "2021"].iter().map(|a| crate::util::wide(a)).collect(); diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index a8cc75d57..70483f41f 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -19,6 +19,11 @@ struct Pending { compute: bool, /// the stand-in was released before the real pipeline was built orphan: std::sync::atomic::AtomicBool, + /// the build, until a worker – or a title thread that cannot wait for the queue + /// (`resolve_wait`) – takes it + job: Mutex>, + /// sent to the workers (a lazy pipeline is sent at its first use) + queued: std::sync::atomic::AtomicBool, } /// stand-in handed to the title → its real pipeline @@ -33,44 +38,53 @@ pub fn enabled() -> bool { /// Builds the real pipeline: its raw pointer, 0 = failed. pub type Job = Box usize + Send>; -fn queue() -> &'static Mutex, Job)>> { - static Q: OnceLock, Job)>>> = OnceLock::new(); +/// Stack of the threads that build pipelines: translation recurses deeply on big programs. +const BUILD_STACK: usize = 64 << 20; + +fn queue() -> &'static Mutex>> { + static Q: OnceLock>>> = OnceLock::new(); Q.get_or_init(|| { - let (tx, rx) = mpsc::channel::<(Arc, Job)>(); + let (tx, rx) = mpsc::channel::>(); let rx = Arc::new(Mutex::new(rx)); - // translation recurses deeply on big programs; DXC itself runs on its own pool + // DXC itself runs on its own pool let n = crate::gpu::recomp::dxc::compile_threads(); for k in 0..n { let rx = rx.clone(); - let _ = std::thread::Builder::new().name(format!("xcl-pso-{k}")).stack_size(64 << 20).spawn(move || loop { + let _ = std::thread::Builder::new().name(format!("xcl-pso-{k}")).stack_size(BUILD_STACK).spawn(move || loop { let next = rx.lock().unwrap().recv(); - let Ok((p, job)) = next else { return }; - let real = job(); - if real == 0 { - FAILED.fetch_add(1, Ordering::Relaxed); - } else { - BUILT.fetch_add(1, Ordering::Relaxed); - } - let orphan = { - let mut done = p.done.lock().unwrap(); - let orphan = p.orphan.load(Ordering::Acquire); - if !orphan { - p.real.store(real, Ordering::Release); - } - *done = true; - p.cv.notify_all(); - orphan - }; - // outside `done`: the Release override takes PENDING (`counts` takes PENDING, then `done`) - if orphan { - release(real); - } + let Ok(p) = next else { return }; + // a title thread may have taken it already (`resolve_wait`) + let Some(job) = p.job.lock().unwrap().take() else { continue }; + finish(&p, job()); }); } Mutex::new(tx) }) } +/// Hand a built pipeline (0 = failed) to whoever waits for it. +fn finish(p: &Pending, real: usize) { + if real == 0 { + FAILED.fetch_add(1, Ordering::Relaxed); + } else { + BUILT.fetch_add(1, Ordering::Relaxed); + } + let orphan = { + let mut done = p.done.lock().unwrap(); + let orphan = p.orphan.load(Ordering::Acquire); + if !orphan { + p.real.store(real, Ordering::Release); + } + *done = true; + p.cv.notify_all(); + orphan + }; + // outside `done`: the Release override takes PENDING (`counts` takes PENDING, then `done`) + if orphan { + release(real); + } +} + /// Release a pipeline state XCL owns (raw pointer, 0 = none). pub fn release(p: usize) { if p != 0 { @@ -80,13 +94,53 @@ pub fn release(p: usize) { /// `standin` went to the title; `job` builds the real pipeline on a worker. pub fn submit(standin: usize, compute: bool, job: Job) { - let p = Arc::new(Pending { real: AtomicUsize::new(0), done: Mutex::new(false), cv: Condvar::new(), compute, orphan: Default::default() }); - PENDING.lock().unwrap().get_or_insert_with(HashMap::new).insert(standin, p.clone()); + let p = pending(standin, compute, job); static ONCE: std::sync::Once = std::sync::Once::new(); ONCE.call_once(|| { crate::xlog_info!("D3D12.X: pipelines whose shaders are not compiled yet get a stand-in and are built in the background"); }); - let _ = queue().lock().unwrap().send((p, job)); + send(p); +} + +/// Pipelines built at their first use (`submit_lazy`), `XCL_LAZY_PSO=0` to build each when +/// the title creates it. A title can create far more pipelines than it draws with: the retail +/// GTA VI creates ~51 000 different ones in its first 30 s; each a pipeline in AMD's driver +/// (~400 KB of its heap) took 20 GB of commit and the system ran out. +pub fn lazy() -> bool { + static ON: OnceLock = OnceLock::new(); + *ON.get_or_init(|| enabled() && std::env::var("XCL_LAZY_PSO").map_or(true, |v| v != "0")) +} + +/// `submit`, the build waiting for the stand-in's first use (`resolve`, `resolve_wait`). +pub fn submit_lazy(standin: usize, compute: bool, job: Job) { + pending(standin, compute, job); + let n = LAZY.fetch_add(1, Ordering::Relaxed) + 1; + if n == 1 || n % 10_000 == 0 { + crate::xlog_info!("D3D12.X: pipelines are built at their first use ({n} created so far)"); + } +} + +static LAZY: AtomicUsize = AtomicUsize::new(0); + +fn pending(standin: usize, compute: bool, job: Job) -> Arc { + let p = Arc::new(Pending { + real: AtomicUsize::new(0), + done: Mutex::new(false), + cv: Condvar::new(), + compute, + orphan: Default::default(), + job: Mutex::new(Some(job)), + queued: Default::default(), + }); + PENDING.lock().unwrap().get_or_insert_with(HashMap::new).insert(standin, p.clone()); + p +} + +/// To the workers, once. +fn send(p: Arc) { + if !p.queued.swap(true, Ordering::AcqRel) { + let _ = queue().lock().unwrap().send(p); + } } fn entry(pso: usize) -> Option> { @@ -95,15 +149,36 @@ fn entry(pso: usize) -> Option> { /// The pipeline to use for `pso` now: the real one once built, else `pso` itself. pub fn resolve(pso: usize) -> usize { - match entry(pso).map(|p| p.real.load(Ordering::Acquire)) { - Some(r) if r != 0 => r, - _ => pso, + let Some(p) = entry(pso) else { return pso }; + match p.real.load(Ordering::Acquire) { + 0 => { + // a lazy pipeline's first use: build it now (the stand-in draws nothing meanwhile) + send(p); + pso + } + r => r, } } /// `resolve`, waiting for a pipeline still being built. pub fn resolve_wait(pso: usize) -> usize { let Some(p) = entry(pso) else { return pso }; + // not started yet: build it now instead of waiting behind the whole queue (thousands of + // pipelines while a title loads – GTA VI's watchdog killed the game while a title thread + // waited here), on a thread with the translator's stack, its compiles first + let job = p.job.lock().unwrap().take(); + if let Some(job) = job { + let real = std::thread::scope(|s| { + std::thread::Builder::new() + .name("xcl-pso-urgent".into()) + .stack_size(BUILD_STACK) + .spawn_scoped(s, || crate::gpu::recomp::dxc::urgent(job)) + .ok() + .and_then(|t| t.join().ok()) + .unwrap_or(0) + }); + finish(&p, real); + } let mut done = p.done.lock().unwrap(); while !*done { done = p.cv.wait(done).unwrap(); diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 3e7a44f19..88e1c5911 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3121,6 +3121,9 @@ unsafe fn standin_graphics(this: *mut c_void, f: PsoFn, desc: *const c_void, rii copy.StreamOutput = std::mem::zeroed(); copy.InputLayout = D3D12_INPUT_LAYOUT_DESC::default(); copy.CachedPSO = D3D12_CACHED_PIPELINE_STATE::default(); + // the console's topology types (rect list 19, none) are not the PC's: the driver refused + // GTA VI's stand-ins (0x80070057) and the title waited in the call for its compiles + pc_topology_type(&mut copy); finish_pso(this, f, © as *const _ as *const c_void, riid, ppv) } @@ -3158,21 +3161,62 @@ unsafe fn go_background( return None; } let dev = Dev(this as usize, f as usize); - super::pso_async::submit( - *ppv as usize, - compute, - Box::new(move || { - let mut out: *mut c_void = std::ptr::null_mut(); - if unsafe { build(dev, &owned, &mut out) } && !out.is_null() { - out as usize - } else { - 0 - } - }), - ); + let job: super::pso_async::Job = Box::new(move || { + let mut out: *mut c_void = std::ptr::null_mut(); + if unsafe { build(dev, &owned, &mut out) } && !out.is_null() { + out as usize + } else { + 0 + } + }); + if LAZY_NEXT.with(|l| l.replace(false)) { + super::pso_async::submit_lazy(*ppv as usize, compute, job); + } else { + super::pso_async::submit(*ppv as usize, compute, job); + } Some(hr) } +thread_local! { + /// the next `go_background` builds at the pipeline's first use (`go_lazy`) + static LAZY_NEXT: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// `go_background` with the build left for the stand-in's first use (`pso_async::lazy`). +#[allow(clippy::too_many_arguments)] +unsafe fn go_lazy( + this: *mut c_void, + f: PsoFn, + desc: *const c_void, + riid: *const GUID, + ppv: *mut *mut c_void, + compute: bool, + owned: OwnedDesc, + standin: unsafe fn(*mut c_void, PsoFn, *const c_void, *const GUID, *mut *mut c_void) -> HRESULT, + build: unsafe fn(Dev, &OwnedDesc, *mut *mut c_void) -> bool, +) -> Option { + LAZY_NEXT.with(|l| l.set(true)); + let r = go_background(this, f, desc, riid, ppv, compute, owned, standin, build); + LAZY_NEXT.with(|l| l.set(false)); + r +} + +/// The title's pipeline has console shaders (what `go_lazy` defers). +unsafe fn console_graphics(desc: *const c_void) -> bool { + use crate::gpu::recomp::pso::is_console; + if !crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) { + return false; + } + let d = &*(desc as *const D3D12_GRAPHICS_PIPELINE_STATE_DESC); + shader_bytes(&d.VS).is_some_and(is_console) && shader_bytes(&d.HS).is_none() && shader_bytes(&d.DS).is_none() && shader_bytes(&d.GS).is_none() +} + +unsafe fn console_compute(desc: *const c_void) -> bool { + use crate::gpu::recomp::pso::is_console; + crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) + && shader_bytes(&(*(desc as *const D3D12_COMPUTE_PIPELINE_STATE_DESC)).CS).is_some_and(is_console) +} + unsafe fn build_graphics(dev: Dev, d: &OwnedDesc, out: *mut *mut c_void) -> bool { let iid = pc_iid(Kind::PipelineState); matches!(translated_graphics_pso(dev.0 as *mut c_void, std::mem::transmute::(dev.1), d.ptr(), &iid, out), Some(hr) if hr >= 0) @@ -3191,12 +3235,18 @@ unsafe fn build_stream(dev: Dev, d: &OwnedDesc, out: *mut *mut c_void) -> bool { pub(super) unsafe extern "system" fn dev_create_graphics_pso(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { super::null::capture_graphics_desc(desc as *const u8); let f: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreateGraphicsPipelineState"))); + if super::pso_async::lazy() && console_graphics(desc) { + if let Some(hr) = own_graphics(desc).and_then(|o| go_lazy(this, f, desc, riid, ppv, false, o, standin_graphics, build_graphics)) { + return hr; + } + } let (translated, missed) = if super::pso_async::enabled() { attempt(|| translated_graphics_pso(this, f, desc, riid, ppv)) } else { (translated_graphics_pso(this, f, desc, riid, ppv), false) }; if missed { if let Some(hr) = own_graphics(desc).and_then(|o| go_background(this, f, desc, riid, ppv, false, o, standin_graphics, build_graphics)) { return hr; } - if let Some(hr) = translated_graphics_pso(this, f, desc, riid, ppv) { + // no stand-in: the title waits in this call – its compiles go first + if let Some(hr) = crate::gpu::recomp::dxc::urgent(|| translated_graphics_pso(this, f, desc, riid, ppv)) { return hr; } } else if let Some(hr) = translated { @@ -3235,6 +3285,14 @@ unsafe fn note_translated_compute(hr: HRESULT, ppv: *mut *mut c_void) { unsafe extern "system" fn dev_create_compute_pso(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { super::null::capture_compute_desc(desc as *const u8); let f: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreateComputePipelineState"))); + if super::pso_async::lazy() && console_compute(desc) { + if let Some(hr) = own_compute(desc).and_then(|o| go_lazy(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) { + // as for go_background below: built (and registered) at its first dispatch + LAST_COMPUTE_TRANSLATED.with(|c| c.set(true)); + LAST_COMPUTE_RS.with(|c| c.set(0)); + return hr; + } + } let (mut console, missed) = if super::pso_async::enabled() { attempt(|| translated_compute_pso(this, f, desc, riid, ppv)) } else { (translated_compute_pso(this, f, desc, riid, ppv), false) }; if missed { if let Some(hr) = own_compute(desc).and_then(|o| go_background(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) { @@ -3246,7 +3304,7 @@ unsafe extern "system" fn dev_create_compute_pso(this: *mut c_void, desc: *const LAST_COMPUTE_RS.with(|c| c.set(0)); return hr; } - console = translated_compute_pso(this, f, desc, riid, ppv); + console = crate::gpu::recomp::dxc::urgent(|| translated_compute_pso(this, f, desc, riid, ppv)); } LAST_COMPUTE_TRANSLATED.with(|c| c.set(matches!(console, Some(Ok(hr)) if hr >= 0))); if let Some(Ok(hr)) = console { @@ -3734,7 +3792,7 @@ pub(super) unsafe extern "system" fn dev_create_pipeline_state(this: *mut c_void if let Some(hr) = own_stream(desc).and_then(|o| go_background(this, f, desc, riid, ppv, false, o, standin_stream, build_stream)) { return hr; } - if let Some(hr) = translated_mesh_stream(this, desc, riid, ppv) { + if let Some(hr) = crate::gpu::recomp::dxc::urgent(|| translated_mesh_stream(this, desc, riid, ppv)) { return hr; } } else if let Some(hr) = translated { From 641f55143864349fa3a5dd02557512af8fe0e43d Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Mon, 23 Nov 2026 20:02:58 +0100 Subject: [PATCH 2/3] D3D12.X: build only graphics pipelines at their first use With GTA VI's compute pipelines built at their first dispatch the device was removed ~20 s in (an invalid call, nothing from the debug layer before it); with graphics ones only it runs at 30 fps. Compute pipelines are far fewer and their first bind waits for them anyway. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XTYmP6vKUQKatSiA2PC95B --- crates/xcl/src/hle/d3d12x/real.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index c03acb9df..bba3211a7 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3242,7 +3242,9 @@ unsafe fn go_lazy( r } -/// The title's pipeline has console shaders (what `go_lazy` defers). +/// The title's graphics pipeline has console shaders (what `go_lazy` defers). Compute pipelines +/// are not deferred: with GTA VI's built at their first dispatch the device was removed (an +/// invalid call, ~20 s in); there are far fewer of them and their first bind waits anyway. unsafe fn console_graphics(desc: *const c_void) -> bool { use crate::gpu::recomp::pso::is_console; if !crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) { @@ -3252,11 +3254,6 @@ unsafe fn console_graphics(desc: *const c_void) -> bool { shader_bytes(&d.VS).is_some_and(is_console) && shader_bytes(&d.HS).is_none() && shader_bytes(&d.DS).is_none() && shader_bytes(&d.GS).is_none() } -unsafe fn console_compute(desc: *const c_void) -> bool { - use crate::gpu::recomp::pso::is_console; - crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) - && shader_bytes(&(*(desc as *const D3D12_COMPUTE_PIPELINE_STATE_DESC)).CS).is_some_and(is_console) -} unsafe fn build_graphics(dev: Dev, d: &OwnedDesc, out: *mut *mut c_void) -> bool { let iid = pc_iid(Kind::PipelineState); @@ -3326,14 +3323,6 @@ unsafe fn note_translated_compute(hr: HRESULT, ppv: *mut *mut c_void) { unsafe extern "system" fn dev_create_compute_pso(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { super::null::capture_compute_desc(desc as *const u8); let f: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreateComputePipelineState"))); - if super::pso_async::lazy() && console_compute(desc) { - if let Some(hr) = own_compute(desc).and_then(|o| go_lazy(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) { - // as for go_background below: built (and registered) at its first dispatch - LAST_COMPUTE_TRANSLATED.with(|c| c.set(true)); - LAST_COMPUTE_RS.with(|c| c.set(0)); - return hr; - } - } let (mut console, missed) = if super::pso_async::enabled() { attempt(|| translated_compute_pso(this, f, desc, riid, ppv)) } else { (translated_compute_pso(this, f, desc, riid, ppv), false) }; if missed { if let Some(hr) = own_compute(desc).and_then(|o| go_background(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) { From 7db28b0f8b14199af6cab6eb10d26a73caddc3f2 Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Mon, 23 Nov 2026 21:42:10 +0100 Subject: [PATCH 3/3] D3D12.X: console compute pipelines are built at their first dispatch too Built at creation, GTA VI's thousands of compute pipelines took 60+ GB of commit in AMD's driver within a minute and the game never left its loading screen (no dispatch at all in 80 s). The device removal this deferral once caused was not the deferral: invalid UAVs of depth buffers (fixed in #163) used by the dispatches it let the game reach. With both, GTA VI reaches its title screen and menus. `XCL_LAZY_COMPUTE=0` builds them at creation. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SKtJseucqXR6iuAE6HBtiA --- crates/xcl/src/hle/d3d12x/real.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index bba3211a7..eaf4141b4 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3242,9 +3242,7 @@ unsafe fn go_lazy( r } -/// The title's graphics pipeline has console shaders (what `go_lazy` defers). Compute pipelines -/// are not deferred: with GTA VI's built at their first dispatch the device was removed (an -/// invalid call, ~20 s in); there are far fewer of them and their first bind waits anyway. +/// The title's graphics pipeline has console shaders (what `go_lazy` defers). unsafe fn console_graphics(desc: *const c_void) -> bool { use crate::gpu::recomp::pso::is_console; if !crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) { @@ -3323,6 +3321,21 @@ unsafe fn note_translated_compute(hr: HRESULT, ppv: *mut *mut c_void) { unsafe extern "system" fn dev_create_compute_pso(this: *mut c_void, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT { super::null::capture_compute_desc(desc as *const u8); let f: PsoFn = std::mem::transmute(orig_fn(this, slot_of(this, "CreateComputePipelineState"))); + // console compute pipelines are built at their first dispatch too (`XCL_LAZY_COMPUTE=0`: at + // creation): GTA VI creates thousands while it loads and dispatches a few hundred; built at + // creation, AMD's driver held 60+ GB of commit within a minute and the title never left its + // loading screen + if super::pso_async::lazy() + && std::env::var("XCL_LAZY_COMPUTE").map_or(true, |v| v != "0") + && crate::gpu::shader::readable(desc as usize, std::mem::size_of::()) + && shader_bytes(&(*(desc as *const D3D12_COMPUTE_PIPELINE_STATE_DESC)).CS).is_some_and(crate::gpu::recomp::pso::is_console) + { + if let Some(hr) = own_compute(desc).and_then(|o| go_lazy(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) { + LAST_COMPUTE_TRANSLATED.with(|c| c.set(true)); + LAST_COMPUTE_RS.with(|c| c.set(0)); + return hr; + } + } let (mut console, missed) = if super::pso_async::enabled() { attempt(|| translated_compute_pso(this, f, desc, riid, ppv)) } else { (translated_compute_pso(this, f, desc, riid, ppv), false) }; if missed { if let Some(hr) = own_compute(desc).and_then(|o| go_background(this, f, desc, riid, ppv, true, o, standin_compute, build_compute)) {