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

latency-min C1: report the monitor's variable-refresh state (NVIDIA)

Veyra Goal Agentdca66de35f40
diff --git a/docs/LATENCY_MIN_PLAN_2026-10-13.md b/docs/LATENCY_MIN_PLAN_2026-10-13.md
index 96e5b355..b2fabdf6 100644
--- a/docs/LATENCY_MIN_PLAN_2026-10-13.md
+++ b/docs/LATENCY_MIN_PLAN_2026-10-13.md
@@ -28,7 +28,7 @@
| **B1 XeSS“提交即送显”**(已实施) | XeSS 时读帧→处理→立即打标签并 Present,不再由调度器等 GPU 完成后才送;一个 XeLL 周期内完成 睡眠→读输入→提交→送显;XeSS 也遵守“GPU 未完成不读下一帧” | 去掉 CPU 等 GPU 的时间和轮询抖动;XeLL 周期对齐 | 屏幕采集 XeSS 2X:周期错位 922/960→0,回调→送显 P95 3.8→3.0ms;采集卡+NR 实测待设备上线 |
| **B2 补帧输出预算**(已实施) | 内容帧率×倍数 > 1.02×刷新率时:DLSS/FSR/VFG 自动降到能放下的最大合法倍数;放不下但源比屏幕慢(60fps@100Hz)保留 2X(仍多出画面);源已占满屏幕(≥0.97×刷新,如 60Hz 屏 + 60fps 源)旁路补帧,真帧直接显示、不等插帧;XeSS 只做 SetEnabled(false) 旁路;新决定持续 1.5 秒才生效,状态栏说明原因 | 不浪费 GPU、动作均匀;60Hz+60fps 时延迟等于仅 NR | 实测:DLSS 6X@320Hz→4X,送显→上屏 6.2/8.0→5.0/6.9ms,垂直同步 12.2/18.4→5.7/8.5ms;模拟 60Hz 旁路回调→送显 8.8ms=仅 NR;30fps+2X@60Hz 保持 2X |
| **B3 “垂直同步”也不排队**(已实施) | 只有显式垂直同步节流:启用时清掉可等待对象积累的计数并放行一帧;直播未补帧时在读采集帧之前取得屏幕容量,每次送显前也取得容量(插帧最多等 ≤2ms 否则让给下一帧);自动/撕裂永不等待;“低延迟队列”=只保留一帧在处理 + 未补帧时 Reflex;XeSS 代理不设最大延迟(Intel:XeLL 以外的延迟手段不受支持) | 垂直同步模式下的排队上限 1 帧 | 回放 6X 超刷新:送显→上屏 18.4→5.8ms;探针源快 5%:7.3→2.5 个刷新;常规配置无回退;采集卡实测待设备上线 |
-| **C1 VRR 研究** | 用户在驱动开启 G-SYNC/FreeSync 后,实测“自动”是否触发可变刷新;若不触发,评估“垂直同步 + B2 输出预算(输出始终低于最高刷新)”的 VRR 模式(不会撕裂) | 少等 0–1 个刷新(60Hz 平均约 8ms) | 需用户开启 VRR;对比送显→上屏 |
+| **C1 VRR 研究**(检测已实施) | 用户在驱动开启 G-SYNC/FreeSync 后,实测“自动”是否触发可变刷新;若不触发,评估“垂直同步 + B2 输出预算(输出始终低于最高刷新)”的 VRR 模式(不会撕裂) | 少等 0–1 个刷新(60Hz 平均约 8ms) | 已加 NVAPI 状态检测、日志与状态栏;本机显示器 possible=false 无法实测,需用户在支持的屏幕上开启后对比 |
| **C2 独立翻转确认** | 用 PresentMon(需管理员)确认全屏/窗口的呈现模式;窗口合成会多 1 个刷新 | 明确“全屏更低”的条件或修掉窗口合成 | PresentMon PresentMode 列 |
| **C3 采集拷贝** | 4K NV12 回调拷贝约 1.5ms,研究直接以驱动缓冲上传 | ≤1.5ms | 回调耗时日志 |
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 254b9359..f86e603d 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -9383,3 +9383,9 @@ v2.0.7 ID 410800361,published_at 2026-10-12T16:24:59Z,latest/非草稿/非
改动:XeSS 呈现器与图共用同一个直接队列,真帧提交后立刻打标签并 Present(GPU 顺序保证在增强之后执行),每次循环就是一个完整 XeLL 周期:睡眠→读帧→提交→送显;XeSS 也遵守“GPU 未完成不读下一帧”(等完再从邮箱取最新帧)。GPU 就绪耗时改由完成轮询记录(从任务创建到观察到完成),统计口径不再是“作业等待”。XessPresenter 日志新增 cycleMismatches(送显的源帧不在本周期准备的次数)。测试开关:`VEYRA_TEST_XESS_PRESENT_AFTER_READY=1` 恢复等 GPU 后送显,`VEYRA_TEST_XESS_STACKED_READS=1` 恢复叠读。
验证(采集卡离线,用屏幕采集直播链路 screen-xess,30fps 源,XeSS 2X,320Hz,测量窗口内):cycleMismatches 旧 922/960 → 新 0/960;回调→送显 P95 3.8→3.0ms;SDK 提交 56→58/s,补帧照常;测试断言 10/10 通过。屏幕采集负载很轻(无 NR),带 NR 的采集卡实测收益待设备上线。
+
+## 2026-10-14 极限低延迟 C1 可变刷新(VRR)检测(Claude)
+
+新增 `include/veyra/gfx/NvidiaVrr.h`:按 ReflexSession 同样的规则只从 System32 加载并常驻 nvapi64.dll,用公开 nvapi(MIT,本地 deps/nvapi-pacing 头文件核对函数 ID 与 NV_GET_VRR_INFO_V1 布局)查询窗口所在显示器的 G-SYNC / G-SYNC Compatible 状态;随刷新率每 2 秒或换屏时重读,变化时写 `display-vrr` 日志;快照 `displayVrr`(0 未知/非 NVIDIA、1 不支持、2 支持未开启、3 已开启、4 生效中),状态栏追加“可变刷新生效中/已开启/屏幕支持可变刷新(未开启)”并补翻译。Veyra 不修改驱动设置。
+
+本机结果:320Hz 显示器 known=true status=0 possible=false(当前连接/设置下不能开 VRR),因此本机无法实测 VRR 对“自动”的效果。用户指引:显示器支持 G-SYNC / FreeSync 时,在 NVIDIA 控制面板“设置 G-SYNC”中开启并选择“为窗口和全屏模式启用”,Veyra 显示同步保持“自动”;VRR 生效后屏幕按帧到达刷新(不超过最高刷新),省掉 0–1 个刷新的等待。多数显示器在 PBP/画中画模式下会关闭 VRR。
diff --git a/i18n/catalog.json b/i18n/catalog.json
index 9c252d53..692ce1e9 100644
--- a/i18n/catalog.json
+++ b/i18n/catalog.json
@@ -15828,6 +15828,27 @@
"zh-TW": "顯示同步:自動",
"en": "Display sync: auto",
"ja": "表示の同期:自動"
+ },
+ {
+ "zh": "可变刷新生效中",
+ "src": "src/ui/QmlPlayerBridge.cpp",
+ "zh-TW": "可變更新生效中",
+ "en": "Variable refresh active",
+ "ja": "可変リフレッシュ動作中"
+ },
+ {
+ "zh": "可变刷新已开启",
+ "src": "src/ui/QmlPlayerBridge.cpp",
+ "zh-TW": "可變更新已開啟",
+ "en": "Variable refresh enabled",
+ "ja": "可変リフレッシュ有効"
+ },
+ {
+ "zh": "屏幕支持可变刷新(未开启)",
+ "src": "src/ui/QmlPlayerBridge.cpp",
+ "zh-TW": "螢幕支援可變更新(未開啟)",
+ "en": "Display supports variable refresh (off)",
+ "ja": "画面は可変リフレッシュに対応(無効)"
}
]
}
diff --git a/include/veyra/engine/EngineController.h b/include/veyra/engine/EngineController.h
index 56e4b33a..526cab5a 100644
--- a/include/veyra/engine/EngineController.h
+++ b/include/veyra/engine/EngineController.h
@@ -125,6 +125,9 @@ struct PlayerSnapshot {
bool displayFgLimited=false;
unsigned displayFgMultiplier=0;
double displayFgRefreshHz=0,displayFgContentFps=0;
+ // Variable refresh of the presenting monitor (NVIDIA only): 0 unknown,
+ // 1 not possible, 2 possible but off, 3 enabled in the driver, 4 active.
+ unsigned displayVrr=0;
// Runtime-reported DLSSG MultiFrameCountMax: 1 = 2X only, 5 = 6X.
// 0 = not queried yet (no session). The UI uses this to offer only the
// multipliers the active GPU can actually honour.
diff --git a/include/veyra/engine/VideoPresenter.h b/include/veyra/engine/VideoPresenter.h
index 6231c545..3d4e5937 100644
--- a/include/veyra/engine/VideoPresenter.h
+++ b/include/veyra/engine/VideoPresenter.h
@@ -7,6 +7,7 @@
#include "veyra/engine/HdrOutputTuning.h"
#include "veyra/gfx/CommandSlotRing.h"
#include "veyra/gfx/ReflexSession.h"
+#include "veyra/gfx/NvidiaVrr.h"
#include "veyra/engine/PresentationSettings.h"
#include <chrono>
#include <array>
@@ -71,6 +72,8 @@ public:
// only at creation; the window may move to another monitor or the mode
// may change, so it is re-read on a monitor change and every 2 s.
double displayRefreshHz();
+ // Variable refresh state of that monitor (NVIDIA only), re-read with it.
+ gfx::VrrState displayVrr()const{return vrr_;}
diagnostics::GpuSample blitTiming(ID3D12Fence* f,uint64_t revision=0,uint64_t epoch=0){gpuTimer_.collect(presentationFence_?presentationFence_.Get():f);if((revision&&gpuTimer_.last().identity.settingsRevision!=revision)||(epoch&&gpuTimer_.last().identity.epoch!=epoch)){diagnostics::GpuSample pending;pending.state=diagnostics::SampleState::Pending;return pending;}return gpuTimer_.last().gpu[size_t(diagnostics::GpuStage::Blit)];}
// Application-side frame-generation timing for present-sink backends
// (XeSS): the copies, barriers and provider prepare work recorded on
@@ -140,7 +143,7 @@ private:
bool xessWasEnabled_=false;
bool xessFailed_=false;
bool xessGenerationSuppressed_=false;
- HMONITOR refreshMonitor_=nullptr;double refreshHz_=0;
+ HMONITOR refreshMonitor_=nullptr;double refreshHz_=0;gfx::VrrState vrr_{};bool refreshQueried_=false;
std::chrono::steady_clock::time_point refreshQuery_{};
uint32_t xessInputId_=0;
struct XessWork {pipeline::FrameIdentity identity{};uint32_t id=0;};
diff --git a/include/veyra/gfx/NvidiaVrr.h b/include/veyra/gfx/NvidiaVrr.h
new file mode 100644
index 00000000..b5e12005
--- /dev/null
+++ b/include/veyra/gfx/NvidiaVrr.h
@@ -0,0 +1,62 @@
+#pragma once
+#include <windows.h>
+#include <cstdint>
+#include <mutex>
+#include <string>
+namespace veyra::gfx {
+// Variable refresh (G-SYNC / G-SYNC Compatible) state of the monitor showing
+// a window, for diagnostics and the status line. Veyra never changes it; the
+// user enables it in the NVIDIA Control Panel.
+// Minimal ABI declarations checked against NVIDIA/nvapi public interfaces
+// (nvapi_interface.h function IDs, NV_GET_VRR_INFO_V1 layout), MIT; same
+// source and loading rules as ReflexSession: System32 nvapi64.dll only, pinned
+// for the life of the process. No SDK header or runtime is distributed.
+struct VrrState {
+ bool known=false; // NVIDIA driver answered for this monitor
+ bool possible=false; // the display can run VRR with the current mode/connection
+ bool requested=false; // VRR is enabled for this display in the driver
+ bool enabled=false; // VRR mode is currently active on the display
+ bool indicator=false; // the driver's VRR indicator overlay is on
+ bool inVrrMode=false; // the display itself reports VRR mode
+ int status=0; // last NvAPI status (0 = OK)
+ bool operator==(const VrrState&)const=default;
+};
+inline VrrState queryVrr(HWND window){
+ struct Info {uint32_t version;uint32_t flags;uint32_t reservedEx[4];};
+ static_assert(sizeof(Info)==24);
+ using Query=void*(__cdecl*)(uint32_t);
+ using Init=int(__cdecl*)();
+ using IdByName=int(__cdecl*)(const char*,uint32_t*);
+ using GetVrr=int(__cdecl*)(uint32_t,Info*);
+ static std::once_flag once;static IdByName idByName=nullptr;static GetVrr getVrr=nullptr;static bool ready=false;
+ std::call_once(once,[]{
+ wchar_t system[MAX_PATH]{};GetSystemDirectoryW(system,MAX_PATH);
+ const std::wstring path=std::wstring(system)+L"\\nvapi64.dll";
+ HMODULE module=LoadLibraryExW(path.c_str(),nullptr,LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if(!module)return;
+ HMODULE pinned=nullptr;GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_PIN,reinterpret_cast<LPCWSTR>(module),&pinned);
+ auto query=reinterpret_cast<Query>(GetProcAddress(module,"nvapi_QueryInterface"));
+ if(!query)return;
+ auto init=reinterpret_cast<Init>(query(0x0150E828));
+ idByName=reinterpret_cast<IdByName>(query(0xAE457190));
+ getVrr=reinterpret_cast<GetVrr>(query(0xDF8FDA57));
+ ready=init&&idByName&&getVrr&&init()==0;
+ });
+ VrrState state;
+ if(!ready||!window)return state;
+ MONITORINFOEXW monitor{};monitor.cbSize=sizeof(monitor);
+ if(!GetMonitorInfoW(MonitorFromWindow(window,MONITOR_DEFAULTTONEAREST),&monitor))return state;
+ char name[CCHDEVICENAME*2]{};
+ if(!WideCharToMultiByte(CP_ACP,0,monitor.szDevice,-1,name,int(sizeof(name)),nullptr,nullptr))return state;
+ uint32_t displayId=0;
+ state.status=idByName(name,&displayId);
+ if(state.status!=0)return state;
+ Info info{};info.version=uint32_t(sizeof(Info))|(1u<<16);
+ state.status=getVrr(displayId,&info);
+ if(state.status!=0)return state;
+ state.known=true;
+ state.enabled=info.flags&1u;state.possible=info.flags&2u;state.requested=info.flags&4u;
+ state.indicator=info.flags&8u;state.inVrrMode=info.flags&16u;
+ return state;
+}
+}
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index f7aa36e7..35dddc50 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -2556,6 +2556,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
snapshot_.previewSkipped=measured.flow.counters.previewSkippedBeforeGraph;
snapshot_.fgBudgetLimited=measured.flow.lastFgRejected100ns>0&&host100ns()-measured.flow.lastFgRejected100ns<10000000;
snapshot_.xessGenerationSuppressed=graph->xessEnabled()&&presenter.xessGenerationSuppressed()&&!fgBypassed; // budget bypass is not an overload
+ {presenter.displayRefreshHz();const auto vrr=presenter.displayVrr();snapshot_.displayVrr=!vrr.known?0u:vrr.enabled||vrr.inVrrMode?4u:vrr.requested?3u:vrr.possible?2u:1u;}
snapshot_.nrActive=graph->nrEnabled()&&graphStats.nrEvaluateCount>0;
snapshot_.nrAutoActive=graph->autoNrPoolReady();
snapshot_.nrAutoPercent=graph->autoNrPoolReady()?AutoNrController::percent(graph->autoNrLevel()):0;
diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cpp
index 697fc869..bb03f25b 100644
--- a/src/engine/VideoPresenter.cpp
+++ b/src/engine/VideoPresenter.cpp
@@ -31,7 +31,7 @@ bool VideoPresenter::open(gfx::D3D12DeviceContext& ctx,HWND window,pipeline::Enh
veyra::log::warn("present","presentation creation cancelled: target window is no longer available");
return false;
}
- viewWidth_=viewHeight_=0;bufferMonitor_=nullptr;monitorWidth_=monitorHeight_=0;refreshMonitor_=nullptr;refreshHz_=0;refreshQuery_={};
+ viewWidth_=viewHeight_=0;bufferMonitor_=nullptr;monitorWidth_=monitorHeight_=0;refreshMonitor_=nullptr;refreshHz_=0;refreshQuery_={};vrr_={};refreshQueried_=false;
++generation_;
Status st=Status::Ok;
// Keep one presentation queue for the native chain's lifetime. A later
@@ -413,7 +413,7 @@ bool VideoPresenter::readPresentedFrameForTest(gfx::D3D12DeviceContext& ctx,gfx:
void VideoPresenter::close(){
metadataSent_=false;metadataDirty_=false;lastMetadata_={};sourceMetadata_={};metadataAttempt_={};
hdrPeakMonitor_=nullptr;hdrPeakInfo_={};hdrPeakQuery_={};
- refreshMonitor_=nullptr;refreshHz_=0;refreshQuery_={};
+ refreshMonitor_=nullptr;refreshHz_=0;refreshQuery_={};vrr_={};refreshQueried_=false;
retainedFrame_.reset();
xessInputId_=0;xessWork_={};xessWorkPosition_=0;
reflex_.close();reflexFrame_=0;
@@ -432,6 +432,9 @@ double VideoPresenter::displayRefreshHz(){
const double hz=gfx::PresentSink::displayRefreshFps(window_);
if(refreshMonitor_&&std::abs(hz-refreshHz_)>0.5)veyra::log::info("display-refresh",std::format("monitor refresh={:.3f} Hz (was {:.3f}; window moved or display mode changed)",hz,refreshHz_));
refreshHz_=hz;refreshMonitor_=monitor;refreshQuery_=now;sink_.setDisplayRefreshHz(hz);
+ const auto vrr=gfx::queryVrr(window_);
+ if(!(vrr==vrr_)||!refreshQueried_)veyra::log::info("display-vrr",std::format("known={} possible={} requested={} active={} displayInVrrMode={} indicator={} status={} refreshHz={:.3f} (NVIDIA G-SYNC / G-SYNC Compatible state of the window's monitor; enabled by the user in the NVIDIA Control Panel, never changed by Veyra)",vrr.known,vrr.possible,vrr.requested,vrr.enabled,vrr.inVrrMode,vrr.indicator,vrr.status,hz));
+ vrr_=vrr;refreshQueried_=true;
}
return refreshHz_;
}
diff --git a/src/ui/QmlPlayerBridge.cpp b/src/ui/QmlPlayerBridge.cpp
index 770dfefe..fcb8c57a 100644
--- a/src/ui/QmlPlayerBridge.cpp
+++ b/src/ui/QmlPlayerBridge.cpp
@@ -6471,6 +6471,10 @@ void QmlPlayerBridge::updateRunStatus() {
const auto sync=i.presentation.display==engine::DisplaySync::Vsync?tr("垂直同步"):tr("自动显示同步");
options<<((refresh>0)?tr("%1 · 屏幕 %2 Hz").arg(sync).arg(refresh,0,'f',1):sync);
}
+ // Variable refresh (NVIDIA G-SYNC / G-SYNC Compatible), set in the driver.
+ if(s.running&&s.displayVrr==4)options<<tr("可变刷新生效中");
+ else if(s.running&&s.displayVrr==3)options<<tr("可变刷新已开启");
+ else if(s.running&&s.displayVrr==2)options<<tr("屏幕支持可变刷新(未开启)");
if(i.presentation.outputRate!=engine::OutputRateMode::Off){
if(s.running&&s.presentationEffective.outputRate==engine::OutputRateMode::Off)
options<<tr("输出限帧 · 当前未生效");