From f6becbf49a4b4e1a14eda4b8c13466654fd16806 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Thu, 30 Jan 2025 20:30:44 -0800 Subject: [PATCH 1/3] Add a script to modified the generated index.d.ts file Just using regexes to keep it simple. Hopefully it's not too brittle. --- generate.mjs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 generate.mjs diff --git a/generate.mjs b/generate.mjs new file mode 100644 index 0000000..24240bb --- /dev/null +++ b/generate.mjs @@ -0,0 +1,68 @@ +import {spawnSync} from 'node:child_process'; +import fs from 'node:fs'; + +export function execute(cmd, args, options) { + const { error, status } = spawnSync(cmd, args, {...options || {}, shell: true, stdio: 'inherit'}); + if (error) { + throw new(Error); + } + if (status !== 0) { + throw new Error(`${cmd} exited with status code: ${status}`); + } +} + +/** + * Transform generated to something closer to what we want + * so we have less manual work to do. + */ +function fixupGenerated(filename) { + let s = fs.readFileSync(filename, { encoding: 'utf-8' }); + + // replace ' | null>' with ' null | undefined>' + // replace ' | null,' with ' null | undefined,' + s = s.replace(/ \| null(>|,)/g, ' | null | undefined$1'); + + // replace Array with Iterable + s = s.replace(/\bArray<(.*?)>/g, 'Iterable<$1>'); + + // add new(): never; + s = s.replace(/(\ndeclare\svar\s\w+:\s\{\n\s+prototype:.*?\n)\};/g, '$1 new(): never;\n};'); + + // replace : GPUExtent3D -> : GPUExtent3DStrict + s = s.replace(/: GPUExtent3D\b/g, ': GPUExtent3DStrict'); + + // replace AllowSharedBufferSource -> BufferSource | SharedArrayBuffer + s = s.replace(/AllowSharedBufferSource/g, 'BufferSource | SharedArrayBuffer'); + + // replace Promise<... | undefined> with Promise<...> + s = s.replace(/( Promise<[^>]*?)\s+\|\s+undefined\s*>/g, '$1>'); + + // fix constants + const constants = [ + 'GPUBufferUsage', + 'GPUColorWrite', + 'GPUMapMode', + 'GPUShaderStage', + 'GPUTextureUsage', + ]; + const constantRE = new RegExp(`interface (${constants.join('|')}) \\{`, 'g'); + s = s.replace(constantRE, 'declare var $1: {'); + + // fix constructables + const constructables = [ + 'GPUInternalError', + 'GPUPipelineError', + 'GPUOutOfMemoryError', + 'GPUUncapturedErrorEvent', + 'GPUValidationError', + ]; + const constructableRE = new RegExp(`(\\ndeclare var (${constructables.join('|')}):\\s{\\n[\\s\\S]*?\\snew\\s\\([^;]*?\\));\\n};`, 'g'); + s = s.replace(constructableRE, '$1: $2;\n};'); + + fs.writeFileSync(filename, s); +} + +execute('./node_modules/.bin/bikeshed-to-ts', ['--in', './gpuweb/spec/index.bs', '--out', './generated/index.d.ts', '--forceGlobal', '--nominal']) +fixupGenerated('./generated/index.d.ts'); +execute('./node_modules/.bin/prettier', ['-w', 'generated/index.d.ts']); + diff --git a/package.json b/package.json index 2d66260..c47fe1a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "test": "for t in tests/*/ ; do (cd \"$t\" && npm i && npm test); done", "build-docs": "cd tsdoc-src && npm ci && npm run build", - "generate": "bikeshed-to-ts --in ./gpuweb/spec/index.bs --out ./generated/index.d.ts --forceGlobal --nominal && prettier -w generated/index.d.ts", + "generate": "node generate.mjs", "format": "prettier -w dist/index.d.ts" }, "devDependencies": { From c17cea4fff8ec3edd40bbc44275f40edb0b74e00 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Thu, 30 Jan 2025 20:48:27 -0800 Subject: [PATCH 2/3] Separate easily separatable modifications to a separate file. --- dist/index.d.ts | 402 ++++++++++++++++----------------- extra.d.ts | 253 +++++++++++++++++++++ generate.mjs | 4 + generated/index.d.ts | 514 ++++++++++++++++++++++++++++++------------- 4 files changed, 821 insertions(+), 352 deletions(-) create mode 100644 extra.d.ts diff --git a/dist/index.d.ts b/dist/index.d.ts index 8756ec0..763330a 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -48,6 +48,210 @@ interface GPUExtent3DDictStrict depth?: undefined; } +interface GPUCanvasConfigurationOut + extends Required< + Omit< + GPUCanvasConfiguration, + "toneMapping" + > + > { + /** {@inheritDoc GPUCanvasConfiguration.viewFormats} */ + viewFormats: GPUTextureFormat[]; + /** + * {@inheritDoc GPUCanvasConfiguration.toneMapping} + */ + toneMapping?: GPUCanvasToneMapping; +} + +interface GPUTextureDescriptor { + /** + * **PROPOSED** addition for Compatibility Mode: + * + * + * > [In compatibility mode,] + * > When specifying a texture, a textureBindingViewDimension property + * > determines the views which can be bound from that texture for sampling. + * > Binding a view of a different dimension for sampling than specified at + * > texture creation time will cause a validation error. + */ + textureBindingViewDimension?: GPUTextureViewDimension; +} + +/** @internal */ +interface __GPUDeviceEventMap { + uncapturederror: GPUUncapturedErrorEvent; +} + +interface GPUDevice { + /** + * An event handler IDL attribute for the {@link GPUDevice#uncapturederror} event type. + */ + onuncapturederror: + | (( + this: GPUDevice, + ev: GPUUncapturedErrorEvent + ) => any) + | null; + + 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 GPUTexelCopyBufferInfo + extends GPUTexelCopyBufferLayout { + /** + * A buffer which either contains texel data to be copied or will store the texel data being + * copied, depending on the method it is being passed to. + */ + buffer: GPUBuffer; +} + +interface GPUTexelCopyBufferLayout { + /** + * The offset, in bytes, from the beginning of the texel data source (such as a + * {@link GPUTexelCopyBufferInfo#buffer|GPUTexelCopyBufferInfo.buffer}) to the start of the texel data + * within that source. + */ + offset?: GPUSize64; + /** + * The stride, in bytes, between the beginning of each texel block row and the subsequent + * texel block row. + * Required if there are multiple texel block rows (i.e. the copy height or depth is more + * than one block). + */ + bytesPerRow?: GPUSize32; + /** + * Number of texel block rows per single texel image of the texture. + * {@link GPUTexelCopyBufferLayout#rowsPerImage} × + * {@link GPUTexelCopyBufferLayout#bytesPerRow} is the stride, in bytes, between the beginning of each + * texel image of data and the subsequent texel image. + * Required if there are multiple texel images (i.e. the copy depth is more than one). + */ + rowsPerImage?: GPUSize32; +} + +interface GPUTexelCopyTextureInfo { + /** + * Texture to copy to/from. + */ + texture: GPUTexture; + /** + * Mip-map level of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + mipLevel?: GPUIntegerCoordinate; + /** + * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. + * Together with `copySize`, defines the full copy sub-region. + */ + origin?: GPUOrigin3D; + /** + * Defines which aspects of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + aspect?: GPUTextureAspect; +} + +interface GPUCopyExternalImageDestInfo + extends GPUTexelCopyTextureInfo { + /** + * Describes the color space and encoding used to encode data into the destination texture. + * This [[#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 may not be necessary. See [[#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 may not be necessary. See [[#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; +} + +/** @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) // ********************************************************************************************* @@ -665,21 +869,6 @@ interface GPUCanvasConfiguration { alphaMode?: GPUCanvasAlphaMode; } -interface GPUCanvasConfigurationOut - extends Required< - Omit< - GPUCanvasConfiguration, - "toneMapping" - > - > { - /** {@inheritDoc GPUCanvasConfiguration.viewFormats} */ - viewFormats: GPUTextureFormat[]; - /** - * {@inheritDoc GPUCanvasConfiguration.toneMapping} - */ - toneMapping?: GPUCanvasToneMapping; -} - interface GPUCanvasToneMapping { mode?: GPUCanvasToneMappingMode; } @@ -760,53 +949,6 @@ interface GPUComputePipelineDescriptor compute: GPUProgrammableStage; } -interface GPUCopyExternalImageDestInfo - extends GPUTexelCopyTextureInfo { - /** - * Describes the color space and encoding used to encode data into the destination texture. - * This [[#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 may not be necessary. See [[#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 may not be necessary. See [[#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} @@ -1500,59 +1642,6 @@ interface GPUStorageTextureBindingLayout { viewDimension?: GPUTextureViewDimension; } -interface GPUTexelCopyBufferInfo - extends GPUTexelCopyBufferLayout { - /** - * A buffer which either contains texel data to be copied or will store the texel data being - * copied, depending on the method it is being passed to. - */ - buffer: GPUBuffer; -} - -interface GPUTexelCopyBufferLayout { - /** - * The offset, in bytes, from the beginning of the texel data source (such as a - * {@link GPUTexelCopyBufferInfo#buffer|GPUTexelCopyBufferInfo.buffer}) to the start of the texel data - * within that source. - */ - offset?: GPUSize64; - /** - * The stride, in bytes, between the beginning of each texel block row and the subsequent - * texel block row. - * Required if there are multiple texel block rows (i.e. the copy height or depth is more - * than one block). - */ - bytesPerRow?: GPUSize32; - /** - * Number of texel block rows per single texel image of the texture. - * {@link GPUTexelCopyBufferLayout#rowsPerImage} × - * {@link GPUTexelCopyBufferLayout#bytesPerRow} is the stride, in bytes, between the beginning of each - * texel image of data and the subsequent texel image. - * Required if there are multiple texel images (i.e. the copy depth is more than one). - */ - rowsPerImage?: GPUSize32; -} - -interface GPUTexelCopyTextureInfo { - /** - * Texture to copy to/from. - */ - texture: GPUTexture; - /** - * Mip-map level of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. - */ - mipLevel?: GPUIntegerCoordinate; - /** - * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. - * Together with `copySize`, defines the full copy sub-region. - */ - origin?: GPUOrigin3D; - /** - * Defines which aspects of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. - */ - aspect?: GPUTextureAspect; -} - interface GPUTextureBindingLayout { /** * Indicates the type required for texture views bound to this binding. @@ -1619,17 +1708,6 @@ interface GPUTextureDescriptor * */ viewFormats?: Iterable; - /** - * **PROPOSED** addition for Compatibility Mode: - * - * - * > [In compatibility mode,] - * > When specifying a texture, a textureBindingViewDimension property - * > determines the views which can be bound from that texture for sampling. - * > Binding a view of a different dimension for sampling than specified at - * > texture creation time will cause a validation error. - */ - textureBindingViewDimension?: GPUTextureViewDimension; } interface GPUTextureViewDescriptor @@ -2447,11 +2525,6 @@ declare var GPUComputePipeline: { new (): never; }; -/** @internal */ -interface __GPUDeviceEventMap { - uncapturederror: GPUUncapturedErrorEvent; -} - interface GPUDevice extends EventTarget, GPUObjectBase { @@ -2627,54 +2700,6 @@ interface GPUDevice * There is no guarantee of the ordering of promise resolution. */ popErrorScope(): Promise; - /** - * An event handler IDL attribute for the {@link GPUDevice#uncapturederror} event type. - */ - onuncapturederror: - | (( - this: GPUDevice, - ev: GPUUncapturedErrorEvent - ) => any) - | null; - - 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; } declare var GPUDevice: { @@ -3322,22 +3347,3 @@ declare var GPUTextureUsage: { readonly STORAGE_BINDING: GPUFlagsConstant; readonly RENDER_ATTACHMENT: GPUFlagsConstant; }; - -/** @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; diff --git a/extra.d.ts b/extra.d.ts new file mode 100644 index 0000000..8f8d62b --- /dev/null +++ b/extra.d.ts @@ -0,0 +1,253 @@ +// ********************************************************************************************* +// This file is manually-edited by diffing against an autogenerated file. See README.md. +// ********************************************************************************************* + +// ********************************************************************************************* +// Manually-written +// ********************************************************************************************* + +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 {} + +type GPUOrigin2DStrict = + + | Iterable + | GPUOrigin2DDictStrict; + +interface GPUOrigin2DDictStrict + extends GPUOrigin2DDict { + /** @deprecated Does not exist for GPUOrigin2D. */ + z?: undefined; +} + +type GPUExtent3DStrict = + + | Iterable + | GPUExtent3DDictStrict; + +// GPUExtent3DDictStrict is 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.) +interface GPUExtent3DDictStrict + extends GPUExtent3DDict { + /** @deprecated The correct name is `depthOrArrayLayers`. */ + depth?: undefined; +} + +interface GPUCanvasConfigurationOut + extends Required< + Omit< + GPUCanvasConfiguration, + "toneMapping" + > + > { + /** {@inheritDoc GPUCanvasConfiguration.viewFormats} */ + viewFormats: GPUTextureFormat[]; + /** + * {@inheritDoc GPUCanvasConfiguration.toneMapping} + */ + toneMapping?: GPUCanvasToneMapping; +} + +interface GPUTextureDescriptor { + /** + * **PROPOSED** addition for Compatibility Mode: + * + * + * > [In compatibility mode,] + * > When specifying a texture, a textureBindingViewDimension property + * > determines the views which can be bound from that texture for sampling. + * > Binding a view of a different dimension for sampling than specified at + * > texture creation time will cause a validation error. + */ + textureBindingViewDimension?: GPUTextureViewDimension; +} + +/** @internal */ +interface __GPUDeviceEventMap { + uncapturederror: GPUUncapturedErrorEvent; +} + +interface GPUDevice { + /** + * An event handler IDL attribute for the {@link GPUDevice#uncapturederror} event type. + */ + onuncapturederror: + | (( + this: GPUDevice, + ev: GPUUncapturedErrorEvent + ) => any) + | null; + + 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 GPUTexelCopyBufferInfo + extends GPUTexelCopyBufferLayout { + /** + * A buffer which either contains texel data to be copied or will store the texel data being + * copied, depending on the method it is being passed to. + */ + buffer: GPUBuffer; +} + +interface GPUTexelCopyBufferLayout { + /** + * The offset, in bytes, from the beginning of the texel data source (such as a + * {@link GPUTexelCopyBufferInfo#buffer|GPUTexelCopyBufferInfo.buffer}) to the start of the texel data + * within that source. + */ + offset?: GPUSize64; + /** + * The stride, in bytes, between the beginning of each texel block row and the subsequent + * texel block row. + * Required if there are multiple texel block rows (i.e. the copy height or depth is more + * than one block). + */ + bytesPerRow?: GPUSize32; + /** + * Number of texel block rows per single texel image of the texture. + * {@link GPUTexelCopyBufferLayout#rowsPerImage} × + * {@link GPUTexelCopyBufferLayout#bytesPerRow} is the stride, in bytes, between the beginning of each + * texel image of data and the subsequent texel image. + * Required if there are multiple texel images (i.e. the copy depth is more than one). + */ + rowsPerImage?: GPUSize32; +} + +interface GPUTexelCopyTextureInfo { + /** + * Texture to copy to/from. + */ + texture: GPUTexture; + /** + * Mip-map level of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + mipLevel?: GPUIntegerCoordinate; + /** + * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. + * Together with `copySize`, defines the full copy sub-region. + */ + origin?: GPUOrigin3D; + /** + * Defines which aspects of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + aspect?: GPUTextureAspect; +} + +interface GPUCopyExternalImageDestInfo + extends GPUTexelCopyTextureInfo { + /** + * Describes the color space and encoding used to encode data into the destination texture. + * This [[#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 may not be necessary. See [[#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 may not be necessary. See [[#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; +} + +/** @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; diff --git a/generate.mjs b/generate.mjs index 24240bb..a00fd7f 100644 --- a/generate.mjs +++ b/generate.mjs @@ -59,6 +59,10 @@ function fixupGenerated(filename) { const constructableRE = new RegExp(`(\\ndeclare var (${constructables.join('|')}):\\s{\\n[\\s\\S]*?\\snew\\s\\([^;]*?\\));\\n};`, 'g'); s = s.replace(constructableRE, '$1: $2;\n};'); + // prepend extra + const extra = fs.readFileSync('extra.d.ts', { encoding: 'utf-8' }); + s = extra + s; + fs.writeFileSync(filename, s); } diff --git a/generated/index.d.ts b/generated/index.d.ts index af8f520..ad534c0 100644 --- a/generated/index.d.ts +++ b/generated/index.d.ts @@ -1,3 +1,256 @@ +// ********************************************************************************************* +// This file is manually-edited by diffing against an autogenerated file. See README.md. +// ********************************************************************************************* + +// ********************************************************************************************* +// Manually-written +// ********************************************************************************************* + +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 {} + +type GPUOrigin2DStrict = + + | Iterable + | GPUOrigin2DDictStrict; + +interface GPUOrigin2DDictStrict + extends GPUOrigin2DDict { + /** @deprecated Does not exist for GPUOrigin2D. */ + z?: undefined; +} + +type GPUExtent3DStrict = + + | Iterable + | GPUExtent3DDictStrict; + +// GPUExtent3DDictStrict is 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.) +interface GPUExtent3DDictStrict + extends GPUExtent3DDict { + /** @deprecated The correct name is `depthOrArrayLayers`. */ + depth?: undefined; +} + +interface GPUCanvasConfigurationOut + extends Required< + Omit< + GPUCanvasConfiguration, + "toneMapping" + > + > { + /** {@inheritDoc GPUCanvasConfiguration.viewFormats} */ + viewFormats: GPUTextureFormat[]; + /** + * {@inheritDoc GPUCanvasConfiguration.toneMapping} + */ + toneMapping?: GPUCanvasToneMapping; +} + +interface GPUTextureDescriptor { + /** + * **PROPOSED** addition for Compatibility Mode: + * + * + * > [In compatibility mode,] + * > When specifying a texture, a textureBindingViewDimension property + * > determines the views which can be bound from that texture for sampling. + * > Binding a view of a different dimension for sampling than specified at + * > texture creation time will cause a validation error. + */ + textureBindingViewDimension?: GPUTextureViewDimension; +} + +/** @internal */ +interface __GPUDeviceEventMap { + uncapturederror: GPUUncapturedErrorEvent; +} + +interface GPUDevice { + /** + * An event handler IDL attribute for the {@link GPUDevice#uncapturederror} event type. + */ + onuncapturederror: + | (( + this: GPUDevice, + ev: GPUUncapturedErrorEvent + ) => any) + | null; + + 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 GPUTexelCopyBufferInfo + extends GPUTexelCopyBufferLayout { + /** + * A buffer which either contains texel data to be copied or will store the texel data being + * copied, depending on the method it is being passed to. + */ + buffer: GPUBuffer; +} + +interface GPUTexelCopyBufferLayout { + /** + * The offset, in bytes, from the beginning of the texel data source (such as a + * {@link GPUTexelCopyBufferInfo#buffer|GPUTexelCopyBufferInfo.buffer}) to the start of the texel data + * within that source. + */ + offset?: GPUSize64; + /** + * The stride, in bytes, between the beginning of each texel block row and the subsequent + * texel block row. + * Required if there are multiple texel block rows (i.e. the copy height or depth is more + * than one block). + */ + bytesPerRow?: GPUSize32; + /** + * Number of texel block rows per single texel image of the texture. + * {@link GPUTexelCopyBufferLayout#rowsPerImage} × + * {@link GPUTexelCopyBufferLayout#bytesPerRow} is the stride, in bytes, between the beginning of each + * texel image of data and the subsequent texel image. + * Required if there are multiple texel images (i.e. the copy depth is more than one). + */ + rowsPerImage?: GPUSize32; +} + +interface GPUTexelCopyTextureInfo { + /** + * Texture to copy to/from. + */ + texture: GPUTexture; + /** + * Mip-map level of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + mipLevel?: GPUIntegerCoordinate; + /** + * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. + * Together with `copySize`, defines the full copy sub-region. + */ + origin?: GPUOrigin3D; + /** + * Defines which aspects of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. + */ + aspect?: GPUTextureAspect; +} + +interface GPUCopyExternalImageDestInfo + extends GPUTexelCopyTextureInfo { + /** + * Describes the color space and encoding used to encode data into the destination texture. + * This [[#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 may not be necessary. See [[#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 may not be necessary. See [[#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; +} + +/** @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; type GPUBindingResource = | GPUSampler @@ -10,24 +263,15 @@ type GPUBufferUsageFlags = number; type GPUColor = - | Array + | Iterable | GPUColorDict; type GPUColorWriteFlags = number; -type GPUCopyExternalImageSource = - - | ImageBitmap - | ImageData - | HTMLImageElement - | HTMLVideoElement - | VideoFrame - | HTMLCanvasElement - | OffscreenCanvas; type GPUDepthBias = number; type GPUExtent3D = - | Array + | Iterable | GPUExtent3DDict; type GPUFlagsConstant = number; @@ -41,11 +285,11 @@ type GPUMapModeFlags = number; type GPUOrigin2D = - | Array + | Iterable | GPUOrigin2DDict; type GPUOrigin3D = - | Array + | Iterable | GPUOrigin3DDict; type GPUPipelineConstantValue = number; @@ -408,7 +652,7 @@ interface GPUBindGroupDescriptor * A list of entries describing the resources to expose to the shader for each binding * described by the {@link GPUBindGroupDescriptor#layout}. */ - entries: Array; + entries: Iterable; } interface GPUBindGroupEntry { @@ -430,7 +674,7 @@ interface GPUBindGroupLayoutDescriptor /** * A list of entries describing the shader resource bindings for a bind group. */ - entries: Array; + entries: Iterable; } interface GPUBindGroupLayoutEntry { @@ -592,7 +836,7 @@ interface GPUCanvasConfiguration { * The formats that views created from textures returned by * {@link GPUCanvasContext#getCurrentTexture} may use. */ - viewFormats?: Array; + viewFormats?: Iterable; /** * The color space that values written into textures returned by * {@link GPUCanvasContext#getCurrentTexture} should be displayed with. @@ -691,53 +935,6 @@ interface GPUComputePipelineDescriptor compute: GPUProgrammableStage; } -interface GPUCopyExternalImageDestInfo - extends GPUTexelCopyTextureInfo { - /** - * Describes the color space and encoding used to encode data into the destination texture. - * This [[#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 may not be necessary. See [[#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 may not be necessary. See [[#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} @@ -794,7 +991,7 @@ interface GPUDeviceDescriptor * Exactly the specified set of features, and no more or less, will be allowed in validation * of API calls on the resulting device. */ - requiredFeatures?: Array; + requiredFeatures?: Iterable; /** * Specifies the limits that are required by the device request. * The request will fail if the adapter cannot provide these limits. @@ -859,7 +1056,11 @@ interface GPUFragmentState * A list of {@link GPUColorTargetState} defining the formats and behaviors of the color targets * this pipeline writes to. */ - targets: Array; + targets: Iterable< + | GPUColorTargetState + | null + | undefined + >; } interface GPUMultisampleState { @@ -923,7 +1124,11 @@ interface GPUPipelineLayoutDescriptor * to a @group attribute in the {@link GPUShaderModule}, with the `N`th element corresponding * with `@group(N)`. */ - bindGroupLayouts: Array; + bindGroupLayouts: Iterable< + | GPUBindGroupLayout + | null + | undefined + >; } interface GPUPrimitiveState { @@ -1176,7 +1381,11 @@ interface GPURenderPassDescriptor * Due to compatible usage list|usage compatibility, no color attachment * may alias another attachment or any resource used inside the render pass. */ - colorAttachments: Array; + 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. @@ -1205,7 +1414,11 @@ interface GPURenderPassLayout /** * A list of the {@link GPUTextureFormat}s of the color attachments for this pass or bundle. */ - colorFormats: Array; + colorFormats: Iterable< + | GPUTextureFormat + | null + | undefined + >; /** * The {@link GPUTextureFormat} of the depth/stencil attachment for this pass or bundle. */ @@ -1387,7 +1600,7 @@ interface GPUShaderModuleDescriptor * errors (like unknown entry point names or incompatible pipeline layouts) to developers, * for example in the browser developer console. */ - compilationHints?: Array; + compilationHints?: Iterable; } interface GPUStencilFaceState { @@ -1429,59 +1642,6 @@ interface GPUStorageTextureBindingLayout { viewDimension?: GPUTextureViewDimension; } -interface GPUTexelCopyBufferInfo - extends GPUTexelCopyBufferLayout { - /** - * A buffer which either contains texel data to be copied or will store the texel data being - * copied, depending on the method it is being passed to. - */ - buffer: GPUBuffer; -} - -interface GPUTexelCopyBufferLayout { - /** - * The offset, in bytes, from the beginning of the texel data source (such as a - * {@link GPUTexelCopyBufferInfo#buffer|GPUTexelCopyBufferInfo.buffer}) to the start of the texel data - * within that source. - */ - offset?: GPUSize64; - /** - * The stride, in bytes, between the beginning of each texel block row and the subsequent - * texel block row. - * Required if there are multiple texel block rows (i.e. the copy height or depth is more - * than one block). - */ - bytesPerRow?: GPUSize32; - /** - * Number of texel block rows per single texel image of the texture. - * {@link GPUTexelCopyBufferLayout#rowsPerImage} × - * {@link GPUTexelCopyBufferLayout#bytesPerRow} is the stride, in bytes, between the beginning of each - * texel image of data and the subsequent texel image. - * Required if there are multiple texel images (i.e. the copy depth is more than one). - */ - rowsPerImage?: GPUSize32; -} - -interface GPUTexelCopyTextureInfo { - /** - * Texture to copy to/from. - */ - texture: GPUTexture; - /** - * Mip-map level of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. - */ - mipLevel?: GPUIntegerCoordinate; - /** - * Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. - * Together with `copySize`, defines the full copy sub-region. - */ - origin?: GPUOrigin3D; - /** - * Defines which aspects of the {@link GPUTexelCopyTextureInfo#texture} to copy to/from. - */ - aspect?: GPUTextureAspect; -} - interface GPUTextureBindingLayout { /** * Indicates the type required for texture views bound to this binding. @@ -1503,7 +1663,7 @@ interface GPUTextureDescriptor /** * The width, height, and depth or layer count of the texture. */ - size: GPUExtent3D; + size: GPUExtent3DStrict; /** * The number of mip levels the texture will contain. */ @@ -1547,7 +1707,7 @@ interface GPUTextureDescriptor * - `format` and `viewFormat` differ only in whether they are `srgb` formats (have the `-srgb` suffix). * */ - viewFormats?: Array; + viewFormats?: Iterable; } interface GPUTextureViewDescriptor @@ -1628,7 +1788,7 @@ interface GPUVertexBufferLayout { /** * An array defining the layout of the vertex attributes within each element. */ - attributes: Array; + attributes: Iterable; } interface GPUVertexState @@ -1637,7 +1797,11 @@ interface GPUVertexState * A list of {@link GPUVertexBufferLayout}s, each defining the layout of vertex attribute data in a * vertex buffer used by this pipeline. */ - buffers?: Array; + buffers?: Iterable< + | GPUVertexBufferLayout + | null + | undefined + >; } interface GPUBindingCommandsMixin { @@ -1646,12 +1810,18 @@ interface GPUBindingCommandsMixin { */ setBindGroup( index: GPUIndex32, - bindGroup: GPUBindGroup | null, - dynamicOffsets?: Array + bindGroup: + | GPUBindGroup + | null + | undefined, + dynamicOffsets?: Iterable ): undefined; setBindGroup( index: GPUIndex32, - bindGroup: GPUBindGroup | null, + bindGroup: + | GPUBindGroup + | null + | undefined, dynamicOffsetsData: Uint32Array, dynamicOffsetsDataStart: GPUSize64, dynamicOffsetsDataLength: GPUSize32 @@ -1729,7 +1899,10 @@ interface GPURenderCommandsMixin { */ setVertexBuffer( slot: GPUIndex32, - buffer: GPUBuffer | null, + buffer: + | GPUBuffer + | null + | undefined, offset?: GPUSize64, size?: GPUSize64 ): undefined; @@ -1800,6 +1973,7 @@ interface GPU { declare var GPU: { prototype: GPU; + new (): never; }; interface GPUAdapter { @@ -1826,6 +2000,7 @@ interface GPUAdapter { declare var GPUAdapter: { prototype: GPUAdapter; + new (): never; }; interface GPUAdapterInfo { @@ -1843,6 +2018,7 @@ interface GPUAdapterInfo { declare var GPUAdapterInfo: { prototype: GPUAdapterInfo; + new (): never; }; interface GPUBindGroup @@ -1857,6 +2033,7 @@ interface GPUBindGroup declare var GPUBindGroup: { prototype: GPUBindGroup; + new (): never; }; interface GPUBindGroupLayout @@ -1871,6 +2048,7 @@ interface GPUBindGroupLayout declare var GPUBindGroupLayout: { prototype: GPUBindGroupLayout; + new (): never; }; interface GPUBuffer @@ -1930,6 +2108,7 @@ interface GPUBuffer declare var GPUBuffer: { prototype: GPUBuffer; + new (): never; }; interface GPUCanvasContext { @@ -1970,6 +2149,7 @@ interface GPUCanvasContext { declare var GPUCanvasContext: { prototype: GPUCanvasContext; + new (): never; }; interface GPUCommandBuffer @@ -1984,6 +2164,7 @@ interface GPUCommandBuffer declare var GPUCommandBuffer: { prototype: GPUCommandBuffer; + new (): never; }; interface GPUCommandEncoder @@ -2032,7 +2213,7 @@ interface GPUCommandEncoder copyBufferToTexture( source: GPUTexelCopyBufferInfo, destination: GPUTexelCopyTextureInfo, - copySize: GPUExtent3D + copySize: GPUExtent3DStrict ): undefined; /** * Encode a command into the {@link GPUCommandEncoder} that copies data from a sub-region of one or @@ -2044,7 +2225,7 @@ interface GPUCommandEncoder copyTextureToBuffer( source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyBufferInfo, - copySize: GPUExtent3D + copySize: GPUExtent3DStrict ): undefined; /** * Encode a command into the {@link GPUCommandEncoder} that copies data from a sub-region of one @@ -2057,7 +2238,7 @@ interface GPUCommandEncoder copyTextureToTexture( source: GPUTexelCopyTextureInfo, destination: GPUTexelCopyTextureInfo, - copySize: GPUExtent3D + copySize: GPUExtent3DStrict ): undefined; /** * Encode a command into the {@link GPUCommandEncoder} that fills a sub-region of a @@ -2097,6 +2278,7 @@ interface GPUCommandEncoder declare var GPUCommandEncoder: { prototype: GPUCommandEncoder; + new (): never; }; interface GPUCompilationInfo { @@ -2111,6 +2293,7 @@ interface GPUCompilationInfo { declare var GPUCompilationInfo: { prototype: GPUCompilationInfo; + new (): never; }; interface GPUCompilationMessage { @@ -2130,6 +2313,7 @@ interface GPUCompilationMessage { declare var GPUCompilationMessage: { prototype: GPUCompilationMessage; + new (): never; }; interface GPUComputePassEncoder @@ -2184,6 +2368,7 @@ interface GPUComputePassEncoder declare var GPUComputePassEncoder: { prototype: GPUComputePassEncoder; + new (): never; }; interface GPUComputePipeline @@ -2199,6 +2384,7 @@ interface GPUComputePipeline declare var GPUComputePipeline: { prototype: GPUComputePipeline; + new (): never; }; interface GPUDevice @@ -2364,6 +2550,7 @@ interface GPUDevice declare var GPUDevice: { prototype: GPUDevice; + new (): never; }; interface GPUDeviceLostInfo { @@ -2379,6 +2566,7 @@ interface GPUDeviceLostInfo { declare var GPUDeviceLostInfo: { prototype: GPUDeviceLostInfo; + new (): never; }; interface GPUError { @@ -2387,6 +2575,7 @@ interface GPUError { declare var GPUError: { prototype: GPUError; + new (): never; }; interface GPUExternalTexture @@ -2401,6 +2590,7 @@ interface GPUExternalTexture declare var GPUExternalTexture: { prototype: GPUExternalTexture; + new (): never; }; interface GPUInternalError @@ -2417,7 +2607,7 @@ declare var GPUInternalError: { prototype: GPUInternalError; new ( message: string - ); + ): GPUInternalError; }; interface GPUOutOfMemoryError @@ -2434,7 +2624,7 @@ declare var GPUOutOfMemoryError: { prototype: GPUOutOfMemoryError; new ( message: string - ); + ): GPUOutOfMemoryError; }; interface GPUPipelineError @@ -2453,7 +2643,7 @@ declare var GPUPipelineError: { new ( message?: string, options: GPUPipelineErrorInit - ); + ): GPUPipelineError; }; interface GPUPipelineLayout @@ -2468,6 +2658,7 @@ interface GPUPipelineLayout declare var GPUPipelineLayout: { prototype: GPUPipelineLayout; + new (): never; }; interface GPUQuerySet @@ -2488,6 +2679,7 @@ interface GPUQuerySet declare var GPUQuerySet: { prototype: GPUQuerySet; + new (): never; }; interface GPUQueue @@ -2504,7 +2696,7 @@ interface GPUQueue * `commandBuffers`: */ submit( - commandBuffers: Array + commandBuffers: Iterable ): undefined; onSubmittedWorkDone(): Promise; /** @@ -2520,7 +2712,9 @@ interface GPUQueue writeBuffer( buffer: GPUBuffer, bufferOffset: GPUSize64, - data: AllowSharedBufferSource, + data: + | BufferSource + | SharedArrayBuffer, dataOffset?: GPUSize64, size?: GPUSize64 ): undefined; @@ -2533,9 +2727,11 @@ interface GPUQueue */ writeTexture( destination: GPUTexelCopyTextureInfo, - data: AllowSharedBufferSource, + data: + | BufferSource + | SharedArrayBuffer, dataLayout: GPUTexelCopyBufferLayout, - size: GPUExtent3D + size: GPUExtent3DStrict ): undefined; /** * Issues a copy operation of the contents of a platform image/canvas @@ -2554,12 +2750,13 @@ interface GPUQueue copyExternalImageToTexture( source: GPUCopyExternalImageSourceInfo, destination: GPUCopyExternalImageDestInfo, - copySize: GPUExtent3D + copySize: GPUExtent3DStrict ): undefined; } declare var GPUQueue: { prototype: GPUQueue; + new (): never; }; interface GPURenderBundle @@ -2574,6 +2771,7 @@ interface GPURenderBundle declare var GPURenderBundle: { prototype: GPURenderBundle; + new (): never; }; interface GPURenderBundleEncoder @@ -2599,6 +2797,7 @@ interface GPURenderBundleEncoder declare var GPURenderBundleEncoder: { prototype: GPURenderBundleEncoder; + new (): never; }; interface GPURenderPassEncoder @@ -2683,7 +2882,7 @@ interface GPURenderPassEncoder * @param bundles - List of render bundles to execute. */ executeBundles( - bundles: Array + bundles: Iterable ): undefined; /** * Completes recording of the render pass commands sequence. @@ -2693,6 +2892,7 @@ interface GPURenderPassEncoder declare var GPURenderPassEncoder: { prototype: GPURenderPassEncoder; + new (): never; }; interface GPURenderPipeline @@ -2708,6 +2908,7 @@ interface GPURenderPipeline declare var GPURenderPipeline: { prototype: GPURenderPipeline; + new (): never; }; interface GPUSampler @@ -2722,6 +2923,7 @@ interface GPUSampler declare var GPUSampler: { prototype: GPUSampler; + new (): never; }; interface GPUShaderModule @@ -2742,6 +2944,7 @@ interface GPUShaderModule declare var GPUShaderModule: { prototype: GPUShaderModule; + new (): never; }; type GPUSupportedFeatures = @@ -2789,6 +2992,7 @@ interface GPUSupportedLimits { declare var GPUSupportedLimits: { prototype: GPUSupportedLimits; + new (): never; }; interface GPUTexture @@ -2822,6 +3026,7 @@ interface GPUTexture declare var GPUTexture: { prototype: GPUTexture; + new (): never; }; interface GPUTextureView @@ -2836,6 +3041,7 @@ interface GPUTextureView declare var GPUTextureView: { prototype: GPUTextureView; + new (): never; }; interface GPUUncapturedErrorEvent @@ -2854,7 +3060,7 @@ declare var GPUUncapturedErrorEvent: { new ( type: string, gpuUncapturedErrorEventInitDict: GPUUncapturedErrorEventInit - ); + ): GPUUncapturedErrorEvent; }; interface GPUValidationError @@ -2871,7 +3077,7 @@ declare var GPUValidationError: { prototype: GPUValidationError; new ( message: string - ); + ): GPUValidationError; }; type WGSLLanguageFeatures = @@ -2883,7 +3089,7 @@ interface Navigator interface WorkerNavigator extends NavigatorGPU {} -interface GPUBufferUsage { +declare var GPUBufferUsage: { readonly MAP_READ: GPUFlagsConstant; readonly MAP_WRITE: GPUFlagsConstant; readonly COPY_SRC: GPUFlagsConstant; @@ -2894,31 +3100,31 @@ interface GPUBufferUsage { readonly STORAGE: GPUFlagsConstant; readonly INDIRECT: GPUFlagsConstant; readonly QUERY_RESOLVE: GPUFlagsConstant; -} +}; -interface GPUColorWrite { +declare var GPUColorWrite: { readonly RED: GPUFlagsConstant; readonly GREEN: GPUFlagsConstant; readonly BLUE: GPUFlagsConstant; readonly ALPHA: GPUFlagsConstant; readonly ALL: GPUFlagsConstant; -} +}; -interface GPUMapMode { +declare var GPUMapMode: { readonly READ: GPUFlagsConstant; readonly WRITE: GPUFlagsConstant; -} +}; -interface GPUShaderStage { +declare var GPUShaderStage: { readonly VERTEX: GPUFlagsConstant; readonly FRAGMENT: GPUFlagsConstant; readonly COMPUTE: GPUFlagsConstant; -} +}; -interface GPUTextureUsage { +declare var GPUTextureUsage: { readonly COPY_SRC: GPUFlagsConstant; readonly COPY_DST: GPUFlagsConstant; readonly TEXTURE_BINDING: GPUFlagsConstant; readonly STORAGE_BINDING: GPUFlagsConstant; readonly RENDER_ATTACHMENT: GPUFlagsConstant; -} +}; From fb0930b7773f8b5c2c2c78cd64dad8947156acf5 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Thu, 30 Jan 2025 20:51:10 -0800 Subject: [PATCH 3/3] format extra.d.ts --- extra.d.ts | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extra.d.ts b/extra.d.ts index 8f8d62b..0123d36 100644 --- a/extra.d.ts +++ b/extra.d.ts @@ -74,7 +74,7 @@ interface GPUTextureDescriptor { * > Binding a view of a different dimension for sampling than specified at * > texture creation time will cause a validation error. */ - textureBindingViewDimension?: GPUTextureViewDimension; + textureBindingViewDimension?: GPUTextureViewDimension; } /** @internal */ @@ -130,7 +130,7 @@ interface GPUDevice { options?: | boolean | EventListenerOptions - ): void; + ): void; } interface GPUTexelCopyBufferInfo diff --git a/package.json b/package.json index c47fe1a..c52460f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "test": "for t in tests/*/ ; do (cd \"$t\" && npm i && npm test); done", "build-docs": "cd tsdoc-src && npm ci && npm run build", "generate": "node generate.mjs", - "format": "prettier -w dist/index.d.ts" + "format": "prettier -w dist/index.d.ts extra.d.ts" }, "devDependencies": { "bikeshed-to-ts": "github:toji/bikeshed-to-ts",