Make use of some globals to stop typing engine everywhere.

This commit is contained in:
2026-05-15 02:20:08 +02:00
parent 36434f8107
commit ad80fb4fd9
21 changed files with 902 additions and 798 deletions

View File

@@ -9,28 +9,31 @@
const CommandBuffer = @This();
const std = @import("std");
const ctx = @import("../AppContext.zig");
const vk = @import("vulkan");
const Engine = @import("Engine.zig");
const QueueType = @import("QueueType.zig").QueueType;
proxy: vk.CommandBufferProxy,
allocator: std.mem.Allocator,
queue_type: QueueType,
pub fn init(engine: *Engine, queue_type: QueueType) !CommandBuffer {
pub fn init(queue_type: QueueType) !CommandBuffer {
const engine = ctx.engine;
const handle = try engine.allocateCommandBuffer(.{
.queue_type = queue_type,
.level = .primary,
});
return .{
.proxy = .init(handle, engine.device.wrapper),
.allocator = engine.vk_allocator.allocator,
.queue_type = queue_type,
};
}
pub fn deinit(self: *CommandBuffer, engine: *Engine) void {
pub fn deinit(self: *CommandBuffer) void {
const engine = ctx.engine;
engine.freeCommandBuffer(.{
.queue_type = self.queue_type,
.command_buffer = self.proxy.handle,
@@ -38,7 +41,9 @@ pub fn deinit(self: *CommandBuffer, engine: *Engine) void {
self.* = undefined;
}
pub fn submit(self: CommandBuffer, engine: *Engine, submit_info: Engine.SubmitInfo) !void {
pub fn submit(self: CommandBuffer, submit_info: Engine.SubmitInfo) !void {
const engine = ctx.engine;
try engine.queueSubmit(self.queue_type, self.proxy.handle, submit_info);
}
@@ -96,11 +101,9 @@ pub fn beginCommandBuffer(self: CommandBuffer) !void {
}
pub fn beginRendering(self: CommandBuffer, rendering_info: RenderingInfo) !void {
var arena: std.heap.ArenaAllocator = .init(self.allocator);
defer arena.deinit();
const allocator = arena.allocator();
const allocator_frame = ctx.allocator_frame;
const color_attachments = try allocator.alloc(vk.RenderingAttachmentInfo, rendering_info.color_attachments.len);
const color_attachments = try allocator_frame.alloc(vk.RenderingAttachmentInfo, rendering_info.color_attachments.len);
for (color_attachments, rendering_info.color_attachments) |*x, color_attachment| {
x.* = .{
.image_view = color_attachment.image_view,
@@ -187,9 +190,11 @@ pub fn bindIndexBuffer(self: CommandBuffer, buffer: vk.Buffer, offset: u64, inde
}
pub fn bindVertexBuffers(self: CommandBuffer, first_binding: u32, bindings: []const VertexBufferBinding) !void {
const allocator_frame = ctx.allocator_frame;
var vertex_buffer_bindings = std.MultiArrayList(VertexBufferBinding){};
defer vertex_buffer_bindings.deinit(self.allocator);
try vertex_buffer_bindings.ensureTotalCapacity(self.allocator, bindings.len);
defer vertex_buffer_bindings.deinit(allocator_frame);
try vertex_buffer_bindings.ensureTotalCapacity(allocator_frame, bindings.len);
for (bindings) |binding| {
vertex_buffer_bindings.appendAssumeCapacity(binding);