Plan §5.5.11 recorded what V4t deliberately left behind: it moved the table
ENTRY of every world texture to the device and kept CREATION with the caches,
because "creating world textures through IGpuTexture is real remaining work and
it belongs with the Vulkan world arm, which is the first thing that cannot use a
GL handle at all." §5.5.12 item 1 handed it forward and named the missing piece
exactly — "an ITextureArray implementation over IGpuTexture, not a codec",
because V6b's BlockCompressionCodec and BlockCompressionMipChain already supply
the BC chains. This is that work.
IWorldTextureArray is the seam, and the slot is what crosses it. Before this
commit ObjectMeshManager read BindlessWrapHandle/BindlessClampHandle off the
concrete GL array and interned them into the device table itself. A 64-bit
ARB_bindless_texture handle has no Vulkan spelling, so the array now answers the
question the caller was really asking — ResolveSlot(wrapping) — and each arm gets
there its own way: ManagedGLTextureArray makes the same idempotent interning call
one level down, and RhiWorldTextureArray returns a pair it registered at
construction. ReleaseTextureSlots replaces the snapshot dictionary the manager
kept for the same reason, and still runs only once physical retirement completes.
Which implementation exists is decided ONCE, by the IWorldTextureArrayFactory
composition builds — plan §3.1's no-runtime-fork rule. Everything above the seam
(capacity policy, slot allocation, ref counting, layer retirement, empty-atlas
eviction, and the whole of ObjectMeshManager's atlas policy) is written once and
branches on nothing.
Three things the RHI array does differently, each because the backends genuinely
differ rather than by choice: BC mip chains are CPU-built through
BlockCompressionMipChain, since Vulkan cannot blit into a compressed image, while
RGBA8 uses the device's blit; filtering lives in an immutable sampler rather than
a texture parameter, so both address modes are registered up front exactly as the
GL array holds two resident handles; and RGB8/A8/Rgba32f are refused at creation
with the reason named. A8 is the interesting refusal — the GL array serves it by
swizzling R into A, and a Vulkan swizzle lives in the image VIEW, which the pinned
GpuTextureDescription does not describe. A silent substitution would render wrong
and look like a shader bug.
TerrainAtlas gains the second construction path V6i drafted and reverted. The
decode is factored out and shared, so both arms read the same DATs, in the same
order, with the same resize-to-max policy; only the upload forks.
ICompositeTextureArrayBackend gains its RHI arm, which is four small methods
because that seam was already a seam.
The Vulkan arm is EXERCISED, not merely present. That is the whole reason the
V6i draft was reverted rather than landed — "built then reverted because nothing
exercised it" — and it is the same failure §5.5.12 measured twice in the
descriptor layouts. So the composition host now builds the real terrain atlas
through IGpuDevice.CreateTexture on the arm with no GL context, and creates and
releases one shared array of each format family plus one composite array at
startup. Creation only; nothing draws them. Releasing them in the same statement
covers one thing a retained bundle would not — that both slot pairs come back and
the images route through the retirement queue.
Gates: Release build; App tests 4,104 / 3 skips; strict GL offline pixel gate vs
0ca802cd 3.20e-05 (18 px of 563,200, inside the documented 9–31 px control band);
GL connected tools/run-repeat-connected-gate.ps1 -Runs 3 at 3/3 RENDERED on the
desktop witness AND 3/3 on the client capture; one Vulkan composition-host run
with VK_LAYER_KHRONOS_validation proven inserted by the loader at zero errors,
zero warnings, no [shutdown] diagnostic, and a captured frame. That run built
terrain-atlas 512x512x33 with 10 mip levels, terrain-alpha-atlas 512x512x8, RGBA8
64x64x32 (slots 3/4, 174,720 mip bytes blitted), BC1 64x64x32 (slots 5/6, 696 mip
bytes encoded) and composite 32x32x8 (slot 7).
One whole-suite run failed Issue181WallPressEquilibriumTests once; it passed
alone and did not recur in five further runs. Seven test classes mutate the same
process-global CameraDiagnostics switches with no xUnit collection isolation, and
this diff touches no camera, visibility or physics code. A separate run of the
UNCHANGED parent tree failed a different zero-allocation test, which is `#250`'s
documented class. Both are filed rather than attributed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AcDream.App.Rendering;
|
|
using AcDream.App.Rendering.Gpu;
|
|
using AcDream.App.Tests.Rendering.Gpu;
|
|
|
|
namespace AcDream.App.Tests.Rendering;
|
|
|
|
/// <summary>
|
|
/// Campaign V slice V6i-2: the composite array pool's backend-neutral arm.
|
|
///
|
|
/// <para>Plan §5.5.12 item 1 recorded that <c>ICompositeTextureArrayBackend</c>
|
|
/// "is already a seam and takes an RHI backend directly", which is why this arm
|
|
/// is four small methods rather than a port. What is worth pinning is the
|
|
/// contract the cache above depends on: create returns a resource whose slot is
|
|
/// live, the release order is entry-then-image, and a resource made by one
|
|
/// backend is never handed to the other.</para>
|
|
/// </summary>
|
|
public sealed class RhiCompositeTextureArrayBackendTests
|
|
{
|
|
private static byte[] Rgba(int width, int height) => new byte[width * height * 4];
|
|
|
|
[Fact]
|
|
public void CreateProducesASingleLevelArrayRegisteredIntoTheTable()
|
|
{
|
|
using var device = new RecordingGpuDevice();
|
|
var backend = new RhiCompositeTextureArrayBackend(device);
|
|
|
|
CompositeTextureArrayResource resource = backend.Create(32, 32, 8);
|
|
|
|
Assert.True(resource.Slot.IsAssigned);
|
|
Assert.Equal(32 * 32 * 4 * 8, resource.Bytes);
|
|
// The GL identity fields are meaningless on this arm and say so.
|
|
Assert.Equal(0u, resource.Name);
|
|
Assert.Equal(0ul, resource.Handle);
|
|
|
|
RecordingGpuTexture image = Assert.IsType<RecordingGpuTexture>(resource.Image);
|
|
Assert.Equal(GpuTextureKind.Texture2DArray, image.Kind);
|
|
Assert.Equal(GpuTextureFormat.Rgba8Unorm, image.Format);
|
|
Assert.Equal(8, image.LayerCount);
|
|
// Composites are the surfaces retail releases the moment they are built;
|
|
// a mip chain would be paid for nothing.
|
|
Assert.Equal(1, image.MipLevelCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void UploadWritesLevelZeroOfTheNamedLayer()
|
|
{
|
|
using var device = new RecordingGpuDevice();
|
|
var backend = new RhiCompositeTextureArrayBackend(device);
|
|
CompositeTextureArrayResource resource = backend.Create(32, 32, 4);
|
|
|
|
backend.Upload(resource, 3, Rgba(32, 32));
|
|
|
|
RecordingGpuTexture image = Assert.IsType<RecordingGpuTexture>(resource.Image);
|
|
Assert.Equal([(0, 3, 32 * 32 * 4)], image.Uploads);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReleaseRetiresTheTableEntryBeforeTheImage()
|
|
{
|
|
using var device = new RecordingGpuDevice();
|
|
var backend = new RhiCompositeTextureArrayBackend(device);
|
|
int before = device.LiveTextureSlotCount;
|
|
CompositeTextureArrayResource resource = backend.Create(32, 32, 4);
|
|
Assert.Equal(before + 1, device.LiveTextureSlotCount);
|
|
|
|
backend.MakeNonResident(resource);
|
|
Assert.Equal(before, device.LiveTextureSlotCount);
|
|
Assert.False(Assert.IsType<RecordingGpuTexture>(resource.Image).IsDisposed);
|
|
|
|
backend.Delete(resource);
|
|
Assert.True(Assert.IsType<RecordingGpuTexture>(resource.Image).IsDisposed);
|
|
}
|
|
|
|
/// <summary>
|
|
/// A GL-made resource reaching this backend is a composition error, not a
|
|
/// runtime condition — and the message says which backend owns it rather
|
|
/// than dereferencing null.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AGlResourceIsRefusedRatherThanDereferenced()
|
|
{
|
|
using var device = new RecordingGpuDevice();
|
|
var backend = new RhiCompositeTextureArrayBackend(device);
|
|
var foreign = new CompositeTextureArrayResource
|
|
{
|
|
Name = 7,
|
|
Handle = 0xDEAD,
|
|
Slot = new GpuTextureSlot(3),
|
|
Width = 32,
|
|
Height = 32,
|
|
Capacity = 1,
|
|
Bytes = 32 * 32 * 4,
|
|
};
|
|
|
|
Assert.Throws<InvalidOperationException>(() => backend.Upload(foreign, 0, Rgba(32, 32)));
|
|
Assert.Throws<InvalidOperationException>(() => backend.Delete(foreign));
|
|
}
|
|
|
|
/// <summary>
|
|
/// The cache caps every array at 64 layers, so the layer ceiling this
|
|
/// backend reports is never the binding constraint — which is what lets it
|
|
/// report Vulkan's guaranteed minimum instead of a capability field the
|
|
/// pinned record does not carry.
|
|
/// </summary>
|
|
[Fact]
|
|
public void TheReportedLayerCeilingExceedsTheCachesOwnCap()
|
|
{
|
|
using var device = new RecordingGpuDevice();
|
|
var backend = new RhiCompositeTextureArrayBackend(device);
|
|
|
|
Assert.True(backend.MaximumArrayLayers >= CompositeTextureArrayCache.MaximumLayersPerArray);
|
|
}
|
|
}
|