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
6 changes: 3 additions & 3 deletions cocos/core/pipeline/custom/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function rebuildLayoutGraph (): void {
const lgData = ppl.layoutGraphBuilder;
lgData.clear();

const defaultStage: number = lg.addGlobal('default', true, true, true, true, true, true, true);
const defaultStage: number = lg.addGlobal('default', true, true, true, true, true, true, true, true);

for (const n in effects) {
const e: EffectAsset = effects[n];
Expand Down Expand Up @@ -203,7 +203,7 @@ export function buildForwardLayout (ppl: Pipeline) {
if (bFromGlobalDescriptorSet) {
buildForwardLayoutFromGlobal(ppl, lg);
} else {
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true);
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true, true);
lg.mergeDescriptors(defaultID);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ export class VectorGraphColorMap implements MutableVertexPropertyMap<GraphColor>

export function buildDeferredLayout (ppl: Pipeline) {
const lg = new WebDescriptorHierarchy();
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true);
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true, true);
lg.mergeDescriptors(defaultID);
const geometryPassID = lg.addRenderStage('Geometry', DeferredStage.GEOMETRY);
const lightingPassID = lg.addRenderStage('Lighting', DeferredStage.LIGHTING);
Expand Down
79 changes: 69 additions & 10 deletions cocos/core/pipeline/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AABB } from '../../geometry/aabb';
import intersect from '../../geometry/intersect';
import { Sphere } from '../../geometry/sphere';
import { AccessFlagBit, Attribute, Buffer, BufferInfo, BufferUsageBit, BufferViewInfo, ClearFlagBit, Color, ColorAttachment, CommandBuffer, DepthStencilAttachment, DescriptorSet, DescriptorSetInfo, Device, deviceManager, Format, Framebuffer,
FramebufferInfo, GeneralBarrierInfo, InputAssemblerInfo, LoadOp, MemoryUsageBit, PipelineState, Rect, RenderPass, RenderPassInfo, SamplerInfo, Shader, StoreOp, SurfaceTransform, Swapchain, Texture, TextureInfo,
FramebufferInfo, GeneralBarrierInfo, InputAssemblerInfo, LoadOp, MemoryUsageBit, PipelineState, Rect, RenderPass, RenderPassInfo, Sampler, SamplerInfo, Shader, StoreOp, SurfaceTransform, Swapchain, Texture, TextureInfo,
TextureType, TextureUsageBit, Viewport } from '../../gfx';
import { legacyCC } from '../../global-exports';
import { Mat4 } from '../../math/mat4';
Expand All @@ -57,7 +57,7 @@ import { ShadowLayerVolume } from '../shadow/csm-layers';
import { LayoutGraph, LayoutGraphData, LayoutGraphDataVisitor, LayoutGraphVisitor, PipelineLayoutData, RenderPhase, RenderPhaseData, RenderStageData } from './layout-graph';
import { Pipeline, SceneVisitor } from './pipeline';
import { Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedResource, MovePass, PresentPass,
RasterPass, RaytracePass, RenderGraph, RenderGraphValue, RenderGraphVisitor, RenderQueue, RenderSwapchain, ResourceDesc,
RasterPass, RaytracePass, RenderData, RenderGraph, RenderGraphValue, RenderGraphVisitor, RenderQueue, RenderSwapchain, ResourceDesc,
ResourceGraph, ResourceGraphVisitor, ResourceTraits, SceneData } from './render-graph';
import { AttachmentType, ComputeView, QueueHint, ResourceDimension, ResourceFlags, SceneFlags, UpdateFrequency } from './types';
import { PipelineUBO } from '../pipeline-ubo';
Expand Down Expand Up @@ -395,6 +395,9 @@ class DeviceRenderQueue {
set renderPhase (val) { this._renderPhase = val; }
private _sceneVisitor: WebSceneVisitor;
private _blitDesc: BlitDesc | null = null;
private _queueId = -1;
set queueId (val) { this._queueId = val; }
get queueId () { return this._queueId; }
constructor (devicePass: DeviceRenderPass) {
this._devicePass = devicePass;
this._sceneVisitor = new WebSceneVisitor(this._devicePass.context.commandBuffer,
Expand Down Expand Up @@ -713,8 +716,12 @@ class DeviceRenderPass {
: new Rect(0, 0, tex.width, tex.height);
cmdBuff.beginRenderPass(this.renderPass, this.framebuffer, renderArea,
this.clearColor, this.clearDepth, this.clearStencil);
const stageId = this.context.layoutGraph.locateChild(this.context.layoutGraph.nullVertex(), 'default');
assert(stageId !== 0xFFFFFFFF);
const layout = this.context.layoutGraph.getLayout(stageId);
const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS);
cmdBuff.bindDescriptorSet(SetIndex.GLOBAL,
this._context.pipeline.globalDSManager.globalDescriptorSet);
layoutData!.descriptorSet!);
for (const queue of this._deviceQueues) {
queue.record();
}
Expand Down Expand Up @@ -756,6 +763,7 @@ class GraphScene {
scene: SceneData | null = null;
blit: Blit | null = null;
dispatch: Dispatch | null = null;
sceneID = -1;
}
class DevicePreSceneTask extends WebSceneTask {
protected _currentQueue: DeviceRenderQueue;
Expand Down Expand Up @@ -907,19 +915,68 @@ class DevicePreSceneTask extends WebSceneTask {
&& this.graphScene.scene!.flags & SceneFlags.SHADOW_CASTER;
}

protected _updateUbo (camera: Camera) {
const ubo = this._currentQueue.devicePass.context.ubo;
ubo.updateGlobalUBO(camera.window);
ubo.updateCameraUBO(camera);
ubo.updateShadowUBO(camera);
private _bindDescriptor (context: ExecutorContext, descId: number, value) {
const layoutData = this._getGlobalDescData(context)!;
// find descriptor binding
for (const block of layoutData.descriptorSetLayoutData.descriptorBlocks) {
for (let i = 0; i !== block.descriptors.length; ++i) {
if (descId === block.descriptors[i].descriptorID) {
if (value instanceof Buffer) layoutData.descriptorSet!.bindBuffer(block.offset + i, value);
else if (value instanceof Texture) layoutData.descriptorSet!.bindTexture(block.offset + i, value);
else if (value instanceof Sampler) layoutData.descriptorSet!.bindSampler(block.offset + i, value);
}
}
}
}

private _getGlobalDescData (context: ExecutorContext) {
const stageId = context.layoutGraph.locateChild(context.layoutGraph.nullVertex(), 'default');
assert(stageId !== 0xFFFFFFFF);
const layout = context.layoutGraph.getLayout(stageId);
const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS)!;
return layoutData;
}

protected _updateGlobal (context: ExecutorContext, data: RenderData) {
const constants = data.constants;
const samplers = data.samplers;
const textures = data.textures;
const device = context.root.device;
for (const [key, value] of constants) {
const buffer = device.createBuffer(new BufferInfo(BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
value.length * 4,
value.length * 4));
buffer.update(new Float32Array(value));
this._bindDescriptor(context, key, buffer);
}
for (const [key, value] of textures) {
this._bindDescriptor(context, key, value);
}
for (const [key, value] of samplers) {
this._bindDescriptor(context, key, value);
}
this._getGlobalDescData(context).descriptorSet!.update();
}
protected _updateUbo () {
const devicePass = this._currentQueue.devicePass;
const context = devicePass.context;
const rasterId = devicePass.rasterPassInfo.id;
const passRenderData = context.renderGraph.getData(rasterId);
// CCGlobal
this._updateGlobal(context, passRenderData);
// CCCamera, CCShadow, CCCSM
const queueId = this._currentQueue.queueId;
const queueRenderData = context.renderGraph.getData(queueId)!;
this._updateGlobal(context, queueRenderData);
}

public submit () {
const context = this._currentQueue.devicePass.context;
const ubo = context.ubo;
if (this.graphScene.blit) {
const blitCam = this.graphScene.blit.camera;
if (blitCam) this._updateUbo(blitCam);
if (blitCam) this._updateUbo();
this._currentQueue.blitDesc!.update();
return;
}
Expand All @@ -928,7 +985,7 @@ class DevicePreSceneTask extends WebSceneTask {
this.graphScene.scene!.light.light!, this.graphScene.scene!.light.level);
return;
}
this._updateUbo(this.camera!);
this._updateUbo();

this._uploadInstanceBuffers();
this._uploadBatchedBuffers();
Expand Down Expand Up @@ -1302,6 +1359,7 @@ class PassVisitor implements RenderGraphVisitor {
queue (value: RenderQueue) {
const deviceQueue = new DeviceRenderQueue(this._currPass!);
deviceQueue.queueHint = value.hint;
deviceQueue.queueId = this._queueID;
this._currQueue = deviceQueue;
this._currPass!.addQueue(deviceQueue);
const rg = this._context.renderGraph;
Expand All @@ -1322,6 +1380,7 @@ class PassVisitor implements RenderGraphVisitor {
scene (value: SceneData) {
const graphScene = new GraphScene();
graphScene.scene = value;
graphScene.sceneID = this._sceneID;
this._currQueue!.addSceneTask(graphScene);
}
blit (value: Blit) {
Expand Down
44 changes: 44 additions & 0 deletions cocos/core/pipeline/custom/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// https://stackoverflow.com/questions/56714318/how-to-disable-multiple-rules-for-eslint-nextline?msclkid=5d4c2298ba7911eca34d0ab30591752e

import { Type } from '../../gfx/base/define';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function replacer (key: unknown, value: unknown) {
if (value instanceof Map) {
Expand Down Expand Up @@ -37,3 +39,45 @@ export function parse (text: string) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(text, reviver);
}

export function getUBOTypeCount (type: Type): number {
switch (type) {
case Type.BOOL:
case Type.INT:
case Type.UINT:
case Type.FLOAT:
return 1;
case Type.INT2:
case Type.FLOAT2:
case Type.UINT2:
case Type.BOOL2:
return 2;
case Type.FLOAT3:
case Type.BOOL3:
case Type.UINT3:
case Type.INT3:
return 3;
case Type.BOOL4:
case Type.FLOAT4:
case Type.UINT4:
case Type.INT4:
return 4;
case Type.MAT2:
return 4;
case Type.MAT2X3:
case Type.MAT3X2:
return 6;
case Type.MAT2X4:
case Type.MAT4X2:
return 8;
case Type.MAT3:
return 9;
case Type.MAT3X4:
case Type.MAT4X3:
return 12;
case Type.MAT4:
return 16;
default:
return 0;
}
}
30 changes: 24 additions & 6 deletions cocos/core/pipeline/custom/web-descriptor-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { EffectAsset } from '../../assets';
import { Descriptor, DescriptorBlock, DescriptorBlockIndex, DescriptorDB, DescriptorTypeOrder, LayoutGraph, LayoutGraphValue, LayoutGraphVisitor, RenderPhase } from './layout-graph';
import { ShaderStageFlagBit, Type, Uniform, UniformBlock } from '../../gfx';
import { ParameterType, UpdateFrequency } from './types';
import { JOINT_UNIFORM_CAPACITY, RenderPassStage, SetIndex, UBOCamera, UBOForwardLight, UBOGlobal, UBOLocal, UBOLocalBatched, UBOMorph, UBOShadow, UBOSkinning, UBOSkinningAnimation, UBOSkinningTexture, UBOUILocal, UBOWorldBound } from '../define';
import { JOINT_UNIFORM_CAPACITY, RenderPassStage, SetIndex, UBOCamera, UBOCSM, UBOForwardLight, UBOGlobal, UBOLocal, UBOLocalBatched, UBOMorph, UBOShadow, UBOSkinning, UBOSkinningAnimation, UBOSkinningTexture, UBOUILocal, UBOWorldBound } from '../define';
import { DefaultVisitor, edge_descriptor, IncidenceGraph, vertex_descriptor } from './graph';
import { ccclass } from '../../data/decorators';

Expand Down Expand Up @@ -406,7 +406,7 @@ export class WebDescriptorHierarchy {
}
}

public addGlobal (vName: string, hasCCGlobal, hasCCCamera, hasCCShadow, hasShadowmap, hasEnv, hasDiffuse, hasSpot): number {
public addGlobal (vName: string, hasCCGlobal, hasCCCamera, hasCCShadow, hasCCCSM, hasShadowmap, hasEnv, hasDiffuse, hasSpot): number {
const passDB: DescriptorDB = new DescriptorDB();
// Add pass layout from define.ts
const globalUniformTarget: DescriptorBlock = this.getLayoutBlock(UpdateFrequency.PER_PASS,
Expand All @@ -420,7 +420,10 @@ export class WebDescriptorHierarchy {
this.setUniform(globalDB, 'cc_time', Type.FLOAT4, 1);
this.setUniform(globalDB, 'cc_screenSize', Type.FLOAT4, 1);
this.setUniform(globalDB, 'cc_nativeSize', Type.FLOAT4, 1);

this.setUniform(globalDB, 'cc_debug_view_mode', Type.FLOAT, 4);
this.setUniform(globalDB, 'cc_debug_view_composite_pack_1', Type.FLOAT, 4);
this.setUniform(globalDB, 'cc_debug_view_composite_pack_2', Type.FLOAT, 4);
this.setUniform(globalDB, 'cc_debug_view_composite_pack_3', Type.FLOAT, 4);
this.setDescriptor(globalUniformTarget, 'CCGlobal', Type.UNKNOWN);
}

Expand Down Expand Up @@ -467,18 +470,33 @@ export class WebDescriptorHierarchy {
this.setDescriptor(globalUniformTarget, 'CCShadow', Type.UNKNOWN);
}

if (hasCCCSM) {
const csmDB: UniformBlock = this.getUniformBlock(SetIndex.GLOBAL,
UBOCSM.BINDING, 'CCCSM', globalUniformTarget);
this.setUniform(csmDB, 'cc_csmViewDir0', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmViewDir1', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmViewDir2', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmAtlas', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_matCSMViewProj', Type.MAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmProjDepthInfo', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmProjInfo', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT);
this.setUniform(csmDB, 'cc_csmSplitsInfo', Type.FLOAT4, 1);

this.setDescriptor(globalUniformTarget, 'CCCSM', Type.UNKNOWN);
}

if (hasShadowmap) {
this.setDescriptor(globalSamplerTexTarget, 'cc_shadowMap', Type.SAMPLER2D);
}
if (hasEnv) {
this.setDescriptor(globalSamplerTexTarget, 'cc_environment', Type.SAMPLER_CUBE);
}
if (hasDiffuse) {
this.setDescriptor(globalSamplerTexTarget, 'cc_diffuseMap', Type.SAMPLER_CUBE);
}
if (hasSpot) {
this.setDescriptor(globalSamplerTexTarget, 'cc_spotShadowMap', Type.SAMPLER2D);
}
if (hasDiffuse) {
this.setDescriptor(globalSamplerTexTarget, 'cc_diffuseMap', Type.SAMPLER_CUBE);
}

this.merge(passDB);

Expand Down
Loading