Repository navigation
SwapChain: added "PRESENT_TIMING" and "GetPresentTimings" - #333
Conversation
"QueuePresent" takes a "presentId", but nothing reports when that presentation reached the display, so a frame loop can't pace by the time frames are shown. "SwapChainBits::PRESENT_TIMING" (requires "features.presentTiming") unlocks "GetPresentTimings": per tracked presentation, the time its first pixel left for the display in the CPU clock of "GetCalibratedTimestamps", and the refresh cycle. VK: "VK_EXT_present_timing" + "VK_KHR_present_id2" + "VK_KHR_calibrated_timestamps". The only time domain NVIDIA advertises is "PRESENT_STAGE_LOCAL", a clock per stage, so the first-pixel-out time is converted with "vkGetCalibratedTimestampsKHR". A full timing queue fails the present, so timing is requested only while a slot is free. Wrapped swap chains drop the flag. D3D12: "GetFrameStatistics", matched to presentations by present count. Other backends: unsupported.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c22985f26e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
D3D12: a disjoint frame-statistics sample also resets the measured refresh cycle, which may have changed with it. VK: the calibrated timestamps functions are loaded by their KHR names when only "VK_KHR_calibrated_timestamps" is enabled, so the CPU time domain (and "features.presentTiming") no longer depends on the EXT extension.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 691208791f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…IMING" Two threads presenting the same swap chain could both record the newer present count: the count was sampled after "Present", outside any lock. With "PRESENT_TIMING" a dedicated lock now covers "Present", "GetLastPresentCount" and the mapping update; "GetPresentTimings" still takes only the short mapping lock, so it never waits behind a blocking "Present". Other swap chains are unchanged.
|
Added five follow-up commits to address a few cases where valid presentations could produce missing or incorrect timing feedback:
Kept Windows builds and 23 controlled regression checks pass. Actual display-timestamp verification and Metal platform testing remain incomplete. |
|
Thanks for your work. We are still improving... |
Thanks for the quick reaction and for the followup commits too, they were necessary. Improving NRI is cool : ) |
|
8ce9384 migrates NRI to The main reason is the capability model: support depends on the actual surface, so checking it for each swapchain fits NRI’s independent devices and swapchains better. Present timing already uses ID2, making one consistent path simpler to maintain. Android adoption matters too: the old wait extension had effectively zero coverage—0.61% in the recent-report query, versus 11.04% for wait2. We’re deliberately starting clean, accepting the lower reported Windows/Linux coverage. If users encounter concrete compatibility gaps, we can add a fallback then. The README and native-wrapper requirements are updated. Debug/Release builds and 25 migration regression checks pass; native Vulkan tests also passed waiting without timing and waiting through a full timing queue, including 64 valid display timestamps. |
|
I think we are good to go now. Thanks! |
Motivation
A frame loop that paces by the CPU time between its frames stutters even at a steady frame rate. Frames are shown at vblanks, and the loop can't see when a frame actually reached the screen (Alen Ladavac, "The Elusive Frame Timing: A Case Study for Smoothness Over Speed", GDC 2018).
QueuePresentalready takes apresentId, but nothing comes back for it. Knowing when each tracked presentation was displayed, and the refresh cycle, lets an application step its simulation by displayed time, notice missed vblanks and choose its own pacing. NRI adds no policy.What I added
SwapChainBits::PRESENT_TIMING(requiresfeatures.presentTiming) andGetPresentTimings: non-blocking, returns per tracked presentation the time its first pixel left for the display (in the CPU clock ofGetCalibratedTimestamps) and the refresh cycle.VK_EXT_present_timingusesVK_KHR_present_id2; presentation waiting usesVK_KHR_present_wait2. ID/wait support is queried per surface. The per-stage clock is converted to the CPU clock with calibrated timestamps and recovers when presentation clock domains change. Wrapped swap chains drop the timing flag. The legacy ID/wait extensions are not used as a fallback.GetFrameStatistics, at most one presentation per call.MTLDrawable.presentedTimecallbacks, converted to the uptime nanoseconds used byGetCalibratedTimestamps. A bounded ordered report queue has callback-owned state that can outlive the swap chain and device; it never retains drawables. Refresh duration and variable-refresh status are unknown.Validation
b85c7fce. The Vulkan checks include an oversized capacity of 1024 while native query and scratch capacities remain bounded to 64. The original PR head reproduces three D3D12 failures and four Vulkan timing failures.