@@ -41,7 +41,7 @@ class VulkanExample : public VulkanExampleBase
4141
4242 // We use a shader storage buffer object to store the particlces
4343 // This is updated by the compute pipeline and displayed as a vertex buffer by the graphics pipeline
44- std::vector <vks::Buffer> storageBuffers;
44+ std::array <vks::Buffer, maxConcurrentFrames > storageBuffers;
4545
4646 // Resources for the graphics part of the example
4747 struct Graphics {
@@ -54,20 +54,20 @@ class VulkanExample : public VulkanExampleBase
5454
5555 // Resources for the compute part of the example
5656 struct Compute {
57- uint32_t queueFamilyIndex; // Used to check if compute and graphics queue families differ and require additional barriers
58- VkQueue queue; // Separate queue for compute commands (queue family may differ from the one used for graphics)
59- VkCommandPool commandPool; // Use a separate command pool (queue family may differ from the one used for graphics)
60- std::vector <VkCommandBuffer> commandBuffers;// Command buffer storing the dispatch commands and barriers
61- std::vector <VkFence> fences; // Synchronization fence to avoid rewriting compute CB if still in use
62- VkDescriptorSetLayout descriptorSetLayout; // Compute shader binding layout
63- std::vector <VkDescriptorSet> descriptorSets; // Compute shader bindings
64- VkPipelineLayout pipelineLayout; // Layout of the compute pipeline
65- VkPipeline pipeline; // Compute pipeline for updating particle positions
66- std::vector <vks::Buffer> uniformBuffers; // Uniform buffer object containing particle system parameters
67- struct UniformData { // Compute shader uniform block object
68- float deltaT; // Frame delta time
69- float destX; // x position of the attractor
70- float destY; // y position of the attractor
57+ uint32_t queueFamilyIndex; // Used to check if compute and graphics queue families differ and require additional barriers
58+ VkQueue queue; // Separate queue for compute commands (queue family may differ from the one used for graphics)
59+ VkCommandPool commandPool; // Use a separate command pool (queue family may differ from the one used for graphics)
60+ std::array <VkCommandBuffer, maxConcurrentFrames > commandBuffers; // Command buffer storing the dispatch commands and barriers
61+ std::array <VkFence, maxConcurrentFrames > fences; // Synchronization fence to avoid rewriting compute CB if still in use
62+ VkDescriptorSetLayout descriptorSetLayout; // Compute shader binding layout
63+ std::array <VkDescriptorSet, maxConcurrentFrames > descriptorSets{}; // Compute shader bindings
64+ VkPipelineLayout pipelineLayout; // Layout of the compute pipeline
65+ VkPipeline pipeline; // Compute pipeline for updating particle positions
66+ std::array <vks::Buffer, maxConcurrentFrames > uniformBuffers; // Uniform buffer object containing particle system parameters
67+ struct UniformData { // Compute shader uniform block object
68+ float deltaT; // Frame delta time
69+ float destX; // x position of the attractor
70+ float destY; // y position of the attractor
7171 int32_t particleCount = PARTICLE_COUNT;
7272 } uniformData{};
7373 } compute{};
@@ -76,11 +76,6 @@ class VulkanExample : public VulkanExampleBase
7676 {
7777 useNewSync = true ;
7878 title = " Compute shader particle system" ;
79- storageBuffers.resize (maxConcurrentFrames);
80- compute.uniformBuffers .resize (maxConcurrentFrames);
81- compute.descriptorSets .resize (maxConcurrentFrames);
82- compute.commandBuffers .resize (maxConcurrentFrames);
83- compute.fences .resize (maxConcurrentFrames);
8479 }
8580
8681 ~VulkanExample ()
@@ -296,14 +291,12 @@ class VulkanExample : public VulkanExampleBase
296291 // Some objects need to be duplicated per frames in flight
297292
298293 // Create command buffers for compute operations
299- compute.commandBuffers .resize (maxConcurrentFrames);
300294 VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo (compute.commandPool , VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 );
301295 for (auto & commandBuffer : compute.commandBuffers ) {
302296 VK_CHECK_RESULT (vkAllocateCommandBuffers (device, &cmdBufAllocateInfo, &commandBuffer));
303297 }
304298
305299 // Fences for compute CB sync
306- compute.fences .resize (maxConcurrentFrames);
307300 for (auto & fence : compute.fences ) {
308301 VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo (VK_FENCE_CREATE_SIGNALED_BIT);
309302 VK_CHECK_RESULT (vkCreateFence (device, &fenceCreateInfo, nullptr , &fence));
0 commit comments