diff --git a/gpu/src/adapter.zig b/gpu/src/adapter.zig index 3bdae1fb..eaea3694 100644 --- a/gpu/src/adapter.zig +++ b/gpu/src/adapter.zig @@ -8,6 +8,34 @@ const RequestDeviceStatus = @import("types.zig").RequestDeviceStatus; const Impl = @import("interface.zig").Impl; pub const Adapter = opaque { + pub const Type = enum(u32) { + discrete_gpu, + integrated_gpu, + cpu, + unknown, + + pub fn name(t: Type) []const u8 { + return switch (t) { + .discrete_gpu => "Discrete GPU", + .integrated_gpu => "Integrated GPU", + .cpu => "CPU", + .unknown => "Unknown", + }; + } + }; + + pub const Properties = extern struct { + next_in_chain: ?*ChainedStructOut = null, + vendor_id: u32, + vendor_name: [*:0]const u8, + architecture: [*:0]const u8, + device_id: u32, + name: [*:0]const u8, + driver_description: [*:0]const u8, + adapter_type: Type, + backend_type: Type, + }; + pub inline fn createDevice(adapter: *Adapter, descriptor: ?*const DeviceDescriptor) ?Device { return Impl.adapterCreateDevice(adapter, descriptor); } @@ -21,7 +49,7 @@ pub const Adapter = opaque { return Impl.adapterGetLimits(adapter, limits); } - pub inline fn getProperties(adapter: *Adapter, properties: *AdapterProperties) void { + pub inline fn getProperties(adapter: *Adapter, properties: *Adapter.Properties) void { Impl.adapterGetProperties(adapter, properties); } @@ -49,34 +77,6 @@ pub const RequestDeviceCallback = fn ( userdata: *anyopaque, ) callconv(.C) void; -pub const AdapterType = enum(u32) { - discrete_gpu, - integrated_gpu, - cpu, - unknown, - - pub fn name(t: AdapterType) []const u8 { - return switch (t) { - .discrete_gpu => "Discrete GPU", - .integrated_gpu => "Integrated GPU", - .cpu => "CPU", - .unknown => "Unknown", - }; - } -}; - -pub const AdapterProperties = extern struct { - next_in_chain: ?*ChainedStructOut = null, - vendor_id: u32, - vendor_name: [*:0]const u8, - architecture: [*:0]const u8, - device_id: u32, - name: [*:0]const u8, - driver_description: [*:0]const u8, - adapter_type: AdapterType, - backend_type: AdapterType, -}; - -test "AdapterType name" { - try testing.expectEqualStrings("Discrete GPU", AdapterType.discrete_gpu.name()); +test "Adapter.Type name" { + try testing.expectEqualStrings("Discrete GPU", Adapter.Type.discrete_gpu.name()); } diff --git a/gpu/src/interface.zig b/gpu/src/interface.zig index 40b5410c..cbe1aa1a 100644 --- a/gpu/src/interface.zig +++ b/gpu/src/interface.zig @@ -22,7 +22,7 @@ pub fn Interface(comptime T: type) type { assertDecl(T, "adapterCreateDevice", fn (adapter: *gpu.Adapter, descriptor: ?*const gpu.DeviceDescriptor) 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.AdapterProperties) callconv(.Inline) void); + 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, "adapterReference", fn (adapter: *gpu.Adapter) callconv(.Inline) void); @@ -253,7 +253,7 @@ pub fn Export(comptime T: type) type { } // WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties); - export fn wgpuAdapterGetProperties(adapter: *gpu.Adapter, properties: *gpu.AdapterProperties) void { + export fn wgpuAdapterGetProperties(adapter: *gpu.Adapter, properties: *gpu.Adapter.Properties) void { return T.adapterGetProperties(adapter, properties); } @@ -1250,7 +1250,7 @@ pub const StubInterface = Interface(struct { unreachable; } - pub inline fn adapterGetProperties(adapter: *gpu.Adapter, properties: *gpu.AdapterProperties) void { + pub inline fn adapterGetProperties(adapter: *gpu.Adapter, properties: *gpu.Adapter.Properties) void { _ = adapter; _ = properties; unreachable;