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: batch 8 - compressed payload pool, pitch-matched capture frames, folded per-second logs, scheduler teardown order
Veyra Goal Agent8a1bb0a61f50
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex c6ec5041..d4fa73a9 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -678,7 +678,6 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,ssource::CaptureMetrics captureFlowBase{},captureFlowLast{};uint64_t rateSkippedBase=0;// Queued steps capture these locals; cancel before their destruction.- OnExit stopPresentation{[&]{liveScheduler.reset();finishReset(stop_?diagnostics::ResetOutcome::Cancelled:diagnostics::ResetOutcome::Failed);std::lock_guard lock(mutex_);if(snapshot_.sessionId==runSessionId){if(frameFlow)snapshot_.metrics.flow=frameFlow->snapshot(host100ns());activeFlow_.reset();}}};const bool injectSourceGap=options.captureReplayForTest&&GetEnvironmentVariableW(L"VEYRA_TEST_REPLAY_SOURCE_GAP",nullptr,0)>0;std::optional<Clock::time_point> sourceGapUntil;// Master media clock for file playback: the audio device clock when@@ -727,6 +726,12 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sreset=true;pendingResetCause=pipeline::ResetReason::Settings;return true;};+ // Declared LAST before the loop on purpose: it is destroyed first at+ // scope exit, so the scheduler (whose queued step/finish lambdas+ // capture the locals above by reference) is torn down before any of+ // those locals (sweep 2026-09-22 B1). Do not move declarations that+ // the lambdas reference below this line.+ OnExit stopPresentation{[&]{liveScheduler.reset();finishReset(stop_?diagnostics::ResetOutcome::Cancelled:diagnostics::ResetOutcome::Failed);std::lock_guard lock(mutex_);if(snapshot_.sessionId==runSessionId){if(frameFlow)snapshot_.metrics.flow=frameFlow->snapshot(host100ns());activeFlow_.reset();}}};while(!stop_){diagnostics::CpuStallTrace loopTrace("engine-stall",frames,45.0);collectTimings();@@ -1621,12 +1626,17 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s}loopTrace.mark("publishSnapshot");const auto gpuP95=[&](diagnostics::GpuStage stage){return gpuStageTimes[size_t(stage)].p95();};- if(Clock::now()>=nextTimingLog){const auto [retained,overwritten]=Logger::instance().frameTraceSize();+ if(veyra::log::verboseFrameLogs()&&Clock::now()>=nextTimingLog){const auto [retained,overwritten]=Logger::instance().frameTraceSize();veyra::log::info("frame-trace",std::format("retained={} capacity=8192 overwritten={} (records available in diagnostic preview)",retained,overwritten));}if(!isCapture&&Clock::now()>=nextTimingLog){const double playbackSpeedNow=[&]{std::lock_guard lock(mutex_);return snapshot_.playbackSpeed;}();+ // present-deviation / output-queue are folded into the+ // player-timing line below (sweep E5); the separate lines stay+ // available under VEYRA_VERBOSE_FRAME_LOGS for old tooling.+ const auto dashboard=frameFlow->snapshot(host100ns());+ if(veyra::log::verboseFrameLogs()){veyra::log::info("present-deviation",std::format("samples={} entryAbsP95Ms={:.3f} returnAbsP95Ms={:.3f} (one sample per actual submission; media-clock deviation, not scanout latency)",presentReturnDeviation.size(),presentEntryDeviation.p95(),presentReturnDeviation.p95()));- {const auto dashboard=frameFlow->snapshot(host100ns());veyra::log::info("output-queue",std::format("pendingFrames={} enhancementProcessingMs={:.3f} extraDelayEstimateMs={:.3f}",dashboard.pendingOutputFrames,dashboard.enhancementProcessing.mean.value_or(-1),dashboard.cpuTiming[size_t(diagnostics::CpuStage::EnhancementDelayEstimate)].mean.value_or(-1)));}- veyra::log::info("player-timing",std::format("revision={} decodeP95Ms={:.3f} graphSubmitP95Ms={:.3f} gpuReadyP95Ms={:.3f} presentP95Ms={:.3f} gpuColorP95Ms={:.3f} gpuSrP95Ms={:.3f} gpuFlowP95Ms={:.3f} gpuNrP95Ms={:.3f} gpuResidualP95Ms={:.3f} gpuFgBatchP95Ms={:.3f} gpuBlitP95Ms={:.3f} slotWaits={} slotWaitMs={:.3f} commandSubmits={} displaySubmits={} expiredGenerated={} previewSkipped={} playbackSpeed={:.3f} processed={}",options.settings.revision,decodeTimes.p95(),processTimes.p95(),liveScheduler?completed.readyP95:gpuReadyTimes.p95(),presentP95,gpuP95(diagnostics::GpuStage::Color),gpuP95(diagnostics::GpuStage::Sr),gpuP95(diagnostics::GpuStage::Flow),gpuP95(diagnostics::GpuStage::Nr),gpuP95(diagnostics::GpuStage::Residual),gpuP95(diagnostics::GpuStage::FgBatch),gpuP95(diagnostics::GpuStage::Blit),slotWaitCount,slotWaitMilliseconds,commandSubmits,submitted,expired,measured.flow.counters.previewSkippedBeforeGraph,playbackSpeedNow,sourceFrames-statsSourceBase));nextTimingLog=Clock::now()+std::chrono::seconds(1);}+ veyra::log::info("output-queue",std::format("pendingFrames={} enhancementProcessingMs={:.3f} extraDelayEstimateMs={:.3f}",dashboard.pendingOutputFrames,dashboard.enhancementProcessing.mean.value_or(-1),dashboard.cpuTiming[size_t(diagnostics::CpuStage::EnhancementDelayEstimate)].mean.value_or(-1)));}+ veyra::log::info("player-timing",std::format("revision={} decodeP95Ms={:.3f} graphSubmitP95Ms={:.3f} gpuReadyP95Ms={:.3f} presentP95Ms={:.3f} gpuColorP95Ms={:.3f} gpuSrP95Ms={:.3f} gpuFlowP95Ms={:.3f} gpuNrP95Ms={:.3f} gpuResidualP95Ms={:.3f} gpuFgBatchP95Ms={:.3f} gpuBlitP95Ms={:.3f} slotWaits={} slotWaitMs={:.3f} commandSubmits={} displaySubmits={} expiredGenerated={} previewSkipped={} playbackSpeed={:.3f} processed={} entryAbsP95Ms={:.3f} returnAbsP95Ms={:.3f} pendingFrames={} enhancementProcessingMs={:.3f}",options.settings.revision,decodeTimes.p95(),processTimes.p95(),liveScheduler?completed.readyP95:gpuReadyTimes.p95(),presentP95,gpuP95(diagnostics::GpuStage::Color),gpuP95(diagnostics::GpuStage::Sr),gpuP95(diagnostics::GpuStage::Flow),gpuP95(diagnostics::GpuStage::Nr),gpuP95(diagnostics::GpuStage::Residual),gpuP95(diagnostics::GpuStage::FgBatch),gpuP95(diagnostics::GpuStage::Blit),slotWaitCount,slotWaitMilliseconds,commandSubmits,submitted,expired,measured.flow.counters.previewSkippedBeforeGraph,playbackSpeedNow,sourceFrames-statsSourceBase,presentEntryDeviation.p95(),presentReturnDeviation.p95(),dashboard.pendingOutputFrames,dashboard.enhancementProcessing.mean.value_or(-1)));nextTimingLog=Clock::now()+std::chrono::seconds(1);}if(isCapture&&Clock::now()>=nextTimingLog){logFrameFlow(measured.flow,"active");const auto rates=snapshot();diff --git a/src/pipeline/EnhanceGraph.cpp b/src/pipeline/EnhanceGraph.cppindex 3413e494..d4d045a5 100644--- a/src/pipeline/EnhanceGraph.cpp+++ b/src/pipeline/EnhanceGraph.cpp@@ -1511,8 +1511,15 @@ bool EnhanceGraph::process(const AVFrame* frame, double ptsMs, bool reset, Frameveyra::log::error("color","Invalid native YUV plane or row stride");return false;}}- for(unsigned plane=0;plane<2;++plane)for(unsigned y=0;y<rows[plane];++y)- std::memcpy(planes[plane]+size_t(y)*strides[plane],frame->data[plane]+ptrdiff_t(y)*frame->linesize[plane],rowBytes[plane]);+ for(unsigned plane=0;plane<2;++plane){+ // Capture frames are allocated with the upload pitch: copy the+ // whole plane in one streaming memcpy (all but the last row's+ // padding is a superset of rowBytes).+ if(frame->linesize[plane]==int(strides[plane])&&rows[plane]>1)+ std::memcpy(planes[plane],frame->data[plane],size_t(strides[plane])*(rows[plane]-1)+rowBytes[plane]);+ else for(unsigned y=0;y<rows[plane];++y)+ std::memcpy(planes[plane]+size_t(y)*strides[plane],frame->data[plane]+ptrdiff_t(y)*frame->linesize[plane],rowBytes[plane]);+ }}else{nv12Ctx_ = sws_getCachedContext(nv12Ctx_, frame->width, frame->height,static_cast<AVPixelFormat>(frame->format),diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cppindex 2d765295..bd51b3b5 100644--- a/src/source/CaptureCardSource.cpp+++ b/src/source/CaptureCardSource.cpp@@ -299,6 +299,12 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {// and swaps it into the mailbox once a frame is ready.struct CompressedSample{std::vector<uint8_t> payload;double time=0;Clock::time_point arrival;REFERENCE_TIME start=0,end=0;bool completeTime=false,bad=false,reset=false;};std::deque<CompressedSample> compressedQueue;size_t compressedQueueLimit=3;+ // Recycled payload buffers: the callback used to allocate a fresh vector+ // per sample under the mailbox lock (MJPEG 4K = several MB); the worker+ // returns the buffer after decode (sweep 2026-09-22 C4).+ std::vector<std::vector<uint8_t>> payloadPool;+ std::vector<uint8_t> takePayload(){if(payloadPool.empty())return {};auto v=std::move(payloadPool.back());payloadPool.pop_back();v.clear();return v;}+ void returnPayload(std::vector<uint8_t>&& v){if(payloadPool.size()<8){v.clear();payloadPool.push_back(std::move(v));}}std::thread decodeThread;std::condition_variable decodeWake;bool decodeStop=false;AVFrame* workerFrame=nullptr;uint64_t compressedDropped=0;double lastCallbackTime=0;// NV12 frames the decode worker may write into. A frame enters this pool@@ -341,6 +347,7 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {if(!draining){metadata.push_back(stamp);if(metadata.size()>64)metadata.pop_front();}const bool produced=compressedDecoder.decode(draining?nullptr:sample.payload.data(),draining?0:sample.payload.size(),int64_t(sample.time*1e7),target,&decodedFrame,hardware);+ if(!draining&&sample.payload.capacity()){std::lock_guard lock(mutex);returnPayload(std::move(sample.payload));}if(!produced){draining=false;// A decoder that needs more input before it can emit a frame is@@ -444,11 +451,12 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {// payload; the decode worker produces the NV12 frame.const auto* payload=reinterpret_cast<const uint8_t*>(data);const size_t bytes=size_t(sample->GetActualDataLength());- CompressedSample entry;entry.payload.assign(payload,payload+bytes);+ CompressedSample entry;entry.payload=takePayload();entry.payload.assign(payload,payload+bytes);if(compressedQueue.size()>=compressedQueueLimit){- if(codec==CaptureCodec::Mjpeg){compressedQueue.pop_front();++compressedDropped;++dropped;entry.bad=true;}+ if(codec==CaptureCodec::Mjpeg){returnPayload(std::move(compressedQueue.front().payload));compressedQueue.pop_front();++compressedDropped;++dropped;entry.bad=true;}else{compressedDropped+=compressedQueue.size();dropped+=compressedQueue.size();+ for(auto& queued:compressedQueue)returnPayload(std::move(queued.payload));compressedQueue.clear();entry.reset=true;entry.bad=true;log::warn("capture-decode","compressed queue overflow: discard damaged history and recover at keyframe");}@@ -819,7 +827,9 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();error_.clefor(auto** f:{&p.frame,&p.pendingFrame,&p.stagingFrame}){*f=av_frame_alloc();if(!*f)return false;(*f)->format=p.layout.format;(*f)->width=p.info.width;(*f)->height=p.info.height;- if(av_frame_get_buffer(*f,32)<0)return false;+ // 256-byte row alignment matches the graph's D3D12 upload pitch, so+ // the ingest copy is one memcpy per plane instead of one per row.+ if(av_frame_get_buffer(*f,256)<0)return false;}p.stagingBusy=false;if(!p.frameEvent)p.frameEvent=CreateEventW(nullptr,FALSE,FALSE,nullptr);@@ -1286,7 +1296,7 @@ void CaptureCardSource::close()noexcept{if(p.audioSession)p.audioSession->stop();p.audioError.clear();if(p.audioPassthrough)p.audioPassthrough->close();p.events.Reset();p.control.Reset();p.grab.Reset();p.nullFilter.Reset();p.grabFilter.Reset();p.audioSink.Reset();p.audioFilter.Reset();p.config.Reset();p.device.Reset();p.builder.Reset();p.graph.Reset();p.referenceClock.Reset();p.audioSession.reset();p.audioPassthrough.reset();- if(p.decodeThread.joinable()){{std::lock_guard lock(p.mutex);p.decodeStop=true;p.compressedQueue.clear();}p.decodeWake.notify_all();p.decodeThread.join();}+ if(p.decodeThread.joinable()){{std::lock_guard lock(p.mutex);p.decodeStop=true;p.compressedQueue.clear();p.payloadPool.clear();}p.decodeWake.notify_all();p.decodeThread.join();}if(p.workerFrame)av_frame_free(&p.workerFrame);for(auto*& frame:p.compressedFree)if(frame)av_frame_free(&frame);p.compressedFree.clear();