From 7a1efdaa698d5004b663845031aa59ea8e08afa9 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 19 Apr 2024 20:48:33 -0700 Subject: [PATCH] core: cleanup sysgpu feature flag logic * `@import("mach").core.gpu` has been renamed to `@import("mach").gpu` * `pub const SYSGPUInterface` now has a default value (i.e. you do not need to write it in your main.zig, if you were.) * You can now check `if (comptime mach.use_sysgpu)` for any conditional code you might have that should only run with sysgpu. This (old): ``` pub const mach_core_options = core.ComptimeOptions{ .use_wgpu = false, .use_sysgpu = true, }; ``` Has been replaced by this: ``` pub const use_sysgpu = true; ``` Signed-off-by: Stephen Gutekanst --- src/Core.zig | 4 +-- src/core/examples/cubemap/main.zig | 1 + src/core/examples/sysgpu/boids/main.zig | 8 +++--- src/core/examples/sysgpu/clear-color/main.zig | 8 +++--- src/core/examples/sysgpu/cubemap/main.zig | 6 ++--- .../sysgpu/deferred-rendering/main.zig | 6 ++--- .../examples/sysgpu/fractal-cube/main.zig | 6 ++--- .../sysgpu/gen-texture-light/main.zig | 6 ++--- src/core/examples/sysgpu/image-blur/main.zig | 6 ++--- src/core/examples/sysgpu/image/main.zig | 6 ++--- .../examples/sysgpu/instanced-cube/main.zig | 6 ++--- src/core/examples/sysgpu/map-async/main.zig | 6 ++--- src/core/examples/sysgpu/pbr-basic/main.zig | 6 ++--- .../sysgpu/pixel-post-process/main.zig | 6 ++--- .../sysgpu/procedural-primitives/main.zig | 7 +++--- src/core/examples/sysgpu/rgb-quad/main.zig | 6 ++--- .../examples/sysgpu/rotating-cube/main.zig | 6 ++--- src/core/examples/sysgpu/sprite2d/main.zig | 6 ++--- .../examples/sysgpu/textured-cube/main.zig | 6 ++--- .../examples/sysgpu/textured-quad/main.zig | 6 ++--- .../examples/sysgpu/triangle-msaa/main.zig | 6 ++--- src/core/examples/sysgpu/triangle/main.zig | 6 ++--- src/core/examples/sysgpu/two-cubes/main.zig | 8 +++--- src/core/main.zig | 25 +------------------ src/core/platform/common.zig | 2 +- src/core/platform/glfw/Core.zig | 9 ++++--- src/core/platform/native_entrypoint.zig | 12 +++++---- src/core/platform/wasm/Core.zig | 3 ++- src/core/platform/wasm/entrypoint.zig | 6 +++-- src/core/platform/wayland/Core.zig | 3 ++- src/core/platform/x11/Core.zig | 9 ++++--- src/main.zig | 10 +++++++- 32 files changed, 85 insertions(+), 132 deletions(-) diff --git a/src/Core.zig b/src/Core.zig index c006e852..520ba979 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -34,8 +34,8 @@ should_exit: bool = false, fn init(core: *Mod) !void { // Initialize GPU implementation - if (comptime mach.core.options.use_wgpu) try mach.core.wgpu.Impl.init(mach.core.allocator, .{}); - if (comptime mach.core.options.use_sysgpu) try mach.core.sysgpu.Impl.init(mach.core.allocator, .{}); + if (comptime !mach.use_sysgpu) try mach.wgpu.Impl.init(mach.core.allocator, .{}); + if (comptime mach.use_sysgpu) try mach.sysgpu.Impl.init(mach.core.allocator, .{}); mach.core.allocator = gpa.allocator(); // TODO: banish this global allocator try mach.core.init(.{}); diff --git a/src/core/examples/cubemap/main.zig b/src/core/examples/cubemap/main.zig index ce970649..7444cbcd 100644 --- a/src/core/examples/cubemap/main.zig +++ b/src/core/examples/cubemap/main.zig @@ -2,6 +2,7 @@ const std = @import("std"); const mach = @import("mach"); const core = mach.core; +const gpu = mach.gpu; const zm = @import("zmath"); const zigimg = @import("zigimg"); diff --git a/src/core/examples/sysgpu/boids/main.zig b/src/core/examples/sysgpu/boids/main.zig index ef86aa12..e0e910bd 100644 --- a/src/core/examples/sysgpu/boids/main.zig +++ b/src/core/examples/sysgpu/boids/main.zig @@ -4,7 +4,7 @@ const std = @import("std"); const mach = @import("mach"); const core = mach.core; -const gpu = core.gpu; +const gpu = mach.gpu; title_timer: core.Timer, timer: core.Timer, @@ -18,10 +18,8 @@ frame_counter: usize, pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; diff --git a/src/core/examples/sysgpu/clear-color/main.zig b/src/core/examples/sysgpu/clear-color/main.zig index 7eb60d68..8f7b8a56 100644 --- a/src/core/examples/sysgpu/clear-color/main.zig +++ b/src/core/examples/sysgpu/clear-color/main.zig @@ -2,16 +2,14 @@ const std = @import("std"); const mach = @import("mach"); const core = mach.core; -const gpu = core.gpu; +const gpu = mach.gpu; const renderer = @import("renderer.zig"); pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; diff --git a/src/core/examples/sysgpu/cubemap/main.zig b/src/core/examples/sysgpu/cubemap/main.zig index ae82fda2..b7c6edc3 100644 --- a/src/core/examples/sysgpu/cubemap/main.zig +++ b/src/core/examples/sysgpu/cubemap/main.zig @@ -27,10 +27,8 @@ depth_texture_view: *gpu.TextureView, pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; pub fn init(app: *App) !void { try core.init(.{}); diff --git a/src/core/examples/sysgpu/deferred-rendering/main.zig b/src/core/examples/sysgpu/deferred-rendering/main.zig index d390a795..cf542b7d 100644 --- a/src/core/examples/sysgpu/deferred-rendering/main.zig +++ b/src/core/examples/sysgpu/deferred-rendering/main.zig @@ -11,10 +11,8 @@ const VertexWriter = @import("vertex_writer.zig").VertexWriter; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const Vec2 = [2]f32; const Vec3 = [3]f32; diff --git a/src/core/examples/sysgpu/fractal-cube/main.zig b/src/core/examples/sysgpu/fractal-cube/main.zig index 1b8bad23..f7fdb31b 100644 --- a/src/core/examples/sysgpu/fractal-cube/main.zig +++ b/src/core/examples/sysgpu/fractal-cube/main.zig @@ -20,10 +20,8 @@ const vertices = @import("cube_mesh.zig").vertices; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const UniformBufferObject = struct { mat: zm.Mat, diff --git a/src/core/examples/sysgpu/gen-texture-light/main.zig b/src/core/examples/sysgpu/gen-texture-light/main.zig index 67864ca4..2cf160fe 100644 --- a/src/core/examples/sysgpu/gen-texture-light/main.zig +++ b/src/core/examples/sysgpu/gen-texture-light/main.zig @@ -19,10 +19,8 @@ const Quat = zm.Quat; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; diff --git a/src/core/examples/sysgpu/image-blur/main.zig b/src/core/examples/sysgpu/image-blur/main.zig index 977a1c28..3a14d906 100644 --- a/src/core/examples/sysgpu/image-blur/main.zig +++ b/src/core/examples/sysgpu/image-blur/main.zig @@ -22,10 +22,8 @@ img_size: gpu.Extent3D, pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; // Constants from the blur.wgsl shader const tile_dimension: u32 = 128; diff --git a/src/core/examples/sysgpu/image/main.zig b/src/core/examples/sysgpu/image/main.zig index d31a4795..cdf2b734 100644 --- a/src/core/examples/sysgpu/image/main.zig +++ b/src/core/examples/sysgpu/image/main.zig @@ -7,10 +7,8 @@ const gpu = mach.gpu; const zigimg = @import("zigimg"); const assets = @import("assets"); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; title_timer: core.Timer, pipeline: *gpu.RenderPipeline, diff --git a/src/core/examples/sysgpu/instanced-cube/main.zig b/src/core/examples/sysgpu/instanced-cube/main.zig index db7a4642..05e72c4e 100644 --- a/src/core/examples/sysgpu/instanced-cube/main.zig +++ b/src/core/examples/sysgpu/instanced-cube/main.zig @@ -24,10 +24,8 @@ bind_group: *gpu.BindGroup, pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; pub fn init(app: *App) !void { try core.init(.{}); diff --git a/src/core/examples/sysgpu/map-async/main.zig b/src/core/examples/sysgpu/map-async/main.zig index 8bea8a00..a450d859 100644 --- a/src/core/examples/sysgpu/map-async/main.zig +++ b/src/core/examples/sysgpu/map-async/main.zig @@ -6,10 +6,8 @@ const gpu = mach.gpu; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; diff --git a/src/core/examples/sysgpu/pbr-basic/main.zig b/src/core/examples/sysgpu/pbr-basic/main.zig index a4c26a7d..ac1cd266 100644 --- a/src/core/examples/sysgpu/pbr-basic/main.zig +++ b/src/core/examples/sysgpu/pbr-basic/main.zig @@ -11,10 +11,8 @@ const VertexWriter = @import("vertex_writer.zig").VertexWriter; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const Vec4 = [4]f32; const Vec3 = [3]f32; diff --git a/src/core/examples/sysgpu/pixel-post-process/main.zig b/src/core/examples/sysgpu/pixel-post-process/main.zig index c819dfad..ccead043 100644 --- a/src/core/examples/sysgpu/pixel-post-process/main.zig +++ b/src/core/examples/sysgpu/pixel-post-process/main.zig @@ -13,10 +13,8 @@ const quad = @import("quad_mesh.zig").quad; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const pixel_size = 8; diff --git a/src/core/examples/sysgpu/procedural-primitives/main.zig b/src/core/examples/sysgpu/procedural-primitives/main.zig index 2dbdf022..8f20785d 100644 --- a/src/core/examples/sysgpu/procedural-primitives/main.zig +++ b/src/core/examples/sysgpu/procedural-primitives/main.zig @@ -8,10 +8,9 @@ const renderer = @import("renderer.zig"); pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; title_timer: core.Timer, diff --git a/src/core/examples/sysgpu/rgb-quad/main.zig b/src/core/examples/sysgpu/rgb-quad/main.zig index c46aadcd..2f8ed683 100644 --- a/src/core/examples/sysgpu/rgb-quad/main.zig +++ b/src/core/examples/sysgpu/rgb-quad/main.zig @@ -16,10 +16,8 @@ const vertices = [_]Vertex{ }; const index_data = [_]u32{ 0, 1, 2, 2, 3, 0 }; -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; pub const App = @This(); diff --git a/src/core/examples/sysgpu/rotating-cube/main.zig b/src/core/examples/sysgpu/rotating-cube/main.zig index 41fa61e5..0555c8ff 100644 --- a/src/core/examples/sysgpu/rotating-cube/main.zig +++ b/src/core/examples/sysgpu/rotating-cube/main.zig @@ -10,10 +10,8 @@ const vertices = @import("cube_mesh.zig").vertices; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const UniformBufferObject = struct { diff --git a/src/core/examples/sysgpu/sprite2d/main.zig b/src/core/examples/sysgpu/sprite2d/main.zig index 03dd2cc4..5a89b0b9 100644 --- a/src/core/examples/sysgpu/sprite2d/main.zig +++ b/src/core/examples/sysgpu/sprite2d/main.zig @@ -11,10 +11,8 @@ const json = std.json; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const speed = 2.0 * 100.0; // pixels per second diff --git a/src/core/examples/sysgpu/textured-cube/main.zig b/src/core/examples/sysgpu/textured-cube/main.zig index 77f5831b..34785439 100644 --- a/src/core/examples/sysgpu/textured-cube/main.zig +++ b/src/core/examples/sysgpu/textured-cube/main.zig @@ -12,10 +12,8 @@ const assets = @import("assets"); pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; const UniformBufferObject = struct { mat: zm.Mat, diff --git a/src/core/examples/sysgpu/textured-quad/main.zig b/src/core/examples/sysgpu/textured-quad/main.zig index ed0e8efe..7b26d6ad 100644 --- a/src/core/examples/sysgpu/textured-quad/main.zig +++ b/src/core/examples/sysgpu/textured-quad/main.zig @@ -22,10 +22,8 @@ const vertices = [_]Vertex{ }; const index_data = [_]u32{ 0, 1, 2, 2, 3, 0 }; -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; diff --git a/src/core/examples/sysgpu/triangle-msaa/main.zig b/src/core/examples/sysgpu/triangle-msaa/main.zig index aceaf3be..60d7d844 100644 --- a/src/core/examples/sysgpu/triangle-msaa/main.zig +++ b/src/core/examples/sysgpu/triangle-msaa/main.zig @@ -6,10 +6,8 @@ const gpu = mach.gpu; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; title_timer: core.Timer, pipeline: *gpu.RenderPipeline, diff --git a/src/core/examples/sysgpu/triangle/main.zig b/src/core/examples/sysgpu/triangle/main.zig index 92d74f55..a52e4d53 100644 --- a/src/core/examples/sysgpu/triangle/main.zig +++ b/src/core/examples/sysgpu/triangle/main.zig @@ -6,10 +6,8 @@ const gpu = mach.gpu; pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; title_timer: core.Timer, pipeline: *gpu.RenderPipeline, diff --git a/src/core/examples/sysgpu/two-cubes/main.zig b/src/core/examples/sysgpu/two-cubes/main.zig index 476f6956..9acdea56 100644 --- a/src/core/examples/sysgpu/two-cubes/main.zig +++ b/src/core/examples/sysgpu/two-cubes/main.zig @@ -2,7 +2,7 @@ const std = @import("std"); const mach = @import("mach"); const core = mach.core; -const gpu = core.gpu; +const gpu = mach.gpu; const zm = @import("zmath"); const Vertex = @import("cube_mesh.zig").Vertex; @@ -24,10 +24,8 @@ bind_group2: *gpu.BindGroup, pub const App = @This(); -pub const mach_core_options = core.ComptimeOptions{ - .use_wgpu = false, - .use_sysgpu = true, -}; +// Use experimental sysgpu graphics API +pub const use_sysgpu = true; pub fn init(app: *App) !void { try core.init(.{}); diff --git a/src/core/main.zig b/src/core/main.zig index efded542..28f9e171 100644 --- a/src/core/main.zig +++ b/src/core/main.zig @@ -44,30 +44,7 @@ fn ErrorSet(comptime F: type) type { return @typeInfo(@typeInfo(F).Fn.return_type.?).ErrorUnion.error_set; } -/// Comptime options that you can configure in your main file by writing e.g.: -/// -/// ``` -/// pub const mach_core_options = core.ComptimeOptions{ -/// .use_wgpu = true, -/// .use_sysgpu = true, -/// }; -/// ``` -pub const ComptimeOptions = struct { - /// Whether to use - use_wgpu: bool = true, - - /// Whether or not to use the experimental sysgpu graphics API. - use_sysgpu: bool = false, -}; - -pub const options = if (@hasDecl(@import("root"), "mach_core_options")) - @import("root").mach_core_options -else - ComptimeOptions{}; - -pub const wgpu = @import("../gpu/main.zig"); - -pub const gpu = if (options.use_sysgpu) sysgpu.sysgpu else wgpu; +const gpu = if (mach.use_sysgpu) sysgpu.sysgpu else @import("../gpu/main.zig"); pub fn AppInterface(comptime app_entry: anytype) void { if (!@hasDecl(app_entry, "App")) { diff --git a/src/core/platform/common.zig b/src/core/platform/common.zig index 2cc77d91..83395a85 100644 --- a/src/core/platform/common.zig +++ b/src/core/platform/common.zig @@ -3,7 +3,7 @@ const builtin = @import("builtin"); const mach = @import("../../main.zig"); const gamemode = mach.gamemode; const mach_core = mach.core; -const gpu = mach_core.gpu; +const gpu = mach.gpu; pub inline fn printUnhandledErrorCallback(_: void, ty: gpu.ErrorType, message: [*:0]const u8) void { switch (ty) { diff --git a/src/core/platform/glfw/Core.zig b/src/core/platform/glfw/Core.zig index 3ac53a53..83d0b7ed 100644 --- a/src/core/platform/glfw/Core.zig +++ b/src/core/platform/glfw/Core.zig @@ -1,8 +1,9 @@ const builtin = @import("builtin"); const std = @import("std"); const glfw = @import("mach-glfw"); +const mach = @import("../../../main.zig"); const mach_core = @import("../../main.zig"); -const gpu = mach_core.gpu; +const gpu = mach.gpu; const objc = @import("objc.zig"); const Options = @import("../../main.zig").Options; const Event = @import("../../main.zig").Event; @@ -136,11 +137,11 @@ pub fn init( input: *Frequency, options: Options, ) !void { - if (!@import("builtin").is_test and mach_core.options.use_wgpu) _ = mach_core.wgpu.Export(blk: { + if (!@import("builtin").is_test and !mach.use_sysgpu) _ = mach.wgpu.Export(blk: { if (@hasDecl(@import("root"), "GPUInterface")) break :blk @import("root").GPUInterface; - break :blk mach_core.wgpu.dawn.Interface; + break :blk mach.wgpu.dawn.Interface; }); - if (!@import("builtin").is_test and mach_core.options.use_sysgpu) _ = mach_core.sysgpu.sysgpu.Export(@import("root").SYSGPUInterface); + if (!@import("builtin").is_test and mach.use_sysgpu) _ = mach.sysgpu.sysgpu.Export(@import("root").SYSGPUInterface); const backend_type = try detectBackendType(allocator); diff --git a/src/core/platform/native_entrypoint.zig b/src/core/platform/native_entrypoint.zig index da55567c..409d9999 100644 --- a/src/core/platform/native_entrypoint.zig +++ b/src/core/platform/native_entrypoint.zig @@ -8,14 +8,16 @@ pub usingnamespace @import("app"); const App = @import("app").App; const std = @import("std"); -const core = @import("mach").core; + +const mach = @import("mach"); +const core = mach.core; pub usingnamespace if (!@hasDecl(App, "GPUInterface")) struct { - pub const GPUInterface = core.wgpu.dawn.Interface; + pub const GPUInterface = mach.wgpu.dawn.Interface; } else struct {}; pub usingnamespace if (!@hasDecl(App, "SYSGPUInterface")) extern struct { - pub const SYSGPUInterface = core.sysgpu.Impl; + pub const SYSGPUInterface = mach.sysgpu.Impl; } else struct {}; pub fn main() !void { @@ -29,8 +31,8 @@ pub fn main() !void { core.allocator = gpa.allocator(); // Initialize GPU implementation - if (comptime core.options.use_wgpu) try core.wgpu.Impl.init(core.allocator, .{}); - if (comptime core.options.use_sysgpu) try core.sysgpu.Impl.init(core.allocator, .{}); + if (comptime !mach.use_sysgpu) try mach.wgpu.Impl.init(core.allocator, .{}); + if (comptime mach.use_sysgpu) try mach.sysgpu.Impl.init(core.allocator, .{}); var app: App = undefined; try app.init(); diff --git a/src/core/platform/wasm/Core.zig b/src/core/platform/wasm/Core.zig index 1060802d..c49546fa 100644 --- a/src/core/platform/wasm/Core.zig +++ b/src/core/platform/wasm/Core.zig @@ -1,8 +1,9 @@ const std = @import("std"); const js = @import("js.zig"); const Timer = @import("Timer.zig"); +const mach = @import("../../../main.zig"); const mach_core = @import("../../main.zig"); -const gpu = mach_core.gpu; +const gpu = mach.gpu; const Options = @import("../../main.zig").Options; const Event = @import("../../main.zig").Event; const KeyEvent = @import("../../main.zig").KeyEvent; diff --git a/src/core/platform/wasm/entrypoint.zig b/src/core/platform/wasm/entrypoint.zig index 57a4ff9a..8caae772 100644 --- a/src/core/platform/wasm/entrypoint.zig +++ b/src/core/platform/wasm/entrypoint.zig @@ -8,8 +8,10 @@ pub usingnamespace @import("app"); const App = @import("app").App; const std = @import("std"); -const core = @import("mach").core; -const gpu = core.gpu; + +const mach = @import("mach"); +const core = mach.core; +const gpu = mach.gpu; pub const GPUInterface = gpu.StubInterface; diff --git a/src/core/platform/wayland/Core.zig b/src/core/platform/wayland/Core.zig index 0cf16f41..a8d44027 100644 --- a/src/core/platform/wayland/Core.zig +++ b/src/core/platform/wayland/Core.zig @@ -1,6 +1,7 @@ const std = @import("std"); +const mach = @import("../../../main.zig"); const mach_core = @import("../../main.zig"); -const gpu = mach_core.gpu; +const gpu = mach.gpu; const Options = @import("../../main.zig").Options; const Event = @import("../../main.zig").Event; const KeyEvent = @import("../../main.zig").KeyEvent; diff --git a/src/core/platform/x11/Core.zig b/src/core/platform/x11/Core.zig index cada992b..b42a0ca5 100644 --- a/src/core/platform/x11/Core.zig +++ b/src/core/platform/x11/Core.zig @@ -1,8 +1,9 @@ const builtin = @import("builtin"); const std = @import("std"); const glfw = @import("mach-glfw"); +const mach = @import("../../../main.zig"); const mach_core = @import("../../main.zig"); -const gpu = mach_core.gpu; +const gpu = mach.gpu; const unicode = @import("unicode.zig"); const Options = @import("../../main.zig").Options; const Event = @import("../../main.zig").Event; @@ -299,11 +300,11 @@ pub fn init( input: *Frequency, options: Options, ) !void { - if (!@import("builtin").is_test and mach_core.options.use_wgpu) _ = mach_core.wgpu.Export(blk: { + if (!@import("builtin").is_test and !mach.use_sysgpu) _ = mach.wgpu.Export(blk: { if (@hasDecl(@import("root"), "GPUInterface")) break :blk @import("root").GPUInterface; - break :blk mach_core.wgpu.dawn.Interface; + break :blk mach.wgpu.dawn.Interface; }); - if (!@import("builtin").is_test and mach_core.options.use_sysgpu) _ = mach_core.sysgpu.sysgpu.Export(@import("root").SYSGPUInterface); + if (!@import("builtin").is_test and mach.use_sysgpu) _ = mach.sysgpu.sysgpu.Export(@import("root").SYSGPUInterface); const libx11 = try LibX11.load(); const libxcursor: ?LibXCursor = LibXCursor.load() catch |err| switch (err) { diff --git a/src/main.zig b/src/main.zig index fef3b4c7..a9869c79 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,7 +4,7 @@ const builtin = @import("builtin"); // Core pub const core = if (build_options.want_core) @import("core/main.zig") else struct {}; pub const Timer = if (build_options.want_core) core.Timer else struct {}; -pub const gpu = if (build_options.want_core) core.gpu else struct {}; +pub const wgpu = if (build_options.want_core) @import("gpu/main.zig") else struct {}; pub const sysjs = if (build_options.want_core) @import("mach-sysjs") else struct {}; pub const Core = if (build_options.want_core) @import("Core.zig") else struct {}; @@ -32,6 +32,14 @@ pub const Mod = ModSet(modules).Mod; pub const EntityID = @import("module/main.zig").EntityID; // TODO: rename to just Entity? pub const Archetype = @import("module/main.zig").Archetype; +/// To use experimental sysgpu graphics API, you can write this in your main.zig: +/// +/// ``` +/// pub const use_sysgpu = true; +/// ``` +pub const use_sysgpu = if (@hasDecl(@import("root"), "use_sysgpu")) @import("root").use_sysgpu else false; +pub const gpu = if (use_sysgpu) sysgpu.sysgpu else wgpu; + test { const std = @import("std"); // TODO: refactor code so we can use this here: