From a78add37a57b51d80ef2fd21a7a0799ba73dd937 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 23 Jul 2020 15:24:54 -0700 Subject: Added Render pass interface stub --- .../GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp | 4 ++++ Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp index 7204cad7..f339e33e 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp @@ -98,6 +98,10 @@ public: /// Implementation of IRenderDevice::CreateQuery() in Vulkan backend. virtual void DILIGENT_CALL_TYPE CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) override final; + /// Implementation of IRenderDevice::CreateRenderPass() in Vulkan backend. + virtual void DILIGENT_CALL_TYPE CreateRenderPass(const RenderPassDesc& Desc, + IRenderPass** ppRenderPass) override final; + /// Implementation of IRenderDeviceVk::GetVkDevice(). virtual VkDevice DILIGENT_CALL_TYPE GetVkDevice() override final { return m_LogicalVkDevice->GetVkDevice(); } diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 4e6049b0..0f59e64c 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -618,4 +618,17 @@ void RenderDeviceVkImpl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) ); } +void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) +{ + //CreateDeviceObject( + // "RenderPass", Desc, ppRenderPass, + // [&]() // + // { + // RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc)); + // pRenderPassVk->RenderPassInterface(IID_RenderPass, reinterpret_cast(ppRenderPass)); + // OnCreateDeviceObject(pRenderPassVk); + // } // + //); +} + } // namespace Diligent -- cgit v1.2.3 From 8a7504ff49c357ad86d547a35bdfd3258bea72df Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 23 Jul 2020 15:58:46 -0700 Subject: Added render pass object implementation stubs in all backends --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 + .../include/RenderPassVkImpl.hpp | 54 ++++++++++++++++++++++ .../src/RenderDeviceVkImpl.cpp | 22 +++++---- .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 47 +++++++++++++++++++ 4 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp create mode 100644 Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 28cf8b0f..1696283c 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -20,6 +20,7 @@ set(INCLUDE include/QueryManagerVk.hpp include/QueryVkImpl.hpp include/RenderDeviceVkImpl.hpp + include/RenderPassVkImpl.hpp include/RenderPassCache.hpp include/SamplerVkImpl.hpp include/ShaderVkImpl.hpp @@ -86,6 +87,7 @@ set(SRC src/QueryManagerVk.cpp src/QueryVkImpl.cpp src/RenderDeviceVkImpl.cpp + src/RenderPassVkImpl.cpp src/RenderPassCache.cpp src/SamplerVkImpl.cpp src/ShaderVkImpl.cpp diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp new file mode 100644 index 00000000..bc50624f --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp @@ -0,0 +1,54 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::RenderPassVkImpl class + +#include "RenderDeviceVk.h" +#include "RenderPassBase.hpp" +#include "RenderDeviceVkImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Render pass implementation in Direct3D11 backend. +class RenderPassVkImpl final : public RenderPassBase +{ +public: + using TRenderPassBase = RenderPassBase; + + RenderPassVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const RenderPassDesc& Desc); + ~RenderPassVkImpl(); +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 0f59e64c..012cb58f 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -37,6 +37,7 @@ #include "DeviceContextVkImpl.hpp" #include "FenceVkImpl.hpp" #include "QueryVkImpl.hpp" +#include "RenderPassVkImpl.hpp" #include "EngineMemory.h" namespace Diligent @@ -71,7 +72,8 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters* sizeof(PipelineStateVkImpl), sizeof(ShaderResourceBindingVkImpl), sizeof(FenceVkImpl), - sizeof(QueryVkImpl) + sizeof(QueryVkImpl), + sizeof(RenderPassVkImpl) } }, m_VulkanInstance {Instance }, @@ -620,15 +622,15 @@ void RenderDeviceVkImpl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) { - //CreateDeviceObject( - // "RenderPass", Desc, ppRenderPass, - // [&]() // - // { - // RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc)); - // pRenderPassVk->RenderPassInterface(IID_RenderPass, reinterpret_cast(ppRenderPass)); - // OnCreateDeviceObject(pRenderPassVk); - // } // - //); + CreateDeviceObject( + "RenderPass", Desc, ppRenderPass, + [&]() // + { + RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc)); + pRenderPassVk->QueryInterface(IID_RenderPass, reinterpret_cast(ppRenderPass)); + OnCreateDeviceObject(pRenderPassVk); + } // + ); } } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp new file mode 100644 index 00000000..7ea5b8b9 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "RenderPassVkImpl.hpp" +#include "EngineMemory.h" + +namespace Diligent +{ + +RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const RenderPassDesc& Desc) : + TRenderPassBase{pRefCounters, pDevice, Desc} +{ +} + +RenderPassVkImpl::~RenderPassVkImpl() +{ +} + +} // namespace Diligent -- cgit v1.2.3 From d8584bffd8b32b71174983fa3f38694b65d42945 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 23 Jul 2020 17:28:38 -0700 Subject: Added IRenderPassVk interface --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 1 + .../include/RenderPassVkImpl.hpp | 12 +++- .../GraphicsEngineVulkan/interface/RenderPassVk.h | 64 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/interface/RenderPassVk.h (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 1696283c..102044b7 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -61,6 +61,7 @@ set(INTERFACE interface/PipelineStateVk.h interface/QueryVk.h interface/RenderDeviceVk.h + interface/RenderPassVk.h interface/SamplerVk.h interface/ShaderVk.h interface/ShaderResourceBindingVk.h diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp index bc50624f..9cf34e08 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp @@ -31,8 +31,10 @@ /// Declaration of Diligent::RenderPassVkImpl class #include "RenderDeviceVk.h" +#include "RenderPassVk.h" #include "RenderPassBase.hpp" #include "RenderDeviceVkImpl.hpp" +#include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent { @@ -40,15 +42,21 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Render pass implementation in Direct3D11 backend. -class RenderPassVkImpl final : public RenderPassBase +class RenderPassVkImpl final : public RenderPassBase { public: - using TRenderPassBase = RenderPassBase; + using TRenderPassBase = RenderPassBase; RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, const RenderPassDesc& Desc); ~RenderPassVkImpl(); + + /// Implementation of ISamplerVk::GetVkRenderPass(). + virtual VkRenderPass DILIGENT_CALL_TYPE GetVkRenderPass() const override final { return m_VkRenderPass; } + +private: + VulkanUtilities::RenderPassWrapper m_VkRenderPass; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/interface/RenderPassVk.h b/Graphics/GraphicsEngineVulkan/interface/RenderPassVk.h new file mode 100644 index 00000000..6096e723 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/interface/RenderPassVk.h @@ -0,0 +1,64 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IRenderPassVk interface + +#include "../../GraphicsEngine/interface/RenderPass.h" + +DILIGENT_BEGIN_NAMESPACE(Diligent) + +// {3DE6938F-D34D-4135-A6FA-15A89E9525D0} +static const INTERFACE_ID IID_RenderPassVk = + {0x3de6938f, 0xd34d, 0x4135, {0xa6, 0xfa, 0x15, 0xa8, 0x9e, 0x95, 0x25, 0xd0}}; + +#define DILIGENT_INTERFACE_NAME IRenderPassVk +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + +#define IRenderPassVkInclusiveMethods \ + /*IRenderPassInclusiveMethods*/ IDeviceObjectInclusiveMethods; \ + IRenderPassVkMethods RenderPassVk + +/// Exposes Vulkan-specific functionality of a RenderPass object. +DILIGENT_BEGIN_INTERFACE(IRenderPassVk, IRenderPass) +{ + /// Returns a Vulkan RenderPass object handle + VIRTUAL VkRenderPass METHOD(GetVkRenderPass)() CONST PURE; +}; +DILIGENT_END_INTERFACE + +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" + +#if DILIGENT_C_INTERFACE + +# define IRenderPassVk_GetVkRenderPass(This) CALL_IFACE_METHOD(RenderPassVk, GetVkRenderPass, This) + +#endif + +DILIGENT_END_NAMESPACE // namespace Diligent -- cgit v1.2.3 From b35dbd3450904e5300f96f6e650d38964078fca7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 23 Jul 2020 20:41:58 -0700 Subject: Implemented RenderPassAttachmentDesc struct; added render pass creation test; WIP implementation of render pass initialization in Vulkan --- .../include/VulkanTypeConversions.hpp | 6 ++++ .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 33 +++++++++++++++++++++- .../src/VulkanTypeConversions.cpp | 20 +++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp index 15420ead..c680c22d 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp @@ -73,4 +73,10 @@ RESOURCE_STATE VkImageLayoutToResourceState(VkImageLayout Layout); SURFACE_TRANSFORM VkSurfaceTransformFlagToSurfaceTransform(VkSurfaceTransformFlagBitsKHR vkTransformFlag); VkSurfaceTransformFlagBitsKHR SurfaceTransformToVkSurfaceTransformFlag(SURFACE_TRANSFORM SrfTransform); +VkAttachmentLoadOp AttachmentLoadOpToVkAttachmentLoadOp(ATTACHMENT_LOAD_OP LoadOp); +ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoadOp); + +VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp); +ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp VkStoreOp); + } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 7ea5b8b9..4483fcdc 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -26,9 +26,10 @@ */ #include "pch.h" +#include #include "RenderPassVkImpl.hpp" -#include "EngineMemory.h" +#include "VulkanTypeConversions.hpp" namespace Diligent { @@ -38,6 +39,36 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, const RenderPassDesc& Desc) : TRenderPassBase{pRefCounters, pDevice, Desc} { + VkRenderPassCreateInfo RenderPassCI = {}; + + RenderPassCI.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + RenderPassCI.pNext = nullptr; + RenderPassCI.flags = 0; + + std::array vkAttachments = {}; + for (Uint32 i = 0; i < m_Desc.AttachmentCount; ++i) + { + const auto& Attachment = m_Desc.pAttachments[i]; + auto& vkAttachment = vkAttachments[i]; + vkAttachment.flags = 0; + vkAttachment.format = TexFormatToVkFormat(Attachment.Format); + vkAttachment.samples = static_cast(0x01 << Attachment.SampleCount); + vkAttachment.loadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.LoadOp); + vkAttachment.storeOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StoreOp); + vkAttachment.stencilLoadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.StencilLoadOp); + vkAttachment.stencilStoreOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StencilStoreOp); + vkAttachment.initialLayout = ResourceStateToVkImageLayout(Attachment.InitialState); + vkAttachment.finalLayout = ResourceStateToVkImageLayout(Attachment.FinalState); + } + RenderPassCI.attachmentCount = Desc.AttachmentCount; + RenderPassCI.pAttachments = vkAttachments.data(); + + + RenderPassCI.subpassCount = Desc.SubpassCount; + RenderPassCI.pSubpasses; + + RenderPassCI.dependencyCount = Desc.DependencyCount; + RenderPassCI.pDependencies; } RenderPassVkImpl::~RenderPassVkImpl() diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index d5e4f48b..592f9522 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1421,4 +1421,24 @@ VkSurfaceTransformFlagBitsKHR SurfaceTransformToVkSurfaceTransformFlag(SURFACE_T // clang-format on } +VkAttachmentLoadOp AttachmentLoadOpToVkAttachmentLoadOp(ATTACHMENT_LOAD_OP LoadOp) +{ + return static_cast(LoadOp); +} + +ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoadOp) +{ + return static_cast(VkLoadOp); +} + +VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp) +{ + return static_cast(StoreOp); +} + +ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp VkStoreOp) +{ + return static_cast(VkStoreOp); +} + } // namespace Diligent -- cgit v1.2.3 From 4b44eea6ac2311d5e9d4373053c6aa382a1e3e0a Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 24 Jul 2020 11:35:54 -0700 Subject: Defined SubpassDesc struct --- .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 79 ++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 4483fcdc..23483370 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -26,7 +26,7 @@ */ #include "pch.h" -#include +#include #include "RenderPassVkImpl.hpp" #include "VulkanTypeConversions.hpp" @@ -45,14 +45,14 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderPassCI.pNext = nullptr; RenderPassCI.flags = 0; - std::array vkAttachments = {}; + std::vector vkAttachments(m_Desc.AttachmentCount); for (Uint32 i = 0; i < m_Desc.AttachmentCount; ++i) { const auto& Attachment = m_Desc.pAttachments[i]; auto& vkAttachment = vkAttachments[i]; vkAttachment.flags = 0; vkAttachment.format = TexFormatToVkFormat(Attachment.Format); - vkAttachment.samples = static_cast(0x01 << Attachment.SampleCount); + vkAttachment.samples = static_cast(0x01 << (Attachment.SampleCount - 1)); vkAttachment.loadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.LoadOp); vkAttachment.storeOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StoreOp); vkAttachment.stencilLoadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.StencilLoadOp); @@ -64,11 +64,82 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderPassCI.pAttachments = vkAttachments.data(); + Uint32 TotalAttachmentReferencesCount = 0; + Uint32 TotalPreserveAttachmentsCount = 0; + CountSubpassAttachmentReferences(Desc, TotalAttachmentReferencesCount, TotalPreserveAttachmentsCount); + std::vector vkAttachmentReferences(TotalAttachmentReferencesCount); + std::vector vkPreserveAttachments(TotalPreserveAttachmentsCount); + + Uint32 CurrAttachmentReferenceInd = 0; + Uint32 CurrPreserveAttachmentInd = 0; + + std::vector vkSubpasses(Desc.SubpassCount); + for (Uint32 i = 0; i < m_Desc.SubpassCount; ++i) + { + const auto& SubpassDesc = m_Desc.pSubpasses[i]; + auto& vkSubpass = vkSubpasses[i]; + vkSubpass.flags = 0; + vkSubpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + vkSubpass.inputAttachmentCount = SubpassDesc.InputAttachmentCount; + + auto ConvertAttachmentReferences = [&](Uint32 NumAttachments, const AttachmentReference* pSrcAttachments) // + { + auto* pCurrVkAttachmentReference = &vkAttachmentReferences[CurrAttachmentReferenceInd]; + for (Uint32 attachment = 0; attachment < NumAttachments; ++attachment, ++CurrAttachmentReferenceInd) + { + vkAttachmentReferences[CurrAttachmentReferenceInd].attachment = pSrcAttachments[attachment].AttachmentIndex; + vkAttachmentReferences[CurrAttachmentReferenceInd].layout = ResourceStateToVkImageLayout(pSrcAttachments[attachment].State); + } + + return pCurrVkAttachmentReference; + }; + + if (SubpassDesc.InputAttachmentCount != 0) + { + vkSubpass.pInputAttachments = ConvertAttachmentReferences(SubpassDesc.InputAttachmentCount, SubpassDesc.pInputAttachments); + } + + vkSubpass.colorAttachmentCount = SubpassDesc.RenderTargetAttachmentCount; + if (SubpassDesc.RenderTargetAttachmentCount != 0) + { + vkSubpass.pColorAttachments = ConvertAttachmentReferences(SubpassDesc.RenderTargetAttachmentCount, SubpassDesc.pRenderTargetAttachments); + if (SubpassDesc.pResolveAttachments != nullptr) + { + vkSubpass.pResolveAttachments = ConvertAttachmentReferences(SubpassDesc.RenderTargetAttachmentCount, SubpassDesc.pResolveAttachments); + } + } + + if (SubpassDesc.pDepthStencilAttachment != nullptr) + { + vkSubpass.pDepthStencilAttachment = ConvertAttachmentReferences(1, SubpassDesc.pDepthStencilAttachment); + } + + vkSubpass.preserveAttachmentCount = SubpassDesc.PreserveAttachmentCount; + if (SubpassDesc.PreserveAttachmentCount != 0) + { + vkSubpass.pPreserveAttachments = &vkPreserveAttachments[CurrPreserveAttachmentInd]; + for (Uint32 prsv_attachment = 0; prsv_attachment < SubpassDesc.PreserveAttachmentCount; ++prsv_attachment, ++CurrPreserveAttachmentInd) + { + vkPreserveAttachments[CurrPreserveAttachmentInd] = SubpassDesc.pPreserveAttachments[prsv_attachment]; + } + } + } + VERIFY_EXPR(CurrAttachmentReferenceInd == vkAttachmentReferences.size()); + VERIFY_EXPR(CurrPreserveAttachmentInd == vkPreserveAttachments.size()); RenderPassCI.subpassCount = Desc.SubpassCount; - RenderPassCI.pSubpasses; + RenderPassCI.pSubpasses = vkSubpasses.data(); + RenderPassCI.dependencyCount = Desc.DependencyCount; RenderPassCI.pDependencies; + + const auto& LogicalDevice = pDevice->GetLogicalDevice(); + + m_VkRenderPass = LogicalDevice.CreateRenderPass(RenderPassCI, Desc.Name); + if (!m_VkRenderPass) + { + LOG_ERROR_AND_THROW("Failed to create Vulkan render pass"); + } } RenderPassVkImpl::~RenderPassVkImpl() -- cgit v1.2.3 From 16dd04efc73e4093a991a517f786ebaf03f3f6d1 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 24 Jul 2020 21:18:48 -0700 Subject: Added framebuffer object implementation stubs --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 + .../include/FramebufferVkImpl.hpp | 53 ++++++++++++++++++++++ .../include/RenderDeviceVkImpl.hpp | 4 ++ .../GraphicsEngineVulkan/src/FramebufferVkImpl.cpp | 47 +++++++++++++++++++ .../src/RenderDeviceVkImpl.cpp | 15 +++++- 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp create mode 100644 Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 102044b7..26e89bba 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -11,6 +11,7 @@ set(INCLUDE include/DescriptorPoolManager.hpp include/DeviceContextVkImpl.hpp include/FenceVkImpl.hpp + include/FramebufferVkImpl.hpp include/VulkanDynamicHeap.hpp include/FramebufferCache.hpp include/GenerateMipsVkHelper.hpp @@ -80,6 +81,7 @@ set(SRC src/DeviceContextVkImpl.cpp src/EngineFactoryVk.cpp src/FenceVkImpl.cpp + src/FramebufferVkImpl.cpp src/VulkanDynamicHeap.cpp src/FramebufferCache.cpp src/GenerateMipsVkHelper.cpp diff --git a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp new file mode 100644 index 00000000..63e56496 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp @@ -0,0 +1,53 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::FramebufferVkImpl class + +#include "FramebufferBase.hpp" +#include "RenderDeviceVkImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Render pass implementation in Direct3D11 backend. +class FramebufferVkImpl final : public FramebufferBase +{ +public: + using TFramebufferBase = FramebufferBase; + + FramebufferVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const FramebufferDesc& Desc); + ~FramebufferVkImpl(); +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp index f339e33e..6ec79aad 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp @@ -102,6 +102,10 @@ public: virtual void DILIGENT_CALL_TYPE CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) override final; + /// Implementation of IRenderDevice::CreateFramebuffer() in Vulkan backend. + virtual void DILIGENT_CALL_TYPE CreateFramebuffer(const FramebufferDesc& Desc, + IFramebuffer** ppFramebuffer) override final; + /// Implementation of IRenderDeviceVk::GetVkDevice(). virtual VkDevice DILIGENT_CALL_TYPE GetVkDevice() override final { return m_LogicalVkDevice->GetVkDevice(); } diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp new file mode 100644 index 00000000..ba515950 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include "FramebufferVkImpl.hpp" +#include "EngineMemory.h" + +namespace Diligent +{ + +FramebufferVkImpl::FramebufferVkImpl(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const FramebufferDesc& Desc) : + TFramebufferBase{pRefCounters, pDevice, Desc} +{ +} + +FramebufferVkImpl::~FramebufferVkImpl() +{ +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 012cb58f..d5f38ade 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -38,6 +38,7 @@ #include "FenceVkImpl.hpp" #include "QueryVkImpl.hpp" #include "RenderPassVkImpl.hpp" +#include "FramebufferVkImpl.hpp" #include "EngineMemory.h" namespace Diligent @@ -73,7 +74,8 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters* sizeof(ShaderResourceBindingVkImpl), sizeof(FenceVkImpl), sizeof(QueryVkImpl), - sizeof(RenderPassVkImpl) + sizeof(RenderPassVkImpl), + sizeof(FramebufferVkImpl) } }, m_VulkanInstance {Instance }, @@ -633,4 +635,15 @@ void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPas ); } +void RenderDeviceVkImpl::CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer) +{ + CreateDeviceObject("Framebuffer", Desc, ppFramebuffer, + [&]() // + { + FramebufferVkImpl* pFramebufferVk(NEW_RC_OBJ(m_FramebufferAllocator, "FramebufferVkImpl instance", FramebufferVkImpl)(this, Desc)); + pFramebufferVk->QueryInterface(IID_Framebuffer, reinterpret_cast(ppFramebuffer)); + OnCreateDeviceObject(pFramebufferVk); + }); +} + } // namespace Diligent -- cgit v1.2.3 From 955768292c4316f6e12c7cceff330a203a756337 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 24 Jul 2020 22:59:29 -0700 Subject: Implemente framebuffer in Vulkan --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 1 + .../include/FramebufferVkImpl.hpp | 14 ++++- .../GraphicsEngineVulkan/interface/FramebufferVk.h | 64 ++++++++++++++++++++++ .../GraphicsEngineVulkan/src/FramebufferVkImpl.cpp | 36 ++++++++++++ .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 2 +- .../GraphicsEngineVulkan/src/TextureVkImpl.cpp | 4 ++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 26e89bba..93a811b1 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -59,6 +59,7 @@ set(INTERFACE interface/DeviceContextVk.h interface/EngineFactoryVk.h interface/FenceVk.h + interface/FramebufferVk.h interface/PipelineStateVk.h interface/QueryVk.h interface/RenderDeviceVk.h diff --git a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp index 63e56496..3e15852c 100644 --- a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp @@ -30,8 +30,10 @@ /// \file /// Declaration of Diligent::FramebufferVkImpl class +#include "FramebufferVk.h" #include "FramebufferBase.hpp" #include "RenderDeviceVkImpl.hpp" +#include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent { @@ -39,15 +41,23 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Render pass implementation in Direct3D11 backend. -class FramebufferVkImpl final : public FramebufferBase +class FramebufferVkImpl final : public FramebufferBase { public: - using TFramebufferBase = FramebufferBase; + using TFramebufferBase = FramebufferBase; FramebufferVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, const FramebufferDesc& Desc); ~FramebufferVkImpl(); + + VkFramebuffer GetVkFramebuffer() const override final + { + return m_VkFramebuffer; + } + +private: + VulkanUtilities::FramebufferWrapper m_VkFramebuffer; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h b/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h new file mode 100644 index 00000000..9edfb2eb --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h @@ -0,0 +1,64 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFramebufferVk interface + +#include "../../GraphicsEngine/interface/Framebuffer.h" + +DILIGENT_BEGIN_NAMESPACE(Diligent) + +// {846BE360-D89B-41AD-B089-7F2439ADCE3A} +static const INTERFACE_ID IID_FramebufferVk = + {0x846be360, 0xd89b, 0x41ad, {0xb0, 0x89, 0x7f, 0x24, 0x39, 0xad, 0xce, 0x3a}}; + +#define DILIGENT_INTERFACE_NAME IFramebufferVk +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + +#define IFramebufferVkInclusiveMethods \ + /*IFramebufferInclusiveMethods*/ IDeviceObjectInclusiveMethods; \ + IFramebufferVkMethods FramebufferVk + +/// Exposes Vulkan-specific functionality of a Framebuffer object. +DILIGENT_BEGIN_INTERFACE(IFramebufferVk, IFramebuffer) +{ + /// Returns a Vulkan framebuffer object handle + VIRTUAL VkFramebuffer METHOD(GetVkFramebuffer)() CONST PURE; +}; +DILIGENT_END_INTERFACE + +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" + +#if DILIGENT_C_INTERFACE + +# define IFramebufferVk_GetVkFramebuffer(This) CALL_IFACE_METHOD(FramebufferVk, GetVkFramebuffer, This) + +#endif + +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp index ba515950..2fc81319 100644 --- a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp @@ -27,8 +27,12 @@ #include "pch.h" +#include + #include "FramebufferVkImpl.hpp" #include "EngineMemory.h" +#include "RenderPassVkImpl.hpp" +#include "TextureViewVkImpl.hpp" namespace Diligent { @@ -38,6 +42,38 @@ FramebufferVkImpl::FramebufferVkImpl(IReferenceCounters* pRefCounters, const FramebufferDesc& Desc) : TFramebufferBase{pRefCounters, pDevice, Desc} { + VkFramebufferCreateInfo FramebufferCI = {}; + + FramebufferCI.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + FramebufferCI.pNext = nullptr; + FramebufferCI.flags = 0; + + auto* pRenderPassVkImpl = ValidatedCast(m_Desc.pRenderPass); + FramebufferCI.renderPass = pRenderPassVkImpl->GetVkRenderPass(); + + FramebufferCI.attachmentCount = m_Desc.AttachmentCount; + + std::vector vkImgViews(m_Desc.AttachmentCount); + for (Uint32 i = 0; i < m_Desc.AttachmentCount; ++i) + { + if (auto* pView = m_Desc.ppAttachments[i]) + { + vkImgViews[i] = ValidatedCast(pView)->GetVulkanImageView(); + } + } + FramebufferCI.pAttachments = vkImgViews.data(); + + FramebufferCI.width = m_Desc.Width; + FramebufferCI.height = m_Desc.Height; + FramebufferCI.layers = m_Desc.NumArraySlices; + + const auto& LogicalDevice = pDevice->GetLogicalDevice(); + + m_VkFramebuffer = LogicalDevice.CreateFramebuffer(FramebufferCI, m_Desc.Name); + if (!m_VkFramebuffer) + { + LOG_ERROR_AND_THROW("Failed to create Vulkan framebuffer"); + } } FramebufferVkImpl::~FramebufferVkImpl() diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 23483370..5ebab9c1 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -52,7 +52,7 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, auto& vkAttachment = vkAttachments[i]; vkAttachment.flags = 0; vkAttachment.format = TexFormatToVkFormat(Attachment.Format); - vkAttachment.samples = static_cast(0x01 << (Attachment.SampleCount - 1)); + vkAttachment.samples = static_cast(Attachment.SampleCount); vkAttachment.loadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.LoadOp); vkAttachment.storeOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StoreOp); vkAttachment.stencilLoadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.StencilLoadOp); diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 2a634162..ca04f900 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -139,6 +139,10 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters, { ImageCI.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; } + if (m_Desc.BindFlags & BIND_INPUT_ATTACHMENT) + { + ImageCI.usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + } if (m_Desc.MiscFlags & MISC_TEXTURE_FLAG_GENERATE_MIPS) { -- cgit v1.2.3 From 0ffb9f5a2b3c9ce7881c1b8853ce4f127d3e816f Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 25 Jul 2020 23:02:04 -0700 Subject: Added static asserts for Attachment Load/Store enums --- Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 592f9522..3d34813f 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1421,21 +1421,25 @@ VkSurfaceTransformFlagBitsKHR SurfaceTransformToVkSurfaceTransformFlag(SURFACE_T // clang-format on } +static_assert(ATTACHMENT_LOAD_OP_LOAD == VK_ATTACHMENT_LOAD_OP_LOAD, "ATTACHMENT_LOAD_OP_LOAD is not equal to VK_ATTACHMENT_LOAD_OP_LOAD"); +static_assert(ATTACHMENT_LOAD_OP_CLEAR == VK_ATTACHMENT_LOAD_OP_CLEAR, "ATTACHMENT_LOAD_OP_CLEAR is not equal to VK_ATTACHMENT_LOAD_OP_CLEAR"); +static_assert(ATTACHMENT_LOAD_OP_DONT_CARE == VK_ATTACHMENT_LOAD_OP_DONT_CARE, "ATTACHMENT_LOAD_OP_DONT_CARE is not equal to VK_ATTACHMENT_LOAD_OP_DONT_CARE"); VkAttachmentLoadOp AttachmentLoadOpToVkAttachmentLoadOp(ATTACHMENT_LOAD_OP LoadOp) { return static_cast(LoadOp); } - ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoadOp) { return static_cast(VkLoadOp); } + +static_assert(ATTACHMENT_STORE_OP_STORE == VK_ATTACHMENT_STORE_OP_STORE, "ATTACHMENT_STORE_OP_STORE is not equal to VK_ATTACHMENT_STORE_OP_STORE"); +static_assert(ATTACHMENT_STORE_OP_DONT_CARE == VK_ATTACHMENT_STORE_OP_DONT_CARE, "ATTACHMENT_STORE_OP_DONT_CARE is not equal to VK_ATTACHMENT_STORE_OP_DONT_CARE"); VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp) { return static_cast(StoreOp); } - ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp VkStoreOp) { return static_cast(VkStoreOp); -- cgit v1.2.3 From 2a37e90153caf4aaa1c9d4aa9f082678feb29756 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 26 Jul 2020 11:59:04 -0700 Subject: Added PIPELINE_STAGE_FLAGS and ACCESS_FLAGS --- .../include/VulkanTypeConversions.hpp | 3 ++ .../src/VulkanTypeConversions.cpp | 61 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp index c680c22d..741ced4f 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp @@ -79,4 +79,7 @@ ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoa VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp); ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp VkStoreOp); +VkPipelineStageFlags PipelineStageFlagsToVkPipelineStageFlags(PIPELINE_STAGE_FLAGS PipelineStageFlags); +VkAccessFlags AccessFlagsToVkAccessFlags(ACCESS_FLAGS AccessFlags); + } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 3d34813f..939c8e9d 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1445,4 +1445,65 @@ ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp V return static_cast(VkStoreOp); } + +// clang-format off +static_assert(PIPELINE_STAGE_FLAG_TOP_OF_PIPE == VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "PIPELINE_STAGE_FLAG_TOP_OF_PIPE != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT"); +static_assert(PIPELINE_STAGE_FLAG_DRAW_INDIRECT == VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, "PIPELINE_STAGE_FLAG_DRAW_INDIRECT != VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT"); +static_assert(PIPELINE_STAGE_FLAG_VERTEX_INPUT == VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, "PIPELINE_STAGE_FLAG_VERTEX_INPUT != VK_PIPELINE_STAGE_VERTEX_INPUT_BIT"); +static_assert(PIPELINE_STAGE_FLAG_VERTEX_SHADER == VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, "PIPELINE_STAGE_FLAG_VERTEX_SHADER != VK_PIPELINE_STAGE_VERTEX_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_HULL_SHADER == VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT, "PIPELINE_STAGE_FLAG_HULL_SHADER != VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_DOMAIN_SHADER == VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT, "PIPELINE_STAGE_FLAG_DOMAIN_SHADER != VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_GEOMETRY_SHADER == VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT, "PIPELINE_STAGE_FLAG_GEOMETRY_SHADER != VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_FRAGMENT_SHADER == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, "PIPELINE_STAGE_FLAG_FRAGMENT_SHADER != VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS == VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS != VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT"); +static_assert(PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS == VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS != VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT"); +static_assert(PIPELINE_STAGE_FLAG_RENDER_TARGET == VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, "PIPELINE_STAGE_FLAG_RENDER_TARGET != VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT"); +static_assert(PIPELINE_STAGE_FLAG_COMPUTE_SHADER == VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, "PIPELINE_STAGE_FLAG_COMPUTE_SHADER != VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_TRANSFER == VK_PIPELINE_STAGE_TRANSFER_BIT, "PIPELINE_STAGE_FLAG_TRANSFER != VK_PIPELINE_STAGE_TRANSFER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_BOTTOM_OF_PIPE == VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "PIPELINE_STAGE_FLAG_BOTTOM_OF_PIPE != VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT"); +static_assert(PIPELINE_STAGE_FLAG_HOST == VK_PIPELINE_STAGE_HOST_BIT, "PIPELINE_STAGE_FLAG_HOST != VK_PIPELINE_STAGE_HOST_BIT"); +static_assert(PIPELINE_STAGE_FLAG_CONDITIONAL_RENDERING == VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT, "PIPELINE_STAGE_FLAG_CONDITIONAL_RENDERING != VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT"); +static_assert(PIPELINE_STAGE_FLAG_SHADING_RATE_TEXTURE == VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV, "PIPELINE_STAGE_FLAG_SHADING_RATE_IMAGE != VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV"); +static_assert(PIPELINE_STAGE_FLAG_RAY_TRACING_SHADER == VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_RAY_TRACING_SHADER != VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV"); +static_assert(PIPELINE_STAGE_FLAG_ACCELERATION_STRUCTURE_BUILD == VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_NV, "PIPELINE_STAGE_FLAG_ACCELERATION_STRUCTURE_BUILD != VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_NV"); +static_assert(PIPELINE_STAGE_FLAG_TASK_SHADER == VK_PIPELINE_STAGE_TASK_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_TASK_SHADER != VK_PIPELINE_STAGE_TASK_SHADER_BIT_NV"); +static_assert(PIPELINE_STAGE_FLAG_MESH_SHADER == VK_PIPELINE_STAGE_MESH_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_MESH_SHADER != VK_PIPELINE_STAGE_MESH_SHADER_BIT_NV"); +static_assert(PIPELINE_STAGE_FLAG_FRAGMENT_DENSITY_PROCESS == VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT, "PIPELINE_STAGE_FLAG_FRAGMENT_DENSITY_PROCESS != VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT"); +// clang-format on +VkPipelineStageFlags PipelineStageFlagsToVkPipelineStageFlags(PIPELINE_STAGE_FLAGS PipelineStageFlags) +{ + return static_cast(PipelineStageFlags); +} + + +// clang-format off +static_assert(ACCESS_FLAG_NONE == 0, ""); +static_assert(ACCESS_FLAG_INDIRECT_COMMAND_READ == VK_ACCESS_INDIRECT_COMMAND_READ_BIT, "ACCESS_FLAG_INDIRECT_COMMAND_READ != VK_ACCESS_INDIRECT_COMMAND_READ_BIT"); +static_assert(ACCESS_FLAG_INDEX_READ == VK_ACCESS_INDEX_READ_BIT, "ACCESS_FLAG_INDEX_READ != VK_ACCESS_INDEX_READ_BIT"); +static_assert(ACCESS_FLAG_VERTEX_READ == VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, "ACCESS_FLAG_VERTEX_READ != VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT"); +static_assert(ACCESS_FLAG_UNIFORM_READ == VK_ACCESS_UNIFORM_READ_BIT, "ACCESS_FLAG_UNIFORM_READ != VK_ACCESS_UNIFORM_READ_BIT"); +static_assert(ACCESS_FLAG_INPUT_ATTACHMENT_READ == VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, "ACCESS_FLAG_INPUT_ATTACHMENT_READ != VK_ACCESS_INPUT_ATTACHMENT_READ_BIT"); +static_assert(ACCESS_FLAG_SHADER_READ == VK_ACCESS_SHADER_READ_BIT, "ACCESS_FLAG_SHADER_READ != VK_ACCESS_SHADER_READ_BIT"); +static_assert(ACCESS_FLAG_SHADER_WRITE == VK_ACCESS_SHADER_WRITE_BIT, "ACCESS_FLAG_SHADER_WRITE != VK_ACCESS_SHADER_WRITE_BIT"); +static_assert(ACCESS_FLAG_RENDER_TARGET_READ == VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "ACCESS_FLAG_RENDER_TARGET_READ != VK_ACCESS_COLOR_ATTACHMENT_READ_BIT"); +static_assert(ACCESS_FLAG_RENDER_TARGET_WRITE == VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "ACCESS_FLAG_RENDER_TARGET_WRITE != VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT"); +static_assert(ACCESS_FLAG_DEPTH_STENCIL_READ == VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, "ACCESS_FLAG_DEPTH_STENCIL_READ != VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT"); +static_assert(ACCESS_FLAG_DEPTH_STENCIL_WRITE == VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, "ACCESS_FLAG_DEPTH_STENCIL_WRITE != VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT"); +static_assert(ACCESS_FLAG_COPY_SRC == VK_ACCESS_TRANSFER_READ_BIT, "ACCESS_FLAG_COPY_SRC != VK_ACCESS_TRANSFER_READ_BIT"); +static_assert(ACCESS_FLAG_COPY_DST == VK_ACCESS_TRANSFER_WRITE_BIT, "ACCESS_FLAG_COPY_DST != VK_ACCESS_TRANSFER_WRITE_BIT"); +static_assert(ACCESS_FLAG_HOST_READ == VK_ACCESS_HOST_READ_BIT, "ACCESS_FLAG_HOST_READ != VK_ACCESS_HOST_READ_BIT"); +static_assert(ACCESS_FLAG_HOST_WRITE == VK_ACCESS_HOST_WRITE_BIT, "ACCESS_FLAG_HOST_WRITE != VK_ACCESS_HOST_WRITE_BIT"); +static_assert(ACCESS_FLAG_MEMORY_READ == VK_ACCESS_MEMORY_READ_BIT, "ACCESS_FLAG_MEMORY_READ != VK_ACCESS_MEMORY_READ_BIT"); +static_assert(ACCESS_FLAG_MEMORY_WRITE == VK_ACCESS_MEMORY_WRITE_BIT, "ACCESS_FLAG_MEMORY_WRITE != VK_ACCESS_MEMORY_WRITE_BIT"); +static_assert(ACCESS_FLAG_CONDITIONAL_RENDERING_READ == VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT, "ACCESS_FLAG_CONDITIONAL_RENDERING_READ != VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT"); +static_assert(ACCESS_FLAG_SHADING_RATE_TEXTURE_READ == VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV, "ACCESS_FLAG_SHADING_RATE_TEXTURE_READ != VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV"); +static_assert(ACCESS_FLAG_ACCELERATION_STRUCTURE_READ == VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV, "ACCESS_FLAG_ACCELERATION_STRUCTURE_READ != VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV"); +static_assert(ACCESS_FLAG_ACCELERATION_STRUCTURE_WRITE == VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NV, "ACCESS_FLAG_ACCELERATION_STRUCTURE_WRITE != VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NV"); +static_assert(ACCESS_FLAG_FRAGMENT_DENSITY_MAP_READ == VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT, "ACCESS_FLAG_FRAGMENT_DENSITY_MAP_READ != VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT"); +// clang-format on +VkAccessFlags AccessFlagsToVkAccessFlags(ACCESS_FLAGS AccessFlags) +{ + return static_cast(AccessFlags); +} + } // namespace Diligent -- cgit v1.2.3 From dfa7d46a0cf961d77be6d4a93eba1831935224f7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 26 Jul 2020 12:56:01 -0700 Subject: Implemented SubpassDependencyDesc struct --- Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 16 ++++++++++++++-- .../GraphicsEngineVulkan/src/VulkanTypeConversions.cpp | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 5ebab9c1..67731739 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -129,9 +129,21 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderPassCI.subpassCount = Desc.SubpassCount; RenderPassCI.pSubpasses = vkSubpasses.data(); - + std::vector vkDependencies(Desc.DependencyCount); + for (Uint32 i = 0; i < Desc.DependencyCount; ++i) + { + const auto& DependencyDesc = m_Desc.pDependencies[i]; + auto& vkDependency = vkDependencies[i]; + vkDependency.srcSubpass = DependencyDesc.SrcSubpass; + vkDependency.dstSubpass = DependencyDesc.DstSubpass; + vkDependency.srcStageMask = DependencyDesc.SrcStageMask; + vkDependency.dstStageMask = DependencyDesc.DstStageMask; + vkDependency.srcAccessMask = DependencyDesc.SrcAccessMask; + vkDependency.dstAccessMask = DependencyDesc.DstAccessMask; + vkDependency.dependencyFlags = 0; + } RenderPassCI.dependencyCount = Desc.DependencyCount; - RenderPassCI.pDependencies; + RenderPassCI.pDependencies = vkDependencies.data(); const auto& LogicalDevice = pDevice->GetLogicalDevice(); diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 939c8e9d..01596a78 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1454,7 +1454,7 @@ static_assert(PIPELINE_STAGE_FLAG_VERTEX_SHADER == VK_PIPELINE_ST static_assert(PIPELINE_STAGE_FLAG_HULL_SHADER == VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT, "PIPELINE_STAGE_FLAG_HULL_SHADER != VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT"); static_assert(PIPELINE_STAGE_FLAG_DOMAIN_SHADER == VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT, "PIPELINE_STAGE_FLAG_DOMAIN_SHADER != VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT"); static_assert(PIPELINE_STAGE_FLAG_GEOMETRY_SHADER == VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT, "PIPELINE_STAGE_FLAG_GEOMETRY_SHADER != VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_FRAGMENT_SHADER == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, "PIPELINE_STAGE_FLAG_FRAGMENT_SHADER != VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT"); +static_assert(PIPELINE_STAGE_FLAG_PIXEL_SHADER == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, "PIPELINE_STAGE_FLAG_PIXEL_SHADER != VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT"); static_assert(PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS == VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS != VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT"); static_assert(PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS == VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS != VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT"); static_assert(PIPELINE_STAGE_FLAG_RENDER_TARGET == VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, "PIPELINE_STAGE_FLAG_RENDER_TARGET != VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT"); -- cgit v1.2.3 From 8798aa2e94602372a61c362d5c3f288cc07388c9 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 26 Jul 2020 19:16:18 -0700 Subject: Added BeginRenderPass, NextSubpass, and EndRenderPass device context methods --- .../GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp | 9 +++++++++ Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 83e2c077..50d1eb0c 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -133,6 +133,15 @@ public: ITextureView* pDepthStencil, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + /// Implementation of IDeviceContext::BeginRenderPass() in Direct3D11 backend. + virtual void DILIGENT_CALL_TYPE BeginRenderPass(const BeginRenderPassAttribs& Attribs) override final; + + /// Implementation of IDeviceContext::NextSubpass() in Direct3D11 backend. + virtual void DILIGENT_CALL_TYPE NextSubpass() override final; + + /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. + virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + // clang-format off /// Implementation of IDeviceContext::Draw() in Vulkan backend. virtual void DILIGENT_CALL_TYPE Draw (const DrawAttribs& Attribs) override final; diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d61ddc97..efa7e34b 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1190,6 +1190,21 @@ void DeviceContextVkImpl::ResetRenderTargets() m_CommandBuffer.EndRenderPass(); } +void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) +{ + UNEXPECTED("Method not implemented"); +} + +void DeviceContextVkImpl::NextSubpass() +{ + UNEXPECTED("Method not implemented"); +} + +void DeviceContextVkImpl::EndRenderPass() +{ + UNEXPECTED("Method not implemented"); +} + void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl* pBuffVk, Uint64 DstOffset, Uint64 NumBytes, -- cgit v1.2.3 From c778652b7fd834aeee7ca046d1a8d1e1d0a9f5e4 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 31 Jul 2020 19:47:37 -0700 Subject: PipelineStateVkImpl: creating implicit IRenderPass object instead of Vulkan render pass --- .../include/PipelineStateVkImpl.hpp | 19 ++- .../include/RenderDeviceVkImpl.hpp | 9 +- .../include/RenderPassCache.hpp | 13 +- .../include/RenderPassVkImpl.hpp | 3 +- .../interface/PipelineStateVk.h | 9 +- .../src/DeviceContextVkImpl.cpp | 7 +- .../src/PipelineStateVkImpl.cpp | 143 ++++++++++----------- .../src/RenderDeviceVkImpl.cpp | 23 ++-- .../GraphicsEngineVulkan/src/RenderPassCache.cpp | 32 +++-- .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 5 +- 10 files changed, 140 insertions(+), 123 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index aca69cac..b8d5b0ec 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -68,8 +68,8 @@ public: /// Implementation of IPipelineState::IsCompatibleWith() in Vulkan backend. virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineState* pPSO) const override final; - /// Implementation of IPipelineStateVk::GetVkRenderPass(). - virtual VkRenderPass DILIGENT_CALL_TYPE GetVkRenderPass() const override final { return m_RenderPass; } + /// Implementation of IPipelineStateVk::GetRenderPass(). + virtual IRenderPassVk* DILIGENT_CALL_TYPE GetRenderPass() const override final { return m_pRenderPass.RawPtr(); } /// Implementation of IPipelineStateVk::GetVkPipeline(). virtual VkPipeline DILIGENT_CALL_TYPE GetVkPipeline() const override final { return m_Pipeline; } @@ -113,13 +113,13 @@ public: return m_SRBMemAllocator; } - static VkRenderPassCreateInfo GetRenderPassCreateInfo(Uint32 NumRenderTargets, - const TEXTURE_FORMAT RTVFormats[], - TEXTURE_FORMAT DSVFormat, - Uint32 SampleCount, - std::array& Attachments, - std::array& AttachmentReferences, - VkSubpassDescription& SubpassDesc); + static RenderPassDesc GetImplicitRenderPassDesc(Uint32 NumRenderTargets, + const TEXTURE_FORMAT RTVFormats[], + TEXTURE_FORMAT DSVFormat, + Uint8 SampleCount, + std::array& Attachments, + std::array& AttachmentReferences, + SubpassDesc& SubpassDesc); void InitializeStaticSRBResources(ShaderResourceCacheVk& ResourceCache) const; @@ -152,7 +152,6 @@ private: std::array m_ShaderModules; - VkRenderPass m_RenderPass = VK_NULL_HANDLE; // Render passes are managed by the render device VulkanUtilities::PipelineWrapper m_Pipeline; PipelineLayout m_PipelineLayout; diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp index 6ec79aad..38bd4893 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp @@ -102,6 +102,11 @@ public: virtual void DILIGENT_CALL_TYPE CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) override final; + void CreateRenderPass(const RenderPassDesc& Desc, + IRenderPass** ppRenderPass, + bool IsDeviceInternal); + + /// Implementation of IRenderDevice::CreateFramebuffer() in Vulkan backend. virtual void DILIGENT_CALL_TYPE CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer) override final; @@ -152,7 +157,7 @@ public: const VulkanUtilities::VulkanLogicalDevice& GetLogicalDevice() { return *m_LogicalVkDevice; } FramebufferCache& GetFramebufferCache() { return m_FramebufferCache; } - RenderPassCache& GetRenderPassCache() { return m_RenderPassCache; } + RenderPassCache& GetImplicitRenderPassCache() { return m_ImplicitRenderPassCache; } VulkanUtilities::VulkanMemoryAllocation AllocateMemory(const VkMemoryRequirements& MemReqs, VkMemoryPropertyFlags MemoryProperties) { @@ -181,7 +186,7 @@ private: EngineVkCreateInfo m_EngineAttribs; FramebufferCache m_FramebufferCache; - RenderPassCache m_RenderPassCache; + RenderPassCache m_ImplicitRenderPassCache; DescriptorSetAllocator m_DescriptorSetAllocator; DescriptorPoolManager m_DynamicDescriptorPool; diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp index bfab6c53..d2def841 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp @@ -36,17 +36,18 @@ #include "Constants.h" #include "HashUtils.hpp" #include "VulkanUtilities/VulkanObjectWrappers.hpp" +#include "RefCntAutoPtr.hpp" namespace Diligent { class RenderDeviceVkImpl; +class RenderPassVkImpl; + class RenderPassCache { public: - RenderPassCache(RenderDeviceVkImpl& DeviceVk) noexcept : - m_DeviceVkImpl{DeviceVk} - {} + RenderPassCache(RenderDeviceVkImpl& DeviceVk) noexcept; // clang-format off RenderPassCache (const RenderPassCache&) = delete; @@ -123,7 +124,7 @@ public: mutable size_t Hash = 0; }; - VkRenderPass GetRenderPass(const RenderPassCacheKey& Key); + RenderPassVkImpl* GetRenderPass(const RenderPassCacheKey& Key); private: struct RenderPassCacheKeyHash @@ -136,8 +137,8 @@ private: RenderDeviceVkImpl& m_DeviceVkImpl; - std::mutex m_Mutex; - std::unordered_map m_Cache; + std::mutex m_Mutex; + std::unordered_map, RenderPassCacheKeyHash> m_Cache; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp index 9cf34e08..5c77784f 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassVkImpl.hpp @@ -49,7 +49,8 @@ public: RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, - const RenderPassDesc& Desc); + const RenderPassDesc& Desc, + bool IsDeviceInternal); ~RenderPassVkImpl(); /// Implementation of ISamplerVk::GetVkRenderPass(). diff --git a/Graphics/GraphicsEngineVulkan/interface/PipelineStateVk.h b/Graphics/GraphicsEngineVulkan/interface/PipelineStateVk.h index 679b6e73..f3377f08 100644 --- a/Graphics/GraphicsEngineVulkan/interface/PipelineStateVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/PipelineStateVk.h @@ -31,6 +31,7 @@ /// Definition of the Diligent::IPipeplineStateVk interface #include "../../GraphicsEngine/interface/PipelineState.h" +#include "RenderPassVk.h" DILIGENT_BEGIN_NAMESPACE(Diligent) @@ -48,8 +49,8 @@ static const INTERFACE_ID IID_PipelineStateVk = /// Exposes Vulkan-specific functionality of a pipeline state object. DILIGENT_BEGIN_INTERFACE(IPipelineStateVk, IPipelineState) { - /// Returns handle to a vulkan render pass object. - VIRTUAL VkRenderPass METHOD(GetVkRenderPass)(THIS) CONST PURE; + /// Returns the pointer to the internal render pass object. + VIRTUAL IRenderPassVk* METHOD(GetRenderPass)(THIS) CONST PURE; /// Returns handle to a vulkan pipeline pass object. VIRTUAL VkPipeline METHOD(GetVkPipeline)(THIS) CONST PURE; @@ -62,8 +63,8 @@ DILIGENT_END_INTERFACE // clang-format off -# define IPipelineStateVk_GetVkRenderPass(This) CALL_IFACE_METHOD(PipelineStateVk, GetVkRenderPass, This) -# define IPipelineStateVk_GetVkPipeline(This) CALL_IFACE_METHOD(PipelineStateVk, GetVkPipeline, This) +# define IPipelineStateVk_GetRenderPass(This) CALL_IFACE_METHOD(PipelineStateVk, GetRenderPass, This) +# define IPipelineStateVk_GetVkPipeline(This) CALL_IFACE_METHOD(PipelineStateVk, GetVkPipeline, This) // clang-format on diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index efa7e34b..7fef3833 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -32,6 +32,7 @@ #include "PipelineStateVkImpl.hpp" #include "TextureVkImpl.hpp" #include "BufferVkImpl.hpp" +#include "RenderPassVkImpl.hpp" #include "VulkanTypeConversions.hpp" #include "CommandListVkImpl.hpp" #include "FenceVkImpl.hpp" @@ -461,7 +462,7 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) #endif #ifdef DILIGENT_DEVELOPMENT - if (m_pPipelineState->GetVkRenderPass() != m_RenderPass) + if (m_pPipelineState->GetRenderPass()->GetVkRenderPass() != m_RenderPass) { DvpLogRenderPass_PSOMismatch(); } @@ -1163,9 +1164,9 @@ void DeviceContextVkImpl::SetRenderTargets(Uint32 NumRen } auto& FBCache = m_pDevice->GetFramebufferCache(); - auto& RPCache = m_pDevice->GetRenderPassCache(); + auto& RPCache = m_pDevice->GetImplicitRenderPassCache(); - m_RenderPass = RPCache.GetRenderPass(RenderPassKey); + m_RenderPass = RPCache.GetRenderPass(RenderPassKey)->GetVkRenderPass(); FBKey.Pass = m_RenderPass; FBKey.CommandQueueMask = ~Uint64{0}; m_Framebuffer = FBCache.GetFramebuffer(FBKey, m_FramebufferWidth, m_FramebufferHeight, m_FramebufferSlices); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 99b27d2c..4355b453 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -32,10 +32,12 @@ #include "VulkanTypeConversions.hpp" #include "RenderDeviceVkImpl.hpp" #include "DeviceContextVkImpl.hpp" +#include "RenderPassVkImpl.hpp" #include "ShaderResourceBindingVkImpl.hpp" #include "EngineMemory.h" #include "StringTools.hpp" + #if !DILIGENT_NO_HLSL # include "spirv-tools/optimizer.hpp" #endif @@ -43,97 +45,88 @@ namespace Diligent { -VkRenderPassCreateInfo PipelineStateVkImpl::GetRenderPassCreateInfo( - Uint32 NumRenderTargets, - const TEXTURE_FORMAT RTVFormats[], - TEXTURE_FORMAT DSVFormat, - Uint32 SampleCount, - std::array& Attachments, - std::array& AttachmentReferences, - VkSubpassDescription& SubpassDesc) +RenderPassDesc PipelineStateVkImpl::GetImplicitRenderPassDesc( + Uint32 NumRenderTargets, + const TEXTURE_FORMAT RTVFormats[], + TEXTURE_FORMAT DSVFormat, + Uint8 SampleCount, + std::array& Attachments, + std::array& AttachmentReferences, + SubpassDesc& SubpassDesc) { VERIFY_EXPR(NumRenderTargets <= MAX_RENDER_TARGETS); - // Prepare render pass create info (7.1) - VkRenderPassCreateInfo RenderPassCI = {}; + RenderPassDesc RPDesc; - RenderPassCI.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - RenderPassCI.pNext = nullptr; - RenderPassCI.flags = 0; // reserved for future use - RenderPassCI.attachmentCount = (DSVFormat != TEX_FORMAT_UNKNOWN ? 1 : 0) + NumRenderTargets; + RPDesc.AttachmentCount = (DSVFormat != TEX_FORMAT_UNKNOWN ? 1 : 0) + NumRenderTargets; - uint32_t AttachmentInd = 0; - VkSampleCountFlagBits SampleCountFlags = static_cast(SampleCount); - VkAttachmentReference* pDepthAttachmentReference = nullptr; + uint32_t AttachmentInd = 0; + AttachmentReference* pDepthAttachmentReference = nullptr; if (DSVFormat != TEX_FORMAT_UNKNOWN) { auto& DepthAttachment = Attachments[AttachmentInd]; - DepthAttachment.flags = 0; // Allowed value VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT - DepthAttachment.format = TexFormatToVkFormat(DSVFormat); - DepthAttachment.samples = SampleCountFlags; - DepthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; // previous contents of the image within the render area - // will be preserved. For attachments with a depth/stencil format, - // this uses the access type VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT. - DepthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; // the contents generated during the render pass and within the render - // area are written to memory. For attachments with a depth/stencil format, - // this uses the access type VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT. - DepthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; - DepthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; - DepthAttachment.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - DepthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - - pDepthAttachmentReference = &AttachmentReferences[AttachmentInd]; - pDepthAttachmentReference->attachment = AttachmentInd; - pDepthAttachmentReference->layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + DepthAttachment.Format = DSVFormat; + DepthAttachment.SampleCount = SampleCount; + DepthAttachment.LoadOp = ATTACHMENT_LOAD_OP_LOAD; // previous contents of the image within the render area + // will be preserved. For attachments with a depth/stencil format, + // this uses the access type VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT. + DepthAttachment.StoreOp = ATTACHMENT_STORE_OP_STORE; // the contents generated during the render pass and within the render + // area are written to memory. For attachments with a depth/stencil format, + // this uses the access type VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT. + DepthAttachment.StencilLoadOp = ATTACHMENT_LOAD_OP_LOAD; + DepthAttachment.StencilStoreOp = ATTACHMENT_STORE_OP_STORE; + DepthAttachment.InitialState = RESOURCE_STATE_DEPTH_WRITE; + DepthAttachment.FinalState = RESOURCE_STATE_DEPTH_WRITE; + + pDepthAttachmentReference = &AttachmentReferences[AttachmentInd]; + pDepthAttachmentReference->AttachmentIndex = AttachmentInd; + pDepthAttachmentReference->State = RESOURCE_STATE_DEPTH_WRITE; ++AttachmentInd; } - VkAttachmentReference* pColorAttachmentsReference = NumRenderTargets > 0 ? &AttachmentReferences[AttachmentInd] : nullptr; + AttachmentReference* pColorAttachmentsReference = NumRenderTargets > 0 ? &AttachmentReferences[AttachmentInd] : nullptr; for (Uint32 rt = 0; rt < NumRenderTargets; ++rt, ++AttachmentInd) { auto& ColorAttachment = Attachments[AttachmentInd]; - ColorAttachment.flags = 0; // Allowed value VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT - ColorAttachment.format = TexFormatToVkFormat(RTVFormats[rt]); - ColorAttachment.samples = SampleCountFlags; - ColorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; // previous contents of the image within the render area - // will be preserved. For attachments with a depth/stencil format, - // this uses the access type VK_ACCESS_COLOR_ATTACHMENT_READ_BIT. - ColorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; // the contents generated during the render pass and within the render - // area are written to memory. For attachments with a color format, - // this uses the access type VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT. - ColorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - ColorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - ColorAttachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - ColorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - - auto& ColorAttachmentRef = AttachmentReferences[AttachmentInd]; - ColorAttachmentRef.attachment = AttachmentInd; - ColorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + ColorAttachment.Format = RTVFormats[rt]; + ColorAttachment.SampleCount = SampleCount; + ColorAttachment.LoadOp = ATTACHMENT_LOAD_OP_LOAD; // previous contents of the image within the render area + // will be preserved. For attachments with a depth/stencil format, + // this uses the access type VK_ACCESS_COLOR_ATTACHMENT_READ_BIT. + ColorAttachment.StoreOp = ATTACHMENT_STORE_OP_STORE; // the contents generated during the render pass and within the render + // area are written to memory. For attachments with a color format, + // this uses the access type VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT. + ColorAttachment.StencilLoadOp = ATTACHMENT_LOAD_OP_DONT_CARE; + ColorAttachment.StencilStoreOp = ATTACHMENT_STORE_OP_DONT_CARE; + ColorAttachment.InitialState = RESOURCE_STATE_RENDER_TARGET; + ColorAttachment.FinalState = RESOURCE_STATE_RENDER_TARGET; + + auto& ColorAttachmentRef = AttachmentReferences[AttachmentInd]; + ColorAttachmentRef.AttachmentIndex = AttachmentInd; + ColorAttachmentRef.State = RESOURCE_STATE_RENDER_TARGET; } - RenderPassCI.pAttachments = Attachments.data(); - RenderPassCI.subpassCount = 1; - RenderPassCI.pSubpasses = &SubpassDesc; - RenderPassCI.dependencyCount = 0; // the number of dependencies between pairs of subpasses, or zero indicating no dependencies. - RenderPassCI.pDependencies = nullptr; // an array of dependencyCount number of VkSubpassDependency structures describing - // dependencies between pairs of subpasses, or NULL if dependencyCount is zero. - - - SubpassDesc.flags = 0; // All bits for this type are defined by extensions - SubpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; // Currently, only graphics subpasses are supported. - SubpassDesc.inputAttachmentCount = 0; - SubpassDesc.pInputAttachments = nullptr; - SubpassDesc.colorAttachmentCount = NumRenderTargets; - SubpassDesc.pColorAttachments = pColorAttachmentsReference; - SubpassDesc.pResolveAttachments = nullptr; - SubpassDesc.pDepthStencilAttachment = pDepthAttachmentReference; - SubpassDesc.preserveAttachmentCount = 0; - SubpassDesc.pPreserveAttachments = nullptr; - - return RenderPassCI; + RPDesc.pAttachments = Attachments.data(); + RPDesc.SubpassCount = 1; + RPDesc.pSubpasses = &SubpassDesc; + RPDesc.DependencyCount = 0; // the number of dependencies between pairs of subpasses, or zero indicating no dependencies. + RPDesc.pDependencies = nullptr; // an array of dependencyCount number of VkSubpassDependency structures describing + // dependencies between pairs of subpasses, or NULL if dependencyCount is zero. + + + SubpassDesc.InputAttachmentCount = 0; + SubpassDesc.pInputAttachments = nullptr; + SubpassDesc.RenderTargetAttachmentCount = NumRenderTargets; + SubpassDesc.pRenderTargetAttachments = pColorAttachmentsReference; + SubpassDesc.pResolveAttachments = nullptr; + SubpassDesc.pDepthStencilAttachment = pDepthAttachmentReference; + SubpassDesc.PreserveAttachmentCount = 0; + SubpassDesc.pPreserveAttachments = nullptr; + + return RPDesc; } static std::vector StripReflection(const std::vector& OriginalSPIRV) @@ -295,14 +288,14 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun { const auto& PhysicalDevice = pDeviceVk->GetPhysicalDevice(); auto& GraphicsPipeline = m_Desc.GraphicsPipeline; - auto& RPCache = pDeviceVk->GetRenderPassCache(); + auto& RPCache = pDeviceVk->GetImplicitRenderPassCache(); RenderPassCache::RenderPassCacheKey Key{ GraphicsPipeline.NumRenderTargets, GraphicsPipeline.SmplDesc.Count, GraphicsPipeline.RTVFormats, GraphicsPipeline.DSVFormat}; - m_RenderPass = RPCache.GetRenderPass(Key); + m_pRenderPass = RPCache.GetRenderPass(Key); VkGraphicsPipelineCreateInfo PipelineCI = {}; @@ -442,7 +435,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun PipelineCI.pDynamicState = &DynamicStateCI; - PipelineCI.renderPass = m_RenderPass; + PipelineCI.renderPass = GetRenderPass()->GetVkRenderPass(); PipelineCI.subpass = 0; PipelineCI.basePipelineHandle = VK_NULL_HANDLE; // a pipeline to derive from PipelineCI.basePipelineIndex = 0; // an index into the pCreateInfos parameter to use as a pipeline to derive from diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index d5f38ade..3b8e569a 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -78,12 +78,12 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters* sizeof(FramebufferVkImpl) } }, - m_VulkanInstance {Instance }, - m_PhysicalDevice {std::move(PhysicalDevice)}, - m_LogicalVkDevice {std::move(LogicalDevice) }, - m_EngineAttribs {EngineCI }, - m_FramebufferCache {*this }, - m_RenderPassCache {*this }, + m_VulkanInstance {Instance }, + m_PhysicalDevice {std::move(PhysicalDevice)}, + m_LogicalVkDevice {std::move(LogicalDevice) }, + m_EngineAttribs {EngineCI }, + m_FramebufferCache {*this }, + m_ImplicitRenderPassCache{*this }, m_DescriptorSetAllocator { *this, @@ -622,19 +622,26 @@ void RenderDeviceVkImpl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) ); } -void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) +void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, + IRenderPass** ppRenderPass, + bool IsDeviceInternal) { CreateDeviceObject( "RenderPass", Desc, ppRenderPass, [&]() // { - RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc)); + RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc, IsDeviceInternal)); pRenderPassVk->QueryInterface(IID_RenderPass, reinterpret_cast(ppRenderPass)); OnCreateDeviceObject(pRenderPassVk); } // ); } +void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) +{ + CreateRenderPass(Desc, ppRenderPass, /*IsDeviceInternal = */ false); +} + void RenderDeviceVkImpl::CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer) { CreateDeviceObject("Framebuffer", Desc, ppFramebuffer, diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp index c352c2a9..29b817ce 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp @@ -30,36 +30,42 @@ #include "RenderPassCache.hpp" #include "RenderDeviceVkImpl.hpp" #include "PipelineStateVkImpl.hpp" +#include "RenderPassVkImpl.hpp" namespace Diligent { +RenderPassCache::RenderPassCache(RenderDeviceVkImpl& DeviceVk) noexcept : + m_DeviceVkImpl{DeviceVk} +{} + + RenderPassCache::~RenderPassCache() { auto& FBCache = m_DeviceVkImpl.GetFramebufferCache(); for (auto it = m_Cache.begin(); it != m_Cache.end(); ++it) { - FBCache.OnDestroyRenderPass(it->second); + FBCache.OnDestroyRenderPass(it->second->GetVkRenderPass()); } } -VkRenderPass RenderPassCache::GetRenderPass(const RenderPassCacheKey& Key) +RenderPassVkImpl* RenderPassCache::GetRenderPass(const RenderPassCacheKey& Key) { std::lock_guard Lock{m_Mutex}; auto it = m_Cache.find(Key); if (it == m_Cache.end()) { // Do not zero-intitialize arrays - std::array Attachments; - std::array AttachmentReferences; + std::array Attachments; + std::array AttachmentReferences; - VkSubpassDescription Subpass; + SubpassDesc Subpass; - auto RenderPassCI = - PipelineStateVkImpl::GetRenderPassCreateInfo(Key.NumRenderTargets, Key.RTVFormats, Key.DSVFormat, - Key.SampleCount, Attachments, AttachmentReferences, Subpass); + auto RPDesc = + PipelineStateVkImpl::GetImplicitRenderPassDesc(Key.NumRenderTargets, Key.RTVFormats, Key.DSVFormat, + Key.SampleCount, Attachments, AttachmentReferences, Subpass); std::stringstream PassNameSS; - PassNameSS << "Render pass: RT count: " << Uint32{Key.NumRenderTargets} << "; sample count: " << Uint32{Key.SampleCount} + PassNameSS << "Implicit render pass: RT count: " << Uint32{Key.NumRenderTargets} << "; sample count: " << Uint32{Key.SampleCount} << "; DSV Format: " << GetTextureFormatAttribs(Key.DSVFormat).Name; if (Key.NumRenderTargets > 0) { @@ -69,9 +75,11 @@ VkRenderPass RenderPassCache::GetRenderPass(const RenderPassCacheKey& Key) PassNameSS << (rt > 0 ? ", " : "") << GetTextureFormatAttribs(Key.RTVFormats[rt]).Name; } } - auto RenderPass = m_DeviceVkImpl.GetLogicalDevice().CreateRenderPass(RenderPassCI, PassNameSS.str().c_str()); - VERIFY_EXPR(RenderPass != VK_NULL_HANDLE); - it = m_Cache.emplace(Key, std::move(RenderPass)).first; + + RefCntAutoPtr pRenderPass; + m_DeviceVkImpl.CreateRenderPass(RPDesc, pRenderPass.GetRawDblPtr(), /* IsDeviceInternal = */ true); + VERIFY_EXPR(pRenderPass != nullptr); + it = m_Cache.emplace(Key, std::move(pRenderPass)).first; } return it->second; diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 67731739..37bdc106 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -36,8 +36,9 @@ namespace Diligent RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, - const RenderPassDesc& Desc) : - TRenderPassBase{pRefCounters, pDevice, Desc} + const RenderPassDesc& Desc, + bool IsDeviceInternal) : + TRenderPassBase{pRefCounters, pDevice, Desc, IsDeviceInternal} { VkRenderPassCreateInfo RenderPassCI = {}; -- cgit v1.2.3 From 910f9f8c26b5d9db1dfa0437030d10951486ee3c Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 31 Jul 2020 20:51:27 -0700 Subject: Added pRenderPass and SubpassIndex members to GraphicsPipelineDesc struct --- .../GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 4355b453..92e0dee6 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -290,12 +290,15 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun auto& GraphicsPipeline = m_Desc.GraphicsPipeline; auto& RPCache = pDeviceVk->GetImplicitRenderPassCache(); - RenderPassCache::RenderPassCacheKey Key{ - GraphicsPipeline.NumRenderTargets, - GraphicsPipeline.SmplDesc.Count, - GraphicsPipeline.RTVFormats, - GraphicsPipeline.DSVFormat}; - m_pRenderPass = RPCache.GetRenderPass(Key); + if (m_pRenderPass == nullptr) + { + RenderPassCache::RenderPassCacheKey Key{ + GraphicsPipeline.NumRenderTargets, + GraphicsPipeline.SmplDesc.Count, + GraphicsPipeline.RTVFormats, + GraphicsPipeline.DSVFormat}; + m_pRenderPass = RPCache.GetRenderPass(Key); + } VkGraphicsPipelineCreateInfo PipelineCI = {}; @@ -436,7 +439,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun PipelineCI.renderPass = GetRenderPass()->GetVkRenderPass(); - PipelineCI.subpass = 0; + PipelineCI.subpass = m_Desc.GraphicsPipeline.SubpassIndex; PipelineCI.basePipelineHandle = VK_NULL_HANDLE; // a pipeline to derive from PipelineCI.basePipelineIndex = 0; // an index into the pCreateInfos parameter to use as a pipeline to derive from -- cgit v1.2.3 From b875435c82aa5efbea55ee17719c4a57b171a811 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 31 Jul 2020 23:31:05 -0700 Subject: Base implementation of BeginRenderPass/NextSubpass/EndRenderPass methods --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp | 6 ++++-- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 50d1eb0c..7090f15a 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -45,6 +45,8 @@ #include "TextureVkImpl.hpp" #include "PipelineStateVkImpl.hpp" #include "QueryVkImpl.hpp" +#include "FramebufferVkImpl.hpp" +#include "RenderpassVkImpl.hpp" #include "HashUtils.hpp" #include "ManagedVulkanObject.hpp" #include "QueryManagerVk.hpp" @@ -53,8 +55,6 @@ namespace Diligent { -class RenderDeviceVkImpl; - struct DeviceContextVkImplTraits { using BufferType = BufferVkImpl; @@ -63,6 +63,8 @@ struct DeviceContextVkImplTraits using DeviceType = RenderDeviceVkImpl; using ICommandQueueType = ICommandQueueVk; using QueryType = QueryVkImpl; + using FramebufferType = FramebufferVkImpl; + using RenderPassType = RenderPassVkImpl; }; /// Device context implementation in Vulkan backend. diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 7fef3833..d1528eaa 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1193,16 +1193,19 @@ void DeviceContextVkImpl::ResetRenderTargets() void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) { + TDeviceContextBase::BeginRenderPass(Attribs); UNEXPECTED("Method not implemented"); } void DeviceContextVkImpl::NextSubpass() { + TDeviceContextBase::NextSubpass(); UNEXPECTED("Method not implemented"); } void DeviceContextVkImpl::EndRenderPass() { + TDeviceContextBase::EndRenderPass(); UNEXPECTED("Method not implemented"); } -- cgit v1.2.3 From bce5daa9ce16d42d0ec6da8cc79388417a3dc936 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 00:10:20 -0700 Subject: Fixed minor build issue --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 7090f15a..eb1dd4a2 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -46,7 +46,7 @@ #include "PipelineStateVkImpl.hpp" #include "QueryVkImpl.hpp" #include "FramebufferVkImpl.hpp" -#include "RenderpassVkImpl.hpp" +#include "RenderPassVkImpl.hpp" #include "HashUtils.hpp" #include "ManagedVulkanObject.hpp" #include "QueryManagerVk.hpp" -- cgit v1.2.3 From 465e53fd32f983aadc2e46c6cee3a0d7b836fe64 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 11:46:38 -0700 Subject: Implemented BeginRenderPass/NextSubpass/EndRenderPass in Vulkan backend --- .../include/DeviceContextVkImpl.hpp | 2 + .../VulkanUtilities/VulkanCommandBuffer.hpp | 28 ++++++++--- .../src/DeviceContextVkImpl.cpp | 57 ++++++++++++++++++++-- 3 files changed, 74 insertions(+), 13 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index eb1dd4a2..41a9395d 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -500,6 +500,8 @@ private: std::unique_ptr m_QueryMgr; Int32 m_ActiveQueriesCounter = 0; + + std::vector m_VkClearValues; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp index 1465024b..5b4fc1e7 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.hpp @@ -156,7 +156,12 @@ public: vkCmdDispatchIndirect(m_VkCmdBuffer, Buffer, Offset); } - __forceinline void BeginRenderPass(VkRenderPass RenderPass, VkFramebuffer Framebuffer, uint32_t FramebufferWidth, uint32_t FramebufferHeight) + __forceinline void BeginRenderPass(VkRenderPass RenderPass, + VkFramebuffer Framebuffer, + uint32_t FramebufferWidth, + uint32_t FramebufferHeight, + uint32_t ClearValueCount = 0, + const VkClearValue* pClearValues = nullptr) { VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE); VERIFY(m_State.RenderPass == VK_NULL_HANDLE, "Current pass has not been ended"); @@ -170,13 +175,13 @@ public: BeginInfo.framebuffer = Framebuffer; // The render area MUST be contained within the framebuffer dimensions (7.4) BeginInfo.renderArea = {{0, 0}, {FramebufferWidth, FramebufferHeight}}; - BeginInfo.clearValueCount = 0; - BeginInfo.pClearValues = nullptr; // an array of VkClearValue structures that contains clear values for - // each attachment, if the attachment uses a loadOp value of VK_ATTACHMENT_LOAD_OP_CLEAR - // or if the attachment has a depth/stencil format and uses a stencilLoadOp value of - // VK_ATTACHMENT_LOAD_OP_CLEAR. The array is indexed by attachment number. Only elements - // corresponding to cleared attachments are used. Other elements of pClearValues are - // ignored (7.4) + BeginInfo.clearValueCount = ClearValueCount; + BeginInfo.pClearValues = pClearValues; // an array of VkClearValue structures that contains clear values for + // each attachment, if the attachment uses a loadOp value of VK_ATTACHMENT_LOAD_OP_CLEAR + // or if the attachment has a depth/stencil format and uses a stencilLoadOp value of + // VK_ATTACHMENT_LOAD_OP_CLEAR. The array is indexed by attachment number. Only elements + // corresponding to cleared attachments are used. Other elements of pClearValues are + // ignored (7.4) vkCmdBeginRenderPass(m_VkCmdBuffer, &BeginInfo, VK_SUBPASS_CONTENTS_INLINE // the contents of the subpass will be recorded inline in the @@ -208,6 +213,13 @@ public: } } + __forceinline void NextSubpass() + { + VERIFY(m_State.RenderPass != VK_NULL_HANDLE, "Render pass has not been started"); + VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE); + vkCmdNextSubpass(m_VkCmdBuffer, VK_SUBPASS_CONTENTS_INLINE); + } + __forceinline void EndCommandBuffer() { VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d1528eaa..47e7b76d 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -115,6 +115,8 @@ DeviceContextVkImpl::DeviceContextVkImpl(IReferenceCounters* p RefCntAutoPtr pDummyVB; m_pDevice->CreateBuffer(DummyVBDesc, nullptr, &pDummyVB); m_DummyVB = pDummyVB.RawPtr(); + + m_VkClearValues.reserve(16); } DeviceContextVkImpl::~DeviceContextVkImpl() @@ -279,7 +281,14 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) { m_CommandBuffer.SetStencilReference(m_StencilRef); m_CommandBuffer.SetBlendConstants(m_BlendFactors); - CommitRenderPassAndFramebuffer(true); + if (PSODesc.GraphicsPipeline.pRenderPass == nullptr) + { + CommitRenderPassAndFramebuffer(true); + } + else + { + // Render pass must be committed explicitly + } CommitViewports(); } @@ -468,7 +477,10 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) } #endif - CommitRenderPassAndFramebuffer((Flags & DRAW_FLAG_VERIFY_STATES) != 0); + if (m_pPipelineState->GetDesc().GraphicsPipeline.pRenderPass == nullptr) + { + CommitRenderPassAndFramebuffer((Flags & DRAW_FLAG_VERIFY_STATES) != 0); + } } BufferVkImpl* DeviceContextVkImpl::PrepareIndirectDrawAttribsBuffer(IBuffer* pAttribsBuffer, RESOURCE_STATE_TRANSITION_MODE TransitonMode) @@ -1194,19 +1206,54 @@ void DeviceContextVkImpl::ResetRenderTargets() void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) { TDeviceContextBase::BeginRenderPass(Attribs); - UNEXPECTED("Method not implemented"); + + auto vkRenderPass = m_pActiveRenderPass->GetVkRenderPass(); + + VkFramebuffer vkFramebuffer = VK_NULL_HANDLE; + uint32_t FramebufferWidth = 0; + uint32_t FramebufferHeight = 0; + if (m_pBoundFramebuffer) + { + vkFramebuffer = m_pBoundFramebuffer->GetVkFramebuffer(); + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + FramebufferWidth = FBDesc.Width; + FramebufferHeight = FBDesc.Height; + } + + VkClearValue* pVkClearValues = nullptr; + if (Attribs.ClearValueCount > 0) + { + m_VkClearValues.resize(Attribs.ClearValueCount); + const auto& RPDesc = m_pActiveRenderPass->GetDesc(); + for (Uint32 i = 0; i < std::min(RPDesc.AttachmentCount, Attribs.ClearValueCount); ++i) + { + const auto& ClearVal = Attribs.pClearValues[i]; + auto& vkClearVal = m_VkClearValues[i]; + + vkClearVal.color.float32[0] = ClearVal.Color[0]; + vkClearVal.color.float32[1] = ClearVal.Color[1]; + vkClearVal.color.float32[2] = ClearVal.Color[2]; + vkClearVal.color.float32[3] = ClearVal.Color[3]; + + vkClearVal.depthStencil.depth = ClearVal.DepthStencil.Depth; + vkClearVal.depthStencil.stencil = ClearVal.DepthStencil.Stencil; + } + pVkClearValues = m_VkClearValues.data(); + } + + m_CommandBuffer.BeginRenderPass(vkRenderPass, vkFramebuffer, FramebufferWidth, FramebufferHeight, Attribs.ClearValueCount, pVkClearValues); } void DeviceContextVkImpl::NextSubpass() { TDeviceContextBase::NextSubpass(); - UNEXPECTED("Method not implemented"); + m_CommandBuffer.NextSubpass(); } void DeviceContextVkImpl::EndRenderPass() { TDeviceContextBase::EndRenderPass(); - UNEXPECTED("Method not implemented"); + m_CommandBuffer.EndRenderPass(); } void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl* pBuffVk, -- cgit v1.2.3 From 89e1718309473686f1bae9ef46c501fc1d6e1520 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 14:22:47 -0700 Subject: Implemented ClearRenderTarget/ClearDepthStencil for inside render pass clears --- .../src/DeviceContextVkImpl.cpp | 76 ++++++++++++++++++---- 1 file changed, 65 insertions(+), 11 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 47e7b76d..78dc2f61 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -644,13 +644,37 @@ void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView const auto& ViewDesc = pVkDSV->GetDesc(); VERIFY(ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D, "Depth-stencil view of a 3D texture should've been created as 2D texture array view"); - if (pVkDSV == m_pBoundDepthStencil) + bool ClearAsAttachment = false; + if (m_pActiveRenderPass != nullptr) + { + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + for (Uint32 i = 0; i < FBDesc.AttachmentCount && !ClearAsAttachment; ++i) + { + ClearAsAttachment = FBDesc.ppAttachments[i] == pView; + } + + if (!ClearAsAttachment) + { + UNEXPECTED("DSV was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearDepthStencil " + "checks if the DSV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); + return; + } + } + else + { + ClearAsAttachment = pVkDSV == m_pBoundDepthStencil; + } + + if (ClearAsAttachment) { // Render pass may not be currently committed VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE && m_Framebuffer != VK_NULL_HANDLE); - TransitionRenderTargets(StateTransitionMode); - // No need to verify states again - CommitRenderPassAndFramebuffer(false); + if (m_pActiveRenderPass == nullptr) + { + TransitionRenderTargets(StateTransitionMode); + // No need to verify states again + CommitRenderPassAndFramebuffer(false); + } VkClearAttachment ClearAttachment = {}; ClearAttachment.aspectMask = 0; @@ -748,22 +772,48 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RG static constexpr const Uint32 InvalidAttachmentIndex = static_cast(-1); Uint32 attachmentIndex = InvalidAttachmentIndex; - for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) + if (m_pActiveRenderPass != nullptr) + { + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + for (Uint32 i = 0; i < FBDesc.AttachmentCount; ++i) + { + if (FBDesc.ppAttachments[i] == pView) + { + attachmentIndex = i; + break; + } + } + + if (attachmentIndex == InvalidAttachmentIndex) + { + UNEXPECTED("RTV was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearRenderTarget " + "checks if the RTV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); + return; + } + } + else { - if (m_pBoundRenderTargets[rt] == pVkRTV) + for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) { - attachmentIndex = rt; - break; + if (m_pBoundRenderTargets[rt] == pVkRTV) + { + attachmentIndex = rt; + break; + } } } + if (attachmentIndex != InvalidAttachmentIndex) { // Render pass may not be currently committed VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE && m_Framebuffer != VK_NULL_HANDLE); - TransitionRenderTargets(StateTransitionMode); - // No need to verify states again - CommitRenderPassAndFramebuffer(false); + if (m_pActiveRenderPass == nullptr) + { + TransitionRenderTargets(StateTransitionMode); + // No need to verify states again + CommitRenderPassAndFramebuffer(false); + } VkClearAttachment ClearAttachment = {}; ClearAttachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -786,6 +836,8 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RG } else { + VERIFY(m_pActiveRenderPass == nullptr, "This branch should never execute inside a render pass."); + // End current render pass and clear the image with vkCmdClearColorImage if (m_CommandBuffer.GetState().RenderPass != VK_NULL_HANDLE) m_CommandBuffer.EndRenderPass(); @@ -1111,6 +1163,8 @@ void DeviceContextVkImpl::TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE void DeviceContextVkImpl::CommitRenderPassAndFramebuffer(bool VerifyStates) { + VERIFY(m_pActiveRenderPass == nullptr, "This method should not be called inside an active render pass."); + const auto& CmdBufferState = m_CommandBuffer.GetState(); if (CmdBufferState.Framebuffer != m_Framebuffer) { -- cgit v1.2.3 From 3aa36ab27691129b99702a4102f73afdd9f4c52b Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 16:56:01 -0700 Subject: Fixed frame buffer attachment clear operations; updated clear render target tests --- .../include/DeviceContextVkImpl.hpp | 6 +- .../src/DeviceContextVkImpl.cpp | 91 +++++++++++----------- 2 files changed, 50 insertions(+), 47 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 41a9395d..ebca0282 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -438,11 +438,11 @@ private: /// Render pass that matches currently bound render targets. /// This render pass may or may not be currently set in the command buffer - VkRenderPass m_RenderPass = VK_NULL_HANDLE; + VkRenderPass m_vkRenderPass = VK_NULL_HANDLE; /// Framebuffer that matches currently bound render targets. /// This framebuffer may or may not be currently set in the command buffer - VkFramebuffer m_Framebuffer = VK_NULL_HANDLE; + VkFramebuffer m_vkFramebuffer = VK_NULL_HANDLE; FixedBlockMemoryAllocator m_CmdListAllocator; @@ -501,7 +501,7 @@ private: std::unique_ptr m_QueryMgr; Int32 m_ActiveQueriesCounter = 0; - std::vector m_VkClearValues; + std::vector m_vkClearValues; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 78dc2f61..d15f5720 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -116,7 +116,7 @@ DeviceContextVkImpl::DeviceContextVkImpl(IReferenceCounters* p m_pDevice->CreateBuffer(DummyVBDesc, nullptr, &pDummyVB); m_DummyVB = pDummyVB.RawPtr(); - m_VkClearValues.reserve(16); + m_vkClearValues.reserve(16); } DeviceContextVkImpl::~DeviceContextVkImpl() @@ -234,9 +234,11 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) if (PipelineStateVkImpl::IsSameObject(m_pPipelineState, pPipelineStateVk)) return; - // Never flush deferred context! - // A query must begin and end in the same command buffer (17.2) - if (!m_bIsDeferred && m_State.NumCommands >= m_NumCommandsToFlush && m_ActiveQueriesCounter == 0) + if (m_State.NumCommands >= m_NumCommandsToFlush && + !m_bIsDeferred && // Never flush deferred context + !m_pActiveRenderPass && // Never flush inside active render pass + m_ActiveQueriesCounter == 0 // A query must begin and end in the same command buffer (17.2) + ) { Flush(); } @@ -471,7 +473,7 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) #endif #ifdef DILIGENT_DEVELOPMENT - if (m_pPipelineState->GetRenderPass()->GetVkRenderPass() != m_RenderPass) + if (m_pPipelineState->GetRenderPass()->GetVkRenderPass() != m_vkRenderPass) { DvpLogRenderPass_PSOMismatch(); } @@ -667,10 +669,11 @@ void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView if (ClearAsAttachment) { - // Render pass may not be currently committed - VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE && m_Framebuffer != VK_NULL_HANDLE); + VERIFY_EXPR(m_vkRenderPass != VK_NULL_HANDLE && m_vkFramebuffer != VK_NULL_HANDLE); if (m_pActiveRenderPass == nullptr) { + // Render pass may not be currently committed + TransitionRenderTargets(StateTransitionMode); // No need to verify states again CommitRenderPassAndFramebuffer(false); @@ -806,10 +809,11 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RG if (attachmentIndex != InvalidAttachmentIndex) { - // Render pass may not be currently committed - VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE && m_Framebuffer != VK_NULL_HANDLE); + VERIFY_EXPR(m_vkRenderPass != VK_NULL_HANDLE && m_vkFramebuffer != VK_NULL_HANDLE); if (m_pActiveRenderPass == nullptr) { + // Render pass may not be currently committed + TransitionRenderTargets(StateTransitionMode); // No need to verify states again CommitRenderPassAndFramebuffer(false); @@ -1027,9 +1031,9 @@ void DeviceContextVkImpl::InvalidateState() LOG_WARNING_MESSAGE("Invalidating context that has outstanding commands in it. Call Flush() to submit commands for execution"); TDeviceContextBase::InvalidateState(); - m_State = ContextState{}; - m_RenderPass = VK_NULL_HANDLE; - m_Framebuffer = VK_NULL_HANDLE; + m_State = ContextState{}; + m_vkRenderPass = VK_NULL_HANDLE; + m_vkFramebuffer = VK_NULL_HANDLE; m_DescrSetBindInfo.Reset(); VERIFY(m_CommandBuffer.GetState().RenderPass == VK_NULL_HANDLE, "Invalidating context with unifinished render pass"); m_CommandBuffer.Reset(); @@ -1166,21 +1170,21 @@ void DeviceContextVkImpl::CommitRenderPassAndFramebuffer(bool VerifyStates) VERIFY(m_pActiveRenderPass == nullptr, "This method should not be called inside an active render pass."); const auto& CmdBufferState = m_CommandBuffer.GetState(); - if (CmdBufferState.Framebuffer != m_Framebuffer) + if (CmdBufferState.Framebuffer != m_vkFramebuffer) { if (CmdBufferState.RenderPass != VK_NULL_HANDLE) m_CommandBuffer.EndRenderPass(); - if (m_Framebuffer != VK_NULL_HANDLE) + if (m_vkFramebuffer != VK_NULL_HANDLE) { - VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE); + VERIFY_EXPR(m_vkRenderPass != VK_NULL_HANDLE); #ifdef DILIGENT_DEVELOPMENT if (VerifyStates) { TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE_VERIFY); } #endif - m_CommandBuffer.BeginRenderPass(m_RenderPass, m_Framebuffer, m_FramebufferWidth, m_FramebufferHeight); + m_CommandBuffer.BeginRenderPass(m_vkRenderPass, m_vkFramebuffer, m_FramebufferWidth, m_FramebufferHeight); } } } @@ -1232,10 +1236,10 @@ void DeviceContextVkImpl::SetRenderTargets(Uint32 NumRen auto& FBCache = m_pDevice->GetFramebufferCache(); auto& RPCache = m_pDevice->GetImplicitRenderPassCache(); - m_RenderPass = RPCache.GetRenderPass(RenderPassKey)->GetVkRenderPass(); - FBKey.Pass = m_RenderPass; + m_vkRenderPass = RPCache.GetRenderPass(RenderPassKey)->GetVkRenderPass(); + FBKey.Pass = m_vkRenderPass; FBKey.CommandQueueMask = ~Uint64{0}; - m_Framebuffer = FBCache.GetFramebuffer(FBKey, m_FramebufferWidth, m_FramebufferHeight, m_FramebufferSlices); + m_vkFramebuffer = FBCache.GetFramebuffer(FBKey, m_FramebufferWidth, m_FramebufferHeight, m_FramebufferSlices); // Set the viewport to match the render target size SetViewports(1, nullptr, 0, 0); @@ -1251,8 +1255,8 @@ void DeviceContextVkImpl::SetRenderTargets(Uint32 NumRen void DeviceContextVkImpl::ResetRenderTargets() { TDeviceContextBase::ResetRenderTargets(); - m_RenderPass = VK_NULL_HANDLE; - m_Framebuffer = VK_NULL_HANDLE; + m_vkRenderPass = VK_NULL_HANDLE; + m_vkFramebuffer = VK_NULL_HANDLE; if (m_CommandBuffer.GetVkCmdBuffer() != VK_NULL_HANDLE && m_CommandBuffer.GetState().RenderPass != VK_NULL_HANDLE) m_CommandBuffer.EndRenderPass(); } @@ -1261,41 +1265,40 @@ void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) { TDeviceContextBase::BeginRenderPass(Attribs); - auto vkRenderPass = m_pActiveRenderPass->GetVkRenderPass(); - - VkFramebuffer vkFramebuffer = VK_NULL_HANDLE; - uint32_t FramebufferWidth = 0; - uint32_t FramebufferHeight = 0; - if (m_pBoundFramebuffer) - { - vkFramebuffer = m_pBoundFramebuffer->GetVkFramebuffer(); - const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); - FramebufferWidth = FBDesc.Width; - FramebufferHeight = FBDesc.Height; - } + VERIFY_EXPR(m_pActiveRenderPass); + VERIFY_EXPR(m_pBoundFramebuffer); + m_vkRenderPass = m_pActiveRenderPass->GetVkRenderPass(); + m_vkFramebuffer = m_pBoundFramebuffer->GetVkFramebuffer(); VkClearValue* pVkClearValues = nullptr; if (Attribs.ClearValueCount > 0) { - m_VkClearValues.resize(Attribs.ClearValueCount); + m_vkClearValues.resize(Attribs.ClearValueCount); const auto& RPDesc = m_pActiveRenderPass->GetDesc(); for (Uint32 i = 0; i < std::min(RPDesc.AttachmentCount, Attribs.ClearValueCount); ++i) { const auto& ClearVal = Attribs.pClearValues[i]; - auto& vkClearVal = m_VkClearValues[i]; + auto& vkClearVal = m_vkClearValues[i]; - vkClearVal.color.float32[0] = ClearVal.Color[0]; - vkClearVal.color.float32[1] = ClearVal.Color[1]; - vkClearVal.color.float32[2] = ClearVal.Color[2]; - vkClearVal.color.float32[3] = ClearVal.Color[3]; - - vkClearVal.depthStencil.depth = ClearVal.DepthStencil.Depth; - vkClearVal.depthStencil.stencil = ClearVal.DepthStencil.Stencil; + const auto& FmtAttribs = GetTextureFormatAttribs(RPDesc.pAttachments[i].Format); + if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH || + FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) + { + vkClearVal.depthStencil.depth = ClearVal.DepthStencil.Depth; + vkClearVal.depthStencil.stencil = ClearVal.DepthStencil.Stencil; + } + else + { + vkClearVal.color.float32[0] = ClearVal.Color[0]; + vkClearVal.color.float32[1] = ClearVal.Color[1]; + vkClearVal.color.float32[2] = ClearVal.Color[2]; + vkClearVal.color.float32[3] = ClearVal.Color[3]; + } } - pVkClearValues = m_VkClearValues.data(); + pVkClearValues = m_vkClearValues.data(); } - m_CommandBuffer.BeginRenderPass(vkRenderPass, vkFramebuffer, FramebufferWidth, FramebufferHeight, Attribs.ClearValueCount, pVkClearValues); + m_CommandBuffer.BeginRenderPass(m_vkRenderPass, m_vkFramebuffer, m_FramebufferWidth, m_FramebufferHeight, Attribs.ClearValueCount, pVkClearValues); } void DeviceContextVkImpl::NextSubpass() -- cgit v1.2.3 From 812fc38d1b0957ed96d93e023b7322d65c5d3f5d Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 18:18:48 -0700 Subject: Updated EndRenderPass to optionally update resource states --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp | 2 +- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index ebca0282..a0249ec9 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -142,7 +142,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; // clang-format off /// Implementation of IDeviceContext::Draw() in Vulkan backend. diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d15f5720..0eb778f0 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1307,9 +1307,9 @@ void DeviceContextVkImpl::NextSubpass() m_CommandBuffer.NextSubpass(); } -void DeviceContextVkImpl::EndRenderPass() +void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) { - TDeviceContextBase::EndRenderPass(); + TDeviceContextBase::EndRenderPass(UpdateResourceStates); m_CommandBuffer.EndRenderPass(); } -- cgit v1.2.3 From 2c8af36b75be6b3c093175987ffa07df921adc56 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 21:26:33 -0700 Subject: Few improvements to render pass API --- Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp | 4 ++-- Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 92e0dee6..73485070 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -99,8 +99,8 @@ RenderPassDesc PipelineStateVkImpl::GetImplicitRenderPassDesc( ColorAttachment.StoreOp = ATTACHMENT_STORE_OP_STORE; // the contents generated during the render pass and within the render // area are written to memory. For attachments with a color format, // this uses the access type VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT. - ColorAttachment.StencilLoadOp = ATTACHMENT_LOAD_OP_DONT_CARE; - ColorAttachment.StencilStoreOp = ATTACHMENT_STORE_OP_DONT_CARE; + ColorAttachment.StencilLoadOp = ATTACHMENT_LOAD_OP_DISCARD; + ColorAttachment.StencilStoreOp = ATTACHMENT_STORE_OP_DISCARD; ColorAttachment.InitialState = RESOURCE_STATE_RENDER_TARGET; ColorAttachment.FinalState = RESOURCE_STATE_RENDER_TARGET; diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 01596a78..90ca6909 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1423,7 +1423,7 @@ VkSurfaceTransformFlagBitsKHR SurfaceTransformToVkSurfaceTransformFlag(SURFACE_T static_assert(ATTACHMENT_LOAD_OP_LOAD == VK_ATTACHMENT_LOAD_OP_LOAD, "ATTACHMENT_LOAD_OP_LOAD is not equal to VK_ATTACHMENT_LOAD_OP_LOAD"); static_assert(ATTACHMENT_LOAD_OP_CLEAR == VK_ATTACHMENT_LOAD_OP_CLEAR, "ATTACHMENT_LOAD_OP_CLEAR is not equal to VK_ATTACHMENT_LOAD_OP_CLEAR"); -static_assert(ATTACHMENT_LOAD_OP_DONT_CARE == VK_ATTACHMENT_LOAD_OP_DONT_CARE, "ATTACHMENT_LOAD_OP_DONT_CARE is not equal to VK_ATTACHMENT_LOAD_OP_DONT_CARE"); +static_assert(ATTACHMENT_LOAD_OP_DISCARD == VK_ATTACHMENT_LOAD_OP_DONT_CARE, "ATTACHMENT_LOAD_OP_DISCARD is not equal to VK_ATTACHMENT_LOAD_OP_DONT_CARE"); VkAttachmentLoadOp AttachmentLoadOpToVkAttachmentLoadOp(ATTACHMENT_LOAD_OP LoadOp) { return static_cast(LoadOp); @@ -1435,7 +1435,7 @@ ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoa static_assert(ATTACHMENT_STORE_OP_STORE == VK_ATTACHMENT_STORE_OP_STORE, "ATTACHMENT_STORE_OP_STORE is not equal to VK_ATTACHMENT_STORE_OP_STORE"); -static_assert(ATTACHMENT_STORE_OP_DONT_CARE == VK_ATTACHMENT_STORE_OP_DONT_CARE, "ATTACHMENT_STORE_OP_DONT_CARE is not equal to VK_ATTACHMENT_STORE_OP_DONT_CARE"); +static_assert(ATTACHMENT_STORE_OP_DISCARD == VK_ATTACHMENT_STORE_OP_DONT_CARE, "ATTACHMENT_STORE_OP_DISCARD is not equal to VK_ATTACHMENT_STORE_OP_DONT_CARE"); VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp) { return static_cast(StoreOp); -- cgit v1.2.3 From 706b34a2e4dbd372dc4255a9b6f021b9c7ee34ac Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 3 Aug 2020 13:46:43 -0700 Subject: Few fixes to render passes --- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 3 +++ Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp | 1 + Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 1 + Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp | 13 +++++++------ 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 0eb778f0..3214c30f 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1298,18 +1298,21 @@ void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) pVkClearValues = m_vkClearValues.data(); } + EnsureVkCmdBuffer(); m_CommandBuffer.BeginRenderPass(m_vkRenderPass, m_vkFramebuffer, m_FramebufferWidth, m_FramebufferHeight, Attribs.ClearValueCount, pVkClearValues); } void DeviceContextVkImpl::NextSubpass() { TDeviceContextBase::NextSubpass(); + EnsureVkCmdBuffer(); m_CommandBuffer.NextSubpass(); } void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) { TDeviceContextBase::EndRenderPass(UpdateResourceStates); + EnsureVkCmdBuffer(); m_CommandBuffer.EndRenderPass(); } diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp index 2fc81319..54b77e36 100644 --- a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp @@ -78,6 +78,7 @@ FramebufferVkImpl::FramebufferVkImpl(IReferenceCounters* pRefCounters, FramebufferVkImpl::~FramebufferVkImpl() { + m_pDevice->SafeReleaseDeviceObject(std::move(m_VkFramebuffer), ~Uint64{0}); } } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 37bdc106..a0a25f89 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -157,6 +157,7 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, RenderPassVkImpl::~RenderPassVkImpl() { + m_pDevice->SafeReleaseDeviceObject(std::move(m_VkRenderPass), ~Uint64{0}); } } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 90ca6909..4dc4872a 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1140,7 +1140,6 @@ VkBorderColor BorderColorToVkBorderColor(const Float32 BorderColor[]) static VkAccessFlags ResourceStateFlagToVkAccessFlags(RESOURCE_STATE StateFlag) { // Currently not used: - //VK_ACCESS_INPUT_ATTACHMENT_READ_BIT //VK_ACCESS_HOST_READ_BIT //VK_ACCESS_HOST_WRITE_BIT //VK_ACCESS_MEMORY_READ_BIT @@ -1155,7 +1154,7 @@ static VkAccessFlags ResourceStateFlagToVkAccessFlags(RESOURCE_STATE StateFlag) //VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NVX //VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NVX - static_assert(RESOURCE_STATE_MAX_BIT == 0x8000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == 0x10000, "This function must be updated to handle new resource state flag"); VERIFY((StateFlag & (StateFlag - 1)) == 0, "Only single bit must be set"); switch (StateFlag) { @@ -1175,6 +1174,7 @@ static VkAccessFlags ResourceStateFlagToVkAccessFlags(RESOURCE_STATE StateFlag) case RESOURCE_STATE_COPY_SOURCE: return VK_ACCESS_TRANSFER_READ_BIT; case RESOURCE_STATE_RESOLVE_DEST: return VK_ACCESS_MEMORY_READ_BIT; case RESOURCE_STATE_RESOLVE_SOURCE: return VK_ACCESS_MEMORY_WRITE_BIT; + case RESOURCE_STATE_INPUT_ATTACHMENT: return VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; case RESOURCE_STATE_PRESENT: return VK_ACCESS_MEMORY_READ_BIT; // clang-format on @@ -1203,7 +1203,7 @@ public: } private: - static constexpr const Uint32 MaxFlagBitPos = 15; + static constexpr const Uint32 MaxFlagBitPos = 16; std::array FlagBitPosToVkAccessFlagsMap; }; @@ -1235,7 +1235,7 @@ RESOURCE_STATE VkAccessFlagsToResourceStates(VkAccessFlagBits AccessFlagBit) case VK_ACCESS_INDEX_READ_BIT: return RESOURCE_STATE_INDEX_BUFFER; case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT: return RESOURCE_STATE_VERTEX_BUFFER; case VK_ACCESS_UNIFORM_READ_BIT: return RESOURCE_STATE_CONSTANT_BUFFER; - case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT: return RESOURCE_STATE_UNKNOWN; + case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT: return RESOURCE_STATE_INPUT_ATTACHMENT; case VK_ACCESS_SHADER_READ_BIT: return RESOURCE_STATE_SHADER_RESOURCE; case VK_ACCESS_SHADER_WRITE_BIT: return RESOURCE_STATE_UNORDERED_ACCESS; case VK_ACCESS_COLOR_ATTACHMENT_READ_BIT: return RESOURCE_STATE_RENDER_TARGET; @@ -1317,7 +1317,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag) //VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, //VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, - static_assert(RESOURCE_STATE_MAX_BIT == 0x8000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == 0x10000, "This function must be updated to handle new resource state flag"); VERIFY((StateFlag & (StateFlag - 1)) == 0, "Only single bit must be set"); switch (StateFlag) { @@ -1337,6 +1337,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag) case RESOURCE_STATE_COPY_SOURCE: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; case RESOURCE_STATE_RESOLVE_DEST: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; case RESOURCE_STATE_RESOLVE_SOURCE: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + case RESOURCE_STATE_INPUT_ATTACHMENT: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; case RESOURCE_STATE_PRESENT: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; // clang-format on @@ -1348,7 +1349,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag) RESOURCE_STATE VkImageLayoutToResourceState(VkImageLayout Layout) { - static_assert(RESOURCE_STATE_MAX_BIT == 0x8000, "This function must be updated to handle new resource state flag"); + static_assert(RESOURCE_STATE_MAX_BIT == 0x10000, "This function must be updated to handle new resource state flag"); switch (Layout) { // clang-format off -- cgit v1.2.3 From 32f8ed61f2a24342bc721051a0493fc4eacc3134 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 3 Aug 2020 17:22:58 -0700 Subject: Vk device: fixed issue with render pass cache destruction --- Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp | 2 ++ Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp | 3 +++ Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp index d2def841..ba21fcd9 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp +++ b/Graphics/GraphicsEngineVulkan/include/RenderPassCache.hpp @@ -126,6 +126,8 @@ public: RenderPassVkImpl* GetRenderPass(const RenderPassCacheKey& Key); + void Destroy(); + private: struct RenderPassCacheKeyHash { diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 3b8e569a..18814e06 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -211,6 +211,9 @@ RenderDeviceVkImpl::~RenderDeviceVkImpl() // the heap into release queues m_DynamicMemoryManager.Destroy(); + // Explicitly destroy render pass cache + m_ImplicitRenderPassCache.Destroy(); + // Wait for the GPU to complete all its operations IdleGPU(); diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp index 29b817ce..a40010f1 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassCache.cpp @@ -41,14 +41,24 @@ RenderPassCache::RenderPassCache(RenderDeviceVkImpl& DeviceVk) noexcept : RenderPassCache::~RenderPassCache() +{ + // Render pass cache is part of the render device, so we can't release + // render pass objects from here as their destructors will attmept to + // call SafeReleaseDeviceObject. + VERIFY(m_Cache.empty(), "Render pass cache is not empty. Did you call Destroy?"); +} + +void RenderPassCache::Destroy() { auto& FBCache = m_DeviceVkImpl.GetFramebufferCache(); for (auto it = m_Cache.begin(); it != m_Cache.end(); ++it) { FBCache.OnDestroyRenderPass(it->second->GetVkRenderPass()); } + m_Cache.clear(); } + RenderPassVkImpl* RenderPassCache::GetRenderPass(const RenderPassCacheKey& Key) { std::lock_guard Lock{m_Mutex}; -- cgit v1.2.3 From 5dba447dab6f8021631ad6628b2754727c52d284 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 3 Aug 2020 19:14:25 -0700 Subject: Added render pass test, fixed default viewport setting issue when beginning the render pass --- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 3 +++ Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 3214c30f..6a5d5ced 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1300,6 +1300,9 @@ void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) EnsureVkCmdBuffer(); m_CommandBuffer.BeginRenderPass(m_vkRenderPass, m_vkFramebuffer, m_FramebufferWidth, m_FramebufferHeight, Attribs.ClearValueCount, pVkClearValues); + + // Set the viewport to match the framebuffer size + SetViewports(1, nullptr, 0, 0); } void DeviceContextVkImpl::NextSubpass() diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 73485070..a4f61fd1 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -394,13 +394,15 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun DepthStencilStateDesc_To_VkDepthStencilStateCI(GraphicsPipeline.DepthStencilDesc); PipelineCI.pDepthStencilState = &DepthStencilStateCI; - std::vector ColorBlendAttachmentStates(m_Desc.GraphicsPipeline.NumRenderTargets); + const auto& RPDesc = m_pRenderPass->GetDesc(); + VERIFY_EXPR(GraphicsPipeline.pRenderPass != nullptr || GraphicsPipeline.NumRenderTargets == RPDesc.AttachmentCount); + std::vector ColorBlendAttachmentStates(RPDesc.AttachmentCount); VkPipelineColorBlendStateCreateInfo BlendStateCI = {}; BlendStateCI.pAttachments = !ColorBlendAttachmentStates.empty() ? ColorBlendAttachmentStates.data() : nullptr; - BlendStateCI.attachmentCount = m_Desc.GraphicsPipeline.NumRenderTargets; // must equal the colorAttachmentCount for the subpass - // in which this pipeline is used. + BlendStateCI.attachmentCount = RPDesc.AttachmentCount; // must equal the colorAttachmentCount for the subpass + // in which this pipeline is used. BlendStateDesc_To_VkBlendStateCI(GraphicsPipeline.BlendDesc, BlendStateCI, ColorBlendAttachmentStates); PipelineCI.pColorBlendState = &BlendStateCI; -- cgit v1.2.3 From 876590adc6002ca131b2580d8109b1ca7826907b Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 3 Aug 2020 21:11:58 -0700 Subject: Added render pass MS resolve test --- Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index a4f61fd1..96592793 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -394,15 +394,16 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun DepthStencilStateDesc_To_VkDepthStencilStateCI(GraphicsPipeline.DepthStencilDesc); PipelineCI.pDepthStencilState = &DepthStencilStateCI; - const auto& RPDesc = m_pRenderPass->GetDesc(); - VERIFY_EXPR(GraphicsPipeline.pRenderPass != nullptr || GraphicsPipeline.NumRenderTargets == RPDesc.AttachmentCount); - std::vector ColorBlendAttachmentStates(RPDesc.AttachmentCount); + const auto& RPDesc = m_pRenderPass->GetDesc(); + const auto NumRTAttachments = RPDesc.pSubpasses[GraphicsPipeline.SubpassIndex].RenderTargetAttachmentCount; + VERIFY_EXPR(GraphicsPipeline.pRenderPass != nullptr || GraphicsPipeline.NumRenderTargets == NumRTAttachments); + std::vector ColorBlendAttachmentStates(NumRTAttachments); VkPipelineColorBlendStateCreateInfo BlendStateCI = {}; BlendStateCI.pAttachments = !ColorBlendAttachmentStates.empty() ? ColorBlendAttachmentStates.data() : nullptr; - BlendStateCI.attachmentCount = RPDesc.AttachmentCount; // must equal the colorAttachmentCount for the subpass - // in which this pipeline is used. + BlendStateCI.attachmentCount = NumRTAttachments; // must equal the colorAttachmentCount for the subpass + // in which this pipeline is used. BlendStateDesc_To_VkBlendStateCI(GraphicsPipeline.BlendDesc, BlendStateCI, ColorBlendAttachmentStates); PipelineCI.pColorBlendState = &BlendStateCI; -- cgit v1.2.3 From 86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 4 Aug 2020 14:05:42 -0700 Subject: Implemented input attachments in Vulkan backend; added test --- .../include/ShaderResourceCacheVk.hpp | 1 + .../include/ShaderResourceLayoutVk.hpp | 5 +++ .../GraphicsEngineVulkan/src/PipelineLayout.cpp | 3 +- .../src/ShaderResourceCacheVk.cpp | 25 +++++++++++++ .../src/ShaderResourceLayoutVk.cpp | 42 +++++++++++++++++++--- 5 files changed, 70 insertions(+), 6 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp index 172c82a8..a5278cb7 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp @@ -117,6 +117,7 @@ public: VkDescriptorImageInfo GetImageDescriptorWriteInfo (bool IsImmutableSampler)const; VkBufferView GetBufferViewWriteInfo () const; VkDescriptorImageInfo GetSamplerDescriptorWriteInfo() const; + VkDescriptorImageInfo GetInputAttachmentDescriptorWriteInfo() const; // clang-format on }; diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp index 07050821..a6d20641 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp @@ -260,6 +260,11 @@ public: VkDescriptorSet vkDescrSet, Uint32 ArrayInd) const; + void CacheInputAttachment(IDeviceObject* pTexView, + ShaderResourceCacheVk::Resource& DstRes, + VkDescriptorSet vkDescrSet, + Uint32 ArrayInd) const; + template bool UpdateCachedResource(ShaderResourceCacheVk::Resource& DstRes, RefCntAutoPtr&& pObject, diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index 32a68780..aa027b25 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -64,7 +64,7 @@ class ResourceTypeToVkDescriptorType public: ResourceTypeToVkDescriptorType() { - static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 10, "Please add corresponding decriptor type"); + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please add the corresponding decriptor type"); m_Map[SPIRVShaderResourceAttribs::ResourceType::UniformBuffer] = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; m_Map[SPIRVShaderResourceAttribs::ResourceType::ROStorageBuffer] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; m_Map[SPIRVShaderResourceAttribs::ResourceType::RWStorageBuffer] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; @@ -75,6 +75,7 @@ public: m_Map[SPIRVShaderResourceAttribs::ResourceType::AtomicCounter] = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; m_Map[SPIRVShaderResourceAttribs::ResourceType::SeparateImage] = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; m_Map[SPIRVShaderResourceAttribs::ResourceType::SeparateSampler] = VK_DESCRIPTOR_TYPE_SAMPLER; + m_Map[SPIRVShaderResourceAttribs::ResourceType::InputAttachment] = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; } VkDescriptorType operator[](SPIRVShaderResourceAttribs::ResourceType ResType) const diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 06239703..caf8ffd2 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -155,6 +155,7 @@ void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl* pCtxVkImpl) for (Uint32 res = 0; res < m_TotalResources; ++res) { auto& Res = pResources[res]; + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below"); switch (Res.Type) { case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer: @@ -312,6 +313,14 @@ void ShaderResourceCacheVk::TransitionResources(DeviceContextVkImpl* pCtxVkImpl) } break; + case SPIRVShaderResourceAttribs::ResourceType::InputAttachment: + { + // Nothing to do with input attachments - they are transitioned by the render pass. + // There is nothing we can validate here - a texture may be in different state at + // the beginning of the render pass before being transitioned to INPUT_ATTACHMENT state. + } + break; + default: UNEXPECTED("Unexpected resource type"); } } @@ -472,4 +481,20 @@ VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetSamplerDescriptorWrite return DescrImgInfo; } +VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetInputAttachmentDescriptorWriteInfo() const +{ + VERIFY(Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Input attachment resource is expected"); + DEV_CHECK_ERR(pObject != nullptr, "Unable to get input attachment write info: cached object is null"); + + auto* pTexViewVk = pObject.RawPtr(); + VERIFY_EXPR(pTexViewVk->GetDesc().ViewType == TEXTURE_VIEW_SHADER_RESOURCE); + + VkDescriptorImageInfo DescrImgInfo; + DescrImgInfo.sampler = VK_NULL_HANDLE; + DescrImgInfo.imageView = pTexViewVk->GetVulkanImageView(); + DescrImgInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + return DescrImgInfo; +} + } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index a02cd8bb..4f28af80 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -526,6 +526,11 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* { VERIFY_EXPR(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage || SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer); AddResource(s, Layout, Resources, SepImg); + }, + [&](const SPIRVShaderResourceAttribs& InputAtt, Uint32) + { + VERIFY_EXPR(InputAtt.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment); + AddResource(s, Layout, Resources, InputAtt); } ); // clang-format on @@ -640,7 +645,7 @@ void ShaderResourceLayoutVk::VkResource::CacheUniformBuffer(IDeviceObject* Uint16& DynamicBuffersCounter) const { VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, "Uniform buffer resource is expected"); - RefCntAutoPtr pBufferVk(pBuffer, IID_BufferVk); + RefCntAutoPtr pBufferVk{pBuffer, IID_BufferVk}; #ifdef DILIGENT_DEVELOPMENT VerifyConstantBufferBinding(SpirvAttribs, GetVariableType(), ArrayInd, pBuffer, pBufferVk.RawPtr(), DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName()); #endif @@ -681,7 +686,7 @@ void ShaderResourceLayoutVk::VkResource::CacheStorageBuffer(IDeviceObject* "Storage buffer resource is expected"); // clang-format on - RefCntAutoPtr pBufferViewVk(pBufferView, IID_BufferViewVk); + RefCntAutoPtr pBufferViewVk{pBufferView, IID_BufferViewVk}; #ifdef DILIGENT_DEVELOPMENT { // HLSL buffer SRVs are mapped to storge buffers in GLSL @@ -727,7 +732,7 @@ void ShaderResourceLayoutVk::VkResource::CacheTexelBuffer(IDeviceObject* "Uniform or storage buffer resource is expected"); // clang-format on - RefCntAutoPtr pBufferViewVk(pBufferView, IID_BufferViewVk); + RefCntAutoPtr pBufferViewVk{pBufferView, IID_BufferViewVk}; #ifdef DILIGENT_DEVELOPMENT { // HLSL buffer SRVs are mapped to storge buffers in GLSL @@ -776,7 +781,7 @@ void ShaderResourceLayoutVk::VkResource::CacheImage(IDeviceObject* "Storage image, separate image or sampled image resource is expected"); // clang-format on - RefCntAutoPtr pTexViewVk0(pTexView, IID_TextureViewVk); + RefCntAutoPtr pTexViewVk0{pTexView, IID_TextureViewVk}; #ifdef DILIGENT_DEVELOPMENT { // HLSL buffer SRVs are mapped to storge buffers in GLSL @@ -840,7 +845,7 @@ void ShaderResourceLayoutVk::VkResource::CacheSeparateSampler(IDeviceObject* VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, "Separate sampler resource is expected"); VERIFY(!IsImmutableSamplerAssigned(), "This separate sampler is assigned an immutable sampler"); - RefCntAutoPtr pSamplerVk(pSampler, IID_Sampler); + RefCntAutoPtr pSamplerVk{pSampler, IID_Sampler}; #ifdef DILIGENT_DEVELOPMENT if (pSampler != nullptr && pSamplerVk == nullptr) { @@ -868,6 +873,28 @@ void ShaderResourceLayoutVk::VkResource::CacheSeparateSampler(IDeviceObject* } } +void ShaderResourceLayoutVk::VkResource::CacheInputAttachment(IDeviceObject* pTexView, + ShaderResourceCacheVk::Resource& DstRes, + VkDescriptorSet vkDescrSet, + Uint32 ArrayInd) const +{ + VERIFY(SpirvAttribs.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Input attachment resource is expected"); + RefCntAutoPtr pTexViewVk0{pTexView, IID_TextureViewVk}; +#ifdef DILIGENT_DEVELOPMENT + VerifyResourceViewBinding(SpirvAttribs, GetVariableType(), ArrayInd, pTexView, pTexViewVk0.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName()); +#endif + if (UpdateCachedResource(DstRes, std::move(pTexViewVk0), [](const TextureViewVkImpl*, const TextureViewVkImpl*) {})) + { + // Do not update descriptor for a dynamic image. All dynamic resource descriptors + // are updated at once by CommitDynamicResources() when SRB is committed. + if (vkDescrSet != VK_NULL_HANDLE && GetVariableType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) + { + VkDescriptorImageInfo DescrImgInfo = DstRes.GetInputAttachmentDescriptorWriteInfo(); + UpdateDescriptorHandle(vkDescrSet, ArrayInd, &DescrImgInfo, nullptr, nullptr); + } + // + } +} void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint32 ArrayIndex, ShaderResourceCacheVk& ResourceCache) const { @@ -898,6 +925,7 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint3 if (pObj) { + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below"); switch (SpirvAttribs.Type) { case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer: @@ -945,6 +973,10 @@ void ShaderResourceLayoutVk::VkResource::BindResource(IDeviceObject* pObj, Uint3 } break; + case SPIRVShaderResourceAttribs::ResourceType::InputAttachment: + CacheInputAttachment(pObj, DstRes, vkDescrSet, ArrayIndex); + break; + default: UNEXPECTED("Unknown resource type ", static_cast(SpirvAttribs.Type)); } } -- cgit v1.2.3 From 3ce2d21558fa0568ab7d332a5c300a661e444f44 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 4 Aug 2020 19:21:19 -0700 Subject: Added more renderpass-related checks --- .../src/DeviceContextVkImpl.cpp | 49 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 6a5d5ced..5f26479d 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -179,7 +179,7 @@ void DeviceContextVkImpl::DisposeVkCmdBuffer(Uint32 CmdQueue, VkCommandBuffer vk public: // clang-format off CmdBufferDeleter(VkCommandBuffer _vkCmdBuff, - VulkanUtilities::VulkanCommandBufferPool& _Pool) noexcept : + VulkanUtilities::VulkanCommandBufferPool& _Pool) noexcept : vkCmdBuff {_vkCmdBuff}, Pool {&_Pool } { @@ -236,7 +236,7 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) if (m_State.NumCommands >= m_NumCommandsToFlush && !m_bIsDeferred && // Never flush deferred context - !m_pActiveRenderPass && // Never flush inside active render pass + !m_pActiveRenderPass && // Never flush inside active render pass (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-vkEndCommandBuffer-commandBuffer-00060) m_ActiveQueriesCounter == 0 // A query must begin and end in the same command buffer (17.2) ) { @@ -305,7 +305,12 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) void DeviceContextVkImpl::TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) { - VERIFY_EXPR(pPipelineState != nullptr); + DEV_CHECK_ERR(pPipelineState != nullptr, "Pipeline state must mot be null"); + if (m_pActiveRenderPass) + { + LOG_ERROR_MESSAGE("State transitions are not allowed inside a render pass."); + return; + } auto* pPipelineStateVk = ValidatedCast(pPipelineState); pPipelineStateVk->CommitAndTransitionShaderResources(pShaderResourceBinding, this, false, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, nullptr); @@ -935,14 +940,19 @@ void DeviceContextVkImpl::Flush() { if (m_bIsDeferred) { - LOG_ERROR_MESSAGE("Flush() should only be called for immediate contexts"); + LOG_ERROR_MESSAGE("Flush() should only be called for immediate contexts."); return; } if (m_ActiveQueriesCounter > 0) { LOG_ERROR_MESSAGE("Flushing device context that has ", m_ActiveQueriesCounter, - " active queries. Vulkan requires that queries are begun and ended in the same command buffer"); + " active queries. Vulkan requires that queries are begun and ended in the same command buffer."); + } + + if (m_pActiveRenderPass != nullptr) + { + LOG_ERROR_MESSAGE("Flushing device context inside an active render pass."); } VkSubmitInfo SubmitInfo = {}; @@ -1147,6 +1157,9 @@ void DeviceContextVkImpl::SetScissorRects(Uint32 NumRects, const Rect* pRects, U void DeviceContextVkImpl::TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { + VERIFY(StateTransitionMode != RESOURCE_STATE_TRANSITION_MODE_TRANSITION || m_pActiveRenderPass == nullptr, + "State transitions are not allowed inside a render pass."); + if (m_pBoundDepthStencil) { auto* pDepthBufferVk = ValidatedCast(m_pBoundDepthStencil->GetTexture()); @@ -1167,7 +1180,7 @@ void DeviceContextVkImpl::TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE void DeviceContextVkImpl::CommitRenderPassAndFramebuffer(bool VerifyStates) { - VERIFY(m_pActiveRenderPass == nullptr, "This method should not be called inside an active render pass."); + VERIFY(m_pActiveRenderPass == nullptr, "This method must not be called inside an active render pass."); const auto& CmdBufferState = m_CommandBuffer.GetState(); if (CmdBufferState.Framebuffer != m_vkFramebuffer) @@ -1265,8 +1278,11 @@ void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) { TDeviceContextBase::BeginRenderPass(Attribs); - VERIFY_EXPR(m_pActiveRenderPass); - VERIFY_EXPR(m_pBoundFramebuffer); + VERIFY_EXPR(m_pActiveRenderPass != nullptr); + VERIFY_EXPR(m_pBoundFramebuffer != nullptr); + VERIFY_EXPR(m_vkRenderPass == VK_NULL_HANDLE); + VERIFY_EXPR(m_vkFramebuffer == VK_NULL_HANDLE); + m_vkRenderPass = m_pActiveRenderPass->GetVkRenderPass(); m_vkFramebuffer = m_pBoundFramebuffer->GetVkFramebuffer(); @@ -1317,6 +1333,14 @@ void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) TDeviceContextBase::EndRenderPass(UpdateResourceStates); EnsureVkCmdBuffer(); m_CommandBuffer.EndRenderPass(); + + if (m_State.NumCommands >= m_NumCommandsToFlush && + !m_bIsDeferred && // Never flush deferred context + m_ActiveQueriesCounter == 0 // A query must begin and end in the same command buffer (17.2) + ) + { + Flush(); + } } void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl* pBuffVk, @@ -2077,6 +2101,8 @@ void DeviceContextVkImpl::UnmapTextureSubresource(ITexture* pTexture, void DeviceContextVkImpl::FinishCommandList(class ICommandList** ppCommandList) { + VERIFY(m_pActiveRenderPass == nullptr, "Finishing command list inside an active render pass."); + if (m_CommandBuffer.GetState().RenderPass != VK_NULL_HANDLE) { m_CommandBuffer.EndRenderPass(); @@ -2241,6 +2267,7 @@ void DeviceContextVkImpl::EndQuery(IQuery* pQuery) void DeviceContextVkImpl::TransitionImageLayout(ITexture* pTexture, VkImageLayout NewLayout) { VERIFY_EXPR(pTexture != nullptr); + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); auto pTextureVk = ValidatedCast(pTexture); if (!pTextureVk->IsInKnownState()) { @@ -2260,6 +2287,7 @@ void DeviceContextVkImpl::TransitionTextureState(TextureVkImpl& Textur bool UpdateTextureState, VkImageSubresourceRange* pSubresRange /* = nullptr*/) { + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); if (OldState == RESOURCE_STATE_UNKNOWN) { if (TextureVk.IsInKnownState()) @@ -2335,6 +2363,7 @@ void DeviceContextVkImpl::TransitionOrVerifyTextureState(TextureVkImpl& { if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); if (Texture.IsInKnownState()) { if (!Texture.CheckState(RequiredState)) @@ -2382,6 +2411,7 @@ void DeviceContextVkImpl::BufferMemoryBarrier(IBuffer* pBuffer, VkAccessFlags Ne void DeviceContextVkImpl::TransitionBufferState(BufferVkImpl& BufferVk, RESOURCE_STATE OldState, RESOURCE_STATE NewState, bool UpdateBufferState) { + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); if (OldState == RESOURCE_STATE_UNKNOWN) { if (BufferVk.IsInKnownState()) @@ -2431,6 +2461,7 @@ void DeviceContextVkImpl::TransitionOrVerifyBufferState(BufferVkImpl& { if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); if (Buffer.IsInKnownState()) { if (!Buffer.CheckState(RequiredState)) @@ -2459,6 +2490,8 @@ VulkanDynamicAllocation DeviceContextVkImpl::AllocateDynamicSpace(Uint32 SizeInB void DeviceContextVkImpl::TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) { + VERIFY(m_pActiveRenderPass == nullptr, "State transitions are not allowed inside a render pass"); + if (BarrierCount == 0) return; -- cgit v1.2.3 From 481158f2ec1b355d30aa4bac2f55f83a04258dc3 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 5 Aug 2020 22:24:14 -0700 Subject: Fixed GCC compiler warnings --- .../src/VulkanTypeConversions.cpp | 104 +++++++++++---------- 1 file changed, 54 insertions(+), 50 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index 4dc4872a..bf34a07a 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1422,9 +1422,12 @@ VkSurfaceTransformFlagBitsKHR SurfaceTransformToVkSurfaceTransformFlag(SURFACE_T // clang-format on } -static_assert(ATTACHMENT_LOAD_OP_LOAD == VK_ATTACHMENT_LOAD_OP_LOAD, "ATTACHMENT_LOAD_OP_LOAD is not equal to VK_ATTACHMENT_LOAD_OP_LOAD"); -static_assert(ATTACHMENT_LOAD_OP_CLEAR == VK_ATTACHMENT_LOAD_OP_CLEAR, "ATTACHMENT_LOAD_OP_CLEAR is not equal to VK_ATTACHMENT_LOAD_OP_CLEAR"); -static_assert(ATTACHMENT_LOAD_OP_DISCARD == VK_ATTACHMENT_LOAD_OP_DONT_CARE, "ATTACHMENT_LOAD_OP_DISCARD is not equal to VK_ATTACHMENT_LOAD_OP_DONT_CARE"); + +#define ASSERT_SAME(Val1, Val2) static_assert(static_cast(Val1) == static_cast(Val2), #Val1 " is expected to be equal to " #Val2) + +ASSERT_SAME(ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_LOAD_OP_LOAD); +ASSERT_SAME(ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_LOAD_OP_CLEAR); +ASSERT_SAME(ATTACHMENT_LOAD_OP_DISCARD, VK_ATTACHMENT_LOAD_OP_DONT_CARE); VkAttachmentLoadOp AttachmentLoadOpToVkAttachmentLoadOp(ATTACHMENT_LOAD_OP LoadOp) { return static_cast(LoadOp); @@ -1435,8 +1438,8 @@ ATTACHMENT_LOAD_OP VkAttachmentLoadOpToAttachmentLoadOp(VkAttachmentLoadOp VkLoa } -static_assert(ATTACHMENT_STORE_OP_STORE == VK_ATTACHMENT_STORE_OP_STORE, "ATTACHMENT_STORE_OP_STORE is not equal to VK_ATTACHMENT_STORE_OP_STORE"); -static_assert(ATTACHMENT_STORE_OP_DISCARD == VK_ATTACHMENT_STORE_OP_DONT_CARE, "ATTACHMENT_STORE_OP_DISCARD is not equal to VK_ATTACHMENT_STORE_OP_DONT_CARE"); +ASSERT_SAME(ATTACHMENT_STORE_OP_STORE, VK_ATTACHMENT_STORE_OP_STORE); +ASSERT_SAME(ATTACHMENT_STORE_OP_DISCARD, VK_ATTACHMENT_STORE_OP_DONT_CARE); VkAttachmentStoreOp AttachmentStoreOpToVkAttachmentStoreOp(ATTACHMENT_STORE_OP StoreOp) { return static_cast(StoreOp); @@ -1448,28 +1451,28 @@ ATTACHMENT_STORE_OP VkAttachmentStoreOpToAttachmentStoreOp(VkAttachmentStoreOp V // clang-format off -static_assert(PIPELINE_STAGE_FLAG_TOP_OF_PIPE == VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "PIPELINE_STAGE_FLAG_TOP_OF_PIPE != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT"); -static_assert(PIPELINE_STAGE_FLAG_DRAW_INDIRECT == VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, "PIPELINE_STAGE_FLAG_DRAW_INDIRECT != VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT"); -static_assert(PIPELINE_STAGE_FLAG_VERTEX_INPUT == VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, "PIPELINE_STAGE_FLAG_VERTEX_INPUT != VK_PIPELINE_STAGE_VERTEX_INPUT_BIT"); -static_assert(PIPELINE_STAGE_FLAG_VERTEX_SHADER == VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, "PIPELINE_STAGE_FLAG_VERTEX_SHADER != VK_PIPELINE_STAGE_VERTEX_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_HULL_SHADER == VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT, "PIPELINE_STAGE_FLAG_HULL_SHADER != VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_DOMAIN_SHADER == VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT, "PIPELINE_STAGE_FLAG_DOMAIN_SHADER != VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_GEOMETRY_SHADER == VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT, "PIPELINE_STAGE_FLAG_GEOMETRY_SHADER != VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_PIXEL_SHADER == VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, "PIPELINE_STAGE_FLAG_PIXEL_SHADER != VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS == VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS != VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT"); -static_assert(PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS == VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, "PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS != VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT"); -static_assert(PIPELINE_STAGE_FLAG_RENDER_TARGET == VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, "PIPELINE_STAGE_FLAG_RENDER_TARGET != VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT"); -static_assert(PIPELINE_STAGE_FLAG_COMPUTE_SHADER == VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, "PIPELINE_STAGE_FLAG_COMPUTE_SHADER != VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_TRANSFER == VK_PIPELINE_STAGE_TRANSFER_BIT, "PIPELINE_STAGE_FLAG_TRANSFER != VK_PIPELINE_STAGE_TRANSFER_BIT"); -static_assert(PIPELINE_STAGE_FLAG_BOTTOM_OF_PIPE == VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "PIPELINE_STAGE_FLAG_BOTTOM_OF_PIPE != VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT"); -static_assert(PIPELINE_STAGE_FLAG_HOST == VK_PIPELINE_STAGE_HOST_BIT, "PIPELINE_STAGE_FLAG_HOST != VK_PIPELINE_STAGE_HOST_BIT"); -static_assert(PIPELINE_STAGE_FLAG_CONDITIONAL_RENDERING == VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT, "PIPELINE_STAGE_FLAG_CONDITIONAL_RENDERING != VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT"); -static_assert(PIPELINE_STAGE_FLAG_SHADING_RATE_TEXTURE == VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV, "PIPELINE_STAGE_FLAG_SHADING_RATE_IMAGE != VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV"); -static_assert(PIPELINE_STAGE_FLAG_RAY_TRACING_SHADER == VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_RAY_TRACING_SHADER != VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV"); -static_assert(PIPELINE_STAGE_FLAG_ACCELERATION_STRUCTURE_BUILD == VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_NV, "PIPELINE_STAGE_FLAG_ACCELERATION_STRUCTURE_BUILD != VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_NV"); -static_assert(PIPELINE_STAGE_FLAG_TASK_SHADER == VK_PIPELINE_STAGE_TASK_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_TASK_SHADER != VK_PIPELINE_STAGE_TASK_SHADER_BIT_NV"); -static_assert(PIPELINE_STAGE_FLAG_MESH_SHADER == VK_PIPELINE_STAGE_MESH_SHADER_BIT_NV, "PIPELINE_STAGE_FLAG_MESH_SHADER != VK_PIPELINE_STAGE_MESH_SHADER_BIT_NV"); -static_assert(PIPELINE_STAGE_FLAG_FRAGMENT_DENSITY_PROCESS == VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT, "PIPELINE_STAGE_FLAG_FRAGMENT_DENSITY_PROCESS != VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT"); +ASSERT_SAME(PIPELINE_STAGE_FLAG_TOP_OF_PIPE, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_DRAW_INDIRECT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_VERTEX_INPUT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_VERTEX_SHADER, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_HULL_SHADER, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_DOMAIN_SHADER, VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_GEOMETRY_SHADER, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_PIXEL_SHADER, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_EARLY_FRAGMENT_TESTS, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_LATE_FRAGMENT_TESTS, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_RENDER_TARGET, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_COMPUTE_SHADER, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_TRANSFER, VK_PIPELINE_STAGE_TRANSFER_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_BOTTOM_OF_PIPE, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_HOST, VK_PIPELINE_STAGE_HOST_BIT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_CONDITIONAL_RENDERING, VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT); +ASSERT_SAME(PIPELINE_STAGE_FLAG_SHADING_RATE_TEXTURE, VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV); +ASSERT_SAME(PIPELINE_STAGE_FLAG_RAY_TRACING_SHADER, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV); +ASSERT_SAME(PIPELINE_STAGE_FLAG_ACCELERATION_STRUCTURE_BUILD, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_NV); +ASSERT_SAME(PIPELINE_STAGE_FLAG_TASK_SHADER, VK_PIPELINE_STAGE_TASK_SHADER_BIT_NV); +ASSERT_SAME(PIPELINE_STAGE_FLAG_MESH_SHADER, VK_PIPELINE_STAGE_MESH_SHADER_BIT_NV); +ASSERT_SAME(PIPELINE_STAGE_FLAG_FRAGMENT_DENSITY_PROCESS, VK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT); // clang-format on VkPipelineStageFlags PipelineStageFlagsToVkPipelineStageFlags(PIPELINE_STAGE_FLAGS PipelineStageFlags) { @@ -1478,33 +1481,34 @@ VkPipelineStageFlags PipelineStageFlagsToVkPipelineStageFlags(PIPELINE_STAGE_FLA // clang-format off -static_assert(ACCESS_FLAG_NONE == 0, ""); -static_assert(ACCESS_FLAG_INDIRECT_COMMAND_READ == VK_ACCESS_INDIRECT_COMMAND_READ_BIT, "ACCESS_FLAG_INDIRECT_COMMAND_READ != VK_ACCESS_INDIRECT_COMMAND_READ_BIT"); -static_assert(ACCESS_FLAG_INDEX_READ == VK_ACCESS_INDEX_READ_BIT, "ACCESS_FLAG_INDEX_READ != VK_ACCESS_INDEX_READ_BIT"); -static_assert(ACCESS_FLAG_VERTEX_READ == VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, "ACCESS_FLAG_VERTEX_READ != VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT"); -static_assert(ACCESS_FLAG_UNIFORM_READ == VK_ACCESS_UNIFORM_READ_BIT, "ACCESS_FLAG_UNIFORM_READ != VK_ACCESS_UNIFORM_READ_BIT"); -static_assert(ACCESS_FLAG_INPUT_ATTACHMENT_READ == VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, "ACCESS_FLAG_INPUT_ATTACHMENT_READ != VK_ACCESS_INPUT_ATTACHMENT_READ_BIT"); -static_assert(ACCESS_FLAG_SHADER_READ == VK_ACCESS_SHADER_READ_BIT, "ACCESS_FLAG_SHADER_READ != VK_ACCESS_SHADER_READ_BIT"); -static_assert(ACCESS_FLAG_SHADER_WRITE == VK_ACCESS_SHADER_WRITE_BIT, "ACCESS_FLAG_SHADER_WRITE != VK_ACCESS_SHADER_WRITE_BIT"); -static_assert(ACCESS_FLAG_RENDER_TARGET_READ == VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, "ACCESS_FLAG_RENDER_TARGET_READ != VK_ACCESS_COLOR_ATTACHMENT_READ_BIT"); -static_assert(ACCESS_FLAG_RENDER_TARGET_WRITE == VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, "ACCESS_FLAG_RENDER_TARGET_WRITE != VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT"); -static_assert(ACCESS_FLAG_DEPTH_STENCIL_READ == VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, "ACCESS_FLAG_DEPTH_STENCIL_READ != VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT"); -static_assert(ACCESS_FLAG_DEPTH_STENCIL_WRITE == VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, "ACCESS_FLAG_DEPTH_STENCIL_WRITE != VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT"); -static_assert(ACCESS_FLAG_COPY_SRC == VK_ACCESS_TRANSFER_READ_BIT, "ACCESS_FLAG_COPY_SRC != VK_ACCESS_TRANSFER_READ_BIT"); -static_assert(ACCESS_FLAG_COPY_DST == VK_ACCESS_TRANSFER_WRITE_BIT, "ACCESS_FLAG_COPY_DST != VK_ACCESS_TRANSFER_WRITE_BIT"); -static_assert(ACCESS_FLAG_HOST_READ == VK_ACCESS_HOST_READ_BIT, "ACCESS_FLAG_HOST_READ != VK_ACCESS_HOST_READ_BIT"); -static_assert(ACCESS_FLAG_HOST_WRITE == VK_ACCESS_HOST_WRITE_BIT, "ACCESS_FLAG_HOST_WRITE != VK_ACCESS_HOST_WRITE_BIT"); -static_assert(ACCESS_FLAG_MEMORY_READ == VK_ACCESS_MEMORY_READ_BIT, "ACCESS_FLAG_MEMORY_READ != VK_ACCESS_MEMORY_READ_BIT"); -static_assert(ACCESS_FLAG_MEMORY_WRITE == VK_ACCESS_MEMORY_WRITE_BIT, "ACCESS_FLAG_MEMORY_WRITE != VK_ACCESS_MEMORY_WRITE_BIT"); -static_assert(ACCESS_FLAG_CONDITIONAL_RENDERING_READ == VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT, "ACCESS_FLAG_CONDITIONAL_RENDERING_READ != VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT"); -static_assert(ACCESS_FLAG_SHADING_RATE_TEXTURE_READ == VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV, "ACCESS_FLAG_SHADING_RATE_TEXTURE_READ != VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV"); -static_assert(ACCESS_FLAG_ACCELERATION_STRUCTURE_READ == VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV, "ACCESS_FLAG_ACCELERATION_STRUCTURE_READ != VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV"); -static_assert(ACCESS_FLAG_ACCELERATION_STRUCTURE_WRITE == VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NV, "ACCESS_FLAG_ACCELERATION_STRUCTURE_WRITE != VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NV"); -static_assert(ACCESS_FLAG_FRAGMENT_DENSITY_MAP_READ == VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT, "ACCESS_FLAG_FRAGMENT_DENSITY_MAP_READ != VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT"); +static_assert(ACCESS_FLAG_NONE == 0, ""); +ASSERT_SAME(ACCESS_FLAG_INDIRECT_COMMAND_READ, VK_ACCESS_INDIRECT_COMMAND_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_INDEX_READ, VK_ACCESS_INDEX_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_VERTEX_READ, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_UNIFORM_READ, VK_ACCESS_UNIFORM_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_INPUT_ATTACHMENT_READ, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_SHADER_READ, VK_ACCESS_SHADER_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_SHADER_WRITE, VK_ACCESS_SHADER_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_RENDER_TARGET_READ, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_RENDER_TARGET_WRITE, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_DEPTH_STENCIL_READ, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_DEPTH_STENCIL_WRITE, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_COPY_SRC, VK_ACCESS_TRANSFER_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_COPY_DST, VK_ACCESS_TRANSFER_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_HOST_READ, VK_ACCESS_HOST_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_HOST_WRITE, VK_ACCESS_HOST_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_MEMORY_READ, VK_ACCESS_MEMORY_READ_BIT); +ASSERT_SAME(ACCESS_FLAG_MEMORY_WRITE, VK_ACCESS_MEMORY_WRITE_BIT); +ASSERT_SAME(ACCESS_FLAG_CONDITIONAL_RENDERING_READ, VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT); +ASSERT_SAME(ACCESS_FLAG_SHADING_RATE_TEXTURE_READ, VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV); +ASSERT_SAME(ACCESS_FLAG_ACCELERATION_STRUCTURE_READ, VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV); +ASSERT_SAME(ACCESS_FLAG_ACCELERATION_STRUCTURE_WRITE, VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_NV); +ASSERT_SAME(ACCESS_FLAG_FRAGMENT_DENSITY_MAP_READ, VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT); // clang-format on VkAccessFlags AccessFlagsToVkAccessFlags(ACCESS_FLAGS AccessFlags) { return static_cast(AccessFlags); } +#undef ASSERT_SAME } // namespace Diligent -- cgit v1.2.3 From 6e663135a6d194f5ed8b41f112c6d5a2c98b080d Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 6 Aug 2020 11:30:15 -0700 Subject: Added few debug checks --- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 5f26479d..3162e3be 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -911,6 +911,11 @@ void DeviceContextVkImpl::FinishFrame() "All queries must be ended before the frame is finished."); } + if (m_pActiveRenderPass != nullptr) + { + LOG_ERROR_MESSAGE("Finishing frame inside an active render pass."); + } + if (!m_MappedTextures.empty()) LOG_ERROR_MESSAGE("There are mapped textures in the device context when finishing the frame. All dynamic resources must be used in the same frame in which they are mapped."); @@ -1012,7 +1017,9 @@ void DeviceContextVkImpl::Flush() m_State = ContextState{}; m_DescrSetBindInfo.Reset(); m_CommandBuffer.Reset(); - m_pPipelineState = nullptr; + m_pPipelineState = nullptr; + m_pActiveRenderPass = nullptr; + m_pBoundFramebuffer = nullptr; } void DeviceContextVkImpl::SetVertexBuffers(Uint32 StartSlot, -- cgit v1.2.3 From a72d485f4b157d5c8fb488bc2afb3b9278e465b7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 6 Aug 2020 20:41:08 -0700 Subject: Treating subpass render target and depth stencil attachments as current RT and DS buffers --- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 3162e3be..e5f37de3 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1214,6 +1214,14 @@ void DeviceContextVkImpl::SetRenderTargets(Uint32 NumRen ITextureView* pDepthStencil, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { +#ifdef DILIGENT_DEVELOPMENT + if (m_pActiveRenderPass != nullptr) + { + LOG_ERROR_MESSAGE("Calling SetRenderTargets inside active render pass is invalid. End the render pass first"); + return; + } +#endif + if (TDeviceContextBase::SetRenderTargets(NumRenderTargets, ppRenderTargets, pDepthStencil)) { FramebufferCache::FramebufferCacheKey FBKey; @@ -1331,15 +1339,15 @@ void DeviceContextVkImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) void DeviceContextVkImpl::NextSubpass() { TDeviceContextBase::NextSubpass(); - EnsureVkCmdBuffer(); + VERIFY_EXPR(m_CommandBuffer.GetVkCmdBuffer() != VK_NULL_HANDLE && m_CommandBuffer.GetState().RenderPass != VK_NULL_HANDLE); m_CommandBuffer.NextSubpass(); } void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) { TDeviceContextBase::EndRenderPass(UpdateResourceStates); - EnsureVkCmdBuffer(); - m_CommandBuffer.EndRenderPass(); + // TDeviceContextBase::EndRenderPass calls ResetRenderTargets() that in turn + // calls m_CommandBuffer.EndRenderPass() if (m_State.NumCommands >= m_NumCommandsToFlush && !m_bIsDeferred && // Never flush deferred context -- cgit v1.2.3 From ec597230af7b2031c7856f0cfa4e63b72e06948b Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 6 Aug 2020 21:13:00 -0700 Subject: Vk backend: fixed ClearRenderTarget and ClearDepthStencil for subpass attachments --- .../src/DeviceContextVkImpl.cpp | 60 +++++----------------- 1 file changed, 12 insertions(+), 48 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index e5f37de3..cc72fbb2 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -651,27 +651,10 @@ void DeviceContextVkImpl::ClearDepthStencil(ITextureView* pView const auto& ViewDesc = pVkDSV->GetDesc(); VERIFY(ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D, "Depth-stencil view of a 3D texture should've been created as 2D texture array view"); - bool ClearAsAttachment = false; - if (m_pActiveRenderPass != nullptr) - { - const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); - for (Uint32 i = 0; i < FBDesc.AttachmentCount && !ClearAsAttachment; ++i) - { - ClearAsAttachment = FBDesc.ppAttachments[i] == pView; - } - - if (!ClearAsAttachment) - { - UNEXPECTED("DSV was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearDepthStencil " - "checks if the DSV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); - return; - } - } - else - { - ClearAsAttachment = pVkDSV == m_pBoundDepthStencil; - } - + bool ClearAsAttachment = pVkDSV == m_pBoundDepthStencil; + VERIFY(m_pActiveRenderPass == nullptr || ClearAsAttachment, + "DSV was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearDepthStencil " + "checks if the DSV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); if (ClearAsAttachment) { VERIFY_EXPR(m_vkRenderPass != VK_NULL_HANDLE && m_vkFramebuffer != VK_NULL_HANDLE); @@ -777,40 +760,21 @@ void DeviceContextVkImpl::ClearRenderTarget(ITextureView* pView, const float* RG VERIFY(ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D, "Render target view of a 3D texture should've been created as 2D texture array view"); // Check if the texture is one of the currently bound render targets - static constexpr const Uint32 InvalidAttachmentIndex = static_cast(-1); + static constexpr const Uint32 InvalidAttachmentIndex = ~Uint32{0}; Uint32 attachmentIndex = InvalidAttachmentIndex; - if (m_pActiveRenderPass != nullptr) - { - const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); - for (Uint32 i = 0; i < FBDesc.AttachmentCount; ++i) - { - if (FBDesc.ppAttachments[i] == pView) - { - attachmentIndex = i; - break; - } - } - - if (attachmentIndex == InvalidAttachmentIndex) - { - UNEXPECTED("RTV was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearRenderTarget " - "checks if the RTV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); - return; - } - } - else + for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) { - for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) + if (m_pBoundRenderTargets[rt] == pVkRTV) { - if (m_pBoundRenderTargets[rt] == pVkRTV) - { - attachmentIndex = rt; - break; - } + attachmentIndex = rt; + break; } } + VERIFY(m_pActiveRenderPass == nullptr || attachmentIndex != InvalidAttachmentIndex, + "Render target was not found in the framebuffer. This is unexpected because TDeviceContextBase::ClearRenderTarget " + "checks if the RTV is bound as a framebuffer attachment and returns false otherwise (in development mode)."); if (attachmentIndex != InvalidAttachmentIndex) { -- cgit v1.2.3 From d04e840486b08bc8356d6e7275a8e7f4d54f68e3 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 8 Aug 2020 15:40:24 -0700 Subject: D3D12 backend: implemented render pass attachment state transitons --- Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp | 2 +- Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 7 +++++-- Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp index 741ced4f..dbba5b7e 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp @@ -65,7 +65,7 @@ VkSamplerAddressMode AddressModeToVkAddressMode(TEXTURE_ADDRESS_MODE AddressMode VkBorderColor BorderColorToVkBorderColor(const Float32 BorderColor[]); VkAccessFlags ResourceStateFlagsToVkAccessFlags(RESOURCE_STATE StateFlags); -VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag); +VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag, bool IsInsideRenderPass = false); RESOURCE_STATE VkAccessFlagsToResourceStates(VkAccessFlags AccessFlags); RESOURCE_STATE VkImageLayoutToResourceState(VkImageLayout Layout); diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index a0a25f89..8858fb50 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -88,8 +88,11 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, auto* pCurrVkAttachmentReference = &vkAttachmentReferences[CurrAttachmentReferenceInd]; for (Uint32 attachment = 0; attachment < NumAttachments; ++attachment, ++CurrAttachmentReferenceInd) { - vkAttachmentReferences[CurrAttachmentReferenceInd].attachment = pSrcAttachments[attachment].AttachmentIndex; - vkAttachmentReferences[CurrAttachmentReferenceInd].layout = ResourceStateToVkImageLayout(pSrcAttachments[attachment].State); + const auto& AttachmnetRef = pSrcAttachments[attachment]; + + vkAttachmentReferences[CurrAttachmentReferenceInd].attachment = AttachmnetRef.AttachmentIndex; + vkAttachmentReferences[CurrAttachmentReferenceInd].layout = + ResourceStateToVkImageLayout(AttachmnetRef.State, /*IsInsideRenderPass = */ true); } return pCurrVkAttachmentReference; diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp index bf34a07a..25966163 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp @@ -1304,7 +1304,7 @@ RESOURCE_STATE VkAccessFlagsToResourceStates(VkAccessFlags AccessFlags) -VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag) +VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag, bool IsInsideRenderPass) { if (StateFlag == RESOURCE_STATE_UNKNOWN) { @@ -1335,7 +1335,7 @@ VkImageLayout ResourceStateToVkImageLayout(RESOURCE_STATE StateFlag) case RESOURCE_STATE_INDIRECT_ARGUMENT: UNEXPECTED("Invalid resource state"); return VK_IMAGE_LAYOUT_UNDEFINED; case RESOURCE_STATE_COPY_DEST: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; case RESOURCE_STATE_COPY_SOURCE: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; - case RESOURCE_STATE_RESOLVE_DEST: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + case RESOURCE_STATE_RESOLVE_DEST: return IsInsideRenderPass ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; case RESOURCE_STATE_RESOLVE_SOURCE: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; case RESOURCE_STATE_INPUT_ATTACHMENT: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; case RESOURCE_STATE_PRESENT: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; -- cgit v1.2.3 From fd6ecbc3e52569119c4e0ff30236bd23f2757737 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 8 Aug 2020 16:48:40 -0700 Subject: Implemented unified render pass attachment state updates within subpasses and after the render pass ends --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp | 2 +- Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index a0249ec9..ebca0282 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -142,7 +142,7 @@ public: virtual void DILIGENT_CALL_TYPE NextSubpass() override final; /// Implementation of IDeviceContext::EndRenderPass() in Direct3D11 backend. - virtual void DILIGENT_CALL_TYPE EndRenderPass(bool UpdateResourceStates) override final; + virtual void DILIGENT_CALL_TYPE EndRenderPass() override final; // clang-format off /// Implementation of IDeviceContext::Draw() in Vulkan backend. diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index cc72fbb2..2310109f 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1307,9 +1307,9 @@ void DeviceContextVkImpl::NextSubpass() m_CommandBuffer.NextSubpass(); } -void DeviceContextVkImpl::EndRenderPass(bool UpdateResourceStates) +void DeviceContextVkImpl::EndRenderPass() { - TDeviceContextBase::EndRenderPass(UpdateResourceStates); + TDeviceContextBase::EndRenderPass(); // TDeviceContextBase::EndRenderPass calls ResetRenderTargets() that in turn // calls m_CommandBuffer.EndRenderPass() -- cgit v1.2.3 From c2a16b234fbd087e3f076895f9ce6873ef7b3e29 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 8 Aug 2020 19:13:00 -0700 Subject: Vk backend: improved handling of RESOURCE_STATE_RESOLVE_DEST attachment state --- Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 8858fb50..c010e460 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -58,8 +58,8 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, vkAttachment.storeOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StoreOp); vkAttachment.stencilLoadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.StencilLoadOp); vkAttachment.stencilStoreOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StencilStoreOp); - vkAttachment.initialLayout = ResourceStateToVkImageLayout(Attachment.InitialState); - vkAttachment.finalLayout = ResourceStateToVkImageLayout(Attachment.FinalState); + vkAttachment.initialLayout = ResourceStateToVkImageLayout(Attachment.InitialState, /*IsInsideRenderPass = */ false); + vkAttachment.finalLayout = ResourceStateToVkImageLayout(Attachment.FinalState, /*IsInsideRenderPass = */ true); } RenderPassCI.attachmentCount = Desc.AttachmentCount; RenderPassCI.pAttachments = vkAttachments.data(); -- cgit v1.2.3 From e9b03b3adc24d569f3ca5e16629daf2d05d5aabc Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 15 Aug 2020 15:39:38 -0700 Subject: Vk backend: not setting render pass in SetPipelineState --- .../src/DeviceContextVkImpl.cpp | 25 ++++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 2310109f..619ec23c 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -283,14 +283,6 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) { m_CommandBuffer.SetStencilReference(m_StencilRef); m_CommandBuffer.SetBlendConstants(m_BlendFactors); - if (PSODesc.GraphicsPipeline.pRenderPass == nullptr) - { - CommitRenderPassAndFramebuffer(true); - } - else - { - // Render pass must be committed explicitly - } CommitViewports(); } @@ -434,6 +426,9 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) #ifdef DILIGENT_DEVELOPMENT if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) DvpVerifyRenderTargets(); + + VERIFY(m_vkRenderPass != VK_NULL_HANDLE, "No render pass is active while executing draw command"); + VERIFY(m_vkFramebuffer != VK_NULL_HANDLE, "No framebuffer is bound while executing draw command"); #endif EnsureVkCmdBuffer(); @@ -477,15 +472,17 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) # endif #endif -#ifdef DILIGENT_DEVELOPMENT - if (m_pPipelineState->GetRenderPass()->GetVkRenderPass() != m_vkRenderPass) + if (m_pPipelineState->GetDesc().GraphicsPipeline.pRenderPass == nullptr) { - DvpLogRenderPass_PSOMismatch(); - } +#ifdef DILIGENT_DEVELOPMENT + if (m_pPipelineState->GetRenderPass()->GetVkRenderPass() != m_vkRenderPass) + { + // Note that different Vulkan render passes may still be compatible, + // so we should only verify implicit render passes + DvpLogRenderPass_PSOMismatch(); + } #endif - if (m_pPipelineState->GetDesc().GraphicsPipeline.pRenderPass == nullptr) - { CommitRenderPassAndFramebuffer((Flags & DRAW_FLAG_VERIFY_STATES) != 0); } } -- cgit v1.2.3