diff --git a/cocos/gfx/webgpu/instantiated.ts b/cocos/gfx/webgpu/instantiated.ts index 9f2cb23f3d0..21a90746e16 100644 --- a/cocos/gfx/webgpu/instantiated.ts +++ b/cocos/gfx/webgpu/instantiated.ts @@ -22,13 +22,12 @@ THE SOFTWARE. */ -import { fetchBuffer, ensureWasmModuleReady, instantiateWasm } from 'pal/wasm'; +import { fetchBuffer, ensureWasmModuleReady, instantiateWasm, fetchUrl } from 'pal/wasm'; import { NATIVE_CODE_BUNDLE_MODE } from 'internal:constants'; import { error, sys } from '../../core'; import { NativeCodeBundleMode } from '../../misc/webassembly-support'; import { WebGPUWasm } from './webgpu-core'; import { overrideWebGPUDefine } from './define'; -// import { overrideSpineDefine } from './spine-define'; const PAGESIZE = 65536; // 64KiB @@ -46,21 +45,14 @@ function initWasm (wasmFactory, wasmUrl: string): Promise { return new Promise((resolve, reject) => { const errorMessage = (err: any): string => `[WebGPU]: WebGPU wasm load failed: ${err}`; // eslint-disable-next-line @typescript-eslint/no-floating-promises - wasmFactory({ - instantiateWasm ( - importObject: WebAssembly.Imports, - receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void, - ) { - instantiateWasm(wasmUrl, importObject).then((result) => { - receiveInstance(result.instance, result.module); - }).catch((err) => reject(errorMessage(err))); - }, - }).then((Instance: any) => { - wasmInstance = Instance; - registerList.forEach((cb) => { - cb(wasmInstance); - }); - }).then(resolve).catch((err: any) => reject(errorMessage(err))); + fetchUrl(wasmUrl).then((currUrl) => { + wasmFactory(currUrl).then((Instance: any) => { + wasmInstance = Instance; + registerList.forEach((cb) => { + cb(wasmInstance); + }); + }).then(resolve).catch((err: any) => reject(errorMessage(err))); + }); }); } diff --git a/cocos/gfx/webgpu/webgpu-command-buffer.ts b/cocos/gfx/webgpu/webgpu-command-buffer.ts index fd5daeed5f1..8cbfddd9d0b 100644 --- a/cocos/gfx/webgpu/webgpu-command-buffer.ts +++ b/cocos/gfx/webgpu/webgpu-command-buffer.ts @@ -630,7 +630,6 @@ export class WebGPUCommandBuffer extends CommandBuffer { } } this._curWebGPUPipelineState!.prepare(this._curGPUInputAssembler!); - const { dynamicOffsetIndices } = gpuPipelineLayout; // ----------------------------wgpu pipline state----------------------------- const wgpuPipeline = this._curGPUPipelineState.nativePipeline as GPURenderPipeline; const pplFunc = (passEncoder: GPURenderPassEncoder): void => { diff --git a/cocos/gfx/webgpu/webgpu-commands.ts b/cocos/gfx/webgpu/webgpu-commands.ts index e6fef4b4ad8..b554a1ed70c 100644 --- a/cocos/gfx/webgpu/webgpu-commands.ts +++ b/cocos/gfx/webgpu/webgpu-commands.ts @@ -37,7 +37,6 @@ import { DescriptorType, Color, Rect, Viewport, BufferTextureCopy, SamplerInfo, - BufferInfo, FormatSize, formatAlignment, alignTo, @@ -66,8 +65,6 @@ import { IWebGPUGPURenderPass, IWebGPUGPUShaderStage, } from './webgpu-gpu-objects'; -import { copy } from '../../core/utils/array'; -import { clear } from '../../asset/asset-manager/utilities'; import { error, log, warn } from '../../core'; const WebGPUAdressMode: GPUAddressMode[] = [ @@ -355,16 +352,10 @@ export function GFXTextureUsageToNative (usage: TextureUsageBit): GPUTextureUsag } if (!nativeUsage) { - // The default value is TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT - // An error will be thrown saying "Destination texture needs to have CopyDst and RenderAttachment usage." - // if you use GPUTextureUsage.COPY_DST without GPUTextureUsage.RENDER_ATTACHMENT. + // The default value is TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT nativeUsage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT; } - // if (!(nativeUsage & GPUTextureUsage.COPY_DST)) { - // nativeUsage |= GPUTextureUsage.COPY_DST; - // } - if ((nativeUsage & GPUTextureUsage.TEXTURE_BINDING) && !(nativeUsage & (GPUTextureUsage.RENDER_ATTACHMENT))) { nativeUsage |= GPUTextureUsage.RENDER_ATTACHMENT; @@ -680,9 +671,6 @@ export function WebGPUCmdFuncUpdateBuffer ( } export function WebGPUCmdFuncCreateTexture (device: WebGPUDevice, gpuTexture: IWebGPUTexture): void { - if (gpuTexture.width === 512 && gpuTexture.height === 512 && gpuTexture.format === Format.R32F) { - console.log('WebGPUCmdFuncCreateTexture shadowmap'); - } // dimension optional gpuTexture.gpuTarget = GFXTextureToWebGPUTexture(gpuTexture.type); gpuTexture.gpuInternalFmt = GFXFormatToWGPUTextureFormat(gpuTexture.format); diff --git a/cocos/gfx/webgpu/webgpu-define.ts b/cocos/gfx/webgpu/webgpu-define.ts index 0aeff61b637..1bed45dffd9 100644 --- a/cocos/gfx/webgpu/webgpu-define.ts +++ b/cocos/gfx/webgpu/webgpu-define.ts @@ -36,6 +36,7 @@ import { } from '../base/define'; import { ccwindow } from '../../core/global-exports'; +import { warn } from 'console'; WEBGPU && promiseForWebGPUInstantiation.then(() => { @@ -193,7 +194,7 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { } buffers[i] = data; } else { - console.log('imageBmp copy not impled!'); + warn('imageBmp copy not impled!'); } } @@ -216,16 +217,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { // replaceAll --> es 2021 required let code = shaderSource; - // referredMap.forEach((value, key)=> { - // const samplerName = key; - // const samplerType = value; - // const exp = new RegExp(`\\b${samplerName}\\b([^;])`); - // let it = exp.exec(code); - // while (it) { - // code = code.replace(exp, `sampler${samplerType}(_${samplerName}, _${samplerName}_sampler)${it[1]}`); - // it = exp.exec(code); - // } - // }); let sampReg = /.*?(\(set = \d+, binding = )(\d+)\) uniform[^;]+sampler(\w*) (\w+);/g; let it = sampReg.exec(code); while (it) { @@ -252,7 +243,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { const paramTypeMap = new Map(); while (funcIter) { paramTypeMap.clear(); - const params = funcIter[2]; let paramsRes = params.slice(); if (params.includes('sampler')) { @@ -270,7 +260,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { paramTypeMap.set(paramName, samplerType); } } - // let singleParamReg = new RegExp(`(\\W?)(\\w+)\\s+\\b([^,)]+)\\b`); code = code.replace(params, paramsRes); @@ -353,7 +342,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { const precisionKeyWord = 'highp'; const isNanIndex = code.indexOf('isnan'); if (isNanIndex !== -1) { - // getPrecision(isNanIndex); functionDefs += `\n bool isNan(${precisionKeyWord} float val) { return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true; @@ -364,7 +352,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => { const isInfIndex = code.indexOf('isinf'); if (isInfIndex !== -1) { - // getPrecision(isInfIndex); functionDefs += `\n bool isInf(${precisionKeyWord} float x) { return x == x * 2.0 && x != 0.0; diff --git a/cocos/gfx/webgpu/webgpu-descriptor-set.ts b/cocos/gfx/webgpu/webgpu-descriptor-set.ts index 51ee4fd8eab..6cca997e017 100644 --- a/cocos/gfx/webgpu/webgpu-descriptor-set.ts +++ b/cocos/gfx/webgpu/webgpu-descriptor-set.ts @@ -48,12 +48,7 @@ export class WebGPUDescriptorSet extends DescriptorSet { private _gpuDescriptorSet: IWebGPUGPUDescriptorSet | null = null; private _bindGroupEntries: Map = new Map(); - private _prepareEntries: GPUBindGroupEntry[] = []; - // private _currBinds: number[] = []; - // private _needUpdate: boolean = false; - // private _prepareDynOffsets: number[] = []; private _dynamicOffsets: number[] = []; - private _dynamicOffsetNum: number = 0; get dynamicOffsets (): number[] { return this._dynamicOffsets; @@ -65,7 +60,6 @@ export class WebGPUDescriptorSet extends DescriptorSet { public initialize (info: Readonly): void { const layout = this._layout = info.layout as WebGPUDescriptorSetLayout; - // layout.addRef(this); const { bindings, descriptorIndices, descriptorCount } = layout.gpuDescriptorSetLayout!; this._buffers = Array(descriptorCount).fill(null); @@ -105,7 +99,6 @@ export class WebGPUDescriptorSet extends DescriptorSet { if (destBind) { destBind.gpuBuffer = buffer.gpuBuffer; } - // const layout = this._layout as WebGPUDescriptorSetLayout; const nativeBuffer = buffer.gpuBuffer.gpuBuffer; const bindGrpEntry: GPUBindGroupEntry = { binding: bind.binding, diff --git a/cocos/gfx/webgpu/webgpu-device.ts b/cocos/gfx/webgpu/webgpu-device.ts index d890a4f9a31..ca45f1f8226 100644 --- a/cocos/gfx/webgpu/webgpu-device.ts +++ b/cocos/gfx/webgpu/webgpu-device.ts @@ -475,7 +475,6 @@ export class WebGPUDevice extends Device { defaultResource.descSet = this.createDescriptorSet(descInfo); defaultResource.descSet.bindBuffer(0, defaultResource.buffer); defaultResource.descSet.update(); - // (defaultResource.descSet as WebGPUDescriptorSet).prepare(DescUpdateFrequency.NORMAL, [0]); } private async initDevice (info: Readonly): Promise { @@ -557,7 +556,6 @@ export class WebGPUDevice extends Device { this._features[Feature.ELEMENT_INDEX_UINT] = true; this._features[Feature.INSTANCED_ARRAYS] = true; this._features[Feature.MULTIPLE_RENDER_TARGETS] = true; - // this._features[Feature.BLEND_MINMAX] = true; this.initFormatFeatures(features); this._queue = this.createQueue(new QueueInfo(QueueType.GRAPHICS)); diff --git a/cocos/gfx/webgpu/webgpu-pipeline-layout.ts b/cocos/gfx/webgpu/webgpu-pipeline-layout.ts index 2acd08898ef..7bb6e41eeed 100644 --- a/cocos/gfx/webgpu/webgpu-pipeline-layout.ts +++ b/cocos/gfx/webgpu/webgpu-pipeline-layout.ts @@ -64,7 +64,6 @@ export class WebGPUPipelineLayout extends PipelineLayout { } this._bindGrpLayouts[i] = bindGroupLayout; } - // setLayout.resetChange(); } this._nativePipelineLayout = nativeDevice?.createPipelineLayout({ bindGroupLayouts: this._bindGrpLayouts }) as GPUPipelineLayout;