From 2e85970aa5f53c8617985b380e4f35920e6d041c Mon Sep 17 00:00:00 2001 From: vakaobr <15154330+vakaobr@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:44:37 -0300 Subject: [PATCH] D3D12.X: read the late-release setting at adoption, not at first release D3DMetal calls Release on adopted resources from a native thread of its own at submit time. That thread has no Wine TEB, so the first-time std::env::var read inside the OnceLock in late_release::enabled() enters Wine's ntdll and never returns. Reading the setting once in adopt(), on the Wine thread that creates the object, makes sure the OnceLock is already set before the host's thread can reach it. Part of #258. Assisted-by: Claude Code (Claude Opus 4.6 (1M context)) --- crates/xcl/src/hle/d3d12x/late_release.rs | 10 ++++++++++ crates/xcl/src/hle/d3d12x/real.rs | 4 ++++ 2 files changed, 14 insertions(+) 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; }