Reputation: 31
I am trying to make a simulation that involves two steps of computation before rendering. I currently have working a compute pipeline that calculate basic physics, and then a graphics pipeline. I would like to be able to add a second compute shader to be run after the first.
First, is it possible to have two consecutive compute shaders in Vulkan?
I have tried a few different variations of trying to get the second compute shader. The method Ithought to be most promising was when calling vkCreateComputePipelines, passing in arrays of VkComputePipelineCreateInfo's and VkPipeline's, and changing the createInfoCount to 2. According to the documentation, it seemed like the createInfoCount referred to the number of both the createInfo's and pipelines, which led us to believe it was possible to have multiple pipelines, however this causes a crash. With just a single compute shader, instead of passing in length-1 array, I directly pass in the address of the createInfo and the pipeline. Changing the createInfo to an array works fine, but as soon as I try to change the pipeline parameter to point to an array (even with just a single pipeline in that array), it causes a crash. Is there a flag or parameter I'd need to adjust to allow multiple pipelines to be created?
Another method we considered was to add multiple computeShaderStageInfo's to the VkComputePipelineCreateInfo, and then only have one createInfo and one compute pipeline. However, unlike VkGraphicsPipelineCreateInfo, it only seems to allow for a single stage, rather than an array of stages.
I also tried creating a second VkCommandBuffer for the second compute shader. I were able to bind the descriptor sets to both command buffers, but only the one dispatched last was run.
Upvotes: 3
Views: 2842
Reputation: 473447
First, is it possible to have two consecutive compute shaders in Vulkan?
No. Compute shaders have no user-defined inputs and no outputs at all, so there would be no direct means for a pipeline containing consecutive compute shaders to communicate. Each dispatch operation executes a single compute shader stage, and that's it.
If you want two consecutive compute shaders, you need two pipelines each with different compute shaders, and appropriate synchronization primitives between them so that they can communicate.
Upvotes: 3