fixing debug allocator
Build / build (push) Successful in 4m14s
Test / build_and_test (push) Has been cancelled

This commit is contained in:
2026-05-08 14:23:49 +02:00
parent eb743c914e
commit e793cb6c3f
9 changed files with 72 additions and 28 deletions
+5 -2
View File
@@ -93,9 +93,12 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
if (config.debug_allocator) {
// All device memory allocations should've been freed by now
if (!self.device_allocator.detectLeaks()) {
const leaks = self.device_allocator.detectLeaks();
if (leaks != 0)
std.log.scoped(.vkDestroyDevice).err("Device was destroyed leaking {d}KB", .{@divTrunc(leaks, 1000)})
else
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
}
self.device_allocator.deinitWithoutLeakChecks();
}
allocator.destroy(self);
+6
View File
@@ -44,6 +44,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance) VkError!*S
.getFormatProperties = getFormatProperties,
.getImageFormatProperties = getImageFormatProperties,
.getSparseImageFormatProperties = getSparseImageFormatProperties,
.enumerateLayerProperties = enumerateLayerProperties,
.enumerateExtensionProperties = enumerateExtensionProperties,
.release = destroy,
@@ -248,6 +249,11 @@ pub fn createDevice(interface: *Interface, allocator: std.mem.Allocator, infos:
return &device.interface;
}
pub fn enumerateLayerProperties(_: *const Interface, count: *u32, p_properties: ?[*]vk.LayerProperties) VkError!void {
count.* = 0;
_ = p_properties;
}
pub fn enumerateExtensionProperties(_: *const Interface, layer_name: ?[]const u8, count: *u32, p_properties: ?[*]vk.ExtensionProperties) VkError!void {
if (layer_name) |_| {
return VkError.LayerNotPresent;
+14 -1
View File
@@ -50,7 +50,7 @@ pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) V
};
}
/// Dummy for docs creation and stuff
/// Dummy to avoid compile error in tests and doc generation
pub fn create(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) VkError!*Self {
_ = allocator;
_ = infos;
@@ -62,6 +62,19 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) VkError!void {
try self.dispatch_table.destroy(self, allocator);
}
pub fn enumerateLayerProperties(count: *u32, p_properties: ?[*]vk.LayerProperties) VkError!void {
if (comptime !builtin.is_test and @hasDecl(root.Instance, "LAYERS")) {
count.* = root.Instance.LAYERS.len;
if (p_properties) |properties| {
for (root.Instance.LAYERS, properties[0..]) |layer, *prop| {
prop.* = layer;
}
}
} else {
count.* = 0;
}
}
pub fn enumerateExtensionProperties(layer_name: ?[]const u8, count: *u32, p_properties: ?[*]vk.ExtensionProperties) VkError!void {
if (layer_name) |_| {
return VkError.LayerNotPresent;
+5
View File
@@ -23,6 +23,7 @@ pub const DispatchTable = struct {
getImageFormatProperties: *const fn (*Self, vk.Format, vk.ImageType, vk.ImageTiling, vk.ImageUsageFlags, vk.ImageCreateFlags) VkError!vk.ImageFormatProperties,
getSparseImageFormatProperties: *const fn (*Self, vk.Format, vk.ImageType, vk.SampleCountFlags, vk.ImageTiling, vk.ImageUsageFlags, ?[*]vk.SparseImageFormatProperties) VkError!u32,
enumerateExtensionProperties: *const fn (*const Self, ?[]const u8, *u32, ?[*]vk.ExtensionProperties) VkError!void,
enumerateLayerProperties: *const fn (*const Self, *u32, ?[*]vk.LayerProperties) VkError!void,
release: *const fn (*Self, std.mem.Allocator) VkError!void,
// VK_KHR_get_physical_device_properties_2
@@ -71,6 +72,10 @@ pub inline fn enumerateExtensionProperties(self: *const Self, layer_name: ?[]con
return try self.dispatch_table.enumerateExtensionProperties(self, layer_name, count, p_properties);
}
pub inline fn enumerateLayerProperties(self: *const Self, count: *u32, p_properties: ?[*]vk.LayerProperties) VkError!void {
return try self.dispatch_table.enumerateLayerProperties(self, count, p_properties);
}
pub inline fn getImageFormatProperties(
self: *Self,
format: vk.Format,
+22 -2
View File
@@ -48,11 +48,11 @@ pub const SurfaceKHR = @import("wsi/SurfaceKHR.zig");
pub const SwapchainKHR = @import("wsi/SwapchainKHR.zig");
pub const WaylandSurfaceKHR = @import("wsi/WaylandSurfaceKHR.zig");
fn entryPointBeginLogTrace(comptime scope: @EnumLiteral()) void {
inline fn entryPointBeginLogTrace(comptime scope: @EnumLiteral()) void {
std.log.scoped(scope).debug("Calling {s}...", .{@tagName(scope)});
}
fn entryPointEndLogTrace() void {}
inline fn entryPointEndLogTrace() void {}
inline fn notImplementedWarning() void {
logger.fixme("function not yet implemented", .{});
@@ -79,6 +79,7 @@ const icd_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkCreateInstance"),
functionMapEntryPoint("vkEnumerateInstanceExtensionProperties"),
functionMapEntryPoint("vkEnumerateInstanceLayerProperties"),
//functionMapEntryPoint("vkEnumerateInstanceVersion"),
functionMapEntryPoint("vkGetInstanceProcAddr"),
});
@@ -94,6 +95,7 @@ const instance_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkCreateDevice"),
functionMapEntryPoint("vkEnumerateDeviceExtensionProperties"),
functionMapEntryPoint("vkEnumerateDeviceLayerProperties"),
functionMapEntryPoint("vkGetPhysicalDeviceFeatures"),
functionMapEntryPoint("vkGetPhysicalDeviceFeatures2KHR"),
functionMapEntryPoint("vkGetPhysicalDeviceFormatProperties"),
@@ -316,6 +318,14 @@ pub export fn strollCreateInstance(info: *const vk.InstanceCreateInfo, callbacks
return .success;
}
pub export fn strollEnumerateInstanceLayerProperties(property_count: *u32, properties: ?[*]vk.LayerProperties) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkEnumerateInstanceLayerProperties);
defer entryPointEndLogTrace();
Instance.enumerateLayerProperties(property_count, properties) catch |err| return toVkResult(err);
return .success;
}
pub export fn strollEnumerateInstanceExtensionProperties(p_layer_name: ?[*:0]const u8, property_count: *u32, properties: ?[*]vk.ExtensionProperties) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkEnumerateInstanceExtensionProperties);
defer entryPointEndLogTrace();
@@ -328,6 +338,7 @@ pub export fn strollEnumerateInstanceExtensionProperties(p_layer_name: ?[*:0]con
return .success;
}
/// Do not make it available to GetProcAddr until Vulkan 1.1 is implemented
pub export fn strollEnumerateInstanceVersion(version: *u32) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkEnumerateInstanceVersion);
defer entryPointEndLogTrace();
@@ -382,6 +393,15 @@ pub export fn strollCreateDevice(p_physical_device: vk.PhysicalDevice, info: *co
return .success;
}
pub export fn strollEnumerateDeviceLayerProperties(p_physical_device: vk.PhysicalDevice, property_count: *u32, properties: ?[*]vk.LayerProperties) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkEnumerateDeviceLayerProperties);
defer entryPointEndLogTrace();
const physical_device = Dispatchable(PhysicalDevice).fromHandleObject(p_physical_device) catch |err| return toVkResult(err);
physical_device.enumerateLayerProperties(property_count, properties) catch |err| return toVkResult(err);
return .success;
}
pub export fn strollEnumerateDeviceExtensionProperties(p_physical_device: vk.PhysicalDevice, p_layer_name: ?[*:0]const u8, property_count: *u32, properties: ?[*]vk.ExtensionProperties) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkEnumerateDeviceExtensionProperties);
defer entryPointEndLogTrace();