Add stereo depth field lowering contract

This commit is contained in:
Meta Vens 2026-05-30 00:40:33 +01:00
commit 8e7ace66c7
5 changed files with 340 additions and 6 deletions

View file

@ -386,7 +386,11 @@ Add contributors in this order:
4. Density/extinction volume: transparent Form, separate resolve semantics.
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.
depth/height pages instead of allocating a private output texture. Stereo
depth dispatch metadata is now typed as `AquariumFieldStereoDepthLowering`:
it must bind the Height claim to shader-readable left/right texture
resources, a calibrated camera pair/profile, and a compute-writable disparity
`SurfacePage`.
Exit gate:
@ -455,6 +459,10 @@ Mimir path:
- raw capture stays in Mimir;
- calibrated features become Form/Appearance/Transport claims;
- calibrated stereo depth starts as a Fensalir D3D12 compute lowering contract:
Mimir declares rectified left/right texture resources and profile/calibration
metadata, while Fensalir owns the UAV disparity `SurfacePage` output and any
eventual SGM-shaped HLSL kernel;
- confidence/density fields are first-class fields;
- stable surfaces emerge only after multi-view/acoustic evidence earns them.
@ -579,6 +587,13 @@ Work packet:
0.75 / spatial budget 1.0; masked reference-error-native covered 3.8261%
of pixels, and budget pressure found the top 5 of 50 tiles carried
90.8321% of measured reference-error delta.
15. Partial: expose the spatial budget phase at the visible layer. Debug mode
20, `Reservoir Spatial Budget`, renders pixels that spend spatial reuse in
green and pixels that skip it in blue. Sequence capture names this mode
`spatial-budget`. Smoke `reservoir-sequence-20260530-003746-*` captured the
debug view at native scale 0.5 / spatial budget 0.5; a whole-image probe
counted 32078 green pixels and 6818 blue pixels in the 304x141 present
output, with remaining pixels from filtering/black margins.
Required verification:

View file

@ -385,6 +385,48 @@ public readonly record struct AquariumFieldTubeSplineLowering(
};
}
public readonly record struct AquariumFieldStereoDepthLowering(
string LoweringKey,
string ClaimKey,
string ProfileKey,
string CalibrationKey,
string CameraPairKey,
string LeftResourceKey,
string RightResourceKey,
string DisparityResourceKey,
string ConfidenceResourceKey,
int Width,
int Height,
int DisparityLevels,
int AggregationPathCount,
float MinDepthMeters,
float MaxDepthMeters)
{
public bool IsValid =>
!string.IsNullOrWhiteSpace(LoweringKey) &&
!string.IsNullOrWhiteSpace(ClaimKey) &&
!string.IsNullOrWhiteSpace(ProfileKey) &&
!string.IsNullOrWhiteSpace(CalibrationKey) &&
!string.IsNullOrWhiteSpace(CameraPairKey) &&
!string.IsNullOrWhiteSpace(LeftResourceKey) &&
!string.IsNullOrWhiteSpace(RightResourceKey) &&
!string.IsNullOrWhiteSpace(DisparityResourceKey) &&
Width > 0 &&
Height > 0 &&
DisparityLevels > 0 &&
AggregationPathCount > 0 &&
MaxDepthMeters > MinDepthMeters;
public AquariumFieldStereoDepthLowering Normalized() => this with
{
Width = Math.Max(1, Width),
Height = Math.Max(1, Height),
DisparityLevels = Math.Max(1, DisparityLevels),
AggregationPathCount = Math.Max(1, AggregationPathCount),
MaxDepthMeters = MaxDepthMeters <= MinDepthMeters ? MinDepthMeters + 0.001f : MaxDepthMeters,
};
}
public readonly record struct AquariumFieldResourceDeclaration(
string ResourceKey,
AquariumFieldResourceKind Kind,
@ -558,6 +600,8 @@ public sealed class AquariumFieldEvidenceFrame
public IReadOnlyList<AquariumFieldTubeSplineLowering> TubeSplineLowerings { get; init; } = [];
public IReadOnlyList<AquariumFieldStereoDepthLowering> StereoDepthLowerings { get; init; } = [];
public float AccumulationWindowSeconds { get; init; }
public float PresentationDelaySeconds { get; init; }
@ -569,7 +613,8 @@ public sealed class AquariumFieldEvidenceFrame
BackendPackets.Count > 0 ||
Resources.Count > 0 ||
ResourceUploads.Count > 0 ||
TubeSplineLowerings.Count > 0;
TubeSplineLowerings.Count > 0 ||
StereoDepthLowerings.Count > 0;
}
public readonly record struct AquariumFieldEvidenceIssue(
@ -850,11 +895,87 @@ public static class AquariumFieldEvidenceValidator
}
}
foreach (var lowering in frame.StereoDepthLowerings)
{
if (!lowering.IsValid)
{
issues.Add(Error(string.IsNullOrWhiteSpace(lowering.LoweringKey) ? "stereo-depth-lowering" : lowering.LoweringKey, "Stereo depth lowering is missing identity, inputs, output, shape, profile, calibration, or depth range."));
continue;
}
if (!claimsByKey.TryGetValue(lowering.ClaimKey, out var claim))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth lowering references unknown claim '{lowering.ClaimKey}'."));
}
else
{
if (claim.Encoding != AquariumFieldEncoding.Height)
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth lowering claim '{lowering.ClaimKey}' is encoded as {claim.Encoding}, not Height."));
}
if (!string.Equals(claim.PayloadHandle, lowering.DisparityResourceKey, StringComparison.Ordinal))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth disparity resource '{lowering.DisparityResourceKey}' does not match claim payload '{claim.PayloadHandle}'."));
}
}
ValidateStereoDepthInputResource(issues, resourcesByKey, lowering, lowering.LeftResourceKey, "left");
ValidateStereoDepthInputResource(issues, resourcesByKey, lowering, lowering.RightResourceKey, "right");
if (!resourcesByKey.TryGetValue(lowering.DisparityResourceKey, out var disparity))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth lowering references unknown disparity resource '{lowering.DisparityResourceKey}'."));
}
else
{
if (disparity.Kind != AquariumFieldResourceKind.SurfacePage)
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth disparity resource '{lowering.DisparityResourceKey}' is {disparity.Kind}, not SurfacePage."));
}
if (disparity.Access != AquariumFieldShaderAccess.UnorderedAccess)
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth disparity resource '{lowering.DisparityResourceKey}' must be compute-writable UnorderedAccess."));
}
}
if (!string.IsNullOrWhiteSpace(lowering.ConfidenceResourceKey) &&
!resourcesByKey.TryGetValue(lowering.ConfidenceResourceKey, out _))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth lowering references unknown confidence resource '{lowering.ConfidenceResourceKey}'."));
}
}
return issues.Count == 0
? AquariumFieldEvidenceValidationReport.Empty
: new AquariumFieldEvidenceValidationReport(issues);
}
private static void ValidateStereoDepthInputResource(
ICollection<AquariumFieldEvidenceIssue> issues,
IReadOnlyDictionary<string, AquariumFieldResourceDeclaration> resourcesByKey,
AquariumFieldStereoDepthLowering lowering,
string resourceKey,
string role)
{
if (!resourcesByKey.TryGetValue(resourceKey, out var resource))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth lowering references unknown {role} input resource '{resourceKey}'."));
return;
}
if (resource.Kind is not (AquariumFieldResourceKind.Texture2D or AquariumFieldResourceKind.RollingTexture))
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth {role} input resource '{resourceKey}' is {resource.Kind}, not Texture2D or RollingTexture."));
}
if (resource.Access != AquariumFieldShaderAccess.ShaderResource)
{
issues.Add(Error(lowering.LoweringKey, $"Stereo depth {role} input resource '{resourceKey}' must be shader-readable."));
}
}
private static AquariumFieldEvidenceIssue Error(string key, string message) =>
new(AquariumFieldEvidenceIssueSeverity.Error, key, message);

View file

@ -304,4 +304,6 @@
{"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-30T01:58:00+01:00","topic":"reservoir-spatial-reuse-budget","lesson":"The renderer now has a first runtime sampling budget inside the reservoir history update owner. GraphicsSettings.FieldReservoirSpatialReuseBudget flows through UI, runtime options, CLI/env overrides, capture scripts, frame constants, and D3D12ReservoirHistoryUpdateCS. Current and temporal rows are still written for every reservoir work-grid pixel; only the 3x3 spatial neighbor reuse pass is spent on the deterministic budget phase. The default is 0.5, so the machine combines half presentation grid reservoir surfaces with half spatial reuse sampling by default. Smoke reservoir-sequence-20260530-003006-* compared native scale 0.5/spatial budget 0.5 against reference scale 0.75/spatial budget 1.0; masked reference-error-native covered 3.8261% of frame pixels, and reservoir-budget-pressure-20260530-003006.* found the top 5/50 tiles carried 90.8321% of measured reference-error delta.","files":["src/Aquarium.Engine.Contracts/GraphicsSettings.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","scripts/capture-fensalir-frame.ps1","scripts/capture-reservoir-mode-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-003006-*"}
{"timestamp":"2026-05-30T02:10:00+01:00","topic":"reservoir-spatial-budget-debug","lesson":"The spatial reuse sampling budget now has a visible owner-layer probe. Render debug mode 20, Reservoir Spatial Budget, colors work-grid pixels that spend 3x3 spatial reuse green and skipped pixels blue; capture-reservoir-mode-sequence.ps1 names the mode spatial-budget. Smoke reservoir-sequence-20260530-003746-* captured the debug view at native scale 0.5/spatial budget 0.5. A bitmap probe on the 304x141 present output counted 32078 green pixels, 6818 blue pixels, and 3968 filtering/other pixels, proving the budget branch is observable where the user sees it.","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","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-003746-*"}
{"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"}
{"timestamp":"2026-05-30T00:37:29+01:00","topic":"stereo-depth-lowering-contract","lesson":"FieldEvidence now carries typed stereo-depth lowering metadata for future D3D12 SGM dispatch. AquariumFieldStereoDepthLowering binds a Height claim to shader-readable left/right texture resources, profile/calibration/camera-pair identity, depth range/disparity settings, and a compute-writable UAV disparity SurfacePage. Validation rejects claim encoding mismatches, payload/resource mismatches, non-UAV disparity outputs, and missing/non-readable inputs. This keeps Mimir libSGM-provenance depth inside Fensalir resource authority rather than a private texture, CPU readback, CUDA, or TensorRT path.","files":["src/Aquarium.Engine.Contracts/Render/AquariumFieldEvidence.cs","tests/Aquarium.Engine.Tests/FieldEvidenceContractTests.cs","docs/perfect-fensalir-machine-roadmap.md","state/map.yaml"],"source":"dotnet test tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj --filter StereoDepth"}

View file

@ -169,9 +169,11 @@ next_actions:
work-grid pixel writes current/temporal rows, while a deterministic phase
spends 3x3 neighbor sampling. Smoke `reservoir-sequence-20260530-003006-*`
proves native scale 0.5 / spatial budget 0.5 against reference scale 0.75 /
spatial budget 1.0. The next cut is turning budget-pressure evidence into a
renderer-owned per-tile adaptive update contract plus future exact producer
SDF replay.
spatial budget 1.0. Debug mode 20, `Reservoir Spatial Budget`, now exposes
the active spatial reuse phase at the visible layer; smoke
`reservoir-sequence-20260530-003746-*` proves it. The next cut is turning
budget-pressure evidence into a renderer-owned per-tile adaptive update
contract plus future exact producer SDF replay.
- Build the planetary flow organ in staged cuts: provenance manifest, static
relief and reanalysis cube-sphere bake pipeline, stochastic advection
contracts, synthetic runtime slice, ERA5/OSCAR baseline learning, then
@ -247,7 +249,14 @@ next_actions:
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
reallocating when shape/format/access are unchanged. FieldEvidence now has
an explicit `AquariumFieldStereoDepthLowering` sidecar for future calibrated
stereo compute dispatch: validation requires a Height claim whose payload is
the compute-writable disparity SurfacePage, shader-readable left/right
Texture2D or RollingTexture resources, profile/calibration/camera-pair
identity, and coherent output shape/range. This keeps Mimir's libSGM-shaped
D3D12 depth path inside typed field/resource authority instead of a private
texture or CUDA/TensorRT dependency. 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

View file

@ -428,6 +428,66 @@ public sealed class FieldEvidenceContractTests
Assert.Contains(report.Issues, issue => issue.Key == "tube-spline:mimir:spectrum:asio-ch0:42");
}
[Fact]
public void ValidatorAcceptsStereoDepthLoweringWithComputeWritableDisparity()
{
var frame = BuildValidStereoDepthEvidenceFrame();
var report = AquariumFieldEvidenceValidator.Validate(frame);
Assert.False(report.HasErrors);
Assert.Empty(report.Issues);
Assert.True(frame.HasInput);
Assert.Equal(AquariumFieldShaderAccess.UnorderedAccess, frame.Resources[2].Access);
}
[Fact]
public void ValidatorRejectsStereoDepthLoweringClaimEncodingMismatch()
{
var frame = BuildValidStereoDepthEvidenceFrame();
frame = new AquariumFieldEvidenceFrame
{
Resources = frame.Resources,
Domains = frame.Domains,
Claims = [frame.Claims[0] with { Encoding = AquariumFieldEncoding.Mesh }],
Candidates = frame.Candidates,
StereoDepthLowerings = frame.StereoDepthLowerings,
AccumulationWindowSeconds = frame.AccumulationWindowSeconds,
PresentationDelaySeconds = frame.PresentationDelaySeconds,
};
var report = AquariumFieldEvidenceValidator.Validate(frame);
Assert.True(report.HasErrors);
Assert.Contains(report.Issues, issue => issue.Key == "stereo-depth:mimir:leap:libsgm");
}
[Fact]
public void ValidatorRejectsStereoDepthLoweringWithoutUnorderedAccessDisparity()
{
var frame = BuildValidStereoDepthEvidenceFrame();
frame = new AquariumFieldEvidenceFrame
{
Resources =
[
frame.Resources[0],
frame.Resources[1],
frame.Resources[2] with { Access = AquariumFieldShaderAccess.ShaderResource },
],
Domains = frame.Domains,
Claims = frame.Claims,
Candidates = frame.Candidates,
StereoDepthLowerings = frame.StereoDepthLowerings,
AccumulationWindowSeconds = frame.AccumulationWindowSeconds,
PresentationDelaySeconds = frame.PresentationDelaySeconds,
};
var report = AquariumFieldEvidenceValidator.Validate(frame);
Assert.True(report.HasErrors);
Assert.Contains(report.Issues, issue => issue.Key == "stereo-depth:mimir:leap:libsgm");
}
[Fact]
public void NormalizerBuildsPendingLoweringRequestsWithoutChoosingBackend()
{
@ -842,4 +902,131 @@ tubeclaim id=spectrum-trail resource=spectrum domain=mimir:spectrum:asio-ch0 con
],
};
}
private static AquariumFieldEvidenceFrame BuildValidStereoDepthEvidenceFrame()
{
var support = new AquariumFieldSupport(
Center: new Vector3(320.0f, 240.0f, 2.0f),
Radius: new Vector3(320.0f, 240.0f, 2.0f),
LocalFrame: Matrix4x4.Identity,
ConservativeRadius: 320.0f,
ProjectedError: 1.0f / 128.0f,
Curvature: 0.0f,
TemporalUncertainty: 0.0f);
var proposal = new AquariumFieldProposalPolicy(
AquariumFieldProposalKind.SensorObservation,
SourcePdf: 1.0f,
TargetContribution: 1.0f,
RepresentedCandidateCount: 1,
Seed: 9u);
return new AquariumFieldEvidenceFrame
{
Resources =
[
new AquariumFieldResourceDeclaration(
"mimir:resource:leap:left-ir",
AquariumFieldResourceKind.Texture2D,
AquariumFieldResourceResidency.SharedGpu,
AquariumFieldShaderAccess.ShaderResource,
"R8_UNorm",
Width: 640,
Height: 480,
DepthOrCount: 1,
StrideBytes: 1,
ValidFromNs: 42,
ValidUntilNs: 42,
Version: 42,
NativeHandle: new IntPtr(0x1001),
NativeHandleKind: "shared-d3d12-texture"),
new AquariumFieldResourceDeclaration(
"mimir:resource:leap:right-ir",
AquariumFieldResourceKind.Texture2D,
AquariumFieldResourceResidency.SharedGpu,
AquariumFieldShaderAccess.ShaderResource,
"R8_UNorm",
Width: 640,
Height: 480,
DepthOrCount: 1,
StrideBytes: 1,
ValidFromNs: 42,
ValidUntilNs: 42,
Version: 42,
NativeHandle: new IntPtr(0x1002),
NativeHandleKind: "shared-d3d12-texture"),
new AquariumFieldResourceDeclaration(
"mimir:resource:leap:disparity-r16f",
AquariumFieldResourceKind.SurfacePage,
AquariumFieldResourceResidency.GpuResident,
AquariumFieldShaderAccess.UnorderedAccess,
"R16Float",
Width: 640,
Height: 480,
DepthOrCount: 1,
StrideBytes: 2,
ValidFromNs: 42,
ValidUntilNs: 42,
Version: 42,
NativeHandle: IntPtr.Zero,
NativeHandleKind: "fensalir-stereo-depth-disparity"),
],
Domains =
[
new AquariumFieldDomain(
"mimir:stereo-depth:leap:libsgm",
"mimir:leap",
AquariumFieldDomainKind.Surface2D,
Matrix4x4.Identity,
Matrix4x4.Identity,
Vector3.Zero,
new Vector3(640.0f, 480.0f, 4.0f),
Vector3.Zero,
"Mimir.Runtime")
],
Claims =
[
new AquariumFieldClaim(
"claim:mimir:stereo-depth:leap:libsgm",
"mimir:stereo-depth:leap:libsgm",
"mimir:leap",
AquariumFieldLayer.Form,
AquariumFieldEncoding.Height,
support,
proposal,
"mimir:resource:leap:disparity-r16f",
ObservedTimeNs: 42,
Confidence: 0.8f)
],
Candidates =
[
new AquariumFieldCandidate(
"candidate:mimir:stereo-depth:leap:libsgm",
"claim:mimir:stereo-depth:leap:libsgm",
AquariumFieldLayer.Form,
AquariumFieldEncoding.Height,
proposal,
AquariumFieldGuide.Valid(0.8f))
],
StereoDepthLowerings =
[
new AquariumFieldStereoDepthLowering(
"stereo-depth:mimir:leap:libsgm",
"claim:mimir:stereo-depth:leap:libsgm",
"d3d12-sgm-libsgm-provenance",
"leap-calibration",
"leap-ir-pair",
"mimir:resource:leap:left-ir",
"mimir:resource:leap:right-ir",
"mimir:resource:leap:disparity-r16f",
"",
Width: 640,
Height: 480,
DisparityLevels: 128,
AggregationPathCount: 4,
MinDepthMeters: 0.15f,
MaxDepthMeters: 4.0f)
],
};
}
}