Skip to content

Commit 6c7f72f

Browse files
committed
Code cleanup
1 parent 5bd19de commit 6c7f72f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

examples/computecloth/computecloth.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A compute shader updates a shader storage buffer that contains particles held together by springs and also does basic
55
* collision detection against a sphere. This storage buffer is then used as the vertex input for the graphics part of the sample
66
*
7-
* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de
7+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
88
*
99
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
1010
*/
@@ -70,17 +70,17 @@ class VulkanExample : public VulkanExampleBase
7070
} graphics;
7171

7272
// 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 ;
7575
struct Compute {
7676
typedef struct Semaphores_t {
7777
VkSemaphore ready{ VK_NULL_HANDLE };
7878
VkSemaphore complete{ VK_NULL_HANDLE };
7979
} semaphores_t;
80-
std::array<semaphores_t, COMPUTE_CMD_BUFFERS> semaphores{};
80+
std::array<semaphores_t, computeCommandBufferCount> semaphores{};
8181
VkQueue queue{ VK_NULL_HANDLE };
8282
VkCommandPool commandPool{ VK_NULL_HANDLE };
83-
std::array<VkCommandBuffer, COMPUTE_CMD_BUFFERS> commandBuffers{};
83+
std::array<VkCommandBuffer, computeCommandBufferCount> commandBuffers{};
8484
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
8585
std::array<VkDescriptorSet, 2> descriptorSets{ VK_NULL_HANDLE };
8686
VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
@@ -492,10 +492,10 @@ class VulkanExample : public VulkanExampleBase
492492
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
493493

494494
// 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+
};
499499

500500
VkGraphicsPipelineCreateInfo pipelineCreateInfo = vks::initializers::pipelineCreateInfo(graphics.pipelineLayout, renderPass);
501501

@@ -536,8 +536,10 @@ class VulkanExample : public VulkanExampleBase
536536
inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
537537
inputAssemblyState.primitiveRestartEnable = VK_FALSE;
538538
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+
};
541543
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &graphics.pipelines.sphere));
542544

543545
buildCommandBuffers();
@@ -662,7 +664,7 @@ class VulkanExample : public VulkanExampleBase
662664

663665
static bool firstDraw = true;
664666
static uint32_t computeSubmitIndex{ 0 }, graphicsSubmitIndex{ 0 };
665-
if (COMPUTE_CMD_BUFFERS > 1) // should be constexpr, but requires C++17
667+
if (computeCommandBufferCount > 1)
666668
{
667669
// SRS - if we are double buffering the compute queue, swap the compute command buffer indices
668670
graphicsSubmitIndex = computeSubmitIndex;
@@ -678,7 +680,7 @@ class VulkanExample : public VulkanExampleBase
678680
}
679681
else {
680682
firstDraw = false;
681-
if (COMPUTE_CMD_BUFFERS > 1) // should be constexpr, but requires C++17
683+
if (computeCommandBufferCount > 1)
682684
{
683685
// SRS - if we are double buffering the compute queue, submit extra command buffer at start
684686
computeSubmitInfo.signalSemaphoreCount = 1;

0 commit comments

Comments
 (0)