dynamically bind the buffers #1607
-
|
I want to implement double buffering — one buffer for rendering and another for data uploading. I'm using both a compute pipeline and a graphics pipeline, and I’d like to dynamically bind the buffers. How can I achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
There isn't a core scene graph feature to do this, but it should be relatively straight forward to create the required subclasses to do it. I haven't tried it yet myself so will just make some suggestions as a starting place, others are welcome to pitch in as well. Perhaps an example for vsgExamples that illustrates this would be nice final outcome. The way that buffers/images are bound in the VSG is via vsg::BindDescriptorSet/BindDescriptorSets, with the DescritorSets that they bind being composed of the DecriptorBuffer/DescriptorImage. The DescriptorSet/Buffer/Image will be tied to statically to the specific buffer/image that you want to to read/write to. For double buffering you'll want two sets of DescriptorSets/Buffer/Image, and with custom BindDescriptorSet implementation that rather binding a specific DescriptorSet you'd have two available and then select based on the frame number. You could then have two custom BindDescriptorSet instances that change the order of the DesciptorSet assigned, then have one for compute subgraph and one for the graphics subgraph. The custom BindDescriptorSet could then select the descriptorSet to bind based on the frame number. One thing you'd need to take care about is that are frame 0 the compute will run but the graphics at frame 0 will be a potentially invalid buffer state. Initializing the buffer that the graphics uses into a valid state. |
Beta Was this translation helpful? Give feedback.
-
|
I defined the DynamicBindDescriptorSets class, which inherits from BindDescriptorSets. It is simple and not very safe, but intuitive and works well. The code is as follows: void DynamicBindDescriptorSets::record(CommandBuffer& commandBuffer) const
{
//info("DynamicBindDescriptorSets::record() ", dynamicOffsets.size(), ", ", dynamicOffsets.data());
auto& vkd = _vulkanData[commandBuffer.deviceID];
vkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint, vkd._vkPipelineLayout, firstSet,
1, &vkd._vkDescriptorSets[dynamicIndex],
static_cast<uint32_t>(dynamicOffsets.size()), dynamicOffsets.data());
} |
Beta Was this translation helpful? Give feedback.
There isn't a core scene graph feature to do this, but it should be relatively straight forward to create the required subclasses to do it. I haven't tried it yet myself so will just make some suggestions as a starting place, others are welcome to pitch in as well. Perhaps an example for vsgExamples that illustrates this would be nice final outcome.
The way that buffers/images are bound in the VSG is via vsg::BindDescriptorSet/BindDescriptorSets, with the DescritorSets that they bind being composed of the DecriptorBuffer/DescriptorImage. The DescriptorSet/Buffer/Image will be tied to statically to the specific buffer/image that you want to to read/write to.
For double buffering you'll wan…