From c9914d6d94bc33cd59e7c071649c6e89498caa07 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 25 Jul 2022 21:18:16 -0700 Subject: [PATCH] gpu: add Adapter.hasFeature Signed-off-by: Stephen Gutekanst --- gpu/TODO-webgpu.h | 4 ---- gpu/src/adapter.zig | 4 ++++ gpu/src/interface.zig | 14 +++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gpu/TODO-webgpu.h b/gpu/TODO-webgpu.h index cc0bc15b..ec5348fa 100644 --- a/gpu/TODO-webgpu.h +++ b/gpu/TODO-webgpu.h @@ -1,9 +1,5 @@ -// WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature); -export fn wgpuAdapterHasFeature(adapter: gpu.Adapter, feature: gpu.FeatureName) bool { - // NOTE: descriptor is nullable, see https://bugs.chromium.org/p/dawn/issues/detail?id=1502 // WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata); -export fn wgpuAdapterRequestDevice(adapter: gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) void { // WGPU_EXPORT void wgpuAdapterReference(WGPUAdapter adapter); export fn wgpuAdapterReference(adapter: gpu.Adapter) void { diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index 80d6f295..0280c045 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -24,6 +24,10 @@ pub const Adapter = *opaque { pub inline fn getProperties(adapter: Adapter, properties: *AdapterProperties) void { impl.adapterGetProperties(adapter, properties); } + + pub inline fn hasFeature(adapter: Adapter, feature: FeatureName) bool { + return impl.adapterHasFeature(adapter, feature); + } }; pub const RequestDeviceCallback = fn ( diff --git a/gpu/src/interface.zig b/gpu/src/interface.zig index 1e059a8a..8794776a 100644 --- a/gpu/src/interface.zig +++ b/gpu/src/interface.zig @@ -23,7 +23,7 @@ pub fn Interface(comptime Impl: type) type { assertDecl(Impl, "adapterEnumerateFeatures", fn (adapter: gpu.Adapter, features: ?[*]gpu.FeatureName) callconv(.Inline) usize); assertDecl(Impl, "adapterGetLimits", fn (adapter: gpu.Adapter, limits: *gpu.SupportedLimits) callconv(.Inline) bool); assertDecl(Impl, "adapterGetProperties", fn (adapter: gpu.Adapter, properties: *gpu.AdapterProperties) callconv(.Inline) void); - // assertDecl(Impl, "adapterHasFeature", fn (adapter: gpu.Adapter, feature: gpu.FeatureName) callconv(.Inline) bool); + assertDecl(Impl, "adapterHasFeature", fn (adapter: gpu.Adapter, feature: gpu.FeatureName) callconv(.Inline) bool); // assertDecl(Impl, "adapterRequestDevice", fn (adapter: gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) callconv(.Inline) void); // assertDecl(Impl, "adapterReference", fn (adapter: gpu.Adapter) callconv(.Inline) void); // assertDecl(Impl, "adapterRelease", fn (adapter: gpu.Adapter) callconv(.Inline) void); @@ -260,6 +260,11 @@ pub fn Export(comptime Impl: type) type { export fn wgpuAdapterGetProperties(adapter: gpu.Adapter, properties: *gpu.AdapterProperties) void { return Impl.adapterGetProperties(adapter, properties); } + + // WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature); + export fn wgpuAdapterHasFeature(adapter: gpu.Adapter, feature: gpu.FeatureName) bool { + return Impl.adapterHasFeature(adapter, feature); + } }; } @@ -293,10 +298,17 @@ pub const NullInterface = Interface(struct { _ = limits; return false; } + pub inline fn adapterGetProperties(adapter: gpu.Adapter, properties: *gpu.AdapterProperties) void { _ = adapter; _ = properties; } + + pub inline fn adapterHasFeature(adapter: gpu.Adapter, feature: gpu.FeatureName) bool { + _ = adapter; + _ = feature; + return false; + } }); test "null" {