Skip to content

Commit c4a48db

Browse files
committed
Update desired_maximum_frame_latency documentation
1 parent 7f64445 commit c4a48db

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
@@ -5789,25 +5789,40 @@ pub struct SurfaceConfiguration<V> {
57895789
/// `AutoNoVsync` will gracefully do a designed sets of fallbacks if their primary modes are
57905790
/// unsupported.
57915791
pub present_mode: PresentMode,
5792-
/// Desired maximum number of frames that the presentation engine should queue in advance.
5793-
///
5794-
/// This is a hint to the backend implementation and will always be clamped to the supported range.
5795-
/// As a consequence, either the maximum frame latency is set directly on the swap chain,
5796-
/// or waits on present are scheduled to avoid exceeding the maximum frame latency if supported,
5797-
/// or the swap chain size is set to (max-latency + 1).
5798-
///
5799-
/// Defaults to 2 when created via `Surface::get_default_config`.
5800-
///
5801-
/// Typical values range from 3 to 1, but higher values are possible:
5802-
/// * Choose 2 or higher for potentially smoother frame display, as it allows to be at least one frame
5803-
/// to be queued up. This typically avoids starving the GPU's work queue.
5804-
/// Higher values are useful for achieving a constant flow of frames to the display under varying load.
5805-
/// * Choose 1 for low latency from frame recording to frame display.
5806-
/// ⚠️ If the backend does not support waiting on present, this will cause the CPU to wait for the GPU
5807-
/// to finish all work related to the previous frame when calling `Surface::get_current_texture`,
5808-
/// causing CPU-GPU serialization (i.e. when `Surface::get_current_texture` returns, the GPU might be idle).
5809-
/// It is currently not possible to query this. See <https://github.com/gfx-rs/wgpu/issues/2869>.
5810-
/// * A value of 0 is generally not supported and always clamped to a higher value.
5792+
/// Desired maximum number of frames between a [`Surface::get_current_texture`] call and the
5793+
/// texture being presented to the screen. This is sometimes called "Frames in Flight".
5794+
///
5795+
/// Defaults to `2` when created via [`Surface::get_default_config`] as this is a reasonable default.
5796+
///
5797+
/// This is ultimately a hint to the backend implementation and will always be clamped
5798+
/// to the supported range.
5799+
///
5800+
/// Typical values are `1` to `3`, but higher values are valid, though likely to be clamped.
5801+
/// * Choose `1` to minimize latency above all else. This only gives a single frame for all of
5802+
/// the CPU and GPU work to complete. ⚠️ As a result of these short swapchains, the CPU and GPU
5803+
/// cannot run in parallel, prioritizing latency over throughput. For applications like GUIs doing
5804+
/// a small amount of GPU work each frame that need low latency, this is a reasonable choice.
5805+
/// * Choose `2` for a balance between latency and throughput. The CPU and GPU both can each use
5806+
/// a full frame to do their computations. This is a reasonable default for most applications.
5807+
/// * Choose `3` or higher to maximize throughput, sacrificing latency when the the CPU and GPU
5808+
/// are using less than a full frame each. For applications that use CPU-side pipelining of frames
5809+
/// this may be a reasonable choice. ⚠️ On 60hz displays the latency can be very noticeable.
5810+
///
5811+
/// This maps to the backend in the following ways:
5812+
/// - Vulkan: Number of frames in the swapchain is `desired_maximum_frame_latency + 1`,
5813+
/// clamped to the supported range.
5814+
/// - DX12: Calls [`IDXGISwapChain2::SetMaximumFrameLatency(desired_maximum_frame_latency)`][SMFL].
5815+
/// - Metal: Sets the `maximumDrawableCount` of the underlying `CAMetalLayer` to
5816+
/// `desired_maximum_frame_latency + 1`, clamped to the supported range.
5817+
/// - OpenGL: Ignored
5818+
///
5819+
/// It also has various subtle interactions with various present modes and apis.
5820+
/// - DX12 + Mailbox: Limits framerate to `desired_maximum_frame_latency * Monitor Hz` fps.
5821+
/// - Vulkan/Metal + Mailbox: If this is set to `2`, limits framerate to `2 * Monitor Hz` fps. `3` or higher is unlimited.
5822+
///
5823+
/// [`Surface::get_current_texture`]: ../wgpu/struct.Surface.html#method.get_current_texture
5824+
/// [`Surface::get_default_config`]: ../wgpu/struct.Surface.html#method.get_default_config
5825+
/// [SMFL]: https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_3/nf-dxgi1_3-idxgiswapchain2-setmaximumframelatency
58115826
pub desired_maximum_frame_latency: u32,
58125827
/// Specifies how the alpha channel of the textures should be handled during compositing.
58135828
pub alpha_mode: CompositeAlphaMode,

0 commit comments

Comments
 (0)