gpu: internalize Device types
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
b5bf0da50d
commit
0a69ef98fa
3 changed files with 32 additions and 33 deletions
|
|
@ -1,7 +1,6 @@
|
|||
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 SupportedLimits = @import("types.zig").SupportedLimits;
|
||||
const RequestDeviceStatus = @import("types.zig").RequestDeviceStatus;
|
||||
|
|
@ -37,7 +36,7 @@ pub const Adapter = opaque {
|
|||
backend_type: Type,
|
||||
};
|
||||
|
||||
pub inline fn createDevice(adapter: *Adapter, descriptor: ?*const DeviceDescriptor) ?*Device {
|
||||
pub inline fn createDevice(adapter: *Adapter, descriptor: ?*const Device.Descriptor) ?*Device {
|
||||
return Impl.adapterCreateDevice(adapter, descriptor);
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +57,7 @@ pub const Adapter = opaque {
|
|||
return Impl.adapterHasFeature(adapter, feature);
|
||||
}
|
||||
|
||||
pub inline fn requestDevice(adapter: *Adapter, descriptor: ?*const DeviceDescriptor, callback: RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
pub inline fn requestDevice(adapter: *Adapter, descriptor: ?*const Device.Descriptor, callback: RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
Impl.adapterRequestDevice(adapter, descriptor, callback, userdata);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,26 @@ const CreateRenderPipelineAsyncCallback = @import("callbacks.zig").CreateRenderP
|
|||
const Impl = @import("interface.zig").Impl;
|
||||
|
||||
pub const Device = opaque {
|
||||
pub const LostCallback = fn (
|
||||
reason: LostReason,
|
||||
message: [*:0]const u8,
|
||||
userdata: *anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const LostReason = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
destroyed = 0x00000001,
|
||||
};
|
||||
|
||||
pub const Descriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
required_features_count: u32 = 0,
|
||||
required_features: ?[*]const FeatureName = null,
|
||||
required_limits: ?*const RequiredLimits,
|
||||
default_queue: QueueDescriptor,
|
||||
};
|
||||
|
||||
pub inline fn createBindGroup(device: *Device, descriptor: *const BindGroup.Descriptor) *BindGroup {
|
||||
return Impl.deviceCreateBindGroup(device, descriptor);
|
||||
}
|
||||
|
|
@ -145,7 +165,7 @@ pub const Device = opaque {
|
|||
Impl.devicePushErrorScope(device, filter);
|
||||
}
|
||||
|
||||
pub inline fn setDeviceLostCallback(device: *Device, callback: DeviceLostCallback, userdata: *anyopaque) void {
|
||||
pub inline fn setDeviceLostCallback(device: *Device, callback: Device.LostCallback, userdata: *anyopaque) void {
|
||||
Impl.deviceSetDeviceLostCallback(device, callback, userdata);
|
||||
}
|
||||
|
||||
|
|
@ -173,23 +193,3 @@ pub const Device = opaque {
|
|||
Impl.deviceRelease(device);
|
||||
}
|
||||
};
|
||||
|
||||
pub const DeviceLostCallback = fn (
|
||||
reason: DeviceLostReason,
|
||||
message: [*:0]const u8,
|
||||
userdata: *anyopaque,
|
||||
) callconv(.C) void;
|
||||
|
||||
pub const DeviceLostReason = enum(u32) {
|
||||
undef = 0x00000000,
|
||||
destroyed = 0x00000001,
|
||||
};
|
||||
|
||||
pub const DeviceDescriptor = extern struct {
|
||||
next_in_chain: ?*const ChainedStruct = null,
|
||||
label: ?[*:0]const u8 = null,
|
||||
required_features_count: u32 = 0,
|
||||
required_features: ?[*]const FeatureName = null,
|
||||
required_limits: ?*const RequiredLimits,
|
||||
default_queue: QueueDescriptor,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ pub const Impl = blk: {
|
|||
pub fn Interface(comptime T: type) type {
|
||||
assertDecl(T, "createInstance", fn (descriptor: ?*const gpu.Instance.Descriptor) callconv(.Inline) ?*gpu.Instance);
|
||||
assertDecl(T, "getProcAddress", fn (device: *gpu.Device, proc_name: [*:0]const u8) callconv(.Inline) ?gpu.Proc);
|
||||
assertDecl(T, "adapterCreateDevice", fn (adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) callconv(.Inline) ?*gpu.Device);
|
||||
assertDecl(T, "adapterCreateDevice", fn (adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor) callconv(.Inline) ?*gpu.Device);
|
||||
assertDecl(T, "adapterEnumerateFeatures", fn (adapter: *gpu.Adapter, features: ?[*]gpu.FeatureName) callconv(.Inline) usize);
|
||||
assertDecl(T, "adapterGetLimits", fn (adapter: *gpu.Adapter, limits: *gpu.SupportedLimits) callconv(.Inline) bool);
|
||||
assertDecl(T, "adapterGetProperties", fn (adapter: *gpu.Adapter, properties: *gpu.Adapter.Properties) callconv(.Inline) void);
|
||||
assertDecl(T, "adapterHasFeature", fn (adapter: *gpu.Adapter, feature: gpu.FeatureName) callconv(.Inline) bool);
|
||||
assertDecl(T, "adapterRequestDevice", fn (adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
assertDecl(T, "adapterRequestDevice", fn (adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
assertDecl(T, "adapterReference", fn (adapter: *gpu.Adapter) callconv(.Inline) void);
|
||||
assertDecl(T, "adapterRelease", fn (adapter: *gpu.Adapter) callconv(.Inline) void);
|
||||
assertDecl(T, "bindGroupSetLabel", fn (bind_group: *gpu.BindGroup, label: [*:0]const u8) callconv(.Inline) void);
|
||||
|
|
@ -106,7 +106,7 @@ pub fn Interface(comptime T: type) type {
|
|||
assertDecl(T, "deviceLoseForTesting", fn (device: *gpu.Device) callconv(.Inline) void);
|
||||
assertDecl(T, "devicePopErrorScope", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: *anyopaque) callconv(.Inline) bool);
|
||||
assertDecl(T, "devicePushErrorScope", fn (device: *gpu.Device, filter: gpu.ErrorFilter) callconv(.Inline) void);
|
||||
assertDecl(T, "deviceSetDeviceLostCallback", fn (device: *gpu.Device, callback: gpu.DeviceLostCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
assertDecl(T, "deviceSetDeviceLostCallback", fn (device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
assertDecl(T, "deviceSetLabel", fn (device: *gpu.Device, label: [*:0]const u8) callconv(.Inline) void);
|
||||
assertDecl(T, "deviceSetLoggingCallback", fn (device: *gpu.Device, callback: gpu.LoggingCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
assertDecl(T, "deviceSetUncapturedErrorCallback", fn (device: *gpu.Device, callback: gpu.ErrorCallback, userdata: *anyopaque) callconv(.Inline) void);
|
||||
|
|
@ -236,7 +236,7 @@ pub fn Export(comptime T: type) type {
|
|||
}
|
||||
|
||||
// WGPU_EXPORT WGPUDevice wgpuAdapterCreateDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor /* nullable */);
|
||||
export fn wgpuAdapterCreateDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) ?*gpu.Device {
|
||||
export fn wgpuAdapterCreateDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor) ?*gpu.Device {
|
||||
return T.adapterCreateDevice(adapter, descriptor);
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ pub fn Export(comptime T: type) type {
|
|||
|
||||
// NOTE: descriptor is nullable, see https://bugs.chromium.org/p/dawn/issues/detail?id=1502
|
||||
// WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata);
|
||||
export fn wgpuAdapterRequestDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
export fn wgpuAdapterRequestDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
T.adapterRequestDevice(adapter, descriptor, callback, userdata);
|
||||
}
|
||||
|
||||
|
|
@ -684,7 +684,7 @@ pub fn Export(comptime T: type) type {
|
|||
}
|
||||
|
||||
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
||||
export fn wgpuDeviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.DeviceLostCallback, userdata: *anyopaque) void {
|
||||
export fn wgpuDeviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: *anyopaque) void {
|
||||
T.deviceSetDeviceLostCallback(device, callback, userdata);
|
||||
}
|
||||
|
||||
|
|
@ -1230,7 +1230,7 @@ pub const StubInterface = Interface(struct {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
pub inline fn adapterCreateDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) ?*gpu.Device {
|
||||
pub inline fn adapterCreateDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor) ?*gpu.Device {
|
||||
_ = adapter;
|
||||
_ = descriptor;
|
||||
unreachable;
|
||||
|
|
@ -1260,7 +1260,7 @@ pub const StubInterface = Interface(struct {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
pub inline fn adapterRequestDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
pub inline fn adapterRequestDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor, callback: gpu.RequestDeviceCallback, userdata: *anyopaque) void {
|
||||
_ = adapter;
|
||||
_ = descriptor;
|
||||
_ = callback;
|
||||
|
|
@ -1781,7 +1781,7 @@ pub const StubInterface = Interface(struct {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.DeviceLostCallback, userdata: *anyopaque) void {
|
||||
pub inline fn deviceSetDeviceLostCallback(device: *gpu.Device, callback: gpu.Device.LostCallback, userdata: *anyopaque) void {
|
||||
_ = device;
|
||||
_ = callback;
|
||||
_ = userdata;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue