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++
fix(gpu): associate frame completion with its producer fence
Veyra Goal Agent1b955b5ed0f9
diff --git a/docs/FG_CADENCE_REPAIR_PLAN_2026-09-20.md b/docs/FG_CADENCE_REPAIR_PLAN_2026-09-20.mdindex a55eacb1..6ac784bf 100644--- a/docs/FG_CADENCE_REPAIR_PLAN_2026-09-20.md+++ b/docs/FG_CADENCE_REPAIR_PLAN_2026-09-20.md@@ -4,6 +4,33 @@ Continuation: affordable same-input reseeding removes a second lost groupafter budget rejection. Fixed6 now measures about280 submissions/s, stillwith15ms holes; acceptance remains open. Fallback is not the requested fix.+## Next experiment: overlap enhancement and interpolation++The retained trace attributes every >10ms gap to a rejected interpolation+group. Test whether NR for input N+1 can overlap FG for input N, instead of+assuming the current serial stage sum is an immutable hardware limit.++1. Carry producer fence identity with each lease and with non-published+ warmup completion. Poll and presentation must use that object's timeline.+ Keep current single graph queue until this prerequisite passes regression.+2. An isolated FG queue needs its own ring/fence/event and drain lifecycle.+ Snapshot motion per parity before handing off; depth is currently immutable.+ No queue may signal another queue's monotonic completion fence.+ The first experiment must be explicitly requested by the realtime engine,+ not enabled globally from inside the graph: player_probe and existing+ export callers still consume numeric fence values on the original queue.+3. Protect video input and generated/status output reuse, including seed-only+ evaluations with no generated leases. Real-frame presentation must wait+ for FG's read of its texture before changing that texture's state.+4. Split timestamp collection by producer queue. Do not subtract timestamps+ from different clocks or treat overlapping sums as elapsed execution time.+ File budget and queued-work prediction need a dependency model before+ promotion; keep any initial feasibility path explicitly experimental.+5. Compare fixed6 same-media cadence, actual GPU overlap and latency against+ checkpoint/fg-same-input-seed-20260920. Validate reset/seek/resize/stop,+ 2X/4X/6X, seeds, exports and non-DLSS paths before enabling normally.+ Separate queues alone do not prove concurrent execution or a speedup.+Latest continuation: prefix admission, carried queue prediction and minimumfile output spacing are now enabled normally; command allocator budget16,two-job capacity unchanged. Experimental admission/spacing flags removed.diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 968be500..bea1dd20 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1,5 +1,36 @@# Veyra 工作记录+Queue identity final regression: fence-fixed2 (30s) retained119.99565/s,+P95/max8.7444/9.009ms, no >10ms gaps or discarded generated frames;+fence-xess4 (30s) final samples app60/SDK240, limited/skipped/expired0;+fence-smoke main startup5s exit0. All under the same task tests directory,+run-short-test watchdogs <=95s. This verifies the prerequisite only, not an+async queue optimization or completed fixed6 cadence repair.++## 2026-09-20 Queue-specific completion prerequisite++Preparing an NR/FG overlap feasibility experiment; no independent FG queue+is enabled yet. FrameLease now owns its producing fence identity alongside+the value. FrameOutputs keeps both video and generation producers, including+seed-only generation. Readiness, completion accounting, queued-work filtering+and presenter GPU waits use the appropriate producer instead of assuming+the context fence. A missing producer for nonzero work remains incomplete;+device-removed UINT64_MAX is not reported as completed work.++Built sustained/admission/presentation-worker/pacing/main targets via+scripts/build-isolated.ps1 in existing build/slider-reset-20260919.+Initial fence-identity-build.log failed on an incomplete context type in an+inline method; moved that method to EnhanceGraph.cpp. Second build passed:+E:/项目/Veyra/logs/fg-cadence-repair-20260920/fence-identity-build2.log.+fence-content6 passes independent fence timelines/missing producer checks,+2/4/6 dynamic groups, reset/seed/skip/content checks; D3D12 errors0.+fence-fixed6:30s, retained5.401s,285.120 submissions/s, P95/max15.025/16.500ms,+81 gaps over10ms all with16.667ms media steps. No retained generated discards.+This is baseline variation, not an optimization claim. fence-lifecycle passes+pause/seek/resume/mode/resize/stop. All test outputs under+E:/项目/Veyra/tests/fg-cadence-repair-20260920, temporary environment under+E:/项目/Veyra/tmp/fg-cadence-repair-20260920. No package or release.+## 2026-09-20 Fixed6 gap attributionSaved verified seed implementation as57213e1,diff --git a/include/veyra/pipeline/EnhanceGraph.h b/include/veyra/pipeline/EnhanceGraph.hindex c229df80..e3758eda 100644--- a/include/veyra/pipeline/EnhanceGraph.h+++ b/include/veyra/pipeline/EnhanceGraph.h@@ -161,6 +161,11 @@ public:double generatedPtsMs = 0.0; // strict midpoint of prev/current PTSuint32_t genSlot = 0; // genFrame[genSlot] holds the DLSSG outputuint64_t genFenceValue = 0;+ Microsoft::WRL::ComPtr<ID3D12Fence> videoFenceObject,genFenceObject;+ bool gpuComplete()const {+ return fenceComplete(videoFenceObject.Get(),videoFenceValue)&&+ fenceComplete(genFenceObject.Get(),genFenceValue);+ }uint64_t realFrameIndex = 0;bool passthrough = false; // VEYRA_GRAPH_OFF: metadata only, no GPU work};@@ -187,6 +192,7 @@ public:if(generated&&slot<kGeneratedPoolSlots){if(auto lease=generatedLeases_[slot].lock())return lease->readyFence;}return uploadFences_[slot%2];}+ ID3D12Fence* presentationReadyFenceObject(unsigned slot,bool generated)const;void presentationSubmitted(unsigned slot,ID3D12Fence* fence,uint64_t value){presentationFences_[slot%2]=fence;presentationValues_[slot%2]=value;}diff --git a/include/veyra/pipeline/FrameBatch.h b/include/veyra/pipeline/FrameBatch.hindex 03031748..0cf8af1e 100644--- a/include/veyra/pipeline/FrameBatch.h+++ b/include/veyra/pipeline/FrameBatch.h@@ -6,6 +6,14 @@#include <d3d12.h>#include <wrl/client.h>namespace veyra::pipeline {+// Fence values are ordered only within the same fence object. Never compare+// a graph fence value with one produced by an independent GPU queue.+inline bool fenceComplete(ID3D12Fence* fence,uint64_t value) {+ if(!value)return true;+ if(!fence)return false;+ const auto completed=fence->GetCompletedValue();+ return completed!=UINT64_MAX&&completed>=value;+}enum class FrameKind { Real, Generated, Hold };enum class GenerationValidity { NotApplicable, Pending, Valid, Disabled, Failed };struct FrameIdentity {@@ -16,9 +24,11 @@ struct FrameIdentity {// consumer fence before overwriting a pool slot. COM lifetime alone is insufficient.struct FrameLease {Microsoft::WRL::ComPtr<ID3D12Resource> texture,sourceReference,baseReference;+ Microsoft::WRL::ComPtr<ID3D12Fence> readyFenceObject;uint64_t readyFence=0,consumerFence=0;uint32_t slot=0;bool referencesValid=false;+ bool ready()const{return fenceComplete(readyFenceObject.Get(),readyFence);}};struct BatchFrame {FrameIdentity identity;diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex c8aa3813..23960abb 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -571,9 +571,8 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,scollectTimings();for(auto it=pendingCompletions.begin();it!=pendingCompletions.end();){auto& watch=**it;auto& batch=watch.output;- const auto completedFence=ctx.fence()->GetCompletedValue();for(unsigned i=0;i<batch.batch.count;++i){const auto& item=batch.batch.frames[i];- if(!watch.frameReadyObserved[i]&&item.lease&&completedFence>=item.lease->readyFence){+ if(!watch.frameReadyObserved[i]&&item.lease&&item.lease->ready()){watch.frameReadyObserved[i]=host100ns();if(traceSubframes)traceFrame(diagnostics::TraceKind::FrameReady,item.identity,batch.batch.batchId,item.lease->readyFence,item.pts100ns,item.subframe,1,elapsedMs(watch.processStart));}@@ -1111,7 +1110,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst auto start=std::chrono::duration_cast<std::chrono::nanoseconds>(processStart.time_since_epoch()).count()/100;int64_t finish=0;for(const auto& previous:pendingCompletions){- if(ctx.fence()->GetCompletedValue()>=std::max(previous->output.videoFenceValue,previous->output.genFenceValue))continue;+ if(previous->output.gpuComplete())continue;const auto began=std::chrono::duration_cast<std::chrono::nanoseconds>(previous->processStart.time_since_epoch()).count()/100;const auto cost=previous->output.fgEvaluated?fgBudget.predicted(start,previous->output.historyReset||previous->output.fgRecovery):fgBudget.baseCost(start);finish=std::max({finish,began,previous->predictedGpuStart100ns})+int64_t(cost.value_or(0)*10000);diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cppindex f2f43f97..4adcf9e3 100644--- a/src/engine/VideoPresenter.cpp+++ b/src/engine/VideoPresenter.cpp@@ -118,7 +118,9 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&}const auto beginEnd=std::chrono::steady_clock::now();if(presentationQueue_){- const HRESULT hr=presentationQueue_->Wait(ctx.fence(),graph.presentationReadyFence(slot,generated));+ auto* producerFence=graph.presentationReadyFenceObject(slot,generated);+ if(!producerFence){veyra::log::error("present","missing producer fence");return false;}+ const HRESULT hr=presentationQueue_->Wait(producerFence,graph.presentationReadyFence(slot,generated));if(FAILED(hr)){veyra::log::error("present",std::format("producer handoff wait hr=0x{:X}",unsigned(hr)));return false;}}Status st=Status::Ok;uint32_t commandSlot=0;auto* list=ring.acquireNext(commandSlot,st);if(!list)return false;diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex fc61b773..c368cca8 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -1911,6 +1911,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameif (!ring_.submitAndSignal(slot)) return false;if(!runFg)gpuTimer_.submitted(ring_.lastSignaledValue());out.videoFenceValue = ring_.lastSignaledValue();+ out.videoFenceObject = context_.fence();// FG reads enhanced SDR color, not the pre-NR guidance input.if (runFg && fgBackend_ && fgBackend_->created()) {@@ -1957,12 +1958,13 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameif(sub==fgCalls)gpuTimer_.submitted(ring_.lastSignaledValue());out.hasGenerated=!resetFg;out.genSlot=parity; out.genFenceValue=ring_.lastSignaledValue();+ out.genFenceObject=context_.fence();out.generatedPtsMs=(prevPtsMs_+ptsMs)*0.5;if(out.hasGenerated){++metrics_.fgSubmittedCandidates;BatchFrame f;f.identity=out.batch.identity;f.kind=FrameKind::Generated;f.validity=GenerationValidity::Pending;f.subframe=sub;f.pts100ns=FrameBatch::interpolate(out.batch.a100ns,out.batch.b100ns,sub,fgMultiplier);- f.lease=std::make_shared<FrameLease>();f.lease->texture=genFrame_[generatedSlot];f.lease->slot=generatedSlot;f.lease->readyFence=out.genFenceValue;generatedLeases_[generatedSlot]=f.lease;out.batch.append(std::move(f));+ f.lease=std::make_shared<FrameLease>();f.lease->texture=genFrame_[generatedSlot];f.lease->slot=generatedSlot;f.lease->readyFence=out.genFenceValue;f.lease->readyFenceObject=out.genFenceObject;generatedLeases_[generatedSlot]=f.lease;out.batch.append(std::move(f));}}}@@ -1975,16 +1977,22 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame++realFrameIndex_;out.realFrameIndex = realFrameIndex_;out.videoSlot = parity;- BatchFrame real;real.identity=out.batch.identity;real.pts100ns=out.batch.b100ns;real.lease=std::make_shared<FrameLease>();real.lease->texture=videoFrame_[parity];real.lease->sourceReference=sourceReferences_[parity];real.lease->baseReference=baseReferences_[parity];real.lease->slot=parity;real.lease->readyFence=out.videoFenceValue;real.lease->referencesValid=retainReferences;realLeases_[parity]=real.lease;out.batch.append(std::move(real));+ BatchFrame real;real.identity=out.batch.identity;real.pts100ns=out.batch.b100ns;real.lease=std::make_shared<FrameLease>();real.lease->texture=videoFrame_[parity];real.lease->sourceReference=sourceReferences_[parity];real.lease->baseReference=baseReferences_[parity];real.lease->slot=parity;real.lease->readyFence=out.videoFenceValue;real.lease->readyFenceObject=out.videoFenceObject;real.lease->referencesValid=retainReferences;realLeases_[parity]=real.lease;out.batch.append(std::move(real));if(veyra::log::verboseFrameLogs())veyra::log::info("frame-batch",std::format("batch={} epoch={} revision={} source={} a={} b={} count={} realSlot={} realFence={} genSlot={} genFence={}",out.batch.batchId,epoch_,out.batch.identity.settingsRevision,out.batch.identity.sourceFrameId,out.batch.a100ns,out.batch.b100ns,out.batch.count,parity,out.videoFenceValue,out.genSlot,out.genFenceValue));return true;}+ID3D12Fence* EnhanceGraph::presentationReadyFenceObject(unsigned slot,bool generated)const+{+ if(generated&&slot<kGeneratedPoolSlots){if(auto lease=generatedLeases_[slot].lock())return lease->readyFenceObject.Get();}+ return context_.fence();+}+bool EnhanceGraph::resolveFrame(FrameOutputs& out,uint32_t index){if(index>=out.batch.count)return false;auto& frame=out.batch.frames[index];- if(!frame.lease||context_.fence()->GetCompletedValue()<frame.lease->readyFence)return false;+ if(!frame.lease||!frame.lease->ready())return false;if(frame.kind!=FrameKind::Generated||frame.validity!=GenerationValidity::Pending)return true;void* data=nullptr;D3D12_RANGE range{0,4};HRESULT hr=fgDisableReadback_[frame.lease->slot]->Map(0,&range,&data);@@ -2008,7 +2016,7 @@ bool EnhanceGraph::resolveGeneration(FrameOutputs& out)}// Warmup evaluates may have no exposed generated leases, but their status// and resources must finish before full-batch completion is reported.- if(context_.fence()->GetCompletedValue()<out.genFenceValue)complete=false;+ if(!out.gpuComplete())complete=false;if(complete)out.hasGenerated=anyValid;return complete;}diff --git a/tests/integration/FgAdmissionTests.cpp b/tests/integration/FgAdmissionTests.cppindex 05bf6077..73d2fe93 100644--- a/tests/integration/FgAdmissionTests.cpp+++ b/tests/integration/FgAdmissionTests.cpp@@ -21,6 +21,21 @@ int wmain(int argc,wchar_t** argv){gfx::DeviceContextDesc device;device.enableDebugLayer=true;bool ok=ctx.initialize(device,status)&&ring.initialize(ctx.device(),ctx.directQueue(),ctx.fence(),ctx.fenceEvent(),6,status);Microsoft::WRL::ComPtr<ID3D12InfoQueue> info;if(ok)ctx.device()->QueryInterface(IID_PPV_ARGS(&info));+ if(ok){+ Microsoft::WRL::ComPtr<ID3D12Fence> enhanced,generatedFence;+ ok=SUCCEEDED(ctx.device()->CreateFence(9,D3D12_FENCE_FLAG_NONE,IID_PPV_ARGS(&enhanced)))&&+ SUCCEEDED(ctx.device()->CreateFence(0,D3D12_FENCE_FLAG_NONE,IID_PPV_ARGS(&generatedFence)));+ if(ok){+ pipeline::FrameLease lease;lease.readyFence=1;lease.readyFenceObject=generatedFence;+ pipeline::EnhanceGraph::FrameOutputs output;output.videoFenceValue=9;output.videoFenceObject=enhanced;+ output.genFenceValue=1;output.genFenceObject=generatedFence;+ ok=!lease.ready()&&!output.gpuComplete();+ ok=ok&&SUCCEEDED(generatedFence->Signal(1))&&lease.ready()&&output.gpuComplete();+ lease.readyFenceObject.Reset();ok=ok&&!lease.ready();+ output.genFenceObject.Reset();ok=ok&&!output.gpuComplete();+ std::cout<<"FENCE_IDENTITY independent timelines and missing producer pass="<<ok<<std::endl;+ }+ }source::MediaFileSource source;source::SourceOpenDesc input;input.path=argv[3];input.preferHardwareDecode=false;ok=ok&&source.open(input);pipeline::EnhanceGraph graph(ctx,ring);pipeline::EnhanceGraphDesc desc;