fix(render): foliage wind no longer depends on the directional-shadow gate (Campaign VM VM6 review 4)
The reviewer's offline pixel apparatus found a real design defect, not a
test artefact: foliage wind was welded to "directional shadows rendered
this frame." Evidence: offline High preset, sun-shadow-strength=0,
wind-strength 2 + lean/branch 1 m — wind-on vs wind-off at the same
pinned clock differed by only 49-65 px, inside the apparatus's own 22 px
run-to-run noise floor (no measurable motion). A CPU probe independently
confirmed ResolveFoliageWind was correct (first advance snaps to Clear
0.25/0.15, gate 1, one graph) — the correct uniform never reached the
world pass.
Root cause: DirectionalSunShadowRenderer.Render's two early-out paths
(!environment.ShouldRender, ResidentWindowUnavailable) left
_currentFrameBinding at its pure Disabled (no-buffer) default.
WbDrawDispatcher.PipelinesFor and TerrainModernRenderer's matching
selection logic only choose the atmospheric receiver pipeline
(mesh_atmospheric, the only pipeline that #includes foliage_wind.glsl)
when TryGetCurrentFrameBinding returns true; with no buffer it always
returned false, so the world pass silently fell back to the plain
mesh_modern pipeline, which has no wind code at all. Because the shadow
gate is ActiveDayGroupMultiplier = dayGroupPolicy x elevationResponse x
strength, this killed wind every night (elevation response -> 0), at
user sun-shadow-strength 0, and under the portal/login cover.
Fix (decouple, not patch): DirectionalShadowFrameBinding gained
IsBindableFor ("a real current-frame allocation exists") separate from
IsValidFor ("...and it is Enabled with real shadow content" -- kept
exactly as VolumetricShaftRenderer's own gate needs it).
TryGetCurrentFrameBinding now returns IsBindableFor. When the built-in
pack supplies an AtmosphericFrame binding (declared packs never do, so
their receiver shaders -- which never declare set 3 binding 5 -- are
unaffected), Render's two early-out paths call a new
PublishDisabledReceiverBinding: it allocates one real ring slice and
writes a DISABLED DirectionalShadowUniforms block -- every matrix
Identity, every control/bias term zero, TextureAndFlags all zero (bit 0
clear is exactly what directional_shadow_receiver.glsl's
acdreamDirectionalShadowVisibility already reads as "no shadow, full
visibility" via its existing early return 1.0), and a unit light
direction (0,0,1) so a fragment shader's normalize() can never produce
NaN. BindDirectionalShadowReceiver and TerrainModernRenderer's
shadow-buffer bind now check Buffer is not null instead of Enabled, so
the disabled block actually gets bound once it is selected.
PublishDisabledReceiverBinding is internal (not private) specifically so
it is testable without standing up a real WbDrawDispatcher/
TerrainModernRenderer pair -- no test in this suite constructs either.
New tests: (a)/(b) PublishDisabledReceiverBinding is bindable-not-valid
with a bound AtmosphericFrame and a genuine no-op with an unbound one;
(c) BindDirectionalShadowReceiver emits both UniformDirectionalShadow and
UniformAtmosphericFrame binds for a disabled binding; (d)
VolumetricShaftRenderer's gate still reports NoCurrentDirectionalShadow
for a disabled binding. ShouldSelectReceiverPipeline itself is untouched
and its existing tests (parametrized directly on bindingValid) remain
valid; no existing test asserted the old "disabled shadows -> plain
pipeline / no binding" behaviour in a way this fix invalidates -- every
existing caller either bypasses Render (calls RenderPrepared directly)
or uses a stale-serial binding IsBindableFor still correctly rejects.
Verify: Release build 0 warnings/0 errors. App hermetic-lane filter
6,050/0 failed. Core.Tests 4,695/0 failed. Full hermetic-filtered
solution: 15,278/0 failed across 15 projects.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
fccba8390d
commit
eec9553582
7 changed files with 381 additions and 7 deletions
|
|
@ -538,6 +538,145 @@ public sealed class DirectionalShadowGpuTests
|
|||
Assert.Equal("shadow-frame", shadowBind.BufferName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round 4, test (a): the offline pixel gate
|
||||
/// found foliage wind welded to "directional shadows rendered this
|
||||
/// frame" — a shadow-gated-off frame used to leave
|
||||
/// TryGetCurrentFrameBinding returning false, which fell the world
|
||||
/// receiver pipeline back to the plain (no-wind) mesh pipeline. This
|
||||
/// proves the fix directly against PublishDisabledReceiverBinding
|
||||
/// (made internal for exactly this reason — see its doc comment):
|
||||
/// given a bound AtmosphericFrame, it publishes a binding that IS
|
||||
/// bindable (TryGetCurrentFrameBinding true) but is NOT a valid shadow
|
||||
/// (IsValidFor false, Enabled false), and the written block's flags
|
||||
/// word is exactly 0 (directional_shadow_receiver.glsl's bit-0-clear
|
||||
/// "full visibility" contract) with a unit light direction (0,0,1) —
|
||||
/// never the zero vector a shader's normalize() could turn into NaN.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PublishDisabledReceiverBinding_IsBindableButNotValidWithZeroFlagsAndUnitDirection()
|
||||
{
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "wind-only-frame", GpuBufferUsage.Uniform);
|
||||
var atmosphericFrame = new AtmosphericFrameBufferBinding(
|
||||
atmosphericBuffer,
|
||||
OffsetBytes: 0u,
|
||||
SizeBytes: 192u);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
default,
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame(),
|
||||
AtmosphericFrame: atmosphericFrame);
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
renderer.PublishDisabledReceiverBinding(frame, in input);
|
||||
|
||||
Assert.True(renderer.TryGetCurrentFrameBinding(frame, out DirectionalShadowFrameBinding binding));
|
||||
Assert.True(binding.IsBindableFor(frame));
|
||||
Assert.False(binding.IsValidFor(frame));
|
||||
Assert.False(binding.Enabled);
|
||||
Assert.Equal(0, binding.CascadeCount);
|
||||
Assert.False(binding.TextureSlot.IsAssigned);
|
||||
Assert.True(binding.AtmosphericFrame.IsBound);
|
||||
Assert.Same(atmosphericBuffer, binding.AtmosphericFrame.Buffer);
|
||||
|
||||
DirectionalShadowUniforms written = MemoryMarshal.Read<DirectionalShadowUniforms>(
|
||||
device.RingBytes.Slice(
|
||||
(int)binding.OffsetBytes,
|
||||
DirectionalShadowUniforms.SizeInBytes));
|
||||
Assert.Equal(0u, written.TextureAndFlags.W);
|
||||
Assert.Equal(new Vector4(0f, 0f, 1f, 0f), written.LightDirectionAndSource);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishDisabledReceiverBinding_NoOpsWhenAtmosphericFrameIsUnboundPreservingTodaysBehaviour()
|
||||
{
|
||||
// Campaign VM VM6 review fix round 4, test (b): a declared (non
|
||||
// built-in) pack never supplies an AtmosphericFrame binding, so
|
||||
// this must stay a pure no-op for it — TryGetCurrentFrameBinding
|
||||
// keeps returning false exactly like before this fix, and a
|
||||
// declared pack's receiver shader (which never declares set 3
|
||||
// binding 5) is unaffected.
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Low);
|
||||
var input = new DirectionalSunShadowRenderInput(
|
||||
default,
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.Identity,
|
||||
new DirectionalShadowCasterFrame());
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
|
||||
renderer.PublishDisabledReceiverBinding(frame, in input);
|
||||
|
||||
Assert.False(renderer.TryGetCurrentFrameBinding(frame, out _));
|
||||
Assert.Empty(device.OfKind<GpuRecordedRingAllocation>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BindDirectionalShadowReceiver_WithADisabledBindingEmitsBothShadowAndAtmosphericBinds()
|
||||
{
|
||||
// Campaign VM VM6 review fix round 4, test (c): the whole point of
|
||||
// publishing a disabled-content binding instead of leaving
|
||||
// TryGetCurrentFrameBinding at false is that BindDirectionalShadowReceiver
|
||||
// (fixed in this same round to check Buffer, not Enabled) actually
|
||||
// emits BOTH binds for it — the safe all-zero shadow block AND the
|
||||
// real wind data — so the world receiver pipeline (selected because
|
||||
// the binding is bindable) has everything it declares.
|
||||
using var device = new RecordingGpuDevice();
|
||||
using IGpuBuffer shadowBuffer = Buffer(device, "disabled-shadow-frame", GpuBufferUsage.Uniform);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "disabled-atmospheric-frame", GpuBufferUsage.Uniform);
|
||||
var binding = new DirectionalShadowFrameBinding(
|
||||
FrameSerial: 1,
|
||||
Enabled: false,
|
||||
Buffer: shadowBuffer,
|
||||
OffsetBytes: 0u,
|
||||
SizeBytes: DirectionalShadowUniforms.SizeInBytes,
|
||||
TextureSlot: GpuTextureSlot.Unassigned,
|
||||
CascadeCount: 0,
|
||||
AtmosphericFrame: new AtmosphericFrameBufferBinding(
|
||||
atmosphericBuffer,
|
||||
OffsetBytes: 0u,
|
||||
SizeBytes: 192u));
|
||||
|
||||
device.Clear();
|
||||
var target = device.CreateRenderTarget(new GpuRenderTargetDescription(
|
||||
"test-world-hdr",
|
||||
640,
|
||||
480,
|
||||
GpuTextureFormat.Rgba16FloatRenderTarget,
|
||||
GpuTextureFormat.Depth24Stencil8,
|
||||
SampleCount: 1));
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
using (IGpuPassEncoder encoder = frame.BeginPass(new GpuPassDescription
|
||||
{
|
||||
Name = "test-world-hdr",
|
||||
Color = new GpuColorAttachment(
|
||||
target,
|
||||
GpuLoadOp.Clear,
|
||||
GpuStoreOp.Store,
|
||||
Vector4.Zero),
|
||||
Depth = new GpuDepthAttachment(GpuLoadOp.Clear, GpuStoreOp.Store, 1f, 0),
|
||||
SampleCount = 1,
|
||||
}))
|
||||
{
|
||||
WbDrawDispatcher.BindDirectionalShadowReceiver(encoder, in binding);
|
||||
}
|
||||
frame.End();
|
||||
|
||||
GpuRecordedUniformBind shadowBind = Assert.Single(
|
||||
device.OfKind<GpuRecordedUniformBind>(),
|
||||
call => call.Binding == GpuBindingModel.UniformDirectionalShadow);
|
||||
Assert.Equal("disabled-shadow-frame", shadowBind.BufferName);
|
||||
GpuRecordedUniformBind atmosphericBind = Assert.Single(
|
||||
device.OfKind<GpuRecordedUniformBind>(),
|
||||
call => call.Binding == GpuBindingModel.UniformAtmosphericFrame);
|
||||
Assert.Equal("disabled-atmospheric-frame", atmosphericBind.BufferName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StableTopology_ReusesRetainedCommandBuffersWithoutFrameRingCopies()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -134,6 +134,52 @@ public sealed class VolumetricShaftRendererTests
|
|||
Assert.Empty(device.CreatedRenderTargets);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DisabledShadowContentBindingStillGatesToNoCurrentDirectionalShadow()
|
||||
{
|
||||
// Campaign VM VM6 review fix round 4, test (d): PublishDisabledReceiverBinding
|
||||
// (DirectionalSunShadowRenderer) now publishes a REAL, bindable
|
||||
// ring allocation even when shadows are gated off, specifically so
|
||||
// the world receiver pipeline keeps reading wind data. This proves
|
||||
// the volumetric pass is unaffected by that change: its own gate
|
||||
// reads IsValidFor, which a disabled-content binding (Enabled
|
||||
// false, TextureSlot Unassigned, CascadeCount 0) still fails, so it
|
||||
// reports NoCurrentDirectionalShadow exactly as it would for no
|
||||
// binding at all — never mistaking "bindable" for "has real shadow
|
||||
// content."
|
||||
var device = new RecordingGpuDevice();
|
||||
using var renderer = Renderer(device, "high");
|
||||
GpuTextureSlot depth = TextureSlot(device, "scene-depth");
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
GpuRingAllocation allocation = frame.AllocateRing(
|
||||
DirectionalShadowUniforms.SizeInBytes,
|
||||
GpuRingUsage.Uniform);
|
||||
allocation.Data.Clear();
|
||||
var disabledContent = new DirectionalShadowFrameBinding(
|
||||
frame.Serial,
|
||||
Enabled: false,
|
||||
allocation.Buffer,
|
||||
allocation.OffsetBytes,
|
||||
DirectionalShadowUniforms.SizeInBytes,
|
||||
GpuTextureSlot.Unassigned,
|
||||
CascadeCount: 0);
|
||||
AtmosphericFrameInputs inputs = Inputs(1280, 720);
|
||||
|
||||
VolumetricShaftOutput output = renderer.Render(
|
||||
frame,
|
||||
in inputs,
|
||||
in disabledContent,
|
||||
depth);
|
||||
frame.End();
|
||||
|
||||
Assert.True(disabledContent.IsBindableFor(frame));
|
||||
Assert.False(disabledContent.IsValidFor(frame));
|
||||
Assert.Equal(
|
||||
VolumetricShaftGateReason.NoCurrentDirectionalShadow,
|
||||
output.Diagnostics.GateReason);
|
||||
Assert.False(output.HasTexture);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResizeAtomicallyReplacesTargetAndResetsMixedResolutionPerformanceWindow()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue