2023-01-21 18:43:21 +01:00
|
|
|
#include "DebugPass.h"
|
|
|
|
|
#include "Graphics/Graphics.h"
|
2023-10-26 18:37:29 +02:00
|
|
|
#include "Graphics/RenderTarget.h"
|
2024-01-16 19:24:49 +01:00
|
|
|
#include "Graphics/Pipeline.h"
|
|
|
|
|
#include "Graphics/Shader.h"
|
2023-01-21 18:43:21 +01:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
|
2023-08-26 15:19:12 +02:00
|
|
|
Array<DebugVertex> gDebugVertices;
|
|
|
|
|
|
|
|
|
|
void Seele::addDebugVertex(DebugVertex vert)
|
|
|
|
|
{
|
|
|
|
|
gDebugVertices.add(vert);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Seele::addDebugVertices(Array<DebugVertex> verts)
|
|
|
|
|
{
|
|
|
|
|
gDebugVertices.addAll(verts);
|
|
|
|
|
}
|
2023-01-21 18:43:21 +01:00
|
|
|
|
2024-01-11 21:40:46 +01:00
|
|
|
DebugPass::DebugPass(Gfx::PGraphics graphics, PScene scene)
|
|
|
|
|
: RenderPass(graphics, scene)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-26 09:58:01 +01:00
|
|
|
|
2024-01-11 21:40:46 +01:00
|
|
|
DebugPass::~DebugPass()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugPass::beginFrame(const Component::Camera& cam)
|
|
|
|
|
{
|
|
|
|
|
RenderPass::beginFrame(cam);
|
|
|
|
|
|
|
|
|
|
VertexBufferCreateInfo vertexBufferInfo = {
|
|
|
|
|
.sourceData = {
|
|
|
|
|
.size = sizeof(DebugVertex) * gDebugVertices.size(),
|
|
|
|
|
.data = (uint8*)gDebugVertices.data(),
|
|
|
|
|
},
|
|
|
|
|
.vertexSize = sizeof(DebugVertex),
|
|
|
|
|
.numVertices = (uint32)gDebugVertices.size(),
|
|
|
|
|
};
|
|
|
|
|
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugPass::render()
|
|
|
|
|
{
|
|
|
|
|
graphics->beginRenderPass(renderPass);
|
|
|
|
|
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
|
|
|
|
|
renderCommand->setViewport(viewport);
|
|
|
|
|
renderCommand->bindPipeline(pipeline);
|
2024-01-26 09:58:01 +01:00
|
|
|
renderCommand->bindDescriptor(viewParamsSet);
|
2024-01-11 21:40:46 +01:00
|
|
|
renderCommand->bindVertexBuffer({ debugVertices });
|
|
|
|
|
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
|
|
|
|
graphics->executeCommands(Array{renderCommand});
|
|
|
|
|
graphics->endRenderPass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugPass::endFrame()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugPass::publishOutputs()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugPass::createRenderPass()
|
|
|
|
|
{
|
|
|
|
|
Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
|
2024-01-31 09:49:53 +01:00
|
|
|
baseColorAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
|
baseColorAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
2024-01-11 21:40:46 +01:00
|
|
|
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
2024-01-31 09:49:53 +01:00
|
|
|
depthAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
|
|
|
|
|
depthAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
|
|
|
|
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
2024-01-11 21:40:46 +01:00
|
|
|
.colorAttachments = {baseColorAttachment},
|
|
|
|
|
.depthAttachment = depthAttachment,
|
|
|
|
|
};
|
2024-01-31 09:49:53 +01:00
|
|
|
|
|
|
|
|
Gfx::SubPassDependency dependency = {
|
|
|
|
|
.srcSubpass = ~0U,
|
|
|
|
|
.dstSubpass = 0,
|
|
|
|
|
.srcStage = Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.dstStage = Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
|
|
|
|
|
.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,
|
|
|
|
|
};
|
|
|
|
|
renderPass = graphics->createRenderPass(std::move(layout), {dependency}, viewport);
|
2024-01-11 21:40:46 +01:00
|
|
|
|
2024-01-16 19:24:49 +01:00
|
|
|
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
2024-01-26 09:58:01 +01:00
|
|
|
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
|
2024-01-16 19:24:49 +01:00
|
|
|
pipelineLayout->create();
|
|
|
|
|
|
2024-01-26 09:58:01 +01:00
|
|
|
ShaderCreateInfo createInfo = {
|
|
|
|
|
.mainModule = "Debug",
|
|
|
|
|
.additionalModules = { "Debug" },
|
|
|
|
|
.name = "DebugVertex",
|
|
|
|
|
.entryPoint = "vertexMain",
|
|
|
|
|
};
|
2024-01-16 19:24:49 +01:00
|
|
|
vertexShader = graphics->createVertexShader(createInfo);
|
2024-01-11 21:40:46 +01:00
|
|
|
|
|
|
|
|
createInfo.name = "DebugFragment";
|
|
|
|
|
createInfo.entryPoint = "fragmentMain";
|
2024-01-16 19:24:49 +01:00
|
|
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
2024-01-11 21:40:46 +01:00
|
|
|
|
2024-01-26 09:58:01 +01:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
vertexInput = graphics->createVertexInput(inputCreate);
|
2024-01-16 19:24:49 +01:00
|
|
|
Gfx::LegacyPipelineCreateInfo gfxInfo;
|
2024-01-26 09:58:01 +01:00
|
|
|
gfxInfo.vertexInput = vertexInput;
|
2024-01-11 21:40:46 +01:00
|
|
|
gfxInfo.vertexShader = vertexShader;
|
|
|
|
|
gfxInfo.fragmentShader = fragmentShader;
|
|
|
|
|
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_LINE;
|
|
|
|
|
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
2024-01-16 19:24:49 +01:00
|
|
|
gfxInfo.pipelineLayout = std::move(pipelineLayout);
|
2024-01-11 21:40:46 +01:00
|
|
|
gfxInfo.renderPass = renderPass;
|
2024-01-16 19:24:49 +01:00
|
|
|
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
2024-01-11 21:40:46 +01:00
|
|
|
}
|