From 4c91713ccd31a36de56083a6f6c57b84accc9344 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 19 Nov 2025 21:21:36 +0100 Subject: [PATCH] adding command descriptors and buffer base --- src/vulkan/Buffer.zig | 32 ++++++++++++++++++++- src/vulkan/commands.zig | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/vulkan/commands.zig diff --git a/src/vulkan/Buffer.zig b/src/vulkan/Buffer.zig index 2570fc1..77b1c97 100644 --- a/src/vulkan/Buffer.zig +++ b/src/vulkan/Buffer.zig @@ -2,12 +2,42 @@ const std = @import("std"); const vk = @import("vulkan"); const VkError = @import("error_set.zig").VkError; +const DeviceMemory = @import("DeviceMemory.zig"); const Device = @import("Device.zig"); const Self = @This(); pub const ObjectType: vk.ObjectType = .buffer; -owner: *const Device, +owner: *Device, size: vk.DeviceSize, offset: vk.DeviceSize, usage: vk.BufferUsageFlags, +memory: ?*DeviceMemory, +allowed_memory_types: u32, + +vtable: *const VTable, + +pub const VTable = struct { + getMemoryRequirements: *const fn (*Self, *vk.MemoryRequirements) void, +}; + +pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.BufferCreateInfo) VkError!Self { + _ = allocator; + return .{ + .owner = device, + .size = info.size, + .offset = 0, + .usage = info.usage, + .memory = null, + .allowed_memory_types = 0, + .vtable = undefined, + }; +} + +pub inline fn bindMemory(self: *Self, memory: *DeviceMemory, offset: vk.DeviceSize) VkError!void { + if (offset >= self.size or self.allowed_memory_types & memory.memory_type_index == 0) { + return VkError.ValidationFailed; + } + self.memory = memory; + self.offset = offset; +} diff --git a/src/vulkan/commands.zig b/src/vulkan/commands.zig new file mode 100644 index 0000000..f20c025 --- /dev/null +++ b/src/vulkan/commands.zig @@ -0,0 +1,61 @@ +const std = @import("std"); +const vk = @import("vulkan"); + +const Buffer = @import("Buffer.zig"); + +pub const CommandType = enum { + BindVertexBuffer, + Draw, + DrawIndexed, + DrawIndirect, + DrawIndexedIndirect, + BindPipeline, +}; + +pub const CommandBindVertexBuffer = struct { + buffers: std.ArrayList(Buffer), + offsets: std.ArrayList(vk.DeviceSize), + first_binding: u32, +}; + +pub const CommandDraw = struct { + vertex_count: u32, + instance_count: u32, + first_vertex: u32, + first_instance: u32, +}; + +pub const CommandDrawIndexed = struct { + index_count: u32, + instance_count: u32, + first_index: u32, + vertex_offset: i32, + first_instance: u32, +}; + +pub const CommandDrawIndirect = struct { + buffer: *Buffer, + offset: vk.DeviceSize, + count: u32, + stride: u32, +}; + +pub const CommandDrawIndexedIndirect = struct { + buffer: *Buffer, + offset: vk.DeviceSize, + count: u32, + stride: u32, +}; + +pub const CommandBindPipeline = struct { + bind_point: vk.PipelineBindPoint, +}; + +pub const Command = union(CommandType) { + BindVertexBuffer: CommandBindVertexBuffer, + Draw: CommandDraw, + DrawIndexed: CommandDrawIndexed, + DrawIndirect: CommandDrawIndirect, + DrawIndexedIndirect: CommandDrawIndexedIndirect, + BindPipeline: CommandBindPipeline, +};