Skip to content

Commit

Permalink
Port to new vulkano
Browse files Browse the repository at this point in the history
This might fix the issue with resizing causing swapchain re-creation
errors, because "Swapchain creation no longer returns an error when the
swapchain extent doesn't match the current surface extent."

cc #3850
  • Loading branch information
tronical committed Nov 11, 2023
1 parent df7657d commit 62dfbd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/renderers/skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ unicode-segmentation = { version = "1.8.0" }
glutin = { workspace = true, default-features = false, features = ["egl", "wgl"] }

ash = { version = "^0.37.2", optional = true }
vulkano = { version = "0.33.0", optional = true, default-features = false }
vulkano = { version = "0.34.0", optional = true, default-features = false }

[target.'cfg(not(target_os = "android"))'.dependencies]
# software renderer fallback
Expand Down
34 changes: 17 additions & 17 deletions internal/renderers/skia/vulkan_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ use vulkano::device::{
Device, DeviceCreateInfo, DeviceExtensions, Queue, QueueCreateInfo, QueueFlags,
};
use vulkano::image::view::ImageView;
use vulkano::image::{ImageAccess, ImageUsage, ImageViewAbstract, SwapchainImage};
use vulkano::instance::{Instance, InstanceCreateInfo, InstanceExtensions};
use vulkano::swapchain::{
AcquireError, Surface, Swapchain, SwapchainCreateInfo, SwapchainPresentInfo,
};
use vulkano::sync::{FlushError, GpuFuture};
use vulkano::{sync, Handle, VulkanLibrary, VulkanObject};
use vulkano::image::{Image, ImageUsage};
use vulkano::instance::{Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions};
use vulkano::swapchain::{Surface, Swapchain, SwapchainCreateInfo, SwapchainPresentInfo};
use vulkano::sync::GpuFuture;
use vulkano::{sync, Handle, Validated, VulkanError, VulkanLibrary, VulkanObject};

use raw_window_handle::HasRawDisplayHandle;
use raw_window_handle::HasRawWindowHandle;
Expand All @@ -30,8 +28,8 @@ pub struct VulkanSurface {
previous_frame_end: RefCell<Option<Box<dyn GpuFuture>>>,
queue: Arc<Queue>,
swapchain: RefCell<Arc<Swapchain>>,
swapchain_images: RefCell<Vec<Arc<SwapchainImage>>>,
swapchain_image_views: RefCell<Vec<Arc<ImageView<SwapchainImage>>>>,
swapchain_images: RefCell<Vec<Arc<Image>>>,
swapchain_image_views: RefCell<Vec<Arc<ImageView>>>,
}

impl VulkanSurface {
Expand Down Expand Up @@ -185,8 +183,8 @@ impl super::Surface for VulkanSurface {
let instance = Instance::new(
library.clone(),
InstanceCreateInfo {
flags: InstanceCreateFlags::ENUMERATE_PORTABILITY,
enabled_extensions: required_extensions,
enumerate_portability: true,
..Default::default()
},
)
Expand Down Expand Up @@ -273,9 +271,11 @@ impl super::Surface for VulkanSurface {
let swapchain = self.swapchain.borrow().clone();

let (image_index, suboptimal, acquire_future) =
match vulkano::swapchain::acquire_next_image(swapchain.clone(), None) {
match vulkano::swapchain::acquire_next_image(swapchain.clone(), None)
.map_err(Validated::unwrap)
{
Ok(r) => r,
Err(AcquireError::OutOfDate) => {
Err(VulkanError::OutOfDate) => {
self.recreate_swapchain.set(true);
return Ok(()); // Try again next frame
}
Expand All @@ -300,14 +300,14 @@ impl super::Surface for VulkanSurface {

let format = image_view.format();

debug_assert_eq!(format, Some(vulkano::format::Format::B8G8R8A8_UNORM));
debug_assert_eq!(format, vulkano::format::Format::B8G8R8A8_UNORM);
let (vk_format, color_type) =
(skia_safe::gpu::vk::Format::B8G8R8A8_UNORM, skia_safe::ColorType::BGRA8888);

let alloc = skia_safe::gpu::vk::Alloc::default();
let image_info = &unsafe {
skia_safe::gpu::vk::ImageInfo::new(
image_object.inner().image.handle().as_raw() as _,
image_object.handle().as_raw() as _,
alloc,
skia_safe::gpu::vk::ImageTiling::OPTIMAL,
skia_safe::gpu::vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
Expand Down Expand Up @@ -351,11 +351,11 @@ impl super::Surface for VulkanSurface {
)
.then_signal_fence_and_flush();

match future {
match future.map_err(Validated::unwrap) {
Ok(future) => {
*self.previous_frame_end.borrow_mut() = Some(future.boxed());
}
Err(FlushError::OutOfDate) => {
Err(VulkanError::OutOfDate) => {
self.recreate_swapchain.set(true);
*self.previous_frame_end.borrow_mut() = Some(sync::now(device.clone()).boxed());
}
Expand Down Expand Up @@ -389,7 +389,7 @@ fn create_surface(
instance: &Arc<Instance>,
window_handle: raw_window_handle::WindowHandle<'_>,
display_handle: raw_window_handle::DisplayHandle<'_>,
) -> Result<Arc<Surface>, vulkano::swapchain::SurfaceCreationError> {
) -> Result<Arc<Surface>, vulkano::Validated<vulkano::VulkanError>> {
match (window_handle.raw_window_handle(), display_handle.raw_display_handle()) {
#[cfg(target_os = "macos")]
(
Expand Down

0 comments on commit 62dfbd7

Please sign in to comment.