feat(rendering): complete current-path render referee

Extend the non-drawing oracle through ordered PView routes, dispatcher visibility and final instance payloads, and accepted retail selection parts. Lifecycle artifacts can now referee the later shadow scene without influencing production visibility or draw decisions.
This commit is contained in:
Erik 2026-07-24 21:28:12 +02:00
parent dbaea19269
commit f9b68f8f2a
11 changed files with 964 additions and 41 deletions

View file

@ -4,6 +4,7 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using AcDream.App.Rendering.Residency;
using AcDream.App.Rendering.Scene;
using AcDream.Core.Lighting;
using AcDream.Core.Meshing;
using AcDream.Core.Rendering;
@ -97,6 +98,7 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
private int _scratchPeakUnits;
private readonly BindlessSupport _bindless;
private ICurrentRenderDispatcherObserver? _currentRenderSceneObserver;
public readonly record struct DrawStats(
EntitySet Set,
@ -843,8 +845,16 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
_dynamicBufferSetCursor = 0;
_dynamicFrameStarted = true;
_activeDynamicBufferSet = null;
_currentRenderSceneObserver?.BeginDispatcherFrame();
}
internal void SetCurrentRenderSceneObserver(
ICurrentRenderDispatcherObserver? observer) =>
_currentRenderSceneObserver = observer;
internal void AbortCurrentRenderSceneObserverFrame() =>
_currentRenderSceneObserver?.AbortDispatcherFrame();
/// <summary>
/// Fix B (A7 #3): hand the dispatcher this frame's GLOBAL point-light snapshot
/// (<see cref="LightManager.PointSnapshot"/>). Call once per frame BEFORE
@ -1471,6 +1481,10 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
ref walkResult,
probeState,
set);
_currentRenderSceneObserver?.ObserveDispatcherDraw(
set,
walkResult.EntitiesWalked,
_walkScratch);
// Tier 1 cache (#53) flush-tracking locals. _walkScratch holds one tuple
// per (entity, MeshRefIndex) and is in entity-order, so all MeshRefs of
@ -1947,6 +1961,10 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
if (anyVao == 0)
{
LastDrawStats = new DrawStats(set, walkResult.EntitiesWalked, _walkScratch.Count, 0, 0, 0, 0, 0, 0);
ObserveCurrentDispatcherSubmission(
visibleInstanceCount: 0,
immediateInstanceCount: 0,
deferTransparent: false);
_cpuStopwatch.Stop();
if (diag) MaybeFlushDiag();
return;
@ -1965,6 +1983,10 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
if (totalInstances == 0)
{
LastDrawStats = new DrawStats(set, walkResult.EntitiesWalked, _walkScratch.Count, 0, 0, 0, 0, 0, 0);
ObserveCurrentDispatcherSubmission(
visibleInstanceCount: 0,
immediateInstanceCount: 0,
deferTransparent);
_cpuStopwatch.Stop();
if (diag) MaybeFlushDiag();
return;
@ -2085,6 +2107,10 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
_opaqueDrawCount,
_transparentDrawCount,
totalTriangles);
ObserveCurrentDispatcherSubmission(
totalInstances,
immediateInstances,
deferTransparent);
// ── Phase 5: upload four buffers ────────────────────────────────────
ActivateNextDynamicBufferSet();
@ -2422,6 +2448,75 @@ public sealed unsafe class WbDrawDispatcher : IDisposable
g.Translucency,
g.CullMode);
private void ObserveCurrentDispatcherSubmission(
int visibleInstanceCount,
int immediateInstanceCount,
bool deferTransparent)
{
ICurrentRenderDispatcherObserver? observer =
_currentRenderSceneObserver;
if (observer is null)
return;
int opaqueGroupCount =
visibleInstanceCount == 0 ? 0 : _opaqueDraws.Count;
int transparentGroupCount =
visibleInstanceCount == 0 ? 0 : _translucentDraws.Count;
StableRenderHash128 hash = StableRenderHash128.Create();
hash.Add(visibleInstanceCount);
hash.Add(immediateInstanceCount);
hash.Add(opaqueGroupCount);
hash.Add(transparentGroupCount);
hash.Add(deferTransparent);
if (visibleInstanceCount != 0)
{
foreach (InstanceGroup group in _opaqueDraws)
AddSubmissionGroup(ref hash, group);
foreach (InstanceGroup group in _translucentDraws)
AddSubmissionGroup(ref hash, group);
}
var submission = new CurrentRenderDispatcherSubmission(
VisibleInstanceCount: visibleInstanceCount,
ImmediateInstanceCount: immediateInstanceCount,
OpaqueGroupCount: opaqueGroupCount,
TransparentGroupCount: transparentGroupCount,
TransparentDeferred: deferTransparent,
Digest: hash.Finish());
observer.ObserveDispatcherSubmission(in submission);
}
private static void AddSubmissionGroup(
ref StableRenderHash128 hash,
InstanceGroup group)
{
GroupKey key = ToKey(group);
hash.Add(key.FirstIndex);
hash.Add(key.BaseVertex);
hash.Add(key.IndexCount);
hash.Add(key.BindlessTextureHandle);
hash.Add(key.TextureLayer);
hash.Add((int)key.Translucency);
hash.Add((int)key.CullMode);
hash.Add(group.Matrices.Count);
for (int index = 0; index < group.Matrices.Count; index++)
{
hash.Add(group.Matrices[index]);
hash.Add(group.LocalSortCenters[index]);
hash.Add(group.Slots[index]);
InstanceLightSet lights = group.LightSets[index];
for (int lightIndex = 0;
lightIndex < LightManager.MaxLightsPerObject;
lightIndex++)
{
hash.Add(lights[lightIndex]);
}
hash.Add(group.IndoorFlags[index]);
hash.Add(group.Opacities[index]);
hash.Add(group.SelectionLighting[index]);
}
}
private void DeferTransparentGroups(Vector3 cameraWorldPosition, Matrix4x4 viewProjection)
{
RetailAlphaQueue queue = _alphaQueue!;