authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-08 19:05:48+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:55+02:00
log979b4102588fbb0d066060a5a6b6e10f584158ac
tree6748c0fa79b9251eda4dc456b89efa8dab8c770f
parenta7563e453dce0cc256a0c40af434731f2cf7dcaf
signaturelock-open Commit is signed but in an unrecognized format.

spirv: Do not generate the Alignment attribute on pointers for now

It seems that some implementations may have problems with these right now, like Intel and Rusticl. In theory, these attributes should be superficial on the pointer type, as alignment guarantees are also added via the alignment option of the OpLoad and OpStore instructions. Therefore, get rid of them for now.

4 files changed, 20 insertions(+), 36 deletions(-)

src/codegen/spirv.zig+14-27
...@@ -825,6 +825,11 @@ pub const DeclGen = struct {...@@ -825,6 +825,11 @@ pub const DeclGen = struct {
825 // - Underaligned pointers. These need to be packed into the word array by using a mixture of825 // - Underaligned pointers. These need to be packed into the word array by using a mixture of
826 // OpSpecConstantOp instructions such as OpConvertPtrToU, OpBitcast, OpShift, etc.826 // OpSpecConstantOp instructions such as OpConvertPtrToU, OpBitcast, OpShift, etc.
827827
828 // TODO: Implement alignment here.
829 // This is hoing to require some hacks because there is no real way to
830 // set an OpVariable's alignment.
831 _ = alignment;
832
828 assert(storage_class != .Generic and storage_class != .Function);833 assert(storage_class != .Generic and storage_class != .Function);
829834
830 log.debug("lowerIndirectConstant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtDebug() });835 log.debug("lowerIndirectConstant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtDebug() });
...@@ -832,7 +837,7 @@ pub const DeclGen = struct {...@@ -832,7 +837,7 @@ pub const DeclGen = struct {
832 const section = &self.spv.globals.section;837 const section = &self.spv.globals.section;
833838
834 const ty_ref = try self.resolveType(ty, .indirect);839 const ty_ref = try self.resolveType(ty, .indirect);
835 const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, alignment);840 const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, 0);
836841
837 // const target = self.getTarget();842 // const target = self.getTarget();
838843
...@@ -874,7 +879,7 @@ pub const DeclGen = struct {...@@ -874,7 +879,7 @@ pub const DeclGen = struct {
874 try icl.flush();879 try icl.flush();
875880
876 const constant_struct_ty_ref = try self.spv.simpleStructType(icl.members.items);881 const constant_struct_ty_ref = try self.spv.simpleStructType(icl.members.items);
877 const ptr_constant_struct_ty_ref = try self.spv.ptrType(constant_struct_ty_ref, storage_class, alignment);882 const ptr_constant_struct_ty_ref = try self.spv.ptrType(constant_struct_ty_ref, storage_class, 0);
878883
879 const constant_struct_id = self.spv.allocId();884 const constant_struct_id = self.spv.allocId();
880 try section.emit(self.spv.gpa, .OpSpecConstantComposite, .{885 try section.emit(self.spv.gpa, .OpSpecConstantComposite, .{
...@@ -909,7 +914,7 @@ pub const DeclGen = struct {...@@ -909,7 +914,7 @@ pub const DeclGen = struct {
909 });914 });
910915
911 if (cast_to_generic) {916 if (cast_to_generic) {
912 const generic_ptr_ty_ref = try self.spv.ptrType(ty_ref, .Generic, alignment);917 const generic_ptr_ty_ref = try self.spv.ptrType(ty_ref, .Generic, 0);
913 try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{918 try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{
914 .id_result_type = self.typeId(generic_ptr_ty_ref),919 .id_result_type = self.typeId(generic_ptr_ty_ref),
915 .id_result = result_id,920 .id_result = result_id,
...@@ -1165,21 +1170,16 @@ pub const DeclGen = struct {...@@ -1165,21 +1170,16 @@ pub const DeclGen = struct {
1165 .Pointer => {1170 .Pointer => {
1166 const ptr_info = ty.ptrInfo().data;1171 const ptr_info = ty.ptrInfo().data;
11671172
1168 const ptr_payload = try self.spv.arena.create(SpvType.Payload.Pointer);1173 const storage_class = spvStorageClass(ptr_info.@"addrspace");
1169 ptr_payload.* = .{1174 const child_ty_ref = try self.resolveType(ptr_info.pointee_type, .indirect);
1170 .storage_class = spvStorageClass(ptr_info.@"addrspace"),1175 const ptr_ty_ref = try self.spv.ptrType(child_ty_ref, storage_class, 0);
1171 .child_type = try self.resolveType(ptr_info.pointee_type, .indirect),
1172 // Note: only available in Kernels!
1173 .alignment = ty.ptrAlignment(target) * 8,
1174 };
1175 const ptr_ty_id = try self.spv.resolveType(SpvType.initPayload(&ptr_payload.base));
11761176
1177 if (ptr_info.size != .Slice) {1177 if (ptr_info.size != .Slice) {
1178 return ptr_ty_id;1178 return ptr_ty_ref;
1179 }1179 }
11801180
1181 return try self.spv.simpleStructType(&.{1181 return try self.spv.simpleStructType(&.{
1182 .{ .ty = ptr_ty_id, .name = "ptr" },1182 .{ .ty = ptr_ty_ref, .name = "ptr" },
1183 .{ .ty = try self.sizeType(), .name = "len" },1183 .{ .ty = try self.sizeType(), .name = "len" },
1184 });1184 });
1185 },1185 },
...@@ -1356,7 +1356,7 @@ pub const DeclGen = struct {...@@ -1356,7 +1356,7 @@ pub const DeclGen = struct {
1356 /// the name of an error in the text executor.1356 /// the name of an error in the text executor.
1357 fn generateTestEntryPoint(self: *DeclGen, name: []const u8, spv_test_decl_index: SpvModule.Decl.Index) !void {1357 fn generateTestEntryPoint(self: *DeclGen, name: []const u8, spv_test_decl_index: SpvModule.Decl.Index) !void {
1358 const anyerror_ty_ref = try self.resolveType(Type.anyerror, .direct);1358 const anyerror_ty_ref = try self.resolveType(Type.anyerror, .direct);
1359 const ptr_anyerror_ty_ref = try self.spv.ptrType(anyerror_ty_ref, .CrossWorkgroup, null);1359 const ptr_anyerror_ty_ref = try self.spv.ptrType(anyerror_ty_ref, .CrossWorkgroup, 0);
1360 const void_ty_ref = try self.resolveType(Type.void, .direct);1360 const void_ty_ref = try self.resolveType(Type.void, .direct);
13611361
1362 const kernel_proto_ty_ref = blk: {1362 const kernel_proto_ty_ref = blk: {
...@@ -1497,19 +1497,6 @@ pub const DeclGen = struct {...@@ -1497,19 +1497,6 @@ pub const DeclGen = struct {
1497 final_storage_class == .Generic,1497 final_storage_class == .Generic,
1498 decl.@"align",1498 decl.@"align",
1499 );1499 );
1500
1501 // if (storage_class == .Generic) {
1502 // const section = &self.spv.globals.section;
1503 // const ty_ref = try self.resolveType(decl.ty, .indirect);
1504 // const ptr_ty_ref = try self.spv.ptrType(ty_ref, storage_class, decl.@"align");
1505 // // TODO: Can we eliminate this cast?
1506 // // TODO: Const-wash pointer?
1507 // try section.emitSpecConstantOp(self.spv.gpa, .OpPtrCastToGeneric, .{
1508 // .id_result_type = self.typeId(ptr_ty_ref),
1509 // .id_result = global_result_id,
1510 // .pointer = casted_result_id,
1511 // });
1512 // }
1513 }1500 }
1514 }1501 }
15151502
src/codegen/spirv/Assembler.zig+1-4
...@@ -388,10 +388,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {...@@ -388,10 +388,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
388 payload.* = .{388 payload.* = .{
389 .storage_class = @intToEnum(spec.StorageClass, operands[1].value),389 .storage_class = @intToEnum(spec.StorageClass, operands[1].value),
390 .child_type = try self.resolveTypeRef(operands[2].ref_id),390 .child_type = try self.resolveTypeRef(operands[2].ref_id),
391 // TODO: Fetch these values from decorations.391 // TODO: Fetch decorations
392 .array_stride = 0,
393 .alignment = null,
394 .max_byte_offset = null,
395 };392 };
396 break :blk SpvType.initPayload(&payload.base);393 break :blk SpvType.initPayload(&payload.base);
397 },394 },
src/codegen/spirv/Module.zig+3-3
...@@ -573,8 +573,8 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {...@@ -573,8 +573,8 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
573 if (info.array_stride != 0) {573 if (info.array_stride != 0) {
574 try self.decorate(ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });574 try self.decorate(ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
575 }575 }
576 if (info.alignment) |alignment| {576 if (info.alignment != 0) {
577 try self.decorate(ref_id, .{ .Alignment = .{ .alignment = alignment } });577 try self.decorate(ref_id, .{ .Alignment = .{ .alignment = info.alignment } });
578 }578 }
579 if (info.max_byte_offset) |max_byte_offset| {579 if (info.max_byte_offset) |max_byte_offset| {
580 try self.decorate(ref_id, .{ .MaxByteOffset = .{ .max_byte_offset = max_byte_offset } });580 try self.decorate(ref_id, .{ .MaxByteOffset = .{ .max_byte_offset = max_byte_offset } });
...@@ -753,7 +753,7 @@ pub fn ptrType(...@@ -753,7 +753,7 @@ pub fn ptrType(
753 self: *Module,753 self: *Module,
754 child: Type.Ref,754 child: Type.Ref,
755 storage_class: spec.StorageClass,755 storage_class: spec.StorageClass,
756 alignment: ?u32,756 alignment: u32,
757) !Type.Ref {757) !Type.Ref {
758 const ptr_payload = try self.arena.create(Type.Payload.Pointer);758 const ptr_payload = try self.arena.create(Type.Payload.Pointer);
759 ptr_payload.* = .{759 ptr_payload.* = .{
src/codegen/spirv/type.zig+2-2
...@@ -547,8 +547,8 @@ pub const Type = extern union {...@@ -547,8 +547,8 @@ pub const Type = extern union {
547 /// This is valid for pointers to elements of an array.547 /// This is valid for pointers to elements of an array.
548 /// If zero, no stride is present.548 /// If zero, no stride is present.
549 array_stride: u32 = 0,549 array_stride: u32 = 0,
550 /// Type has the 'Alignment' decoration.550 /// If nonzero, type has the 'Alignment' decoration.
551 alignment: ?u32,551 alignment: u32 = 0,
552 /// Type has the 'MaxByteOffset' decoration.552 /// Type has the 'MaxByteOffset' decoration.
553 max_byte_offset: ?u32 = null,553 max_byte_offset: ?u32 = null,
554 };554 };