2024-06-04 21:34:14 +02:00
|
|
|
#include "VisibilityPass.h"
|
2024-06-07 09:19:47 +02:00
|
|
|
#include "Graphics/Shader.h"
|
2024-06-04 21:34:14 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
VisibilityPass::VisibilityPass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {}
|
2024-06-04 21:34:14 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
VisibilityPass::~VisibilityPass() {}
|
2024-06-04 21:34:14 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
void VisibilityPass::beginFrame(const Component::Camera& cam) {
|
2024-06-04 21:34:14 +02:00
|
|
|
RenderPass::beginFrame(cam);
|
2024-06-19 10:33:19 +02:00
|
|
|
cullingBuffer->rotateBuffer(VertexData::getMeshletCount() * sizeof(VertexData::MeshletCullingInfo), true);
|
2024-06-04 21:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
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);
|
2024-06-07 09:19:47 +02:00
|
|
|
cullingBuffer->clear();
|
2024-06-10 10:13:37 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
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);
|
2024-06-07 09:19:47 +02:00
|
|
|
visibilityDescriptor->reset();
|
|
|
|
|
visibilitySet = visibilityDescriptor->allocateDescriptorSet();
|
2024-09-27 15:57:37 +02:00
|
|
|
visibilitySet->updateTexture(0, 0, visibilityAttachment.getTexture());
|
|
|
|
|
visibilitySet->updateBuffer(1, 0, cullingBuffer);
|
2024-06-07 09:19:47 +02:00
|
|
|
visibilitySet->writeChanges();
|
2024-06-09 12:20:04 +02:00
|
|
|
|
2024-06-15 21:47:20 +02:00
|
|
|
query->beginQuery();
|
2024-08-13 22:44:04 +02:00
|
|
|
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "VisibilityBegin");
|
2024-06-07 09:19:47 +02:00
|
|
|
Gfx::OComputeCommand command = graphics->createComputeCommand("VisibilityCommand");
|
|
|
|
|
command->bindPipeline(visibilityPipeline);
|
|
|
|
|
command->bindDescriptor({viewParamsSet, visibilitySet});
|
2024-06-07 18:43:10 +02:00
|
|
|
command->dispatch(threadGroupSize.x, threadGroupSize.y, threadGroupSize.z);
|
2024-06-07 09:19:47 +02:00
|
|
|
Array<Gfx::OComputeCommand> commands;
|
|
|
|
|
commands.add(std::move(command));
|
|
|
|
|
graphics->executeCommands(std::move(commands));
|
2024-08-13 22:44:04 +02:00
|
|
|
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "VisibilityEnd");
|
2024-06-15 21:47:20 +02:00
|
|
|
query->endQuery();
|
2024-06-09 12:20:04 +02:00
|
|
|
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);
|
2024-06-04 21:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
void VisibilityPass::endFrame() {}
|
2024-06-04 21:34:14 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
void VisibilityPass::publishOutputs() {
|
2024-06-07 09:19:47 +02:00
|
|
|
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");
|
2024-06-09 12:20:04 +02:00
|
|
|
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,
|
|
|
|
|
});
|
2024-06-04 21:34:14 +02:00
|
|
|
visibilityDescriptor->create();
|
|
|
|
|
|
|
|
|
|
visibilityLayout = graphics->createPipelineLayout("VisibilityLayout");
|
|
|
|
|
visibilityLayout->addDescriptorLayout(visibilityDescriptor);
|
2024-07-10 21:07:10 +02:00
|
|
|
visibilityLayout->addDescriptorLayout(viewParamsLayout);
|
2024-06-09 12:20:04 +02:00
|
|
|
|
2024-07-10 21:07:10 +02:00
|
|
|
ShaderCompilationInfo createInfo = {
|
2024-06-04 21:34:14 +02:00
|
|
|
.name = "Visibility",
|
2024-07-10 21:07:10 +02:00
|
|
|
.modules = {"VisibilityCompute"},
|
|
|
|
|
.entryPoints = {{"computeMain", "VisibilityCompute"}},
|
2024-06-04 21:34:14 +02:00
|
|
|
.rootSignature = visibilityLayout,
|
|
|
|
|
};
|
2024-07-10 21:07:10 +02:00
|
|
|
graphics->beginShaderCompilation(createInfo);
|
|
|
|
|
visibilityShader = graphics->createComputeShader({0});
|
2024-06-04 21:34:14 +02:00
|
|
|
visibilityLayout->create();
|
|
|
|
|
|
|
|
|
|
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
|
|
|
|
pipelineInfo.computeShader = visibilityShader;
|
2024-07-10 21:07:10 +02:00
|
|
|
pipelineInfo.pipelineLayout = visibilityLayout;
|
2024-06-04 21:34:14 +02:00
|
|
|
visibilityPipeline = graphics->createComputePipeline(std::move(pipelineInfo));
|
2024-06-07 09:19:47 +02:00
|
|
|
|
2024-06-19 10:33:19 +02:00
|
|
|
cullingBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
|
|
|
|
.clearValue = 0xffffffff,
|
|
|
|
|
.name = "CullingBuffer",
|
|
|
|
|
});
|
2024-06-07 09:19:47 +02:00
|
|
|
resources->registerBufferOutput("CULLINGBUFFER", cullingBuffer);
|
2024-06-15 21:47:20 +02:00
|
|
|
|
2024-07-01 12:17:04 +02:00
|
|
|
query = graphics->createPipelineStatisticsQuery("VisibilityPipelineStatistics");
|
2024-06-15 21:47:20 +02:00
|
|
|
resources->registerQueryOutput("VISIBILITY_QUERY", query);
|
2024-06-04 21:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 11:03:23 +02:00
|
|
|
void VisibilityPass::createRenderPass() {
|
|
|
|
|
visibilityAttachment = resources->requestRenderTarget("VISIBILITY");
|
|
|
|
|
timestamps = resources->requestTimestampQuery("TIMESTAMPS");
|
|
|
|
|
}
|