test: replace render source freezes

This commit is contained in:
Erik 2026-08-18 14:58:25 +02:00
parent c31a9ac411
commit 5a33369074
7 changed files with 425 additions and 345 deletions

View file

@ -1,4 +1,6 @@
using AcDream.App.Rendering;
using AcDream.App.Rendering.Gpu;
using AcDream.App.Tests.Rendering.Gpu;
namespace AcDream.App.Tests.Rendering;
@ -88,48 +90,34 @@ public sealed class ResourceCleanupGroupTests
/// re-growing a second resource without re-growing the rollback fails here.
/// </summary>
[Fact]
public void TextRendererConstructorOwnsExactlyOneDeviceResource()
public void TextRendererConstructionCreatesAndDisposesOnlyOnePipeline()
{
string source = File.ReadAllText(Path.Combine(
FindRepoRoot(),
"src",
"AcDream.App",
"Rendering",
"TextRenderer.cs"));
using var device = new RecordingGpuDevice();
int buffersBefore = device.CreatedBuffers.Count;
int pipelinesBefore = device.CreatedPipelines.Count;
int samplersBefore = device.CreatedSamplers.Count;
int texturesBefore = device.CreatedTextures.Count;
int slotsBefore = device.LiveTextureSlotCount;
Assert.Equal(1, CountOccurrences(source, "device.CreatePipeline("));
Assert.Equal(0, CountOccurrences(source, "device.CreateTexture("));
Assert.Equal(0, CountOccurrences(source, "device.CreateBuffer("));
Assert.Equal(0, CountOccurrences(source, "device.CreateSampler("));
Assert.Equal(0, CountOccurrences(source, "device.RegisterTexture("));
var renderer = new TextRenderer(
device,
new NullGpuFrameSource(),
shaderDir: "unused");
// And the one resource is released.
Assert.Contains("public void Dispose() => _pipeline.Dispose();", source, StringComparison.Ordinal);
RecordingGpuPipeline pipeline = Assert.Single(
device.CreatedPipelines.Skip(pipelinesBefore));
Assert.Equal(buffersBefore, device.CreatedBuffers.Count);
Assert.Equal(samplersBefore, device.CreatedSamplers.Count);
Assert.Equal(texturesBefore, device.CreatedTextures.Count);
Assert.Equal(slotsBefore, device.LiveTextureSlotCount);
renderer.Dispose();
Assert.True(pipeline.IsDisposed);
}
private static int CountOccurrences(string source, string needle)
private sealed class NullGpuFrameSource : ICurrentGpuFrameSource
{
int count = 0;
for (int i = source.IndexOf(needle, StringComparison.Ordinal);
i >= 0;
i = source.IndexOf(needle, i + needle.Length, StringComparison.Ordinal))
{
count++;
}
return count;
}
private static string FindRepoRoot()
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
return directory.FullName;
directory = directory.Parent;
}
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
public IGpuFrame? CurrentFrame => null;
}
}