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]);