go-vk icon indicating copy to clipboard operation
go-vk copied to clipboard

Go-like handling of pNext in Vulkanize()

Open bbredesen opened this issue 1 year ago • 0 comments

Extending structures through pNext is very awkward right now, requiring the developer to set up the structure, call Vulkanize() on it, and then cast the result to unsafe.Pointer before assigning to the base structure.

The XML spec includes a "structextends" property, showing what other structs can be extended with this one. (Note that there could be multiple types, separated by commas.)

For example, VkPhysicalDeviceFeatures2 is extended by many feature extensions like VkPhysicalDevicePrivateDataFeatures, VkPhysicalDeviceVariablePointersFeatures, VkPhysicalDeviceMultiviewFeatures, etc. Each of those public-facing structs could implement a guard interface called PhysicalDeviceFeaturres2Extender (or similar), and then vk.PhysicalDeviceFeatures2.PNext would have its type set to that interface. The Vulkanize function would then handle the recursive Vulkanization and casting to unsafe.Pointer behind the scenes.

Note that there are also 70+ "returnedonly" structs that extend other structs. The fix above does NOT address structs returned from Vulkan.

bbredesen avatar Mar 02 '23 14:03 bbredesen