@@ -40,14 +40,13 @@ struct Vertex
4040
4141 static vk::VertexInputBindingDescription getBindingDescription ()
4242 {
43- return {0 , sizeof (Vertex), vk::VertexInputRate::eVertex};
43+ return {. binding = 0 , . stride = sizeof (Vertex), . inputRate = vk::VertexInputRate::eVertex};
4444 }
4545
4646 static std::array<vk::VertexInputAttributeDescription, 2 > getAttributeDescriptions ()
4747 {
48- return {
49- vk::VertexInputAttributeDescription (0 , 0 , vk::Format::eR32G32Sfloat, offsetof (Vertex, pos)),
50- vk::VertexInputAttributeDescription (1 , 0 , vk::Format::eR32G32B32Sfloat, offsetof (Vertex, color))};
48+ return {{{.location = 0 , .binding = 0 , .format = vk::Format::eR32G32Sfloat, .offset = offsetof (Vertex, pos)},
49+ {.location = 1 , .binding = 0 , .format = vk::Format::eR32G32B32Sfloat, .offset = offsetof (Vertex, color)}}};
5150 }
5251};
5352
@@ -278,6 +277,7 @@ class HelloTriangleApplication
278277 vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
279278 bool supportsRequiredFeatures = features.template get <vk::PhysicalDeviceVulkan11Features>().shaderDrawParameters &&
280279 features.template get <vk::PhysicalDeviceVulkan13Features>().dynamicRendering &&
280+ features.template get <vk::PhysicalDeviceVulkan13Features>().synchronization2 &&
281281 features.template get <vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState ;
282282
283283 // Return true if the physicalDevice meets all the criteria
@@ -316,12 +316,16 @@ class HelloTriangleApplication
316316 }
317317
318318 // query for required features (Vulkan 1.1 and 1.3)
319- vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT> featureChain = {
320- {}, // vk::PhysicalDeviceFeatures2
321- {.shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
322- {.synchronization2 = true , .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
323- {.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
324- };
319+ vk::StructureChain<vk::PhysicalDeviceFeatures2,
320+ vk::PhysicalDeviceVulkan11Features,
321+ vk::PhysicalDeviceVulkan13Features,
322+ vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>
323+ featureChain = {
324+ {}, // vk::PhysicalDeviceFeatures2
325+ {.shaderDrawParameters = true }, // vk::PhysicalDeviceVulkan11Features
326+ {.synchronization2 = true , .dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
327+ {.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
328+ };
325329
326330 // create a Device
327331 float queuePriority = 0 .5f ;
@@ -389,7 +393,10 @@ class HelloTriangleApplication
389393
390394 auto bindingDescription = Vertex::getBindingDescription ();
391395 auto attributeDescriptions = Vertex::getAttributeDescriptions ();
392- vk::PipelineVertexInputStateCreateInfo vertexInputInfo{.vertexBindingDescriptionCount = 1 , .pVertexBindingDescriptions = &bindingDescription, .vertexAttributeDescriptionCount = static_cast <uint32_t >(attributeDescriptions.size ()), .pVertexAttributeDescriptions = attributeDescriptions.data ()};
396+ vk::PipelineVertexInputStateCreateInfo vertexInputInfo{.vertexBindingDescriptionCount = 1 ,
397+ .pVertexBindingDescriptions = &bindingDescription,
398+ .vertexAttributeDescriptionCount = static_cast <uint32_t >(attributeDescriptions.size ()),
399+ .pVertexAttributeDescriptions = attributeDescriptions.data ()};
393400 vk::PipelineInputAssemblyStateCreateInfo inputAssembly{.topology = vk::PrimitiveTopology::eTriangleList};
394401 vk::PipelineViewportStateCreateInfo viewportState{.viewportCount = 1 , .scissorCount = 1 };
395402
@@ -442,11 +449,15 @@ class HelloTriangleApplication
442449
443450 void createVertexBuffer ()
444451 {
445- vk::BufferCreateInfo bufferInfo{.size = sizeof (vertices[0 ]) * vertices.size (), .usage = vk::BufferUsageFlagBits::eVertexBuffer, .sharingMode = vk::SharingMode::eExclusive};
452+ vk::BufferCreateInfo bufferInfo{.size = sizeof (vertices[0 ]) * vertices.size (),
453+ .usage = vk::BufferUsageFlagBits::eVertexBuffer,
454+ .sharingMode = vk::SharingMode::eExclusive};
446455 vertexBuffer = vk::raii::Buffer (device, bufferInfo);
447456
448457 vk::MemoryRequirements memRequirements = vertexBuffer.getMemoryRequirements ();
449- vk::MemoryAllocateInfo memoryAllocateInfo{.allocationSize = memRequirements.size , .memoryTypeIndex = findMemoryType (memRequirements.memoryTypeBits , vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent)};
458+ vk::MemoryAllocateInfo memoryAllocateInfo{
459+ .allocationSize = memRequirements.size ,
460+ .memoryTypeIndex = findMemoryType (memRequirements.memoryTypeBits , vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent)};
450461 vertexBufferMemory = vk::raii::DeviceMemory (device, memoryAllocateInfo);
451462
452463 vertexBuffer.bindMemory (*vertexBufferMemory, 0 );
@@ -482,7 +493,8 @@ class HelloTriangleApplication
482493 {
483494 auto &commandBuffer = commandBuffers[frameIndex];
484495 commandBuffer.begin ({});
485- // Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
496+
497+ // Before starting rendering, transition the swapchain image to vk::ImageLayout::eColorAttachmentOptimal
486498 transition_image_layout (
487499 imageIndex,
488500 vk::ImageLayout::eUndefined,
@@ -509,9 +521,10 @@ class HelloTriangleApplication
509521 commandBuffer.setViewport (0 , vk::Viewport (0 .0f , 0 .0f , static_cast <float >(swapChainExtent.width ), static_cast <float >(swapChainExtent.height ), 0 .0f , 1 .0f ));
510522 commandBuffer.setScissor (0 , vk::Rect2D (vk::Offset2D (0 , 0 ), swapChainExtent));
511523 commandBuffer.bindVertexBuffers (0 , *vertexBuffer, {0 });
512- commandBuffer.draw (3 , 1 , 0 , 0 );
524+ commandBuffer.draw (static_cast < uint32_t >(vertices. size ()) , 1 , 0 , 0 );
513525 commandBuffer.endRendering ();
514- // After rendering, transition the swapchain image to PRESENT_SRC
526+
527+ // After rendering, transition the swapchain image to vk::ImageLayout::ePresentSrcKHR
515528 transition_image_layout (
516529 imageIndex,
517530 vk::ImageLayout::eColorAttachmentOptimal,
0 commit comments