adding some base commadns
This commit is contained in:
@@ -6,14 +6,15 @@ const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
|
||||
const Buffer = @import("Buffer.zig");
|
||||
const CommandPool = @import("CommandPool.zig");
|
||||
const DescriptorSet = @import("DescriptorSet.zig");
|
||||
const Device = @import("Device.zig");
|
||||
const Event = @import("Event.zig");
|
||||
const Framebuffer = @import("Framebuffer.zig");
|
||||
const Image = @import("Image.zig");
|
||||
const Pipeline = @import("Pipeline.zig");
|
||||
const DescriptorSet = @import("DescriptorSet.zig");
|
||||
const RenderPass = @import("RenderPass.zig");
|
||||
|
||||
const State = enum {
|
||||
Initial,
|
||||
@@ -38,8 +39,10 @@ dispatch_table: *const DispatchTable,
|
||||
|
||||
pub const DispatchTable = struct {
|
||||
begin: *const fn (*Self, *const vk.CommandBufferBeginInfo) VkError!void,
|
||||
beginRenderPass: *const fn (*Self, *RenderPass, *Framebuffer, vk.Rect2D, ?[]const vk.ClearValue) VkError!void,
|
||||
bindDescriptorSets: *const fn (*Self, vk.PipelineBindPoint, u32, [lib.VULKAN_MAX_DESCRIPTOR_SETS]?*DescriptorSet, []const u32) VkError!void,
|
||||
bindPipeline: *const fn (*Self, vk.PipelineBindPoint, *Pipeline) VkError!void,
|
||||
bindVertexBuffer: *const fn (*Self, usize, *Buffer, usize) VkError!void,
|
||||
blitImage: *const fn (*Self, *Image, vk.ImageLayout, *Image, vk.ImageLayout, []const vk.ImageBlit, vk.Filter) 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,
|
||||
@@ -48,7 +51,9 @@ pub const DispatchTable = struct {
|
||||
copyImageToBuffer: *const fn (*Self, *Image, vk.ImageLayout, *Buffer, []const vk.BufferImageCopy) VkError!void,
|
||||
dispatch: *const fn (*Self, u32, u32, u32) VkError!void,
|
||||
dispatchIndirect: *const fn (*Self, *Buffer, vk.DeviceSize) VkError!void,
|
||||
draw: *const fn (*Self, usize, usize, usize, usize) VkError!void,
|
||||
end: *const fn (*Self) VkError!void,
|
||||
endRenderPass: *const fn (*Self) VkError!void,
|
||||
executeCommands: *const fn (*Self, *Self) VkError!void,
|
||||
fillBuffer: *const fn (*Self, *Buffer, vk.DeviceSize, vk.DeviceSize, u32) VkError!void,
|
||||
pipelineBarrier: *const fn (*Self, vk.PipelineStageFlags, vk.PipelineStageFlags, vk.DependencyFlags, []const vk.MemoryBarrier, []const vk.BufferMemoryBarrier, []const vk.ImageMemoryBarrier) VkError!void,
|
||||
@@ -91,7 +96,7 @@ pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
self.vtable.destroy(self, allocator);
|
||||
}
|
||||
|
||||
pub inline fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError!void {
|
||||
pub fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError!void {
|
||||
if (!self.pool.flags.reset_command_buffer_bit) {
|
||||
self.transitionState(.Recording, &.{.Initial}) catch return VkError.ValidationFailed;
|
||||
} else {
|
||||
@@ -102,13 +107,13 @@ pub inline fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError
|
||||
self.begin_info = info.*;
|
||||
}
|
||||
|
||||
pub inline fn end(self: *Self) VkError!void {
|
||||
pub fn end(self: *Self) VkError!void {
|
||||
self.transitionState(.Executable, &.{.Recording}) catch return VkError.ValidationFailed;
|
||||
try self.dispatch_table.end(self);
|
||||
self.begin_info = null;
|
||||
}
|
||||
|
||||
pub inline fn reset(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void {
|
||||
pub fn reset(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void {
|
||||
if (!self.pool.flags.reset_command_buffer_bit) {
|
||||
return VkError.ValidationFailed;
|
||||
}
|
||||
@@ -117,7 +122,7 @@ pub inline fn reset(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void
|
||||
try self.dispatch_table.reset(self, flags);
|
||||
}
|
||||
|
||||
pub inline fn submit(self: *Self) VkError!void {
|
||||
pub fn submit(self: *Self) VkError!void {
|
||||
if (self.begin_info) |begin_info| {
|
||||
if (!begin_info.flags.simultaneous_use_bit) {
|
||||
self.transitionState(.Pending, &.{.Executable}) catch return VkError.ValidationFailed;
|
||||
@@ -127,7 +132,7 @@ pub inline fn submit(self: *Self) VkError!void {
|
||||
self.transitionState(.Pending, &.{ .Pending, .Executable }) catch return VkError.ValidationFailed;
|
||||
}
|
||||
|
||||
pub inline fn finish(self: *Self) VkError!void {
|
||||
pub fn finish(self: *Self) VkError!void {
|
||||
if (self.begin_info) |begin_info| {
|
||||
if (!begin_info.flags.one_time_submit_bit) {
|
||||
self.transitionState(.Invalid, &.{.Pending}) catch return VkError.ValidationFailed;
|
||||
@@ -139,7 +144,11 @@ pub inline fn finish(self: *Self) VkError!void {
|
||||
|
||||
// Commands ====================================================================================================
|
||||
|
||||
pub inline fn bindDescriptorSets(self: *Self, bind_point: vk.PipelineBindPoint, first_set: u32, sets: []const vk.DescriptorSet, dynamic_offsets: []const u32) VkError!void {
|
||||
pub inline fn beginRenderPass(self: *Self, render_pass: *RenderPass, framebuffer: *Framebuffer, render_area: vk.Rect2D, clear_values: ?[]const vk.ClearValue) VkError!void {
|
||||
try self.dispatch_table.beginRenderPass(self, render_pass, framebuffer, render_area, clear_values);
|
||||
}
|
||||
|
||||
pub fn bindDescriptorSets(self: *Self, bind_point: vk.PipelineBindPoint, first_set: u32, sets: []const vk.DescriptorSet, dynamic_offsets: []const u32) VkError!void {
|
||||
std.debug.assert(sets.len < lib.VULKAN_MAX_DESCRIPTOR_SETS);
|
||||
var inner_sets = [_]?*DescriptorSet{null} ** lib.VULKAN_MAX_DESCRIPTOR_SETS;
|
||||
for (sets, inner_sets[0..sets.len]) |set, *inner_set| {
|
||||
@@ -152,11 +161,15 @@ pub inline fn bindPipeline(self: *Self, bind_point: vk.PipelineBindPoint, pipeli
|
||||
try self.dispatch_table.bindPipeline(self, bind_point, pipeline);
|
||||
}
|
||||
|
||||
pub inline fn bindVertexBuffer(self: *Self, index: usize, buffer: *Buffer, offset: usize) VkError!void {
|
||||
try self.dispatch_table.bindVertexBuffer(self, index, buffer, offset);
|
||||
}
|
||||
|
||||
pub inline fn blitImage(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Image, dst_layout: vk.ImageLayout, regions: []const vk.ImageBlit, filter: vk.Filter) VkError!void {
|
||||
try self.dispatch_table.blitImage(self, src, src_layout, dst, dst_layout, regions, filter);
|
||||
}
|
||||
|
||||
pub inline fn clearColorImage(self: *Self, image: *Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, ranges: []const vk.ImageSubresourceRange) VkError!void {
|
||||
pub fn clearColorImage(self: *Self, image: *Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, ranges: []const vk.ImageSubresourceRange) VkError!void {
|
||||
for (ranges) |range| {
|
||||
try self.dispatch_table.clearColorImage(self, image, layout, color, range);
|
||||
}
|
||||
@@ -186,6 +199,14 @@ pub inline fn dispatchIndirect(self: *Self, buffer: *Buffer, offset: vk.DeviceSi
|
||||
try self.dispatch_table.dispatchIndirect(self, buffer, offset);
|
||||
}
|
||||
|
||||
pub inline fn draw(self: *Self, vertex_count: usize, instance_count: usize, first_vertex: usize, first_instance: usize) VkError!void {
|
||||
try self.dispatch_table.draw(self, vertex_count, instance_count, first_vertex, first_instance);
|
||||
}
|
||||
|
||||
pub inline fn endRenderPass(self: *Self) VkError!void {
|
||||
try self.dispatch_table.endRenderPass(self);
|
||||
}
|
||||
|
||||
pub inline fn executeCommands(self: *Self, commands: *Self) VkError!void {
|
||||
try self.dispatch_table.executeCommands(self, commands);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,6 @@ pub inline fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
|
||||
for (self.buffers.items) |non_dis_cmd| {
|
||||
non_dis_cmd.intrusiveDestroy(allocator);
|
||||
}
|
||||
self.buffers.shrinkAndFree(allocator, BUFFER_POOL_BASE_CAPACITY);
|
||||
self.buffers.clearRetainingCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
const ImageView = @import("ImageView.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .framebuffer;
|
||||
|
||||
owner: *Device,
|
||||
width: usize,
|
||||
height: usize,
|
||||
layers: usize,
|
||||
attachments: []*ImageView,
|
||||
|
||||
vtable: *const VTable,
|
||||
|
||||
@@ -19,14 +25,30 @@ pub const VTable = struct {
|
||||
};
|
||||
|
||||
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.FramebufferCreateInfo) VkError!Self {
|
||||
_ = allocator;
|
||||
_ = info;
|
||||
const object_allocator = VulkanAllocator.from(allocator).cloneWithScope(.object);
|
||||
|
||||
const attachments = object_allocator.allocator().alloc(*ImageView, info.attachment_count) catch return VkError.OutOfHostMemory;
|
||||
errdefer object_allocator.allocator().free(attachments);
|
||||
|
||||
if (info.p_attachments) |base_attachements| {
|
||||
for (base_attachements, attachments, 0..info.attachment_count) |base_attachment, *attachment, _| {
|
||||
attachment.* = try NonDispatchable(ImageView).fromHandleObject(base_attachment);
|
||||
}
|
||||
} else {
|
||||
return VkError.ValidationFailed;
|
||||
}
|
||||
|
||||
return .{
|
||||
.owner = device,
|
||||
.width = @intCast(info.width),
|
||||
.height = @intCast(info.height),
|
||||
.layers = @intCast(info.layers),
|
||||
.attachments = attachments,
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
allocator.free(self.attachments);
|
||||
self.vtable.destroy(self, allocator);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
@@ -11,6 +11,7 @@ const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .render_pass;
|
||||
|
||||
owner: *Device,
|
||||
attachments: []vk.AttachmentDescription,
|
||||
|
||||
vtable: *const VTable,
|
||||
|
||||
@@ -19,14 +20,27 @@ pub const VTable = struct {
|
||||
};
|
||||
|
||||
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.RenderPassCreateInfo) VkError!Self {
|
||||
_ = allocator;
|
||||
_ = info;
|
||||
const object_allocator = VulkanAllocator.from(allocator).cloneWithScope(.object);
|
||||
|
||||
const attachments = object_allocator.allocator().alloc(vk.AttachmentDescription, info.attachment_count) catch return VkError.OutOfHostMemory;
|
||||
errdefer object_allocator.allocator().free(attachments);
|
||||
|
||||
if (info.p_attachments) |base_attachements| {
|
||||
for (base_attachements, attachments, 0..info.attachment_count) |base_attachment, *attachment, _| {
|
||||
attachment.* = base_attachment;
|
||||
}
|
||||
} else {
|
||||
return VkError.ValidationFailed;
|
||||
}
|
||||
|
||||
return .{
|
||||
.owner = device,
|
||||
.attachments = attachments,
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
allocator.free(self.attachments);
|
||||
self.vtable.destroy(self, allocator);
|
||||
}
|
||||
|
||||
+12
-25
@@ -1569,10 +1569,10 @@ pub export fn strollWaitForFences(p_device: vk.Device, count: u32, p_fences: [*]
|
||||
|
||||
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err);
|
||||
|
||||
loop: for (p_fences, 0..count) |p_fence, _| {
|
||||
for (p_fences, 0..count) |p_fence, _| {
|
||||
const fence = NonDispatchable(Fence).fromHandleObject(p_fence) catch |err| return toVkResult(err);
|
||||
fence.wait(timeout) catch |err| return toVkResult(err);
|
||||
if (waitForAll == .false) break :loop;
|
||||
if (waitForAll == .false) break;
|
||||
}
|
||||
return .success;
|
||||
}
|
||||
@@ -1612,11 +1612,12 @@ pub export fn strollCmdBeginRenderPass(p_cmd: vk.CommandBuffer, info: *const vk.
|
||||
if (info.s_type != .render_pass_begin_info) {
|
||||
return errorLogger(VkError.ValidationFailed);
|
||||
}
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
const render_pass = NonDispatchable(RenderPass).fromHandleObject(info.render_pass) catch |err| return errorLogger(err);
|
||||
const framebuffer = NonDispatchable(Framebuffer).fromHandleObject(info.framebuffer) catch |err| return errorLogger(err);
|
||||
cmd.beginRenderPass(render_pass, framebuffer, info.render_area, if (info.p_clear_values) |clear_values| clear_values[0..info.clear_value_count] else null) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = contents;
|
||||
}
|
||||
|
||||
@@ -1668,14 +1669,10 @@ pub export fn strollCmdBindVertexBuffers(p_cmd: vk.CommandBuffer, first: u32, co
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = first;
|
||||
_ = count;
|
||||
_ = p_buffers;
|
||||
_ = offsets;
|
||||
for (p_buffers, offsets, 0..count) |p_buffer, offset, i| {
|
||||
const buffer = NonDispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
|
||||
cmd.bindVertexBuffer(first + i, buffer, offset) catch |err| return errorLogger(err);
|
||||
}
|
||||
}
|
||||
|
||||
pub export fn strollCmdBlitImage(
|
||||
@@ -1821,14 +1818,7 @@ pub export fn strollCmdDraw(p_cmd: vk.CommandBuffer, vertex_count: u32, instance
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = vertex_count;
|
||||
_ = instance_count;
|
||||
_ = first_vertex;
|
||||
_ = first_instance;
|
||||
cmd.draw(vertex_count, instance_count, first_vertex, first_instance) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn strollCmdDrawIndexed(p_cmd: vk.CommandBuffer, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: u32, first_instance: u32) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -1897,10 +1887,7 @@ pub export fn strollCmdEndRenderPass(p_cmd: vk.CommandBuffer) callconv(vk.vulkan
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
cmd.endRenderPass() catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn strollCmdExecuteCommands(p_cmd: vk.CommandBuffer, count: u32, p_cmds: [*]const vk.CommandBuffer) callconv(vk.vulkan_call_conv) void {
|
||||
|
||||
Reference in New Issue
Block a user