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 <stephen@hexops.com>
This commit is contained in:
parent
6a2358baf8
commit
7a1efdaa69
32 changed files with 85 additions and 132 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(.{}){};
|
||||
|
||||
|
|
|
|||
|
|
@ -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(.{}){};
|
||||
|
||||
|
|
|
|||
|
|
@ -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(.{});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(.{}){};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(.{});
|
||||
|
|
|
|||
|
|
@ -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(.{}){};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(.{}){};
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(.{});
|
||||
|
|
|
|||
|
|
@ -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")) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue