forked from mirror/vulkan-zig
Move fence waiting to SwapImage
This commit is contained in:
@@ -99,14 +99,10 @@ pub const Swapchain = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn waitForAllFences(self: Swapchain) !void {
|
pub fn waitForAllFences(self: Swapchain) !void {
|
||||||
for (self.swap_images) |si| {
|
for (self.swap_images) |si| si.waitForFence(self.gc) catch {};
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
@@ -147,9 +143,8 @@ pub const Swapchain = struct {
|
|||||||
|
|
||||||
// Step 1: Make sure the current frame has finished rendering
|
// Step 1: Make sure the current frame has finished rendering
|
||||||
const current = self.currentSwapImage();
|
const current = self.currentSwapImage();
|
||||||
const fence_ptr = @ptrCast([*]const vk.Fence, ¤t.frame_fence);
|
try current.waitForFence(self.gc);
|
||||||
_ = try self.gc.vkd.waitForFences(self.gc.dev, 1, fence_ptr, vk.TRUE, std.math.maxInt(u64));
|
try self.gc.vkd.resetFences(self.gc.dev, 1, @ptrCast([*]const vk.Fence, ¤t.frame_fence));
|
||||||
try self.gc.vkd.resetFences(self.gc.dev, 1, fence_ptr);
|
|
||||||
|
|
||||||
// Step 2: Submit the command buffer
|
// Step 2: Submit the command buffer
|
||||||
const wait_stage = [_]vk.PipelineStageFlags{.{.top_of_pipe_bit = true}};
|
const wait_stage = [_]vk.PipelineStageFlags{.{.top_of_pipe_bit = true}};
|
||||||
@@ -236,11 +231,16 @@ const SwapImage = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: SwapImage, gc: *const GraphicsContext) void {
|
fn deinit(self: SwapImage, gc: *const GraphicsContext) void {
|
||||||
|
self.waitForFence(gc) catch return;
|
||||||
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);
|
||||||
gc.vkd.destroyFence(gc.dev, self.frame_fence, null);
|
gc.vkd.destroyFence(gc.dev, self.frame_fence, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn waitForFence(self: SwapImage, gc: *const GraphicsContext) !void {
|
||||||
|
_ = try gc.vkd.waitForFences(gc.dev, 1, @ptrCast([*]const vk.Fence, &self.frame_fence), vk.TRUE, std.math.maxInt(u64));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn initSwapchainImages(gc: *const GraphicsContext, swapchain: vk.SwapchainKHR, format: vk.Format, allocator: *Allocator) ![]SwapImage {
|
fn initSwapchainImages(gc: *const GraphicsContext, swapchain: vk.SwapchainKHR, format: vk.Format, allocator: *Allocator) ![]SwapImage {
|
||||||
|
|||||||
Reference in New Issue
Block a user