Search code examples
c++apiconventionsvulkan

What is the purpose of stype field?


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?


Solution

  • 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.