switching to smp_allocator
Build / build (push) Successful in 2m5s
Test / build_and_test (push) Successful in 1h14m49s

This commit is contained in:
2026-04-04 03:59:54 +02:00
parent c0e71d501a
commit 6f6f2e6ab2
6 changed files with 86 additions and 23 deletions
+9 -4
View File
@@ -35,8 +35,14 @@ pub const Interface = base.Device;
const SpawnError = std.Thread.SpawnError;
const DeviceAllocator = struct {
pub inline fn allocator(_: @This()) std.mem.Allocator {
return std.heap.smp_allocator;
}
};
interface: Interface,
device_allocator: if (config.debug_allocator) std.heap.DebugAllocator(.{}) else std.heap.ThreadSafeAllocator,
device_allocator: if (config.debug_allocator) std.heap.DebugAllocator(.{}) else DeviceAllocator,
workers: std.Thread.Pool,
blitter: Blitter,
@@ -77,7 +83,7 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
self.* = .{
.interface = interface,
.device_allocator = if (config.debug_allocator) .init else .{ .child_allocator = std.heap.c_allocator }, // TODO: better device allocator
.device_allocator = if (config.debug_allocator) .init else .{},
.workers = undefined,
.blitter = .init,
};
@@ -100,9 +106,8 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
if (!self.device_allocator.detectLeaks()) {
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
}
allocator.destroy(self);
}
allocator.destroy(self);
}
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {
+1 -1
View File
@@ -129,12 +129,12 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
var it = self.stages.iterator();
while (it.next()) |stage| {
stage.value.module.unref(allocator);
for (stage.value.runtimes) |*runtime| {
runtime.deinit(device_allocator);
}
device_allocator.free(stage.value.runtimes);
device_allocator.free(stage.value.entry);
stage.value.module.unref(allocator);
}
allocator.destroy(self);
}
+8 -2
View File
@@ -9,16 +9,22 @@ const Alignment = std.mem.Alignment;
const Self = @This();
const FallbackAllocator = struct {
pub inline fn allocator(_: @This()) std.mem.Allocator {
return std.heap.smp_allocator;
}
};
callbacks: ?vk.AllocationCallbacks,
scope: vk.SystemAllocationScope,
fallback_allocator: std.heap.ThreadSafeAllocator,
fallback_allocator: FallbackAllocator,
pub fn init(callbacks: ?*const vk.AllocationCallbacks, scope: vk.SystemAllocationScope) Self {
const deref_callbacks = if (callbacks) |c| c.* else null;
return .{
.callbacks = deref_callbacks,
.scope = scope,
.fallback_allocator = .{ .child_allocator = std.heap.c_allocator },
.fallback_allocator = .{},
};
}