adding command buffer pool logic

This commit is contained in:
2025-11-15 21:29:08 +01:00
parent fbdce598e3
commit 027bd2ce1c
8 changed files with 65 additions and 33 deletions

View File

@@ -2,9 +2,12 @@ const std = @import("std");
const vk = @import("vulkan");
const base = @import("base");
const NonDispatchable = base.NonDispatchable;
const VkError = base.VkError;
const Device = base.Device;
const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
const Self = @This();
pub const Interface = base.CommandPool;
@@ -28,10 +31,18 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
return self;
}
pub fn allocateCommandBuffers(interface: *Interface, info: *const vk.CommandBufferAllocateInfo) VkError![]*base.CommandBuffer {
_ = interface;
_ = info;
return VkError.FeatureNotPresent;
pub fn allocateCommandBuffers(interface: *Interface, info: *const vk.CommandBufferAllocateInfo) VkError!void {
const allocator = interface.host_allocator.allocator();
while (interface.buffers.capacity < interface.buffers.items.len + info.command_buffer_count) {
interface.buffers.ensureUnusedCapacity(allocator, base.CommandPool.BUFFER_POOL_BASE_CAPACITY) catch return VkError.OutOfHostMemory;
}
for (0..info.command_buffer_count) |_| {
const cmd = try SoftCommandBuffer.create(interface.owner, allocator, info);
const non_dis_cmd = try NonDispatchable(base.CommandBuffer).wrap(allocator, &cmd.interface);
interface.buffers.appendAssumeCapacity(non_dis_cmd);
}
}
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {

View File

@@ -7,6 +7,7 @@ const cpuinfo = @import("cpuinfo");
const SoftDevice = @import("SoftDevice.zig");
const VkError = base.VkError;
const VulkanAllocator = base.VulkanAllocator;
const Self = @This();
pub const Interface = base.PhysicalDevice;
@@ -14,6 +15,8 @@ pub const Interface = base.PhysicalDevice;
interface: Interface,
pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkError!*Self {
const command_allocator = VulkanAllocator.from(allocator).cloneWithScope(.command).allocator();
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
errdefer allocator.destroy(self);
@@ -81,8 +84,8 @@ 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(allocator) catch return VkError.InitializationFailed;
defer info.deinit(allocator);
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;