Added function for submitting a pre present image memory barrier, moved barrier setup into functions, removed unnecessary vkQueueWaitIdle
This commit is contained in:
parent
80c6fc0206
commit
cf02e5aa4b
2 changed files with 45 additions and 13 deletions
|
|
@ -109,10 +109,12 @@ void VulkanExampleBase::createCommandBuffers()
|
|||
VkResult vkRes = vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, drawCmdBuffers.data());
|
||||
assert(!vkRes);
|
||||
|
||||
// Create one command buffer for submitting the
|
||||
// post present image memory barrier
|
||||
// Command buffers for submitting present barriers
|
||||
cmdBufAllocateInfo.commandBufferCount = 1;
|
||||
|
||||
// Pre present
|
||||
vkRes = vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &prePresentCmdBuffer);
|
||||
assert(!vkRes);
|
||||
// Post present
|
||||
vkRes = vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &postPresentCmdBuffer);
|
||||
assert(!vkRes);
|
||||
}
|
||||
|
|
@ -120,6 +122,7 @@ void VulkanExampleBase::createCommandBuffers()
|
|||
void VulkanExampleBase::destroyCommandBuffers()
|
||||
{
|
||||
vkFreeCommandBuffers(device, cmdPool, (uint32_t)drawCmdBuffers.size(), drawCmdBuffers.data());
|
||||
vkFreeCommandBuffers(device, cmdPool, 1, &prePresentCmdBuffer);
|
||||
vkFreeCommandBuffers(device, cmdPool, 1, &postPresentCmdBuffer);
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +350,34 @@ void VulkanExampleBase::renderLoop()
|
|||
#endif
|
||||
}
|
||||
|
||||
// todo : comment
|
||||
void VulkanExampleBase::submitPrePresentBarrier(VkImage image)
|
||||
{
|
||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||
|
||||
VkResult vkRes = vkBeginCommandBuffer(prePresentCmdBuffer, &cmdBufInfo);
|
||||
assert(!vkRes);
|
||||
|
||||
VkImageMemoryBarrier prePresentBarrier = vkTools::prePresentBarrier(image);
|
||||
vkCmdPipelineBarrier(
|
||||
prePresentCmdBuffer,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_FLAGS_NONE,
|
||||
0, nullptr, // No memory barriers,
|
||||
0, nullptr, // No buffer barriers,
|
||||
1, &prePresentBarrier);
|
||||
|
||||
vkRes = vkEndCommandBuffer(prePresentCmdBuffer);
|
||||
assert(!vkRes);
|
||||
|
||||
VkSubmitInfo submitInfo = vkTools::initializers::submitInfo();
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &prePresentCmdBuffer;
|
||||
|
||||
vkRes = vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
assert(!vkRes);
|
||||
}
|
||||
|
||||
void VulkanExampleBase::submitPostPresentBarrier(VkImage image)
|
||||
{
|
||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||
|
|
@ -362,23 +392,19 @@ void VulkanExampleBase::submitPostPresentBarrier(VkImage image)
|
|||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
0,
|
||||
0, NULL, // No memory barriers,
|
||||
0, NULL, // No buffer barriers,
|
||||
0, nullptr, // No memory barriers,
|
||||
0, nullptr, // No buffer barriers,
|
||||
1, &postPresentBarrier);
|
||||
|
||||
vkRes = vkEndCommandBuffer(postPresentCmdBuffer);
|
||||
assert(!vkRes);
|
||||
|
||||
VkSubmitInfo submitInfo = {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
VkSubmitInfo submitInfo = vkTools::initializers::submitInfo();
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &postPresentCmdBuffer;
|
||||
|
||||
vkRes = vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
assert(!vkRes);
|
||||
|
||||
vkRes = vkQueueWaitIdle(queue);
|
||||
assert(!vkRes);
|
||||
}
|
||||
|
||||
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
||||
|
|
|
|||
|
|
@ -68,8 +68,10 @@ protected:
|
|||
VkCommandPool cmdPool;
|
||||
// Command buffer used for setup
|
||||
VkCommandBuffer setupCmdBuffer = VK_NULL_HANDLE;
|
||||
// Command buffer for submitting a post present barrier
|
||||
// Command buffer for submitting a post present image barrier
|
||||
VkCommandBuffer postPresentCmdBuffer = VK_NULL_HANDLE;
|
||||
// Command buffer for submitting a pre present image barrier
|
||||
VkCommandBuffer prePresentCmdBuffer = VK_NULL_HANDLE;
|
||||
// Command buffers used for rendering
|
||||
std::vector<VkCommandBuffer> drawCmdBuffers;
|
||||
// Global render pass for frame buffer writes
|
||||
|
|
@ -230,8 +232,12 @@ public:
|
|||
// Start the main render loop
|
||||
void renderLoop();
|
||||
|
||||
// Submit a pre present image barrier to the queue
|
||||
// Transforms the (framebuffer) image layout from color attachment to present(khr) for presenting to the swap chain
|
||||
void submitPrePresentBarrier(VkImage image);
|
||||
|
||||
// Submit a post present image barrier to the queue
|
||||
// Transforms image layout back to color attachment layout
|
||||
// Transforms the (framebuffer) image layout back from present(khr) to color attachment layout
|
||||
void submitPostPresentBarrier(VkImage image);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue