authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-17 01:51:47+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:36:44-07:00
log18d0909adaac1ba67a06d92632423a435e4458f4
treee45453b0d4695281d3fe154223eb7cf35afeadd7
parent66036e600058081ce2f9248fd221900dce793cdd

spirv: fixes


1 files changed, 21 insertions(+), 20 deletions(-)

src/codegen/spirv.zig+21-20
...@@ -708,7 +708,7 @@ pub const DeclGen = struct {...@@ -708,7 +708,7 @@ pub const DeclGen = struct {
708 const elem_ty = array_type.child.toType();708 const elem_ty = array_type.child.toType();
709 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);709 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
710710
711 const constituents = try self.gpa.alloc(IdRef, ty.arrayLenIncludingSentinel(mod));711 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));
712 defer self.gpa.free(constituents);712 defer self.gpa.free(constituents);
713713
714 switch (aggregate.storage) {714 switch (aggregate.storage) {
...@@ -1289,19 +1289,19 @@ pub const DeclGen = struct {...@@ -1289,19 +1289,19 @@ pub const DeclGen = struct {
1289 }1289 }
12901290
1291 const UnionLayout = struct {1291 const UnionLayout = struct {
1292 active_field: usize,1292 active_field: u32,
1293 active_field_ty: Type,1293 active_field_ty: Type,
1294 payload_size: usize,1294 payload_size: u32,
12951295
1296 tag_size: usize,1296 tag_size: u32,
1297 tag_index: usize,1297 tag_index: u32,
1298 active_field_size: usize,1298 active_field_size: u32,
1299 active_field_index: usize,1299 active_field_index: u32,
1300 payload_padding_size: usize,1300 payload_padding_size: u32,
1301 payload_padding_index: usize,1301 payload_padding_index: u32,
1302 padding_size: usize,1302 padding_size: u32,
1303 padding_index: usize,1303 padding_index: u32,
1304 total_fields: usize,1304 total_fields: u32,
1305 };1305 };
13061306
1307 fn unionLayout(self: *DeclGen, ty: Type, maybe_active_field: ?usize) UnionLayout {1307 fn unionLayout(self: *DeclGen, ty: Type, maybe_active_field: ?usize) UnionLayout {
...@@ -1314,28 +1314,28 @@ pub const DeclGen = struct {...@@ -1314,28 +1314,28 @@ pub const DeclGen = struct {
1314 const active_field_ty = union_obj.field_types.get(ip)[active_field].toType();1314 const active_field_ty = union_obj.field_types.get(ip)[active_field].toType();
13151315
1316 var union_layout = UnionLayout{1316 var union_layout = UnionLayout{
1317 .active_field = active_field,1317 .active_field = @intCast(active_field),
1318 .active_field_ty = active_field_ty,1318 .active_field_ty = active_field_ty,
1319 .payload_size = layout.payload_size,1319 .payload_size = @intCast(layout.payload_size),
1320 .tag_size = layout.tag_size,1320 .tag_size = @intCast(layout.tag_size),
1321 .tag_index = undefined,1321 .tag_index = undefined,
1322 .active_field_size = undefined,1322 .active_field_size = undefined,
1323 .active_field_index = undefined,1323 .active_field_index = undefined,
1324 .payload_padding_size = undefined,1324 .payload_padding_size = undefined,
1325 .payload_padding_index = undefined,1325 .payload_padding_index = undefined,
1326 .padding_size = layout.padding,1326 .padding_size = @intCast(layout.padding),
1327 .padding_index = undefined,1327 .padding_index = undefined,
1328 .total_fields = undefined,1328 .total_fields = undefined,
1329 };1329 };
13301330
1331 union_layout.active_field_size = if (active_field_ty.hasRuntimeBitsIgnoreComptime(mod))1331 union_layout.active_field_size = if (active_field_ty.hasRuntimeBitsIgnoreComptime(mod))
1332 active_field_ty.abiSize(mod)1332 @intCast(active_field_ty.abiSize(mod))
1333 else1333 else
1334 0;1334 0;
1335 union_layout.payload_padding_size = layout.payload_size - union_layout.active_field_size;1335 union_layout.payload_padding_size = @intCast(layout.payload_size - union_layout.active_field_size);
13361336
1337 const tag_first = layout.tag_align.compare(.gte, layout.payload_align);1337 const tag_first = layout.tag_align.compare(.gte, layout.payload_align);
1338 var field_index: usize = 0;1338 var field_index: u32 = 0;
13391339
1340 if (union_layout.tag_size != 0 and tag_first) {1340 if (union_layout.tag_size != 0 and tag_first) {
1341 union_layout.tag_index = field_index;1341 union_layout.tag_index = field_index;
...@@ -1534,6 +1534,7 @@ pub const DeclGen = struct {...@@ -1534,6 +1534,7 @@ pub const DeclGen = struct {
1534 .id_result = decl_id,1534 .id_result = decl_id,
1535 .storage_class = actual_storage_class,1535 .storage_class = actual_storage_class,
1536 });1536 });
1537 self.spv.globalPtr(spv_decl_index).?.result_id = decl_id;
15371538
1538 // Now emit the instructions that initialize the variable.1539 // Now emit the instructions that initialize the variable.
1539 const initializer_id = self.spv.allocId();1540 const initializer_id = self.spv.allocId();