fix(render): complete S4 chunk 2 final alpha parity round

Final allowed fix round for S4-c2 on cc8e5677a. This lands every item in
the campaign packet section 12 without adding a flush site, shader, distance,
overflow recovery draw, or graphical-client run.

R2-1 particle row 5: ParticleRenderer now constructs and owns the actual
particle-mesh-opaque pipeline using the existing particle_mesh shaders and
layout, Blend=None, depth test/write enabled with WorldCompare, dynamic
per-batch cull, clockwise front face, and no alpha-to-coverage. The production
dispatch selects it for an opaque-classified mesh particle whose clamped
material alpha is 1.0. Nonopaque mesh pipelines remain depth-write-off. The
production route keeps cached reserve/immediate delegates and the warmed
append/immediate paths allocate 0 B.

R2-2 EnvCell exact per-subset routing: ObjectMeshManager carries Content's
TextureBatchData.RetailSurfaceMask onto ObjectRenderBatch at the real upload
boundary. EnvCellRenderer scans the active prepared cell snapshot and feeds
each real transparent batch's exact mask through RetailAlphaMeshRouter. Pure
0x08 Base1ClipMap reaches CLIP, 0x02 alpha-family reaches ALPHA, and table
Immediate subsets draw at the cell turn. Separate fixed-route draw sources
coalesce to at most one token per (cell,list) and filtered replay draws only
that list's subsets; a mixed cell contributes to both lists without duplicate
replay. Detail-on routes eligible subsets immediately with the detail pass.
The warmed dispatch/source allocation pins measure 0 B; the production scan/filter is covered behaviorally and uses only retained scratch/enumerators (static allocation audit).

R2-3 capacity cleanup: RetailAlphaQueue registers a source before the 3,000
entry capacity return. A source whose first append is rejected is therefore
reset by flush, EndFrame, or abort, but its rejected payload is never prepared
or drawn.

R2-4 production proof and prose: both actual Wb submit sites are exercised;
the particle tests call the production dispatcher and inspect the constructed
owner's production pipeline/selector; EnvCell tests upload real Content batch
masks through ObjectMeshManager and drain real filtered MDI calls. The A1
positive proof executes WorldSceneRenderer's real outdoor frame owner through
RetailPViewRenderer.DrawInside and RetailAlphaQueue.EndFrame and observes
[DrawBuilding x N, RenderNormalMode] with no LandscapeFlush. The packet and
register now state the varying retail first-for-list truth and the exact
per-subset EnvCell/AP-238, visible AP-239 compositing, and AP-240 feeder scope.
Physical active register counts remain AP=159 and AD=92.

Final clean-state gates (actual output):
- Release solution build: Build succeeded; 0 Warning(s); 0 Error(s).
- Hermetic solution filter: every project green, 16,728 passed / 0 failed /
  0 skipped total; AcDream.App.Tests 6,875/6,875.
- InstalledDat: 255 passed / 10 failed / 1 skipped / 266 total, exactly the
  allowed identities: TowerAscent_StaircaseStaysConeVisible_EveryStep;
  MainGameUiAndChatInput_MediaBearingChildrenNowBuildAsRealWidgets (#383);
  EveryAuthoredInvisibleWidget_StartsHiddenAcrossAllLayouts (#383);
  Oh_doorway_still_first_frame_diff (#458); and the six
  AlphaFlushCounts_{CathedralArrival,CathedralLeak,CathedralStairArch,
  FoundryDeep,HoltburgDoorwayStill,TerraceEdge}_MatchesRetailFrame2. All six
  AlphaFlushSites_* pass in the same lane.
- VulkanShaderDescriptorContractTests + VulkanShaderManifestTests +
  RenderPackSpirvValidatorTests: 32 passed / 0 failed / 0 skipped.
- Corrected queue/router/walk/driver/particle/Wb/EnvCell/PView production
  filter: 211 passed / 0 failed / 0 skipped.
- Explicit warmed production allocation pins: 2 passed; both measure 0 B.
- Register: physical AP-238/AP-239/AP-240/AD-120/~~AP-34~~ rows each count
  exactly 1; active physical rows AP=159 and AD=92.
- git diff --check: PASS.

Production mutation checks (each applied, run to the named first failure, and
exactly reversed before the final gates):

1. Restoring the particle row-5 throw fails
   OpaqueClassifiedMeshBatch_WithNoMaterialAlpha_DrawsImmediateOnOpaqueDepthState
   first with InvalidOperationException: mutation: row 5 unreachable.

2. Deleting row 5's immediate callback fails that same production-dispatch
   test's first collection assertion: expected [(Mesh, 11, True)], actual [].

3. Constructing the actual owner pipeline with depthWrite:false fails
   ImmediateOpaqueMesh_UsesProductionParticleMeshOpaquePipelineDescription
   first at Assert.True(description.Depth.Write): expected true, actual false.

4. Mapping the production selector back to _meshAlphaPipeline fails that same
   test first at Assert.Same: expected particle-mesh-opaque, actual
   particle-mesh-alpha.

5. Dropping RetailSurfaceMask at the real ObjectMeshManager upload boundary
   fails the mixed-cell production scan first: expected Clip | Alpha, actual
   Immediate.

6. Hardcoding the uploaded EnvCell scan to MaskAlphaFamily fails the mixed-cell
   production scan first: expected Clip | Alpha, actual Alpha; the pure-mask
   pin also reports expected Clip, actual Alpha.

7. Inverting the production detail predicate fails the detail-on production
   pin first: expected Immediate, actual Clip.

8. Removing both EnvCell replay filters fails the mixed production drain's real
   MDI assertions: each call expected DrawCount 1, actual DrawCount 2.

9. Moving RegisterSource below the full-capacity return fails every
   RejectedFirstUseSource_IsCleanedWithoutPrepareOrDraw row (flush, EndFrame,
   abort) at the first ResetCount assertion: expected 1, actual 0.

10. Hardcoding detailSurfaceActive=false at the real Wb dispatch fails both
    production submit-site tests at their first queue-count assertion:
    expected 0, actual 1.

11. Restoring RetailPViewRenderer's removed outdoor LandscapeFlush call fails
    OutdoorProductionPView_DrainsBuildingThenRenderNormalModeWithoutLandscapeFlush
    first at the real drain sequence: expected [DrawBuilding,
    RenderNormalMode], actual [DrawBuilding, LandscapeFlush,
    RenderNormalMode].

12. Deleting WorldSceneRenderer's final EndFrame owner drain fails that same
    full-path A1 test first: expected [DrawBuilding, RenderNormalMode], actual
    [DrawBuilding].

Not done/deferred: none. No retail conflict or infeasible contract item was
found. No graphical client was launched.

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
Erik 2026-09-04 08:56:49 +02:00
parent 9ccb61a8ec
commit 0aa166aa09
14 changed files with 1779 additions and 224 deletions

View file

@ -1,16 +1,30 @@
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Reflection;
using AcDream.App.Composition;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Gpu;
using AcDream.App.Rendering.Gpu.Vk;
using AcDream.App.Rendering.Packs;
using AcDream.App.Rendering.Scene;
using AcDream.App.Rendering.Selection;
using AcDream.App.Rendering.Vfx;
using AcDream.App.Rendering.Walk;
using AcDream.App.Rendering.Wb;
using AcDream.App.Streaming;
using AcDream.App.Tests.Architecture;
using AcDream.App.Tests.Rendering.Gpu;
using AcDream.Content;
using AcDream.Core.Physics;
using AcDream.Core.Rendering;
using AcDream.Core.World;
using AcDream.Runtime;
using AcDream.Runtime.World;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
using DatReaderWriter.Lib.IO;
using Microsoft.Extensions.Logging.Abstractions;
namespace AcDream.App.Tests.Rendering;
@ -513,6 +527,38 @@ public sealed class WorldSceneRendererTests
}
}
/// <summary>
/// S4-c2 fix round 2 (A1): this is the positive, concrete owner-path
/// proof. It opens the real recording GPU world scope, executes
/// <see cref="RetailPViewRenderer.DrawInside(RetailPViewFrameInput,
/// RetailPViewPassExecutor)"/> for an outdoor root containing one real
/// walk building, then lets <see cref="WorldSceneRenderer"/> close the
/// SAME <see cref="RetailAlphaQueue"/> through <c>EndFrame</c>. Only
/// drains that pass retail's threshold gate are observed. The production
/// order is therefore the building's own zero-threshold barrier followed
/// by the final RenderNormalMode drain; an outdoor LandscapeFlush is
/// forbidden. Restoring the removed outdoor
/// <c>passes.FlushLandscapeAlpha()</c> call inserts LandscapeFlush between
/// those two entries. Moving/deleting <c>_alpha.EndFrame()</c> removes or
/// reorders RenderNormalMode. The IL pin in
/// <c>RetailPViewRendererOutdoorFlushTests</c> remains secondary only.
/// </summary>
[Fact]
public void OutdoorProductionPView_DrainsBuildingThenRenderNormalModeWithoutLandscapeFlush()
{
var drains = new List<RetailAlphaFlushSite>();
using var fixture = new OutdoorAlphaOwnerFixture(drains.Add);
WorldRenderFrameOutcome outcome = fixture.Renderer.Render(default);
Assert.True(outcome.NormalWorldDrawn);
Assert.Equal(1, fixture.PView.DrawCount);
Assert.Equal(
[RetailAlphaFlushSite.DrawBuilding, RetailAlphaFlushSite.RenderNormalMode],
drains);
Assert.DoesNotContain(RetailAlphaFlushSite.LandscapeFlush, drains);
}
private sealed class Rig
{
public Rig(
@ -603,6 +649,241 @@ public sealed class WorldSceneRendererTests
public WorldSceneRenderer Renderer { get; }
}
private sealed class OutdoorAlphaOwnerFixture : IDisposable
{
private readonly RecordingGpuDevice _device;
private readonly TextureCache _textures;
private readonly WbMeshAdapter _meshAdapter;
private readonly WbDrawDispatcher _dispatcher;
private readonly EnvCellRenderer _envCells;
private readonly ClipFrame _clipFrame;
private readonly RenderSceneShadowRuntime _renderScene;
private readonly IGpuPassEncoder _pass;
private readonly IDisposable _scopePublication;
public OutdoorAlphaOwnerFixture(Action<RetailAlphaFlushSite> observeDrain)
{
_device = new RecordingGpuDevice();
var frames = new GpuDeviceFrameLifetime(_device);
var scope = new FixedWorldPassScope();
var dat = new NoopDatReaderWriter();
var prepared = new NullPreparedAssetSource();
_textures = new TextureCache(_device, dat);
_meshAdapter = new WbMeshAdapter(
_device,
dat,
prepared,
NullLogger<WbMeshAdapter>.Instance,
_device.Retirement);
var spawns = new EntitySpawnAdapter(
_textures,
_ => throw new NotSupportedException("The empty owner-path fixture never spawns entities."));
var alpha = new RetailAlphaQueue(drainObserver: observeDrain);
_dispatcher = new WbDrawDispatcher(
_device,
frames,
scope,
_textures,
_meshAdapter,
spawns,
new EntityClassificationCache(),
new AcDream.Core.Rendering.TranslucencyFadeManager(),
alphaQueue: alpha);
_envCells = new EnvCellRenderer(
_device,
frames,
scope,
_meshAdapter.MeshManager!,
new WbFrustum());
_clipFrame = ClipFrame.NoClip();
var glDiagnostics = new WorldRenderDiagnostics(
new DefaultGlStateReader(),
new NullDiagnosticLog());
var terrainDiagnostics = new TerrainDrawDiagnosticsController(
enabled: false,
glDiagnostics,
new EmptyFrameFacts(),
new NullDiagnosticLog());
var pviewPasses = new RetailPViewPassExecutor(
new NullWorldPassSurface(),
NullRenderFrameGlState.Instance,
_clipFrame,
terrain: null,
_envCells,
_dispatcher,
sky: null,
particles: null,
particleRenderer: null,
portalDepthMask: null,
alpha,
glDiagnostics,
terrainDiagnostics);
const uint landblockId = 0xF4180000u;
var building = new WalkBuilding
{
PositionCellId = landblockId | 1u,
DrawingBsp = new WalkBspNode { InPortals = [] },
};
var entry = new WalkBuildingFactory.Entry(
building,
Matrix4x4.Identity,
Matrix4x4.Identity);
var buildings = new WalkBuildingRegistry();
buildings.Publish(landblockId, [entry]);
var landscape = new WalkLandscapeAssembler();
landscape.PublishLandblock(landblockId, maxZ: 10f, minZ: -1f, [entry]);
var cells = new CellVisibility();
_renderScene = new RenderSceneShadowRuntime(RenderSceneGeneration.FromRaw(1));
var retailPView = new RetailPViewRenderer(
_renderScene,
buildings,
landscape,
cells,
new ShadowObjectRegistry());
PView = new CountingPView(new WorldScenePViewRenderer(retailPView, pviewPasses));
frames.BeginFrame();
IGpuFrame frame = frames.CurrentFrame!;
_pass = frame.BeginPass(
GpuPassDescription.BackbufferClear(
"s4-c2-outdoor-owner-path",
Vector4.Zero,
sampleCount: 1));
_scopePublication = scope.Publish(_pass);
_dispatcher.BeginFrame(frameSlot: 0);
_envCells.BeginFrame(frameSlot: 0);
var calls = new List<string>();
var root = new LoadedCell
{
CellId = landblockId | 1u,
IsOutdoorNode = true,
WorldTransform = Matrix4x4.Identity,
InverseWorldTransform = Matrix4x4.Identity,
};
var day = new DayGroupData { Name = "s4-c2-owner" };
var foundation = new RenderFrameFoundation(
PortalViewportVisible: false,
Sky: default,
Atmosphere: default);
Renderer = new WorldSceneRenderer(
new FoundationSource(foundation),
new LoginSource(false),
new SkySource(day, dayFraction: 0f),
new FrameBuilder(calls, CreateFrame(root, playerSeenOutside: true)),
new EntitySource(),
selection: null,
alpha,
new ParticleVisibility(calls),
PView,
new PViewCells(),
new PassExecutor(calls),
new WorldRenderRangeState(nearRadius: 4, farRadius: 12),
new Diagnostics(calls));
}
public CountingPView PView { get; }
public WorldSceneRenderer Renderer { get; }
public void Dispose()
{
_scopePublication.Dispose();
_pass.Dispose();
_envCells.Dispose();
_dispatcher.Dispose();
_meshAdapter.Dispose();
_textures.Dispose();
_renderScene.Dispose();
_clipFrame.Dispose();
_device.Dispose();
}
}
private sealed class CountingPView(IWorldScenePViewRenderer inner) : IWorldScenePViewRenderer
{
public int DrawCount { get; private set; }
public RetailPViewFrameResult DrawInside(RetailPViewFrameInput input)
{
DrawCount++;
return inner.DrawInside(input);
}
public void AbortFrame() => inner.AbortFrame();
}
private sealed class NullWorldPassSurface : IWorldPassSurface
{
public void PrepareClipFrame() { }
public void EnableClipDistances() { }
public void DisableClipDistances() { }
public void ClearInteriorDepth() =>
throw new InvalidOperationException("An outdoor root cannot clear interior depth.");
}
private sealed class FixedWorldPassScope : IWorldPassScope
{
private IGpuPassEncoder? _encoder;
public int SampleCount => 1;
public IGpuPassEncoder? CurrentEncoder => _encoder;
public int AttachmentWidth => 1024;
public int AttachmentHeight => 720;
public WorldFrameSections Sections { get; } = new();
public IGpuPassEncoder RequireEncoder() =>
_encoder ?? throw new InvalidOperationException("No recording world pass is open.");
public void ClearInteriorDepth() =>
throw new InvalidOperationException("An outdoor root cannot clear interior depth.");
public IDisposable Publish(IGpuPassEncoder encoder)
{
Assert.Null(_encoder);
_encoder = encoder;
Sections.Reset();
return new Publication(this);
}
private sealed class Publication(FixedWorldPassScope owner) : IDisposable
{
public void Dispose()
{
owner._encoder = null;
owner.Sections.Reset();
}
}
}
private sealed class DefaultGlStateReader : IRenderGlStateReader
{
public RenderGlStateSnapshot CaptureState() => default;
public RenderGlScissorSnapshot CaptureScissor() => default;
}
private sealed class NullDiagnosticLog : IRenderFrameDiagnosticLog
{
public void WriteLine(string message) { }
}
private sealed class EmptyFrameFacts : IFramePipelineDiagnosticFactsSource
{
public TerrainRenderDiagnosticFacts CaptureTerrain() => default;
public FramePipelineDiagnosticFacts CaptureFrame() => default;
}
private sealed class FoundationSource(RenderFrameFoundation foundation) :
IRenderFrameFoundationSource
{
@ -909,6 +1190,137 @@ public sealed class WorldSceneRendererTests
}
}
private sealed class NullPreparedAssetSource : IPreparedAssetSource
{
public PreparedAssetSourceStats Stats => default;
public CacheStats DecodedTextureCacheStats => default;
public PreparedAssetPresence Probe(
AcDream.Content.Pak.PakAssetType type,
uint sourceFileId) =>
PreparedAssetPresence.Missing;
public PreparedAssetReadResult Read(
in PreparedAssetRequest request,
CancellationToken cancellationToken = default) =>
PreparedAssetReadResult.Missing;
public void Dispose() { }
}
private sealed class NoopDatReaderWriter : IDatReaderWriter
{
private readonly StubDatabase _portal = new();
private readonly StubDatabase _highRes = new();
private readonly StubDatabase _language = new();
private readonly StubDatabase _cell = new();
public string SourceDirectory => string.Empty;
public IDatDatabase Portal => _portal;
public IDatDatabase Cell => _cell;
public ReadOnlyDictionary<uint, IDatDatabase> CellRegions { get; } =
new(new Dictionary<uint, IDatDatabase>());
public IDatDatabase HighRes => _highRes;
public IDatDatabase Language => _language;
public IDatDatabase Local => _language;
public ReadOnlyDictionary<uint, uint> RegionFileMap { get; } =
new(new Dictionary<uint, uint>());
public int PortalIteration => 0;
public int CellIteration => 0;
public int HighResIteration => 0;
public int LanguageIteration => 0;
public bool TryGetFileBytes(
uint regionId,
uint fileId,
ref byte[] bytes,
out int bytesRead)
{
bytesRead = 0;
return false;
}
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj =>
Array.Empty<uint>();
public IEnumerable<IDatReaderWriter.IdResolution> ResolveId(uint id) =>
Array.Empty<IDatReaderWriter.IdResolution>();
public bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
public bool TrySave<T>(
uint regionId,
T obj,
int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
[return: MaybeNull]
public T Get<T>(uint fileId) where T : IDBObj => default;
public bool TryGet<T>(
uint fileId,
[MaybeNullWhen(false)] out T value) where T : IDBObj
{
value = default;
return false;
}
public void Dispose() { }
private sealed class StubDatabase : IDatDatabase
{
public DatDatabase Db => throw new NotSupportedException();
public int Iteration => 0;
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj =>
Array.Empty<uint>();
public bool TryGet<T>(
uint fileId,
[MaybeNullWhen(false)] out T value) where T : IDBObj
{
value = default;
return false;
}
public bool TryGetFileBytes(
uint fileId,
[MaybeNullWhen(false)] out byte[] value)
{
value = null;
return false;
}
public bool TryGetFileBytes(
uint fileId,
ref byte[] bytes,
out int bytesRead)
{
bytesRead = 0;
return false;
}
public bool TrySave<T>(T obj, int iteration = 0) where T : IDBObj =>
throw new NotSupportedException();
public void Dispose() { }
}
}
private static WorldRenderFrame CreateFrame(
LoadedCell? clipRoot,
bool playerSeenOutside)