UNPKG

@webgpu/types

Version:

This package defines Typescript types (`.d.ts`) for the upcoming [WebGPU standard](https://github.com/gpuweb/gpuweb/wiki/Implementation-Status).

1,574 lines (1,470 loc) 118 kB
// ********************************************************************************************* // This file is manually-edited by diffing against an autogenerated file. See README.md. // ********************************************************************************************* // ********************************************************************************************* // Manually-written - auto copied from extra.d.ts // ********************************************************************************************* // AllowSharedBufferSource wasn't introduced until TypeScript 5.2. // But it also didn't include SharedArrayBuffer in the union. // This broke in ES2024 when ArrayBuffer gained some properties that SharedArrayBuffer didn't. // So, we use our own definition for AllowSharedBufferSource. type GPUAllowSharedBufferSource = | BufferSource | SharedArrayBuffer; // Stronger typing for getContext() interface HTMLCanvasElement { getContext( contextId: | "webgpu" ): GPUCanvasContext | null; } interface OffscreenCanvas { getContext( contextId: | "webgpu" ): GPUCanvasContext | null; } // Defined as an empty interface here to prevent errors when using these types in a worker. interface HTMLVideoElement {} // Strict types defined to help developers catch a common class of errors. // This interface defines depth as an undefined, which will cause a type check failure if someone // attempts to set depth rather than depthOrArrayLayers on a GPUExtent3D (an easy mistake to make.) type GPUOrigin2DStrict = | Iterable<GPUIntegerCoordinate> | GPUOrigin2DDictStrict; interface GPUOrigin2DDictStrict extends GPUOrigin2DDict { /** @deprecated Does not exist for GPUOrigin2D. */ z?: undefined; } type GPUExtent3DStrict = | Iterable<GPUIntegerCoordinate> | GPUExtent3DDictStrict; interface GPUExtent3DDictStrict extends GPUExtent3DDict { /** @deprecated The correct name is `depthOrArrayLayers`. */ depth?: undefined; } // Stronger typing for event listeners. /** @internal */ interface __GPUDeviceEventMap { uncapturederror: GPUUncapturedErrorEvent; } // Extensions to the generated definition below. interface GPUDevice { addEventListener< K extends keyof __GPUDeviceEventMap >( type: K, listener: ( this: GPUDevice, ev: __GPUDeviceEventMap[K] ) => any, options?: | boolean | AddEventListenerOptions ): void; addEventListener( type: string, listener: EventListenerOrEventListenerObject, options?: | boolean | AddEventListenerOptions ): void; removeEventListener< K extends keyof __GPUDeviceEventMap >( type: K, listener: ( this: GPUDevice, ev: __GPUDeviceEventMap[K] ) => any, options?: | boolean | EventListenerOptions ): void; removeEventListener( type: string, listener: EventListenerOrEventListenerObject, options?: | boolean | EventListenerOptions ): void; } interface GPUCanvasConfigurationOut extends Required< Omit< GPUCanvasConfiguration, "toneMapping" > > { /** {@inheritDoc GPUCanvasConfiguration.viewFormats} */ viewFormats: GPUTextureFormat[]; /** * {@inheritDoc GPUCanvasConfiguration.toneMapping} */ toneMapping?: GPUCanvasToneMapping; } /** @deprecated Use {@link GPUTexelCopyBufferLayout} */ type GPUImageDataLayout = GPUTexelCopyBufferLayout; /** @deprecated Use {@link GPUTexelCopyBufferInfo} */ type GPUImageCopyBuffer = GPUTexelCopyBufferInfo; /** @deprecated Use {@link GPUTexelCopyTextureInfo} */ type GPUImageCopyTexture = GPUTexelCopyTextureInfo; /** @deprecated Use {@link GPUCopyExternalImageDestInfo} */ type GPUImageCopyTextureTagged = GPUCopyExternalImageDestInfo; /** @deprecated Use {@link GPUCopyExternalImageSourceInfo} */ type GPUImageCopyExternalImage = GPUCopyExternalImageSourceInfo; /** @deprecated Use {@link GPUCopyExternalImageSource} */ type GPUImageCopyExternalImageSource = GPUCopyExternalImageSource; // ********************************************************************************************* // Semi-auto-generated (by manual diff with autogenerated types) // ********************************************************************************************* type GPUBindingResource = | GPUSampler | GPUTexture | GPUTextureView | GPUBuffer | GPUBufferBinding | GPUExternalTexture; type GPUBufferDynamicOffset = number; type GPUBufferUsageFlags = number; type GPUColor = | Iterable<number> | GPUColorDict; type GPUColorWriteFlags = number; type GPUCopyExternalImageSource = | ImageBitmap | ImageData | HTMLImageElement | HTMLVideoElement | VideoFrame | HTMLCanvasElement | OffscreenCanvas; type GPUDepthBias = number; type GPUExtent3D = | Iterable<GPUIntegerCoordinate> | GPUExtent3DDict; type GPUFlagsConstant = number; type GPUIndex32 = number; type GPUIntegerCoordinate = number; type GPUIntegerCoordinateOut = number; type GPUMapModeFlags = number; type GPUOrigin2D = | Iterable<GPUIntegerCoordinate> | GPUOrigin2DDict; type GPUOrigin3D = | Iterable<GPUIntegerCoordinate> | GPUOrigin3DDict; type GPUPipelineConstantValue = number; type GPUSampleMask = number; type GPUShaderStageFlags = number; type GPUSignedOffset32 = number; type GPUSize32 = number; type GPUSize32Out = number; type GPUSize64 = number; type GPUSize64Out = number; type GPUStencilValue = number; type GPUTextureUsageFlags = number; type GPUAddressMode = | "clamp-to-edge" | "repeat" | "mirror-repeat"; type GPUAutoLayoutMode = "auto"; type GPUBlendFactor = | "zero" | "one" | "src" | "one-minus-src" | "src-alpha" | "one-minus-src-alpha" | "dst" | "one-minus-dst" | "dst-alpha" | "one-minus-dst-alpha" | "src-alpha-saturated" | "constant" | "one-minus-constant" | "src1" | "one-minus-src1" | "src1-alpha" | "one-minus-src1-alpha"; type GPUBlendOperation = | "add" | "subtract" | "reverse-subtract" | "min" | "max"; type GPUBufferBindingType = | "uniform" | "storage" | "read-only-storage"; type GPUBufferMapState = | "unmapped" | "pending" | "mapped"; type GPUCanvasAlphaMode = | "opaque" | "premultiplied"; type GPUCanvasToneMappingMode = | "standard" | "extended"; type GPUCompareFunction = | "never" | "less" | "equal" | "less-equal" | "greater" | "not-equal" | "greater-equal" | "always"; type GPUCompilationMessageType = | "error" | "warning" | "info"; type GPUCullMode = | "none" | "front" | "back"; type GPUDeviceLostReason = | "unknown" | "destroyed"; type GPUErrorFilter = | "validation" | "out-of-memory" | "internal"; type GPUFeatureName = | "core-features-and-limits" | "depth-clip-control" | "depth32float-stencil8" | "texture-compression-bc" | "texture-compression-bc-sliced-3d" | "texture-compression-etc2" | "texture-compression-astc" | "texture-compression-astc-sliced-3d" | "timestamp-query" | "indirect-first-instance" | "shader-f16" | "rg11b10ufloat-renderable" | "bgra8unorm-storage" | "float32-filterable" | "float32-blendable" | "clip-distances" | "dual-source-blending" | "subgroups" | "texture-formats-tier1" | "texture-formats-tier2" | "primitive-index" | "texture-component-swizzle"; type GPUFilterMode = | "nearest" | "linear"; type GPUFrontFace = | "ccw" | "cw"; type GPUIndexFormat = | "uint16" | "uint32"; type GPULoadOp = | "load" | "clear"; type GPUMipmapFilterMode = | "nearest" | "linear"; type GPUPipelineErrorReason = | "validation" | "internal"; type GPUPowerPreference = | "low-power" | "high-performance"; type GPUPrimitiveTopology = | "point-list" | "line-list" | "line-strip" | "triangle-list" | "triangle-strip"; type GPUQueryType = | "occlusion" | "timestamp"; type GPUSamplerBindingType = | "filtering" | "non-filtering" | "comparison"; type GPUStencilOperation = | "keep" | "zero" | "replace" | "invert" | "increment-clamp" | "decrement-clamp" | "increment-wrap" | "decrement-wrap"; type GPUStorageTextureAccess = | "write-only" | "read-only" | "read-write"; type GPUStoreOp = | "store" | "discard"; type GPUTextureAspect = | "all" | "stencil-only" | "depth-only"; type GPUTextureDimension = | "1d" | "2d" | "3d"; type GPUTextureFormat = | "r8unorm" | "r8snorm" | "r8uint" | "r8sint" | "r16unorm" | "r16snorm" | "r16uint" | "r16sint" | "r16float" | "rg8unorm" | "rg8snorm" | "rg8uint" | "rg8sint" | "r32uint" | "r32sint" | "r32float" | "rg16unorm" | "rg16snorm" | "rg16uint" | "rg16sint" | "rg16float" | "rgba8unorm" | "rgba8unorm-srgb" | "rgba8snorm" | "rgba8uint" | "rgba8sint" | "bgra8unorm" | "bgra8unorm-srgb" | "rgb9e5ufloat" | "rgb10a2uint" | "rgb10a2unorm" | "rg11b10ufloat" | "rg32uint" | "rg32sint" | "rg32float" | "rgba16unorm" | "rgba16snorm" | "rgba16uint" | "rgba16sint" | "rgba16float" | "rgba32uint" | "rgba32sint" | "rgba32float" | "stencil8" | "depth16unorm" | "depth24plus" | "depth24plus-stencil8" | "depth32float" | "depth32float-stencil8" | "bc1-rgba-unorm" | "bc1-rgba-unorm-srgb" | "bc2-rgba-unorm" | "bc2-rgba-unorm-srgb" | "bc3-rgba-unorm" | "bc3-rgba-unorm-srgb" | "bc4-r-unorm" | "bc4-r-snorm" | "bc5-rg-unorm" | "bc5-rg-snorm" | "bc6h-rgb-ufloat" | "bc6h-rgb-float" | "bc7-rgba-unorm" | "bc7-rgba-unorm-srgb" | "etc2-rgb8unorm" | "etc2-rgb8unorm-srgb" | "etc2-rgb8a1unorm" | "etc2-rgb8a1unorm-srgb" | "etc2-rgba8unorm" | "etc2-rgba8unorm-srgb" | "eac-r11unorm" | "eac-r11snorm" | "eac-rg11unorm" | "eac-rg11snorm" | "astc-4x4-unorm" | "astc-4x4-unorm-srgb" | "astc-5x4-unorm" | "astc-5x4-unorm-srgb" | "astc-5x5-unorm" | "astc-5x5-unorm-srgb" | "astc-6x5-unorm" | "astc-6x5-unorm-srgb" | "astc-6x6-unorm" | "astc-6x6-unorm-srgb" | "astc-8x5-unorm" | "astc-8x5-unorm-srgb" | "astc-8x6-unorm" | "astc-8x6-unorm-srgb" | "astc-8x8-unorm" | "astc-8x8-unorm-srgb" | "astc-10x5-unorm" | "astc-10x5-unorm-srgb" | "astc-10x6-unorm" | "astc-10x6-unorm-srgb" | "astc-10x8-unorm" | "astc-10x8-unorm-srgb" | "astc-10x10-unorm" | "astc-10x10-unorm-srgb" | "astc-12x10-unorm" | "astc-12x10-unorm-srgb" | "astc-12x12-unorm" | "astc-12x12-unorm-srgb"; type GPUTextureSampleType = | "float" | "unfilterable-float" | "depth" | "sint" | "uint"; type GPUTextureViewDimension = | "1d" | "2d" | "2d-array" | "cube" | "cube-array" | "3d"; type GPUVertexFormat = | "uint8" | "uint8x2" | "uint8x4" | "sint8" | "sint8x2" | "sint8x4" | "unorm8" | "unorm8x2" | "unorm8x4" | "snorm8" | "snorm8x2" | "snorm8x4" | "uint16" | "uint16x2" | "uint16x4" | "sint16" | "sint16x2" | "sint16x4" | "unorm16" | "unorm16x2" | "unorm16x4" | "snorm16" | "snorm16x2" | "snorm16x4" | "float16" | "float16x2" | "float16x4" | "float32" | "float32x2" | "float32x3" | "float32x4" | "uint32" | "uint32x2" | "uint32x3" | "uint32x4" | "sint32" | "sint32x2" | "sint32x3" | "sint32x4" | "unorm10-10-10-2" | "unorm8x4-bgra"; type GPUVertexStepMode = | "vertex" | "instance"; interface GPUBindGroupDescriptor extends GPUObjectDescriptorBase { /** * The {@link GPUBindGroupLayout} the entries of this bind group will conform to. */ layout: GPUBindGroupLayout; /** * A list of entries describing the resources to expose to the shader for each binding * described by the {@link GPUBindGroupDescriptor#layout}. */ entries: Iterable<GPUBindGroupEntry>; } interface GPUBindGroupEntry { /** * A unique identifier for a resource binding within the {@link GPUBindGroup}, corresponding to a * {@link GPUBindGroupLayoutEntry#binding | GPUBindGroupLayoutEntry.binding} and a @binding * attribute in the {@link GPUShaderModule}. */ binding: GPUIndex32; /** * The resource to bind, which may be a {@link GPUSampler}, {@link GPUTexture}, {@link GPUTextureView}, * {@link GPUBuffer}, {@link GPUBufferBinding}, or {@link GPUExternalTexture}. */ resource: GPUBindingResource; } interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase { /** * A list of entries describing the shader resource bindings for a bind group. */ entries: Iterable<GPUBindGroupLayoutEntry>; } interface GPUBindGroupLayoutEntry { /** * A unique identifier for a resource binding within the {@link GPUBindGroupLayout}, corresponding * to a {@link GPUBindGroupEntry#binding | GPUBindGroupEntry.binding} and a @binding * attribute in the {@link GPUShaderModule}. */ binding: GPUIndex32; /** * A bitset of the members of {@link GPUShaderStage}. * Each set bit indicates that a {@link GPUBindGroupLayoutEntry}'s resource * will be accessible from the associated shader stage. */ visibility: GPUShaderStageFlags; /** */ buffer?: GPUBufferBindingLayout; /** */ sampler?: GPUSamplerBindingLayout; /** */ texture?: GPUTextureBindingLayout; /** */ storageTexture?: GPUStorageTextureBindingLayout; /** * Exactly one of these members must be set, indicating the binding type. * The contents of the member specify options specific to that type. * The corresponding resource in {@link GPUDevice#createBindGroup} requires * the corresponding binding resource type for this binding. */ externalTexture?: GPUExternalTextureBindingLayout; } interface GPUBlendComponent { /** * Defines the {@link GPUBlendOperation} used to calculate the values written to the target * attachment components. */ operation?: GPUBlendOperation; /** * Defines the {@link GPUBlendFactor} operation to be performed on values from the fragment shader. */ srcFactor?: GPUBlendFactor; /** * Defines the {@link GPUBlendFactor} operation to be performed on values from the target attachment. */ dstFactor?: GPUBlendFactor; } interface GPUBlendState { /** * Defines the blending behavior of the corresponding render target for color channels. */ color: GPUBlendComponent; /** * Defines the blending behavior of the corresponding render target for the alpha channel. */ alpha: GPUBlendComponent; } interface GPUBufferBinding { /** * The {@link GPUBuffer} to bind. */ buffer: GPUBuffer; /** * The offset, in bytes, from the beginning of {@link GPUBufferBinding#buffer} to the * beginning of the range exposed to the shader by the buffer binding. */ offset?: GPUSize64; /** * The size, in bytes, of the buffer binding. * If not map/exist|provided, specifies the range starting at * {@link GPUBufferBinding#offset} and ending at the end of {@link GPUBufferBinding#buffer}. */ size?: GPUSize64; } interface GPUBufferBindingLayout { /** * Indicates the type required for buffers bound to this binding. */ type?: GPUBufferBindingType; /** * Indicates whether this binding requires a dynamic offset. */ hasDynamicOffset?: boolean; /** * Indicates the minimum {@link GPUBufferBinding#size} of a buffer binding used with this bind point. * Bindings are always validated against this size in {@link GPUDevice#createBindGroup}. * If this *is not* `0`, pipeline creation additionally [$validating shader binding|validates$] * that this value &ge; the minimum buffer binding size of the variable. * If this *is* `0`, it is ignored by pipeline creation, and instead draw/dispatch commands * [$Validate encoder bind groups|validate$] that each binding in the {@link GPUBindGroup} * satisfies the minimum buffer binding size of the variable. * Note: * Similar execution-time validation is theoretically possible for other * binding-related fields specified for early validation, like * {@link GPUTextureBindingLayout#sampleType} and {@link GPUStorageTextureBindingLayout#format}, * which currently can only be validated in pipeline creation. * However, such execution-time validation could be costly or unnecessarily complex, so it is * available only for {@link GPUBufferBindingLayout#minBindingSize} which is expected to have the * most ergonomic impact. */ minBindingSize?: GPUSize64; } interface GPUBufferDescriptor extends GPUObjectDescriptorBase { /** * The size of the buffer in bytes. */ size: GPUSize64; /** * The allowed usages for the buffer. */ usage: GPUBufferUsageFlags; /** * If `true` creates the buffer in an already mapped state, allowing * {@link GPUBuffer#getMappedRange} to be called immediately. It is valid to set * {@link GPUBufferDescriptor#mappedAtCreation} to `true` even if {@link GPUBufferDescriptor#usage} * does not contain {@link GPUBufferUsage#MAP_READ} or {@link GPUBufferUsage#MAP_WRITE}. This can be * used to set the buffer's initial data. * Guarantees that even if the buffer creation eventually fails, it will still appear as if the * mapped range can be written/read to until it is unmapped. */ mappedAtCreation?: boolean; } interface GPUCanvasConfiguration { /** * The {@link GPUDevice} that textures returned by {@link GPUCanvasContext#getCurrentTexture} will be * compatible with. */ device: GPUDevice; /** * The format that textures returned by {@link GPUCanvasContext#getCurrentTexture} will have. * Must be one of the Supported context formats. */ format: GPUTextureFormat; /** * The usage that textures returned by {@link GPUCanvasContext#getCurrentTexture} will have. * {@link GPUTextureUsage#RENDER_ATTACHMENT} is the default, but is not automatically included * if the usage is explicitly set. Be sure to include {@link GPUTextureUsage#RENDER_ATTACHMENT} * when setting a custom usage if you wish to use textures returned by * {@link GPUCanvasContext#getCurrentTexture} as color targets for a render pass. */ usage?: GPUTextureUsageFlags; /** * The formats that views created from textures returned by * {@link GPUCanvasContext#getCurrentTexture} may use. */ viewFormats?: Iterable<GPUTextureFormat>; /** * The color space that values written into textures returned by * {@link GPUCanvasContext#getCurrentTexture} should be displayed with. */ colorSpace?: PredefinedColorSpace; /** * The tone mapping determines how the content of textures returned by * {@link GPUCanvasContext#getCurrentTexture} are to be displayed. * <div class=note heading> * This is a required feature, but user agents might not yet implement it, * effectively supporting only the default {@link GPUCanvasToneMapping}. * In such implementations, this member **should not** exist in its implementation of * {@link GPUCanvasConfiguration}, to make feature detection possible using * {@link GPUCanvasContext#getConfiguration}. * This is especially important in implementations which otherwise have HDR capabilities * (where a <l>'@media/dynamic-range'</l> of <l>''@media/dynamic-range/high''</l> would be * exposed). * If an implementation exposes this member and a `high` dynamic range, it **should** render the * canvas as an HDR element, not clamp values to the SDR range of the HDR display. * </div> */ toneMapping?: GPUCanvasToneMapping; /** * Determines the effect that alpha values will have on the content of textures returned by * {@link GPUCanvasContext#getCurrentTexture} when read, displayed, or used as an image source. */ alphaMode?: GPUCanvasAlphaMode; } interface GPUCanvasToneMapping { mode?: GPUCanvasToneMappingMode; } interface GPUColorDict { /** * The red channel value. */ r: number; /** * The green channel value. */ g: number; /** * The blue channel value. */ b: number; /** * The alpha channel value. */ a: number; } interface GPUColorTargetState { /** * The {@link GPUTextureFormat} of this color target. The pipeline will only be compatible with * {@link GPURenderPassEncoder}s which use a {@link GPUTextureView} of this format in the * corresponding color attachment. */ format: GPUTextureFormat; /** * The blending behavior for this color target. If left undefined, disables blending for this * color target. */ blend?: GPUBlendState; /** * Bitmask controlling which channels are are written to when drawing to this color target. */ writeMask?: GPUColorWriteFlags; } type GPUCommandBufferDescriptor = GPUObjectDescriptorBase; type GPUCommandEncoderDescriptor = GPUObjectDescriptorBase; interface GPUComputePassDescriptor extends GPUObjectDescriptorBase { /** * Defines which timestamp values will be written for this pass, and where to write them to. */ timestampWrites?: GPUComputePassTimestampWrites; } interface GPUComputePassTimestampWrites { /** * The {@link GPUQuerySet}, of type {@link GPUQueryType} `"timestamp"`, that the query results will be * written to. */ querySet: GPUQuerySet; /** * If defined, indicates the query index in {@link GPURenderPassTimestampWrites#querySet} into * which the timestamp at the beginning of the compute pass will be written. */ beginningOfPassWriteIndex?: GPUSize32; /** * If defined, indicates the query index in {@link GPURenderPassTimestampWrites#querySet} into * which the timestamp at the end of the compute pass will be written. */ endOfPassWriteIndex?: GPUSize32; } interface GPUComputePipelineDescriptor extends GPUPipelineDescriptorBase { /** * Describes the compute shader entry point of the pipeline. */ compute: GPUProgrammableStage; } interface GPUCopyExternalImageDestInfo extends GPUTexelCopyTextureInfo { /** * Describes the color space and encoding used to encode data into the destination texture. * This {@link https://www.w3.org/TR/webgpu/#color-space-conversions | may result} in values outside of the range [0, 1] * being written to the target texture, if its format can represent them. * Otherwise, the results are clamped to the target texture format's range. * Note: * If {@link GPUCopyExternalImageDestInfo#colorSpace} matches the source image, * conversion might not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}. */ colorSpace?: PredefinedColorSpace; /** * Describes whether the data written into the texture should have its RGB channels * premultiplied by the alpha channel, or not. * If this option is set to `true` and the {@link GPUCopyExternalImageSourceInfo#source} is also * premultiplied, the source RGB values must be preserved even if they exceed their * corresponding alpha values. * Note: * If {@link GPUCopyExternalImageDestInfo#premultipliedAlpha} matches the source image, * conversion might not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}. */ premultipliedAlpha?: boolean; } interface GPUCopyExternalImageSourceInfo { /** * The source of the texel copy. The copy source data is captured at the moment that * {@link GPUQueue#copyExternalImageToTexture} is issued. Source size is determined as described * by the external source dimensions table. */ source: GPUCopyExternalImageSource; /** * Defines the origin of the copy - the minimum (top-left) corner of the source sub-region to copy from. * Together with `copySize`, defines the full copy sub-region. */ origin?: GPUOrigin2D; /** * Describes whether the source image is vertically flipped, or not. * If this option is set to `true`, the copy is flipped vertically: the bottom row of the source * region is copied into the first row of the destination region, and so on. * The {@link GPUCopyExternalImageSourceInfo#origin} option is still relative to the top-left corner * of the source image, increasing downward. */ flipY?: boolean; } interface GPUDepthStencilState { /** * The {@link GPUTextureViewDescriptor#format} of {@link GPURenderPassDescriptor#depthStencilAttachment} * this {@link GPURenderPipeline} will be compatible with. */ format: GPUTextureFormat; /** * Indicates if this {@link GPURenderPipeline} can modify * {@link GPURenderPassDescriptor#depthStencilAttachment} depth values. */ depthWriteEnabled?: boolean; /** * The comparison operation used to test fragment depths against * {@link GPURenderPassDescriptor#depthStencilAttachment} depth values. */ depthCompare?: GPUCompareFunction; /** * Defines how stencil comparisons and operations are performed for front-facing primitives. */ stencilFront?: GPUStencilFaceState; /** * Defines how stencil comparisons and operations are performed for back-facing primitives. */ stencilBack?: GPUStencilFaceState; /** * Bitmask controlling which {@link GPURenderPassDescriptor#depthStencilAttachment} stencil value * bits are read when performing stencil comparison tests. */ stencilReadMask?: GPUStencilValue; /** * Bitmask controlling which {@link GPURenderPassDescriptor#depthStencilAttachment} stencil value * bits are written to when performing stencil operations. */ stencilWriteMask?: GPUStencilValue; /** * Constant depth bias added to each triangle fragment. See [$biased fragment depth$] for details. */ depthBias?: GPUDepthBias; /** * Depth bias that scales with the triangle fragment’s slope. See [$biased fragment depth$] for details. */ depthBiasSlopeScale?: number; /** * The maximum depth bias of a triangle fragment. See [$biased fragment depth$] for details. */ depthBiasClamp?: number; } interface GPUDeviceDescriptor extends GPUObjectDescriptorBase { /** * Specifies the features that are required by the device request. * The request will fail if the adapter cannot provide these features. * Exactly the specified set of features, and no more or less, will be allowed in validation * of API calls on the resulting device. */ requiredFeatures?: Iterable<GPUFeatureName>; /** * Specifies the limits that are required by the device request. * The request will fail if the adapter cannot provide these limits. * Each key with a non-`undefined` value must be the name of a member of supported limits. * API calls on the resulting device perform validation according to the exact limits of the * device (not the adapter; see {@link https://www.w3.org/TR/webgpu/#limits}). * <!-- If we ever need limit types other than GPUSize32/GPUSize64, we can change the value * type to `double` or `any` in the future and write out the type conversion explicitly (by * reference to WebIDL spec). Or change the entire type to `any` and add back a `dictionary * GPULimits` and define the conversion of the whole object by reference to WebIDL. --> */ requiredLimits?: Record< string, | GPUSize64 | undefined >; /** * The descriptor for the default {@link GPUQueue}. */ defaultQueue?: GPUQueueDescriptor; } interface GPUExtent3DDict { /** * The width of the extent. */ width: GPUIntegerCoordinate; /** * The height of the extent. */ height?: GPUIntegerCoordinate; /** * The depth of the extent or the number of array layers it contains. * If used with a {@link GPUTexture} with a {@link GPUTextureDimension} of {@link GPUTextureDimension} `"3d"` * defines the depth of the texture. If used with a {@link GPUTexture} with a {@link GPUTextureDimension} * of {@link GPUTextureDimension} `"2d"` defines the number of array layers in the texture. */ depthOrArrayLayers?: GPUIntegerCoordinate; } interface GPUExternalTextureBindingLayout {} interface GPUExternalTextureDescriptor extends GPUObjectDescriptorBase { /** * The video source to import the external texture from. Source size is determined as described * by the external source dimensions table. */ source: | HTMLVideoElement | VideoFrame; /** * The color space the image contents of {@link GPUExternalTextureDescriptor#source} will be * converted into when reading. */ colorSpace?: PredefinedColorSpace; } interface GPUFragmentState extends GPUProgrammableStage { /** * A list of {@link GPUColorTargetState} defining the formats and behaviors of the color targets * this pipeline writes to. */ targets: Iterable< | GPUColorTargetState | null | undefined >; } interface GPUMultisampleState { /** * Number of samples per pixel. This {@link GPURenderPipeline} will be compatible only * with attachment textures ({@link GPURenderPassDescriptor#colorAttachments} * and {@link GPURenderPassDescriptor#depthStencilAttachment}) * with matching {@link GPUTextureDescriptor#sampleCount}s. */ count?: GPUSize32; /** * Mask determining which samples are written to. */ mask?: GPUSampleMask; /** * When `true` indicates that a fragment's alpha channel should be used to generate a sample * coverage mask. */ alphaToCoverageEnabled?: boolean; } interface GPUObjectDescriptorBase { /** * The initial value of {@link GPUObjectBase#label | GPUObjectBase.label}. */ label?: string; } interface GPUOrigin2DDict { x?: GPUIntegerCoordinate; y?: GPUIntegerCoordinate; } interface GPUOrigin3DDict { x?: GPUIntegerCoordinate; y?: GPUIntegerCoordinate; z?: GPUIntegerCoordinate; } interface GPUPipelineDescriptorBase extends GPUObjectDescriptorBase { /** * The {@link GPUPipelineLayout} for this pipeline, or {@link GPUAutoLayoutMode} `"auto"` to generate * the pipeline layout automatically. * Note: If {@link GPUAutoLayoutMode} `"auto"` is used the pipeline cannot share {@link GPUBindGroup}s * with any other pipelines. */ layout: | GPUPipelineLayout | GPUAutoLayoutMode; } interface GPUPipelineErrorInit { reason: GPUPipelineErrorReason; } interface GPUPipelineLayoutDescriptor extends GPUObjectDescriptorBase { /** * A list of optional {@link GPUBindGroupLayout}s the pipeline will use. Each element corresponds * to a @group attribute in the {@link GPUShaderModule}, with the `N`th element corresponding * with `@group(N)`. */ bindGroupLayouts: Iterable< | GPUBindGroupLayout | null | undefined >; /** * The size, in bytes, of the immediate data range used by the pipeline. */ immediateSize?: GPUSize32; } interface GPUPrimitiveState { /** * The type of primitive to be constructed from the vertex inputs. */ topology?: GPUPrimitiveTopology; /** * For pipelines with strip topologies * ({@link GPUPrimitiveTopology} `"line-strip"` or {@link GPUPrimitiveTopology} `"triangle-strip"`), * this determines the index buffer format and primitive restart value * ({@link GPUIndexFormat} `"uint16"`/`0xFFFF` or {@link GPUIndexFormat} `"uint32"`/`0xFFFFFFFF`). * It is not allowed on pipelines with non-strip topologies. * Note: Some implementations require knowledge of the primitive restart value to compile * pipeline state objects. * To use a strip-topology pipeline with an indexed draw call * ({@link GPURenderCommandsMixin#drawIndexed()} or {@link GPURenderCommandsMixin#drawIndexedIndirect}), * this must be set, and it must match the index buffer format used with the draw call * (set in {@link GPURenderCommandsMixin#setIndexBuffer}). * See {@link https://www.w3.org/TR/webgpu/#primitive-assembly} for additional details. */ stripIndexFormat?: GPUIndexFormat; /** * Defines which polygons are considered front-facing. */ frontFace?: GPUFrontFace; /** * Defines which polygon orientation will be culled, if any. */ cullMode?: GPUCullMode; /** * If true, indicates that depth clipping is disabled. * Requires the {@link GPUFeatureName} `"depth-clip-control"` feature to be enabled. */ unclippedDepth?: boolean; } interface GPUProgrammableStage { /** * The {@link GPUShaderModule} containing the code that this programmable stage will execute. */ module: GPUShaderModule; /** * The name of the function in {@link GPUProgrammableStage#module} that this stage will use to * perform its work. * NOTE: Since the {@link GPUProgrammableStage#entryPoint} dictionary member is * not required, methods which consume a {@link GPUProgrammableStage} must use the * "[$get the entry point$]" algorithm to determine which entry point * it refers to. */ entryPoint?: string; /** * Specifies the values of pipeline-overridable constants in the shader module * {@link GPUProgrammableStage#module}. * Each such pipeline-overridable constant is uniquely identified by a single * pipeline-overridable constant identifier string, representing the pipeline * constant ID of the constant if its declaration specifies one, and otherwise the * constant's identifier name. * The key of each key-value pair must equal the * pipeline-overridable constant identifier string|identifier string * of one such constant, with the comparison performed * according to the rules for WGSL identifier comparison. * When the pipeline is executed, that constant will have the specified value. * Values are specified as <dfn typedef for="">GPUPipelineConstantValue</dfn>, which is a `double`. * They are converted [$to WGSL type$] of the pipeline-overridable constant (`bool`/`i32`/`u32`/`f32`/`f16`). * If conversion fails, a validation error is generated. * <div class=example> * Pipeline-overridable constants defined in WGSL: * ```wgsl * @id(0) override has_point_light: bool = true; // Algorithmic control. * @id(1200) override specular_param: f32 = 2.3; // Numeric control. * @id(1300) override gain: f32; // Must be overridden. * override width: f32 = 0.0; // Specifed at the API level * // using the name "width". * override depth: f32; // Specifed at the API level * // using the name "depth". * // Must be overridden. * override height = 2 * depth; // The default value * // (if not set at the API level), * // depends on another * // overridable constant. * ``` * Corresponding JavaScript code, providing only the overrides which are required * (have no defaults): * ```js * { * // ... * constants: { * 1300: 2.0, // "gain" * depth: -1, // "depth" * } * } * ``` * Corresponding JavaScript code, overriding all constants: * ```js * { * // ... * constants: { * 0: false, // "has_point_light" * 1200: 3.0, // "specular_param" * 1300: 2.0, // "gain" * width: 20, // "width" * depth: -1, // "depth" * height: 15, // "height" * } * } * ``` * </div> */ constants?: Record< string, GPUPipelineConstantValue >; } interface GPUQuerySetDescriptor extends GPUObjectDescriptorBase { /** * The type of queries managed by {@link GPUQuerySet}. */ type: GPUQueryType; /** * The number of queries managed by {@link GPUQuerySet}. */ count: GPUSize32; } type GPUQueueDescriptor = GPUObjectDescriptorBase; type GPURenderBundleDescriptor = GPUObjectDescriptorBase; interface GPURenderBundleEncoderDescriptor extends GPURenderPassLayout { /** * If `true`, indicates that the render bundle does not modify the depth component of the * {@link GPURenderPassDepthStencilAttachment} of any render pass the render bundle is executed * in. * See read-only depth-stencil. */ depthReadOnly?: boolean; /** * If `true`, indicates that the render bundle does not modify the stencil component of the * {@link GPURenderPassDepthStencilAttachment} of any render pass the render bundle is executed * in. * See read-only depth-stencil. */ stencilReadOnly?: boolean; } interface GPURenderPassColorAttachment { /** * Describes the texture subresource that will be output to for this color attachment. * The subresource is determined by calling [$get as texture view$]({@link GPURenderPassColorAttachment#view}). */ view: | GPUTexture | GPUTextureView; /** * Indicates the depth slice index of {@link GPUTextureViewDimension} `"3d"` {@link GPURenderPassColorAttachment#view} * that will be output to for this color attachment. */ depthSlice?: GPUIntegerCoordinate; /** * Describes the texture subresource that will receive the resolved output for this color * attachment if {@link GPURenderPassColorAttachment#view} is multisampled. * The subresource is determined by calling [$get as texture view$]({@link GPURenderPassColorAttachment#resolveTarget}). */ resolveTarget?: | GPUTexture | GPUTextureView; /** * Indicates the value to clear {@link GPURenderPassColorAttachment#view} to prior to executing the * render pass. If not map/exist|provided, defaults to `{r: 0, g: 0, b: 0, a: 0}`. Ignored * if {@link GPURenderPassColorAttachment#loadOp} is not {@link GPULoadOp} `"clear"`. * The components of {@link GPURenderPassColorAttachment#clearValue} are all double values. * They are converted [$to a texel value of texture format$] matching the render attachment. * If conversion fails, a validation error is generated. */ clearValue?: GPUColor; /** * Indicates the load operation to perform on {@link GPURenderPassColorAttachment#view} prior to * executing the render pass. * Note: It is recommended to prefer clearing; see {@link GPULoadOp} `"clear"` for details. */ loadOp: GPULoadOp; /** * The store operation to perform on {@link GPURenderPassColorAttachment#view} * after executing the render pass. */ storeOp: GPUStoreOp; } interface GPURenderPassDepthStencilAttachment { /** * Describes the texture subresource that will be output to and read from for this * depth/stencil attachment. * The subresource is determined by calling [$get as texture view$]({@link GPURenderPassDepthStencilAttachment#view}). */ view: | GPUTexture | GPUTextureView; /** * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s depth component * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#depthLoadOp} * is not {@link GPULoadOp} `"clear"`. Must be between 0.0 and 1.0, inclusive. * <!-- POSTV1(unrestricted-depth): unless unrestricted depth is enabled --> */ depthClearValue?: number; /** * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s * depth component prior to executing the render pass. * Note: It is recommended to prefer clearing; see {@link GPULoadOp} `"clear"` for details. */ depthLoadOp?: GPULoadOp; /** * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s * depth component after executing the render pass. */ depthStoreOp?: GPUStoreOp; /** * Indicates that the depth component of {@link GPURenderPassDepthStencilAttachment#view} * is read only. */ depthReadOnly?: boolean; /** * Indicates the value to clear {@link GPURenderPassDepthStencilAttachment#view}'s stencil component * to prior to executing the render pass. Ignored if {@link GPURenderPassDepthStencilAttachment#stencilLoadOp} * is not {@link GPULoadOp} `"clear"`. * The value will be converted to the type of the stencil aspect of `view` by taking the same * number of LSBs as the number of bits in the stencil aspect of one texel block|texel of `view`. */ stencilClearValue?: GPUStencilValue; /** * Indicates the load operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s * stencil component prior to executing the render pass. * Note: It is recommended to prefer clearing; see {@link GPULoadOp} `"clear"` for details. */ stencilLoadOp?: GPULoadOp; /** * The store operation to perform on {@link GPURenderPassDepthStencilAttachment#view}'s * stencil component after executing the render pass. */ stencilStoreOp?: GPUStoreOp; /** * Indicates that the stencil component of {@link GPURenderPassDepthStencilAttachment#view} * is read only. */ stencilReadOnly?: boolean; } interface GPURenderPassDescriptor extends GPUObjectDescriptorBase { /** * The set of {@link GPURenderPassColorAttachment} values in this sequence defines which * color attachments will be output to when executing this render pass. * Due to compatible usage list|usage compatibility, no color attachment * may alias another attachment or any resource used inside the render pass. */ colorAttachments: Iterable< | GPURenderPassColorAttachment | null | undefined >; /** * The {@link GPURenderPassDepthStencilAttachment} value that defines the depth/stencil * attachment that will be output to and tested against when executing this render pass. * Due to compatible usage list|usage compatibility, no writable depth/stencil attachment * may alias another attachment or any resource used inside the render pass. */ depthStencilAttachment?: GPURenderPassDepthStencilAttachment; /** * The {@link GPUQuerySet} value defines where the occlusion query results will be stored for this pass. */ occlusionQuerySet?: GPUQuerySet; /** * Defines which timestamp values will be written for this pass, and where to write them to. */ timestampWrites?: GPURenderPassTimestampWrites; /** * The maximum number of draw calls that will be done in the render pass. Used by some * implementations to size work injected before the render pass. Keeping the default value * is a good default, unless it is known that more draw calls will be done. */ maxDrawCount?: GPUSize64; } interface GPURenderPassLayout extends GPUObjectDescriptorBase { /** * A list of the {@link GPUTextureFormat}s of the color attachments for this pass or bundle. */ colorFormats: Iterable< | GPUTextureFormat | null | undefined >; /** * The {@link GPUTextureFormat} of the depth/stencil attachment for this pass or bundle. */ depthStencilFormat?: GPUTextureFormat; /** * Number of samples per pixel in the attachments for this pass or bundle. */ sampleCount?: GPUSize32; } interface GPURenderPassTimestampWrites { /** * The {@link GPUQuerySet}, of type {@link GPUQueryType} `"timestamp"`, that the query results will be * written to. */ querySet: GPUQuerySet; /** * If defined, indicates the query index in {@link GPURenderPassTimestampWrites#querySet} into * which the timestamp at the beginning of the render pass will be written. */ beginningOfPassWriteIndex?: GPUSize32; /** * If defined, indicates the query index in {@link GPURenderPassTimestampWrites#querySet} into * which the timestamp at the end of the render pass will be written. */ endOfPassWriteIndex?: GPUSize32; } interface GPURenderPipelineDescriptor extends GPUPipelineDescriptorBase { /** * Describes the vertex shader entry point of the pipeline and its input buffer layouts. */ vertex: GPUVertexState; /** * Describes the primitive-related properties of the pipeline. */ primitive?: GPUPrimitiveState; /** * Describes the optional depth-stencil properties, including the testing, operations, and bias. */ depthStencil?: GPUDepthStencilState; /** * Describes the multi-sampling properties of the pipeline. */ multisample?: GPUMultisampleState; /** * Describes the fragment shader entry point of the pipeline and its output colors. If * not map/exist|provided, the {@link https://www.w3.org/TR/webgpu/#no-color-output} mode is enabled. */ fragment?: GPUFragmentState; } interface GPURequestAdapterOptions { /** * Requests an adapter that supports at least a particular set of capabilities. * This influences the {@link adapter#[[default feature level]]} of devices created * from this adapter. The capabilities for each level are defined below, and the exact * steps are defined in {@link GPU#requestAdapter} and "a new device". * If the implementation or system does not support all of the capabilities in the * requested feature level, {@link GPU#requestAdapter} will return `null`. * Note: * Applications should typically make a single {@link GPU#requestAdapter} call with the lowest * feature level they support, then inspect the adapter for additional capabilities they can * use optionally, and request those in {@link GPUAdapter#requestDevice}. * The allowed <dfn dfn for="">feature level string</dfn> values are: * <dl dfn-type=dfn dfn-for="feature level string"> * : <dfn noexport>"core"</dfn> * The following set of capabilities: * - The limit/Default limits. * - {@link GPUFeatureName} `"core-features-and-limits"`. * Note: * Adapters with this {@link adapter#[[default feature level]]} may * conventionally be referred to as "Core-defaulting". * : <dfn noexport>"compatibility"</dfn> * The following set of capabilities: * - The limit/Compatibility Mode Default limits. * - No features. (It excludes the {@link GPUFeatureName} `"core-features-and-limits"` feature.) * If the implementation cannot enforce the stricter "Compatibility Mode" * validation rules, {@link GPU#requestAdapter} will ignore this request and * treat it as a request for feature level string/"core". * Note: * Adapters with this {@link adapter#[[default feature level]]} may * conventionally be referred to as "Compatibility-defaulting". */ featureLevel?: string; /** * Optionally provides a hint indicating what class of adapter should be selected from * the system's available adapters. * The value of this hint may influence which adapter is chosen, but it must not * influence whether an adapter is returned or not. * Note: * The primary utility of this hint is to influence which GPU is used in a multi-GPU system. * For instance, some laptops have a low-power integrated GPU and a high-performance * discrete GPU. This hint may also affect the power configuration of the selected GPU to * match the requested power preference. * Note: * Depending on the exact hardware configuration, such as battery status and attached displays * or removable GPUs, the user agent may select different adapters given the same power * preference. * Typically, given the same hardware configuration and state and * `powerPreference`, the user agent is likely to select the same adapter. */ powerPreference?: GPUPowerPreference; /** * When set to `true` indicates that only a fallback adapter may be returned. If the user * agent does not support a fallback adapter, will cause {@link GPU#requestAdapter} to * resolve to `null`. * Note: * {@link GPU#requestAdapter} may still return a fallback adapter if * {@link GPURequestAdapterOptions#forceFallbackAdapter} is set to `false` and either no * other appropriate adapter is available or the user agent chooses to return a * fallback adapter. Developers that wish to prevent their applications from running on * fallback adapters should check the {@link GPUAdapter#info}.{@link GPUAdapterInfo#isFallbackAdapter} * attribute prior to requesting a {@link GPUDevice}. */ forceFallbackAdapter?: boolean; xrCompatible?: boolean; } interface GPUSamplerBindingLayout { /** * Indicates the required type of a sampler bound to this bindings. */ type?: GPUSamplerBindingType; } interface GPUSamplerDescriptor extends GPUObjectDescriptorBase { /** */ addressModeU?: GPUAddressMode; /** */ addressModeV?: GPUAddressMode; /** * Specifies the {@link GPUAddressMode | address modes} for the texture width, height, and depth * coordinates, respectively. */ addressModeW?: GPUAddressMode; /** * Specifies the sampling behavior when the sampled area is smaller than or equal to one * texel. */ magFilter?: GPUFilterMode; /** * Specifies the sampling behavior when the sampled area is larger than one texel. */ minFilter?: GPUFilterMode; /** * Specifies behavior for sampling between mipmap levels. */ mipmapFilter?: GPUMipmapFilterMode; /** */ lodMinClamp?: number; /** * Specifies the minimum and maximum levels of detail, respectively, used internally when * sampling a texture. */ lodMaxClamp?: number; /** * When provided the sampler will be a comparison sampler with the specified * {@link GPUCompareFunction}. * Note: Comparison samplers may use filtering, but the sampling results will be * implementation-dependent and may differ from the normal filtering rules. */ compare?: GPUCompareFunction; /** * Specifies the maximum anisotropy value clamp used by the sampler. Anisotropic filtering is * enabled when {@link GPUSamplerDescriptor#maxAnisotropy} is &gt; 1 and the implementation supports it. * Anisotropic filtering improves the image quality of textures sampled at oblique viewing * angles. Higher {@link GPUSamplerDescriptor#maxAnisotropy} values indicate the maximum ratio