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);
|
var sc = try au.SwapChain.init(alloc);
|
||||||
defer sc.deinit();
|
defer sc.deinit();
|
||||||
|
|
||||||
var flight = std.MultiArrayList(struct {
|
const flight = try alloc.alloc(
|
||||||
acquire: vk.Semaphore,
|
struct {
|
||||||
complete: vk.Semaphore,
|
acquire: vk.Semaphore = .null_handle,
|
||||||
fence: vk.Fence,
|
complete: vk.Semaphore = .null_handle,
|
||||||
pool: vk.CommandPool,
|
fence: vk.Fence = .null_handle,
|
||||||
}){};
|
pool: vk.CommandPool = .null_handle,
|
||||||
defer {
|
},
|
||||||
for (flight.items(.acquire)) |sem| {
|
3, // FRAMES IN FLIGHT
|
||||||
au.D.destroySemaphore(sem, null);
|
);
|
||||||
}
|
defer alloc.free(flight);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
try flight.resize(alloc, 3); // FRAMES IN FLIGHT
|
for (flight) |*frame| {
|
||||||
for (flight.items(.acquire)) |*sem| {
|
frame.acquire = try au.D.createSemaphore(&.{}, null);
|
||||||
sem.* = try au.D.createSemaphore(&.{}, null);
|
frame.complete = try au.D.createSemaphore(&.{}, null);
|
||||||
}
|
frame.fence = try au.D.createFence(&.{ .flags = .{ .signaled_bit = true } }, null);
|
||||||
for (flight.items(.complete)) |*sem| {
|
frame.pool = try au.D.createCommandPool(&.{ .queue_family_index = au.device_config.family }, null);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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;
|
var flight_idx: usize = 0;
|
||||||
while (!au.W.should_close()) : (flight_idx = (flight_idx + 1) % flight.len) {
|
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
|
// todo switch mode depending on if window is focused
|
||||||
const events = au.wait_events_timeout(0.10);
|
const events = au.wait_events_timeout(0.10);
|
||||||
|
Reference in New Issue
Block a user