forked from mirror/vulkan-zig
Make command enums lower camel case to reflect command function name style
This commit is contained in:
@@ -6,76 +6,76 @@ const Allocator = std.mem.Allocator;
|
|||||||
const required_device_extensions = [_][]const u8{vk.extension_info.khr_swapchain.name};
|
const required_device_extensions = [_][]const u8{vk.extension_info.khr_swapchain.name};
|
||||||
|
|
||||||
const BaseDispatch = vk.BaseWrapper(.{
|
const BaseDispatch = vk.BaseWrapper(.{
|
||||||
.CreateInstance,
|
.createInstance,
|
||||||
});
|
});
|
||||||
|
|
||||||
const InstanceDispatch = vk.InstanceWrapper(.{
|
const InstanceDispatch = vk.InstanceWrapper(.{
|
||||||
.DestroyInstance,
|
.destroyInstance,
|
||||||
.CreateDevice,
|
.createDevice,
|
||||||
.DestroySurfaceKHR,
|
.destroySurfaceKHR,
|
||||||
.EnumeratePhysicalDevices,
|
.enumeratePhysicalDevices,
|
||||||
.GetPhysicalDeviceProperties,
|
.getPhysicalDeviceProperties,
|
||||||
.EnumerateDeviceExtensionProperties,
|
.enumerateDeviceExtensionProperties,
|
||||||
.GetPhysicalDeviceSurfaceFormatsKHR,
|
.getPhysicalDeviceSurfaceFormatsKHR,
|
||||||
.GetPhysicalDeviceSurfacePresentModesKHR,
|
.getPhysicalDeviceSurfacePresentModesKHR,
|
||||||
.GetPhysicalDeviceSurfaceCapabilitiesKHR,
|
.getPhysicalDeviceSurfaceCapabilitiesKHR,
|
||||||
.GetPhysicalDeviceQueueFamilyProperties,
|
.getPhysicalDeviceQueueFamilyProperties,
|
||||||
.GetPhysicalDeviceSurfaceSupportKHR,
|
.getPhysicalDeviceSurfaceSupportKHR,
|
||||||
.GetPhysicalDeviceMemoryProperties,
|
.getPhysicalDeviceMemoryProperties,
|
||||||
.GetDeviceProcAddr,
|
.getDeviceProcAddr,
|
||||||
});
|
});
|
||||||
|
|
||||||
const DeviceDispatch = vk.DeviceWrapper(.{
|
const DeviceDispatch = vk.DeviceWrapper(.{
|
||||||
.DestroyDevice,
|
.destroyDevice,
|
||||||
.GetDeviceQueue,
|
.getDeviceQueue,
|
||||||
.CreateSemaphore,
|
.createSemaphore,
|
||||||
.CreateFence,
|
.createFence,
|
||||||
.CreateImageView,
|
.createImageView,
|
||||||
.DestroyImageView,
|
.destroyImageView,
|
||||||
.DestroySemaphore,
|
.destroySemaphore,
|
||||||
.DestroyFence,
|
.destroyFence,
|
||||||
.GetSwapchainImagesKHR,
|
.getSwapchainImagesKHR,
|
||||||
.CreateSwapchainKHR,
|
.createSwapchainKHR,
|
||||||
.DestroySwapchainKHR,
|
.destroySwapchainKHR,
|
||||||
.AcquireNextImageKHR,
|
.acquireNextImageKHR,
|
||||||
.DeviceWaitIdle,
|
.deviceWaitIdle,
|
||||||
.WaitForFences,
|
.waitForFences,
|
||||||
.ResetFences,
|
.resetFences,
|
||||||
.QueueSubmit,
|
.queueSubmit,
|
||||||
.QueuePresentKHR,
|
.queuePresentKHR,
|
||||||
.CreateCommandPool,
|
.createCommandPool,
|
||||||
.DestroyCommandPool,
|
.destroyCommandPool,
|
||||||
.AllocateCommandBuffers,
|
.allocateCommandBuffers,
|
||||||
.FreeCommandBuffers,
|
.freeCommandBuffers,
|
||||||
.QueueWaitIdle,
|
.queueWaitIdle,
|
||||||
.CreateShaderModule,
|
.createShaderModule,
|
||||||
.DestroyShaderModule,
|
.destroyShaderModule,
|
||||||
.CreatePipelineLayout,
|
.createPipelineLayout,
|
||||||
.DestroyPipelineLayout,
|
.destroyPipelineLayout,
|
||||||
.CreateRenderPass,
|
.createRenderPass,
|
||||||
.DestroyRenderPass,
|
.destroyRenderPass,
|
||||||
.CreateGraphicsPipelines,
|
.createGraphicsPipelines,
|
||||||
.DestroyPipeline,
|
.destroyPipeline,
|
||||||
.CreateFramebuffer,
|
.createFramebuffer,
|
||||||
.DestroyFramebuffer,
|
.destroyFramebuffer,
|
||||||
.BeginCommandBuffer,
|
.beginCommandBuffer,
|
||||||
.EndCommandBuffer,
|
.endCommandBuffer,
|
||||||
.AllocateMemory,
|
.allocateMemory,
|
||||||
.FreeMemory,
|
.freeMemory,
|
||||||
.CreateBuffer,
|
.createBuffer,
|
||||||
.DestroyBuffer,
|
.destroyBuffer,
|
||||||
.GetBufferMemoryRequirements,
|
.getBufferMemoryRequirements,
|
||||||
.MapMemory,
|
.mapMemory,
|
||||||
.UnmapMemory,
|
.unmapMemory,
|
||||||
.BindBufferMemory,
|
.bindBufferMemory,
|
||||||
.CmdBeginRenderPass,
|
.cmdBeginRenderPass,
|
||||||
.CmdEndRenderPass,
|
.cmdEndRenderPass,
|
||||||
.CmdBindPipeline,
|
.cmdBindPipeline,
|
||||||
.CmdDraw,
|
.cmdDraw,
|
||||||
.CmdSetViewport,
|
.cmdSetViewport,
|
||||||
.CmdSetScissor,
|
.cmdSetScissor,
|
||||||
.CmdBindVertexBuffers,
|
.cmdBindVertexBuffers,
|
||||||
.CmdCopyBuffer,
|
.cmdCopyBuffer,
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const GraphicsContext = struct {
|
pub const GraphicsContext = struct {
|
||||||
|
|||||||
@@ -440,19 +440,70 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
|
|
||||||
try self.writer.print("pub const {s}Command = enum {{\n", .{dispatch_type_name});
|
try self.writer.print("pub const {s}Command = enum {{\n", .{dispatch_type_name});
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
if (decl.decl_type == .command) {
|
const command = switch (decl.decl_type) {
|
||||||
const command = decl.decl_type.command;
|
.command => |cmd| cmd,
|
||||||
if (classifyCommandDispatch(decl.name, command) == dispatch_type) {
|
else => continue,
|
||||||
try self.writer.print("{s},\n", .{trimVkNamespace(decl.name)});
|
};
|
||||||
}
|
|
||||||
|
if (classifyCommandDispatch(decl.name, command) == dispatch_type) {
|
||||||
|
try self.writeIdentifierWithCase(.camel, trimVkNamespace(decl.name));
|
||||||
|
try self.writer.writeAll(",\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
try self.writer.print(
|
||||||
|
\\
|
||||||
|
\\pub fn symbol(self: {s}Command) [:0]const u8 {{
|
||||||
|
\\ return switch (self) {{
|
||||||
|
\\
|
||||||
|
, .{dispatch_type_name}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (self.registry.decls) |decl| {
|
||||||
|
const command = switch (decl.decl_type) {
|
||||||
|
.command => |cmd| cmd,
|
||||||
|
else => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (classifyCommandDispatch(decl.name, command) == dispatch_type) {
|
||||||
|
try self.writer.writeAll(".");
|
||||||
|
try self.writeIdentifierWithCase(.camel, trimVkNamespace(decl.name));
|
||||||
|
try self.writer.print(" => \"{s}\",\n", .{ decl.name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try self.writer.writeAll("};\n}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
try self.writer.print(
|
||||||
|
\\
|
||||||
|
\\pub fn PfnType(comptime self: {s}Command) type {{
|
||||||
|
\\ return switch (self) {{
|
||||||
|
\\
|
||||||
|
, .{dispatch_type_name}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (self.registry.decls) |decl| {
|
||||||
|
const command = switch (decl.decl_type) {
|
||||||
|
.command => |cmd| cmd,
|
||||||
|
else => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (classifyCommandDispatch(decl.name, command) == dispatch_type) {
|
||||||
|
try self.writer.writeAll(".");
|
||||||
|
try self.writeIdentifierWithCase(.camel, trimVkNamespace(decl.name));
|
||||||
|
try self.writer.writeAll(" => ");
|
||||||
|
try self.renderCommandPtrName(decl.name);
|
||||||
|
try self.writer.writeAll(",\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try self.writer.writeAll("};\n}\n");
|
||||||
|
}
|
||||||
|
|
||||||
try self.writer.writeAll("};\n");
|
try self.writer.writeAll("};\n");
|
||||||
try self.writer.print(
|
|
||||||
\\fn {s}CommandToString(cmd: {s}Command) []const u8 {{
|
|
||||||
\\ return std.meta.tagName(cmd);
|
|
||||||
\\}}
|
|
||||||
, .{ dispatch_type_name, dispatch_type_name });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renderCopyright(self: *Self) !void {
|
fn renderCopyright(self: *Self) !void {
|
||||||
@@ -965,17 +1016,16 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
|
|
||||||
try self.writer.print(
|
try self.writer.print(
|
||||||
\\pub fn {s}Wrapper(comptime cmds: anytype) type {{
|
\\pub fn {s}Wrapper(comptime cmds: anytype) type {{
|
||||||
|
\\ const cmd_array: [cmds.len]{s}Command = cmds;
|
||||||
\\ comptime var fields: [cmds.len]std.builtin.TypeInfo.StructField = undefined;
|
\\ comptime var fields: [cmds.len]std.builtin.TypeInfo.StructField = undefined;
|
||||||
\\ inline for (cmds) |cmd, i| {{
|
\\ inline for (cmd_array) |cmd, i| {{
|
||||||
\\ const cmd_name = {s}CommandToString(cmd);
|
\\ const PfnType = cmd.PfnType();
|
||||||
\\ const cmd_type_name = "Pfn" ++ cmd_name;
|
|
||||||
\\ const cmd_type = @field(GlobalScope, cmd_type_name);
|
|
||||||
\\ fields[i] = .{{
|
\\ fields[i] = .{{
|
||||||
\\ .name = "vk" ++ cmd_name,
|
\\ .name = cmd.symbol(),
|
||||||
\\ .field_type = cmd_type,
|
\\ .field_type = PfnType,
|
||||||
\\ .default_value = null,
|
\\ .default_value = null,
|
||||||
\\ .is_comptime = false,
|
\\ .is_comptime = false,
|
||||||
\\ .alignment = @alignOf(*cmd_type),
|
\\ .alignment = @alignOf(PfnType),
|
||||||
\\ }};
|
\\ }};
|
||||||
\\ }}
|
\\ }}
|
||||||
\\ const Dispatch = @Type(.{{
|
\\ const Dispatch = @Type(.{{
|
||||||
|
|||||||
Reference in New Issue
Block a user