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>
176 lines
7.4 KiB
C#
176 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
namespace AcDream.App.Tests.Rendering.Gpu.Vk;
|
|
|
|
/// <summary>
|
|
/// Campaign V slice V6c, plan §4.6: the committed SPIR-V must match the GLSL it
|
|
/// was compiled from.
|
|
///
|
|
/// <para>Plan §4.6 rules out runtime shader compilation — CI has no Vulkan SDK,
|
|
/// and a native shaderc dependency plus a startup cost would be paid for shaders
|
|
/// that never change at runtime — so the <c>.spv</c> artifacts are committed.
|
|
/// The obvious hazard follows immediately: someone edits a shader, the GL
|
|
/// backend picks it up because it compiles GLSL at startup, and the Vulkan
|
|
/// backend silently keeps rendering the old one. This test is what turns that
|
|
/// into a red build.</para>
|
|
///
|
|
/// <para>It also pins which production shaders are Vulkan-expressible TODAY. As
|
|
/// of Campaign V slice V11 (which deleted the one pair that never was —
|
|
/// <c>mesh.vert</c>/<c>mesh.frag</c>, the pre-modern-pipeline shader the N.5 ship
|
|
/// amendment's mandatory modern path made unreachable) every remaining pair
|
|
/// compiles. A future non-ready pair's failure is a specific source-level fact
|
|
/// belonging to a renderer-port slice that has not landed — not a toolchain gap.
|
|
/// Recording them here means the next slice inherits an inventory rather than a
|
|
/// rediscovery.</para>
|
|
/// </summary>
|
|
public sealed class VulkanShaderManifestTests
|
|
{
|
|
private sealed record StageEntry(string Stage, string SourceSha256, bool Compiled, string? Message);
|
|
|
|
private sealed record ShaderEntry(string Name, bool VulkanReady, IReadOnlyList<StageEntry> Stages);
|
|
|
|
private sealed record Manifest(string Note, IReadOnlyList<ShaderEntry> Shaders);
|
|
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
};
|
|
|
|
private static string RepositoryRoot()
|
|
{
|
|
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
|
|
directory = directory.Parent;
|
|
return directory?.FullName
|
|
?? throw new InvalidOperationException("Could not locate the repository root from the test binary.");
|
|
}
|
|
|
|
private static string ShadersDirectory() =>
|
|
Path.Combine(RepositoryRoot(), "src", "AcDream.App", "Rendering", "Shaders");
|
|
|
|
private static string SpirvDirectory() => Path.Combine(ShadersDirectory(), "spv");
|
|
|
|
private static Manifest ReadManifest()
|
|
{
|
|
string path = Path.Combine(SpirvDirectory(), "shaders.manifest.json");
|
|
Assert.True(File.Exists(path), $"The shader manifest is missing at {path}. Run tools/compile-shaders.ps1.");
|
|
return JsonSerializer.Deserialize<Manifest>(File.ReadAllText(path), JsonOptions)
|
|
?? throw new InvalidOperationException("The shader manifest could not be parsed.");
|
|
}
|
|
|
|
private static string Sha256OfSource(string path)
|
|
{
|
|
// Line endings are normalised before hashing so a checkout with a
|
|
// different core.autocrlf setting does not report every shader stale.
|
|
string text = File.ReadAllText(path).Replace("\r\n", "\n");
|
|
return Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(text)));
|
|
}
|
|
|
|
[Fact]
|
|
public void EveryGlslPairIsRecordedInTheManifest()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
string[] pairs = Directory
|
|
.EnumerateFiles(ShadersDirectory(), "*.vert")
|
|
.Select(Path.GetFileNameWithoutExtension)
|
|
.Where(name => name is not null && File.Exists(Path.Combine(ShadersDirectory(), $"{name}.frag")))
|
|
.Select(name => name!)
|
|
.OrderBy(name => name, StringComparer.Ordinal)
|
|
.ToArray();
|
|
|
|
Assert.Equal(pairs, manifest.Shaders.Select(shader => shader.Name).OrderBy(n => n, StringComparer.Ordinal));
|
|
}
|
|
|
|
[Fact]
|
|
public void CommittedSpirvIsNotStaleAgainstItsGlslSource()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
var stale = new List<string>();
|
|
|
|
foreach (ShaderEntry shader in manifest.Shaders)
|
|
{
|
|
foreach (StageEntry stage in shader.Stages)
|
|
{
|
|
string source = Path.Combine(ShadersDirectory(), $"{shader.Name}.{stage.Stage}");
|
|
if (!File.Exists(source))
|
|
{
|
|
stale.Add($"{shader.Name}.{stage.Stage}: the GLSL source no longer exists");
|
|
continue;
|
|
}
|
|
|
|
string actual = Sha256OfSource(source);
|
|
if (!string.Equals(actual, stage.SourceSha256, StringComparison.Ordinal))
|
|
stale.Add($"{shader.Name}.{stage.Stage}: source changed since the .spv was built");
|
|
}
|
|
}
|
|
|
|
Assert.True(
|
|
stale.Count == 0,
|
|
"Committed SPIR-V is out of date. Run tools/compile-shaders.ps1 and commit the result.\n "
|
|
+ string.Join("\n ", stale));
|
|
}
|
|
|
|
[Fact]
|
|
public void EveryShaderTheManifestCallsReadyHasBothSpirvArtifacts()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
foreach (ShaderEntry shader in manifest.Shaders.Where(entry => entry.VulkanReady))
|
|
{
|
|
foreach (string stage in (string[])["vert", "frag"])
|
|
{
|
|
string path = Path.Combine(SpirvDirectory(), $"{shader.Name}.{stage}.spv");
|
|
Assert.True(File.Exists(path), $"{shader.Name} is marked Vulkan-ready but {path} is missing.");
|
|
long length = new FileInfo(path).Length;
|
|
Assert.True(length > 0 && length % 4 == 0, $"{path} is not a whole number of SPIR-V words.");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ShadersTheManifestCallsUnreadyHaveNoStaleSpirvLeftBehind()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
foreach (ShaderEntry shader in manifest.Shaders.Where(entry => !entry.VulkanReady))
|
|
{
|
|
foreach (string stage in (string[])["vert", "frag"])
|
|
{
|
|
string path = Path.Combine(SpirvDirectory(), $"{shader.Name}.{stage}.spv");
|
|
// A leftover .spv from an earlier attempt would be loaded
|
|
// happily by the device and would be a shader nobody can account
|
|
// for.
|
|
Assert.False(File.Exists(path), $"{shader.Name} is not Vulkan-ready but {path} exists.");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void EveryUnreadyShaderRecordsWhyItCannotBeCompiledYet()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
foreach (ShaderEntry shader in manifest.Shaders.Where(entry => !entry.VulkanReady))
|
|
{
|
|
Assert.Contains(shader.Stages, stage => !stage.Compiled && !string.IsNullOrWhiteSpace(stage.Message));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TheRhiVerificationShaderIsCompiled()
|
|
{
|
|
Manifest manifest = ReadManifest();
|
|
ShaderEntry probe = Assert.Single(
|
|
manifest.Shaders,
|
|
shader => string.Equals(shader.Name, "vk_probe", StringComparison.Ordinal));
|
|
|
|
// Plan §4.11 wants the capability probe to build a real pipeline from
|
|
// committed .spv; slice V5 deferred that to V6c because no toolchain
|
|
// existed. If this pair ever stops compiling, the Vulkan backend has no
|
|
// pipeline it can build at all.
|
|
Assert.True(probe.VulkanReady, "vk_probe must compile — the whole Vulkan backend draws with it.");
|
|
}
|
|
}
|