diff options
| author | Robin Voetter <robin@voetter.nl> | 2025-02-18 21:14:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-18 21:14:02 +0100 |
| commit | 4720a79477e7f0faf30bcce3ea4bfd3056469a79 (patch) | |
| tree | 917bd1ad111065e548971ffec88e2b6b5ac2f6c6 /src/codegen/spirv/Assembler.zig | |
| parent | 0779e847f79851419dfeb39595b1817ce72ea9fa (diff) | |
| parent | 787208293960a02fbaf175a442d911c426a205cd (diff) | |
| download | zig-4720a79477e7f0faf30bcce3ea4bfd3056469a79.tar.gz zig-4720a79477e7f0faf30bcce3ea4bfd3056469a79.zip | |
Merge pull request #22889 from alichraghi/ali_spv
spirv: miscellaneous stuff
Diffstat (limited to 'src/codegen/spirv/Assembler.zig')
| -rw-r--r-- | src/codegen/spirv/Assembler.zig | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/codegen/spirv/Assembler.zig b/src/codegen/spirv/Assembler.zig index 2cfb590273..0713a63a7e 100644 --- a/src/codegen/spirv/Assembler.zig +++ b/src/codegen/spirv/Assembler.zig @@ -135,6 +135,9 @@ const AsmValue = union(enum) { /// This is a pre-supplied constant integer value. constant: u32, + /// This is a pre-supplied constant string value. + string: []const u8, + /// Retrieve the result-id of this AsmValue. Asserts that this AsmValue /// is of a variant that allows the result to be obtained (not an unresolved /// forward declaration, not in the process of being declared, etc). @@ -144,6 +147,7 @@ const AsmValue = union(enum) { .unresolved_forward_reference, // TODO: Lower this value as constant? .constant, + .string, => unreachable, .value => |result| result, .ty => |result| result, @@ -274,6 +278,16 @@ fn processInstruction(self: *Assembler) !void { .OpEntryPoint => { return self.fail(0, "cannot export entry points via OpEntryPoint, export the kernel using callconv(.Kernel)", .{}); }, + .OpCapability => { + try self.spv.addCapability(@enumFromInt(self.inst.operands.items[0].value)); + return; + }, + .OpExtension => { + const ext_name_offset = self.inst.operands.items[0].string; + const ext_name = std.mem.sliceTo(self.inst.string_bytes.items[ext_name_offset..], 0); + try self.spv.addExtension(ext_name); + return; + }, .OpExtInstImport => blk: { const set_name_offset = self.inst.operands.items[1].string; const set_name = std.mem.sliceTo(self.inst.string_bytes.items[set_name_offset..], 0); @@ -635,6 +649,28 @@ fn parseBitEnum(self: *Assembler, kind: spec.OperandKind) !void { /// Also handles parsing any required extra operands. fn parseValueEnum(self: *Assembler, kind: spec.OperandKind) !void { const tok = self.currentToken(); + if (self.eatToken(.placeholder)) { + const name = self.tokenText(tok)[1..]; + const value = self.value_map.get(name) orelse { + return self.fail(tok.start, "invalid placeholder '${s}'", .{name}); + }; + switch (value) { + .constant => |literal32| { + try self.inst.operands.append(self.gpa, .{ .value = literal32 }); + }, + .string => |str| { + const enumerant = for (kind.enumerants()) |enumerant| { + if (std.mem.eql(u8, enumerant.name, str)) break enumerant; + } else { + return self.fail(tok.start, "'{s}' is not a valid value for enumeration {s}", .{ str, @tagName(kind) }); + }; + try self.inst.operands.append(self.gpa, .{ .value = enumerant.value }); + }, + else => return self.fail(tok.start, "value '{s}' cannot be used as placeholder", .{name}), + } + return; + } + try self.expectToken(.value); const text = self.tokenText(tok); |
