Working on visibility pass

This commit is contained in:
Dynamitos
2024-06-07 09:19:47 +02:00
parent ad00e16cf9
commit cb21e8a85a
24 changed files with 450 additions and 373 deletions
+6 -15
View File
@@ -85,19 +85,6 @@ void BasePass::beginFrame(const Component::Camera& cam)
void BasePass::render()
{
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
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);
opaqueCulling->updateBuffer(0, oLightIndexList);
opaqueCulling->updateTexture(1, oLightGrid);
transparentCulling->updateBuffer(0, tLightIndexList);
@@ -112,6 +99,8 @@ void BasePass::render()
permutation.setViewCulling(useViewCulling);
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)
@@ -176,11 +165,11 @@ void BasePass::render()
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(vertexData->getInstanceDataSet());
command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
command->bindDescriptor(opaqueCulling);
command->bindDescriptor(vertexData->getInstanceDataSet());
for (const auto& drawCall : materialData.instances)
{
command->bindDescriptor(drawCall.materialInstance->getDescriptorSet());
@@ -221,6 +210,8 @@ void BasePass::publishOutputs()
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);
@@ -32,6 +32,8 @@ private:
PCameraActor source;
Gfx::OPipelineLayout basePassLayout;
Gfx::ODescriptorLayout lightCullingLayout;
Gfx::PShaderBuffer cullingBuffer;
};
DEFINE_REF(BasePass)
} // namespace Seele
@@ -66,6 +66,8 @@ void CachedDepthPass::render()
for (VertexData *vertexData : VertexData::getList())
{
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
// Create Pipeline(VertexData)
// Descriptors:
@@ -120,8 +122,8 @@ void CachedDepthPass::render()
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet);
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);
@@ -205,6 +207,8 @@ void CachedDepthPass::publishOutputs()
void CachedDepthPass::createRenderPass()
{
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {visibilityAttachment},
.depthAttachment = depthAttachment,
@@ -21,6 +21,8 @@ private:
Gfx::OTexture2D depthBuffer;
Gfx::OTexture2D visibilityBuffer;
Gfx::OPipelineLayout depthPrepassLayout;
Gfx::PShaderBuffer cullingBuffer;
};
DEFINE_REF(CachedDepthPass)
}
@@ -66,6 +66,8 @@ void DepthPrepass::render()
for (VertexData *vertexData : VertexData::getList())
{
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
// Create Pipeline(VertexData)
// Descriptors:
// ViewData => global, static
@@ -119,14 +121,14 @@ void DepthPrepass::render()
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(vertexData->getVertexDataSet());
command->bindDescriptor(viewParamsSet);
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->drawMesh(vertexData->getNumInstances(), 1, 1);
command->drawMesh(vertexData->getNumInstances(), 1, 1);
}
else
{
@@ -174,6 +176,13 @@ void DepthPrepass::render()
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
// Sync culling reads to compute write
cullingBuffer->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
}
void DepthPrepass::endFrame()
@@ -186,13 +195,15 @@ void DepthPrepass::publishOutputs()
void DepthPrepass::createRenderPass()
{
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
visibilityAttachment = resources->requestRenderTarget("VISIBILITY");
visibilityAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
visibilityAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
visibilityAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
visibilityAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
@@ -20,6 +20,8 @@ private:
Gfx::RenderTargetAttachment depthAttachment;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::OPipelineLayout depthPrepassLayout;
Gfx::PShaderBuffer cullingBuffer;
};
DEFINE_REF(DepthPrepass)
} // namespace Seele
@@ -81,6 +81,19 @@ void LightCullingPass::render()
commands.add(std::move(computeCommand));
//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);
}
void LightCullingPass::endFrame()
@@ -1,4 +1,5 @@
#include "VisibilityPass.h"
#include "Graphics/Shader.h"
using namespace Seele;
@@ -15,15 +16,46 @@ VisibilityPass::~VisibilityPass()
void VisibilityPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
visibilityDescriptor->reset();
visibilitySet = visibilityDescriptor->allocateDescriptorSet();
visibilitySet->updateTexture(0, visibilityAttachment->getTexture());
visibliitySet->updateBuffer(StaticMeshVertexData::getInstance()->get)
//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);
}
void VisibilityPass::render()
{
cullingBuffer->rotateBuffer(VertexData::getMeshletCount() * sizeof(VertexData::MeshletCullingInfo));
cullingBuffer->clear();
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});
command->dispatch(threadGroupSize.x, threadGroupSize.y, threadGroupSize.z);
Array<Gfx::OComputeCommand> commands;
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);
}
void VisibilityPass::endFrame()
@@ -32,8 +64,11 @@ void VisibilityPass::endFrame()
}
void VisibilityPass::publishOutputs()
{
visibilityDescriptor = graphcis->createDescriptorLayout("pVisibilityParams");
{
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->create();
@@ -55,6 +90,9 @@ void VisibilityPass::publishOutputs()
pipelineInfo.computeShader = visibilityShader;
pipelineInfo.pipelineLayout = std::move(visibilityLayout);
visibilityPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.dynamic = true, .name = "CullingBuffer"});
resources->registerBufferOutput("CULLINGBUFFER", cullingBuffer);
}
void VisibilityPass::createRenderPass()
@@ -15,16 +15,18 @@ public:
virtual void endFrame() override;
virtual void publishOutputs() override;
virtual void createRenderPass() override;
uint64 allocate
private:
static constexpr uint32 BLOCK_SIZE = 32;
Gfx::RenderTargetAttachment visibilityAttachment;
Gfx::PDescriptorSet visibilitySet;
Gfx::ODescriptorLayout visibilityDescriptor;
Gfx::OPipelineLayout visibilityLayout;
Gfx::OComputeShader visibilityShader;
Gfx::PComputePipeline visibilityPipeline;
// Holds culling information for every meshlet for each instance
Gfx::OShaderBuffer cullingBuffer;
glm::uvec3 threadGroupSize;
};
DEFINE_REF(VisibilityPass)
}