runtime hooks

This commit is contained in:
David Allemang
2024-07-10 13:06:44 -04:00
parent e297865e93
commit fd1bd9dbf5
6 changed files with 138 additions and 51 deletions

View File

@@ -9,6 +9,8 @@ const vk = @import("vk");
const nu = @import("../nu.zig");
const au = @import("Render/au.zig");
const Hook = @import("hooks.zig").Hook;
pub const Options = struct {
app_name: [*:0]const u8 = "nu-au-app",
app_version: struct {
@@ -27,6 +29,14 @@ pub const Options = struct {
frames_in_flight: u8 = 3,
};
pub const Hooks = struct {
pub const Present = Hook(fn (au.CommandBufferProxy) void);
present: Present,
};
pub var hooks: Hooks = undefined;
var sc: au.SwapChain = undefined;
var flights: au.Flights = undefined;
@@ -40,6 +50,21 @@ pub fn init(alloc: std.mem.Allocator) !void {
flights = try au.Flights.init(alloc, nu.options.render.frames_in_flight);
errdefer flights.deinit();
hooks = .{ .present = Hooks.Present.init(alloc) };
errdefer hooks.present.deinit();
}
pub fn deinit() void {
hooks.present.deinit();
flights.deinit();
sc.deinit();
au.deinit();
}
pub fn connect() !void {
try nu.hooks.frame.register(nu_frame);
try nu.hooks.close.register(nu_close);
}
pub fn nu_frame() !void {
@@ -70,7 +95,7 @@ pub fn nu_frame() !void {
// todo manage frame in flight state for each hook; pass the current flight in as context.
// will need some comptime -> anytype mapping.
try nu.invoke_hook("nu_render_present", .{cmd});
hooks.present.invoke(.{cmd});
target.end_rendering(cmd);
try cmd.endCommandBuffer();
@@ -102,12 +127,8 @@ pub fn nu_frame() !void {
}
}
pub fn nu_close() !void {
try au.D.deviceWaitIdle();
}
pub fn deinit() void {
flights.deinit();
sc.deinit();
au.deinit();
pub fn nu_close() void {
au.D.deviceWaitIdle() catch |err| {
std.debug.panic("Device wait failed: {!}", .{err});
};
}