fixing some issues

This commit is contained in:
2025-12-04 17:43:58 +01:00
parent 1457062233
commit 4b8aae9eb9
9 changed files with 35 additions and 30 deletions

View File

@@ -1,6 +1,8 @@
const std = @import("std");
const vk = @import("vulkan");
const logger = @import("lib.zig").logger;
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
const VulkanAllocator = @import("VulkanAllocator.zig");
@@ -96,6 +98,10 @@ pub fn createQueues(self: *Self, allocator: std.mem.Allocator, info: *const vk.D
}
const queue = try self.vtable.createQueue(allocator, self, queue_info.queue_family_index, @intCast(family_ptr.items.len), queue_info.flags);
logger.indent();
defer logger.unindent();
const dispatchable_queue = try Dispatchable(Queue).wrap(allocator, queue);
family_ptr.append(allocator, dispatchable_queue) catch return VkError.OutOfHostMemory;
}

View File

@@ -21,6 +21,7 @@ pub fn Dispatchable(comptime T: type) type {
.object_type = T.ObjectType,
.object = object,
};
std.log.debug("Created dispatchable handle at 0x{X}", .{@intFromPtr(self)});
return self;
}

View File

@@ -2,6 +2,8 @@ const std = @import("std");
const builtin = @import("builtin");
const vk = @import("vulkan");
const logger = @import("lib.zig").logger;
const VkError = @import("error_set.zig").VkError;
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
const PhysicalDevice = @import("PhysicalDevice.zig");
@@ -78,6 +80,9 @@ pub fn releasePhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError
}
pub fn requestPhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError!void {
logger.indent();
defer logger.unindent();
try self.vtable.requestPhysicalDevices(self, allocator);
if (self.physical_devices.items.len == 0) {
std.log.scoped(.vkCreateInstance).err("No VkPhysicalDevice found", .{});

View File

@@ -16,6 +16,7 @@ pub fn NonDispatchable(comptime T: type) type {
.object_type = T.ObjectType,
.object = object,
};
std.log.debug("Created non dispatchable handle at 0x{X}", .{@intFromPtr(self)});
return self;
}

View File

@@ -83,5 +83,7 @@ pub fn getSparseImageFormatProperties(
}
pub fn releasePhysicalDevice(self: *Self, allocator: std.mem.Allocator) VkError!void {
self.queue_family_props.deinit(allocator);
self.queue_family_props = .empty;
try self.dispatch_table.release(self, allocator);
}

View File

@@ -3,16 +3,13 @@
const std = @import("std");
const vk = @import("vulkan");
const builtin = @import("builtin");
const DRIVER_DEBUG_ALLOCATOR_ENV_NAME = @import("lib.zig").DRIVER_DEBUG_ALLOCATOR_ENV_NAME;
const Allocator = std.mem.Allocator;
const Alignment = std.mem.Alignment;
const Self = @This();
/// Global debug allocator for leaks detection purpose
pub var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
var fallback_allocator: std.heap.ThreadSafeAllocator = .{ .child_allocator = std.heap.c_allocator };
callbacks: ?vk.AllocationCallbacks,
scope: vk.SystemAllocationScope,
@@ -94,10 +91,5 @@ fn free(context: *anyopaque, ptr: []u8, alignment: Alignment, ret_addr: usize) v
}
inline fn getFallbackAllocator() std.mem.Allocator {
if (std.process.hasEnvVarConstant(DRIVER_DEBUG_ALLOCATOR_ENV_NAME) or builtin.mode == std.builtin.OptimizeMode.Debug) {
@branchHint(.unlikely);
return debug_allocator.allocator();
} else {
return std.heap.page_allocator;
}
return fallback_allocator.allocator();
}

View File

@@ -347,13 +347,6 @@ pub export fn strollDestroyInstance(p_instance: vk.Instance, callbacks: ?*const
const dispatchable = Dispatchable(Instance).fromHandle(p_instance) catch |err| return errorLogger(err);
dispatchable.object.deinit(allocator) catch |err| return errorLogger(err);
dispatchable.destroy(allocator);
if (std.process.hasEnvVarConstant(lib.DRIVER_DEBUG_ALLOCATOR_ENV_NAME) or builtin.mode == std.builtin.OptimizeMode.Debug) {
// All host memory allocations should've been freed by now
if (!VulkanAllocator.debug_allocator.detectLeaks()) {
std.log.scoped(.vkDestroyInstance).debug("No memory leaks detected", .{});
}
}
}
pub export fn strollEnumeratePhysicalDevices(p_instance: vk.Instance, count: *u32, p_devices: ?[*]vk.PhysicalDevice) callconv(vk.vulkan_call_conv) vk.Result {