aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorszdarkhack <szdarkhack@hotmail.com>2016-10-08 09:51:22 +0300
committerTony Barbour <tony@LunarG.com>2016-10-11 11:01:39 -0600
commitd322ff06db2fb6432cca90d445debde0215ed221 (patch)
tree8bdbd1c0e1bf44194798c9ebbd4c21f46191a126
parentaae7aa38d5ba9b8c41f218a2168c31506a53a82b (diff)
downloadusermoji-d322ff06db2fb6432cca90d445debde0215ed221.tar.xz
cube.c: Remove excess tests from presentation fences
Instead of using a bool array and both checking and writing to it every frame for no reason, just create the presentation fences with the VK_FENCE_CREATE_SIGNALED_BIT flag.
-rw-r--r--demos/cube.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/demos/cube.c b/demos/cube.c
index f497ab32..5a23657d 100644
--- a/demos/cube.c
+++ b/demos/cube.c
@@ -356,7 +356,6 @@ struct demo {
VkSwapchainKHR swapchain;
SwapchainBuffers *buffers;
VkFence fences[FRAME_LAG];
- bool fencesInited[FRAME_LAG];
int frame_index;
VkCommandPool cmd_pool;
@@ -786,18 +785,14 @@ void demo_update_data_buffer(struct demo *demo) {
static void demo_draw(struct demo *demo) {
VkResult U_ASSERT_ONLY err;
- if (demo->fencesInited[demo->frame_index])
- {
- // Ensure no more than FRAME_LAG presentations are outstanding
- vkWaitForFences(demo->device, 1, &demo->fences[demo->frame_index], VK_TRUE, UINT64_MAX);
- vkResetFences(demo->device, 1, &demo->fences[demo->frame_index]);
- }
+ // Ensure no more than FRAME_LAG presentations are outstanding
+ vkWaitForFences(demo->device, 1, &demo->fences[demo->frame_index], VK_TRUE, UINT64_MAX);
+ vkResetFences(demo->device, 1, &demo->fences[demo->frame_index]);
// Get the index of the next available swapchain image:
err = demo->fpAcquireNextImageKHR(demo->device, demo->swapchain, UINT64_MAX,
demo->image_acquired_semaphores[demo->frame_index], demo->fences[demo->frame_index],
&demo->current_buffer);
- demo->fencesInited[demo->frame_index] = true;
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
// demo->swapchain is out of date (e.g. the window was resized) and
@@ -2043,9 +2038,7 @@ static void demo_cleanup(struct demo *demo) {
// Wait for fences from present operations
for (i = 0; i < FRAME_LAG; i++) {
- if (demo->fencesInited[i]) {
- vkWaitForFences(demo->device, 1, &demo->fences[i], VK_TRUE, UINT64_MAX);
- }
+ vkWaitForFences(demo->device, 1, &demo->fences[i], VK_TRUE, UINT64_MAX);
vkDestroyFence(demo->device, demo->fences[i], NULL);
vkDestroySemaphore(demo->device, demo->image_acquired_semaphores[i], NULL);
vkDestroySemaphore(demo->device, demo->draw_complete_semaphores[i], NULL);
@@ -3155,11 +3148,10 @@ static void demo_init_vk_swapchain(struct demo *demo) {
VkFenceCreateInfo fence_ci = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
- .flags = 0
+ .flags = VK_FENCE_CREATE_SIGNALED_BIT
};
for (uint32_t i = 0; i < FRAME_LAG; i++) {
vkCreateFence(demo->device, &fence_ci, NULL, &demo->fences[i]);
- demo->fencesInited[i] = false;
err = vkCreateSemaphore(demo->device, &semaphoreCreateInfo, NULL,
&demo->image_acquired_semaphores[i]);
assert(!err);