Backed out 2 changesets (bug 1908320) for causing wr failures on align-items-baseline...
[gecko.git] / dom / webidl / WebGPU.webidl
bloba6d790cce931a8ca6dd4ecadaced2615fb47208a
1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/.
5  *
6  * The origin of this IDL file is
7  * https://gpuweb.github.io/gpuweb/
8  */
10 interface mixin GPUObjectBase {
11     attribute USVString? label;
14 dictionary GPUObjectDescriptorBase {
15     USVString label = "";
18 [Func="mozilla::webgpu::Instance::PrefEnabled",
19  Exposed=(Window, DedicatedWorker), SecureContext]
20 interface GPUSupportedLimits {
21     readonly attribute unsigned long maxTextureDimension1D;
22     readonly attribute unsigned long maxTextureDimension2D;
23     readonly attribute unsigned long maxTextureDimension3D;
24     readonly attribute unsigned long maxTextureArrayLayers;
25     readonly attribute unsigned long maxBindGroups;
26     readonly attribute unsigned long maxBindGroupsPlusVertexBuffers;
27     readonly attribute unsigned long maxBindingsPerBindGroup;
28     readonly attribute unsigned long maxDynamicUniformBuffersPerPipelineLayout;
29     readonly attribute unsigned long maxDynamicStorageBuffersPerPipelineLayout;
30     readonly attribute unsigned long maxSampledTexturesPerShaderStage;
31     readonly attribute unsigned long maxSamplersPerShaderStage;
32     readonly attribute unsigned long maxStorageBuffersPerShaderStage;
33     readonly attribute unsigned long maxStorageTexturesPerShaderStage;
34     readonly attribute unsigned long maxUniformBuffersPerShaderStage;
35     readonly attribute unsigned long long maxUniformBufferBindingSize;
36     readonly attribute unsigned long long maxStorageBufferBindingSize;
37     readonly attribute unsigned long minUniformBufferOffsetAlignment;
38     readonly attribute unsigned long minStorageBufferOffsetAlignment;
39     readonly attribute unsigned long maxVertexBuffers;
40     readonly attribute unsigned long long maxBufferSize;
41     readonly attribute unsigned long maxVertexAttributes;
42     readonly attribute unsigned long maxVertexBufferArrayStride;
43     readonly attribute unsigned long maxInterStageShaderComponents;
44     readonly attribute unsigned long maxInterStageShaderVariables;
45     readonly attribute unsigned long maxColorAttachments;
46     readonly attribute unsigned long maxColorAttachmentBytesPerSample;
47     readonly attribute unsigned long maxComputeWorkgroupStorageSize;
48     readonly attribute unsigned long maxComputeInvocationsPerWorkgroup;
49     readonly attribute unsigned long maxComputeWorkgroupSizeX;
50     readonly attribute unsigned long maxComputeWorkgroupSizeY;
51     readonly attribute unsigned long maxComputeWorkgroupSizeZ;
52     readonly attribute unsigned long maxComputeWorkgroupsPerDimension;
55 [Func="mozilla::webgpu::Instance::PrefEnabled",
56  Exposed=(Window, DedicatedWorker), SecureContext]
57 interface GPUSupportedFeatures {
58     readonly setlike<DOMString>;
61 [Func="mozilla::webgpu::Instance::PrefEnabled",
62  Exposed=(Window, DedicatedWorker), SecureContext]
63 interface GPUAdapterInfo {
64     readonly attribute DOMString vendor;
65     readonly attribute DOMString architecture;
66     readonly attribute DOMString device;
67     readonly attribute DOMString description;
69     // Non-standard; see <https://bugzilla.mozilla.org/show_bug.cgi?id=1831994>.
70     [ChromeOnly] readonly attribute DOMString wgpuName;
71     [ChromeOnly] readonly attribute unsigned long wgpuVendor;
72     [ChromeOnly] readonly attribute unsigned long wgpuDevice;
73     [ChromeOnly] readonly attribute DOMString wgpuDeviceType;
74     [ChromeOnly] readonly attribute DOMString wgpuDriver;
75     [ChromeOnly] readonly attribute DOMString wgpuDriverInfo;
76     [ChromeOnly] readonly attribute DOMString wgpuBackend;
79 interface mixin NavigatorGPU {
80     [SameObject, Func="mozilla::webgpu::Instance::PrefEnabled", Exposed=(Window, DedicatedWorker), SecureContext] readonly attribute GPU gpu;
82 // NOTE: see `dom/webidl/Navigator.webidl`
83 // Navigator includes NavigatorGPU;
84 // NOTE: see `dom/webidl/WorkerNavigator.webidl`
85 // WorkerNavigator includes NavigatorGPU;
88     Func="mozilla::webgpu::Instance::PrefEnabled",
89     Exposed=(Window, DedicatedWorker), SecureContext
91 interface GPU {
92     [Throws]
93     Promise<GPUAdapter?> requestAdapter(optional GPURequestAdapterOptions options = {});
94     GPUTextureFormat getPreferredCanvasFormat();
97 dictionary GPURequestAdapterOptions {
98     GPUPowerPreference powerPreference;
99     boolean forceFallbackAdapter = false;
102 enum GPUPowerPreference {
103     "low-power",
104     "high-performance",
107 [Func="mozilla::webgpu::Instance::PrefEnabled",
108  Exposed=(Window, DedicatedWorker), SecureContext]
109 interface GPUAdapter {
110     [SameObject] readonly attribute GPUSupportedFeatures features;
111     [SameObject] readonly attribute GPUSupportedLimits limits;
112     readonly attribute boolean isFallbackAdapter;
114     [Throws]
115     Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
116     [Throws]
117     Promise<GPUAdapterInfo> requestAdapterInfo(optional sequence<DOMString> unmaskHints = []);
120 dictionary GPUDeviceDescriptor
121          : GPUObjectDescriptorBase {
122     sequence<GPUFeatureName> requiredFeatures = [];
123     record<DOMString, GPUSize64> requiredLimits;
124     GPUQueueDescriptor defaultQueue = {};
127 enum GPUFeatureName {
128     "depth-clip-control",
129     "depth32float-stencil8",
130     "texture-compression-bc",
131     "texture-compression-etc2",
132     "texture-compression-astc",
133     "timestamp-query",
134     "indirect-first-instance",
135     "shader-f16",
136     "rg11b10ufloat-renderable",
137     "bgra8unorm-storage",
138     "float32-filterable",
141 [Func="mozilla::webgpu::Instance::PrefEnabled",
142  Exposed=(Window, DedicatedWorker), SecureContext]
143 interface GPUDevice : EventTarget {
144     [SameObject] readonly attribute GPUSupportedFeatures features;
145     [SameObject] readonly attribute GPUSupportedLimits limits;
147     [SameObject, BinaryName="getQueue"] readonly attribute GPUQueue queue;
149     undefined destroy();
151     [Throws]
152     GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
153     GPUTexture createTexture(GPUTextureDescriptor descriptor);
154     GPUSampler createSampler(optional GPUSamplerDescriptor descriptor = {});
156     GPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
157     GPUPipelineLayout createPipelineLayout(GPUPipelineLayoutDescriptor descriptor);
158     GPUBindGroup createBindGroup(GPUBindGroupDescriptor descriptor);
160     [Throws]
161     GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
162     GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
163     GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
164     [Throws]
165     Promise<GPUComputePipeline> createComputePipelineAsync(GPUComputePipelineDescriptor descriptor);
166     [Throws]
167     Promise<GPURenderPipeline> createRenderPipelineAsync(GPURenderPipelineDescriptor descriptor);
169     GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
170     GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
172     //GPUQuerySet createQuerySet(GPUQuerySetDescriptor descriptor);
174 GPUDevice includes GPUObjectBase;
176 [Func="mozilla::webgpu::Instance::PrefEnabled",
177  Exposed=(Window, DedicatedWorker), SecureContext]
178 interface GPUBuffer {
179     readonly attribute GPUSize64Out size;
180     readonly attribute GPUFlagsConstant usage;
182     readonly attribute GPUBufferMapState mapState;
184     [Throws]
185     Promise<undefined> mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size);
186     [Throws]
187     ArrayBuffer getMappedRange(optional GPUSize64 offset = 0, optional GPUSize64 size);
188     [Throws]
189     undefined unmap();
191     [Throws]
192     undefined destroy();
194 GPUBuffer includes GPUObjectBase;
196 enum GPUBufferMapState {
197     "unmapped",
198     "pending",
199     "mapped",
202 dictionary GPUBufferDescriptor
203          : GPUObjectDescriptorBase {
204     required GPUSize64 size;
205     required GPUBufferUsageFlags usage;
206     boolean mappedAtCreation = false;
209 typedef [EnforceRange] unsigned long GPUBufferUsageFlags;
210 [Func="mozilla::webgpu::Instance::PrefEnabled",
211  Exposed=(Window, DedicatedWorker), SecureContext]
212 namespace GPUBufferUsage {
213     const GPUFlagsConstant MAP_READ      = 0x0001;
214     const GPUFlagsConstant MAP_WRITE     = 0x0002;
215     const GPUFlagsConstant COPY_SRC      = 0x0004;
216     const GPUFlagsConstant COPY_DST      = 0x0008;
217     const GPUFlagsConstant INDEX         = 0x0010;
218     const GPUFlagsConstant VERTEX        = 0x0020;
219     const GPUFlagsConstant UNIFORM       = 0x0040;
220     const GPUFlagsConstant STORAGE       = 0x0080;
221     const GPUFlagsConstant INDIRECT      = 0x0100;
222     const GPUFlagsConstant QUERY_RESOLVE = 0x0200;
225 typedef [EnforceRange] unsigned long GPUMapModeFlags;
226 [Func="mozilla::webgpu::Instance::PrefEnabled",
227  Exposed=(Window, DedicatedWorker), SecureContext]
228 namespace GPUMapMode {
229     const GPUFlagsConstant READ  = 0x0001;
230     const GPUFlagsConstant WRITE = 0x0002;
233 [Func="mozilla::webgpu::Instance::PrefEnabled",
234  Exposed=(Window, DedicatedWorker), SecureContext]
235 interface GPUTexture {
236     GPUTextureView createView(optional GPUTextureViewDescriptor descriptor = {});
238     undefined destroy();
240     readonly attribute GPUIntegerCoordinateOut width;
241     readonly attribute GPUIntegerCoordinateOut height;
242     readonly attribute GPUIntegerCoordinateOut depthOrArrayLayers;
243     readonly attribute GPUIntegerCoordinateOut mipLevelCount;
244     readonly attribute GPUSize32Out sampleCount;
245     readonly attribute GPUTextureDimension dimension;
246     readonly attribute GPUTextureFormat format;
247     readonly attribute GPUFlagsConstant usage;
249 GPUTexture includes GPUObjectBase;
251 dictionary GPUTextureDescriptor
252          : GPUObjectDescriptorBase {
253     required GPUExtent3D size;
254     GPUIntegerCoordinate mipLevelCount = 1;
255     GPUSize32 sampleCount = 1;
256     GPUTextureDimension dimension = "2d";
257     required GPUTextureFormat format;
258     required GPUTextureUsageFlags usage;
259     sequence<GPUTextureFormat> viewFormats = [];
262 enum GPUTextureDimension {
263     "1d",
264     "2d",
265     "3d",
268 typedef [EnforceRange] unsigned long GPUTextureUsageFlags;
269 [Func="mozilla::webgpu::Instance::PrefEnabled",
270  Exposed=(Window, DedicatedWorker), SecureContext]
271 namespace GPUTextureUsage {
272     const GPUFlagsConstant COPY_SRC          = 0x01;
273     const GPUFlagsConstant COPY_DST          = 0x02;
274     const GPUFlagsConstant TEXTURE_BINDING   = 0x04;
275     const GPUFlagsConstant STORAGE_BINDING   = 0x08;
276     const GPUFlagsConstant RENDER_ATTACHMENT = 0x10;
279 [Func="mozilla::webgpu::Instance::PrefEnabled",
280  Exposed=(Window, DedicatedWorker), SecureContext]
281 interface GPUTextureView {
283 GPUTextureView includes GPUObjectBase;
285 dictionary GPUTextureViewDescriptor
286          : GPUObjectDescriptorBase {
287     GPUTextureFormat format;
288     GPUTextureViewDimension dimension;
289     GPUTextureAspect aspect = "all";
290     GPUIntegerCoordinate baseMipLevel = 0;
291     GPUIntegerCoordinate mipLevelCount;
292     GPUIntegerCoordinate baseArrayLayer = 0;
293     GPUIntegerCoordinate arrayLayerCount;
296 enum GPUTextureViewDimension {
297     "1d",
298     "2d",
299     "2d-array",
300     "cube",
301     "cube-array",
302     "3d",
305 enum GPUTextureAspect {
306     "all",
307     "stencil-only",
308     "depth-only",
311 enum GPUTextureFormat {
312     // 8-bit formats
313     "r8unorm",
314     "r8snorm",
315     "r8uint",
316     "r8sint",
318     // 16-bit formats
319     "r16uint",
320     "r16sint",
321     "r16float",
322     "rg8unorm",
323     "rg8snorm",
324     "rg8uint",
325     "rg8sint",
327     // 32-bit formats
328     "r32uint",
329     "r32sint",
330     "r32float",
331     "rg16uint",
332     "rg16sint",
333     "rg16float",
334     "rgba8unorm",
335     "rgba8unorm-srgb",
336     "rgba8snorm",
337     "rgba8uint",
338     "rgba8sint",
339     "bgra8unorm",
340     "bgra8unorm-srgb",
341     // Packed 32-bit formats
342     "rgb9e5ufloat",
343     "rgb10a2unorm",
344     "rg11b10ufloat",
346     // 64-bit formats
347     "rg32uint",
348     "rg32sint",
349     "rg32float",
350     "rgba16uint",
351     "rgba16sint",
352     "rgba16float",
354     // 128-bit formats
355     "rgba32uint",
356     "rgba32sint",
357     "rgba32float",
359     // Depth/stencil formats
360     "stencil8",
361     "depth16unorm",
362     "depth24plus",
363     "depth24plus-stencil8",
364     "depth32float",
366     // "depth32float-stencil8" feature
367     "depth32float-stencil8",
369     // BC compressed formats usable if "texture-compression-bc" is both
370     // supported by the device/user agent and enabled in requestDevice.
371     "bc1-rgba-unorm",
372     "bc1-rgba-unorm-srgb",
373     "bc2-rgba-unorm",
374     "bc2-rgba-unorm-srgb",
375     "bc3-rgba-unorm",
376     "bc3-rgba-unorm-srgb",
377     "bc4-r-unorm",
378     "bc4-r-snorm",
379     "bc5-rg-unorm",
380     "bc5-rg-snorm",
381     "bc6h-rgb-ufloat",
382     "bc6h-rgb-float",
383     "bc7-rgba-unorm",
384     "bc7-rgba-unorm-srgb",
387 [Func="mozilla::webgpu::Instance::PrefEnabled",
388  Exposed=(Window, DedicatedWorker), SecureContext]
389 interface GPUSampler {
391 GPUSampler includes GPUObjectBase;
393 dictionary GPUSamplerDescriptor
394          : GPUObjectDescriptorBase {
395     GPUAddressMode addressModeU = "clamp-to-edge";
396     GPUAddressMode addressModeV = "clamp-to-edge";
397     GPUAddressMode addressModeW = "clamp-to-edge";
398     GPUFilterMode magFilter = "nearest";
399     GPUFilterMode minFilter = "nearest";
400     GPUMipmapFilterMode mipmapFilter = "nearest";
401     float lodMinClamp = 0;
402     float lodMaxClamp = 1000.0; // TODO: What should this be?
403     GPUCompareFunction compare;
404     [Clamp] unsigned short maxAnisotropy = 1;
407 enum GPUAddressMode {
408     "clamp-to-edge",
409     "repeat",
410     "mirror-repeat",
413 enum GPUFilterMode {
414     "nearest",
415     "linear",
418 enum GPUMipmapFilterMode {
419     "nearest",
420     "linear",
423 enum GPUCompareFunction {
424     "never",
425     "less",
426     "equal",
427     "less-equal",
428     "greater",
429     "not-equal",
430     "greater-equal",
431     "always",
434 [Func="mozilla::webgpu::Instance::PrefEnabled",
435  Exposed=(Window, DedicatedWorker), SecureContext]
436 interface GPUBindGroupLayout {
438 GPUBindGroupLayout includes GPUObjectBase;
440 dictionary GPUBindGroupLayoutDescriptor
441          : GPUObjectDescriptorBase {
442     required sequence<GPUBindGroupLayoutEntry> entries;
445 dictionary GPUBindGroupLayoutEntry {
446     required GPUIndex32 binding;
447     required GPUShaderStageFlags visibility;
449     GPUBufferBindingLayout buffer;
450     GPUSamplerBindingLayout sampler;
451     GPUTextureBindingLayout texture;
452     GPUStorageTextureBindingLayout storageTexture;
455 typedef [EnforceRange] unsigned long GPUShaderStageFlags;
456 [Func="mozilla::webgpu::Instance::PrefEnabled",
457  Exposed=(Window, DedicatedWorker), SecureContext]
458 namespace GPUShaderStage {
459     const GPUFlagsConstant VERTEX   = 0x1;
460     const GPUFlagsConstant FRAGMENT = 0x2;
461     const GPUFlagsConstant COMPUTE  = 0x4;
464 enum GPUBufferBindingType {
465     "uniform",
466     "storage",
467     "read-only-storage",
470 dictionary GPUBufferBindingLayout {
471     GPUBufferBindingType type = "uniform";
472     boolean hasDynamicOffset = false;
473     GPUSize64 minBindingSize = 0;
476 enum GPUSamplerBindingType {
477     "filtering",
478     "non-filtering",
479     "comparison",
482 dictionary GPUSamplerBindingLayout {
483     GPUSamplerBindingType type = "filtering";
486 enum GPUTextureSampleType {
487     "float",
488     "unfilterable-float",
489     "depth",
490     "sint",
491     "uint",
494 dictionary GPUTextureBindingLayout {
495     GPUTextureSampleType sampleType = "float";
496     GPUTextureViewDimension viewDimension = "2d";
497     boolean multisampled = false;
500 enum GPUStorageTextureAccess {
501     "write-only",
502     "read-only",
503     "read-write",
506 dictionary GPUStorageTextureBindingLayout {
507     GPUStorageTextureAccess access = "write-only";
508     required GPUTextureFormat format;
509     GPUTextureViewDimension viewDimension = "2d";
512 [Func="mozilla::webgpu::Instance::PrefEnabled",
513  Exposed=(Window, DedicatedWorker), SecureContext]
514 interface GPUBindGroup {
516 GPUBindGroup includes GPUObjectBase;
518 dictionary GPUBindGroupDescriptor
519          : GPUObjectDescriptorBase {
520     required GPUBindGroupLayout layout;
521     required sequence<GPUBindGroupEntry> entries;
524 typedef (GPUSampler or GPUTextureView or GPUBufferBinding) GPUBindingResource;
526 dictionary GPUBindGroupEntry {
527     required GPUIndex32 binding;
528     required GPUBindingResource resource;
531 dictionary GPUBufferBinding {
532     required GPUBuffer buffer;
533     GPUSize64 offset = 0;
534     GPUSize64 size;
537 [Func="mozilla::webgpu::Instance::PrefEnabled",
538  Exposed=(Window, DedicatedWorker), SecureContext]
539 interface GPUPipelineLayout {
541 GPUPipelineLayout includes GPUObjectBase;
543 dictionary GPUPipelineLayoutDescriptor
544          : GPUObjectDescriptorBase {
545     required sequence<GPUBindGroupLayout> bindGroupLayouts;
548 [Func="mozilla::webgpu::Instance::PrefEnabled",
549  Exposed=(Window, DedicatedWorker), SecureContext]
550 interface GPUShaderModule {
551     [Throws]
552     Promise<GPUCompilationInfo> getCompilationInfo();
554 GPUShaderModule includes GPUObjectBase;
556 dictionary GPUShaderModuleDescriptor
557          : GPUObjectDescriptorBase {
558     // UTF8String is not observably different from USVString
559     required UTF8String code;
560     object sourceMap;
563 enum GPUCompilationMessageType {
564     "error",
565     "warning",
566     "info",
569 [Func="mozilla::webgpu::Instance::PrefEnabled",
570  Exposed=(Window, DedicatedWorker), SecureContext]
571 interface GPUCompilationMessage {
572     readonly attribute DOMString message;
573     readonly attribute GPUCompilationMessageType type;
574     readonly attribute unsigned long long lineNum;
575     readonly attribute unsigned long long linePos;
576     readonly attribute unsigned long long offset;
577     readonly attribute unsigned long long length;
580 [Func="mozilla::webgpu::Instance::PrefEnabled",
581  Exposed=(Window, DedicatedWorker), SecureContext]
582 interface GPUCompilationInfo {
583     [Cached, Frozen, Pure]
584     readonly attribute sequence<GPUCompilationMessage> messages;
587 enum GPUAutoLayoutMode {
588     "auto",
591 dictionary GPUPipelineDescriptorBase
592          : GPUObjectDescriptorBase {
593     required (GPUPipelineLayout or GPUAutoLayoutMode) layout;
596 interface mixin GPUPipelineBase {
597     GPUBindGroupLayout getBindGroupLayout(unsigned long index);
600 dictionary GPUProgrammableStage {
601     required GPUShaderModule module;
602     USVString entryPoint;
603     record<USVString, GPUPipelineConstantValue> constants;
606 typedef double GPUPipelineConstantValue; // May represent WGSL's bool, f32, i32, u32, and f16 if enabled.
608 //TODO: Serializable
609 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
610 [Func="mozilla::webgpu::Instance::PrefEnabled",
611  Exposed=(Window, DedicatedWorker), SecureContext]
612 interface GPUComputePipeline {
614 GPUComputePipeline includes GPUObjectBase;
615 GPUComputePipeline includes GPUPipelineBase;
617 dictionary GPUComputePipelineDescriptor
618          : GPUPipelineDescriptorBase {
619     required GPUProgrammableStage compute;
622 //TODO: Serializable
623 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
624 [Func="mozilla::webgpu::Instance::PrefEnabled",
625  Exposed=(Window, DedicatedWorker), SecureContext]
626 interface GPURenderPipeline {
628 GPURenderPipeline includes GPUObjectBase;
629 GPURenderPipeline includes GPUPipelineBase;
631 dictionary GPURenderPipelineDescriptor
632          : GPUPipelineDescriptorBase {
633     required GPUVertexState vertex;
634     GPUPrimitiveState primitive = {};
635     GPUDepthStencilState depthStencil;
636     GPUMultisampleState multisample = {};
637     GPUFragmentState fragment;
640 dictionary GPUPrimitiveState {
641     GPUPrimitiveTopology topology = "triangle-list";
642     GPUIndexFormat stripIndexFormat;
643     GPUFrontFace frontFace = "ccw";
644     GPUCullMode cullMode = "none";
646     // Requires "depth-clip-control" feature.
647     boolean unclippedDepth = false;
650 enum GPUPrimitiveTopology {
651     "point-list",
652     "line-list",
653     "line-strip",
654     "triangle-list",
655     "triangle-strip",
658 enum GPUFrontFace {
659     "ccw",
660     "cw",
663 enum GPUCullMode {
664     "none",
665     "front",
666     "back",
669 dictionary GPUMultisampleState {
670     GPUSize32 count = 1;
671     GPUSampleMask mask = 0xFFFFFFFF;
672     boolean alphaToCoverageEnabled = false;
675 dictionary GPUFragmentState
676          : GPUProgrammableStage {
677     required sequence<GPUColorTargetState> targets;
680 dictionary GPUColorTargetState {
681     required GPUTextureFormat format;
683     GPUBlendState blend;
684     GPUColorWriteFlags writeMask = 0xF;  // GPUColorWrite.ALL
687 dictionary GPUBlendState {
688     required GPUBlendComponent color;
689     required GPUBlendComponent alpha;
692 typedef [EnforceRange] unsigned long GPUColorWriteFlags;
693 [Func="mozilla::webgpu::Instance::PrefEnabled",
694  Exposed=(Window, DedicatedWorker), SecureContext]
695 namespace GPUColorWrite {
696     const GPUFlagsConstant RED   = 0x1;
697     const GPUFlagsConstant GREEN = 0x2;
698     const GPUFlagsConstant BLUE  = 0x4;
699     const GPUFlagsConstant ALPHA = 0x8;
700     const GPUFlagsConstant ALL   = 0xF;
703 dictionary GPUBlendComponent {
704     GPUBlendOperation operation = "add";
705     GPUBlendFactor srcFactor = "one";
706     GPUBlendFactor dstFactor = "zero";
709 enum GPUBlendFactor {
710     "zero",
711     "one",
712     "src",
713     "one-minus-src",
714     "src-alpha",
715     "one-minus-src-alpha",
716     "dst",
717     "one-minus-dst",
718     "dst-alpha",
719     "one-minus-dst-alpha",
720     "src-alpha-saturated",
721     "constant",
722     "one-minus-constant",
725 enum GPUBlendOperation {
726     "add",
727     "subtract",
728     "reverse-subtract",
729     "min",
730     "max",
733 dictionary GPUDepthStencilState {
734     required GPUTextureFormat format;
736     boolean depthWriteEnabled = false;
737     GPUCompareFunction depthCompare = "always";
739     GPUStencilFaceState stencilFront = {};
740     GPUStencilFaceState stencilBack = {};
742     GPUStencilValue stencilReadMask = 0xFFFFFFFF;
743     GPUStencilValue stencilWriteMask = 0xFFFFFFFF;
745     GPUDepthBias depthBias = 0;
746     float depthBiasSlopeScale = 0;
747     float depthBiasClamp = 0;
750 dictionary GPUStencilFaceState {
751     GPUCompareFunction compare = "always";
752     GPUStencilOperation failOp = "keep";
753     GPUStencilOperation depthFailOp = "keep";
754     GPUStencilOperation passOp = "keep";
757 enum GPUStencilOperation {
758     "keep",
759     "zero",
760     "replace",
761     "invert",
762     "increment-clamp",
763     "decrement-clamp",
764     "increment-wrap",
765     "decrement-wrap",
768 enum GPUIndexFormat {
769     "uint16",
770     "uint32",
773 enum GPUVertexFormat {
774     "uint8x2",
775     "uint8x4",
776     "sint8x2",
777     "sint8x4",
778     "unorm8x2",
779     "unorm8x4",
780     "snorm8x2",
781     "snorm8x4",
782     "uint16x2",
783     "uint16x4",
784     "sint16x2",
785     "sint16x4",
786     "unorm16x2",
787     "unorm16x4",
788     "snorm16x2",
789     "snorm16x4",
790     "float16x2",
791     "float16x4",
792     "float32",
793     "float32x2",
794     "float32x3",
795     "float32x4",
796     "uint32",
797     "uint32x2",
798     "uint32x3",
799     "uint32x4",
800     "sint32",
801     "sint32x2",
802     "sint32x3",
803     "sint32x4",
806 enum GPUVertexStepMode {
807     "vertex",
808     "instance",
811 dictionary GPUVertexState
812          : GPUProgrammableStage {
813     sequence<GPUVertexBufferLayout?> buffers = [];
816 dictionary GPUVertexBufferLayout {
817     required GPUSize64 arrayStride;
818     GPUVertexStepMode stepMode = "vertex";
819     required sequence<GPUVertexAttribute> attributes;
822 dictionary GPUVertexAttribute {
823     required GPUVertexFormat format;
824     required GPUSize64 offset;
826     required GPUIndex32 shaderLocation;
829 dictionary GPUImageDataLayout {
830     GPUSize64 offset = 0;
831     GPUSize32 bytesPerRow;
832     GPUSize32 rowsPerImage;
835 dictionary GPUImageCopyBuffer
836          : GPUImageDataLayout {
837     required GPUBuffer buffer;
840 dictionary GPUImageCopyTexture {
841     required GPUTexture texture;
842     GPUIntegerCoordinate mipLevel = 0;
843     GPUOrigin3D origin;
844     GPUTextureAspect aspect = "all";
847 dictionary GPUImageCopyTextureTagged
848          : GPUImageCopyTexture {
849     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
850     boolean premultipliedAlpha = false;
853 dictionary GPUImageCopyExternalImage {
854     required (ImageBitmap or HTMLCanvasElement or OffscreenCanvas) source;
855     GPUOrigin2D origin = {};
856     boolean flipY = false;
859 [Func="mozilla::webgpu::Instance::PrefEnabled",
860  Exposed=(Window, DedicatedWorker), SecureContext]
861 interface GPUCommandBuffer {
863 GPUCommandBuffer includes GPUObjectBase;
865 dictionary GPUCommandBufferDescriptor
866          : GPUObjectDescriptorBase {
869 interface mixin GPUCommandsMixin {
872 [Func="mozilla::webgpu::Instance::PrefEnabled",
873  Exposed=(Window, DedicatedWorker), SecureContext]
874 interface GPUCommandEncoder {
875     GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor);
876     GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor = {});
878     undefined copyBufferToBuffer(
879         GPUBuffer source,
880         GPUSize64 sourceOffset,
881         GPUBuffer destination,
882         GPUSize64 destinationOffset,
883         GPUSize64 size);
885     undefined copyBufferToTexture(
886         GPUImageCopyBuffer source,
887         GPUImageCopyTexture destination,
888         GPUExtent3D copySize);
890     undefined copyTextureToBuffer(
891         GPUImageCopyTexture source,
892         GPUImageCopyBuffer destination,
893         GPUExtent3D copySize);
895     undefined copyTextureToTexture(
896         GPUImageCopyTexture source,
897         GPUImageCopyTexture destination,
898         GPUExtent3D copySize);
900     undefined clearBuffer(
901         GPUBuffer buffer,
902         optional GPUSize64 offset = 0,
903         optional GPUSize64 size);
905     GPUCommandBuffer finish(optional GPUCommandBufferDescriptor descriptor = {});
907 GPUCommandEncoder includes GPUObjectBase;
908 GPUCommandEncoder includes GPUCommandsMixin;
909 GPUCommandEncoder includes GPUDebugCommandsMixin;
911 dictionary GPUCommandEncoderDescriptor
912          : GPUObjectDescriptorBase {
915 interface mixin GPUBindingCommandsMixin {
916     undefined setBindGroup(GPUIndex32 index, GPUBindGroup bindGroup,
917         optional sequence<GPUBufferDynamicOffset> dynamicOffsets = []);
920 interface mixin GPUDebugCommandsMixin {
921     undefined pushDebugGroup(USVString groupLabel);
922     undefined popDebugGroup();
923     undefined insertDebugMarker(USVString markerLabel);
926 [Func="mozilla::webgpu::Instance::PrefEnabled",
927  Exposed=(Window, DedicatedWorker), SecureContext]
928 interface GPUComputePassEncoder {
929     undefined setPipeline(GPUComputePipeline pipeline);
930     undefined dispatchWorkgroups(GPUSize32 workgroupCountX, optional GPUSize32 workgroupCountY = 1, optional GPUSize32 workgroupCountZ = 1);
931     [Pref="dom.webgpu.indirect-dispatch.enabled"]
932     undefined dispatchWorkgroupsIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
934     undefined end();
936 GPUComputePassEncoder includes GPUObjectBase;
937 GPUComputePassEncoder includes GPUCommandsMixin;
938 GPUComputePassEncoder includes GPUDebugCommandsMixin;
939 GPUComputePassEncoder includes GPUBindingCommandsMixin;
941 dictionary GPUComputePassDescriptor
942          : GPUObjectDescriptorBase {
945 [Func="mozilla::webgpu::Instance::PrefEnabled",
946  Exposed=(Window, DedicatedWorker), SecureContext]
947 interface GPURenderPassEncoder {
948     undefined setViewport(float x, float y,
949         float width, float height,
950         float minDepth, float maxDepth);
952     undefined setScissorRect(GPUIntegerCoordinate x, GPUIntegerCoordinate y,
953                         GPUIntegerCoordinate width, GPUIntegerCoordinate height);
955     undefined setBlendConstant(GPUColor color);
956     undefined setStencilReference(GPUStencilValue reference);
958     //undefined beginOcclusionQuery(GPUSize32 queryIndex);
959     //undefined endOcclusionQuery();
961     undefined executeBundles(sequence<GPURenderBundle> bundles);
962     undefined end();
964 GPURenderPassEncoder includes GPUObjectBase;
965 GPURenderPassEncoder includes GPUCommandsMixin;
966 GPURenderPassEncoder includes GPUDebugCommandsMixin;
967 GPURenderPassEncoder includes GPUBindingCommandsMixin;
968 GPURenderPassEncoder includes GPURenderCommandsMixin;
970 dictionary GPURenderPassDescriptor
971          : GPUObjectDescriptorBase {
972     required sequence<GPURenderPassColorAttachment> colorAttachments;
973     GPURenderPassDepthStencilAttachment depthStencilAttachment;
974     GPUQuerySet occlusionQuerySet;
977 dictionary GPURenderPassColorAttachment {
978     required GPUTextureView view;
979     GPUTextureView resolveTarget;
981     GPUColor clearValue;
982     required GPULoadOp loadOp;
983     required GPUStoreOp storeOp;
986 dictionary GPURenderPassDepthStencilAttachment {
987     required GPUTextureView view;
989     float depthClearValue;
990     GPULoadOp depthLoadOp;
991     GPUStoreOp depthStoreOp;
992     boolean depthReadOnly = false;
994     GPUStencilValue stencilClearValue = 0;
995     GPULoadOp stencilLoadOp;
996     GPUStoreOp stencilStoreOp;
997     boolean stencilReadOnly = false;
1000 enum GPULoadOp {
1001     "load",
1002     "clear",
1005 enum GPUStoreOp {
1006     "store",
1007     "discard",
1010 dictionary GPURenderPassLayout
1011          : GPUObjectDescriptorBase {
1012     required sequence<GPUTextureFormat> colorFormats;
1013     GPUTextureFormat depthStencilFormat;
1014     GPUSize32 sampleCount = 1;
1017 interface mixin GPURenderCommandsMixin {
1018     undefined setPipeline(GPURenderPipeline pipeline);
1020     undefined setIndexBuffer(GPUBuffer buffer, GPUIndexFormat indexFormat, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
1021     undefined setVertexBuffer(GPUIndex32 slot, GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
1023     undefined draw(GPUSize32 vertexCount, optional GPUSize32 instanceCount = 1,
1024         optional GPUSize32 firstVertex = 0, optional GPUSize32 firstInstance = 0);
1025     undefined drawIndexed(GPUSize32 indexCount, optional GPUSize32 instanceCount = 1,
1026         optional GPUSize32 firstIndex = 0,
1027         optional GPUSignedOffset32 baseVertex = 0,
1028         optional GPUSize32 firstInstance = 0);
1030     [Pref="dom.webgpu.indirect-dispatch.enabled"]
1031     undefined drawIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
1032     [Pref="dom.webgpu.indirect-dispatch.enabled"]
1033     undefined drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
1036 [Func="mozilla::webgpu::Instance::PrefEnabled",
1037  Exposed=(Window, DedicatedWorker), SecureContext]
1038 interface GPURenderBundle {
1040 GPURenderBundle includes GPUObjectBase;
1042 dictionary GPURenderBundleDescriptor
1043          : GPUObjectDescriptorBase {
1046 [Func="mozilla::webgpu::Instance::PrefEnabled",
1047  Exposed=(Window, DedicatedWorker), SecureContext]
1048 interface GPURenderBundleEncoder {
1049     GPURenderBundle finish(optional GPURenderBundleDescriptor descriptor = {});
1051 GPURenderBundleEncoder includes GPUObjectBase;
1052 GPURenderBundleEncoder includes GPUCommandsMixin;
1053 GPURenderBundleEncoder includes GPUDebugCommandsMixin;
1054 GPURenderBundleEncoder includes GPUBindingCommandsMixin;
1055 GPURenderBundleEncoder includes GPURenderCommandsMixin;
1057 dictionary GPURenderBundleEncoderDescriptor
1058          : GPURenderPassLayout {
1059     boolean depthReadOnly = false;
1060     boolean stencilReadOnly = false;
1063 dictionary GPUQueueDescriptor
1064          : GPUObjectDescriptorBase {
1067 //TODO: use [AllowShared] on BufferSource
1068 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696216
1069 // https://github.com/heycam/webidl/issues/961
1071 [Func="mozilla::webgpu::Instance::PrefEnabled",
1072  Exposed=(Window, DedicatedWorker), SecureContext]
1073 interface GPUQueue {
1074     undefined submit(sequence<GPUCommandBuffer> buffers);
1076     [Throws]
1077     Promise<undefined> onSubmittedWorkDone();
1079     [Throws]
1080     undefined writeBuffer(
1081         GPUBuffer buffer,
1082         GPUSize64 bufferOffset,
1083         BufferSource data,
1084         optional GPUSize64 dataOffset = 0,
1085         optional GPUSize64 size);
1087     [Throws]
1088     undefined writeTexture(
1089         GPUImageCopyTexture destination,
1090         BufferSource data,
1091         GPUImageDataLayout dataLayout,
1092         GPUExtent3D size);
1094     [Throws]
1095     undefined copyExternalImageToTexture(
1096         GPUImageCopyExternalImage source,
1097         GPUImageCopyTextureTagged destination,
1098         GPUExtent3D copySize);
1100 GPUQueue includes GPUObjectBase;
1102 [Func="mozilla::webgpu::Instance::PrefEnabled",
1103  Exposed=(Window, DedicatedWorker), SecureContext]
1104 interface GPUQuerySet {
1105     undefined destroy();
1107 GPUQuerySet includes GPUObjectBase;
1109 dictionary GPUQuerySetDescriptor
1110          : GPUObjectDescriptorBase {
1111     required GPUQueryType type;
1112     required GPUSize32 count;
1113     sequence<GPUPipelineStatisticName> pipelineStatistics = [];
1116 enum GPUPipelineStatisticName {
1117     "vertex-shader-invocations",
1118     "clipper-invocations",
1119     "clipper-primitives-out",
1120     "fragment-shader-invocations",
1121     "compute-shader-invocations"
1124 enum GPUQueryType {
1125     "occlusion",
1126     "pipeline-statistics",
1127     "timestamp",
1130 [Func="mozilla::webgpu::Instance::PrefEnabled",
1131  Exposed=(Window, DedicatedWorker), SecureContext]
1132 interface GPUCanvasContext {
1133     readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;
1135     undefined configure(GPUCanvasConfiguration configuration);
1136     undefined unconfigure();
1138     [Throws]
1139     GPUTexture getCurrentTexture();
1142 enum GPUCanvasAlphaMode {
1143     "opaque",
1144     "premultiplied",
1147 dictionary GPUCanvasConfiguration {
1148     required GPUDevice device;
1149     required GPUTextureFormat format;
1150     GPUTextureUsageFlags usage = 0x10;  // GPUTextureUsage.RENDER_ATTACHMENT
1151     sequence<GPUTextureFormat> viewFormats = [];
1152     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
1153     GPUCanvasAlphaMode alphaMode = "opaque";
1156 enum GPUDeviceLostReason {
1157     "destroyed",
1160 [Func="mozilla::webgpu::Instance::PrefEnabled",
1161  Exposed=(Window, DedicatedWorker), SecureContext]
1162 interface GPUDeviceLostInfo {
1163     readonly attribute any reason; // GPUDeviceLostReason or undefined
1164     readonly attribute DOMString message;
1167 partial interface GPUDevice {
1168     [Throws]
1169     readonly attribute Promise<GPUDeviceLostInfo> lost;
1172 [Func="mozilla::webgpu::Instance::PrefEnabled",
1173  Exposed=(Window, DedicatedWorker), SecureContext]
1174 interface GPUError {
1175     readonly attribute DOMString message;
1178 [Func="mozilla::webgpu::Instance::PrefEnabled",
1179  Exposed=(Window, DedicatedWorker), SecureContext]
1180 interface GPUValidationError
1181         : GPUError {
1182     [Throws]
1183     constructor(DOMString message);
1186 [Func="mozilla::webgpu::Instance::PrefEnabled",
1187  Exposed=(Window, DedicatedWorker), SecureContext]
1188 interface GPUOutOfMemoryError
1189         : GPUError {
1190     [Throws]
1191     constructor(DOMString message);
1194 [Func="mozilla::webgpu::Instance::PrefEnabled",
1195  Exposed=(Window, DedicatedWorker), SecureContext]
1196 interface GPUInternalError
1197         : GPUError {
1198     [Throws]
1199     constructor(DOMString message);
1202 enum GPUErrorFilter {
1203     "validation",
1204     "out-of-memory",
1205     "internal",
1208 partial interface GPUDevice {
1209     undefined pushErrorScope(GPUErrorFilter filter);
1210     [Throws]
1211     Promise<GPUError?> popErrorScope();
1214 partial interface GPUDevice {
1215     [Exposed=(Window, DedicatedWorker)]
1216     attribute EventHandler onuncapturederror;
1219 typedef [EnforceRange] unsigned long GPUBufferDynamicOffset;
1220 typedef [EnforceRange] unsigned long GPUStencilValue;
1221 typedef [EnforceRange] unsigned long GPUSampleMask;
1222 typedef [EnforceRange] long GPUDepthBias;
1224 typedef [EnforceRange] unsigned long long GPUSize64;
1225 typedef [EnforceRange] unsigned long GPUIntegerCoordinate;
1226 typedef [EnforceRange] unsigned long GPUIndex32;
1227 typedef [EnforceRange] unsigned long GPUSize32;
1228 typedef [EnforceRange] long GPUSignedOffset32;
1230 typedef unsigned long long GPUSize64Out;
1231 typedef unsigned long GPUIntegerCoordinateOut;
1232 typedef unsigned long GPUSize32Out;
1234 typedef unsigned long GPUFlagsConstant;
1236 dictionary GPUColorDict {
1237     required double r;
1238     required double g;
1239     required double b;
1240     required double a;
1242 typedef (sequence<double> or GPUColorDict) GPUColor;
1244 dictionary GPUOrigin2DDict {
1245     GPUIntegerCoordinate x = 0;
1246     GPUIntegerCoordinate y = 0;
1248 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin2DDict) GPUOrigin2D;
1250 dictionary GPUOrigin3DDict {
1251     GPUIntegerCoordinate x = 0;
1252     GPUIntegerCoordinate y = 0;
1253     GPUIntegerCoordinate z = 0;
1255 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin3DDict) GPUOrigin3D;
1257 dictionary GPUExtent3DDict {
1258     required GPUIntegerCoordinate width;
1259     GPUIntegerCoordinate height = 1;
1260     GPUIntegerCoordinate depthOrArrayLayers = 1;
1262 typedef (sequence<GPUIntegerCoordinate> or GPUExtent3DDict) GPUExtent3D;