Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of pNext in Vulkan structures

Tags:

vulkan

A lot of the structures used in Vulkan have a sType member, which identifies the type of the structure, and a pNext member, for extension-specific structures. This answer explains quite well what the sType member is for, and why it is needed. It briefly touches on pNext, although I'm not sure I understand the rationale behind it.

If the first member of every structure is sType, couldn't extensions just define their own structure types when they need different/extra parameters?

like image 920
Andrew Williamson Avatar asked Apr 12 '16 00:04

Andrew Williamson


1 Answers

As clearly stated in the specification:

Any parameter that is a structure containing a void* pNext member must have a value of pNext that is either NULL, or points to a valid structure that is defined by an enabled extension.

It's for extensions.

If the first member of every structure is sType, couldn't extensions just define their own structure types when they need different/extra parameters?

That wouldn't be extensible.

There is only one sType field. So how could two extensions extend the same API with new values? Similarly, how could an old extension work alongside new versions of Vulkan that itself uses a different data structure identified by sType.

With pNext, you don't have that 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. So multiple extensions can extend the same data structures.

sType doesn't need this, because it will only be changed in higher versions of Vulkan.

like image 109
Nicol Bolas Avatar answered Oct 24 '22 18:10

Nicol Bolas