From 1f8415f1b28bc99387047bf72abf573e3ca61091 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Tue, 27 Jan 2026 22:56:03 +0100 Subject: [PATCH] fixing crashes --- .gitignore | 1 + build.zig | 1 + build.zig.zon | 9 ++++--- src/soft/SoftShaderModule.zig | 10 +++---- src/vulkan/DescriptorSetLayout.zig | 3 +++ src/vulkan/ShaderModule.zig | 43 ++---------------------------- src/vulkan/lib.zig | 2 -- src/vulkan/lib_vulkan.zig | 2 ++ 8 files changed, 18 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 92930e5..dbcf264 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ scripts/__pycache__/ *.xml *.html *.pyc +*.spv diff --git a/build.zig b/build.zig index 66ebe20..ab24017 100644 --- a/build.zig +++ b/build.zig @@ -32,6 +32,7 @@ pub fn build(b: *std.Build) !void { const zdt = b.dependency("zdt", .{}).module("zdt"); const zigrc = b.dependency("zigrc", .{}).module("zigrc"); + //const spv_tools = b.dependency("SPIRV_Tools", .{}).module("zigrc"); const vulkan_headers = b.dependency("vulkan_headers", .{}); const vulkan_utility_libraries = b.dependency("vulkan_utility_libraries", .{}); diff --git a/build.zig.zon b/build.zig.zon index b22cd80..511e029 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,6 +5,10 @@ .minimum_zig_version = "0.15.2", .dependencies = .{ + //.SPIRV_Tools = .{ + // .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Toolz#2eed675251bbcf21ef34368d289be49d83bce781", + // .hash = "SPIRV_Tools-2026.1.0-7hzMwUeVAAA2Q60MBfoAvZypYnJ9Rzf-hxUkZAaJAo57", + //}, .compile_commands = .{ .url = "git+https://github.com/the-argus/zig-compile-commands#f74e2d13e43fafab3a71e19557a0e1cfbf0f2e1b", .hash = "zig_compile_commands-0.0.1-OZg5-a3CAACM-h32Kjb1obTMqrKGs9YoDhorVZ8-LGle", @@ -34,9 +38,8 @@ .hash = "zigrc-1.0.0-lENlWzvQAACulrbkL9PVhWjFsWSkYhi7AmfSbCM-2Xlh", }, .SPIRV_Interpreter = .{ - .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#e21d26d9975b96a222b70648ceeea9e473e9657f", - .hash = "SPIRV_Interpreter-0.0.1-ajmpn2tAAwCBI0oWa3VKlYX3MEM0OxN4iXQ-PwO6_Vhx", - //.path = "../SPIRV-Interpreter", + .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#57de432d0b43f050b5117a7c6add09e3906664fd", + .hash = "SPIRV_Interpreter-0.0.1-ajmpnyg_AwCeuAEr4KMaBqdCWA2IUsT8Q3mGuUo1PZ2b", }, .cpuinfo = .{ .url = "git+https://github.com/Kbz-8/cpuinfo#4883954cfcec3f6c9ca9c4aaddfc26107e08726f", diff --git a/src/soft/SoftShaderModule.zig b/src/soft/SoftShaderModule.zig index 0d19f27..66f44c4 100644 --- a/src/soft/SoftShaderModule.zig +++ b/src/soft/SoftShaderModule.zig @@ -27,13 +27,9 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v self.* = .{ .interface = interface, - .module = spv.Module.init( - allocator, - code, - .{ - .use_simd_vectors_specializations = !std.process.hasEnvVarConstant(lib.NO_SHADER_SIMD_ENV_NAME), - }, - ) catch |err| switch (err) { + .module = spv.Module.init(allocator, code, .{ + .use_simd_vectors_specializations = !std.process.hasEnvVarConstant(lib.NO_SHADER_SIMD_ENV_NAME), + }) catch |err| switch (err) { spv.Module.ModuleError.OutOfMemory => return VkError.OutOfHostMemory, else => return VkError.ValidationFailed, }, diff --git a/src/vulkan/DescriptorSetLayout.zig b/src/vulkan/DescriptorSetLayout.zig index c247ca3..98e9c87 100644 --- a/src/vulkan/DescriptorSetLayout.zig +++ b/src/vulkan/DescriptorSetLayout.zig @@ -30,5 +30,8 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr } pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void { + if (self.bindings) |bindings| { + allocator.free(bindings); + } self.vtable.destroy(self, allocator); } diff --git a/src/vulkan/ShaderModule.zig b/src/vulkan/ShaderModule.zig index 66404eb..c13dd00 100644 --- a/src/vulkan/ShaderModule.zig +++ b/src/vulkan/ShaderModule.zig @@ -20,12 +20,8 @@ pub const VTable = struct { }; pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) VkError!Self { - if (std.process.hasEnvVarConstant(lib.DRIVER_LOG_SPIRV_ENV_NAME)) { - logShaderModule(allocator, info) catch |e| { - std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text: {s}", .{@errorName(e)}); - }; - } - + _ = allocator; + _ = info; return .{ .owner = device, .vtable = undefined, @@ -35,38 +31,3 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Shade pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void { self.vtable.destroy(self, allocator); } - -fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) !void { - std.log.scoped(.ShaderModule).info("Logging SPIR-V module", .{}); - - var process = std.process.Child.init(&[_][]const u8{ "spirv-dis", "/home/kbz_8/Documents/Code/Zig/SPIRV-Interpreter/example/shader.spv" }, allocator); - - process.stdout_behavior = .Pipe; - process.stderr_behavior = .Pipe; - process.stdin_behavior = .Pipe; - - var stdout: std.ArrayList(u8) = .empty; - defer stdout.deinit(allocator); - var stderr: std.ArrayList(u8) = .empty; - defer stderr.deinit(allocator); - - try process.spawn(); - errdefer { - _ = process.kill() catch {}; - } - - _ = info; - //try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024); - //if (process.stdin) |stdin| { - // _ = try stdin.write(@as([*]const u8, @ptrCast(info.p_code))[0..info.code_size]); - //} else { - // std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.", .{}); - //} - _ = try process.wait(); - - if (stderr.items.len != 0) { - std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.\n{s}", .{stderr.items}); - } else if (stdout.items.len != 0) { - std.log.scoped(.ShaderModule).info("{s}\n{d}", .{ stdout.items, stdout.items.len }); - } -} diff --git a/src/vulkan/lib.zig b/src/vulkan/lib.zig index 4f510b1..93e13cd 100644 --- a/src/vulkan/lib.zig +++ b/src/vulkan/lib.zig @@ -50,8 +50,6 @@ pub const VULKAN_VENDOR_ID = @typeInfo(vk.VendorId).@"enum".fields[@typeInfo(vk. pub const DRIVER_DEBUG_ALLOCATOR_ENV_NAME = "STROLL_DEBUG_ALLOCATOR"; pub const DRIVER_LOGS_ENV_NAME = "STROLL_LOGS_LEVEL"; -pub const DRIVER_LOG_SPIRV_ENV_NAME = "STROLL_LOG_SPIRV"; - /// Default driver name pub const DRIVER_NAME = "Unnamed Stroll Driver"; /// Default Vulkan version diff --git a/src/vulkan/lib_vulkan.zig b/src/vulkan/lib_vulkan.zig index a286fb4..c6f3ffb 100644 --- a/src/vulkan/lib_vulkan.zig +++ b/src/vulkan/lib_vulkan.zig @@ -741,6 +741,7 @@ pub export fn strollCreateComputePipelines(p_device: vk.Device, p_cache: vk.Pipe defer entryPointEndLogTrace(); const allocator = VulkanAllocator.init(callbacks, .object).allocator(); + const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err); const cache = if (p_cache == .null_handle) null else NonDispatchable(PipelineCache).fromHandleObject(p_cache) catch |err| return toVkResult(err); @@ -772,6 +773,7 @@ pub export fn strollCreateComputePipelines(p_device: vk.Device, p_cache: vk.Pipe global_res = local_res; } } + return global_res; }