Skip to content

Add simple API sample for VK_EXT_present_timing.#1535

Open
nvlduc wants to merge 1 commit intoKhronosGroup:mainfrom
nvlduc:present_timing_api
Open

Add simple API sample for VK_EXT_present_timing.#1535
nvlduc wants to merge 1 commit intoKhronosGroup:mainfrom
nvlduc:present_timing_api

Conversation

@nvlduc
Copy link
Copy Markdown

@nvlduc nvlduc commented Apr 29, 2026

Description

This change adds a new "API" sample demonstrating usage of the VK_EXT_present_timing API. I chose this type of sample as opposed to a more complex demo to focus on the API design of this particular extension, rather than exploring the problem space of frame pacing and swapchain best practices which require interactions with other unrelated extensions.

The simple rendering (a circle moving across the display) is a decent test to verify the quality of a VK_EXT_present_timing implementation.

I unfortunately do not have equipment to build this on macOS or Android.

This sample was tested using latest NVIDIA beta developer drivers on Windows 11 (596.10) and Linux (595.44.05) with an NVIDIA RTX 4080.

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions
    • I have not tested on macOS / Android.

If this PR contains framework changes:

  • I did a full batch run using the batch command line argument to make sure all samples still work properly

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist:

  • I have tested the sample on at least one compliant Vulkan implementation
  • If the sample is vendor-specific, I have tagged it appropriately
  • I have stated on what implementation the sample has been tested so that others can test on different implementations and platforms
  • Any dependent assets have been merged and published in downstream modules
  • For new samples, I have added a paragraph with a summary to the appropriate chapter in the readme of the folder that the sample belongs to e.g. api samples readme
  • For new samples, I have added a tutorial README.md file to guide users through what they need to know to implement code using this feature. For example, see conditional_rendering
  • For new samples, I have added a link to the Antora navigation so that the sample will be listed at the Vulkan documentation site

Copy link
Copy Markdown
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting sample!
Unfortunately, it doesn't run on my environment (Win11, NVIDIA RTX A3000 Laptop GPU). It gets a VK_ERROR_SURFACE_LOST_KHR on vkQueuePresentKHR after vkGetPastPresentationTimingEXT got more than 0 (1, to be precise) past_presentation_properties.presentationTimingCount for the first time.
Any idea what that might mean?

Besides that, I have a couple of questions...

== Extension Features

VK_EXT_present_timing exposes 3 features at the physical device level:
* `presentTiming` is required for the extension to be exposed, and allows the application to query past presentation timings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want an empty line before this one.

=== Timing Properties

`VkSwapchainTimingPropertiesEXT` exposes a `refreshDuration` and a `refreshInterval` value. These two fields put together describe the behavior of the presentation engine:
* If both values are equal, the presentation engine is operating in a fixed refresh rate mode (FRR), and the value indicates the length of a refresh cycle in nanoseconds.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably an empty line before this one, again?


=== Time Domains

The time values are all expressed in a time domain chosen by the application among a list of candidates exposed by the swapchain. `VK_EXT_present_timing` introduces new opaque times domains that are local to a given swapchain: `VK_TIME_DOMAIN_PRESENT_STAGE_LOCAL_EXT`, which all implementations must support, and `VK_TIME_DOMAIN_SWAPCHAIN_LOCAL_EXT`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

times domains -> time domains ?

}

// Do triple-buffering when possible. This is clamped to the min and max image count limits.
desired_swapchain_images = std::max(surface_capabilities.surfaceCapabilities.minImageCount, 3u);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On desired_swapchain_image: maybe something with "count" in its name?

}

// Find a supported composite type.
composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if (surface_capabilities.surfaceCapabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) is false?

{
can_use_present_timing = false;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just

	can_use_present_timing = display_present_stage &&
	                         (present_timing_capabilities.presentAtRelativeTimeSupported ||
	                          present_timing_capabilities.presentAtAbsoluteTimeSupported);

past_presentation_properties.pPresentationTimings = past_presentation_timings.data();
past_presentation_properties.presentationTimingCount = past_presentation_timings.size();

VK_CHECK(vkGetPastPresentationTimingEXT(get_device_handle(), &past_presentation_info, &past_presentation_properties));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't vkGetPastPresentationTimingEXT an enumeration call?
First call to determine the number of VkPastPresentationTimingEXT to get, and second call to actually get them?
past_presentation_timings could be a std::vector, then.

{
query_swapchain_timing_properties();
select_target_present_duration();
timing_properties_counter = past_presentation_properties.timingPropertiesCounter;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timing_properties_counter has already been set in query_swapchain_timing_properties() by calling vkGetSwapchainTimingPropertiesEXT.
Is that supposed to be identical to what you get with vkGetPastPresentationTimingEXT?

invalidate_timing_history();
}

time_domains_counter = past_presentation_properties.timeDomainsCounter;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the above, now with time_domains_counter, select_swapchain_time_domain(), and vkGetSwapchainTimeDomainPropertiesEXT

std::array<VkPastPresentationTimingEXT, history_buffer_size> past_presentation_timings;

/// Frame timing history. This is not directly used and is meant as an example.
std::array<FrameTimingData, history_buffer_size> timing_history;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need past_presentation_timings and timing_history to be the same size, or can they be sized differently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants