Files
cocos4/native/cocos/core/Root.h
T
hyde zhou 02407dbc70 V3.6.0 pipeline (#11277)
* decouple GlobalDescriptorSetManager from RenderPipeline

* formatting

* move interface onGlobalPipelineStateChanged from PipelineSceneData to Pipeline

* add layouts

* fix eslint error

* rendergraph creates device resources

* restore resourceGraph

* resource graph updated

* add scene interface

* layout graph updated

* stop use IntrusivePtr<gfx::Swapchain>

* add setViewport setScissor

* scene transversal modified

* accidentally omitted

* remove pipeline event from pipeline, decouple terrain from render pipeline

* shadingScale moved from PipelineSceneData to Pipeline

* Pipeline removed from PipelineSceneData

* pipelineEvent refactored

* fix typo

* rendergraph executes

* interface changed

* fix submit

* Update the draw function

* pipeline runtime added to pipeline

* automatically barrier

* typo

* comment

* forgot sth important

* add classic/custom pipeline switch

* web pipeline can be enabled

* relax pipeline interface

* pipeline use gfx::Color

* decouple native RenderPipeline

* fix clang tidy

* add get pipelineSceneData

* present refactored

* added executor example

* half way done

* find slot

* merge & sort layout

* layout graph updated

* enable native usesCustomPipeline

* change mergedbs

* fix comment

* fix eslint error

* fix

* draft

* update the rendergraph compiler

* update the compiler

* update executor

* update to latest

* revert mtlcmdbuffer manually

* valid added

* external node

* add framebuffer

* fix linter

* fix linter

* fix implicit narrow cast

* fix linter

* use native root.pipeline

* use Root to get pipeline instance

* fix ccstd::string

* turn off validation

* cleanup

* ccstd::pmr::string changed

* update the pipeline ubo

* use ccstd::pmr::string

* uses ccstd::pmr::vector

* uses ccstd::pmr::map

* reconstruction

* external res

* compile issue

* clang tidy

* fix ccstd::pmr::string hash

* fix potential issue

* Fixed some rendering errors of webpipeline in the editor

* Optimize attachment load/storeOp logic

* update executor

* WebPipeline bug fixed in editor

* Fix the problem of resource cache error when camera is deleted or added

* webpipeline performs logic adjustments and bug fixes

* render graph updated

* descriptor updated

* descriptor updated

* fix member traits

* libstdc++ does not support hashing std::pmr::string on linux

* refactor descriptor

* jsb allocator walkaround

* rename

* descriptor type refactored

* fix default

* adding layout graph builder

* transfer env

* switch env

* switch env

* adding native layout builder

* adding native builder

* adding layout graph

* adding descriptor

* adding descriptor layout

* create layout graph builder added

* fix root

* format

* add web layout graph builder

* refactor web layout graph

* fix intrusive ptr

* descriptor set data updated

* before applying another idea

* debug string added

* adding render graph

* adding resource graph

* adding native pipeline

* graph remove edge temporary fix

* remove_edge simplified

* remove edge simplified

* outIter renamed

* remove edges simplified

* fix reference graph impl

* run test case

* adding native impl

* remove unused native

* queue added

* pass reorder v1.0

* adding native pipeline

* adding native pipeline

* fix bug

* render graph setup added

* render graph updated

* fix ccstd::string

* getFirstChildLayout, num of children must be 1

* remove examples

* structure refactor

* pass reorder & framegraphDispatcher interface

* remove test code

* remove debug code

* ts added object detection

* ts get name added

* RenderGraph setup moved

* add ts layout graph implement

* fix lint

* fix ci: implicit type conversion

* ci

* adding warmup

* turn off custom

* pipeline updated

* format

* try disable clang 64 to 32 narrow warning

Co-authored-by: zxx43 <zxx43@hotmail.com>
Co-authored-by: GengineJS <476393671@qq.com>
Co-authored-by: Zeqiang Li <zeqiang-li@outlook.com>
2022-06-01 19:06:59 +08:00

287 lines
7.8 KiB
C++

/****************************************************************************
Copyright (c) 2021 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <cstdint>
//#include "3d/skeletal-animation/DataPoolManager.h"
#include "core/memop/Pool.h"
#include "renderer/pipeline/RenderPipeline.h"
#include "scene/Light.h"
#include "scene/Model.h"
#include "scene/RenderScene.h"
#include "scene/RenderWindow.h"
#include "scene/SphereLight.h"
namespace cc {
namespace scene {
class Camera;
struct DrawBatch2D;
} // namespace scene
namespace gfx {
class SwapChain;
class Device;
} // namespace gfx
namespace render {
class PipelineRuntime;
class Pipeline;
} // namespace render
class CallbacksInvoker;
class Root final {
public:
static Root *getInstance(); //cjh todo: put Root Managerment to Director class.
explicit Root(gfx::Device *device);
~Root();
// @minggo IRootInfo seems is not use, and how to return Promise?
void initialize(gfx::Swapchain *swapchain);
void destroy();
/**
* @zh
* 重置大小
* @param width 屏幕宽度
* @param height 屏幕高度
*/
void resize(uint32_t width, uint32_t height);
bool setRenderPipeline(pipeline::RenderPipeline *rppl = nullptr);
void onGlobalPipelineStateChanged();
/**
* @zh
* 激活指定窗口为当前窗口
* @param window GFX 窗口
*/
void activeWindow(scene::RenderWindow *);
/**
* @zh
* 重置累计时间
*/
void resetCumulativeTime();
/**
* @zh
* 每帧执行函数
* @param deltaTime 间隔时间
*/
void frameMove(float deltaTime, int32_t totalFrames); // NOTE: c++ doesn't have a Director, so totalFrames need to be set from JS
/**
* @zh
* 创建窗口
* @param info GFX 窗口描述信息
*/
scene::RenderWindow *createWindow(scene::IRenderWindowInfo &);
/**
* @zh
* 销毁指定的窗口
* @param window GFX 窗口
*/
void destroyWindow(scene::RenderWindow *);
/**
* @zh
* 销毁全部窗口
*/
void destroyWindows();
/**
* @zh
* 创建渲染场景
* @param info 渲染场景描述信息
*/
scene::RenderScene *createScene(const scene::IRenderSceneInfo &);
/**
* @zh
* 销毁指定的渲染场景
* @param scene 渲染场景
*/
void destroyScene(scene::RenderScene *);
/**
* @zh
* 销毁全部场景
*/
void destroyScenes();
template <typename T, typename = std::enable_if_t<std::is_base_of<scene::Model, T>::value>>
T *createModel() {
//cjh TODO: need use model pool?
T *model = ccnew T();
model->initialize();
return model;
}
void destroyModel(scene::Model *model);
template <typename T, typename = std::enable_if_t<std::is_base_of<scene::Light, T>::value>>
T *createLight() {
//TODO(xwx): need use model pool?
T *light = ccnew T();
light->initialize();
return light;
}
void destroyLight(scene::Light *light);
scene::Camera *createCamera() const;
/**
* @zh
* GFX 设备
*/
inline gfx::Device *getDevice() const { return _device; }
inline void setDevice(gfx::Device *device) { _device = device; }
/**
* @zh
* 主窗口
*/
inline scene::RenderWindow *getMainWindow() const { return _mainWindow.get(); }
/**
* @zh
* 当前窗口
*/
inline void setCurWindow(scene::RenderWindow *window) { _curWindow = window; }
inline scene::RenderWindow *getCurWindow() const { return _curWindow.get(); }
/**
* @zh
* 临时窗口(用于数据传输)
*/
void setTempWindow(scene::RenderWindow *window) { _tempWindow = window; }
inline scene::RenderWindow *getTempWindow() const { return _tempWindow.get(); }
/**
* @zh
* 窗口列表
*/
inline const ccstd::vector<IntrusivePtr<scene::RenderWindow>> &getWindows() const { return _windows; }
/**
* @zh
* 是否启用自定义渲染管线
*/
inline bool usesCustomPipeline() const { return _usesCustomPipeline; }
/**
* @zh
* 渲染管线
*/
inline render::PipelineRuntime *getPipeline() const { return _pipelineRuntime.get(); }
/**
* @zh
* 自定义渲染管线
*/
render::Pipeline *getCustomPipeline() const;
/**
* @zh
* UI实例
* 引擎内部使用,用户无需调用此接口
*/
inline scene::DrawBatch2D *getBatcher2D() const { return _batcher2D; }
/**
* @zh
* 场景列表
*/
inline const ccstd::vector<IntrusivePtr<scene::RenderScene>> &getScenes() const { return _scenes; }
/**
* @zh
* 累计时间(秒)
*/
inline float getCumulativeTime() const { return _cumulativeTime; }
/**
* @zh
* 帧时间(秒)
*/
inline float getFrameTime() const { return _frameTime; }
/**
* @zh
* 一秒内的累计帧数
*/
inline uint32_t getFrameCount() const { return _frameCount; }
/**
* @zh
* 每秒帧率
*/
inline uint32_t getFps() const { return _fps; }
/**
* @zh
* 每秒固定帧率
*/
void setFixedFPS(uint32_t fps) { _fixedFPS = fps; }
inline uint32_t getFixedFPS() const { return _fixedFPS; }
// inline DataPoolManager *getDataPoolManager() { return _dataPoolMgr.get(); }
inline bool isUsingDeferredPipeline() const { return _useDeferredPipeline; }
inline CallbacksInvoker *getEventProcessor() const { return _eventProcessor; }
private:
gfx::Device *_device{nullptr};
gfx::Swapchain *_swapchain{nullptr};
IntrusivePtr<scene::RenderWindow> _mainWindow;
IntrusivePtr<scene::RenderWindow> _curWindow;
IntrusivePtr<scene::RenderWindow> _tempWindow;
ccstd::vector<IntrusivePtr<scene::RenderWindow>> _windows;
IntrusivePtr<pipeline::RenderPipeline> _pipeline{nullptr};
std::unique_ptr<render::PipelineRuntime> _pipelineRuntime;
scene::DrawBatch2D *_batcher2D{nullptr};
// IntrusivePtr<DataPoolManager> _dataPoolMgr;
ccstd::vector<IntrusivePtr<scene::RenderScene>> _scenes;
float _cumulativeTime{0.F};
float _frameTime{0.F};
float _fpsTime{0.F};
uint32_t _frameCount{0};
uint32_t _fps{0};
uint32_t _fixedFPS{0};
bool _useDeferredPipeline{false};
bool _usesCustomPipeline{false};
CallbacksInvoker *_eventProcessor{nullptr};
// Cache ccstd::vector to avoid allocate every frame in frameMove
ccstd::vector<scene::Camera *> _cameraList;
ccstd::vector<gfx::Swapchain *> _swapchains;
//
};
} // namespace cc