mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
spirv: make IdResultType and IdRef weak aliases of IdResult
Previously they were strong aliases, but as these types are used quite intermittendly it resulted in a lot of toRef() calls. Removing them improves readability a bit.
This commit is contained in:
parent
0c2526b18e
commit
700dee34d5
6 changed files with 73 additions and 95 deletions
|
|
@ -227,7 +227,7 @@ pub const DeclGen = struct {
|
||||||
/// keep track of the previous block.
|
/// keep track of the previous block.
|
||||||
fn beginSpvBlock(self: *DeclGen, label_id: IdResult) !void {
|
fn beginSpvBlock(self: *DeclGen, label_id: IdResult) !void {
|
||||||
try self.func.body.emit(self.spv.gpa, .OpLabel, .{ .id_result = label_id });
|
try self.func.body.emit(self.spv.gpa, .OpLabel, .{ .id_result = label_id });
|
||||||
self.current_block_label_id = label_id.toRef();
|
self.current_block_label_id = label_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SPIR-V requires enabling specific integer sizes through capabilities, and so if they are not enabled, we need
|
/// SPIR-V requires enabling specific integer sizes through capabilities, and so if they are not enabled, we need
|
||||||
|
|
@ -340,7 +340,7 @@ pub const DeclGen = struct {
|
||||||
};
|
};
|
||||||
const decl = self.module.declPtr(fn_decl_index);
|
const decl = self.module.declPtr(fn_decl_index);
|
||||||
self.module.markDeclAlive(decl);
|
self.module.markDeclAlive(decl);
|
||||||
return self.ids.get(fn_decl_index).?.toRef();
|
return self.ids.get(fn_decl_index).?;
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = self.getTarget();
|
const target = self.getTarget();
|
||||||
|
|
@ -350,7 +350,7 @@ pub const DeclGen = struct {
|
||||||
|
|
||||||
if (val.isUndef()) {
|
if (val.isUndef()) {
|
||||||
try section.emit(self.spv.gpa, .OpUndef, .{ .id_result_type = result_type_id, .id_result = result_id });
|
try section.emit(self.spv.gpa, .OpUndef, .{ .id_result_type = result_type_id, .id_result = result_id });
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ty.zigTypeTag()) {
|
switch (ty.zigTypeTag()) {
|
||||||
|
|
@ -538,7 +538,7 @@ pub const DeclGen = struct {
|
||||||
else => return self.todo("constant generation of type {s}: {}", .{ @tagName(ty.zigTypeTag()), ty.fmtDebug() }),
|
else => return self.todo("constant generation of type {s}: {}", .{ @tagName(ty.zigTypeTag()), ty.fmtDebug() }),
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn a Zig type into a SPIR-V Type, and return its type result-id.
|
/// Turn a Zig type into a SPIR-V Type, and return its type result-id.
|
||||||
|
|
@ -766,7 +766,7 @@ pub const DeclGen = struct {
|
||||||
.id_result_type = try self.resolveTypeId(decl.ty.fnReturnType()),
|
.id_result_type = try self.resolveTypeId(decl.ty.fnReturnType()),
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.function_control = .{}, // TODO: We can set inline here if the type requires it.
|
.function_control = .{}, // TODO: We can set inline here if the type requires it.
|
||||||
.function_type = prototype_id.toRef(),
|
.function_type = prototype_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const params = decl.ty.fnParamLen();
|
const params = decl.ty.fnParamLen();
|
||||||
|
|
@ -780,7 +780,7 @@ pub const DeclGen = struct {
|
||||||
.id_result_type = param_type_id,
|
.id_result_type = param_type_id,
|
||||||
.id_result = arg_result_id,
|
.id_result = arg_result_id,
|
||||||
});
|
});
|
||||||
self.args.appendAssumeCapacity(arg_result_id.toRef());
|
self.args.appendAssumeCapacity(arg_result_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This could probably be done in a better way...
|
// TODO: This could probably be done in a better way...
|
||||||
|
|
@ -791,7 +791,7 @@ pub const DeclGen = struct {
|
||||||
try self.func.prologue.emit(self.spv.gpa, .OpLabel, .{
|
try self.func.prologue.emit(self.spv.gpa, .OpLabel, .{
|
||||||
.id_result = root_block_id,
|
.id_result = root_block_id,
|
||||||
});
|
});
|
||||||
self.current_block_label_id = root_block_id.toRef();
|
self.current_block_label_id = root_block_id;
|
||||||
|
|
||||||
const main_body = self.air.getMainBody();
|
const main_body = self.air.getMainBody();
|
||||||
try self.genBody(main_body);
|
try self.genBody(main_body);
|
||||||
|
|
@ -804,7 +804,7 @@ pub const DeclGen = struct {
|
||||||
defer self.module.gpa.free(fqn);
|
defer self.module.gpa.free(fqn);
|
||||||
|
|
||||||
try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
|
try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
|
||||||
.target = result_id.toRef(),
|
.target = result_id,
|
||||||
.name = fqn,
|
.name = fqn,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -928,7 +928,7 @@ pub const DeclGen = struct {
|
||||||
.operand_1 = lhs_id,
|
.operand_1 = lhs_id,
|
||||||
.operand_2 = rhs_id,
|
.operand_2 = rhs_id,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
|
fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
|
||||||
|
|
@ -951,9 +951,9 @@ pub const DeclGen = struct {
|
||||||
.id_result_type = result_type_id,
|
.id_result_type = result_type_id,
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.base = lhs_id,
|
.base = lhs_id,
|
||||||
.shift = shift_id.toRef(),
|
.shift = shift_id,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maskStrangeInt(self: *DeclGen, ty_id: IdResultType, int_id: IdRef, bits: u16) !IdRef {
|
fn maskStrangeInt(self: *DeclGen, ty_id: IdResultType, int_id: IdRef, bits: u16) !IdRef {
|
||||||
|
|
@ -976,9 +976,9 @@ pub const DeclGen = struct {
|
||||||
.id_result_type = ty_id,
|
.id_result_type = ty_id,
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.operand_1 = int_id,
|
.operand_1 = int_id,
|
||||||
.operand_2 = mask_id.toRef(),
|
.operand_2 = mask_id,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airArithOp(
|
fn airArithOp(
|
||||||
|
|
@ -1046,7 +1046,7 @@ pub const DeclGen = struct {
|
||||||
// TODO: Trap on overflow? Probably going to be annoying.
|
// TODO: Trap on overflow? Probably going to be annoying.
|
||||||
// TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.
|
// TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airOverflowArithOp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airOverflowArithOp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1089,7 +1089,7 @@ pub const DeclGen = struct {
|
||||||
.operand_1 = lhs,
|
.operand_1 = lhs,
|
||||||
.operand_2 = rhs,
|
.operand_2 = rhs,
|
||||||
});
|
});
|
||||||
break :blk result_id.toRef();
|
break :blk result_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Now convert the SPIR-V flavor result into a Zig-flavor result.
|
// Now convert the SPIR-V flavor result into a Zig-flavor result.
|
||||||
|
|
@ -1111,7 +1111,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.unsigned_value = overflow,
|
.unsigned_value = overflow,
|
||||||
});
|
});
|
||||||
break :blk result_id.toRef();
|
break :blk result_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: If copying this function for borrow, make sure to convert -1 to 1 as appropriate.
|
// TODO: If copying this function for borrow, make sure to convert -1 to 1 as appropriate.
|
||||||
|
|
@ -1127,7 +1127,7 @@ pub const DeclGen = struct {
|
||||||
casted_overflow,
|
casted_overflow,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1163,7 +1163,7 @@ pub const DeclGen = struct {
|
||||||
self.func.body.writeOperand(spec.LiteralInteger, unsigned);
|
self.func.body.writeOperand(spec.LiteralInteger, unsigned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airCmp(self: *DeclGen, inst: Air.Inst.Index, comptime fop: Opcode, comptime sop: Opcode, comptime uop: Opcode) !?IdRef {
|
fn airCmp(self: *DeclGen, inst: Air.Inst.Index, comptime fop: Opcode, comptime sop: Opcode, comptime uop: Opcode) !?IdRef {
|
||||||
|
|
@ -1215,7 +1215,7 @@ pub const DeclGen = struct {
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bitcast(self: *DeclGen, target_type_id: IdResultType, value_id: IdRef) !IdRef {
|
fn bitcast(self: *DeclGen, target_type_id: IdResultType, value_id: IdRef) !IdRef {
|
||||||
|
|
@ -1225,7 +1225,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.operand = value_id,
|
.operand = value_id,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airBitcast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airBitcast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1258,7 +1258,7 @@ pub const DeclGen = struct {
|
||||||
.unsigned_value = operand_id,
|
.unsigned_value = operand_id,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1272,7 +1272,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.operand = operand_id,
|
.operand = operand_id,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extractField(self: *DeclGen, result_ty: IdResultType, object: IdRef, field: u32) !IdRef {
|
fn extractField(self: *DeclGen, result_ty: IdResultType, object: IdRef, field: u32) !IdRef {
|
||||||
|
|
@ -1283,7 +1283,7 @@ pub const DeclGen = struct {
|
||||||
.composite = object,
|
.composite = object,
|
||||||
.indexes = &.{field},
|
.indexes = &.{field},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
|
fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
|
||||||
|
|
@ -1314,7 +1314,7 @@ pub const DeclGen = struct {
|
||||||
.composite = slice,
|
.composite = slice,
|
||||||
.indexes = &.{0},
|
.indexes = &.{0},
|
||||||
});
|
});
|
||||||
break :blk result_id.toRef();
|
break :blk result_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const result_id = self.spv.allocId();
|
const result_id = self.spv.allocId();
|
||||||
|
|
@ -1324,7 +1324,7 @@ pub const DeclGen = struct {
|
||||||
.base = slice_ptr,
|
.base = slice_ptr,
|
||||||
.indexes = &.{index},
|
.indexes = &.{index},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1347,7 +1347,7 @@ pub const DeclGen = struct {
|
||||||
.composite = slice,
|
.composite = slice,
|
||||||
.indexes = &.{0},
|
.indexes = &.{0},
|
||||||
});
|
});
|
||||||
break :blk result_id.toRef();
|
break :blk result_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const elem_ptr = blk: {
|
const elem_ptr = blk: {
|
||||||
|
|
@ -1358,7 +1358,7 @@ pub const DeclGen = struct {
|
||||||
.base = slice_ptr,
|
.base = slice_ptr,
|
||||||
.indexes = &.{index},
|
.indexes = &.{index},
|
||||||
});
|
});
|
||||||
break :blk result_id.toRef();
|
break :blk result_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const result_id = self.spv.allocId();
|
const result_id = self.spv.allocId();
|
||||||
|
|
@ -1367,7 +1367,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.pointer = elem_ptr,
|
.pointer = elem_ptr,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1392,7 +1392,7 @@ pub const DeclGen = struct {
|
||||||
.base = base_ptr,
|
.base = base_ptr,
|
||||||
.indexes = &.{rhs},
|
.indexes = &.{rhs},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
|
||||||
|
|
@ -1418,7 +1418,7 @@ pub const DeclGen = struct {
|
||||||
.composite = object,
|
.composite = object,
|
||||||
.indexes = &.{field_index},
|
.indexes = &.{field_index},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn structFieldPtr(
|
fn structFieldPtr(
|
||||||
|
|
@ -1446,9 +1446,9 @@ pub const DeclGen = struct {
|
||||||
.id_result_type = result_type_id,
|
.id_result_type = result_type_id,
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.base = object_ptr,
|
.base = object_ptr,
|
||||||
.indexes = &.{field_index_id.toRef()},
|
.indexes = &.{field_index_id},
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
else => unreachable, // TODO
|
else => unreachable, // TODO
|
||||||
|
|
@ -1483,7 +1483,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.storage_class = storage_class,
|
.storage_class = storage_class,
|
||||||
});
|
});
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airArg(self: *DeclGen) IdRef {
|
fn airArg(self: *DeclGen) IdRef {
|
||||||
|
|
@ -1503,7 +1503,7 @@ pub const DeclGen = struct {
|
||||||
var incoming_blocks = try std.ArrayListUnmanaged(IncomingBlock).initCapacity(self.gpa, 4);
|
var incoming_blocks = try std.ArrayListUnmanaged(IncomingBlock).initCapacity(self.gpa, 4);
|
||||||
|
|
||||||
try self.blocks.putNoClobber(self.gpa, inst, .{
|
try self.blocks.putNoClobber(self.gpa, inst, .{
|
||||||
.label_id = label_id.toRef(),
|
.label_id = label_id,
|
||||||
.incoming_blocks = &incoming_blocks,
|
.incoming_blocks = &incoming_blocks,
|
||||||
});
|
});
|
||||||
defer {
|
defer {
|
||||||
|
|
@ -1538,7 +1538,7 @@ pub const DeclGen = struct {
|
||||||
self.func.body.writeOperand(spec.PairIdRefIdRef, .{ incoming.break_value_id, incoming.src_label_id });
|
self.func.body.writeOperand(spec.PairIdRefIdRef, .{ incoming.break_value_id, incoming.src_label_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
|
fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
|
||||||
|
|
@ -1571,8 +1571,8 @@ pub const DeclGen = struct {
|
||||||
|
|
||||||
try self.func.body.emit(self.spv.gpa, .OpBranchConditional, .{
|
try self.func.body.emit(self.spv.gpa, .OpBranchConditional, .{
|
||||||
.condition = condition_id,
|
.condition = condition_id,
|
||||||
.true_label = then_label_id.toRef(),
|
.true_label = then_label_id,
|
||||||
.false_label = else_label_id.toRef(),
|
.false_label = else_label_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
try self.beginSpvBlock(then_label_id);
|
try self.beginSpvBlock(then_label_id);
|
||||||
|
|
@ -1610,7 +1610,7 @@ pub const DeclGen = struct {
|
||||||
.memory_access = access,
|
.memory_access = access,
|
||||||
});
|
});
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
|
fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
|
||||||
|
|
@ -1620,13 +1620,13 @@ pub const DeclGen = struct {
|
||||||
const loop_label_id = self.spv.allocId();
|
const loop_label_id = self.spv.allocId();
|
||||||
|
|
||||||
// Jump to the loop entry point
|
// Jump to the loop entry point
|
||||||
try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id.toRef() });
|
try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id });
|
||||||
|
|
||||||
// TODO: Look into OpLoopMerge.
|
// TODO: Look into OpLoopMerge.
|
||||||
try self.beginSpvBlock(loop_label_id);
|
try self.beginSpvBlock(loop_label_id);
|
||||||
try self.genBody(body);
|
try self.genBody(body);
|
||||||
|
|
||||||
try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id.toRef() });
|
try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {
|
fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {
|
||||||
|
|
@ -1658,7 +1658,7 @@ pub const DeclGen = struct {
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.pointer = ptr,
|
.pointer = ptr,
|
||||||
});
|
});
|
||||||
try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = result_id.toRef() });
|
try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = result_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
|
fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
|
||||||
|
|
@ -1730,7 +1730,7 @@ pub const DeclGen = struct {
|
||||||
// Emit the instruction before generating the blocks.
|
// Emit the instruction before generating the blocks.
|
||||||
try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
|
try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
|
||||||
self.func.body.writeOperand(IdRef, cond);
|
self.func.body.writeOperand(IdRef, cond);
|
||||||
self.func.body.writeOperand(IdRef, default.toRef());
|
self.func.body.writeOperand(IdRef, default);
|
||||||
|
|
||||||
// Emit each of the cases
|
// Emit each of the cases
|
||||||
{
|
{
|
||||||
|
|
@ -1965,6 +1965,6 @@ pub const DeclGen = struct {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_id.toRef();
|
return result_id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ const AsmValue = union(enum) {
|
||||||
return switch (self) {
|
return switch (self) {
|
||||||
.just_declared, .unresolved_forward_reference => unreachable,
|
.just_declared, .unresolved_forward_reference => unreachable,
|
||||||
.value => |result| result,
|
.value => |result| result,
|
||||||
.ty => |ref| spv.typeResultId(ref).toRef(),
|
.ty => |ref| spv.typeResultId(ref),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -486,7 +486,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
|
||||||
section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @enumToInt(self.inst.opcode);
|
section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @enumToInt(self.inst.opcode);
|
||||||
|
|
||||||
if (maybe_result_id) |result| {
|
if (maybe_result_id) |result| {
|
||||||
return AsmValue{ .value = result.toRef() };
|
return AsmValue{ .value = result };
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef {
|
||||||
const result = try self.source_file_names.getOrPut(self.gpa, path);
|
const result = try self.source_file_names.getOrPut(self.gpa, path);
|
||||||
if (!result.found_existing) {
|
if (!result.found_existing) {
|
||||||
const file_result_id = self.allocId();
|
const file_result_id = self.allocId();
|
||||||
result.value_ptr.* = file_result_id.toRef();
|
result.value_ptr.* = file_result_id;
|
||||||
try self.sections.debug_strings.emit(self.gpa, .OpString, .{
|
try self.sections.debug_strings.emit(self.gpa, .OpString, .{
|
||||||
.id_result = file_result_id,
|
.id_result = file_result_id,
|
||||||
.string = path,
|
.string = path,
|
||||||
|
|
@ -205,7 +205,7 @@ pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef {
|
||||||
try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
|
try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
|
||||||
.source_language = .Unknown, // TODO: Register Zig source language.
|
.source_language = .Unknown, // TODO: Register Zig source language.
|
||||||
.version = 0, // TODO: Zig version as u32?
|
.version = 0, // TODO: Zig version as u32?
|
||||||
.file = file_result_id.toRef(),
|
.file = file_result_id,
|
||||||
.source = null, // TODO: Store actual source also?
|
.source = null, // TODO: Store actual source also?
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +239,7 @@ pub fn typeResultId(self: Module, type_ref: Type.Ref) IdResultType {
|
||||||
|
|
||||||
/// Get the result-id of a particular type as IdRef, by Type.Ref. Asserts type_ref is valid.
|
/// Get the result-id of a particular type as IdRef, by Type.Ref. Asserts type_ref is valid.
|
||||||
pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
|
pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
|
||||||
return self.type_cache.values()[@enumToInt(type_ref)].toRef();
|
return self.type_cache.values()[@enumToInt(type_ref)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unconditionally emit a spir-v type into the appropriate section.
|
/// Unconditionally emit a spir-v type into the appropriate section.
|
||||||
|
|
@ -250,7 +250,7 @@ pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
|
||||||
/// be emitted at this point.
|
/// be emitted at this point.
|
||||||
pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
const result_id = self.allocId();
|
const result_id = self.allocId();
|
||||||
const ref_id = result_id.toRef();
|
const ref_id = result_id;
|
||||||
const types = &self.sections.types_globals_constants;
|
const types = &self.sections.types_globals_constants;
|
||||||
const debug_names = &self.sections.debug_names;
|
const debug_names = &self.sections.debug_names;
|
||||||
const annotations = &self.sections.annotations;
|
const annotations = &self.sections.annotations;
|
||||||
|
|
@ -260,14 +260,14 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
.void => {
|
.void => {
|
||||||
try types.emit(self.gpa, .OpTypeVoid, result_id_operand);
|
try types.emit(self.gpa, .OpTypeVoid, result_id_operand);
|
||||||
try debug_names.emit(self.gpa, .OpName, .{
|
try debug_names.emit(self.gpa, .OpName, .{
|
||||||
.target = result_id.toRef(),
|
.target = result_id,
|
||||||
.name = "void",
|
.name = "void",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
.bool => {
|
.bool => {
|
||||||
try types.emit(self.gpa, .OpTypeBool, result_id_operand);
|
try types.emit(self.gpa, .OpTypeBool, result_id_operand);
|
||||||
try debug_names.emit(self.gpa, .OpName, .{
|
try debug_names.emit(self.gpa, .OpName, .{
|
||||||
.target = result_id.toRef(),
|
.target = result_id,
|
||||||
.name = "bool",
|
.name = "bool",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -302,7 +302,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
defer self.gpa.free(name);
|
defer self.gpa.free(name);
|
||||||
|
|
||||||
try debug_names.emit(self.gpa, .OpName, .{
|
try debug_names.emit(self.gpa, .OpName, .{
|
||||||
.target = result_id.toRef(),
|
.target = result_id,
|
||||||
.name = name,
|
.name = name,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -316,25 +316,25 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
const name = try std.fmt.allocPrint(self.gpa, "f{}", .{bits});
|
const name = try std.fmt.allocPrint(self.gpa, "f{}", .{bits});
|
||||||
defer self.gpa.free(name);
|
defer self.gpa.free(name);
|
||||||
try debug_names.emit(self.gpa, .OpName, .{
|
try debug_names.emit(self.gpa, .OpName, .{
|
||||||
.target = result_id.toRef(),
|
.target = result_id,
|
||||||
.name = name,
|
.name = name,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
.vector => try types.emit(self.gpa, .OpTypeVector, .{
|
.vector => try types.emit(self.gpa, .OpTypeVector, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.component_type = self.typeResultId(ty.childType()).toRef(),
|
.component_type = self.typeResultId(ty.childType()),
|
||||||
.component_count = ty.payload(.vector).component_count,
|
.component_count = ty.payload(.vector).component_count,
|
||||||
}),
|
}),
|
||||||
.matrix => try types.emit(self.gpa, .OpTypeMatrix, .{
|
.matrix => try types.emit(self.gpa, .OpTypeMatrix, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.column_type = self.typeResultId(ty.childType()).toRef(),
|
.column_type = self.typeResultId(ty.childType()),
|
||||||
.column_count = ty.payload(.matrix).column_count,
|
.column_count = ty.payload(.matrix).column_count,
|
||||||
}),
|
}),
|
||||||
.image => {
|
.image => {
|
||||||
const info = ty.payload(.image);
|
const info = ty.payload(.image);
|
||||||
try types.emit(self.gpa, .OpTypeImage, .{
|
try types.emit(self.gpa, .OpTypeImage, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.sampled_type = self.typeResultId(ty.childType()).toRef(),
|
.sampled_type = self.typeResultId(ty.childType()),
|
||||||
.dim = info.dim,
|
.dim = info.dim,
|
||||||
.depth = @enumToInt(info.depth),
|
.depth = @enumToInt(info.depth),
|
||||||
.arrayed = @boolToInt(info.arrayed),
|
.arrayed = @boolToInt(info.arrayed),
|
||||||
|
|
@ -347,7 +347,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
.sampler => try types.emit(self.gpa, .OpTypeSampler, result_id_operand),
|
.sampler => try types.emit(self.gpa, .OpTypeSampler, result_id_operand),
|
||||||
.sampled_image => try types.emit(self.gpa, .OpTypeSampledImage, .{
|
.sampled_image => try types.emit(self.gpa, .OpTypeSampledImage, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.image_type = self.typeResultId(ty.childType()).toRef(),
|
.image_type = self.typeResultId(ty.childType()),
|
||||||
}),
|
}),
|
||||||
.array => {
|
.array => {
|
||||||
const info = ty.payload(.array);
|
const info = ty.payload(.array);
|
||||||
|
|
@ -365,8 +365,8 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
|
|
||||||
try types.emit(self.gpa, .OpTypeArray, .{
|
try types.emit(self.gpa, .OpTypeArray, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.element_type = self.typeResultId(ty.childType()).toRef(),
|
.element_type = self.typeResultId(ty.childType()),
|
||||||
.length = length_id.toRef(),
|
.length = length_id,
|
||||||
});
|
});
|
||||||
if (info.array_stride != 0) {
|
if (info.array_stride != 0) {
|
||||||
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
||||||
|
|
@ -376,7 +376,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
const info = ty.payload(.runtime_array);
|
const info = ty.payload(.runtime_array);
|
||||||
try types.emit(self.gpa, .OpTypeRuntimeArray, .{
|
try types.emit(self.gpa, .OpTypeRuntimeArray, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.element_type = self.typeResultId(ty.childType()).toRef(),
|
.element_type = self.typeResultId(ty.childType()),
|
||||||
});
|
});
|
||||||
if (info.array_stride != 0) {
|
if (info.array_stride != 0) {
|
||||||
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
||||||
|
|
@ -387,7 +387,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
try types.emitRaw(self.gpa, .OpTypeStruct, 1 + info.members.len);
|
try types.emitRaw(self.gpa, .OpTypeStruct, 1 + info.members.len);
|
||||||
types.writeOperand(IdResult, result_id);
|
types.writeOperand(IdResult, result_id);
|
||||||
for (info.members) |member| {
|
for (info.members) |member| {
|
||||||
types.writeOperand(IdRef, self.typeResultId(member.ty).toRef());
|
types.writeOperand(IdRef, self.typeResultId(member.ty));
|
||||||
}
|
}
|
||||||
try self.decorateStruct(ref_id, info);
|
try self.decorateStruct(ref_id, info);
|
||||||
},
|
},
|
||||||
|
|
@ -400,7 +400,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
try types.emit(self.gpa, .OpTypePointer, .{
|
try types.emit(self.gpa, .OpTypePointer, .{
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
.storage_class = info.storage_class,
|
.storage_class = info.storage_class,
|
||||||
.type = self.typeResultId(ty.childType()).toRef(),
|
.type = self.typeResultId(ty.childType()),
|
||||||
});
|
});
|
||||||
if (info.array_stride != 0) {
|
if (info.array_stride != 0) {
|
||||||
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
|
||||||
|
|
@ -416,9 +416,9 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
const info = ty.payload(.function);
|
const info = ty.payload(.function);
|
||||||
try types.emitRaw(self.gpa, .OpTypeFunction, 2 + info.parameters.len);
|
try types.emitRaw(self.gpa, .OpTypeFunction, 2 + info.parameters.len);
|
||||||
types.writeOperand(IdResult, result_id);
|
types.writeOperand(IdResult, result_id);
|
||||||
types.writeOperand(IdRef, self.typeResultId(info.return_type).toRef());
|
types.writeOperand(IdRef, self.typeResultId(info.return_type));
|
||||||
for (info.parameters) |parameter_type| {
|
for (info.parameters) |parameter_type| {
|
||||||
types.writeOperand(IdRef, self.typeResultId(parameter_type).toRef());
|
types.writeOperand(IdRef, self.typeResultId(parameter_type));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.event => try types.emit(self.gpa, .OpTypeEvent, result_id_operand),
|
.event => try types.emit(self.gpa, .OpTypeEvent, result_id_operand),
|
||||||
|
|
@ -433,7 +433,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
|
||||||
.named_barrier => try types.emit(self.gpa, .OpTypeNamedBarrier, result_id_operand),
|
.named_barrier => try types.emit(self.gpa, .OpTypeNamedBarrier, result_id_operand),
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_id.toResultType();
|
return result_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct) !void {
|
fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct) !void {
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ fn writeOperands(section: *Section, comptime Operands: type, operands: Operands)
|
||||||
|
|
||||||
pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand) void {
|
pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand) void {
|
||||||
switch (Operand) {
|
switch (Operand) {
|
||||||
spec.IdResultType, spec.IdResult, spec.IdRef => section.writeWord(operand.id),
|
spec.IdResult => section.writeWord(operand.id),
|
||||||
|
|
||||||
spec.LiteralInteger => section.writeWord(operand),
|
spec.LiteralInteger => section.writeWord(operand),
|
||||||
|
|
||||||
|
|
@ -258,9 +258,7 @@ fn operandsSize(comptime Operands: type, operands: Operands) usize {
|
||||||
|
|
||||||
fn operandSize(comptime Operand: type, operand: Operand) usize {
|
fn operandSize(comptime Operand: type, operand: Operand) usize {
|
||||||
return switch (Operand) {
|
return switch (Operand) {
|
||||||
spec.IdResultType,
|
|
||||||
spec.IdResult,
|
spec.IdResult,
|
||||||
spec.IdRef,
|
|
||||||
spec.LiteralInteger,
|
spec.LiteralInteger,
|
||||||
spec.LiteralExtInstInteger,
|
spec.LiteralExtInstInteger,
|
||||||
=> 1,
|
=> 1,
|
||||||
|
|
@ -382,7 +380,9 @@ test "SPIR-V Section emit() - string" {
|
||||||
}, section.instructions.items);
|
}, section.instructions.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SPIR-V Section emit()- extended mask" {
|
test "SPIR-V Section emit() - extended mask" {
|
||||||
|
if (@import("builtin").zig_backend == .stage1) return error.SkipZigTest;
|
||||||
|
|
||||||
var section = Section{};
|
var section = Section{};
|
||||||
defer section.deinit(std.testing.allocator);
|
defer section.deinit(std.testing.allocator);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,11 @@
|
||||||
const Version = @import("std").builtin.Version;
|
const Version = @import("std").builtin.Version;
|
||||||
|
|
||||||
pub const Word = u32;
|
pub const Word = u32;
|
||||||
pub const IdResultType = struct {
|
|
||||||
id: Word,
|
|
||||||
pub fn toRef(self: IdResultType) IdRef {
|
|
||||||
return .{ .id = self.id };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pub const IdResult = struct {
|
pub const IdResult = struct {
|
||||||
id: Word,
|
id: Word,
|
||||||
pub fn toRef(self: IdResult) IdRef {
|
|
||||||
return .{ .id = self.id };
|
|
||||||
}
|
|
||||||
pub fn toResultType(self: IdResult) IdResultType {
|
|
||||||
return .{ .id = self.id };
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
pub const IdRef = struct { id: Word };
|
pub const IdResultType = IdResult;
|
||||||
|
pub const IdRef = IdResult;
|
||||||
|
|
||||||
pub const IdMemorySemantics = IdRef;
|
pub const IdMemorySemantics = IdRef;
|
||||||
pub const IdScope = IdRef;
|
pub const IdScope = IdRef;
|
||||||
|
|
|
||||||
|
|
@ -80,22 +80,11 @@ fn render(writer: anytype, allocator: Allocator, registry: g.CoreRegistry) !void
|
||||||
\\const Version = @import("std").builtin.Version;
|
\\const Version = @import("std").builtin.Version;
|
||||||
\\
|
\\
|
||||||
\\pub const Word = u32;
|
\\pub const Word = u32;
|
||||||
\\pub const IdResultType = struct{
|
|
||||||
\\ id: Word,
|
|
||||||
\\ pub fn toRef(self: IdResultType) IdRef {
|
|
||||||
\\ return .{.id = self.id};
|
|
||||||
\\ }
|
|
||||||
\\};
|
|
||||||
\\pub const IdResult = struct{
|
\\pub const IdResult = struct{
|
||||||
\\ id: Word,
|
\\ id: Word,
|
||||||
\\ pub fn toRef(self: IdResult) IdRef {
|
|
||||||
\\ return .{.id = self.id};
|
|
||||||
\\ }
|
|
||||||
\\ pub fn toResultType(self: IdResult) IdResultType {
|
|
||||||
\\ return .{.id = self.id};
|
|
||||||
\\ }
|
|
||||||
\\};
|
\\};
|
||||||
\\pub const IdRef = struct{ id: Word };
|
\\pub const IdResultType = IdResult;
|
||||||
|
\\pub const IdRef = IdResult;
|
||||||
\\
|
\\
|
||||||
\\pub const IdMemorySemantics = IdRef;
|
\\pub const IdMemorySemantics = IdRef;
|
||||||
\\pub const IdScope = IdRef;
|
\\pub const IdScope = IdRef;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue