aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2023-09-23 01:31:07 +0200
committerRobin Voetter <robin@voetter.nl>2023-10-15 13:59:20 +0200
commit4e22f811e746ab5771ea7355ed8dfbfcda0420c2 (patch)
treeee60da28fb14c7925dd5cb188949dcf43cdba312 /src/codegen/spirv
parenta241cf90d66ee0a47fafc49dc65fe32871557a01 (diff)
downloadzig-4e22f811e746ab5771ea7355ed8dfbfcda0420c2.tar.gz
zig-4e22f811e746ab5771ea7355ed8dfbfcda0420c2.zip
spirv: opaque types
Diffstat (limited to 'src/codegen/spirv')
-rw-r--r--src/codegen/spirv/Cache.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/codegen/spirv/Cache.zig b/src/codegen/spirv/Cache.zig
index 68fea5c47a..7f5590344c 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,
@@ -539,6 +547,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 +712,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 +894,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)))) },