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
signature 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 {
12151215 try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
12161216 return ty_ref;
12171217 },
1218 .Opaque => {
1219 return try self.spv.resolve(.{
1220 .opaque_type = .{
1221 .name = .none, // TODO
1222 },
1223 });
1224 },
12181225
12191226 .Null,
12201227 .Undefined,
src/codegen/spirv/Cache.zig+25
......@@ -81,6 +81,9 @@ const Tag = enum {
8181 /// have member names trailing.
8282 /// data is payload to SimpleStructType
8383 type_struct_simple_with_member_names,
84 /// Opaque type.
85 /// data is name string.
86 type_opaque,
8487
8588 // -- Values
8689 /// Value of type u8
......@@ -235,6 +238,7 @@ pub const Key = union(enum) {
235238 function_type: FunctionType,
236239 ptr_type: PointerType,
237240 struct_type: StructType,
241 opaque_type: OpaqueType,
238242
239243 // -- values
240244 int: Int,
......@@ -289,6 +293,10 @@ pub const Key = union(enum) {
289293 }
290294 };
291295
296 pub const OpaqueType = struct {
297 name: String = .none,
298 };
299
292300 pub const Int = struct {
293301 /// The type: any bitness integer.
294302 ty: Ref,
......@@ -539,6 +547,13 @@ fn emit(
539547 }
540548 // TODO: Decorations?
541549 },
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 },
542557 .int => |int| {
543558 const int_type = self.lookup(int.ty).int_type;
544559 const ty_id = self.resultId(int.ty);
......@@ -697,6 +712,11 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
697712 };
698713 }
699714 },
715 .opaque_type => |opaque_type| Item{
716 .tag = .type_opaque,
717 .result_id = result_id,
718 .data = @intFromEnum(opaque_type.name),
719 },
700720 .int => |int| blk: {
701721 const int_type = self.lookup(int.ty).int_type;
702722 if (int_type.signedness == .unsigned and int_type.bits == 8) {
......@@ -874,6 +894,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
874894 },
875895 };
876896 },
897 .type_opaque => .{
898 .opaque_type = .{
899 .name = @as(String, @enumFromInt(data)),
900 },
901 },
877902 .float16 => .{ .float = .{
878903 .ty = self.get(.{ .float_type = .{ .bits = 16 } }),
879904 .value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },