From 9dc834a0ac694d576a584a89f72733a0bb2f4485 Mon Sep 17 00:00:00 2001 From: James0124 Date: Mon, 27 Feb 2023 18:52:09 +0900 Subject: [PATCH] Treat `VK_SUBOPTIMAL_KHR` as `VK_SUCCESS` on Android. (#3525) --- CHANGELOG.md | 4 ++++ wgpu-hal/src/vulkan/instance.rs | 5 +++++ wgpu-hal/src/vulkan/mod.rs | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356bc2d80c..23009baaa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,10 @@ By @teoxoy in [#3436](https://github.com/gfx-rs/wgpu/pull/3436) - `copyTextureToTexture` src/dst aspects must both refer to all aspects of src/dst format. By @teoxoy in [#3431](https://github.com/gfx-rs/wgpu/pull/3431) - Validate before extracting texture selectors. By @teoxoy in [#3487](https://github.com/gfx-rs/wgpu/pull/3487) +#### Vulkan + +- Treat `VK_SUBOPTIMAL_KHR` as `VK_SUCCESS` on Android. By @James2022-rgb in [#3525](https://github.com/gfx-rs/wgpu/pull/3525) + ## wgpu-0.15.0 (2023-01-25) ### Major Changes diff --git a/wgpu-hal/src/vulkan/instance.rs b/wgpu-hal/src/vulkan/instance.rs index 186334e08f..328795a13b 100644 --- a/wgpu-hal/src/vulkan/instance.rs +++ b/wgpu-hal/src/vulkan/instance.rs @@ -758,6 +758,11 @@ impl crate::Surface for super::Surface { sc.functor .acquire_next_image(sc.raw, timeout_ns, vk::Semaphore::null(), sc.fence) } { + // We treat `VK_SUBOPTIMAL_KHR` as `VK_SUCCESS` on Android. + // See the comment in `Queue::present`. + #[cfg(target_os = "android")] + Ok((index, _)) => (index, false), + #[cfg(not(target_os = "android"))] Ok(pair) => pair, Err(error) => { return match error { diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index ee30224b07..06b139f54b 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -595,6 +595,11 @@ impl crate::Queue for Queue { })? }; if suboptimal { + // We treat `VK_SUBOPTIMAL_KHR` as `VK_SUCCESS` on Android. + // On Android 10+, libvulkan's `vkQueuePresentKHR` implementation returns `VK_SUBOPTIMAL_KHR` if not doing pre-rotation + // (i.e `VkSwapchainCreateInfoKHR::preTransform` not being equal to the current device orientation). + // This is always the case when the device orientation is anything other than the identity one, as we unconditionally use `VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR`. + #[cfg(not(target_os = "android"))] log::warn!("Suboptimal present of frame {}", texture.index); } Ok(())