authorgravatar for mick@sayson.comMick Sayson <mick@sayson.com> 2026-07-06 17:12:49-07:00
committergravatar for alichraghi@noreply.codeberg.orgAli Cheraghi <alichraghi@noreply.codeberg.org> 2026-07-08 16:43:51+02:00
logac7bf53d9486d6c9a079a818dc87891551eaeac1
treec23c684d2e395f5447a5afc80d708a33f3cf999d
parent93905c89057e9d7020aa2e6130bde7cd91ac4484

hardcode opengl float type alignment

fixes compilation of attached test case

2 files changed, 29 insertions(+), 2 deletions(-)

src/Type.zig+2-2
...@@ -1019,8 +1019,8 @@ pub fn abiAlignment(ty: Type, zcu: *const Zcu) Alignment {...@@ -1019,8 +1019,8 @@ pub fn abiAlignment(ty: Type, zcu: *const Zcu) Alignment {
1019 .c_longdouble => cTypeAlign(target, .longdouble),1019 .c_longdouble => cTypeAlign(target, .longdouble),
10201020
1021 .f16 => .@"2",1021 .f16 => .@"2",
1022 .f32 => cTypeAlign(target, .float),1022 .f32 => if (target.os.tag == .opengl) .@"4" else cTypeAlign(target, .float),
1023 .f64 => switch (target.cTypeBitSize(.double)) {1023 .f64 => if (target.os.tag == .opengl) .@"8" else switch (target.cTypeBitSize(.double)) {
1024 64 => cTypeAlign(target, .double),1024 64 => cTypeAlign(target, .double),
1025 else => .@"8",1025 else => .@"8",
1026 },1026 },
test/cases/storage_buffer_opengl.zig created+27
...@@ -0,0 +1,27 @@
1const std = @import("std");
2
3const RuntimeArray = @SpirvType(.{ .runtime_array = @Vector(4, f32) });
4const Buffer = extern struct {
5 data: RuntimeArray,
6};
7
8const output = @extern(*addrspace(.storage_buffer) Buffer, .{
9 .name = "output",
10 .decoration = .{ .descriptor = .{ .set = 0, .binding = 0 } },
11});
12
13const num_segments = 20;
14
15export 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