|
|
@@ -519,7 +519,7 @@ pub(crate) fn let_go_idle() {
|
|
|
if map.is_empty() {
|
|
|
return;
|
|
|
}
|
|
|
- let idle_ms = crate::host::ram_idle_ms(crate::host::available_physical_ram());
|
|
|
+ let idle_ms = crate::host::ram_idle_ms(crate::residency::headroom());
|
|
|
// A list that recorded an upload or a check holds the staging until it
|
|
|
// is reset: one only the table holds is named by no list, recorded or
|
|
|
// running.
|
|
|
@@ -788,6 +788,25 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // The video decoder cycles CPU-written linear plane buffers. Keep a
|
|
|
+ // dedicated per-list upload buffer through the list's GPU fence so
|
|
|
+ // concurrent frames never overwrite each other or stall on staging hashes.
|
|
|
+ if staging.movie_plane() {
|
|
|
+ let (at, len) = staging.memory();
|
|
|
+ let footprint = staging.footprints[0].Footprint;
|
|
|
+ let pitch = footprint.RowPitch as usize;
|
|
|
+ let bytes = pitch * staging.rows[0] as usize;
|
|
|
+ let plane = staging.clone();
|
|
|
+ let Some(source) = list.plane_upload(bytes as u64, (at, len), move |dst| {
|
|
|
+ fill_plane(&plane.layout, at, len, dst, bytes, pitch);
|
|
|
+ }) else {
|
|
|
+ once!("no upload buffer for a CPU-written movie plane");
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ record_upload(list, resource, texture, &staging, &source, 0);
|
|
|
+ staging.uploaded.store(true, Relaxed);
|
|
|
+ return;
|
|
|
+ }
|
|
|
// The host texture has the staging buffer's contents: only the check
|
|
|
// at submission is left, and what it finds changed the next list that
|
|
|
// samples the texture uploads (a frame late where every list of the
|
|
|
@@ -807,6 +826,59 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
};
|
|
|
staging.expected.store(there, Relaxed);
|
|
|
}
|
|
|
+ record_upload(list, resource, texture, &staging, &staging.buffer, staging.base);
|
|
|
+ // When the list is submitted, its copy takes what the staging buffer
|
|
|
+ // holds by then: noted before the check below, which sets `dirty`
|
|
|
+ // again if it detiles (the next list then uploads once more).
|
|
|
+ {
|
|
|
+ let staging = staging.clone();
|
|
|
+ list.defer_host(move || {
|
|
|
+ staging.uploaded.store(true, Relaxed);
|
|
|
+ staging.dirty.store(false, Relaxed);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // A host copy that took the place of one with fewer levels: the slots
|
|
|
+ // that show that one are made again once this upload has run.
|
|
|
+ if staging.first == staging.level0 && copy.grown.swap(false, Relaxed) {
|
|
|
+ let start = staging.memory as u64;
|
|
|
+ list.defer_host(move || crate::descriptor::host::levels_changed_after(start));
|
|
|
+ }
|
|
|
+ let noted = staging.clone();
|
|
|
+ // Levels on demand (`crate::tiles`): after the check below, in the
|
|
|
+ // order of this list's steps, and before the list is executed, the
|
|
|
+ // levels the staging buffer holds as the title's are given the card's
|
|
|
+ // memory if they have none. The list copies every level, so each one
|
|
|
+ // given here is written whole by it (the rest are copies into no
|
|
|
+ // memory, which the card drops).
|
|
|
+ let on_demand = if staging.on_demand { crate::resource::host_tiled(resource) } else { None };
|
|
|
+ let Some(on_demand) = on_demand else {
|
|
|
+ // Once per submission however many of its lists sample the texture.
|
|
|
+ list.defer_texture(staging);
|
|
|
+ // Then what the list's copy puts in the host copy is known.
|
|
|
+ list.defer_host(move || noted.note_held());
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ list.defer_texture(staging.clone());
|
|
|
+ list.defer_host(move || {
|
|
|
+ let waiting = on_demand.uploaded(staging.detiled.load(Relaxed), staging.memory as u64);
|
|
|
+ staging.waiting.store(if waiting { crate::host::moment().max(1) } else { 0 }, Relaxed);
|
|
|
+ // A texture picked by index has no staging buffer after this
|
|
|
+ // upload: its slots are made due again by the texture pass.
|
|
|
+ if waiting {
|
|
|
+ crate::descriptor::host::levels_waiting(staging.memory as u64);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+fn record_upload(
|
|
|
+ list: &HostList,
|
|
|
+ resource: This,
|
|
|
+ texture: &ID3D12Resource,
|
|
|
+ staging: &Staging,
|
|
|
+ source: &ID3D12Resource,
|
|
|
+ base: u64,
|
|
|
+) {
|
|
|
+ use std::sync::atomic::Ordering::Relaxed;
|
|
|
const COPY_DEST: u32 = 0x400;
|
|
|
// A texture cut from a block may lie where another did: what the card
|
|
|
// holds of that one is done with before the first upload into this one.
|
|
|
@@ -826,14 +898,13 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
unsafe { list.list.ResourceBarrier(&[aliasing]) };
|
|
|
}
|
|
|
crate::list::ensure_state(list, resource, COPY_DEST);
|
|
|
- // The staging buffer lives as long as `staging`, which the deferred
|
|
|
- // refresh below holds until the list is reset.
|
|
|
+ // The staging/plane upload buffer lives until the list is reset.
|
|
|
for (i, footprint) in staging.footprints.iter().enumerate() {
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
{
|
|
|
let f = footprint.Footprint;
|
|
|
// SAFETY: live resources.
|
|
|
- let (gpu, d) = unsafe { (staging.buffer.GetGPUVirtualAddress(), texture.GetDesc()) };
|
|
|
+ let (gpu, d) = unsafe { (source.GetGPUVirtualAddress(), texture.GetDesc()) };
|
|
|
let len = u64::from(f.RowPitch) * u64::from(staging.rows[i]) * u64::from(f.Depth);
|
|
|
list.note_read(
|
|
|
|| {
|
|
|
@@ -846,14 +917,14 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
d.MipLevels,
|
|
|
staging.footprints.len(),
|
|
|
staging.size,
|
|
|
- staging.base + footprint.Offset,
|
|
|
+ base + footprint.Offset,
|
|
|
f.Width,
|
|
|
f.Height,
|
|
|
f.Depth,
|
|
|
f.RowPitch
|
|
|
)
|
|
|
},
|
|
|
- (gpu + staging.base + footprint.Offset, len),
|
|
|
+ (gpu + base + footprint.Offset, len),
|
|
|
);
|
|
|
}
|
|
|
let to = D3D12_TEXTURE_COPY_LOCATION {
|
|
|
@@ -866,11 +937,11 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
};
|
|
|
let from = D3D12_TEXTURE_COPY_LOCATION {
|
|
|
// SAFETY: as above.
|
|
|
- pResource: unsafe { std::mem::transmute_copy(&staging.buffer) },
|
|
|
+ pResource: unsafe { std::mem::transmute_copy(source) },
|
|
|
Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
|
|
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 {
|
|
|
PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
|
|
|
- Offset: staging.base + footprint.Offset,
|
|
|
+ Offset: base + footprint.Offset,
|
|
|
..*footprint
|
|
|
},
|
|
|
},
|
|
|
@@ -878,45 +949,32 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
// SAFETY: an open list; both locations name live resources.
|
|
|
unsafe { list.list.CopyTextureRegion(&to, 0, 0, 0, &from, None) };
|
|
|
}
|
|
|
- // When the list is submitted, its copy takes what the staging buffer
|
|
|
- // holds by then: noted before the check below, which sets `dirty`
|
|
|
- // again if it detiles (the next list then uploads once more).
|
|
|
+}
|
|
|
+
|
|
|
+fn fill_plane(
|
|
|
+ layout: &victory_formats::texture::Layout,
|
|
|
+ at: usize,
|
|
|
+ len: usize,
|
|
|
+ dst: usize,
|
|
|
+ bytes: usize,
|
|
|
+ pitch: usize,
|
|
|
+) {
|
|
|
+ let _pin = crate::watch::title_memory_reading();
|
|
|
+ // SAFETY: the list owns this full upload allocation until its GPU work completes.
|
|
|
+ let out = unsafe { std::slice::from_raw_parts_mut(dst as *mut u8, bytes) };
|
|
|
+ let mip = &layout.mips[0];
|
|
|
+ if mip.offset == 0
|
|
|
+ && mip.pitch as usize * layout.desc.element_bytes as usize == pitch
|
|
|
+ && bytes <= len
|
|
|
+ && crate::host::read_into(at as *const _, out)
|
|
|
{
|
|
|
- let staging = staging.clone();
|
|
|
- list.defer_host(move || {
|
|
|
- staging.uploaded.store(true, Relaxed);
|
|
|
- staging.dirty.store(false, Relaxed);
|
|
|
- });
|
|
|
- }
|
|
|
- // A host copy that took the place of one with fewer levels: the slots
|
|
|
- // that show that one are made again once this upload has run.
|
|
|
- if staging.first == staging.level0 && copy.grown.swap(false, Relaxed) {
|
|
|
- let start = staging.memory as u64;
|
|
|
- list.defer_host(move || crate::descriptor::host::levels_changed_after(start));
|
|
|
- }
|
|
|
- let noted = staging.clone();
|
|
|
- // Levels on demand (`crate::tiles`): after the check below, in the
|
|
|
- // order of this list's steps, and before the list is executed, the
|
|
|
- // levels the staging buffer holds as the title's are given the card's
|
|
|
- // memory if they have none. The list copies every level, so each one
|
|
|
- // given here is written whole by it (the rest are copies into no
|
|
|
- // memory, which the card drops).
|
|
|
- let on_demand = if staging.on_demand { crate::resource::host_tiled(resource) } else { None };
|
|
|
- let Some(on_demand) = on_demand else {
|
|
|
- // Once per submission however many of its lists sample the texture.
|
|
|
- list.defer_texture(staging);
|
|
|
- // Then what the list's copy puts in the host copy is known.
|
|
|
- list.defer_host(move || noted.note_held());
|
|
|
return;
|
|
|
- };
|
|
|
- list.defer_texture(staging.clone());
|
|
|
- list.defer_host(move || {
|
|
|
- let waiting = on_demand.uploaded(staging.detiled.load(Relaxed), staging.memory as u64);
|
|
|
- staging.waiting.store(if waiting { crate::host::moment().max(1) } else { 0 }, Relaxed);
|
|
|
- // A texture picked by index has no staging buffer after this
|
|
|
- // upload: its slots are made due again by the texture pass.
|
|
|
- if waiting {
|
|
|
- crate::descriptor::host::levels_waiting(staging.memory as u64);
|
|
|
+ }
|
|
|
+ with_read(len, |read| {
|
|
|
+ crate::host::copy_mapped(read.as_mut_ptr(), at as *const u8, len, false);
|
|
|
+ if let Err(error) = layout.detile(read, 0, 0, out, pitch, bytes) {
|
|
|
+ out.fill(0);
|
|
|
+ once!("could not copy the linear plane into the list's upload buffer: {error:?}");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -1169,6 +1227,20 @@ impl Staging {
|
|
|
preparing[3].fetch_add(read as u64, Relaxed);
|
|
|
}
|
|
|
|
|
|
+ fn movie_plane(&self) -> bool {
|
|
|
+ use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8_UNORM;
|
|
|
+ let desc = &self.layout.desc;
|
|
|
+ !self.on_demand
|
|
|
+ && desc.dimension == victory_formats::texture::Dimension::Tex2d
|
|
|
+ && desc.swizzle.0 == 0
|
|
|
+ && desc.depth == 1
|
|
|
+ && desc.mips == 1
|
|
|
+ && desc.samples == 1
|
|
|
+ && self.footprints.len() == 1
|
|
|
+ && self.footprints[0].Offset == 0
|
|
|
+ && self.footprints[0].Footprint.Format == DXGI_FORMAT_R8_UNORM
|
|
|
+ }
|
|
|
+
|
|
|
/// Returns the bytes of title memory read.
|
|
|
fn refresh_now(&self) -> usize {
|
|
|
let whole = std::time::Instant::now();
|