The purpose of pNext in Vulcan structures

Many of the structures used in Vulkan have an sType member that identifies the type of structure and a pNext member for extension-specific structures. This answer explains quite well why the sType member is needed and why it is needed. It briefly touches on pNext, although I'm not sure I understand the meaning of this.

If the first member of each structure is sType, could the extensions define their own structure types when they need different / additional parameters?

+5
source share
1 answer

As clearly stated in the specification:

Any parameter that is a structure containing the void* pNext member must have a pNext value that is either NULL or indicates a valid structure, which is determined by the allowed extension.

It is for extensions.

If the first member of each structure is sType, could the extensions define their own structure types when they need different / additional parameters?

That would not be extensible.

There is only one sType field. So, how can two extensions extend the same API with new values? Just like the old extension works with the new versions of Vulkan, which itself uses a different data structure identified by sType .

With pNext you do not have this problem. Each extension data structure will not only have its own internal sType field, but it will no doubt also have its own pNext field. Thus, multiple extensions can extend the same data structures.

sType does not need this because it will only be changed in higher versions of Vulkan.

+5
source

Source: https://habr.com/ru/post/1246906/


All Articles