gpu: implement Adapter properties

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-07 11:28:25 -07:00 committed by Stephen Gutekanst
parent c7c8764129
commit f849e03443
3 changed files with 51 additions and 43 deletions

View file

@ -40,6 +40,9 @@ limits: SupportedLimits,
/// Always false on native implementations of WebGPU (TODO: why is this not queryable in Dawn?)
fallback: bool,
// TODO: docs
properties: Properties,
// The type erased pointer to the Adapter implementation
ptr: *anyopaque,
vtable: *const VTable,
@ -60,22 +63,40 @@ pub fn hasFeature(adapter: Adapter, feature: FeatureName) bool {
return false;
}
// TODO:
// typedef struct WGPUAdapterProperties {
// WGPUChainedStructOut * nextInChain;
// uint32_t vendorID;
// uint32_t deviceID;
// char const * name;
// char const * driverDescription;
// WGPUAdapterType adapterType;
// WGPUBackendType backendType;
// } WGPUAdapterProperties;
// TODO: docs
pub const Properties = struct {
vendor_id: u32,
device_id: u32,
name: []const u8,
driver_description: []const u8,
adapter_type: Type,
backend_type: BackendType,
};
// TODO:
// typedef enum WGPUAdapterType {
// WGPUAdapterType_DiscreteGPU = 0x00000000,
// WGPUAdapterType_IntegratedGPU = 0x00000001,
// WGPUAdapterType_CPU = 0x00000002,
// WGPUAdapterType_Unknown = 0x00000003,
// WGPUAdapterType_Force32 = 0x7FFFFFFF
// } WGPUAdapterType;
// TODO: docs
pub const Type = enum(u32) {
discrete_gpu,
integrated_gpu,
cpu,
unknown,
};
// TODO: docs
pub const BackendType = enum(u32) {
nul,
webgpu,
d3d11,
d3d12,
metal,
vulkan,
opengl,
opengles,
};
test "syntax" {
_ = VTable;
_ = hasFeature;
_ = Properties;
_ = Type;
_ = BackendType;
}

View file

@ -84,18 +84,6 @@ const interface_vtable = Interface.VTable{
}).requestAdapter,
};
// TODO:
// typedef void (*WGPURequestAdapterCallback)(WGPURequestAdapterStatus status, WGPUAdapter adapter, char const * message, void * userdata);
// WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata);
// typedef enum WGPURequestAdapterStatus {
// WGPURequestAdapterStatus_Success = 0x00000000,
// WGPURequestAdapterStatus_Unavailable = 0x00000001,
// WGPURequestAdapterStatus_Error = 0x00000002,
// WGPURequestAdapterStatus_Unknown = 0x00000003,
// WGPURequestAdapterStatus_Force32 = 0x7FFFFFFF
// } WGPURequestAdapterStatus;
/// Returns the gpu.Interface for interacting with this native instance.
pub fn interface(native: *NativeInstance) Interface {
return .{
@ -191,17 +179,28 @@ const surface_vtable = Surface.VTable{
};
fn wrapAdapter(adapter: c.WGPUAdapter) Adapter {
var c_props: c.WGPUAdapterProperties = undefined;
c.wgpuAdapterGetProperties(adapter, &c_props);
const properties = Adapter.Properties{
.vendor_id = c_props.vendorID,
.device_id = c_props.deviceID,
.name = std.mem.span(c_props.name),
.driver_description = std.mem.span(c_props.driverDescription),
.adapter_type = @intToEnum(Adapter.Type, c_props.adapterType),
.backend_type = @intToEnum(Adapter.BackendType, c_props.backendType),
};
// TODO: implement Adapter interface:
// WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features);
// WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature);
// WGPU_EXPORT bool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits);
// WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties);
return .{
// TODO:
.features = undefined,
// TODO:
.limits = undefined,
.properties = properties,
// TODO: why is fallback not queryable on Dawn?
.fallback = false,

View file

@ -43,18 +43,6 @@ typedef enum WGPUAlphaMode {
WGPUAlphaMode_Force32 = 0x7FFFFFFF
} WGPUAlphaMode;
typedef enum WGPUBackendType {
WGPUBackendType_Null = 0x00000000,
WGPUBackendType_WebGPU = 0x00000001,
WGPUBackendType_D3D11 = 0x00000002,
WGPUBackendType_D3D12 = 0x00000003,
WGPUBackendType_Metal = 0x00000004,
WGPUBackendType_Vulkan = 0x00000005,
WGPUBackendType_OpenGL = 0x00000006,
WGPUBackendType_OpenGLES = 0x00000007,
WGPUBackendType_Force32 = 0x7FFFFFFF
} WGPUBackendType;
typedef enum WGPUBlendFactor {
WGPUBlendFactor_Zero = 0x00000000,
WGPUBlendFactor_One = 0x00000001,