upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/crates/victory-gpu/src/texture.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/victory-gpu/src/texture.rs')
-rw-r--r--crates/victory-gpu/src/texture.rs34
1 files changed, 27 insertions, 7 deletions
diff --git a/crates/victory-gpu/src/texture.rs b/crates/victory-gpu/src/texture.rs
index 61bd6bc..e749738 100644
--- a/crates/victory-gpu/src/texture.rs
+++ b/crates/victory-gpu/src/texture.rs
@@ -91,6 +91,11 @@ pub(crate) struct Staging {
91 /// recorded again about a second later if the card has room by then 91 /// recorded again about a second later if the card has room by then
92 /// ([`upload`]). 92 /// ([`upload`]).
93 waiting: std::sync::atomic::AtomicU64, 93 waiting: std::sync::atomic::AtomicU64,
94 /// Recorded for a one-shot decoration bake (`BAKING`): submission-time
95 /// refresh must wait for title memory to stop remapping
96 /// (`title_memory_reading`) instead of taking `no_wait()` /
97 /// `refresh_unlocked()` or the 30-frame partial-read throttle.
98 exact: std::sync::atomic::AtomicBool,
94} 99}
95 100
96/// What a texture's staging buffer holds: the hash of the memory detiled 101/// What a texture's staging buffer holds: the hash of the memory detiled
@@ -756,6 +761,10 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
756 return; 761 return;
757 }; 762 };
758 use std::sync::atomic::Ordering::Relaxed; 763 use std::sync::atomic::Ordering::Relaxed;
764 let baking = BAKING.get();
765 if baking {
766 staging.exact.store(true, Relaxed);
767 }
759 let picking = PICKING.get(); 768 let picking = PICKING.get();
760 if picking.is_none() { 769 if picking.is_none() {
761 // A draw samples it through a table: kept and checked from here on. 770 // A draw samples it through a table: kept and checked from here on.
@@ -810,8 +819,10 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
810 // The host texture has the staging buffer's contents: only the check 819 // The host texture has the staging buffer's contents: only the check
811 // at submission is left, and what it finds changed the next list that 820 // at submission is left, and what it finds changed the next list that
812 // samples the texture uploads (a frame late where every list of the 821 // samples the texture uploads (a frame late where every list of the
813 // frame was recorded before that check). 822 // frame was recorded before that check). During a one-shot bake we
814 if staging.uploaded.load(Relaxed) && !staging.dirty.load(Relaxed) { 823 // always record the copy so any change found at submission lands in
824 // VRAM before the bake draw executes.
825 if !baking && staging.uploaded.load(Relaxed) && !staging.dirty.load(Relaxed) {
815 #[cfg(feature = "diagnostics")] 826 #[cfg(feature = "diagnostics")]
816 crate::copystat::add(crate::copystat::C::TexSkipped, 1); 827 crate::copystat::add(crate::copystat::C::TexSkipped, 1);
817 list.defer_texture(staging); 828 list.defer_texture(staging);
@@ -1254,12 +1265,13 @@ impl Staging {
1254 let start = self.memory as usize; 1265 let start = self.memory as usize;
1255 let mut last = waited(0, || self.last.lock().unwrap_or_else(|e| e.into_inner())); 1266 let mut last = waited(0, || self.last.lock().unwrap_or_else(|e| e.into_inner()));
1256 let last = &mut *last; 1267 let last = &mut *last;
1268 let exact = self.exact.swap(false, std::sync::atomic::Ordering::Relaxed);
1257 let alone = self.once.load(std::sync::atomic::Ordering::Relaxed); 1269 let alone = self.once.load(std::sync::atomic::Ordering::Relaxed);
1258 if alone && last.hash.is_some() { 1270 if alone && !exact && last.hash.is_some() {
1259 return 0; 1271 return 0;
1260 } 1272 }
1261 if !alone && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) { 1273 if !alone && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) {
1262 if last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) { 1274 if !exact && last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) {
1263 return 0; 1275 return 0;
1264 } 1276 }
1265 last.asked = now; 1277 last.asked = now;
@@ -1303,7 +1315,7 @@ impl Staging {
1303 last.hot_until = frame + HOT_FRAMES; 1315 last.hot_until = frame + HOT_FRAMES;
1304 } 1316 }
1305 let hot = hot_textures() && frame < last.hot_until; 1317 let hot = hot_textures() && frame < last.hot_until;
1306 if unwritten && !turn && !hot { 1318 if !exact && unwritten && !turn && !hot {
1307 return 0; 1319 return 0;
1308 } 1320 }
1309 blind = unwritten; 1321 blind = unwritten;
@@ -1322,7 +1334,7 @@ impl Staging {
1322 // stays mapped (see `crate::watch::title_memory_reading`; without 1334 // stays mapped (see `crate::watch::title_memory_reading`; without
1323 // it a page went between the asking and the read in runs 71 and 1335 // it a page went between the asking and the read in runs 71 and
1324 // 74). 1336 // 74).
1325 let _mapped = if no_wait() { 1337 let _mapped = if no_wait() && !exact {
1326 // Not waited for: while the runtime remaps title memory the 1338 // Not waited for: while the runtime remaps title memory the
1327 // texture is read through the kernel instead, whole or not at 1339 // texture is read through the kernel instead, whole or not at
1328 // all (`no_wait`). 1340 // all (`no_wait`).
@@ -1342,7 +1354,7 @@ impl Staging {
1342 // unmapped pages is slow, and nothing tells us when pages 1354 // unmapped pages is slow, and nothing tells us when pages
1343 // arrive): a mip that streams in shows up to 30 frames late. 1355 // arrive): a mip that streams in shows up to 30 frames late.
1344 let frame = crate::frame::current(); 1356 let frame = crate::frame::current();
1345 if last.partial.is_some_and(|at| frame < at + 30) { 1357 if !exact && last.partial.is_some_and(|at| frame < at + 30) {
1346 return 0; 1358 return 0;
1347 } 1359 }
1348 last.partial = Some(frame); 1360 last.partial = Some(frame);
@@ -1878,6 +1890,13 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
1878 let (piece, buffer, base, data) = match crate::pool::staging(host, total) { 1890 let (piece, buffer, base, data) = match crate::pool::staging(host, total) {
1879 Some((piece, buffer, base, data)) => (Some(piece), buffer, base, data), 1891 Some((piece, buffer, base, data)) => (Some(piece), buffer, base, data),
1880 None => { 1892 None => {
1893 let speculative = PICKING.get().is_some() && !BAKING.get();
1894 if crate::residency::upload_refused()
1895 || (speculative && !crate::residency::allow_staging_growth(false))
1896 {
1897 crate::residency::note_staging_deferred();
1898 return None;
1899 }
1881 let (buffer, data) = host.upload_buffer(total)?; 1900 let (buffer, data) = host.upload_buffer(total)?;
1882 crate::host::name(&buffer, || { 1901 crate::host::name(&buffer, || {
1883 format!( 1902 format!(
@@ -1919,6 +1938,7 @@ fn staging(resource: This, copy: &crate::resource::HostTexture, first: u32) -> O
1919 detiled: std::sync::atomic::AtomicU32::new(0), 1938 detiled: std::sync::atomic::AtomicU32::new(0),
1920 judged: [const { std::sync::atomic::AtomicU64::new(0) }; 2], 1939 judged: [const { std::sync::atomic::AtomicU64::new(0) }; 2],
1921 waiting: std::sync::atomic::AtomicU64::new(0), 1940 waiting: std::sync::atomic::AtomicU64::new(0),
1941 exact: std::sync::atomic::AtomicBool::new(BAKING.get()),
1922 }); 1942 });
1923 map.insert(resource as usize, s.clone()); 1943 map.insert(resource as usize, s.clone());
1924 Some(s) 1944 Some(s)