From 621be5db352a05864de8b7e4f7963304fb922f64 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Thu, 30 Apr 2026 00:26:50 +0200 Subject: [PATCH] base index draw --- build.zig.zon | 5 +++-- src/soft/SoftCommandBuffer.zig | 29 +++++++++++++++++++++++++++++ src/vulkan/CommandBuffer.zig | 5 +++++ src/vulkan/lib_vulkan.zig | 8 +------- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index ed06482..2e8d922 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -31,11 +31,12 @@ .hash = "zmath-0.11.0-dev-wjwivdMsAwD-xaLj76YHUq3t9JDH-X16xuMTmnDzqbu2", }, .SPIRV_Interpreter = .{ - .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#ce172090044354d5ea70f1bf79bd077fb6722e29", - .hash = "SPIRV_Interpreter-0.0.1-ajmpn2cbBQA67LOLx5fml7Uf7iRw32jwOZh0ZIX4YJyh", + .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#5faf8fd30548f8bd96a18568fb21de698db64ca8", + .hash = "SPIRV_Interpreter-0.0.1-ajmpn_crBQAl1X8EYgNQjoTn_3XZ1DDOBCZMpfyD6MTu", .lazy = true, }, //.SPIRV_Interpreter = .{ + // // For development // .path = "../SPIRV-Interpreter", // .lazy = true, //}, diff --git a/src/soft/SoftCommandBuffer.zig b/src/soft/SoftCommandBuffer.zig index c01b7e4..71840b6 100644 --- a/src/soft/SoftCommandBuffer.zig +++ b/src/soft/SoftCommandBuffer.zig @@ -48,6 +48,7 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v .beginRenderPass = beginRenderPass, .bindDescriptorSets = bindDescriptorSets, .bindPipeline = bindPipeline, + .bindIndexBuffer = bindIndexBuffer, .bindVertexBuffer = bindVertexBuffer, .blitImage = blitImage, .clearAttachment = clearAttachment, @@ -226,6 +227,34 @@ 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 bindIndexBuffer(interface: *Interface, buffer: *base.Buffer, offset: usize, index_type: vk.IndexType) 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_type: vk.IndexType, + + 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.* = .{ + .buffer = @alignCast(@fieldParentPtr("interface", buffer)), + .offset = offset, + .index_type = index_type, + }; + 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(); diff --git a/src/vulkan/CommandBuffer.zig b/src/vulkan/CommandBuffer.zig index cd60f4b..2b482b2 100644 --- a/src/vulkan/CommandBuffer.zig +++ b/src/vulkan/CommandBuffer.zig @@ -42,6 +42,7 @@ pub const DispatchTable = struct { 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, + bindIndexBuffer: *const fn (*Self, *Buffer, usize, vk.IndexType) 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, clearAttachment: *const fn (*Self, vk.ClearAttachment, vk.ClearRect) VkError!void, @@ -163,6 +164,10 @@ pub inline fn bindPipeline(self: *Self, bind_point: vk.PipelineBindPoint, pipeli try self.dispatch_table.bindPipeline(self, bind_point, pipeline); } +pub inline fn bindIndexBuffer(self: *Self, buffer: *Buffer, offset: usize, index_type: vk.IndexType) VkError!void { + try self.dispatch_table.bindIndexBuffer(self, buffer, offset, index_type); +} + pub inline fn bindVertexBuffer(self: *Self, index: usize, buffer: *Buffer, offset: usize) VkError!void { try self.dispatch_table.bindVertexBuffer(self, index, buffer, offset); } diff --git a/src/vulkan/lib_vulkan.zig b/src/vulkan/lib_vulkan.zig index d20c34b..d969e54 100644 --- a/src/vulkan/lib_vulkan.zig +++ b/src/vulkan/lib_vulkan.zig @@ -1651,13 +1651,7 @@ pub export fn strollCmdBindIndexBuffer(p_cmd: vk.CommandBuffer, p_buffer: vk.Buf const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err); const buffer = NonDispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err); - - notImplementedWarning(); - - _ = cmd; - _ = buffer; - _ = offset; - _ = index_type; + cmd.bindIndexBuffer(buffer, offset, index_type) catch |err| return errorLogger(err); } pub export fn strollCmdBindPipeline(p_cmd: vk.CommandBuffer, bind_point: vk.PipelineBindPoint, p_pipeline: vk.Pipeline) callconv(vk.vulkan_call_conv) void {