working on vertex implementation
Build / build (push) Successful in 2m41s
Test / build_and_test (push) Successful in 29m1s

This commit is contained in:
2026-04-26 03:59:36 +02:00
parent 79e0bf483c
commit 6c6d11f063
7 changed files with 167 additions and 44 deletions
+64 -36
View File
@@ -15,21 +15,12 @@ const SoftFramebuffer = @import("../SoftFramebuffer.zig");
const SoftPipeline = @import("../SoftPipeline.zig");
const SoftRenderPass = @import("../SoftRenderPass.zig");
const vertex_dispatcher = @import("vertex_dispatcher.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,
@@ -39,20 +30,7 @@ pub const VertexBuffer = struct {
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,
};
const Vertex = struct {
position: F32x4,
point_size: f32,
index: usize,
};
device: *SoftDevice,
@@ -72,23 +50,73 @@ pub fn init(device: *SoftDevice, state: *PipelineState) Self {
};
}
pub fn drawPrimitive(self: *Self, vertex_count: usize, instance_count: usize, first_vertex: usize, first_instance: usize) void {
const allocator = self.device.device_allocator.allocator();
pub fn draw(self: *Self, vertex_count: usize, instance_count: usize, first_vertex: usize, first_instance: usize) VkError!void {
_ = first_vertex;
_ = first_instance;
const vertices = self.fetchVertexInput(allocator, vertex_count, instance_count, first_vertex, first_instance);
_ = vertices;
self.inputAssemblyStage() catch |err| {
std.log.scoped(.@"Input assembly stage").err("catched a '{s}'", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpErrorReturnTrace(trace);
}
};
self.vertexShaderStage(vertex_count, instance_count) catch |err| {
std.log.scoped(.@"Input assembly stage").err("catched a '{s}'", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpErrorReturnTrace(trace);
}
};
self.primitiveAssemblyStage();
self.fragmentShaderStage();
}
pub fn deinit(self: *Self) void {
_ = self;
}
fn fetchVertexInput(self: *const Self, allocator: std.mem.Allocator, vertex_count: usize, instance_count: usize, first_vertex: usize, first_instance: usize) []Vertex {
_ = self;
_ = allocator;
_ = vertex_count;
_ = instance_count;
_ = first_vertex;
_ = first_instance;
return undefined;
fn inputAssemblyStage(self: *Self) !void {
const pipeline = self.state.pipeline orelse return;
for ((pipeline.stages.getPtr(.vertex) orelse return).runtimes) |*rt| {
for (pipeline.interface.mode.graphics.input_assembly.attribute_description orelse return) |attribute| {
const location_result = try rt.getResultByLocation(attribute.location, .input);
const vertex_buffer = self.state.data.graphics.vertex_buffers[attribute.binding];
const buffer = vertex_buffer.buffer;
const buffer_memory_size = base.format.texelSize(attribute.format);
const buffer_memory = if (buffer.interface.memory) |memory| memory else return VkError.InvalidDeviceMemoryDrv;
const buffer_memory_map: []u8 = @as([*]u8, @ptrCast(@alignCast(try buffer_memory.map(buffer.interface.offset + attribute.offset, buffer_memory_size))))[0..buffer_memory_size];
try rt.writeInput(buffer_memory_map, location_result);
}
}
}
fn vertexShaderStage(self: *Self, vertex_count: usize, instance_count: usize) !void {
const invocation_count = vertex_count * instance_count;
const pipeline = self.state.pipeline orelse return;
const batch_size = (pipeline.stages.getPtr(.vertex) orelse return).runtimes.len;
var wg: std.Io.Group = .init;
for (0..@min(batch_size, invocation_count)) |batch_id| {
const run_data: vertex_dispatcher.RunData = .{
.renderer = self,
.pipeline = pipeline,
.batch_id = batch_id,
.batch_size = batch_size,
.invocation_count = invocation_count,
};
wg.async(self.device.interface.io(), vertex_dispatcher.runWrapper, .{run_data});
}
wg.await(self.device.interface.io()) catch return VkError.DeviceLost;
}
fn primitiveAssemblyStage(self: *Self) void {
_ = self;
}
fn fragmentShaderStage(self: *Self) void {
_ = self;
}