Implement swapchain image acquisition

This commit is contained in:
Bill Currie 2020-02-14 11:11:27 +09:00
parent 53b46f0541
commit d56f88f779
2 changed files with 33 additions and 0 deletions

View file

@ -13,5 +13,10 @@ struct vulkan_ctx_s;
qfv_swapchain_t *QFV_CreateSwapchain (struct vulkan_ctx_s *ctx, qfv_swapchain_t *QFV_CreateSwapchain (struct vulkan_ctx_s *ctx,
VkSwapchainKHR old_swapchain); VkSwapchainKHR old_swapchain);
void QFV_DestroySwapchain (qfv_swapchain_t *swapchain); void QFV_DestroySwapchain (qfv_swapchain_t *swapchain);
struct qfv_semaphore_s;
struct qfv_fence_s;
int QFV_AcquireNextImage (qfv_swapchain_t *swapchain,
struct qfv_semaphore_s *semaphore,
struct qfv_fence_s *fence, uint32_t *imageIndex);
#endif//__QF_Vulkan_swapchain_h #endif//__QF_Vulkan_swapchain_h

View file

@ -11,6 +11,7 @@
#include "QF/sys.h" #include "QF/sys.h"
#include "QF/Vulkan/qf_vid.h" #include "QF/Vulkan/qf_vid.h"
#include "QF/Vulkan/cvars.h" #include "QF/Vulkan/cvars.h"
#include "QF/Vulkan/command.h"
#include "QF/Vulkan/device.h" #include "QF/Vulkan/device.h"
#include "QF/Vulkan/instance.h" #include "QF/Vulkan/instance.h"
#include "QF/Vulkan/swapchain.h" #include "QF/Vulkan/swapchain.h"
@ -157,3 +158,30 @@ QFV_DestroySwapchain (qfv_swapchain_t *swapchain)
dfunc->vkDestroySwapchainKHR (dev, swapchain->swapchain, 0); dfunc->vkDestroySwapchainKHR (dev, swapchain->swapchain, 0);
free (swapchain); free (swapchain);
} }
int
QFV_AcquireNextImage (qfv_swapchain_t *swapchain, qfv_semaphore_t *semaphore,
qfv_fence_t *fence, uint32_t *imageIndex)
{
qfv_device_t *device = swapchain->device;
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
uint64_t timeout = 2000000000;
VkSemaphore sem = semaphore ? semaphore->semaphore : VK_NULL_HANDLE;
VkFence fnc = fence ? fence->fence : VK_NULL_HANDLE;
*imageIndex = ~0u;
VkResult res = dfunc->vkAcquireNextImageKHR (dev, swapchain->swapchain,
timeout, sem, fnc,
imageIndex);
switch (res) {
case VK_SUCCESS:
case VK_TIMEOUT:
case VK_NOT_READY:
return 1;
case VK_SUBOPTIMAL_KHR:
case VK_ERROR_OUT_OF_DATE_KHR:
return 0;
default:
Sys_Error ("vkAcquireNextImageKHR failed: %d", res);
}
}