More Refactoring

This commit is contained in:
Dynamitos
2023-11-15 17:42:57 +01:00
parent f8f48352a3
commit 35966cb5b7
60 changed files with 1217 additions and 2332 deletions
+1 -1
View File
@@ -11,6 +11,7 @@
#include "RenderGraph.h"
#include "Material/MaterialInstance.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -128,7 +129,6 @@ void BasePass::render()
else
{
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
@@ -8,6 +8,7 @@
#include "Actor/CameraActor.h"
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -89,7 +90,6 @@ void DepthPrepass::render()
else
{
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = collection->vertexDeclaration;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
@@ -141,13 +141,14 @@ void DepthPrepass::endFrame()
void DepthPrepass::publishOutputs()
{
TextureCreateInfo depthBufferInfo;
// If we render to a part of an image, the depth buffer itself must
// still match the size of the whole image or their coordinate systems go out of sync
depthBufferInfo.width = viewport->getOwner()->getWidth();
depthBufferInfo.height = viewport->getOwner()->getHeight();
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getWidth(),
.height = viewport->getOwner()->getHeight(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
@@ -4,6 +4,7 @@
#include "Actor/CameraActor.h"
#include "Component/Camera.h"
#include "RenderGraph.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -130,14 +131,13 @@ void LightCullingPass::publishOutputs()
cullingPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
uint32 counterReset = 0;
ShaderBufferCreateInfo structInfo =
{
ShaderBufferCreateInfo structInfo = {
.sourceData = {
.size = sizeof(uint32),
.data = (uint8*)&counterReset,
.owner = Gfx::QueueType::COMPUTE,
},
.stride = sizeof(uint32),
.numElements = 1,
.dynamic = true,
};
oLightIndexCounter = graphics->createShaderBuffer(structInfo);
@@ -151,7 +151,6 @@ void LightCullingPass::publishOutputs()
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE
},
.stride = sizeof(uint32),
.dynamic = false,
};
oLightIndexList = graphics->createShaderBuffer(structInfo);
@@ -160,9 +159,9 @@ void LightCullingPass::publishOutputs()
resources->registerBufferOutput("LIGHTCULLING_TLIGHTLIST", tLightIndexList);
TextureCreateInfo textureInfo = {
.format = Gfx::SE_FORMAT_R32G32_UINT,
.width = dispatchParams.numThreadGroups.x,
.height = dispatchParams.numThreadGroups.y,
.format = Gfx::SE_FORMAT_R32G32_UINT,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
};
oLightGrid = graphics->createTexture2D(textureInfo);
@@ -226,7 +225,7 @@ void LightCullingPass::setupFrustums()
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr,
},
.stride = sizeof(Frustum),
.numElements = numThreads.x * numThreads.y * numThreads.z,
.dynamic = false,
});
@@ -1,6 +1,6 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/Resources.h"
#include "Graphics/Shader.h"
#include "Scene/Scene.h"
namespace Seele
@@ -1,6 +1,7 @@
#include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h"
#include "Asset/AssetRegistry.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -13,71 +14,6 @@ SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
.fogColor = Vector(0.2, 0.1, 0.6),
.blendFactor = 0,
};
Array<Vector> vertices = {
// Back
Vector(-512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, -512, 512),
Vector( 512, -512, 512),
Vector(-512, 512, 512),
Vector( 512, 512, 512),
// Front
Vector( 512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, -512, -512),
Vector(-512, -512, -512),
Vector( 512, 512, -512),
Vector(-512, 512, -512),
// Top
Vector(-512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, -512),
Vector( 512, -512, -512),
Vector(-512, -512, 512),
Vector( 512, -512, 512),
// Bottom
Vector(-512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, 512),
Vector( 512, 512, 512),
Vector(-512, 512, -512),
Vector( 512, 512, -512),
// Left
Vector(-512, -512, -512),
Vector(-512, 512, -512),
Vector(-512, -512, 512),
Vector(-512, -512, 512),
Vector(-512, 512, -512),
Vector(-512, 512, 512),
// Right
Vector( 512, -512, 512),
Vector( 512, 512, 512),
Vector( 512, -512, -512),
Vector( 512, -512, -512),
Vector( 512, 512, 512),
Vector( 512, 512, -512),
};
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData = {
.size = sizeof(Vector) * vertices.size(),
.data = (uint8*)vertices.data(),
},
.vertexSize = sizeof(Vector),
.numVertices = (uint32)vertices.size(),
};
cubeBuffer = graphics->createVertexBuffer(vertexBufferInfo);
}
SkyboxRenderPass::~SkyboxRenderPass()
{
@@ -146,7 +82,7 @@ void SkyboxRenderPass::publishOutputs()
textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
textureLayout->create();
skyboxSampler = graphics->createSamplerState({});
skyboxSampler = graphics->createSampler({});
}
void SkyboxRenderPass::createRenderPass()
@@ -169,16 +105,6 @@ void SkyboxRenderPass::createRenderPass()
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
declaration = graphics->createVertexDeclaration({
Gfx::VertexElement {
.binding = 0,
.offset = 0,
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(Vector),
}
});
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
pipelineLayout->addDescriptorLayout(1, skyboxDataLayout);
@@ -186,7 +112,6 @@ void SkyboxRenderPass::createRenderPass()
pipelineLayout->create();
Gfx::LegacyPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = declaration;
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
@@ -1,13 +1,10 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/Resources.h"
#include "Graphics/Shader.h"
#include "Component/Skybox.h"
namespace Seele
{
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
class SkyboxRenderPass : public RenderPass
{
public:
@@ -27,11 +24,10 @@ private:
Gfx::PDescriptorSet skyboxDataSet;
Gfx::ODescriptorLayout textureLayout;
Gfx::PDescriptorSet textureSet;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline;
Gfx::OSamplerState skyboxSampler;
Gfx::OSampler skyboxSampler;
Component::Skybox skybox;
};
DEFINE_REF(SkyboxRenderPass)
+8 -37
View File
@@ -2,6 +2,7 @@
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -43,15 +44,13 @@ void TextPass::beginFrame(const Component::Camera& cam)
});
x += (glyph.advance >> 6) * render.scale;
}
VertexBufferCreateInfo vbInfo = {
res.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()),
},
.vertexSize = sizeof(GlyphInstanceData),
.numVertices = static_cast<uint32>(instanceData.size()),
};
res.vertexBuffer = graphics->createVertexBuffer(vbInfo);
},
.numElements = instanceData.size(),
});
res.textureArraySet = fd.textureArraySet;
@@ -83,10 +82,10 @@ void TextPass::render()
for(const auto& resource : res)
{
command->bindDescriptor({generalSet, resource.textureArraySet});
command->bindVertexBuffer({resource.vertexBuffer});
//command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(layoutRef, 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);
//command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
}
commands.add(command);
}
@@ -120,33 +119,6 @@ void TextPass::createRenderPass()
createInfo.name = "TextFragment";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> elements;
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, widthHeight),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 1,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
elements.add({
.binding = 0,
.offset = offsetof(GlyphInstanceData, glyphIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 2,
.stride = sizeof(GlyphInstanceData),
.instanced = 1
});
declaration = graphics->createVertexDeclaration(elements);
generalLayout = graphics->createDescriptorLayout("TextGeneral");
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
@@ -164,7 +136,7 @@ void TextPass::createRenderPass()
.dynamic = true,
});
glyphSampler = graphics->createSamplerState({
glyphSampler = graphics->createSampler({
.magFilter = Gfx::SE_FILTER_LINEAR,
.minFilter = Gfx::SE_FILTER_LINEAR,
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
@@ -190,7 +162,6 @@ void TextPass::createRenderPass()
renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass;
+3 -4
View File
@@ -1,8 +1,8 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/Resources.h"
#include "Asset/FontAsset.h"
#include "Graphics/Shader.h"
namespace Seele
{
@@ -58,7 +58,7 @@ private:
struct TextResources
{
Gfx::PVertexBuffer vertexBuffer;
Gfx::PShaderBuffer instanceBuffer;
Gfx::PDescriptorSet textureArraySet;
TextData textData;
};
@@ -73,9 +73,8 @@ private:
Gfx::PDescriptorSet generalSet;
Gfx::OUniformBuffer projectionBuffer;
Gfx::OSamplerState glyphSampler;
Gfx::OSampler glyphSampler;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PPipelineLayout layoutRef;
+4 -46
View File
@@ -2,6 +2,7 @@
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
using namespace Seele;
@@ -61,9 +62,9 @@ void UIPass::endFrame()
void UIPass::publishOutputs()
{
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getWidth(),
.height = viewport->getHeight(),
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
@@ -74,9 +75,9 @@ void UIPass::publishOutputs()
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
TextureCreateInfo colorBufferInfo = {
.format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT,
.width = viewport->getWidth(),
.height = viewport->getHeight(),
.format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT,
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
};
colorBuffer = graphics->createTexture2D(colorBufferInfo);
@@ -97,48 +98,6 @@ void UIPass::createRenderPass()
createInfo.name = "UIFragment";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
Array<Gfx::VertexElement> decl;
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundImageIndex),
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 1,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, backgroundColor),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 2,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, opacity),
.vertexFormat = Gfx::SE_FORMAT_R32_SFLOAT,
.attributeIndex = 3,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
decl.add({
.binding = 0,
.offset = offsetof(UI::RenderElementStyle, dimensions),
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 4,
.stride = sizeof(UI::RenderElementStyle),
.instanced = 1
});
declaration = graphics->createVertexDeclaration(decl);
descriptorLayout = graphics->createDescriptorLayout("UIDescriptorLayout");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -156,7 +115,7 @@ void UIPass::createRenderPass()
.dynamic = false,
};
Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::OSamplerState backgroundSampler = graphics->createSamplerState({});
Gfx::OSampler backgroundSampler = graphics->createSampler({});
info = {
.sourceData = {
@@ -181,7 +140,6 @@ void UIPass::createRenderPass()
renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass;
+1 -2
View File
@@ -1,7 +1,7 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/Resources.h"
#include "Graphics/Shader.h"
namespace Seele
{
@@ -31,7 +31,6 @@ private:
Gfx::OUniformBuffer numTexturesBuffer;
Gfx::OVertexBuffer elementBuffer;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline;