Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions crates/xcl/src/hle/d3d12x/device_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ pub(super) unsafe extern "system" fn create_command_allocator_x(this: *mut c_voi
real::dev_create_command_allocator(this, pc_list_type(ty) as usize, riid, ppv)
}

fn active_list_allocator(alloc: usize) -> usize {
active_list_allocator_with(alloc, super::alloc_pool::current)
}

fn active_list_allocator_with(alloc: usize, current: impl FnOnce(usize) -> usize) -> usize {
current(alloc)
}

unsafe fn create_list(this: *mut c_void, node: u32, ty: u32, alloc: usize, pso: usize, riid: *const GUID, ppv: *mut *mut c_void) -> HRESULT {
let dma = !riid.is_null() && guid_bytes(&*riid) == guid_bytes(&IID_XBOX_DMA_COMMAND_LIST);
let riid = if dma { &IID_GRAPHICS_COMMAND_LIST as *const GUID } else { riid };
Expand All @@ -97,9 +105,10 @@ unsafe fn create_list(this: *mut c_void, node: u32, ty: u32, alloc: usize, pso:
real::dev_create_command_list_x(this, node, ty, alloc, pso, riid, ppv)
} else {
let resolved_pso = super::pso_async::resolve_for_bind(pso);
let hr = real::dev_create_command_list(this, node, ty, alloc, resolved_pso, riid, ppv);
let pc_alloc = active_list_allocator(alloc);
let hr = real::dev_create_command_list(this, node, ty, pc_alloc, resolved_pso, riid, ppv);
if hr >= 0 && !ppv.is_null() && !(*ppv).is_null() {
super::list_x::on_create(*ppv, alloc, pso, D3D12_COMMAND_LIST_TYPE(ty as i32));
super::list_x::on_create_with_backing(*ppv, alloc, pc_alloc, pso, D3D12_COMMAND_LIST_TYPE(ty as i32));
super::dred::reset(*ppv);
if pso != 0 {
super::dred::mark_pipeline(*ppv, pso, resolved_pso);
Expand Down Expand Up @@ -1333,6 +1342,14 @@ pub(super) unsafe extern "system" fn create_command_signature_x(this: *mut c_voi
mod tests {
use super::*;

#[test]
fn new_command_lists_use_the_allocator_pools_active_backing() {
assert_eq!(active_list_allocator_with(0x1000, |alloc| {
assert_eq!(alloc, 0x1000);
0x2000
}), 0x2000);
}

#[test]
fn console_types_and_descs_become_pc_ones() {
assert_eq!(pc_list_type(XBOX_TYPE_DMA), D3D12_COMMAND_LIST_TYPE_COPY.0 as u32);
Expand Down
28 changes: 27 additions & 1 deletion crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,14 @@ unsafe fn try_native_depth_bias(list: *mut c_void, bias: DepthBias) -> bool {
/// # Safety
/// `list` must be null or a valid `ID3D12GraphicsCommandList` COM pointer.
pub unsafe fn on_create(list: *mut c_void, alloc: usize, pso: usize, ty: D3D12_COMMAND_LIST_TYPE) {
on_create_with_backing(list, alloc, alloc, pso, ty)
}

/// Record a newly created command list's logical title allocator and native recording backing.
///
/// # Safety
/// `list` must be null or a valid `ID3D12GraphicsCommandList` COM pointer.
pub(super) unsafe fn on_create_with_backing(list: *mut c_void, alloc: usize, backing: usize, pso: usize, ty: D3D12_COMMAND_LIST_TYPE) {
if list.is_null() {
return;
}
Expand All @@ -1258,7 +1266,7 @@ pub unsafe fn on_create(list: *mut c_void, alloc: usize, pso: usize, ty: D3D12_C
WRITE64_SIGNAL_LISTS.fetch_sub(1, Ordering::AcqRel);
}
}
super::alloc_pool::created_on(key, alloc, ty.0);
super::alloc_pool::created_on(key, backing, ty.0);
m.insert(key, ListState { allocator: alloc, list_type: Some(ty), bound_pso: pso, ..Default::default() });
old
};
Expand Down Expand Up @@ -5355,6 +5363,24 @@ mod tests {
use super::*;
use std::sync::Arc;

#[test]
fn creation_keeps_logical_allocator_separate_from_recording_backing() {
let list = 0x7e57_a101usize as *mut c_void;
let (logical, backing) = (0x7e57_a110usize, 0x7e57_a120usize);
unsafe { on_create_with_backing(list, logical, backing, 0, D3D12_COMMAND_LIST_TYPE_DIRECT) };

let tracked = LISTS.lock().unwrap().as_ref().unwrap()[&(list as usize)].allocator;
assert_eq!(tracked, logical);
assert_eq!(super::super::alloc_pool::recording_backing_for_test(list as usize), Some(backing));

on_allocator_release(logical);
assert_eq!(LISTS.lock().unwrap().as_ref().unwrap()[&(list as usize)].allocator, 0);
assert_eq!(super::super::alloc_pool::recording_backing_for_test(list as usize), Some(backing));

LISTS.lock().unwrap().as_mut().unwrap().remove(&(list as usize));
super::super::alloc_pool::forget_list(list as usize);
}

#[test]
fn mirror_snapshot_keeps_order_and_refreshes_only_on_miss() {
let first = (100, 100, 1_000);
Expand Down
Loading