un-comment command buffer sections

This commit is contained in:
David Allemang
2024-04-01 21:28:49 -04:00
parent d6baf2ef09
commit 6f7378cf21

View File

@@ -502,145 +502,155 @@ fn copyBuffer(
try vkd.queueWaitIdle(queue); try vkd.queueWaitIdle(queue);
} }
// fn createCommandBuffers( fn createCommandBuffers(
// pool: vk.CommandPool, views: []const vk.Image,
// allocator: Allocator, images: []const vk.ImageView,
// vertex_buffer: vk.Buffer, dev: vk.Device,
// index_buffer: vk.Buffer, vkd: gfx.DeviceDispatch,
// pipeline: vk.Pipeline, pool: vk.CommandPool,
// extent: vk.Extent2D, allocator: Allocator,
// ) ![]vk.CommandBuffer { vertex_buffer: vk.Buffer,
// const cmdbufs = try allocator.alloc(vk.CommandBuffer, swapchain.swap_images.len); index_buffer: vk.Buffer,
// errdefer allocator.free(cmdbufs); pipeline: vk.Pipeline,
// extent: vk.Extent2D,
// try vkd.allocateCommandBuffers(dev, &.{ ) ![]vk.CommandBuffer {
// .command_pool = pool, const cmdbufs = try allocator.alloc(vk.CommandBuffer, images.len);
// .level = .primary, errdefer allocator.free(cmdbufs);
// .command_buffer_count = @as(u32, @truncate(cmdbufs.len)),
// }, cmdbufs.ptr);
// errdefer vkd.freeCommandBuffers(dev, pool, @truncate(cmdbufs.len), cmdbufs.ptr);
//
// const clear = vk.ClearValue{
// .color = .{ .float_32 = .{ 0, 0, 0, 1 } },
// };
//
// const viewport = vk.Viewport{
// .x = 0,
// .y = 0,
// .width = @as(f32, @floatFromInt(extent.width)),
// .height = @as(f32, @floatFromInt(extent.height)),
// .min_depth = 0,
// .max_depth = 1,
// };
//
// const scissor = vk.Rect2D{
// .offset = .{ .x = 0, .y = 0 },
// .extent = extent,
// };
//
// for (cmdbufs, swapchain.swap_images) |cmdbuf, image| {
// try vkd.beginCommandBuffer(cmdbuf, &.{});
//
// vkd.cmdPipelineBarrier(
// cmdbuf,
// .{ .top_of_pipe_bit = true },
// .{ .color_attachment_output_bit = true },
// .{},
// 0,
// null,
// 0,
// null,
// 1,
// @ptrCast(&vk.ImageMemoryBarrier{
// .src_access_mask = .{},
// .dst_access_mask = .{ .color_attachment_write_bit = true },
// .old_layout = .undefined,
// .new_layout = .color_attachment_optimal,
// .src_queue_family_index = 0,
// .dst_queue_family_index = 0,
// .image = image.image,
// .subresource_range = .{
// .aspect_mask = .{ .color_bit = true },
// .base_mip_level = 0,
// .level_count = 1,
// .base_array_layer = 0,
// .layer_count = 1,
// },
// }),
// );
//
// vkd.cmdSetViewport(cmdbuf, 0, 1, @ptrCast(&viewport));
// vkd.cmdSetScissor(cmdbuf, 0, 1, @ptrCast(&scissor));
//
// const color_attachments = [_]vk.RenderingAttachmentInfoKHR{
// .{
// .image_view = image.view,
// .image_layout = .color_attachment_optimal,
// .resolve_mode = .{},
// .resolve_image_view = .null_handle,
// .resolve_image_layout = .undefined,
// .load_op = .clear,
// .store_op = .store,
// .clear_value = clear,
// },
// };
//
// const render_info = vk.RenderingInfoKHR{
// .render_area = scissor, // since we always do full-frame changes
// .layer_count = 1,
// .view_mask = 0,
// .color_attachment_count = color_attachments.len,
// .p_color_attachments = &color_attachments,
// };
//
// vkd.cmdBeginRenderingKHR(cmdbuf, &render_info);
//
// vkd.cmdBindPipeline(cmdbuf, .graphics, pipeline);
// const offset = [_]vk.DeviceSize{0};
// vkd.cmdBindVertexBuffers(cmdbuf, 0, 1, @ptrCast(&vertex_buffer), &offset);
// vkd.cmdBindIndexBuffer(cmdbuf, index_buffer, 0, .uint16);
// vkd.cmdDrawIndexed(cmdbuf, indices.len, 1, 0, 0, 0);
//
// vkd.cmdEndRenderingKHR(cmdbuf);
//
// vkd.cmdPipelineBarrier(
// cmdbuf,
// .{ .color_attachment_output_bit = true },
// .{ .bottom_of_pipe_bit = true },
// .{},
// 0,
// null,
// 0,
// null,
// 1,
// @ptrCast(&vk.ImageMemoryBarrier{
// .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 = 0,
// .dst_queue_family_index = 0,
// .image = image.image,
// .subresource_range = .{
// .aspect_mask = .{ .color_bit = true },
// .base_mip_level = 0,
// .level_count = 1,
// .base_array_layer = 0,
// .layer_count = 1,
// },
// }),
// );
//
// try vkd.endCommandBuffer(cmdbuf);
// }
//
// return cmdbufs;
// }
// fn destroyCommandBuffers(gc: *const Context, pool: vk.CommandPool, allocator: Allocator, cmdbufs: []vk.CommandBuffer) void { try vkd.allocateCommandBuffers(dev, &.{
// vkd.freeCommandBuffers(dev, pool, @truncate(cmdbufs.len), cmdbufs.ptr); .command_pool = pool,
// allocator.free(cmdbufs); .level = .primary,
// } .command_buffer_count = @as(u32, @truncate(cmdbufs.len)),
}, cmdbufs.ptr);
errdefer vkd.freeCommandBuffers(dev, pool, @truncate(cmdbufs.len), cmdbufs.ptr);
const clear = vk.ClearValue{
.color = .{ .float_32 = .{ 0, 0, 0, 1 } },
};
const viewport = vk.Viewport{
.x = 0,
.y = 0,
.width = @as(f32, @floatFromInt(extent.width)),
.height = @as(f32, @floatFromInt(extent.height)),
.min_depth = 0,
.max_depth = 1,
};
const scissor = vk.Rect2D{
.offset = .{ .x = 0, .y = 0 },
.extent = extent,
};
for (cmdbufs, images, views) |cmdbuf, image, view| {
try vkd.beginCommandBuffer(cmdbuf, &.{});
vkd.cmdPipelineBarrier(
cmdbuf,
.{ .top_of_pipe_bit = true },
.{ .color_attachment_output_bit = true },
.{},
0,
null,
0,
null,
1,
@ptrCast(&vk.ImageMemoryBarrier{
.src_access_mask = .{},
.dst_access_mask = .{ .color_attachment_write_bit = true },
.old_layout = .undefined,
.new_layout = .color_attachment_optimal,
.src_queue_family_index = 0,
.dst_queue_family_index = 0,
.image = image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
.layer_count = 1,
},
}),
);
vkd.cmdSetViewport(cmdbuf, 0, 1, @ptrCast(&viewport));
vkd.cmdSetScissor(cmdbuf, 0, 1, @ptrCast(&scissor));
const color_attachments = [_]vk.RenderingAttachmentInfoKHR{
.{
.image_view = view,
.image_layout = .color_attachment_optimal,
.resolve_mode = .{},
.resolve_image_view = .null_handle,
.resolve_image_layout = .undefined,
.load_op = .clear,
.store_op = .store,
.clear_value = clear,
},
};
const render_info = vk.RenderingInfoKHR{
.render_area = scissor, // since we always do full-frame changes
.layer_count = 1,
.view_mask = 0,
.color_attachment_count = color_attachments.len,
.p_color_attachments = &color_attachments,
};
vkd.cmdBeginRenderingKHR(cmdbuf, &render_info);
vkd.cmdBindPipeline(cmdbuf, .graphics, pipeline);
const offset = [_]vk.DeviceSize{0};
vkd.cmdBindVertexBuffers(cmdbuf, 0, 1, @ptrCast(&vertex_buffer), &offset);
vkd.cmdBindIndexBuffer(cmdbuf, index_buffer, 0, .uint16);
vkd.cmdDrawIndexed(cmdbuf, indices.len, 1, 0, 0, 0);
vkd.cmdEndRenderingKHR(cmdbuf);
vkd.cmdPipelineBarrier(
cmdbuf,
.{ .color_attachment_output_bit = true },
.{ .bottom_of_pipe_bit = true },
.{},
0,
null,
0,
null,
1,
@ptrCast(&vk.ImageMemoryBarrier{
.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 = 0,
.dst_queue_family_index = 0,
.image = image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
.layer_count = 1,
},
}),
);
try vkd.endCommandBuffer(cmdbuf);
}
return cmdbufs;
}
fn destroyCommandBuffers(
dev: vk.Device,
vkd: gfx.DeviceDispatch,
pool: vk.CommandPool,
allocator: Allocator,
cmdbufs: []vk.CommandBuffer,
) void {
vkd.freeCommandBuffers(dev, pool, @truncate(cmdbufs.len), cmdbufs.ptr);
allocator.free(cmdbufs);
}
fn createPipeline(dev: vk.Device, layout: vk.PipelineLayout, format: vk.SurfaceFormatKHR, vkd: gfx.DeviceDispatch) !vk.Pipeline { fn createPipeline(dev: vk.Device, layout: vk.PipelineLayout, format: vk.SurfaceFormatKHR, vkd: gfx.DeviceDispatch) !vk.Pipeline {
const vert = try vkd.createShaderModule(dev, &.{ const vert = try vkd.createShaderModule(dev, &.{