mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 17:42:41 +08:00
V3.8.2 pipeline (#16244)
This commit is contained in:
@@ -26,13 +26,83 @@
|
||||
#include <iterator>
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "cocos/renderer/pipeline/Define.h"
|
||||
#include "cocos/renderer/pipeline/InstancedBuffer.h"
|
||||
#include "cocos/renderer/pipeline/PipelineStateManager.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/GslUtils.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
LayoutGraphData::vertex_descriptor ProbeHelperQueue::getDefaultId(const LayoutGraphData &lg) {
|
||||
const auto passID = locate(LayoutGraphData::null_vertex(), "default", lg);
|
||||
CC_ENSURES(passID != LayoutGraphData::null_vertex());
|
||||
const auto phaseID = locate(passID, "default", lg);
|
||||
CC_ENSURES(phaseID != LayoutGraphData::null_vertex());
|
||||
return phaseID;
|
||||
}
|
||||
|
||||
void ProbeHelperQueue::removeMacro() const {
|
||||
for (auto *subModel : probeMap) {
|
||||
std::vector<cc::scene::IMacroPatch> patches;
|
||||
patches.insert(patches.end(), subModel->getPatches().begin(), subModel->getPatches().end());
|
||||
|
||||
for (int j = 0; j != patches.size(); ++j) {
|
||||
const cc::scene::IMacroPatch &patch = patches[j];
|
||||
if (patch.name == "CC_USE_RGBE_OUTPUT") {
|
||||
patches.erase(patches.begin() + j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
subModel->onMacroPatchesStateChanged(patches);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ProbeHelperQueue::getPassIndexFromLayout(
|
||||
const cc::IntrusivePtr<cc::scene::SubModel> &subModel,
|
||||
LayoutGraphData::vertex_descriptor phaseLayoutId) {
|
||||
const auto &passes = subModel->getPasses();
|
||||
for (uint32_t k = 0; k != passes->size(); ++k) {
|
||||
if (passes->at(k)->getPhaseID() == phaseLayoutId) {
|
||||
return static_cast<int>(k);
|
||||
}
|
||||
}
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
void ProbeHelperQueue::applyMacro(
|
||||
const LayoutGraphData &lg, const cc::scene::Model &model,
|
||||
LayoutGraphData::vertex_descriptor probeLayoutId) {
|
||||
const std::vector<cc::IntrusivePtr<cc::scene::SubModel>> &subModels = model.getSubModels();
|
||||
for (const auto &subModel : subModels) {
|
||||
const bool isTransparent = subModel->getPasses()->at(0)->getBlendState()->targets[0].blend;
|
||||
if (isTransparent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto passIdx = getPassIndexFromLayout(subModel, probeLayoutId);
|
||||
bool bUseReflectPass = true;
|
||||
if (passIdx < 0) {
|
||||
probeLayoutId = getDefaultId(lg);
|
||||
passIdx = getPassIndexFromLayout(subModel, probeLayoutId);
|
||||
bUseReflectPass = false;
|
||||
}
|
||||
if (passIdx < 0) {
|
||||
continue;
|
||||
}
|
||||
if (!bUseReflectPass) {
|
||||
std::vector<cc::scene::IMacroPatch> patches;
|
||||
patches.insert(patches.end(), subModel->getPatches().begin(), subModel->getPatches().end());
|
||||
const cc::scene::IMacroPatch useRGBEPatch = {"CC_USE_RGBE_OUTPUT", true};
|
||||
patches.emplace_back(useRGBEPatch);
|
||||
subModel->onMacroPatchesStateChanged(patches);
|
||||
probeMap.emplace_back(subModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
void RenderDrawQueue::add(const scene::Model &model, float depth, uint32_t subModelIdx, uint32_t passIdx) {
|
||||
const auto *subModel = model.getSubModels()[subModelIdx].get();
|
||||
@@ -62,9 +132,9 @@ void RenderDrawQueue::sortTransparent() {
|
||||
}
|
||||
|
||||
void RenderDrawQueue::recordCommandBuffer(
|
||||
gfx::Device * /*device*/, const scene::Camera * /*camera*/,
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff,
|
||||
uint32_t subpassIndex) const {
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuff,
|
||||
uint32_t lightByteOffset) const {
|
||||
for (const auto &instance : instances) {
|
||||
const auto *subModel = instance.subModel;
|
||||
|
||||
@@ -76,7 +146,11 @@ void RenderDrawQueue::recordCommandBuffer(
|
||||
|
||||
cmdBuff->bindPipelineState(pso);
|
||||
cmdBuff->bindDescriptorSet(pipeline::materialSet, pass->getDescriptorSet());
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet());
|
||||
if (lightByteOffset != 0xFFFFFFFF) {
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet(), 1, &lightByteOffset);
|
||||
} else {
|
||||
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet());
|
||||
}
|
||||
cmdBuff->bindInputAssembler(inputAssembler);
|
||||
cmdBuff->draw(inputAssembler);
|
||||
}
|
||||
@@ -138,8 +212,9 @@ void RenderInstancingQueue::uploadBuffers(gfx::CommandBuffer *cmdBuffer) const {
|
||||
}
|
||||
|
||||
void RenderInstancingQueue::recordCommandBuffer(
|
||||
gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer,
|
||||
gfx::DescriptorSet *ds, uint32_t offset, const ccstd::vector<uint32_t> *dynamicOffsets) const {
|
||||
gfx::RenderPass *renderPass, uint32_t subpassIndex,
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
uint32_t lightByteOffset) const { //
|
||||
const auto &renderQueue = sortedBatches;
|
||||
for (const auto *instanceBuffer : renderQueue) {
|
||||
if (!instanceBuffer->hasPendingModels()) {
|
||||
@@ -154,16 +229,13 @@ void RenderInstancingQueue::recordCommandBuffer(
|
||||
continue;
|
||||
}
|
||||
auto *pso = pipeline::PipelineStateManager::getOrCreatePipelineState(
|
||||
drawPass, instance.shader, instance.ia, renderPass);
|
||||
drawPass, instance.shader, instance.ia, renderPass, subpassIndex);
|
||||
if (lastPSO != pso) {
|
||||
cmdBuffer->bindPipelineState(pso);
|
||||
lastPSO = pso;
|
||||
}
|
||||
if (ds) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::globalSet, ds, 1, &offset);
|
||||
}
|
||||
if (dynamicOffsets) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, *dynamicOffsets);
|
||||
if (lightByteOffset != 0xFFFFFFFF) {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, 1, &lightByteOffset);
|
||||
} else {
|
||||
cmdBuffer->bindDescriptorSet(pipeline::localSet, instance.descriptorSet, instanceBuffer->dynamicOffsets());
|
||||
}
|
||||
@@ -180,6 +252,20 @@ void NativeRenderQueue::sort() {
|
||||
transparentInstancingQueue.sort();
|
||||
}
|
||||
|
||||
void NativeRenderQueue::recordCommands(
|
||||
gfx::CommandBuffer *cmdBuffer,
|
||||
gfx::RenderPass *renderPass,
|
||||
uint32_t subpassIndex) const {
|
||||
opaqueQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
opaqueInstancingQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
transparentQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
transparentInstancingQueue.recordCommandBuffer(
|
||||
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
Reference in New Issue
Block a user