0
votes

I have a particle system, first I run a compute shader and update all the properties and then I use those properties as vao input in vertex shader.

Now I need a barrier between those stages, but I'm not sure how to do it, whatever I try I get some error.

Currently I have a pipeline barrier like this:

  VkMemoryBarrier memoryBarrier;
  memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
  memoryBarrier.pNext = nullptr;
  memoryBarrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
  memoryBarrier.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;

  vkCmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
                   VK_PIPELINE_STAGE_VERTEX_INPUT_B

And I create the render pass with this dependency:

VkSubpassDependency computeDependency;
computeDependency.srcSubpass = 0;
computeDependency.dstSubpass = 0;
computeDependency.srcStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
computeDependency.dstStageMask = VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
computeDependency.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
computeDependency.dstAccessMask = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
computeDependency.dependencyFlags = 0;

But this doesn't work as I get this error: Validation layer: Dependency 1 specifies a source stage mask that contains stages not in the GRAPHICS pipeline as used by the source subpass 0. The Vulkan spec states: For any element of pDependencies, if the srcSubpass is not VK_SUBPASS_EXTERNAL, all stage flags included in the srcStageMask member of that dependency must be a pipeline stage supported by the pipeline identified by the pipelineBindPoint member of the source subpass (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkRenderPassCreateInfo-pDependencies-00837)

1

1 Answers

2
votes

You cannot execute a compute shader in the middle of a subpass. The render pass scope of vkCmdDispatch is "outside", which is also why dependencies between subpasses can only specify stages supported by graphics operations. Therefore, any dependency between a compute shader and a consumer within a rendering process is an external dependency: a dependency between the subpass containing the rendering process and the outside world.

So your srcSubpass should be VK_SUBPASS_EXTERNAL.