Snektron/vulkan-zig

Add an easier way to enable all functions of a particular extension

Closed this issue · 2 comments

Currently, you're required to write out all functions that you want to use:

const DeviceDispatch = vk.DeviceWrapper(.{
    .destroyDevice = true,
    .getDeviceQueue = true,
    .createSemaphore = true,
    .createFence = true,
    .createImageView = true,
    ...,
    .getSwapchainImagesKHR = true,
    .createSwapchainKHR = true,
    .destroySwapchainKHR = true,
    .acquireNextImageKHR = true,

});

It would be nice if there was a way to just import all functions from a particular extension. Since the Flags already implement the FlagsMixing, perhaps we could do something like

const DeviceDispatch = vk.DeviceWrapper(vk.deviceFunctions.merge(
    vk.extension_info.ext_swapchain_colorspace.functions,
));

Now that #127 is merged, I realize that actually creating the function sets is kind of verbose. I figured, maybe there is a way to unify the "Info" structs, and pass a set of these instead of a set of functions specifically. A quick mock up:

// User declares a set of features and extensions up front. These contain both the base/instance/device functions of the feature or extension.
const things = .{
  vk.features.version_1_0,
  vk.extensions.khr_surface,
  vk.extensions.khr_swapchain,
  // A "custom" set can also be created. This would just initialize the `Info` structure
  .{
    .instance_functions = .{
      .getPhysicalDeviceFeatures2KHR = true,
    },
    .device_features = .{
      .cmdPushDescriptorSetKHR = true,
    },
  },
};

// Instead of separately passing each function to a wrapper, just pass the set
const InstanceDispatch = vk.InstanceWrapper(things);
const DeviceDispatch = vk.DeviceWrapper(things);

Implemented the above. It wasn't so hard and feels pretty nice