feat(render): Campaign V slice V6i-2 commit 2 — world texture creation crosses to IGpuTexture
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>
This commit is contained in:
parent
f7344758f8
commit
c8d0f70bbe
12 changed files with 1662 additions and 95 deletions
|
|
@ -9,11 +9,21 @@ using System.Runtime.InteropServices;
|
|||
using AcDream.App.Rendering;
|
||||
|
||||
namespace AcDream.App.Rendering.Wb {
|
||||
public class ManagedGLTextureArray : ITextureArray {
|
||||
public class ManagedGLTextureArray : ITextureArray, IWorldTextureArray {
|
||||
private readonly bool[] _usedLayers;
|
||||
private readonly GL GL;
|
||||
private readonly OpenGLGraphicsDevice _device;
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Campaign V slice V6i-2: the device whose one texture table this
|
||||
/// array's two resident handles are interned into. Before this slice
|
||||
/// <c>ObjectMeshManager</c> read the handles off this object and did the
|
||||
/// interning itself; a 64-bit bindless handle cannot cross to Vulkan, so
|
||||
/// the array now answers <see cref="ResolveSlot"/> instead. Null only
|
||||
/// for the legacy <c>OpenGLGraphicsDevice.CreateTextureArrayInternal</c>
|
||||
/// entry points, which no shared atlas uses.
|
||||
/// </summary>
|
||||
private readonly AcDream.App.Rendering.Gpu.Gl.GlGpuDevice? _worldTextureTable;
|
||||
private static int _nextId = 0;
|
||||
private bool _needsMipmapRegeneration = false;
|
||||
private readonly bool _isCompressed;
|
||||
|
|
@ -53,7 +63,15 @@ namespace AcDream.App.Rendering.Wb {
|
|||
}
|
||||
|
||||
public ManagedGLTextureArray(OpenGLGraphicsDevice graphicsDevice, TextureFormat format, int width, int height,
|
||||
int size, ILogger logger, TextureParameters? texParams = null) {
|
||||
int size, ILogger logger, TextureParameters? texParams = null)
|
||||
: this(graphicsDevice, format, width, height, size, logger, worldTextureTable: null, texParams) {
|
||||
}
|
||||
|
||||
internal ManagedGLTextureArray(OpenGLGraphicsDevice graphicsDevice, TextureFormat format, int width, int height,
|
||||
int size, ILogger logger,
|
||||
AcDream.App.Rendering.Gpu.Gl.GlGpuDevice? worldTextureTable,
|
||||
TextureParameters? texParams = null) {
|
||||
_worldTextureTable = worldTextureTable;
|
||||
var p = texParams ?? TextureParameters.Default;
|
||||
if (width <= 0 || height <= 0 || size <= 0) {
|
||||
throw new ArgumentException($"Invalid texture array dimensions: {width}x{height}x{size}");
|
||||
|
|
@ -532,6 +550,48 @@ namespace AcDream.App.Rendering.Wb {
|
|||
Volatile.Read(ref _disposeQueued) != 0
|
||||
&& Volatile.Read(ref _disposeRelease) is null;
|
||||
|
||||
bool IWorldTextureArray.HasDurableDisposeOwnership => HasDurableDisposeOwnership;
|
||||
|
||||
bool IWorldTextureArray.IsPhysicalRetirementComplete => IsPhysicalRetirementComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign V slice V6i-2: this array's device-table slot for the
|
||||
/// requested address mode.
|
||||
///
|
||||
/// <para>The interning call is the one <c>ObjectMeshManager</c> made
|
||||
/// itself before this slice, moved one level down so the caller can be
|
||||
/// written against <see cref="IWorldTextureArray"/> instead of against a
|
||||
/// 64-bit <c>ARB_bindless_texture</c> handle that has no Vulkan
|
||||
/// spelling. It is idempotent by handle, which is why it stays a per-batch
|
||||
/// call rather than becoming cached state — exactly as before.</para>
|
||||
/// </summary>
|
||||
AcDream.App.Rendering.Gpu.GpuTextureSlot IWorldTextureArray.ResolveSlot(bool wrapping) {
|
||||
if (_worldTextureTable is null)
|
||||
return AcDream.App.Rendering.Gpu.GpuTextureSlot.Unassigned;
|
||||
ulong handle = wrapping ? _retiredWrapHandle : _retiredClampHandle;
|
||||
if (handle == 0)
|
||||
handle = wrapping ? BindlessWrapHandle : BindlessClampHandle;
|
||||
return _worldTextureTable.RegisterWorldTextureHandle(handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retires both table entries. <see cref="Dispose"/> zeroes the public
|
||||
/// handle properties, so the values are captured there and read from the
|
||||
/// captures here — this is called after physical retirement completes,
|
||||
/// which is necessarily after Dispose.
|
||||
/// </summary>
|
||||
public void ReleaseTextureSlots() {
|
||||
if (_worldTextureTable is null)
|
||||
return;
|
||||
_worldTextureTable.ReleaseWorldTextureHandle(_retiredWrapHandle);
|
||||
_worldTextureTable.ReleaseWorldTextureHandle(_retiredClampHandle);
|
||||
_retiredWrapHandle = 0;
|
||||
_retiredClampHandle = 0;
|
||||
}
|
||||
|
||||
private ulong _retiredWrapHandle;
|
||||
private ulong _retiredClampHandle;
|
||||
|
||||
public void Unbind() {
|
||||
GL.BindTexture(GLEnum.Texture2DArray, 0);
|
||||
GLHelpers.CheckErrors(GL);
|
||||
|
|
@ -555,6 +615,12 @@ namespace AcDream.App.Rendering.Wb {
|
|||
ulong bindlessClampHandle = BindlessClampHandle;
|
||||
long textureBytes = CalculateTotalSize();
|
||||
|
||||
// Slice V6i-2: the handles the two table entries are keyed by. The
|
||||
// properties are zeroed below, so ReleaseTextureSlots — which runs
|
||||
// only once physical retirement completes — reads these captures.
|
||||
_retiredWrapHandle = bindlessWrapHandle;
|
||||
_retiredClampHandle = bindlessClampHandle;
|
||||
|
||||
NativePtr = 0;
|
||||
BindlessWrapHandle = 0;
|
||||
BindlessClampHandle = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue