Skip to content

Commit

Permalink
Fixed the issue where the testlist was not displayed.
Browse files Browse the repository at this point in the history
  • Loading branch information
GengineJS committed Jan 22, 2025
1 parent 6af7930 commit 0227211
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 60 deletions.
9 changes: 7 additions & 2 deletions cocos/gfx/webgpu/webgpu-command-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
66 changes: 8 additions & 58 deletions cocos/gfx/webgpu/webgpu-descriptor-set-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -68,7 +68,12 @@ export class WebGPUDescriptorSetLayout extends DescriptorSetLayout {
}
public initialize (info: Readonly<DescriptorSetLayoutInfo>): 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;
Expand Down Expand Up @@ -103,7 +108,7 @@ export class WebGPUDescriptorSetLayout extends DescriptorSetLayout {
),
);
});
const device = WebGPUDeviceManager.instance.nativeDevice!;
const device = gfxDevice.nativeDevice!;
const groupLayout = device.createBindGroupLayout({
entries: bindGrpLayoutEntries,
});
Expand All @@ -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();
Expand Down

0 comments on commit 0227211

Please sign in to comment.