adding command descriptors and buffer base

This commit is contained in:
2025-11-19 21:21:36 +01:00
parent 8ee6c9f63d
commit 4c91713ccd
2 changed files with 92 additions and 1 deletions

View File

@@ -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;
}

61
src/vulkan/commands.zig git.filemode.normal_file
View File

@@ -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,
};