fix(gpu): bind ambient depth only to a matching SRV

Only the resolve pass uses depth. Require the correct descriptor type and matching dimensions to prevent D3D12 error 646.
This commit is contained in:
Jeremy Goldberg committed 2026-11-26 02:00:21 -05:00
1 parent 033be27f33
commit c05b44b34a
2 files changed
+24 -12

No files matched your search

+4 -2
View File
@@ -430,7 +430,7 @@ pub(crate) struct Views {
/// The image the title's program just wrote.
pub(crate) image: D3D12_GPU_DESCRIPTOR_HANDLE,
/// The scene's depth, for [`Role::Resolve`].
pub(crate) depth: D3D12_GPU_DESCRIPTOR_HANDLE,
pub(crate) depth: Option<D3D12_GPU_DESCRIPTOR_HANDLE>,
/// The size of the image, and how many slices it has.
pub(crate) size: [u32; 2],
pub(crate) slices: u32,
@@ -484,7 +484,9 @@ pub(crate) fn after(list: &HostList, role: Role, views: &Views) -> bool {
uav_barrier(l);
l.SetComputeRootSignature(&pass.root);
l.SetComputeRoot32BitConstants(0, 12, words.as_ptr().cast(), 0);
l.SetComputeRootDescriptorTable(1, views.depth);
if let Some(depth) = views.depth {
l.SetComputeRootDescriptorTable(1, depth);
}
l.SetComputeRootDescriptorTable(2, views.image);
l.SetComputeRootUnorderedAccessView(3, pass.cells.GetGPUVirtualAddress());
l.SetComputeRootUnorderedAccessView(4, pass.points.GetGPUVirtualAddress());
+20 -10
View File
@@ -2735,8 +2735,9 @@ impl State {
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,
let resource = match (kind, crate::descriptor::view(table + u64::from(offset) * 4)?) {
(ResourceType::Srv, View::Shader(r, _))
| (ResourceType::Uav, View::Unordered(r, ..)) => r,
_ => return None,
};
let start = match self.ambient_tables.iter().find(|m| m.0 == slot) {
@@ -2753,19 +2754,28 @@ impl State {
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");
let Some((of, image)) = entry(ResourceType::Uav, at) else {
once!(?role, "no stand-in for the indirect light: missing image UAV");
return false;
};
let depth = match role {
Role::Resolve => {
let Some((seen, depth)) = entry(ResourceType::Srv, DEPTH) else {
once!(?role, "no stand-in for the indirect light: missing depth SRV");
return false;
};
if (seen.Width, seen.Height) != (of.Width, of.Height) {
once!(?role, "no stand-in for the indirect light: depth dimensions differ");
return false;
}
Some(depth)
}
Role::Radiance | Role::Air => None,
};
// (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) {
if of.Format.0 != format || volume != (role == Role::Air) {
once!(?role, format = of.Format.0, "no stand-in for the indirect light: another image");
return false;
}