Contract amendment 2 of three, and V4g's remaining half behind it. Plan section
5.5.16 defect 2: PortalDepthMaskRenderer's two-pass punch (#117) is built on
glStencilFunc/glStencilOp/glStencilMask, GpuPipelineDescription carried no
stencil state at all, and nothing else can express it - so the renderer stayed
raw GL, invisible to the Vulkan arm, and V4g's "stencil/depth-mask pipelines"
row could not be written.
The amendment splits the way core Vulkan 1.3 splits. The ENABLE and the
attachment intent are baked: GpuPipelineDescription.StencilTest, false by
default so no pipeline in the tree changed. The per-draw compare, three outcome
ops, reference and both masks are a GpuStencilState that the pipeline carries as
a DEFAULT and IGpuPassEncoder.SetStencil overrides - exactly the split cull
mode, front face and depth write already have, and exactly what
VK_DYNAMIC_STATE_STENCIL_OP/_COMPARE_MASK/_WRITE_MASK/_REFERENCE make dynamic.
The four stencil dynamic states are declared ONLY by a pipeline that tests
stencil: declaring a dynamic state obliges every draw with the pipeline to have
set it, so adding them unconditionally would make every existing pipeline depend
on a call none of them make. GpuStencilOp carries three values because the punch
uses three - Replace marks, Equal gates, Zero self-cleans - and a fourth would
be a facility with no consumer.
The arm. Three pipelines, not one, because depth COMPARE is not dynamic in the
contract and the punch's two passes differ in it: mark tests LEQUAL and writes
no depth, punch tests ALWAYS and writes, seal is ALWAYS + write with no stencil.
All three write no colour, which is what retail's "COLOR-INVISIBLE triangle fan"
means. The fan is expanded to a triangle LIST on the CPU - the contract has no
fan topology and Vulkan's is not portable - which is exact: triangle i is
(v0, v[i+1], v[i+2]), the same triangles in the same order.
portal_depth.{vert,frag} is a new committed shader pair, and this is the ONE
renderer in the campaign whose two arms do not share a source. Its clip planes
have to travel in the TerrainClip uniform block at binding 2, which is already
precisely this shape and already read by terrain_modern.vert and sky.vert - but
on GL that binding is held globally by ClipFrame for terrain, so a portal draw
that rebound it would leave every later terrain draw in the frame reading the
wrong region. The GL arm therefore keeps its inline program.
PortalDepthShaderParityTests is the tripwire: retail's far-Z constant
(0.99999988, from DrawPortalPolyInternal 0x0059bc90), #129's capped mark-bias
expression and the eight-half-plane loop are asserted to appear in both. Both
are deleted at V11. 9/10 shader pairs now compile to SPIR-V.
Two GL-side gaps closed while the state was being extended, both of section 7.1
rule 1's class rather than new work. GlAmbientCapabilityState now saves and
restores the stencil test, function, ops and both masks - the portal punch draws
mid-frame among renderers that are still raw GL and assume the test is off - and
the COLOUR MASK, which had no consumer until a colour-invisible pipeline existed
and whose absence would have blacked out every raw-GL renderer after such a
pass.
PortalTunnelPresentation was re-read and confirmed as V6k left it: it clears
depth and draws into the active viewport, binds no framebuffer of its own, and
needs no port for section 5.4's sake. It remains unported on the Vulkan arm -
the composition uses NullLocalPlayerTeleportPresentation there - which is an
absence on the V7 list, not a defect.
Gates. Release build green. App tests 4,129/3 skips; complete Release suite
9,192/5 (one solution-wide run reported a single App failure that did not
reproduce in two subsequent runs, solution-wide or alone - the documented
rerun-singly flake class). Strict GL offline pixel gate against 08ffe141:
2.31e-05, 13 differing pixels of 563,200, inside the documented 9-31 band. GL
connected -Runs 3: 3/3 RENDERED on the desktop witness and 3/3 on the client
capture. One offline Vulkan run with VK_LAYER_KHRONOS_validation proven inserted
by the loader: zero validation errors, zero warnings, a captured world frame.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
79 lines
3.7 KiB
C#
79 lines
3.7 KiB
C#
using AcDream.App.Rendering;
|
|
using Xunit;
|
|
|
|
namespace AcDream.App.Tests.Rendering;
|
|
|
|
/// <summary>
|
|
/// Campaign V slice V6l: the portal depth mask is the one renderer whose two arms
|
|
/// do NOT share a shader source, and this is the tripwire that stops them
|
|
/// drifting.
|
|
///
|
|
/// <para>Every other RHI arm in the campaign compiles the same GLSL file the GL
|
|
/// arm does. This one cannot: its clip planes would have to travel in the
|
|
/// <c>TerrainClip</c> uniform block at binding 2, and on GL that binding is held
|
|
/// globally by <c>ClipFrame</c> for terrain — a portal draw that rebound it would
|
|
/// leave every later terrain draw in the frame reading the wrong region. So the
|
|
/// GL arm keeps its inline program, the RHI arm compiles
|
|
/// <c>Rendering/Shaders/portal_depth.vert</c>, and the numbers that decide where
|
|
/// depth lands are asserted to appear in both.</para>
|
|
///
|
|
/// <para>Deleted with the GL arm at V11, when the inline string goes.</para>
|
|
/// </summary>
|
|
public class PortalDepthShaderParityTests
|
|
{
|
|
private static string PortalDepthVertexSource() =>
|
|
File.ReadAllText(Path.Combine(
|
|
AppContext.BaseDirectory,
|
|
"Rendering",
|
|
"Shaders",
|
|
"portal_depth.vert"));
|
|
|
|
[Fact]
|
|
public void BothArmsPunchWithRetailsFarZConstant()
|
|
{
|
|
// 0.99999988 is retail's own value at the tail of
|
|
// D3DPolyRender::DrawPortalPolyInternal (0x0059bc90). It decides where
|
|
// the punched depth lands, so the two arms agreeing on it is the whole
|
|
// point of this file.
|
|
const string FarZ = "0.99999988";
|
|
Assert.Contains(FarZ, PortalDepthMaskRenderer.VertSrc, StringComparison.Ordinal);
|
|
Assert.Contains(FarZ, PortalDepthVertexSource(), StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void BothArmsApplyTheSameEyeCappedMarkBias()
|
|
{
|
|
// #129's capped bias: min(bias, cap / max(w*w, 1e-6)), then z -= bias*w.
|
|
// Spelled with different identifier names on the two arms — the RHI arm
|
|
// reads the shared push block's uParamA/uParamB — so the assertion is on
|
|
// the SHAPE that decides the result rather than on the text.
|
|
string rhi = PortalDepthVertexSource();
|
|
Assert.Contains("max(clipPos.w * clipPos.w, 1e-6)", PortalDepthMaskRenderer.VertSrc, StringComparison.Ordinal);
|
|
Assert.Contains("max(clipPos.w * clipPos.w, 1e-6)", rhi, StringComparison.Ordinal);
|
|
Assert.Contains("clipPos.z -= biasNdc * clipPos.w", PortalDepthMaskRenderer.VertSrc, StringComparison.Ordinal);
|
|
Assert.Contains("clipPos.z -= biasNdc * clipPos.w", rhi, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void BothArmsClipAgainstEightHalfPlanes()
|
|
{
|
|
// The plane budget is ClipFrame.MaxPlanes and GL's guaranteed
|
|
// GL_MAX_CLIP_DISTANCES; a shader that looped to a different number
|
|
// would clip a differently-shaped region than the one the CPU published.
|
|
Assert.Equal(8, ClipFrame.MaxPlanes);
|
|
Assert.Contains("for (int i = 0; i < 8; i++)", PortalDepthMaskRenderer.VertSrc, StringComparison.Ordinal);
|
|
Assert.Contains("for (int i = 0; i < 8; i++)", PortalDepthVertexSource(), StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public void TheRhiArmReadsTheClipPlanesFromTheSharedTerrainClipBlock()
|
|
{
|
|
string rhi = PortalDepthVertexSource();
|
|
Assert.Contains("uniform TerrainClip", rhi, StringComparison.Ordinal);
|
|
Assert.Contains("binding = 2", rhi, StringComparison.Ordinal);
|
|
// And the block is the one ClipFrame already packs for terrain and sky:
|
|
// an int count padded to 16 bytes, then eight vec4 planes.
|
|
Assert.Equal(144, ClipFrame.TerrainUboBytes);
|
|
Assert.Equal(2u, ClipFrame.TerrainClipUboBinding);
|
|
}
|
|
}
|