From 1826edbb9cb6abc48ae7c8ef608c6ec6944b7506 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 27 May 2026 23:34:44 +0100 Subject: [PATCH] Prove OBS program texture bridge --- docs/obs-stem-plugin.md | 17 ++++++++-- .../mimir_obs_program_texture_source.cpp | 24 ++++++-------- src/Mimir.Runtime/MimirRuntime.cs | 32 ++++++++++++++++++- state/evidence.jsonl | 1 + 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/docs/obs-stem-plugin.md b/docs/obs-stem-plugin.md index b33a840..aac1f8a 100644 --- a/docs/obs-stem-plugin.md +++ b/docs/obs-stem-plugin.md @@ -32,11 +32,22 @@ Shared D3D12 texture name: Global\MimirFensalirProgramTexture ``` OBS/libobs is D3D11 internally on Windows, so this source opens the named D3D12 -texture, creates an OBS-readable shared D3D11 texture, and performs a GPU-to-GPU -copy during OBS render before drawing the source. This avoids CPU readback and -does not require Spout2. It is not pure zero-copy yet; the remaining copy is the +texture, creates an OBS-readable legacy shared D3D11 texture, opens that same +bridge texture from D3D12, and performs a GPU-to-GPU copy during OBS render +before drawing the source. This avoids CPU readback and does not require +Spout2. It is not pure zero-copy yet; the remaining copy is the D3D12-to-libobs-D3D11 boundary. +For a visible interop witness while the real Mimir scene is sparse, launch +Mimir with: + +```text +MIMIR_OBS_PROOF_VISUAL=1 +``` + +That enables a small bright SDF/starfield proof visual. It is a debug witness, +not production scene policy. + ### Audio `MimirObsStemSharedMemoryPublisher` writes the latest validated diff --git a/native/obs_stem_source/mimir_obs_program_texture_source.cpp b/native/obs_stem_source/mimir_obs_program_texture_source.cpp index e897cf0..afc510c 100644 --- a/native/obs_stem_source/mimir_obs_program_texture_source.cpp +++ b/native/obs_stem_source/mimir_obs_program_texture_source.cpp @@ -248,7 +248,7 @@ static bool create_obs_bridge_texture(MimirProgramTextureSource *ctx) desc.SampleDesc.Count = 1; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE; + desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; HRESULT hr = ctx->d3d11_device->CreateTexture2D(&desc, nullptr, &ctx->bridge_texture_d3d11); if (FAILED(hr)) { @@ -256,32 +256,28 @@ static bool create_obs_bridge_texture(MimirProgramTextureSource *ctx) return false; } - ComPtr dxgi_resource; - hr = ctx->bridge_texture_d3d11.As(&dxgi_resource); + ComPtr legacy_resource; + hr = ctx->bridge_texture_d3d11.As(&legacy_resource); if (FAILED(hr)) { - blog(LOG_WARNING, "Mimir OBS program texture: bridge texture is not IDXGIResource1: 0x%08lx", static_cast(hr)); + blog(LOG_WARNING, "Mimir OBS program texture: bridge texture is not IDXGIResource: 0x%08lx", static_cast(hr)); return false; } - hr = dxgi_resource->CreateSharedHandle( - nullptr, - DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, - nullptr, - &ctx->bridge_shared_handle); - if (FAILED(hr)) { - blog(LOG_WARNING, "Mimir OBS program texture: CreateSharedHandle bridge failed: 0x%08lx", static_cast(hr)); + hr = legacy_resource->GetSharedHandle(&ctx->bridge_shared_handle); + if (FAILED(hr) || !ctx->bridge_shared_handle) { + blog(LOG_WARNING, "Mimir OBS program texture: GetSharedHandle bridge failed: 0x%08lx", static_cast(hr)); return false; } hr = ctx->d3d12_device->OpenSharedHandle(ctx->bridge_shared_handle, IID_PPV_ARGS(&ctx->bridge_texture_d3d12)); if (FAILED(hr)) { - blog(LOG_WARNING, "Mimir OBS program texture: D3D12 open bridge handle failed: 0x%08lx", static_cast(hr)); + blog(LOG_WARNING, "Mimir OBS program texture: D3D12 open legacy bridge handle failed: 0x%08lx", static_cast(hr)); return false; } - ctx->obs_texture = gs_texture_open_nt_shared(static_cast(reinterpret_cast(ctx->bridge_shared_handle))); + ctx->obs_texture = gs_texture_open_shared(static_cast(reinterpret_cast(ctx->bridge_shared_handle))); if (!ctx->obs_texture) { - blog(LOG_WARNING, "Mimir OBS program texture: OBS failed to open bridge shared texture"); + blog(LOG_WARNING, "Mimir OBS program texture: OBS failed to open legacy bridge shared texture"); return false; } diff --git a/src/Mimir.Runtime/MimirRuntime.cs b/src/Mimir.Runtime/MimirRuntime.cs index fbc9749..458f5a2 100644 --- a/src/Mimir.Runtime/MimirRuntime.cs +++ b/src/Mimir.Runtime/MimirRuntime.cs @@ -51,6 +51,7 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec private readonly float spectrumUpdateIntervalSeconds; private readonly int spectrumTubeSubdivisions; private readonly int spectrumSourceLaneCapacity; + private readonly bool obsProofVisualEnabled; private readonly float calibrationGain; private readonly float watermarkGain; private readonly bool syntheticSpectrumPreview; @@ -128,6 +129,7 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec spectrumUpdateIntervalSeconds = ParseSpectrumUpdateIntervalSeconds(); spectrumTubeSubdivisions = ParseSpectrumTubeSubdivisions(); spectrumSourceLaneCapacity = ParseSpectrumSourceLaneCapacity(); + obsProofVisualEnabled = IsTruthy(Environment.GetEnvironmentVariable("MIMIR_OBS_PROOF_VISUAL")); calibrationGain = settings.Audio.CalibrationGain; watermarkGain = settings.Audio.WatermarkGain; syntheticSpectrumPreview = IsTruthy(Environment.GetEnvironmentVariable("MIMIR_SYNTHETIC_SPECTRUM_PREVIEW")); @@ -188,13 +190,41 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec new AquariumSceneState { TraceHeightFieldSurface = false, - UseStarfieldBackground = false, + UseStarfieldBackground = obsProofVisualEnabled, + SdfObjects = obsProofVisualEnabled ? BuildObsProofSdfObjects(runtimeSeconds) : [], + SdfLights = obsProofVisualEnabled ? BuildObsProofSdfLights(runtimeSeconds) : [], FieldEvidenceFrame = fieldEvidenceFrame, BufferFieldFrame = AquariumBufferFieldFrame.Empty, SplineFrame = AquariumSplineFrame.Empty, }); } + private static AquariumSdfObject[] BuildObsProofSdfObjects(float timeSeconds) + { + var center = new Vector3(MathF.Sin(timeSeconds * 0.8f) * 1.2f, 0.25f, 0.0f); + return + [ + new AquariumSdfObject( + new Vector4(center, 1.2f), + new Vector4(center, 0.0f), + new Vector4(1.0f, timeSeconds, 0.0f, 0.0f)) + ]; + } + + private static AquariumSdfLight[] BuildObsProofSdfLights(float timeSeconds) + { + var lightOrbit = new Vector3(MathF.Cos(timeSeconds) * 2.0f, 1.8f, MathF.Sin(timeSeconds) * 2.0f); + return + [ + new AquariumSdfLight( + new Vector4(lightOrbit, 3.0f), + new Vector4(4.0f, 0.9f, 0.2f, 10.0f)), + new AquariumSdfLight( + new Vector4(-1.8f, 1.0f, 2.5f, 2.0f), + new Vector4(0.1f, 1.4f, 3.6f, 10.0f)) + ]; + } + private AquariumFieldEvidenceFrame BuildFieldEvidenceFrame() { var buffers = synchronization.Buffers.Buffers; diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 035da30..3f9114c 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -195,3 +195,4 @@ {"ts": "2026-05-27T21:29:19+01:00", "type": "verification", "status": "ok", "note": "Added scripts/install-obs-mimir-plugin.ps1 as the installation boundary for the native OBS plugin. It can build/copy mimir_obs_stem_source.dll into an OBS root's obs-plugins\\\\64bit directory, supports OBS_STUDIO_ROOT or -ObsRoot for portable installs, and -WhatIf verified the local standard OBS path without writing into Program Files."} {"ts": "2026-05-27T21:30:23+01:00", "type": "verification", "status": "ok", "note": "The OBS plugin install path now uses OBS's plugin package layout under C:\\\\ProgramData\\\\obs-studio\\\\plugins by default instead of requiring writes to C:\\\\Program Files. scripts/install-obs-mimir-plugin.ps1 -SkipBuild installed mimir_obs_stem_source.dll to C:\\\\ProgramData\\\\obs-studio\\\\plugins\\\\mimir_obs_stem_source\\\\bin\\\\64bit, registering Mimir Program Texture and Mimir Audio Stem for the next OBS launch."} {"ts": "2026-05-27T21:31:36+01:00", "type": "verification", "status": "ok", "note": "Installed Mimir OBS plugin was loaded by local OBS Studio 32.1.2 from C:\\\\ProgramData\\\\obs-studio\\\\plugins\\\\mimir_obs_stem_source\\\\bin\\\\64bit. A hidden launch/kill smoke produced OBS log line 'Mimir OBS sources loaded' and listed mimir_obs_stem_source.dll. OBS also warned that en-US text was missing for the module; locale packaging is cosmetic but should be cleaned before distribution. Live video rendering still needs an OBS scene source while Fensalir publishes Global\\\\MimirFensalirProgramTexture."} +{"ts": "2026-05-27T23:34:13+01:00", "type": "verification", "status": "ok", "note": "Live OBS program texture proof succeeded. With Mimir/Fensalir publishing Global\\\\MimirFensalirProgramTexture at 1264x681 and MIMIR_OBS_PROOF_VISUAL=1, OBS 32.1.2 loaded mimir_obs_stem_source.dll, the Mimir Program Texture source opened the shared texture, and the user visually confirmed the Fensalir debug/proof scene in OBS. The working bridge uses a legacy shared D3D11 texture because libobs accepts that handle path; D3D12 opens the same bridge texture and copies GPU-to-GPU from the Fensalir D3D12 program texture. This removes Spout2 and CPU readback from the program-video proof path while retaining the explicit D3D12-to-D3D11 boundary copy."}