Refactor Vulkan setup phase 3

This commit is contained in:
2026-05-15 12:39:32 -08:00
parent 6e18542b2b
commit ed1b9db61e
12 changed files with 860 additions and 651 deletions
+65
View File
@@ -0,0 +1,65 @@
const std = @import("std");
const vk = @import("vulkan");
const device = @import("device.zig");
pub const RenderPassContext = struct {
render_pass: vk.RenderPass,
pub fn destroy(self: *const RenderPassContext, ldc: *const device.LogicalDeviceContext) void {
ldc.vkd.destroyRenderPass(ldc.device, self.render_pass, null);
}
};
pub fn initRenderPass(ldc: device.LogicalDeviceContext, format: vk.Format) !RenderPassContext {
const color_attachment = vk.AttachmentDescription{
.format = format,
.samples = .{ .@"1_bit" = true },
.load_op = .clear,
.store_op = .store,
.stencil_load_op = .dont_care,
.stencil_store_op = .dont_care,
.initial_layout = .undefined,
.final_layout = .present_src_khr,
};
const color_attachment_ref = vk.AttachmentReference{
.attachment = 0,
.layout = .color_attachment_optimal,
};
const subpass = vk.SubpassDescription{
.pipeline_bind_point = .graphics,
.color_attachment_count = 1,
.p_color_attachments = @ptrCast(&color_attachment_ref),
};
const subpass_dependency = vk.SubpassDependency{
.src_subpass = vk.SUBPASS_EXTERNAL,
.dst_subpass = 0,
.src_stage_mask = .{
.color_attachment_output_bit = true,
},
.src_access_mask = .{},
.dst_stage_mask = .{
.color_attachment_output_bit = true,
},
.dst_access_mask = .{
.color_attachment_write_bit = true,
},
};
const render_pass_create_info = vk.RenderPassCreateInfo{
.attachment_count = 1,
.p_attachments = @ptrCast(&color_attachment),
.subpass_count = 1,
.p_subpasses = @ptrCast(&subpass),
.dependency_count = 1,
.p_dependencies = @ptrCast(&subpass_dependency),
};
const render_pass = try ldc.vkd.createRenderPass(ldc.device, &render_pass_create_info, null);
std.debug.print("created render pass\n", .{});
return .{ .render_pass = render_pass };
}