Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update web pipeline for webgpu #16207

Merged
merged 17 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
507 changes: 189 additions & 318 deletions cocos/gfx/webgpu/webgpu-define.ts

Large diffs are not rendered by default.

72 changes: 55 additions & 17 deletions cocos/rendering/custom/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import { VectorGraphColorMap } from './effect';
import { DefaultVisitor, depthFirstSearch, ReferenceGraphView } from './graph';
import { LayoutGraphData } from './layout-graph';
import { BasicPipeline } from './pipeline';
import { Blit, ClearView, ComputePass, ComputeSubpass, CopyPass, Dispatch, FormatView, ManagedBuffer, ManagedResource, ManagedTexture, MovePass,
import {
Blit, ClearView, ComputePass, ComputeSubpass, CopyPass, Dispatch, FormatView, ManagedBuffer, ManagedResource, ManagedTexture, MovePass,
RasterPass, RasterSubpass, RaytracePass, RenderGraph, RenderGraphVisitor, RasterView, ComputeView,
RenderQueue, RenderSwapchain, ResolvePass, ResourceGraph, ResourceGraphVisitor, SceneData, SubresourceView } from './render-graph';
RenderQueue, RenderSwapchain, ResolvePass, ResourceGraph, ResourceGraphVisitor, SceneData, SubresourceView, PersistentBuffer, PersistentTexture,
} from './render-graph';
import { AccessType, ResourceResidency, SceneFlags } from './types';
import { hashCombineNum, hashCombineStr } from './define';

Expand Down Expand Up @@ -83,10 +85,11 @@ class PassVisitor implements RenderGraphVisitor {
public queueID = 0xFFFFFFFF;
public sceneID = 0xFFFFFFFF;
public passID = 0xFFFFFFFF;
public dispatchID = 0xFFFFFFFF;
// output resourcetexture id
public resID = 0xFFFFFFFF;
public context: CompilerContext;
private _currPass: RasterPass | CopyPass | null = null;
private _currPass: RasterPass | CopyPass | ComputePass | null = null;
private _resVisitor: ResourceVisitor;
constructor (context: CompilerContext) {
this.context = context;
Expand All @@ -98,6 +101,12 @@ class PassVisitor implements RenderGraphVisitor {
protected _isCopyPass (u: number): boolean {
return !!this.context.renderGraph.tryGetCopy(u);
}
protected _isCompute (u: number): boolean {
return !!this.context.renderGraph.tryGetCompute(u);
}
protected _isDispatch (u: number): boolean {
return !!this.context.renderGraph.tryGetDispatch(u);
}
protected _isQueue (u: number): boolean {
return !!this.context.renderGraph.tryGetQueue(u);
}
Expand Down Expand Up @@ -242,12 +251,14 @@ class PassVisitor implements RenderGraphVisitor {
}
applyID (id: number, resId: number): void {
this.resID = resId;
if (this._isRasterPass(id) || this._isCopyPass(id)) {
if (this._isRasterPass(id) || this._isCopyPass(id) || this._isCompute(id)) {
this.passID = id;
} else if (this._isQueue(id)) {
this.queueID = id;
} else if (this._isScene(id) || this._isBlit(id)) {
this.sceneID = id;
} else if (this._isDispatch(id)) {
this.dispatchID = id;
}
}
rasterPass (pass: RasterPass): void {
Expand All @@ -258,10 +269,20 @@ class PassVisitor implements RenderGraphVisitor {
// }
this._currPass = pass;
}
rasterSubpass (value: RasterSubpass): void {}
computeSubpass (value: ComputeSubpass): void {}
compute (value: ComputePass): void {}
resolve (value: ResolvePass): void {}
rasterSubpass (value: RasterSubpass): void {
// noop
}
computeSubpass (value: ComputeSubpass): void {
// noop
}
compute (value: ComputePass): void {
this._currPass = value;
const rg = context.renderGraph;
rg.setValid(this.passID, true);
}
resolve (value: ResolvePass): void {
// noop
}
copy (value: CopyPass): void {
const rg = context.renderGraph;
if (rg.getValid(this.passID)) {
Expand All @@ -283,18 +304,32 @@ class PassVisitor implements RenderGraphVisitor {
}
}
}
move (value: MovePass): void {}
raytrace (value: RaytracePass): void {}
queue (value: RenderQueue): void {}
move (value: MovePass): void {
// noop
}
raytrace (value: RaytracePass): void {
// noop
}
queue (value: RenderQueue): void {
// noop
}
scene (value: SceneData): void {
this._fetchValidPass();
}
blit (value: Blit): void {
this._fetchValidPass();
}
dispatch (value: Dispatch): void {}
clear (value: ClearView[]): void {}
viewport (value: Viewport): void {}
dispatch (value: Dispatch): void {
const rg = this.context.renderGraph;
rg.setValid(this.queueID, true);
rg.setValid(this.dispatchID, true);
}
clear (value: ClearView[]): void {
// noop
}
viewport (value: Viewport): void {
// noop
}
}

class PassManagerVisitor extends DefaultVisitor {
Expand Down Expand Up @@ -342,19 +377,20 @@ class ResourceVisitor implements ResourceGraphVisitor {
managed (value: ManagedResource): void {
this.dependency();
}
persistentBuffer (value: Buffer): void {
persistentBuffer (value: Buffer | PersistentBuffer): void {
// noop
}

dependency (): void {
if (!this._passManagerVis) {
this._passManagerVis = new PassManagerVisitor(this._context, this.resID);
this._passManagerVis = new PassManagerVisitor(this._context, this.resID);
} else {
this._passManagerVis.resId = this.resID;
}
depthFirstSearch(this._passManagerVis.graphView, this._passManagerVis, this._passManagerVis.colorMap);
}

persistentTexture (value: Texture): void {
persistentTexture (value: Texture | PersistentTexture): void {
this.dependency();
}
framebuffer (value: Framebuffer): void {
Expand All @@ -364,8 +400,10 @@ class ResourceVisitor implements ResourceGraphVisitor {
this.dependency();
}
formatView (value: FormatView): void {
// noop
}
subresourceView (value: SubresourceView): void {
// noop
}
}

Expand Down
10 changes: 8 additions & 2 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { ImageAsset, Material, Texture2D } from '../../asset/assets';
import { getProfilerCamera, SRGBToLinear } from '../pipeline-funcs';
import { RenderWindow } from '../../render-scene/core/render-window';
import { RenderData, RenderGraph } from './render-graph';
import { WebPipeline } from './web-pipeline';
import { WebComputePassBuilder, WebPipeline } from './web-pipeline';
import { DescriptorSetData, LayoutGraph, LayoutGraphData } from './layout-graph';
import { AABB } from '../../core/geometry';
import { DebugViewCompositeType, DebugViewSingleType } from '../debug-view';
Expand Down Expand Up @@ -2178,7 +2178,7 @@ export function buildHBAOPasses (
return { rtName: haboCombined.rtName, dsName: inputDS };
}

export const MAX_LIGHTS_PER_CLUSTER = 100;
export const MAX_LIGHTS_PER_CLUSTER = 200;
export const CLUSTERS_X = 16;
export const CLUSTERS_Y = 8;
export const CLUSTERS_Z = 24;
Expand Down Expand Up @@ -2240,6 +2240,9 @@ export function buildLightClusterBuildPass (

const width = camera.width * ppl.pipelineSceneData.shadingScale;
const height = camera.height * ppl.pipelineSceneData.shadingScale;
if ('setCurrConstant' in clusterPass) { // web-pipeline
(clusterPass as WebComputePassBuilder).addConstant('CCConst', 'cluster-build-cs');
}
clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0));
clusterPass.setVec4('cc_viewPort', new Vec4(0, 0, width, height));
clusterPass.setVec4('cc_workGroup', new Vec4(CLUSTERS_X, CLUSTERS_Y, CLUSTERS_Z, 0));
Expand Down Expand Up @@ -2280,6 +2283,9 @@ export function buildLightClusterCullingPass (

const width = camera.width * ppl.pipelineSceneData.shadingScale;
const height = camera.height * ppl.pipelineSceneData.shadingScale;
if ('setCurrConstant' in clusterPass) { // web-pipeline
(clusterPass as WebComputePassBuilder).addConstant('CCConst', 'cluster-build-cs');
}
clusterPass.setVec4('cc_nearFar', new Vec4(camera.nearClip, camera.farClip, camera.getClipSpaceMinz(), 0));
clusterPass.setVec4('cc_viewPort', new Vec4(width, height, width, height));
clusterPass.setVec4('cc_workGroup', new Vec4(CLUSTERS_X, CLUSTERS_Y, CLUSTERS_Z, 0));
Expand Down
Loading
Loading