Commit 4e22f811e7

Robin Voetter <robin@voetter.nl>
2023-09-23 01:31:07
spirv: opaque types
1 parent a241cf9
Changed files (2)
src
codegen
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)))) },
src/codegen/spirv.zig
@@ -1215,6 +1215,13 @@ pub const DeclGen = struct {
                 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
                 return ty_ref;
             },
+            .Opaque => {
+                return try self.spv.resolve(.{
+                    .opaque_type = .{
+                        .name = .none, // TODO
+                    },
+                });
+            },
 
             .Null,
             .Undefined,