update to Zig 2024.10-mach (helps hexops/mach#1276)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
55e6abda61
commit
26c5cb5d60
28 changed files with 192 additions and 203 deletions
|
|
@ -5,7 +5,7 @@ var libgl: std.DynLib = undefined;
|
|||
|
||||
fn removeOptional(comptime T: type) type {
|
||||
return switch (@typeInfo(T)) {
|
||||
.Optional => |opt| opt.child,
|
||||
.optional => |opt| opt.child,
|
||||
else => T,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub fn emitSpecConstantOp(
|
|||
section.writeOperand(spec.IdRef, operands.id_result);
|
||||
section.writeOperand(Opcode, opcode);
|
||||
|
||||
const fields = @typeInfo(opcode.Operands()).Struct.fields;
|
||||
const fields = @typeInfo(opcode.Operands()).@"struct".fields;
|
||||
// First 2 fields are always id_result_type and id_result.
|
||||
inline for (fields[2..]) |field| {
|
||||
section.writeOperand(field.type, @field(operands, field.name));
|
||||
|
|
@ -92,8 +92,8 @@ pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
|
|||
|
||||
fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void {
|
||||
const fields = switch (@typeInfo(Operands)) {
|
||||
.Struct => |info| info.fields,
|
||||
.Void => return,
|
||||
.@"struct" => |info| info.fields,
|
||||
.void => return,
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
|
|
@ -119,24 +119,24 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
|
|||
spec.PairIdRefLiteralInteger => section.writeWords(&.{ operand.target.id, operand.member }),
|
||||
spec.PairIdRefIdRef => section.writeWords(&.{ operand[0].id, operand[1].id }),
|
||||
else => switch (@typeInfo(Operand)) {
|
||||
.Enum => section.writeWord(@intFromEnum(operand)),
|
||||
.Optional => |info| if (operand) |child| {
|
||||
.@"enum" => section.writeWord(@intFromEnum(operand)),
|
||||
.optional => |info| if (operand) |child| {
|
||||
section.writeOperand(info.child, child);
|
||||
},
|
||||
.Pointer => |info| {
|
||||
.pointer => |info| {
|
||||
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
|
||||
for (operand) |item| {
|
||||
section.writeOperand(info.child, item);
|
||||
}
|
||||
},
|
||||
.Struct => |info| {
|
||||
.@"struct" => |info| {
|
||||
if (info.layout == .@"packed") {
|
||||
section.writeWord(@bitCast(operand));
|
||||
} else {
|
||||
section.writeExtendedMask(Operand, operand);
|
||||
}
|
||||
},
|
||||
.Union => section.writeExtendedUnion(Operand, operand),
|
||||
.@"union" => section.writeExtendedUnion(Operand, operand),
|
||||
else => unreachable,
|
||||
},
|
||||
}
|
||||
|
|
@ -172,12 +172,12 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
|
|||
|
||||
fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
|
||||
var mask: Word = 0;
|
||||
inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| {
|
||||
inline for (@typeInfo(Operand).@"struct".fields, 0..) |field, bit| {
|
||||
switch (@typeInfo(field.type)) {
|
||||
.Optional => if (@field(operand, field.name) != null) {
|
||||
.optional => if (@field(operand, field.name) != null) {
|
||||
mask |= 1 << @intCast(bit);
|
||||
},
|
||||
.Bool => if (@field(operand, field.name)) {
|
||||
.bool => if (@field(operand, field.name)) {
|
||||
mask |= 1 << @intCast(bit);
|
||||
},
|
||||
else => unreachable,
|
||||
|
|
@ -186,12 +186,12 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
|
|||
|
||||
section.writeWord(mask);
|
||||
|
||||
inline for (@typeInfo(Operand).Struct.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"struct".fields) |field| {
|
||||
switch (@typeInfo(field.type)) {
|
||||
.Optional => |info| if (@field(operand, field.name)) |child| {
|
||||
.optional => |info| if (@field(operand, field.name)) |child| {
|
||||
section.writeOperands(info.child, child);
|
||||
},
|
||||
.Bool => {},
|
||||
.bool => {},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ fn writeExtendedUnion(section: *Section, comptime Operand: type, operand: Operan
|
|||
const tag = std.meta.activeTag(operand);
|
||||
section.writeWord(@intFromEnum(tag));
|
||||
|
||||
inline for (@typeInfo(Operand).Union.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"union".fields) |field| {
|
||||
if (@field(Operand, field.name) == tag) {
|
||||
section.writeOperands(field.type, @field(operand, field.name));
|
||||
return;
|
||||
|
|
@ -216,8 +216,8 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us
|
|||
|
||||
fn operandsSize(comptime Operands: type, operands: Operands) usize {
|
||||
const fields = switch (@typeInfo(Operands)) {
|
||||
.Struct => |info| info.fields,
|
||||
.Void => return 0,
|
||||
.@"struct" => |info| info.fields,
|
||||
.void => return 0,
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
|
|
@ -252,9 +252,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
spec.PairIdRefIdRef,
|
||||
=> 2,
|
||||
else => switch (@typeInfo(Operand)) {
|
||||
.Enum => 1,
|
||||
.Optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
|
||||
.Pointer => |info| blk: {
|
||||
.@"enum" => 1,
|
||||
.optional => |info| if (operand) |child| operandSize(info.child, child) else 0,
|
||||
.pointer => |info| blk: {
|
||||
std.debug.assert(info.size == .Slice); // Should be no other pointer types in the spec.
|
||||
var total: usize = 0;
|
||||
for (operand) |item| {
|
||||
|
|
@ -262,8 +262,8 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
}
|
||||
break :blk total;
|
||||
},
|
||||
.Struct => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
|
||||
.Union => extendedUnionSize(Operand, operand),
|
||||
.@"struct" => |info| if (info.layout == .@"packed") 1 else extendedMaskSize(Operand, operand),
|
||||
.@"union" => extendedUnionSize(Operand, operand),
|
||||
else => unreachable,
|
||||
},
|
||||
};
|
||||
|
|
@ -272,13 +272,13 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
|
|||
fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
|
||||
var total: usize = 0;
|
||||
var any_set = false;
|
||||
inline for (@typeInfo(Operand).Struct.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"struct".fields) |field| {
|
||||
switch (@typeInfo(field.type)) {
|
||||
.Optional => |info| if (@field(operand, field.name)) |child| {
|
||||
.optional => |info| if (@field(operand, field.name)) |child| {
|
||||
total += operandsSize(info.child, child);
|
||||
any_set = true;
|
||||
},
|
||||
.Bool => if (@field(operand, field.name)) {
|
||||
.bool => if (@field(operand, field.name)) {
|
||||
any_set = true;
|
||||
},
|
||||
else => unreachable,
|
||||
|
|
@ -292,7 +292,7 @@ fn extendedMaskSize(comptime Operand: type, operand: Operand) usize {
|
|||
|
||||
fn extendedUnionSize(comptime Operand: type, operand: Operand) usize {
|
||||
const tag = std.meta.activeTag(operand);
|
||||
inline for (@typeInfo(Operand).Union.fields) |field| {
|
||||
inline for (@typeInfo(Operand).@"union".fields) |field| {
|
||||
if (@field(Operand, field.name) == tag) {
|
||||
// Add one for the tag itself.
|
||||
return 1 + operandsSize(field.type, @field(operand, field.name));
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ fn Printer(comptime Writer: type) type {
|
|||
fn printFieldAny(self: @This(), indent: u16, name: []const u8, value: anytype) !void {
|
||||
try self.printFieldName(indent, name);
|
||||
try self.tty.setColor(self.writer, .cyan);
|
||||
if (@typeInfo(@TypeOf(value)) == .Pointer) {
|
||||
if (@typeInfo(@TypeOf(value)) == .pointer) {
|
||||
// assume string
|
||||
try self.writer.print("{s}", .{value});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub const BindGroup = opaque {
|
|||
texture_view: ?*TextureView = null,
|
||||
|
||||
/// Helper to create a buffer BindGroup.Entry.
|
||||
pub fn buffer(binding: u32, buf: *Buffer, offset: u64, size: u64, elem_size: u32) Entry {
|
||||
pub fn initBuffer(binding: u32, buf: *Buffer, offset: u64, size: u64, elem_size: u32) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.buffer = buf,
|
||||
|
|
@ -34,7 +34,7 @@ pub const BindGroup = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a sampler BindGroup.Entry.
|
||||
pub fn sampler(binding: u32, _sampler: *Sampler) Entry {
|
||||
pub fn initSampler(binding: u32, _sampler: *Sampler) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.sampler = _sampler,
|
||||
|
|
@ -43,7 +43,7 @@ pub const BindGroup = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a texture view BindGroup.Entry.
|
||||
pub fn textureView(binding: u32, texture_view: *TextureView) Entry {
|
||||
pub fn initTextureView(binding: u32, texture_view: *TextureView) Entry {
|
||||
return .{
|
||||
.binding = binding,
|
||||
.texture_view = texture_view,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub const BindGroupLayout = opaque {
|
|||
storage_texture: StorageTextureBindingLayout = .{},
|
||||
|
||||
/// Helper to create a buffer BindGroupLayout.Entry.
|
||||
pub fn buffer(
|
||||
pub fn initBuffer(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Buffer.BindingType,
|
||||
|
|
@ -45,7 +45,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a sampler BindGroupLayout.Entry.
|
||||
pub fn sampler(
|
||||
pub fn initSampler(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
binding_type: Sampler.BindingType,
|
||||
|
|
@ -58,7 +58,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a texture BindGroupLayout.Entry.
|
||||
pub fn texture(
|
||||
pub fn initTexture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
sample_type: Texture.SampleType,
|
||||
|
|
@ -77,7 +77,7 @@ pub const BindGroupLayout = opaque {
|
|||
}
|
||||
|
||||
/// Helper to create a storage texture BindGroupLayout.Entry.
|
||||
pub fn storageTexture(
|
||||
pub fn initStorageTexture(
|
||||
binding: u32,
|
||||
visibility: ShaderStageFlags,
|
||||
access: StorageTextureAccess,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue