Staging before meshlet linearization

This commit is contained in:
Dynamitos committed 2024-05-09 08:41:46 +02:00
1 parent 46a2713729
commit 7fc7ba56d4
33 files changed
+888 -709

No files matched your search

@@ -7,11 +7,16 @@ using namespace Seele;
StaticDepthPrepass::StaticDepthPrepass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
{
meshletCullingLayout = graphics->createDescriptorLayout("pCullingList");
meshletCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, });
meshletCullingLayout->create();
depthPrepassLayout = graphics->createPipelineLayout("DepthPrepassLayout");
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
depthPrepassLayout->addDescriptorLayout(meshletCullingLayout);
if (graphics->supportMeshShading())
{
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true, true, "MeshletPass");
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true);
}
else
{
@@ -30,82 +35,95 @@ void StaticDepthPrepass::beginFrame(const Component::Camera& cam)
void StaticDepthPrepass::render()
{
// Static Meshes
Array<Gfx::ORenderCommand> commands;
graphics->beginRenderPass(renderPass);
Gfx::ShaderPermutation permutation;
if (graphics->supportMeshShading())
{
Gfx::ShaderPermutation permutation;
permutation.setTaskFile("StaticMeshletPass");
permutation.setMeshFile("StaticMeshletPass");
}
else
{
permutation.setVertexFile("LegacyPass");
}
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
permutation.setVertexData(vd->getTypeName());
meshletCullingLayout->reset();
for (size_t i = 0; i < vd->getStaticMeshes().size(); ++i)
{
const auto& mesh = vd->getStaticMeshes()[i];
Gfx::PermutationId id(permutation);
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
permutation.setTaskFile("StaticMeshletPass");
permutation.setMeshFile("StaticMeshletPass");
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,
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
permutation.setVertexFile("LegacyPass");
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
permutation.setVertexData(vd->getTypeName());
for (const auto& [_, mappings] : vd->)
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vd->getVertexDataSet());
command->bindDescriptor(vd->getInstanceDataSet(), { 0, 0 });
for (const auto& instance : mesh.staticInstance)
{
permutation.setMaterial(mapping.material->getBaseMaterial()->getName());
Gfx::PermutationId id(permutation);
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
command->setViewport(viewport);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
if (graphics->supportMeshShading())
{
Gfx::MeshPipelineCreateInfo pipelineInfo;
pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
else
{
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
command->bindDescriptor(viewParamsSet);
command->bindDescriptor(vd->getVertexDataSet());
command->bindDescriptor(vd->getInstanceDataSet(), { 0, 0 });
if (graphics->supportMeshShading())
{
command->drawMesh(vd->getMeshData(mapping.mapped).size(), 1, 1);
}
else
{
command->bindIndexBuffer(vd->getIndexBuffer());
uint32 instanceOffset = 0;
for (const auto& meshData : vd->getMeshData(mapping.mapped))
{
if (meshData.numIndices > 0)
{
command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
}
instanceOffset++;
}
}
commands.add(std::move(command));
Gfx::PDescriptorSet cullingSet = meshletCullingLayout->allocateDescriptorSet();
cullingSet->updateBuffer(0, instance.culledMeshletBuffer);
cullingSet->writeChanges();
command->bindDescriptor(cullingSet);
if (graphics->supportMeshShading())
{
command->drawMesh(instance.meshletIds.size(), 1, 1);
}
else
{
//command->bindIndexBuffer(vd->getIndexBuffer());
//uint32 instanceOffset = 0;
//for (const auto& meshData : vd->getMeshData(mapping.mapped))
//{
// if (meshData.numIndices > 0)
// {
// command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex, meshData.indicesOffset, instanceOffset);
// }
// instanceOffset++;
//}
}
}
commands.add(std::move(command));
}
graphics->endRenderPass();
}
void StaticDepthPrepass::endFrame()
@@ -125,7 +143,7 @@ void StaticDepthPrepass::publishOutputs()
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_GENERAL,
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);
}
@@ -144,14 +162,6 @@ void StaticDepthPrepass::createRenderPass()
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = 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_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
.srcAccess = Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_SHADER_READ_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,