| 1 | const std = @import("std"); |
| 2 | |
| 3 | const RuntimeArray = @SpirvType(.{ .runtime_array = @Vector(4, f32) }); |
| 4 | const Buffer = extern struct { |
| 5 | data: RuntimeArray, |
| 6 | }; |
| 7 | |
| 8 | const output = @extern(*addrspace(.storage_buffer) Buffer, .{ |
| 9 | .name = "output", |
| 10 | .decoration = .{ .descriptor = .{ .set = 0, .binding = 0 } }, |
| 11 | }); |
| 12 | |
| 13 | const num_segments = 20; |
| 14 | |
| 15 | export fn main() callconv(.{ .spirv_kernel = .{ .x = 1, .y = 1, .z = 1 } }) void { |
| 16 | const val = std.spirv.global_invocation_id[0]; |
| 17 | if (val > num_segments) return; |
| 18 | var val_f: f32 = @floatFromInt(val); |
| 19 | val_f /= num_segments; |
| 20 | output.data[val] = .{ val_f, val_f, 0, 1 }; |
| 21 | } |
| 22 | |
| 23 | // compile |
| 24 | // output_mode=Obj |
| 25 | // backend=auto |
| 26 | // target=spirv32-opengl |
| 27 | // emit_bin=true |