From b3696351934e4a0c0764ddea0becc94192e7eea6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Thu, 11 Aug 2022 12:52:28 -0700 Subject: [PATCH] gpu: add Device.enumerateFeaturesOwned helper Signed-off-by: Stephen Gutekanst --- gpu/README.md | 2 +- gpu/src/device.zig | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gpu/README.md b/gpu/README.md index 94a5a869..51d5e3c1 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -155,6 +155,7 @@ The slice helpers are: * `Buffer.getConstMappedRange` * `Buffer.getMappedRange` * `CommandEncoder.writeBuffer` +* `Device.enumerateFeaturesOwned` * `Queue.writeTexture` * `Queue.writeBuffer` * `RenderPassEncoder.executeBundles` @@ -220,7 +221,6 @@ There may be other opportunities for helpers, to improve the existing APIs, or a The following are definitive candidates for helpers we haven't implemented yet: * `gpu.ComputePassEncoder.setBindGroup` (slice param) -* `gpu.Device.enumerateFeatures` (owned slice) * `gpu.RenderBundleEncoder.setBindGroup` (slice param) * `gpu.RenderPassEncoder.setBindGroup` (slice param) * Other `next_in_chain` extensions (look at dawn.json after the bug to get this documented was fixed) diff --git a/gpu/src/device.zig b/gpu/src/device.zig index eeec0f2b..718a1489 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -181,10 +181,22 @@ pub const Device = opaque { Impl.deviceDestroy(device); } + /// Call once with null to determine the array length, and again to fetch the feature list. + /// + /// Consider using the enumerateFeaturesOwned helper. pub inline fn enumerateFeatures(device: *Device, features: [*]FeatureName) usize { return Impl.deviceEnumerateFeatures(device, features); } + /// Enumerates the adapter features, storing the result in an allocated slice which is owned by + /// the caller. + pub inline fn enumerateFeaturesOwned(device: *Device, allocator: std.mem.Allocator) ![]FeatureName { + const count = device.enumerateFeatures(null); + var data = try allocator.alloc(FeatureName, count); + _ = device.enumerateFeatures(data.ptr); + return data; + } + pub inline fn getLimits(device: *Device, limits: *SupportedLimits) bool { return Impl.deviceGetLimits(device, limits); }