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++

perf: reduce MFG status readbacks

Veyra Goal Agent88915a3c8280
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 0f11aff4..75f0ef5b 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -5009,3 +5009,20 @@ GPU full-group 观测约 NR 6.715ms、Flow 1.056ms、FG batch 10.042ms,slot CP
4.519/16.692/17.102ms,18 个间隔超过 16.667ms,36 次 rejected→warmup;GPU
P95 约 NR5.664ms、Flow1.265ms、FG10.659ms,slot CPU wait 仍为 0。降低 NR 分辨率
接近但没有达到均匀固定 6X,因此仍只作为性能对照,不改变原画质验收目标。
+### 2026-09-20 MFG status readback reduction (retained)
+
+First single-variable optimization on the fixed6X baseline: the disable flag is
+copied to readback once after the final MFG Evaluate, while all generated frames
+in that batch reference the same per-batch readback slot. Texture slots and
+fences remain distinct, so queued batches do not alias status memory. Changes:
+`include/veyra/pipeline/FrameBatch.h`, `src/pipeline/EnhanceGraph.cpp`.
+
+Build `E:/项目/Veyra/logs/fg-cadence-repair-20260920/status-readback-build.log`
+succeeded; UI contract tests passed. `status-readback-fixed6` on p001/NR1080/4K
+fixed6X reached 308.1 software submissions/s in the retained trace window,
+with 252 full6 groups and no discarded generated subframes; the corresponding
+baseline recheck was 303.7/s. Frame-flow cumulative generated FPS was 240 vs
+225 in that pair of runs. This is a small positive result, not fixed6X acceptance.
+The fixed2 regression remained 119.996/s with no gaps over16.667ms. Keep this
+change as the current experiment checkpoint and test the next optimization from
+here; no package, release or shutdown.
diff --git a/include/veyra/pipeline/FrameBatch.h b/include/veyra/pipeline/FrameBatch.h
index 0cf8af1e..2182dcdd 100644
--- a/include/veyra/pipeline/FrameBatch.h
+++ b/include/veyra/pipeline/FrameBatch.h
@@ -27,6 +27,10 @@ struct FrameLease {
Microsoft::WRL::ComPtr<ID3D12Fence> readyFenceObject;
uint64_t readyFence=0,consumerFence=0;
uint32_t slot=0;
+ // MFG status is written once per input pair. Generated frames in the same
+ // batch share the final per-batch readback slot, while their textures keep
+ // distinct slots and fences.
+ uint32_t statusSlot=UINT32_MAX;
bool referencesValid=false;
bool ready()const{return fenceComplete(readyFenceObject.Get(),readyFence);}
};
diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cpp
index c368cca8..92849e2a 100644
--- a/src/pipeline/EnhanceGraph.cpp
+++ b/src/pipeline/EnhanceGraph.cpp
@@ -1915,6 +1915,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
// FG reads enhanced SDR color, not the pre-NR guidance input.
if (runFg && fgBackend_ && fgBackend_->created()) {
+ const uint32_t statusReadbackSlot=parity+(fgCalls-1)*2;
for(uint32_t sub=1;sub<=fgCalls;++sub){
const uint32_t generatedSlot=parity+(sub-1)*2;
auto* flist=ring_.acquireNext(slot,st); if(!flist)return false;
@@ -1948,8 +1949,14 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
gpuTimer_.mark(flist,timingStage,true);if(sub==fgCalls)gpuTimer_.mark(flist,GpuStage::FgBatch,true);
tracker_.uavBarrier(flist,genFrame_[generatedSlot].Get());
tracker_.uavBarrier(flist,fgDisable_[parity].Get());
- tracker_.transition(flist,fgDisable_[parity].Get(),D3D12_RESOURCE_STATE_COPY_SOURCE);
- flist->CopyBufferRegion(fgDisableReadback_[generatedSlot].Get(),0,fgDisable_[parity].Get(),0,4);
+ // The disable flag describes the whole MFG input pair. Copy it once,
+ // after the final Evaluate, instead of issuing one readback per
+ // generated subframe. The last generated slot remains unique to this
+ // batch, so queued batches never alias their status readback.
+ if(sub==fgCalls){
+ tracker_.transition(flist,fgDisable_[parity].Get(),D3D12_RESOURCE_STATE_COPY_SOURCE);
+ flist->CopyBufferRegion(fgDisableReadback_[statusReadbackSlot].Get(),0,fgDisable_[parity].Get(),0,4);
+ }
tracker_.transition(flist,videoFrame_[parity].Get(),D3D12_RESOURCE_STATE_COMMON);
tracker_.transition(flist,genFrame_[generatedSlot].Get(),D3D12_RESOURCE_STATE_COMMON);
tracker_.transition(flist,depthTex_.Get(),D3D12_RESOURCE_STATE_COMMON);
@@ -1964,7 +1971,7 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frame
++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;f.lease->readyFenceObject=out.genFenceObject;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->statusSlot=statusReadbackSlot;f.lease->readyFence=out.genFenceValue;f.lease->readyFenceObject=out.genFenceObject;generatedLeases_[generatedSlot]=f.lease;out.batch.append(std::move(f));
}
}
}
@@ -1995,7 +2002,8 @@ bool EnhanceGraph::resolveFrame(FrameOutputs& out,uint32_t index)
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);
+ const auto statusSlot=frame.lease->statusSlot==UINT32_MAX?frame.lease->slot:frame.lease->statusSlot;
+ HRESULT hr=fgDisableReadback_[statusSlot]->Map(0,&range,&data);
if(FAILED(hr)){frame.validity=GenerationValidity::Failed;veyra::log::error("fg-status",std::format("Map hr=0x{:X}",unsigned(hr)));return true;}
const bool disabled=*static_cast<uint8_t*>(data)!=0;
const bool rejected=disabled||out.contentDuplicate;