[Flint] implementing fences and improving image/buffer copy
Test / build_and_test (push) Successful in 5m6s
Build / build (push) Successful in 6m59s

This commit is contained in:
2026-07-13 18:50:13 +02:00
parent 348e8ac66e
commit b3c4248cae
12 changed files with 505 additions and 98 deletions
+69 -6
View File
@@ -3,6 +3,9 @@ const vk = @import("vulkan");
const base = @import("base");
const FlintCommandBuffer = @import("FlintCommandBuffer.zig");
const FlintDevice = @import("FlintDevice.zig");
const FlintFence = @import("FlintFence.zig");
const kmd = @import("kmd.zig");
const VkError = base.VkError;
@@ -10,24 +13,35 @@ const Self = @This();
pub const Interface = base.Queue;
interface: Interface,
completion: *FlintFence,
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);
var interface = try Interface.init(allocator, device, index, family_index, flags);
const completion = try FlintFence.create(device, allocator, &.{
.s_type = .fence_create_info,
.p_next = null,
.flags = .{ .signaled_bit = true },
});
errdefer completion.interface.destroy(allocator);
interface.dispatch_table = &.{
.bindSparse = bindSparse,
.submit = submit,
.waitIdle = waitIdle,
};
self.* = .{ .interface = interface };
self.* = .{
.interface = interface,
.completion = completion,
};
return &self.interface;
}
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.completion.interface.destroy(allocator);
allocator.destroy(self);
}
@@ -39,7 +53,20 @@ pub fn bindSparse(interface: *Interface, info: []const vk.BindSparseInfo, fence:
}
pub fn submit(interface: *Interface, infos: []Interface.SubmitInfo, fence: ?*base.Fence) VkError!void {
_ = interface;
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
const device: *FlintDevice = @alignCast(@fieldParentPtr("interface", interface.owner));
var remaining_batches: usize = 0;
for (infos) |info| {
for (info.command_buffers.items) |command_buffer| {
const intel_command_buffer: *FlintCommandBuffer = @alignCast(@fieldParentPtr("interface", command_buffer));
if (intel_command_buffer.batch.items.len != 0) remaining_batches += 1;
}
}
const batch_count = remaining_batches;
try self.completion.interface.reset();
for (infos) |info| {
for (info.wait_semaphores.items) |semaphore| {
try semaphore.wait();
@@ -47,18 +74,54 @@ pub fn submit(interface: *Interface, infos: []Interface.SubmitInfo, fence: ?*bas
for (info.command_buffers.items) |command_buffer| {
const intel_command_buffer: *FlintCommandBuffer = @alignCast(@fieldParentPtr("interface", command_buffer));
try intel_command_buffer.submitGpuBatch();
if (intel_command_buffer.batch.items.len == 0) {
try intel_command_buffer.submitGpuBatch(&.{});
continue;
}
remaining_batches -= 1;
var syncs: [2]kmd.SyncDependency = undefined;
var sync_count: usize = 0;
if (remaining_batches == 0) {
syncs[sync_count] = .{ .handle = self.completion.handle, .signal = true };
sync_count += 1;
if (fence) |base_fence| {
const flint_fence: *FlintFence = @alignCast(@fieldParentPtr("interface", base_fence));
syncs[sync_count] = .{ .handle = flint_fence.handle, .signal = true };
sync_count += 1;
}
}
try intel_command_buffer.submitGpuBatch(syncs[0..sync_count]);
}
for (info.signal_semaphores.items) |semaphore| {
try semaphore.signal();
}
}
if (fence) |value| {
try value.signal();
if (batch_count == 0) {
var syncs: [2]kmd.SyncDependency = undefined;
var sync_count: usize = 1;
syncs[0] = .{ .handle = self.completion.handle, .signal = true };
if (fence) |base_fence| {
const flint_fence: *FlintFence = @alignCast(@fieldParentPtr("interface", base_fence));
syncs[sync_count] = .{ .handle = flint_fence.handle, .signal = true };
sync_count += 1;
}
// A real no-op request preserves queue order: its output fence cannot
// signal ahead of an earlier request that is still running.
try device.kmd.submitBatch(
interface.owner.io(),
interface.host_allocator.allocator(),
&.{},
&.{},
syncs[0..sync_count],
);
}
}
pub fn waitIdle(interface: *Interface) VkError!void {
_ = interface;
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
try self.completion.interface.wait(std.math.maxInt(u64));
}