From ac7bf53d9486d6c9a079a818dc87891551eaeac1 Mon Sep 17 00:00:00 2001 From: Mick Sayson Date: Mon, 6 Jul 2026 17:12:49 -0700 Subject: [PATCH] hardcode opengl float type alignment fixes compilation of attached test case --- src/Type.zig | 4 ++-- test/cases/storage_buffer_opengl.zig | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/cases/storage_buffer_opengl.zig diff --git a/src/Type.zig b/src/Type.zig index 0e54f7c51f36c9a88558c792b7fed439929f68c7..fc867194e3f3ebe2a3a772946a0f57d90d87dbe9 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -1019,8 +1019,8 @@ pub fn abiAlignment(ty: Type, zcu: *const Zcu) Alignment { .c_longdouble => cTypeAlign(target, .longdouble), .f16 => .@"2", - .f32 => cTypeAlign(target, .float), - .f64 => switch (target.cTypeBitSize(.double)) { + .f32 => if (target.os.tag == .opengl) .@"4" else cTypeAlign(target, .float), + .f64 => if (target.os.tag == .opengl) .@"8" else switch (target.cTypeBitSize(.double)) { 64 => cTypeAlign(target, .double), else => .@"8", }, diff --git a/test/cases/storage_buffer_opengl.zig b/test/cases/storage_buffer_opengl.zig new file mode 100644 index 0000000000000000000000000000000000000000..495cf165a7e1f07bb24c2c621b00c1d8a2a66124 --- /dev/null +++ b/test/cases/storage_buffer_opengl.zig @@ -0,0 +1,27 @@ +const std = @import("std"); + +const RuntimeArray = @SpirvType(.{ .runtime_array = @Vector(4, f32) }); +const Buffer = extern struct { + data: RuntimeArray, +}; + +const output = @extern(*addrspace(.storage_buffer) Buffer, .{ + .name = "output", + .decoration = .{ .descriptor = .{ .set = 0, .binding = 0 } }, +}); + +const num_segments = 20; + +export fn main() callconv(.{ .spirv_kernel = .{ .x = 1, .y = 1, .z = 1 } }) void { + const val = std.spirv.global_invocation_id[0]; + if (val > num_segments) return; + var val_f: f32 = @floatFromInt(val); + val_f /= num_segments; + output.data[val] = .{ val_f, val_f, 0, 1 }; +} + +// compile +// output_mode=Obj +// backend=auto +// target=spirv32-opengl +// emit_bin=true -- 2.54.0