adding command pool base

This commit is contained in:
2025-11-12 22:50:41 +01:00
parent d52d6f3ea7
commit e08fba24a6
17 changed files with 177 additions and 71 deletions

37
src/vulkan/CommandPool.zig git.filemode.normal_file
View File

@@ -0,0 +1,37 @@
const std = @import("std");
const vk = @import("vulkan");
const VkError = @import("error_set.zig").VkError;
const Device = @import("Device.zig");
const Self = @This();
pub const ObjectType: vk.ObjectType = .command_pool;
owner: *Device,
flags: vk.CommandPoolCreateFlags,
queue_family_index: u32,
vtable: *const VTable,
pub const VTable = struct {
destroy: *const fn (*Self, std.mem.Allocator) void,
reset: *const fn (*Self, vk.CommandPoolResetFlags) VkError!void,
};
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.CommandPoolCreateInfo) VkError!Self {
_ = allocator;
return .{
.owner = device,
.flags = info.flags,
.queue_family_index = info.queue_family_index,
.vtable = undefined,
};
}
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
self.vtable.destroy(self, allocator);
}
pub inline fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
try self.vtable.reset(self, flags);
}

View File

@@ -4,10 +4,13 @@ const vk = @import("vulkan");
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
const VulkanAllocator = @import("VulkanAllocator.zig");
const VkError = @import("error_set.zig").VkError;
const PhysicalDevice = @import("PhysicalDevice.zig");
const Queue = @import("Queue.zig");
const CommandPool = @import("CommandPool.zig");
const DeviceMemory = @import("DeviceMemory.zig");
const Fence = @import("Fence.zig");
const Queue = @import("Queue.zig");
const Self = @This();
pub const ObjectType: vk.ObjectType = .device;
@@ -25,11 +28,13 @@ pub const VTable = struct {
pub const DispatchTable = struct {
allocateMemory: *const fn (*Self, std.mem.Allocator, *const vk.MemoryAllocateInfo) VkError!*DeviceMemory,
createCommandPool: *const fn (*Self, std.mem.Allocator, *const vk.CommandPoolCreateInfo) VkError!*CommandPool,
createFence: *const fn (*Self, std.mem.Allocator, *const vk.FenceCreateInfo) VkError!*Fence,
destroy: *const fn (*Self, std.mem.Allocator) VkError!void,
destroyCommandPool: *const fn (*Self, std.mem.Allocator, *CommandPool) VkError!void,
destroyFence: *const fn (*Self, std.mem.Allocator, *Fence) VkError!void,
freeMemory: *const fn (*Self, std.mem.Allocator, *DeviceMemory) VkError!void,
getFenceStatus: *const fn (*Self, *Fence) VkError!void,
destroy: *const fn (*Self, std.mem.Allocator) VkError!void,
resetFences: *const fn (*Self, []*Fence) VkError!void,
waitForFences: *const fn (*Self, []*Fence, bool, u64) VkError!void,
};
@@ -66,7 +71,7 @@ pub fn createQueues(self: *Self, allocator: std.mem.Allocator, info: *const vk.D
}
}
pub fn destroy(self: *Self, allocator: std.mem.Allocator) VkError!void {
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) VkError!void {
var it = self.queues.iterator();
while (it.next()) |entry| {
const family = entry.value_ptr;
@@ -102,6 +107,16 @@ pub inline fn waitForFences(self: *Self, fences: []*Fence, waitForAll: bool, tim
try self.dispatch_table.waitForFences(self, fences, waitForAll, timeout);
}
// Command Pool functions ============================================================================================================================
pub inline fn createCommandPool(self: *Self, allocator: std.mem.Allocator, info: *const vk.CommandPoolCreateInfo) VkError!*CommandPool {
return self.dispatch_table.createCommandPool(self, allocator, info);
}
pub inline fn destroyCommandPool(self: *Self, allocator: std.mem.Allocator, pool: *CommandPool) VkError!void {
try self.dispatch_table.destroyCommandPool(self, allocator, pool);
}
// Memory functions ==================================================================================================================================
pub inline fn allocateMemory(self: *Self, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*DeviceMemory {

View File

@@ -7,7 +7,7 @@ const Device = @import("Device.zig");
const Self = @This();
pub const ObjectType: vk.ObjectType = .fence;
owner: *const Device,
owner: *Device,
flags: vk.FenceCreateFlags,
vtable: *const VTable,
@@ -20,7 +20,8 @@ pub const VTable = struct {
wait: *const fn (*Self, u64) VkError!void,
};
pub fn init(device: *const Device, info: *const vk.FenceCreateInfo) VkError!Self {
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.FenceCreateInfo) VkError!Self {
_ = allocator;
return .{
.owner = device,
.flags = info.flags,

View File

@@ -35,7 +35,7 @@ pub fn init(allocator: std.mem.Allocator, instance: *const Instance) VkError!Sel
.device_type = undefined,
.device_name = [_]u8{0} ** vk.MAX_PHYSICAL_DEVICE_NAME_SIZE,
.pipeline_cache_uuid = undefined,
.limits = undefined,
.limits = std.mem.zeroInit(vk.PhysicalDeviceLimits, .{}),
.sparse_properties = undefined,
},
.mem_props = .{

View File

@@ -14,6 +14,7 @@ pub const Device = @import("Device.zig");
pub const PhysicalDevice = @import("PhysicalDevice.zig");
pub const Queue = @import("Queue.zig");
pub const CommandPool = @import("CommandPool.zig");
pub const DeviceMemory = @import("DeviceMemory.zig");
pub const Fence = @import("Fence.zig");

View File

@@ -19,6 +19,7 @@ const Device = @import("Device.zig");
const PhysicalDevice = @import("PhysicalDevice.zig");
const Queue = @import("Queue.zig");
const CommandPool = @import("CommandPool.zig");
const DeviceMemory = @import("DeviceMemory.zig");
const Fence = @import("Fence.zig");
@@ -73,9 +74,11 @@ const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComp
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkAllocateMemory"),
functionMapEntryPoint("vkCreateCommandPool"),
functionMapEntryPoint("vkCreateFence"),
functionMapEntryPoint("vkDestroyCommandPool"),
functionMapEntryPoint("vkDestroyFence"),
functionMapEntryPoint("vkDestroyDevice"),
functionMapEntryPoint("vkCreateFence"),
functionMapEntryPoint("vkFreeMemory"),
functionMapEntryPoint("vkGetDeviceQueue"),
functionMapEntryPoint("vkGetFenceStatus"),
@@ -291,6 +294,18 @@ pub export fn strollAllocateMemory(p_device: vk.Device, p_info: ?*const vk.Memor
return .success;
}
pub export fn strollCreateCommandPool(p_device: vk.Device, p_info: ?*const vk.CommandPoolCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_pool: *vk.CommandPool) callconv(vk.vulkan_call_conv) vk.Result {
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .command_pool_create_info) {
return .error_validation_failed;
}
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
const pool = device.createCommandPool(allocator, info) catch |err| return toVkResult(err);
p_pool.* = (NonDispatchable(CommandPool).wrap(allocator, pool) catch |err| return toVkResult(err)).toVkHandle(vk.CommandPool);
return .success;
}
pub export fn strollCreateFence(p_device: vk.Device, p_info: ?*const vk.FenceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_fence: *vk.Fence) callconv(vk.vulkan_call_conv) vk.Result {
const info = p_info orelse return .error_validation_failed;
if (info.s_type != .fence_create_info) {
@@ -314,6 +329,15 @@ pub export fn strollDestroyDevice(p_device: vk.Device, callbacks: ?*const vk.All
dispatchable.destroy(allocator);
}
pub export fn strollDestroyCommandPool(p_device: vk.Device, p_pool: vk.CommandPool, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
const device = Dispatchable(Device).fromHandleObject(p_device) catch return;
const non_dispatchable_pool = NonDispatchable(CommandPool).fromHandle(p_pool) catch return;
device.destroyCommandPool(allocator, non_dispatchable_pool.object) catch return;
non_dispatchable_pool.destroy(allocator);
}
pub export fn strollDestroyFence(p_device: vk.Device, p_fence: vk.Fence, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
const device = Dispatchable(Device).fromHandleObject(p_device) catch return;