|
|
@@ -61,6 +61,9 @@ pub(crate) struct Staging {
|
|
|
uploaded: std::sync::atomic::AtomicBool,
|
|
|
/// When a list last recorded a use of it (`crate::host::moment`).
|
|
|
used: std::sync::atomic::AtomicU64,
|
|
|
+ /// How many bytes of the texture's memory were mapped when a list last
|
|
|
+ /// recorded an upload of it ([`fill_unlocked`]; 0: not asked).
|
|
|
+ expected: std::sync::atomic::AtomicU64,
|
|
|
/// Levels on demand (`crate::tiles`): the texture's host copy was made
|
|
|
/// without memory of its own when the staging buffer was made.
|
|
|
on_demand: bool,
|
|
|
@@ -344,16 +347,38 @@ pub(crate) fn alias(list: &HostList, placed: This, source: This) -> bool {
|
|
|
/// through the kernel costs about 0.6 ms a megabyte against 0.3 in place.
|
|
|
///
|
|
|
/// What changes for the picture: a texture that arrives while the runtime
|
|
|
-/// is remapping may show a frame later. It never shows partly read.
|
|
|
+/// is remapping may show a frame later. A staging buffer that holds nothing
|
|
|
+/// yet is filled with what is there all the same ([`fill_unlocked`]): a list
|
|
|
+/// has recorded the upload from it by then.
|
|
|
fn no_wait() -> bool {
|
|
|
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
|
*ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_NO_WAIT").is_some_and(|v| v == "1"))
|
|
|
}
|
|
|
|
|
|
+/// Whether a refresh that does not wait ([`no_wait`]) and finds a page
|
|
|
+/// missing fills a staging buffer that was never filled from the pages that
|
|
|
+/// are there (`VICTORY_TEXTURE_FILL=0`: it was left as it was made).
|
|
|
+///
|
|
|
+/// Left for the next refresh, it was uploaded as it was: the upload is
|
|
|
+/// recorded before the refresh, and a texture picked by index has no next
|
|
|
+/// refresh (its staging buffer goes with the upload). A texture the title
|
|
|
+/// holds only the smaller levels of is never all there, so whenever the
|
|
|
+/// runtime was remapping at that moment, its levels became zeros on the
|
|
|
+/// card, good ones too: of 16,135 textures a recorded frame's slots show,
|
|
|
+/// 2,382 had zeros in the first level shown; 137 of that frame's 787 repeated
|
|
|
+/// uploads put zeros over a filled level (run pic1-1; 68,700 refreshes left
|
|
|
+/// in the 150 s of world of run play1).
|
|
|
+fn fill_unlocked() -> bool {
|
|
|
+ static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
|
+ *ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_FILL").is_none_or(|v| v != "0"))
|
|
|
+}
|
|
|
+
|
|
|
/// Since the last frame-rate line, with [`no_wait`]: refreshes that read
|
|
|
/// through the kernel because title memory was being remapped, and those
|
|
|
-/// left for the next refresh because a page was not there.
|
|
|
-pub(crate) static UNLOCKED: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2];
|
|
|
+/// left for the next refresh because a page was not there; staging buffers
|
|
|
+/// filled from the pages there ([`fill_unlocked`]), and of them those that
|
|
|
+/// got less than was mapped (their slots are looked at again).
|
|
|
+pub(crate) static UNLOCKED: [std::sync::atomic::AtomicU64; 4] = [const { std::sync::atomic::AtomicU64::new(0) }; 4];
|
|
|
|
|
|
/// Since the last frame-rate line, of texture refreshes on every thread, in
|
|
|
/// microseconds: waiting for the texture's own lock (another thread is
|
|
|
@@ -658,6 +683,10 @@ pub(crate) fn upload(list: &HostList, resource: This, texture: &ID3D12Resource)
|
|
|
}
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
crate::copystat::add(crate::copystat::C::TexUploads, 1);
|
|
|
+ if no_wait() && fill_unlocked() {
|
|
|
+ let there = mapped_bytes(staging.memory, staging.layout.size as usize);
|
|
|
+ staging.expected.store(there, 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.
|
|
|
@@ -1115,10 +1144,11 @@ impl Staging {
|
|
|
|
|
|
/// A refresh while the runtime is remapping title memory ([`no_wait`]):
|
|
|
/// the texture is read through the kernel, which fails if a page of it
|
|
|
- /// is not there at this moment. Then nothing is taken and the texture
|
|
|
- /// is looked at again at its next refresh (what was learnt about writes
|
|
|
- /// to it is forgotten, so that it is not passed over as unwritten).
|
|
|
- /// Returns the bytes read.
|
|
|
+ /// is not there at this moment. Then a staging buffer that was filled
|
|
|
+ /// before keeps what it holds and the texture is looked at again at its
|
|
|
+ /// next refresh (what was learnt about writes to it is forgotten, so
|
|
|
+ /// that it is not passed over as unwritten); one never filled takes the
|
|
|
+ /// pages that are there ([`Staging::fill`]). Returns the bytes read.
|
|
|
fn refresh_unlocked(&self, last: &mut Last, size: usize) -> usize {
|
|
|
use std::sync::atomic::Ordering::Relaxed;
|
|
|
let read = with_read(size, |read| {
|
|
|
@@ -1135,6 +1165,8 @@ impl Staging {
|
|
|
if read {
|
|
|
UNLOCKED[0].fetch_add(1, Relaxed);
|
|
|
size
|
|
|
+ } else if last.hash.is_none() && fill_unlocked() {
|
|
|
+ self.fill(last, size)
|
|
|
} else {
|
|
|
UNLOCKED[1].fetch_add(1, Relaxed);
|
|
|
last.asked = 0;
|
|
|
@@ -1142,6 +1174,46 @@ impl Staging {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// The first filling of the staging buffer while the runtime is
|
|
|
+ /// remapping title memory, of a texture not all of which can be read:
|
|
|
+ /// with the pages that are there, zeros for the others, as a partly
|
|
|
+ /// mapped texture is filled under the lock. Pages that are away only
|
|
|
+ /// for the moment of a change (the runtime unmaps the rest of a view to
|
|
|
+ /// change one page of it) are read when that change is over. If less
|
|
|
+ /// was read than was mapped when the upload was recorded, or is mapped
|
|
|
+ /// now, the texture's slots are looked at again.
|
|
|
+ fn fill(&self, last: &mut Last, size: usize) -> usize {
|
|
|
+ use std::sync::atomic::Ordering::Relaxed;
|
|
|
+ let start = self.memory as u64;
|
|
|
+ let mut there = 0;
|
|
|
+ let got = with_read(size, |read| {
|
|
|
+ let mut got = 0;
|
|
|
+ for _ in 0..4 {
|
|
|
+ got = crate::host::read_there(self.memory, read) as u64;
|
|
|
+ crate::watch::change_over();
|
|
|
+ there = mapped_bytes(self.memory, size);
|
|
|
+ if got >= there {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if got != 0 {
|
|
|
+ last.hash = Some(blake3::hash(read));
|
|
|
+ self.detile(read);
|
|
|
+ }
|
|
|
+ got
|
|
|
+ });
|
|
|
+ last.partial = Some(crate::frame::current());
|
|
|
+ UNLOCKED[2].fetch_add(1, Relaxed);
|
|
|
+ if got < there.max(self.expected.load(Relaxed)) {
|
|
|
+ UNLOCKED[3].fetch_add(1, Relaxed);
|
|
|
+ last.asked = 0;
|
|
|
+ crate::descriptor::host::read_short(start);
|
|
|
+ } else {
|
|
|
+ crate::descriptor::host::read_all(start);
|
|
|
+ }
|
|
|
+ size
|
|
|
+ }
|
|
|
+
|
|
|
/// Detiles `tiled` (the texture's memory) into the staging buffer.
|
|
|
fn detile(&self, tiled: &[u8]) {
|
|
|
self.dirty.store(true, std::sync::atomic::Ordering::Relaxed);
|
|
|
@@ -1512,6 +1584,7 @@ fn staging(resource: This, texture: &ID3D12Resource) -> Option<Arc<Staging>> {
|
|
|
dirty: std::sync::atomic::AtomicBool::new(true),
|
|
|
uploaded: std::sync::atomic::AtomicBool::new(false),
|
|
|
used: std::sync::atomic::AtomicU64::new(crate::host::moment()),
|
|
|
+ expected: std::sync::atomic::AtomicU64::new(0),
|
|
|
on_demand,
|
|
|
detiled: std::sync::atomic::AtomicU32::new(0),
|
|
|
judged: [const { std::sync::atomic::AtomicU64::new(0) }; 2],
|