Files
Seele/src/Engine/Graphics/RenderPass/BasePass.cpp
T

631 lines
30 KiB
C++
Raw Normal View History

#include "BasePass.h"
2024-07-05 12:02:46 +02:00
#include "Asset/AssetRegistry.h"
2025-04-06 09:57:47 +02:00
#include "Asset/EnvironmentMapAsset.h"
2024-06-09 12:20:04 +02:00
#include "Component/Camera.h"
#include "Graphics/Command.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
#include "Graphics/Graphics.h"
#include "Graphics/Initializer.h"
2024-07-05 12:02:46 +02:00
#include "Graphics/Pipeline.h"
2023-11-05 10:36:01 +01:00
#include "Graphics/Shader.h"
2024-06-09 12:20:04 +02:00
#include "Material/MaterialInstance.h"
2025-02-28 16:56:51 +09:00
#include "Math/Matrix.h"
2021-01-19 15:30:00 +01:00
#include "Math/Vector.h"
2024-06-09 12:20:04 +02:00
using namespace Seele;
2024-07-05 12:02:46 +02:00
Array<DebugVertex> gDebugVertices;
void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
2025-01-08 19:15:12 +01:00
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics), scene(scene) {
2025-05-23 16:12:33 +02:00
// waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout);
2024-05-09 08:41:46 +02:00
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
basePassLayout->addDescriptorLayout(viewParamsLayout);
basePassLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
2024-06-18 19:19:05 +02:00
basePassLayout->addDescriptorLayout(Material::getDescriptorLayout());
2024-05-09 08:41:46 +02:00
lightCullingLayout = graphics->createDescriptorLayout("pLightCullingData");
2024-06-09 12:20:04 +02:00
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = LIGHTINDEX_NAME,
2024-06-09 12:20:04 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
lightCullingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = LIGHTGRID_NAME,
2024-06-09 12:20:04 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
2024-05-09 08:41:46 +02:00
lightCullingLayout->create();
basePassLayout->addDescriptorLayout(lightCullingLayout);
2024-05-12 19:36:32 +02:00
basePassLayout->addPushConstants(Gfx::SePushConstantRange{
2024-06-18 19:19:05 +02:00
.stageFlags = Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
2024-05-12 19:36:32 +02:00
.offset = 0,
.size = sizeof(VertexData::DrawCallOffsets),
2024-06-09 12:20:04 +02:00
});
2024-05-09 08:41:46 +02:00
2024-06-09 12:20:04 +02:00
if (graphics->supportMeshShading()) {
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig{
.baseLayout = basePassLayout,
.taskFile = "DrawListTask",
.mainFile = "DrawListMesh",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = true,
.hasTaskShader = true,
.useMaterial = true,
.useVisibility = false,
});
} else {
graphics->getShaderCompiler()->registerRenderPass("BasePass", Gfx::PassConfig{
.baseLayout = basePassLayout,
.taskFile = "",
.mainFile = "LegacyPass",
.fragmentFile = "BasePass",
.hasFragmentShader = true,
.useMeshShading = false,
.hasTaskShader = false,
.useMaterial = true,
.useVisibility = false,
});
2024-05-09 08:41:46 +02:00
}
2024-07-05 12:02:46 +02:00
skybox = Seele::Component::Skybox{
2025-07-09 23:25:03 +02:00
.day = scene->getLightEnvironment()->getEnvironmentMap()->getSkybox(),
.night = scene->getLightEnvironment()->getEnvironmentMap()->getSkybox(),
2025-05-12 22:48:01 +02:00
.fogColor = Vector(0, 0, 0),
2024-07-05 12:02:46 +02:00
.blendFactor = 0,
};
}
2024-06-09 12:20:04 +02:00
BasePass::~BasePass() {}
2023-10-24 15:01:09 +02:00
2025-04-11 23:13:19 +02:00
void BasePass::beginFrame(const Component::Camera& cam, const Component::Transform& transform) {
2025-05-06 19:36:43 +02:00
viewParamsSet = createViewParamsSet(cam, transform);
2020-10-03 11:00:10 +02:00
2025-04-11 23:13:19 +02:00
cameraPos = transform.getPosition();
cameraForward = transform.getForward();
2024-06-20 21:57:26 +02:00
2023-11-05 10:36:01 +01:00
lightCullingLayout->reset();
2024-02-21 10:30:04 +01:00
opaqueCulling = lightCullingLayout->allocateDescriptorSet();
transparentCulling = lightCullingLayout->allocateDescriptorSet();
2024-07-05 12:02:46 +02:00
2025-05-23 16:12:33 +02:00
// waterRenderer->beginFrame();
// terrainRenderer->beginFrame(viewParamsSet, cam);
2024-07-05 12:02:46 +02:00
2024-08-13 22:44:04 +02:00
// Debug vertices
{
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData =
{
.size = sizeof(DebugVertex) * gDebugVertices.size(),
.data = (uint8*)gDebugVertices.data(),
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)gDebugVertices.size(),
.name = "DebugVertices",
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
debugVertices->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT);
}
2024-07-05 12:02:46 +02:00
// Skybox
2024-08-13 22:44:04 +02:00
{
skyboxDataLayout->reset();
textureLayout->reset();
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
2025-05-23 16:12:33 +02:00
2024-08-13 22:44:04 +02:00
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
2025-02-28 16:56:51 +09:00
skyboxDataSet->updateConstants("transformMatrix", 0, &skyboxData.transformMatrix);
skyboxDataSet->updateConstants("fogBlend", 0, &skyboxData.fogColor);
2024-08-13 22:44:04 +02:00
skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(SKYBOXDAY_NAME, 0, skybox.day->getDefaultView());
textureSet->updateTexture(SKYBOXNIGHT_NAME, 0, skybox.night->getDefaultView());
2025-02-28 16:56:51 +09:00
textureSet->updateSampler(SKYBOXSAMPLER_NAME, 0, skyboxSampler);
2024-08-13 22:44:04 +02:00
textureSet->writeChanges();
}
2020-10-03 11:00:10 +02:00
}
2024-06-09 12:20:04 +02:00
void BasePass::render() {
2025-05-06 19:36:43 +02:00
graphics->beginDebugRegion("BasePass");
2025-03-09 22:42:05 +01:00
opaqueCulling->updateBuffer(LIGHTINDEX_NAME, 0, oLightIndexList);
opaqueCulling->updateTexture(LIGHTGRID_NAME, 0, oLightGrid->getDefaultView());
2025-03-09 22:42:05 +01:00
transparentCulling->updateBuffer(LIGHTINDEX_NAME, 0, tLightIndexList);
transparentCulling->updateTexture(LIGHTGRID_NAME, 0, tLightGrid->getDefaultView());
2024-02-21 10:30:04 +01:00
opaqueCulling->writeChanges();
transparentCulling->writeChanges();
2023-01-21 18:43:21 +01: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, "BaseBegin");
2023-11-10 22:26:47 +01:00
graphics->beginRenderPass(renderPass);
2024-06-20 21:57:26 +02:00
Array<VertexData::TransparentDraw> transparentData;
2025-05-06 19:36:43 +02:00
{
graphics->beginDebugRegion("Opaque");
2025-05-09 23:05:47 +02:00
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setDepthCulling(true); // always use the culling info
permutation.setPositionOnly(false);
2025-05-06 19:36:43 +02:00
// Base Rendering
for (VertexData* vertexData : VertexData::getList()) {
transparentData.addAll(vertexData->getTransparentData());
permutation.setVertexData(vertexData->getTypeName());
for (const auto& materialData : vertexData->getMaterialData()) {
// material not used for any active meshes, skip
if (materialData.instances.size() == 0)
continue;
// Create Pipeline(Material, VertexData)
// Descriptors:
// ViewData => global, static
// VertexData => per meshtype
// SceneData => per material instance
// LightEnv => provided by scene
// Material => per material
// LightCulling => calculated by pass
permutation.setMaterial(materialData.material->getName(), materialData.material->getProfile());
Gfx::PermutationId id(permutation);
2024-05-12 19:36:32 +02:00
2025-05-06 19:36:43 +02:00
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
command->setViewport(viewport);
2024-05-12 19:36:32 +02:00
2025-05-06 19:36:43 +02:00
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
2024-06-20 21:57:26 +02:00
//bool twoSided = materialData.material->isTwoSided();
2024-06-20 21:57:26 +02:00
2024-06-09 12:20:04 +02:00
if (graphics->supportMeshShading()) {
2025-05-06 19:36:43 +02:00
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState =
{
.samples = msColorAttachment.getNumSamples(),
},
.rasterizationState =
{
2025-06-30 21:15:14 +02:00
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
2025-05-06 19:36:43 +02:00
},
.colorBlend =
{
.attachmentCount = 1,
},
};
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
2024-06-09 12:20:04 +02:00
} else {
2025-05-06 19:36:43 +02:00
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState =
{
.samples = msColorAttachment.getNumSamples(),
},
.rasterizationState =
{
2025-06-30 21:15:14 +02:00
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
2025-05-06 19:36:43 +02:00
},
.colorBlend =
{
.attachmentCount = 1,
},
};
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
}
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(),
scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(), opaqueCulling});
for (const auto& drawCall : materialData.instances) {
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT |
Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
if (graphics->supportMeshShading()) {
command->drawMesh((uint32)drawCall.instanceMeshData.size(), 1, 1);
} else {
command->bindIndexBuffer(vertexData->getIndexBuffer());
for (const auto& meshData : drawCall.instanceMeshData) {
// all meshlets of a mesh share the same indices offset
command->drawIndexed(meshData.indicesRange.size, 1, meshData.indicesRange.offset,
vertexData->getIndicesOffset(meshData.meshletRange.offset), 0);
}
2024-05-22 10:30:45 +02:00
}
}
2025-05-06 19:36:43 +02:00
commands.add(std::move(command));
}
}
2025-05-09 23:05:47 +02:00
graphics->executeCommands(std::move(commands));
2025-05-06 19:36:43 +02:00
graphics->endDebugRegion();
2024-05-12 19:36:32 +02:00
}
2025-05-23 16:12:33 +02:00
// commands.add(waterRenderer->render(viewParamsSet));
// commands.add(terrainRenderer->render(viewParamsSet));
2024-08-13 22:44:04 +02:00
// Skybox
{
2025-05-06 19:36:43 +02:00
graphics->beginDebugRegion("Skybox");
2024-08-13 22:44:04 +02:00
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
skyboxCommand->setViewport(viewport);
2025-03-20 20:15:38 +01:00
skyboxCommand->bindPipeline(skyboxPipeline);
2024-08-13 22:44:04 +02:00
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
skyboxCommand->draw(36, 1, 0, 0);
graphics->executeCommands(std::move(skyboxCommand));
2025-05-06 19:36:43 +02:00
graphics->endDebugRegion();
2024-08-13 22:44:04 +02:00
}
2024-07-05 12:02:46 +02:00
// Transparent rendering
{
2025-05-06 19:36:43 +02:00
graphics->beginDebugRegion("Transparent");
2025-05-09 23:05:47 +02:00
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setPositionOnly(false);
2024-07-17 09:33:37 +02:00
permutation.setDepthCulling(false); // ignore visibility infos for transparency
2024-07-05 12:02:46 +02:00
Map<float, VertexData::TransparentDraw> sortedDraws;
for (const auto& t : transparentData) {
Vector toCenter = Vector(t.worldPosition) - cameraPos;
float dist = glm::length(toCenter) * glm::dot(glm::normalize(toCenter), cameraForward);
sortedDraws[dist] = t;
}
Gfx::ORenderCommand transparentCommand = graphics->createRenderCommand("TransparentDraw");
transparentCommand->setViewport(viewport);
for (const auto& [_, t] : sortedDraws) {
permutation.setVertexData(t.vertexData->getTypeName());
2025-01-30 23:25:41 +01:00
permutation.setMaterial(t.matInst->getBaseMaterial()->getName(), t.matInst->getBaseMaterial()->getProfile());
2024-07-05 12:02:46 +02:00
Gfx::PermutationId id(permutation);
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
assert(collection != nullptr);
//bool twoSided = t.matInst->getBaseMaterial()->isTwoSided();
2024-07-05 12:02:46 +02:00
if (graphics->supportMeshShading()) {
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = collection->taskShader,
.meshShader = collection->meshShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState =
{
2025-03-10 18:35:35 +01:00
.samples = msColorAttachment.getNumSamples(),
2024-07-05 12:02:46 +02:00
},
.rasterizationState =
{
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
2024-07-05 12:02:46 +02:00
},
.colorBlend =
{
.attachmentCount = 1,
.blendAttachments =
{
Gfx::ColorBlendState::BlendAttachment{
.blendEnable = true,
},
},
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
transparentCommand->bindPipeline(pipeline);
} else {
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
.vertexShader = collection->vertexShader,
.fragmentShader = collection->fragmentShader,
.renderPass = renderPass,
.pipelineLayout = collection->pipelineLayout,
.multisampleState =
{
2025-03-10 18:35:35 +01:00
.samples = msColorAttachment.getNumSamples(),
2024-07-05 12:02:46 +02:00
},
.rasterizationState =
{
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
2024-07-05 12:02:46 +02:00
},
.depthStencilState =
{
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER_OR_EQUAL,
},
.colorBlend =
{
.attachmentCount = 1,
.blendAttachments =
{
Gfx::ColorBlendState::BlendAttachment{
.blendEnable = true,
},
},
},
};
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
transparentCommand->bindPipeline(pipeline);
}
transparentCommand->bindDescriptor({viewParamsSet, t.vertexData->getVertexDataSet(), t.vertexData->getInstanceDataSet(),
scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(),
transparentCulling});
transparentCommand->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT |
Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
0, sizeof(VertexData::DrawCallOffsets), &t.offsets);
if (graphics->supportMeshShading()) {
2025-03-10 18:35:35 +01:00
transparentCommand->drawMesh(1, 1, 1);
2024-07-05 12:02:46 +02:00
} else {
// command->bindIndexBuffer(t.vertexData->getIndexBuffer());
// for (const auto& meshData : drawCall.instanceMeshData) {
// // all meshlets of a mesh share the same indices offset
// command->drawIndexed(meshData.numIndices, 1, meshData.firstIndex,
// vertexData->getIndicesOffset(meshData.meshletOffset), 0);
// }
}
}
2025-05-09 23:05:47 +02:00
graphics->executeCommands(std::move(transparentCommand));
2025-05-06 19:36:43 +02:00
graphics->endDebugRegion();
2024-06-20 21:57:26 +02:00
}
2024-07-05 12:02:46 +02:00
// Debug vertices
if (gDebugVertices.size() > 0) {
2025-05-06 19:36:43 +02:00
graphics->beginDebugRegion("Debug");
2025-05-09 23:05:47 +02:00
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setDepthCulling(true); // always use the culling info
permutation.setPositionOnly(false);
2024-07-05 12:02:46 +02:00
Gfx::ORenderCommand debugCommand = graphics->createRenderCommand("DebugRender");
debugCommand->setViewport(viewport);
debugCommand->bindPipeline(debugPipeline);
debugCommand->bindDescriptor(viewParamsSet);
debugCommand->bindVertexBuffer({debugVertices});
debugCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
2025-05-09 23:05:47 +02:00
graphics->executeCommands(std::move(debugCommand));
2025-05-06 19:36:43 +02:00
graphics->endDebugRegion();
2024-06-20 21:57:26 +02:00
}
graphics->endRenderPass();
2024-06-15 21:47:20 +02:00
query->endQuery();
2024-08-13 22:44:04 +02:00
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "BaseEnd");
2024-07-05 12:02:46 +02:00
gDebugVertices.clear();
2025-05-06 19:36:43 +02:00
graphics->endDebugRegion();
}
2020-10-03 11:00:10 +02:00
2024-06-09 12:20:04 +02:00
void BasePass::endFrame() {}
2021-05-06 17:02:10 +02:00
2024-06-09 12:20:04 +02:00
void BasePass::publishOutputs() {
2025-03-09 22:42:05 +01:00
basePassDepth = graphics->createTexture2D(TextureCreateInfo{
2024-06-11 14:15:29 +02:00
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
2025-03-09 22:42:05 +01:00
});
2024-06-11 14:15:29 +02:00
2025-03-09 22:42:05 +01:00
basePassColor = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
});
msBasePassDepth = graphics->createTexture2D(TextureCreateInfo{
2024-07-05 12:02:46 +02:00
.format = Gfx::SE_FORMAT_D32_SFLOAT,
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
2025-03-10 18:35:35 +01:00
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT,
2024-07-05 12:02:46 +02:00
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
2025-03-09 22:42:05 +01:00
});
2025-05-23 16:12:33 +02:00
2025-03-09 22:42:05 +01:00
msBasePassColor = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
2024-07-05 12:02:46 +02:00
.width = viewport->getOwner()->getFramebufferWidth(),
.height = viewport->getOwner()->getFramebufferHeight(),
2025-03-10 18:35:35 +01:00
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT, // todo: configure
2024-07-05 12:02:46 +02:00
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
2025-03-09 22:42:05 +01:00
});
2024-07-05 12:02:46 +02:00
depthAttachment = Gfx::RenderTargetAttachment(basePassDepth->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
2025-05-23 16:12:33 +02:00
Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
2024-07-05 12:02:46 +02:00
msDepthAttachment =
Gfx::RenderTargetAttachment(msBasePassDepth->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
2024-07-05 12:02:46 +02:00
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE);
2025-03-04 19:38:03 +09:00
msDepthAttachment.clear.depthStencil.depth = 0.0f;
2024-07-05 12:02:46 +02:00
2025-05-23 16:12:33 +02:00
colorAttachment =
Gfx::RenderTargetAttachment(basePassColor->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2025-05-23 16:12:33 +02:00
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
2024-07-05 12:02:46 +02:00
msColorAttachment =
Gfx::RenderTargetAttachment(msBasePassColor->getDefaultView(), Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2024-07-05 12:02:46 +02:00
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE);
2025-03-04 19:38:03 +09:00
msColorAttachment.clear.color.float32[0] = 0;
msColorAttachment.clear.color.float32[1] = 1;
msColorAttachment.clear.color.float32[2] = 0;
msColorAttachment.clear.color.float32[3] = 1;
2024-07-05 12:02:46 +02:00
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
2024-06-11 14:15:29 +02:00
resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment);
2024-06-15 21:47:20 +02:00
2024-08-13 22:44:04 +02:00
timestamps = graphics->createTimestampQuery(2, "BaseTS");
2024-07-01 12:17:04 +02:00
query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics");
2024-06-15 21:47:20 +02:00
resources->registerQueryOutput("BASEPASS_QUERY", query);
2021-05-06 17:02:10 +02:00
}
2024-06-09 12:20:04 +02:00
void BasePass::createRenderPass() {
2025-05-23 16:12:33 +02:00
// RenderPass::beginFrame(Component::Camera());
// terrainRenderer = new TerrainRenderer(graphics, scene, viewParamsLayout, viewParamsSet);
2024-06-07 09:19:47 +02:00
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
2024-09-03 11:03:23 +02:00
timestamps = resources->requestTimestampQuery("TIMESTAMPS");
2024-06-07 09:19:47 +02:00
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
2024-07-05 12:02:46 +02:00
.colorAttachments = {msColorAttachment},
.resolveAttachments = {colorAttachment},
.depthAttachment = msDepthAttachment,
.depthResolveAttachment = {depthAttachment},
2023-12-10 22:27:59 +01:00
};
Array<Gfx::SubPassDependency> dependency = {
{
.srcSubpass = ~0U,
.dstSubpass = 0,
2024-07-05 12:02:46 +02:00
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
2024-06-09 12:20:04 +02:00
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2024-02-01 15:00:13 +01:00
},
{
.srcSubpass = 0,
.dstSubpass = ~0U,
2024-07-05 12:02:46 +02:00
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
2024-06-09 12:20:04 +02:00
.srcAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
2024-02-01 15:00:13 +01:00
},
};
2025-04-12 17:40:14 +02:00
renderPass = graphics->createRenderPass(std::move(layout), std::move(dependency), viewport->getRenderArea(), "BasePass");
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");
2024-07-05 12:02:46 +02:00
2025-05-23 16:12:33 +02:00
// waterRenderer->setViewport(viewport, renderPass);
// terrainRenderer->setViewport(viewport, renderPass);
2024-08-13 22:44:04 +02:00
2024-07-05 12:02:46 +02:00
// Debug rendering
{
debugPipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
debugPipelineLayout->addDescriptorLayout(viewParamsLayout);
2024-07-10 21:07:10 +02:00
ShaderCompilationInfo createInfo = {
2024-07-05 12:02:46 +02:00
.name = "DebugVertex",
2024-07-10 21:07:10 +02:00
.modules = {"Debug"},
.entryPoints =
{
{"vertexMain", "Debug"},
{"fragmentMain", "Debug"},
},
2024-07-05 12:02:46 +02:00
.rootSignature = debugPipelineLayout,
};
2024-07-10 21:07:10 +02:00
graphics->beginShaderCompilation(createInfo);
debugVertexShader = graphics->createVertexShader({0});
debugFragmentShader = graphics->createFragmentShader({1});
2024-07-05 12:02:46 +02:00
debugPipelineLayout->create();
VertexInputStateCreateInfo inputCreate = {
.bindings =
{
VertexInputBinding{
.binding = 0,
.stride = sizeof(DebugVertex),
.inputRate = Gfx::SE_VERTEX_INPUT_RATE_VERTEX,
},
},
.attributes =
{
VertexInputAttribute{
.location = 0,
.binding = 0,
.format = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.offset = 0,
},
VertexInputAttribute{
.location = 1,
.binding = 0,
.format = Gfx::SE_FORMAT_R32G32B32_SFLOAT,
.offset = sizeof(Vector),
},
},
};
debugVertexInput = graphics->createVertexInput(inputCreate);
Gfx::LegacyPipelineCreateInfo gfxInfo = {
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST,
.vertexInput = debugVertexInput,
.vertexShader = debugVertexShader,
.fragmentShader = debugFragmentShader,
.renderPass = renderPass,
.pipelineLayout = debugPipelineLayout,
.multisampleState =
{
2025-03-10 18:35:35 +01:00
.samples = msColorAttachment.getNumSamples(),
2024-07-05 12:02:46 +02:00
},
.rasterizationState =
{
.polygonMode = Gfx::SE_POLYGON_MODE_LINE,
.lineWidth = 5.f,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
debugPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
}
// Skybox
{
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
2025-05-23 16:12:33 +02:00
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "transformMatrix", .uniformLength = sizeof(Matrix4)});
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{.name = "fogBlend", .uniformLength = sizeof(Vector4)});
2024-07-05 12:02:46 +02:00
skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = SKYBOXDAY_NAME,
2024-07-05 12:02:46 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2025-02-28 16:56:51 +09:00
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
2024-07-05 12:02:46 +02:00
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = SKYBOXNIGHT_NAME,
2024-07-05 12:02:46 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
2025-02-28 16:56:51 +09:00
.access = Gfx::SE_DESCRIPTOR_ACCESS_SAMPLE_BIT,
2024-07-05 12:02:46 +02:00
});
textureLayout->addDescriptorBinding(Gfx::DescriptorBinding{
2025-02-28 16:56:51 +09:00
.name = SKYBOXSAMPLER_NAME,
2024-07-05 12:02:46 +02:00
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
textureLayout->create();
skyboxSampler = graphics->createSampler({});
skyboxData.transformMatrix = Matrix4(1);
skyboxData.fogColor = skybox.fogColor;
skyboxData.blendFactor = skybox.blendFactor;
pipelineLayout = graphics->createPipelineLayout("SkyboxLayout");
pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
pipelineLayout->addDescriptorLayout(textureLayout);
2024-07-10 21:07:10 +02:00
ShaderCompilationInfo createInfo = {
2024-07-05 12:02:46 +02:00
.name = "SkyboxVertex",
2024-07-10 21:07:10 +02:00
.modules = {"Skybox"},
.entryPoints = {{"vertexMain", "Skybox"}, {"fragmentMain", "Skybox"}},
2024-07-05 12:02:46 +02:00
.rootSignature = pipelineLayout,
};
2024-07-10 21:07:10 +02:00
graphics->beginShaderCompilation(createInfo);
vertexShader = graphics->createVertexShader({0});
fragmentShader = graphics->createFragmentShader({1});
2024-07-05 12:02:46 +02:00
pipelineLayout->create();
Gfx::LegacyPipelineCreateInfo gfxInfo = {
.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.vertexShader = vertexShader,
.fragmentShader = fragmentShader,
.renderPass = renderPass,
.pipelineLayout = pipelineLayout,
.multisampleState =
{
2025-03-10 18:35:35 +01:00
.samples = msColorAttachment.getNumSamples(),
2024-07-05 12:02:46 +02:00
},
.rasterizationState =
{
.polygonMode = Gfx::SE_POLYGON_MODE_FILL,
},
.colorBlend =
{
.attachmentCount = 1,
},
};
2025-03-20 20:15:38 +01:00
skyboxPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
2024-07-05 12:02:46 +02:00
}
2021-05-06 17:02:10 +02:00
}