forked from mirror/vulkan-zig
Separate parsed registries into core and non-core
This commit is contained in:
@@ -6,9 +6,30 @@ pub fn generate(allocator: *Allocator, spec_jsons: []const []const u8, writer: a
|
|||||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
|
||||||
const registries = try arena.allocator.alloc(reg.Registry, spec_jsons.len);
|
// Only one of the passed specs may be core (and one of them _must_ be core) -
|
||||||
for (registries) |*registry, i| {
|
// the others must be exensions.
|
||||||
var tokens = std.json.TokenStream.init(spec_jsons[i]);
|
var core_registry: reg.CoreRegistry = undefined;
|
||||||
registry.* = try std.json.parse(reg.Registry, &tokens, .{.allocator = &arena.allocator});
|
const num_ext_registries = spec_jsons.len - 1;
|
||||||
|
const ext_registries = try arena.allocator.alloc(reg.ExtensionRegistry, num_ext_registries);
|
||||||
|
|
||||||
|
var ext_registry_i: usize = 0;
|
||||||
|
for (spec_jsons) |spec_json| {
|
||||||
|
var tokens = std.json.TokenStream.init(spec_json);
|
||||||
|
const registry = try std.json.parse(reg.Registry, &tokens, .{.allocator = &arena.allocator});
|
||||||
|
switch (registry) {
|
||||||
|
.core => |parsed_core_registry| core_registry = parsed_core_registry,
|
||||||
|
.extension => |parsed_ext_registry| {
|
||||||
|
if (ext_registry_i == num_ext_registries) {
|
||||||
|
return error.NoCoreRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
ext_registries[ext_registry_i] = parsed_ext_registry;
|
||||||
|
ext_registry_i += 1;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ext_registry_i != num_ext_registries) {
|
||||||
|
return error.MultipleCoreRegistries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ pub const CoreRegistry = struct {
|
|||||||
pub const ExtensionRegistry = struct {
|
pub const ExtensionRegistry = struct {
|
||||||
copyright: [][]const u8,
|
copyright: [][]const u8,
|
||||||
version: u32,
|
version: u32,
|
||||||
minor_version: u32,
|
|
||||||
revision: u32,
|
revision: u32,
|
||||||
instructions: []Instruction,
|
instructions: []Instruction,
|
||||||
operand_kinds: []OperandKind,
|
operand_kinds: []OperandKind = &[_]OperandKind{},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Instruction = struct {
|
pub const Instruction = struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user