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
87 changes: 86 additions & 1 deletion crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,14 @@ fn indirect_signature(sig: usize) -> IndirectSignatureInfo {
.and_then(|signatures| signatures.get(&sig).copied()).unwrap_or_default()
}

/// An ExecuteIndirect that could have drawn is skipped: an occlusion query open on the list
/// reads as visible, as for a skipped draw (`graphics_bound`). A Dispatch signature makes no samples.
fn note_skipped_indirect(this: *mut c_void, signature: IndirectSignatureInfo) {
if !signature.dispatches() {

@gut0to gut0to Dec 1, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!dispatches() treats every non-Dispatch signature as draw-capable, but a valid ExecuteIndirect signature can contain only root-argument updates. When that root-only signature is skipped here, note_dropped_draw marks an active occlusion query visible even though no draw produced samples. Could signature classification also record whether a draw argument is present and force visibility only for draw-capable signatures? AI-assisted static review: I used an AI assistant to inspect this path; I checked the signature rules against https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-createcommandsignature.

super::list_x::note_dropped_draw(this);
}
}

pub(super) fn note_dispatch_mesh_signature(sig: usize, companion_dispatch: usize, byte_stride: u32, mesh_offset: u32) {
DISPATCH_MESH_SIGS
.lock()
Expand Down Expand Up @@ -3554,6 +3562,7 @@ unsafe fn execute_indirect_snapshot(
}
let Some((pso, bound_unbuilt)) = resolve_indirect_pipeline(this as usize, raw_pso, resolution) else {
ei_work(this, dispatches, super::targets::SKIPPED);
note_skipped_indirect(this, signature);
count_indirect_skip(dispatches);
return;
};
Expand All @@ -3576,6 +3585,7 @@ unsafe fn execute_indirect_snapshot(
DrawPipeline::StandIn => {
ei_work(this, dispatches, super::targets::STANDIN);
count_indirect_skip(dispatches);
note_skipped_indirect(this, signature);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
crate::xlog_warn!("D3D12.X: ExecuteIndirect with a pipeline that is still being built skipped");
Expand All @@ -3592,6 +3602,7 @@ unsafe fn execute_indirect_snapshot(
// signature does not have.
let Some(msig) = dispatch_mesh_sig_of(sig) else {
ei_work(this, dispatches, super::targets::SKIPPED);
note_skipped_indirect(this, signature);
count(DRAWS_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand Down Expand Up @@ -3703,6 +3714,7 @@ unsafe fn execute_indirect_snapshot(
// see as two-pass.)
if let Some(tp) = super::real::two_pass_of_exact(pso) {
ei_work(this, dispatches, super::targets::SKIPPED);
note_skipped_indirect(this, signature);
count(DRAWS_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand Down Expand Up @@ -3746,6 +3758,9 @@ unsafe fn execute_indirect_snapshot(
}
if signature.root_changes() {
ei_work(this, dispatches, super::targets::SKIPPED);
if gfx {
note_skipped_indirect(this, signature);
}
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
crate::xlog_warn!("D3D12.X: ExecuteIndirect that changes root arguments with a translated pipeline skipped");
Expand Down Expand Up @@ -3869,6 +3884,9 @@ unsafe fn execute_indirect_snapshot(
}
Err(e) => {
ei_work(this, dispatches, super::targets::SKIPPED);
if gfx {
note_skipped_indirect(this, signature);
}
count(if gfx { DRAWS_SKIPPED } else { DISPATCHES_SKIPPED });
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand Down Expand Up @@ -4161,6 +4179,7 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<(ID3D12GraphicsCommandList
// (Close → E_INVALIDARG). It draws only through DispatchMesh.
if let Some(tp) = super::real::two_pass_of_exact(real) {
super::targets::note_draw(this, super::targets::SKIPPED);
super::list_x::note_dropped_draw(this);
count(DRAWS_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand Down Expand Up @@ -4190,7 +4209,7 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<(ID3D12GraphicsCommandList
}
}
// a pending stand-in draws nothing: an occlusion query around it resolves as visible
if super::pso_async::is_pending(pso) {
if super::pso_async::is_stand_in(pso) {
super::list_x::note_dropped_draw(this);
}
// a PC pipeline (also a stand-in or fallback): the title's root signature
Expand Down Expand Up @@ -5499,6 +5518,72 @@ mod tests {
assert!(!pso_async::is_pending(building));
}

/// An ExecuteIndirect skipped inside an occlusion query leaves it visible, as a skipped draw
/// does (`note_dropped_draw`): the skipped call could have made samples, and a query that
/// reads 0 makes the title treat its objects as hidden. A Dispatch signature makes none.
#[test]
fn execute_indirect_skipped_inside_an_occlusion_query_reports_visible() {
use windows::Win32::Graphics::Direct3D12::D3D12_QUERY_TYPE_OCCLUSION;
unsafe extern "system" fn fake_query(_this: *mut c_void, _heap: usize, _ty: D3D12_QUERY_TYPE, _index: u32) {}
let mut orig_vt = [0usize; 64];
orig_vt[52] = fake_query as usize;
orig_vt[53] = fake_query as usize;
orig_vt[59] = fake_execute_indirect 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: unsafe { 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 list = &*fake as *const FakeAdoptedList as *mut c_void;
let (sig, sig_dispatch, sig_root) = (0x7E57_7000usize, 0x7E57_7001usize, 0x7E57_7002usize);
note_indirect_signature(sig, IndirectSignatureInfo::new(false, false, None));
note_indirect_signature(sig_dispatch, IndirectSignatureInfo::new(true, false, None));
note_indirect_signature(sig_root, IndirectSignatureInfo::new(false, true, None));
// the query of `heap` around one ExecuteIndirect: does it read as visible?
let visible = |heap: usize, pso: usize, sig: usize| unsafe {
reset(list, 0x7E57_7100, pso);
list_x::begin_query_x(list, heap, D3D12_QUERY_TYPE_OCCLUSION, 0);
execute_indirect(list, sig, 1, 0, 0, 0, 0);
list_x::end_query_x(list, heap, D3D12_QUERY_TYPE_OCCLUSION, 0);
list_x::forced_visible_for_test(heap, 0)
};
// a pipeline still being built (its job waits for `release`, a worker does not finish it)
let (release, gate) = std::sync::mpsc::channel::<()>();
let building = 0x7E57_7010usize;
pso_async::submit_lazy(building, false, Box::new(move || { let _ = gate.recv(); 0 }), 0);
pso_async::image_only(building);
assert!(pso_async::is_pending(building));
let pending = visible(0x7E57_7201, building, sig);
let pending_dispatch = visible(0x7E57_7202, building, sig_dispatch);
let _ = release.send(());
// a finished two-pass mesh pipeline
let two_pass = 0x7E57_7020usize;
real::register_two_pass_for_test(two_pass, "MS");
let two = visible(0x7E57_7203, two_pass, sig);
// a translated graphics pipeline with a root-changing signature (the ABI bind itself needs a real list)
let translated = 0x7E57_7030usize;
real::register_translated_graphics_for_test(translated);
let root = visible(0x7E57_7204, translated, sig_root);
real::forget_pso_for_test(translated);
real::forget_pso_for_test(two_pass);
pso_async::released(building);
assert!(pending, "a pipeline still being built");
assert!(!pending_dispatch, "a Dispatch signature makes no samples");
assert!(two, "a two-pass pipeline");
assert!(root, "a root-changing signature");
forget(list);
list_x::forget_list_for_test(list);
assert_eq!(fake.execute_indirect_calls.load(Ordering::Relaxed), 0);
}

/// A dispatch writes an ExecuteIndirect's group count through another buffer over the same
/// memory (as translated shaders write through the memory windows), a UAV barrier (what a
/// console barrier becomes), then the ExecuteIndirect: it runs the count just written, not
Expand Down
10 changes: 10 additions & 0 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6879,6 +6879,16 @@ pub(super) unsafe extern "system" fn begin_query_x(this: *mut c_void, heap: usiz
pc::<QueryFn>(this, PC_BEGIN_QUERY)(this, heap, ty, index);
}

#[cfg(test)]
pub(super) fn forced_visible_for_test(heap: usize, index: u32) -> bool {
VISIBLE.lock().unwrap().as_ref().is_some_and(|m| m.contains_key(&(heap, index)))
}

#[cfg(test)]
pub(super) fn forget_list_for_test(list: *mut c_void) {
LISTS.lock().unwrap().as_mut().map(|m| m.remove(&(list as usize)));
}

/// command list #29 EndQuery(heap, type, index) (PC #53)
pub(super) unsafe extern "system" fn end_query_x(this: *mut c_void, heap: usize, ty: D3D12_QUERY_TYPE, index: u32) {
if is_occlusion(ty) {
Expand Down
5 changes: 5 additions & 0 deletions crates/xcl/src/hle/d3d12x/pso_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12419,6 +12419,11 @@ pub fn is_pending(pso: usize) -> bool {
entry(pso).is_some_and(|p| !*p.build.done.lock().unwrap())
}

/// `pso` is a stand-in with no real pipeline: still being built, or its build failed (it draws nothing).
pub fn is_stand_in(pso: usize) -> bool {
entry(pso).is_some_and(|p| p.build.real.load(Ordering::Acquire) == 0)
}

/// `pso` is a stand-in whose real pipeline is being built or was built, and `resolved`, what a
/// `resolve_wait` gave for it, is the stand-in (`pso` itself, or the driver pipeline a shared
/// stand-in binds: `shared`): the bind has the stand-in, also when the build finished since (a
Expand Down
Loading