Depth Culling works??

This commit is contained in:
Dynamitos
2024-06-11 14:15:29 +02:00
parent 2ba30a8fcc
commit 52c4f11d28
22 changed files with 264 additions and 92 deletions
+16 -25
View File
@@ -14,7 +14,6 @@
#include "RenderGraph.h"
#include "Window/Window.h"
using namespace Seele;
extern bool useViewCulling;
@@ -164,13 +163,10 @@ void BasePass::render() {
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
command->bindDescriptor(opaqueCulling);
for (const auto& drawCall : materialData.instances) {
command->bindDescriptor(drawCall.materialInstance->getDescriptorSet());
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(),
scene->getLightEnvironment()->getDescriptorSet(), drawCall.materialInstance->getDescriptorSet(),
opaqueCulling});
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading()) {
@@ -190,37 +186,32 @@ void BasePass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
// Sync color write with next pass/swapchain present
// 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(
// 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
//);
}
void BasePass::endFrame() {}
void BasePass::publishOutputs() {
TextureCreateInfo depthBufferInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.samples = viewport->getSamples(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
basePassDepth = graphics->createTexture2D(depthBufferInfo);
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);
depthAttachment =
Gfx::RenderTargetAttachment(basePassDepth, 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("BASEPASS_DEPTH", depthAttachment);
}
void BasePass::createRenderPass() {
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {colorAttachment},
.depthAttachment = depthAttachment,
@@ -28,6 +28,9 @@ class BasePass : public RenderPass {
Gfx::PDescriptorSet opaqueCulling;
Gfx::PDescriptorSet transparentCulling;
// use a different texture here so we can do multisampling
Gfx::OTexture2D basePassDepth;
PCameraActor source;
Gfx::OPipelineLayout basePassLayout;
Gfx::ODescriptorLayout lightCullingLayout;
@@ -6,8 +6,8 @@ target_sources(Engine
CachedDepthPass.cpp
DebugPass.h
DebugPass.cpp
DepthPrepass.h
DepthPrepass.cpp
DepthCullingPass.h
DepthCullingPass.cpp
LightCullingPass.h
LightCullingPass.cpp
RayTracingPass.h
@@ -32,7 +32,7 @@ target_sources(Engine
BasePass.h
CachedDepthPass.h
DebugPass.h
DepthPrepass.h
DepthCullingPass.h
LightCullingPass.h
RayTracingPass.h
RenderGraph.h
@@ -113,9 +113,7 @@ void CachedDepthPass::render() {
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), 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);
@@ -143,18 +141,6 @@ void CachedDepthPass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
// Sync depth read/write with depth pass depth read
// 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(
// 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() {}
+1 -1
View File
@@ -74,7 +74,7 @@ void DebugPass::createRenderPass() {
colorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
colorAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment = resources->requestRenderTarget("BASEPASS_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);
@@ -1,4 +1,4 @@
#include "DepthPrepass.h"
#include "DepthCullingPass.h"
#include "Graphics/Shader.h"
using namespace Seele;
@@ -6,9 +6,18 @@ using namespace Seele;
extern bool usePositionOnly;
extern bool useViewCulling;
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
DepthCullingPass::DepthCullingPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
depthTextureLayout = graphics->createDescriptorLayout("pDepthAttachment");
depthTextureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
.shaderStages = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
});
depthTextureLayout->create();
depthPrepassLayout = graphics->createPipelineLayout("DepthPrepassLayout");
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
depthPrepassLayout->addDescriptorLayout(depthTextureLayout);
depthPrepassLayout->addPushConstants(Gfx::SePushConstantRange{
.stageFlags = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
@@ -41,11 +50,32 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) : RenderPass(g
}
}
DepthPrepass::~DepthPrepass() {}
DepthCullingPass::~DepthCullingPass() {}
void DepthPrepass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
void DepthCullingPass::beginFrame(const Component::Camera& cam) { RenderPass::beginFrame(cam); }
void DepthCullingPass::render() {
depthAttachment.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, Gfx::SE_ACCESS_TRANSFER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
depthMipTexture->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
graphics->copyTexture(depthAttachment.getTexture(), Gfx::PTexture2D(depthMipTexture));
depthMipTexture->generateMipmaps();
depthAttachment.getTexture()->changeLayout(
Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthMipTexture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT);
Gfx::PDescriptorSet set = depthTextureLayout->allocateDescriptorSet();
set->updateTexture(0, Gfx::PTexture2D(depthMipTexture));
set->writeChanges();
void DepthPrepass::render() {
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
@@ -112,9 +142,7 @@ void DepthPrepass::render() {
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), set});
uint32 offset = 0;
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offset);
@@ -146,24 +174,24 @@ void DepthPrepass::render() {
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);
// Sync depth read/write with base pass read
// 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);
}
void DepthPrepass::endFrame() {}
void DepthCullingPass::endFrame() {}
void DepthPrepass::publishOutputs() {}
void DepthCullingPass::publishOutputs() {
uint32 width = viewport->getOwner()->getFramebufferWidth();
uint32 height = viewport->getOwner()->getFramebufferHeight();
uint32 mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
TextureCreateInfo depthMipInfo = {
.format = Gfx::SE_FORMAT_D32_SFLOAT, .width = width, .height = height, .mipLevels = mipLevels, .name = "DepthMipTexture"};
depthMipTexture = graphics->createTexture2D(depthMipInfo);
}
void DepthPrepass::createRenderPass() {
void DepthCullingPass::createRenderPass() {
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
@@ -3,12 +3,12 @@
#include "RenderPass.h"
namespace Seele {
class DepthPrepass : public RenderPass {
class DepthCullingPass : public RenderPass {
public:
DepthPrepass(Gfx::PGraphics graphics, PScene scene);
DepthPrepass(DepthPrepass&&) = default;
DepthPrepass& operator=(DepthPrepass&&) = default;
virtual ~DepthPrepass();
DepthCullingPass(Gfx::PGraphics graphics, PScene scene);
DepthCullingPass(DepthCullingPass&&) = default;
DepthCullingPass& operator=(DepthCullingPass&&) = default;
virtual ~DepthCullingPass();
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override;
virtual void endFrame() override;
@@ -16,11 +16,13 @@ class DepthPrepass : public RenderPass {
virtual void createRenderPass() override;
private:
Gfx::OTexture2D depthMipTexture;
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::ODescriptorLayout depthTextureLayout;
Gfx::OPipelineLayout depthPrepassLayout;
Gfx::PShaderBuffer cullingBuffer;
};
DEFINE_REF(DepthPrepass)
DEFINE_REF(DepthCullingPass)
} // namespace Seele