webgpu: zig fmt
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e9bad16cda
commit
8a4cbc0e5d
3 changed files with 53 additions and 61 deletions
|
|
@ -23,7 +23,7 @@ pub fn build(b: *Builder) void {
|
||||||
dawn_example.setBuildMode(mode);
|
dawn_example.setBuildMode(mode);
|
||||||
dawn_example.setTarget(target);
|
dawn_example.setTarget(target);
|
||||||
dawn.link(b, dawn_example, .{});
|
dawn.link(b, dawn_example, .{});
|
||||||
glfw.link(b, dawn_example, .{.system_sdk = .{.set_sysroot = false}});
|
glfw.link(b, dawn_example, .{ .system_sdk = .{ .set_sysroot = false } });
|
||||||
dawn_example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
|
dawn_example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
|
||||||
dawn_example.addIncludeDir("libs/dawn/out/Debug/gen/src/include");
|
dawn_example.addIncludeDir("libs/dawn/out/Debug/gen/src/include");
|
||||||
dawn_example.addIncludeDir("libs/dawn/out/Debug/gen/src");
|
dawn_example.addIncludeDir("libs/dawn/out/Debug/gen/src");
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,11 @@ pub fn build(b: *Builder) void {
|
||||||
main_tests.setTarget(target);
|
main_tests.setTarget(target);
|
||||||
link(b, main_tests, .{});
|
link(b, main_tests, .{});
|
||||||
|
|
||||||
|
|
||||||
const example = b.addExecutable("hello_triangle", "examples/hello_triangle.zig");
|
const example = b.addExecutable("hello_triangle", "examples/hello_triangle.zig");
|
||||||
example.setBuildMode(mode);
|
example.setBuildMode(mode);
|
||||||
example.setTarget(target);
|
example.setTarget(target);
|
||||||
link(b, example, .{});
|
link(b, example, .{});
|
||||||
glfw.link(b, example, .{.system_sdk = .{.set_sysroot = false}});
|
glfw.link(b, example, .{ .system_sdk = .{ .set_sysroot = false } });
|
||||||
example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
|
example.addPackagePath("glfw", "libs/mach-glfw/src/main.zig");
|
||||||
example.addIncludeDir("out/Debug/gen/src/include");
|
example.addIncludeDir("out/Debug/gen/src/include");
|
||||||
example.addIncludeDir("out/Debug/gen/src");
|
example.addIncludeDir("out/Debug/gen/src");
|
||||||
|
|
@ -68,7 +67,7 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
|
||||||
});
|
});
|
||||||
|
|
||||||
lib.linkLibCpp(); // TODO: is it actually needed if we build with Zig?
|
lib.linkLibCpp(); // TODO: is it actually needed if we build with Zig?
|
||||||
glfw.link(b, lib, .{.system_sdk = .{.set_sysroot = false}});
|
glfw.link(b, lib, .{ .system_sdk = .{ .set_sysroot = false } });
|
||||||
addCommonSources(b, lib, options, target);
|
addCommonSources(b, lib, options, target);
|
||||||
addDawnPlatformSources(b, lib, options);
|
addDawnPlatformSources(b, lib, options);
|
||||||
addDawnNativeSources(b, lib, options, target);
|
addDawnNativeSources(b, lib, options, target);
|
||||||
|
|
@ -102,7 +101,6 @@ fn addCommonSources(b: *Builder, step: *std.build.LibExeObjStep, options: Option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adds dawn platform sources; derived from src/dawn_platform/BUILD.gn
|
// Adds dawn platform sources; derived from src/dawn_platform/BUILD.gn
|
||||||
fn addDawnPlatformSources(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
fn addDawnPlatformSources(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
||||||
_ = options;
|
_ = options;
|
||||||
|
|
@ -1271,8 +1269,7 @@ fn addDawnUtilsSources(b: *Builder, step: *std.build.LibExeObjStep, options: Opt
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
if (options.linux_window_manager == .X11) {
|
if (options.linux_window_manager == .X11) {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ const assert = std.debug.assert;
|
||||||
const glfw = @import("glfw");
|
const glfw = @import("glfw");
|
||||||
const c = @import("c.zig").c;
|
const c = @import("c.zig").c;
|
||||||
|
|
||||||
|
|
||||||
// #include "SampleUtils.h"
|
// #include "SampleUtils.h"
|
||||||
|
|
||||||
// #include "common/Assert.h"
|
// #include "common/Assert.h"
|
||||||
|
|
@ -27,11 +26,11 @@ const c = @import("c.zig").c;
|
||||||
fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, ptr: ?*c_void) callconv(.C) void {
|
fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, ptr: ?*c_void) callconv(.C) void {
|
||||||
_ = ptr;
|
_ = ptr;
|
||||||
switch (error_type) {
|
switch (error_type) {
|
||||||
c.WGPUErrorType_Validation => std.debug.print("dawn: validation error: {s}\n", .{message}),
|
c.WGPUErrorType_Validation => std.debug.print("dawn: validation error: {s}\n", .{message}),
|
||||||
c.WGPUErrorType_OutOfMemory => std.debug.print("dawn: out of memory: {s}\n", .{message}),
|
c.WGPUErrorType_OutOfMemory => std.debug.print("dawn: out of memory: {s}\n", .{message}),
|
||||||
c.WGPUErrorType_Unknown => std.debug.print("dawn: unknown error: {s}\n", .{message}),
|
c.WGPUErrorType_Unknown => std.debug.print("dawn: unknown error: {s}\n", .{message}),
|
||||||
c.WGPUErrorType_DeviceLost => std.debug.print("dawn: device lost: {s}\n", .{message}),
|
c.WGPUErrorType_DeviceLost => std.debug.print("dawn: device lost: {s}\n", .{message}),
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,11 +50,7 @@ fn printDeviceError(error_type: c.WGPUErrorType, message: [*c]const u8, ptr: ?*c
|
||||||
// # error
|
// # error
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
|
const CmdBufType = enum { none, terrible };
|
||||||
const CmdBufType = enum {
|
|
||||||
none,
|
|
||||||
terrible
|
|
||||||
};
|
|
||||||
|
|
||||||
// static std::unique_ptr<dawn_native::Instance> instance;
|
// static std::unique_ptr<dawn_native::Instance> instance;
|
||||||
// static utils::BackendBinding* binding = nullptr;
|
// static utils::BackendBinding* binding = nullptr;
|
||||||
|
|
@ -111,36 +106,36 @@ pub fn setup() !Setup {
|
||||||
var procs: ?*const c.DawnProcTable = null;
|
var procs: ?*const c.DawnProcTable = null;
|
||||||
var c_device: ?c.WGPUDevice = null;
|
var c_device: ?c.WGPUDevice = null;
|
||||||
switch (cmd_buf_type) {
|
switch (cmd_buf_type) {
|
||||||
CmdBufType.none => {
|
CmdBufType.none => {
|
||||||
procs = backend_procs;
|
procs = backend_procs;
|
||||||
c_device = backend_device;
|
c_device = backend_device;
|
||||||
},
|
},
|
||||||
CmdBufType.terrible => {
|
CmdBufType.terrible => {
|
||||||
// TODO(slimsag):
|
// TODO(slimsag):
|
||||||
@panic("not implemented");
|
@panic("not implemented");
|
||||||
// c2sBuf = new utils::TerribleCommandBuffer();
|
// c2sBuf = new utils::TerribleCommandBuffer();
|
||||||
// s2cBuf = new utils::TerribleCommandBuffer();
|
// s2cBuf = new utils::TerribleCommandBuffer();
|
||||||
|
|
||||||
// dawn_wire::WireServerDescriptor serverDesc = {};
|
// dawn_wire::WireServerDescriptor serverDesc = {};
|
||||||
// serverDesc.procs = &backendProcs;
|
// serverDesc.procs = &backendProcs;
|
||||||
// serverDesc.serializer = s2cBuf;
|
// serverDesc.serializer = s2cBuf;
|
||||||
|
|
||||||
// wireServer = new dawn_wire::WireServer(serverDesc);
|
// wireServer = new dawn_wire::WireServer(serverDesc);
|
||||||
// c2sBuf->SetHandler(wireServer);
|
// c2sBuf->SetHandler(wireServer);
|
||||||
|
|
||||||
// dawn_wire::WireClientDescriptor clientDesc = {};
|
// dawn_wire::WireClientDescriptor clientDesc = {};
|
||||||
// clientDesc.serializer = c2sBuf;
|
// clientDesc.serializer = c2sBuf;
|
||||||
|
|
||||||
// wireClient = new dawn_wire::WireClient(clientDesc);
|
// wireClient = new dawn_wire::WireClient(clientDesc);
|
||||||
// procs = dawn_wire::client::GetProcs();
|
// procs = dawn_wire::client::GetProcs();
|
||||||
// s2cBuf->SetHandler(wireClient);
|
// s2cBuf->SetHandler(wireClient);
|
||||||
|
|
||||||
// auto deviceReservation = wireClient->ReserveDevice();
|
// auto deviceReservation = wireClient->ReserveDevice();
|
||||||
// wireServer->InjectDevice(backendDevice, deviceReservation.id,
|
// wireServer->InjectDevice(backendDevice, deviceReservation.id,
|
||||||
// deviceReservation.generation);
|
// deviceReservation.generation);
|
||||||
|
|
||||||
// cDevice = deviceReservation.device;
|
// cDevice = deviceReservation.device;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c.dawnProcSetProcs(procs.?);
|
c.dawnProcSetProcs(procs.?);
|
||||||
|
|
@ -154,25 +149,25 @@ pub fn setup() !Setup {
|
||||||
|
|
||||||
fn setupGLFWWindowHintsForBackend(backend: c.WGPUBackendType) !void {
|
fn setupGLFWWindowHintsForBackend(backend: c.WGPUBackendType) !void {
|
||||||
switch (backend) {
|
switch (backend) {
|
||||||
c.WGPUBackendType_OpenGL => {
|
c.WGPUBackendType_OpenGL => {
|
||||||
// Ask for OpenGL 4.4 which is what the GL backend requires for compute shaders and
|
// Ask for OpenGL 4.4 which is what the GL backend requires for compute shaders and
|
||||||
// texture views.
|
// texture views.
|
||||||
try glfw.Window.hint(.context_version_major, 4);
|
try glfw.Window.hint(.context_version_major, 4);
|
||||||
try glfw.Window.hint(.context_version_minor, 4);
|
try glfw.Window.hint(.context_version_minor, 4);
|
||||||
try glfw.Window.hint(.opengl_forward_compat, 1); // true
|
try glfw.Window.hint(.opengl_forward_compat, 1); // true
|
||||||
try glfw.Window.hint(.opengl_profile, glfw.opengl_core_profile);
|
try glfw.Window.hint(.opengl_profile, glfw.opengl_core_profile);
|
||||||
},
|
},
|
||||||
c.WGPUBackendType_OpenGLES => {
|
c.WGPUBackendType_OpenGLES => {
|
||||||
try glfw.Window.hint(.context_version_major, 3);
|
try glfw.Window.hint(.context_version_major, 3);
|
||||||
try glfw.Window.hint(.context_version_minor, 1);
|
try glfw.Window.hint(.context_version_minor, 1);
|
||||||
try glfw.Window.hint(.client_api, glfw.opengl_es_api);
|
try glfw.Window.hint(.client_api, glfw.opengl_es_api);
|
||||||
try glfw.Window.hint(.context_creation_api, glfw.egl_context_api);
|
try glfw.Window.hint(.context_creation_api, glfw.egl_context_api);
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
// Without this GLFW will initialize a GL context on the window, which prevents using
|
// Without this GLFW will initialize a GL context on the window, which prevents using
|
||||||
// the window with other APIs (by crashing in weird ways).
|
// the window with other APIs (by crashing in weird ways).
|
||||||
try glfw.Window.hint(.client_api, glfw.no_api);
|
try glfw.Window.hint(.client_api, glfw.no_api);
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue