clean up acquire/present
This commit is contained in:
@@ -89,20 +89,24 @@ pub fn rebuild(self: *Self) !bool {
|
|||||||
} }, null);
|
} }, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo repopulate images and synchronization
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getImage(self: Self, idx: u32) vk.Image {
|
pub fn acquire(self: Self, semaphore: vk.Semaphore, fence: vk.Fence) !Target {
|
||||||
return self.images.items[idx];
|
const acq = try au.D.acquireNextImageKHR(self.handle, std.math.maxInt(u64), semaphore, fence);
|
||||||
|
return .{
|
||||||
|
.idx = acq.image_index,
|
||||||
|
.image = self.images.items[acq.image_index],
|
||||||
|
.view = self.views.items[acq.image_index],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getView(self: Self, idx: u32) vk.ImageView {
|
const Target = struct {
|
||||||
return self.views.items[idx];
|
idx: u32,
|
||||||
}
|
image: vk.Image,
|
||||||
|
view: vk.ImageView,
|
||||||
|
|
||||||
pub fn beginRendering(self: Self, cmd: au.CommandBufferProxy, area: vk.Rect2D, idx: u32) void {
|
pub fn begin_rendering(self: Target, cmd: au.CommandBufferProxy, area: vk.Rect2D) void {
|
||||||
cmd.pipelineBarrier(
|
cmd.pipelineBarrier(
|
||||||
.{ .top_of_pipe_bit = true },
|
.{ .top_of_pipe_bit = true },
|
||||||
.{ .color_attachment_output_bit = true },
|
.{ .color_attachment_output_bit = true },
|
||||||
@@ -120,7 +124,7 @@ pub fn beginRendering(self: Self, cmd: au.CommandBufferProxy, area: vk.Rect2D, i
|
|||||||
.new_layout = .color_attachment_optimal,
|
.new_layout = .color_attachment_optimal,
|
||||||
.src_queue_family_index = 0,
|
.src_queue_family_index = 0,
|
||||||
.dst_queue_family_index = 0,
|
.dst_queue_family_index = 0,
|
||||||
.image = self.getImage(idx),
|
.image = self.image,
|
||||||
.subresource_range = .{
|
.subresource_range = .{
|
||||||
.aspect_mask = .{ .color_bit = true },
|
.aspect_mask = .{ .color_bit = true },
|
||||||
.base_mip_level = 0,
|
.base_mip_level = 0,
|
||||||
@@ -139,7 +143,7 @@ pub fn beginRendering(self: Self, cmd: au.CommandBufferProxy, area: vk.Rect2D, i
|
|||||||
.color_attachment_count = 1,
|
.color_attachment_count = 1,
|
||||||
.p_color_attachments = &.{
|
.p_color_attachments = &.{
|
||||||
vk.RenderingAttachmentInfo{
|
vk.RenderingAttachmentInfo{
|
||||||
.image_view = self.getView(idx),
|
.image_view = self.view,
|
||||||
.image_layout = .color_attachment_optimal,
|
.image_layout = .color_attachment_optimal,
|
||||||
.resolve_mode = .{},
|
.resolve_mode = .{},
|
||||||
.resolve_image_view = .null_handle,
|
.resolve_image_view = .null_handle,
|
||||||
@@ -150,9 +154,9 @@ pub fn beginRendering(self: Self, cmd: au.CommandBufferProxy, area: vk.Rect2D, i
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn endRendering(self: Self, cmd: au.CommandBufferProxy, idx: u32) void {
|
pub fn end_rendering(self: Target, cmd: au.CommandBufferProxy) void {
|
||||||
cmd.endRendering();
|
cmd.endRendering();
|
||||||
|
|
||||||
cmd.pipelineBarrier(
|
cmd.pipelineBarrier(
|
||||||
@@ -172,7 +176,7 @@ pub fn endRendering(self: Self, cmd: au.CommandBufferProxy, idx: u32) void {
|
|||||||
.new_layout = .present_src_khr,
|
.new_layout = .present_src_khr,
|
||||||
.src_queue_family_index = 0,
|
.src_queue_family_index = 0,
|
||||||
.dst_queue_family_index = 0,
|
.dst_queue_family_index = 0,
|
||||||
.image = self.getImage(idx),
|
.image = self.image,
|
||||||
.subresource_range = .{
|
.subresource_range = .{
|
||||||
.aspect_mask = .{ .color_bit = true },
|
.aspect_mask = .{ .color_bit = true },
|
||||||
.base_mip_level = 0,
|
.base_mip_level = 0,
|
||||||
@@ -183,4 +187,16 @@ pub fn endRendering(self: Self, cmd: au.CommandBufferProxy, idx: u32) void {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn present(self: Self, wait_semaphores: []const vk.Semaphore, target: Target) !vk.Result {
|
||||||
|
return try au.Q.presentKHR(&vk.PresentInfoKHR{
|
||||||
|
.wait_semaphore_count = @intCast(wait_semaphores.len),
|
||||||
|
.p_wait_semaphores = wait_semaphores.ptr,
|
||||||
|
.swapchain_count = 1,
|
||||||
|
.p_swapchains = &.{self.handle},
|
||||||
|
.p_image_indices = &.{target.idx},
|
||||||
|
.p_results = null,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
20
src/main.zig
20
src/main.zig
@@ -248,12 +248,7 @@ pub fn main() !void {
|
|||||||
try au.D.resetFences(1, &.{flight.fence});
|
try au.D.resetFences(1, &.{flight.fence});
|
||||||
try au.D.resetCommandPool(flight.pool, .{});
|
try au.D.resetCommandPool(flight.pool, .{});
|
||||||
|
|
||||||
const acq = try au.D.acquireNextImageKHR(
|
const tgt = try sc.acquire(flight.acquire, .null_handle);
|
||||||
sc.handle,
|
|
||||||
std.math.maxInt(u64),
|
|
||||||
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 } });
|
||||||
@@ -263,7 +258,7 @@ pub fn main() !void {
|
|||||||
.extent = sc.cinfo.image_extent,
|
.extent = sc.cinfo.image_extent,
|
||||||
};
|
};
|
||||||
|
|
||||||
sc.beginRendering(cmd, render_area, acq.image_index);
|
tgt.begin_rendering(cmd, render_area);
|
||||||
record_render(
|
record_render(
|
||||||
cmd,
|
cmd,
|
||||||
uber,
|
uber,
|
||||||
@@ -273,7 +268,7 @@ pub fn main() !void {
|
|||||||
descriptorSet,
|
descriptorSet,
|
||||||
);
|
);
|
||||||
im.c.ImGui_ImplVulkan_RenderDrawData(im.c.igGetDrawData(), @ptrFromInt(@intFromEnum(cmd.handle)), null);
|
im.c.ImGui_ImplVulkan_RenderDrawData(im.c.igGetDrawData(), @ptrFromInt(@intFromEnum(cmd.handle)), null);
|
||||||
sc.endRendering(cmd, acq.image_index);
|
tgt.end_rendering(cmd);
|
||||||
|
|
||||||
for (vertex_data) |*v| {
|
for (vertex_data) |*v| {
|
||||||
for (v.pos[0..2]) |*f| {
|
for (v.pos[0..2]) |*f| {
|
||||||
@@ -304,14 +299,7 @@ pub fn main() !void {
|
|||||||
@panic("Submission failed");
|
@panic("Submission failed");
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = try au.Q.presentKHR(&vk.PresentInfoKHR{
|
_ = try sc.present(&.{flight.complete}, tgt); // todo suboptimal?
|
||||||
.wait_semaphore_count = 1,
|
|
||||||
.p_wait_semaphores = &.{flight.complete},
|
|
||||||
.swapchain_count = 1,
|
|
||||||
.p_swapchains = &.{sc.handle},
|
|
||||||
.p_image_indices = &.{acq.image_index},
|
|
||||||
.p_results = null,
|
|
||||||
}); // todo suboptimal?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try au.D.deviceWaitIdle();
|
try au.D.deviceWaitIdle();
|
||||||
|
Reference in New Issue
Block a user