This commit is contained in:
parent
e94c91bd21
commit
79158399d7
1 changed files with 34 additions and 14 deletions
|
|
@ -66,7 +66,11 @@ public:
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet;
|
||||||
VkDescriptorSetLayout descriptorSetLayout;
|
VkDescriptorSetLayout descriptorSetLayout;
|
||||||
|
|
||||||
VkSemaphore presentCompleteSemaphore;
|
// Synchronization semaphores
|
||||||
|
struct {
|
||||||
|
VkSemaphore presentComplete;
|
||||||
|
VkSemaphore submitSignal;
|
||||||
|
} semaphores;
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
|
|
@ -92,7 +96,8 @@ public:
|
||||||
vkDestroyBuffer(device, indices.buf, nullptr);
|
vkDestroyBuffer(device, indices.buf, nullptr);
|
||||||
vkFreeMemory(device, indices.mem, nullptr);
|
vkFreeMemory(device, indices.mem, nullptr);
|
||||||
|
|
||||||
vkDestroySemaphore(device, presentCompleteSemaphore, nullptr);
|
vkDestroySemaphore(device, semaphores.presentComplete, nullptr);
|
||||||
|
vkDestroySemaphore(device, semaphores.submitSignal, nullptr);
|
||||||
|
|
||||||
vkDestroyBuffer(device, uniformDataVS.buffer, nullptr);
|
vkDestroyBuffer(device, uniformDataVS.buffer, nullptr);
|
||||||
vkFreeMemory(device, uniformDataVS.memory, nullptr);
|
vkFreeMemory(device, uniformDataVS.memory, nullptr);
|
||||||
|
|
@ -202,27 +207,38 @@ public:
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
// Get next image in the swap chain (back/front buffer)
|
// Get next image in the swap chain (back/front buffer)
|
||||||
err = swapChain.acquireNextImage(presentCompleteSemaphore, ¤tBuffer);
|
err = swapChain.acquireNextImage(semaphores.presentComplete, ¤tBuffer);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
// The submit infor strcuture contains a list of
|
// The submit infor strcuture contains a list of
|
||||||
// command buffers and semaphores to be submitted to a queue
|
// command buffers and semaphores to be submitted to a queue
|
||||||
// If you want to submit multiple command buffers, pass an array
|
// If you want to submit multiple command buffers, pass an array
|
||||||
|
VkPipelineStageFlags pipelineStages = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo = {};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
submitInfo.pWaitDstStageMask = &pipelineStages;
|
||||||
|
// The wait semaphore ensures that the image is presented
|
||||||
|
// before we start submitting command buffers agein
|
||||||
submitInfo.waitSemaphoreCount = 1;
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
submitInfo.pWaitSemaphores = &presentCompleteSemaphore;
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
||||||
// Submit the currently active command buffer
|
// Submit the currently active command buffer
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||||
|
// The signal semaphore is used during queue presentation
|
||||||
|
// to ensure that the image is not rendered before all
|
||||||
|
// commands have been submitted
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &semaphores.submitSignal;
|
||||||
|
|
||||||
// Submit to the graphics queue
|
// Submit to the graphics queue
|
||||||
err = vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
err = vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
// Present the current buffer to the swap chain
|
// Present the current buffer to the swap chain
|
||||||
// This will display the image
|
// We pass the signal semaphore from the submit info
|
||||||
err = swapChain.queuePresent(queue, currentBuffer);
|
// to ensure that the image is not rendered until
|
||||||
|
// all commands have been submitted
|
||||||
|
err = swapChain.queuePresent(queue, currentBuffer, semaphores.submitSignal);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
|
|
||||||
// Add a post present image memory barrier
|
// Add a post present image memory barrier
|
||||||
|
|
@ -276,17 +292,21 @@ public:
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a semaphore used to make sure that the image isn't rendered
|
// Create synchronzation semaphores
|
||||||
// until all commands have been submitted
|
|
||||||
// This is used to ensure that the image isn't presented until
|
|
||||||
// it's ready for presentation
|
|
||||||
void prepareSemaphore()
|
void prepareSemaphore()
|
||||||
{
|
{
|
||||||
VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {};
|
VkSemaphoreCreateInfo semaphoreCreateInfo = {};
|
||||||
presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
||||||
presentCompleteSemaphoreCreateInfo.pNext = NULL;
|
semaphoreCreateInfo.pNext = NULL;
|
||||||
|
|
||||||
VkResult err = vkCreateSemaphore(device, &presentCompleteSemaphoreCreateInfo, nullptr, &presentCompleteSemaphore);
|
// This semaphore ensures that the image is complete
|
||||||
|
// before starting to submit again
|
||||||
|
VkResult err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphores.presentComplete);
|
||||||
|
assert(!err);
|
||||||
|
|
||||||
|
// This semaphore ensures that all commands submitted
|
||||||
|
// have been finished before submitting the image to the queue
|
||||||
|
err = vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphores.submitSignal);
|
||||||
assert(!err);
|
assert(!err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue