diff --git a/docs/fensalir-rendering-rebuild-migration.md b/docs/fensalir-rendering-rebuild-migration.md index 0f7c58d..0f78d31 100644 --- a/docs/fensalir-rendering-rebuild-migration.md +++ b/docs/fensalir-rendering-rebuild-migration.md @@ -159,6 +159,33 @@ MimirObservation { } ``` +The payload handle is not authority. It must resolve through a declared +resource before shader lowering can consume it. + +### 2.5. Resource Declaration + +Live payloads have an explicit Fensalir resource contract: + +```text +FensalirResource { + resourceKey + kind: structured-buffer | texture2d | rolling-texture | mesh | surface-page | volume + residency: gpu-resident | shared-gpu + shaderAccess: SRV | UAV | vertex-buffer | index-buffer | indirect-args + format + dimensions / count / stride + nativeHandle and nativeHandleKind + valid time range + version / sequence +} +``` + +Mimir may mint stable resource keys from native/GPU handles, but Fensalir owns +resolution. A DSL packet may reference `mimir:resource:*`; it may not treat a +bare string as payload truth. If the resource contract is absent, expired, +CPU-only, or incompatible with the selected backend, lowering must defer instead +of rendering a lie with nice lighting. + ### 3. Calibration Constraint Calibration and sync become explicit constraints: @@ -238,6 +265,7 @@ owner. Create pure mapping types for: - rolling stream windows; +- resource declarations for live GPU/native payload views; - observations; - calibration constraints; - surface intent. @@ -249,6 +277,7 @@ Acceptance: - one synthetic buffer can produce observations and surface intent in a unit test; +- claims that reference live payloads also declare a typed Fensalir resource; - the mapping can run repeatedly without growing allocations; - stream/source ids remain stable across frames. diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 385028a..424ccda 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -41,6 +41,12 @@ calibration constraints, and surface intent; Fensalir's side is to turn those into field claims, selected lowerings, reusable evidence, temporal guides, and program output. +Payload handles are now demoted to names inside a resource authority. Mimir +declares live native/GPU payloads as typed Fensalir resources with shape, +residency, shader access, validity, version, and native handle metadata; claims +and lowering requests reference those resource keys. A string handle without a +matching resource declaration is not payload truth. + The old script stack is gone. Do not add a compatibility edge unless it protects a named invariant that the native runtime cannot protect yet. @@ -143,6 +149,13 @@ a named invariant that the native runtime cannot protect yet. every second frequency bin, and one subdivision per segment. Decimation is allowed only by persistent sequence or frequency-bin identity, never by render-frame phase. +- `MimirFensalirFieldLowering` now emits `AquariumFieldResourceDeclaration` + rows for live native/GPU payload views. Observation claims reference + `mimir:resource:*` keys, and Fensalir validation/planning can reject or defer + packets whose resources are missing, CPU-only, or backend-incompatible. + `Mimir.BufferSmoke --fensalir-field-evidence-smoke` proves the first + hardware-free receipt with one declared resource, three claims, three pending + lowering requests, and zero backend packets. - `MimirRuntime` queues bioacoustic timeline PCM through Fensalir audio when the active timing witness is allowed. `MimirAudioSynchronizationSettings.Mode` selects `chirp-only`, `passive`, or `hybrid`; passive disables active diff --git a/notes/current-system-map.md b/notes/current-system-map.md index b4df0a2..5081645 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -316,6 +316,13 @@ lowers those into field claims with travel/depth, metadata, control, and reservoir-guide lanes. If a path only paints pixels, it is a fallback/debug draw, not the Perfect Machine surface. +The live payload boundary is now explicit. Mimir declares each live native/GPU +payload view as an `AquariumFieldResourceDeclaration` with resource key, kind, +residency, shader access, format, shape, valid time range, version, and native +handle metadata. Field claims and lowering requests reference those +`mimir:resource:*` keys. The handle string is only a name; Fensalir validation +and planning own typed resource resolution before shader lowering. + The current teardown/migration map is `docs/fensalir-rendering-rebuild-migration.md`, paired with Fensalir's `docs/rendering-teardown-rebuild-protocol.md`. The intended cut is explicit: diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 878c17b..c5ca1b2 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -536,7 +536,7 @@ static int RunFensalirFieldEvidenceSmoke() var requests = AquariumFieldEvidenceNormalizer.BuildLoweringRequests(frame); Console.WriteLine( - $"fensalir-field-evidence-smoke domains={frame.Domains.Count} claims={frame.Claims.Count} candidates={frame.Candidates.Count} packets={frame.BackendPackets.Count} requests={requests.Count} errors={validation.HasErrors}"); + $"fensalir-field-evidence-smoke domains={frame.Domains.Count} resources={frame.Resources.Count} claims={frame.Claims.Count} candidates={frame.Candidates.Count} packets={frame.BackendPackets.Count} requests={requests.Count} errors={validation.HasErrors}"); if (validation.HasErrors) { @@ -547,8 +547,11 @@ static int RunFensalirFieldEvidenceSmoke() } return !validation.HasErrors && + frame.Resources.Count == 1 && + frame.Resources[0].ResourceKey == MimirFensalirBridgeMapper.ResourceKeyForPayload(window.Payload) && frame.BackendPackets.Count == 0 && frame.Claims.Count == 3 && + frame.Claims.Any(claim => claim.PayloadHandle == frame.Resources[0].ResourceKey) && requests.Count == 3 && requests.All(static request => request.IsPendingBackendSelection) ? 0 diff --git a/src/Mimir.Runtime/Synchronization/MimirFensalirBridgeContracts.cs b/src/Mimir.Runtime/Synchronization/MimirFensalirBridgeContracts.cs index 8a0025a..34c0819 100644 --- a/src/Mimir.Runtime/Synchronization/MimirFensalirBridgeContracts.cs +++ b/src/Mimir.Runtime/Synchronization/MimirFensalirBridgeContracts.cs @@ -47,7 +47,11 @@ public enum MimirSurfaceIntentPurpose public readonly record struct MimirBridgePayloadView( ulong NativeHandle, string NativeHandleKind, - int ByteLength); + int ByteLength, + string ResourceKey = "") +{ + public bool HasResource => NativeHandle != 0 || !string.IsNullOrWhiteSpace(ResourceKey); +} public readonly record struct MimirBridgeSampleDescriptor( MimirStreamKind Kind, @@ -357,7 +361,29 @@ public static class MimirFensalirBridgeMapper { var nativeHandle = sample.VideoFrame?.NativeHandle ?? sample.AudioBlock?.NativeHandle ?? sample.PayloadHandle; var nativeHandleKind = sample.VideoFrame?.NativeHandleKind ?? sample.AudioBlock?.NativeHandleKind ?? ""; - return new MimirBridgePayloadView(nativeHandle, nativeHandleKind, sample.ByteLength); + return new MimirBridgePayloadView( + nativeHandle, + nativeHandleKind, + sample.ByteLength, + ResourceKeyForPayload(nativeHandle, nativeHandleKind)); + } + + public static string ResourceKeyForPayload(MimirBridgePayloadView payload) => + !string.IsNullOrWhiteSpace(payload.ResourceKey) + ? payload.ResourceKey + : ResourceKeyForPayload(payload.NativeHandle, payload.NativeHandleKind); + + private static string ResourceKeyForPayload(ulong nativeHandle, string nativeHandleKind) + { + if (nativeHandle == 0) + { + return ""; + } + + var kind = string.IsNullOrWhiteSpace(nativeHandleKind) + ? "native" + : nativeHandleKind.Trim().ToLowerInvariant(); + return $"mimir:resource:{kind}:{nativeHandle:x}"; } private static long DeviceTimestampNs(MimirStreamSample sample) => diff --git a/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs b/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs index 4eea4fe..d7552e0 100644 --- a/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs +++ b/src/Mimir.Runtime/Synchronization/MimirFensalirFieldLowering.cs @@ -23,17 +23,21 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt var claims = new List(); var candidates = new List(); var packets = new List(); + var resources = new List(); + var seenResources = new HashSet(StringComparer.Ordinal); var seenDomains = new HashSet(StringComparer.Ordinal); foreach (var window in windows) { AddDomain(domains, seenDomains, DomainForWindow(window)); + AddResource(resources, seenResources, ResourceForWindow(window)); } foreach (var observation in observations) { var domain = DomainForObservation(observation); AddDomain(domains, seenDomains, domain); + AddResource(resources, seenResources, ResourceForObservation(observation)); var claim = ClaimForObservation(observation, domain.DomainKey); claims.Add(claim); @@ -70,6 +74,7 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt Claims = claims, Candidates = candidates, BackendPackets = packets, + Resources = resources, AccumulationWindowSeconds = (float)options.AccumulationWindowSeconds, PresentationDelaySeconds = (float)options.PresentationDelaySeconds }; @@ -209,6 +214,17 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt } } + private static void AddResource( + ICollection resources, + ISet seenResources, + AquariumFieldResourceDeclaration resource) + { + if (resource.HasIdentity && seenResources.Add(resource.ResourceKey)) + { + resources.Add(resource); + } + } + private static AquariumFieldDomain DomainForWindow(MimirRollingStreamWindow window) => new( DomainKeyForWindow(window.WindowId), @@ -224,6 +240,81 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt Vector3.Zero, "Mimir.Runtime"); + private static AquariumFieldResourceDeclaration ResourceForWindow(MimirRollingStreamWindow window) + { + if (!window.Payload.HasResource) + { + return default; + } + + var resourceKey = MimirFensalirBridgeMapper.ResourceKeyForPayload(window.Payload); + if (string.IsNullOrWhiteSpace(resourceKey)) + { + return default; + } + + var descriptor = window.SampleDescriptor; + var isVideo = descriptor.Kind == MimirStreamKind.Video; + var width = isVideo + ? Math.Max(1, descriptor.Width) + : Math.Max(1, descriptor.FrameCount); + var height = isVideo + ? Math.Max(1, descriptor.Height) + : Math.Max(1, descriptor.Channels); + var stride = isVideo + ? Math.Max(1, descriptor.StrideBytes) + : BytesPerAudioFrame(descriptor.AudioSampleFormat) * Math.Max(1, descriptor.Channels); + var count = isVideo + ? 1 + : Math.Max(1, descriptor.FrameCount * descriptor.Channels); + + return new AquariumFieldResourceDeclaration( + ResourceKey: resourceKey, + Kind: ResourceKindForDescriptor(descriptor, window.Payload.NativeHandleKind), + Residency: ResourceResidencyForHandle(window.Payload.NativeHandleKind), + Access: ResourceAccessForDescriptor(descriptor), + Format: ResourceFormatForDescriptor(descriptor), + Width: width, + Height: height, + DepthOrCount: count, + StrideBytes: stride, + ValidFromNs: window.WindowStartNs, + ValidUntilNs: window.EdgeNs, + Version: window.SequenceId, + NativeHandle: new IntPtr(unchecked((long)window.Payload.NativeHandle)), + NativeHandleKind: window.Payload.NativeHandleKind); + } + + private static AquariumFieldResourceDeclaration ResourceForObservation(MimirObservation observation) + { + if (!observation.Payload.HasResource) + { + return default; + } + + var resourceKey = MimirFensalirBridgeMapper.ResourceKeyForPayload(observation.Payload); + if (string.IsNullOrWhiteSpace(resourceKey)) + { + return default; + } + + return new AquariumFieldResourceDeclaration( + ResourceKey: resourceKey, + Kind: ResourceKindForObservation(observation.Modality, observation.Payload.NativeHandleKind), + Residency: ResourceResidencyForHandle(observation.Payload.NativeHandleKind), + Access: AquariumFieldShaderAccess.ShaderResource, + Format: observation.Modality == MimirObservationModality.Camera ? "native-video" : "native-audio", + Width: Math.Max(1, observation.Payload.ByteLength), + Height: 1, + DepthOrCount: Math.Max(1, observation.Payload.ByteLength), + StrideBytes: Math.Max(1, observation.Payload.ByteLength), + ValidFromNs: observation.ObservedTimeNs, + ValidUntilNs: observation.CanonicalTimeEstimateNs + Math.Max(0, observation.UncertaintyNs), + Version: observation.Provenance.SequenceId, + NativeHandle: new IntPtr(unchecked((long)observation.Payload.NativeHandle)), + NativeHandleKind: observation.Payload.NativeHandleKind); + } + private static AquariumFieldDomain DomainForObservation(MimirObservation observation) => new( DomainKeyForObservation(observation.ObservationKey), @@ -441,17 +532,67 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt private static string PayloadHandle(MimirBridgePayloadView payload) { - if (payload.NativeHandle == 0) + return MimirFensalirBridgeMapper.ResourceKeyForPayload(payload); + } + + private static AquariumFieldResourceKind ResourceKindForDescriptor( + MimirBridgeSampleDescriptor descriptor, + string nativeHandleKind) + { + if (descriptor.Kind == MimirStreamKind.Audio) { - return ""; + return AquariumFieldResourceKind.StructuredBuffer; } - var kind = string.IsNullOrWhiteSpace(payload.NativeHandleKind) - ? "native" - : payload.NativeHandleKind; - return $"{kind}:{payload.NativeHandle:x}"; + if (nativeHandleKind.Contains("mesh", StringComparison.OrdinalIgnoreCase)) + { + return AquariumFieldResourceKind.Mesh; + } + + return nativeHandleKind.Contains("rolling", StringComparison.OrdinalIgnoreCase) + ? AquariumFieldResourceKind.RollingTexture + : AquariumFieldResourceKind.Texture2D; } + private static AquariumFieldResourceKind ResourceKindForObservation( + MimirObservationModality modality, + string nativeHandleKind) + { + if (nativeHandleKind.Contains("curve", StringComparison.OrdinalIgnoreCase) || + nativeHandleKind.Contains("spline", StringComparison.OrdinalIgnoreCase)) + { + return AquariumFieldResourceKind.CurvePointBuffer; + } + + return modality == MimirObservationModality.Camera + ? AquariumFieldResourceKind.Texture2D + : AquariumFieldResourceKind.StructuredBuffer; + } + + private static AquariumFieldResourceResidency ResourceResidencyForHandle(string nativeHandleKind) => + nativeHandleKind.Contains("cpu", StringComparison.OrdinalIgnoreCase) + ? AquariumFieldResourceResidency.CpuVisible + : AquariumFieldResourceResidency.SharedGpu; + + private static AquariumFieldShaderAccess ResourceAccessForDescriptor(MimirBridgeSampleDescriptor descriptor) => + descriptor.Kind == MimirStreamKind.Video + ? AquariumFieldShaderAccess.ShaderResource + : AquariumFieldShaderAccess.ShaderResource; + + private static string ResourceFormatForDescriptor(MimirBridgeSampleDescriptor descriptor) => + descriptor.Kind == MimirStreamKind.Video + ? descriptor.PixelFormat.ToString() + : descriptor.AudioSampleFormat.ToString(); + + private static int BytesPerAudioFrame(MimirAudioSampleFormat format) => + format switch + { + MimirAudioSampleFormat.Float32 or MimirAudioSampleFormat.Int32 => 4, + MimirAudioSampleFormat.Int24 => 3, + MimirAudioSampleFormat.Int16 => 2, + _ => 1, + }; + private static string DomainKeyForWindow(string windowId) => $"mimir:window:{windowId}"; private static string DomainKeyForObservation(string observationKey) => $"mimir:observation:{observationKey}"; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 38c6563..027f1f8 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -138,3 +138,4 @@ {"ts": "2026-05-26T14:39:17+01:00", "type": "correction", "status": "ok", "note": "Corrected the Phase 1 field evidence boundary: Mimir no longer emits AquariumFieldBackendPacket rows with Backend=Unknown for surface intents. Surface intent now lowers only to field domains, claims, and candidates; backend packet selection remains Fensalir authority. dotnet build Mimir.slnx --no-restore passed with 0 warnings and 0 errors after the cut."} {"ts": "2026-05-26T14:44:02+01:00", "type": "implementation", "status": "ok", "note": "Added BufferSmoke --fensalir-field-evidence-smoke as a hardware-free contract receipt. It builds a synthetic rolling audio window, observation, bioacoustic calibration constraint, and audio-spectrum surface intent, lowers them through MimirFensalirFieldLowering, validates with AquariumFieldEvidenceValidator, and verifies Fensalir receives three pending lowering requests and zero backend packets. Smoke passed: domains=4 claims=3 candidates=3 packets=0 requests=3 errors=False."} {"ts": "2026-05-26T14:50:33+01:00", "type": "implementation", "status": "ok", "note": "MimirRuntime now publishes AquariumFieldEvidenceFrame on every AquariumSceneState from live rolling buffers, latest observations, audio sync calibration constraints, and per-source surface intent. Existing direct spectrum splines remain diagnostic; Fensalir receives backend-neutral domains/claims/candidates through FieldEvidenceFrame. dotnet build Mimir.slnx --no-restore passed with the pre-existing EveRelay CA2024 warning, and --fensalir-field-evidence-smoke still passes."} +{"ts": "2026-05-26T16:21:31+01:00", "type": "implementation", "status": "ok", "note": "Added the typed Fensalir resource boundary for field evidence. AquariumFieldEvidenceFrame now carries AquariumFieldResourceDeclaration rows; claims/packets that use mimir:resource:* handles validate against declared resources, and the lowering planner defers missing, CPU-only, or backend-incompatible resource requests. MimirFensalirFieldLowering emits resource declarations from live MimirBridgePayloadView/native handles, and observation claims reference those resource keys instead of bare kind:handle strings. dotnet build Mimir.slnx passed with the pre-existing EveRelay CA2024 warning; BufferSmoke --fensalir-field-evidence-smoke passed with domains=4 resources=1 claims=3 candidates=3 packets=0 requests=3 errors=False."} diff --git a/state/map.yaml b/state/map.yaml index ccd784a..a4bf216 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -51,6 +51,10 @@ invariants: - Mimir publishes physical observations, calibration constraints, and surface intent. Fensalir owns field claims, selected lowerings, evidence reservoirs, temporal guide lanes, and program presentation. + - 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 + shader lowering can consume them. - EVE fullscreen output must use native decode/composite over Fensalir-owned program pixels; WebKit/DOM layout is forbidden as pixel authority. - Faust/native DSP owns hot audio alignment, separation, spatialization, and @@ -283,6 +287,13 @@ accepted_design: texture capture. - `native/reservoir` owns the lower shared-edge rolling-buffer invariant for Fensalir/Faust integration. + - `MimirFensalirFieldLowering` now emits `AquariumFieldResourceDeclaration` + rows for live payload views. Observation claims reference + `mimir:resource:*` keys, and Fensalir validation/planning can reject or + defer packets whose resource declaration is missing, CPU-only, or + backend-incompatible. `Mimir.BufferSmoke --fensalir-field-evidence-smoke` + proves the current receipt: one declared resource, three claims, three + pending lowering requests, zero backend packets, and no validation errors. - `config/perfect-machine.example.json` declares live owners, sensors, reservoir views, and runtime policy. - `src/Mimir.Runtime/Synchronization` now includes the Perfect Machine module