Skip to content

Commit a682d9e

Browse files
authored
Update desired_maximum_frame_latency documentation (#8421)
1 parent c6dc8ee commit a682d9e

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

examples/features/src/framework.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ impl SurfaceWrapper {
196196
config.format = format;
197197
config.view_formats.push(format);
198198
};
199+
config.present_mode = wgpu::PresentMode::Immediate;
200+
config.desired_maximum_frame_latency = 3;
199201

200202
surface.configure(&context.device, &config);
201203
self.config = Some(config);

wgpu-types/src/lib.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5814,25 +5814,40 @@ pub struct SurfaceConfiguration<V> {
58145814
/// `AutoNoVsync` will gracefully do a designed sets of fallbacks if their primary modes are
58155815
/// unsupported.
58165816
pub present_mode: PresentMode,
5817-
/// Desired maximum number of frames that the presentation engine should queue in advance.
5818-
///
5819-
/// This is a hint to the backend implementation and will always be clamped to the supported range.
5820-
/// As a consequence, either the maximum frame latency is set directly on the swap chain,
5821-
/// or waits on present are scheduled to avoid exceeding the maximum frame latency if supported,
5822-
/// or the swap chain size is set to (max-latency + 1).
5823-
///
5824-
/// Defaults to 2 when created via `Surface::get_default_config`.
5825-
///
5826-
/// Typical values range from 3 to 1, but higher values are possible:
5827-
/// * Choose 2 or higher for potentially smoother frame display, as it allows to be at least one frame
5828-
/// to be queued up. This typically avoids starving the GPU's work queue.
5829-
/// Higher values are useful for achieving a constant flow of frames to the display under varying load.
5830-
/// * Choose 1 for low latency from frame recording to frame display.
5831-
/// ⚠️ If the backend does not support waiting on present, this will cause the CPU to wait for the GPU
5832-
/// to finish all work related to the previous frame when calling `Surface::get_current_texture`,
5833-
/// causing CPU-GPU serialization (i.e. when `Surface::get_current_texture` returns, the GPU might be idle).
5834-
/// It is currently not possible to query this. See <https://github.com/gfx-rs/wgpu/issues/2869>.
5835-
/// * A value of 0 is generally not supported and always clamped to a higher value.
5817+
/// Desired maximum number of monitor refreshes between a [`Surface::get_current_texture`] call and the
5818+
/// texture being presented to the screen. This is sometimes called "Frames in Flight".
5819+
///
5820+
/// Defaults to `2` when created via [`Surface::get_default_config`] as this is a reasonable default.
5821+
///
5822+
/// This is ultimately a hint to the backend implementation and will always be clamped
5823+
/// to the supported range.
5824+
///
5825+
/// Typical values are `1` to `3`, but higher values are valid, though likely to be clamped.
5826+
/// * Choose `1` to minimize latency above all else. This only gives a single monitor refresh for all of
5827+
/// the CPU and GPU work to complete. ⚠️ As a result of these short swapchains, the CPU and GPU
5828+
/// cannot run in parallel, prioritizing latency over throughput. For applications like GUIs doing
5829+
/// a small amount of GPU work each frame that need low latency, this is a reasonable choice.
5830+
/// * Choose `2` for a balance between latency and throughput. The CPU and GPU both can each use
5831+
/// a full monitor refresh to do their computations. This is a reasonable default for most applications.
5832+
/// * Choose `3` or higher to maximize throughput, sacrificing latency when the the CPU and GPU
5833+
/// are using less than a full monitor refresh each. For applications that use CPU-side pipelining
5834+
/// of frames this may be a reasonable choice. ⚠️ On 60hz displays the latency can be very noticeable.
5835+
///
5836+
/// This maps to the backend in the following ways:
5837+
/// - Vulkan: Number of frames in the swapchain is `desired_maximum_frame_latency + 1`,
5838+
/// clamped to the supported range.
5839+
/// - DX12: Calls [`IDXGISwapChain2::SetMaximumFrameLatency(desired_maximum_frame_latency)`][SMFL].
5840+
/// - Metal: Sets the `maximumDrawableCount` of the underlying `CAMetalLayer` to
5841+
/// `desired_maximum_frame_latency + 1`, clamped to the supported range.
5842+
/// - OpenGL: Ignored
5843+
///
5844+
/// It also has various subtle interactions with various present modes and APIs.
5845+
/// - DX12 + Mailbox: Limits framerate to `desired_maximum_frame_latency * Monitor Hz` fps.
5846+
/// - Vulkan/Metal + Mailbox: If this is set to `2`, limits framerate to `2 * Monitor Hz` fps. `3` or higher is unlimited.
5847+
///
5848+
/// [`Surface::get_current_texture`]: ../wgpu/struct.Surface.html#method.get_current_texture
5849+
/// [`Surface::get_default_config`]: ../wgpu/struct.Surface.html#method.get_default_config
5850+
/// [SMFL]: https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_3/nf-dxgi1_3-idxgiswapchain2-setmaximumframelatency
58365851
pub desired_maximum_frame_latency: u32,
58375852
/// Specifies how the alpha channel of the textures should be handled during compositing.
58385853
pub alpha_mode: CompositeAlphaMode,

0 commit comments

Comments
 (0)