bbredesen / go-vk

A Go binding around the Vulkan graphics and compute API.
MIT License
64 stars 1 forks source link

Go-like handling of pNext in Vulkanize() #3

Open bbredesen opened 1 year ago

bbredesen commented 1 year ago

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.