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: R2.1 pipeline data contracts (rational PTS, color/flags/gpu-handle, bounded window, frame-boundary resets) 50/50 tests
Veyra Goal Agent07eb66d21bbd
diff --git a/CMakeLists.txt b/CMakeLists.txtindex c320a611..13d58c59 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -181,6 +181,27 @@ target_compile_definitions(veyra_unified_tests PRIVATEtarget_include_directories(veyra_unified_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)target_link_libraries(veyra_unified_tests PRIVATE d3d12 veyra_gfx veyra_ngx)+# 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+ src/pipeline/ResetCoordinator.cpp+)+veyra_apply_warnings(veyra_pipeline)+target_compile_features(veyra_pipeline PRIVATE cxx_std_20)+target_compile_definitions(veyra_pipeline PRIVATE+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+target_include_directories(veyra_pipeline PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)++add_executable(veyra_pipeline_tests+ tests/unit/PipelineContractTests.cpp+)+veyra_apply_warnings(veyra_pipeline_tests)+target_compile_features(veyra_pipeline_tests PRIVATE cxx_std_20)+target_compile_definitions(veyra_pipeline_tests PRIVATE+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+target_include_directories(veyra_pipeline_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)+target_link_libraries(veyra_pipeline_tests PRIVATE veyra_pipeline)+add_executable(veyra_scene_teststests/unit/SceneCadenceTests.cppsrc/core/SceneCadenceAnalyzer.cppdiff --git a/include/veyra/pipeline/FramePacket.h b/include/veyra/pipeline/FramePacket.hnew file mode 100644index 00000000..3cd42035--- /dev/null+++ b/include/veyra/pipeline/FramePacket.h@@ -0,0 +1,166 @@+#pragma once++// Pipeline FramePacket - the product-grade frame contract (Playbook R2).+// Fixes over the veyra::core draft: exact rational timestamps that can express+// negative and unknown PTS, full color description with assumed flags, ten+// frame event flags, and GPU textures that carry their own lifetime contract+// (owner slot, expected state, ready fence value, extent, format).+#include <cstdint>+#include <d3d12.h>+#include <dxgiformat.h>++namespace veyra::pipeline {++// Exact rational timestamp. den > 0. known=false means the container/source+// did not provide a timestamp (never fabricate one; downstream must handle).+struct Rational {+ int64_t num = 0;+ int32_t den = 1;+ bool known = true;++ static Rational unknown() { return Rational{0, 1, false}; }+ bool isUnknown() const { return !known; }+ bool isNegative() const { return known && num < 0; }+ double toDouble() const { return den == 0 ? 0.0 : static_cast<double>(num) / den; }+ // Rounded conversion to 100 ns units for logging/interop.+ int64_t to100ns() const {+ if (den == 0) { return 0; }+ return static_cast<int64_t>(static_cast<long double>(num) * 10000000.0L+ / static_cast<long double>(den) + (num >= 0 ? 0.5L : -0.5L));+ }+ bool equals(const Rational& o) const {+ if (known != o.known) { return false; }+ if (!known) { return true; }+ // Cross-multiply to avoid requiring a canonical form.+ return static_cast<long double>(num) * o.den == static_cast<long double>(o.num) * den;+ }+};++enum class SourceKind : uint8_t {+ Unknown = 0,+ File, // FFmpeg demux/decode (player, export)+ CaptureCard, // physical DirectShow/UVC capture+ Image, // WIC single image+ TestPattern, // synthetic harness input+};++inline const char* sourceKindName(SourceKind k) {+ switch (k) {+ case SourceKind::File: return "File";+ case SourceKind::CaptureCard: return "CaptureCard";+ case SourceKind::Image: return "Image";+ case SourceKind::TestPattern: return "TestPattern";+ default: return "Unknown";+ }+}++enum class SourcePixelFormat : uint8_t {+ Unknown = 0,+ NV12, // SDR limited 8-bit planar+ P010, // 10-bit HDR path - V1 must fail closed, not misread as SDR+ Yuv420P, // software decode planar+ Yuy2, // packed capture format+ Bgra8, // 8-bit BGRA+ Rgba16F, // canonical linear working format+};++enum class ColorRange : uint8_t { Unknown = 0, Limited, Full };+enum class YuvMatrix : uint8_t { Unknown = 0, BT601, BT709, BT2020NCL, BT2020CL };+enum class TransferFunction : uint8_t { Unknown = 0, SRGB, BT709, BT2020_10, Linear };+enum class ColorPrimaries : uint8_t { Unknown = 0, BT601_525, BT601_625, BT709, BT2020 };++struct SampleAspectRatio {+ uint32_t num = 1;+ uint32_t den = 1;+};++// Full ingress color metadata. Assumed flags must be set when a value was+// derived from a documented default (SD->601, HD SDR->709) rather than the+// container; the UI surfaces these.+struct ColorDescription {+ SourcePixelFormat pixelFormat = SourcePixelFormat::Unknown;+ ColorRange range = ColorRange::Unknown;+ YuvMatrix matrix = YuvMatrix::Unknown;+ TransferFunction transfer = TransferFunction::Unknown;+ ColorPrimaries primaries = ColorPrimaries::Unknown;+ uint16_t rotationDegrees = 0; // 0 / 90 / 180 / 270+ SampleAspectRatio sar;++ bool rangeAssumed = false;+ bool matrixAssumed = false;+ bool transferAssumed = false;+ bool primariesAssumed = false;++ bool isHdrPath() const {+ return pixelFormat == SourcePixelFormat::P010+ || transfer == TransferFunction::BT2020_10;+ }+};++enum class FrameFlagBits : uint32_t {+ None = 0,+ Open = 1u << 0, // first frame after open/start+ Seek = 1u << 1,+ Cut = 1u << 2, // detected scene cut+ Drop = 1u << 3, // capture mailbox dropped stale frame(s)+ Duplicate = 1u << 4, // repeated source frame+ Resize = 1u << 5, // extent change+ Discontinuity = 1u << 6, // PTS jump / sequence gap+ PauseResume = 1u << 7,+ DeviceLost = 1u << 8,+ Eos = 1u << 9,+};+using FrameFlags = uint32_t;++constexpr bool hasFrameFlag(FrameFlags flags, FrameFlagBits bit) {+ return (flags & static_cast<uint32_t>(bit)) != 0;+}+// Any flag that invalidates temporal history (consumers must reset).+constexpr FrameFlags historyBreakingFlags() {+ return static_cast<uint32_t>(FrameFlagBits::Seek)+ | static_cast<uint32_t>(FrameFlagBits::Cut)+ | static_cast<uint32_t>(FrameFlagBits::Drop)+ | static_cast<uint32_t>(FrameFlagBits::Resize)+ | static_cast<uint32_t>(FrameFlagBits::Discontinuity)+ | static_cast<uint32_t>(FrameFlagBits::PauseResume)+ | static_cast<uint32_t>(FrameFlagBits::DeviceLost);+}+constexpr bool breaksHistory(FrameFlags flags) {+ return (flags & historyBreakingFlags()) != 0;+}++// GPU texture with an explicit lifetime contract. The packet never owns the+// resource; it names who owns the transition (command slot), the state the+// content is in, and the fence value after which it is safe to consume.+struct GpuTextureHandle {+ ID3D12Resource* resource = nullptr;+ D3D12_RESOURCE_STATES expectedState = D3D12_RESOURCE_STATE_COMMON;+ uint32_t ownerSlot = 0; // command slot responsible for writes/transitions+ uint64_t readyFenceValue = 0; // content ready at this fence value (0 = CPU/CPU-visible)+ uint32_t width = 0;+ uint32_t height = 0;+ DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;++ bool present() const {+ return resource != nullptr && width > 0 && height > 0+ && format != DXGI_FORMAT_UNKNOWN;+ }+};++struct FramePacket {+ uint64_t sequence = 0; // monotonic per source (0 reserved as invalid)+ Rational pts;+ Rational duration;+ SourceKind sourceKind = SourceKind::Unknown;+ FrameFlags flags = 0;+ ColorDescription colorInfo;+ uint64_t sourceEpoch = 1; // ResetCoordinator epoch at frame boundary++ GpuTextureHandle color; // canonical linear RGBA16F working texture++ bool valid() const {+ return sequence > 0 && color.present() && !pts.isUnknown();+ }+};++} // namespace veyra::pipelinediff --git a/include/veyra/pipeline/FrameWindow.h b/include/veyra/pipeline/FrameWindow.hnew file mode 100644index 00000000..59aaff0b--- /dev/null+++ b/include/veyra/pipeline/FrameWindow.h@@ -0,0 +1,45 @@+#pragma once++// Pipeline FrameWindow - fixed temporal context (Playbook R2/R6).+// prev/current/next plus an explicit lookaheadFrames mode. The unbounded+// vector from the veyra::core draft is intentionally gone: capture never+// buffers more than the mode requires, and DLSSG never receives a third+// frame as an input (C is for Veyra-side validation only).+#include <cstdint>+#include <initializer_list>++#include "veyra/pipeline/FramePacket.h"++namespace veyra::pipeline {++struct FrameWindow {+ static constexpr uint32_t kMaxLookahead = 2;++ const FramePacket* prev = nullptr; // A (null on first frame / after reset)+ const FramePacket* current = nullptr; // B+ const FramePacket* next = nullptr; // C (validation only; null is not an error)++ // 0 = NR Low Latency (no deliberate wait for a future frame)+ // 1 = FG Low Latency (A/B pair; A-half generated after B arrives)+ // 2 = Buffered Quality (A/B/C; C validates A/B guidance/depth/cut)+ uint32_t lookaheadFrames = 0;++ bool valid() const { return current != nullptr && current->valid(); }++ bool consistentLookahead() const { return lookaheadFrames <= kMaxLookahead; }++ // All present frames must come from one reset epoch; mixing epochs means+ // history survived a reset and must be rejected by consumers.+ bool sameSourceEpoch() const {+ uint64_t epoch = 0;+ bool first = true;+ for (const FramePacket* p : { prev, current, next }) {+ if (p == nullptr) { continue; }+ if (first) { epoch = p->sourceEpoch; first = false; }+ else if (p->sourceEpoch != epoch) { return false; }+ }+ return true;+ }+};++} // namespace veyra::pipelinediff --git a/include/veyra/pipeline/GuidanceFrame.h b/include/veyra/pipeline/GuidanceFrame.hnew file mode 100644index 00000000..c90b3570--- /dev/null+++ b/include/veyra/pipeline/GuidanceFrame.h@@ -0,0 +1,62 @@+#pragma once++// Pipeline GuidanceFrame - the unified motion/depth/confidence contract+// consumed by SR (V1: explicit Zero), NR (Feature 18), and FG (DLSSG).+// Direction: current -> previous, post-SR workingExtent pixels.+#include <cstdint>++#include "veyra/pipeline/FramePacket.h"+#include "veyra/pipeline/ResetCoordinator.h"++namespace veyra::pipeline {++enum class GuidanceProvenance : uint8_t {+ None = 0,+ Zero, // honest fallback: all-zero motion/depth+ Nvof, // NVIDIA Optical Flow motion + cost-derived confidence+ Dav2, // DAV2 depth only (motion zero) - diagnostics/A-B+ NvofDav2, // NVOF motion + DAV2 depth+};++inline const char* guidanceProvenanceName(GuidanceProvenance p) {+ switch (p) {+ case GuidanceProvenance::Zero: return "Zero";+ case GuidanceProvenance::Nvof: return "Nvof";+ case GuidanceProvenance::Dav2: return "Dav2";+ case GuidanceProvenance::NvofDav2: return "NvofDav2";+ default: return "None";+ }+}++struct GuidanceFrame {+ GpuTextureHandle motion; // R16G16_FLOAT, current->previous, workingExtent px+ GpuTextureHandle depth; // R32_FLOAT normalized relative depth+ GpuTextureHandle confidence; // R8_UNORM, 1 = trust, 0 = reject++ GuidanceProvenance provenance = GuidanceProvenance::Zero;+ uint64_t sourceSequence = 0; // FramePacket::sequence guidance was built from+ uint64_t sourceEpoch = 0; // epoch at production time (stale check)++ // Depth produced at interval > 1: frames since the last inference result.+ uint32_t depthAgeFrames = 0;++ // Set when this guidance follows a reset boundary (first frame of a new+ // epoch): providers must not consume pre-reset history.+ bool requiresReset = false;+ ResetReason resetReason = ResetReason::None;++ bool valid() const {+ return motion.present() && depth.present() && confidence.present()+ && sourceSequence > 0 && provenance != GuidanceProvenance::None;+ }++ // Motion must match the working extent exactly; consumers never rescale+ // silently (the NGX adapter applies the documented consumer-side scale).+ bool extentsMatch(uint32_t width, uint32_t height) const {+ return motion.width == width && motion.height == height+ && depth.width == width && depth.height == height+ && confidence.width == width && confidence.height == height;+ }+};++} // namespace veyra::pipelinediff --git a/include/veyra/pipeline/ResetCoordinator.h b/include/veyra/pipeline/ResetCoordinator.hnew file mode 100644index 00000000..0f5fa24b--- /dev/null+++ b/include/veyra/pipeline/ResetCoordinator.h@@ -0,0 +1,73 @@+#pragma once++// Pipeline ResetCoordinator - single source of truth for reset epochs+// (Playbook R2). Events are staged with notifyReset() and the epoch advances+// exactly once per real-frame boundary in beginFrame(), so SR, NR, FG, NVOF,+// depth, and cadence all observe the SAME epoch for a given frame. Modules+// never decide resets on their own.+#include <cstdint>++namespace veyra::pipeline {++enum class ResetReason : uint8_t {+ None = 0,+ Open, // source opened / started+ Seek,+ SceneCut,+ FrameDrop, // capture mailbox drop / PTS gap+ Resize, // extent or quality-mode change+ SourceSwitch,+ PauseResume,+ DeviceLost,+ _Count+};++inline const char* resetReasonName(ResetReason r) {+ switch (r) {+ case ResetReason::Open: return "Open";+ case ResetReason::Seek: return "Seek";+ case ResetReason::SceneCut: return "SceneCut";+ case ResetReason::FrameDrop: return "FrameDrop";+ case ResetReason::Resize: return "Resize";+ case ResetReason::SourceSwitch: return "SourceSwitch";+ case ResetReason::PauseResume: return "PauseResume";+ case ResetReason::DeviceLost: return "DeviceLost";+ default: return "None";+ }+}++class ResetCoordinator {+public:+ // Stage a reset event. Multiple events between frame boundaries collapse+ // into ONE epoch bump; every staged reason is still counted.+ void notifyReset(ResetReason reason);++ // Advance the frame boundary. Must be called exactly once per real frame,+ // before any consumer reads epoch() for that frame. Returns the epoch in+ // effect for the frame that is beginning.+ uint64_t beginFrame(uint64_t sequence);++ uint64_t epoch() const { return epoch_; }+ ResetReason lastReason() const { return lastReason_; }+ uint64_t lastResetSequence() const { return lastResetSequence_; }+ bool hasPendingReset() const { return pending_; }++ // True if `otherEpoch` predates the current epoch (stale history that+ // must not be consumed by NVOF/depth/NR/FG).+ bool isStale(uint64_t otherEpoch) const { return otherEpoch < epoch_; }++ uint32_t resetCount(ResetReason reason) const {+ return resetCount_[static_cast<uint8_t>(reason)];+ }+ uint32_t totalResets() const;++private:+ uint64_t epoch_ = 1;+ bool pending_ = false;+ ResetReason pendingReason_ = ResetReason::None;+ ResetReason lastReason_ = ResetReason::None;+ uint64_t lastResetSequence_ = 0;+ uint32_t resetCount_[static_cast<uint8_t>(ResetReason::_Count)] = {};+};++} // namespace veyra::pipelinediff --git a/loop/JOURNAL.md b/loop/JOURNAL.mdindex e30f045b..c2f15731 100644--- a/loop/JOURNAL.md+++ b/loop/JOURNAL.md@@ -944,6 +944,40 @@ C staged teardown 定位崩溃=swapChain_.Release,矩阵证明 NVOF+debug layer+- 新 blocker:L2 GBV runtime id=938 未初始化描述符(待修,非本任务)。- 未执行:query-heap GPU timestamp(用户明令禁止);Reviewer/checkpoint(未授权)。+## Cycle 033 — R2.1 pipeline 数据契约迁移(2026-09-06 Goal)++### Before++- Phase: 5(重开,in_progress)+- 唯一任务: 按 Playbook R2 建立 include/veyra/pipeline 契约族:FramePacket(Rational PTS/duration 可表达负值与未知、ColorDescription 含 format/range/matrix/transfer/primaries/rotation/SAR+assumed 标志、FrameFlags 十类事件位、GpuTextureHandle 携带 owner slot/expected state/ready fence/extent/format、SourceKind)、FrameWindow(固定 prev/current/next + lookaheadFrames 0/1/2,删除无界 vector)、GuidanceFrame(provenance/sourceSequence/depthAge)、ResetCoordinator(pending→帧边界消费的单调 epoch);src/pipeline/ResetCoordinator.cpp + veyra_pipeline target + tests/unit/PipelineContractTests.cpp(8 类 reset、负/未知 PTS、跨 epoch 拒绝、窗口上限、fence 所有权)。旧 veyra/core 保留为迁移期兼容层。+- 可证伪假设: 若契约或 ResetCoordinator 帧边界语义错误(如同一帧多次事件多次 bump、epoch 在帧中变化、窗口可超 2 lookahead),新单测将以真实断言失败。+- 预计修改文件: include/veyra/pipeline/{FramePacket,FrameWindow,GuidanceFrame,ResetCoordinator}.h、src/pipeline/ResetCoordinator.cpp、tests/unit/PipelineContractTests.cpp、CMakeLists.txt。+- 快速检查命令: `build x64-debug` → 0;`veyra_pipeline_tests.exe` → 0(全部断言过);`veyra_unified_tests.exe` 仍 0(旧契约未破坏)。+- 预期新增证据: 新契约单测全绿 + 旧测试无回归。++### After++- 实际修改: include/veyra/pipeline/{FramePacket,FrameWindow,GuidanceFrame,ResetCoordinator}.h(新契约族)、src/pipeline/ResetCoordinator.cpp、tests/unit/PipelineContractTests.cpp(50 断言)、CMakeLists.txt(veyra_pipeline STATIC + veyra_pipeline_tests;插在 unified_tests 之后)、tools/descriptor_present_probe/main.cpp(617 行 ExitProcess 后不可达 return 修复——debug W4/WX 下 C4702 阻塞构建的接管遗留修复)。+- 契约要点落地:+ - Rational(int64 num/int32 den/known 标志):负 PTS 可表达、unknown 与已知 0 区分、交叉相乘相等、100ns 舍入(1/3→3333333、2/3→6666667 验证进位);+ - ColorDescription:SourcePixelFormat(含 P010→isHdrPath 供 V1 fail-closed)/range/matrix/transfer/primaries/rotation/SAR + 四个 assumed 标志;+ - FrameFlags 十位(Open/Seek/Cut/Drop/Duplicate/Resize/Discontinuity/PauseResume/DeviceLost/Eos)+ breaksHistory 复合判定(Duplicate 不破坏历史);+ - GpuTextureHandle:resource/expectedState/ownerSlot/readyFenceValue/extent/format,present() 要求全部有效;+ - FrameWindow:固定 prev/current/next + lookaheadFrames ≤2 上限(3 与 0xFFFFFFFF 均被拒),next==null 非错误,跨 epoch 拒绝;无 vector;+ - GuidanceFrame:motion RG16F current→previous workingExtent 像素/depth R32F/confidence R8 + provenance/sourceSequence/sourceEpoch/depthAgeFrames/requiresReset + extentsMatch(消费者不静默缩放);+ - ResetCoordinator:notifyReset 暂存(多事件计次)→ beginFrame 帧边界恰好一次 bump;8 类理由各计次;无事件边界 epoch 不变;isStale 拒绝旧 epoch。+- 实际命令与 exit code:+ - `build x64-debug` → 首次 exit 6(FrameWindow 缺 <initializer_list>;descriptor_present_probe:617 C4702 不可达代码 debug WX 报错)→ 修复后 exit 0;+ - `veyra_pipeline_tests.exe` Debug → **exit 0,50/50**(首版 1 失败:我的 1/3→3333334 期望算错,公式正确,测试改为 1/3→3333333 + 2/3→6666667 进位验证);+ - `veyra_unified_tests.exe` Debug → exit 0,51/51(旧 core 契约兼容层无回归);+ - `build x64-release` → exit 0;Release `veyra_pipeline_tests.exe` → exit 0,50/50。+- 失败 fingerprint: build|debug|6|initializer_list+C4702 → 两处独立修复,第 1 轮关闭。+- 是否有进展,依据: 是——产品级数据契约从"ptsUs 无符号/无颜色元数据/裸指针/无界 vector"升级为 Playbook R2 全字段契约,且新旧测试双配置全绿。+- STATE/BACKLOG 更新: cycle.completed=33;BACKLOG R2.1 → DONE;nextAction → R2.2(FrameWindow/GuidanceFrame 消费侧接线与迁移层,随后 R2.3 ResetCoordinator 集成测试)。+- 下一唯一动作: R2.2 — 把 player_probe/NvOfSession 的窗口语义对接新 FrameWindow(固定 A/B/C + lookaheadFrames),并让 GuidanceFrame 携带 provenance/age;迁移期兼容层保持旧测试绿。++---+## Cycle 032 — R1.2 确定性 corpus 生成器(2026-09-06 Goal)### Beforediff --git a/loop/STATE.json b/loop/STATE.jsonindex a4887545..893c7796 100644--- a/loop/STATE.json+++ b/loop/STATE.json@@ -76,14 +76,14 @@}],"cycle": {- "completed": 32,+ "completed": 33,"maximum": 120,"sameFailureAttempts": 0,"maximumSameFailureAttempts": 3,"noProgressCycles": 0,"maximumNoProgressCycles": 5},- "currentTask": "R1.2 complete (Cycle 032): veyra_clip_gen extended to five deterministic scenarios (translation/occlusion/cut-flash-duplicate/particles/ui-text), corpus of 10 clips (1080p60 + 4K60, 600 frames each) generated with SHA256 corpus-manifest.json. DLL-shadowing fixed via isolated clipgen runtime dir. Phase5 gate corpus:* x4 now PASS while implementation gaps stay red (30/42 fail, exit 1).",+ "currentTask": "R2.1 complete (Cycle 033): include/veyra/pipeline contract family landed (Rational PTS with negative/unknown, ColorDescription with assumed flags + P010 HDR fail-closed path, 10-bit FrameFlags with breaksHistory, GpuTextureHandle with owner slot/expected state/ready fence, FrameWindow fixed prev/current/next + lookaheadFrames<=2 no vector, GuidanceFrame provenance/age/sourceSequence, ResetCoordinator frame-boundary epoch). PipelineContractTests 50/50 debug+release; legacy unified tests 51/51 no regression. veyra_pipeline static target created.","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 R2.1: migrate data contracts to include/veyra/pipeline (Rational PTS/duration, ColorDescription with assumed flags, FrameFlags 10 events, GpuTextureHandle with owner slot/expected state/ready fence, FrameWindow fixed prev/current/next + lookaheadFrames 0/1/2 without unbounded vector, GuidanceFrame provenance/age/sourceSequence, ResetCoordinator frame-boundary consumption) plus PipelineContractTests covering 8 reset events, negative/unknown PTS, cross-epoch rejection, window cap and fence ownership.",- "updatedAt": "2026-09-06T16:35:00+08:00"+ "nextAction": "Playbook R2.2: wire NVOF/depth guidance production to the new GuidanceFrame contract (provenance, sourceSequence, depthAge, extentsMatch) and migrate probe window semantics onto FrameWindow fixed prev/current/next with lookaheadFrames modes; keep veyra::core compat layer compiling. Then R2.3 ResetCoordinator integration tests (open/seek/cut/drop/resize/source-switch/pause-resume/device-lost at real-frame boundaries).",+ "updatedAt": "2026-09-06T16:55:00+08:00"}diff --git a/src/pipeline/ResetCoordinator.cpp b/src/pipeline/ResetCoordinator.cppnew file mode 100644index 00000000..9698c967--- /dev/null+++ b/src/pipeline/ResetCoordinator.cpp@@ -0,0 +1,33 @@+#include "veyra/pipeline/ResetCoordinator.h"++namespace veyra::pipeline {++void ResetCoordinator::notifyReset(ResetReason reason) {+ if (reason == ResetReason::None) { return; }+ ++resetCount_[static_cast<uint8_t>(reason)];+ if (!pending_) {+ pending_ = true;+ pendingReason_ = reason;+ }+}++uint64_t ResetCoordinator::beginFrame(uint64_t sequence) {+ if (pending_) {+ ++epoch_;+ lastReason_ = pendingReason_;+ lastResetSequence_ = sequence;+ pending_ = false;+ pendingReason_ = ResetReason::None;+ }+ return epoch_;+}++uint32_t ResetCoordinator::totalResets() const {+ uint32_t total = 0;+ for (int i = 1; i < static_cast<int>(ResetReason::_Count); ++i) {+ total += resetCount_[i];+ }+ return total;+}++} // namespace veyra::pipelinediff --git a/tests/unit/PipelineContractTests.cpp b/tests/unit/PipelineContractTests.cppnew file mode 100644index 00000000..42dc7a80--- /dev/null+++ b/tests/unit/PipelineContractTests.cpp@@ -0,0 +1,205 @@+// Pipeline contract unit tests (Playbook R2): exact timestamps, frame flags,+// fixed window with bounded lookahead, GPU handle lifetime fields, and the+// ResetCoordinator frame-boundary epoch semantics. Pure CPU - no D3D12 device.+#include <cstdio>+#include <cstring>++#include "veyra/pipeline/FramePacket.h"+#include "veyra/pipeline/FrameWindow.h"+#include "veyra/pipeline/GuidanceFrame.h"+#include "veyra/pipeline/ResetCoordinator.h"++using namespace veyra::pipeline;++namespace {++int g_checks = 0;+int g_failures = 0;++void check(const char* name, bool ok, const char* detail = "") {+ ++g_checks;+ if (!ok) {+ ++g_failures;+ std::printf(" [FAIL] %s :: %s\n", name, detail);+ } else {+ std::printf(" [PASS] %s\n", name);+ }+}++FramePacket makePacket(uint64_t seq, uint64_t epoch) {+ FramePacket p;+ p.sequence = seq;+ p.pts = Rational{static_cast<int64_t>(seq) * 1001, 60000};+ p.duration = Rational{1001, 60000};+ p.sourceKind = SourceKind::File;+ p.sourceEpoch = epoch;+ p.color.resource = reinterpret_cast<ID3D12Resource*>(0x10 + seq);+ p.color.width = 3840;+ p.color.height = 2160;+ p.color.format = DXGI_FORMAT_R16G16B16A16_FLOAT;+ p.color.expectedState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;+ p.color.ownerSlot = 2;+ p.color.readyFenceValue = 100 + seq;+ return p;+}++} // namespace++int main() {+ std::printf("pipeline-contract: rational timestamps\n");+ {+ const Rational a{1001, 60000};+ const Rational b{2002, 120000};+ const Rational neg{-5, 3};+ const Rational unk = Rational::unknown();+ check("rational:cross-equal", a.equals(b));+ check("rational:negative-representable", neg.isNegative() && neg.to100ns() < 0);+ check("rational:unknown-distinct-from-zero", unk.isUnknown() && !unk.isNegative());+ check("rational:unknown-not-equal-known-zero", !unk.equals(Rational{0, 1}));+ check("rational:100ns-rounding", Rational{1, 3}.to100ns() == 3333333+ && Rational{2, 3}.to100ns() == 6666667);+ }++ std::printf("pipeline-contract: color description + flags\n");+ {+ ColorDescription cd;+ cd.pixelFormat = SourcePixelFormat::NV12;+ cd.range = ColorRange::Limited;+ cd.matrix = YuvMatrix::BT709;+ cd.matrixAssumed = true; // HD SDR documented default+ cd.rotationDegrees = 0;+ check("color:hdr-path-detected", [&] {+ ColorDescription hdr; hdr.pixelFormat = SourcePixelFormat::P010;+ return hdr.isHdrPath();+ }());+ check("color:assumed-flag-survives", cd.matrixAssumed && !cd.rangeAssumed);++ constexpr FrameFlags seekCut =+ static_cast<uint32_t>(FrameFlagBits::Seek) | static_cast<uint32_t>(FrameFlagBits::Cut);+ check("flags:seek-breaks-history", breaksHistory(static_cast<uint32_t>(FrameFlagBits::Seek)));+ check("flags:duplicate-does-not-break-history",+ !breaksHistory(static_cast<uint32_t>(FrameFlagBits::Duplicate)));+ check("flags:composite-breaks", breaksHistory(seekCut));+ check("flags:hasflag", hasFrameFlag(seekCut, FrameFlagBits::Cut)+ && !hasFrameFlag(seekCut, FrameFlagBits::Eos));+ }++ std::printf("pipeline-contract: gpu texture handle ownership\n");+ {+ FramePacket p = makePacket(7, 1);+ check("handle:present-requires-format-extent", [&] {+ GpuTextureHandle h = p.color;+ h.format = DXGI_FORMAT_UNKNOWN;+ return !h.present();+ }());+ check("handle:fence-ownership-fields", p.color.ownerSlot == 2 && p.color.readyFenceValue == 107+ && p.color.expectedState == D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);+ check("packet:valid-requires-known-pts", [&] {+ FramePacket q = makePacket(1, 1);+ q.pts = Rational::unknown();+ return !q.valid();+ }());+ }++ std::printf("pipeline-contract: frame window bounded\n");+ {+ FrameWindow w;+ check("window:default-zero-lookahead", w.lookaheadFrames == 0 && w.consistentLookahead());+ w.lookaheadFrames = 1;+ check("window:fg-mode-1-ok", w.consistentLookahead());+ w.lookaheadFrames = 2;+ check("window:buffered-mode-2-ok", w.consistentLookahead());+ w.lookaheadFrames = 3;+ check("window:cap-3-rejected", !w.consistentLookahead());+ w.lookaheadFrames = 0xFFFFFFFFu;+ check("window:cap-overflow-rejected", !w.consistentLookahead());+ check("window:next-null-not-error", [&] {+ const FramePacket cur = makePacket(2, 4);+ FrameWindow v;+ v.current = &cur;+ v.lookaheadFrames = 1; // mode says pair, but stream end has no C yet+ return v.valid() && v.consistentLookahead();+ }());++ const FramePacket a = makePacket(1, 4);+ const FramePacket b = makePacket(2, 4);+ const FramePacket c = makePacket(3, 4);+ FrameWindow ok;+ ok.prev = &a; ok.current = &b; ok.next = &c; ok.lookaheadFrames = 2;+ check("window:same-epoch", ok.sameSourceEpoch() && ok.valid());+ FramePacket stale = makePacket(0, 3);+ FrameWindow mixed;+ mixed.prev = &stale; mixed.current = &b;+ check("window:mixed-epoch-rejected", !mixed.sameSourceEpoch());+ }++ std::printf("pipeline-contract: guidance frame\n");+ {+ GuidanceFrame g;+ g.motion.resource = reinterpret_cast<ID3D12Resource*>(0x1);+ g.motion.format = DXGI_FORMAT_R16G16_FLOAT;+ g.depth.resource = reinterpret_cast<ID3D12Resource*>(0x2);+ g.depth.format = DXGI_FORMAT_R32_FLOAT;+ g.confidence.resource = reinterpret_cast<ID3D12Resource*>(0x3);+ g.confidence.format = DXGI_FORMAT_R8_UNORM;+ g.motion.width = g.depth.width = g.confidence.width = 3840;+ g.motion.height = g.depth.height = g.confidence.height = 2160;+ g.provenance = GuidanceProvenance::NvofDav2;+ g.sourceSequence = 42;+ g.sourceEpoch = 5;+ g.depthAgeFrames = 3;+ check("guidance:valid", g.valid());+ check("guidance:extent-match", g.extentsMatch(3840, 2160) && !g.extentsMatch(1920, 1080));+ check("guidance:provenance-name", std::strcmp(guidanceProvenanceName(GuidanceProvenance::NvofDav2), "NvofDav2") == 0);+ }++ std::printf("pipeline-contract: reset coordinator epochs\n");+ {+ ResetCoordinator rc;+ check("reset:initial-epoch-1", rc.epoch() == 1 && !rc.hasPendingReset());++ // All eight event reasons stage and advance the epoch.+ const ResetReason reasons[] = {+ ResetReason::Open, ResetReason::Seek, ResetReason::SceneCut,+ ResetReason::FrameDrop, ResetReason::Resize, ResetReason::SourceSwitch,+ ResetReason::PauseResume, ResetReason::DeviceLost,+ };+ uint64_t seq = 1;+ uint64_t expectedEpoch = 1;+ for (const ResetReason r : reasons) {+ rc.notifyReset(r);+ check("reset:pending-staged", rc.hasPendingReset());+ const uint64_t frameEpoch = rc.beginFrame(seq++);+ ++expectedEpoch;+ check("reset:epoch-advanced-once", frameEpoch == expectedEpoch+ && rc.epoch() == expectedEpoch && !rc.hasPendingReset());+ }+ check("reset:eight-reasons-counted", rc.totalResets() == 8);++ // Multiple events between boundaries collapse into one bump.+ rc.notifyReset(ResetReason::Seek);+ rc.notifyReset(ResetReason::SceneCut);+ rc.notifyReset(ResetReason::Resize);+ const uint64_t before = rc.epoch();+ const uint64_t frameEpoch = rc.beginFrame(seq);+ check("reset:collapse-one-bump", frameEpoch == before + 1 && rc.epoch() == before + 1);+ check("reset:all-events-counted", rc.totalResets() == 11);+ check("reset:first-reason-recorded", rc.lastReason() == ResetReason::Seek);++ // No pending event: epoch unchanged at the boundary.+ const uint64_t stable = rc.beginFrame(seq + 100);+ check("reset:stable-without-events", stable == rc.epoch());++ // Stale history detection.+ check("reset:stale-old-epoch", rc.isStale(1) && rc.isStale(rc.epoch() - 1));+ check("reset:current-not-stale", !rc.isStale(rc.epoch()));+ check("reset:none-ignored", [&] {+ ResetCoordinator r2;+ r2.notifyReset(ResetReason::None);+ return !r2.hasPendingReset() && r2.beginFrame(1) == 1;+ }());+ }++ std::printf("pipeline-contract: %d checks, %d failures\n", g_checks, g_failures);+ return g_failures == 0 ? 0 : 1;+}diff --git a/tools/descriptor_present_probe/main.cpp b/tools/descriptor_present_probe/main.cppindex 256fa7db..7f1b2d6a 100644--- a/tools/descriptor_present_probe/main.cpp+++ b/tools/descriptor_present_probe/main.cpp@@ -614,5 +614,4 @@ int main(int argc, char** argv)// --no-debug exits 0). All D3D objects are already released above, so// terminate immediately with the real verdict code.ExitProcess(static_cast<UINT>(rc));- return rc;}