Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / webidl / WebGPU.webidl
blob62a2794cec0046d5805392fbb6fa2dbc3feaa8dc
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     GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
161     GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
162     GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
163     [Throws]
164     Promise<GPUComputePipeline> createComputePipelineAsync(GPUComputePipelineDescriptor descriptor);
165     [Throws]
166     Promise<GPURenderPipeline> createRenderPipelineAsync(GPURenderPipelineDescriptor descriptor);
168     GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
169     GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
171     //GPUQuerySet createQuerySet(GPUQuerySetDescriptor descriptor);
173 GPUDevice includes GPUObjectBase;
175 [Func="mozilla::webgpu::Instance::PrefEnabled",
176  Exposed=(Window, DedicatedWorker), SecureContext]
177 interface GPUBuffer {
178     readonly attribute GPUSize64Out size;
179     readonly attribute GPUFlagsConstant usage;
181     readonly attribute GPUBufferMapState mapState;
183     [Throws]
184     Promise<undefined> mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size);
185     [Throws]
186     ArrayBuffer getMappedRange(optional GPUSize64 offset = 0, optional GPUSize64 size);
187     [Throws]
188     undefined unmap();
190     [Throws]
191     undefined destroy();
193 GPUBuffer includes GPUObjectBase;
195 enum GPUBufferMapState {
196     "unmapped",
197     "pending",
198     "mapped",
201 dictionary GPUBufferDescriptor
202          : GPUObjectDescriptorBase {
203     required GPUSize64 size;
204     required GPUBufferUsageFlags usage;
205     boolean mappedAtCreation = false;
208 typedef [EnforceRange] unsigned long GPUBufferUsageFlags;
209 [Func="mozilla::webgpu::Instance::PrefEnabled",
210  Exposed=(Window, DedicatedWorker), SecureContext]
211 interface GPUBufferUsage {
212     const GPUFlagsConstant MAP_READ      = 0x0001;
213     const GPUFlagsConstant MAP_WRITE     = 0x0002;
214     const GPUFlagsConstant COPY_SRC      = 0x0004;
215     const GPUFlagsConstant COPY_DST      = 0x0008;
216     const GPUFlagsConstant INDEX         = 0x0010;
217     const GPUFlagsConstant VERTEX        = 0x0020;
218     const GPUFlagsConstant UNIFORM       = 0x0040;
219     const GPUFlagsConstant STORAGE       = 0x0080;
220     const GPUFlagsConstant INDIRECT      = 0x0100;
221     const GPUFlagsConstant QUERY_RESOLVE = 0x0200;
224 typedef [EnforceRange] unsigned long GPUMapModeFlags;
225 [Func="mozilla::webgpu::Instance::PrefEnabled",
226  Exposed=(Window, DedicatedWorker), SecureContext]
227 interface GPUMapMode {
228     const GPUFlagsConstant READ  = 0x0001;
229     const GPUFlagsConstant WRITE = 0x0002;
232 [Func="mozilla::webgpu::Instance::PrefEnabled",
233  Exposed=(Window, DedicatedWorker), SecureContext]
234 interface GPUTexture {
235     GPUTextureView createView(optional GPUTextureViewDescriptor descriptor = {});
237     undefined destroy();
239     readonly attribute GPUIntegerCoordinateOut width;
240     readonly attribute GPUIntegerCoordinateOut height;
241     readonly attribute GPUIntegerCoordinateOut depthOrArrayLayers;
242     readonly attribute GPUIntegerCoordinateOut mipLevelCount;
243     readonly attribute GPUSize32Out sampleCount;
244     readonly attribute GPUTextureDimension dimension;
245     readonly attribute GPUTextureFormat format;
246     readonly attribute GPUFlagsConstant usage;
248 GPUTexture includes GPUObjectBase;
250 dictionary GPUTextureDescriptor
251          : GPUObjectDescriptorBase {
252     required GPUExtent3D size;
253     GPUIntegerCoordinate mipLevelCount = 1;
254     GPUSize32 sampleCount = 1;
255     GPUTextureDimension dimension = "2d";
256     required GPUTextureFormat format;
257     required GPUTextureUsageFlags usage;
258     sequence<GPUTextureFormat> viewFormats = [];
261 enum GPUTextureDimension {
262     "1d",
263     "2d",
264     "3d",
267 typedef [EnforceRange] unsigned long GPUTextureUsageFlags;
268 [Func="mozilla::webgpu::Instance::PrefEnabled",
269  Exposed=(Window, DedicatedWorker), SecureContext]
270 interface GPUTextureUsage {
271     const GPUFlagsConstant COPY_SRC          = 0x01;
272     const GPUFlagsConstant COPY_DST          = 0x02;
273     const GPUFlagsConstant TEXTURE_BINDING   = 0x04;
274     const GPUFlagsConstant STORAGE_BINDING   = 0x08;
275     const GPUFlagsConstant RENDER_ATTACHMENT = 0x10;
278 [Func="mozilla::webgpu::Instance::PrefEnabled",
279  Exposed=(Window, DedicatedWorker), SecureContext]
280 interface GPUTextureView {
282 GPUTextureView includes GPUObjectBase;
284 dictionary GPUTextureViewDescriptor
285          : GPUObjectDescriptorBase {
286     GPUTextureFormat format;
287     GPUTextureViewDimension dimension;
288     GPUTextureAspect aspect = "all";
289     GPUIntegerCoordinate baseMipLevel = 0;
290     GPUIntegerCoordinate mipLevelCount;
291     GPUIntegerCoordinate baseArrayLayer = 0;
292     GPUIntegerCoordinate arrayLayerCount;
295 enum GPUTextureViewDimension {
296     "1d",
297     "2d",
298     "2d-array",
299     "cube",
300     "cube-array",
301     "3d",
304 enum GPUTextureAspect {
305     "all",
306     "stencil-only",
307     "depth-only",
310 enum GPUTextureFormat {
311     // 8-bit formats
312     "r8unorm",
313     "r8snorm",
314     "r8uint",
315     "r8sint",
317     // 16-bit formats
318     "r16uint",
319     "r16sint",
320     "r16float",
321     "rg8unorm",
322     "rg8snorm",
323     "rg8uint",
324     "rg8sint",
326     // 32-bit formats
327     "r32uint",
328     "r32sint",
329     "r32float",
330     "rg16uint",
331     "rg16sint",
332     "rg16float",
333     "rgba8unorm",
334     "rgba8unorm-srgb",
335     "rgba8snorm",
336     "rgba8uint",
337     "rgba8sint",
338     "bgra8unorm",
339     "bgra8unorm-srgb",
340     // Packed 32-bit formats
341     "rgb9e5ufloat",
342     "rgb10a2unorm",
343     "rg11b10ufloat",
345     // 64-bit formats
346     "rg32uint",
347     "rg32sint",
348     "rg32float",
349     "rgba16uint",
350     "rgba16sint",
351     "rgba16float",
353     // 128-bit formats
354     "rgba32uint",
355     "rgba32sint",
356     "rgba32float",
358     // Depth/stencil formats
359     "stencil8",
360     "depth16unorm",
361     "depth24plus",
362     "depth24plus-stencil8",
363     "depth32float",
365     // "depth32float-stencil8" feature
366     "depth32float-stencil8",
368     // BC compressed formats usable if "texture-compression-bc" is both
369     // supported by the device/user agent and enabled in requestDevice.
370     "bc1-rgba-unorm",
371     "bc1-rgba-unorm-srgb",
372     "bc2-rgba-unorm",
373     "bc2-rgba-unorm-srgb",
374     "bc3-rgba-unorm",
375     "bc3-rgba-unorm-srgb",
376     "bc4-r-unorm",
377     "bc4-r-snorm",
378     "bc5-rg-unorm",
379     "bc5-rg-snorm",
380     "bc6h-rgb-ufloat",
381     "bc6h-rgb-float",
382     "bc7-rgba-unorm",
383     "bc7-rgba-unorm-srgb",
386 [Func="mozilla::webgpu::Instance::PrefEnabled",
387  Exposed=(Window, DedicatedWorker), SecureContext]
388 interface GPUSampler {
390 GPUSampler includes GPUObjectBase;
392 dictionary GPUSamplerDescriptor
393          : GPUObjectDescriptorBase {
394     GPUAddressMode addressModeU = "clamp-to-edge";
395     GPUAddressMode addressModeV = "clamp-to-edge";
396     GPUAddressMode addressModeW = "clamp-to-edge";
397     GPUFilterMode magFilter = "nearest";
398     GPUFilterMode minFilter = "nearest";
399     GPUMipmapFilterMode mipmapFilter = "nearest";
400     float lodMinClamp = 0;
401     float lodMaxClamp = 1000.0; // TODO: What should this be?
402     GPUCompareFunction compare;
403     [Clamp] unsigned short maxAnisotropy = 1;
406 enum GPUAddressMode {
407     "clamp-to-edge",
408     "repeat",
409     "mirror-repeat",
412 enum GPUFilterMode {
413     "nearest",
414     "linear",
417 enum GPUMipmapFilterMode {
418     "nearest",
419     "linear",
422 enum GPUCompareFunction {
423     "never",
424     "less",
425     "equal",
426     "less-equal",
427     "greater",
428     "not-equal",
429     "greater-equal",
430     "always",
433 [Func="mozilla::webgpu::Instance::PrefEnabled",
434  Exposed=(Window, DedicatedWorker), SecureContext]
435 interface GPUBindGroupLayout {
437 GPUBindGroupLayout includes GPUObjectBase;
439 dictionary GPUBindGroupLayoutDescriptor
440          : GPUObjectDescriptorBase {
441     required sequence<GPUBindGroupLayoutEntry> entries;
444 dictionary GPUBindGroupLayoutEntry {
445     required GPUIndex32 binding;
446     required GPUShaderStageFlags visibility;
448     GPUBufferBindingLayout buffer;
449     GPUSamplerBindingLayout sampler;
450     GPUTextureBindingLayout texture;
451     GPUStorageTextureBindingLayout storageTexture;
454 typedef [EnforceRange] unsigned long GPUShaderStageFlags;
455 [Func="mozilla::webgpu::Instance::PrefEnabled",
456  Exposed=(Window, DedicatedWorker), SecureContext]
457 interface GPUShaderStage {
458     const GPUFlagsConstant VERTEX   = 0x1;
459     const GPUFlagsConstant FRAGMENT = 0x2;
460     const GPUFlagsConstant COMPUTE  = 0x4;
463 enum GPUBufferBindingType {
464     "uniform",
465     "storage",
466     "read-only-storage",
469 dictionary GPUBufferBindingLayout {
470     GPUBufferBindingType type = "uniform";
471     boolean hasDynamicOffset = false;
472     GPUSize64 minBindingSize = 0;
475 enum GPUSamplerBindingType {
476     "filtering",
477     "non-filtering",
478     "comparison",
481 dictionary GPUSamplerBindingLayout {
482     GPUSamplerBindingType type = "filtering";
485 enum GPUTextureSampleType {
486     "float",
487     "unfilterable-float",
488     "depth",
489     "sint",
490     "uint",
493 dictionary GPUTextureBindingLayout {
494     GPUTextureSampleType sampleType = "float";
495     GPUTextureViewDimension viewDimension = "2d";
496     boolean multisampled = false;
499 enum GPUStorageTextureAccess {
500     "write-only",
503 dictionary GPUStorageTextureBindingLayout {
504     GPUStorageTextureAccess access = "write-only";
505     required GPUTextureFormat format;
506     GPUTextureViewDimension viewDimension = "2d";
509 [Func="mozilla::webgpu::Instance::PrefEnabled",
510  Exposed=(Window, DedicatedWorker), SecureContext]
511 interface GPUBindGroup {
513 GPUBindGroup includes GPUObjectBase;
515 dictionary GPUBindGroupDescriptor
516          : GPUObjectDescriptorBase {
517     required GPUBindGroupLayout layout;
518     required sequence<GPUBindGroupEntry> entries;
521 typedef (GPUSampler or GPUTextureView or GPUBufferBinding) GPUBindingResource;
523 dictionary GPUBindGroupEntry {
524     required GPUIndex32 binding;
525     required GPUBindingResource resource;
528 dictionary GPUBufferBinding {
529     required GPUBuffer buffer;
530     GPUSize64 offset = 0;
531     GPUSize64 size;
534 [Func="mozilla::webgpu::Instance::PrefEnabled",
535  Exposed=(Window, DedicatedWorker), SecureContext]
536 interface GPUPipelineLayout {
538 GPUPipelineLayout includes GPUObjectBase;
540 dictionary GPUPipelineLayoutDescriptor
541          : GPUObjectDescriptorBase {
542     required sequence<GPUBindGroupLayout> bindGroupLayouts;
545 [Func="mozilla::webgpu::Instance::PrefEnabled",
546  Exposed=(Window, DedicatedWorker), SecureContext]
547 interface GPUShaderModule {
548     [Throws]
549     Promise<GPUCompilationInfo> compilationInfo(); // To be removed with <https://bugzilla.mozilla.org/show_bug.cgi?id=1846892>
550     [Throws]
551     Promise<GPUCompilationInfo> getCompilationInfo();
553 GPUShaderModule includes GPUObjectBase;
555 dictionary GPUShaderModuleDescriptor
556          : GPUObjectDescriptorBase {
557     // UTF8String is not observably different from USVString
558     required UTF8String code;
559     object sourceMap;
562 enum GPUCompilationMessageType {
563     "error",
564     "warning",
565     "info",
568 [Func="mozilla::webgpu::Instance::PrefEnabled",
569  Exposed=(Window, DedicatedWorker), SecureContext]
570 interface GPUCompilationMessage {
571     readonly attribute DOMString message;
572     readonly attribute GPUCompilationMessageType type;
573     readonly attribute unsigned long long lineNum;
574     readonly attribute unsigned long long linePos;
575     readonly attribute unsigned long long offset;
576     readonly attribute unsigned long long length;
579 [Func="mozilla::webgpu::Instance::PrefEnabled",
580  Exposed=(Window, DedicatedWorker), SecureContext]
581 interface GPUCompilationInfo {
582     [Cached, Frozen, Pure]
583     readonly attribute sequence<GPUCompilationMessage> messages;
586 enum GPUAutoLayoutMode {
587     "auto",
590 dictionary GPUPipelineDescriptorBase
591          : GPUObjectDescriptorBase {
592     required (GPUPipelineLayout or GPUAutoLayoutMode) layout;
595 interface mixin GPUPipelineBase {
596     GPUBindGroupLayout getBindGroupLayout(unsigned long index);
599 dictionary GPUProgrammableStage {
600     required GPUShaderModule module;
601     required USVString entryPoint;
604 //TODO: Serializable
605 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
606 [Func="mozilla::webgpu::Instance::PrefEnabled",
607  Exposed=(Window, DedicatedWorker), SecureContext]
608 interface GPUComputePipeline {
610 GPUComputePipeline includes GPUObjectBase;
611 GPUComputePipeline includes GPUPipelineBase;
613 dictionary GPUComputePipelineDescriptor
614          : GPUPipelineDescriptorBase {
615     required GPUProgrammableStage compute;
618 //TODO: Serializable
619 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
620 [Func="mozilla::webgpu::Instance::PrefEnabled",
621  Exposed=(Window, DedicatedWorker), SecureContext]
622 interface GPURenderPipeline {
624 GPURenderPipeline includes GPUObjectBase;
625 GPURenderPipeline includes GPUPipelineBase;
627 dictionary GPURenderPipelineDescriptor
628          : GPUPipelineDescriptorBase {
629     required GPUVertexState vertex;
630     GPUPrimitiveState primitive = {};
631     GPUDepthStencilState depthStencil;
632     GPUMultisampleState multisample = {};
633     GPUFragmentState fragment;
636 dictionary GPUPrimitiveState {
637     GPUPrimitiveTopology topology = "triangle-list";
638     GPUIndexFormat stripIndexFormat;
639     GPUFrontFace frontFace = "ccw";
640     GPUCullMode cullMode = "none";
642     // Requires "depth-clip-control" feature.
643     boolean unclippedDepth = false;
646 enum GPUPrimitiveTopology {
647     "point-list",
648     "line-list",
649     "line-strip",
650     "triangle-list",
651     "triangle-strip",
654 enum GPUFrontFace {
655     "ccw",
656     "cw",
659 enum GPUCullMode {
660     "none",
661     "front",
662     "back",
665 dictionary GPUMultisampleState {
666     GPUSize32 count = 1;
667     GPUSampleMask mask = 0xFFFFFFFF;
668     boolean alphaToCoverageEnabled = false;
671 dictionary GPUFragmentState
672          : GPUProgrammableStage {
673     required sequence<GPUColorTargetState> targets;
676 dictionary GPUColorTargetState {
677     required GPUTextureFormat format;
679     GPUBlendState blend;
680     GPUColorWriteFlags writeMask = 0xF;  // GPUColorWrite.ALL
683 dictionary GPUBlendState {
684     required GPUBlendComponent color;
685     required GPUBlendComponent alpha;
688 typedef [EnforceRange] unsigned long GPUColorWriteFlags;
689 [Func="mozilla::webgpu::Instance::PrefEnabled",
690  Exposed=(Window, DedicatedWorker), SecureContext]
691 interface GPUColorWrite {
692     const GPUFlagsConstant RED   = 0x1;
693     const GPUFlagsConstant GREEN = 0x2;
694     const GPUFlagsConstant BLUE  = 0x4;
695     const GPUFlagsConstant ALPHA = 0x8;
696     const GPUFlagsConstant ALL   = 0xF;
699 dictionary GPUBlendComponent {
700     GPUBlendOperation operation = "add";
701     GPUBlendFactor srcFactor = "one";
702     GPUBlendFactor dstFactor = "zero";
705 enum GPUBlendFactor {
706     "zero",
707     "one",
708     "src",
709     "one-minus-src",
710     "src-alpha",
711     "one-minus-src-alpha",
712     "dst",
713     "one-minus-dst",
714     "dst-alpha",
715     "one-minus-dst-alpha",
716     "src-alpha-saturated",
717     "constant",
718     "one-minus-constant",
721 enum GPUBlendOperation {
722     "add",
723     "subtract",
724     "reverse-subtract",
725     "min",
726     "max",
729 dictionary GPUDepthStencilState {
730     required GPUTextureFormat format;
732     boolean depthWriteEnabled = false;
733     GPUCompareFunction depthCompare = "always";
735     GPUStencilFaceState stencilFront = {};
736     GPUStencilFaceState stencilBack = {};
738     GPUStencilValue stencilReadMask = 0xFFFFFFFF;
739     GPUStencilValue stencilWriteMask = 0xFFFFFFFF;
741     GPUDepthBias depthBias = 0;
742     float depthBiasSlopeScale = 0;
743     float depthBiasClamp = 0;
746 dictionary GPUStencilFaceState {
747     GPUCompareFunction compare = "always";
748     GPUStencilOperation failOp = "keep";
749     GPUStencilOperation depthFailOp = "keep";
750     GPUStencilOperation passOp = "keep";
753 enum GPUStencilOperation {
754     "keep",
755     "zero",
756     "replace",
757     "invert",
758     "increment-clamp",
759     "decrement-clamp",
760     "increment-wrap",
761     "decrement-wrap",
764 enum GPUIndexFormat {
765     "uint16",
766     "uint32",
769 enum GPUVertexFormat {
770     "uint8x2",
771     "uint8x4",
772     "sint8x2",
773     "sint8x4",
774     "unorm8x2",
775     "unorm8x4",
776     "snorm8x2",
777     "snorm8x4",
778     "uint16x2",
779     "uint16x4",
780     "sint16x2",
781     "sint16x4",
782     "unorm16x2",
783     "unorm16x4",
784     "snorm16x2",
785     "snorm16x4",
786     "float16x2",
787     "float16x4",
788     "float32",
789     "float32x2",
790     "float32x3",
791     "float32x4",
792     "uint32",
793     "uint32x2",
794     "uint32x3",
795     "uint32x4",
796     "sint32",
797     "sint32x2",
798     "sint32x3",
799     "sint32x4",
802 enum GPUVertexStepMode {
803     "vertex",
804     "instance",
807 dictionary GPUVertexState
808          : GPUProgrammableStage {
809     sequence<GPUVertexBufferLayout?> buffers = [];
812 dictionary GPUVertexBufferLayout {
813     required GPUSize64 arrayStride;
814     GPUVertexStepMode stepMode = "vertex";
815     required sequence<GPUVertexAttribute> attributes;
818 dictionary GPUVertexAttribute {
819     required GPUVertexFormat format;
820     required GPUSize64 offset;
822     required GPUIndex32 shaderLocation;
825 dictionary GPUImageDataLayout {
826     GPUSize64 offset = 0;
827     GPUSize32 bytesPerRow;
828     GPUSize32 rowsPerImage;
831 dictionary GPUImageCopyBuffer
832          : GPUImageDataLayout {
833     required GPUBuffer buffer;
836 dictionary GPUImageCopyTexture {
837     required GPUTexture texture;
838     GPUIntegerCoordinate mipLevel = 0;
839     GPUOrigin3D origin;
840     GPUTextureAspect aspect = "all";
843 dictionary GPUImageCopyTextureTagged
844          : GPUImageCopyTexture {
845     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
846     boolean premultipliedAlpha = false;
849 dictionary GPUImageCopyExternalImage {
850     required (ImageBitmap or HTMLCanvasElement or OffscreenCanvas) source;
851     GPUOrigin2D origin = {};
852     boolean flipY = false;
855 [Func="mozilla::webgpu::Instance::PrefEnabled",
856  Exposed=(Window, DedicatedWorker), SecureContext]
857 interface GPUCommandBuffer {
859 GPUCommandBuffer includes GPUObjectBase;
861 dictionary GPUCommandBufferDescriptor
862          : GPUObjectDescriptorBase {
865 interface mixin GPUCommandsMixin {
868 [Func="mozilla::webgpu::Instance::PrefEnabled",
869  Exposed=(Window, DedicatedWorker), SecureContext]
870 interface GPUCommandEncoder {
871     GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor);
872     GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor = {});
874     undefined copyBufferToBuffer(
875         GPUBuffer source,
876         GPUSize64 sourceOffset,
877         GPUBuffer destination,
878         GPUSize64 destinationOffset,
879         GPUSize64 size);
881     undefined copyBufferToTexture(
882         GPUImageCopyBuffer source,
883         GPUImageCopyTexture destination,
884         GPUExtent3D copySize);
886     undefined copyTextureToBuffer(
887         GPUImageCopyTexture source,
888         GPUImageCopyBuffer destination,
889         GPUExtent3D copySize);
891     undefined copyTextureToTexture(
892         GPUImageCopyTexture source,
893         GPUImageCopyTexture destination,
894         GPUExtent3D copySize);
896     GPUCommandBuffer finish(optional GPUCommandBufferDescriptor descriptor = {});
898 GPUCommandEncoder includes GPUObjectBase;
899 GPUCommandEncoder includes GPUCommandsMixin;
900 GPUCommandEncoder includes GPUDebugCommandsMixin;
902 dictionary GPUCommandEncoderDescriptor
903          : GPUObjectDescriptorBase {
906 interface mixin GPUBindingCommandsMixin {
907     undefined setBindGroup(GPUIndex32 index, GPUBindGroup bindGroup,
908         optional sequence<GPUBufferDynamicOffset> dynamicOffsets = []);
911 interface mixin GPUDebugCommandsMixin {
912     undefined pushDebugGroup(USVString groupLabel);
913     undefined popDebugGroup();
914     undefined insertDebugMarker(USVString markerLabel);
917 [Func="mozilla::webgpu::Instance::PrefEnabled",
918  Exposed=(Window, DedicatedWorker), SecureContext]
919 interface GPUComputePassEncoder {
920     undefined setPipeline(GPUComputePipeline pipeline);
921     undefined dispatchWorkgroups(GPUSize32 workgroupCountX, optional GPUSize32 workgroupCountY = 1, optional GPUSize32 workgroupCountZ = 1);
922     [Pref="dom.webgpu.indirect-dispatch.enabled"]
923     undefined dispatchWorkgroupsIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
925     [Throws]
926     undefined end();
928 GPUComputePassEncoder includes GPUObjectBase;
929 GPUComputePassEncoder includes GPUCommandsMixin;
930 GPUComputePassEncoder includes GPUDebugCommandsMixin;
931 GPUComputePassEncoder includes GPUBindingCommandsMixin;
933 dictionary GPUComputePassDescriptor
934          : GPUObjectDescriptorBase {
937 [Func="mozilla::webgpu::Instance::PrefEnabled",
938  Exposed=(Window, DedicatedWorker), SecureContext]
939 interface GPURenderPassEncoder {
940     undefined setViewport(float x, float y,
941         float width, float height,
942         float minDepth, float maxDepth);
944     undefined setScissorRect(GPUIntegerCoordinate x, GPUIntegerCoordinate y,
945                         GPUIntegerCoordinate width, GPUIntegerCoordinate height);
947     undefined setBlendConstant(GPUColor color);
948     undefined setStencilReference(GPUStencilValue reference);
950     //undefined beginOcclusionQuery(GPUSize32 queryIndex);
951     //undefined endOcclusionQuery();
953     undefined executeBundles(sequence<GPURenderBundle> bundles);
954     [Throws]
955     undefined end();
957 GPURenderPassEncoder includes GPUObjectBase;
958 GPURenderPassEncoder includes GPUCommandsMixin;
959 GPURenderPassEncoder includes GPUDebugCommandsMixin;
960 GPURenderPassEncoder includes GPUBindingCommandsMixin;
961 GPURenderPassEncoder includes GPURenderCommandsMixin;
963 dictionary GPURenderPassDescriptor
964          : GPUObjectDescriptorBase {
965     required sequence<GPURenderPassColorAttachment> colorAttachments;
966     GPURenderPassDepthStencilAttachment depthStencilAttachment;
967     GPUQuerySet occlusionQuerySet;
970 dictionary GPURenderPassColorAttachment {
971     required GPUTextureView view;
972     GPUTextureView resolveTarget;
974     GPUColor clearValue;
975     required GPULoadOp loadOp;
976     required GPUStoreOp storeOp;
979 dictionary GPURenderPassDepthStencilAttachment {
980     required GPUTextureView view;
982     float depthClearValue;
983     GPULoadOp depthLoadOp;
984     GPUStoreOp depthStoreOp;
985     boolean depthReadOnly = false;
987     GPUStencilValue stencilClearValue = 0;
988     GPULoadOp stencilLoadOp;
989     GPUStoreOp stencilStoreOp;
990     boolean stencilReadOnly = false;
993 enum GPULoadOp {
994     "load",
995     "clear",
998 enum GPUStoreOp {
999     "store",
1000     "discard",
1003 dictionary GPURenderPassLayout
1004          : GPUObjectDescriptorBase {
1005     required sequence<GPUTextureFormat> colorFormats;
1006     GPUTextureFormat depthStencilFormat;
1007     GPUSize32 sampleCount = 1;
1010 interface mixin GPURenderCommandsMixin {
1011     undefined setPipeline(GPURenderPipeline pipeline);
1013     undefined setIndexBuffer(GPUBuffer buffer, GPUIndexFormat indexFormat, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
1014     undefined setVertexBuffer(GPUIndex32 slot, GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
1016     undefined draw(GPUSize32 vertexCount, optional GPUSize32 instanceCount = 1,
1017         optional GPUSize32 firstVertex = 0, optional GPUSize32 firstInstance = 0);
1018     undefined drawIndexed(GPUSize32 indexCount, optional GPUSize32 instanceCount = 1,
1019         optional GPUSize32 firstIndex = 0,
1020         optional GPUSignedOffset32 baseVertex = 0,
1021         optional GPUSize32 firstInstance = 0);
1023     [Pref="dom.webgpu.indirect-dispatch.enabled"]
1024     undefined drawIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
1025     [Pref="dom.webgpu.indirect-dispatch.enabled"]
1026     undefined drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
1029 [Func="mozilla::webgpu::Instance::PrefEnabled",
1030  Exposed=(Window, DedicatedWorker), SecureContext]
1031 interface GPURenderBundle {
1033 GPURenderBundle includes GPUObjectBase;
1035 dictionary GPURenderBundleDescriptor
1036          : GPUObjectDescriptorBase {
1039 [Func="mozilla::webgpu::Instance::PrefEnabled",
1040  Exposed=(Window, DedicatedWorker), SecureContext]
1041 interface GPURenderBundleEncoder {
1042     GPURenderBundle finish(optional GPURenderBundleDescriptor descriptor = {});
1044 GPURenderBundleEncoder includes GPUObjectBase;
1045 GPURenderBundleEncoder includes GPUCommandsMixin;
1046 GPURenderBundleEncoder includes GPUDebugCommandsMixin;
1047 GPURenderBundleEncoder includes GPUBindingCommandsMixin;
1048 GPURenderBundleEncoder includes GPURenderCommandsMixin;
1050 dictionary GPURenderBundleEncoderDescriptor
1051          : GPURenderPassLayout {
1052     boolean depthReadOnly = false;
1053     boolean stencilReadOnly = false;
1056 dictionary GPUQueueDescriptor
1057          : GPUObjectDescriptorBase {
1060 //TODO: use [AllowShared] on BufferSource
1061 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696216
1062 // https://github.com/heycam/webidl/issues/961
1064 [Func="mozilla::webgpu::Instance::PrefEnabled",
1065  Exposed=(Window, DedicatedWorker), SecureContext]
1066 interface GPUQueue {
1067     undefined submit(sequence<GPUCommandBuffer> buffers);
1069     [Throws]
1070     Promise<undefined> onSubmittedWorkDone();
1072     [Throws]
1073     undefined writeBuffer(
1074         GPUBuffer buffer,
1075         GPUSize64 bufferOffset,
1076         BufferSource data,
1077         optional GPUSize64 dataOffset = 0,
1078         optional GPUSize64 size);
1080     [Throws]
1081     undefined writeTexture(
1082         GPUImageCopyTexture destination,
1083         BufferSource data,
1084         GPUImageDataLayout dataLayout,
1085         GPUExtent3D size);
1087     [Throws]
1088     undefined copyExternalImageToTexture(
1089         GPUImageCopyExternalImage source,
1090         GPUImageCopyTextureTagged destination,
1091         GPUExtent3D copySize);
1093 GPUQueue includes GPUObjectBase;
1095 [Func="mozilla::webgpu::Instance::PrefEnabled",
1096  Exposed=(Window, DedicatedWorker), SecureContext]
1097 interface GPUQuerySet {
1098     undefined destroy();
1100 GPUQuerySet includes GPUObjectBase;
1102 dictionary GPUQuerySetDescriptor
1103          : GPUObjectDescriptorBase {
1104     required GPUQueryType type;
1105     required GPUSize32 count;
1106     sequence<GPUPipelineStatisticName> pipelineStatistics = [];
1109 enum GPUPipelineStatisticName {
1110     "vertex-shader-invocations",
1111     "clipper-invocations",
1112     "clipper-primitives-out",
1113     "fragment-shader-invocations",
1114     "compute-shader-invocations"
1117 enum GPUQueryType {
1118     "occlusion",
1119     "pipeline-statistics",
1120     "timestamp",
1123 [Func="mozilla::webgpu::Instance::PrefEnabled",
1124  Exposed=(Window, DedicatedWorker), SecureContext]
1125 interface GPUCanvasContext {
1126     readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;
1128     undefined configure(GPUCanvasConfiguration configuration);
1129     undefined unconfigure();
1131     [Throws]
1132     GPUTexture getCurrentTexture();
1135 enum GPUCanvasAlphaMode {
1136     "opaque",
1137     "premultiplied",
1140 dictionary GPUCanvasConfiguration {
1141     required GPUDevice device;
1142     required GPUTextureFormat format;
1143     GPUTextureUsageFlags usage = 0x10;  // GPUTextureUsage.RENDER_ATTACHMENT
1144     sequence<GPUTextureFormat> viewFormats = [];
1145     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
1146     GPUCanvasAlphaMode alphaMode = "opaque";
1149 enum GPUDeviceLostReason {
1150     "destroyed",
1153 [Func="mozilla::webgpu::Instance::PrefEnabled",
1154  Exposed=(Window, DedicatedWorker), SecureContext]
1155 interface GPUDeviceLostInfo {
1156     readonly attribute any reason; // GPUDeviceLostReason or undefined
1157     readonly attribute DOMString message;
1160 partial interface GPUDevice {
1161     [Throws]
1162     readonly attribute Promise<GPUDeviceLostInfo> lost;
1165 [Func="mozilla::webgpu::Instance::PrefEnabled",
1166  Exposed=(Window, DedicatedWorker), SecureContext]
1167 interface GPUError {
1168     readonly attribute DOMString message;
1171 [Func="mozilla::webgpu::Instance::PrefEnabled",
1172  Exposed=(Window, DedicatedWorker), SecureContext]
1173 interface GPUValidationError
1174         : GPUError {
1175     [Throws]
1176     constructor(DOMString message);
1179 [Func="mozilla::webgpu::Instance::PrefEnabled",
1180  Exposed=(Window, DedicatedWorker), SecureContext]
1181 interface GPUOutOfMemoryError
1182         : GPUError {
1183     [Throws]
1184     constructor(DOMString message);
1187 [Func="mozilla::webgpu::Instance::PrefEnabled",
1188  Exposed=(Window, DedicatedWorker), SecureContext]
1189 interface GPUInternalError
1190         : GPUError {
1191     [Throws]
1192     constructor(DOMString message);
1195 enum GPUErrorFilter {
1196     "validation",
1197     "out-of-memory",
1198     "internal",
1201 partial interface GPUDevice {
1202     undefined pushErrorScope(GPUErrorFilter filter);
1203     [Throws]
1204     Promise<GPUError?> popErrorScope();
1207 partial interface GPUDevice {
1208     [Exposed=(Window, DedicatedWorker)]
1209     attribute EventHandler onuncapturederror;
1212 typedef [EnforceRange] unsigned long GPUBufferDynamicOffset;
1213 typedef [EnforceRange] unsigned long GPUStencilValue;
1214 typedef [EnforceRange] unsigned long GPUSampleMask;
1215 typedef [EnforceRange] long GPUDepthBias;
1217 typedef [EnforceRange] unsigned long long GPUSize64;
1218 typedef [EnforceRange] unsigned long GPUIntegerCoordinate;
1219 typedef [EnforceRange] unsigned long GPUIndex32;
1220 typedef [EnforceRange] unsigned long GPUSize32;
1221 typedef [EnforceRange] long GPUSignedOffset32;
1223 typedef unsigned long long GPUSize64Out;
1224 typedef unsigned long GPUIntegerCoordinateOut;
1225 typedef unsigned long GPUSize32Out;
1227 typedef unsigned long GPUFlagsConstant;
1229 dictionary GPUColorDict {
1230     required double r;
1231     required double g;
1232     required double b;
1233     required double a;
1235 typedef (sequence<double> or GPUColorDict) GPUColor;
1237 dictionary GPUOrigin2DDict {
1238     GPUIntegerCoordinate x = 0;
1239     GPUIntegerCoordinate y = 0;
1241 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin2DDict) GPUOrigin2D;
1243 dictionary GPUOrigin3DDict {
1244     GPUIntegerCoordinate x = 0;
1245     GPUIntegerCoordinate y = 0;
1246     GPUIntegerCoordinate z = 0;
1248 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin3DDict) GPUOrigin3D;
1250 dictionary GPUExtent3DDict {
1251     required GPUIntegerCoordinate width;
1252     GPUIntegerCoordinate height = 1;
1253     GPUIntegerCoordinate depthOrArrayLayers = 1;
1255 typedef (sequence<GPUIntegerCoordinate> or GPUExtent3DDict) GPUExtent3D;