From 02272115a232fdf35db1c192fc1bae93b246ad16 Mon Sep 17 00:00:00 2001 From: GengineJS <476393671@qq.com> Date: Wed, 22 Jan 2025 13:43:08 +0800 Subject: [PATCH] Fixed the issue where the testlist was not displayed. --- cocos/gfx/webgpu/webgpu-command-buffer.ts | 9 ++- .../webgpu/webgpu-descriptor-set-layout.ts | 66 +++---------------- 2 files changed, 15 insertions(+), 60 deletions(-) diff --git a/cocos/gfx/webgpu/webgpu-command-buffer.ts b/cocos/gfx/webgpu/webgpu-command-buffer.ts index bbf78aa3909..61ce824ceb1 100644 --- a/cocos/gfx/webgpu/webgpu-command-buffer.ts +++ b/cocos/gfx/webgpu/webgpu-command-buffer.ts @@ -615,6 +615,7 @@ export class WebGPUCommandBuffer extends CommandBuffer { } const gpuPipelineLayout = this._curGPUPipelineState.gpuPipelineLayout as IWebGPUGPUPipelineLayout; const wgpuPipLayout = (currPipelineState?.pipelineLayout as WebGPUPipelineLayout); + const device = WebGPUDeviceManager.instance; for (let i = 0; i < groupSets.length; i++) { const currSetIdx = groupSets[i]; const currDesc = descriptorSets[currSetIdx]; @@ -623,7 +624,7 @@ export class WebGPUCommandBuffer extends CommandBuffer { } else { const currLayout = wgpuPipLayout.setLayouts[currSetIdx]; const currLayoutInfo = new DescriptorSetInfo(currLayout); - const newDescSet = WebGPUDeviceManager.instance.createDescriptorSet(currLayoutInfo) as WebGPUDescriptorSet; + const newDescSet = device.createDescriptorSet(currLayoutInfo) as WebGPUDescriptorSet; descriptorSets[currSetIdx] = newDescSet; newDescSet.prepare(true); } @@ -666,8 +667,12 @@ export class WebGPUCommandBuffer extends CommandBuffer { const bgfunc = (passEncoder: GPURenderPassEncoder): void => { const gpuBindGroupSize = wgpuBindGroups.length; for (let i = 0; i < gpuBindGroupSize; i++) { + let currBindGroup = wgpuBindGroups[i]; + if (!currBindGroup) { + currBindGroup = (device.defaultResource.descSet as WebGPUDescriptorSet).gpuDescriptorSet.bindGroup; + } // FIXME: this is a special sentence that 2 in 3 parameters I'm not certain. - passEncoder.setBindGroup(i, wgpuBindGroups[i], wgpuDynOffsets[i]); + passEncoder.setBindGroup(i, currBindGroup, wgpuDynOffsets[i]); } }; this._renderPassFuncQueue.push(bgfunc); diff --git a/cocos/gfx/webgpu/webgpu-descriptor-set-layout.ts b/cocos/gfx/webgpu/webgpu-descriptor-set-layout.ts index 168bea9a59b..b057ed4d7fb 100644 --- a/cocos/gfx/webgpu/webgpu-descriptor-set-layout.ts +++ b/cocos/gfx/webgpu/webgpu-descriptor-set-layout.ts @@ -29,7 +29,7 @@ import { DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE, } from '../base/define'; -import { DescUpdateFrequency, WebGPUDeviceManager, isBound } from './define'; +import { WebGPUDeviceManager } from './define'; import { WebGPUTexture } from './webgpu-texture'; import { DescriptorSet } from '../base/descriptor-set'; import { WebGPUBuffer } from './webgpu-buffer'; @@ -68,7 +68,12 @@ export class WebGPUDescriptorSetLayout extends DescriptorSetLayout { } public initialize (info: Readonly): void { Array.prototype.push.apply(this._bindings, info.bindings); - + const gfxDevice = WebGPUDeviceManager.instance; + // If the bindings are empty, it will cause the corresponding group to be generated as null, + // which will trigger a warning for the corresponding set being unbound. + if (!this._bindings.length) { + this._bindings.push(gfxDevice.defaultResource.setLayout.bindings[0]); + } let descriptorCount = 0; let maxBinding = -1; const flattenedIndices: number[] = []; const bindingSize = this._bindings.length; @@ -103,7 +108,7 @@ export class WebGPUDescriptorSetLayout extends DescriptorSetLayout { ), ); }); - const device = WebGPUDeviceManager.instance.nativeDevice!; + const device = gfxDevice.nativeDevice!; const groupLayout = device.createBindGroupLayout({ entries: bindGrpLayoutEntries, }); @@ -117,61 +122,6 @@ export class WebGPUDescriptorSetLayout extends DescriptorSetLayout { }; } - public removeRef (ref: DescriptorSet): void { - const index = this.references.indexOf(ref); - if (index !== -1) { - this.references.splice(index, 1); - } - if (this.references.length === 0) { - this.clear(); - } - } - - public addRef (ref: DescriptorSet): void { - if (!this.references.includes(ref)) { - this.references.push(ref); - } - } - - public resetGroupLayout (): void { - if (this._gpuDescriptorSetLayout?.bindGroupLayout) { - this._gpuDescriptorSetLayout.bindGroupLayout = null; - this._hasChange = true; - } - } - - public prepare (frequency: DescUpdateFrequency, binds: number[], vertBinds: number[] = [], fragBinds: number[] = []): void { - if (isBound(binds, this._currBinds) && frequency !== DescUpdateFrequency.LOW - && binds.length === this._prepareEntries.length) return; - this._currBinds = binds; - if (frequency !== DescUpdateFrequency.LOW) { - this._prepareEntries.length = 0; - binds.forEach((bind: number) => { - let currGrpEntryLayout = this._bindGrpLayoutEntries.get(bind < 0 ? 0 : bind)!; - if (!currGrpEntryLayout && bind < 0) { - currGrpEntryLayout = Array.from(this._bindGrpLayoutEntries.values())[0]; - } - if (vertBinds.includes(currGrpEntryLayout.binding) && !(currGrpEntryLayout.visibility & GPUShaderStage.VERTEX)) { - currGrpEntryLayout.visibility |= GPUShaderStage.VERTEX; - } else if (!vertBinds.includes(currGrpEntryLayout.binding) && (currGrpEntryLayout.visibility & GPUShaderStage.VERTEX)) { - currGrpEntryLayout.visibility ^= GPUShaderStage.VERTEX; - } - if (fragBinds.includes(currGrpEntryLayout.binding) && !(currGrpEntryLayout.visibility & GPUShaderStage.FRAGMENT)) { - currGrpEntryLayout.visibility |= GPUShaderStage.FRAGMENT; - } else if (!fragBinds.includes(currGrpEntryLayout.binding) && (currGrpEntryLayout.visibility & GPUShaderStage.FRAGMENT)) { - currGrpEntryLayout.visibility ^= GPUShaderStage.FRAGMENT; - } - this._prepareEntries.push(currGrpEntryLayout); - }); - } else { - this._prepareEntries = Array.from(this._bindGrpLayoutEntries.values()); - } - this._hasChange = true; - const nativeDevice = WebGPUDeviceManager.instance.nativeDevice; - const bindGrpLayout = nativeDevice?.createBindGroupLayout({ entries: this._prepareEntries }); - this._gpuDescriptorSetLayout!.bindGroupLayout = bindGrpLayout!; - } - public clear (): void { this.buffers.clear(); this.textures.clear();