diff --git a/common/video/vulkan/vulkan_context.cpp b/common/video/vulkan/vulkan_context.cpp index 8cf4ae4e..12beddb5 100644 --- a/common/video/vulkan/vulkan_context.cpp +++ b/common/video/vulkan/vulkan_context.cpp @@ -11,6 +11,7 @@ static std::unique_ptr dl; Context::Context() { + swapchain = std::make_unique(*this); } Context::~Context() @@ -180,7 +181,6 @@ bool Context::init() init_command_pool(); init_descriptor_pool(); - swapchain = std::make_unique(*this); wait_idle(); return true; } diff --git a/common/video/vulkan/vulkan_swapchain.cpp b/common/video/vulkan/vulkan_swapchain.cpp index dc311c0a..f89c2abf 100644 --- a/common/video/vulkan/vulkan_swapchain.cpp +++ b/common/video/vulkan/vulkan_swapchain.cpp @@ -12,7 +12,6 @@ Swapchain::Swapchain(Context &context_) command_pool(context.command_pool.get()), surface(context.surface.get()) { - create_render_pass(); end_render_pass_function = nullptr; } @@ -152,6 +151,9 @@ bool Swapchain::uncreate() bool Swapchain::create() { + if (!render_pass) + create_render_pass(); + frames.clear(); image_data.clear(); diff --git a/gtk/src/gtk_display_driver_vulkan.cpp b/gtk/src/gtk_display_driver_vulkan.cpp index 3937a3ef..266811ad 100644 --- a/gtk/src/gtk_display_driver_vulkan.cpp +++ b/gtk/src/gtk_display_driver_vulkan.cpp @@ -130,15 +130,15 @@ int S9xVulkanDisplayDriver::init() wl_surface *surface = gdk_wayland_window_get_wl_surface(drawing_area->get_window()->gobj()); wl_display *display = gdk_wayland_display_get_wl_display(drawing_area->get_display()->gobj()); - if (!wayland_surface->attach(display, surface, get_metrics(*drawing_area))) - goto abort; - if (!context->init_wayland()) - goto abort; - if (!context->create_wayland_surface(wayland_surface->display, wayland_surface->child)) - goto abort; context->swapchain->set_desired_size(current_width, current_height); - if (!context->create_swapchain()) - goto abort; + if (!wayland_surface->attach(display, surface, get_metrics(*drawing_area)) || + !context->init_wayland() || + !context->create_wayland_surface(wayland_surface->display, wayland_surface->child) || + !context->create_swapchain()) + { + context.reset(); + return -1; + } } #endif if (GDK_IS_X11_WINDOW(drawing_area->get_window()->gobj())) @@ -146,12 +146,13 @@ int S9xVulkanDisplayDriver::init() display = gdk_x11_display_get_xdisplay(drawing_area->get_display()->gobj()); xid = gdk_x11_window_get_xid(drawing_area->get_window()->gobj()); - if (!context->init_Xlib()) - goto abort; - if (!context->create_Xlib_surface(display, xid)) - goto abort; - if (!context->create_swapchain()) - goto abort; + if (!context->init_Xlib() || + !context->create_Xlib_surface(display, xid) || + !context->create_swapchain()) + { + context.reset(); + return -1; + } } device = context->device; @@ -179,10 +180,6 @@ int S9xVulkanDisplayDriver::init() simple_output = std::make_unique(context.get(), vk::Format::eR5G6B5UnormPack16); return 0; - -abort: - context.reset(); - return -1; } void S9xVulkanDisplayDriver::deinit() diff --git a/qt/src/EmuCanvasVulkan.cpp b/qt/src/EmuCanvasVulkan.cpp index eca44852..aa48275e 100644 --- a/qt/src/EmuCanvasVulkan.cpp +++ b/qt/src/EmuCanvasVulkan.cpp @@ -89,12 +89,13 @@ bool EmuCanvasVulkan::createContext() #ifdef _WIN32 auto hwnd = (HWND)winId(); - if (!context->init_win32()) - goto fail; - if (!context->create_win32_surface(nullptr, hwnd)) - goto fail; - if (!context->swapchain->create()) - goto fail; + if (!context->init_win32() || + !context->create_win32_surface(nullptr, hwnd) || + !context->swapchain->create()) + { + context.reset(); + return false; + } #else if (platform == "wayland") { @@ -104,30 +105,27 @@ bool EmuCanvasVulkan::createContext() wayland_surface->attach(display, surface, { parent->x() - main_window->x(), parent->y() - main_window->y(), width(), height(), static_cast(devicePixelRatio()) }); auto [scaled_width, scaled_height] = wayland_surface->get_size(); - if (!context->init_wayland()) - goto fail; - - if (!context->create_wayland_surface(display, wayland_surface->child)) - goto fail; - context->swapchain->set_desired_size(scaled_width, scaled_height); - if (!context->swapchain->create()) - goto fail; + if (!context->init_wayland() || + !context->create_wayland_surface(display, wayland_surface->child) || + !context->swapchain->create()) + { + context.reset(); + return false; + } } else if (platform == "xcb") { auto display = (Display *)pni->nativeResourceForWindow("display", window); auto xid = (Window)winId(); - if (!context->init_Xlib()) - goto fail; - - if (!context->create_Xlib_surface(display, xid)) - goto fail; - - context->wait_idle(); - if (!context->swapchain->create()) - goto fail; + if (!context->init_Xlib() || + !context->create_Xlib_surface(display, xid) || + !context->swapchain->create()) + { + context.reset(); + return false; + } } #endif @@ -142,10 +140,6 @@ bool EmuCanvasVulkan::createContext() paintEvent(nullptr); return true; - -fail: - context.reset(); - return false; } void EmuCanvasVulkan::tryLoadShader()