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: attribute XeSS scheduler gaps to pending fences

Veyra Goal Agenta0e39ea0cca4
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index 9d5b76ed..ae6495ea 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -53,6 +53,12 @@ SAOG0721/Magpie commit `3841698348bfb246623d4acf791984c8b68a577b`,
the native deadline without modifying it. The upstream deadline rewrite is
not ported. The audited DLL remains unchanged on disk.
+Read-only fence attribution additionally checks the same pinned provider's
+scheduler at 0x21EE30: context+0x328 is the ID3D12Fence queried at 0x21EECF,
+and timestamp lookup+0x18 holds the target tested at 0x21EEEB. Veyra samples
+GetCompletedValue around its synchronous scheduler call only when tracing;
+no fence value, event, deadline or queue submission is modified.
+
### Magpie NR temporal residual route (2026-09-20)
Veyra's optional `src/pipeline/NrTemporalPass.cpp` and
diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md
index b5894b34..5e093f80 100644
--- a/docs/CURRENT_STATUS.md
+++ b/docs/CURRENT_STATUS.md
@@ -7,6 +7,9 @@
整段统计仍发现约四分之一的输出间隔短于1ms及约46ms的偶发长间隔;后端/倍率切换回归通过。
尚未通过完整节奏/画质验收,默认仍关闭。详见
[本轮诊断与候选](FG_STABILITY_PROGRESS_2026-09-21.md)。
+新增只读 fence 追踪:重负载保留的351次首帧调度全部在进入时有未完成GPU依赖,
+不能把约8.5ms的前段耗时全部当作无效等待删除;仍需区分队列积压、GPU工作与唤醒。
+诊断版后端切换回归通过,尚无新增已接受的调度优化。
开发工作区为 `E:/项目/Veyra/worktrees/playback-nr-20260920`,
分支 `codex/fg-stability-20260921`;开工存档 `d2ae8ee`,诊断存档 `0143baf`。
正式版仍为1.4.3,最新本地交付仍为下述1.4.4beta。
diff --git a/docs/FG_STABILITY_PROGRESS_2026-09-21.md b/docs/FG_STABILITY_PROGRESS_2026-09-21.md
index a5cc7cbf..a72b43c0 100644
--- a/docs/FG_STABILITY_PROGRESS_2026-09-21.md
+++ b/docs/FG_STABILITY_PROGRESS_2026-09-21.md
@@ -183,3 +183,38 @@ short/long burst boundaries independently; no extra queue or fixed wait.
P2 DLSS long gaps and P3-P6 remain as listed in the execution plan; this work
does not change or complete them. Independent denoising prerequisites remain
unresolved. No software performance claim is extended to other GPUs.
+
+## Fence readiness attribution
+
+Read-only tracing now samples the audited scheduler fence on entry and at
+timestamp calculation, with the native lookup target. Only our synchronous
+index1 scheduler calls are sampled; pointers are thread-local and cleared
+on return. No resource lifetime, signal, wait or deadline is changed.
+UINT64_MAX completion is classified as device removal, not readiness.
+
+20s heavy source-timing-on run, fence-on/sr-nr-xess4: exit0, source52.25/s,
+process age P95 38.815ms. All351 retained first-index samples had a pending
+fence on entry and a completed fence at deadline calculation. None was
+already ready or still pending. Entry-to-deadline mean8.465ms/P95 14.300ms;
+subsequent deadline wait mean3.815ms. This proves a real pending dependency,
+NOT that all8.465ms is GPU execution, nor that hardware alone is responsible.
+Queue backlog and CPU wake time remain possible contributors. Do not delete
+the wait. Retained SDK-return max47.473ms includes36.954ms in native Present,
+so even the largest spike is not explained solely by this fence wait.
+
+Static follow-up: VideoPresenter passes the shared direct queue to XeSS;
+only DLSS has the separate presentation queue. Provider code at0x21F030
+signals the sampled fence via a queue at context+0x10. Attribution of that
+queue's identity and preceding submissions is the next bounded investigation;
+do not simply enable the DLSS queue path for XeSS without resource retirement
+and tagging contracts. No new optimization is accepted by this diagnostic.
+
+Build log: E:/项目/Veyra/logs/fg-stability-fence-trace-20260921.log, exit0.
+EXE SHA256:90b63920f3e30d06ac509779adba087baeb953e09267316f18e3444219825387.
+Tests use existing matrix and timeline analyzer commands, cases sr-nr-xess4,
+seconds20. Evidence under E:/项目/Veyra/tests/fg-stability-20260921/fence-on.
+Five analyzer tests pass, including pending/ready/device-removed attribution.
+deadline-hook-switch and fence-hook-switch both pass12 backend/multiplier
+transactions plus3 layout sizes, exit0. This is lifecycle evidence, not visual
+acceptance or physical multi-monitor testing. Default candidate remains off;
+full goal and P2-P6 remain unfinished.
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 29067629..3d76bc17 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -5823,3 +5823,20 @@ 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.
+
+Fence attribution follow-up: verified clean branch at512de1c before edits.
+Existing pre-work checkpoint d2ae8ee remains intact. Added opt-in completed
+fence snapshots to FrameTrace/Log/XessPacing and analyzer classification;
+corrected XessPacing.h's unverified claim of correct provider spacing.
+Same build-isolated command, target veyra, log under E:/项目/Veyra/logs/
+fg-stability-fence-trace-20260921.log, exit0. Updated only isolated app staging.
+fg-utilization-matrix.py --cases sr-nr-xess4 --seconds20 with trace and source
+timing enabled, output tests/fg-stability-20260921/fence-on; exit0.
+analyze-xess-timeline.py produced adjacent xess-timeline.json:351/351 entry
+fences pending then complete at deadline; mean8.465ms before deadline,
+3.815ms after. Source52.25/s, ageP95 38.815ms. Not isolated GPU duration.
+Both deadline-hook-switch and fence-hook-switch ui-fg-backends.py runs pass
+12 transactions,3 layout sizes, exit0. TEMP/TMP set to existing task tmp.
+test-xess-timeline.py passes5 tests. No runtime mutation, package, push or
+publication. Full acceptance and P2-P6 remain outstanding; next inspect
+producer-queue dependency before changing scheduling.
diff --git a/include/veyra/diagnostics/FrameTrace.h b/include/veyra/diagnostics/FrameTrace.h
index 0e89158c..2f5d2550 100644
--- a/include/veyra/diagnostics/FrameTrace.h
+++ b/include/veyra/diagnostics/FrameTrace.h
@@ -45,6 +45,8 @@ struct FrameTraceEvent {
uint32_t providerCycle=0,preparationCycle=0;
uint32_t providerCallerRva=0;
int64_t providerScheduleBeginHost=0;
+ bool providerFenceSampled=false;
+ uint64_t providerFenceBefore=0,providerFenceAtDeadline=0,providerFenceTarget=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/include/veyra/gfx/XessPacing.h b/include/veyra/gfx/XessPacing.h
index 160acf12..51265d4d 100644
--- a/include/veyra/gfx/XessPacing.h
+++ b/include/veyra/gfx/XessPacing.h
@@ -15,8 +15,8 @@ namespace veyra::gfx {
// 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
+// The provider estimates spacing from its timing inputs; this does not prove
+// uniform burst-boundary cadence under load. It 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
diff --git a/scripts/acceptance/analyze-xess-timeline.py b/scripts/acceptance/analyze-xess-timeline.py
index fa4b8d2e..34b09b5d 100644
--- a/scripts/acceptance/analyze-xess-timeline.py
+++ b/scripts/acceptance/analyze-xess-timeline.py
@@ -27,6 +27,7 @@ def analyze(path):
for previous, current in zip(outputs, outputs[1:])]
transitions = {}
deadlines = [row for row in events if row["event"] == "ProviderDeadline"]
+ fence_groups = {name: [] for name in ("readyAtEntry", "pendingThenReady", "stillPending", "deviceRemoved")}
first_schedule_parts = {name: [] for name in ("beforeDeadlineMs", "afterDeadlineMs", "deadlineLeadMs")}
for output in outputs:
begin = int(output.get("providerScheduleBeginHost", 0))
@@ -37,6 +38,13 @@ def analyze(path):
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"]))
+ if int(row.get("providerFenceSampled", 0)):
+ before, after, target = (int(row[key]) for key in
+ ("providerFenceBefore", "providerFenceAtDeadline", "providerFenceTarget"))
+ category = ("deviceRemoved" if max(before, after) == (1 << 64) - 1 else
+ "readyAtEntry" if before >= target else
+ "pendingThenReady" if after >= target else "stillPending")
+ fence_groups[category].append((int(row["host"]) - begin) / 10000)
for previous, current in zip(outputs, outputs[1:]):
if not int(previous.get("providerCallerRva", 0)) or not int(current.get("providerCallerRva", 0)):
continue
@@ -97,6 +105,7 @@ def analyze(path):
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()},
+ fenceEntryToDeadlineMs={name: distribution(values) for name, values in fence_groups.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),
diff --git a/scripts/acceptance/test-xess-timeline.py b/scripts/acceptance/test-xess-timeline.py
index 666c0cc4..84795860 100644
--- a/scripts/acceptance/test-xess-timeline.py
+++ b/scripts/acceptance/test-xess-timeline.py
@@ -29,6 +29,17 @@ def cycle(number, epoch, begin, instance=1, revision=1, app=True):
class TimelineTests(unittest.TestCase):
+ def test_fence_readiness_and_device_removal(self):
+ for before, after, expected in [(9, 10, "pendingThenReady"), (10, 10, "readyAtEntry"),
+ (8, 9, "stillPending"), ((1 << 64) - 1, 10, "deviceRemoved")]:
+ text = cycle(1, 1, 0)
+ text += "event=ProviderOutput presentBeginHost=50000 presentEndHost=60000 providerScheduleBeginHost=30000\n"
+ text += (f"event=ProviderDeadline host=40000 detail=1 ms=0.9 providerFenceSampled=1 "
+ f"providerFenceBefore={before} providerFenceAtDeadline={after} providerFenceTarget=10\n")
+ groups = timeline.analyze(Trace(text))["fenceEntryToDeadlineMs"]
+ self.assertEqual(groups[expected]["samples"], 1)
+ self.assertEqual(sum(group["samples"] for group in groups.values()), 1)
+
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"
diff --git a/src/base/Log.cpp b/src/base/Log.cpp
index ce847aa9..2b94539a 100644
--- a/src/base/Log.cpp
+++ b/src/base/Log.cpp
@@ -181,7 +181,9 @@ std::string Logger::diagnosticReport(){std::ostringstream o;o<<"Veyra 本地诊
<<" entryDeviationMs="<<e.entryDeviationMs<<" returnDeviationMs="<<e.returnDeviationMs
<<" queueDepth="<<e.queueDepth<<" mediaDeviationValid="<<e.mediaDeviationValid
<<" providerInstance="<<e.providerInstance<<" providerCycle="<<e.providerCycle<<" preparationCycle="<<e.preparationCycle
- <<" providerCallerRva="<<e.providerCallerRva<<" providerScheduleBeginHost="<<e.providerScheduleBeginHost<<'\n';
+ <<" providerCallerRva="<<e.providerCallerRva<<" providerScheduleBeginHost="<<e.providerScheduleBeginHost
+ <<" providerFenceSampled="<<e.providerFenceSampled<<" providerFenceBefore="<<e.providerFenceBefore
+ <<" providerFenceAtDeadline="<<e.providerFenceAtDeadline<<" providerFenceTarget="<<e.providerFenceTarget<<'\n';
return diagnostics::redact(o.str());
}
void Logger::flush()
diff --git a/src/gfx/XessPacing.cpp b/src/gfx/XessPacing.cpp
index 946d3657..e81ff4a7 100644
--- a/src/gfx/XessPacing.cpp
+++ b/src/gfx/XessPacing.cpp
@@ -10,6 +10,7 @@
#include <filesystem>
#include <intrin.h>
#include <mutex>
+#include <d3d12.h>
namespace veyra::gfx {
namespace {
@@ -24,6 +25,15 @@ 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;
+// Read-only samples around our synchronous scheduler call. The provider owns
+// the fence for the entire call; never retain it across calls or rebuilds.
+struct FenceObservation {
+ void* ring=nullptr;
+ ID3D12Fence* fence=nullptr;
+ uint64_t before=0;
+};
+thread_local FenceObservation fenceObservation;
+
struct OutputIntervals {
// Quarter-millisecond bins, with a separate overflow bin at 250ms.
std::array<uint64_t,1001> bins{};
@@ -118,6 +128,13 @@ void* traceDeadline(void* ctx,int64_t* out,void* lookup,void* timing,uint32_t in
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;
+ if(lookup&&fenceObservation.fence&&fenceObservation.ring==ctx&&index==1){
+ event.providerFenceSampled=true;
+ event.providerFenceBefore=fenceObservation.before;
+ event.providerFenceAtDeadline=fenceObservation.fence->GetCompletedValue();
+ // Scheduler lookup local+0x18 supplies the fence value at 0x21eeeb.
+ std::memcpy(&event.providerFenceTarget,static_cast<uint8_t*>(lookup)+0x18,sizeof(uint64_t));
+ }
// Audited native scheduler uses QPC converted to nanoseconds, not host100ns.
const auto frequency=s.frequency.QuadPart;
if(out&&frequency>0){
@@ -181,9 +198,16 @@ void scheduleFrame(void* ctx, uint8_t* burst, uint64_t index) {
const uint64_t count = *reinterpret_cast<uint64_t*>(burst + 8);
LARGE_INTEGER before{}, after{};
+ if(s.traceEnabled&&gate&&index==1){
+ ID3D12Fence* fence=nullptr;
+ // Audited 0x21eecf reads this pointer before GetCompletedValue.
+ std::memcpy(&fence,static_cast<uint8_t*>(ctx)+0x328,sizeof(fence));
+ if(fence)fenceObservation={static_cast<uint8_t*>(ctx)+XessPacing::kRingOffset,fence,fence->GetCompletedValue()};
+ }
QueryPerformanceCounter(&before);
const bool ok = s.sched(ctx, burst, gate, timing, static_cast<uint32_t>(index));
QueryPerformanceCounter(&after);
+ fenceObservation={};
std::lock_guard statsLock(s.statsMutex);
++s.scheduled;