adding public queue functions and worker base
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ dispatch_table: *const DispatchTable,
|
||||
vtable: *const VTable,
|
||||
|
||||
pub const VTable = struct {
|
||||
createQueue: *const fn (std.mem.Allocator, *const Self, u32, u32, vk.DeviceQueueCreateFlags) VkError!*Queue,
|
||||
createQueue: *const fn (std.mem.Allocator, *Self, u32, u32, vk.DeviceQueueCreateFlags) VkError!*Queue,
|
||||
destroyQueue: *const fn (*Queue, std.mem.Allocator) VkError!void,
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const Fence = @import("Fence.zig");
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .queue;
|
||||
|
||||
owner: *const Device,
|
||||
owner: *Device,
|
||||
family_index: u32,
|
||||
index: u32,
|
||||
flags: vk.DeviceQueueCreateFlags,
|
||||
@@ -16,12 +16,12 @@ flags: vk.DeviceQueueCreateFlags,
|
||||
dispatch_table: *const DispatchTable,
|
||||
|
||||
pub const DispatchTable = struct {
|
||||
bindSparse: *const fn (*Self, []*const vk.BindSparseInfo, ?*Fence) VkError!void,
|
||||
submit: *const fn (*Self, []*const vk.SubmitInfo, ?*Fence) VkError!void,
|
||||
bindSparse: *const fn (*Self, []const vk.BindSparseInfo, ?*Fence) VkError!void,
|
||||
submit: *const fn (*Self, []const vk.SubmitInfo, ?*Fence) VkError!void,
|
||||
waitIdle: *const fn (*Self) VkError!void,
|
||||
};
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, device: *const Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!Self {
|
||||
pub fn init(allocator: std.mem.Allocator, device: *Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!Self {
|
||||
std.log.scoped(.vkCreateDevice).info("Creating device queue with family index {d} and index {d}", .{ family_index, index });
|
||||
_ = allocator;
|
||||
return .{
|
||||
@@ -33,11 +33,11 @@ pub fn init(allocator: std.mem.Allocator, device: *const Device, index: u32, fam
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn bindSparse(self: *Self, info: []*const vk.BindSparseInfo, fence: ?*Fence) VkError!void {
|
||||
pub inline fn bindSparse(self: *Self, info: []const vk.BindSparseInfo, fence: ?*Fence) VkError!void {
|
||||
try self.dispatch_table.bindSparse(self, info, fence);
|
||||
}
|
||||
|
||||
pub inline fn submit(self: *Self, info: []*const vk.SubmitInfo, fence: ?*Fence) VkError!void {
|
||||
pub inline fn submit(self: *Self, info: []const vk.SubmitInfo, fence: ?*Fence) VkError!void {
|
||||
try self.dispatch_table.submit(self, info, fence);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,11 @@ const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
|
||||
const Instance = @import("Instance.zig");
|
||||
const Device = @import("Device.zig");
|
||||
const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||
const Queue = @import("Queue.zig");
|
||||
|
||||
const DeviceMemory = @import("DeviceMemory.zig");
|
||||
const Fence = @import("Fence.zig");
|
||||
const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||
|
||||
// This file contains all exported Vulkan entrypoints.
|
||||
|
||||
@@ -80,6 +82,9 @@ const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapEntryPoint("vkMapMemory"),
|
||||
functionMapEntryPoint("vkUnmapMemory"),
|
||||
functionMapEntryPoint("vkResetFences"),
|
||||
functionMapEntryPoint("vkQueueBindSparse"),
|
||||
functionMapEntryPoint("vkQueueSubmit"),
|
||||
functionMapEntryPoint("vkQueueWaitIdle"),
|
||||
functionMapEntryPoint("vkWaitForFences"),
|
||||
});
|
||||
|
||||
@@ -389,6 +394,26 @@ pub export fn strollResetFences(p_device: vk.Device, count: u32, p_fences: [*]co
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollQueueBindSparse(p_queue: vk.Queue, count: u32, info: [*]vk.BindSparseInfo, p_fence: vk.Fence) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const queue = Dispatchable(Queue).fromHandleObject(p_queue) catch |err| return toVkResult(err);
|
||||
const fence = if (p_fence != .null_handle) NonDispatchable(Fence).fromHandleObject(p_fence) catch |err| return toVkResult(err) else null;
|
||||
queue.bindSparse(info[0..count], fence) catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollQueueSubmit(p_queue: vk.Queue, count: u32, info: [*]const vk.SubmitInfo, p_fence: vk.Fence) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const queue = Dispatchable(Queue).fromHandleObject(p_queue) catch |err| return toVkResult(err);
|
||||
const fence = if (p_fence != .null_handle) NonDispatchable(Fence).fromHandleObject(p_fence) catch |err| return toVkResult(err) else null;
|
||||
queue.submit(info[0..count], fence) catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollQueueWaitIdle(p_queue: vk.Queue) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const queue = Dispatchable(Queue).fromHandleObject(p_queue) catch |err| return toVkResult(err);
|
||||
queue.waitIdle() catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollWaitForFences(p_device: vk.Device, count: u32, p_fences: [*]const vk.Fence, waitForAll: vk.Bool32, timeout: u64) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
|
||||
const allocator = std.heap.c_allocator;
|
||||
|
||||
Reference in New Issue
Block a user