adding some opcodes
Build / build (push) Has been cancelled
Test / build_and_test (push) Has been cancelled

This commit is contained in:
2026-03-11 01:28:33 +01:00
parent ffa1f56089
commit 857e877f33
7 changed files with 110 additions and 50 deletions
+47 -17
View File
@@ -13,17 +13,22 @@ const NonDispatchable = base.NonDispatchable;
const Self = @This();
pub const Interface = base.DescriptorSet;
const DescriptorBuffer = struct {
object: ?*SoftBuffer,
offset: vk.DeviceSize,
size: vk.DeviceSize,
};
const Descriptor = union(enum) {
buffer: struct {
object: ?*SoftBuffer,
offset: vk.DeviceSize,
size: vk.DeviceSize,
},
buffer: []DescriptorBuffer,
image: struct {},
};
interface: Interface,
/// Memory containing actual binding descriptors and their array
heap: []u8,
descriptors: []Descriptor,
pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.DescriptorSetLayout) VkError!*Self {
@@ -38,11 +43,38 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.
.write = write,
};
const descriptors = allocator.alloc(Descriptor, layout.bindings.len) catch return VkError.OutOfHostMemory;
errdefer allocator.free(descriptors);
const heap_size = blk: {
var size: usize = layout.bindings.len * @sizeOf(Descriptor);
for (layout.bindings) |binding| {
const struct_size: usize = switch (binding.descriptor_type) {
.storage_buffer, .storage_buffer_dynamic => @sizeOf(DescriptorBuffer),
else => 0,
};
size += binding.array_size * struct_size;
}
break :blk size;
};
const heap = allocator.alloc(u8, heap_size) catch return VkError.OutOfHostMemory;
errdefer allocator.free(heap);
var local_heap = std.heap.FixedBufferAllocator.init(heap);
const local_allocator = local_heap.allocator();
const descriptors = local_allocator.alloc(Descriptor, layout.bindings.len) catch return VkError.OutOfHostMemory;
for (descriptors, layout.bindings) |*descriptor, binding| {
switch (binding.descriptor_type) {
.storage_buffer, .storage_buffer_dynamic => descriptor.* = .{
.buffer = local_allocator.alloc(DescriptorBuffer, binding.array_size) catch return VkError.OutOfHostMemory,
},
else => {},
}
}
self.* = .{
.interface = interface,
.heap = heap,
.descriptors = descriptors,
};
return self;
@@ -56,7 +88,7 @@ pub fn copy(interface: *Interface, copy_data: vk.CopyDescriptorSet) VkError!void
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
allocator.free(self.descriptors);
allocator.free(self.heap);
allocator.destroy(self);
}
@@ -66,19 +98,17 @@ pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!v
switch (write_data.descriptor_type) {
.storage_buffer, .storage_buffer_dynamic => {
for (write_data.p_buffer_info, 0..write_data.descriptor_count) |buffer_info, i| {
const desc = &self.descriptors[write_data.dst_binding + i];
const desc = &self.descriptors[write_data.dst_binding].buffer[i];
desc.* = .{
.buffer = .{
.object = null,
.offset = buffer_info.offset,
.size = buffer_info.range,
},
.object = null,
.offset = buffer_info.offset,
.size = buffer_info.range,
};
if (buffer_info.buffer != .null_handle) {
const buffer = try NonDispatchable(Buffer).fromHandleObject(buffer_info.buffer);
desc.buffer.object = @as(*SoftBuffer, @alignCast(@fieldParentPtr("interface", buffer)));
if (desc.buffer.size == vk.WHOLE_SIZE) {
desc.buffer.size = if (buffer.memory) |memory| memory.size - desc.buffer.offset else return VkError.InvalidDeviceMemoryDrv;
desc.object = @as(*SoftBuffer, @alignCast(@fieldParentPtr("interface", buffer)));
if (desc.size == vk.WHOLE_SIZE) {
desc.size = if (buffer.memory) |memory| memory.size - desc.offset else return VkError.InvalidDeviceMemoryDrv;
}
}
}