Blocks and chunks

This commit is contained in:
2025-11-28 23:24:22 +01:00
parent 2541dee18d
commit 81a56f393e
32 changed files with 714 additions and 113 deletions

View File

@@ -92,6 +92,23 @@ pub fn CommandBuffer(comptime queue_type: QueueType, comptime transient: Transie
}, contents);
}
pub inline fn bindDescriptorSet(
self: Self,
pipeline_bind_point: vk.PipelineBindPoint,
layout: vk.PipelineLayout,
set: u32,
descriptor_set: vk.DescriptorSet,
dynamic_offset: ?u32,
) void {
self.bindDescriptorSets(
pipeline_bind_point,
layout,
set,
&.{descriptor_set},
if (dynamic_offset) |x| &.{x} else &.{},
);
}
pub inline fn bindDescriptorSets(
self: Self,
pipeline_bind_point: vk.PipelineBindPoint,

View File

@@ -570,6 +570,12 @@ pub const DescriptorPoolCreateInfo = struct {
};
pub const DescriptorSetAllocateInfo = struct {
descriptor_pool: vk.DescriptorPool,
set_layout: vk.DescriptorSetLayout,
variable_descriptor_count: ?u32 = null,
};
pub const DescriptorSetsAllocateInfo = struct {
descriptor_pool: vk.DescriptorPool,
set_layouts: []const vk.DescriptorSetLayout,
variable_descriptor_counts: []const u32 = &.{},
@@ -733,7 +739,17 @@ pub fn createBuffer(self: *Engine, create_info: BufferCreateInfo) !vk.Buffer {
return buffer;
}
pub fn allocateDescriptorSets(self: *Engine, allocate_info: DescriptorSetAllocateInfo, descriptor_sets: []vk.DescriptorSet) !void {
pub fn allocateDescriptorSet(self: *Engine, allocate_info: DescriptorSetAllocateInfo) !vk.DescriptorSet {
var descriptor_sets: [1]vk.DescriptorSet = undefined;
try self.allocateDescriptorSets(.{
.descriptor_pool = allocate_info.descriptor_pool,
.set_layouts = &.{allocate_info.set_layout},
.variable_descriptor_counts = if (allocate_info.variable_descriptor_count) |x| &.{x} else &.{},
}, &descriptor_sets);
return descriptor_sets[0];
}
pub fn allocateDescriptorSets(self: *Engine, allocate_info: DescriptorSetsAllocateInfo, descriptor_sets: []vk.DescriptorSet) !void {
std.debug.assert(descriptor_sets.len >= allocate_info.set_layouts.len);
const has_variable_descriptor_counts = allocate_info.variable_descriptor_counts.len > 0;
@@ -1031,6 +1047,11 @@ pub fn destroyShaderModule(self: *Engine, shader_module: vk.ShaderModule) void {
self.device.destroyShaderModule(shader_module, &self.vk_allocator.interface);
}
pub fn freeDescriptorSet(self: *Engine, descriptor_pool: vk.DescriptorPool, descriptor_set: vk.DescriptorSet) void {
const descriptor_sets = [_]vk.DescriptorSet{descriptor_set};
self.device.freeDescriptorSets(descriptor_pool, descriptor_sets.len, &descriptor_sets) catch unreachable;
}
pub fn freeMemory(self: *Engine, device_memory: vk.DeviceMemory) void {
self.device.freeMemory(device_memory, &self.vk_allocator.interface);
}