Commit 0ba467b5 authored by Niklas Haas's avatar Niklas Haas

vulkan: allow suppressing suboptimal swapchain recreation

Clients like mpv which handle resize events on their own anyway can set
this in order to control the exact timing of swapchain recreations,
possibly delaying it until the next frame as appropriate - or doing it
at a more convenient time, rather than immediately before frame
acquisition.
parent f947e1d1
Pipeline #12071 passed with stages
in 2 minutes and 32 seconds
......@@ -2,7 +2,7 @@ project('libplacebo', ['c', 'cpp'],
license: 'LGPL2.1+',
default_options: ['c_std=c99'],
meson_version: '>=0.47',
version: '1.28.0',
version: '1.29.0',
)
# Version number
......
......@@ -229,6 +229,14 @@ struct pl_vulkan_swapchain_params {
// finished displaying it. So this only provides a rough guideline.
// Optional, defaults to 3.
int swapchain_depth;
// This suppresses automatic recreation of the swapchain when any call
// returns VK_SUBOPTIMAL_KHR. Normally, libplacebo will recreate the
// swapchain internally on the next `pl_swapchain_start_frame`. If enabled,
// clients are assumed to take care of swapchain recreations themselves, by
// calling `pl_swapchain_resize` as appropriate. libplacebo will tolerate
// the "suboptimal" status indefinitely.
bool allow_suboptimal;
};
// Creates a new vulkan swapchain based on an existing VkSurfaceKHR. Using this
......@@ -238,6 +246,11 @@ struct pl_vulkan_swapchain_params {
const struct pl_swapchain *pl_vulkan_create_swapchain(const struct pl_vulkan *vk,
const struct pl_vulkan_swapchain_params *params);
// This will return true if the vulkan swapchain is internally detected
// as being suboptimal (VK_SUBOPTIMAL_KHR). This might be of use to clients
// who have `params->allow_suboptimal` enabled.
bool pl_vulkan_swapchain_suboptimal(const struct pl_vulkan *vk);
// VkImage interop API
// Wraps an external VkImage into a pl_tex abstraction. By default, the image
......
......@@ -27,6 +27,7 @@ struct priv {
VkSurfaceKHR surf;
// current swapchain and metadata:
struct pl_vulkan_swapchain_params params;
VkSwapchainCreateInfoKHR protoInfo; // partially filled-in prototype
VkSwapchainKHR swapchain;
VkSwapchainKHR old_swapchain;
......@@ -263,6 +264,7 @@ const struct pl_swapchain *pl_vulkan_create_swapchain(const struct pl_vulkan *pl
sw->gpu = gpu;
struct priv *p = TA_PRIV(sw);
p->params = *params;
p->vk = vk;
p->surf = params->surface;
p->swapchain_depth = PL_DEF(params->swapchain_depth, 3);
......@@ -572,9 +574,15 @@ static bool vk_sw_start_frame(const struct pl_swapchain *sw,
{
struct priv *p = TA_PRIV(sw);
struct vk_ctx *vk = p->vk;
if ((!p->swapchain || p->suboptimal) && !vk_sw_recreate(sw, 0, 0))
if (!p->swapchain && !vk_sw_recreate(sw, 0, 0))
return false;
if (p->suboptimal && !p->params.allow_suboptimal) {
PL_TRACE(vk, "Swapchain is suboptimal, recreating...");
if (!vk_sw_recreate(sw, 0, 0))
return false;
}
VkSemaphore sem_in = p->sems_in[p->idx_sems];
PL_TRACE(vk, "vkAcquireNextImageKHR signals %p", (void *) sem_in);
......@@ -708,6 +716,12 @@ static bool vk_sw_resize(const struct pl_swapchain *sw, int *width, int *height)
return ok;
}
bool pl_vulkan_swapchain_suboptimal(const struct pl_vulkan *vk)
{
struct priv *p = TA_PRIV(vk);
return p->suboptimal;
}
static struct pl_sw_fns vulkan_swapchain = {
.destroy = vk_sw_destroy,
.latency = vk_sw_latency,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment