Fix some synchronization in the example + remove unused import

This commit is contained in:
Robin Voetter
2020-07-11 00:42:20 +02:00
parent b344d97f98
commit 0955d94ac5
2 changed files with 10 additions and 6 deletions

View File

@@ -1,6 +1,5 @@
const std = @import("std"); const std = @import("std");
const vk = @import("vulkan"); const vk = @import("vulkan");
const c = @import("c.zig");
const GraphicsContext = @import("graphics-context.zig").GraphicsContext; const GraphicsContext = @import("graphics-context.zig").GraphicsContext;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
@@ -99,7 +98,15 @@ pub const Swapchain = struct {
self.gc.vkd.destroySemaphore(self.gc.dev, self.next_image_acquired, null); self.gc.vkd.destroySemaphore(self.gc.dev, self.next_image_acquired, null);
} }
pub fn waitForAllFences(self: Swapchain) !void {
for (self.swap_images) |si| {
// Any error result is fatal anyway
_ = try self.gc.vkd.waitForFences(self.gc.dev, 1, @ptrCast([*]const vk.Fence, &si.frame_fence), vk.TRUE, std.math.maxInt(u64));
}
}
pub fn deinit(self: Swapchain) void { pub fn deinit(self: Swapchain) void {
self.waitForAllFences() catch return;
self.deinitExceptSwapchain(); self.deinitExceptSwapchain();
self.gc.vkd.destroySwapchainKHR(self.gc.dev, self.handle, null); self.gc.vkd.destroySwapchainKHR(self.gc.dev, self.handle, null);
} }
@@ -229,10 +236,6 @@ const SwapImage = struct {
} }
fn deinit(self: SwapImage, gc: *const GraphicsContext) void { fn deinit(self: SwapImage, gc: *const GraphicsContext) void {
// Ignore any error (and the result), and still try to delete the other resources.
// If this errors, the error is likely to be triggered elsewhere anyway.
const result = gc.vkd.waitForFences(gc.dev, 1, @ptrCast([*]const vk.Fence, &self.frame_fence), vk.TRUE, std.math.maxInt(u64));
gc.vkd.destroyImageView(gc.dev, self.view, null); gc.vkd.destroyImageView(gc.dev, self.view, null);
gc.vkd.destroySemaphore(gc.dev, self.image_acquired, null); gc.vkd.destroySemaphore(gc.dev, self.image_acquired, null);
gc.vkd.destroySemaphore(gc.dev, self.render_finished, null); gc.vkd.destroySemaphore(gc.dev, self.render_finished, null);

View File

@@ -153,8 +153,9 @@ pub fn main() !void {
c.glfwSwapBuffers(window); c.glfwSwapBuffers(window);
c.glfwPollEvents(); c.glfwPollEvents();
try gc.vkd.queueWaitIdle(gc.graphics_queue.handle);
} }
try swapchain.waitForAllFences();
} }
fn uploadVertices(gc: *const GraphicsContext, pool: vk.CommandPool, buffer: vk.Buffer, memory: vk.DeviceMemory) !void { fn uploadVertices(gc: *const GraphicsContext, pool: vk.CommandPool, buffer: vk.Buffer, memory: vk.DeviceMemory) !void {