compiles again

This commit is contained in:
Dynamitos
2023-11-05 10:36:01 +01:00
parent 4746c0f838
commit 77eb92838c
112 changed files with 1717 additions and 1540 deletions
+93 -82
View File
@@ -1,5 +1,6 @@
#include "BasePass.h"
#include "Graphics/Graphics.h"
#include "Graphics/Shader.h"
#include "Window/Window.h"
#include "Component/Camera.h"
#include "Component/Mesh.h"
@@ -13,47 +14,25 @@ using namespace Seele;
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
, descriptorSets(4)
, descriptorSets(6)
{
UniformBufferCreateInfo uniformInitializer;
basePassLayout = graphics->createPipelineLayout();
lightLayout = graphics->createDescriptorLayout("LightLayout");
// Directional Lights
lightLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
lightLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
// Point Lights
lightLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
lightLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
// Light Index List
lightLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
// Light Grid
lightLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
lightLayout->create();
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, lightLayout);
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
viewLayout = graphics->createDescriptorLayout("ViewLayout");
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformInitializer.sourceData.size = sizeof(ViewParameter);
uniformInitializer.sourceData.data = (uint8*)&viewParams;
uniformInitializer.bDynamic = true;
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
viewLayout->create();
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
// oLightIndexList
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
// tLightIndexList
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
// oLightGrid
lightCullingLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
// tLightGrid
lightCullingLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
lightCullingLayout->create();
sceneLayout = graphics->createDescriptorLayout("SceneLayout");
sceneLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
sceneLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
sceneLayout->create();
basePassLayout->addDescriptorLayout(INDEX_SCENE_DATA, sceneLayout);
//basePassLayout->addPushConstants(Gfx::SePushConstantRange{
// .stageFlags = (Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT),
// .offset = 0,
// .size = sizeof(uint32),
//});
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
}
BasePass::~BasePass()
@@ -62,61 +41,95 @@ BasePass::~BasePass()
void BasePass::beginFrame(const Component::Camera& cam)
{
DataSource uniformUpdate;
RenderPass::beginFrame(cam);
viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = viewport->getProjectionMatrix();
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams;
viewParamBuffer->updateContents(uniformUpdate);
viewLayout->reset();
lightLayout->reset();
descriptorSets[INDEX_SCENE_DATA] = sceneLayout->allocateDescriptorSet();
descriptorSets[INDEX_SCENE_DATA]->updateBuffer(0, passData.sceneDataBuffer);
descriptorSets[INDEX_SCENE_DATA]->writeChanges();
descriptorSets[INDEX_LIGHT_ENV] = lightLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "BasePass beginFrame()" << std::endl;
//co_return;
lightCullingLayout->reset();
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
descriptorSets[INDEX_LIGHT_CULLING] = lightCullingLayout->allocateDescriptorSet();
}
void BasePass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
oLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
tLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
oLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
tLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(0, passData.lightEnv.directionalLights);
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(1, passData.lightEnv.numDirectional);
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(2, passData.lightEnv.pointLights);
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(3, passData.lightEnv.numPoints);
descriptorSets[INDEX_LIGHT_ENV]->updateBuffer(4, oLightIndexList);
descriptorSets[INDEX_LIGHT_ENV]->updateTexture(5, oLightGrid);
descriptorSets[INDEX_LIGHT_ENV]->writeChanges();
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(0, oLightIndexList);
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(1, tLightIndexList);
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(2, oLightGrid);
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(3, tLightGrid);
descriptorSets[INDEX_LIGHT_CULLING]->writeChanges();
graphics->beginRenderPass(renderPass);
for (const auto& meshBatch : passData.staticDrawList)
Gfx::ShaderPermutation permutation;
permutation.hasFragment = true;
permutation.useMeshShading = true;
permutation.hasTaskShader = true;
std::memcpy(permutation.taskFile, "MeshletBasePass", std::strlen("MeshletBasePass"));
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", std::strlen("MeshletBasePass"));
std::memcpy(permutation.fragmentFile, "BasePass", std::strlen("BasePass"));
for (VertexData* vertexData : VertexData::getList())
{
processor->processMeshBatch(meshBatch, viewport, renderPass, basePassLayout, primitiveLayout, descriptorSets);
std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str()));
const auto& materials = vertexData->getMaterialData();
for (const auto& [_, materialData] : materials)
{
// Create Pipeline(Material, VertexData)
// Descriptors:
// ViewData => global, static
// LightEnv => global, static
// LightCulling => global, static
// Material => per material
// VertexData => per meshtype
// SceneData => per material instance
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str()));
Gfx::PermutationId id(permutation);
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout);
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
layout->create();
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
Gfx::MeshPipelineCreateInfo pipelineInfo;
pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = layout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo);
command->bindPipeline(pipeline);
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
for (const auto& [_, instance] : materialData.instances)
{
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
command->bindDescriptor(descriptorSets);
command->dispatch(instance.numMeshes, 1, 1);
}
}
}
graphics->executeCommands(processor->getRenderCommands());
graphics->endRenderPass();
//std::cout << "BasePass render()" << std::endl;
//co_return;
}
void BasePass::endFrame()
{
//std::cout << "BasePass endFrame()" << std::endl;
//co_return;
}
void BasePass::publishOutputs()
@@ -131,16 +144,14 @@ void BasePass::createRenderPass()
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR;
colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(std::move(layout), viewport);
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST");
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
}
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
{
defines["INDEX_LIGHT_ENV"] = "0";
defines["INDEX_VIEW_PARAMS"] = "1";
defines["INDEX_MATERIAL"] = "2";
defines["INDEX_SCENE_DATA"] = "3";
}
+18 -14
View File
@@ -9,6 +9,8 @@ class BasePass : public RenderPass
{
public:
BasePass(Gfx::PGraphics graphics, PScene scene);
BasePass(BasePass&&) = default;
BasePass& operator=(BasePass&&) = default;
virtual ~BasePass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -19,24 +21,26 @@ public:
private:
Gfx::PRenderTargetAttachment colorAttachment;
Gfx::PTexture2D depthBuffer;
Gfx::PShaderBuffer oLightIndexList;
Gfx::PShaderBuffer tLightIndexList;
Gfx::PTexture2D oLightGrid;
Gfx::PTexture2D tLightGrid;
Array<Gfx::PDescriptorSet> descriptorSets;
PCameraActor source;
Gfx::OPipelineLayout basePassLayout;
// Set 0: Light environment
static constexpr uint32 INDEX_LIGHT_ENV = 0;
Gfx::OShaderBuffer oLightIndexList;
Gfx::OTexture oLightGrid;
Gfx::ODescriptorLayout lightLayout;
// Set 1: viewParameter
static constexpr uint32 INDEX_VIEW_PARAMS = 1;
Gfx::ODescriptorLayout viewLayout;
Gfx::OUniformBuffer viewParamBuffer;
// Set 2: materials, generated
static constexpr uint32 INDEX_MATERIAL = 2;
// Set 3: primitive scene data
static constexpr uint32 INDEX_SCENE_DATA = 3;
Gfx::ODescriptorLayout sceneLayout;
// Set 0: viewParameter, provided by renderpass
// Set 1: light environment, provided by lightenv
static constexpr uint32 INDEX_LIGHT_ENV = 1;
// Set 2: light culling data
static constexpr uint32 INDEX_LIGHT_CULLING = 2;
Gfx::ODescriptorLayout lightCullingLayout;
// Set 3: material data, generated from material
static constexpr uint32 INDEX_MATERIAL = 3;
// Set 4: vertex buffers, provided by vertexdata
static constexpr uint32 INDEX_VERTEX_DATA = 4;
// Set 5: instance data, provided by vertexdata
static constexpr uint32 INDEX_SCENE_DATA = 5;
};
DEFINE_REF(BasePass)
} // namespace Seele
@@ -12,6 +12,7 @@ target_sources(Engine
RenderGraphResources.h
RenderGraphResources.cpp
RenderPass.h
RenderPass.cpp
SkyboxRenderPass.h
SkyboxRenderPass.cpp
TextPass.h
+126 -125
View File
@@ -16,128 +16,129 @@ void Seele::addDebugVertices(Array<DebugVertex> verts)
gDebugVertices.addAll(verts);
}
DebugPass::DebugPass(Gfx::PGraphics graphics)
: RenderPass(graphics)
{
}
DebugPass::~DebugPass()
{
}
void DebugPass::beginFrame(const Component::Camera& cam)
{
DataSource uniformUpdate;
viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = viewport->getProjectionMatrix();
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams;
viewParamsBuffer->updateContents(uniformUpdate);
descriptorLayout->reset();
descriptorSet = descriptorLayout->allocateDescriptorSet();
descriptorSet->updateBuffer(0, viewParamsBuffer);
descriptorSet->writeChanges();
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData = {
.size = sizeof(DebugVertex) * passData.vertices.size(),
.data = (uint8*)passData.vertices.data(),
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)passData.vertices.size(),
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
}
void DebugPass::render()
{
graphics->beginRenderPass(renderPass);
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(descriptorSet);
renderCommand->bindVertexBuffer({VertexInputStream(0, 0, debugVertices)});
renderCommand->draw((uint32)passData.vertices.size(), 1, 0, 0);
graphics->executeCommands(Array{renderCommand});
graphics->endRenderPass();
}
void DebugPass::endFrame()
{
}
void DebugPass::publishOutputs()
{
UniformBufferCreateInfo viewCreateInfo = {
.sourceData = DataSource {
.size = sizeof(ViewParameter),
.data = nullptr,
},
.bDynamic = true
};
viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
descriptorLayout->create();
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->create();
}
void DebugPass::createRenderPass()
{
Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
ShaderCreateInfo createInfo;
createInfo.name = "DebugVertex";
createInfo.mainModule = "Debug";
createInfo.entryPoint = "vertexMain";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "DebugFragment";
createInfo.entryPoint = "fragmentMain";
Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
Gfx::VertexElement {
.streamIndex = 0,
.offset = offsetof(DebugVertex, position),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(DebugVertex),
},
Gfx::VertexElement {
.streamIndex = 0,
.offset = offsetof(DebugVertex, color),
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 1,
.stride = sizeof(DebugVertex),
}
});
GraphicsPipelineCreateInfo gfxInfo;
gfxInfo.vertexDeclaration = vertexDecl;
gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE;
gfxInfo.rasterizationState.lineWidth = 5.f;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
gfxInfo.pipelineLayout = pipelineLayout;
gfxInfo.renderPass = renderPass;
pipeline = graphics->createGraphicsPipeline(gfxInfo);
}
//DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene)
// : RenderPass(graphics, scene)
//{
//
//}
//DebugPass::~DebugPass()
//{
//
//}
//
//void DebugPass::beginFrame(const Component::Camera& cam)
//{
// RenderPass::beginFrame(cam);
// DataSource uniformUpdate;
//
// viewParams.viewMatrix = cam.getViewMatrix();
// viewParams.projectionMatrix = viewport->getProjectionMatrix();
// viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
// viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
// uniformUpdate.size = sizeof(ViewParameter);
// uniformUpdate.data = (uint8*)&viewParams;
// viewParamsBuffer->updateContents(uniformUpdate);
// descriptorLayout->reset();
// descriptorSet = descriptorLayout->allocateDescriptorSet();
// descriptorSet->updateBuffer(0, viewParamsBuffer);
// descriptorSet->writeChanges();
//
// VertexBufferCreateInfo vertexBufferInfo = {
// .sourceData = {
// .size = sizeof(DebugVertex) * passData.vertices.size(),
// .data = (uint8*)passData.vertices.data(),
// },
// .vertexSize = sizeof(DebugVertex),
// .numVertices = (uint32)passData.vertices.size(),
// };
// debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
//
//}
//
//void DebugPass::render()
//{
// graphics->beginRenderPass(renderPass);
// Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
// renderCommand->setViewport(viewport);
// renderCommand->bindPipeline(pipeline);
// renderCommand->bindDescriptor(descriptorSet);
// renderCommand->bindVertexBuffer({VertexInputStream(0, 0, debugVertices)});
// renderCommand->draw((uint32)passData.vertices.size(), 1, 0, 0);
// graphics->executeCommands(Array{renderCommand});
// graphics->endRenderPass();
//}
//
//void DebugPass::endFrame()
//{
//
//}
//
//void DebugPass::publishOutputs()
//{
// UniformBufferCreateInfo viewCreateInfo = {
// .sourceData = DataSource {
// .size = sizeof(ViewParameter),
// .data = nullptr,
// },
// .dynamic = true
// };
// viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
//
// descriptorLayout = graphics->createDescriptorLayout("DebugDescLayout");
// descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
// descriptorLayout->create();
//
// pipelineLayout = graphics->createPipelineLayout();
// pipelineLayout->addDescriptorLayout(0, descriptorLayout);
// pipelineLayout->create();
//}
//
//void DebugPass::createRenderPass()
//{
// Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
// baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
// Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
// depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
// Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
// renderPass = graphics->createRenderPass(layout, viewport);
//
// ShaderCreateInfo createInfo;
// createInfo.name = "DebugVertex";
// createInfo.mainModule = "Debug";
// createInfo.entryPoint = "vertexMain";
// createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
// Gfx::PVertexShader vertexShader = graphics->createVertexShader(createInfo);
//
// createInfo.name = "DebugFragment";
//
// createInfo.entryPoint = "fragmentMain";
// Gfx::PFragmentShader fragmentShader = graphics->createFragmentShader(createInfo);
//
// Gfx::PVertexDeclaration vertexDecl = graphics->createVertexDeclaration({
// Gfx::VertexElement {
// .streamIndex = 0,
// .offset = offsetof(DebugVertex, position),
// .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
// .attributeIndex = 0,
// .stride = sizeof(DebugVertex),
// },
// Gfx::VertexElement {
// .streamIndex = 0,
// .offset = offsetof(DebugVertex, color),
// .vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
// .attributeIndex = 1,
// .stride = sizeof(DebugVertex),
// }
// });
//
// GraphicsPipelineCreateInfo gfxInfo;
// gfxInfo.vertexDeclaration = vertexDecl;
// gfxInfo.vertexShader = vertexShader;
// gfxInfo.fragmentShader = fragmentShader;
// gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE;
// gfxInfo.rasterizationState.lineWidth = 5.f;
// gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
// gfxInfo.pipelineLayout = pipelineLayout;
// gfxInfo.renderPass = renderPass;
// pipeline = graphics->createGraphicsPipeline(gfxInfo);
//}
+8 -6
View File
@@ -11,7 +11,9 @@ DECLARE_REF(Viewport)
class DebugPass : public RenderPass
{
public:
DebugPass(Gfx::PGraphics graphics);
DebugPass(Gfx::PGraphics graphics, PScene scene);
DebugPass(DebugPass&&) = default;
DebugPass& operator=(DebugPass&&) = default;
virtual ~DebugPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -19,12 +21,12 @@ public:
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
Gfx::PVertexBuffer debugVertices;
Gfx::PUniformBuffer viewParamsBuffer;
Gfx::PDescriptorLayout descriptorLayout;
Gfx::OVertexBuffer debugVertices;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OGraphicsPipeline pipeline;
};
DEFINE_REF(DebugPass)
} // namespace Seele
+16 -31
View File
@@ -1,5 +1,6 @@
#include "DepthPrepass.h"
#include "Graphics/Graphics.h"
#include "Graphics/Shader.h"
#include "Window/Window.h"
#include "Component/Camera.h"
#include "Component/Mesh.h"
@@ -16,15 +17,7 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
UniformBufferCreateInfo uniformInitializer;
depthPrepassLayout = graphics->createPipelineLayout();
viewLayout = graphics->createDescriptorLayout("ViewLayout");
viewLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
uniformInitializer.sourceData.size = sizeof(ViewParameter);
uniformInitializer.sourceData.data = (uint8*)&viewParams;
uniformInitializer.bDynamic = true;
viewParamBuffer = graphics->createUniformBuffer(uniformInitializer);
viewLayout->create();
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewLayout);
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
}
DepthPrepass::~DepthPrepass()
@@ -33,22 +26,8 @@ DepthPrepass::~DepthPrepass()
void DepthPrepass::beginFrame(const Component::Camera& cam)
{
DataSource uniformUpdate;
viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = viewport->getProjectionMatrix();
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
viewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams;
viewParamBuffer->updateContents(uniformUpdate);
viewLayout->reset();
descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet();
descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer);
descriptorSets[INDEX_VIEW_PARAMS]->writeChanges();
//std::cout << "DepthPrepass beginFrame()" << std::endl;
//co_return;
RenderPass::beginFrame(cam);
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
}
void DepthPrepass::render()
@@ -57,9 +36,16 @@ void DepthPrepass::render()
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);
Gfx::ShaderPermutation permutation;
permutation.hasFragment = false;
permutation.useMeshShading = true;
permutation.hasTaskShader = true;
std::memcpy(permutation.taskFile, "MeshletBasePass", sizeof("MeshletBasePass"));
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", sizeof("MeshletBasePass"));
graphics->beginRenderPass(renderPass);
for (VertexData* vertexData : VertexData::getList())
{
std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str()));
const auto& materials = vertexData->getMaterialData();
for (const auto& [_, materialData] : materials)
{
@@ -69,6 +55,9 @@ void DepthPrepass::render()
// Material => per material
// VertexData => per meshtype
// SceneData => per material instance
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str()));
Gfx::PermutationId id(permutation);
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
@@ -91,14 +80,10 @@ void DepthPrepass::render()
}
}
graphics->endRenderPass();
//std::cout << "DepthPrepass render()" << std::endl;
//co_return;
}
void DepthPrepass::endFrame()
{
//std::cout << "DepthPrepass endFrame()" << std::endl;
//co_return;
}
void DepthPrepass::publishOutputs()
@@ -119,8 +104,8 @@ void DepthPrepass::publishOutputs()
void DepthPrepass::createRenderPass()
{
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(depthAttachment);
renderPass = graphics->createRenderPass(std::move(layout), viewport);
}
void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>& defines)
@@ -8,7 +8,9 @@ class DepthPrepass : public RenderPass
{
public:
DepthPrepass(Gfx::PGraphics graphics, PScene scene);
~DepthPrepass();
DepthPrepass(DepthPrepass&&) = default;
DepthPrepass& operator=(DepthPrepass&&) = default;
virtual ~DepthPrepass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
virtual void endFrame() override;
@@ -23,15 +25,12 @@ private:
Gfx::OPipelineLayout depthPrepassLayout;
// Set 0: viewParameter
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
Gfx::ODescriptorLayout viewLayout;
Gfx::OUniformBuffer viewParamBuffer;
// Set 1: materials, generated
static constexpr uint32 INDEX_MATERIAL = 1;
constexpr static uint32 INDEX_MATERIAL = 1;
// Set 2: vertices, from VertexData
static constexpr uint32 INDEX_VERTEX_DATA = 2;
constexpr static uint32 INDEX_VERTEX_DATA = 2;
// Set 3: mesh data, either index buffer or meshlet data
static constexpr uint32 INDEX_SCENE_DATA = 3;
constexpr static uint32 INDEX_SCENE_DATA = 3;
Gfx::ODescriptorLayout sceneDataLayout;
};
DEFINE_REF(DepthPrepass)
@@ -19,46 +19,30 @@ LightCullingPass::~LightCullingPass()
void LightCullingPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
uint32_t viewportWidth = viewport->getSizeX();
uint32_t viewportHeight = viewport->getSizeY();
DataSource uniformUpdate;
viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = viewport->getProjectionMatrix();
viewParams.cameraPosition = Vector4(cam.getCameraPosition(), 1);
viewParams.screenDimensions = Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight));
uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams;
viewParamsBuffer->updateContents(uniformUpdate);
DataSource counterReset;
uint32 reset = 0;
counterReset.data = (uint8*)&reset;
counterReset.size = sizeof(uint32);
DataSource counterReset = {
.size = sizeof(uint32),
.data = (uint8*)&reset,
};
oLightIndexCounter->updateContents(counterReset);
tLightIndexCounter->updateContents(counterReset);
cullingDescriptorLayout->reset();
lightEnvDescriptorLayout->reset();
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
lightEnvDescriptorSet = lightEnvDescriptorLayout->allocateDescriptorSet();
cullingDescriptorSet->updateBuffer(0, viewParamsBuffer);
cullingDescriptorSet->updateBuffer(1, dispatchParamsBuffer);
cullingDescriptorSet->updateBuffer(3, oLightIndexCounter);
cullingDescriptorSet->updateBuffer(4, tLightIndexCounter);
cullingDescriptorSet->updateBuffer(5, oLightIndexList);
cullingDescriptorSet->updateBuffer(6, tLightIndexList);
cullingDescriptorSet->updateTexture(7, oLightGrid);
cullingDescriptorSet->updateTexture(8, tLightGrid);
cullingDescriptorSet->updateBuffer(9, frustumBuffer);
lightEnvDescriptorSet->updateBuffer(0, passData.lightEnv.directionalLights);
lightEnvDescriptorSet->updateBuffer(1, passData.lightEnv.numDirectional);
lightEnvDescriptorSet->updateBuffer(2, passData.lightEnv.pointLights);
lightEnvDescriptorSet->updateBuffer(3, passData.lightEnv.numPoints);
lightEnvDescriptorSet->writeChanges();
cullingDescriptorSet->updateBuffer(0, dispatchParamsBuffer);
cullingDescriptorSet->updateTexture(1, depthAttachment);
cullingDescriptorSet->updateBuffer(2, oLightIndexCounter);
cullingDescriptorSet->updateBuffer(3, tLightIndexCounter);
cullingDescriptorSet->updateBuffer(4, oLightIndexList);
cullingDescriptorSet->updateBuffer(5, tLightIndexList);
cullingDescriptorSet->updateTexture(6, Gfx::PTexture2D(oLightGrid));
cullingDescriptorSet->updateTexture(7, Gfx::PTexture2D(tLightGrid));
cullingDescriptorSet->updateBuffer(8, frustumBuffer);
//std::cout << "LightCulling beginFrame()" << std::endl;
//co_return;
}
@@ -80,9 +64,8 @@ void LightCullingPass::render()
cullingDescriptorSet->writeChanges();
Gfx::PComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand");
computeCommand->bindPipeline(cullingPipeline);
Array<Gfx::PDescriptorSet> descriptorSets = {cullingDescriptorSet, lightEnvDescriptorSet};
computeCommand->bindDescriptor(descriptorSets);
//computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
computeCommand->bindDescriptor({ viewParamsSet, lightEnv->getDescriptorSet(), cullingDescriptorSet });
computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
Array<Gfx::PComputeCommand> commands = {computeCommand};
graphics->executeCommands(commands);
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
@@ -105,42 +88,41 @@ void LightCullingPass::publishOutputs()
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParams.numThreads = numThreadGroups * glm::uvec3(BLOCK_SIZE, BLOCK_SIZE, 1);
dispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(DispatchParams),
.data = (uint8*)&dispatchParams,
},
.dynamic = false,
});
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
//ViewParams
// Dispatchparams
cullingDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
//Dispatchparams
cullingDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
//DepthTexture
cullingDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
cullingDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
//o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(4, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
cullingDescriptorLayout->addDescriptorBinding(5, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
//o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
cullingDescriptorLayout->addDescriptorBinding(6, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
//t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
cullingDescriptorLayout->addDescriptorBinding(7, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
//Frustums
cullingDescriptorLayout->addDescriptorBinding(9, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, viewportWidth * viewportHeight);
cullingDescriptorLayout->addDescriptorBinding(8, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, viewportWidth * viewportHeight);
lightEnvDescriptorLayout = graphics->createDescriptorLayout("LightEnv");
// Directional Lights
lightEnvDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_DIRECTIONAL_LIGHTS);
lightEnvDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
// Point Lights
lightEnvDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_POINT_LIGHTS);
lightEnvDescriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
lightEnv = scene->getLightEnvironment();
cullingLayout = graphics->createPipelineLayout();
cullingLayout->addDescriptorLayout(0, cullingDescriptorLayout);
cullingLayout->addDescriptorLayout(1, lightEnvDescriptorLayout);
cullingLayout->addDescriptorLayout(0, viewParamsLayout);
cullingLayout->addDescriptorLayout(1, lightEnv->getDescriptorLayout());
cullingLayout->addDescriptorLayout(2, cullingDescriptorLayout);
cullingLayout->create();
ShaderCreateInfo createInfo;
@@ -148,9 +130,6 @@ void LightCullingPass::publishOutputs()
createInfo.mainModule = "LightCulling";
createInfo.entryPoint = "cullLights";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
createInfo.defines["INDEX_LIGHT_ENV"] = "1";
createInfo.defines["NUM_MATERIAL_TEXCOORDS"] = "0";
cullingShader = graphics->createComputeShader(createInfo);
Gfx::ComputePipelineCreateInfo pipelineInfo;
@@ -167,7 +146,7 @@ void LightCullingPass::publishOutputs()
.owner = Gfx::QueueType::COMPUTE,
},
.stride = sizeof(uint32),
.bDynamic = true,
.dynamic = true,
};
oLightIndexCounter = graphics->createShaderBuffer(structInfo);
tLightIndexCounter = graphics->createShaderBuffer(structInfo);
@@ -181,7 +160,7 @@ void LightCullingPass::publishOutputs()
.owner = Gfx::QueueType::COMPUTE
},
.stride = sizeof(uint32),
.bDynamic = false,
.dynamic = false,
};
oLightIndexList = graphics->createShaderBuffer(structInfo);
tLightIndexList = graphics->createShaderBuffer(structInfo);
@@ -197,8 +176,8 @@ void LightCullingPass::publishOutputs()
oLightGrid = graphics->createTexture2D(textureInfo);
tLightGrid = graphics->createTexture2D(textureInfo);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", oLightGrid);
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", tLightGrid);
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", Gfx::PTexture2D(oLightGrid));
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", Gfx::PTexture2D(tLightGrid));
}
@@ -219,28 +198,22 @@ void LightCullingPass::setupFrustums()
glm::uvec3 numThreads = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
viewParams = {
.viewMatrix = Matrix4(),
.projectionMatrix = Matrix4(),
.cameraPosition = Vector4(),
.screenDimensions = glm::vec2(viewportWidth, viewportHeight),
};
RenderPass::beginFrame(Component::Camera());
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
Gfx::PDescriptorLayout frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
Gfx::ODescriptorLayout frustumDescriptorLayout = graphics->createDescriptorLayout("FrustumLayout");
frustumDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
frustumDescriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
frustumDescriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
frustumLayout = graphics->createPipelineLayout();
frustumLayout->addDescriptorLayout(0, frustumDescriptorLayout);
frustumLayout->addDescriptorLayout(0, viewParamsLayout);
frustumLayout->addDescriptorLayout(1, frustumDescriptorLayout);
frustumLayout->create();
ShaderCreateInfo createInfo;
createInfo.name = "Frustum";
createInfo.mainModule = "ComputeFrustums";
createInfo.entryPoint = "computeFrustums";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0";
frustumShader = graphics->createComputeShader(createInfo);
Gfx::ComputePipelineCreateInfo pipelineInfo;
@@ -248,40 +221,31 @@ void LightCullingPass::setupFrustums()
pipelineInfo.pipelineLayout = frustumLayout;
frustumPipeline = graphics->createComputePipeline(pipelineInfo);
DataSource resourceInfo;
UniformBufferCreateInfo uniformInfo;
resourceInfo.size = sizeof(ViewParameter);
resourceInfo.data = (uint8*)&viewParams;
resourceInfo.owner = Gfx::QueueType::COMPUTE;
uniformInfo.sourceData = resourceInfo;
uniformInfo.bDynamic = false;
viewParamsBuffer = graphics->createUniformBuffer(uniformInfo);
resourceInfo.size = sizeof(DispatchParams);
resourceInfo.data = (uint8*)&dispatchParams;
uniformInfo.sourceData = resourceInfo;
uniformInfo.bDynamic = false;
dispatchParamsBuffer = graphics->createUniformBuffer(uniformInfo);
ShaderBufferCreateInfo structuredInfo = {
Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(DispatchParams),
.data = (uint8*) & dispatchParams,
},
.dynamic = false,
});
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr,
},
.stride = sizeof(Frustum),
.bDynamic = false,
};
frustumBuffer = graphics->createShaderBuffer(structuredInfo);
.dynamic = false,
});
frustumDescriptorSet = frustumDescriptorLayout->allocateDescriptorSet();
frustumDescriptorSet->updateBuffer(0, viewParamsBuffer);
frustumDescriptorSet->updateBuffer(1, dispatchParamsBuffer);
frustumDescriptorSet->updateBuffer(2, frustumBuffer);
frustumDescriptorSet->updateBuffer(0, frustumDispatchParamsBuffer);
frustumDescriptorSet->updateBuffer(1, frustumBuffer);
frustumDescriptorSet->writeChanges();
Gfx::PComputeCommand command = graphics->createComputeCommand("FrustumCommand");
command->bindPipeline(frustumPipeline);
command->bindDescriptor(frustumDescriptorSet);
command->bindDescriptor({ viewParamsSet, frustumDescriptorSet });
command->dispatch(numThreadGroups.x, numThreadGroups.y, numThreadGroups.z);
Array<Gfx::PComputeCommand> commands = {command};
graphics->executeCommands(commands);
@@ -12,6 +12,8 @@ class LightCullingPass : public RenderPass
{
public:
LightCullingPass(Gfx::PGraphics graphics, PScene scene);
LightCullingPass(LightCullingPass&&) = default;
LightCullingPass& operator=(LightCullingPass&&) = default;
virtual ~LightCullingPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -39,30 +41,29 @@ private:
{
Plane planes[4];
};
Gfx::PShaderBuffer frustumBuffer;
Gfx::PUniformBuffer dispatchParamsBuffer;
Gfx::PUniformBuffer viewParamsBuffer;
Gfx::PDescriptorSet frustumDescriptorSet;
Gfx::PComputeShader frustumShader;
Gfx::PPipelineLayout frustumLayout;
Gfx::PComputePipeline frustumPipeline;
Gfx::OShaderBuffer frustumBuffer;
Gfx::OUniformBuffer dispatchParamsBuffer;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::PDescriptorSet frustumDescriptorSet;
Gfx::OComputeShader frustumShader;
Gfx::OPipelineLayout frustumLayout;
Gfx::OComputePipeline frustumPipeline;
PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment;
Gfx::PShaderBuffer frustums;
Gfx::PShaderBuffer oLightIndexCounter;
Gfx::PShaderBuffer tLightIndexCounter;
Gfx::PShaderBuffer oLightIndexList;
Gfx::PShaderBuffer tLightIndexList;
Gfx::PTexture2D oLightGrid;
Gfx::PTexture2D tLightGrid;
Gfx::PDescriptorSet lightEnvDescriptorSet;
Gfx::OShaderBuffer frustums;
Gfx::OShaderBuffer oLightIndexCounter;
Gfx::OShaderBuffer tLightIndexCounter;
Gfx::OShaderBuffer oLightIndexList;
Gfx::OShaderBuffer tLightIndexList;
Gfx::OTexture2D oLightGrid;
Gfx::OTexture2D tLightGrid;
Gfx::PDescriptorSet cullingDescriptorSet;
Gfx::PDescriptorLayout lightEnvDescriptorLayout;
Gfx::PDescriptorLayout cullingDescriptorLayout;
Gfx::PComputeShader cullingShader;
Gfx::PPipelineLayout cullingLayout;
Gfx::PComputePipeline cullingPipeline;
Gfx::ODescriptorLayout cullingDescriptorLayout;
Gfx::OComputeShader cullingShader;
Gfx::OPipelineLayout cullingLayout;
Gfx::OComputePipeline cullingPipeline;
};
DEFINE_REF(LightCullingPass)
} // namespace Seele
+2 -2
View File
@@ -24,7 +24,7 @@ template<typename This, typename... Rest>
class RenderGraph<This, Rest...> : private RenderGraph<Rest...>
{
public:
RenderGraph(PRenderGraphResources resources, This&& pass, Rest&&... rest)
RenderGraph(PRenderGraphResources resources, This pass, Rest... rest)
: RenderGraph<Rest...>(resources, std::move(rest)...)
, resources(resources)
, rp(std::move(pass))
@@ -83,7 +83,7 @@ class RenderGraphBuilder
{
public:
template<typename... RenderPasses>
static RenderGraph<RenderPasses...> build(RenderPasses&&... renderPasses)
static RenderGraph<RenderPasses...> build(RenderPasses... renderPasses)
{
PRenderGraphResources resources = new RenderGraphResources();
return RenderGraph<RenderPasses...>(resources, std::move(renderPasses)...);
@@ -0,0 +1,54 @@
#include "RenderPass.h"
using namespace Seele;
RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
: graphics(graphics)
, scene(scene)
{
viewParamsLayout = graphics->createDescriptorLayout("ViewLayout");
viewParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
UniformBufferCreateInfo uniformInitializer = {
.sourceData = {
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
},
.dynamic = true,
};
viewParamsBuffer = graphics->createUniformBuffer(uniformInitializer);
viewParamsLayout->create();
}
RenderPass::~RenderPass()
{}
void RenderPass::beginFrame(const Component::Camera& cam)
{
viewParams = {
.viewMatrix = cam.getViewMatrix(),
.projectionMatrix = viewport->getProjectionMatrix(),
.cameraPosition = Vector4(cam.getCameraPosition(), 1),
.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY())),
};
DataSource uniformUpdate = {
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
};
viewParamsBuffer->updateContents(uniformUpdate);
viewParamsLayout->reset();
viewParamsSet = viewParamsLayout->allocateDescriptorSet();
viewParamsSet->updateBuffer(0, viewParamsBuffer);
viewParamsSet->writeChanges();
}
void RenderPass::setResources(PRenderGraphResources _resources)
{
resources = _resources;
}
void RenderPass::setViewport(Gfx::PViewport _viewport)
{
viewport = _viewport;
publishOutputs();
}
+12 -14
View File
@@ -15,23 +15,17 @@ DECLARE_NAME_REF(Gfx, RenderPass)
class RenderPass
{
public:
RenderPass(Gfx::PGraphics graphics, PScene scene)
: graphics(graphics)
, scene(scene)
{}
virtual ~RenderPass()
{}
virtual void beginFrame(const Component::Camera& cam) = 0;
RenderPass(Gfx::PGraphics graphics, PScene scene);
RenderPass(RenderPass&&) = default;
RenderPass& operator=(RenderPass&&) = default;
virtual ~RenderPass();
virtual void beginFrame(const Component::Camera& cam);
virtual void render() = 0;
virtual void endFrame() = 0;
virtual void publishOutputs() = 0;
virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources _resources) { resources = _resources; }
void setViewport(Gfx::PViewport _viewport)
{
viewport = _viewport;
publishOutputs();
}
void setResources(PRenderGraphResources _resources);
void setViewport(Gfx::PViewport _viewport);
protected:
struct ViewParameter
{
@@ -42,7 +36,11 @@ protected:
Vector2 pad0;
} viewParams;
PRenderGraphResources resources;
Gfx::PRenderPass renderPass;
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
Gfx::ODescriptorLayout viewParamsLayout;
Gfx::OShaderBuffer viewParamsBuffer;
Gfx::PDescriptorSet viewParamsSet;
Gfx::ORenderPass renderPass;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
PScene scene;
@@ -86,6 +86,7 @@ SkyboxRenderPass::~SkyboxRenderPass()
void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
DataSource uniformUpdate;
viewParams.viewMatrix = cam.getViewMatrix();
@@ -131,7 +132,7 @@ void SkyboxRenderPass::publishOutputs()
.size = sizeof(ViewParameter),
.data = nullptr,
},
.bDynamic = true
.dynamic = true
};
viewParamsBuffer = graphics->createUniformBuffer(viewCreateInfo);
@@ -161,8 +162,8 @@ void SkyboxRenderPass::createRenderPass()
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(baseColorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(std::move(layout), viewport);
ShaderCreateInfo createInfo;
createInfo.name = "SkyboxVertex";
@@ -12,6 +12,8 @@ class SkyboxRenderPass : public RenderPass
{
public:
SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene);
SkyboxRenderPass(SkyboxRenderPass&&) = default;
SkyboxRenderPass& operator=(SkyboxRenderPass&&) = default;
virtual ~SkyboxRenderPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -19,13 +21,13 @@ public:
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
Gfx::PVertexBuffer cubeBuffer;
Gfx::PUniformBuffer viewParamsBuffer;
Gfx::PDescriptorLayout descriptorLayout;
Gfx::OVertexBuffer cubeBuffer;
Gfx::OUniformBuffer viewParamsBuffer;
Gfx::ODescriptorLayout descriptorLayout;
Gfx::PDescriptorSet descriptorSet;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::PSamplerState skyboxSampler;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OGraphicsPipeline pipeline;
Gfx::OSamplerState skyboxSampler;
Component::Skybox skybox;
};
DEFINE_REF(SkyboxRenderPass)
+9 -7
View File
@@ -15,8 +15,9 @@ TextPass::~TextPass()
}
void TextPass::beginFrame(const Component::Camera&)
void TextPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
for(TextRender& render : texts)
{
FontData& fd = getFontData(render.font);
@@ -126,7 +127,7 @@ void TextPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(GlyphInstanceData),
.bInstanced = 1
.instanced = 1
});
elements.add({
.binding = 0,
@@ -134,7 +135,7 @@ void TextPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 1,
.stride = sizeof(GlyphInstanceData),
.bInstanced = 1
.instanced = 1
});
elements.add({
.binding = 0,
@@ -142,7 +143,7 @@ void TextPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 2,
.stride = sizeof(GlyphInstanceData),
.bInstanced = 1
.instanced = 1
});
declaration = graphics->createVertexDeclaration(elements);
@@ -160,7 +161,7 @@ void TextPass::createRenderPass()
.size = sizeof(Matrix4),
.data = nullptr,
},
.bDynamic = true,
.dynamic = true,
});
glyphSampler = graphics->createSamplerState({
@@ -184,8 +185,8 @@ void TextPass::createRenderPass()
.size = sizeof(TextData)});
pipelineLayout->create();
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
@@ -229,6 +230,7 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font)
}
fd.glyphDataSet = glyphData;
textureArrayLayout->reset();
fd.textureArraySet = textureArrayLayout->allocateDescriptorSet();
fd.textureArraySet->updateTextureArray(0, textures);
fd.textureArraySet->writeChanges();
+11 -9
View File
@@ -21,6 +21,8 @@ class TextPass : public RenderPass
{
public:
TextPass(Gfx::PGraphics graphics, PScene scene);
TextPass(TextPass&&) = default;
TextPass& operator=(TextPass&&) = default;
virtual ~TextPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -65,19 +67,19 @@ private:
Gfx::PRenderTargetAttachment renderTarget;
Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PDescriptorLayout generalLayout;
Gfx::PDescriptorLayout textureArrayLayout;
Gfx::ODescriptorLayout generalLayout;
Gfx::ODescriptorLayout textureArrayLayout;
Gfx::PDescriptorSet generalSet;
Gfx::PUniformBuffer projectionBuffer;
Gfx::PSamplerState glyphSampler;
Gfx::OUniformBuffer projectionBuffer;
Gfx::OSamplerState glyphSampler;
Gfx::PVertexDeclaration declaration;
Gfx::PVertexShader vertexShader;
Gfx::PFragmentShader fragmentShader;
Gfx::PPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::OVertexDeclaration declaration;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OGraphicsPipeline pipeline;
Array<TextRender> texts;
};
DEFINE_REF(TextPass);
+11 -10
View File
@@ -15,8 +15,9 @@ UIPass::~UIPass()
}
void UIPass::beginFrame(const Component::Camera&)
void UIPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
VertexBufferCreateInfo info = {
.sourceData = {
.size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()),
@@ -103,7 +104,7 @@ void UIPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 0,
.stride = sizeof(UI::RenderElementStyle),
.bInstanced = 1
.instanced = 1
});
decl.add({
.binding = 0,
@@ -111,7 +112,7 @@ void UIPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32_UINT,
.attributeIndex = 1,
.stride = sizeof(UI::RenderElementStyle),
.bInstanced = 1
.instanced = 1
});
decl.add({
.binding = 0,
@@ -119,7 +120,7 @@ void UIPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.attributeIndex = 2,
.stride = sizeof(UI::RenderElementStyle),
.bInstanced = 1
.instanced = 1
});
decl.add({
.binding = 0,
@@ -127,7 +128,7 @@ void UIPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32_SFLOAT,
.attributeIndex = 3,
.stride = sizeof(UI::RenderElementStyle),
.bInstanced = 1
.instanced = 1
});
decl.add({
.binding = 0,
@@ -135,7 +136,7 @@ void UIPass::createRenderPass()
.vertexFormat = Gfx::SE_FORMAT_R32G32_SFLOAT,
.attributeIndex = 4,
.stride = sizeof(UI::RenderElementStyle),
.bInstanced = 1
.instanced = 1
});
declaration = graphics->createVertexDeclaration(decl);
@@ -152,7 +153,7 @@ void UIPass::createRenderPass()
.size = sizeof(Matrix4),
.data = (uint8*)&projectionMatrix,
},
.bDynamic = false,
.dynamic = false,
};
Gfx::PUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::PSamplerState backgroundSampler = graphics->createSamplerState({});
@@ -162,7 +163,7 @@ void UIPass::createRenderPass()
.size = sizeof(uint32),
.data = nullptr
},
.bDynamic = true,
.dynamic = true,
};
numTexturesBuffer = graphics->createUniformBuffer(info);
@@ -176,8 +177,8 @@ void UIPass::createRenderPass()
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->create();
Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(renderTarget, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport);
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(std::move(renderTarget), std::move(depthAttachment));
renderPass = graphics->createRenderPass(std::move(layout), viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexDeclaration = declaration;
+3 -1
View File
@@ -11,6 +11,8 @@ class UIPass : public RenderPass
{
public:
UIPass(Gfx::PGraphics graphics, PScene scene);
UIPass(UIPass&&) = default;
UIPass& operator=(UIPass&&) = default;
virtual ~UIPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
@@ -24,7 +26,7 @@ private:
Gfx::OTexture2D depthBuffer;
Gfx::ODescriptorLayout descriptorLayout;
Gfx::ODescriptorSet descriptorSet;
Gfx::PDescriptorSet descriptorSet;
Gfx::OUniformBuffer numTexturesBuffer;
Gfx::OVertexBuffer elementBuffer;