mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
[pipeline] refactor custom pipeline init (#14040)
This commit is contained in:
+1
-1
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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!;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_)
|
||||
|
||||
@@ -13857,31 +13861,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<cc::pipeline::PipelineSceneData>(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;
|
||||
@@ -14367,6 +14346,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<cc::pipeline::PipelineSceneData>(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<cc::pipeline::PipelineSceneData>(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));
|
||||
|
||||
@@ -14378,12 +14398,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));
|
||||
|
||||
@@ -26444,7 +26444,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");
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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<PassOverrides> stateOverrides;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -48,6 +48,8 @@ ccstd::vector<gfx::Attribute> getActiveAttributes(
|
||||
ccstd::string getShaderInstanceName(
|
||||
const ccstd::string& name, const ccstd::vector<IMacroInfo>& macros);
|
||||
|
||||
void addEffectDefaultProperties(EffectAsset& effect);
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -50,7 +50,7 @@ DescriptorSetAgent::~DescriptorSetAgent() {
|
||||
|
||||
void DescriptorSetAgent::doInit(const DescriptorSetInfo &info) {
|
||||
DescriptorSetInfo actorInfo;
|
||||
actorInfo.layout = static_cast<DescriptorSetLayoutAgent *>(info.layout)->getActor();
|
||||
actorInfo.layout = static_cast<const DescriptorSetLayoutAgent *>(info.layout)->getActor();
|
||||
|
||||
ENQUEUE_MESSAGE_2(
|
||||
DeviceAgent::getInstance()->getMessageQueue(),
|
||||
|
||||
@@ -1419,7 +1419,7 @@ struct DescriptorSetLayoutInfo {
|
||||
};
|
||||
|
||||
struct DescriptorSetInfo {
|
||||
DescriptorSetLayout *layout{nullptr};
|
||||
const DescriptorSetLayout *layout{nullptr};
|
||||
|
||||
EXPOSE_COPY_FN(DescriptorSetInfo)
|
||||
};
|
||||
|
||||
@@ -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<ObjectWithId<Buffer>> _buffers;
|
||||
ccstd::vector<ObjectWithId<Texture>> _textures;
|
||||
ccstd::vector<ObjectWithId<Sampler>> _samplers;
|
||||
|
||||
@@ -43,7 +43,7 @@ GLES2DescriptorSet::~GLES2DescriptorSet() {
|
||||
}
|
||||
|
||||
void GLES2DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) {
|
||||
const GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<GLES2DescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<const GLES2DescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount;
|
||||
const size_t bindingCount = gpuDescriptorSetLayout->bindings.size();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ GLES3DescriptorSet::~GLES3DescriptorSet() {
|
||||
}
|
||||
|
||||
void GLES3DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) {
|
||||
const GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<GLES3DescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<const GLES3DescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount;
|
||||
const size_t bindingCount = gpuDescriptorSetLayout->bindings.size();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ CCMTLDescriptorSet::CCMTLDescriptorSet() : DescriptorSet() {
|
||||
}
|
||||
|
||||
void CCMTLDescriptorSet::doInit(const DescriptorSetInfo &info) {
|
||||
const auto gpuDescriptorSetLayout = static_cast<CCMTLDescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const auto gpuDescriptorSetLayout = static_cast<const CCMTLDescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
const auto descriptorCount = gpuDescriptorSetLayout->descriptorCount;
|
||||
const auto bindingCount = gpuDescriptorSetLayout->bindings.size();
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ DescriptorSetValidator::~DescriptorSetValidator() {
|
||||
void DescriptorSetValidator::doInit(const DescriptorSetInfo &info) {
|
||||
CC_ASSERT(!isInited());
|
||||
_inited = true;
|
||||
CC_ASSERT(info.layout && static_cast<DescriptorSetLayoutValidator *>(info.layout)->isInited());
|
||||
CC_ASSERT(info.layout && static_cast<const DescriptorSetLayoutValidator *>(info.layout)->isInited());
|
||||
|
||||
/////////// execute ///////////
|
||||
|
||||
DescriptorSetInfo actorInfo;
|
||||
actorInfo.layout = static_cast<DescriptorSetLayoutValidator *>(info.layout)->getActor();
|
||||
actorInfo.layout = static_cast<const DescriptorSetLayoutValidator *>(info.layout)->getActor();
|
||||
|
||||
_actor->initialize(actorInfo);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ CCVKDescriptorSet::~CCVKDescriptorSet() {
|
||||
}
|
||||
|
||||
void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) {
|
||||
CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<CCVKDescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast<const CCVKDescriptorSetLayout *>(_layout)->gpuDescriptorSetLayout();
|
||||
uint32_t bindingCount = utils::toUint(gpuDescriptorSetLayout->bindings.size());
|
||||
uint32_t descriptorCount = gpuDescriptorSetLayout->descriptorCount;
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
inline const RenderObjectList &getRenderObjects() const { return _renderObjects; }
|
||||
inline void setRenderObjects(RenderObjectList &&ro) { _renderObjects = std::forward<RenderObjectList>(ro); }
|
||||
inline const ccstd::vector<const scene::Light *> &getValidPunctualLights() const { return _validPunctualLights; }
|
||||
inline void setValidPunctualLights(ccstd::vector<const scene::Light *> 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; }
|
||||
|
||||
@@ -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<gfx::Uniform>& 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
|
||||
|
||||
@@ -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<gfx::Uniform>& blockMembers);
|
||||
|
||||
gfx::DescriptorSet* getOrCreatePerPassDescriptorSet(
|
||||
gfx::Device* device,
|
||||
LayoutGraphData& lg, LayoutGraphData::vertex_descriptor vertID);
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -26,10 +26,14 @@
|
||||
#include <boost/graph/filtered_graph.hpp>
|
||||
#include <variant>
|
||||
#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<bool>& validPassesIn,
|
||||
gfx::Device* deviceIn,
|
||||
cc::gfx::CommandBuffer* cmdBuffIn,
|
||||
ccstd::pmr::unordered_map<
|
||||
const scene::RenderScene*,
|
||||
ccstd::pmr::unordered_map<scene::Camera*, NativeRenderQueue>>& 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<bool>& 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<scene::Camera*, NativeRenderQueue>>& 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<bool>* 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 <class T>
|
||||
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<uint32_t>(value.size()),
|
||||
static_cast<uint32_t>(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<Barrier>& 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<uint32_t>(value.size()),
|
||||
// static_cast<uint32_t>(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<uint32_t>(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<NativeProgramLibrary*>(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));
|
||||
|
||||
@@ -44,8 +44,6 @@ NativeRenderingModule* sRenderingModule = nullptr;
|
||||
} // namespace
|
||||
|
||||
RenderingModule* Factory::init(gfx::Device* deviceIn, const ccstd::vector<unsigned char>& bufferIn) {
|
||||
std::ignore = deviceIn;
|
||||
|
||||
std::shared_ptr<NativeProgramLibrary> ptr(
|
||||
allocatePmrUniquePtr<NativeProgramLibrary>(
|
||||
boost::container::pmr::get_default_resource()));
|
||||
@@ -55,6 +53,7 @@ RenderingModule* Factory::init(gfx::Device* deviceIn, const ccstd::vector<unsign
|
||||
BinaryInputArchive ar(iss, boost::container::pmr::get_default_resource());
|
||||
load(ar, ptr->layoutGraph);
|
||||
}
|
||||
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<NativeRenderingModule*>(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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<gfx::PipelineLayout> 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<unsigned> &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
const Record<ccstd::string, uint32_t> &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
const ccstd::vector<int32_t> &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const override;
|
||||
const Record<ccstd::string, uint32_t> &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;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#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<ccstd::pmr::string> &valueNames,
|
||||
const DescriptorSetLayoutData &layout, uint32_t set,
|
||||
gfx::ShaderInfo &shaderInfo, ccstd::pmr::vector<uint32_t> &blockSizes) {
|
||||
gfx::ShaderInfo &shaderInfo, ccstd::vector<int32_t> &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<uint32_t> &blockSizes) {
|
||||
ccstd::vector<int32_t> &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<uint32_t> &blockSizes) {
|
||||
gfx::ShaderInfo &shaderInfo, ccstd::vector<int32_t> &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<uint32_t> &blockSizes) {
|
||||
ccstd::vector<int32_t> &blockSizes) {
|
||||
std::array<const DescriptorSetLayoutData *, 4> 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<size_t>(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<RenderPhaseTag>(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<uint32_t> blockSizes(alloc);
|
||||
ccstd::vector<int32_t> blockSizes;
|
||||
makeShaderInfo(lg, passLayout, phaseLayout, srcShaderInfo, programData,
|
||||
fixedLocal, shaderInfo, blockSizes);
|
||||
|
||||
@@ -1084,7 +1141,7 @@ IntrusivePtr<gfx::PipelineLayout> 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<unsigned> &NativeProgramLibrary::getBlockSizes(
|
||||
uint32_t phaseID, const ccstd::pmr::string &programName) const {
|
||||
const ccstd::vector<int32_t> &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<ccstd::string, uint32_t> &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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<gfx::Attribute> attributesIn, ccstd::pmr::vector<unsigned> blockSizesIn, Record<ccstd::string, uint32_t> handleMapIn, const allocator_type& alloc) noexcept
|
||||
ProgramInfo::ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector<gfx::Attribute> attributesIn, ccstd::vector<signed> blockSizesIn, Record<ccstd::string, uint32_t> 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
|
||||
|
||||
@@ -49,7 +49,7 @@ struct ProgramInfo {
|
||||
}
|
||||
|
||||
ProgramInfo(const allocator_type& alloc) noexcept; // NOLINT
|
||||
ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector<gfx::Attribute> attributesIn, ccstd::pmr::vector<unsigned> blockSizesIn, Record<ccstd::string, uint32_t> handleMapIn, const allocator_type& alloc) noexcept;
|
||||
ProgramInfo(IProgramInfo programInfoIn, gfx::ShaderInfo shaderInfoIn, ccstd::pmr::vector<gfx::Attribute> attributesIn, ccstd::vector<signed> blockSizesIn, Record<ccstd::string, uint32_t> 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<gfx::Attribute> attributes;
|
||||
ccstd::pmr::vector<unsigned> blockSizes;
|
||||
ccstd::vector<signed> blockSizes;
|
||||
Record<ccstd::string, uint32_t> handleMap;
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ struct ProgramGroup {
|
||||
ProgramGroup& operator=(ProgramGroup&& rhs) = default;
|
||||
ProgramGroup& operator=(ProgramGroup const& rhs) = default;
|
||||
|
||||
PmrFlatMap<ccstd::pmr::string, ProgramInfo> programInfos;
|
||||
PmrTransparentMap<ccstd::pmr::string, ProgramInfo> programInfos;
|
||||
PmrFlatMap<ccstd::pmr::string, IntrusivePtr<ProgramProxy>> programProxies;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<gfx::PipelineLayout> 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<unsigned> &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual const Record<ccstd::string, uint32_t> &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual const ccstd::vector<int32_t> &getBlockSizes(uint32_t phaseID, const ccstd::string &programName) const = 0;
|
||||
virtual const Record<ccstd::string, uint32_t> &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;
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace cc {
|
||||
namespace render {
|
||||
|
||||
ProgramLibrary* getProgramLibrary();
|
||||
RenderingModule* getRenderingModule();
|
||||
|
||||
} // namespace render
|
||||
|
||||
|
||||
@@ -44,14 +44,6 @@ inline void cleanPath(std::basic_string<CharT, std::char_traits<CharT>, 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'};
|
||||
|
||||
+207
-58
@@ -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<IMacroPatch> &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<int32_t> &blockSizes = tmplInfo->blockSizes;
|
||||
const auto &handleMap = tmplInfo->handleMap;
|
||||
|
||||
const auto alignment = device->getCapabilities().uboOffsetAlignment;
|
||||
ccstd::vector<uint32_t> 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<int32_t>(std::ceil(static_cast<float>(size) / static_cast<float>(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<int32_t>(std::ceil(static_cast<float>(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<int32_t>(std::ceil(static_cast<float>(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<float *>(const_cast<uint8_t *>(_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<gfx::Buffer> &rootBuffer,
|
||||
IntrusivePtr<ArrayBuffer> &rootBlock,
|
||||
ccstd::vector<uint32_t> &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<int32_t>(std::ceil(static_cast<float>(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<uint32_t> &startOffsets,
|
||||
size_t &count) {
|
||||
bufferViewInfo.buffer = _rootBuffer;
|
||||
bufferViewInfo.offset = startOffsets[count++];
|
||||
bufferViewInfo.range = static_cast<int32_t>(std::ceil(static_cast<float>(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<float *>(const_cast<uint8_t *>(_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<gfx::UniformBlock> &blocks,
|
||||
const ccstd::vector<int32_t> &blockSizes) {
|
||||
gfx::Device *device = _device;
|
||||
const auto alignment = device->getCapabilities().uboOffsetAlignment;
|
||||
ccstd::vector<uint32_t> 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<pipeline::SetIndex>(block.set) != pipeline::SetIndex::MATERIAL) {
|
||||
continue;
|
||||
}
|
||||
const auto &size = blockSizes[i];
|
||||
startOffsets.emplace_back(lastOffset);
|
||||
lastOffset += static_cast<int32_t>(std::ceil(static_cast<float>(size) / static_cast<float>(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<pipeline::SetIndex>(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<IBlockInfo> &blocks,
|
||||
const ccstd::vector<int32_t> &blockSizes) {
|
||||
gfx::Device *device = _device;
|
||||
const auto alignment = device->getCapabilities().uboOffsetAlignment;
|
||||
ccstd::vector<uint32_t> 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<int32_t>(std::ceil(static_cast<float>(size) / static_cast<float>(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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ccstd::string, IPropertyInfo> &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<IBlockInfo> &blocks,
|
||||
const ccstd::vector<int32_t> &blockSizes);
|
||||
void buildMaterialUniformBlocks(
|
||||
const ccstd::vector<gfx::UniformBlock> &blocks,
|
||||
const ccstd::vector<int32_t> &blockSizes);
|
||||
void buildUniformBlock(
|
||||
uint32_t binding, int32_t size,
|
||||
gfx::BufferViewInfo &bufferViewInfo,
|
||||
ccstd::vector<uint32_t> &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<ArrayBuffer> _rootBlock;
|
||||
ccstd::vector<IBlockRef> _blocks; // Point to position in _rootBlock
|
||||
|
||||
IProgramInfo *_shaderInfo; // weakref to template of ProgramLib
|
||||
const IProgramInfo *_shaderInfo; // weakref to template of ProgramLib
|
||||
MacroRecord _defines;
|
||||
Record<ccstd::string, IPropertyInfo> _properties;
|
||||
IntrusivePtr<gfx::Shader> _shader;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -168,7 +168,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<const cc::scene::Light *>, validPunctualLights, getValidPunctualLights, setValidPunctualLights);
|
||||
|
||||
%attribute(cc::pipeline::RenderStage, ccstd::string&, _name, getName, setName);
|
||||
%attribute(cc::pipeline::RenderStage, uint32_t, _priority, getPriority, setPriority);
|
||||
|
||||
@@ -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' }],
|
||||
|
||||
Reference in New Issue
Block a user