From e52662546bb01c589c55cc3046a24dce33219977 Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Thu, 26 Nov 2026 00:25:03 -0800 Subject: [PATCH] D3D12.X: reserve split continuations without allocators The transactional split already reserves a closed continuation before closing the producer, but a cache miss made a private allocator, opened a list on it, and closed the list only to Reset it later onto the title allocator. CreateCommandList1 directly makes the required closed allocator-free object. Use that path when ID3D12Device4 is available and retain the existing allocator-backed path for older devices and Close-failure injection tests. This preserves the integrated preflight/commit/rollback model and allocator generation tracking. The Windows GNU library/test cross-check passed with existing warnings. Windows MSVC, GPU tests, and title smoke were not available here. Adapted from the CreateCommandList1 reservation concept in #2717 by Kalmarv with Claude Code (Claude Opus 5.5); its core close-before-create fix was already superseded by the integrated transactional split. Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/hle/d3d12x/list_x.rs | 12 ++++++++++++ crates/xcl/src/hle/d3d12x/real.rs | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index a55525abb8..6c66ebaffe 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -3534,6 +3534,18 @@ unsafe fn reserve_closed_segment( note_reserved_closed(spare as usize, ty); return Some(spare); } + // CreateCommandList1 produces exactly the allocator-free closed object the transaction + // needs. Keep the older path as a compatibility fallback for devices without ID3D12Device4. + #[cfg(test)] + let close_is_hooked = CLOSE_HOOK.lock().unwrap().iter().any(|h| h.0 == wrapper as usize); + #[cfg(not(test))] + let close_is_hooked = false; + if !close_is_hooked { + if let Some(made) = real::create_closed_pc_command_list(dev.as_raw(), ty) { + note_reserved_closed(made as usize, ty); + return Some(made); + } + } let temp: ID3D12CommandAllocator = dev.CreateCommandAllocator(ty).ok()?; if !real::is_adopted(temp.as_raw()) { real::adopt(temp.as_raw(), real::Kind::CommandAllocator); diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 912543a0b7..c8e6e6f312 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3331,6 +3331,31 @@ pub(super) unsafe fn create_raw_pc_command_list( }; (hr >= 0 && !out.is_null()).then_some(out) } + +/// Create a raw adopted PC command list already closed and without an allocator. Split +/// preparation can reserve this while the producer still records; it is Reset onto the title's +/// allocator only after that producer has closed. +pub(super) unsafe fn create_closed_pc_command_list(dev: *mut c_void, ty: D3D12_COMMAND_LIST_TYPE) -> Option<*mut c_void> { + if dev.is_null() { + return None; + } + let iid = layout::parse_guid(layout::find("ID3D12GraphicsCommandList")?.iid); + let mut out = std::ptr::null_mut(); + let hr = if is_ext(vt(dev) as usize) { + dev_create_command_list1(dev, 0, ty.0 as usize, D3D12_COMMAND_LIST_FLAG_NONE.0 as usize, &iid, &mut out) + } else { + let dev4 = ID3D12Device::from_raw_borrowed(&dev)?.cast::().ok()?; + match dev4.CreateCommandList1::(0, ty, D3D12_COMMAND_LIST_FLAG_NONE) { + Ok(list) => { + out = list.into_raw(); + adopt(out, Kind::CommandList); + 0 + } + Err(e) => e.code().0, + } + }; + (hr >= 0 && !out.is_null()).then_some(out) +} creator!(dev_create_descriptor_heap, "CreateDescriptorHeap", Kind::DescriptorHeap, [a1]); creator!(dev_create_committed_resource, "CreateCommittedResource", Kind::Resource, [a1, a2, a3, a4, a5]); creator!(dev_create_committed_resource1, "CreateCommittedResource1", Kind::Resource, [a1, a2, a3, a4, a5, a6]);