gpu: update to latest revision as of 2022-08-06

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-06 23:08:39 -07:00 committed by Stephen Gutekanst
parent f856fccb76
commit 9f4a93cbef
8 changed files with 43 additions and 20 deletions

View file

@ -114,6 +114,7 @@ The rules for translating `webgpu.h` are as follows:
* `null` -> `nul`
* `error` -> `err`
* `type` -> `typ`
* `opaque` -> `opaq`
* Undefined in Zig commonly means _undefined memory_. WebGPU however uses _undefined_ as terminology to indicate something was not _specified_, as the optional _none value_, which Zig represents as _null_. Since _null_ is a reserved keyword in Zig, we rename all WebGPU _undefined_ terminology to "_unspecified_" instead.
* Constant names map using a few simple rules, but it's easiest to describe them with some concrete examples:
* `RG11B10Ufloat -> rg11_b10_ufloat`

View file

@ -2,16 +2,19 @@ const ChainedStruct = @import("types.zig").ChainedStruct;
const Texture = @import("texture.zig").Texture;
pub const Interface = @import("dawn_impl.zig").Interface;
/// TODO: Can be chained in gpu.Device.Descriptor
pub const CacheDeviceDescriptor = extern struct {
chain: ChainedStruct,
isolation_key: [*:0]const u8 = "",
};
/// TODO: Can be chained in gpu.CommandEncoder.Descriptor
pub const EncoderInternalUsageDescriptor = extern struct {
chain: ChainedStruct,
use_internal_usages: bool = false,
};
/// TODO: Can be chained in gpu.Instance.Descriptor
pub const InstanceDescriptor = extern struct {
chain: ChainedStruct,
additional_runtime_search_paths_count: u32,
@ -19,11 +22,13 @@ pub const InstanceDescriptor = extern struct {
additional_runtime_search_paths: ?[*]const u8,
};
/// TODO: Can be chained in gpu.Texture.Descriptor
pub const TextureInternalUsageDescriptor = extern struct {
chain: ChainedStruct,
internal_usage: Texture.UsageFlags = Texture.UsageFlags.none,
};
/// TODO: Can be chained in gpu.Device.Descriptor
pub const TogglesDeviceDescriptor = extern struct {
chain: ChainedStruct,
force_enabled_toggles_count: u32 = 0,

View file

@ -463,6 +463,13 @@ pub const Interface = struct {
return @ptrCast(*gpu.ExternalTexture, procs.deviceCreateErrorExternalTexture.?(@ptrCast(c.WGPUDevice, device)));
}
pub inline fn deviceCreateErrorTexture(device: *gpu.Device, descriptor: *const gpu.Texture.Descriptor) *gpu.Texture {
return @ptrCast(*gpu.Texture, procs.deviceCreateErrorTexture.?(
@ptrCast(c.WGPUDevice, device),
@ptrCast(*const c.WGPUTextureDescriptor, descriptor),
));
}
pub inline fn deviceCreateExternalTexture(device: *gpu.Device, external_texture_descriptor: *const gpu.ExternalTexture.Descriptor) *gpu.ExternalTexture {
return @ptrCast(*gpu.ExternalTexture, procs.deviceCreateExternalTexture.?(
@ptrCast(c.WGPUDevice, device),
@ -655,10 +662,10 @@ pub const Interface = struct {
));
}
pub inline fn instanceRequestAdapter(instance: *gpu.Instance, options: *const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
pub inline fn instanceRequestAdapter(instance: *gpu.Instance, options: ?*const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
procs.instanceRequestAdapter.?(
@ptrCast(c.WGPUInstance, instance),
@ptrCast(*const c.WGPURequestAdapterOptions, options),
@ptrCast(?*const c.WGPURequestAdapterOptions, options),
@ptrCast(c.WGPURequestAdapterCallback, callback),
userdata,
);

View file

@ -107,6 +107,10 @@ pub const Device = opaque {
return Impl.deviceCreateErrorExternalTexture(device);
}
pub inline fn createErrorTexture(device: *Device, descriptor: *const Texture.Descriptor) *Texture {
return Impl.deviceCreateErrorTexture(device, descriptor);
}
pub inline fn createExternalTexture(device: *Device, external_texture_descriptor: *const ExternalTexture.Descriptor) *ExternalTexture {
return Impl.deviceCreateExternalTexture(device, external_texture_descriptor);
}

View file

@ -3,11 +3,13 @@ const TextureView = @import("texture_view.zig").TextureView;
const Impl = @import("interface.zig").Impl;
pub const ExternalTexture = opaque {
/// TODO: Can be chained in gpu.BindGroup.Entry
pub const BindingEntry = extern struct {
chain: ChainedStruct,
external_texture: *ExternalTexture,
};
/// TODO: Can be chained in gpu.BindGroupLayout.Entry
pub const BindingLayout = extern struct {
chain: ChainedStruct,
};

View file

@ -17,7 +17,7 @@ pub const Instance = opaque {
pub inline fn requestAdapter(
instance: *Instance,
options: *const RequestAdapterOptions,
options: ?*const RequestAdapterOptions,
context: anytype,
comptime callback: fn (
status: RequestAdapterStatus,

View file

@ -89,6 +89,7 @@ pub fn Interface(comptime T: type) type {
assertDecl(T, "deviceCreateComputePipelineAsync", fn (device: *gpu.Device, descriptor: *const gpu.ComputePipeline.Descriptor, callback: gpu.CreateComputePipelineAsyncCallback, userdata: ?*anyopaque) callconv(.Inline) void);
assertDecl(T, "deviceCreateErrorBuffer", fn (device: *gpu.Device) callconv(.Inline) *gpu.Buffer);
assertDecl(T, "deviceCreateErrorExternalTexture", fn (device: *gpu.Device) callconv(.Inline) *gpu.ExternalTexture);
assertDecl(T, "deviceCreateErrorTexture", fn (device: *gpu.Device, descriptor: *const gpu.Texture.Descriptor) callconv(.Inline) *gpu.Texture);
assertDecl(T, "deviceCreateExternalTexture", fn (device: *gpu.Device, external_texture_descriptor: *const gpu.ExternalTexture.Descriptor) callconv(.Inline) *gpu.ExternalTexture);
assertDecl(T, "deviceCreatePipelineLayout", fn (device: *gpu.Device, pipeline_layout_descriptor: *const gpu.PipelineLayout.Descriptor) callconv(.Inline) *gpu.PipelineLayout);
assertDecl(T, "deviceCreateQuerySet", fn (device: *gpu.Device, descriptor: *const gpu.QuerySet.Descriptor) callconv(.Inline) *gpu.QuerySet);
@ -120,7 +121,7 @@ pub fn Interface(comptime T: type) type {
assertDecl(T, "externalTextureReference", fn (external_texture: *gpu.ExternalTexture) callconv(.Inline) void);
assertDecl(T, "externalTextureRelease", fn (external_texture: *gpu.ExternalTexture) callconv(.Inline) void);
assertDecl(T, "instanceCreateSurface", fn (instance: *gpu.Instance, descriptor: *const gpu.Surface.Descriptor) callconv(.Inline) *gpu.Surface);
assertDecl(T, "instanceRequestAdapter", fn (instance: *gpu.Instance, options: *const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) callconv(.Inline) void);
assertDecl(T, "instanceRequestAdapter", fn (instance: *gpu.Instance, options: ?*const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) callconv(.Inline) void);
assertDecl(T, "instanceReference", fn (instance: *gpu.Instance) callconv(.Inline) void);
assertDecl(T, "instanceRelease", fn (instance: *gpu.Instance) callconv(.Inline) void);
assertDecl(T, "pipelineLayoutSetLabel", fn (pipeline_layout: *gpu.PipelineLayout, label: [*:0]const u8) callconv(.Inline) void);
@ -262,8 +263,7 @@ pub fn Export(comptime T: type) type {
return T.adapterHasFeature(adapter, feature);
}
// 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);
// WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor /* nullable */, WGPURequestDeviceCallback callback, void * userdata);
export fn wgpuAdapterRequestDevice(adapter: *gpu.Adapter, descriptor: ?*const gpu.Device.Descriptor, callback: gpu.RequestDeviceCallback, userdata: ?*anyopaque) void {
T.adapterRequestDevice(adapter, descriptor, callback, userdata);
}
@ -590,6 +590,11 @@ pub fn Export(comptime T: type) type {
return T.deviceCreateErrorExternalTexture(device);
}
// WGPU_EXPORT WGPUTexture wgpuDeviceCreateErrorTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor);
export fn wgpuDeviceCreateErrorTexture(device: *gpu.Device, descriptor: *const gpu.Texture.Descriptor) *gpu.Texture {
return T.deviceCreateErrorTexture(device, descriptor);
}
// WGPU_EXPORT WGPUExternalTexture wgpuDeviceCreateExternalTexture(WGPUDevice device, WGPUExternalTextureDescriptor const * externalTextureDescriptor);
export fn wgpuDeviceCreateExternalTexture(device: *gpu.Device, external_texture_descriptor: *const gpu.ExternalTexture.Descriptor) *gpu.ExternalTexture {
return T.deviceCreateExternalTexture(device, external_texture_descriptor);
@ -745,8 +750,8 @@ pub fn Export(comptime T: type) type {
return T.instanceCreateSurface(instance, descriptor);
}
// WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata);
export fn wgpuInstanceRequestAdapter(instance: *gpu.Instance, options: *const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
// WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPURequestAdapterOptions const * options /* nullable */, WGPURequestAdapterCallback callback, void * userdata);
export fn wgpuInstanceRequestAdapter(instance: *gpu.Instance, options: ?*const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
T.instanceRequestAdapter(instance, options, callback, userdata);
}
@ -1668,6 +1673,12 @@ pub const StubInterface = Interface(struct {
unreachable;
}
pub inline fn deviceCreateErrorTexture(device: *gpu.Device, descriptor: *const gpu.Texture.Descriptor) *gpu.Texture {
_ = device;
_ = descriptor;
unreachable;
}
pub inline fn deviceCreateExternalTexture(device: *gpu.Device, external_texture_descriptor: *const gpu.ExternalTexture.Descriptor) *gpu.ExternalTexture {
_ = device;
_ = external_texture_descriptor;
@ -1853,7 +1864,7 @@ pub const StubInterface = Interface(struct {
unreachable;
}
pub inline fn instanceRequestAdapter(instance: *gpu.Instance, options: *const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
pub inline fn instanceRequestAdapter(instance: *gpu.Instance, options: ?*const gpu.RequestAdapterOptions, callback: gpu.RequestAdapterCallback, userdata: ?*anyopaque) void {
_ = instance;
_ = options;
_ = callback;

View file

@ -73,10 +73,7 @@ pub const RenderPassDescriptor = extern struct {
timestamp_writes: ?[*]const RenderPassTimestampWrite = null,
};
pub const AlphaMode = enum(u32) {
premultiplied = 0x00000000,
unpremultiplied = 0x00000001,
};
pub const AlphaMode = enum(u32) { premultiplied = 0x00000000, unpremultiplied = 0x00000001, opaq = 0x00000002 };
pub const BackendType = enum(u32) {
nul,
@ -193,7 +190,6 @@ pub const FeatureName = enum(u32) {
texture_compression_etc2 = 0x00000006,
texture_compression_astc = 0x00000007,
indirect_first_instance = 0x00000008,
depth_clamping = 0x000003e8,
dawn_shader_float16 = 0x000003e9,
dawn_internal_usages = 0x000003ea,
dawn_multi_planar_formats = 0x000003eb,
@ -299,7 +295,6 @@ pub const SType = enum(u32) {
surface_descriptor_from_windows_swap_chain_panel = 0x0000000E,
render_pass_descriptor_max_draw_count = 0x0000000F,
dawn_texture_internal_usage_descriptor = 0x000003E8,
primitive_depth_clamping_state = 0x000003E9,
dawn_toggles_device_descriptor = 0x000003EA,
dawn_encoder_internal_usage_descriptor = 0x000003EB,
dawn_instance_descriptor = 0x000003EC,
@ -532,6 +527,7 @@ pub const CopyTextureForBrowserOptions = extern struct {
// TODO: dawn.json says length 7, does it mean array length?
dst_transfer_function_parameters: ?*const f32,
dst_alpha_mode: AlphaMode = .unpremultiplied,
internal_usage: bool = false,
};
pub const MultisampleState = extern struct {
@ -541,11 +537,7 @@ pub const MultisampleState = extern struct {
alpha_to_coverage_enabled: bool = false,
};
pub const PrimitiveDepthClampingState = extern struct {
chain: ChainedStruct,
clamp_depth: bool = false,
};
/// TODO: Can be chained in gpu.PrimitiveState
pub const PrimitiveDepthClipControl = extern struct {
chain: ChainedStruct,
unclipped_depth: bool = false,
@ -559,6 +551,7 @@ pub const PrimitiveState = extern struct {
cull_mode: CullMode = .none,
};
/// TODO: Can be chained in gpu.RenderPassDescriptor
pub const RenderPassDescriptorMaxDrawCount = extern struct {
chain: ChainedStruct,
max_draw_count: u64 = 50000000,