From e23d0974b92bf870343f3fdee30294254a62505e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 2 Dec 2018 19:47:36 -0800 Subject: Made DeviceContextBase template class little more readable by keeping only two template parameters --- .../GraphicsEngine/include/DeviceContextBase.h | 140 +++++++++++---------- 1 file changed, 71 insertions(+), 69 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 46d02bac..9f760e48 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -55,22 +55,21 @@ struct VertexStreamInfo /// Base implementation of the device context. /// \tparam BaseInterface - base interface that this class will inheret. -/// \tparam BufferImplType - buffer implemenation type (BufferVkImpl, BufferD3D12Impl, etc.) -/// \tparam TextureImplType - texture implemenation type (TextureVkImpl, TextureD3D12Impl, etc.) -/// \tparam PipelineStateImplType - pipeline state implementation type (PipelineStateVkImpl, PipelineStateD3D12Impl, etc.) +/// \tparam ImplementationTraits - implementation traits that define specific implementation details +/// (texture implemenation type, buffer implementation type, etc.) /// \remarks Device context keeps strong references to all objects currently bound to /// the pipeline: buffers, states, samplers, shaders, etc. /// The context also keeps strong references to the device and /// the swap chain. -template +template class DeviceContextBase : public ObjectBase { public: - using TObjectBase = ObjectBase; - using TextureViewImplType = typename TextureImplType::ViewImplType; + using TObjectBase = ObjectBase; + using BufferImplType = typename ImplementationTraits::BufferType; + using TextureImplType = typename ImplementationTraits::TextureType; + using PipelineStateImplType = typename ImplementationTraits::PipelineStateType; + using TextureViewImplType = typename TextureImplType::ViewImplType; /// \param pRefCounters - reference counters object that controls the lifetime of this device context. /// \param pRenderDevice - render device. @@ -275,8 +274,8 @@ protected: }; -template -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags ) { #ifdef DEVELOPMENT @@ -327,14 +326,14 @@ inline void DeviceContextBase{}; } -template -inline void DeviceContextBase :: SetPipelineState(PipelineStateImplType* pPipelineState, int /*Dummy*/) +template +inline void DeviceContextBase :: SetPipelineState(PipelineStateImplType* pPipelineState, int /*Dummy*/) { m_pPipelineState = pPipelineState; } -template -inline bool DeviceContextBase :: +template +inline bool DeviceContextBase :: CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, int) { #ifdef DEVELOPMENT @@ -356,15 +355,15 @@ inline bool DeviceContextBase -inline void DeviceContextBase :: InvalidateState() +template +inline void DeviceContextBase :: InvalidateState() { - DeviceContextBase :: ClearStateCache(); + DeviceContextBase :: ClearStateCache(); m_IsDefaultFramebufferBound = false; } -template -inline void DeviceContextBase :: SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset ) +template +inline void DeviceContextBase :: SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset ) { m_pIndexBuffer = ValidatedCast(pIndexBuffer); m_IndexDataStartOffset = ByteOffset; @@ -378,8 +377,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: GetPipelineState(IPipelineState** ppPSO, float* BlendFactors, Uint32& StencilRef) +template +inline void DeviceContextBase :: GetPipelineState(IPipelineState** ppPSO, float* BlendFactors, Uint32& StencilRef) { VERIFY( ppPSO != nullptr, "Null pointer provided null" ); VERIFY(* ppPSO == nullptr, "Memory address contains a pointer to a non-null blend state" ); @@ -397,8 +396,8 @@ inline void DeviceContextBase -inline bool DeviceContextBase ::SetBlendFactors(const float* BlendFactors, int) +template +inline bool DeviceContextBase :: SetBlendFactors(const float* BlendFactors, int) { bool FactorsDiffer = false; for( Uint32 f = 0; f < 4; ++f ) @@ -410,8 +409,8 @@ inline bool DeviceContextBase -inline bool DeviceContextBase :: SetStencilRef(Uint32 StencilRef, int) +template +inline bool DeviceContextBase :: SetStencilRef(Uint32 StencilRef, int) { if (m_StencilRef != StencilRef) { @@ -421,8 +420,9 @@ inline bool DeviceContextBase -inline void DeviceContextBase :: SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32& RTWidth, Uint32& RTHeight ) +template +inline void DeviceContextBase :: + SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32& RTWidth, Uint32& RTHeight ) { if ( RTWidth == 0 || RTHeight == 0 ) { @@ -449,8 +449,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: GetViewports( Uint32 &NumViewports, Viewport* pViewports ) +template +inline void DeviceContextBase :: GetViewports( Uint32 &NumViewports, Viewport* pViewports ) { NumViewports = m_NumViewports; if ( pViewports ) @@ -460,8 +460,9 @@ inline void DeviceContextBase -inline void DeviceContextBase :: SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32& RTWidth, Uint32& RTHeight ) +template +inline void DeviceContextBase :: + SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32& RTWidth, Uint32& RTHeight ) { if ( RTWidth == 0 || RTHeight == 0 ) { @@ -480,8 +481,8 @@ inline void DeviceContextBase -inline bool DeviceContextBase :: +template +inline bool DeviceContextBase :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil ) { bool bBindRenderTargets = false; @@ -603,8 +604,9 @@ inline bool DeviceContextBase -inline void DeviceContextBase :: GetRenderTargets( Uint32 &NumRenderTargets, ITextureView** ppRTVs, ITextureView** ppDSV ) +template +inline void DeviceContextBase :: + GetRenderTargets( Uint32 &NumRenderTargets, ITextureView** ppRTVs, ITextureView** ppDSV ) { NumRenderTargets = m_NumBoundRenderTargets; @@ -636,8 +638,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: ClearStateCache() +template +inline void DeviceContextBase :: ClearStateCache() { for(Uint32 stream=0; stream < m_NumVertexStreams; ++stream) m_VertexStreams[stream] = VertexStreamInfo{}; @@ -671,8 +673,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: ResetRenderTargets() +template +inline void DeviceContextBase :: ResetRenderTargets() { for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) m_pBoundRenderTargets[rt].Release(); @@ -692,8 +694,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { VERIFY(pBuffer != nullptr, "Buffer must not be null"); @@ -703,8 +705,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: CopyBuffer(IBuffer* pSrcBuffer, Uint32 SrcOffset, RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, @@ -721,8 +723,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData ) { VERIFY(pBuffer, "pBuffer must not be null"); @@ -771,8 +773,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) { VERIFY(pBuffer, "pBuffer must not be null"); @@ -785,8 +787,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: UpdateTexture(ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData, RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, RESOURCE_STATE_TRANSITION_MODE TextureTransitionMode) { @@ -794,8 +796,8 @@ inline void DeviceContextBaseGetDesc(), MipLevel, Slice, DstBox, SubresData ); } -template -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: CopyTexture( const CopyTextureAttribs& CopyAttribs ) { VERIFY( CopyAttribs.pSrcTexture, "Src texture must not be null" ); @@ -803,8 +805,8 @@ inline void DeviceContextBase -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: MapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice, @@ -817,8 +819,8 @@ inline void DeviceContextBaseGetDesc(), MipLevel, ArraySlice, MapType, MapFlags, pMapRegion); } -template -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) { VERIFY(pTexture, "pTexture must not be null"); @@ -826,8 +828,8 @@ inline void DeviceContextBaseGetDesc().ArraySize, "Array slice is out of range"); } -template -inline void DeviceContextBase :: +template +inline void DeviceContextBase :: GenerateMips(ITextureView* pTexView) { VERIFY(pTexView != nullptr, "pTexView must not be null"); @@ -838,8 +840,8 @@ inline void DeviceContextBase -inline bool DeviceContextBase :: +template +inline bool DeviceContextBase :: DvpVerifyDrawArguments(const DrawAttribs& drawAttribs) { if (!m_pPipelineState) @@ -875,8 +877,8 @@ inline bool DeviceContextBase -inline bool DeviceContextBase :: +template +inline bool DeviceContextBase :: DvpVerifyDispatchArguments(const DispatchComputeAttribs& DispatchAttrs) { if (!m_pPipelineState) @@ -906,8 +908,8 @@ inline bool DeviceContextBase -void DeviceContextBase :: +template +void DeviceContextBase :: DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier) { DEV_CHECK_ERR((Barrier.pTexture != nullptr) ^ (Barrier.pBuffer != nullptr), "Exactly one of pTexture or pBuffer members of StateTransitionDesc must not be null"); @@ -952,8 +954,8 @@ void DeviceContextBase -bool DeviceContextBase :: +template +bool DeviceContextBase :: DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName) { if (Texture.IsInKnownState() && !Texture.CheckState(RequiredState)) @@ -967,9 +969,9 @@ bool DeviceContextBase -bool DeviceContextBase :: - DvpVerifyBufferState (const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName) +template +bool DeviceContextBase :: + DvpVerifyBufferState(const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName) { if (Buffer.IsInKnownState() && !Buffer.CheckState(RequiredState)) { -- cgit v1.2.3