Skip to content

Commit

Permalink
engine add WebGPU support
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Jan 15, 2025
1 parent a107d84 commit a7b7730
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 94 deletions.
14 changes: 10 additions & 4 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { BufferInfo, Buffer, BufferUsageBit, ClearFlagBit, Color, DescriptorSet,
Format, Rect, Sampler, StoreOp, Texture, Viewport, MemoryUsageBit,
UniformBlock,
Device,
API,
} from '../../gfx';
import { ReflectionProbe } from '../../render-scene/scene/reflection-probe';
import { Camera, SkyBoxFlagValue } from '../../render-scene/scene/camera';
Expand Down Expand Up @@ -422,13 +423,15 @@ export function getDescBinding (descId, descData: DescriptorSetData): number {

export function getDescBindingFromName (bindingName: string): number {
const pipeline = cclegacy.director.root.pipeline as WebPipeline;
const isWebGPU = pipeline.device.gfxAPI === API.WEBGPU;
const layoutGraph = pipeline.layoutGraph;
const vertIds = layoutGraph.v();
const descId = layoutGraph.attributeIndex.get(bindingName);
let currDesData: DescriptorSetData;
for (const i of vertIds) {
const layout = layoutGraph.getLayout(i);
for (const [k, descData] of layout.descriptorSets) {
const sets = layout.getSets(isWebGPU);
for (const [k, descData] of sets) {
const layoutData = descData.descriptorSetLayoutData;
const blocks = layoutData.descriptorBlocks;
for (const b of blocks) {
Expand Down Expand Up @@ -491,17 +494,19 @@ export function getDescriptorSetDataFromLayout (layoutName: string): DescriptorS
return descLayout;
}
const webPip = cclegacy.director.root.pipeline as WebPipeline;
const isWebGPU = webPip.device.gfxAPI === API.WEBGPU;
const stageId = webPip.layoutGraph.locateChild(webPip.layoutGraph.N, layoutName);
const layout = webPip.layoutGraph.getLayout(stageId);
const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS);
const layoutData = layout.getSet(UpdateFrequency.PER_PASS, isWebGPU);
layouts.set(layoutName, layoutData!);
return layoutData;
}

export function getDescriptorSetDataFromLayoutId (id: number): DescriptorSetData | undefined {
const webPip = cclegacy.director.root.pipeline as WebPipeline;
const isWebGPU = webPip.device.gfxAPI === API.WEBGPU;
const layout = webPip.layoutGraph.getLayout(id);
const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS);
const layoutData = layout.getSet(UpdateFrequency.PER_PASS, isWebGPU);
return layoutData;
}

Expand All @@ -514,7 +519,8 @@ function getUniformBlock (block: string, layoutName: string): UniformBlock | und
const lg = webPip.layoutGraph;
const nodeId = lg.locateChild(0xFFFFFFFF, layoutName);
const ppl = lg.getLayout(nodeId);
const layout = ppl.descriptorSets.get(UpdateFrequency.PER_PASS)!.descriptorSetLayoutData;
const isWebGPU = webPip.device.gfxAPI === API.WEBGPU;
const layout = ppl.getSet(UpdateFrequency.PER_PASS, isWebGPU)!.descriptorSetLayoutData;
const nameID: number = lg.attributeIndex.get(block)!;
return layout.uniformBlocks.get(nameID);
}
Expand Down
8 changes: 6 additions & 2 deletions cocos/rendering/custom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { macro } from '../../core/platform/macro';
import { LayoutGraphData, loadLayoutGraphData } from './layout-graph';
import { BinaryInputArchive } from './binary-archive';
import { WebProgramLibrary } from './web-program-library';
import { Device } from '../../gfx';
import { API, Device } from '../../gfx';
import { initializeLayoutGraphData, terminateLayoutGraphData, getCustomPassID, getCustomPhaseID, getCustomSubpassID } from './layout-graph-utils';
import { ProgramLibrary } from './private';
import { forceResizeAllWindows } from './framework';
Expand Down Expand Up @@ -97,7 +97,11 @@ export function init (device: Device, arrayBuffer: ArrayBuffer | null): void {
}

export function destroy (): void {
terminateLayoutGraphData(defaultLayoutGraph);
if (_pipeline) {
terminateLayoutGraphData(defaultLayoutGraph, _pipeline.device.gfxAPI === API.WEBGPU);
} else {
terminateLayoutGraphData(defaultLayoutGraph, false);
}
}

export function getPassID (name: string | undefined): number {
Expand Down
Loading

0 comments on commit a7b7730

Please sign in to comment.