Remove legacy render passes and frambebuffers in favor of dynamic rendering

Somehow, some way, we ended up with net positive lines changed
This commit is contained in:
2026-05-13 17:28:16 +02:00
parent e736c0df34
commit 36434f8107
6 changed files with 231 additions and 219 deletions

View File

@@ -22,6 +22,7 @@ const Player = @import("Player.zig");
const Skybox = @import("engine/Skybox.zig");
const StagingBuffer = @import("engine/StagingBuffer.zig");
const Swapchain = @import("engine/Swapchain.zig");
const Texture = @import("engine/Texture.zig");
const Textures = @import("assets/Textures.zig");
allocator: std.mem.Allocator,
@@ -401,8 +402,10 @@ pub fn init(allocator: std.mem.Allocator, io: std.Io, engine: *Engine, swapchain
.dynamic_states = &.{ .viewport, .scissor },
},
.layout = pipeline_layout,
.render_pass = swapchain.render_pass,
.subpass = 0,
.view_mask = 0,
.color_attachment_formats = &.{swapchain.params.surface_format.format},
.depth_attachment_format = Texture.Usage.depth.vkFormat(),
.stencil_attachment_format = .undefined,
});
errdefer engine.destroyPipeline(pipeline);
engine.setObjectName(pipeline, "P Main", .{});
@@ -638,10 +641,10 @@ pub fn init(allocator: std.mem.Allocator, io: std.Io, engine: *Engine, swapchain
var skybox = try Skybox.load(
"skybox.hdr",
engine,
swapchain,
&stbi,
512,
global_uniforms.buffer,
swapchain.render_pass,
allocator,
io,
);
@@ -650,8 +653,8 @@ pub fn init(allocator: std.mem.Allocator, io: std.Io, engine: *Engine, swapchain
var gui = try Gui.init(
allocator,
engine,
swapchain,
global_uniforms.buffer,
swapchain.render_pass,
);
errdefer gui.deinit(engine, allocator);
@@ -896,28 +899,94 @@ fn render(self: *Game) !void {
try command_buffer.beginCommandBuffer();
{
command_buffer.beginRenderPass(.{
.render_pass = self.swapchain.render_pass,
.framebuffer = self.swapchain.swapchain_images[self.swapchain.image_index.?].framebuffer,
const swapchain_image = &self.swapchain.swapchain_images[self.swapchain.image_index.?];
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true },
.dst_stage_mask = .{ .color_attachment_output_bit = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{},
.dst_access_mask = .{
.color_attachment_read_bit = true,
.color_attachment_write_bit = true,
},
.old_layout = .undefined,
.new_layout = .color_attachment_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
.layer_count = 1,
},
},
},
});
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .late_fragment_tests_bit = true },
.dst_stage_mask = .{ .early_fragment_tests_bit = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{
.depth_stencil_attachment_write_bit = true,
},
.dst_access_mask = .{
.depth_stencil_attachment_write_bit = true,
},
.old_layout = .undefined,
.new_layout = .depth_stencil_attachment_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = self.swapchain.depth_texture.?.image,
.subresource_range = .{
.aspect_mask = .{ .depth_bit = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
.layer_count = 1,
},
},
},
});
try command_buffer.beginRendering(.{
.render_area = .{
.offset = .{ .x = 0, .y = 0 },
.extent = extent,
},
.clear_values = &.{
.layer_count = 1,
.view_mask = 0,
.color_attachments = &.{
.{
.color = .{
.float_32 = .{ 0, 0, 0, 0 },
.image_view = swapchain_image.image_view,
.image_layout = .color_attachment_optimal,
.load_op = .clear,
.store_op = .store,
.clear_value = .{
.color = .{
.float_32 = .{ 0, 0, 0, 0 },
},
},
},
.{
},
.depth_attachment = .{
.image_view = self.swapchain.depth_texture.?.image_view,
.image_layout = .depth_attachment_optimal,
.load_op = .clear,
.store_op = .dont_care,
.clear_value = .{
.depth_stencil = .{
.depth = 0,
.stencil = 0,
},
},
},
}, .@"inline");
defer command_buffer.endRenderPass();
});
command_buffer.setViewport(0, &.{
.{
@@ -936,7 +1005,7 @@ fn render(self: *Game) !void {
},
});
// --- SUBPASS 0 (MAIN) ---
// --- RENDER 3D SCENE ---
command_buffer.bindPipeline(.graphics, self.pipeline);
try command_buffer.bindVertexBuffers(0, &.{
@@ -955,11 +1024,35 @@ fn render(self: *Game) !void {
try self.skybox.draw(command_buffer);
// --- SUBPASS 1 (GUI) ---
command_buffer.nextSubpass(.@"inline");
// --- RENDER GUI ---
try self.gui.draw(self.engine, command_buffer);
// --- FINALIZE ---
command_buffer.endRendering();
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true },
.dst_stage_mask = .{ .bottom_of_pipe_bit = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{ .color_attachment_write_bit = true },
.dst_access_mask = .{},
.old_layout = .color_attachment_optimal,
.new_layout = .present_src_khr,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
.layer_count = 1,
},
},
},
});
}
try command_buffer.endCommandBuffer();