Merge agent/reflect: A stand-in for reflections without rays (VICTORY_AMBIENT_SPECULAR=<share>[,<sky>], off by default)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-27 01:26:46 +05:30
commit ff18de231c
2 files changed
+317 -14

No files matched your search

+72 -4
View File
@@ -3767,10 +3767,29 @@ impl State {
/// 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};
use crate::ambient::{AIR, DEPTH, LIGHT, MISS_DEPTH, MISS_LIGHT, MissNote, RADIANCE, Role, Views};
let Some(t) = p.stages.first().map(|s| s.translated()) else {
return false;
};
// Which surfaces the miss program's rays are of (its first root
// constant): water's reflections are left as they are (the depth
// here is of what lies under it).
let layer = match role {
Role::Miss => t
.used
.iter()
.find(|u| u.root == RootType::Constants)
.and_then(|u| match self.roots_ref(true).get(usize::from(u.slot)) {
Some(Root::Constants(c)) => c.first().copied(),
_ => None,
})
.unwrap_or(u32::MAX),
_ => 0,
};
if role == Role::Miss && !matches!(layer, crate::ambient::MISS_OPAQUE | crate::ambient::MISS_ALPHA) {
crate::ambient::note_miss(MissNote::Water);
return false;
}
let Some(heap) = (self.heaps[0] != 0).then(|| crate::descriptor::heap(self.heaps[0] as This).host()).flatten()
else {
return false;
@@ -3799,29 +3818,63 @@ impl State {
Role::Resolve => LIGHT,
Role::Radiance => RADIANCE,
Role::Air => AIR,
Role::Miss => MISS_LIGHT,
};
let image = entry(ResourceType::Uav, at);
let depth = match role {
Role::Resolve => entry(ResourceType::Srv, DEPTH),
Role::Miss => entry(ResourceType::Srv, MISS_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");
if role == Role::Miss {
crate::ambient::note_miss(MissNote::NotReady);
}
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) {
// The miss program's image is of half the picture's size, its depth
// (32-bit) of the whole.
let sizes = match role {
Role::Miss => {
use windows::Win32::Graphics::Dxgi::Common::{
DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_D32_FLOAT_S8X24_UINT, DXGI_FORMAT_R32_FLOAT,
DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32G8X24_TYPELESS,
};
matches!(
seen.Format,
DXGI_FORMAT_R32_TYPELESS
| DXGI_FORMAT_R32_FLOAT
| DXGI_FORMAT_D32_FLOAT
| DXGI_FORMAT_R32G8X24_TYPELESS
| DXGI_FORMAT_D32_FLOAT_S8X24_UINT
) && seen.Width >= of.Width
&& seen.Height >= of.Height
&& seen.Width <= of.Width * 4
}
_ => (seen.Width, seen.Height) == (of.Width, of.Height),
};
if of.Format.0 != format || !sizes || volume != (role == Role::Air) {
once!(?role, format = of.Format.0, "no stand-in for the indirect light: another image");
if role == Role::Miss {
crate::ambient::note_miss(MissNote::NotReady);
}
return false;
}
crate::ambient::after(list, role, &Views {
let ran = crate::ambient::after(list, role, &Views {
image,
depth,
size: [of.Width as u32, of.Height],
slices: u32::from(of.DepthOrArraySize),
})
depth_size: [seen.Width as u32, seen.Height],
});
if ran && role == Role::Miss {
crate::ambient::note_miss(MissNote::Ran(layer));
}
ran
}
/// What a draw or dispatch runs, for the device-removed report
@@ -5145,6 +5198,21 @@ impl State {
} else {
self.drew(Some(p));
}
// The stand-in for reflections after the program that gives rays
// that found nothing the sky (`crate::ambient`, `Role::Miss`): the
// execution held back is recorded first. (Not after one joined to
// the run before: the tables noted are another program's.)
if kind == DISPATCH
&& !joined
&& let Some(role @ crate::ambient::Role::Miss) = p.stages.first().and_then(|s| s.shader.ambient)
&& crate::ambient::on()
{
unsettle_indirect(list);
if self.ambient(list, p, role) {
self.host_pipeline = 0;
self.host_roots[1] = 0;
}
}
// The scratch buffer stays readable as arguments: the next draw of
// the window reads it with no barrier, and the next clamp moves it
// back (`crate::indirect`).