adding draw indexed
This commit is contained in:
@@ -18,6 +18,9 @@ pub const RunData = struct {
|
||||
batch_id: usize,
|
||||
batch_size: usize,
|
||||
vertex_count: usize,
|
||||
first_vertex: usize,
|
||||
first_instance: usize,
|
||||
indices: ?[]const u32,
|
||||
instance_index: usize,
|
||||
draw_call: *Renderer.DrawCall,
|
||||
};
|
||||
@@ -41,7 +44,10 @@ inline fn run(data: RunData) !void {
|
||||
|
||||
var invocation_index: usize = data.batch_id;
|
||||
while (invocation_index < data.vertex_count) : (invocation_index += data.batch_size) {
|
||||
setupBuiltins(rt, invocation_index, data.instance_index) catch |err| switch (err) {
|
||||
const vertex_index = if (data.indices) |indices| indices[invocation_index] else data.first_vertex + invocation_index;
|
||||
const instance_index = data.first_instance + data.instance_index;
|
||||
|
||||
setupBuiltins(rt, vertex_index, instance_index) catch |err| switch (err) {
|
||||
SpvRuntimeError.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
@@ -56,7 +62,7 @@ inline fn run(data: RunData) !void {
|
||||
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 offset = buffer.interface.offset + (binding_info.stride * invocation_index) + attribute.offset;
|
||||
const offset = buffer.interface.offset + vertex_buffer.offset + (binding_info.stride * vertex_index) + attribute.offset;
|
||||
|
||||
const buffer_memory_map: []u8 = @as([*]u8, @ptrCast(@alignCast(try buffer_memory.map(offset, buffer_memory_size))))[0..buffer_memory_size];
|
||||
|
||||
@@ -89,7 +95,7 @@ inline fn run(data: RunData) !void {
|
||||
}
|
||||
}
|
||||
|
||||
fn setupBuiltins(rt: *spv.Runtime, invocation_index: usize, instance_index: usize) !void {
|
||||
try rt.writeBuiltIn(std.mem.asBytes(&invocation_index), .VertexIndex);
|
||||
fn setupBuiltins(rt: *spv.Runtime, vertex_index: usize, instance_index: usize) !void {
|
||||
try rt.writeBuiltIn(std.mem.asBytes(&vertex_index), .VertexIndex);
|
||||
try rt.writeBuiltIn(std.mem.asBytes(&instance_index), .InstanceIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user