authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-23 01:31:07+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 13:59:20+02:00
log4e22f811e746ab5771ea7355ed8dfbfcda0420c2
treeee60da28fb14c7925dd5cb188949dcf43cdba312
parenta241cf90d66ee0a47fafc49dc65fe32871557a01
signaturebadge-check Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: opaque types


2 files changed, 32 insertions(+), 0 deletions(-)

src/codegen/spirv.zig+7
...@@ -1215,6 +1215,13 @@ pub const DeclGen = struct {...@@ -1215,6 +1215,13 @@ pub const DeclGen = struct {
1215 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });1215 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
1216 return ty_ref;1216 return ty_ref;
1217 },1217 },
1218 .Opaque => {
1219 return try self.spv.resolve(.{
1220 .opaque_type = .{
1221 .name = .none, // TODO
1222 },
1223 });
1224 },
12181225
1219 .Null,1226 .Null,
1220 .Undefined,1227 .Undefined,
src/codegen/spirv/Cache.zig+25
...@@ -81,6 +81,9 @@ const Tag = enum {...@@ -81,6 +81,9 @@ const Tag = enum {
81 /// have member names trailing.81 /// have member names trailing.
82 /// data is payload to SimpleStructType82 /// data is payload to SimpleStructType
83 type_struct_simple_with_member_names,83 type_struct_simple_with_member_names,
84 /// Opaque type.
85 /// data is name string.
86 type_opaque,
8487
85 // -- Values88 // -- Values
86 /// Value of type u889 /// Value of type u8
...@@ -235,6 +238,7 @@ pub const Key = union(enum) {...@@ -235,6 +238,7 @@ pub const Key = union(enum) {
235 function_type: FunctionType,238 function_type: FunctionType,
236 ptr_type: PointerType,239 ptr_type: PointerType,
237 struct_type: StructType,240 struct_type: StructType,
241 opaque_type: OpaqueType,
238242
239 // -- values243 // -- values
240 int: Int,244 int: Int,
...@@ -289,6 +293,10 @@ pub const Key = union(enum) {...@@ -289,6 +293,10 @@ pub const Key = union(enum) {
289 }293 }
290 };294 };
291295
296 pub const OpaqueType = struct {
297 name: String = .none,
298 };
299
292 pub const Int = struct {300 pub const Int = struct {
293 /// The type: any bitness integer.301 /// The type: any bitness integer.
294 ty: Ref,302 ty: Ref,
...@@ -539,6 +547,13 @@ fn emit(...@@ -539,6 +547,13 @@ fn emit(
539 }547 }
540 // TODO: Decorations?548 // TODO: Decorations?
541 },549 },
550 .opaque_type => |opaque_type| {
551 const name = if (self.getString(opaque_type.name)) |name| name else "";
552 try section.emit(spv.gpa, .OpTypeOpaque, .{
553 .id_result = result_id,
554 .literal_string = name,
555 });
556 },
542 .int => |int| {557 .int => |int| {
543 const int_type = self.lookup(int.ty).int_type;558 const int_type = self.lookup(int.ty).int_type;
544 const ty_id = self.resultId(int.ty);559 const ty_id = self.resultId(int.ty);
...@@ -697,6 +712,11 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {...@@ -697,6 +712,11 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
697 };712 };
698 }713 }
699 },714 },
715 .opaque_type => |opaque_type| Item{
716 .tag = .type_opaque,
717 .result_id = result_id,
718 .data = @intFromEnum(opaque_type.name),
719 },
700 .int => |int| blk: {720 .int => |int| blk: {
701 const int_type = self.lookup(int.ty).int_type;721 const int_type = self.lookup(int.ty).int_type;
702 if (int_type.signedness == .unsigned and int_type.bits == 8) {722 if (int_type.signedness == .unsigned and int_type.bits == 8) {
...@@ -874,6 +894,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {...@@ -874,6 +894,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
874 },894 },
875 };895 };
876 },896 },
897 .type_opaque => .{
898 .opaque_type = .{
899 .name = @as(String, @enumFromInt(data)),
900 },
901 },
877 .float16 => .{ .float = .{902 .float16 => .{ .float = .{
878 .ty = self.get(.{ .float_type = .{ .bits = 16 } }),903 .ty = self.get(.{ .float_type = .{ .bits = 16 } }),
879 .value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },904 .value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },