authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-06-02 16:09:20+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-06-10 20:32:43+02:00
log4e7159ae1d08ce74548e0adc3b3936aacc23a06e
treec823195dcfbee3ce2ce1b205bff888f834c1fb4a
parent4bd9d9b7e0d769dd8d7701b73e54ae249ac7f1da
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: remove OpCompositeConstruct workarounds

Now that we use POCL to test, we no longer need this ✨

1 files changed, 15 insertions(+), 32 deletions(-)

src/codegen/spirv.zig+15-32
......@@ -780,21 +780,14 @@ const DeclGen = struct {
780780 /// Result is in `direct` representation.
781781 fn constructStruct(self: *DeclGen, ty: Type, types: []const Type, constituents: []const IdRef) !IdRef {
782782 assert(types.len == constituents.len);
783 // The Khronos LLVM-SPIRV translator crashes because it cannot construct structs which'
784 // operands are not constant.
785 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349
786 // For now, just initialize the struct by setting the fields manually...
787 // TODO: Make this OpCompositeConstruct when we can
788 const ptr_composite_id = try self.alloc(ty, .{ .storage_class = .Function });
789 for (constituents, types, 0..) |constitent_id, member_ty, index| {
790 const ptr_member_ty_id = try self.ptrType(member_ty, .Function);
791 const ptr_id = try self.accessChain(ptr_member_ty_id, ptr_composite_id, &.{@as(u32, @intCast(index))});
792 try self.func.body.emit(self.spv.gpa, .OpStore, .{
793 .pointer = ptr_id,
794 .object = constitent_id,
795 });
796 }
797 return try self.load(ty, ptr_composite_id, .{});
783
784 const result_id = self.spv.allocId();
785 try self.func.body.emit(self.spv.gpa, .OpCompositeConstruct, .{
786 .id_result_type = try self.resolveType(ty, .direct),
787 .id_result = result_id,
788 .constituents = constituents,
789 });
790 return result_id;
798791 }
799792
800793 /// Construct a vector at runtime.
......@@ -839,23 +832,13 @@ const DeclGen = struct {
839832 /// Constituents should be in `indirect` representation (as the elements of an array should be).
840833 /// Result is in `direct` representation.
841834 fn constructArray(self: *DeclGen, ty: Type, constituents: []const IdRef) !IdRef {
842 // The Khronos LLVM-SPIRV translator crashes because it cannot construct structs which'
843 // operands are not constant.
844 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349
845 // For now, just initialize the struct by setting the fields manually...
846 // TODO: Make this OpCompositeConstruct when we can
847 const mod = self.module;
848 const ptr_composite_id = try self.alloc(ty, .{ .storage_class = .Function });
849 const ptr_elem_ty_id = try self.ptrType(ty.elemType2(mod), .Function);
850 for (constituents, 0..) |constitent_id, index| {
851 const ptr_id = try self.accessChain(ptr_elem_ty_id, ptr_composite_id, &.{@as(u32, @intCast(index))});
852 try self.func.body.emit(self.spv.gpa, .OpStore, .{
853 .pointer = ptr_id,
854 .object = constitent_id,
855 });
856 }
857
858 return try self.load(ty, ptr_composite_id, .{});
835 const result_id = self.spv.allocId();
836 try self.func.body.emit(self.spv.gpa, .OpCompositeConstruct, .{
837 .id_result_type = try self.resolveType(ty, .direct),
838 .id_result = result_id,
839 .constituents = constituents,
840 });
841 return result_id;
859842 }
860843
861844 /// This function generates a load for a constant in direct (ie, non-memory) representation.