adding public queue functions and worker base

This commit is contained in:
2025-11-12 17:40:54 +01:00
parent d03515c335
commit 9a0cc0d03d
9 changed files with 96 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ const std = @import("std");
const vk = @import("vulkan");
const base = @import("base");
const SoftDevice = @import("SoftDevice.zig");
const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
const SoftFence = @import("SoftFence.zig");
@@ -11,9 +12,11 @@ const Self = @This();
pub const Interface = base.Queue;
interface: Interface,
wait_group: std.Thread.WaitGroup,
mutex: std.Thread.Mutex,
worker_mutex: std.Thread.Mutex,
pub fn create(allocator: std.mem.Allocator, device: *const base.Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!*Interface {
pub fn create(allocator: std.mem.Allocator, device: *base.Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!*Interface {
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
errdefer allocator.destroy(self);
@@ -27,7 +30,9 @@ pub fn create(allocator: std.mem.Allocator, device: *const base.Device, index: u
self.* = .{
.interface = interface,
.wait_group = .{},
.mutex = .{},
.worker_mutex = .{},
};
return &self.interface;
}
@@ -37,21 +42,46 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
allocator.destroy(self);
}
pub fn bindSparse(interface: *Interface, info: []*const vk.BindSparseInfo, fence: ?*base.Fence) VkError!void {
pub fn bindSparse(interface: *Interface, info: []const vk.BindSparseInfo, fence: ?*base.Fence) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
_ = self;
_ = info;
_ = fence;
return VkError.FeatureNotPresent;
}
pub fn submit(interface: *Interface, info: []*const vk.SubmitInfo, fence: ?*base.Fence) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
_ = self;
pub fn submit(interface: *Interface, info: []const vk.SubmitInfo, fence: ?*base.Fence) VkError!void {
var self: *Self = @alignCast(@fieldParentPtr("interface", interface));
_ = info;
_ = fence;
const Runner = struct {
fn run(queue: *Self, p_fence: ?*base.Fence) void {
// Waiting for older submits to finish execution
queue.worker_mutex.lock();
defer queue.worker_mutex.unlock();
// TODO: commands executions
std.log.debug("Queue execution", .{});
std.Thread.sleep(1_000_000_000);
if (p_fence) |fence_obj| {
fence_obj.signal() catch {};
}
}
};
self.mutex.lock();
defer self.mutex.unlock();
var soft_device: *SoftDevice = @alignCast(@fieldParentPtr("interface", interface.owner));
soft_device.workers.spawnWg(&self.wait_group, Runner.run, .{ self, fence });
}
pub fn waitIdle(interface: *Interface) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
_ = self;
self.mutex.lock();
defer self.mutex.unlock();
self.wait_group.wait();
}