starting to test swapchain

This commit is contained in:
David Allemang
2024-06-27 14:17:06 -04:00
parent 1c748022de
commit 1f82923f59
4 changed files with 150 additions and 11 deletions

View File

@@ -99,19 +99,86 @@ pub fn main() !void {
try au.init(alloc);
defer au.deinit();
var sc = try au.SwapChain.init(alloc);
defer sc.deinit();
const pool = try au.D.createCommandPool(&.{ .queue_family_index = au.device_config.family }, null);
defer au.D.destroyCommandPool(pool, null);
const fence: vk.Fence = try au.D.createFence(&.{ .flags = .{ .signaled_bit = true } }, null);
defer au.D.destroyFence(fence, null);
const sem_ready: vk.Semaphore = try au.D.createSemaphore(&.{}, null);
defer au.D.destroySemaphore(sem_ready, null);
const sem_done: vk.Semaphore = try au.D.createSemaphore(&.{}, null);
defer au.D.destroySemaphore(sem_done, null);
const cmdbufs: [1]vk.CommandBuffer = undefined;
try au.D.allocateCommandBuffers(
&.{ .command_pool = pool, .command_buffer_count = @intCast(cmdbufs.len), .level = .primary },
cmdbufs.ptr,
);
defer au.D.freeCommandBuffers(pool, @intCast(cmdbufs.len), cmdbufs.ptr);
{
const cmd = au.CommandBufferProxy.init(cmdbufs[0], au.D);
const clear = vk.ClearValue{ .color = .{ .float_32 = .{ 0, 0, 0, 1 } } };
const viewport = vk.Viewport{
.x = 0,
.y = 0,
.width = sc.cinfo.image_extent.width,
.height = sc.cinfo.image_extent.height,
.min_depth = 0,
.max_depth = 1,
};
const scissor = vk.Rect2D{ .offset = .{ .x = 0, .y = 0 }, .extent = sc.cinfo.image_extent };
try cmd.beginCommandBuffer(&.{});
cmd.pipelineBarrier(
.{ .top_of_pipe_bit = true },
.{ .color_attachment_output_bit = true },
.{},
0,
null,
0,
null,
1,
@ptrCast(&vk.ImageMemoryBarrier{
.src_access_mask = .{},
.dst_access_mask = .{ .color_attachment_write_bit = true },
.old_layout = .undefined,
.new_layout = .color_attachment_optimal,
.src_queue_family_index = 0,
.dst_queue_family_index = 0,
.image = .null_handle, // todo this needs to point to the swapchain image, so I can't get away from recording a command buffer for each one.
}),
);
}
while (!au.W.should_close()) {
// todo switch mode depending on if window is focused
const events = au.wait_events_timeout(0.10);
for (events) |u| switch (u) {
.cursorPos,
.windowPos,
.windowSize,
.framebufferSize,
.windowRefresh,
=> {},
.framebufferSize => sc.mark(),
.cursorPos, .windowPos, .windowSize, .windowRefresh => {},
else => |e| std.debug.print("{any}\n", .{e}),
};
_ = try sc.rebuild();
const acq = try au.D.acquireNextImageKHR(sc.handle, std.math.maxInt(u64), sem_ready, .null_handle);
const pre = try au.Q.presentKHR(&vk.PresentInfoKHR{
.wait_semaphore_count = 1,
.p_wait_semaphores = &.{sem_done},
.swapchain_count = 1,
.p_swapchains = &.{sc.handle},
.p_image_indices = &.{acq.image_index},
.p_results = null,
});
std.debug.print("present result: {}\n", .{pre});
}
try au.D.deviceWaitIdle();