From 25fb888d2683efa6aba95bfb360bf59af016c7a8 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 10 Nov 2019 17:59:21 +0100 Subject: [PATCH] vulkan oit: get rid of depth2 attachment --- core/rend/vulkan/oit_drawer.cpp | 26 +++++++++++--------------- core/rend/vulkan/oit_drawer.h | 8 ++------ core/rend/vulkan/oit_pipeline.cpp | 24 ++++++++++-------------- core/rend/vulkan/oit_pipeline.h | 4 ++-- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/core/rend/vulkan/oit_drawer.cpp b/core/rend/vulkan/oit_drawer.cpp index 384e2983c..fc8e7b81b 100644 --- a/core/rend/vulkan/oit_drawer.cpp +++ b/core/rend/vulkan/oit_drawer.cpp @@ -353,7 +353,7 @@ bool OITDrawer::Draw(const Texture *fogTexture) // Color subpass cmdBuffer.nextSubpass(vk::SubpassContents::eInline); - GetCurrentDescSet().UpdatePass1Uniforms(stencilImageView, depthImageView); + GetCurrentDescSet().UpdatePass1Uniforms(depthAttachment->GetStencilView(), depthAttachment->GetImageView()); GetCurrentDescSet().BindPass1DescriptorSets(cmdBuffer); // OP + PT @@ -365,7 +365,7 @@ bool OITDrawer::Draw(const Texture *fogTexture) // Final subpass cmdBuffer.nextSubpass(vk::SubpassContents::eInline); - GetCurrentDescSet().UpdatePass2Uniforms(colorImageView); + GetCurrentDescSet().UpdatePass2Uniforms(color1Attachment->GetImageView()); GetCurrentDescSet().BindPass2DescriptorSets(cmdBuffer); // Tr modifier volumes @@ -421,31 +421,27 @@ void OITDrawer::MakeBuffers(int width, int height) void OITDrawer::MakeAttachments(int width, int height) { - colorAttachment = std::unique_ptr(new FramebufferAttachment(GetContext()->GetPhysicalDevice(), + color1Attachment = std::unique_ptr(new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice(), allocator)); - colorAttachment->Init(width, height, GetContext()->GetColorFormat(), vk::ImageUsageFlagBits::eInputAttachment); - colorImageView = colorAttachment->GetImageView(); + color1Attachment->Init(width, height, GetContext()->GetColorFormat(), vk::ImageUsageFlagBits::eInputAttachment); + + color2Attachment = std::unique_ptr(new FramebufferAttachment(GetContext()->GetPhysicalDevice(), + GetContext()->GetDevice(), allocator)); + color2Attachment->Init(width, height, GetContext()->GetColorFormat(), vk::ImageUsageFlagBits::eInputAttachment); depthAttachment = std::unique_ptr(new FramebufferAttachment(GetContext()->GetPhysicalDevice(), GetContext()->GetDevice(), allocator)); depthAttachment->Init(width, height, GetContext()->GetDepthFormat(), vk::ImageUsageFlagBits::eInputAttachment); - depthImageView = depthAttachment->GetImageView(); - stencilImageView = depthAttachment->GetStencilView(); - depth2Attachment = std::unique_ptr(new FramebufferAttachment(GetContext()->GetPhysicalDevice(), - GetContext()->GetDevice(), allocator)); - depth2Attachment->Init(width, height, GetContext()->GetDepthFormat()); - printf("color attachment %p depth %p depth2 %p\n", (VkImage)colorAttachment->GetImage(), (VkImage)depthAttachment->GetImage(), - (VkImage)depth2Attachment->GetImage()); + printf("color attachment %p depth %p\n", (VkImage)color1Attachment->GetImage(), (VkImage)depthAttachment->GetImage()); } void OITDrawer::MakeFramebuffers(int width, int height) { vk::ImageView attachments[] = { nullptr, // swap chain image view, set later - colorImageView, - depthImageView, - depth2Attachment->GetImageView() + color1Attachment->GetImageView(), + depthAttachment->GetImageView(), }; framebuffers.reserve(GetContext()->GetSwapChainSize()); for (int i = 0; i < GetContext()->GetSwapChainSize(); i++) diff --git a/core/rend/vulkan/oit_drawer.h b/core/rend/vulkan/oit_drawer.h index c9c7c8279..dd9f17efe 100644 --- a/core/rend/vulkan/oit_drawer.h +++ b/core/rend/vulkan/oit_drawer.h @@ -106,13 +106,9 @@ private: std::unique_ptr quadBuffer; - vk::ImageView colorImageView; - vk::ImageView depthImageView; - vk::ImageView stencilImageView; - - std::unique_ptr colorAttachment; + std::unique_ptr color1Attachment; + std::unique_ptr color2Attachment; std::unique_ptr depthAttachment; - std::unique_ptr depth2Attachment; SamplerManager *samplerManager = nullptr; vk::Rect2D currentScissor; diff --git a/core/rend/vulkan/oit_pipeline.cpp b/core/rend/vulkan/oit_pipeline.cpp index 95949c202..c6bb83f92 100644 --- a/core/rend/vulkan/oit_pipeline.cpp +++ b/core/rend/vulkan/oit_pipeline.cpp @@ -35,28 +35,22 @@ void OITPipelineManager::MakeRenderPass() // OP+PT depth attachment vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1, vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore, vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore, - vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal), - // new depth attachment - vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1, - vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eDontCare, vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare, - vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilAttachmentOptimal), + vk::ImageLayout::eUndefined, 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 depth2Reference(3, vk::ImageLayout::eDepthStencilAttachmentOptimal); - vk::AttachmentReference depthInput(2, vk::ImageLayout::eShaderReadOnlyOptimal); // eShaderReadOnlyOptimal really? + vk::AttachmentReference depthReadOnlyRef(2, vk::ImageLayout::eDepthStencilReadOnlyOptimal); vk::AttachmentReference colorInput(1, vk::ImageLayout::eShaderReadOnlyOptimal); - vk::AttachmentReference unused(VK_ATTACHMENT_UNUSED, vk::ImageLayout::eUndefined); vk::SubpassDescription subpasses[] = { // Depth and modvol pass FIXME subpass 0 shouldn't reference the color attachment vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 0, nullptr, 1, &colorReference, nullptr, &depthReference), // Color pass - vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &depthInput, 1, &colorReference, nullptr, &depth2Reference), + vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &depthReadOnlyRef, 1, &colorReference, nullptr, &depthReadOnlyRef), // Final pass - vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &colorInput, 1, &swapChainReference, nullptr, &unused), + vk::SubpassDescription(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &colorInput, 1, &swapChainReference, nullptr, nullptr), }; vk::SubpassDependency dependencies[] = { @@ -117,17 +111,19 @@ void OITPipelineManager::CreatePipeline(u32 listType, bool autosort, const PolyP // Depth and stencil vk::CompareOp depthOp; - if (listType == ListType_Punch_Through || autosort) + if (pass == 1) + depthOp = vk::CompareOp::eEqual; + else if (listType == ListType_Punch_Through || autosort) depthOp = vk::CompareOp::eGreaterOrEqual; else depthOp = depthOps[pp.isp.DepthMode]; bool depthWriteEnable; + if (pass != 0) + depthWriteEnable = false; // Z Write Disable seems to be ignored for punch-through. // Fixes Worms World Party, Bust-a-Move 4 and Re-Volt - if (listType == ListType_Punch_Through) + else if (listType == ListType_Punch_Through) depthWriteEnable = true; - else if (listType == ListType_Translucent) - depthWriteEnable = false; else depthWriteEnable = !pp.isp.ZWriteDis; diff --git a/core/rend/vulkan/oit_pipeline.h b/core/rend/vulkan/oit_pipeline.h index df1613098..9614f5f93 100644 --- a/core/rend/vulkan/oit_pipeline.h +++ b/core/rend/vulkan/oit_pipeline.h @@ -130,9 +130,9 @@ public: vk::DescriptorSetAllocateInfo(GetContext()->GetDescriptorPool(), 1, &pass1Layout)).front()); } std::vector writeDescriptorSets; - vk::DescriptorImageInfo stencilImageInfo(vk::Sampler(), stencilImageView, vk::ImageLayout::eShaderReadOnlyOptimal); + vk::DescriptorImageInfo stencilImageInfo(vk::Sampler(), stencilImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal); writeDescriptorSets.push_back(vk::WriteDescriptorSet(*pass1DescSet, 0, 0, 1, vk::DescriptorType::eInputAttachment, &stencilImageInfo, nullptr, nullptr)); - vk::DescriptorImageInfo depthImageInfo(vk::Sampler(), depthImageView, vk::ImageLayout::eShaderReadOnlyOptimal); + vk::DescriptorImageInfo depthImageInfo(vk::Sampler(), depthImageView, vk::ImageLayout::eDepthStencilReadOnlyOptimal); writeDescriptorSets.push_back(vk::WriteDescriptorSet(*pass1DescSet, 1, 0, 1, vk::DescriptorType::eInputAttachment, &depthImageInfo, nullptr, nullptr)); GetContext()->GetDevice().updateDescriptorSets(writeDescriptorSets, nullptr);