gpu: improve how limits are represented
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
070126b85d
commit
39ab0105a9
6 changed files with 36 additions and 25 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const FeatureName = @import("feature_name.zig").FeatureName;
|
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 Device = @import("Device.zig");
|
||||||
|
|
||||||
const Adapter = @This();
|
const Adapter = @This();
|
||||||
|
|
@ -31,7 +31,7 @@ features: []FeatureName,
|
||||||
/// The best limits which can be used to create devices on this adapter.
|
/// 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.
|
/// 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.
|
/// If set to true indicates that the adapter is a fallback adapter.
|
||||||
///
|
///
|
||||||
|
|
@ -54,7 +54,8 @@ vtable: *const VTable,
|
||||||
request_device_frame_size: usize,
|
request_device_frame_size: usize,
|
||||||
|
|
||||||
pub const VTable = struct {
|
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);
|
// WGPU_EXPORT WGPUDevice wgpuAdapterCreateDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor);
|
||||||
reference: fn (ptr: *anyopaque) void,
|
reference: fn (ptr: *anyopaque) void,
|
||||||
release: fn (ptr: *anyopaque) void,
|
release: fn (ptr: *anyopaque) void,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
//! https://gpuweb.github.io/gpuweb/#devices
|
//! https://gpuweb.github.io/gpuweb/#devices
|
||||||
//! https://gpuweb.github.io/gpuweb/#gpuadapter
|
//! https://gpuweb.github.io/gpuweb/#gpuadapter
|
||||||
const FeatureName = @import("feature_name.zig").FeatureName;
|
const FeatureName = @import("feature_name.zig").FeatureName;
|
||||||
|
const Limits = @import("Limits.zig");
|
||||||
|
|
||||||
const Device = @This();
|
const Device = @This();
|
||||||
|
|
||||||
|
|
@ -56,8 +57,7 @@ pub const VTable = struct {
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[]const u8 = null,
|
label: ?[]const u8 = null,
|
||||||
required_features: ?[]FeatureName = null,
|
required_features: ?[]FeatureName = null,
|
||||||
// TODO:
|
required_limits: ?Limits = null,
|
||||||
//required_limits: ?RequiredLimits = null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test "syntax" {
|
test "syntax" {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
pub const SupportedLimits = struct {};
|
// TODO: docs
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// typedef struct WGPUSupportedLimits {
|
// typedef struct WGPUSupportedLimits {
|
||||||
// WGPUChainedStructOut * nextInChain;
|
// WGPUChainedStructOut * nextInChain;
|
||||||
// WGPULimits limits;
|
// WGPULimits limits;
|
||||||
// } WGPUSupportedLimits;
|
// } WGPUSupportedLimits;
|
||||||
|
|
||||||
|
// TODO:
|
||||||
// typedef struct WGPULimits {
|
// typedef struct WGPULimits {
|
||||||
// uint32_t maxTextureDimension1D;
|
// uint32_t maxTextureDimension1D;
|
||||||
// uint32_t maxTextureDimension2D;
|
// uint32_t maxTextureDimension2D;
|
||||||
|
|
@ -2,20 +2,20 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @import("c.zig").c;
|
const c = @import("c.zig").c;
|
||||||
|
|
||||||
pub const Interface = @import("Interface.zig");
|
const Interface = @import("Interface.zig");
|
||||||
pub const RequestAdapterOptions = Interface.RequestAdapterOptions;
|
const RequestAdapterOptions = Interface.RequestAdapterOptions;
|
||||||
pub const RequestAdapterErrorCode = Interface.RequestAdapterErrorCode;
|
const RequestAdapterErrorCode = Interface.RequestAdapterErrorCode;
|
||||||
pub const RequestAdapterError = Interface.RequestAdapterError;
|
const RequestAdapterError = Interface.RequestAdapterError;
|
||||||
pub const RequestAdapterResponse = Interface.RequestAdapterResponse;
|
const RequestAdapterResponse = Interface.RequestAdapterResponse;
|
||||||
|
|
||||||
pub const Adapter = @import("Adapter.zig");
|
const Adapter = @import("Adapter.zig");
|
||||||
pub const RequestDeviceErrorCode = Adapter.RequestDeviceErrorCode;
|
const RequestDeviceErrorCode = Adapter.RequestDeviceErrorCode;
|
||||||
pub const RequestDeviceError = Adapter.RequestDeviceError;
|
const RequestDeviceError = Adapter.RequestDeviceError;
|
||||||
pub const RequestDeviceResponse = Adapter.RequestDeviceResponse;
|
const RequestDeviceResponse = Adapter.RequestDeviceResponse;
|
||||||
|
|
||||||
pub const Device = @import("Device.zig");
|
|
||||||
|
|
||||||
|
const Device = @import("Device.zig");
|
||||||
const Surface = @import("Surface.zig");
|
const Surface = @import("Surface.zig");
|
||||||
|
const Limits = @import("Limits.zig");
|
||||||
|
|
||||||
const NativeInstance = @This();
|
const NativeInstance = @This();
|
||||||
|
|
||||||
|
|
@ -233,12 +233,17 @@ const adapter_vtable = Adapter.VTable{
|
||||||
pub fn requestDevice(ptr: *anyopaque, descriptor: *const Device.Descriptor) callconv(.Async) RequestDeviceResponse {
|
pub fn requestDevice(ptr: *anyopaque, descriptor: *const Device.Descriptor) callconv(.Async) RequestDeviceResponse {
|
||||||
const adapter = @ptrCast(c.WGPUAdapter, @alignCast(@alignOf(c.WGPUAdapter), ptr));
|
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{
|
const desc = c.WGPUDeviceDescriptor{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.label = if (descriptor.label) |l| @ptrCast([*c]const u8, l) else 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,
|
.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,
|
.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 {
|
const callback = (struct {
|
||||||
|
|
@ -295,6 +300,12 @@ const device_vtable = Device.VTable{
|
||||||
}).release,
|
}).release,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn convertLimits(l: Limits) c.WGPULimits {
|
||||||
|
// TODO: implement!
|
||||||
|
_ = l;
|
||||||
|
return std.mem.zeroes(c.WGPULimits);
|
||||||
|
}
|
||||||
|
|
||||||
test "syntax" {
|
test "syntax" {
|
||||||
_ = wrap;
|
_ = wrap;
|
||||||
_ = interface_vtable;
|
_ = interface_vtable;
|
||||||
|
|
@ -304,4 +315,5 @@ test "syntax" {
|
||||||
_ = adapter_vtable;
|
_ = adapter_vtable;
|
||||||
_ = wrapDevice;
|
_ = wrapDevice;
|
||||||
_ = device_vtable;
|
_ = device_vtable;
|
||||||
|
_ = convertLimits;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -955,11 +955,6 @@ typedef struct WGPURenderPassColorAttachment {
|
||||||
WGPUColor clearValue;
|
WGPUColor clearValue;
|
||||||
} WGPURenderPassColorAttachment;
|
} WGPURenderPassColorAttachment;
|
||||||
|
|
||||||
typedef struct WGPURequiredLimits {
|
|
||||||
WGPUChainedStruct const * nextInChain;
|
|
||||||
WGPULimits limits;
|
|
||||||
} WGPURequiredLimits;
|
|
||||||
|
|
||||||
typedef struct WGPUTextureDescriptor {
|
typedef struct WGPUTextureDescriptor {
|
||||||
WGPUChainedStruct const * nextInChain;
|
WGPUChainedStruct const * nextInChain;
|
||||||
char const * label;
|
char const * label;
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ pub const NativeInstance = @import("NativeInstance.zig");
|
||||||
pub const Adapter = @import("Adapter.zig");
|
pub const Adapter = @import("Adapter.zig");
|
||||||
pub const Device = @import("Device.zig");
|
pub const Device = @import("Device.zig");
|
||||||
pub const Surface = @import("Surface.zig");
|
pub const Surface = @import("Surface.zig");
|
||||||
|
pub const Limits = @import("Limits.zig");
|
||||||
|
|
||||||
pub const FeatureName = @import("feature_name.zig").FeatureName;
|
pub const FeatureName = @import("feature_name.zig").FeatureName;
|
||||||
pub const SupportedLimits = @import("supported_limits.zig").SupportedLimits;
|
|
||||||
|
|
||||||
test "syntax" {
|
test "syntax" {
|
||||||
_ = Interface;
|
_ = Interface;
|
||||||
|
|
@ -41,7 +41,7 @@ test "syntax" {
|
||||||
_ = Adapter;
|
_ = Adapter;
|
||||||
_ = Device;
|
_ = Device;
|
||||||
_ = Surface;
|
_ = Surface;
|
||||||
|
_ = Limits;
|
||||||
|
|
||||||
_ = FeatureName;
|
_ = FeatureName;
|
||||||
_ = SupportedLimits;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue