render with swapchain
This commit is contained in:
@@ -6,6 +6,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const vk = @import("vk");
|
||||
|
||||
const nu = @import("../nu.zig");
|
||||
const au = @import("Render/au.zig");
|
||||
|
||||
pub const Options = struct {
|
||||
@@ -26,15 +27,79 @@ pub const Options = struct {
|
||||
frames_in_flight: u8 = 3,
|
||||
};
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) !void {
|
||||
// todo make ctx not globals
|
||||
var sc: au.SwapChain = undefined;
|
||||
var flights: au.Flights = undefined;
|
||||
|
||||
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();
|
||||
|
||||
sc = try au.SwapChain.init(alloc);
|
||||
errdefer sc.deinit();
|
||||
|
||||
flights = try au.Flights.init(alloc, nu.options.render.frames_in_flight);
|
||||
errdefer flights.deinit();
|
||||
}
|
||||
|
||||
pub fn frame() void {}
|
||||
pub fn frame() !void {
|
||||
const flight: au.Flights.Flight = flights.next();
|
||||
try flight.wait();
|
||||
|
||||
while (true) {
|
||||
_ = try sc.rebuild();
|
||||
|
||||
const target = sc.acquire(flight.acquire, .null_handle) catch |err| switch (err) {
|
||||
error.OutOfDateKHR => {
|
||||
sc.mark();
|
||||
continue;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
|
||||
const render_area: vk.Rect2D = .{
|
||||
.offset = .{ .x = 0, .y = 0 },
|
||||
.extent = sc.cinfo.image_extent,
|
||||
};
|
||||
|
||||
try au.D.resetCommandPool(flight.pool, .{});
|
||||
var cmd = au.CommandBufferProxy.init(flight.cmd, au.D.wrapper);
|
||||
|
||||
try cmd.beginCommandBuffer(&.{ .flags = .{ .one_time_submit_bit = true } });
|
||||
target.begin_rendering(cmd, render_area);
|
||||
target.end_rendering(cmd);
|
||||
try cmd.endCommandBuffer();
|
||||
|
||||
try au.Q.submit(1, &.{
|
||||
vk.SubmitInfo{
|
||||
.wait_semaphore_count = 1,
|
||||
.p_wait_semaphores = &.{flight.acquire},
|
||||
.p_wait_dst_stage_mask = &.{
|
||||
vk.PipelineStageFlags{ .color_attachment_output_bit = true },
|
||||
},
|
||||
.command_buffer_count = 1,
|
||||
.p_command_buffers = &.{cmd.handle},
|
||||
.signal_semaphore_count = 1,
|
||||
.p_signal_semaphores = &.{flight.complete},
|
||||
},
|
||||
}, flight.fence);
|
||||
|
||||
if (sc.present(&.{flight.complete}, target)) |_| {
|
||||
return;
|
||||
} else |err| switch (err) {
|
||||
error.OutOfDateKHR => {
|
||||
try flight.wait();
|
||||
sc.mark();
|
||||
continue;
|
||||
},
|
||||
else => return err,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
au.D.deviceWaitIdle() catch {};
|
||||
flights.deinit();
|
||||
sc.deinit();
|
||||
au.deinit();
|
||||
}
|
||||
|
Reference in New Issue
Block a user