vk/swapchain: Consolidate native swapchain implementation for platforms where it is not implemented

- NATIVE swapchain only matters in headless scenarios or where we otherwise cannot access WSI properly.
- It is now optional, with a stub provided when WSI is not available.
This commit is contained in:
kd-11 2025-03-01 14:31:16 +03:00
parent c499b5d964
commit 36e9a6b0dd
4 changed files with 25 additions and 122 deletions

View file

@ -5,52 +5,7 @@
namespace vk
{
#if defined(ANDROID)
class swapchain_ANDROID : public native_swapchain_base
{
void* surface_handle = nullptr; // FIXME: No idea what the android native surface is called
public:
swapchain_ANDROID(physical_device& gpu, u32 present_queue, u32 graphics_queue, u32 transfer_queue, VkFormat format = VK_FORMAT_B8G8R8A8_UNORM)
: native_swapchain_base(gpu, present_queue, graphics_queue, transfer_queue, format)
{}
~swapchain_ANDROID() {}
bool init() override
{
//TODO: get from `surface`
m_width = 0;
m_height = 0;
if (m_width == 0 || m_height == 0)
{
rsx_log.error("Invalid window dimensions %d x %d", m_width, m_height);
return false;
}
init_swapchain_images(dev, 3);
return true;
}
void create(display_handle_t& window_handle) override
{
surface_handle = window_handle;
}
void destroy(bool full = true) override
{
swapchain_images.clear();
if (full)
dev.destroy();
}
VkResult present(VkSemaphore /*semaphore*/, u32 /*index*/) override
{
fmt::throw_exception("Native macOS swapchain is not implemented yet!");
}
};
using swapchain_ANDROID = native_swapchain_base;
using swapchain_NATIVE = swapchain_ANDROID;
// TODO: Implement this

View file

@ -121,6 +121,28 @@ namespace vk
VkResult acquire_next_swapchain_image(VkSemaphore semaphore, u64 timeout, u32* result) override;
// Clients must implement these methods to render without WSI support
bool init() override
{
fmt::throw_exception("Native swapchain is not implemented yet!");
}
void create(display_handle_t& /*window_handle*/) override
{
fmt::throw_exception("Native swapchain is not implemented yet!");
}
void destroy(bool /*full*/ = true) override
{
fmt::throw_exception("Native swapchain is not implemented yet!");
}
VkResult present(VkSemaphore /*semaphore*/, u32 /*index*/) override
{
fmt::throw_exception("Native swapchain is not implemented yet!");
}
// Generic accessors
void end_frame(command_buffer& cmd, u32 index) override
{
swapchain_images[index].second->do_dma_transfer(cmd);

View file

@ -5,52 +5,7 @@
namespace vk
{
#if defined(__APPLE__)
class swapchain_MacOS : public native_swapchain_base
{
void* nsView = nullptr;
public:
swapchain_MacOS(physical_device& gpu, u32 present_queue, u32 graphics_queue, u32 transfer_queue, VkFormat format = VK_FORMAT_B8G8R8A8_UNORM)
: native_swapchain_base(gpu, present_queue, graphics_queue, transfer_queue, format)
{}
~swapchain_MacOS() {}
bool init() override
{
//TODO: get from `nsView`
m_width = 0;
m_height = 0;
if (m_width == 0 || m_height == 0)
{
rsx_log.error("Invalid window dimensions %d x %d", m_width, m_height);
return false;
}
init_swapchain_images(dev, 3);
return true;
}
void create(display_handle_t& window_handle) override
{
nsView = window_handle;
}
void destroy(bool full = true) override
{
swapchain_images.clear();
if (full)
dev.destroy();
}
VkResult present(VkSemaphore /*semaphore*/, u32 /*index*/) override
{
fmt::throw_exception("Native macOS swapchain is not implemented yet!");
}
};
using swapchain_MacOS = native_swapchain_base;
using swapchain_NATIVE = swapchain_MacOS;
static

View file

@ -122,36 +122,7 @@ namespace vk
#endif
#if defined(HAVE_WAYLAND)
class swapchain_Wayland : public native_swapchain_base
{
public:
swapchain_Wayland(physical_device& gpu, u32 present_queue, u32 graphics_queue, u32 transfer_queue, VkFormat format = VK_FORMAT_B8G8R8A8_UNORM)
: native_swapchain_base(gpu, present_queue, graphics_queue, transfer_queue, format)
{}
~swapchain_Wayland() {}
bool init() override
{
fmt::throw_exception("Native Wayland swapchain is not implemented yet!");
}
void create(display_handle_t& window_handle) override
{
fmt::throw_exception("Native Wayland swapchain is not implemented yet!");
}
void destroy(bool full = true) override
{
fmt::throw_exception("Native Wayland swapchain is not implemented yet!");
}
VkResult present(VkSemaphore /*semaphore*/, u32 index) override
{
fmt::throw_exception("Native Wayland swapchain is not implemented yet!");
}
};
using swapchain_Wayland = native_swapchain_base;
#ifndef HAVE_X11
using swapchain_NATIVE = swapchain_Wayland;