From 52bccdf738323a46bf99cc37a1cfc4d3c56d39d7 Mon Sep 17 00:00:00 2001 From: hyde zhou Date: Fri, 13 Jan 2023 14:02:46 +0800 Subject: [PATCH] [pipeline] refactor custom pipeline init (#14040) --- cocos/game/game.ts | 2 +- cocos/rendering/custom/define.ts | 4 +- cocos/rendering/custom/index.jsb.ts | 2 +- cocos/rendering/custom/index.ts | 2 +- cocos/rendering/custom/layout-graph-utils.ts | 6 +- cocos/rendering/custom/web-program-library.ts | 4 - .../global-descriptor-set-manager.ts | 7 +- cocos/rendering/pipeline-funcs.ts | 5 +- cocos/rendering/scene-culling.ts | 2 + native/cocos/2d/renderer/Batcher2d.cpp | 10 +- native/cocos/2d/renderer/Batcher2d.h | 2 +- native/cocos/2d/renderer/RenderDrawInfo.cpp | 2 +- native/cocos/2d/renderer/RenderDrawInfo.h | 2 +- native/cocos/bindings/auto/jsb_2d_auto.cpp | 2 +- .../cocos/bindings/auto/jsb_pipeline_auto.cpp | 72 +++-- native/cocos/bindings/auto/jsb_scene_auto.cpp | 2 +- native/cocos/core/assets/EffectAsset.cpp | 10 +- native/cocos/core/assets/EffectAsset.h | 2 + native/cocos/engine/Engine.cpp | 12 +- native/cocos/renderer/core/ProgramLib.cpp | 12 +- native/cocos/renderer/core/ProgramLib.h | 2 +- native/cocos/renderer/core/ProgramUtils.cpp | 11 + native/cocos/renderer/core/ProgramUtils.h | 2 + .../renderer/gfx-agent/DescriptorSetAgent.cpp | 2 +- .../cocos/renderer/gfx-base/GFXDef-common.h | 2 +- .../renderer/gfx-base/GFXDescriptorSet.h | 4 +- .../renderer/gfx-gles2/GLES2DescriptorSet.cpp | 2 +- .../renderer/gfx-gles3/GLES3DescriptorSet.cpp | 2 +- .../renderer/gfx-metal/MTLDescriptorSet.mm | 2 +- .../gfx-validator/DescriptorSetValidator.cpp | 4 +- .../renderer/gfx-vulkan/VKDescriptorSet.cpp | 2 +- .../renderer/pipeline/PipelineSceneData.h | 1 + .../pipeline/custom/LayoutGraphUtils.cpp | 34 ++- .../pipeline/custom/LayoutGraphUtils.h | 5 + .../pipeline/custom/NativeExecutor.cpp | 240 ++++++++++++---- .../pipeline/custom/NativeFactory.cpp | 15 +- .../pipeline/custom/NativeLayoutGraph.cpp | 5 +- .../pipeline/custom/NativePipelineTypes.h | 14 +- .../pipeline/custom/NativeProgramLibrary.cpp | 126 +++++++-- .../pipeline/custom/NativeRenderingModule.cpp | 12 +- .../renderer/pipeline/custom/NativeTypes.cpp | 11 +- .../renderer/pipeline/custom/NativeTypes.h | 6 +- .../renderer/pipeline/custom/PrivateTypes.h | 14 +- .../pipeline/custom/RenderingModule.h | 1 + .../pipeline/custom/details/PathUtils.h | 8 - native/cocos/scene/Pass.cpp | 265 ++++++++++++++---- native/cocos/scene/Pass.h | 19 +- native/tools/swig-config/assets.i | 2 + native/tools/swig-config/pipeline.i | 2 +- templates/launcher/application.ejs | 2 - 50 files changed, 717 insertions(+), 262 deletions(-) diff --git a/cocos/game/game.ts b/cocos/game/game.ts index 5adb8fcbae..0eea011afa 100644 --- a/cocos/game/game.ts +++ b/cocos/game/game.ts @@ -769,7 +769,7 @@ export class Game extends EventTarget { this.emit(Game.EVENT_PRE_SUBSYSTEM_INIT); return this.onPreSubsystemInitDelegate.dispatch(); }) - .then(() => effectSettings.init(config.effectSettingsPath)) + .then(() => effectSettings.init(settings.querySettings(Settings.Category.RENDERING, 'effectSettingsPath') as string)) .then(() => { // initialize custom render pipeline if (!cclegacy.rendering || !cclegacy.rendering.enableEffectImport) { diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index 1ccbc88b18..039bd86048 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -482,7 +482,7 @@ export function buildPostprocessPass (camera: Camera, const postprocessPassRTName = `postprocessPassRTName${cameraID}`; const postprocessPassDS = `postprocessPassDS${cameraID}`; if (!ppl.containsResource(postprocessPassRTName)) { - ppl.addRenderTexture(postprocessPassRTName, Format.RGBA8, width, height, camera.window); + ppl.addRenderTexture(postprocessPassRTName, Format.BGRA8, width, height, camera.window); ppl.addDepthStencil(postprocessPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } ppl.updateRenderWindow(postprocessPassRTName, camera.window); @@ -537,7 +537,7 @@ export function buildForwardPass (camera: Camera, const forwardPassDSName = `dsForwardPassDS${cameraName}`; if (!ppl.containsResource(forwardPassRTName)) { if (!isOffScreen) { - ppl.addRenderTexture(forwardPassRTName, Format.RGBA8, width, height, camera.window); + ppl.addRenderTexture(forwardPassRTName, Format.BGRA8, width, height, camera.window); } else { ppl.addRenderTarget(forwardPassRTName, Format.RGBA16F, width, height, ResourceResidency.MANAGED); } diff --git a/cocos/rendering/custom/index.jsb.ts b/cocos/rendering/custom/index.jsb.ts index 1b12495412..983fb6aa94 100644 --- a/cocos/rendering/custom/index.jsb.ts +++ b/cocos/rendering/custom/index.jsb.ts @@ -36,7 +36,7 @@ export * from './pipeline'; export * from './archive'; export const INVALID_ID = 0xFFFFFFFF; -export const enableEffectImport = false; +export const enableEffectImport = true; let _renderModule: RenderingModule; diff --git a/cocos/rendering/custom/index.ts b/cocos/rendering/custom/index.ts index e196d781c8..bec30702a2 100644 --- a/cocos/rendering/custom/index.ts +++ b/cocos/rendering/custom/index.ts @@ -45,7 +45,7 @@ export * from './types'; export * from './pipeline'; export * from './archive'; -export const enableEffectImport = !EDITOR; +export const enableEffectImport = true; export const programLib: ProgramLibrary = new WebProgramLibrary(defaultLayoutGraph); export function createCustomPipeline (): Pipeline { diff --git a/cocos/rendering/custom/layout-graph-utils.ts b/cocos/rendering/custom/layout-graph-utils.ts index 6ac8689e6a..a22afd1add 100644 --- a/cocos/rendering/custom/layout-graph-utils.ts +++ b/cocos/rendering/custom/layout-graph-utils.ts @@ -1145,7 +1145,7 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder { if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER || index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) { layout.uniformBlockCapacity += block.capacity; - } else { + } else if (index.descriptorType === DescriptorTypeOrder.SAMPLER_TEXTURE) { layout.samplerTextureCapacity += block.capacity; } } @@ -1174,7 +1174,7 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder { if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER || index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) { layout.uniformBlockCapacity += block.capacity; - } else { + } else if (index.descriptorType === DescriptorTypeOrder.SAMPLER_TEXTURE) { layout.samplerTextureCapacity += block.capacity; } } @@ -1338,7 +1338,7 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData, if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER || index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) { data.uniformBlockCapacity += block.capacity; - } else { + } else if (index.descriptorType === DescriptorTypeOrder.SAMPLER_TEXTURE) { data.samplerTextureCapacity += block.capacity; } data.descriptorBlocks.push(block); diff --git a/cocos/rendering/custom/web-program-library.ts b/cocos/rendering/custom/web-program-library.ts index e3f27bf230..51e720e141 100644 --- a/cocos/rendering/custom/web-program-library.ts +++ b/cocos/rendering/custom/web-program-library.ts @@ -443,10 +443,6 @@ function calculateFlattenedBinding ( // update flattened sampler texture binding setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplerTextures); - setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplers); - setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.textures); - setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.buffers); - setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.images); } } diff --git a/cocos/rendering/global-descriptor-set-manager.ts b/cocos/rendering/global-descriptor-set-manager.ts index 61e2dc7b95..810f4fe2b6 100644 --- a/cocos/rendering/global-descriptor-set-manager.ts +++ b/cocos/rendering/global-descriptor-set-manager.ts @@ -26,7 +26,7 @@ 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 { getDescBindingFromName } from './custom/define'; +import { getDescBindingFromName, getDescriptorSetDataFromLayout } from './custom/define'; import { UBOShadow, globalDescriptorSetLayout, PipelineGlobalBindings, isEnableEffect } from './define'; const _samplerLinearInfo = new SamplerInfo( @@ -178,8 +178,9 @@ export class GlobalDSManager { // The global descriptorSet is managed by the pipeline and binds the buffer if (!this._descriptorSetMap.has(light)) { - const globalDescriptorSet = this._globalDescriptorSet; - const descriptorSet = device.createDescriptorSet(new DescriptorSetInfo(this._descriptorSetLayout)); + const globalDescriptorSet = isEnableEffect() ? getDescriptorSetDataFromLayout('default')!.descriptorSet! : this._globalDescriptorSet; + const descriptorSet = device.createDescriptorSet(new DescriptorSetInfo(isEnableEffect() + ? getDescriptorSetDataFromLayout('default')!.descriptorSetLayout! : this._descriptorSetLayout)); this._descriptorSetMap.set(light, descriptorSet); // Create & Sync ALL UBO Buffer, Texture, Sampler diff --git a/cocos/rendering/pipeline-funcs.ts b/cocos/rendering/pipeline-funcs.ts index b212288ded..f588a43718 100644 --- a/cocos/rendering/pipeline-funcs.ts +++ b/cocos/rendering/pipeline-funcs.ts @@ -26,7 +26,7 @@ import { EDITOR } from 'internal:constants'; import { CommandBuffer, Device, Rect, RenderPass, Viewport } from '../gfx'; import { IVec4Like } from '../core'; import { PipelineStateManager } from './pipeline-state-manager'; -import { SetIndex } from './define'; +import { isEnableEffect, SetIndex } from './define'; import { Camera, Model } from '../render-scene/scene'; import { Layers } from '../scene-graph/layers'; @@ -77,6 +77,9 @@ export function decideProfilerCamera (cameras: Camera[]) { } export function renderProfiler (device: Device, renderPass: RenderPass, cmdBuff: CommandBuffer, profiler: Model | null, camera: Camera) { + if (isEnableEffect()) { + return; + } if (!profiler || !profiler.enabled) { return; } diff --git a/cocos/rendering/scene-culling.ts b/cocos/rendering/scene-culling.ts index 627b98cd84..84ee578b08 100644 --- a/cocos/rendering/scene-culling.ts +++ b/cocos/rendering/scene-culling.ts @@ -77,6 +77,8 @@ export function validPunctualLightsCulling (pipeline: RenderPipeline, camera: Ca validPunctualLights.push(light); } } + // in jsb, std::vector is not synchronized, so we need to assign it manually + sceneData.validPunctualLights = validPunctualLights; } export function shadowCulling (camera: Camera, sceneData: PipelineSceneData, layer: ShadowLayerVolume) { const scene = camera.scene!; diff --git a/native/cocos/2d/renderer/Batcher2d.cpp b/native/cocos/2d/renderer/Batcher2d.cpp index 3625d4ad68..5862a00bf8 100644 --- a/native/cocos/2d/renderer/Batcher2d.cpp +++ b/native/cocos/2d/renderer/Batcher2d.cpp @@ -231,7 +231,7 @@ CC_FORCE_INLINE void Batcher2d::handleModelDraw(RenderEntity* entity, RenderDraw bool isMask = entity->getIsMask(); if (isMask) { - //Mask Comp + // Mask Comp insertMaskBatch(entity); } else { entity->setEnumStencilStage(_stencilManager->getStencilStage()); @@ -295,7 +295,7 @@ CC_FORCE_INLINE void Batcher2d::handleSubNode(RenderEntity* entity, RenderDrawIn } } -CC_FORCE_INLINE void Batcher2d::handleDrawInfo(RenderEntity* entity, RenderDrawInfo* drawInfo, Node* node) { //NOLINT(misc-no-recursion) +CC_FORCE_INLINE void Batcher2d::handleDrawInfo(RenderEntity* entity, RenderDrawInfo* drawInfo, Node* node) { // NOLINT(misc-no-recursion) CC_ASSERT(entity); CC_ASSERT(drawInfo); RenderDrawInfoType drawInfoType = drawInfo->getEnumDrawInfoType(); @@ -380,7 +380,7 @@ void Batcher2d::generateBatchForMiddleware(RenderEntity* entity, RenderDrawInfo* auto* texture = drawInfo->getTexture(); auto* sampler = drawInfo->getSampler(); auto* meshBuffer = drawInfo->getMeshBuffer(); - //set meshbuffer offset + // set meshbuffer offset auto indexOffset = drawInfo->getIndexOffset(); auto indexCount = drawInfo->getIbCount(); indexOffset += indexCount; @@ -425,7 +425,7 @@ void Batcher2d::resetRenderStates() { _currDrawInfo = nullptr; } -gfx::DescriptorSet* Batcher2d::getDescriptorSet(gfx::Texture* texture, gfx::Sampler* sampler, gfx::DescriptorSetLayout* dsLayout) { +gfx::DescriptorSet* Batcher2d::getDescriptorSet(gfx::Texture* texture, gfx::Sampler* sampler, const gfx::DescriptorSetLayout* dsLayout) { ccstd::hash_t hash = 2; size_t textureHash; if (texture != nullptr) { @@ -522,7 +522,7 @@ void Batcher2d::reset() { } } } - //meshBuffer cannot clear because it is not transported at every frame. + // meshBuffer cannot clear because it is not transported at every frame. _currMeshBuffer = nullptr; _indexStart = 0; diff --git a/native/cocos/2d/renderer/Batcher2d.h b/native/cocos/2d/renderer/Batcher2d.h index 8aa875b91f..18acf6f050 100644 --- a/native/cocos/2d/renderer/Batcher2d.h +++ b/native/cocos/2d/renderer/Batcher2d.h @@ -137,7 +137,7 @@ private: void insertMaskBatch(RenderEntity* entity); void createClearModel(); - gfx::DescriptorSet* getDescriptorSet(gfx::Texture* texture, gfx::Sampler* sampler, gfx::DescriptorSetLayout* dsLayout); + gfx::DescriptorSet* getDescriptorSet(gfx::Texture* texture, gfx::Sampler* sampler, const gfx::DescriptorSetLayout* dsLayout); StencilManager* _stencilManager{nullptr}; diff --git a/native/cocos/2d/renderer/RenderDrawInfo.cpp b/native/cocos/2d/renderer/RenderDrawInfo.cpp index 4c05041e78..f376de0f97 100644 --- a/native/cocos/2d/renderer/RenderDrawInfo.cpp +++ b/native/cocos/2d/renderer/RenderDrawInfo.cpp @@ -136,7 +136,7 @@ gfx::InputAssembler* RenderDrawInfo::initIAInfo(gfx::Device* device) { return ia; } -void RenderDrawInfo::updateLocalDescriptorSet(Node* transform, gfx::DescriptorSetLayout* dsLayout) { +void RenderDrawInfo::updateLocalDescriptorSet(Node* transform, const gfx::DescriptorSetLayout* dsLayout) { if (_localDSBF == nullptr) { _localDSBF = new LocalDSBF(); auto* device = Root::getInstance()->getDevice(); diff --git a/native/cocos/2d/renderer/RenderDrawInfo.h b/native/cocos/2d/renderer/RenderDrawInfo.h index a0beea79ef..ee4ab7b2b4 100644 --- a/native/cocos/2d/renderer/RenderDrawInfo.h +++ b/native/cocos/2d/renderer/RenderDrawInfo.h @@ -218,7 +218,7 @@ public: void resetMeshIA(); inline gfx::DescriptorSet* getLocalDes() { return _localDSBF->ds; } - void updateLocalDescriptorSet(Node* transform, gfx::DescriptorSetLayout* dsLayout); + void updateLocalDescriptorSet(Node* transform, const gfx::DescriptorSetLayout* dsLayout); inline void resetDrawInfo() { destroy(); diff --git a/native/cocos/bindings/auto/jsb_2d_auto.cpp b/native/cocos/bindings/auto/jsb_2d_auto.cpp index 3ae50e93a1..6f6efc022d 100644 --- a/native/cocos/bindings/auto/jsb_2d_auto.cpp +++ b/native/cocos/bindings/auto/jsb_2d_auto.cpp @@ -1287,7 +1287,7 @@ static bool js_cc_RenderDrawInfo_updateLocalDescriptorSet(se::State& s) ok &= sevalue_to_native(args[1], &arg3, s.thisObject()); SE_PRECONDITION2(ok, false, "Error processing arguments"); - (arg1)->updateLocalDescriptorSet(arg2,arg3); + (arg1)->updateLocalDescriptorSet(arg2,(cc::gfx::DescriptorSetLayout const *)arg3); return true; diff --git a/native/cocos/bindings/auto/jsb_pipeline_auto.cpp b/native/cocos/bindings/auto/jsb_pipeline_auto.cpp index 446b58a559..92ea11390b 100644 --- a/native/cocos/bindings/auto/jsb_pipeline_auto.cpp +++ b/native/cocos/bindings/auto/jsb_pipeline_auto.cpp @@ -130,6 +130,10 @@ using namespace cc; #define cc_pipeline_PipelineSceneData_lightProbes_get(self_) self_->getLightProbes() +#define cc_pipeline_PipelineSceneData_validPunctualLights_get(self_) self_->getValidPunctualLights() +#define cc_pipeline_PipelineSceneData_validPunctualLights_set(self_, val_) self_->setValidPunctualLights(val_) + + #define cc_pipeline_RenderStage__name_get(self_) self_->getName() #define cc_pipeline_RenderStage__name_set(self_, val_) self_->setName(val_) @@ -13550,31 +13554,6 @@ static bool js_cc_pipeline_PipelineSceneData_setShadowFramebuffer(se::State& s) } SE_BIND_FUNC(js_cc_pipeline_PipelineSceneData_setShadowFramebuffer) -static bool js_cc_pipeline_PipelineSceneData_getValidPunctualLights(se::State& s) -{ - CC_UNUSED bool ok = true; - const auto& args = s.args(); - size_t argc = args.size(); - cc::pipeline::PipelineSceneData *arg1 = (cc::pipeline::PipelineSceneData *) NULL ; - ccstd::vector< cc::scene::Light const * > *result = 0 ; - - if(argc != 0) { - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; - } - arg1 = SE_THIS_OBJECT(s); - if (nullptr == arg1) return true; - result = (ccstd::vector< cc::scene::Light const * > *) &((cc::pipeline::PipelineSceneData const *)arg1)->getValidPunctualLights(); - - 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_pipeline_PipelineSceneData_getValidPunctualLights) - static bool js_cc_pipeline_PipelineSceneData_getOctree(se::State& s) { CC_UNUSED bool ok = true; @@ -14060,6 +14039,47 @@ static bool js_cc_pipeline_PipelineSceneData_lightProbes_get(se::State& s) } SE_BIND_PROP_GET(js_cc_pipeline_PipelineSceneData_lightProbes_get) +static bool js_cc_pipeline_PipelineSceneData_validPunctualLights_set(se::State& s) +{ + CC_UNUSED bool ok = true; + const auto& args = s.args(); + size_t argc = args.size(); + cc::pipeline::PipelineSceneData *arg1 = (cc::pipeline::PipelineSceneData *) NULL ; + ccstd::vector< cc::scene::Light const * > arg2 ; + + 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"); + + cc_pipeline_PipelineSceneData_validPunctualLights_set(arg1,SWIG_STD_MOVE(arg2)); + + + return true; +} +SE_BIND_PROP_SET(js_cc_pipeline_PipelineSceneData_validPunctualLights_set) + +static bool js_cc_pipeline_PipelineSceneData_validPunctualLights_get(se::State& s) +{ + CC_UNUSED bool ok = true; + cc::pipeline::PipelineSceneData *arg1 = (cc::pipeline::PipelineSceneData *) NULL ; + ccstd::vector< cc::scene::Light const * > result; + + arg1 = SE_THIS_OBJECT(s); + if (nullptr == arg1) return true; + result = cc_pipeline_PipelineSceneData_validPunctualLights_get(arg1); + + ok &= nativevalue_to_se(result, s.rval(), s.thisObject() /*ctx*/); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + + + + return true; +} +SE_BIND_PROP_GET(js_cc_pipeline_PipelineSceneData_validPunctualLights_get) + bool js_register_cc_pipeline_PipelineSceneData(se::Object* obj) { auto* cls = se::Class::create("PipelineSceneData", obj, nullptr, _SE(js_new_cc_pipeline_PipelineSceneData)); @@ -14071,12 +14091,12 @@ bool js_register_cc_pipeline_PipelineSceneData(se::Object* obj) { cls->defineProperty("skybox", _SE(js_cc_pipeline_PipelineSceneData_skybox_get), nullptr); cls->defineProperty("shadows", _SE(js_cc_pipeline_PipelineSceneData_shadows_get), nullptr); cls->defineProperty("lightProbes", _SE(js_cc_pipeline_PipelineSceneData_lightProbes_get), nullptr); + cls->defineProperty("validPunctualLights", _SE(js_cc_pipeline_PipelineSceneData_validPunctualLights_get), _SE(js_cc_pipeline_PipelineSceneData_validPunctualLights_set)); cls->defineFunction("activate", _SE(js_cc_pipeline_PipelineSceneData_activate)); cls->defineFunction("destroy", _SE(js_cc_pipeline_PipelineSceneData_destroy)); cls->defineFunction("updatePipelineSceneData", _SE(js_cc_pipeline_PipelineSceneData_updatePipelineSceneData)); cls->defineFunction("setShadowFramebuffer", _SE(js_cc_pipeline_PipelineSceneData_setShadowFramebuffer)); - cls->defineFunction("getValidPunctualLights", _SE(js_cc_pipeline_PipelineSceneData_getValidPunctualLights)); cls->defineFunction("getOctree", _SE(js_cc_pipeline_PipelineSceneData_getOctree)); cls->defineFunction("getOcclusionQueryInputAssembler", _SE(js_cc_pipeline_PipelineSceneData_getOcclusionQueryInputAssembler)); cls->defineFunction("getOcclusionQueryPass", _SE(js_cc_pipeline_PipelineSceneData_getOcclusionQueryPass)); diff --git a/native/cocos/bindings/auto/jsb_scene_auto.cpp b/native/cocos/bindings/auto/jsb_scene_auto.cpp index a767ecd508..5ce129f253 100644 --- a/native/cocos/bindings/auto/jsb_scene_auto.cpp +++ b/native/cocos/bindings/auto/jsb_scene_auto.cpp @@ -26743,7 +26743,7 @@ static bool js_cc_ProgramLib_getTemplate(se::State& s) SE_PRECONDITION2(ok, false, "Error processing arguments"); arg2 = &temp2; - result = (cc::IProgramInfo *)(arg1)->getTemplate((ccstd::string const &)*arg2); + result = (cc::IProgramInfo *)((cc::ProgramLib const *)arg1)->getTemplate((ccstd::string const &)*arg2); ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); SE_PRECONDITION2(ok, false, "Error processing arguments"); diff --git a/native/cocos/core/assets/EffectAsset.cpp b/native/cocos/core/assets/EffectAsset.cpp index 4d5070360d..9a74e9b171 100644 --- a/native/cocos/core/assets/EffectAsset.cpp +++ b/native/cocos/core/assets/EffectAsset.cpp @@ -23,9 +23,11 @@ ****************************************************************************/ #include "core/assets/EffectAsset.h" +#include "ProgramUtils.h" #include "cocos.h" #include "core/Root.h" #include "core/platform/Debug.h" +#include "cocos/renderer/pipeline/custom/RenderingModule.h" #include "engine/BaseEngine.h" #include "renderer/core/ProgramLib.h" @@ -164,7 +166,13 @@ EffectAsset *EffectAsset::get(const ccstd::string &name) { } void EffectAsset::onLoaded() { - ProgramLib::getInstance()->registerEffect(this); + auto *programLib = render::getProgramLibrary(); + if (programLib) { + render::addEffectDefaultProperties(*this); + programLib->addEffect(this); + } else { + ProgramLib::getInstance()->registerEffect(this); + } EffectAsset::registerAsset(this); #if !CC_EDITOR if (CC_CURRENT_ENGINE()->isInited()) { diff --git a/native/cocos/core/assets/EffectAsset.h b/native/cocos/core/assets/EffectAsset.h index cb535a94f2..03d0a7acc5 100644 --- a/native/cocos/core/assets/EffectAsset.h +++ b/native/cocos/core/assets/EffectAsset.h @@ -374,6 +374,8 @@ struct IPassInfoFull final { // cjh } : public IPassInfo { // IPassInfoFull // generated part index_t passIndex{0}; + uint32_t passID = 0xFFFFFFFF; + uint32_t phaseID = 0xFFFFFFFF; MacroRecord defines; ccstd::optional stateOverrides; diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index 67394b764a..03b96121de 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -37,6 +37,7 @@ #include "renderer/GFXDeviceManager.h" #include "renderer/core/ProgramLib.h" #include "renderer/pipeline/RenderPipeline.h" +#include "renderer/pipeline/custom/RenderingModule.h" #if CC_USE_AUDIO #include "cocos/audio/include/AudioEngine.h" @@ -191,6 +192,11 @@ void Engine::destroy() { delete _builtinResMgr; delete _programLib; + + if (cc::render::getRenderingModule()) { + cc::render::Factory::destroy(cc::render::getRenderingModule()); + } + CC_SAFE_DESTROY_AND_DELETE(_gfxDevice); delete _fs; _scheduler.reset(); @@ -225,9 +231,9 @@ void Engine::close() { // NOLINT cc::AudioEngine::stopAll(); #endif - //#if CC_USE_SOCKET - // cc::network::WebSocket::closeAllConnections(); - //#endif + // #if CC_USE_SOCKET + // cc::network::WebSocket::closeAllConnections(); + // #endif cc::DeferredReleasePool::clear(); _scheduler->removeAllFunctionsToBePerformedInCocosThread(); diff --git a/native/cocos/renderer/core/ProgramLib.cpp b/native/cocos/renderer/core/ProgramLib.cpp index 3caaa17675..a35cdc9357 100644 --- a/native/cocos/renderer/core/ProgramLib.cpp +++ b/native/cocos/renderer/core/ProgramLib.cpp @@ -178,15 +178,7 @@ void ProgramLib::registerEffect(EffectAsset *effect) { auto *tmpl = define(shader); tmpl->effectName = effect->getName(); } - - for (auto &tech : effect->_techniques) { - for (auto &pass : tech.passes) { - // grab default property declaration if there is none - if (pass.propertyIndex.has_value() && !pass.properties.has_value()) { - pass.properties = tech.passes[pass.propertyIndex.value()].properties; - } - } - } + render::addEffectDefaultProperties(*effect); } IProgramInfo *ProgramLib::define(IShaderInfo &shader) { @@ -362,7 +354,7 @@ IProgramInfo *ProgramLib::define(IShaderInfo &shader) { * @param name Target shader name */ -IProgramInfo *ProgramLib::getTemplate(const ccstd::string &name) { +const IProgramInfo *ProgramLib::getTemplate(const ccstd::string &name) const { auto it = _templates.find(name); return it != _templates.end() ? &it->second : nullptr; } diff --git a/native/cocos/renderer/core/ProgramLib.h b/native/cocos/renderer/core/ProgramLib.h index 08756da5bb..c6b60569ec 100644 --- a/native/cocos/renderer/core/ProgramLib.h +++ b/native/cocos/renderer/core/ProgramLib.h @@ -101,7 +101,7 @@ public: * @param name Target shader name */ - IProgramInfo *getTemplate(const ccstd::string &name); + const IProgramInfo *getTemplate(const ccstd::string &name) const; /** * @en Gets the shader template info with its name diff --git a/native/cocos/renderer/core/ProgramUtils.cpp b/native/cocos/renderer/core/ProgramUtils.cpp index aa9cff5a6f..382f46d50a 100644 --- a/native/cocos/renderer/core/ProgramUtils.cpp +++ b/native/cocos/renderer/core/ProgramUtils.cpp @@ -248,6 +248,17 @@ ccstd::string getShaderInstanceName(const ccstd::string &name, const ccstd::vect return ret.str(); } +void addEffectDefaultProperties(EffectAsset& effect) { + for (auto &tech : effect._techniques) { + for (auto &pass : tech.passes) { + // grab default property declaration if there is none + if (pass.propertyIndex.has_value() && !pass.properties.has_value()) { + pass.properties = tech.passes[pass.propertyIndex.value()].properties; + } + } + } +} + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/core/ProgramUtils.h b/native/cocos/renderer/core/ProgramUtils.h index 4057443d23..e7f3402632 100644 --- a/native/cocos/renderer/core/ProgramUtils.h +++ b/native/cocos/renderer/core/ProgramUtils.h @@ -48,6 +48,8 @@ ccstd::vector getActiveAttributes( ccstd::string getShaderInstanceName( const ccstd::string& name, const ccstd::vector& macros); +void addEffectDefaultProperties(EffectAsset& effect); + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp index 3eac95852e..48ba863ddb 100644 --- a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp @@ -50,7 +50,7 @@ DescriptorSetAgent::~DescriptorSetAgent() { void DescriptorSetAgent::doInit(const DescriptorSetInfo &info) { DescriptorSetInfo actorInfo; - actorInfo.layout = static_cast(info.layout)->getActor(); + actorInfo.layout = static_cast(info.layout)->getActor(); ENQUEUE_MESSAGE_2( DeviceAgent::getInstance()->getMessageQueue(), diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index b9254f1439..0070ce8b88 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -1419,7 +1419,7 @@ struct DescriptorSetLayoutInfo { }; struct DescriptorSetInfo { - DescriptorSetLayout *layout{nullptr}; + const DescriptorSetLayout *layout{nullptr}; EXPOSE_COPY_FN(DescriptorSetInfo) }; diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h index 90f37b4ebe..f0f213ad6e 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h @@ -54,7 +54,7 @@ public: Texture *getTexture(uint32_t binding, uint32_t index) const; Sampler *getSampler(uint32_t binding, uint32_t index) const; - inline DescriptorSetLayout *getLayout() const { return _layout; } + inline const DescriptorSetLayout *getLayout() const { return _layout; } inline void bindBuffer(uint32_t binding, Buffer *buffer) { bindBuffer(binding, buffer, 0U); } inline void bindTexture(uint32_t binding, Texture *texture) { bindTexture(binding, texture, 0U); } @@ -73,7 +73,7 @@ protected: uint32_t id = INVALID_OBJECT_ID; }; - DescriptorSetLayout *_layout = nullptr; + const DescriptorSetLayout *_layout = nullptr; ccstd::vector> _buffers; ccstd::vector> _textures; ccstd::vector> _samplers; diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp index a6a83dec4e..55b99ec13e 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp @@ -43,7 +43,7 @@ GLES2DescriptorSet::~GLES2DescriptorSet() { } void GLES2DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { - const GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); + const GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; const size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp index ed76b77062..bc9128083f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp @@ -44,7 +44,7 @@ GLES3DescriptorSet::~GLES3DescriptorSet() { } void GLES3DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { - const GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); + const GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; const size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm index 3452e23b25..1364da5db8 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm @@ -37,7 +37,7 @@ CCMTLDescriptorSet::CCMTLDescriptorSet() : DescriptorSet() { } void CCMTLDescriptorSet::doInit(const DescriptorSetInfo &info) { - const auto gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); + const auto gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); const auto descriptorCount = gpuDescriptorSetLayout->descriptorCount; const auto bindingCount = gpuDescriptorSetLayout->bindings.size(); diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp index 01196dffbd..b85bac174c 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp @@ -48,12 +48,12 @@ DescriptorSetValidator::~DescriptorSetValidator() { void DescriptorSetValidator::doInit(const DescriptorSetInfo &info) { CC_ASSERT(!isInited()); _inited = true; - CC_ASSERT(info.layout && static_cast(info.layout)->isInited()); + CC_ASSERT(info.layout && static_cast(info.layout)->isInited()); /////////// execute /////////// DescriptorSetInfo actorInfo; - actorInfo.layout = static_cast(info.layout)->getActor(); + actorInfo.layout = static_cast(info.layout)->getActor(); _actor->initialize(actorInfo); } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index 1821cfa9ab..727597846b 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -44,7 +44,7 @@ CCVKDescriptorSet::~CCVKDescriptorSet() { } void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { - CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); + CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); uint32_t bindingCount = utils::toUint(gpuDescriptorSetLayout->bindings.size()); uint32_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.h b/native/cocos/renderer/pipeline/PipelineSceneData.h index 48603ae1f5..41c97fbc41 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.h +++ b/native/cocos/renderer/pipeline/PipelineSceneData.h @@ -64,6 +64,7 @@ public: inline const RenderObjectList &getRenderObjects() const { return _renderObjects; } inline void setRenderObjects(RenderObjectList &&ro) { _renderObjects = std::forward(ro); } inline const ccstd::vector &getValidPunctualLights() const { return _validPunctualLights; } + inline void setValidPunctualLights(ccstd::vector lights) { _validPunctualLights = std::move(lights); } inline bool isHDR() const { return _isHDR; } inline void setHDR(bool val) { _isHDR = val; } inline scene::Shadows *getShadows() const { return _shadow; } diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp index 3530961ca6..02ba74a11b 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.cpp @@ -29,8 +29,9 @@ #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 "LayoutGraphTypes.h" +#include "LayoutGraphGraphs.h" +#include "RenderCommonTypes.h" #include "details/Map.h" namespace cc { @@ -49,7 +50,7 @@ DescriptorBlockData& getDescriptorBlockData( iter = map.emplace( std::piecewise_construct, std::forward_as_tuple(index), - std::forward_as_tuple()) + std::forward_as_tuple(index.descriptorType, index.visibility, 0)) .first; return iter->second; @@ -241,6 +242,13 @@ void makeDescriptorSetLayoutData( } // increate total capacity capacity += block.capacity; + data.capacity += block.capacity; + if (index.descriptorType == DescriptorTypeOrder::UNIFORM_BUFFER + || index.descriptorType == DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER) { + data.uniformBlockCapacity += block.capacity; + } else if (index.descriptorType == DescriptorTypeOrder::SAMPLER_TEXTURE) { + data.samplerTextureCapacity += block.capacity; + } data.descriptorBlocks.emplace_back(std::move(block)); } } @@ -293,6 +301,26 @@ uint32_t getSize(const ccstd::vector& blockMembers) { return prevSize; } +gfx::DescriptorSet* getOrCreatePerPassDescriptorSet( + gfx::Device* device, + LayoutGraphData& lg, LayoutGraphData::vertex_descriptor vertID) { + auto& ppl = get(LayoutGraphData::Layout, lg, vertID); + auto iter = ppl.descriptorSets.find(UpdateFrequency::PER_PASS); + if (iter == ppl.descriptorSets.end()) { + return nullptr; + } + auto& data = iter->second; + if (!data.descriptorSet) { + if (!data.descriptorSetLayout) { + data.descriptorSetLayout = device->createDescriptorSetLayout(data.descriptorSetLayoutInfo); + } + CC_ENSURES(data.descriptorSetLayout); + data.descriptorSet = device->createDescriptorSet(gfx::DescriptorSetInfo{data.descriptorSetLayout.get()}); + } + CC_ENSURES(data.descriptorSet); + return data.descriptorSet; +} + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h index e893e1e108..3a06f524b6 100644 --- a/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h +++ b/native/cocos/renderer/pipeline/custom/LayoutGraphUtils.h @@ -27,6 +27,7 @@ #include "cocos/core/assets/EffectAsset.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" #include "cocos/renderer/pipeline/custom/RenderCommonTypes.h" +#include "gfx-base/GFXDevice.h" namespace cc { @@ -49,6 +50,10 @@ void initializeDescriptorSetLayoutInfo( uint32_t getSize(const ccstd::vector& blockMembers); +gfx::DescriptorSet* getOrCreatePerPassDescriptorSet( + gfx::Device* device, + LayoutGraphData& lg, LayoutGraphData::vertex_descriptor vertID); + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index 63564d42b2..1aa88ca77b 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -26,10 +26,14 @@ #include #include #include "FGDispatcherGraphs.h" +#include "LayoutGraphGraphs.h" +#include "LayoutGraphTypes.h" +#include "LayoutGraphUtils.h" #include "NativePipelineFwd.h" #include "NativePipelineTypes.h" #include "RenderGraphGraphs.h" #include "RenderGraphTypes.h" +#include "RenderingModule.h" #include "cocos/renderer/gfx-base/GFXBarrier.h" #include "cocos/renderer/gfx-base/GFXDef-common.h" #include "cocos/renderer/gfx-base/GFXDevice.h" @@ -42,6 +46,7 @@ #include "details/GraphView.h" #include "details/GslUtils.h" #include "details/Range.h" +#include "pipeline/Define.h" namespace cc { @@ -49,34 +54,16 @@ namespace render { namespace { +constexpr uint32_t INVALID_ID = 0xFFFFFFFF; + struct RenderGraphVisitorContext { - RenderGraphVisitorContext( - NativeRenderContext& contextIn, - const RenderGraph& gIn, - ResourceGraph& resgIn, - const FrameGraphDispatcher& fgdIn, - const FrameGraphDispatcher::BarrierMap& barrierMapIn, - const ccstd::pmr::vector& validPassesIn, - gfx::Device* deviceIn, - cc::gfx::CommandBuffer* cmdBuffIn, - ccstd::pmr::unordered_map< - const scene::RenderScene*, - ccstd::pmr::unordered_map>& sceneQueuesIn, - PipelineRuntime* pplIn, - boost::container::pmr::memory_resource* scratchIn) - : context(contextIn), - g(gIn), - resourceGraph(resgIn), - fgd(fgdIn), - barrierMap(barrierMapIn), - validPasses(validPassesIn), - device(deviceIn), - cmdBuff(cmdBuffIn), - sceneQueues(sceneQueuesIn), - ppl(pplIn), - scratch(scratchIn) {} + RenderGraphVisitorContext(RenderGraphVisitorContext&&) = delete; + RenderGraphVisitorContext(RenderGraphVisitorContext const&) = delete; + RenderGraphVisitorContext& operator=(RenderGraphVisitorContext&&) = delete; + RenderGraphVisitorContext& operator=(RenderGraphVisitorContext const&) = delete; NativeRenderContext& context; + LayoutGraphData& lg; const RenderGraph& g; ResourceGraph& resourceGraph; const FrameGraphDispatcher& fgd; @@ -84,12 +71,12 @@ struct RenderGraphVisitorContext { const ccstd::pmr::vector& validPasses; gfx::Device* device = nullptr; cc::gfx::CommandBuffer* cmdBuff = nullptr; - boost::container::pmr::memory_resource* scratch = nullptr; - gfx::RenderPass* currentPass = nullptr; ccstd::pmr::unordered_map< const scene::RenderScene*, ccstd::pmr::unordered_map>& sceneQueues; PipelineRuntime* ppl = nullptr; + boost::container::pmr::memory_resource* scratch = nullptr; + gfx::RenderPass* currentPass = nullptr; }; void clear(gfx::RenderPassInfo& info) { @@ -359,6 +346,92 @@ struct RenderGraphFilter { const ccstd::pmr::vector* validPasses = nullptr; }; +void bindDescValue(gfx::DescriptorSet& desc, uint32_t binding, gfx::Buffer* value) { + desc.bindBuffer(binding, value); +} + +void bindDescValue(gfx::DescriptorSet& desc, uint32_t binding, gfx::Texture* value) { + desc.bindTexture(binding, value); +} + +void bindDescValue(gfx::DescriptorSet& desc, uint32_t binding, gfx::Sampler* value) { + desc.bindSampler(binding, value); +} + +template +void bindGlobalDesc(gfx::DescriptorSet& desc, uint32_t binding, T* value) { + bindDescValue(desc, binding, value); +} + +uint32_t getDescBinding(uint32_t descId, const DescriptorSetData& descData) { + const auto& layoutData = descData; + // find descriptor binding + for (const auto& block : layoutData.descriptorSetLayoutData.descriptorBlocks) { + for (uint32_t i = 0; i != block.descriptors.size(); ++i) { + if (descId == block.descriptors[i].descriptorID.value) { + return block.offset + i; + } + } + } + return 0xFFFFFFFF; +} + +void updateGlobal( + RenderGraphVisitorContext& ctx, + DescriptorSetData& descriptorSetData, + const RenderData& data, + bool isUpdate = false) { + const auto& constants = data.constants; + const auto& samplers = data.samplers; + const auto& textures = data.textures; + auto& device = *ctx.device; + auto& descriptorSet = *descriptorSetData.descriptorSet; + for (const auto& [key, value] : constants) { + const auto bindId = getDescBinding(key, descriptorSetData); + if (bindId == INVALID_ID) { + continue; + } + auto* buffer = descriptorSet.getBuffer(bindId); + bool haveBuff = true; + if (!buffer && !isUpdate) { + gfx::BufferInfo info{ + gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, + gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, + static_cast(value.size()), + static_cast(value.size())}; + buffer = device.createBuffer(info); + haveBuff = false; + } + CC_ENSURES(buffer); + if (isUpdate) { + buffer->update(value.data()); + } + if (!haveBuff) { + bindGlobalDesc(descriptorSet, bindId, buffer); + } + } + for (const auto& [key, value] : textures) { + const auto bindId = getDescBinding(key, descriptorSetData); + if (bindId == INVALID_ID) { + continue; + } + auto* tex = descriptorSet.getTexture(bindId); + if (!tex || isUpdate) { + bindGlobalDesc(descriptorSet, bindId, value.get()); + } + } + for (const auto& [key, value] : samplers) { + const auto bindId = getDescBinding(key, descriptorSetData); + if (bindId == INVALID_ID) { + continue; + } + auto* sampler = descriptorSet.getSampler(bindId); + if (!sampler || isUpdate) { + bindGlobalDesc(descriptorSet, bindId, value.get()); + } + } +} + struct RenderGraphVisitor : boost::dfs_visitor<> { void submitBarriers(const std::vector& barriers) const { const auto& resg = ctx.resourceGraph; @@ -415,7 +488,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { submitBarriers(iter->second.blockBarrier.rearBarriers); } } - void begin(const RasterPass& pass) const { + void begin(const RasterPass& pass, RenderGraph::vertex_descriptor vertID) const { // viewport auto vp = pass.viewport; if (vp.width == 0 && vp.height == 0) { @@ -426,28 +499,92 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { gfx::Rect scissor{0, 0, vp.width, vp.height}; // render pass - auto iter = ctx.context.renderPasses.find(pass); - if (iter == ctx.context.renderPasses.end()) { - bool added = false; - std::tie(iter, added) = ctx.context.renderPasses.emplace( - pass, createPersistentRenderPassAndFramebuffer(ctx, pass)); - CC_ENSURES(added); + { + auto iter = ctx.context.renderPasses.find(pass); + if (iter == ctx.context.renderPasses.end()) { + bool added = false; + std::tie(iter, added) = ctx.context.renderPasses.emplace( + pass, createPersistentRenderPassAndFramebuffer(ctx, pass)); + CC_ENSURES(added); + } + ++iter->second.refCount; + const auto& data = iter->second; + auto* cmdBuff = ctx.cmdBuff; + + cmdBuff->beginRenderPass( + data.renderPass.get(), + data.framebuffer.get(), + scissor, data.clearColors.data(), + data.clearDepth, data.clearStencil); + + ctx.currentPass = data.renderPass.get(); } - ++iter->second.refCount; - const auto& data = iter->second; - auto* cmdBuff = ctx.cmdBuff; - - cmdBuff->beginRenderPass( - data.renderPass.get(), - data.framebuffer.get(), - scissor, data.clearColors.data(), - data.clearDepth, data.clearStencil); - - ctx.currentPass = data.renderPass.get(); // update states + const auto& layoutName = get(RenderGraph::Layout, ctx.g, vertID); + const auto& layoutID = locate(LayoutGraphData::null_vertex(), layoutName, ctx.lg); + auto& layout = get(LayoutGraphData::Layout, ctx.lg, layoutID); + auto iter = layout.descriptorSets.find(UpdateFrequency::PER_PASS); + if (iter == layout.descriptorSets.end()) { + return; + } + + auto* passDescriptorSet = getOrCreatePerPassDescriptorSet( + ctx.device, ctx.lg, layoutID); + CC_ENSURES(passDescriptorSet); + auto& descriptorSet = *passDescriptorSet; + + auto& set = iter->second; + const auto& user = get(RenderGraph::Data, ctx.g, vertID); + const auto& data = set.descriptorSetLayoutData; + + for (const auto& block : data.descriptorBlocks) { + CC_EXPECTS(block.descriptors.size() == block.capacity); + auto bindID = block.offset; + switch (block.type) { + case DescriptorTypeOrder::UNIFORM_BUFFER: { + for (const auto& d : block.descriptors) { + const auto& uniformBlock = data.uniformBlocks.at(d.descriptorID); + } + + // auto* buffer = descriptorSet.getBuffer(bindID); + // if (!buffer) { + // gfx::BufferInfo info{ + // gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST, + // gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, + // static_cast(value.size()), + // static_cast(value.size())}; + // buffer = device.createBuffer(info); + // haveBuff = false; + // } + break; + } + case DescriptorTypeOrder::DYNAMIC_UNIFORM_BUFFER: + break; + case DescriptorTypeOrder::SAMPLER_TEXTURE: + break; + case DescriptorTypeOrder::SAMPLER: + break; + case DescriptorTypeOrder::TEXTURE: + break; + case DescriptorTypeOrder::STORAGE_BUFFER: + break; + case DescriptorTypeOrder::DYNAMIC_STORAGE_BUFFER: + break; + case DescriptorTypeOrder::STORAGE_IMAGE: + break; + case DescriptorTypeOrder::INPUT_ATTACHMENT: + break; + } + } + + // passDescriptorSet->bindBuffer(); + + // cmdBuff->bindDescriptorSet( + // static_cast(pipeline::SetIndex::GLOBAL), passDescriptorSet); + // auto offset = ctx.ppl->getPipelineUBO()->getCurrentCameraUBOOffset(); - // cmdBuff->bindDescriptorSet(pipeline::globalSet, ctx.getDescriptorSet(), 1, &offset); + // cmdBuff->bindDescriptorSet(pipeline::globalSet, ctx.getDescriptorSet(), 1, &offset); } void begin(const ComputePass& pass) const { // NOLINT(readability-convert-member-functions-to-static) std::ignore = pass; @@ -619,7 +756,7 @@ struct RenderGraphVisitor : boost::dfs_visitor<> { [&](const RasterPass& pass) { mountResources(pass); frontBarriers(vertID); - begin(pass); + begin(pass, vertID); }, [&](const ComputePass& pass) { mountResources(pass); @@ -991,7 +1128,7 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) { auto& ppl = *this; auto* scratch = &ppl.unsyncPool; - // CC_LOG_INFO(rg.print(scratch).c_str()); + auto& lg = dynamic_cast(getProgramLibrary())->layoutGraph; RenderGraphContextCleaner contextCleaner(ppl.nativeContext); ResourceCleaner cleaner(ppl.resourceGraph); @@ -1048,14 +1185,15 @@ void NativePipeline::executeRenderGraph(const RenderGraph& rg) { } // submit commands - RenderGraphVisitorContext ctx( - ppl.nativeContext, rg, ppl.resourceGraph, + RenderGraphVisitorContext ctx{ + ppl.nativeContext, + lg, rg, ppl.resourceGraph, fgd, fgd.barrierMap, validPasses, ppl.device, submit.primaryCommandBuffer, sceneQueues, &ppl, - scratch); + scratch}; RenderGraphVisitor visitor{{}, ctx}; boost::depth_first_search(fg, visitor, get(colors, rg)); diff --git a/native/cocos/renderer/pipeline/custom/NativeFactory.cpp b/native/cocos/renderer/pipeline/custom/NativeFactory.cpp index 0a00dc93a5..3b700f4807 100644 --- a/native/cocos/renderer/pipeline/custom/NativeFactory.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeFactory.cpp @@ -44,8 +44,6 @@ 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())); @@ -55,6 +53,7 @@ RenderingModule* Factory::init(gfx::Device* deviceIn, const ccstd::vectorlayoutGraph); } + ptr->init(deviceIn); sRenderingModule = ccnew NativeRenderingModule(std::move(ptr)); return sRenderingModule; @@ -64,11 +63,16 @@ void Factory::destroy(RenderingModule* renderingModule) noexcept { auto* ptr = dynamic_cast(renderingModule); if (ptr) { ptr->programLibrary.reset(); + CC_EXPECTS(sRenderingModule == renderingModule); + sRenderingModule = nullptr; } } Pipeline* Factory::createPipeline() { - return ccnew NativePipeline(boost::container::pmr::get_default_resource()); + auto* ptr = ccnew NativePipeline(boost::container::pmr::get_default_resource()); + CC_EXPECTS(sRenderingModule); + sRenderingModule->programLibrary->pipeline = ptr; + return ptr; } ProgramLibrary* getProgramLibrary() { @@ -78,6 +82,11 @@ ProgramLibrary* getProgramLibrary() { return sRenderingModule->programLibrary.get(); } +RenderingModule* getRenderingModule() { + CC_EXPECTS(sRenderingModule); + return sRenderingModule; +} + } // namespace render } // namespace cc diff --git a/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp index 26c5c95a5c..cb650442d9 100644 --- a/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeLayoutGraph.cpp @@ -273,13 +273,12 @@ ccstd::string NativeLayoutGraphBuilder::print() const { oss << "\n"; - auto &g = *data; + const auto &g = *data; for (const auto v : makeRange(vertices(g))) { if (parent(v, g) != LayoutGraphData::null_vertex()) { continue; } const auto &name = get(LayoutGraphData::Name, g, v); - const auto &freq = get(LayoutGraphData::Update, g, v); OSS << "\"" << name << "\": "; visit( @@ -288,7 +287,7 @@ ccstd::string NativeLayoutGraphBuilder::print() const { }, tag(v, g)); - oss << "<" << getName(freq) << "> {\n"; + oss << " {\n"; INDENT_BEG(); const auto &info = get(LayoutGraphData::Layout, g, v); for (const auto &set : info.descriptorSets) { diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h index de24d01349..05449f73b8 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h +++ b/native/cocos/renderer/pipeline/custom/NativePipelineTypes.h @@ -523,17 +523,17 @@ public: NativeProgramLibrary(const allocator_type& alloc) noexcept; // NOLINT - void addEffect(EffectAsset *effectAsset) override; + void addEffect(const EffectAsset *effectAsset) override; void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) override; ccstd::string getKey(uint32_t phaseID, const ccstd::string &programName, const MacroRecord &defines) const override; IntrusivePtr getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::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; + const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) override; + const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) override; + const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::string &programName) const override; + const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::string &programName) const override; ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) 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; + const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const override; + const Record &getHandleMap(uint32_t phaseID, const ccstd::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; diff --git a/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp index be86c7e0fe..0af2cd0a67 100644 --- a/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeProgramLibrary.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "LayoutGraphGraphs.h" #include "LayoutGraphUtils.h" #include "NativePipelineTypes.h" #include "ProgramLib.h" @@ -39,6 +40,7 @@ #include "cocos/renderer/pipeline/Define.h" #include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h" #include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h" +#include "details/Range.h" #include "gfx-base/GFXDescriptorSetLayout.h" #include "gfx-base/GFXShader.h" #include "pipeline/custom/NativePipelineFwd.h" @@ -167,8 +169,12 @@ void makeLocalDescriptorSetLayoutData( } data.bindingMap.emplace(nameID, b.binding); } - const auto &v = source.blocks.at(ccstd::string(name)); - data.uniformBlocks.emplace(nameID, v); + { + auto iter = source.blocks.find(ccstd::string(name)); + if (iter != source.blocks.end()) { + data.uniformBlocks.emplace(nameID, iter->second); + } + } } } @@ -253,7 +259,7 @@ ShaderProgramData &buildProgramData( void populateMergedShaderInfo( const ccstd::pmr::vector &valueNames, const DescriptorSetLayoutData &layout, uint32_t set, - gfx::ShaderInfo &shaderInfo, ccstd::pmr::vector &blockSizes) { + gfx::ShaderInfo &shaderInfo, ccstd::vector &blockSizes) { for (const auto &descriptorBlock : layout.descriptorBlocks) { auto binding = descriptorBlock.offset; switch (descriptorBlock.type) { @@ -371,7 +377,7 @@ void populateGroupedShaderInfo( const DescriptorSetLayoutData &layout, const IDescriptorInfo &descriptorInfo, uint32_t set, gfx::ShaderInfo &shaderInfo, - ccstd::pmr::vector &blockSizes) { + ccstd::vector &blockSizes) { for (const auto &descriptorBlock : layout.descriptorBlocks) { const auto visibility = descriptorBlock.visibility; auto binding = descriptorBlock.offset; @@ -500,7 +506,7 @@ void populateGroupedShaderInfo( void populateLocalShaderInfo( const IDescriptorInfo &target, const pipeline::DescriptorSetLayoutInfos &source, - gfx::ShaderInfo &shaderInfo, ccstd::pmr::vector &blockSizes) { + gfx::ShaderInfo &shaderInfo, ccstd::vector &blockSizes) { const auto set = setIndex(UpdateFrequency::PER_INSTANCE); for (const auto &block : target.blocks) { auto blockIter = source.blocks.find(block.name); @@ -699,7 +705,7 @@ void makeShaderInfo( const ShaderProgramData *programData, bool fixedLocal, gfx::ShaderInfo &shaderInfo, - ccstd::pmr::vector &blockSizes) { + ccstd::vector &blockSizes) { std::array descriptorSets{}; const pipeline::DescriptorSetLayoutInfos *fixedInstanceDescriptorSetLayout = nullptr; { // pass @@ -714,7 +720,7 @@ void makeShaderInfo( } { // phase auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_PHASE); - if (iter != passLayouts.descriptorSets.end()) { + if (iter != phaseLayouts.descriptorSets.end()) { descriptorSets[static_cast(UpdateFrequency::PER_PHASE)] = &iter->second.descriptorSetLayoutData; populateMergedShaderInfo( lg.valueNames, iter->second.descriptorSetLayoutData, @@ -900,7 +906,7 @@ const gfx::DescriptorSetLayout &getOrCreateProgramDescriptorSetLayout( const NativeProgramLibrary &lib, gfx::Device *device, LayoutGraphData &lg, uint32_t phaseID, - const ccstd::pmr::string &programName, UpdateFrequency rate) { + std::string_view programName, UpdateFrequency rate) { CC_EXPECTS(rate < UpdateFrequency::PER_PHASE); auto &phase = get(RenderPhaseTag{}, phaseID, lg); const auto iter = phase.shaderIndex.find(programName); @@ -921,11 +927,59 @@ const gfx::DescriptorSetLayout &getOrCreateProgramDescriptorSetLayout( return *layout.descriptorSetLayout; } +void populatePipelineLayoutInfo( + const NativeProgramLibrary &lib, + const PipelineLayoutData &layout, + UpdateFrequency rate, + gfx::PipelineLayoutInfo &info) { + auto iter = layout.descriptorSets.find(rate); + if (iter != layout.descriptorSets.end()) { + const auto &set = iter->second; + CC_EXPECTS(set.descriptorSetLayout); + info.setLayouts.emplace_back(set.descriptorSetLayout.get()); + } else { + info.setLayouts.emplace_back(lib.emptyDescriptorSetLayout.get()); + } +} + } // namespace void NativeProgramLibrary::init(gfx::Device *device) { emptyDescriptorSetLayout = device->createDescriptorSetLayout({}); emptyPipelineLayout = device->createPipelineLayout({}); + auto &lg = layoutGraph; + for (const auto v : makeRange(vertices(lg))) { + auto &layout = get(LayoutGraphData::Layout, lg, v); + for (auto &&[update, set] : layout.descriptorSets) { + if (set.descriptorSetLayout) { + CC_LOG_WARNING("descriptor set layout already initialized. It will be overwritten"); + } + initializeDescriptorSetLayoutInfo( + set.descriptorSetLayoutData, + set.descriptorSetLayoutInfo); + set.descriptorSetLayout = device->createDescriptorSetLayout(set.descriptorSetLayoutInfo); + CC_ENSURES(set.descriptorSetLayout); + set.descriptorSet = device->createDescriptorSet(gfx::DescriptorSetInfo{set.descriptorSetLayout.get()}); + CC_ENSURES(set.descriptorSet); + } + } + + for (const auto v : makeRange(vertices(lg))) { + if (!holds(v, lg)) { + continue; + } + const auto phaseID = v; + const auto passID = parent(phaseID, lg); + const auto &passLayout = get(LayoutGraphData::Layout, lg, passID); + const auto &phaseLayout = get(LayoutGraphData::Layout, lg, phaseID); + gfx::PipelineLayoutInfo info; + populatePipelineLayoutInfo(*this, passLayout, UpdateFrequency::PER_PASS, info); + populatePipelineLayoutInfo(*this, phaseLayout, UpdateFrequency::PER_PHASE, info); + populatePipelineLayoutInfo(*this, phaseLayout, UpdateFrequency::PER_BATCH, info); + populatePipelineLayoutInfo(*this, phaseLayout, UpdateFrequency::PER_INSTANCE, info); + auto &phase = get(RenderPhaseTag{}, phaseID, lg); + phase.pipelineLayout = device->createPipelineLayout(info); + } } void NativeProgramLibrary::destroy() { @@ -933,7 +987,7 @@ void NativeProgramLibrary::destroy() { emptyPipelineLayout.reset(); } -void NativeProgramLibrary::addEffect(EffectAsset *effectAssetIn) { +void NativeProgramLibrary::addEffect(const EffectAsset *effectAssetIn) { auto &lg = layoutGraph; boost::container::pmr::memory_resource *scratch = &unsycPool; const auto &effect = *effectAssetIn; @@ -961,6 +1015,9 @@ void NativeProgramLibrary::addEffect(EffectAsset *effectAssetIn) { .first; } auto &phasePrograms = iter->second.programInfos; + if (phasePrograms.find(std::string_view{srcShaderInfo.name}) != phasePrograms.end()) { + continue; + } auto alloc = phasePrograms.get_allocator(); // build program @@ -970,12 +1027,12 @@ void NativeProgramLibrary::addEffect(EffectAsset *effectAssetIn) { ShaderProgramData *programData = nullptr; if (!mergeHighFrequency) { auto &phase = get(RenderPhaseTag{}, phaseID, lg); - buildProgramData(programName, srcShaderInfo, lg, phase, fixedLocal, scratch); + programData = &buildProgramData(programName, srcShaderInfo, lg, phase, fixedLocal, scratch); } // shaderInfo and blockSizes gfx::ShaderInfo shaderInfo; - ccstd::pmr::vector blockSizes(alloc); + ccstd::vector blockSizes; makeShaderInfo(lg, passLayout, phaseLayout, srcShaderInfo, programData, fixedLocal, shaderInfo, blockSizes); @@ -1084,7 +1141,7 @@ IntrusivePtr NativeProgramLibrary::getPipelineLayout( } const gfx::DescriptorSetLayout &NativeProgramLibrary::getMaterialDescriptorSetLayout( - gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) { + gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) { if (mergeHighFrequency) { CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); const auto passID = parent(phaseID, layoutGraph); @@ -1096,7 +1153,7 @@ const gfx::DescriptorSetLayout &NativeProgramLibrary::getMaterialDescriptorSetLa } const gfx::DescriptorSetLayout &NativeProgramLibrary::getLocalDescriptorSetLayout( - gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) { + gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) { if (mergeHighFrequency) { CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); const auto passID = parent(phaseID, layoutGraph); @@ -1108,15 +1165,23 @@ const gfx::DescriptorSetLayout &NativeProgramLibrary::getLocalDescriptorSetLayou } const IProgramInfo &NativeProgramLibrary::getProgramInfo( - uint32_t phaseID, const ccstd::pmr::string &programName) const { + uint32_t phaseID, const ccstd::string &programName) const { const auto &group = phases.at(phaseID); - return group.programInfos.at(programName).programInfo; + auto iter = group.programInfos.find(std::string_view{programName}); + if (iter != group.programInfos.end()) { + return iter->second.programInfo; + } + throw std::invalid_argument("program not found"); } const gfx::ShaderInfo &NativeProgramLibrary::getShaderInfo( - uint32_t phaseID, const ccstd::pmr::string &programName) const { + uint32_t phaseID, const ccstd::string &programName) const { const auto &group = phases.at(phaseID); - return group.programInfos.at(programName).shaderInfo; + auto iter = group.programInfos.find(std::string_view{programName}); + if (iter != group.programInfos.end()) { + return iter->second.shaderInfo; + } + throw std::invalid_argument("program not found"); } ProgramProxy *NativeProgramLibrary::getProgramVariant( @@ -1165,7 +1230,12 @@ ProgramProxy *NativeProgramLibrary::getProgramVariant( for (const auto &m : macroArray) { ss << "#define " << m.name << " " << m.value << std::endl; } - auto prefix = pipeline->getConstantMacros() + programInfo.constantMacros + ss.str(); + + std::string prefix; + if (pipeline) { + prefix += pipeline->getConstantMacros(); + } + prefix += programInfo.constantMacros + ss.str(); const IShaderSource *src = &programInfo.glsl3; const auto *deviceShaderVersion = getDeviceShaderVersion(device); @@ -1191,20 +1261,26 @@ ProgramProxy *NativeProgramLibrary::getProgramVariant( return res.first->second.get(); } -const ccstd::pmr::vector &NativeProgramLibrary::getBlockSizes( - uint32_t phaseID, const ccstd::pmr::string &programName) const { +const ccstd::vector &NativeProgramLibrary::getBlockSizes( + uint32_t phaseID, const ccstd::string &programName) const { CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); const auto &group = phases.at(phaseID); - const auto &info = group.programInfos.at(programName); - return info.blockSizes; + auto iter = group.programInfos.find(std::string_view{programName}); + if (iter != group.programInfos.end()) { + return iter->second.blockSizes; + } + throw std::invalid_argument("program not found"); } const Record &NativeProgramLibrary::getHandleMap( - uint32_t phaseID, const ccstd::pmr::string &programName) const { + uint32_t phaseID, const ccstd::string &programName) const { CC_EXPECTS(phaseID != LayoutGraphData::null_vertex()); const auto &group = phases.at(phaseID); - const auto &info = group.programInfos.at(programName); - return info.handleMap; + auto iter = group.programInfos.find(std::string_view{programName}); + if (iter != group.programInfos.end()) { + return iter->second.handleMap; + } + throw std::invalid_argument("program not found"); } uint32_t NativeProgramLibrary::getProgramID( diff --git a/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp b/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp index 09001e9514..110f994473 100644 --- a/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeRenderingModule.cpp @@ -23,20 +23,22 @@ ****************************************************************************/ #include "NativePipelineTypes.h" +#include "details/GslUtils.h" +#include "LayoutGraphGraphs.h" namespace cc { namespace render { uint32_t NativeRenderingModule::getPassID(const ccstd::string &name) const { - std::ignore = name; - return LayoutGraphData::null_vertex(); + CC_EXPECTS(programLibrary); + return locate(LayoutGraphData::null_vertex(), name, programLibrary->layoutGraph); } uint32_t NativeRenderingModule::getPhaseID(uint32_t passID, const ccstd::string &name) const { - std::ignore = passID; - std::ignore = name; - return LayoutGraphData::null_vertex(); + CC_EXPECTS(programLibrary); + CC_EXPECTS(passID != LayoutGraphData::null_vertex()); + return locate(passID, name, programLibrary->layoutGraph); } } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/NativeTypes.cpp b/native/cocos/renderer/pipeline/custom/NativeTypes.cpp index 4b8f02e5de..f0d21eea6a 100644 --- a/native/cocos/renderer/pipeline/custom/NativeTypes.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeTypes.cpp @@ -35,28 +35,27 @@ namespace cc { namespace render { ProgramInfo::ProgramInfo(const allocator_type& alloc) noexcept -: attributes(alloc), - blockSizes(alloc) {} +: attributes(alloc) {} -ProgramInfo::ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector attributesIn, ccstd::pmr::vector blockSizesIn, Record handleMapIn, const allocator_type& alloc) noexcept +ProgramInfo::ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector attributesIn, ccstd::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), + blockSizes(std::move(blockSizesIn)), handleMap(std::move(handleMapIn)) {} 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), + blockSizes(std::move(rhs.blockSizes)), handleMap(std::move(rhs.handleMap)) {} ProgramInfo::ProgramInfo(ProgramInfo const& rhs, const allocator_type& alloc) : programInfo(rhs.programInfo), shaderInfo(rhs.shaderInfo), attributes(rhs.attributes, alloc), - blockSizes(rhs.blockSizes, alloc), + blockSizes(rhs.blockSizes), handleMap(rhs.handleMap) {} ProgramGroup::ProgramGroup(const allocator_type& alloc) noexcept diff --git a/native/cocos/renderer/pipeline/custom/NativeTypes.h b/native/cocos/renderer/pipeline/custom/NativeTypes.h index 4311205ecb..3d3eae733a 100644 --- a/native/cocos/renderer/pipeline/custom/NativeTypes.h +++ b/native/cocos/renderer/pipeline/custom/NativeTypes.h @@ -49,7 +49,7 @@ struct ProgramInfo { } 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(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector attributesIn, ccstd::vector blockSizesIn, Record handleMapIn, const allocator_type& alloc) noexcept; ProgramInfo(ProgramInfo&& rhs, const allocator_type& alloc); ProgramInfo(ProgramInfo const& rhs, const allocator_type& alloc); @@ -61,7 +61,7 @@ struct ProgramInfo { IProgramInfo programInfo; gfx::ShaderInfo shaderInfo; ccstd::pmr::vector attributes; - ccstd::pmr::vector blockSizes; + ccstd::vector blockSizes; Record handleMap; }; @@ -80,7 +80,7 @@ struct ProgramGroup { ProgramGroup& operator=(ProgramGroup&& rhs) = default; ProgramGroup& operator=(ProgramGroup const& rhs) = default; - PmrFlatMap programInfos; + PmrTransparentMap programInfos; PmrFlatMap> programProxies; }; diff --git a/native/cocos/renderer/pipeline/custom/PrivateTypes.h b/native/cocos/renderer/pipeline/custom/PrivateTypes.h index fbe2e18f00..d8c6b49372 100644 --- a/native/cocos/renderer/pipeline/custom/PrivateTypes.h +++ b/native/cocos/renderer/pipeline/custom/PrivateTypes.h @@ -60,17 +60,17 @@ public: ProgramLibrary& operator=(ProgramLibrary const& rhs) = delete; virtual ~ProgramLibrary() noexcept = default; - virtual void addEffect(EffectAsset *effectAsset) = 0; + virtual void addEffect(const EffectAsset *effectAsset) = 0; virtual void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) = 0; virtual ccstd::string getKey(uint32_t phaseID, const ccstd::string &programName, const MacroRecord &defines) const = 0; virtual IntrusivePtr getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::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 const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) = 0; + virtual const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) = 0; + virtual const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::string &programName) const = 0; + virtual const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::string &programName) const = 0; virtual ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) = 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 const ccstd::vector &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const = 0; + virtual const Record &getHandleMap(uint32_t phaseID, const ccstd::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; diff --git a/native/cocos/renderer/pipeline/custom/RenderingModule.h b/native/cocos/renderer/pipeline/custom/RenderingModule.h index 4b150742f8..4acff013a7 100644 --- a/native/cocos/renderer/pipeline/custom/RenderingModule.h +++ b/native/cocos/renderer/pipeline/custom/RenderingModule.h @@ -30,6 +30,7 @@ namespace cc { namespace render { ProgramLibrary* getProgramLibrary(); +RenderingModule* getRenderingModule(); } // namespace render diff --git a/native/cocos/renderer/pipeline/custom/details/PathUtils.h b/native/cocos/renderer/pipeline/custom/details/PathUtils.h index f5c6c32a1f..e455672918 100644 --- a/native/cocos/renderer/pipeline/custom/details/PathUtils.h +++ b/native/cocos/renderer/pipeline/custom/details/PathUtils.h @@ -44,14 +44,6 @@ inline void cleanPath(std::basic_string, Allocato CC_EXPECTS(!str.empty()); CC_EXPECTS(boost::algorithm::starts_with(str, std::string_view(slash))); CC_EXPECTS(str.find(doubleSlash) == string_t::npos); - CC_EXPECTS([&]() { // NOLINT - bool valid = true; - for (uint8_t c : str) { - if (c < uint8_t('.')) - valid = false; - } - return valid; - }()); { // remove all /./ constexpr CharT current[] = {'/', '.', '/', '\0'}; diff --git a/native/cocos/scene/Pass.cpp b/native/cocos/scene/Pass.cpp index 268c460b4e..07c903d32b 100644 --- a/native/cocos/scene/Pass.cpp +++ b/native/cocos/scene/Pass.cpp @@ -30,6 +30,8 @@ #include "core/assets/TextureBase.h" #include "core/builtin/BuiltinResMgr.h" #include "core/platform/Debug.h" +#include "gfx-base/GFXDevice.h" +#include "pipeline/custom/details/GslUtils.h" #include "renderer/core/PassUtils.h" #include "renderer/core/ProgramLib.h" #include "renderer/gfx-base/GFXDef.h" @@ -44,6 +46,8 @@ namespace scene { namespace { +constexpr uint32_t INVALID_ID = 0xFFFFFFFF; + ccstd::hash_t serializeBlendState(const gfx::BlendState &bs) { ccstd::hash_t hashValue{2}; ccstd::hash_combine(hashValue, bs.isA2C); @@ -410,9 +414,9 @@ void Pass::resetTexture(const ccstd::string &name, uint32_t index) { } void Pass::resetUBOs() { - for (auto &u : _shaderInfo->blocks) { + for (const auto &u : _shaderInfo->blocks) { uint32_t ofs = 0; - for (auto &cur : u.members) { + for (const auto &cur : u.members) { const auto &block = _blocks[u.binding]; const auto &info = _properties[cur.name]; const auto &givenDefault = info.value; @@ -428,7 +432,7 @@ void Pass::resetUBOs() { } void Pass::resetTextures() { - for (auto &u : _shaderInfo->samplerTextures) { + for (const auto &u : _shaderInfo->samplerTextures) { for (int32_t j = 0; j < u.count; j++) { resetTexture(u.name, j); } @@ -492,7 +496,16 @@ gfx::Shader *Pass::getShaderVariant(const ccstd::vector &patches) { _defines[patch.name] = patch.value; } - auto *shader = ProgramLib::getInstance()->getGFXShader(_device, _programName, _defines, pipeline); + gfx::Shader *shader = nullptr; + auto *programLib = render::getProgramLibrary(); + if (programLib) { + const auto *program = programLib->getProgramVariant(_device, _phaseID, _programName, _defines); + if (program) { + shader = program->getShader(); + } + } else { + shader = ProgramLib::getInstance()->getGFXShader(_device, _programName, _defines, pipeline); + } for (const auto &patch : patches) { auto iter = _defines.find(patch.name); @@ -531,6 +544,9 @@ IPassInfoFull Pass::getPassInfoFull() const { ret.dynamicStates = _dynamicStates; ret.phase = _phaseString; + ret.passID = _passID; + ret.phaseID = _phaseID; + return ret; } @@ -546,6 +562,35 @@ void Pass::doInit(const IPassInfoFull &info, bool /*copyDefines*/ /* = false */) auto *programLib = ProgramLib::getInstance(); _priority = pipeline::RenderPriority::DEFAULT; _stage = pipeline::RenderPassStage::DEFAULT; + auto *programLib2 = render::getProgramLibrary(); + if (programLib2) { + const auto *rendering = render::getRenderingModule(); + CC_EXPECTS(rendering); + if (info.phaseID != 0xFFFFFFFF) { + _passID = info.passID; + _phaseID = info.phaseID; + } else { + if (info.pass) { + _passID = rendering->getPassID(*info.pass); + } else { + _passID = rendering->getPassID("default"); + } + CC_ENSURES(_passID != 0xFFFFFFFF); + if (info.phase) { + _phaseID = rendering->getPhaseID(_passID, *info.phase); + } else { + _phaseID = rendering->getPhaseID(_passID, "default"); + } + } + if (_passID == INVALID_ID) { + CC_LOG_ERROR("Invalid pass ID"); + return; + } + if (_phaseID == INVALID_ID) { + CC_LOG_ERROR("Invalid phase ID"); + return; + } + } _phaseString = "default"; _phase = pipeline::getPhaseID(_phaseString); _primitive = gfx::PrimitiveMode::TRIANGLE_LIST; @@ -554,11 +599,18 @@ void Pass::doInit(const IPassInfoFull &info, bool /*copyDefines*/ /* = false */) _propertyIndex = info.propertyIndex.has_value() ? info.propertyIndex.value() : info.passIndex; _programName = info.program; _defines = info.defines; // cjh c++ always does copy by assignment. copyDefines ? ({ ...info.defines }) : info.defines; - _shaderInfo = programLib->getTemplate(info.program); + // init shader info + if (programLib2) { + CC_EXPECTS(_phaseID != INVALID_ID); + _shaderInfo = &programLib2->getProgramInfo(_phaseID, _programName); + } else { + _shaderInfo = programLib->getTemplate(info.program); + } if (info.properties.has_value()) { _properties = info.properties.value(); } - // + + // init gfx gfx::Device *device = _device; Pass::fillPipelineInfo(this, info); if (info.stateOverrides.has_value()) { @@ -567,63 +619,45 @@ void Pass::doInit(const IPassInfoFull &info, bool /*copyDefines*/ /* = false */) // init descriptor set gfx::DescriptorSetInfo dsInfo; - dsInfo.layout = programLib->getDescriptorSetLayout(_device, info.program); + if (programLib2) { + CC_EXPECTS(_phaseID != INVALID_ID); + dsInfo.layout = &programLib2->getMaterialDescriptorSetLayout( + _device, _phaseID, _programName); + } else { + dsInfo.layout = programLib->getDescriptorSetLayout(_device, info.program); + } _descriptorSet = _device->createDescriptorSet(dsInfo); // calculate total size required const auto &blocks = _shaderInfo->blocks; - const auto *tmplInfo = programLib->getTemplateInfo(info.program); - const ccstd::vector &blockSizes = tmplInfo->blockSizes; - const auto &handleMap = tmplInfo->handleMap; - - const auto alignment = device->getCapabilities().uboOffsetAlignment; - ccstd::vector startOffsets; - startOffsets.reserve(blocks.size()); - uint32_t lastSize = 0; - uint32_t lastOffset = 0; - for (size_t i = 0; i < blocks.size(); i++) { - const auto &size = blockSizes[i]; - startOffsets.emplace_back(lastOffset); - lastOffset += static_cast(std::ceil(static_cast(size) / static_cast(alignment))) * alignment; - lastSize = size; - } - - // create gfx buffer resource - uint32_t totalSize = !startOffsets.empty() ? (startOffsets[startOffsets.size() - 1] + lastSize) : 0; - if (totalSize > 0) { - gfx::BufferInfo bufferInfo; - bufferInfo.usage = gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST; - bufferInfo.memUsage = gfx::MemoryUsageBit::DEVICE; - // https://bugs.chromium.org/p/chromium/issues/detail?id=988988 - bufferInfo.size = static_cast(std::ceil(static_cast(totalSize) / 16.F)) * 16; - _rootBuffer = device->createBuffer(bufferInfo); - _rootBlock = ccnew ArrayBuffer(totalSize); - } - - gfx::BufferViewInfo bufferViewInfo; - - // create buffer views - for (size_t i = 0, count = 0; i < blocks.size(); i++) { - int32_t binding = blocks[i].binding; - int32_t size = blockSizes[i]; - bufferViewInfo.buffer = _rootBuffer; - bufferViewInfo.offset = startOffsets[count++]; - bufferViewInfo.range = static_cast(std::ceil(static_cast(size) / 16.F)) * 16; - if (binding >= _buffers.size()) { - _buffers.resize(binding + 1); + const auto *tmplInfo + = programLib2 + ? nullptr + : programLib->getTemplateInfo(info.program); + const auto &blockSizes = [&]() -> const auto & { + if (programLib2) { + return programLib2->getBlockSizes(_phaseID, _programName); } - auto *bufferView = device->createBuffer(bufferViewInfo); - _buffers[binding] = bufferView; - // non-builtin UBO data pools, note that the effect compiler - // guarantees these bindings to be consecutive, starting from 0 and non-array-typed - if (binding >= _blocks.size()) { - _blocks.resize(binding + 1); - } - _blocks[binding].data = reinterpret_cast(const_cast(_rootBlock->getData()) + bufferViewInfo.offset); - _blocks[binding].count = size / 4; - _blocks[binding].offset = bufferViewInfo.offset / 4; - _descriptorSet->bindBuffer(binding, bufferView); + return tmplInfo->blockSizes; } + (); + const auto &handleMap = [&]() -> const auto & { + if (programLib2) { + CC_EXPECTS(_phaseID != INVALID_ID); + return programLib2->getHandleMap(_phaseID, _programName); + } + return tmplInfo->handleMap; + } + (); + + // build uniform blocks + if (programLib2) { + const auto &shaderInfo = programLib2->getShaderInfo(_phaseID, _programName); + buildMaterialUniformBlocks(shaderInfo.blocks, blockSizes); + } else { + buildUniformBlocks(blocks, blockSizes); + } + // store handles _propertyHandleMap = handleMap; auto &directHandleMap = _propertyHandleMap; @@ -640,6 +674,117 @@ void Pass::doInit(const IPassInfoFull &info, bool /*copyDefines*/ /* = false */) utils::mergeToMap(directHandleMap, indirectHandleMap); } +namespace { + +void calculateTotalSize( + gfx::Device *device, const uint32_t lastSize, + IntrusivePtr &rootBuffer, + IntrusivePtr &rootBlock, + ccstd::vector &startOffsets) { + uint32_t totalSize = !startOffsets.empty() ? (startOffsets[startOffsets.size() - 1] + lastSize) : 0; + if (totalSize > 0) { + gfx::BufferInfo bufferInfo; + bufferInfo.usage = gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST; + bufferInfo.memUsage = gfx::MemoryUsageBit::DEVICE; + // https://bugs.chromium.org/p/chromium/issues/detail?id=988988 + bufferInfo.size = static_cast(std::ceil(static_cast(totalSize) / 16.F)) * 16; + rootBuffer = device->createBuffer(bufferInfo); + rootBlock = ccnew ArrayBuffer(totalSize); + } +} + +} // namespace + +void Pass::buildUniformBlock( + uint32_t binding, int32_t size, + gfx::BufferViewInfo &bufferViewInfo, + ccstd::vector &startOffsets, + size_t &count) { + bufferViewInfo.buffer = _rootBuffer; + bufferViewInfo.offset = startOffsets[count++]; + bufferViewInfo.range = static_cast(std::ceil(static_cast(size) / 16.F)) * 16; + if (binding >= _buffers.size()) { + _buffers.resize(binding + 1); + } + auto *bufferView = _device->createBuffer(bufferViewInfo); + _buffers[binding] = bufferView; + // non-builtin UBO data pools, note that the effect compiler + // guarantees these bindings to be consecutive, starting from 0 and non-array-typed + if (binding >= _blocks.size()) { + _blocks.resize(binding + 1); + } + _blocks[binding].data = reinterpret_cast(const_cast(_rootBlock->getData()) + bufferViewInfo.offset); + _blocks[binding].count = size / 4; + _blocks[binding].offset = bufferViewInfo.offset / 4; + _descriptorSet->bindBuffer(binding, bufferView); +} + +void Pass::buildMaterialUniformBlocks( + const ccstd::vector &blocks, + const ccstd::vector &blockSizes) { + gfx::Device *device = _device; + const auto alignment = device->getCapabilities().uboOffsetAlignment; + ccstd::vector startOffsets; + startOffsets.reserve(blocks.size()); + uint32_t lastSize = 0; + uint32_t lastOffset = 0; + for (size_t i = 0; i < blocks.size(); i++) { + const auto &block = blocks[i]; + if (static_cast(block.set) != pipeline::SetIndex::MATERIAL) { + continue; + } + const auto &size = blockSizes[i]; + startOffsets.emplace_back(lastOffset); + lastOffset += static_cast(std::ceil(static_cast(size) / static_cast(alignment))) * alignment; + lastSize = size; + } + + // create gfx buffer resource + if (lastSize != 0) { + calculateTotalSize(device, lastSize, _rootBuffer, _rootBlock, startOffsets); + } + + // create buffer views + gfx::BufferViewInfo bufferViewInfo{}; + for (size_t i = 0, count = 0; i < blocks.size(); i++) { + const auto &block = blocks[i]; + if (static_cast(block.set) != pipeline::SetIndex::MATERIAL) { + continue; + } + const auto binding = block.binding; + int32_t size = blockSizes[i]; + buildUniformBlock(binding, size, bufferViewInfo, startOffsets, count); + } +} + +void Pass::buildUniformBlocks( + const ccstd::vector &blocks, + const ccstd::vector &blockSizes) { + gfx::Device *device = _device; + const auto alignment = device->getCapabilities().uboOffsetAlignment; + ccstd::vector startOffsets; + startOffsets.reserve(blocks.size()); + uint32_t lastSize = 0; + uint32_t lastOffset = 0; + for (size_t i = 0; i < blocks.size(); i++) { + const auto &size = blockSizes[i]; + startOffsets.emplace_back(lastOffset); + lastOffset += static_cast(std::ceil(static_cast(size) / static_cast(alignment))) * alignment; + lastSize = size; + } + + // create gfx buffer resource + calculateTotalSize(device, lastSize, _rootBuffer, _rootBlock, startOffsets); + + // create buffer views + gfx::BufferViewInfo bufferViewInfo; + for (size_t i = 0, count = 0; i < blocks.size(); i++) { + const auto binding = blocks[i].binding; + int32_t size = blockSizes[i]; + buildUniformBlock(binding, size, bufferViewInfo, startOffsets, count); + } +} + void Pass::syncBatchingScheme() { auto iter = _defines.find("USE_INSTANCING"); if (iter != _defines.end()) { @@ -690,7 +835,11 @@ void Pass::updatePassHash() { _hash = Pass::getPassHash(this); } -gfx::DescriptorSetLayout *Pass::getLocalSetLayout() const { +const gfx::DescriptorSetLayout *Pass::getLocalSetLayout() const { + auto *programLib = render::getProgramLibrary(); + if (programLib) { + return &programLib->getLocalDescriptorSetLayout(_device, _phaseID, _programName); + } return ProgramLib::getInstance()->getDescriptorSetLayout(_device, _programName, true); } diff --git a/native/cocos/scene/Pass.h b/native/cocos/scene/Pass.h index 5fccb1c28d..d2830a73f2 100644 --- a/native/cocos/scene/Pass.h +++ b/native/cocos/scene/Pass.h @@ -263,8 +263,8 @@ public: // infos inline Root *getRoot() const { return _root; } inline gfx::Device *getDevice() const { return _device; } - inline IProgramInfo *getShaderInfo() const { return _shaderInfo; } - gfx::DescriptorSetLayout *getLocalSetLayout() const; + inline const IProgramInfo *getShaderInfo() const { return _shaderInfo; } + const gfx::DescriptorSetLayout *getLocalSetLayout() const; inline const ccstd::string &getProgram() const { return _programName; } inline const Record &getProperties() const { return _properties; } inline const MacroRecord &getDefines() const { return _defines; } @@ -306,6 +306,19 @@ public: virtual void beginChangeStatesSilently() {} virtual void endChangeStatesSilently() {} +private: + void buildUniformBlocks( + const ccstd::vector &blocks, + const ccstd::vector &blockSizes); + void buildMaterialUniformBlocks( + const ccstd::vector &blocks, + const ccstd::vector &blockSizes); + void buildUniformBlock( + uint32_t binding, int32_t size, + gfx::BufferViewInfo &bufferViewInfo, + ccstd::vector &startOffsets, + size_t &count); + protected: void setState(const gfx::BlendState &bs, const gfx::DepthStencilState &dss, const gfx::RasterizerState &rs, gfx::DescriptorSet *ds); void doInit(const IPassInfoFull &info, bool copyDefines = false); @@ -325,7 +338,7 @@ protected: IntrusivePtr _rootBlock; ccstd::vector _blocks; // Point to position in _rootBlock - IProgramInfo *_shaderInfo; // weakref to template of ProgramLib + const IProgramInfo *_shaderInfo; // weakref to template of ProgramLib MacroRecord _defines; Record _properties; IntrusivePtr _shader; diff --git a/native/tools/swig-config/assets.i b/native/tools/swig-config/assets.i index abffcf8888..b21252ae46 100644 --- a/native/tools/swig-config/assets.i +++ b/native/tools/swig-config/assets.i @@ -62,6 +62,8 @@ %ignore cc::EffectAsset::_techniques; %ignore cc::EffectAsset::_shaders; %ignore cc::EffectAsset::_combinations; +%ignore cc::IPassInfoFull::passID; +%ignore cc::IPassInfoFull::phaseID; // ----- Rename Section ------ // Brief: Classes, methods or attributes needs to be renamed diff --git a/native/tools/swig-config/pipeline.i b/native/tools/swig-config/pipeline.i index d19faad42d..5d15c9e216 100644 --- a/native/tools/swig-config/pipeline.i +++ b/native/tools/swig-config/pipeline.i @@ -167,7 +167,7 @@ using namespace cc; %attribute(cc::pipeline::PipelineSceneData, cc::scene::Skybox*, skybox, getSkybox); %attribute(cc::pipeline::PipelineSceneData, cc::scene::Shadows*, shadows, getShadows); %attribute(cc::pipeline::PipelineSceneData, cc::gi::LightProbes*, lightProbes, getLightProbes); - +%attribute(cc::pipeline::PipelineSceneData, ccstd::vector, validPunctualLights, getValidPunctualLights, setValidPunctualLights); %attribute(cc::pipeline::RenderStage, ccstd::string&, _name, getName, setName); %attribute(cc::pipeline::RenderStage, uint32_t, _priority, getPriority, setPriority); diff --git a/templates/launcher/application.ejs b/templates/launcher/application.ejs index 9b688444b2..5ad2fdae89 100644 --- a/templates/launcher/application.ejs +++ b/templates/launcher/application.ejs @@ -3,7 +3,6 @@ let cc; export class Application { constructor () { this.settingsPath = '<%= settingsJsonPath %>'; - this.effectSettingsPath = 'src/effect.bin'; this.showFPS = <%= showFPS %>; } @@ -26,7 +25,6 @@ export class Application { return cc.game.init({ debugMode: <%= debugMode %> ? cc.DebugMode.INFO : cc.DebugMode.ERROR, settingsPath: this.settingsPath, - effectSettingsPath: this.effectSettingsPath, overrideSettings: { // assets: { // preloadBundles: [{ bundle: 'main', version: 'xxx' }],