Skip to content

Commit 79e9ab7

Browse files
bors[bot]aloucks
andauthored
Merge #512
512: Add PresentMode::Mailbox r=kvark a=aloucks @kvark Would you be open to renaming the presents modes to match the vulkan/gfx-hal nomenclature? Considering these aren't part of the webgpu spec, I think it would make more sense to keep things consistent. I can update this PR if you're good with it. ```rust pub enum PresentMode { /// 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, } ``` Co-authored-by: Aaron Loucks <[email protected]>
2 parents 584c9d7 + fe95fdd commit 79e9ab7

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

examples/triangle/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int main() {
208208
.format = WGPUTextureFormat_Bgra8Unorm,
209209
.width = prev_width,
210210
.height = prev_height,
211-
.present_mode = WGPUPresentMode_Vsync,
211+
.present_mode = WGPUPresentMode_Fifo,
212212
});
213213

214214
while (!glfwWindowShouldClose(window)) {
@@ -225,7 +225,7 @@ int main() {
225225
.format = WGPUTextureFormat_Bgra8Unorm,
226226
.width = width,
227227
.height = height,
228-
.present_mode = WGPUPresentMode_Vsync,
228+
.present_mode = WGPUPresentMode_Fifo,
229229
});
230230
}
231231

ffi/wgpu.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ typedef enum {
126126
} WGPUPowerPreference;
127127

128128
typedef enum {
129-
WGPUPresentMode_NoVsync = 0,
130-
WGPUPresentMode_Vsync = 1,
129+
WGPUPresentMode_Immediate = 0,
130+
WGPUPresentMode_Mailbox = 1,
131+
WGPUPresentMode_Fifo = 2,
131132
} WGPUPresentMode;
132133

133134
typedef enum {

wgpu-core/src/swap_chain.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,20 @@ pub struct SwapChain<B: hal::Backend> {
6363
#[repr(C)]
6464
#[derive(Copy, Clone, Debug)]
6565
pub enum PresentMode {
66-
NoVsync = 0,
67-
Vsync = 1,
66+
/// The presentation engine does **not** wait for a vertical blanking period and
67+
/// the request is presented immediately. This is a low-latency presentation mode,
68+
/// but visible tearing may be observed. Will fallback to `Fifo` if unavailable on the
69+
/// selected platform and backend. Not optimal for mobile.
70+
Immediate = 0,
71+
/// The presentation engine waits for the next vertical blanking period to update
72+
/// the current image, but frames may be submitted without delay. This is a low-latency
73+
/// presentation mode and visible tearing will **not** be observed. Will fallback to `Fifo`
74+
/// if unavailable on the selected platform and backend. Not optimal for mobile.
75+
Mailbox = 1,
76+
/// The presentation engine waits for the next vertical blanking period to update
77+
/// the current image. The framerate will be capped at the display refresh rate,
78+
/// corresponding to the `VSync`. Tearing cannot be observed. Optimal for mobile.
79+
Fifo = 2,
6880
}
6981

7082
#[repr(C)]
@@ -93,8 +105,9 @@ impl SwapChainDescriptor {
93105
config.image_usage = conv::map_texture_usage(self.usage, hal::format::Aspects::COLOR);
94106
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
95107
config.present_mode = match self.present_mode {
96-
PresentMode::NoVsync => hal::window::PresentMode::IMMEDIATE,
97-
PresentMode::Vsync => hal::window::PresentMode::FIFO,
108+
PresentMode::Immediate => hal::window::PresentMode::IMMEDIATE,
109+
PresentMode::Mailbox => hal::window::PresentMode::MAILBOX,
110+
PresentMode::Fifo => hal::window::PresentMode::FIFO,
98111
};
99112
config
100113
}

0 commit comments

Comments
 (0)