From 60496259b2cbc09c377569307ca34d19cdbcab5a Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 24 Jul 2022 19:11:26 -0700 Subject: [PATCH] gpu: add Adapter.enumerateFeatures Signed-off-by: Stephen Gutekanst --- gpu/TODO-webgpu.h | 1 - gpu/src/adapter.zig | 6 ++++++ gpu/src/interface.zig | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gpu/TODO-webgpu.h b/gpu/TODO-webgpu.h index 0bc9c4c3..38e45a34 100644 --- a/gpu/TODO-webgpu.h +++ b/gpu/TODO-webgpu.h @@ -10,7 +10,6 @@ typedef void (*WGPURequestAdapterCallback)(WGPURequestAdapterStatus status, WGPU typedef void (*WGPURequestDeviceCallback)(WGPURequestDeviceStatus status, WGPUDevice device, char const * message, void * userdata); // Methods of Adapter -WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features); WGPU_EXPORT bool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits); WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties); WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature); diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index e13044f2..6e6a78dc 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -2,12 +2,18 @@ const testing = @import("std").testing; const ChainedStructOut = @import("types.zig").ChainedStructOut; const Device = @import("device.zig").Device; const DeviceDescriptor = @import("device.zig").DeviceDescriptor; +const FeatureName = @import("types.zig").FeatureName; const impl = @import("interface.zig").impl; pub const Adapter = *opaque { pub inline fn createDevice(adapter: Adapter, descriptor: ?*const DeviceDescriptor) ?Device { return impl.createDevice(adapter, descriptor); } + + /// Call once with null to determine the array length, and again to fetch the feature list. + pub inline fn enumerateFeatures(adapter: Adapter, features: ?[*]FeatureName) usize { + return impl.adapterEnumerateFeatures(adapter, features); + } }; pub const AdapterType = enum(u32) { diff --git a/gpu/src/interface.zig b/gpu/src/interface.zig index 6c3885fb..bea0c7c4 100644 --- a/gpu/src/interface.zig +++ b/gpu/src/interface.zig @@ -20,6 +20,7 @@ pub fn Interface(comptime Impl: type) type { assertDecl(Impl, "createInstance", fn (descriptor: *const InstanceDescriptor) callconv(.Inline) ?Instance); assertDecl(Impl, "getProcAddress", fn (device: gpu.Device, proc_name: [*:0]const u8) callconv(.Inline) ?gpu.Proc); assertDecl(Impl, "adapterCreateDevice", fn (adapter: gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) callconv(.Inline) ?gpu.Device); + assertDecl(Impl, "adapterEnumerateFeatures", fn (adapter: gpu.Adapter, features: ?[*]gpu.FeatureName) callconv(.Inline) usize); return Impl; } @@ -47,6 +48,11 @@ pub fn Export(comptime Impl: type) type { export fn wgpuAdapterCreateDevice(adapter: gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) ?gpu.Device { return Impl.adapterCreateDevice(adapter, descriptor); } + + // WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features); + export fn wgpuAdapterEnumerateFeatures(adapter: gpu.Adapter, features: ?[*]gpu.FeatureName) usize { + return Impl.adapterEnumerateFeatures(adapter, features); + } }; } @@ -68,6 +74,12 @@ pub const NullInterface = Interface(struct { _ = descriptor; return null; } + + pub inline fn adapterEnumerateFeatures(adapter: gpu.Adapter, features: ?[*]gpu.FeatureName) usize { + _ = adapter; + _ = features; + return 0; + } }); test "null" {