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
9 changes: 5 additions & 4 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
if unbuilt_compute && super::list_x::defer(this, raw_pso, super::list_x::Deferred::Indirect(sig, max, args, args_off, count_buf, count_off)) {
return;
}
let (pso, bound_unbuilt) = super::pso_async::resolve_wait_bound(raw_pso);
let ((pso, bound_unbuilt), generation) = super::pso_async::resolve_wait_bound_and_pin_if_enabled(raw_pso);
super::list_x::record_native_generation(this as usize, generation);
let (gfx, compute) = (super::real::is_translated_graphics(pso), super::real::is_translated_compute(pso));
let args_off_title = args_off;
let (args_off, count_off) = (args_off + super::real::buffer_delta(args), count_off + super::real::buffer_delta(count_buf));
Expand Down Expand Up @@ -650,7 +651,7 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList>
let list = ID3D12GraphicsCommandList::from_raw_borrowed(&this)?.clone();
let pso = with(this, |s| s.pso);
// a pipeline still being built in the background is waited for (its stand-in draws nothing)
let real = super::pso_async::resolve_wait(pso);
let real = super::list_x::resolve_and_record_pipeline_wait(list.as_raw() as usize, pso);
if !super::real::is_translated_graphics(real) {
// A finished two-pass MS/GS pipeline is a PC mesh shader pipeline (MS+PS) registered in
// TWO_PASS rather than TRANSLATED_GRAPHICS. Binding the title's graphics RS and issuing
Expand Down Expand Up @@ -1013,7 +1014,7 @@ pub(super) unsafe fn dispatch_flags(this: *mut c_void, x: u32, y: u32, z: u32, f
if super::pso_async::is_pending(pso) && super::list_x::defer(this, pso, super::list_x::Deferred::Dispatch(x, y, z, flags)) {
return;
}
let pso = super::pso_async::resolve_wait(pso);
let pso = super::list_x::resolve_and_record_pipeline_wait(this as usize, pso);
let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return };
if !super::real::is_translated_compute(pso) {
// a console pipeline without a translation (including a background build that
Expand Down Expand Up @@ -1199,7 +1200,7 @@ unsafe fn bind_abi_with_root(
Ok(p as usize)
};
// a pipeline still being built in the background is waited for
let real = super::pso_async::resolve_wait(pso);
let real = super::list_x::resolve_and_record_pipeline_wait(list.as_raw() as usize, pso);
// a compute shader takes no more arguments from registers than it has (`inline_for`)
let user_sgprs = if gfx { None } else { super::real::pso_user_sgprs(real) };
let inline = layout.as_ref().map_or(0, |l| if gfx { l.inline_gfx } else { console_list::inline_for(l, user_sgprs) } as usize).min(args.len());
Expand Down
27 changes: 25 additions & 2 deletions crates/xcl/src/hle/d3d12x/console_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,18 @@ unsafe extern "system" fn cl_reset(this: *mut c_void, allocator: *mut c_void, ps
}
with_list(obj, |st| new_chunk(obj, st));
let f: unsafe extern "system" fn(usize, *mut c_void, *mut c_void) -> HRESULT = std::mem::transmute(pc_vtable_call(pc, 10));
f(pc, allocator, pc_pso(pso))
// The adopted physical slot reaches real::cl_reset, which resolves and records the initial
// generation. Do not clear that capture again in this outer console wrapper.
forward_reset(pc, allocator, pso, |pc, allocator, pso| f(pc, allocator, pso))
}

unsafe fn forward_reset(
pc: usize,
allocator: *mut c_void,
pso: *mut c_void,
call: impl FnOnce(usize, *mut c_void, *mut c_void) -> HRESULT,
) -> HRESULT {
call(pc, allocator, pc_pso(pso))
}

unsafe extern "system" fn cl_dispatch(this: *mut c_void, x: u32, y: u32, z: u32) {
Expand Down Expand Up @@ -890,7 +901,7 @@ pub unsafe fn close(obj: *mut c_void) -> Result<Translation, String> {
// a pipeline still being built in the background is waited for; if
// the background translation failed, skip instead of binding XCL's
// ABI root signature onto the stand-in
let real = super::pso_async::resolve_wait((*p).pc);
let real = super::list_x::resolve_and_record_pipeline_wait(st.pc, (*p).pc);
if !super::real::is_translated_compute(real) {
out.skipped_dispatches += 1;
continue;
Expand Down Expand Up @@ -997,6 +1008,18 @@ fn bytemuck_u32(v: &[u32]) -> &[u8] {
mod tests {
use super::*;

#[test]
fn console_reset_preserves_the_physical_initial_generation_capture() {
let mut pins = vec![1u64];
let hr = unsafe { forward_reset(0xC1, std::ptr::null_mut(), std::ptr::null_mut(), |_, _, _| {
pins.clear();
pins.push(2);
S_OK
}) };
assert_eq!(hr, S_OK);
assert_eq!(pins, [2], "the outer wrapper must not clear the physical Reset hook's new pin");
}

#[test]
fn layout_packs_parameters_in_order() {
// RTS0 v2: consts b0 x19 | UAV u0 | UAV u1 | SRV t0
Expand Down
3 changes: 2 additions & 1 deletion crates/xcl/src/hle/d3d12x/device_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ unsafe fn create_list(this: *mut c_void, node: u32, ty: u32, alloc: usize, pso:
let hr = if super::console_list::enabled() {
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 (resolved_pso, generation) = super::pso_async::resolve_and_pin_if_enabled(pso);
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_with_backing(*ppv, alloc, pc_alloc, pso, D3D12_COMMAND_LIST_TYPE(ty as i32));
super::list_x::record_native_generation(*ppv as usize, generation);
super::dred::reset(*ppv);
if pso != 0 {
super::dred::mark_pipeline(*ppv, pso, resolved_pso);
Expand Down
Loading
Loading