Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan 1 3 hello triangle sample #1230

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

alihuawei
Copy link
Collaborator

This Pull Request introduces a new sample, "Hello Triangle", leveraging Vulkan 1.3 features and modern C++20 language enhancements. The sample aims to provide developers with an updated and clean starting point for learning and experimenting with the latest Vulkan API functionalities.

1: Sample is using vertex buffer to load vertices compared to hardcoded in the vertex shader in hello_triangle 1.0.
2: Sample is using dynamic rendering so frame buffers and Render passes removed.
3: Used Synchronization2 in image layout transition.
3: Updated the code to use VK_DEBUG_UTILS (new) instead VK_DEBUG_REPORT(old).
4: Update the code to use Dynamic pipeline status.
5: Removed unused parameters from functions.
6: Used C++20 initializers.

The sample is built and tested on Windows and Linux OS.

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making:
  • My changes build on Windows and Linux.

Sample Checklist

  • I have tested the sample on at least one compliant Vulkan implementation
  • For new samples, I have added a paragraph with a summary to the appropriate chapter in the readme of the folder that the sample belongs to e.g. api samples readme
  • For new samples, I have added a tutorial README.md file to guide users through what they need to know to implement code using this feature. For example, see conditional_rendering
  • For new samples, I have added a link to the Antora navigation so that the sample will be listed at the Vulkan documentation site

1: It is using vertex buffer to load vertices compared to hardcoded in shader in hello_triangle 1.0
2: It is using dynamic rendering so frame buffers and Render passes removed
3: Used Synchronization2 in image layout transition.
3: Updated the code to use VK_DEBUG_UTILS (new) instead VK_DEBUG_REPORT(old)
4: Update the code to use Dynamic pipeline status
5: Removed unused parameters from functions
6: Used C++20 initializers
Signed-off-by: aliasifhuawei <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Nov 18, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@gary-sweet gary-sweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be missing a change to samples/CMakeLists.txt that actually exposes the sample.

I know very little about the background to this change, but it does seem a little odd that using the newer version of Vulkan results in 200 more lines of code for hello_triangle than we used to have.

@SaschaWillems
Copy link
Collaborator

SaschaWillems commented Nov 23, 2024

This seems to be missing a change to samples/CMakeLists.txt that actually exposes the sample.

I know very little about the background to this change, but it does seem a little odd that using the newer version of Vulkan results in 200 more lines of code for hello_triangle than we used to have.

I think that's at least partially due to the sample doing things that the original hello triangle sample is missing. E.g. creating a proper vertex buffer instead of hardcoding it in the shaders like the non 1.3 sample does. But I agree that this sample could be an opportunity to reduce line count. It does a several not so optimal things 1:1 like the hello triangle sample. E.g. having a function to deduce the shader stage from a file extension while it only uses vertex and fragment shader stages.

Copy link
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add a few comments, mostly things also not that great with the VK 1.0 hello triangle sample.

But I also noticed lots of validation errors when running this sample that need to be fixed:

[error] -1733013297 Validation Layer: Error: VUID-VkBufferCreateInfo-flags-parameter: Validation Error: [ VUID-VkBufferCreateInfo-flags-parameter ] | MessageID = 0x98b450cf | vkCreateBuffer(): pCreateInfo->flags contains flag bits (0x80) which are not recognized members of VkBufferCreateFlagBits.
The Vulkan spec states: flags must be a valid combination of VkBufferCreateFlagBits values (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkBufferCreateInfo-flags-parameter)
[error] -153856805 Validation Layer: Error: VUID-VkBufferCreateInfo-None-09500: Validation Error: [ VUID-VkBufferCreateInfo-None-09500 ] | MessageID = 0xf6d454db | vkCreateBuffer(): pCreateInfo->usage is zero.
The Vulkan spec states: If the pNext chain does not include a VkBufferUsageFlags2CreateInfoKHR structure, usage must not be 0 (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkBufferCreateInfo-None-09500)
[error] 1895430949 Validation Layer: Error: VUID-VkGraphicsPipelineCreateInfo-topology-08773: Validation Error: [ VUID-VkGraphicsPipelineCreateInfo-topology-08773 ] Object 0: handle = 0xd175b40000000013, type = VK_OBJECT_TYPE_SHADER_MODULE; | MessageID = 0x70f9fb25 | vkCreateGraphicsPipelines(): pCreateInfos[0].pStages[0] SPIR-V (Vertex) PointSize is not written to, but Pipeline topology is set to VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the pipeline is being created with a Vertex Execution Model and no TessellationEvaluation or Geometry Execution Model, and the topology member of pInputAssembly is VK_PRIMITIVE_TOPOLOGY_POINT_LIST, and either VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state is not enabled or dynamicPrimitiveTopologyUnrestricted is VK_FALSE, a PointSize decorated variable must be written to if maintenance5 is not enabled (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-topology-08773)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f93d0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f93d0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6efca0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f93d0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f93d0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)
[error] -1696391559 Validation Layer: Error: VUID-vkCmdBindVertexBuffers-pBuffers-00627: Validation Error: [ VUID-vkCmdBindVertexBuffers-pBuffers-00627 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xfa21a40000000003, type = VK_OBJECT_TYPE_BUFFER; | MessageID = 0x9ae31e79 | vkCmdBindVertexBuffers(): pBuffers[0] (VkBuffer 0xfa21a40000000003[]) was created with VkBufferUsageFlags2KHR(0) but requires VK_BUFFER_USAGE_VERTEX_BUFFER_BIT.
The Vulkan spec states: All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindVertexBuffers-pBuffers-00627)
[error] -901174136 Validation Layer: Error: VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500: Validation Error: [ VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500 ] Object 0: handle = 0x1fb5f6f3830, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0xdd3a8a0000000015, type = VK_OBJECT_TYPE_PIPELINE; | MessageID = 0xca492c88 | vkCmdDraw():  the last primitive topology VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST state set by vkCmdSetPrimitiveTopology is not compatible with the pipeline topology VK_PRIMITIVE_TOPOLOGY_POINT_LIST.
The Vulkan spec states: If the bound graphics pipeline state was created with the VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY dynamic state enabled and the dynamicPrimitiveTopologyUnrestricted is VK_FALSE, then the primitiveTopology parameter of vkCmdSetPrimitiveTopology must be of the same topology class as the pipeline VkPipelineInputAssemblyStateCreateInfo::topology state (https://vulkan.lunarg.com/doc/view/1.3.296.0/windows/1.3-extensions/vkspec.html#VUID-vkCmdDraw-dynamicPrimitiveTopologyUnrestricted-07500)

samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few issues.

samples/CMakeLists.txt Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved

instance_info.pNext = &debug_messenger_create_info;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you skipped the portability handling here:

#if (defined(VKB_ENABLE_PORTABILITY))
	if (portability_enumeration_available)
	{
		instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
	}
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, my thought process was i am going to check for Vulkan 1.3 which is not supported on IOS anyway but you are correct i should do portability handling so when V1.3 is available on iOS it should work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this sample is specifically targeting Vulkan 1.3-compatible hardware, and the code already checks for Vulkan 1.3 support on the selected device, there's no need to enable the portability extension (VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR). The portability subset is mainly used to ensure Vulkan works on devices with partial or non-standard Vulkan implementations, such as older or embedded systems.

However, in this case, I am focusing on platforms where Vulkan 1.3 is fully supported (modern desktops, mobile devices, etc.). Therefore, enabling the portability flag is unnecessary.

@SaschaWillems what is your opinion about this ?

// Enable required Vulkan 1.3 features
vulkan13_features.dynamicRendering = VK_TRUE;
vulkan13_features.synchronization2 = VK_TRUE;
extended_dynamic_state_features.extendedDynamicState = VK_TRUE;
Copy link
Contributor

@asuessenbach asuessenbach Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct way to handle feature requests.

With vkGetPhysicalDeviceFeatures2, you get what features would be supported. You could check them here to decide if your code would be able to run with or without them.

Unconditionally setting them to VK_TRUE is wrong. If they were VK_FALSE before, device creation would just fail.

Instead, you should use feature structs, where just those features are set to VK_TRUE you really want to ask for, and use those to create the device.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that's what we want. It's a 1.3 sample and those features are a requirement. So imo it's fine to set them that way, as device creation will then fail with a proper error message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure, that's what we want.
I think, the samples here should show how to do it right.
You're right, the spec says that you can check for extension presence and you can check for feature support. You don't have to, as vkCreateDevice would fail with some appropriate error code if you ask for something not supported.
But here, you're asking for each and every feature (listed by your structure chain) that's supported by that device (plus some that might actually not be supported). You should not do that, as it might result in sub-optimal performance or
unnecessary memory consumption.
Instead, you should just ask for the extensions you need and the features you need.
And I think, it would be a good habit to check for their support before just trying to create the device.

Copy link
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more validation errors :)

Added a few comments, but mostly (if not all) are cosmetic.

samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
samples/api/hello_triangle_1_3/hello_triangle_1_3.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sample itself looks good to me now :)

One thing that should be expanded though is the readme. Newer samples should come with at least a basic tutorial or overview of what the sample does / how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants