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

feat(xess): port the burst pacing hook, and fix the silent 2X fallback

Veyra Goal Agentef016ba9c278
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37d83439..50d2f370 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -77,6 +77,7 @@ add_library(veyra_gfx STATIC
src/gfx/PresentSink.cpp
src/gfx/XessPresenter.cpp
src/gfx/XessMfgUnlock.cpp
+ src/gfx/XessPacing.cpp
src/gfx/FsrFgPresenter.cpp
src/gfx/FsrSrBackend.cpp
)
diff --git a/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md b/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
index b6846f44..884e3a34 100644
--- a/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
+++ b/docs/FRAMEGEN_FSR_DOLBY_STATUS_2026-09-16.md
@@ -82,7 +82,7 @@ $env:VEYRA_TEST_FG_FORCE_MULTIPLIER='1'
| 项 | 状态 | 说明 / 下一步 |
| --- | --- | --- |
-| XeSS 节奏 hook(A-2) | **未移植(移植计划已细化)** | 上游 `XeFGPacing.h` RVA/算法逐项核实完毕,见 [XeSS 节奏移植计划](XESS_PACING_PORT_PLAN_2026-09-16.md):只移植核心调度调用(present thunk `0x25C0` + 调度器 `0x21EE30`),先不移植时间戳/截止时间层。>2X 的生成帧间距仍标注**未验证** |
+| XeSS 节奏 hook(A-2) | **已移植并实测(`9dd…`:见提交记录)** | present thunk `0x25C0` 接管 + 提供方调度器 `0x21EE30`,只在 >2X 安装、退出回滚。4K/30fps 素材 4X 实测:`refused=0`、同 burst 内间距 mean≈**8.303ms**(目标 33.33/4=8.33ms)、min≈8.14ms、max≈8.42ms,339 真实 / 1005 生成、exit 0;关掉 hook 的对照里 4X 完全没有调度发生。**未移植**:上游时间戳/截止时间层与墙钟回退。顺带修掉 XeSS 2X 静默退回原生呈现的 bug(现在 280 真实 / 276 生成) |
| 40 系 DLSS MFG 解锁(C-2) | **已实现并提交(`9179449`)** | 移植 `ImDreamt/MFGAdaUnlock-RenoDx`(MIT):两处 `0x1b0` 架构比较改写、PTX 中点修正(注入 temporal 参数 + 104 处 0.5 替换 + fatbin 截断逼 JIT)、8 个 `dlfg_kernel` 槽位重定向,全程进程内、可回滚。本机结构扫描与 `--apply-test` 全部通过(gates=2/descriptors=8/ptx=99362/midpoints=104;`applied=1 readBack=1 restored=1`),50 系 6X 完全不受影响。**行为未验证**:3X/4X 是否真出运动帧、Ada 缺硬件 flip metering 是否冻结,需要 40 系实机 |
| 30 系原生 2X(D) | **决策:不移植无许可证的上游,改用 FSR 补帧** | `dlssg_for_sm86` 无许可证 → 项目规则禁止复制;它本质是把 DLSSG 代理成 FSR3 补帧,而 Veyra 自己的 FSR 帧生成(E)已经能提供同样的 2X 且厂商无关。详见 [30 系补帧决策](DLSSG_30SERIES_DECISION_2026-09-16.md)。**未验证**:FSR 补帧在 RTX 30 实机上能否运行 |
| FSR 帧生成(E) | **已完成并实测(2X)** | 见上文 §一.5 与 [接入记录](FSR_FRAMEGEN_INTEGRATION_2026-09-16.md);4.0.1 ML 需 AMD 卡复测 |
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index d78298a0..b2593860 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -2349,6 +2349,41 @@ DLSSG 能力门控没有排除 FSR,导致 FSR 会话下任何就地设置变
### 2026-09-16 采集音频改为可手动指定(用户反馈自动识别不好用)
+### 2026-09-16 XeSS 节奏 hook(A-2)移植 + 用 4K/30fps 素材实测
+
+移植 `Coldwood1026/OptiScaler`(GPL-3.0,`70676c5f`)`XeFGPacing.h` 的**核心调度调用**到
+`include/veyra/gfx/XessPacing.h` + `src/gfx/XessPacing.cpp`(present thunk `0x25C0` 用既有
+`ThunkHook` 接管,返回地址过滤 `0x2202ED`/`0x220467`,把循环里的生成帧交给提供方自己的调度器
+`0x21EE30`,参数 `gate=burst[0xC0]&1` + ring 快照 `0x224CF0(ctx+0x168)`)。
+安装前三处 thunk 的目标逐一校验(present→`0x21F730`、sched→`0x21EE30`、ring→`0x224CF0`),
+不匹配就拒绝;只在 >2X 会话安装,退出时 `ThunkHook::remove()` 原字节恢复。
+
+测试素材:用户指定的 `GTAVI_An_Extended_Look_4K_Native.mp4`(4K / 30fps)。
+
+**4X 实测(`logs/fsr/xess4x-final.log`)**:
+
+- `[xess-pacing] installed for 4X: present thunk hooked, scheduler wired`;
+- 提供方调度器在线(日志里 `ctx+0x340=0 ctx+0x341=1`),`refused=0` → 每次调用都真的执行,
+ 不是"打进去但被门控空转";
+- **同一 burst 内生成帧间距 mean=8.303–8.306ms、min≈8.14–8.19、max≈8.37–8.42**,
+ 而 30fps 4X 的目标间距是 33.33/4 = **8.33ms** → 间距由提供方自己的调度器给出并与目标吻合;
+- 339 真实帧 / 1005 生成帧(≈3×,即 4X)、exit 0、30.00fps 播放、无丢帧;
+- 退出:`unlock rolled back 5/5`,`xess-pacing removed (scheduled=… refused=0 bypassed=0)`。
+
+**对照(`VEYRA_DISABLE_XESS_PACING=1`,`logs/fsr/xess4x-unpaced.log`)**:4X 仍然每真实帧出 4 帧,
+但**没有任何调度发生**(无 scheduling 日志)——中间帧不带呈现时间,就是修复前的状态。
+这个对照只能证明"有没有调度",修复前的观感数字(一串挤一起)来自上游分析,不作为本机实测。
+
+**顺带修掉一个真 bug**:`XessPresenter` 原先对 2X 也走解锁路径,而解锁在"无需解锁"时返回
+`applied=false`,被当成失败 → **XeSS 2X 会静默退回原生呈现(等于没补帧)**。现在 >1 才解锁,
+2X 走提供方原生 2X:实测 `Create result=0`、`maxInterpolations=1 => 2X`、280 真实 / 276 生成、
+exit 0(`logs/fsr/xess2x-fixed.log`)。
+
+回归:delivery 短测 PASS(`logs/delivery/05331f9d7c294b03b190dd8aeed19936/result.json`)、
+`veyra_repair_contract_tests` 165 项 0 失败。
+
+**未移植**:上游的时间戳/截止时间层(`0x3430`/`0x7A30`)与墙钟回退;当前只做核心调度调用。
+
用户反馈"自动识别并不好用",要求在采集面板里像 HDR 那样手动选。已加:
- 采集面板新增下拉框「采集音频(变更需重连)」:**自动**(优先线性 PCM,PCM 不可用时位流解码)、
diff --git a/include/veyra/gfx/XessPacing.h b/include/veyra/gfx/XessPacing.h
new file mode 100644
index 00000000..94aa38b2
--- /dev/null
+++ b/include/veyra/gfx/XessPacing.h
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <windows.h>
+
+#include <cstdint>
+#include <string>
+
+namespace veyra::gfx {
+
+// Spreads Intel's generated frames out in time above 2X.
+//
+// Ported from Coldwood1026/OptiScaler (GPL-3.0, commit
+// 70676c5f037c8c26f1ec355b250a72303cd268da, OptiScaler/proxies/XeFGPacing.h) and
+// reduced to the part that fixes the actual defect: the provider schedules only
+// the last frame of a burst, so at 3X/4X the intermediate ones are presented
+// back to back and read as a clump followed by a gap.
+//
+// The provider already knows the correct spacing - it computes
+// "real frame duration / multiplier" once per burst - but only ever hands the
+// last generated frame to its own scheduler. This port intercepts the present
+// thunk, recognises the two call sites that present generated frames, and hands
+// the loop's frames to the provider's own scheduler with the arguments the
+// present already carries (burst, frame index, gate byte, ring snapshot).
+// Everything else is forwarded untouched.
+//
+// Provider identity and structure are verified before the thunk is touched; a
+// mismatch refuses the hook instead of guessing, and release() restores the
+// original bytes exactly. 2X never installs anything.
+class XessPacing {
+public:
+ // libxess_fg.dll 1.3.1.78 (same audited build as XessMfgUnlock).
+ static constexpr uint64_t kKnownProviderSize = 22957432ull;
+ static constexpr const char* kKnownProviderSha256 =
+ "EC5E0C65E075570C6EDE72618BB666D0BE0C2E10B2EA9762C0FE8CB8E375AB27";
+ static constexpr uint32_t kKnownTimeDateStamp = 0x69CB0F4Du;
+ static constexpr uint32_t kKnownSizeOfImage = 0x015ED000u;
+ // Provider internals (verified against the audited build before hooking).
+ static constexpr uint32_t kPresentThunkRva = 0x25C0;
+ static constexpr uint32_t kNativePresentRva = 0x21F730;
+ static constexpr uint32_t kSchedThunkRva = 0x3100;
+ static constexpr uint32_t kSchedFnRva = 0x21EE30;
+ static constexpr uint32_t kRingSnapshotThunkRva = 0x4DA0;
+ static constexpr uint32_t kRingSnapshotFnRva = 0x224CF0;
+ static constexpr uint32_t kPacedCallerRva = 0x2202ED;
+ static constexpr uint32_t kLastFrameCallerRva = 0x220467;
+ static constexpr uint32_t kBurstGateOffset = 0xC0;
+ static constexpr uint32_t kSchedLimiterOffset = 0x340;
+ static constexpr uint32_t kSchedEnableOffset = 0x341;
+ static constexpr uint32_t kRingOffset = 0x168;
+
+ struct State {
+ bool providerLoaded = false;
+ bool structureVerified = false; // thunks and RVAs match the audited build
+ bool installed = false; // present thunk redirected
+ uint32_t generatedFrames = 0; // requested (1 = 2X, no hook needed)
+ uint64_t scheduled = 0; // frames handed to the provider scheduler
+ uint64_t refused = 0; // scheduler said no (its own gate)
+ uint64_t forwarded = 0; // presents left untouched
+ uint64_t bypassed = 0; // frames skipped because the scheduler was off
+ // Measured spacing between two consecutive scheduled frames.
+ double meanGapMs = 0.0, minGapMs = 0.0, maxGapMs = 0.0;
+ uint64_t gapSamples = 0;
+ std::wstring detail;
+ };
+
+ // Installs the hook when the session really asks for more than one generated
+ // frame. Anything that does not match the audited provider refuses.
+ static State install(HMODULE provider, uint32_t generatedFrames);
+ static void release();
+ static State snapshot();
+ static bool installed();
+ // Read-only identity check, mirroring XessMfgUnlock::providerIsAudited.
+ static bool providerIsAudited(const std::wstring& path);
+};
+
+} // namespace veyra::gfx
diff --git a/src/gfx/XessPacing.cpp b/src/gfx/XessPacing.cpp
new file mode 100644
index 00000000..ed0942a7
--- /dev/null
+++ b/src/gfx/XessPacing.cpp
@@ -0,0 +1,306 @@
+#include "veyra/gfx/XessPacing.h"
+
+#include "veyra/Log.h"
+#include "veyra/ThunkHook.h"
+
+#include <algorithm>
+#include <cstring>
+#include <filesystem>
+#include <intrin.h>
+#include <mutex>
+
+namespace veyra::gfx {
+namespace {
+
+// Provider signatures. The present is a member function: `this` in rcx plus six
+// arguments, two of which arrive on the stack.
+using PresentFn = int64_t (*)(void*, uint32_t, uint32_t, uint64_t, void*, void*, uint64_t);
+// The provider's own frame scheduler and its ring snapshot helper.
+using SchedFn = bool (*)(void*, void*, uint8_t, void*, uint32_t);
+using RingSnapshotFn = void* (*)(void*, void*);
+
+struct PacingState {
+ std::mutex mutex;
+ ThunkHook hook;
+ bool installed = false;
+ uint8_t* base = nullptr;
+ PresentFn native = nullptr;
+ SchedFn sched = nullptr;
+ RingSnapshotFn ringSnapshot = nullptr;
+ uint32_t generatedFrames = 0;
+ // Counters, written only from the provider's present thread.
+ uint64_t scheduled = 0, refused = 0, forwarded = 0, bypassed = 0;
+ LARGE_INTEGER frequency{};
+ int64_t lastScheduledQpc = 0;
+ uint64_t lastScheduledIndex = 0;
+ uint64_t lastScheduledCount = 0;
+ int64_t gapSum = 0, gapMin = 0, gapMax = 0;
+ uint64_t gapSamples = 0;
+ // Gaps that cross a burst boundary include the real frame the provider
+ // presents itself, so they are counted but not mixed into the in-burst
+ // spacing that shows whether the fix worked.
+ uint64_t boundaryGaps = 0;
+ int64_t statsDeadlineQpc = 0;
+ int64_t lastMultiplier = 0;
+ int32_t logBudget = 6;
+};
+
+PacingState& state() {
+ static PacingState instance;
+ return instance;
+}
+
+double msFromQpc(const PacingState& s, int64_t qpc) {
+ return s.frequency.QuadPart > 0 ? (double(qpc) * 1000.0) / double(s.frequency.QuadPart) : 0.0;
+}
+
+std::string narrow(const std::wstring& value) {
+ if (value.empty()) return {};
+ const int length = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), int(value.size()), nullptr, 0, nullptr, nullptr);
+ if (length <= 0) return {};
+ std::string text(size_t(length), '\0');
+ WideCharToMultiByte(CP_UTF8, 0, value.c_str(), int(value.size()), text.data(), length, nullptr, nullptr);
+ return text;
+}
+
+// The provider's scheduler is only live when its limiter is off; calling it
+// while the limiter owns the pacing is a silent no-op, which would look like a
+// successful fix while changing nothing.
+bool schedulerUsable(void* ctx) {
+ const auto* bytes = static_cast<const uint8_t*>(ctx);
+ return bytes[XessPacing::kSchedLimiterOffset] == 0 && bytes[XessPacing::kSchedEnableOffset] != 0;
+}
+
+// One schedule call per generated frame, mirroring the provider's own order:
+// snapshot the ring first, then schedule. Every argument is in hand because we
+// sit inside the present call the provider itself made.
+void scheduleFrame(void* ctx, uint8_t* burst, uint64_t index) {
+ auto& s = state();
+ if (s.sched == nullptr || s.ringSnapshot == nullptr) return;
+ alignas(16) uint8_t timing[0x20]{};
+ s.ringSnapshot(reinterpret_cast<uint8_t*>(ctx) + XessPacing::kRingOffset, timing);
+ const uint8_t gate = burst[XessPacing::kBurstGateOffset] & 1;
+ const uint64_t count = *reinterpret_cast<uint64_t*>(burst + 8);
+
+ LARGE_INTEGER before{}, after{};
+ QueryPerformanceCounter(&before);
+ const bool ok = s.sched(ctx, burst, gate, timing, static_cast<uint32_t>(index));
+ QueryPerformanceCounter(&after);
+
+ ++s.scheduled;
+ if (!ok) ++s.refused;
+
+ const bool sameBurst = s.lastScheduledQpc != 0 && count == s.lastScheduledCount && index == s.lastScheduledIndex + 1;
+ if (s.lastScheduledQpc != 0 && !sameBurst) ++s.boundaryGaps;
+ if (sameBurst) {
+ const int64_t gap = after.QuadPart - s.lastScheduledQpc;
+ s.gapSum += gap;
+ s.gapMin = s.gapSamples == 0 ? gap : (std::min)(s.gapMin, gap);
+ s.gapMax = (std::max)(s.gapMax, gap);
+ ++s.gapSamples;
+ }
+ s.lastScheduledQpc = after.QuadPart;
+ s.lastScheduledIndex = index;
+ s.lastScheduledCount = count;
+ s.lastMultiplier = static_cast<int64_t>(count) + 1;
+
+ // Bounded logging: the schedule must be visible going out, but this runs on
+ // the present thread.
+ if (s.logBudget > 0 && index == 1) {
+ --s.logBudget;
+ log::info("xess-pacing", std::format("frame {}/{} -> {} in {:.3f} ms (ctx+0x340={} ctx+0x341={} ring samples={} median={})",
+ index, count + 1, ok ? "scheduled" : "REFUSED",
+ msFromQpc(s, after.QuadPart - before.QuadPart),
+ reinterpret_cast<uint8_t*>(ctx)[XessPacing::kSchedLimiterOffset],
+ reinterpret_cast<uint8_t*>(ctx)[XessPacing::kSchedEnableOffset],
+ *reinterpret_cast<uint64_t*>(timing),
+ *reinterpret_cast<uint64_t*>(timing + 8)));
+ }
+ if (s.statsDeadlineQpc != 0 && after.QuadPart >= s.statsDeadlineQpc && s.gapSamples > 0) {
+ // The measured gap is the only direct evidence that frames really come
+ // out spread; report it instead of claiming the intent.
+ log::info("xess-pacing", std::format("multiplier={}X scheduled={} refused={} bypassed={} forwarded={} inBurstGaps={} mean={:.3f}ms min={:.3f}ms max={:.3f}ms burstBoundaries={}",
+ s.lastMultiplier, s.scheduled, s.refused, s.bypassed, s.forwarded,
+ s.gapSamples, msFromQpc(s, s.gapSum / int64_t(s.gapSamples)),
+ msFromQpc(s, s.gapMin), msFromQpc(s, s.gapMax), s.boundaryGaps));
+ s.gapSum = 0; s.gapSamples = 0; s.gapMin = 0; s.gapMax = 0;
+ s.statsDeadlineQpc = after.QuadPart + (s.frequency.QuadPart * 2);
+ }
+}
+
+// Only the two call sites that present *generated* frames are paced; the other
+// presenters of this thunk are forwarded byte-for-byte untouched.
+void tryPace(void* ctx, void* arg5, void* arg6, uint64_t arg7, bool isLast) {
+ if (arg5 == nullptr) return;
+ const uint8_t flag = static_cast<uint8_t>(arg7);
+ if ((flag == 1) == isLast) return;
+ auto* burst = reinterpret_cast<uint8_t*>(arg5) - 0x38;
+ const uint64_t count = *reinterpret_cast<uint64_t*>(burst + 8);
+ if (count < 1 || count > 5) return;
+ uint64_t index = count;
+ if (!isLast) {
+ auto* frames = *reinterpret_cast<uint8_t**>(burst);
+ if (frames == nullptr || reinterpret_cast<uint8_t*>(arg6) < frames) return;
+ const uint64_t offset = reinterpret_cast<uint8_t*>(arg6) - frames;
+ if ((offset % 8) != 0) return;
+ index = offset / 8;
+ if (index < 1 || index >= count) return;
+ }
+ auto& s = state();
+ if (s.sched != nullptr && schedulerUsable(ctx)) {
+ // The provider keeps the last frame of the burst; scheduling it twice
+ // would put two timestamps on one frame.
+ if (!isLast) scheduleFrame(ctx, burst, index);
+ return;
+ }
+ // Limiter owns the pacing: the provider already waits for the last frame,
+ // and nothing here pretends to have paced the intermediate ones.
+ ++s.bypassed;
+}
+
+int64_t detour(void* ctx, uint32_t a2, uint32_t a3, uint64_t a4, void* arg5, void* arg6, uint64_t arg7) {
+ auto& s = state();
+ if (s.installed) {
+ auto* caller = static_cast<uint8_t*>(_ReturnAddress());
+ if (caller == s.base + XessPacing::kPacedCallerRva) tryPace(ctx, arg5, arg6, arg7, false);
+ else if (caller == s.base + XessPacing::kLastFrameCallerRva) tryPace(ctx, arg5, arg6, arg7, true);
+ else ++s.forwarded;
+ }
+ return s.native(ctx, a2, a3, a4, arg5, arg6, arg7);
+}
+
+// A thunk is `E9 rel32` followed by 0xCC padding; the rel32 must reach
+// `expectedTarget`. Anything else means this is not the build the RVAs were
+// derived from, and the hook refuses.
+bool thunkTargets(const uint8_t* base, uint32_t rva, uint32_t expectedTargetRva) {
+ const uint8_t* thunk = base + rva;
+ if (thunk[0] != 0xE9) return false;
+ int32_t displacement = 0;
+ std::memcpy(&displacement, thunk + 1, sizeof(displacement));
+ const auto target = reinterpret_cast<uintptr_t>(thunk) + 5 + displacement;
+ return target == reinterpret_cast<uintptr_t>(base + expectedTargetRva);
+}
+
+} // namespace
+
+XessPacing::State XessPacing::install(HMODULE provider, uint32_t generatedFrames) {
+ auto& s = state();
+ std::lock_guard lock(s.mutex);
+ State result{};
+ result.generatedFrames = generatedFrames;
+ if (provider == nullptr) {
+ result.detail = L"no provider module";
+ return result;
+ }
+ result.providerLoaded = true;
+ if (generatedFrames < 2) {
+ result.detail = L"2X: pacing is not needed (the provider presents one generated frame per real frame)";
+ return result;
+ }
+ if (s.installed) {
+ result = snapshot();
+ return result;
+ }
+ auto* base = reinterpret_cast<uint8_t*>(provider);
+ const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(base);
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE) {
+ result.detail = L"provider is not a PE image";
+ return result;
+ }
+ const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS64*>(base + dos->e_lfanew);
+ if (nt->Signature != IMAGE_NT_SIGNATURE || nt->OptionalHeader.SizeOfImage != kKnownSizeOfImage ||
+ nt->FileHeader.TimeDateStamp != kKnownTimeDateStamp) {
+ result.detail = L"provider build does not match the audited identity";
+ return result;
+ }
+ // All three thunks must point where the port expects, in this exact build.
+ const bool presentOk = thunkTargets(base, kPresentThunkRva, kNativePresentRva);
+ const bool schedOk = thunkTargets(base, kSchedThunkRva, kSchedFnRva);
+ const bool ringOk = thunkTargets(base, kRingSnapshotThunkRva, kRingSnapshotFnRva);
+ if (!presentOk || !schedOk || !ringOk) {
+ result.detail = std::format(L"thunk verification failed (present={} scheduler={} ring={})",
+ presentOk ? 1 : 0, schedOk ? 1 : 0, ringOk ? 1 : 0);
+ return result;
+ }
+ result.structureVerified = true;
+ QueryPerformanceFrequency(&s.frequency);
+ s.base = base;
+ s.sched = reinterpret_cast<SchedFn>(base + kSchedFnRva);
+ s.ringSnapshot = reinterpret_cast<RingSnapshotFn>(base + kRingSnapshotFnRva);
+ s.generatedFrames = generatedFrames;
+ s.scheduled = s.refused = s.forwarded = s.bypassed = 0;
+ s.lastScheduledQpc = 0;
+ s.gapSum = s.gapSamples = 0;
+ s.gapMin = s.gapMax = 0;
+ s.lastMultiplier = 0;
+ s.logBudget = 6;
+ s.statsDeadlineQpc = s.frequency.QuadPart > 0 ? 0 : 0;
+ auto status = s.hook.install(base + kPresentThunkRva, reinterpret_cast<void*>(&detour), 11);
+ if (!status.installed) {
+ s.sched = nullptr;
+ s.ringSnapshot = nullptr;
+ result.detail = std::format(L"thunk hook refused: {}", std::wstring(status.error.begin(), status.error.end()));
+ return result;
+ }
+ s.native = reinterpret_cast<PresentFn>(status.trampoline != nullptr ? status.trampoline : base + kNativePresentRva);
+ s.installed = true;
+ // Arm the periodic stats window only once frame times are being measured.
+ LARGE_INTEGER now{};
+ QueryPerformanceCounter(&now);
+ s.statsDeadlineQpc = now.QuadPart + (s.frequency.QuadPart * 2);
+ result.installed = true;
+ result.detail = std::format(L"present thunk {} hooked, scheduler at +0x{:X} (original target +0x{:X})",
+ kPresentThunkRva, kSchedFnRva, kNativePresentRva);
+ log::info("xess-pacing", std::format("installed for {}X: present thunk hooked, scheduler wired, {}",
+ generatedFrames + 1, narrow(result.detail)));
+ return result;
+}
+
+void XessPacing::release() {
+ auto& s = state();
+ std::lock_guard lock(s.mutex);
+ if (!s.installed) return;
+ s.installed = false;
+ (void)s.hook.remove();
+ s.native = nullptr;
+ s.sched = nullptr;
+ s.ringSnapshot = nullptr;
+ log::info("xess-pacing", std::format("removed (scheduled={} refused={} bypassed={} forwarded={})",
+ s.scheduled, s.refused, s.bypassed, s.forwarded));
+}
+
+XessPacing::State XessPacing::snapshot() {
+ auto& s = state();
+ std::lock_guard lock(s.mutex);
+ State result{};
+ result.providerLoaded = s.base != nullptr;
+ result.structureVerified = s.sched != nullptr;
+ result.installed = s.installed;
+ result.generatedFrames = s.generatedFrames;
+ result.scheduled = s.scheduled;
+ result.refused = s.refused;
+ result.forwarded = s.forwarded;
+ result.bypassed = s.bypassed;
+ result.gapSamples = s.gapSamples;
+ if (s.gapSamples > 0) {
+ result.meanGapMs = msFromQpc(s, s.gapSum / int64_t(s.gapSamples));
+ result.minGapMs = msFromQpc(s, s.gapMin);
+ result.maxGapMs = msFromQpc(s, s.gapMax);
+ }
+ return result;
+}
+
+bool XessPacing::installed() {
+ auto& s = state();
+ std::lock_guard lock(s.mutex);
+ return s.installed;
+}
+
+bool XessPacing::providerIsAudited(const std::wstring& path) {
+ std::error_code ec;
+ const auto size = std::filesystem::file_size(path, ec);
+ if (ec || size != kKnownProviderSize) return false;
+ return true;
+}
+
+} // namespace veyra::gfx
diff --git a/src/gfx/XessPresenter.cpp b/src/gfx/XessPresenter.cpp
index 37a57b5f..beeef7bb 100644
--- a/src/gfx/XessPresenter.cpp
+++ b/src/gfx/XessPresenter.cpp
@@ -2,11 +2,24 @@
#include "veyra/Log.h"
#include "veyra/RuntimePaths.h"
#include "veyra/gfx/XessMfgUnlock.h"
+#include "veyra/gfx/XessPacing.h"
#ifdef VEYRA_HAS_XESS
#include <xess_fg/xefg_swapchain_d3d12.h>
#include <xell/xell_d3d12.h>
#endif
+namespace {
+// Local wide->narrow for log lines (the presenter's detail strings are wide).
+std::string narrowDetail(const std::wstring& value){
+ if(value.empty())return {};
+ const int length=WideCharToMultiByte(CP_UTF8,0,value.c_str(),int(value.size()),nullptr,0,nullptr,nullptr);
+ if(length<=0)return {};
+ std::string text(size_t(length),'\0');
+ WideCharToMultiByte(CP_UTF8,0,value.c_str(),int(value.size()),text.data(),length,nullptr,nullptr);
+ return text;
+}
+}
+
namespace veyra::gfx {
struct XessPresenter::Impl {
uint64_t generated=0,presented=0;
@@ -47,6 +60,9 @@ struct XessPresenter::Impl {
if(ll&&xellDestroyContextFn)check(xellDestroyContextFn(ll),"XeLL destroy",true);
// Restore the provider bytes only after every XeFG/XeLL context is gone.
XessMfgUnlock::release();
+ // Same rule for the pacing thunk: the present hook is removed before the
+ // provider module is released.
+ XessPacing::release();
if(fgDll)FreeLibrary(fgDll);if(llDll)FreeLibrary(llDll);
}
#endif
@@ -87,7 +103,10 @@ bool XessPresenter::initialize(ID3D12Device* device,ID3D12CommandQueue* queue,ID
// Multi-frame generation needs the audited OptiScaler unlock before the
// first XeFG context exists; 2X deliberately leaves the provider untouched.
p.requestedGenerated=fgMultiplier>1?fgMultiplier-1:0;
- if(p.requestedGenerated>0){
+ // 2X is the provider's stock behaviour: no unlock, no pacing, and the
+ // presenter must not treat "nothing to unlock" as a failure (that used to
+ // drop the whole XeSS session back to native presentation).
+ if(p.requestedGenerated>1){
const auto unlock=XessMfgUnlock::apply(p.fgDll,p.requestedGenerated);
p.maxInterpolations=unlock.maxInterpolations;
veyra::log::info("xess-mfg",std::format("unlock requestedGenerated={} applied={} identityVerified={} recognisedBuild={}",
@@ -96,6 +115,16 @@ bool XessPresenter::initialize(ID3D12Device* device,ID3D12CommandQueue* queue,ID
log::error("xess-mfg",std::format("unlock unavailable for {}X request; keeping stock presentation",p.requestedGenerated+1));
return false;
}
+ // Above 2X the provider presents a burst of generated frames back to
+ // back; hand its intermediate frames to its own frame scheduler.
+ if(GetEnvironmentVariableW(L"VEYRA_DISABLE_XESS_PACING",nullptr,0)==0){
+ const auto pacing=XessPacing::install(p.fgDll,p.requestedGenerated);
+ log::info("xess-pacing",std::format("install requestedGenerated={} installed={} structureVerified={} detail={}",
+ p.requestedGenerated,pacing.installed,pacing.structureVerified,
+ narrowDetail(pacing.detail)));
+ }else{
+ log::warn("xess-pacing","disabled by VEYRA_DISABLE_XESS_PACING (diagnostic only)");
+ }
}
if(!p.check(p.xellD3D12CreateContextFn(device,&p.ll),"XeLL create",true)||!p.check(p.xefgSwapChainD3D12CreateContextFn(device,&p.fg),"Create",true))return false;
if(!p.check(p.xefgSwapChainSetLatencyReductionFn(p.fg,p.ll),"Attach XeLL",true))return false;