adding SSBO unit test
All checks were successful
Build / build (push) Successful in 1m49s
Test / build (push) Successful in 4m36s

This commit is contained in:
2026-03-07 15:20:02 +01:00
parent 7bf671d974
commit 16eb184808
2 changed files with 78 additions and 1 deletions

View File

@@ -23,7 +23,9 @@ pub const case = struct {
pub const Config = struct {
source: []const u32,
inputs: []const []const u8 = &.{},
expected_outputs: []const []const u8,
expected_outputs: []const []const u8 = &.{},
descriptor_sets: []const []const []const u8 = &.{},
expected_descriptor_sets: []const []const []const u8 = &.{},
};
pub fn expect(config: Config) !void {
@@ -50,6 +52,12 @@ pub const case = struct {
try rt.writeInput(input[0..], module.input_locations[n]);
}
for (config.descriptor_sets, 0..) |descriptor_set, set_index| {
for (descriptor_set, 0..) |descriptor_binding, binding_index| {
try rt.writeDescriptorSet(allocator, descriptor_binding, @intCast(set_index), @intCast(binding_index));
}
}
try rt.callEntryPoint(allocator, try rt.getEntryPointByName("main"));
for (config.expected_outputs, 0..) |expected, n| {
@@ -59,6 +67,16 @@ pub const case = struct {
try rt.readOutput(output[0..], module.output_locations[n]);
try std.testing.expectEqualSlices(u8, expected, output);
}
for (config.expected_descriptor_sets, 0..) |expected_descriptor_set, set_index| {
for (expected_descriptor_set, 0..) |expected_descriptor_binding, binding_index| {
const data = try allocator.alloc(u8, expected_descriptor_binding.len);
defer allocator.free(data);
try rt.readDescriptorSet(data, @intCast(set_index), @intCast(binding_index));
try std.testing.expectEqualSlices(u8, expected_descriptor_binding, data);
}
}
}
}
@@ -104,4 +122,5 @@ test {
std.testing.refAllDecls(@import("inputs.zig"));
std.testing.refAllDecls(@import("loops.zig"));
std.testing.refAllDecls(@import("maths.zig"));
std.testing.refAllDecls(@import("ssbo.zig"));
}

58
test/ssbo.zig git.filemode.normal_file
View File

@@ -0,0 +1,58 @@
const std = @import("std");
const root = @import("root.zig");
const compileNzsl = root.compileNzsl;
const case = root.case;
test "Simple SSBO" {
const allocator = std.testing.allocator;
const shader =
\\ [nzsl_version("1.1")]
\\ module;
\\
\\ [layout(std430)]
\\ struct SSBO
\\ {
\\ data: dyn_array[u32]
\\ }
\\
\\ external
\\ {
\\ [set(0), binding(0)] ssbo: storage[SSBO],
\\ }
\\
\\ [entry(compute)]
\\ [workgroup(16, 1, 1)]
\\ fn main()
\\ {
\\ for i in 0 -> 256
\\ {
\\ ssbo.data[i] = u32(i);
\\ }
\\ }
;
const code = try compileNzsl(allocator, shader);
defer allocator.free(code);
var expected = [_]u32{0} ** 256;
for (expected[0..], 0..) |*val, i| {
val.* = @intCast(i);
}
try case.expect(.{
.source = code,
.descriptor_sets = &.{
// Set 0
&.{
// Binding 0
std.mem.asBytes(&[_]u32{0} ** 256),
},
},
.expected_descriptor_sets = &.{
// Set 0
&.{
// Binding 0
std.mem.asBytes(&expected),
},
},
});
}