wip polymorphic modules
This commit is contained in:
@@ -9,9 +9,7 @@ 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 {
|
||||
pub const Config = struct {
|
||||
app_name: [*:0]const u8 = "nu-au-app",
|
||||
app_version: struct {
|
||||
variant: u3 = 0,
|
||||
@@ -27,20 +25,29 @@ pub const Options = struct {
|
||||
patch: u12 = 0,
|
||||
} = .{},
|
||||
frames_in_flight: u8 = 3,
|
||||
use_debug_messenger: bool = switch (builtin.mode) {
|
||||
.Debug, .ReleaseSafe => true,
|
||||
.ReleaseSmall, .ReleaseFast => false,
|
||||
},
|
||||
};
|
||||
const config = nu.config.render;
|
||||
|
||||
pub const Hooks = struct {
|
||||
pub const Present = Hook(fn (au.CommandBufferProxy) void);
|
||||
|
||||
present: Present,
|
||||
};
|
||||
|
||||
pub var hooks: Hooks = undefined;
|
||||
pub fn module() nu.Module {
|
||||
return nu.Module{
|
||||
.name = "Render",
|
||||
.setup = setup,
|
||||
.teardown = teardown,
|
||||
.frame = frame,
|
||||
.dependencies = &.{nu.Window.driver().module},
|
||||
};
|
||||
}
|
||||
|
||||
var sc: au.SwapChain = undefined;
|
||||
var flights: au.Flights = undefined;
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) !void {
|
||||
pub var present: nu.Hook(fn (au.CommandBufferProxy) void) = undefined;
|
||||
|
||||
pub fn setup(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();
|
||||
@@ -48,26 +55,22 @@ pub fn init(alloc: std.mem.Allocator) !void {
|
||||
sc = try au.SwapChain.init(alloc);
|
||||
errdefer sc.deinit();
|
||||
|
||||
flights = try au.Flights.init(alloc, nu.options.render.frames_in_flight);
|
||||
flights = try au.Flights.init(alloc, config.frames_in_flight);
|
||||
errdefer flights.deinit();
|
||||
|
||||
hooks = .{ .present = Hooks.Present.init(alloc) };
|
||||
errdefer hooks.present.deinit();
|
||||
present = @TypeOf(present).init(alloc);
|
||||
errdefer present.deinit();
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
hooks.present.deinit();
|
||||
pub fn teardown() void {
|
||||
au.D.deviceWaitIdle() catch |err| std.debug.panic("Device wait failed: {!}", .{err});
|
||||
errdefer 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 {
|
||||
pub fn frame() !void {
|
||||
const flight: au.Flights.Flight = flights.next();
|
||||
try flight.wait();
|
||||
|
||||
@@ -95,7 +98,8 @@ 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.
|
||||
hooks.present.invoke(.{cmd});
|
||||
|
||||
present.invoke(.{cmd});
|
||||
|
||||
target.end_rendering(cmd);
|
||||
try cmd.endCommandBuffer();
|
||||
@@ -126,9 +130,3 @@ pub fn nu_frame() !void {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nu_close() void {
|
||||
au.D.deviceWaitIdle() catch |err| {
|
||||
std.debug.panic("Device wait failed: {!}", .{err});
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user