From 26c5cb5d607e0dff3c34390ad9677cc226c89e3e Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 4 Oct 2024 13:45:45 -0700 Subject: [PATCH] update to Zig 2024.10-mach (helps hexops/mach#1276) Signed-off-by: Stephen Gutekanst --- .zigversion | 2 +- build.zig.zon | 50 ++++----- examples/custom-renderer/Renderer.zig | 4 +- examples/glyphs/App.zig | 4 +- examples/glyphs/Glyphs.zig | 8 +- examples/hardware-check/App.zig | 4 +- examples/sprite/App.zig | 4 +- examples/text/App.zig | 4 +- src/Audio.zig | 8 +- src/core/Darwin.zig | 4 - src/core/Linux.zig | 5 - src/core/Null.zig | 4 - src/core/linux/Wayland.zig | 24 ++-- src/gamemode.zig | 2 +- src/gfx/SpritePipeline.zig | 36 +++--- src/gfx/TextPipeline.zig | 24 ++-- src/module/entities.zig | 10 +- src/module/module.zig | 116 ++++++++++---------- src/sysaudio/alsa.zig | 2 +- src/sysaudio/jack.zig | 2 +- src/sysaudio/main.zig | 4 +- src/sysaudio/pipewire.zig | 2 +- src/sysaudio/pulseaudio.zig | 2 +- src/sysgpu/opengl/proc.zig | 2 +- src/sysgpu/shader/codegen/spirv/Section.zig | 52 ++++----- src/sysgpu/shader/print_air.zig | 2 +- src/sysgpu/sysgpu/bind_group.zig | 6 +- src/sysgpu/sysgpu/bind_group_layout.zig | 8 +- 28 files changed, 192 insertions(+), 203 deletions(-) diff --git a/.zigversion b/.zigversion index f873e88a..a8bedd2f 100644 --- a/.zigversion +++ b/.zigversion @@ -1 +1 @@ -0.13.0-dev.351+64ef45eb0 +0.14.0-dev.1710+8ee52f99c diff --git a/build.zig.zon b/build.zig.zon index 1ef4d637..b1d49fd5 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,71 +12,71 @@ }, .dependencies = .{ .mach_freetype = .{ - .url = "https://pkg.machengine.org/mach-freetype/86fc8024d4ddd53df75dfa4f3ad4eebe0b1b4284.tar.gz", - .hash = "12206251ed342f400b80abf3c338521f5d8c83eb596899abf77a2afe0cfd46e61ff0", + .url = "https://pkg.machengine.org/mach-freetype/288ab786fa21216e2420b9d8b42aec8cc17d1a2c.tar.gz", + .hash = "12207fcf92e0ebf400ed9a4f4a3e31b3719bf829db933f2007dd398eb7568e5cc71a", .lazy = true, }, .font_assets = .{ - .url = "https://github.com/hexops/font-assets/archive/899f16b815fde126ba8f6fb781e65253f461b7bf.tar.gz", - .hash = "12202b816e7c31c516bd87218fd56f9b1f93671e4ab42a2a98110d586c4b3bdd2730", + .url = "https://github.com/hexops/font-assets/archive/0cd16a0a8a59b525508d6bf3cd22e9c409ad461f.tar.gz", + .hash = "1220fd0ff82273f04dfbc2ffd91b1423a0a28dff7382194676a9949b87eabb6d45b2", .lazy = true, }, .mach_objc = .{ - .url = "https://pkg.machengine.org/mach-objc/773066d8a4632fa4248fe6440737f1e51a80ab0f.tar.gz", - .hash = "122024a2904908c61347c7055e2ab2aa09b66c41c7d430b213e00269cf9d4eb9a86d", + .url = "https://pkg.machengine.org/mach-objc/8c04f317104d5a0b24806c6da7ddea2cf67ece94.tar.gz", + .hash = "1220396d9181fde88d809dbe7cb7f337f4217b4e242106e417053ce5877c9330d15e", .lazy = true, }, .xcode_frameworks = .{ - .url = "https://pkg.machengine.org/xcode-frameworks/122b43323db27b2082a2d44ed2121de21c9ccf75.tar.gz", - .hash = "12205d131983601cdb3500f38e9d8adaed5574fb0211b8b39291d2e9b90c6555ce59", + .url = "https://pkg.machengine.org/xcode-frameworks/a6bf82e032d4d9923ad5c222d466710fcc05f249.tar.gz", + .hash = "12208da4dfcd9b53fb367375fb612ec73f38e53015f1ce6ae6d6e8437a637078e170", // TODO(build): be able to mark this dependency as lazy // .lazy = true, }, .direct3d_headers = .{ - .url = "https://pkg.machengine.org/direct3d-headers/9417c58f11628b7072f0c63b687282de83592891.tar.gz", - .hash = "12203594c3c97220742be1cc5343547bb25d8947e77bd52c50ef713da676d6f6d31f", + .url = "https://pkg.machengine.org/direct3d-headers/edfc992810c9f19b4003f398ed30e08a0dd3d356.tar.gz", + .hash = "1220749946556b76ab6875dd37061bfc26b6a99655f1d712760cf3f1cf0c0f276022", // TODO(build): be able to mark this dependency as lazy // .lazy = true, }, .opengl_headers = .{ - .url = "https://pkg.machengine.org/opengl-headers/96c7c6eca973240a503016ca9d270d76e75dc590.tar.gz", - .hash = "12209f5ec4fa073c3b5b5129a72b7b230596af48a732bed539e35161395ed590095d", + .url = "https://pkg.machengine.org/opengl-headers/6efe91ce7a3c1e83b9235df3da491e45e2f05cc3.tar.gz", + .hash = "1220462ef96ab2bc32844924ce271b1157ac2f2dcede8263506a1b6f6df3f467cae4", .lazy = true, }, .vulkan_zig_generated = .{ - .url = "https://pkg.machengine.org/vulkan-zig-generated/b97664ad438782f723020efb07c3e59e0b3c90c0.tar.gz", - .hash = "1220d2b6789b71a94e692cb2f060bff4ffa4edfe196216cd573da68e74ab884eb34e", + .url = "https://pkg.machengine.org/vulkan-zig-generated/d0d0711f4fe64666354bfabe97e9ad44425503e6.tar.gz", + .hash = "1220ed0faeb2bb655616c078dbf9a3c4468392829b1e1ee48b1a2fdbf8052d9de854", .lazy = true, }, .linux_audio_headers = .{ - .url = "https://pkg.machengine.org/linux-audio-headers/55524472876fe73bac0dcaa11b38f92958751ad4.tar.gz", - .hash = "122042c20087cc1e40d24a61c9d725be36ac5914d6e87e1776cc3cfaecedbcc0be16", + .url = "https://pkg.machengine.org/linux-audio-headers/f3c7af67371ac8ccc1ba9c9401833b78ab7d7300.tar.gz", + .hash = "12205e969e48f38bcc1184c4ea41785b662d1c694fb31225406a871cf491a5bed31e", .lazy = true, }, .wayland_headers = .{ - .url = "https://pkg.machengine.org/wayland-headers/ed5542501a548ac23841c8f22cec0af89f46325a.tar.gz", - .hash = "1220f350a0782d20a6618ea4e2884f7d0205a4e9b02c2d65fe3bf7b8113e7860fadf", + .url = "https://pkg.machengine.org/wayland-headers/1c525e7de7be1507195cd38b1094e6b7795150ee.tar.gz", + .hash = "122009619b6245915453c63c1e0dbeed987bd23e7b46b41a7f4b959b98c6b687c28e", .lazy = true, }, .x11_headers = .{ - .url = "https://pkg.machengine.org/x11-headers/22bb51a939722a819bf52aba100ac6c25acfbaff.tar.gz", - .hash = "1220ddf168c855cf69b4f8c5284403106a3c681913e34453df10cc5a588d9bd1d005", + .url = "https://pkg.machengine.org/x11-headers/aaf971d5e0c4326323b433d6072705dc63bfb501.tar.gz", + .hash = "122023550e14d4e3400c59a26890f9c2eaccfbbb8f852cf3e44ce6a061b0cb488339", .lazy = true, }, // Dependencies used by examples only .zigimg = .{ - .url = "https://github.com/zigimg/zigimg/archive/588f11f24cdc3b12f46082217dc830436b7f325e.tar.gz", - .hash = "1220dc313944ea71a87b4f54f26b1427ad2992a721a221cb42f7f80b8eee4e4944b7", + .url = "https://github.com/zigimg/zigimg/archive/d9dbbe22b5f7b5f1f4772169ed93ffeed8e8124d.tar.gz", + .hash = "122013646f7038ecc71ddf8a0d7de346d29a6ec40140af57f838b0a975c69af512b0", .lazy = true, }, .mach_opus = .{ - .url = "https://pkg.machengine.org/mach-opus/9dafde653d4c5f1610f84f8f40df370bce9c6439.tar.gz", - .hash = "12203e942ae6563c5fb05dff8e8a406b71fe6682342ae5d8d26093e6f9e3d2e02777", + .url = "https://pkg.machengine.org/mach-opus/1bb1b393740e0308683a74ec98da2b65a4af5db6.tar.gz", + .hash = "122007171e1ba7ab2676b6c98bd716e10705a99a9abf4e3f7a0ef7e5ffe5ff4e0fc3", .lazy = true, }, .mach_example_assets = .{ - .url = "https://pkg.machengine.org/mach-example-assets/c2b0aae2b0f359d3d9bd6eea4560ef294126d1e5.tar.gz", + .url = "https://pkg.machengine.org/mach-example-assets/78c6639e46aa88671d5ae7a28e097870d9e763c6.tar.gz", .hash = "12204101e99906bee0fde5f82682bc822744a6f879dbf45374bebd92458492313df9", .lazy = true, }, diff --git a/examples/custom-renderer/Renderer.zig b/examples/custom-renderer/Renderer.zig index 89b0555a..e7a5708c 100644 --- a/examples/custom-renderer/Renderer.zig +++ b/examples/custom-renderer/Renderer.zig @@ -62,7 +62,7 @@ fn init( .mapped_at_creation = .false, }); - const bind_group_layout_entry = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0); + const bind_group_layout_entry = gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, true, 0); const bind_group_layout = device.createBindGroupLayout( &gpu.BindGroupLayout.Descriptor.init(.{ .label = label, @@ -77,7 +77,7 @@ fn init( &gpu.BindGroup.Descriptor.init(.{ .label = label, .layout = bind_group_layout, - .entries = &.{gpu.BindGroup.Entry.buffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject), @sizeOf(UniformBufferObject))}, + .entries = &.{gpu.BindGroup.Entry.initBuffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject), @sizeOf(UniformBufferObject))}, }), ); } diff --git a/examples/glyphs/App.zig b/examples/glyphs/App.zig index 33cc45df..4feb17bc 100644 --- a/examples/glyphs/App.zig +++ b/examples/glyphs/App.zig @@ -20,7 +20,7 @@ spawn_timer: mach.time.Timer, fps_timer: mach.time.Timer, frame_count: usize, sprites: usize, -rand: std.rand.DefaultPrng, +rand: std.Random.DefaultPrng, time: f32, pipeline: mach.EntityID, frame_encoder: *gpu.CommandEncoder = undefined, @@ -94,7 +94,7 @@ fn init( .fps_timer = try mach.time.Timer.start(), .frame_count = 0, .sprites = 0, - .rand = std.rand.DefaultPrng.init(1337), + .rand = std.Random.DefaultPrng.init(1337), .time = 0, .pipeline = pipeline, }); diff --git a/examples/glyphs/Glyphs.zig b/examples/glyphs/Glyphs.zig index f693f4c4..f5104bc0 100644 --- a/examples/glyphs/Glyphs.zig +++ b/examples/glyphs/Glyphs.zig @@ -1,6 +1,6 @@ const mach = @import("mach"); const gpu = mach.gpu; -const ft = @import("freetype"); +const freetype = @import("freetype"); const std = @import("std"); const assets = @import("assets"); @@ -20,8 +20,8 @@ var gpa = std.heap.GeneralPurposeAllocator(.{}){}; texture_atlas: mach.gfx.Atlas, texture: *gpu.Texture, -ft: ft.Library, -face: ft.Face, +ft: freetype.Library, +face: freetype.Face, regions: RegionMap = .{}, allocator: std.mem.Allocator, @@ -63,7 +63,7 @@ fn init( .rgba, ); - const ft_lib = try ft.Library.init(); + const ft_lib = try freetype.Library.init(); const face = try ft_lib.createFaceMemory(assets.roboto_medium_ttf, 0); glyphs.init(.{ diff --git a/examples/hardware-check/App.zig b/examples/hardware-check/App.zig index 03b3f7ed..80d2898c 100644 --- a/examples/hardware-check/App.zig +++ b/examples/hardware-check/App.zig @@ -28,7 +28,7 @@ frame_count: usize, frame_rate: usize, num_sprites_spawned: usize, score: usize, -rand: std.rand.DefaultPrng, +rand: std.Random.DefaultPrng, time: f32, allocator: std.mem.Allocator, pipeline: mach.EntityID, @@ -148,7 +148,7 @@ fn init( .frame_rate = 0, .num_sprites_spawned = 0, .score = 0, - .rand = std.rand.DefaultPrng.init(1337), + .rand = std.Random.DefaultPrng.init(1337), .time = 0, .allocator = allocator, .pipeline = pipeline, diff --git a/examples/sprite/App.zig b/examples/sprite/App.zig index 106d93fa..8ce68bd2 100644 --- a/examples/sprite/App.zig +++ b/examples/sprite/App.zig @@ -25,7 +25,7 @@ spawn_timer: mach.time.Timer, fps_timer: mach.time.Timer, frame_count: usize, sprites: usize, -rand: std.rand.DefaultPrng, +rand: std.Random.DefaultPrng, time: f32, allocator: std.mem.Allocator, pipeline: mach.EntityID, @@ -98,7 +98,7 @@ fn init( .fps_timer = try mach.time.Timer.start(), .frame_count = 0, .sprites = 0, - .rand = std.rand.DefaultPrng.init(1337), + .rand = std.Random.DefaultPrng.init(1337), .time = 0, .allocator = allocator, .pipeline = pipeline, diff --git a/examples/text/App.zig b/examples/text/App.zig index 2e04b6e6..0eedd187 100644 --- a/examples/text/App.zig +++ b/examples/text/App.zig @@ -21,7 +21,7 @@ spawning: bool = false, spawn_timer: mach.time.Timer, fps_timer: mach.time.Timer, frame_count: usize, -rand: std.rand.DefaultPrng, +rand: std.Random.DefaultPrng, time: f32, style1: mach.EntityID, pipeline: mach.EntityID, @@ -109,7 +109,7 @@ fn init( .player = player, .fps_timer = try mach.time.Timer.start(), .frame_count = 0, - .rand = std.rand.DefaultPrng.init(1337), + .rand = std.Random.DefaultPrng.init(1337), .time = 0, .style1 = style1, .pipeline = pipeline, diff --git a/src/Audio.zig b/src/Audio.zig index 26ab5a90..728fc4fd 100644 --- a/src/Audio.zig +++ b/src/Audio.zig @@ -283,10 +283,10 @@ inline fn mixSamples(a: []f32, b: []const f32, volume: f32) void { if (vector_length) |vec_len| { const Vec = @Vector(vec_len, f32); const vec_blocks_len = b.len - (b.len % vec_len); - while (i < vec_blocks_len) : (i += vec_len) { const b_vec: Vec = b[i..][0..vec_len].*; - a[i..][0..vec_len].* += b_vec * @as(Vec, @splat(volume)); + const a_vec: *Vec = @ptrCast(@alignCast(a[i..][0..vec_len])); + a_vec.* += b_vec * @as(Vec, @splat(volume)); } } @@ -300,9 +300,11 @@ inline fn mixSamplesDuplicate(a: []f32, b: f32) void { // use SIMD when available if (vector_length) |vec_len| { + const Vec = @Vector(vec_len, f32); const vec_blocks_len = a.len - (a.len % vec_len); while (i < vec_blocks_len) : (i += vec_len) { - a[i..][0..vec_len].* += @as(@Vector(vec_len, f32), @splat(b)); + const a_vec: *Vec = @ptrCast(@alignCast(a[i..][0..vec_len])); + a_vec.* += @as(Vec, @splat(b)); } } diff --git a/src/core/Darwin.zig b/src/core/Darwin.zig index 2d0e17d8..40113803 100644 --- a/src/core/Darwin.zig +++ b/src/core/Darwin.zig @@ -155,10 +155,6 @@ pub fn setSize(_: *Darwin, _: Size) void { return; } -pub fn size(_: *Darwin) Size { - return Size{ .width = 100, .height = 100 }; -} - pub fn setCursorMode(_: *Darwin, _: CursorMode) void { return; } diff --git a/src/core/Linux.zig b/src/core/Linux.zig index 551cffe7..41cff7d9 100644 --- a/src/core/Linux.zig +++ b/src/core/Linux.zig @@ -155,10 +155,6 @@ pub fn setSize(_: *Linux, _: Size) void { return; } -pub fn size(_: *Linux) Size { - return Size{ .width = 100, .height = 100 }; -} - pub fn setCursorMode(_: *Linux, _: CursorMode) void { return; } @@ -192,4 +188,3 @@ pub fn deinitLinuxGamemode() void { mach.gamemode.stop(); gamemode_log.info("gamemode: deactivated", .{}); } - diff --git a/src/core/Null.zig b/src/core/Null.zig index aa753223..4dd4ebd2 100644 --- a/src/core/Null.zig +++ b/src/core/Null.zig @@ -80,10 +80,6 @@ pub fn setSize(_: *Null, _: Size) void { return; } -pub fn size(_: *Null) Size { - return Size{ .width = 100, .height = 100 }; -} - pub fn setCursorMode(_: *Null, _: CursorMode) void { return; } diff --git a/src/core/linux/Wayland.zig b/src/core/linux/Wayland.zig index 8cf05ccc..aa1030a2 100644 --- a/src/core/linux/Wayland.zig +++ b/src/core/linux/Wayland.zig @@ -23,26 +23,26 @@ pub const c = @cImport({ // This needs to be declared here so it can be used in the exported functions below, // but doesn't need to be defined until run time (and can't be defined until run time). -var libwaylandclient: LibWaylandClient = undefined; +var libwaylandclient_global: LibWaylandClient = undefined; // These exported functions are defined because the wayland headers don't define them, -// and then the linker gets confused. They reference undefined `libwaylandclient` at -// compile time, but since they are not run until run time, after `libwaylandclient` is +// and then the linker gets confused. They reference undefined `libwaylandclient_global` at +// compile time, but since they are not run until run time, after `libwaylandclient_global` is // defined, an error never occurs. export fn wl_proxy_add_listener(proxy: ?*c.struct_wl_proxy, implementation: [*c]?*const fn () callconv(.C) void, data: ?*anyopaque) c_int { - return @call(.always_tail, libwaylandclient.wl_proxy_add_listener, .{ proxy, implementation, data }); + return @call(.always_tail, libwaylandclient_global.wl_proxy_add_listener, .{ proxy, implementation, data }); } export fn wl_proxy_get_version(proxy: ?*c.struct_wl_proxy) u32 { - return @call(.always_tail, libwaylandclient.wl_proxy_get_version, .{proxy}); + return @call(.always_tail, libwaylandclient_global.wl_proxy_get_version, .{proxy}); } export fn wl_proxy_marshal_flags(proxy: ?*c.struct_wl_proxy, opcode: u32, interface: [*c]const c.struct_wl_interface, version: u32, flags: u32, ...) ?*c.struct_wl_proxy { var arg_list: std.builtin.VaList = @cVaStart(); defer @cVaEnd(&arg_list); - return @call(.always_tail, libwaylandclient.wl_proxy_marshal_flags, .{ proxy, opcode, interface, version, flags, arg_list }); + return @call(.always_tail, libwaylandclient_global.wl_proxy_marshal_flags, .{ proxy, opcode, interface, version, flags, arg_list }); } export fn wl_proxy_destroy(proxy: ?*c.struct_wl_proxy) void { - return @call(.always_tail, libwaylandclient.wl_proxy_destroy, .{proxy}); + return @call(.always_tail, libwaylandclient_global.wl_proxy_destroy, .{proxy}); } state: *Core, @@ -76,14 +76,14 @@ pub fn init( core: *Core.Mod, options: InitOptions, ) !Wayland { - libwaylandclient = try LibWaylandClient.load(); + libwaylandclient_global = try LibWaylandClient.load(); var wl = Wayland{ .core = @fieldParentPtr("platform", linux), .state = core.state(), .libxkbcommon = try LibXkbCommon.load(), - .libwaylandclient = libwaylandclient, + .libwaylandclient = libwaylandclient_global, .interfaces = Interfaces{}, - .display = libwaylandclient.wl_display_connect(null) orelse return error.FailedToConnectToWaylandDisplay, + .display = libwaylandclient_global.wl_display_connect(null) orelse return error.FailedToConnectToWaylandDisplay, .title = try options.allocator.dupeZ(u8, options.title), .size = &linux.size, .modifiers = .{ @@ -206,7 +206,7 @@ const LibXkbCommon = struct { pub fn load() !LibXkbCommon { var lib: LibXkbCommon = undefined; lib.handle = std.DynLib.open("libxkbcommon.so.0") catch return error.LibraryNotFound; - inline for (@typeInfo(LibXkbCommon).Struct.fields[1..]) |field| { + inline for (@typeInfo(LibXkbCommon).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse { @@ -258,7 +258,7 @@ const LibWaylandClient = struct { pub fn load() !LibWaylandClient { var lib: LibWaylandClient = undefined; lib.handle = std.DynLib.open("libwayland-client.so.0") catch return error.LibraryNotFound; - inline for (@typeInfo(LibWaylandClient).Struct.fields[1..]) |field| { + inline for (@typeInfo(LibWaylandClient).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse { diff --git a/src/gamemode.zig b/src/gamemode.zig index 4426a0a3..928d55a1 100644 --- a/src/gamemode.zig +++ b/src/gamemode.zig @@ -109,7 +109,7 @@ const linux_impl = struct { // Populate symbol table. var sym_table: SymbolTable = undefined; - inline for (@typeInfo(SymbolTable).Struct.fields) |field| { + inline for (@typeInfo(SymbolTable).@"struct".fields) |field| { @field(sym_table, field.name) = dl.lookup(field.type, field.name ++ &[_:0]u8{}) orelse { log.err("libgamemode missing symbol '{s}'", .{field.name}); return error.MissingSymbol; diff --git a/src/gfx/SpritePipeline.zig b/src/gfx/SpritePipeline.zig index 41567f86..3e4e4f2a 100644 --- a/src/gfx/SpritePipeline.zig +++ b/src/gfx/SpritePipeline.zig @@ -238,15 +238,15 @@ fn buildPipeline( &gpu.BindGroupLayout.Descriptor.init(.{ .label = label, .entries = &.{ - gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), - gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering), - gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false), - gpu.BindGroupLayout.Entry.texture(6, .{ .fragment = true }, .float, .dimension_2d, false), - gpu.BindGroupLayout.Entry.texture(7, .{ .fragment = true }, .float, .dimension_2d, false), - gpu.BindGroupLayout.Entry.texture(8, .{ .fragment = true }, .float, .dimension_2d, false), + gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering), + gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false), + gpu.BindGroupLayout.Entry.initTexture(6, .{ .fragment = true }, .float, .dimension_2d, false), + gpu.BindGroupLayout.Entry.initTexture(7, .{ .fragment = true }, .float, .dimension_2d, false), + gpu.BindGroupLayout.Entry.initTexture(8, .{ .fragment = true }, .float, .dimension_2d, false), }, }), ); @@ -264,15 +264,15 @@ fn buildPipeline( .label = label, .layout = bind_group_layout, .entries = &.{ - gpu.BindGroup.Entry.buffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), - gpu.BindGroup.Entry.buffer(1, transforms, 0, @sizeOf(math.Mat4x4) * sprite_buffer_cap, @sizeOf(math.Mat4x4)), - gpu.BindGroup.Entry.buffer(2, uv_transforms, 0, @sizeOf(math.Mat3x3) * sprite_buffer_cap, @sizeOf(math.Mat3x3)), - gpu.BindGroup.Entry.buffer(3, sizes, 0, @sizeOf(math.Vec2) * sprite_buffer_cap, @sizeOf(math.Vec2)), - gpu.BindGroup.Entry.sampler(4, texture_sampler), - gpu.BindGroup.Entry.textureView(5, texture_view), - gpu.BindGroup.Entry.textureView(6, texture2_view), - gpu.BindGroup.Entry.textureView(7, texture3_view), - gpu.BindGroup.Entry.textureView(8, texture4_view), + gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), + gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * sprite_buffer_cap, @sizeOf(math.Mat4x4)), + gpu.BindGroup.Entry.initBuffer(2, uv_transforms, 0, @sizeOf(math.Mat3x3) * sprite_buffer_cap, @sizeOf(math.Mat3x3)), + gpu.BindGroup.Entry.initBuffer(3, sizes, 0, @sizeOf(math.Vec2) * sprite_buffer_cap, @sizeOf(math.Vec2)), + gpu.BindGroup.Entry.initSampler(4, texture_sampler), + gpu.BindGroup.Entry.initTextureView(5, texture_view), + gpu.BindGroup.Entry.initTextureView(6, texture2_view), + gpu.BindGroup.Entry.initTextureView(7, texture3_view), + gpu.BindGroup.Entry.initTextureView(8, texture4_view), }, }), ); diff --git a/src/gfx/TextPipeline.zig b/src/gfx/TextPipeline.zig index 9c7875df..bb60f431 100644 --- a/src/gfx/TextPipeline.zig +++ b/src/gfx/TextPipeline.zig @@ -280,12 +280,12 @@ fn buildPipeline( &gpu.BindGroupLayout.Descriptor.init(.{ .label = label, .entries = &.{ - gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), - gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.buffer(2, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.buffer(3, .{ .vertex = true }, .read_only_storage, false, 0), - gpu.BindGroupLayout.Entry.sampler(4, .{ .fragment = true }, .filtering), - gpu.BindGroupLayout.Entry.texture(5, .{ .fragment = true }, .float, .dimension_2d, false), + gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(1, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(2, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initBuffer(3, .{ .vertex = true }, .read_only_storage, false, 0), + gpu.BindGroupLayout.Entry.initSampler(4, .{ .fragment = true }, .filtering), + gpu.BindGroupLayout.Entry.initTexture(5, .{ .fragment = true }, .float, .dimension_2d, false), }, }), ); @@ -299,12 +299,12 @@ fn buildPipeline( .label = label, .layout = bind_group_layout, .entries = &.{ - gpu.BindGroup.Entry.buffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), - gpu.BindGroup.Entry.buffer(1, transforms, 0, @sizeOf(math.Mat4x4) * texts_buffer_cap, @sizeOf(math.Mat4x4)), - gpu.BindGroup.Entry.buffer(2, colors, 0, @sizeOf(math.Vec4) * texts_buffer_cap, @sizeOf(math.Vec4)), - gpu.BindGroup.Entry.buffer(3, glyphs, 0, @sizeOf(Glyph) * texts_buffer_cap, @sizeOf(Glyph)), - gpu.BindGroup.Entry.sampler(4, texture_sampler), - gpu.BindGroup.Entry.textureView(5, texture_view), + gpu.BindGroup.Entry.initBuffer(0, uniforms, 0, @sizeOf(Uniforms), @sizeOf(Uniforms)), + gpu.BindGroup.Entry.initBuffer(1, transforms, 0, @sizeOf(math.Mat4x4) * texts_buffer_cap, @sizeOf(math.Mat4x4)), + gpu.BindGroup.Entry.initBuffer(2, colors, 0, @sizeOf(math.Vec4) * texts_buffer_cap, @sizeOf(math.Vec4)), + gpu.BindGroup.Entry.initBuffer(3, glyphs, 0, @sizeOf(Glyph) * texts_buffer_cap, @sizeOf(Glyph)), + gpu.BindGroup.Entry.initSampler(4, texture_sampler), + gpu.BindGroup.Entry.initTextureView(5, texture_view), }, }), ); diff --git a/src/module/entities.zig b/src/module/entities.zig index 52a23f48..51b9747d 100644 --- a/src/module/entities.zig +++ b/src/module/entities.zig @@ -755,7 +755,7 @@ pub fn Database(comptime modules: anytype) type { .is_comptime = false, .alignment = @alignOf(usize), }}; - for (@typeInfo(@TypeOf(q)).Struct.fields) |slice| { + for (@typeInfo(@TypeOf(q)).@"struct".fields) |slice| { const value: ComponentQuery = @field(q, slice.name); switch (value) { .read => |v| { @@ -787,7 +787,7 @@ pub fn Database(comptime modules: anytype) type { } } break :blk @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -801,7 +801,7 @@ pub fn Database(comptime modules: anytype) type { var slices: Slices = undefined; slices.len = archetype.len; - inline for (@typeInfo(@TypeOf(q)).Struct.fields) |slice| { + inline for (@typeInfo(@TypeOf(q)).@"struct".fields) |slice| { const value: ComponentQuery = @field(q, slice.name); switch (value) { .read => |v| { @@ -840,8 +840,8 @@ pub fn Database(comptime modules: anytype) type { /// value is `.read()` or `.write()` determines whether the slices are `[]T` (mutable) or /// `[]const T` (immutable). pub fn query(entities: *Self, comptime q: anytype) !QueryResult(q) { - var op_and: [@typeInfo(@TypeOf(q)).Struct.fields.len]QueryDynamic = undefined; - inline for (@typeInfo(@TypeOf(q)).Struct.fields, 0..) |slice, i| { + var op_and: [@typeInfo(@TypeOf(q)).@"struct".fields.len]QueryDynamic = undefined; + inline for (@typeInfo(@TypeOf(q)).@"struct".fields, 0..) |slice, i| { const value: ComponentQuery = @field(q, slice.name); switch (value) { .read => |v| op_and[i] = .{ .read = entities.componentName(v.module, v.component) }, diff --git a/src/module/module.zig b/src/module/module.zig index 9707e208..6d7c210a 100644 --- a/src/module/module.zig +++ b/src/module/module.zig @@ -17,9 +17,9 @@ fn ModuleInterface(comptime M: type) type { } fn validateModule(comptime M: type, comptime systems: bool) void { - if (@typeInfo(M) != .Struct) @compileError("mach: expected module struct, found: " ++ @typeName(M)); + if (@typeInfo(M) != .@"struct") @compileError("mach: expected module struct, found: " ++ @typeName(M)); if (!@hasDecl(M, "name")) @compileError("mach: module must have `pub const name = .foobar;`: " ++ @typeName(M)); - if (@typeInfo(@TypeOf(M.name)) != .EnumLiteral) @compileError("mach: module must have `pub const name = .foobar;`, found type:" ++ @typeName(M.name)); + if (@typeInfo(@TypeOf(M.name)) != .enum_literal) @compileError("mach: module must have `pub const name = .foobar;`, found type:" ++ @typeName(M.name)); if (systems) { if (@hasDecl(M, "systems")) validateSystems("mach: module ." ++ @tagName(M.name) ++ " systems ", M.systems); _ = ComponentTypesM(M); @@ -44,14 +44,14 @@ pub const AnySystem = struct { /// Type-returning variant of merge() pub fn Merge(comptime tuple: anytype) type { - if (@typeInfo(@TypeOf(tuple)) != .Struct or !@typeInfo(@TypeOf(tuple)).Struct.is_tuple) { + if (@typeInfo(@TypeOf(tuple)) != .@"struct" or !@typeInfo(@TypeOf(tuple)).@"struct".is_tuple) { @compileError("Expected to find a tuple, found: " ++ @typeName(@TypeOf(tuple))); } var tuple_fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{}; loop: inline for (tuple) |elem| { @setEvalBranchQuota(10_000); - if (@typeInfo(@TypeOf(elem)) == .Type and @typeInfo(elem) == .Struct) { + if (@typeInfo(@TypeOf(elem)) == .type and @typeInfo(elem) == .@"struct") { // Struct type validateModule(elem, false); for (tuple_fields) |field| if (@as(*const type, @ptrCast(field.default_value.?)).* == elem) @@ -65,7 +65,7 @@ pub fn Merge(comptime tuple: anytype) type { .is_comptime = false, .alignment = if (@sizeOf(elem) > 0) @alignOf(elem) else 0, }}; - } else if (@typeInfo(@TypeOf(elem)) == .Struct and @typeInfo(@TypeOf(elem)).Struct.is_tuple) { + } else if (@typeInfo(@TypeOf(elem)) == .@"struct" and @typeInfo(@TypeOf(elem)).@"struct".is_tuple) { // Nested tuple inline for (Merge(elem){}) |Nested| { validateModule(Nested, false); @@ -86,7 +86,7 @@ pub fn Merge(comptime tuple: anytype) type { } } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .is_tuple = true, .layout = .auto, .decls = &.{}, @@ -172,7 +172,7 @@ pub fn Modules(comptime modules: anytype) type { try m.dispatch_queue.ensureTotalCapacity(1024); // TODO(module): better default allocations // Default initialize m.mod - inline for (@typeInfo(@TypeOf(m.mod)).Struct.fields) |field| { + inline for (@typeInfo(@TypeOf(m.mod)).@"struct".fields) |field| { const Mod2 = @TypeOf(@field(m.mod, field.name)); @field(m.mod, field.name) = Mod2{ .__is_initialized = false, @@ -341,15 +341,15 @@ pub fn Modules(comptime modules: anytype) type { ) !void { const Injectable = comptime blk: { var types: []const type = &[0]type{}; - for (@typeInfo(ModsByName(modules)).Struct.fields) |field| { + for (@typeInfo(ModsByName(modules)).@"struct".fields) |field| { const ModPtr = @TypeOf(@as(*field.type, undefined)); types = types ++ [_]type{ModPtr}; } break :blk std.meta.Tuple(types); }; var injectable: Injectable = undefined; - outer: inline for (@typeInfo(Injectable).Struct.fields) |field| { - inline for (@typeInfo(ModsByName(modules)).Struct.fields) |injectable_field| { + outer: inline for (@typeInfo(Injectable).@"struct".fields) |field| { + inline for (@typeInfo(ModsByName(modules)).@"struct".fields) |injectable_field| { if (*injectable_field.type == field.type) { @field(injectable, field.name) = &@field(m.mod, injectable_field.name); continue :outer; @@ -404,14 +404,14 @@ pub fn Modules(comptime modules: anytype) type { /// Call system handler with the specified name in the specified module inline fn callSystem(m: *@This(), module_name: ModuleName(modules), system_name: System, args: []u8, injectable: anytype) !void { - if (@typeInfo(@TypeOf(system_name)).Enum.fields.len == 0) return; + if (@typeInfo(@TypeOf(system_name)).@"enum".fields.len == 0) return; switch (system_name) { inline else => |ev_name| { switch (module_name) { inline else => |mod_name| { const M = @field(NamespacedModules(modules){}, @tagName(mod_name)); _ = ModuleInterface(M); // Validate the module - if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { + if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| { comptime if (!std.mem.eql(u8, @tagName(ev_name), field.name)) continue; if (m.debug_trace) log.debug("trace: .{s}.{s}", .{ @tagName(M.name), @@ -419,8 +419,8 @@ pub fn Modules(comptime modules: anytype) type { }); const handler = @field(M.systems, @tagName(ev_name)).handler; - if (@typeInfo(@TypeOf(handler)) == .Type) continue; // Pre-declaration of what args an system has, nothing to do. - if (@typeInfo(@TypeOf(handler)) != .Fn) @compileError(std.fmt.comptimePrint("mach: module .{s} declares system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ + if (@typeInfo(@TypeOf(handler)) == .type) continue; // Pre-declaration of what args an system has, nothing to do. + if (@typeInfo(@TypeOf(handler)) != .@"fn") @compileError(std.fmt.comptimePrint("mach: module .{s} declares system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ @tagName(M.name), @tagName(ev_name), @typeName(@TypeOf(handler)), @@ -439,9 +439,9 @@ pub fn Modules(comptime modules: anytype) type { const StdArgs = UninjectedArgsTuple(Handler); const std_args: *StdArgs = @alignCast(@ptrCast(args_data.ptr)); const args = injectArgs(Handler, @TypeOf(injectable), injectable, std_args.*, debug_name); - const Ret = @typeInfo(Handler).Fn.return_type orelse void; + const Ret = @typeInfo(Handler).@"fn".return_type orelse void; switch (@typeInfo(Ret)) { - .ErrorUnion => try @call(.auto, handler, args), + .error_union => try @call(.auto, handler, args), else => @call(.auto, handler, args), } } @@ -461,7 +461,7 @@ pub fn ModsByName(comptime modules: anytype) type { }}; } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -678,18 +678,18 @@ pub fn ModSet(comptime modules: anytype) type { inline fn injectArgs(comptime Function: type, comptime Injectable: type, injectable_args: Injectable, std_args: UninjectedArgsTuple(Function), comptime debug_name: anytype) std.meta.ArgsTuple(Function) { var args: std.meta.ArgsTuple(Function) = undefined; comptime var std_args_index = 0; - outer: inline for (@typeInfo(std.meta.ArgsTuple(Function)).Struct.fields) |arg| { + outer: inline for (@typeInfo(std.meta.ArgsTuple(Function)).@"struct".fields) |arg| { // Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so, // it is considered an injected argument. - inline for (@typeInfo(Injectable).Struct.fields) |inject_field| { + inline for (@typeInfo(Injectable).@"struct".fields) |inject_field| { if (inject_field.type == arg.type and @alignOf(inject_field.type) == @alignOf(arg.type)) { // Inject argument @field(args, arg.name) = @field(injectable_args, inject_field.name); continue :outer; } } - if (@typeInfo(arg.type) == .Pointer and - @typeInfo(std.meta.Child(arg.type)) == .Struct and + if (@typeInfo(arg.type) == .pointer and + @typeInfo(std.meta.Child(arg.type)) == .@"struct" and @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument")) { // Argument is declared as injectable, but we do not have a value to inject for it. @@ -714,15 +714,15 @@ inline fn injectArgs(comptime Function: type, comptime Injectable: type, injecta // parameters which would **not** be injected. fn UninjectedArgsTuple(comptime Function: type) type { var std_args: []const type = &[0]type{}; - inline for (@typeInfo(std.meta.ArgsTuple(Function)).Struct.fields) |arg| { + inline for (@typeInfo(std.meta.ArgsTuple(Function)).@"struct".fields) |arg| { // Is this a Struct or *Struct, with a `pub const IsInjectedArgument = void;` decl? If so, // it is considered an injected argument. const is_injected = blk: { switch (@typeInfo(arg.type)) { - .Struct => break :blk @hasDecl(arg.type, "IsInjectedArgument"), - .Pointer => { + .@"struct" => break :blk @hasDecl(arg.type, "IsInjectedArgument"), + .pointer => { switch (@typeInfo(std.meta.Child(arg.type))) { - .Struct => break :blk @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"), + .@"struct" => break :blk @hasDecl(std.meta.Child(arg.type), "IsInjectedArgument"), else => break :blk false, } }, @@ -737,7 +737,7 @@ fn UninjectedArgsTuple(comptime Function: type) type { // TODO: cannot use std.meta.stringToEnum for some reason; an issue with its internal comptime map and u0 values pub fn stringToEnum(comptime T: type, str: []const u8) ?T { - inline for (@typeInfo(T).Enum.fields) |enumField| { + inline for (@typeInfo(T).@"enum".fields) |enumField| { if (std.mem.eql(u8, str, enumField.name)) { return @field(T, enumField.name); } @@ -750,7 +750,7 @@ fn SystemArgsM(comptime M: type, system_name: anytype) type { const which = "systems"; if (!@hasDecl(M, which)) return @TypeOf(.{}); - inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { + inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| { comptime if (!std.mem.eql(u8, field.name, @tagName(system_name))) continue; if (!@hasField(@TypeOf(M.systems), @tagName(system_name))) @compileError(std.fmt.comptimePrint("mach: module .{s} declares no {s} system .{s}", .{ @tagName(M.name), @@ -759,9 +759,9 @@ fn SystemArgsM(comptime M: type, system_name: anytype) type { })); const handler = @field(M.systems, @tagName(system_name)).handler; const Handler = switch (@typeInfo(@TypeOf(handler))) { - .Type => handler, // Pre-declaration of what args an event has - .Fn => blk: { - if (@typeInfo(@TypeOf(handler)) != .Fn) @compileError(std.fmt.comptimePrint("mach: module .{s} declares {s} system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ + .type => handler, // Pre-declaration of what args an event has + .@"fn" => blk: { + if (@typeInfo(@TypeOf(handler)) != .@"fn") @compileError(std.fmt.comptimePrint("mach: module .{s} declares {s} system .{s} = .{{ .handler = T }}, expected fn but found: {s}", .{ @tagName(M.name), which, @tagName(system_name), @@ -782,7 +782,7 @@ fn SystemEnum(comptime modules: anytype) type { var i: u32 = 0; for (modules) |M| { _ = ModuleInterface(M); // Validate the module - if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { + if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| { const exists_already = blk: { for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true; break :blk false; @@ -794,7 +794,7 @@ fn SystemEnum(comptime modules: anytype) type { }; } return @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0, .fields = enum_fields, .decls = &[_]std.builtin.Type.Declaration{}, @@ -808,7 +808,7 @@ fn SystemEnumM(comptime M: anytype) type { var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{}; var i: u32 = 0; _ = ModuleInterface(M); // Validate the module - if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).Struct.fields) |field| { + if (@hasDecl(M, "systems")) inline for (@typeInfo(@TypeOf(M.systems)).@"struct".fields) |field| { const exists_already = blk: { for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) break :blk true; break :blk false; @@ -819,7 +819,7 @@ fn SystemEnumM(comptime M: anytype) type { } }; return @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = if (enum_fields.len > 0) std.math.IntFittingRange(0, enum_fields.len - 1) else u0, .fields = enum_fields, .decls = &[_]std.builtin.Type.Declaration{}, @@ -840,7 +840,7 @@ pub fn ComponentName(comptime modules: anytype) type { var enum_fields: []const std.builtin.Type.EnumField = &[0]std.builtin.Type.EnumField{}; var i: usize = 0; inline for (modules) |M| { - search: for (@typeInfo(ComponentTypesM(M)).Struct.fields) |field| { + search: for (@typeInfo(ComponentTypesM(M)).@"struct".fields) |field| { for (enum_fields) |existing| if (std.mem.eql(u8, existing.name, field.name)) continue :search; enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{ .name = field.name, @@ -850,7 +850,7 @@ pub fn ComponentName(comptime modules: anytype) type { } } return @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = std.math.IntFittingRange(0, enum_fields.len - 1), .fields = enum_fields, .decls = &[_]std.builtin.Type.Declaration{}, @@ -866,7 +866,7 @@ pub fn ModuleName(comptime modules: anytype) type { enum_fields = enum_fields ++ [_]std.builtin.Type.EnumField{.{ .name = @tagName(M.name), .value = i }}; } return @Type(.{ - .Enum = .{ + .@"enum" = .{ .tag_type = std.math.IntFittingRange(0, enum_fields.len - 1), .fields = enum_fields, .decls = &[_]std.builtin.Type.Declaration{}, @@ -889,7 +889,7 @@ fn NamespacedModules(comptime modules: anytype) type { }}; } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -900,12 +900,12 @@ fn NamespacedModules(comptime modules: anytype) type { // TODO: tests fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) void { - if (@typeInfo(@TypeOf(systems)) != .Struct or @typeInfo(@TypeOf(systems)).Struct.is_tuple) { + if (@typeInfo(@TypeOf(systems)) != .@"struct" or @typeInfo(@TypeOf(systems)).@"struct".is_tuple) { @compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(systems))); } - inline for (@typeInfo(@TypeOf(systems)).Struct.fields) |field| { + inline for (@typeInfo(@TypeOf(systems)).@"struct".fields) |field| { const Event = field.type; - if (@typeInfo(Event) != .Struct) @compileError(std.fmt.comptimePrint( + if (@typeInfo(Event) != .@"struct") @compileError(std.fmt.comptimePrint( error_prefix ++ "expected .{s} = .{{}}, found type: {s}", .{ field.name, @typeName(Event) }, )); @@ -917,9 +917,9 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo .{field.name}, )); const valid_handler_type = switch (@typeInfo(@TypeOf(event.handler))) { - .Fn => true, - .Type => switch (@typeInfo(event.handler)) { - .Fn => true, + .@"fn" => true, + .type => switch (@typeInfo(event.handler)) { + .@"fn" => true, else => false, }, else => false, @@ -930,8 +930,8 @@ fn validateSystems(comptime error_prefix: anytype, comptime systems: anytype) vo )); switch (@typeInfo(@TypeOf(event.handler))) { - .Fn => _ = UninjectedArgsTuple(@TypeOf(event.handler)), - .Type => _ = UninjectedArgsTuple(event.handler), + .@"fn" => _ = UninjectedArgsTuple(@TypeOf(event.handler)), + .type => _ = UninjectedArgsTuple(event.handler), else => unreachable, } } @@ -964,7 +964,7 @@ pub fn ComponentTypesByName(comptime modules: anytype) type { }}; } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -988,13 +988,13 @@ fn ComponentTypesM(comptime M: anytype) type { if (!@hasDecl(M, "components")) { return struct {}; } - if (@typeInfo(@TypeOf(M.components)) != .Struct or @typeInfo(@TypeOf(M.components)).Struct.is_tuple) { + if (@typeInfo(@TypeOf(M.components)) != .@"struct" or @typeInfo(@TypeOf(M.components)).@"struct".is_tuple) { @compileError(error_prefix ++ "expected a struct .{}, found: " ++ @typeName(@TypeOf(M.components))); } var fields: []const std.builtin.Type.StructField = &[0]std.builtin.Type.StructField{}; - inline for (@typeInfo(@TypeOf(M.components)).Struct.fields) |field| { + inline for (@typeInfo(@TypeOf(M.components)).@"struct".fields) |field| { const Component = field.type; - if (@typeInfo(Component) != .Struct) @compileError(std.fmt.comptimePrint( + if (@typeInfo(Component) != .@"struct") @compileError(std.fmt.comptimePrint( error_prefix ++ "expected .{s} = .{{}}, found type: {s}", .{ field.name, @typeName(Component) }, )); @@ -1005,7 +1005,7 @@ fn ComponentTypesM(comptime M: anytype) type { error_prefix ++ ".{s} missing field `.type = T`", .{field.name}, )); - if (@typeInfo(@TypeOf(component.type)) != .Type) @compileError(std.fmt.comptimePrint( + if (@typeInfo(@TypeOf(component.type)) != .type) @compileError(std.fmt.comptimePrint( error_prefix ++ ".{s} expected field `.type = T`, found: {s}", .{ field.name, @typeName(@TypeOf(component.type)) }, )); @@ -1034,7 +1034,7 @@ fn ComponentTypesM(comptime M: anytype) type { }}; } return @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .is_tuple = false, .fields = fields, @@ -1045,10 +1045,10 @@ fn ComponentTypesM(comptime M: anytype) type { fn isString(comptime S: type) bool { return switch (@typeInfo(S)) { - .Pointer => |p| switch (p.size) { + .pointer => |p| switch (p.size) { .Many, .Slice => p.child == u8, .One => switch (@typeInfo(p.child)) { - .Array => |a| a.child == u8, + .array => |a| a.child == u8, else => false, }, else => false, @@ -1194,7 +1194,7 @@ test "system name" { Sprite2D, })); - const locals = @typeInfo(Ms.System).Enum; + const locals = @typeInfo(Ms.System).@"enum"; try testing.expect(type, u3).eql(locals.tag_type); try testing.expect(usize, 8).eql(locals.fields.len); try testing.expect([]const u8, "foo").eql(locals.fields[0].name); @@ -1224,7 +1224,7 @@ test ModuleName { Sprite2D, }); _ = Modules(modules); - const info = @typeInfo(ModuleName(modules)).Enum; + const info = @typeInfo(ModuleName(modules)).@"enum"; try testing.expect(type, u2).eql(info.tag_type); try testing.expect(usize, 4).eql(info.fields.len); @@ -1242,8 +1242,8 @@ const TupleTester = struct { fn assertTuple(comptime expected: anytype, comptime Actual: type) void { const info = @typeInfo(Actual); - if (info != .Struct) @compileError("Expected struct type"); - if (!info.Struct.is_tuple) @compileError("Struct type must be a tuple type"); + if (info != .@"struct") @compileError("Expected struct type"); + if (!info.@"struct".is_tuple) @compileError("Struct type must be a tuple type"); const fields_list = std.meta.fields(Actual); if (expected.len != fields_list.len) @compileError("Argument count mismatch"); diff --git a/src/sysaudio/alsa.zig b/src/sysaudio/alsa.zig index 00f20a62..d08708e1 100644 --- a/src/sysaudio/alsa.zig +++ b/src/sysaudio/alsa.zig @@ -70,7 +70,7 @@ const Lib = struct { pub fn load() !void { lib.handle = std.DynLib.open("libasound.so") catch return error.LibraryNotFound; - inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { + inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; diff --git a/src/sysaudio/jack.zig b/src/sysaudio/jack.zig index 22addc98..cac94fa3 100644 --- a/src/sysaudio/jack.zig +++ b/src/sysaudio/jack.zig @@ -34,7 +34,7 @@ const Lib = struct { pub fn load() !void { lib.handle = std.DynLib.open("libjack.so") catch return error.LibraryNotFound; - inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { + inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; diff --git a/src/sysaudio/main.zig b/src/sysaudio/main.zig index dc5c4298..8b2e6bd8 100644 --- a/src/sysaudio/main.zig +++ b/src/sysaudio/main.zig @@ -35,12 +35,12 @@ pub const Context = struct { if (backend) |b| { break :blk try @typeInfo( std.meta.fieldInfo(backends.Context, b).type, - ).Pointer.child.init(allocator, options); + ).pointer.child.init(allocator, options); } else { inline for (std.meta.fields(Backend), 0..) |b, i| { if (@typeInfo( std.meta.fieldInfo(backends.Context, @as(Backend, @enumFromInt(b.value))).type, - ).Pointer.child.init(allocator, options)) |d| { + ).pointer.child.init(allocator, options)) |d| { break :blk d; } else |err| { if (i == std.meta.fields(Backend).len - 1) diff --git a/src/sysaudio/pipewire.zig b/src/sysaudio/pipewire.zig index b3861727..323677be 100644 --- a/src/sysaudio/pipewire.zig +++ b/src/sysaudio/pipewire.zig @@ -34,7 +34,7 @@ const Lib = struct { pub fn load() !void { lib.handle = std.DynLib.open("libpipewire-0.3.so") catch return error.LibraryNotFound; - inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { + inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; diff --git a/src/sysaudio/pulseaudio.zig b/src/sysaudio/pulseaudio.zig index 9a14497c..3431f428 100644 --- a/src/sysaudio/pulseaudio.zig +++ b/src/sysaudio/pulseaudio.zig @@ -62,7 +62,7 @@ const Lib = struct { pub fn load() !void { lib.handle = std.DynLib.open("libpulse.so") catch return error.LibraryNotFound; - inline for (@typeInfo(Lib).Struct.fields[1..]) |field| { + inline for (@typeInfo(Lib).@"struct".fields[1..]) |field| { const name = std.fmt.comptimePrint("{s}\x00", .{field.name}); const name_z: [:0]const u8 = @ptrCast(name[0 .. name.len - 1]); @field(lib, field.name) = lib.handle.lookup(field.type, name_z) orelse return error.SymbolLookup; diff --git a/src/sysgpu/opengl/proc.zig b/src/sysgpu/opengl/proc.zig index 70577798..e4e70b46 100644 --- a/src/sysgpu/opengl/proc.zig +++ b/src/sysgpu/opengl/proc.zig @@ -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, }; } diff --git a/src/sysgpu/shader/codegen/spirv/Section.zig b/src/sysgpu/shader/codegen/spirv/Section.zig index 467a948b..13b9dae4 100644 --- a/src/sysgpu/shader/codegen/spirv/Section.zig +++ b/src/sysgpu/shader/codegen/spirv/Section.zig @@ -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)); diff --git a/src/sysgpu/shader/print_air.zig b/src/sysgpu/shader/print_air.zig index 8ce92c76..60b1e316 100644 --- a/src/sysgpu/shader/print_air.zig +++ b/src/sysgpu/shader/print_air.zig @@ -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 { diff --git a/src/sysgpu/sysgpu/bind_group.zig b/src/sysgpu/sysgpu/bind_group.zig index b2a0b452..0767104d 100644 --- a/src/sysgpu/sysgpu/bind_group.zig +++ b/src/sysgpu/sysgpu/bind_group.zig @@ -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, diff --git a/src/sysgpu/sysgpu/bind_group_layout.zig b/src/sysgpu/sysgpu/bind_group_layout.zig index cc295d85..652c4dd3 100644 --- a/src/sysgpu/sysgpu/bind_group_layout.zig +++ b/src/sysgpu/sysgpu/bind_group_layout.zig @@ -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,