upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/shims/xbox_present.cpp
diff options
context:
space:
mode:
authorAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 12:54:49 +0100
committerAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 12:54:49 +0100
commit6728a00c2a27d9e21785d262f5ab8479c819dc89 (patch)
treea98a95b4851d388166332140f053f4e2958a70ca /runtime/shims/xbox_present.cpp
parentbb2e18421dac527374eb837c88b5063c5d96f81f (diff)
PresentX: implement ImmediateThresholdPercent with VK_KHR/EXT_swapchain_maintenance1
A frame presented after the vblank it was due at is flipped at once (IMMEDIATE, else FIFO_RELAXED) when the scan would be within the threshold percentage of the screen, instead of waiting a whole interval. The decision is the pure leonida::decide_present_sync(late_us, interval_us, threshold); FramePacer reports the lateness against the vblank after the token's origin and records the tear in GetFrameStatisticsX (PercentScanned) and immediate_presents(). VulkanPresenter creates a vsync swapchain with FIFO plus the tear mode when the surface lists it as compatible (VkSurfacePresentModeCompatibilityKHR) and chains VkSwapchainPresentModeInfoKHR on a tearing present. The device enables the KHR (else EXT) extension, its feature and the matching instance extensions only where present; without them the threshold is ignored and logged once, as before. LEONIDA_PRESENT_NO_TEAR=1 turns it off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/xbox_present.cpp')
-rw-r--r--runtime/shims/xbox_present.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp
index 9b687eaf5..47c514d97 100644
--- a/runtime/shims/xbox_present.cpp
+++ b/runtime/shims/xbox_present.cpp
@@ -52,8 +52,13 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam
52 std::lock_guard serialise(present_mutex_); 52 std::lock_guard serialise(present_mutex_);
53 if (plane_count > 2 || (plane_count && !planes)) return E_INVALIDARG; 53 if (plane_count > 2 || (plane_count && !planes)) return E_INVALIDARG;
54 if (pacer_.suspended()) return from_pacer(hr::invalid_state); 54 if (pacer_.suspended()) return from_pacer(hr::invalid_state);
55 if (params && params->ImmediateThresholdPercent != 0.0f) 55 // A zero, negative or NaN threshold never tears.
56 log_once(logged_threshold_, "ImmediateThresholdPercent is not implemented: a late frame waits for the next vblank"); 56 const float threshold = params ? params->ImmediateThresholdPercent : 0.0f;
57 const bool wants_tear = threshold > 0.0f;
58 if (wants_tear && !presenter_->tear_supported())
59 log_once(logged_threshold_,
60 "ImmediateThresholdPercent is not implemented here (the swapchain cannot switch to IMMEDIATE or "
61 "FIFO_RELAXED: no VK_KHR/EXT_swapchain_maintenance1 or no such mode): a late frame waits for the next vblank");
57 62
58 // Unpaced (no interval registered): do not hold the queue for vblanks. 63 // Unpaced (no interval registered): do not hold the queue for vblanks.
59 const UINT sync_interval = pacer_.registered() ? 1 : 0; 64 const UINT sync_interval = pacer_.registered() ? 1 : 0;
@@ -110,9 +115,20 @@ HRESULT XboxPresentation::PresentX(UINT plane_count, const XboxPresentPlaneParam
110 if (plane_count == 2) 115 if (plane_count == 2)
111 log_once(logged_planes_, "PresentX with 2 planes: only plane 0 is shown; HDR/GameDVR plane composition is not implemented"); 116 log_once(logged_planes_, "PresentX with 2 planes: only plane 0 is shown; HDR/GameDVR plane composition is not implemented");
112 117
113 const HRESULT result = presenter_->present(resource, sync_interval, rect); 118 // How late the frame is, now that everything that can refuse it has: past the vblank it was due at, by what part of
119 // the interval the scan has moved on. The presenter says whether it really queued it as a tear.
120 FramePacer::PresentTiming timing;
121 bool tear = false;
122 if (wants_tear && sync_interval > 0 && presenter_->tear_supported()) {
123 timing = pacer_.present_timing(token);
124 tear = leonida::decide_present_sync(timing.late_us, timing.period_us, threshold) == leonida::PresentSync::immediate;
125 }
126 const HRESULT result = presenter_->present(resource, sync_interval, rect, tear);
114 if (FAILED(result)) return pacer_.suspended() ? from_pacer(hr::invalid_state) : result; 127 if (FAILED(result)) return pacer_.suspended() ? from_pacer(hr::invalid_state) : result;
115 pacer_.commit_present_token(token, plane_count); 128 pacer_.commit_present_token(token, plane_count,
129 tear && presenter_->last_present_tore() ? leonida::PresentSync::immediate
130 : leonida::PresentSync::vblank,
131 timing.late_us);
116 ++presents_; 132 ++presents_;
117 return S_OK; 133 return S_OK;
118} 134}