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
21 changes: 17 additions & 4 deletions runtime/d3d12/src/commands/compute_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ impl Bindings {
list.SetComputeRootShaderResourceView(slot, va);
}
if let Some(bvh) = &root.bvh {
match self.console_scenes(guest, root, arena) {
match self.console_scenes(guest, root, arena, resources) {
Some((nodes, offsets)) => {
list.SetComputeRootShaderResourceView(root.bvh_slot(), nodes);
if let Some(offsets) = offsets {
Expand Down Expand Up @@ -658,8 +658,21 @@ impl Bindings {
guest: &super::List,
root: &SceneRoot,
arena: Option<&Arc<crate::device::descriptor_paging::Arena>>,
resources: &crate::device::MediaResources,
) -> Option<(u64, Option<u64>)> {
use crate::device::console_heap::{self, EMPTY_SCENE, SCENES};
// The list holds the buffer it binds by address: a larger buffer may
// replace it before the list has run, and the smaller one is given
// back after a while. Without room to hold it the walk keeps its
// empty buffer.
let hold = |buffer: &ID3D12Resource| {
let mut held = resources.lock().unwrap_or_else(|e| e.into_inner());
let room = held.try_reserve(1).is_ok();
if room {
held.push(ID3D12Pageable::from(buffer.clone()));
}
room
};
let declares_offsets = root.bvh.as_ref()?.offsets();
if !console_heap::enabled() {
return None;
Expand All @@ -679,15 +692,15 @@ impl Bindings {
if !declares_offsets {
// The walk reaches its nodes from what another pass left it: an
// address in the buffer the scenes are in.
let nodes = heap.buffer();
let nodes = heap.buffer_held().filter(|(buffer, _)| hold(buffer));
crate::diagnostics::log_once(&root.program.first_console, || {
format!(
"console walk {}: it declares no scene offsets and is given {}",
root.program.source_hash,
if nodes.is_some() { "the buffer alone" } else { "nothing yet: it keeps its empty buffer" }
)
});
return nodes.map(|nodes| (nodes, None));
return nodes.map(|(_, nodes)| (nodes, None));
}
let mut offsets = [EMPTY_SCENE; SCENES];
let mut found = Vec::with_capacity(root.console.len());
Expand All @@ -700,7 +713,7 @@ impl Bindings {
}
found.push((*source, address, at));
}
let bound = heap.bind(device, offsets);
let bound = heap.bind(device, offsets).filter(|(buffer, ..)| hold(buffer));
crate::diagnostics::log_once(&root.program.first_console, || {
let mut text = format!("console walk {}: {} scenes", root.program.source_hash, found.len());
for (index, (source, address, at)) in found.iter().enumerate() {
Expand Down
7 changes: 3 additions & 4 deletions runtime/d3d12/src/commands/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,9 @@ impl Recording {
}
let result = self.inline_scenes(list).map(|(vas, geometry)| {
let Some(root) = self.bindings.scene_root() else { return };
let console = root
.bvh
.as_ref()
.and_then(|_| self.bindings.console_scenes(list, root, self.descriptor_arena.as_ref()));
let console = root.bvh.as_ref().and_then(|_| {
self.bindings.console_scenes(list, root, self.descriptor_arena.as_ref(), &self.resources)
});
// SAFETY: the active list is open, as `dispatch_scene` requires.
unsafe { self.bindings.dispatch_scene(&self.active.native, root, &vas, geometry, console, dispatch) };
crate::diagnostics::log_once(&root.program.first_dispatch, || {
Expand Down
9 changes: 5 additions & 4 deletions runtime/d3d12/src/device/console_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,11 @@ impl ConsoleHeap {
Some((space.buffer.clone(), space.address, space.address + block))
}

/// The buffer's GPU address, for a walk that reads no scene offsets. None
/// while nothing was placed, when the buffer the walk already has serves.
pub(crate) fn buffer(&self) -> Option<u64> {
self.lock().space.as_ref().map(|space| space.address)
/// The buffer and its address, taken together: a list that binds the
/// address holds the buffer, since a larger one may replace it before
/// that list has run.
pub(crate) fn buffer_held(&self) -> Option<(ID3D12Resource, u64)> {
self.lock().space.as_ref().map(|space| (space.buffer.clone(), space.address))
}

/// Structures named, scene addresses named, and bytes in places that are
Expand Down
Loading