comptime topological sort of dependencies
This commit is contained in:
@@ -32,21 +32,11 @@ pub const Config = struct {
|
||||
};
|
||||
const config = nu.config.render;
|
||||
|
||||
pub fn module() nu.Module {
|
||||
return nu.Module{
|
||||
.name = "Render",
|
||||
.setup = setup,
|
||||
.teardown = teardown,
|
||||
.frame = frame,
|
||||
.dependencies = &.{nu.Window.driver().module},
|
||||
};
|
||||
}
|
||||
pub const depends = .{nu.Window};
|
||||
|
||||
var sc: au.SwapChain = undefined;
|
||||
var flights: au.Flights = undefined;
|
||||
|
||||
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);
|
||||
@@ -57,20 +47,16 @@ pub fn setup(alloc: std.mem.Allocator) !void {
|
||||
|
||||
flights = try au.Flights.init(alloc, config.frames_in_flight);
|
||||
errdefer flights.deinit();
|
||||
|
||||
present = @TypeOf(present).init(alloc);
|
||||
errdefer 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 frame() !void {
|
||||
pub fn render(engine: anytype) !void {
|
||||
const flight: au.Flights.Flight = flights.next();
|
||||
try flight.wait();
|
||||
|
||||
@@ -97,9 +83,8 @@ pub fn frame() !void {
|
||||
target.begin_rendering(cmd, render_area);
|
||||
|
||||
// todo manage frame in flight state for each hook; pass the current flight in as context.
|
||||
// will need some comptime -> anytype mapping.
|
||||
|
||||
present.invoke(.{cmd});
|
||||
engine.invoke("present", .{cmd});
|
||||
|
||||
target.end_rendering(cmd);
|
||||
try cmd.endCommandBuffer();
|
||||
|
Reference in New Issue
Block a user