adding command pool base
This commit is contained in:
39
src/soft/SoftCommandPool.zig
git.filemode.normal_file
39
src/soft/SoftCommandPool.zig
git.filemode.normal_file
@@ -0,0 +1,39 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
|
||||
const VkError = base.VkError;
|
||||
const Device = base.Device;
|
||||
|
||||
const Self = @This();
|
||||
pub const Interface = base.CommandPool;
|
||||
|
||||
interface: Interface,
|
||||
|
||||
pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const vk.CommandPoolCreateInfo) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(self);
|
||||
|
||||
var interface = try Interface.init(device, allocator, info);
|
||||
|
||||
interface.vtable = &.{
|
||||
.destroy = destroy,
|
||||
.reset = reset,
|
||||
};
|
||||
|
||||
self.* = .{
|
||||
.interface = interface,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn reset(interface: *Interface, flags: vk.CommandPoolResetFlags) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
_ = self;
|
||||
_ = flags;
|
||||
}
|
||||
@@ -5,9 +5,11 @@ const builtin = @import("builtin");
|
||||
|
||||
const Debug = std.builtin.OptimizeMode.Debug;
|
||||
|
||||
const SoftQueue = @import("SoftQueue.zig");
|
||||
|
||||
const SoftCommandPool = @import("SoftCommandPool.zig");
|
||||
const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
|
||||
const SoftFence = @import("SoftFence.zig");
|
||||
const SoftQueue = @import("SoftQueue.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
|
||||
@@ -33,8 +35,10 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
|
||||
|
||||
interface.dispatch_table = &.{
|
||||
.allocateMemory = allocateMemory,
|
||||
.createCommandPool = createCommandPool,
|
||||
.createFence = createFence,
|
||||
.destroy = destroy,
|
||||
.destroyCommandPool = destroyCommandPool,
|
||||
.destroyFence = destroyFence,
|
||||
.freeMemory = freeMemory,
|
||||
.getFenceStatus = getFenceStatus,
|
||||
@@ -99,6 +103,17 @@ pub fn waitForFences(_: *Interface, fences: []*base.Fence, waitForAll: bool, tim
|
||||
}
|
||||
}
|
||||
|
||||
// Command Pool functions ============================================================================================================================
|
||||
|
||||
pub fn createCommandPool(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.CommandPoolCreateInfo) VkError!*base.CommandPool {
|
||||
const pool = try SoftCommandPool.create(interface, allocator, info);
|
||||
return &pool.interface;
|
||||
}
|
||||
|
||||
pub fn destroyCommandPool(_: *Interface, allocator: std.mem.Allocator, pool: *base.CommandPool) VkError!void {
|
||||
pool.destroy(allocator);
|
||||
}
|
||||
|
||||
// Memory functions ==================================================================================================================================
|
||||
|
||||
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {
|
||||
|
||||
@@ -13,11 +13,11 @@ mutex: std.Thread.Mutex,
|
||||
condition: std.Thread.Condition,
|
||||
is_signaled: bool,
|
||||
|
||||
pub fn create(device: *const Device, allocator: std.mem.Allocator, info: *const vk.FenceCreateInfo) VkError!*Self {
|
||||
pub fn create(device: *Device, allocator: std.mem.Allocator, info: *const vk.FenceCreateInfo) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(self);
|
||||
|
||||
var interface = try Interface.init(device, info);
|
||||
var interface = try Interface.init(device, allocator, info);
|
||||
|
||||
interface.vtable = &.{
|
||||
.destroy = destroy,
|
||||
|
||||
@@ -32,6 +32,8 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
||||
interface.props.device_id = root.DEVICE_ID;
|
||||
interface.props.device_type = .cpu;
|
||||
|
||||
interface.props.limits.max_bound_descriptor_sets = 1024; // tmp
|
||||
|
||||
interface.mem_props.memory_type_count = 1;
|
||||
interface.mem_props.memory_types[0] = .{
|
||||
.heap_index = 0,
|
||||
@@ -76,7 +78,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
||||
},
|
||||
// TODO: maybe add a compute specialized queue
|
||||
};
|
||||
interface.queue_family_props = std.ArrayList(vk.QueueFamilyProperties).fromOwnedSlice(queue_family_props[0..]);
|
||||
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;
|
||||
@@ -140,5 +142,6 @@ pub fn getSparseImageFormatProperties(
|
||||
|
||||
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
interface.queue_family_props.deinit(allocator);
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ pub fn submit(interface: *Interface, info: []const vk.SubmitInfo, fence: ?*base.
|
||||
|
||||
// TODO: commands executions
|
||||
|
||||
std.log.debug("Queue execution", .{});
|
||||
std.Thread.sleep(1_000_000_000);
|
||||
if (p_fence) |fence_obj| {
|
||||
fence_obj.signal() catch {};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ pub const SoftDevice = @import("SoftDevice.zig");
|
||||
pub const SoftPhysicalDevice = @import("SoftPhysicalDevice.zig");
|
||||
pub const SoftQueue = @import("SoftQueue.zig");
|
||||
|
||||
pub const SoftCommandPool = @import("SoftCommandPool.zig");
|
||||
pub const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
|
||||
pub const SoftFence = @import("SoftFence.zig");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user