Skip to content
Merged
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
27 changes: 21 additions & 6 deletions crates/victory-gpu/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ impl State {
if list.take_rebind() {
(self.host_pipeline, self.host_roots[1]) = (0, 0);
}
// Compute work may write the arguments of indirect draws after it:
// they get a clamp of their own (`crate::indirect`).
if compute {
crate::indirect::end(list);
}
// Heaps first: a root signature with directly indexed heaps must be
// set after them. Title memory's views need a view heap: ours where
// the title binds none (the BVH builder's dispatches may not).
Expand Down Expand Up @@ -588,6 +593,9 @@ impl State {
{
list.defer_heap(&host.viewed);
}
if writes {
crate::indirect::wrote_anywhere(list);
}
crate::bindless::note_draw(writes);
}
for stage in &p.stages {
Expand Down Expand Up @@ -769,6 +777,7 @@ impl State {
l.SetGraphicsRootShaderResourceView(param, table);
}
if let Some(param) = stage.memory_dirty {
crate::indirect::wrote_anywhere(list);
if compute {
l.SetComputeRootUnorderedAccessView(param, dirty);
} else {
Expand Down Expand Up @@ -1651,13 +1660,19 @@ impl State {
if let Some((s, at)) = &counter {
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)) {
// Bounded first: a clamp binds a compute pipeline of its own (draws
// that join a batch record none, and keep what is bound).
let offset = args.offset(arguments);
let at = (args.gpu(arguments) - offset, offset, arguments);
let Some(bound) = crate::indirect::bounded(list, &args.buffer, at, (kind, stride, max), kind == DISPATCH)
else {
why("not bounded (no clamp, or arguments not 4-byte aligned)");
return false;
};
if bound.replaced_compute() {
self.host_pipeline = 0;
self.host_roots[1] = 0;
}
self.host_pipeline = 0;
self.host_roots[1] = 0;
let ran = match kind {
DRAW | INDEXED => {
(self.topology != RECTANGLES || self.completes_rectangles() || {
Expand All @@ -1673,7 +1688,7 @@ impl State {
_ => false,
};
if !ran {
crate::indirect::done(list, &args.buffer);
bound.done(list, &args.buffer);
#[cfg(feature = "diagnostics")]
match crate::pipeline::host_pipeline(self.pipeline as This) {
None => {
Expand Down Expand Up @@ -1712,7 +1727,7 @@ impl State {
let name = crate::pipeline::shaders_of(pipeline);
crate::capture::read_indirect(list, (&args.buffer, args.offset(arguments)), count, (kind, stride, max), name);
}
crate::indirect::done(list, &args.buffer);
bound.done(list, &args.buffer);
if kind == DISPATCH {
DISPATCHED.fetch_add(1, Ordering::Relaxed);
} else {
Expand Down
29 changes: 28 additions & 1 deletion crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ 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)>>,
/// The indirect draws one clamp of their arguments bounds (`indirect`).
indirect: Mutex<crate::indirect::Batches>,
/// 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 @@ -834,6 +836,7 @@ impl Host {
pipelines: Mutex::default(),
id,
budget: OnceLock::new(),
indirect: Mutex::default(),
#[cfg(feature = "diagnostics")]
notes: Mutex::default(),
#[cfg(feature = "diagnostics")]
Expand Down Expand Up @@ -1420,6 +1423,7 @@ impl HostList {
}

pub(crate) fn close(&self) {
crate::indirect::end(self);
for (from, to, bytes) in &self.deferred().read_backs {
// SAFETY: an open list; buffers of ours it holds.
unsafe {
Expand Down Expand Up @@ -1452,6 +1456,7 @@ impl HostList {
/// for).
pub(crate) fn reset(&self) {
*self.deferred() = Deferred::default();
*self.indirect() = crate::indirect::Batches::default();
self.states.lock().unwrap_or_else(|e| e.into_inner()).clear();
self.twins.lock().unwrap_or_else(|e| e.into_inner()).clear();
self.pipelines.lock().unwrap_or_else(|e| e.into_inner()).clear();
Expand Down Expand Up @@ -1734,6 +1739,12 @@ impl HostList {
self.deferred()
.copies
.push(Step::GpuWrite(shadow.clone(), address, len, marked));
crate::indirect::wrote(self, address as u64, len as u64);
}

/// The list's batch of indirect draws (`crate::indirect`).
pub(crate) fn indirect(&self) -> std::sync::MutexGuard<'_, crate::indirect::Batches> {
self.indirect.lock().unwrap_or_else(|e| e.into_inner())
}

/// Shaders of the list take views from the heap itself
Expand Down Expand Up @@ -2830,6 +2841,8 @@ struct Meter {
copy_stats_frames: u64,
drawn: u64,
logged: std::time::Instant,
/// Frames since the argument clamps' reasons were last logged.
clamp_frames: f64,
/// The caption the window had, once read.
caption: Option<Vec<u16>>,
}
Expand All @@ -2844,6 +2857,7 @@ impl Meter {
copy_stats_frames: 0,
drawn: crate::draw::drawn(),
logged: now,
clamp_frames: 0.0,
caption: None,
}
}
Expand Down Expand Up @@ -2885,6 +2899,9 @@ impl Meter {
});
let dropped = crate::draw::take_dropped() as f64 / frames;
let indirect = crate::list::take_indirect() as f64 / frames;
let (clamps, bounded) = crate::indirect::take_counts();
self.clamp_frames += frames;
let (clamps, bounded) = (clamps as f64 / frames, bounded as f64 / frames);
let root_views = crate::draw::take_root_view_slots() as f64 / frames;
// Over the same frames as the counts above.
#[cfg(feature = "diagnostics")]
Expand All @@ -2896,9 +2913,19 @@ impl Meter {
{copy_mb:.1} MB, textures {texture_ms:.1} ms {texture_mb:.1} MB; {gpu:.1} on the \
GPU; {back_ms:.1} copying back {back_mb:.1} MB), {draws:.0} draws/frame, \
dropped {dropped:.0} without a host pipeline ({making} being made) and \
{indirect:.0} indirect; {root_views:.0} root-view slots/frame",
{indirect:.0} indirect; {root_views:.0} root-view slots/frame; {clamps:.0} \
argument clamps for {bounded:.0} indirect executions/frame",
making = crate::pipeline::making()
);
let [none, buffer, anywhere, range, full, synced] =
crate::indirect::take_reasons().map(|n| n as f64 / self.clamp_frames.max(1.0));
self.clamp_frames = 0.0;
tracing::info!(
"argument clamps opened per frame: {none:.0} with none open (a list's first indirect \
draw, or the first after compute work), {buffer:.0} for another argument buffer, \
{anywhere:.0} after shader writes anywhere, {range:.0} over a written range, {full:.0} \
with the job memory full; {synced:.0} barriers alone after declared writes"
);
let (textures, bytes, used, shared, saved, replaced) = crate::resource::texture_counts();
tracing::info!(
"host textures: {textures} ({:.0} MB, {:.0} MB of them used by lists), title textures sharing one {shared} (saving {:.0} MB), replacing one {replaced}; \
Expand Down
Loading