Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+98 -103
View File
@@ -1,26 +1,25 @@
#include "BasePass.h"
#include "Actor/CameraActor.h"
#include "Component/Camera.h"
#include "Component/Mesh.h"
#include "Graphics/Command.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
#include "Graphics/Graphics.h"
#include "Graphics/Initializer.h"
#include "Graphics/Shader.h"
#include "Window/Window.h"
#include "Component/Camera.h"
#include "Component/Mesh.h"
#include "Actor/CameraActor.h"
#include "Graphics/StaticMeshVertexData.h"
#include "Material/MaterialInstance.h"
#include "Math/Vector.h"
#include "RenderGraph.h"
#include "Material/MaterialInstance.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Command.h"
#include "Graphics/StaticMeshVertexData.h"
#include "Window/Window.h"
using namespace Seele;
extern bool useViewCulling;
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
basePassLayout->addDescriptorLayout(viewParamsLayout);
@@ -28,9 +27,15 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
lightCullingLayout = graphics->createDescriptorLayout("pLightCullingData");
// oLightIndexList
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, });
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
// oLightGrid
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, });
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
lightCullingLayout->create();
basePassLayout->addDescriptorLayout(lightCullingLayout);
@@ -38,44 +43,38 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
.stageFlags = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
.size = sizeof(VertexData::DrawCallOffsets),
});
});
if (graphics->supportMeshShading())
{
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig {
.baseLayout = basePassLayout,
.taskFile = "DrawListTask",
.mainFile = "DrawListMesh",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = true,
.useVisibility = false,
});
}
else
{
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig {
.baseLayout = basePassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = true,
.useVisibility = false,
});
if (graphics->supportMeshShading()) {
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig{
.baseLayout = basePassLayout,
.taskFile = "DrawListTask",
.mainFile = "DrawListMesh",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = true,
.useVisibility = false,
});
} else {
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig{
.baseLayout = basePassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = true,
.useVisibility = false,
});
}
}
BasePass::~BasePass()
{
}
BasePass::~BasePass() {}
void BasePass::beginFrame(const Component::Camera& cam)
{
void BasePass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
lightCullingLayout->reset();
@@ -83,8 +82,7 @@ void BasePass::beginFrame(const Component::Camera& cam)
transparentCulling = lightCullingLayout->allocateDescriptorSet();
}
void BasePass::render()
{
void BasePass::render() {
opaqueCulling->updateBuffer(0, oLightIndexList);
opaqueCulling->updateTexture(1, oLightGrid);
transparentCulling->updateBuffer(0, tLightIndexList);
@@ -97,14 +95,12 @@ void BasePass::render()
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setViewCulling(useViewCulling);
for (VertexData* vertexData : VertexData::getList())
{
for (VertexData* vertexData : VertexData::getList()) {
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
permutation.setVertexData(vertexData->getTypeName());
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials)
{
for (const auto& materialData : materials) {
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
@@ -124,43 +120,46 @@ void BasePass::render()
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
if (graphics->supportMeshShading()) {
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
} else {
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -170,21 +169,18 @@ void BasePass::render()
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
command->bindDescriptor(opaqueCulling);
for (const auto& drawCall : materialData.instances)
{
for (const auto& drawCall : materialData.instances) {
command->bindDescriptor(drawCall.materialInstance->getDescriptorSet());
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading())
{
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading()) {
command->drawMesh(drawCall.instanceMeshData.size(), 1, 1);
}
else
{
} else {
command->bindIndexBuffer(vertexData->getIndexBuffer());
for (const auto& meshData : drawCall.instanceMeshData)
{
for (const auto& meshData : drawCall.instanceMeshData) {
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), 0);
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex,
vertexData->getIndicesOffset(meshData.meshletOffset), 0);
}
}
}
@@ -195,14 +191,14 @@ void BasePass::render()
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
// Sync color write with next pass/swapchain present
//colorAttachment.getTexture()->pipelineBarrier(
// colorAttachment.getTexture()->pipelineBarrier(
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
//);
// Sync depth with next pass/next frame
//depthAttachment.getTexture()->pipelineBarrier(
// depthAttachment.getTexture()->pipelineBarrier(
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
@@ -210,20 +206,15 @@ void BasePass::render()
//);
}
void BasePass::endFrame()
{
}
void BasePass::endFrame() {}
void BasePass::publishOutputs()
{
colorAttachment = Gfx::RenderTargetAttachment(viewport,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
void BasePass::publishOutputs() {
colorAttachment = Gfx::RenderTargetAttachment(viewport, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
}
void BasePass::createRenderPass()
{
void BasePass::createRenderPass() {
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
@@ -231,7 +222,7 @@ void BasePass::createRenderPass()
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { colorAttachment },
.colorAttachments = {colorAttachment},
.depthAttachment = depthAttachment,
};
Array<Gfx::SubPassDependency> dependency = {
@@ -240,16 +231,20 @@ void BasePass::createRenderPass()
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
+6 -7
View File
@@ -2,12 +2,10 @@
#include "MinimalEngine.h"
#include "RenderPass.h"
namespace Seele
{
namespace Seele {
DECLARE_REF(CameraActor)
class BasePass : public RenderPass
{
public:
class BasePass : public RenderPass {
public:
BasePass(Gfx::PGraphics graphics, PScene scene);
BasePass(BasePass&&) = default;
BasePass& operator=(BasePass&&) = default;
@@ -17,7 +15,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment colorAttachment;
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
@@ -25,7 +24,7 @@ private:
Gfx::PShaderBuffer tLightIndexList;
Gfx::PTexture2D oLightGrid;
Gfx::PTexture2D tLightGrid;
Gfx::PDescriptorSet opaqueCulling;
Gfx::PDescriptorSet transparentCulling;
@@ -6,9 +6,7 @@ using namespace Seele;
extern bool usePositionOnly;
extern bool useViewCulling;
CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
depthPrepassLayout = graphics->createPipelineLayout("CachedDepthLayout");
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
@@ -16,55 +14,45 @@ CachedDepthPass::CachedDepthPass(Gfx::PGraphics graphics, PScene scene)
.offset = 0,
.size = sizeof(VertexData::DrawCallOffsets),
});
if (graphics->supportMeshShading())
{
if (graphics->supportMeshShading()) {
graphics->getShaderCompiler()->registerRenderPass("CachedDepthPass", Gfx::PassConfig{
.baseLayout = depthPrepassLayout,
.taskFile = "DrawListTask",
.mainFile = "DrawListMesh",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = false,
.useVisibility = true,
});
}
else
{
.baseLayout = depthPrepassLayout,
.taskFile = "DrawListTask",
.mainFile = "DrawListMesh",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = false,
.useVisibility = true,
});
} else {
graphics->getShaderCompiler()->registerRenderPass("CachedDepthPass", Gfx::PassConfig{
.baseLayout = depthPrepassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = false,
.useVisibility = true,
});
.baseLayout = depthPrepassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = false,
.useVisibility = true,
});
}
}
CachedDepthPass::~CachedDepthPass()
{
}
CachedDepthPass::~CachedDepthPass() {}
void CachedDepthPass::beginFrame(const Component::Camera &cam)
{
RenderPass::beginFrame(cam);
}
void CachedDepthPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
void CachedDepthPass::render()
{
void CachedDepthPass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("CachedDepthPass");
permutation.setPositionOnly(usePositionOnly);
permutation.setViewCulling(useViewCulling);
for (VertexData *vertexData : VertexData::getList())
{
for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
@@ -79,45 +67,48 @@ void CachedDepthPass::render()
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
const Gfx::ShaderCollection *collection = graphics->getShaderCompiler()->findShaders(id);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
if (graphics->supportMeshShading()) {
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
} else {
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -126,27 +117,23 @@ void CachedDepthPass::render()
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
uint32 offset = 0;
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offset);
if (graphics->supportMeshShading())
{
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offset);
if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1);
}
else
{
const auto &materials = vertexData->getMaterialData();
for (const auto &materialData : materials)
{
} else {
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials) {
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
for (const auto &drawCall : materialData.instances)
{
for (const auto& drawCall : materialData.instances) {
command->bindIndexBuffer(vertexData->getIndexBuffer());
uint32 inst = drawCall.offsets.instanceOffset;
for (const auto &meshData : drawCall.instanceMeshData)
{
for (const auto& meshData : drawCall.instanceMeshData) {
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex,
vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
}
}
}
@@ -157,25 +144,22 @@ void CachedDepthPass::render()
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
// Sync depth read/write with depth pass depth read
//depthBuffer->pipelineBarrier(
// depthBuffer->pipelineBarrier(
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
// Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
// sync visibility write with depth pass visibility write
//visibilityBuffer->pipelineBarrier(
// visibilityBuffer->pipelineBarrier(
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
}
void CachedDepthPass::endFrame()
{
}
void CachedDepthPass::endFrame() {}
void CachedDepthPass::publishOutputs()
{
void CachedDepthPass::publishOutputs() {
// 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
TextureCreateInfo depthBufferInfo = {
@@ -186,8 +170,7 @@ void CachedDepthPass::publishOutputs()
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
@@ -199,14 +182,12 @@ void CachedDepthPass::publishOutputs()
};
visibilityBuffer = graphics->createTexture2D(visibilityInfo);
visibilityAttachment =
Gfx::RenderTargetAttachment(visibilityBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::RenderTargetAttachment(visibilityBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("VISIBILITY", visibilityAttachment);
}
void CachedDepthPass::createRenderPass()
{
void CachedDepthPass::createRenderPass() {
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
@@ -219,16 +200,20 @@ void CachedDepthPass::createRenderPass()
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
@@ -1,11 +1,9 @@
#pragma once
#include "RenderPass.h"
namespace Seele
{
class CachedDepthPass : public RenderPass
{
public:
namespace Seele {
class CachedDepthPass : public RenderPass {
public:
CachedDepthPass(Gfx::PGraphics graphics, PScene scene);
CachedDepthPass(CachedDepthPass&&) = default;
CachedDepthPass& operator=(CachedDepthPass&&) = default;
@@ -15,14 +13,15 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::OTexture2D depthBuffer;
Gfx::OTexture2D visibilityBuffer;
Gfx::OPipelineLayout depthPrepassLayout;
Gfx::PShaderBuffer cullingBuffer;
};
DEFINE_REF(CachedDepthPass)
}
} // namespace Seele
+48 -70
View File
@@ -1,77 +1,62 @@
#include "DebugPass.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Pipeline.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Shader.h"
using namespace Seele;
Array<DebugVertex> gDebugVertices;
void Seele::addDebugVertex(DebugVertex vert)
{
gDebugVertices.add(vert);
}
void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
void Seele::addDebugVertices(Array<DebugVertex> verts)
{
gDebugVertices.addAll(verts);
}
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
DebugPass::~DebugPass()
{
}
DebugPass::~DebugPass() {}
void DebugPass::beginFrame(const Component::Camera& cam)
{
void DebugPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData = {
.size = sizeof(DebugVertex) * gDebugVertices.size(),
.data = (uint8*)gDebugVertices.data(),
},
.sourceData =
{
.size = sizeof(DebugVertex) * gDebugVertices.size(),
.data = (uint8*)gDebugVertices.data(),
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)gDebugVertices.size(),
.name = "DebugVertices",
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
}
void DebugPass::render()
{
void DebugPass::render() {
graphics->beginRenderPass(renderPass);
if (gDebugVertices.size() > 0)
{
if (gDebugVertices.size() > 0) {
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
renderCommand->setViewport(viewport);
renderCommand->bindPipeline(pipeline);
renderCommand->bindDescriptor(viewParamsSet);
renderCommand->bindVertexBuffer({ debugVertices });
renderCommand->bindVertexBuffer({debugVertices});
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
Array<Gfx::ORenderCommand> commands;
commands.add(std::move(renderCommand));
graphics->executeCommands({ std::move(commands) });
graphics->executeCommands({std::move(commands)});
}
graphics->endRenderPass();
gDebugVertices.clear();
// Sync color write with next pass/swapchain present
//colorAttachment.getTexture()->pipelineBarrier(
// colorAttachment.getTexture()->pipelineBarrier(
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
// Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
//);
// Sync depth with next pass/next frame
//depthAttachment.getTexture()->pipelineBarrier(
// depthAttachment.getTexture()->pipelineBarrier(
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
// Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
@@ -79,28 +64,22 @@ void DebugPass::render()
//);
}
void DebugPass::endFrame()
{
}
void DebugPass::endFrame() {}
void DebugPass::publishOutputs()
{
}
void DebugPass::publishOutputs() {}
void DebugPass::createRenderPass()
{
void DebugPass::createRenderPass() {
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
colorAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
colorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
colorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {colorAttachment},
.colorAttachments = {colorAttachment},
.depthAttachment = depthAttachment,
};
@@ -110,20 +89,24 @@ void DebugPass::createRenderPass()
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
pipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
pipelineLayout->addDescriptorLayout(viewParamsLayout);
@@ -141,27 +124,22 @@ void DebugPass::createRenderPass()
pipelineLayout->create();
VertexInputStateCreateInfo inputCreate = {
.bindings = {
VertexInputBinding {
.binding = 0,
.stride = sizeof(DebugVertex),
.inputRate = Gfx::SE_VERTEX_INPUT_RATE_VERTEX,
.bindings =
{
VertexInputBinding{
.binding = 0,
.stride = sizeof(DebugVertex),
.inputRate = Gfx::SE_VERTEX_INPUT_RATE_VERTEX,
},
},
},
.attributes = {
VertexInputAttribute {
.location = 0,
.binding = 0,
.format = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.offset = 0,
},
VertexInputAttribute {
.location = 1,
.binding = 0,
.format = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.offset = sizeof(Vector)
}
},
.attributes = {VertexInputAttribute{
.location = 0,
.binding = 0,
.format = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.offset = 0,
},
VertexInputAttribute{
.location = 1, .binding = 0, .format = Gfx::SE_FORMAT_R32G32B32_SFLOAT, .offset = sizeof(Vector)}},
};
vertexInput = graphics->createVertexInput(inputCreate);
Gfx::LegacyPipelineCreateInfo gfxInfo;
+8 -8
View File
@@ -1,17 +1,16 @@
#pragma once
#include "RenderPass.h"
#include "Scene/Scene.h"
#include "Graphics/DebugVertex.h"
#include "Graphics/Pipeline.h"
#include "RenderPass.h"
#include "Scene/Scene.h"
namespace Seele
{
namespace Seele {
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
class DebugPass : public RenderPass
{
public:
class DebugPass : public RenderPass {
public:
DebugPass(Gfx::PGraphics graphics, PScene scene);
DebugPass(DebugPass&&) = default;
DebugPass& operator=(DebugPass&&) = default;
@@ -21,7 +20,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment colorAttachment;
Gfx::RenderTargetAttachment depthAttachment;
Gfx::OVertexInput vertexInput;
+81 -101
View File
@@ -6,9 +6,7 @@ using namespace Seele;
extern bool usePositionOnly;
extern bool useViewCulling;
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
depthPrepassLayout = graphics->createPipelineLayout("DepthPrepassLayout");
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
@@ -16,55 +14,45 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
.offset = 0,
.size = sizeof(VertexData::DrawCallOffsets),
});
if (graphics->supportMeshShading())
{
if (graphics->supportMeshShading()) {
graphics->getShaderCompiler()->registerRenderPass("DepthPass", Gfx::PassConfig{
.baseLayout = depthPrepassLayout,
.taskFile = "DepthCullingTask",
.mainFile = "DepthCullingMesh",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = false,
.useVisibility = true,
});
}
else
{
.baseLayout = depthPrepassLayout,
.taskFile = "DepthCullingTask",
.mainFile = "DepthCullingMesh",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = false,
.useVisibility = true,
});
} else {
graphics->getShaderCompiler()->registerRenderPass("DepthPass", Gfx::PassConfig{
.baseLayout = depthPrepassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = false,
.useVisibility = true,
});
.baseLayout = depthPrepassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "VisibilityPass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = false,
.useVisibility = true,
});
}
}
DepthPrepass::~DepthPrepass()
{
}
DepthPrepass::~DepthPrepass() {}
void DepthPrepass::beginFrame(const Component::Camera &cam)
{
RenderPass::beginFrame(cam);
}
void DepthPrepass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
void DepthPrepass::render()
{
void DepthPrepass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("DepthPass");
permutation.setPositionOnly(usePositionOnly);
permutation.setViewCulling(useViewCulling);
for (VertexData *vertexData : VertexData::getList())
{
for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
@@ -78,45 +66,48 @@ void DepthPrepass::render()
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
const Gfx::ShaderCollection *collection = graphics->getShaderCompiler()->findShaders(id);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
if (graphics->supportMeshShading()) {
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
} else {
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState = {
.samples = viewport->getSamples(),
},
.depthStencilState = {
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend = {
.attachmentCount = 1,
},
.multisampleState =
{
.samples = viewport->getSamples(),
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -125,27 +116,23 @@ void DepthPrepass::render()
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
uint32 offset = 0;
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offset);
if (graphics->supportMeshShading())
{
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offset);
if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1);
}
else
{
const auto &materials = vertexData->getMaterialData();
for (const auto &materialData : materials)
{
for (const auto &drawCall : materialData.instances)
{
} else {
const auto& materials = vertexData->getMaterialData();
for (const auto& materialData : materials) {
for (const auto& drawCall : materialData.instances) {
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
command->bindIndexBuffer(vertexData->getIndexBuffer());
uint32 inst = drawCall.offsets.instanceOffset;
for (const auto &meshData : drawCall.instanceMeshData)
{
for (const auto& meshData : drawCall.instanceMeshData) {
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex,
vertexData->getIndicesOffset(meshData.meshletOffset), inst++);
}
}
}
@@ -156,38 +143,27 @@ void DepthPrepass::render()
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
// Sync depth read/write with compute read
depthAttachment.getTexture()->pipelineBarrier(
depthAttachment.getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
// Sync depth read/write with base pass read
//depthAttachment.getTexture()->pipelineBarrier(
// depthAttachment.getTexture()->pipelineBarrier(
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
// Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
// Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
// Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
//);
// Sync visibility write with compute read
visibilityAttachment.getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
visibilityAttachment.getTexture()->pipelineBarrier(Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
void DepthPrepass::endFrame()
{
}
void DepthPrepass::endFrame() {}
void DepthPrepass::publishOutputs()
{
}
void DepthPrepass::publishOutputs() {}
void DepthPrepass::createRenderPass()
{
void DepthPrepass::createRenderPass() {
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
@@ -209,16 +185,20 @@ void DepthPrepass::createRenderPass()
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
};
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport);
@@ -2,11 +2,9 @@
#include "MinimalEngine.h"
#include "RenderPass.h"
namespace Seele
{
class DepthPrepass : public RenderPass
{
public:
namespace Seele {
class DepthPrepass : public RenderPass {
public:
DepthPrepass(Gfx::PGraphics graphics, PScene scene);
DepthPrepass(DepthPrepass&&) = default;
DepthPrepass& operator=(DepthPrepass&&) = default;
@@ -16,7 +14,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::OPipelineLayout depthPrepassLayout;
@@ -1,62 +1,46 @@
#include "LightCullingPass.h"
#include "Graphics/Graphics.h"
#include "Scene/Scene.h"
#include "Actor/CameraActor.h"
#include "Component/Camera.h"
#include "RenderGraph.h"
#include "Graphics/Command.h"
#include "Graphics/Graphics.h"
#include "RenderGraph.h"
#include "Scene/Scene.h"
using namespace Seele;
extern bool useLightCulling;
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
LightCullingPass::~LightCullingPass()
{
LightCullingPass::~LightCullingPass() {}
}
void LightCullingPass::beginFrame(const Component::Camera& cam)
{
void LightCullingPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
oLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
tLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
uint32 reset = 0;
ShaderBufferCreateInfo counterReset = {
.sourceData = {
.size = sizeof(uint32),
.data = (uint8*)&reset,
.owner = Gfx::QueueType::COMPUTE
}
};
.sourceData = {.size = sizeof(uint32), .data = (uint8*)&reset, .owner = Gfx::QueueType::COMPUTE}};
oLightIndexCounter->rotateBuffer(sizeof(uint32));
oLightIndexCounter->updateContents(counterReset);
tLightIndexCounter->rotateBuffer(sizeof(uint32));
tLightIndexCounter->updateContents(counterReset);
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
oLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
cullingDescriptorLayout->reset();
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
}
void LightCullingPass::render()
{
void LightCullingPass::render() {
depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE);
cullingDescriptorSet->updateTexture(0, depthAttachment);
cullingDescriptorSet->updateBuffer(1, oLightIndexCounter);
@@ -67,41 +51,31 @@ void LightCullingPass::render()
cullingDescriptorSet->updateTexture(6, Gfx::PTexture2D(tLightGrid));
cullingDescriptorSet->writeChanges();
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand");
if (useLightCulling)
{
if (useLightCulling) {
computeCommand->bindPipeline(cullingEnabledPipeline);
}
else
{
} else {
computeCommand->bindPipeline(cullingPipeline);
}
computeCommand->bindDescriptor({ viewParamsSet, dispatchParamsSet, cullingDescriptorSet, lightEnv->getDescriptorSet() });
computeCommand->bindDescriptor({viewParamsSet, dispatchParamsSet, cullingDescriptorSet, lightEnv->getDescriptorSet()});
computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
Array<Gfx::OComputeCommand> commands;
commands.add(std::move(computeCommand));
//std::cout << "Execute" << std::endl;
// std::cout << "Execute" << std::endl;
graphics->executeCommands(std::move(commands));
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);
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);
}
void LightCullingPass::endFrame()
{
}
void LightCullingPass::endFrame() {}
void LightCullingPass::publishOutputs()
{
void LightCullingPass::publishOutputs() {
setupFrustums();
uint32_t viewportWidth = viewport->getWidth();
uint32_t viewportHeight = viewport->getHeight();
@@ -109,14 +83,10 @@ void LightCullingPass::publishOutputs()
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParams.numThreads = numThreadGroups * glm::uvec3(BLOCK_SIZE, BLOCK_SIZE, 1);
dispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(DispatchParams),
.data = (uint8*)&dispatchParams,
.owner = Gfx::QueueType::COMPUTE
},
.sourceData = {.size = sizeof(DispatchParams), .data = (uint8*)&dispatchParams, .owner = Gfx::QueueType::COMPUTE},
.dynamic = false,
.name = "DispatchParams",
});
});
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, dispatchParamsBuffer);
@@ -125,20 +95,29 @@ void LightCullingPass::publishOutputs()
cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams");
//DepthTexture
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, });
//o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
//t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT });
// DepthTexture
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
// o_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
// t_lightIndexCounter
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
// o_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
// t_lightIndexList
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
// o_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
// t_lightGrid
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
cullingDescriptorLayout->create();
@@ -172,7 +151,7 @@ void LightCullingPass::publishOutputs()
cullingEnableLayout->addDescriptorLayout(dispatchParamsLayout);
cullingEnableLayout->addDescriptorLayout(cullingDescriptorLayout);
cullingEnableLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
ShaderCreateInfo createInfo = {
.name = "Culling",
.mainModule = "LightCulling",
@@ -182,20 +161,21 @@ void LightCullingPass::publishOutputs()
createInfo.defines["LIGHT_CULLING"] = "1";
cullingEnabledShader = graphics->createComputeShader(createInfo);
cullingEnableLayout->create();
Gfx::ComputePipelineCreateInfo pipelineInfo;
pipelineInfo.computeShader = cullingShader;
pipelineInfo.pipelineLayout = std::move(cullingEnableLayout);
cullingEnabledPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
}
uint32 counterReset = 0;
ShaderBufferCreateInfo structInfo = {
.sourceData = {
.size = sizeof(uint32),
.data = (uint8*)&counterReset,
.owner = Gfx::QueueType::COMPUTE,
},
.sourceData =
{
.size = sizeof(uint32),
.data = (uint8*)&counterReset,
.owner = Gfx::QueueType::COMPUTE,
},
.numElements = 1,
.dynamic = true,
.name = "oLightIndexCounter",
@@ -204,14 +184,10 @@ void LightCullingPass::publishOutputs()
structInfo.name = "tLightIndexCounter";
tLightIndexCounter = graphics->createShaderBuffer(structInfo);
structInfo = {
.sourceData = {
.size = (uint32)sizeof(uint32)
* dispatchParams.numThreadGroups.x
* dispatchParams.numThreadGroups.y
* dispatchParams.numThreadGroups.z * 8192,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE
},
.sourceData = {.size = (uint32)sizeof(uint32) * dispatchParams.numThreadGroups.x * dispatchParams.numThreadGroups.y *
dispatchParams.numThreadGroups.z * 8192,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE},
.dynamic = false,
.name = "oLightIndexList",
};
@@ -234,15 +210,9 @@ void LightCullingPass::publishOutputs()
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", Gfx::PTexture2D(tLightGrid));
}
void LightCullingPass::createRenderPass() { depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTexture(); }
void LightCullingPass::createRenderPass()
{
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTexture();
}
void LightCullingPass::setupFrustums()
{
void LightCullingPass::setupFrustums() {
uint32_t viewportWidth = viewport->getWidth();
uint32_t viewportHeight = viewport->getHeight();
@@ -254,8 +224,12 @@ void LightCullingPass::setupFrustums()
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT});
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
@@ -277,25 +251,17 @@ void LightCullingPass::setupFrustums()
frustumPipeline = graphics->createComputePipeline(pipelineInfo);
Gfx::OUniformBuffer frustumDispatchParamsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(DispatchParams),
.data = (uint8*)&dispatchParams,
.owner = Gfx::QueueType::COMPUTE
},
.sourceData = {.size = sizeof(DispatchParams), .data = (uint8*)&dispatchParams, .owner = Gfx::QueueType::COMPUTE},
.dynamic = false,
.name = "FrustumDispatch"
});
.name = "FrustumDispatch"});
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE
},
.numElements = numThreads.x * numThreads.y * numThreads.z,
.dynamic = false,
.name = "FrustumBuffer"
});
frustumBuffer = graphics->createShaderBuffer(
ShaderBufferCreateInfo{.sourceData = {.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
.data = nullptr,
.owner = Gfx::QueueType::COMPUTE},
.numElements = numThreads.x * numThreads.y * numThreads.z,
.dynamic = false,
.name = "FrustumBuffer"});
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
dispatchParamsSet->updateBuffer(0, frustumDispatchParamsBuffer);
@@ -304,11 +270,11 @@ void LightCullingPass::setupFrustums()
Gfx::OComputeCommand command = graphics->createComputeCommand("FrustumCommand");
command->bindPipeline(frustumPipeline);
command->bindDescriptor({ viewParamsSet, dispatchParamsSet });
command->bindDescriptor({viewParamsSet, dispatchParamsSet});
command->dispatch(numThreadGroups.x, numThreadGroups.y, numThreadGroups.z);
Array<Gfx::OComputeCommand> commands;
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
@@ -1,16 +1,15 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/Shader.h"
#include "RenderPass.h"
#include "Scene/Scene.h"
namespace Seele
{
namespace Seele {
DECLARE_REF(CameraActor)
DECLARE_REF(Scene)
DECLARE_REF(Viewport)
class LightCullingPass : public RenderPass
{
public:
class LightCullingPass : public RenderPass {
public:
LightCullingPass(Gfx::PGraphics graphics, PScene scene);
LightCullingPass(LightCullingPass&&) = default;
LightCullingPass& operator=(LightCullingPass&&) = default;
@@ -20,24 +19,22 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
void setupFrustums();
static constexpr uint32 BLOCK_SIZE = 32;
static constexpr uint32 INDEX_LIGHT_ENV = 1;
struct DispatchParams
{
struct DispatchParams {
glm::uvec3 numThreadGroups;
uint32_t pad0;
glm::uvec3 numThreads;
uint32_t pad1;
} dispatchParams;
struct Plane
{
struct Plane {
Vector n;
float d;
};
struct Frustum
{
struct Frustum {
Plane planes[4];
};
@@ -49,7 +46,7 @@ private:
Gfx::OComputeShader frustumShader;
Gfx::PComputePipeline frustumPipeline;
Gfx::OPipelineLayout frustumLayout;
PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment;
Gfx::OShaderBuffer oLightIndexCounter;
@@ -1,11 +1,9 @@
#pragma once
#include "RenderPass.h"
namespace Seele
{
class RayTracingPass : public RenderPass
{
public:
namespace Seele {
class RayTracingPass : public RenderPass {
public:
RayTracingPass(Gfx::PGraphics graphics, PScene scene);
RayTracingPass(RayTracingPass&& other) = default;
RayTracingPass& operator=(RayTracingPass&& other) = default;
@@ -14,7 +12,7 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
};
}
} // namespace Seele
+17 -31
View File
@@ -1,54 +1,40 @@
#pragma once
#include "RenderPass.h"
namespace Seele
{
class RenderGraph
{
public:
RenderGraph()
{
res = new RenderGraphResources();
}
void addPass(ORenderPass pass)
{
namespace Seele {
class RenderGraph {
public:
RenderGraph() { res = new RenderGraphResources(); }
void addPass(ORenderPass pass) {
pass->setResources(res);
passes.add(std::move(pass));
passes.add(std::move(pass));
}
void setViewport(Gfx::PViewport viewport)
{
for (auto& pass : passes)
{
void setViewport(Gfx::PViewport viewport) {
for (auto& pass : passes) {
pass->setViewport(viewport);
}
}
void createRenderPass()
{
for (auto& pass : passes)
{
void createRenderPass() {
for (auto& pass : passes) {
pass->publishOutputs();
}
for (auto& pass : passes)
{
for (auto& pass : passes) {
pass->createRenderPass();
}
}
void render(const Component::Camera& cam)
{
for (auto& pass : passes)
{
void render(const Component::Camera& cam) {
for (auto& pass : passes) {
pass->beginFrame(cam);
}
for (auto& pass : passes)
{
for (auto& pass : passes) {
pass->render();
}
for (auto& pass : passes)
{
for (auto& pass : passes) {
pass->endFrame();
}
}
private:
private:
PRenderGraphResources res;
List<ORenderPass> passes;
};
@@ -3,51 +3,31 @@
using namespace Seele;
RenderGraphResources::RenderGraphResources()
{
}
RenderGraphResources::RenderGraphResources() {}
RenderGraphResources::~RenderGraphResources()
{
}
RenderGraphResources::~RenderGraphResources() {}
Gfx::RenderTargetAttachment RenderGraphResources::requestRenderTarget(const std::string& outputName)
{
Gfx::RenderTargetAttachment RenderGraphResources::requestRenderTarget(const std::string& outputName) {
return registeredAttachments.at(outputName);
}
Gfx::PTexture RenderGraphResources::requestTexture(const std::string& outputName)
{
return registeredTextures.at(outputName);
}
Gfx::PTexture RenderGraphResources::requestTexture(const std::string& outputName) { return registeredTextures.at(outputName); }
Gfx::PShaderBuffer RenderGraphResources::requestBuffer(const std::string& outputName)
{
return registeredBuffers.at(outputName);
}
Gfx::PShaderBuffer RenderGraphResources::requestBuffer(const std::string& outputName) { return registeredBuffers.at(outputName); }
Gfx::PUniformBuffer RenderGraphResources::requestUniform(const std::string& outputName)
{
return registeredUniforms.at(outputName);
}
Gfx::PUniformBuffer RenderGraphResources::requestUniform(const std::string& outputName) { return registeredUniforms.at(outputName); }
void RenderGraphResources::registerRenderPassOutput(const std::string& outputName, Gfx::RenderTargetAttachment attachment)
{
void RenderGraphResources::registerRenderPassOutput(const std::string& outputName, Gfx::RenderTargetAttachment attachment) {
registeredAttachments[outputName] = attachment;
}
void RenderGraphResources::registerTextureOutput(const std::string& outputName, Gfx::PTexture texture)
{
void RenderGraphResources::registerTextureOutput(const std::string& outputName, Gfx::PTexture texture) {
registeredTextures[outputName] = texture;
}
void RenderGraphResources::registerBufferOutput(const std::string& outputName, Gfx::PShaderBuffer buffer)
{
void RenderGraphResources::registerBufferOutput(const std::string& outputName, Gfx::PShaderBuffer buffer) {
registeredBuffers[outputName] = buffer;
}
void RenderGraphResources::registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer)
{
void RenderGraphResources::registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer) {
registeredUniforms[outputName] = buffer;
}
@@ -1,16 +1,15 @@
#pragma once
#include "MinimalEngine.h"
#include "Graphics/Buffer.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Texture.h"
#include "Graphics/Buffer.h"
#include "MinimalEngine.h"
namespace Seele
{
namespace Seele {
DECLARE_REF(ViewFrame)
class RenderGraphResources
{
public:
class RenderGraphResources {
public:
RenderGraphResources();
~RenderGraphResources();
Gfx::RenderTargetAttachment requestRenderTarget(const std::string& outputName);
@@ -21,7 +20,8 @@ public:
void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer);
void registerBufferOutput(const std::string& outputName, Gfx::PShaderBuffer buffer);
void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer);
protected:
protected:
Map<std::string, Gfx::RenderTargetAttachment> registeredAttachments;
Map<std::string, Gfx::PTexture> registeredTextures;
Map<std::string, Gfx::PShaderBuffer> registeredBuffers;
+16 -26
View File
@@ -2,18 +2,19 @@
using namespace Seele;
RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
: graphics(graphics)
, scene(scene)
{
RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene) : graphics(graphics), scene(scene) {
viewParamsLayout = graphics->createDescriptorLayout("pViewParams");
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
UniformBufferCreateInfo uniformInitializer = {
.sourceData = {
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
},
.sourceData =
{
.size = sizeof(ViewParameter),
.data = (uint8*)&viewParams,
},
.dynamic = true,
.name = "viewParamsBuffer",
};
@@ -21,11 +22,9 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
viewParamsLayout->create();
}
RenderPass::~RenderPass()
{}
RenderPass::~RenderPass() {}
void RenderPass::beginFrame(const Component::Camera& cam)
{
void RenderPass::beginFrame(const Component::Camera& cam) {
viewParams = {
.viewMatrix = cam.getViewMatrix(),
.inverseViewMatrix = glm::inverse(cam.getViewMatrix()),
@@ -40,23 +39,14 @@ void RenderPass::beginFrame(const Component::Camera& cam)
};
viewParamsBuffer->rotateBuffer(sizeof(ViewParameter));
viewParamsBuffer->updateContents(uniformUpdate);
viewParamsBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT);
viewParamsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_ALL_COMMANDS_BIT);
viewParamsLayout->reset();
viewParamsSet = viewParamsLayout->allocateDescriptorSet();
viewParamsSet->updateBuffer(0, viewParamsBuffer);
viewParamsSet->writeChanges();
}
void RenderPass::setResources(PRenderGraphResources _resources)
{
resources = _resources;
}
void RenderPass::setResources(PRenderGraphResources _resources) { resources = _resources; }
void RenderPass::setViewport(Gfx::PViewport _viewport)
{
viewport = _viewport;
}
void RenderPass::setViewport(Gfx::PViewport _viewport) { viewport = _viewport; }
+13 -14
View File
@@ -1,20 +1,19 @@
#pragma once
#include "MinimalEngine.h"
#include "Math/Math.h"
#include "RenderGraphResources.h"
#include "Component/Camera.h"
#include "Scene/Scene.h"
#include "Material/MaterialInstance.h"
#include "Graphics/VertexData.h"
#include "Material/MaterialInstance.h"
#include "Math/Math.h"
#include "MinimalEngine.h"
#include "RenderGraphResources.h"
#include "Scene/Scene.h"
namespace Seele
{
namespace Seele {
DECLARE_NAME_REF(Gfx, Viewport)
DECLARE_NAME_REF(Gfx, Graphics)
DECLARE_NAME_REF(Gfx, RenderPass)
class RenderPass
{
public:
class RenderPass {
public:
RenderPass(Gfx::PGraphics graphics, PScene scene);
RenderPass(RenderPass&&) = default;
RenderPass& operator=(RenderPass&&) = default;
@@ -26,9 +25,9 @@ public:
virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources _resources);
void setViewport(Gfx::PViewport _viewport);
protected:
struct ViewParameter
{
protected:
struct ViewParameter {
Matrix4 viewMatrix;
Matrix4 inverseViewMatrix;
Matrix4 projectionMatrix;
@@ -46,7 +45,7 @@ protected:
PScene scene;
};
DEFINE_REF(RenderPass)
template<typename RP>
template <typename RP>
concept RenderPassType = std::derived_from<RP, RenderPass>;
} // namespace Seele
@@ -1,13 +1,12 @@
#include "SkyboxRenderPass.h"
#include "Graphics/Graphics.h"
#include "Asset/AssetRegistry.h"
#include "Graphics/Command.h"
#include "Graphics/Graphics.h"
using namespace Seele;
SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
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>(),
@@ -15,13 +14,9 @@ SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
.blendFactor = 0,
};
}
SkyboxRenderPass::~SkyboxRenderPass()
{
SkyboxRenderPass::~SkyboxRenderPass() {}
}
void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
{
void SkyboxRenderPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
skyboxDataLayout->reset();
@@ -30,14 +25,12 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
skyboxBuffer->updateContents(DataSource{
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
});
});
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, skyboxBuffer);
skyboxDataSet->writeChanges();
skyboxBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT
);
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_VERTEX_SHADER_BIT);
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
@@ -45,16 +38,13 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
textureSet->writeChanges();
}
void SkyboxRenderPass::render()
{
void SkyboxRenderPass::render() {
colorAttachment.getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Gfx::SE_ACCESS_COLOR_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
);
Gfx::SE_ACCESS_COLOR_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
depthAttachment.getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
);
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
graphics->beginRenderPass(renderPass);
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("SkyboxRender");
renderCommand->setViewport(viewport);
@@ -67,48 +57,56 @@ void SkyboxRenderPass::render()
graphics->endRenderPass();
}
void SkyboxRenderPass::endFrame()
{
void SkyboxRenderPass::endFrame() {}
}
void SkyboxRenderPass::publishOutputs()
{
void SkyboxRenderPass::publishOutputs() {
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
textureLayout->create();
skyboxSampler = graphics->createSampler({});
}
void SkyboxRenderPass::createRenderPass()
{
void SkyboxRenderPass::createRenderPass() {
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
//colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
// colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
//depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
//Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
// .colorAttachments = { colorAttachment },
// .depthAttachment = depthAttachment
//};
//renderPass = graphics->createRenderPass(std::move(layout), viewport);
// depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
// Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
// .colorAttachments = { colorAttachment },
// .depthAttachment = depthAttachment
// };
// renderPass = graphics->createRenderPass(std::move(layout), viewport);
skyboxData.transformMatrix = Matrix4(1);
skyboxData.fogColor = skybox.fogColor;
skyboxData.blendFactor = skybox.blendFactor;
skyboxBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
},
.sourceData =
{
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
},
.dynamic = true,
});
});
ShaderCreateInfo createInfo = {
.name = "SkyboxVertex",
@@ -1,13 +1,12 @@
#pragma once
#include "RenderPass.h"
#include "Graphics/Shader.h"
#include "Component/Skybox.h"
#include "Graphics/Shader.h"
#include "RenderPass.h"
namespace Seele
{
class SkyboxRenderPass : public RenderPass
{
public:
namespace Seele {
class SkyboxRenderPass : public RenderPass {
public:
SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene);
SkyboxRenderPass(SkyboxRenderPass&&) = default;
SkyboxRenderPass& operator=(SkyboxRenderPass&&) = default;
@@ -17,7 +16,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment colorAttachment;
Gfx::RenderTargetAttachment depthAttachment;
Gfx::ODescriptorLayout skyboxDataLayout;
@@ -29,8 +29,7 @@ private:
Gfx::OPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::OSampler skyboxSampler;
struct SkyboxData
{
struct SkyboxData {
Matrix4 transformMatrix;
Vector fogColor;
float blendFactor;
+62 -69
View File
@@ -1,40 +1,32 @@
#include "TextPass.h"
#include "Graphics/Command.h"
#include "Graphics/Enums.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
#include "RenderGraph.h"
using namespace Seele;
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
TextPass::TextPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
TextPass::~TextPass()
{
}
TextPass::~TextPass() {}
void TextPass::beginFrame(const Component::Camera& cam)
{
void TextPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
for(TextRender& render : texts)
{
for (TextRender& render : texts) {
FontData& fd = getFontData(render.font);
TextResources& res = textResources[render.font].add();
Array<GlyphInstanceData> instanceData;
float x = render.position.x;
float y = render.position.y;
for(uint32 c : render.text)
{
for (uint32 c : render.text) {
const GlyphData& glyph = fd.glyphDataSet[fd.characterToGlyphIndex[c]];
Vector2 bearing = glyph.bearing;
Vector2 size = glyph.size;
float xpos = x + bearing.x * render.scale;
float ypos = y - (size.y - bearing.y) * render.scale;
float w = size.x * render.scale;
float h = size.y * render.scale;
@@ -46,10 +38,11 @@ void TextPass::beginFrame(const Component::Camera& cam)
x += (glyph.advance >> 6) * render.scale;
}
res.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = {
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()),
},
.sourceData =
{
.size = static_cast<uint32>(instanceData.size() * sizeof(GlyphInstanceData)),
.data = reinterpret_cast<uint8*>(instanceData.data()),
},
.numElements = instanceData.size(),
});
@@ -68,48 +61,42 @@ void TextPass::beginFrame(const Component::Camera& cam)
projectionBuffer->updateContents(projectionUpdate);
generalSet->updateBuffer(1, projectionBuffer);
generalSet->writeChanges();
//co_return;
// co_return;
}
void TextPass::render()
{
void TextPass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
for(const auto& [fontAsset, res] : textResources)
{
for (const auto& [fontAsset, res] : textResources) {
Gfx::ORenderCommand command = graphics->createRenderCommand("TextPassCommand");
command->setViewport(viewport);
command->bindPipeline(pipeline);
for(const auto& resource : res)
{
for (const auto& resource : res) {
command->bindDescriptor({generalSet, resource.textureArraySet});
//command->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(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->bindVertexBuffer({resource.vertexBuffer});
command->pushConstants(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);
}
commands.add(std::move(command));
}
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
textResources.clear();
//co_return;
// co_return;
}
void TextPass::endFrame()
{
//co_return;
void TextPass::endFrame() {
// co_return;
}
void TextPass::publishOutputs()
{
}
void TextPass::publishOutputs() {}
void TextPass::createRenderPass()
{
void TextPass::createRenderPass() {
renderTarget = resources->requestRenderTarget("UIPASS_COLOR");
depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH");
ShaderCreateInfo createInfo = {
.name = "TextVertex",
.mainModule = "TextPass",
@@ -118,22 +105,35 @@ void TextPass::createRenderPass()
vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "TextFragment";
createInfo.entryPoint = "fragmentMain";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
generalLayout = graphics->createDescriptorLayout("pRender");
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
generalLayout->create();
textureArrayLayout = graphics->createDescriptorLayout("pGlyphTextures");
textureArrayLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, .descriptorCount = 256, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,});
textureArrayLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY,
.descriptorCount = 256,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT,
});
textureArrayLayout->create();
projectionBuffer = graphics->createUniformBuffer({
.sourceData = {
.size = sizeof(Matrix4),
.data = nullptr,
},
.sourceData =
{
.size = sizeof(Matrix4),
.data = nullptr,
},
.dynamic = true,
});
@@ -148,22 +148,17 @@ void TextPass::createRenderPass()
generalSet->updateBuffer(0, projectionBuffer);
generalSet->updateSampler(1, glyphSampler);
generalSet->writeChanges();
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(generalLayout);
pipelineLayout->addDescriptorLayout(textureArrayLayout);
pipelineLayout->addPushConstants({
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
.size = sizeof(TextData)});
pipelineLayout->addPushConstants(
{.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, .offset = 0, .size = sizeof(TextData)});
pipelineLayout->create();
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {renderTarget},
.depthAttachment = depthAttachment
};
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{.colorAttachments = {renderTarget}, .depthAttachment = depthAttachment};
renderPass = graphics->createRenderPass(std::move(layout), {}, viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
@@ -172,7 +167,8 @@ void TextPass::createRenderPass()
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.colorBlend.attachmentCount = 1;
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
pipelineInfo.colorBlend.blendAttachments[0].colorWriteMask = Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT | Gfx::SE_COLOR_COMPONENT_A_BIT;
pipelineInfo.colorBlend.blendAttachments[0].colorWriteMask =
Gfx::SE_COLOR_COMPONENT_R_BIT | Gfx::SE_COLOR_COMPONENT_G_BIT | Gfx::SE_COLOR_COMPONENT_B_BIT | Gfx::SE_COLOR_COMPONENT_A_BIT;
pipelineInfo.colorBlend.blendAttachments[0].srcColorBlendFactor = Gfx::SE_BLEND_FACTOR_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].dstColorBlendFactor = Gfx::SE_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
pipelineInfo.colorBlend.blendAttachments[0].alphaBlendOp = Gfx::SE_BLEND_OP_ADD;
@@ -183,19 +179,16 @@ void TextPass::createRenderPass()
pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
}
TextPass::FontData& TextPass::getFontData(PFontAsset font)
{
if(fontData.exists(font))
{
TextPass::FontData& TextPass::getFontData(PFontAsset font) {
if (fontData.exists(font)) {
return fontData[font];
}
}
const auto& fontGlyphs = font->getGlyphData();
FontData& fd = fontData[font];
Array<GlyphData> glyphData;
Array<Gfx::PTexture> textures;
glyphData.reserve(fontGlyphs.size());
for(const auto& [key, value] : fontGlyphs)
{
for (const auto& [key, value] : fontGlyphs) {
fd.characterToGlyphIndex[key] = static_cast<uint32>(glyphData.size());
GlyphData& gd = glyphData.add();
gd.bearing = value.bearing;
@@ -204,7 +197,7 @@ TextPass::FontData& TextPass::getFontData(PFontAsset font)
textures.add(font->getTexture(value.textureIndex));
}
fd.glyphDataSet = glyphData;
textureArrayLayout->reset();
fd.textureArraySet = textureArrayLayout->allocateDescriptorSet();
fd.textureArraySet->updateTextureArray(0, textures);
+14 -20
View File
@@ -1,24 +1,22 @@
#pragma once
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Asset/FontAsset.h"
#include "Graphics/Shader.h"
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
namespace Seele
{
namespace Seele {
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, ShaderBuffer)
struct TextRender
{
struct TextRender {
std::string text;
PFontAsset font;
Vector4 textColor;
Vector2 position;
float scale;
};
class TextPass : public RenderPass
{
public:
class TextPass : public RenderPass {
public:
TextPass(Gfx::PGraphics graphics, PScene scene);
TextPass(TextPass&&) = default;
TextPass& operator=(TextPass&&) = default;
@@ -28,26 +26,23 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
struct GlyphData
{
private:
struct GlyphData {
Vector2 bearing;
Vector2 size;
uint32 advance;
};
struct GlyphInstanceData
{
struct GlyphInstanceData {
Vector2 position;
Vector2 widthHeight;
uint32 glyphIndex;
};
struct TextData
{
struct TextData {
Vector4 textColor;
float scale;
};
struct FontData
{
struct FontData {
Gfx::PDescriptorSet textureArraySet;
Array<GlyphData> glyphDataSet;
Map<uint32, uint32> characterToGlyphIndex;
@@ -55,8 +50,7 @@ private:
FontData& getFontData(PFontAsset font);
Map<PFontAsset, FontData> fontData;
struct TextResources
{
struct TextResources {
Gfx::PShaderBuffer instanceBuffer;
Gfx::PDescriptorSet textureArraySet;
TextData textData;
+50 -55
View File
@@ -1,30 +1,21 @@
#include "UIPass.h"
#include "Graphics/Command.h"
#include "Graphics/Enums.h"
#include "RenderGraph.h"
#include "Graphics/Graphics.h"
#include "Graphics/RenderTarget.h"
#include "Graphics/Command.h"
#include "RenderGraph.h"
using namespace Seele;
UIPass::UIPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
UIPass::UIPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
UIPass::~UIPass()
{
}
UIPass::~UIPass() {}
void UIPass::beginFrame(const Component::Camera& cam)
{
void UIPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
VertexBufferCreateInfo info = {
.sourceData = {
.size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()),
.data = (uint8*)renderElements.data()
},
.sourceData = {.size = (uint32)(sizeof(UI::RenderElementStyle) * renderElements.size()), .data = (uint8*)renderElements.data()},
.vertexSize = sizeof(UI::RenderElementStyle),
.numVertices = (uint32)renderElements.size(),
};
@@ -37,11 +28,10 @@ void UIPass::beginFrame(const Component::Camera& cam)
descriptorSet->updateBuffer(2, numTexturesBuffer);
descriptorSet->updateTextureArray(3, usedTextures);
descriptorSet->writeChanges();
//co_return;
// co_return;
}
void UIPass::render()
{
void UIPass::render() {
graphics->beginRenderPass(renderPass);
Gfx::ORenderCommand command = graphics->createRenderCommand("UIPassCommand");
command->setViewport(viewport);
@@ -53,17 +43,15 @@ void UIPass::render()
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
//co_return;
// co_return;
}
void UIPass::endFrame()
{
//co_return;
void UIPass::endFrame() {
// co_return;
}
void UIPass::publishOutputs()
{
void UIPass::publishOutputs() {
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getWidth(),
@@ -72,10 +60,9 @@ void UIPass::publishOutputs()
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
TextureCreateInfo colorBufferInfo = {
@@ -85,16 +72,14 @@ void UIPass::publishOutputs()
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
};
colorBuffer = graphics->createTexture2D(colorBufferInfo);
renderTarget =
Gfx::RenderTargetAttachment(colorBuffer,
Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
renderTarget.clear.color = { {0.0f, 0.0f, 0.0f, 1.0f} };
renderTarget = Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR,
Gfx::SE_ATTACHMENT_STORE_OP_STORE);
renderTarget.clear.color = {{0.0f, 0.0f, 0.0f, 1.0f}};
resources->registerRenderPassOutput("UIPASS_COLOR", renderTarget);
}
void UIPass::createRenderPass()
{
void UIPass::createRenderPass() {
ShaderCreateInfo createInfo = {
.name = "UIVertex",
.mainModule = "UIPass",
@@ -103,32 +88,45 @@ void UIPass::createRenderPass()
vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "UIFragment";
createInfo.entryPoint = "fragmentMain";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
descriptorLayout = graphics->createDescriptorLayout("pParams");
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, .descriptorCount = 256, .bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY,
.descriptorCount = 256,
.bindingFlags = Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT,
});
descriptorLayout->create();
Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
UniformBufferCreateInfo info = {
.sourceData = {
.size = sizeof(Matrix4),
.data = (uint8*)&projectionMatrix,
},
.sourceData =
{
.size = sizeof(Matrix4),
.data = (uint8*)&projectionMatrix,
},
.dynamic = false,
};
Gfx::OUniformBuffer uniformBuffer = graphics->createUniformBuffer(info);
Gfx::OSampler backgroundSampler = graphics->createSampler({});
info = {
.sourceData = {
.size = sizeof(uint32),
.data = nullptr
},
.sourceData = {.size = sizeof(uint32), .data = nullptr},
.dynamic = true,
};
@@ -143,12 +141,9 @@ void UIPass::createRenderPass()
pipelineLayout->addDescriptorLayout(descriptorLayout);
pipelineLayout->create();
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { renderTarget },
.depthAttachment = depthAttachment
};
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{.colorAttachments = {renderTarget}, .depthAttachment = depthAttachment};
renderPass = graphics->createRenderPass(std::move(layout), {}, viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
+7 -7
View File
@@ -1,15 +1,14 @@
#pragma once
#include "Graphics/Shader.h"
#include "RenderPass.h"
#include "UI/RenderHierarchy.h"
#include "Graphics/Shader.h"
namespace Seele
{
namespace Seele {
DECLARE_NAME_REF(Gfx, Texture2D)
DECLARE_NAME_REF(Gfx, RenderTargetAttachment)
class UIPass : public RenderPass
{
public:
class UIPass : public RenderPass {
public:
UIPass(Gfx::PGraphics graphics, PScene scene);
UIPass(UIPass&&) = default;
UIPass& operator=(UIPass&&) = default;
@@ -19,7 +18,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
Gfx::RenderTargetAttachment renderTarget;
Gfx::OTexture2D colorBuffer;
Gfx::RenderTargetAttachment depthAttachment;
@@ -5,64 +5,44 @@ using namespace Seele;
extern bool resetVisibility;
VisibilityPass::VisibilityPass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
}
VisibilityPass::VisibilityPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
VisibilityPass::~VisibilityPass()
{
VisibilityPass::~VisibilityPass() {}
}
void VisibilityPass::beginFrame(const Component::Camera& cam)
{
void VisibilityPass::beginFrame(const Component::Camera& cam) {
RenderPass::beginFrame(cam);
cullingBuffer->rotateBuffer(VertexData::getMeshletCount() * sizeof(VertexData::MeshletCullingInfo), true);
if (resetVisibility)
{
if (resetVisibility) {
Array<VertexData::MeshletCullingInfo> cullingData(VertexData::getMeshletCount());
std::memset(cullingData.data(), 0xffff, cullingData.size() * sizeof(VertexData::MeshletCullingInfo));
cullingBuffer->updateContents(ShaderBufferCreateInfo{
.sourceData = {
.size = VertexData::getMeshletCount() * sizeof(VertexData::MeshletCullingInfo),
.data = (uint8 *)cullingData.data(),
},
.numElements = VertexData::getMeshletCount()});
cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
cullingBuffer->updateContents(
ShaderBufferCreateInfo{.sourceData =
{
.size = VertexData::getMeshletCount() * sizeof(VertexData::MeshletCullingInfo),
.data = (uint8*)cullingData.data(),
},
.numElements = VertexData::getMeshletCount()});
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
resetVisibility = false;
}
}
void VisibilityPass::render()
{
cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT,
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
void VisibilityPass::render() {
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT,
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
cullingBuffer->clear();
cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
visibilityDescriptor->reset();
visibilitySet = visibilityDescriptor->allocateDescriptorSet();
visibilitySet->updateTexture(0, visibilityAttachment.getTexture());
visibilitySet->updateBuffer(1, cullingBuffer);
visibilitySet->writeChanges();
Gfx::OComputeCommand command = graphics->createComputeCommand("VisibilityCommand");
command->bindPipeline(visibilityPipeline);
command->bindDescriptor({viewParamsSet, visibilitySet});
@@ -71,33 +51,33 @@ void VisibilityPass::render()
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT
);
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT);
}
void VisibilityPass::endFrame()
{
void VisibilityPass::endFrame() {}
}
void VisibilityPass::publishOutputs()
{
void VisibilityPass::publishOutputs() {
uint32_t viewportWidth = viewport->getWidth();
uint32_t viewportHeight = viewport->getHeight();
threadGroupSize = glm::ceil(glm::vec3(viewportWidth / (float)BLOCK_SIZE, viewportHeight / (float)BLOCK_SIZE, 1));
visibilityDescriptor = graphics->createDescriptorLayout("pVisibilityParams");
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, });
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT, });
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
visibilityDescriptor->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT,
});
visibilityDescriptor->create();
visibilityLayout = graphics->createPipelineLayout("VisibilityLayout");
visibilityLayout->addDescriptorLayout(viewParamsLayout);
visibilityLayout->addDescriptorLayout(visibilityDescriptor);
ShaderCreateInfo createInfo = {
.name = "Visibility",
.mainModule = "VisibilityCompute",
@@ -116,7 +96,4 @@ void VisibilityPass::publishOutputs()
resources->registerBufferOutput("CULLINGBUFFER", cullingBuffer);
}
void VisibilityPass::createRenderPass()
{
visibilityAttachment = resources->requestRenderTarget("VISIBILITY");
}
void VisibilityPass::createRenderPass() { visibilityAttachment = resources->requestRenderTarget("VISIBILITY"); }
@@ -1,11 +1,9 @@
#pragma once
#include "RenderPass.h"
namespace Seele
{
class VisibilityPass : public RenderPass
{
public:
namespace Seele {
class VisibilityPass : public RenderPass {
public:
VisibilityPass(Gfx::PGraphics graphics, PScene scene);
VisibilityPass(VisibilityPass&&) = default;
VisibilityPass& operator=(VisibilityPass&&) = default;
@@ -15,7 +13,8 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
private:
private:
static constexpr uint32 BLOCK_SIZE = 32;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::PDescriptorSet visibilitySet;
@@ -29,4 +28,4 @@ private:
glm::uvec3 threadGroupSize;
};
DEFINE_REF(VisibilityPass)
}
} // namespace Seele