From 40f92dd9d9f2f54281a2fb21169e8bf0efde66a6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 11 Mar 2022 18:26:53 -0700 Subject: [PATCH] gpu: use PowerPreference Signed-off-by: Stephen Gutekanst --- gpu/examples/sample_utils.zig | 4 +++- gpu/src/BindGroupLayout.zig | 1 - gpu/src/Interface.zig | 4 ++-- gpu/src/NativeInstance.zig | 4 +--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gpu/examples/sample_utils.zig b/gpu/examples/sample_utils.zig index d0f565df..260832ef 100644 --- a/gpu/examples/sample_utils.zig +++ b/gpu/examples/sample_utils.zig @@ -74,7 +74,9 @@ pub fn setup(allocator: std.mem.Allocator) !Setup { try discoverAdapters(instance, window, backend_type); // Request an adapter. - const backend_adapter = switch (nosuspend gpu_interface.requestAdapter(&.{})) { + const backend_adapter = switch (nosuspend gpu_interface.requestAdapter(&.{ + .power_preference = .high_performance, + })) { .adapter => |v| v, .err => |err| { std.debug.print("failed to get adapter: error={} {s}\n", .{ err.code, err.message }); diff --git a/gpu/src/BindGroupLayout.zig b/gpu/src/BindGroupLayout.zig index 7f76b261..b84df521 100644 --- a/gpu/src/BindGroupLayout.zig +++ b/gpu/src/BindGroupLayout.zig @@ -34,7 +34,6 @@ pub const Descriptor = struct { entries: []const Entry, }; -// TODO: can this be extern struct / ABI compatible? pub const Entry = struct { binding: u32, visibility: ShaderStage, diff --git a/gpu/src/Interface.zig b/gpu/src/Interface.zig index 8bd161f9..d0db1d55 100644 --- a/gpu/src/Interface.zig +++ b/gpu/src/Interface.zig @@ -5,6 +5,7 @@ const std = @import("std"); const Surface = @import("Surface.zig"); const Adapter = @import("Adapter.zig"); +const PowerPreference = @import("enums.zig").PowerPreference; const Interface = @This(); @@ -30,8 +31,7 @@ pub inline fn release(interface: Interface) void { } pub const RequestAdapterOptions = struct { - // TODO: - //power_preference: PowerPreference, + power_preference: PowerPreference, force_fallback_adapter: bool = false, /// Only respected by native WebGPU implementations. diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 24631954..b9f61d8f 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -69,9 +69,7 @@ const interface_vtable = Interface.VTable{ const opt = c.WGPURequestAdapterOptions{ .nextInChain = null, .compatibleSurface = if (options.compatible_surface) |surface| @ptrCast(c.WGPUSurface, surface.ptr) else null, - // TODO: - //.powerPreference = power_preference, - .powerPreference = c.WGPUPowerPreference_Undefined, + .powerPreference = @enumToInt(options.power_preference), .forceFallbackAdapter = options.force_fallback_adapter, };