adding descriptor writes for storage buffers
This commit is contained in:
@@ -22,6 +22,7 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
|||||||
|
|
||||||
interface.dispatch_table = &.{
|
interface.dispatch_table = &.{
|
||||||
.begin = begin,
|
.begin = begin,
|
||||||
|
.bindPipeline = bindPipeline,
|
||||||
.clearColorImage = clearColorImage,
|
.clearColorImage = clearColorImage,
|
||||||
.copyBuffer = copyBuffer,
|
.copyBuffer = copyBuffer,
|
||||||
.copyImage = copyImage,
|
.copyImage = copyImage,
|
||||||
@@ -64,6 +65,16 @@ pub fn reset(interface: *Interface, flags: vk.CommandBufferResetFlags) VkError!v
|
|||||||
|
|
||||||
// Commands ====================================================================================================
|
// Commands ====================================================================================================
|
||||||
|
|
||||||
|
pub fn bindPipeline(interface: *Interface, bind_point: vk.PipelineBindPoint, pipeline: *base.Pipeline) VkError!void {
|
||||||
|
_ = interface;
|
||||||
|
_ = pipeline;
|
||||||
|
|
||||||
|
if (bind_point != .graphics and bind_point != .compute) {
|
||||||
|
std.log.warn("Software driver does not support bind point {s}", .{@tagName(bind_point)});
|
||||||
|
return VkError.ValidationFailed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clearColorImage(interface: *Interface, image: *base.Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, range: vk.ImageSubresourceRange) VkError!void {
|
pub fn clearColorImage(interface: *Interface, image: *base.Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, range: vk.ImageSubresourceRange) VkError!void {
|
||||||
// No-op
|
// No-op
|
||||||
_ = interface;
|
_ = interface;
|
||||||
|
|||||||
@@ -4,12 +4,28 @@ const base = @import("base");
|
|||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
const Device = base.Device;
|
||||||
|
const Buffer = base.Buffer;
|
||||||
|
|
||||||
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
|
|
||||||
|
const NonDispatchable = base.NonDispatchable;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorSet;
|
pub const Interface = base.DescriptorSet;
|
||||||
|
|
||||||
|
const Descriptor = union(enum) {
|
||||||
|
buffer: struct {
|
||||||
|
object: ?*SoftBuffer,
|
||||||
|
offset: vk.DeviceSize,
|
||||||
|
size: vk.DeviceSize,
|
||||||
|
},
|
||||||
|
image: struct {},
|
||||||
|
};
|
||||||
|
|
||||||
interface: Interface,
|
interface: Interface,
|
||||||
|
|
||||||
|
descriptors: []Descriptor,
|
||||||
|
|
||||||
pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.DescriptorSetLayout) VkError!*Self {
|
pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.DescriptorSetLayout) VkError!*Self {
|
||||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
@@ -22,8 +38,12 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.
|
|||||||
.write = write,
|
.write = write,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const descriptors = allocator.alloc(Descriptor, layout.bindings.len) catch return VkError.OutOfHostMemory;
|
||||||
|
errdefer allocator.free(descriptors);
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.interface = interface,
|
.interface = interface,
|
||||||
|
.descriptors = descriptors,
|
||||||
};
|
};
|
||||||
return self;
|
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 {
|
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
||||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||||
|
allocator.free(self.descriptors);
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!void {
|
pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!void {
|
||||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
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)}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ fn taskRunner(self: *Self, info: Interface.SubmitInfo, p_fence: ?*base.Fence, ru
|
|||||||
command_buffers.deinit(soft_device.device_allocator.allocator());
|
command_buffers.deinit(soft_device.device_allocator.allocator());
|
||||||
}
|
}
|
||||||
|
|
||||||
var device = Device.init();
|
var device = Device.init(soft_device);
|
||||||
defer device.deinit();
|
defer device.deinit();
|
||||||
|
|
||||||
loop: for (info.command_buffers.items) |command_buffer| {
|
loop: for (info.command_buffers.items) |command_buffer| {
|
||||||
|
|||||||
29
src/soft/device/ComputeRoutines.zig
git.filemode.normal_file
29
src/soft/device/ComputeRoutines.zig
git.filemode.normal_file
@@ -0,0 +1,29 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const vk = @import("vulkan");
|
||||||
|
const base = @import("base");
|
||||||
|
const spv = @import("spv");
|
||||||
|
|
||||||
|
const SoftDevice = @import("../SoftDevice.zig");
|
||||||
|
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||||
|
|
||||||
|
const VkError = base.VkError;
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
device: *SoftDevice,
|
||||||
|
pipeline: ?*SoftPipeline,
|
||||||
|
|
||||||
|
pub fn init(device: *SoftDevice) Self {
|
||||||
|
return .{
|
||||||
|
.device = device,
|
||||||
|
.pipeline = null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn destroy(self: *Self) void {
|
||||||
|
_ = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bindPipeline(self: *Self, pipeline: *SoftPipeline) void {
|
||||||
|
self.pipeline = pipeline;
|
||||||
|
}
|
||||||
@@ -2,24 +2,38 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
|
const SoftDevice = @import("../SoftDevice.zig");
|
||||||
const SoftImage = @import("../SoftImage.zig");
|
const SoftImage = @import("../SoftImage.zig");
|
||||||
|
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||||
|
|
||||||
|
const ComputeRoutines = @import("ComputeRoutines.zig");
|
||||||
|
|
||||||
const cmd = base.commands;
|
const cmd = base.commands;
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
pub fn init() Self {
|
compute_routine: ComputeRoutines,
|
||||||
return .{};
|
|
||||||
|
pub fn init(device: *SoftDevice) Self {
|
||||||
|
return .{
|
||||||
|
.compute_routine = .init(device),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
_ = self;
|
self.compute_routine.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch(self: *Self, command: *const cmd.Command) VkError!void {
|
pub fn dispatch(self: *Self, command: *const cmd.Command) VkError!void {
|
||||||
_ = self;
|
|
||||||
switch (command.*) {
|
switch (command.*) {
|
||||||
|
.BindPipeline => |data| {
|
||||||
|
if (data.bind_point == .compute) {
|
||||||
|
self.compute_routine.bindPipeline(@alignCast(@fieldParentPtr("interface", data.pipeline)));
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
},
|
||||||
.ClearColorImage => |data| try clearColorImage(&data),
|
.ClearColorImage => |data| try clearColorImage(&data),
|
||||||
.CopyBuffer => |data| try copyBuffer(&data),
|
.CopyBuffer => |data| try copyBuffer(&data),
|
||||||
.CopyImage => |data| try copyImage(&data),
|
.CopyImage => |data| try copyImage(&data),
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const Buffer = @import("Buffer.zig");
|
|||||||
const CommandPool = @import("CommandPool.zig");
|
const CommandPool = @import("CommandPool.zig");
|
||||||
const Event = @import("Event.zig");
|
const Event = @import("Event.zig");
|
||||||
const Image = @import("Image.zig");
|
const Image = @import("Image.zig");
|
||||||
|
const Pipeline = @import("Pipeline.zig");
|
||||||
|
|
||||||
const COMMAND_BUFFER_BASE_CAPACITY = 256;
|
const COMMAND_BUFFER_BASE_CAPACITY = 256;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ vtable: *const VTable,
|
|||||||
dispatch_table: *const DispatchTable,
|
dispatch_table: *const DispatchTable,
|
||||||
|
|
||||||
pub const DispatchTable = struct {
|
pub const DispatchTable = struct {
|
||||||
|
bindPipeline: *const fn (*Self, vk.PipelineBindPoint, *Pipeline) VkError!void,
|
||||||
begin: *const fn (*Self, *const vk.CommandBufferBeginInfo) VkError!void,
|
begin: *const fn (*Self, *const vk.CommandBufferBeginInfo) VkError!void,
|
||||||
clearColorImage: *const fn (*Self, *Image, vk.ImageLayout, *const vk.ClearColorValue, vk.ImageSubresourceRange) VkError!void,
|
clearColorImage: *const fn (*Self, *Image, vk.ImageLayout, *const vk.ClearColorValue, vk.ImageSubresourceRange) VkError!void,
|
||||||
copyBuffer: *const fn (*Self, *Buffer, *Buffer, []const vk.BufferCopy) VkError!void,
|
copyBuffer: *const fn (*Self, *Buffer, *Buffer, []const vk.BufferCopy) VkError!void,
|
||||||
@@ -133,31 +135,41 @@ fn cleanCommandList(self: *Self) void {
|
|||||||
|
|
||||||
// Commands ====================================================================================================
|
// Commands ====================================================================================================
|
||||||
|
|
||||||
|
pub inline fn bindPipeline(self: *Self, bind_point: vk.PipelineBindPoint, pipeline: *Pipeline) VkError!void {
|
||||||
|
const allocator = self.host_allocator.allocator();
|
||||||
|
try self.dispatch_table.bindPipeline(self, bind_point, pipeline);
|
||||||
|
self.commands.append(allocator, .{ .BindPipeline = .{
|
||||||
|
.bind_point = bind_point,
|
||||||
|
.pipeline = pipeline,
|
||||||
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
|
}
|
||||||
|
|
||||||
pub inline fn clearColorImage(self: *Self, image: *Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, ranges: []const vk.ImageSubresourceRange) VkError!void {
|
pub inline fn clearColorImage(self: *Self, image: *Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, ranges: []const vk.ImageSubresourceRange) VkError!void {
|
||||||
const allocator = self.host_allocator.allocator();
|
const allocator = self.host_allocator.allocator();
|
||||||
for (ranges) |range| {
|
for (ranges) |range| {
|
||||||
|
try self.dispatch_table.clearColorImage(self, image, layout, color, range);
|
||||||
self.commands.append(allocator, .{ .ClearColorImage = .{
|
self.commands.append(allocator, .{ .ClearColorImage = .{
|
||||||
.image = image,
|
.image = image,
|
||||||
.layout = layout,
|
.layout = layout,
|
||||||
.clear_color = color.*,
|
.clear_color = color.*,
|
||||||
.range = range,
|
.range = range,
|
||||||
} }) catch return VkError.OutOfHostMemory;
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
try self.dispatch_table.clearColorImage(self, image, layout, color, range);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn copyBuffer(self: *Self, src: *Buffer, dst: *Buffer, regions: []const vk.BufferCopy) VkError!void {
|
pub inline fn copyBuffer(self: *Self, src: *Buffer, dst: *Buffer, regions: []const vk.BufferCopy) VkError!void {
|
||||||
const allocator = self.host_allocator.allocator();
|
const allocator = self.host_allocator.allocator();
|
||||||
|
try self.dispatch_table.copyBuffer(self, src, dst, regions);
|
||||||
self.commands.append(allocator, .{ .CopyBuffer = .{
|
self.commands.append(allocator, .{ .CopyBuffer = .{
|
||||||
.src = src,
|
.src = src,
|
||||||
.dst = dst,
|
.dst = dst,
|
||||||
.regions = allocator.dupe(vk.BufferCopy, regions) catch return VkError.OutOfHostMemory,
|
.regions = allocator.dupe(vk.BufferCopy, regions) catch return VkError.OutOfHostMemory,
|
||||||
} }) catch return VkError.OutOfHostMemory;
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
try self.dispatch_table.copyBuffer(self, src, dst, regions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn copyImage(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Image, dst_layout: vk.ImageLayout, regions: []const vk.ImageCopy) VkError!void {
|
pub inline fn copyImage(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Image, dst_layout: vk.ImageLayout, regions: []const vk.ImageCopy) VkError!void {
|
||||||
const allocator = self.host_allocator.allocator();
|
const allocator = self.host_allocator.allocator();
|
||||||
|
try self.dispatch_table.copyImage(self, src, src_layout, dst, dst_layout, regions);
|
||||||
self.commands.append(allocator, .{ .CopyImage = .{
|
self.commands.append(allocator, .{ .CopyImage = .{
|
||||||
.src = src,
|
.src = src,
|
||||||
.src_layout = src_layout,
|
.src_layout = src_layout,
|
||||||
@@ -165,29 +177,28 @@ pub inline fn copyImage(self: *Self, src: *Image, src_layout: vk.ImageLayout, ds
|
|||||||
.dst_layout = dst_layout,
|
.dst_layout = dst_layout,
|
||||||
.regions = allocator.dupe(vk.ImageCopy, regions) catch return VkError.OutOfHostMemory,
|
.regions = allocator.dupe(vk.ImageCopy, regions) catch return VkError.OutOfHostMemory,
|
||||||
} }) catch return VkError.OutOfHostMemory;
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
try self.dispatch_table.copyImage(self, src, src_layout, dst, dst_layout, regions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn copyImageToBuffer(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Buffer, regions: []const vk.BufferImageCopy) VkError!void {
|
pub inline fn copyImageToBuffer(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Buffer, regions: []const vk.BufferImageCopy) VkError!void {
|
||||||
const allocator = self.host_allocator.allocator();
|
const allocator = self.host_allocator.allocator();
|
||||||
|
try self.dispatch_table.copyImageToBuffer(self, src, src_layout, dst, regions);
|
||||||
self.commands.append(allocator, .{ .CopyImageToBuffer = .{
|
self.commands.append(allocator, .{ .CopyImageToBuffer = .{
|
||||||
.src = src,
|
.src = src,
|
||||||
.src_layout = src_layout,
|
.src_layout = src_layout,
|
||||||
.dst = dst,
|
.dst = dst,
|
||||||
.regions = allocator.dupe(vk.BufferImageCopy, regions) catch return VkError.OutOfHostMemory,
|
.regions = allocator.dupe(vk.BufferImageCopy, regions) catch return VkError.OutOfHostMemory,
|
||||||
} }) catch return VkError.OutOfHostMemory;
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
try self.dispatch_table.copyImageToBuffer(self, src, src_layout, dst, regions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn fillBuffer(self: *Self, buffer: *Buffer, offset: vk.DeviceSize, size: vk.DeviceSize, data: u32) VkError!void {
|
pub inline fn fillBuffer(self: *Self, buffer: *Buffer, offset: vk.DeviceSize, size: vk.DeviceSize, data: u32) VkError!void {
|
||||||
const allocator = self.host_allocator.allocator();
|
const allocator = self.host_allocator.allocator();
|
||||||
|
try self.dispatch_table.fillBuffer(self, buffer, offset, size, data);
|
||||||
self.commands.append(allocator, .{ .FillBuffer = .{
|
self.commands.append(allocator, .{ .FillBuffer = .{
|
||||||
.buffer = buffer,
|
.buffer = buffer,
|
||||||
.offset = offset,
|
.offset = offset,
|
||||||
.size = if (size == vk.WHOLE_SIZE) buffer.size else size,
|
.size = if (size == vk.WHOLE_SIZE) buffer.size else size,
|
||||||
.data = data,
|
.data = data,
|
||||||
} }) catch return VkError.OutOfHostMemory;
|
} }) catch return VkError.OutOfHostMemory;
|
||||||
try self.dispatch_table.fillBuffer(self, buffer, offset, size, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn resetEvent(self: *Self, event: *Event, stage: vk.PipelineStageFlags) VkError!void {
|
pub inline fn resetEvent(self: *Self, event: *Event, stage: vk.PipelineStageFlags) VkError!void {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, layout: *DescriptorSe
|
|||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn copy(self: *Self, copy_data: vk.CopyDescriptorSet) VkError!void {
|
pub inline fn copy(self: *Self, copy_data: vk.CopyDescriptorSet) VkError!void {
|
||||||
try self.vtable.copy(self, copy_data);
|
try self.vtable.copy(self, copy_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const vk = @import("vulkan");
|
|||||||
|
|
||||||
const Buffer = @import("Buffer.zig");
|
const Buffer = @import("Buffer.zig");
|
||||||
const Image = @import("Image.zig");
|
const Image = @import("Image.zig");
|
||||||
|
const Pipeline = @import("Pipeline.zig");
|
||||||
|
|
||||||
pub const CommandType = enum {
|
pub const CommandType = enum {
|
||||||
BindPipeline,
|
BindPipeline,
|
||||||
@@ -20,6 +21,7 @@ pub const CommandType = enum {
|
|||||||
|
|
||||||
pub const CommandBindPipeline = struct {
|
pub const CommandBindPipeline = struct {
|
||||||
bind_point: vk.PipelineBindPoint,
|
bind_point: vk.PipelineBindPoint,
|
||||||
|
pipeline: *Pipeline,
|
||||||
};
|
};
|
||||||
pub const CommandBindVertexBuffer = struct {
|
pub const CommandBindVertexBuffer = struct {
|
||||||
buffers: []*const Buffer,
|
buffers: []*const Buffer,
|
||||||
|
|||||||
@@ -1707,12 +1707,8 @@ pub export fn strollCmdBindPipeline(p_cmd: vk.CommandBuffer, bind_point: vk.Pipe
|
|||||||
defer entryPointEndLogTrace();
|
defer entryPointEndLogTrace();
|
||||||
|
|
||||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||||
|
const pipeline = Dispatchable(Pipeline).fromHandleObject(p_pipeline) catch |err| return errorLogger(err);
|
||||||
notImplementedWarning();
|
cmd.bindPipeline(bind_point, pipeline) catch |err| return errorLogger(err);
|
||||||
|
|
||||||
_ = cmd;
|
|
||||||
_ = bind_point;
|
|
||||||
_ = p_pipeline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub export fn strollCmdBindVertexBuffers(p_cmd: vk.CommandBuffer, first: u32, count: u32, p_buffers: [*]const vk.Buffer, offsets: [*]const vk.DeviceSize) callconv(vk.vulkan_call_conv) void {
|
pub export fn strollCmdBindVertexBuffers(p_cmd: vk.CommandBuffer, first: u32, count: u32, p_buffers: [*]const vk.Buffer, offsets: [*]const vk.DeviceSize) callconv(vk.vulkan_call_conv) void {
|
||||||
|
|||||||
Reference in New Issue
Block a user