zig-chess/src/vulkan/render_pass.zig

67 lines
2.0 KiB
Zig

const std = @import("std");
const log = std.log.scoped(.graphics);
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);
log.debug("created render pass", .{});
return .{ .render_pass = render_pass };
}