| ... | @@ -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/1349 | 444 | // 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 can | 446 | // TODO: Make this OpCompositeConstruct when we can |
| 447 | // TODO: Make this Function storage type | 447 | 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 well | 455 | // 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); |
| 451 | | 457 | |
| ... | @@ -454,7 +460,7 @@ pub const DeclGen = struct { | ... | @@ -454,7 +460,7 @@ pub const DeclGen = struct { |
| 454 | | 460 | |
| 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 can | 486 | // TODO: Make this OpCompositeConstruct when we can |
| 481 | // TODO: Make this Function storage type | 487 | // 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 well | 496 | // 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); |
| 485 | | 498 | |
| 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); |
| 489 | | 502 | |
| 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); |