2020-08-06 00:54:43 +02:00
|
|
|
#include "BasePass.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
2023-11-05 10:36:01 +01:00
|
|
|
#include "Graphics/Shader.h"
|
2021-01-19 15:30:00 +01:00
|
|
|
#include "Window/Window.h"
|
2022-11-17 16:47:42 +01:00
|
|
|
#include "Component/Camera.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
#include "Component/Mesh.h"
|
2022-11-17 16:47:42 +01:00
|
|
|
#include "Actor/CameraActor.h"
|
2021-01-19 15:30:00 +01:00
|
|
|
#include "Math/Vector.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
#include "RenderGraph.h"
|
2023-01-21 18:43:21 +01:00
|
|
|
#include "Material/MaterialInstance.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
2020-08-06 00:54:43 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
|
|
|
|
: RenderPass(graphics, scene)
|
2023-11-05 10:36:01 +01:00
|
|
|
, descriptorSets(6)
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2020-10-03 11:00:10 +02:00
|
|
|
basePassLayout = graphics->createPipelineLayout();
|
|
|
|
|
|
2023-11-05 10:36:01 +01:00
|
|
|
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
|
|
|
|
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2023-11-05 10:36:01 +01:00
|
|
|
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
|
|
|
|
|
// oLightIndexList
|
|
|
|
|
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
// tLightIndexList
|
|
|
|
|
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
|
|
|
// oLightGrid
|
|
|
|
|
lightCullingLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
|
|
|
|
|
// tLightGrid
|
|
|
|
|
lightCullingLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
|
|
|
|
|
lightCullingLayout->create();
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2023-11-05 10:36:01 +01:00
|
|
|
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
|
2020-08-06 00:54:43 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-03 11:00:10 +02:00
|
|
|
BasePass::~BasePass()
|
2023-10-24 15:01:09 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 16:47:42 +01:00
|
|
|
void BasePass::beginFrame(const Component::Camera& cam)
|
2020-10-03 11:00:10 +02:00
|
|
|
{
|
2023-11-05 10:36:01 +01:00
|
|
|
RenderPass::beginFrame(cam);
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2023-11-05 10:36:01 +01:00
|
|
|
lightCullingLayout->reset();
|
|
|
|
|
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
|
|
|
|
|
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
|
|
|
|
|
descriptorSets[INDEX_LIGHT_CULLING] = lightCullingLayout->allocateDescriptorSet();
|
2020-10-03 11:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void BasePass::render()
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2023-11-05 10:36:01 +01:00
|
|
|
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);
|
2021-06-04 18:27:49 +02:00
|
|
|
|
2023-11-05 10:36:01 +01:00
|
|
|
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(0, oLightIndexList);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(1, tLightIndexList);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(2, oLightGrid);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(3, tLightGrid);
|
|
|
|
|
descriptorSets[INDEX_LIGHT_CULLING]->writeChanges();
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2020-08-06 00:54:43 +02:00
|
|
|
graphics->beginRenderPass(renderPass);
|
2023-11-05 10:36:01 +01:00
|
|
|
Gfx::ShaderPermutation permutation;
|
|
|
|
|
permutation.hasFragment = true;
|
|
|
|
|
permutation.useMeshShading = true;
|
|
|
|
|
permutation.hasTaskShader = true;
|
|
|
|
|
std::memcpy(permutation.taskFile, "MeshletBasePass", std::strlen("MeshletBasePass"));
|
|
|
|
|
std::memcpy(permutation.vertexMeshFile, "MeshletBasePass", std::strlen("MeshletBasePass"));
|
|
|
|
|
std::memcpy(permutation.fragmentFile, "BasePass", std::strlen("BasePass"));
|
|
|
|
|
for (VertexData* vertexData : VertexData::getList())
|
2020-08-06 00:54:43 +02:00
|
|
|
{
|
2023-11-05 10:36:01 +01:00
|
|
|
std::memcpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), std::strlen(vertexData->getTypeName().c_str()));
|
|
|
|
|
const auto& materials = vertexData->getMaterialData();
|
|
|
|
|
for (const auto& [_, materialData] : materials)
|
|
|
|
|
{
|
|
|
|
|
// Create Pipeline(Material, VertexData)
|
|
|
|
|
// Descriptors:
|
|
|
|
|
// ViewData => global, static
|
|
|
|
|
// LightEnv => global, static
|
|
|
|
|
// LightCulling => global, static
|
|
|
|
|
// Material => per material
|
|
|
|
|
// VertexData => per meshtype
|
|
|
|
|
// SceneData => per material instance
|
|
|
|
|
|
|
|
|
|
std::memcpy(permutation.materialName, materialData.material->getName().c_str(), std::strlen(materialData.material->getName().c_str()));
|
|
|
|
|
Gfx::PermutationId id(permutation);
|
|
|
|
|
|
|
|
|
|
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
|
|
|
|
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout);
|
|
|
|
|
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
|
|
|
|
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
|
|
|
|
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
|
|
|
|
|
layout->create();
|
|
|
|
|
|
|
|
|
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
|
|
|
|
assert(collection != nullptr);
|
|
|
|
|
Gfx::MeshPipelineCreateInfo pipelineInfo;
|
|
|
|
|
pipelineInfo.taskShader = collection->taskShader;
|
|
|
|
|
pipelineInfo.meshShader = collection->meshShader;
|
|
|
|
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
|
|
|
|
pipelineInfo.pipelineLayout = layout;
|
|
|
|
|
pipelineInfo.renderPass = renderPass;
|
|
|
|
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
|
|
|
|
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(pipelineInfo);
|
|
|
|
|
command->bindPipeline(pipeline);
|
|
|
|
|
|
|
|
|
|
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
|
|
|
|
|
for (const auto& [_, instance] : materialData.instances)
|
|
|
|
|
{
|
|
|
|
|
descriptorSets[INDEX_MATERIAL] = instance.materialInstance->getDescriptorSet();
|
|
|
|
|
descriptorSets[INDEX_SCENE_DATA] = instance.descriptorSet;
|
|
|
|
|
command->bindDescriptor(descriptorSets);
|
|
|
|
|
command->dispatch(instance.numMeshes, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 12:10:23 +01:00
|
|
|
}
|
2020-08-06 00:54:43 +02:00
|
|
|
graphics->endRenderPass();
|
|
|
|
|
}
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2022-04-15 23:45:44 +02:00
|
|
|
void BasePass::endFrame()
|
2020-10-03 11:00:10 +02:00
|
|
|
{
|
|
|
|
|
}
|
2021-05-06 17:02:10 +02:00
|
|
|
|
|
|
|
|
void BasePass::publishOutputs()
|
|
|
|
|
{
|
2021-06-12 18:51:29 +02:00
|
|
|
colorAttachment = new Gfx::SwapchainAttachment(viewport->getOwner());
|
2021-10-01 19:55:04 +02:00
|
|
|
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BasePass::createRenderPass()
|
2023-03-09 17:39:57 +01:00
|
|
|
{
|
2021-10-01 19:55:04 +02:00
|
|
|
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
2021-05-06 17:02:10 +02:00
|
|
|
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
|
2022-11-17 16:47:42 +01:00
|
|
|
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR;
|
|
|
|
|
colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE;
|
2023-11-05 10:36:01 +01:00
|
|
|
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
|
|
|
|
|
renderPass = graphics->createRenderPass(std::move(layout), viewport);
|
2021-10-01 19:55:04 +02:00
|
|
|
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
|
2023-11-05 10:36:01 +01:00
|
|
|
tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST");
|
2021-10-01 19:55:04 +02:00
|
|
|
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
2023-11-05 10:36:01 +01:00
|
|
|
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
|
2021-05-06 17:02:10 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-06 14:47:21 +01:00
|
|
|
void BasePass::modifyRenderPassMacros(Map<const char*, const char*>&)
|
2021-05-06 17:02:10 +02:00
|
|
|
{
|
|
|
|
|
}
|