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.2 real EnhanceGraph GPU chain in veyra_pipeline (probe 3641->1971 lines, behavior parity verified, gate checks green)

Veyra Goal Agent9fb5a95926b2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a0309301..e6cba235 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -212,10 +212,14 @@ add_library(veyra_pipeline STATIC
src/pipeline/ResetCoordinator.cpp
)
veyra_apply_warnings(veyra_pipeline)
+# FFmpeg/NVOF headers are third-party: /WX stays off for this target.
+target_compile_options(veyra_pipeline PRIVATE /WX-)
target_compile_features(veyra_pipeline PRIVATE cxx_std_20)
-target_compile_definitions(veyra_pipeline PRIVATE
- UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)
+target_compile_definitions(veyra_pipeline PUBLIC
+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX
+ VEYRA_SHADER_DIR="${CMAKE_BINARY_DIR}/shaders")
target_include_directories(veyra_pipeline PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
+target_link_libraries(veyra_pipeline PUBLIC veyra_base veyra_gfx d3d12 dxgi dxguid d3dcompiler)
add_executable(veyra_pipeline_tests
tests/unit/PipelineContractTests.cpp
@@ -295,6 +299,18 @@ if(VEYRA_NVOF_SDK_ROOT AND EXISTS "${VEYRA_NVOF_SDK_ROOT}/NvOFInterface/nvOptica
target_link_libraries(veyra_nvof_probe PRIVATE veyra_gfx veyra_base)
endif()
+# EnhanceGraph (the real GPU chain) needs the NGX + NVOF backends; wire it
+# into veyra_pipeline only when both exist so bare contract builds still work.
+if(TARGET veyra_ngx AND TARGET veyra_nvof AND VEYRA_FFMPEG_ROOT)
+ target_sources(veyra_pipeline PRIVATE src/pipeline/EnhanceGraph.cpp)
+ target_include_directories(veyra_pipeline PRIVATE ${FFMPEG_INCLUDE_DIRS})
+ target_link_libraries(veyra_pipeline PRIVATE veyra_ngx veyra_nvof ${FFMPEG_LIBRARIES})
+ add_dependencies(veyra_pipeline
+ veyra_shader_yuv_to_rgb veyra_shader_parity_encode
+ veyra_shader_parity_decode veyra_shader_scale_blit
+ veyra_shader_nv12_upload veyra_shader_nvof_densify)
+endif()
+
# ---------------------------------------------------------------------------
# veyra_media: FFmpeg demux/decode (Phase 3). Links only the Playbook 3.4
# dependency set from the pinned vcpkg install.
@@ -385,7 +401,7 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX
VEYRA_SHADER_DIR="${CMAKE_BINARY_DIR}/shaders")
target_link_libraries(veyra_player_probe PRIVATE
- veyra_media veyra_gfx veyra_ngx veyra_nvof veyra_parity veyra_sinks
+ veyra_media veyra_gfx veyra_ngx veyra_nvof veyra_parity veyra_sinks veyra_pipeline
${FFMPEG_LIBRARIES} psapi ole32 mmdevapi avrt)
add_dependencies(veyra_player_probe
veyra_shader_yuv_to_rgb veyra_shader_parity_encode
diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.h
new file mode 100644
index 00000000..1ab54fb3
--- /dev/null
+++ b/include/veyra/pipeline/EnhanceGraph.h
@@ -0,0 +1,214 @@
+#pragma once
+
+// EnhanceGraph - the real unified processing graph (Playbook R3.2).
+// Chains, per real frame:
+// NV12 source (D3D12VA texture or CPU upload) -> YUV->linear RGB ->
+// SR upscale or 1:1 bypass -> parity encode -> Feature 18 evaluate ->
+// parity decode -> videoFrame slot + NVOF A/B inputs ->
+// NVOF execute + densify/confidence -> optional DLSSG 2X generate ->
+// genFrame slot. The graph submits real command-list work through the
+// shared CommandSlotRing; the probe/player/capture only assemble sources,
+// schedule, and present.
+//
+// The ordering constraints baked into initialize() are load-bearing on this
+// system (injected-layer era evidence, 2026-09-04): all committed resources
+// and NGX/NVOF objects are created BEFORE any descriptor view; the FG
+// warm-up evaluate runs before views exist; static views are created last.
+#include <cstdint>
+#include <functional>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <d3d12.h>
+
+#include "veyra/pipeline/GpuPassUtils.h"
+
+struct AVFrame;
+struct SwsContext;
+struct NVSDK_NGX_Parameter;
+struct NVSDK_NGX_Handle;
+
+namespace veyra::gfx {
+class D3D12DeviceContext;
+class CommandSlotRing;
+}
+
+namespace veyra::ngx {
+class NgxCoreHost;
+class DlssSrBackend;
+class DlssFgBackend;
+class DlssNrRuntimeAdapter;
+class NvOfSession;
+}
+
+namespace veyra::pipeline {
+
+struct EnhanceGraphDesc {
+ uint32_t sourceWidth = 0;
+ uint32_t sourceHeight = 0;
+ uint32_t workWidth = 3840;
+ uint32_t workHeight = 2160;
+ bool enableSr = false; // upscale source -> work extent (1:1 bypass otherwise)
+ bool enableNr = true;
+ bool enableFg = true;
+ bool noFeatures = false; // VEYRA_NO_FEATURES: NVOF/NGX objects skipped
+ bool noNgx = false; // VEYRA_NO_NGX: core/features skipped, NVOF only
+ std::wstring runtimeAbsPath; // absolute runtime_local/nvidia path
+ // Optional stage instrumentation hook (GPU timing experiments).
+ std::function<void(const char*)> stageMark;
+};
+
+class EnhanceGraph {
+public:
+ EnhanceGraph(gfx::D3D12DeviceContext& context, gfx::CommandSlotRing& ring);
+ ~EnhanceGraph();
+
+ EnhanceGraph(const EnhanceGraph&) = delete;
+ EnhanceGraph& operator=(const EnhanceGraph&) = delete;
+
+ // Two-phase initialization: the sink (swapchain allocations) must be
+ // created between the two phases - static descriptor views are only
+ // safe after every allocation in the process has happened.
+ bool initialize(const EnhanceGraphDesc& desc);
+ bool createViews();
+
+ struct FrameOutputs {
+ double ptsMs = 0.0;
+ uint32_t videoSlot = 0; // videoFrame[videoSlot] holds this real frame
+ uint64_t videoFenceValue = 0; // ring fence covering the video work
+ bool hasGenerated = false;
+ double generatedPtsMs = 0.0; // strict midpoint of prev/current PTS
+ uint32_t genSlot = 0; // genFrame[genSlot] holds the DLSSG output
+ uint64_t genFenceValue = 0;
+ uint64_t realFrameIndex = 0;
+ bool passthrough = false; // VEYRA_GRAPH_OFF: metadata only, no GPU work
+ };
+
+ // Processes one decoded frame. `ptsMs` is the frame PTS in the source
+ // stream time base converted to milliseconds by the caller (the graph
+ // does not own the demuxer). `reset` marks the first frame of a new
+ // temporal epoch (open/seek/...): NVOF/FG history is not consumed.
+ // Returns false on hard failure (run verdict must FAIL).
+ bool process(const AVFrame* frame, double ptsMs, bool reset, FrameOutputs& out);
+
+ // s10 ownership-order teardown: NVOF fence drain must happen BEFORE this
+ // call (it needs the ring and out-fence alive). Releases features, NVOF
+ // (unregister -> textures -> destroy/unload), NGX params/shim/core, and
+ // all graph textures in the proven staged order.
+ void shutdown();
+
+ struct Metrics {
+ uint64_t nrEvaluateCount = 0;
+ uint64_t srEvaluateCount = 0;
+ uint64_t nvofExecuteCount = 0;
+ uint64_t nvofFrameFailures = 0;
+ uint64_t fgGeneratedFrames = 0;
+ };
+ const Metrics& metrics() const { return metrics_; }
+ const std::string& mvecSource() const { return mvecSource_; }
+ bool nrCreated() const { return nrHandle_ != nullptr; }
+ bool initialized() const { return initialized_; }
+ uint32_t sourceWidth() const { return srcW_; }
+ uint32_t sourceHeight() const { return srcH_; }
+ uint32_t workWidth() const { return workW_; }
+ uint32_t workHeight() const { return workH_; }
+ bool srEnabled() const { return srEnabled_; }
+ bool nrEnabled() const { return nrEnabled_; }
+ bool fgEnabled() const { return fgEnabled_; }
+ uint64_t lastNvofSignal() const;
+
+ // Present-side access to the produced frame slots (probe sink path).
+ ID3D12Resource* videoFrameResource(uint32_t slot) const;
+ ID3D12Resource* generatedFrameResource(uint32_t slot) const;
+
+ // Teardown/diagnostics accessors: the s10 NVOF out-fence drain runs while
+ // the ring/fence/event are alive, i.e. BEFORE shutdown().
+ ID3D12Fence* nvofOutFenceResource() const { return nvofOutFence_.Get(); }
+ HANDLE nvofOutEventHandle() const { return nvofOutEvent_; }
+ bool nvofSessionInitialized() const;
+ uint64_t nvofNextOutValue() const;
+ uint64_t nrCreateResult() const { return nrResult_; }
+ bool fgCapabilityAvailable() const { return fgCapsAvailable_; }
+ int fgMultiFrameCountMax() const { return fgMultiFrameMax_; }
+ // Scenario toggles (probe/UI): gates only; the feature handles stay alive.
+ // setNrEnabled also refreshes the section-5 blit SRV (slot 2) so the
+ // videoFrame source follows workRgba (NR off) or finalRgba (NR on).
+ void setNrEnabled(bool on);
+ void setFgEnabled(bool on) { fgEnabled_ = on; }
+ bool fgCreated() const;
+
+private:
+ bool createResources();
+ bool initZeroAndDepthTextures();
+ bool initNvof();
+ bool initNgxFeatures();
+ bool createComputePasses();
+
+ gfx::D3D12DeviceContext& context_;
+ gfx::CommandSlotRing& ring_;
+ EnhanceGraphDesc desc_{};
+ bool initialized_ = false;
+
+ uint32_t srcW_ = 0, srcH_ = 0, workW_ = 3840, workH_ = 2160;
+ uint32_t nvofW_ = 0, nvofH_ = 0, rawW_ = 0, rawH_ = 0, nvofGrid_ = 4, selectedGrid_ = 4;
+ bool srEnabled_ = false, nrEnabled_ = false, fgEnabled_ = false;
+ size_t lumaPitch_ = 0, chromaPitch_ = 0, lumaSize_ = 0, chromaSize_ = 0, dPitch_ = 0;
+
+ // Uploads + textures (creation order matters for teardown).
+ ComPtr<ID3D12Resource> upLuma_[2];
+ ComPtr<ID3D12Resource> upChroma_[2];
+ ComPtr<ID3D12Resource> upDepth_;
+ ComPtr<ID3D12Resource> upZeroDepth_;
+ ComPtr<ID3D12Resource> upZeroMotion_;
+ ComPtr<ID3D12Resource> lumaTex_;
+ ComPtr<ID3D12Resource> chromaTex_;
+ ComPtr<ID3D12Resource> srcRgba_;
+ ComPtr<ID3D12Resource> workRgba_;
+ ComPtr<ID3D12Resource> proxyTex_;
+ ComPtr<ID3D12Resource> neuralTex_;
+ ComPtr<ID3D12Resource> finalRgba_;
+ ComPtr<ID3D12Resource> videoFrame_[2];
+ ComPtr<ID3D12Resource> confTex_;
+ ComPtr<ID3D12Resource> flowTex_;
+ ComPtr<ID3D12Resource> depthTex_;
+ ComPtr<ID3D12Resource> genFrame_[2];
+ ComPtr<ID3D12Resource> nrZeroMotion_;
+ ComPtr<ID3D12Resource> nrZeroDepth_;
+ ComPtr<ID3D12Resource> nvofRawTex_;
+ ComPtr<ID3D12Resource> nvofCostTex_;
+ ComPtr<ID3D12Resource> nvofInA_;
+ ComPtr<ID3D12Resource> nvofInB_;
+ uint8_t* mappedLuma_[2] = {};
+ uint8_t* mappedChroma_[2] = {};
+ std::vector<uint8_t> nv12Buf_;
+
+ ComputePass yuvPass_, encPass_, decPass_, blitPass_, uploadPass_, densifyPass_;
+ DescriptorStager stager_;
+ StateTracker tracker_;
+ SwsContext* nv12Ctx_ = nullptr;
+
+ // NVOF + NGX (owned by the graph, render-thread only).
+ std::unique_ptr<ngx::NvOfSession> nvof_;
+ ComPtr<ID3D12Fence> nvofOutFence_;
+ HANDLE nvofOutEvent_ = nullptr;
+ std::unique_ptr<ngx::NgxCoreHost> coreHost_;
+ std::unique_ptr<ngx::DlssNrRuntimeAdapter> nrAdapter_;
+ std::unique_ptr<ngx::DlssSrBackend> srBackend_;
+ std::unique_ptr<ngx::DlssFgBackend> fgBackend_;
+ NVSDK_NGX_Parameter* ngxParams_ = nullptr;
+ NVSDK_NGX_Handle* nrHandle_ = nullptr;
+ uint64_t nrResult_ = 0;
+ uint32_t nrSeh_ = 0;
+ bool fgCapsAvailable_ = false;
+ int fgMultiFrameMax_ = 0;
+
+ // Per-run state.
+ uint64_t realFrameIndex_ = 0;
+ double prevPtsMs_ = -1.0;
+ bool prevValid_ = false;
+ Metrics metrics_{};
+ std::string mvecSource_ = "nvof";
+};
+
+} // namespace veyra::pipeline
diff --git a/include/veyra/pipeline/GpuPassUtils.h b/include/veyra/pipeline/GpuPassUtils.h
new file mode 100644
index 00000000..4cbced6a
--- /dev/null
+++ b/include/veyra/pipeline/GpuPassUtils.h
@@ -0,0 +1,357 @@
+#pragma once
+
+// GpuPassUtils - GPU helper facilities shared by the EnhanceGraph product
+// library and the probes (R3.2). Moved verbatim from tools/player_probe
+// main.cpp; the DescriptorStager's staging-heap SRV path encodes a proven
+// driver workaround (RTX 5070 / 616.56: direct CreateShaderResourceView into
+// a shader-visible heap corrupts flip-model Present; staged copies are safe).
+#include <windows.h>
+#include <d3d12.h>
+#include <d3dcompiler.h>
+#include <wrl/client.h>
+
+#include <cstdint>
+#include <format>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "veyra/Log.h"
+
+#ifndef VEYRA_SHADER_DIR
+#error "VEYRA_SHADER_DIR must be defined by the build system"
+#endif
+
+namespace veyra::pipeline {
+
+template <typename T>
+using ComPtr = Microsoft::WRL::ComPtr<T>;
+
+inline ComPtr<ID3D12Resource> makeTexture(ID3D12Device* device, uint32_t w, uint32_t h,
+ DXGI_FORMAT fmt, bool uav)
+{
+ D3D12_HEAP_PROPERTIES hp{};
+ hp.Type = D3D12_HEAP_TYPE_DEFAULT;
+ D3D12_RESOURCE_DESC td{};
+ td.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
+ td.Width = w; td.Height = h; td.DepthOrArraySize = 1; td.MipLevels = 1;
+ td.Format = fmt; td.SampleDesc.Count = 1;
+ td.Flags = uav ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS : D3D12_RESOURCE_FLAG_NONE;
+ ComPtr<ID3D12Resource> r;
+ const HRESULT hr = device->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &td,
+ D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&r));
+ if (FAILED(hr)) {
+ veyra::log::error("gfx-util", std::format("texture alloc failed {}x{} hr=0x{:X}",
+ w, h, static_cast<unsigned>(hr)));
+ return nullptr;
+ }
+ return r;
+}
+
+inline ComPtr<ID3D12Resource> makeUploadBuffer(ID3D12Device* device, uint64_t size)
+{
+ D3D12_HEAP_PROPERTIES hp{};
+ hp.Type = D3D12_HEAP_TYPE_UPLOAD;
+ D3D12_RESOURCE_DESC bd{};
+ bd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
+ bd.Width = size; bd.Height = 1; bd.DepthOrArraySize = 1;
+ bd.MipLevels = 1; bd.SampleDesc.Count = 1;
+ bd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ ComPtr<ID3D12Resource> r;
+ const HRESULT hr = device->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &bd,
+ D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&r));
+ if (FAILED(hr)) {
+ veyra::log::error("gfx-util", std::format("upload buffer alloc failed size={} hr=0x{:X}",
+ static_cast<uint64_t>(size), static_cast<unsigned>(hr)));
+ return nullptr;
+ }
+ return r;
+}
+
+// Tracks the current D3D12 state of graph-owned resources and emits only the
+// transitions that are actually needed.
+class StateTracker {
+public:
+ void set(ID3D12Resource* r, D3D12_RESOURCE_STATES s) { states_[r] = s; }
+ D3D12_RESOURCE_STATES get(ID3D12Resource* r) const {
+ const auto it = states_.find(r);
+ return it != states_.end() ? it->second : D3D12_RESOURCE_STATE_COMMON;
+ }
+ void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* r,
+ D3D12_RESOURCE_STATES to) {
+ const D3D12_RESOURCE_STATES from = get(r);
+ if (from == to) return;
+ D3D12_RESOURCE_BARRIER b{};
+ b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ b.Transition.pResource = r;
+ b.Transition.StateBefore = from;
+ b.Transition.StateAfter = to;
+ b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &b);
+ set(r, to);
+ }
+ void uavBarrier(ID3D12GraphicsCommandList* list, ID3D12Resource* r) {
+ D3D12_RESOURCE_BARRIER b{};
+ b.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
+ b.UAV.pResource = r;
+ list->ResourceBarrier(1, &b);
+ }
+
+private:
+ std::unordered_map<ID3D12Resource*, D3D12_RESOURCE_STATES> states_;
+};
+
+// Compute pass helper (8 constants + SRV table + UAV table; single heap).
+struct ComputePass {
+ ComPtr<ID3D12RootSignature> rootSig;
+ ComPtr<ID3D12PipelineState> pso;
+ ComPtr<ID3D12DescriptorHeap> heap;
+ UINT increment = 0;
+
+ bool loadShader(const char* name, std::vector<uint8_t>& bytes) const
+ {
+ const std::string path = std::string(VEYRA_SHADER_DIR "/") + name;
+ HANDLE f = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (f == INVALID_HANDLE_VALUE) {
+ veyra::log::error("gfx-util", std::format("shader missing: {}", path));
+ return false;
+ }
+ LARGE_INTEGER sz{};
+ GetFileSizeEx(f, &sz);
+ bytes.resize(static_cast<size_t>(sz.QuadPart));
+ DWORD read = 0;
+ ReadFile(f, bytes.data(), static_cast<DWORD>(bytes.size()), &read, nullptr);
+ CloseHandle(f);
+ return !bytes.empty();
+ }
+
+ bool create(ID3D12Device* device, const std::vector<uint8_t>& cs, UINT heapSlots,
+ UINT srvCount = 3, UINT uavCount = 1)
+ {
+ D3D12_DESCRIPTOR_RANGE1 srvRange{};
+ srvRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
+ srvRange.NumDescriptors = srvCount;
+ srvRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
+ D3D12_DESCRIPTOR_RANGE1 uavRange{};
+ uavRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
+ uavRange.NumDescriptors = uavCount;
+ uavRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
+ D3D12_ROOT_PARAMETER1 rp[3]{};
+ rp[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
+ rp[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+ rp[0].Constants.ShaderRegister = 0;
+ rp[0].Constants.Num32BitValues = 8;
+ rp[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
+ rp[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+ rp[1].DescriptorTable.NumDescriptorRanges = 1;
+ rp[1].DescriptorTable.pDescriptorRanges = &srvRange;
+ rp[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
+ rp[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+ rp[2].DescriptorTable.NumDescriptorRanges = 1;
+ rp[2].DescriptorTable.pDescriptorRanges = &uavRange;
+ D3D12_VERSIONED_ROOT_SIGNATURE_DESC rd{};
+ rd.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
+ rd.Desc_1_1.NumParameters = 3;
+ rd.Desc_1_1.pParameters = rp;
+ ComPtr<ID3DBlob> sig, err;
+ if (FAILED(D3D12SerializeVersionedRootSignature(&rd, &sig, &err))) return false;
+ if (FAILED(device->CreateRootSignature(0, sig->GetBufferPointer(),
+ sig->GetBufferSize(), IID_PPV_ARGS(&rootSig)))) return false;
+ D3D12_COMPUTE_PIPELINE_STATE_DESC pd{};
+ pd.pRootSignature = rootSig.Get();
+ pd.CS.pShaderBytecode = cs.data();
+ pd.CS.BytecodeLength = cs.size();
+ if (FAILED(device->CreateComputePipelineState(&pd, IID_PPV_ARGS(&pso)))) return false;
+ D3D12_DESCRIPTOR_HEAP_DESC hd{};
+ hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
+ hd.NumDescriptors = heapSlots;
+ hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
+ if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap)))) return false;
+ increment = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+ return true;
+ }
+
+ void bind(ID3D12GraphicsCommandList* list, const float constants[8],
+ uint64_t srvGpu, uint64_t uavGpu) const
+ {
+ ID3D12DescriptorHeap* heaps[] = { heap.Get() };
+ list->SetDescriptorHeaps(1, heaps);
+ list->SetComputeRootSignature(rootSig.Get());
+ list->SetPipelineState(pso.Get());
+ list->SetComputeRoot32BitConstants(0, 8, constants, 0);
+ const D3D12_GPU_DESCRIPTOR_HANDLE srv{ srvGpu };
+ const D3D12_GPU_DESCRIPTOR_HANDLE uav{ uavGpu };
+ list->SetComputeRootDescriptorTable(1, srv);
+ list->SetComputeRootDescriptorTable(2, uav);
+ }
+};
+
+inline bool loadShaderBytes(const char* name, std::vector<uint8_t>& bytes)
+{
+ const std::string path = std::string(VEYRA_SHADER_DIR "/") + name;
+ HANDLE f = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (f == INVALID_HANDLE_VALUE) {
+ veyra::log::error("gfx-util", std::format("shader missing: {}", path));
+ return false;
+ }
+ LARGE_INTEGER sz{};
+ GetFileSizeEx(f, &sz);
+ bytes.resize(static_cast<size_t>(sz.QuadPart));
+ DWORD read = 0;
+ ReadFile(f, bytes.data(), static_cast<DWORD>(bytes.size()), &read, nullptr);
+ CloseHandle(f);
+ return !bytes.empty();
+}
+
+inline void makeSrv(ID3D12Device* device, ID3D12Resource* resource, DXGI_FORMAT fmt,
+ const D3D12_CPU_DESCRIPTOR_HANDLE& handle)
+{
+ D3D12_SHADER_RESOURCE_VIEW_DESC srv{};
+ srv.Format = fmt;
+ srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ srv.Texture2D.MostDetailedMip = 0;
+ srv.Texture2D.MipLevels = 1;
+ srv.Texture2D.PlaneSlice = 0;
+ srv.Texture2D.ResourceMinLODClamp = 0.0f;
+ device->CreateShaderResourceView(resource, &srv, handle);
+}
+
+inline void makeUav(ID3D12Device* device, ID3D12Resource* resource, DXGI_FORMAT fmt,
+ const D3D12_CPU_DESCRIPTOR_HANDLE& handle)
+{
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uav{};
+ uav.Format = fmt;
+ uav.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
+ device->CreateUnorderedAccessView(resource, nullptr, &uav, handle);
+}
+
+// Driver workaround (evidenced by bare-present stages 5-9, 2026-09-04):
+// on this driver (RTX 5070, 616.56), CreateShaderResourceView writing
+// directly into a SHADER-VISIBLE CBV_SRV_UAV heap corrupts the flip-model
+// Present path (fabricated DXGI_ERROR_DEVICE_REMOVED, removedReason
+// DXGI_ERROR_INVALID_CALL, no DRED). Creating the SRV in a NON-shader-
+// visible staging heap and CopyDescriptorsSimple into the visible heap is
+// proven safe (stage 9: 600/600 presents). UAVs/CBVs direct into visible
+// heaps are safe (stages 7/8) and stay direct.
+class DescriptorStager {
+public:
+ bool initialize(ID3D12Device* device, UINT slots)
+ {
+ device_ = device;
+ D3D12_DESCRIPTOR_HEAP_DESC hd{};
+ hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
+ hd.NumDescriptors = slots;
+ hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
+ if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap_)))) return false;
+ increment_ = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+ capacity_ = slots;
+ return true;
+ }
+
+ // Creates an SRV for `resource` via the staging heap and copies it into
+ // `targetSlot` of `visibleHeap`. srvDesc may be null for defaults.
+ void stageSrv(ID3D12Resource* resource, const D3D12_SHADER_RESOURCE_VIEW_DESC* srvDesc,
+ ID3D12DescriptorHeap* visibleHeap, UINT targetSlot)
+ {
+ const UINT stagingSlot = next_ % capacity_;
+ next_ = (next_ + 1) % capacity_;
+ const D3D12_CPU_DESCRIPTOR_HANDLE staging{
+ heap_->GetCPUDescriptorHandleForHeapStart().ptr + stagingSlot * increment_ };
+ device_->CreateShaderResourceView(resource, srvDesc, staging);
+ const D3D12_CPU_DESCRIPTOR_HANDLE dst{
+ visibleHeap->GetCPUDescriptorHandleForHeapStart().ptr + targetSlot * increment_ };
+ device_->CopyDescriptorsSimple(1, dst, staging, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+ }
+
+ ID3D12DescriptorHeap* heap() const { return heap_.Get(); }
+ UINT increment() const { return increment_; }
+
+private:
+ ID3D12Device* device_ = nullptr;
+ ComPtr<ID3D12DescriptorHeap> heap_;
+ UINT increment_ = 0;
+ UINT capacity_ = 0;
+ UINT next_ = 0;
+};
+
+// Graphics present pass: fullscreen triangle blit onto a flip back buffer
+// (flip buffers may only transition PRESENT <-> RENDER_TARGET).
+struct GraphicsPass {
+ ComPtr<ID3D12RootSignature> rootSig;
+ ComPtr<ID3D12PipelineState> pso;
+ ComPtr<ID3D12DescriptorHeap> heap;
+ UINT increment = 0;
+
+ bool create(ID3D12Device* device, const std::vector<uint8_t>& vs,
+ const std::vector<uint8_t>& ps, UINT heapSlots)
+ {
+ D3D12_DESCRIPTOR_RANGE1 srvRange{};
+ srvRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
+ srvRange.NumDescriptors = 1;
+ srvRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
+ D3D12_STATIC_SAMPLER_DESC sampler{};
+ sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
+ sampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
+ sampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
+ sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
+ sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
+ sampler.ShaderRegister = 0;
+ sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
+ D3D12_ROOT_PARAMETER1 rp[2]{};
+ rp[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
+ rp[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
+ rp[0].Constants.ShaderRegister = 0;
+ rp[0].Constants.Num32BitValues = 8;
+ rp[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
+ rp[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
+ rp[1].DescriptorTable.NumDescriptorRanges = 1;
+ rp[1].DescriptorTable.pDescriptorRanges = &srvRange;
+ D3D12_VERSIONED_ROOT_SIGNATURE_DESC rd{};
+ rd.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
+ rd.Desc_1_1.NumParameters = 2;
+ rd.Desc_1_1.pParameters = rp;
+ rd.Desc_1_1.NumStaticSamplers = 1;
+ rd.Desc_1_1.pStaticSamplers = &sampler;
+ ComPtr<ID3DBlob> sig, err;
+ if (FAILED(D3D12SerializeVersionedRootSignature(&rd, &sig, &err))) return false;
+ if (FAILED(device->CreateRootSignature(0, sig->GetBufferPointer(),
+ sig->GetBufferSize(), IID_PPV_ARGS(&rootSig)))) return false;
+ D3D12_GRAPHICS_PIPELINE_STATE_DESC pd{};
+ pd.pRootSignature = rootSig.Get();
+ pd.VS.pShaderBytecode = vs.data();
+ pd.VS.BytecodeLength = vs.size();
+ pd.PS.pShaderBytecode = ps.data();
+ pd.PS.BytecodeLength = ps.size();
+ pd.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
+ pd.SampleMask = UINT_MAX;
+ pd.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
+ pd.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
+ pd.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
+ pd.NumRenderTargets = 1;
+ pd.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
+ pd.SampleDesc.Count = 1;
+ if (FAILED(device->CreateGraphicsPipelineState(&pd, IID_PPV_ARGS(&pso)))) return false;
+ D3D12_DESCRIPTOR_HEAP_DESC hd{};
+ hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
+ hd.NumDescriptors = heapSlots;
+ hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
+ if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap)))) return false;
+ increment = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+ return true;
+ }
+};
+
+inline D3D12_CPU_DESCRIPTOR_HANDLE cpuHandleOf(const ComputePass& p, UINT slot)
+{
+ return D3D12_CPU_DESCRIPTOR_HANDLE{ p.heap->GetCPUDescriptorHandleForHeapStart().ptr + slot * p.increment };
+}
+
+inline D3D12_GPU_DESCRIPTOR_HANDLE gpuHandleOf(const ComputePass& p, UINT slot)
+{
+ return D3D12_GPU_DESCRIPTOR_HANDLE{ p.heap->GetGPUDescriptorHandleForHeapStart().ptr + slot * p.increment };
+}
+
+} // namespace veyra::pipeline
diff --git a/loop/BACKLOG.md b/loop/BACKLOG.md
index c34d8150..44daca63 100644
--- a/loop/BACKLOG.md
+++ b/loop/BACKLOG.md
@@ -25,7 +25,7 @@
- [x] **R2.3 ResetCoordinator tests**:open/seek/cut/drop/resize/source-switch/pause-resume/device-lost 八类事件同一 epoch;负/缺失 PTS、跨 epoch history、窗口上限和 fence ownership 测试 Debug/Release 通过。
<!-- 2026-09-06 Goal cycles 030-033: R0.1 takeover fingerprint 61feb89b + probes r0-*; R1.1 gate 42-check fail-closed proven red 34/42; R1.2 corpus 10 clips + SHA256 manifest (corpus:* green); R2.1-R2.3 delivered as one contract family include/veyra/pipeline + PipelineContractTests 50/50 debug+release (rational PTS, 8 reset reasons at frame boundaries, cross-epoch rejection, window cap, fence ownership). Checkpoints: bb9c5361/7ec1e0c/c7d6414/07eb66d. -->
- [x] **R3.1 CMake 产品库**:建立并实际链接 `veyra_pipeline`、`veyra_guidance`、`veyra_sources`、`veyra_sinks`;不允许空 target 或只含接口。
-- [ ] **R3.2 真 EnhanceGraph**:把 D3D12VA/YUV、SR、scene、NVOF/confidence、parity encode、Feature18、parity decode、optional FG、post mix 的真实提交从 `player_probe`/harness 迁入共享 graph;主路径 readback=0。
+- [x] **R3.2 真 EnhanceGraph**:把 D3D12VA/YUV、SR、scene、NVOF/confidence、parity encode、Feature18、parity decode、optional FG、post mix 的真实提交从 `player_probe`/harness 迁入共享 graph;主路径 readback=0。
- [ ] **R3.3 probe 去重**:`player_probe` 只做参数、组装、scenario、JSON;目标小于 800 行且不保留第二套 NGX/NVOF/barrier/resource lifetime。headless test 与 player probe 对 300 帧产生同计数/输出 hash。
- [ ] **R4.1 NVOF provider**:复用已存在 SDK 5.0.7 与 `NvOfSession`;保留 B8G8R8A8、SHORT2 `/32`、grid4、cost、10/10 位移与逆序释放证据;第一帧/reset 不消费旧 history。
- [ ] **R4.2 Guidance validator**:GPU cost+luma warp residual+out-of-frame/occlusion;Buffered/Export 增加 forward/back consistency;confidence 平滑衰减 motion;可视化与 P05/P50/P95。
diff --git a/loop/JOURNAL.md b/loop/JOURNAL.md
index 090b271b..0c6e5bae 100644
--- a/loop/JOURNAL.md
+++ b/loop/JOURNAL.md
@@ -944,6 +944,37 @@ C staged teardown 定位崩溃=swapChain_.Release,矩阵证明 NVOF+debug layer+
- 新 blocker:L2 GBV runtime id=938 未初始化描述符(待修,非本任务)。
- 未执行:query-heap GPU timestamp(用户明令禁止);Reviewer/checkpoint(未授权)。
+## Cycle 037 — R3.2a GPU 辅助设施迁入 veyra_pipeline(2026-09-06 Goal)
+
+### Before
+
+- Phase: 5(重开,in_progress)
+- 唯一任务: 把 player_probe 的 GPU 辅助设施逐字迁入 `include/veyra/pipeline/GpuPassUtils.h`(makeTexture/makeUploadBuffer/StateTracker/ComputePass/loadShaderBytes/makeSrv/makeUav/DescriptorStager/GraphicsPass + cpu/gpuHandle helper),player_probe 删除本地副本改用产品库版本;veyra_pipeline 定义 VEYRA_SHADER_DIR 并链接 d3d12;probe 链接 veyra_pipeline(本步即真实依赖)。
+- 可证伪假设: 若迁移引入行为差异,player probe 冒烟(exit 12/计数/mvecSource)将变化;预期完全不变。
+- 预计修改文件: include/veyra/pipeline/GpuPassUtils.h(新)、tools/player_probe/main.cpp(删 101-419 区段改 include)、CMakeLists.txt(veyra_pipeline 加 VEYRA_SHADER_DIR+d3d12;probe 已链 veyra_pipeline? 否——加链接)。
+- 快速检查命令: `build` 双配置 → 0;player 冒烟 exit 12 + driftP95 同量级 + mvecSource=nvof + NR/FG 计数非零;`phase5.ps1` → product:player-links-pipeline 转 PASS。
+- 预期新增证据: probe 用产品库辅助设施运行无回归 + gate 检查转绿。
+
+### After
+
+- 实际修改(三个子步骤一个 cycle,如实记录):
+ - **R3.2a**: include/veyra/pipeline/GpuPassUtils.h(makeTexture/makeUploadBuffer/StateTracker/ComputePass/loadShaderBytes/makeSrv/makeUav/DescriptorStager/GraphicsPass + cpu/gpuHandleOf,357 行逐字迁移);player_probe 删除本地副本改 using;veyra_pipeline 定义 VEYRA_SHADER_DIR 并链 d3d12/d3dcompiler。
+ - **R3.2b**: include/veyra/pipeline/EnhanceGraph.h(214 行)+ src/pipeline/EnhanceGraph.cpp(1020 行)——完整 GPU 链类:资源/零初始化上传(**直接 ExecuteCommandLists**)/NVOF init/NGX core+snippet+NR Create+SR Create+FG Create+warmup(**snippetEvaluateFeature/evaluate**)/五个 compute pass/静态 views/createViews 独立阶段(sink 之间)/process 全链(NV12 源→YUV→SR/bypass→parity→NR evaluate→parity decode→videoFrame+NVOF A/B→NVOF execute+densify→FG evaluate→genFrame)/shutdown(s10 三相 NVOF teardown + 逆序 NGX + 分阶段纹理释放)/场景 toggle setter(setNrEnabled 同步刷新 blit slot 2 SRV——原 probe 运行时行为)。
+ - **R3.2c**: player_probe 3641→**1971 行**:引擎初始化段→graph 构造;processOneFrame 500 行→薄包装(graph.process + presentQueue 推送,保持 previous→generated→current 呈现顺序);teardown 拆分(NVOF fence drain 用 graph 访问器在 graph.shutdown() 前,audio/ring/queue-drain/sink/ring/context 留 probe);bare-stage 诊断改用本地 NgxCoreHost;pumpPresents 用 graph 纹理访问器;JSON 计数经全局桥接。
+- 调试历程(4 个真问题 + 1 个测试期望):
+ 1. 首轮 Present 即 DEVICE_REMOVED(0x887A0005/DRIVER_INTERNAL_ERROR,无 DRED、debug layer 0 错误——注入层假报特征)。二分定位:**graph views 创建后首 Present 必挂**;VEYRA_GRAPH_VIEWS_OFF=1 则 958 presents 全过。曾试 SRV 全走 DescriptorStager(stage9 安全路径)仍挂——本机上"已初始化描述符+dispatch+Present"组合即触发,而**基线 r0/r32a 的 views 默认从未创建**(VEYRA_VIEWS_* 门控默认关),dispatch 一直消费未写槽位(这正是 GBV id=938 blocker 的来源)。裁定:createViews 复刻原始 env 门控(默认 OFF),保持与全部 t10/r0 证据一致的运行时行为;描述符初始化与注入层的交互是 **R6.1 的既定范围**。
+ 2. 计数全零但链路实际在跑(插桩证明 nr/sr/fg 递增):我的批量改名把 JSON 桥接捕获行 RHS 也改成自赋值(g_graphNrEval = g_graphNrEval)。修复后计数恢复。
+ 3. sink 顺序约束:graph views 必须在 swapchain 分配之后——拆出 createViews() 独立阶段,probe 在 sink+audio 后调用。
+ 4. 编译轮次:FFmpeg include 缺失(加 FFMPEG guard 条件)、hwcontext_d3d12va 头、/WX- 第三方头、createViews 链接名、bareCore 声明位置、残留释放段/gmetrics 作用域——各一次修复。
+- 最终验证(默认 env,r32final-185450): **exit 12(已知 drift FAIL 不变)**;driftP95=2827ms(基线 2803-2858 同量级);presents=958、**nr=432、sr=497、fg=461、nvof=461、mvecSource=nvof**(真实 NVOF 引导)、audioUnderruns=0、自然 teardown——与迁移前基线完全对等,**零行为回归**。
+- Gate: `phase5.ps1` → exit 1,**26/45**;**product:enhance-graph-submits-gpu 与 product:player-links-pipeline 双双转绿**(EnhanceGraph.cpp 真含 ExecuteCommandLists+NGX evaluate;probe 真链接并调用 veyra_pipeline)。剩余红项 = quality-runner(R3.3/R4)+ 矩阵/depth/耐久(R4/R5)。
+- 失败 fingerprint: player|present-removed|1|views-initialized-trips-injected-layer → 按证据回退到基线门控语义,R6.1 负责 descriptor 初始化。第 1 次尝试关闭。
+- 是否有进展,依据: 是——撤销 Phase 5 的核心 P0("EnhanceGraph 只计数,真实 GPU 链在 harness")已修复:真实链现在在产品库内执行,probe 只做组装/调度/呈现/JSON;且行为对等有机器证据。
+- STATE/BACKLOG 更新: cycle.completed=37;BACKLOG R3.2 → DONE;R3.3(probe<800 行 + headless 同 hash 验证)为下一动作。
+- 下一唯一动作: R3.3 — player_probe 1971 行继续去重(bare-stage 诊断矩阵 ~570 行可移入独立诊断工具或删除其二义段),加 headless integration test 与 probe 对同一 300 帧输入产生相同 output/config hash 与 Evaluate 计数(R3 最窄证明),使 quality-runner 具备基础。
+
+---
+
## Cycle 036 — R3.1c veyra_sources:MediaFileSource(2026-09-06 Goal)
### Before
diff --git a/loop/STATE.json b/loop/STATE.json
index b668f034..b611ce05 100644
--- a/loop/STATE.json
+++ b/loop/STATE.json
@@ -76,14 +76,14 @@
}
],
"cycle": {
- "completed": 36,
+ "completed": 37,
"maximum": 120,
"sameFailureAttempts": 0,
"maximumSameFailureAttempts": 3,
"noProgressCycles": 0,
"maximumNoProgressCycles": 5
},
- "currentTask": "R3.1 complete (Cycles 034-036): all four product libraries established with real members and gate-verified - veyra_pipeline (contracts+ResetCoordinator), veyra_guidance (IGuidanceProvider+ZeroGuidanceProvider GPU-verified 13/13), veyra_sinks (WASAPI audio extracted, no regression), veyra_sources (MediaFileSource composing veyra_media, 23/23 corpus-driven contract tests). Phase5 gate 28/45: all product-target checks green; remaining = quality runner, player-links-pipeline, enhance-graph-submits-gpu + matrix/depth/endurance (R3.2+).",
+ "currentTask": "R3.2 complete (Cycle 037): the REAL GPU chain now lives in veyra_pipeline::EnhanceGraph (src/pipeline/EnhanceGraph.cpp, 1020 lines - ExecuteCommandLists + NGX evaluate + full per-frame chain + s10-ordered teardown). player_probe is assembly/scheduling/present/JSON only (3641->1971 lines) and genuinely links veyra_pipeline. Behavior parity verified: exit 12 unchanged, nr=432/sr=497/fg=461/nvof=461/mvecSource=nvof/presents=958/underruns=0, natural teardown. Gate: product:enhance-graph-submits-gpu + product:player-links-pipeline BOTH GREEN (26/45). System finding recorded: initialized descriptors + dispatch + Present trips the injected-layer fabricated removal; baseline views-off semantics preserved (R6.1 owns the descriptor-init fix).",
"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.2: move the real GPU chain from tools/player_probe/main.cpp into src/pipeline/EnhanceGraph.cpp - ingress color conversion (NV12Upload/YUV->RGB), SR bypass-or-upscale decision, parity encode, Feature 18 evaluate, parity decode, NVOF guidance production (born as NvofGuidanceProvider in veyra_guidance), optional FG, bounded post mix. EnhanceGraph::process must submit real command lists (gate: ExecuteCommandLists + NGX evaluate in src/pipeline/EnhanceGraph.cpp). Then R3.3 slims player_probe below 800 lines as assembly+JSON only.",
- "updatedAt": "2026-09-06T18:40:00+08:00"
+ "nextAction": "Playbook R3.3: deduplicate player_probe further (bare-stage diagnostic matrix ~570 lines -> separate diagnostic tool or fold into descriptor_present_probe), then build the headless quality runner base: veyra_quality_probe target that links veyra_pipeline + veyra_sources and runs the corpus through EnhanceGraph headlessly (offscreen, no window/audio), emitting the R1.1 gate JSON contract (extents/frames/counters/hashes). Target: player_probe <800 lines and quality:runner-exe check green.",
+ "updatedAt": "2026-09-06T19:00:00+08:00"
}
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
new file mode 100644
index 00000000..0cf2d23a
--- /dev/null
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -0,0 +1,1020 @@
+// EnhanceGraph implementation - the real GPU chain migrated from
+// tools/player_probe main.cpp (R3.2). Ordering constraints preserved from the
+// injected-layer era evidence: committed resources and NGX/NVOF objects are
+// created BEFORE descriptor views; FG warm-up evaluate precedes views; static
+// views are created last. Per-frame execution uses the shared command slot
+// ring (NR evaluates on a fresh list - snippet constraint).
+#include "veyra/pipeline/EnhanceGraph.h"
+
+#include <algorithm>
+#include <chrono>
+#include <cmath>
+#include <cstring>
+#include <fstream>
+#include <thread>
+
+#include "veyra/Log.h"
+#include "veyra/Result.h"
+#include "veyra/gfx/CommandSlotRing.h"
+#include "veyra/gfx/D3D12DeviceContext.h"
+#include "veyra/ngx/DlssFgBackend.h"
+#include "veyra/ngx/DlssNrParameters.h"
+#include "veyra/ngx/DlssNrRuntimeAdapter.h"
+#include "veyra/ngx/DlssSrBackend.h"
+#include "veyra/ngx/NgxCoreHost.h"
+#include "veyra/ngx/NgxParameters.h"
+#include "veyra/ngx/NvOfSession.h"
+
+extern "C" {
+#include <libavutil/frame.h>
+#include <libavutil/hwcontext_d3d12va.h>
+#include <libswscale/swscale.h>
+}
+
+namespace veyra::pipeline {
+
+namespace {
+
+constexpr int64_t usPerSecond = 1000000;
+
+} // namespace
+
+EnhanceGraph::EnhanceGraph(gfx::D3D12DeviceContext& context, gfx::CommandSlotRing& ring)
+ : context_(context)
+ , ring_(ring)
+{
+}
+
+EnhanceGraph::~EnhanceGraph()
+{
+ // shutdown() must have run (features/NVOF/NGX need ordered teardown while
+ // the device is alive); ComPtr releases afterwards are then no-ops.
+}
+
+// ---------------------------------------------------------------------------
+// initialize: exact ordering of the proven probe sequence.
+// ---------------------------------------------------------------------------
+bool EnhanceGraph::initialize(const EnhanceGraphDesc& desc)
+{
+ desc_ = desc;
+ srcW_ = desc.sourceWidth;
+ srcH_ = desc.sourceHeight;
+ workW_ = desc.workWidth;
+ workH_ = desc.workHeight;
+ nvofW_ = workW_;
+ nvofH_ = workH_;
+ srEnabled_ = desc.enableSr;
+ nrEnabled_ = desc.enableNr && !desc.noFeatures && !desc.noNgx;
+ fgEnabled_ = desc.enableFg && !desc.noNgx;
+ Status st = Status::Ok;
+
+ lumaPitch_ = (static_cast<size_t>(srcW_) + 255) & ~size_t(255);
+ chromaPitch_ = lumaPitch_;
+ lumaSize_ = lumaPitch_ * srcH_;
+ chromaSize_ = chromaPitch_ * (srcH_ / 2);
+ dPitch_ = (static_cast<size_t>(workW_) * 4 + 255) & ~size_t(255);
+ const size_t dSize = dPitch_ * workH_;
+ nv12Buf_.resize(lumaSize_ + chromaSize_);
+
+ if (!createResources()) return false;
+ if (!initZeroAndDepthTextures()) return false;
+ if (!initNvof()) return false;
+ if (!initNgxFeatures()) return false;
+ if (!createComputePasses()) return false;
+
+ initialized_ = true;
+ veyra::log::info("graph", std::format("initialized src={}x{} work={}x{} sr={} nr={} fg={} nvof={}",
+ srcW_, srcH_, workW_, workH_, srEnabled_ ? 1 : 0, nrEnabled_ ? 1 : 0,
+ fgEnabled_ ? 1 : 0, (nvof_ && nvof_->initialized()) ? 1 : 0));
+ return true;
+}
+
+bool EnhanceGraph::createResources()
+{
+ upLuma_[0] = makeUploadBuffer(context_.device(), lumaSize_);
+ upLuma_[1] = makeUploadBuffer(context_.device(), lumaSize_);
+ upChroma_[0] = makeUploadBuffer(context_.device(), chromaSize_);
+ upChroma_[1] = makeUploadBuffer(context_.device(), chromaSize_);
+ upDepth_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
+ upZeroDepth_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
+ upZeroMotion_ = makeUploadBuffer(context_.device(), dPitch_ * workH_);
+ lumaTex_ = makeTexture(context_.device(), srcW_, srcH_, DXGI_FORMAT_R8_UNORM, true);
+ chromaTex_ = makeTexture(context_.device(), srcW_, srcH_ / 2, DXGI_FORMAT_R8G8_UNORM, true);
+ srcRgba_ = makeTexture(context_.device(), srcW_, srcH_, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
+ workRgba_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
+ proxyTex_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ neuralTex_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ finalRgba_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
+ videoFrame_[0] = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ videoFrame_[1] = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ confTex_ = makeTexture(context_.device(), nvofW_, nvofH_, DXGI_FORMAT_R8_UNORM, true);
+ flowTex_ = makeTexture(context_.device(), nvofW_, nvofH_, DXGI_FORMAT_R16G16_FLOAT, true);
+ depthTex_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R32_FLOAT, false);
+ genFrame_[0] = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ genFrame_[1] = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R8G8B8A8_UNORM, true);
+ nrZeroMotion_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R16G16_FLOAT, false);
+ nrZeroDepth_ = makeTexture(context_.device(), workW_, workH_, DXGI_FORMAT_R32_FLOAT, false);
+ rawW_ = (nvofW_ + nvofGrid_ - 1) / nvofGrid_;
+ rawH_ = (nvofH_ + nvofGrid_ - 1) / nvofGrid_;
+ nvofRawTex_ = makeTexture(context_.device(), rawW_, rawH_, DXGI_FORMAT_R16G16_SINT, false);
+ nvofCostTex_ = makeTexture(context_.device(), rawW_, rawH_, DXGI_FORMAT_R8_UINT, false);
+ nvofInA_ = makeTexture(context_.device(), nvofW_, nvofH_, DXGI_FORMAT_B8G8R8A8_UNORM, true);
+ nvofInB_ = makeTexture(context_.device(), nvofW_, nvofH_, DXGI_FORMAT_B8G8R8A8_UNORM, true);
+
+ if (!upLuma_[0] || !upLuma_[1] || !upChroma_[0] || !upChroma_[1] ||
+ !upDepth_ || !upZeroDepth_ || !upZeroMotion_ ||
+ !lumaTex_ || !chromaTex_ || !srcRgba_ || !workRgba_ || !proxyTex_ ||
+ !neuralTex_ || !finalRgba_ || !videoFrame_[0] || !videoFrame_[1] ||
+ !flowTex_ || !depthTex_ || !genFrame_[0] || !genFrame_[1] ||
+ !nrZeroMotion_ || !nrZeroDepth_ || !nvofRawTex_ || !nvofCostTex_ ||
+ !nvofInA_ || !nvofInB_ || !confTex_) {
+ veyra::log::error("graph", "resource allocation failed");
+ return false;
+ }
+
+ // Persistent mapping of the NV12 upload ring (before any views).
+ bool uploadsMapped = true;
+ for (int i = 0; i < 2; ++i) {
+ if (FAILED(upLuma_[i]->Map(0, nullptr, reinterpret_cast<void**>(&mappedLuma_[i]))) ||
+ FAILED(upChroma_[i]->Map(0, nullptr, reinterpret_cast<void**>(&mappedChroma_[i])))) {
+ uploadsMapped = false;
+ }
+ }
+ if (!uploadsMapped) {
+ veyra::log::error("graph", "NV12 upload persistent map failed");
+ return false;
+ }
+ veyra::log::info("graph", "NV12 upload ring persistently mapped (2 buffers)");
+ return true;
+}
+
+bool EnhanceGraph::initZeroAndDepthTextures()
+{
+ // Depth constants uploaded once (copies are safe before views exist).
+ uint8_t* d = nullptr; uint8_t* zd = nullptr; uint8_t* zm = nullptr;
+ upDepth_->Map(0, nullptr, reinterpret_cast<void**>(&d));
+ upZeroDepth_->Map(0, nullptr, reinterpret_cast<void**>(&zd));
+ upZeroMotion_->Map(0, nullptr, reinterpret_cast<void**>(&zm));
+ for (uint32_t y = 0; y < workH_; ++y) {
+ float* dRow = reinterpret_cast<float*>(d + y * dPitch_);
+ float* zdRow = reinterpret_cast<float*>(zd + y * dPitch_);
+ uint16_t* zmRow = reinterpret_cast<uint16_t*>(zm + y * dPitch_);
+ for (uint32_t x = 0; x < workW_; ++x) {
+ dRow[x] = 0.9f; // explicit constant far depth (video content)
+ zdRow[x] = 0.5f; // NR zero-depth explicit fallback
+ zmRow[x * 2] = 0; zmRow[x * 2 + 1] = 0;
+ }
+ }
+ upDepth_->Unmap(0, nullptr);
+ upZeroDepth_->Unmap(0, nullptr);
+ upZeroMotion_->Unmap(0, nullptr);
+
+ Status st = Status::Ok;
+ ID3D12GraphicsCommandList* list = ring_.acquire(0, st);
+ if (list == nullptr) return false;
+ auto uploadTex = [&](ID3D12Resource* tex, const ComPtr<ID3D12Resource>& up, DXGI_FORMAT fmt) {
+ D3D12_RESOURCE_BARRIER b{};
+ b.Transition.pResource = tex;
+ b.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
+ b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
+ b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &b);
+ D3D12_TEXTURE_COPY_LOCATION dst{}, src{};
+ dst.pResource = tex;
+ dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ src.pResource = up.Get();
+ src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
+ src.PlacedFootprint.Footprint.Format = fmt;
+ src.PlacedFootprint.Footprint.Width = workW_;
+ src.PlacedFootprint.Footprint.Height = workH_;
+ src.PlacedFootprint.Footprint.Depth = 1;
+ src.PlacedFootprint.Footprint.RowPitch = static_cast<UINT>(dPitch_);
+ list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
+ D3D12_RESOURCE_BARRIER back{};
+ back.Transition.pResource = tex;
+ back.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
+ back.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+ back.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ list->ResourceBarrier(1, &back);
+ };
+ uploadTex(depthTex_.Get(), upDepth_, DXGI_FORMAT_R32_FLOAT);
+ uploadTex(nrZeroDepth_.Get(), upZeroDepth_, DXGI_FORMAT_R32_FLOAT);
+ uploadTex(nrZeroMotion_.Get(), upZeroMotion_, DXGI_FORMAT_R16G16_FLOAT);
+ list->Close();
+ ID3D12CommandList* lists[] = { list };
+ context_.directQueue()->ExecuteCommandLists(1, lists);
+ ComPtr<ID3D12Fence> initFence;
+ context_.device()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&initFence));
+ context_.directQueue()->Signal(initFence.Get(), 1);
+ if (nvofOutEvent_ == nullptr) {
+ nvofOutEvent_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
+ }
+ initFence->SetEventOnCompletion(1, nvofOutEvent_);
+ WaitForSingleObject(nvofOutEvent_, 5000);
+ veyra::log::info("graph", "depth/zero guidance textures initialized");
+ return true;
+}
+
+bool EnhanceGraph::initNvof()
+{
+ if (desc_.noFeatures) {
+ veyra::log::info("graph", "VEYRA_NO_FEATURES: NVOF session skipped");
+ return true;
+ }
+ nvof_ = std::make_unique<ngx::NvOfSession>();
+ if (nvofOutFence_ == nullptr) {
+ if (FAILED(context_.device()->CreateFence(0, D3D12_FENCE_FLAG_NONE,
+ IID_PPV_ARGS(&nvofOutFence_)))) {
+ veyra::log::error("graph", "NVOF out fence creation failed");
+ return false;
+ }
+ }
+ if (nvofOutEvent_ == nullptr) {
+ nvofOutEvent_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
+ }
+ ngx::NvOfSession::Desc nd{};
+ nd.width = nvofW_; nd.height = nvofH_;
+ nd.inFence = context_.fence();
+ nd.outFence = nvofOutFence_.Get();
+ nd.gridSize = 4;
+ // s6 contract: B8G8R8A8 inputs, raw R16G16_SINT + R8_UINT cost at grid
+ // extent, passed explicitly; allocation failure = fail closed.
+ Status st = Status::Ok;
+ if (!nvof_->initialize(context_.device(), nvofInA_.Get(), nvofInB_.Get(),
+ nvofRawTex_.Get(), nvofCostTex_.Get(), nd, st)) {
+ veyra::log::error("graph", "NVOF init failed");
+ return false;
+ }
+ selectedGrid_ = nvof_->caps().selectedGrid;
+ return true;
+}
+
+bool EnhanceGraph::initNgxFeatures()
+{
+ if (desc_.noNgx) {
+ veyra::log::warn("graph", "VEYRA_NO_NGX: core+features skipped; NVOF only");
+ return true;
+ }
+ // Read the local NGX identity (same loader contract as the probes).
+ std::ifstream ids(std::wstring(desc_.runtimeAbsPath) + L"\\..\\config\\ngx-local.json",
+ std::ios::binary);
+ std::string idText((std::istreambuf_iterator<char>(ids)), std::istreambuf_iterator<char>());
+ std::string projectId, engineVersion;
+ {
+ auto scan = [&idText](const char* key) {
+ const std::string needle = std::string("\"") + key + "\"";
+ size_t p = idText.find(needle);
+ if (p == std::string::npos) return std::string();
+ p = idText.find('"', idText.find(':', p + needle.size()));
+ if (p == std::string::npos) return std::string();
+ return idText.substr(p + 1, idText.find('"', p + 1) - p - 1);
+ };
+ projectId = scan("ngxProjectId");
+ engineVersion = scan("engineVersion");
+ }
+ if (projectId.empty()) {
+ veyra::log::error("graph", "ngx-local.json missing");
+ return false;
+ }
+
+ coreHost_ = std::make_unique<ngx::NgxCoreHost>();
+ Status st = Status::Ok;
+ if (!coreHost_->initialize(context_.device(), desc_.runtimeAbsPath.c_str(),
+ projectId.c_str(), engineVersion.c_str(), st)) {
+ return false;
+ }
+
+ fgBackend_ = std::make_unique<ngx::DlssFgBackend>();
+ ngx::DlssFgBackend::Capability fgCaps{};
+ const bool fgAvailable = fgBackend_->queryCapability(*coreHost_, fgCaps, st);
+ if (!fgAvailable) {
+ veyra::log::error("graph", "FG unavailable; fail closed");
+ return false;
+ }
+ fgCapsAvailable_ = fgCaps.available;
+ fgMultiFrameMax_ = fgCaps.multiFrameCountMax;
+ veyra::log::info("graph", std::format("FG capability available={} multiFrameMax={}",
+ fgCaps.available, fgCaps.multiFrameCountMax));
+
+ nrAdapter_ = std::make_unique<ngx::DlssNrRuntimeAdapter>();
+ if (!nrAdapter_->load(desc_.runtimeAbsPath.c_str(), st) ||
+ !nrAdapter_->installCallerCompatibility(st) ||
+ !nrAdapter_->snippetInitExt(context_.device(), desc_.runtimeAbsPath.c_str(), nrResult_, nrSeh_) ||
+ nrResult_ != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
+ veyra::log::error("graph", std::format("NR snippet init failed 0x{:X}", nrResult_));
+ return false;
+ }
+ ngxParams_ = coreHost_->allocateParameters(st);
+ if (ngxParams_ == nullptr) return false;
+
+ srBackend_ = std::make_unique<ngx::DlssSrBackend>();
+
+ // NR feature create (8.5 create parameter contract).
+ {
+ namespace p = ngx::dlssnr;
+ ngx::ParameterBlock pb(ngxParams_);
+ pb.setU32(p::kWidth, workW_); pb.setU32(p::kHeight, workH_);
+ pb.setU32(p::kInputWidth, workW_); pb.setU32(p::kInputHeight, workH_);
+ pb.setU32(p::kOutputWidth, workW_); pb.setU32(p::kOutputHeight, workH_);
+ pb.setU32(p::kOutputDotWidth, workW_); pb.setU32(p::kOutputDotHeight, workH_);
+ pb.setU32(p::kUpscaling, 0);
+ pb.setF32(p::kScale, 1.0f); pb.setF32(p::kScalingRatio, 1.0f);
+ pb.setVoid(p::kComputeScalingRatioCallback,
+ reinterpret_cast<void*>(&ngx::DlssNrRuntimeAdapter::scalingRatioCallback));
+ pb.setI32(p::kHintRenderPreset, 0);
+ pb.setU32(p::kStdWidth, workW_); pb.setU32(p::kStdHeight, workH_);
+ pb.setI32(p::kPerfQualityValue, 1);
+ pb.setU32(p::kCreationNodeMask, 1); pb.setU32(p::kVisibilityNodeMask, 1);
+ ID3D12GraphicsCommandList* list = ring_.acquire(0, st);
+ if (list == nullptr) return false;
+ if (!nrAdapter_->snippetCreateFeature(list, ngxParams_, &nrHandle_, nrResult_, nrSeh_) ||
+ nrResult_ != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
+ veyra::log::error("graph", std::format("NR create failed 0x{:X}", nrResult_));
+ return false;
+ }
+ (void)ring_.submitAndSignal(0);
+ (void)ring_.waitIdle();
+ }
+
+ if (srEnabled_ && !desc_.noFeatures) {
+ ngx::DlssSrBackend::CreateDesc sd{};
+ sd.inputWidth = srcW_; sd.inputHeight = srcH_;
+ sd.outputWidth = workW_; sd.outputHeight = workH_;
+ sd.perfQuality = 1; sd.enableOutputSubrects = false;
+ ID3D12GraphicsCommandList* list = ring_.acquire(0, st);
+ if (list == nullptr) return false;
+ if (!srBackend_->create(*coreHost_, list, ngxParams_, sd, st) || !srBackend_->created()) {
+ veyra::log::error("graph", "SR create failed");
+ return false;
+ }
+ (void)ring_.submitAndSignal(0);
+ (void)ring_.waitIdle();
+ }
+
+ // FG create + warm-up evaluate BEFORE descriptor views (the runtime
+ // allocates internals at the first evaluate and would fail after views
+ // exist on this system).
+ {
+ ngx::DlssFgBackend::CreateDesc fd{};
+ fd.width = workW_; fd.height = workH_;
+ fd.renderWidth = workW_; fd.renderHeight = workH_;
+ fd.backbufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
+ ID3D12GraphicsCommandList* list = ring_.acquire(0, st);
+ if (list == nullptr) return false;
+ if (!fgBackend_->create(*coreHost_, list, ngxParams_, fd, st) || !fgBackend_->created()) {
+ veyra::log::error("graph", std::format("FG create failed 0x{:X}", fgBackend_->createResult()));
+ return false;
+ }
+ (void)ring_.submitAndSignal(0);
+ (void)ring_.waitIdle();
+
+ ID3D12GraphicsCommandList* wlist = ring_.acquire(0, st);
+ if (wlist == nullptr) return false;
+ D3D12_RESOURCE_BARRIER b[4]{};
+ for (int i = 0; i < 4; ++i) {
+ b[i].Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
+ b[i].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
+ }
+ b[0].Transition.pResource = nvofInB_.Get();
+ b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
+ b[1].Transition.pResource = nrZeroMotion_.Get();
+ b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
+ b[2].Transition.pResource = depthTex_.Get();
+ b[2].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
+ b[3].Transition.pResource = genFrame_[0].Get();
+ b[3].Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
+ wlist->ResourceBarrier(4, b);
+ ngx::DlssFgBackend::EvalDesc fe{};
+ fe.backbuffer = nvofInB_.Get();
+ fe.depth = depthTex_.Get();
+ fe.mvecs = nrZeroMotion_.Get();
+ fe.outputInterpolated = genFrame_[0].Get();
+ fe.reset = true;
+ fe.frameId = 0;
+ fe.mvecScaleX = 1.0f;
+ fe.mvecScaleY = 1.0f;
+ const bool warmOk = fgBackend_->evaluate(wlist, ngxParams_, fe, st);
+ (void)warmOk;
+ for (int i = 0; i < 4; ++i) b[i].Transition.StateBefore = b[i].Transition.StateAfter;
+ b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+ b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+ b[2].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+ b[3].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
+ wlist->ResourceBarrier(4, b);
+ if (!ring_.submitAndSignal(0) || !ring_.waitIdle()) return false;
+ veyra::log::info("graph", std::format("FG warm-up evaluate done ok={} result=0x{:X}",
+ warmOk ? 1 : 0, fgBackend_->createResult()));
+ }
+ return true;
+}
+
+bool EnhanceGraph::createComputePasses()
+{
+ std::vector<uint8_t> cs;
+ if (!yuvPass_.loadShader("YuvToLinearRgb.dxil", cs) || !yuvPass_.create(context_.device(), cs, 8)) return false;
+ if (!encPass_.loadShader("ParityEncode.dxil", cs) || !encPass_.create(context_.device(), cs, 8)) return false;
+ if (!decPass_.loadShader("ParityDecode.dxil", cs) || !decPass_.create(context_.device(), cs, 8)) return false;
+ if (!blitPass_.loadShader("ScaleBlit.dxil", cs) || !blitPass_.create(context_.device(), cs, 16)) return false;
+ if (!uploadPass_.loadShader("Nv12Upload.dxil", cs) || !uploadPass_.create(context_.device(), cs, 4, 1, 2)) return false;
+ if (!densifyPass_.loadShader("NvofDensify.dxil", cs) ||
+ !densifyPass_.create(context_.device(), cs, 6, 2, 2)) return false;
+ if (!stager_.initialize(context_.device(), 64)) {
+ veyra::log::error("graph", "descriptor stager init failed");
+ return false;
+ }
+ return true;
+}
+
+bool EnhanceGraph::createViews()
+{
+ // Original probe env-matrix semantics (default OFF): the proven runtime
+ // configuration on this system runs the dispatches against
+ // never-written descriptor slots (GBV id=938 - the known Phase 6 R6.1
+ // blocker). Initializing the slots trips the injected-layer fabricated
+ // device-removed on Present; solving that interaction is R6.1 scope.
+ const bool viewsTex = GetEnvironmentVariableW(L"VEYRA_VIEWS_TEX", nullptr, 0) != 0;
+ const bool viewsRaw = GetEnvironmentVariableW(L"VEYRA_VIEWS_RAW", nullptr, 0) != 0;
+ const bool viewsUav = GetEnvironmentVariableW(L"VEYRA_VIEWS_UAV", nullptr, 0) != 0;
+ if (!viewsTex && !viewsRaw && !viewsUav) {
+ veyra::log::info("graph", "static views skipped (default; VEYRA_VIEWS_* opt-in)");
+ return true;
+ }
+ auto cpu = [this](const ComputePass& p, UINT slot) { return cpuHandleOf(p, slot); };
+ auto gpu = [this](const ComputePass& p, UINT slot) { return gpuHandleOf(p, slot); };
+ (void)gpu;
+ // SRVs must go through the staging heap (CopyDescriptorsSimple into the
+ // visible heap): direct CreateShaderResourceView writes into visible
+ // heaps trigger the fabricated device-removed on this system (bare
+ // stage 9 evidence; the safe path is proven 600/600).
+ auto stagedSrv = [this](ID3D12Resource* resource, DXGI_FORMAT fmt,
+ ComputePass& pass, UINT slot) {
+ D3D12_SHADER_RESOURCE_VIEW_DESC srv{};
+ srv.Format = fmt;
+ srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ srv.Texture2D.MostDetailedMip = 0;
+ srv.Texture2D.MipLevels = 1;
+ srv.Texture2D.PlaneSlice = 0;
+ srv.Texture2D.ResourceMinLODClamp = 0.0f;
+ stager_.stageSrv(resource, &srv, pass.heap.Get(), slot);
+ };
+
+ // STATIC DESCRIPTOR VIEWS (LAST: system constraint).
+ if (viewsTex) stagedSrv(lumaTex_.Get(), DXGI_FORMAT_R8_UNORM, yuvPass_, 0);
+ if (viewsTex) stagedSrv(chromaTex_.Get(), DXGI_FORMAT_R8G8_UNORM, yuvPass_, 1);
+ if (viewsUav) makeUav(context_.device(), srcRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(yuvPass_, 2));
+ if (viewsTex) stagedSrv(workRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, encPass_, 0);
+ if (viewsUav) makeUav(context_.device(), proxyTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpu(encPass_, 1));
+ if (viewsTex) stagedSrv(workRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, decPass_, 0);
+ if (viewsTex) stagedSrv(proxyTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass_, 1);
+ if (viewsTex) stagedSrv(neuralTex_.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass_, 2);
+ if (viewsUav) makeUav(context_.device(), finalRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(decPass_, 3));
+ // Upload pass: raw buffer SRVs per parity (slots 0/1), plane UAVs (2/3).
+ for (int i = 0; i < 2; ++i) {
+ D3D12_SHADER_RESOURCE_VIEW_DESC raw{};
+ raw.Format = DXGI_FORMAT_R32_TYPELESS;
+ raw.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
+ raw.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ raw.Buffer.FirstElement = 0;
+ raw.Buffer.NumElements = static_cast<UINT>(lumaSize_ / 4);
+ raw.Buffer.StructureByteStride = 0; // RAW view
+ if (viewsRaw) stager_.stageSrv(upLuma_[i].Get(), &raw, uploadPass_.heap.Get(), static_cast<UINT>(i));
+ }
+ if (viewsUav) makeUav(context_.device(), lumaTex_.Get(), DXGI_FORMAT_R8_UNORM, cpu(uploadPass_, 2));
+ if (viewsUav) makeUav(context_.device(), chromaTex_.Get(), DXGI_FORMAT_R8G8_UNORM, cpu(uploadPass_, 3));
+ // Blit pass layout (all static; per-use offsets chosen at bind time):
+ // 0: srcRgba SRV 1: workRgba UAV (SR bypass / NR-off blit)
+ // 2: finalRgba SRV 3/4: videoFrame UAV (section 5)
+ // 5: nvofInB SRV 6: nvofInA UAV (NVOF A:=B)
+ // 7/8: videoFrame SRV 9: nvofInB UAV (NVOF B:=video)
+ // 10: genTex SRV 11/12: videoFrame SRV (presents)
+ // 13/14: genTex SRV (slot 2)
+ if (viewsTex) stagedSrv(srcRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass_, 0);
+ if (viewsUav) makeUav(context_.device(), workRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpu(blitPass_, 1));
+ if (viewsTex) stagedSrv(finalRgba_.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass_, 2);
+ if (viewsUav) makeUav(context_.device(), videoFrame_[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpu(blitPass_, 3));
+ if (viewsUav) makeUav(context_.device(), videoFrame_[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpu(blitPass_, 4));
+ if (viewsTex) stagedSrv(nvofInB_.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, blitPass_, 5);
+ if (viewsUav) makeUav(context_.device(), nvofInA_.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, cpu(blitPass_, 6));
+ if (viewsTex) stagedSrv(videoFrame_[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 7);
+ if (viewsTex) stagedSrv(videoFrame_[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 8);
+ if (viewsUav) makeUav(context_.device(), nvofInB_.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, cpu(blitPass_, 9));
+ if (viewsTex) stagedSrv(genFrame_[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 10);
+ if (viewsTex) stagedSrv(genFrame_[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 13);
+ if (viewsTex) stagedSrv(videoFrame_[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 11);
+ if (viewsTex) stagedSrv(videoFrame_[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass_, 12);
+
+ // Densify pass views: 0=rawFlow SRV(int2) 1=cost SRV(uint)
+ // 2=flowOut UAV(float2) 3=confOut UAV(float).
+ {
+ D3D12_SHADER_RESOURCE_VIEW_DESC rf{};
+ rf.Format = DXGI_FORMAT_R16G16_SINT;
+ rf.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ rf.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ rf.Texture2D.MostDetailedMip = 0;
+ rf.Texture2D.MipLevels = 1;
+ rf.Texture2D.PlaneSlice = 0;
+ rf.Texture2D.ResourceMinLODClamp = 0.0f;
+ if (viewsTex) stager_.stageSrv(nvofRawTex_.Get(), &rf, densifyPass_.heap.Get(), 0);
+ D3D12_SHADER_RESOURCE_VIEW_DESC rc{};
+ rc.Format = DXGI_FORMAT_R8_UINT;
+ rc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ rc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ rc.Texture2D.MostDetailedMip = 0;
+ rc.Texture2D.MipLevels = 1;
+ rc.Texture2D.PlaneSlice = 0;
+ rc.Texture2D.ResourceMinLODClamp = 0.0f;
+ if (viewsTex) stager_.stageSrv(nvofCostTex_.Get(), &rc, densifyPass_.heap.Get(), 1);
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uf{};
+ uf.Format = DXGI_FORMAT_R16G16_FLOAT;
+ uf.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
+ context_.device()->CreateUnorderedAccessView(flowTex_.Get(), nullptr, &uf, cpu(densifyPass_, 2));
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uc{};
+ uc.Format = DXGI_FORMAT_R8_UNORM;
+ uc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
+ context_.device()->CreateUnorderedAccessView(confTex_.Get(), nullptr, &uc, cpu(densifyPass_, 3));
+ }
+ return true;
+}
+
+// ---------------------------------------------------------------------------
+// process: the per-frame chain (verbatim from the probe lambda).
+// ---------------------------------------------------------------------------
+bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, FrameOutputs& out)
+{
+ out = FrameOutputs{};
+ out.ptsMs = ptsMs;
+ static const bool graphOff = GetEnvironmentVariableW(L"VEYRA_GRAPH_OFF", nullptr, 0) != 0;
+ if (frame->pts == AV_NOPTS_VALUE || frame->pts < 0) {
+ return true; // no timestamp: skip this frame entirely
+ }
+
+ const uint32_t parity = static_cast<uint32_t>(realFrameIndex_ % 2);
+ if (graphOff) {
+ prevPtsMs_ = ptsMs;
+ prevValid_ = true;
+ ++realFrameIndex_;
+ out.realFrameIndex = realFrameIndex_;
+ out.videoSlot = parity;
+ out.passthrough = true;
+ return true;
+ }
+ const uint32_t slot = static_cast<uint32_t>(realFrameIndex_ % 4);
+ Status st = Status::Ok;
+
+ // 1. Source NV12: D3D12VA texture directly (GPU) or CPU upload.
+ ID3D12Resource* nv12Texture = nullptr;
+ ID3D12GraphicsCommandList* list = ring_.acquire(slot, st);
+ if (list == nullptr) { veyra::log::error("graph", "ring acquire"); return false; }
+
+ if (frame->format == AV_PIX_FMT_D3D12) {
+ auto* d3dFrame = reinterpret_cast<AVD3D12VAFrame*>(frame->data[0]);
+ if (d3dFrame == nullptr || d3dFrame->texture == nullptr) {
+ veyra::log::error("graph", "null d3d12va frame");
+ return false;
+ }
+ nv12Texture = d3dFrame->texture;
+ const UINT nv12Slice = static_cast<UINT>(d3dFrame->subresource_index);
+ if (d3dFrame->sync_ctx.fence != nullptr) {
+ if (FAILED(context_.directQueue()->Wait(
+ d3dFrame->sync_ctx.fence, d3dFrame->sync_ctx.fence_value))) {
+ veyra::log::error("graph", "nv12 fence wait");
+ return false;
+ }
+ }
+ const bool isArray = nv12Texture->GetDesc().DepthOrArraySize > 1;
+ D3D12_SHADER_RESOURCE_VIEW_DESC lumaSrv{};
+ lumaSrv.Format = DXGI_FORMAT_R8_UNORM;
+ lumaSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ lumaSrv.Texture2D.MostDetailedMip = 0;
+ lumaSrv.Texture2D.MipLevels = 1;
+ lumaSrv.Texture2D.ResourceMinLODClamp = 0.0f;
+ if (isArray) {
+ lumaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
+ lumaSrv.Texture2DArray.MostDetailedMip = 0;
+ lumaSrv.Texture2DArray.MipLevels = 1;
+ lumaSrv.Texture2DArray.FirstArraySlice = nv12Slice;
+ lumaSrv.Texture2DArray.ArraySize = 1;
+ lumaSrv.Texture2DArray.PlaneSlice = 0;
+ } else {
+ lumaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ lumaSrv.Texture2D.MostDetailedMip = 0;
+ lumaSrv.Texture2D.MipLevels = 1;
+ lumaSrv.Texture2D.PlaneSlice = 0;
+ }
+ context_.device()->CreateShaderResourceView(nv12Texture, &lumaSrv, cpuHandleOf(yuvPass_, 0));
+ D3D12_SHADER_RESOURCE_VIEW_DESC chromaSrv{};
+ chromaSrv.Format = DXGI_FORMAT_R8G8_UNORM;
+ chromaSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ chromaSrv.Texture2D.MostDetailedMip = 0;
+ chromaSrv.Texture2D.MipLevels = 1;
+ chromaSrv.Texture2D.ResourceMinLODClamp = 0.0f;
+ if (isArray) {
+ chromaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
+ chromaSrv.Texture2DArray.MostDetailedMip = 0;
+ chromaSrv.Texture2DArray.MipLevels = 1;
+ chromaSrv.Texture2DArray.FirstArraySlice = nv12Slice;
+ chromaSrv.Texture2DArray.ArraySize = 1;
+ chromaSrv.Texture2DArray.PlaneSlice = 1;
+ } else {
+ chromaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
+ chromaSrv.Texture2D.MostDetailedMip = 0;
+ chromaSrv.Texture2D.MipLevels = 1;
+ chromaSrv.Texture2D.PlaneSlice = 1;
+ }
+ context_.device()->CreateShaderResourceView(nv12Texture, &chromaSrv, cpuHandleOf(yuvPass_, 1));
+ tracker_.transition(list, nv12Texture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ } else {
+ nv12Ctx_ = sws_getCachedContext(nv12Ctx_, frame->width, frame->height,
+ static_cast<AVPixelFormat>(frame->format),
+ frame->width, frame->height, AV_PIX_FMT_NV12, SWS_POINT,
+ nullptr, nullptr, nullptr);
+ if (nv12Ctx_ == nullptr) { veyra::log::error("graph", "sws"); return false; }
+ uint8_t* planes[2] = { nv12Buf_.data(), nv12Buf_.data() + lumaSize_ };
+ const int strides[2] = { static_cast<int>(lumaPitch_), static_cast<int>(chromaPitch_) };
+ sws_scale(nv12Ctx_, frame->data, frame->linesize, 0, frame->height, planes, strides);
+ for (uint32_t y = 0; y < srcH_; ++y)
+ std::memcpy(mappedLuma_[parity] + y * lumaPitch_, planes[0] + y * lumaPitch_, srcW_);
+ for (uint32_t y = 0; y < srcH_ / 2; ++y)
+ std::memcpy(mappedChroma_[parity] + y * chromaPitch_, planes[1] + y * chromaPitch_, srcW_);
+ tracker_.transition(list, lumaTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ tracker_.transition(list, chromaTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ tracker_.transition(list, upLuma_[parity].Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ const float constants[8] = {
+ static_cast<float>(srcW_), static_cast<float>(srcH_),
+ static_cast<float>(lumaPitch_), static_cast<float>(chromaPitch_), 0, 0, 0, 0 };
+ uploadPass_.bind(list, constants,
+ gpuHandleOf(uploadPass_, parity).ptr, gpuHandleOf(uploadPass_, 2).ptr);
+ list->Dispatch((srcW_ + 31) / 32 * 2, (srcH_ + 31) / 32 * 2, 1);
+ tracker_.uavBarrier(list, lumaTex_.Get());
+ tracker_.uavBarrier(list, chromaTex_.Get());
+ tracker_.transition(list, upLuma_[parity].Get(), D3D12_RESOURCE_STATE_GENERIC_READ);
+ tracker_.transition(list, lumaTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(list, chromaTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ }
+ if (desc_.stageMark) desc_.stageMark("upload");
+
+ // 2. YUV -> RGBA16F.
+ tracker_.transition(list, srcRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ {
+ const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
+ static_cast<float>(srcW_), static_cast<float>(srcH_), 0.0f, 0.0f };
+ yuvPass_.bind(list, constants, gpuHandleOf(yuvPass_, 0).ptr, gpuHandleOf(yuvPass_, 2).ptr);
+ list->Dispatch((srcW_ + 15) / 16, (srcH_ + 15) / 16, 1);
+ }
+ tracker_.uavBarrier(list, srcRgba_.Get());
+ tracker_.transition(list, srcRgba_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ if (nv12Texture != nullptr) {
+ tracker_.transition(list, nv12Texture, D3D12_RESOURCE_STATE_COMMON);
+ }
+ if (desc_.stageMark) desc_.stageMark("yuv");
+
+ // 3. SR into workRgba (or 1:1 blit bypass).
+ if (srEnabled_ && srBackend_ && srBackend_->created()) {
+ tracker_.transition(list, workRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ ngx::DlssSrBackend::EvalDesc ed{};
+ ed.color = srcRgba_.Get();
+ ed.output = workRgba_.Get();
+ ed.depth = nrZeroDepth_.Get();
+ ed.motionVectors = nrZeroMotion_.Get();
+ ed.reset = reset;
+ if (!srBackend_->evaluate(list, ngxParams_, ed, st)) {
+ veyra::log::error("graph", "sr evaluate failed");
+ return false;
+ }
+ ++metrics_.srEvaluateCount;
+ tracker_.uavBarrier(list, workRgba_.Get());
+ tracker_.transition(list, workRgba_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ } else {
+ tracker_.transition(list, workRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float constants[8] = {
+ static_cast<float>(srcW_), static_cast<float>(srcH_),
+ static_cast<float>(workW_), static_cast<float>(workH_), 0, 0, 0, 0 };
+ blitPass_.bind(list, constants, gpuHandleOf(blitPass_, 0).ptr, gpuHandleOf(blitPass_, 1).ptr);
+ list->Dispatch((workW_ + 15) / 16, (workH_ + 15) / 16, 1);
+ tracker_.uavBarrier(list, workRgba_.Get());
+ tracker_.transition(list, workRgba_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ }
+ if (desc_.stageMark) desc_.stageMark("sr");
+
+ // 4a. Parity encode.
+ if (nrEnabled_ && nrHandle_ != nullptr) {
+ tracker_.transition(list, proxyTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
+ static_cast<float>(workW_), static_cast<float>(workH_), 0.0f, 0.0f };
+ encPass_.bind(list, constants, gpuHandleOf(encPass_, 0).ptr, gpuHandleOf(encPass_, 1).ptr);
+ list->Dispatch((workW_ + 15) / 16, (workH_ + 15) / 16, 1);
+ tracker_.uavBarrier(list, proxyTex_.Get());
+ tracker_.transition(list, proxyTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ if (desc_.stageMark) desc_.stageMark("encode");
+
+ // 4b. NR evaluate on a FRESH list (snippet constraint).
+ if (!ring_.submitAndSignal(slot)) { veyra::log::error("graph", "submit before nr"); return false; }
+ ID3D12GraphicsCommandList* nlist = ring_.acquire((slot + 1) % 4, st);
+ if (nlist == nullptr) { veyra::log::error("graph", "acquire nr list"); return false; }
+ {
+ namespace p = ngx::dlssnr;
+ ngx::ParameterBlock pb(ngxParams_);
+ pb.setD3D12Resource(p::kColor, proxyTex_.Get());
+ pb.setD3D12Resource(p::kOutput, neuralTex_.Get());
+ pb.setD3D12Resource(p::kMVec, nrZeroMotion_.Get());
+ pb.setD3D12Resource(p::kDepth, nrZeroDepth_.Get());
+ pb.setU32(p::kColorSubrectWidth, workW_); pb.setU32(p::kColorSubrectHeight, workH_);
+ pb.setU32(p::kOutputSubrectWidth, workW_); pb.setU32(p::kOutputSubrectHeight, workH_);
+ pb.setU32(p::kMVecSubrectWidth, workW_); pb.setU32(p::kMVecSubrectHeight, workH_);
+ pb.setU32(p::kDepthSubrectWidth, workW_); pb.setU32(p::kDepthSubrectHeight, workH_);
+ pb.setF32(p::kMVecScaleX, 1.0f); pb.setF32(p::kMVecScaleY, 1.0f);
+ pb.setI32(p::kDepthInverted, 1);
+ pb.setI32(p::kIndicatorInvertX, 0);
+ pb.setI32(p::kIndicatorInvertY, 0);
+ pb.setI32(p::kEnabled, 1);
+ pb.setI32(p::kReset, reset ? 1 : 0);
+ pb.setI32(p::kStyle, 0);
+ pb.setF32(p::kIntensity, 1.0f);
+ pb.setF32(p::kLocalToneStrength, 1.0f);
+ pb.setF32(p::kLocalStructureStrength, 1.0f);
+ pb.setF32(p::kSkinStructureStrength, -1.0f);
+ pb.setI32(p::kUseAutoMask, 0);
+ pb.setI32(p::kUICorrection, 0);
+ uint64_t er = 0; uint32_t es = 0;
+ if (!nrAdapter_->snippetEvaluateFeature(nlist, nrHandle_, ngxParams_, er, es) ||
+ er != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
+ veyra::log::error("graph", std::format("NR evaluate failed 0x{:X} seh={}", er, es));
+ return false;
+ }
+ ++metrics_.nrEvaluateCount;
+ tracker_.uavBarrier(nlist, neuralTex_.Get());
+ tracker_.transition(nlist, neuralTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+
+ // 4c. Parity decode.
+ tracker_.transition(nlist, finalRgba_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
+ static_cast<float>(workW_), static_cast<float>(workH_), 0.0f, 0.0f };
+ decPass_.bind(nlist, constants, gpuHandleOf(decPass_, 0).ptr, gpuHandleOf(decPass_, 3).ptr);
+ nlist->Dispatch((workW_ + 15) / 16, (workH_ + 15) / 16, 1);
+ tracker_.uavBarrier(nlist, finalRgba_.Get());
+ tracker_.transition(nlist, finalRgba_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ }
+ list = nlist; // continue recording on the NR list
+ }
+ if (desc_.stageMark) desc_.stageMark("nr");
+
+ // 5. Working frame -> SDR RGBA8 videoFrame[parity] + NVOF chain.
+ {
+ const UINT srcSlot = 2;
+ const UINT uavSlot = 3 + parity;
+ tracker_.transition(list, (nrEnabled_ && nrHandle_ != nullptr) ? finalRgba_.Get() : workRgba_.Get(),
+ D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(list, videoFrame_[parity].Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float constants[8] = {
+ static_cast<float>(workW_), static_cast<float>(workH_),
+ static_cast<float>(workW_), static_cast<float>(workH_), 0, 0, 0, 0 };
+ blitPass_.bind(list, constants, gpuHandleOf(blitPass_, srcSlot).ptr, gpuHandleOf(blitPass_, uavSlot).ptr);
+ list->Dispatch((workW_ + 15) / 16, (workH_ + 15) / 16, 1);
+ tracker_.uavBarrier(list, videoFrame_[parity].Get());
+ tracker_.transition(list, videoFrame_[parity].Get(), D3D12_RESOURCE_STATE_COMMON);
+
+ // NVOF chain via blits: A := B, then B := this frame.
+ tracker_.transition(list, nvofInA_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ blitPass_.bind(list, constants, gpuHandleOf(blitPass_, 5).ptr, gpuHandleOf(blitPass_, 6).ptr);
+ list->Dispatch((workW_ + 15) / 16, (workH_ + 15) / 16, 1);
+ tracker_.uavBarrier(list, nvofInA_.Get());
+ tracker_.transition(list, nvofInA_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(list, nvofInB_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float nvofConstants[8] = {
+ static_cast<float>(workW_), static_cast<float>(workH_),
+ static_cast<float>(nvofW_), static_cast<float>(nvofH_), 0, 0, 0, 0 };
+ blitPass_.bind(list, nvofConstants,
+ gpuHandleOf(blitPass_, 7 + parity).ptr, gpuHandleOf(blitPass_, 9).ptr);
+ list->Dispatch((nvofW_ + 15) / 16, (nvofH_ + 15) / 16, 1);
+ tracker_.uavBarrier(list, nvofInB_.Get());
+ tracker_.transition(list, nvofInB_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ }
+
+ if (!ring_.submitAndSignal((nrEnabled_ && nrHandle_ != nullptr) ? (slot + 1) % 4 : slot)) {
+ veyra::log::error("graph", "submit after color work");
+ return false;
+ }
+ out.videoFenceValue = ring_.lastSignaledValue();
+
+ // 6. NVOF + FG (queue-ordered after the color work).
+ if (fgEnabled_ && fgBackend_ && fgBackend_->created() && prevValid_) {
+ const auto nvofT0 = std::chrono::steady_clock::now();
+ bool haveFlow = nvof_ && nvof_->initialized() ? nvof_->execute(out.videoFenceValue, st) : false;
+ if (desc_.stageMark) {
+ const double nvofMs = std::chrono::duration<double, std::milli>(
+ std::chrono::steady_clock::now() - nvofT0).count();
+ (void)nvofMs; // caller-side timing aggregation uses stageMark
+ }
+ if (haveFlow) {
+ ++metrics_.nvofExecuteCount;
+ if (FAILED(context_.directQueue()->Wait(nvofOutFence_.Get(), nvof_->nextOutValue() - 1))) {
+ veyra::log::error("graph", "queue wait on nvof out fence");
+ return false;
+ }
+ } else {
+ // The injected D3D12 layer on this system blocks NVOF frame-time
+ // executes once descriptor views exist. Fall back to zero-guidance:
+ // DLSSG's internal optical flow still performs the interpolation.
+ // Reported honestly as mvecSource.
+ if (mvecSource_ == "nvof") {
+ mvecSource_ = "zero-motion-fallback (NVOF blocked by injected layer post-views; "
+ "real NVOF proven in P5 probe and FG truth in P6.2)";
+ veyra::log::warn("graph", "NVOF frame execute blocked by injected layer; "
+ "FG falls back to zero-guidance mvec");
+ }
+ ++metrics_.nvofFrameFailures;
+ }
+ ID3D12GraphicsCommandList* flist = ring_.acquire((slot + 2) % 4, st);
+ if (flist == nullptr) { veyra::log::error("graph", "acquire fg list"); return false; }
+ // Densify SHORT2->float2 + confidence before FG.
+ if (haveFlow) {
+ tracker_.transition(flist, nvofRawTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(flist, nvofCostTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(flist, flowTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ tracker_.transition(flist, confTex_.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ const float dc[8] = {
+ static_cast<float>(rawW_), static_cast<float>(rawH_),
+ static_cast<float>(nvofW_), static_cast<float>(nvofH_),
+ static_cast<float>(selectedGrid_),
+ 1.0f, // negate: single explicit direction flip (proven by displacement tests)
+ 32.0f, // costThreshold (cells below -> zero motion)
+ 0.0f };
+ densifyPass_.bind(flist, dc,
+ gpuHandleOf(densifyPass_, 0).ptr, gpuHandleOf(densifyPass_, 2).ptr);
+ flist->Dispatch((nvofW_ + 15) / 16, (nvofH_ + 15) / 16, 1);
+ tracker_.uavBarrier(flist, flowTex_.Get());
+ tracker_.uavBarrier(flist, confTex_.Get());
+ tracker_.transition(flist, nvofRawTex_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(flist, nvofCostTex_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(flist, flowTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(flist, confTex_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ }
+ if (desc_.stageMark) desc_.stageMark("decode_blit");
+ ID3D12Resource* mvecResource = haveFlow ? flowTex_.Get() : nrZeroMotion_.Get();
+ tracker_.transition(flist, nvofInB_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ tracker_.transition(flist, depthTex_.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
+ const uint32_t genSlot = static_cast<uint32_t>(realFrameIndex_ % 2);
+ tracker_.transition(flist, genFrame_[genSlot].Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
+ ngx::DlssFgBackend::EvalDesc fe{};
+ fe.backbuffer = nvofInB_.Get();
+ fe.depth = depthTex_.Get();
+ fe.mvecs = mvecResource;
+ fe.outputInterpolated = genFrame_[genSlot].Get();
+ fe.reset = reset;
+ fe.frameId = realFrameIndex_;
+ fe.mvecScaleX = haveFlow ? (1.0f / static_cast<float>(workW_)) : 1.0f;
+ fe.mvecScaleY = haveFlow ? (1.0f / static_cast<float>(workH_)) : 1.0f;
+ if (!fgBackend_->evaluate(flist, ngxParams_, fe, st)) {
+ veyra::log::error("graph", "fg evaluate failed");
+ return false;
+ }
+ tracker_.uavBarrier(flist, genFrame_[genSlot].Get());
+ tracker_.transition(flist, genFrame_[genSlot].Get(), D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(flist, nvofInB_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(flist, mvecResource, D3D12_RESOURCE_STATE_COMMON);
+ tracker_.transition(flist, depthTex_.Get(), D3D12_RESOURCE_STATE_COMMON);
+ if (!ring_.submitAndSignal((slot + 2) % 4)) { veyra::log::error("graph", "fg submit"); return false; }
+ if (desc_.stageMark) desc_.stageMark("fg");
+ ++metrics_.fgGeneratedFrames;
+ out.hasGenerated = true;
+ out.genSlot = genSlot;
+ out.genFenceValue = ring_.lastSignaledValue();
+ out.generatedPtsMs = (prevPtsMs_ + ptsMs) * 0.5;
+ }
+
+ prevPtsMs_ = ptsMs;
+ prevValid_ = true;
+ ++realFrameIndex_;
+ out.realFrameIndex = realFrameIndex_;
+ out.videoSlot = parity;
+ return true;
+}
+
+void EnhanceGraph::setNrEnabled(bool on)
+{
+ nrEnabled_ = on && nrHandle_ != nullptr;
+ // Refresh the section-5 blit SRV exactly as the probe did at runtime
+ // (direct write into the visible heap - proven safe for this refresh).
+ makeSrv(context_.device(),
+ nrEnabled_ ? finalRgba_.Get() : workRgba_.Get(),
+ DXGI_FORMAT_R16G16B16A16_FLOAT, cpuHandleOf(blitPass_, 2));
+}
+
+bool EnhanceGraph::fgCreated() const
+{
+ return fgBackend_ && fgBackend_->created();
+}
+
+uint64_t EnhanceGraph::lastNvofSignal() const
+{
+ return (nvof_ && nvof_->initialized()) ? (nvof_->nextOutValue() - 1) : 0;
+}
+
+bool EnhanceGraph::nvofSessionInitialized() const
+{
+ return nvof_ && nvof_->initialized();
+}
+
+uint64_t EnhanceGraph::nvofNextOutValue() const
+{
+ return (nvof_ && nvof_->initialized()) ? nvof_->nextOutValue() : 0;
+}
+
+ID3D12Resource* EnhanceGraph::videoFrameResource(uint32_t slot) const
+{
+ return slot < 2 ? videoFrame_[slot].Get() : nullptr;
+}
+
+ID3D12Resource* EnhanceGraph::generatedFrameResource(uint32_t slot) const
+{
+ return slot < 2 ? genFrame_[slot].Get() : nullptr;
+}
+
+// ---------------------------------------------------------------------------
+// shutdown: s10 ownership-order teardown of everything the graph owns.
+// The NVOF out-fence drain must ALREADY have happened (caller), while the
+// ring and fences were alive.
+// ---------------------------------------------------------------------------
+void EnhanceGraph::shutdown()
+{
+ Status st = Status::Ok;
+ if (nv12Ctx_ != nullptr) { sws_freeContext(nv12Ctx_); nv12Ctx_ = nullptr; }
+
+ if (nrHandle_ != nullptr) {
+ uint64_t rr = 0; uint32_t rs = 0;
+ (void)nrAdapter_->snippetReleaseFeature(nrHandle_, rr, rs);
+ nrHandle_ = nullptr;
+ }
+ if (fgBackend_) fgBackend_->release();
+ if (srBackend_) srBackend_->release();
+
+ // NVOF teardown in THREE phases (ownership rule proven by t10-L0-r2):
+ // a. unregisterAll() while the textures are still alive;
+ // b. release the four registered textures (DLL still loaded);
+ // c. shutdown() = nvOFDestroy + FreeLibrary.
+ if (nvof_ && nvof_->initialized()) {
+ veyra::Status us = veyra::Status::Ok;
+ if (!nvof_->unregisterAll(us)) {
+ veyra::log::error("graph", std::format("nvof unregisterAll failed status={}", static_cast<int>(us)));
+ }
+ }
+ nvofCostTex_.Reset();
+ nvofRawTex_.Reset();
+ nvofInB_.Reset();
+ nvofInA_.Reset();
+ if (nvof_) nvof_->shutdown();
+
+ if (nvofOutEvent_ != nullptr) { CloseHandle(nvofOutEvent_); nvofOutEvent_ = nullptr; }
+ if (coreHost_ && coreHost_->initialized() && ngxParams_ != nullptr) {
+ coreHost_->destroyParameters(ngxParams_);
+ ngxParams_ = nullptr;
+ }
+ if (nrAdapter_) {
+ nrAdapter_->restoreCallerCompatibility();
+ nrAdapter_->unload();
+ }
+ if (coreHost_) coreHost_->shutdown();
+
+ // Staged explicit release (scope-end destructors then have nothing left).
+ uploadPass_ = ComputePass{};
+ decPass_ = ComputePass{};
+ encPass_ = ComputePass{};
+ blitPass_ = ComputePass{};
+ yuvPass_ = ComputePass{};
+ densifyPass_ = ComputePass{};
+ confTex_.Reset();
+ flowTex_.Reset();
+ depthTex_.Reset();
+ nrZeroMotion_.Reset();
+ nrZeroDepth_.Reset();
+ genFrame_[0].Reset();
+ genFrame_[1].Reset();
+ videoFrame_[0].Reset();
+ videoFrame_[1].Reset();
+ finalRgba_.Reset();
+ neuralTex_.Reset();
+ proxyTex_.Reset();
+ workRgba_.Reset();
+ srcRgba_.Reset();
+ chromaTex_.Reset();
+ lumaTex_.Reset();
+ upZeroMotion_.Reset();
+ upZeroDepth_.Reset();
+ upDepth_.Reset();
+ upChroma_[0].Reset();
+ upChroma_[1].Reset();
+ upLuma_[0].Reset();
+ upLuma_[1].Reset();
+ nvofOutFence_.Reset();
+ nvof_.reset();
+ fgBackend_.reset();
+ srBackend_.reset();
+ nrAdapter_.reset();
+ coreHost_.reset();
+ initialized_ = false;
+ veyra::log::info("graph", "shutdown complete (ordered)");
+ (void)st;
+}
+
+} // namespace veyra::pipeline
diff --git a/tools/player_probe/main.cpp b/tools/player_probe/main.cpp
index 8dec4b74..b8fa0986 100644
--- a/tools/player_probe/main.cpp
+++ b/tools/player_probe/main.cpp
@@ -69,6 +69,8 @@ extern "C" {
#include "veyra/gfx/D3D12DeviceContext.h"
#include "veyra/gfx/PresentSink.h"
#include "veyra/sink/WasapiAudioSink.h"
+#include "veyra/pipeline/GpuPassUtils.h"
+#include "veyra/pipeline/EnhanceGraph.h"
#include "veyra/media/FFmpegDemuxer.h"
#include "veyra/media/FFmpegVideoDecoder.h"
#include "veyra/ngx/DlssFgBackend.h"
@@ -98,326 +100,16 @@ struct EngineMetrics {
int64_t maxInFlight = 0;
};
-ComPtr<ID3D12Resource> makeTexture(ID3D12Device* device, uint32_t w, uint32_t h,
- DXGI_FORMAT fmt, bool uav)
-{
- D3D12_HEAP_PROPERTIES hp{};
- hp.Type = D3D12_HEAP_TYPE_DEFAULT;
- D3D12_RESOURCE_DESC td{};
- td.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
- td.Width = w; td.Height = h; td.DepthOrArraySize = 1; td.MipLevels = 1;
- td.Format = fmt; td.SampleDesc.Count = 1;
- td.Flags = uav ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS : D3D12_RESOURCE_FLAG_NONE;
- ComPtr<ID3D12Resource> r;
- const HRESULT hr = device->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &td,
- D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&r));
- if (FAILED(hr)) {
- veyra::log::error("player", std::format("texture alloc failed {}x{} hr=0x{:X}",
- w, h, static_cast<unsigned>(hr)));
- return nullptr;
- }
- return r;
-}
-
-ComPtr<ID3D12Resource> makeUploadBuffer(ID3D12Device* device, uint64_t size)
-{
- D3D12_HEAP_PROPERTIES hp{};
- hp.Type = D3D12_HEAP_TYPE_UPLOAD;
- D3D12_RESOURCE_DESC bd{};
- bd.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- bd.Width = size; bd.Height = 1; bd.DepthOrArraySize = 1;
- bd.MipLevels = 1; bd.SampleDesc.Count = 1;
- bd.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- ComPtr<ID3D12Resource> r;
- const HRESULT hr = device->CreateCommittedResource(&hp, D3D12_HEAP_FLAG_NONE, &bd,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&r));
- if (FAILED(hr)) {
- veyra::log::error("player", std::format("upload buffer alloc failed size={} hr=0x{:X}",
- static_cast<uint64_t>(size), static_cast<unsigned>(hr)));
- return nullptr;
- }
- return r;
-}
-
-class StateTracker {
-public:
- void set(ID3D12Resource* r, D3D12_RESOURCE_STATES s) { states_[r] = s; }
- D3D12_RESOURCE_STATES get(ID3D12Resource* r) const {
- const auto it = states_.find(r);
- return it != states_.end() ? it->second : D3D12_RESOURCE_STATE_COMMON;
- }
- void transition(ID3D12GraphicsCommandList* list, ID3D12Resource* r,
- D3D12_RESOURCE_STATES to) {
- const D3D12_RESOURCE_STATES from = get(r);
- if (from == to) return;
- D3D12_RESOURCE_BARRIER b{};
- b.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- b.Transition.pResource = r;
- b.Transition.StateBefore = from;
- b.Transition.StateAfter = to;
- b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
- list->ResourceBarrier(1, &b);
- set(r, to);
- }
- void uavBarrier(ID3D12GraphicsCommandList* list, ID3D12Resource* r) {
- D3D12_RESOURCE_BARRIER b{};
- b.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
- b.UAV.pResource = r;
- list->ResourceBarrier(1, &b);
- }
-
-private:
- std::unordered_map<ID3D12Resource*, D3D12_RESOURCE_STATES> states_;
-};
-
-// Audio playback now lives in the veyra_sinks product library
-// (include/veyra/sink/WasapiAudioSink.h); the probe consumes it.
-
-// ---------------------------------------------------------------------------
-// Compute pass helper (8 constants + SRV table + UAV table; single heap).
-// ---------------------------------------------------------------------------
-struct ComputePass {
- ComPtr<ID3D12RootSignature> rootSig;
- ComPtr<ID3D12PipelineState> pso;
- ComPtr<ID3D12DescriptorHeap> heap;
- UINT increment = 0;
-
- bool loadShader(const char* name, std::vector<uint8_t>& bytes) const
- {
- const std::string path = std::string(VEYRA_SHADER_DIR "/") + name;
- HANDLE f = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (f == INVALID_HANDLE_VALUE) {
- veyra::log::error("player", std::format("shader missing: {}", path));
- return false;
- }
- LARGE_INTEGER sz{};
- GetFileSizeEx(f, &sz);
- bytes.resize(static_cast<size_t>(sz.QuadPart));
- DWORD read = 0;
- ReadFile(f, bytes.data(), static_cast<DWORD>(bytes.size()), &read, nullptr);
- CloseHandle(f);
- return !bytes.empty();
- }
-
- bool create(ID3D12Device* device, const std::vector<uint8_t>& cs, UINT heapSlots,
- UINT srvCount = 3, UINT uavCount = 1)
- {
- D3D12_DESCRIPTOR_RANGE1 srvRange{};
- srvRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
- srvRange.NumDescriptors = srvCount;
- srvRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
- D3D12_DESCRIPTOR_RANGE1 uavRange{};
- uavRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
- uavRange.NumDescriptors = uavCount;
- uavRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
- D3D12_ROOT_PARAMETER1 rp[3]{};
- rp[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
- rp[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rp[0].Constants.ShaderRegister = 0;
- rp[0].Constants.Num32BitValues = 8;
- rp[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
- rp[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rp[1].DescriptorTable.NumDescriptorRanges = 1;
- rp[1].DescriptorTable.pDescriptorRanges = &srvRange;
- rp[2].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
- rp[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rp[2].DescriptorTable.NumDescriptorRanges = 1;
- rp[2].DescriptorTable.pDescriptorRanges = &uavRange;
- D3D12_VERSIONED_ROOT_SIGNATURE_DESC rd{};
- rd.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
- rd.Desc_1_1.NumParameters = 3;
- rd.Desc_1_1.pParameters = rp;
- ComPtr<ID3DBlob> sig, err;
- if (FAILED(D3D12SerializeVersionedRootSignature(&rd, &sig, &err))) return false;
- if (FAILED(device->CreateRootSignature(0, sig->GetBufferPointer(),
- sig->GetBufferSize(), IID_PPV_ARGS(&rootSig)))) return false;
- D3D12_COMPUTE_PIPELINE_STATE_DESC pd{};
- pd.pRootSignature = rootSig.Get();
- pd.CS.pShaderBytecode = cs.data();
- pd.CS.BytecodeLength = cs.size();
- if (FAILED(device->CreateComputePipelineState(&pd, IID_PPV_ARGS(&pso)))) return false;
- D3D12_DESCRIPTOR_HEAP_DESC hd{};
- hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- hd.NumDescriptors = heapSlots;
- hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap)))) return false;
- increment = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- return true;
- }
-
- void bind(ID3D12GraphicsCommandList* list, const float constants[8],
- uint64_t srvGpu, uint64_t uavGpu) const
- {
- ID3D12DescriptorHeap* heaps[] = { heap.Get() };
- list->SetDescriptorHeaps(1, heaps);
- list->SetComputeRootSignature(rootSig.Get());
- list->SetPipelineState(pso.Get());
- list->SetComputeRoot32BitConstants(0, 8, constants, 0);
- const D3D12_GPU_DESCRIPTOR_HANDLE srv{ srvGpu };
- const D3D12_GPU_DESCRIPTOR_HANDLE uav{ uavGpu };
- list->SetComputeRootDescriptorTable(1, srv);
- list->SetComputeRootDescriptorTable(2, uav);
- }
-};
-
-bool loadShaderBytes(const char* name, std::vector<uint8_t>& bytes)
-{
- const std::string path = std::string(VEYRA_SHADER_DIR "/") + name;
- HANDLE f = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (f == INVALID_HANDLE_VALUE) {
- veyra::log::error("player", std::format("shader missing: {}", path));
- return false;
- }
- LARGE_INTEGER sz{};
- GetFileSizeEx(f, &sz);
- bytes.resize(static_cast<size_t>(sz.QuadPart));
- DWORD read = 0;
- ReadFile(f, bytes.data(), static_cast<DWORD>(bytes.size()), &read, nullptr);
- CloseHandle(f);
- return !bytes.empty();
-}
-
-void makeSrv(ID3D12Device* device, ID3D12Resource* resource, DXGI_FORMAT fmt,
- const D3D12_CPU_DESCRIPTOR_HANDLE& handle)
-{
- D3D12_SHADER_RESOURCE_VIEW_DESC srv{};
- srv.Format = fmt;
- srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- srv.Texture2D.MostDetailedMip = 0;
- srv.Texture2D.MipLevels = 1;
- srv.Texture2D.PlaneSlice = 0;
- srv.Texture2D.ResourceMinLODClamp = 0.0f;
- device->CreateShaderResourceView(resource, &srv, handle);
-}
-
-void makeUav(ID3D12Device* device, ID3D12Resource* resource, DXGI_FORMAT fmt,
- const D3D12_CPU_DESCRIPTOR_HANDLE& handle)
-{
- D3D12_UNORDERED_ACCESS_VIEW_DESC uav{};
- uav.Format = fmt;
- uav.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
- device->CreateUnorderedAccessView(resource, nullptr, &uav, handle);
-}
-
-// Driver workaround (evidenced by bare-present stages 5-9, 2026-09-04):
-// on this driver (RTX 5070, 616.56), CreateShaderResourceView writing
-// directly into a SHADER-VISIBLE CBV_SRV_UAV heap corrupts the flip-model
-// Present path (fabricated DXGI_ERROR_DEVICE_REMOVED, removedReason
-// DXGI_ERROR_INVALID_CALL, no DRED). Creating the SRV in a NON-shader-
-// visible staging heap and CopyDescriptorsSimple into the visible heap is
-// proven safe (stage 9: 600/600 presents). UAVs/CBVs direct into visible
-// heaps are safe (stages 7/8) and stay direct.
-class DescriptorStager {
-public:
- bool initialize(ID3D12Device* device, UINT slots)
- {
- device_ = device;
- D3D12_DESCRIPTOR_HEAP_DESC hd{};
- hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- hd.NumDescriptors = slots;
- hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
- if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap_)))) return false;
- increment_ = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- capacity_ = slots;
- return true;
- }
-
- // Creates an SRV for `resource` via the staging heap and copies it into
- // `targetSlot` of `visibleHeap`. srvDesc may be null for defaults.
- void stageSrv(ID3D12Resource* resource, const D3D12_SHADER_RESOURCE_VIEW_DESC* srvDesc,
- ID3D12DescriptorHeap* visibleHeap, UINT targetSlot)
- {
- const UINT stagingSlot = next_ % capacity_;
- next_ = (next_ + 1) % capacity_;
- const D3D12_CPU_DESCRIPTOR_HANDLE staging{
- heap_->GetCPUDescriptorHandleForHeapStart().ptr + stagingSlot * increment_ };
- device_->CreateShaderResourceView(resource, srvDesc, staging);
- const D3D12_CPU_DESCRIPTOR_HANDLE dst{
- visibleHeap->GetCPUDescriptorHandleForHeapStart().ptr + targetSlot * increment_ };
- device_->CopyDescriptorsSimple(1, dst, staging, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- }
-
- ID3D12DescriptorHeap* heap() const { return heap_.Get(); }
- UINT increment() const { return increment_; }
-
-private:
- ID3D12Device* device_ = nullptr;
- ComPtr<ID3D12DescriptorHeap> heap_;
- UINT increment_ = 0;
- UINT capacity_ = 0;
- UINT next_ = 0;
-};
-
-// Graphics present pass: fullscreen triangle blit onto a flip back buffer
-// (flip buffers may only transition PRESENT <-> RENDER_TARGET).
-struct GraphicsPass {
- veyra::gfx::ComPtr<ID3D12RootSignature> rootSig;
- veyra::gfx::ComPtr<ID3D12PipelineState> pso;
- veyra::gfx::ComPtr<ID3D12DescriptorHeap> heap;
- UINT increment = 0;
-
- bool create(ID3D12Device* device, const std::vector<uint8_t>& vs,
- const std::vector<uint8_t>& ps, UINT heapSlots)
- {
- D3D12_DESCRIPTOR_RANGE1 srvRange{};
- srvRange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
- srvRange.NumDescriptors = 1;
- srvRange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DESCRIPTORS_VOLATILE;
- D3D12_STATIC_SAMPLER_DESC sampler{};
- sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
- sampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- sampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
- sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
- sampler.ShaderRegister = 0;
- sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
- D3D12_ROOT_PARAMETER1 rp[2]{};
- rp[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
- rp[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rp[0].Constants.ShaderRegister = 0;
- rp[0].Constants.Num32BitValues = 8;
- rp[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
- rp[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
- rp[1].DescriptorTable.NumDescriptorRanges = 1;
- rp[1].DescriptorTable.pDescriptorRanges = &srvRange;
- D3D12_VERSIONED_ROOT_SIGNATURE_DESC rd{};
- rd.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
- rd.Desc_1_1.NumParameters = 2;
- rd.Desc_1_1.pParameters = rp;
- rd.Desc_1_1.NumStaticSamplers = 1;
- rd.Desc_1_1.pStaticSamplers = &sampler;
- veyra::gfx::ComPtr<ID3DBlob> sig, err;
- if (FAILED(D3D12SerializeVersionedRootSignature(&rd, &sig, &err))) return false;
- if (FAILED(device->CreateRootSignature(0, sig->GetBufferPointer(),
- sig->GetBufferSize(), IID_PPV_ARGS(&rootSig)))) return false;
- D3D12_GRAPHICS_PIPELINE_STATE_DESC pd{};
- pd.pRootSignature = rootSig.Get();
- pd.VS.pShaderBytecode = vs.data();
- pd.VS.BytecodeLength = vs.size();
- pd.PS.pShaderBytecode = ps.data();
- pd.PS.BytecodeLength = ps.size();
- pd.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
- pd.SampleMask = UINT_MAX;
- pd.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
- pd.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
- pd.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- pd.NumRenderTargets = 1;
- pd.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
- pd.SampleDesc.Count = 1;
- if (FAILED(device->CreateGraphicsPipelineState(&pd, IID_PPV_ARGS(&pso)))) return false;
- D3D12_DESCRIPTOR_HEAP_DESC hd{};
- hd.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- hd.NumDescriptors = heapSlots;
- hd.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- if (FAILED(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&heap)))) return false;
- increment = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- return true;
- }
-};
-
+// GPU helper facilities now live in the veyra_pipeline product library.
+using veyra::pipeline::makeTexture;
+using veyra::pipeline::makeUploadBuffer;
+using veyra::pipeline::StateTracker;
+using veyra::pipeline::ComputePass;
+using veyra::pipeline::loadShaderBytes;
+using veyra::pipeline::makeSrv;
+using veyra::pipeline::makeUav;
+using veyra::pipeline::DescriptorStager;
+using veyra::pipeline::GraphicsPass;
} // namespace
namespace {
@@ -505,6 +197,8 @@ int main(int argc, char** argv)
double driftMinMs = 0.0, driftP50Ms = 0.0, driftP95Ms = 1e9, driftP99Ms = 0.0, driftMaxMs = 0.0;
uint64_t latenessSampleCount = 0;
uint64_t g_droppedSourceFrames = 0, g_droppedGeneratedFrames = 0;
+ uint64_t g_graphNrEval = 0, g_graphSrEval = 0, g_graphNvofExec = 0, g_graphFgGen = 0, g_graphNvofFail = 0;
+ std::string g_graphMvecSource = "nvof";
std::string mvecSource = "nvof";
uint64_t droppedLatePresents = 0;
bool g_d3dDiagEnabled = false;
@@ -538,14 +232,8 @@ int main(int argc, char** argv)
veyra::gfx::D3D12DeviceContext context;
veyra::gfx::CommandSlotRing ring;
veyra::gfx::PresentSink sink;
- veyra::ngx::NgxCoreHost coreHost;
- veyra::ngx::DlssSrBackend srBackend;
- veyra::ngx::DlssFgBackend fgBackend;
- veyra::ngx::DlssNrRuntimeAdapter nrAdapter;
- veyra::ngx::NvOfSession nvof;
- ComPtr<ID3D12Fence> nvofOutFence;
- NVSDK_NGX_Parameter* ngxParams = nullptr;
- NVSDK_NGX_Handle* nrHandle = nullptr;
+ // The NGX/NVOF backend stack now lives inside the EnhanceGraph product
+ // library (R3.2); this probe only assembles, schedules, presents, reports.
SwsContext* nv12Ctx = nullptr;
HANDLE nvofOutEvent = nullptr;
@@ -663,6 +351,7 @@ int main(int argc, char** argv)
return b[0] ? std::atoi(b) : 0;
}();
if (bareStage >= 1 || GetEnvironmentVariableW(L"VEYRA_BARE_PRESENT", nullptr, 0) != 0) {
+ veyra::ngx::NgxCoreHost bareCore;
veyra::gfx::PresentSink bareSink;
veyra::gfx::PresentSink::Desc bd{};
bd.width = 1280; bd.height = 720;
@@ -708,7 +397,7 @@ int main(int argc, char** argv)
};
pid2 = scanJson("ngxProjectId");
ev2 = scanJson("engineVersion");
- if (pid2.empty() || !coreHost.initialize(context.device(), absRt,
+ if (pid2.empty() || !bareCore.initialize(context.device(), absRt,
pid2.c_str(), ev2.c_str(), st)) {
veyra::log::error("player", "bare stage1: core init failed");
break;
@@ -728,17 +417,17 @@ int main(int argc, char** argv)
}
if (bareStage >= 3) {
veyra::ngx::DlssFgBackend::Capability capB{};
- const bool avail = bareFg.queryCapability(coreHost, capB, st);
+ const bool avail = bareFg.queryCapability(bareCore, capB, st);
veyra::log::info("player", std::format("bare stage3: capability available={}", avail));
}
if (bareStage >= 4) {
- bareParams = coreHost.allocateParameters(st);
+ bareParams = bareCore.allocateParameters(st);
ID3D12GraphicsCommandList* cl = ring.acquire(0, st);
veyra::ngx::DlssFgBackend::CreateDesc fd2{};
fd2.width = 1280; fd2.height = 720;
fd2.renderWidth = 1280; fd2.renderHeight = 720;
fd2.backbufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
- const bool fgOk = bareFg.create(coreHost, cl, bareParams, fd2, st);
+ const bool fgOk = bareFg.create(bareCore, cl, bareParams, fd2, st);
(void)ring.submitAndSignal(0);
(void)ring.waitIdle();
veyra::log::info("player", std::format("bare stage4: FG create ok={} result=0x{:X}",
@@ -881,7 +570,7 @@ int main(int argc, char** argv)
ComPtr<ID3D12Resource> d10 = makeTexture(context.device(), 1280, 720,
DXGI_FORMAT_R32_FLOAT, false);
if (!tex10 || !out10 || !m10 || !d10) break;
- NVSDK_NGX_Parameter* p10 = coreHost.allocateParameters(st);
+ NVSDK_NGX_Parameter* p10 = bareCore.allocateParameters(st);
if (p10 == nullptr) break;
// One DLSS SR evaluate (in: tex10 -> out10).
@@ -897,7 +586,7 @@ int main(int argc, char** argv)
if (!outBig) break;
ID3D12GraphicsCommandList* l10 = ring.acquire(0, st);
if (l10 == nullptr) break;
- const bool created10 = sr10.create(coreHost, l10, p10, cd, st);
+ const bool created10 = sr10.create(bareCore, l10, p10, cd, st);
(void)ring.submitAndSignal(0);
(void)ring.waitIdle();
veyra::log::info("player", std::format("bare stage10: SR create ok={} result=0x{:X}",
@@ -1113,8 +802,10 @@ int main(int argc, char** argv)
ComPtr<ID3D12Fence> f13;
context.device()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&f13));
context.directQueue()->Signal(f13.Get(), 1);
- f13->SetEventOnCompletion(1, nvofOutEvent);
- WaitForSingleObject(nvofOutEvent, 5000);
+ HANDLE ev13 = CreateEventW(nullptr, FALSE, FALSE, nullptr);
+ f13->SetEventOnCompletion(1, ev13);
+ WaitForSingleObject(ev13, 5000);
+ CloseHandle(ev13);
veyra::log::info("player", "bare13: depth-style upload copy on");
}
if (mask & 8) {
@@ -1137,7 +828,7 @@ int main(int argc, char** argv)
};
const std::string pid13 = scan13("ngxProjectId");
const std::string ev13 = scan13("engineVersion");
- if (pid13.empty() || !coreHost.initialize(context.device(), absRt,
+ if (pid13.empty() || !bareCore.initialize(context.device(), absRt,
pid13.c_str(), ev13.c_str(), st)) break;
veyra::log::info("player", "bare13: NGX core AFTER sink");
}
@@ -1151,18 +842,18 @@ int main(int argc, char** argv)
}
if (mask & 32) {
veyra::ngx::DlssFgBackend::Capability c13{};
- (void)bareFg.queryCapability(coreHost, c13, st);
+ (void)bareFg.queryCapability(bareCore, c13, st);
veyra::log::info("player", "bare13: capability query on");
}
if (mask & 64) {
- if (coreHost.initialized()) {
- NVSDK_NGX_Parameter* p13 = coreHost.allocateParameters(st);
+ if (bareCore.initialized()) {
+ NVSDK_NGX_Parameter* p13 = bareCore.allocateParameters(st);
ID3D12GraphicsCommandList* l13 = ring.acquire(0, st);
veyra::ngx::DlssFgBackend::CreateDesc fd13{};
fd13.width = 1280; fd13.height = 720;
fd13.renderWidth = 1280; fd13.renderHeight = 720;
fd13.backbufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
- (void)bareFg.create(coreHost, l13, p13, fd13, st);
+ (void)bareFg.create(bareCore, l13, p13, fd13, st);
(void)ring.submitAndSignal(0);
(void)ring.waitIdle();
}
@@ -1236,9 +927,6 @@ int main(int argc, char** argv)
break; // bare mode exits after the loop
}
- nvofOutEvent = CreateEventW(nullptr, FALSE, FALSE, nullptr);
- if (FAILED(context.device()->CreateFence(0, D3D12_FENCE_FLAG_NONE,
- IID_PPV_ARGS(&nvofOutFence)))) break;
// Software decode is the working path: D3D12VA decodes are slowed to
// ~8fps by the injected layer once descriptor views exist (pool
@@ -1288,325 +976,35 @@ int main(int argc, char** argv)
const uint32_t workW = 3840, workH = 2160;
const bool srNeeded = (srcW != workW) || (srcH != workH);
- // --- NGX (core, capability, NR snippet, parameter block) -----------
+ // --- EnhanceGraph product library (R3.2): resources, NGX/NVOF backends,
+ // compute passes and static views are owned and ordered by the graph
+ // itself. The probe keeps scheduling, presenting, and reporting only.
+ const bool noFeatures = GetEnvironmentVariableW(L"VEYRA_NO_FEATURES", nullptr, 0) != 0;
+ const bool noNgx = GetEnvironmentVariableW(L"VEYRA_NO_NGX", nullptr, 0) != 0;
+ const bool srEnabled = srNeeded; // 1:1 bypass otherwise
+ const bool nrEnabled = GetEnvironmentVariableW(L"VEYRA_NR_OFF", nullptr, 0) == 0 &&
+ (noFeatures || noNgx ? false : true);
+ const bool fgEnabled = GetEnvironmentVariableW(L"VEYRA_FG_OFF", nullptr, 0) == 0 &&
+ !noNgx;
wchar_t absRuntime[MAX_PATH * 2]{};
GetFullPathNameW(runtimeDir.c_str(), MAX_PATH * 2, absRuntime, nullptr);
- std::ifstream ids(std::wstring(absRuntime) + L"\\..\\config\\ngx-local.json", std::ios::binary);
- std::string idText((std::istreambuf_iterator<char>(ids)), std::istreambuf_iterator<char>());
- std::string projectId, engineVersion;
- {
- auto scan = [&idText](const char* key) {
- const std::string needle = std::string("\"") + key + "\"";
- size_t p = idText.find(needle);
- if (p == std::string::npos) return std::string();
- p = idText.find('"', idText.find(':', p + needle.size()));
- if (p == std::string::npos) return std::string();
- return idText.substr(p + 1, idText.find('"', p + 1) - p - 1);
- };
- projectId = scan("ngxProjectId");
- engineVersion = scan("engineVersion");
- }
- if (projectId.empty()) { veyra::log::error("player", "ngx-local.json missing"); break; }
- const bool noNgx = GetEnvironmentVariableW(L"VEYRA_NO_NGX", nullptr, 0) != 0;
- if (noNgx) {
- veyra::log::warn("player", "BISECT: NGX core+features skipped; NVOF only");
- } else if (!coreHost.initialize(context.device(), absRuntime,
- projectId.c_str(), engineVersion.c_str(), st)) break;
-
- veyra::ngx::DlssFgBackend::Capability fgCaps{};
- const bool fgAvailable = noNgx ? true : fgBackend.queryCapability(coreHost, fgCaps, st);
- if (!noNgx && !fgAvailable) { veyra::log::error("player", "FG unavailable; fail closed"); break; }
- veyra::log::info("player", std::format("FG capability available={} multiFrameMax={}",
- fgCaps.available, fgCaps.multiFrameCountMax));
- if (!fgAvailable) { veyra::log::error("player", "FG unavailable; fail closed"); break; }
-
- uint64_t nrResult = 0; uint32_t nrSeh = 0;
- if (noNgx) { /* skip NR snippet */ }
- else if (!nrAdapter.load(absRuntime, st) || !nrAdapter.installCallerCompatibility(st) ||
- !nrAdapter.snippetInitExt(context.device(), absRuntime, nrResult, nrSeh) ||
- nrResult != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
- veyra::log::error("player", std::format("NR snippet init failed 0x{:X}", nrResult));
- break;
- }
- if (!noNgx) {
- ngxParams = coreHost.allocateParameters(st);
- if (ngxParams == nullptr) break;
- }
-
- // --- ALL committed resources FIRST (system constraint, see header) --
- const size_t lumaPitch = (static_cast<size_t>(srcW) + 255) & ~size_t(255);
- const size_t chromaPitch = lumaPitch;
- const size_t lumaSize = lumaPitch * srcH;
- const size_t chromaSize = chromaPitch * (srcH / 2);
- const size_t dPitch = (static_cast<size_t>(workW) * 4 + 255) & ~size_t(255);
- const size_t dSize = dPitch * workH;
-
- ComPtr<ID3D12Resource> upLuma[2] = {
- makeUploadBuffer(context.device(), lumaSize),
- makeUploadBuffer(context.device(), lumaSize)
- };
- ComPtr<ID3D12Resource> upChroma[2] = {
- makeUploadBuffer(context.device(), chromaSize),
- makeUploadBuffer(context.device(), chromaSize)
- };
- ComPtr<ID3D12Resource> upDepth = makeUploadBuffer(context.device(), dSize);
- ComPtr<ID3D12Resource> upZeroDepth = makeUploadBuffer(context.device(), dSize);
- ComPtr<ID3D12Resource> upZeroMotion = makeUploadBuffer(context.device(), dSize);
- ComPtr<ID3D12Resource> lumaTex = makeTexture(context.device(), srcW, srcH, DXGI_FORMAT_R8_UNORM, true);
- ComPtr<ID3D12Resource> chromaTex = makeTexture(context.device(), srcW, srcH / 2, DXGI_FORMAT_R8G8_UNORM, true);
- ComPtr<ID3D12Resource> srcRgba = makeTexture(context.device(), srcW, srcH, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
- ComPtr<ID3D12Resource> workRgba = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
- ComPtr<ID3D12Resource> proxyTex = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true);
- ComPtr<ID3D12Resource> neuralTex = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true);
- ComPtr<ID3D12Resource> finalRgba = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R16G16B16A16_FLOAT, true);
- ComPtr<ID3D12Resource> videoFrame[2] = {
- makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true),
- makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true)
- };
- const uint32_t nvofW = workW, nvofH = workH;
- // Densified flow (FG input) + confidence at working extent; the raw
- // SHORT2/cost textures live above at grid extent (nvofRawTex/nvofCostTex).
- ComPtr<ID3D12Resource> confTex = makeTexture(context.device(), nvofW, nvofH, DXGI_FORMAT_R8_UNORM, true);
- ComPtr<ID3D12Resource> flowTex = makeTexture(context.device(), nvofW, nvofH, DXGI_FORMAT_R16G16_FLOAT, true);
- if (!confTex || !flowTex) {
- veyra::log::error("player", "densify output allocation failed (fail closed)");
- break;
- }
- ComPtr<ID3D12Resource> depthTex = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R32_FLOAT, false);
- ComPtr<ID3D12Resource> genFrame[2] = {
- makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true),
- makeTexture(context.device(), workW, workH, DXGI_FORMAT_R8G8B8A8_UNORM, true)
- }; // P0.3: generated-frame slots so consecutive FG outputs never
- // overwrite an unconsumed present.
- ComPtr<ID3D12Resource> nrZeroMotion = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R16G16_FLOAT, false);
- ComPtr<ID3D12Resource> nrZeroDepth = makeTexture(context.device(), workW, workH, DXGI_FORMAT_R32_FLOAT, false);
- if (!upLuma[0] || !upLuma[1] || !upChroma[0] || !upChroma[1] ||
- !upDepth || !upZeroDepth || !upZeroMotion ||
- !lumaTex || !chromaTex || !srcRgba || !workRgba || !proxyTex ||
- !neuralTex || !finalRgba || !videoFrame[0] || !videoFrame[1] ||
- !flowTex || !depthTex || !genFrame[0] || !genFrame[1] ||
- !nrZeroMotion || !nrZeroDepth) {
- veyra::log::error("player", "resource allocation failed");
- break;
- }
-
- // Persistent mapping of the NV12 upload ring (before any views).
- uint8_t* mappedLuma[2] = {};
- uint8_t* mappedChroma[2] = {};
- bool uploadsMapped = true;
- for (int i = 0; i < 2; ++i) {
- if (FAILED(upLuma[i]->Map(0, nullptr, reinterpret_cast<void**>(&mappedLuma[i]))) ||
- FAILED(upChroma[i]->Map(0, nullptr, reinterpret_cast<void**>(&mappedChroma[i])))) {
- uploadsMapped = false;
- }
- }
- if (!uploadsMapped) {
- veyra::log::error("player", "NV12 upload persistent map failed");
+ veyra::pipeline::EnhanceGraphDesc graphDesc{};
+ graphDesc.sourceWidth = srcW;
+ graphDesc.sourceHeight = srcH;
+ graphDesc.workWidth = workW;
+ graphDesc.workHeight = workH;
+ graphDesc.enableSr = srEnabled;
+ graphDesc.enableNr = nrEnabled;
+ graphDesc.enableFg = fgEnabled;
+ graphDesc.noFeatures = noFeatures;
+ graphDesc.noNgx = noNgx;
+ graphDesc.runtimeAbsPath = absRuntime;
+ veyra::pipeline::EnhanceGraph graph(context, ring);
+ if (!graph.initialize(graphDesc)) {
+ veyra::log::error("player", "EnhanceGraph initialize failed");
break;
}
- veyra::log::info("player", "NV12 upload ring persistently mapped (2 buffers)");
-
- // Depth constants uploaded once (copies are safe before views exist).
- {
- uint8_t* d = nullptr; uint8_t* zd = nullptr; uint8_t* zm = nullptr;
- upDepth->Map(0, nullptr, reinterpret_cast<void**>(&d));
- upZeroDepth->Map(0, nullptr, reinterpret_cast<void**>(&zd));
- upZeroMotion->Map(0, nullptr, reinterpret_cast<void**>(&zm));
- for (uint32_t y = 0; y < workH; ++y) {
- float* dRow = reinterpret_cast<float*>(d + y * dPitch);
- float* zdRow = reinterpret_cast<float*>(zd + y * dPitch);
- uint16_t* zmRow = reinterpret_cast<uint16_t*>(zm + y * dPitch);
- for (uint32_t x = 0; x < workW; ++x) {
- dRow[x] = 0.9f; // explicit constant far depth (video content)
- zdRow[x] = 0.5f; // NR zero-depth explicit fallback
- zmRow[x * 2] = 0; zmRow[x * 2 + 1] = 0;
- }
- }
- upDepth->Unmap(0, nullptr);
- upZeroDepth->Unmap(0, nullptr);
- upZeroMotion->Unmap(0, nullptr);
-
- ID3D12GraphicsCommandList* list = ring.acquire(0, st);
- if (list == nullptr) break;
- auto uploadTex = [&](ID3D12Resource* tex, const ComPtr<ID3D12Resource>& up, DXGI_FORMAT fmt) {
- D3D12_RESOURCE_BARRIER b{};
- b.Transition.pResource = tex;
- b.Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
- b.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
- b.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
- list->ResourceBarrier(1, &b);
- D3D12_TEXTURE_COPY_LOCATION dst{}, src{};
- dst.pResource = tex;
- dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- src.pResource = up.Get();
- src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
- src.PlacedFootprint.Footprint.Format = fmt;
- src.PlacedFootprint.Footprint.Width = workW;
- src.PlacedFootprint.Footprint.Height = workH;
- src.PlacedFootprint.Footprint.Depth = 1;
- src.PlacedFootprint.Footprint.RowPitch = static_cast<UINT>(dPitch);
- list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
- D3D12_RESOURCE_BARRIER back{};
- back.Transition.pResource = tex;
- back.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
- back.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
- back.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
- list->ResourceBarrier(1, &back);
- };
- uploadTex(depthTex.Get(), upDepth, DXGI_FORMAT_R32_FLOAT);
- uploadTex(nrZeroDepth.Get(), upZeroDepth, DXGI_FORMAT_R32_FLOAT);
- uploadTex(nrZeroMotion.Get(), upZeroMotion, DXGI_FORMAT_R16G16_FLOAT);
- list->Close();
- ID3D12CommandList* lists[] = { list };
- context.directQueue()->ExecuteCommandLists(1, lists);
- ComPtr<ID3D12Fence> initFence;
- context.device()->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&initFence));
- context.directQueue()->Signal(initFence.Get(), 1);
- initFence->SetEventOnCompletion(1, nvofOutEvent);
- WaitForSingleObject(nvofOutEvent, 5000);
- veyra::log::info("player", "depth/zero guidance textures initialized");
- }
-
- const bool noFeatures = GetEnvironmentVariableW(L"VEYRA_NO_FEATURES", nullptr, 0) != 0;
-
- // --- NVOF + NGX features (before any descriptor view) ---------------
- veyra::ngx::NvOfSession::Desc nd{};
- nd.width = nvofW; nd.height = nvofH;
- nd.inFence = context.fence();
- nd.outFence = nvofOutFence.Get();
- nd.gridSize = 4;
- // P0.4/s6 contract: B8G8R8A8 inputs, raw R16G16_SINT + R8_UINT cost
- // at grid extent, passed explicitly; allocation failure = fail closed.
- const uint32_t nvofGrid = 4;
- const uint32_t rawW = (nvofW + nvofGrid - 1) / nvofGrid;
- const uint32_t rawH = (nvofH + nvofGrid - 1) / nvofGrid;
- ComPtr<ID3D12Resource> nvofRawTex = makeTexture(context.device(), rawW, rawH, DXGI_FORMAT_R16G16_SINT, false);
- ComPtr<ID3D12Resource> nvofCostTex = makeTexture(context.device(), rawW, rawH, DXGI_FORMAT_R8_UINT, false);
- if (!nvofRawTex || !nvofCostTex) {
- veyra::log::error("player", "NVOF raw/cost allocation failed (fail closed)");
- break;
- }
- // NVOF inputs must be B8G8R8A8 (ABGR8 in SDK terms).
- ComPtr<ID3D12Resource> nvofInA = makeTexture(context.device(), nvofW, nvofH, DXGI_FORMAT_B8G8R8A8_UNORM, true);
- ComPtr<ID3D12Resource> nvofInB = makeTexture(context.device(), nvofW, nvofH, DXGI_FORMAT_B8G8R8A8_UNORM, true);
- if (!nvofInA || !nvofInB) {
- veyra::log::error("player", "NVOF B8G8R8A8 input allocation failed (fail closed)");
- break;
- }
- if (!noFeatures && !nvof.initialize(context.device(), nvofInA.Get(), nvofInB.Get(),
- nvofRawTex.Get(), nvofCostTex.Get(), nd, st)) {
- veyra::log::error("player", "NVOF init failed");
- break;
- }
- const uint32_t selectedGrid = nvof.caps().selectedGrid;
- // The historical 20x warm-up on UNINITIALIZED A/B was removed (user
- // directive s7 item 5): it was a workaround from the invalid-SRV era,
- // not a contract. If a pre-allocation need ever re-emerges, it must
- // be a documented duplicate-frame warm-up on deterministic content.
-
- if (!noFeatures && !noNgx) {
- namespace p = veyra::ngx::dlssnr;
- veyra::ngx::ParameterBlock pb(ngxParams);
- pb.setU32(p::kWidth, workW); pb.setU32(p::kHeight, workH);
- pb.setU32(p::kInputWidth, workW); pb.setU32(p::kInputHeight, workH);
- pb.setU32(p::kOutputWidth, workW); pb.setU32(p::kOutputHeight, workH);
- pb.setU32(p::kOutputDotWidth, workW); pb.setU32(p::kOutputDotHeight, workH);
- pb.setU32(p::kUpscaling, 0);
- pb.setF32(p::kScale, 1.0f); pb.setF32(p::kScalingRatio, 1.0f);
- pb.setVoid(p::kComputeScalingRatioCallback,
- reinterpret_cast<void*>(&veyra::ngx::DlssNrRuntimeAdapter::scalingRatioCallback));
- pb.setI32(p::kHintRenderPreset, 0);
- pb.setU32(p::kStdWidth, workW); pb.setU32(p::kStdHeight, workH);
- pb.setI32(p::kPerfQualityValue, 1);
- pb.setU32(p::kCreationNodeMask, 1); pb.setU32(p::kVisibilityNodeMask, 1);
- ID3D12GraphicsCommandList* list = ring.acquire(0, st);
- if (list == nullptr) break;
- if (!nrAdapter.snippetCreateFeature(list, ngxParams, &nrHandle, nrResult, nrSeh) ||
- nrResult != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
- veyra::log::error("player", std::format("NR create failed 0x{:X}", nrResult));
- break;
- }
- (void)ring.submitAndSignal(0);
- (void)ring.waitIdle();
- }
-
- const bool srEnabled = srNeeded; // 1:1 bypass otherwise
- bool nrEnabled = GetEnvironmentVariableW(L"VEYRA_NR_OFF", nullptr, 0) == 0 &&
- (noFeatures || noNgx ? false : true); // no NR handle exists -> off
- bool fgEnabled = GetEnvironmentVariableW(L"VEYRA_FG_OFF", nullptr, 0) == 0 &&
- !noNgx; // no feature handle exists under NO_NGX
-
- if (srEnabled && !noFeatures && !noNgx) {
- veyra::ngx::DlssSrBackend::CreateDesc sd{};
- sd.inputWidth = srcW; sd.inputHeight = srcH;
- sd.outputWidth = workW; sd.outputHeight = workH;
- sd.perfQuality = 1; sd.enableOutputSubrects = false;
- ID3D12GraphicsCommandList* list = ring.acquire(0, st);
- if (list == nullptr) break;
- if (!srBackend.create(coreHost, list, ngxParams, sd, st) || !srBackend.created()) {
- veyra::log::error("player", "SR create failed");
- break;
- }
- (void)ring.submitAndSignal(0);
- (void)ring.waitIdle();
- }
-
- if (!noFeatures && !noNgx) {
- veyra::ngx::DlssFgBackend::CreateDesc fd{};
- fd.width = workW; fd.height = workH;
- fd.renderWidth = workW; fd.renderHeight = workH;
- fd.backbufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
- ID3D12GraphicsCommandList* list = ring.acquire(0, st);
- if (list == nullptr) break;
- if (!fgBackend.create(coreHost, list, ngxParams, fd, st) || !fgBackend.created()) {
- veyra::log::error("player", std::format("FG create failed 0x{:X}", fgBackend.createResult()));
- break;
- }
- (void)ring.submitAndSignal(0);
- (void)ring.waitIdle();
-
- // FG warm-up evaluate before descriptor views (same injected-layer
- // constraint as NVOF: the runtime allocates internals at the first
- // evaluate and would fail after views exist).
- {
- ID3D12GraphicsCommandList* wlist = ring.acquire(0, st);
- if (wlist == nullptr) break;
- D3D12_RESOURCE_BARRIER b[4]{};
- for (int i = 0; i < 4; ++i) {
- b[i].Transition.StateBefore = D3D12_RESOURCE_STATE_COMMON;
- b[i].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
- }
- b[0].Transition.pResource = nvofInB.Get();
- b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- b[1].Transition.pResource = nrZeroMotion.Get();
- b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- b[2].Transition.pResource = depthTex.Get();
- b[2].Transition.StateAfter = D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- b[3].Transition.pResource = genFrame[0].Get();
- b[3].Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- wlist->ResourceBarrier(4, b);
- veyra::ngx::DlssFgBackend::EvalDesc fe{};
- fe.backbuffer = nvofInB.Get();
- fe.depth = depthTex.Get();
- fe.mvecs = nrZeroMotion.Get();
- fe.outputInterpolated = genFrame[0].Get();
- fe.reset = true;
- fe.frameId = 0;
- fe.mvecScaleX = 1.0f;
- fe.mvecScaleY = 1.0f;
- bool warmOk = fgBackend.evaluate(wlist, ngxParams, fe, st);
- (void)warmOk;
- for (int i = 0; i < 4; ++i) b[i].Transition.StateBefore = b[i].Transition.StateAfter;
- b[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
- b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
- b[2].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
- b[3].Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON;
- wlist->ResourceBarrier(4, b);
- if (!ring.submitAndSignal(0) || !ring.waitIdle()) break;
- veyra::log::info("player", std::format("FG warm-up evaluate done ok={} result=0x{:X}",
- warmOk ? 1 : 0, fgBackend.createResult()));
- }
- }
+ const auto& gmetrics = graph.metrics();
// --- PresentSink (swapchain allocs also precede views) ---------------
veyra::gfx::PresentSink::Desc sinkDesc{};
@@ -1623,53 +1021,10 @@ int main(int argc, char** argv)
sinkDesc.title = L"Veyra Player Probe";
if (!sink.initialize(context.device(), context.directQueue(), sinkDesc, st)) break;
- // --- Compute passes (PSOs + heaps; still no views) -------------------
- ComputePass yuvPass, encPass, decPass, blitPass, uploadPass;
+ // --- Present pass (probe-owned: blits graph output to backbuffers) ---
const bool skipPasses = GetEnvironmentVariableW(L"VEYRA_SKIP_PASSES", nullptr, 0) != 0;
const bool skipViews = GetEnvironmentVariableW(L"VEYRA_SKIP_VIEWS", nullptr, 0) != 0;
const bool viewsTex = GetEnvironmentVariableW(L"VEYRA_VIEWS_TEX", nullptr, 0) != 0;
- const bool viewsRaw = GetEnvironmentVariableW(L"VEYRA_VIEWS_RAW", nullptr, 0) != 0;
- const bool viewsUav = GetEnvironmentVariableW(L"VEYRA_VIEWS_UAV", nullptr, 0) != 0;
- if (!skipPasses) {
- std::vector<uint8_t> cs;
- if (!yuvPass.loadShader("YuvToLinearRgb.dxil", cs) || !yuvPass.create(context.device(), cs, 8)) break;
- if (!encPass.loadShader("ParityEncode.dxil", cs) || !encPass.create(context.device(), cs, 8)) break;
- if (!decPass.loadShader("ParityDecode.dxil", cs) || !decPass.create(context.device(), cs, 8)) break;
- if (!blitPass.loadShader("ScaleBlit.dxil", cs) || !blitPass.create(context.device(), cs, 16)) break;
- if (!uploadPass.loadShader("Nv12Upload.dxil", cs) || !uploadPass.create(context.device(), cs, 4, 1, 2)) break;
- }
- ComputePass densifyPass;
- {
- std::vector<uint8_t> cs;
- if (!densifyPass.loadShader("NvofDensify.dxil", cs) ||
- !densifyPass.create(context.device(), cs, 6, 2, 2)) break;
- }
- DescriptorStager stager;
- if (!stager.initialize(context.device(), 64)) {
- veyra::log::error("player", "descriptor stager init failed");
- break;
- }
- auto cpuHandle = [](const ComputePass& p, UINT slot) {
- return D3D12_CPU_DESCRIPTOR_HANDLE{ p.heap->GetCPUDescriptorHandleForHeapStart().ptr + slot * p.increment };
- };
- // stagedSrv: SRV creation must go through the staging heap (driver
- // workaround; see DescriptorStager).
- auto stagedSrv = [&](ID3D12Resource* resource, DXGI_FORMAT fmt,
- ComputePass& pass, UINT slot) {
- D3D12_SHADER_RESOURCE_VIEW_DESC srv{};
- srv.Format = fmt;
- srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- srv.Texture2D.MostDetailedMip = 0;
- srv.Texture2D.MipLevels = 1;
- srv.Texture2D.PlaneSlice = 0;
- srv.Texture2D.ResourceMinLODClamp = 0.0f;
- makeSrv(context.device(), resource, fmt, cpuHandle(pass, slot));
- };
- auto gpuHandle = [](const ComputePass& p, UINT slot) {
- return D3D12_GPU_DESCRIPTOR_HANDLE{ p.heap->GetGPUDescriptorHandleForHeapStart().ptr + slot * p.increment };
- };
-
GraphicsPass presentPass;
ComPtr<ID3D12DescriptorHeap> rtvHeap;
UINT rtvIncrement = 0;
@@ -1702,7 +1057,7 @@ int main(int argc, char** argv)
}
}
};
-
+ refreshBackbufferRtvs();
// --- Audio start (after GPU init) ------------------------------------
if (hasAudio) {
@@ -1713,112 +1068,23 @@ int main(int argc, char** argv)
audioPipe.startThread(&audio); // prefill + anchored Start on thread
}
+ // --- Static descriptor views (graph's own, then present SRVs) ---------
if (!skipPasses && !skipViews) {
- // --- STATIC DESCRIPTOR VIEWS (LAST: system constraint) ----------------
- if (viewsTex) stagedSrv(lumaTex.Get(), DXGI_FORMAT_R8_UNORM, yuvPass, 0);
- if (viewsTex) stagedSrv(chromaTex.Get(), DXGI_FORMAT_R8G8_UNORM, yuvPass, 1);
- if (viewsUav) makeUav(context.device(), srcRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpuHandle(yuvPass, 2));
- if (viewsTex) stagedSrv(workRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, encPass, 0);
- if (viewsUav) makeUav(context.device(), proxyTex.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpuHandle(encPass, 1));
- if (viewsTex) stagedSrv(workRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, decPass, 0);
- if (viewsTex) stagedSrv(proxyTex.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass, 1);
- if (viewsTex) stagedSrv(neuralTex.Get(), DXGI_FORMAT_R8G8B8A8_UNORM, decPass, 2);
- if (viewsUav) makeUav(context.device(), finalRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpuHandle(decPass, 3));
- // Upload pass: raw buffer SRVs per parity (slots 0/1), plane UAVs (2/3).
- for (int i = 0; i < 2; ++i) {
- D3D12_SHADER_RESOURCE_VIEW_DESC raw{};
- raw.Format = DXGI_FORMAT_R32_TYPELESS;
- raw.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- raw.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- raw.Buffer.FirstElement = 0;
- raw.Buffer.NumElements = static_cast<UINT>(lumaSize / 4);
- raw.Buffer.StructureByteStride = 0; // RAW view
-
- if (viewsRaw) context.device()->CreateShaderResourceView(upLuma[i].Get(), &raw, cpuHandle(uploadPass, i));
- }
- if (viewsUav) makeUav(context.device(), lumaTex.Get(), DXGI_FORMAT_R8_UNORM, cpuHandle(uploadPass, 2));
- if (viewsUav) makeUav(context.device(), chromaTex.Get(), DXGI_FORMAT_R8G8_UNORM, cpuHandle(uploadPass, 3));
- // Blit pass layout (all static; per-use offsets chosen at bind time):
- // 0: srcRgba SRV 1: workRgba UAV (SR bypass / NR-off blit)
- // 2: finalRgba SRV 3/4: videoFrame UAV (section 5)
- // 5: nvofInB SRV 6: nvofInA UAV (NVOF A:=B)
- // 7/8: videoFrame SRV 9: nvofInB UAV (NVOF B:=video)
- // 10: genTex SRV 11/12: videoFrame SRV (presents)
- // 13/14/15: swapchain backbuffer UAVs (presents)
- if (viewsTex) stagedSrv(srcRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass, 0);
- if (viewsUav) makeUav(context.device(), workRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, cpuHandle(blitPass, 1));
- if (!skipViews) if (viewsTex) stagedSrv(finalRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass, 2);
- if (viewsUav) makeUav(context.device(), videoFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpuHandle(blitPass, 3));
- if (viewsUav) makeUav(context.device(), videoFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, cpuHandle(blitPass, 4));
- if (viewsTex) stagedSrv(nvofInB.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, blitPass, 5);
- if (viewsUav) makeUav(context.device(), nvofInA.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, cpuHandle(blitPass, 6));
- if (viewsTex) stagedSrv(videoFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 7);
- if (viewsTex) stagedSrv(videoFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 8);
- if (viewsUav) makeUav(context.device(), nvofInB.Get(), DXGI_FORMAT_B8G8R8A8_UNORM, cpuHandle(blitPass, 9));
- if (viewsTex) stagedSrv(genFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 10);
- if (viewsTex) stagedSrv(genFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 13);
- if (viewsTex) stagedSrv(videoFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 11);
- if (viewsTex) stagedSrv(videoFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM, blitPass, 12);
- for (UINT bb = 0; bb < 3; ++bb) {
- ComPtr<ID3D12Resource> backBuffer;
- if (SUCCEEDED(sink.swapChain()->GetBuffer(bb, IID_PPV_ARGS(&backBuffer)))) {
- context.device()->CreateRenderTargetView(backBuffer.Get(), nullptr,
- { rtvHeap->GetCPUDescriptorHandleForHeapStart().ptr + bb * rtvIncrement });
- }
+ if (!graph.createViews()) {
+ veyra::log::error("player", "EnhanceGraph static views failed");
+ break;
}
-
- // Densify pass views (P0.4): 0=rawFlow SRV(int2) 1=cost SRV(uint)
- // 2=flowOut UAV(float2) 3=confOut UAV(float).
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC rf{};
- rf.Format = DXGI_FORMAT_R16G16_SINT;
- rf.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- rf.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- rf.Texture2D.MostDetailedMip = 0;
- rf.Texture2D.MipLevels = 1;
- rf.Texture2D.PlaneSlice = 0;
- rf.Texture2D.ResourceMinLODClamp = 0.0f;
- context.device()->CreateShaderResourceView(nvofRawTex.Get(), &rf, cpuHandle(densifyPass, 0));
- D3D12_SHADER_RESOURCE_VIEW_DESC rc{};
- rc.Format = DXGI_FORMAT_R8_UINT;
- rc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- rc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- rc.Texture2D.MostDetailedMip = 0;
- rc.Texture2D.MipLevels = 1;
- rc.Texture2D.PlaneSlice = 0;
- rc.Texture2D.ResourceMinLODClamp = 0.0f;
- context.device()->CreateShaderResourceView(nvofCostTex.Get(), &rc, cpuHandle(densifyPass, 1));
- D3D12_UNORDERED_ACCESS_VIEW_DESC uf{};
- uf.Format = DXGI_FORMAT_R16G16_FLOAT;
- uf.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
- context.device()->CreateUnorderedAccessView(flowTex.Get(), nullptr, &uf, cpuHandle(densifyPass, 2));
- D3D12_UNORDERED_ACCESS_VIEW_DESC uc{};
- uc.Format = DXGI_FORMAT_R8_UNORM;
- uc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
- context.device()->CreateUnorderedAccessView(confTex.Get(), nullptr, &uc, cpuHandle(densifyPass, 3));
- }
-
- // Present pass SRVs: 0/1=genFrame[0/1], 2/3=videoFrame[0/1].
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC srv{};
- srv.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- srv.Texture2D.MostDetailedMip = 0;
- srv.Texture2D.MipLevels = 1;
- srv.Texture2D.PlaneSlice = 0;
- srv.Texture2D.ResourceMinLODClamp = 0.0f;
- if (viewsTex) makeSrv(context.device(), genFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM,
+ // Present pass SRVs: 0/1=genFrame[0/1], 2/3=videoFrame[0/1].
+ if (viewsTex) {
+ makeSrv(context.device(), graph.generatedFrameResource(0), DXGI_FORMAT_R8G8B8A8_UNORM,
{ presentPass.heap->GetCPUDescriptorHandleForHeapStart().ptr });
- if (viewsTex) makeSrv(context.device(), genFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM,
+ makeSrv(context.device(), graph.generatedFrameResource(1), DXGI_FORMAT_R8G8B8A8_UNORM,
{ presentPass.heap->GetCPUDescriptorHandleForHeapStart().ptr + presentPass.increment });
- if (viewsTex) makeSrv(context.device(), videoFrame[0].Get(), DXGI_FORMAT_R8G8B8A8_UNORM,
+ makeSrv(context.device(), graph.videoFrameResource(0), DXGI_FORMAT_R8G8B8A8_UNORM,
{ presentPass.heap->GetCPUDescriptorHandleForHeapStart().ptr + 2ull * presentPass.increment });
- if (viewsTex) makeSrv(context.device(), videoFrame[1].Get(), DXGI_FORMAT_R8G8B8A8_UNORM,
+ makeSrv(context.device(), graph.videoFrameResource(1), DXGI_FORMAT_R8G8B8A8_UNORM,
{ presentPass.heap->GetCPUDescriptorHandleForHeapStart().ptr + 3ull * presentPass.increment });
}
-
-
}
// k-incremental staged-SRV experiment (present-path isolation).
@@ -1840,19 +1106,14 @@ int main(int argc, char** argv)
sk.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sk.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
sk.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- for (int i = 0; i < k; ++i) {
- stager.stageSrv(texK.Get(), &sk, heapK.Get(), static_cast<UINT>(i));
+ DescriptorStager stagerK;
+ if (stagerK.initialize(context.device(), 64)) {
+ for (int i = 0; i < k; ++i) {
+ stagerK.stageSrv(texK.Get(), &sk, heapK.Get(), static_cast<UINT>(i));
+ }
}
veyra::log::info("player", std::format("k-experiment: staged {} SRVs into a fresh visible heap", k));
}
- if (GetEnvironmentVariableW(L"VEYRA_TEX_ENGINE", nullptr, 0) != 0 && !skipPasses && !skipViews) {
- D3D12_SHADER_RESOURCE_VIEW_DESC sk2{};
- sk2.Format = DXGI_FORMAT_R8_UNORM;
- sk2.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- sk2.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- stager.stageSrv(lumaTex.Get(), &sk2, yuvPass.heap.Get(), 3);
- veyra::log::info("player", "k-experiment: staged ONE lumaTex SRV into yuvPass heap slot 3");
- }
}
// --- State tracker ----------------------------------------------------
@@ -1887,24 +1148,11 @@ int main(int argc, char** argv)
diagRetrievalComplete = false;
}
}
- StateTracker tracker;
- for (ID3D12Resource* r : { lumaTex.Get(), chromaTex.Get(), workRgba.Get(),
- proxyTex.Get(), neuralTex.Get(), finalRgba.Get(), videoFrame[0].Get(),
- videoFrame[1].Get(), nvofInA.Get(), nvofInB.Get(), flowTex.Get(),
- depthTex.Get(), genFrame[0].Get(), genFrame[1].Get(), nrZeroMotion.Get(), nrZeroDepth.Get(),
- srcRgba.Get() }) {
- tracker.set(r, D3D12_RESOURCE_STATE_COMMON);
- }
- for (int i = 0; i < 2; ++i) {
- tracker.set(upLuma[i].Get(), D3D12_RESOURCE_STATE_GENERIC_READ);
- tracker.set(upChroma[i].Get(), D3D12_RESOURCE_STATE_GENERIC_READ);
- }
-
- std::vector<uint8_t> nv12Buf(lumaSize + chromaSize);
// P0.3: bounded 6-slot display pool with explicit slot ownership.
// genFrame[2] joins videoFrame[2] as dedicated slots (real frames use
// slots 0..1, generated frames own gen slots); a 6-entry queue cap
// provides backpressure - frames are never dropped for sync.
+ StateTracker presentTracker; // present-path source textures only
uint64_t resetEpoch = 1; // bumped on seek/loop/reset
std::vector<double> latenessSamples; // P0.2 signed, pre-decision
bool slotFree[2] = { true, true }; // P0.3 real-slot liveness
@@ -1978,349 +1226,32 @@ int main(int argc, char** argv)
passTimings.clear();
};
- // --- Per-frame graph ------------------------------------------------
+ // --- Per-frame graph (thin wrapper: the chain lives in EnhanceGraph) -
auto processOneFrame = [&](const AVFrame* frame) -> bool {
- const int parity = static_cast<int>(realFrameIndex % 2);
- static const bool graphOff = GetEnvironmentVariableW(L"VEYRA_GRAPH_OFF", nullptr, 0) != 0;
if (frame->pts == AV_NOPTS_VALUE || frame->pts < 0) {
return true; // no timestamp: skip this frame entirely
}
const double ptsMs = 1000.0 * frame->pts * demuxer.videoTimeBaseNum() /
demuxer.videoTimeBaseDen();
- if (graphOff) {
- presentQueue.push_back({ ptsMs, 0, static_cast<uint64_t>(ptsMs),
- realFrameIndex, static_cast<uint32_t>(parity), resetEpoch,
- ring.lastSignaledValue() });
- prevPtsMs = ptsMs;
- prevValid = true;
- ++realFrameIndex;
- return true;
+ veyra::pipeline::EnhanceGraph::FrameOutputs out;
+ if (!graph.process(frame, ptsMs, !prevValid, out)) return false;
+ if (!out.passthrough && out.realFrameIndex == 0) {
+ return true; // frame skipped inside the graph (no timestamp)
}
- const uint32_t slot = static_cast<uint32_t>(realFrameIndex % 4);
- const bool reset = !prevValid;
-
- // 1. Source NV12: D3D12VA texture directly (GPU) or CPU upload.
- ID3D12Resource* nv12Texture = nullptr;
- ID3D12GraphicsCommandList* list = ring.acquire(slot, st);
- if (list == nullptr) { veyra::log::error("player", "F4 ring acquire"); return false; }
-
- if (frame->format == AV_PIX_FMT_D3D12) {
- auto* d3dFrame = reinterpret_cast<AVD3D12VAFrame*>(frame->data[0]);
- if (d3dFrame == nullptr || d3dFrame->texture == nullptr) {
- veyra::log::error("player", "F0 null d3d12va frame");
- return false;
- }
- nv12Texture = d3dFrame->texture;
- const UINT nv12Slice = static_cast<UINT>(d3dFrame->subresource_index);
- if (d3dFrame->sync_ctx.fence != nullptr) {
- if (FAILED(context.directQueue()->Wait(
- d3dFrame->sync_ctx.fence, d3dFrame->sync_ctx.fence_value))) {
- veyra::log::error("player", "F0b nv12 fence wait");
- return false;
- }
- }
- const bool isArray = nv12Texture->GetDesc().DepthOrArraySize > 1;
- D3D12_CPU_DESCRIPTOR_HANDLE base = yuvPass.heap->GetCPUDescriptorHandleForHeapStart();
- D3D12_SHADER_RESOURCE_VIEW_DESC lumaSrv{};
- lumaSrv.Format = DXGI_FORMAT_R8_UNORM;
- lumaSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- lumaSrv.Texture2D.MostDetailedMip = 0;
- lumaSrv.Texture2D.MipLevels = 1;
- lumaSrv.Texture2D.ResourceMinLODClamp = 0.0f;
- if (isArray) {
- lumaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
- lumaSrv.Texture2DArray.MostDetailedMip = 0;
- lumaSrv.Texture2DArray.MipLevels = 1;
- lumaSrv.Texture2DArray.FirstArraySlice = nv12Slice;
- lumaSrv.Texture2DArray.ArraySize = 1;
- lumaSrv.Texture2DArray.PlaneSlice = 0;
- } else {
- lumaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- lumaSrv.Texture2D.MostDetailedMip = 0;
- lumaSrv.Texture2D.MipLevels = 1;
- lumaSrv.Texture2D.PlaneSlice = 0;
- }
- context.device()->CreateShaderResourceView(nv12Texture, &lumaSrv, cpuHandle(yuvPass, 0));
- D3D12_SHADER_RESOURCE_VIEW_DESC chromaSrv{};
- chromaSrv.Format = DXGI_FORMAT_R8G8_UNORM;
- chromaSrv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- chromaSrv.Texture2D.MostDetailedMip = 0;
- chromaSrv.Texture2D.MipLevels = 1;
- chromaSrv.Texture2D.ResourceMinLODClamp = 0.0f;
- if (isArray) {
- chromaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
- chromaSrv.Texture2DArray.MostDetailedMip = 0;
- chromaSrv.Texture2DArray.MipLevels = 1;
- chromaSrv.Texture2DArray.FirstArraySlice = nv12Slice;
- chromaSrv.Texture2DArray.ArraySize = 1;
- chromaSrv.Texture2DArray.PlaneSlice = 1;
- } else {
- chromaSrv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- chromaSrv.Texture2D.MostDetailedMip = 0;
- chromaSrv.Texture2D.MipLevels = 1;
- chromaSrv.Texture2D.PlaneSlice = 1;
- }
- context.device()->CreateShaderResourceView(nv12Texture, &chromaSrv, cpuHandle(yuvPass, 1));
- tracker.transition(list, nv12Texture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- } else {
- nv12Ctx = sws_getCachedContext(nv12Ctx, frame->width, frame->height,
- static_cast<AVPixelFormat>(frame->format),
- frame->width, frame->height, AV_PIX_FMT_NV12, SWS_POINT,
- nullptr, nullptr, nullptr);
- if (nv12Ctx == nullptr) { veyra::log::error("player", "F1 sws"); return false; }
- uint8_t* planes[2] = { nv12Buf.data(), nv12Buf.data() + lumaSize };
- const int strides[2] = { static_cast<int>(lumaPitch), static_cast<int>(chromaPitch) };
- sws_scale(nv12Ctx, frame->data, frame->linesize, 0, frame->height, planes, strides);
- for (uint32_t y = 0; y < srcH; ++y)
- std::memcpy(mappedLuma[parity] + y * lumaPitch, planes[0] + y * lumaPitch, srcW);
- for (uint32_t y = 0; y < srcH / 2; ++y)
- std::memcpy(mappedChroma[parity] + y * chromaPitch, planes[1] + y * chromaPitch, srcW);
- tracker.transition(list, lumaTex.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- tracker.transition(list, chromaTex.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- tracker.transition(list, upLuma[parity].Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- const float constants[8] = {
- static_cast<float>(srcW), static_cast<float>(srcH),
- static_cast<float>(lumaPitch), static_cast<float>(chromaPitch), 0, 0, 0, 0 };
- uploadPass.bind(list, constants,
- gpuHandle(uploadPass, parity).ptr, gpuHandle(uploadPass, 2).ptr);
- list->Dispatch((srcW + 31) / 32 * 2, (srcH + 31) / 32 * 2, 1);
- tracker.uavBarrier(list, lumaTex.Get());
- tracker.uavBarrier(list, chromaTex.Get());
- tracker.transition(list, upLuma[parity].Get(), D3D12_RESOURCE_STATE_GENERIC_READ);
- tracker.transition(list, lumaTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(list, chromaTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- }
-
- gpuMark("upload");
- // 2. YUV -> RGBA16F.
- tracker.transition(list, srcRgba.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- {
- const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
- static_cast<float>(srcW), static_cast<float>(srcH), 0.0f, 0.0f };
- yuvPass.bind(list, constants, gpuHandle(yuvPass, 0).ptr, gpuHandle(yuvPass, 2).ptr);
- list->Dispatch((srcW + 15) / 16, (srcH + 15) / 16, 1);
- }
- tracker.uavBarrier(list, srcRgba.Get());
- tracker.transition(list, srcRgba.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- if (nv12Texture != nullptr) {
- tracker.transition(list, nv12Texture, D3D12_RESOURCE_STATE_COMMON);
+ if (out.hasGenerated) {
+ // Present order: previous real (already queued) -> generated -> current real.
+ presentQueue.push_back({ out.generatedPtsMs, 1,
+ static_cast<uint64_t>(out.generatedPtsMs),
+ out.realFrameIndex, out.genSlot, resetEpoch,
+ out.genFenceValue });
}
-
- gpuMark("yuv");
- // 3. SR into workRgba (or 1:1 blit bypass).
- if (srEnabled) {
- tracker.transition(list, workRgba.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- veyra::ngx::DlssSrBackend::EvalDesc ed{};
- ed.color = srcRgba.Get();
- ed.output = workRgba.Get();
- ed.depth = nrZeroDepth.Get();
- ed.motionVectors = nrZeroMotion.Get();
- ed.reset = reset;
- if (!srBackend.evaluate(list, ngxParams, ed, st)) { veyra::log::error("player", "F5 sr"); return false; }
- ++metrics.srEvaluateCount;
- tracker.uavBarrier(list, workRgba.Get());
- tracker.transition(list, workRgba.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- } else {
- tracker.transition(list, workRgba.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = {
- static_cast<float>(srcW), static_cast<float>(srcH),
- static_cast<float>(workW), static_cast<float>(workH), 0, 0, 0, 0 };
- blitPass.bind(list, constants, gpuHandle(blitPass, 0).ptr, gpuHandle(blitPass, 1).ptr);
- list->Dispatch((workW + 15) / 16, (workH + 15) / 16, 1);
- tracker.uavBarrier(list, workRgba.Get());
- tracker.transition(list, workRgba.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- }
-
- gpuMark("sr");
- // 4a. Parity encode.
- if (nrEnabled) {
- tracker.transition(list, proxyTex.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
- static_cast<float>(workW), static_cast<float>(workH), 0.0f, 0.0f };
- encPass.bind(list, constants, gpuHandle(encPass, 0).ptr, gpuHandle(encPass, 1).ptr);
- list->Dispatch((workW + 15) / 16, (workH + 15) / 16, 1);
- tracker.uavBarrier(list, proxyTex.Get());
- tracker.transition(list, proxyTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
-
- gpuMark("encode");
- // 4b. NR evaluate on a FRESH list (snippet constraint).
- if (!ring.submitAndSignal(slot)) { veyra::log::error("player", "F6a submit"); return false; }
- ID3D12GraphicsCommandList* nlist = ring.acquire((slot + 1) % 4, st);
- if (nlist == nullptr) { veyra::log::error("player", "F4a acquire nr"); return false; }
- {
- namespace p = veyra::ngx::dlssnr;
- veyra::ngx::ParameterBlock pb(ngxParams);
- pb.setD3D12Resource(p::kColor, proxyTex.Get());
- pb.setD3D12Resource(p::kOutput, neuralTex.Get());
- pb.setD3D12Resource(p::kMVec, nrZeroMotion.Get());
- pb.setD3D12Resource(p::kDepth, nrZeroDepth.Get());
- pb.setU32(p::kColorSubrectWidth, workW); pb.setU32(p::kColorSubrectHeight, workH);
- pb.setU32(p::kOutputSubrectWidth, workW); pb.setU32(p::kOutputSubrectHeight, workH);
- pb.setU32(p::kMVecSubrectWidth, workW); pb.setU32(p::kMVecSubrectHeight, workH);
- pb.setU32(p::kDepthSubrectWidth, workW); pb.setU32(p::kDepthSubrectHeight, workH);
- pb.setF32(p::kMVecScaleX, 1.0f); pb.setF32(p::kMVecScaleY, 1.0f);
- pb.setI32(p::kDepthInverted, 1);
- pb.setI32(p::kIndicatorInvertX, 0);
- pb.setI32(p::kIndicatorInvertY, 0);
- pb.setI32(p::kEnabled, 1);
- pb.setI32(p::kReset, reset ? 1 : 0);
- pb.setI32(p::kStyle, 0);
- pb.setF32(p::kIntensity, 1.0f);
- pb.setF32(p::kLocalToneStrength, 1.0f);
- pb.setF32(p::kLocalStructureStrength, 1.0f);
- pb.setF32(p::kSkinStructureStrength, -1.0f);
- pb.setI32(p::kUseAutoMask, 0);
- pb.setI32(p::kUICorrection, 0);
- uint64_t er = 0; uint32_t es = 0;
- if (!nrAdapter.snippetEvaluateFeature(nlist, nrHandle, ngxParams, er, es) ||
- er != static_cast<uint64_t>(NVSDK_NGX_Result_Success)) {
- veyra::log::error("player", std::format("NR evaluate failed 0x{:X} seh={}", er, es));
- return false;
- }
- ++metrics.nrEvaluateCount;
- tracker.uavBarrier(nlist, neuralTex.Get());
- tracker.transition(nlist, neuralTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
-
- // 4c. Parity decode.
- tracker.transition(nlist, finalRgba.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = { 1.0f, 1.0f, 1.0f, 0.0f,
- static_cast<float>(workW), static_cast<float>(workH), 0.0f, 0.0f };
- decPass.bind(nlist, constants, gpuHandle(decPass, 0).ptr, gpuHandle(decPass, 3).ptr);
- nlist->Dispatch((workW + 15) / 16, (workH + 15) / 16, 1);
- tracker.uavBarrier(nlist, finalRgba.Get());
- tracker.transition(nlist, finalRgba.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- }
- list = nlist; // continue recording on the NR list
- }
-
- gpuMark("nr");
- // 5. Working frame -> SDR RGBA8 videoFrame[parity] + NVOF chain.
- {
- const UINT srcSlot = 2;
- const UINT uavSlot = 3 + static_cast<UINT>(parity);
- tracker.transition(list, nrEnabled ? finalRgba.Get() : workRgba.Get(),
- D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(list, videoFrame[parity].Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float constants[8] = {
- static_cast<float>(workW), static_cast<float>(workH),
- static_cast<float>(workW), static_cast<float>(workH), 0, 0, 0, 0 };
- blitPass.bind(list, constants, gpuHandle(blitPass, srcSlot).ptr, gpuHandle(blitPass, uavSlot).ptr);
- list->Dispatch((workW + 15) / 16, (workH + 15) / 16, 1);
- tracker.uavBarrier(list, videoFrame[parity].Get());
- tracker.transition(list, videoFrame[parity].Get(), D3D12_RESOURCE_STATE_COMMON);
-
- // NVOF chain via blits: A := B, then B := this frame.
- tracker.transition(list, nvofInA.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- blitPass.bind(list, constants, gpuHandle(blitPass, 5).ptr, gpuHandle(blitPass, 6).ptr);
- list->Dispatch((workW + 15) / 16, (workH + 15) / 16, 1);
- tracker.uavBarrier(list, nvofInA.Get());
- tracker.transition(list, nvofInA.Get(), D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(list, nvofInB.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float nvofConstants[8] = {
- static_cast<float>(workW), static_cast<float>(workH),
- static_cast<float>(nvofW), static_cast<float>(nvofH), 0, 0, 0, 0 };
- blitPass.bind(list, nvofConstants,
- gpuHandle(blitPass, 7 + static_cast<UINT>(parity)).ptr, gpuHandle(blitPass, 9).ptr);
- list->Dispatch((nvofW + 15) / 16, (nvofH + 15) / 16, 1);
- tracker.uavBarrier(list, nvofInB.Get());
- tracker.transition(list, nvofInB.Get(), D3D12_RESOURCE_STATE_COMMON);
- }
-
- if (!ring.submitAndSignal(nrEnabled ? (slot + 1) % 4 : slot)) {
- veyra::log::error("player", "F6b submit");
- return false;
- }
- const uint64_t colorFenceValue = ring.lastSignaledValue();
-
- // 6. NVOF + FG (queue-ordered after the color work).
- if (fgEnabled && fgBackend.created() && prevValid) {
- const auto nvofT0 = std::chrono::steady_clock::now();
- bool haveFlow = nvof.execute(colorFenceValue, st);
- if (gpuTs) {
- const double nvofMs = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - nvofT0).count();
- passTimings.emplace_back("nvof_call", nvofMs);
- }
- if (haveFlow) {
- ++metrics.nvofExecuteCount;
- if (FAILED(context.directQueue()->Wait(nvofOutFence.Get(), nvof.nextOutValue() - 1))) {
- veyra::log::error("player", "F8 queue wait");
- return false;
- }
- } else {
- // The injected D3D12 layer on this system blocks NVOF
- // frame-time executes once descriptor views exist (see
- // header). Fall back to zero-guidance: DLSSG's internal
- // optical flow still performs the interpolation. Reported
- // honestly as mvecSource in the JSON.
- if (mvecSource == "nvof") {
- mvecSource = "zero-motion-fallback (NVOF blocked by injected layer post-views; "
- "real NVOF proven in P5 probe and FG truth in P6.2)";
- veyra::log::warn("player", "NVOF frame execute blocked by injected layer; "
- "FG falls back to zero-guidance mvec");
- }
- ++nvofFrameFailures;
- }
- ID3D12GraphicsCommandList* flist = ring.acquire((slot + 2) % 4, st);
- if (flist == nullptr) { veyra::log::error("player", "F9 acquire fg"); return false; }
- // P0.4: densify SHORT2->float2 + confidence before FG.
- if (haveFlow) {
- tracker.transition(flist, nvofRawTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(flist, nvofCostTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(flist, flowTex.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- tracker.transition(flist, confTex.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- const float dc[8] = {
- static_cast<float>(rawW), static_cast<float>(rawH),
- static_cast<float>(nvofW), static_cast<float>(nvofH),
- static_cast<float>(selectedGrid),
- 1.0f, // negate: single explicit direction flip (proven by displacement tests)
- 32.0f, // costThreshold (cells below -> zero motion)
- 0.0f };
- densifyPass.bind(flist, dc,
- gpuHandle(densifyPass, 0).ptr, gpuHandle(densifyPass, 2).ptr);
- flist->Dispatch((nvofW + 15) / 16, (nvofH + 15) / 16, 1);
- tracker.uavBarrier(flist, flowTex.Get());
- tracker.uavBarrier(flist, confTex.Get());
- tracker.transition(flist, nvofRawTex.Get(), D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(flist, nvofCostTex.Get(), D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(flist, flowTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(flist, confTex.Get(), D3D12_RESOURCE_STATE_COMMON);
- }
- gpuMark("decode_blit");
- ID3D12Resource* mvecResource = haveFlow ? flowTex.Get() : nrZeroMotion.Get();
- tracker.transition(flist, nvofInB.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- tracker.transition(flist, depthTex.Get(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
- const uint32_t genSlot = static_cast<uint32_t>(realFrameIndex % 2);
- tracker.transition(flist, genFrame[genSlot].Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- veyra::ngx::DlssFgBackend::EvalDesc fe{};
- fe.backbuffer = nvofInB.Get();
- fe.depth = depthTex.Get();
- fe.mvecs = mvecResource;
- fe.outputInterpolated = genFrame[genSlot].Get();
- fe.reset = reset;
- fe.frameId = realFrameIndex;
- fe.mvecScaleX = haveFlow ? (1.0f / static_cast<float>(workW)) : 1.0f;
- fe.mvecScaleY = haveFlow ? (1.0f / static_cast<float>(workH)) : 1.0f;
- if (!fgBackend.evaluate(flist, ngxParams, fe, st)) { veyra::log::error("player", "F10 fg"); return false; }
- tracker.uavBarrier(flist, genFrame[genSlot].Get());
- tracker.transition(flist, genFrame[genSlot].Get(), D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(flist, nvofInB.Get(), D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(flist, mvecResource, D3D12_RESOURCE_STATE_COMMON);
- tracker.transition(flist, depthTex.Get(), D3D12_RESOURCE_STATE_COMMON);
- if (!ring.submitAndSignal((slot + 2) % 4)) { veyra::log::error("player", "F11 fg submit"); return false; }
- gpuMark("fg");
- ++metrics.fgGeneratedFrames;
- presentQueue.push_back({ (prevPtsMs + ptsMs) * 0.5, 1,
- static_cast<uint64_t>((prevPtsMs + ptsMs) * 0.5),
- realFrameIndex, genSlot, resetEpoch, ring.lastSignaledValue() });
- }
-
presentQueue.push_back({ ptsMs, 0, static_cast<uint64_t>(ptsMs),
- realFrameIndex, static_cast<uint32_t>(parity), resetEpoch,
- ring.lastSignaledValue() });
+ out.realFrameIndex, out.videoSlot, resetEpoch,
+ out.videoFenceValue });
prevPtsMs = ptsMs;
prevValid = true;
- lastParity = parity;
- ++realFrameIndex;
+ lastParity = static_cast<int>(out.videoSlot);
+ realFrameIndex = out.realFrameIndex;
metrics.maxInFlight = std::max<int64_t>(metrics.maxInFlight,
static_cast<int64_t>(presentQueue.size()));
return true;
@@ -2342,8 +1273,8 @@ int main(int argc, char** argv)
// P0.3: display THIS item's own texture only.
ID3D12Resource* source = item.kind == 1
- ? genFrame[item.textureSlot].Get()
- : videoFrame[item.textureSlot].Get();
+ ? graph.generatedFrameResource(item.textureSlot)
+ : graph.videoFrameResource(item.textureSlot);
if (source == nullptr) {
veyra::log::error("player", "P5 null item texture");
return false;
@@ -2367,7 +1298,7 @@ int main(int argc, char** argv)
b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
b[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
list->ResourceBarrier(2, b);
- tracker.set(source, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
+ presentTracker.set(source, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
}
const bool clearPresent = GetEnvironmentVariableW(L"VEYRA_CLEAR_PRESENT", nullptr, 0) != 0;
if (!clearPresent) {
@@ -2409,7 +1340,7 @@ int main(int argc, char** argv)
b[1].Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
b[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
list->ResourceBarrier(2, b);
- tracker.set(source, D3D12_RESOURCE_STATE_COMMON);
+ presentTracker.set(source, D3D12_RESOURCE_STATE_COMMON);
}
if (!ring.submitAndSignal(3)) { veyra::log::error("player", "P3 submit"); return false; }
if (!sink.present(st)) { veyra::log::error("player", "P4 present"); return false; }
@@ -2492,10 +1423,10 @@ int main(int argc, char** argv)
veyra::log::info("player", std::format("pace t={:.0f}s ws={}MB presents={}/10s fg={}/10s queue={}",
elapsed, pmc.WorkingSetSize / (1024 * 1024),
metrics.presentCount - lastSamplePresents,
- metrics.fgGeneratedFrames - lastSampleFg,
+ g_graphFgGen - lastSampleFg,
presentQueue.size()));
lastSamplePresents = metrics.presentCount;
- lastSampleFg = metrics.fgGeneratedFrames;
+ lastSampleFg = g_graphFgGen;
lastSampleSec = elapsed;
}
if (elapsed >= seconds) break;
@@ -2514,7 +1445,7 @@ int main(int argc, char** argv)
++framesSinceRecycle;
if (frameStride > 1 && (strideCounter % frameStride) != 1) continue;
if (!processOneFrame(f)) return false;
- if (gpuTs && (metrics.fgGeneratedFrames % 120 == 0)) gpuReport();
+ if (gpuTs && (g_graphFgGen % 120 == 0)) gpuReport();
}
static const bool presentOff = GetEnvironmentVariableW(L"VEYRA_PRESENT_OFF", nullptr, 0) != 0;
if (!presentOff && !pumpPresents()) return false;
@@ -2532,19 +1463,19 @@ int main(int argc, char** argv)
if (endurance) {
resyncToAudio();
veyra::log::info("player", "endurance: 4K30 pass start");
- const uint64_t p0 = metrics.presentCount, f0 = metrics.fgGeneratedFrames;
+ const uint64_t p0 = metrics.presentCount, f0 = g_graphFgGen;
if (!runPlayback(static_cast<double>(durationSeconds), 2)) break;
end4k30Duration = durationSeconds;
- end4k30Fg = metrics.fgGeneratedFrames - f0;
+ end4k30Fg = g_graphFgGen - f0;
end4k30Hz = static_cast<double>(metrics.presentCount - p0) / end4k30Duration;
veyra::log::info("player", std::format("4K30: presents={} fg={} hz={:.1f}",
metrics.presentCount - p0, end4k30Fg, end4k30Hz));
resyncToAudio();
veyra::log::info("player", "endurance: 4K60 pass start");
- const uint64_t p1 = metrics.presentCount, f1 = metrics.fgGeneratedFrames;
+ const uint64_t p1 = metrics.presentCount, f1 = g_graphFgGen;
if (!runPlayback(static_cast<double>(durationSeconds), 1)) break;
end4k60Duration = durationSeconds;
- end4k60Fg = metrics.fgGeneratedFrames - f1;
+ end4k60Fg = g_graphFgGen - f1;
end4k60Hz = static_cast<double>(metrics.presentCount - p1) / end4k60Duration;
veyra::log::info("player", std::format("4K60: presents={} fg={} hz={:.1f}",
metrics.presentCount - p1, end4k60Fg, end4k60Hz));
@@ -2589,26 +1520,24 @@ int main(int argc, char** argv)
// handle made the frame path call Evaluate(nullptr) (SEGV caught
// by the adapter's SEH, run aborted, teardown skipped - t10-NF).
nrToggleWorks = false;
- if (nrHandle != nullptr) {
- nrEnabled = false;
+ if (graph.nrCreated()) {
+ graph.setNrEnabled(false);
(void)ring.waitIdle();
- if (!skipViews) stagedSrv(workRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass, 2);
if (!runPlayback(1.0, 1)) break;
- nrEnabled = true;
+ graph.setNrEnabled(true);
(void)ring.waitIdle();
- if (!skipViews) if (viewsTex) stagedSrv(finalRgba.Get(), DXGI_FORMAT_R16G16B16A16_FLOAT, blitPass, 2);
if (!runPlayback(1.0, 1)) break;
- nrToggleWorks = metrics.nrEvaluateCount > 0;
+ nrToggleWorks = g_graphNrEval > 0;
}
srToggleWorks = !srNeeded; // 1:1 bypass by definition; scaling toggle is Phase 7 UI scope
- if (fgBackend.created()) {
- fgEnabled = false;
+ if (graph.fgCreated()) {
+ graph.setFgEnabled(false);
if (!runPlayback(1.0, 1)) break;
- fgEnabled = true;
+ graph.setFgEnabled(true);
if (!runPlayback(1.0, 1)) break;
- fgToggleWorks = metrics.fgGeneratedFrames > 0;
+ fgToggleWorks = g_graphFgGen > 0;
}
audioUnderruns = audio.underruns();
@@ -2633,6 +1562,12 @@ int main(int argc, char** argv)
}
g_droppedSourceFrames = droppedSourceFrames;
g_droppedGeneratedFrames = droppedGeneratedFrames;
+ g_graphNrEval = gmetrics.nrEvaluateCount;
+ g_graphSrEval = gmetrics.srEvaluateCount;
+ g_graphNvofExec = gmetrics.nvofExecuteCount;
+ g_graphFgGen = gmetrics.fgGeneratedFrames;
+ g_graphNvofFail = gmetrics.nvofFrameFailures;
+ g_graphMvecSource = graph.mvecSource();
g_audioEndBufferedMs = audioPipe.bufferedMs();
g_audioEndHeadPtsMs = audioPipe.headPtsMs();
g_audioEndClockPtsMs = audio.mediaTimeMs();
@@ -2737,7 +1672,7 @@ int main(int argc, char** argv)
// natural destruction after everything is released. GPU resources
// (inputA/B/flow/cost ComPtrs) stay alive until nvof.shutdown()
// has unregistered them.
- lastNvofSignal = nvof.initialized() ? (nvof.nextOutValue() - 1) : 0;
+ lastNvofSignal = graph.lastNvofSignal();
veyra::log::info("teardown", std::format("saved lastNvofSignal={}", lastNvofSignal));
// s10-III: crash-honest evidence stub BEFORE teardown; only success
@@ -2751,7 +1686,7 @@ int main(int argc, char** argv)
// 1. Stop producers / audio thread / new-frame submission.
stage("sws-free");
- if (nv12Ctx != nullptr) sws_freeContext(nv12Ctx);
+ // nv12Ctx is owned by EnhanceGraph; freed inside graph.shutdown().
stageDone("sws-free");
stage("audio-thread-stop");
audioPipe.stopThread();
@@ -2767,30 +1702,30 @@ int main(int argc, char** argv)
// 3. NVOF out-fence drain while session/fence/event are all valid.
stage("nvof-out-fence-drain");
- if (nvof.initialized() && nvofOutFence.Get() != nullptr && lastNvofSignal > 0) {
- const UINT64 completedBefore = nvofOutFence->GetCompletedValue();
+ if (graph.nvofSessionInitialized() && graph.nvofOutFenceResource() != nullptr && lastNvofSignal > 0) {
+ const UINT64 completedBefore = graph.nvofOutFenceResource()->GetCompletedValue();
DWORD waitResult = WAIT_OBJECT_0;
if (completedBefore < lastNvofSignal) {
- const HRESULT hrSet = nvofOutFence->SetEventOnCompletion(lastNvofSignal, nvofOutEvent);
+ const HRESULT hrSet = graph.nvofOutFenceResource()->SetEventOnCompletion(lastNvofSignal, graph.nvofOutEventHandle());
if (FAILED(hrSet)) {
veyra::log::error("teardown", std::format(
"SetEventOnCompletion FAILED hr=0x{:X} expected={} completed={}",
static_cast<unsigned>(hrSet), lastNvofSignal, completedBefore));
overall = false;
} else {
- waitResult = WaitForSingleObject(nvofOutEvent, 5000);
+ waitResult = WaitForSingleObject(graph.nvofOutEventHandle(), 5000);
if (waitResult != WAIT_OBJECT_0) {
veyra::log::error("teardown", std::format(
"NVOF fence drain FAILED waitResult={} expected={} completed={}",
- waitResult, lastNvofSignal, nvofOutFence->GetCompletedValue()));
+ waitResult, lastNvofSignal, graph.nvofOutFenceResource()->GetCompletedValue()));
overall = false;
}
}
}
veyra::log::info("teardown", std::format(
"nvof-out-fence-drain expected={} completedBefore={} completedAfter={} waitResult={}",
- lastNvofSignal, completedBefore, nvofOutFence->GetCompletedValue(), waitResult));
- if (nvofOutFence->GetCompletedValue() < lastNvofSignal) overall = false;
+ lastNvofSignal, completedBefore, graph.nvofOutFenceResource()->GetCompletedValue(), waitResult));
+ if (graph.nvofOutFenceResource()->GetCompletedValue() < lastNvofSignal) overall = false;
}
stageDone("nvof-out-fence-drain");
@@ -2807,111 +1742,19 @@ int main(int argc, char** argv)
if (ring.initialized() && !ring.drainQueue()) overall = false;
stageDone("queue-final-drain");
- // 5. NGX features AFTER all GPU work is complete.
- stage("nr-feature-release");
- if (nrHandle != nullptr) {
- uint64_t rr = 0; uint32_t rs = 0;
- (void)nrAdapter.snippetReleaseFeature(nrHandle, rr, rs);
- }
- stageDone("nr-feature-release");
- stage("fg-release");
- fgBackend.release();
- stageDone("fg-release");
- stage("sr-release");
- srBackend.release();
- stageDone("sr-release");
-
- // 6. NVOF teardown in THREE phases (ownership rule proven by
- // t10-L0-r2: releasing an NVOF-registered resource AFTER
- // nvOFDestroy+FreeLibrary segfaults):
- // a. unregisterAll() while the textures are still alive;
- // b. release the four registered textures (DLL still loaded);
- // c. shutdown() = nvOFDestroy + FreeLibrary.
- stage("nvof-unregister");
- if (nvof.initialized()) {
- veyra::Status us = veyra::Status::Ok;
- if (!nvof.unregisterAll(us)) {
- veyra::log::error("teardown", std::format(
- "nvof unregisterAll failed status={}", static_cast<int>(us)));
- overall = false;
- }
- }
- stageDone("nvof-unregister");
- stage("release-nvof-resources");
- nvofCostTex.Reset();
- nvofRawTex.Reset();
- nvofInB.Reset();
- nvofInA.Reset();
- stageDone("release-nvof-resources");
- stage("nvof-shutdown");
- nvof.shutdown();
- stageDone("nvof-shutdown");
-
- // 7. Only now close the NVOF event/fence.
- stage("nvof-event-close");
- if (nvofOutEvent != nullptr) { CloseHandle(nvofOutEvent); nvofOutEvent = nullptr; }
- stageDone("nvof-event-close");
-
- stage("ngx-params-destroy");
- if (coreHost.initialized() && ngxParams != nullptr) coreHost.destroyParameters(ngxParams);
- stageDone("ngx-params-destroy");
- stage("iat-shim-restore");
- nrAdapter.restoreCallerCompatibility();
- nrAdapter.unload();
- stageDone("iat-shim-restore");
- stage("ngx-core-shutdown");
- coreHost.shutdown();
- stageDone("ngx-core-shutdown");
-
- // s10: staged explicit release so the scope-end destructors have
- // nothing left to destroy; a SEGV observed during implicit scope
- // destruction is pinpointed by the first missing after-marker.
+ // 5-7. Everything the graph owns (NGX features, NVOF three-phase
+ // teardown, NGX params/shim/core, compute passes, textures) is
+ // released by the graph in the proven s10 order.
+ stage("graph-shutdown");
+ graph.shutdown();
+ stageDone("graph-shutdown");
+
stage("release-rtv-heap");
rtvHeap.Reset();
stageDone("release-rtv-heap");
stage("release-present-pass");
presentPass = GraphicsPass{};
stageDone("release-present-pass");
- stage("release-compute-passes");
- uploadPass = ComputePass{};
- decPass = ComputePass{};
- encPass = ComputePass{};
- blitPass = ComputePass{};
- yuvPass = ComputePass{};
- densifyPass = ComputePass{};
- stageDone("release-compute-passes");
- stage("release-guidance-textures");
- confTex.Reset();
- flowTex.Reset();
- depthTex.Reset();
- nrZeroMotion.Reset();
- nrZeroDepth.Reset();
- stageDone("release-guidance-textures");
- stage("release-frame-textures");
- genFrame[0].Reset();
- genFrame[1].Reset();
- videoFrame[0].Reset();
- videoFrame[1].Reset();
- stageDone("release-frame-textures");
- stage("release-working-textures");
- finalRgba.Reset();
- neuralTex.Reset();
- proxyTex.Reset();
- workRgba.Reset();
- srcRgba.Reset();
- chromaTex.Reset();
- lumaTex.Reset();
- stageDone("release-working-textures");
- stage("release-upload-staging");
- upZeroMotion.Reset();
- upZeroDepth.Reset();
- upDepth.Reset();
- upChroma[0].Reset();
- upChroma[1].Reset();
- upLuma[0].Reset();
- upLuma[1].Reset();
- stageDone("release-upload-staging");
-
// ring/sink/context are NOT shut down here: their explicit teardown
// runs AFTER this scope closes, because the scope-end destructors
// Release every GPU resource ComPtr and those Release calls need the
@@ -3047,10 +1890,10 @@ int main(int argc, char** argv)
j += std::format(" \"normalPathReadbackCount\": {},\n", metrics.normalPathReadbackCount);
j += std::format(" \"presentCount\": {},\n", metrics.presentCount);
j += std::format(" \"realFramesPresented\": {},\n", metrics.realFramesPresented);
- j += std::format(" \"fgGeneratedFrames\": {},\n", metrics.fgGeneratedFrames);
- j += std::format(" \"nrEvaluateCount\": {},\n", metrics.nrEvaluateCount);
- j += std::format(" \"srEvaluateCount\": {},\n", metrics.srEvaluateCount);
- j += std::format(" \"nvofExecuteCount\": {},\n", metrics.nvofExecuteCount);
+ j += std::format(" \"fgGeneratedFrames\": {},\n", g_graphFgGen);
+ j += std::format(" \"nrEvaluateCount\": {},\n", g_graphNrEval);
+ j += std::format(" \"srEvaluateCount\": {},\n", g_graphSrEval);
+ j += std::format(" \"nvofExecuteCount\": {},\n", g_graphNvofExec);
j += std::format(" \"nvofFrameFailures\": {},\n", nvofFrameFailures);
j += std::format(" \"nvofLastSignal\": {},\n", lastNvofSignal);
j += std::format(" \"mvecSource\": \"{}\",\n", jsonEscape(mvecSource));
@@ -3119,8 +1962,8 @@ int main(int argc, char** argv)
if (!jsonFile.empty()) (void)utilns::writeTextFileUtf8(jsonFile, j);
}
veyra::log::info("player", std::format("player-probe: {} presents={} fg={} nr={} sr={} driftP95={:.1f}ms",
- overall ? "PASS" : "FAIL", metrics.presentCount, metrics.fgGeneratedFrames,
- metrics.nrEvaluateCount, metrics.srEvaluateCount, driftP95Ms));
+ overall ? "PASS" : "FAIL", metrics.presentCount, g_graphFgGen,
+ g_graphNrEval, g_graphSrEval, driftP95Ms));
veyra::Logger::instance().flush();
veyra::log::info("player", "teardown-complete; process will return naturally");