vk oit: use a 2nd depth attachment for subpass 1

subpass 1 needs writable depth buffer (see
9f60c5e854)
This commit is contained in:
Flyinghead 2021-05-30 18:20:04 +02:00
parent 24f9003cd3
commit c3bc5cfc3b
3 changed files with 31 additions and 15 deletions

View File

@ -255,7 +255,8 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
{ {
needDepthTransition = false; needDepthTransition = false;
// Not convinced that this is really needed but it makes validation layers happy // Not convinced that this is really needed but it makes validation layers happy
setImageLayout(cmdBuffer, depthAttachment->GetImage(), GetContext()->GetDepthFormat(), 1, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilReadOnlyOptimal); for (auto& attachment : depthAttachments)
setImageLayout(cmdBuffer, attachment->GetImage(), GetContext()->GetDepthFormat(), 1, vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
} }
OITDescriptorSets::VertexShaderUniforms vtxUniforms; OITDescriptorSets::VertexShaderUniforms vtxUniforms;
@ -279,8 +280,8 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
const vk::Buffer mainBuffer = GetMainBuffer(0)->buffer.get(); const vk::Buffer mainBuffer = GetMainBuffer(0)->buffer.get();
GetCurrentDescSet().UpdateUniforms(mainBuffer, offsets.vertexUniformOffset, offsets.fragmentUniformOffset, GetCurrentDescSet().UpdateUniforms(mainBuffer, offsets.vertexUniformOffset, offsets.fragmentUniformOffset,
fogTexture->GetImageView(), offsets.polyParamsOffset, fogTexture->GetImageView(), offsets.polyParamsOffset,
offsets.polyParamsSize, depthAttachment->GetStencilView(), offsets.polyParamsSize, depthAttachments[0]->GetStencilView(),
depthAttachment->GetImageView(), paletteTexture->GetImageView()); depthAttachments[0]->GetImageView(), paletteTexture->GetImageView());
GetCurrentDescSet().BindPerFrameDescriptorSets(cmdBuffer); GetCurrentDescSet().BindPerFrameDescriptorSets(cmdBuffer);
GetCurrentDescSet().UpdateColorInputDescSet(0, colorAttachments[0]->GetImageView()); GetCurrentDescSet().UpdateColorInputDescSet(0, colorAttachments[0]->GetImageView());
GetCurrentDescSet().UpdateColorInputDescSet(1, colorAttachments[1]->GetImageView()); GetCurrentDescSet().UpdateColorInputDescSet(1, colorAttachments[1]->GetImageView());
@ -295,10 +296,11 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
OITDescriptorSets::PushConstants pushConstants = { }; OITDescriptorSets::PushConstants pushConstants = { };
cmdBuffer.pushConstants<OITDescriptorSets::PushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants); cmdBuffer.pushConstants<OITDescriptorSets::PushConstants>(pipelineManager->GetPipelineLayout(), vk::ShaderStageFlagBits::eFragment, 0, pushConstants);
const std::array<vk::ClearValue, 3> clear_colors = { const std::array<vk::ClearValue, 4> clear_colors = {
vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}), vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}),
vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}), vk::ClearColorValue(std::array<float, 4>{0.f, 0.f, 0.f, 1.f}),
vk::ClearDepthStencilValue{ 0.f, 0 }, vk::ClearDepthStencilValue{ 0.f, 0 },
vk::ClearDepthStencilValue{ 0.f, 0 },
}; };
RenderPass previous_pass = {}; RenderPass previous_pass = {};
@ -434,17 +436,21 @@ void OITDrawer::MakeBuffers(int width, int height)
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment); vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment);
} }
depthAttachment.reset(); for (auto& attachment : depthAttachments)
depthAttachment = std::unique_ptr<FramebufferAttachment>( {
attachment.reset();
attachment = std::unique_ptr<FramebufferAttachment>(
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice())); new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()));
depthAttachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(), attachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(),
vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment); vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment);
}
needDepthTransition = true; needDepthTransition = true;
vk::ImageView attachments[] = { vk::ImageView attachments[] = {
colorAttachments[1]->GetImageView(), colorAttachments[1]->GetImageView(),
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachment->GetImageView(), depthAttachments[0]->GetImageView(),
depthAttachments[1]->GetImageView(),
}; };
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true), vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true),
ARRAY_SIZE(attachments), attachments, width, height, 1); ARRAY_SIZE(attachments), attachments, width, height, 1);
@ -474,7 +480,8 @@ void OITScreenDrawer::MakeFramebuffers(const vk::Extent2D& viewport)
vk::ImageView attachments[] = { vk::ImageView attachments[] = {
finalColorAttachments.back()->GetImageView(), finalColorAttachments.back()->GetImageView(),
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachment->GetImageView(), depthAttachments[0]->GetImageView(),
depthAttachments[1]->GetImageView(),
}; };
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true), vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true),
ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1); ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1);
@ -599,7 +606,8 @@ vk::CommandBuffer OITTextureDrawer::NewFrame()
vk::ImageView imageViews[] = { vk::ImageView imageViews[] = {
colorImageView, colorImageView,
colorAttachments[0]->GetImageView(), colorAttachments[0]->GetImageView(),
depthAttachment->GetImageView(), depthAttachments[0]->GetImageView(),
depthAttachments[1]->GetImageView(),
}; };
framebuffers.resize(GetContext()->GetSwapChainSize()); framebuffers.resize(GetContext()->GetSwapChainSize());
framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(), framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(),

View File

@ -72,7 +72,8 @@ protected:
colorAttachments[1].reset(); colorAttachments[1].reset();
tempFramebuffers[0].reset(); tempFramebuffers[0].reset();
tempFramebuffers[1].reset(); tempFramebuffers[1].reset();
depthAttachment.reset(); depthAttachments[0].reset();
depthAttachments[1].reset();
mainBuffers.clear(); mainBuffers.clear();
descriptorSets.clear(); descriptorSets.clear();
} }
@ -116,7 +117,7 @@ protected:
vk::Rect2D viewport; vk::Rect2D viewport;
std::array<std::unique_ptr<FramebufferAttachment>, 2> colorAttachments; std::array<std::unique_ptr<FramebufferAttachment>, 2> colorAttachments;
std::unique_ptr<FramebufferAttachment> depthAttachment; std::array<std::unique_ptr<FramebufferAttachment>, 2> depthAttachments;
vk::CommandBuffer currentCommandBuffer; vk::CommandBuffer currentCommandBuffer;
std::vector<bool> clearNeeded; std::vector<bool> clearNeeded;

View File

@ -37,12 +37,19 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
last ? vk::AttachmentStoreOp::eDontCare : vk::AttachmentStoreOp::eStore, last ? vk::AttachmentStoreOp::eDontCare : vk::AttachmentStoreOp::eStore,
vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare,
initial ? vk::ImageLayout::eUndefined : vk::ImageLayout::eDepthStencilReadOnlyOptimal, vk::ImageLayout::eDepthStencilReadOnlyOptimal), initial ? vk::ImageLayout::eUndefined : vk::ImageLayout::eDepthStencilReadOnlyOptimal, vk::ImageLayout::eDepthStencilReadOnlyOptimal),
// OP+PT depth attachment for subpass 1
vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1,
initial ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad,
last ? vk::AttachmentStoreOp::eDontCare : vk::AttachmentStoreOp::eStore,
vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare,
initial ? vk::ImageLayout::eUndefined : vk::ImageLayout::eDepthStencilReadOnlyOptimal, vk::ImageLayout::eDepthStencilReadOnlyOptimal),
}; };
vk::AttachmentReference swapChainReference(0, vk::ImageLayout::eColorAttachmentOptimal); vk::AttachmentReference swapChainReference(0, vk::ImageLayout::eColorAttachmentOptimal);
vk::AttachmentReference colorReference(1, vk::ImageLayout::eColorAttachmentOptimal); vk::AttachmentReference colorReference(1, vk::ImageLayout::eColorAttachmentOptimal);
vk::AttachmentReference depthReference(2, vk::ImageLayout::eDepthStencilAttachmentOptimal); vk::AttachmentReference depthReference(2, vk::ImageLayout::eDepthStencilAttachmentOptimal);
vk::AttachmentReference depthReadOnlyRef(2, vk::ImageLayout::eDepthStencilReadOnlyOptimal); vk::AttachmentReference depthReadOnlyRef(2, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
vk::AttachmentReference depthReference2(3, vk::ImageLayout::eDepthStencilAttachmentOptimal);
vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal); vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal);
// vk 1.2 sdk wants this layout for subpass 2 // vk 1.2 sdk wants this layout for subpass 2
vk::AttachmentReference depthRefStencilReadOnly(2, vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal); vk::AttachmentReference depthRefStencilReadOnly(2, vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal);
@ -59,7 +66,7 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
1, &depthReadOnlyRef, 1, &depthReadOnlyRef,
1, &colorReference, 1, &colorReference,
nullptr, nullptr,
&depthReadOnlyRef), &depthReference2),
// Final pass // Final pass
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
1, &colorInput, 1, &colorInput,