Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions crates/victory-gpu/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ impl State {
arguments: u64,
count: Option<u64>,
) -> bool {
// Skip before the argument clamp can mutate the indirect buffer.
// Skip before recording unnecessary clamp work.
#[cfg(feature = "diagnostics")]
if crate::pipeline::is_skipped(self.pipeline as This) {
crate::pipeline::note_drop(self.pipeline as This);
Expand Down Expand Up @@ -996,10 +996,16 @@ impl State {
s.refresh(list, *at, 4);
}
// Bounded first: the clamp binds a compute pipeline of its own.
if !crate::indirect::bound(list, &args.buffer, args.gpu(arguments), (kind, stride, max)) {
why("not bounded (no clamp, or arguments not 4-byte aligned)");
let count_source = counter.as_ref().map(|(s, at)| (&s.buffer, s.offset(*at)));
let Some(clamped) = crate::indirect::bound(
list,
(&args.buffer, args.offset(arguments)),
count_source,
(kind, stride, max),
) else {
why("argument clamp unavailable");
return false;
}
};
self.host_pipeline = 0;
self.host_roots[1] = 0;
let ran = match kind {
Expand All @@ -1015,7 +1021,7 @@ impl State {
_ => false,
};
if !ran {
crate::indirect::done(list, &args.buffer);
crate::indirect::done(list, &clamped);
#[cfg(feature = "diagnostics")]
match crate::pipeline::host_pipeline(self.pipeline as This) {
None => crate::pipeline::note_drop(self.pipeline as This),
Expand All @@ -1027,19 +1033,19 @@ impl State {
list.note_op(|| {
self.op_text(format!("indirect kind {kind} max {max} at {arguments:#x}"), kind == DISPATCH)
});
// SAFETY: an open list with everything set; the buffers are host
// copies the list keeps alive (refresh), the signature is cached.
// SAFETY: an open list with everything set; the list holds both
// buffers, and the signature is cached.
unsafe {
list.list.ExecuteIndirect(
&signature,
max,
&args.buffer,
args.offset(arguments),
counter.as_ref().map(|(s, _)| &s.buffer),
counter.as_ref().map_or(0, |(s, at)| s.offset(*at)),
&clamped,
if count_source.is_some() { crate::indirect::COUNT_BYTES } else { 0 },
count_source.map(|_| &clamped),
0,
)
};
crate::indirect::done(list, &args.buffer);
crate::indirect::done(list, &clamped);
if kind == DISPATCH {
DISPATCHED.fetch_add(1, Ordering::Relaxed);
} else {
Expand Down
30 changes: 27 additions & 3 deletions crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub(crate) struct HostList {
/// The work its indirect executions may still do (`indirect`): a
/// shader-writable word, zeroed when the list is submitted.
budget: OnceLock<Option<(ID3D12Resource, usize)>>,
arguments: Mutex<Option<ID3D12Resource>>,
/// The texts of the markers `note_op` set, in order (for device-removed
/// data without marker texts), with the host GPU range a copy reads.
#[cfg(feature = "diagnostics")]
Expand Down Expand Up @@ -498,6 +499,8 @@ struct Deferred {
refreshed: std::collections::HashSet<(usize, usize, usize)>,
/// Textures whose contents the list brings up to date.
textures: std::collections::HashSet<usize>,
/// Host buffers that earlier shaders in this list used as UAVs.
gpu_written: std::collections::HashSet<usize>,
/// Bottom-of-pipe writes, done once the list has run: address, what,
/// bytes.
writes: Vec<(usize, crate::queue::Written, usize)>,
Expand Down Expand Up @@ -573,6 +576,7 @@ impl Host {
prelude: (prelude_allocator, prelude),
pipelines: Mutex::default(),
budget: OnceLock::new(),
arguments: Mutex::new(None),
#[cfg(feature = "diagnostics")]
notes: Mutex::default(),
#[cfg(feature = "diagnostics")]
Expand Down Expand Up @@ -1199,9 +1203,13 @@ impl HostList {
address: usize,
len: usize,
) {
self.deferred()
.copies
.push(Step::GpuWrite(shadow.clone(), address, len));
let mut deferred = self.deferred();
deferred.gpu_written.insert(shadow.buffer.as_raw() as usize);
deferred.copies.push(Step::GpuWrite(shadow.clone(), address, len));
}

pub(crate) fn gpu_written(&self, buffer: &ID3D12Resource) -> bool {
self.deferred().gpu_written.contains(&(buffer.as_raw() as usize))
}

/// Stores `what` (`bytes` of it) at `dst` once the list has run.
Expand Down Expand Up @@ -1274,6 +1282,22 @@ impl HostList {
Some(unsafe { buffer.GetGPUVirtualAddress() })
}

/// The list's private argument buffer, in COMMON between uses.
pub(crate) fn arguments(&self, bytes: u64) -> Option<ID3D12Resource> {
let mut arguments = self.arguments.lock().unwrap_or_else(|e| e.into_inner());
// SAFETY: a descriptor query on a live resource.
if let Some(buffer) = arguments.as_ref().filter(|buffer| unsafe { buffer.GetDesc() }.Width >= bytes) {
return Some(buffer.clone());
}
let (buffer, _) = host()?.shared_buffer(bytes.checked_next_power_of_two()?.max(1 << 16))?;
name(&buffer, || "indirect arguments".into());
// Earlier commands can still reference the smaller allocation.
if let Some(old) = arguments.replace(buffer.clone()) {
self.keep(&old);
}
Some(buffer)
}

/// Keeps `object` alive until the list is reset.
pub(crate) fn keep(&self, object: &impl Interface) {
if let Ok(object) = object.cast::<windows::core::IUnknown>() {
Expand Down
Loading