Skip to content
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
35 changes: 26 additions & 9 deletions cocos/core/pipeline/custom/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Buffer, Framebuffer, Texture } from '../../gfx';
import { assert } from '../../platform/debug';
import { LayoutGraphData } from './layout-graph';
import { Pipeline } from './pipeline';
import { AccessType, Blit, ComputePass, CopyPass, Dispatch, ManagedResource, MovePass,
import { AccessType, Blit, ComputePass, ComputeView, CopyPass, Dispatch, ManagedResource, MovePass,
PresentPass, RasterPass, RasterView, RaytracePass, RenderGraph, RenderGraphValue, RenderGraphVisitor,
RenderQueue, RenderSwapchain, ResourceGraph, ResourceGraphVisitor, SceneData } from './render-graph';
import { ResourceResidency } from './types';
Expand Down Expand Up @@ -82,39 +82,56 @@ class PassVisitor implements RenderGraphVisitor {
rg.visitVertex(this, sceneID);
}
}
scene (value: SceneData) {
private _fetchValidPass () {
if (this._currPass!.isValid) {
return;
}
const outputId = this.resID;
const outputName = this._context.resourceGraph.vertexName(outputId);
const readViews: Map<string, RasterView> = new Map();
const pass = this._currPass!;
for (const [name, raster] of pass.rasterViews) {

for (const [readName, raster] of pass.rasterViews) {
// find the pass
if (name === outputName
if (readName === outputName
&& raster.accessType !== AccessType.READ) {
assert(!pass.isValid, 'The same pass cannot output multiple resources with the same name at the same time');
pass.isValid = true;
continue;
}
if (raster.accessType !== AccessType.WRITE) {
readViews.set(name, raster);
readViews.set(readName, raster);
}
}
if (pass.isValid) {
for (const [name, raster] of readViews) {
const resVisitor = new ResourceVisitor(this._context);
const resourceGraph = this._context.resourceGraph;
const vertID = resourceGraph.vertex(name);
let resVisitor;
let resourceGraph;
let vertID;
for (const [rasterName, raster] of readViews) {
resVisitor = new ResourceVisitor(this._context);
resourceGraph = this._context.resourceGraph;
vertID = resourceGraph.vertex(rasterName);
if (vertID) {
resVisitor.resID = vertID;
resourceGraph.visitVertex(resVisitor, vertID);
}
}
for (const [computeName, cViews] of pass.computeViews) {
resVisitor = new ResourceVisitor(this._context);
resourceGraph = this._context.resourceGraph;
vertID = resourceGraph.vertex(computeName);
if (vertID) {
resVisitor.resID = vertID;
resourceGraph.visitVertex(resVisitor, vertID);
}
}
}
}
scene (value: SceneData) {
this._fetchValidPass();
}
blit (value: Blit) {
this._fetchValidPass();
}
dispatch (value: Dispatch) {
}
Expand Down
17 changes: 17 additions & 0 deletions cocos/core/pipeline/custom/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export function buildForwardLayout (ppl: Pipeline) {
enum DeferredStage {
GEOMETRY,
LIGHTING,
POST
}

export class VectorGraphColorMap implements MutableVertexPropertyMap<GraphColor> {
Expand All @@ -234,9 +235,11 @@ export function buildDeferredLayout (ppl: Pipeline) {
const lg = new WebDescriptorHierarchy();
const geometryPassID = lg.addRenderStage('Geometry', DeferredStage.GEOMETRY);
const lightingPassID = lg.addRenderStage('Lighting', DeferredStage.LIGHTING);
const postPassID = lg.addRenderStage('Postprocess', DeferredStage.POST);

const geometryQueueID = lg.addRenderPhase('Queue', geometryPassID);
const lightingQueueID = lg.addRenderPhase('Queue', lightingPassID);
const postQueueID = lg.addRenderPhase('Queue', postPassID);

const lightingDescriptors = lg.layoutGraph.getDescriptors(lightingQueueID);

Expand All @@ -255,6 +258,20 @@ export function buildDeferredLayout (ppl: Pipeline) {
const colorMap = new VectorGraphColorMap(lg.layoutGraph.numVertices());
depthFirstSearch(lg.layoutGraph, visitor, colorMap);

lg.mergeDescriptors(lightingPassID);
// Postprocess
const postDescriptors = lg.layoutGraph.getDescriptors(postPassID);

const postPassBlock = lg.getLayoutBlock(UpdateFrequency.PER_PASS,
ParameterType.TABLE,
DescriptorTypeOrder.SAMPLER_TEXTURE,
ShaderStageFlagBit.FRAGMENT,
postDescriptors);

lg.setDescriptor(postPassBlock, 'outputResultMap', Type.FLOAT4);
lg.merge(postDescriptors);

lg.mergeDescriptors(postPassID);
if (visitor.error) {
console.log(visitor.error);
}
Expand Down
Loading