Argument clamps in batches (VICTORY_INDIRECT_BATCH)
One pass clamps the arguments of all indirect executions between two points where they may change; its jobs are in upload memory that is filled while the list is recorded. The replayed frame: 2,355 clamps become 980 passes, 86.1 -> 77.7 ms; with VICTORY_INDIRECT_BATCH=2 133 passes, 84.6 -> 75.3 ms. Replay: --batch-clamps, --only-buffers, --listing; --compare runs turn by turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
65b4c43ec1
commit
037596241a
9 files changed
+1492
-53
No files matched your search
@@ -767,6 +767,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The batches of clamped records in one scratch buffer
|
||||
/// ([`HostList::batch_place`]).
|
||||
const BATCHES: u32 = 8;
|
||||
|
||||
/// A host command list and its allocator, always used together.
|
||||
pub(crate) struct HostList {
|
||||
allocator: ID3D12CommandAllocator,
|
||||
@@ -802,6 +806,9 @@ pub(crate) struct HostList {
|
||||
/// 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)>>,
|
||||
/// Scratch buffers of the batched clamps (`crate::indirect::batch`), and
|
||||
/// how many batches of this recording have a place in them.
|
||||
batch_args: Mutex<(Vec<ID3D12Resource>, u32)>,
|
||||
/// Counts the list in [`ALIVE`] while it lives.
|
||||
_alive: Counted,
|
||||
/// The texts of the markers `note_op` set, in order (for device-removed
|
||||
@@ -3221,6 +3228,7 @@ impl Host {
|
||||
budget: OnceLock::new(),
|
||||
card_budget: OnceLock::new(),
|
||||
indirect_args: Mutex::default(),
|
||||
batch_args: Mutex::default(),
|
||||
_alive: Counted::new(),
|
||||
#[cfg(feature = "diagnostics")]
|
||||
notes: Mutex::default(),
|
||||
@@ -4873,6 +4881,7 @@ impl HostList {
|
||||
if let Some((scratch, _)) = scratch {
|
||||
self.indirect_common(&scratch);
|
||||
}
|
||||
self.batches_common();
|
||||
self.card_budget_out();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if let Some((heap, back)) = self.stamps() {
|
||||
@@ -5594,6 +5603,43 @@ impl HostList {
|
||||
Some(buffer)
|
||||
}
|
||||
|
||||
/// Where the next batch of clamped records goes: a device-local buffer
|
||||
/// the list keeps from recording to recording, the batch's place in it
|
||||
/// and the state the buffer is in. Every batch of a recording has a place
|
||||
/// of its own: the executions before it may still read theirs.
|
||||
pub(crate) fn batch_place(&self) -> Option<(ID3D12Resource, u32, D3D12_RESOURCE_STATES)> {
|
||||
use crate::indirect::batch::{JOBS, SLOT};
|
||||
let mut args = self.batch_args.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let (buffer, i) = ((args.1 / BATCHES) as usize, args.1 % BATCHES);
|
||||
if buffer == args.0.len() {
|
||||
let size = u64::from(BATCHES * JOBS * SLOT);
|
||||
let made = host()?.uav_buffer(size)?;
|
||||
name(&made, || format!("indirect batches {size:#x}"));
|
||||
args.0.push(made);
|
||||
}
|
||||
args.1 += 1;
|
||||
// (Its first batch finds it as the recording before left it:
|
||||
// `batches_common`.)
|
||||
let state = if i == 0 { D3D12_RESOURCE_STATE_COMMON } else { D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT };
|
||||
Some((args.0[buffer].clone(), i * JOBS * SLOT, state))
|
||||
}
|
||||
|
||||
/// Before the list closes: the scratch buffers of the batched clamps go
|
||||
/// back to the common state, where the next recording expects them.
|
||||
fn batches_common(&self) {
|
||||
let mut args = self.batch_args.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let used = std::mem::take(&mut args.1).div_ceil(BATCHES) as usize;
|
||||
let barriers: Vec<D3D12_RESOURCE_BARRIER> = args.0[..used]
|
||||
.iter()
|
||||
.map(|b| transition(b, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, D3D12_RESOURCE_STATE_COMMON))
|
||||
.collect();
|
||||
if !barriers.is_empty() {
|
||||
// SAFETY: an open list and live buffers this recording left in
|
||||
// `INDIRECT_ARGUMENT`.
|
||||
unsafe { self.list.ResourceBarrier(&barriers) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves `scratch` back to the common state if a clamp left it readable
|
||||
/// as indirect arguments ([`HostList::indirect_readable`]): where the
|
||||
/// list's first clamp expects it. Done before the list closes and before
|
||||
|
||||
Reference in new issue
Block a user