simplify frames in flight struct
This commit is contained in:
56
src/main.zig
56
src/main.zig
@@ -61,45 +61,33 @@ pub fn main() !void {
|
||||
var sc = try au.SwapChain.init(alloc);
|
||||
defer sc.deinit();
|
||||
|
||||
var flight = std.MultiArrayList(struct {
|
||||
acquire: vk.Semaphore,
|
||||
complete: vk.Semaphore,
|
||||
fence: vk.Fence,
|
||||
pool: vk.CommandPool,
|
||||
}){};
|
||||
defer {
|
||||
for (flight.items(.acquire)) |sem| {
|
||||
au.D.destroySemaphore(sem, null);
|
||||
}
|
||||
for (flight.items(.complete)) |sem| {
|
||||
au.D.destroySemaphore(sem, null);
|
||||
}
|
||||
for (flight.items(.fence)) |fnc| {
|
||||
au.D.destroyFence(fnc, null);
|
||||
}
|
||||
for (flight.items(.pool)) |pool| {
|
||||
au.D.destroyCommandPool(pool, null);
|
||||
}
|
||||
flight.deinit(alloc);
|
||||
}
|
||||
const flight = try alloc.alloc(
|
||||
struct {
|
||||
acquire: vk.Semaphore = .null_handle,
|
||||
complete: vk.Semaphore = .null_handle,
|
||||
fence: vk.Fence = .null_handle,
|
||||
pool: vk.CommandPool = .null_handle,
|
||||
},
|
||||
3, // FRAMES IN FLIGHT
|
||||
);
|
||||
defer alloc.free(flight);
|
||||
|
||||
try flight.resize(alloc, 3); // FRAMES IN FLIGHT
|
||||
for (flight.items(.acquire)) |*sem| {
|
||||
sem.* = try au.D.createSemaphore(&.{}, null);
|
||||
}
|
||||
for (flight.items(.complete)) |*sem| {
|
||||
sem.* = try au.D.createSemaphore(&.{}, null);
|
||||
}
|
||||
for (flight.items(.fence)) |*fnc| {
|
||||
fnc.* = try au.D.createFence(&.{ .flags = .{ .signaled_bit = true } }, null);
|
||||
}
|
||||
for (flight.items(.pool)) |*pool| {
|
||||
pool.* = try au.D.createCommandPool(&.{ .queue_family_index = au.device_config.family }, null);
|
||||
for (flight) |*frame| {
|
||||
frame.acquire = try au.D.createSemaphore(&.{}, null);
|
||||
frame.complete = try au.D.createSemaphore(&.{}, null);
|
||||
frame.fence = try au.D.createFence(&.{ .flags = .{ .signaled_bit = true } }, null);
|
||||
frame.pool = try au.D.createCommandPool(&.{ .queue_family_index = au.device_config.family }, null);
|
||||
}
|
||||
defer for (flight) |frame| {
|
||||
au.D.destroySemaphore(frame.acquire, null);
|
||||
au.D.destroySemaphore(frame.complete, null);
|
||||
au.D.destroyFence(frame.fence, null);
|
||||
au.D.destroyCommandPool(frame.pool, null);
|
||||
};
|
||||
|
||||
var flight_idx: usize = 0;
|
||||
while (!au.W.should_close()) : (flight_idx = (flight_idx + 1) % flight.len) {
|
||||
const frame = flight.get(flight_idx);
|
||||
const frame = flight[flight_idx];
|
||||
|
||||
// todo switch mode depending on if window is focused
|
||||
const events = au.wait_events_timeout(0.10);
|
||||
|
Reference in New Issue
Block a user