spirv: make generic globals invocation-local

This commit is contained in:
Robin Voetter
2024-03-02 13:08:21 +01:00
parent 20d7bb68ac
commit 9b18125562
10 changed files with 1262 additions and 778 deletions

View File

@@ -42,6 +42,26 @@ const StringPairContext = struct {
const OperandKindMap = std.ArrayHashMap(StringPair, OperandKind, StringPairContext, true);
/// Khronos made it so that these names are not defined explicitly, so
/// we need to hardcode it (like they did).
/// See https://github.com/KhronosGroup/SPIRV-Registry/
const set_names = std.ComptimeStringMap([]const u8, .{
.{ "opencl.std.100", "OpenCL.std" },
.{ "glsl.std.450", "GLSL.std.450" },
.{ "opencl.debuginfo.100", "OpenCL.DebugInfo.100" },
.{ "spv-amd-shader-ballot", "SPV_AMD_shader_ballot" },
.{ "nonsemantic.shader.debuginfo.100", "NonSemantic.Shader.DebugInfo.100" },
.{ "nonsemantic.vkspreflection", "NonSemantic.VkspReflection" },
.{ "nonsemantic.clspvreflection", "NonSemantic.ClspvReflection.6" }, // This version needs to be handled manually
.{ "spv-amd-gcn-shader", "SPV_AMD_gcn_shader" },
.{ "spv-amd-shader-trinary-minmax", "SPV_AMD_shader_trinary_minmax" },
.{ "debuginfo", "DebugInfo" },
.{ "nonsemantic.debugprintf", "NonSemantic.DebugPrintf" },
.{ "spv-amd-shader-explicit-vertex-parameter", "SPV_AMD_shader_explicit_vertex_parameter" },
.{ "nonsemantic.debugbreak", "NonSemantic.DebugBreak" },
.{ "zig", "zig" },
});
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
@@ -88,7 +108,7 @@ fn readExtRegistry(exts: *std.ArrayList(Extension), a: Allocator, dir: std.fs.Di
std.sort.block(Instruction, spec.instructions, CmpInst{}, CmpInst.lt);
try exts.append(.{ .name = try a.dupe(u8, name), .spec = spec });
try exts.append(.{ .name = set_names.get(name).?, .spec = spec });
}
fn readRegistry(comptime RegistryType: type, a: Allocator, dir: std.fs.Dir, path: []const u8) !RegistryType {
@@ -150,6 +170,8 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
try writer.writeAll(
\\//! This file is auto-generated by tools/gen_spirv_spec.zig.
\\
\\const std = @import("std");
\\
\\pub const Version = packed struct(Word) {
\\ padding: u8 = 0,
\\ minor: u8,
@@ -163,8 +185,20 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
\\
\\pub const Word = u32;
\\pub const IdResult = enum(Word) {
\\ none,
\\ _,
\\ none,
\\ _,
\\
\\ pub fn format(
\\ self: IdResult,
\\ comptime _: []const u8,
\\ _: std.fmt.FormatOptions,
\\ writer: anytype,
\\ ) @TypeOf(writer).Error!void {
\\ switch (self) {
\\ .none => try writer.writeAll("(none)"),
\\ else => try writer.print("%{}", .{@intFromEnum(self)}),
\\ }
\\ }
\\};
\\pub const IdResultType = IdResult;
\\pub const IdRef = IdResult;
@@ -220,6 +254,7 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
\\ operands: []const Operand,
\\};
\\
\\pub const zig_generator_id: Word = 41;
\\
);