diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-12-02 23:36:10 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-12-02 23:36:10 +0000 |
| commit | da52d8bbc1ffcf82ed98e0198ecb2bc25530b2c0 (patch) | |
| tree | 3f2bd399de343b2c77ced0f167423476bd5f8835 /Graphics/GraphicsEngine | |
| parent | Brought back MapType paramter to UnmapBuffer() function. The performance hit ... (diff) | |
| download | DiligentCore-da52d8bbc1ffcf82ed98e0198ecb2bc25530b2c0.tar.gz DiligentCore-da52d8bbc1ffcf82ed98e0198ecb2bc25530b2c0.zip | |
Added explicit state transition control to CopyBuffer() and CopyTexture() methods
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 45 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/TextureBase.h | 4 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/DeviceContext.h | 134 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/Texture.cpp | 24 |
4 files changed, 113 insertions, 94 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 9de83dec..0d0a6337 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -114,7 +114,13 @@ public: virtual void UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override = 0; /// Base implementation of IDeviceContext::CopyBuffer(); validates input parameters. - virtual void CopyBuffer(IBuffer *pSrcBuffer, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size)override = 0; + virtual void CopyBuffer(IBuffer* pSrcBuffer, + Uint32 SrcOffset, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + IBuffer* pDstBuffer, + Uint32 DstOffset, + Uint32 Size, + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode)override = 0; /// Base implementation of IDeviceContext::MapBuffer(); validates input parameters. virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override = 0; @@ -127,16 +133,7 @@ public: RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode )override = 0; /// Base implementaiton of IDeviceContext::CopyTexture(); validates input parameters - virtual void CopyTexture( ITexture* pSrcTexture, - Uint32 SrcMipLevel, - Uint32 SrcSlice, - const Box *pSrcBox, - ITexture* pDstTexture, - Uint32 DstMipLevel, - Uint32 DstSlice, - Uint32 DstX, - Uint32 DstY, - Uint32 DstZ )override = 0; + virtual void CopyTexture( const CopyTextureAttribs& CopyAttribs )override = 0; /// Base implementaiton of IDeviceContext::MapTextureSubresource() virtual void MapTextureSubresource(ITexture* pTexture, @@ -706,7 +703,13 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, Pi template<typename BaseInterface, typename BufferImplType, typename TextureImplType, typename PipelineStateImplType> inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, PipelineStateImplType> :: - CopyBuffer(IBuffer *pSrcBuffer, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size) + CopyBuffer(IBuffer* pSrcBuffer, + Uint32 SrcOffset, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + IBuffer* pDstBuffer, + Uint32 DstOffset, + Uint32 Size, + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) { VERIFY(pSrcBuffer != nullptr, "Source buffer must not be null"); VERIFY(pDstBuffer != nullptr, "Destination buffer must not be null"); @@ -791,21 +794,11 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, Pi template<typename BaseInterface, typename BufferImplType, typename TextureImplType, typename PipelineStateImplType> inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, PipelineStateImplType> :: - CopyTexture( ITexture* pSrcTexture, - Uint32 SrcMipLevel, - Uint32 SrcSlice, - const Box* pSrcBox, - ITexture* pDstTexture, - Uint32 DstMipLevel, - Uint32 DstSlice, - Uint32 DstX, - Uint32 DstY, - Uint32 DstZ ) + CopyTexture( const CopyTextureAttribs& CopyAttribs ) { - VERIFY( pSrcTexture, "pSrcTexture must not be null" ); - VERIFY( pDstTexture, "pSrcTexture must not be null" ); - ValidateCopyTextureParams( pSrcTexture->GetDesc(), SrcMipLevel, SrcSlice, pSrcBox, - pDstTexture->GetDesc(), DstMipLevel, DstSlice, DstX, DstY, DstZ ); + VERIFY( CopyAttribs.pSrcTexture, "Src texture must not be null" ); + VERIFY( CopyAttribs.pDstTexture, "Dst texture must not be null" ); + ValidateCopyTextureParams( CopyAttribs ); } template<typename BaseInterface, typename BufferImplType, typename TextureImplType, typename PipelineStateImplType> diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h index 1aaec627..990b9bc2 100644 --- a/Graphics/GraphicsEngine/include/TextureBase.h +++ b/Graphics/GraphicsEngine/include/TextureBase.h @@ -38,9 +38,7 @@ namespace Diligent void ValidateTextureDesc(const TextureDesc& TexDesc); void ValidateUpdateTextureParams( const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData ); -void ValidateCopyTextureParams( const TextureDesc& SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box* pSrcBox, - const TextureDesc& DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice, - Uint32 DstX, Uint32 DstY, Uint32 DstZ ); +void ValidateCopyTextureParams( const CopyTextureAttribs& CopyAttribs ); void ValidateMapTextureParams(const TextureDesc& TexDesc, Uint32 MipLevel, Uint32 ArraySlice, diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 2d252810..c515ce88 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -296,27 +296,6 @@ enum SET_RENDER_TARGETS_FLAGS }; DEFINE_FLAG_ENUM_OPERATORS(SET_RENDER_TARGETS_FLAGS) -/// Defines state transitions performed by IDeviceContext::ClearRenderTarget() command -enum CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE -{ - /// Perform no state transitions - CLEAR_RENDER_TARGET_NO_TRANSITION = 0, - - /// Transition the render target to the required state. - /// \remarks In D3D12 backend, the render target must always be transitioned to - /// Diligent::RESOURCE_STATE_RENDER_TARGET state. In Vulkan backend - /// however this depends on whether the render pass has been started. - /// To clear render target outside of render pass, it must be in - /// Diligent::RESOURCE_STATE_COPY_DEST state. Inside a render pass it - /// must be in Diligent::RESOURCE_STATE_RENDER_TARGET state. - CLEAR_RENDER_TARGET_TRANSITION_STATE, - - /// Do not perform transition, but verify that the state is correct. - /// This mode only has effect in debug and development builds. No validation - /// is performed in release build. - CLEAR_RENDER_TARGET_VERIFY_STATE -}; - /// Defines resource state transitions performed by various commands enum RESOURCE_STATE_TRANSITION_MODE { @@ -400,6 +379,60 @@ struct Rect }; +/// Defines copy texture command attributes + +/// This structure is used by IDeviceContext::CopyTexture() +struct CopyTextureAttribs +{ + /// Source texture to copy data from. + ITexture* pSrcTexture = nullptr; + + /// Mip level of the source texture to copy data from. + Uint32 SrcMipLevel = 0; + + /// Array slice of the source texture to copy data from. Must be 0 for non-array textures. + Uint32 SrcSlice = 0; + + /// Source region to copy. Use nullptr to copy the entire subresource. + const Box* pSrcBox = nullptr; + + /// Source texture state transition mode (see Diligent::RESOURCE_STATE_TRANSITION_MODE). + RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE; + + /// Destination texture to copy data to. + ITexture* pDstTexture = nullptr; + + /// Mip level to copy data to. + Uint32 DstMipLevel = 0; + + /// Array slice to copy data to. Must be 0 for non-array textures. + Uint32 DstSlice = 0; + + /// X offset on the destination subresource. + Uint32 DstX = 0; + + /// Y offset on the destination subresource. + Uint32 DstY = 0; + + /// Z offset on the destination subresource + Uint32 DstZ = 0; + + /// Destination texture state transition mode (see Diligent::RESOURCE_STATE_TRANSITION_MODE). + RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE; + + CopyTextureAttribs(){} + + CopyTextureAttribs(ITexture* _pSrcTexture, + RESOURCE_STATE_TRANSITION_MODE _SrcTextureTransitionMode, + ITexture* _pDstTexture, + RESOURCE_STATE_TRANSITION_MODE _DstTextureTransitionMode) : + pSrcTexture (_pSrcTexture), + SrcTextureTransitionMode(_SrcTextureTransitionMode), + pDstTexture (_pDstTexture), + DstTextureTransitionMode(_DstTextureTransitionMode) + {} +}; + /// Device context interface /// \remarks Device context keeps strong references to all objects currently bound to @@ -638,10 +671,16 @@ public: /// Diligent::TEXTURE_VIEW_RENDER_TARGET. /// \param [in] RGBA - A 4-component array that represents the color to fill the render target with. /// If nullptr is provided, the default array {0,0,0,0} will be used. - /// \param [in] StateTransitionMode - Defines requires state transitions (see Diligent::CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE) + /// \param [in] StateTransitionMode - Defines requires state transitions (see Diligent::RESOURCE_STATE_TRANSITION_MODE) /// \remarks The full extent of the view is always cleared. Viewport and scissor settings are not applied. - /// \note The render target view must be bound to the pipeline for clear operation to be performed. - virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, CLEAR_RENDER_TARGET_STATE_TRANSITION_MODE StateTransitionMode) = 0; + /// \note The render target view must be bound to the pipeline for clear operation to be performed in OpenGL backend. + /// \remarks In D3D12 backend clearing render targets requires textures to always be transitioned to + /// Diligent::RESOURCE_STATE_RENDER_TARGET state. In Vulkan backend however this depends on whether a + /// render pass has been started. To clear render target outside of a render pass, the texture must be transitioned to + /// Diligent::RESOURCE_STATE_COPY_DEST state. Inside a render pass it must be in Diligent::RESOURCE_STATE_RENDER_TARGET + /// state. When using Diligent::RESOURCE_STATE_TRANSITION_TRANSITION mode, the engine takes care of proper + /// resource state transition, otherwise it is the responsibility of the application. + virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) = 0; /// Finishes recording commands and generates a command list @@ -684,13 +723,21 @@ public: /// Copies the data from one buffer to another - /// \param [in] pSrcBuffer - Source buffer to copy data from. - /// \param [in] SrcOffset - Offset in bytes from the beginning of the source buffer to the beginning of data to copy. - /// \param [in] pDstBuffer - Destination buffer to copy data to. - /// \param [in] DstOffset - Offset in bytes from the beginning of the destination buffer to the beginning - /// of the destination region. - /// \param [in] Size - Size in bytes of data to copy. - virtual void CopyBuffer(IBuffer* pSrcBuffer, Uint32 SrcOffset, IBuffer* pDstBuffer, Uint32 DstOffset, Uint32 Size) = 0; + /// \param [in] pSrcBuffer - Source buffer to copy data from. + /// \param [in] SrcOffset - Offset in bytes from the beginning of the source buffer to the beginning of data to copy. + /// \param [in] SrcBufferTransitionMode - State transition mode of the source buffer (see Diligent::RESOURCE_STATE_TRANSITION_MODE). + /// \param [in] pDstBuffer - Destination buffer to copy data to. + /// \param [in] DstOffset - Offset in bytes from the beginning of the destination buffer to the beginning + /// of the destination region. + /// \param [in] Size - Size in bytes of data to copy. + /// \param [in] DstBufferTransitionMode - State transition mode of the destination buffer (see Diligent::RESOURCE_STATE_TRANSITION_MODE) + virtual void CopyBuffer(IBuffer* pSrcBuffer, + Uint32 SrcOffset, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + IBuffer* pDstBuffer, + Uint32 DstOffset, + Uint32 Size, + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) = 0; /// Maps the buffer @@ -730,29 +777,8 @@ public: /// Copies data from one texture to another - /// \param [in] pSrcTexture - Source texture to copy data from - /// \param [in] SrcMipLevel - Mip level of the source texture to copy data from. - /// \param [in] SrcSlice - Array slice of the source texture to copy data from. - /// Should be 0 for non-array textures. - /// \param [in] pSrcBox - Source region to copy. - /// Use nullptr to copy the entire subresource. - /// \param [in] pDstTexture - Destination texture to copy data to - /// \param [in] DstMipLevel - Mip level to copy data to. - /// \param [in] DstSlice - Array slice to copy data to. - /// Must be 0 for non-array textures. - /// \param [in] DstX - X offset on the destination subresource - /// \param [in] DstY - Y offset on the destination subresource - /// \param [in] DstZ - Z offset on the destination subresource - virtual void CopyTexture(ITexture* pSrcTexture, - Uint32 SrcMipLevel, - Uint32 SrcSlice, - const Box *pSrcBox, - ITexture* pDstTexture, - Uint32 DstMipLevel, - Uint32 DstSlice, - Uint32 DstX, - Uint32 DstY, - Uint32 DstZ) = 0; + /// \param [in] CopyAttribs - Structure describing copy command attributes, see Diligent::CopyTextureAttribs for details. + virtual void CopyTexture(const CopyTextureAttribs& CopyAttribs) = 0; /// Maps the texture subresource diff --git a/Graphics/GraphicsEngine/src/Texture.cpp b/Graphics/GraphicsEngine/src/Texture.cpp index 7276d956..90d616a9 100644 --- a/Graphics/GraphicsEngine/src/Texture.cpp +++ b/Graphics/GraphicsEngine/src/Texture.cpp @@ -214,37 +214,39 @@ void ValidateUpdateTextureParams( const TextureDesc& TexDesc, Uint32 MipLevel, U #endif } -void ValidateCopyTextureParams( const TextureDesc &SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, - const TextureDesc &DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice, - Uint32 DstX, Uint32 DstY, Uint32 DstZ ) +void ValidateCopyTextureParams(const CopyTextureAttribs& CopyAttribs ) { + VERIFY_EXPR(CopyAttribs.pSrcTexture != nullptr && CopyAttribs.pDstTexture != nullptr); Box SrcBox; + const auto& SrcTexDesc = CopyAttribs.pSrcTexture->GetDesc(); + const auto& DstTexDesc = CopyAttribs.pDstTexture->GetDesc(); + auto pSrcBox = CopyAttribs.pSrcBox; if( pSrcBox == nullptr ) { - SrcBox.MaxX = std::max( SrcTexDesc.Width >> SrcMipLevel, 1u ); + SrcBox.MaxX = std::max( SrcTexDesc.Width >> CopyAttribs.SrcMipLevel, 1u ); if( SrcTexDesc.Type == RESOURCE_DIM_TEX_1D || SrcTexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) SrcBox.MaxY = 1; else - SrcBox.MaxY = std::max( SrcTexDesc.Height >> SrcMipLevel, 1u ); + SrcBox.MaxY = std::max( SrcTexDesc.Height >> CopyAttribs.SrcMipLevel, 1u ); if( SrcTexDesc.Type == RESOURCE_DIM_TEX_3D ) - SrcBox.MaxZ = std::max( SrcTexDesc.Depth >> SrcMipLevel, 1u ); + SrcBox.MaxZ = std::max( SrcTexDesc.Depth >> CopyAttribs.SrcMipLevel, 1u ); else SrcBox.MaxZ = 1; pSrcBox = &SrcBox; } - ValidateTextureRegion(SrcTexDesc, SrcMipLevel, SrcSlice, *pSrcBox); + ValidateTextureRegion(SrcTexDesc, CopyAttribs.SrcMipLevel, CopyAttribs.SrcSlice, *pSrcBox); Box DstBox; - DstBox.MinX = DstX; + DstBox.MinX = CopyAttribs.DstX; DstBox.MaxX = DstBox.MinX + (pSrcBox->MaxX - pSrcBox->MinX); - DstBox.MinY = DstY; + DstBox.MinY = CopyAttribs.DstY; DstBox.MaxY = DstBox.MinY + (pSrcBox->MaxY - pSrcBox->MinY); - DstBox.MinZ = DstZ; + DstBox.MinZ = CopyAttribs.DstZ; DstBox.MaxZ = DstBox.MinZ + (pSrcBox->MaxZ - pSrcBox->MinZ); - ValidateTextureRegion(DstTexDesc, DstMipLevel, DstSlice, DstBox); + ValidateTextureRegion(DstTexDesc, CopyAttribs.DstMipLevel, CopyAttribs.DstSlice, DstBox); } void ValidateMapTextureParams(const TextureDesc& TexDesc, |
