diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index d1ed06a..9c215a3 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -41,6 +41,11 @@ The research ledger is That note is not a dependency grant: CUDA implementations, TensorRT ports, and monocular model demos are provenance only. The live owner is Fensalir D3D12 compute over Mimir-declared texture resources and calibration state. +The first contract slice now exists in `MimirStereoDepthConfigurations` and +`MimirFensalirFieldLowering.BuildStereoDepthCandidateFrame`: a calibrated +stereo pair profile emits a GPU-resident R16F disparity `SurfacePage`, an R8 +confidence texture, and a Height FieldEvidence claim planned to the +`SurfacePage` backend. This is the socket for the kernel, not the kernel. Those claims are not inherently pixel-sized. Pixel-level resolve consumes the reservoir, but claim support is chosen from the represented field. Smooth @@ -298,6 +303,11 @@ a named invariant that the native runtime cannot protect yet. D3D12 handle and accepts Mimir video format names. `Mimir.BufferSmoke --fensalir-camera-observation-smoke` verifies the split, and `--fensalir-texture-lease-smoke` verifies the engine-owned lease path. + `Mimir.BufferSmoke --stereo-depth-contract-smoke` verifies the next visual + socket: libSGM-provenance D3D12 SGM is represented as a non-dependency + profile, and synthetic rectified Leap stereo depth lowers to one planned + `SurfacePage` packet with no CUDA, CPU disparity image, or monocular metric + authority. - Mimir's active proof path no longer uses the direct `AquariumAcousticFieldFrame` builder either. Sync states lower into FieldEvidence calibration constraints through `MapCalibrationConstraints`, @@ -527,7 +537,9 @@ a named invariant that the native runtime cannot protect yet. lane over rectified synchronized camera texture pairs, emitting GPU-resident disparity/depth/confidence resources and FieldEvidence claims. Keep `libSGM` as provenance for algorithm shape and benchmark pressure, not - as imported CUDA authority. + as imported CUDA authority. The typed contract and smoke exist; the next cut + is the actual HLSL/D3D12 cost-volume and SGM aggregation kernel behind that + contract. 9. Move mic alignment, room suppression, voice separation, spatialization, and stem generation into Faust/native DSP. 10. Keep the OBS bridge witness ledger as evidence before expanding receiver diff --git a/docs/perfect-machine-domain-index.md b/docs/perfect-machine-domain-index.md index b4a822c..c003fbd 100644 --- a/docs/perfect-machine-domain-index.md +++ b/docs/perfect-machine-domain-index.md @@ -176,6 +176,11 @@ Likely shape: permissive SGM provenance, especially `libSGM`: rectified texture pairs plus calibration produce GPU-resident disparity/depth/confidence resources, which then lower into FieldEvidence claims. +- Current contract proof: + `Mimir.BufferSmoke --stereo-depth-contract-smoke` validates the profile and + FieldEvidence socket. The synthetic Leap stereo pair produces an R16F + disparity `SurfacePage`, an R8 confidence `Texture2D`, one Height claim, and + one planned `SurfacePage` packet. It is not yet a live compute kernel. - Native reservoir preserves rolling evidence. - Fusion emits surface/material/render claims. - Program video publishes via Spout2. @@ -265,7 +270,8 @@ Six optical sensors with high-rate Eyes and Leap IR mean: 4. Fractional delay/SRO actuator proof. 5. Direct Leap/PS3/Kiyo runtime drivers. 6. D3D12 stereo disparity/depth compute lane, with `libSGM` as provenance and - Fensalir as live owner. + Fensalir as live owner. Contract/profile smoke exists; implement the HLSL + cost-volume, aggregation, winner/subpixel, and confidence passes next. 7. Native reservoir integration with Fensalir/Faust. 8. Raven/phone receiver codebook/schedule local decode. 9. GPU visual fusion and Spout2 program video. diff --git a/docs/perfect-machine-module-library.md b/docs/perfect-machine-module-library.md index fd0e44d..da88999 100644 --- a/docs/perfect-machine-module-library.md +++ b/docs/perfect-machine-module-library.md @@ -19,6 +19,7 @@ job-interview answer for why it belongs in the body of the machine. | Benchmark panels | `Mimir.Runtime` | Decoder golf and meatspace acceptance degradation panels with receipt roots and thresholds. | `src/Mimir.Runtime/Synchronization/MimirBenchmarkPanelConfiguration.cs` | | Capture profiles | `Mimir.Runtime` + native workers | Hardware intent for Leap, Kiyos, PS Eyes, Starfire Scarlett, and Raven Scarlett. | `src/Mimir.Runtime/Synchronization/MimirNativeCaptureConfiguration.cs` | | Camera ingest strategies | `Mimir.Runtime` + native workers | Diagnostic metadata, managed native wrapper, native SPSC ring, and shared-GPU-texture ingest shapes. | `src/Mimir.Runtime/Synchronization/MimirCameraIngestConfiguration.cs` | +| Stereo depth profiles | `Mimir.Runtime` + Fensalir | SGM-shaped stereo disparity/depth profiles with libSGM as provenance for the first D3D12 lane, not a CUDA dependency. | `src/Mimir.Runtime/Synchronization/MimirStereoDepthConfiguration.cs` | | Reservoir strategies | `Mimir.Runtime` + native reservoir + Fensalir | Managed rolling buffers, native shared-edge rings, and derived GPU temporal field storage. | `src/Mimir.Runtime/Synchronization/MimirReservoirConfiguration.cs` | | Distributed witnesses | `Mimir.Runtime` + CultMesh | Raven, phone, microcontroller, and remote camera rig configurations for compact timing/path state. | `src/Mimir.Runtime/Synchronization/MimirDistributedWitnessConfiguration.cs` | | Network transports | `Mimir.Runtime` + CultMesh | Typed timing state, debug windows, SRT bridge media, and experimental browser transport policy plus constraint-based selection. | `src/Mimir.Runtime/Synchronization/MimirNetworkTransportConfiguration.cs`, `src/Mimir.Runtime/Synchronization/MimirNetworkTransportSelector.cs` | @@ -28,7 +29,7 @@ job-interview answer for why it belongs in the body of the machine. | Compute offload configurations | `Mimir.Runtime` + CultMesh | Local-heavy, distributed witness, and calibration sweep workload placement. | `src/Mimir.Runtime/Synchronization/MimirComputeOffloadConfiguration.cs` | | Assembly plans | `Mimir.Runtime` | Named combinations of modules that prove synthetic, Scarlett, meatspace, and distributed cuts. | `src/Mimir.Runtime/Synchronization/MimirMachineAssemblyPlan.cs` | | OBS publication profiles | Fensalir + Faust + OBS | Spout/shared-texture video and separately mixable Faust stem publication. | `src/Mimir.Runtime/Synchronization/MimirObsPublicationConfiguration.cs` | -| Fensalir lowering | `Mimir.Runtime` -> Fensalir | Pure mapping from Mimir rolling/video/audio state into Fensalir GPU sensor and acoustic field frames. | `src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs` | +| Fensalir lowering | `Mimir.Runtime` -> Fensalir | Pure mapping from Mimir rolling/video/audio state into Fensalir GPU sensor, stereo-depth, and acoustic field frames. | `src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs` | | Module catalog | `Mimir.Runtime` | Indexes the live module set and verification commands. | `src/Mimir.Runtime/Synchronization/MimirModuleLibrary.cs` | | Manifest factory | `Mimir.Runtime` | Produces an exportable JSON manifest for tools, docs, UI, and remote witnesses. | `src/Mimir.Runtime/Synchronization/MimirPerfectMachineManifest.cs` | diff --git a/notes/current-system-map.md b/notes/current-system-map.md index 6cbac34..f5d7590 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -396,6 +396,12 @@ current permissive north-star reference: Mimir/Fensalir should rebuild the SGM shape over synchronized rectified texture pairs, calibration state, typed GPU resources, and explicit fences. CUDA, TensorRT, and monocular depth demos remain research references only. +The first live contract exists: `MimirStereoDepthConfigurations` names the +libSGM-provenance D3D12 SGM profile, and +`MimirFensalirFieldLowering.BuildStereoDepthCandidateFrame` lowers a synthetic +rectified stereo result into GPU-resident disparity/confidence resources plus a +Height FieldEvidence claim planned as a `SurfacePage` packet. The kernel itself +is still future work. Fensalir must not be treated as a traditional rendering pipeline. Mimir does not ask it to "draw a thing" and hope post-processing makes the result true. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 4fcd851..40aaffd 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -83,6 +83,11 @@ Get-Content .\state\evidence.jsonl -Tail 8 Provenance]]. `libSGM` is the current permissive north-star reference for a future Fensalir-owned D3D12 stereo SGM compute lane. Do not import CUDA or TensorRT as live depth authority. + The first code contract is in `MimirStereoDepthConfigurations` and + `MimirFensalirFieldLowering.BuildStereoDepthCandidateFrame`; run + `dotnet run --project .\src\Mimir.BufferSmoke\Mimir.BufferSmoke.csproj -- --stereo-depth-contract-smoke` + to verify the synthetic R16F disparity `SurfacePage` FieldEvidence socket. + This proves the lane shape, not the SGM kernel. - Fensalir also owns the EVE-facing dashboard pixels through `Global\MimirFensalirProgramTexture`. `src/Mimir.EveRelay` opens that shared texture, encodes H.264 Annex-B with NVENC by default, and serves EveCanvas diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 193361a..94a7fa8 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -139,6 +139,11 @@ if (args.Any(arg => string.Equals(arg, "--fensalir-texture-lease-smoke", StringC return RunFensalirTextureLeaseSmoke(); } +if (args.Any(arg => string.Equals(arg, "--stereo-depth-contract-smoke", StringComparison.OrdinalIgnoreCase))) +{ + return RunStereoDepthContractSmoke(); +} + if (args.Any(arg => string.Equals(arg, "--ks-camera-driver-smoke", StringComparison.OrdinalIgnoreCase))) { return RunKsCameraDriverSmoke(args); @@ -2218,12 +2223,81 @@ static MimirRollingStreamBuffer BuildSyntheticAudioBuffer(string sourceId, int s return buffer; } +static AquariumFieldEvidenceFrame BuildSyntheticStereoDepthFrame(MimirFensalirFieldLowering lowerer) +{ + var profile = MimirStereoDepthConfigurations.D3D12SgmLibSgmProvenance; + return lowerer.BuildStereoDepthCandidateFrame( + [ + new MimirStereoDepthFieldCandidate( + CandidateKey: "synthetic-leap-plane", + CalibrationId: "synthetic-rectified-leap-calibration", + CameraPairId: "leap-stereo-ir", + ProducerKey: profile.Id, + ProfileId: profile.Id, + LeftObservationKey: "leap-left-ir:1", + RightObservationKey: "leap-right-ir:1", + LeftResourceKey: "mimir:resource:texture2d:leap-left-ir", + RightResourceKey: "mimir:resource:texture2d:leap-right-ir", + DisparityResourceKey: "mimir:resource:stereo-depth:leap-disparity-r16f", + ConfidenceResourceKey: "mimir:resource:stereo-depth:leap-confidence-r8", + Width: 640, + Height: 240, + DisparityLevels: profile.DisparityLevels, + AggregationPathCount: profile.AggregationPathCount, + MinDepthMeters: 0.20, + MaxDepthMeters: 4.0, + Confidence: 0.93, + ObservedTimeNs: 1_000_000_000L) + ]); +} + +static int RunStereoDepthContractSmoke() +{ + var profile = MimirStereoDepthConfigurations.D3D12SgmLibSgmProvenance; + var frame = BuildSyntheticStereoDepthFrame(new MimirFensalirFieldLowering()); + var validation = AquariumFieldEvidenceValidator.Validate(frame); + var plan = AquariumFieldLoweringPlanner.Plan(frame); + var claim = frame.Claims.FirstOrDefault(); + var disparity = frame.Resources.FirstOrDefault(resource => resource.ResourceKey == "mimir:resource:stereo-depth:leap-disparity-r16f"); + var confidence = frame.Resources.FirstOrDefault(resource => resource.ResourceKey == "mimir:resource:stereo-depth:leap-confidence-r8"); + + Console.WriteLine( + $"stereo-depth-contract profile={profile.Id} provenance={profile.Provenance} liveDependency={profile.LiveDependency} disparityLevels={profile.DisparityLevels} paths={profile.AggregationPathCount}"); + Console.WriteLine( + $"stereo-depth-field resources={frame.Resources.Count} claims={frame.Claims.Count} planned={plan.Packets.Count} deferred={plan.DeferredRequests.Count} errors={validation.HasErrors}"); + Console.WriteLine( + $"stereo-depth-output disparity={disparity.ResourceKey} kind={disparity.Kind} format={disparity.Format} confidence={confidence.ResourceKey} confidenceFormat={confidence.Format} backend={(plan.Packets.Count > 0 ? plan.Packets[0].Backend : AquariumFieldBackendKind.Unknown)}"); + + return !validation.HasErrors && + !profile.LiveDependency && + profile.Algorithm == MimirStereoDepthAlgorithm.SemiGlobalMatching && + profile.License == "Apache-2.0" && + profile.RequiresRectifiedInputs && + profile.RequiresCalibration && + profile.NegativeChecks.Any(check => check.Contains("no CUDA", StringComparison.OrdinalIgnoreCase)) && + frame.Resources.Count == 2 && + disparity.Kind == AquariumFieldResourceKind.SurfacePage && + disparity.Residency == AquariumFieldResourceResidency.GpuResident && + disparity.Format == "R16Float" && + confidence.Kind == AquariumFieldResourceKind.Texture2D && + confidence.Format == "R8_UNorm" && + claim.Encoding == AquariumFieldEncoding.Height && + claim.PayloadHandle == disparity.ResourceKey && + claim.ProducerKey == profile.Id && + plan.Packets.Count == 1 && + plan.Packets[0].Backend == AquariumFieldBackendKind.SurfacePage && + plan.DeferredRequests.Count == 0 + ? 0 + : 1; +} + static int RunPerfectMachineProfileSmoke() { var profiles = MimirPerfectMachineProfiles.All; var calibrationPlans = MimirCalibrationSessionPlans.BuiltIn; var audioFields = MimirAudioFieldConfigurations.BuiltIn; var visualFields = MimirVisualFusionConfigurations.BuiltIn; + var stereoDepthProfiles = MimirStereoDepthConfigurations.BuiltIn; var computePlans = MimirComputeOffloadConfigurations.BuiltIn; var assemblyPlans = MimirMachineAssemblyPlans.BuiltIn; var captureProfiles = MimirNativeCaptureConfigurations.BuiltIn; @@ -2353,6 +2427,8 @@ static int RunPerfectMachineProfileSmoke() 1_000_000_000L) ]); var visualMarkerPlan = AquariumFieldLoweringPlanner.Plan(visualMarkerFrame); + var stereoDepthFrame = BuildSyntheticStereoDepthFrame(lowerer); + var stereoDepthPlan = AquariumFieldLoweringPlanner.Plan(stereoDepthFrame); var authority = new MimirAuthorityPolicyEvaluator().Evaluate(new MimirAuthorityEvaluationInput( "raven-scarlett-witness", new HashSet(["known-node", "matching-codebook", "clock-fit-confidence", "response-profile"], StringComparer.Ordinal), @@ -2368,7 +2444,7 @@ static int RunPerfectMachineProfileSmoke() new HashSet(StringComparer.Ordinal))); Console.WriteLine( - $"perfect-machine-profile-smoke profiles={profiles.Count} calibrationPlans={calibrationPlans.Count} audioFields={audioFields.Count} visualFields={visualFields.Count} computePlans={computePlans.Count} assemblyPlans={assemblyPlans.Count} captureProfiles={captureProfiles.Count} publications={publications.Count} languageProfiles={languageProfiles.Count} pathLearning={pathLearningProfiles.Count} localization={localizationProfiles.Count} benchmarkPanels={benchmarkPanels.Count} actuatorStrategies={actuatorStrategies.Count} cameraIngest={cameraIngestStrategies.Count} reservoirs={reservoirStrategies.Count} distributedWitnesses={distributedWitnesses.Count} networkTransports={networkTransports.Count} authorityPolicies={authorityPolicies.Count} modules={moduleCatalog.Count}"); + $"perfect-machine-profile-smoke profiles={profiles.Count} calibrationPlans={calibrationPlans.Count} audioFields={audioFields.Count} visualFields={visualFields.Count} stereoDepth={stereoDepthProfiles.Count} computePlans={computePlans.Count} assemblyPlans={assemblyPlans.Count} captureProfiles={captureProfiles.Count} publications={publications.Count} languageProfiles={languageProfiles.Count} pathLearning={pathLearningProfiles.Count} localization={localizationProfiles.Count} benchmarkPanels={benchmarkPanels.Count} actuatorStrategies={actuatorStrategies.Count} cameraIngest={cameraIngestStrategies.Count} reservoirs={reservoirStrategies.Count} distributedWitnesses={distributedWitnesses.Count} networkTransports={networkTransports.Count} authorityPolicies={authorityPolicies.Count} modules={moduleCatalog.Count}"); Console.WriteLine( $"perfect-machine-codebook id={codebook.CodebookId} motifs={codebook.Motifs.Length} decoder={decoder.Configuration.Id} augmentations={decoder.Configuration.TemplateAugmentations.Length}"); Console.WriteLine( @@ -2381,6 +2457,8 @@ static int RunPerfectMachineProfileSmoke() $"perfect-machine-localization candidates={localizationGrid.Count} best=({localization?.PositionMeters.X ?? float.NaN:0.000},{localization?.PositionMeters.Y ?? float.NaN:0.000},{localization?.PositionMeters.Z ?? float.NaN:0.000}) score={localization?.Score ?? 0.0:0.000} sourceClaims={acousticSourceFrame.Claims.Count} sourcePlanned={acousticSourcePlan.Packets.Count} sourceDeferred={acousticSourcePlan.DeferredRequests.Count}"); Console.WriteLine( $"perfect-machine-visual-marker claims={visualMarkerFrame.Claims.Count} planned={visualMarkerPlan.Packets.Count} deferred={visualMarkerPlan.DeferredRequests.Count}"); + Console.WriteLine( + $"perfect-machine-stereo-depth profiles={stereoDepthProfiles.Count} resources={stereoDepthFrame.Resources.Count} claims={stereoDepthFrame.Claims.Count} planned={stereoDepthPlan.Packets.Count} deferred={stereoDepthPlan.DeferredRequests.Count}"); Console.WriteLine( $"perfect-machine-authority appliesTo=raven-scarlett-witness decision={authority.Decision} rule={authority.RuleId}"); Console.WriteLine( @@ -2390,6 +2468,7 @@ static int RunPerfectMachineProfileSmoke() calibrationPlans.Count >= 3 && audioFields.Count >= 4 && visualFields.Count >= 4 && + stereoDepthProfiles.Count >= 3 && computePlans.Count >= 3 && assemblyPlans.Count >= 4 && captureProfiles.Count >= 8 && @@ -2425,6 +2504,12 @@ static int RunPerfectMachineProfileSmoke() visualMarkerPlan.DeferredRequests.Count == 0 && visualMarkerFrame.Claims[0].ClaimKey.Contains("synthetic-camera-rig-calibration", StringComparison.Ordinal) && visualMarkerFrame.Claims[0].ClaimKey.Contains("synthetic-marker-a", StringComparison.Ordinal) && + stereoDepthFrame.Resources.Count == 2 && + stereoDepthFrame.Claims.Count == 1 && + stereoDepthPlan.Packets.Count == 1 && + stereoDepthPlan.Packets[0].Backend == AquariumFieldBackendKind.SurfacePage && + stereoDepthPlan.DeferredRequests.Count == 0 && + stereoDepthProfiles.Any(profile => profile.Id == MimirStereoDepthConfigurations.D3D12SgmLibSgmProvenance.Id && !profile.LiveDependency) && localization is { Score: > 0.90 } && authority.Decision == MimirAuthorityDecision.TrustedEvidence && transport.Transport?.Id == MimirNetworkTransportConfigurations.CultMeshTimingState.Id && diff --git a/src/Mimir.Runtime/Synchronization/MimirComputeOffloadConfiguration.cs b/src/Mimir.Runtime/Synchronization/MimirComputeOffloadConfiguration.cs index 5b63587..4f9a30b 100644 --- a/src/Mimir.Runtime/Synchronization/MimirComputeOffloadConfiguration.cs +++ b/src/Mimir.Runtime/Synchronization/MimirComputeOffloadConfiguration.cs @@ -10,6 +10,7 @@ public enum MimirWorkloadKind FaustDsp, CameraCapture, VisualFeatureExtraction, + StereoDepthEstimation, VisualFusion, ObsPublication } @@ -41,6 +42,7 @@ public static class MimirComputeOffloadConfigurations new(MimirWorkloadKind.FaustDsp, MimirComputeBackend.FaustNativeDsp, "Faust/native DSP", CanRunRemote: false, RequiresRealtime: true, "Alignment, separation, and spatial bed are audio-rate DSP."), new(MimirWorkloadKind.CameraCapture, MimirComputeBackend.NativeSimd, "native capture workers", CanRunRemote: true, RequiresRealtime: true, "Drivers own device reads and timestamps."), new(MimirWorkloadKind.VisualFeatureExtraction, MimirComputeBackend.D3D12Compute, "Fensalir", CanRunRemote: false, RequiresRealtime: true, "GPU owns dense feature work."), + new(MimirWorkloadKind.StereoDepthEstimation, MimirComputeBackend.D3D12Compute, "Fensalir", CanRunRemote: false, RequiresRealtime: true, "Calibrated stereo depth derives from synchronized texture resources and never from CPU readback."), new(MimirWorkloadKind.VisualFusion, MimirComputeBackend.D3D12Compute, "Fensalir", CanRunRemote: false, RequiresRealtime: true, "Fensalir owns temporal evidence field."), new(MimirWorkloadKind.ObsPublication, MimirComputeBackend.D3D12Compute, "OBS/Fensalir output", CanRunRemote: false, RequiresRealtime: true, "OBS receives program surfaces, not sync authority.") ]); @@ -63,7 +65,8 @@ public static class MimirComputeOffloadConfigurations new(MimirWorkloadKind.BioacousticDecode, MimirComputeBackend.NativeSimd, "calibration worker", CanRunRemote: true, RequiresRealtime: false, "Large candidate batches can use native SIMD."), new(MimirWorkloadKind.PathCalibration, MimirComputeBackend.D3D12Compute, "calibration worker", CanRunRemote: true, RequiresRealtime: false, "GPU is useful when batches are large enough."), new(MimirWorkloadKind.ClockHypothesis, MimirComputeBackend.ManagedScalar, "calibration worker", CanRunRemote: true, RequiresRealtime: false, "Clock solve stays branchy and inspectable."), - new(MimirWorkloadKind.VisualFeatureExtraction, MimirComputeBackend.D3D12Compute, "Fensalir/calibration worker", CanRunRemote: true, RequiresRealtime: false, "Offline feature batches may run away from the render tick.") + new(MimirWorkloadKind.VisualFeatureExtraction, MimirComputeBackend.D3D12Compute, "Fensalir/calibration worker", CanRunRemote: true, RequiresRealtime: false, "Offline feature batches may run away from the render tick."), + new(MimirWorkloadKind.StereoDepthEstimation, MimirComputeBackend.D3D12Compute, "Fensalir/calibration worker", CanRunRemote: true, RequiresRealtime: false, "Stereo kernels can replay calibration captures, but their output remains derived evidence.") ]); public static IReadOnlyList BuiltIn { get; } = diff --git a/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs b/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs index e8b557b..b60be01 100644 --- a/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs +++ b/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs @@ -180,6 +180,45 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt }; } + public AquariumFieldEvidenceFrame BuildStereoDepthCandidateFrame( + IEnumerable depthCandidates) + { + var domains = new List(); + var claims = new List(); + var candidates = new List(); + var resources = new List(); + var seenDomains = new HashSet(StringComparer.Ordinal); + var seenResources = new HashSet(StringComparer.Ordinal); + + foreach (var depthCandidate in depthCandidates) + { + if (string.IsNullOrWhiteSpace(depthCandidate.CandidateKey) || + string.IsNullOrWhiteSpace(depthCandidate.DisparityResourceKey)) + { + continue; + } + + var domain = DomainForStereoDepthCandidate(depthCandidate); + AddDomain(domains, seenDomains, domain); + AddResource(resources, seenResources, DisparityResourceForStereoDepthCandidate(depthCandidate)); + AddResource(resources, seenResources, ConfidenceResourceForStereoDepthCandidate(depthCandidate)); + + var claim = ClaimForStereoDepthCandidate(depthCandidate, domain.DomainKey); + claims.Add(claim); + candidates.Add(CandidateForClaim(claim, AquariumFieldGuide.Valid(claim.Confidence))); + } + + return new AquariumFieldEvidenceFrame + { + Domains = domains, + Claims = claims, + Candidates = candidates, + Resources = resources, + AccumulationWindowSeconds = (float)options.AccumulationWindowSeconds, + PresentationDelaySeconds = (float)options.PresentationDelaySeconds + }; + } + private static void AddDomain( ICollection domains, ISet seenDomains, @@ -354,6 +393,24 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt "Mimir.Runtime"); } + private static AquariumFieldDomain DomainForStereoDepthCandidate(MimirStereoDepthFieldCandidate candidate) + { + var width = Math.Max(1, candidate.Width); + var height = Math.Max(1, candidate.Height); + var maxDepth = Math.Max(candidate.MinDepthMeters, candidate.MaxDepthMeters); + var depthExtent = Math.Max(0.001f, (float)maxDepth); + return new AquariumFieldDomain( + DomainKeyForStereoDepthCandidate(candidate), + "", + AquariumFieldDomainKind.Surface2D, + Matrix4x4.Identity, + Matrix4x4.Identity, + Vector3.Zero, + new Vector3(width, height, depthExtent), + Vector3.Zero, + "Fensalir D3D12 compute"); + } + private static AquariumFieldDomain DomainForSurfaceIntent(MimirSurfaceIntent intent) => new( DomainKeyForSurfaceIntent(intent.IntentKey), @@ -462,6 +519,32 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt Confidence: confidence); } + private AquariumFieldClaim ClaimForStereoDepthCandidate( + MimirStereoDepthFieldCandidate depthCandidate, + string domainKey) + { + var confidence = Clamp01((float)depthCandidate.Confidence); + var represented = Math.Max(1, depthCandidate.Width * depthCandidate.Height); + var proposal = new AquariumFieldProposalPolicy( + AquariumFieldProposalKind.DeterministicStructural, + SourcePdf: 1.0f, + TargetContribution: confidence, + RepresentedCandidateCount: represented, + Seed: StableSeed(depthCandidate.CandidateKey)); + + return new AquariumFieldClaim( + ClaimKey: $"stereo-depth:{depthCandidate.CalibrationId}:{depthCandidate.CameraPairId}:{depthCandidate.CandidateKey}", + DomainKey: domainKey, + ProducerKey: depthCandidate.ProducerKey, + Layer: AquariumFieldLayer.Form, + Encoding: AquariumFieldEncoding.Height, + Support: SupportForStereoDepthCandidate(depthCandidate), + Proposal: proposal, + PayloadHandle: depthCandidate.DisparityResourceKey, + ObservedTimeNs: depthCandidate.ObservedTimeNs, + Confidence: confidence); + } + private AquariumFieldClaim ClaimForSurfaceIntent( MimirSurfaceIntent intent, string domainKey, @@ -603,6 +686,57 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt TemporalUncertainty: 0.0f); } + private AquariumFieldSupport SupportForStereoDepthCandidate(MimirStereoDepthFieldCandidate depthCandidate) + { + var width = Math.Max(1.0f, depthCandidate.Width); + var height = Math.Max(1.0f, depthCandidate.Height); + var depthRange = Math.Max(0.001f, (float)(depthCandidate.MaxDepthMeters - depthCandidate.MinDepthMeters)); + return new AquariumFieldSupport( + Center: new Vector3(width * 0.5f, height * 0.5f, depthRange * 0.5f), + Radius: new Vector3(width * 0.5f, height * 0.5f, depthRange * 0.5f), + LocalFrame: Matrix4x4.Identity, + ConservativeRadius: MathF.Max(width, height) * 0.5f, + ProjectedError: 1.0f / Math.Max(1, depthCandidate.DisparityLevels), + Curvature: 0.0f, + TemporalUncertainty: 0.0f); + } + + private static AquariumFieldResourceDeclaration DisparityResourceForStereoDepthCandidate( + MimirStereoDepthFieldCandidate depthCandidate) => + AquariumFieldResourceDeclaration.SurfacePage( + depthCandidate.DisparityResourceKey, + Math.Max(1, depthCandidate.Width), + Math.Max(1, depthCandidate.Height), + format: "R16Float", + version: checked((ulong)Math.Max(0L, depthCandidate.ObservedTimeNs)), + validFromNs: depthCandidate.ObservedTimeNs, + validUntilNs: depthCandidate.ObservedTimeNs); + + private static AquariumFieldResourceDeclaration ConfidenceResourceForStereoDepthCandidate( + MimirStereoDepthFieldCandidate depthCandidate) + { + if (string.IsNullOrWhiteSpace(depthCandidate.ConfidenceResourceKey)) + { + return default; + } + + return new AquariumFieldResourceDeclaration( + ResourceKey: depthCandidate.ConfidenceResourceKey, + Kind: AquariumFieldResourceKind.Texture2D, + Residency: AquariumFieldResourceResidency.GpuResident, + Access: AquariumFieldShaderAccess.ShaderResource, + Format: "R8_UNorm", + Width: Math.Max(1, depthCandidate.Width), + Height: Math.Max(1, depthCandidate.Height), + DepthOrCount: 1, + StrideBytes: 1, + ValidFromNs: depthCandidate.ObservedTimeNs, + ValidUntilNs: depthCandidate.ObservedTimeNs, + Version: checked((ulong)Math.Max(0L, depthCandidate.ObservedTimeNs)), + NativeHandle: IntPtr.Zero, + NativeHandleKind: "fensalir-stereo-depth-confidence"); + } + private AquariumFieldSupport SupportForSurfaceIntent(MimirSurfaceIntent intent) { var age = Math.Max(0.0f, (float)intent.SupportPolicy.MaximumAgeSeconds); @@ -772,6 +906,9 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt private static string DomainKeyForVisualMarkerCandidate(MimirVisualMarkerFieldCandidate candidate) => $"mimir:visual-marker:{candidate.CalibrationId}:{candidate.MarkerId}:{candidate.CandidateKey}"; + private static string DomainKeyForStereoDepthCandidate(MimirStereoDepthFieldCandidate candidate) => + $"mimir:stereo-depth:{candidate.CalibrationId}:{candidate.CameraPairId}:{candidate.CandidateKey}"; + private static string DomainKeyForSurfaceIntent(string intentKey) => $"mimir:intent:{intentKey}"; private static float Clamp01(float value) => Math.Clamp(value, 0.0f, 1.0f); diff --git a/src/Mimir.Runtime/Synchronization/MimirModuleLibrary.cs b/src/Mimir.Runtime/Synchronization/MimirModuleLibrary.cs index d016807..6ac08fe 100644 --- a/src/Mimir.Runtime/Synchronization/MimirModuleLibrary.cs +++ b/src/Mimir.Runtime/Synchronization/MimirModuleLibrary.cs @@ -80,6 +80,12 @@ public static class MimirModuleLibrary "Ingest configurations for diagnostic metadata, managed native wrappers, native SPSC rings, and shared GPU textures.", MimirCameraIngestConfigurations.BuiltIn.Select(profile => profile.Id).ToArray(), ["dotnet run --project .\\src\\Mimir.BufferSmoke\\Mimir.BufferSmoke.csproj -- --perfect-machine-profile-smoke"]), + new( + "stereo-depth", + "Fensalir D3D12 compute", + "SGM-shaped stereo disparity/depth profiles. libSGM is provenance for the first D3D12 lane, not a CUDA dependency.", + MimirStereoDepthConfigurations.BuiltIn.Select(profile => profile.Id).ToArray(), + ["dotnet run --project .\\src\\Mimir.BufferSmoke\\Mimir.BufferSmoke.csproj -- --stereo-depth-contract-smoke"]), new( "reservoir-strategies", "Mimir.Runtime + native/reservoir + Fensalir", diff --git a/src/Mimir.Runtime/Synchronization/MimirStereoDepthConfiguration.cs b/src/Mimir.Runtime/Synchronization/MimirStereoDepthConfiguration.cs new file mode 100644 index 0000000..6b6fcb9 --- /dev/null +++ b/src/Mimir.Runtime/Synchronization/MimirStereoDepthConfiguration.cs @@ -0,0 +1,116 @@ +namespace Mimir.Runtime.Synchronization; + +public enum MimirStereoDepthAlgorithm +{ + SemiGlobalMatching, + LearnedStereoReference, + MonocularReference +} + +public enum MimirStereoDepthOutputKind +{ + DisparitySurfacePage, + MetricDepthSurfacePage, + ConfidenceTexture +} + +public sealed record MimirStereoDepthKernelProfile( + string Id, + string Description, + MimirStereoDepthAlgorithm Algorithm, + string Owner, + string Provenance, + string License, + bool LiveDependency, + int DisparityLevels, + int AggregationPathCount, + bool RequiresRectifiedInputs, + bool RequiresCalibration, + string[] RequiredInputResources, + string[] OutputResources, + string[] NegativeChecks); + +public sealed record MimirStereoDepthFieldCandidate( + string CandidateKey, + string CalibrationId, + string CameraPairId, + string ProducerKey, + string ProfileId, + string LeftObservationKey, + string RightObservationKey, + string LeftResourceKey, + string RightResourceKey, + string DisparityResourceKey, + string ConfidenceResourceKey, + int Width, + int Height, + int DisparityLevels, + int AggregationPathCount, + double MinDepthMeters, + double MaxDepthMeters, + double Confidence, + long ObservedTimeNs); + +public static class MimirStereoDepthConfigurations +{ + public static MimirStereoDepthKernelProfile D3D12SgmLibSgmProvenance { get; } = new( + "d3d12-sgm-libsgm-provenance", + "Fensalir-owned HLSL/D3D12 stereo SGM lane modeled on libSGM's CUDA pipeline shape.", + MimirStereoDepthAlgorithm.SemiGlobalMatching, + "Fensalir D3D12 compute", + "https://github.com/fixstars/libSGM", + "Apache-2.0", + LiveDependency: false, + DisparityLevels: 128, + AggregationPathCount: 4, + RequiresRectifiedInputs: true, + RequiresCalibration: true, + RequiredInputResources: ["left Texture2D", "right Texture2D", "stereo calibration"], + OutputResources: ["R16Float disparity SurfacePage", "R8_UNorm confidence Texture2D"], + NegativeChecks: + [ + "no CUDA runtime dependency", + "no CPU disparity image in the live path", + "no monocular model accepted as metric depth without scale authority", + "no untyped texture handle without resource and fence provenance" + ]); + + public static MimirStereoDepthKernelProfile FastAcvNetReference { get; } = new( + "fast-acvnet-reference", + "MIT learned-stereo reference for quality/failure comparison; not the first live kernel.", + MimirStereoDepthAlgorithm.LearnedStereoReference, + "research/provenance", + "https://github.com/gangweiX/Fast-ACVNet", + "MIT", + LiveDependency: false, + DisparityLevels: 192, + AggregationPathCount: 0, + RequiresRectifiedInputs: true, + RequiresCalibration: true, + RequiredInputResources: ["left Texture2D", "right Texture2D", "model weights"], + OutputResources: ["learned disparity/depth reference"], + NegativeChecks: ["does not own live geometry", "does not introduce model runtime before D3D12 SGM socket exists"]); + + public static MimirStereoDepthKernelProfile DepthAnythingSmallReference { get; } = new( + "depth-anything-v2-small-reference", + "Apache-2.0 monocular relative-depth reference for assistive evidence only.", + MimirStereoDepthAlgorithm.MonocularReference, + "research/provenance", + "https://github.com/DepthAnything/Depth-Anything-V2", + "Apache-2.0 for V2 Small only; larger variants are non-commercial", + LiveDependency: false, + DisparityLevels: 0, + AggregationPathCount: 0, + RequiresRectifiedInputs: false, + RequiresCalibration: false, + RequiredInputResources: ["single camera Texture2D", "model weights"], + OutputResources: ["relative depth reference"], + NegativeChecks: ["does not own metric scene geometry", "does not bypass calibrated stereo"]); + + public static IReadOnlyList BuiltIn { get; } = + [ + D3D12SgmLibSgmProvenance, + FastAcvNetReference, + DepthAnythingSmallReference + ]; +} diff --git a/src/Mimir.Runtime/Synchronization/MimirVisualFusionConfiguration.cs b/src/Mimir.Runtime/Synchronization/MimirVisualFusionConfiguration.cs index 8488f6e..62e3ae0 100644 --- a/src/Mimir.Runtime/Synchronization/MimirVisualFusionConfiguration.cs +++ b/src/Mimir.Runtime/Synchronization/MimirVisualFusionConfiguration.cs @@ -14,6 +14,7 @@ public enum MimirVisualFusionModel { TimestampedFramesOnly, SparseFeatureTracks, + StereoSgmDepth, VisualConstrainedAudioField, TemporalGaussianClaims, FullHybridEvidenceField @@ -58,6 +59,15 @@ public static class MimirVisualFusionConfigurations PublishesSpout: false, UsesAudioConstraints: false); + public static MimirVisualFusionConfiguration StereoSgmDepth { get; } = new( + "stereo-sgm-depth", + "Rectified synchronized stereo texture pairs lower through a Fensalir-owned D3D12 SGM depth lane.", + MimirVisualFusionModel.StereoSgmDepth, + CreateDefaultSensors(), + RequiresFensalirD3D12: true, + PublishesSpout: false, + UsesAudioConstraints: false); + public static MimirVisualFusionConfiguration AudioConstrainedField { get; } = new( "audio-constrained-field", "Visual feature tracks constrain acoustic source hypotheses before Fensalir stabilizes field claims.", @@ -80,6 +90,7 @@ public static class MimirVisualFusionConfigurations [ CadenceProof, TrackingFusion, + StereoSgmDepth, AudioConstrainedField, FullHybridEvidence ]; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 737fd5f..9262bad 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -229,3 +229,4 @@ {"ts": "2026-05-29T22:23:04+01:00", "type": "decision", "status": "ok", "note": "Raven display/audio sync uses shared clock-domain correction: Raven display frames can be tagged raven-sync, while Raven audio routed into Scarlett earns the timing offset applied by MimirSynchronizedBufferPlanner; network arrival timestamps remain metadata."} {"ts": "2026-05-29T23:50:56+01:00", "type": "decision", "status": "ok", "note": "Fast stereo depth is mapped as a future Fensalir-owned D3D12 compute lane, with libSGM as permissive SGM provenance rather than a CUDA dependency. External TensorRT/monocular depth projects remain reference evidence only; live depth must consume Mimir-declared texture resources, calibration, and fences, then emit GPU disparity/depth/confidence resources and FieldEvidence claims."} {"ts": "2026-05-29T23:52:11+01:00", "type": "decision", "status": "ok", "note": "Mimir Program panel now owns Fensalir presentation intent: video visibility/solo/opacity/layer filters production surface intents, audio mute/solo/gain feeds Faust controls and streaming samples, and LUT presets are typed postprocess state with exposure/bloom mapped to current GraphicsSettings until renderer LUT sampling lands."} +{"ts": "2026-05-30T00:21:36+01:00", "type": "implementation", "status": "ok", "note": "Added the first stereo-depth contract slice: MimirStereoDepthConfigurations names a non-dependency libSGM-provenance D3D12 SGM profile, compute/visual/module catalogs include stereo depth, and MimirFensalirFieldLowering.BuildStereoDepthCandidateFrame lowers synthetic rectified stereo depth into GPU-resident R16F disparity SurfacePage plus R8 confidence Texture2D and a Height FieldEvidence claim. Verified with --stereo-depth-contract-smoke and --perfect-machine-profile-smoke; actual HLSL/D3D12 SGM kernel remains future work."} diff --git a/state/map.yaml b/state/map.yaml index 19fbb83..4afdddd 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -57,6 +57,12 @@ invariants: disparity lane over synchronized rectified texture pairs and calibration state. CUDA, TensorRT, and monocular depth demos are provenance only, not live dependencies or geometry authority. + - The first stereo-depth contract is code-visible: + `MimirStereoDepthConfigurations` names the libSGM-provenance D3D12 SGM + profile, and `MimirFensalirFieldLowering.BuildStereoDepthCandidateFrame` + lowers synthetic rectified stereo depth into an R16F disparity SurfacePage, + R8 confidence Texture2D, and Height FieldEvidence claim. The actual SGM + HLSL/D3D12 kernel is still future work. - Fensalir packet payload handles are not authority. Live payload references must resolve through declared typed GPU/native resources with shape, residency, shader access, validity, version, and handle metadata before