Screw rendergraphs (for now)

This commit is contained in:
Dynamitos
2021-10-01 19:55:04 +02:00
parent bd739068d6
commit 5dfc8300c5
25 changed files with 222 additions and 226 deletions
+17 -22
View File
@@ -8,8 +8,8 @@
using namespace Seele;
BasePassMeshProcessor::BasePassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass)
: MeshProcessor(scene, graphics)
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass)
: MeshProcessor(graphics)
, target(viewport)
, translucentBasePass(translucentBasePass)
, cachedPrimitiveIndex(0)
@@ -79,9 +79,9 @@ void BasePassMeshProcessor::clearCommands()
cachedPrimitiveIndex = 0;
}
BasePass::BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(renderGraph, graphics, viewport)
, processor(new BasePassMeshProcessor(scene, viewport, graphics, false))
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(graphics, viewport)
, processor(new BasePassMeshProcessor(viewport, graphics, false))
, descriptorSets(4)
, source(source->getCameraComponent())
{
@@ -124,11 +124,6 @@ BasePass::~BasePass()
{
}
void BasePass::updateViewFrame(PViewFrame viewFrame)
{
}
void BasePass::beginFrame()
{
processor->clearCommands();
@@ -149,10 +144,10 @@ void BasePass::beginFrame()
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
/*for(auto &&meshBatch : scene->getStaticMeshes())
for(auto &&meshBatch : passData.staticDrawList)
{
meshBatch.material->updateDescriptorData();
}*/
}
}
void BasePass::render()
@@ -173,10 +168,10 @@ void BasePass::render()
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
graphics->beginRenderPass(renderPass);
/*for (auto &&meshBatch : scene->getStaticMeshes())
for (auto &&meshBatch : passData.staticDrawList)
{
processor->addMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets);
}*/
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
}
@@ -188,21 +183,21 @@ void BasePass::endFrame()
void BasePass::publishOutputs()
{
colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
renderGraph->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
}
void BasePass::createRenderPass()
{
directLightBuffer = renderGraph->requestBuffer("DIRECTIONAL_LIGHTS");
pointLightBuffer = renderGraph->requestBuffer("POINT_LIGHTS");
numDirLightBuffer = renderGraph->requestUniform("NUM_DIRECTIONAL_LIGHTS");
numPointLightBuffer = renderGraph->requestUniform("NUM_POINT_LIGHTS");
Gfx::PRenderTargetAttachment depthAttachment = renderGraph->requestRenderTarget("DEPTHPREPASS_DEPTH");
directLightBuffer = resources->requestBuffer("DIRECTIONAL_LIGHTS");
pointLightBuffer = resources->requestBuffer("POINT_LIGHTS");
numDirLightBuffer = resources->requestUniform("NUM_DIRECTIONAL_LIGHTS");
numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS");
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
oLightIndexList = renderGraph->requestBuffer("LIGHTCULLING_OLIGHTLIST");
oLightGrid = renderGraph->requestTexture("LIGHTCULLING_OLIGHTGRID");
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
}
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
+3 -5
View File
@@ -8,7 +8,7 @@ namespace Seele
class BasePassMeshProcessor : public MeshProcessor
{
public:
BasePassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor();
virtual void addMeshBatch(
@@ -33,15 +33,13 @@ DECLARE_REF(CameraActor)
DECLARE_REF(CameraComponent)
struct BasePassData
{
const LightEnv lightEnv;
const Array<StaticMeshBatch> staticDrawList;
};
class BasePass : public RenderPass
class BasePass : public RenderPass<BasePassData>
{
public:
BasePass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
virtual ~BasePass();
virtual void updateViewFrame(PViewFrame viewFrame) override;
virtual void beginFrame() override;
virtual void render() override;
virtual void endFrame() override;
@@ -11,6 +11,5 @@ target_sources(SeeleEngine
RenderGraph.h
RenderGraph.cpp
RenderPass.h
RenderPass.cpp
UIPass.h
UIPass.cpp)
+11 -11
View File
@@ -8,8 +8,8 @@
using namespace Seele;
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics)
: MeshProcessor(scene, graphics)
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics)
: MeshProcessor(graphics)
, target(viewport)
, cachedPrimitiveIndex(0)
{
@@ -78,9 +78,9 @@ void DepthPrepassMeshProcessor::clearCommands()
cachedPrimitiveIndex = 0;
}
DepthPrepass::DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(renderGraph, graphics, viewport)
, processor(new DepthPrepassMeshProcessor(scene, viewport, graphics))
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source)
: RenderPass(graphics, viewport)
, processor(new DepthPrepassMeshProcessor(viewport, graphics))
, descriptorSets(3)
, source(source->getCameraComponent())
{
@@ -107,7 +107,7 @@ DepthPrepass::~DepthPrepass()
{
}
void DepthPrepass::beginFrame(UPViewFrame& viewFrame)
void DepthPrepass::beginFrame()
{
processor->clearCommands();
primitiveLayout->reset();
@@ -125,13 +125,13 @@ void DepthPrepass::beginFrame(UPViewFrame& viewFrame)
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
/*for(auto &&meshBatch : scene->getStaticMeshes())
for(auto &&meshBatch : passData.staticDrawList)
{
meshBatch.material->updateDescriptorData();
}*/
}
}
void DepthPrepass::render(UPViewFrame& viewFrame)
void DepthPrepass::render()
{
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
@@ -146,7 +146,7 @@ void DepthPrepass::render(UPViewFrame& viewFrame)
graphics->endRenderPass();
}
void DepthPrepass::endFrame(UPViewFrame& viewFrame)
void DepthPrepass::endFrame()
{
}
@@ -163,7 +163,7 @@ void DepthPrepass::publishOutputs()
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f;
renderGraph->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
}
void DepthPrepass::createRenderPass()
@@ -8,7 +8,7 @@ namespace Seele
class DepthPrepassMeshProcessor : public MeshProcessor
{
public:
DepthPrepassMeshProcessor(const PScene scene, Gfx::PViewport viewport, Gfx::PGraphics graphics);
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics);
virtual ~DepthPrepassMeshProcessor();
virtual void addMeshBatch(
@@ -30,10 +30,14 @@ private:
DEFINE_REF(DepthPrepassMeshProcessor)
DECLARE_REF(CameraActor)
DECLARE_REF(CameraComponent)
class DepthPrepass : public RenderPass
struct DepthPrepassData
{
const Array<StaticMeshBatch> staticDrawList;
};
class DepthPrepass : public RenderPass<DepthPrepassData>
{
public:
DepthPrepass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source);
~DepthPrepass();
virtual void beginFrame() override;
virtual void render() override;
@@ -7,8 +7,8 @@
using namespace Seele;
LightCullingPass::LightCullingPass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera)
: RenderPass(renderGraph, graphics, viewport)
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera)
: RenderPass(graphics, viewport)
, source(camera->getCameraComponent())
{
}
@@ -18,7 +18,7 @@ LightCullingPass::~LightCullingPass()
}
void LightCullingPass::beginFrame(UPViewFrame& viewFrame)
void LightCullingPass::beginFrame()
{
uint32_t viewportWidth = viewport->getSizeX();
uint32_t viewportHeight = viewport->getSizeY();
@@ -33,7 +33,7 @@ void LightCullingPass::beginFrame(UPViewFrame& viewFrame)
uniformUpdate.data = (uint8*)&viewParams;
viewParamsBuffer->updateContents(uniformUpdate);
/*LightEnv lightEnv = scene->getLightBuffer();
LightEnv lightEnv = passData.lightEnv;
for(uint32 i = 0; i < lightEnv.numPointLights; ++i)
{
lightEnv.pointLights[i].positionVS = lightEnv.pointLights[i].positionWS;
@@ -41,7 +41,7 @@ void LightCullingPass::beginFrame(UPViewFrame& viewFrame)
uniformUpdate.size = sizeof(PointLight) * MAX_POINT_LIGHTS;
uniformUpdate.data = (uint8*)&lightEnv.pointLights;
pointLightBuffer->updateContents(uniformUpdate);
*/
BulkResourceData counterReset;
uint32 reset = 0;
counterReset.data = (uint8*)&reset;
@@ -71,7 +71,7 @@ void LightCullingPass::beginFrame(UPViewFrame& viewFrame)
lightEnvDescriptorSet->writeChanges();
}
void LightCullingPass::render(UPViewFrame& viewFrame)
void LightCullingPass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
@@ -97,7 +97,7 @@ void LightCullingPass::render(UPViewFrame& viewFrame)
depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS);
}
void LightCullingPass::endFrame(UPViewFrame& viewFrame)
void LightCullingPass::endFrame()
{
}
@@ -130,32 +130,33 @@ void LightCullingPass::publishOutputs()
structInfo.bDynamic = false;
oLightIndexList = graphics->createStructuredBuffer(structInfo);
tLightIndexList = graphics->createStructuredBuffer(structInfo);
renderGraph->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
renderGraph->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
/*const LightEnv& lightEnv = scene->getLightBuffer();
resources->registerBufferOutput("LIGHTCULLING_OLIGHTLIST", oLightIndexList);
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
const LightEnv& lightEnv = passData.lightEnv;
resourceData.size = sizeof(DirectionalLight) * MAX_DIRECTIONAL_LIGHTS;
resourceData.data = (uint8*)&lightEnv.directionalLights;*/
resourceData.data = (uint8*)&lightEnv.directionalLights;
structInfo.resourceData = resourceData;
structInfo.bDynamic = true;
directLightBuffer = graphics->createStructuredBuffer(structInfo);
resourceData.size = sizeof(PointLight) * MAX_POINT_LIGHTS;
//resourceData.data = (uint8*)&lightEnv.pointLights;
resourceData.data = (uint8*)&lightEnv.pointLights;
structInfo.resourceData = resourceData;
pointLightBuffer = graphics->createStructuredBuffer(structInfo);
UniformBufferCreateInfo uniformInfo;
resourceData.size = sizeof(uint32);
//resourceData.data = (uint8*)&lightEnv.numDirectionalLights;
resourceData.data = (uint8*)&lightEnv.numDirectionalLights;
uniformInfo.resourceData = resourceData;
uniformInfo.bDynamic = true;
numDirLightBuffer = graphics->createUniformBuffer(uniformInfo);
//resourceData.data = (uint8*)&lightEnv.numPointLights;
resourceData.data = (uint8*)&lightEnv.numPointLights;
uniformInfo.resourceData = resourceData;
uniformInfo.bDynamic = true;
numPointLightBuffer = graphics->createUniformBuffer(uniformInfo);
renderGraph->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer);
renderGraph->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer);
renderGraph->registerBufferOutput("POINT_LIGHTS", pointLightBuffer);
renderGraph->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer);
resources->registerBufferOutput("DIRECTIONAL_LIGHTS", directLightBuffer);
resources->registerUniformOutput("NUM_DIRECTIONAL_LIGHTS", numDirLightBuffer);
resources->registerBufferOutput("POINT_LIGHTS", pointLightBuffer);
resources->registerUniformOutput("NUM_POINT_LIGHTS", numPointLightBuffer);
TextureCreateInfo textureInfo;
textureInfo.width = dispatchParams.numThreadGroups.x;
textureInfo.height = dispatchParams.numThreadGroups.y;
@@ -163,9 +164,8 @@ void LightCullingPass::publishOutputs()
textureInfo.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT;
oLightGrid = graphics->createTexture2D(textureInfo);
tLightGrid = graphics->createTexture2D(textureInfo);
renderGraph->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid);
renderGraph->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid);
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid);
}
@@ -229,7 +229,7 @@ void LightCullingPass::createRenderPass()
pipelineInfo.pipelineLayout = cullingLayout;
cullingPipeline = graphics->createComputePipeline(pipelineInfo);
depthAttachment = renderGraph->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture();
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH")->getTexture();
}
void LightCullingPass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
@@ -1,6 +1,7 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
#include "Scene/Scene.h"
namespace Seele
{
@@ -8,10 +9,14 @@ DECLARE_REF(CameraActor)
DECLARE_REF(CameraComponent)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
class LightCullingPass : public RenderPass
struct LightCullingPassData
{
const LightEnv lightEnv;
};
class LightCullingPass : public RenderPass<LightCullingPassData>
{
public:
LightCullingPass(PRenderGraph renderGraph, const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera);
LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera);
virtual ~LightCullingPass();
virtual void beginFrame() override;
virtual void render() override;
@@ -4,9 +4,8 @@
using namespace Seele;
MeshProcessor::MeshProcessor(const PScene scene, Gfx::PGraphics graphics)
: scene(scene)
, graphics(graphics)
MeshProcessor::MeshProcessor(Gfx::PGraphics graphics)
: graphics(graphics)
{
}
@@ -9,7 +9,7 @@ namespace Seele
class MeshProcessor
{
public:
MeshProcessor(const PScene scene, Gfx::PGraphics graphics);
MeshProcessor(Gfx::PGraphics graphics);
virtual ~MeshProcessor();
protected:
PScene scene;
+12 -44
View File
@@ -2,49 +2,17 @@
using namespace Seele;
RenderGraph::RenderGraph()
RenderGraphResources::RenderGraphResources()
{
}
RenderGraph::~RenderGraph()
{
}
void RenderGraph::setup()
RenderGraphResources::~RenderGraphResources()
{
for(auto& pass : renderPasses)
{
pass->publishOutputs();
}
for(auto& pass : renderPasses)
{
pass->createRenderPass();
}
}
void RenderGraph::addRenderPass(UPRenderPass renderPass)
{
renderPasses.add(std::move(renderPass));
}
void RenderGraph::render(PViewFrame viewFrame)
{
for(auto& pass : renderPasses)
{
pass->beginFrame(viewFrame);
}
for(auto& pass : renderPasses)
{
pass->render(viewFrame);
}
for(auto& pass : renderPasses)
{
pass->endFrame(viewFrame);
}
}
Gfx::PRenderTargetAttachment RenderGraph::requestRenderTarget(const std::string& outputName)
Gfx::PRenderTargetAttachment RenderGraphResources::requestRenderTarget(const std::string& outputName)
{
if(registeredAttachments.find(outputName) == registeredAttachments.end())
{
@@ -54,7 +22,7 @@ Gfx::PRenderTargetAttachment RenderGraph::requestRenderTarget(const std::string&
return registeredAttachments[outputName];
}
Gfx::PTexture RenderGraph::requestTexture(const std::string& outputName)
Gfx::PTexture RenderGraphResources::requestTexture(const std::string& outputName)
{
if(registeredTextures.find(outputName) == registeredTextures.end())
{
@@ -64,7 +32,7 @@ Gfx::PTexture RenderGraph::requestTexture(const std::string& outputName)
return registeredTextures[outputName];
}
Gfx::PStructuredBuffer RenderGraph::requestBuffer(const std::string& outputName)
Gfx::PStructuredBuffer RenderGraphResources::requestBuffer(const std::string& outputName)
{
if(registeredBuffers.find(outputName) == registeredBuffers.end())
{
@@ -74,7 +42,7 @@ Gfx::PStructuredBuffer RenderGraph::requestBuffer(const std::string& outputName)
return registeredBuffers[outputName];
}
Gfx::PUniformBuffer RenderGraph::requestUniform(const std::string& outputName)
Gfx::PUniformBuffer RenderGraphResources::requestUniform(const std::string& outputName)
{
if(registeredUniforms.find(outputName) == registeredUniforms.end())
{
@@ -84,21 +52,21 @@ Gfx::PUniformBuffer RenderGraph::requestUniform(const std::string& outputName)
return registeredUniforms[outputName];
}
void RenderGraph::registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment)
void RenderGraphResources::registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment)
{
registeredAttachments[outputName] = attachment;
}
void RenderGraph::registerTextureOutput(const std::string& outputName, Gfx::PTexture texture)
void RenderGraphResources::registerTextureOutput(const std::string& outputName, Gfx::PTexture texture)
{
registeredTextures[outputName] = texture;
}
void RenderGraph::registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer)
void RenderGraphResources::registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer)
{
registeredBuffers[outputName] = buffer;
}
void RenderGraph::registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer)
void RenderGraphResources::registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer)
{
registeredUniforms[outputName] = buffer;
}
+6 -9
View File
@@ -6,14 +6,12 @@
namespace Seele
{
DECLARE_REF(ViewFrame)
class RenderGraph
class RenderGraphResources
{
public:
RenderGraph();
~RenderGraph();
void setup();
void addRenderPass(UPRenderPass renderPass);
void render(PViewFrame viewFrame);
RenderGraphResources();
~RenderGraphResources();
Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName);
Gfx::PTexture requestTexture(const std::string& outputName);
Gfx::PStructuredBuffer requestBuffer(const std::string& outputName);
@@ -22,12 +20,11 @@ public:
void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer);
void registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer);
void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer);
private:
protected:
Map<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
Map<std::string, Gfx::PTexture> registeredTextures;
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers;
Map<std::string, Gfx::PUniformBuffer> registeredUniforms;
List<UPRenderPass> renderPasses;
};
DEFINE_REF(RenderGraph)
DEFINE_REF(RenderGraphResources)
} // namespace Seele
@@ -1,13 +0,0 @@
#include "RenderPass.h"
using namespace Seele;
RenderPass::RenderPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport)
: renderGraph(renderGraph), graphics(graphics), viewport(viewport)
{
}
RenderPass::~RenderPass()
{
}
+17 -6
View File
@@ -7,18 +7,26 @@ namespace Seele
DECLARE_NAME_REF(Gfx, Viewport)
DECLARE_NAME_REF(Gfx, Graphics)
DECLARE_NAME_REF(Gfx, RenderPass)
DECLARE_REF(RenderGraph)
DECLARE_REF(RenderGraphResources)
template<typename RenderPassDataType>
class RenderPass
{
public:
RenderPass(PRenderGraph rendergraph, Gfx::PGraphics graphics, Gfx::PViewport viewport);
virtual ~RenderPass();
virtual void updateViewFrame(PViewFrame viewFrame) = 0;
RenderPass(Gfx::PGraphics graphics, Gfx::PViewport viewport)
: graphics(graphics)
, viewport(viewport)
{}
virtual ~RenderPass()
{}
void updateViewFrame(RenderPassDataType viewFrame) {
passData = std::move(viewFrame);
}
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
virtual void publishOutputs() = 0;
virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources resources) { this->resources = resources; }
protected:
_declspec(align(16)) struct ViewParameter
{
@@ -28,10 +36,13 @@ protected:
Vector4 cameraPosition;
Vector2 screenDimensions;
} viewParams;
PRenderGraphResources resources;
RenderPassDataType passData;
Gfx::PRenderPass renderPass;
PRenderGraph renderGraph;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
};
DEFINE_REF(RenderPass)
template<typename T>
concept RenderPassType = true;
} // namespace Seele
+6 -6
View File
@@ -4,8 +4,8 @@
using namespace Seele;
UIPass::UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
: RenderPass(renderGraph, graphics, viewport)
UIPass::UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment)
: RenderPass(graphics, viewport)
, renderTarget(attachment)
{
}
@@ -15,12 +15,12 @@ UIPass::~UIPass()
}
void UIPass::beginFrame(UPViewFrame& viewFrame)
void UIPass::beginFrame()
{
}
void UIPass::render(UPViewFrame& viewFrame)
void UIPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
@@ -31,7 +31,7 @@ void UIPass::render(UPViewFrame& viewFrame)
graphics->endRenderPass();
}
void UIPass::endFrame(UPViewFrame& viewFrame)
void UIPass::endFrame()
{
}
@@ -51,7 +51,7 @@ void UIPass::publishOutputs()
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f;
renderGraph->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
}
void UIPass::createRenderPass()
+2 -3
View File
@@ -11,10 +11,10 @@ struct UIPassData
{
const UI::RenderHierarchy hierarchy;
};
class UIPass : public RenderPass
class UIPass : public RenderPass<UIPassData>
{
public:
UIPass(PRenderGraph renderGraph, Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget);
virtual ~UIPass();
virtual void beginFrame() override;
virtual void render() override;
@@ -22,7 +22,6 @@ public:
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
PUIViewFrame uiFrame;
Gfx::PRenderTargetAttachment renderTarget;
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer;
View File
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "View.h"
namespace Seele
{
// A frame is the mutable data needed to
// process a time step for the game updates
// It contains all the game update relevant data
// and is handed over to the renderer for read only processing
// If the game loop runs faster than the renderer, the renderer
// simply discards old Frames and starts working on the more recent ones
// if the game loop runs slower than the renderer (bad), the renderer has to wait
struct Frame
{
uint64 frameNumber;
Array<PViewFrame> viewFrame;
};
} // namespace Seele
+13 -5
View File
@@ -5,11 +5,8 @@ using namespace Seele;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo)
, renderGraph(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle())))
{
renderGraph = new RenderGraph();
Gfx::PRenderTargetAttachment attachment = new Gfx::SwapchainAttachment(window->getGfxHandle());
renderGraph->addRenderPass(new UIPass(renderGraph, graphics, viewport, attachment));
renderGraph->setup();
}
InspectorView::~InspectorView()
@@ -20,12 +17,23 @@ void InspectorView::beginFrame()
{
}
void InspectorView::render()
void InspectorView::update()
{
}
void InspectorView::endFrame()
{
}
void InspectorView::prepareRender()
{
}
void InspectorView::render()
{
}
void InspectorView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
+11 -11
View File
@@ -7,24 +7,24 @@
namespace Seele
{
DECLARE_REF(Actor)
class InspectorViewFrame : public ViewFrame
{
public:
protected:
const UI::RenderHierarchy hierarchy;
};
class InspectorView : public View
{
public:
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~InspectorView();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
void selectActor();
virtual void beginFrame() override;
virtual void update() override;
virtual void endFrame() override;
virtual void prepareRender() override;
virtual void render() override;
void selectActor();
protected:
UIPass renderGraph;
UIPassData uiPassData;
UI::PPanel rootPanel;
PActor selectedActor;
+29 -9
View File
@@ -3,23 +3,18 @@
#include "Window.h"
#include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
using namespace Seele;
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
: View(graphics, owner, createInfo)
, activeCamera(new CameraActor())
, depthPrepass(DepthPrepass(graphics, viewport, activeCamera))
, lightCullingPass(LightCullingPass(graphics, viewport, activeCamera))
, basePass(BasePass(graphics, viewport, activeCamera))
{
scene = new Scene(graphics);
activeCamera = new CameraActor();
scene->addActor(activeCamera);
renderGraph = new RenderGraph();
renderGraph->addRenderPass(new DepthPrepass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->addRenderPass(new LightCullingPass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->addRenderPass(new BasePass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->setup();
}
Seele::SceneView::~SceneView()
@@ -32,6 +27,31 @@ void SceneView::beginFrame()
scene->tick(Gfx::currentFrameDelta);
}
void SceneView::update()
{
}
void SceneView::endFrame()
{
depthPrepassData.staticDrawList = scene->getStaticMeshes();
lightCullingPassData.lightEnv = scene->getLightBuffer();
basePassData.staticDrawList = scene->getStaticMeshes();
}
void SceneView::prepareRender()
{
depthPrepass.updateViewFrame(depthPrepassData);
lightCullingPass.updateViewFrame(lightCullingPassData);
basePass.updateViewFrame(basePassData);
}
void SceneView::render()
{
depthPrepass.render();
lightCullingPass.render();
basePass.render();
}
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
{
if(action != InputAction::RELEASE)
+17 -8
View File
@@ -1,28 +1,37 @@
#pragma once
#include "View.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
namespace Seele
{
DECLARE_REF(Scene)
DECLARE_REF(CameraActor)
class SceneViewFrame : public ViewFrame
{
public:
protected:
const PScene scene;
};
DEFINE_REF(SceneViewFrame)
class SceneView : public View
{
public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView();
virtual void beginFrame() override;
virtual void update() override;
virtual void endFrame() override;
virtual void prepareRender() override;
virtual void render() override;
PScene getScene() const { return scene; }
private:
PScene scene;
PCameraActor activeCamera;
DepthPrepass depthPrepass;
LightCullingPass lightCullingPass;
BasePass basePass;
DepthPrepassData depthPrepassData;
LightCullingPassData lightCullingData;
BasePassData basePassData;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
+5 -16
View File
@@ -2,30 +2,19 @@
#include "Window.h"
#include "Graphics/Graphics.h"
Seele::View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
using namespace Seele;
View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
: graphics(graphics), owner(window)
{
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
}
Seele::View::~View()
View::~View()
{
}
void Seele::View::beginFrame()
{
}
void Seele::View::render()
{
}
void Seele::View::endFrame()
{
}
void Seele::View::applyArea(URect area)
void View::applyArea(URect area)
{
}
+12 -14
View File
@@ -5,33 +5,31 @@ namespace Seele
{
DECLARE_REF(Window)
// A ViewFrame is the render relevant data of a View
class ViewFrame
{
public:
protected:
};
DEFINE_REF(ViewFrame)
// A view is a part of the window, which can be anything from a scene viewport to an inspector
class View
{
public:
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~View();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
// These are called from the view thread, and handle updating game data
virtual void beginFrame() {}
virtual void update() {}
// End frame is called with a lock, so it is safe to write to shared memory
virtual void endFrame() {}
// These are called from the render thread
// prepare render is also locked, so reading from shared memory is also safe
virtual void prepareRender() {}
virtual void render() {}
void applyArea(URect area);
void setFocused();
protected:
UPViewFrame currentFrame;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
PWindow owner;
PRenderGraph renderGraph;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) = 0;
+4 -10
View File
@@ -16,7 +16,6 @@ void Window::addView(PView view)
{
WindowView* windowView = new WindowView();
windowView->view = view;
windowView->renderGraph = view->renderGraph;
windowView->worker = std::thread(&Window::viewWorker, this, windowView);
views.add(windowView);
}
@@ -26,15 +25,11 @@ void Window::render()
gfxHandle->beginFrame();
for(auto& windowView : views)
{
UPViewFrame frame;
{
std::lock_guard lock(windowView->workerMutex);
frame = std::move(windowView->currentFrame);
}
if(frame != nullptr)
{
windowView->renderGraph->render(std::move(frame));
windowView->view->prepareRender();
}
windowView->view->render();
}
gfxHandle->endFrame();
}
@@ -64,9 +59,8 @@ void Window::viewWorker(WindowView* windowView)
while(true)
{
windowView->view->beginFrame();
windowView->view->render();
windowView->view->endFrame();
windowView->view->update();
std::lock_guard lock(windowView->workerMutex);
windowView->currentFrame = std::move(windowView->view->currentFrame);
windowView->view->endFrame();
}
}
-2
View File
@@ -7,8 +7,6 @@ namespace Seele
struct WindowView
{
PView view;
PRenderGraph renderGraph;
UPViewFrame currentFrame;
std::thread worker;
std::mutex workerMutex;
};