vk oit: use a 2nd depth attachment for subpass 1
subpass 1 needs writable depth buffer (see
9f60c5e854
)
This commit is contained in:
parent
24f9003cd3
commit
c3bc5cfc3b
|
@ -255,7 +255,8 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
|
|||
{
|
||||
needDepthTransition = false;
|
||||
// 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;
|
||||
|
@ -279,8 +280,8 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
|
|||
const vk::Buffer mainBuffer = GetMainBuffer(0)->buffer.get();
|
||||
GetCurrentDescSet().UpdateUniforms(mainBuffer, offsets.vertexUniformOffset, offsets.fragmentUniformOffset,
|
||||
fogTexture->GetImageView(), offsets.polyParamsOffset,
|
||||
offsets.polyParamsSize, depthAttachment->GetStencilView(),
|
||||
depthAttachment->GetImageView(), paletteTexture->GetImageView());
|
||||
offsets.polyParamsSize, depthAttachments[0]->GetStencilView(),
|
||||
depthAttachments[0]->GetImageView(), paletteTexture->GetImageView());
|
||||
GetCurrentDescSet().BindPerFrameDescriptorSets(cmdBuffer);
|
||||
GetCurrentDescSet().UpdateColorInputDescSet(0, colorAttachments[0]->GetImageView());
|
||||
GetCurrentDescSet().UpdateColorInputDescSet(1, colorAttachments[1]->GetImageView());
|
||||
|
@ -295,10 +296,11 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
|
|||
OITDescriptorSets::PushConstants 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::ClearDepthStencilValue{ 0.f, 0 },
|
||||
vk::ClearDepthStencilValue{ 0.f, 0 },
|
||||
};
|
||||
|
||||
RenderPass previous_pass = {};
|
||||
|
@ -434,17 +436,21 @@ void OITDrawer::MakeBuffers(int width, int height)
|
|||
vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment);
|
||||
}
|
||||
|
||||
depthAttachment.reset();
|
||||
depthAttachment = std::unique_ptr<FramebufferAttachment>(
|
||||
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()));
|
||||
depthAttachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(),
|
||||
vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment);
|
||||
for (auto& attachment : depthAttachments)
|
||||
{
|
||||
attachment.reset();
|
||||
attachment = std::unique_ptr<FramebufferAttachment>(
|
||||
new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice()));
|
||||
attachment->Init(maxWidth, maxHeight, GetContext()->GetDepthFormat(),
|
||||
vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eInputAttachment);
|
||||
}
|
||||
needDepthTransition = true;
|
||||
|
||||
vk::ImageView attachments[] = {
|
||||
colorAttachments[1]->GetImageView(),
|
||||
colorAttachments[0]->GetImageView(),
|
||||
depthAttachment->GetImageView(),
|
||||
depthAttachments[0]->GetImageView(),
|
||||
depthAttachments[1]->GetImageView(),
|
||||
};
|
||||
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), pipelineManager->GetRenderPass(true, true),
|
||||
ARRAY_SIZE(attachments), attachments, width, height, 1);
|
||||
|
@ -474,7 +480,8 @@ void OITScreenDrawer::MakeFramebuffers(const vk::Extent2D& viewport)
|
|||
vk::ImageView attachments[] = {
|
||||
finalColorAttachments.back()->GetImageView(),
|
||||
colorAttachments[0]->GetImageView(),
|
||||
depthAttachment->GetImageView(),
|
||||
depthAttachments[0]->GetImageView(),
|
||||
depthAttachments[1]->GetImageView(),
|
||||
};
|
||||
vk::FramebufferCreateInfo createInfo(vk::FramebufferCreateFlags(), screenPipelineManager->GetRenderPass(true, true),
|
||||
ARRAY_SIZE(attachments), attachments, viewport.width, viewport.height, 1);
|
||||
|
@ -599,7 +606,8 @@ vk::CommandBuffer OITTextureDrawer::NewFrame()
|
|||
vk::ImageView imageViews[] = {
|
||||
colorImageView,
|
||||
colorAttachments[0]->GetImageView(),
|
||||
depthAttachment->GetImageView(),
|
||||
depthAttachments[0]->GetImageView(),
|
||||
depthAttachments[1]->GetImageView(),
|
||||
};
|
||||
framebuffers.resize(GetContext()->GetSwapChainSize());
|
||||
framebuffers[GetCurrentImage()] = device.createFramebufferUnique(vk::FramebufferCreateInfo(vk::FramebufferCreateFlags(),
|
||||
|
|
|
@ -72,7 +72,8 @@ protected:
|
|||
colorAttachments[1].reset();
|
||||
tempFramebuffers[0].reset();
|
||||
tempFramebuffers[1].reset();
|
||||
depthAttachment.reset();
|
||||
depthAttachments[0].reset();
|
||||
depthAttachments[1].reset();
|
||||
mainBuffers.clear();
|
||||
descriptorSets.clear();
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ protected:
|
|||
|
||||
vk::Rect2D viewport;
|
||||
std::array<std::unique_ptr<FramebufferAttachment>, 2> colorAttachments;
|
||||
std::unique_ptr<FramebufferAttachment> depthAttachment;
|
||||
std::array<std::unique_ptr<FramebufferAttachment>, 2> depthAttachments;
|
||||
vk::CommandBuffer currentCommandBuffer;
|
||||
std::vector<bool> clearNeeded;
|
||||
|
||||
|
|
|
@ -37,12 +37,19 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
|
|||
last ? vk::AttachmentStoreOp::eDontCare : vk::AttachmentStoreOp::eStore,
|
||||
vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare,
|
||||
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 colorReference(1, vk::ImageLayout::eColorAttachmentOptimal);
|
||||
vk::AttachmentReference depthReference(2, vk::ImageLayout::eDepthStencilAttachmentOptimal);
|
||||
|
||||
vk::AttachmentReference depthReadOnlyRef(2, vk::ImageLayout::eDepthStencilReadOnlyOptimal);
|
||||
vk::AttachmentReference depthReference2(3, vk::ImageLayout::eDepthStencilAttachmentOptimal);
|
||||
vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||
// vk 1.2 sdk wants this layout for subpass 2
|
||||
vk::AttachmentReference depthRefStencilReadOnly(2, vk::ImageLayout::eDepthAttachmentStencilReadOnlyOptimal);
|
||||
|
@ -59,7 +66,7 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last)
|
|||
1, &depthReadOnlyRef,
|
||||
1, &colorReference,
|
||||
nullptr,
|
||||
&depthReadOnlyRef),
|
||||
&depthReference2),
|
||||
// Final pass
|
||||
vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics,
|
||||
1, &colorInput,
|
||||
|
|
Loading…
Reference in New Issue