making opt-in device debug allocator
This commit is contained in:
@@ -32,7 +32,6 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
const zdt = b.dependency("zdt", .{}).module("zdt");
|
const zdt = b.dependency("zdt", .{}).module("zdt");
|
||||||
const zigrc = b.dependency("zigrc", .{}).module("zigrc");
|
const zigrc = b.dependency("zigrc", .{}).module("zigrc");
|
||||||
//const spv_tools = b.dependency("SPIRV_Tools", .{}).module("zigrc");
|
|
||||||
const vulkan_headers = b.dependency("vulkan_headers", .{});
|
const vulkan_headers = b.dependency("vulkan_headers", .{});
|
||||||
const vulkan_utility_libraries = b.dependency("vulkan_utility_libraries", .{});
|
const vulkan_utility_libraries = b.dependency("vulkan_utility_libraries", .{});
|
||||||
|
|
||||||
@@ -143,6 +142,12 @@ fn customSoft(b: *std.Build, lib: *std.Build.Step.Compile) !void {
|
|||||||
.@"use-llvm" = true,
|
.@"use-llvm" = true,
|
||||||
}).module("spv");
|
}).module("spv");
|
||||||
lib.root_module.addImport("spv", spv);
|
lib.root_module.addImport("spv", spv);
|
||||||
|
|
||||||
|
const debug_allocator_option = b.option(bool, "debug-allocator", "debug device allocator") orelse false;
|
||||||
|
|
||||||
|
const options = b.addOptions();
|
||||||
|
options.addOption(bool, "debug_allocator", debug_allocator_option);
|
||||||
|
lib.root_module.addOptions("config", options);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addCTest(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, vulkan_headers: *std.Build.Dependency, impl: *const ImplementationDesc, impl_lib: *std.Build.Step.Compile) !*std.Build.Step.Compile {
|
fn addCTest(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, vulkan_headers: *std.Build.Dependency, impl: *const ImplementationDesc, impl_lib: *std.Build.Step.Compile) !*std.Build.Step.Compile {
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
const config = @import("config");
|
||||||
const Debug = std.builtin.OptimizeMode.Debug;
|
|
||||||
|
|
||||||
const SoftQueue = @import("SoftQueue.zig");
|
const SoftQueue = @import("SoftQueue.zig");
|
||||||
const Blitter = @import("device/Blitter.zig");
|
const Blitter = @import("device/Blitter.zig");
|
||||||
@@ -37,7 +36,7 @@ pub const Interface = base.Device;
|
|||||||
const SpawnError = std.Thread.SpawnError;
|
const SpawnError = std.Thread.SpawnError;
|
||||||
|
|
||||||
interface: Interface,
|
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,
|
workers: std.Thread.Pool,
|
||||||
blitter: Blitter,
|
blitter: Blitter,
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
|
|||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.interface = interface,
|
.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,
|
.workers = undefined,
|
||||||
.blitter = .init,
|
.blitter = .init,
|
||||||
};
|
};
|
||||||
@@ -96,7 +95,7 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
|
|||||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
self.workers.deinit();
|
self.workers.deinit();
|
||||||
|
|
||||||
if (builtin.mode == Debug) {
|
if (config.debug_allocator) {
|
||||||
// All device memory allocations should've been freed by now
|
// All device memory allocations should've been freed by now
|
||||||
if (!self.device_allocator.detectLeaks()) {
|
if (!self.device_allocator.detectLeaks()) {
|
||||||
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
|
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const DebugStack = @import("DebugStack.zig");
|
const DebugStack = @import("DebugStack.zig");
|
||||||
|
const lib = @import("../lib.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
@@ -14,6 +15,9 @@ pub const init: Self = .{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn indent(self: *Self) void {
|
pub fn indent(self: *Self) void {
|
||||||
|
if (lib.getLogVerboseLevel() == .None) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const new_indent_level, const has_overflown = @addWithOverflow(self.indent_level, 1);
|
const new_indent_level, const has_overflown = @addWithOverflow(self.indent_level, 1);
|
||||||
if (has_overflown == 0) {
|
if (has_overflown == 0) {
|
||||||
self.indent_level = new_indent_level;
|
self.indent_level = new_indent_level;
|
||||||
@@ -21,6 +25,9 @@ pub fn indent(self: *Self) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn unindent(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);
|
const new_indent_level, const has_overflown = @subWithOverflow(self.indent_level, 1);
|
||||||
if (has_overflown == 0) {
|
if (has_overflown == 0) {
|
||||||
self.indent_level = new_indent_level;
|
self.indent_level = new_indent_level;
|
||||||
|
|||||||
@@ -24,12 +24,18 @@ pub inline fn getManager() *ThreadSafeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn fixme(comptime format: []const u8, args: anytype) void {
|
pub inline fn fixme(comptime format: []const u8, args: anytype) void {
|
||||||
|
if (lib.getLogVerboseLevel() == .None) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
getManager().get().disableIndent();
|
getManager().get().disableIndent();
|
||||||
defer getManager().get().enableIndent();
|
defer getManager().get().enableIndent();
|
||||||
nestedFixme(format, args);
|
nestedFixme(format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn nestedFixme(comptime format: []const u8, args: anytype) void {
|
pub inline fn nestedFixme(comptime format: []const u8, args: anytype) void {
|
||||||
|
if (lib.getLogVerboseLevel() == .None) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
std.log.scoped(.FIXME).warn("FIXME: " ++ format, args);
|
std.log.scoped(.FIXME).warn("FIXME: " ++ format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user