Vulkan: What is the point of sType in vk*CreateInfo structs?

后端 未结 1 580
悲哀的现实
悲哀的现实 2020-12-03 06:48

In all of the create info structs (vk*CreateInfo) in the new Vulkan API, there is ALWAYS a .sType member. Why is this there if the value can only b

相关标签:
1条回答
  • 2020-12-03 07:19

    So that the API can be changed without breaking backwards compatibility.

    If version 1.1 of Vulkan wants to expand on the creation of, for example, command buffer pools, how would it do that? Well, they could add a whole new entrypoint: vkCreateCommandPool2. But this function would have almost the exact same signature as vkCreateCommandPool; the only difference is that they take different pCreateInfo structures.

    So instead, all you have to do is declare a VkCommandPoolCreateInfo2 structure. And then declare that vkCreateCommandPool can take either one. How would the implementation tell which one you passed in?

    Because the first 4 bytes of any such structure is sType. They can test that value. If the value is VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, then it's the old structure. If it's VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO_2, then it's the new one.

    This also makes it easier for extensions to fully override a CreateInfo structure. The pNext field is for augmenting an API with additional parameters. With sType, an extension can change existing parameters.

    0 讨论(0)
提交回复
热议问题