mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
pipeline: constant macros (#3394)
This commit is contained in:
@@ -34,23 +34,25 @@
|
||||
|
||||
namespace cc {
|
||||
namespace pipeline {
|
||||
RenderPipeline *RenderPipeline::_instance = nullptr;
|
||||
|
||||
RenderPipeline *RenderPipeline::instance = nullptr;
|
||||
|
||||
RenderPipeline *RenderPipeline::getInstance() {
|
||||
return RenderPipeline::_instance;
|
||||
return RenderPipeline::instance;
|
||||
}
|
||||
|
||||
RenderPipeline::RenderPipeline()
|
||||
: _device(gfx::Device::getInstance()) {
|
||||
RenderPipeline::_instance = this;
|
||||
RenderPipeline::instance = this;
|
||||
|
||||
setDescriptorSetLayout();
|
||||
generateConstantMacros();
|
||||
|
||||
_pipelineUBO = new PipelineUBO();
|
||||
_pipelineSceneData = new PipelineSceneData();
|
||||
}
|
||||
|
||||
RenderPipeline::~RenderPipeline() {
|
||||
}
|
||||
RenderPipeline::~RenderPipeline() = default;
|
||||
|
||||
#define INIT_GLOBAL_DESCSET_LAYOUT(info) \
|
||||
do { \
|
||||
@@ -130,8 +132,9 @@ bool RenderPipeline::activate() {
|
||||
_pipelineUBO->activate(_device, this);
|
||||
_pipelineSceneData->activate(_device, this);
|
||||
|
||||
for (const auto flow : _flows)
|
||||
for (auto *const flow : _flows) {
|
||||
flow->activate(this);
|
||||
}
|
||||
|
||||
// has not initBuiltinRes,
|
||||
// create temporary default Texture to binding sampler2d
|
||||
@@ -140,8 +143,8 @@ bool RenderPipeline::activate() {
|
||||
gfx::TextureType::TEX2D,
|
||||
gfx::TextureUsageBit::COLOR_ATTACHMENT | gfx::TextureUsageBit::SAMPLED,
|
||||
gfx::Format::RGBA8,
|
||||
1u,
|
||||
1u,
|
||||
1U,
|
||||
1U,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,16 +152,16 @@ bool RenderPipeline::activate() {
|
||||
}
|
||||
|
||||
void RenderPipeline::render(const vector<uint> &cameras) {
|
||||
for (const auto flow : _flows) {
|
||||
for (auto *const flow : _flows) {
|
||||
for (const auto cameraID : cameras) {
|
||||
Camera *camera = GET_CAMERA(cameraID);
|
||||
auto *camera = GET_CAMERA(cameraID);
|
||||
flow->render(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::destroy() {
|
||||
for (auto flow : _flows) {
|
||||
for (auto *flow : _flows) {
|
||||
flow->destroy();
|
||||
}
|
||||
_flows.clear();
|
||||
@@ -168,7 +171,7 @@ void RenderPipeline::destroy() {
|
||||
CC_SAFE_DESTROY(_pipelineUBO);
|
||||
CC_SAFE_DESTROY(_pipelineSceneData);
|
||||
|
||||
for (const auto cmdBuffer : _commandBuffers) {
|
||||
for (auto *const cmdBuffer : _commandBuffers) {
|
||||
cmdBuffer->destroy();
|
||||
}
|
||||
_commandBuffers.clear();
|
||||
@@ -185,5 +188,17 @@ void RenderPipeline::setPipelineSharedSceneData(uint handle) {
|
||||
_pipelineSceneData->setPipelineSharedSceneData(handle);
|
||||
}
|
||||
|
||||
void RenderPipeline::generateConstantMacros() {
|
||||
_constantMacros = StringUtil::format(
|
||||
R"(
|
||||
#define CC_DEVICE_SUPPORT_FLOAT_TEXTURE %d
|
||||
#define CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS %d
|
||||
#define CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS $d
|
||||
)",
|
||||
_device->hasFeature(gfx::Feature::TEXTURE_FLOAT) ? 1 : 0,
|
||||
_device->getCapabilities().maxVertexUniformVectors,
|
||||
_device->getCapabilities().maxFragmentUniformVectors);
|
||||
}
|
||||
|
||||
} // namespace pipeline
|
||||
} // namespace cc
|
||||
|
||||
@@ -37,10 +37,10 @@ namespace gfx {
|
||||
class CommandBuffer;
|
||||
class DescriptorSet;
|
||||
class DescriptorSetLayout;
|
||||
struct Camera;
|
||||
} // namespace gfx
|
||||
namespace pipeline {
|
||||
class DefineMap;
|
||||
struct Camera;
|
||||
|
||||
struct CC_DLL RenderPipelineInfo {
|
||||
uint tag = 0;
|
||||
@@ -52,38 +52,43 @@ public:
|
||||
static RenderPipeline *getInstance();
|
||||
|
||||
RenderPipeline();
|
||||
virtual ~RenderPipeline();
|
||||
~RenderPipeline() override;
|
||||
|
||||
virtual bool activate();
|
||||
virtual void destroy();
|
||||
virtual bool initialize(const RenderPipelineInfo &info);
|
||||
virtual void render(const vector<uint> &cameras);
|
||||
virtual void resize(uint width, uint height) {};
|
||||
|
||||
virtual void resize(uint width, uint height){};
|
||||
|
||||
void setPipelineSharedSceneData(uint handle);
|
||||
|
||||
CC_INLINE const RenderFlowList &getFlows() const { return _flows; }
|
||||
CC_INLINE uint getTag() const { return _tag; }
|
||||
CC_INLINE const map<String, InternalBindingInst> &getGlobalBindings() const { return _globalBindings; }
|
||||
CC_INLINE const DefineMap &getMacros() const { return _macros; }
|
||||
CC_INLINE void setValue(const String &name, bool value) { _macros.setValue(name, value); }
|
||||
CC_INLINE gfx::DescriptorSet *getDescriptorSet() const { return _descriptorSet; }
|
||||
CC_INLINE gfx::DescriptorSetLayout *getDescriptorSetLayout() const { return _descriptorSetLayout; }
|
||||
CC_INLINE gfx::Texture *getDefaultTexture() const { return _defaultTexture; }
|
||||
CC_INLINE PipelineSceneData *getPipelineSceneData() const { return _pipelineSceneData; }
|
||||
CC_INLINE const gfx::CommandBufferList &getCommandBuffers() const { return _commandBuffers; }
|
||||
CC_INLINE PipelineUBO *getPipelineUBO() const { return _pipelineUBO; }
|
||||
CC_INLINE gfx::Device *getDevice() { return _device; }
|
||||
inline const RenderFlowList & getFlows() const { return _flows; }
|
||||
inline uint getTag() const { return _tag; }
|
||||
inline const map<String, InternalBindingInst> &getGlobalBindings() const { return _globalBindings; }
|
||||
inline const DefineMap & getMacros() const { return _macros; }
|
||||
inline void setValue(const String &name, bool value) { _macros.setValue(name, value); }
|
||||
inline gfx::DescriptorSet * getDescriptorSet() const { return _descriptorSet; }
|
||||
inline gfx::DescriptorSetLayout * getDescriptorSetLayout() const { return _descriptorSetLayout; }
|
||||
inline gfx::Texture * getDefaultTexture() const { return _defaultTexture; }
|
||||
inline PipelineSceneData * getPipelineSceneData() const { return _pipelineSceneData; }
|
||||
inline const gfx::CommandBufferList & getCommandBuffers() const { return _commandBuffers; }
|
||||
inline PipelineUBO * getPipelineUBO() const { return _pipelineUBO; }
|
||||
inline const String & getConstantMacros() { return _constantMacros; }
|
||||
inline gfx::Device * getDevice() { return _device; }
|
||||
|
||||
protected:
|
||||
static RenderPipeline *_instance;
|
||||
void setDescriptorSetLayout();
|
||||
static RenderPipeline *instance;
|
||||
|
||||
static void setDescriptorSetLayout();
|
||||
|
||||
void generateConstantMacros();
|
||||
|
||||
gfx::CommandBufferList _commandBuffers;
|
||||
RenderFlowList _flows;
|
||||
map<String, InternalBindingInst> _globalBindings;
|
||||
DefineMap _macros;
|
||||
uint _tag = 0;
|
||||
String _constantMacros;
|
||||
|
||||
gfx::Device * _device = nullptr;
|
||||
gfx::DescriptorSetLayout *_descriptorSetLayout = nullptr;
|
||||
|
||||
@@ -4,7 +4,7 @@ This is a guide to help you setting up the appropriate environment to enable aut
|
||||
|
||||
For now, **Visual Studio Code** is our first recommended IDE for the job, while a brief discussion about the support in different IDEs can be found at the end of this document.
|
||||
|
||||
## VS Code Integration
|
||||
## VS Code With `C/C++` & `Clang-Tidy` Extension
|
||||
|
||||
* Make sure both `clang-tidy` and `clang-format` are directly accessible in your terminal environment, i.e. install LLVM and add the bin folder into the environment path. LLVM 11+ is recommended.
|
||||
|
||||
@@ -77,6 +77,14 @@ For now, **Visual Studio Code** is our first recommended IDE for the job, while
|
||||
|
||||
> Also note: Once new source files have been added to the project in the CMakeLists, the `compile_commands.json` has to be regenerated by running the same script in the third step.
|
||||
|
||||
## VS Code With `clangd` Extension
|
||||
|
||||
Another fairly decent choice is to install the `clangd` extension only: (`clangd` and `C/C++` extension conflicts with each other so you can't have both)
|
||||
|
||||

|
||||
|
||||
`clangd` is the official language server by LLVM. Compared to the first approach, it has real-time linting & fixing support (much better performance and IDE integration). However it only supports a portion of clang-tidy rules, so the reports won't be identical to the CI environment and it doesn't provide a 'fix-all' command. But combined with the CLI approach below it still can be of a great help.
|
||||
|
||||
## Command Line Interface
|
||||
|
||||
The second recommended way is to directly use the CLI.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -59,7 +59,7 @@ skip = ForwardPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLi
|
||||
|
||||
rename_functions =
|
||||
|
||||
getter_setter= RenderPipeline::[descriptorSet descriptorSetLayout]
|
||||
getter_setter= RenderPipeline::[descriptorSet descriptorSetLayout constantMacros]
|
||||
|
||||
rename_classes =
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(engine_native CXX)
|
||||
enable_language(C ASM)
|
||||
@@ -11,7 +11,7 @@ else
|
||||
exit 1
|
||||
fi
|
||||
cp CMakeLists.txt CMakeLists-bak.txt
|
||||
echo -e "cmake_minimum_required(VERSION 3.8)\nproject(engine_native CXX)\nenable_language(C ASM)" | cat - CMakeLists-bak.txt > CMakeLists.txt
|
||||
cat utils/CMakeLists.header.txt CMakeLists-bak.txt > CMakeLists.txt
|
||||
cmake -Bbuild -DCC_USE_GLES2=ON -DCC_USE_VULKAN=ON -DCC_USE_GLES3=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE="$ndk_path/build/cmake/android.toolchain.cmake" -DANDROID_PLATFORM=android-21 -G"Unix Makefiles"
|
||||
mv CMakeLists-bak.txt CMakeLists.txt
|
||||
cp build/compile_commands.json .
|
||||
|
||||
Reference in New Issue
Block a user