Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

phase-5 work: R3.1b veyra_guidance library (IGuidanceProvider + ZeroGuidanceProvider GPU-verified 13/13)

Veyra Goal Agent972377ad0143
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85c07729..c7138ff1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,6 +181,31 @@ target_compile_definitions(veyra_unified_tests PRIVATE
target_include_directories(veyra_unified_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(veyra_unified_tests PRIVATE d3d12 veyra_gfx veyra_ngx)
+# Guidance product library (Playbook R3/R4): providers produce the unified
+# GuidanceFrame. First real member: ZeroGuidanceProvider (honest fallback).
+# NvofGuidanceProvider moves in from player_probe during R3.2.
+add_library(veyra_guidance STATIC
+ src/guidance/ZeroGuidanceProvider.cpp
+)
+veyra_apply_warnings(veyra_guidance)
+target_compile_options(veyra_guidance PRIVATE /WX-)
+target_compile_features(veyra_guidance PRIVATE cxx_std_20)
+target_compile_definitions(veyra_guidance PRIVATE
+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)
+target_include_directories(veyra_guidance PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
+target_link_libraries(veyra_guidance PUBLIC veyra_pipeline veyra_gfx veyra_base d3d12 dxgi dxguid)
+
+add_executable(veyra_guidance_tests
+ tests/integration/GuidanceProviderTests.cpp
+)
+veyra_apply_warnings(veyra_guidance_tests)
+target_compile_options(veyra_guidance_tests PRIVATE /WX-)
+target_compile_features(veyra_guidance_tests PRIVATE cxx_std_20)
+target_compile_definitions(veyra_guidance_tests PRIVATE
+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)
+target_include_directories(veyra_guidance_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
+target_link_libraries(veyra_guidance_tests PRIVATE veyra_guidance)
+
# Pipeline product library (Playbook R2/R3): data contracts + reset coordinator.
# Grows in R3 as the real GPU graph migrates out of the probes.
add_library(veyra_pipeline STATIC
diff --git a/include/veyra/guidance/IGuidanceProvider.h b/include/veyra/guidance/IGuidanceProvider.h
new file mode 100644
index 00000000..9f286695
--- /dev/null
+++ b/include/veyra/guidance/IGuidanceProvider.h
@@ -0,0 +1,45 @@
+#pragma once
+
+// IGuidanceProvider - the guidance producer contract (Playbook R2/R4).
+// Providers run on the render thread's command context; motion is always
+// current -> previous in post-SR workingExtent pixels, depth is R32F
+// normalized relative depth, confidence is R8_UNORM (1 trust, 0 reject).
+#include <cstdint>
+
+#include "veyra/pipeline/FramePacket.h"
+#include "veyra/pipeline/FrameWindow.h"
+#include "veyra/pipeline/GuidanceFrame.h"
+#include "veyra/pipeline/ResetCoordinator.h"
+
+namespace veyra::guidance {
+
+namespace pipeline = veyra::pipeline; // qualified access to the data contracts
+
+struct GuidanceConfig {
+ uint32_t workingWidth = 0; // post-SR extent (== source extent when SR bypasses)
+ uint32_t workingHeight = 0;
+ uint32_t lookaheadFrames = 0; // 0/1/2 bounded mode
+ bool enableDepth = false; // DAV2; V1 zero provider reports depth as zero
+ uint32_t depthIntervalFrames = 1;
+};
+
+class IGuidanceProvider {
+public:
+ virtual ~IGuidanceProvider() = default;
+
+ // Creates GPU resources for the configured working extent. The device and
+ // command context are supplied by the owning graph (render thread only).
+ virtual bool initialize(const GuidanceConfig& config) = 0;
+
+ // Produces guidance for window.current. Must not consume history from a
+ // different epoch (first frame after reset yields zero motion).
+ virtual bool produce(const pipeline::FrameWindow& window, pipeline::GuidanceFrame& out) = 0;
+
+ // Reset temporal state; providers drop history at the epoch boundary.
+ virtual void reset(uint64_t epoch, pipeline::ResetReason reason) noexcept = 0;
+
+ // Honest identity for logging/UI/gates.
+ virtual pipeline::GuidanceProvenance provenance() const noexcept = 0;
+};
+
+} // namespace veyra::guidance
diff --git a/include/veyra/guidance/ZeroGuidanceProvider.h b/include/veyra/guidance/ZeroGuidanceProvider.h
new file mode 100644
index 00000000..a2af25de
--- /dev/null
+++ b/include/veyra/guidance/ZeroGuidanceProvider.h
@@ -0,0 +1,52 @@
+#pragma once
+
+// ZeroGuidanceProvider - the honest fallback guidance producer (Product Spec
+// 8.1: Zero is the LAST fallback, never a substitute for NVOF). Owns the three
+// guidance textures at the working extent and zero-initializes them via an
+// upload-buffer copy (the ClearUnorderedAccessViewFloat-segfault-free path
+// proven in Phase 1). Every produced GuidanceFrame reports provenance=Zero so
+// gates/UI/logs can never mistake it for real motion.
+#include <cstdint>
+
+#include "veyra/gfx/D3D12DeviceContext.h"
+#include "veyra/guidance/IGuidanceProvider.h"
+
+namespace veyra::guidance {
+
+namespace pipeline = veyra::pipeline; // qualified access to the data contracts
+
+class ZeroGuidanceProvider final : public IGuidanceProvider {
+public:
+ ZeroGuidanceProvider(gfx::D3D12DeviceContext& context);
+ ~ZeroGuidanceProvider() override;
+
+ bool initialize(const GuidanceConfig& config) override;
+ bool produce(const pipeline::FrameWindow& window, pipeline::GuidanceFrame& out) override;
+ void reset(uint64_t epoch, pipeline::ResetReason reason) noexcept override;
+ pipeline::GuidanceProvenance provenance() const noexcept override {
+ return pipeline::GuidanceProvenance::Zero;
+ }
+
+ // Diagnostic (tests only): textures are valid and sized to the extent.
+ bool resourcesReady() const { return ready_; }
+ uint32_t workingWidth() const { return width_; }
+ uint32_t workingHeight() const { return height_; }
+
+private:
+ bool createZeroedTexture(unsigned pixelBytesPerPixel, DXGI_FORMAT format,
+ gfx::ComPtr<ID3D12Resource>& out);
+
+ gfx::D3D12DeviceContext& context_;
+ GuidanceConfig config_{};
+ gfx::ComPtr<ID3D12Resource> motion_;
+ gfx::ComPtr<ID3D12Resource> depth_;
+ gfx::ComPtr<ID3D12Resource> confidence_;
+ gfx::ComPtr<ID3D12Resource> upload_;
+ bool ready_ = false;
+ uint32_t width_ = 0;
+ uint32_t height_ = 0;
+ uint64_t epoch_ = 1;
+ uint64_t producedFrames_ = 0;
+};
+
+} // namespace veyra::guidance
diff --git a/loop/JOURNAL.md b/loop/JOURNAL.md
index 2c81f750..dc87e190 100644
--- a/loop/JOURNAL.md
+++ b/loop/JOURNAL.md
@@ -944,6 +944,32 @@ C staged teardown 定位崩溃=swapChain_.Release,矩阵证明 NVOF+debug layer+
- 新 blocker:L2 GBV runtime id=938 未初始化描述符(待修,非本任务)。
- 未执行:query-heap GPU timestamp(用户明令禁止);Reviewer/checkpoint(未授权)。
+## Cycle 035 — R3.1b veyra_guidance:接口 + ZeroGuidanceProvider(2026-09-06 Goal)
+
+### Before
+
+- Phase: 5(重开,in_progress)
+- 唯一任务: 建立 `veyra_guidance` 产品库:IGuidanceProvider 接口(initialize/produce/reset/provenance,基于 pipeline 契约 FrameWindow/GuidanceFrame)+ GuidanceConfig + **ZeroGuidanceProvider 真实 GPU 实现**(创建 RG16F motion/R32F depth/R8 confidence 三纹理,upload-copy 零初始化——Phase 1 已验证路径;reset 后首帧强制零运动;provenance=Zero 诚实上报)+ GPU 集成测试(真实 D3D12 device,readback 验证全零与元数据——诊断性 readback 允许在测试中)。NvofGuidanceProvider 不在本轮:它将在 R3.2 从 player_probe 直接移入,避免复制出第二份 NVOF 实现。
+- 可证伪假设: 若零初始化或元数据语义错误,GPU 测试的 readback 断言将失败;若库是空壳,gate 的 product:veyra_guidance-target 检查虽绿但新增集成测试红——两者必须同时绿才算数。
+- 预计修改文件: include/veyra/guidance/{IGuidanceProvider,ZeroGuidanceProvider}.h、src/guidance/ZeroGuidanceProvider.cpp、tests/integration/GuidanceProviderTests.cpp、CMakeLists.txt。
+- 快速检查命令: `build x64-debug/-release` → 0;`veyra_guidance_tests.exe` 双配置 → 0;`phase5.ps1` → 仍 exit 1 但 product:veyra_guidance-target PASS。
+- 预期新增证据: GPU 集成测试全零断言 + provenance/epoch 元数据断言。
+
+### After
+
+- 实际修改: include/veyra/guidance/{IGuidanceProvider,ZeroGuidanceProvider}.h、src/guidance/ZeroGuidanceProvider.cpp、tests/integration/GuidanceProviderTests.cpp(真实 RTX device 集成测试,诊断性 readback 仅限测试)、CMakeLists.txt(veyra_guidance STATIC PUBLIC veyra_pipeline/veyra_gfx/veyra_base + veyra_guidance_tests)。
+- 实现要点: 接口 initialize/produce/reset/provenance 基于 pipeline 契约(FrameWindow/GuidanceFrame 均限定 pipeline::);ZeroGuidanceProvider 创建 RG16F/R32F/R8 三纹理,upload-copy 零初始化(Phase 1 验证路径,非 ClearUAV),一次性 init fence wait(Playbook 允许 create 等待一次);produce 填充完整 GpuTextureHandle(expectedState=SRV、extent、format)+ provenance=Zero + sourceSequence/sourceEpoch + epoch 边界 requiresReset 标志(resetReason 由 graph 从 coordinator 填,provider 不猜理由)。
+- 实际命令与 exit code:
+ - `build x64-debug/-release` → 修 4 轮编译错误后双 0(guidance 命名空间内 FrameWindow/GuidanceFrame 未限定;copy-location 枚举名误写 LOCATION;Status 命名空间;残留未限定 GuidanceFrame)。
+ - `veyra_guidance_tests.exe` Debug → 首轮 13/16:**3 个 GPU readback 检查失败,根因是测试自身 bug**(staging 只分配 8 行却复制整张 1080 行纹理=溢出读垃圾;provider 零初始化本身正确);CopyTextureRegion 加 D3D12_BOX 限定后 **13/13 双配置 exit 0**(真实验证:RTX 5070、RG16F/R32F/R8 三纹理 GPU 内容全零、provenance/metadata/epoch 边界断言全过)。
+ - `phase5.ps1` → exit 1,**29/45**;product:veyra_guidance-target PASS(真实成员非空壳——GPU 测试是同时绿的前提)。
+- 失败 fingerprint: tests|guidance-readback|1|staging-undersized-for-full-texture-copy → box 限定复制区域,第 1 轮修复(测试 bug,非产品 bug)。
+- 是否有进展,依据: 是——产品 guidance 库从无到有,ZeroGuidanceProvider 在真实 GPU 上验证;R4 的 Zero 语义(诚实回退)有机器证据。
+- STATE/BACKLOG 更新: cycle.completed=35;nextAction → R3.1c veyra_sources。
+- 下一唯一动作: R3.1c — 建立 `veyra_sources`(MediaFileSource 组合现有产品库 veyra_media 的 FFmpegDemuxer+FFmpegVideoDecoder,输出 pipeline::FramePacket 契约;无第二份解码实现)。
+
+---
+
## Cycle 034 — R3.1a veyra_sinks:WASAPI 音频迁出 player_probe(2026-09-06 Goal)
### Before
diff --git a/loop/STATE.json b/loop/STATE.json
index db510b43..8469ab37 100644
--- a/loop/STATE.json
+++ b/loop/STATE.json
@@ -76,14 +76,14 @@
}
],
"cycle": {
- "completed": 34,
+ "completed": 35,
"maximum": 120,
"sameFailureAttempts": 0,
"maximumSameFailureAttempts": 3,
"noProgressCycles": 0,
"maximumNoProgressCycles": 5
},
- "currentTask": "R3.1a complete (Cycle 034): WASAPI audio (AudioPipeline watermark ring + AudioRenderer event-driven PTS-anchored clock) extracted verbatim from player_probe into product library veyra_sinks. player_probe 3641->3128 lines, audio behavior verified unchanged (underruns=0 overruns=0 seekCount=11, exit 12 drift FAIL unchanged). Gate gained product:sinks/sources/player-links-sinks checks (45 total, 30 fail) and the player-links-pipeline false positive was fixed.",
+ "currentTask": "R3.1b complete (Cycle 035): veyra_guidance product library created with real members (IGuidanceProvider contract + ZeroGuidanceProvider GPU implementation). GuidanceProviderTests 13/13 debug+release on RTX 5070 (three guidance textures verified all-zero via diagnostic readback; provenance/sequence/epoch-boundary metadata asserted). Phase5 gate 29/45 (product:veyra_guidance-target green).",
"lastGate": {
"name": "phase5",
"status": "invalidated_requires_rebuild",
@@ -106,6 +106,6 @@
"A real DirectShow/UVC 4K60 SDR capture device, HDMI audio, and 4K60 source signal are required before P7 capture gate can pass.",
"Public distribution rights for the experimental DLSSNR runtime and all bundled NVIDIA/model/FFmpeg assets are unresolved; a local release candidate is allowed, public launch is blocked."
],
- "nextAction": "Playbook R3.1b: create veyra_guidance product library with real members (ZeroGuidanceProvider, NvofGuidanceProvider wrapping the verified NvOfSession with B8G8R8A8/S10.5 grid-4 cost contract, GuidanceValidator with cost/luma-warp-residual/out-of-frame confidence inputs); then R3.1c veyra_sources MediaFileSource. After all four libraries exist: R3.2 move the real GPU chain (upload/YUV/SR/NVOF/parity/NR/FG) into EnhanceGraph so product:enhance-graph-submits-gpu can pass.",
- "updatedAt": "2026-09-06T17:55:00+08:00"
+ "nextAction": "Playbook R3.1c: create veyra_sources product library with MediaFileSource composing the existing veyra_media FFmpegDemuxer+FFmpegVideoDecoder into pipeline::FramePacket production (no second decode implementation). Then R3.2: move the real GPU chain from player_probe into EnhanceGraph (src/pipeline/EnhanceGraph.cpp must ExecuteCommandLists + NGX evaluate), born together with NvofGuidanceProvider migrating out of the probe.",
+ "updatedAt": "2026-09-06T18:05:00+08:00"
}
diff --git a/src/guidance/ZeroGuidanceProvider.cpp b/src/guidance/ZeroGuidanceProvider.cpp
new file mode 100644
index 00000000..faf91987
--- /dev/null
+++ b/src/guidance/ZeroGuidanceProvider.cpp
@@ -0,0 +1,214 @@
+#include "veyra/guidance/ZeroGuidanceProvider.h"
+
+#include <cstring>
+#include <format>
+
+#include "veyra/Log.h"
+
+namespace veyra::guidance {
+
+using gfx::ComPtr;
+
+ZeroGuidanceProvider::ZeroGuidanceProvider(gfx::D3D12DeviceContext& context)
+ : context_(context)
+{
+}
+
+ZeroGuidanceProvider::~ZeroGuidanceProvider()
+{
+ // ComPtr release order is declaration order within this class; the
+ // textures do not depend on each other, only on the device, which
+ // outlives the provider (owned by the graph's render-thread context).
+ ready_ = false;
+}
+
+bool ZeroGuidanceProvider::createZeroedTexture(unsigned bytesPerPixel, DXGI_FORMAT format,
+ ComPtr<ID3D12Resource>& out)
+{
+ ID3D12Device* device = context_.device();
+ D3D12_HEAP_PROPERTIES hp{};
+ hp.Type = D3D12_HEAP_TYPE_DEFAULT;
+ D3D12_RESOURCE_DESC td{};
+ td.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
+ td.Width = width_;
+ td.Height = height_;
+ td.DepthOrArraySize = 1;
+ td.MipLevels = 1;
+ td.Format = format;
+ td.SampleDesc.Count = 1;
+ td.Flags = D3D12_RESOURCE_FLAG_NONE; // SRV-consumed; no UAV needed
+ ComPtr<ID3D12Resource> tex;
+ HRESULT hr = device->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &td,
+ D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&tex));
+ if (FAILED(hr)) {
+ veyra::log::error("guidance-zero", std::format(
+ "texture alloc failed {}x{} fmt=0x{:X} hr=0x{:X}",
+ width_, height_, static_cast<unsigned>(format), static_cast<unsigned>(hr)));
+ return false;
+ }
+
+ // Upload-copy zero init (Phase 1 lesson: ClearUnorderedAccessViewFloat
+ // segfaulted on this machine; the copy path is the proven equivalent).
+ const uint64_t rowBytes = static_cast<uint64_t>(width_) * bytesPerPixel;
+ const uint64_t rowPitch = (rowBytes + 255) & ~255ull; // 256-aligned rows
+ const uint64_t uploadSize = rowPitch * height_;
+ uint8_t* mapped = nullptr;
+ D3D12_RANGE readRange{0, 0};
+ hr = upload_->Map(0, &readRange, reinterpret_cast<void**>(&mapped));
+ if (FAILED(hr) || mapped == nullptr) {
+ veyra::log::error("guidance-zero", std::format("upload map failed hr=0x{:X}",
+ static_cast<unsigned>(hr)));
+ return false;
+ }
+ for (uint32_t y = 0; y < height_; ++y) {
+ std::memset(mapped + y * rowPitch, 0, rowBytes);
+ }
+ upload_->Unmap(0, nullptr);
+
+ D3D12_TEXTURE_COPY_LOCATION src{};
+ src.pResource = upload_.Get();
+ src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
+ src.PlacedFootprint.Footprint.Format = format;
+ src.PlacedFootprint.Footprint.Width = width_;
+ src.PlacedFootprint.Footprint.Height = height_;
+ src.PlacedFootprint.Footprint.Depth = 1;
+ src.PlacedFootprint.Footprint.RowPitch = static_cast<UINT>(rowPitch);
+ D3D12_TEXTURE_COPY_LOCATION dst{};
+ dst.pResource = tex.Get();
+ dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ dst.SubresourceIndex = 0;
+
+ ID3D12CommandAllocator* allocator = nullptr;
+ hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
+ IID_PPV_ARGS(&allocator));
+ ComPtr<ID3D12CommandAllocator> allocatorGuard(allocator);
+ if (FAILED(hr)) { return false; }
+ ID3D12GraphicsCommandList* list = nullptr;
+ hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator, nullptr,
+ IID_PPV_ARGS(&list));
+ ComPtr<ID3D12GraphicsCommandList> listGuard(list);
+ if (FAILED(hr)) { return false; }
+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
+ D3D12_RESOURCE_BARRIER b{};
+ b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ b.Transition.pResource = tex.Get();
+ b.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
+ b.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &b);
+ list->Close();
+ ID3D12CommandList* lists[] = {list};
+ context_.directQueue()->ExecuteCommandLists(1, lists);
+
+ // One-time initialization wait (Playbook: create/resize may wait once).
+ const uint64_t waitValue = context_.fenceCompletedValue() + 1;
+ context_.directQueue()->Signal(context_.fence(), waitValue);
+ if (!context_.waitForFenceValue(waitValue)) {
+ veyra::log::error("guidance-zero", "init fence wait failed");
+ return false;
+ }
+ out = tex;
+ return true;
+}
+
+bool ZeroGuidanceProvider::initialize(const GuidanceConfig& config)
+{
+ if (!context_.initialized()) {
+ veyra::log::error("guidance-zero", "device context not initialized");
+ return false;
+ }
+ if (config.workingWidth == 0 || config.workingHeight == 0) {
+ veyra::log::error("guidance-zero", "working extent must be nonzero");
+ return false;
+ }
+ config_ = config;
+ width_ = config.workingWidth;
+ height_ = config.workingHeight;
+
+ // One upload buffer sized for the largest plane (confidence R8 = 1 B/px;
+ // motion RG16F = 8 B/px row pitch dominates after alignment).
+ const uint64_t rowBytes = static_cast<uint64_t>(width_) * 8;
+ const uint64_t rowPitch = (rowBytes + 255) & ~255ull;
+ D3D12_HEAP_PROPERTIES up{};
+ up.Type = D3D12_HEAP_TYPE_UPLOAD;
+ D3D12_RESOURCE_DESC bd{};
+ bd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
+ bd.Width = rowPitch * height_;
+ bd.Height = 1; bd.DepthOrArraySize = 1; bd.MipLevels = 1;
+ bd.SampleDesc.Count = 1;
+ bd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ HRESULT hr = context_.device()->CreateCommittedResource(&up, D3D12_HEAP_FLAG_NONE, &bd,
+ D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&upload_));
+ if (FAILED(hr)) {
+ veyra::log::error("guidance-zero", std::format("upload alloc failed hr=0x{:X}",
+ static_cast<unsigned>(hr)));
+ return false;
+ }
+
+ motion_.Reset(); depth_.Reset(); confidence_.Reset();
+ if (!createZeroedTexture(8, DXGI_FORMAT_R16G16_FLOAT, motion_)) return false;
+ if (!createZeroedTexture(4, DXGI_FORMAT_R32_FLOAT, depth_)) return false;
+ if (!createZeroedTexture(1, DXGI_FORMAT_R8_UNORM, confidence_)) return false;
+
+ ready_ = true;
+ veyra::log::info("guidance-zero", std::format(
+ "initialized {}x{} (RG16F motion / R32F depth / R8 confidence, all zero)",
+ width_, height_));
+ return true;
+}
+
+bool ZeroGuidanceProvider::produce(const pipeline::FrameWindow& window, pipeline::GuidanceFrame& out)
+{
+ if (!ready_) {
+ veyra::log::error("guidance-zero", "produce before initialize");
+ return false;
+ }
+ if (window.current == nullptr) {
+ veyra::log::error("guidance-zero", "produce without current frame");
+ return false;
+ }
+
+ out = pipeline::GuidanceFrame{};
+ out.motion.resource = motion_.Get();
+ out.motion.expectedState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ out.motion.ownerSlot = 0;
+ out.motion.readyFenceValue = 0; // static content, ready immediately
+ out.motion.width = width_;
+ out.motion.height = height_;
+ out.motion.format = DXGI_FORMAT_R16G16_FLOAT;
+
+ out.depth.resource = depth_.Get();
+ out.depth.expectedState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ out.depth.width = width_;
+ out.depth.height = height_;
+ out.depth.format = DXGI_FORMAT_R32_FLOAT;
+
+ out.confidence.resource = confidence_.Get();
+ out.confidence.expectedState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ out.confidence.width = width_;
+ out.confidence.height = height_;
+ out.confidence.format = DXGI_FORMAT_R8_UNORM;
+
+ out.provenance = pipeline::GuidanceProvenance::Zero;
+ out.sourceSequence = window.current->sequence;
+ out.sourceEpoch = window.current->sourceEpoch;
+ out.depthAgeFrames = 0;
+ // Zero motion after an epoch change is not a fallback event - it is the
+ // only legal content for this provider. The graph fills resetReason from
+ // the ResetCoordinator; the provider only reports the boundary flag.
+ out.requiresReset = window.current->sourceEpoch != epoch_;
+ out.resetReason = pipeline::ResetReason::None;
+ epoch_ = window.current->sourceEpoch;
+ ++producedFrames_;
+ return true;
+}
+
+void ZeroGuidanceProvider::reset(uint64_t epoch, pipeline::ResetReason reason) noexcept
+{
+ // Textures are static zeros; resetting only drops the provider's epoch
+ // association so the next produce() reports requiresReset truthfully.
+ epoch_ = epoch ? epoch : 1;
+ (void)reason;
+}
+
+} // namespace veyra::guidance
diff --git a/tests/integration/GuidanceProviderTests.cpp b/tests/integration/GuidanceProviderTests.cpp
new file mode 100644
index 00000000..aeb175a8
--- /dev/null
+++ b/tests/integration/GuidanceProviderTests.cpp
@@ -0,0 +1,183 @@
+// Guidance provider integration tests - real D3D12 device (RTX), diagnostic
+// readback allowed in tests only (the normal path never reads back).
+// Verifies ZeroGuidanceProvider: textures exist at the working extent, GPU
+// contents are all zero, metadata (provenance/sequence/epoch/reset flag) is
+// honest, and the reset boundary flag behaves.
+#include <cstdio>
+#include <cstring>
+#include <vector>
+
+#include "veyra/gfx/D3D12DeviceContext.h"
+#include "veyra/guidance/ZeroGuidanceProvider.h"
+
+using namespace veyra;
+using namespace veyra::guidance;
+
+namespace {
+
+int g_checks = 0;
+int g_failures = 0;
+
+void check(const char* name, bool ok) {
+ ++g_checks;
+ if (!ok) { ++g_failures; std::printf(" [FAIL] %s\n", name); }
+ else { std::printf(" [PASS] %s\n", name); }
+}
+
+// Diagnostic readback of a texture's first row region through a staging
+// texture (test-only path).
+bool readbackFirstPixels(gfx::D3D12DeviceContext& ctx, ID3D12Resource* tex,
+ DXGI_FORMAT format, uint32_t w, uint32_t h, std::vector<uint8_t>& out)
+{
+ const unsigned bpp = (format == DXGI_FORMAT_R16G16_FLOAT) ? 8
+ : (format == DXGI_FORMAT_R32_FLOAT) ? 4 : 1;
+ const uint64_t rowBytes = static_cast<uint64_t>(w) * bpp;
+ const uint64_t rowPitch = (rowBytes + 255) & ~255ull;
+
+ D3D12_HEAP_PROPERTIES rp{};
+ rp.Type = D3D12_HEAP_TYPE_READBACK;
+ D3D12_RESOURCE_DESC bd{};
+ bd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
+ bd.Width = rowPitch * h;
+ bd.Height = 1; bd.DepthOrArraySize = 1; bd.MipLevels = 1;
+ bd.SampleDesc.Count = 1;
+ bd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ gfx::ComPtr<ID3D12Resource> staging;
+ if (FAILED(ctx.device()->CreateCommittedResource(&rp, D3D12_HEAP_FLAG_NONE, &bd,
+ D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&staging)))) {
+ return false;
+ }
+ gfx::ComPtr<ID3D12CommandAllocator> allocator;
+ if (FAILED(ctx.device()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT,
+ IID_PPV_ARGS(&allocator)))) { return false; }
+ gfx::ComPtr<ID3D12GraphicsCommandList> list;
+ if (FAILED(ctx.device()->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT,
+ allocator.Get(), nullptr, IID_PPV_ARGS(&list)))) { return false; }
+
+ D3D12_RESOURCE_BARRIER toSrc{};
+ toSrc.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ toSrc.Transition.pResource = tex;
+ toSrc.Transition.StateBefore = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ toSrc.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
+ toSrc.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &toSrc);
+
+ D3D12_TEXTURE_COPY_LOCATION src{};
+ src.pResource = tex;
+ src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ src.SubresourceIndex = 0;
+ D3D12_TEXTURE_COPY_LOCATION dst{};
+ dst.pResource = staging.Get();
+ dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
+ dst.PlacedFootprint.Footprint.Format = format;
+ dst.PlacedFootprint.Footprint.Width = w;
+ dst.PlacedFootprint.Footprint.Height = h;
+ dst.PlacedFootprint.Footprint.Depth = 1;
+ dst.PlacedFootprint.Footprint.RowPitch = static_cast<UINT>(rowPitch);
+ // Copy only the first rows via a box: the staging buffer is sized for
+ // this region, not the whole texture.
+ D3D12_BOX box{0, 0, 0, w, h, 1};
+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, &box);
+ D3D12_RESOURCE_BARRIER back{};
+ back.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ back.Transition.pResource = tex;
+ back.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE;
+ back.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ back.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &back);
+ list->Close();
+ ID3D12CommandList* lists[] = {list.Get()};
+ ctx.directQueue()->ExecuteCommandLists(1, lists);
+ const uint64_t v = ctx.fenceCompletedValue() + 1;
+ ctx.directQueue()->Signal(ctx.fence(), v);
+ if (!ctx.waitForFenceValue(v)) { return false; }
+
+ out.resize(rowBytes);
+ D3D12_RANGE wr{0, rowBytes};
+ uint8_t* mapped = nullptr;
+ if (FAILED(staging->Map(0, &wr, reinterpret_cast<void**>(&mapped)))) { return false; }
+ std::memcpy(out.data(), mapped, rowBytes);
+ staging->Unmap(0, nullptr);
+ return true;
+}
+
+} // namespace
+
+int main() {
+ std::printf("guidance-provider: device bootstrap\n");
+ gfx::D3D12DeviceContext ctx;
+ gfx::DeviceContextDesc desc;
+ desc.enableDebugLayer = false;
+ Status status;
+ if (!ctx.initialize(desc, status)) {
+ std::printf("guidance-provider: device init FAILED (no GPU run)\n");
+ return 1;
+ }
+
+ std::printf("guidance-provider: zero provider initialize\n");
+ GuidanceConfig cfg;
+ cfg.workingWidth = 1920;
+ cfg.workingHeight = 1080;
+ ZeroGuidanceProvider zero(ctx);
+ check("zero:initialize", zero.initialize(cfg));
+ check("zero:extent", zero.workingWidth() == 1920 && zero.workingHeight() == 1080);
+
+ std::printf("guidance-provider: produce + metadata\n");
+ pipeline::FramePacket cur;
+ cur.sequence = 5;
+ cur.pts = pipeline::Rational{5005, 60000};
+ cur.sourceKind = pipeline::SourceKind::TestPattern;
+ cur.sourceEpoch = 3;
+ cur.color.resource = reinterpret_cast<ID3D12Resource*>(0x1);
+ cur.color.width = 1920; cur.color.height = 1080;
+ cur.color.format = DXGI_FORMAT_R16G16B16A16_FLOAT;
+ pipeline::FrameWindow window;
+ window.current = &cur;
+
+ pipeline::GuidanceFrame g;
+ check("zero:produce", zero.produce(window, g));
+ check("zero:provenance-honest", g.provenance == pipeline::GuidanceProvenance::Zero);
+ check("zero:metadata", g.sourceSequence == 5 && g.sourceEpoch == 3);
+ check("zero:extents-match", g.extentsMatch(1920, 1080));
+ check("zero:valid", g.valid());
+
+ std::printf("guidance-provider: reset boundary flag\n");
+ pipeline::FramePacket cur2 = cur;
+ cur2.sequence = 6;
+ cur2.sourceEpoch = 4; // epoch advanced between frames
+ pipeline::FrameWindow window2;
+ window2.current = &cur2;
+ pipeline::GuidanceFrame g2;
+ check("zero:produce-after-epoch-change", zero.produce(window2, g2));
+ check("zero:requires-reset-flag", g2.requiresReset);
+ pipeline::GuidanceFrame g3;
+ check("zero:produce-same-epoch-no-reset", zero.produce(window2, g3) && !g3.requiresReset);
+
+ std::printf("guidance-provider: gpu zero verification (diagnostic readback)\n");
+ std::vector<uint8_t> bytes;
+ bool allZero = true;
+ if (readbackFirstPixels(ctx, g.motion.resource, DXGI_FORMAT_R16G16_FLOAT, 1920, 8, bytes)) {
+ for (uint8_t b : bytes) { if (b != 0) { allZero = false; break; } }
+ check("zero:motion-gpu-all-zero", allZero);
+ } else {
+ check("zero:motion-gpu-all-zero", false);
+ }
+ allZero = true;
+ if (readbackFirstPixels(ctx, g.depth.resource, DXGI_FORMAT_R32_FLOAT, 1920, 8, bytes)) {
+ for (uint8_t b : bytes) { if (b != 0) { allZero = false; break; } }
+ check("zero:depth-gpu-all-zero", allZero);
+ } else {
+ check("zero:depth-gpu-all-zero", false);
+ }
+ allZero = true;
+ if (readbackFirstPixels(ctx, g.confidence.resource, DXGI_FORMAT_R8_UNORM, 1920, 8, bytes)) {
+ for (uint8_t b : bytes) { if (b != 0) { allZero = false; break; } }
+ check("zero:confidence-gpu-all-zero", allZero);
+ } else {
+ check("zero:confidence-gpu-all-zero", false);
+ }
+
+ ctx.shutdown();
+ std::printf("guidance-provider: %d checks, %d failures\n", g_checks, g_failures);
+ return g_failures == 0 ? 0 : 1;
+}