authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-12-03 00:13:25+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:52+02:00
logfbe5f0c3459484babcf3d4ba6fe4901612a409bb
tree4e3f1c4b21e50ed3d7b7d0e3f27f4ad6069aee8a
parentc9db6e43af366215cd8bf494ea54ad14e4b97cc0
signaturelock-open Commit is signed but in an unrecognized format.

spirv: initial decl_ref pointer generation

Starts lowering decl_ref Pointer constants.

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

src/codegen/spirv.zig+25-5
......@@ -373,15 +373,16 @@ pub const DeclGen = struct {
373373 const ty = self.spv.typeRefType(ty_ref);
374374 const ty_id = self.typeId(ty_ref);
375375
376 const literal: spec.LiteralContextDependentNumber = switch (ty.intSignedness()) {
376 const Lit = spec.LiteralContextDependentNumber;
377 const literal = switch (ty.intSignedness()) {
377378 .signed => switch (ty.intFloatBits()) {
378 1...32 => .{ .int32 = @intCast(i32, value) },
379 33...64 => .{ .int64 = @intCast(i64, value) },
379 1...32 => Lit{ .int32 = @intCast(i32, value) },
380 33...64 => Lit{ .int64 = @intCast(i64, value) },
380381 else => unreachable, // TODO: composite integer literals
381382 },
382383 .unsigned => switch (ty.intFloatBits()) {
383 1...32 => .{ .uint32 = @intCast(u32, value) },
384 33...64 => .{ .uint64 = @intCast(u64, value) },
384 1...32 => Lit{ .uint32 = @intCast(u32, value) },
385 33...64 => Lit{ .uint64 = @intCast(u64, value) },
385386 else => unreachable,
386387 },
387388 };
......@@ -552,6 +553,19 @@ pub const DeclGen = struct {
552553 .constituents = constituents,
553554 });
554555 },
556 .Pointer => switch (val.tag()) {
557 .decl_ref => {
558 const decl_index = val.castTag(.decl_ref).?.data;
559 const decl_result_id = self.spv.allocId();
560 try self.genDeclRef(decl_result_id, decl_index);
561 try section.emit(self.spv.gpa, .OpVariable, .{
562 .id_result_type = result_ty_id,
563 .id_result = result_id,
564 .storage_class = spirvStorageClass(ty.ptrAddressSpace()),
565 });
566 },
567 else => return self.todo("constant pointer of value type {s}", .{@tagName(val.tag())}),
568 },
555569 .Fn => switch (repr) {
556570 .direct => unreachable,
557571 .indirect => return self.todo("function pointers", .{}),
......@@ -561,6 +575,12 @@ pub const DeclGen = struct {
561575 }
562576 }
563577
578 fn genDeclRef(self: *DeclGen, result_id: IdRef, decl_index: Decl.Index) Error!void {
579 const decl = self.module.declPtr(decl_index);
580 self.module.markDeclAlive(decl);
581 try self.genConstant(result_id, decl.ty, decl.val, .indirect);
582 }
583
564584 /// Turn a Zig type into a SPIR-V Type, and return its type result-id.
565585 fn resolveTypeId(self: *DeclGen, ty: Type) !IdResultType {
566586 const type_ref = try self.resolveType(ty, .direct);