4
4
* A compute shader updates a shader storage buffer that contains particles held together by springs and also does basic
5
5
* collision detection against a sphere. This storage buffer is then used as the vertex input for the graphics part of the sample
6
6
*
7
- * Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
7
+ * Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
8
8
*
9
9
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
10
10
*/
@@ -70,17 +70,17 @@ class VulkanExample : public VulkanExampleBase
70
70
} graphics;
71
71
72
72
// Resources for the compute part of the example
73
- // SRS - Number of compute command buffers: set to 1 for serialized processing or 2 for in-parallel with graphics queue
74
- # define COMPUTE_CMD_BUFFERS 2
73
+ // Number of compute command buffers: set to 1 for serialized processing or 2 for in-parallel with graphics queue
74
+ static constexpr size_t computeCommandBufferCount = 2 ;
75
75
struct Compute {
76
76
typedef struct Semaphores_t {
77
77
VkSemaphore ready{ VK_NULL_HANDLE };
78
78
VkSemaphore complete{ VK_NULL_HANDLE };
79
79
} semaphores_t ;
80
- std::array<semaphores_t , COMPUTE_CMD_BUFFERS > semaphores{};
80
+ std::array<semaphores_t , computeCommandBufferCount > semaphores{};
81
81
VkQueue queue{ VK_NULL_HANDLE };
82
82
VkCommandPool commandPool{ VK_NULL_HANDLE };
83
- std::array<VkCommandBuffer, COMPUTE_CMD_BUFFERS > commandBuffers{};
83
+ std::array<VkCommandBuffer, computeCommandBufferCount > commandBuffers{};
84
84
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
85
85
std::array<VkDescriptorSet, 2 > descriptorSets{ VK_NULL_HANDLE };
86
86
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
@@ -492,10 +492,10 @@ class VulkanExample : public VulkanExampleBase
492
492
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo (dynamicStateEnables);
493
493
494
494
// Rendering pipeline
495
- std::array<VkPipelineShaderStageCreateInfo, 2 > shaderStages;
496
-
497
- shaderStages[ 0 ] = loadShader (getShadersPath () + " computecloth/cloth.vert .spv" , VK_SHADER_STAGE_VERTEX_BIT);
498
- shaderStages[ 1 ] = loadShader ( getShadersPath () + " computecloth/cloth.frag.spv " , VK_SHADER_STAGE_FRAGMENT_BIT) ;
495
+ std::array<VkPipelineShaderStageCreateInfo, 2 > shaderStages = {
496
+ loadShader ( getShadersPath () + " computecloth/cloth.vert.spv " , VK_SHADER_STAGE_VERTEX_BIT),
497
+ loadShader (getShadersPath () + " computecloth/cloth.frag .spv" , VK_SHADER_STAGE_FRAGMENT_BIT)
498
+ } ;
499
499
500
500
VkGraphicsPipelineCreateInfo pipelineCreateInfo = vks::initializers::pipelineCreateInfo (graphics.pipelineLayout , renderPass);
501
501
@@ -536,8 +536,10 @@ class VulkanExample : public VulkanExampleBase
536
536
inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
537
537
inputAssemblyState.primitiveRestartEnable = VK_FALSE;
538
538
rasterizationState.polygonMode = VK_POLYGON_MODE_FILL;
539
- shaderStages[0 ] = loadShader (getShadersPath () + " computecloth/sphere.vert.spv" , VK_SHADER_STAGE_VERTEX_BIT);
540
- shaderStages[1 ] = loadShader (getShadersPath () + " computecloth/sphere.frag.spv" , VK_SHADER_STAGE_FRAGMENT_BIT);
539
+ shaderStages = {
540
+ loadShader (getShadersPath () + " computecloth/sphere.vert.spv" , VK_SHADER_STAGE_VERTEX_BIT),
541
+ loadShader (getShadersPath () + " computecloth/sphere.frag.spv" , VK_SHADER_STAGE_FRAGMENT_BIT)
542
+ };
541
543
VK_CHECK_RESULT (vkCreateGraphicsPipelines (device, pipelineCache, 1 , &pipelineCreateInfo, nullptr , &graphics.pipelines .sphere ));
542
544
543
545
buildCommandBuffers ();
@@ -662,7 +664,7 @@ class VulkanExample : public VulkanExampleBase
662
664
663
665
static bool firstDraw = true ;
664
666
static uint32_t computeSubmitIndex{ 0 }, graphicsSubmitIndex{ 0 };
665
- if (COMPUTE_CMD_BUFFERS > 1 ) // should be constexpr, but requires C++17
667
+ if (computeCommandBufferCount > 1 )
666
668
{
667
669
// SRS - if we are double buffering the compute queue, swap the compute command buffer indices
668
670
graphicsSubmitIndex = computeSubmitIndex;
@@ -678,7 +680,7 @@ class VulkanExample : public VulkanExampleBase
678
680
}
679
681
else {
680
682
firstDraw = false ;
681
- if (COMPUTE_CMD_BUFFERS > 1 ) // should be constexpr, but requires C++17
683
+ if (computeCommandBufferCount > 1 )
682
684
{
683
685
// SRS - if we are double buffering the compute queue, submit extra command buffer at start
684
686
computeSubmitInfo.signalSemaphoreCount = 1 ;
0 commit comments