A range shaders write is declared once until the list next writes title memory (from Belobug dd799aad, romainhedouin); VICTORY_DECLARE_ONCE=0 for the old way
Dispatches declare the same few ranges again and again: 4,003 to 5,550 steps a frame of fork-b1-fast, each a flush of its copy's pending refreshes and two locks on the thread that submits (the snapshots alone 1.7 to 2.0 ms a frame). The ranges and their order stay what they were. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2547124475
commit
c8ede50886
2 files changed
+31
-7
No files matched your search
@@ -2184,6 +2184,10 @@ struct Deferred {
|
|||||||
/// Buffer ranges refreshed since the last title copy (host copy,
|
/// Buffer ranges refreshed since the last title copy (host copy,
|
||||||
/// address, bytes): refreshing them again would find the same bytes.
|
/// address, bytes): refreshing them again would find the same bytes.
|
||||||
refreshed: std::collections::HashSet<(usize, usize, usize), std::hash::BuildHasherDefault<AddressHash>>,
|
refreshed: std::collections::HashSet<(usize, usize, usize), std::hash::BuildHasherDefault<AddressHash>>,
|
||||||
|
/// Ranges declared written by shaders since the list last wrote title
|
||||||
|
/// memory (host copy, address, bytes): declaring them again would
|
||||||
|
/// change nothing.
|
||||||
|
gpu_written: std::collections::HashSet<(usize, usize, usize), std::hash::BuildHasherDefault<AddressHash>>,
|
||||||
/// Textures whose contents the list brings up to date.
|
/// Textures whose contents the list brings up to date.
|
||||||
textures: std::collections::HashSet<usize>,
|
textures: std::collections::HashSet<usize>,
|
||||||
/// Bottom-of-pipe writes, done once the list has run: address, what,
|
/// Bottom-of-pipe writes, done once the list has run: address, what,
|
||||||
@@ -2218,6 +2222,13 @@ impl Deferred {
|
|||||||
self.upload_bytes += size;
|
self.upload_bytes += size;
|
||||||
self.uploads.push(buffer);
|
self.uploads.push(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The steps recorded last write title memory: what was brought up to
|
||||||
|
/// date before them is not any more.
|
||||||
|
fn title_written(&mut self) {
|
||||||
|
self.refreshed.clear();
|
||||||
|
self.gpu_written.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Deferred {
|
impl Drop for Deferred {
|
||||||
@@ -3685,6 +3696,12 @@ fn continues(last: (usize, usize, usize), next: (usize, usize, usize)) -> bool {
|
|||||||
&& (d.checked_add(all).is_some_and(|end| end <= s) || s.checked_add(all).is_some_and(|end| end <= d))
|
&& (d.checked_add(all).is_some_and(|end| end <= s) || s.checked_add(all).is_some_and(|end| end <= d))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See [`HostList::defer_gpu_write`].
|
||||||
|
fn declare_once() -> bool {
|
||||||
|
static ON: OnceLock<bool> = OnceLock::new();
|
||||||
|
*ON.get_or_init(|| std::env::var("VICTORY_DECLARE_ONCE").map_or(true, |v| v != "0"))
|
||||||
|
}
|
||||||
|
|
||||||
/// The ranges the shaders of `runs` may write, per host copy, as declared.
|
/// The ranges the shaders of `runs` may write, per host copy, as declared.
|
||||||
/// One list's lock at a time: a submission may name a list twice.
|
/// One list's lock at a time: a submission may name a list twice.
|
||||||
fn declared_writes(runs: &[&HostList]) -> Vec<Declared> {
|
fn declared_writes(runs: &[&HostList]) -> Vec<Declared> {
|
||||||
@@ -6630,7 +6647,7 @@ impl HostList {
|
|||||||
deferred
|
deferred
|
||||||
.copies
|
.copies
|
||||||
.push(Step::Copy(dst as usize, src as usize, len));
|
.push(Step::Copy(dst as usize, src as usize, len));
|
||||||
deferred.refreshed.clear();
|
deferred.title_written();
|
||||||
self.changed_something();
|
self.changed_something();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6677,15 +6694,20 @@ impl HostList {
|
|||||||
|
|
||||||
/// Shaders of the list write `[address, address + len)` of a buffer's
|
/// Shaders of the list write `[address, address + len)` of a buffer's
|
||||||
/// host copy: copied back into title memory once the list has run.
|
/// host copy: copied back into title memory once the list has run.
|
||||||
|
/// Declared once until the list next writes title memory (but with
|
||||||
|
/// `VICTORY_DECLARE_ONCE=0`): the dispatches of a frame declared the
|
||||||
|
/// same ranges thousands of times, each a step of its own.
|
||||||
pub(crate) fn defer_gpu_write(
|
pub(crate) fn defer_gpu_write(
|
||||||
&self,
|
&self,
|
||||||
shadow: &std::sync::Arc<crate::shadow::Shadow>,
|
shadow: &std::sync::Arc<crate::shadow::Shadow>,
|
||||||
address: usize,
|
address: usize,
|
||||||
len: usize,
|
len: usize,
|
||||||
) {
|
) {
|
||||||
self.deferred()
|
let mut deferred = self.deferred();
|
||||||
.copies
|
let key = (std::sync::Arc::as_ptr(shadow) as usize, address, len);
|
||||||
.push(Step::GpuWrite(shadow.clone(), address, len));
|
if deferred.gpu_written.insert(key) || !declare_once() {
|
||||||
|
deferred.copies.push(Step::GpuWrite(shadow.clone(), address, len));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A read back: once the list has run, `rows` rows of `row` bytes go
|
/// A read back: once the list has run, `rows` rows of `row` bytes go
|
||||||
@@ -7012,8 +7034,10 @@ impl HostList {
|
|||||||
/// Runs `work` when the list is submitted, in order with its copies.
|
/// Runs `work` when the list is submitted, in order with its copies.
|
||||||
/// `work` may write title memory (refreshes after it copy again).
|
/// `work` may write title memory (refreshes after it copy again).
|
||||||
pub(crate) fn defer(&self, work: impl Fn() + Send + 'static) {
|
pub(crate) fn defer(&self, work: impl Fn() + Send + 'static) {
|
||||||
self.deferred().copies.push(Step::Run(Box::new(work)));
|
let mut deferred = self.deferred();
|
||||||
self.deferred().refreshed.clear();
|
deferred.copies.push(Step::Run(Box::new(work)));
|
||||||
|
deferred.title_written();
|
||||||
|
drop(deferred);
|
||||||
self.changed_something();
|
self.changed_something();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ impl HostList {
|
|||||||
shadow: to,
|
shadow: to,
|
||||||
from: scratch.map(|s| s.2 as usize),
|
from: scratch.map(|s| s.2 as usize),
|
||||||
}));
|
}));
|
||||||
deferred.refreshed.clear();
|
deferred.title_written();
|
||||||
self.changed_something();
|
self.changed_something();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user