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

View File

@@ -12,8 +12,6 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2 - uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Building - name: Building
run: zig build run: zig build

View File

@@ -12,8 +12,6 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2 - uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Building - name: Building
run: zig build run: zig build

View File

@@ -73,6 +73,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&run_tests.step); test_step.dependOn(&run_tests.step);
const volk = b.lazyDependency("volk", .{}) orelse continue; const volk = b.lazyDependency("volk", .{}) orelse continue;
const kvf = b.lazyDependency("kvf", .{}) orelse continue;
const c_test_exe = b.addExecutable(.{ const c_test_exe = b.addExecutable(.{
.name = b.fmt("c_test_vulkan_{s}", .{impl.name}), .name = b.fmt("c_test_vulkan_{s}", .{impl.name}),
@@ -84,6 +85,7 @@ pub fn build(b: *std.Build) !void {
}); });
c_test_exe.root_module.addSystemIncludePath(volk.path("")); c_test_exe.root_module.addSystemIncludePath(volk.path(""));
c_test_exe.root_module.addSystemIncludePath(kvf.path(""));
c_test_exe.root_module.addSystemIncludePath(vulkan_headers.path("include")); c_test_exe.root_module.addSystemIncludePath(vulkan_headers.path("include"));
c_test_exe.root_module.addCSourceFile(.{ c_test_exe.root_module.addCSourceFile(.{

View File

@@ -5,6 +5,10 @@
.minimum_zig_version = "0.15.2", .minimum_zig_version = "0.15.2",
.dependencies = .{ .dependencies = .{
.compile_commands = .{
.url = "git+https://github.com/the-argus/zig-compile-commands#f74e2d13e43fafab3a71e19557a0e1cfbf0f2e1b",
.hash = "zig_compile_commands-0.0.1-OZg5-a3CAACM-h32Kjb1obTMqrKGs9YoDhorVZ8-LGle",
},
.vulkan_headers = .{ .vulkan_headers = .{
.url = "git+https://github.com/KhronosGroup/Vulkan-Headers?ref=v1.4.330#ee3b5caaa7e372715873c7b9c390ee1c3ca5db25", .url = "git+https://github.com/KhronosGroup/Vulkan-Headers?ref=v1.4.330#ee3b5caaa7e372715873c7b9c390ee1c3ca5db25",
.hash = "N-V-__8AAFXYAQKsK51AAGXB9HziPDFjS_DVUq6_QHVxHrBM", .hash = "N-V-__8AAFXYAQKsK51AAGXB9HziPDFjS_DVUq6_QHVxHrBM",
@@ -17,19 +21,20 @@
.url = "git+https://github.com/FObersteiner/zdt/?ref=v0.8.1#8b551a0a3e5ae64a32b5bad0e6a93119787b43af", .url = "git+https://github.com/FObersteiner/zdt/?ref=v0.8.1#8b551a0a3e5ae64a32b5bad0e6a93119787b43af",
.hash = "zdt-0.8.1-xr0_vAxUDwCJRDh9pcAS_mdZBIsvcGTtN-K8JJSWY4I6", .hash = "zdt-0.8.1-xr0_vAxUDwCJRDh9pcAS_mdZBIsvcGTtN-K8JJSWY4I6",
}, },
.volk = .{
.url = "git+https://github.com/zeux/volk/#8f53cc717f50f142db4736f401d0b61956cd78f9",
.hash = "N-V-__8AAPn9BwCBHnaxOC_rffCpFI7QRfi5qBCLvov9EYK3",
.lazy = true,
},
.cpuinfo = .{ .cpuinfo = .{
.url = "git+https://github.com/Kbz-8/cpuinfo-zig#77f82a1248194e7fb706967343c66021f8522766", .url = "git+https://github.com/Kbz-8/cpuinfo-zig#77f82a1248194e7fb706967343c66021f8522766",
.hash = "cpuinfo-0.1.0-V7dMLcghAADJuG7dkd3MnwDPZ232pBK_8uGjxY43eP5u", .hash = "cpuinfo-0.1.0-V7dMLcghAADJuG7dkd3MnwDPZ232pBK_8uGjxY43eP5u",
.lazy = true, .lazy = true,
}, },
.compile_commands = .{ .volk = .{
.url = "git+https://github.com/the-argus/zig-compile-commands#f74e2d13e43fafab3a71e19557a0e1cfbf0f2e1b", .url = "git+https://github.com/zeux/volk/#8f53cc717f50f142db4736f401d0b61956cd78f9",
.hash = "zig_compile_commands-0.0.1-OZg5-a3CAACM-h32Kjb1obTMqrKGs9YoDhorVZ8-LGle", .hash = "N-V-__8AAPn9BwCBHnaxOC_rffCpFI7QRfi5qBCLvov9EYK3",
.lazy = true,
},
.kvf = .{
.url = "git+https://github.com/Kbz-8/KVF#492a2f8e08f5aa3f5e9c9869668829af3f483d26",
.hash = "N-V-__8AALuHAgC55XjEl7WQZIw2YjKvEwvE04FMHGtzVOH5",
.lazy = true,
}, },
}, },

39
src/soft/SoftCommandPool.zig git.filemode.normal_file
View 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;
}

View File

@@ -5,9 +5,11 @@ const builtin = @import("builtin");
const Debug = std.builtin.OptimizeMode.Debug; const Debug = std.builtin.OptimizeMode.Debug;
const SoftQueue = @import("SoftQueue.zig");
const SoftCommandPool = @import("SoftCommandPool.zig");
const SoftDeviceMemory = @import("SoftDeviceMemory.zig"); const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
const SoftFence = @import("SoftFence.zig"); const SoftFence = @import("SoftFence.zig");
const SoftQueue = @import("SoftQueue.zig");
const VkError = base.VkError; const VkError = base.VkError;
@@ -33,8 +35,10 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
interface.dispatch_table = &.{ interface.dispatch_table = &.{
.allocateMemory = allocateMemory, .allocateMemory = allocateMemory,
.createCommandPool = createCommandPool,
.createFence = createFence, .createFence = createFence,
.destroy = destroy, .destroy = destroy,
.destroyCommandPool = destroyCommandPool,
.destroyFence = destroyFence, .destroyFence = destroyFence,
.freeMemory = freeMemory, .freeMemory = freeMemory,
.getFenceStatus = getFenceStatus, .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 ================================================================================================================================== // Memory functions ==================================================================================================================================
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory { pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {

View File

@@ -13,11 +13,11 @@ mutex: std.Thread.Mutex,
condition: std.Thread.Condition, condition: std.Thread.Condition,
is_signaled: bool, 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; const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
errdefer allocator.destroy(self); errdefer allocator.destroy(self);
var interface = try Interface.init(device, info); var interface = try Interface.init(device, allocator, info);
interface.vtable = &.{ interface.vtable = &.{
.destroy = destroy, .destroy = destroy,

View File

@@ -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_id = root.DEVICE_ID;
interface.props.device_type = .cpu; 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_type_count = 1;
interface.mem_props.memory_types[0] = .{ interface.mem_props.memory_types[0] = .{
.heap_index = 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 // 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 // TODO: use Pytorch's cpuinfo someday
const info = cpuinfo.get(allocator) catch return VkError.InitializationFailed; 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 { pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface)); const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
interface.queue_family_props.deinit(allocator);
allocator.destroy(self); allocator.destroy(self);
} }

View File

@@ -62,8 +62,6 @@ pub fn submit(interface: *Interface, info: []const vk.SubmitInfo, fence: ?*base.
// TODO: commands executions // TODO: commands executions
std.log.debug("Queue execution", .{});
std.Thread.sleep(1_000_000_000);
if (p_fence) |fence_obj| { if (p_fence) |fence_obj| {
fence_obj.signal() catch {}; fence_obj.signal() catch {};
} }

View File

@@ -7,6 +7,7 @@ pub const SoftDevice = @import("SoftDevice.zig");
pub const SoftPhysicalDevice = @import("SoftPhysicalDevice.zig"); pub const SoftPhysicalDevice = @import("SoftPhysicalDevice.zig");
pub const SoftQueue = @import("SoftQueue.zig"); pub const SoftQueue = @import("SoftQueue.zig");
pub const SoftCommandPool = @import("SoftCommandPool.zig");
pub const SoftDeviceMemory = @import("SoftDeviceMemory.zig"); pub const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
pub const SoftFence = @import("SoftFence.zig"); pub const SoftFence = @import("SoftFence.zig");

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 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 Queue = @import("Queue.zig");
const CommandPool = @import("CommandPool.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;
@@ -25,11 +28,13 @@ pub const VTable = struct {
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,
createCommandPool: *const fn (*Self, std.mem.Allocator, *const vk.CommandPoolCreateInfo) VkError!*CommandPool,
createFence: *const fn (*Self, std.mem.Allocator, *const vk.FenceCreateInfo) VkError!*Fence, 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, destroyFence: *const fn (*Self, std.mem.Allocator, *Fence) VkError!void,
freeMemory: *const fn (*Self, std.mem.Allocator, *DeviceMemory) VkError!void, freeMemory: *const fn (*Self, std.mem.Allocator, *DeviceMemory) VkError!void,
getFenceStatus: *const fn (*Self, *Fence) 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, resetFences: *const fn (*Self, []*Fence) VkError!void,
waitForFences: *const fn (*Self, []*Fence, bool, u64) 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(); var it = self.queues.iterator();
while (it.next()) |entry| { while (it.next()) |entry| {
const family = entry.value_ptr; 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); 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 ================================================================================================================================== // Memory functions ==================================================================================================================================
pub inline fn allocateMemory(self: *Self, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*DeviceMemory { 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(); const Self = @This();
pub const ObjectType: vk.ObjectType = .fence; pub const ObjectType: vk.ObjectType = .fence;
owner: *const Device, owner: *Device,
flags: vk.FenceCreateFlags, flags: vk.FenceCreateFlags,
vtable: *const VTable, vtable: *const VTable,
@@ -20,7 +20,8 @@ pub const VTable = struct {
wait: *const fn (*Self, u64) VkError!void, 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 .{ return .{
.owner = device, .owner = device,
.flags = info.flags, .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_type = undefined,
.device_name = [_]u8{0} ** vk.MAX_PHYSICAL_DEVICE_NAME_SIZE, .device_name = [_]u8{0} ** vk.MAX_PHYSICAL_DEVICE_NAME_SIZE,
.pipeline_cache_uuid = undefined, .pipeline_cache_uuid = undefined,
.limits = undefined, .limits = std.mem.zeroInit(vk.PhysicalDeviceLimits, .{}),
.sparse_properties = undefined, .sparse_properties = undefined,
}, },
.mem_props = .{ .mem_props = .{

View File

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

View File

@@ -19,6 +19,7 @@ const Device = @import("Device.zig");
const PhysicalDevice = @import("PhysicalDevice.zig"); const PhysicalDevice = @import("PhysicalDevice.zig");
const Queue = @import("Queue.zig"); const Queue = @import("Queue.zig");
const CommandPool = @import("CommandPool.zig");
const DeviceMemory = @import("DeviceMemory.zig"); const DeviceMemory = @import("DeviceMemory.zig");
const Fence = @import("Fence.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(.{ const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
functionMapEntryPoint("vkAllocateMemory"), functionMapEntryPoint("vkAllocateMemory"),
functionMapEntryPoint("vkCreateCommandPool"),
functionMapEntryPoint("vkCreateFence"),
functionMapEntryPoint("vkDestroyCommandPool"),
functionMapEntryPoint("vkDestroyFence"), functionMapEntryPoint("vkDestroyFence"),
functionMapEntryPoint("vkDestroyDevice"), functionMapEntryPoint("vkDestroyDevice"),
functionMapEntryPoint("vkCreateFence"),
functionMapEntryPoint("vkFreeMemory"), functionMapEntryPoint("vkFreeMemory"),
functionMapEntryPoint("vkGetDeviceQueue"), functionMapEntryPoint("vkGetDeviceQueue"),
functionMapEntryPoint("vkGetFenceStatus"), functionMapEntryPoint("vkGetFenceStatus"),
@@ -291,6 +294,18 @@ pub export fn strollAllocateMemory(p_device: vk.Device, p_info: ?*const vk.Memor
return .success; 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 { 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; const info = p_info orelse return .error_validation_failed;
if (info.s_type != .fence_create_info) { 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); 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 { 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 allocator = VulkanAllocator.init(callbacks, .object).allocator();
const device = Dispatchable(Device).fromHandleObject(p_device) catch return; const device = Dispatchable(Device).fromHandleObject(p_device) catch return;

View File

@@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#define VK_NO_PROTOTYPES #define VK_NO_PROTOTYPES
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
@@ -16,6 +15,11 @@
#define VOLK_IMPLEMENTATION #define VOLK_IMPLEMENTATION
#include <volk.h> #include <volk.h>
#define KVF_IMPLEMENTATION
#define KVF_ENABLE_VALIDATION_LAYERS
#define KVF_NO_KHR
#include <kvf.h>
#define CheckVk(x) \ #define CheckVk(x) \
do { \ do { \
if((x) != VK_SUCCESS) \ if((x) != VK_SUCCESS) \
@@ -49,60 +53,25 @@ int main(void)
const char* extensions[] = { VK_LUNARG_DIRECT_DRIVER_LOADING_EXTENSION_NAME }; const char* extensions[] = { VK_LUNARG_DIRECT_DRIVER_LOADING_EXTENSION_NAME };
VkInstanceCreateInfo instance_create_info = {}; VkInstance instance = kvfCreateInstanceNext(extensions, 1, &direct_driver_list);
instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_create_info.pApplicationInfo = NULL;
instance_create_info.enabledExtensionCount = 1;
instance_create_info.ppEnabledExtensionNames = extensions;
instance_create_info.pNext = &direct_driver_list;
VkInstance instance = VK_NULL_HANDLE;
CheckVk(vkCreateInstance(&instance_create_info, NULL, &instance));
volkLoadInstance(instance); volkLoadInstance(instance);
uint32_t count; VkPhysicalDevice physical_device = kvfPickGoodPhysicalDevice(instance, VK_NULL_HANDLE, NULL, 0);
vkEnumeratePhysicalDevices(instance, &count, NULL);
VkPhysicalDevice* physical_devices = (VkPhysicalDevice*)calloc(count, sizeof(VkPhysicalDevice));
vkEnumeratePhysicalDevices(instance, &count, physical_devices);
VkPhysicalDeviceProperties props; VkDevice device = kvfCreateDevice(physical_device, NULL, 0, NULL);
vkGetPhysicalDeviceProperties(physical_devices[0], &props);
printf("VkPhysicalDevice name %s\n", props.deviceName);
VkDeviceQueueCreateInfo queue_create_infos = {0};
queue_create_infos.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queue_create_infos.queueFamilyIndex = 1;
queue_create_infos.queueCount = 1;
VkDeviceCreateInfo device_create_info = {0};
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device_create_info.queueCreateInfoCount = 1;
device_create_info.pQueueCreateInfos = &queue_create_infos;
VkDevice device = VK_NULL_HANDLE;
CheckVk(vkCreateDevice(physical_devices[0], &device_create_info, NULL, &device));
volkLoadDevice(device); volkLoadDevice(device);
VkQueue queue = VK_NULL_HANDLE; VkQueue queue = kvfGetDeviceQueue(device, KVF_GRAPHICS_QUEUE);
vkGetDeviceQueue(device, 1, 0, &queue); VkFence fence = kvfCreateFence(device);
VkFenceCreateInfo fence_info = {}; kvfSubmitCommandBuffer(device, VK_NULL_HANDLE, KVF_GRAPHICS_QUEUE, VK_NULL_HANDLE, VK_NULL_HANDLE, fence, NULL);
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; kvfWaitForFence(device, fence);
fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
VkFence fence = VK_NULL_HANDLE;
CheckVk(vkCreateFence(device, &fence_info, NULL, &fence));
CheckVk(vkQueueSubmit(queue, 0, NULL, fence)); kvfDestroyFence(device, fence);
CheckVk(vkQueueSubmit(queue, 0, NULL, fence));
CheckVk(vkQueueSubmit(queue, 0, NULL, fence));
CheckVk(vkQueueWaitIdle(queue));
vkDestroyFence(device, fence, NULL); kvfDestroyDevice(device);
kvfDestroyInstance(instance);
vkDestroyDevice(device, NULL);
vkDestroyInstance(instance, NULL);
free(physical_devices);
dlclose(lib); dlclose(lib);
return 0; return 0;
} }