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

diagnostics: distinguish XeSS resource preparation from deadline waiting

Veyra Goal Agent512de1c8447b
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index f08b8257..9d5b76ed 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -46,6 +46,13 @@ The provider DLL on disk is never modified, re-signed or renamed; only the mappe
XeSS pacing adaptation (2026-09-19): `include/veyra/gfx/XessPacing.h` and `src/gfx/XessPacing.cpp` also adapt the above pinned OptiScaler `XeFGPacing.h` NoteFrame/PaceFrame/WaitUntil logic: a bounded 15-period median, generated-frame deadlines, and the provider-owned tail limiter condition. Veyra retains its audited call-site hooks, adds synchronized statistics and complete hooked-present-return gap measurements, and does not port upstream timestamp hooks. Provider scheduling remains preferred; wall-clock pacing is used only when its scheduler is unavailable. No on-disk runtime changes.
+XeSS read-only timing diagnostics (2026-09-21): the timestamp callback ABI and
+pinned provider locations (0x3430 / 0x224B30) were cross-checked against
+SAOG0721/Magpie commit `3841698348bfb246623d4acf791984c8b68a577b`,
+`src/Magpie.Core/XeSSFGPacing.h` (GPL-3.0). Veyra's trace-only hook records
+the native deadline without modifying it. The upstream deadline rewrite is
+not ported. The audited DLL remains unchanged on disk.
+
### Magpie NR temporal residual route (2026-09-20)
Veyra's optional `src/pipeline/NrTemporalPass.cpp` and
diff --git a/docs/FG_STABILITY_PROGRESS_2026-09-21.md b/docs/FG_STABILITY_PROGRESS_2026-09-21.md
index bddfe355..a5cc7cbf 100644
--- a/docs/FG_STABILITY_PROGRESS_2026-09-21.md
+++ b/docs/FG_STABILITY_PROGRESS_2026-09-21.md
@@ -137,6 +137,44 @@ seek or continuous-resize acceptance. Analyzer3 synthetic tests still pass.
## Next acceptance and remaining phases
+### Scheduler wait attribution follow-up
+
+Trace-only ProviderOutput now records the audited caller RVA and hook entry.
+ProviderDeadline records native timestamp-calculation completion and remaining
+deadline time without rewriting the result. QPC is converted to the native
+nanosecond domain separately from the host trace clock. ABI/RVAs were checked
+against pinned Magpie and the actual provider machine code. GPL attribution
+is in THIRD_PARTY_NOTICES.md. No runtime file was changed.
+
+Two20s source-timing-on runs in caller-on/{native-nr-xess4,sr-nr-xess4}
+show light-source60/s and heavy52.19/s. In retained heavy output transitions:
+2202ed->2202ed mean4.306ms;2202ed->220467 mean4.310ms;
+220467->220db2 mean0.228ms;220db2->2202ed mean13.020ms,
+of which12.366ms is inside the extra scheduler call. Native/light has
+5.687ms in that scheduler position, versus2.241ms tail-to-next return.
+These identify call sites, not guessed source IDs or physical image order.
+
+Important correction: the native scheduler includes a fence-completion check
+and possible event wait for index1 before computing its time deadline. It is
+NOT a pure sleep-until function. A subsequent20s heavy run with read-only
+deadline hook (deadline-on/sr-nr-xess4) separates350 retained first-index calls:
+before-deadline mean8.375ms/P95 14.272ms, after-deadline mean3.883ms,
+native deadline lead mean3.882ms. Throughput52.24/s, ageP95 39.034ms, exit0.
+The pre-deadline segment includes fence wait, lookup and CPU scheduling;
+it is not yet an isolated GPU duration. Blindly deleting it can violate
+resource readiness. Timestamp rewrite alone cannot be credited with removing
+this segment. Next isolate actual fence readiness/producer queue ownership
+before selecting a scheduling change. Do not relabel all12ms as wasted time.
+
+Build logs: logs/fg-stability-{caller,deadline}-trace-20260921.log, both exit0.
+All artifacts relative to E:/项目/Veyra/. Runs use the same matrix harness and
+media described above, --seconds20; source timing and trace enabled. Adjacent
+xess-timeline.json is generated by analyze-xess-timeline.py. Four synthetic
+tests cover gap decomposition, legacy missing fields and source joins. All
+pass. Deadline hook remains diagnostic-only; dynamic hook rebuild test still
+needed (previous switch regression predates this hook). No optimization has
+been promoted, packaged or published by this follow-up.
+
Full-run interval aggregation, sustained run and selector switches now have
evidence above. Dynamic seek/continuous-resize and visual correspondence
remain required before enabling by
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index f3f5735e..29067629 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -5808,3 +5808,18 @@ Ran ui-fg-backends.py with staged EXE, native p001.mp4, output source-timing-swi
exit0. TEMP/TMP scoped to E:/项目/Veyra/tmp/fg-stability-20260921.
test-xess-timeline.py3 tests pass; git diff --check passes. No new runtime,
delivery package, push or release. Goal remains active; P2-P6 not completed.
+
+Scheduler attribution follow-up: added caller RVA and hook-entry stamps, plus
+read-only ProviderDeadline trace behind VEYRA_TEST_TRACE_XESS. Native deadline
+unchanged; no new waiting or FG policy. Pinned upstream provenance recorded.
+Builds with existing build-isolated command exit0, logs/fg-stability-caller-trace-
+20260921.log and fg-stability-deadline-trace-20260921.log under E:/项目/Veyra.
+Sequential20s matrix runs caller-on native-nr-xess4/sr-nr-xess4 and deadline-on
+sr-nr-xess4 exit0, no smoke failure. Evidence tests/fg-stability-20260921.
+Read actual audited provider via pefile/capstone: index1 scheduler can wait
+for a fence before computing deadline. Split350 retained heavy first-index
+calls:8.375ms before deadline calculation,3.883ms after. Do not claim first
+segment is pure GPU time or remove the safety wait. Source52.24/s repeats.
+Next action changes from speculative timestamp port to fence/producer timing
+attribution. No cadence fix accepted. Analyzer4 tests pass; diff check passes.
+No package/runtime change, push or publication; goal remains active.
diff --git a/include/veyra/diagnostics/FrameTrace.h b/include/veyra/diagnostics/FrameTrace.h
index 9037e63a..0e89158c 100644
--- a/include/veyra/diagnostics/FrameTrace.h
+++ b/include/veyra/diagnostics/FrameTrace.h
@@ -5,7 +5,7 @@
#include <vector>
namespace veyra::diagnostics {
-enum class TraceKind { Submitted, Ready, Present, Gpu, Reset, Cancelled, FrameReady, Discarded, XessSleep, XessBind, XessPresent, ProviderOutput };
+enum class TraceKind { Submitted, Ready, Present, Gpu, Reset, Cancelled, FrameReady, Discarded, XessSleep, XessBind, XessPresent, ProviderOutput, ProviderDeadline };
inline const char* traceKindName(TraceKind kind) {
switch(kind){
case TraceKind::Submitted:return "Submitted";
@@ -20,6 +20,7 @@ inline const char* traceKindName(TraceKind kind) {
case TraceKind::XessBind:return "XessBind";
case TraceKind::XessPresent:return "XessPresent";
case TraceKind::ProviderOutput:return "ProviderOutput";
+ case TraceKind::ProviderDeadline:return "ProviderDeadline";
}
return "Unknown";
}
@@ -42,6 +43,8 @@ struct FrameTraceEvent {
// cycle is not a source ID; several queued sources can share it.
uint64_t providerInstance=0;
uint32_t providerCycle=0,preparationCycle=0;
+ uint32_t providerCallerRva=0;
+ int64_t providerScheduleBeginHost=0;
};
// Owned by the logger, independent of the deduplicated error history. No
// allocation, formatting or disk I/O occurs when an event is recorded.
diff --git a/scripts/acceptance/analyze-xess-timeline.py b/scripts/acceptance/analyze-xess-timeline.py
index b696f231..fa4b8d2e 100644
--- a/scripts/acceptance/analyze-xess-timeline.py
+++ b/scripts/acceptance/analyze-xess-timeline.py
@@ -25,6 +25,28 @@ def analyze(path):
key=lambda row: int(row["presentEndHost"]))
output_gaps = [(int(current["presentEndHost"]) - int(previous["presentEndHost"])) / 10000
for previous, current in zip(outputs, outputs[1:])]
+ transitions = {}
+ deadlines = [row for row in events if row["event"] == "ProviderDeadline"]
+ first_schedule_parts = {name: [] for name in ("beforeDeadlineMs", "afterDeadlineMs", "deadlineLeadMs")}
+ for output in outputs:
+ begin = int(output.get("providerScheduleBeginHost", 0))
+ end = int(output["presentBeginHost"])
+ matches = [row for row in deadlines if begin <= int(row["host"]) <= end and int(row["detail"]) == 1]
+ if begin and len(matches) == 1:
+ row = matches[0]
+ first_schedule_parts["beforeDeadlineMs"].append((int(row["host"]) - begin) / 10000)
+ first_schedule_parts["afterDeadlineMs"].append((end - int(row["host"])) / 10000)
+ first_schedule_parts["deadlineLeadMs"].append(float(row["ms"]))
+ for previous, current in zip(outputs, outputs[1:]):
+ if not int(previous.get("providerCallerRva", 0)) or not int(current.get("providerCallerRva", 0)):
+ continue
+ key = f'{int(previous["providerCallerRva"]):x}->{int(current["providerCallerRva"]):x}'
+ group = transitions.setdefault(key, {name: [] for name in ("returnGapMs", "beforeHookMs", "hookPacingMs", "nativeCallMs")})
+ group["returnGapMs"].append((int(current["presentEndHost"]) - int(previous["presentEndHost"])) / 10000)
+ if int(current.get("providerScheduleBeginHost", 0)):
+ group["beforeHookMs"].append((int(current["providerScheduleBeginHost"]) - int(previous["presentEndHost"])) / 10000)
+ group["hookPacingMs"].append((int(current["presentBeginHost"]) - int(current["providerScheduleBeginHost"])) / 10000)
+ group["nativeCallMs"].append((int(current["presentEndHost"]) - int(current["presentBeginHost"])) / 10000)
for event in events:
if not event["event"].startswith("Xess"):
continue
@@ -74,6 +96,9 @@ def analyze(path):
return dict(scope="Retained bounded CPU trace only; Present wall time includes descheduling, not GPU execution or scanout.",
overwritten=int(header[3]) if header else None, cycles=len(rows), linkedCycles=len(linked),
sdkReturnIntervalMs=distribution(output_gaps),
+ firstScheduleParts={name: distribution(values) for name, values in first_schedule_parts.items()},
+ sdkCallerTransitions={key: {name: distribution(values) for name, values in group.items()}
+ for key, group in transitions.items()},
sdkReturnGapsOver10ms=sum(gap>10 for gap in output_gaps),
sdkReturnGapsUnder1ms=sum(gap<1 for gap in output_gaps),
missingOrAmbiguousLinks=len(rows)-len(linked),
diff --git a/scripts/acceptance/test-xess-timeline.py b/scripts/acceptance/test-xess-timeline.py
index 0be7d51f..666c0cc4 100644
--- a/scripts/acceptance/test-xess-timeline.py
+++ b/scripts/acceptance/test-xess-timeline.py
@@ -29,6 +29,24 @@ def cycle(number, epoch, begin, instance=1, revision=1, app=True):
class TimelineTests(unittest.TestCase):
+ def test_output_gap_components_and_legacy_unknown(self):
+ text = cycle(1, 1, 0)
+ text += "event=ProviderOutput presentBeginHost=9000 presentEndHost=10000 providerCallerRva=1 providerScheduleBeginHost=8000\n"
+ text += "event=ProviderOutput presentBeginHost=50000 presentEndHost=60000 providerCallerRva=2 providerScheduleBeginHost=30000\n"
+ text += "event=ProviderDeadline host=40000 detail=1 count=4 ms=0.9\n"
+ text += "event=ProviderOutput presentBeginHost=69000 presentEndHost=70000\n"
+ result = timeline.analyze(Trace(text))
+ group = result["sdkCallerTransitions"]["1->2"]
+ self.assertEqual(group["returnGapMs"]["mean"], 5)
+ self.assertEqual(group["beforeHookMs"]["mean"], 2)
+ self.assertEqual(group["hookPacingMs"]["mean"], 2)
+ self.assertEqual(group["nativeCallMs"]["mean"], 1)
+ self.assertEqual(len(result["sdkCallerTransitions"]), 1)
+ self.assertEqual(result["sdkReturnIntervalMs"]["samples"], 2)
+ self.assertEqual(result["firstScheduleParts"]["beforeDeadlineMs"]["mean"], 1)
+ self.assertEqual(result["firstScheduleParts"]["afterDeadlineMs"]["mean"], 1)
+ self.assertEqual(result["firstScheduleParts"]["deadlineLeadMs"]["mean"], 0.9)
+
def test_epoch_boundary_included(self):
result = timeline.analyze(Trace(cycle(1, 1, 0) + cycle(2, 1, 160000) + cycle(3, 2, 620000)))
self.assertEqual(result["sourcePresentIntervalMs"]["mean"], 31)
diff --git a/src/base/Log.cpp b/src/base/Log.cpp
index c14379ae..ce847aa9 100644
--- a/src/base/Log.cpp
+++ b/src/base/Log.cpp
@@ -180,7 +180,8 @@ std::string Logger::diagnosticReport(){std::ostringstream o;o<<"Veyra 本地诊
<<" presentBeginHost="<<e.presentBeginHost<<" presentEndHost="<<e.presentEndHost
<<" entryDeviationMs="<<e.entryDeviationMs<<" returnDeviationMs="<<e.returnDeviationMs
<<" queueDepth="<<e.queueDepth<<" mediaDeviationValid="<<e.mediaDeviationValid
- <<" providerInstance="<<e.providerInstance<<" providerCycle="<<e.providerCycle<<" preparationCycle="<<e.preparationCycle<<'\n';
+ <<" providerInstance="<<e.providerInstance<<" providerCycle="<<e.providerCycle<<" preparationCycle="<<e.preparationCycle
+ <<" providerCallerRva="<<e.providerCallerRva<<" providerScheduleBeginHost="<<e.providerScheduleBeginHost<<'\n';
return diagnostics::redact(o.str());
}
void Logger::flush()
diff --git a/src/gfx/XessPacing.cpp b/src/gfx/XessPacing.cpp
index 1aebb957..946d3657 100644
--- a/src/gfx/XessPacing.cpp
+++ b/src/gfx/XessPacing.cpp
@@ -20,6 +20,9 @@ using PresentFn = int64_t (*)(void*, uint32_t, uint32_t, uint64_t, void*, void*,
// 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*);
+using TimestampFn = void* (*)(void*, int64_t*, void*, void*, uint32_t, uint32_t);
+// Same pinned provider locations documented by Magpie 3841698348bfb246.
+constexpr uint32_t timestampThunkRva=0x3430,timestampFnRva=0x224B30;
struct OutputIntervals {
// Quarter-millisecond bins, with a separate overflow bin at 250ms.
@@ -48,6 +51,8 @@ struct PacingState {
std::mutex mutex;
std::mutex statsMutex;
ThunkHook hook;
+ ThunkHook timestampHook;
+ TimestampFn timestampNative=nullptr;
bool installed = false;
const bool traceEnabled=GetEnvironmentVariableW(L"VEYRA_TEST_TRACE_XESS",nullptr,0)>0;
uint8_t* base = nullptr;
@@ -106,6 +111,23 @@ std::string narrow(const std::wstring& value) {
return text;
}
+void* traceDeadline(void* ctx,int64_t* out,void* lookup,void* timing,uint32_t index,uint32_t count) {
+ auto& s=state();
+ void* result=s.timestampNative(ctx,out,lookup,timing,index,count);
+ LARGE_INTEGER now{};QueryPerformanceCounter(&now);
+ diagnostics::FrameTraceEvent event;event.kind=diagnostics::TraceKind::ProviderDeadline;
+ event.host100ns=std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()/100;
+ event.detail=index;event.count=count;
+ // Audited native scheduler uses QPC converted to nanoseconds, not host100ns.
+ const auto frequency=s.frequency.QuadPart;
+ if(out&&frequency>0){
+ const auto ns=(now.QuadPart/frequency)*1000000000LL+(now.QuadPart%frequency)*1000000000LL/frequency;
+ event.milliseconds=double(*out-ns)/1000000.0;
+ }
+ Logger::instance().recordFrame(event);
+ return result;
+}
+
// 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.
@@ -238,19 +260,23 @@ void tryPace(void* ctx, void* arg5, void* arg6, uint64_t arg7, bool isLast) {
int64_t detour(void* ctx, uint32_t a2, uint32_t a3, uint64_t a4, void* arg5, void* arg6, uint64_t arg7) {
auto& s = state();
+ const auto host=[](){return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()/100;};
+ const auto scheduleBegin=s.traceEnabled?host():0;
+ auto* caller = static_cast<uint8_t*>(_ReturnAddress());
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 {std::lock_guard statsLock(s.statsMutex);++s.forwarded;}
}
- const auto host=[](){return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()/100;};
const auto nativeBegin=s.traceEnabled?host():0;
const auto result=s.native(ctx, a2, a3, a4, arg5, arg6, arg7);
if(s.traceEnabled){
diagnostics::FrameTraceEvent event;event.kind=diagnostics::TraceKind::ProviderOutput;
event.host100ns=event.presentEndHost=host();event.presentBeginHost=nativeBegin;
event.milliseconds=double(event.presentEndHost-nativeBegin)/10000;
+ event.providerScheduleBeginHost=scheduleBegin;
+ const auto address=reinterpret_cast<uintptr_t>(caller),base=reinterpret_cast<uintptr_t>(s.base);
+ if(address>=base&&address-base<XessPacing::kKnownSizeOfImage)event.providerCallerRva=uint32_t(address-base);
Logger::instance().recordFrame(event);
}
LARGE_INTEGER now{};QueryPerformanceCounter(&now);
@@ -352,6 +378,11 @@ XessPacing::State XessPacing::install(HMODULE provider, uint32_t generatedFrames
}
s.native = reinterpret_cast<PresentFn>(status.trampoline != nullptr ? status.trampoline : base + kNativePresentRva);
s.installed = true;
+ if(s.traceEnabled&&thunkTargets(base,timestampThunkRva,timestampFnRva)){
+ s.timestampNative=reinterpret_cast<TimestampFn>(base+timestampFnRva);
+ const auto traceStatus=s.timestampHook.install(base+timestampThunkRva,reinterpret_cast<void*>(&traceDeadline),11);
+ log::info("xess-pacing",std::format("read-only deadline trace installed={}",traceStatus.installed));
+ }
// Arm the periodic stats window only once frame times are being measured.
LARGE_INTEGER now{};
QueryPerformanceCounter(&now);
@@ -370,6 +401,8 @@ void XessPacing::release() {
if (!s.installed) return;
s.installed = false;
(void)s.hook.remove();
+ (void)s.timestampHook.remove();
+ s.timestampNative=nullptr;
s.native = nullptr;
s.sched = nullptr;
s.ringSnapshot = nullptr;