Vulkan: Allocate swapchain on context create.

This commit is contained in:
BearOso 2024-10-07 14:43:52 -05:00
parent befb0ba768
commit 13824a6ef4
4 changed files with 40 additions and 47 deletions

View File

@ -11,6 +11,7 @@ static std::unique_ptr<vk::DynamicLoader> dl;
Context::Context()
{
swapchain = std::make_unique<Swapchain>(*this);
}
Context::~Context()
@ -180,7 +181,6 @@ bool Context::init()
init_command_pool();
init_descriptor_pool();
swapchain = std::make_unique<Swapchain>(*this);
wait_idle();
return true;
}

View File

@ -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();

View File

@ -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<Vulkan::SimpleOutput>(context.get(), vk::Format::eR5G6B5UnormPack16);
return 0;
abort:
context.reset();
return -1;
}
void S9xVulkanDisplayDriver::deinit()

View File

@ -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<int>(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()