From 051d08424c0bcdf8f9792519b4e0fb6e70737918 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Thu, 5 Mar 2020 18:19:18 -0500 Subject: [PATCH 1/2] Add PresentMode::Mailbox --- ffi/wgpu.h | 1 + wgpu-core/src/swap_chain.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 06ee444f6b..0c6a89018c 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -128,6 +128,7 @@ typedef enum { typedef enum { WGPUPresentMode_NoVsync = 0, WGPUPresentMode_Vsync = 1, + WGPUPresentMode_Mailbox = 2, } WGPUPresentMode; typedef enum { diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index 90a5e0b535..f914fdc804 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -65,6 +65,7 @@ pub struct SwapChain { pub enum PresentMode { NoVsync = 0, Vsync = 1, + Mailbox = 2, } #[repr(C)] @@ -95,6 +96,7 @@ impl SwapChainDescriptor { config.present_mode = match self.present_mode { PresentMode::NoVsync => hal::window::PresentMode::IMMEDIATE, PresentMode::Vsync => hal::window::PresentMode::FIFO, + PresentMode::Mailbox => hal::window::PresentMode::MAILBOX, }; config } From fe95fddf5af4bdad4c3fff17bae5713993954716 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Fri, 6 Mar 2020 00:48:45 -0500 Subject: [PATCH 2/2] Use vulkan nomenclature for PresentMode variants https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPresentModeKHR.html --- examples/triangle/main.c | 4 ++-- ffi/wgpu.h | 6 +++--- wgpu-core/src/swap_chain.rs | 21 ++++++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/triangle/main.c b/examples/triangle/main.c index 05eab3e59a..dd0d8509b7 100644 --- a/examples/triangle/main.c +++ b/examples/triangle/main.c @@ -208,7 +208,7 @@ int main() { .format = WGPUTextureFormat_Bgra8Unorm, .width = prev_width, .height = prev_height, - .present_mode = WGPUPresentMode_Vsync, + .present_mode = WGPUPresentMode_Fifo, }); while (!glfwWindowShouldClose(window)) { @@ -225,7 +225,7 @@ int main() { .format = WGPUTextureFormat_Bgra8Unorm, .width = width, .height = height, - .present_mode = WGPUPresentMode_Vsync, + .present_mode = WGPUPresentMode_Fifo, }); } diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 0c6a89018c..9f94162f76 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -126,9 +126,9 @@ typedef enum { } WGPUPowerPreference; typedef enum { - WGPUPresentMode_NoVsync = 0, - WGPUPresentMode_Vsync = 1, - WGPUPresentMode_Mailbox = 2, + WGPUPresentMode_Immediate = 0, + WGPUPresentMode_Mailbox = 1, + WGPUPresentMode_Fifo = 2, } WGPUPresentMode; typedef enum { diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index f914fdc804..3205701b7c 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -63,9 +63,20 @@ pub struct SwapChain { #[repr(C)] #[derive(Copy, Clone, Debug)] pub enum PresentMode { - NoVsync = 0, - Vsync = 1, - Mailbox = 2, + /// The presentation engine does **not** wait for a vertical blanking period and + /// the request is presented immediately. This is a low-latency presentation mode, + /// but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the + /// selected platform and backend. Not optimal for mobile. + Immediate = 0, + /// The presentation engine waits for the next vertical blanking period to update + /// the current image, but frames may be submitted without delay. This is a low-latency + /// presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo` + /// if unavailable on the selected platform and backend. Not optimal for mobile. + Mailbox = 1, + /// The presentation engine waits for the next vertical blanking period to update + /// the current image. The framerate will be capped at the display refresh rate, + /// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile. + Fifo = 2, } #[repr(C)] @@ -94,9 +105,9 @@ impl SwapChainDescriptor { config.image_usage = conv::map_texture_usage(self.usage, hal::format::Aspects::COLOR); config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE; config.present_mode = match self.present_mode { - PresentMode::NoVsync => hal::window::PresentMode::IMMEDIATE, - PresentMode::Vsync => hal::window::PresentMode::FIFO, + PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE, PresentMode::Mailbox => hal::window::PresentMode::MAILBOX, + PresentMode::Fifo => hal::window::PresentMode::FIFO, }; config }