mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
fix RenderInstancedQueue
This commit is contained in:
@@ -37,12 +37,12 @@ public:
|
||||
|
||||
CC_INLINE const InstancedItemList &getInstances() const { return _instancedItems; }
|
||||
CC_INLINE const PipelineStateInfo *getPSOCI() const { return _psoci; }
|
||||
CC_INLINE Pass *getPass() const { return _pass; }
|
||||
CC_INLINE const Pass *getPass() const { return _pass; }
|
||||
|
||||
private:
|
||||
static map<const Pass *, std::shared_ptr<InstancedBuffer>> _buffers;
|
||||
InstancedItemList _instancedItems;
|
||||
Pass *_pass = nullptr;
|
||||
const Pass *_pass = nullptr;
|
||||
const PipelineStateInfo *_psoci = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
namespace cc {
|
||||
namespace pipeline {
|
||||
map<uint, gfx::PipelineState *> PipelineStateManager::_PSOHashMap;
|
||||
gfx::PipelineState *PipelineStateManager::getOrCreatePipelineStage(uint psociID,
|
||||
uint passID,
|
||||
gfx::PipelineState *PipelineStateManager::getOrCreatePipelineStage(const PipelineStateInfo *psoci,
|
||||
const Pass *pass,
|
||||
const gfx::InputAssembler *inputAssembler,
|
||||
gfx::RenderPass *renderPass) {
|
||||
const auto *psoci = GET_PSOCI(psociID, 0);
|
||||
const auto *pass = GET_PASS(psoci->passID, 0);
|
||||
const auto passHash = pass->hash;
|
||||
const auto iaHash = inputAssembler->getAttributesHash();
|
||||
const auto hash = passHash ^ passHash ^ iaHash;
|
||||
|
||||
@@ -7,15 +7,16 @@ namespace gfx {
|
||||
class InputAssembler;
|
||||
class PipelineState;
|
||||
class RenderPass;
|
||||
struct PipelineStateInfo;
|
||||
}; // namespace gfx
|
||||
|
||||
namespace pipeline {
|
||||
struct PipelineStateInfo;
|
||||
struct Pass;
|
||||
|
||||
class CC_DLL PipelineStateManager {
|
||||
public:
|
||||
static gfx::PipelineState *getOrCreatePipelineStage(uint psociID,
|
||||
uint passID,
|
||||
static gfx::PipelineState *getOrCreatePipelineStage(const PipelineStateInfo *psoci,
|
||||
const Pass *pass,
|
||||
const gfx::InputAssembler *inputAssembler,
|
||||
gfx::RenderPass *renderPass);
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "RenderInstancedQueue.h"
|
||||
#include "InstancedBuffer.h"
|
||||
#include "PipelineStateManager.h"
|
||||
#include "gfx/GFXCommandBuffer.h"
|
||||
#include "helper/Pass.h"
|
||||
|
||||
namespace cc {
|
||||
namespace pipeline {
|
||||
void RenderInstancedQueue::clear() {
|
||||
for(auto it : _queues) {
|
||||
for (auto it : _queues) {
|
||||
it->clear();
|
||||
}
|
||||
_queues.clear();
|
||||
@@ -15,44 +17,26 @@ void RenderInstancedQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderP
|
||||
for (auto instanceBuffer : _queues) {
|
||||
const auto &instances = instanceBuffer->getInstances();
|
||||
const auto psoci = instanceBuffer->getPSOCI();
|
||||
if(psoci) {
|
||||
const auto pass = instanceBuffer->getPass();
|
||||
if (psoci) {
|
||||
instanceBuffer->uploadBuffers();
|
||||
gfx::PipelineState *lastPSO = nullptr;
|
||||
for (size_t b = 0; b < instances.size(); ++b) {
|
||||
const auto &instance = instances[b];
|
||||
if (!instance.count) { continue; }
|
||||
// auto pso = PipelineStateManager::getOrCreatePipelineStage(psoci, instance.ia, renderPass);
|
||||
// if (lastPSO !== pso) {
|
||||
// cmdBuff.bindPipelineState(pso);
|
||||
// cmdBuff.bindBindingLayout(psoci.bindingLayout);
|
||||
// lastPSO = pso;
|
||||
// }
|
||||
// cmdBuff.bindInputAssembler(instance.ia);
|
||||
// cmdBuff.draw(instance.ia);
|
||||
if (!instance.count) {
|
||||
continue;
|
||||
}
|
||||
auto pso = PipelineStateManager::getOrCreatePipelineStage(psoci, pass, instance.ia, renderPass);
|
||||
if (lastPSO != pso) {
|
||||
cmdBuff->bindPipelineState(pso);
|
||||
cmdBuff->bindBindingLayout(GET_BINDING_LAYOUT(psoci->bindingLayoutID));
|
||||
lastPSO = pso;
|
||||
}
|
||||
cmdBuff->bindInputAssembler(instance.ia);
|
||||
cmdBuff->draw(instance.ia);
|
||||
}
|
||||
}
|
||||
}
|
||||
// const it = this.queue.values(); let res = it.next();
|
||||
// while (!res.done) {
|
||||
// const { instances, psoci } = res.value;
|
||||
// if (psoci) {
|
||||
// res.value.uploadBuffers();
|
||||
// let lastPSO: GFXPipelineState | null = null;
|
||||
// for (let b = 0; b < instances.length; ++b) {
|
||||
// const instance = instances[b];
|
||||
// if (!instance.count) { continue; }
|
||||
// const pso = PipelineStateManager.getOrCreatePipelineState(device, psoci, renderPass, instance.ia);
|
||||
// if (lastPSO !== pso) {
|
||||
// cmdBuff.bindPipelineState(pso);
|
||||
// cmdBuff.bindBindingLayout(psoci.bindingLayout);
|
||||
// lastPSO = pso;
|
||||
// }
|
||||
// cmdBuff.bindInputAssembler(instance.ia);
|
||||
// cmdBuff.draw(instance.ia);
|
||||
// }
|
||||
// }
|
||||
// res = it.next();
|
||||
// }
|
||||
}
|
||||
|
||||
} // namespace pipeline
|
||||
|
||||
@@ -42,7 +42,7 @@ void RenderQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *rend
|
||||
const auto iaPtr = GET_IA(subModelPtr->iaID);
|
||||
const auto psoCIPtr = GET_PSOCI(subModelPtr->psociID, passIdx);
|
||||
const auto passPtr = GET_PASS(subModelPtr->materialID, passIdx);
|
||||
auto *pso = PipelineStateManager::getOrCreatePipelineStage(subModelPtr->psociID, passIdx, iaPtr, renderPass);
|
||||
auto *pso = PipelineStateManager::getOrCreatePipelineStage(psoCIPtr, passPtr, iaPtr, renderPass);
|
||||
cmdBuff->bindPipelineState(pso);
|
||||
cmdBuff->bindBindingLayout(GET_BINDING_LAYOUT(psoCIPtr->bindingLayoutID));
|
||||
cmdBuff->bindInputAssembler(iaPtr);
|
||||
|
||||
@@ -34,6 +34,7 @@ void LinearToSRGB(gfx::Color &out, const gfx::Color &linear) {
|
||||
out.b = std::sqrt(linear.b);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ForwardStage::ForwardStage() : RenderStage() {
|
||||
_batchedQueue = CC_NEW(RenderBatchedQueue);
|
||||
_instancedQueue = CC_NEW(RenderInstancedQueue);
|
||||
@@ -49,7 +50,8 @@ bool ForwardStage::initialize(const RenderStageInfo &info) {
|
||||
RenderStage::initialize(info);
|
||||
_renderQueueDescriptors = {
|
||||
{false, RenderQueueSortMode::FRONT_TO_BACK, {"default"}},
|
||||
{true, RenderQueueSortMode::BACK_TO_FRONT, {"default", "planarShadow"}}};
|
||||
{true, RenderQueueSortMode::BACK_TO_FRONT, {"default", "planarShadow"}}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user