adding descriptor writes for storage buffers
This commit is contained in:
@@ -4,12 +4,28 @@ const base = @import("base");
|
||||
|
||||
const VkError = base.VkError;
|
||||
const Device = base.Device;
|
||||
const Buffer = base.Buffer;
|
||||
|
||||
const SoftBuffer = @import("SoftBuffer.zig");
|
||||
|
||||
const NonDispatchable = base.NonDispatchable;
|
||||
|
||||
const Self = @This();
|
||||
pub const Interface = base.DescriptorSet;
|
||||
|
||||
const Descriptor = union(enum) {
|
||||
buffer: struct {
|
||||
object: ?*SoftBuffer,
|
||||
offset: vk.DeviceSize,
|
||||
size: vk.DeviceSize,
|
||||
},
|
||||
image: struct {},
|
||||
};
|
||||
|
||||
interface: Interface,
|
||||
|
||||
descriptors: []Descriptor,
|
||||
|
||||
pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.DescriptorSetLayout) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(self);
|
||||
@@ -22,8 +38,12 @@ 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);
|
||||
|
||||
self.* = .{
|
||||
.interface = interface,
|
||||
.descriptors = descriptors,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
@@ -36,11 +56,30 @@ 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.destroy(self);
|
||||
}
|
||||
|
||||
pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
_ = self;
|
||||
_ = write_data;
|
||||
|
||||
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];
|
||||
desc.* = .{
|
||||
.buffer = .{
|
||||
.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)));
|
||||
}
|
||||
}
|
||||
},
|
||||
else => base.unsupported("descriptor type {s} for writting", .{@tagName(write_data.descriptor_type)}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user