From 67353d9b1c47f053dc4bef9399bc97e16a0df4d9 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Sat, 21 Mar 2026 05:19:45 +0100 Subject: [PATCH] adding spirv interpreter results table dump --- .gitignore | 1 + build.zig | 2 ++ build.zig.zon | 4 ++-- src/soft/device/ComputeRoutines.zig | 35 +++++++++++++++++++++++++++++ src/soft/lib.zig | 4 +++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index dbcf264..5ae5879 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ scripts/__pycache__/ *.html *.pyc *.spv +*_table_dump.txt diff --git a/build.zig b/build.zig index 73f56fd..ac39cc1 100644 --- a/build.zig +++ b/build.zig @@ -299,6 +299,8 @@ fn addMultithreadedCTS(b: *std.Build, target: std.Build.ResolvedTarget, impl: *c run.addArg(b.fmt("{s}{s}", .{ cache_path, mustpass_path })); run.addArg("--output"); run.addArg("./cts"); + run.addArg("--timeout"); + run.addArg("300"); if (jobs_count) |count| { run.addArg(b.fmt("-j{d}", .{count})); } diff --git a/build.zig.zon b/build.zig.zon index caecb6e..a3b78c5 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -59,8 +59,8 @@ .lazy = true, }, .SPIRV_Interpreter = .{ - .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#fe47277468c694b10153282761efd3d6f90d8f6a", - .hash = "SPIRV_Interpreter-0.0.1-ajmpn2u-AwAPdrXzLzxHPezx3Kkb63hkecdY0oPEJ2ad", + .url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#569d7fda01340f2fc195d868df7d3fc583f900bd", + .hash = "SPIRV_Interpreter-0.0.1-ajmpn3PFAwD7uWTP4W8ULr8mLWlV5BiqvfOIsLyYjDij", }, }, diff --git a/src/soft/device/ComputeRoutines.zig b/src/soft/device/ComputeRoutines.zig index 710318e..778aed1 100644 --- a/src/soft/device/ComputeRoutines.zig +++ b/src/soft/device/ComputeRoutines.zig @@ -29,11 +29,19 @@ device: *SoftDevice, state: *PipelineState, batch_size: usize, +invocation_index: std.atomic.Value(usize), + +early_dump: ?u32, +final_dump: ?u32, + pub fn init(device: *SoftDevice, state: *PipelineState) Self { return .{ .device = device, .state = state, .batch_size = 0, + .invocation_index = .init(0), + .early_dump = std.process.parseEnvVarInt(lib.DUMP_EARLY_RESULT_TABLE_ENV_NAME, u32, 10) catch null, + .final_dump = std.process.parseEnvVarInt(lib.DUMP_FINAL_RESULT_TABLE_ENV_NAME, u32, 10) catch null, }; } @@ -51,6 +59,8 @@ pub fn dispatch(self: *Self, group_count_x: u32, group_count_y: u32, group_count const invocations_per_workgroup = spv_module.local_size_x * spv_module.local_size_y * spv_module.local_size_z; + self.invocation_index.store(0, .monotonic); + var wg: std.Thread.WaitGroup = .{}; for (0..@min(self.batch_size, group_count)) |batch_id| { if (std.process.hasEnvVarConstant(lib.SINGLE_THREAD_COMPUTE_EXECUTION_ENV_NAME)) { @@ -128,12 +138,19 @@ inline fn run(data: RunData) !void { }); for (0..data.invocations_per_workgroup) |i| { + const invocation_index = data.self.invocation_index.fetchAdd(1, .monotonic); + try setupSubgroupBuiltins(data.self, rt, .{ @as(u32, @intCast(group_x)), @as(u32, @intCast(group_y)), @as(u32, @intCast(group_z)), }, i); + if (data.self.early_dump != null and data.self.early_dump.? == invocation_index) { + @branchHint(.cold); + try dumpResultsTable(allocator, rt, true); + } + rt.callEntryPoint(allocator, entry) catch |err| switch (err) { // Some errors can be ignored SpvRuntimeError.OutOfBounds, @@ -141,11 +158,29 @@ inline fn run(data: RunData) !void { => {}, else => return err, }; + + if (data.self.final_dump != null and data.self.final_dump.? == invocation_index) { + @branchHint(.cold); + try dumpResultsTable(allocator, rt, false); + } + try rt.flushDescriptorSets(allocator); } } } +inline fn dumpResultsTable(allocator: std.mem.Allocator, rt: *spv.Runtime, is_early: bool) !void { + @branchHint(.cold); + const file = try std.fs.cwd().createFile( + std.fmt.comptimePrint("{s}_compute_result_table_dump.txt", .{if (is_early) "early" else "final"}), + .{ .truncate = true }, + ); + defer file.close(); + var buffer = [_]u8{0} ** 1024; + var writer = file.writer(buffer[0..]); + try rt.dumpResultsTable(allocator, &writer.interface); +} + fn writeDescriptorSets(self: *Self, rt: *spv.Runtime) !void { sets: for (self.state.sets[0..], 0..) |set, set_index| { if (set == null) diff --git a/src/soft/lib.zig b/src/soft/lib.zig index 93fb7bb..0c9570f 100644 --- a/src/soft/lib.zig +++ b/src/soft/lib.zig @@ -41,7 +41,9 @@ pub const DRIVER_VERSION = vk.makeApiVersion(0, 0, 0, 1); pub const DEVICE_ID = 0x600DCAFE; pub const NO_SHADER_SIMD_ENV_NAME = "STROLL_SOFT_NO_SIMD"; -pub const SINGLE_THREAD_COMPUTE_EXECUTION_ENV_NAME = "STROLL_SINGLE_THREAD_COMPUTE_EXECUTION"; +pub const SINGLE_THREAD_COMPUTE_EXECUTION_ENV_NAME = "STROLL_SOFT_SINGLE_THREAD_COMPUTE_EXECUTION"; +pub const DUMP_EARLY_RESULT_TABLE_ENV_NAME = "STROLL_SOFT_DUMP_EARLY_RESULT_TABLE_FOR_INVOCATION"; +pub const DUMP_FINAL_RESULT_TABLE_ENV_NAME = "STROLL_SOFT_DUMP_FINAL_RESULT_TABLE_FOR_INVOCATION"; /// Generic system memory. pub const MEMORY_TYPE_GENERIC_BIT = 0;