From 174ba0eff2b2327f924ad96b87fb0c6d4f4c85b1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 30 Jun 2022 10:25:02 +0800 Subject: [PATCH] Add macros: CC_USE_GEOMETRY_RENDERER and CC_USE_DEBUG_RENDERER to control these debugging features. (#11740) --- native/CMakeLists.txt | 28 ++++++++++++-- native/cocos/engine/Engine.cpp | 14 +++++-- native/cocos/profiler/Profiler.cpp | 8 +++- .../renderer/pipeline/GeometryRenderer.h | 18 ++++++--- .../renderer/pipeline/PipelineSceneData.cpp | 5 +++ .../renderer/pipeline/RenderPipeline.cpp | 22 ++++++++--- .../cocos/renderer/pipeline/RenderPipeline.h | 17 +++++++-- .../pipeline/custom/NativePipelineImpl.cpp | 16 +++++--- .../pipeline/deferred/DeferredPipeline.cpp | 4 +- .../pipeline/deferred/LightingStage.cpp | 13 ++++++- .../pipeline/deferred/PostProcessStage.cpp | 2 + .../pipeline/forward/ForwardPipeline.cpp | 4 +- .../pipeline/forward/ForwardStage.cpp | 9 ++++- .../cocos/renderer/pipeline/helper/Utils.cpp | 6 ++- native/cocos/renderer/pipeline/helper/Utils.h | 2 + native/cocos/scene/Camera.cpp | 8 +++- native/cocos/scene/Camera.h | 10 ++++- native/tools/bindings-generator/generator.py | 38 +++++++++++++++++++ .../spidermonkey/templates/ifunction.c | 9 +++++ .../templates/ifunction_overloaded.c | 9 +++++ .../spidermonkey/templates/layout_foot.c | 6 +++ .../targets/spidermonkey/templates/prelude.c | 3 ++ .../targets/spidermonkey/templates/prelude.h | 3 ++ .../targets/spidermonkey/templates/register.c | 3 ++ native/tools/tojs/pipeline.ini | 6 ++- native/tools/tojs/render.ini | 2 + native/tools/tojs/scene.ini | 2 + templates/common/CMakeLists.txt | 2 + 28 files changed, 231 insertions(+), 38 deletions(-) diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 7e77d3e720..21d1272437 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -30,6 +30,8 @@ cc_set_if_undefined(USE_MODULES OFF) cc_set_if_undefined(USE_SERVER_MODE OFF) cc_set_if_undefined(USE_CCACHE OFF) cc_set_if_undefined(USE_PLUGINS ON) +cc_set_if_undefined(USE_DEBUG_RENDERER ON) +cc_set_if_undefined(USE_GEOMETRY_RENDERER ON) add_definitions() @@ -1160,8 +1162,6 @@ cocos_source_files( cocos/renderer/pipeline/deferred/PostProcessStage.h cocos/renderer/pipeline/UIPhase.cpp cocos/renderer/pipeline/UIPhase.h - cocos/renderer/pipeline/GeometryRenderer.h - cocos/renderer/pipeline/GeometryRenderer.cpp cocos/renderer/pipeline/helper/Utils.h cocos/renderer/pipeline/helper/Utils.cpp cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -1208,6 +1208,13 @@ cocos_source_files( cocos/renderer/pipeline/custom/RenderInterfaceTypes.h ) +if (USE_GEOMETRY_RENDERER) + cocos_source_files( + cocos/renderer/pipeline/GeometryRenderer.h + cocos/renderer/pipeline/GeometryRenderer.cpp + ) +endif() + ##### terrain # # cocos_source_files( @@ -1289,9 +1296,14 @@ cocos_source_files( ) ##### profiler +if (USE_DEBUG_RENDERER) cocos_source_files( cocos/profiler/DebugRenderer.h cocos/profiler/DebugRenderer.cpp +) +endif() + +cocos_source_files( cocos/profiler/Profiler.h cocos/profiler/Profiler.cpp cocos/profiler/GameStats.h @@ -1806,8 +1818,6 @@ cocos_source_files( cocos/core/assets/BitmapFont.cpp cocos/core/assets/Font.h cocos/core/assets/Font.cpp - cocos/core/assets/FreeTypeFont.h - cocos/core/assets/FreeTypeFont.cpp # builtin cocos/core/builtin/BuiltinResMgr.cpp @@ -1906,6 +1916,14 @@ cocos_source_files( ) +# FreeTypeFont is used in DebugRenderer currently +if (USE_DEBUG_RENDERER) +cocos_source_files( + cocos/core/assets/FreeTypeFont.h + cocos/core/assets/FreeTypeFont.cpp +) +endif() + cocos_source_files(MODULE ccgeometry cocos/core/geometry/AABB.cpp cocos/core/geometry/AABB.h @@ -2829,6 +2847,8 @@ function(cc_apply_definations target) $,CC_USE_JOB_SYSTEM_TBB=1,CC_USE_JOB_SYSTEM_TBB=0> $,CC_USE_JOB_SYSTEM_TASKFLOW=1,CC_USE_JOB_SYSTEM_TASKFLOW=0> $,CC_USE_PHYSICS_PHYSX=1,CC_USE_PHYSICS_PHYSX=0> + $,CC_USE_DEBUG_RENDERER=1,CC_USE_DEBUG_RENDERER=0> + $,CC_USE_GEOMETRY_RENDERER=1,CC_USE_GEOMETRY_RENDERER=0> $,CC_EDITOR=1,CC_EDITOR=0> $<$:SCRIPT_ENGINE_TYPE=1> $<$:CC_DEBUG=1> diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index 664936adcc..856ba86c3c 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -60,7 +60,9 @@ #include "core/assets/FreeTypeFont.h" #include "network/HttpClient.h" #include "platform/interfaces/modules/ISystemWindow.h" -#include "profiler/DebugRenderer.h" +#if CC_USE_DEBUG_RENDERER + #include "profiler/DebugRenderer.h" +#endif #include "profiler/Profiler.h" namespace { @@ -107,7 +109,10 @@ int32_t Engine::init() { _programLib = ccnew ProgramLib(); _builtinResMgr = ccnew BuiltinResMgr; +#if CC_USE_DEBUG_RENDERER _debugRenderer = ccnew DebugRenderer(); +#endif + #if CC_USE_PROFILER _profiler = ccnew Profiler(); #endif @@ -149,11 +154,15 @@ void Engine::destroy() { #endif // Profiler depends on DebugRenderer, should delete it after deleting Profiler, // and delete DebugRenderer after RenderPipeline::destroy which destroy DebugRenderer. +#if CC_USE_DEBUG_RENDERER delete _debugRenderer; +#endif //TODO(): Delete some global objects. - +#if CC_USE_DEBUG_RENDERER + // FreeTypeFontFace is only used in DebugRenderer now, so use CC_USE_DEBUG_RENDERER macro temporarily FreeTypeFontFace::destroyFreeType(); +#endif #if CC_USE_DRAGONBONES dragonBones::ArmatureCacheMgr::destroyInstance(); @@ -213,7 +222,6 @@ void Engine::close() { // NOLINT _scheduler->unscheduleAll(); BasePlatform::getPlatform()->setHandleEventCallback(nullptr); - // TODO(timlyeee): The code below is a hack on v3.6, and should be replaced in the future. exit(0); diff --git a/native/cocos/profiler/Profiler.cpp b/native/cocos/profiler/Profiler.cpp index 6e6f15e54c..0d9d81d739 100644 --- a/native/cocos/profiler/Profiler.cpp +++ b/native/cocos/profiler/Profiler.cpp @@ -24,7 +24,9 @@ ****************************************************************************/ #include "Profiler.h" -#include "DebugRenderer.h" +#if CC_USE_DEBUG_RENDERER + #include "DebugRenderer.h" +#endif #include "application/ApplicationManager.h" #include "base/Log.h" #include "base/Macros.h" @@ -129,7 +131,7 @@ Profiler::Profiler() { _mainThreadId = std::this_thread::get_id(); _root = ccnew ProfilerBlock(nullptr, "MainThread"); _current = _root; - + Profiler::instance = this; } @@ -218,6 +220,7 @@ void Profiler::doFrameUpdate() { } void Profiler::printStats() { +#if CC_USE_DEBUG_RENDERER auto *renderer = CC_DEBUG_RENDERER; const auto *window = CC_CURRENT_ENGINE()->getInterface(); const auto viewSize = window->getViewSize() * Device::getDevicePixelRatio(); @@ -382,6 +385,7 @@ void Profiler::printStats() { lines += 0.5F; } +#endif } void Profiler::beginBlock(const ccstd::string &name) { diff --git a/native/cocos/renderer/pipeline/GeometryRenderer.h b/native/cocos/renderer/pipeline/GeometryRenderer.h index 51ed454889..a14e7c7c21 100644 --- a/native/cocos/renderer/pipeline/GeometryRenderer.h +++ b/native/cocos/renderer/pipeline/GeometryRenderer.h @@ -25,12 +25,16 @@ #pragma once -#include "base/Macros.h" -#include "base/RefCounted.h" -#include "gfx-base/GFXDef-common.h" -#include "math/Vec2.h" -#include "math/Vec3.h" -#include "math/Vec4.h" +// NOTE: Still need to wrap all code in CC_USE_GEOMETRY_RENDERER block +// since auto-generated binding code will include GeometryRenderer.h +#if CC_USE_GEOMETRY_RENDERER + + #include "base/Macros.h" + #include "base/RefCounted.h" + #include "gfx-base/GFXDef-common.h" + #include "math/Vec2.h" + #include "math/Vec3.h" + #include "math/Vec4.h" namespace cc { @@ -110,3 +114,5 @@ private: } // namespace pipeline } // namespace cc + +#endif // #if CC_USE_GEOMETRY_RENDERER diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.cpp b/native/cocos/renderer/pipeline/PipelineSceneData.cpp index 6b46116a3e..3612213a1c 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.cpp +++ b/native/cocos/renderer/pipeline/PipelineSceneData.cpp @@ -60,8 +60,13 @@ PipelineSceneData::~PipelineSceneData() { void PipelineSceneData::activate(gfx::Device *device) { _device = device; +#if CC_USE_GEOMETRY_RENDERER initGeometryRenderer(); +#endif + +#if CC_USE_DEBUG_RENDERER initDebugRenderer(); +#endif initOcclusionQuery(); } diff --git a/native/cocos/renderer/pipeline/RenderPipeline.cpp b/native/cocos/renderer/pipeline/RenderPipeline.cpp index ecddf48c37..317f88e164 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.cpp +++ b/native/cocos/renderer/pipeline/RenderPipeline.cpp @@ -25,7 +25,9 @@ #include "RenderPipeline.h" #include "BatchedBuffer.h" -#include "GeometryRenderer.h" +#if CC_USE_GEOMETRY_RENDERER + #include "GeometryRenderer.h" +#endif #include "GlobalDescriptorSetManager.h" #include "InstancedBuffer.h" #include "PipelineSceneData.h" @@ -38,7 +40,9 @@ #include "frame-graph/FrameGraph.h" #include "gfx-base/GFXDevice.h" #include "helper/Utils.h" -#include "profiler/DebugRenderer.h" +#if CC_USE_DEBUG_RENDERER + #include "profiler/DebugRenderer.h" +#endif #include "scene/Camera.h" #include "scene/Skybox.h" @@ -83,7 +87,9 @@ bool RenderPipeline::activate(gfx::Swapchain * /*swapchain*/) { _descriptorSet = _globalDSManager->getGlobalDescriptorSet(); _pipelineUBO->activate(_device, this); _pipelineSceneData->activate(_device); +#if CC_USE_DEBUG_RENDERER CC_DEBUG_RENDERER->activate(_device); +#endif // generate macros here rather than construct func because _clusterEnabled // switch may be changed in root.ts setRenderPipeline() function which is after @@ -125,19 +131,21 @@ void RenderPipeline::destroyQuadInputAssembler() { _quadIA.clear(); } +#if CC_USE_GEOMETRY_RENDERER void RenderPipeline::updateGeometryRenderer(const ccstd::vector &cameras) { if (_geometryRenderer) { - return ; + return; } - + // Query the first camera rendering to swapchain. for (const auto *camera : cameras) { - if (camera && camera->getWindow() && camera->getWindow()->getSwapchain() ) { + if (camera && camera->getWindow() && camera->getWindow()->getSwapchain()) { _geometryRenderer = camera->getGeometryRenderer(); return; } } } +#endif bool RenderPipeline::destroy() { for (auto *flow : _flows) { @@ -145,12 +153,16 @@ bool RenderPipeline::destroy() { } _flows.clear(); +#if CC_USE_GEOMETRY_RENDERER _geometryRenderer = nullptr; +#endif _descriptorSet = nullptr; CC_SAFE_DESTROY_AND_DELETE(_globalDSManager); CC_SAFE_DESTROY_AND_DELETE(_pipelineUBO); CC_SAFE_DESTROY_NULL(_pipelineSceneData); +#if CC_USE_DEBUG_RENDERER CC_DEBUG_RENDERER->destroy(); +#endif for (auto *const queryPool : _queryPools) { queryPool->destroy(); diff --git a/native/cocos/renderer/pipeline/RenderPipeline.h b/native/cocos/renderer/pipeline/RenderPipeline.h index 5aad22e013..cebf617939 100644 --- a/native/cocos/renderer/pipeline/RenderPipeline.h +++ b/native/cocos/renderer/pipeline/RenderPipeline.h @@ -120,16 +120,24 @@ public: inline bool isBloomEnabled() const { return _bloomEnabled; } inline void setBloomEnabled(bool enable) { _bloomEnabled = enable; } - - inline GeometryRenderer *getGeometryRenderer() const { return _geometryRenderer; } + + inline GeometryRenderer *getGeometryRenderer() const { +#if CC_USE_GEOMETRY_RENDERER + return _geometryRenderer; +#else + return nullptr; +#endif + } protected: static RenderPipeline *instance; void generateConstantMacros(); void destroyQuadInputAssembler(); - + +#if CC_USE_GEOMETRY_RENDERER void updateGeometryRenderer(const ccstd::vector &cameras); +#endif static void framegraphGC(); @@ -151,7 +159,10 @@ protected: PipelineUBO *_pipelineUBO{nullptr}; IntrusivePtr _profiler; IntrusivePtr _pipelineSceneData; + +#if CC_USE_GEOMETRY_RENDERER IntrusivePtr _geometryRenderer; +#endif // has not initBuiltinRes, // create temporary default Texture to binding sampler2d diff --git a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp b/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp index e9a530509f..2dcc81ecd1 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipelineImpl.cpp @@ -62,7 +62,9 @@ #include "pipeline/custom/Range.h" #include "pipeline/custom/RenderGraphTypes.h" #include "pipeline/custom/RenderInterfaceTypes.h" -#include "profiler/DebugRenderer.h" +#if CC_USE_DEBUG_RENDERER + #include "profiler/DebugRenderer.h" +#endif namespace cc { @@ -273,10 +275,10 @@ LayoutGraphBuilder *NativePipeline::getLayoutGraphBuilder() { return ccnew NativeLayoutGraphBuilder(device, &layoutGraph); } -gfx::DescriptorSetLayout *NativePipeline::getDescriptorSetLayout(const ccstd::string& shaderName, UpdateFrequency freq) { +gfx::DescriptorSetLayout *NativePipeline::getDescriptorSetLayout(const ccstd::string &shaderName, UpdateFrequency freq) { auto iter = layoutGraph.shaderLayoutIndex.find(boost::string_view(shaderName)); if (iter != layoutGraph.shaderLayoutIndex.end()) { - const auto& layouts = get(LayoutGraphData::Layout, layoutGraph, iter->second).descriptorSets; + const auto &layouts = get(LayoutGraphData::Layout, layoutGraph, iter->second).descriptorSets; auto iter2 = layouts.find(freq); if (iter2 != layouts.end()) { return iter2->second.descriptorSetLayout.get(); @@ -318,7 +320,9 @@ bool NativePipeline::activate(gfx::Swapchain *swapchainIn) { macros["CC_PIPELINE_TYPE"] = 0; globalDSManager->activate(device); pipelineSceneData->activate(device); +#if CC_USE_DEBUG_RENDERER DebugRenderer::getInstance()->activate(device); +#endif // generate macros here rather than construct func because _clusterEnabled // switch may be changed in root.ts setRenderPipeline() function which is after @@ -494,15 +498,15 @@ void NativePipeline::setShadingScale(float scale) { pipelineSceneData->setShadingScale(scale); } -void NativePipeline::setMacroString(const ccstd::string& name, const ccstd::string& value) { +void NativePipeline::setMacroString(const ccstd::string &name, const ccstd::string &value) { macros[name] = value; } -void NativePipeline::setMacroInt(const ccstd::string& name, int32_t value) { +void NativePipeline::setMacroInt(const ccstd::string &name, int32_t value) { macros[name] = value; } -void NativePipeline::setMacroBool(const ccstd::string& name, bool value) { +void NativePipeline::setMacroBool(const ccstd::string &name, bool value) { macros[name] = value; } diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index 9e941c0b4d..4534047d30 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -105,8 +105,10 @@ bool DeferredPipeline::activate(gfx::Swapchain *swapchain) { void DeferredPipeline::render(const ccstd::vector &cameras) { CC_PROFILE(DeferredPipelineRender); +#if CC_USE_GEOMETRY_RENDERER updateGeometryRenderer(cameras); // for capability - +#endif + auto *device = gfx::Device::getInstance(); bool enableOcclusionQuery = isOcclusionQueryEnabled(); if (enableOcclusionQuery) { diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index b8f5c16420..3dc834d7e4 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -26,7 +26,9 @@ #include "LightingStage.h" #include "../BatchedBuffer.h" #include "../Define.h" -#include "../GeometryRenderer.h" +#if CC_USE_GEOMETRY_RENDERER + #include "../GeometryRenderer.h" +#endif #include "../GlobalDescriptorSetManager.h" #include "../InstancedBuffer.h" #include "../PipelineStateManager.h" @@ -526,12 +528,19 @@ void LightingStage::fgTransparent(scene::Camera *camera) { } _planarShadowQueue->recordCommandBuffer(_device, table.getRenderPass(), cmdBuff); +#if CC_USE_GEOMETRY_RENDERER if (camera->getGeometryRenderer()) { camera->getGeometryRenderer()->render(table.getRenderPass(), cmdBuff, pipeline->getPipelineSceneData()); } +#endif }; - if (!_isTransparentQueueEmpty || (camera->getGeometryRenderer() && !camera->getGeometryRenderer()->empty())) { + if (!_isTransparentQueueEmpty +#if CC_USE_GEOMETRY_RENDERER + || (camera->getGeometryRenderer() && !camera->getGeometryRenderer()->empty())) { +#else + ) { +#endif pipeline->getFrameGraph().addPass(static_cast(DeferredInsertPoint::DIP_TRANSPARENT), DeferredPipeline::fgStrHandleTransparentPass, transparentSetup, transparentExec); } diff --git a/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp b/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp index 57e150dd7a..383c69ce58 100644 --- a/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/PostProcessStage.cpp @@ -227,7 +227,9 @@ void PostProcessStage::render(scene::Camera *camera) { _uiPhase->render(camera, renderPass); renderProfiler(renderPass, cmdBuff, pipeline->getProfiler(), camera); +#if CC_USE_DEBUG_RENDERER renderDebugRenderer(renderPass, cmdBuff, pipeline->getPipelineSceneData(), camera); +#endif }; // add pass diff --git a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp index 4fa57244e4..0830973530 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardPipeline.cpp @@ -89,8 +89,10 @@ bool ForwardPipeline::activate(gfx::Swapchain *swapchain) { void ForwardPipeline::render(const ccstd::vector &cameras) { CC_PROFILE(ForwardPipelineRender); +#if CC_USE_GEOMETRY_RENDERER updateGeometryRenderer(cameras); // for capability - +#endif + auto *device = gfx::Device::getInstance(); const bool enableOcclusionQuery = isOcclusionQueryEnabled(); if (enableOcclusionQuery) { diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index efb455f205..ecc4c173f4 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -25,7 +25,9 @@ #include "ForwardStage.h" #include "../BatchedBuffer.h" -#include "../GeometryRenderer.h" +#if CC_USE_GEOMETRY_RENDERER + #include "../GeometryRenderer.h" +#endif #include "../InstancedBuffer.h" #include "../PipelineSceneData.h" #include "../PipelineUBO.h" @@ -231,13 +233,18 @@ void ForwardStage::render(scene::Camera *camera) { _planarShadowQueue->recordCommandBuffer(_device, renderPass, cmdBuff); _renderQueues[1]->recordCommandBuffer(_device, camera, renderPass, cmdBuff); } + +#if CC_USE_GEOMETRY_RENDERER if (camera->getGeometryRenderer()) { camera->getGeometryRenderer()->render(renderPass, cmdBuff, pipeline->getPipelineSceneData()); } +#endif _uiPhase->render(camera, renderPass); renderProfiler(renderPass, cmdBuff, _pipeline->getProfiler(), camera); +#if CC_USE_DEBUG_RENDERER renderDebugRenderer(renderPass, cmdBuff, _pipeline->getPipelineSceneData(), camera); +#endif }; // add pass diff --git a/native/cocos/renderer/pipeline/helper/Utils.cpp b/native/cocos/renderer/pipeline/helper/Utils.cpp index 91ad676185..7e6ad0471c 100644 --- a/native/cocos/renderer/pipeline/helper/Utils.cpp +++ b/native/cocos/renderer/pipeline/helper/Utils.cpp @@ -25,7 +25,9 @@ #include "renderer/pipeline/helper/Utils.h" #include "renderer/pipeline/PipelineStateManager.h" -#include "profiler/DebugRenderer.h" +#if CC_USE_DEBUG_RENDERER + #include "profiler/DebugRenderer.h" +#endif #include "gfx-base/GFXSwapchain.h" #include "pipeline/Define.h" #include "scene/Camera.h" @@ -71,6 +73,7 @@ void renderProfiler(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff, sc } } +#if CC_USE_DEBUG_RENDERER void renderDebugRenderer(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff, PipelineSceneData *sceneData, const scene::Camera *camera) { if (camera != profilerCamera) { return; @@ -78,6 +81,7 @@ void renderDebugRenderer(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuf CC_DEBUG_RENDERER->render(renderPass, cmdBuff, sceneData); } +#endif } // namespace pipeline } // namespace cc diff --git a/native/cocos/renderer/pipeline/helper/Utils.h b/native/cocos/renderer/pipeline/helper/Utils.h index 46043a2050..c904ea06cc 100644 --- a/native/cocos/renderer/pipeline/helper/Utils.h +++ b/native/cocos/renderer/pipeline/helper/Utils.h @@ -71,7 +71,9 @@ extern const scene::Camera *profilerCamera; void decideProfilerCamera(const ccstd::vector &cameras); void renderProfiler(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff, scene::Model *profiler, const scene::Camera *camera); +#if CC_USE_DEBUG_RENDERER void renderDebugRenderer(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff, PipelineSceneData *sceneData, const scene::Camera *camera); +#endif } // namespace pipeline } // namespace cc diff --git a/native/cocos/scene/Camera.cpp b/native/cocos/scene/Camera.cpp index 6d9d54c48e..8f9958754e 100644 --- a/native/cocos/scene/Camera.cpp +++ b/native/cocos/scene/Camera.cpp @@ -30,7 +30,9 @@ #include "math/MathUtil.h" #include "renderer/gfx-base/GFXDevice.h" #include "renderer/pipeline/Define.h" -#include "renderer/pipeline/GeometryRenderer.h" +#if CC_USE_GEOMETRY_RENDERER + #include "renderer/pipeline/GeometryRenderer.h" +#endif namespace cc { namespace scene { @@ -104,7 +106,9 @@ void Camera::destroy() { _window = nullptr; } _name.clear(); +#if CC_USE_GEOMETRY_RENDERER CC_SAFE_DESTROY_NULL(_geometryRenderer); +#endif CC_SAFE_RELEASE_NULL(_frustum); } @@ -216,10 +220,12 @@ void Camera::changeTargetWindow(RenderWindow *window) { } void Camera::initGeometryRenderer() { +#if CC_USE_GEOMETRY_RENDERER if (!_geometryRenderer) { _geometryRenderer = ccnew pipeline::GeometryRenderer(); _geometryRenderer->activate(_device); } +#endif } void Camera::detachCamera() { diff --git a/native/cocos/scene/Camera.h b/native/cocos/scene/Camera.h index f5925fcb9a..7391d7a188 100644 --- a/native/cocos/scene/Camera.h +++ b/native/cocos/scene/Camera.h @@ -313,7 +313,13 @@ public: inline gfx::SurfaceTransform getSurfaceTransform() const { return _curTransform; } void initGeometryRenderer(); - inline pipeline::GeometryRenderer *getGeometryRenderer() const { return _geometryRenderer.get(); } + inline pipeline::GeometryRenderer *getGeometryRenderer() const { +#if CC_USE_GEOMETRY_RENDERER + return _geometryRenderer.get(); +#else + return nullptr; +#endif + } void detachCamera(); @@ -365,7 +371,9 @@ private: gfx::ClearFlagBit _clearFlag{gfx::ClearFlagBit::NONE}; float _clearDepth{1.0F}; +#if CC_USE_GEOMETRY_RENDERER IntrusivePtr _geometryRenderer; +#endif static const ccstd::vector FSTOPS; static const ccstd::vector SHUTTERS; diff --git a/native/tools/bindings-generator/generator.py b/native/tools/bindings-generator/generator.py index a145d42cbc..0fd7a1e3c1 100755 --- a/native/tools/bindings-generator/generator.py +++ b/native/tools/bindings-generator/generator.py @@ -1109,6 +1109,7 @@ class NativeClass(object): self.is_abstract = self.class_name in generator.abstract_classes self.is_persistent = self.class_name in generator.persistent_classes self.is_class_owned_by_cpp = self.class_name in self.generator.classes_owned_by_cpp + self.module_config = self.generator.class_module_configs[self.class_name] if self.class_name in self.generator.class_module_configs else {} # logger.info("class_name:" + self.class_name + ", is_class_owned_by_cpp:" + str(self.is_class_owned_by_cpp)) self._current_visibility = cindex.AccessSpecifier.PRIVATE if is_struct: @@ -1323,6 +1324,9 @@ class NativeClass(object): register = Template(file=os.path.join(self.generator.target, "templates", "register.c"), searchList=[{"current_class": self}]) self.generator.impl_file.write(unicode(register)) + if len(self.module_config) > 0: + self.generator.head_file.write('#endif //' + self.module_config[0] + '\n') + self.generator.class_json_list.append(self.toJSON()) def should_export_field(self, field_name): @@ -1595,6 +1599,8 @@ class Generator(object): self.impl_file = None self.head_file = None self.json_file = None + self.class_module_configs = {} + self.method_module_configs = {} self.skip_classes = {} self.skip_public_fields_classes = {} self.bind_fields = {} @@ -1645,6 +1651,31 @@ class Generator(object): if sys.platform == 'win32' and self.win32_clang_flags != None: self.clang_args.extend(self.win32_clang_flags) + if opts['class_module_configs']: + class_module_configs = re.split(",\n?", opts['class_module_configs']) + for class_module_config in class_module_configs: + class_name, macros = class_module_config.split("::") + self.class_module_configs[class_name] = [] + match = re.match("\[([^]]+)\]", macros) + if match: + self.class_module_configs[class_name] = match.group(1).split(" ") + else: + raise Exception("invalid list of class_module_configs methods") + + if opts['method_module_configs']: + method_module_configs = re.split(",\n?", opts['method_module_configs']) + for method_module_config in method_module_configs: + class_name, config_group = method_module_config.split("::") + self.method_module_configs[class_name] = {} + match = re.match("\[([^]]+)\]", config_group) + if match: + method_config_list = match.group(1).split(" ") + for method_config in method_config_list: + method_name, macro = method_config.split('/') + self.method_module_configs[class_name][method_name] = macro + else: + raise Exception("invalid list of method_module_configs methods") + if opts['skip']: list_of_skips = re.split(",\n?", opts['skip']) for skip in list_of_skips: @@ -1771,6 +1802,11 @@ class Generator(object): return self.rename_functions[class_name][method_name] return None + def get_method_module_macro(self, class_name, method_name): + if class_name in self.method_module_configs and method_name in self.method_module_configs[class_name]: + return self.method_module_configs[class_name][method_name] + return None + def get_class_or_rename_class(self, class_name): if class_name in self.rename_classes: @@ -2330,6 +2366,8 @@ def main(): 'base_classes_to_skip': config.get(s, 'base_classes_to_skip'), 'getter_setter': config.get(s, 'getter_setter') if config.has_option(s, 'getter_setter') else "", 'abstract_classes': config.get(s, 'abstract_classes'), + 'class_module_configs': config.get(s, 'class_module_configs') if config.has_option(s, 'class_module_configs') else {}, + 'method_module_configs': config.get(s, 'method_module_configs') if config.has_option(s, 'method_module_configs') else {}, 'persistent_classes': config.get(s, 'persistent_classes') if config.has_option(s, 'persistent_classes') else None, 'classes_owned_by_cpp': config.get(s, 'classes_owned_by_cpp') if config.has_option(s, 'classes_owned_by_cpp') else None, 'skip': config.get(s, 'skip'), diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c index 5c3871d3bf..654d64b6c5 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c @@ -2,6 +2,10 @@ static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming) { +#set $module_macro = $generator.get_method_module_macro($class_name, $func_name) +#if $module_macro +\#if $module_macro +#end if auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); // SE_PRECONDITION2(cobj, false, "${signature_name} : Invalid Native Object"); if (nullptr == cobj) return true; @@ -87,6 +91,11 @@ static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-nam SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, $arg_count); #end if return false; +#if $module_macro +\#else + return true; +\#endif // \#if $module_macro +#end if } #if $current_class is not None #if $current_class.is_getter_attribute($func_name) diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c index 488180825c..06672fbb98 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c @@ -2,6 +2,10 @@ static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming) { +#set $module_macro = $generator.get_method_module_macro($class_name, $func_name) +#if $module_macro +\#if $module_macro +#end if CC_UNUSED bool ok = true; auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); // SE_PRECONDITION2( cobj, false, "${signature_name} : Invalid Native Object"); @@ -83,6 +87,11 @@ static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-nam #end for SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; +#if $module_macro +\#else + return true; +\#endif // \#if $module_macro +#end if } #if $current_class is not None #if $current_class.is_getter_attribute($func_name) diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c b/native/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c index f4c295d3a4..bb06f97e70 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/layout_foot.c @@ -17,7 +17,13 @@ bool register_all_${prefix}(se::Object* obj) // NOLINT #for jsclass in $sorted_classes #if $in_listed_classes(jsclass.class_name) + #if len($jsclass.module_config) > 0 + \#if $jsclass.module_config[0] + #end if js_register_${prefix}_${jsclass.nested_class_name}(ns); + #if len($jsclass.module_config) > 0 + \#endif // $jsclass.module_config[0] + #end if #end if #end for return true; diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.c b/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.c index 0bf1fde052..4edf0fd8bf 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.c @@ -1,3 +1,6 @@ #set generator = $current_class.generator +#if len($current_class.module_config) > 0 +\#if $current_class.module_config[0] +#end if se::Object* __jsb_${current_class.underlined_class_name}_proto = nullptr; // NOLINT se::Class* __jsb_${current_class.underlined_class_name}_class = nullptr; // NOLINT diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.h b/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.h index 423a3ad6d2..d480d34878 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.h +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/prelude.h @@ -1,5 +1,8 @@ #set generator = $current_class.generator +#if len($current_class.module_config) > 0 +\#if $current_class.module_config[0] +#end if extern se::Object *__jsb_${current_class.underlined_class_name}_proto; // NOLINT extern se::Class * __jsb_${current_class.underlined_class_name}_class; // NOLINT diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/register.c b/native/tools/bindings-generator/targets/spidermonkey/templates/register.c index 416146f865..f23d84c955 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/register.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/register.c @@ -110,3 +110,6 @@ bool js_register_${generator.prefix}_${current_class.nested_class_name}(se::Obje se::ScriptEngine::getInstance()->clearException(); return true; } +#if len($current_class.module_config) > 0 +\#endif // $current_class.module_config[0] +#end if diff --git a/native/tools/tojs/pipeline.ini b/native/tools/tojs/pipeline.ini index b537f2865c..ec1199165d 100644 --- a/native/tools/tojs/pipeline.ini +++ b/native/tools/tojs/pipeline.ini @@ -17,7 +17,7 @@ clang_headers = clang_flags = -nostdinc -x c++ -std=c++17 -fsigned-char -mfloat-abi=soft -U__SSE__ cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/renderer -I%(cocosdir)s -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/sources -I%(cocosdir)s/external/android/armeabi-v7a/include/v8 -I%(cocosdir)s/external/android/armeabi-v7a/include/uv -cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_IOS=1 -DCC_PLATFORM_MACOS=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 +cocos_flags = -DANDROID -DCC_PLATFORM=3 -DCC_PLATFORM_IOS=1 -DCC_PLATFORM_MACOS=4 -DCC_PLATFORM_WINDOWS=2 -DCC_PLATFORM_ANDROID=3 -DCC_USE_GEOMETRY_RENDERER=1 -DCC_USE_DEBUG_RENDERER=1 cxxgenerator_headers = @@ -79,3 +79,7 @@ base_classes_to_skip = Clonable Object RefCounted # classes that create no constructor # Set is special and we will use a hand-written constructor abstract_classes = RenderStage RenderFlow RenderPipeline + +class_module_configs = GeometryRenderer::[CC_USE_GEOMETRY_RENDERER] +method_module_configs = RenderPipeline::[getGeometryRenderer/CC_USE_GEOMETRY_RENDERER] + diff --git a/native/tools/tojs/render.ini b/native/tools/tojs/render.ini index cd9cb628c6..c5c4719a78 100644 --- a/native/tools/tojs/render.ini +++ b/native/tools/tojs/render.ini @@ -80,3 +80,5 @@ persistent_classes = classes_owned_by_cpp = obtain_return_value = + +method_module_configs = PipelineRuntime::[getGeometryRenderer/CC_USE_GEOMETRY_RENDERER] diff --git a/native/tools/tojs/scene.ini b/native/tools/tojs/scene.ini index 3ef3c89941..61ce2f177e 100644 --- a/native/tools/tojs/scene.ini +++ b/native/tools/tojs/scene.ini @@ -144,3 +144,5 @@ base_classes_to_skip = RefCounted # classes that create no constructor # Set is special and we will use a hand-written constructor abstract_classes = EventListener ProgramLib + +method_module_configs = Camera::[getGeometryRenderer/CC_USE_GEOMETRY_RENDERER] diff --git a/templates/common/CMakeLists.txt b/templates/common/CMakeLists.txt index e2772dc2c8..283a259a2c 100755 --- a/templates/common/CMakeLists.txt +++ b/templates/common/CMakeLists.txt @@ -23,6 +23,8 @@ option(USE_WEBSOCKET_SERVER "Enable WebSocket Server" OFF) option(USE_JOB_SYSTEM_TASKFLOW "Use taskflow as job system backend" OFF) option(USE_JOB_SYSTEM_TBB "Use tbb as job system backend" OFF) option(USE_PHYSICS_PHYSX "USE PhysX Physics" ON) +option(USE_DEBUG_RENDERER "USE Debug Renderer" ON) +option(USE_GEOMETRY_RENDERER "USE Geometry Renderer" ON) if(NOT RES_DIR) message(FATAL_ERROR "RES_DIR is not set!")