Add a convenience Qvk_MemoryBarrier function

This commit is contained in:
Ricardo Garcia 2021-02-14 00:02:08 +01:00
parent 8599cab275
commit e0e52de47f
2 changed files with 18 additions and 7 deletions

View file

@ -312,6 +312,7 @@ void QVk_DrawColorRect(float *ubo, VkDeviceSize uboSize, qvkrenderpasstype_t rp
void QVk_DrawTexRect(const float *ubo, VkDeviceSize uboSize, qvktexture_t *texture);
void QVk_BindPipeline(qvkpipeline_t *pipeline);
void QVk_SubmitStagingBuffers(void);
void Qvk_MemoryBarrier(VkCommandBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask);
// debug label related functions
void QVk_DebugSetObjectName(uint64_t obj, VkObjectType objType, const char *objName);

View file

@ -1158,6 +1158,18 @@ static void CreateStagingBuffers()
}
}
// Records a memory barrier in the given command buffer.
void Qvk_MemoryBarrier(VkCommandBuffer cmdBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask)
{
const VkMemoryBarrier memBarrier = {
.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
.pNext = NULL,
.srcAccessMask = srcAccessMask,
.dstAccessMask = dstAccessMask,
};
vkCmdPipelineBarrier(cmdBuffer, srcStageMask, dstStageMask, 0u, 1u, &memBarrier, 0u, NULL, 0u, NULL);
}
// internal helper
static void SubmitStagingBuffer(int index)
{
@ -1167,14 +1179,12 @@ static void SubmitStagingBuffer(int index)
return;
}
VkMemoryBarrier memBarrier = {
.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
.pNext = NULL,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
};
Qvk_MemoryBarrier(vk_stagingBuffers[index].cmdBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT,
(VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT));
vkCmdPipelineBarrier(vk_stagingBuffers[index].cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, 0, 1, &memBarrier, 0, NULL, 0, NULL);
VK_VERIFY(vkEndCommandBuffer(vk_stagingBuffers[index].cmdBuffer));
VkSubmitInfo submitInfo = {