Skip to content

Commit

Permalink
Merge branch 'v3.8.1_wgpu' into __editor__
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Sep 1, 2023
2 parents e2e4ceb + 8ebabdb commit 4cc3a6f
Show file tree
Hide file tree
Showing 43 changed files with 1,756 additions and 1,168 deletions.
504 changes: 189 additions & 315 deletions cocos/gfx/webgpu/webgpu-define.ts

Large diffs are not rendered by default.

77 changes: 48 additions & 29 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,
} 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 @@ -160,10 +169,10 @@ class PassVisitor implements RenderGraphVisitor {
const resId = resGraph.vertex(input);
const trait = resGraph.getTraits(resId);
switch (trait.residency) {
case ResourceResidency.PERSISTENT:
assert(raster.storeOp === StoreOp.STORE, `Persistent resources must have storeOp set to 'store'.`);
break;
default:
case ResourceResidency.PERSISTENT:
assert(raster.storeOp === StoreOp.STORE, `Persistent resources must have storeOp set to 'store'.`);
break;
default:
}
const useContext = new ResourceUseContext();
resContext.set(input, useContext);
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 @@ -260,7 +271,11 @@ class PassVisitor implements RenderGraphVisitor {
}
rasterSubpass (value: RasterSubpass): void {}
computeSubpass (value: ComputeSubpass): void {}
compute (value: ComputePass): void {}
compute (value: ComputePass): void {
this._currPass = value;
const rg = context.renderGraph;
rg.setValid(this.passID, true);
}
resolve (value: ResolvePass): void {}
copy (value: CopyPass): void {
const rg = context.renderGraph;
Expand Down Expand Up @@ -292,7 +307,11 @@ class PassVisitor implements RenderGraphVisitor {
blit (value: Blit): void {
this._fetchValidPass();
}
dispatch (value: Dispatch): void {}
dispatch (value: Dispatch): void {
const rg = this.context.renderGraph;
rg.setValid(this.queueID, true);
rg.setValid(this.dispatchID, true);
}
clear (value: ClearView[]): void {}
viewport (value: Viewport): void {}
}
Expand Down Expand Up @@ -347,7 +366,7 @@ class ResourceVisitor implements ResourceGraphVisitor {

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;
}
Expand Down Expand Up @@ -434,17 +453,17 @@ export class Compiler {
const min = rasterArr.reduce((prev, current): number => (prev < current ? prev : current));
const firstRaster = use.rasters.get(min)!;
switch (trait.residency) {
case ResourceResidency.PERSISTENT:
assert(
firstRaster.loadOp !== LoadOp.DISCARD,
`The loadOp for persistent resources in the top-level pass cannot be set to 'discard'.`,
);
break;
case ResourceResidency.MANAGED:
assert(firstRaster.loadOp === LoadOp.CLEAR, `The loadOp for Managed resources in the top-level pass can only be set to 'clear'.`);
break;
default:
break;
case ResourceResidency.PERSISTENT:
assert(
firstRaster.loadOp !== LoadOp.DISCARD,
`The loadOp for persistent resources in the top-level pass cannot be set to 'discard'.`,
);
break;
case ResourceResidency.MANAGED:
assert(firstRaster.loadOp === LoadOp.CLEAR, `The loadOp for Managed resources in the top-level pass can only be set to 'clear'.`);
break;
default:
break;
}
const computeArr: number[] = Array.from(use.computes.keys());
const max = rasterArr.reduce((prev, current): number => (prev > current ? prev : current));
Expand All @@ -455,12 +474,12 @@ export class Compiler {
if (max > maxCompute) {
const lastRaster = use.rasters.get(max)!;
switch (trait.residency) {
case ResourceResidency.MANAGED:
// TODO
// assert(lastRaster.storeOp === StoreOp.DISCARD, `MANAGED resources that are not being used must be set to 'discard'.`);
break;
default:
break;
case ResourceResidency.MANAGED:
// TODO
// assert(lastRaster.storeOp === StoreOp.DISCARD, `MANAGED resources that are not being used must be set to 'discard'.`);
break;
default:
break;
}
}
}
Expand All @@ -482,7 +501,7 @@ export class ResourceManagerVisitor extends DefaultVisitor {
discoverVertex (u: number, gv: ResourceGraph): void {
const traits = this._resourceGraph.getTraits(u);
if (traits.residency === ResourceResidency.MANAGED
|| traits.residency === ResourceResidency.MEMORYLESS) {
|| traits.residency === ResourceResidency.MEMORYLESS) {
return;
}
this._resVisitor.resID = u;
Expand Down
Loading

0 comments on commit 4cc3a6f

Please sign in to comment.