Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS committed Feb 26, 2025
1 parent ba9df78 commit 6fa7f75
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 56 deletions.
26 changes: 9 additions & 17 deletions cocos/gfx/webgpu/instantiated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -46,21 +45,14 @@ function initWasm (wasmFactory, wasmUrl: string): Promise<void> {
return new Promise<void>((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)));
});
});
}

Expand Down
1 change: 0 additions & 1 deletion cocos/gfx/webgpu/webgpu-command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
14 changes: 1 addition & 13 deletions cocos/gfx/webgpu/webgpu-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
DescriptorType,
Color, Rect, Viewport, BufferTextureCopy,
SamplerInfo,
BufferInfo,
FormatSize,
formatAlignment,
alignTo,
Expand Down Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 2 additions & 15 deletions cocos/gfx/webgpu/webgpu-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from '../base/define';

import { ccwindow } from '../../core/global-exports';
import { warn } from 'console';


WEBGPU && promiseForWebGPUInstantiation.then(() => {
Expand Down Expand Up @@ -193,7 +194,7 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
}
buffers[i] = data;
} else {
console.log('imageBmp copy not impled!');
warn('imageBmp copy not impled!');
}
}

Expand All @@ -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) {
Expand All @@ -252,7 +243,6 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
const paramTypeMap = new Map<string, string>();
while (funcIter) {
paramTypeMap.clear();

const params = funcIter[2];
let paramsRes = params.slice();
if (params.includes('sampler')) {
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions cocos/gfx/webgpu/webgpu-descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ export class WebGPUDescriptorSet extends DescriptorSet {

private _gpuDescriptorSet: IWebGPUGPUDescriptorSet | null = null;
private _bindGroupEntries: Map<number, GPUBindGroupEntry> = new Map<number, GPUBindGroupEntry>();
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;
Expand All @@ -65,7 +60,6 @@ export class WebGPUDescriptorSet extends DescriptorSet {

public initialize (info: Readonly<DescriptorSetInfo>): void {
const layout = this._layout = info.layout as WebGPUDescriptorSetLayout;
// layout.addRef(this);
const { bindings, descriptorIndices, descriptorCount } = layout.gpuDescriptorSetLayout!;

this._buffers = Array(descriptorCount).fill(null);
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions cocos/gfx/webgpu/webgpu-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceInfo>): Promise<boolean> {
Expand Down Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion cocos/gfx/webgpu/webgpu-pipeline-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class WebGPUPipelineLayout extends PipelineLayout {
}
this._bindGrpLayouts[i] = bindGroupLayout;
}
// setLayout.resetChange();
}

this._nativePipelineLayout = nativeDevice?.createPipelineLayout({ bindGroupLayouts: this._bindGrpLayouts }) as GPUPipelineLayout;
Expand Down

0 comments on commit 6fa7f75

Please sign in to comment.