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

Without the structure builder every reflection ray the screen-space march leaves misses, and CS_RayMiss
(06bb6e728c7c99bf) writes the sky's light into the rays' texture (#38965, 853x480 R11G11B10, capture
C:\dev\captures\haze2): mean RGB (6.7, 10.9, 18.9) against (0.72, 0.44, 0.50) for the lit scene in the same
units, 100-1000x the room it should show and blue (the user's "reflections show a bright colour"; eyes glowing
blue-white, blue blotches on floors). Not a cleared or stale texture, and the cube maps are the sky's.

With the switch, right after each CS_RayMiss of opaque surfaces and of the alpha layer (not water: its first
root constant is 2), a pass of ours reflects the view direction about the normal made from the depth CS_RayMiss
itself reads (table (0,1000): #46202, a 1706x960 D32 target drawn in list 167 of the frame, before the trace)
and writes share x the light stand-in's directional estimate along it (ambient.rs, from
CS_CacheScreenSpaceRadiance), mixed with <sky> of the title's colour and never brighter than the estimate;
sky pixels (depth at the far plane) keep the title's value. CS_ResolveScreenSpace then writes its own hits
over it, so screen-space reflections stay. Expected cost under 0.15 ms a frame at 1706x960 (three dispatches).
A line every 10 s says it ran.

Written by a helper; built and tested at the merge into local/drive. A side finding to check: the diffuse
stand-in's depth slot (ambient::DEPTH, (0,464)) may name the stencil plane of #6481 after the
_ReflectiveCaustics variant 34fb51b8a0312e82.

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
1 parent a83bc910a7
commit 2db59d4813
2 files changed
+317 -14

No files matched your search

+72 -4
View File
@@ -3635,10 +3635,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;
@@ -3667,29 +3686,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
@@ -4978,6 +5031,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`).