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++
Video-memory watchdog rebuilds the swapchain, then the graph, and logs what each frees
Veyra Goal Agent165680ddeb64
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex dc51ef19..e6959f27 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -643,10 +643,18 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sauto nextTimingLog=Clock::now()+std::chrono::seconds(1);// Video memory watchdog. A field log (RTX 5060 Ti, 2026-10-01) grew +3 GB a minute while// fullscreen, kept it after leaving fullscreen, and every pass slowed down once usage- // passed the budget (5 fps). Unreproduced here; the log line names what else was loaded.- uint64_t vramFloor=0,vramRevision=~0ull;auto vramSettleUntil=Clock::now();bool vramWarned=false;- // VEYRA_TEST_VRAM_LEAK_MIB=n: hold on to n MiB more of video memory every second.+ // passed the budget (5 fps). Unreproduced here. On growth beyond max(2 GiB, budget/4)+ // with no settings change the log names every third-party module, and the loop+ // rebuilds first the presentation swapchain, then (if that released less than half)+ // the processing graph too, logging what each released: the swapchain step points+ // at the driver or an overlay hooked on it, the graph step at our own passes.+ uint64_t vramFloor=0,vramRevision=~0ull,vramRecoverBefore=0,vramRecoverGrowth=0;auto vramSettleUntil=Clock::now(),vramRecoverCheckAt=Clock::now();+ bool vramWarned=false;int vramRecoverStep=0,vramRecoverDone=0,vramRecoveries=0;+ // VEYRA_TEST_VRAM_LEAK_MIB=n: hold on to n MiB more of video memory every second;+ // VEYRA_TEST_VRAM_LEAK_RELEASE=1 lets the swapchain rebuild free it (as a leak tied+ // to the swapchain would), otherwise nothing frees it.const uint64_t testLeakMiB=[]{wchar_t v[16]{};return GetEnvironmentVariableW(L"VEYRA_TEST_VRAM_LEAK_MIB",v,16)?uint64_t(_wtoi(v)):0ull;}();+ const bool testLeakReleases=GetEnvironmentVariableW(L"VEYRA_TEST_VRAM_LEAK_RELEASE",nullptr,0)>0;std::vector<Microsoft::WRL::ComPtr<ID3D12Resource>> testLeak;auto watchVram=[&](uint64_t usage,uint64_t budget){if(testLeakMiB){@@ -656,15 +664,34 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(SUCCEEDED(ctx.device()->CreateCommittedResource(&heap,D3D12_HEAP_FLAG_NONE,&desc,D3D12_RESOURCE_STATE_COMMON,nullptr,IID_PPV_ARGS(&r))))testLeak.push_back(r);}if(!usage)return;+ if(vramRecoverDone){+ if(Clock::now()<vramRecoverCheckAt)return;+ const int64_t released=(int64_t(vramRecoverBefore)-int64_t(usage))/(1<<20);+ veyra::log::warn("vram-watch",std::format("{} rebuild released {} MiB of {} MiB growth (before {} MiB, now {} MiB)",+ vramRecoverDone==1?"swapchain":"graph+swapchain",released,vramRecoverGrowth>>20,vramRecoverBefore>>20,usage>>20));+ // The graph is rebuilt only with room for it: a rebuild that runs out of budget+ // stops the session, which is worse than running slowly.+ if(vramRecoverDone==1&&released<int64_t(vramRecoverGrowth>>21)){+ if(budget&&usage<budget/100*85)vramRecoverStep=2;+ else veyra::log::warn("vram-watch","graph rebuild skipped: too close to the budget to rebuild safely");+ }+ vramRecoverDone=0;vramFloor=0;vramSettleUntil=Clock::now()+std::chrono::seconds(5);+ return;+ }+ if(vramRecoverStep)return;if(options.settings.revision!=vramRevision){vramRevision=options.settings.revision;vramFloor=0;vramSettleUntil=Clock::now()+std::chrono::seconds(10);}if(Clock::now()<vramSettleUntil)return;if(!vramFloor||usage<vramFloor)vramFloor=usage;const uint64_t growth=usage-vramFloor,limit=std::max<uint64_t>(2048ull<<20,budget/4);- if(vramWarned||growth<=limit)return;- vramWarned=true;- veyra::log::warn("vram-watch",std::format("video memory grew {} MiB with no settings change (now {} of {} MiB budget); third-party modules: {}",- growth>>20,usage>>20,budget>>20,gfx::thirdPartyModules()));- std::lock_guard lock(mutex_);snapshot_.vramRunawayMiB=growth>>20;+ if(growth<=limit)return;+ if(!vramWarned){+ vramWarned=true;+ veyra::log::warn("vram-watch",std::format("video memory grew {} MiB with no settings change (now {} of {} MiB budget); third-party modules: {}",+ growth>>20,usage>>20,budget>>20,gfx::thirdPartyModules()));+ std::lock_guard lock(mutex_);snapshot_.vramRunawayMiB=growth>>20;+ }else veyra::log::warn("vram-watch",std::format("video memory grew {} MiB again (now {} MiB)",growth>>20,usage>>20));+ if(vramRecoveries<3){++vramRecoveries;vramRecoverStep=1;vramRecoverGrowth=growth;}+ else{vramFloor=usage;} // give up rebuilding; report again only on further growth};auto anchor=Clock::now(),statsStart=anchor;double anchorMs=0;uint64_t frames=0,sourceFrames=0;bool wasPaused=false;double discardBefore=0;double lastAudioClockMs=0;bool audioClockExhausted=false;auto audioTailAnchor=anchor;@@ -1274,6 +1301,19 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(!graph.initialize(gd)||!presenter.open(ctx,window,graph,options.settings.captureCompatible,!isCapture&&!isImage)||!graph.createViews()){status(L"串流尺寸切换失败",true);break;}reset=true;pendingResetCause=pipeline::ResetReason::Resize;}+ if(vramRecoverStep){+ // Video memory watchdog (see watchVram): rebuild between frames, measure later.+ const int step=vramRecoverStep;vramRecoverStep=0;+ drainLivePresentation();if(!ring.drainQueue()){status(L"显存回收时排空失败",true);break;}+ uint64_t budget=0;ctx.videoMemoryInfo(budget,vramRecoverBefore);+ veyra::log::warn("vram-watch",std::format("rebuilding the {} to release video memory (usage {} MiB)",step==1?"presentation swapchain":"processing graph and swapchain",vramRecoverBefore>>20));+ presenter.close();+ if(step==2){graph.shutdown();out={};hasOutput=false;}+ if(step==1&&testLeakReleases)testLeak.clear();+ if((step==2&&!graph.initialize(gd))||!presenter.open(ctx,window,graph,options.settings.captureCompatible,!isCapture&&!isImage)||(step==2&&!graph.createViews())){status(L"显存回收后重建失败,请重新打开片源",true);break;}+ reset=true;pendingResetCause=pipeline::ResetReason::Resize;+ vramRecoverDone=step;vramRecoverCheckAt=Clock::now()+std::chrono::seconds(3);+ }const bool rereadCached=transaction&&frame==cachedFrame;if(!isImage&&!isCapture&&seekSeconds_>=0)continue;const bool halfRate=isCapture&&options.settings.content==ContentRate::Capture60To30&&diff --git a/src/ui/QmlPlayerBridge.cpp b/src/ui/QmlPlayerBridge.cppindex 7cf10331..82ac44d3 100644--- a/src/ui/QmlPlayerBridge.cpp+++ b/src/ui/QmlPlayerBridge.cpp@@ -794,9 +794,9 @@ QmlPlayerBridge::QmlPlayerBridge(engine::EngineController& engine, std::filesystif(impl_->poll()){emit settingsChanged();emit chainChanged();}if (impl_->snapshot.vramRunawayMiB && impl_->vramNoticeSession != impl_->snapshot.sessionId) {impl_->vramNoticeSession = impl_->snapshot.sessionId;- emit notice(tr("显存在设置没变的情况下涨了 %1 GB,继续下去会越来越卡。常见原因是游戏加加、小飞机(RTSS)、"- "显卡叠加层/即时重放或录屏软件在全屏时注入了本程序:请关掉它们的游戏内显示后重开本软件。"- "当时加载的第三方模块已写进日志(vram-watch)")+ emit notice(tr("显存在设置没变的情况下涨了 %1 GB,已自动重建显示链回收显存(画面会闪一下)。"+ "如果反复出现:常见原因是 NVIDIA Smooth Motion、游戏加加、小飞机(RTSS)、显卡叠加层/即时重放"+ "或录屏软件在全屏时注入了本程序,请关掉它们后再试,并把日志发给我们(vram-watch)").arg(impl_->snapshot.vramRunawayMiB / 1024.0, 0, 'f', 1), true);}tickSubtitles();@@ -883,6 +883,9 @@ QmlPlayerBridge::QmlPlayerBridge(engine::EngineController& engine, std::filesyst{L"graphics-hook64.dll", "OBS game capture"}, {L"DiscordHook64.dll", "Discord overlay"},{L"gameoverlayrenderer64.dll", "Steam overlay"}, {L"nvspcap64.dll", "NVIDIA overlay / instant replay"},{L"ow-graphics-hook64.dll", "Overwolf overlay"},+ // The driver's presentation layer; it carries NVIDIA Smooth Motion, which only+ // engages for fullscreen windows (suspected in the fullscreen-only VRAM growth).+ {L"NvPresent64.dll", "NVIDIA present layer (Smooth Motion)"},};static bool loggedOthers[std::size(others)]{};for (size_t k = 0; k < std::size(others); ++k)@@ -891,7 +894,7 @@ QmlPlayerBridge::QmlPlayerBridge(engine::EngineController& engine, std::filesystveyra::log::info("overlay-hooks", std::format("{} is injected into this process", others[k].product));}static bool handled = false;- if (const auto* hook = gfx::injectedPresentationHook(); hook && !handled) {+ if (const auto* hook = gfx::xessBlockingHook(); hook && !handled) {handled = true;veyra::log::warn("overlay-hooks", std::format("{} is injected into this process ({}); XeSS frame generation is ""kept off while it is present", hook->product, QString::fromWCharArray(hook->module).toStdString()));@@ -1187,7 +1190,7 @@ void QmlPlayerBridge::setFgBackendName(const QString& value) {return;}if (want == engine::FrameGenerationBackend::XeSS) {- if (const auto* hook = gfx::injectedPresentationHook()) {+ if (const auto* hook = gfx::xessBlockingHook()) {emit notice(tr("检测到 %1 正在注入本程序,它和 XeSS 补帧一起用会导致闪退,已保持原来的补帧方式。""关掉它的帧数显示后可以用 XeSS;不关也可以用 DLSS 或 FSR 补帧").arg(QString::fromUtf8(hook->product)), true);emit settingsChanged();