Add UAV surface pages for depth outputs
This commit is contained in:
parent
4d4cf36353
commit
cee474566e
6 changed files with 130 additions and 10 deletions
|
|
@ -384,7 +384,9 @@ Add contributors in this order:
|
|||
2. Compact Form/Appearance splats: first fractal/splat proof.
|
||||
3. Mesh summary contributor: triangles as field evidence, not bypass.
|
||||
4. Density/extinction volume: transparent Form, separate resolve semantics.
|
||||
5. SurfacePage/VolumeTexture resources: resource-backed claims.
|
||||
5. SurfacePage/VolumeTexture resources: resource-backed claims. SurfacePage can
|
||||
now be shader-readable or UAV-backed; use the UAV path for compute-produced
|
||||
depth/height pages instead of allocating a private output texture.
|
||||
|
||||
Exit gate:
|
||||
|
||||
|
|
|
|||
|
|
@ -391,6 +391,12 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
surfacePage = null!;
|
||||
if (declaration.Kind != AquariumFieldResourceKind.SurfacePage ||
|
||||
declaration.Residency != AquariumFieldResourceResidency.GpuResident ||
|
||||
declaration.Access is not (AquariumFieldShaderAccess.ShaderResource or AquariumFieldShaderAccess.UnorderedAccess))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (declaration.HasSourceAsset &&
|
||||
declaration.Access != AquariumFieldShaderAccess.ShaderResource)
|
||||
{
|
||||
return false;
|
||||
|
|
@ -398,9 +404,10 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
|
||||
if (textures.TryGetValue(declaration.ResourceKey, out var existing) &&
|
||||
existing.Kind == AquariumFieldResourceKind.SurfacePage &&
|
||||
existing.Version == declaration.Version &&
|
||||
SurfacePageMatches(existing, declaration) &&
|
||||
string.Equals(existing.SourceUri, declaration.SourceUri, StringComparison.Ordinal))
|
||||
{
|
||||
textures[declaration.ResourceKey] = existing with { Version = declaration.Version };
|
||||
surfacePage = existing.Texture;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -519,16 +526,17 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
AquariumFieldResourceDeclaration declaration)
|
||||
{
|
||||
if (declaration.Residency != AquariumFieldResourceResidency.GpuResident ||
|
||||
declaration.Access != AquariumFieldShaderAccess.ShaderResource)
|
||||
declaration.Access is not (AquariumFieldShaderAccess.ShaderResource or AquariumFieldShaderAccess.UnorderedAccess))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (textures.TryGetValue(declaration.ResourceKey, out var existing) &&
|
||||
existing.Kind == AquariumFieldResourceKind.SurfacePage &&
|
||||
existing.Version == declaration.Version &&
|
||||
SurfacePageMatches(existing, declaration) &&
|
||||
string.Equals(existing.SourceUri, declaration.SourceUri, StringComparison.Ordinal))
|
||||
{
|
||||
textures[declaration.ResourceKey] = existing with { Version = declaration.Version };
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -767,6 +775,25 @@ internal sealed class D3D12FieldResourceRegistry : IDisposable
|
|||
|
||||
private static string RegistryKey(string resourceKey) => RegistryPrefix + resourceKey;
|
||||
|
||||
private static bool SurfacePageMatches(Texture2DSlot existing, AquariumFieldResourceDeclaration declaration)
|
||||
{
|
||||
if (!D3D12FieldTextureFormat.TryFormat(declaration.Format, out var format))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (declaration.HasSourceAsset &&
|
||||
existing.Version != declaration.Version)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return existing.Texture.Width == Math.Max(1, declaration.Width) &&
|
||||
existing.Texture.Height == Math.Max(1, declaration.Height) &&
|
||||
existing.Texture.Format == format &&
|
||||
existing.Texture.AllowsUnorderedAccess == (declaration.Access == AquariumFieldShaderAccess.UnorderedAccess);
|
||||
}
|
||||
|
||||
private static int PositiveModulo(int value, int modulo)
|
||||
{
|
||||
var remainder = value % modulo;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
|
||||
public Format Format { get; }
|
||||
|
||||
public bool AllowsUnorderedAccess { get; }
|
||||
|
||||
public ResourceStates State { get; private set; } = ResourceStates.CopyDest;
|
||||
|
||||
private readonly ID3D12Resource? uploadResource;
|
||||
|
|
@ -27,6 +29,7 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
int width,
|
||||
int height,
|
||||
Format format,
|
||||
bool allowsUnorderedAccess,
|
||||
string name)
|
||||
{
|
||||
Resource = resource;
|
||||
|
|
@ -34,6 +37,7 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
Width = width;
|
||||
Height = height;
|
||||
Format = format;
|
||||
AllowsUnorderedAccess = allowsUnorderedAccess;
|
||||
Resource.Name = name;
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +100,7 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
|
||||
var width = Math.Max(1, declaration.Width);
|
||||
var height = Math.Max(1, declaration.Height);
|
||||
var allowsUnorderedAccess = declaration.Access == AquariumFieldShaderAccess.UnorderedAccess;
|
||||
var resource = device.CreateCommittedResource(
|
||||
HeapType.Default,
|
||||
ResourceDescription.Texture2D(
|
||||
|
|
@ -106,8 +111,8 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
1,
|
||||
1,
|
||||
0,
|
||||
ResourceFlags.None),
|
||||
ResourceStates.PixelShaderResource,
|
||||
allowsUnorderedAccess ? ResourceFlags.AllowUnorderedAccess : ResourceFlags.None),
|
||||
allowsUnorderedAccess ? ResourceStates.UnorderedAccess : ResourceStates.PixelShaderResource,
|
||||
null);
|
||||
|
||||
texture = new D3D12FieldTexture2D(
|
||||
|
|
@ -116,8 +121,9 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
width,
|
||||
height,
|
||||
format,
|
||||
allowsUnorderedAccess,
|
||||
$"Aquarium D3D12 Field Texture2D {declaration.ResourceKey}");
|
||||
texture.State = ResourceStates.PixelShaderResource;
|
||||
texture.State = allowsUnorderedAccess ? ResourceStates.UnorderedAccess : ResourceStates.PixelShaderResource;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +150,7 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
declaration.Width,
|
||||
declaration.Height,
|
||||
format,
|
||||
allowsUnorderedAccess: false,
|
||||
$"Aquarium D3D12 Shared Field Texture2D {declaration.ResourceKey}");
|
||||
texture.State = ResourceStates.PixelShaderResource;
|
||||
return true;
|
||||
|
|
@ -172,6 +179,26 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
descriptor.Cpu);
|
||||
}
|
||||
|
||||
public bool TryCreateUnorderedAccessView(ID3D12Device device, D3D12DescriptorSlot descriptor)
|
||||
{
|
||||
if (!AllowsUnorderedAccess)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
device.CreateUnorderedAccessView(
|
||||
Resource,
|
||||
null,
|
||||
new UnorderedAccessViewDescription
|
||||
{
|
||||
Format = Format,
|
||||
ViewDimension = UnorderedAccessViewDimension.Texture2D,
|
||||
Texture2D = new Texture2DUnorderedAccessView(),
|
||||
},
|
||||
descriptor.Cpu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Transition(ID3D12GraphicsCommandList commandList, ResourceStates nextState)
|
||||
{
|
||||
if (State == nextState)
|
||||
|
|
@ -243,7 +270,14 @@ internal sealed unsafe class D3D12FieldTexture2D : IDisposable
|
|||
});
|
||||
var destination = new TextureCopyLocation(texture, 0);
|
||||
commandList.CopyTextureRegion(destination, 0, 0, 0, source, null);
|
||||
var fieldTexture = new D3D12FieldTexture2D(texture, upload, width, height, Format.R8G8B8A8_UNorm, name);
|
||||
var fieldTexture = new D3D12FieldTexture2D(
|
||||
texture,
|
||||
upload,
|
||||
width,
|
||||
height,
|
||||
Format.R8G8B8A8_UNorm,
|
||||
allowsUnorderedAccess: false,
|
||||
name: name);
|
||||
fieldTexture.Transition(commandList, ResourceStates.PixelShaderResource);
|
||||
return fieldTexture;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,3 +303,4 @@
|
|||
{"timestamp":"2026-05-30T01:05:00+01:00","topic":"reservoir-disocclusion-mask","lesson":"Temporal disocclusion is now exposed by the reservoir owner instead of inferred from broad rejection color. Debug mode 19 maps temporal rejection codes for previous UV loss, previous-closer history, and support loss into a focused disocclusion mask, and the sequence measurer prefers disocclusion masks over rejection masks when both exist. The native-only 320x180 smoke set reservoir-sequence-20260530-000151-* produced a 3.1098% frame mask and a masked temporal-native delta row, proving the mask path is live. The remaining proof gap is a high-budget reference or repeated-sample reference mode so masked deltas can become actual error scores.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","scripts/capture-reservoir-mode-sequence.ps1","scripts/measure-reservoir-sequence.ps1","tests/Aquarium.Engine.Tests/FieldReservoirAbiTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-sequence-20260530-000151-*"}
|
||||
{"timestamp":"2026-05-30T01:25:00+01:00","topic":"reservoir-higher-work-grid-reference","lesson":"The sequence harness can now score candidates against a same-time higher-work-grid native-domain reference without violating the no-native-reservoir-buffer rule. capture-reservoir-mode-sequence.ps1 accepts -ReferenceFieldReservoirScale, captures reference rows in native-domain mode at that larger scale, and labels them reference in the manifest. measure-reservoir-sequence.ps1 emits reference-error rows and masked reference-error rows using disocclusion/rejection masks when present. The 320x180 smoke set reservoir-sequence-20260530-001046-* compared native scale 0.5 against reference scale 0.75 at the same ready-frame count; masked reference-error-native covered 3.0468% of frame pixels and changed 42.0368%. The next architectural step is adaptive update/sample budget policy driven by these reference-error pressure signals.","files":["scripts/capture-reservoir-mode-sequence.ps1","scripts/measure-reservoir-sequence.ps1","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-sequence-20260530-001046-*"}
|
||||
{"timestamp":"2026-05-30T01:40:00+01:00","topic":"reservoir-budget-pressure-probe","lesson":"The reservoir quality harness now converts same-time higher-work-grid reference error into per-tile budget pressure without making the probe a runtime owner. measure-reservoir-budget-pressure.ps1 reads a sequence manifest, compares a candidate final capture against the native-domain reference final capture at the same ready frame, applies disocclusion/rejection masks when present, and ranks fixed tiles by mean reference error times mask coverage. On reservoir-budget-pressure-20260530-001046.* the probe measured 1306/42864 pixels and found the top 5/50 tiles carried 99.3305% of measured reference-error delta, giving a concrete target for adaptive update policy while preserving the no-native-resolution-reservoir invariant.","files":["scripts/measure-reservoir-budget-pressure.ps1","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml","state/scratch.md"],"source":"artifacts/fensalir-captures/reservoir-budget-pressure-20260530-001046.*"}
|
||||
{"timestamp":"2026-05-30T00:29:26+01:00","topic":"surfacepage-uav-depth-socket","lesson":"SurfacePage resources can now be GPU-resident unordered-access outputs as well as shader-readable pages. D3D12FieldTexture2D tracks UAV capability, creates UAV descriptors, and D3D12FieldResourceRegistry resolves UnorderedAccess SurfacePages while reusing empty pages across version changes when shape/format/access are unchanged. This gives Mimir stereo-depth/height outputs a real compute-writable resource socket without private output textures or CPU readback.","files":["src/Aquarium.Engine/Render/D3D12FieldTexture2D.cs","src/Aquarium.Engine/Render/D3D12FieldResourceRegistry.cs","tests/Aquarium.Engine.Tests/D3D12SharedTextureInteropTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml"],"source":"dotnet test tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj --filter RegistryResolvesUnorderedAccessSurfacePageForComputeDepthOutput"}
|
||||
|
|
|
|||
|
|
@ -238,8 +238,12 @@ next_actions:
|
|||
renderer result instead of guessed. SurfacePage resources now have a first
|
||||
resolver: contracts and DSL can declare GPU-resident 2D pages with width,
|
||||
height, format, version,
|
||||
and optional local source, and the D3D12 registry allocates/imports them as
|
||||
shader-readable page textures. VolumeTexture resources now have the same
|
||||
optional local source, and optional unordered-access output intent; the
|
||||
D3D12 registry allocates/imports them as shader-readable page textures or
|
||||
compute-writable UAV-backed pages. Empty SurfacePage version is content
|
||||
freshness, not texture identity, so compute outputs can update without
|
||||
reallocating when shape/format/access are unchanged. VolumeTexture
|
||||
resources now have the same
|
||||
first resolver shape: contracts and DSL can declare GPU-resident 3D
|
||||
textures with dimensions, depth, format, and version, and the D3D12 registry
|
||||
allocates them as shader-readable volume textures. Mesh resources are now
|
||||
|
|
|
|||
|
|
@ -17,6 +17,58 @@ namespace Aquarium.Engine.Tests;
|
|||
|
||||
public sealed class D3D12SharedTextureInteropTests
|
||||
{
|
||||
[Fact]
|
||||
public void RegistryResolvesUnorderedAccessSurfacePageForComputeDepthOutput()
|
||||
{
|
||||
using var d3d12 = D3D12.D3D12CreateDevice<ID3D12Device>(IntPtr.Zero, FeatureLevel.Level_11_0);
|
||||
var declaration = new AquariumFieldResourceDeclaration(
|
||||
ResourceKey: "mimir:resource:stereo-depth:leap-disparity-r16f",
|
||||
Kind: AquariumFieldResourceKind.SurfacePage,
|
||||
Residency: AquariumFieldResourceResidency.GpuResident,
|
||||
Access: AquariumFieldShaderAccess.UnorderedAccess,
|
||||
Format: "R16Float",
|
||||
Width: 64,
|
||||
Height: 24,
|
||||
DepthOrCount: 1,
|
||||
StrideBytes: 2,
|
||||
ValidFromNs: 0,
|
||||
ValidUntilNs: 0,
|
||||
Version: 1,
|
||||
NativeHandle: IntPtr.Zero,
|
||||
NativeHandleKind: "fensalir-stereo-depth-output");
|
||||
|
||||
using var registry = new D3D12FieldResourceRegistry();
|
||||
var resources = new D3D12ResourceRegistry();
|
||||
var stats = registry.Resolve(d3d12, resources, [declaration]);
|
||||
|
||||
Assert.Equal(1, stats.Declared);
|
||||
Assert.Equal(1, stats.SurfacePages);
|
||||
Assert.Equal(1, stats.Resolved);
|
||||
Assert.Equal(0, stats.Unsupported);
|
||||
Assert.True(registry.TryGetSurfacePage(declaration.ResourceKey, out var resolved));
|
||||
Assert.Equal(64, resolved.Width);
|
||||
Assert.Equal(24, resolved.Height);
|
||||
Assert.Equal(Format.R16_Float, resolved.Format);
|
||||
Assert.True(resolved.AllowsUnorderedAccess);
|
||||
|
||||
using var descriptors = new D3D12DescriptorArena(
|
||||
d3d12,
|
||||
DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView,
|
||||
2,
|
||||
DescriptorHeapFlags.None,
|
||||
"test surface page descriptors");
|
||||
Assert.True(resolved.TryCreateUnorderedAccessView(d3d12, descriptors.Allocate()));
|
||||
resolved.CreateShaderResourceView(d3d12, descriptors.Allocate());
|
||||
|
||||
var nextFrameStats = registry.Resolve(d3d12, resources, [declaration with { Version = 2 }]);
|
||||
|
||||
Assert.Equal(1, nextFrameStats.Resolved);
|
||||
Assert.Equal(0, nextFrameStats.Unsupported);
|
||||
Assert.Equal(0, nextFrameStats.StaleRemoved);
|
||||
Assert.True(registry.TryGetSurfacePage(declaration.ResourceKey, out var nextFrameResolved));
|
||||
Assert.Same(resolved, nextFrameResolved);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegistryResolvesD3D11NtSharedBgraTextureAsD3D12Texture2D()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue