Commit 2 deleted the GL rendering backend's implementations; this step removes the package references and shader vocabulary they leave behind, so nothing in the App project still spells Silk.NET.OpenGL. Silk.NET.OpenGL and Silk.NET.OpenGL.Extensions.ARB are dropped from AcDream.App.csproj. Chorizite.Core stays — the audit is NOT clean: its Render.Enums (TextureFormat, BufferUsage) and Lib.BoundingBox types are used directly and extensively across the Wb texture/mesh pipeline, independent of the deleted GL IUniformBuffer implementers the package comment used to cite. The stale comment is corrected in place. IMeshPipelineDevice.Gl is removed along with the GL? gl parameter threaded through WbMeshAdapter's four constructors, WorldRenderComposition's CreateMeshAdapter, and VulkanMeshPipelineDevice's Gl => null implementation — nothing read any of them once the legacy per-mesh upload bodies were gone (confirmed by grep: the sole non-doc-comment hit was a test assertion). While in WbMeshAdapter.Dispose(), found and fixed a real bug along the way: its teardown still pattern-matched the deleted GL GpuFrameFlightController to decide whether to wait for submitted work, which VulkanFrameFlightController replaced at slice V6a without this site being updated — so the wait had been silently dead on every Vulkan run since then. Retargeted to VulkanFrameFlightController, which carries the same WaitForSubmittedWork(). The GL pixel-format vocabulary (Silk.NET.OpenGL.PixelFormat/PixelType) that WorldTextureArray/TextureFormatExtensions/TextureAtlasManager used for upload validation is replaced by AcDream.Content's existing Silk.NET-free UploadPixelFormat/UploadPixelType enums (added at MP1a to keep the bake tool GL-free); two new members (Rgb, Red, Float) extend that enum with their GL ABI constants to cover the full vocabulary WorldTextureArray needs, since MP1a's original set only covered what the extractor itself emits. ObjectMeshManager's App-boundary cast `(Silk.NET.OpenGL.PixelFormat?)batch.UploadPixelFormat` becomes a direct pass-through now that both sides share the type. GpuBindingModel.StorageTextureTable (the GL-only binding=9 emulation of the Vulkan texture table) is deleted and StorageBindingCount drops from 10 to 9; the descriptor-set-layout code that builds from that count (VulkanPipelineLayouts, VulkanFrameBindings) is untouched and just allocates one fewer always-dummy-seeded, always-unused binding. Several fully dead GL-only classes came along for the ride, confirmed by zero construction sites: SilkFramebufferViewportTarget (NullFramebufferViewportTarget is the sole production IFramebufferViewportTarget), SilkRenderGlStateReader (NullRenderGlStateReader.Instance is the sole IRenderGlStateReader), RuntimeRenderFrameClearPhase (VulkanRenderFrameClearPhase is the sole IRenderFrameClearPhase, expressing the same atmosphere-clear logic as a pass load-op instead), and GpuFrameTimer plus FrameProfiler's GL-owning FrameBoundary(GL) overload and BeginGpuFrame/EndGpuFrame bracket (RecordGpuSample is the only GPU-timing path any backend uses now — the ACDREAM_WB_DIAG nested-query exclusion these existed for no longer applies, since WbDrawDispatcher's own diagnostic GPU sampling already moved to the device's Vulkan timer pool). GpuFrameFlightController itself stays (never constructed with a real fence API in production, but its retirement-ledger/serial-ring logic is backend-neutral and still covered by its own unit tests) — only its GL-specific parts (the public GL constructor overload, SilkGpuFenceApi) are deleted, since removing the whole class would mean restructuring the frozen Slice-8 composition shape's GpuFrameFlightController? threading, which is out of this commit's scope. TextureParameters.cs and BufferUsageExtensions.cs (zero callers each) are deleted outright. common.glsl is deleted: nothing in the actual Vulkan .spv build reads it. tools/ShaderCompiler/Program.cs compiles each .vert/.frag pair directly and tools/ShaderCompiler/VulkanGlslPreamble.cs injects its own complete self-contained preamble per file; common.glsl's textual concatenation was exclusively Shader.cs's GL-only mechanism, deleted at Commit 2. The five shader files that named it in comments (mesh_modern.vert, particle.vert, particle.frag, sky.frag, terrain_modern.frag) are corrected to point at VulkanGlslPreamble.cs instead. mesh.vert/mesh.frag — the pre-N.5 legacy shader pair the mandatory modern path already made unreachable, with zero C# consumers and no compiled .spv — are deleted too. Regenerated via tools/compile-shaders.ps1: 9/9 remaining shader pairs compile (previously 9/10, with mesh the sole failure — the VulkanShaderManifestTests doc comment's "nine of ten are not Vulkan-expressible" was already stale before this commit). Test fallout: dead-subject test methods/files are deleted rather than patched (TextRendererFailureSafetyTests.cs, ClipFrameUploadTests.cs, GpuResourceRetirementTransactionTests.cs's GL queue tests, one WorldRenderDiagnosticsTests source-order test, one RenderFrameResourceControllerTests clear-phase-order test); tests whose subject moved or was renamed are updated in place rather than deleted (GpuContractTests, VulkanCapabilityGateTests, MeshPipelineDeviceSeamTests' pinned seven-member surface now reads six, ParticleBindlessInstanceTests' cross-dialect check now covers the one surviving dialect, WbMeshAdapterTests' misleadingly-named null-gl test — gpuDevice was always the parameter that actually threw). Build: `dotnet build AcDream.slnx -c Release` — 0 warnings, 0 errors, with the Silk.NET.OpenGL/.Extensions.ARB package references physically removed from the csproj (not just unreferenced in code). Tests: full-solution `dotnet test` green across every project. Zero remaining `using Silk.NET.OpenGL` anywhere in src/ or tests/. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
262 lines
8.9 KiB
C#
262 lines
8.9 KiB
C#
using System.Numerics;
|
|
using System.Reflection;
|
|
using AcDream.App.Rendering;
|
|
using AcDream.Core.Vfx;
|
|
|
|
namespace AcDream.App.Tests.Rendering;
|
|
|
|
public sealed class WorldRenderDiagnosticsTests
|
|
{
|
|
[Fact]
|
|
public void GlTripwire_DisabledPerformsNoGlRead()
|
|
{
|
|
var gl = new RecordingGlStateReader();
|
|
var log = new RecordingLog();
|
|
var diagnostics = new WorldRenderDiagnostics(gl, log);
|
|
|
|
diagnostics.EmitGlStateTripwireIfChanged(enabled: false);
|
|
|
|
Assert.Equal(0, gl.StateCaptureCount);
|
|
Assert.Empty(log.Messages);
|
|
}
|
|
|
|
[Fact]
|
|
public void GlTripwire_LogsOnlyChangesAndReportsStableFrameCount()
|
|
{
|
|
var gl = new RecordingGlStateReader
|
|
{
|
|
State = State(depthFunction: 0x201),
|
|
};
|
|
var log = new RecordingLog();
|
|
var diagnostics = new WorldRenderDiagnostics(gl, log);
|
|
|
|
diagnostics.EmitGlStateTripwireIfChanged(enabled: true);
|
|
diagnostics.EmitGlStateTripwireIfChanged(enabled: true);
|
|
gl.State = State(depthFunction: 0x203);
|
|
diagnostics.EmitGlStateTripwireIfChanged(enabled: true);
|
|
|
|
Assert.Equal(3, gl.StateCaptureCount);
|
|
Assert.Collection(
|
|
log.Messages,
|
|
first =>
|
|
{
|
|
Assert.StartsWith("[gl-state] frame=1 stable=0", first);
|
|
Assert.Contains("dfunc=0x201", first);
|
|
},
|
|
changed =>
|
|
{
|
|
Assert.StartsWith("[gl-state] frame=3 stable=1", changed);
|
|
Assert.Contains("dfunc=0x203", changed);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void ScissorProbe_SequenceAdvancesAcrossSuppressedDuplicates()
|
|
{
|
|
var gl = new RecordingGlStateReader
|
|
{
|
|
Scissor = new RenderGlScissorSnapshot(
|
|
true,
|
|
new IntRenderRectangle(1, 2, 3, 4)),
|
|
};
|
|
var log = new RecordingLog();
|
|
var diagnostics = new WorldRenderDiagnostics(gl, log);
|
|
|
|
diagnostics.EmitClipRouteScissorProbe(true, true, new Vector4(-1, -1, 1, 1));
|
|
diagnostics.EmitClipRouteScissorProbe(true, true, new Vector4(-1, -1, 1, 1));
|
|
gl.Scissor = new RenderGlScissorSnapshot(
|
|
true,
|
|
new IntRenderRectangle(5, 6, 7, 8));
|
|
diagnostics.EmitClipRouteScissorProbe(true, true, new Vector4(-1, -1, 1, 1));
|
|
|
|
Assert.Equal(3, gl.ScissorCaptureCount);
|
|
Assert.Collection(
|
|
log.Messages,
|
|
first => Assert.StartsWith("[clip-route-scis] n=1", first),
|
|
changed => Assert.StartsWith("[clip-route-scis] n=3", changed));
|
|
}
|
|
|
|
[Fact]
|
|
public void Owner_RetainsNoBorrowedFrameProductsOrBroadRuntimeOwners()
|
|
{
|
|
FieldInfo[] fields = typeof(WorldRenderDiagnostics).GetFields(
|
|
BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
Type[] forbidden =
|
|
[
|
|
typeof(GameWindow),
|
|
typeof(PortalVisibilityFrame),
|
|
typeof(ClipFrameAssembly),
|
|
typeof(InteriorEntityPartition.Result),
|
|
typeof(AcDream.Core.Physics.PhysicsEngine),
|
|
typeof(CameraController),
|
|
typeof(CellVisibility),
|
|
];
|
|
foreach (Type type in forbidden)
|
|
Assert.DoesNotContain(fields, field => field.FieldType == type);
|
|
Assert.DoesNotContain(
|
|
fields,
|
|
field => typeof(Delegate).IsAssignableFrom(field.FieldType));
|
|
}
|
|
|
|
// Campaign V slice V11 deleted SilkRenderGlStateReader, the raw-GL
|
|
// IRenderGlStateReader implementation this test pinned (it was never
|
|
// constructed in production — NullRenderGlStateReader.Instance is the
|
|
// sole surviving implementer), so the "consume the entering GL error
|
|
// before other state reads" source-order tripwire it protected has
|
|
// nothing left to pin.
|
|
|
|
[Fact]
|
|
public void TerrainDiagnostics_RetryFailedPublicationWithoutLosingSamples()
|
|
{
|
|
var log = new ThrowOnceLog();
|
|
var diagnostics = new WorldRenderDiagnostics(new RecordingGlStateReader(), log);
|
|
var facts = new TerrainRenderDiagnosticFacts(3, 5, 8);
|
|
|
|
diagnostics.BeginTerrainDraw();
|
|
diagnostics.EndTerrainDraw();
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
diagnostics.PublishTerrainDiagnostics(facts));
|
|
|
|
diagnostics.BeginTerrainDraw();
|
|
diagnostics.EndTerrainDraw();
|
|
diagnostics.PublishTerrainDiagnostics(facts);
|
|
|
|
Assert.Single(log.Messages);
|
|
Assert.Contains("draws=3/frame", log.Messages[0]);
|
|
Assert.Contains("visible=3", log.Messages[0]);
|
|
Assert.Contains("loaded=5", log.Messages[0]);
|
|
Assert.Contains("capacity=8", log.Messages[0]);
|
|
}
|
|
|
|
[Fact]
|
|
public void RenderSignature_LogsOnlyChangesAndCarriesStableCount()
|
|
{
|
|
var log = new RecordingLog();
|
|
var diagnostics = new WorldRenderDiagnostics(new RecordingGlStateReader(), log);
|
|
|
|
EmitMinimalSignature(diagnostics, "flat");
|
|
EmitMinimalSignature(diagnostics, "flat");
|
|
EmitMinimalSignature(diagnostics, "pview");
|
|
|
|
Assert.Collection(
|
|
log.Messages,
|
|
first => Assert.StartsWith("[render-sig] frame=1 stable=0 branch=flat", first),
|
|
changed => Assert.StartsWith("[render-sig] frame=3 stable=1 branch=pview", changed));
|
|
}
|
|
|
|
[Fact]
|
|
public void OutStageParticleProbe_IsDisabledWithoutEnumerationAndSuppressesDuplicates()
|
|
{
|
|
var log = new RecordingLog();
|
|
var diagnostics = new WorldRenderDiagnostics(new RecordingGlStateReader(), log);
|
|
var particles = new ParticleSystem(new EmitterDescRegistry());
|
|
|
|
diagnostics.EmitOutStageParticles(false, particles, new HashSet<uint>());
|
|
diagnostics.EmitOutStageParticles(true, particles, new HashSet<uint>());
|
|
diagnostics.EmitOutStageParticles(true, particles, new HashSet<uint>());
|
|
|
|
Assert.Single(log.Messages);
|
|
Assert.Equal(
|
|
"[outstage-pt] ids=0 attachedEmitters=0 matched=0 unattached=0 matchedIds=[] unmatchedIds=[]",
|
|
log.Messages[0]);
|
|
}
|
|
|
|
private static RenderGlStateSnapshot State(int depthFunction) => new(
|
|
DepthTest: true,
|
|
DepthWrite: true,
|
|
DepthFunction: depthFunction,
|
|
Blend: false,
|
|
BlendSource: 1,
|
|
BlendDestination: 0,
|
|
CullFace: true,
|
|
CullMode: 0x405,
|
|
FrontFace: 0x900,
|
|
Scissor: false,
|
|
ScissorBox: new IntRenderRectangle(0, 0, 1280, 720),
|
|
Viewport: new IntRenderRectangle(0, 0, 1280, 720),
|
|
DrawFramebuffer: 0,
|
|
AlphaToCoverage: false,
|
|
Stencil: false,
|
|
ClipBits: 0,
|
|
Error: 0);
|
|
|
|
private sealed class RecordingGlStateReader : IRenderGlStateReader
|
|
{
|
|
public RenderGlStateSnapshot State { get; set; } = WorldRenderDiagnosticsTests.State(0x201);
|
|
public RenderGlScissorSnapshot Scissor { get; set; }
|
|
public int StateCaptureCount { get; private set; }
|
|
public int ScissorCaptureCount { get; private set; }
|
|
|
|
public RenderGlStateSnapshot CaptureState()
|
|
{
|
|
StateCaptureCount++;
|
|
return State;
|
|
}
|
|
|
|
public RenderGlScissorSnapshot CaptureScissor()
|
|
{
|
|
ScissorCaptureCount++;
|
|
return Scissor;
|
|
}
|
|
}
|
|
|
|
private sealed class RecordingLog : IRenderFrameDiagnosticLog
|
|
{
|
|
public List<string> Messages { get; } = [];
|
|
|
|
public void WriteLine(string message) => Messages.Add(message);
|
|
}
|
|
|
|
private sealed class ThrowOnceLog : IRenderFrameDiagnosticLog
|
|
{
|
|
private bool _throw = true;
|
|
public List<string> Messages { get; } = [];
|
|
|
|
public void WriteLine(string message)
|
|
{
|
|
if (_throw)
|
|
{
|
|
_throw = false;
|
|
throw new InvalidOperationException("diagnostic sink failed");
|
|
}
|
|
|
|
Messages.Add(message);
|
|
}
|
|
}
|
|
|
|
private static void EmitMinimalSignature(
|
|
WorldRenderDiagnostics diagnostics,
|
|
string branch) =>
|
|
diagnostics.EmitRenderSignatureIfChanged(
|
|
enabled: true,
|
|
branch: branch,
|
|
clipRoot: null,
|
|
viewerRoot: null,
|
|
playerRoot: null,
|
|
viewerCellId: 0,
|
|
playerCellId: 0,
|
|
playerIndoorGate: false,
|
|
cameraInsideCell: false,
|
|
renderSkyGate: false,
|
|
drawSkyThisFrame: false,
|
|
terrainDrawn: false,
|
|
terrainClipMode: TerrainClipMode.Skip,
|
|
skyDrawn: false,
|
|
depthClear: false,
|
|
outdoorSceneryDrawn: false,
|
|
outdoorPortalDrawn: false,
|
|
outdoorRootObjectCount: 0,
|
|
liveDynamicDrawnCount: 0,
|
|
sceneParticles: "none",
|
|
portalFrame: null,
|
|
clipAssembly: null,
|
|
drawableCells: null,
|
|
partition: null,
|
|
exteriorPortalFrame: null,
|
|
exteriorClipAssembly: null,
|
|
exteriorDrawableCells: null,
|
|
exteriorPartition: null,
|
|
cameraPosition: Vector3.Zero,
|
|
playerPosition: Vector3.Zero);
|
|
}
|