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 <aloucks@cofront.net>
This commit is contained in:
bors[bot]
2020-03-06 15:04:41 +00:00
committed by GitHub
3 changed files with 22 additions and 8 deletions

View File

@@ -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,
});
}

View File

@@ -126,8 +126,9 @@ typedef enum {
} WGPUPowerPreference;
typedef enum {
WGPUPresentMode_NoVsync = 0,
WGPUPresentMode_Vsync = 1,
WGPUPresentMode_Immediate = 0,
WGPUPresentMode_Mailbox = 1,
WGPUPresentMode_Fifo = 2,
} WGPUPresentMode;
typedef enum {

View File

@@ -63,8 +63,20 @@ pub struct SwapChain<B: hal::Backend> {
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub enum PresentMode {
NoVsync = 0,
Vsync = 1,
/// 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)]
@@ -93,8 +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
}