working on queues
This commit is contained in:
@@ -39,7 +39,7 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
|
|||||||
.workers = undefined,
|
.workers = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.workers.init(.{ .allocator = std.heap.c_allocator }) catch |err| return switch (err) {
|
self.workers.init(.{ .allocator = self.interface.host_allocator.allocator() }) catch |err| return switch (err) {
|
||||||
SpawnError.OutOfMemory, SpawnError.LockedMemoryLimitExceeded => VkError.OutOfDeviceMemory,
|
SpawnError.OutOfMemory, SpawnError.LockedMemoryLimitExceeded => VkError.OutOfDeviceMemory,
|
||||||
else => VkError.Unknown,
|
else => VkError.Unknown,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) V
|
|||||||
// Software driver only has one physical device (the CPU)
|
// Software driver only has one physical device (the CPU)
|
||||||
const physical_device = try SoftPhysicalDevice.create(allocator, interface);
|
const physical_device = try SoftPhysicalDevice.create(allocator, interface);
|
||||||
errdefer physical_device.interface.releasePhysicalDevice(allocator) catch {};
|
errdefer physical_device.interface.releasePhysicalDevice(allocator) catch {};
|
||||||
interface.physical_devices.append(allocator, try Dispatchable(SoftPhysicalDevice.Interface).wrap(allocator, &physical_device.interface)) catch return VkError.OutOfHostMemory;
|
interface.physical_devices.append(allocator, try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface)) catch return VkError.OutOfHostMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn releasePhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
fn releasePhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createDevice(interface: *Interface, allocator: std.mem.Allocator, infos: *const vk.DeviceCreateInfo) VkError!*SoftDevice.Interface {
|
pub fn createDevice(interface: *Interface, allocator: std.mem.Allocator, infos: *const vk.DeviceCreateInfo) VkError!*base.Device {
|
||||||
const device = try SoftDevice.create(interface, allocator, infos);
|
const device = try SoftDevice.create(interface, allocator, infos);
|
||||||
return &device.interface;
|
return &device.interface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,3 +12,41 @@ pub const Interface = base.Queue;
|
|||||||
|
|
||||||
interface: Interface,
|
interface: Interface,
|
||||||
mutex: std.Thread.Mutex,
|
mutex: std.Thread.Mutex,
|
||||||
|
|
||||||
|
pub fn create(allocator: std.mem.Allocator, device: *const base.Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!*Self {
|
||||||
|
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||||
|
errdefer allocator.destroy(self);
|
||||||
|
|
||||||
|
var interface = try Interface.init(allocator, device, index, family_index, flags);
|
||||||
|
|
||||||
|
interface.dispatch_table = &.{
|
||||||
|
.bindSparse = bindSparse,
|
||||||
|
.submit = submit,
|
||||||
|
.waitIdle = waitIdle,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.* = .{
|
||||||
|
.interface = interface,
|
||||||
|
.mutex = .{},
|
||||||
|
};
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bindSparse(interface: *Interface, info: []*const vk.BindSparseInfo, fence: ?*base.Fence) VkError!void {
|
||||||
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
|
_ = self;
|
||||||
|
_ = info;
|
||||||
|
_ = fence;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn submit(interface: *Interface, info: []*const vk.SubmitInfo, fence: ?*base.Fence) VkError!void {
|
||||||
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
|
_ = self;
|
||||||
|
_ = info;
|
||||||
|
_ = fence;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn waitIdle(interface: *Interface) VkError!void {
|
||||||
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
|
_ = self;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
|
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
|
||||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
const PhysicalDevice = @import("PhysicalDevice.zig");
|
const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||||
const DeviceMemory = @import("DeviceMemory.zig");
|
const DeviceMemory = @import("DeviceMemory.zig");
|
||||||
const Fence = @import("Fence.zig");
|
const Fence = @import("Fence.zig");
|
||||||
|
const Queue = @import("Queue.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .device;
|
pub const ObjectType: vk.ObjectType = .device;
|
||||||
@@ -13,6 +15,7 @@ pub const ObjectType: vk.ObjectType = .device;
|
|||||||
physical_device: *const PhysicalDevice,
|
physical_device: *const PhysicalDevice,
|
||||||
dispatch_table: *const DispatchTable,
|
dispatch_table: *const DispatchTable,
|
||||||
host_allocator: VulkanAllocator,
|
host_allocator: VulkanAllocator,
|
||||||
|
queues: std.AutoArrayHashMapUnmanaged(u32, *Dispatchable(Queue)),
|
||||||
|
|
||||||
pub const DispatchTable = struct {
|
pub const DispatchTable = struct {
|
||||||
allocateMemory: *const fn (*Self, std.mem.Allocator, *const vk.MemoryAllocateInfo) VkError!*DeviceMemory,
|
allocateMemory: *const fn (*Self, std.mem.Allocator, *const vk.MemoryAllocateInfo) VkError!*DeviceMemory,
|
||||||
@@ -32,10 +35,12 @@ pub fn init(allocator: std.mem.Allocator, physical_device: *const PhysicalDevice
|
|||||||
.physical_device = physical_device,
|
.physical_device = physical_device,
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
.host_allocator = vulkan_allocator.*,
|
.host_allocator = vulkan_allocator.*,
|
||||||
|
.queues = .empty,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
pub fn destroy(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||||
|
self.queues.deinit(allocator);
|
||||||
try self.dispatch_table.destroy(self, allocator);
|
try self.dispatch_table.destroy(self, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ comptime {
|
|||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .instance;
|
pub const ObjectType: vk.ObjectType = .instance;
|
||||||
|
|
||||||
physical_devices: std.ArrayList(*Dispatchable(PhysicalDevice)),
|
physical_devices: std.ArrayListUnmanaged(*Dispatchable(PhysicalDevice)),
|
||||||
dispatch_table: *const DispatchTable,
|
dispatch_table: *const DispatchTable,
|
||||||
|
|
||||||
pub const DispatchTable = struct {
|
pub const DispatchTable = struct {
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ pub const DispatchTable = struct {
|
|||||||
waitIdle: *const fn (*Self) VkError!void,
|
waitIdle: *const fn (*Self) VkError!void,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, device: *const Device, index: u32, info: vk.DeviceQueueCreateInfo) VkError!Self {
|
pub fn init(allocator: std.mem.Allocator, device: *const Device, index: u32, family_index: u32, flags: vk.DeviceQueueCreateFlags) VkError!Self {
|
||||||
_ = allocator;
|
_ = allocator;
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.family_index = info.queueFamilyIndex,
|
.family_index = family_index,
|
||||||
.index = index,
|
.index = index,
|
||||||
.flags = info.flags,
|
.flags = flags,
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user