authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-17 03:39:22+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:36:44-07:00
log42226fc1b77ba042e72fcdfb1f3c1973650a7cc3
tree397b535d031c38589c7b5c50927ea5961044d6a8
parent06d9e3b2eb7a5c44edfce672b61feb2efc7234a6

spirv: make construct(Struct|Array) use the Function storage class


1 files changed, 18 insertions(+), 5 deletions(-)

src/codegen/spirv.zig+18-5
...@@ -444,8 +444,14 @@ pub const DeclGen = struct {...@@ -444,8 +444,14 @@ pub const DeclGen = struct {
444 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349444 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/1349
445 // For now, just initialize the struct by setting the fields manually...445 // For now, just initialize the struct by setting the fields manually...
446 // TODO: Make this OpCompositeConstruct when we can446 // TODO: Make this OpCompositeConstruct when we can
447 // TODO: Make this Function storage type447 const ptr_ty_ref = try self.spv.ptrType(result_ty_ref, .Function);
448 const ptr_composite_id = try self.alloc(result_ty_ref, null);448 const ptr_composite_id = self.spv.allocId();
449 try self.func.prologue.emit(self.spv.gpa, .OpVariable, .{
450 .id_result_type = self.typeId(ptr_ty_ref),
451 .id_result = ptr_composite_id,
452 .storage_class = .Function,
453 });
454
449 // Note: using 32-bit ints here because usize crashes the translator as well455 // Note: using 32-bit ints here because usize crashes the translator as well
450 const index_ty_ref = try self.intType(.unsigned, 32);456 const index_ty_ref = try self.intType(.unsigned, 32);
451457
...@@ -454,7 +460,7 @@ pub const DeclGen = struct {...@@ -454,7 +460,7 @@ pub const DeclGen = struct {
454460
455 for (constituents, member_types, 0..) |constitent_id, member_ty_ref, index| {461 for (constituents, member_types, 0..) |constitent_id, member_ty_ref, index| {
456 const index_id = try self.constInt(index_ty_ref, index);462 const index_id = try self.constInt(index_ty_ref, index);
457 const ptr_member_ty_ref = try self.spv.ptrType(member_ty_ref, .Generic);463 const ptr_member_ty_ref = try self.spv.ptrType(member_ty_ref, .Function);
458 const ptr_id = try self.accessChain(ptr_member_ty_ref, ptr_composite_id, &.{index_id});464 const ptr_id = try self.accessChain(ptr_member_ty_ref, ptr_composite_id, &.{index_id});
459 try self.func.body.emit(self.spv.gpa, .OpStore, .{465 try self.func.body.emit(self.spv.gpa, .OpStore, .{
460 .pointer = ptr_id,466 .pointer = ptr_id,
...@@ -479,13 +485,20 @@ pub const DeclGen = struct {...@@ -479,13 +485,20 @@ pub const DeclGen = struct {
479 // For now, just initialize the struct by setting the fields manually...485 // For now, just initialize the struct by setting the fields manually...
480 // TODO: Make this OpCompositeConstruct when we can486 // TODO: Make this OpCompositeConstruct when we can
481 // TODO: Make this Function storage type487 // TODO: Make this Function storage type
482 const ptr_composite_id = try self.alloc(result_ty_ref, null);488 const ptr_ty_ref = try self.spv.ptrType(result_ty_ref, .Function);
489 const ptr_composite_id = self.spv.allocId();
490 try self.func.prologue.emit(self.spv.gpa, .OpVariable, .{
491 .id_result_type = self.typeId(ptr_ty_ref),
492 .id_result = ptr_composite_id,
493 .storage_class = .Function,
494 });
495
483 // Note: using 32-bit ints here because usize crashes the translator as well496 // Note: using 32-bit ints here because usize crashes the translator as well
484 const index_ty_ref = try self.intType(.unsigned, 32);497 const index_ty_ref = try self.intType(.unsigned, 32);
485498
486 const spv_composite_ty = self.spv.cache.lookup(result_ty_ref).array_type;499 const spv_composite_ty = self.spv.cache.lookup(result_ty_ref).array_type;
487 const elem_ty_ref = spv_composite_ty.element_type;500 const elem_ty_ref = spv_composite_ty.element_type;
488 const ptr_elem_ty_ref = try self.spv.ptrType(elem_ty_ref, .Generic);501 const ptr_elem_ty_ref = try self.spv.ptrType(elem_ty_ref, .Function);
489502
490 for (constituents, 0..) |constitent_id, index| {503 for (constituents, 0..) |constitent_id, index| {
491 const index_id = try self.constInt(index_ty_ref, index);504 const index_id = try self.constInt(index_ty_ref, index);