good but wrong teardown order; device wait idle

This commit is contained in:
David Allemang
2024-07-09 16:09:22 -04:00
parent 59912a4bc6
commit 2bb3b71b2b
5 changed files with 133 additions and 9 deletions

View File

@@ -30,11 +30,33 @@ pub const Options = struct {
var sc: au.SwapChain = undefined;
var flights: au.Flights = undefined;
const PresentCallback = *const fn (au.CommandBufferProxy) void;
var present_callbacks: std.ArrayList(PresentCallback) = undefined;
pub fn add_present_callback(cb: PresentCallback) !void {
if (std.mem.indexOfScalar(PresentCallback, present_callbacks.items, cb)) |_| {
return;
} else {
try present_callbacks.append(cb);
}
}
pub fn remove_present_callback(cb: PresentCallback) void {
if (std.mem.indexOfScalar(PresentCallback, present_callbacks.items, cb)) |idx| {
_ = present_callbacks.orderedRemove(idx);
} else {
return;
}
}
pub fn init(alloc: std.mem.Allocator) !void {
// todo pick apart au into helpers; not a sub-module filled with its own globals.
try au.init(alloc);
errdefer au.deinit();
present_callbacks = std.ArrayList(PresentCallback).init(alloc);
errdefer present_callbacks.deinit();
sc = try au.SwapChain.init(alloc);
errdefer sc.deinit();
@@ -67,6 +89,9 @@ pub fn frame() !void {
try cmd.beginCommandBuffer(&.{ .flags = .{ .one_time_submit_bit = true } });
target.begin_rendering(cmd, render_area);
for (present_callbacks.items) |cb| {
cb(cmd);
}
target.end_rendering(cmd);
try cmd.endCommandBuffer();
@@ -98,6 +123,7 @@ pub fn frame() !void {
}
pub fn deinit() void {
present_callbacks.deinit();
au.D.deviceWaitIdle() catch {};
flights.deinit();
sc.deinit();