diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-08-01 18:46:38 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-08-02 19:21:43 +0000 |
| commit | 465e53fd32f983aadc2e46c6cee3a0d7b836fe64 (patch) | |
| tree | 206a706c553fac838c468d5aad80def8e5b9be03 /Graphics | |
| parent | Fixed minor build issue (diff) | |
| download | DiligentCore-465e53fd32f983aadc2e46c6cee3a0d7b836fe64.tar.gz DiligentCore-465e53fd32f983aadc2e46c6cee3a0d7b836fe64.zip | |
Implemented BeginRenderPass/NextSubpass/EndRenderPass in Vulkan backend
Diffstat (limited to 'Graphics')
6 files changed, 136 insertions, 60 deletions
diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 8136c582..5eca22a9 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -617,9 +617,21 @@ typedef struct CopyTextureAttribs CopyTextureAttribs; /// This structure is used by IDeviceContext::BeginRenderPass(). struct BeginRenderPassAttribs { + /// Render pass to begin. IRenderPass* pRenderPass DEFAULT_INITIALIZER(nullptr); + /// Framebuffer containing the attachments that are used with the render pass. IFramebuffer* pFramebuffer DEFAULT_INITIALIZER(nullptr); + + /// The number of elements in pClearValues array. + Uint32 ClearValueCount DEFAULT_INITIALIZER(0); + + /// A pointer to an array of ClearValueCount OptimizedClearValue structures that contains + /// clear values for each attachment, if the attachment uses a LoadOp value of ATTACHMENT_LOAD_OP_CLEAR + /// or if the attachment has a depth/stencil format and uses a StencilLoadOp value of 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. + OptimizedClearValue* pClearValues DEFAULT_INITIALIZER(nullptr); }; typedef struct BeginRenderPassAttribs BeginRenderPassAttribs; diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index 5fbb5412..796d7449 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1079,6 +1079,55 @@ DILIGENT_TYPED_ENUM(PRIMITIVE_TOPOLOGY, Uint8) PRIMITIVE_TOPOLOGY_NUM_TOPOLOGIES }; + +/// Defines optimized depth-stencil clear value. +struct DepthStencilClearValue +{ + /// Depth clear value + Float32 Depth DEFAULT_INITIALIZER(1.f); + /// Stencil clear value + Uint8 Stencil DEFAULT_INITIALIZER(0); + +#if DILIGENT_CPP_INTERFACE + DepthStencilClearValue()noexcept{} + + DepthStencilClearValue(Float32 _Depth, + Uint8 _Stencil)noexcept : + Depth {_Depth }, + Stencil {_Stencil} + {} +#endif +}; +typedef struct DepthStencilClearValue DepthStencilClearValue; + +/// Defines optimized clear value. +struct OptimizedClearValue +{ + /// Format + TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN); + + /// Render target clear value + Float32 Color[4] DEFAULT_INITIALIZER({}); + + /// Depth stencil clear value + DepthStencilClearValue DepthStencil; + +#if DILIGENT_CPP_INTERFACE + bool operator == (const OptimizedClearValue& rhs)const + { + return Format == rhs.Format && + Color[0] == rhs.Color[0] && + Color[1] == rhs.Color[1] && + Color[2] == rhs.Color[2] && + Color[3] == rhs.Color[3] && + DepthStencil.Depth == rhs.DepthStencil.Depth && + DepthStencil.Stencil == rhs.DepthStencil.Stencil; + } +#endif +}; +typedef struct OptimizedClearValue OptimizedClearValue; + + /// Describes common device object attributes struct DeviceObjectAttribs { diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h index 294bb875..3f61338f 100644 --- a/Graphics/GraphicsEngine/interface/Texture.h +++ b/Graphics/GraphicsEngine/interface/Texture.h @@ -32,6 +32,7 @@ /// \file /// Definition of the Diligent::ITexture interface and related data structures +#include "GraphicsTypes.h" #include "DeviceObject.h" #include "TextureView.h" @@ -42,53 +43,6 @@ DILIGENT_BEGIN_NAMESPACE(Diligent) static const INTERFACE_ID IID_Texture = {0xa64b0e60, 0x1b5e, 0x4cfd,{0xb8, 0x80, 0x66, 0x3a, 0x1a, 0xdc, 0xbe, 0x98}}; -/// Defines optimized depth-stencil clear value. -struct DepthStencilClearValue -{ - /// Depth clear value - Float32 Depth DEFAULT_INITIALIZER(1.f); - /// Stencil clear value - Uint8 Stencil DEFAULT_INITIALIZER(0); - -#if DILIGENT_CPP_INTERFACE - DepthStencilClearValue()noexcept{} - - DepthStencilClearValue(Float32 _Depth, - Uint8 _Stencil)noexcept : - Depth {_Depth }, - Stencil {_Stencil} - {} -#endif -}; -typedef struct DepthStencilClearValue DepthStencilClearValue; - -/// Defines optimized clear value. -struct OptimizedClearValue -{ - /// Format - TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN); - - /// Render target clear value - Float32 Color[4] DEFAULT_INITIALIZER({}); - - /// Depth stencil clear value - DepthStencilClearValue DepthStencil; - -#if DILIGENT_CPP_INTERFACE - bool operator == (const OptimizedClearValue& rhs)const - { - return Format == rhs.Format && - Color[0] == rhs.Color[0] && - Color[1] == rhs.Color[1] && - Color[2] == rhs.Color[2] && - Color[3] == rhs.Color[3] && - DepthStencil.Depth == rhs.DepthStencil.Depth && - DepthStencil.Stencil == rhs.DepthStencil.Stencil; - } -#endif -}; -typedef struct OptimizedClearValue OptimizedClearValue; - /// Texture description struct TextureDesc DILIGENT_DERIVE(DeviceObjectAttribs) 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<QueryManagerVk> m_QueryMgr; Int32 m_ActiveQueriesCounter = 0; + + std::vector<VkClearValue> 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<IBuffer> pDummyVB; m_pDevice->CreateBuffer(DummyVBDesc, nullptr, &pDummyVB); m_DummyVB = pDummyVB.RawPtr<BufferVkImpl>(); + + 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, |
