|
|
@@ -735,8 +735,13 @@ pub(crate) struct HostList {
|
|
|
/// The pipelines the list binds, for reports of slow submissions.
|
|
|
pipelines: Mutex<std::collections::BTreeSet<String>>,
|
|
|
/// The work its indirect executions may still do (`indirect`): a
|
|
|
- /// shader-writable word, zeroed when the list is submitted.
|
|
|
+ /// shader-writable word, zeroed when the list is submitted, and after
|
|
|
+ /// it what the clamp notes about mesh records. In memory the CPU maps.
|
|
|
budget: OnceLock<Option<(ID3D12Resource, usize)>>,
|
|
|
+ /// The same words in the card's own memory ([`card_budget`]), which the
|
|
|
+ /// clamp uses instead when there is one: zeroed in the list before its
|
|
|
+ /// first clamp, its notes copied to `budget` when the list closes.
|
|
|
+ card_budget: OnceLock<Option<ID3D12Resource>>,
|
|
|
/// Device-local scratch buffer for clamped indirect arguments (`indirect`),
|
|
|
/// grown to the largest indirect execution recorded on the list.
|
|
|
indirect_args: Mutex<Option<(ID3D12Resource, u64)>>,
|
|
|
@@ -1216,6 +1221,16 @@ pub(crate) fn dred_on() -> bool {
|
|
|
/// budget buffers, a run late).
|
|
|
static MESH_GROUPS: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2];
|
|
|
|
|
|
+/// Whether a list's indirect-work budget lives in the card's own memory
|
|
|
+/// (`VICTORY_INDIRECT_CARD_BUDGET=0` keeps it in memory the CPU maps, as
|
|
|
+/// before). The clamp charges it with atomics, at least two in a row for
|
|
|
+/// every clamp; in mapped memory on a card of its own each of them
|
|
|
+/// crosses the bus.
|
|
|
+fn card_budget() -> bool {
|
|
|
+ static ON: OnceLock<bool> = OnceLock::new();
|
|
|
+ *ON.get_or_init(|| std::env::var_os("VICTORY_INDIRECT_CARD_BUDGET").is_none_or(|v| v != "0"))
|
|
|
+}
|
|
|
+
|
|
|
/// Whether each list of a submission runs and is timed on its own, slow
|
|
|
/// ones logged with their commands (`VICTORY_GPU_TIMING`, diagnostics
|
|
|
/// builds; the commands are noted with `VICTORY_D3D12_DRED` on).
|
|
|
@@ -1598,7 +1613,8 @@ struct Deferred {
|
|
|
/// memory they go to, the bytes of a row, the rows, the title's row
|
|
|
/// pitch.
|
|
|
backs: Vec<(ID3D12Resource, usize, [usize; 3])>,
|
|
|
- /// Whether a step zeroes the indirect-work budget.
|
|
|
+ /// Whether the indirect-work budget is zeroed for this recording (a
|
|
|
+ /// step on the CPU, or in the list for the card's copy).
|
|
|
budget_zeroed: bool,
|
|
|
/// The indirect scratch buffer (`HostList::indirect_args`, by its
|
|
|
/// interface pointer) that a clamp in this recording left readable as
|
|
|
@@ -2838,6 +2854,7 @@ impl Host {
|
|
|
prelude,
|
|
|
pipelines: Mutex::default(),
|
|
|
budget: OnceLock::new(),
|
|
|
+ card_budget: OnceLock::new(),
|
|
|
indirect_args: Mutex::default(),
|
|
|
_alive: Counted::new(),
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
@@ -4415,6 +4432,7 @@ impl HostList {
|
|
|
if let Some((scratch, _)) = scratch {
|
|
|
self.indirect_common(&scratch);
|
|
|
}
|
|
|
+ self.card_budget_out();
|
|
|
#[cfg(feature = "diagnostics")]
|
|
|
if let Some((heap, back)) = self.stamps() {
|
|
|
let count = (self.notes.lock().unwrap_or_else(|e| e.into_inner()).len() as u32).min(STAMPS - 1);
|
|
|
@@ -4998,6 +5016,7 @@ impl HostList {
|
|
|
Some((b, d as usize))
|
|
|
})
|
|
|
.as_ref()?;
|
|
|
+ let card = self.card_budget.get_or_init(|| self.make_card_budget()).as_ref();
|
|
|
let mut deferred = self.deferred();
|
|
|
if !deferred.budget_zeroed {
|
|
|
deferred.budget_zeroed = true;
|
|
|
@@ -5005,7 +5024,8 @@ impl HostList {
|
|
|
// SAFETY: the list's own mapped words, written before it runs.
|
|
|
// The words after the budget hold what the clamp noted about the
|
|
|
// list's last run (mesh dispatches: the largest group count
|
|
|
- // asked for, the groups asked in all): taken, then zeroed.
|
|
|
+ // asked for, the groups asked in all; with the card's copy, as
|
|
|
+ // the list's end copied them here): taken, then zeroed.
|
|
|
deferred.copies.push(Step::Host(Box::new(move || unsafe {
|
|
|
let words = at as *mut u32;
|
|
|
let (largest, all) = (words.add(1).read_volatile(), words.add(2).read_volatile());
|
|
|
@@ -5015,9 +5035,84 @@ impl HostList {
|
|
|
words.add(k).write_volatile(0);
|
|
|
}
|
|
|
})));
|
|
|
+ drop(deferred);
|
|
|
+ if let Some(card) = card {
|
|
|
+ self.zero_card_budget(card);
|
|
|
+ }
|
|
|
}
|
|
|
// SAFETY: a live buffer.
|
|
|
- Some(unsafe { buffer.GetGPUVirtualAddress() })
|
|
|
+ Some(unsafe { card.unwrap_or(buffer).GetGPUVirtualAddress() })
|
|
|
+ }
|
|
|
+
|
|
|
+ /// The budget's words in the card's own memory ([`card_budget`]), if
|
|
|
+ /// the list can zero them itself (`WriteBufferImmediate`).
|
|
|
+ fn make_card_budget(&self) -> Option<ID3D12Resource> {
|
|
|
+ if !card_budget() {
|
|
|
+ return None;
|
|
|
+ }
|
|
|
+ self.list.cast::<ID3D12GraphicsCommandList2>().ok()?;
|
|
|
+ let buffer = host()?.uav_buffer(256)?;
|
|
|
+ name(&buffer, || "indirect budget".to_owned());
|
|
|
+ Some(buffer)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Records, before the list's first clamp, the zeroing of the card's
|
|
|
+ /// copy of the budget: common, written as a copy, then left for
|
|
|
+ /// unordered access until the list closes ([`HostList::card_budget_out`]).
|
|
|
+ fn zero_card_budget(&self, card: &ID3D12Resource) {
|
|
|
+ let Ok(list2) = self.list.cast::<ID3D12GraphicsCommandList2>() else {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ // SAFETY: a live buffer.
|
|
|
+ let at = unsafe { card.GetGPUVirtualAddress() };
|
|
|
+ let zeros = [0u64, 4, 8].map(|offset| D3D12_WRITEBUFFERIMMEDIATE_PARAMETER {
|
|
|
+ Dest: at + offset,
|
|
|
+ Value: 0,
|
|
|
+ });
|
|
|
+ // SAFETY: an open list; the buffer is the list's own and in the
|
|
|
+ // common state at the start of every recording.
|
|
|
+ unsafe {
|
|
|
+ self.list.ResourceBarrier(&[transition(
|
|
|
+ card,
|
|
|
+ D3D12_RESOURCE_STATE_COMMON,
|
|
|
+ D3D12_RESOURCE_STATE_COPY_DEST,
|
|
|
+ )]);
|
|
|
+ list2.WriteBufferImmediate(zeros.len() as u32, zeros.as_ptr(), None);
|
|
|
+ self.list.ResourceBarrier(&[transition(
|
|
|
+ card,
|
|
|
+ D3D12_RESOURCE_STATE_COPY_DEST,
|
|
|
+ D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
|
|
+ )]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Before the list closes, if this recording charged the card's copy
|
|
|
+ /// of the budget: its notes on mesh records go to the mapped words
|
|
|
+ /// (read at the next submission), and it goes back to common.
|
|
|
+ fn card_budget_out(&self) {
|
|
|
+ if !self.deferred().budget_zeroed {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let (Some(Some(card)), Some(Some((mapped, _)))) =
|
|
|
+ (self.card_budget.get(), self.budget.get())
|
|
|
+ else {
|
|
|
+ return;
|
|
|
+ };
|
|
|
+ // SAFETY: an open list; both buffers are the list's own. The
|
|
|
+ // mapped one is promoted from common to the copy destination.
|
|
|
+ unsafe {
|
|
|
+ self.list.ResourceBarrier(&[transition(
|
|
|
+ card,
|
|
|
+ D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
|
|
+ D3D12_RESOURCE_STATE_COPY_SOURCE,
|
|
|
+ )]);
|
|
|
+ self.list.CopyBufferRegion(mapped, 4, card, 4, 8);
|
|
|
+ self.list.ResourceBarrier(&[transition(
|
|
|
+ card,
|
|
|
+ D3D12_RESOURCE_STATE_COPY_SOURCE,
|
|
|
+ D3D12_RESOURCE_STATE_COMMON,
|
|
|
+ )]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// A device-local unordered-access buffer of at least `size` bytes for
|