adding some base commadns
This commit is contained in:
@@ -3,15 +3,15 @@ const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const InterfaceFactory = @import("interface").Interface;
|
||||
|
||||
const VkError = base.VkError;
|
||||
const Device = base.Device;
|
||||
const VkError = base.VkError;
|
||||
|
||||
const SoftBuffer = @import("SoftBuffer.zig");
|
||||
const SoftDescriptorSet = @import("SoftDescriptorSet.zig");
|
||||
const SoftFramebuffer = @import("SoftFramebuffer.zig");
|
||||
const SoftImage = @import("SoftImage.zig");
|
||||
const SoftPipeline = @import("SoftPipeline.zig");
|
||||
const SoftDescriptorSet = @import("SoftDescriptorSet.zig");
|
||||
const SoftRenderPass = @import("SoftRenderPass.zig");
|
||||
|
||||
const ExecutionDevice = @import("device/Device.zig");
|
||||
const blitter = @import("device/blitter.zig");
|
||||
@@ -45,8 +45,10 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
|
||||
interface.dispatch_table = &.{
|
||||
.begin = begin,
|
||||
.beginRenderPass = beginRenderPass,
|
||||
.bindDescriptorSets = bindDescriptorSets,
|
||||
.bindPipeline = bindPipeline,
|
||||
.bindVertexBuffer = bindVertexBuffer,
|
||||
.blitImage = blitImage,
|
||||
.clearColorImage = clearColorImage,
|
||||
.copyBuffer = copyBuffer,
|
||||
@@ -55,7 +57,9 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
.copyImageToBuffer = copyImageToBuffer,
|
||||
.dispatch = dispatch,
|
||||
.dispatchIndirect = dispatchIndirect,
|
||||
.draw = draw,
|
||||
.end = end,
|
||||
.endRenderPass = endRenderPass,
|
||||
.executeCommands = executeCommands,
|
||||
.fillBuffer = fillBuffer,
|
||||
.pipelineBarrier = pipelineBarrier,
|
||||
@@ -113,6 +117,36 @@ pub fn reset(interface: *Interface, _: vk.CommandBufferResetFlags) VkError!void
|
||||
|
||||
// Commands ====================================================================================================
|
||||
|
||||
pub fn beginRenderPass(interface: *Interface, render_pass: *base.RenderPass, framebuffer: *base.Framebuffer, render_area: vk.Rect2D, clear_values: ?[]const vk.ClearValue) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
|
||||
const CommandImpl = struct {
|
||||
const Impl = @This();
|
||||
|
||||
render_pass: *SoftRenderPass,
|
||||
framebuffer: *SoftFramebuffer,
|
||||
render_area: vk.Rect2D,
|
||||
clear_values: ?[]const vk.ClearValue,
|
||||
|
||||
pub fn execute(context: *anyopaque, device: *ExecutionDevice) VkError!void {
|
||||
const impl: *Impl = @ptrCast(@alignCast(context));
|
||||
device.renderer.render_pass = impl.render_pass;
|
||||
device.renderer.framebuffer = impl.framebuffer;
|
||||
}
|
||||
};
|
||||
|
||||
const cmd = allocator.create(CommandImpl) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(cmd);
|
||||
cmd.* = .{
|
||||
.render_pass = @alignCast(@fieldParentPtr("interface", render_pass)),
|
||||
.framebuffer = @alignCast(@fieldParentPtr("interface", framebuffer)),
|
||||
.render_area = render_area,
|
||||
.clear_values = clear_values,
|
||||
};
|
||||
self.commands.append(allocator, .{ .ptr = cmd, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn bindDescriptorSets(interface: *Interface, bind_point: vk.PipelineBindPoint, first_set: u32, sets: [base.VULKAN_MAX_DESCRIPTOR_SETS]?*base.DescriptorSet, dynamic_offsets: []const u32) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
@@ -171,6 +205,37 @@ pub fn bindPipeline(interface: *Interface, bind_point: vk.PipelineBindPoint, pip
|
||||
self.commands.append(allocator, .{ .ptr = cmd, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn bindVertexBuffer(interface: *Interface, index: usize, buffer: *base.Buffer, offset: usize) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
|
||||
const CommandImpl = struct {
|
||||
const Impl = @This();
|
||||
|
||||
buffer: *const SoftBuffer,
|
||||
offset: usize,
|
||||
index: usize,
|
||||
|
||||
pub fn execute(context: *anyopaque, device: *ExecutionDevice) VkError!void {
|
||||
const impl: *Impl = @ptrCast(@alignCast(context));
|
||||
device.renderer.dynamic_state.vertex_buffers[impl.index] = .{
|
||||
.buffer = impl.buffer,
|
||||
.offset = impl.offset,
|
||||
.size = 0,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const cmd = allocator.create(CommandImpl) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(cmd);
|
||||
cmd.* = .{
|
||||
.buffer = @alignCast(@fieldParentPtr("interface", buffer)),
|
||||
.offset = offset,
|
||||
.index = index,
|
||||
};
|
||||
self.commands.append(allocator, .{ .ptr = cmd, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn blitImage(interface: *Interface, src: *base.Image, _: vk.ImageLayout, dst: *base.Image, _: vk.ImageLayout, regions: []const vk.ImageBlit, filter: vk.Filter) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
@@ -361,7 +426,7 @@ pub fn dispatch(interface: *Interface, group_count_x: u32, group_count_y: u32, g
|
||||
|
||||
pub fn execute(context: *anyopaque, device: *ExecutionDevice) VkError!void {
|
||||
const impl: *Impl = @ptrCast(@alignCast(context));
|
||||
try device.compute_routines.dispatch(impl.group_count_x, impl.group_count_y, impl.group_count_z);
|
||||
try device.compute.dispatch(impl.group_count_x, impl.group_count_y, impl.group_count_z);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -390,7 +455,7 @@ pub fn dispatchIndirect(interface: *Interface, buffer: *base.Buffer, offset: vk.
|
||||
const size = 3 * @sizeOf(u32);
|
||||
const memory = if (impl.buffer.interface.memory) |memory| memory else return VkError.InvalidDeviceMemoryDrv;
|
||||
const map: []u32 = @as([*]u32, @ptrCast(@alignCast(try memory.map(impl.offset, size))))[0..3];
|
||||
try device.compute_routines.dispatch(map[0], map[1], map[2]);
|
||||
try device.compute.dispatch(map[0], map[1], map[2]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -403,6 +468,50 @@ pub fn dispatchIndirect(interface: *Interface, buffer: *base.Buffer, offset: vk.
|
||||
self.commands.append(allocator, .{ .ptr = cmd, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn draw(interface: *Interface, vertex_count: usize, instance_count: usize, first_vertex: usize, first_instance: usize) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
|
||||
const CommandImpl = struct {
|
||||
const Impl = @This();
|
||||
|
||||
vertex_count: usize,
|
||||
first_vertex: usize,
|
||||
instance_count: usize,
|
||||
first_instance: usize,
|
||||
|
||||
pub fn execute(context: *anyopaque, device: *ExecutionDevice) VkError!void {
|
||||
const impl: *Impl = @ptrCast(@alignCast(context));
|
||||
_ = impl;
|
||||
_ = device;
|
||||
}
|
||||
};
|
||||
|
||||
const cmd = allocator.create(CommandImpl) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(cmd);
|
||||
cmd.* = .{
|
||||
.vertex_count = vertex_count,
|
||||
.first_vertex = first_vertex,
|
||||
.instance_count = instance_count,
|
||||
.first_instance = first_instance,
|
||||
};
|
||||
self.commands.append(allocator, .{ .ptr = cmd, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn endRenderPass(interface: *Interface) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
|
||||
const CommandImpl = struct {
|
||||
pub fn execute(_: *anyopaque, device: *ExecutionDevice) VkError!void {
|
||||
device.renderer.render_pass = null;
|
||||
device.renderer.framebuffer = null;
|
||||
}
|
||||
};
|
||||
|
||||
self.commands.append(allocator, .{ .ptr = undefined, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
|
||||
pub fn executeCommands(interface: *Interface, commands: *Interface) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const allocator = self.command_allocator.allocator();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
const root = @import("lib.zig");
|
||||
const lib = @import("lib.zig");
|
||||
const cpuinfo = @cImport(@cInclude("cpuinfo.h"));
|
||||
|
||||
const SoftDevice = @import("SoftDevice.zig");
|
||||
@@ -34,9 +34,9 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance) VkError!*S
|
||||
.release = destroy,
|
||||
};
|
||||
|
||||
interface.props.api_version = @bitCast(root.VULKAN_VERSION);
|
||||
interface.props.driver_version = @bitCast(root.DRIVER_VERSION);
|
||||
interface.props.device_id = root.DEVICE_ID;
|
||||
interface.props.api_version = @bitCast(lib.VULKAN_VERSION);
|
||||
interface.props.driver_version = @bitCast(lib.DRIVER_VERSION);
|
||||
interface.props.device_id = lib.DEVICE_ID;
|
||||
interface.props.device_type = .cpu;
|
||||
interface.props.limits = .{
|
||||
.max_image_dimension_1d = 4096,
|
||||
@@ -68,8 +68,8 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance) VkError!*S
|
||||
.max_descriptor_set_sampled_images = 96,
|
||||
.max_descriptor_set_storage_images = 24,
|
||||
.max_descriptor_set_input_attachments = 4,
|
||||
.max_vertex_input_attributes = 16,
|
||||
.max_vertex_input_bindings = 16,
|
||||
.max_vertex_input_attributes = lib.MAX_VERTEX_INPUT_ATTRIBUTES,
|
||||
.max_vertex_input_bindings = lib.MAX_VERTEX_INPUT_BINDINGS,
|
||||
.max_vertex_input_attribute_offset = 2047,
|
||||
.max_vertex_input_binding_stride = 2048,
|
||||
.max_vertex_output_components = 64,
|
||||
@@ -207,7 +207,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance) VkError!*S
|
||||
defer command_allocator.free(name);
|
||||
|
||||
var writer = std.Io.Writer.fixed(device_name[0 .. vk.MAX_PHYSICAL_DEVICE_NAME_SIZE - 1]);
|
||||
writer.print("{s} [" ++ root.DRIVER_NAME ++ " StrollDriver]", .{name}) catch return VkError.InitializationFailed;
|
||||
writer.print("{s} [" ++ lib.DRIVER_NAME ++ " StrollDriver]", .{name}) catch return VkError.InitializationFailed;
|
||||
}
|
||||
|
||||
@memcpy(&interface.props.device_name, &device_name);
|
||||
|
||||
@@ -92,8 +92,7 @@ fn taskRunner(self: *Self, info: Interface.SubmitInfo, p_fence: ?*base.Fence, ru
|
||||
command_buffers.deinit(soft_device.device_allocator.allocator());
|
||||
}
|
||||
|
||||
var execution_device: ExecutionDevice = .init;
|
||||
execution_device.setup(soft_device);
|
||||
var execution_device: ExecutionDevice = .init(soft_device);
|
||||
defer execution_device.deinit();
|
||||
|
||||
for (info.command_buffers.items) |command_buffer| {
|
||||
|
||||
@@ -4,7 +4,7 @@ const base = @import("base");
|
||||
const spv = @import("spv");
|
||||
const lib = @import("../lib.zig");
|
||||
|
||||
const PipelineState = @import("PipelineState.zig");
|
||||
const PipelineState = @import("Device.zig").PipelineState;
|
||||
|
||||
const SoftDevice = @import("../SoftDevice.zig");
|
||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||
@@ -45,7 +45,7 @@ pub fn init(device: *SoftDevice, state: *PipelineState) Self {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn destroy(self: *Self) void {
|
||||
pub fn deinit(self: *Self) void {
|
||||
_ = self;
|
||||
}
|
||||
|
||||
+19
-10
@@ -4,36 +4,45 @@ const base = @import("base");
|
||||
|
||||
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
||||
const SoftDevice = @import("../SoftDevice.zig");
|
||||
const SoftFramebuffer = @import("../SoftFramebuffer.zig");
|
||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||
const SoftRenderPass = @import("../SoftRenderPass.zig");
|
||||
|
||||
const ComputeRoutines = @import("ComputeRoutines.zig");
|
||||
const PipelineState = @import("PipelineState.zig");
|
||||
const ComputeDispatcher = @import("ComputeDispatcher.zig");
|
||||
const Renderer = @import("Renderer.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
compute_routines: ComputeRoutines,
|
||||
pub const PipelineState = struct {
|
||||
pipeline: ?*SoftPipeline,
|
||||
sets: [base.VULKAN_MAX_DESCRIPTOR_SETS]?*SoftDescriptorSet,
|
||||
};
|
||||
|
||||
compute: ComputeDispatcher,
|
||||
renderer: Renderer,
|
||||
|
||||
/// .graphics = 0
|
||||
/// .compute = 1
|
||||
pipeline_states: [2]PipelineState,
|
||||
|
||||
pub const init: Self = .{
|
||||
.compute_routines = undefined,
|
||||
.pipeline_states = undefined,
|
||||
};
|
||||
pub fn init(device: *SoftDevice) Self {
|
||||
var self: Self = undefined;
|
||||
|
||||
pub fn setup(self: *Self, device: *SoftDevice) void {
|
||||
for (self.pipeline_states[0..]) |*state| {
|
||||
state.* = .{
|
||||
.pipeline = null,
|
||||
.sets = [_]?*SoftDescriptorSet{null} ** base.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||
};
|
||||
}
|
||||
self.compute_routines = .init(device, &self.pipeline_states[@intFromEnum(vk.PipelineBindPoint.compute)]);
|
||||
self.compute = .init(device, &self.pipeline_states[@intFromEnum(vk.PipelineBindPoint.compute)]);
|
||||
self.renderer = .init();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
self.compute_routines.destroy();
|
||||
self.compute.deinit();
|
||||
self.renderer.deinit();
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
|
||||
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||
|
||||
pipeline: ?*SoftPipeline,
|
||||
sets: [base.VULKAN_MAX_DESCRIPTOR_SETS]?*SoftDescriptorSet,
|
||||
@@ -0,0 +1,63 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
const lib = @import("../lib.zig");
|
||||
|
||||
const SoftBuffer = @import("../SoftBuffer.zig");
|
||||
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
||||
const SoftDevice = @import("../SoftDevice.zig");
|
||||
const SoftFramebuffer = @import("../SoftFramebuffer.zig");
|
||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||
const SoftRenderPass = @import("../SoftRenderPass.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
const VertexInputBindingState = struct {
|
||||
input_rate: vk.VertexInputRate,
|
||||
stride: usize,
|
||||
};
|
||||
|
||||
const VertexInputAttributeState = struct {
|
||||
format: vk.Format,
|
||||
offset: usize,
|
||||
binding: usize,
|
||||
};
|
||||
|
||||
pub const VertexBuffer = struct {
|
||||
buffer: *const SoftBuffer,
|
||||
offset: usize,
|
||||
size: usize,
|
||||
};
|
||||
|
||||
pub const DynamicState = struct {
|
||||
viewport: vk.Viewport,
|
||||
scissor: vk.Rect2D,
|
||||
|
||||
line_width: f32,
|
||||
cull_mode: vk.CullModeFlags,
|
||||
front_face: vk.FrontFace,
|
||||
primitive_topology: vk.PrimitiveTopology,
|
||||
|
||||
vertex_input_bindings: [lib.MAX_VERTEX_INPUT_BINDINGS]VertexInputBindingState,
|
||||
vertex_input_attributes: [lib.MAX_VERTEX_INPUT_ATTRIBUTES]VertexInputAttributeState,
|
||||
|
||||
vertex_buffers: [lib.MAX_VERTEX_INPUT_BINDINGS]VertexBuffer,
|
||||
};
|
||||
|
||||
render_pass: ?*SoftRenderPass,
|
||||
framebuffer: ?*SoftFramebuffer,
|
||||
dynamic_state: DynamicState,
|
||||
|
||||
pub fn init() Self {
|
||||
return .{
|
||||
.render_pass = null,
|
||||
.framebuffer = null,
|
||||
.dynamic_state = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
_ = self;
|
||||
}
|
||||
@@ -55,6 +55,9 @@ pub const MIN_UNIFORM_BUFFER_ALIGNMENT = 256;
|
||||
/// Vulkan 1.2 requires buffer offset alignment to be at most 256.
|
||||
pub const MIN_STORAGE_BUFFER_ALIGNMENT = 256;
|
||||
|
||||
pub const MAX_VERTEX_INPUT_BINDINGS = 16;
|
||||
pub const MAX_VERTEX_INPUT_ATTRIBUTES = 32;
|
||||
|
||||
pub const std_options = base.std_options;
|
||||
|
||||
comptime {
|
||||
|
||||
Reference in New Issue
Block a user