perf(streaming): cursor publication across frame budgets

This commit is contained in:
Erik 2026-07-24 19:10:18 +02:00
parent bb16f74fd4
commit 98f1ac8934
32 changed files with 2215 additions and 823 deletions

View file

@ -1,5 +1,6 @@
using System.Numerics;
using System.Reflection;
using System.Collections.Immutable;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Wb;
using AcDream.App.Streaming;
@ -194,6 +195,47 @@ public sealed class LandblockRenderPublisherTests
Assert.Equal(1, first.Diagnostics.CompleteCount);
}
[Fact]
public void RetainedEnvCellPublisher_AdvancesOneShellBeforeAtomicCommit()
{
var envPublisher = new RecordingEnvCellPublisher();
EnvCellLandblockBuild envCells = new(
LandblockId,
Array.Empty<LoadedCell>(),
[
Shell(0xA9B40100u, 1),
Shell(0xA9B40101u, 2),
Shell(0xA9B40102u, 3),
]);
var publisher = new LandblockRenderPublisher(
publishTerrain: static (_, _, _) => { },
removeTerrain: static _ => { },
cellVisibility: new CellVisibility(),
worldState: new GpuWorldState(),
envCellPublisher: envPublisher);
LandblockRenderPublication receipt = publisher.PreparePublication(
Build(envCells),
EmptyMesh());
publisher.BeginPublication(receipt);
Assert.False(publisher.AdvanceCompleteOne(receipt));
Assert.Equal(0, envPublisher.AdvancedShells);
Assert.Equal(0, envPublisher.CommitCount);
for (int shell = 1; shell <= 3; shell++)
{
Assert.False(publisher.AdvanceCompleteOne(receipt));
Assert.Equal(shell, envPublisher.AdvancedShells);
Assert.Equal(0, envPublisher.CommitCount);
}
Assert.False(publisher.AdvanceCompleteOne(receipt));
Assert.Equal(0, envPublisher.CommitCount);
Assert.False(publisher.AdvanceCompleteOne(receipt));
Assert.Equal(1, envPublisher.CommitCount);
Assert.True(publisher.AdvanceCompleteOne(receipt));
Assert.Equal(1, publisher.Diagnostics.CompleteCount);
}
[Fact]
public void PrepareAndRetirementOperationsStayBalancedAtTheirOwnerBoundary()
{
@ -341,6 +383,19 @@ public sealed class LandblockRenderPublisherTests
InverseWorldTransform = Matrix4x4.Identity,
};
private static EnvCellShellPlacement Shell(uint cellId, ulong geometryId) =>
new(
cellId,
geometryId,
EnvironmentId: 1u,
CellStructure: 0,
Surfaces: ImmutableArray<ushort>.Empty,
WorldPosition: Vector3.Zero,
Rotation: Quaternion.Identity,
Transform: Matrix4x4.Identity,
LocalBounds: new WbBoundingBox(Vector3.Zero, Vector3.One),
WorldBounds: new WbBoundingBox(Vector3.Zero, Vector3.One));
private static LandblockMeshData MeshAtHeights(float first, float second) => new(
[
new TerrainVertex(new Vector3(0f, 0f, first), Vector3.UnitZ, 0, 0, 0, 0),
@ -362,4 +417,42 @@ public sealed class LandblockRenderPublisherTests
}
throw new DirectoryNotFoundException("Could not locate repository root.");
}
private sealed class RecordingEnvCellPublisher :
IEnvCellLandblockPublisher
{
private readonly object _owner = new();
public int AdvancedShells { get; private set; }
public int CommitCount { get; private set; }
public EnvCellLandblockPublication PreparePublication(
EnvCellLandblockBuild build) =>
new(_owner, build);
public bool AdvancePreparationOne(
EnvCellLandblockPublication publication)
{
Assert.Same(_owner, publication.Owner);
if (publication.PreparationCommitted)
return true;
if (publication.ShellCursor < publication.Build.Shells.Length)
{
publication.ShellCursor++;
AdvancedShells++;
return false;
}
publication.PreparationCommitted = true;
return true;
}
public void CommitPublication(
EnvCellLandblockPublication publication)
{
Assert.True(publication.PreparationCommitted);
publication.PublicationCommitted = true;
CommitCount++;
}
}
}