Adding interface for renderpass layout transitions

This commit is contained in:
Dynamitos
2024-01-31 09:49:53 +01:00
parent 1bf08f696b
commit 5678021c9e
34 changed files with 616 additions and 184 deletions
+29 -8
View File
@@ -72,10 +72,8 @@ void BasePass::render()
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);
depthAttachment->getTexture()->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
depthAttachment->getTexture()->transferOwnership(Gfx::QueueType::GRAPHICS);
depthAttachment->getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
@@ -137,6 +135,7 @@ void BasePass::render()
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
@@ -149,6 +148,7 @@ void BasePass::render()
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
pipelineInfo.colorBlend.attachmentCount = 1;
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
}
@@ -190,19 +190,40 @@ void BasePass::endFrame()
void BasePass::publishOutputs()
{
colorAttachment = new Gfx::SwapchainAttachment(viewport, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
colorAttachment = new Gfx::SwapchainAttachment(viewport,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
}
void BasePass::createRenderPass()
{
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
depthAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { colorAttachment },
.depthAttachment = depthAttachment,
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
Array<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,
},
{
.srcSubpass = ~0U,
.dstSubpass = 0,
.srcStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstStage = Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccess = Gfx::SE_ACCESS_NONE,
.dstAccess = Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
}
};
renderPass = graphics->createRenderPass(std::move(layout), {dependency}, viewport);
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
tLightIndexList = resources->requestBuffer("LIGHTCULLING_TLIGHTLIST");
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
+15 -4
View File
@@ -70,14 +70,25 @@ void DebugPass::publishOutputs()
void DebugPass::createRenderPass()
{
Gfx::PRenderTargetAttachment baseColorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
baseColorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
baseColorAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
baseColorAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
depthAttachment->setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
depthAttachment->setInitialLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {baseColorAttachment},
.depthAttachment = depthAttachment,
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
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);
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
@@ -86,7 +86,7 @@ void DepthPrepass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
command->bindPipeline(pipeline);
@@ -98,6 +98,7 @@ void DepthPrepass::render()
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.renderPass = renderPass;
//pipelineInfo.depthStencilState.depthWriteEnable = false;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
@@ -151,17 +152,27 @@ void DepthPrepass::publishOutputs()
};
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
new Gfx::RenderTargetAttachment(depthBuffer,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_GENERAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
depthAttachment->clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("DEPTHPREPASS_DEPTH", depthAttachment);
}
void DepthPrepass::createRenderPass()
{
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.depthAttachment = depthAttachment,
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
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);
}
void DepthPrepass::modifyRenderPassMacros(Map<const char*, const char*>&)
@@ -22,6 +22,14 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
{
RenderPass::beginFrame(cam);
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT
);
uint32 reset = 0;
DataSource counterReset = {
.size = sizeof(uint32),
@@ -45,23 +53,36 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
void LightCullingPass::render()
{
oLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
oLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
oLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightIndexCounter->pipelineBarrier(
Gfx::SE_ACCESS_MEMORY_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_MEMORY_WRITE_BIT | Gfx::SE_ACCESS_MEMORY_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT
);
tLightIndexList->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightGrid->pipelineBarrier(
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
depthAttachment->pipelineBarrier(
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment->transferOwnership(Gfx::QueueType::COMPUTE);
cullingDescriptorSet->updateTexture(0, depthAttachment);
cullingDescriptorSet->writeChanges();
Gfx::PComputeCommand computeCommand = graphics->createComputeCommand("CullingCommand");
computeCommand->bindPipeline(cullingPipeline);
computeCommand->bindDescriptor({ viewParamsSet, dispatchParamsSet, cullingDescriptorSet, lightEnv->getDescriptorSet() });
//computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
computeCommand->dispatch(dispatchParams.numThreadGroups.x, dispatchParams.numThreadGroups.y, dispatchParams.numThreadGroups.z);
Array<Gfx::PComputeCommand> commands = {computeCommand};
graphics->executeCommands(commands);
//std::cout << "LightCulling render()" << std::endl;
@@ -52,7 +52,6 @@ private:
PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment;
Gfx::OShaderBuffer frustums;
Gfx::OShaderBuffer oLightIndexCounter;
Gfx::OShaderBuffer tLightIndexCounter;
Gfx::OShaderBuffer oLightIndexList;
@@ -87,14 +87,14 @@ void SkyboxRenderPass::publishOutputs()
void SkyboxRenderPass::createRenderPass()
{
colorAttachment = resources->requestRenderTarget("BASEPASS_COLOR");
colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
//colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
.colorAttachments = { colorAttachment },
.depthAttachment = depthAttachment
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
//depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD;
//Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
// .colorAttachments = { colorAttachment },
// .depthAttachment = depthAttachment
//};
//renderPass = graphics->createRenderPass(std::move(layout), viewport);
skyboxData.transformMatrix = Matrix4(1);
skyboxData.fogColor = skybox.fogColor;
+2 -2
View File
@@ -158,11 +158,11 @@ void TextPass::createRenderPass()
.size = sizeof(TextData)});
pipelineLayout->create();
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = {renderTarget},
.depthAttachment = depthAttachment
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
renderPass = graphics->createRenderPass(std::move(layout), {}, viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = vertexShader;
+8 -4
View File
@@ -70,7 +70,9 @@ void UIPass::publishOutputs()
depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
new Gfx::RenderTargetAttachment(depthBuffer,
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);
depthAttachment->clear.depthStencil.depth = 1.0f;
resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment);
@@ -82,7 +84,9 @@ void UIPass::publishOutputs()
};
colorBuffer = graphics->createTexture2D(colorBufferInfo);
renderTarget =
new Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
new Gfx::RenderTargetAttachment(colorBuffer,
Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
renderTarget->clear.color = { {0.0f, 0.0f, 0.0f, 1.0f} };
resources->registerRenderPassOutput("UIPASS_COLOR", renderTarget);
}
@@ -136,11 +140,11 @@ void UIPass::createRenderPass()
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->create();
Gfx::ORenderTargetLayout layout = new Gfx::RenderTargetLayout{
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
.colorAttachments = { renderTarget },
.depthAttachment = depthAttachment
};
renderPass = graphics->createRenderPass(std::move(layout), viewport);
renderPass = graphics->createRenderPass(std::move(layout), {}, viewport);
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = vertexShader;