making opt-in device debug allocator

This commit is contained in:
2026-03-17 15:14:15 +01:00
parent d2695f60a3
commit c763dd56d4
4 changed files with 23 additions and 6 deletions
+4 -5
View File
@@ -2,8 +2,7 @@ const std = @import("std");
const vk = @import("vulkan");
const base = @import("base");
const builtin = @import("builtin");
const Debug = std.builtin.OptimizeMode.Debug;
const config = @import("config");
const SoftQueue = @import("SoftQueue.zig");
const Blitter = @import("device/Blitter.zig");
@@ -37,7 +36,7 @@ pub const Interface = base.Device;
const SpawnError = std.Thread.SpawnError;
interface: Interface,
device_allocator: if (builtin.mode == Debug) std.heap.DebugAllocator(.{}) else std.heap.ThreadSafeAllocator,
device_allocator: if (config.debug_allocator) std.heap.DebugAllocator(.{}) else std.heap.ThreadSafeAllocator,
workers: std.Thread.Pool,
blitter: Blitter,
@@ -78,7 +77,7 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
self.* = .{
.interface = interface,
.device_allocator = if (builtin.mode == Debug) .init else .{ .child_allocator = std.heap.c_allocator }, // TODO: better device allocator
.device_allocator = if (config.debug_allocator) .init else .{ .child_allocator = std.heap.c_allocator }, // TODO: better device allocator
.workers = undefined,
.blitter = .init,
};
@@ -96,7 +95,7 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.workers.deinit();
if (builtin.mode == Debug) {
if (config.debug_allocator) {
// All device memory allocations should've been freed by now
if (!self.device_allocator.detectLeaks()) {
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
+7
View File
@@ -1,5 +1,6 @@
const std = @import("std");
const DebugStack = @import("DebugStack.zig");
const lib = @import("../lib.zig");
const Self = @This();
@@ -14,6 +15,9 @@ pub const init: Self = .{
};
pub fn indent(self: *Self) void {
if (lib.getLogVerboseLevel() == .None) {
return;
}
const new_indent_level, const has_overflown = @addWithOverflow(self.indent_level, 1);
if (has_overflown == 0) {
self.indent_level = new_indent_level;
@@ -21,6 +25,9 @@ pub fn indent(self: *Self) void {
}
pub fn unindent(self: *Self) void {
if (lib.getLogVerboseLevel() == .None) {
return;
}
const new_indent_level, const has_overflown = @subWithOverflow(self.indent_level, 1);
if (has_overflown == 0) {
self.indent_level = new_indent_level;
+6
View File
@@ -24,12 +24,18 @@ pub inline fn getManager() *ThreadSafeManager {
}
pub inline fn fixme(comptime format: []const u8, args: anytype) void {
if (lib.getLogVerboseLevel() == .None) {
return;
}
getManager().get().disableIndent();
defer getManager().get().enableIndent();
nestedFixme(format, args);
}
pub inline fn nestedFixme(comptime format: []const u8, args: anytype) void {
if (lib.getLogVerboseLevel() == .None) {
return;
}
std.log.scoped(.FIXME).warn("FIXME: " ++ format, args);
}