From dafe63ff779c553de7fbbed195bd5a92523d81c0 Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Thu, 28 Nov 2024 10:18:39 +0800 Subject: [PATCH 1/3] Fix the error caused by the lag in the WebGPU API --- @types/webGPU.d.ts | 1144 +++++++++++++++-------------- cocos/gfx/webgpu/webgpu-device.ts | 6 +- 2 files changed, 587 insertions(+), 563 deletions(-) diff --git a/@types/webGPU.d.ts b/@types/webGPU.d.ts index 8b2bebe872b..7530f67d501 100644 --- a/@types/webGPU.d.ts +++ b/@types/webGPU.d.ts @@ -9,14 +9,14 @@ interface HTMLCanvasElement { getContext( contextId: - | 'webgpu' + | "webgpu" ): GPUCanvasContext | null; } interface OffscreenCanvas { getContext( contextId: - | 'webgpu' + | "webgpu" ): GPUCanvasContext | null; } @@ -68,15 +68,7 @@ type GPUColor = | GPUColorDict; type GPUColorWriteFlags = number; -type GPUDepthBias = - number; -type GPUExtent3D = - - | Iterable - | GPUExtent3DDict; -type GPUFlagsConstant = - number; -type GPUImageCopyExternalImageSource = +type GPUCopyExternalImageSource = | ImageBitmap | ImageData @@ -85,6 +77,14 @@ type GPUImageCopyExternalImageSource = | VideoFrame | HTMLCanvasElement | OffscreenCanvas; +type GPUDepthBias = + number; +type GPUExtent3D = + + | Iterable + | GPUExtent3DDict; +type GPUFlagsConstant = + number; type GPUIndex32 = number; type GPUIntegerCoordinate = @@ -123,311 +123,334 @@ type GPUTextureUsageFlags = number; type GPUAddressMode = - | 'clamp-to-edge' - | 'repeat' - | 'mirror-repeat'; + | "clamp-to-edge" + | "repeat" + | "mirror-repeat"; type GPUAutoLayoutMode = - 'auto'; + "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'; + | "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'; + | "add" + | "subtract" + | "reverse-subtract" + | "min" + | "max"; type GPUBufferBindingType = - | 'uniform' - | 'storage' - | 'read-only-storage'; + | "uniform" + | "storage" + | "read-only-storage"; type GPUBufferMapState = - | 'unmapped' - | 'pending' - | 'mapped'; + | "unmapped" + | "pending" + | "mapped"; type GPUCanvasAlphaMode = - | 'opaque' - | 'premultiplied'; + | "opaque" + | "premultiplied"; +type GPUCanvasToneMappingMode = + + | "standard" + | "extended"; type GPUCompareFunction = - | 'never' - | 'less' - | 'equal' - | 'less-equal' - | 'greater' - | 'not-equal' - | 'greater-equal' - | 'always'; + | "never" + | "less" + | "equal" + | "less-equal" + | "greater" + | "not-equal" + | "greater-equal" + | "always"; type GPUCompilationMessageType = - | 'error' - | 'warning' - | 'info'; + | "error" + | "warning" + | "info"; type GPUCullMode = - | 'none' - | 'front' - | 'back'; + | "none" + | "front" + | "back"; type GPUDeviceLostReason = - | 'unknown' - | 'destroyed'; + | "unknown" + | "destroyed"; type GPUErrorFilter = - | 'validation' - | 'out-of-memory' - | 'internal'; + | "validation" + | "out-of-memory" + | "internal"; type GPUFeatureName = - | 'depth-clip-control' - | 'depth32float-stencil8' - | 'texture-compression-bc' - | 'texture-compression-etc2' - | 'texture-compression-astc' - | 'timestamp-query' - | 'indirect-first-instance' - | 'shader-f16' - | 'rg11b10ufloat-renderable' - | 'bgra8unorm-storage' - | 'float32-filterable'; + | "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"; type GPUFilterMode = - | 'nearest' - | 'linear'; + | "nearest" + | "linear"; type GPUFrontFace = - | 'ccw' - | 'cw'; + | "ccw" + | "cw"; type GPUIndexFormat = - | 'uint16' - | 'uint32'; + | "uint16" + | "uint32"; type GPULoadOp = - | 'load' - | 'clear'; + | "load" + | "clear"; type GPUMipmapFilterMode = - | 'nearest' - | 'linear'; + | "nearest" + | "linear"; type GPUPipelineErrorReason = - | 'validation' - | 'internal'; + | "validation" + | "internal"; type GPUPowerPreference = - | 'low-power' - | 'high-performance'; + | "low-power" + | "high-performance"; type GPUPrimitiveTopology = - | 'point-list' - | 'line-list' - | 'line-strip' - | 'triangle-list' - | 'triangle-strip'; + | "point-list" + | "line-list" + | "line-strip" + | "triangle-list" + | "triangle-strip"; type GPUQueryType = - | 'occlusion' - | 'timestamp'; + | "occlusion" + | "timestamp"; type GPUSamplerBindingType = - | 'filtering' - | 'non-filtering' - | 'comparison'; + | "filtering" + | "non-filtering" + | "comparison"; type GPUStencilOperation = - | 'keep' - | 'zero' - | 'replace' - | 'invert' - | 'increment-clamp' - | 'decrement-clamp' - | 'increment-wrap' - | 'decrement-wrap'; + | "keep" + | "zero" + | "replace" + | "invert" + | "increment-clamp" + | "decrement-clamp" + | "increment-wrap" + | "decrement-wrap"; type GPUStorageTextureAccess = - | 'write-only' - | 'read-only' - | 'read-write'; + | "write-only" + | "read-only" + | "read-write"; type GPUStoreOp = - | 'store' - | 'discard'; + | "store" + | "discard"; type GPUTextureAspect = - | 'all' - | 'stencil-only' - | 'depth-only'; + | "all" + | "stencil-only" + | "depth-only"; type GPUTextureDimension = - | '1d' - | '2d' - | '3d'; + | "1d" + | "2d" + | "3d"; type GPUTextureFormat = - | 'r8unorm' - | 'r8snorm' - | 'r8uint' - | 'r8sint' - | 'r16uint' - | 'r16sint' - | 'r16float' - | 'rg8unorm' - | 'rg8snorm' - | 'rg8uint' - | 'rg8sint' - | 'r32uint' - | 'r32sint' - | 'r32float' - | 'rg16uint' - | 'rg16sint' - | 'rg16float' - | 'rgba8unorm' - | 'rgba8unorm-srgb' - | 'rgba8snorm' - | 'rgba8uint' - | 'rgba8sint' - | 'bgra8unorm' - | 'bgra8unorm-srgb' - | 'rgb9e5ufloat' - | 'rgb10a2uint' - | 'rgb10a2unorm' - | 'rg11b10ufloat' - | 'rg32uint' - | 'rg32sint' - | 'rg32float' - | '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'; + | "r8unorm" + | "r8snorm" + | "r8uint" + | "r8sint" + | "r16uint" + | "r16sint" + | "r16float" + | "rg8unorm" + | "rg8snorm" + | "rg8uint" + | "rg8sint" + | "r32uint" + | "r32sint" + | "r32float" + | "rg16uint" + | "rg16sint" + | "rg16float" + | "rgba8unorm" + | "rgba8unorm-srgb" + | "rgba8snorm" + | "rgba8uint" + | "rgba8sint" + | "bgra8unorm" + | "bgra8unorm-srgb" + | "rgb9e5ufloat" + | "rgb10a2uint" + | "rgb10a2unorm" + | "rg11b10ufloat" + | "rg32uint" + | "rg32sint" + | "rg32float" + | "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'; + | "float" + | "unfilterable-float" + | "depth" + | "sint" + | "uint"; type GPUTextureViewDimension = - | '1d' - | '2d' - | '2d-array' - | 'cube' - | 'cube-array' - | '3d'; + | "1d" + | "2d" + | "2d-array" + | "cube" + | "cube-array" + | "3d"; type GPUVertexFormat = - | 'uint8x2' - | 'uint8x4' - | 'sint8x2' - | 'sint8x4' - | 'unorm8x2' - | 'unorm8x4' - | 'snorm8x2' - | 'snorm8x4' - | 'uint16x2' - | 'uint16x4' - | 'sint16x2' - | 'sint16x4' - | 'unorm16x2' - | 'unorm16x4' - | 'snorm16x2' - | 'snorm16x4' - | 'float16x2' - | 'float16x4' - | 'float32' - | 'float32x2' - | 'float32x3' - | 'float32x4' - | 'uint32' - | 'uint32x2' - | 'uint32x3' - | 'uint32x4' - | 'sint32' - | 'sint32x2' - | 'sint32x3' - | 'sint32x4' - | 'unorm10-10-10-2'; + | "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'; + | "vertex" + | "instance"; interface GPUBindGroupDescriptor extends GPUObjectDescriptorBase { @@ -458,6 +481,9 @@ interface GPUBindGroupEntry { interface GPUBindGroupLayoutDescriptor extends GPUObjectDescriptorBase { + /** + * A list of entries describing the shader resource bindings for a bind group. + */ entries: Iterable; } @@ -574,7 +600,7 @@ interface GPUBufferBindingLayout { */ minBindingSize?: GPUSize64; } -type PredefinedGPUColorSpace = 'display-p3' | 'srgb'; + interface GPUBufferDescriptor extends GPUObjectDescriptorBase { /** @@ -625,7 +651,12 @@ interface GPUCanvasConfiguration { * The color space that values written into textures returned by * {@link GPUCanvasContext#getCurrentTexture} should be displayed with. */ - colorSpace?: PredefinedGPUColorSpace; + colorSpace?: PredefinedColorSpace; + /** + * The tone mapping determines how the content of textures returned by + * {@link GPUCanvasContext#getCurrentTexture} are to be displayed. + */ + 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. @@ -633,6 +664,25 @@ 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; +} + interface GPUColorDict { /** * The red channel value. @@ -709,6 +759,53 @@ 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} @@ -744,15 +841,15 @@ interface GPUDepthStencilState { */ stencilWriteMask?: GPUStencilValue; /** - * Constant depth bias added to each fragment. See [$biased fragment depth$] for details. + * Constant depth bias added to each triangle fragment. See [$biased fragment depth$] for details. */ depthBias?: GPUDepthBias; /** - * Depth bias that scales with the fragment’s slope. See [$biased fragment depth$] for details. + * Depth bias that scales with the triangle fragment’s slope. See [$biased fragment depth$] for details. */ depthBiasSlopeScale?: number; /** - * The maximum depth bias of a fragment. See [$biased fragment depth$] for details. + * The maximum depth bias of a triangle fragment. See [$biased fragment depth$] for details. */ depthBiasClamp?: number; } @@ -769,9 +866,9 @@ interface GPUDeviceDescriptor /** * Specifies the limits that are required by the device request. * The request will fail if the adapter cannot provide these limits. - * Each key must be the name of a member of supported limits. - * Exactly the specified limits, and no limit/better or worse, - * will be allowed in validation of API calls on the resulting device. + * 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 [[#limits]]). *