Commit 863af429 authored by Niklas Haas's avatar Niklas Haas

Revert "swapchain: improve latency consistency and documentation"

This reverts commit 52c21bbc.
parent 4d36fc44
...@@ -74,11 +74,12 @@ struct pl_swapchain_frame { ...@@ -74,11 +74,12 @@ struct pl_swapchain_frame {
// Retrieve a new frame from the swapchain. Returns whether successful. It's // Retrieve a new frame from the swapchain. Returns whether successful. It's
// worth noting that this function can fail sporadically for benign reasons, // worth noting that this function can fail sporadically for benign reasons,
// for example the window being invisible or inaccessible. This function *may* // for example the window being invisible or inaccessible. This function may
// block until an image is available, which may be the case if the user not // block until an image is available, which may be the case if the GPU is
// calling `pl_swapchain_swap_buffers` often enough to meter rendering. It may // rendering frames significantly faster than the display can output them. It
// also be non-blocking, so users shouldn't rely on this call alone in order to // may also be non-blocking, so users shouldn't rely on this call alone in
// meter rendering speed. (Specifics depend on the underlying graphics API) // order to meter rendering speed. (Specifics depend on the underlying graphics
// API)
bool pl_swapchain_start_frame(const struct pl_swapchain *sw, bool pl_swapchain_start_frame(const struct pl_swapchain *sw,
struct pl_swapchain_frame *out_frame); struct pl_swapchain_frame *out_frame);
...@@ -95,9 +96,8 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw); ...@@ -95,9 +96,8 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw);
// Performs a "buffer swap", or some generalization of the concept. In layman's // Performs a "buffer swap", or some generalization of the concept. In layman's
// terms, this blocks until the execution of the Nth previously submitted frame // terms, this blocks until the execution of the Nth previously submitted frame
// has been "made complete/visible" in some sense. (The N derives from the // has been "made complete" in some sense. (The N derives from the swapchain's
// swapchain's built-in latency. See `pl_swapchain_latency` for more // built-in latency. See `pl_swapchain_latency` for more information).
// information).
// //
// Users should include this call in their rendering loops in order to make // Users should include this call in their rendering loops in order to make
// sure they aren't submitting rendering commands faster than the GPU can // sure they aren't submitting rendering commands faster than the GPU can
...@@ -110,11 +110,11 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw); ...@@ -110,11 +110,11 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw);
// struct pl_swapchain_frame frame; // struct pl_swapchain_frame frame;
// bool ok = pl_swapchain_start_frame(swapchain, &frame); // bool ok = pl_swapchain_start_frame(swapchain, &frame);
// if (!ok) { // if (!ok) {
// // wait some time, or decide to stop rendering // /* wait some time, or decide to stop rendering */
// continue; // continue;
// } // }
// //
// // do some rendering with frame.fbo // /* do some rendering with frame.fbo */
// //
// ok = pl_swapchain_submit_frame(swapchain); // ok = pl_swapchain_submit_frame(swapchain);
// if (!ok) // if (!ok)
...@@ -125,7 +125,8 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw); ...@@ -125,7 +125,8 @@ bool pl_swapchain_submit_frame(const struct pl_swapchain *sw);
// //
// The duration this function blocks for, if at all, may be very inconsistent // The duration this function blocks for, if at all, may be very inconsistent
// and should not be used as an authoritative source of vsync timing // and should not be used as an authoritative source of vsync timing
// information without sufficient smoothing/filtering. // information without sufficient smoothing/filtering (and if so, the time that
// `start_frame` blocked for should also be included).
void pl_swapchain_swap_buffers(const struct pl_swapchain *sw); void pl_swapchain_swap_buffers(const struct pl_swapchain *sw);
#endif // LIBPLACEBO_SWAPCHAIN_H_ #endif // LIBPLACEBO_SWAPCHAIN_H_
...@@ -34,7 +34,6 @@ struct priv { ...@@ -34,7 +34,6 @@ struct priv {
int frames_in_flight; // number of frames currently queued int frames_in_flight; // number of frames currently queued
struct pl_color_repr color_repr; struct pl_color_repr color_repr;
struct pl_color_space color_space; struct pl_color_space color_space;
struct pl_swapchain_frame cached_frame; // cached next frame
// state of the images: // state of the images:
const struct pl_tex **images; // pl_tex wrappers for the VkImages const struct pl_tex **images; // pl_tex wrappers for the VkImages
...@@ -441,8 +440,6 @@ static bool vk_sw_recreate(const struct pl_swapchain *sw) ...@@ -441,8 +440,6 @@ static bool vk_sw_recreate(const struct pl_swapchain *sw)
VkImage *vkimages = NULL; VkImage *vkimages = NULL;
int num_images = 0; int num_images = 0;
p->cached_frame.fbo = NULL;
p->last_imgidx = -1;
// It's invalid to trigger another swapchain recreation while there's more // It's invalid to trigger another swapchain recreation while there's more
// than one swapchain already active, so we need to flush any pending // than one swapchain already active, so we need to flush any pending
...@@ -537,18 +534,6 @@ static bool vk_sw_start_frame(const struct pl_swapchain *sw, ...@@ -537,18 +534,6 @@ static bool vk_sw_start_frame(const struct pl_swapchain *sw,
if (!p->swapchain && !vk_sw_recreate(sw)) if (!p->swapchain && !vk_sw_recreate(sw))
return false; return false;
// If we already had a cached frame, re-use that directly
if (p->cached_frame.fbo) {
*out_frame = p->cached_frame;
p->cached_frame.fbo = NULL;
return true;
}
if (p->last_imgidx >= 0) {
PL_ERR(sw, "pl_swapchain_start_frame called twice in a row?");
return false;
}
VkSemaphore sem_in = p->sems_in[p->idx_sems]; VkSemaphore sem_in = p->sems_in[p->idx_sems];
PL_TRACE(vk, "vkAcquireNextImageKHR signals %p", (void *) sem_in); PL_TRACE(vk, "vkAcquireNextImageKHR signals %p", (void *) sem_in);
...@@ -585,7 +570,6 @@ static bool vk_sw_start_frame(const struct pl_swapchain *sw, ...@@ -585,7 +570,6 @@ static bool vk_sw_start_frame(const struct pl_swapchain *sw,
// If we've exhausted the number of attempts to recreate the swapchain, // If we've exhausted the number of attempts to recreate the swapchain,
// just give up silently and let the user retry some time later. // just give up silently and let the user retry some time later.
p->last_imgidx = -1;
return false; return false;
} }
...@@ -602,18 +586,10 @@ static bool vk_sw_submit_frame(const struct pl_swapchain *sw) ...@@ -602,18 +586,10 @@ static bool vk_sw_submit_frame(const struct pl_swapchain *sw)
if (!p->swapchain) if (!p->swapchain)
return false; return false;
if (p->last_imgidx < 0) {
PL_ERR(sw, "pl_swapchain_submit_frame called without start_frame?");
return false;
}
uint32_t imgidx = p->last_imgidx;
p->last_imgidx = -1;
VkSemaphore sem_out = p->sems_out[p->idx_sems++]; VkSemaphore sem_out = p->sems_out[p->idx_sems++];
p->idx_sems %= p->num_sems; p->idx_sems %= p->num_sems;
pl_vulkan_hold(gpu, p->images[imgidx], pl_vulkan_hold(gpu, p->images[p->last_imgidx],
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_ACCESS_MEMORY_READ_BIT, sem_out); VK_ACCESS_MEMORY_READ_BIT, sem_out);
...@@ -641,7 +617,7 @@ static bool vk_sw_submit_frame(const struct pl_swapchain *sw) ...@@ -641,7 +617,7 @@ static bool vk_sw_submit_frame(const struct pl_swapchain *sw)
.pWaitSemaphores = &sem_out, .pWaitSemaphores = &sem_out,
.swapchainCount = 1, .swapchainCount = 1,
.pSwapchains = &p->swapchain, .pSwapchains = &p->swapchain,
.pImageIndices = &imgidx, .pImageIndices = &p->last_imgidx,
}; };
PL_TRACE(vk, "vkQueuePresentKHR waits on %p", (void *) sem_out); PL_TRACE(vk, "vkQueuePresentKHR waits on %p", (void *) sem_out);
...@@ -669,14 +645,6 @@ static void vk_sw_swap_buffers(const struct pl_swapchain *sw) ...@@ -669,14 +645,6 @@ static void vk_sw_swap_buffers(const struct pl_swapchain *sw)
while (p->frames_in_flight >= p->swapchain_depth) while (p->frames_in_flight >= p->swapchain_depth)
vk_poll_commands(p->vk, 1000000); // 1 ms vk_poll_commands(p->vk, 1000000); // 1 ms
// Pre-fetch the next swapchain image (if possible), since this will also
// typically block. If not possible, just ignore the error (the user
// will most likely run into it on the next `start_frame` call)
if (!p->cached_frame.fbo && p->last_imgidx < 0) {
if (!vk_sw_start_frame(sw, &p->cached_frame))
p->cached_frame.fbo = NULL;
}
} }
static struct pl_sw_fns vulkan_swapchain = { static struct pl_sw_fns vulkan_swapchain = {
......
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