mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
Develop pipeline merge (#15374)
This commit is contained in:
@@ -35,7 +35,6 @@
|
||||
#include "LayoutGraphUtils.h"
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "ProgramLib.h"
|
||||
#include "ProgramUtils.h"
|
||||
#include "base/Ptr.h"
|
||||
#include "cocos/base/Log.h"
|
||||
#include "cocos/core/assets/EffectAsset.h"
|
||||
@@ -74,7 +73,7 @@ constexpr uint32_t setIndex(UpdateFrequency rate) {
|
||||
|
||||
constexpr auto INVALID_ID = LayoutGraphData::null_vertex();
|
||||
|
||||
std::tuple<uint32_t, uint32_t, const IShaderInfo *, uint32_t>
|
||||
std::tuple<uint32_t, uint32_t, uint32_t, const IShaderInfo *, uint32_t>
|
||||
getEffectShader(
|
||||
const LayoutGraphData &lg,
|
||||
const EffectAsset &effect, const IPassInfo &pass) {
|
||||
@@ -87,18 +86,27 @@ getEffectShader(
|
||||
}
|
||||
if (passID == INVALID_ID) {
|
||||
CC_LOG_ERROR("Invalid render pass");
|
||||
return {INVALID_ID, INVALID_ID, nullptr, INVALID_ID};
|
||||
return {INVALID_ID, INVALID_ID, INVALID_ID, nullptr, INVALID_ID};
|
||||
}
|
||||
|
||||
auto subpassID = INVALID_ID;
|
||||
if (pass.subpass) {
|
||||
subpassID = locate(passID, *pass.subpass, lg);
|
||||
if (subpassID == INVALID_ID) {
|
||||
CC_LOG_ERROR("Invalid render subpass");
|
||||
return {INVALID_ID, INVALID_ID, INVALID_ID, nullptr, INVALID_ID};
|
||||
}
|
||||
}
|
||||
|
||||
auto phaseID = INVALID_ID;
|
||||
if (pass.phase) {
|
||||
phaseID = locate(passID, *pass.phase, lg);
|
||||
phaseID = locate(subpassID == INVALID_ID ? passID : subpassID, *pass.phase, lg);
|
||||
} else {
|
||||
phaseID = locate(passID, "default", lg);
|
||||
phaseID = locate(subpassID == INVALID_ID ? passID : subpassID, "default", lg);
|
||||
}
|
||||
if (phaseID == INVALID_ID) {
|
||||
CC_LOG_ERROR("Invalid render phase");
|
||||
return {INVALID_ID, INVALID_ID, nullptr, INVALID_ID};
|
||||
return {INVALID_ID, INVALID_ID, INVALID_ID, nullptr, INVALID_ID};
|
||||
}
|
||||
|
||||
const IShaderInfo *srcShaderInfo = nullptr;
|
||||
@@ -111,7 +119,7 @@ getEffectShader(
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {passID, phaseID, srcShaderInfo, shaderID};
|
||||
return {passID, subpassID, phaseID, srcShaderInfo, shaderID};
|
||||
}
|
||||
|
||||
int validateShaderInfo(const IShaderInfo &srcShaderInfo) {
|
||||
@@ -1004,7 +1012,7 @@ void overwriteProgramBlockInfo(
|
||||
|
||||
gfx::DescriptorSetLayout *getDescriptorSetLayout(
|
||||
const LayoutGraphData &lg,
|
||||
uint32_t passID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters)
|
||||
uint32_t subpassOrPassID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters)
|
||||
if (rate < UpdateFrequency::PER_PASS) {
|
||||
const auto &phaseData = get(LayoutGraphData::LayoutTag{}, lg, phaseID);
|
||||
auto iter = phaseData.descriptorSets.find(rate);
|
||||
@@ -1020,9 +1028,9 @@ gfx::DescriptorSetLayout *getDescriptorSetLayout(
|
||||
}
|
||||
|
||||
CC_EXPECTS(rate == UpdateFrequency::PER_PASS);
|
||||
CC_EXPECTS(passID == parent(phaseID, lg));
|
||||
CC_EXPECTS(subpassOrPassID == parent(phaseID, lg));
|
||||
|
||||
const auto &passData = get(LayoutGraphData::LayoutTag{}, lg, passID);
|
||||
const auto &passData = get(LayoutGraphData::LayoutTag{}, lg, subpassOrPassID);
|
||||
auto iter = passData.descriptorSets.find(rate);
|
||||
if (iter != passData.descriptorSets.end()) {
|
||||
const auto &data = iter->second;
|
||||
@@ -1064,7 +1072,7 @@ gfx::DescriptorSetLayout *getProgramDescriptorSetLayout(
|
||||
const gfx::DescriptorSetLayout &getOrCreateDescriptorSetLayout(
|
||||
const NativeProgramLibrary &lib,
|
||||
const LayoutGraphData &lg,
|
||||
uint32_t passID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters)
|
||||
uint32_t subpassOrPassID, uint32_t phaseID, UpdateFrequency rate) { // NOLINT(bugprone-easily-swappable-parameters)
|
||||
if (rate < UpdateFrequency::PER_PASS) {
|
||||
const auto &phaseData = get(LayoutGraphData::LayoutTag{}, lg, phaseID);
|
||||
auto iter = phaseData.descriptorSets.find(rate);
|
||||
@@ -1080,9 +1088,9 @@ const gfx::DescriptorSetLayout &getOrCreateDescriptorSetLayout(
|
||||
}
|
||||
|
||||
CC_EXPECTS(rate == UpdateFrequency::PER_PASS);
|
||||
CC_EXPECTS(passID == parent(phaseID, lg));
|
||||
CC_EXPECTS(subpassOrPassID == parent(phaseID, lg));
|
||||
|
||||
const auto &passData = get(LayoutGraphData::LayoutTag{}, lg, passID);
|
||||
const auto &passData = get(LayoutGraphData::LayoutTag{}, lg, subpassOrPassID);
|
||||
const auto iter = passData.descriptorSets.find(rate);
|
||||
if (iter != passData.descriptorSets.end()) {
|
||||
const auto &data = iter->second;
|
||||
@@ -1193,8 +1201,8 @@ void NativeProgramLibrary::init(gfx::Device *deviceIn) {
|
||||
continue;
|
||||
}
|
||||
const auto phaseID = v;
|
||||
const auto passID = parent(phaseID, lg);
|
||||
const auto &passLayout = get(LayoutGraphData::LayoutTag{}, lg, passID);
|
||||
const auto subpassOrPassID = parent(phaseID, lg);
|
||||
const auto &passLayout = get(LayoutGraphData::LayoutTag{}, lg, subpassOrPassID);
|
||||
const auto &phaseLayout = get(LayoutGraphData::LayoutTag{}, lg, phaseID);
|
||||
gfx::PipelineLayoutInfo info;
|
||||
populatePipelineLayoutInfo(*this, passLayout, UpdateFrequency::PER_PASS, info);
|
||||
@@ -1247,16 +1255,17 @@ void NativeProgramLibrary::addEffect(const EffectAsset *effectAssetIn) {
|
||||
for (const auto &tech : effect._techniques) {
|
||||
for (const auto &pass : tech.passes) {
|
||||
const auto &programName = pass.program;
|
||||
const auto [passID, phaseID, pShaderInfo, shaderID] =
|
||||
const auto [passID, subpassID, phaseID, pShaderInfo, shaderID] =
|
||||
getEffectShader(lg, effect, pass);
|
||||
if (pShaderInfo == nullptr || validateShaderInfo(*pShaderInfo)) {
|
||||
CC_LOG_ERROR("program not found");
|
||||
continue;
|
||||
}
|
||||
const auto subpassOrPassID = subpassID == INVALID_ID ? passID : subpassID;
|
||||
const auto &srcShaderInfo = *pShaderInfo;
|
||||
CC_ENSURES(passID != INVALID_ID && phaseID != INVALID_ID);
|
||||
const auto &passLayout = get(LayoutGraphData::LayoutTag{}, lg, passID);
|
||||
const auto &phaseLayout = get(LayoutGraphData::LayoutTag{}, lg, phaseID);
|
||||
CC_ENSURES(subpassOrPassID != INVALID_ID && phaseID != INVALID_ID);
|
||||
const auto &passLayout = get(LayoutGraphData::LayoutTag{}, lg, subpassOrPassID);
|
||||
const auto &phaseLayout = get(LayoutGraphData::LayoutTag{}, lg, subpassOrPassID);
|
||||
|
||||
// programs
|
||||
auto iter = this->phases.find(phaseID);
|
||||
@@ -1365,13 +1374,13 @@ IntrusivePtr<gfx::PipelineLayout> NativeProgramLibrary::getPipelineLayout(
|
||||
}
|
||||
|
||||
// get pass
|
||||
const auto passID = parent(phaseID, lg);
|
||||
if (passID == LayoutGraphData::null_vertex()) {
|
||||
const auto subpassOrPassID = parent(phaseID, lg);
|
||||
if (subpassOrPassID == LayoutGraphData::null_vertex()) {
|
||||
return emptyPipelineLayout;
|
||||
}
|
||||
// create pipeline layout
|
||||
gfx::PipelineLayoutInfo info{};
|
||||
auto *passSet = getDescriptorSetLayout(lg, passID, phaseID, UpdateFrequency::PER_PASS);
|
||||
auto *passSet = getDescriptorSetLayout(lg, subpassOrPassID, phaseID, UpdateFrequency::PER_PASS);
|
||||
if (passSet) {
|
||||
info.setLayouts.emplace_back(passSet);
|
||||
}
|
||||
@@ -1385,7 +1394,7 @@ IntrusivePtr<gfx::PipelineLayout> NativeProgramLibrary::getPipelineLayout(
|
||||
if (instanceSet) {
|
||||
info.setLayouts.emplace_back(instanceSet);
|
||||
}
|
||||
auto *phaseSet = getDescriptorSetLayout(lg, passID, phaseID, UpdateFrequency::PER_PHASE);
|
||||
auto *phaseSet = getDescriptorSetLayout(lg, subpassOrPassID, phaseID, UpdateFrequency::PER_PHASE);
|
||||
if (phaseSet) {
|
||||
info.setLayouts.emplace_back(phaseSet);
|
||||
}
|
||||
@@ -1397,9 +1406,9 @@ const gfx::DescriptorSetLayout &NativeProgramLibrary::getMaterialDescriptorSetLa
|
||||
gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) {
|
||||
if (mergeHighFrequency) {
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto passID = parent(phaseID, layoutGraph);
|
||||
const auto subpassOrPassID = parent(phaseID, layoutGraph);
|
||||
return getOrCreateDescriptorSetLayout(
|
||||
*this, layoutGraph, passID, phaseID, UpdateFrequency::PER_BATCH);
|
||||
*this, layoutGraph, subpassOrPassID, phaseID, UpdateFrequency::PER_BATCH);
|
||||
}
|
||||
return getOrCreateProgramDescriptorSetLayout(
|
||||
*this, device, layoutGraph, phaseID, programName, UpdateFrequency::PER_BATCH);
|
||||
@@ -1409,9 +1418,9 @@ const gfx::DescriptorSetLayout &NativeProgramLibrary::getLocalDescriptorSetLayou
|
||||
gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) {
|
||||
if (mergeHighFrequency) {
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto passID = parent(phaseID, layoutGraph);
|
||||
const auto subpassOrPassID = parent(phaseID, layoutGraph);
|
||||
return getOrCreateDescriptorSetLayout(
|
||||
*this, layoutGraph, passID, phaseID, UpdateFrequency::PER_INSTANCE);
|
||||
*this, layoutGraph, subpassOrPassID, phaseID, UpdateFrequency::PER_INSTANCE);
|
||||
}
|
||||
if (fixedLocal) {
|
||||
return *localDescriptorSetLayout;
|
||||
|
||||
Reference in New Issue
Block a user