0

In Vulkan, some functions require you pass a struct containing various parameters. One of the fields is named stype and needs to be set to the type of struct it is.

An example of stype's usage:

VkInstanceCreateInfo info;
info.stype = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
...
VkInstance instance;
vkCreateInstance(&info, nullptr, &instance);

The function vkCreateInstance takes a const VkInstanceCreateInfo* as a parameter, so what's the point of the stype field? What was the issue that existed that they fixed by adding the field?

user112513312
  • 459
  • 1
  • 7
  • 15
  • Probably to make it possible for later versions of the API to add fields to the struct. The value you put in that field tells vulkan which version of the struct you are using so it knows which fields do exist. – Eelke Mar 05 '17 at 10:30

2 Answers2

3

So that a future version can update the struct by changing the type without needing a new entry point.

However currently it's used for the extension structs found through the pNext linked list. And making all the structs with a uniform layout like that doesn't cost anything. The implementation can simply ignore the first field and just assume it's correct.

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
0

From https://www.khronos.org/registry/vulkan/specs/1.0/man/html/VkInstanceCreateInfo.html

sType is used to describe the type of the structure. It must be filled out in every structure.

Aishwarya Shiva
  • 3,460
  • 15
  • 58
  • 107