Commit 572517376a
Changed files (3)
src
codegen
src/codegen/spirv/Cache.zig
@@ -462,11 +462,11 @@ fn emit(
switch (key) {
.void_type => {
try section.emit(spv.gpa, .OpTypeVoid, .{ .id_result = result_id });
- try spv.debugName(result_id, "void", .{});
+ try spv.debugName(result_id, "void");
},
.bool_type => {
try section.emit(spv.gpa, .OpTypeBool, .{ .id_result = result_id });
- try spv.debugName(result_id, "bool", .{});
+ try spv.debugName(result_id, "bool");
},
.int_type => |int| {
try section.emit(spv.gpa, .OpTypeInt, .{
@@ -481,14 +481,14 @@ fn emit(
.unsigned => "u",
.signed => "i",
};
- try spv.debugName(result_id, "{s}{}", .{ ui, int.bits });
+ try spv.debugNameFmt(result_id, "{s}{}", .{ ui, int.bits });
},
.float_type => |float| {
try section.emit(spv.gpa, .OpTypeFloat, .{
.id_result = result_id,
.width = float.bits,
});
- try spv.debugName(result_id, "f{}", .{float.bits});
+ try spv.debugNameFmt(result_id, "f{}", .{float.bits});
},
.vector_type => |vector| {
try section.emit(spv.gpa, .OpTypeVector, .{
@@ -530,11 +530,11 @@ fn emit(
section.writeOperand(IdResult, self.resultId(member_type));
}
if (self.getString(struct_type.name)) |name| {
- try spv.debugName(result_id, "{s}", .{name});
+ try spv.debugName(result_id, name);
}
for (struct_type.memberNames(), 0..) |member_name, i| {
if (self.getString(member_name)) |name| {
- try spv.memberDebugName(result_id, @as(u32, @intCast(i)), "{s}", .{name});
+ try spv.memberDebugName(result_id, @as(u32, @intCast(i)), name);
}
}
// TODO: Decorations?
src/codegen/spirv/Module.zig
@@ -645,18 +645,20 @@ pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8
});
}
-pub fn debugName(self: *Module, target: IdResult, comptime fmt: []const u8, args: anytype) !void {
- const name = try std.fmt.allocPrint(self.gpa, fmt, args);
- defer self.gpa.free(name);
+pub fn debugName(self: *Module, target: IdResult, name: []const u8) !void {
try self.sections.debug_names.emit(self.gpa, .OpName, .{
.target = target,
.name = name,
});
}
-pub fn memberDebugName(self: *Module, target: IdResult, member: u32, comptime fmt: []const u8, args: anytype) !void {
+pub fn debugNameFmt(self: *Module, target: IdResult, comptime fmt: []const u8, args: anytype) !void {
const name = try std.fmt.allocPrint(self.gpa, fmt, args);
defer self.gpa.free(name);
+ try self.debugName(target, name);
+}
+
+pub fn memberDebugName(self: *Module, target: IdResult, member: u32, name: []const u8) !void {
try self.sections.debug_names.emit(self.gpa, .OpMemberName, .{
.type = target,
.member = member,
src/codegen/spirv.zig
@@ -1474,10 +1474,7 @@ pub const DeclGen = struct {
try self.spv.addFunction(spv_decl_index, self.func);
const fqn = ip.stringToSlice(try decl.getFullyQualifiedName(self.module));
- try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
- .target = decl_id,
- .name = fqn,
- });
+ try self.spv.debugName(decl_id, fqn);
// Temporarily generate a test kernel declaration if this is a test function.
if (self.module.test_functions.contains(self.decl_index)) {
@@ -1548,17 +1545,8 @@ pub const DeclGen = struct {
try self.spv.addFunction(spv_decl_index, self.func);
const fqn = ip.stringToSlice(try decl.getFullyQualifiedName(self.module));
- try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
- .target = decl_id,
- .name = fqn,
- });
-
- const init_name = try std.fmt.allocPrint(self.gpa, "initializer of {s}", .{fqn});
- defer self.gpa.free(init_name);
- try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
- .target = initializer_id,
- .name = init_name,
- });
+ try self.spv.debugName(decl_id, fqn);
+ try self.spv.debugNameFmt(initializer_id, "initializer of {s}", .{fqn});
}
}
@@ -1756,11 +1744,10 @@ pub const DeclGen = struct {
.switch_br => return self.airSwitchBr(inst),
.unreach, .trap => return self.airUnreach(),
- .dbg_stmt => return self.airDbgStmt(inst),
- .dbg_inline_begin => return self.airDbgInlineBegin(inst),
- .dbg_inline_end => return self.airDbgInlineEnd(inst),
- .dbg_var_ptr => return,
- .dbg_var_val => return,
+ .dbg_stmt => return self.airDbgStmt(inst),
+ .dbg_inline_begin => return self.airDbgInlineBegin(inst),
+ .dbg_inline_end => return self.airDbgInlineEnd(inst),
+ .dbg_var_ptr, .dbg_var_val => return self.airDbgVar(inst),
.dbg_block_begin => return,
.dbg_block_end => return,
@@ -3566,6 +3553,13 @@ pub const DeclGen = struct {
_ = self.base_line_stack.pop();
}
+ fn airDbgVar(self: *DeclGen, inst: Air.Inst.Index) !void {
+ const pl_op = self.air.instructions.items(.data)[inst].pl_op;
+ const target_id = try self.resolve(pl_op.operand);
+ const name = self.air.nullTerminatedString(pl_op.payload);
+ try self.spv.debugName(target_id, name);
+ }
+
fn airAssembly(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
const mod = self.module;
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;