diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-11-30 06:40:42 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-11-30 06:40:42 +0000 |
| commit | 34cab1f1c50047f2a82cbb2656921c2d88e39ee7 (patch) | |
| tree | 9c520570008618d81bc4cba9a3aa5dd9455ba714 /Graphics/GraphicsEngine | |
| parent | Improved const-correctness; updated comments; added DRAW_FLAG_VERIFY_STATES a... (diff) | |
| download | DiligentCore-34cab1f1c50047f2a82cbb2656921c2d88e39ee7.tar.gz DiligentCore-34cab1f1c50047f2a82cbb2656921c2d88e39ee7.zip | |
Improved type safety of different flag types
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 18 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/Buffer.h | 6 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/DeviceContext.h | 56 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/GraphicsTypes.h | 18 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/MapHelper.h | 4 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/Texture.h | 10 |
6 files changed, 68 insertions, 44 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index ad012626..293e438c 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -89,12 +89,12 @@ public: /// Base implementation of IDeviceContext::SetVertexBuffers(); validates parameters and /// caches references to the buffers. - inline virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, Uint32 Flags )override = 0; + inline virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags )override = 0; inline virtual void InvalidateState()override = 0; /// Base implementation of IDeviceContext::CommitShaderResources(); validates parameters. - inline bool CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags, int); + inline bool CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags, int); /// Base implementation of IDeviceContext::SetIndexBuffer(); caches the strong reference to the index buffer inline virtual void SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset )override = 0; @@ -116,7 +116,7 @@ public: virtual void CopyBuffer(IBuffer *pSrcBuffer, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size)override = 0; /// Base implementation of IDeviceContext::MapBuffer(); validates input parameters. - virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData)override = 0; + virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override = 0; /// Base implementation of IDeviceContext::UnmapBuffer() virtual void UnmapBuffer(IBuffer* pBuffer)override = 0; @@ -141,7 +141,7 @@ public: Uint32 MipLevel, Uint32 ArraySlice, MAP_TYPE MapType, - Uint32 MapFlags, + MAP_FLAGS MapFlags, const Box* pMapRegion, MappedTextureSubresource& MappedData)override = 0; @@ -257,7 +257,8 @@ protected: template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> -inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, Uint32 Flags ) +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: + SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags ) { #ifdef DEVELOPMENT if ( StartSlot >= MaxBufferSlots ) @@ -314,7 +315,8 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType } template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> -inline bool DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags, int) +inline bool DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: + CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags, int) { #ifdef DEVELOPMENT if (!m_pPipelineState) @@ -695,7 +697,7 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: - MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) + MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData ) { VERIFY(pBuffer, "pBuffer must not be null"); @@ -779,7 +781,7 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType Uint32 MipLevel, Uint32 ArraySlice, MAP_TYPE MapType, - Uint32 MapFlags, + MAP_FLAGS MapFlags, const Box* pMapRegion, MappedTextureSubresource& MappedData) { diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index d8ba656d..b192d18a 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -75,14 +75,14 @@ struct BufferDesc : DeviceObjectAttribs /// Diligent::BIND_VERTEX_BUFFER, Diligent::BIND_INDEX_BUFFER, Diligent::BIND_UNIFORM_BUFFER, /// Diligent::BIND_SHADER_RESOURCE, Diligent::BIND_STREAM_OUTPUT, Diligent::BIND_UNORDERED_ACCESS, /// Diligent::BIND_INDIRECT_DRAW_ARGS - Uint32 BindFlags = 0; + BIND_FLAGS BindFlags = BIND_NONE; /// Buffer usage, see Diligent::USAGE for details USAGE Usage = USAGE_DEFAULT; /// CPU access flags or 0 if no CPU access is allowed, - /// see Diligent::CPU_ACCESS_FLAG for details. - Uint8 CPUAccessFlags = 0; + /// see Diligent::CPU_ACCESS_FLAGS for details. + CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; /// Buffer mode, see Diligent::BUFFER_MODE BUFFER_MODE Mode = BUFFER_MODE_UNDEFINED; diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 60898af7..70088d2a 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -27,6 +27,7 @@ /// Definition of the Diligent::IDeviceContext interface and related data structures #include "../../../Primitives/interface/Object.h" +#include "../../../Primitives/interface/FlagEnum.h" #include "DeviceCaps.h" #include "Constants.h" #include "Buffer.h" @@ -57,15 +58,15 @@ enum DRAW_FLAGS : Uint8 /// Perform no state transitions DRAW_FLAG_NONE = 0x00, - /// Transition vertex buffers to RESOURCE_STATE_VERTEX_BUFFER state (see Diligent::RESOURCE_STATE). + /// Transition vertex buffers to Diligent::RESOURCE_STATE_VERTEX_BUFFER state (see Diligent::RESOURCE_STATE). /// Vertex buffers in unknown state will not be transitioned. DRAW_FLAG_TRANSITION_VERTEX_BUFFERS = 0x01, - /// Transition index buffer to RESOURCE_STATE_INDEX_BUFFER state (see Diligent::RESOURCE_STATE). + /// Transition index buffer to Diligent::RESOURCE_STATE_INDEX_BUFFER state (see Diligent::RESOURCE_STATE). /// If the index buffer is in unknown state, this flag has no effect. DRAW_FLAG_TRANSITION_INDEX_BUFFER = 0x02, - /// Transition indirect draw arguments buffer to RESOURCE_STATE_INDIRECT_ARGUMENT state (see Diligent::RESOURCE_STATE). + /// Transition indirect draw arguments buffer to Diligent::RESOURCE_STATE_INDIRECT_ARGUMENT state (see Diligent::RESOURCE_STATE). /// If the buffer is in unknown state, this flag has no effect. DRAW_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER = 0x04, @@ -78,6 +79,7 @@ enum DRAW_FLAGS : Uint8 /// application explicitly manages the states. DRAW_FLAG_VERIFY_STATES = 0x08 }; +DEFINE_FLAG_ENUM_OPERATORS(DRAW_FLAGS) /// Defines the draw command attributes @@ -101,7 +103,7 @@ struct DrawAttribs VALUE_TYPE IndexType = VT_UNDEFINED; /// Additional flags controlling the draw command behavior, see Diligent::DRAW_FLAGS. - Uint8 Flags = DRAW_FLAG_NONE; + DRAW_FLAGS Flags = DRAW_FLAG_NONE; /// Number of instances to draw. If more than one instance is specified, /// instanced draw call will be performed. @@ -155,12 +157,13 @@ struct DrawAttribs /// Defines which parts of the depth-stencil buffer to clear. /// These flags are used by IDeviceContext::ClearDepthStencil(). -enum CLEAR_DEPTH_STENCIL_FLAGS : Int32 +enum CLEAR_DEPTH_STENCIL_FLAGS : Uint32 { - CLEAR_DEPTH_FLAG = 0x01, ///< Clear depth part of the buffer - CLEAR_STENCIL_FLAG = 0x02 ///< Clear stencil part of the buffer + CLEAR_DEPTH_FLAG_NONE = 0x00, ///< Perform no clear + CLEAR_DEPTH_FLAG = 0x01, ///< Clear depth part of the buffer + CLEAR_STENCIL_FLAG = 0x02 ///< Clear stencil part of the buffer }; - +DEFINE_FLAG_ENUM_OPERATORS(CLEAR_DEPTH_STENCIL_FLAGS) /// Dispatch compute command flags enum DISPATCH_FLAGS : Uint8 @@ -177,6 +180,7 @@ enum DISPATCH_FLAGS : Uint8 /// flag has no effect in release build. DISPATCH_FLAG_VERIFY_STATES = 0x02 }; +DEFINE_FLAG_ENUM_OPERATORS(DISPATCH_FLAGS) /// Describes dispatch command arguments. @@ -199,7 +203,7 @@ struct DispatchComputeAttribs Uint32 DispatchArgsByteOffset; /// Flags controlling the dispatch command behavior, see Diligent::DISPATCH_FLAGS. - Uint8 Flags = DISPATCH_FLAG_FLAG_NONE; + DISPATCH_FLAGS Flags = DISPATCH_FLAG_FLAG_NONE; /// Initializes the structure to perform non-indirect dispatch command @@ -231,16 +235,23 @@ struct DispatchComputeAttribs }; /// Defines allowed flags for IDeviceContext::SetVertexBuffers() function. -enum SET_VERTEX_BUFFERS_FLAGS : Int32 +enum SET_VERTEX_BUFFERS_FLAGS : Uint8 { + /// No extra operations + SET_VERTEX_BUFFERS_FLAG_NONE = 0x00, + /// Reset the vertex buffers to only the buffers specified in this /// call. All buffers previously bound to the pipeline will be unbound. SET_VERTEX_BUFFERS_FLAG_RESET = 0x01 }; +DEFINE_FLAG_ENUM_OPERATORS(SET_VERTEX_BUFFERS_FLAGS) /// Defines allowed flags for IDeviceContext::CommitShaderResources() function. -enum COMMIT_SHADER_RESOURCES_FLAG +enum COMMIT_SHADER_RESOURCES_FLAGS : Uint8 { + /// Perform no extra operations + COMMIT_SHADER_RESOURCES_FLAG_NONE = 0x00, + /// Transition resources being committed /// If this flag is specified when IDeviceContext::CommitShaderResources() is called, @@ -254,8 +265,9 @@ enum COMMIT_SHADER_RESOURCES_FLAG /// that all resources are transitioned to correct states when /// COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES flag is not set. /// No resource state validation is performed in release build. - COMMIT_SHADER_RESOURCES_FLAG_VERIFY_STATES = 0x02 + COMMIT_SHADER_RESOURCES_FLAG_VERIFY_STATES = 0x02 }; +DEFINE_FLAG_ENUM_OPERATORS(COMMIT_SHADER_RESOURCES_FLAGS) /// Describes the viewport. @@ -363,7 +375,7 @@ public: /// \param [in] pShaderResourceBinding - Shader resource binding whose resources will be committed. /// If pipeline state contains no shader resources, this parameter /// can be null. - /// \param [in] Flags - Additional flags for the operation. See Diligent::COMMIT_SHADER_RESOURCES_FLAG + /// \param [in] Flags - Additional flags for the operation. See Diligent::COMMIT_SHADER_RESOURCES_FLAGS /// for a list of allowed values. /// /// \remarks Pipeline state object that was used to create the shader resource binding must be bound @@ -399,7 +411,7 @@ public: /// manually by setting the state to Diligent::RESOURCE_STATE_UNKNOWN (which will disable automatic state /// management) using IBuffer::SetState() or ITexture::SetState() and explicitly transitioning the states with /// IDeviceContext::TransitionResourceStates(). See IDeviceContext::TransitionResourceStates() for details. - virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags) = 0; + virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags) = 0; /// Sets the stencil reference value @@ -435,11 +447,11 @@ public: /// It is suggested to specify Diligent::SET_VERTEX_BUFFERS_FLAG_RESET flag /// whenever possible. This will assure that no buffers from previous draw calls are /// are bound to the pipeline. - virtual void SetVertexBuffers(Uint32 StartSlot, - Uint32 NumBuffersSet, - IBuffer** ppBuffers, - Uint32* pOffsets, - Uint32 Flags) = 0; + virtual void SetVertexBuffers(Uint32 StartSlot, + Uint32 NumBuffersSet, + IBuffer** ppBuffers, + Uint32* pOffsets, + SET_VERTEX_BUFFERS_FLAGS Flags) = 0; /// Invalidates the cached context state. @@ -551,7 +563,7 @@ public: /// \param [in] Stencil - Value to clear stencil part of the view with. /// \remarks The full extent of the view is always cleared. Viewport and scissor settings are not applied. /// \note The depth-stencil view must be bound to the pipeline for clear operation to be performed. - virtual void ClearDepthStencil(ITextureView* pView, Uint32 ClearFlags = CLEAR_DEPTH_FLAG, float fDepth = 1.f, Uint8 Stencil = 0) = 0; + virtual void ClearDepthStencil(ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags = CLEAR_DEPTH_FLAG, float fDepth = 1.f, Uint8 Stencil = 0) = 0; /// Clears a render target view @@ -614,7 +626,7 @@ public: /// \param [in] MapType - Type of the map operation. See Diligent::MAP_TYPE. /// \param [in] MapFlags - Special map flags. See Diligent::MAP_FLAGS. /// \param [out] pMappedData - Reference to the void pointer to store the address of the mapped region. - virtual void MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; + virtual void MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid &pMappedData ) = 0; /// Unmaps the previously mapped buffer @@ -680,7 +692,7 @@ public: Uint32 MipLevel, Uint32 ArraySlice, MAP_TYPE MapType, - Uint32 MapFlags, + MAP_FLAGS MapFlags, const Box* pMapRegion, MappedTextureSubresource& MappedData ) = 0; diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index b542bde9..b9344120 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -28,6 +28,7 @@ #include "../../../Primitives/interface/BasicTypes.h" #include "../../../Primitives/interface/DebugOutput.h" +#include "../../../Primitives/interface/FlagEnum.h" /// Graphics engine namespace namespace Diligent @@ -77,6 +78,7 @@ namespace Diligent BIND_UNORDERED_ACCESS = 0x80L,///< A buffer or a texture can be bound as an unordered access view BIND_INDIRECT_DRAW_ARGS = 0x100L///< A buffer can be bound as the source buffer for indirect draw commands }; + DEFINE_FLAG_ENUM_OPERATORS(BIND_FLAGS) /// Resource usage @@ -113,11 +115,13 @@ namespace Diligent /// - BufferDesc to describe CPU access mode for a buffer /// - TextureDesc to describe CPU access mode for a texture /// \note Only USAGE_DYNAMIC resources can be mapped - enum CPU_ACCESS_FLAG : Uint8 + enum CPU_ACCESS_FLAGS : Uint8 { - CPU_ACCESS_READ = 0x01, ///< A resource can be mapped for reading - CPU_ACCESS_WRITE = 0x02 ///< A resource can be mapped for writing + CPU_ACCESS_NONE = 0x00, ///< No CPU access + CPU_ACCESS_READ = 0x01, ///< A resource can be mapped for reading + CPU_ACCESS_WRITE = 0x02 ///< A resource can be mapped for writing }; + DEFINE_FLAG_ENUM_OPERATORS(CPU_ACCESS_FLAGS) /// Resource mapping type @@ -149,6 +153,8 @@ namespace Diligent /// - ITexture::Map to describe texture mapping flags enum MAP_FLAGS : Uint8 { + MAP_FLAG_NONE = 0x000, + /// Specifies that map operation should not wait until previous command that /// using the same resource completes. Map returns null pointer if the resource /// is still in use.\n @@ -167,6 +173,7 @@ namespace Diligent /// D3D11 counterpart: D3D11_MAP_WRITE_NO_OVERWRITE. OpenGL counterpart: GL_MAP_UNSYNCHRONIZED_BIT MAP_FLAG_DO_NOT_SYNCHRONIZE = 0x004 }; + DEFINE_FLAG_ENUM_OPERATORS(MAP_FLAGS) /// Describes resource dimension @@ -892,13 +899,16 @@ namespace Diligent /// Miscellaneous texture flags /// The enumeration is used by TextureDesc to describe misc texture flags - enum MISC_TEXTURE_FLAG : Uint8 + enum MISC_TEXTURE_FLAGS : Uint8 { + MISC_TEXTURE_FLAG_NONE = 0x00, + /// Allow automatic mipmap generation with ITextureView::GenerateMips() /// \note A texture must be created with BIND_RENDER_TARGET bind flag MISC_TEXTURE_FLAG_GENERATE_MIPS = 0x01 }; + DEFINE_FLAG_ENUM_OPERATORS(MISC_TEXTURE_FLAGS) /// Input primitive topology. diff --git a/Graphics/GraphicsEngine/interface/MapHelper.h b/Graphics/GraphicsEngine/interface/MapHelper.h index aae341c5..71264c3b 100644 --- a/Graphics/GraphicsEngine/interface/MapHelper.h +++ b/Graphics/GraphicsEngine/interface/MapHelper.h @@ -63,7 +63,7 @@ public: /// Initializes the object and maps the provided resource. /// See Map() for details. - MapHelper( IDeviceContext *pContext, IBuffer *pBuffer, MAP_TYPE MapType, Uint32 MapFlags ) : + MapHelper( IDeviceContext *pContext, IBuffer *pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags ) : MapHelper() { Map(pContext, pBuffer, MapType, MapFlags); @@ -106,7 +106,7 @@ public: /// \param pBuffer - Pointer to the buffer interface to map. /// \param MapType - Type of the map operation, see Diligent::MAP_TYPE for details. /// \param MapFlags - Additional map flags, see Diligent::MAP_FLAGS. - void Map( IDeviceContext *pContext, IBuffer *pBuffer, MAP_TYPE MapType, Uint32 MapFlags ) + void Map( IDeviceContext *pContext, IBuffer *pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags ) { VERIFY(!m_pBuffer && !m_pMappedData && !m_pContext, "Object already mapped"); Unmap(); diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h index b8c84409..aad67467 100644 --- a/Graphics/GraphicsEngine/interface/Texture.h +++ b/Graphics/GraphicsEngine/interface/Texture.h @@ -119,14 +119,14 @@ struct TextureDesc : DeviceObjectAttribs /// Diligent::BIND_SHADER_RESOURCE, Diligent::BIND_RENDER_TARGET, Diligent::BIND_DEPTH_STENCIL, /// Diligent::and BIND_UNORDERED_ACCESS. \n /// Multisampled textures cannot have Diligent::BIND_UNORDERED_ACCESS flag set - Uint32 BindFlags = 0; + BIND_FLAGS BindFlags = BIND_NONE; /// CPU access flags or 0 if no CPU access is allowed, - /// see Diligent::CPU_ACCESS_FLAG for details. - Uint32 CPUAccessFlags = 0; + /// see Diligent::CPU_ACCESS_FLAGS for details. + CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; - /// Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAG for details. - Uint32 MiscFlags = 0; + /// Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAGS for details. + MISC_TEXTURE_FLAGS MiscFlags = MISC_TEXTURE_FLAG_NONE; /// Optimized clear value OptimizedClearValue ClearValue; |
