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

@@ -147,7 +147,7 @@ pub fn build(b: *std.Build) !void {
const run_cts = b.addSystemCommand(&[_][]const u8{
try cts_exe_path.getPath3(b, null).toString(b.allocator),
b.fmt("--deqp-caselist-file={s}", .{try cts.path("mustpass/1.0.0/vk-default.txt").getPath3(b, null).toString(b.allocator)}),
b.fmt("--deqp-vk-library-path={s}/{s}", .{ b.getInstallPath(.lib, ""), lib.out_lib_filename }),
b.fmt("--deqp-vk-library-path={s}", .{b.getInstallPath(.lib, lib.out_lib_filename)}),
});
run_cts.step.dependOn(&lib_install.step);

View File

@@ -12,6 +12,9 @@ const VulkanAllocator = base.VulkanAllocator;
const Self = @This();
pub const Interface = base.PhysicalDevice;
// Device name should always be the same so avoid reprocessing it multiple times
var device_name = [_]u8{0} ** vk.MAX_PHYSICAL_DEVICE_NAME_SIZE;
interface: Interface,
pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkError!*Self {
@@ -34,7 +37,6 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
interface.props.driver_version = @bitCast(root.DRIVER_VERSION);
interface.props.device_id = root.DEVICE_ID;
interface.props.device_type = .cpu;
interface.props.limits = .{
.max_image_dimension_1d = 4096,
.max_image_dimension_2d = 4096,
@@ -190,12 +192,16 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
};
interface.queue_family_props.appendSlice(allocator, queue_family_props[0..]) catch return VkError.OutOfHostMemory;
// TODO: use Pytorch's cpuinfo someday
const info = cpuinfo.get(command_allocator) catch return VkError.InitializationFailed;
defer info.deinit(command_allocator);
if (device_name[0] == 0) {
// TODO: use Pytorch's cpuinfo someday
const info = cpuinfo.get(command_allocator) catch return VkError.InitializationFailed;
defer info.deinit(command_allocator);
var writer = std.Io.Writer.fixed(interface.props.device_name[0 .. vk.MAX_PHYSICAL_DEVICE_NAME_SIZE - 1]);
writer.print("{s} [" ++ root.DRIVER_NAME ++ " StrollDriver]", .{info.name}) catch return VkError.InitializationFailed;
var writer = std.Io.Writer.fixed(device_name[0 .. vk.MAX_PHYSICAL_DEVICE_NAME_SIZE - 1]);
writer.print("{s} [" ++ root.DRIVER_NAME ++ " StrollDriver]", .{info.name}) catch return VkError.InitializationFailed;
}
@memcpy(&interface.props.device_name, &device_name);
self.* = .{
.interface = interface,
@@ -203,6 +209,11 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
return self;
}
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
allocator.destroy(self);
}
pub fn createDevice(interface: *Interface, allocator: std.mem.Allocator, infos: *const vk.DeviceCreateInfo) VkError!*base.Device {
const device = try SoftDevice.create(interface, allocator, infos);
return &device.interface;
@@ -255,9 +266,3 @@ pub fn getSparseImageFormatProperties(
_ = flags;
return undefined;
}
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
interface.queue_family_props.deinit(allocator);
allocator.destroy(self);
}

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 {