gpu: implement Adapter properties
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
c7c8764129
commit
f849e03443
3 changed files with 51 additions and 43 deletions
|
|
@ -40,6 +40,9 @@ limits: SupportedLimits,
|
||||||
/// Always false on native implementations of WebGPU (TODO: why is this not queryable in Dawn?)
|
/// Always false on native implementations of WebGPU (TODO: why is this not queryable in Dawn?)
|
||||||
fallback: bool,
|
fallback: bool,
|
||||||
|
|
||||||
|
// TODO: docs
|
||||||
|
properties: Properties,
|
||||||
|
|
||||||
// The type erased pointer to the Adapter implementation
|
// The type erased pointer to the Adapter implementation
|
||||||
ptr: *anyopaque,
|
ptr: *anyopaque,
|
||||||
vtable: *const VTable,
|
vtable: *const VTable,
|
||||||
|
|
@ -60,22 +63,40 @@ pub fn hasFeature(adapter: Adapter, feature: FeatureName) bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO: docs
|
||||||
// typedef struct WGPUAdapterProperties {
|
pub const Properties = struct {
|
||||||
// WGPUChainedStructOut * nextInChain;
|
vendor_id: u32,
|
||||||
// uint32_t vendorID;
|
device_id: u32,
|
||||||
// uint32_t deviceID;
|
name: []const u8,
|
||||||
// char const * name;
|
driver_description: []const u8,
|
||||||
// char const * driverDescription;
|
adapter_type: Type,
|
||||||
// WGPUAdapterType adapterType;
|
backend_type: BackendType,
|
||||||
// WGPUBackendType backendType;
|
};
|
||||||
// } WGPUAdapterProperties;
|
|
||||||
|
|
||||||
// TODO:
|
// TODO: docs
|
||||||
// typedef enum WGPUAdapterType {
|
pub const Type = enum(u32) {
|
||||||
// WGPUAdapterType_DiscreteGPU = 0x00000000,
|
discrete_gpu,
|
||||||
// WGPUAdapterType_IntegratedGPU = 0x00000001,
|
integrated_gpu,
|
||||||
// WGPUAdapterType_CPU = 0x00000002,
|
cpu,
|
||||||
// WGPUAdapterType_Unknown = 0x00000003,
|
unknown,
|
||||||
// WGPUAdapterType_Force32 = 0x7FFFFFFF
|
};
|
||||||
// } WGPUAdapterType;
|
|
||||||
|
// TODO: docs
|
||||||
|
pub const BackendType = enum(u32) {
|
||||||
|
nul,
|
||||||
|
webgpu,
|
||||||
|
d3d11,
|
||||||
|
d3d12,
|
||||||
|
metal,
|
||||||
|
vulkan,
|
||||||
|
opengl,
|
||||||
|
opengles,
|
||||||
|
};
|
||||||
|
|
||||||
|
test "syntax" {
|
||||||
|
_ = VTable;
|
||||||
|
_ = hasFeature;
|
||||||
|
_ = Properties;
|
||||||
|
_ = Type;
|
||||||
|
_ = BackendType;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,18 +84,6 @@ const interface_vtable = Interface.VTable{
|
||||||
}).requestAdapter,
|
}).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.
|
/// Returns the gpu.Interface for interacting with this native instance.
|
||||||
pub fn interface(native: *NativeInstance) Interface {
|
pub fn interface(native: *NativeInstance) Interface {
|
||||||
return .{
|
return .{
|
||||||
|
|
@ -191,17 +179,28 @@ const surface_vtable = Surface.VTable{
|
||||||
};
|
};
|
||||||
|
|
||||||
fn wrapAdapter(adapter: c.WGPUAdapter) Adapter {
|
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:
|
// TODO: implement Adapter interface:
|
||||||
// WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features);
|
// WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features);
|
||||||
// WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature);
|
// WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature);
|
||||||
// WGPU_EXPORT bool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits);
|
// WGPU_EXPORT bool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits);
|
||||||
// WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties);
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
// TODO:
|
// TODO:
|
||||||
.features = undefined,
|
.features = undefined,
|
||||||
// TODO:
|
// TODO:
|
||||||
.limits = undefined,
|
.limits = undefined,
|
||||||
|
.properties = properties,
|
||||||
|
|
||||||
// TODO: why is fallback not queryable on Dawn?
|
// TODO: why is fallback not queryable on Dawn?
|
||||||
.fallback = false,
|
.fallback = false,
|
||||||
|
|
|
||||||
12
gpu/src/TODO
12
gpu/src/TODO
|
|
@ -43,18 +43,6 @@ typedef enum WGPUAlphaMode {
|
||||||
WGPUAlphaMode_Force32 = 0x7FFFFFFF
|
WGPUAlphaMode_Force32 = 0x7FFFFFFF
|
||||||
} WGPUAlphaMode;
|
} 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 {
|
typedef enum WGPUBlendFactor {
|
||||||
WGPUBlendFactor_Zero = 0x00000000,
|
WGPUBlendFactor_Zero = 0x00000000,
|
||||||
WGPUBlendFactor_One = 0x00000001,
|
WGPUBlendFactor_One = 0x00000001,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue