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
770 changes: 770 additions & 0 deletions crates/xcl/src/hle/d3d12x/alias_copy.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/xcl/src/hle/d3d12x/device_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void,
}
real::note_title_address(*ppv as usize, va as usize);
super::depth_uav::note_created(*ppv, &x, Some(va as usize), state);
super::alias_copy::note_created(this, *ppv, va as usize, d.as_ptr(), state);
super::lut3d::created("CreatePlacedResourceX (GPU-owned: on the title's pages / an arena)", *ppv, Some(&x), Some(va as usize), false, state);
}
return hr;
Expand All @@ -1313,6 +1314,7 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void,
Ok(()) => {
real::note_title_address(*ppv as usize, va as usize);
super::depth_uav::note_created(*ppv, &x, Some(va as usize), state);
super::alias_copy::note_created(this, *ppv, va as usize, d.as_ptr(), state);
super::lut3d::created(if placed_hr.is_some() { "CreatePlacedResourceX (sampled: on shared pages)" } else if small_hr.is_some() { "CreatePlacedResourceX (sampled: 4 KiB placement)" } else { "CreatePlacedResourceX (sampled: committed)" }, *ppv, Some(&x), Some(va as usize), true, state);
return hr;
}
Expand All @@ -1331,6 +1333,7 @@ pub(super) unsafe extern "system" fn create_placed_resource_x(this: *mut c_void,
real::note_title_address(*ppv as usize, va as usize);
if !buffer {
super::depth_uav::note_created(*ppv, &x, Some(va as usize), state);
super::alias_copy::note_created(this, *ppv, va as usize, d.as_ptr(), state);
super::lut3d::created("CreatePlacedResourceX (a resource of its own: not kept in step)", *ppv, Some(&x), Some(va as usize), false, state);
}
}
Expand Down
17 changes: 17 additions & 0 deletions crates/xcl/src/hle/d3d12x/late_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ enum Dead {
/// a reference of XCL's own to a superseded target, whose tiles then leave the shared pages
/// (`hold_unmap`)
Unmap(usize),
/// a reference to a resource XCL owns (`hold_own`)
Own(usize),
}

struct Batch {
Expand Down Expand Up @@ -300,6 +302,17 @@ pub fn hold_unmap(res: ID3D12Resource) {
start_thread();
}

/// A resource XCL owns that lists in flight may name (the copy buffer of an alias pair whose
/// textures the title released, `alias_copy`) is let go as the title's own resources are: once
/// every queue is past a fence value signalled after this. `XCL_LATE_RELEASE=0`: now.
pub fn hold_own(res: ID3D12Resource) {
if !enabled() {
return drop(res);
}
HELD.lock().unwrap().get_or_insert_with(Held::default).open.push(Dead::Own(res.into_raw() as usize));
start_thread();
}

/// Release what every queue XCL knows of is past: the title's, the tile-mapping one, the
/// upload ones.
pub unsafe fn drain_known(seal_now: bool) {
Expand Down Expand Up @@ -337,6 +350,10 @@ pub unsafe fn drain_known(seal_now: bool) {
drop(ID3D12Heap::from_raw(h as *mut c_void));
continue;
}
Dead::Own(r) => {
drop(ID3D12Resource::from_raw(r as *mut c_void));
continue;
}
Dead::Unmap(r) => {
// (then the reference goes: the title's last one may have gone meanwhile)
let r = ID3D12Resource::from_raw(r as *mut c_void);
Expand Down
29 changes: 29 additions & 0 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6453,6 +6453,9 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
if uav_transition && !any_uav {
out.push([2, 0, 0, 0, 0, 0, 0, 0]);
}
// (a sampled texture in the memory of a written one of another format: copied from it after
// these, where they take the written one out of a written state)
let alias_jobs = if super::alias_copy::on() { super::alias_copy::plan(&out) } else { Vec::new() };
// depth buffers whose depth plane can have a twin: in PARK where the title has them in
// UNORDERED_ACCESS, the twin copied around the transitions (`depth_uav`)
let plane_copies = super::depth_uav::any_kept().then(|| {
Expand Down Expand Up @@ -6492,6 +6495,32 @@ pub(super) unsafe extern "system" fn resource_barrier_x(this: *mut c_void, n: u3
plane_copies_on(this, &p.to_twin, true);
stencil_copies_on(this, &p.stencil_to_twin, true);
}
super::alias_copy::record(this, &alias_jobs);
}

/// The texels of the texture `from` into the texture `to` through `buffer`, on the PC list past
/// the hooks of a title's calls (`alias_copy::record`): the barriers `before`, each level and
/// layer of `from` into the buffer by the first footprint of its `parts`, the barrier `between`,
/// each out of the buffer into `to` by the second, the barriers `after`. `to` is noted as written
/// by the GPU on this list.
#[allow(clippy::too_many_arguments)]
pub(super) unsafe fn texture_through_buffer(
list: *mut c_void, from: usize, to: usize, buffer: usize, parts: &[(D3D12_PLACED_SUBRESOURCE_FOOTPRINT, D3D12_PLACED_SUBRESOURCE_FOOTPRINT)], before: &[[u32; 8]], between: &[u32; 8], after: &[[u32; 8]],
) {
let barriers = |b: &[[u32; 8]]| pc::<unsafe extern "system" fn(*mut c_void, u32, *const [u32; 8])>(list, PC_RESOURCE_BARRIER)(list, b.len() as u32, b.as_ptr());
let copy = pc::<unsafe extern "system" fn(*mut c_void, *const D3D12_TEXTURE_COPY_LOCATION, u32, u32, u32, *const D3D12_TEXTURE_COPY_LOCATION, *const D3D12_BOX)>(list, PC_COPY_TEXTURE_REGION);
let part = |res: usize, k: usize| D3D12_TEXTURE_COPY_LOCATION { pResource: transmute_copy(&res), Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: k as u32 } };
let rows = |f: &D3D12_PLACED_SUBRESOURCE_FOOTPRINT| D3D12_TEXTURE_COPY_LOCATION { pResource: transmute_copy(&buffer), Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: *f } };
barriers(before);
for (k, (written, _)) in parts.iter().enumerate() {
copy(list, &rows(written), 0, 0, 0, &part(from, k), std::ptr::null());
}
barriers(std::slice::from_ref(between));
for (k, (_, read)) in parts.iter().enumerate() {
copy(list, &part(to, k), 0, 0, 0, &rows(read), std::ptr::null());
}
barriers(after);
note_texture_write(list as usize, to, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
}

/// The copies between stencil planes and their twins around a title's barriers
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/hle/d3d12x/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#![allow(non_snake_case)]

mod alias_copy;
mod alloc_pool;
pub use alloc_pool::AllocatorSubmitStats;
mod barrier_groups;
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,7 @@ unsafe extern "system" fn res_release(this: *mut c_void) -> u32 {
super::small_tex::gone(this as usize);
}
super::depth_uav::forget(this as usize);
super::alias_copy::forget(this as usize);
super::barrier_groups::forget(this as usize);
let final_state = super::title_textures::forget(this as usize);
super::lut3d::forget(this as usize);
Expand Down
10 changes: 8 additions & 2 deletions crates/xcl/src/hle/d3d12x/title_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,20 +935,26 @@ pub(super) fn publish_submission_effects(queue: Option<WriterQueueId>, writes: &
return;
}
let mut newly_written = Vec::new();
// (what an alias copy went into is written by the GPU, and is not read back into the title's
// memory: asked before `TEXTURES` is held)
let copied_into: Vec<bool> = if super::alias_copy::on() { writes.iter().map(|w| super::alias_copy::is_copy_destination(w.res)).collect() } else { Vec::new() };
{
let mut t = TEXTURES.lock().unwrap();
// (the stamp is for the queue's page mappings: with them off, a publish takes no call count)
let call = crate::hle::kernelx::mirrors::page_mappings().then(crate::hle::kernelx::mirrors::calls);
if let Some(queue) = queue {
for &write in writes {
for (k, &write) in writes.iter().enumerate() {
let Some(e) = t.get_mut(write.res).filter(|e| e.generation == write.generation) else { continue };
let n = subresource_count(&e.tex);
if write.subresource != D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES && !(n <= 1 && write.subresource == 0) && write.subresource as usize >= n {
continue;
}
let epoch = NEXT_GPU_EPOCH.fetch_add(1, Ordering::Relaxed) + 1;
let writer = GpuWriter { epoch, queue };
apply_gpu_writer(&mut e.gpu_writers, n, write.subresource, writer);
// (no writer: `prepare_downloads` finds nothing of it to read back)
if !copied_into.get(k).copied().unwrap_or(false) {
apply_gpu_writer(&mut e.gpu_writers, n, write.subresource, writer);
}
if let Some(call) = call {
// (`Entry::written_call`: a mapping changed by a later call is newer than this write)
e.written_call = call;
Expand Down
Loading