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 {...@@ -780,21 +780,14 @@ const DeclGen = struct {
780 /// Result is in `direct` representation.780 /// Result is in `direct` representation.
781 fn constructStruct(self: *DeclGen, ty: Type, types: []const Type, constituents: []const IdRef) !IdRef {781 fn constructStruct(self: *DeclGen, ty: Type, types: []const Type, constituents: []const IdRef) !IdRef {
782 assert(types.len == constituents.len);782 assert(types.len == constituents.len);
783 // The Khronos LLVM-SPIRV translator crashes because it cannot construct structs which'783
784 // operands are not constant.784 const result_id = self.spv.allocId();
785 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349785 try self.func.body.emit(self.spv.gpa, .OpCompositeConstruct, .{
786 // For now, just initialize the struct by setting the fields manually...786 .id_result_type = try self.resolveType(ty, .direct),
787 // TODO: Make this OpCompositeConstruct when we can787 .id_result = result_id,
788 const ptr_composite_id = try self.alloc(ty, .{ .storage_class = .Function });788 .constituents = constituents,
789 for (constituents, types, 0..) |constitent_id, member_ty, index| {789 });
790 const ptr_member_ty_id = try self.ptrType(member_ty, .Function);790 return result_id;
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, .{});
798 }791 }
799792
800 /// Construct a vector at runtime.793 /// Construct a vector at runtime.
...@@ -839,23 +832,13 @@ const DeclGen = struct {...@@ -839,23 +832,13 @@ const DeclGen = struct {
839 /// Constituents should be in `indirect` representation (as the elements of an array should be).832 /// Constituents should be in `indirect` representation (as the elements of an array should be).
840 /// Result is in `direct` representation.833 /// Result is in `direct` representation.
841 fn constructArray(self: *DeclGen, ty: Type, constituents: []const IdRef) !IdRef {834 fn constructArray(self: *DeclGen, ty: Type, constituents: []const IdRef) !IdRef {
842 // The Khronos LLVM-SPIRV translator crashes because it cannot construct structs which'835 const result_id = self.spv.allocId();
843 // operands are not constant.836 try self.func.body.emit(self.spv.gpa, .OpCompositeConstruct, .{
844 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349837 .id_result_type = try self.resolveType(ty, .direct),
845 // For now, just initialize the struct by setting the fields manually...838 .id_result = result_id,
846 // TODO: Make this OpCompositeConstruct when we can839 .constituents = constituents,
847 const mod = self.module;840 });
848 const ptr_composite_id = try self.alloc(ty, .{ .storage_class = .Function });841 return result_id;
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, .{});
859 }842 }
860843
861 /// This function generates a load for a constant in direct (ie, non-memory) representation.844 /// This function generates a load for a constant in direct (ie, non-memory) representation.