From df9b49b539c74e22c646d45f313305efc2fcc187 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Thu, 22 Dec 2022 19:09:48 +0800 Subject: [PATCH] [pipeline] update custom pipeline (#13744) --- cocos/asset/assets/effect-asset.ts | 3 +- cocos/render-scene/core/pass.ts | 23 +- cocos/render-scene/core/program-utils.ts | 36 +- cocos/render-scene/scene/submodel.ts | 15 +- cocos/rendering/custom/define.ts | 101 +- cocos/rendering/custom/executor.ts | 82 +- cocos/rendering/custom/index.jsb.ts | 21 +- cocos/rendering/custom/index.ts | 1 + cocos/rendering/custom/layout-graph-utils.ts | 199 +++- cocos/rendering/custom/layout-graph.ts | 21 +- cocos/rendering/custom/pipeline.ts | 5 + cocos/rendering/custom/private.ts | 3 + cocos/rendering/custom/web-pipeline.ts | 7 +- cocos/rendering/custom/web-program-library.ts | 179 ++- cocos/rendering/custom/web-types.ts | 12 +- cocos/rendering/define.ts | 4 + .../global-descriptor-set-manager.ts | 7 +- cocos/rendering/pipeline-ubo.ts | 22 +- .../rendering/render-additive-light-queue.ts | 29 +- .../render-reflection-probe-queue.ts | 21 +- .../render-shadow-map-batched-queue.ts | 13 +- cocos/rendering/ui-phase.ts | 7 +- native/CMakeLists.txt | 28 +- .../cocos/bindings/auto/jsb_assets_auto.cpp | 88 ++ .../cocos/bindings/auto/jsb_render_auto.cpp | 156 +++ native/cocos/bindings/auto/jsb_render_auto.h | 5 + native/cocos/bindings/auto/jsb_scene_auto.cpp | 2 +- native/cocos/core/assets/EffectAsset.h | 3 +- native/cocos/renderer/core/ProgramLib.cpp | 122 +- native/cocos/renderer/core/ProgramUtils.cpp | 169 +++ .../ProgramUtils.h} | 24 +- .../renderer/frame-graph/ImmutableState.cpp | 1 - .../renderer/pipeline/custom/BinaryArchive.h | 25 + .../pipeline/custom/FGDispatcherGraphs.h | 13 +- .../pipeline/custom/FGDispatcherTypes.h | 6 +- .../pipeline/custom/FrameGraphDispatcher.cpp | 6 +- .../pipeline/custom/LayoutGraphGraphs.h | 29 +- .../pipeline/custom/LayoutGraphReflection.cpp | 35 - .../pipeline/custom/LayoutGraphReflection.h | 36 - .../custom/LayoutGraphSerialization.h | 8 +- .../pipeline/custom/LayoutGraphTypes.cpp | 11 +- .../pipeline/custom/LayoutGraphTypes.h | 14 +- .../pipeline/custom/LayoutGraphUtils.cpp | 298 +++++ ...{LayoutGraphJsb.cpp => LayoutGraphUtils.h} | 38 +- .../pipeline/custom/NativeExecutor.cpp | 12 +- .../pipeline/custom/NativeFactory.cpp | 75 ++ .../custom/{LayoutGraphJsb.h => NativeFwd.h} | 17 +- ...outGraphImpl.cpp => NativeLayoutGraph.cpp} | 13 +- ...ivePipelineImpl.cpp => NativePipeline.cpp} | 8 +- .../pipeline/custom/NativePipelineFwd.h | 7 +- .../pipeline/custom/NativePipelineGraphs.h | 7 +- .../pipeline/custom/NativePipelineTypes.cpp | 4 + .../pipeline/custom/NativePipelineTypes.h | 67 +- .../pipeline/custom/NativeProgramLibrary.cpp | 1048 +++++++++++++++++ .../pipeline/custom/NativeRenderGraph.cpp | 18 +- .../pipeline/custom/NativeRenderQueue.cpp | 2 +- ...faceImpl.cpp => NativeRenderingModule.cpp} | 13 +- .../pipeline/custom/NativeResourceGraph.cpp | 2 +- .../{RenderGraphJsb.cpp => NativeTypes.cpp} | 76 +- .../renderer/pipeline/custom/NativeTypes.h | 102 ++ .../renderer/pipeline/custom/PrivateTypes.h | 15 +- .../pipeline/custom/RenderCommonJsb.cpp | 2 +- .../custom/RenderCommonReflection.cpp | 35 - .../custom/RenderCommonSerialization.h | 4 +- .../pipeline/custom/RenderGraphGraphs.h | 67 +- .../renderer/pipeline/custom/RenderGraphJsb.h | 43 - .../pipeline/custom/RenderGraphNames.h | 84 -- .../pipeline/custom/RenderGraphReflection.cpp | 35 - .../pipeline/custom/RenderGraphReflection.h | 36 - .../pipeline/custom/RenderGraphTypes.h | 5 +- .../pipeline/custom/RenderInterfaceFwd.h | 1 + .../pipeline/custom/RenderInterfaceTypes.h | 15 + .../custom/{ => details}/DebugUtils.h | 22 +- .../pipeline/custom/{ => details}/GraphImpl.h | 8 +- .../custom/{ => details}/GraphTypes.h | 10 +- .../pipeline/custom/{ => details}/GraphView.h | 0 .../pipeline/custom/{ => details}/GslUtils.h | 2 +- .../custom/{ => details}/JsbConversion.h | 10 +- .../pipeline/custom/{ => details}/Map.h | 4 +- .../pipeline/custom/{ => details}/Overload.h | 6 +- .../pipeline/custom/{ => details}/PathUtils.h | 4 +- .../pipeline/custom/{ => details}/Pmr.h | 6 +- .../pipeline/custom/{ => details}/Range.h | 0 .../custom/{ => details}/SerializationUtils.h | 0 .../pipeline/custom/{ => details}/Set.h | 3 +- .../pipeline/custom/{ => details}/Utility.h | 0 .../renderer/pipeline/custom/test/test.h | 2 +- 87 files changed, 2969 insertions(+), 849 deletions(-) create mode 100644 native/cocos/renderer/core/ProgramUtils.cpp rename native/cocos/renderer/{pipeline/custom/RenderCommonReflection.h => core/ProgramUtils.h} (73%) delete mode 100644 native/cocos/renderer/pipeline/custom/LayoutGraphReflection.cpp delete mode 100644 native/cocos/renderer/pipeline/custom/LayoutGraphReflection.h create mode 100644 native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp rename native/cocos/renderer/pipeline/custom/{LayoutGraphJsb.cpp => LayoutGraphUtils.h} (61%) create mode 100644 native/cocos/renderer/pipeline/custom/NativeFactory.cpp rename native/cocos/renderer/pipeline/custom/{LayoutGraphJsb.h => NativeFwd.h} (86%) rename native/cocos/renderer/pipeline/custom/{NativeLayoutGraphImpl.cpp => NativeLayoutGraph.cpp} (98%) rename native/cocos/renderer/pipeline/custom/{NativePipelineImpl.cpp => NativePipeline.cpp} (99%) create mode 100644 native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp rename native/cocos/renderer/pipeline/custom/{RenderInterfaceImpl.cpp => NativeRenderingModule.cpp} (81%) rename native/cocos/renderer/pipeline/custom/{RenderGraphJsb.cpp => NativeTypes.cpp} (50%) create mode 100644 native/cocos/renderer/pipeline/custom/NativeTypes.h delete mode 100644 native/cocos/renderer/pipeline/custom/RenderCommonReflection.cpp delete mode 100644 native/cocos/renderer/pipeline/custom/RenderGraphJsb.h delete mode 100644 native/cocos/renderer/pipeline/custom/RenderGraphNames.h delete mode 100644 native/cocos/renderer/pipeline/custom/RenderGraphReflection.cpp delete mode 100644 native/cocos/renderer/pipeline/custom/RenderGraphReflection.h rename native/cocos/renderer/pipeline/custom/{ => details}/DebugUtils.h (86%) rename native/cocos/renderer/pipeline/custom/{ => details}/GraphImpl.h (99%) rename native/cocos/renderer/pipeline/custom/{ => details}/GraphTypes.h (99%) rename native/cocos/renderer/pipeline/custom/{ => details}/GraphView.h (100%) rename native/cocos/renderer/pipeline/custom/{ => details}/GslUtils.h (98%) rename native/cocos/renderer/pipeline/custom/{ => details}/JsbConversion.h (95%) rename native/cocos/renderer/pipeline/custom/{ => details}/Map.h (97%) rename native/cocos/renderer/pipeline/custom/{ => details}/Overload.h (98%) rename native/cocos/renderer/pipeline/custom/{ => details}/PathUtils.h (96%) rename native/cocos/renderer/pipeline/custom/{ => details}/Pmr.h (93%) rename native/cocos/renderer/pipeline/custom/{ => details}/Range.h (100%) rename native/cocos/renderer/pipeline/custom/{ => details}/SerializationUtils.h (100%) rename native/cocos/renderer/pipeline/custom/{ => details}/Set.h (97%) rename native/cocos/renderer/pipeline/custom/{ => details}/Utility.h (100%) diff --git a/cocos/asset/assets/effect-asset.ts b/cocos/asset/assets/effect-asset.ts index 4d1106848a..de430a6e52 100644 --- a/cocos/asset/assets/effect-asset.ts +++ b/cocos/asset/assets/effect-asset.ts @@ -34,7 +34,7 @@ import { programLib } from '../../render-scene/core/program-lib'; import { Asset } from './asset'; import { cclegacy, warnID } from '../../core'; import { ProgramLibrary } from '../../rendering/custom/private'; -import { getCombinationDefines } from '../../render-scene/core/program-utils'; +import { addEffectDefaultProperties, getCombinationDefines } from '../../render-scene/core/program-utils'; export declare namespace EffectAsset { export interface IPropertyInfo { @@ -302,6 +302,7 @@ export class EffectAsset extends Asset { */ public onLoaded () { if (cclegacy.rendering && cclegacy.rendering.enableEffectImport) { + addEffectDefaultProperties(this); (cclegacy.rendering.programLib as ProgramLibrary).addEffect(this); } else { programLib.register(this); diff --git a/cocos/render-scene/core/pass.ts b/cocos/render-scene/core/pass.ts index 37d24b0043..e4eb5e58e8 100644 --- a/cocos/render-scene/core/pass.ts +++ b/cocos/render-scene/core/pass.ts @@ -124,11 +124,7 @@ export class Pass { if (info.stage !== undefined) { pass._stage = info.stage; } if (info.dynamicStates !== undefined) { pass._dynamicStates = info.dynamicStates; } if (info.phase !== undefined) { - if (cclegacy.rendering && cclegacy.rendering.enableEffectImport) { - pass._phase = cclegacy.rendering.completePhaseName(info.phase); - } else { - pass._phase = getPhaseID(info.phase); - } + pass._phase = getPhaseID(info.phase); } const bs = pass._bs; @@ -595,20 +591,25 @@ export class Pass { this._stage = RenderPassStage.DEFAULT; if (cclegacy.rendering && cclegacy.rendering.enableEffectImport) { const r = cclegacy.rendering; - this._phase = r.completePhaseName(info.phase); - this._passID = r.getPassID(info.pass); + if (typeof info.phase === 'number') { + this._passID = (info as Pass)._passID; + this._phaseID = (info as Pass)._phaseID; + } else { + this._passID = r.getPassID(info.pass); + if (this._passID !== r.INVALID_ID) { + this._phaseID = r.getPhaseID(this._passID, info.phase); + } + } if (this._passID === r.INVALID_ID) { console.error(`Invalid render pass, program: ${info.program}`); return; } - this._phaseID = r.getPhaseID(this._passID, info.phase); if (this._phaseID === r.INVALID_ID) { console.error(`Invalid render phase, program: ${info.program}`); return; } - } else { - this._phase = getPhaseID('default'); } + this._phase = getPhaseID('default'); this._primitive = PrimitiveMode.TRIANGLE_LIST; this._passIndex = info.passIndex; @@ -838,6 +839,8 @@ export class Pass { get primitive (): PrimitiveMode { return this._primitive; } get stage (): RenderPassStage { return this._stage; } get phase (): number { return this._phase; } + get passID (): number { return this._passID; } + get phaseID (): number { return this._phaseID; } get rasterizerState (): RasterizerState { return this._rs; } get depthStencilState (): DepthStencilState { return this._dss; } get blendState (): BlendState { return this._bs; } diff --git a/cocos/render-scene/core/program-utils.ts b/cocos/render-scene/core/program-utils.ts index f840e7e2c9..370847aa4f 100644 --- a/cocos/render-scene/core/program-utils.ts +++ b/cocos/render-scene/core/program-utils.ts @@ -25,6 +25,7 @@ import { EffectAsset } from '../../asset/assets/effect-asset'; import { Attribute, GetTypeSize, ShaderInfo, Uniform } from '../../gfx/base/define'; +import { UBOForwardLight, UBOSkinning } from '../../rendering/define'; import { genHandle, MacroRecord } from './pass-utils'; import { IProgramInfo } from './program-lib'; @@ -114,8 +115,28 @@ export function getVariantKey (programInfo: IProgramInfo, defines: MacroRecord) return `${key.toString(16)}|${programInfo.hash}`; } +const defaultUniformCounts = new Map(); +defaultUniformCounts.set('cc_joints', UBOSkinning.LAYOUT.members[0].count); +defaultUniformCounts.set('cc_lightPos', UBOForwardLight.LIGHTS_PER_PASS); +defaultUniformCounts.set('cc_lightColor', UBOForwardLight.LIGHTS_PER_PASS); +defaultUniformCounts.set('cc_lightSizeRangeAngle', UBOForwardLight.LIGHTS_PER_PASS); +defaultUniformCounts.set('cc_lightDir', UBOForwardLight.LIGHTS_PER_PASS); + +function getUniformSize (prevSize: number, m: Uniform) { + if (m.count) { + return prevSize + GetTypeSize(m.type) * m.count; + } else { + const count = defaultUniformCounts.get(m.name); + if (count !== undefined) { + return prevSize + GetTypeSize(m.type) * count; + } + console.error(`uniform '${m.name}' must have a count`); + } + return prevSize; +} + export function getSize (blockMembers: Uniform[]) { - return blockMembers.reduce((s, m) => s + GetTypeSize(m.type) * m.count, 0); + return blockMembers.reduce(getUniformSize, 0); } export function genHandles (tmpl: EffectAsset.IShaderInfo | ShaderInfo) { @@ -182,3 +203,16 @@ export function getCombinationDefines (combination: EffectAsset.IPreCompileInfo) }, [] as MacroRecord[]), [{}] as MacroRecord[]); return defines; } + +export function addEffectDefaultProperties (effect: EffectAsset) { + for (let i = 0; i < effect.techniques.length; i++) { + const tech = effect.techniques[i]; + for (let j = 0; j < tech.passes.length; j++) { + const pass = tech.passes[j]; + // grab default property declaration if there is none + if (pass.propertyIndex !== undefined && pass.properties === undefined) { + pass.properties = tech.passes[pass.propertyIndex].properties; + } + } + } +} diff --git a/cocos/render-scene/scene/submodel.ts b/cocos/render-scene/scene/submodel.ts index 30a12e526b..ff2e2c5dac 100644 --- a/cocos/render-scene/scene/submodel.ts +++ b/cocos/render-scene/scene/submodel.ts @@ -24,10 +24,12 @@ */ import { RenderingSubMesh } from '../../asset/assets/rendering-sub-mesh'; -import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING, INST_MAT_WORLD, INST_SH, UBOSH } from '../../rendering/define'; +import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING, + INST_MAT_WORLD, INST_SH, UBOSH, isEnableEffect } from '../../rendering/define'; import { BatchingSchemes, IMacroPatch, Pass } from '../core/pass'; import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, TextureType, TextureUsageBit, TextureInfo, - Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager, Attribute, Feature, FormatInfos, getTypedArrayConstructor } from '../../gfx'; + Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager, + Attribute, Feature, FormatInfos, getTypedArrayConstructor } from '../../gfx'; import { errorID, Mat4, cclegacy } from '../../core'; import { getPhaseID } from '../../rendering/pass-phase'; import { Root } from '../../root'; @@ -196,7 +198,7 @@ export class SubModel { * @en Get or set instance matrix id, access by sub model * @zh 获取或者设置硬件实例化中的矩阵索引,通过子模型访问 */ - set instancedWorldMatrixIndex (val : number) { + set instancedWorldMatrixIndex (val: number) { this._instancedWorldMatrixIndex = val; } get instancedWorldMatrixIndex () { @@ -207,7 +209,7 @@ export class SubModel { * @en Get or set instance SH id, access by sub model * @zh 获取或者设置硬件实例化中的球谐索引,通过子模型访问 */ - set instancedSHIndex (val : number) { + set instancedSHIndex (val: number) { this._instancedSHIndex = val; } get instancedSHIndex () { @@ -260,9 +262,10 @@ export class SubModel { } this.priority = RenderPriority.DEFAULT; - + const r = cclegacy.rendering; // initialize resources for reflection material - if (passes[0].phase === getPhaseID('reflection')) { + if (((!r || !r.enableEffectImport) && passes[0].phase === getPhaseID('reflection')) + || (isEnableEffect() && passes[0].phaseID === r.getPhaseID(r.getPassID('default'), 'reflection'))) { let texWidth = root.mainWindow!.width; let texHeight = root.mainWindow!.height; const minSize = 512; diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index f05d0c5f46..190ada0b63 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -1,4 +1,5 @@ -import { ClearFlagBit, Color, Format, LoadOp, Rect, StoreOp, Viewport } from '../../gfx'; +import { BufferInfo, Buffer, BufferUsageBit, ClearFlagBit, Color, DescriptorSet, + Format, LoadOp, MemoryUsageBit, Rect, Sampler, StoreOp, Texture, Viewport } from '../../gfx'; import { Camera, CSMLevel, DirectionalLight, Light, LightType, ReflectionProbe, ShadowType, SKYBOX_FLAG, SpotLight } from '../../render-scene/scene'; import { supportsR32FloatTexture } from '../define'; import { Pipeline } from './pipeline'; @@ -7,6 +8,9 @@ import { Vec4, macro, geometry, toRadian, cclegacy } from '../../core'; import { Material } from '../../asset/assets'; import { SRGBToLinear } from '../pipeline-funcs'; import { RenderWindow } from '../../render-scene/core/render-window'; +import { RenderData } from './render-graph'; +import { WebPipeline } from './web-pipeline'; +import { DescriptorBlockData, DescriptorSetData } from './layout-graph'; // Anti-aliasing type, other types will be gradually added in the future export enum AntiAliasing { @@ -1067,3 +1071,98 @@ export function updateCameraUBO (setter: any, camera: Readonly, ppl: Rea setter.setVec4('cc_screenScale', new Vec4(sceneData.shadingScale, sceneData.shadingScale, 1.0 / sceneData.shadingScale, 1.0 / sceneData.shadingScale)); setter.setVec4('cc_exposure', new Vec4(camera.exposure, 1.0 / camera.exposure, sceneData.isHDR ? 1.0 : 0.0, 1.0 / Camera.standardExposureValue)); } + +function bindDescValue (desc: DescriptorSet, binding: number, value) { + if (value instanceof Buffer) { + desc.bindBuffer(binding, value); + } else if (value instanceof Texture) { + desc.bindTexture(binding, value); + } else if (value instanceof Sampler) { + desc.bindSampler(binding, value); + } +} + +function bindGlobalDesc (pipeline: Pipeline, binding: number, value) { + bindDescValue(pipeline.descriptorSet, binding, value); +} + +function getDescBinding (descId, descData: DescriptorSetData): number { + const layoutData = descData; + // 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) { + return block.offset + i; + } + } + } + return -1; +} + +export function getDescBindingFromName (bindingName: string) { + const pipeline = cclegacy.director.root.pipeline as WebPipeline; + const layoutGraph = pipeline.layoutGraph; + const vertIds = layoutGraph.vertices(); + const descId = layoutGraph.attributeIndex.get(bindingName); + let currDesData; + for (const i of vertIds) { + const layout = layoutGraph.getLayout(i); + for (const [k, descData] of layout.descriptorSets) { + const layoutData = descData.descriptorSetLayoutData; + const blocks = layoutData.descriptorBlocks; + for (const b of blocks) { + for (const ds of b.descriptors) { + if (ds.descriptorID === descId) { + currDesData = descData; + return getDescBinding(descId, currDesData); + } + } + } + } + } + return -1; +} + +function applyGlobalDescBinding (pipeline: Pipeline, data: RenderData, isUpdate = false) { + const constants = data.constants; + const samplers = data.samplers; + const textures = data.textures; + const device = cclegacy.director.root.device; + const currPip = pipeline as WebPipeline; + for (const [key, value] of constants) { + const bindId = getDescBinding(key, currPip.globalDescriptorSetData); + let buffer = pipeline.descriptorSet.getBuffer(bindId); + let haveBuff = true; + if (!buffer && !isUpdate) { + buffer = device.createBuffer(new BufferInfo(BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST, + MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, + value.length * 4, + value.length * 4)); + haveBuff = false; + } + if (isUpdate) buffer.update(new Float32Array(value)); + if (!haveBuff) bindGlobalDesc(pipeline, bindId, buffer); + } + for (const [key, value] of textures) { + const bindId = getDescBinding(key, currPip.globalDescriptorSetData); + const tex = pipeline.descriptorSet.getTexture(bindId); + if (!tex || isUpdate) { + bindGlobalDesc(pipeline, bindId, value); + } + } + for (const [key, value] of samplers) { + const bindId = getDescBinding(key, currPip.globalDescriptorSetData); + const sampler = pipeline.descriptorSet.getSampler(bindId); + if (!sampler || isUpdate) { + bindGlobalDesc(pipeline, bindId, value); + } + } +} + +export function initGlobalDescBinding (pipeline: Pipeline, data: RenderData) { + applyGlobalDescBinding(pipeline, data); +} + +export function updateGlobalDescBinding (pipeline: Pipeline, data: RenderData) { + applyGlobalDescBinding(pipeline, data, true); +} diff --git a/cocos/rendering/custom/executor.ts b/cocos/rendering/custom/executor.ts index 7e1c4667a4..d5df7b9d90 100644 --- a/cocos/rendering/custom/executor.ts +++ b/cocos/rendering/custom/executor.ts @@ -30,7 +30,7 @@ */ /* eslint-disable max-len */ import { getPhaseID, InstancedBuffer, PipelineStateManager } from '..'; -import { assert } from '../../core'; +import { assert, cclegacy } from '../../core'; import intersect from '../../core/geometry/intersect'; import { Sphere } from '../../core/geometry/sphere'; import { AccessFlagBit, Attribute, Buffer, BufferInfo, BufferUsageBit, BufferViewInfo, Color, ColorAttachment, CommandBuffer, DepthStencilAttachment, DescriptorSet, DescriptorSetInfo, Device, deviceManager, Format, Framebuffer, @@ -40,13 +40,11 @@ import { legacyCC } from '../../core/global-exports'; import { Vec3 } from '../../core/math/vec3'; import { Vec4 } from '../../core/math/vec4'; import { BatchingSchemes } from '../../render-scene'; -import { DirectionalLight } from '../../render-scene/scene'; import { Camera } from '../../render-scene/scene/camera'; -import { LightType } from '../../render-scene/scene/light'; -import { CSMLevel, ShadowType } from '../../render-scene/scene/shadows'; +import { ShadowType } from '../../render-scene/scene/shadows'; import { Root } from '../../root'; import { BatchedBuffer } from '../batched-buffer'; -import { SetIndex, UBODeferredLight, UBOForwardLight, UBOLocal } from '../define'; +import { isEnableEffect, SetIndex, UBODeferredLight, UBOForwardLight, UBOLocal } from '../define'; import { PipelineSceneData } from '../pipeline-scene-data'; import { PipelineInputAssemblerData } from '../render-pipeline'; import { LayoutGraphData, PipelineLayoutData, RenderPhaseData, RenderStageData } from './layout-graph'; @@ -65,7 +63,7 @@ import { renderProfiler } from '../pipeline-funcs'; import { PlanarShadowQueue } from '../planar-shadow-queue'; import { DefaultVisitor, depthFirstSearch, ReferenceGraphView } from './graph'; import { VectorGraphColorMap } from './effect'; -import { getRenderArea } from './define'; +import { getDescBindingFromName, getRenderArea, updateGlobalDescBinding } from './define'; import { RenderReflectionProbeQueue } from '../render-reflection-probe-queue'; import { ReflectionProbeManager } from '../reflection-probe-manager'; @@ -371,6 +369,7 @@ class BlitDesc { const deferredLitsBufView = device.createBuffer(new BufferViewInfo(this._lightVolumeBuffer, 0, totalSize)); this._lightBufferData = new Float32Array(totalSize / Float32Array.BYTES_PER_ELEMENT); + const binding = isEnableEffect() ? getDescBindingFromName('CCForwardLight') : UBOForwardLight.BINDING; this._stageDesc.bindBuffer(UBOForwardLight.BINDING, deferredLitsBufView); } const _localUBO = device.createBuffer(new BufferInfo( @@ -389,7 +388,7 @@ class DeviceRenderQueue { private _postSceneTasks: DevicePostSceneTask[] = []; private _devicePass: DeviceRenderPass; private _hint: QueueHint = QueueHint.NONE; - private _phaseID = getPhaseID('default'); + private _phaseID: number = getPhaseID('default'); private _renderPhase: RenderPhaseData | null = null; protected _transversal: DeviceSceneTransversal | null = null; get phaseID (): number { return this._phaseID; } @@ -402,6 +401,7 @@ class DeviceRenderQueue { get queueId () { return this._queueId; } constructor (devicePass: DeviceRenderPass) { this._devicePass = devicePass; + if (isEnableEffect()) this._phaseID = cclegacy.rendering.getPhaseID(devicePass.passID, 'default'); this._sceneVisitor = new WebSceneVisitor(this._devicePass.context.commandBuffer, this._devicePass.context.pipeline.pipelineSceneData); } @@ -455,7 +455,7 @@ class DeviceRenderQueue { class SubmitInfo { public instances = new Set(); - public renderInstanceQueue : InstancedBuffer[] = []; + public renderInstanceQueue: InstancedBuffer[] = []; public batches = new Set(); public opaqueList: RenderInfo[] = []; public transparentList: RenderInfo[] = []; @@ -534,6 +534,7 @@ class DeviceRenderPass { protected _deviceQueues: DeviceRenderQueue[] = []; protected _clearDepth = 1; protected _clearStencil = 0; + protected _passID: number; protected _context: ExecutorContext; protected _viewport: Viewport | null = null; private _rasterInfo: RasterPassInfo; @@ -543,6 +544,7 @@ class DeviceRenderPass { this._context = context; this._rasterInfo = passInfo; const device = context.device; + this._passID = cclegacy.rendering.getPassID(this._context.renderGraph.getLayout(passInfo.id)); const depthStencilAttachment = new DepthStencilAttachment(); depthStencilAttachment.format = Format.DEPTH_STENCIL; depthStencilAttachment.depthLoadOp = LoadOp.DISCARD; @@ -636,6 +638,7 @@ class DeviceRenderPass { swapchain ? [swapchain.colorTexture] : colorTexs, swapchain ? swapchain.depthStencilTexture : depthTex)); } + get passID (): number { return this._passID; } get renderLayout () { return this._layout; } get context () { return this._context; } get renderPass () { return this._renderPass; } @@ -669,7 +672,7 @@ class DeviceRenderPass { const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS)!; return layoutData; } - genQuadVertexData (surfaceTransform: SurfaceTransform, renderArea: Rect) : Float32Array { + genQuadVertexData (surfaceTransform: SurfaceTransform, renderArea: Rect): Float32Array { const vbData = new Float32Array(4 * 4); const minX = renderArea.x / this._context.width; @@ -905,7 +908,7 @@ class DevicePreSceneTask extends WebSceneTask { for (const subModel of subModels) { const passes = subModel.passes; for (const p of passes) { - if (p.phase !== this._currentQueue.phaseID) continue; + if (((isEnableEffect()) ? p.phaseID : p.phase) !== this._currentQueue.phaseID) continue; const batchingScheme = p.batchingScheme; if (batchingScheme === BatchingSchemes.INSTANCING) { const instancedBuffer = p.getInstancedBuffer(); @@ -961,8 +964,10 @@ class DevicePreSceneTask extends WebSceneTask { const pass = subModel.passes[passIdx]; const shader = subModel.shaders[passIdx]; const currTransparent = pass.blendState.targets[0].blend; - const phases = getPhaseID('default') | getPhaseID('planarShadow'); - if (currTransparent !== isTransparent || !(pass.phase & (isTransparent ? phases : this._currentQueue.phaseID))) { + const passId = this._currentQueue.devicePass.passID; + const phase = isEnableEffect() ? cclegacy.rendering.getPhaseID(passId, 'default') | cclegacy.rendering.getPhaseID(passId, 'planarShadow') + : getPhaseID('default') | getPhaseID('planarShadow'); + if (currTransparent !== isTransparent || !(pass.phaseID & (isTransparent ? phase : this._currentQueue.phaseID))) { return; } const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | passIdx; @@ -1022,57 +1027,8 @@ class DevicePreSceneTask extends WebSceneTask { && this.graphScene.scene!.flags & SceneFlags.SHADOW_CASTER; } - private _bindDescValue (desc: DescriptorSet, binding: number, value) { - if (value instanceof Buffer) { - desc.bindBuffer(binding, value); - } else if (value instanceof Texture) { - desc.bindTexture(binding, value); - } else if (value instanceof Sampler) { - desc.bindSampler(binding, value); - } - } - - private _bindGlobalDesc (context: ExecutorContext, binding: number, value) { - const layoutData = this._currentQueue.devicePass.getGlobalDescData(context)!; - this._bindDescValue(layoutData.descriptorSet!, binding, value); - } - - private _bindDescriptor (context: ExecutorContext, descId: number, value) { - const layoutData = this._currentQueue.devicePass.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) { - this._bindGlobalDesc(context, block.offset + i, value); - } - } - } - } - 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) { - let buffer = context.pipeline.descriptorSet.getBuffer(key); - let haveBuff = true; - if (!buffer) { - buffer = device.createBuffer(new BufferInfo(BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST, - MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, - value.length * 4, - value.length * 4)); - haveBuff = false; - } - buffer.update(new Float32Array(value)); - if (!haveBuff) 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); - } + updateGlobalDescBinding(context.pipeline, data); context.pipeline.descriptorSet.update(); } @@ -1222,7 +1178,7 @@ class DeviceSceneTask extends WebSceneTask { const count = batch.shaders.length; for (let j = 0; j < count; j++) { const pass = batch.passes[j]; - if (pass.phase !== this._currentQueue.phaseID) continue; + if (((isEnableEffect()) ? pass.phaseID : pass.phase) !== this._currentQueue.phaseID) continue; const shader = batch.shaders[j]; const inputAssembler: any = batch.inputAssembler!; const pso = PipelineStateManager.getOrCreatePipelineState(deviceManager.gfxDevice, pass, shader, this._renderPass, inputAssembler); diff --git a/cocos/rendering/custom/index.jsb.ts b/cocos/rendering/custom/index.jsb.ts index 796380a9a1..0397fc416e 100644 --- a/cocos/rendering/custom/index.jsb.ts +++ b/cocos/rendering/custom/index.jsb.ts @@ -25,7 +25,7 @@ declare const render: any; -import { Pipeline, PipelineBuilder } from './pipeline'; +import { Pipeline, PipelineBuilder, RenderingModule } from './pipeline'; import { buildDeferredLayout, buildForwardLayout } from './effect'; import { macro } from '../../core/platform/macro'; import { DeferredPipelineBuilder, ForwardPipelineBuilder } from './builtin-pipelines'; @@ -39,6 +39,8 @@ export * from './archive'; export const INVALID_ID = 0xFFFFFFFF; export const enableEffectImport = false; +let _renderModule: RenderingModule; + export function createCustomPipeline (): Pipeline { const ppl = render.Factory.createPipeline(); const pplName = macro.CUSTOM_PIPELINE_NAME; @@ -76,19 +78,28 @@ function addCustomBuiltinPipelines (map: Map) { addCustomBuiltinPipelines(customPipelineBuilderMap); export function init (device: Device, arrayBuffer: ArrayBuffer) { - // noop + _renderModule = render.Factory.init(device, arrayBuffer); } export function destroy () { - // noop + render.Factory.destroy(_renderModule); } export function getPassID (name: string | undefined): number { - return INVALID_ID; + if (name === undefined) { + return _renderModule.getPassID('default'); + } + return _renderModule.getPassID(name); } export function getPhaseID (passID: number, name: string | number | undefined): number { - return INVALID_ID; + if (name === undefined) { + return _renderModule.getPhaseID(passID, 'default'); + } + if (typeof(name) === 'number') { + return _renderModule.getPhaseID(passID, name.toString()); + } + return _renderModule.getPhaseID(passID, name); } export function completePhaseName (name: string | number | undefined): string { diff --git a/cocos/rendering/custom/index.ts b/cocos/rendering/custom/index.ts index 8a1682ff58..95e48e7c46 100644 --- a/cocos/rendering/custom/index.ts +++ b/cocos/rendering/custom/index.ts @@ -23,6 +23,7 @@ THE SOFTWARE. */ +import { EDITOR } from 'internal:constants'; import { Pipeline, PipelineBuilder } from './pipeline'; import { WebPipeline } from './web-pipeline'; import { buildDeferredLayout, buildForwardLayout } from './effect'; diff --git a/cocos/rendering/custom/layout-graph-utils.ts b/cocos/rendering/custom/layout-graph-utils.ts index f5022c3615..eed4a84dcb 100644 --- a/cocos/rendering/custom/layout-graph-utils.ts +++ b/cocos/rendering/custom/layout-graph-utils.ts @@ -32,6 +32,9 @@ import { DescriptorBlockData, DescriptorData, DescriptorDB, DescriptorSetData, D import { LayoutGraphBuilder } from './pipeline'; import { UpdateFrequency, getUpdateFrequencyName, getDescriptorTypeOrderName, Descriptor, DescriptorBlock, DescriptorBlockFlattened, DescriptorBlockIndex, DescriptorTypeOrder, ParameterType } from './types'; +export const INVALID_ID = 0xFFFFFFFF; + +// get name of gfx.Type function getGfxTypeName (type: Type): string { switch (type) { case Type.UNKNOWN: return 'Unknown'; @@ -85,6 +88,7 @@ function getGfxTypeName (type: Type): string { } } +// get DescriptorType from DescriptorTypeOrder export function getGfxDescriptorType (type: DescriptorTypeOrder): DescriptorType { switch (type) { case DescriptorTypeOrder.UNIFORM_BUFFER: @@ -111,10 +115,40 @@ export function getGfxDescriptorType (type: DescriptorTypeOrder): DescriptorType } } +// get DescriptorTypeOrder from DescriptorType +export function getDescriptorTypeOrder (type: DescriptorType): DescriptorTypeOrder { + switch (type) { + case DescriptorType.UNIFORM_BUFFER: + return DescriptorTypeOrder.UNIFORM_BUFFER; + case DescriptorType.DYNAMIC_UNIFORM_BUFFER: + return DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER; + case DescriptorType.SAMPLER_TEXTURE: + return DescriptorTypeOrder.SAMPLER_TEXTURE; + case DescriptorType.SAMPLER: + return DescriptorTypeOrder.SAMPLER; + case DescriptorType.TEXTURE: + return DescriptorTypeOrder.TEXTURE; + case DescriptorType.STORAGE_BUFFER: + return DescriptorTypeOrder.STORAGE_BUFFER; + case DescriptorType.DYNAMIC_STORAGE_BUFFER: + return DescriptorTypeOrder.DYNAMIC_STORAGE_BUFFER; + case DescriptorType.STORAGE_IMAGE: + return DescriptorTypeOrder.STORAGE_IMAGE; + case DescriptorType.INPUT_ATTACHMENT: + return DescriptorTypeOrder.INPUT_ATTACHMENT; + case DescriptorType.UNKNOWN: + default: + console.error('DescriptorTypeOrder not found'); + return DescriptorTypeOrder.INPUT_ATTACHMENT; + } +} + +// find passID using name export function getCustomPassID (lg: LayoutGraphData, name: string | undefined): number { return lg.locateChild(lg.nullVertex(), name || 'default'); } +// find phaseID using passID and phase name export function getCustomPhaseID (lg: LayoutGraphData, passID: number, name: string | number | undefined): number { if (name === undefined) { return lg.locateChild(passID, 'default'); @@ -125,10 +159,12 @@ export function getCustomPhaseID (lg: LayoutGraphData, passID: number, name: str return lg.locateChild(passID, name); } +// check ShaderStageFlagBit has certain bits function hasFlag (flags: ShaderStageFlagBit, flagToTest: ShaderStageFlagBit): boolean { return (flags & flagToTest) !== 0; } +// get name of visibility function getVisibilityName (stage: ShaderStageFlagBit): string { let count = 0; let str = ''; @@ -177,6 +213,7 @@ function getVisibilityName (stage: ShaderStageFlagBit): string { return str; } +// print LayoutGraphData export class PrintVisitor extends DefaultVisitor { discoverVertex (u: number, g: LayoutGraphData) { const ppl: PipelineLayoutData = g.getLayout(u); @@ -248,14 +285,17 @@ export class PrintVisitor extends DefaultVisitor { oss = ''; } +// text tools, indent 4 spaces function indent (space: string): string { return `${space} `; } +// text tools, unindent 4 spaces function unindent (space: string): string { return space.substring(0, space.length > 4 ? space.length - 4 : 0); } +// flatten DescriptorBlock to DescriptorBlockFlattened function convertDescriptorBlock (block: DescriptorBlock): DescriptorBlockFlattened { const flattened = new DescriptorBlockFlattened(); @@ -291,6 +331,7 @@ function convertDescriptorBlock (block: DescriptorBlock): DescriptorBlockFlatten return flattened; } +// cache of descriptor blocks class DescriptorCounter { public addDescriptor (key: string, name: string, count: number) { // key is DescriptorBlockIndex @@ -310,6 +351,7 @@ class DescriptorCounter { readonly inspector = new Map>(); } +// print LayoutGraph (not LayoutGraphData) class LayoutGraphPrintVisitor extends DefaultVisitor { discoverVertex (v: number, g: LayoutGraph) { const info: DescriptorDB = g.getDescriptors(v); @@ -364,6 +406,7 @@ class LayoutGraphPrintVisitor extends DefaultVisitor { oss = ''; } +// get pass name from effect function getPassName (pass: EffectAsset.IPassInfo): string { if (pass.pass === undefined) { return 'default'; @@ -371,6 +414,7 @@ function getPassName (pass: EffectAsset.IPassInfo): string { return pass.pass; } +// get phase name from effect function getPhaseName (pass: EffectAsset.IPassInfo): string { if (pass.phase === undefined) { return 'default'; @@ -381,6 +425,7 @@ function getPhaseName (pass: EffectAsset.IPassInfo): string { return pass.phase; } +// key of Visibility export class VisibilityIndex { constructor ( updateFrequency = UpdateFrequency.PER_INSTANCE, @@ -396,6 +441,7 @@ export class VisibilityIndex { descriptorType: DescriptorTypeOrder; } +// descriptors of same visibility export class VisibilityBlock { public mergeVisibility (name: string, vis: ShaderStageFlagBit) { // for each descriptor, merge visibility @@ -418,6 +464,7 @@ export class VisibilityBlock { descriptors = new Map(); } +// visibility database of phase export class VisibilityDB { public getBlock (index: VisibilityIndex): VisibilityBlock { const key = JSON.stringify(index); @@ -431,6 +478,7 @@ export class VisibilityDB { blocks = new Map(); } +// visibility database of pass export class VisibilityPass { public getPhase (phaseName: string): VisibilityDB { const phase = this.phases.get(phaseName); @@ -516,6 +564,7 @@ export class VisibilityGraph { passes = new Map(); } +// graph coloring help class class VectorGraphColorMap implements MutableVertexPropertyMap { constructor (sz: number) { this.colors = new Array(sz); @@ -529,6 +578,7 @@ class VectorGraphColorMap implements MutableVertexPropertyMap { readonly colors: Array; } +// class to layout all descriptors export class LayoutGraphInfo { constructor (visg: VisibilityGraph) { this.visg = visg; @@ -925,6 +975,7 @@ export class LayoutGraphInfo { } } +// sort descriptorBlocks using DescriptorBlockIndex function sortDescriptorBlocks (lhs: [string, T], rhs: [string, T]): number { const lhsIndex: DescriptorBlockIndex = JSON.parse(lhs[0]); const rhsIndex: DescriptorBlockIndex = JSON.parse(rhs[0]); @@ -939,6 +990,7 @@ function sortDescriptorBlocks (lhs: [string, T], rhs: [string, T]): number { return lhsValue - rhsValue; } +// build LayoutGraphData function buildLayoutGraphDataImpl (graph: LayoutGraph, builder: LayoutGraphBuilder) { for (const v of graph.vertices()) { const db = graph.getDescriptors(v); @@ -1001,7 +1053,8 @@ function buildLayoutGraphDataImpl (graph: LayoutGraph, builder: LayoutGraphBuild } } -function getDescriptorID (lg: LayoutGraphData, name: string): number { +// get descriptor nameID from name +export function getOrCreateDescriptorID (lg: LayoutGraphData, name: string): number { const nameID = lg.attributeIndex.get(name); if (nameID === undefined) { const newID = lg.valueNames.length; @@ -1012,6 +1065,7 @@ function getDescriptorID (lg: LayoutGraphData, name: string): number { return nameID; } +// LayoutGraphData builder class LayoutGraphBuilder2 implements LayoutGraphBuilder { public constructor (lg: LayoutGraphData) { this.lg = lg; @@ -1084,7 +1138,7 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder { for (let j = 0; j < block.descriptors.length; ++j) { const name: string = block.descriptorNames[j]; const d: Descriptor = block.descriptors[j]; - const nameID = getDescriptorID(lg, name); + const nameID = getOrCreateDescriptorID(lg, name); const data = new DescriptorData(nameID, d.type, d.count); dstBlock.descriptors.push(data); } @@ -1095,7 +1149,7 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder { const ppl: PipelineLayoutData = g.getLayout(nodeID); const setData = this.getDescriptorSetData(ppl, index.updateFrequency); const layout = setData.descriptorSetLayoutData; - const nameID = getDescriptorID(g, name); + const nameID = getOrCreateDescriptorID(g, name); layout.uniformBlocks.set(nameID, uniformBlock); } reserveDescriptorBlock (nodeID: number, index: DescriptorBlockIndex, block: DescriptorBlockFlattened): void { @@ -1140,6 +1194,7 @@ export function printLayoutGraphData (g: LayoutGraphData): string { return visitor.oss; } +// lookup DescriptorBlockData from Map function getDescriptorBlockData (map: Map, index: DescriptorBlockIndex): DescriptorBlockData { const key = JSON.stringify(index); const block = map.get(key); @@ -1151,6 +1206,7 @@ function getDescriptorBlockData (map: Map, index: D return newBlock; } +// make DescriptorSetLayoutData from effect directly export function makeDescriptorSetLayoutData (lg: LayoutGraphData, rate: UpdateFrequency, set: number, descriptors: EffectAsset.IDescriptorInfo): DescriptorSetLayoutData { @@ -1164,7 +1220,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.UNIFORM_BUFFER, visibility: cb.stageFlags, }); - const nameID = getDescriptorID(lg, cb.name); + const nameID = getOrCreateDescriptorID(lg, cb.name); block.descriptors.push(new DescriptorData(nameID, Type.UNKNOWN, 1)); // add uniform buffer uniformBlocks.set(nameID, new UniformBlock(set, 0xFFFFFFFF, cb.name, cb.members, 1)); @@ -1177,7 +1233,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.SAMPLER_TEXTURE, visibility: samplerTexture.stageFlags, }); - const nameID = getDescriptorID(lg, samplerTexture.name); + const nameID = getOrCreateDescriptorID(lg, samplerTexture.name); block.descriptors.push(new DescriptorData(nameID, samplerTexture.type, samplerTexture.count)); } for (let i = 0; i < descriptors.samplers.length; i++) { @@ -1188,7 +1244,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.SAMPLER, visibility: sampler.stageFlags, }); - const nameID = getDescriptorID(lg, sampler.name); + const nameID = getOrCreateDescriptorID(lg, sampler.name); block.descriptors.push(new DescriptorData(nameID, Type.SAMPLER, sampler.count)); } for (let i = 0; i < descriptors.textures.length; i++) { @@ -1199,7 +1255,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.TEXTURE, visibility: texture.stageFlags, }); - const nameID = getDescriptorID(lg, texture.name); + const nameID = getOrCreateDescriptorID(lg, texture.name); block.descriptors.push(new DescriptorData(nameID, texture.type, texture.count)); } for (let i = 0; i < descriptors.buffers.length; i++) { @@ -1210,7 +1266,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.STORAGE_BUFFER, visibility: buffer.stageFlags, }); - const nameID = getDescriptorID(lg, buffer.name); + const nameID = getOrCreateDescriptorID(lg, buffer.name); block.descriptors.push(new DescriptorData(nameID, Type.UNKNOWN, 1)); } for (let i = 0; i < descriptors.images.length; i++) { @@ -1221,7 +1277,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.STORAGE_IMAGE, visibility: image.stageFlags, }); - const nameID = getDescriptorID(lg, image.name); + const nameID = getOrCreateDescriptorID(lg, image.name); block.descriptors.push(new DescriptorData(nameID, image.type, image.count)); } for (let i = 0; i < descriptors.subpassInputs.length; i++) { @@ -1232,7 +1288,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, descriptorType: DescriptorTypeOrder.INPUT_ATTACHMENT, visibility: subpassInput.stageFlags, }); - const nameID = getDescriptorID(lg, subpassInput.name); + const nameID = getOrCreateDescriptorID(lg, subpassInput.name); block.descriptors.push(new DescriptorData(nameID, Type.UNKNOWN, subpassInput.count)); } @@ -1258,6 +1314,11 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, data.uniformBlocks.set(d.descriptorID, ub); } // update block capacity + const binding = data.bindingMap.get(d.descriptorID); + if (binding !== undefined) { + console.error(`Duplicated descriptor ${d.descriptorID}`); + } + data.bindingMap.set(d.descriptorID, block.offset + block.capacity); block.capacity += d.count; } // increate total capacity @@ -1267,6 +1328,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, return data; } +// fill DescriptorSetLayoutInfo from DescriptorSetLayoutData export function initializeDescriptorSetLayoutInfo (layoutData: DescriptorSetLayoutData, info: DescriptorSetLayoutInfo): void { for (let i = 0; i < layoutData.descriptorBlocks.length; ++i) { @@ -1299,6 +1361,7 @@ function populatePipelineLayoutInfo (layout: PipelineLayoutData, } } +// initialize layout graph module export function initializeLayoutGraphData (device: Device, lg: LayoutGraphData) { // create descriptor sets _emptyDescriptorSetLayout = device.createDescriptorSetLayout(new DescriptorSetLayoutInfo()); @@ -1333,6 +1396,7 @@ export function initializeLayoutGraphData (device: Device, lg: LayoutGraphData) } } +// terminate layout graph module export function terminateLayoutGraphData (lg: LayoutGraphData) { for (const v of lg.vertices()) { const layoutData = lg.getLayout(v); @@ -1346,14 +1410,17 @@ export function terminateLayoutGraphData (lg: LayoutGraphData) { _emptyDescriptorSetLayout.destroy(); } +// get empty descriptor set layout export function getEmptyDescriptorSetLayout (): DescriptorSetLayout { return _emptyDescriptorSetLayout; } +// get empty pipeline layout export function getEmptyPipelineLayout (): PipelineLayout { return _emptyPipelineLayout; } +// get descriptor set from LayoutGraphData (not from ProgramData) export function getOrCreateDescriptorSetLayout (lg: LayoutGraphData, passID: number, phaseID: number, rate: UpdateFrequency): DescriptorSetLayout { if (rate < UpdateFrequency.PER_PASS) { @@ -1384,6 +1451,7 @@ export function getOrCreateDescriptorSetLayout (lg: LayoutGraphData, return _emptyDescriptorSetLayout; } +// getDescriptorSetLayout from LayoutGraphData export function getDescriptorSetLayout (lg: LayoutGraphData, passID: number, phaseID: number, rate: UpdateFrequency): DescriptorSetLayout | null { if (rate < UpdateFrequency.PER_PASS) { @@ -1414,26 +1482,97 @@ export function getDescriptorSetLayout (lg: LayoutGraphData, return null; } -const _emptyDescriptorSetLayoutData = new DescriptorSetLayoutData(); - -export function getDescriptorSetLayoutData (lg: LayoutGraphData, - passID: number, phaseID: number, rate: UpdateFrequency): DescriptorSetLayoutData { - if (rate < UpdateFrequency.PER_PASS) { - const phaseData = lg.getLayout(phaseID); - const data = phaseData.descriptorSets.get(rate); - if (data !== undefined) { - return data.descriptorSetLayoutData; +// get or create DescriptorBlockData from DescriptorSetLayoutData +export function getOrCreateDescriptorBlockData (data: DescriptorSetLayoutData, + type: DescriptorType, vis: ShaderStageFlagBit): DescriptorBlockData { + const order = getDescriptorTypeOrder(type); + for (const block of data.descriptorBlocks) { + if (block.type === order && block.visibility === vis) { + return block; } - return _emptyDescriptorSetLayoutData; } - - assert(rate === UpdateFrequency.PER_PASS); - assert(passID === lg.getParent(phaseID)); - - const passData = lg.getLayout(passID); - const data = passData.descriptorSets.get(rate); - if (data) { - return data.descriptorSetLayoutData; - } - return _emptyDescriptorSetLayoutData; + const block = new DescriptorBlockData(order, vis); + data.descriptorBlocks.push(block); + return block; +} + +export function getProgramID (lg: LayoutGraphData, phaseID: number, programName: string): number { + assert(phaseID !== lg.nullVertex()); + const phase = lg.getRenderPhase(phaseID); + const programID = phase.shaderIndex.get(programName); + if (programID === undefined) { + return INVALID_ID; + } + return programID; +} + +export function getDescriptorNameID (lg: LayoutGraphData, name: string): number { + const nameID = lg.attributeIndex.get(name); + if (nameID === undefined) { + return INVALID_ID; + } + return nameID; +} + +export function getDescriptorName (lg: LayoutGraphData, nameID: number): string { + if (nameID >= lg.valueNames.length) { + return ''; + } + return lg.valueNames[nameID]; +} + +export function getPerPassDescriptorSetLayoutData (lg: LayoutGraphData, + passID: number): DescriptorSetLayoutData | null { + assert(passID !== lg.nullVertex()); + const node = lg.getLayout(passID); + const set = node.descriptorSets.get(UpdateFrequency.PER_PASS); + if (set === undefined) { + return null; + } + return set.descriptorSetLayoutData; +} + +export function getPerPhaseDescriptorSetLayoutData (lg: LayoutGraphData, + phaseID: number): DescriptorSetLayoutData | null { + assert(phaseID !== lg.nullVertex()); + const node = lg.getLayout(phaseID); + const set = node.descriptorSets.get(UpdateFrequency.PER_PHASE); + if (set === undefined) { + return null; + } + return set.descriptorSetLayoutData; +} + +export function getPerBatchDescriptorSetLayoutData (lg: LayoutGraphData, + phaseID: number, programID): DescriptorSetLayoutData | null { + assert(phaseID !== lg.nullVertex()); + const phase = lg.getRenderPhase(phaseID); + assert(programID < phase.shaderPrograms.length); + const program = phase.shaderPrograms[programID]; + const set = program.layout.descriptorSets.get(UpdateFrequency.PER_BATCH); + if (set === undefined) { + return null; + } + return set.descriptorSetLayoutData; +} + +export function getPerInstanceDescriptorSetLayoutData (lg: LayoutGraphData, + phaseID: number, programID): DescriptorSetLayoutData | null { + assert(phaseID !== lg.nullVertex()); + const phase = lg.getRenderPhase(phaseID); + assert(programID < phase.shaderPrograms.length); + const program = phase.shaderPrograms[programID]; + const set = program.layout.descriptorSets.get(UpdateFrequency.PER_INSTANCE); + if (set === undefined) { + return null; + } + return set.descriptorSetLayoutData; +} + +export function getBinding (layout: DescriptorSetLayoutData, nameID: number) { + const binding = layout.bindingMap.get(nameID); + if (binding === undefined) { + return 0xFFFFFFFF; + } + return binding; } diff --git a/cocos/rendering/custom/layout-graph.ts b/cocos/rendering/custom/layout-graph.ts index 953e180e80..d4228e7461 100644 --- a/cocos/rendering/custom/layout-graph.ts +++ b/cocos/rendering/custom/layout-graph.ts @@ -605,16 +605,24 @@ export class DescriptorBlockData { } export class DescriptorSetLayoutData { - constructor (slot = 0xFFFFFFFF, capacity = 0, descriptorBlocks: DescriptorBlockData[] = [], uniformBlocks: Map = new Map()) { + constructor ( + slot = 0xFFFFFFFF, + capacity = 0, + descriptorBlocks: DescriptorBlockData[] = [], + uniformBlocks: Map = new Map(), + bindingMap: Map = new Map(), + ) { this.slot = slot; this.capacity = capacity; this.descriptorBlocks = descriptorBlocks; this.uniformBlocks = uniformBlocks; + this.bindingMap = bindingMap; } slot: number; capacity: number; readonly descriptorBlocks: DescriptorBlockData[]; readonly uniformBlocks: Map; + readonly bindingMap: Map; } export class DescriptorSetData { @@ -1420,6 +1428,11 @@ export function saveDescriptorSetLayoutData (ar: OutputArchive, v: DescriptorSet ar.writeNumber(k1); saveUniformBlock(ar, v1); } + ar.writeNumber(v.bindingMap.size); // Map + for (const [k1, v1] of v.bindingMap) { + ar.writeNumber(k1); + ar.writeNumber(v1); + } } export function loadDescriptorSetLayoutData (ar: InputArchive, v: DescriptorSetLayoutData) { @@ -1440,6 +1453,12 @@ export function loadDescriptorSetLayoutData (ar: InputArchive, v: DescriptorSetL loadUniformBlock(ar, v1); v.uniformBlocks.set(k1, v1); } + sz = ar.readNumber(); // Map + for (let i1 = 0; i1 !== sz; ++i1) { + const k1 = ar.readNumber(); + const v1 = ar.readNumber(); + v.bindingMap.set(k1, v1); + } } export function saveDescriptorSetData (ar: OutputArchive, v: DescriptorSetData) { diff --git a/cocos/rendering/custom/pipeline.ts b/cocos/rendering/custom/pipeline.ts index 8bafe22508..d0ae3a991d 100644 --- a/cocos/rendering/custom/pipeline.ts +++ b/cocos/rendering/custom/pipeline.ts @@ -189,5 +189,10 @@ export interface PipelineBuilder { setup (cameras: Camera[], pipeline: Pipeline): void; } +export interface RenderingModule { + getPassID (name: string): number; + getPhaseID (passID: number, name: string): number; +} + export class Factory { } diff --git a/cocos/rendering/custom/private.ts b/cocos/rendering/custom/private.ts index dd6bef8031..c447a17bfd 100644 --- a/cocos/rendering/custom/private.ts +++ b/cocos/rendering/custom/private.ts @@ -52,4 +52,7 @@ export interface ProgramLibrary { getProgramVariant (device: Device, phaseID: number, name: string, defines: MacroRecord/*, null*/): ProgramProxy | null; getBlockSizes (phaseID: number, programName: string): number[]; getHandleMap (phaseID: number, programName: string): Record; + getProgramID (phaseID: number, programName: string): number; + getDescriptorNameID (name: string): number; + getDescriptorName (nameID: number): string; } diff --git a/cocos/rendering/custom/web-pipeline.ts b/cocos/rendering/custom/web-pipeline.ts index 66c0056d1e..340f5b282f 100644 --- a/cocos/rendering/custom/web-pipeline.ts +++ b/cocos/rendering/custom/web-pipeline.ts @@ -52,6 +52,7 @@ import { CustomPipelineBuilder } from './custom-pipeline'; import { decideProfilerCamera } from '../pipeline-funcs'; import { DebugViewCompositeType } from '../debug-view'; import { getUBOTypeCount } from './utils'; +import { initGlobalDescBinding } from './define'; export class WebSetter { constructor (data: RenderData, lg: LayoutGraphData) { @@ -524,6 +525,7 @@ export class WebRasterQueueBuilder extends WebSetter implements RasterQueueBuild setShadowUBOView(this, camera); } setTextureUBOView(this, camera, this._pipeline); + initGlobalDescBinding(cclegacy.director.root.pipeline, this._data); } addScene (sceneName: string, sceneFlags = SceneFlags.NONE): void { const sceneData = new SceneData(sceneName, sceneFlags); @@ -550,6 +552,7 @@ export class WebRasterQueueBuilder extends WebSetter implements RasterQueueBuild setShadowUBOView(this, camera); } setTextureUBOView(this, camera, this._pipeline); + initGlobalDescBinding(cclegacy.director.root.pipeline, this._data); } clearRenderTarget (name: string, color: Color = new Color()) { this._renderGraph.addVertex( @@ -856,7 +859,7 @@ export class WebPipeline implements Pipeline { return this._combineSignY; } - public globalDescriptorSetData () { + get globalDescriptorSetData () { return this._globalDescSetData; } @@ -1147,6 +1150,7 @@ export class WebPipeline implements Pipeline { ); const result = new WebRasterPassBuilder(data, this._renderGraph!, this._layoutGraph, vertID, pass, this._pipelineSceneData); this._updateRasterPassConstants(result, width, height); + initGlobalDescBinding(cclegacy.director.root.pipeline, data); return result; } public getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout { @@ -1165,6 +1169,7 @@ export class WebPipeline implements Pipeline { get layoutGraph () { return this._layoutGraph; } + protected _updateRasterPassConstants (setter: WebSetter, width: number, height: number) { const director = cclegacy.director; const root = director.root; diff --git a/cocos/rendering/custom/web-program-library.ts b/cocos/rendering/custom/web-program-library.ts index e2766e77c2..c051e9b9a4 100644 --- a/cocos/rendering/custom/web-program-library.ts +++ b/cocos/rendering/custom/web-program-library.ts @@ -25,20 +25,21 @@ /* eslint-disable max-len */ import { EffectAsset } from '../../asset/assets'; -import { Attribute, DescriptorSetLayout, Device, MemoryAccessBit, PipelineLayout, PipelineLayoutInfo, Shader, ShaderInfo, ShaderStage, ShaderStageFlagBit, Uniform, UniformBlock, UniformInputAttachment, UniformSampler, UniformSamplerTexture, UniformStorageBuffer, UniformStorageImage, UniformTexture } from '../../gfx'; +import { Attribute, DescriptorSetLayout, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, Device, MemoryAccessBit, PipelineLayout, PipelineLayoutInfo, Shader, ShaderInfo, ShaderStage, ShaderStageFlagBit, Type, Uniform, UniformBlock, UniformInputAttachment, UniformSampler, UniformSamplerTexture, UniformStorageBuffer, UniformStorageImage, UniformTexture } from '../../gfx'; import { genHandles, getActiveAttributes, getCombinationDefines, getShaderInstanceName, getSize, getVariantKey, populateMacros, prepareDefines } from '../../render-scene/core/program-utils'; import { getDeviceShaderVersion, MacroRecord } from '../../render-scene'; import { IProgramInfo } from '../../render-scene/core/program-lib'; -import { DescriptorSetData, DescriptorSetLayoutData, LayoutGraphData, LayoutGraphDataValue, PipelineLayoutData, RenderPhaseData, ShaderProgramData } from './layout-graph'; +import { DescriptorBlockData, DescriptorData, DescriptorSetData, DescriptorSetLayoutData, LayoutGraphData, LayoutGraphDataValue, PipelineLayoutData, RenderPhaseData, ShaderProgramData } from './layout-graph'; import { ProgramLibrary, ProgramProxy } from './private'; import { DescriptorTypeOrder, UpdateFrequency } from './types'; -import { ProgramGroup, ProgramHost, ProgramInfo, ProgramLibraryData } from './web-types'; -import { getCustomPassID, getCustomPhaseID, getOrCreateDescriptorSetLayout, getEmptyDescriptorSetLayout, getEmptyPipelineLayout, initializeDescriptorSetLayoutInfo, makeDescriptorSetLayoutData, getDescriptorSetLayout } from './layout-graph-utils'; +import { ProgramGroup, ProgramHost, ProgramInfo } from './web-types'; +import { getCustomPassID, getCustomPhaseID, getOrCreateDescriptorSetLayout, getEmptyDescriptorSetLayout, getEmptyPipelineLayout, initializeDescriptorSetLayoutInfo, makeDescriptorSetLayoutData, getDescriptorSetLayout, getOrCreateDescriptorID, getDescriptorTypeOrder, getProgramID, getDescriptorNameID, getDescriptorName, INVALID_ID } from './layout-graph-utils'; import { assert } from '../../core/platform/debug'; +import { IDescriptorSetLayoutInfo, localDescriptorSetLayout } from '../define'; -const INVALID_ID = 0xFFFFFFFF; const _setIndex = [2, 1, 3, 0]; +// make IProgramInfo from IShaderInfo function makeProgramInfo (effectName: string, shader: EffectAsset.IShaderInfo): IProgramInfo { const programInfo = { ...shader } as IProgramInfo; programInfo.effectName = effectName; @@ -48,6 +49,7 @@ function makeProgramInfo (effectName: string, shader: EffectAsset.IShaderInfo): return programInfo; } +// overwrite IProgramInfo using gfx.ShaderInfo function overwriteProgramBlockInfo (shaderInfo: ShaderInfo, programInfo: IProgramInfo) { const set = _setIndex[UpdateFrequency.PER_BATCH]; for (const block of programInfo.blocks) { @@ -68,7 +70,8 @@ function overwriteProgramBlockInfo (shaderInfo: ShaderInfo, programInfo: IProgra } } -function populateMixedShaderInfo ( +// add descriptor to size-reserved descriptor set +function populateGroupedShaderInfo ( layout: DescriptorSetLayoutData, descriptorInfo: EffectAsset.IDescriptorInfo, set: number, shaderInfo: ShaderInfo, blockSizes: number[], @@ -169,6 +172,7 @@ function populateMixedShaderInfo ( } } +// add merged descriptor to gfx.ShaderInfo function populateMergedShaderInfo (valueNames: string[], layout: DescriptorSetLayoutData, set: number, shaderInfo: ShaderInfo, blockSizes: number[]) { @@ -255,6 +259,7 @@ function populateMergedShaderInfo (valueNames: string[], } } +// add descriptor from effect to gfx.ShaderInfo function populateShaderInfo ( descriptorInfo: EffectAsset.IDescriptorInfo, set: number, shaderInfo: ShaderInfo, blockSizes: number[], @@ -303,12 +308,46 @@ function populateShaderInfo ( } } +// add fixed local descriptors to gfx.ShaderInfo +function populateLocalShaderInfo ( + target: EffectAsset.IDescriptorInfo, + source: IDescriptorSetLayoutInfo, shaderInfo: ShaderInfo, blockSizes: number[], +) { + const set = _setIndex[UpdateFrequency.PER_INSTANCE]; + for (let i = 0; i < target.blocks.length; i++) { + const block = target.blocks[i]; + const info = source.layouts[block.name] as UniformBlock | undefined; + const binding = info && source.bindings.find((bd) => bd.binding === info.binding); + if (!info || !binding || !(binding.descriptorType & DESCRIPTOR_BUFFER_TYPE)) { + console.warn(`builtin UBO '${block.name}' not available!`); + continue; + } + blockSizes.push(getSize(block.members)); + shaderInfo.blocks.push(new UniformBlock(set, binding.binding, block.name, + block.members.map((m) => new Uniform(m.name, m.type, m.count)), 1)); // effect compiler guarantees block count = 1 + } + for (let i = 0; i < target.samplerTextures.length; i++) { + const samplerTexture = target.samplerTextures[i]; + const info = source.layouts[samplerTexture.name] as UniformSamplerTexture; + const binding = info && source.bindings.find((bd) => bd.binding === info.binding); + if (!info || !binding || !(binding.descriptorType & DESCRIPTOR_SAMPLER_TYPE)) { + console.warn(`builtin samplerTexture '${samplerTexture.name}' not available!`); + continue; + } + shaderInfo.samplerTextures.push(new UniformSamplerTexture( + set, binding.binding, samplerTexture.name, samplerTexture.type, samplerTexture.count, + )); + } +} + +// make gfx.ShaderInfo function makeShaderInfo ( lg: LayoutGraphData, passLayouts: PipelineLayoutData, phaseLayouts: PipelineLayoutData, srcShaderInfo: EffectAsset.IShaderInfo, programData: ShaderProgramData | null, + fixedLocal: boolean, ): [ShaderInfo, Array] { const shaderInfo = new ShaderInfo(); const blockSizes = new Array(); @@ -337,7 +376,7 @@ function makeShaderInfo ( } else { const batchLayout = phaseLayouts.descriptorSets.get(UpdateFrequency.PER_BATCH); if (batchLayout) { - populateMixedShaderInfo(batchLayout.descriptorSetLayoutData, + populateGroupedShaderInfo(batchLayout.descriptorSetLayoutData, batchInfo, _setIndex[UpdateFrequency.PER_BATCH], shaderInfo, blockSizes); } @@ -346,15 +385,19 @@ function makeShaderInfo ( { // instance const instanceInfo = srcShaderInfo.descriptors[UpdateFrequency.PER_INSTANCE]; if (programData) { - const perInstance = programData.layout.descriptorSets.get(UpdateFrequency.PER_INSTANCE); - if (perInstance) { - populateMergedShaderInfo(lg.valueNames, perInstance.descriptorSetLayoutData, - _setIndex[UpdateFrequency.PER_INSTANCE], shaderInfo, blockSizes); + if (fixedLocal) { + populateLocalShaderInfo(instanceInfo, localDescriptorSetLayout, shaderInfo, blockSizes); + } else { + const perInstance = programData.layout.descriptorSets.get(UpdateFrequency.PER_INSTANCE); + if (perInstance) { + populateMergedShaderInfo(lg.valueNames, perInstance.descriptorSetLayoutData, + _setIndex[UpdateFrequency.PER_INSTANCE], shaderInfo, blockSizes); + } } } else { const instanceLayout = phaseLayouts.descriptorSets.get(UpdateFrequency.PER_INSTANCE); if (instanceLayout) { - populateMixedShaderInfo(instanceLayout.descriptorSetLayoutData, + populateGroupedShaderInfo(instanceLayout.descriptorSetLayoutData, instanceInfo, _setIndex[UpdateFrequency.PER_INSTANCE], shaderInfo, blockSizes); } @@ -378,27 +421,93 @@ class WebProgramProxy implements ProgramProxy { host: ProgramHost; } +// find name and type from local descriptor set info +function getDescriptorNameAndType (source: IDescriptorSetLayoutInfo, binding: number): [string, Type] { + for (const name in source.layouts) { + const v = source.layouts[name]; + if (v.binding === binding) { + assert(v.name === name); + let type = Type.UNKNOWN; + if (v instanceof UniformSamplerTexture) { + type = v.type; + } else if (v instanceof UniformStorageImage) { + type = v.type; + } + return [v.name, type]; + } + } + console.error('descriptor not found'); + return ['', Type.UNKNOWN]; +} + +// make DescriptorSetLayoutData from local descriptor set info +function makeLocalDescriptorSetLayoutData (lg: LayoutGraphData, + source: IDescriptorSetLayoutInfo): DescriptorSetLayoutData { + const data = new DescriptorSetLayoutData(); + for (const b of source.bindings) { + const [name, type] = getDescriptorNameAndType(source, b.binding); + const nameID = getOrCreateDescriptorID(lg, name); + const order = getDescriptorTypeOrder(b.descriptorType); + const block = new DescriptorBlockData(order, b.stageFlags, b.count); + block.offset = b.binding; + block.descriptors.push(new DescriptorData(nameID, type, b.count)); + data.descriptorBlocks.push(block); + const binding = data.bindingMap.get(nameID); + if (binding !== undefined) { + console.error(`duplicate descriptor name '${name}'`); + } + data.bindingMap.set(nameID, b.binding); + const v = source.layouts[name]; + if (v instanceof UniformBlock) { + data.uniformBlocks.set(nameID, v); + } + } + return data; +} + +// make descriptor sets for ShaderProgramData (PerBatch, PerInstance) function buildProgramData ( programName: string, srcShaderInfo: EffectAsset.IShaderInfo, lg: LayoutGraphData, phase: RenderPhaseData, programData: ShaderProgramData, + fixedLocal: boolean, ) { { const perBatch = makeDescriptorSetLayoutData(lg, UpdateFrequency.PER_BATCH, _setIndex[UpdateFrequency.PER_BATCH], srcShaderInfo.descriptors[UpdateFrequency.PER_BATCH]); - const setData = new DescriptorSetData(perBatch); + const setData = new DescriptorSetData(perBatch); initializeDescriptorSetLayoutInfo(setData.descriptorSetLayoutData, setData.descriptorSetLayoutInfo); programData.layout.descriptorSets.set(UpdateFrequency.PER_BATCH, setData); } - { + if (fixedLocal) { + const perInstance = makeLocalDescriptorSetLayoutData(lg, localDescriptorSetLayout); + const setData = new DescriptorSetData(perInstance); + initializeDescriptorSetLayoutInfo(setData.descriptorSetLayoutData, + setData.descriptorSetLayoutInfo); + if (localDescriptorSetLayout.bindings.length !== setData.descriptorSetLayoutInfo.bindings.length) { + console.error('local descriptor set layout inconsistent'); + } else { + for (let k = 0; k !== localDescriptorSetLayout.bindings.length; ++k) { + const b = localDescriptorSetLayout.bindings[k]; + const b2 = setData.descriptorSetLayoutInfo.bindings[k]; + if (b.binding !== b2.binding + || b.descriptorType !== b2.descriptorType + || b.count !== b2.count + || b.stageFlags !== b2.stageFlags) { + console.error('local descriptor set layout inconsistent'); + } + } + } + programData.layout.descriptorSets.set(UpdateFrequency.PER_INSTANCE, setData); + } else { const perInstance = makeDescriptorSetLayoutData(lg, UpdateFrequency.PER_INSTANCE, _setIndex[UpdateFrequency.PER_INSTANCE], srcShaderInfo.descriptors[UpdateFrequency.PER_INSTANCE]); - const setData = new DescriptorSetData(perInstance); + const setData = new DescriptorSetData(perInstance); initializeDescriptorSetLayoutInfo(setData.descriptorSetLayoutData, setData.descriptorSetLayoutInfo); programData.layout.descriptorSets.set(UpdateFrequency.PER_INSTANCE, setData); @@ -408,6 +517,7 @@ function buildProgramData ( phase.shaderPrograms.push(programData); } +// get or create PerProgram gfx.DescriptorSetLayout function getOrCreateProgramDescriptorSetLayout (device: Device, lg: LayoutGraphData, phaseID: number, programName: string, rate: UpdateFrequency): DescriptorSetLayout { @@ -430,6 +540,7 @@ function getOrCreateProgramDescriptorSetLayout (device: Device, return layout.descriptorSetLayout; } +// get PerProgram gfx.DescriptorSetLayout function getProgramDescriptorSetLayout (device: Device, lg: LayoutGraphData, phaseID: number, programName: string, rate: UpdateFrequency): DescriptorSetLayout | null { @@ -452,6 +563,7 @@ function getProgramDescriptorSetLayout (device: Device, return layout.descriptorSetLayout; } +// find shader program in LayoutGraphData function getEffectShader (lg: LayoutGraphData, effect: EffectAsset, pass: EffectAsset.IPassInfo): [number, number, EffectAsset.IShaderInfo | null, number] { const programName = pass.program; @@ -478,6 +590,7 @@ function getEffectShader (lg: LayoutGraphData, effect: EffectAsset, return [passID, phaseID, srcShaderInfo, shaderID]; } +// valid IShaderInfo is compatible function validateShaderInfo (srcShaderInfo: EffectAsset.IShaderInfo): number { // source shader info if (srcShaderInfo.descriptors === undefined) { @@ -487,15 +600,16 @@ function validateShaderInfo (srcShaderInfo: EffectAsset.IShaderInfo): number { return 0; } -export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibrary { +export class WebProgramLibrary implements ProgramLibrary { constructor (lg: LayoutGraphData) { - super(lg); + this.layoutGraph = lg; for (const v of lg.vertices()) { if (lg.holds(LayoutGraphDataValue.RenderPhase, v)) { this.phases.set(v, new ProgramGroup()); } } } + // add effect to database addEffect (effect: EffectAsset): void { const lg = this.layoutGraph; for (const tech of effect.techniques) { @@ -526,12 +640,12 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr if (!this.mergeHighFrequency) { const phase = lg.getRenderPhase(phaseID); programData = new ShaderProgramData(); - buildProgramData(programName, srcShaderInfo, lg, phase, programData); + buildProgramData(programName, srcShaderInfo, lg, phase, programData, this.fixedLocal); } // shaderInfo and blockSizes const [shaderInfo, blockSizes] = makeShaderInfo(lg, passLayout, phaseLayout, - srcShaderInfo, programData); + srcShaderInfo, programData, this.fixedLocal); // overwrite programInfo overwriteProgramBlockInfo(shaderInfo, programInfo); @@ -551,6 +665,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr } } } + // precompile effect precompileEffect (device: Device, effect: EffectAsset): void { const lg = this.layoutGraph; for (const tech of effect.techniques) { @@ -575,6 +690,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr } } } + // get IProgramInfo getProgramInfo (phaseID: number, programName: string): IProgramInfo { assert(phaseID !== INVALID_ID); const group = this.phases.get(phaseID)!; @@ -582,13 +698,14 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr return info.programInfo; } + // get gfx.ShaderInfo getShaderInfo (phaseID: number, programName: string): ShaderInfo { assert(phaseID !== INVALID_ID); const group = this.phases.get(phaseID)!; const info = group.programInfos.get(programName)!; return info.shaderInfo; } - + // get shader key getKey (phaseID: number, programName: string, defines: MacroRecord): string { assert(phaseID !== INVALID_ID); // get phase @@ -605,7 +722,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr } return getVariantKey(info.programInfo, defines); } - + // get program variant getProgramVariant (device: Device, phaseID: number, name: string, defines: MacroRecord, key: string | null = null): ProgramProxy | null { assert(phaseID !== INVALID_ID); // get phase @@ -635,7 +752,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr // prepare variant const macroArray = prepareDefines(defines, programInfo.defines); const prefix = this.layoutGraph.constantMacros + programInfo.constantMacros - + macroArray.reduce((acc, cur) => `${acc}#define ${cur.name} ${cur.value}\n`, ''); + + macroArray.reduce((acc, cur) => `${acc}#define ${cur.name} ${cur.value}\n`, ''); let src = programInfo.glsl3; const deviceShaderVersion = getDeviceShaderVersion(device); @@ -662,6 +779,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr // create return new WebProgramProxy(host); } + // get material descriptor set layout getMaterialDescriptorSetLayout (device: Device, phaseID: number, programName: string): DescriptorSetLayout { if (this.mergeHighFrequency) { assert(phaseID !== INVALID_ID); @@ -671,6 +789,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr return getOrCreateProgramDescriptorSetLayout(device, this.layoutGraph, phaseID, programName, UpdateFrequency.PER_BATCH); } + // get local descriptor set layout getLocalDescriptorSetLayout (device: Device, phaseID: number, programName: string): DescriptorSetLayout { if (this.mergeHighFrequency) { assert(phaseID !== INVALID_ID); @@ -680,6 +799,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr return getOrCreateProgramDescriptorSetLayout(device, this.layoutGraph, phaseID, programName, UpdateFrequency.PER_INSTANCE); } + // get related uniform block sizes getBlockSizes (phaseID: number, programName: string): number[] { assert(phaseID !== INVALID_ID); const group = this.phases.get(phaseID); @@ -694,6 +814,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr } return info.blockSizes; } + // get property handle map getHandleMap (phaseID: number, programName: string): Record { assert(phaseID !== INVALID_ID); const group = this.phases.get(phaseID); @@ -708,6 +829,7 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr } return info.handleMap; } + // get shader pipeline layout getPipelineLayout (device: Device, phaseID: number, programName: string): PipelineLayout { if (this.mergeHighFrequency) { assert(phaseID !== INVALID_ID); @@ -752,4 +874,17 @@ export class WebProgramLibrary extends ProgramLibraryData implements ProgramLibr programData.pipelineLayout = device.createPipelineLayout(info); return programData.pipelineLayout; } + getProgramID (phaseID: number, programName: string): number { + return getProgramID(this.layoutGraph, phaseID, programName); + } + getDescriptorNameID (name: string): number { + return getDescriptorNameID(this.layoutGraph, name); + } + getDescriptorName (nameID: number): string { + return getDescriptorName(this.layoutGraph, nameID); + } + layoutGraph: LayoutGraphData; + readonly phases: Map = new Map(); + mergeHighFrequency = false; + fixedLocal = true; } diff --git a/cocos/rendering/custom/web-types.ts b/cocos/rendering/custom/web-types.ts index 3be03dcad5..8a824dc55a 100644 --- a/cocos/rendering/custom/web-types.ts +++ b/cocos/rendering/custom/web-types.ts @@ -30,7 +30,6 @@ */ /* eslint-disable max-len */ import { Attribute, Shader, ShaderInfo } from '../../gfx'; -import { LayoutGraphData } from './layout-graph'; import { IProgramInfo } from '../../render-scene/core/program-lib'; export class ProgramInfo { @@ -58,19 +57,10 @@ export class ProgramHost { constructor (program: Shader) { this.program = program; } - readonly program: Shader; + /*refcount*/ program: Shader; } export class ProgramGroup { readonly programInfos: Map = new Map(); readonly programHosts: Map = new Map(); } - -export class ProgramLibraryData { - constructor (layoutGraph: LayoutGraphData) { - this.layoutGraph = layoutGraph; - } - /*pointer*/ layoutGraph: LayoutGraphData; - readonly phases: Map = new Map(); - mergeHighFrequency = false; -} diff --git a/cocos/rendering/define.ts b/cocos/rendering/define.ts index 507c75d089..b3cd6ae050 100644 --- a/cocos/rendering/define.ts +++ b/cocos/rendering/define.ts @@ -755,4 +755,8 @@ export function supportsR32FloatTexture (device: Device) { && !(device.gfxAPI === API.WEBGL); // wegl 1 Single-channel float type is not supported under webgl1, so it is excluded } +export function isEnableEffect (): boolean { + return !!(cclegacy.rendering && cclegacy.rendering.enableEffectImport); +} + /* eslint-enable max-len */ diff --git a/cocos/rendering/global-descriptor-set-manager.ts b/cocos/rendering/global-descriptor-set-manager.ts index 8cd034d5ab..565d6e4ab9 100644 --- a/cocos/rendering/global-descriptor-set-manager.ts +++ b/cocos/rendering/global-descriptor-set-manager.ts @@ -23,10 +23,12 @@ THE SOFTWARE. */ +import { cclegacy } from '../core'; import { Device, BufferUsageBit, MemoryUsageBit, BufferInfo, Filter, Address, Sampler, DescriptorSet, DescriptorSetInfo, Buffer, Texture, DescriptorSetLayoutInfo, DescriptorSetLayout, SamplerInfo } from '../gfx'; import { Light } from '../render-scene/scene'; -import { UBOShadow, globalDescriptorSetLayout, PipelineGlobalBindings } from './define'; +import { getDescBindingFromName } from './custom/define'; +import { UBOShadow, globalDescriptorSetLayout, PipelineGlobalBindings, isEnableEffect } from './define'; const _samplerLinearInfo = new SamplerInfo( Filter.LINEAR, @@ -194,7 +196,8 @@ export class GlobalDSManager { UBOShadow.SIZE, UBOShadow.SIZE, )); - descriptorSet.bindBuffer(UBOShadow.BINDING, shadowUBO); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + descriptorSet.bindBuffer(binding, shadowUBO); descriptorSet.update(); } diff --git a/cocos/rendering/pipeline-ubo.ts b/cocos/rendering/pipeline-ubo.ts index 6583165394..367b20d2e7 100644 --- a/cocos/rendering/pipeline-ubo.ts +++ b/cocos/rendering/pipeline-ubo.ts @@ -24,7 +24,7 @@ */ import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING, - supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, UBOCSM } from './define'; + supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, UBOCSM, isEnableEffect } from './define'; import { Device, BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet } from '../gfx'; import { Camera } from '../render-scene/scene/camera'; import { Mat4, Vec3, Vec4, Color, toRadian, cclegacy } from '../core'; @@ -36,6 +36,8 @@ import { RenderWindow } from '../render-scene/core/render-window'; import { builtinResMgr } from '../asset/asset-manager/builtin-res-mgr'; import { Texture2D } from '../asset/assets'; import { DebugViewCompositeType } from './debug-view'; +import { legacyCC } from '../core/global-exports'; +import { getDescBindingFromName } from './custom/define'; const _matShadowView = new Mat4(); const _matShadowProj = new Mat4(); @@ -433,6 +435,9 @@ export class PipelineUBO { this._device = device; this._pipeline = pipeline; const ds = this._pipeline.descriptorSet; + if (isEnableEffect()) { + return; + } this._initCombineSignY(); const globalUBO = device.createBuffer(new BufferInfo( @@ -456,14 +461,16 @@ export class PipelineUBO { UBOShadow.SIZE, UBOShadow.SIZE, )); - ds.bindBuffer(UBOShadow.BINDING, shadowUBO); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + ds.bindBuffer(binding, shadowUBO); const csmUBO = device.createBuffer(new BufferInfo( BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST, MemoryUsageBit.HOST | MemoryUsageBit.DEVICE, UBOCSM.SIZE, UBOCSM.SIZE, )); - ds.bindBuffer(UBOCSM.BINDING, csmUBO); + const csmBinding = isEnableEffect() ? getDescBindingFromName('CCCSM') : UBOCSM.BINDING; + ds.bindBuffer(csmBinding, csmUBO); } /** @@ -507,8 +514,10 @@ export class PipelineUBO { } PipelineUBO.updateShadowUBOView(this._pipeline, this._shadowUBO, this._csmUBO, camera); ds.update(); - cmdBuffer[0].updateBuffer(ds.getBuffer(UBOShadow.BINDING), this._shadowUBO); - cmdBuffer[0].updateBuffer(ds.getBuffer(UBOCSM.BINDING), this._csmUBO); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + cmdBuffer[0].updateBuffer(ds.getBuffer(binding), this._shadowUBO); + const csmBinding = isEnableEffect() ? getDescBindingFromName('CCCSM') : UBOCSM.BINDING; + cmdBuffer[0].updateBuffer(ds.getBuffer(csmBinding), this._csmUBO); } public updateShadowUBOLight (globalDS: DescriptorSet, light: Light, level = 0) { @@ -516,7 +525,8 @@ export class PipelineUBO { globalDS.bindTexture(UNIFORM_SHADOWMAP_BINDING, builtinResMgr.get('default-texture').getGFXTexture()!); globalDS.bindTexture(UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, builtinResMgr.get('default-texture').getGFXTexture()!); globalDS.update(); - this._pipeline.commandBuffers[0].updateBuffer(globalDS.getBuffer(UBOShadow.BINDING), this._shadowUBO); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + this._pipeline.commandBuffers[0].updateBuffer(globalDS.getBuffer(binding), this._shadowUBO); } public updateShadowUBORange (offset: number, data: Mat4 | Color) { diff --git a/cocos/rendering/render-additive-light-queue.ts b/cocos/rendering/render-additive-light-queue.ts index b84dfec9a8..0031d86283 100644 --- a/cocos/rendering/render-additive-light-queue.ts +++ b/cocos/rendering/render-additive-light-queue.ts @@ -26,7 +26,7 @@ import { BatchingSchemes, Pass } from '../render-scene/core/pass'; import { Model } from '../render-scene/scene/model'; import { PipelineStateManager } from './pipeline-state-manager'; -import { Vec3, nextPow2, Mat4, Color, Pool, geometry } from '../core'; +import { Vec3, nextPow2, Mat4, Color, Pool, geometry, cclegacy } from '../core'; import { Device, RenderPass, Buffer, BufferUsageBit, MemoryUsageBit, BufferInfo, BufferViewInfo, CommandBuffer } from '../gfx'; import { RenderBatchedQueue } from './render-batched-queue'; @@ -37,11 +37,12 @@ import { SubModel } from '../render-scene/scene/submodel'; import { getPhaseID } from './pass-phase'; import { Light, LightType } from '../render-scene/scene/light'; import { SetIndex, UBOForwardLight, UBOShadow, UNIFORM_SHADOWMAP_BINDING, - UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, supportsR32FloatTexture } from './define'; + UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, supportsR32FloatTexture, isEnableEffect } from './define'; import { Camera, ShadowType } from '../render-scene/scene'; import { GlobalDSManager } from './global-descriptor-set-manager'; import { PipelineUBO } from './pipeline-ubo'; import { PipelineRuntime } from './custom/pipeline'; +import { getDescBindingFromName } from './custom/define'; interface IAdditiveLightPass { subModel: SubModel; @@ -67,16 +68,22 @@ function cullSpotLight (light: SpotLight, model: Model) { && (!geometry.intersect.aabbWithAABB(model.worldBounds, light.aabb) || !geometry.intersect.aabbFrustum(model.worldBounds, light.frustum))); } -const _phaseID = getPhaseID('forward-add'); +const phaseName = 'forward-add'; +let _phaseID = getPhaseID(phaseName); const _lightPassIndices: number[] = []; function getLightPassIndices (subModels: SubModel[], lightPassIndices: number[]) { + const r = cclegacy.rendering; + if (isEnableEffect()) { + _phaseID = r.getPhaseID(r.getPassID('default'), phaseName); + } lightPassIndices.length = 0; let hasValidLightPass = false; for (let j = 0; j < subModels.length; j++) { const { passes } = subModels[j]; let lightPassIndex = -1; for (let k = 0; k < passes.length; k++) { - if (passes[k].phase === _phaseID) { + if (((!r || !r.enableEffectImport) && passes[k].phase === _phaseID) + || (isEnableEffect() && passes[k].phaseID === _phaseID)) { lightPassIndex = k; hasValidLightPass = true; break; @@ -155,7 +162,8 @@ export class RenderAdditiveLightQueue { const key = keys[i]; const descriptorSet = descriptorSetMap.get(key)!; if (descriptorSet) { - descriptorSet.getBuffer(UBOShadow.BINDING).destroy(); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + descriptorSet.getBuffer(binding).destroy(); descriptorSet.getTexture(UNIFORM_SHADOWMAP_BINDING).destroy(); descriptorSet.getTexture(UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING).destroy(); descriptorSet.destroy(); @@ -195,6 +203,7 @@ export class RenderAdditiveLightQueue { if (isTransparent) { continue; } + const binding = isEnableEffect() ? getDescBindingFromName('CCForwardLight') : UBOForwardLight.BINDING; subModel.descriptorSet.bindBuffer(UBOForwardLight.BINDING, this._firstLightBufferView); subModel.descriptorSet.update(); @@ -255,7 +264,7 @@ export class RenderAdditiveLightQueue { } // light culling - protected _lightCulling (model:Model, validPunctualLights: Light[]) { + protected _lightCulling (model: Model, validPunctualLights: Light[]) { let isCulled = false; for (let l = 0; l < validPunctualLights.length; l++) { const light = validPunctualLights[l]; @@ -332,8 +341,8 @@ export class RenderAdditiveLightQueue { const light = validPunctualLights[i]; const descriptorSet = globalDSManager.getOrCreateDescriptorSet(light); if (!descriptorSet) { continue; } - let matShadowProj : Mat4; - let matShadowInvProj : Mat4; + let matShadowProj: Mat4; + let matShadowInvProj: Mat4; switch (light.type) { case LightType.SPHERE: { // planar PROJ @@ -422,8 +431,8 @@ export class RenderAdditiveLightQueue { default: } descriptorSet.update(); - - cmdBuff.updateBuffer(descriptorSet.getBuffer(UBOShadow.BINDING)!, this._shadowUBO); + const binding = isEnableEffect() ? getDescBindingFromName('CCShadow') : UBOShadow.BINDING; + cmdBuff.updateBuffer(descriptorSet.getBuffer(binding)!, this._shadowUBO); } } diff --git a/cocos/rendering/render-reflection-probe-queue.ts b/cocos/rendering/render-reflection-probe-queue.ts index 129beac93b..a5c6fe706c 100644 --- a/cocos/rendering/render-reflection-probe-queue.ts +++ b/cocos/rendering/render-reflection-probe-queue.ts @@ -24,7 +24,7 @@ */ import { SubModel } from '../render-scene/scene/submodel'; -import { SetIndex } from './define'; +import { isEnableEffect, SetIndex } from './define'; import { Device, RenderPass, Shader, CommandBuffer } from '../gfx'; import { getPhaseID } from './pass-phase'; import { PipelineStateManager } from './pipeline-state-manager'; @@ -35,7 +35,7 @@ import { PipelineRuntime } from './custom/pipeline'; import { IMacroPatch, RenderScene } from '../render-scene'; import { RenderInstancedQueue } from './render-instanced-queue'; import { RenderBatchedQueue } from './render-batched-queue'; -import { geometry } from '../core'; +import { cclegacy, geometry } from '../core'; import { Layers } from '../scene-graph/layers'; // eslint-disable-next-line max-len @@ -43,12 +43,14 @@ const REFLECTION_PROBE_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_ Layers.BitMask.SCENE_GIZMO, Layers.BitMask.PROFILER]); const CC_USE_RGBE_OUTPUT = 'CC_USE_RGBE_OUTPUT'; -const _phaseID = getPhaseID('default'); -const _phaseReflectMapID = getPhaseID('reflect-map'); +let _phaseID = getPhaseID('default'); +let _phaseReflectMapID = getPhaseID('reflect-map'); function getPassIndex (subModel: SubModel): number { const passes = subModel.passes; + const r = cclegacy.rendering; + if (isEnableEffect()) _phaseID = r.getPhaseID(r.getPassID('default'), 'default'); for (let k = 0; k < passes.length; k++) { - if (passes[k].phase === _phaseID) { + if (((!r || !r.enableEffectImport) && passes[k].phase === _phaseID) || (isEnableEffect() && passes[k].phaseID === _phaseID)) { return k; } } @@ -57,8 +59,11 @@ function getPassIndex (subModel: SubModel): number { function getReflectMapPassIndex (subModel: SubModel): number { const passes = subModel.passes; + const r = cclegacy.rendering; + if (isEnableEffect()) _phaseReflectMapID = r.getPhaseID(r.getPassID('default'), 'reflect-map'); for (let k = 0; k < passes.length; k++) { - if (passes[k].phase === _phaseReflectMapID) { + if (((!r || !r.enableEffectImport) && passes[k].phase === _phaseReflectMapID) + || (isEnableEffect() && passes[k].phaseID === _phaseReflectMapID)) { return k; } } @@ -74,7 +79,7 @@ export class RenderReflectionProbeQueue { private _subModelsArray: SubModel[] = []; private _passArray: Pass[] = []; private _shaderArray: Shader[] = []; - private _rgbeSubModelsArray:SubModel[]=[] + private _rgbeSubModelsArray: SubModel[]=[] private _instancedQueue: RenderInstancedQueue; private _batchedQueue: RenderBatchedQueue; @@ -83,7 +88,7 @@ export class RenderReflectionProbeQueue { this._instancedQueue = new RenderInstancedQueue(); this._batchedQueue = new RenderBatchedQueue(); } - public gatherRenderObjects (probe: ReflectionProbe, scene:RenderScene, cmdBuff: CommandBuffer) { + public gatherRenderObjects (probe: ReflectionProbe, scene: RenderScene, cmdBuff: CommandBuffer) { this.clear(); const sceneData = this._pipeline.pipelineSceneData; const skybox = sceneData.skybox; diff --git a/cocos/rendering/render-shadow-map-batched-queue.ts b/cocos/rendering/render-shadow-map-batched-queue.ts index d245f468be..cf3ff6d7e9 100644 --- a/cocos/rendering/render-shadow-map-batched-queue.ts +++ b/cocos/rendering/render-shadow-map-batched-queue.ts @@ -24,7 +24,7 @@ */ import { SubModel } from '../render-scene/scene/submodel'; -import { SetIndex } from './define'; +import { isEnableEffect, SetIndex } from './define'; import { Device, RenderPass, Shader, CommandBuffer } from '../gfx'; import { getPhaseID } from './pass-phase'; import { PipelineStateManager } from './pipeline-state-manager'; @@ -33,17 +33,20 @@ import { RenderInstancedQueue } from './render-instanced-queue'; import { RenderBatchedQueue } from './render-batched-queue'; import { ShadowType } from '../render-scene/scene/shadows'; import { Light, LightType } from '../render-scene/scene/light'; -import { geometry } from '../core'; +import { cclegacy, geometry } from '../core'; import { Model } from '../render-scene/scene/model'; import { Camera, DirectionalLight, SpotLight } from '../render-scene/scene'; import { shadowCulling } from './scene-culling'; import { PipelineRuntime } from './custom/pipeline'; -const _phaseID = getPhaseID('shadow-caster'); -function getShadowPassIndex (subModel: SubModel) : number { +let _phaseID = getPhaseID('shadow-caster'); +function getShadowPassIndex (subModel: SubModel): number { const passes = subModel.passes; + const r = cclegacy.rendering; + if (isEnableEffect()) _phaseID = r.getPhaseID(r.getPassID('default'), 'shadow-caster'); for (let k = 0; k < passes.length; k++) { - if (passes[k].phase === _phaseID) { + if (((!r || !r.enableEffectImport) && passes[k].phase === _phaseID) + || (isEnableEffect() && passes[k].phaseID === _phaseID)) { return k; } } diff --git a/cocos/rendering/ui-phase.ts b/cocos/rendering/ui-phase.ts index 83a7d172f6..38fd0b4e39 100644 --- a/cocos/rendering/ui-phase.ts +++ b/cocos/rendering/ui-phase.ts @@ -25,14 +25,19 @@ import { RenderPass } from '../gfx'; import { PipelineStateManager } from './pipeline-state-manager'; -import { SetIndex } from './define'; +import { isEnableEffect, SetIndex } from './define'; import { Camera } from '../render-scene/scene/camera'; import { RenderPipeline } from './render-pipeline'; import { getPhaseID } from './pass-phase'; +import { cclegacy } from '../core'; export class UIPhase { private _phaseID = getPhaseID('default'); private declare _pipeline: RenderPipeline; + constructor () { + const r = cclegacy.rendering; + if (isEnableEffect()) this._phaseID = r.getPhaseID(r.getPassID('default'), 'default'); + } public activate (pipeline: RenderPipeline) { this._pipeline = pipeline; diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index f2ae2084d8..201188e535 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1088,6 +1088,8 @@ cocos_source_files( cocos/renderer/core/PassUtils.cpp cocos/renderer/core/ProgramLib.h cocos/renderer/core/ProgramLib.cpp + cocos/renderer/core/ProgramUtils.h + cocos/renderer/core/ProgramUtils.cpp cocos/renderer/core/MaterialInstance.h cocos/renderer/core/MaterialInstance.cpp cocos/renderer/core/PassInstance.h @@ -1312,7 +1314,7 @@ cocos_source_files( cocos/renderer/pipeline/helper/Utils.cpp cocos/renderer/pipeline/custom/BinaryArchive.h cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp - cocos/renderer/pipeline/custom/SerializationUtils.h + cocos/renderer/pipeline/custom/details/SerializationUtils.h cocos/renderer/pipeline/custom/test/test.h cocos/renderer/pipeline/custom/NativeDefaultScene.cpp cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -1330,23 +1332,27 @@ cocos_source_files( cocos/renderer/pipeline/custom/FGDispatcherTypes.h cocos/renderer/pipeline/custom/LayoutGraphFwd.h cocos/renderer/pipeline/custom/LayoutGraphGraphs.h - cocos/renderer/pipeline/custom/LayoutGraphJsb.cpp - cocos/renderer/pipeline/custom/LayoutGraphJsb.h cocos/renderer/pipeline/custom/LayoutGraphNames.h - cocos/renderer/pipeline/custom/LayoutGraphReflection.cpp - cocos/renderer/pipeline/custom/LayoutGraphReflection.h cocos/renderer/pipeline/custom/LayoutGraphSerialization.h cocos/renderer/pipeline/custom/LayoutGraphTypes.cpp cocos/renderer/pipeline/custom/LayoutGraphTypes.h + cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp + cocos/renderer/pipeline/custom/LayoutGraphUtils.h cocos/renderer/pipeline/custom/NativeExecutor.cpp - cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp + cocos/renderer/pipeline/custom/NativeFactory.cpp + cocos/renderer/pipeline/custom/NativeFwd.h + cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp + cocos/renderer/pipeline/custom/NativePipeline.cpp cocos/renderer/pipeline/custom/NativePipelineFwd.h cocos/renderer/pipeline/custom/NativePipelineGraphs.h - cocos/renderer/pipeline/custom/NativePipelineImpl.cpp cocos/renderer/pipeline/custom/NativePipelineTypes.cpp cocos/renderer/pipeline/custom/NativePipelineTypes.h + cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp cocos/renderer/pipeline/custom/NativeRenderGraph.cpp cocos/renderer/pipeline/custom/NativeRenderQueue.cpp + cocos/renderer/pipeline/custom/NativeRenderingModule.cpp + cocos/renderer/pipeline/custom/NativeTypes.cpp + cocos/renderer/pipeline/custom/NativeTypes.h cocos/renderer/pipeline/custom/PrivateFwd.h cocos/renderer/pipeline/custom/PrivateTypes.cpp cocos/renderer/pipeline/custom/PrivateTypes.h @@ -1354,22 +1360,14 @@ cocos_source_files( cocos/renderer/pipeline/custom/RenderCommonJsb.cpp cocos/renderer/pipeline/custom/RenderCommonJsb.h cocos/renderer/pipeline/custom/RenderCommonNames.h - cocos/renderer/pipeline/custom/RenderCommonReflection.cpp - cocos/renderer/pipeline/custom/RenderCommonReflection.h cocos/renderer/pipeline/custom/RenderCommonSerialization.h cocos/renderer/pipeline/custom/RenderCommonTypes.cpp cocos/renderer/pipeline/custom/RenderCommonTypes.h cocos/renderer/pipeline/custom/RenderGraphFwd.h cocos/renderer/pipeline/custom/RenderGraphGraphs.h - cocos/renderer/pipeline/custom/RenderGraphJsb.cpp - cocos/renderer/pipeline/custom/RenderGraphJsb.h - cocos/renderer/pipeline/custom/RenderGraphNames.h - cocos/renderer/pipeline/custom/RenderGraphReflection.cpp - cocos/renderer/pipeline/custom/RenderGraphReflection.h cocos/renderer/pipeline/custom/RenderGraphTypes.cpp cocos/renderer/pipeline/custom/RenderGraphTypes.h cocos/renderer/pipeline/custom/RenderInterfaceFwd.h - cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp cocos/renderer/pipeline/custom/RenderInterfaceTypes.cpp cocos/renderer/pipeline/custom/RenderInterfaceTypes.h ) diff --git a/native/cocos/bindings/auto/jsb_assets_auto.cpp b/native/cocos/bindings/auto/jsb_assets_auto.cpp index 32008a9f2d..552e3f6047 100644 --- a/native/cocos/bindings/auto/jsb_assets_auto.cpp +++ b/native/cocos/bindings/auto/jsb_assets_auto.cpp @@ -11512,6 +11512,43 @@ static bool js_cc_IPassInfoFull_phase_get(se::State& s) } SE_BIND_PROP_GET(js_cc_IPassInfoFull_phase_get) +static bool js_cc_IPassInfoFull_pass_set(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::IPassInfoFull *arg1 = (cc::IPassInfoFull *) NULL ; + + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= sevalue_to_native(args[0], &arg1->pass, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + + + + return true; +} +SE_BIND_PROP_SET(js_cc_IPassInfoFull_pass_set) + +static bool js_cc_IPassInfoFull_pass_get(se::State& s) +{ + CC_UNUSED bool ok = true; + cc::IPassInfoFull *arg1 = (cc::IPassInfoFull *) NULL ; + + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= nativevalue_to_se(arg1->pass, s.rval(), s.thisObject() /*ctx*/); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + SE_HOLD_RETURN_VALUE(arg1->pass, s.thisObject(), s.rval()); + + + + return true; +} +SE_BIND_PROP_GET(js_cc_IPassInfoFull_pass_get) + static bool js_cc_IPassInfoFull_program_set(se::State& s) { CC_UNUSED bool ok = true; @@ -11930,6 +11967,12 @@ bool sevalue_to_native(const se::Value &from, cc::IPassInfoFull * to, se::Object } + json->getProperty("pass", &field, true); + if (!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->pass), ctx); + } + + json->getProperty("program", &field, true); if (!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->program), ctx); @@ -11994,6 +12037,7 @@ bool js_register_cc_IPassInfoFull(se::Object* obj) { cls->defineProperty("blendState", _SE(js_cc_IPassInfoFull_blendState_get), _SE(js_cc_IPassInfoFull_blendState_set)); cls->defineProperty("dynamicStates", _SE(js_cc_IPassInfoFull_dynamicStates_get), _SE(js_cc_IPassInfoFull_dynamicStates_set)); cls->defineProperty("phase", _SE(js_cc_IPassInfoFull_phase_get), _SE(js_cc_IPassInfoFull_phase_set)); + cls->defineProperty("pass", _SE(js_cc_IPassInfoFull_pass_get), _SE(js_cc_IPassInfoFull_pass_set)); cls->defineProperty("program", _SE(js_cc_IPassInfoFull_program_get), _SE(js_cc_IPassInfoFull_program_set)); cls->defineProperty("embeddedMacros", _SE(js_cc_IPassInfoFull_embeddedMacros_get), _SE(js_cc_IPassInfoFull_embeddedMacros_set)); cls->defineProperty("propertyIndex", _SE(js_cc_IPassInfoFull_propertyIndex_get), _SE(js_cc_IPassInfoFull_propertyIndex_set)); @@ -16660,6 +16704,43 @@ static bool js_cc_IShaderInfo_subpassInputs_get(se::State& s) } SE_BIND_PROP_GET(js_cc_IShaderInfo_subpassInputs_get) +static bool js_cc_IShaderInfo_descriptors_set(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::IShaderInfo *arg1 = (cc::IShaderInfo *) NULL ; + + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= sevalue_to_native(args[0], &arg1->descriptors, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + + + + return true; +} +SE_BIND_PROP_SET(js_cc_IShaderInfo_descriptors_set) + +static bool js_cc_IShaderInfo_descriptors_get(se::State& s) +{ + CC_UNUSED bool ok = true; + cc::IShaderInfo *arg1 = (cc::IShaderInfo *) NULL ; + + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= nativevalue_to_se(arg1->descriptors, s.rval(), s.thisObject() /*ctx*/); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + SE_HOLD_RETURN_VALUE(arg1->descriptors, s.thisObject(), s.rval()); + + + + return true; +} +SE_BIND_PROP_GET(js_cc_IShaderInfo_descriptors_get) + static bool js_cc_IShaderInfo_getSource(se::State& s) { CC_UNUSED bool ok = true; @@ -16817,6 +16898,12 @@ bool sevalue_to_native(const se::Value &from, cc::IShaderInfo * to, se::Object * } + json->getProperty("descriptors", &field, true); + if (!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->descriptors), ctx); + } + + return ok; } @@ -16840,6 +16927,7 @@ bool js_register_cc_IShaderInfo(se::Object* obj) { cls->defineProperty("buffers", _SE(js_cc_IShaderInfo_buffers_get), _SE(js_cc_IShaderInfo_buffers_set)); cls->defineProperty("images", _SE(js_cc_IShaderInfo_images_get), _SE(js_cc_IShaderInfo_images_set)); cls->defineProperty("subpassInputs", _SE(js_cc_IShaderInfo_subpassInputs_get), _SE(js_cc_IShaderInfo_subpassInputs_set)); + cls->defineProperty("descriptors", _SE(js_cc_IShaderInfo_descriptors_get), _SE(js_cc_IShaderInfo_descriptors_set)); cls->defineFunction("getSource", _SE(js_cc_IShaderInfo_getSource)); diff --git a/native/cocos/bindings/auto/jsb_render_auto.cpp b/native/cocos/bindings/auto/jsb_render_auto.cpp index 70477cb2f0..b793cf413f 100644 --- a/native/cocos/bindings/auto/jsb_render_auto.cpp +++ b/native/cocos/bindings/auto/jsb_render_auto.cpp @@ -3782,10 +3782,163 @@ bool js_register_cc_render_PipelineBuilder(se::Object* obj) { } +se::Class* __jsb_cc_render_RenderingModule_class = nullptr; +se::Object* __jsb_cc_render_RenderingModule_proto = nullptr; +SE_DECLARE_FINALIZE_FUNC(js_delete_cc_render_RenderingModule) + +static bool js_delete_cc_render_RenderingModule(se::State& s) +{ + return true; +} +SE_BIND_FINALIZE_FUNC(js_delete_cc_render_RenderingModule) + +static bool js_cc_render_RenderingModule_getPassID(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::render::RenderingModule *arg1 = (cc::render::RenderingModule *) NULL ; + ccstd::string *arg2 = 0 ; + ccstd::string temp2 ; + uint32_t result; + + if(argc != 1) { + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; + } + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= sevalue_to_native(args[0], &temp2, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + arg2 = &temp2; + + result = ((cc::render::RenderingModule const *)arg1)->getPassID((ccstd::string const &)*arg2); + + ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); + + + return true; +} +SE_BIND_FUNC(js_cc_render_RenderingModule_getPassID) + +static bool js_cc_render_RenderingModule_getPhaseID(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::render::RenderingModule *arg1 = (cc::render::RenderingModule *) NULL ; + uint32_t arg2 ; + ccstd::string *arg3 = 0 ; + ccstd::string temp3 ; + uint32_t result; + + if(argc != 2) { + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + return false; + } + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + + ok &= sevalue_to_native(args[0], &arg2, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + + + ok &= sevalue_to_native(args[1], &temp3, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + arg3 = &temp3; + + result = ((cc::render::RenderingModule const *)arg1)->getPhaseID(arg2,(ccstd::string const &)*arg3); + + ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); + + + return true; +} +SE_BIND_FUNC(js_cc_render_RenderingModule_getPhaseID) + +bool js_register_cc_render_RenderingModule(se::Object* obj) { + auto* cls = se::Class::create("RenderingModule", obj, nullptr, nullptr); + + cls->defineStaticProperty("__isJSB", se::Value(true), se::PropertyAttribute::READ_ONLY | se::PropertyAttribute::DONT_ENUM | se::PropertyAttribute::DONT_DELETE); + + cls->defineFunction("getPassID", _SE(js_cc_render_RenderingModule_getPassID)); + cls->defineFunction("getPhaseID", _SE(js_cc_render_RenderingModule_getPhaseID)); + + + + + cls->defineFinalizeFunction(_SE(js_delete_cc_render_RenderingModule)); + + + cls->install(); + JSBClassType::registerClass(cls); + + __jsb_cc_render_RenderingModule_proto = cls->getProto(); + __jsb_cc_render_RenderingModule_class = cls; + se::ScriptEngine::getInstance()->clearException(); + return true; +} + + se::Class* __jsb_cc_render_Factory_class = nullptr; se::Object* __jsb_cc_render_Factory_proto = nullptr; SE_DECLARE_FINALIZE_FUNC(js_delete_cc_render_Factory) +static bool js_cc_render_Factory_init_static(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + gfx::Device *arg1 = (gfx::Device *) NULL ; + ccstd::vector< unsigned char > *arg2 = 0 ; + ccstd::vector< unsigned char > temp2 ; + cc::render::RenderingModule *result = 0 ; + + if(argc != 2) { + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2); + return false; + } + + ok &= sevalue_to_native(args[0], &arg1, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + + ok &= sevalue_to_native(args[1], &temp2, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + arg2 = &temp2; + + result = (cc::render::RenderingModule *)cc::render::Factory::init(arg1,(ccstd::vector< unsigned char > const &)*arg2); + + ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + + + return true; +} +SE_BIND_FUNC(js_cc_render_Factory_init_static) + +static bool js_cc_render_Factory_destroy_static(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::render::RenderingModule *arg1 = (cc::render::RenderingModule *) NULL ; + + if(argc != 1) { + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; + } + + ok &= sevalue_to_native(args[0], &arg1, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + cc::render::Factory::destroy(arg1); + + + return true; +} +SE_BIND_FUNC(js_cc_render_Factory_destroy_static) + static bool js_cc_render_Factory_createPipeline_static(se::State& s) { CC_UNUSED bool ok = true; @@ -3837,6 +3990,8 @@ bool js_register_cc_render_Factory(se::Object* obj) { + cls->defineStaticFunction("init", _SE(js_cc_render_Factory_init_static)); + cls->defineStaticFunction("destroy", _SE(js_cc_render_Factory_destroy_static)); cls->defineStaticFunction("createPipeline", _SE(js_cc_render_Factory_createPipeline_static)); @@ -3881,6 +4036,7 @@ bool register_all_render(se::Object* obj) { js_register_cc_render_LayoutGraphBuilder(ns); js_register_cc_render_Pipeline(ns); js_register_cc_render_PipelineBuilder(ns); + js_register_cc_render_RenderingModule(ns); js_register_cc_render_Factory(ns); /* Register global variables & global functions */ diff --git a/native/cocos/bindings/auto/jsb_render_auto.h b/native/cocos/bindings/auto/jsb_render_auto.h index 4354fd19d2..aad4ad1805 100644 --- a/native/cocos/bindings/auto/jsb_render_auto.h +++ b/native/cocos/bindings/auto/jsb_render_auto.h @@ -119,6 +119,11 @@ extern se::Object *__jsb_cc_render_PipelineBuilder_proto; // NOLINT extern se::Class * __jsb_cc_render_PipelineBuilder_class; // NOLINT +JSB_REGISTER_OBJECT_TYPE(cc::render::RenderingModule); +extern se::Object *__jsb_cc_render_RenderingModule_proto; // NOLINT +extern se::Class * __jsb_cc_render_RenderingModule_class; // NOLINT + + JSB_REGISTER_OBJECT_TYPE(cc::render::Factory); extern se::Object *__jsb_cc_render_Factory_proto; // NOLINT extern se::Class * __jsb_cc_render_Factory_class; // NOLINT diff --git a/native/cocos/bindings/auto/jsb_scene_auto.cpp b/native/cocos/bindings/auto/jsb_scene_auto.cpp index eaf73adc87..1fd859aae0 100644 --- a/native/cocos/bindings/auto/jsb_scene_auto.cpp +++ b/native/cocos/bindings/auto/jsb_scene_auto.cpp @@ -7286,7 +7286,7 @@ static bool js_cc_scene_LODGroup_isLockLevelChanged(se::State& s) } arg1 = SE_THIS_OBJECT(s); if (nullptr == arg1) return true; - result = (bool)(arg1)->isLockLevelChanged(); + result = (bool)((cc::scene::LODGroup const *)arg1)->isLockLevelChanged(); ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); diff --git a/native/cocos/core/assets/EffectAsset.h b/native/cocos/core/assets/EffectAsset.h index b79342d946..48070f6bff 100644 --- a/native/cocos/core/assets/EffectAsset.h +++ b/native/cocos/core/assets/EffectAsset.h @@ -365,6 +365,7 @@ struct IPassInfoFull final { // cjh } : public IPassInfo { ccstd::optional blendState; ccstd::optional dynamicStates; ccstd::optional phase; + ccstd::optional pass; // IPassInfo ccstd::string program; // auto-generated from 'vert' and 'frag' ccstd::optional embeddedMacros; @@ -535,7 +536,7 @@ struct IShaderInfo { ccstd::vector buffers; ccstd::vector images; ccstd::vector subpassInputs; - // ccstd::vector descriptors; + ccstd::vector descriptors; const IShaderSource *getSource(const ccstd::string &version) const { if (version == "glsl1") return &glsl1; diff --git a/native/cocos/renderer/core/ProgramLib.cpp b/native/cocos/renderer/core/ProgramLib.cpp index fcd4da5cad..a6896b181d 100644 --- a/native/cocos/renderer/core/ProgramLib.cpp +++ b/native/cocos/renderer/core/ProgramLib.cpp @@ -28,6 +28,7 @@ #include #include #include +#include "ProgramUtils.h" #include "base/Log.h" #include "core/assets/EffectAsset.h" #include "renderer/gfx-base/GFXDevice.h" @@ -37,10 +38,6 @@ namespace cc { namespace { -int32_t getBitCount(int32_t cnt) { - return std::ceil(std::log2(std::max(cnt, 2))); // std::max checks number types -} - ccstd::string mapDefine(const IDefineInfo &info, const ccstd::optional &def) { if (info.type == "boolean") { return def.has_value() ? (macroRecordAsBool(def.value()) ? "1" : "0") : "0"; @@ -148,29 +145,6 @@ int32_t getSize(const IBlockInfo &block) { return s; } -auto genHandles(const IProgramInfo &tmpl) { - Record handleMap{}; - // block member handles - for (const auto &block : tmpl.blocks) { - const auto members = block.members; - uint32_t offset = 0; - for (const auto &uniform : members) { - handleMap[uniform.name] = genHandle(block.binding, - uniform.type, - uniform.count, - offset); - offset += (getTypeSize(uniform.type) >> 2) * uniform.count; // assumes no implicit padding, which is guaranteed by effect compiler - } - } - // samplerTexture handles - for (const auto &samplerTexture : tmpl.samplerTextures) { - handleMap[samplerTexture.name] = genHandle(samplerTexture.binding, - samplerTexture.type, - samplerTexture.count); - } - return handleMap; -} - bool dependencyCheck(const ccstd::vector &dependencies, const MacroRecord &defines) { for (const auto &d : dependencies) { // NOLINT(readability-use-anyofallof) if (d[0] == '!') { // negative dependency @@ -292,65 +266,7 @@ IProgramInfo *ProgramLib::define(IShaderInfo &shader) { IProgramInfo &tmpl = _templates[shader.name]; tmpl.copyFrom(shader); - // calculate option mask offset - int32_t offset = 0; - for (auto &def : tmpl.defines) { - int32_t cnt = 1; - if (def.type == "number") { - auto &range = def.range.value(); - cnt = getBitCount(range[1] - range[0] + 1); // inclusive on both ends - def.map = [=](const MacroValue &value) -> int32_t { - if (ccstd::holds_alternative(value)) { - return ccstd::get(value) - range[0]; - } - if (ccstd::holds_alternative(value)) { - return (ccstd::get(value) ? 1 : 0) - range[0]; - } - CC_ABORT(); // We only support macro with int32_t type now. - return 0; - }; - } else if (def.type == "string") { - cnt = getBitCount(static_cast(def.options.value().size())); - def.map = [=](const MacroValue &value) -> int32_t { - const auto *pValue = ccstd::get_if(&value); - if (pValue != nullptr) { - auto idx = static_cast(std::find(def.options.value().begin(), def.options.value().end(), *pValue) - def.options.value().begin()); - return std::max(0, idx); - } - return 0; - }; - } else if (def.type == "boolean") { - def.map = [](const MacroValue &value) -> int32_t { - const auto *pBool = ccstd::get_if(&value); - if (pBool != nullptr) { - return *pBool ? 1 : 0; - } - const auto *pInt = ccstd::get_if(&value); - if (pInt != nullptr) { - return *pInt ? 1 : 0; - } - const auto *pString = ccstd::get_if(&value); - if (pString != nullptr) { - return *pString != "0" || !(*pString).empty() ? 1 : 0; - } - return 0; - }; - } - def.offset = offset; - offset += cnt; - } - if (offset > 31) { - tmpl.uber = true; - } - // generate constant macros - { - tmpl.constantMacros.clear(); - std::stringstream ss; - for (auto &key : tmpl.builtins.statistics) { - ss << "#define " << key.first << " " << key.second << std::endl; - } - tmpl.constantMacros = ss.str(); - } + render::populateMacros(tmpl); if (_templateInfos.count(tmpl.hash) == 0) { ITemplateInfo tmplInfo{}; @@ -500,7 +416,7 @@ IProgramInfo *ProgramLib::define(IShaderInfo &shader) { auto &fragmentShaderInfo = tmplInfo.shaderInfo.stages.back(); fragmentShaderInfo.stage = gfx::ShaderStageFlagBit::FRAGMENT; fragmentShaderInfo.source = ""; - tmplInfo.handleMap = genHandles(tmpl); + tmplInfo.handleMap = render::genHandles(tmpl); tmplInfo.setLayouts = {}; _templateInfos[tmpl.hash] = tmplInfo; @@ -563,37 +479,7 @@ ccstd::string ProgramLib::getKey(const ccstd::string &name, const MacroRecord &d auto itTpl = _templates.find(name); CC_ASSERT(itTpl != _templates.end()); auto &tmpl = itTpl->second; - auto &tmplDefs = tmpl.defines; - if (tmpl.uber) { - std::stringstream key; - for (auto &tmplDef : tmplDefs) { - auto itDef = defines.find(tmplDef.name); - if (itDef == defines.end() || !tmplDef.map) { - continue; - } - const auto &value = itDef->second; - auto mapped = tmplDef.map(value); - auto offset = tmplDef.offset; - key << offset << mapped << "|"; - } - ccstd::string ret{key.str() + std::to_string(tmpl.hash)}; - return ret; - } - uint32_t key = 0; - std::stringstream ss; - for (auto &tmplDef : tmplDefs) { - auto itDef = defines.find(tmplDef.name); - if (itDef == defines.end() || !tmplDef.map) { - continue; - } - const auto &value = itDef->second; - auto mapped = tmplDef.map(value); - auto offset = tmplDef.offset; - key |= (mapped << offset); - } - ss << std::hex << key << "|" << std::to_string(tmpl.hash); - ccstd::string ret{ss.str()}; - return ret; + return render::getVariantKey(tmpl, defines); } void ProgramLib::destroyShaderByDefines(const MacroRecord &defines) { diff --git a/native/cocos/renderer/core/ProgramUtils.cpp b/native/cocos/renderer/core/ProgramUtils.cpp new file mode 100644 index 0000000000..dafc093ffd --- /dev/null +++ b/native/cocos/renderer/core/ProgramUtils.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** + Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ +#include "ProgramUtils.h" + +namespace cc { + +namespace render { + +namespace { + +int32_t getBitCount(int32_t cnt) { + return std::ceil(std::log2(std::max(cnt, 2))); // std::max checks number types +} + +template +ccstd::unordered_map genHandlesImpl(const ShaderInfoT &tmpl) { + Record handleMap{}; + // block member handles + for (const auto &block : tmpl.blocks) { + const auto members = block.members; + uint32_t offset = 0; + for (const auto &uniform : members) { + handleMap[uniform.name] = genHandle(block.binding, + uniform.type, + uniform.count, + offset); + offset += (getTypeSize(uniform.type) >> 2) * uniform.count; // assumes no implicit padding, which is guaranteed by effect compiler + } + } + // samplerTexture handles + for (const auto &samplerTexture : tmpl.samplerTextures) { + handleMap[samplerTexture.name] = genHandle(samplerTexture.binding, + samplerTexture.type, + samplerTexture.count); + } + return handleMap; +} + +} // namespace + +void populateMacros(IProgramInfo &tmpl) { + // calculate option mask offset + int32_t offset = 0; + for (auto &def : tmpl.defines) { + int32_t cnt = 1; + if (def.type == "number") { + auto &range = def.range.value(); + cnt = getBitCount(range[1] - range[0] + 1); // inclusive on both ends + def.map = [=](const MacroValue &value) -> int32_t { + if (ccstd::holds_alternative(value)) { + return ccstd::get(value) - range[0]; + } + if (ccstd::holds_alternative(value)) { + return (ccstd::get(value) ? 1 : 0) - range[0]; + } + CC_ABORT(); // We only support macro with int32_t type now. + return 0; + }; + } else if (def.type == "string") { + cnt = getBitCount(static_cast(def.options.value().size())); + def.map = [=](const MacroValue &value) -> int32_t { + const auto *pValue = ccstd::get_if(&value); + if (pValue != nullptr) { + auto idx = static_cast(std::find(def.options.value().begin(), def.options.value().end(), *pValue) - def.options.value().begin()); + return std::max(0, idx); + } + return 0; + }; + } else if (def.type == "boolean") { + def.map = [](const MacroValue &value) -> int32_t { + const auto *pBool = ccstd::get_if(&value); + if (pBool != nullptr) { + return *pBool ? 1 : 0; + } + const auto *pInt = ccstd::get_if(&value); + if (pInt != nullptr) { + return *pInt ? 1 : 0; + } + const auto *pString = ccstd::get_if(&value); + if (pString != nullptr) { + return *pString != "0" || !(*pString).empty() ? 1 : 0; + } + return 0; + }; + } + def.offset = offset; + offset += cnt; + } + if (offset > 31) { + tmpl.uber = true; + } + // generate constant macros + { + tmpl.constantMacros.clear(); + std::stringstream ss; + for (auto &key : tmpl.builtins.statistics) { + ss << "#define " << key.first << " " << key.second << std::endl; + } + tmpl.constantMacros = ss.str(); + } +} + +ccstd::unordered_map genHandles(const IProgramInfo &tmpl) { + return genHandlesImpl(tmpl); +} + +ccstd::unordered_map genHandles(const gfx::ShaderInfo &tmpl) { + return genHandlesImpl(tmpl); +} + +ccstd::string getVariantKey(const IProgramInfo &tmpl, const MacroRecord &defines) { + const auto &tmplDefs = tmpl.defines; + if (tmpl.uber) { + std::stringstream key; + for (const auto &tmplDef : tmplDefs) { + auto itDef = defines.find(tmplDef.name); + if (itDef == defines.end() || !tmplDef.map) { + continue; + } + const auto &value = itDef->second; + auto mapped = tmplDef.map(value); + auto offset = tmplDef.offset; + key << offset << mapped << "|"; + } + ccstd::string ret{key.str() + std::to_string(tmpl.hash)}; + return ret; + } + uint32_t key = 0; + std::stringstream ss; + for (const auto &tmplDef : tmplDefs) { + auto itDef = defines.find(tmplDef.name); + if (itDef == defines.end() || !tmplDef.map) { + continue; + } + const auto &value = itDef->second; + auto mapped = tmplDef.map(value); + auto offset = tmplDef.offset; + key |= (mapped << offset); + } + ss << std::hex << key << "|" << std::to_string(tmpl.hash); + ccstd::string ret{ss.str()}; + return ret; +} + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonReflection.h b/native/cocos/renderer/core/ProgramUtils.h similarity index 73% rename from native/cocos/renderer/pipeline/custom/RenderCommonReflection.h rename to native/cocos/renderer/core/ProgramUtils.h index 752de77c98..8dbdbbaf01 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonReflection.h +++ b/native/cocos/renderer/core/ProgramUtils.h @@ -1,5 +1,5 @@ /**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd. http://www.cocos.com @@ -23,13 +23,19 @@ THE SOFTWARE. ****************************************************************************/ -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off #pragma once -#include "cocos/renderer/pipeline/custom/RenderCommonFwd.h" +#include "cocos/renderer/core/ProgramLib.h" -// clang-format on +namespace cc { + +namespace render { + +void populateMacros(IProgramInfo& tmpl); + +ccstd::unordered_map genHandles(const IProgramInfo& tmpl); +ccstd::unordered_map genHandles(const gfx::ShaderInfo& tmpl); +ccstd::string getVariantKey(const IProgramInfo& tmpl, const MacroRecord& defines); + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/frame-graph/ImmutableState.cpp b/native/cocos/renderer/frame-graph/ImmutableState.cpp index 8b2906cb44..643b29b230 100644 --- a/native/cocos/renderer/frame-graph/ImmutableState.cpp +++ b/native/cocos/renderer/frame-graph/ImmutableState.cpp @@ -28,7 +28,6 @@ #include #include "DevicePassResourceTable.h" #include "gfx-base/GFXBarrier.h" -#include "pipeline/custom/GslUtils.h" namespace cc { namespace framegraph { diff --git a/native/cocos/renderer/pipeline/custom/BinaryArchive.h b/native/cocos/renderer/pipeline/custom/BinaryArchive.h index 1089bf9548..23f8a10242 100644 --- a/native/cocos/renderer/pipeline/custom/BinaryArchive.h +++ b/native/cocos/renderer/pipeline/custom/BinaryArchive.h @@ -1,3 +1,28 @@ +/**************************************************************************** + Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + #pragma once #include #include diff --git a/native/cocos/renderer/pipeline/custom/FGDispatcherGraphs.h b/native/cocos/renderer/pipeline/custom/FGDispatcherGraphs.h index 329b4934c7..585f5d7a28 100644 --- a/native/cocos/renderer/pipeline/custom/FGDispatcherGraphs.h +++ b/native/cocos/renderer/pipeline/custom/FGDispatcherGraphs.h @@ -33,10 +33,9 @@ #include #include #include "cocos/renderer/pipeline/custom/FGDispatcherTypes.h" -#include "cocos/renderer/pipeline/custom/GraphImpl.h" -#include "cocos/renderer/pipeline/custom/GslUtils.h" -#include "cocos/renderer/pipeline/custom/Overload.h" -#include "cocos/renderer/pipeline/custom/PathUtils.h" +#include "cocos/renderer/pipeline/custom/details/GraphImpl.h" +#include "cocos/renderer/pipeline/custom/details/Overload.h" +#include "cocos/renderer/pipeline/custom/details/PathUtils.h" namespace cc { @@ -220,8 +219,8 @@ inline void remove_vertex(ResourceAccessGraph::vertex_descriptor u, ResourceAcce impl::removeVectorVertex(const_cast(g), u, ResourceAccessGraph::directed_category{}); // remove components - g.passID.erase(g.passID.begin() + std::ptrdiff_t(u)); - g.access.erase(g.access.begin() + std::ptrdiff_t(u)); + g.passID.erase(g.passID.begin() + static_cast(u)); + g.access.erase(g.access.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) @@ -452,7 +451,7 @@ inline void remove_vertex(RelationGraph::vertex_descriptor u, RelationGraph& g) impl::removeVectorVertex(const_cast(g), u, RelationGraph::directed_category{}); // remove components - g.descID.erase(g.descID.begin() + std::ptrdiff_t(u)); + g.descID.erase(g.descID.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) diff --git a/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h b/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h index b0239ab47a..6c1b5f7781 100644 --- a/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h +++ b/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h @@ -37,11 +37,11 @@ #include #include "cocos/base/std/container/string.h" #include "cocos/base/std/container/vector.h" -#include "cocos/renderer/pipeline/custom/GraphTypes.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" -#include "cocos/renderer/pipeline/custom/Map.h" #include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" -#include "cocos/renderer/pipeline/custom/Set.h" +#include "cocos/renderer/pipeline/custom/details/GraphTypes.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" +#include "cocos/renderer/pipeline/custom/details/Set.h" #include "gfx-base/GFXDef-common.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index 8594efe4a2..e81d95515e 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -37,13 +37,13 @@ #include "FGDispatcherTypes.h" #include "LayoutGraphGraphs.h" #include "LayoutGraphTypes.h" -#include "Range.h" #include "RenderGraphGraphs.h" #include "base/Log.h" #include "boost/graph/depth_first_search.hpp" #include "boost/graph/hawick_circuits.hpp" #include "boost/graph/visitors.hpp" #include "boost/lexical_cast.hpp" +#include "details/Range.h" #include "gfx-base/GFXBarrier.h" #include "gfx-base/GFXDef-common.h" #include "gfx-base/GFXDef.h" @@ -51,9 +51,9 @@ #include "gfx-base/states/GFXBufferBarrier.h" #include "gfx-base/states/GFXTextureBarrier.h" #include "math/Vec2.h" -#include "pipeline/custom/GslUtils.h" #include "pipeline/custom/RenderCommonFwd.h" #include "pipeline/custom/RenderGraphTypes.h" +#include "pipeline/custom/details/GslUtils.h" namespace cc { @@ -184,7 +184,7 @@ bool tryAddEdge(uint32_t srcVertex, uint32_t dstVertex, Graph &graph); // for transive_closure.hpp line 231 inline RelationGraph::vertex_descriptor add_vertex(RelationGraph &g) { // NOLINT - thread_local uint32_t count = 0; // unused + thread_local uint32_t count = 0; // unused return add_vertex(g, count++); } diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphGraphs.h b/native/cocos/renderer/pipeline/custom/LayoutGraphGraphs.h index ca7360788d..2ce8ce38b1 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphGraphs.h +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphGraphs.h @@ -32,11 +32,10 @@ #pragma once #include #include -#include "cocos/renderer/pipeline/custom/GraphImpl.h" -#include "cocos/renderer/pipeline/custom/GslUtils.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" -#include "cocos/renderer/pipeline/custom/Overload.h" -#include "cocos/renderer/pipeline/custom/PathUtils.h" +#include "cocos/renderer/pipeline/custom/details/GraphImpl.h" +#include "cocos/renderer/pipeline/custom/details/Overload.h" +#include "cocos/renderer/pipeline/custom/details/PathUtils.h" namespace cc { @@ -1145,7 +1144,7 @@ inline void removePathImpl(LayoutGraph::vertex_descriptor u, LayoutGraph& g) noe // notice: here we use ccstd::string, not std::pmr::string // we do not want to increase the memory of g auto pathName = getPath(u, g); - auto iter = g.pathIndex.find(std::string_view(pathName)); + auto iter = g.pathIndex.find(std::string_view{pathName}); CC_EXPECTS(iter != g.pathIndex.end()); g.pathIndex.erase(iter); for (auto&& nvp : g.pathIndex) { @@ -1203,14 +1202,14 @@ inline void remove_vertex_value_impl(const LayoutGraph::VertexHandle& h, LayoutG ccstd::visit( overload( [&](const impl::ValueHandle& h) { - g.stages.erase(g.stages.begin() + std::ptrdiff_t(h.value)); + g.stages.erase(g.stages.begin() + static_cast(h.value)); if (h.value == g.stages.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.phases.erase(g.phases.begin() + std::ptrdiff_t(h.value)); + g.phases.erase(g.phases.begin() + static_cast(h.value)); if (h.value == g.phases.size()) { return; } @@ -1226,8 +1225,8 @@ inline void remove_vertex(LayoutGraph::vertex_descriptor u, LayoutGraph& g) noex impl::removeVectorVertex(const_cast(g), u, LayoutGraph::directed_category{}); // remove components - g.names.erase(g.names.begin() + std::ptrdiff_t(u)); - g.descriptors.erase(g.descriptors.begin() + std::ptrdiff_t(u)); + g.names.erase(g.names.begin() + static_cast(u)); + g.descriptors.erase(g.descriptors.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) @@ -1845,7 +1844,7 @@ inline void removePathImpl(LayoutGraphData::vertex_descriptor u, LayoutGraphData // notice: here we use ccstd::string, not std::pmr::string // we do not want to increase the memory of g auto pathName = getPath(u, g); - auto iter = g.pathIndex.find(std::string_view(pathName)); + auto iter = g.pathIndex.find(std::string_view{pathName}); CC_EXPECTS(iter != g.pathIndex.end()); g.pathIndex.erase(iter); for (auto&& nvp : g.pathIndex) { @@ -1903,14 +1902,14 @@ inline void remove_vertex_value_impl(const LayoutGraphData::VertexHandle& h, Lay ccstd::visit( overload( [&](const impl::ValueHandle& h) { - g.stages.erase(g.stages.begin() + std::ptrdiff_t(h.value)); + g.stages.erase(g.stages.begin() + static_cast(h.value)); if (h.value == g.stages.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.phases.erase(g.phases.begin() + std::ptrdiff_t(h.value)); + g.phases.erase(g.phases.begin() + static_cast(h.value)); if (h.value == g.phases.size()) { return; } @@ -1926,9 +1925,9 @@ inline void remove_vertex(LayoutGraphData::vertex_descriptor u, LayoutGraphData& impl::removeVectorVertex(const_cast(g), u, LayoutGraphData::directed_category{}); // remove components - g.names.erase(g.names.begin() + std::ptrdiff_t(u)); - g.updateFrequencies.erase(g.updateFrequencies.begin() + std::ptrdiff_t(u)); - g.layouts.erase(g.layouts.begin() + std::ptrdiff_t(u)); + g.names.erase(g.names.begin() + static_cast(u)); + g.updateFrequencies.erase(g.updateFrequencies.begin() + static_cast(u)); + g.layouts.erase(g.layouts.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.cpp b/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.cpp deleted file mode 100644 index 7fad571b80..0000000000 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#include "LayoutGraphReflection.h" -#include "LayoutGraphTypes.h" - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.h b/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.h deleted file mode 100644 index ce99723f6a..0000000000 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphReflection.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#pragma once -#include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h" -#include "cocos/renderer/pipeline/custom/RenderCommonReflection.h" - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphSerialization.h b/native/cocos/renderer/pipeline/custom/LayoutGraphSerialization.h index 8795bf8b4a..2f96f1c83b 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphSerialization.h +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphSerialization.h @@ -29,12 +29,12 @@ * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= */ #pragma once -#include #include "cocos/renderer/pipeline/custom/ArchiveTypes.h" +#include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" -#include "cocos/renderer/pipeline/custom/Range.h" #include "cocos/renderer/pipeline/custom/RenderCommonSerialization.h" -#include "cocos/renderer/pipeline/custom/SerializationUtils.h" +#include "cocos/renderer/pipeline/custom/details/Range.h" +#include "cocos/renderer/pipeline/custom/details/SerializationUtils.h" namespace cc { @@ -202,6 +202,7 @@ inline void save(OutputArchive& ar, const DescriptorSetLayoutData& v) { save(ar, v.capacity); save(ar, v.descriptorBlocks); save(ar, v.uniformBlocks); + save(ar, v.bindingMap); } inline void load(InputArchive& ar, DescriptorSetLayoutData& v) { @@ -209,6 +210,7 @@ inline void load(InputArchive& ar, DescriptorSetLayoutData& v) { load(ar, v.capacity); load(ar, v.descriptorBlocks); load(ar, v.uniformBlocks); + load(ar, v.bindingMap); } inline void save(OutputArchive& ar, const DescriptorSetData& v) { diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.cpp b/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.cpp index 84cc875a95..e40aa4a038 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.cpp +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.cpp @@ -134,19 +134,22 @@ DescriptorBlockData::DescriptorBlockData(DescriptorBlockData const& rhs, const a DescriptorSetLayoutData::DescriptorSetLayoutData(const allocator_type& alloc) noexcept : descriptorBlocks(alloc), - uniformBlocks(alloc) {} + uniformBlocks(alloc), + bindingMap(alloc) {} -DescriptorSetLayoutData::DescriptorSetLayoutData(uint32_t slotIn, uint32_t capacityIn, ccstd::pmr::vector descriptorBlocksIn, ccstd::pmr::unordered_map uniformBlocksIn, const allocator_type& alloc) noexcept // NOLINT +DescriptorSetLayoutData::DescriptorSetLayoutData(uint32_t slotIn, uint32_t capacityIn, ccstd::pmr::vector descriptorBlocksIn, ccstd::pmr::unordered_map uniformBlocksIn, PmrFlatMap bindingMapIn, const allocator_type& alloc) noexcept // NOLINT : slot(slotIn), capacity(capacityIn), descriptorBlocks(std::move(descriptorBlocksIn), alloc), - uniformBlocks(std::move(uniformBlocksIn), alloc) {} + uniformBlocks(std::move(uniformBlocksIn), alloc), + bindingMap(std::move(bindingMapIn), alloc) {} DescriptorSetLayoutData::DescriptorSetLayoutData(DescriptorSetLayoutData&& rhs, const allocator_type& alloc) : slot(rhs.slot), capacity(rhs.capacity), descriptorBlocks(std::move(rhs.descriptorBlocks), alloc), - uniformBlocks(std::move(rhs.uniformBlocks), alloc) {} + uniformBlocks(std::move(rhs.uniformBlocks), alloc), + bindingMap(std::move(rhs.bindingMap), alloc) {} DescriptorSetData::DescriptorSetData(const allocator_type& alloc) noexcept : descriptorSetLayoutData(alloc) {} diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h b/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h index 3cecf5ff03..9ff71faaa8 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h @@ -42,11 +42,11 @@ #include "cocos/renderer/gfx-base/GFXDescriptorSet.h" #include "cocos/renderer/gfx-base/GFXDescriptorSetLayout.h" #include "cocos/renderer/gfx-base/GFXPipelineLayout.h" -#include "cocos/renderer/pipeline/custom/GraphTypes.h" #include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h" -#include "cocos/renderer/pipeline/custom/Map.h" #include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" -#include "cocos/renderer/pipeline/custom/Set.h" +#include "cocos/renderer/pipeline/custom/details/GraphTypes.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" +#include "cocos/renderer/pipeline/custom/details/Set.h" namespace cc { @@ -304,6 +304,11 @@ inline bool operator!=(const NameLocalID& lhs, const NameLocalID& rhs) noexcept return !(lhs == rhs); } +inline bool operator<(const NameLocalID& lhs, const NameLocalID& rhs) noexcept { + return std::forward_as_tuple(lhs.value) < + std::forward_as_tuple(rhs.value); +} + struct DescriptorData { DescriptorData() = default; DescriptorData(NameLocalID descriptorIDIn, gfx::Type typeIn, uint32_t countIn) noexcept @@ -351,7 +356,7 @@ struct DescriptorSetLayoutData { } DescriptorSetLayoutData(const allocator_type& alloc) noexcept; // NOLINT - DescriptorSetLayoutData(uint32_t slotIn, uint32_t capacityIn, ccstd::pmr::vector descriptorBlocksIn, ccstd::pmr::unordered_map uniformBlocksIn, const allocator_type& alloc) noexcept; + DescriptorSetLayoutData(uint32_t slotIn, uint32_t capacityIn, ccstd::pmr::vector descriptorBlocksIn, ccstd::pmr::unordered_map uniformBlocksIn, PmrFlatMap bindingMapIn, const allocator_type& alloc) noexcept; DescriptorSetLayoutData(DescriptorSetLayoutData&& rhs, const allocator_type& alloc); DescriptorSetLayoutData(DescriptorSetLayoutData&& rhs) noexcept = default; @@ -363,6 +368,7 @@ struct DescriptorSetLayoutData { uint32_t capacity{0}; ccstd::pmr::vector descriptorBlocks; ccstd::pmr::unordered_map uniformBlocks; + PmrFlatMap bindingMap; }; struct DescriptorSetData { diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp new file mode 100644 index 0000000000..3530961ca6 --- /dev/null +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp @@ -0,0 +1,298 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include "LayoutGraphUtils.h" +#include +#include +#include "cocos/base/Log.h" +#include "cocos/base/std/container/string.h" +#include "cocos/renderer/gfx-base/GFXDef-common.h" +#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" +#include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" +#include "details/Map.h" + +namespace cc { + +namespace render { + +namespace { + +DescriptorBlockData& getDescriptorBlockData( + PmrFlatMap& map, + const DescriptorBlockIndex& index) { + auto iter = map.find(index); + if (iter != map.end()) { + return iter->second; + } + iter = map.emplace( + std::piecewise_construct, + std::forward_as_tuple(index), + std::forward_as_tuple()) + .first; + + return iter->second; +} + +} // namespace + +gfx::DescriptorType getGfxDescriptorType(DescriptorTypeOrder type) { + switch (type) { + case DescriptorTypeOrder::UNIFORM_BUFFER: + return gfx::DescriptorType::UNIFORM_BUFFER; + case DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER: + return gfx::DescriptorType::DYNAMIC_UNIFORM_BUFFER; + case DescriptorTypeOrder::SAMPLER_TEXTURE: + return gfx::DescriptorType::SAMPLER_TEXTURE; + case DescriptorTypeOrder::SAMPLER: + return gfx::DescriptorType::SAMPLER; + case DescriptorTypeOrder::TEXTURE: + return gfx::DescriptorType::TEXTURE; + case DescriptorTypeOrder::STORAGE_BUFFER: + return gfx::DescriptorType::STORAGE_BUFFER; + case DescriptorTypeOrder::DYNAMIC_STORAGE_BUFFER: + return gfx::DescriptorType::DYNAMIC_STORAGE_BUFFER; + case DescriptorTypeOrder::STORAGE_IMAGE: + return gfx::DescriptorType::STORAGE_IMAGE; + case DescriptorTypeOrder::INPUT_ATTACHMENT: + return gfx::DescriptorType::INPUT_ATTACHMENT; + default: + CC_LOG_ERROR("DescriptorType not found"); + return gfx::DescriptorType::INPUT_ATTACHMENT; + } +} + +DescriptorTypeOrder getDescriptorTypeOrder(gfx::DescriptorType type) { + switch (type) { + case gfx::DescriptorType::UNIFORM_BUFFER: + return DescriptorTypeOrder::UNIFORM_BUFFER; + case gfx::DescriptorType::DYNAMIC_UNIFORM_BUFFER: + return DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER; + case gfx::DescriptorType::SAMPLER_TEXTURE: + return DescriptorTypeOrder::SAMPLER_TEXTURE; + case gfx::DescriptorType::SAMPLER: + return DescriptorTypeOrder::SAMPLER; + case gfx::DescriptorType::TEXTURE: + return DescriptorTypeOrder::TEXTURE; + case gfx::DescriptorType::STORAGE_BUFFER: + return DescriptorTypeOrder::STORAGE_BUFFER; + case gfx::DescriptorType::DYNAMIC_STORAGE_BUFFER: + return DescriptorTypeOrder::DYNAMIC_STORAGE_BUFFER; + case gfx::DescriptorType::STORAGE_IMAGE: + return DescriptorTypeOrder::STORAGE_IMAGE; + case gfx::DescriptorType::INPUT_ATTACHMENT: + return DescriptorTypeOrder::INPUT_ATTACHMENT; + case gfx::DescriptorType::UNKNOWN: + default: + CC_LOG_ERROR("DescriptorTypeOrder not found"); + return DescriptorTypeOrder::INPUT_ATTACHMENT; + } +} + +NameLocalID getOrCreateDescriptorID(LayoutGraphData& lg, std::string_view name) { + auto iter = lg.attributeIndex.find(name); + if (iter != lg.attributeIndex.end()) { + return iter->second; + } + const auto id = static_cast(lg.valueNames.size()); + lg.attributeIndex.emplace(name, NameLocalID{id}); + lg.valueNames.emplace_back(name); + return NameLocalID{id}; +} + +void makeDescriptorSetLayoutData( + LayoutGraphData& lg, + UpdateFrequency rate, uint32_t set, const IDescriptorInfo& descriptors, + DescriptorSetLayoutData& data, + boost::container::pmr::memory_resource* scratch) { + PmrFlatMap map(scratch); + PmrFlatMap uniformBlocks(scratch); + for (const auto& cb : descriptors.blocks) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::UNIFORM_BUFFER, + cb.stageFlags, + }); + + const auto nameID = getOrCreateDescriptorID(lg, cb.name); + block.descriptors.emplace_back(nameID, gfx::Type::UNKNOWN, 1); + // add uniform buffer + uniformBlocks.emplace( + std::piecewise_construct, + std::forward_as_tuple(nameID), + std::forward_as_tuple(gfx::UniformBlock{set, 0xFFFFFFFF, cb.name, cb.members, 1})); + } + for (const auto& samplerTexture : descriptors.samplerTextures) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::SAMPLER_TEXTURE, + samplerTexture.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, samplerTexture.name); + block.descriptors.emplace_back(nameID, samplerTexture.type, samplerTexture.count); + } + for (const auto& sampler : descriptors.samplers) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::SAMPLER, + sampler.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, sampler.name); + block.descriptors.emplace_back(nameID, gfx::Type::SAMPLER, sampler.count); + } + for (const auto& texture : descriptors.textures) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::TEXTURE, + texture.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, texture.name); + block.descriptors.emplace_back(nameID, texture.type, texture.count); + } + for (const auto& buffer : descriptors.buffers) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::STORAGE_BUFFER, + buffer.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, buffer.name); + block.descriptors.emplace_back(nameID, gfx::Type::UNKNOWN, 1); + } + for (const auto& image : descriptors.images) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::STORAGE_IMAGE, + image.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, image.name); + block.descriptors.emplace_back(nameID, image.type, image.count); + } + for (const auto& subpassInput : descriptors.subpassInputs) { + auto& block = getDescriptorBlockData( + map, DescriptorBlockIndex{ + rate, + ParameterType::TABLE, + DescriptorTypeOrder::INPUT_ATTACHMENT, + subpassInput.stageFlags, + }); + const auto nameID = getOrCreateDescriptorID(lg, subpassInput.name); + block.descriptors.emplace_back(nameID, gfx::Type::UNKNOWN, subpassInput.count); + } + + // calculate bindings + uint32_t capacity = 0; + for (auto&& [index, block] : map) { + block.offset = capacity; + for (const auto& d : block.descriptors) { + if (index.descriptorType == DescriptorTypeOrder::UNIFORM_BUFFER) { + // update uniform buffer binding + auto iter = uniformBlocks.find(d.descriptorID); + if (iter == uniformBlocks.end()) { + CC_LOG_ERROR("Uniform block not found"); + continue; + } + auto& ub = iter->second; + assert(ub.binding == 0xFFFFFFFF); + ub.binding = block.capacity; + // add uniform buffer to output + data.uniformBlocks.emplace(d.descriptorID, std::move(ub)); + } + // update block capacity + auto iter = data.bindingMap.find(d.descriptorID); + if (iter != data.bindingMap.end()) { + CC_LOG_ERROR("Duplicated descriptor name: %s", lg.valueNames[d.descriptorID.value].c_str()); + continue; + } + data.bindingMap.emplace(d.descriptorID, block.offset + block.capacity); + block.capacity += d.count; + } + // increate total capacity + capacity += block.capacity; + data.descriptorBlocks.emplace_back(std::move(block)); + } +} + +void initializeDescriptorSetLayoutInfo( + const DescriptorSetLayoutData& layoutData, + gfx::DescriptorSetLayoutInfo& info) { + for (const auto& block : layoutData.descriptorBlocks) { + auto slot = block.offset; + for (const auto& d : block.descriptors) { + auto& binding = info.bindings.emplace_back(); + binding.binding = slot; + binding.descriptorType = getGfxDescriptorType(block.type); + binding.count = d.count; + binding.stageFlags = block.visibility; + binding.immutableSamplers = {}; + + // update slot + slot += d.count; + } + } +} + +namespace { + +const ccstd::unordered_map DEFAULT_UNIFORM_COUNTS{ + {"cc_joints", pipeline::UBOSkinning::layout.members[0].count}, + {"cc_lightPos", pipeline::UBOForwardLight::LIGHTS_PER_PASS}, + {"cc_lightColor", pipeline::UBOForwardLight::LIGHTS_PER_PASS}, + {"cc_lightSizeRangeAngle", pipeline::UBOForwardLight::LIGHTS_PER_PASS}, + {"cc_lightDir", pipeline::UBOForwardLight::LIGHTS_PER_PASS}, +}; + +} // namespace + +uint32_t getSize(const ccstd::vector& blockMembers) { + uint32_t prevSize = 0; + for (const auto& m : blockMembers) { + if (m.count) { + prevSize += getTypeSize(m.type) * m.count; + continue; + } + auto iter = DEFAULT_UNIFORM_COUNTS.find(m.name); + if (iter != DEFAULT_UNIFORM_COUNTS.end()) { + prevSize += getTypeSize(m.type) * iter->second; + continue; + } + CC_LOG_ERROR("Invalid uniform count: %s", m.name.c_str()); + } + return prevSize; +} + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphJsb.cpp b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h similarity index 61% rename from native/cocos/renderer/pipeline/custom/LayoutGraphJsb.cpp rename to native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h index 0384625d96..9e659d3fe9 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphJsb.cpp +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h @@ -23,15 +23,33 @@ THE SOFTWARE. ****************************************************************************/ -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#include "cocos/bindings/auto/jsb_gfx_auto.h" -#include "cocos/renderer/pipeline/custom/JsbConversion.h" -#include "cocos/renderer/pipeline/custom/LayoutGraphJsb.h" +#pragma once +#include +#include "cocos/core/assets/EffectAsset.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" +#include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" -// clang-format on +namespace cc { + +namespace render { + +gfx::DescriptorType getGfxDescriptorType(DescriptorTypeOrder type); +DescriptorTypeOrder getDescriptorTypeOrder(gfx::DescriptorType type); + +NameLocalID getOrCreateDescriptorID(LayoutGraphData& lg, std::string_view name); + +void makeDescriptorSetLayoutData( + LayoutGraphData& lg, + UpdateFrequency rate, uint32_t set, const IDescriptorInfo& descriptors, + DescriptorSetLayoutData& data, + boost::container::pmr::memory_resource* scratch); + +void initializeDescriptorSetLayoutInfo( + const DescriptorSetLayoutData& layoutData, + gfx::DescriptorSetLayoutInfo& info); + +uint32_t getSize(const ccstd::vector& blockMembers); + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index 3cf35ebab9..3fc4ee30a3 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -2,17 +2,10 @@ #include #include #include "FGDispatcherGraphs.h" -#include "GraphTypes.h" -#include "GraphView.h" -#include "GslUtils.h" #include "NativePipelineFwd.h" #include "NativePipelineTypes.h" -#include "Pmr.h" -#include "Range.h" -#include "RenderCommonFwd.h" #include "RenderGraphGraphs.h" #include "RenderGraphTypes.h" -#include "Set.h" #include "cocos/renderer/gfx-base/GFXBarrier.h" #include "cocos/renderer/gfx-base/GFXDef-common.h" #include "cocos/renderer/gfx-base/GFXDevice.h" @@ -22,6 +15,9 @@ #include "cocos/scene/Pass.h" #include "cocos/scene/RenderScene.h" #include "cocos/scene/Skybox.h" +#include "details/GraphView.h" +#include "details/GslUtils.h" +#include "details/Range.h" namespace cc { @@ -971,7 +967,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) { auto& ppl = *this; auto* scratch = &ppl.unsyncPool; - //CC_LOG_INFO(rg.print(scratch).c_str()); + // CC_LOG_INFO(rg.print(scratch).c_str()); RenderGraphContextCleaner contextCleaner(ppl.nativeContext); ResourceCleaner cleaner(ppl.resourceGraph); diff --git a/native/cocos/renderer/pipeline/custom/NativeFactory.cpp b/native/cocos/renderer/pipeline/custom/NativeFactory.cpp new file mode 100644 index 0000000000..cfa0bd5d43 --- /dev/null +++ b/native/cocos/renderer/pipeline/custom/NativeFactory.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include +#include "BinaryArchive.h" +#include "LayoutGraphSerialization.h" +#include "NativePipelineTypes.h" +#include "RenderInterfaceTypes.h" +#include "details/GslUtils.h" +#include "pipeline/custom/LayoutGraphTypes.h" +#include "pipeline/custom/details/Pmr.h" + +namespace cc { + +namespace render { + +namespace { + +NativeRenderingModule* sRenderingModule = nullptr; + +} // namespace + +RenderingModule* Factory::init(gfx::Device* deviceIn, const ccstd::vector& bufferIn) { + std::ignore = deviceIn; + + std::shared_ptr ptr( + allocatePmrUniquePtr( + boost::container::pmr::get_default_resource())); + { + std::string buffer(bufferIn.begin(), bufferIn.end()); + std::istringstream iss(buffer, std::ios::binary); + BinaryInputArchive ar(iss, boost::container::pmr::get_default_resource()); + load(ar, ptr->layoutGraph); + } + + sRenderingModule = ccnew NativeRenderingModule(std::move(ptr)); + return sRenderingModule; +} + +void Factory::destroy(RenderingModule* renderingModule) noexcept { + auto* ptr = dynamic_cast(renderingModule); + if (ptr) { + ptr->programLibrary.reset(); + } +} + +Pipeline* Factory::createPipeline() { + return ccnew NativePipeline(boost::container::pmr::get_default_resource()); +} + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphJsb.h b/native/cocos/renderer/pipeline/custom/NativeFwd.h similarity index 86% rename from native/cocos/renderer/pipeline/custom/LayoutGraphJsb.h rename to native/cocos/renderer/pipeline/custom/NativeFwd.h index f61ae9043f..94839135b5 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphJsb.h +++ b/native/cocos/renderer/pipeline/custom/NativeFwd.h @@ -30,8 +30,21 @@ */ // clang-format off #pragma once -#include "cocos/bindings/manual/jsb_conversions.h" +#include "cocos/base/std/variant.h" +#include "cocos/renderer/core/ProgramLib.h" #include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h" -#include "cocos/renderer/pipeline/custom/RenderCommonJsb.h" +#include "cocos/renderer/pipeline/custom/RenderInterfaceFwd.h" + +namespace cc { + +namespace render { + +struct ProgramInfo; +struct ProgramHost; +struct ProgramGroup; + +} // namespace render + +} // namespace cc // clang-format on diff --git a/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp b/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp similarity index 98% rename from native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp rename to native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp index 82b382f1be..bfe8a1f6d1 100644 --- a/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp @@ -23,17 +23,16 @@ THE SOFTWARE. ****************************************************************************/ -#include "DebugUtils.h" -#include "GslUtils.h" #include "LayoutGraphGraphs.h" #include "LayoutGraphNames.h" #include "LayoutGraphTypes.h" #include "NativePipelineGraphs.h" -#include "Pmr.h" -#include "Range.h" #include "RenderCommonNames.h" #include "cocos/renderer/gfx-base/GFXDevice.h" - +#include "details/DebugUtils.h" +#include "details/GslUtils.h" +#include "details/Pmr.h" +#include "details/Range.h" namespace cc { @@ -87,7 +86,7 @@ void NativeLayoutGraphBuilder::addDescriptorBlock( for (const auto &pairD : block.descriptors) { const auto &name = pairD.first; const auto &d = pairD.second; - auto iter = g.attributeIndex.find(std::string_view(name)); + auto iter = g.attributeIndex.find(std::string_view{name}); if (iter == g.attributeIndex.end()) { auto attrID = gsl::narrow_cast(g.valueNames.size()); g.valueNames.emplace_back(name); @@ -109,7 +108,7 @@ void NativeLayoutGraphBuilder::addUniformBlock(uint32_t nodeID, const Descriptor auto &g = *data; auto &ppl = get(LayoutGraphData::Layout, g, nodeID); auto &layout = ppl.descriptorSets[index.updateFrequency].descriptorSetLayoutData; - auto iter = g.attributeIndex.find(std::string_view(name)); + auto iter = g.attributeIndex.find(std::string_view{name}); if (iter == g.attributeIndex.end()) { auto attrID = gsl::narrow_cast(g.valueNames.size()); g.valueNames.emplace_back(name); diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp similarity index 99% rename from native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp rename to native/cocos/renderer/pipeline/custom/NativePipeline.cpp index ca9d58fe92..26cdf91355 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -30,16 +30,12 @@ #include #include #include -#include "DebugUtils.h" -#include "GslUtils.h" #include "LayoutGraphFwd.h" #include "LayoutGraphGraphs.h" #include "LayoutGraphNames.h" #include "LayoutGraphTypes.h" #include "NativePipelineFwd.h" #include "NativePipelineTypes.h" -#include "Pmr.h" -#include "Range.h" #include "RenderCommonTypes.h" #include "RenderGraphGraphs.h" #include "RenderGraphTypes.h" @@ -62,6 +58,8 @@ #include "cocos/renderer/pipeline/RenderPipeline.h" #include "cocos/scene/RenderScene.h" #include "cocos/scene/RenderWindow.h" +#include "details/DebugUtils.h" +#include "details/GslUtils.h" #if CC_USE_DEBUG_RENDERER #include "profiler/DebugRenderer.h" @@ -343,7 +341,7 @@ LayoutGraphBuilder *NativePipeline::getLayoutGraphBuilder() { } gfx::DescriptorSetLayout *NativePipeline::getDescriptorSetLayout(const ccstd::string &shaderName, UpdateFrequency freq) { - auto iter = layoutGraph.shaderLayoutIndex.find(std::string_view(shaderName)); + auto iter = layoutGraph.shaderLayoutIndex.find(std::string_view{shaderName}); if (iter != layoutGraph.shaderLayoutIndex.end()) { const auto &layouts = get(LayoutGraphData::Layout, layoutGraph, iter->second).descriptorSets; auto iter2 = layouts.find(freq); diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h b/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h index dc904a47be..2a7473e398 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineFwd.h @@ -32,9 +32,9 @@ #pragma once #include "cocos/base/std/variant.h" #include "cocos/renderer/pipeline/InstancedBuffer.h" -#include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h" +#include "cocos/renderer/pipeline/custom/NativeFwd.h" +#include "cocos/renderer/pipeline/custom/PrivateFwd.h" #include "cocos/renderer/pipeline/custom/RenderGraphFwd.h" -#include "cocos/renderer/pipeline/custom/RenderInterfaceFwd.h" namespace cc { @@ -58,6 +58,9 @@ class DefaultForwardLightingTransversal; struct ResourceGroup; struct NativeRenderContext; class NativePipeline; +class NativeProgramProxy; +class NativeProgramLibrary; +class NativeRenderingModule; } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineGraphs.h b/native/cocos/renderer/pipeline/custom/NativePipelineGraphs.h index ff4380695d..c4f316fde5 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineGraphs.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineGraphs.h @@ -32,10 +32,9 @@ #pragma once #include #include -#include "cocos/renderer/pipeline/custom/GraphImpl.h" -#include "cocos/renderer/pipeline/custom/GslUtils.h" #include "cocos/renderer/pipeline/custom/NativePipelineTypes.h" -#include "cocos/renderer/pipeline/custom/Overload.h" -#include "cocos/renderer/pipeline/custom/PathUtils.h" +#include "cocos/renderer/pipeline/custom/details/GraphImpl.h" +#include "cocos/renderer/pipeline/custom/details/Overload.h" +#include "cocos/renderer/pipeline/custom/details/PathUtils.h" // clang-format on diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.cpp b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.cpp index e0079793ea..985864782e 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.cpp @@ -108,6 +108,10 @@ NativeRenderContext::NativeRenderContext(const allocator_type& alloc) noexcept : renderPasses(alloc), resourceGroups(alloc) {} +NativeProgramLibrary::NativeProgramLibrary(const allocator_type& alloc) noexcept +: layoutGraph(alloc), + phases(alloc) {} + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h index be9a96db4f..a8a0fdc42f 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h @@ -37,11 +37,12 @@ #include "cocos/renderer/gfx-base/GFXRenderPass.h" #include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" #include "cocos/renderer/pipeline/InstancedBuffer.h" -#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" #include "cocos/renderer/pipeline/custom/NativePipelineFwd.h" +#include "cocos/renderer/pipeline/custom/NativeTypes.h" +#include "cocos/renderer/pipeline/custom/PrivateTypes.h" #include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" -#include "cocos/renderer/pipeline/custom/RenderInterfaceTypes.h" -#include "cocos/renderer/pipeline/custom/Set.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" +#include "cocos/renderer/pipeline/custom/details/Set.h" namespace cc { @@ -502,6 +503,66 @@ public: RenderGraph renderGraph; }; +class NativeProgramProxy final : public ProgramProxy { +public: + NativeProgramProxy() = default; + NativeProgramProxy(IntrusivePtr shaderIn) noexcept // NOLINT + : shader(std::move(shaderIn)) {} + + const ccstd::string &getName() const noexcept override; + gfx::Shader *getShader() const noexcept override; + + IntrusivePtr shader; +}; + +class NativeProgramLibrary final : public ProgramLibrary { +public: + using allocator_type = boost::container::pmr::polymorphic_allocator; + allocator_type get_allocator() const noexcept { // NOLINT + return {layoutGraph.get_allocator().resource()}; + } + + NativeProgramLibrary(const allocator_type& alloc) noexcept; // NOLINT + + void addEffect(EffectAsset *effectAsset) override; + void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) override; + ccstd::string getKey(uint32_t phaseID, const ccstd::pmr::string &programName, const MacroRecord &defines) const override; + const gfx::PipelineLayout &getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override; + const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override; + const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override; + const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const override; + const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const override; + ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines, const ccstd::pmr::string *key) const override; + const ccstd::pmr::vector &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const override; + const Record &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const override; + uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) override; + uint32_t getDescriptorNameID(const ccstd::pmr::string &name) override; + const ccstd::pmr::string &getDescriptorName(uint32_t nameID) override; + + void init(gfx::Device* device); + void destroy(); + + LayoutGraphData layoutGraph; + PmrFlatMap phases; + boost::container::pmr::unsynchronized_pool_resource unsycPool; + bool mergeHighFrequency{false}; + bool fixedLocal{true}; + IntrusivePtr emptyDescriptorSetLayout; + IntrusivePtr emptyPipelineLayout; +}; + +class NativeRenderingModule final : public RenderingModule { +public: + NativeRenderingModule() = default; + NativeRenderingModule(std::shared_ptr programLibraryIn) noexcept // NOLINT + : programLibrary(std::move(programLibraryIn)) {} + + uint32_t getPassID(const ccstd::string &name) const override; + uint32_t getPhaseID(uint32_t passID, const ccstd::string &name) const override; + + std::shared_ptr programLibrary; +}; + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp new file mode 100644 index 0000000000..732c30805f --- /dev/null +++ b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp @@ -0,0 +1,1048 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include +#include +#include +#include +#include "LayoutGraphUtils.h" +#include "NativePipelineTypes.h" +#include "ProgramLib.h" +#include "ProgramUtils.h" +#include "cocos/base/Log.h" +#include "cocos/core/assets/EffectAsset.h" +#include "cocos/renderer/core/ProgramUtils.h" +#include "cocos/renderer/gfx-base/GFXDef-common.h" +#include "cocos/renderer/pipeline/Define.h" +#include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h" +#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" +#include "gfx-base/GFXDescriptorSetLayout.h" +#include "pipeline/custom/PrivateTypes.h" +#include "pipeline/custom/details/GslUtils.h" + +namespace cc { + +namespace render { + +const ccstd::string &NativeProgramProxy::getName() const noexcept { + return shader->getName(); +} + +gfx::Shader *NativeProgramProxy::getShader() const noexcept { + return shader; +} + +namespace { + +constexpr uint32_t SET_INDEX[4] = {2, 1, 3, 0}; + +constexpr uint32_t setIndex(UpdateFrequency rate) { + return SET_INDEX[static_cast(rate)]; +} + +constexpr auto INVALID_ID = LayoutGraphData::null_vertex(); + +std::tuple +getEffectShader( + const LayoutGraphData &lg, + const EffectAsset &effect, const IPassInfo &pass) { + const auto &programName = pass.program; + auto passID = INVALID_ID; + if (pass.pass) { + passID = locate(INVALID_ID, *pass.pass, lg); + } else { + passID = locate(INVALID_ID, "default", lg); + } + if (passID == INVALID_ID) { + CC_LOG_ERROR("Invalid render pass"); + return {INVALID_ID, INVALID_ID, nullptr, INVALID_ID}; + } + + auto phaseID = INVALID_ID; + if (pass.phase) { + phaseID = locate(passID, *pass.phase, lg); + } else { + phaseID = locate(passID, "default", lg); + } + if (phaseID == INVALID_ID) { + CC_LOG_ERROR("Invalid render phase"); + return {INVALID_ID, INVALID_ID, nullptr, INVALID_ID}; + } + + const IShaderInfo *srcShaderInfo = nullptr; + auto shaderID = INVALID_ID; + for (uint32_t i = 0; i != effect._shaders.size(); ++i) { + const auto &shader = effect._shaders[i]; + if (shader.name == programName) { + srcShaderInfo = &shader; + shaderID = i; + break; + } + } + return {passID, phaseID, srcShaderInfo, shaderID}; +} + +int validateShaderInfo(const IShaderInfo &srcShaderInfo) { + if (srcShaderInfo.descriptors.empty()) { + CC_LOG_ERROR("No descriptors in shaderInfo"); + return 1; + } + return 0; +} + +IProgramInfo makeProgramInfo(const ccstd::string &effectName, const IShaderInfo &shader) { + IProgramInfo programInfo; + programInfo.copyFrom(shader); + programInfo.effectName = effectName; + + populateMacros(programInfo); + + return programInfo; +} + +std::tuple getDescriptorNameAndType( + const pipeline::DescriptorSetLayoutInfos &source, + uint32_t binding) { + for (const auto &[name, block] : source.blocks) { + if (block.binding == binding) { + return {name, gfx::Type::UNKNOWN}; + } + } + for (const auto &[name, texture] : source.samplers) { + if (texture.binding == binding) { + return {name, texture.type}; + } + } + for (const auto &[name, image] : source.storeImages) { + if (image.binding == binding) { + return {name, image.type}; + } + } + return {"", gfx::Type::UNKNOWN}; +} + +void makeLocalDescriptorSetLayoutData( + LayoutGraphData &lg, + const pipeline::DescriptorSetLayoutInfos &source, + DescriptorSetLayoutData &data) { + for (const auto &b : source.bindings) { + const auto [name, type] = getDescriptorNameAndType(source, b.binding); + const auto nameID = getOrCreateDescriptorID(lg, name); + const auto order = getDescriptorTypeOrder(b.descriptorType); + { + auto &block = data.descriptorBlocks.emplace_back(order, b.stageFlags, b.count); + block.offset = b.binding; + block.descriptors.emplace_back(nameID, type, b.count); + } + { + auto iter = data.bindingMap.find(nameID); + if (iter != data.bindingMap.end()) { + CC_LOG_ERROR("Duplicate descriptor name: %s", name.data()); + } + data.bindingMap.emplace(nameID, b.binding); + } + const auto &v = source.blocks.at(ccstd::string(name)); + data.uniformBlocks.emplace(nameID, v); + } +} + +ShaderProgramData &buildProgramData( + const ccstd::string &programName, + const IShaderInfo &srcShaderInfo, + LayoutGraphData &lg, + RenderPhaseData &phase, + bool fixedLocal, + boost::container::pmr::memory_resource *scratch) { + // add shader + auto shaderID = static_cast(phase.shaderPrograms.size()); + phase.shaderIndex.emplace(programName, shaderID); + auto &programData = phase.shaderPrograms.emplace_back(); + + // build per-batch + { + auto res = programData.layout.descriptorSets.emplace( + std::piecewise_construct, + std::forward_as_tuple(UpdateFrequency::PER_BATCH), + std::forward_as_tuple()); + CC_ENSURES(res.second); + + auto &setData = res.first->second; + + makeDescriptorSetLayoutData( + lg, UpdateFrequency::PER_BATCH, + setIndex(UpdateFrequency::PER_BATCH), + srcShaderInfo.descriptors[static_cast(UpdateFrequency::PER_BATCH)], + setData.descriptorSetLayoutData, scratch); + initializeDescriptorSetLayoutInfo( + setData.descriptorSetLayoutData, setData.descriptorSetLayoutInfo); + } + + // build per-instance + if (fixedLocal) { + auto res = programData.layout.descriptorSets.emplace( + std::piecewise_construct, + std::forward_as_tuple(UpdateFrequency::PER_INSTANCE), + std::forward_as_tuple()); + CC_ENSURES(res.second); + auto &setData = res.first->second; + auto &perInstance = setData.descriptorSetLayoutData; + makeLocalDescriptorSetLayoutData(lg, pipeline::localDescriptorSetLayout, perInstance); + initializeDescriptorSetLayoutInfo( + setData.descriptorSetLayoutData, + setData.descriptorSetLayoutInfo); + if (pipeline::localDescriptorSetLayout.bindings.size() != setData.descriptorSetLayoutInfo.bindings.size()) { + CC_LOG_ERROR("Mismatched local descriptor set layout"); + } else { + for (uint32_t i = 0; i != pipeline::localDescriptorSetLayout.bindings.size(); ++i) { + const auto &a = pipeline::localDescriptorSetLayout.bindings[i]; + const auto &b = setData.descriptorSetLayoutInfo.bindings[i]; + if (a.binding != b.binding || + a.descriptorType != b.descriptorType || + a.count != b.count || + a.stageFlags != b.stageFlags) { + CC_LOG_ERROR("Mismatched local descriptor set layout"); + } + } + } + } else { + auto res = programData.layout.descriptorSets.emplace( + std::piecewise_construct, + std::forward_as_tuple(UpdateFrequency::PER_INSTANCE), + std::forward_as_tuple()); + CC_ENSURES(res.second); + auto &setData = res.first->second; + makeDescriptorSetLayoutData( + lg, UpdateFrequency::PER_INSTANCE, + setIndex(UpdateFrequency::PER_INSTANCE), + srcShaderInfo.descriptors[static_cast(UpdateFrequency::PER_INSTANCE)], + setData.descriptorSetLayoutData, scratch); + initializeDescriptorSetLayoutInfo( + setData.descriptorSetLayoutData, + setData.descriptorSetLayoutInfo); + } + + return programData; +} + +void populateMergedShaderInfo( + const ccstd::pmr::vector &valueNames, + const DescriptorSetLayoutData &layout, uint32_t set, + gfx::ShaderInfo &shaderInfo, ccstd::pmr::vector &blockSizes) { + for (const auto &descriptorBlock : layout.descriptorBlocks) { + auto binding = descriptorBlock.offset; + switch (descriptorBlock.type) { + case DescriptorTypeOrder::UNIFORM_BUFFER: + for (const auto &block : descriptorBlock.descriptors) { + auto iter = layout.uniformBlocks.find(block.descriptorID); + + if (iter == layout.uniformBlocks.end()) { + CC_LOG_ERROR("Failed to find uniform block in layout"); + continue; + } + const auto &uniformBlock = iter->second; + blockSizes.emplace_back(getSize(uniformBlock.members)); + shaderInfo.blocks.emplace_back( + gfx::UniformBlock{ + set, + binding, + ccstd::string(valueNames.at(block.descriptorID.value)), + uniformBlock.members, + 1, + } // count is always 1 for UniformBlock + ); + ++binding; + } + if (binding != descriptorBlock.offset + descriptorBlock.capacity) { + CC_LOG_ERROR("Uniform buffer binding mismatch for set"); + } + break; + case DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER: + // not implemented yet + break; + case DescriptorTypeOrder::SAMPLER_TEXTURE: + for (const auto &tex : descriptorBlock.descriptors) { + shaderInfo.samplerTextures.emplace_back(gfx::UniformSamplerTexture{ + set, + binding, + ccstd::string(valueNames.at(tex.descriptorID.value)), + tex.type, + tex.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::SAMPLER: + for (const auto &sampler : descriptorBlock.descriptors) { + shaderInfo.samplers.emplace_back(gfx::UniformSampler{ + set, + binding, + ccstd::string(valueNames.at(sampler.descriptorID.value)), + sampler.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::TEXTURE: + for (const auto &texture : descriptorBlock.descriptors) { + shaderInfo.textures.emplace_back(gfx::UniformTexture{ + set, + binding, + ccstd::string(valueNames.at(texture.descriptorID.value)), + texture.type, + texture.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::STORAGE_BUFFER: + for (const auto &buffer : descriptorBlock.descriptors) { + shaderInfo.buffers.emplace_back(gfx::UniformStorageBuffer{ + set, + binding, + ccstd::string(valueNames.at(buffer.descriptorID.value)), + 1, + gfx::MemoryAccessBit::READ_WRITE, /*buffer.memoryAccess*/ + }); + // effect compiler guarantees buffer count = 1 + ++binding; + } + break; + case DescriptorTypeOrder::DYNAMIC_STORAGE_BUFFER: + // not implemented yet + break; + case DescriptorTypeOrder::STORAGE_IMAGE: + for (const auto &image : descriptorBlock.descriptors) { + shaderInfo.images.emplace_back(gfx::UniformStorageImage{ + set, + binding, + ccstd::string(valueNames.at(image.descriptorID.value)), + image.type, + image.count, + gfx::MemoryAccessBit::READ_WRITE, /*image.memoryAccess*/ + }); + ++binding; + } + break; + case DescriptorTypeOrder::INPUT_ATTACHMENT: + for (const auto &subpassInput : descriptorBlock.descriptors) { + shaderInfo.subpassInputs.emplace_back(gfx::UniformInputAttachment{ + set, + binding, + ccstd::string(valueNames.at(subpassInput.descriptorID.value)), + subpassInput.count, + }); + ++binding; + } + break; + default: + CC_LOG_ERROR("Unknown descriptor type"); + } + } +} + +// add descriptor to size-reserved descriptor set +void populateGroupedShaderInfo( + const DescriptorSetLayoutData &layout, + const IDescriptorInfo &descriptorInfo, uint32_t set, + gfx::ShaderInfo &shaderInfo, + ccstd::pmr::vector &blockSizes) { + for (const auto &descriptorBlock : layout.descriptorBlocks) { + const auto visibility = descriptorBlock.visibility; + auto binding = descriptorBlock.offset; + + switch (descriptorBlock.type) { + case DescriptorTypeOrder::UNIFORM_BUFFER: + for (const auto &block : descriptorInfo.blocks) { + if (block.stageFlags != visibility) { + continue; + } + blockSizes.emplace_back(getSize(block.members)); + shaderInfo.blocks.emplace_back( + gfx::UniformBlock{ + set, + binding, + block.name, + block.members, + 1, + } // count is always 1 for UniformBlock + ); + ++binding; + } + break; + case DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER: + // not implemented yet + break; + case DescriptorTypeOrder::SAMPLER_TEXTURE: + for (const auto &tex : descriptorInfo.samplerTextures) { + if (tex.stageFlags != visibility) { + continue; + } + shaderInfo.samplerTextures.emplace_back(gfx::UniformSamplerTexture{ + set, + binding, + tex.name, + tex.type, + tex.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::SAMPLER: + for (const auto &sampler : descriptorInfo.samplers) { + if (sampler.stageFlags != visibility) { + continue; + } + shaderInfo.samplers.emplace_back(gfx::UniformSampler{ + set, + binding, + sampler.name, + sampler.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::TEXTURE: + for (const auto &texture : descriptorInfo.textures) { + if (texture.stageFlags != visibility) { + continue; + } + shaderInfo.textures.emplace_back(gfx::UniformTexture{ + set, + binding, + texture.name, + texture.type, + texture.count, + }); + ++binding; + } + break; + case DescriptorTypeOrder::STORAGE_BUFFER: + for (const auto &buffer : descriptorInfo.buffers) { + if (buffer.stageFlags != visibility) { + continue; + } + shaderInfo.buffers.emplace_back(gfx::UniformStorageBuffer{ + set, + binding, + buffer.name, + 1, + buffer.memoryAccess, + }); // effect compiler guarantees buffer count = 1 + ++binding; + } + break; + case DescriptorTypeOrder::DYNAMIC_STORAGE_BUFFER: + // not implemented yet + break; + case DescriptorTypeOrder::STORAGE_IMAGE: + for (const auto &image : descriptorInfo.images) { + if (image.stageFlags != visibility) { + continue; + } + shaderInfo.images.emplace_back(gfx::UniformStorageImage{ + set, + binding, + image.name, + image.type, + image.count, + image.memoryAccess, + }); + ++binding; + } + break; + case DescriptorTypeOrder::INPUT_ATTACHMENT: + for (const auto &subpassInput : descriptorInfo.subpassInputs) { + if (subpassInput.stageFlags != visibility) { + continue; + } + shaderInfo.subpassInputs.emplace_back(gfx::UniformInputAttachment{ + set, + subpassInput.binding, + subpassInput.name, + subpassInput.count, + }); + ++binding; + } + break; + default: + CC_LOG_ERROR("Unknown descriptor type"); + } + } +} + +// add fixed local descriptors to gfx.ShaderInfo +void populateLocalShaderInfo( + const IDescriptorInfo &target, + const pipeline::DescriptorSetLayoutInfos &source, + gfx::ShaderInfo &shaderInfo, ccstd::pmr::vector &blockSizes) { + const auto set = setIndex(UpdateFrequency::PER_INSTANCE); + for (const auto &block : target.blocks) { + auto blockIter = source.blocks.find(block.name); + if (blockIter == source.blocks.end()) { + continue; + } + const auto &info = blockIter->second; + + const gfx::DescriptorSetLayoutBinding *pBinding = nullptr; + for (const auto &b : source.bindings) { + if (b.binding == info.binding) { + pBinding = &b; + } + } + if (!pBinding || !(pBinding->descriptorType & gfx::DESCRIPTOR_BUFFER_TYPE)) { + CC_LOG_ERROR("builtin UBO not available !"); + continue; + } + + const auto &binding = *pBinding; + blockSizes.emplace_back(getSize(block.members)); + shaderInfo.blocks.emplace_back( + gfx::UniformBlock{ + set, + binding.binding, + block.name, + block.members, + 1, + }); // effect compiler guarantees block count = 1 + } + for (const auto &samplerTexture : target.samplerTextures) { + auto iter = source.samplers.find(samplerTexture.name); + if (iter == source.samplers.end()) { + CC_LOG_ERROR("builtin sampler not available !"); + continue; + } + const auto &info = iter->second; + + const gfx::DescriptorSetLayoutBinding *pBinding = nullptr; + for (const auto &b : source.bindings) { + if (b.binding == info.binding) { + pBinding = &b; + } + } + if (!pBinding || !(pBinding->descriptorType & gfx::DESCRIPTOR_SAMPLER_TYPE)) { + CC_LOG_ERROR("builtin sampler not available !"); + continue; + } + const auto &binding = *pBinding; + shaderInfo.samplerTextures.emplace_back(gfx::UniformSamplerTexture{ + set, + binding.binding, + samplerTexture.name, + samplerTexture.type, + samplerTexture.count, + }); + } +} + +void makeShaderInfo( + LayoutGraphData &lg, + const PipelineLayoutData &passLayouts, // NOLINT(bugprone-easily-swappable-parameters) + const PipelineLayoutData &phaseLayouts, + const IShaderInfo &srcShaderInfo, + const ShaderProgramData *programData, + bool fixedLocal, + gfx::ShaderInfo &shaderInfo, + ccstd::pmr::vector &blockSizes) { + { // pass + auto iter = passLayouts.descriptorSets.find(UpdateFrequency::PER_PASS); + if (iter != passLayouts.descriptorSets.end()) { + populateMergedShaderInfo( + lg.valueNames, iter->second.descriptorSetLayoutData, + setIndex(UpdateFrequency::PER_PASS), + shaderInfo, blockSizes); + } + } + { // phase + auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_PHASE); + if (iter != passLayouts.descriptorSets.end()) { + populateMergedShaderInfo( + lg.valueNames, iter->second.descriptorSetLayoutData, + setIndex(UpdateFrequency::PER_PHASE), + shaderInfo, blockSizes); + } + } + { // batch + const auto &batchInfo = srcShaderInfo.descriptors.at( + static_cast(UpdateFrequency::PER_BATCH)); + if (programData) { + auto iter = programData->layout.descriptorSets.find(UpdateFrequency::PER_BATCH); + if (iter != programData->layout.descriptorSets.end()) { + populateMergedShaderInfo( + lg.valueNames, iter->second.descriptorSetLayoutData, + setIndex(UpdateFrequency::PER_BATCH), + shaderInfo, blockSizes); + } + } else { + auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_BATCH); + if (iter != phaseLayouts.descriptorSets.end()) { + populateGroupedShaderInfo( + iter->second.descriptorSetLayoutData, + batchInfo, setIndex(UpdateFrequency::PER_BATCH), + shaderInfo, blockSizes); + } + } + } + { // instance + const auto &instanceInfo = srcShaderInfo.descriptors.at( + static_cast(UpdateFrequency::PER_INSTANCE)); + if (programData) { + if (fixedLocal) { + populateLocalShaderInfo( + instanceInfo, + pipeline::localDescriptorSetLayout, shaderInfo, blockSizes); + } else { + auto iter = programData->layout.descriptorSets.find( + UpdateFrequency::PER_INSTANCE); + if (iter != programData->layout.descriptorSets.end()) { + populateMergedShaderInfo( + lg.valueNames, iter->second.descriptorSetLayoutData, + setIndex(UpdateFrequency::PER_INSTANCE), + shaderInfo, blockSizes); + } + } + } else { + auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_INSTANCE); + if (iter != phaseLayouts.descriptorSets.end()) { + populateGroupedShaderInfo( + iter->second.descriptorSetLayoutData, + instanceInfo, setIndex(UpdateFrequency::PER_INSTANCE), + shaderInfo, blockSizes); + } + } + } +} + +// overwrite IProgramInfo using gfx.ShaderInfo +void overwriteProgramBlockInfo(const gfx::ShaderInfo &shaderInfo, IProgramInfo &programInfo) { + const auto set = setIndex(UpdateFrequency::PER_BATCH); + for (auto &block : programInfo.blocks) { + auto found = false; + for (const auto &src : shaderInfo.blocks) { + if (src.set != set) { + continue; + } + if (src.name == block.name) { + block.binding = src.binding; + found = true; + break; + } + } + if (!found) { + CC_LOG_ERROR("block not found in shaderInfo"); + } + } +} + +gfx::DescriptorSetLayout *getDescriptorSetLayout( + const LayoutGraphData &lg, + uint32_t passID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters) + if (rate < UpdateFrequency::PER_PASS) { + const auto &phaseData = get(LayoutGraphData::Layout, lg, phaseID); + auto iter = phaseData.descriptorSets.find(rate); + if (iter != phaseData.descriptorSets.end()) { + const auto &data = iter->second; + if (!data.descriptorSetLayout) { + CC_LOG_ERROR("descriptor set layout not initialized"); + return nullptr; + } + return data.descriptorSetLayout; + } + return nullptr; + } + + CC_EXPECTS(rate == UpdateFrequency::PER_PASS); + CC_EXPECTS(passID == parent(phaseID, lg)); + + const auto &passData = get(LayoutGraphData::Layout, lg, passID); + auto iter = passData.descriptorSets.find(rate); + if (iter != passData.descriptorSets.end()) { + const auto &data = iter->second; + if (!data.descriptorSetLayout) { + CC_LOG_ERROR("descriptor set layout not initialized"); + return nullptr; + } + return data.descriptorSetLayout; + } + return nullptr; +} + +gfx::DescriptorSetLayout *getProgramDescriptorSetLayout( + gfx::Device *device, + LayoutGraphData &lg, uint32_t phaseID, + const ccstd::pmr::string &programName, UpdateFrequency rate) { + CC_EXPECTS(rate < UpdateFrequency::PER_PHASE); + auto &phase = get(RenderPhaseTag{}, phaseID, lg); + const auto iter = phase.shaderIndex.find(programName); + if (iter == phase.shaderIndex.end()) { + return nullptr; + } + const auto programID = iter->second; + auto &programData = phase.shaderPrograms.at(programID); + + auto iter2 = programData.layout.descriptorSets.find(rate); + if (iter2 == programData.layout.descriptorSets.end()) { + return nullptr; + } + auto &layout = iter2->second; + if (layout.descriptorSetLayout) { + return layout.descriptorSetLayout; + } + layout.descriptorSetLayout = device->createDescriptorSetLayout(layout.descriptorSetLayoutInfo); + return layout.descriptorSetLayout; +} + +// get descriptor set from LayoutGraphData (not from ProgramData) +const gfx::DescriptorSetLayout &getOrCreateDescriptorSetLayout( + const NativeProgramLibrary &lib, + const LayoutGraphData &lg, + uint32_t passID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters) + if (rate < UpdateFrequency::PER_PASS) { + const auto &phaseData = get(LayoutGraphData::Layout, lg, phaseID); + auto iter = phaseData.descriptorSets.find(rate); + if (iter != phaseData.descriptorSets.end()) { + const auto &data = iter->second; + if (!data.descriptorSetLayout) { + CC_LOG_ERROR("descriptor set layout not initialized"); + return *lib.emptyDescriptorSetLayout; + } + return *data.descriptorSetLayout; + } + return *lib.emptyDescriptorSetLayout; + } + + CC_EXPECTS(rate == UpdateFrequency::PER_PASS); + CC_EXPECTS(passID == parent(phaseID, lg)); + + const auto &passData = get(LayoutGraphData::Layout, lg, passID); + const auto iter = passData.descriptorSets.find(rate); + if (iter != passData.descriptorSets.end()) { + const auto &data = iter->second; + if (!data.descriptorSetLayout) { + CC_LOG_ERROR("descriptor set layout not initialized"); + return *lib.emptyDescriptorSetLayout; + } + return *data.descriptorSetLayout; + } + return *lib.emptyDescriptorSetLayout; +} + +// get or create PerProgram gfx.DescriptorSetLayout +const gfx::DescriptorSetLayout &getOrCreateProgramDescriptorSetLayout( + const NativeProgramLibrary &lib, + gfx::Device *device, + LayoutGraphData &lg, uint32_t phaseID, + const ccstd::pmr::string &programName, UpdateFrequency rate) { + CC_EXPECTS(rate < UpdateFrequency::PER_PHASE); + auto &phase = get(RenderPhaseTag{}, phaseID, lg); + const auto iter = phase.shaderIndex.find(programName); + if (iter == phase.shaderIndex.end()) { + return *lib.emptyDescriptorSetLayout; + } + const auto programID = iter->second; + auto &programData = phase.shaderPrograms.at(programID); + const auto iter2 = programData.layout.descriptorSets.find(rate); + if (iter2 == programData.layout.descriptorSets.end()) { + return *lib.emptyDescriptorSetLayout; + } + auto &layout = iter2->second; + if (layout.descriptorSetLayout) { + return *layout.descriptorSetLayout; + } + layout.descriptorSetLayout = device->createDescriptorSetLayout(layout.descriptorSetLayoutInfo); + return *layout.descriptorSetLayout; +} + +} // namespace + +void NativeProgramLibrary::init(gfx::Device *device) { + emptyDescriptorSetLayout = device->createDescriptorSetLayout({}); + emptyPipelineLayout = device->createPipelineLayout({}); +} + +void NativeProgramLibrary::destroy() { + emptyDescriptorSetLayout.reset(); + emptyPipelineLayout.reset(); +} + +void NativeProgramLibrary::addEffect(EffectAsset *effectAssetIn) { + auto &lg = layoutGraph; + boost::container::pmr::memory_resource *scratch = &unsycPool; + const auto &effect = *effectAssetIn; + for (const auto &tech : effect._techniques) { + for (const auto &pass : tech.passes) { + const auto &programName = pass.program; + const auto [passID, phaseID, pShaderInfo, shaderID] = + getEffectShader(lg, effect, pass); + if (pShaderInfo == nullptr || validateShaderInfo(*pShaderInfo)) { + CC_LOG_ERROR("program not found"); + continue; + } + const auto &srcShaderInfo = *pShaderInfo; + CC_ENSURES(passID != INVALID_ID && phaseID != INVALID_ID); + const auto &passLayout = get(LayoutGraphData::Layout, lg, passID); + const auto &phaseLayout = get(LayoutGraphData::Layout, lg, phaseID); + + // programs + auto iter = this->phases.find(phaseID); + if (iter == this->phases.end()) { + iter = this->phases.emplace(std::piecewise_construct, + std::forward_as_tuple(phaseID), + std::forward_as_tuple()) + .first; + } + auto &phasePrograms = iter->second.programInfos; + auto alloc = phasePrograms.get_allocator(); + + // build program + auto programInfo = makeProgramInfo(effect._name, srcShaderInfo); + + // collect program descriptors + ShaderProgramData *programData = nullptr; + if (!mergeHighFrequency) { + auto &phase = get(RenderPhaseTag{}, phaseID, lg); + buildProgramData(programName, srcShaderInfo, lg, phase, fixedLocal, scratch); + } + + // shaderInfo and blockSizes + gfx::ShaderInfo shaderInfo; + ccstd::pmr::vector blockSizes(alloc); + makeShaderInfo(lg, passLayout, phaseLayout, srcShaderInfo, programData, + fixedLocal, shaderInfo, blockSizes); + + // overwrite programInfo + overwriteProgramBlockInfo(shaderInfo, programInfo); + + // handle map + auto handleMap = genHandles(shaderInfo); + + // attributes + ccstd::pmr::vector attributes(alloc); + for (const auto &attr : programInfo.attributes) { + attributes.emplace_back(gfx::Attribute{ + attr.name, + attr.format, + attr.isNormalized, + 0, + attr.isInstanced, + attr.location, + }); + } + + // create programInfo + auto res = phasePrograms.emplace( + std::piecewise_construct, + std::forward_as_tuple(srcShaderInfo.name), + std::forward_as_tuple( + std::move(programInfo), + std::move(shaderInfo), + std::move(attributes), + std::move(blockSizes), + std::move(handleMap))); + CC_ENSURES(res.second); + } + } +} + +void NativeProgramLibrary::precompileEffect(gfx::Device *device, EffectAsset *effectAsset) { + // noop +} + +ccstd::string NativeProgramLibrary::getKey( + uint32_t phaseID, const ccstd::pmr::string &programName, + const MacroRecord &defines) const { + auto iter = phases.find(phaseID); + if (iter == phases.end()) { + CC_LOG_ERROR("phase not found"); + return ""; + } + const auto &phase = iter->second; + auto iter2 = phase.programInfos.find(programName); + if (iter2 == phase.programInfos.end()) { + CC_LOG_ERROR("program not found"); + return ""; + } + const auto &info = iter2->second; + return getVariantKey(info.programInfo, defines); +} + +const gfx::PipelineLayout &NativeProgramLibrary::getPipelineLayout( + gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) { + if (mergeHighFrequency) { + CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); + const auto &layout = get(RenderPhaseTag{}, phaseID, layoutGraph); + return *layout.pipelineLayout; + } + auto &lg = layoutGraph; + auto &phase = get(RenderPhaseTag{}, phaseID, lg); + const auto iter = phase.shaderIndex.find(programName); + if (iter == phase.shaderIndex.end()) { + return *emptyPipelineLayout; + } + const auto programID = iter->second; + auto &programData = phase.shaderPrograms.at(programID); + if (programData.pipelineLayout) { + return *programData.pipelineLayout; + } + + // get pass + const auto passID = parent(phaseID, lg); + if (passID == LayoutGraphData::null_vertex()) { + return *emptyPipelineLayout; + } + // create pipeline layout + gfx::PipelineLayoutInfo info{}; + auto *passSet = getDescriptorSetLayout(lg, passID, phaseID, UpdateFrequency::PER_PASS); + if (passSet) { + info.setLayouts.emplace_back(passSet); + } + auto *phaseSet = getDescriptorSetLayout(lg, passID, phaseID, UpdateFrequency::PER_PHASE); + if (phaseSet) { + info.setLayouts.emplace_back(phaseSet); + } + auto *batchSet = getProgramDescriptorSetLayout( + device, lg, phaseID, programName, UpdateFrequency::PER_BATCH); + if (batchSet) { + info.setLayouts.emplace_back(batchSet); + } + auto *instanceSet = getProgramDescriptorSetLayout( + device, lg, phaseID, programName, UpdateFrequency::PER_INSTANCE); + if (instanceSet) { + info.setLayouts.emplace_back(instanceSet); + } + programData.pipelineLayout = device->createPipelineLayout(info); + return *programData.pipelineLayout; +} + +const gfx::DescriptorSetLayout &NativeProgramLibrary::getMaterialDescriptorSetLayout( + gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) { + if (mergeHighFrequency) { + CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); + const auto passID = parent(phaseID, layoutGraph); + return getOrCreateDescriptorSetLayout( + *this, layoutGraph, passID, phaseID, UpdateFrequency::PER_BATCH); + } + return getOrCreateProgramDescriptorSetLayout( + *this, device, layoutGraph, phaseID, programName, UpdateFrequency::PER_BATCH); +} + +const gfx::DescriptorSetLayout &NativeProgramLibrary::getLocalDescriptorSetLayout( + gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) { + if (mergeHighFrequency) { + CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); + const auto passID = parent(phaseID, layoutGraph); + return getOrCreateDescriptorSetLayout( + *this, layoutGraph, passID, phaseID, UpdateFrequency::PER_INSTANCE); + } + return getOrCreateProgramDescriptorSetLayout( + *this, device, layoutGraph, phaseID, programName, UpdateFrequency::PER_INSTANCE); +} + +const IProgramInfo &NativeProgramLibrary::getProgramInfo( + uint32_t phaseID, const ccstd::pmr::string &programName) const { + const auto &group = phases.at(phaseID); + return group.programInfos.at(programName).programInfo; +} + +const gfx::ShaderInfo &NativeProgramLibrary::getShaderInfo( + uint32_t phaseID, const ccstd::pmr::string &programName) const { + const auto &group = phases.at(phaseID); + return group.programInfos.at(programName).shaderInfo; +} + +ProgramProxy *NativeProgramLibrary::getProgramVariant( + gfx::Device *device, uint32_t phaseID, const ccstd::string &name, + const MacroRecord &defines, const ccstd::pmr::string *key0) const { + auto iter = phases.find(phaseID); + if (iter == phases.end()) { + CC_LOG_ERROR("phase not found"); + return nullptr; + } + const auto &phase = iter->second; + auto iter2 = phase.programInfos.find(std::string_view{name}); + if (iter2 == phase.programInfos.end()) { + CC_LOG_ERROR("program not found"); + return nullptr; + } + const auto &info = iter2->second; + + const auto &programInfo = info.programInfo; + + std::string_view key; + ccstd::string key1; + + if (key0 == nullptr) { + key1 = getVariantKey(programInfo, defines); + key = key1; + } else { + key = *key0; + } + + auto iter3 = phase.programHosts.find(key); + if (iter3 != phase.programHosts.end()) { + return new NativeProgramProxy(iter3->second.program); + } + + std::ignore = device; + std::ignore = phaseID; + std::ignore = name; + std::ignore = defines; + std::ignore = key; + return nullptr; +} + +const ccstd::pmr::vector &NativeProgramLibrary::getBlockSizes( + uint32_t phaseID, const ccstd::pmr::string &programName) const { + std::ignore = phaseID; + std::ignore = programName; + throw std::runtime_error("not implemented"); +} + +const Record &NativeProgramLibrary::getHandleMap( + uint32_t phaseID, const ccstd::pmr::string &programName) const { + std::ignore = phaseID; + std::ignore = programName; + throw std::runtime_error("not implemented"); +} + +uint32_t NativeProgramLibrary::getProgramID( + uint32_t phaseID, const ccstd::pmr::string &programName) { + std::ignore = phaseID; + std::ignore = programName; + throw std::runtime_error("not implemented"); +} + +uint32_t NativeProgramLibrary::getDescriptorNameID(const ccstd::pmr::string &name) { + std::ignore = name; + return 0xFFFFFFFF; +} + +const ccstd::pmr::string &NativeProgramLibrary::getDescriptorName(uint32_t nameID) { + std::ignore = nameID; + throw std::runtime_error("not implemented"); +} + +} // namespace render + +} // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp index 9a10f61b38..6fbd020552 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp @@ -1,12 +1,12 @@ #include #include -#include "DebugUtils.h" -#include "GraphView.h" #include "LayoutGraphGraphs.h" #include "NativePipelineGraphs.h" #include "NativePipelineTypes.h" +#include "RenderCommonNames.h" #include "RenderGraphGraphs.h" -#include "RenderGraphNames.h" +#include "details/DebugUtils.h" +#include "details/GraphView.h" #include "gfx-base/GFXDef-common.h" #include "pipeline/custom/RenderCommonTypes.h" #include "pipeline/custom/RenderGraphFwd.h" @@ -21,7 +21,7 @@ ccstd::string NativeRasterPassBuilder::getName() const { } void NativeRasterPassBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, passID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name}; } void NativeRasterPassBuilder::addRasterView(const ccstd::string &name, const RasterView &view) { @@ -51,7 +51,7 @@ ccstd::string NativeRasterQueueBuilder::getName() const { } void NativeRasterQueueBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, queueID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, queueID) = std::string_view{name}; } void NativeRasterQueueBuilder::addSceneOfCamera(scene::Camera *camera, LightInfo light, SceneFlags sceneFlags) { @@ -364,7 +364,7 @@ ccstd::string NativeComputeQueueBuilder::getName() const { } void NativeComputeQueueBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, queueID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, queueID) = std::string_view{name}; } void NativeComputeQueueBuilder::addDispatch(const ccstd::string &shader, uint32_t threadGroupCountX, uint32_t threadGroupCountY, uint32_t threadGroupCountZ) { @@ -443,7 +443,7 @@ ccstd::string NativeComputePassBuilder::getName() const { } void NativeComputePassBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, passID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name}; } void NativeComputePassBuilder::addComputeView(const ccstd::string &name, const ComputeView &view) { @@ -534,7 +534,7 @@ ccstd::string NativeMovePassBuilder::getName() const { } void NativeMovePassBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, passID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name}; } void NativeMovePassBuilder::addPair(const MovePair &pair) { @@ -547,7 +547,7 @@ ccstd::string NativeCopyPassBuilder::getName() const { } void NativeCopyPassBuilder::setName(const ccstd::string &name) { - get(RenderGraph::Name, *renderGraph, passID) = std::string_view(name); + get(RenderGraph::Name, *renderGraph, passID) = std::string_view{name}; } void NativeCopyPassBuilder::addPair(const CopyPair &pair) { diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp index d4f2e62db2..59668807d2 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp @@ -1,9 +1,9 @@ #include #include -#include "GslUtils.h" #include "NativePipelineTypes.h" #include "cocos/renderer/pipeline/Define.h" #include "cocos/renderer/pipeline/PipelineStateManager.h" +#include "details/GslUtils.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp similarity index 81% rename from native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp rename to native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp index 8b1c6122ed..a0da95dc61 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp @@ -24,15 +24,20 @@ ****************************************************************************/ #include "NativePipelineTypes.h" -#include "RenderInterfaceTypes.h" -#include "boost/container/pmr/global_resource.hpp" namespace cc { namespace render { -Pipeline* Factory::createPipeline() { - return ccnew NativePipeline(boost::container::pmr::get_default_resource()); +uint32_t NativeRenderingModule::getPassID(const ccstd::string &name) const { + std::ignore = name; + return LayoutGraphData::null_vertex(); +} + +uint32_t NativeRenderingModule::getPhaseID(uint32_t passID, const ccstd::string &name) const { + std::ignore = passID; + std::ignore = name; + return LayoutGraphData::null_vertex(); } } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index db988d875c..d93d901181 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -24,10 +24,10 @@ ****************************************************************************/ #include "NativePipelineTypes.h" -#include "Range.h" #include "RenderGraphGraphs.h" #include "RenderGraphTypes.h" #include "cocos/renderer/gfx-base/GFXDevice.h" +#include "details/Range.h" #include "gfx-base/GFXDef-common.h" #include "pipeline/custom/RenderCommonFwd.h" diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphJsb.cpp b/native/cocos/renderer/pipeline/custom/NativeTypes.cpp similarity index 50% rename from native/cocos/renderer/pipeline/custom/RenderGraphJsb.cpp rename to native/cocos/renderer/pipeline/custom/NativeTypes.cpp index 5328bb898b..362f553bd9 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphJsb.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeTypes.cpp @@ -29,49 +29,51 @@ * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= */ // clang-format off -#include "cocos/bindings/auto/jsb_gfx_auto.h" -#include "cocos/bindings/auto/jsb_scene_auto.h" -#include "cocos/renderer/pipeline/custom/JsbConversion.h" -#include "cocos/renderer/pipeline/custom/RenderGraphJsb.h" -#include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" +#include "NativeTypes.h" -bool nativevalue_to_se(const cc::render::ClearView &from, se::Value &to, se::Object *ctx) { // NOLINT - se::HandleObject obj(se::Object::createPlainObject()); - se::Value tmp; +namespace cc { - nativevalue_to_se(from.slotName, tmp, ctx); - obj->setProperty("slotName", tmp); +namespace render { - nativevalue_to_se(from.clearFlags, tmp, ctx); - obj->setProperty("clearFlags", tmp); +ProgramInfo::ProgramInfo(const allocator_type& alloc) noexcept +: attributes(alloc), + blockSizes(alloc) {} - nativevalue_to_se(from.clearColor, tmp, ctx); - obj->setProperty("clearColor", tmp); +ProgramInfo::ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector attributesIn, ccstd::pmr::vector blockSizesIn, Record handleMapIn, const allocator_type& alloc) noexcept +: programInfo(std::move(programInfoIn)), + shaderInfo(std::move(shaderInfoIn)), + attributes(std::move(attributesIn), alloc), + blockSizes(std::move(blockSizesIn), alloc), + handleMap(std::move(handleMapIn)) {} - to.setObject(obj); - return true; -} +ProgramInfo::ProgramInfo(ProgramInfo&& rhs, const allocator_type& alloc) +: programInfo(std::move(rhs.programInfo)), + shaderInfo(std::move(rhs.shaderInfo)), + attributes(std::move(rhs.attributes), alloc), + blockSizes(std::move(rhs.blockSizes), alloc), + handleMap(std::move(rhs.handleMap)) {} -template <> -bool sevalue_to_native(const se::Value &from, cc::render::ClearView *to, se::Object *ctx) { // NOLINT - SE_PRECONDITION2(from.isObject(), false, " Convert parameter to ClearView failed !"); +ProgramInfo::ProgramInfo(ProgramInfo const& rhs, const allocator_type& alloc) +: programInfo(rhs.programInfo), + shaderInfo(rhs.shaderInfo), + attributes(rhs.attributes, alloc), + blockSizes(rhs.blockSizes, alloc), + handleMap(rhs.handleMap) {} - auto *obj = const_cast(from.toObject()); - bool ok = true; - se::Value field; - obj->getProperty("slotName", &field, true); - if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->slotName), ctx); - } - obj->getProperty("clearFlags", &field, true); - if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->clearFlags), ctx); - } - obj->getProperty("clearColor", &field, true); - if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->clearColor), ctx); - } - return ok; -} +ProgramGroup::ProgramGroup(const allocator_type& alloc) noexcept +: programInfos(alloc), + programHosts(alloc) {} + +ProgramGroup::ProgramGroup(ProgramGroup&& rhs, const allocator_type& alloc) +: programInfos(std::move(rhs.programInfos), alloc), + programHosts(std::move(rhs.programHosts), alloc) {} + +ProgramGroup::ProgramGroup(ProgramGroup const& rhs, const allocator_type& alloc) +: programInfos(rhs.programInfos, alloc), + programHosts(rhs.programHosts, alloc) {} + +} // namespace render + +} // namespace cc // clang-format on diff --git a/native/cocos/renderer/pipeline/custom/NativeTypes.h b/native/cocos/renderer/pipeline/custom/NativeTypes.h new file mode 100644 index 0000000000..cd92938751 --- /dev/null +++ b/native/cocos/renderer/pipeline/custom/NativeTypes.h @@ -0,0 +1,102 @@ +/**************************************************************************** + Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +/** + * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= + * The following section is auto-generated. + * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= + */ +// clang-format off +#pragma once +#include "cocos/base/Ptr.h" +#include "cocos/base/std/container/string.h" +#include "cocos/base/std/hash/hash.h" +#include "cocos/renderer/core/ProgramLib.h" +#include "cocos/renderer/gfx-base/GFXRenderPass.h" +#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h" +#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" +#include "cocos/renderer/pipeline/custom/NativeFwd.h" +#include "cocos/renderer/pipeline/custom/RenderInterfaceTypes.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" + +namespace cc { + +namespace render { + +struct ProgramInfo { + using allocator_type = boost::container::pmr::polymorphic_allocator; + allocator_type get_allocator() const noexcept { // NOLINT + return {attributes.get_allocator().resource()}; + } + + ProgramInfo(const allocator_type& alloc) noexcept; // NOLINT + ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector attributesIn, ccstd::pmr::vector blockSizesIn, Record handleMapIn, const allocator_type& alloc) noexcept; + ProgramInfo(ProgramInfo&& rhs, const allocator_type& alloc); + ProgramInfo(ProgramInfo const& rhs, const allocator_type& alloc); + + ProgramInfo(ProgramInfo&& rhs) noexcept = default; + ProgramInfo(ProgramInfo const& rhs) = delete; + ProgramInfo& operator=(ProgramInfo&& rhs) = default; + ProgramInfo& operator=(ProgramInfo const& rhs) = default; + + IProgramInfo programInfo; + gfx::ShaderInfo shaderInfo; + ccstd::pmr::vector attributes; + ccstd::pmr::vector blockSizes; + Record handleMap; +}; + +struct ProgramHost { + ProgramHost() = default; + ProgramHost(IntrusivePtr programIn) noexcept // NOLINT + : program(std::move(programIn)) {} + + IntrusivePtr program; +}; + +struct ProgramGroup { + using allocator_type = boost::container::pmr::polymorphic_allocator; + allocator_type get_allocator() const noexcept { // NOLINT + return {programInfos.get_allocator().resource()}; + } + + ProgramGroup(const allocator_type& alloc) noexcept; // NOLINT + ProgramGroup(ProgramGroup&& rhs, const allocator_type& alloc); + ProgramGroup(ProgramGroup const& rhs, const allocator_type& alloc); + + ProgramGroup(ProgramGroup&& rhs) noexcept = default; + ProgramGroup(ProgramGroup const& rhs) = delete; + ProgramGroup& operator=(ProgramGroup&& rhs) = default; + ProgramGroup& operator=(ProgramGroup const& rhs) = default; + + PmrFlatMap programInfos; + PmrFlatMap programHosts; +}; + +} // namespace render + +} // namespace cc + +// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/PrivateTypes.h b/native/cocos/renderer/pipeline/custom/PrivateTypes.h index 55e9cf89ba..63ca5478dd 100644 --- a/native/cocos/renderer/pipeline/custom/PrivateTypes.h +++ b/native/cocos/renderer/pipeline/custom/PrivateTypes.h @@ -39,14 +39,14 @@ namespace cc { namespace render { -class ProgramProxy { +class ProgramProxy : public RefCounted { public: ProgramProxy() noexcept = default; ProgramProxy(ProgramProxy&& rhs) = delete; ProgramProxy(ProgramProxy const& rhs) = delete; ProgramProxy& operator=(ProgramProxy&& rhs) = delete; ProgramProxy& operator=(ProgramProxy const& rhs) = delete; - virtual ~ProgramProxy() noexcept = default; + ~ProgramProxy() noexcept override = default; virtual const ccstd::string &getName() const noexcept = 0; virtual gfx::Shader *getShader() const noexcept = 0; @@ -63,15 +63,18 @@ public: virtual void addEffect(EffectAsset *effectAsset) = 0; virtual void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) = 0; - virtual ccstd::pmr::string getKey(uint32_t phaseID, const ccstd::pmr::string &programName, const MacroRecord &defines) const = 0; - virtual const gfx::PipelineLayout &getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; - virtual const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; - virtual const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; + virtual ccstd::string getKey(uint32_t phaseID, const ccstd::pmr::string &programName, const MacroRecord &defines) const = 0; + virtual const gfx::PipelineLayout &getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0; + virtual const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0; + virtual const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0; virtual const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; virtual const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; virtual ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines, const ccstd::pmr::string *key) const = 0; virtual const ccstd::pmr::vector &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; virtual const Record &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0; + virtual uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) = 0; + virtual uint32_t getDescriptorNameID(const ccstd::pmr::string &name) = 0; + virtual const ccstd::pmr::string &getDescriptorName(uint32_t nameID) = 0; ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines) const { return getProgramVariant(device, phaseID, name, defines, nullptr); } diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp index 37177bd69f..9ec881b1e4 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp +++ b/native/cocos/renderer/pipeline/custom/RenderCommonJsb.cpp @@ -31,9 +31,9 @@ // clang-format off #include "cocos/bindings/auto/jsb_gfx_auto.h" #include "cocos/bindings/auto/jsb_scene_auto.h" -#include "cocos/renderer/pipeline/custom/JsbConversion.h" #include "cocos/renderer/pipeline/custom/RenderCommonJsb.h" #include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" +#include "cocos/renderer/pipeline/custom/details/JsbConversion.h" bool nativevalue_to_se(const cc::render::RasterView &from, se::Value &to, se::Object *ctx) { // NOLINT se::HandleObject obj(se::Object::createPlainObject()); diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonReflection.cpp b/native/cocos/renderer/pipeline/custom/RenderCommonReflection.cpp deleted file mode 100644 index 607451c174..0000000000 --- a/native/cocos/renderer/pipeline/custom/RenderCommonReflection.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#include "RenderCommonReflection.h" -#include "RenderCommonTypes.h" - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/RenderCommonSerialization.h b/native/cocos/renderer/pipeline/custom/RenderCommonSerialization.h index ef530ff08c..5f16f24a92 100644 --- a/native/cocos/renderer/pipeline/custom/RenderCommonSerialization.h +++ b/native/cocos/renderer/pipeline/custom/RenderCommonSerialization.h @@ -30,9 +30,9 @@ */ #pragma once #include "cocos/renderer/pipeline/custom/ArchiveTypes.h" -#include "cocos/renderer/pipeline/custom/Range.h" #include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" -#include "cocos/renderer/pipeline/custom/SerializationUtils.h" +#include "cocos/renderer/pipeline/custom/details/Range.h" +#include "cocos/renderer/pipeline/custom/details/SerializationUtils.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h b/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h index 0af81630d8..a6c3d10cc1 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphGraphs.h @@ -32,11 +32,10 @@ #pragma once #include #include -#include "cocos/renderer/pipeline/custom/GraphImpl.h" -#include "cocos/renderer/pipeline/custom/GslUtils.h" -#include "cocos/renderer/pipeline/custom/Overload.h" -#include "cocos/renderer/pipeline/custom/PathUtils.h" #include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" +#include "cocos/renderer/pipeline/custom/details/GraphImpl.h" +#include "cocos/renderer/pipeline/custom/details/Overload.h" +#include "cocos/renderer/pipeline/custom/details/PathUtils.h" namespace cc { @@ -210,49 +209,49 @@ inline void remove_vertex_value_impl(const ResourceGraph::VertexHandle& h, Resou ccstd::visit( overload( [&](const impl::ValueHandle& h) { - g.resources.erase(g.resources.begin() + std::ptrdiff_t(h.value)); + g.resources.erase(g.resources.begin() + static_cast(h.value)); if (h.value == g.resources.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.managedBuffers.erase(g.managedBuffers.begin() + std::ptrdiff_t(h.value)); + g.managedBuffers.erase(g.managedBuffers.begin() + static_cast(h.value)); if (h.value == g.managedBuffers.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.managedTextures.erase(g.managedTextures.begin() + std::ptrdiff_t(h.value)); + g.managedTextures.erase(g.managedTextures.begin() + static_cast(h.value)); if (h.value == g.managedTextures.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.buffers.erase(g.buffers.begin() + std::ptrdiff_t(h.value)); + g.buffers.erase(g.buffers.begin() + static_cast(h.value)); if (h.value == g.buffers.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.textures.erase(g.textures.begin() + std::ptrdiff_t(h.value)); + g.textures.erase(g.textures.begin() + static_cast(h.value)); if (h.value == g.textures.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.framebuffers.erase(g.framebuffers.begin() + std::ptrdiff_t(h.value)); + g.framebuffers.erase(g.framebuffers.begin() + static_cast(h.value)); if (h.value == g.framebuffers.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.swapchains.erase(g.swapchains.begin() + std::ptrdiff_t(h.value)); + g.swapchains.erase(g.swapchains.begin() + static_cast(h.value)); if (h.value == g.swapchains.size()) { return; } @@ -279,11 +278,11 @@ inline void remove_vertex(ResourceGraph::vertex_descriptor u, ResourceGraph& g) impl::removeVectorVertex(const_cast(g), u, ResourceGraph::directed_category{}); // remove components - g.names.erase(g.names.begin() + std::ptrdiff_t(u)); - g.descs.erase(g.descs.begin() + std::ptrdiff_t(u)); - g.traits.erase(g.traits.begin() + std::ptrdiff_t(u)); - g.states.erase(g.states.begin() + std::ptrdiff_t(u)); - g.samplerInfo.erase(g.samplerInfo.begin() + std::ptrdiff_t(u)); + g.names.erase(g.names.begin() + static_cast(u)); + g.descs.erase(g.descs.begin() + static_cast(u)); + g.traits.erase(g.traits.begin() + static_cast(u)); + g.states.erase(g.states.begin() + static_cast(u)); + g.samplerInfo.erase(g.samplerInfo.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) @@ -674,8 +673,8 @@ inline void remove_vertex(SubpassGraph::vertex_descriptor u, SubpassGraph& g) no impl::removeVectorVertex(const_cast(g), u, SubpassGraph::directed_category{}); // remove components - g.names.erase(g.names.begin() + std::ptrdiff_t(u)); - g.subpasses.erase(g.subpasses.begin() + std::ptrdiff_t(u)); + g.names.erase(g.names.begin() + static_cast(u)); + g.subpasses.erase(g.subpasses.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) @@ -3692,84 +3691,84 @@ inline void remove_vertex_value_impl(const RenderGraph::VertexHandle& h, RenderG ccstd::visit( overload( [&](const impl::ValueHandle& h) { - g.rasterPasses.erase(g.rasterPasses.begin() + std::ptrdiff_t(h.value)); + g.rasterPasses.erase(g.rasterPasses.begin() + static_cast(h.value)); if (h.value == g.rasterPasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.computePasses.erase(g.computePasses.begin() + std::ptrdiff_t(h.value)); + g.computePasses.erase(g.computePasses.begin() + static_cast(h.value)); if (h.value == g.computePasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.copyPasses.erase(g.copyPasses.begin() + std::ptrdiff_t(h.value)); + g.copyPasses.erase(g.copyPasses.begin() + static_cast(h.value)); if (h.value == g.copyPasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.movePasses.erase(g.movePasses.begin() + std::ptrdiff_t(h.value)); + g.movePasses.erase(g.movePasses.begin() + static_cast(h.value)); if (h.value == g.movePasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.presentPasses.erase(g.presentPasses.begin() + std::ptrdiff_t(h.value)); + g.presentPasses.erase(g.presentPasses.begin() + static_cast(h.value)); if (h.value == g.presentPasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.raytracePasses.erase(g.raytracePasses.begin() + std::ptrdiff_t(h.value)); + g.raytracePasses.erase(g.raytracePasses.begin() + static_cast(h.value)); if (h.value == g.raytracePasses.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.renderQueues.erase(g.renderQueues.begin() + std::ptrdiff_t(h.value)); + g.renderQueues.erase(g.renderQueues.begin() + static_cast(h.value)); if (h.value == g.renderQueues.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.scenes.erase(g.scenes.begin() + std::ptrdiff_t(h.value)); + g.scenes.erase(g.scenes.begin() + static_cast(h.value)); if (h.value == g.scenes.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.blits.erase(g.blits.begin() + std::ptrdiff_t(h.value)); + g.blits.erase(g.blits.begin() + static_cast(h.value)); if (h.value == g.blits.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.dispatches.erase(g.dispatches.begin() + std::ptrdiff_t(h.value)); + g.dispatches.erase(g.dispatches.begin() + static_cast(h.value)); if (h.value == g.dispatches.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.clearViews.erase(g.clearViews.begin() + std::ptrdiff_t(h.value)); + g.clearViews.erase(g.clearViews.begin() + static_cast(h.value)); if (h.value == g.clearViews.size()) { return; } impl::reindexVectorHandle(g._vertices, h.value); }, [&](const impl::ValueHandle& h) { - g.viewports.erase(g.viewports.begin() + std::ptrdiff_t(h.value)); + g.viewports.erase(g.viewports.begin() + static_cast(h.value)); if (h.value == g.viewports.size()) { return; } @@ -3785,10 +3784,10 @@ inline void remove_vertex(RenderGraph::vertex_descriptor u, RenderGraph& g) noex impl::removeVectorVertex(const_cast(g), u, RenderGraph::directed_category{}); // remove components - g.names.erase(g.names.begin() + std::ptrdiff_t(u)); - g.layoutNodes.erase(g.layoutNodes.begin() + std::ptrdiff_t(u)); - g.data.erase(g.data.begin() + std::ptrdiff_t(u)); - g.valid.erase(g.valid.begin() + std::ptrdiff_t(u)); + g.names.erase(g.names.begin() + static_cast(u)); + g.layoutNodes.erase(g.layoutNodes.begin() + static_cast(u)); + g.data.erase(g.data.begin() + static_cast(u)); + g.valid.erase(g.valid.begin() + static_cast(u)); } // MutablePropertyGraph(Vertex) diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphJsb.h b/native/cocos/renderer/pipeline/custom/RenderGraphJsb.h deleted file mode 100644 index d9d748ee53..0000000000 --- a/native/cocos/renderer/pipeline/custom/RenderGraphJsb.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#pragma once -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/renderer/pipeline/custom/RenderCommonJsb.h" -#include "cocos/renderer/pipeline/custom/RenderGraphFwd.h" - -bool nativevalue_to_se(const cc::render::ClearView &from, se::Value &to, se::Object *ctx); // NOLINT - -// if function overload is used, android build fails -template <> -bool sevalue_to_native(const se::Value &from, cc::render::ClearView *to, se::Object *ctx); // NOLINT - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphNames.h b/native/cocos/renderer/pipeline/custom/RenderGraphNames.h deleted file mode 100644 index c8332bebcc..0000000000 --- a/native/cocos/renderer/pipeline/custom/RenderGraphNames.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#pragma once -#include "cocos/renderer/pipeline/custom/RenderCommonNames.h" -#include "cocos/renderer/pipeline/custom/RenderGraphTypes.h" - -namespace cc { - -namespace render { - -inline const char* getName(const ResourceDesc& /*v*/) noexcept { return "ResourceDesc"; } -inline const char* getName(const ResourceTraits& /*v*/) noexcept { return "ResourceTraits"; } -inline const char* getName(const RenderSwapchain& /*v*/) noexcept { return "RenderSwapchain"; } -inline const char* getName(const ResourceStates& /*v*/) noexcept { return "ResourceStates"; } -inline const char* getName(const ManagedBuffer& /*v*/) noexcept { return "ManagedBuffer"; } -inline const char* getName(const ManagedTexture& /*v*/) noexcept { return "ManagedTexture"; } -inline const char* getName(const ManagedResource& /*v*/) noexcept { return "ManagedResource"; } -inline const char* getName(const ManagedTag& /*v*/) noexcept { return "Managed"; } -inline const char* getName(const ManagedBufferTag& /*v*/) noexcept { return "ManagedBuffer"; } -inline const char* getName(const ManagedTextureTag& /*v*/) noexcept { return "ManagedTexture"; } -inline const char* getName(const PersistentBufferTag& /*v*/) noexcept { return "PersistentBuffer"; } -inline const char* getName(const PersistentTextureTag& /*v*/) noexcept { return "PersistentTexture"; } -inline const char* getName(const FramebufferTag& /*v*/) noexcept { return "Framebuffer"; } -inline const char* getName(const SwapchainTag& /*v*/) noexcept { return "Swapchain"; } -inline const char* getName(const SamplerTag& /*v*/) noexcept { return "Sampler"; } -inline const char* getName(const ResourceGraph& /*v*/) noexcept { return "ResourceGraph"; } -inline const char* getName(const RasterSubpass& /*v*/) noexcept { return "RasterSubpass"; } -inline const char* getName(const SubpassGraph& /*v*/) noexcept { return "SubpassGraph"; } -inline const char* getName(const RasterPass& /*v*/) noexcept { return "RasterPass"; } -inline const char* getName(const ComputePass& /*v*/) noexcept { return "ComputePass"; } -inline const char* getName(const CopyPass& /*v*/) noexcept { return "CopyPass"; } -inline const char* getName(const MovePass& /*v*/) noexcept { return "MovePass"; } -inline const char* getName(const RaytracePass& /*v*/) noexcept { return "RaytracePass"; } -inline const char* getName(const QueueTag& /*v*/) noexcept { return "Queue"; } -inline const char* getName(const SceneTag& /*v*/) noexcept { return "Scene"; } -inline const char* getName(const DispatchTag& /*v*/) noexcept { return "Dispatch"; } -inline const char* getName(const BlitTag& /*v*/) noexcept { return "Blit"; } -inline const char* getName(const PresentTag& /*v*/) noexcept { return "Present"; } -inline const char* getName(const ClearTag& /*v*/) noexcept { return "Clear"; } -inline const char* getName(const ViewportTag& /*v*/) noexcept { return "Viewport"; } -inline const char* getName(const ClearView& /*v*/) noexcept { return "ClearView"; } -inline const char* getName(const RenderQueue& /*v*/) noexcept { return "RenderQueue"; } -inline const char* getName(const SceneData& /*v*/) noexcept { return "SceneData"; } -inline const char* getName(const Dispatch& /*v*/) noexcept { return "Dispatch"; } -inline const char* getName(const Blit& /*v*/) noexcept { return "Blit"; } -inline const char* getName(const Present& /*v*/) noexcept { return "Present"; } -inline const char* getName(const PresentPass& /*v*/) noexcept { return "PresentPass"; } -inline const char* getName(const RenderData& /*v*/) noexcept { return "RenderData"; } -inline const char* getName(const RenderGraph& /*v*/) noexcept { return "RenderGraph"; } - -} // namespace render - -} // namespace cc - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphReflection.cpp b/native/cocos/renderer/pipeline/custom/RenderGraphReflection.cpp deleted file mode 100644 index a5942f291e..0000000000 --- a/native/cocos/renderer/pipeline/custom/RenderGraphReflection.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#include "RenderGraphReflection.h" -#include "RenderGraphTypes.h" - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphReflection.h b/native/cocos/renderer/pipeline/custom/RenderGraphReflection.h deleted file mode 100644 index a945a96460..0000000000 --- a/native/cocos/renderer/pipeline/custom/RenderGraphReflection.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** - Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd. - - http://www.cocos.com - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated engine source code (the "Software"), a limited, - worldwide, royalty-free, non-assignable, revocable and non-exclusive license - to use Cocos Creator solely to develop games on your target platforms. You shall - not use Cocos Creator software for developing other software or tools that's - used for developing games. You are not granted to publish, distribute, - sublicense, and/or sell copies of Cocos Creator. - - The software or tools in this License Agreement are licensed, not sold. - Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -****************************************************************************/ - -/** - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - * The following section is auto-generated. - * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= - */ -// clang-format off -#pragma once -#include "cocos/renderer/pipeline/custom/RenderCommonReflection.h" -#include "cocos/renderer/pipeline/custom/RenderGraphFwd.h" - -// clang-format on diff --git a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h index 900b5bd1ae..393211ec8a 100644 --- a/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderGraphTypes.h @@ -45,11 +45,10 @@ #include "cocos/renderer/gfx-base/GFXSwapchain.h" #include "cocos/renderer/gfx-base/GFXTexture.h" #include "cocos/renderer/gfx-base/states/GFXSampler.h" -#include "cocos/renderer/pipeline/custom/GraphTypes.h" -#include "cocos/renderer/pipeline/custom/Map.h" #include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" #include "cocos/renderer/pipeline/custom/RenderGraphFwd.h" -#include "cocos/renderer/pipeline/custom/Set.h" +#include "cocos/renderer/pipeline/custom/details/GraphTypes.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" #include "cocos/scene/Camera.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h index 344b8e2dcb..f169138ddd 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceFwd.h @@ -56,6 +56,7 @@ class SceneTransversal; class LayoutGraphBuilder; class Pipeline; class PipelineBuilder; +class RenderingModule; class Factory; } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index 976cbf0b99..470ec359d2 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -325,8 +325,23 @@ public: virtual void setup(const ccstd::vector &cameras, Pipeline *pipeline) = 0; }; +class RenderingModule { +public: + RenderingModule() noexcept = default; + RenderingModule(RenderingModule&& rhs) = delete; + RenderingModule(RenderingModule const& rhs) = delete; + RenderingModule& operator=(RenderingModule&& rhs) = delete; + RenderingModule& operator=(RenderingModule const& rhs) = delete; + virtual ~RenderingModule() noexcept = default; + + virtual uint32_t getPassID(const ccstd::string &name) const = 0; + virtual uint32_t getPhaseID(uint32_t passID, const ccstd::string &name) const = 0; +}; + class Factory { public: + static RenderingModule* init(gfx::Device* deviceIn, const ccstd::vector& bufferIn); + static void destroy(RenderingModule* renderingModule) noexcept; static Pipeline *createPipeline(); }; diff --git a/native/cocos/renderer/pipeline/custom/DebugUtils.h b/native/cocos/renderer/pipeline/custom/details/DebugUtils.h similarity index 86% rename from native/cocos/renderer/pipeline/custom/DebugUtils.h rename to native/cocos/renderer/pipeline/custom/details/DebugUtils.h index 0f5862bfb4..a1049839f7 100644 --- a/native/cocos/renderer/pipeline/custom/DebugUtils.h +++ b/native/cocos/renderer/pipeline/custom/details/DebugUtils.h @@ -26,7 +26,7 @@ #pragma once #include #include -#include "base/std/container/string.h" +#include "cocos/base/std/container/string.h" namespace cc { @@ -69,18 +69,19 @@ inline void indent(ccstd::pmr::string& str) { } inline void unindent(ccstd::string& str) noexcept { - auto sz = str.size() < size_t(4) ? str.size() : size_t(4); + auto sz = str.size() < static_cast(4) ? str.size() : static_cast(4); str.erase(str.size() - sz); } inline void unindent(ccstd::pmr::string& str) noexcept { - auto sz = str.size() < size_t(4) ? str.size() : size_t(4); + auto sz = str.size() < static_cast(4) ? str.size() : static_cast(4); str.erase(str.size() - sz); } -inline void copyString(std::ostream& os, - std::string_view space, std::string_view str, // NOLINT(bugprone-easily-swappable-parameters) - bool append = false) { +inline void copyString( + std::ostream& os, + std::string_view space, std::string_view str, // NOLINT(bugprone-easily-swappable-parameters) + bool append = false) { std::istringstream iss{ccstd::string(str)}; ccstd::string line; int count = 0; @@ -117,9 +118,10 @@ inline void copyString(std::ostream& os, std::string_view str) { } } -inline void copyCppString(std::ostream& os, - std::string_view space, std::string_view str, // NOLINT(bugprone-easily-swappable-parameters) - bool append = false) { +inline void copyCppString( + std::ostream& os, + std::string_view space, std::string_view str, // NOLINT(bugprone-easily-swappable-parameters) + bool append = false) { std::istringstream iss{ccstd::string(str)}; ccstd::string line; int count = 0; @@ -132,7 +134,7 @@ inline void copyCppString(std::ostream& os, #if defined(_MSC_VER) && _MSC_VER < 1920 os << space << line << '\n'; #else - os << space.substr(0, std::max(size_t(4), space.size()) - 4) << line << "\n"; + os << space.substr(0, std::max(static_cast(4), space.size()) - 4) << line << "\n"; #endif } else { if (append) { diff --git a/native/cocos/renderer/pipeline/custom/GraphImpl.h b/native/cocos/renderer/pipeline/custom/details/GraphImpl.h similarity index 99% rename from native/cocos/renderer/pipeline/custom/GraphImpl.h rename to native/cocos/renderer/pipeline/custom/details/GraphImpl.h index 95296a4a92..9ef1d2ff47 100644 --- a/native/cocos/renderer/pipeline/custom/GraphImpl.h +++ b/native/cocos/renderer/pipeline/custom/details/GraphImpl.h @@ -28,10 +28,10 @@ #include #include #include -#include "base/std/container/vector.h" -#include "base/std/variant.h" -#include "renderer/pipeline/custom/GraphTypes.h" -#include "renderer/pipeline/custom/GslUtils.h" +#include "cocos/base/std/container/vector.h" +#include "cocos/base/std/variant.h" +#include "cocos/renderer/pipeline/custom/details/GraphTypes.h" +#include "cocos/renderer/pipeline/custom/details/GslUtils.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/GraphTypes.h b/native/cocos/renderer/pipeline/custom/details/GraphTypes.h similarity index 99% rename from native/cocos/renderer/pipeline/custom/GraphTypes.h rename to native/cocos/renderer/pipeline/custom/details/GraphTypes.h index 5c18218019..4e2f1fbe09 100644 --- a/native/cocos/renderer/pipeline/custom/GraphTypes.h +++ b/native/cocos/renderer/pipeline/custom/details/GraphTypes.h @@ -30,11 +30,11 @@ #include #include #include -#include "base/memory/Memory.h" -#include "base/std/container/list.h" -#include "base/std/container/string.h" -#include "base/std/variant.h" -#include "renderer/pipeline/custom/Overload.h" +#include "cocos/base/memory/Memory.h" +#include "cocos/base/std/container/list.h" +#include "cocos/base/std/container/string.h" +#include "cocos/base/std/variant.h" +#include "cocos/renderer/pipeline/custom/details/Overload.h" namespace boost { diff --git a/native/cocos/renderer/pipeline/custom/GraphView.h b/native/cocos/renderer/pipeline/custom/details/GraphView.h similarity index 100% rename from native/cocos/renderer/pipeline/custom/GraphView.h rename to native/cocos/renderer/pipeline/custom/details/GraphView.h diff --git a/native/cocos/renderer/pipeline/custom/GslUtils.h b/native/cocos/renderer/pipeline/custom/details/GslUtils.h similarity index 98% rename from native/cocos/renderer/pipeline/custom/GslUtils.h rename to native/cocos/renderer/pipeline/custom/details/GslUtils.h index ed43ca9428..9c5071897a 100644 --- a/native/cocos/renderer/pipeline/custom/GslUtils.h +++ b/native/cocos/renderer/pipeline/custom/details/GslUtils.h @@ -24,8 +24,8 @@ ****************************************************************************/ #pragma once -#include #include +#include "cocos/base/Macros.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/JsbConversion.h b/native/cocos/renderer/pipeline/custom/details/JsbConversion.h similarity index 95% rename from native/cocos/renderer/pipeline/custom/JsbConversion.h rename to native/cocos/renderer/pipeline/custom/details/JsbConversion.h index 97338cc1f1..6dc59ae5bd 100644 --- a/native/cocos/renderer/pipeline/custom/JsbConversion.h +++ b/native/cocos/renderer/pipeline/custom/details/JsbConversion.h @@ -24,11 +24,11 @@ ****************************************************************************/ #pragma once -#include "base/std/container/map.h" -#include "base/std/container/string.h" -#include "base/std/container/vector.h" -#include "bindings/manual/jsb_conversions.h" -#include "renderer/pipeline/custom/Map.h" +#include "cocos/base/std/container/map.h" +#include "cocos/base/std/container/string.h" +#include "cocos/base/std/container/vector.h" +#include "cocos/bindings/manual/jsb_conversions.h" +#include "cocos/renderer/pipeline/custom/details/Map.h" template inline bool nativevalue_to_se( // NOLINT(readability-identifier-naming) diff --git a/native/cocos/renderer/pipeline/custom/Map.h b/native/cocos/renderer/pipeline/custom/details/Map.h similarity index 97% rename from native/cocos/renderer/pipeline/custom/Map.h rename to native/cocos/renderer/pipeline/custom/details/Map.h index e8cb82b4e3..99b5058b1d 100644 --- a/native/cocos/renderer/pipeline/custom/Map.h +++ b/native/cocos/renderer/pipeline/custom/details/Map.h @@ -28,8 +28,8 @@ #include #include #include -#include "cocos/renderer/pipeline/custom/Pmr.h" -#include "cocos/renderer/pipeline/custom/Utility.h" +#include "cocos/renderer/pipeline/custom/details/Pmr.h" +#include "cocos/renderer/pipeline/custom/details/Utility.h" // for std::less<> the transparent comparator // see https://stackoverflow.com/questions/20317413/what-are-transparent-comparators diff --git a/native/cocos/renderer/pipeline/custom/Overload.h b/native/cocos/renderer/pipeline/custom/details/Overload.h similarity index 98% rename from native/cocos/renderer/pipeline/custom/Overload.h rename to native/cocos/renderer/pipeline/custom/details/Overload.h index 9607ab9e18..6566b6b4a1 100644 --- a/native/cocos/renderer/pipeline/custom/Overload.h +++ b/native/cocos/renderer/pipeline/custom/details/Overload.h @@ -24,12 +24,10 @@ ****************************************************************************/ #pragma once - -#include "boost/mp11/algorithm.hpp" -#include "cocos/base/std/variant.h" - +#include #include #include +#include "cocos/base/std/variant.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/PathUtils.h b/native/cocos/renderer/pipeline/custom/details/PathUtils.h similarity index 96% rename from native/cocos/renderer/pipeline/custom/PathUtils.h rename to native/cocos/renderer/pipeline/custom/details/PathUtils.h index 9904c3b5a4..93fd706924 100644 --- a/native/cocos/renderer/pipeline/custom/PathUtils.h +++ b/native/cocos/renderer/pipeline/custom/details/PathUtils.h @@ -25,10 +25,10 @@ #pragma once -#include #include #include -#include "base/std/container/array.h" +#include "cocos/base/std/container/array.h" +#include "cocos/renderer/pipeline/custom/details/GslUtils.h" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/Pmr.h b/native/cocos/renderer/pipeline/custom/details/Pmr.h similarity index 93% rename from native/cocos/renderer/pipeline/custom/Pmr.h rename to native/cocos/renderer/pipeline/custom/details/Pmr.h index 7f6223d54d..a48ad3f7d8 100644 --- a/native/cocos/renderer/pipeline/custom/Pmr.h +++ b/native/cocos/renderer/pipeline/custom/details/Pmr.h @@ -24,10 +24,10 @@ ****************************************************************************/ #pragma once +#include +#include +#include #include -#include "boost/container/pmr/global_resource.hpp" -#include "boost/container/pmr/polymorphic_allocator.hpp" -#include "boost/container/pmr/unsynchronized_pool_resource.hpp" namespace cc { diff --git a/native/cocos/renderer/pipeline/custom/Range.h b/native/cocos/renderer/pipeline/custom/details/Range.h similarity index 100% rename from native/cocos/renderer/pipeline/custom/Range.h rename to native/cocos/renderer/pipeline/custom/details/Range.h diff --git a/native/cocos/renderer/pipeline/custom/SerializationUtils.h b/native/cocos/renderer/pipeline/custom/details/SerializationUtils.h similarity index 100% rename from native/cocos/renderer/pipeline/custom/SerializationUtils.h rename to native/cocos/renderer/pipeline/custom/details/SerializationUtils.h diff --git a/native/cocos/renderer/pipeline/custom/Set.h b/native/cocos/renderer/pipeline/custom/details/Set.h similarity index 97% rename from native/cocos/renderer/pipeline/custom/Set.h rename to native/cocos/renderer/pipeline/custom/details/Set.h index a15338167c..1fc0537ab9 100644 --- a/native/cocos/renderer/pipeline/custom/Set.h +++ b/native/cocos/renderer/pipeline/custom/details/Set.h @@ -24,11 +24,12 @@ ****************************************************************************/ #pragma once -#include #include #include #include #include +#include "cocos/base/std/hash/hash_fwd.hpp" +#include "cocos/renderer/pipeline/custom/details/Utility.h" // for std::less<> the transparent comparator // see https://stackoverflow.com/questions/20317413/what-are-transparent-comparators diff --git a/native/cocos/renderer/pipeline/custom/Utility.h b/native/cocos/renderer/pipeline/custom/details/Utility.h similarity index 100% rename from native/cocos/renderer/pipeline/custom/Utility.h rename to native/cocos/renderer/pipeline/custom/details/Utility.h diff --git a/native/cocos/renderer/pipeline/custom/test/test.h b/native/cocos/renderer/pipeline/custom/test/test.h index 0db00c7742..2bd7878822 100644 --- a/native/cocos/renderer/pipeline/custom/test/test.h +++ b/native/cocos/renderer/pipeline/custom/test/test.h @@ -35,9 +35,9 @@ #include "../FGDispatcherTypes.h" #include "../LayoutGraphGraphs.h" #include "../NativePipelineTypes.h" -#include "../Range.h" #include "../RenderGraphGraphs.h" #include "../RenderGraphTypes.h" +#include "../details/Range.h" #include "GFXDeviceManager.h" #include "cocos/base/std/container/vector.h" #include "frame-graph/FrameGraph.h"