mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
Changed the GeometryRenderer and DebugRenderer from using intrusive calls to registering callbacks. (#330)
* Changed the GeometryRenderer and DebugRenderer from using intrusive calls to registering callbacks (custom pipeline). * Changed the GeometryRenderer and DebugRenderer from using intrusive calls to registering callbacks. (old pipeline) * CI error: Function parameter names cannot be omitted. * Move the devil string to macro
This commit is contained in:
@@ -688,6 +688,9 @@ static constexpr uint32_t CLUSTER_LIGHT_BINDING = 4;
|
||||
static constexpr uint32_t CLUSTER_LIGHT_INDEX_BINDING = 5;
|
||||
static constexpr uint32_t CLUSTER_LIGHT_GRID_BINDING = 6;
|
||||
|
||||
constexpr const char *GEOMETRY_RENDERER_COMMAND = "geometry-renderer";
|
||||
constexpr const char *DEBUG_RENDERER_COMMAND = "debug-renderer";
|
||||
|
||||
void localDescriptorSetLayoutResizeMaxJoints(uint32_t maxCount);
|
||||
|
||||
} // namespace pipeline
|
||||
|
||||
@@ -47,6 +47,34 @@
|
||||
namespace cc {
|
||||
namespace pipeline {
|
||||
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
DebugRendererRenderCommand::DebugRendererRenderCommand(PipelineSceneData *sceneData)
|
||||
: _sceneData(sceneData) {
|
||||
}
|
||||
|
||||
void DebugRendererRenderCommand::beginRenderCommand(const RenderCommandContext &ctx) {
|
||||
renderDebugRenderer(ctx.renderPass, ctx.cmdBuff, _sceneData, ctx.camera);
|
||||
}
|
||||
|
||||
void DebugRendererRenderCommand::endRenderCommand(const RenderCommandContext & /*ctx*/) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
GeometryRendererRenderCommand::GeometryRendererRenderCommand(PipelineSceneData *sceneData)
|
||||
: _sceneData(sceneData) {
|
||||
}
|
||||
|
||||
void GeometryRendererRenderCommand::beginRenderCommand(const RenderCommandContext &ctx) {
|
||||
if (ctx.camera && ctx.camera->getGeometryRenderer()) {
|
||||
ctx.camera->getGeometryRenderer()->render(ctx.renderPass, ctx.cmdBuff, _sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
void GeometryRendererRenderCommand::endRenderCommand(const RenderCommandContext & /*ctx*/) {
|
||||
}
|
||||
#endif
|
||||
|
||||
framegraph::StringHandle RenderPipeline::fgStrHandleOutDepthTexture = framegraph::FrameGraph::stringToHandle("depthTexture");
|
||||
framegraph::StringHandle RenderPipeline::fgStrHandleOutColorTexture = framegraph::FrameGraph::stringToHandle("outputTexture");
|
||||
framegraph::StringHandle RenderPipeline::fgStrHandlePostprocessPass = framegraph::FrameGraph::stringToHandle("pipelinePostPass");
|
||||
@@ -87,6 +115,10 @@ bool RenderPipeline::activate(gfx::Swapchain * /*swapchain*/) {
|
||||
_pipelineSceneData->activate(_device);
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
CC_DEBUG_RENDERER->activate(_device);
|
||||
addRenderCommand(cc::pipeline::DEBUG_RENDERER_COMMAND, std::make_shared<DebugRendererRenderCommand>(getPipelineSceneData()));
|
||||
#endif
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
addRenderCommand(cc::pipeline::GEOMETRY_RENDERER_COMMAND, std::make_shared<GeometryRendererRenderCommand>(getPipelineSceneData()));
|
||||
#endif
|
||||
|
||||
// generate macros here rather than construct func because _clusterEnabled
|
||||
@@ -115,6 +147,15 @@ void RenderPipeline::onGlobalPipelineStateChanged() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void RenderPipeline::addRenderCommand(const ccstd::string &name, std::shared_ptr<RenderCommand> ptr) {
|
||||
_renderCommands[name] = std::move(ptr);
|
||||
}
|
||||
|
||||
RenderCommand *RenderPipeline::getRenderCommand(const ccstd::string &name) const {
|
||||
const auto iter = _renderCommands.find(name);
|
||||
return iter == _renderCommands.end() ? nullptr : iter->second.get();
|
||||
}
|
||||
|
||||
void RenderPipeline::destroyQuadInputAssembler() {
|
||||
CC_SAFE_DESTROY_AND_DELETE(_quadIB);
|
||||
|
||||
|
||||
@@ -34,11 +34,14 @@
|
||||
#include "renderer/core/PassUtils.h"
|
||||
#include "scene/Model.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace cc {
|
||||
namespace gfx {
|
||||
class CommandBuffer;
|
||||
class DescriptorSet;
|
||||
class DescriptorSetLayout;
|
||||
class RenderPass;
|
||||
} // namespace gfx
|
||||
namespace scene {
|
||||
class Camera;
|
||||
@@ -54,6 +57,53 @@ class PipelineSceneData;
|
||||
class GlobalDSManager;
|
||||
class RenderStage;
|
||||
class GeometryRenderer;
|
||||
|
||||
struct RenderCommandContext {
|
||||
gfx::RenderPass *renderPass{nullptr};
|
||||
gfx::CommandBuffer *cmdBuff{nullptr};
|
||||
PipelineSceneData *sceneData{nullptr};
|
||||
const scene::Camera *camera{nullptr};
|
||||
};
|
||||
|
||||
class RenderCommand {
|
||||
public:
|
||||
RenderCommand() noexcept = default;
|
||||
RenderCommand(RenderCommand &&rhs) = delete;
|
||||
RenderCommand(RenderCommand const &rhs) = delete;
|
||||
RenderCommand &operator=(RenderCommand &&rhs) = delete;
|
||||
RenderCommand &operator=(RenderCommand const &rhs) = delete;
|
||||
virtual ~RenderCommand() noexcept = default;
|
||||
|
||||
virtual void beginRenderCommand(const RenderCommandContext &ctx) = 0;
|
||||
virtual void endRenderCommand(const RenderCommandContext &ctx) = 0;
|
||||
};
|
||||
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
class DebugRendererRenderCommand final : public RenderCommand {
|
||||
public:
|
||||
explicit DebugRendererRenderCommand(PipelineSceneData *sceneData);
|
||||
|
||||
void beginRenderCommand(const RenderCommandContext &ctx) override;
|
||||
void endRenderCommand(const RenderCommandContext &ctx) override;
|
||||
|
||||
private:
|
||||
PipelineSceneData *_sceneData{nullptr};
|
||||
};
|
||||
#endif
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
class GeometryRendererRenderCommand final : public RenderCommand {
|
||||
public:
|
||||
explicit GeometryRendererRenderCommand(PipelineSceneData *sceneData);
|
||||
|
||||
void beginRenderCommand(const RenderCommandContext &ctx) override;
|
||||
void endRenderCommand(const RenderCommandContext &ctx) override;
|
||||
|
||||
private:
|
||||
PipelineSceneData *_sceneData{nullptr};
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CC_DLL RenderPipelineInfo {
|
||||
uint32_t tag = 0;
|
||||
RenderFlowList flows;
|
||||
@@ -140,6 +190,9 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
void addRenderCommand(const ccstd::string &name, std::shared_ptr<RenderCommand> ptr);
|
||||
RenderCommand *getRenderCommand(const ccstd::string &name) const;
|
||||
|
||||
inline void resetRenderQueue(bool reset) { _resetRenderQueue = reset; }
|
||||
inline bool isRenderQueueReset() const { return _resetRenderQueue; }
|
||||
|
||||
@@ -194,6 +247,7 @@ protected:
|
||||
ccstd::unordered_map<Vec4, gfx::InputAssembler *, Hasher<Vec4>> _quadIA;
|
||||
|
||||
framegraph::FrameGraph _fg;
|
||||
ccstd::unordered_map<ccstd::string, std::shared_ptr<RenderCommand>> _renderCommands;
|
||||
ccstd::unordered_map<gfx::ClearFlags, gfx::RenderPass *> _renderPasses;
|
||||
|
||||
// use cluster culling or not
|
||||
|
||||
@@ -63,6 +63,7 @@ struct CustomRenderGraphContext {
|
||||
const RenderGraph* renderGraph{nullptr};
|
||||
const ResourceGraph* resourceGraph{nullptr};
|
||||
gfx::CommandBuffer* primaryCommandBuffer{nullptr};
|
||||
gfx::RenderPass* currentRenderPass{nullptr};
|
||||
};
|
||||
|
||||
class CustomRenderPass : public Customization {
|
||||
|
||||
@@ -44,12 +44,6 @@
|
||||
#include "details/GraphView.h"
|
||||
#include "details/GslUtils.h"
|
||||
#include "details/Range.h"
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
#include "cocos/renderer/pipeline/helper/Utils.h"
|
||||
#endif
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
#include "cocos/renderer/pipeline/GeometryRenderer.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -704,11 +698,15 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
ctx.cmdBuff, ctx.currentPass, ctx.subpassIndex, sceneData.flags);
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
if (any(sceneData.flags & SceneFlags::GEOMETRY) &&
|
||||
camera && camera->getGeometryRenderer()) {
|
||||
camera->getGeometryRenderer()->render(
|
||||
ctx.currentPass, ctx.cmdBuff, ctx.ppl->getPipelineSceneData());
|
||||
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, sceneID);
|
||||
if (!renderData.custom.empty()) {
|
||||
const auto& commands = ctx.ppl->custom.renderCommands;
|
||||
auto iter = commands.find(renderData.custom);
|
||||
if (iter != commands.end()) {
|
||||
ctx.customContext.currentRenderPass = ctx.currentPass;
|
||||
iter->second->beginRenderCommand(ctx.customContext, sceneID);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (any(sceneData.flags & SceneFlags::REFLECTION_PROBE)) {
|
||||
@@ -786,24 +784,18 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
|
||||
}
|
||||
|
||||
void begin(const Blit& blit, RenderGraph::vertex_descriptor vertID) const {
|
||||
tryBindPassDescriptorSet(vertID);
|
||||
tryBindQueueDescriptorSets(vertID);
|
||||
const auto& renderData = get(RenderGraph::DataTag{}, ctx.g, vertID);
|
||||
if (!renderData.custom.empty()) {
|
||||
const auto& commands = ctx.ppl->custom.renderCommands;
|
||||
auto iter = commands.find(renderData.custom);
|
||||
if (iter != commands.end()) {
|
||||
ctx.customContext.currentRenderPass = ctx.currentPass;
|
||||
iter->second->beginRenderCommand(ctx.customContext, vertID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
if (blit.blitType == BlitType::DRAW_PROFILE) {
|
||||
auto* renderPass = ctx.currentPass;
|
||||
auto* cmdBuff = ctx.cmdBuff;
|
||||
renderDebugRenderer(renderPass, cmdBuff, ctx.ppl->getPipelineSceneData(), cc::pipeline::profilerCamera);
|
||||
}
|
||||
#endif
|
||||
tryBindPassDescriptorSet(vertID);
|
||||
tryBindQueueDescriptorSets(vertID);
|
||||
|
||||
switch (blit.blitType) {
|
||||
case BlitType::FULLSCREEN_QUAD:
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
#include "profiler/DebugRenderer.h"
|
||||
#endif
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
#include "cocos/renderer/pipeline/GeometryRenderer.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
@@ -106,6 +110,54 @@ void addSubresourceNode<gfx::Format::DEPTH_STENCIL>(ResourceGraph::vertex_descri
|
||||
|
||||
} // namespace
|
||||
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
namespace {
|
||||
class DebugRendererRenderCommand final : public CustomRenderCommand {
|
||||
public:
|
||||
explicit DebugRendererRenderCommand(pipeline::PipelineSceneData *sceneData)
|
||||
: _sceneData(sceneData) {}
|
||||
|
||||
void beginRenderCommand(const CustomRenderGraphContext &rg, RenderGraph::vertex_descriptor vertID) override {
|
||||
std::ignore = vertID;
|
||||
if (rg.currentRenderPass) {
|
||||
DebugRenderer::getInstance()->render(rg.currentRenderPass, rg.primaryCommandBuffer, _sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
void endRenderCommand(const CustomRenderGraphContext &rg, RenderGraph::vertex_descriptor vertID) override {
|
||||
std::ignore = rg;
|
||||
std::ignore = vertID;
|
||||
}
|
||||
|
||||
private:
|
||||
pipeline::PipelineSceneData *_sceneData{nullptr};
|
||||
};
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
class GeometryRendererRenderCommand final : public CustomRenderCommand {
|
||||
public:
|
||||
explicit GeometryRendererRenderCommand(pipeline::PipelineSceneData *sceneData)
|
||||
: _sceneData(sceneData) {}
|
||||
|
||||
void beginRenderCommand(const CustomRenderGraphContext &rg, RenderGraph::vertex_descriptor vertID) override {
|
||||
const auto &sceneData = get(SceneTag{}, vertID, *rg.renderGraph);
|
||||
if (sceneData.camera && sceneData.camera->getGeometryRenderer()) {
|
||||
sceneData.camera->getGeometryRenderer()->render(rg.currentRenderPass, rg.primaryCommandBuffer, _sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
void endRenderCommand(const CustomRenderGraphContext &rg, RenderGraph::vertex_descriptor vertID) override {
|
||||
std::ignore = vertID;
|
||||
std::ignore = rg;
|
||||
}
|
||||
|
||||
private:
|
||||
pipeline::PipelineSceneData *_sceneData{nullptr};
|
||||
};
|
||||
#endif
|
||||
|
||||
NativePipeline::NativePipeline(const allocator_type &alloc) noexcept
|
||||
: device(gfx::Device::getInstance()),
|
||||
globalDSManager(std::make_unique<pipeline::GlobalDSManager>()),
|
||||
@@ -1385,6 +1437,10 @@ bool NativePipeline::activate(gfx::Swapchain *swapchainIn) {
|
||||
pipelineSceneData->activate(device);
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
DebugRenderer::getInstance()->activate(device);
|
||||
addCustomRenderCommand(cc::pipeline::DEBUG_RENDERER_COMMAND, std::make_shared<DebugRendererRenderCommand>(getPipelineSceneData()));
|
||||
#endif
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
addCustomRenderCommand(cc::pipeline::GEOMETRY_RENDERER_COMMAND, std::make_shared<GeometryRendererRenderCommand>(getPipelineSceneData()));
|
||||
#endif
|
||||
// generate macros here rather than construct func because _clusterEnabled
|
||||
// switch may be changed in root.ts setRenderPipeline() function which is after
|
||||
|
||||
@@ -913,6 +913,13 @@ SceneBuilder *NativeRenderQueueBuilder::addScene(
|
||||
data);
|
||||
}
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
if (any(sceneFlags & SceneFlags::GEOMETRY)) {
|
||||
auto &data = get(RenderGraph::DataTag{}, *renderGraph, sceneID);
|
||||
data.custom = cc::pipeline::GEOMETRY_RENDERER_COMMAND;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (any(sceneFlags & SceneFlags::UI)) {
|
||||
CC_EXPECTS(camera);
|
||||
const auto passOrSubpassId = parent(nodeID, *renderGraph);
|
||||
@@ -1086,6 +1093,31 @@ void NativeRenderQueueBuilder::addProfiler(const scene::Camera *camera) {
|
||||
*renderGraph,
|
||||
passOrSubpassId);
|
||||
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
const auto debugId = addVertex2(
|
||||
BlitTag{},
|
||||
std::forward_as_tuple("DebugRenderer"),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(),
|
||||
std::forward_as_tuple(
|
||||
IntrusivePtr<Material>{},
|
||||
RenderGraph::null_vertex(),
|
||||
SceneFlags::NONE,
|
||||
nullptr,
|
||||
BlitType::FULLSCREEN_QUAD),
|
||||
*renderGraph,
|
||||
queueId);
|
||||
auto &debugData = get(RenderGraph::DataTag{}, *renderGraph, debugId);
|
||||
debugData.custom = cc::pipeline::DEBUG_RENDERER_COMMAND;
|
||||
setCameraUBOValues(
|
||||
*camera,
|
||||
*layoutGraph,
|
||||
*pipelineRuntime->getPipelineSceneData(),
|
||||
camera->getScene() ? camera->getScene()->getMainLight() : nullptr,
|
||||
debugData);
|
||||
#endif
|
||||
|
||||
const auto sceneId = addVertex2(
|
||||
BlitTag{},
|
||||
std::forward_as_tuple("Profiler"),
|
||||
|
||||
@@ -647,8 +647,8 @@ 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());
|
||||
if (auto *command = pipeline->getRenderCommand(cc::pipeline::GEOMETRY_RENDERER_COMMAND)) {
|
||||
command->beginRenderCommand({table.getRenderPass(), cmdBuff, pipeline->getPipelineSceneData(), camera});
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -228,7 +228,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);
|
||||
if (auto *command = pipeline->getRenderCommand(cc::pipeline::DEBUG_RENDERER_COMMAND)) {
|
||||
command->beginRenderCommand({renderPass, cmdBuff, pipeline->getPipelineSceneData(), camera});
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "ForwardStage.h"
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
#include "../GeometryRenderer.h"
|
||||
#endif
|
||||
#include "../InstancedBuffer.h"
|
||||
#include "../PipelineSceneData.h"
|
||||
#include "../PipelineUBO.h"
|
||||
@@ -262,15 +259,17 @@ void ForwardStage::render(scene::Camera *camera) {
|
||||
}
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
if (camera->getGeometryRenderer()) {
|
||||
camera->getGeometryRenderer()->render(renderPass, cmdBuff, pipeline->getPipelineSceneData());
|
||||
if (auto *command = pipeline->getRenderCommand(cc::pipeline::GEOMETRY_RENDERER_COMMAND)) {
|
||||
command->beginRenderCommand({renderPass, cmdBuff, pipeline->getPipelineSceneData(), camera});
|
||||
}
|
||||
#endif
|
||||
|
||||
_uiPhase->render(camera, renderPass);
|
||||
renderProfiler(renderPass, cmdBuff, _pipeline->getProfiler(), camera);
|
||||
#if CC_USE_DEBUG_RENDERER
|
||||
renderDebugRenderer(renderPass, cmdBuff, _pipeline->getPipelineSceneData(), camera);
|
||||
if (auto *command = pipeline->getRenderCommand(cc::pipeline::DEBUG_RENDERER_COMMAND)) {
|
||||
command->beginRenderCommand({renderPass, cmdBuff, pipeline->getPipelineSceneData(), camera});
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -105,6 +105,12 @@ using namespace cc;
|
||||
%ignore cc::pipeline::GeometryRenderer::activate;
|
||||
%ignore cc::pipeline::GeometryRenderer::render;
|
||||
%ignore cc::pipeline::GeometryRenderer::destroy;
|
||||
%ignore cc::pipeline::RenderCommand;
|
||||
%ignore cc::pipeline::RenderCommandContext;
|
||||
%ignore cc::pipeline::DebugRendererRenderCommand;
|
||||
%ignore cc::pipeline::GeometryRendererRenderCommand;
|
||||
%ignore cc::pipeline::RenderPipeline::addRenderCommand;
|
||||
%ignore cc::pipeline::RenderPipeline::getRenderCommand;
|
||||
|
||||
// ----- Rename Section ------
|
||||
// Brief: Classes, methods or attributes needs to be renamed
|
||||
|
||||
Reference in New Issue
Block a user