gpu: correct feature storage location

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-18 20:03:38 -07:00 committed by Stephen Gutekanst
parent 653c528441
commit 9f1775aa7c
3 changed files with 16 additions and 10 deletions

View file

@ -27,6 +27,7 @@ const Adapter = @This();
/// The features which can be used to create devices on this adapter.
features: []Feature,
_features: [std.enums.values(Feature).len]Feature = undefined,
/// The best limits which can be used to create devices on this adapter.
///

View file

@ -6,6 +6,8 @@
//!
//! https://gpuweb.github.io/gpuweb/#devices
//! https://gpuweb.github.io/gpuweb/#gpuadapter
const std = @import("std");
const Feature = @import("enums.zig").Feature;
const ErrorType = @import("enums.zig").ErrorType;
const ErrorFilter = @import("enums.zig").ErrorFilter;
@ -34,6 +36,7 @@ const Device = @This();
/// The features supported by the device (i.e. the ones with which it was created).
features: []Feature,
_features: [std.enums.values(Feature).len]Feature = undefined,
/// The limits supported by the device (which are exactly the ones with which it was created).
limits: Limits,

View file

@ -225,14 +225,11 @@ fn wrapAdapter(adapter: c.WGPUAdapter) Adapter {
.backend_type = @intToEnum(Adapter.BackendType, c_props.backendType),
};
var features: [std.enums.values(Feature).len]c.WGPUFeatureName = undefined;
const features_len = c.wgpuAdapterEnumerateFeatures(adapter.?, &features[0]);
var supported_limits: c.WGPUSupportedLimits = undefined;
if (!c.wgpuAdapterGetLimits(adapter.?, &supported_limits)) @panic("failed to get adapter limits (this is a bug in mach/gpu)");
return .{
.features = @bitCast([]Feature, features[0..features_len]),
var wrapped = Adapter{
.features = undefined,
.limits = @bitCast(Limits, supported_limits.limits),
.properties = properties,
@ -242,6 +239,10 @@ fn wrapAdapter(adapter: c.WGPUAdapter) Adapter {
.ptr = adapter.?,
.vtable = &adapter_vtable,
};
const features_len = c.wgpuAdapterEnumerateFeatures(adapter.?, @ptrCast(*c.WGPUFeatureName, &wrapped._features[0]));
wrapped.features = wrapped._features[0..features_len];
return wrapped;
}
const adapter_vtable = Adapter.VTable{
@ -303,18 +304,19 @@ const adapter_vtable = Adapter.VTable{
};
fn wrapDevice(device: c.WGPUDevice) Device {
var features: [std.enums.values(Feature).len]c.WGPUFeatureName = undefined;
const features_len = c.wgpuDeviceEnumerateFeatures(device.?, &features[0]);
var supported_limits: c.WGPUSupportedLimits = undefined;
if (!c.wgpuDeviceGetLimits(device.?, &supported_limits)) @panic("failed to get device limits (this is a bug in mach/gpu)");
return .{
.features = @bitCast([]Feature, features[0..features_len]),
var wrapped = Device{
.features = undefined,
.limits = @bitCast(Limits, supported_limits.limits),
.ptr = device.?,
.vtable = &device_vtable,
};
const features_len = c.wgpuDeviceEnumerateFeatures(device.?, @ptrCast(*c.WGPUFeatureName, &wrapped._features[0]));
wrapped.features = wrapped._features[0..features_len];
return wrapped;
}
const device_vtable = Device.VTable{