I have two compute shaders that are to be executed one after the other. The first compute shader performs some calculations and stores the number of results in a buffer with VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, which should be the number of workgroups for the second compute shader. After this compute shader, a vkCmdPipelineBarrier should synchronize it. The second compute shader is executed by the vkCmdDispatchIndirect command. Both shader execution commands are located in the same command buffer.
VkMemoryBarrier memoryBarrier; memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; memoryBarrier.pNext = NULL; memoryBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; memoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader1->getPipeline()); vkCmdBindDescriptorSets(m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader1->getPipelineLayout(), 0, 1, &m_descriptorShader1, 0, 0); vkCmdDispatch(m_commandBuffer, 100, 1, 1); vkCmdPipelineBarrier(m_commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr); vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader2->getPipeline()); vkCmdBindDescriptorSets(m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader2->getPipelineLayout(), 0, 1, &m_descriptorShader2, 0, 0); vkCmdDispatchIndirect(m_commandBuffer, infoSSBO.getVkBuffer(), 0); The following error occurs when attempting to use the VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT flag:
VUID-vkCmdPipelineBarrier-dstAccessMask-02816(ERROR / SPEC): msgNum: 1774732925 - Validation Error: [ VUID-vkCmdPipelineBarrier-dstAccessMask-02816 ] Object 0: handle = 0x1f6932cc430, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x69c8467d | vkCmdPipelineBarrier(): .pMemoryBarriers[0].dstAccessMask bit VK_ACCESS_SHADER_READ_BIT is not supported by stage mask (VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT). The Vulkan spec states: The dstAccessMask member of each element of pMemoryBarriers must only include access flags that are supported by one or more of the pipeline stages in dstStageMask, as specified in the table of supported access types (https://vulkan.lunarg.com/doc/view/1.2.189.2/windows/1.2-extensions/vkspec.html#VUID-vkCmdPipelineBarrier-dstAccessMask-02816) Objects: 1 [0] 0x1f6932cc430, type: 6, name: NULL
If the “VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT” flag is used for both (src and dst), synchronization does not appear to work.
Which flags does the barrier need?
EDIT:
I changed the code to the following:
VkMemoryBarrier memoryBarrierIndirect; memoryBarrierIndirect.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; memoryBarrierIndirect.pNext = NULL; memoryBarrierIndirect.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; memoryBarrierIndirect.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT | VK_ACCESS_SHADER_READ_BIT; vkCmdPipelineBarrier(m_coverageRuleCommandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 1, &memoryBarrierIndirect, 0, nullptr, 0, nullptr); It seems to work (the correct number of workgroups is executed), but the “VK_LAYER_KHRONOS_validation” is printing:
VUID-vkCmdPipelineBarrier-dstAccessMask-02816(ERROR / SPEC): msgNum: 1774732925 - Validation Error: [ VUID-vkCmdPipelineBarrier-dstAccessMask-02816 ] Object 0: handle = 0x1c85d885f30, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x69c8467d | vkCmdPipelineBarrier(): .pMemoryBarriers[0].dstAccessMask bit VK_ACCESS_INDIRECT_COMMAND_READ_BIT is not supported by stage mask (VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT). The Vulkan spec states: The dstAccessMask member of each element of pMemoryBarriers must only include access flags that are supported by one or more of the pipeline stages in dstStageMask, as specified in the table of supported access types (https://vulkan.lunarg.com/doc/view/1.2.189.2/windows/1.2-extensions/vkspec.html#VUID-vkCmdPipelineBarrier-dstAccessMask-02816) Objects: 1 [0] 0x1c85d885f30, type: 6, name: NULL
I am afraid that it will not work properly on other computers. How can this be fixed?