Refactoring graphics

This commit is contained in:
Dynamitos
2023-10-26 18:37:29 +02:00
parent 28e5c9ff01
commit 1ca861459c
113 changed files with 3131 additions and 3221 deletions
+1 -8
View File
@@ -7,6 +7,7 @@
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Material/MaterialInstance.h"
#include "Graphics/Descriptor.h"
using namespace Seele;
@@ -59,14 +60,6 @@ BasePass::~BasePass()
{
}
void BasePass::readScene()
{
Array<InstanceData> instances;
scene->view<Component::Transform, Component::Mesh>([]
(const Component::Transform& transform, const Component::Mesh& mesh) {
});
}
void BasePass::beginFrame(const Component::Camera& cam)
{
BulkResourceData uniformUpdate;
@@ -10,7 +10,6 @@ class BasePass : public RenderPass
public:
BasePass(Gfx::PGraphics graphics, PScene scene);
virtual ~BasePass();
virtual void readScene() override;
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
virtual void endFrame() override;
@@ -1,5 +1,6 @@
#include "DebugPass.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
using namespace Seele;
@@ -1,6 +1,5 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
#include "Scene/Scene.h"
#include "Graphics/DebugVertex.h"
@@ -68,7 +68,7 @@ void DepthPrepass::render()
// ViewData => global, static
// Material => per material
// VertexData => per meshtype
// SceneData => per topology
// SceneData => per material instance
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
Gfx::PPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
@@ -7,8 +7,8 @@
using namespace Seele;
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
@@ -153,7 +153,7 @@ void LightCullingPass::publishOutputs()
createInfo.defines["NUM_MATERIAL_TEXCOORDS"] = "0";
cullingShader = graphics->createComputeShader(createInfo);
ComputePipelineCreateInfo pipelineInfo;
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = cullingLayout;
cullingPipeline = graphics->createComputePipeline(pipelineInfo);
@@ -243,7 +243,7 @@ void LightCullingPass::setupFrustums()
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
frustumShader = graphics->createComputeShader(createInfo);
ComputePipelineCreateInfo pipelineInfo;
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = frustumShader;
pipelineInfo.pipelineLayout = frustumLayout;
frustumPipeline = graphics->createComputePipeline(pipelineInfo);
@@ -1,6 +1,6 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Resources.h"
#include "Scene/Scene.h"
namespace Seele
@@ -8,14 +8,10 @@ namespace Seele
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
struct LightCullingPassData
{
LightEnv lightEnv;
};
class LightCullingPass : public RenderPass
{
public:
LightCullingPass(Gfx::PGraphics graphics);
LightCullingPass(Gfx::PGraphics graphics, PScene scene);
virtual ~LightCullingPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -1,6 +1,8 @@
#pragma once
#include "MinimalEngine.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Texture.h"
#include "Graphics/Buffer.h"
namespace Seele
{
@@ -3,7 +3,6 @@
#include "Math/Math.h"
#include "RenderGraphResources.h"
#include "Component/Camera.h"
#include "Graphics/TopologyData.h"
#include "Scene/Scene.h"
#include "Material/MaterialInstance.h"
#include "Graphics/VertexData.h"
@@ -42,19 +41,6 @@ protected:
Vector2 screenDimensions;
Vector2 pad0;
} viewParams;
struct DrawListId
{
DrawListId(PMaterialInstance mat, PVertexData vertex)
{
id = mat->getBaseMaterial()->getName();
}
std::strong_ordering operator<=>(const DrawListId& other) const
{
return id <=> other.id;
}
std::string id;
};
Map<DrawListId, DrawListInfo> drawList;
PRenderGraphResources resources;
Gfx::PRenderPass renderPass;
Gfx::PGraphics graphics;
@@ -1,11 +1,18 @@
#include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h"
#include "Asset/AssetRegistry.h"
using namespace Seele;
SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
skybox = Seele::Component::Skybox{
.day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(),
.night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(),
.fogColor = Vector(0.2, 0.1, 0.6),
.blendFactor = 0,
};
Array<Vector> vertices = {
// Back
Vector(-512, -512, 512),
@@ -91,8 +98,8 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, viewParamsBuffer);
descriptorSet->updateTexture(1, passData.skybox.day);
descriptorSet->updateTexture(2, passData.skybox.night);
descriptorSet->updateTexture(1, skybox.day);
descriptorSet->updateTexture(2, skybox.night);
descriptorSet->updateSampler(3, skyboxSampler);
descriptorSet->writeChanges();
}
@@ -104,9 +111,9 @@ void SkyboxRenderPass::render()
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(descriptorSet);
renderCommand->bindVertexBuffer({ VertexInputStream(0, 0, cubeBuffer) });
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(Vector), &passData.skybox.fogColor);
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, sizeof(Vector), sizeof(float), &passData.skybox.blendFactor);
renderCommand->bindVertexBuffer({ cubeBuffer });
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(Vector), &skybox.fogColor);
renderCommand->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, sizeof(Vector), sizeof(float), &skybox.blendFactor);
renderCommand->draw(36, 1, 0, 0);
graphics->executeCommands(Array{ renderCommand });
graphics->endRenderPass();
@@ -170,15 +177,15 @@ void SkyboxRenderPass::createRenderPass()
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
Gfx::VertexElement {
.streamIndex = 0,
.binding = 0,
.offset = 0,
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(Vector),
}
});
});
GraphicsPipelineCreateInfo gfxInfo;
Gfx::LegacyPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = vertexDecl;
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
@@ -1,6 +1,6 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Resources.h"
#include "Component/Skybox.h"
namespace Seele
@@ -11,7 +11,7 @@ DECLARE_REF(Viewport)
class SkyboxRenderPass : public RenderPass
{
public:
SkyboxRenderPass(Gfx::PGraphics graphics);
SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene);
virtual ~SkyboxRenderPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -26,6 +26,7 @@ private:
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::PSamplerState skyboxSampler;
Component::Skybox skybox;
};
DEFINE_REF(SkyboxRenderPass)
} // namespace Seele
+9 -9
View File
@@ -1,12 +1,12 @@
#include "TextPass.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/VertexShaderInput.h"
#include "Graphics/RenderTarget.h"
using namespace Seele;
TextPass::TextPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
@@ -17,7 +17,7 @@ TextPass::~TextPass()
void TextPass::beginFrame(const Component::Camera&)
{
for(TextRender& render : passData.texts)
for(TextRender& render : texts)
{
FontData& fd = getFontData(render.font);
TextResources& res = textResources[render.font].add();
@@ -82,7 +82,7 @@ void TextPass::render()
for(const auto& resource : res)
{
command->bindDescriptor({generalSet, resource.textureArraySet});
command->bindVertexBuffer({VertexInputStream(0, 0, resource.vertexBuffer)});
command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
@@ -121,7 +121,7 @@ void TextPass::createRenderPass()
fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> elements;
elements.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(GlyphInstanceData, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 0,
@@ -129,7 +129,7 @@ void TextPass::createRenderPass()
.bInstanced = 1
});
elements.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(GlyphInstanceData, widthHeight),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 1,
@@ -137,7 +137,7 @@ void TextPass::createRenderPass()
.bInstanced = 1
});
elements.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(GlyphInstanceData, glyphIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 2,
@@ -187,7 +187,7 @@ void TextPass::createRenderPass()
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
GraphicsPipelineCreateInfo pipelineInfo;
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
+4 -3
View File
@@ -1,7 +1,7 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Resources.h"
#include "Asset/FontAsset.h"
namespace Seele
@@ -20,7 +20,7 @@ struct TextRender
class TextPass : public RenderPass
{
public:
TextPass(Gfx::PGraphics graphics);
TextPass(Gfx::PGraphics graphics, PScene scene);
virtual ~TextPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -60,7 +60,7 @@ private:
Gfx::PDescriptorSet textureArraySet;
TextData textData;
};
std::map<PFontAsset, Array<TextResources>> textResources;
Map<PFontAsset, Array<TextResources>> textResources;
Gfx::PRenderTargetAttachment renderTarget;
Gfx::PRenderTargetAttachment depthAttachment;
@@ -78,6 +78,7 @@ private:
Gfx::PFragmentShader fragmentShader;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Array<TextRender> texts;
};
DEFINE_REF(TextPass);
} // namespace Seele
+17 -15
View File
@@ -1,11 +1,12 @@
#include "UIPass.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
using namespace Seele;
UIPass::UIPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
UIPass::UIPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
@@ -18,20 +19,20 @@ void UIPass::beginFrame(const Component::Camera&)
{
VertexBufferCreateInfo info = {
.resourceData = {
.size = (uint32)(sizeof(UI::RenderElementStyle) * passData.renderElements.size()),
.data = (uint8*)passData.renderElements.data()
.size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()),
.data = (uint8*)renderElements.data()
},
.vertexSize = sizeof(UI::RenderElementStyle),
.numVertices = (uint32)passData.renderElements.size(),
.numVertices = (uint32)renderElements.size(),
};
elementBuffer = graphics->createVertexBuffer(info);
uint32 numTextures = static_cast<uint32>(passData.usedTextures.size());
uint32 numTextures = static_cast<uint32>(usedTextures.size());
numTexturesBuffer->updateContents({
.size = sizeof(uint32),
.data = (uint8*)&numTextures,
});
descriptorSet->updateBuffer(2, numTexturesBuffer);
descriptorSet->updateTextureArray(3, passData.usedTextures);
descriptorSet->updateTextureArray(3, usedTextures);
descriptorSet->writeChanges();
//co_return;
}
@@ -42,11 +43,12 @@ void UIPass::render()
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
command->setViewport(viewport);
command->bindPipeline(pipeline);
command->bindVertexBuffer({VertexInputStream(0, 0, elementBuffer)});
command->bindVertexBuffer({elementBuffer});
command->bindDescriptor(descriptorSet);
command->draw(4, static_cast<uint32>(passData.renderElements.size()), 0, 0);
command->draw(4, static_cast<uint32>(renderElements.size()), 0, 0);
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
graphics->endRenderPass();
//co_return;
}
@@ -96,7 +98,7 @@ void UIPass::createRenderPass()
fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> decl;
decl.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
@@ -104,7 +106,7 @@ void UIPass::createRenderPass()
.bInstanced = 1
});
decl.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundImageIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 1,
@@ -112,7 +114,7 @@ void UIPass::createRenderPass()
.bInstanced = 1
});
decl.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundColor),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 2,
@@ -120,7 +122,7 @@ void UIPass::createRenderPass()
.bInstanced = 1
});
decl.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, opacity),
.vertexFormat = Gfx::SE_FORMAT_R32_SFLOAT,
.attributeIndex = 3,
@@ -128,7 +130,7 @@ void UIPass::createRenderPass()
.bInstanced = 1
});
decl.add({
.streamIndex = 0,
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, dimensions),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 4,
@@ -177,7 +179,7 @@ void UIPass::createRenderPass()
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
GraphicsPipelineCreateInfo pipelineInfo;
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
+6 -8
View File
@@ -1,21 +1,16 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/GraphicsResources.h"
#include "Graphics/Resources.h"
namespace Seele
{
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
struct UIPassData
{
Array<UI::RenderElementStyle> renderElements;
Array<Gfx::PTexture> usedTextures;
};
class UIPass : public RenderPass<UIPassData>
class UIPass : public RenderPass
{
public:
UIPass(Gfx::PGraphics graphics);
UIPass(Gfx::PGraphics graphics, PScene scene);
virtual ~UIPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -39,6 +34,9 @@ private:
Gfx::PFragmentShader fragmentShader;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Array<UI::RenderElementStyle> renderElements;
Array<Gfx::PTexture> usedTextures;
};
DEFINE_REF(UIPass);
} // namespace Seele