Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper.
watchdog for a GPU queue wait (5000 ms). A value that is not a number above 0 keeps the
default. Expiry stops the title before later GPU work is submitted; it never treats elapsed
time as proof that the waited-for work completed.
- `XCL_MAP_SYNC=1`: forces a synchronous GPU readback on every `ID3D12Resource::Map` of a
sparse console buffer instead of skipping pages whose GPU writes are already tracked.
- Retired two-pass mesh buffers from tracked command lists can be reused once all GPU
submissions that used them complete, even while the title still holds the command allocator.
- Direct two-pass mesh draws can reuse one smaller record buffer across several slices when
Expand Down
70 changes: 70 additions & 0 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ pub(super) unsafe fn flush_two_pass(this: *mut c_void, why: RunEnd) {
}
return;
}
super::list_x::note_untracked_gpu_write(this);
let (Some(list), Some(records)) = (ID3D12GraphicsCommandList::from_raw_borrowed(&this), records) else { return };
RUN_ENDS[run_end_index(why)].fetch_add(1, Ordering::Relaxed);
let steps: Vec<Step> = items.iter().map(RunItem::step).collect();
Expand Down Expand Up @@ -3378,6 +3379,7 @@ fn note_no_root_signature() {
}

pub(super) unsafe extern "system" fn dispatch_mesh(this: *mut c_void, x: u32, y: u32, z: u32) {
super::list_x::note_untracked_gpu_write(this);
let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailDraw);
let _t = crate::hle::api_cost::time_if(super::look_stats::deep(), crate::hle::api_cost::Call::DrawRecord);
let _c = capture_work(this, || super::capture::WorkKind::DispatchMesh([x, y, z]), true);
Expand Down Expand Up @@ -3526,6 +3528,7 @@ pub(super) unsafe fn execute_indirect_classified(
this: *mut c_void, sig: usize, max: u32, args: usize, args_off: u64,
count_buf: usize, count_off: u64, signature: IndirectSignatureInfo,
) {
super::list_x::note_untracked_gpu_write(this);
let (pso, resolution) = with(this, |state| (state.pso, state.resolution.clone()));
execute_indirect_snapshot(
this, sig, max, args, args_off, count_buf, count_off, signature, pso, resolution, true,
Expand Down Expand Up @@ -4137,6 +4140,7 @@ fn cpu_rect_expansion(pso: usize) -> bool {

/// #12 DrawInstanced
pub(super) unsafe extern "system" fn draw_instanced(this: *mut c_void, vertices: u32, instances: u32, first_vertex: u32, first_instance: u32) {
super::list_x::note_untracked_gpu_write(this);
let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailDraw);
let _t = crate::hle::api_cost::time_if(super::look_stats::deep(), crate::hle::api_cost::Call::DrawRecord);
let _c = capture_work(this, || super::capture::WorkKind::Draw { vertices, instances, first_vertex, first_instance }, true);
Expand Down Expand Up @@ -4167,6 +4171,7 @@ static STOP_ABI_TEST: Mutex<()> = Mutex::new(());

/// #13 DrawIndexedInstanced
pub(super) unsafe extern "system" fn draw_indexed_instanced(this: *mut c_void, indices: u32, instances: u32, first_index: u32, base_vertex: i32, first_instance: u32) {
super::list_x::note_untracked_gpu_write(this);
let _detail = crate::stall::detail_span(crate::stall::StallKind::DetailDraw);
let _t = crate::hle::api_cost::time_if(super::look_stats::deep(), crate::hle::api_cost::Call::DrawRecord);
let _c = capture_work(this, || super::capture::WorkKind::DrawIndexed { indices, instances, first_index, base_vertex, first_instance }, true);
Expand Down Expand Up @@ -4823,6 +4828,7 @@ fn skip_untranslated_dispatch(pso: usize) {

/// `Dispatch` / `DispatchX(x, y, z, flags)`.
pub(super) unsafe fn dispatch_flags(this: *mut c_void, x: u32, y: u32, z: u32, flags: u32) {
super::list_x::note_untracked_gpu_write(this);
let _t = crate::hle::api_cost::time_if(super::look_stats::deep(), crate::hle::api_cost::Call::DispatchRecord);
let (bound_pso, resolution) = with(this, |s| (s.pso, s.resolution.clone()));
let _c = capture_work(this, || captured_dispatch(bound_pso, [x, y, z], flags), false);
Expand Down Expand Up @@ -10186,4 +10192,68 @@ void ms(uint3 g : SV_GroupID) { o.Store((v * 16u + g.x) * 4u, rec.Load(g.x * 4u)
assert_eq!(TWO_PASS[TP_SHRUNK].load(Ordering::Relaxed), shrunk_before);
}
}

#[test]
fn draw_instanced_marks_tracked_list_untracked_and_respects_fast_paths() {
use super::super::{list_x, sparse};
let cancel_if_some = |tok: Option<sparse::UntrackedSubmitToken>| -> bool {
if let Some(t) = tok {
sparse::cancel_untracked_submit(t);
true
} else {
false
}
};
let prev = sparse::set_sparse_buffers_active_for_test(false);
struct RestoreSparseActive(bool);
impl Drop for RestoreSparseActive {
fn drop(&mut self) {
sparse::set_sparse_buffers_active_for_test(self.0);
}
}
let _restore = RestoreSparseActive(prev);

unsafe {
let mut orig_vt = [0usize; 64];
orig_vt[1] = fake_add_ref as usize;
orig_vt[2] = fake_release as usize;
orig_vt[12] = fake_draw_instanced as usize;
let mut ext_vt = vec![0usize; 65];
ext_vt[0] = orig_vt.as_ptr() as usize;
ext_vt[1..].copy_from_slice(&orig_vt);
let fake = Box::new(FakeAdoptedList {
vt: ext_vt.as_ptr().add(1),
refs: AtomicUsize::new(1),
dispatch_calls: AtomicUsize::new(0),
set_compute_rs_calls: AtomicUsize::new(0),
set_compute_uav_calls: AtomicUsize::new(0),
set_pso_calls: AtomicUsize::new(0),
last_pso: AtomicUsize::new(0),
execute_indirect_calls: AtomicUsize::new(0),
});
let raw = (&*fake as *const FakeAdoptedList) as *mut c_void;
let alloc = 0x7ff0_2222_1000usize;
// With no sparse buffers active, draw_instanced and begin_submission take the atomic fast-path.
draw_instanced(raw, 3, 1, 0, 0);
assert!(!list_x::has_list_state(raw as usize), "no sparse buffers: draw_instanced must not lock/populate LISTS");
assert!(!cancel_if_some(list_x::begin_submission(&[raw], false)));

// A list created while sparse buffers were inactive stays conservatively untracked if sparse activates later.
list_x::on_create_with_backing(raw, alloc, 0, 0, D3D12_COMMAND_LIST_TYPE_DIRECT);
sparse::set_sparse_buffers_active_for_test(true);
assert!(cancel_if_some(list_x::begin_submission(&[raw], false)), "list created before sparse activation must stay conservative");

// Fresh tracked list created after sparse activation starts clean, and non-indexed draw_instanced marks it untracked.
list_x::on_create_with_backing(raw, alloc, 0, 0, D3D12_COMMAND_LIST_TYPE_DIRECT);
assert!(!cancel_if_some(list_x::begin_submission(&[raw], false)));
draw_instanced(raw, 3, 1, 0, 0);
// Repeated draw_instanced hits the lock-free dirty-list cache and preserves untracked status.
draw_instanced(raw, 6, 1, 0, 0);
assert!(cancel_if_some(list_x::begin_submission(&[raw], false)), "DrawInstanced must mark command list untracked");

list_x::on_release(raw as usize);
forget(raw);
drop(fake);
}
}
}
Loading
Loading