Merge day/light

This commit is contained in:
local committed 2026-11-25 12:55:58 -06:00
commit a02177b7d0
11 files changed
+854 -13

No files matched your search

+76 -1
View File
@@ -321,6 +321,10 @@ pub(crate) struct State {
/// report of a removed device, `crate::host::indirects`).
#[cfg(feature = "diagnostics")]
user: Vec<u32>,
/// The tables the last bind made afresh for a program the stand-in for
/// the indirect light follows (`crate::ambient`): root parameter, bytes
/// into the view heap.
ambient_tables: Vec<(u8, u32)>,
/// What the host list has: pipeline, root signature, heaps.
host_pipeline: usize,
/// Graphics, compute.
@@ -1284,7 +1288,7 @@ impl State {
addresses.push(self.view_address(compute, u.slot, u.dword));
}
}
crate::memory::ready(list, heap, &addresses, &written, &constants, use_)
crate::memory::ready(list, heap, &addresses, &written, &constants, use_, t.threads)
}
/// The bound heap holding `handle`.
@@ -1473,6 +1477,10 @@ impl State {
once!("a draw whose descriptor table found no free slots is dropped");
return false;
}
if stage.shader.ambient.is_some() {
self.ambient_tables.clear();
self.ambient_tables.extend(made.iter().copied());
}
// What the shader stores through root views and raw addresses is
// copied back into title memory afterwards.
let writes = (t.stores || !write_skip())
@@ -2647,6 +2655,73 @@ impl State {
unsafe { list.list.Dispatch(x, y, z) };
self.buffers_written();
DISPATCHED.fetch_add(1, Ordering::Relaxed);
if let Some(role) = p.stages.first().and_then(|s| s.shader.ambient)
&& crate::ambient::on()
&& self.ambient(list, p, role)
{
self.host_pipeline = 0;
self.host_roots[1] = 0;
}
}
/// The stand-in for the indirect light after a dispatch of `p`
/// (`crate::ambient`). Whether it recorded anything.
fn ambient(&self, list: &HostList, p: &HostPipeline, role: crate::ambient::Role) -> bool {
use crate::ambient::{AIR, DEPTH, LIGHT, RADIANCE, Role, Views};
let Some(t) = p.stages.first().map(|s| s.translated()) else {
return false;
};
let Some(heap) = (self.heaps[0] != 0).then(|| crate::descriptor::heap(self.heaps[0] as This).host()).flatten()
else {
return false;
};
let entry = |kind: ResourceType, (slot, offset): (u8, u32)| {
t.used.iter().find(|u| {
u.kind == kind && u.root == RootType::Table && (u.slot, u.table_offset_dwords) == (slot, offset)
})?;
let Some(Root::Table(table)) = self.roots_ref(true).get(usize::from(slot)) else {
return None;
};
let resource = match crate::descriptor::view(table + u64::from(offset) * 4)? {
View::Shader(r, _) | View::Unordered(r, ..) => r,
_ => return None,
};
let start = match self.ambient_tables.iter().find(|m| m.0 == slot) {
Some(m) => m.1,
None => self.user_value(true, slot, RootType::Table, 0),
};
let host = crate::resource::host_resource(resource as This)?;
// SAFETY: a live resource.
let desc = unsafe { host.GetDesc() };
Some((desc, heap.gpu_handle((start + offset * 4) / 32)))
};
let at = match role {
Role::Resolve => LIGHT,
Role::Radiance => RADIANCE,
Role::Air => AIR,
};
let image = entry(ResourceType::Uav, at);
let depth = match role {
Role::Resolve => entry(ResourceType::Srv, DEPTH),
Role::Radiance | Role::Air => image,
};
let (Some((of, image)), Some((seen, depth))) = (image, depth) else {
once!(?role, "no stand-in for the indirect light: other tables");
return false;
};
// (R32_UINT holding R9G9B9E5; R11G11B10_FLOAT.)
let format = if role == Role::Resolve { 42 } else { 26 };
let volume = of.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D;
if of.Format.0 != format || (seen.Width, seen.Height) != (of.Width, of.Height) || volume != (role == Role::Air) {
once!(?role, format = of.Format.0, "no stand-in for the indirect light: another image");
return false;
}
crate::ambient::after(list, role, &Views {
image,
depth,
size: [of.Width as u32, of.Height],
slices: u32::from(of.DepthOrArraySize),
})
}
/// What a draw or dispatch runs, for the device-removed report