forked from mirror/vulkan-zig
also generate command aliases (fixes #71)
This commit is contained in:
@@ -306,16 +306,22 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
return mem.endsWith(u8, base_name, "Flags");
|
return mem.endsWith(u8, base_name, "Flags");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolveDeclaration(self: Self, start_name: []const u8) ?*const reg.DeclarationType {
|
fn resolveDeclaration(self: Self, name: []const u8) ?reg.DeclarationType {
|
||||||
var name = start_name;
|
const decl = self.declarations_by_name.get(name) orelse return null;
|
||||||
return while (true) {
|
return self.resolveAlias(decl.*) catch return null;
|
||||||
const decl = self.declarations_by_name.get(name) orelse return null;
|
}
|
||||||
if (decl.* != .alias) {
|
|
||||||
break decl;
|
|
||||||
}
|
|
||||||
|
|
||||||
name = decl.alias.name;
|
fn resolveAlias(self: Self, start_decl: reg.DeclarationType) !reg.DeclarationType {
|
||||||
} else unreachable;
|
var decl = start_decl;
|
||||||
|
while (true) {
|
||||||
|
const name = switch (decl) {
|
||||||
|
.alias => |alias| alias.name,
|
||||||
|
else => return decl,
|
||||||
|
};
|
||||||
|
|
||||||
|
const decl_ptr = self.declarations_by_name.get(name) orelse return error.InvalidRegistry;
|
||||||
|
decl = decl_ptr.*;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn isInOutPointer(self: Self, ptr: reg.Pointer) !bool {
|
fn isInOutPointer(self: Self, ptr: reg.Pointer) !bool {
|
||||||
@@ -324,7 +330,7 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const decl = self.resolveDeclaration(ptr.child.name) orelse return error.InvalidRegistry;
|
const decl = self.resolveDeclaration(ptr.child.name) orelse return error.InvalidRegistry;
|
||||||
if (decl.* != .container) {
|
if (decl != .container) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,15 +959,23 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
|
|
||||||
fn renderCommandPtrs(self: *Self) !void {
|
fn renderCommandPtrs(self: *Self) !void {
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
if (decl.decl_type != .command) {
|
switch (decl.decl_type) {
|
||||||
continue;
|
.command => {
|
||||||
|
try self.writer.writeAll("pub const ");
|
||||||
|
try self.renderCommandPtrName(decl.name);
|
||||||
|
try self.writer.writeAll(" = ");
|
||||||
|
try self.renderCommandPtr(decl.decl_type.command, false);
|
||||||
|
try self.writer.writeAll(";\n");
|
||||||
|
},
|
||||||
|
.alias => |alias| if (alias.target == .other_command) {
|
||||||
|
try self.writer.writeAll("pub const ");
|
||||||
|
try self.renderCommandPtrName(decl.name);
|
||||||
|
try self.writer.writeAll(" = ");
|
||||||
|
try self.renderCommandPtrName(alias.name);
|
||||||
|
try self.writer.writeAll(";\n");
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
try self.writer.writeAll("pub const ");
|
|
||||||
try self.renderCommandPtrName(decl.name);
|
|
||||||
try self.writer.writeAll(" = ");
|
|
||||||
try self.renderCommandPtr(decl.decl_type.command, false);
|
|
||||||
try self.writer.writeAll(";\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1044,7 +1058,10 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
\\
|
\\
|
||||||
, .{name});
|
, .{name});
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
const command = switch (decl.decl_type) {
|
// If the target type does not exist, it was likely an empty enum -
|
||||||
|
// assume spec is correct and that this was not a function alias.
|
||||||
|
const decl_type = self.resolveAlias(decl.decl_type) catch continue;
|
||||||
|
const command = switch (decl_type) {
|
||||||
.command => |cmd| cmd,
|
.command => |cmd| cmd,
|
||||||
else => continue,
|
else => continue,
|
||||||
};
|
};
|
||||||
@@ -1062,7 +1079,10 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
\\
|
\\
|
||||||
, .{name});
|
, .{name});
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
const command = switch (decl.decl_type) {
|
// If the target type does not exist, it was likely an empty enum -
|
||||||
|
// assume spec is correct and that this was not a function alias.
|
||||||
|
const decl_type = self.resolveAlias(decl.decl_type) catch continue;
|
||||||
|
const command = switch (decl_type) {
|
||||||
.command => |cmd| cmd,
|
.command => |cmd| cmd,
|
||||||
else => continue,
|
else => continue,
|
||||||
};
|
};
|
||||||
@@ -1083,7 +1103,10 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
\\
|
\\
|
||||||
, .{name});
|
, .{name});
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
const command = switch (decl.decl_type) {
|
// If the target type does not exist, it was likely an empty enum -
|
||||||
|
// assume spec is correct and that this was not a function alias.
|
||||||
|
const decl_type = self.resolveAlias(decl.decl_type) catch continue;
|
||||||
|
const command = switch (decl_type) {
|
||||||
.command => |cmd| cmd,
|
.command => |cmd| cmd,
|
||||||
else => continue,
|
else => continue,
|
||||||
};
|
};
|
||||||
@@ -1153,11 +1176,27 @@ fn Renderer(comptime WriterType: type) type {
|
|||||||
try self.renderWrapperLoader(dispatch_type);
|
try self.renderWrapperLoader(dispatch_type);
|
||||||
|
|
||||||
for (self.registry.decls) |decl| {
|
for (self.registry.decls) |decl| {
|
||||||
if (decl.decl_type == .command) {
|
// If the target type does not exist, it was likely an empty enum -
|
||||||
const command = decl.decl_type.command;
|
// assume spec is correct and that this was not a function alias.
|
||||||
if (classifyCommandDispatch(decl.name, command) == dispatch_type) {
|
const decl_type = self.resolveAlias(decl.decl_type) catch continue;
|
||||||
try self.renderWrapper(decl.name, decl.decl_type.command);
|
const command = switch (decl_type) {
|
||||||
}
|
.command => |cmd| cmd,
|
||||||
|
else => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (classifyCommandDispatch(decl.name, command) != dispatch_type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (decl.decl_type) {
|
||||||
|
.command => try self.renderWrapper(decl.name, decl.decl_type.command),
|
||||||
|
.alias => |alias| {
|
||||||
|
try self.writer.writeAll("pub const ");
|
||||||
|
try self.writeIdentifierWithCase(.camel, trimVkNamespace(decl.name));
|
||||||
|
try self.writer.writeAll(" = ");
|
||||||
|
try self.writeIdentifierWithCase(.camel, trimVkNamespace(alias.name));
|
||||||
|
try self.writer.writeAll(";\n");
|
||||||
|
},
|
||||||
|
else => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user