vulkan-zig
vulkan-zig copied to clipboard
Use opaque types instead of handle enums
Instead of the following generated code:
pub const Instance = enum(usize) { null_handle = 0, _ };
we can make use of opaque types:
pub const Instance = opaque {}; // maybe *opaque {}?
This improves type safety with explicit nullability in generated code, and makes it easier to use with other C APIs that expect an opaque pointer. For example the instance argument in destroyInstance is not obviously nullable until you read the Vulkan spec, and null is obviously cleaner than .null_handle. This seems like a missed opportunity.
Indeed, these were not a thing when vulkan-zig was initially made. Seems like a good idea, though there will be a slight incompatibility between dispatchable and non-dispatchable handles. I don't think that is much of a problem, though.