aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Cache.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2023-10-16 02:04:09 +0200
committerGitHub <noreply@github.com>2023-10-16 02:04:09 +0200
commitfd6b3db34252f2a548630c0e57fe80f32202aa12 (patch)
tree0111caae6ee7e5c69a98702199609b163ed27405 /src/codegen/spirv/Cache.zig
parenta1e0b9979ab2a47ad1d13dd06106c3143d9a1c9e (diff)
parent8c153221b9e1ff34edd18382770d02aae36dbe74 (diff)
downloadzig-fd6b3db34252f2a548630c0e57fe80f32202aa12.tar.gz
zig-fd6b3db34252f2a548630c0e57fe80f32202aa12.zip
Merge pull request #17293 from Snektron/spirv-aaaa
spirv: more instructions
Diffstat (limited to 'src/codegen/spirv/Cache.zig')
-rw-r--r--src/codegen/spirv/Cache.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/codegen/spirv/Cache.zig b/src/codegen/spirv/Cache.zig
index 68fea5c47a..ad2d3442e5 100644
--- a/src/codegen/spirv/Cache.zig
+++ b/src/codegen/spirv/Cache.zig
@@ -81,6 +81,9 @@ const Tag = enum {
/// have member names trailing.
/// data is payload to SimpleStructType
type_struct_simple_with_member_names,
+ /// Opaque type.
+ /// data is name string.
+ type_opaque,
// -- Values
/// Value of type u8
@@ -235,6 +238,7 @@ pub const Key = union(enum) {
function_type: FunctionType,
ptr_type: PointerType,
struct_type: StructType,
+ opaque_type: OpaqueType,
// -- values
int: Int,
@@ -289,6 +293,10 @@ pub const Key = union(enum) {
}
};
+ pub const OpaqueType = struct {
+ name: String = .none,
+ };
+
pub const Int = struct {
/// The type: any bitness integer.
ty: Ref,
@@ -427,6 +435,13 @@ pub const Key = union(enum) {
else => unreachable,
};
}
+
+ pub fn isNumericalType(self: Key) bool {
+ return switch (self) {
+ .int_type, .float_type => true,
+ else => false,
+ };
+ }
};
pub fn deinit(self: *Self, spv: *const Module) void {
@@ -539,6 +554,13 @@ fn emit(
}
// TODO: Decorations?
},
+ .opaque_type => |opaque_type| {
+ const name = if (self.getString(opaque_type.name)) |name| name else "";
+ try section.emit(spv.gpa, .OpTypeOpaque, .{
+ .id_result = result_id,
+ .literal_string = name,
+ });
+ },
.int => |int| {
const int_type = self.lookup(int.ty).int_type;
const ty_id = self.resultId(int.ty);
@@ -697,6 +719,11 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
};
}
},
+ .opaque_type => |opaque_type| Item{
+ .tag = .type_opaque,
+ .result_id = result_id,
+ .data = @intFromEnum(opaque_type.name),
+ },
.int => |int| blk: {
const int_type = self.lookup(int.ty).int_type;
if (int_type.signedness == .unsigned and int_type.bits == 8) {
@@ -874,6 +901,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
},
};
},
+ .type_opaque => .{
+ .opaque_type = .{
+ .name = @as(String, @enumFromInt(data)),
+ },
+ },
.float16 => .{ .float = .{
.ty = self.get(.{ .float_type = .{ .bits = 16 } }),
.value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },