fix crash in immediate present mode

This commit is contained in:
David Allemang
2024-07-08 17:21:09 -04:00
committed by David Allemang
parent 2f678f273f
commit 1cb340e154
2 changed files with 63 additions and 64 deletions

View File

@@ -240,8 +240,6 @@ const CandidateDeviceInfo = struct {
defer alloc.free(modes); defer alloc.free(modes);
_ = try I.getPhysicalDeviceSurfacePresentModesKHR(pdev, W.surface, &mode_count, modes.ptr); _ = try I.getPhysicalDeviceSurfacePresentModesKHR(pdev, W.surface, &mode_count, modes.ptr);
std.debug.print("Modes ({s}): {any}\n", .{props.device_name, modes});
if (std.mem.indexOfAny(vk.PresentModeKHR, modes, &.{ if (std.mem.indexOfAny(vk.PresentModeKHR, modes, &.{
vk.PresentModeKHR.mailbox_khr, vk.PresentModeKHR.mailbox_khr,
vk.PresentModeKHR.immediate_khr, vk.PresentModeKHR.immediate_khr,

View File

@@ -57,10 +57,6 @@ fn record_render(
cmd.drawIndexed(indices.len, 1, 0, 0, 0); cmd.drawIndexed(indices.len, 1, 0, 0, 0);
} }
pub fn loader_wrapper(procname: [*c]const u8, _: ?*anyopaque) callconv(.C) vk.PfnVoidFunction {
return c.glfwGetInstanceProcAddress(au.I.handle, procname);
}
pub fn main() !void { pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.detectLeaks(); defer _ = gpa.detectLeaks();
@@ -69,14 +65,6 @@ pub fn main() !void {
try au.init(alloc); try au.init(alloc);
defer au.deinit(); defer au.deinit();
{
const props = au.I.getPhysicalDeviceProperties(au.device_config.pdev);
std.debug.print(
"Selected Device:\n {s}\n mode: {}\n",
.{ props.device_name, au.device_config.mode },
);
}
var sc = try au.SwapChain.init(alloc); var sc = try au.SwapChain.init(alloc);
defer sc.deinit(); defer sc.deinit();
@@ -105,7 +93,6 @@ pub fn main() !void {
defer uber.deinit(); defer uber.deinit();
const vkalloc = au.VkAllocator.init(); const vkalloc = au.VkAllocator.init();
std.debug.print("heaps: {any}\ntypes: {any}\n", .{ vkalloc.heaps(), vkalloc.types() });
const vertex_buffer = try au.D.createBuffer(&vk.BufferCreateInfo{ const vertex_buffer = try au.D.createBuffer(&vk.BufferCreateInfo{
.size = @sizeOf(@TypeOf(vertices)), .size = @sizeOf(@TypeOf(vertices)),
@@ -215,14 +202,24 @@ pub fn main() !void {
} }
} }
_ = try sc.rebuild();
_ = try au.D.waitForFences(1, &.{flight.fence}, vk.TRUE, std.math.maxInt(u64)); _ = try au.D.waitForFences(1, &.{flight.fence}, vk.TRUE, std.math.maxInt(u64));
try au.D.resetFences(1, &.{flight.fence}); try au.D.resetFences(1, &.{flight.fence});
// TODO need to check the standard to see what happens to a fence or semaphore on OutOfDateKHR error.
// acquire, submit, and present.
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,
};
try au.D.resetCommandPool(flight.pool, .{}); try au.D.resetCommandPool(flight.pool, .{});
const tgt = try sc.acquire(flight.acquire, .null_handle);
var cmd = au.CommandBufferProxy.init(flight.cmd, au.D.wrapper); var cmd = au.CommandBufferProxy.init(flight.cmd, au.D.wrapper);
try cmd.beginCommandBuffer(&.{ .flags = .{ .one_time_submit_bit = true } }); try cmd.beginCommandBuffer(&.{ .flags = .{ .one_time_submit_bit = true } });
@@ -231,7 +228,7 @@ pub fn main() !void {
.extent = sc.cinfo.image_extent, .extent = sc.cinfo.image_extent,
}; };
tgt.begin_rendering(cmd, render_area); target.begin_rendering(cmd, render_area);
record_render( record_render(
cmd, cmd,
uber, uber,
@@ -241,7 +238,7 @@ pub fn main() !void {
descriptorSet, descriptorSet,
); );
ui.Draw(cmd); ui.Draw(cmd);
tgt.end_rendering(cmd); target.end_rendering(cmd);
for (vertex_data) |*v| { for (vertex_data) |*v| {
for (v.pos[0..2]) |*f| { for (v.pos[0..2]) |*f| {
@@ -251,7 +248,7 @@ pub fn main() !void {
try cmd.endCommandBuffer(); try cmd.endCommandBuffer();
au.Q.submit( try au.Q.submit(
1, 1,
&.{ &.{
vk.SubmitInfo{ vk.SubmitInfo{
@@ -265,14 +262,18 @@ pub fn main() !void {
}, },
}, },
flight.fence, flight.fence,
) catch { );
std.debug.print("Failed to submit.\nWaiting for idle...", .{});
au.D.deviceWaitIdle() catch
std.debug.print("deviceWaitIdle failed\n", .{});
@panic("Submission failed");
};
_ = try sc.present(&.{flight.complete}, tgt); // todo suboptimal? if (sc.present(&.{flight.complete}, target)) |_| {
break;
} else |err| switch (err) {
error.OutOfDateKHR => {
sc.mark();
continue;
},
else => return err,
}
}
} }
try au.D.deviceWaitIdle(); try au.D.deviceWaitIdle();