|
@@ -57,9 +57,9 @@ pub(crate) struct Staging {
|
|
|
/// Which host copy it uploads into, and what that is told to hold.
|
|
/// Which host copy it uploads into, and what that is told to hold.
|
|
|
serial: u64,
|
|
serial: u64,
|
|
|
holds: Arc<crate::resource::Holds>,
|
|
holds: Arc<crate::resource::Holds>,
|
|
|
- /// Title memory being remapped is waited for whatever [`no_wait`] says:
|
|
|
|
|
- /// a list that bakes from the texture now recorded the upload.
|
|
|
|
|
- waits: std::sync::atomic::AtomicBool,
|
|
|
|
|
|
|
+ /// Made by the pass over textures picked by index, for one upload
|
|
|
|
|
+ /// ([`once`]): read when the list is submitted, and never looked at again.
|
|
|
|
|
+ once: std::sync::atomic::AtomicBool,
|
|
|
/// The staging buffer's bytes (counted in `STAGED` while it lives).
|
|
/// The staging buffer's bytes (counted in `STAGED` while it lives).
|
|
|
bytes: u64,
|
|
bytes: u64,
|
|
|
memory: *const u8,
|
|
memory: *const u8,
|
|
@@ -95,7 +95,7 @@ pub(crate) struct Staging {
|
|
|
/// (memory not watched), or the write-watch asking it was detiled after.
|
|
/// (memory not watched), or the write-watch asking it was detiled after.
|
|
|
#[derive(Default)]
|
|
#[derive(Default)]
|
|
|
struct Last {
|
|
struct Last {
|
|
|
- hash: Option<blake3::Hash>,
|
|
|
|
|
|
|
+ hash: Option<Digest>,
|
|
|
asked: u64,
|
|
asked: u64,
|
|
|
/// The frame a partly mapped texture was last read in.
|
|
/// The frame a partly mapped texture was last read in.
|
|
|
partial: Option<u64>,
|
|
partial: Option<u64>,
|
|
@@ -648,11 +648,76 @@ pub(crate) fn upload(list: &HostList, resource: This, _texture: &ID3D12Resource)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
thread_local! {
|
|
thread_local! {
|
|
|
- /// The thread records uploads for a draw that bakes from them
|
|
|
|
|
- /// ([`Staging::waits`]).
|
|
|
|
|
|
|
+ /// The thread records uploads for a draw that bakes from them.
|
|
|
pub(crate) static BAKING: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
|
pub(crate) static BAKING: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
|
|
|
|
+ /// The thread records the upload of a texture picked by index, of which
|
|
|
|
|
+ /// that many bytes were found mapped just now (`u64::MAX`: not asked).
|
|
|
|
|
+ pub(crate) static PICKING: std::cell::Cell<Option<u64>> = const { std::cell::Cell::new(None) };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// Whether a staging buffer made for one upload of a texture picked by index
|
|
|
|
|
+/// is filled without asking the write watch and the guards
|
|
|
|
|
+/// (`VICTORY_TEXTURE_ONCE=0`: with, as before). What they say is for the next
|
|
|
|
|
+/// refresh, and there is none: the buffer goes with the upload. Asking guards
|
|
|
|
|
+/// the texture's blocks (a change of protection, under the lock every other
|
|
|
|
|
+/// refresh wants), and the title's next write there faults to open them.
|
|
|
|
|
+fn once() -> bool {
|
|
|
|
|
+ static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
|
|
|
+ *ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_ONCE").is_none_or(|v| v != "0"))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// A 128-bit digest of `bytes`, to tell a texture's memory changed: four
|
|
|
|
|
+/// lanes of folded multiplications over 64 bytes at a time. (Not a
|
|
|
|
|
+/// cryptographic one, which took 0.27 ms a megabyte, four times the detiling
|
|
|
|
|
+/// it was to spare; nobody makes up textures to collide.)
|
|
|
|
|
+pub(crate) fn digest(bytes: &[u8]) -> Digest {
|
|
|
|
|
+ const K: [u64; 8] = [
|
|
|
|
|
+ 0xa076_1d64_78bd_642f,
|
|
|
|
|
+ 0xe703_7ed1_a0b4_28db,
|
|
|
|
|
+ 0x8ebc_6af0_9c88_c6e3,
|
|
|
|
|
+ 0x5899_65cc_7537_4cc3,
|
|
|
|
|
+ 0x1d8e_4e27_c47d_124f,
|
|
|
|
|
+ 0xeb44_acca_b455_d165,
|
|
|
|
|
+ 0x9e37_79b9_7f4a_7c15,
|
|
|
|
|
+ 0xc2b2_ae3d_27d4_eb4f,
|
|
|
|
|
+ ];
|
|
|
|
|
+ let fold = |a: u64, b: u64| {
|
|
|
|
|
+ let p = u128::from(a) * u128::from(b);
|
|
|
|
|
+ p as u64 ^ (p >> 64) as u64
|
|
|
|
|
+ };
|
|
|
|
|
+ let word = |b: &[u8]| {
|
|
|
|
|
+ let mut w = [0; 8];
|
|
|
|
|
+ w[..b.len()].copy_from_slice(b);
|
|
|
|
|
+ u64::from_le_bytes(w)
|
|
|
|
|
+ };
|
|
|
|
|
+ let mut lanes = [K[0], K[1], K[2], K[3]];
|
|
|
|
|
+ let mut step = |block: &[u8; 64]| {
|
|
|
|
|
+ for (i, lane) in lanes.iter_mut().enumerate() {
|
|
|
|
|
+ let a = word(&block[16 * i..16 * i + 8]);
|
|
|
|
|
+ let b = word(&block[16 * i + 8..16 * i + 16]);
|
|
|
|
|
+ // (What went in is added again: a product with a factor of zero
|
|
|
|
|
+ // forgets neither the lane nor the block.)
|
|
|
|
|
+ *lane = fold(a ^ K[4 + i], b ^ *lane).wrapping_add(a.rotate_left(23) ^ lane.rotate_left(41)) ^ b;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ let mut blocks = bytes.chunks_exact(64);
|
|
|
|
|
+ for block in &mut blocks {
|
|
|
|
|
+ step(block.try_into().unwrap_or(&[0; 64]));
|
|
|
|
|
+ }
|
|
|
|
|
+ let rest = blocks.remainder();
|
|
|
|
|
+ let mut last = [0u8; 64];
|
|
|
|
|
+ last[..rest.len()].copy_from_slice(rest);
|
|
|
|
|
+ step(&last);
|
|
|
|
|
+ let len = bytes.len() as u64;
|
|
|
|
|
+ let low = fold(lanes[0] ^ K[1], lanes[1] ^ len) ^ fold(lanes[2] ^ K[3], lanes[3] ^ K[5]);
|
|
|
|
|
+ let high = fold(lanes[0].rotate_left(32) ^ K[6], lanes[2] ^ len) ^ fold(lanes[1].rotate_left(32) ^ K[7], lanes[3] ^ K[2]);
|
|
|
|
|
+ Digest(u128::from(low) << 64 | u128::from(high))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// See [`digest`].
|
|
|
|
|
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
+pub(crate) struct Digest(u128);
|
|
|
|
|
+
|
|
|
/// [`upload`] of the levels from `first` on, the ones a view shows: of a
|
|
/// [`upload`] of the levels from `first` on, the ones a view shows: of a
|
|
|
/// texture the title placed there may be no memory of the larger ones, and
|
|
/// texture the title placed there may be no memory of the larger ones, and
|
|
|
/// what lies there is another texture's. (After victory-amd 4436f8f1.)
|
|
/// what lies there is another texture's. (After victory-amd 4436f8f1.)
|
|
@@ -684,8 +749,10 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
return;
|
|
return;
|
|
|
};
|
|
};
|
|
|
use std::sync::atomic::Ordering::Relaxed;
|
|
use std::sync::atomic::Ordering::Relaxed;
|
|
|
- if BAKING.get() {
|
|
|
|
|
- staging.waits.store(true, Relaxed);
|
|
|
|
|
|
|
+ let picking = PICKING.get();
|
|
|
|
|
+ if picking.is_none() {
|
|
|
|
|
+ // A draw samples it through a table: kept and checked from here on.
|
|
|
|
|
+ staging.once.store(false, Relaxed);
|
|
|
}
|
|
}
|
|
|
staging.used.store(crate::host::moment(), Relaxed);
|
|
staging.used.store(crate::host::moment(), Relaxed);
|
|
|
// Levels on demand: a view of the texture now starts at another
|
|
// Levels on demand: a view of the texture now starts at another
|
|
@@ -727,7 +794,10 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
|
|
|
#[cfg(feature = "diagnostics")]
|
|
#[cfg(feature = "diagnostics")]
|
|
|
crate::copystat::add(crate::copystat::C::TexUploads, 1);
|
|
crate::copystat::add(crate::copystat::C::TexUploads, 1);
|
|
|
if no_wait() && fill_unlocked() {
|
|
if no_wait() && fill_unlocked() {
|
|
|
- let there = mapped_bytes(staging.memory, staging.read);
|
|
|
|
|
|
|
+ let there = match picking {
|
|
|
|
|
+ Some(there) if there != u64::MAX => there,
|
|
|
|
|
+ _ => mapped_bytes(staging.memory, staging.read),
|
|
|
|
|
+ };
|
|
|
staging.expected.store(there, Relaxed);
|
|
staging.expected.store(there, Relaxed);
|
|
|
}
|
|
}
|
|
|
const COPY_DEST: u32 = 0x400;
|
|
const COPY_DEST: u32 = 0x400;
|
|
@@ -867,6 +937,46 @@ impl Drop for Claimed {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// Records copies of zeros into every subresource of `texture`, which is in
|
|
|
|
|
+/// the copy destination state.
|
|
|
|
|
+pub(crate) fn zeros(list: &HostList, host: &crate::host::Host, texture: &ID3D12Resource) {
|
|
|
|
|
+ // SAFETY: a live resource.
|
|
|
|
|
+ let d = unsafe { texture.GetDesc() };
|
|
|
|
|
+ let layers = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { u32::from(d.DepthOrArraySize) };
|
|
|
|
|
+ let count = u32::from(d.MipLevels) * layers;
|
|
|
|
|
+ let mut footprints = vec![D3D12_PLACED_SUBRESOURCE_FOOTPRINT::default(); count as usize];
|
|
|
|
|
+ let mut bytes = 0u64;
|
|
|
|
|
+ // SAFETY: outputs for `count` subresources.
|
|
|
|
|
+ unsafe {
|
|
|
|
|
+ host.device
|
|
|
|
|
+ .GetCopyableFootprints(&d, 0, count, 0, Some(footprints.as_mut_ptr()), None, None, Some(&mut bytes));
|
|
|
|
|
+ }
|
|
|
|
|
+ if bytes == 0 || bytes == u64::MAX {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let Some((buffer, data)) = list.upload(host, bytes) else {
|
|
|
|
|
+ return;
|
|
|
|
|
+ };
|
|
|
|
|
+ // SAFETY: a mapped buffer of `bytes` bytes, just made.
|
|
|
|
|
+ unsafe { std::ptr::write_bytes(data, 0, bytes as usize) };
|
|
|
|
|
+ for (i, footprint) in footprints.iter().enumerate() {
|
|
|
|
|
+ let to = D3D12_TEXTURE_COPY_LOCATION {
|
|
|
|
|
+ // SAFETY: a borrowed pointer the location never releases.
|
|
|
|
|
+ pResource: unsafe { std::mem::transmute_copy(texture) },
|
|
|
|
|
+ Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
|
|
|
|
+ Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: i as u32 },
|
|
|
|
|
+ };
|
|
|
|
|
+ let from = D3D12_TEXTURE_COPY_LOCATION {
|
|
|
|
|
+ // SAFETY: as above; the list holds the buffer until it is reset.
|
|
|
|
|
+ pResource: unsafe { std::mem::transmute_copy(&buffer) },
|
|
|
|
|
+ Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
|
|
|
|
+ Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: *footprint },
|
|
|
|
|
+ };
|
|
|
|
|
+ // SAFETY: an open list; both locations name live resources.
|
|
|
|
|
+ unsafe { list.list.CopyTextureRegion(&to, 0, 0, 0, &from, None) };
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// Levels on demand (`crate::tiles`): the card itself is about to write
|
|
/// Levels on demand (`crate::tiles`): the card itself is about to write
|
|
|
/// title texture `resource` in `list` (a copy or a resolve into level
|
|
/// title texture `resource` in `list` (a copy or a resolve into level
|
|
|
/// `level`, or into every level). If its host copy `texture` was made
|
|
/// `level`, or into every level). If its host copy `texture` was made
|
|
@@ -1064,7 +1174,11 @@ impl Staging {
|
|
|
let start = self.memory as usize;
|
|
let start = self.memory as usize;
|
|
|
let mut last = waited(0, || self.last.lock().unwrap_or_else(|e| e.into_inner()));
|
|
let mut last = waited(0, || self.last.lock().unwrap_or_else(|e| e.into_inner()));
|
|
|
let last = &mut *last;
|
|
let last = &mut *last;
|
|
|
- if let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) {
|
|
|
|
|
|
|
+ let alone = self.once.load(std::sync::atomic::Ordering::Relaxed);
|
|
|
|
|
+ if alone && last.hash.is_some() {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if !alone && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) {
|
|
|
if last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) {
|
|
if last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -1092,7 +1206,8 @@ impl Staging {
|
|
|
static GUARD: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
static GUARD: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
|
// The guard saw no write: a change the hash finds came another way.
|
|
// The guard saw no write: a change the hash finds came another way.
|
|
|
let mut blind = false;
|
|
let mut blind = false;
|
|
|
- if *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
|
|
|
|
|
|
+ if !alone
|
|
|
|
|
+ && *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
|
|
&& let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
|
|
&& let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
|
|
|
{
|
|
{
|
|
|
const HASH_EVERY: u64 = 8;
|
|
const HASH_EVERY: u64 = 8;
|
|
@@ -1127,7 +1242,7 @@ impl Staging {
|
|
|
// stays mapped (see `crate::watch::title_memory_reading`; without
|
|
// stays mapped (see `crate::watch::title_memory_reading`; without
|
|
|
// it a page went between the asking and the read in runs 71 and
|
|
// it a page went between the asking and the read in runs 71 and
|
|
|
// 74).
|
|
// 74).
|
|
|
- let _mapped = if no_wait() && !self.waits.load(std::sync::atomic::Ordering::Relaxed) {
|
|
|
|
|
|
|
+ let _mapped = if no_wait() {
|
|
|
// Not waited for: while the runtime remaps title memory the
|
|
// Not waited for: while the runtime remaps title memory the
|
|
|
// texture is read through the kernel instead, whole or not at
|
|
// texture is read through the kernel instead, whole or not at
|
|
|
// all (`no_wait`).
|
|
// all (`no_wait`).
|
|
@@ -1155,7 +1270,7 @@ impl Staging {
|
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
|
let changed = with_read(size, |read| {
|
|
let changed = with_read(size, |read| {
|
|
|
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
|
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
|
|
- let hash = blake3::hash(read);
|
|
|
|
|
|
|
+ let hash = digest(read);
|
|
|
if last.hash == Some(hash) {
|
|
if last.hash == Some(hash) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -1177,7 +1292,7 @@ impl Staging {
|
|
|
}
|
|
}
|
|
|
if through_copy() {
|
|
if through_copy() {
|
|
|
return with_title(self.memory, size, |tiled| {
|
|
return with_title(self.memory, size, |tiled| {
|
|
|
- let hash = blake3::hash(tiled);
|
|
|
|
|
|
|
+ let hash = digest(tiled);
|
|
|
#[cfg(feature = "diagnostics")]
|
|
#[cfg(feature = "diagnostics")]
|
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
|
if last.hash == Some(hash) {
|
|
if last.hash == Some(hash) {
|
|
@@ -1194,7 +1309,7 @@ impl Staging {
|
|
|
// SAFETY: committed memory of the texture's layout size, and it
|
|
// SAFETY: committed memory of the texture's layout size, and it
|
|
|
// stays committed while `_mapped` is held.
|
|
// stays committed while `_mapped` is held.
|
|
|
let tiled = unsafe { std::slice::from_raw_parts(self.memory, size) };
|
|
let tiled = unsafe { std::slice::from_raw_parts(self.memory, size) };
|
|
|
- let hash = blake3::hash(tiled);
|
|
|
|
|
|
|
+ let hash = digest(tiled);
|
|
|
#[cfg(feature = "diagnostics")]
|
|
#[cfg(feature = "diagnostics")]
|
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
crate::copystat::add(crate::copystat::C::TexHashed, size as u64);
|
|
|
if last.hash == Some(hash) {
|
|
if last.hash == Some(hash) {
|
|
@@ -1221,7 +1336,7 @@ impl Staging {
|
|
|
if !crate::host::read_into(self.memory, read) {
|
|
if !crate::host::read_into(self.memory, read) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- let hash = blake3::hash(read);
|
|
|
|
|
|
|
+ let hash = digest(read);
|
|
|
if last.hash != Some(hash) {
|
|
if last.hash != Some(hash) {
|
|
|
last.hash = Some(hash);
|
|
last.hash = Some(hash);
|
|
|
self.detile(read);
|
|
self.detile(read);
|
|
@@ -1256,14 +1371,14 @@ impl Staging {
|
|
|
let mut got = 0;
|
|
let mut got = 0;
|
|
|
for _ in 0..4 {
|
|
for _ in 0..4 {
|
|
|
got = crate::host::read_there(self.memory, read) as u64;
|
|
got = crate::host::read_there(self.memory, read) as u64;
|
|
|
- crate::watch::change_over();
|
|
|
|
|
there = mapped_bytes(self.memory, size);
|
|
there = mapped_bytes(self.memory, size);
|
|
|
- if got >= there {
|
|
|
|
|
|
|
+ if got >= there.max(self.expected.load(Relaxed)) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
+ crate::watch::change_over();
|
|
|
}
|
|
}
|
|
|
if got != 0 {
|
|
if got != 0 {
|
|
|
- last.hash = Some(blake3::hash(read));
|
|
|
|
|
|
|
+ last.hash = Some(digest(read));
|
|
|
self.detile(read);
|
|
self.detile(read);
|
|
|
}
|
|
}
|
|
|
got
|
|
got
|
|
@@ -1361,14 +1476,14 @@ pub(crate) fn fingerprint(at: u64, len: u64) -> u64 {
|
|
|
static READ: std::cell::RefCell<Vec<u8>> = const { std::cell::RefCell::new(Vec::new()) };
|
|
static READ: std::cell::RefCell<Vec<u8>> = const { std::cell::RefCell::new(Vec::new()) };
|
|
|
}
|
|
}
|
|
|
let len = len as usize;
|
|
let len = len as usize;
|
|
|
- let mut hasher = blake3::Hasher::new();
|
|
|
|
|
|
|
+ let mut print = 0u128;
|
|
|
READ.with(|read| {
|
|
READ.with(|read| {
|
|
|
let mut read = read.borrow_mut();
|
|
let mut read = read.borrow_mut();
|
|
|
read.resize(3 * WINDOW, 0);
|
|
read.resize(3 * WINDOW, 0);
|
|
|
let mut take = |from: usize, bytes: usize| {
|
|
let mut take = |from: usize, bytes: usize| {
|
|
|
read[..bytes].fill(0);
|
|
read[..bytes].fill(0);
|
|
|
crate::host::copy_mapped(read.as_mut_ptr(), (at as usize + from) as *const u8, bytes, false);
|
|
crate::host::copy_mapped(read.as_mut_ptr(), (at as usize + from) as *const u8, bytes, false);
|
|
|
- hasher.update(&read[..bytes]);
|
|
|
|
|
|
|
+ print = print.rotate_left(37) ^ digest(&read[..bytes]).0;
|
|
|
};
|
|
};
|
|
|
if len <= 3 * WINDOW {
|
|
if len <= 3 * WINDOW {
|
|
|
take(0, len);
|
|
take(0, len);
|
|
@@ -1378,9 +1493,7 @@ pub(crate) fn fingerprint(at: u64, len: u64) -> u64 {
|
|
|
take(len - WINDOW, WINDOW);
|
|
take(len - WINDOW, WINDOW);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- let hash = hasher.finalize();
|
|
|
|
|
- let mut first = [0u8; 8];
|
|
|
|
|
- first.copy_from_slice(&hash.as_bytes()[..8]);
|
|
|
|
|
|
|
+ let first = (print as u64 ^ (print >> 64) as u64).to_le_bytes();
|
|
|
u64::from_le_bytes(first) | 1
|
|
u64::from_le_bytes(first) | 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1436,7 +1549,7 @@ pub(crate) fn unchanged(resource: This, first: u32) -> bool {
|
|
|
if crate::host::read_there(memory, read) == 0 {
|
|
if crate::host::read_there(memory, read) == 0 {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- blake3::hash(read) == held
|
|
|
|
|
|
|
+ digest(read) == held
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1456,12 +1569,13 @@ pub(crate) fn is_staged(resource: This) -> bool {
|
|
|
|
|
|
|
|
/// The bytes of a title texture's memory, and whether all of it is mapped,
|
|
/// The bytes of a title texture's memory, and whether all of it is mapped,
|
|
|
/// if the texture has been staged for upload.
|
|
/// if the texture has been staged for upload.
|
|
|
-pub(crate) fn staged(resource: This) -> Option<(u64, bool)> {
|
|
|
|
|
|
|
+/// (Whether it is mapped is asked only if `ask`; else it counts as mapped.)
|
|
|
|
|
+pub(crate) fn staged(resource: This, ask: bool) -> Option<(u64, bool)> {
|
|
|
let s = {
|
|
let s = {
|
|
|
let map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
|
|
let map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
|
|
|
map.as_ref()?.get(&(resource as usize))?.clone()
|
|
map.as_ref()?.get(&(resource as usize))?.clone()
|
|
|
};
|
|
};
|
|
|
- Some((s.read as u64, committed(s.memory, s.read)))
|
|
|
|
|
|
|
+ Some((s.read as u64, !ask || committed(s.memory, s.read)))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Whether `[at, at + len)` is committed memory (streamed textures may be
|
|
/// Whether `[at, at + len)` is committed memory (streamed textures may be
|
|
@@ -1713,7 +1827,7 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
|
|
|
read,
|
|
read,
|
|
|
serial: copy.serial,
|
|
serial: copy.serial,
|
|
|
holds: copy.holds.clone(),
|
|
holds: copy.holds.clone(),
|
|
|
- waits: std::sync::atomic::AtomicBool::new(false),
|
|
|
|
|
|
|
+ once: std::sync::atomic::AtomicBool::new(once() && !on_demand && PICKING.get().is_some()),
|
|
|
bytes: total,
|
|
bytes: total,
|
|
|
memory,
|
|
memory,
|
|
|
last: Mutex::default(),
|
|
last: Mutex::default(),
|
|
@@ -1932,6 +2046,36 @@ mod allocation_costs {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// The digest tells every length and every changed byte apart, zeros
|
|
|
|
|
+ /// among them.
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn a_digest_tells_bytes_apart() {
|
|
|
|
|
+ use super::digest;
|
|
|
|
|
+ let zeros = [0u8; 400];
|
|
|
|
|
+ let mut seen: Vec<super::Digest> = (0..400).map(|n| digest(&zeros[..n])).collect();
|
|
|
|
|
+ for at in 0..400 {
|
|
|
|
|
+ for value in [1u8, 0x80, 0xff] {
|
|
|
|
|
+ let mut bytes = zeros;
|
|
|
|
|
+ bytes[at] = value;
|
|
|
|
|
+ seen.push(digest(&bytes));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let text: Vec<u8> = (0..400u32).map(|i| (i * 37 >> 2) as u8).collect();
|
|
|
|
|
+ for at in 0..399 {
|
|
|
|
|
+ let mut bytes = text.clone();
|
|
|
|
|
+ bytes.swap(at, at + 1);
|
|
|
|
|
+ if bytes != text {
|
|
|
|
|
+ seen.push(digest(&bytes));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ seen.push(digest(&text));
|
|
|
|
|
+ let n = seen.len();
|
|
|
|
|
+ seen.sort_unstable_by_key(|d| d.0);
|
|
|
|
|
+ seen.dedup();
|
|
|
|
|
+ assert_eq!(seen.len(), n);
|
|
|
|
|
+ assert_eq!(digest(&text), digest(&text.clone()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/// What a texture met for the first time costs, by step, in
|
|
/// What a texture met for the first time costs, by step, in
|
|
|
/// milliseconds a megabyte on one thread: for whether a store of
|
|
/// milliseconds a megabyte on one thread: for whether a store of
|
|
|
/// detiled copies on disk could be worth it (its key is a hash of the
|
|
/// detiled copies on disk could be worth it (its key is a hash of the
|
|
@@ -1965,6 +2109,9 @@ mod allocation_costs {
|
|
|
timed("blake3", &mut || {
|
|
timed("blake3", &mut || {
|
|
|
std::hint::black_box(blake3::hash(&title));
|
|
std::hint::black_box(blake3::hash(&title));
|
|
|
});
|
|
});
|
|
|
|
|
+ timed("digest", &mut || {
|
|
|
|
|
+ std::hint::black_box(super::digest(&title));
|
|
|
|
|
+ });
|
|
|
timed("detiled into upload memory", &mut || {
|
|
timed("detiled into upload memory", &mut || {
|
|
|
let mut at = 0;
|
|
let mut at = 0;
|
|
|
for (mip, m) in layout.mips.iter().enumerate() {
|
|
for (mip, m) in layout.mips.iter().enumerate() {
|