vulkan-zig icon indicating copy to clipboard operation
vulkan-zig copied to clipboard

Use opaque types instead of handle enums

Open anyputer opened this issue 1 year ago • 2 comments

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.

anyputer avatar Jan 11 '24 16:01 anyputer

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.

Snektron avatar Jan 11 '24 19:01 Snektron