improving vulkan allocator; ci skip
This commit is contained in:
2
.github/workflows/Build.yml
vendored
2
.github/workflows/Build.yml
vendored
@@ -9,6 +9,8 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: mlugg/setup-zig@v2
|
||||
|
||||
2
.github/workflows/Test.yml
vendored
2
.github/workflows/Test.yml
vendored
@@ -9,6 +9,8 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: mlugg/setup-zig@v2
|
||||
|
||||
@@ -2,6 +2,7 @@ const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
const CommandBuffer = @import("CommandBuffer.zig");
|
||||
const Device = @import("Device.zig");
|
||||
|
||||
@@ -15,6 +16,7 @@ flags: vk.CommandPoolCreateFlags,
|
||||
queue_family_index: u32,
|
||||
buffers: std.ArrayList(*CommandBuffer),
|
||||
first_free_buffer_index: usize,
|
||||
host_allocator: VulkanAllocator,
|
||||
|
||||
vtable: *const VTable,
|
||||
|
||||
@@ -30,6 +32,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Comma
|
||||
.flags = info.flags,
|
||||
.queue_family_index = info.queue_family_index,
|
||||
.buffers = .initCapacity(allocator, BUFFER_POOL_BASE_CAPACITY) catch return VkError.OutOfHostMemory,
|
||||
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
||||
.first_free_buffer_index = 0,
|
||||
.vtable = undefined,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ pub const ObjectType: vk.ObjectType = .device;
|
||||
|
||||
physical_device: *const PhysicalDevice,
|
||||
queues: std.AutoArrayHashMapUnmanaged(u32, std.ArrayList(*Dispatchable(Queue))),
|
||||
host_allocator: *VulkanAllocator,
|
||||
host_allocator: VulkanAllocator,
|
||||
|
||||
dispatch_table: *const DispatchTable,
|
||||
vtable: *const VTable,
|
||||
@@ -45,7 +45,7 @@ pub fn init(allocator: std.mem.Allocator, physical_device: *const PhysicalDevice
|
||||
return .{
|
||||
.physical_device = physical_device,
|
||||
.queues = .empty,
|
||||
.host_allocator = @ptrCast(@alignCast(allocator.ptr)),
|
||||
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
||||
.dispatch_table = undefined,
|
||||
.vtable = undefined,
|
||||
};
|
||||
@@ -110,6 +110,10 @@ pub inline fn waitForFences(self: *Self, fences: []*Fence, waitForAll: bool, tim
|
||||
|
||||
// Command Pool functions ============================================================================================================================
|
||||
|
||||
pub inline fn allocateCommandBuffers(self: *Self, info: *const vk.CommandPoolCreateInfo) VkError![]*CommandBuffer {
|
||||
return self.dispatch_table.createCommandPool(self, allocator, info);
|
||||
}
|
||||
|
||||
pub inline fn createCommandPool(self: *Self, allocator: std.mem.Allocator, info: *const vk.CommandPoolCreateInfo) VkError!*CommandPool {
|
||||
return self.dispatch_table.createCommandPool(self, allocator, info);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,22 @@ pub fn allocator(self: *const Self) Allocator {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn from(a: Allocator) *Self {
|
||||
const self: *Self = @ptrCast(@alignCast(a.ptr));
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn clone(self: *Self) Self {
|
||||
return self.cloneWithScope(self.scope);
|
||||
}
|
||||
|
||||
pub fn cloneWithScope(self: *Self, scope: vk.SystemAllocationScope) Self {
|
||||
return .{
|
||||
.callbacks = self.callbacks,
|
||||
.scope = scope,
|
||||
};
|
||||
}
|
||||
|
||||
fn alloc(context: *anyopaque, len: usize, alignment: Alignment, ret_addr: usize) ?[*]u8 {
|
||||
const self: *Self = @ptrCast(@alignCast(context));
|
||||
if (self.callbacks.?.pfn_allocation) |pfn_allocation| {
|
||||
|
||||
@@ -73,6 +73,7 @@ const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComp
|
||||
});
|
||||
|
||||
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapEntryPoint("vkAllocateCommandBuffers"),
|
||||
functionMapEntryPoint("vkAllocateMemory"),
|
||||
functionMapEntryPoint("vkCreateCommandPool"),
|
||||
functionMapEntryPoint("vkCreateFence"),
|
||||
@@ -282,6 +283,17 @@ pub export fn strollGetPhysicalDeviceSparseImageFormatProperties(
|
||||
|
||||
// Device functions ==========================================================================================================================================
|
||||
|
||||
pub export fn strollAllocateCommandBuffers(p_device: vk.Device, p_info: ?*const vk.CommandBufferAllocateInfo, p_cmds: [*]vk.CommandBuffer) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const info = p_info orelse return .error_validation_failed;
|
||||
if (info.s_type != .command_buffer_allocate_info) {
|
||||
return .error_validation_failed;
|
||||
}
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
|
||||
const cmds = device.allocateCommandBuffers(info) catch |err| return toVkResult(err);
|
||||
@memcpy(p_cmds[0..info.command_buffer_count], cmds[0..info.command_buffer_count]);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollAllocateMemory(p_device: vk.Device, p_info: ?*const vk.MemoryAllocateInfo, callbacks: ?*const vk.AllocationCallbacks, p_memory: *vk.DeviceMemory) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
const info = p_info orelse return .error_validation_failed;
|
||||
if (info.s_type != .memory_allocate_info) {
|
||||
|
||||
Reference in New Issue
Block a user