Make spectrum upload a fixed rolling matrix

This commit is contained in:
Meta Vens 2026-05-27 11:39:07 +01:00
commit e88a9407b7
7 changed files with 168 additions and 81 deletions

View file

@ -234,7 +234,13 @@ GPU buffer contents rather than an empty declaration. The runtime-level receipt
is `Mimir.BufferSmoke --mimir-spectrum-upload-smoke`: it boots Mimir's frame
path, advances spectrum analysis, and verifies one Float32 upload, one planned
TubeField packet, a resource-bound local blackbody ramp Texture2D, and no live
legacy spline/buffer-field dashboard input.
legacy spline/buffer-field dashboard input. The runtime resource is no longer a
latest-frame row dump: it is a rolling column matrix where physical columns are
flattened `(history age, source lane)` pairs. Mimir emits one TubeField claim
per source lane, using `ColumnStride=sourceCount` and `ColumnStep.z=0.1` so
each source renders its own age trail from newest to older samples. The
resource declaration keeps a fixed history capacity; new frames update content
version and upload data, but they do not grow the GPU buffer as the trail fills.
### 3. Calibration Constraint

View file

@ -147,6 +147,12 @@ a named invariant that the native runtime cannot protect yet.
resource upload plus planned TubeField packet while legacy spline and buffer
field inputs stay empty. The same runtime path declares the local blackbody
ramp PNG as a GPU-resident Texture2D resource and binds it by resource key.
The uploaded spectrum resource is a rolling column matrix now: physical
columns are flattened `(history age, source lane)` pairs, and Mimir emits one
Tube claim/lowering per source with `ColumnStride=sourceCount` so each lane
traverses its own age trail at `z = age * 0.1`. The resource uses a fixed
history-column capacity so frame-to-frame content versions do not resize the
GPU buffer while the history fills.
- `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

View file

@ -384,7 +384,12 @@ it. `Mimir.BufferSmoke --mimir-spectrum-upload-smoke` verifies this through the
actual `MimirRuntime` frame path and confirms the legacy direct spline and
buffer-field dashboard inputs are empty. The same path declares the local
blackbody ramp as a Texture2D field resource and binds the TubeField material by
resource key.
resource key. Runtime spectrum columns now represent `(history age, source
lane)` pairs rather than only the latest spectra; Mimir emits one TubeField
claim/lowering per source, each striding through the shared resource to render
its own age trail at `z = age * 0.1`. The resource advertises a fixed history
capacity, so content updates do not resize the GPU buffer while the rolling
trail fills.
## Known Risks

View file

@ -644,7 +644,10 @@ static int RunMimirSpectrumUploadSmoke()
};
using var runtime = new MimirRuntime(new AquariumRuntimeOptions(Headless: true, CultCachePath: null), settings);
runtime.OnSceneReady();
runtime.Update(0.0f, new InputState());
var input = new InputState();
runtime.Update(0.0f, input);
runtime.Update(0.2f, input);
runtime.Update(0.2f, input);
var frame = runtime.Frame;
var field = frame.Scene.FieldEvidenceFrame;
@ -660,14 +663,21 @@ static int RunMimirSpectrumUploadSmoke()
.Where(lowering => string.Equals(lowering.ResourceKey, "mimir:resource:spectrum:field-upload", StringComparison.Ordinal))
.ToArray();
var matchingClaims = field.Claims
.Where(claim => string.Equals(claim.ClaimKey, "intent:mimir:spectrum:field-upload", StringComparison.Ordinal))
.Where(claim => claim.ClaimKey.StartsWith("intent:mimir:spectrum:field-upload:", StringComparison.Ordinal))
.ToArray();
var resource = matchingResources.FirstOrDefault();
var ramp = matchingRamps.FirstOrDefault();
var lowering = matchingLowerings.FirstOrDefault();
var claim = matchingClaims.FirstOrDefault();
var validation = AquariumFieldEvidenceValidator.Validate(field);
var plan = AquariumFieldLoweringPlanner.Plan(field);
const int expectedSourceCount = 4;
const int expectedHistoryCount = 3;
const int expectedHistoryCapacity = 40;
var plannedTubePackets = plan.Packets
.Where(packet =>
packet.Backend == AquariumFieldBackendKind.TubeField &&
string.Equals(packet.PayloadHandle, "mimir:resource:spectrum:field-upload", StringComparison.Ordinal))
.ToArray();
Console.WriteLine(
$"mimir-spectrum-upload-smoke resources={field.Resources.Count} uploads={field.ResourceUploads.Count} claims={field.Claims.Count} tubeLowerings={field.TubeSplineLowerings.Count} planned={plan.Packets.Count} errors={validation.HasErrors} legacySplines={frame.Scene.SplineFrame.Splines.Count} bufferFields={frame.Scene.BufferFieldFrame.SplineTubeFields.Count + frame.Scene.BufferFieldFrame.TextureSplineFields.Count} uploadFloats={upload?.Float32Data.Count ?? 0}");
@ -679,8 +689,8 @@ static int RunMimirSpectrumUploadSmoke()
upload is not null &&
matchingResources.Length == 1 &&
matchingRamps.Length == 1 &&
matchingLowerings.Length == 1 &&
matchingClaims.Length == 1 &&
matchingLowerings.Length == 4 &&
matchingClaims.Length == matchingLowerings.Length &&
upload.Version == resource.Version &&
upload.Float32Data.Count == resource.DepthOrCount &&
resource.Kind == AquariumFieldResourceKind.StructuredBuffer &&
@ -693,14 +703,18 @@ static int RunMimirSpectrumUploadSmoke()
ramp.Access == AquariumFieldShaderAccess.ShaderResource &&
string.Equals(ramp.Format, "Rgba8Unorm", StringComparison.OrdinalIgnoreCase) &&
string.Equals(ramp.SourceUri, @"D:\WIP4\Projects\Aetheria\Assets\Resources\Ramps\blackbody.png", StringComparison.OrdinalIgnoreCase) &&
lowering.Width * lowering.Height == upload.Float32Data.Count &&
lowering.ClaimKey == claim.ClaimKey &&
string.Equals(lowering.RampResourceKey, ramp.ResourceKey, StringComparison.Ordinal) &&
claim.PayloadHandle == resource.ResourceKey &&
plan.Packets.Any(packet =>
packet.Backend == AquariumFieldBackendKind.TubeField &&
string.Equals(packet.ClaimKey, claim.ClaimKey, StringComparison.Ordinal) &&
string.Equals(packet.PayloadHandle, resource.ResourceKey, StringComparison.Ordinal))
resource.Height == expectedSourceCount * expectedHistoryCapacity &&
lowering.Width * resource.Height == upload.Float32Data.Count &&
matchingLowerings.All(item =>
item.ColumnCount == expectedHistoryCount &&
item.ColumnStride == expectedSourceCount &&
item.RollingModulo == resource.Height &&
Math.Abs(item.ColumnStep.Z - 0.1f) < 0.0001f &&
string.Equals(item.RampResourceKey, ramp.ResourceKey, StringComparison.Ordinal) &&
matchingClaims.Any(claim =>
string.Equals(claim.ClaimKey, item.ClaimKey, StringComparison.Ordinal) &&
string.Equals(claim.PayloadHandle, resource.ResourceKey, StringComparison.Ordinal))) &&
plannedTubePackets.Length == matchingLowerings.Length
? 0
: 1;
}

View file

@ -21,7 +21,7 @@ public sealed class MimirRuntime : IAquariumRuntime
private const float DefaultSpectrumUpdateIntervalSeconds = 0.2f;
private const int SpectrumHistoryWindowCount = 40;
private const float SpectrumChannelSeparation = 1.75f;
private const float SpectrumWindowDepthSeparation = 0.18f;
private const float SpectrumWindowDepthSeparation = 0.1f;
private const float SpectrumWidth = 12.0f;
private const float SpectrumAmplitudeHeight = 1.1f;
private const float SpectrumCameraDefaultDistanceMultiplier = 10.0f;
@ -239,21 +239,57 @@ public sealed class MimirRuntime : IAquariumRuntime
return frame;
}
var width = Math.Max(2, spectra.Max(static spectrum => spectrum.BandDecibels.Count));
var height = spectra.Length;
var samples = new float[width * height];
for (var row = 0; row < spectra.Length; row++)
var historyFrames = spectrumHistory.Count > 0
? spectrumHistory.Reverse().ToArray()
: [new MimirSpectrumHistoryFrame(spectrumHistorySequence, runtimeSeconds, spectra)];
var sourceIds = historyFrames
.SelectMany(static history => history.Spectra)
.Where(static spectrum => spectrum.BandDecibels.Count >= 2)
.Select(static spectrum => spectrum.SourceId)
.Distinct(StringComparer.Ordinal)
.OrderBy(static sourceId => sourceId, StringComparer.Ordinal)
.ToArray();
if (sourceIds.Length == 0)
{
WriteNormalizedSpectrum(spectra[row], samples.AsSpan(row * width, width));
return frame;
}
var sourceIndexById = sourceIds
.Select((sourceId, index) => (sourceId, index))
.ToDictionary(static item => item.sourceId, static item => item.index, StringComparer.Ordinal);
var width = Math.Max(2, historyFrames
.SelectMany(static history => history.Spectra)
.Where(static spectrum => spectrum.BandDecibels.Count >= 2)
.Select(static spectrum => spectrum.BandDecibels.Count)
.DefaultIfEmpty(2)
.Max());
var historyCount = historyFrames.Length;
var sourceCount = sourceIds.Length;
var activeColumnCount = checked(sourceCount * historyCount);
var resourceColumnCapacity = checked(sourceCount * SpectrumHistoryWindowCount);
var samples = new float[width * resourceColumnCapacity];
for (var historyIndex = 0; historyIndex < historyFrames.Length; historyIndex++)
{
foreach (var spectrum in historyFrames[historyIndex].Spectra)
{
if (!sourceIndexById.TryGetValue(spectrum.SourceId, out var sourceIndex))
{
continue;
}
var physicalColumn = historyIndex * sourceCount + sourceIndex;
WriteNormalizedSpectrum(spectrum, samples.AsSpan(physicalColumn * width, width));
}
}
const string domainKey = "mimir:domain:spectrum:field-upload";
const string claimKey = "intent:mimir:spectrum:field-upload";
var version = unchecked((ulong)Math.Max(0, spectrumHistorySequence));
var confidence = (float)Math.Clamp(spectra.Average(static spectrum => spectrum.Rms > 0.0 ? 1.0 : 0.65), 0.0, 1.0);
var maxY = Math.Max(0, sourceCount - 1) * SpectrumChannelSeparation + SpectrumAmplitudeHeight;
var maxZ = Math.Max(0, SpectrumHistoryWindowCount - 1) * SpectrumWindowDepthSeparation;
var support = new AquariumFieldSupport(
Center: Vector3.Zero,
Radius: new Vector3(5.0f, SpectrumAmplitudeHeight, Math.Max(0.1f, height * 0.1f)),
Center: new Vector3(0.0f, maxY * 0.5f, maxZ * 0.5f),
Radius: new Vector3(5.0f, Math.Max(SpectrumAmplitudeHeight, maxY), Math.Max(0.1f, maxZ)),
LocalFrame: Matrix4x4.Identity,
ConservativeRadius: 5.0f,
ProjectedError: 0.0f,
@ -263,7 +299,7 @@ public sealed class MimirRuntime : IAquariumRuntime
AquariumFieldProposalKind.DebugIntent,
SourcePdf: 1.0f,
TargetContribution: confidence,
RepresentedCandidateCount: height,
RepresentedCandidateCount: activeColumnCount,
Seed: 0x5EC7_0001u);
var resource = new AquariumFieldResourceDeclaration(
ResourceKey: SpectrumFieldResourceKey,
@ -272,7 +308,7 @@ public sealed class MimirRuntime : IAquariumRuntime
Access: AquariumFieldShaderAccess.ShaderResource,
Format: "Float32",
Width: width,
Height: height,
Height: resourceColumnCapacity,
DepthOrCount: samples.Length,
StrideBytes: sizeof(float),
ValidFromNs: 0,
@ -284,18 +320,70 @@ public sealed class MimirRuntime : IAquariumRuntime
SpectrumRampResourceKey,
SpectrumRampTexturePath,
version: 1);
var claim = new AquariumFieldClaim(
ClaimKey: claimKey,
DomainKey: domainKey,
ProducerKey: "Mimir.Runtime",
Layer: AquariumFieldLayer.Form,
Encoding: AquariumFieldEncoding.Tube,
Support: support,
Proposal: proposal,
PayloadHandle: SpectrumFieldResourceKey,
ObservedTimeNs: 0,
Confidence: confidence);
var axisStepX = width > 1 ? 10.0f / (width - 1) : 10.0f;
var claims = new List<AquariumFieldClaim>(sourceCount);
var candidates = new List<AquariumFieldCandidate>(sourceCount);
var lowerings = new List<AquariumFieldTubeSplineLowering>(sourceCount);
for (var sourceIndex = 0; sourceIndex < sourceIds.Length; sourceIndex++)
{
var sourceId = sourceIds[sourceIndex];
var claimKey = $"intent:mimir:spectrum:field-upload:{sourceId}";
var sourceSupport = support with
{
Center = new Vector3(0.0f, sourceIndex * SpectrumChannelSeparation + SpectrumAmplitudeHeight * 0.5f, maxZ * 0.5f),
Radius = new Vector3(5.0f, SpectrumAmplitudeHeight, Math.Max(0.1f, maxZ)),
};
var sourceProposal = proposal with
{
RepresentedCandidateCount = historyCount,
Seed = unchecked(proposal.Seed + (uint)sourceIndex),
};
claims.Add(new AquariumFieldClaim(
ClaimKey: claimKey,
DomainKey: domainKey,
ProducerKey: "Mimir.Runtime",
Layer: AquariumFieldLayer.Form,
Encoding: AquariumFieldEncoding.Tube,
Support: sourceSupport,
Proposal: sourceProposal,
PayloadHandle: SpectrumFieldResourceKey,
ObservedTimeNs: 0,
Confidence: confidence));
candidates.Add(new AquariumFieldCandidate(
$"{claimKey}:candidate",
claimKey,
AquariumFieldLayer.Form,
AquariumFieldEncoding.Tube,
sourceProposal,
AquariumFieldGuide.Valid(confidence, spectrumUpdateIntervalSeconds)));
lowerings.Add(new AquariumFieldTubeSplineLowering(
LoweringKey: $"tube-spline:mimir:spectrum:field-upload:{sourceId}",
ClaimKey: claimKey,
ResourceKey: SpectrumFieldResourceKey,
Width: width,
Height: resourceColumnCapacity,
StrideBytes: sizeof(float),
FirstColumn: sourceIndex,
ColumnCount: historyCount,
ColumnStride: sourceCount,
RollingModulo: resourceColumnCapacity,
RollingOffset: 0,
Origin: new Vector3(-5.0f, sourceIndex * SpectrumChannelSeparation, 0.0f),
AxisStep: new Vector3(axisStepX, 0.0f, 0.0f),
ColumnStep: new Vector3(0.0f, 0.0f, SpectrumWindowDepthSeparation),
AmplitudePower: 2.0f,
AmplitudeScale: SpectrumAmplitudeHeight,
NormalizeMin: 0.0f,
NormalizeMax: 1.0f,
BaseRadius: 0.012f,
RadiusScale: 0.030f,
Alpha: 0.92f,
Feather: 0.20f,
RampTexturePath: SpectrumRampTexturePath,
RampResourceKey: SpectrumRampResourceKey,
EmissionScale: 10.0f,
CatmullRomSubdivisions: 4).Normalized());
}
return new AquariumFieldEvidenceFrame
{
@ -309,22 +397,12 @@ public sealed class MimirRuntime : IAquariumRuntime
Matrix4x4.Identity,
Matrix4x4.Identity,
new Vector3(-5.0f, 0.0f, 0.0f),
new Vector3(5.0f, SpectrumAmplitudeHeight, Math.Max(0.1f, height * 0.1f)),
new Vector3(5.0f, maxY, Math.Max(0.1f, maxZ)),
Vector3.Zero,
"Mimir.Runtime"),
],
Claims = [.. frame.Claims, claim],
Candidates =
[
.. frame.Candidates,
new AquariumFieldCandidate(
$"{claimKey}:candidate",
claimKey,
AquariumFieldLayer.Form,
AquariumFieldEncoding.Tube,
proposal,
AquariumFieldGuide.Valid(confidence, spectrumUpdateIntervalSeconds)),
],
Claims = [.. frame.Claims, .. claims],
Candidates = [.. frame.Candidates, .. candidates],
BackendPackets = frame.BackendPackets,
Resources = [.. frame.Resources, resource, ramp],
ResourceUploads =
@ -337,37 +415,7 @@ public sealed class MimirRuntime : IAquariumRuntime
Float32Data = samples,
},
],
TubeSplineLowerings =
[
.. frame.TubeSplineLowerings,
new AquariumFieldTubeSplineLowering(
LoweringKey: "tube-spline:mimir:spectrum:field-upload",
ClaimKey: claimKey,
ResourceKey: SpectrumFieldResourceKey,
Width: width,
Height: height,
StrideBytes: sizeof(float),
FirstColumn: 0,
ColumnCount: height,
ColumnStride: 1,
RollingModulo: height,
RollingOffset: 0,
Origin: new Vector3(-5.0f, 0.0f, 0.0f),
AxisStep: new Vector3(axisStepX, 0.0f, 0.0f),
ColumnStep: new Vector3(0.0f, 0.0f, 0.1f),
AmplitudePower: 2.0f,
AmplitudeScale: SpectrumAmplitudeHeight,
NormalizeMin: 0.0f,
NormalizeMax: 1.0f,
BaseRadius: 0.012f,
RadiusScale: 0.030f,
Alpha: 0.92f,
Feather: 0.20f,
RampTexturePath: SpectrumRampTexturePath,
RampResourceKey: SpectrumRampResourceKey,
EmissionScale: 10.0f,
CatmullRomSubdivisions: 4).Normalized(),
],
TubeSplineLowerings = [.. frame.TubeSplineLowerings, .. lowerings],
AccumulationWindowSeconds = frame.AccumulationWindowSeconds,
PresentationDelaySeconds = frame.PresentationDelaySeconds,
};

View file

@ -162,3 +162,5 @@
{"ts": "2026-05-26T23:48:24+01:00", "type": "verification", "status": "ok", "note": "Headless Fensalir with Mimir.Runtime and MIMIR_SYNTHETIC_SPECTRUM_PREVIEW=1 captured artifacts/runtime/mimir-spectrum-upload-headless.png. The screenshot shows visible TubeField spectrum arcs from the resource-upload path; stderr was empty. Use Mimir.Runtime.csproj, not Mimir.App.csproj, as the dev-reload client assembly because the runtime factory lives there."}
{"ts": "2026-05-26T23:49:49+01:00", "type": "implementation", "status": "ok", "note": "Mimir's runtime spectrum FieldEvidence path now declares the blackbody PNG as a GPU-resident Texture2D field resource and binds the TubeSpline lowering to that ramp by resource key, instead of falling back to unbound white/linear material."}
{"ts": "2026-05-26T23:51:02+01:00", "type": "verification", "status": "ok", "note": "Runtime blackbody ramp binding verified. Mimir build passed with one unrelated existing Mimir.EveRelay CA2024 warning; --mimir-spectrum-upload-smoke reports resources=2/uploads=1/planned=1/errors=False; both Fensalir field smokes pass; headless Fensalir captured artifacts/runtime/mimir-spectrum-upload-headless-ramp.png with visible ramp-colored TubeField arcs and empty stderr."}
{"ts": "2026-05-27T11:33:22+01:00", "type": "implementation", "status": "ok", "note": "Mimir spectrum upload is now a rolling column matrix instead of a latest-frame row dump. The shared Float32 resource flattens physical columns as history-age/source-lane pairs; Mimir emits one TubeField claim/lowering per source with ColumnStride=sourceCount and ColumnStep.z=0.1 so each source gets its own age trail through the shared GPU buffer."}
{"ts": "2026-05-27T11:38:16+01:00", "type": "implementation", "status": "ok", "note": "Mimir spectrum resource declarations now use fixed history capacity instead of growing with the currently filled trail. The runtime smoke proves 48 bands x 4 source lanes x 40 history capacity = 7680 uploaded floats while only the active history count is emitted through each source lowering. This avoids frame-to-frame GPU buffer resizing while preserving the rolling age trail."}

View file

@ -362,6 +362,12 @@ accepted_design:
The runtime spectrum path also declares the local blackbody PNG as a
GPU-resident Texture2D field resource and binds the TubeField material by
`RampResourceKey`.
Runtime spectrum columns now represent flattened `(history age, source
lane)` pairs. Mimir emits one TubeField claim/lowering per source, each
using `ColumnStride=sourceCount` through the shared Float32 resource so the
generated geometry renders a true age trail at `z = age * 0.1`. The
spectrum resource advertises a fixed history capacity so frame content
versions do not resize the GPU buffer while the rolling trail fills.
- `config/perfect-machine.example.json` declares live owners, sensors,
reservoir views, and runtime policy.
- `src/Mimir.Runtime/Synchronization` now includes the Perfect Machine module