Lower live Leap packed stereo to depth socket
This commit is contained in:
parent
d6823245c2
commit
2c197cb3ae
9 changed files with 247 additions and 36 deletions
|
|
@ -149,6 +149,11 @@ if (args.Any(arg => string.Equals(arg, "--stereo-depth-contract-smoke", StringCo
|
|||
return RunStereoDepthContractSmoke();
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--leap-packed-stereo-depth-smoke", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunLeapPackedStereoDepthSmoke();
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--ks-camera-driver-smoke", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunKsCameraDriverSmoke(args);
|
||||
|
|
@ -2396,6 +2401,72 @@ static int RunStereoDepthContractSmoke()
|
|||
: 1;
|
||||
}
|
||||
|
||||
static int RunLeapPackedStereoDepthSmoke()
|
||||
{
|
||||
const string sourceId = "leap-stereo-ir";
|
||||
var frameDescriptor = new MimirVideoFrameDescriptor(
|
||||
Width: 640,
|
||||
Height: 240,
|
||||
PixelFormat: MimirVideoPixelFormat.LeapStereoIr,
|
||||
StrideBytes: 1280,
|
||||
DeviceTimestampNs: 1_000_000_000L,
|
||||
NativeHandle: 0xCAFE,
|
||||
NativeHandleKind: "fensalir-owned-d3d12-texture2d",
|
||||
ResourceKey: MimirFensalirTextureLeaseClient.ResourceKeyForSource(sourceId),
|
||||
ProducerFenceHandle: 0xD00D,
|
||||
ProducerFenceValue: 7);
|
||||
var sample = new MimirStreamSample(
|
||||
sourceId,
|
||||
MimirStreamKind.Video,
|
||||
MimirStreamOrigin.LocalDevice,
|
||||
TimestampNs: frameDescriptor.DeviceTimestampNs,
|
||||
ArrivalNs: frameDescriptor.DeviceTimestampNs,
|
||||
Sequence: 7,
|
||||
PayloadHandle: frameDescriptor.NativeHandle,
|
||||
ByteLength: 0,
|
||||
VideoFrame: frameDescriptor);
|
||||
var buffer = new MimirRollingStreamBuffer(
|
||||
new MimirStreamDescriptor(sourceId, MimirStreamKind.Video, MimirStreamOrigin.LocalDevice),
|
||||
TimeSpan.FromSeconds(5));
|
||||
buffer.Append(sample);
|
||||
|
||||
var lowerer = new MimirFensalirFieldLowering();
|
||||
var cameraFrame = lowerer.BuildCameraObservationFrame([buffer]);
|
||||
var windows = new List<MimirRollingStreamWindow>();
|
||||
MimirFensalirBridgeMapper.MapWindows([buffer], windows);
|
||||
var stereoFrame = lowerer.BuildLeapPackedStereoDepthCandidateFrame(windows, cameraFrame.Resources);
|
||||
var validation = AquariumFieldEvidenceValidator.Validate(stereoFrame);
|
||||
var plan = AquariumFieldLoweringPlanner.Plan(stereoFrame);
|
||||
var lowering = stereoFrame.StereoDepthLowerings.FirstOrDefault();
|
||||
var packedResource = stereoFrame.Resources.FirstOrDefault(resource =>
|
||||
string.Equals(resource.ResourceKey, frameDescriptor.ResourceKey, StringComparison.Ordinal));
|
||||
var disparity = stereoFrame.Resources.FirstOrDefault(resource =>
|
||||
string.Equals(resource.ResourceKey, "mimir:resource:stereo-depth:leap-stereo-ir:disparity-r16f", StringComparison.Ordinal));
|
||||
|
||||
Console.WriteLine(
|
||||
$"leap-packed-stereo-depth resources={stereoFrame.Resources.Count} claims={stereoFrame.Claims.Count} lowerings={stereoFrame.StereoDepthLowerings.Count} planned={plan.Packets.Count} deferred={plan.DeferredRequests.Count} errors={validation.HasErrors}");
|
||||
Console.WriteLine(
|
||||
$"leap-packed-stereo-depth-input packed={packedResource.ResourceKey} format={packedResource.Format} left={lowering.LeftResourceKey} right={lowering.RightResourceKey} calibration={lowering.CalibrationKey}");
|
||||
Console.WriteLine(
|
||||
$"leap-packed-stereo-depth-output disparity={disparity.ResourceKey} access={disparity.Access} format={disparity.Format} minDisparity={lowering.MinDisparity} disparities={lowering.DisparityLevels} paths={lowering.AggregationPathCount}");
|
||||
|
||||
return !validation.HasErrors &&
|
||||
stereoFrame.Resources.Count == 3 &&
|
||||
stereoFrame.Claims.Count == 1 &&
|
||||
stereoFrame.StereoDepthLowerings.Count == 1 &&
|
||||
packedResource.Format == "LeapStereoIr" &&
|
||||
lowering.LeftResourceKey == frameDescriptor.ResourceKey &&
|
||||
lowering.RightResourceKey == frameDescriptor.ResourceKey &&
|
||||
lowering.CalibrationKey == "leapuvc-packed-stereo-ir-calibration-pending" &&
|
||||
disparity.Kind == AquariumFieldResourceKind.SurfacePage &&
|
||||
disparity.Access == AquariumFieldShaderAccess.UnorderedAccess &&
|
||||
plan.Packets.Count == 1 &&
|
||||
plan.Packets[0].Backend == AquariumFieldBackendKind.SurfacePage &&
|
||||
plan.DeferredRequests.Count == 0
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
||||
static int RunPerfectMachineProfileSmoke()
|
||||
{
|
||||
var profiles = MimirPerfectMachineProfiles.All;
|
||||
|
|
|
|||
|
|
@ -321,7 +321,8 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
|
|||
}
|
||||
|
||||
var frame = fieldLowering.BuildFieldEvidenceFrame(windows, observations, constraints, intents);
|
||||
return AddSpectrumFieldEvidence(frame);
|
||||
frame = AddSpectrumFieldEvidence(frame);
|
||||
return AddLeapStereoDepthFieldEvidence(frame, windows);
|
||||
}
|
||||
|
||||
private void CommitProducerLeases(IReadOnlyList<MimirRollingStreamWindow> windows)
|
||||
|
|
@ -368,6 +369,58 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
|
|||
Purpose: MimirSurfaceIntentPurpose.Production);
|
||||
}
|
||||
|
||||
private AquariumFieldEvidenceFrame AddLeapStereoDepthFieldEvidence(
|
||||
AquariumFieldEvidenceFrame frame,
|
||||
IReadOnlyList<MimirRollingStreamWindow> windows)
|
||||
{
|
||||
var stereoFrame = fieldLowering.BuildLeapPackedStereoDepthCandidateFrame(windows, frame.Resources);
|
||||
if (!stereoFrame.HasInput)
|
||||
{
|
||||
return frame;
|
||||
}
|
||||
|
||||
return new AquariumFieldEvidenceFrame
|
||||
{
|
||||
Domains = [.. frame.Domains, .. stereoFrame.Domains],
|
||||
Claims = [.. frame.Claims, .. stereoFrame.Claims],
|
||||
Candidates = [.. frame.Candidates, .. stereoFrame.Candidates],
|
||||
BackendPackets = [.. frame.BackendPackets, .. stereoFrame.BackendPackets],
|
||||
Resources = MergeResources(frame.Resources, stereoFrame.Resources),
|
||||
ResourceUploads = [.. frame.ResourceUploads, .. stereoFrame.ResourceUploads],
|
||||
TubeSplineLowerings = [.. frame.TubeSplineLowerings, .. stereoFrame.TubeSplineLowerings],
|
||||
StereoDepthLowerings = [.. frame.StereoDepthLowerings, .. stereoFrame.StereoDepthLowerings],
|
||||
AccumulationWindowSeconds = frame.AccumulationWindowSeconds,
|
||||
PresentationDelaySeconds = frame.PresentationDelaySeconds,
|
||||
};
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AquariumFieldResourceDeclaration> MergeResources(
|
||||
IReadOnlyList<AquariumFieldResourceDeclaration> first,
|
||||
IReadOnlyList<AquariumFieldResourceDeclaration> second)
|
||||
{
|
||||
if (first.Count == 0)
|
||||
{
|
||||
return second;
|
||||
}
|
||||
|
||||
if (second.Count == 0)
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
var resources = new List<AquariumFieldResourceDeclaration>(first.Count + second.Count);
|
||||
var seen = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var resource in first.Concat(second))
|
||||
{
|
||||
if (resource.HasIdentity && seen.Add(resource.ResourceKey))
|
||||
{
|
||||
resources.Add(resource);
|
||||
}
|
||||
}
|
||||
|
||||
return resources;
|
||||
}
|
||||
|
||||
private AquariumFieldEvidenceFrame AddSpectrumFieldEvidence(AquariumFieldEvidenceFrame frame)
|
||||
{
|
||||
if (lastAudioSpectra.Count == 0)
|
||||
|
|
|
|||
|
|
@ -180,6 +180,63 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
};
|
||||
}
|
||||
|
||||
public AquariumFieldEvidenceFrame BuildLeapPackedStereoDepthCandidateFrame(
|
||||
IEnumerable<MimirRollingStreamWindow> windows,
|
||||
IEnumerable<AquariumFieldResourceDeclaration> inputResources)
|
||||
{
|
||||
var resourcesByKey = inputResources
|
||||
.Where(static resource => resource.HasIdentity)
|
||||
.GroupBy(static resource => resource.ResourceKey, StringComparer.Ordinal)
|
||||
.ToDictionary(static group => group.Key, static group => group.First(), StringComparer.Ordinal);
|
||||
var leapWindow = windows
|
||||
.Where(static window =>
|
||||
window.Status == MimirBridgeWindowStatus.Live &&
|
||||
window.SourceKind == MimirStreamKind.Video &&
|
||||
window.SampleDescriptor.PixelFormat == MimirVideoPixelFormat.LeapStereoIr &&
|
||||
window.Payload.HasResource &&
|
||||
!string.IsNullOrWhiteSpace(window.Payload.ResourceKey))
|
||||
.OrderByDescending(static window => window.EdgeNs)
|
||||
.FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(leapWindow.WindowId))
|
||||
{
|
||||
return AquariumFieldEvidenceFrame.Empty;
|
||||
}
|
||||
|
||||
var packedResourceKey = MimirFensalirBridgeMapper.ResourceKeyForPayload(leapWindow.Payload);
|
||||
if (!resourcesByKey.TryGetValue(packedResourceKey, out var packedInput))
|
||||
{
|
||||
return AquariumFieldEvidenceFrame.Empty;
|
||||
}
|
||||
|
||||
var profile = MimirStereoDepthConfigurations.D3D12SgmLibSgmProvenance;
|
||||
var sourceSegment = SanitizeResourceSegment(leapWindow.StreamId);
|
||||
var candidate = new MimirStereoDepthFieldCandidate(
|
||||
CandidateKey: $"live-{sourceSegment}-{leapWindow.SequenceId}",
|
||||
CalibrationId: "leapuvc-packed-stereo-ir-calibration-pending",
|
||||
CameraPairId: leapWindow.StreamId,
|
||||
ProducerKey: profile.Id,
|
||||
ProfileId: profile.Id,
|
||||
LeftObservationKey: $"{leapWindow.WindowId}:left-packed-r",
|
||||
RightObservationKey: $"{leapWindow.WindowId}:right-packed-g",
|
||||
LeftResourceKey: packedResourceKey,
|
||||
RightResourceKey: packedResourceKey,
|
||||
DisparityResourceKey: $"mimir:resource:stereo-depth:{sourceSegment}:disparity-r16f",
|
||||
ConfidenceResourceKey: $"mimir:resource:stereo-depth:{sourceSegment}:confidence-r8",
|
||||
Width: Math.Max(1, leapWindow.SampleDescriptor.Width),
|
||||
Height: Math.Max(1, leapWindow.SampleDescriptor.Height),
|
||||
MinDisparity: profile.MinDisparity,
|
||||
DisparityLevels: profile.DisparityLevels,
|
||||
AggregationPathCount: profile.AggregationPathCount,
|
||||
CensusRadius: profile.CensusRadius,
|
||||
SmoothnessPenaltySmall: profile.SmoothnessPenaltySmall,
|
||||
SmoothnessPenaltyLarge: profile.SmoothnessPenaltyLarge,
|
||||
MinDepthMeters: 0.20,
|
||||
MaxDepthMeters: 4.0,
|
||||
Confidence: 0.50,
|
||||
ObservedTimeNs: leapWindow.EdgeNs);
|
||||
return BuildStereoDepthCandidateFrame([candidate], [packedInput]);
|
||||
}
|
||||
|
||||
public AquariumFieldEvidenceFrame BuildStereoDepthCandidateFrame(
|
||||
IEnumerable<MimirStereoDepthFieldCandidate> depthCandidates,
|
||||
IEnumerable<AquariumFieldResourceDeclaration>? inputResources = null)
|
||||
|
|
@ -951,6 +1008,19 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
|
||||
private static string DomainKeyForSurfaceIntent(string intentKey) => $"mimir:intent:{intentKey}";
|
||||
|
||||
private static string SanitizeResourceSegment(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
var chars = value.Trim().ToLowerInvariant()
|
||||
.Select(static character => char.IsLetterOrDigit(character) ? character : '-')
|
||||
.ToArray();
|
||||
return chars.Length == 0 ? "unknown" : new string(chars);
|
||||
}
|
||||
|
||||
private static float Clamp01(float value) => Math.Clamp(value, 0.0f, 1.0f);
|
||||
|
||||
private static uint StableSeed(string key)
|
||||
|
|
|
|||
Loading…
Reference in a new issue