Bug 1814101 - Add requestAdapterInfo for webgpu. r=gfx-reviewers,webidl,jimb,smaug
[gecko.git] / dom / webidl / WebGPU.webidl
blob66f84a640e250a549c064d02b309b8692d598e9a
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 [Pref="dom.webgpu.enabled",
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 maxDynamicUniformBuffersPerPipelineLayout;
27     readonly attribute unsigned long maxDynamicStorageBuffersPerPipelineLayout;
28     readonly attribute unsigned long maxSampledTexturesPerShaderStage;
29     readonly attribute unsigned long maxSamplersPerShaderStage;
30     readonly attribute unsigned long maxStorageBuffersPerShaderStage;
31     readonly attribute unsigned long maxStorageTexturesPerShaderStage;
32     readonly attribute unsigned long maxUniformBuffersPerShaderStage;
33     readonly attribute unsigned long maxUniformBufferBindingSize;
34     readonly attribute unsigned long maxStorageBufferBindingSize;
35     readonly attribute unsigned long minUniformBufferOffsetAlignment;
36     readonly attribute unsigned long minStorageBufferOffsetAlignment;
37     readonly attribute unsigned long maxVertexBuffers;
38     readonly attribute unsigned long maxVertexAttributes;
39     readonly attribute unsigned long maxVertexBufferArrayStride;
40     readonly attribute unsigned long maxInterStageShaderComponents;
41     readonly attribute unsigned long maxComputeWorkgroupStorageSize;
42     readonly attribute unsigned long maxComputeInvocationsPerWorkgroup;
43     readonly attribute unsigned long maxComputeWorkgroupSizeX;
44     readonly attribute unsigned long maxComputeWorkgroupSizeY;
45     readonly attribute unsigned long maxComputeWorkgroupSizeZ;
46     readonly attribute unsigned long maxComputeWorkgroupsPerDimension;
49 [Pref="dom.webgpu.enabled",
50  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
51 interface GPUSupportedFeatures {
52     readonly setlike<DOMString>;
55 // ****************************************************************************
56 // INITIALIZATION
57 // ****************************************************************************
60     Pref="dom.webgpu.enabled",
61     Exposed=(Window /* ,DedicatedWorker */), SecureContext
63 interface GPU {
64     // May reject with DOMException
65     [NewObject]
66     Promise<GPUAdapter?> requestAdapter(optional GPURequestAdapterOptions options = {});
67     GPUTextureFormat getPreferredCanvasFormat();
70 // Add a "webgpu" member to Navigator/Worker that contains the global instance of a "WebGPU"
71 interface mixin GPUProvider {
72     [SameObject, Replaceable, Pref="dom.webgpu.enabled", Exposed=(Window /* ,DedicatedWorker */), SecureContext] readonly attribute GPU gpu;
75 dictionary GPURequestAdapterOptions {
76     GPUPowerPreference powerPreference;
77     boolean forceFallbackAdapter = false;
80 enum GPUPowerPreference {
81     "low-power",
82     "high-performance"
85 [Pref="dom.webgpu.enabled",
86  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
87 interface GPUAdapterInfo {
88     readonly attribute DOMString vendor;
89     readonly attribute DOMString architecture;
90     readonly attribute DOMString device;
91     readonly attribute DOMString description;
94 [Pref="dom.webgpu.enabled",
95  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
96 interface GPUAdapter {
97     [SameObject] readonly attribute GPUSupportedFeatures features;
98     [SameObject] readonly attribute GPUSupportedLimits limits;
99     readonly attribute boolean isFallbackAdapter;
101     [NewObject]
102     Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
103     [NewObject]
104     Promise<GPUAdapterInfo> requestAdapterInfo(optional sequence<DOMString> unmaskHints = []);
107 dictionary GPUDeviceDescriptor {
108     sequence<GPUFeatureName> requiredFeatures = [];
109     record<DOMString, GPUSize64> requiredLimits;
112 enum GPUFeatureName {
113     "depth-clip-control",
114     "depth24unorm-stencil8",
115     "depth32float-stencil8",
116     "pipeline-statistics-query",
117     "texture-compression-bc",
118     "texture-compression-etc2",
119     "texture-compression-astc",
120     "timestamp-query",
121     "indirect-first-instance",
124 // Device
125 [Pref="dom.webgpu.enabled",
126  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
127 interface GPUDevice: EventTarget {
128     [SameObject] readonly attribute GPUSupportedFeatures features;
129     [SameObject] readonly attribute GPUSupportedLimits limits;
131     // Overriding the name to avoid collision with `class Queue` in gcc
132     [SameObject, BinaryName="getQueue"] readonly attribute GPUQueue queue;
134     undefined destroy();
136     [NewObject, Throws]
137     GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
138     [NewObject]
139     GPUTexture createTexture(GPUTextureDescriptor descriptor);
140     [NewObject]
141     GPUSampler createSampler(optional GPUSamplerDescriptor descriptor = {});
143     GPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
144     GPUPipelineLayout createPipelineLayout(GPUPipelineLayoutDescriptor descriptor);
145     GPUBindGroup createBindGroup(GPUBindGroupDescriptor descriptor);
147     GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
148     GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
149     GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
151     [NewObject]
152     Promise<GPUComputePipeline> createComputePipelineAsync(GPUComputePipelineDescriptor descriptor);
153     [NewObject]
154     Promise<GPURenderPipeline> createRenderPipelineAsync(GPURenderPipelineDescriptor descriptor);
156     [NewObject]
157     GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
158     [NewObject]
159     GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
160     //[NewObject]
161     //GPUQuerySet createQuerySet(GPUQuerySetDescriptor descriptor);
163 GPUDevice includes GPUObjectBase;
165 // Buffer
166 [Pref="dom.webgpu.enabled",
167  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
168 interface GPUBuffer {
169     [NewObject]
170     Promise<undefined> mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size);
171     [NewObject, Throws]
172     ArrayBuffer getMappedRange(optional GPUSize64 offset = 0, optional GPUSize64 size);
173     [Throws]
174     undefined unmap();
175     [Throws]
176     undefined destroy();
178 GPUBuffer includes GPUObjectBase;
180 dictionary GPUBufferDescriptor : GPUObjectDescriptorBase {
181     required GPUSize64 size;
182     required GPUBufferUsageFlags usage;
183     boolean mappedAtCreation = false;
186 typedef [EnforceRange] unsigned long GPUBufferUsageFlags;
187 [Pref="dom.webgpu.enabled",
188  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
189 interface GPUBufferUsage {
190     const GPUBufferUsageFlags MAP_READ      = 0x0001;
191     const GPUBufferUsageFlags MAP_WRITE     = 0x0002;
192     const GPUBufferUsageFlags COPY_SRC      = 0x0004;
193     const GPUBufferUsageFlags COPY_DST      = 0x0008;
194     const GPUBufferUsageFlags INDEX         = 0x0010;
195     const GPUBufferUsageFlags VERTEX        = 0x0020;
196     const GPUBufferUsageFlags UNIFORM       = 0x0040;
197     const GPUBufferUsageFlags STORAGE       = 0x0080;
198     const GPUBufferUsageFlags INDIRECT      = 0x0100;
199     const GPUBufferUsageFlags QUERY_RESOLVE = 0x0200;
202 typedef [EnforceRange] unsigned long GPUMapModeFlags;
204 [Pref="dom.webgpu.enabled",
205  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
206 interface GPUMapMode
208     const GPUMapModeFlags READ  = 0x0001;
209     const GPUMapModeFlags WRITE = 0x0002;
212 typedef sequence<any> GPUMappedBuffer;
214 // Texture
216 [Pref="dom.webgpu.enabled",
217  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
218 interface GPUTexture {
219     [NewObject]
220     GPUTextureView createView(optional GPUTextureViewDescriptor descriptor = {});
222     undefined destroy();
224 GPUTexture includes GPUObjectBase;
226 dictionary GPUTextureDescriptor : GPUObjectDescriptorBase {
227     required GPUExtent3D size;
228     GPUIntegerCoordinate mipLevelCount = 1;
229     GPUSize32 sampleCount = 1;
230     GPUTextureDimension dimension = "2d";
231     required GPUTextureFormat format;
232     required GPUTextureUsageFlags usage;
235 enum GPUTextureDimension {
236     "1d",
237     "2d",
238     "3d",
241 typedef [EnforceRange] unsigned long GPUTextureUsageFlags;
242 [Pref="dom.webgpu.enabled",
243  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
244 interface GPUTextureUsage {
245     const GPUTextureUsageFlags COPY_SRC          = 0x01;
246     const GPUTextureUsageFlags COPY_DST          = 0x02;
247     const GPUTextureUsageFlags TEXTURE_BINDING   = 0x04;
248     const GPUTextureUsageFlags STORAGE_BINDING   = 0x08;
249     const GPUTextureUsageFlags RENDER_ATTACHMENT = 0x10;
252 enum GPUTextureComponentType {
253     "float",
254     "sint",
255     "uint",
256     "depth-comparison"
259 // Texture view
260 [Pref="dom.webgpu.enabled",
261  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
262 interface GPUTextureView {
264 GPUTextureView includes GPUObjectBase;
266 dictionary GPUTextureViewDescriptor : GPUObjectDescriptorBase {
267     GPUTextureFormat format;
268     GPUTextureViewDimension dimension;
269     GPUTextureAspect aspect = "all";
270     GPUIntegerCoordinate baseMipLevel = 0;
271     GPUIntegerCoordinate mipLevelCount;
272     GPUIntegerCoordinate baseArrayLayer = 0;
273     GPUIntegerCoordinate arrayLayerCount;
276 enum GPUTextureViewDimension {
277     "1d",
278     "2d",
279     "2d-array",
280     "cube",
281     "cube-array",
282     "3d"
285 enum GPUTextureAspect {
286     "all",
287     "stencil-only",
288     "depth-only"
291 enum GPUTextureFormat {
292     // 8-bit formats
293     "r8unorm",
294     "r8snorm",
295     "r8uint",
296     "r8sint",
298     // 16-bit formats
299     "r16uint",
300     "r16sint",
301     "r16float",
302     "rg8unorm",
303     "rg8snorm",
304     "rg8uint",
305     "rg8sint",
307     // 32-bit formats
308     "r32uint",
309     "r32sint",
310     "r32float",
311     "rg16uint",
312     "rg16sint",
313     "rg16float",
314     "rgba8unorm",
315     "rgba8unorm-srgb",
316     "rgba8snorm",
317     "rgba8uint",
318     "rgba8sint",
319     "bgra8unorm",
320     "bgra8unorm-srgb",
321     // Packed 32-bit formats
322     "rgb10a2unorm",
323     "rg11b10float",
325     // 64-bit formats
326     "rg32uint",
327     "rg32sint",
328     "rg32float",
329     "rgba16uint",
330     "rgba16sint",
331     "rgba16float",
333     // 128-bit formats
334     "rgba32uint",
335     "rgba32sint",
336     "rgba32float",
338     // Depth and stencil formats
339     //"stencil8", //TODO
340     //"depth16unorm",
341     "depth24plus",
342     "depth24plus-stencil8",
343     "depth32float",
345     // BC compressed formats usable if "texture-compression-bc" is both
346     // supported by the device/user agent and enabled in requestDevice.
347     "bc1-rgba-unorm",
348     "bc1-rgba-unorm-srgb",
349     "bc2-rgba-unorm",
350     "bc2-rgba-unorm-srgb",
351     "bc3-rgba-unorm",
352     "bc3-rgba-unorm-srgb",
353     "bc4-r-unorm",
354     "bc4-r-snorm",
355     "bc5-rg-unorm",
356     "bc5-rg-snorm",
357     "bc6h-rgb-ufloat",
358     "bc6h-rgb-float",
359     "bc7-rgba-unorm",
360     "bc7-rgba-unorm-srgb",
362     // "depth24unorm-stencil8" feature
363     //"depth24unorm-stencil8",
365     // "depth32float-stencil8" feature
366     //"depth32float-stencil8",
369 [Pref="dom.webgpu.enabled",
370  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
371 interface GPUSampler {
373 GPUSampler includes GPUObjectBase;
375 dictionary GPUSamplerDescriptor : GPUObjectDescriptorBase {
376     GPUAddressMode addressModeU = "clamp-to-edge";
377     GPUAddressMode addressModeV = "clamp-to-edge";
378     GPUAddressMode addressModeW = "clamp-to-edge";
379     GPUFilterMode magFilter = "nearest";
380     GPUFilterMode minFilter = "nearest";
381     GPUFilterMode mipmapFilter = "nearest";
382     float lodMinClamp = 0;
383     float lodMaxClamp = 1000.0; // TODO: What should this be?
384     GPUCompareFunction compare;
385     [Clamp] unsigned short maxAnisotropy = 1;
388 // Sampler
389 enum GPUAddressMode {
390     "clamp-to-edge",
391     "repeat",
392     "mirror-repeat"
395 enum GPUFilterMode {
396     "nearest",
397     "linear",
400 enum GPUCompareFunction {
401     "never",
402     "less",
403     "equal",
404     "less-equal",
405     "greater",
406     "not-equal",
407     "greater-equal",
408     "always"
411 [Pref="dom.webgpu.enabled",
412  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
413 interface GPUBindGroupLayout {
415 GPUBindGroupLayout includes GPUObjectBase;
417 dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase {
418     required sequence<GPUBindGroupLayoutEntry> entries;
421 dictionary GPUBindGroupLayoutEntry {
422     required GPUIndex32 binding;
423     required GPUShaderStageFlags visibility;
424     GPUBufferBindingLayout buffer;
425     GPUSamplerBindingLayout sampler;
426     GPUTextureBindingLayout texture;
427     GPUStorageTextureBindingLayout storageTexture;
430 typedef [EnforceRange] unsigned long GPUShaderStageFlags;
431 [Pref="dom.webgpu.enabled",
432  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
433 interface GPUShaderStage {
434     const GPUShaderStageFlags VERTEX = 1;
435     const GPUShaderStageFlags FRAGMENT = 2;
436     const GPUShaderStageFlags COMPUTE = 4;
439 enum GPUBufferBindingType {
440     "uniform",
441     "storage",
442     "read-only-storage",
445 dictionary GPUBufferBindingLayout {
446     GPUBufferBindingType type = "uniform";
447     boolean hasDynamicOffset = false;
448     GPUSize64 minBindingSize = 0;
451 enum GPUSamplerBindingType {
452     "filtering",
453     "non-filtering",
454     "comparison",
457 dictionary GPUSamplerBindingLayout {
458     GPUSamplerBindingType type = "filtering";
461 enum GPUTextureSampleType {
462   "float",
463   "unfilterable-float",
464   "depth",
465   "sint",
466   "uint",
469 dictionary GPUTextureBindingLayout {
470     GPUTextureSampleType sampleType = "float";
471     GPUTextureViewDimension viewDimension = "2d";
472     boolean multisampled = false;
475 enum GPUStorageTextureAccess {
476     "write-only",
479 dictionary GPUStorageTextureBindingLayout {
480     GPUStorageTextureAccess access = "write-only";
481     required GPUTextureFormat format;
482     GPUTextureViewDimension viewDimension = "2d";
485 [Pref="dom.webgpu.enabled",
486  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
487 interface GPUBindGroup {
489 GPUBindGroup includes GPUObjectBase;
491 dictionary GPUBindGroupDescriptor : GPUObjectDescriptorBase {
492     required GPUBindGroupLayout layout;
493     required sequence<GPUBindGroupEntry> entries;
496 typedef (GPUSampler or GPUTextureView or GPUBufferBinding) GPUBindingResource;
498 dictionary GPUBindGroupEntry {
499     required GPUIndex32 binding;
500     required GPUBindingResource resource;
503 dictionary GPUBufferBinding {
504     required GPUBuffer buffer;
505     GPUSize64 offset = 0;
506     GPUSize64 size;
509 // PipelineLayout
510 [Pref="dom.webgpu.enabled",
511  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
512 interface GPUPipelineLayout {
514 GPUPipelineLayout includes GPUObjectBase;
516 dictionary GPUPipelineLayoutDescriptor : GPUObjectDescriptorBase {
517     required sequence<GPUBindGroupLayout> bindGroupLayouts;
520 // ShaderModule
521 [Pref="dom.webgpu.enabled",
522  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
523 interface GPUShaderModule {
524     [Throws]
525     Promise<GPUCompilationInfo> compilationInfo();
527 GPUShaderModule includes GPUObjectBase;
529 dictionary GPUShaderModuleDescriptor : GPUObjectDescriptorBase {
530     // UTF8String is not observably different from USVString
531     required UTF8String code;
532     object sourceMap;
535 enum GPUCompilationMessageType {
536     "error",
537     "warning",
538     "info"
541 [Pref="dom.webgpu.enabled",
542  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
543 interface GPUCompilationMessage {
544     readonly attribute DOMString message;
545     readonly attribute GPUCompilationMessageType type;
546     readonly attribute unsigned long long lineNum;
547     readonly attribute unsigned long long linePos;
548     readonly attribute unsigned long long offset;
549     readonly attribute unsigned long long length;
552 [Pref="dom.webgpu.enabled",
553  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
554 interface GPUCompilationInfo {
555     [Cached, Frozen, Pure]
556     readonly attribute sequence<GPUCompilationMessage> messages;
559 // Common stuff for ComputePipeline and RenderPipeline
560 dictionary GPUPipelineDescriptorBase : GPUObjectDescriptorBase {
561     GPUPipelineLayout layout;
564 interface mixin GPUPipelineBase {
565     GPUBindGroupLayout getBindGroupLayout(unsigned long index);
568 dictionary GPUProgrammableStage {
569     required GPUShaderModule module;
570     required USVString entryPoint;
573 //TODO: Serializable
574 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
575 [Pref="dom.webgpu.enabled",
576  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
577 interface GPUComputePipeline {
579 GPUComputePipeline includes GPUObjectBase;
580 GPUComputePipeline includes GPUPipelineBase;
582 // ComputePipeline
583 dictionary GPUComputePipelineDescriptor : GPUPipelineDescriptorBase {
584     required GPUProgrammableStage compute;
587 //TODO: Serializable
588 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696219
589 [Pref="dom.webgpu.enabled",
590  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
591 interface GPURenderPipeline {
593 GPURenderPipeline includes GPUObjectBase;
594 GPURenderPipeline includes GPUPipelineBase;
596 dictionary GPURenderPipelineDescriptor : GPUPipelineDescriptorBase {
597     required GPUVertexState vertex;
598     GPUPrimitiveState primitive = {};
599     GPUDepthStencilState depthStencil;
600     GPUMultisampleState multisample = {};
601     GPUFragmentState fragment;
604 dictionary GPUPrimitiveState {
605     GPUPrimitiveTopology topology = "triangle-list";
606     GPUIndexFormat stripIndexFormat;
607     GPUFrontFace frontFace = "ccw";
608     GPUCullMode cullMode = "none";
609     // Enable depth clamping (requires "depth-clamping" feature)
610     boolean clampDepth = false;
613 enum GPUPrimitiveTopology {
614     "point-list",
615     "line-list",
616     "line-strip",
617     "triangle-list",
618     "triangle-strip"
621 enum GPUFrontFace {
622     "ccw",
623     "cw"
626 enum GPUCullMode {
627     "none",
628     "front",
629     "back"
632 dictionary GPUMultisampleState {
633     GPUSize32 count = 1;
634     GPUSampleMask mask = 0xFFFFFFFF;
635     boolean alphaToCoverageEnabled = false;
638 dictionary GPUFragmentState: GPUProgrammableStage {
639     required sequence<GPUColorTargetState> targets;
642 dictionary GPUColorTargetState {
643     required GPUTextureFormat format;
644     GPUBlendState blend;
645     GPUColorWriteFlags writeMask = 0xF;  // GPUColorWrite.ALL
648 dictionary GPUBlendState {
649     required GPUBlendComponent color;
650     required GPUBlendComponent alpha;
653 typedef [EnforceRange] unsigned long GPUColorWriteFlags;
654 [Pref="dom.webgpu.enabled",
655  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
656 interface GPUColorWrite {
657     const GPUColorWriteFlags RED    = 0x1;
658     const GPUColorWriteFlags GREEN  = 0x2;
659     const GPUColorWriteFlags BLUE   = 0x4;
660     const GPUColorWriteFlags ALPHA  = 0x8;
661     const GPUColorWriteFlags ALL    = 0xF;
664 dictionary GPUBlendComponent {
665     GPUBlendFactor srcFactor = "one";
666     GPUBlendFactor dstFactor = "zero";
667     GPUBlendOperation operation = "add";
670 enum GPUBlendFactor {
671     "zero",
672     "one",
673     "src",
674     "one-minus-src",
675     "src-alpha",
676     "one-minus-src-alpha",
677     "dst",
678     "one-minus-dst",
679     "dst-alpha",
680     "one-minus-dst-alpha",
681     "src-alpha-saturated",
682     "constant",
683     "one-minus-constant",
686 enum GPUBlendOperation {
687     "add",
688     "subtract",
689     "reverse-subtract",
690     "min",
691     "max"
694 dictionary GPUDepthStencilState {
695     required GPUTextureFormat format;
697     boolean depthWriteEnabled = false;
698     GPUCompareFunction depthCompare = "always";
700     GPUStencilFaceState stencilFront = {};
701     GPUStencilFaceState stencilBack = {};
703     GPUStencilValue stencilReadMask = 0xFFFFFFFF;
704     GPUStencilValue stencilWriteMask = 0xFFFFFFFF;
706     GPUDepthBias depthBias = 0;
707     float depthBiasSlopeScale = 0;
708     float depthBiasClamp = 0;
711 dictionary GPUStencilFaceState {
712     GPUCompareFunction compare = "always";
713     GPUStencilOperation failOp = "keep";
714     GPUStencilOperation depthFailOp = "keep";
715     GPUStencilOperation passOp = "keep";
718 enum GPUStencilOperation {
719     "keep",
720     "zero",
721     "replace",
722     "invert",
723     "increment-clamp",
724     "decrement-clamp",
725     "increment-wrap",
726     "decrement-wrap"
729 enum GPUIndexFormat {
730     "uint16",
731     "uint32",
734 enum GPUVertexFormat {
735     "uint8x2",
736     "uint8x4",
737     "sint8x2",
738     "sint8x4",
739     "unorm8x2",
740     "unorm8x4",
741     "snorm8x2",
742     "snorm8x4",
743     "uint16x2",
744     "uint16x4",
745     "sint16x2",
746     "sint16x4",
747     "unorm16x2",
748     "unorm16x4",
749     "snorm16x2",
750     "snorm16x4",
751     "float16x2",
752     "float16x4",
753     "float32",
754     "float32x2",
755     "float32x3",
756     "float32x4",
757     "uint32",
758     "uint32x2",
759     "uint32x3",
760     "uint32x4",
761     "sint32",
762     "sint32x2",
763     "sint32x3",
764     "sint32x4",
767 enum GPUVertexStepMode {
768     "vertex",
769     "instance",
772 dictionary GPUVertexState: GPUProgrammableStage {
773     sequence<GPUVertexBufferLayout?> buffers = [];
776 dictionary GPUVertexBufferLayout {
777     required GPUSize64 arrayStride;
778     GPUVertexStepMode stepMode = "vertex";
779     required sequence<GPUVertexAttribute> attributes;
782 dictionary GPUVertexAttribute {
783     required GPUVertexFormat format;
784     required GPUSize64 offset;
785     required GPUIndex32 shaderLocation;
788 dictionary GPUImageDataLayout {
789     GPUSize64 offset = 0;
790     required GPUSize32 bytesPerRow;
791     GPUSize32 rowsPerImage = 0;
794 dictionary GPUImageCopyBuffer : GPUImageDataLayout {
795     required GPUBuffer buffer;
798 dictionary GPUImageCopyExternalImage {
799     required (ImageBitmap or HTMLCanvasElement or OffscreenCanvas) source;
800     GPUOrigin2D origin = {};
801     boolean flipY = false;
804 dictionary GPUImageCopyTexture {
805     required GPUTexture texture;
806     GPUIntegerCoordinate mipLevel = 0;
807     GPUOrigin3D origin;
808     GPUTextureAspect aspect = "all";
811 dictionary GPUImageCopyTextureTagged : GPUImageCopyTexture {
812     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
813     boolean premultipliedAlpha = false;
816 dictionary GPUImageBitmapCopyView {
817     //required ImageBitmap imageBitmap; //TODO
818     GPUOrigin2D origin;
821 [Pref="dom.webgpu.enabled",
822  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
823 interface GPUCommandBuffer {
825 GPUCommandBuffer includes GPUObjectBase;
827 // Command Buffer
828 dictionary GPUCommandBufferDescriptor : GPUObjectDescriptorBase {
831 [Pref="dom.webgpu.enabled",
832  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
833 interface GPUCommandEncoder {
834     [NewObject]
835     GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor = {});
836     [NewObject]
837     GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor);
839     undefined copyBufferToBuffer(
840         GPUBuffer source,
841         GPUSize64 sourceOffset,
842         GPUBuffer destination,
843         GPUSize64 destinationOffset,
844         GPUSize64 size);
846     undefined copyBufferToTexture(
847         GPUImageCopyBuffer source,
848         GPUImageCopyTexture destination,
849         GPUExtent3D copySize);
851     undefined copyTextureToBuffer(
852         GPUImageCopyTexture source,
853         GPUImageCopyBuffer destination,
854         GPUExtent3D copySize);
856     undefined copyTextureToTexture(
857         GPUImageCopyTexture source,
858         GPUImageCopyTexture destination,
859         GPUExtent3D copySize);
861     /*
862     undefined copyImageBitmapToTexture(
863         GPUImageBitmapCopyView source,
864         GPUImageCopyTexture destination,
865         GPUExtent3D copySize);
866     */
868     undefined pushDebugGroup(USVString groupLabel);
869     undefined popDebugGroup();
870     undefined insertDebugMarker(USVString markerLabel);
872     [NewObject]
873     GPUCommandBuffer finish(optional GPUCommandBufferDescriptor descriptor = {});
875 GPUCommandEncoder includes GPUObjectBase;
877 dictionary GPUCommandEncoderDescriptor : GPUObjectDescriptorBase {
880 interface mixin GPUProgrammablePassEncoder {
881     undefined setBindGroup(GPUIndex32 index, GPUBindGroup bindGroup,
882                            optional sequence<GPUBufferDynamicOffset> dynamicOffsets = []);
884     undefined pushDebugGroup(USVString groupLabel);
885     undefined popDebugGroup();
886     undefined insertDebugMarker(USVString markerLabel);
889 [Pref="dom.webgpu.enabled",
890  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
891 interface GPUComputePassEncoder {
892     undefined setPipeline(GPUComputePipeline pipeline);
893     undefined dispatchWorkgroups(GPUSize32 x, optional GPUSize32 y = 1, optional GPUSize32 z = 1);
894     [Pref="dom.webgpu.indirect-dispatch.enabled"]
895     undefined dispatchWorkgroupsIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
897     [Throws]
898     undefined endPass();
900 GPUComputePassEncoder includes GPUObjectBase;
901 GPUComputePassEncoder includes GPUProgrammablePassEncoder;
903 dictionary GPUComputePassDescriptor : GPUObjectDescriptorBase {
906 interface mixin GPURenderEncoderBase {
907     undefined setPipeline(GPURenderPipeline pipeline);
909     undefined setIndexBuffer(GPUBuffer buffer, GPUIndexFormat indexFormat, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
910     undefined setVertexBuffer(GPUIndex32 slot, GPUBuffer buffer, optional GPUSize64 offset = 0, optional GPUSize64 size = 0);
912     undefined draw(GPUSize32 vertexCount,
913                    optional GPUSize32 instanceCount = 1,
914                    optional GPUSize32 firstVertex = 0,
915                    optional GPUSize32 firstInstance = 0);
916     undefined drawIndexed(GPUSize32 indexCount,
917                           optional GPUSize32 instanceCount = 1,
918                           optional GPUSize32 firstIndex = 0,
919                           optional GPUSignedOffset32 baseVertex = 0,
920                           optional GPUSize32 firstInstance = 0);
922     [Pref="dom.webgpu.indirect-dispatch.enabled"]
923     undefined drawIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
924     [Pref="dom.webgpu.indirect-dispatch.enabled"]
925     undefined drawIndexedIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
928 [Pref="dom.webgpu.enabled",
929  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
930 interface GPURenderPassEncoder {
931     undefined setViewport(float x, float y,
932                           float width, float height,
933                           float minDepth, float maxDepth);
935     undefined setScissorRect(GPUIntegerCoordinate x, GPUIntegerCoordinate y,
936                              GPUIntegerCoordinate width, GPUIntegerCoordinate height);
938     undefined setBlendConstant(GPUColor color);
939     undefined setStencilReference(GPUStencilValue reference);
941     //undefined beginOcclusionQuery(GPUSize32 queryIndex);
942     //undefined endOcclusionQuery();
944     //undefined beginPipelineStatisticsQuery(GPUQuerySet querySet, GPUSize32 queryIndex);
945     //undefined endPipelineStatisticsQuery();
947     //undefined writeTimestamp(GPUQuerySet querySet, GPUSize32 queryIndex);
949     undefined executeBundles(sequence<GPURenderBundle> bundles);
951     [Throws]
952     undefined endPass();
954 GPURenderPassEncoder includes GPUObjectBase;
955 GPURenderPassEncoder includes GPUProgrammablePassEncoder;
956 GPURenderPassEncoder includes GPURenderEncoderBase;
958 dictionary GPURenderPassDescriptor : GPUObjectDescriptorBase {
959     required sequence<GPURenderPassColorAttachment> colorAttachments;
960     GPURenderPassDepthStencilAttachment depthStencilAttachment;
961     GPUQuerySet occlusionQuerySet;
964 dictionary GPURenderPassColorAttachment {
965     required GPUTextureView view;
966     GPUTextureView resolveTarget;
968     required (GPULoadOp or GPUColor) loadValue;
969     required GPUStoreOp storeOp;
972 dictionary GPURenderPassDepthStencilAttachment {
973     required GPUTextureView view;
975     required (GPULoadOp or float) depthLoadValue;
976     required GPUStoreOp depthStoreOp;
978     required (GPULoadOp or GPUStencilValue) stencilLoadValue;
979     required GPUStoreOp stencilStoreOp;
982 enum GPULoadOp {
983     "load"
986 enum GPUStoreOp {
987     "store",
988     "discard"
991 dictionary GPURenderPassLayout: GPUObjectDescriptorBase {
992     required sequence<GPUTextureFormat> colorFormats;
993     GPUTextureFormat depthStencilFormat;
994     GPUSize32 sampleCount = 1;
997 [Pref="dom.webgpu.enabled",
998  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
999 interface GPURenderBundle {
1001 GPURenderBundle includes GPUObjectBase;
1003 dictionary GPURenderBundleDescriptor : GPUObjectDescriptorBase {
1006 [Pref="dom.webgpu.enabled",
1007  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1008 interface GPURenderBundleEncoder {
1009     GPURenderBundle finish(optional GPURenderBundleDescriptor descriptor = {});
1011 GPURenderBundleEncoder includes GPUObjectBase;
1012 GPURenderBundleEncoder includes GPUProgrammablePassEncoder;
1013 GPURenderBundleEncoder includes GPURenderEncoderBase;
1015 dictionary GPURenderBundleEncoderDescriptor : GPURenderPassLayout {
1016     boolean depthReadOnly = false;
1017     boolean stencilReadOnly = false;
1020 //TODO: use [AllowShared] on BufferSource
1021 // https://bugzilla.mozilla.org/show_bug.cgi?id=1696216
1022 // https://github.com/heycam/webidl/issues/961
1024 [Pref="dom.webgpu.enabled",
1025  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1026 interface GPUQueue {
1027     undefined submit(sequence<GPUCommandBuffer> buffers);
1029     //TODO:
1030     //Promise<undefined> onSubmittedWorkDone();
1032     [Throws]
1033     undefined writeBuffer(
1034         GPUBuffer buffer,
1035         GPUSize64 bufferOffset,
1036         BufferSource data,
1037         optional GPUSize64 dataOffset = 0,
1038         optional GPUSize64 size);
1040     [Throws]
1041     undefined writeTexture(
1042       GPUImageCopyTexture destination,
1043       BufferSource data,
1044       GPUImageDataLayout dataLayout,
1045       GPUExtent3D size);
1047     [Throws]
1048     undefined copyExternalImageToTexture(
1049       GPUImageCopyExternalImage source,
1050       GPUImageCopyTextureTagged destination,
1051       GPUExtent3D copySize);
1053 GPUQueue includes GPUObjectBase;
1055 [Pref="dom.webgpu.enabled",
1056  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1057 interface GPUQuerySet {
1058     undefined destroy();
1060 GPUQuerySet includes GPUObjectBase;
1062 dictionary GPUQuerySetDescriptor : GPUObjectDescriptorBase {
1063     required GPUQueryType type;
1064     required GPUSize32 count;
1065     sequence<GPUPipelineStatisticName> pipelineStatistics = [];
1068 enum GPUPipelineStatisticName {
1069     "vertex-shader-invocations",
1070     "clipper-invocations",
1071     "clipper-primitives-out",
1072     "fragment-shader-invocations",
1073     "compute-shader-invocations"
1076 enum GPUQueryType {
1077     "occlusion",
1078     "pipeline-statistics",
1079     "timestamp"
1082 [Pref="dom.webgpu.enabled",
1083  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1084 interface GPUCanvasContext {
1085     // Calling configure() a second time invalidates the previous one,
1086     // and all of the textures it's produced.
1087     undefined configure(GPUCanvasConfiguration descriptor);
1088     undefined unconfigure();
1090     [Throws]
1091     GPUTexture getCurrentTexture();
1094 enum GPUCanvasCompositingAlphaMode {
1095     "opaque",
1096     "premultiplied",
1099 dictionary GPUCanvasConfiguration {
1100     required GPUDevice device;
1101     required GPUTextureFormat format;
1102     GPUTextureUsageFlags usage = 0x10; //GPUTextureUsage.OUTPUT_ATTACHMENT
1103     //GPUPredefinedColorSpace colorSpace = "srgb"; //TODO
1104     GPUCanvasCompositingAlphaMode compositingAlphaMode = "opaque";
1107 enum GPUDeviceLostReason {
1108     "destroyed",
1111 [Pref="dom.webgpu.enabled",
1112  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1113 interface GPUDeviceLostInfo {
1114     readonly attribute any reason; // GPUDeviceLostReason or undefined
1115     readonly attribute DOMString message;
1118 partial interface GPUDevice {
1119     [Throws]
1120     readonly attribute Promise<GPUDeviceLostInfo> lost;
1121     undefined pushErrorScope(GPUErrorFilter filter);
1122     [NewObject]
1123     Promise<GPUError?> popErrorScope();
1124     [Exposed=(Window /* ,DedicatedWorker */)]
1125     attribute EventHandler onuncapturederror;
1128 [Pref="dom.webgpu.enabled",
1129  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1130 interface GPUOutOfMemoryError {
1131     //constructor();
1134 [Pref="dom.webgpu.enabled",
1135  Exposed=(Window /* ,DedicatedWorker */), SecureContext]
1136 interface GPUValidationError {
1137     [Throws]
1138     constructor(DOMString message);
1139     readonly attribute DOMString message;
1142 typedef (GPUOutOfMemoryError or GPUValidationError) GPUError;
1144 enum GPUErrorFilter {
1145     "out-of-memory",
1146     "validation"
1149 typedef [EnforceRange] unsigned long GPUBufferDynamicOffset;
1150 typedef [EnforceRange] unsigned long GPUStencilValue;
1151 typedef [EnforceRange] unsigned long GPUSampleMask;
1152 typedef [EnforceRange] long GPUDepthBias;
1154 typedef [EnforceRange] unsigned long long GPUSize64;
1155 typedef [EnforceRange] unsigned long GPUIntegerCoordinate;
1156 typedef [EnforceRange] unsigned long GPUIndex32;
1157 typedef [EnforceRange] unsigned long GPUSize32;
1158 typedef [EnforceRange] long GPUSignedOffset32;
1160 dictionary GPUColorDict {
1161     required double r;
1162     required double g;
1163     required double b;
1164     required double a;
1166 typedef (sequence<double> or GPUColorDict) GPUColor;
1168 dictionary GPUOrigin2DDict {
1169     GPUIntegerCoordinate x = 0;
1170     GPUIntegerCoordinate y = 0;
1172 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin2DDict) GPUOrigin2D;
1174 dictionary GPUOrigin3DDict {
1175     GPUIntegerCoordinate x = 0;
1176     GPUIntegerCoordinate y = 0;
1177     GPUIntegerCoordinate z = 0;
1179 typedef (sequence<GPUIntegerCoordinate> or GPUOrigin3DDict) GPUOrigin3D;
1181 dictionary GPUExtent3DDict {
1182     required GPUIntegerCoordinate width;
1183     GPUIntegerCoordinate height = 1;
1184     GPUIntegerCoordinate depthOrArrayLayers = 1;
1186 typedef (sequence<GPUIntegerCoordinate> or GPUExtent3DDict) GPUExtent3D;