working on events

This commit is contained in:
2025-12-14 23:11:35 +01:00
parent 86e1e8ab6c
commit bbd21e55de
5 changed files with 136 additions and 33 deletions

View File

@@ -28,6 +28,9 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
.end = end,
.fillBuffer = fillBuffer,
.reset = reset,
.resetEvent = resetEvent,
.setEvent = setEvent,
.waitEvents = waitEvents,
};
self.* = .{
@@ -93,3 +96,28 @@ pub fn copyImage(interface: *Interface, src: *base.Image, dst: *base.Image, regi
_ = dst;
_ = regions;
}
pub fn resetEvent(interface: *Interface, event: *base.Event, stage: vk.PipelineStageFlags) VkError!void {
// No-op
_ = interface;
_ = event;
_ = stage;
}
pub fn setEvent(interface: *Interface, event: *base.Event, stage: vk.PipelineStageFlags) VkError!void {
// No-op
_ = interface;
_ = event;
_ = stage;
}
pub fn waitEvents(interface: *Interface, events: []*const base.Event, src_stage: vk.PipelineStageFlags, dst_stage: vk.PipelineStageFlags, memory_barriers: []const vk.MemoryBarrier, buffer_barriers: []const vk.BufferMemoryBarrier, image_barriers: []const vk.ImageMemoryBarrier) VkError!void {
// No-op
_ = interface;
_ = events;
_ = src_stage;
_ = dst_stage;
_ = memory_barriers;
_ = buffer_barriers;
_ = image_barriers;
}

View File

@@ -9,6 +9,9 @@ const Self = @This();
pub const Interface = base.Event;
interface: Interface,
mutex: std.Thread.Mutex,
condition: std.Thread.Condition,
is_signaled: bool,
pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const vk.EventCreateInfo) VkError!*Self {
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
@@ -18,10 +21,17 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
interface.vtable = &.{
.destroy = destroy,
.getStatus = getStatus,
.reset = reset,
.signal = signal,
.wait = wait,
};
self.* = .{
.interface = interface,
.mutex = std.Thread.Mutex{},
.condition = std.Thread.Condition{},
.is_signaled = false,
};
return self;
}
@@ -30,3 +40,49 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
allocator.destroy(self);
}
pub fn getStatus(interface: *Interface) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.mutex.lock();
defer self.mutex.unlock();
if (!self.is_signaled) {
return VkError.EventReset;
}
}
pub fn reset(interface: *Interface) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.mutex.lock();
defer self.mutex.unlock();
self.is_signaled = false;
}
pub fn signal(interface: *Interface) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.mutex.lock();
defer self.mutex.unlock();
self.is_signaled = true;
self.condition.broadcast();
}
pub fn wait(interface: *Interface, timeout: u64) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
self.mutex.lock();
defer self.mutex.unlock();
if (self.is_signaled) return;
if (timeout == 0) return VkError.Timeout;
if (timeout == std.math.maxInt(@TypeOf(timeout))) {
self.condition.wait(&self.mutex);
} else {
self.condition.timedWait(&self.mutex, timeout) catch return VkError.Timeout;
}
}