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

fix(capture): keep Qt presentation outside native OBS swapchain rebuild

Veyra Goal Agentcc7f5a37b980
diff --git a/apps/veyra-qml/main.cpp b/apps/veyra-qml/main.cpp
index 4f6462ff..3c017c4d 100644
--- a/apps/veyra-qml/main.cpp
+++ b/apps/veyra-qml/main.cpp
@@ -20,6 +20,7 @@
#include <QQmlContext>
#include <QQuickItem>
#include <QQuickWindow>
+#include "veyra/gfx/ObsQtFrameGate.h"
#include <QSGRendererInterface>
#include <QKeyEvent>
#include <QTimer>
@@ -756,6 +757,18 @@ static int runApplication(int argc, char** argv, QString& restartProgram, QStrin
return 1;
}
if (testSize.isValid()) window->resize(testSize);
+ if(!softwareUi){
+ auto windows=window->findChildren<QQuickWindow*>();windows.prepend(window);
+ for(auto* quick:windows){
+ auto gate=veyra::gfx::registerObsQtFrameGate();
+ QObject::connect(quick,&QQuickWindow::beforeFrameBegin,quick,[gate]{
+ gate->beginFrame(GetModuleHandleW(L"graphics-hook64.dll")!=nullptr);
+ },Qt::DirectConnection);
+ QObject::connect(quick,&QQuickWindow::afterFrameEnd,quick,[gate]{gate->endFrame();},Qt::DirectConnection);
+ QObject::connect(quick,&QQuickWindow::sceneGraphInvalidated,quick,[gate]{gate->endFrame();},Qt::DirectConnection);
+ }
+ veyra::log::info("qml-window",std::format("OBS resize frame gates registered windows={}",windows.size()));
+ }
// Fullscreen must own the whole monitor. Without telling the shell, the taskbar
// stayed above the fullscreen picture on some systems (field report with the
diff --git a/include/veyra/gfx/ObsQtFrameGate.h b/include/veyra/gfx/ObsQtFrameGate.h
new file mode 100644
index 00000000..089ca645
--- /dev/null
+++ b/include/veyra/gfx/ObsQtFrameGate.h
@@ -0,0 +1,53 @@
+#pragma once
+#include <memory>
+#include <mutex>
+#include <vector>
+
+namespace veyra::gfx {
+// OBS 32.1.2 dxgi-capture.cpp clears process-wide capture state at the start
+// of ANY ResizeBuffers. Qt and the native video must not race to Present
+// during that call. Each Qt window keeps its own gate (no UI/UI lock order).
+class ObsQtFrameGate {
+public:
+ void beginFrame(bool hookActive) {
+ if(hookActive&&!held_){mutex_.lock();held_=true;}
+ }
+ void endFrame() {
+ if(held_){held_=false;mutex_.unlock();}
+ }
+ std::mutex& mutex(){return mutex_;}
+private:
+ std::mutex mutex_;
+ bool held_=false; // accessed only by this window's render thread
+};
+inline std::mutex obsQtRegistryMutex;
+inline std::vector<std::weak_ptr<ObsQtFrameGate>> obsQtFrameGates;
+inline std::shared_ptr<ObsQtFrameGate> registerObsQtFrameGate(){
+ auto gate=std::make_shared<ObsQtFrameGate>();
+ const std::lock_guard lock(obsQtRegistryMutex);
+ std::erase_if(obsQtFrameGates,[](const auto& existing){return existing.expired();});
+ obsQtFrameGates.push_back(gate);
+ return gate;
+}
+class ObsNativeResizeHold {
+public:
+ ObsNativeResizeHold(){
+ {
+ const std::lock_guard lock(obsQtRegistryMutex);
+ for(auto& entry:obsQtFrameGates)if(auto gate=entry.lock())gates_.push_back(std::move(gate));
+ }
+ for(auto& gate:gates_){
+ locks_.emplace_back(gate->mutex(),std::try_to_lock);
+ if(!locks_.back().owns_lock()){
+ locks_.clear();ready_=false;break;
+ }
+ }
+ }
+ bool ready()const{return ready_;}
+ size_t windows()const{return gates_.size();}
+private:
+ std::vector<std::shared_ptr<ObsQtFrameGate>> gates_;
+ std::vector<std::unique_lock<std::mutex>> locks_;
+ bool ready_=true;
+};
+}
diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cpp
index bd38b54f..09942bba 100644
--- a/src/engine/VideoPresenter.cpp
+++ b/src/engine/VideoPresenter.cpp
@@ -3,6 +3,7 @@
#include "veyra/pipeline/EnhanceGraph.h"
#include "veyra/gfx/D3D12DeviceContext.h"
#include "veyra/gfx/CommandSlotRing.h"
+#include "veyra/gfx/ObsQtFrameGate.h"
#include "veyra/sink/ImageExportSink.h"
namespace veyra::engine {
bool VideoPresenter::beginSourceInput(){
@@ -137,7 +138,14 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&
SUCCEEDED(ctx.device()->GetDeviceRemovedReason())&&
!GetEnvironmentVariableW(L"VEYRA_TEST_DISABLE_PAUSED_PRESENT_REUSE",nullptr,0))return true;
retainedFrame_.reset(); // A failed present never seeds an idle cache.
- if(!windowChanging&&(targetWidth!=sink_.width()||targetHeight!=sink_.height())&&GetTickCount64()>=deferUntil&&now-lastResize_>=std::chrono::milliseconds(100)&&sink_.resizeDue()) {
+ bool resizeReady=!windowChanging&&(targetWidth!=sink_.width()||targetHeight!=sink_.height())&&GetTickCount64()>=deferUntil&&now-lastResize_>=std::chrono::milliseconds(100)&&sink_.resizeDue();
+ std::optional<gfx::ObsNativeResizeHold> captureResizeHold;
+ if(resizeReady&&GetModuleHandleW(L"graphics-hook64.dll")){
+ captureResizeHold.emplace();resizeReady=captureResizeHold->ready();
+ if(!resizeReady)captureResizeHold.reset(); // no native wait; retry next frame
+ else veyra::log::info("capture-resize",std::format("exclusive native resize target={}x{} qtWindows={}",targetWidth,targetHeight,captureResizeHold->windows()));
+ }
+ if(resizeReady) {
resized=true;
if(!ring.drainQueue())return false;sink_.resize(targetWidth,targetHeight);
// A capture hook may temporarily retain a DXGI buffer. Keep the old