From 34cab1f1c50047f2a82cbb2656921c2d88e39ee7 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 29 Nov 2018 22:40:42 -0800 Subject: Improved type safety of different flag types --- .../include/D3D11TypeConversions.h | 38 ++++++++++------------ .../include/DeviceContextD3D11Impl.h | 10 +++--- .../src/DeviceContextD3D11Impl.cpp | 10 +++--- .../GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp | 4 +-- 4 files changed, 29 insertions(+), 33 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h index a8571222..a2800d00 100644 --- a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h +++ b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h @@ -46,17 +46,17 @@ inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags) return D3D11BindFlags; } -inline Uint32 D3D11BindFlagsToBindFlags(UINT D3D11BindFlags) +inline BIND_FLAGS D3D11BindFlagsToBindFlags(UINT D3D11BindFlags) { - Uint32 BindFlags = 0; - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_VERTEX_BUFFER) ? BIND_VERTEX_BUFFER : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_INDEX_BUFFER) ? BIND_INDEX_BUFFER : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_CONSTANT_BUFFER) ? BIND_UNIFORM_BUFFER : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_SHADER_RESOURCE) ? BIND_SHADER_RESOURCE : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_STREAM_OUTPUT) ? BIND_STREAM_OUTPUT : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_RENDER_TARGET) ? BIND_RENDER_TARGET : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_DEPTH_STENCIL) ? BIND_DEPTH_STENCIL : 0); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? BIND_UNORDERED_ACCESS : 0); + BIND_FLAGS BindFlags = BIND_NONE; + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_VERTEX_BUFFER) ? BIND_VERTEX_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_INDEX_BUFFER) ? BIND_INDEX_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_CONSTANT_BUFFER) ? BIND_UNIFORM_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_SHADER_RESOURCE) ? BIND_SHADER_RESOURCE : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_STREAM_OUTPUT) ? BIND_STREAM_OUTPUT : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_RENDER_TARGET) ? BIND_RENDER_TARGET : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_DEPTH_STENCIL) ? BIND_DEPTH_STENCIL : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? BIND_UNORDERED_ACCESS : BIND_NONE); VERIFY_EXPR( (D3D11BindFlags & (D3D11_BIND_VERTEX_BUFFER|D3D11_BIND_INDEX_BUFFER|D3D11_BIND_CONSTANT_BUFFER| D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_STREAM_OUTPUT|D3D11_BIND_RENDER_TARGET| @@ -120,10 +120,6 @@ inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_M d3d11MapFlags |= (MapFlags & MAP_FLAG_DO_NOT_WAIT) ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0; } -inline UINT MapFlagsToD3D11MapFlags(Uint32 MapFlags) -{ -} - inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) { UINT D3D11CPUAccessFlags = 0; @@ -132,11 +128,11 @@ inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) return D3D11CPUAccessFlags; } -inline Uint8 D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags) +inline CPU_ACCESS_FLAGS D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags) { - Uint8 CPUAccessFlags = 0; - CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : 0; - CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) ? CPU_ACCESS_WRITE : 0; + CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; + CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : CPU_ACCESS_NONE; + CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) ? CPU_ACCESS_WRITE : CPU_ACCESS_NONE; VERIFY_EXPR(D3D11CPUAccessFlags == CPUAccessFlagsToD3D11CPUAccessFlags(CPUAccessFlags)); return CPUAccessFlags; } @@ -148,10 +144,10 @@ inline UINT MiscTextureFlagsToD3D11Flags(Uint32 Flags) return D3D11MiscFlags; } -inline Uint32 D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags) +inline MISC_TEXTURE_FLAGS D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags) { - Uint32 MiscFlags = 0; - MiscFlags |= (D3D11MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) ? MISC_TEXTURE_FLAG_GENERATE_MIPS : 0; + MISC_TEXTURE_FLAGS MiscFlags = MISC_TEXTURE_FLAG_NONE; + MiscFlags |= (D3D11MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) ? MISC_TEXTURE_FLAG_GENERATE_MIPS : MISC_TEXTURE_FLAG_NONE; return MiscFlags; } diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index a21630a8..08bdd7a0 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -58,13 +58,13 @@ public: virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding)override final; - virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags)override final; + virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags)override final; virtual void SetStencilRef(Uint32 StencilRef)override final; virtual void SetBlendFactors(const float* pBlendFactors = nullptr)override final; - virtual void SetVertexBuffers(Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, Uint32 Flags)override final; + virtual void SetVertexBuffers(Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags)override final; virtual void InvalidateState()override final; @@ -80,7 +80,7 @@ public: virtual void DispatchCompute(const DispatchComputeAttribs& DispatchAttrs)override final; - virtual void ClearDepthStencil(ITextureView* pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil)override final; + virtual void ClearDepthStencil(ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final; virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA)override final; @@ -90,7 +90,7 @@ public: virtual void CopyBuffer(IBuffer *pSrcBuffer, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size)override final; - virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData)override final; + virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override final; virtual void UnmapBuffer(IBuffer* pBuffer)override final; @@ -111,7 +111,7 @@ public: Uint32 MipLevel, Uint32 ArraySlice, MAP_TYPE MapType, - Uint32 MapFlags, + MAP_FLAGS MapFlags, const Box* pMapRegion, MappedTextureSubresource& MappedData )override final; diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 2d6d14d1..c07912e3 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -617,7 +617,7 @@ namespace Diligent TransitionAndCommitShaderResources(pPipelineState, pShaderResourceBinding, false); } - void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags) + void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags) { if (!DeviceContextBase::CommitShaderResources(pShaderResourceBinding, Flags, 0 /*Dummy*/)) return; @@ -872,7 +872,7 @@ namespace Diligent m_pd3d11DeviceContext->Dispatch( DispatchAttrs.ThreadGroupCountX, DispatchAttrs.ThreadGroupCountY, DispatchAttrs.ThreadGroupCountZ ); } - void DeviceContextD3D11Impl::ClearDepthStencil( ITextureView* pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil ) + void DeviceContextD3D11Impl::ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil ) { if (pView == nullptr) { @@ -973,7 +973,7 @@ namespace Diligent } - void DeviceContextD3D11Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData) + void DeviceContextD3D11Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) { TDeviceContextBase::MapBuffer(pBuffer, MapType, MapFlags, pMappedData); @@ -1076,7 +1076,7 @@ namespace Diligent Uint32 MipLevel, Uint32 ArraySlice, MAP_TYPE MapType, - Uint32 MapFlags, + MAP_FLAGS MapFlags, const Box* pMapRegion, MappedTextureSubresource& MappedData ) { @@ -1126,7 +1126,7 @@ namespace Diligent { } - void DeviceContextD3D11Impl::SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32* pOffsets, Uint32 Flags ) + void DeviceContextD3D11Impl::SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags ) { TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pOffsets, Flags ); m_bCommittedD3D11VBsUpToDate = false; diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp index e37584ad..cb25af84 100644 --- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp @@ -86,8 +86,8 @@ void SwapChainD3D11Impl::CreateRTVandDSV() DepthBufferDesc.SampleCount = m_SwapChainDesc.SamplesCount; DepthBufferDesc.Usage = USAGE_DEFAULT; DepthBufferDesc.BindFlags = BIND_DEPTH_STENCIL; - DepthBufferDesc.CPUAccessFlags = 0; - DepthBufferDesc.MiscFlags = 0; + DepthBufferDesc.CPUAccessFlags = CPU_ACCESS_NONE; + DepthBufferDesc.MiscFlags = MISC_TEXTURE_FLAG_NONE; RefCntAutoPtr ptex2DDepthBuffer; m_pRenderDevice->CreateTexture(DepthBufferDesc, TextureData{}, &ptex2DDepthBuffer); auto pDSV = ptex2DDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); -- cgit v1.2.3