commit c81a9ca715aac3ccdc03f5562aa2c91ae31219eb
parent 506852b0122e929c01834aba8292c16e2f054bfb
Author: Christian Ermann <christianermann@gmail.com>
Date: Sun, 20 Apr 2025 19:41:13 -0700
Add Instance configuration
Diffstat:
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/src/instance.zig b/src/instance.zig
@@ -1,5 +1,6 @@
const c = @cImport({
@cInclude("webgpu.h");
+ @cInclude("wgpu.h");
});
const ChainedStruct = @import("common.zig").ChainedStruct;
@@ -7,7 +8,53 @@ const Surface = @import("surface.zig").Surface;
pub const Instance = opaque {
pub const Descriptor = extern struct {
- next_in_chain: ?*const ChainedStruct = null,
+ pub const Next = extern union {
+ generic: ?*const ChainedStruct,
+ extras: *const Extras,
+ };
+ next: Next = .{ .generic = null },
+ };
+
+ pub const Extras = extern struct {
+ next: ?*const ChainedStruct = null,
+ backends: Backends,
+ flags: Flags,
+ dx12_compiler: DX12Compiler,
+ gles3_minor_version: GLES3MinorVersion,
+ dxil_path: ?[*:0]const u8,
+ dxc_path: ?[*:0]const u8,
+
+ pub const Backends = enum(u32) {
+ all = 0x00000000,
+ vulkan = 0x00000001,
+ gl = 0x00000002,
+ metal = 0x00000004,
+ dx12 = 0x00000008,
+ dx11 = 0x00000010,
+ browser_webgpu = 0x00000020,
+ primary = 0x0000002D,
+ secondary = 0x00000012,
+ };
+
+ pub const Flags = enum(u32) {
+ default = 0x00000000,
+ debug = 0x00000001,
+ validation = 0x00000002,
+ discard_hal_labels = 0x00000004,
+ };
+
+ pub const DX12Compiler = enum(u32) {
+ undefined = 0x00000000,
+ fxc = 0x00000001,
+ dxc = 0x00000002,
+ };
+
+ pub const GLES3MinorVersion = enum(u32) {
+ automatic = 0x00000000,
+ version0 = 0x00000001,
+ version1 = 0x00000002,
+ version2 = 0x00000003,
+ };
};
pub fn create(descriptor: ?*const Descriptor) ?*Instance {
diff --git a/src/main.zig b/src/main.zig
@@ -13,7 +13,18 @@ pub fn main() !void {
const display = try glfw.native.getX11Display();
const window_id = try glfw.native.getX11Window(window);
- const instance = Instance.create(null) orelse {
+ const instance = Instance.create(&.{
+ .next = .{
+ .extras = &.{
+ .backends = .primary,
+ .flags = .default,
+ .dx12_compiler = .undefined,
+ .gles3_minor_version = .automatic,
+ .dxil_path = null,
+ .dxc_path = null,
+ },
+ },
+ }) orelse {
std.log.err("failed to create GPU instance", .{});
std.process.exit(1);
};