authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-11-29 23:44:31+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:51+02:00
log8a00ec162c76ef28cbbca59a7124d7d175a77e97
treecaa6c579cb256603f8d5e08a52c0eb627c31a98b
parent700dee34d5c7bdedc678032689c761e3a417fa03
signaturelock-open Commit is signed but in an unrecognized format.

spirv: more fixes and improvements

- Formatting. - Improve `decorate` helper function to generate a decoration for a result-id. - Reorder some functions in a more logical way

3 files changed, 132 insertions(+), 139 deletions(-)

src/codegen/spirv.zig+60-70
......@@ -880,7 +880,9 @@ pub const DeclGen = struct {
880880 // TODO: We probably need to have a special implementation of this for the C abi.
881881 .ret_ptr => try self.airAlloc(inst),
882882 .block => try self.airBlock(inst),
883
883884 .load => try self.airLoad(inst),
885 .store => return self.airStore(inst),
884886
885887 .br => return self.airBr(inst),
886888 .breakpoint => return,
......@@ -891,7 +893,6 @@ pub const DeclGen = struct {
891893 .loop => return self.airLoop(inst),
892894 .ret => return self.airRet(inst),
893895 .ret_load => return self.airRetLoad(inst),
894 .store => return self.airStore(inst),
895896 .switch_br => return self.airSwitchBr(inst),
896897 .unreach => return self.airUnreach(),
897898
......@@ -964,13 +965,8 @@ pub const DeclGen = struct {
964965 33...64 => .{ .uint64 = mask_value },
965966 else => unreachable,
966967 };
967 // TODO: We should probably optimize these constants a bit.
968 const mask_id = self.spv.allocId();
969 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpConstant, .{
970 .id_result_type = ty_id,
971 .id_result = mask_id,
972 .value = mask_lit,
973 });
968 // TODO: We should probably optimize the amount of these constants a bit.
969 const mask_id = try self.spv.emitConstant(ty_id, mask_lit);
974970 const result_id = self.spv.allocId();
975971 try self.func.body.emit(self.spv.gpa, .OpBitwiseAnd, .{
976972 .id_result_type = ty_id,
......@@ -1119,13 +1115,11 @@ pub const DeclGen = struct {
11191115 // Finally, construct the Zig type.
11201116 // Layout is result, overflow.
11211117 const result_id = self.spv.allocId();
1118 const constituents = [_]IdRef{ result, casted_overflow };
11221119 try self.func.body.emit(self.spv.gpa, .OpCompositeConstruct, .{
11231120 .id_result_type = result_type_id,
11241121 .id_result = result_id,
1125 .constituents = &.{
1126 result,
1127 casted_overflow,
1128 },
1122 .constituents = &constituents,
11291123 });
11301124 return result_id;
11311125 }
......@@ -1277,11 +1271,12 @@ pub const DeclGen = struct {
12771271
12781272 fn extractField(self: *DeclGen, result_ty: IdResultType, object: IdRef, field: u32) !IdRef {
12791273 const result_id = self.spv.allocId();
1274 const indexes = [_]u32{field};
12801275 try self.func.body.emit(self.spv.gpa, .OpCompositeExtract, .{
12811276 .id_result_type = result_ty,
12821277 .id_result = result_id,
12831278 .composite = object,
1284 .indexes = &.{field},
1279 .indexes = &indexes,
12851280 });
12861281 return result_id;
12871282 }
......@@ -1318,11 +1313,12 @@ pub const DeclGen = struct {
13181313 };
13191314
13201315 const result_id = self.spv.allocId();
1316 const indexes = [_]IdRef{index};
13211317 try self.func.body.emit(self.spv.gpa, .OpInBoundsAccessChain, .{
13221318 .id_result_type = spv_ptr_ty,
13231319 .id_result = result_id,
13241320 .base = slice_ptr,
1325 .indexes = &.{index},
1321 .indexes = &indexes,
13261322 });
13271323 return result_id;
13281324 }
......@@ -1335,14 +1331,13 @@ pub const DeclGen = struct {
13351331 const slice = try self.resolve(bin_op.lhs);
13361332 const index = try self.resolve(bin_op.rhs);
13371333
1338 const spv_elem_ty = try self.resolveTypeId(self.air.typeOfIndex(inst));
13391334 var slice_buf: Type.SlicePtrFieldTypeBuffer = undefined;
1340 const spv_ptr_ty = try self.resolveTypeId(slice_ty.slicePtrFieldType(&slice_buf));
1335 const ptr_ty_id = try self.resolveTypeId(slice_ty.slicePtrFieldType(&slice_buf));
13411336
13421337 const slice_ptr = blk: {
13431338 const result_id = self.spv.allocId();
13441339 try self.func.body.emit(self.spv.gpa, .OpCompositeExtract, .{
1345 .id_result_type = spv_ptr_ty,
1340 .id_result_type = ptr_ty_id,
13461341 .id_result = result_id,
13471342 .composite = slice,
13481343 .indexes = &.{0},
......@@ -1352,22 +1347,17 @@ pub const DeclGen = struct {
13521347
13531348 const elem_ptr = blk: {
13541349 const result_id = self.spv.allocId();
1350 const indexes = [_]IdRef{index};
13551351 try self.func.body.emit(self.spv.gpa, .OpInBoundsAccessChain, .{
1356 .id_result_type = spv_ptr_ty,
1352 .id_result_type = ptr_ty_id,
13571353 .id_result = result_id,
13581354 .base = slice_ptr,
1359 .indexes = &.{index},
1355 .indexes = &indexes,
13601356 });
13611357 break :blk result_id;
13621358 };
13631359
1364 const result_id = self.spv.allocId();
1365 try self.func.body.emit(self.spv.gpa, .OpLoad, .{
1366 .id_result_type = spv_elem_ty,
1367 .id_result = result_id,
1368 .pointer = elem_ptr,
1369 });
1370 return result_id;
1360 return try self.load(slice_ty, elem_ptr);
13711361 }
13721362
13731363 fn airPtrElemPtr(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
......@@ -1386,11 +1376,12 @@ pub const DeclGen = struct {
13861376 const rhs = try self.resolve(bin_op.rhs);
13871377
13881378 const result_id = self.spv.allocId();
1379 const indexes = [_]IdRef{rhs};
13891380 try self.func.body.emit(self.spv.gpa, .OpInBoundsAccessChain, .{
13901381 .id_result_type = result_type_id,
13911382 .id_result = result_id,
13921383 .base = base_ptr,
1393 .indexes = &.{rhs},
1384 .indexes = &indexes,
13941385 });
13951386 return result_id;
13961387 }
......@@ -1412,11 +1403,12 @@ pub const DeclGen = struct {
14121403 assert(struct_ty.zigTypeTag() == .Struct); // Cannot do unions yet.
14131404
14141405 const result_id = self.spv.allocId();
1406 const indexes = [_]u32{field_index};
14151407 try self.func.body.emit(self.spv.gpa, .OpCompositeExtract, .{
14161408 .id_result_type = field_ty_id,
14171409 .id_result = result_id,
14181410 .composite = object,
1419 .indexes = &.{field_index},
1411 .indexes = &indexes,
14201412 });
14211413 return result_id;
14221414 }
......@@ -1433,20 +1425,16 @@ pub const DeclGen = struct {
14331425 .Struct => switch (object_ty.containerLayout()) {
14341426 .Packed => unreachable, // TODO
14351427 else => {
1436 const field_index_id = self.spv.allocId();
14371428 const u32_ty_id = self.spv.typeResultId(try self.intType(.unsigned, 32));
1438 try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpConstant, .{
1439 .id_result_type = u32_ty_id,
1440 .id_result = field_index_id,
1441 .value = .{ .uint32 = field_index },
1442 });
1429 const field_index_id = try self.spv.emitConstant(u32_ty_id, .{ .uint32 = field_index });
14431430 const result_id = self.spv.allocId();
14441431 const result_type_id = try self.resolveTypeId(result_ptr_ty);
1432 const indexes = [_]IdRef{field_index_id};
14451433 try self.func.body.emit(self.spv.gpa, .OpInBoundsAccessChain, .{
14461434 .id_result_type = result_type_id,
14471435 .id_result = result_id,
14481436 .base = object_ptr,
1449 .indexes = &.{field_index_id},
1437 .indexes = &indexes,
14501438 });
14511439 return result_id;
14521440 },
......@@ -1591,28 +1579,51 @@ pub const DeclGen = struct {
15911579 });
15921580 }
15931581
1594 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !IdRef {
1582 fn airLoad(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
15951583 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
1596 const operand_id = try self.resolve(ty_op.operand);
1597 const ty = self.air.typeOfIndex(inst);
1584 const ptr_ty = self.air.typeOf(ty_op.operand);
1585 const operand = try self.resolve(ty_op.operand);
1586 if (!ptr_ty.isVolatilePtr() and self.liveness.isUnused(inst)) return null;
15981587
1599 const result_type_id = try self.resolveTypeId(ty);
1600 const result_id = self.spv.allocId();
1588 return try self.load(ptr_ty, operand);
1589 }
16011590
1591 fn load(self: *DeclGen, ptr_ty: Type, ptr: IdRef) !IdRef {
1592 const value_ty = ptr_ty.childType();
1593 const result_type_id = try self.resolveTypeId(value_ty);
1594 const result_id = self.spv.allocId();
16021595 const access = spec.MemoryAccess.Extended{
1603 .Volatile = ty.isVolatilePtr(),
1596 .Volatile = ptr_ty.isVolatilePtr(),
16041597 };
1605
16061598 try self.func.body.emit(self.spv.gpa, .OpLoad, .{
16071599 .id_result_type = result_type_id,
16081600 .id_result = result_id,
1609 .pointer = operand_id,
1601 .pointer = ptr,
16101602 .memory_access = access,
16111603 });
1612
16131604 return result_id;
16141605 }
16151606
1607 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
1608 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1609 const ptr_ty = self.air.typeOf(bin_op.lhs);
1610 const ptr = try self.resolve(bin_op.lhs);
1611 const value = try self.resolve(bin_op.rhs);
1612
1613 try self.store(ptr_ty, ptr, value);
1614 }
1615
1616 fn store(self: *DeclGen, ptr_ty: Type, ptr: IdRef, value: IdRef) !void {
1617 const access = spec.MemoryAccess.Extended{
1618 .Volatile = ptr_ty.isVolatilePtr(),
1619 };
1620 try self.func.body.emit(self.spv.gpa, .OpStore, .{
1621 .pointer = ptr,
1622 .object = value,
1623 .memory_access = access,
1624 });
1625 }
1626
16161627 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
16171628 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
16181629 const loop = self.air.extraData(Air.Block, ty_pl.payload);
......@@ -1644,7 +1655,6 @@ pub const DeclGen = struct {
16441655 const un_op = self.air.instructions.items(.data)[inst].un_op;
16451656 const ptr_ty = self.air.typeOf(un_op);
16461657 const ret_ty = ptr_ty.childType();
1647 const ret_ty_id = try self.resolveTypeId(ret_ty);
16481658
16491659 if (!ret_ty.hasRuntimeBitsIgnoreComptime()) {
16501660 try self.func.body.emit(self.spv.gpa, .OpReturn, {});
......@@ -1652,29 +1662,9 @@ pub const DeclGen = struct {
16521662 }
16531663
16541664 const ptr = try self.resolve(un_op);
1655 const result_id = self.spv.allocId();
1656 try self.func.body.emit(self.spv.gpa, .OpLoad, .{
1657 .id_result_type = ret_ty_id,
1658 .id_result = result_id,
1659 .pointer = ptr,
1660 });
1661 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = result_id });
1662 }
1663
1664 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
1665 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1666 const dst_ptr_id = try self.resolve(bin_op.lhs);
1667 const src_val_id = try self.resolve(bin_op.rhs);
1668 const lhs_ty = self.air.typeOf(bin_op.lhs);
1669
1670 const access = spec.MemoryAccess.Extended{
1671 .Volatile = lhs_ty.isVolatilePtr(),
1672 };
1673
1674 try self.func.body.emit(self.spv.gpa, .OpStore, .{
1675 .pointer = dst_ptr_id,
1676 .object = src_val_id,
1677 .memory_access = access,
1665 const value = try self.load(ptr_ty, ptr);
1666 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{
1667 .value = value,
16781668 });
16791669 }
16801670
......@@ -1691,7 +1681,7 @@ pub const DeclGen = struct {
16911681 const backing_bits = self.backingIntBits(bits) orelse {
16921682 return self.todo("implement composite int switch", .{});
16931683 };
1694 break :blk if (backing_bits <= 32) 1 else 2;
1684 break :blk if (backing_bits <= 32) @as(u32, 1) else 2;
16951685 },
16961686 .Enum => blk: {
16971687 var buffer: Type.Payload.Bits = undefined;
......@@ -1700,7 +1690,7 @@ pub const DeclGen = struct {
17001690 const backing_bits = self.backingIntBits(int_info.bits) orelse {
17011691 return self.todo("implement composite int switch", .{});
17021692 };
1703 break :blk if (backing_bits <= 32) 1 else 2;
1693 break :blk if (backing_bits <= 32) @as(u32, 1) else 2;
17041694 },
17051695 else => return self.todo("implement switch for type {s}", .{@tagName(cond_ty.zigTypeTag())}), // TODO: Figure out which types apply here, and work around them as we can only do integers.
17061696 };
src/codegen/spirv/Module.zig+72-41
......@@ -253,7 +253,6 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
253253 const ref_id = result_id;
254254 const types = &self.sections.types_globals_constants;
255255 const debug_names = &self.sections.debug_names;
256 const annotations = &self.sections.annotations;
257256 const result_id_operand = .{ .id_result = result_id };
258257
259258 switch (ty.tag()) {
......@@ -355,13 +354,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
355354
356355 const size_type = Type.initTag(.u32);
357356 const size_type_id = try self.resolveTypeId(size_type);
358
359 const length_id = self.allocId();
360 try types.emit(self.gpa, .OpConstant, .{
361 .id_result_type = size_type_id,
362 .id_result = length_id,
363 .value = .{ .uint32 = info.length },
364 });
357 const length_id = try self.emitConstant(size_type_id, .{ .uint32 = info.length });
365358
366359 try types.emit(self.gpa, .OpTypeArray, .{
367360 .id_result = result_id,
......@@ -369,7 +362,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
369362 .length = length_id,
370363 });
371364 if (info.array_stride != 0) {
372 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
365 try self.decorate(ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
373366 }
374367 },
375368 .runtime_array => {
......@@ -379,7 +372,7 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
379372 .element_type = self.typeResultId(ty.childType()),
380373 });
381374 if (info.array_stride != 0) {
382 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
375 try self.decorate(ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
383376 }
384377 },
385378 .@"struct" => {
......@@ -403,13 +396,13 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
403396 .type = self.typeResultId(ty.childType()),
404397 });
405398 if (info.array_stride != 0) {
406 try annotations.decorate(self.gpa, ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
399 try self.decorate(ref_id, .{ .ArrayStride = .{ .array_stride = info.array_stride } });
407400 }
408401 if (info.alignment) |alignment| {
409 try annotations.decorate(self.gpa, ref_id, .{ .Alignment = .{ .alignment = alignment } });
402 try self.decorate(ref_id, .{ .Alignment = .{ .alignment = alignment } });
410403 }
411404 if (info.max_byte_offset) |max_byte_offset| {
412 try annotations.decorate(self.gpa, ref_id, .{ .MaxByteOffset = .{ .max_byte_offset = max_byte_offset } });
405 try self.decorate(ref_id, .{ .MaxByteOffset = .{ .max_byte_offset = max_byte_offset } });
413406 }
414407 },
415408 .function => {
......@@ -438,7 +431,6 @@ pub fn emitType(self: *Module, ty: Type) error{OutOfMemory}!IdResultType {
438431
439432fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct) !void {
440433 const debug_names = &self.sections.debug_names;
441 const annotations = &self.sections.annotations;
442434
443435 if (info.name.len != 0) {
444436 try debug_names.emit(self.gpa, .OpName, .{
......@@ -449,15 +441,15 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct
449441
450442 // Decorations for the struct type itself.
451443 if (info.decorations.block)
452 try annotations.decorate(self.gpa, target, .Block);
444 try self.decorate(target, .Block);
453445 if (info.decorations.buffer_block)
454 try annotations.decorate(self.gpa, target, .BufferBlock);
446 try self.decorate(target, .BufferBlock);
455447 if (info.decorations.glsl_shared)
456 try annotations.decorate(self.gpa, target, .GLSLShared);
448 try self.decorate(target, .GLSLShared);
457449 if (info.decorations.glsl_packed)
458 try annotations.decorate(self.gpa, target, .GLSLPacked);
450 try self.decorate(target, .GLSLPacked);
459451 if (info.decorations.c_packed)
460 try annotations.decorate(self.gpa, target, .CPacked);
452 try self.decorate(target, .CPacked);
461453
462454 // Decorations for the struct members.
463455 const extra = info.member_decoration_extra;
......@@ -476,8 +468,7 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct
476468
477469 switch (member.offset) {
478470 .none => {},
479 else => try annotations.decorateMember(
480 self.gpa,
471 else => try self.decorateMember(
481472 target,
482473 index,
483474 .{ .Offset = .{ .byte_offset = @enumToInt(member.offset) } },
......@@ -485,70 +476,70 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct
485476 }
486477
487478 switch (d.matrix_layout) {
488 .row_major => try annotations.decorateMember(self.gpa, target, index, .RowMajor),
489 .col_major => try annotations.decorateMember(self.gpa, target, index, .ColMajor),
479 .row_major => try self.decorateMember(target, index, .RowMajor),
480 .col_major => try self.decorateMember(target, index, .ColMajor),
490481 .none => {},
491482 }
492483 if (d.matrix_layout != .none) {
493 try annotations.decorateMember(self.gpa, target, index, .{
484 try self.decorateMember(target, index, .{
494485 .MatrixStride = .{ .matrix_stride = extra[extra_i] },
495486 });
496487 extra_i += 1;
497488 }
498489
499490 if (d.no_perspective)
500 try annotations.decorateMember(self.gpa, target, index, .NoPerspective);
491 try self.decorateMember(target, index, .NoPerspective);
501492 if (d.flat)
502 try annotations.decorateMember(self.gpa, target, index, .Flat);
493 try self.decorateMember(target, index, .Flat);
503494 if (d.patch)
504 try annotations.decorateMember(self.gpa, target, index, .Patch);
495 try self.decorateMember(target, index, .Patch);
505496 if (d.centroid)
506 try annotations.decorateMember(self.gpa, target, index, .Centroid);
497 try self.decorateMember(target, index, .Centroid);
507498 if (d.sample)
508 try annotations.decorateMember(self.gpa, target, index, .Sample);
499 try self.decorateMember(target, index, .Sample);
509500 if (d.invariant)
510 try annotations.decorateMember(self.gpa, target, index, .Invariant);
501 try self.decorateMember(target, index, .Invariant);
511502 if (d.@"volatile")
512 try annotations.decorateMember(self.gpa, target, index, .Volatile);
503 try self.decorateMember(target, index, .Volatile);
513504 if (d.coherent)
514 try annotations.decorateMember(self.gpa, target, index, .Coherent);
505 try self.decorateMember(target, index, .Coherent);
515506 if (d.non_writable)
516 try annotations.decorateMember(self.gpa, target, index, .NonWritable);
507 try self.decorateMember(target, index, .NonWritable);
517508 if (d.non_readable)
518 try annotations.decorateMember(self.gpa, target, index, .NonReadable);
509 try self.decorateMember(target, index, .NonReadable);
519510
520511 if (d.builtin) {
521 try annotations.decorateMember(self.gpa, target, index, .{
512 try self.decorateMember(target, index, .{
522513 .BuiltIn = .{ .built_in = @intToEnum(spec.BuiltIn, extra[extra_i]) },
523514 });
524515 extra_i += 1;
525516 }
526517 if (d.stream) {
527 try annotations.decorateMember(self.gpa, target, index, .{
518 try self.decorateMember(target, index, .{
528519 .Stream = .{ .stream_number = extra[extra_i] },
529520 });
530521 extra_i += 1;
531522 }
532523 if (d.location) {
533 try annotations.decorateMember(self.gpa, target, index, .{
524 try self.decorateMember(target, index, .{
534525 .Location = .{ .location = extra[extra_i] },
535526 });
536527 extra_i += 1;
537528 }
538529 if (d.component) {
539 try annotations.decorateMember(self.gpa, target, index, .{
530 try self.decorateMember(target, index, .{
540531 .Component = .{ .component = extra[extra_i] },
541532 });
542533 extra_i += 1;
543534 }
544535 if (d.xfb_buffer) {
545 try annotations.decorateMember(self.gpa, target, index, .{
536 try self.decorateMember(target, index, .{
546537 .XfbBuffer = .{ .xfb_buffer_number = extra[extra_i] },
547538 });
548539 extra_i += 1;
549540 }
550541 if (d.xfb_stride) {
551 try annotations.decorateMember(self.gpa, target, index, .{
542 try self.decorateMember(target, index, .{
552543 .XfbStride = .{ .xfb_stride = extra[extra_i] },
553544 });
554545 extra_i += 1;
......@@ -557,10 +548,50 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct
557548 const len = extra[extra_i];
558549 extra_i += 1;
559550 const semantic = @ptrCast([*]const u8, &extra[extra_i])[0..len];
560 try annotations.decorateMember(self.gpa, target, index, .{
551 try self.decorateMember(target, index, .{
561552 .UserSemantic = .{ .semantic = semantic },
562553 });
563554 extra_i += std.math.divCeil(u32, extra_i, @sizeOf(u32)) catch unreachable;
564555 }
565556 }
566557}
558
559pub fn emitConstant(
560 self: *Module,
561 ty_id: spec.IdRef,
562 value: spec.LiteralContextDependentNumber,
563) !IdRef {
564 const result_id = self.allocId();
565 try self.sections.types_globals_constants.emit(self.gpa, .OpConstant, .{
566 .id_result_type = ty_id,
567 .id_result = result_id,
568 .value = value,
569 });
570 return result_id;
571}
572
573/// Decorate a result-id.
574pub fn decorate(
575 self: *Module,
576 target: spec.IdRef,
577 decoration: spec.Decoration.Extended,
578) !void {
579 try self.sections.annotations.emit(self.gpa, .OpDecorate, .{
580 .target = target,
581 .decoration = decoration,
582 });
583}
584
585/// Decorate a result-id which is a member of some struct.
586pub fn decorateMember(
587 self: *Module,
588 structure_type: spec.IdRef,
589 member: u32,
590 decoration: spec.Decoration.Extended,
591) !void {
592 try self.sections.annotations.emit(self.gpa, .OpMemberDecorate, .{
593 .structure_type = structure_type,
594 .member = member,
595 .decoration = decoration,
596 });
597}
src/codegen/spirv/Section.zig-28
......@@ -65,34 +65,6 @@ pub fn emit(
6565 section.writeOperands(opcode.Operands(), operands);
6666}
6767
68/// Decorate a result-id.
69pub fn decorate(
70 section: *Section,
71 allocator: Allocator,
72 target: spec.IdRef,
73 decoration: spec.Decoration.Extended,
74) !void {
75 try section.emit(allocator, .OpDecorate, .{
76 .target = target,
77 .decoration = decoration,
78 });
79}
80
81/// Decorate a result-id which is a member of some struct.
82pub fn decorateMember(
83 section: *Section,
84 allocator: Allocator,
85 structure_type: spec.IdRef,
86 member: u32,
87 decoration: spec.Decoration.Extended,
88) !void {
89 try section.emit(allocator, .OpMemberDecorate, .{
90 .structure_type = structure_type,
91 .member = member,
92 .decoration = decoration,
93 });
94}
95
9668pub fn writeWord(section: *Section, word: Word) void {
9769 section.instructions.appendAssumeCapacity(word);
9870}