Async render passes

This commit is contained in:
2021-11-24 12:10:23 +01:00
parent 94be513538
commit 5fafdda770
23 changed files with 199 additions and 162 deletions
+18 -8
View File
@@ -20,13 +20,13 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
{
}
void BasePassMeshProcessor::addMeshBatch(
Job BasePassMeshProcessor::processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet>& descriptorSets,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 /*staticMeshId*/)
{
PMaterialAsset material = batch.material;
@@ -34,11 +34,12 @@ void BasePassMeshProcessor::addMeshBatch(
const PVertexShaderInput vertexInput = batch.vertexInput;
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
const Gfx::ShaderCollection* collection = material->getShaders(Gfx::RenderPassType::BasePass, vertexInput->getType());
assert(collection != nullptr);
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand();
renderCommand->setViewport(target);
pipelineLayout->addDescriptorLayout(BasePass::INDEX_MATERIAL, material->getDescriptorLayout());
pipelineLayout->create();
Gfx::PDescriptorSet materialSet = material->createDescriptorSet();
@@ -63,6 +64,7 @@ void BasePassMeshProcessor::addMeshBatch(
false);
}
renderCommands.add(renderCommand);
co_return;
}
Array<Gfx::PRenderCommand> BasePassMeshProcessor::getRenderCommands()
@@ -120,7 +122,7 @@ BasePass::~BasePass()
{
}
void BasePass::beginFrame()
Job BasePass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
@@ -140,9 +142,10 @@ void BasePass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
co_return;
}
void BasePass::render()
Job BasePass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
@@ -159,16 +162,23 @@ void BasePass::render()
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
graphics->beginRenderPass(renderPass);
List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList)
{
processor->addMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
jobs.add(processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets));
}
for(auto& job : jobs)
{
co_await job;
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
co_return;
}
void BasePass::endFrame()
Job BasePass::endFrame()
{
co_return;
}
void BasePass::publishOutputs()
+6 -6
View File
@@ -11,13 +11,13 @@ public:
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor();
virtual void addMeshBatch(
virtual Job processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet>& descriptorSets,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId = -1) override;
Array<Gfx::PRenderCommand> getRenderCommands();
void clearCommands();
@@ -40,9 +40,9 @@ class BasePass : public RenderPass<BasePassData>
public:
BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
virtual ~BasePass();
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual Job beginFrame() override;
virtual Job render() override;
virtual Job endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
@@ -18,13 +18,13 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
{
}
void DepthPrepassMeshProcessor::addMeshBatch(
Job DepthPrepassMeshProcessor::processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet>& descriptorSets,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 /*staticMeshId*/)
{
PMaterialAsset material = batch.material;
@@ -61,6 +61,7 @@ void DepthPrepassMeshProcessor::addMeshBatch(
true);
}
renderCommands.add(renderCommand);
co_return;
}
Array<Gfx::PRenderCommand> DepthPrepassMeshProcessor::getRenderCommands()
@@ -104,7 +105,7 @@ DepthPrepass::~DepthPrepass()
{
}
void DepthPrepass::beginFrame()
Job DepthPrepass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
@@ -122,26 +123,33 @@ void DepthPrepass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
co_return;
}
void DepthPrepass::render()
Job DepthPrepass::render()
{
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
graphics->beginRenderPass(renderPass);
List<Job> jobs;
for (auto &&meshBatch : passData.staticDrawList)
{
processor->addMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets);
jobs.add(processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets));
}
for(auto& job : jobs)
{
co_await job;
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
co_return;
}
void DepthPrepass::endFrame()
Job DepthPrepass::endFrame()
{
co_return;
}
void DepthPrepass::publishOutputs()
@@ -11,12 +11,12 @@ public:
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
virtual ~DepthPrepassMeshProcessor();
virtual void addMeshBatch(
virtual Job processMeshBatch(
const MeshBatch& batch,
const Gfx::PRenderPass renderPass,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet>& descriptorSets,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId = -1) override;
Array<Gfx::PRenderCommand> getRenderCommands();
@@ -39,9 +39,9 @@ class DepthPrepass : public RenderPass<DepthPrepassData>
public:
DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
~DepthPrepass();
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual Job beginFrame() override;
virtual Job render() override;
virtual Job endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
@@ -18,7 +18,7 @@ LightCullingPass::~LightCullingPass()
}
void LightCullingPass::beginFrame()
Job LightCullingPass::beginFrame()
{
uint32_t viewportWidth = viewport->getSizeX();
uint32_t viewportHeight = viewport->getSizeY();
@@ -75,9 +75,10 @@ void LightCullingPass::beginFrame()
lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer);
lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer);
lightEnvDescriptorSet->writeChanges();
co_return;
}
void LightCullingPass::render()
Job LightCullingPass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
@@ -101,11 +102,12 @@ void LightCullingPass::render()
graphics->executeCommands(commands);
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS);
co_return;
}
void LightCullingPass::endFrame()
Job LightCullingPass::endFrame()
{
co_return;
}
void LightCullingPass::publishOutputs()
@@ -18,9 +18,9 @@ class LightCullingPass : public RenderPass<LightCullingPassData>
public:
LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera);
virtual ~LightCullingPass();
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual Job beginFrame() override;
virtual Job render() override;
virtual Job endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
static void modifyRenderPassMacros(Map<const char*, const char*>& defines);
@@ -3,6 +3,7 @@
#include "Scene/Scene.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/MeshBatch.h"
#include "ThreadPool.h"
namespace Seele
{
@@ -14,13 +15,13 @@ public:
protected:
PScene scene;
Gfx::PGraphics graphics;
virtual void addMeshBatch(
const MeshBatch& meshBatch,
virtual Job processMeshBatch(
const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent,
const Gfx::PRenderPass renderPass,
const Gfx::PRenderPass& renderPass,
Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet>& descriptorSets,
Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId = -1) = 0;
void buildMeshDrawCommand(
const MeshBatch& meshBatch,
+4 -3
View File
@@ -2,6 +2,7 @@
#include "MinimalEngine.h"
#include "Math/Math.h"
#include "RenderGraph.h"
#include "ThreadPool.h"
namespace Seele
{
@@ -21,9 +22,9 @@ public:
void updateViewFrame(RenderPassDataType viewFrame) {
passData = std::move(viewFrame);
}
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
virtual Job beginFrame() = 0;
virtual Job render() = 0;
virtual Job endFrame() = 0;
virtual void publishOutputs() = 0;
virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources resources) { this->resources = resources; }
+6 -5
View File
@@ -15,12 +15,12 @@ UIPass::~UIPass()
}
void UIPass::beginFrame()
Job UIPass::beginFrame()
{
co_return;
}
void UIPass::render()
Job UIPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
@@ -29,11 +29,12 @@ void UIPass::render()
command->draw(4, 1, 0, 0);
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
graphics->endRenderPass();
co_return;
}
void UIPass::endFrame()
Job UIPass::endFrame()
{
co_return;
}
void UIPass::publishOutputs()
+3 -3
View File
@@ -16,9 +16,9 @@ class UIPass : public RenderPass<UIPassData>
public:
UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
virtual ~UIPass();
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
virtual Job beginFrame() override;
virtual Job render() override;
virtual Job endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private: