diff --git a/crates/xcl/src/hle/d3d12x/late_release.rs b/crates/xcl/src/hle/d3d12x/late_release.rs index 18ddc684e7..b9b96b4d04 100644 --- a/crates/xcl/src/hle/d3d12x/late_release.rs +++ b/crates/xcl/src/hle/d3d12x/late_release.rs @@ -92,6 +92,16 @@ pub fn enabled() -> bool { *ON.get_or_init(|| !std::env::var("XCL_LATE_RELEASE").is_ok_and(|v| v.trim() == "0")) } +/// Force the one-time read of `XCL_LATE_RELEASE` on the calling (Wine) thread. +/// +/// D3DMetal calls `Release` on adopted resources from a native thread of its own, which has +/// no Wine TEB. Reading the environment there for the first time never returns. Calling +/// this from `real::adopt` -- on the Wine thread that creates the object -- makes sure the +/// `OnceLock` inside `enabled()` is already set before the host's thread can reach it. +pub fn init() { + let _ = enabled(); +} + /// how long a last `Release` itself waits for queues with nothing to do to say so const IDLE_WAIT: Duration = Duration::from_micros(300); diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index fed31e6224..d917a02d3e 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -714,6 +714,10 @@ pub unsafe fn adopt(obj: *mut c_void, kind: Kind) { if is_ext(v) { return; } + // Read the setting `res_release` needs here, on the thread adopting the object: D3DMetal + // releases the resources of an executed list on a thread of its own, which has no Wine TEB, + // and reading the environment there for the first time never returns. + super::late_release::init(); let ext = class_for(obj, v, kind); *(obj as *mut usize) = ext; }