Skip to content

Allow chaining extension structs onto VkPresentInfoKHR at present time - #9847

Open
stuartparmenter wants to merge 4 commits into
gfx-rs:trunkfrom
stuartparmenter:nv-present-metering
Open

Allow chaining extension structs onto VkPresentInfoKHR at present time#9847
stuartparmenter wants to merge 4 commits into
gfx-rs:trunkfrom
stuartparmenter:nv-present-metering

Conversation

@stuartparmenter

@stuartparmenter stuartparmenter commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Connections
Reworked per review feedback (#9847 (review)): instead of dedicated VK_NV_present_metering support, this now adds a generic extension point.

Description
Adds wgpu_hal::vulkan::Surface::set_next_present_chain(), reachable via Surface::as_hal(), which attaches a caller-provided pNext chain to the VkPresentInfoKHR of the surface's next presentation. The chain is caller-owned (so driver-written feedback fields can be read back after the present), consumed by the next present, and discarded if the surface is reconfigured first.

Combined with the existing Adapter::open_with_callback() for enabling device extensions, this lets users plug in presentation extensions wgpu has no dedicated support for — e.g. VK_NV_present_metering, which meters the display timing of a batch of presented frames for frame generation — without wgpu carrying per-vendor code. The NV struct definitions now live in the consumer (dlss_wgpu) rather than in wgpu.

Testing
Used for DLSS Frame Generation presentation pacing in a Bevy branch on Windows (RTX 5090, driver 610.74): the extension is enabled via open_with_callback, and a caller-owned VkSetPresentConfigNV is chained onto the first present of each generated+real frame batch. The driver meters the batch with no CPU-side present timing, and validation layers are quiet.

Squash or Rebase?
Squash.

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.

@inner-daemons inner-daemons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that you mostly copied the support for vk_google_present_timing so some of my style comments might not need to be addressed (they are my opinion but go against previous project decisions).

I am incredibly skeptical of this though. Special integration with an nvidia-on-vulkan only extension is weird and I wouldn't like to add very many cases like this. I'd much prefer to let users plug in vulkan extensions as they need them. My last comment proposed a solution for this.

Either way I would not be in favor of this PR landing but other maintainers can opine on that, I've reviewed the code and it looks mostly fine.

Comment thread wgpu-hal/src/vulkan/present_metering.rs Outdated
Comment thread wgpu-hal/src/vulkan/swapchain/native.rs Outdated
Comment thread wgpu-hal/src/vulkan/swapchain/native.rs Outdated
Comment thread wgpu-hal/src/vulkan/swapchain/native.rs
@inner-daemons inner-daemons self-assigned this Jul 10, 2026
Adds wgpu_hal::vulkan::Surface::set_next_present_chain(), which attaches a
caller-provided pNext chain to the VkPresentInfoKHR of the surface's next
presentation. Combined with Adapter::open_with_callback() for enabling the
corresponding device extension, this allows using presentation extensions
wgpu has no dedicated support for, such as VK_NV_present_metering.
@stuartparmenter stuartparmenter changed the title Add VK_NV_present_metering support Allow chaining extension structs onto VkPresentInfoKHR at present time Jul 10, 2026
@stuartparmenter

stuartparmenter commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Reworked as suggested — thanks for the pointer. What's left is a single generic Surface::set_next_present_chain() that splices a caller-owned pNext chain onto VkPresentInfoKHR at the next present, with extension enablement handled by the existing open_with_callback. The VK_NV_present_metering structs moved out to dlss_wgpu, and I've verified the frame-generation pacing still works end to end with the new shape (RTX 5090).

stuartparmenter added a commit to stuartparmenter/dlss_wgpu that referenced this pull request Jul 10, 2026
Defines the extension's structs manually (not yet in ash) and enables the
extension in request_device when supported, reported via
FeatureSupport::present_metering_supported. PresentMetering owns the
VkSetPresentConfigNV chained onto the next present via wgpu's new
Surface::set_next_present_chain (gfx-rs/wgpu#9847), which meters the
display timing of a batch of presented frames.

Temporarily patches wgpu to a local checkout until a release includes
set_next_present_chain.
@inner-daemons
inner-daemons self-requested a review July 10, 2026 22:13
@cwfitzgerald cwfitzgerald self-assigned this Jul 15, 2026
stuartparmenter added a commit to stuartparmenter/bevy that referenced this pull request Jul 24, 2026
New paced_present module (behind the paced_present cargo feature) lets
a producer take over a window's swapchain presentation and present
multiple textures per rendered frame, evenly metered by the driver via
VK_NV_present_metering (wgpu VULKAN_NV_PRESENT_METERING, gfx-rs/wgpu#9847).
Producers mark windows in PacedWindows during extract (suppressing
normal swapchain acquisition) and submit a PacedPresentPlan of texture
views; presentation blits each with the screenshot pipeline and presents
back to back.

Also adds a public ScreenshotPreparation system set so attachment
overriding systems can order against screenshot preparation, and points
[patch.crates-io] at the wgpu branch exposing the extension.
@inner-daemons

Copy link
Copy Markdown
Collaborator

@cwfitzgerald Now that it is possible to handle it manually, should we remove the special support for vk_google_present_timing?

@inner-daemons inner-daemons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Honestly looks entirely good to me, minus a nit about the changelog.

Comment thread CHANGELOG.md

#### Vulkan

- Add `wgpu_hal::vulkan::Surface::set_next_present_chain`, which attaches a caller-provided `pNext` chain to the `VkPresentInfoKHR` of the surface's next presentation. With `Adapter::open_with_callback` to enable the device extension, this supports presentation extensions wgpu has no dedicated support for, such as [VK_NV_present_metering](https://registry.khronos.org/vulkan/specs/latest/man/html/VK_NV_present_metering.html) for metering the display timing of frame-generation frames. By @stuartparmenter in [#9847](https://github.com/gfx-rs/wgpu/pull/9847).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Normally we have a section for wgpu-hal which is separate from wgpu so that people who are using wgpu don't have to filter through e.g. a bunch of breaking changes on wgpu-hal that doesn't affect them.

@andyleiserson andyleiserson added the feature: api interop Issues with Underlying API Interop label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: api interop Issues with Underlying API Interop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants