removing dependency
Test / build (push) Failing after 40s
Build / build (push) Failing after 41s

This commit is contained in:
2026-07-04 21:04:25 +02:00
parent 589d30168f
commit 72001d9728
11 changed files with 5 additions and 760 deletions
+1 -109
View File
@@ -27,121 +27,13 @@ pub fn build(b: *std.Build) void {
.use_llvm = use_llvm,
});
const install_spv_lib = b.addInstallArtifact(spv_lib, .{});
b.installArtifact(spv_lib);
addSandbox(b, target, optimize, use_llvm, spv_mod, &install_spv_lib.step);
addExample(b, target, optimize, use_llvm, spv_mod, &install_spv_lib.step);
addZigTests(b, target, optimize, use_llvm, spv_mod, zmath);
addCffi(b, target, optimize, use_llvm, spv_mod);
addDocs(b, spv_mod);
}
fn addExample(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
use_llvm: bool,
spv_mod: *std.Build.Module,
install_spv_lib_step: *std.Build.Step,
) void {
const no_example = b.option(bool, "no-example", "Skip example build") orelse false;
if (!no_example) {
const sdl3 = b.lazyDependency("sdl3", .{
.target = target,
.optimize = optimize,
}) orelse return;
const exe = b.addExecutable(.{
.name = "spirv_interpreter_example",
.root_module = b.createModule(.{
.root_source_file = b.path("example/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "spv", .module = spv_mod },
.{ .name = "sdl3", .module = sdl3.module("sdl3") },
},
}),
.use_llvm = use_llvm,
});
const install_exe = b.addInstallArtifact(exe, .{});
install_exe.step.dependOn(install_spv_lib_step);
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
const run_step = b.step("example", "Run the example");
run_step.dependOn(&run_exe.step);
addShaderCompileStep(
b,
"example-shader",
"Compile example shader using nzslc",
"example/shader.nzsl",
"example",
);
}
}
fn addSandbox(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
use_llvm: bool,
spv_mod: *std.Build.Module,
install_spv_lib_step: *std.Build.Step,
) void {
const exe = b.addExecutable(.{
.name = "spirv_interpreter_sandbox",
.root_module = b.createModule(.{
.root_source_file = b.path("sandbox/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "spv", .module = spv_mod },
},
}),
.use_llvm = use_llvm,
});
const install_exe = b.addInstallArtifact(exe, .{});
install_exe.step.dependOn(install_spv_lib_step);
const run_exe = b.addRunArtifact(exe);
run_exe.step.dependOn(&install_exe.step);
const run_step = b.step("sandbox", "Run the sandbox");
run_step.dependOn(&run_exe.step);
addShaderCompileStep(
b,
"sandbox-shader",
"Compile sandbox shader using nzslc",
"sandbox/shader.nzsl",
"sandbox",
);
}
fn addShaderCompileStep(
b: *std.Build,
step_name: []const u8,
description: []const u8,
shader_path: []const u8,
output_dir: []const u8,
) void {
const cmd = b.addSystemCommand(&.{
"nzslc",
shader_path,
"--compile=spv,spv-dis",
"-o",
output_dir,
});
const step = b.step(step_name, description);
step.dependOn(&cmd.step);
}
fn addZigTests(
b: *std.Build,
target: std.Build.ResolvedTarget,
+4 -7
View File
@@ -1,6 +1,10 @@
.{
.name = .SPIRV_Interpreter,
.version = "1.0.0",
.fingerprint = 0xd87ec8ab9fa9396a,
.minimum_zig_version = "0.16.0",
.dependencies = .{
.zmath = .{
.url = "git+https://github.com/zig-gamedev/zmath.git#3a5955b2b72cd081563fbb084eff05bffd1e3fbb",
@@ -11,22 +15,15 @@
.hash = "NZSL-1.1.5-N0xSVHV7AAB168H2nqMDYY0hjUXtXJ9_eQGNHasSr9r8",
.lazy = true,
},
.sdl3 = .{
.url = "git+https://codeberg.org/7Games/zig-sdl3?ref=v0.2.0#40c2e4b579aa556db37a502c936426aa1c8b5c95",
.hash = "sdl3-0.2.0-NmT1Q0mFJwBi9kZmArzh2rfJ_mFshydV0zPGULVlpACc",
.lazy = true,
},
.pretty = .{
.url = "git+https://github.com/Kbz-8/pretty.git#f91d534d033277ca1ae7fcd598a070e8b3ddc532",
.hash = "pretty-0.10.6-Tm65r7FTAQA5BEL8tcIcF-Wp4XRC7J7BhuRI0KUnFj2X",
},
},
.minimum_zig_version = "0.16.0",
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"LICENSE",
},
.fingerprint = 0xd87ec8ab9fa9396a,
}
-152
View File
@@ -1,152 +0,0 @@
const std = @import("std");
const sdl3 = @import("sdl3");
const spv = @import("spv");
const shader_source = @embedFile("shader.spv");
const screen_width = 400;
const screen_height = 240;
pub fn main() !void {
{
//var gpa: std.heap.DebugAllocator(.{}) = .init;
//defer _ = gpa.deinit();
const allocator = std.heap.smp_allocator;
var threaded: std.Io.Threaded = .init(allocator, .{
.async_limit = @enumFromInt(screen_height),
});
defer threaded.deinit();
const io = threaded.io();
defer sdl3.shutdown();
const init_flags = sdl3.InitFlags{ .video = true, .events = true };
try sdl3.init(init_flags);
defer sdl3.quit(init_flags);
const window = try sdl3.video.Window.init("Hello triangle", screen_width, screen_height, .{});
defer window.deinit();
const surface = try window.getSurface();
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
defer module.deinit(allocator);
const fragment_count = screen_height * screen_width;
const batch_size = switch (threaded.async_limit) {
.nothing => 1,
.unlimited => std.Thread.getCpuCount() catch 1, // If we cannot get the CPU count, fallback on single runtime
else => |count| @intFromEnum(count),
};
const runners: []Runner = try allocator.alloc(Runner, batch_size);
defer {
for (runners) |*runner| {
runner.rt.deinit(allocator);
}
allocator.free(runners);
}
for (runners) |*runner| {
var rt = try spv.Runtime.init(allocator, &module, undefined);
runner.* = .{
.allocator = allocator,
.surface = surface,
.rt = rt,
.entry = try rt.getEntryPointByName("main"),
.color = try rt.getResultByName("color"),
.time = try rt.getResultByName("time"),
.pos = try rt.getResultByName("pos"),
.res = try rt.getResultByName("res"),
.invocation_count = fragment_count,
.batch_size = batch_size,
};
}
const timer = std.Io.Timestamp.now(io, .real);
var wg: std.Io.Group = .init;
var quit = false;
while (!quit) {
try surface.clear(.{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 1.0 });
while (sdl3.events.poll()) |event|
switch (event) {
.quit => quit = true,
.terminating => quit = true,
else => {},
};
{
try surface.lock();
defer surface.unlock();
const pixel_map: [*]u32 = @as([*]u32, @ptrCast(@alignCast((surface.getPixels() orelse return).ptr)));
const duration = timer.untilNow(io, .real);
const delta: f32 = @as(f32, @floatFromInt(duration.toNanoseconds())) / std.time.ns_per_s;
for (0..@min(batch_size, fragment_count)) |batch_id| {
wg.async(io, Runner.runWrapper, .{ &runners[batch_id], batch_id, pixel_map, delta });
}
try wg.await(io);
}
try window.updateSurface();
}
}
std.log.info("Successfully executed", .{});
}
const Runner = struct {
const Self = @This();
allocator: std.mem.Allocator,
surface: sdl3.surface.Surface,
rt: spv.Runtime,
entry: spv.SpvWord,
color: spv.SpvWord,
time: spv.SpvWord,
pos: spv.SpvWord,
res: spv.SpvWord,
invocation_count: usize,
batch_size: usize,
fn runWrapper(self: *Self, batch_id: usize, pixel_map: [*]u32, timer: f32) void {
@call(.always_inline, Self.run, .{ self, batch_id, pixel_map, timer }) catch |err| {
std.log.err("{s}", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
std.debug.dumpErrorReturnTrace(trace);
}
std.process.abort();
};
}
fn run(self: *Self, batch_id: usize, pixel_map: [*]u32, timer: f32) !void {
var rt = self.rt; // Copy to avoid pointer access of `self` at runtime. Okay as Runtime contains only pointers and trivially copyable fields
var output: [4]f32 = undefined;
var invocation_index: usize = batch_id;
while (invocation_index < self.invocation_count) : (invocation_index += self.batch_size) {
const y = @divTrunc(invocation_index, screen_width);
const x = @mod(invocation_index, screen_width);
try rt.writeInput(std.mem.asBytes(&timer), self.time);
try rt.writeInput(std.mem.asBytes(&[_]f32{ @floatFromInt(screen_width), @floatFromInt(screen_height) }), self.res);
try rt.writeInput(std.mem.asBytes(&[_]f32{ @floatFromInt(x), @floatFromInt(y) }), self.pos);
try rt.callEntryPoint(self.allocator, self.entry);
try rt.readOutput(std.mem.asBytes(output[0..]), self.color);
const rgba = self.surface.mapRgba(
@intCast(std.math.clamp(@as(i32, @intFromFloat(output[0] * 255.0)), 0, 255)),
@intCast(std.math.clamp(@as(i32, @intFromFloat(output[1] * 255.0)), 0, 255)),
@intCast(std.math.clamp(@as(i32, @intFromFloat(output[2] * 255.0)), 0, 255)),
@intCast(std.math.clamp(@as(i32, @intFromFloat(output[3] * 255.0)), 0, 255)),
);
pixel_map[invocation_index] = rgba.value;
}
}
};
-6
View File
@@ -1,6 +0,0 @@
gpu_stats=0
font_size=16
resolution
hud_compact
background_alpha=0
width=140
-68
View File
@@ -1,68 +0,0 @@
[nzsl_version("1.1")]
module;
struct FragIn
{
[location(0)] time: f32,
[location(1)] res: vec2[f32],
[location(2)] pos: vec2[f32],
}
struct FragOut
{
[location(0)] color: vec4[f32]
}
[entry(frag)]
fn main(input: FragIn) -> FragOut
{
const I: i32 = 128;
const A: f32 = 7.5;
const MA: f32 = 100.0;
const MI: f32 = 0.001;
let uv0 = input.pos / input.res * 2.0 - vec2[f32](1.0, 1.0);
let uv = vec2[f32](uv0.x * (input.res.x / input.res.y), uv0.y);
let col = vec3[f32](0.0, 0.0, 0.0);
let ro = vec3[f32](0.0, 0.0, -2.0);
let rd = vec3[f32](uv.x, uv.y, 1.0);
let dt = 0.0;
let ds = 0.0;
let dm = -1.0;
let p = ro;
let c = vec3[f32](0.0, 0.0, 0.0);
let l = vec3[f32](0.0, sin(input.time * 0.2) * 4.0, cos(input.time * 0.2) * 4.0);
for i in 0 -> I
{
p = ro + rd * dt;
ds = length(c - p) - 1.0;
dt += ds;
if (dm == -1.0 || ds < dm)
dm = ds;
if (ds <= MI)
{
let value = max(dot(normalize(c - p), normalize(p - l)) - 0.35, 0.0);
col = vec3[f32](value, value, value);
break;
}
if (ds >= MA)
{
if (dot(normalize(rd), normalize(l - ro)) <= 1.0)
{
let value = max(dot(normalize(rd), normalize(l - ro)) + 0.15, 0.05)/ 1.15 * (1.0 - dm * A);
col = vec3[f32](value, value, value);
}
break;
}
}
let output: FragOut;
output.color = vec4[f32](col.x, col.y, col.z, 1.0);
return output;
}
Binary file not shown.
-281
View File
@@ -1,281 +0,0 @@
Version 1.0
Generator: 2560130
Bound: 203
Schema: 0
OpCapability Capability(Shader)
%42 = OpExtInstImport "GLSL.std.450"
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(Fragment) %43 "main" %5 %11 %14 %20
OpExecutionMode %43 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(NZSL) 4198400
OpSourceExtension "Version: 1.1"
OpName %16 "FragIn"
OpMemberName %16 0 "time"
OpMemberName %16 1 "res"
OpMemberName %16 2 "pos"
OpName %21 "FragOut"
OpMemberName %21 0 "color"
OpName %5 "time"
OpName %11 "res"
OpName %14 "pos"
OpName %20 "color"
OpName %43 "main"
OpDecorate %5 Decoration(Location) 0
OpDecorate %11 Decoration(Location) 1
OpDecorate %14 Decoration(Location) 2
OpDecorate %20 Decoration(Location) 0
OpMemberDecorate %16 0 Decoration(Offset) 0
OpMemberDecorate %16 1 Decoration(Offset) 8
OpMemberDecorate %16 2 Decoration(Offset) 16
OpMemberDecorate %21 0 Decoration(Offset) 0
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpTypeFloat 32
%4 = OpTypePointer StorageClass(Input) %3
%6 = OpTypeInt 32 1
%7 = OpConstant %6 i32(0)
%8 = OpTypePointer StorageClass(Function) %3
%9 = OpTypeVector %3 2
%10 = OpTypePointer StorageClass(Input) %9
%12 = OpConstant %6 i32(1)
%13 = OpTypePointer StorageClass(Function) %9
%15 = OpConstant %6 i32(2)
%16 = OpTypeStruct %3 %9 %9
%17 = OpTypePointer StorageClass(Function) %16
%18 = OpTypeVector %3 4
%19 = OpTypePointer StorageClass(Output) %18
%21 = OpTypeStruct %18
%22 = OpConstant %3 f32(2)
%23 = OpConstant %3 f32(1)
%24 = OpConstant %3 f32(0)
%25 = OpTypeVector %3 3
%26 = OpTypePointer StorageClass(Function) %25
%27 = OpConstant %3 f32(-2)
%28 = OpConstant %3 f32(-1)
%29 = OpConstant %3 f32(0.2)
%30 = OpConstant %3 f32(4)
%31 = OpTypePointer StorageClass(Function) %6
%32 = OpConstant %6 i32(128)
%33 = OpTypeBool
%34 = OpConstant %3 f32(0.001)
%35 = OpConstant %3 f32(0.35)
%36 = OpConstant %3 f32(100)
%37 = OpConstant %3 f32(0.15)
%38 = OpConstant %3 f32(0.05)
%39 = OpConstant %3 f32(1.15)
%40 = OpConstant %3 f32(7.5)
%41 = OpTypePointer StorageClass(Function) %21
%200 = OpTypePointer StorageClass(Function) %18
%5 = OpVariable %4 StorageClass(Input)
%11 = OpVariable %10 StorageClass(Input)
%14 = OpVariable %10 StorageClass(Input)
%20 = OpVariable %19 StorageClass(Output)
%43 = OpFunction %1 FunctionControl(0) %2
%44 = OpLabel
%45 = OpVariable %13 StorageClass(Function)
%46 = OpVariable %13 StorageClass(Function)
%47 = OpVariable %26 StorageClass(Function)
%48 = OpVariable %26 StorageClass(Function)
%49 = OpVariable %26 StorageClass(Function)
%50 = OpVariable %8 StorageClass(Function)
%51 = OpVariable %8 StorageClass(Function)
%52 = OpVariable %8 StorageClass(Function)
%53 = OpVariable %26 StorageClass(Function)
%54 = OpVariable %26 StorageClass(Function)
%55 = OpVariable %26 StorageClass(Function)
%56 = OpVariable %31 StorageClass(Function)
%57 = OpVariable %31 StorageClass(Function)
%58 = OpVariable %8 StorageClass(Function)
%59 = OpVariable %8 StorageClass(Function)
%60 = OpVariable %41 StorageClass(Function)
%61 = OpVariable %17 StorageClass(Function)
%62 = OpAccessChain %8 %61 %7
OpCopyMemory %62 %5
%63 = OpAccessChain %13 %61 %12
OpCopyMemory %63 %11
%64 = OpAccessChain %13 %61 %15
OpCopyMemory %64 %14
%65 = OpAccessChain %13 %61 %15
%66 = OpLoad %9 %65
%67 = OpAccessChain %13 %61 %12
%68 = OpLoad %9 %67
%69 = OpFDiv %9 %66 %68
%70 = OpVectorTimesScalar %9 %69 %22
%71 = OpCompositeConstruct %9 %23 %23
%72 = OpFSub %9 %70 %71
OpStore %45 %72
%73 = OpLoad %9 %45
%74 = OpCompositeExtract %3 %73 0
%75 = OpAccessChain %13 %61 %12
%76 = OpLoad %9 %75
%77 = OpCompositeExtract %3 %76 0
%78 = OpAccessChain %13 %61 %12
%79 = OpLoad %9 %78
%80 = OpCompositeExtract %3 %79 1
%81 = OpFDiv %3 %77 %80
%82 = OpFMul %3 %74 %81
%83 = OpLoad %9 %45
%84 = OpCompositeExtract %3 %83 1
%85 = OpCompositeConstruct %9 %82 %84
OpStore %46 %85
%86 = OpCompositeConstruct %25 %24 %24 %24
OpStore %47 %86
%87 = OpCompositeConstruct %25 %24 %24 %27
OpStore %48 %87
%88 = OpLoad %9 %46
%89 = OpCompositeExtract %3 %88 0
%90 = OpLoad %9 %46
%91 = OpCompositeExtract %3 %90 1
%92 = OpCompositeConstruct %25 %89 %91 %23
OpStore %49 %92
OpStore %50 %24
OpStore %51 %24
OpStore %52 %28
%93 = OpLoad %25 %48
OpStore %53 %93
%94 = OpCompositeConstruct %25 %24 %24 %24
OpStore %54 %94
%95 = OpAccessChain %8 %61 %7
%96 = OpLoad %3 %95
%97 = OpFMul %3 %96 %29
%98 = OpExtInst %3 GLSLstd450 Sin %97
%99 = OpFMul %3 %98 %30
%100 = OpAccessChain %8 %61 %7
%101 = OpLoad %3 %100
%102 = OpFMul %3 %101 %29
%103 = OpExtInst %3 GLSLstd450 Cos %102
%104 = OpFMul %3 %103 %30
%105 = OpCompositeConstruct %25 %24 %99 %104
OpStore %55 %105
OpStore %56 %7
OpStore %57 %32
OpBranch %106
%106 = OpLabel
%110 = OpLoad %6 %56
%111 = OpLoad %6 %57
%112 = OpSLessThan %33 %110 %111
OpLoopMerge %108 %109 LoopControl(0)
OpBranchConditional %112 %107 %108
%107 = OpLabel
%113 = OpLoad %25 %48
%114 = OpLoad %25 %49
%115 = OpLoad %3 %50
%116 = OpVectorTimesScalar %25 %114 %115
%117 = OpFAdd %25 %113 %116
OpStore %53 %117
%118 = OpLoad %25 %54
%119 = OpLoad %25 %53
%120 = OpFSub %25 %118 %119
%121 = OpExtInst %3 GLSLstd450 Length %120
%122 = OpFSub %3 %121 %23
OpStore %51 %122
%123 = OpLoad %3 %50
%124 = OpLoad %3 %51
%125 = OpFAdd %3 %123 %124
OpStore %50 %125
%129 = OpLoad %3 %52
%130 = OpFOrdEqual %33 %129 %28
%131 = OpLoad %3 %51
%132 = OpLoad %3 %52
%133 = OpFOrdLessThan %33 %131 %132
%134 = OpLogicalOr %33 %130 %133
OpSelectionMerge %126 SelectionControl(0)
OpBranchConditional %134 %127 %128
%127 = OpLabel
%135 = OpLoad %3 %51
OpStore %52 %135
OpBranch %126
%128 = OpLabel
OpBranch %126
%126 = OpLabel
%139 = OpLoad %3 %51
%140 = OpFOrdLessThanEqual %33 %139 %34
OpSelectionMerge %136 SelectionControl(0)
OpBranchConditional %140 %137 %138
%137 = OpLabel
%141 = OpLoad %25 %54
%142 = OpLoad %25 %53
%143 = OpFSub %25 %141 %142
%144 = OpExtInst %25 GLSLstd450 Normalize %143
%145 = OpLoad %25 %53
%146 = OpLoad %25 %55
%147 = OpFSub %25 %145 %146
%148 = OpExtInst %25 GLSLstd450 Normalize %147
%149 = OpDot %3 %144 %148
%150 = OpFSub %3 %149 %35
%151 = OpExtInst %3 GLSLstd450 FMax %150 %24
OpStore %58 %151
%152 = OpLoad %3 %58
%153 = OpLoad %3 %58
%154 = OpLoad %3 %58
%155 = OpCompositeConstruct %25 %152 %153 %154
OpStore %47 %155
OpBranch %108
%138 = OpLabel
OpBranch %136
%136 = OpLabel
%159 = OpLoad %3 %51
%160 = OpFOrdGreaterThanEqual %33 %159 %36
OpSelectionMerge %156 SelectionControl(0)
OpBranchConditional %160 %157 %158
%157 = OpLabel
%164 = OpLoad %25 %49
%165 = OpExtInst %25 GLSLstd450 Normalize %164
%166 = OpLoad %25 %55
%167 = OpLoad %25 %48
%168 = OpFSub %25 %166 %167
%169 = OpExtInst %25 GLSLstd450 Normalize %168
%170 = OpDot %3 %165 %169
%171 = OpFOrdLessThanEqual %33 %170 %23
OpSelectionMerge %161 SelectionControl(0)
OpBranchConditional %171 %162 %163
%162 = OpLabel
%172 = OpLoad %25 %49
%173 = OpExtInst %25 GLSLstd450 Normalize %172
%174 = OpLoad %25 %55
%175 = OpLoad %25 %48
%176 = OpFSub %25 %174 %175
%177 = OpExtInst %25 GLSLstd450 Normalize %176
%178 = OpDot %3 %173 %177
%179 = OpFAdd %3 %178 %37
%180 = OpExtInst %3 GLSLstd450 FMax %179 %38
%181 = OpFDiv %3 %180 %39
%182 = OpLoad %3 %52
%183 = OpFMul %3 %182 %40
%184 = OpFSub %3 %23 %183
%185 = OpFMul %3 %181 %184
OpStore %59 %185
%186 = OpLoad %3 %59
%187 = OpLoad %3 %59
%188 = OpLoad %3 %59
%189 = OpCompositeConstruct %25 %186 %187 %188
OpStore %47 %189
OpBranch %161
%163 = OpLabel
OpBranch %161
%161 = OpLabel
OpBranch %108
%158 = OpLabel
OpBranch %156
%156 = OpLabel
%190 = OpLoad %6 %56
%191 = OpIAdd %6 %190 %12
OpStore %56 %191
OpBranch %109
%109 = OpLabel
OpBranch %106
%108 = OpLabel
%192 = OpLoad %25 %47
%193 = OpCompositeExtract %3 %192 0
%194 = OpLoad %25 %47
%195 = OpCompositeExtract %3 %194 1
%196 = OpLoad %25 %47
%197 = OpCompositeExtract %3 %196 2
%198 = OpCompositeConstruct %18 %193 %195 %197 %23
%199 = OpAccessChain %200 %60 %7
OpStore %199 %198
%201 = OpLoad %21 %60
%202 = OpCompositeExtract %18 %201 0
OpStore %20 %202
OpReturn
OpFunctionEnd
-53
View File
@@ -1,53 +0,0 @@
const std = @import("std");
const spv = @import("spv");
const shader_source = @embedFile("shader.spv");
const SSBO = struct {
value: [256]i32 = [_]i32{0} ** 256,
};
pub fn main() !void {
{
var gpa: std.heap.DebugAllocator(.{
.enable_memory_limit = true,
}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
defer module.deinit(allocator);
var rt = try spv.Runtime.init(allocator, &module);
defer rt.deinit(allocator);
const entry = try rt.getEntryPointByName("main");
var ssbo: SSBO = .{};
try rt.writeDescriptorSet(std.mem.asBytes(&ssbo), 0, 0, 0);
for (0..16) |i| {
for (0..16) |x| {
const global_invocation_indices = [3]i32{
@as(i32, @intCast(i * 16 + x)),
1,
1,
};
try rt.writeBuiltIn(std.mem.asBytes(&global_invocation_indices), .GlobalInvocationId);
rt.callEntryPoint(allocator, entry) catch |err| switch (err) {
spv.Runtime.RuntimeError.OutOfBounds => continue,
else => return err,
};
try rt.flushDescriptorSets(allocator);
}
}
std.log.info("Output: {any}", .{ssbo});
std.log.info("Total memory used: {d:.3} KB\n", .{@as(f32, @floatFromInt(gpa.total_requested_bytes)) / 1000.0});
}
std.log.info("Successfully executed", .{});
}
-25
View File
@@ -1,25 +0,0 @@
[nzsl_version("1.1")]
module;
struct Input
{
[builtin(global_invocation_indices)] indices: vec3[u32]
}
[layout(std430)]
struct SSBO
{
data: dyn_array[i32]
}
external
{
[set(0), binding(0)] ssbo: storage[SSBO],
}
[entry(compute)]
[workgroup(16, 1, 1)]
fn main(input: Input)
{
ssbo.data[input.indices.x] = i32(input.indices.x);
}
Binary file not shown.
-59
View File
@@ -1,59 +0,0 @@
Version 1.0
Generator: 2560130
Bound: 32
Schema: 0
OpCapability Capability(Shader)
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(GLCompute) %17 "main" %11
OpExecutionMode %17 ExecutionMode(LocalSize) 16 1 1
OpSource SourceLanguage(NZSL) 4198400
OpSourceExtension "Version: 1.1"
OpName %3 "SSBO"
OpMemberName %3 0 "data"
OpName %14 "Input"
OpMemberName %14 0 "indices"
OpName %5 "ssbo"
OpName %11 "global_invocation_indices"
OpName %17 "main"
OpDecorate %5 Decoration(Binding) 0
OpDecorate %5 Decoration(DescriptorSet) 0
OpDecorate %11 Decoration(BuiltIn) BuiltIn(GlobalInvocationId)
OpDecorate %2 Decoration(ArrayStride) 4
OpDecorate %3 Decoration(BufferBlock)
OpMemberDecorate %3 0 Decoration(Offset) 0
OpMemberDecorate %14 0 Decoration(Offset) 0
%1 = OpTypeInt 32 1
%2 = OpTypeRuntimeArray %1
%3 = OpTypeStruct %2
%4 = OpTypePointer StorageClass(Uniform) %3
%6 = OpTypeVoid
%7 = OpTypeFunction %6
%8 = OpTypeInt 32 0
%9 = OpTypeVector %8 3
%10 = OpTypePointer StorageClass(Input) %9
%12 = OpConstant %1 i32(0)
%13 = OpTypePointer StorageClass(Function) %9
%14 = OpTypeStruct %9
%15 = OpTypePointer StorageClass(Function) %14
%16 = OpTypeRuntimeArray %1
%26 = OpTypePointer StorageClass(Uniform) %2
%31 = OpTypePointer StorageClass(Uniform) %1
%5 = OpVariable %4 StorageClass(Uniform)
%11 = OpVariable %10 StorageClass(Input)
%17 = OpFunction %6 FunctionControl(0) %7
%18 = OpLabel
%19 = OpVariable %15 StorageClass(Function)
%20 = OpAccessChain %13 %19 %12
OpCopyMemory %20 %11
%21 = OpAccessChain %13 %19 %12
%22 = OpLoad %9 %21
%23 = OpCompositeExtract %8 %22 0
%24 = OpBitcast %1 %23
%25 = OpAccessChain %26 %5 %12
%27 = OpAccessChain %13 %19 %12
%28 = OpLoad %9 %27
%29 = OpCompositeExtract %8 %28 0
%30 = OpAccessChain %31 %25 %29
OpStore %30 %24
OpReturn
OpFunctionEnd