authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-11-28 19:14:16+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:51+02:00
log700dee34d5c7bdedc678032689c761e3a417fa03
tree3ddf95feb67fe929ab3f9ebd1fc716699af226f5
parent0c2526b18ec21d8155b070022d3b3b9069303744
signaturelock-open Commit is signed but in an unrecognized format.

spirv: make IdResultType and IdRef weak aliases of IdResult

Previously they were strong aliases, but as these types are used quite intermittendly it resulted in a lot of toRef() calls. Removing them improves readability a bit.

6 files changed, 73 insertions(+), 95 deletions(-)

src/codegen/spirv.zig+43-43
......@@ -227,7 +227,7 @@ pub const DeclGen = struct {
227227 /// keep track of the previous block.
228228 fn beginSpvBlock(self: *DeclGen, label_id: IdResult) !void {
229229 try self.func.body.emit(self.spv.gpa, .OpLabel, .{ .id_result = label_id });
230 self.current_block_label_id = label_id.toRef();
230 self.current_block_label_id = label_id;
231231 }
232232
233233 /// SPIR-V requires enabling specific integer sizes through capabilities, and so if they are not enabled, we need
......@@ -340,7 +340,7 @@ pub const DeclGen = struct {
340340 };
341341 const decl = self.module.declPtr(fn_decl_index);
342342 self.module.markDeclAlive(decl);
343 return self.ids.get(fn_decl_index).?.toRef();
343 return self.ids.get(fn_decl_index).?;
344344 }
345345
346346 const target = self.getTarget();
......@@ -350,7 +350,7 @@ pub const DeclGen = struct {
350350
351351 if (val.isUndef()) {
352352 try section.emit(self.spv.gpa, .OpUndef, .{ .id_result_type = result_type_id, .id_result = result_id });
353 return result_id.toRef();
353 return result_id;
354354 }
355355
356356 switch (ty.zigTypeTag()) {
......@@ -538,7 +538,7 @@ pub const DeclGen = struct {
538538 else => return self.todo("constant generation of type {s}: {}", .{ @tagName(ty.zigTypeTag()), ty.fmtDebug() }),
539539 }
540540
541 return result_id.toRef();
541 return result_id;
542542 }
543543
544544 /// Turn a Zig type into a SPIR-V Type, and return its type result-id.
......@@ -766,7 +766,7 @@ pub const DeclGen = struct {
766766 .id_result_type = try self.resolveTypeId(decl.ty.fnReturnType()),
767767 .id_result = result_id,
768768 .function_control = .{}, // TODO: We can set inline here if the type requires it.
769 .function_type = prototype_id.toRef(),
769 .function_type = prototype_id,
770770 });
771771
772772 const params = decl.ty.fnParamLen();
......@@ -780,7 +780,7 @@ pub const DeclGen = struct {
780780 .id_result_type = param_type_id,
781781 .id_result = arg_result_id,
782782 });
783 self.args.appendAssumeCapacity(arg_result_id.toRef());
783 self.args.appendAssumeCapacity(arg_result_id);
784784 }
785785
786786 // TODO: This could probably be done in a better way...
......@@ -791,7 +791,7 @@ pub const DeclGen = struct {
791791 try self.func.prologue.emit(self.spv.gpa, .OpLabel, .{
792792 .id_result = root_block_id,
793793 });
794 self.current_block_label_id = root_block_id.toRef();
794 self.current_block_label_id = root_block_id;
795795
796796 const main_body = self.air.getMainBody();
797797 try self.genBody(main_body);
......@@ -804,7 +804,7 @@ pub const DeclGen = struct {
804804 defer self.module.gpa.free(fqn);
805805
806806 try self.spv.sections.debug_names.emit(self.gpa, .OpName, .{
807 .target = result_id.toRef(),
807 .target = result_id,
808808 .name = fqn,
809809 });
810810 } else {
......@@ -928,7 +928,7 @@ pub const DeclGen = struct {
928928 .operand_1 = lhs_id,
929929 .operand_2 = rhs_id,
930930 });
931 return result_id.toRef();
931 return result_id;
932932 }
933933
934934 fn airShift(self: *DeclGen, inst: Air.Inst.Index, comptime opcode: Opcode) !?IdRef {
......@@ -951,9 +951,9 @@ pub const DeclGen = struct {
951951 .id_result_type = result_type_id,
952952 .id_result = result_id,
953953 .base = lhs_id,
954 .shift = shift_id.toRef(),
954 .shift = shift_id,
955955 });
956 return result_id.toRef();
956 return result_id;
957957 }
958958
959959 fn maskStrangeInt(self: *DeclGen, ty_id: IdResultType, int_id: IdRef, bits: u16) !IdRef {
......@@ -976,9 +976,9 @@ pub const DeclGen = struct {
976976 .id_result_type = ty_id,
977977 .id_result = result_id,
978978 .operand_1 = int_id,
979 .operand_2 = mask_id.toRef(),
979 .operand_2 = mask_id,
980980 });
981 return result_id.toRef();
981 return result_id;
982982 }
983983
984984 fn airArithOp(
......@@ -1046,7 +1046,7 @@ pub const DeclGen = struct {
10461046 // TODO: Trap on overflow? Probably going to be annoying.
10471047 // TODO: Look into SPV_KHR_no_integer_wrap_decoration which provides NoSignedWrap/NoUnsignedWrap.
10481048
1049 return result_id.toRef();
1049 return result_id;
10501050 }
10511051
10521052 fn airOverflowArithOp(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1089,7 +1089,7 @@ pub const DeclGen = struct {
10891089 .operand_1 = lhs,
10901090 .operand_2 = rhs,
10911091 });
1092 break :blk result_id.toRef();
1092 break :blk result_id;
10931093 };
10941094
10951095 // Now convert the SPIR-V flavor result into a Zig-flavor result.
......@@ -1111,7 +1111,7 @@ pub const DeclGen = struct {
11111111 .id_result = result_id,
11121112 .unsigned_value = overflow,
11131113 });
1114 break :blk result_id.toRef();
1114 break :blk result_id;
11151115 };
11161116
11171117 // TODO: If copying this function for borrow, make sure to convert -1 to 1 as appropriate.
......@@ -1127,7 +1127,7 @@ pub const DeclGen = struct {
11271127 casted_overflow,
11281128 },
11291129 });
1130 return result_id.toRef();
1130 return result_id;
11311131 }
11321132
11331133 fn airShuffle(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1163,7 +1163,7 @@ pub const DeclGen = struct {
11631163 self.func.body.writeOperand(spec.LiteralInteger, unsigned);
11641164 }
11651165 }
1166 return result_id.toRef();
1166 return result_id;
11671167 }
11681168
11691169 fn airCmp(self: *DeclGen, inst: Air.Inst.Index, comptime fop: Opcode, comptime sop: Opcode, comptime uop: Opcode) !?IdRef {
......@@ -1215,7 +1215,7 @@ pub const DeclGen = struct {
12151215 else => unreachable,
12161216 }
12171217
1218 return result_id.toRef();
1218 return result_id;
12191219 }
12201220
12211221 fn bitcast(self: *DeclGen, target_type_id: IdResultType, value_id: IdRef) !IdRef {
......@@ -1225,7 +1225,7 @@ pub const DeclGen = struct {
12251225 .id_result = result_id,
12261226 .operand = value_id,
12271227 });
1228 return result_id.toRef();
1228 return result_id;
12291229 }
12301230
12311231 fn airBitcast(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1258,7 +1258,7 @@ pub const DeclGen = struct {
12581258 .unsigned_value = operand_id,
12591259 }),
12601260 }
1261 return result_id.toRef();
1261 return result_id;
12621262 }
12631263
12641264 fn airNot(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1272,7 +1272,7 @@ pub const DeclGen = struct {
12721272 .id_result = result_id,
12731273 .operand = operand_id,
12741274 });
1275 return result_id.toRef();
1275 return result_id;
12761276 }
12771277
12781278 fn extractField(self: *DeclGen, result_ty: IdResultType, object: IdRef, field: u32) !IdRef {
......@@ -1283,7 +1283,7 @@ pub const DeclGen = struct {
12831283 .composite = object,
12841284 .indexes = &.{field},
12851285 });
1286 return result_id.toRef();
1286 return result_id;
12871287 }
12881288
12891289 fn airSliceField(self: *DeclGen, inst: Air.Inst.Index, field: u32) !?IdRef {
......@@ -1314,7 +1314,7 @@ pub const DeclGen = struct {
13141314 .composite = slice,
13151315 .indexes = &.{0},
13161316 });
1317 break :blk result_id.toRef();
1317 break :blk result_id;
13181318 };
13191319
13201320 const result_id = self.spv.allocId();
......@@ -1324,7 +1324,7 @@ pub const DeclGen = struct {
13241324 .base = slice_ptr,
13251325 .indexes = &.{index},
13261326 });
1327 return result_id.toRef();
1327 return result_id;
13281328 }
13291329
13301330 fn airSliceElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1347,7 +1347,7 @@ pub const DeclGen = struct {
13471347 .composite = slice,
13481348 .indexes = &.{0},
13491349 });
1350 break :blk result_id.toRef();
1350 break :blk result_id;
13511351 };
13521352
13531353 const elem_ptr = blk: {
......@@ -1358,7 +1358,7 @@ pub const DeclGen = struct {
13581358 .base = slice_ptr,
13591359 .indexes = &.{index},
13601360 });
1361 break :blk result_id.toRef();
1361 break :blk result_id;
13621362 };
13631363
13641364 const result_id = self.spv.allocId();
......@@ -1367,7 +1367,7 @@ pub const DeclGen = struct {
13671367 .id_result = result_id,
13681368 .pointer = elem_ptr,
13691369 });
1370 return result_id.toRef();
1370 return result_id;
13711371 }
13721372
13731373 fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1392,7 +1392,7 @@ pub const DeclGen = struct {
13921392 .base = base_ptr,
13931393 .indexes = &.{rhs},
13941394 });
1395 return result_id.toRef();
1395 return result_id;
13961396 }
13971397
13981398 fn airStructFieldVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1418,7 +1418,7 @@ pub const DeclGen = struct {
14181418 .composite = object,
14191419 .indexes = &.{field_index},
14201420 });
1421 return result_id.toRef();
1421 return result_id;
14221422 }
14231423
14241424 fn structFieldPtr(
......@@ -1446,9 +1446,9 @@ pub const DeclGen = struct {
14461446 .id_result_type = result_type_id,
14471447 .id_result = result_id,
14481448 .base = object_ptr,
1449 .indexes = &.{field_index_id.toRef()},
1449 .indexes = &.{field_index_id},
14501450 });
1451 return result_id.toRef();
1451 return result_id;
14521452 },
14531453 },
14541454 else => unreachable, // TODO
......@@ -1483,7 +1483,7 @@ pub const DeclGen = struct {
14831483 .id_result = result_id,
14841484 .storage_class = storage_class,
14851485 });
1486 return result_id.toRef();
1486 return result_id;
14871487 }
14881488
14891489 fn airArg(self: *DeclGen) IdRef {
......@@ -1503,7 +1503,7 @@ pub const DeclGen = struct {
15031503 var incoming_blocks = try std.ArrayListUnmanaged(IncomingBlock).initCapacity(self.gpa, 4);
15041504
15051505 try self.blocks.putNoClobber(self.gpa, inst, .{
1506 .label_id = label_id.toRef(),
1506 .label_id = label_id,
15071507 .incoming_blocks = &incoming_blocks,
15081508 });
15091509 defer {
......@@ -1538,7 +1538,7 @@ pub const DeclGen = struct {
15381538 self.func.body.writeOperand(spec.PairIdRefIdRef, .{ incoming.break_value_id, incoming.src_label_id });
15391539 }
15401540
1541 return result_id.toRef();
1541 return result_id;
15421542 }
15431543
15441544 fn airBr(self: *DeclGen, inst: Air.Inst.Index) !void {
......@@ -1571,8 +1571,8 @@ pub const DeclGen = struct {
15711571
15721572 try self.func.body.emit(self.spv.gpa, .OpBranchConditional, .{
15731573 .condition = condition_id,
1574 .true_label = then_label_id.toRef(),
1575 .false_label = else_label_id.toRef(),
1574 .true_label = then_label_id,
1575 .false_label = else_label_id,
15761576 });
15771577
15781578 try self.beginSpvBlock(then_label_id);
......@@ -1610,7 +1610,7 @@ pub const DeclGen = struct {
16101610 .memory_access = access,
16111611 });
16121612
1613 return result_id.toRef();
1613 return result_id;
16141614 }
16151615
16161616 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
......@@ -1620,13 +1620,13 @@ pub const DeclGen = struct {
16201620 const loop_label_id = self.spv.allocId();
16211621
16221622 // Jump to the loop entry point
1623 try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id.toRef() });
1623 try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id });
16241624
16251625 // TODO: Look into OpLoopMerge.
16261626 try self.beginSpvBlock(loop_label_id);
16271627 try self.genBody(body);
16281628
1629 try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id.toRef() });
1629 try self.func.body.emit(self.spv.gpa, .OpBranch, .{ .target_label = loop_label_id });
16301630 }
16311631
16321632 fn airRet(self: *DeclGen, inst: Air.Inst.Index) !void {
......@@ -1658,7 +1658,7 @@ pub const DeclGen = struct {
16581658 .id_result = result_id,
16591659 .pointer = ptr,
16601660 });
1661 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = result_id.toRef() });
1661 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = result_id });
16621662 }
16631663
16641664 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
......@@ -1730,7 +1730,7 @@ pub const DeclGen = struct {
17301730 // Emit the instruction before generating the blocks.
17311731 try self.func.body.emitRaw(self.spv.gpa, .OpSwitch, 2 + (cond_words + 1) * num_conditions);
17321732 self.func.body.writeOperand(IdRef, cond);
1733 self.func.body.writeOperand(IdRef, default.toRef());
1733 self.func.body.writeOperand(IdRef, default);
17341734
17351735 // Emit each of the cases
17361736 {
......@@ -1965,6 +1965,6 @@ pub const DeclGen = struct {
19651965 return null;
19661966 }
19671967
1968 return result_id.toRef();
1968 return result_id;
19691969 }
19701970};
src/codegen/spirv/Assembler.zig+2-2
......@@ -135,7 +135,7 @@ const AsmValue = union(enum) {
135135 return switch (self) {
136136 .just_declared, .unresolved_forward_reference => unreachable,
137137 .value => |result| result,
138 .ty => |ref| spv.typeResultId(ref).toRef(),
138 .ty => |ref| spv.typeResultId(ref),
139139 };
140140 }
141141};
......@@ -486,7 +486,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
486486 section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @enumToInt(self.inst.opcode);
487487
488488 if (maybe_result_id) |result| {
489 return AsmValue{ .value = result.toRef() };
489 return AsmValue{ .value = result };
490490 }
491491 return null;
492492}
src/codegen/spirv/Module.zig+20-20
......@@ -196,7 +196,7 @@ pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef {
196196 const result = try self.source_file_names.getOrPut(self.gpa, path);
197197 if (!result.found_existing) {
198198 const file_result_id = self.allocId();
199 result.value_ptr.* = file_result_id.toRef();
199 result.value_ptr.* = file_result_id;
200200 try self.sections.debug_strings.emit(self.gpa, .OpString, .{
201201 .id_result = file_result_id,
202202 .string = path,
......@@ -205,7 +205,7 @@ pub fn resolveSourceFileName(self: *Module, decl: *ZigDecl) !IdRef {
205205 try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
206206 .source_language = .Unknown, // TODO: Register Zig source language.
207207 .version = 0, // TODO: Zig version as u32?
208 .file = file_result_id.toRef(),
208 .file = file_result_id,
209209 .source = null, // TODO: Store actual source also?
210210 });
211211 }
......@@ -239,7 +239,7 @@ pub fn typeResultId(self: Module, type_ref: Type.Ref) IdResultType {
239239
240240/// Get the result-id of a particular type as IdRef, by Type.Ref. Asserts type_ref is valid.
241241pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
242 return self.type_cache.values()[@enumToInt(type_ref)].toRef();
242 return self.type_cache.values()[@enumToInt(type_ref)];
243243}
244244
245245/// Unconditionally emit a spir-v type into the appropriate section.
......@@ -250,7 +250,7 @@ pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef {
250250/// be emitted at this point.
251251pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
252252 const result_id = self.allocId();
253 const ref_id = result_id.toRef();
253 const ref_id = result_id;
254254 const types = &self.sections.types_globals_constants;
255255 const debug_names = &self.sections.debug_names;
256256 const annotations = &self.sections.annotations;
......@@ -260,14 +260,14 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
260260 .void => {
261261 try types.emit(self.gpa, .OpTypeVoid, result_id_operand);
262262 try debug_names.emit(self.gpa, .OpName, .{
263 .target = result_id.toRef(),
263 .target = result_id,
264264 .name = "void",
265265 });
266266 },
267267 .bool => {
268268 try types.emit(self.gpa, .OpTypeBool, result_id_operand);
269269 try debug_names.emit(self.gpa, .OpName, .{
270 .target = result_id.toRef(),
270 .target = result_id,
271271 .name = "bool",
272272 });
273273 },
......@@ -302,7 +302,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
302302 defer self.gpa.free(name);
303303
304304 try debug_names.emit(self.gpa, .OpName, .{
305 .target = result_id.toRef(),
305 .target = result_id,
306306 .name = name,
307307 });
308308 },
......@@ -316,25 +316,25 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
316316 const name = try std.fmt.allocPrint(self.gpa, "f{}", .{bits});
317317 defer self.gpa.free(name);
318318 try debug_names.emit(self.gpa, .OpName, .{
319 .target = result_id.toRef(),
319 .target = result_id,
320320 .name = name,
321321 });
322322 },
323323 .vector => try types.emit(self.gpa, .OpTypeVector, .{
324324 .id_result = result_id,
325 .component_type = self.typeResultId(ty.childType()).toRef(),
325 .component_type = self.typeResultId(ty.childType()),
326326 .component_count = ty.payload(.vector).component_count,
327327 }),
328328 .matrix => try types.emit(self.gpa, .OpTypeMatrix, .{
329329 .id_result = result_id,
330 .column_type = self.typeResultId(ty.childType()).toRef(),
330 .column_type = self.typeResultId(ty.childType()),
331331 .column_count = ty.payload(.matrix).column_count,
332332 }),
333333 .image => {
334334 const info = ty.payload(.image);
335335 try types.emit(self.gpa, .OpTypeImage, .{
336336 .id_result = result_id,
337 .sampled_type = self.typeResultId(ty.childType()).toRef(),
337 .sampled_type = self.typeResultId(ty.childType()),
338338 .dim = info.dim,
339339 .depth = @enumToInt(info.depth),
340340 .arrayed = @boolToInt(info.arrayed),
......@@ -347,7 +347,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
347347 .sampler => try types.emit(self.gpa, .OpTypeSampler, result_id_operand),
348348 .sampled_image => try types.emit(self.gpa, .OpTypeSampledImage, .{
349349 .id_result = result_id,
350 .image_type = self.typeResultId(ty.childType()).toRef(),
350 .image_type = self.typeResultId(ty.childType()),
351351 }),
352352 .array => {
353353 const info = ty.payload(.array);
......@@ -365,8 +365,8 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
365365
366366 try types.emit(self.gpa, .OpTypeArray, .{
367367 .id_result = result_id,
368 .element_type = self.typeResultId(ty.childType()).toRef(),
369 .length = length_id.toRef(),
368 .element_type = self.typeResultId(ty.childType()),
369 .length = length_id,
370370 });
371371 if (info.array_stride != 0) {
372372 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
......@@ -376,7 +376,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
376376 const info = ty.payload(.runtime_array);
377377 try types.emit(self.gpa, .OpTypeRuntimeArray, .{
378378 .id_result = result_id,
379 .element_type = self.typeResultId(ty.childType()).toRef(),
379 .element_type = self.typeResultId(ty.childType()),
380380 });
381381 if (info.array_stride != 0) {
382382 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
......@@ -387,7 +387,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
387387 try types.emitRaw(self.gpa, .OpTypeStruct, 1 + info.members.len);
388388 types.writeOperand(IdResult, result_id);
389389 for (info.members) |member| {
390 types.writeOperand(IdRef, self.typeResultId(member.ty).toRef());
390 types.writeOperand(IdRef, self.typeResultId(member.ty));
391391 }
392392 try self.decorateStruct(ref_id, info);
393393 },
......@@ -400,7 +400,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
400400 try types.emit(self.gpa, .OpTypePointer, .{
401401 .id_result = result_id,
402402 .storage_class = info.storage_class,
403 .type = self.typeResultId(ty.childType()).toRef(),
403 .type = self.typeResultId(ty.childType()),
404404 });
405405 if (info.array_stride != 0) {
406406 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
......@@ -416,9 +416,9 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
416416 const info = ty.payload(.function);
417417 try types.emitRaw(self.gpa, .OpTypeFunction, 2 + info.parameters.len);
418418 types.writeOperand(IdResult, result_id);
419 types.writeOperand(IdRef, self.typeResultId(info.return_type).toRef());
419 types.writeOperand(IdRef, self.typeResultId(info.return_type));
420420 for (info.parameters) |parameter_type| {
421 types.writeOperand(IdRef, self.typeResultId(parameter_type).toRef());
421 types.writeOperand(IdRef, self.typeResultId(parameter_type));
422422 }
423423 },
424424 .event => try types.emit(self.gpa, .OpTypeEvent, result_id_operand),
......@@ -433,7 +433,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
433433 .named_barrier => try types.emit(self.gpa, .OpTypeNamedBarrier, result_id_operand),
434434 }
435435
436 return result_id.toResultType();
436 return result_id;
437437}
438438
439439fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct) !void {
src/codegen/spirv/Section.zig+4-4
......@@ -122,7 +122,7 @@ fn writeOperands(section: *Section, comptime Operands: type, operands: Operands)
122122
123123pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand) void {
124124 switch (Operand) {
125 spec.IdResultType, spec.IdResult, spec.IdRef => section.writeWord(operand.id),
125 spec.IdResult => section.writeWord(operand.id),
126126
127127 spec.LiteralInteger => section.writeWord(operand),
128128
......@@ -258,9 +258,7 @@ fn operandsSize(comptime Operands: type, operands: Operands) usize {
258258
259259fn operandSize(comptime Operand: type, operand: Operand) usize {
260260 return switch (Operand) {
261 spec.IdResultType,
262261 spec.IdResult,
263 spec.IdRef,
264262 spec.LiteralInteger,
265263 spec.LiteralExtInstInteger,
266264 => 1,
......@@ -382,7 +380,9 @@ test "SPIR-V Section emit() - string" {
382380 }, section.instructions.items);
383381}
384382
385test "SPIR-V Section emit()- extended mask" {
383test "SPIR-V Section emit() - extended mask" {
384 if (@import("builtin").zig_backend == .stage1) return error.SkipZigTest;
385
386386 var section = Section{};
387387 defer section.deinit(std.testing.allocator);
388388
src/codegen/spirv/spec.zig+2-13
......@@ -3,22 +3,11 @@
33const Version = @import("std").builtin.Version;
44
55pub const Word = u32;
6pub const IdResultType = struct {
7 id: Word,
8 pub fn toRef(self: IdResultType) IdRef {
9 return .{ .id = self.id };
10 }
11};
126pub const IdResult = struct {
137 id: Word,
14 pub fn toRef(self: IdResult) IdRef {
15 return .{ .id = self.id };
16 }
17 pub fn toResultType(self: IdResult) IdResultType {
18 return .{ .id = self.id };
19 }
208};
21pub const IdRef = struct { id: Word };
9pub const IdResultType = IdResult;
10pub const IdRef = IdResult;
2211
2312pub const IdMemorySemantics = IdRef;
2413pub const IdScope = IdRef;
tools/gen_spirv_spec.zig+2-13
......@@ -80,22 +80,11 @@ fn render(writer: anytype, allocator: Allocator, registry: g.CoreRegistry) !void
8080 \\const Version = @import("std").builtin.Version;
8181 \\
8282 \\pub const Word = u32;
83 \\pub const IdResultType = struct{
84 \\ id: Word,
85 \\ pub fn toRef(self: IdResultType) IdRef {
86 \\ return .{.id = self.id};
87 \\ }
88 \\};
8983 \\pub const IdResult = struct{
9084 \\ id: Word,
91 \\ pub fn toRef(self: IdResult) IdRef {
92 \\ return .{.id = self.id};
93 \\ }
94 \\ pub fn toResultType(self: IdResult) IdResultType {
95 \\ return .{.id = self.id};
96 \\ }
9785 \\};
98 \\pub const IdRef = struct{ id: Word };
86 \\pub const IdResultType = IdResult;
87 \\pub const IdRef = IdResult;
9988 \\
10089 \\pub const IdMemorySemantics = IdRef;
10190 \\pub const IdScope = IdRef;