From 9e62ec0d4b9c7ea9d6fc3d19b9d29481dffb697c Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 9 Nov 2019 22:17:46 -0800 Subject: Added 'ResolveTextureSubresource' device context command (API Version 240041) (not yet implemented in OpenGL backend) --- .../GraphicsEngine/include/DeviceContextBase.h | 38 ++++++++++++++++++++ Graphics/GraphicsEngine/interface/APIInfo.h | 2 +- Graphics/GraphicsEngine/interface/DeviceContext.h | 42 +++++++++++++++++++++- Graphics/GraphicsEngine/interface/GraphicsTypes.h | 5 --- 4 files changed, 80 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 5ed6dc56..98962e44 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -161,6 +161,10 @@ public: /// Sets the strong pointer to the swap chain virtual void SetSwapChain( ISwapChain* pSwapChain )override final { m_pSwapChain = pSwapChain; } + virtual void ResolveTextureSubresource(ITexture* pSrcTexture, + ITexture* pDstTexture, + const ResolveTextureSubresourceAttribs& ResolveAttribs)override = 0; + /// Returns the swap chain ISwapChain* GetSwapChain() { return m_pSwapChain; } @@ -1250,6 +1254,40 @@ bool DeviceContextBase :: return true; } +template +void DeviceContextBase :: + ResolveTextureSubresource(ITexture* pSrcTexture, + ITexture* pDstTexture, + const ResolveTextureSubresourceAttribs& ResolveAttribs) +{ + VERIFY_EXPR(pSrcTexture != nullptr && pDstTexture != nullptr); + const auto& SrcTexDesc = pSrcTexture->GetDesc(); + const auto& DstTexDesc = pDstTexture->GetDesc(); + DEV_CHECK_ERR(SrcTexDesc.SampleCount > 1, "Source texture '", SrcTexDesc.Name, "' of a resolve operation is not multi-sampled"); + DEV_CHECK_ERR(DstTexDesc.SampleCount == 1, "Destination texture '", DstTexDesc.Name, "' of a resolve operation is multi-sampled"); + auto SrcMipLevelProps = GetMipLevelProperties(SrcTexDesc, ResolveAttribs.SrcMipLevel); + auto DstMipLevelProps = GetMipLevelProperties(DstTexDesc, ResolveAttribs.DstMipLevel); + DEV_CHECK_ERR(SrcMipLevelProps.LogicalWidth == DstMipLevelProps.LogicalWidth && SrcMipLevelProps.LogicalHeight == DstMipLevelProps.LogicalHeight, + "The size (", SrcMipLevelProps.LogicalWidth, "x", SrcMipLevelProps.LogicalHeight, ") of the source subresource of a resolve operation " + "(texture '", SrcTexDesc.Name, "', mip ", ResolveAttribs.SrcMipLevel, ", slice ", ResolveAttribs.SrcSlice, + ") does not match the size (", DstMipLevelProps.LogicalWidth, "x", DstMipLevelProps.LogicalHeight, + ") of the destination subresource (texture '", DstTexDesc.Name, "', mip ", ResolveAttribs.DstMipLevel, ", slice ", + ResolveAttribs.DstSlice, ")"); + + const auto& SrcFmtAttribs = GetTextureFormatAttribs(SrcTexDesc.Format); + const auto& DstFmtAttribs = GetTextureFormatAttribs(DstTexDesc.Format); + const auto& ResolveFmtAttribs = GetTextureFormatAttribs(ResolveAttribs.Format); + if (ResolveAttribs.Format != TEX_FORMAT_UNKNOWN) + { + DEV_CHECK_ERR(!SrcFmtAttribs.IsTypeless && !DstFmtAttribs.IsTypeless, + "Format of a resolve operations must not be unknown when one of the texture formats is typeless"); + } + if (SrcFmtAttribs.IsTypeless || DstFmtAttribs.IsTypeless) + { + DEV_CHECK_ERR(!ResolveFmtAttribs.IsTypeless, "Format of a resolve operations must not be typeless when one of the texture formats is typeless"); + } +} + #endif // DEVELOPMENT } diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index b59997de..cdfcf2ac 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -26,7 +26,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240040 +#define DILIGENT_API_VERSION 240041 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index baa2dd64..f631482f 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -403,6 +403,36 @@ struct DispatchComputeIndirectAttribs {} }; + +/// Describes multi-sampled texture resolve command arguments. + +/// This structure is used by IDeviceContext::ResolveTextureSubresource(). +struct ResolveTextureSubresourceAttribs +{ + /// Mip level of the source multi-sampled texture to resolve. + Uint32 SrcMipLevel = 0; + + /// Array slice of the source multi-sampled texture to resolve. + Uint32 SrcSlice = 0; + + /// Source texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE. + RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE; + + /// Mip level of the destination non-multi-sampled texture. + Uint32 DstMipLevel = 0; + + /// Array slice of the destination non-multi-sampled texture. + Uint32 DstSlice = 0; + + /// Destination texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE. + RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE; + + /// If one or both textures are typeless, specifies the type of the typeless texture. + /// If both texture formats are not typeless, in which case they must be identical, this member must be + /// either TEX_FORMAT_UNKNOWN, or match this format. + TEXTURE_FORMAT Format = TEX_FORMAT_UNKNOWN; +}; + /// Defines allowed flags for IDeviceContext::SetVertexBuffers() function. enum SET_VERTEX_BUFFERS_FLAGS : Uint8 { @@ -1151,7 +1181,7 @@ public: /// When StateTransitionDesc::UpdateResourceState is set to true, the method may update the state of the /// corresponding resource which is not thread safe. No other threads should read or write the sate of that /// resource. - + /// /// \note Any method that uses Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode may alter /// the state of resources it works with. Diligent::RESOURCE_STATE_TRANSITION_MODE_VERIFY mode /// makes the method read the states, but not write them. When Diligent::RESOURCE_STATE_TRANSITION_MODE_NONE @@ -1161,6 +1191,16 @@ public: /// Refer to http://diligentgraphics.com/2018/12/09/resource-state-management/ for detailed explanation /// of resource state management in Diligent Engine. virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) = 0; + + + /// Resolves a multi-sampled texture subresource into a non-multi-sampled texture subresource. + + /// \param [in] pSrcTexture - Source multi-sampled texture. + /// \param [in] pDstTexture - Destination non-multi-sampled texture. + /// \param [in] ResolveAttribs - Resolve command attributes, see Diligent::ResolveTextureSubresourceAttribs for details. + virtual void ResolveTextureSubresource(ITexture* pSrcTexture, + ITexture* pDstTexture, + const ResolveTextureSubresourceAttribs& ResolveAttribs) = 0; }; } diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index bc2fe679..449f2b84 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1209,9 +1209,6 @@ namespace Diligent /// Swap chain usage flags. Default value is Diligent::SWAP_CHAIN_USAGE_RENDER_TARGET SWAP_CHAIN_USAGE_FLAGS Usage = SWAP_CHAIN_USAGE_RENDER_TARGET; - /// Sample count. Default value is 1 - Uint32 SamplesCount = 1; - /// Number of buffers int the swap chain Uint32 BufferCount = 2; @@ -1234,7 +1231,6 @@ namespace Diligent Uint32 _Height, TEXTURE_FORMAT _ColorBufferFormat, TEXTURE_FORMAT _DepthBufferFormat, - Uint32 _SamplesCount = SwapChainDesc{}.SamplesCount, Uint32 _BufferCount = SwapChainDesc{}.BufferCount, Float32 _DefaultDepthValue = SwapChainDesc{}.DefaultDepthValue, Uint8 _DefaultStencilValue = SwapChainDesc{}.DefaultStencilValue, @@ -1243,7 +1239,6 @@ namespace Diligent Height (_Height), ColorBufferFormat (_ColorBufferFormat), DepthBufferFormat (_DepthBufferFormat), - SamplesCount (_SamplesCount), BufferCount (_BufferCount), DefaultDepthValue (_DefaultDepthValue), DefaultStencilValue (_DefaultStencilValue), -- cgit v1.2.3