From 39ab0105a94815008663d3924f212ce10402dce7 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 7 Mar 2022 22:55:24 -0700 Subject: [PATCH] gpu: improve how limits are represented Signed-off-by: Stephen Gutekanst --- gpu/src/Adapter.zig | 7 ++-- gpu/src/Device.zig | 4 +-- gpu/src/{supported_limits.zig => Limits.zig} | 5 ++- gpu/src/NativeInstance.zig | 36 +++++++++++++------- gpu/src/TODO | 5 --- gpu/src/main.zig | 4 +-- 6 files changed, 36 insertions(+), 25 deletions(-) rename gpu/src/{supported_limits.zig => Limits.zig} (97%) diff --git a/gpu/src/Adapter.zig b/gpu/src/Adapter.zig index f58cfc8a..f80cd513 100644 --- a/gpu/src/Adapter.zig +++ b/gpu/src/Adapter.zig @@ -20,7 +20,7 @@ const std = @import("std"); const FeatureName = @import("feature_name.zig").FeatureName; -const SupportedLimits = @import("supported_limits.zig").SupportedLimits; +const Limits = @import("Limits.zig"); const Device = @import("Device.zig"); const Adapter = @This(); @@ -31,7 +31,7 @@ features: []FeatureName, /// The best limits which can be used to create devices on this adapter. /// /// Each adapter limit will be the same or better than its default value in supported limits. -limits: SupportedLimits, +limits: Limits, /// If set to true indicates that the adapter is a fallback adapter. /// @@ -54,7 +54,8 @@ vtable: *const VTable, request_device_frame_size: usize, pub const VTable = struct { - // TODO: + // TODO: is this method actually useful over requestDevice? Doesn't appear to be available in + // web either: // WGPU_EXPORT WGPUDevice wgpuAdapterCreateDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor); reference: fn (ptr: *anyopaque) void, release: fn (ptr: *anyopaque) void, diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig index c9e306dc..490e93a5 100644 --- a/gpu/src/Device.zig +++ b/gpu/src/Device.zig @@ -7,6 +7,7 @@ //! https://gpuweb.github.io/gpuweb/#devices //! https://gpuweb.github.io/gpuweb/#gpuadapter const FeatureName = @import("feature_name.zig").FeatureName; +const Limits = @import("Limits.zig"); const Device = @This(); @@ -56,8 +57,7 @@ pub const VTable = struct { pub const Descriptor = struct { label: ?[]const u8 = null, required_features: ?[]FeatureName = null, - // TODO: - //required_limits: ?RequiredLimits = null, + required_limits: ?Limits = null, }; test "syntax" { diff --git a/gpu/src/supported_limits.zig b/gpu/src/Limits.zig similarity index 97% rename from gpu/src/supported_limits.zig rename to gpu/src/Limits.zig index 9f67bcfd..055b605a 100644 --- a/gpu/src/supported_limits.zig +++ b/gpu/src/Limits.zig @@ -1,9 +1,12 @@ -pub const SupportedLimits = struct {}; +// TODO: docs + // TODO: // typedef struct WGPUSupportedLimits { // WGPUChainedStructOut * nextInChain; // WGPULimits limits; // } WGPUSupportedLimits; + +// TODO: // typedef struct WGPULimits { // uint32_t maxTextureDimension1D; // uint32_t maxTextureDimension2D; diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 52913efa..87bec0cf 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -2,20 +2,20 @@ const std = @import("std"); const c = @import("c.zig").c; -pub const Interface = @import("Interface.zig"); -pub const RequestAdapterOptions = Interface.RequestAdapterOptions; -pub const RequestAdapterErrorCode = Interface.RequestAdapterErrorCode; -pub const RequestAdapterError = Interface.RequestAdapterError; -pub const RequestAdapterResponse = Interface.RequestAdapterResponse; +const Interface = @import("Interface.zig"); +const RequestAdapterOptions = Interface.RequestAdapterOptions; +const RequestAdapterErrorCode = Interface.RequestAdapterErrorCode; +const RequestAdapterError = Interface.RequestAdapterError; +const RequestAdapterResponse = Interface.RequestAdapterResponse; -pub const Adapter = @import("Adapter.zig"); -pub const RequestDeviceErrorCode = Adapter.RequestDeviceErrorCode; -pub const RequestDeviceError = Adapter.RequestDeviceError; -pub const RequestDeviceResponse = Adapter.RequestDeviceResponse; - -pub const Device = @import("Device.zig"); +const Adapter = @import("Adapter.zig"); +const RequestDeviceErrorCode = Adapter.RequestDeviceErrorCode; +const RequestDeviceError = Adapter.RequestDeviceError; +const RequestDeviceResponse = Adapter.RequestDeviceResponse; +const Device = @import("Device.zig"); const Surface = @import("Surface.zig"); +const Limits = @import("Limits.zig"); const NativeInstance = @This(); @@ -233,12 +233,17 @@ const adapter_vtable = Adapter.VTable{ pub fn requestDevice(ptr: *anyopaque, descriptor: *const Device.Descriptor) callconv(.Async) RequestDeviceResponse { const adapter = @ptrCast(c.WGPUAdapter, @alignCast(@alignOf(c.WGPUAdapter), ptr)); + const required_limits = if (descriptor.required_limits) |l| c.WGPURequiredLimits{ + .nextInChain = null, + .limits = convertLimits(l), + } else null; + const desc = c.WGPUDeviceDescriptor{ .nextInChain = null, .label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else null, .requiredFeaturesCount = if (descriptor.required_features) |f| @intCast(u32, f.len) else 0, .requiredFeatures = if (descriptor.required_features) |f| @ptrCast([*c]const c_uint, &f[0]) else null, - .requiredLimits = null, // TODO + .requiredLimits = if (required_limits) |*l| l else null, }; const callback = (struct { @@ -295,6 +300,12 @@ const device_vtable = Device.VTable{ }).release, }; +fn convertLimits(l: Limits) c.WGPULimits { + // TODO: implement! + _ = l; + return std.mem.zeroes(c.WGPULimits); +} + test "syntax" { _ = wrap; _ = interface_vtable; @@ -304,4 +315,5 @@ test "syntax" { _ = adapter_vtable; _ = wrapDevice; _ = device_vtable; + _ = convertLimits; } diff --git a/gpu/src/TODO b/gpu/src/TODO index 3e07136e..9eeeef96 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -955,11 +955,6 @@ typedef struct WGPURenderPassColorAttachment { WGPUColor clearValue; } WGPURenderPassColorAttachment; -typedef struct WGPURequiredLimits { - WGPUChainedStruct const * nextInChain; - WGPULimits limits; -} WGPURequiredLimits; - typedef struct WGPUTextureDescriptor { WGPUChainedStruct const * nextInChain; char const * label; diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 9346c4b4..59b61729 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -30,9 +30,9 @@ pub const NativeInstance = @import("NativeInstance.zig"); pub const Adapter = @import("Adapter.zig"); pub const Device = @import("Device.zig"); pub const Surface = @import("Surface.zig"); +pub const Limits = @import("Limits.zig"); pub const FeatureName = @import("feature_name.zig").FeatureName; -pub const SupportedLimits = @import("supported_limits.zig").SupportedLimits; test "syntax" { _ = Interface; @@ -41,7 +41,7 @@ test "syntax" { _ = Adapter; _ = Device; _ = Surface; + _ = Limits; _ = FeatureName; - _ = SupportedLimits; }