Skip to content

Commit 4e7159a

Browse files
committed
spirv: remove OpCompositeConstruct workarounds
Now that we use POCL to test, we no longer need this ✨
1 parent 4bd9d9b commit 4e7159a

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/codegen/spirv.zig

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

0 commit comments

Comments
 (0)