From 56d729dbc03cf2033e764196891cbf40223389ec Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 23 Nov 2019 15:46:06 -0800 Subject: clang-formatted GraphicsEngineD3D11 project --- .../GraphicsEngineD3D11/include/BufferD3D11Impl.h | 22 +- .../include/BufferViewD3D11Impl.h | 20 +- .../include/CommandListD3D11Impl.h | 6 +- .../include/D3D11TypeConversions.h | 78 +- .../include/D3D11TypeDefinitions.h | 196 +- .../include/DeviceContextD3D11Impl.h | 163 +- .../include/EngineD3D11Defines.h | 2 +- .../GraphicsEngineD3D11/include/FenceD3D11Impl.h | 20 +- .../include/PipelineStateD3D11Impl.h | 55 +- .../include/RenderDeviceD3D11Impl.h | 51 +- .../GraphicsEngineD3D11/include/SamplerD3D11Impl.h | 4 +- .../GraphicsEngineD3D11/include/ShaderD3D11Impl.h | 22 +- .../include/ShaderResourceBindingD3D11Impl.h | 35 +- .../include/ShaderResourceCacheD3D11.h | 161 +- .../include/ShaderResourceLayoutD3D11.h | 212 +- .../include/ShaderResourcesD3D11.h | 36 +- .../include/SwapChainD3D11Impl.h | 20 +- .../GraphicsEngineD3D11/include/Texture1D_D3D11.h | 26 +- .../GraphicsEngineD3D11/include/Texture2D_D3D11.h | 26 +- .../GraphicsEngineD3D11/include/Texture3D_D3D11.h | 24 +- .../GraphicsEngineD3D11/include/TextureBaseD3D11.h | 34 +- .../include/TextureViewD3D11Impl.h | 20 +- Graphics/GraphicsEngineD3D11/include/pch.h | 26 +- .../GraphicsEngineD3D11/interface/BufferD3D11.h | 5 +- .../interface/BufferViewD3D11.h | 5 +- .../interface/DeviceContextD3D11.h | 5 +- .../interface/EngineFactoryD3D11.h | 148 +- .../GraphicsEngineD3D11/interface/FenceD3D11.h | 6 +- .../interface/PipelineStateD3D11.h | 13 +- .../interface/RenderDeviceD3D11.h | 28 +- .../GraphicsEngineD3D11/interface/SamplerD3D11.h | 7 +- .../GraphicsEngineD3D11/interface/ShaderD3D11.h | 5 +- .../interface/ShaderResourceBindingD3D11.h | 6 +- .../GraphicsEngineD3D11/interface/SwapChainD3D11.h | 4 +- .../GraphicsEngineD3D11/interface/TextureD3D11.h | 5 +- .../interface/TextureViewD3D11.h | 5 +- .../GraphicsEngineD3D11/src/BufferD3D11Impl.cpp | 151 +- .../src/BufferViewD3D11Impl.cpp | 18 +- .../src/CommandListD3D11Impl.cpp | 10 +- .../src/D3D11TypeConversions.cpp | 48 +- .../src/DeviceContextD3D11Impl.cpp | 3455 ++++++++++---------- .../GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp | 196 +- .../GraphicsEngineD3D11/src/FenceD3D11Impl.cpp | 24 +- .../src/PipelineStateD3D11Impl.cpp | 130 +- .../src/RenderDeviceD3D11Impl.cpp | 281 +- .../GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp | 44 +- .../GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp | 86 +- .../src/ShaderResourceBindingD3D11Impl.cpp | 78 +- .../src/ShaderResourceCacheD3D11.cpp | 425 +-- .../src/ShaderResourceLayoutD3D11.cpp | 343 +- .../src/ShaderResourcesD3D11.cpp | 223 +- .../GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp | 56 +- .../GraphicsEngineD3D11/src/Texture1D_D3D11.cpp | 136 +- .../GraphicsEngineD3D11/src/Texture2D_D3D11.cpp | 138 +- .../GraphicsEngineD3D11/src/Texture3D_D3D11.cpp | 121 +- .../GraphicsEngineD3D11/src/TextureBaseD3D11.cpp | 99 +- .../src/TextureViewD3D11Impl.cpp | 18 +- 57 files changed, 3897 insertions(+), 3684 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h index 80072c6e..668c1943 100644 --- a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h @@ -45,26 +45,26 @@ public: BufferD3D11Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const BufferDesc& BuffDesc, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const BufferDesc& BuffDesc, const BufferData* pBuffData = nullptr); BufferD3D11Impl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const BufferDesc& BuffDesc, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, ID3D11Buffer* pd3d11Buffer); ~BufferD3D11Impl(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of IBufferD3D11::GetD3D11Buffer(). - virtual ID3D11Buffer* GetD3D11Buffer()override final{ return m_pd3d11Buffer; } + virtual ID3D11Buffer* GetD3D11Buffer() override final { return m_pd3d11Buffer; } /// Implementation of IBuffer::GetNativeHandle(). - virtual void* GetNativeHandle()override final { return GetD3D11Buffer(); } + virtual void* GetNativeHandle() override final { return GetD3D11Buffer(); } void AddState(RESOURCE_STATE State) { @@ -81,13 +81,13 @@ public: } private: - virtual void CreateViewInternal( const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView )override; + virtual void CreateViewInternal(const struct BufferViewDesc& ViewDesc, IBufferView** ppView, bool bIsDefaultView) override; - void CreateUAV( struct BufferViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ); - void CreateSRV( struct BufferViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV ); + void CreateUAV(struct BufferViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV); + void CreateSRV(struct BufferViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV); friend class DeviceContextD3D11Impl; CComPtr m_pd3d11Buffer; ///< D3D11 buffer object }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h index a6b4bebe..b37c0ec3 100644 --- a/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h @@ -42,23 +42,23 @@ class BufferViewD3D11Impl final : public BufferViewBase; - BufferViewD3D11Impl( IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - const BufferViewDesc& ViewDesc, - class IBuffer* pBuffer, - ID3D11View* pD3D11View, - bool bIsDefaultView); + BufferViewD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + const BufferViewDesc& ViewDesc, + class IBuffer* pBuffer, + ID3D11View* pD3D11View, + bool bIsDefaultView); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject **ppInterface) final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) final; /// Implementation of IBufferViewD3D11::GetD3D11View(). - virtual ID3D11View* GetD3D11View()override final + virtual ID3D11View* GetD3D11View() override final { return m_pD3D11View; } - + protected: CComPtr m_pD3D11View; ///; CommandListD3D11Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, + RenderDeviceD3D11Impl* pDevice, ID3D11CommandList* pd3d11CommandList); ~CommandListD3D11Impl(); - ID3D11CommandList* GetD3D11CommandList(){ return m_pd3d11CommandList; } + ID3D11CommandList* GetD3D11CommandList() { return m_pd3d11CommandList; } private: CComPtr m_pd3d11CommandList; ///< D3D11 CommandList object }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h index d87daf93..388292bc 100644 --- a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h +++ b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h @@ -34,6 +34,7 @@ namespace Diligent inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags) { + // clang-format off UINT D3D11BindFlags = 0; D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_VERTEX_BUFFER) ? D3D11_BIND_VERTEX_BUFFER : 0); D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_INDEX_BUFFER) ? D3D11_BIND_INDEX_BUFFER : 0); @@ -43,12 +44,14 @@ inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags) D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_RENDER_TARGET) ? D3D11_BIND_RENDER_TARGET : 0); D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_DEPTH_STENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0); D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNORDERED_ACCESS) ? D3D11_BIND_UNORDERED_ACCESS : 0); + // clang-format on return D3D11BindFlags; } inline BIND_FLAGS D3D11BindFlagsToBindFlags(UINT D3D11BindFlags) { BIND_FLAGS BindFlags = BIND_NONE; + // clang-format off 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); @@ -61,6 +64,7 @@ inline BIND_FLAGS D3D11BindFlagsToBindFlags(UINT 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| D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_UNORDERED_ACCESS)) == BindFlagsToD3D11BindFlags(BindFlags)); + // clang-format on return BindFlags; } @@ -68,52 +72,56 @@ D3D11_PRIMITIVE_TOPOLOGY TopologyToD3D11Topology(PRIMITIVE_TOPOLOGY Topology); inline D3D11_USAGE UsageToD3D11Usage(USAGE Usage) { - switch(Usage) + switch (Usage) { + // clang-format off case USAGE_STATIC: return D3D11_USAGE_IMMUTABLE; case USAGE_DEFAULT: return D3D11_USAGE_DEFAULT; case USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC; case USAGE_STAGING: return D3D11_USAGE_STAGING; - default: UNEXPECTED("Unknow usage" ); return D3D11_USAGE_DEFAULT; + // clang-format on + default: UNEXPECTED("Unknow usage"); return D3D11_USAGE_DEFAULT; } } inline USAGE D3D11UsageToUsage(D3D11_USAGE D3D11Usage) { - switch(D3D11Usage) + switch (D3D11Usage) { + // clang-format off case D3D11_USAGE_IMMUTABLE: return USAGE_STATIC; case D3D11_USAGE_DEFAULT: return USAGE_DEFAULT; case D3D11_USAGE_DYNAMIC: return USAGE_DYNAMIC; case D3D11_USAGE_STAGING: return USAGE_STAGING; - default: UNEXPECTED("Unknow D3D11 usage" ); return USAGE_DEFAULT; + // clang-format on + default: UNEXPECTED("Unknow D3D11 usage"); return USAGE_DEFAULT; } } inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_MAP& d3d11MapType, UINT& d3d11MapFlags) -{ +{ d3d11MapType = static_cast(0); - switch(MapType) + switch (MapType) { - case MAP_READ: + case MAP_READ: d3d11MapType = D3D11_MAP_READ; - break; + break; - case MAP_WRITE: - if(MapFlags & MAP_FLAG_DISCARD) + case MAP_WRITE: + if (MapFlags & MAP_FLAG_DISCARD) d3d11MapType = D3D11_MAP_WRITE_DISCARD; - else if(MapFlags & MAP_FLAG_DO_NOT_SYNCHRONIZE) + else if (MapFlags & MAP_FLAG_DO_NOT_SYNCHRONIZE) d3d11MapType = D3D11_MAP_WRITE_NO_OVERWRITE; - else + else d3d11MapType = D3D11_MAP_WRITE; - break; + break; - case MAP_READ_WRITE: + case MAP_READ_WRITE: d3d11MapType = D3D11_MAP_READ_WRITE; - break; + break; - default: - UNEXPECTED( "Unknown map type" ); + default: + UNEXPECTED("Unknown map type"); } d3d11MapFlags = 0; @@ -123,7 +131,7 @@ inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_M inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) { UINT D3D11CPUAccessFlags = 0; - D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0; + D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0; D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_WRITE) ? D3D11_CPU_ACCESS_WRITE : 0; return D3D11CPUAccessFlags; } @@ -131,7 +139,7 @@ inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) inline CPU_ACCESS_FLAGS D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags) { CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; - CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : 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; @@ -152,21 +160,29 @@ inline MISC_TEXTURE_FLAGS D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags) } D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter); + D3D11_TEXTURE_ADDRESS_MODE TexAddressModeToD3D11AddressMode(TEXTURE_ADDRESS_MODE Mode); D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Func); -void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc &DepthStencilDesc, D3D11_DEPTH_STENCIL_DESC &d3d11DSSDesc); -void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc &RasterizerDesc, D3D11_RASTERIZER_DESC &d3d11RSDesc); -void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc &BSDesc, D3D11_BLEND_DESC &D3D11BSDesc); -void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, - std::vector >& D3D11InputElements); -void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC &D3D11SRVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC &D3D11RTVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC &D3D11DSVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC &D3D11UAVDesc); +void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, + D3D11_DEPTH_STENCIL_DESC& d3d11DSSDesc); -void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC &D3D11SRVDesc); -void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC &D3D11UAVDesc); +void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, + D3D11_RASTERIZER_DESC& d3d11RSDesc); -} +void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, + D3D11_BLEND_DESC& D3D11BSDesc); + +void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, + std::vector>& D3D11InputElements); + +void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC& D3D11RTVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC& D3D11DSVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); + +void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc); +void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeDefinitions.h b/Graphics/GraphicsEngineD3D11/include/D3D11TypeDefinitions.h index 61dbb2bb..585e5e77 100644 --- a/Graphics/GraphicsEngineD3D11/include/D3D11TypeDefinitions.h +++ b/Graphics/GraphicsEngineD3D11/include/D3D11TypeDefinitions.h @@ -27,57 +27,57 @@ /// Definitions of D3D11 types // Filters -#define D3D_FILTER_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR -#define D3D_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT -#define D3D_FILTER_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR -#define D3D_FILTER_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT -#define D3D_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR -#define D3D_FILTER_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT -#define D3D_FILTER_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_LINEAR -#define D3D_FILTER_ANISOTROPIC D3D11_FILTER_ANISOTROPIC - -#define D3D_FILTER_COMPARISON_MIN_MAG_MIP_POINT D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT -#define D3D_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR -#define D3D_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT -#define D3D_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR -#define D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT -#define D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR -#define D3D_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT -#define D3D_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR -#define D3D_FILTER_COMPARISON_ANISOTROPIC D3D11_FILTER_COMPARISON_ANISOTROPIC +#define D3D_FILTER_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR +#define D3D_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT +#define D3D_FILTER_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR +#define D3D_FILTER_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT +#define D3D_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR +#define D3D_FILTER_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT +#define D3D_FILTER_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_LINEAR +#define D3D_FILTER_ANISOTROPIC D3D11_FILTER_ANISOTROPIC + +#define D3D_FILTER_COMPARISON_MIN_MAG_MIP_POINT D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT +#define D3D_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR +#define D3D_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT +#define D3D_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR +#define D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT +#define D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR +#define D3D_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT +#define D3D_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR +#define D3D_FILTER_COMPARISON_ANISOTROPIC D3D11_FILTER_COMPARISON_ANISOTROPIC // Minimum/maximum filtering is not supported in d3d11 -#define D3D_FILTER_MINIMUM_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MINIMUM_ANISOTROPIC D3D11_FILTER_MIN_MAG_MIP_POINT - -#define D3D_FILTER_MAXIMUM_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT -#define D3D_FILTER_MAXIMUM_ANISOTROPIC D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MINIMUM_ANISOTROPIC D3D11_FILTER_MIN_MAG_MIP_POINT + +#define D3D_FILTER_MAXIMUM_MIN_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR D3D11_FILTER_MIN_MAG_MIP_POINT +#define D3D_FILTER_MAXIMUM_ANISOTROPIC D3D11_FILTER_MIN_MAG_MIP_POINT // Comparison functions -#define D3D_COMPARISON_FUNC_NEVER D3D11_COMPARISON_NEVER -#define D3D_COMPARISON_FUNC_LESS D3D11_COMPARISON_LESS -#define D3D_COMPARISON_FUNC_EQUAL D3D11_COMPARISON_EQUAL -#define D3D_COMPARISON_FUNC_LESS_EQUAL D3D11_COMPARISON_LESS_EQUAL -#define D3D_COMPARISON_FUNC_GREATER D3D11_COMPARISON_GREATER -#define D3D_COMPARISON_FUNC_NOT_EQUAL D3D11_COMPARISON_NOT_EQUAL -#define D3D_COMPARISON_FUNC_GREATER_EQUAL D3D11_COMPARISON_GREATER_EQUAL -#define D3D_COMPARISON_FUNC_ALWAYS D3D11_COMPARISON_ALWAYS +#define D3D_COMPARISON_FUNC_NEVER D3D11_COMPARISON_NEVER +#define D3D_COMPARISON_FUNC_LESS D3D11_COMPARISON_LESS +#define D3D_COMPARISON_FUNC_EQUAL D3D11_COMPARISON_EQUAL +#define D3D_COMPARISON_FUNC_LESS_EQUAL D3D11_COMPARISON_LESS_EQUAL +#define D3D_COMPARISON_FUNC_GREATER D3D11_COMPARISON_GREATER +#define D3D_COMPARISON_FUNC_NOT_EQUAL D3D11_COMPARISON_NOT_EQUAL +#define D3D_COMPARISON_FUNC_GREATER_EQUAL D3D11_COMPARISON_GREATER_EQUAL +#define D3D_COMPARISON_FUNC_ALWAYS D3D11_COMPARISON_ALWAYS // Stencil operations #define D3D_STENCIL_OP_KEEP D3D11_STENCIL_OP_KEEP @@ -90,8 +90,8 @@ #define D3D_STENCIL_OP_DECR D3D11_STENCIL_OP_DECR // Depth write masks -#define D3D_DEPTH_WRITE_MASK_ALL D3D11_DEPTH_WRITE_MASK_ALL -#define D3D_DEPTH_WRITE_MASK_ZERO D3D11_DEPTH_WRITE_MASK_ZERO +#define D3D_DEPTH_WRITE_MASK_ALL D3D11_DEPTH_WRITE_MASK_ALL +#define D3D_DEPTH_WRITE_MASK_ZERO D3D11_DEPTH_WRITE_MASK_ZERO // Cull modes #define D3D_CULL_MODE_NONE D3D11_CULL_NONE @@ -103,23 +103,23 @@ #define D3D_FILL_MODE_SOLID D3D11_FILL_SOLID // Blend sources -#define D3D_BLEND_ZERO D3D11_BLEND_ZERO -#define D3D_BLEND_ONE D3D11_BLEND_ONE -#define D3D_BLEND_SRC_COLOR D3D11_BLEND_SRC_COLOR -#define D3D_BLEND_INV_SRC_COLOR D3D11_BLEND_INV_SRC_COLOR -#define D3D_BLEND_SRC_ALPHA D3D11_BLEND_SRC_ALPHA -#define D3D_BLEND_INV_SRC_ALPHA D3D11_BLEND_INV_SRC_ALPHA -#define D3D_BLEND_DEST_ALPHA D3D11_BLEND_DEST_ALPHA -#define D3D_BLEND_INV_DEST_ALPHA D3D11_BLEND_INV_DEST_ALPHA -#define D3D_BLEND_DEST_COLOR D3D11_BLEND_DEST_COLOR -#define D3D_BLEND_INV_DEST_COLOR D3D11_BLEND_INV_DEST_COLOR -#define D3D_BLEND_SRC_ALPHA_SAT D3D11_BLEND_SRC_ALPHA_SAT -#define D3D_BLEND_BLEND_FACTOR D3D11_BLEND_BLEND_FACTOR -#define D3D_BLEND_INV_BLEND_FACTOR D3D11_BLEND_INV_BLEND_FACTOR -#define D3D_BLEND_SRC1_COLOR D3D11_BLEND_SRC1_COLOR -#define D3D_BLEND_INV_SRC1_COLOR D3D11_BLEND_INV_SRC1_COLOR -#define D3D_BLEND_SRC1_ALPHA D3D11_BLEND_SRC1_ALPHA -#define D3D_BLEND_INV_SRC1_ALPHA D3D11_BLEND_INV_SRC1_ALPHA +#define D3D_BLEND_ZERO D3D11_BLEND_ZERO +#define D3D_BLEND_ONE D3D11_BLEND_ONE +#define D3D_BLEND_SRC_COLOR D3D11_BLEND_SRC_COLOR +#define D3D_BLEND_INV_SRC_COLOR D3D11_BLEND_INV_SRC_COLOR +#define D3D_BLEND_SRC_ALPHA D3D11_BLEND_SRC_ALPHA +#define D3D_BLEND_INV_SRC_ALPHA D3D11_BLEND_INV_SRC_ALPHA +#define D3D_BLEND_DEST_ALPHA D3D11_BLEND_DEST_ALPHA +#define D3D_BLEND_INV_DEST_ALPHA D3D11_BLEND_INV_DEST_ALPHA +#define D3D_BLEND_DEST_COLOR D3D11_BLEND_DEST_COLOR +#define D3D_BLEND_INV_DEST_COLOR D3D11_BLEND_INV_DEST_COLOR +#define D3D_BLEND_SRC_ALPHA_SAT D3D11_BLEND_SRC_ALPHA_SAT +#define D3D_BLEND_BLEND_FACTOR D3D11_BLEND_BLEND_FACTOR +#define D3D_BLEND_INV_BLEND_FACTOR D3D11_BLEND_INV_BLEND_FACTOR +#define D3D_BLEND_SRC1_COLOR D3D11_BLEND_SRC1_COLOR +#define D3D_BLEND_INV_SRC1_COLOR D3D11_BLEND_INV_SRC1_COLOR +#define D3D_BLEND_SRC1_ALPHA D3D11_BLEND_SRC1_ALPHA +#define D3D_BLEND_INV_SRC1_ALPHA D3D11_BLEND_INV_SRC1_ALPHA // Blend operations #define D3D_BLEND_OP_ADD D3D11_BLEND_OP_ADD @@ -129,10 +129,10 @@ #define D3D_BLEND_OP_MAX D3D11_BLEND_OP_MAX // Color masks -#define D3D_COLOR_WRITE_ENABLE_RED D3D11_COLOR_WRITE_ENABLE_RED -#define D3D_COLOR_WRITE_ENABLE_GREEN D3D11_COLOR_WRITE_ENABLE_GREEN -#define D3D_COLOR_WRITE_ENABLE_BLUE D3D11_COLOR_WRITE_ENABLE_BLUE -#define D3D_COLOR_WRITE_ENABLE_ALPHA D3D11_COLOR_WRITE_ENABLE_ALPHA +#define D3D_COLOR_WRITE_ENABLE_RED D3D11_COLOR_WRITE_ENABLE_RED +#define D3D_COLOR_WRITE_ENABLE_GREEN D3D11_COLOR_WRITE_ENABLE_GREEN +#define D3D_COLOR_WRITE_ENABLE_BLUE D3D11_COLOR_WRITE_ENABLE_BLUE +#define D3D_COLOR_WRITE_ENABLE_ALPHA D3D11_COLOR_WRITE_ENABLE_ALPHA // Input classification #define D3D_INPUT_CLASSIFICATION_PER_VERTEX_DATA D3D11_INPUT_PER_VERTEX_DATA @@ -150,36 +150,36 @@ // d3d11.h aliases D3D11_SRV_DIMENSION as D3D_SRV_DIMENSION, so there is no // need to redefine this enum -// RTV Dimensions -#define D3D_RTV_DIMENSION_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN -#define D3D_RTV_DIMENSION_BUFFER D3D11_RTV_DIMENSION_BUFFER -#define D3D_RTV_DIMENSION_TEXTURE1D D3D11_RTV_DIMENSION_TEXTURE1D -#define D3D_RTV_DIMENSION_TEXTURE1DARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY -#define D3D_RTV_DIMENSION_TEXTURE2D D3D11_RTV_DIMENSION_TEXTURE2D -#define D3D_RTV_DIMENSION_TEXTURE2DARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY -#define D3D_RTV_DIMENSION_TEXTURE2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS -#define D3D_RTV_DIMENSION_TEXTURE2DMSARRAY D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY -#define D3D_RTV_DIMENSION_TEXTURE3D D3D11_RTV_DIMENSION_TEXTURE3D - - -// DSV Dimensions -#define D3D_DSV_DIMENSION_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN -#define D3D_DSV_DIMENSION_TEXTURE1D D3D11_DSV_DIMENSION_TEXTURE1D -#define D3D_DSV_DIMENSION_TEXTURE1DARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY -#define D3D_DSV_DIMENSION_TEXTURE2D D3D11_DSV_DIMENSION_TEXTURE2D -#define D3D_DSV_DIMENSION_TEXTURE2DARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY -#define D3D_DSV_DIMENSION_TEXTURE2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS -#define D3D_DSV_DIMENSION_TEXTURE2DMSARRAY D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY +// RTV Dimensions +#define D3D_RTV_DIMENSION_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN +#define D3D_RTV_DIMENSION_BUFFER D3D11_RTV_DIMENSION_BUFFER +#define D3D_RTV_DIMENSION_TEXTURE1D D3D11_RTV_DIMENSION_TEXTURE1D +#define D3D_RTV_DIMENSION_TEXTURE1DARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY +#define D3D_RTV_DIMENSION_TEXTURE2D D3D11_RTV_DIMENSION_TEXTURE2D +#define D3D_RTV_DIMENSION_TEXTURE2DARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY +#define D3D_RTV_DIMENSION_TEXTURE2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS +#define D3D_RTV_DIMENSION_TEXTURE2DMSARRAY D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY +#define D3D_RTV_DIMENSION_TEXTURE3D D3D11_RTV_DIMENSION_TEXTURE3D + + +// DSV Dimensions +#define D3D_DSV_DIMENSION_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN +#define D3D_DSV_DIMENSION_TEXTURE1D D3D11_DSV_DIMENSION_TEXTURE1D +#define D3D_DSV_DIMENSION_TEXTURE1DARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY +#define D3D_DSV_DIMENSION_TEXTURE2D D3D11_DSV_DIMENSION_TEXTURE2D +#define D3D_DSV_DIMENSION_TEXTURE2DARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY +#define D3D_DSV_DIMENSION_TEXTURE2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS +#define D3D_DSV_DIMENSION_TEXTURE2DMSARRAY D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY // UAV Dimensions -#define D3D_UAV_DIMENSION_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN -#define D3D_UAV_DIMENSION_BUFFER D3D11_UAV_DIMENSION_BUFFER -#define D3D_UAV_DIMENSION_TEXTURE1D D3D11_UAV_DIMENSION_TEXTURE1D -#define D3D_UAV_DIMENSION_TEXTURE1DARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY -#define D3D_UAV_DIMENSION_TEXTURE2D D3D11_UAV_DIMENSION_TEXTURE2D -#define D3D_UAV_DIMENSION_TEXTURE2DARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY -#define D3D_UAV_DIMENSION_TEXTURE3D D3D11_UAV_DIMENSION_TEXTURE3D +#define D3D_UAV_DIMENSION_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN +#define D3D_UAV_DIMENSION_BUFFER D3D11_UAV_DIMENSION_BUFFER +#define D3D_UAV_DIMENSION_TEXTURE1D D3D11_UAV_DIMENSION_TEXTURE1D +#define D3D_UAV_DIMENSION_TEXTURE1DARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY +#define D3D_UAV_DIMENSION_TEXTURE2D D3D11_UAV_DIMENSION_TEXTURE2D +#define D3D_UAV_DIMENSION_TEXTURE2DARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY +#define D3D_UAV_DIMENSION_TEXTURE3D D3D11_UAV_DIMENSION_TEXTURE3D // Buffer flags -#define D3D_BUFFER_UAV_FLAG_RAW D3D11_BUFFER_UAV_FLAG_RAW -#define D3D_BUFFER_UAV_FLAG_NONE 0 \ No newline at end of file +#define D3D_BUFFER_UAV_FLAG_RAW D3D11_BUFFER_UAV_FLAG_RAW +#define D3D_BUFFER_UAV_FLAG_NONE 0 diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index 81d40cb4..d455fc85 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -34,7 +34,7 @@ #include "PipelineStateD3D11Impl.h" #ifdef _DEBUG -# define VERIFY_CONTEXT_BINDINGS +# define VERIFY_CONTEXT_BINDINGS #endif namespace Diligent @@ -62,22 +62,22 @@ public: ID3D11DeviceContext* pd3d11DeviceContext, const struct EngineD3D11CreateInfo& EngineAttribs, bool bIsDeferred); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of IDeviceContext::SetPipelineState() in Direct3D11 backend. - virtual void SetPipelineState(IPipelineState* pPipelineState)override final; + virtual void SetPipelineState(IPipelineState* pPipelineState) override final; /// Implementation of IDeviceContext::TransitionShaderResources() in Direct3D11 backend. - virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding)override final; + virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) override final; /// Implementation of IDeviceContext::CommitShaderResources() in Direct3D11 backend. - virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::SetStencilRef() in Direct3D11 backend. - virtual void SetStencilRef(Uint32 StencilRef)override final; + virtual void SetStencilRef(Uint32 StencilRef) override final; /// Implementation of IDeviceContext::SetBlendFactors() in Direct3D11 backend. - virtual void SetBlendFactors(const float* pBlendFactors = nullptr)override final; + virtual void SetBlendFactors(const float* pBlendFactors = nullptr) override final; /// Implementation of IDeviceContext::SetVertexBuffers() in Direct3D11 backend. virtual void SetVertexBuffers(Uint32 StartSlot, @@ -85,56 +85,56 @@ public: IBuffer** ppBuffers, Uint32* pOffsets, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, - SET_VERTEX_BUFFERS_FLAGS Flags)override final; - + SET_VERTEX_BUFFERS_FLAGS Flags) override final; + /// Implementation of IDeviceContext::InvalidateState() in Direct3D11 backend. - virtual void InvalidateState()override final; + virtual void InvalidateState() override final; /// Implementation of IDeviceContext::SetIndexBuffer() in Direct3D11 backend. - virtual void SetIndexBuffer(IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + virtual void SetIndexBuffer(IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::SetViewports() in Direct3D11 backend. - virtual void SetViewports(Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight)override final; + virtual void SetViewports(Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight) override final; /// Implementation of IDeviceContext::SetScissorRects() in Direct3D11 backend. - virtual void SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight)override final; + virtual void SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight) override final; /// Implementation of IDeviceContext::SetRenderTargets() in Direct3D11 backend. virtual void SetRenderTargets(Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::Draw() in Direct3D11 backend. - virtual void Draw (const DrawAttribs& Attribs)override final; + virtual void Draw(const DrawAttribs& Attribs) override final; /// Implementation of IDeviceContext::DrawIndexed() in Direct3D11 backend. - virtual void DrawIndexed (const DrawIndexedAttribs& Attribs)override final; + virtual void DrawIndexed(const DrawIndexedAttribs& Attribs) override final; /// Implementation of IDeviceContext::DrawIndirect() in Direct3D11 backend. - virtual void DrawIndirect (const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer)override final; + virtual void DrawIndirect(const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; /// Implementation of IDeviceContext::DrawIndexedIndirect() in Direct3D11 backend. - virtual void DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer)override final; + virtual void DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; /// Implementation of IDeviceContext::DispatchCompute() in Direct3D11 backend. - virtual void DispatchCompute(const DispatchComputeAttribs& Attribs)override final; + virtual void DispatchCompute(const DispatchComputeAttribs& Attribs) override final; /// Implementation of IDeviceContext::DispatchComputeIndirect() in Direct3D11 backend. - virtual void DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer)override final; + virtual void DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; /// Implementation of IDeviceContext::ClearDepthStencil() in Direct3D11 backend. virtual void ClearDepthStencil(ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::ClearRenderTarget() in Direct3D11 backend. - virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::UpdateBuffer() in Direct3D11 backend. virtual void UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::CopyBuffer() in Direct3D11 backend. virtual void CopyBuffer(IBuffer* pSrcBuffer, @@ -143,13 +143,13 @@ public: IBuffer* pDstBuffer, Uint32 DstOffset, Uint32 Size, - RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode)override final; + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) override final; /// Implementation of IDeviceContext::MapBuffer() in Direct3D11 backend. - virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override final; + virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) override final; /// Implementation of IDeviceContext::UnmapBuffer() in Direct3D11 backend. - virtual void UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType)override final; + virtual void UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) override final; /// Implementation of IDeviceContext::UpdateTexture() in Direct3D11 backend. virtual void UpdateTexture(ITexture* pTexture, @@ -158,10 +158,10 @@ public: const Box& DstBox, const TextureSubResData& SubresData, RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)override final; + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; /// Implementation of IDeviceContext::CopyTexture() in Direct3D11 backend. - virtual void CopyTexture(const CopyTextureAttribs& CopyAttribs)override final; + virtual void CopyTexture(const CopyTextureAttribs& CopyAttribs) override final; /// Implementation of IDeviceContext::MapTextureSubresource() in Direct3D11 backend. virtual void MapTextureSubresource(ITexture* pTexture, @@ -170,51 +170,51 @@ public: MAP_TYPE MapType, MAP_FLAGS MapFlags, const Box* pMapRegion, - MappedTextureSubresource& MappedData)override final; + MappedTextureSubresource& MappedData) override final; /// Implementation of IDeviceContext::UnmapTextureSubresource() in Direct3D11 backend. - virtual void UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice)override final; + virtual void UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) override final; /// Implementation of IDeviceContext::GenerateMips() in Direct3D11 backend. - virtual void GenerateMips(ITextureView* pTextureView)override final; + virtual void GenerateMips(ITextureView* pTextureView) override final; /// Implementation of IDeviceContext::FinishFrame() in Direct3D11 backend. - virtual void FinishFrame()override final; + virtual void FinishFrame() override final; /// Implementation of IDeviceContext::TransitionResourceStates() in Direct3D11 backend. - virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers)override final; - + virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) override final; + /// Implementation of IDeviceContext::ResolveTextureSubresource() in Direct3D11 backend. virtual void ResolveTextureSubresource(ITexture* pSrcTexture, ITexture* pDstTexture, - const ResolveTextureSubresourceAttribs& ResolveAttribs)override final; + const ResolveTextureSubresourceAttribs& ResolveAttribs) override final; /// Implementation of IDeviceContext::FinishCommandList() in Direct3D11 backend. - void FinishCommandList(class ICommandList** ppCommandList)override final; + void FinishCommandList(class ICommandList** ppCommandList) override final; /// Implementation of IDeviceContext::ExecuteCommandList() in Direct3D11 backend. - virtual void ExecuteCommandList(class ICommandList* pCommandList)override final; + virtual void ExecuteCommandList(class ICommandList* pCommandList) override final; /// Implementation of IDeviceContext::SignalFence() in Direct3D11 backend. - virtual void SignalFence(IFence* pFence, Uint64 Value)override final; + virtual void SignalFence(IFence* pFence, Uint64 Value) override final; /// Implementation of IDeviceContext::WaitForFence() in Direct3D11 backend. - virtual void WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext)override final; + virtual void WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext) override final; /// Implementation of IDeviceContext::WaitForIdle() in Direct3D11 backend. - virtual void WaitForIdle()override final; + virtual void WaitForIdle() override final; /// Implementation of IDeviceContext::Flush() in Direct3D11 backend. - virtual void Flush()override final; + virtual void Flush() override final; /// Implementation of IDeviceContextD3D11::GetD3D11DeviceContext(). - virtual ID3D11DeviceContext* GetD3D11DeviceContext()override final { return m_pd3d11DeviceContext; } + virtual ID3D11DeviceContext* GetD3D11DeviceContext() override final { return m_pd3d11DeviceContext; } void CommitRenderTargets(); - /// Clears committed shader resource cache. This function - /// is called once per frame (before present) to release all - /// outstanding objects that are only kept alive by references + /// Clears committed shader resource cache. This function + /// is called once per frame (before present) to release all + /// outstanding objects that are only kept alive by references /// in the cache. The function does not release cached vertex and /// index buffers, input layout, depth-stencil, rasterizer, and blend /// states. @@ -227,7 +227,6 @@ public: static constexpr int NumShaderTypes = 6; private: - /// Commits d3d11 index buffer to d3d11 device context. void CommitD3D11IndexBuffer(VALUE_TYPE IndexType); @@ -235,11 +234,11 @@ private: void CommitD3D11VertexBuffers(class PipelineStateD3D11Impl* pPipelineStateD3D11); /// Helper template function used to facilitate resource unbinding - template - void UnbindResourceView(TD3D11ResourceViewType CommittedD3D11ViewsArr[][NumSlots], - ID3D11Resource* CommittedD3D11ResourcesArr[][NumSlots], + template + void UnbindResourceView(TD3D11ResourceViewType CommittedD3D11ViewsArr[][NumSlots], + ID3D11Resource* CommittedD3D11ResourcesArr[][NumSlots], Uint8 NumCommittedResourcesArr[], ID3D11Resource* pd3d11ResToUndind, TSetD3D11View SetD3D11ViewMethods[]); @@ -249,7 +248,7 @@ private: /// context. All shader bindings are retained. void UnbindTextureFromInput(TextureBaseD3D11* pTexture, ID3D11Resource* pd3d11Resource); - /// Unbinds a buffer from input (shader resource views slots, index + /// Unbinds a buffer from input (shader resource views slots, index /// and vertex buffer slots). /// \note The function only unbinds the buffer from d3d11 device /// context. All shader bindings are retained. @@ -273,16 +272,18 @@ private: __forceinline void PrepareForIndexedDraw(DRAW_FLAGS Flags, VALUE_TYPE IndexType); - template + template void TransitionAndCommitShaderResources(IPipelineState* pPSO, IShaderResourceBinding* pShaderResourceBinding, bool VerifyStates); void ClearStateCache(); CComPtr m_pd3d11DeviceContext; ///< D3D11 device context + // clang-format off + /// An array of D3D11 constant buffers committed to D3D11 device context, - /// for each shader type. The context addref's all bound resources, so we do + /// for each shader type. The context addref's all bound resources, so we do /// not need to keep strong references. ID3D11Buffer* m_CommittedD3D11CBs [NumShaderTypes][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {}; @@ -316,15 +317,17 @@ private: Uint8 m_NumCommittedSamplers[NumShaderTypes] = {}; Uint8 m_NumCommittedUAVs [NumShaderTypes] = {}; + // clang-format on + /// An array of D3D11 vertex buffers committed to D3D device context. - /// There is no need to keep strong references because D3D11 device context + /// There is no need to keep strong references because D3D11 device context /// already does. Buffers cannot be destroyed while bound to the context. /// We only mirror all bindings. ID3D11Buffer* m_CommittedD3D11VertexBuffers[MaxBufferSlots] = {}; /// An array of strides of committed vertex buffers - UINT m_CommittedD3D11VBStrides [MaxBufferSlots] = {}; + UINT m_CommittedD3D11VBStrides[MaxBufferSlots] = {}; /// An array of offsets of committed vertex buffers - UINT m_CommittedD3D11VBOffsets [MaxBufferSlots] = {}; + UINT m_CommittedD3D11VBOffsets[MaxBufferSlots] = {}; /// Number committed vertex buffers UINT m_NumCommittedD3D11VBs = 0; /// Flag indicating if currently committed D3D11 vertex buffers are up to date @@ -335,9 +338,9 @@ private: /// to keep strong reference. ID3D11InputLayout* m_CommittedD3D11InputLayout = nullptr; - /// Strong reference to D3D11 buffer committed as index buffer + /// Strong reference to D3D11 buffer committed as index buffer /// to D3D device context. - CComPtr m_CommittedD3D11IndexBuffer; + CComPtr m_CommittedD3D11IndexBuffer; /// Format of the committed D3D11 index buffer VALUE_TYPE m_CommittedIBFormat = VT_UNDEFINED; /// Offset of the committed D3D11 index buffer @@ -358,7 +361,7 @@ private: #ifdef VERIFY_CONTEXT_BINDINGS /// Helper template function used to facilitate context verification - template + template void dbgVerifyCommittedResources(TD3D11ResourceType CommittedD3D11ResourcesArr[][MaxResources], Uint8 NumCommittedResourcesArr[], TGetD3D11ResourcesType GetD3D11ResMethods[], @@ -366,18 +369,18 @@ private: SHADER_TYPE ShaderType); /// Helper template function used to facilitate validation of SRV and UAV consistency with D3D11 resources - template + template void dbgVerifyViewConsistency(TD3D11ViewType CommittedD3D11ViewArr[][MaxResources], ID3D11Resource* CommittedD3D11ResourcesArr[][MaxResources], Uint8 NumCommittedResourcesArr[], const Char* ResourceName, SHADER_TYPE ShaderType); - /// Debug function that verifies that SRVs cached in m_CommittedD3D11SRVs + /// Debug function that verifies that SRVs cached in m_CommittedD3D11SRVs /// array comply with resources actually committed to D3D11 device context void dbgVerifyCommittedSRVs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN); - /// Debug function that verifies that UAVs cached in m_CommittedD3D11UAVs + /// Debug function that verifies that UAVs cached in m_CommittedD3D11UAVs /// array comply with resources actually committed to D3D11 device context void dbgVerifyCommittedUAVs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN); @@ -385,35 +388,35 @@ private: /// array comply with resources actually committed to D3D11 device context void dbgVerifyCommittedSamplers(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN); - /// Debug function that verifies that constant buffers cached in m_CommittedD3D11CBs + /// Debug function that verifies that constant buffers cached in m_CommittedD3D11CBs /// array comply with buffers actually committed to D3D11 device context void dbgVerifyCommittedCBs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN); - /// Debug function that verifies that index buffer cached in - /// m_CommittedD3D11IndexBuffer is the buffer actually committed to D3D11 + /// Debug function that verifies that index buffer cached in + /// m_CommittedD3D11IndexBuffer is the buffer actually committed to D3D11 /// device context void dbgVerifyCommittedIndexBuffer(); - /// Debug function that verifies that vertex buffers cached in - /// m_CommittedD3D11VertexBuffers are the buffers actually committed to D3D11 + /// Debug function that verifies that vertex buffers cached in + /// m_CommittedD3D11VertexBuffers are the buffers actually committed to D3D11 /// device context void dbgVerifyCommittedVertexBuffers(); - /// Debug function that verifies that shaders cached in - /// m_CommittedD3DShaders are the shaders actually committed to D3D11 + /// Debug function that verifies that shaders cached in + /// m_CommittedD3DShaders are the shaders actually committed to D3D11 /// device context void dbgVerifyCommittedShaders(); #else - #define dbgVerifyRenderTargetFormats(...) - #define dbgVerifyCommittedSRVs(...) - #define dbgVerifyCommittedUAVs(...) - #define dbgVerifyCommittedSamplers(...) - #define dbgVerifyCommittedCBs(...) - #define dbgVerifyCommittedIndexBuffer(...) - #define dbgVerifyCommittedVertexBuffers(...) - #define dbgVerifyCommittedShaders(...) +# define dbgVerifyRenderTargetFormats(...) +# define dbgVerifyCommittedSRVs(...) +# define dbgVerifyCommittedUAVs(...) +# define dbgVerifyCommittedSamplers(...) +# define dbgVerifyCommittedCBs(...) +# define dbgVerifyCommittedIndexBuffer(...) +# define dbgVerifyCommittedVertexBuffers(...) +# define dbgVerifyCommittedShaders(...) #endif // VERIFY_CONTEXT_BINDINGS }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/EngineD3D11Defines.h b/Graphics/GraphicsEngineD3D11/include/EngineD3D11Defines.h index 8f828905..c7d06e7f 100644 --- a/Graphics/GraphicsEngineD3D11/include/EngineD3D11Defines.h +++ b/Graphics/GraphicsEngineD3D11/include/EngineD3D11Defines.h @@ -24,5 +24,5 @@ #pragma once #ifdef _DEBUG -# define VERIFY_SHADER_BINDINGS +# define VERIFY_SHADER_BINDINGS #endif diff --git a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h index 99eb7cea..01ad5a25 100644 --- a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h @@ -49,10 +49,10 @@ public: ~FenceD3D11Impl(); /// Implementation of IFence::GetCompletedValue() in Direct3D11 backend. - virtual Uint64 GetCompletedValue()override final; + virtual Uint64 GetCompletedValue() override final; /// Implementation of IFence::Reset() in Direct3D11 backend. - virtual void Reset(Uint64 Value)override final; + virtual void Reset(Uint64 Value) override final; void AddPendingQuery(CComPtr pCtx, CComPtr pQuery, Uint64 Value) { @@ -68,14 +68,16 @@ private: CComPtr pd3d11Query; Uint64 Value; - PendingFenceData(CComPtr pCtx, CComPtr pQuery, Uint64 _Value) : - pd3d11Ctx (std::move(pCtx)), - pd3d11Query(std::move(pQuery)), - Value (_Value) + PendingFenceData(CComPtr pCtx, CComPtr pQuery, Uint64 _Value) : + // clang-format off + pd3d11Ctx {std::move(pCtx)}, + pd3d11Query{std::move(pQuery)}, + Value {_Value} + // clang-format on {} }; - std::deque< PendingFenceData > m_PendingQueries; - volatile Uint64 m_LastCompletedFenceValue = 0; + std::deque m_PendingQueries; + volatile Uint64 m_LastCompletedFenceValue = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h index 046974d2..8217a074 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h @@ -49,10 +49,10 @@ public: const PipelineStateDesc& PipelineDesc); ~PipelineStateD3D11Impl(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; - + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + /// Implementation of IPipelineState::BindStaticResources() in Direct3D11 backend. - virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)override final; + virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) override final; /// Implementation of IPipelineState::GetStaticVariableCount() in Direct3D11 backend. virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; @@ -64,41 +64,41 @@ public: virtual IShaderResourceVariable* GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; /// Implementation of IPipelineState::CreateShaderResourceBinding() in Direct3D11 backend. - virtual void CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding, bool InitStaticResources)override final; + virtual void CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) override final; /// Implementation of IPipelineState::IsCompatibleWith() in Direct3D11 backend. - virtual bool IsCompatibleWith(const IPipelineState *pPSO)const override final; + virtual bool IsCompatibleWith(const IPipelineState* pPSO) const override final; /// Implementation of IPipelineStateD3D11::GetD3D11BlendState() method. - virtual ID3D11BlendState* GetD3D11BlendState()override final; + virtual ID3D11BlendState* GetD3D11BlendState() override final; /// Implementation of IPipelineStateD3D11::GetD3D11RasterizerState() method. - virtual ID3D11RasterizerState* GetD3D11RasterizerState()override final; + virtual ID3D11RasterizerState* GetD3D11RasterizerState() override final; /// Implementation of IPipelineStateD3D11::GetD3D11DepthStencilState() method. - virtual ID3D11DepthStencilState* GetD3D11DepthStencilState()override final; + virtual ID3D11DepthStencilState* GetD3D11DepthStencilState() override final; /// Implementation of IPipelineStateD3D11::GetD3D11InputLayout() method. - virtual ID3D11InputLayout* GetD3D11InputLayout()override final; + virtual ID3D11InputLayout* GetD3D11InputLayout() override final; /// Implementation of IPipelineStateD3D11::GetD3D11VertexShader() method. - virtual ID3D11VertexShader* GetD3D11VertexShader()override final; + virtual ID3D11VertexShader* GetD3D11VertexShader() override final; /// Implementation of IPipelineStateD3D11::GetD3D11PixelShader() method. - virtual ID3D11PixelShader* GetD3D11PixelShader()override final; + virtual ID3D11PixelShader* GetD3D11PixelShader() override final; /// Implementation of IPipelineStateD3D11::GetD3D11GeometryShader() method. - virtual ID3D11GeometryShader* GetD3D11GeometryShader()override final; + virtual ID3D11GeometryShader* GetD3D11GeometryShader() override final; /// Implementation of IPipelineStateD3D11::GetD3D11DomainShader() method. - virtual ID3D11DomainShader* GetD3D11DomainShader()override final; + virtual ID3D11DomainShader* GetD3D11DomainShader() override final; /// Implementation of IPipelineStateD3D11::GetD3D11HullShader() method. - virtual ID3D11HullShader* GetD3D11HullShader()override final; + virtual ID3D11HullShader* GetD3D11HullShader() override final; /// Implementation of IPipelineStateD3D11::GetD3D11ComputeShader() method. - virtual ID3D11ComputeShader* GetD3D11ComputeShader()override final; + virtual ID3D11ComputeShader* GetD3D11ComputeShader() override final; SRBMemoryAllocator& GetSRBMemoryAllocator() @@ -106,7 +106,7 @@ public: return m_SRBMemAllocator; } - const ShaderResourceLayoutD3D11& GetStaticResourceLayout(Uint32 s)const + const ShaderResourceLayoutD3D11& GetStaticResourceLayout(Uint32 s) const { VERIFY_EXPR(s < m_NumShaders); return m_pStaticResourceLayouts[s]; @@ -118,36 +118,37 @@ public: return m_pStaticResourceCaches[s]; } - void SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const; + void SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd) const; private: - CComPtr m_pd3d11BlendState; CComPtr m_pd3d11RasterizerState; CComPtr m_pd3d11DepthStencilState; CComPtr m_pd3d11InputLayout; // The caches are indexed by the shader order in the PSO, not shader index - ShaderResourceCacheD3D11* m_pStaticResourceCaches = nullptr; - ShaderResourceLayoutD3D11* m_pStaticResourceLayouts= nullptr; + ShaderResourceCacheD3D11* m_pStaticResourceCaches = nullptr; + ShaderResourceLayoutD3D11* m_pStaticResourceLayouts = nullptr; // SRB memory allocator must be defined before the default shader res binding SRBMemoryAllocator m_SRBMemAllocator; - Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; + Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; - Uint16 m_StaticSamplerOffsets[MaxShadersInPipeline+1] = {}; + Uint16 m_StaticSamplerOffsets[MaxShadersInPipeline + 1] = {}; struct StaticSamplerInfo { const D3DShaderResourceAttribs& Attribs; RefCntAutoPtr pSampler; StaticSamplerInfo(const D3DShaderResourceAttribs& _Attribs, - RefCntAutoPtr _pSampler) : - Attribs (_Attribs), - pSampler (std::move(_pSampler)) + RefCntAutoPtr _pSampler) : + // clang-format off + Attribs {_Attribs}, + pSampler {std::move(_pSampler)} + // clang-format on {} }; - std::vector< StaticSamplerInfo, STDAllocatorRawMem > m_StaticSamplers; + std::vector> m_StaticSamplers; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h index bb3ec034..aa39df32 100644 --- a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h @@ -39,58 +39,58 @@ class RenderDeviceD3D11Impl final : public RenderDeviceD3DBase; - RenderDeviceD3D11Impl( IReferenceCounters* pRefCounters, - IMemoryAllocator& RawMemAllocator, - IEngineFactory* pEngineFactory, - const EngineD3D11CreateInfo& EngineAttribs, - ID3D11Device* pd3d11Device, - Uint32 NumDeferredContexts ); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + RenderDeviceD3D11Impl(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + IEngineFactory* pEngineFactory, + const EngineD3D11CreateInfo& EngineAttribs, + ID3D11Device* pd3d11Device, + Uint32 NumDeferredContexts); + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of IRenderDevice::CreateBuffer() in Direct3D11 backend. - virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)override final; + virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer) override final; /// Implementation of IRenderDevice::CreateShader() in Direct3D11 backend. - virtual void CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)override final; + virtual void CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader) override final; /// Implementation of IRenderDevice::CreateTexture() in Direct3D11 backend. - virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)override final; - + virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture) override final; + /// Implementation of IRenderDevice::CreateSampler() in Direct3D11 backend. - virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)override final; + virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) override final; /// Implementation of IRenderDevice::CreatePipelineState() in Direct3D11 backend. - virtual void CreatePipelineState(const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState)override final; + virtual void CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState) override final; /// Implementation of IRenderDevice::CreateFence() in Direct3D11 backend. - virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final; + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence) override final; /// Implementation of IRenderDeviceD3D11::GetD3D11Device() in Direct3D11 backend. - ID3D11Device* GetD3D11Device()override final{return m_pd3d11Device;} + ID3D11Device* GetD3D11Device() override final { return m_pd3d11Device; } /// Implementation of IRenderDeviceD3D11::CreateBufferFromD3DResource() in Direct3D11 backend. - virtual void CreateBufferFromD3DResource(ID3D11Buffer* pd3d11Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer)override final; + virtual void CreateBufferFromD3DResource(ID3D11Buffer* pd3d11Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) override final; /// Implementation of IRenderDeviceD3D11::CreateTextureFromD3DResource() for 1D textures in Direct3D11 backend. - virtual void CreateTextureFromD3DResource(ID3D11Texture1D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture)override final; + virtual void CreateTextureFromD3DResource(ID3D11Texture1D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; /// Implementation of IRenderDeviceD3D11::CreateTextureFromD3DResource() for 2D textures in Direct3D11 backend. - virtual void CreateTextureFromD3DResource(ID3D11Texture2D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture)override final; + virtual void CreateTextureFromD3DResource(ID3D11Texture2D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; /// Implementation of IRenderDeviceD3D11::CreateTextureFromD3DResource() for 3D textures in Direct3D11 backend. - virtual void CreateTextureFromD3DResource(ID3D11Texture3D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture)override final; + virtual void CreateTextureFromD3DResource(ID3D11Texture3D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; /// Implementation of IRenderDevice::ReleaseStaleResources() in Direct3D11 backend. - virtual void ReleaseStaleResources(bool ForceRelease = false)override final {} + virtual void ReleaseStaleResources(bool ForceRelease = false) override final {} /// Implementation of IRenderDevice::IdleGPU() in Direct3D11 backend. - virtual void IdleGPU()override final; + virtual void IdleGPU() override final; - size_t GetCommandQueueCount()const { return 1; } - Uint64 GetCommandQueueMask()const { return Uint64{1};} + size_t GetCommandQueueCount() const { return 1; } + Uint64 GetCommandQueueMask() const { return Uint64{1}; } private: - virtual void TestTextureFormat( TEXTURE_FORMAT TexFormat )override final; + virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; EngineD3D11CreateInfo m_EngineAttribs; @@ -98,5 +98,4 @@ private: CComPtr m_pd3d11Device; }; -} - +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h index 0c97f209..6f89ee5e 100644 --- a/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h @@ -50,11 +50,11 @@ public: virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of ISamplerD3D11::ISamplerD3D11() method. - virtual ID3D11SamplerState* GetD3D11SamplerState()override final{ return m_pd3dSampler; } + virtual ID3D11SamplerState* GetD3D11SamplerState() override final { return m_pd3dSampler; } private: /// D3D11 sampler CComPtr m_pd3dSampler; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h index bb08d523..8ce4f600 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h @@ -52,44 +52,44 @@ public: class RenderDeviceD3D11Impl* pRenderDeviceD3D11, const ShaderCreateInfo& ShaderCI); ~ShaderD3D11Impl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of IShader::GetResourceCount() in Direct3D11 backend. - virtual Uint32 GetResourceCount()const override final + virtual Uint32 GetResourceCount() const override final { return m_pShaderResources->GetTotalResources(); } /// Implementation of IShader::GetResource() in Direct3D11 backend. - virtual ShaderResourceDesc GetResource(Uint32 Index)const override final + virtual ShaderResourceDesc GetResource(Uint32 Index) const override final { return GetHLSLResource(Index); } /// Implementation of IShaderD3D::GetHLSLResource() method. - virtual HLSLShaderResourceDesc GetHLSLResource(Uint32 Index)const override final + virtual HLSLShaderResourceDesc GetHLSLResource(Uint32 Index) const override final { return m_pShaderResources->GetHLSLShaderResourceDesc(Index); } /// Implementation of IShaderD3D11::GetD3D11Shader() method. - virtual ID3D11DeviceChild* GetD3D11Shader()override final + virtual ID3D11DeviceChild* GetD3D11Shader() override final { return m_pShader; } - ID3DBlob* GetBytecode(){return m_pShaderByteCode;} + ID3DBlob* GetBytecode() { return m_pShaderByteCode; } - const std::shared_ptr& GetD3D11Resources()const{return m_pShaderResources;} + const std::shared_ptr& GetD3D11Resources() const { return m_pShaderResources; } private: /// D3D11 shader CComPtr m_pShader; - - // ShaderResources class instance must be referenced through the shared pointer, because + + // ShaderResources class instance must be referenced through the shared pointer, because // it is referenced by ShaderResourceLayoutD3D11 class instances std::shared_ptr m_pShaderResources; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h index fad239d3..0bde6c75 100755 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.h @@ -49,47 +49,56 @@ public: bool IsInternal); ~ShaderResourceBindingD3D11Impl(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of IShaderResourceBinding::BindResources() in Direct3D11 backend. - virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override final; + virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) override final; /// Implementation of IShaderResourceBinding::GetVariableByName() in Direct3D11 backend. - virtual IShaderResourceVariable* GetVariableByName(SHADER_TYPE ShaderType, const char* Name)override final; + virtual IShaderResourceVariable* GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final; /// Implementation of IShaderResourceBinding::GetVariableCount() in Direct3D11 backend. virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final; /// Implementation of IShaderResourceBinding::GetVariableByIndex() in Direct3D11 backend. - virtual IShaderResourceVariable* GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index)override final; + virtual IShaderResourceVariable* GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; /// Implementation of IShaderResourceBinding::InitializeStaticResources() in Direct3D11 backend. - virtual void InitializeStaticResources(const IPipelineState* pPipelineState)override final; + virtual void InitializeStaticResources(const IPipelineState* pPipelineState) override final; - ShaderResourceCacheD3D11& GetResourceCache (Uint32 Ind){VERIFY_EXPR(Ind < m_NumActiveShaders); return m_pBoundResourceCaches[Ind];} - ShaderResourceLayoutD3D11& GetResourceLayout(Uint32 Ind){VERIFY_EXPR(Ind < m_NumActiveShaders); return m_pResourceLayouts[Ind];} + ShaderResourceCacheD3D11& GetResourceCache(Uint32 Ind) + { + VERIFY_EXPR(Ind < m_NumActiveShaders); + return m_pBoundResourceCaches[Ind]; + } - inline bool IsStaticResourcesBound(){return m_bIsStaticResourcesBound;} + ShaderResourceLayoutD3D11& GetResourceLayout(Uint32 Ind) + { + VERIFY_EXPR(Ind < m_NumActiveShaders); + return m_pResourceLayouts[Ind]; + } + + inline bool IsStaticResourcesBound() { return m_bIsStaticResourcesBound; } Uint32 GetNumActiveShaders() { return static_cast(m_NumActiveShaders); } - Int32 GetActiveShaderTypeIndex(Uint32 s){return m_ShaderTypeIndex[s];} + Int32 GetActiveShaderTypeIndex(Uint32 s) { return m_ShaderTypeIndex[s]; } private: // The caches are indexed by the shader order in the PSO, not shader index ShaderResourceCacheD3D11* m_pBoundResourceCaches = nullptr; ShaderResourceLayoutD3D11* m_pResourceLayouts = nullptr; - - Int8 m_ShaderTypeIndex[6] = {}; + + Int8 m_ShaderTypeIndex[6] = {}; // Resource layout index in m_ResourceLayouts[] array for every shader stage Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; Uint8 m_NumActiveShaders = 0; - + bool m_bIsStaticResourcesBound = false; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h index ef197549..0792f4f4 100755 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h @@ -51,18 +51,20 @@ public: ~ShaderResourceCacheD3D11(); - + // clang-format off ShaderResourceCacheD3D11 (const ShaderResourceCacheD3D11&) = delete; ShaderResourceCacheD3D11& operator = (const ShaderResourceCacheD3D11&) = delete; ShaderResourceCacheD3D11 (ShaderResourceCacheD3D11&&) = delete; ShaderResourceCacheD3D11& operator = (ShaderResourceCacheD3D11&&) = delete; + // clang-format on /// Describes a resource associated with a cached constant buffer struct CachedCB { /// Strong reference to the buffer RefCntAutoPtr pBuff; - __forceinline void Set(RefCntAutoPtr &&_pBuff) + + __forceinline void Set(RefCntAutoPtr&& _pBuff) { pBuff = std::move(_pBuff); } @@ -73,7 +75,8 @@ public: { /// Strong reference to the sampler RefCntAutoPtr pSampler; - __forceinline void Set(SamplerD3D11Impl *pSam) + + __forceinline void Set(SamplerD3D11Impl* pSam) { pSampler = pSam; } @@ -84,17 +87,19 @@ public: { /// Wee keep strong reference to the view instead of the reference /// to the texture or buffer because this is more efficient from - /// performance point of view: this avoids one pair of - /// AddStrongRef()/ReleaseStrongRef(). The view holds strong reference + /// performance point of view: this avoids one pair of + /// AddStrongRef()/ReleaseStrongRef(). The view holds strong reference /// to the texture or the buffer, so it makes no difference. RefCntAutoPtr pView; - TextureBaseD3D11* pTexture; - BufferD3D11Impl* pBuffer; + + TextureBaseD3D11* pTexture = nullptr; + BufferD3D11Impl* pBuffer = nullptr; + // There is no need to keep strong reference to D3D11 resource as // it is already kept by either pTexture or pBuffer - ID3D11Resource* pd3d11Resource; - CachedResource()noexcept : pTexture{nullptr}, pBuffer{nullptr}, pd3d11Resource{nullptr} - {} + ID3D11Resource* pd3d11Resource = nullptr; + + CachedResource() noexcept {} __forceinline void Set(RefCntAutoPtr&& pTexView) { @@ -124,37 +129,37 @@ public: __forceinline void SetCB(Uint32 Slot, RefCntAutoPtr&& pBuffD3D11Impl) { - auto *pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr; + auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr; SetD3D11ResourceInternal(Slot, GetCBCount(), &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff); } __forceinline void SetTexSRV(Uint32 Slot, RefCntAutoPtr&& pTexView) { - auto pd3d11SRV = pTexView ? static_cast(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; + auto* pd3d11SRV = pTexView ? static_cast(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; SetD3D11ResourceInternal(Slot, GetSRVCount(), &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV); } __forceinline void SetBufSRV(Uint32 Slot, RefCntAutoPtr&& pBuffView) { - auto pd3d11SRV = pBuffView ? static_cast(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; + auto* pd3d11SRV = pBuffView ? static_cast(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; SetD3D11ResourceInternal(Slot, GetSRVCount(), &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV); } __forceinline void SetTexUAV(Uint32 Slot, RefCntAutoPtr&& pTexView) { - auto pd3d11UAV = pTexView ? static_cast(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; + auto* pd3d11UAV = pTexView ? static_cast(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; SetD3D11ResourceInternal(Slot, GetUAVCount(), &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV); } __forceinline void SetBufUAV(Uint32 Slot, RefCntAutoPtr&& pBuffView) { - auto pd3d11UAV = pBuffView ? static_cast(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; + auto* pd3d11UAV = pBuffView ? static_cast(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; SetD3D11ResourceInternal(Slot, GetUAVCount(), &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV); } __forceinline void SetSampler(Uint32 Slot, SamplerD3D11Impl* pSampler) { - auto *pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr; + auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr; SetD3D11ResourceInternal(Slot, GetSamplerCount(), &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); } @@ -162,47 +167,47 @@ public: __forceinline CachedCB& GetCB(Uint32 Slot) { - VERIFY(Slot < GetCBCount(), "CB slot is out of range" ); - ShaderResourceCacheD3D11::CachedCB *CBs; - ID3D11Buffer **pd3d11CBs; + VERIFY(Slot < GetCBCount(), "CB slot is out of range"); + ShaderResourceCacheD3D11::CachedCB* CBs; + ID3D11Buffer** pd3d11CBs; GetCBArrays(CBs, pd3d11CBs); return CBs[Slot]; } __forceinline CachedResource& GetSRV(Uint32 Slot) { - VERIFY(Slot < GetSRVCount(), "SRV slot is out of range" ); - ShaderResourceCacheD3D11::CachedResource *SRVResources; - ID3D11ShaderResourceView **pd3d11SRVs; + VERIFY(Slot < GetSRVCount(), "SRV slot is out of range"); + ShaderResourceCacheD3D11::CachedResource* SRVResources; + ID3D11ShaderResourceView** pd3d11SRVs; GetSRVArrays(SRVResources, pd3d11SRVs); return SRVResources[Slot]; } __forceinline CachedResource& GetUAV(Uint32 Slot) { - VERIFY(Slot < GetUAVCount(), "UAV slot is out of range" ); - ShaderResourceCacheD3D11::CachedResource *UAVResources; - ID3D11UnorderedAccessView **pd3d11UAVs; + VERIFY(Slot < GetUAVCount(), "UAV slot is out of range"); + ShaderResourceCacheD3D11::CachedResource* UAVResources; + ID3D11UnorderedAccessView** pd3d11UAVs; GetUAVArrays(UAVResources, pd3d11UAVs); return UAVResources[Slot]; } - + __forceinline CachedSampler& GetSampler(Uint32 Slot) { - VERIFY(Slot < GetSamplerCount(), "Sampler slot is out of range" ); - ShaderResourceCacheD3D11::CachedSampler *Samplers; - ID3D11SamplerState **pd3d11Samplers; + VERIFY(Slot < GetSamplerCount(), "Sampler slot is out of range"); + ShaderResourceCacheD3D11::CachedSampler* Samplers; + ID3D11SamplerState** pd3d11Samplers; GetSamplerArrays(Samplers, pd3d11Samplers); return Samplers[Slot]; } - __forceinline bool IsCBBound(Uint32 Slot)const + __forceinline bool IsCBBound(Uint32 Slot) const { - CachedCB* CBs = nullptr; + CachedCB* CBs = nullptr; ID3D11Buffer** d3d11CBs = nullptr; const_cast(this)->GetCBArrays(CBs, d3d11CBs); - if( Slot < GetCBCount() && d3d11CBs[Slot] != nullptr ) + if (Slot < GetCBCount() && d3d11CBs[Slot] != nullptr) { VERIFY(CBs[Slot].pBuff != nullptr, "No relevant buffer resource"); return true; @@ -210,40 +215,40 @@ public: return false; } - __forceinline bool IsSRVBound(Uint32 Slot, bool dbgIsTextureView)const + __forceinline bool IsSRVBound(Uint32 Slot, bool dbgIsTextureView) const { - CachedResource* SRVResources = nullptr; - ID3D11ShaderResourceView** d3d11SRVs = nullptr; + CachedResource* SRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; const_cast(this)->GetSRVArrays(SRVResources, d3d11SRVs); - if( Slot < GetSRVCount() && d3d11SRVs[Slot] != nullptr ) + if (Slot < GetSRVCount() && d3d11SRVs[Slot] != nullptr) { - VERIFY( ( dbgIsTextureView && SRVResources[Slot].pTexture != nullptr) || - (!dbgIsTextureView && SRVResources[Slot].pBuffer != nullptr), "No relevant resource"); + VERIFY((dbgIsTextureView && SRVResources[Slot].pTexture != nullptr) || (!dbgIsTextureView && SRVResources[Slot].pBuffer != nullptr), + "No relevant resource"); return true; } return false; } - __forceinline bool IsUAVBound(Uint32 Slot, bool dbgIsTextureView)const + __forceinline bool IsUAVBound(Uint32 Slot, bool dbgIsTextureView) const { - CachedResource* UAVResources = nullptr; - ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + CachedResource* UAVResources = nullptr; + ID3D11UnorderedAccessView** d3d11UAVs = nullptr; const_cast(this)->GetUAVArrays(UAVResources, d3d11UAVs); - if( Slot < GetUAVCount() && d3d11UAVs[Slot] != nullptr ) + if (Slot < GetUAVCount() && d3d11UAVs[Slot] != nullptr) { - VERIFY( ( dbgIsTextureView && UAVResources[Slot].pTexture != nullptr) || - (!dbgIsTextureView && UAVResources[Slot].pBuffer != nullptr), "No relevant resource"); + VERIFY((dbgIsTextureView && UAVResources[Slot].pTexture != nullptr) || (!dbgIsTextureView && UAVResources[Slot].pBuffer != nullptr), + "No relevant resource"); return true; } return false; } - __forceinline bool IsSamplerBound(Uint32 Slot)const + __forceinline bool IsSamplerBound(Uint32 Slot) const { - CachedSampler* Samplers = nullptr; + CachedSampler* Samplers = nullptr; ID3D11SamplerState** d3d11Samplers = nullptr; const_cast(this)->GetSamplerArrays(Samplers, d3d11Samplers); - if( Slot < GetSamplerCount() && d3d11Samplers[Slot] != nullptr ) + if (Slot < GetSamplerCount() && d3d11Samplers[Slot] != nullptr) { VERIFY(Samplers[Slot].pSampler != nullptr, "No relevant sampler"); return true; @@ -253,50 +258,48 @@ public: void dbgVerifyCacheConsistency(); - __forceinline Uint32 GetCBCount() const{ return (m_SRVOffset - m_CBOffset) / (sizeof(CachedCB) + sizeof(ID3D11Buffer*)); } - __forceinline Uint32 GetSRVCount() const{ return (m_SamplerOffset - m_SRVOffset) / (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)); } - __forceinline Uint32 GetSamplerCount()const{ return (m_UAVOffset - m_SamplerOffset) / (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)); } - __forceinline Uint32 GetUAVCount() const{ return (m_MemoryEndOffset - m_UAVOffset) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)); } + // clang-format off + __forceinline Uint32 GetCBCount() const { return (m_SRVOffset - m_CBOffset) / (sizeof(CachedCB) + sizeof(ID3D11Buffer*)); } + __forceinline Uint32 GetSRVCount() const { return (m_SamplerOffset - m_SRVOffset) / (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)); } + __forceinline Uint32 GetSamplerCount() const { return (m_UAVOffset - m_SamplerOffset) / (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)); } + __forceinline Uint32 GetUAVCount() const { return (m_MemoryEndOffset - m_UAVOffset) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)); } + // clang-format on - __forceinline void GetCBArrays(CachedCB* &CBs, ID3D11Buffer** &pd3d11CBs) + __forceinline void GetCBArrays(CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs) { - CBs = reinterpret_cast( m_pResourceData + m_CBOffset ); - pd3d11CBs = reinterpret_cast( CBs + GetCBCount() ); + CBs = reinterpret_cast(m_pResourceData + m_CBOffset); + pd3d11CBs = reinterpret_cast(CBs + GetCBCount()); } - __forceinline void GetSRVArrays(CachedResource* &SRVResources, ID3D11ShaderResourceView** &d3d11SRVs) + __forceinline void GetSRVArrays(CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs) { - SRVResources = reinterpret_cast( m_pResourceData + m_SRVOffset ); - d3d11SRVs = reinterpret_cast( SRVResources + GetSRVCount() ); + SRVResources = reinterpret_cast(m_pResourceData + m_SRVOffset); + d3d11SRVs = reinterpret_cast(SRVResources + GetSRVCount()); } - __forceinline void GetSamplerArrays(CachedSampler* &Samplers, ID3D11SamplerState** &pd3d11Samplers) + __forceinline void GetSamplerArrays(CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers) { - Samplers = reinterpret_cast( m_pResourceData + m_SamplerOffset ); - pd3d11Samplers = reinterpret_cast( Samplers + GetSamplerCount() ); + Samplers = reinterpret_cast(m_pResourceData + m_SamplerOffset); + pd3d11Samplers = reinterpret_cast(Samplers + GetSamplerCount()); } - __forceinline void GetUAVArrays(CachedResource* &UAVResources, ID3D11UnorderedAccessView** &pd3d11UAVs) + __forceinline void GetUAVArrays(CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs) { - UAVResources = reinterpret_cast( m_pResourceData + m_UAVOffset ); - pd3d11UAVs = reinterpret_cast( UAVResources + GetUAVCount() ); + UAVResources = reinterpret_cast(m_pResourceData + m_UAVOffset); + pd3d11UAVs = reinterpret_cast(UAVResources + GetUAVCount()); } - __forceinline bool IsInitialized()const + __forceinline bool IsInitialized() const { - return m_MemoryEndOffset != InvalidResourceOffset; + return m_MemoryEndOffset != InvalidResourceOffset; } private: - - template - __forceinline void SetD3D11ResourceInternal(Uint32 Slot, Uint32 Size, - TGetResourceArraysFunc GetArrays, - TSrcResourceType &&pResource, - TD3D11ResourceType *pd3d11Resource) + template + __forceinline void SetD3D11ResourceInternal(Uint32 Slot, Uint32 Size, TGetResourceArraysFunc GetArrays, TSrcResourceType&& pResource, TD3D11ResourceType* pd3d11Resource) { - VERIFY(Slot < Size, "Resource cache is not big enough" ); - VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr, + VERIFY(Slot < Size, "Resource cache is not big enough"); + VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr, "Resource and D3D11 resource must be set/unset atomically"); TCachedResourceType* Resources; TD3D11ResourceType** d3d11ResArr; @@ -311,11 +314,11 @@ private: // Max SRV count: 128 // Max Sampler count: 16 // Max UAV count: 8 - static constexpr const Uint16 m_CBOffset = 0; - Uint16 m_SRVOffset = InvalidResourceOffset; - Uint16 m_SamplerOffset = InvalidResourceOffset; - Uint16 m_UAVOffset = InvalidResourceOffset; - Uint16 m_MemoryEndOffset = InvalidResourceOffset; + static constexpr const Uint16 m_CBOffset = 0; + Uint16 m_SRVOffset = InvalidResourceOffset; + Uint16 m_SamplerOffset = InvalidResourceOffset; + Uint16 m_UAVOffset = InvalidResourceOffset; + Uint16 m_MemoryEndOffset = InvalidResourceOffset; Uint8* m_pResourceData = nullptr; @@ -324,4 +327,4 @@ private: #endif }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 84caeaa8..4bb588aa 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -48,107 +48,112 @@ public: ShaderResourceLayoutD3D11(IObject& Owner, std::shared_ptr pSrcResources, const PipelineResourceLayoutDesc& ResourceLayout, - const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, + Uint32 NumVarTypes, ShaderResourceCacheD3D11& ResourceCache, IMemoryAllocator& ResCacheDataAllocator, IMemoryAllocator& ResLayoutDataAllocator); ~ShaderResourceLayoutD3D11(); + // clang-format off // No copies, only moves are allowed ShaderResourceLayoutD3D11 (const ShaderResourceLayoutD3D11&) = delete; ShaderResourceLayoutD3D11& operator = (const ShaderResourceLayoutD3D11&) = delete; ShaderResourceLayoutD3D11 ( ShaderResourceLayoutD3D11&&) = default; ShaderResourceLayoutD3D11& operator = ( ShaderResourceLayoutD3D11&&) = delete; + // clang-format on - static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, + static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes); - void CopyResources(ShaderResourceCacheD3D11& DstCache)const; + void CopyResources(ShaderResourceCacheD3D11& DstCache) const; using ShaderVariableD3D11Base = ShaderVariableD3DBase; struct ConstBuffBindInfo final : ShaderVariableD3D11Base { - ConstBuffBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) + ConstBuffBindInfo(const D3DShaderResourceAttribs& ResourceAttribs, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base{ParentResLayout, ResourceAttribs, VariableType} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - virtual bool IsBound(Uint32 ArrayIndex)const override final + virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsCBBound(m_Attribs.BindPoint + ArrayIndex); } }; - + struct TexSRVBindInfo final : ShaderVariableD3D11Base { - TexSRVBindInfo( const D3DShaderResourceAttribs& _TextureAttribs, - Uint32 _SamplerIndex, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs, VariableType), - SamplerIndex(_SamplerIndex) + TexSRVBindInfo(const D3DShaderResourceAttribs& _TextureAttribs, + Uint32 _SamplerIndex, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base{ParentResLayout, _TextureAttribs, VariableType}, + SamplerIndex{_SamplerIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - virtual bool IsBound(Uint32 ArrayIndex)const override final + virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsSRVBound(m_Attribs.BindPoint + ArrayIndex, true); } - - bool ValidSamplerAssigned() const {return SamplerIndex != InvalidSamplerIndex;} + + bool ValidSamplerAssigned() const { return SamplerIndex != InvalidSamplerIndex; } static constexpr Uint32 InvalidSamplerIndex = static_cast(-1); - const Uint32 SamplerIndex; + const Uint32 SamplerIndex; }; struct TexUAVBindInfo final : ShaderVariableD3D11Base { - TexUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + TexUAVBindInfo(const D3DShaderResourceAttribs& ResourceAttribs, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Provide non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - __forceinline virtual bool IsBound(Uint32 ArrayIndex)const override final + __forceinline virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsUAVBound(m_Attribs.BindPoint + ArrayIndex, true); @@ -157,51 +162,52 @@ public: struct BuffUAVBindInfo final : ShaderVariableD3D11Base { - BuffUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) + BuffUAVBindInfo(const D3DShaderResourceAttribs& ResourceAttribs, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base{ParentResLayout, ResourceAttribs, VariableType} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - virtual bool IsBound(Uint32 ArrayIndex)const override final + virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsUAVBound(m_Attribs.BindPoint + ArrayIndex, false); } - }; struct BuffSRVBindInfo final : ShaderVariableD3D11Base { - BuffSRVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) + BuffSRVBindInfo(const D3DShaderResourceAttribs& ResourceAttribs, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base{ParentResLayout, ResourceAttribs, VariableType} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - virtual bool IsBound(Uint32 ArrayIndex)const override final + virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsSRVBound(m_Attribs.BindPoint + ArrayIndex, false); @@ -210,24 +216,25 @@ public: struct SamplerBindInfo final : ShaderVariableD3D11Base { - SamplerBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) + SamplerBindInfo(const D3DShaderResourceAttribs& ResourceAttribs, + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base{ParentResLayout, ResourceAttribs, VariableType} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void Set(IDeviceObject* pObject)override final{ BindResource(pObject, 0); } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final + virtual void Set(IDeviceObject* pObject) override final { BindResource(pObject, 0); } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final { VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.BindCount, FirstElement, NumElements); - for(Uint32 elem=0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement+elem); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); } - virtual bool IsBound(Uint32 ArrayIndex)const override final + virtual bool IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < m_Attribs.BindCount); return m_ParentResLayout.m_ResourceCache.IsSamplerBound(m_Attribs.BindPoint + ArrayIndex); @@ -236,20 +243,20 @@ public: // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive // while Layout is alive - void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache ); - + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache); + #ifdef DEVELOPMENT - bool dvpVerifyBindings()const; + bool dvpVerifyBindings() const; #endif - IShaderResourceVariable* GetShaderVariable( const Char* Name ); - IShaderResourceVariable* GetShaderVariable( Uint32 Index ); - __forceinline SHADER_TYPE GetShaderType()const{return m_pResources->GetShaderType();} + IShaderResourceVariable* GetShaderVariable(const Char* Name); + IShaderResourceVariable* GetShaderVariable(Uint32 Index); + __forceinline SHADER_TYPE GetShaderType() const { return m_pResources->GetShaderType(); } - IObject& GetOwner(){return m_Owner;} + IObject& GetOwner() { return m_Owner; } - Uint32 GetVariableIndex(const ShaderVariableD3D11Base& Variable)const; - Uint32 GetTotalResourceCount()const + Uint32 GetVariableIndex(const ShaderVariableD3D11Base& Variable) const; + Uint32 GetTotalResourceCount() const { auto ResourceCount = GetNumCBs() + GetNumTexSRVs() + GetNumTexUAVs() + GetNumBufUAVs() + GetNumBufSRVs(); // Do not expose sampler variables when using combined texture samplers @@ -258,6 +265,7 @@ public: return ResourceCount; } + // clang-format off Uint32 GetNumCBs() const { return (m_TexSRVsOffset - 0 ) / sizeof(ConstBuffBindInfo);} Uint32 GetNumTexSRVs() const { return (m_TexUAVsOffset - m_TexSRVsOffset ) / sizeof(TexSRVBindInfo); } Uint32 GetNumTexUAVs() const { return (m_BuffSRVsOffset - m_TexUAVsOffset ) / sizeof(TexUAVBindInfo) ; } @@ -272,13 +280,15 @@ public: template<> Uint32 GetNumResources () const { return GetNumBufSRVs(); } template<> Uint32 GetNumResources () const { return GetNumBufUAVs(); } template<> Uint32 GetNumResources () const { return GetNumSamplers(); } + // clang-format on - const Char* GetShaderName()const + const Char* GetShaderName() const { return m_pResources->GetShaderName(); } private: + // clang-format off /* 0 */ IObject& m_Owner; /* 8 */ std::shared_ptr m_pResources; @@ -309,31 +319,33 @@ private: template<> OffsetType GetResourceOffset () const { return m_BuffUAVsOffset; } template<> OffsetType GetResourceOffset () const { return m_SamplerOffset; } - template + // clang-format on + + template ResourceType& GetResource(Uint32 ResIndex) { - VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources()-1, ")"); + VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources() - 1, ")"); auto Offset = GetResourceOffset(); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; } - - template - const ResourceType& GetConstResource(Uint32 ResIndex)const + + template + const ResourceType& GetConstResource(Uint32 ResIndex) const { - VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources()-1, ")"); + VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources() - 1, ")"); auto Offset = GetResourceOffset(); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; } - - template - IShaderResourceVariable* GetResourceByName( const Char* Name ); - - template + + template + IShaderResourceVariable* GetResourceByName(const Char* Name); + + template void HandleResources(THandleCB HandleCB, THandleTexSRV HandleTexSRV, THandleTexUAV HandleTexUAV, @@ -360,18 +372,18 @@ private: HandleSampler(GetResource(s)); } - template + template void HandleConstResources(THandleCB HandleCB, THandleTexSRV HandleTexSRV, THandleTexUAV HandleTexUAV, THandleBufSRV HandleBufSRV, THandleBufUAV HandleBufUAV, - THandleSampler HandleSampler)const + THandleSampler HandleSampler) const { for (Uint32 cb = 0; cb < GetNumResources(); ++cb) HandleCB(GetConstResource(cb)); @@ -396,4 +408,4 @@ private: friend class ShaderVariableLocator; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h index e028371a..badf141d 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h @@ -40,33 +40,33 @@ // | | unique_ptr | | | | | | | // | ShaderResourcesD3D11 |--------------->| CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | // |______________________| |________|___________|___________|___________|___________|____________| -// A A A A A A A +// A A A A A A A // | \ \ \ \ \ \ -// |shared_ptr Ref Ref Ref Ref Ref Ref +// |shared_ptr Ref Ref Ref Ref Ref Ref // ________|__________________ ____\_________\__________\__________\___________\_______ ___\______ // | | unique_ptr | | | | | | | // | ShaderResourceLayoutD3D11 |--------------->| CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | // |___________________________| |________|___________|___________|___________|___________|__________| -// | A +// | A // |_________________SamplerIndex_________________| -// +// // // One ShaderResourcesD3D11 instance can be referenced by multiple objects // // -// _______ ________________________________ +// _______ ________________________________ // | | | | // ----| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl | // | |___________________________| |________________________________| // | // | -// _________________ ______________________ | _______ ________________________________ +// _________________ ______________________ | _______ ________________________________ // | | shared_ptr | | shared_ptr| | | | | // | ShaderD3D11Impl |--------------->| ShaderResourcesD3D11 |<---------------| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl | // |_________________| |______________________| | |___________________________| |________________________________| // A | // | | -// __________ | | _______ ________________________________ +// __________ | | _______ ________________________________ // | | shared_ptr | | | | | | // | ShaderResourceLayoutD3D11 |------------------- ----| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl | // |___________________________| |___________________________| |________________________________| @@ -95,6 +95,7 @@ public: const char* CombinedSamplerSuffix); ~ShaderResourcesD3D11(); + // clang-format off ShaderResourcesD3D11 (const ShaderResourcesD3D11&) = delete; ShaderResourcesD3D11 ( ShaderResourcesD3D11&&) = delete; ShaderResourcesD3D11& operator = (const ShaderResourcesD3D11&) = delete; @@ -104,21 +105,23 @@ public: __forceinline Int32 GetMaxSRVBindPoint() const { return m_MaxSRVBindPoint; } __forceinline Int32 GetMaxSamplerBindPoint()const { return m_MaxSamplerBindPoint; } __forceinline Int32 GetMaxUAVBindPoint() const { return m_MaxUAVBindPoint; } + // clang-format on #ifdef DEVELOPMENT - void dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[], - ID3D11ShaderResourceView* CommittedD3D11SRVs[], - ID3D11Resource* CommittedD3D11SRVResources[], - ID3D11SamplerState* CommittedD3D11Samplers[], - ID3D11UnorderedAccessView* CommittedD3D11UAVs[], - ID3D11Resource* CommittedD3D11UAVResources[], - class ShaderResourceCacheD3D11& ResourceCache)const; + void dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[], + ID3D11ShaderResourceView* CommittedD3D11SRVs[], + ID3D11Resource* CommittedD3D11SRVResources[], + ID3D11SamplerState* CommittedD3D11Samplers[], + ID3D11UnorderedAccessView* CommittedD3D11UAVs[], + ID3D11Resource* CommittedD3D11UAVResources[], + class ShaderResourceCacheD3D11& ResourceCache) const; #endif - + private: using MaxBindPointType = Int8; + // clang-format off MaxBindPointType m_MaxCBBindPoint = -1; // Max == 13 MaxBindPointType m_MaxSRVBindPoint = -1; // Max == 127 MaxBindPointType m_MaxSamplerBindPoint = -1; // Max == 15 @@ -129,6 +132,7 @@ private: static_assert(D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max SRV slot"); static_assert(D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max Sampler slot"); static_assert(D3D11_PS_CS_UAV_REGISTER_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max UAV slot"); + // clang-format on }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h index 7d3f46b8..3ee493dd 100644 --- a/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h @@ -41,36 +41,36 @@ public: using TSwapChainBase = SwapChainD3DBase; SwapChainD3D11Impl(IReferenceCounters* pRefCounters, - const SwapChainDesc& SCDesc, + const SwapChainDesc& SCDesc, const FullScreenModeDesc& FSDesc, class RenderDeviceD3D11Impl* pRenderDeviceD3D11, class DeviceContextD3D11Impl* pDeviceContextD3D11, void* pNativeWndHandle); ~SwapChainD3D11Impl(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of ISwapChain::Present() in Direct3D11 backend. - virtual void Present(Uint32 SyncInterval)override final; + virtual void Present(Uint32 SyncInterval) override final; /// Implementation of ISwapChain::Resize() in Direct3D11 backend. - virtual void Resize(Uint32 NewWidth, Uint32 NewHeight)override final; + virtual void Resize(Uint32 NewWidth, Uint32 NewHeight) override final; /// Implementation of ISwapChainD3D11::GetDXGISwapChain() in Direct3D11 backend. - virtual IDXGISwapChain* GetDXGISwapChain()override final{ return m_pSwapChain; } + virtual IDXGISwapChain* GetDXGISwapChain() override final { return m_pSwapChain; } /// Implementation of ISwapChainD3D11::GetCurrentBackBufferRTV() in Direct3D11 backend. - virtual ITextureViewD3D11* GetCurrentBackBufferRTV()override final{return m_pRenderTargetView;} + virtual ITextureViewD3D11* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } /// Implementation of ISwapChainD3D11::GetDepthBufferDSV() in Direct3D11 backend. - virtual ITextureViewD3D11* GetDepthBufferDSV() override final{return m_pDepthStencilView;} + virtual ITextureViewD3D11* GetDepthBufferDSV() override final { return m_pDepthStencilView; } private: - virtual void UpdateSwapChain(bool CreateNew)override final; - void CreateRTVandDSV(); + virtual void UpdateSwapChain(bool CreateNew) override final; + void CreateRTVandDSV(); RefCntAutoPtr m_pRenderTargetView; RefCntAutoPtr m_pDepthStencilView; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h index 9bc827e9..79527e18 100644 --- a/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h @@ -35,24 +35,26 @@ namespace Diligent class Texture1D_D3D11 final : public TextureBaseD3D11 { public: - Texture1D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const TextureDesc& TexDesc, + Texture1D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const TextureDesc& TexDesc, const TextureData* pInitData = nullptr); - Texture1D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, + Texture1D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, RESOURCE_STATE InitialState, ID3D11Texture1D* pd3d11Texture); ~Texture1D_D3D11(); protected: - virtual void CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV )override final; - virtual void CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV )override final; - virtual void CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV )override final; - virtual void CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV )override final; + // clang-format off + virtual void CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) override final; + virtual void CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) override final; + virtual void CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) override final; + virtual void CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) override final; + // clang-format on }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h index 9bcbd3a4..84a48fc3 100644 --- a/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h @@ -35,24 +35,26 @@ namespace Diligent class Texture2D_D3D11 final : public TextureBaseD3D11 { public: - Texture2D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const TextureDesc& TexDesc, + Texture2D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const TextureDesc& TexDesc, const TextureData* pInitData = nullptr); - Texture2D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, + Texture2D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, RESOURCE_STATE InitialState, ID3D11Texture2D* pd3d11Texture); ~Texture2D_D3D11(); protected: - virtual void CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV )override final; - virtual void CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV )override final; - virtual void CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV )override final; - virtual void CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV )override final; + // clang-format off + virtual void CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) override final; + virtual void CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) override final; + virtual void CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) override final; + virtual void CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) override final; + // clang-format on }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h index 2ccbfb4f..ffef6f4e 100644 --- a/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h @@ -36,23 +36,25 @@ class Texture3D_D3D11 final : public TextureBaseD3D11 { public: Texture3D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const TextureDesc& TexDesc, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const TextureDesc& TexDesc, const TextureData* pInitData = nullptr); - Texture3D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, + Texture3D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, RESOURCE_STATE InitialState, ID3D11Texture3D* pd3d11Texture); ~Texture3D_D3D11(); protected: - virtual void CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV )override final; - virtual void CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV )override final; - virtual void CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV )override final; - virtual void CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV )override final; + // clang-format off + virtual void CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) override final; + virtual void CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) override final; + virtual void CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) override final; + virtual void CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) override final; + // clang-format on }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h index ca76b4d4..07bcb9a6 100644 --- a/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h @@ -45,19 +45,19 @@ public: using ViewImplType = TextureViewD3D11Impl; TextureBaseD3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const TextureDesc& TexDesc, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const TextureDesc& TexDesc, const TextureData* pInitData = nullptr); ~TextureBaseD3D11(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of ITextureD3D11::GetD3D11Texture(). - virtual ID3D11Resource* GetD3D11Texture()override final{ return m_pd3d11Texture; } + virtual ID3D11Resource* GetD3D11Texture() override final { return m_pd3d11Texture; } /// Implementation of ITexture::GetNativeHandle(). - virtual void* GetNativeHandle()override final { return GetD3D11Texture(); } + virtual void* GetNativeHandle() override final { return GetD3D11Texture(); } void AddState(RESOURCE_STATE State) { @@ -74,19 +74,21 @@ public: } protected: - void CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView )override final; - void PrepareD3D11InitData(const TextureData* pInitData, - Uint32 NumSubresources, - std::vector >& D3D11InitData); - - virtual void CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV ) = 0; - virtual void CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV ) = 0; - virtual void CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV ) = 0; - virtual void CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ) = 0; + void CreateViewInternal(const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView) override final; + void PrepareD3D11InitData(const TextureData* pInitData, + Uint32 NumSubresources, + std::vector>& D3D11InitData); + + // clang-format off + virtual void CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) = 0; + virtual void CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) = 0; + virtual void CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) = 0; + virtual void CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) = 0; + // clang-format on friend class RenderDeviceD3D11Impl; /// D3D11 texture CComPtr m_pd3d11Texture; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h index c7883c64..7c06bce2 100644 --- a/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h @@ -42,24 +42,24 @@ class TextureViewD3D11Impl final : public TextureViewBase; - TextureViewD3D11Impl( IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - const TextureViewDesc& ViewDesc, - class ITexture* pTexture, - ID3D11View* pD3D11View, - bool bIsDefaultView); + TextureViewD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + const TextureViewDesc& ViewDesc, + class ITexture* pTexture, + ID3D11View* pD3D11View, + bool bIsDefaultView); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; /// Implementation of ITextureViewD3D11::GetD3D11View(). - virtual ID3D11View* GetD3D11View()override final + virtual ID3D11View* GetD3D11View() override final { return m_pD3D11View; } - + private: /// D3D11 view CComPtr m_pD3D11View; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/pch.h b/Graphics/GraphicsEngineD3D11/include/pch.h index a181b137..8b5b26f3 100644 --- a/Graphics/GraphicsEngineD3D11/include/pch.h +++ b/Graphics/GraphicsEngineD3D11/include/pch.h @@ -31,11 +31,11 @@ #include "targetver.h" #ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #endif #ifndef NOMINMAX -# define NOMINMAX +# define NOMINMAX #endif #include "PlatformDefinitions.h" @@ -45,25 +45,25 @@ #include #if PLATFORM_WIN32 -# ifndef D3D11_VERSION -# define D3D11_VERSION 0 -# endif +# ifndef D3D11_VERSION +# define D3D11_VERSION 0 +# endif #elif PLATFORM_UNIVERSAL_WINDOWS -# ifndef D3D11_VERSION -# define D3D11_VERSION 2 -# endif +# ifndef D3D11_VERSION +# define D3D11_VERSION 2 +# endif #endif #if D3D11_VERSION == 0 -# include +# include #elif D3D11_VERSION == 1 -# include +# include #elif D3D11_VERSION == 2 -# include +# include #elif D3D11_VERSION == 3 -# include +# include #elif D3D11_VERSION == 4 -# include +# include #endif #include "EngineD3D11Defines.h" diff --git a/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h b/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h index 81132133..19b31b9f 100644 --- a/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {4A696D2E-44BB-4C4B-9DE2-3AF7C94DCFC0} static constexpr INTERFACE_ID IID_BufferD3D11 = -{ 0x4a696d2e, 0x44bb, 0x4c4b, { 0x9d, 0xe2, 0x3a, 0xf7, 0xc9, 0x4d, 0xcf, 0xc0 } }; + {0x4a696d2e, 0x44bb, 0x4c4b, {0x9d, 0xe2, 0x3a, 0xf7, 0xc9, 0x4d, 0xcf, 0xc0}}; /// Exposes Direct3D11-specific functionality of a buffer object. class IBufferD3D11 : public IBuffer { public: - /// Returns a pointer to the ID3D11Buffer interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11Buffer* GetD3D11Buffer() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h b/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h index 701e5df8..740f352a 100644 --- a/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {6ABA95FC-CD7D-4C03-8CAE-AFC45F9696B7} static constexpr INTERFACE_ID IID_BufferViewD3D11 = -{ 0x6aba95fc, 0xcd7d, 0x4c03, { 0x8c, 0xae, 0xaf, 0xc4, 0x5f, 0x96, 0x96, 0xb7 } }; + {0x6aba95fc, 0xcd7d, 0x4c03, {0x8c, 0xae, 0xaf, 0xc4, 0x5f, 0x96, 0x96, 0xb7}}; /// Exposes Direct3D11-specific functionality of a buffer view object. class IBufferViewD3D11 : public IBufferView { public: - /// Returns a pointer to the ID3D11View interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11View* GetD3D11View() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h b/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h index 948bac58..d46c375b 100644 --- a/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {F0EE0335-C8AB-4EC1-BB15-B8EE5F003B99} static constexpr INTERFACE_ID IID_DeviceContextD3D11 = -{ 0xf0ee0335, 0xc8ab, 0x4ec1, { 0xbb, 0x15, 0xb8, 0xee, 0x5f, 0x0, 0x3b, 0x99 } }; + {0xf0ee0335, 0xc8ab, 0x4ec1, {0xbb, 0x15, 0xb8, 0xee, 0x5f, 0x0, 0x3b, 0x99}}; /// Exposes Direct3D11-specific functionality of a device context. class IDeviceContextD3D11 : public IDeviceContext { public: - /// Returns a pointer to the ID3D11DeviceContext interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11DeviceContext* GetD3D11DeviceContext() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h index fb658ebe..e357bc05 100644 --- a/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h @@ -34,15 +34,15 @@ #include "../../GraphicsEngine/interface/SwapChain.h" #if PLATFORM_UNIVERSAL_WINDOWS && defined(ENGINE_DLL) -# include "../../../Common/interface/StringTools.h" +# include "../../../Common/interface/StringTools.h" #endif namespace Diligent { // {62663A30-AAF0-4A9A-9729-9EAC6BF789F2} -static const INTERFACE_ID IID_EngineFactoryD3D11 = -{ 0x62663a30, 0xaaf0, 0x4a9a, { 0x97, 0x29, 0x9e, 0xac, 0x6b, 0xf7, 0x89, 0xf2 } }; +static const INTERFACE_ID IID_EngineFactoryD3D11 = + {0x62663a30, 0xaaf0, 0x4a9a, {0x97, 0x29, 0x9e, 0xac, 0x6b, 0xf7, 0x89, 0xf2}}; /// Engine factory for Direct3D11 rendering backend. class IEngineFactoryD3D11 : public IEngineFactory @@ -51,14 +51,14 @@ public: /// Creates a render device and device contexts for Direct3D11-based engine implementation. /// \param [in] EngineCI - Engine creation info. - /// \param [out] ppDevice - Address of the memory location where pointer to + /// \param [out] ppDevice - Address of the memory location where pointer to /// the created device will be written. - /// \param [out] ppContexts - Address of the memory location where pointers to + /// \param [out] ppContexts - Address of the memory location where pointers to /// the contexts will be written. Immediate context goes at /// position 0. If EngineCI.NumDeferredContexts > 0, /// pointers to deferred contexts are written afterwards. - virtual void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, + virtual void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, IDeviceContext** ppContexts) = 0; @@ -68,19 +68,19 @@ public: /// \param [in] pImmediateContext - Pointer to the immediate device context. /// \param [in] SCDesc - Swap chain description. /// \param [in] FSDesc - Fullscreen mode description. - /// \param [in] pNativeWndHandle - Platform-specific native handle of the window + /// \param [in] pNativeWndHandle - Platform-specific native handle of the window /// the swap chain will be associated with: /// * On Win32 platform, this should be the window handle (HWND) - /// * On Universal Windows Platform, this should be the reference + /// * On Universal Windows Platform, this should be the reference /// to the core window (Windows::UI::Core::CoreWindow) - /// - /// \param [out] ppSwapChain - Address of the memory location where pointer to the new + /// + /// \param [out] ppSwapChain - Address of the memory location where pointer to the new /// swap chain will be written. - virtual void CreateSwapChainD3D11( IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SCDesc, + virtual void CreateSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pImmediateContext, + const SwapChainDesc& SCDesc, const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, + void* pNativeWndHandle, ISwapChain** ppSwapChain) = 0; @@ -89,17 +89,17 @@ public: /// \param [in] pd3d11NativeDevice - pointer to the native Direct3D11 device. /// \param [in] pd3d11ImmediateContext - pointer to the native Direct3D11 immediate context. /// \param [in] EngineCI - Engine creation info. - /// \param [out] ppDevice - Address of the memory location where pointer to + /// \param [out] ppDevice - Address of the memory location where pointer to /// the created device will be written. - /// \param [out] ppContexts - Address of the memory location where pointers to + /// \param [out] ppContexts - Address of the memory location where pointers to /// the contexts will be written. Immediate context goes at /// position 0. If EngineCI.NumDeferredContexts > 0, /// pointers to the deferred contexts are written afterwards. - virtual void AttachToD3D11Device(void* pd3d11NativeDevice, - void* pd3d11ImmediateContext, - const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts) = 0; + virtual void AttachToD3D11Device(void* pd3d11NativeDevice, + void* pd3d11ImmediateContext, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts) = 0; /// Enumerates hardware adapters available on this machine. @@ -108,7 +108,7 @@ public: /// \param [in,out] NumAdapters - Number of adapters. If Adapters is null, this value /// will be overwritten with the number of adapters available /// on this system. If Adapters is not null, this value should - /// contain the maximum number of elements reserved in the array + /// contain the maximum number of elements reserved in the array /// pointed to by Adapters. In the latter case, this value /// is overwritten with the actual number of elements written to /// Adapters. @@ -116,7 +116,7 @@ public: /// null is provided, the number of available adapters is /// written to NumAdapters. virtual void EnumerateHardwareAdapters(DIRECT3D_FEATURE_LEVEL MinFeatureLevel, - Uint32& NumAdapters, + Uint32& NumAdapters, HardwareAdapterAttribs* Adapters) = 0; @@ -127,72 +127,72 @@ public: /// \param [in] OutputId - Adapter output id. /// \param [in] Format - Display mode format. /// \param [in, out] NumDisplayModes - Number of display modes. If DisplayModes is null, this - /// value is overwritten with the number of display modes + /// value is overwritten with the number of display modes /// available for this output. If DisplayModes is not null, /// this value should contain the maximum number of elements /// to be written to DisplayModes array. It is overwritten with /// the actual number of display modes written. virtual void EnumerateDisplayModes(DIRECT3D_FEATURE_LEVEL MinFeatureLevel, - Uint32 AdapterId, - Uint32 OutputId, - TEXTURE_FORMAT Format, - Uint32& NumDisplayModes, + Uint32 AdapterId, + Uint32 OutputId, + TEXTURE_FORMAT Format, + Uint32& NumDisplayModes, DisplayModeAttribs* DisplayModes) = 0; }; #if ENGINE_DLL - typedef IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)(); +typedef IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)(); - static bool LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type &GetFactoryFunc) +static bool LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type& GetFactoryFunc) +{ + GetFactoryFunc = nullptr; + std::string LibName = "GraphicsEngineD3D11_"; + +# if _WIN64 + LibName += "64"; +# else + LibName += "32"; +# endif + +# ifdef _DEBUG + LibName += "d"; +# else + LibName += "r"; +# endif + + LibName += ".dll"; +# if PLATFORM_WIN32 + auto hModule = LoadLibraryA(LibName.c_str()); +# elif PLATFORM_UNIVERSAL_WINDOWS + auto hModule = LoadPackagedLibrary(WidenString(LibName).c_str(), 0); +# else +# error Unexpected platform +# endif + if (hModule == NULL) { - GetFactoryFunc = nullptr; - std::string LibName = "GraphicsEngineD3D11_"; - -#if _WIN64 - LibName += "64"; -#else - LibName += "32"; -#endif - -#ifdef _DEBUG - LibName += "d"; -#else - LibName += "r"; -#endif + std::stringstream ss; + ss << "Failed to load " << LibName << " library.\n"; + OutputDebugStringA(ss.str().c_str()); + return false; + } - LibName += ".dll"; -#if PLATFORM_WIN32 - auto hModule = LoadLibraryA( LibName.c_str() ); -#elif PLATFORM_UNIVERSAL_WINDOWS - auto hModule = LoadPackagedLibrary(WidenString(LibName).c_str(), 0); -#else -# error Unexpected platform -#endif - if( hModule == NULL ) - { - std::stringstream ss; - ss << "Failed to load " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - return false; - } - - GetFactoryFunc = reinterpret_cast( GetProcAddress(hModule, "GetEngineFactoryD3D11") ); - if( GetFactoryFunc == NULL ) - { - std::stringstream ss; - ss << "Failed to load GetEngineFactoryD3D11() from " << LibName << " library.\n"; - OutputDebugStringA(ss.str().c_str()); - FreeLibrary( hModule ); - return false; - } - - return true; + GetFactoryFunc = reinterpret_cast(GetProcAddress(hModule, "GetEngineFactoryD3D11")); + if (GetFactoryFunc == NULL) + { + std::stringstream ss; + ss << "Failed to load GetEngineFactoryD3D11() from " << LibName << " library.\n"; + OutputDebugStringA(ss.str().c_str()); + FreeLibrary(hModule); + return false; } + + return true; +} #else - IEngineFactoryD3D11* GetEngineFactoryD3D11(); +IEngineFactoryD3D11* GetEngineFactoryD3D11(); #endif -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h b/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h index 4d88ffdc..e5729252 100644 --- a/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h @@ -33,14 +33,12 @@ namespace Diligent // {45F2BE28-652B-4180-B6E4-E75F83F63CC7} static constexpr INTERFACE_ID IID_FenceD3D11 = -{ 0x45f2be28, 0x652b, 0x4180, { 0xb6, 0xe4, 0xe7, 0x5f, 0x83, 0xf6, 0x3c, 0xc7 } }; + {0x45f2be28, 0x652b, 0x4180, {0xb6, 0xe4, 0xe7, 0x5f, 0x83, 0xf6, 0x3c, 0xc7}}; /// Exposes Direct3D11-specific functionality of a fence object. class IFenceD3D11 : public IFence { -public: - }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/PipelineStateD3D11.h b/Graphics/GraphicsEngineD3D11/interface/PipelineStateD3D11.h index 1f689a86..cc97ede1 100644 --- a/Graphics/GraphicsEngineD3D11/interface/PipelineStateD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/PipelineStateD3D11.h @@ -32,21 +32,20 @@ namespace Diligent { // {3EA6E3F4-9966-47FC-8CE8-0EB3E2273061} -static constexpr INTERFACE_ID IID_PipelineStateD3D11 = -{ 0x3ea6e3f4, 0x9966, 0x47fc, { 0x8c, 0xe8, 0xe, 0xb3, 0xe2, 0x27, 0x30, 0x61 } }; +static constexpr INTERFACE_ID IID_PipelineStateD3D11 = + {0x3ea6e3f4, 0x9966, 0x47fc, {0x8c, 0xe8, 0xe, 0xb3, 0xe2, 0x27, 0x30, 0x61}}; /// Exposes Direct3D11-specific functionality of a pipeline state object. class IPipelineStateD3D11 : public IPipelineState { public: - /// Returns a pointer to the ID3D11BlendState interface of the internal Direct3D11 object. - + /// The method does *NOT* call AddRef() on the returned interface, /// so Release() must not be called. virtual ID3D11BlendState* GetD3D11BlendState() = 0; - + /// Returns a pointer to the ID3D11RasterizerState interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -84,7 +83,7 @@ public: /// The method does *NOT* call AddRef() on the returned interface, /// so Release() must not be called. virtual ID3D11GeometryShader* GetD3D11GeometryShader() = 0; - + /// Returns a pointer to the ID3D11DomainShader interface of the internal domain shader object. /// The method does *NOT* call AddRef() on the returned interface, @@ -104,4 +103,4 @@ public: virtual ID3D11ComputeShader* GetD3D11ComputeShader() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h index 91c70a3a..99aaed0d 100644 --- a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {05B1CBB8-FCAD-49EE-BADA-7801223EC3FE} static constexpr INTERFACE_ID IID_RenderDeviceD3D11 = -{ 0x5b1cbb8, 0xfcad, 0x49ee, { 0xba, 0xda, 0x78, 0x1, 0x22, 0x3e, 0xc3, 0xfe } }; + {0x5b1cbb8, 0xfcad, 0x49ee, {0xba, 0xda, 0x78, 0x1, 0x22, 0x3e, 0xc3, 0xfe}}; /// Exposes Direct3D11-specific functionality of a render device. class IRenderDeviceD3D11 : public IRenderDevice { public: - /// Returns a pointer to the ID3D11Device interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -49,14 +48,14 @@ public: /// Creates a buffer object from native d3d11 buffer /// \param [in] pd3d11Buffer - Pointer to the native buffer - /// \param [in] BuffDesc - Buffer description. Most of the fields will be - /// populated automatically if left in default values. + /// \param [in] BuffDesc - Buffer description. Most of the fields will be + /// populated automatically if left in default values. /// The only field that must be populated is BufferDesc::Format, /// when initializing a formatted buffer. /// \param [in] InitialState - Initial buffer state. See Diligent::RESOURCE_STATE. /// \param [out] ppBuffer - Address of the memory location where the pointer to the - /// buffer interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// buffer interface will be stored. + /// The function calls AddRef(), so that the new object will contain /// one reference. virtual void CreateBufferFromD3DResource(ID3D11Buffer* pd3d11Buffer, const BufferDesc& BuffDesc, @@ -68,8 +67,8 @@ public: /// \param [in] pd3d11Texture - pointer to the native 1D texture /// \param [in] InitialState - Initial texture state. See Diligent::RESOURCE_STATE. /// \param [out] ppTexture - Address of the memory location where the pointer to the - /// texture interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// texture interface will be stored. + /// The function calls AddRef(), so that the new object will contain /// one reference. virtual void CreateTextureFromD3DResource(ID3D11Texture1D* pd3d11Texture, RESOURCE_STATE InitialState, @@ -80,8 +79,8 @@ public: /// \param [in] pd3d11Texture - pointer to the native 2D texture /// \param [in] InitialState - Initial texture state. See Diligent::RESOURCE_STATE. /// \param [out] ppTexture - Address of the memory location where the pointer to the - /// texture interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// texture interface will be stored. + /// The function calls AddRef(), so that the new object will contain /// one reference. virtual void CreateTextureFromD3DResource(ID3D11Texture2D* pd3d11Texture, RESOURCE_STATE InitialState, @@ -92,13 +91,12 @@ public: /// \param [in] pd3d11Texture - pointer to the native 3D texture /// \param [in] InitialState - Initial texture state. See Diligent::RESOURCE_STATE. /// \param [out] ppTexture - Address of the memory location where the pointer to the - /// texture interface will be stored. - /// The function calls AddRef(), so that the new object will contain + /// texture interface will be stored. + /// The function calls AddRef(), so that the new object will contain /// one reference. virtual void CreateTextureFromD3DResource(ID3D11Texture3D* pd3d11Texture, RESOURCE_STATE InitialState, - ITexture** ppTexture) = 0; - + ITexture** ppTexture) = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h b/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h index 9baa298e..154459cd 100644 --- a/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h @@ -33,18 +33,17 @@ namespace Diligent // {31A3BFAF-738E-4D8C-AD18-B021C5D948DD} static constexpr INTERFACE_ID IID_SamplerD3D11 = -{ 0x31a3bfaf, 0x738e, 0x4d8c, { 0xad, 0x18, 0xb0, 0x21, 0xc5, 0xd9, 0x48, 0xdd } }; + {0x31a3bfaf, 0x738e, 0x4d8c, {0xad, 0x18, 0xb0, 0x21, 0xc5, 0xd9, 0x48, 0xdd}}; /// Exposes Direct3D11-specific functionality of a sampler object. class ISamplerD3D11 : public ISampler { public: - /// Returns a pointer to the ID3D11SamplerState interface of the internal Direct3D11 object. - + /// The method does *NOT* call AddRef() on the returned interface, /// so Release() must not be called. virtual ID3D11SamplerState* GetD3D11SamplerState() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h index 6a7fbc61..e5353041 100644 --- a/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {C513E83E-B037-405B-8B49-BF8F5C220DEE} static constexpr INTERFACE_ID IID_ShaderD3D11 = -{ 0xc513e83e, 0xb037, 0x405b, { 0x8b, 0x49, 0xbf, 0x8f, 0x5c, 0x22, 0xd, 0xee } }; + {0xc513e83e, 0xb037, 0x405b, {0x8b, 0x49, 0xbf, 0x8f, 0x5c, 0x22, 0xd, 0xee}}; /// Exposes Direct3D11-specific functionality of a shader object. class IShaderD3D11 : public IShaderD3D { public: - /// Returns a pointer to the ID3D11DeviceChild interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11DeviceChild* GetD3D11Shader() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/ShaderResourceBindingD3D11.h b/Graphics/GraphicsEngineD3D11/interface/ShaderResourceBindingD3D11.h index acbcc803..1eb442f8 100644 --- a/Graphics/GraphicsEngineD3D11/interface/ShaderResourceBindingD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/ShaderResourceBindingD3D11.h @@ -33,13 +33,11 @@ namespace Diligent // {97A6D4AC-D4AF-4AA9-B46C-67417B89026A} static constexpr INTERFACE_ID IID_ShaderResourceBindingD3D11 = -{ 0x97a6d4ac, 0xd4af, 0x4aa9, { 0xb4, 0x6c, 0x67, 0x41, 0x7b, 0x89, 0x2, 0x6a } }; + {0x97a6d4ac, 0xd4af, 0x4aa9, {0xb4, 0x6c, 0x67, 0x41, 0x7b, 0x89, 0x2, 0x6a}}; /// Exposes Direct3D11-specific functionality of a shader resource binding object. class IShaderResourceBindingD3D11 : public IShaderResourceBinding { -public: - }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h b/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h index fa4d0081..6f5a522d 100644 --- a/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h @@ -34,7 +34,7 @@ namespace Diligent // {4DAF2E76-9204-4DC4-A53A-B00097412D3A} static constexpr INTERFACE_ID IID_SwapChainD3D11 = -{ 0x4daf2e76, 0x9204, 0x4dc4, { 0xa5, 0x3a, 0xb0, 0x0, 0x97, 0x41, 0x2d, 0x3a } }; + {0x4daf2e76, 0x9204, 0x4dc4, {0xa5, 0x3a, 0xb0, 0x0, 0x97, 0x41, 0x2d, 0x3a}}; /// Exposes Direct3D11-specific functionality of a swap chain. class ISwapChainD3D11 : public ISwapChain @@ -53,4 +53,4 @@ public: virtual IDXGISwapChain* GetDXGISwapChain() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h b/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h index 2861e406..147a0ccd 100644 --- a/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {F3A84CC2-E485-4E72-A08A-437D7FFBA3AB} static constexpr INTERFACE_ID IID_TextureD3D11 = -{ 0xf3a84cc2, 0xe485, 0x4e72, { 0xa0, 0x8a, 0x43, 0x7d, 0x7f, 0xfb, 0xa3, 0xab } }; + {0xf3a84cc2, 0xe485, 0x4e72, {0xa0, 0x8a, 0x43, 0x7d, 0x7f, 0xfb, 0xa3, 0xab}}; /// Exposes Direct3D11-specific functionality of a texture object. class ITextureD3D11 : public ITexture { public: - /// Returns a pointer to the ID3D11Resource interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11Resource* GetD3D11Texture() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h b/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h index 24395b30..827be5bc 100644 --- a/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h @@ -33,13 +33,12 @@ namespace Diligent // {0767EBE4-AD47-4E70-9B65-38C6B9CAC37D} static constexpr INTERFACE_ID IID_TextureViewD3D11 = -{ 0x767ebe4, 0xad47, 0x4e70, { 0x9b, 0x65, 0x38, 0xc6, 0xb9, 0xca, 0xc3, 0x7d } }; + {0x767ebe4, 0xad47, 0x4e70, {0x9b, 0x65, 0x38, 0xc6, 0xb9, 0xca, 0xc3, 0x7d}}; /// Exposes Direct3D11-specific functionality of a texture view object. class ITextureViewD3D11 : public ITextureView { public: - /// Returns a pointer to the ID3D11View interface of the internal Direct3D11 object. /// The method does *NOT* call AddRef() on the returned interface, @@ -47,4 +46,4 @@ public: virtual ID3D11View* GetD3D11View() = 0; }; -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp index 9ef2c373..e7da925a 100644 --- a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp @@ -35,11 +35,12 @@ namespace Diligent { -BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const BufferDesc& BuffDesc, - const BufferData* pBuffData /*= nullptr*/) : +BufferD3D11Impl ::BufferD3D11Impl(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& BuffViewObjMemAllocator, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const BufferDesc& BuffDesc, + const BufferData* pBuffData /*= nullptr*/) : + // clang-format off TBufferBase { pRefCounters, @@ -48,10 +49,11 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, BuffDesc, false } +// clang-format on { #define LOG_BUFFER_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Buffer \"", m_Desc.Name ? m_Desc.Name : "", "\": ", ##__VA_ARGS__); - if( m_Desc.Usage == USAGE_STATIC && (pBuffData == nullptr || pBuffData->pData == nullptr)) + if (m_Desc.Usage == USAGE_STATIC && (pBuffData == nullptr || pBuffData->pData == nullptr)) LOG_BUFFER_ERROR_AND_THROW("Static buffer must be initialized with data at creation time"); if (m_Desc.BindFlags & BIND_UNIFORM_BUFFER) @@ -64,16 +66,16 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, D3D11BuffDesc.BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); D3D11BuffDesc.ByteWidth = m_Desc.uiSizeInBytes; D3D11BuffDesc.MiscFlags = 0; - if( m_Desc.BindFlags & BIND_INDIRECT_DRAW_ARGS ) + if (m_Desc.BindFlags & BIND_INDIRECT_DRAW_ARGS) { D3D11BuffDesc.MiscFlags |= D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS; } D3D11BuffDesc.Usage = UsageToD3D11Usage(m_Desc.Usage); - + // Size of each element in the buffer structure (in bytes) when the buffer represents a structured buffer, or // the size of the format that is used for views of the buffer D3D11BuffDesc.StructureByteStride = m_Desc.ElementByteStride; - if( (m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || (m_Desc.BindFlags & BIND_SHADER_RESOURCE) ) + if ((m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || (m_Desc.BindFlags & BIND_SHADER_RESOURCE)) { if (m_Desc.Mode == BUFFER_MODE_STRUCTURED) { @@ -84,7 +86,7 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, { VERIFY(D3D11BuffDesc.StructureByteStride != 0, "StructureByteStride cannot not be zero for a formatted buffer"); } - else if( m_Desc.Mode == BUFFER_MODE_RAW) + else if (m_Desc.Mode == BUFFER_MODE_RAW) { D3D11BuffDesc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; } @@ -94,16 +96,16 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, } } - D3D11BuffDesc.CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags( m_Desc.CPUAccessFlags ); + D3D11BuffDesc.CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); D3D11_SUBRESOURCE_DATA InitData; - InitData.pSysMem = pBuffData ? pBuffData->pData : nullptr; + InitData.pSysMem = pBuffData ? pBuffData->pData : nullptr; InitData.SysMemPitch = pBuffData ? pBuffData->DataSize : 0; InitData.SysMemSlicePitch = 0; - auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateBuffer(&D3D11BuffDesc, InitData.pSysMem ? &InitData : nullptr, &m_pd3d11Buffer), - "Failed to create the Direct3D11 buffer" ); + auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateBuffer(&D3D11BuffDesc, InitData.pSysMem ? &InitData : nullptr, &m_pd3d11Buffer), + "Failed to create the Direct3D11 buffer"); if (*m_Desc.Name != 0) { @@ -114,50 +116,63 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, SetState(RESOURCE_STATE_UNDEFINED); } -static BufferDesc BuffDescFromD3D11Buffer(ID3D11Buffer *pd3d11Buffer, BufferDesc BuffDesc) +static BufferDesc BuffDescFromD3D11Buffer(ID3D11Buffer* pd3d11Buffer, BufferDesc BuffDesc) { D3D11_BUFFER_DESC D3D11BuffDesc; pd3d11Buffer->GetDesc(&D3D11BuffDesc); - VERIFY(BuffDesc.uiSizeInBytes == 0 || BuffDesc.uiSizeInBytes == D3D11BuffDesc.ByteWidth, "Buffer size specified by the BufferDesc (",BuffDesc.uiSizeInBytes,") does not match d3d11 buffer size (", D3D11BuffDesc.ByteWidth, ")" ); - BuffDesc.uiSizeInBytes = Uint32{ D3D11BuffDesc.ByteWidth }; + VERIFY(BuffDesc.uiSizeInBytes == 0 || BuffDesc.uiSizeInBytes == D3D11BuffDesc.ByteWidth, + "Buffer size specified by the BufferDesc (", BuffDesc.uiSizeInBytes, + ") does not match d3d11 buffer size (", D3D11BuffDesc.ByteWidth, ")"); + BuffDesc.uiSizeInBytes = Uint32{D3D11BuffDesc.ByteWidth}; auto BindFlags = D3D11BindFlagsToBindFlags(D3D11BuffDesc.BindFlags); if (D3D11BuffDesc.MiscFlags & D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS) BindFlags |= BIND_INDIRECT_DRAW_ARGS; - VERIFY(BuffDesc.BindFlags == 0 || BuffDesc.BindFlags == BindFlags, "Bind flags specified by the BufferDesc (", BuffDesc.BindFlags,") do not match bind flags recovered from d3d11 buffer desc (", BindFlags, ")" ); + VERIFY(BuffDesc.BindFlags == 0 || BuffDesc.BindFlags == BindFlags, + "Bind flags specified by the BufferDesc (", BuffDesc.BindFlags, + ") do not match bind flags recovered from d3d11 buffer desc (", BindFlags, ")"); BuffDesc.BindFlags = BindFlags; auto Usage = D3D11UsageToUsage(D3D11BuffDesc.Usage); - VERIFY(BuffDesc.Usage == 0 || BuffDesc.Usage == Usage, "Usage specified by the BufferDesc (", BuffDesc.Usage,") do not match buffer usage recovered from d3d11 buffer desc (", Usage, ")" ); + VERIFY(BuffDesc.Usage == 0 || BuffDesc.Usage == Usage, + "Usage specified by the BufferDesc (", BuffDesc.Usage, + ") do not match buffer usage recovered from d3d11 buffer desc (", Usage, ")"); BuffDesc.Usage = Usage; auto CPUAccessFlags = D3D11CPUAccessFlagsToCPUAccessFlags(D3D11BuffDesc.CPUAccessFlags); - VERIFY(BuffDesc.CPUAccessFlags == 0 || BuffDesc.CPUAccessFlags == CPUAccessFlags, "CPU access flags specified by the BufferDesc (", BuffDesc.CPUAccessFlags, ") do not match CPU access flags recovered from d3d11 buffer desc (", CPUAccessFlags, ")"); + VERIFY(BuffDesc.CPUAccessFlags == 0 || BuffDesc.CPUAccessFlags == CPUAccessFlags, + "CPU access flags specified by the BufferDesc (", BuffDesc.CPUAccessFlags, + ") do not match CPU access flags recovered from d3d11 buffer desc (", CPUAccessFlags, ")"); BuffDesc.CPUAccessFlags = CPUAccessFlags; - if( (BuffDesc.BindFlags & BIND_UNORDERED_ACCESS) || (BuffDesc.BindFlags & BIND_SHADER_RESOURCE) ) + if ((BuffDesc.BindFlags & BIND_UNORDERED_ACCESS) || (BuffDesc.BindFlags & BIND_SHADER_RESOURCE)) { if (D3D11BuffDesc.StructureByteStride != 0) { - VERIFY(BuffDesc.ElementByteStride == 0 || BuffDesc.ElementByteStride == D3D11BuffDesc.StructureByteStride, "Element byte stride specified by the BufferDesc (", BuffDesc.ElementByteStride, ") does not match the structured byte stride recovered from d3d11 buffer desc (", D3D11BuffDesc.StructureByteStride, ")"); - BuffDesc.ElementByteStride = Uint32{ D3D11BuffDesc.StructureByteStride }; + VERIFY(BuffDesc.ElementByteStride == 0 || BuffDesc.ElementByteStride == D3D11BuffDesc.StructureByteStride, + "Element byte stride specified by the BufferDesc (", BuffDesc.ElementByteStride, + ") does not match the structured byte stride recovered from d3d11 buffer desc (", D3D11BuffDesc.StructureByteStride, ")"); + BuffDesc.ElementByteStride = Uint32{D3D11BuffDesc.StructureByteStride}; } - if(D3D11BuffDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) + if (D3D11BuffDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED) { - VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_STRUCTURED, "Inconsistent buffer mode: BUFFER_MODE_STRUCTURED or BUFFER_MODE_UNDEFINED is expected"); + VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_STRUCTURED, + "Inconsistent buffer mode: BUFFER_MODE_STRUCTURED or BUFFER_MODE_UNDEFINED is expected"); BuffDesc.Mode = BUFFER_MODE_STRUCTURED; } - else if(D3D11BuffDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS) + else if (D3D11BuffDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS) { - VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_RAW, "Inconsistent buffer mode: BUFFER_MODE_RAW or BUFFER_MODE_UNDEFINED is expected"); + VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_RAW, + "Inconsistent buffer mode: BUFFER_MODE_RAW or BUFFER_MODE_UNDEFINED is expected"); BuffDesc.Mode = BUFFER_MODE_RAW; } else { if (BuffDesc.ElementByteStride != 0) { - VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_FORMATTED, "Inconsistent buffer mode: BUFFER_MODE_FORMATTED or BUFFER_MODE_UNDEFINED is expected"); + VERIFY(BuffDesc.Mode == BUFFER_MODE_UNDEFINED || BuffDesc.Mode == BUFFER_MODE_FORMATTED, + "Inconsistent buffer mode: BUFFER_MODE_FORMATTED or BUFFER_MODE_UNDEFINED is expected"); BuffDesc.Mode = BUFFER_MODE_FORMATTED; } else @@ -167,12 +182,13 @@ static BufferDesc BuffDescFromD3D11Buffer(ID3D11Buffer *pd3d11Buffer, BufferDesc return BuffDesc; } -BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - class RenderDeviceD3D11Impl* pDeviceD3D11, - const BufferDesc& BuffDesc, - RESOURCE_STATE InitialState, - ID3D11Buffer* pd3d11Buffer) : +BufferD3D11Impl ::BufferD3D11Impl(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& BuffViewObjMemAllocator, + class RenderDeviceD3D11Impl* pDeviceD3D11, + const BufferDesc& BuffDesc, + RESOURCE_STATE InitialState, + ID3D11Buffer* pd3d11Buffer) : + // clang-format off TBufferBase { pRefCounters, @@ -181,80 +197,79 @@ BufferD3D11Impl :: BufferD3D11Impl(IReferenceCounters* pRefCounters, BuffDescFromD3D11Buffer(pd3d11Buffer, BuffDesc), false } +// clang-format on { m_pd3d11Buffer = pd3d11Buffer; SetState(InitialState); } -BufferD3D11Impl :: ~BufferD3D11Impl() +BufferD3D11Impl ::~BufferD3D11Impl() { } -IMPLEMENT_QUERY_INTERFACE( BufferD3D11Impl, IID_BufferD3D11, TBufferBase ) +IMPLEMENT_QUERY_INTERFACE(BufferD3D11Impl, IID_BufferD3D11, TBufferBase) -void BufferD3D11Impl::CreateViewInternal( const BufferViewDesc& OrigViewDesc, IBufferView** ppView, bool bIsDefaultView ) +void BufferD3D11Impl::CreateViewInternal(const BufferViewDesc& OrigViewDesc, IBufferView** ppView, bool bIsDefaultView) { - VERIFY( ppView != nullptr, "Null pointer provided" ); - if( !ppView )return; - VERIFY( *ppView == nullptr, "Overwriting reference to existing object may cause memory leaks" ); + VERIFY(ppView != nullptr, "Null pointer provided"); + if (!ppView) return; + VERIFY(*ppView == nullptr, "Overwriting reference to existing object may cause memory leaks"); *ppView = nullptr; try { - auto *pDeviceD3D11Impl = ValidatedCast(GetDevice()); - auto &BuffViewAllocator = pDeviceD3D11Impl->GetBuffViewObjAllocator(); - VERIFY( &BuffViewAllocator == &m_dbgBuffViewAllocator, "Buff view allocator does not match allocator provided at buffer initialization" ); + auto* pDeviceD3D11Impl = ValidatedCast(GetDevice()); + auto& BuffViewAllocator = pDeviceD3D11Impl->GetBuffViewObjAllocator(); + VERIFY(&BuffViewAllocator == &m_dbgBuffViewAllocator, "Buff view allocator does not match allocator provided at buffer initialization"); BufferViewDesc ViewDesc = OrigViewDesc; - if( ViewDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS ) + if (ViewDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS) { CComPtr pUAV; - CreateUAV( ViewDesc, &pUAV ); - *ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D11Impl instance", BufferViewD3D11Impl, bIsDefaultView ? this : nullptr) - ( pDeviceD3D11Impl, ViewDesc, this, pUAV, bIsDefaultView ); + CreateUAV(ViewDesc, &pUAV); + *ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D11Impl instance", BufferViewD3D11Impl, bIsDefaultView ? this : nullptr)(pDeviceD3D11Impl, ViewDesc, this, pUAV, bIsDefaultView); } - else if( ViewDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE ) + else if (ViewDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE) { - CComPtr pSRV; - CreateSRV( ViewDesc, &pSRV ); - *ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D11Impl instance", BufferViewD3D11Impl, bIsDefaultView ? this : nullptr) - (pDeviceD3D11Impl, ViewDesc, this, pSRV, bIsDefaultView ); + CComPtr pSRV; + CreateSRV(ViewDesc, &pSRV); + *ppView = NEW_RC_OBJ(BuffViewAllocator, "BufferViewD3D11Impl instance", BufferViewD3D11Impl, bIsDefaultView ? this : nullptr)(pDeviceD3D11Impl, ViewDesc, this, pSRV, bIsDefaultView); } - if( !bIsDefaultView && *ppView ) + if (!bIsDefaultView && *ppView) (*ppView)->AddRef(); } - catch( const std::runtime_error & ) + catch (const std::runtime_error&) { - const auto *ViewTypeName = GetBufferViewTypeLiteralName(OrigViewDesc.ViewType); - LOG_ERROR("Failed to create view \"", OrigViewDesc.Name ? OrigViewDesc.Name : "", "\" (", ViewTypeName, ") for buffer \"", m_Desc.Name, "\"" ); + const auto* ViewTypeName = GetBufferViewTypeLiteralName(OrigViewDesc.ViewType); + LOG_ERROR("Failed to create view \"", OrigViewDesc.Name ? OrigViewDesc.Name : "", "\" (", ViewTypeName, ") for buffer \"", m_Desc.Name, "\""); } } -void BufferD3D11Impl::CreateUAV( BufferViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ) +void BufferD3D11Impl::CreateUAV(BufferViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) { - CorrectBufferViewDesc( UAVDesc ); + CorrectBufferViewDesc(UAVDesc); D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc; BufferViewDesc_to_D3D11_UAV_DESC(m_Desc, UAVDesc, D3D11_UAVDesc); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Buffer, &D3D11_UAVDesc, ppD3D11UAV ), - "Failed to create D3D11 unordered access view" ); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateUnorderedAccessView(m_pd3d11Buffer, &D3D11_UAVDesc, ppD3D11UAV), + "Failed to create D3D11 unordered access view"); } -void BufferD3D11Impl::CreateSRV( struct BufferViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV ) +void BufferD3D11Impl::CreateSRV(struct BufferViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) { - CorrectBufferViewDesc( SRVDesc ); + CorrectBufferViewDesc(SRVDesc); D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc; BufferViewDesc_to_D3D11_SRV_DESC(m_Desc, SRVDesc, D3D11_SRVDesc); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Buffer, &D3D11_SRVDesc, ppD3D11SRV ), - "Failed to create D3D11 shader resource view" ); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateShaderResourceView(m_pd3d11Buffer, &D3D11_SRVDesc, ppD3D11SRV), + "Failed to create D3D11 shader resource view"); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp index daf5779d..e5d8e0de 100644 --- a/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp @@ -27,12 +27,13 @@ namespace Diligent { -BufferViewD3D11Impl::BufferViewD3D11Impl( IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - const BufferViewDesc& ViewDesc, - IBuffer* pBuffer, - ID3D11View* pD3D11View, - bool bIsDefaultView ) : +BufferViewD3D11Impl::BufferViewD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + const BufferViewDesc& ViewDesc, + IBuffer* pBuffer, + ID3D11View* pD3D11View, + bool bIsDefaultView) : + // clang-format off TBufferViewBase { pRefCounters, @@ -42,6 +43,7 @@ BufferViewD3D11Impl::BufferViewD3D11Impl( IReferenceCounters* pRefCounters, bIsDefaultView }, m_pD3D11View{pD3D11View} +// clang-format on { if (*m_Desc.Name != 0) { @@ -50,6 +52,6 @@ BufferViewD3D11Impl::BufferViewD3D11Impl( IReferenceCounters* pRefCounters, } } -IMPLEMENT_QUERY_INTERFACE( BufferViewD3D11Impl, IID_BufferViewD3D11, TBufferViewBase ) +IMPLEMENT_QUERY_INTERFACE(BufferViewD3D11Impl, IID_BufferViewD3D11, TBufferViewBase) -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/CommandListD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/CommandListD3D11Impl.cpp index 2c139ca0..6a2ef90c 100644 --- a/Graphics/GraphicsEngineD3D11/src/CommandListD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/CommandListD3D11Impl.cpp @@ -30,16 +30,16 @@ namespace Diligent { -CommandListD3D11Impl :: CommandListD3D11Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - ID3D11CommandList* pd3d11CommandList) : +CommandListD3D11Impl::CommandListD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + ID3D11CommandList* pd3d11CommandList) : TCommandListBase{pRefCounters, pDevice}, m_pd3d11CommandList{pd3d11CommandList} { } -CommandListD3D11Impl :: ~CommandListD3D11Impl() +CommandListD3D11Impl::~CommandListD3D11Impl() { } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp index 7b0f9d9e..35007538 100644 --- a/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp +++ b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp @@ -46,23 +46,26 @@ D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Fu return ComparisonFuncToD3DComparisonFunc(Func); } -void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, D3D11_DEPTH_STENCIL_DESC& d3d11DSSDesc) +void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, + D3D11_DEPTH_STENCIL_DESC& d3d11DSSDesc) { DepthStencilStateDesc_To_D3D_DEPTH_STENCIL_DESC(DepthStencilDesc, d3d11DSSDesc); } -void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, D3D11_RASTERIZER_DESC& d3d11RSDesc) +void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, + D3D11_RASTERIZER_DESC& d3d11RSDesc) { RasterizerStateDesc_To_D3D_RASTERIZER_DESC(RasterizerDesc, d3d11RSDesc); - d3d11RSDesc.ScissorEnable = RasterizerDesc.ScissorEnable ? TRUE : FALSE; + d3d11RSDesc.ScissorEnable = RasterizerDesc.ScissorEnable ? TRUE : FALSE; } -void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, D3D11_BLEND_DESC& d3d11BSDesc) +void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, + D3D11_BLEND_DESC& d3d11BSDesc) { BlendStateDescToD3DBlendDesc(BSDesc, d3d11BSDesc); - for( int i = 0; i < 8; ++i ) + for (int i = 0; i < 8; ++i) { const auto& SrcRTDesc = BSDesc.RenderTargets[i]; if (SrcRTDesc.LogicOperationEnable) @@ -72,8 +75,8 @@ void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, D3D11_BLEN } } -void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, - std::vector >& D3D11InputElements) +void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, + std::vector>& D3D11InputElements) { LayoutElements_To_D3D_INPUT_ELEMENT_DESCs(InputLayout, D3D11InputElements); } @@ -85,38 +88,47 @@ D3D11_PRIMITIVE_TOPOLOGY TopologyToD3D11Topology(PRIMITIVE_TOPOLOGY Topology) -void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc, Uint32 SampleCount) +void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, + D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc, + Uint32 SampleCount) { TextureViewDesc_to_D3D_SRV_DESC(TexViewDesc, D3D11SRVDesc, SampleCount); } -void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC& D3D11RTVDesc, Uint32 SampleCount) +void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, + D3D11_RENDER_TARGET_VIEW_DESC& D3D11RTVDesc, + Uint32 SampleCount) { TextureViewDesc_to_D3D_RTV_DESC(TexViewDesc, D3D11RTVDesc, SampleCount); } -void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC& D3D11DSVDesc, Uint32 SampleCount) +void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, + D3D11_DEPTH_STENCIL_VIEW_DESC& D3D11DSVDesc, + Uint32 SampleCount) { TextureViewDesc_to_D3D_DSV_DESC(TexViewDesc, D3D11DSVDesc, SampleCount); } -void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc) +void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, + D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc) { TextureViewDesc_to_D3D_UAV_DESC(TexViewDesc, D3D11UAVDesc); } -void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc) +void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, + const BufferViewDesc& SRVDesc, + D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc) { if (BuffDesc.Mode == BUFFER_MODE_RAW && SRVDesc.Format.ValueType == VT_UNDEFINED) { // Raw buffer view UINT ElementByteStride = 4; - DEV_CHECK_ERR( (SRVDesc.ByteOffset % 16) == 0, "Byte offest (", SRVDesc.ByteOffset, ") is not multiple of 16" ); - DEV_CHECK_ERR( (SRVDesc.ByteWidth % ElementByteStride) == 0, "Byte width (", SRVDesc.ByteWidth, ") is not multiple of 4" ); + DEV_CHECK_ERR((SRVDesc.ByteOffset % 16) == 0, "Byte offest (", SRVDesc.ByteOffset, ") is not multiple of 16"); + DEV_CHECK_ERR((SRVDesc.ByteWidth % ElementByteStride) == 0, "Byte width (", SRVDesc.ByteWidth, ") is not multiple of 4"); D3D11SRVDesc.BufferEx.FirstElement = SRVDesc.ByteOffset / ElementByteStride; - D3D11SRVDesc.BufferEx.NumElements = SRVDesc.ByteWidth / ElementByteStride; + D3D11SRVDesc.BufferEx.NumElements = SRVDesc.ByteWidth / ElementByteStride; D3D11SRVDesc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW; D3D11SRVDesc.Format = DXGI_FORMAT_R32_TYPELESS; D3D11SRVDesc.ViewDimension = D3D_SRV_DIMENSION_BUFFEREX; @@ -127,9 +139,11 @@ void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, const BufferVi } } -void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc) +void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc& BuffDesc, + const BufferViewDesc& UAVDesc, + D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc) { BufferViewDesc_to_D3D_UAV_DESC(BuffDesc, UAVDesc, D3D11UAVDesc); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 974ee98f..ee99c2ba 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -41,86 +41,91 @@ namespace Diligent { - DeviceContextD3D11Impl::DeviceContextD3D11Impl( IReferenceCounters* pRefCounters, - IMemoryAllocator& Allocator, - RenderDeviceD3D11Impl* pDevice, - ID3D11DeviceContext* pd3d11DeviceContext, - const struct EngineD3D11CreateInfo& EngineAttribs, - bool bIsDeferred ) : - TDeviceContextBase - { - pRefCounters, - pDevice, - bIsDeferred - }, - m_pd3d11DeviceContext{pd3d11DeviceContext }, - m_DebugFlags {EngineAttribs.DebugFlags }, - m_CmdListAllocator {GetRawAllocator(), sizeof(CommandListD3D11Impl), 64} - { - } +DeviceContextD3D11Impl::DeviceContextD3D11Impl(IReferenceCounters* pRefCounters, + IMemoryAllocator& Allocator, + RenderDeviceD3D11Impl* pDevice, + ID3D11DeviceContext* pd3d11DeviceContext, + const struct EngineD3D11CreateInfo& EngineAttribs, + bool bIsDeferred) : + // clang-format off + TDeviceContextBase + { + pRefCounters, + pDevice, + bIsDeferred + }, + m_pd3d11DeviceContext{pd3d11DeviceContext }, + m_DebugFlags {EngineAttribs.DebugFlags }, + m_CmdListAllocator {GetRawAllocator(), sizeof(CommandListD3D11Impl), 64} +// clang-format on +{ +} + +IMPLEMENT_QUERY_INTERFACE(DeviceContextD3D11Impl, IID_DeviceContextD3D11, TDeviceContextBase) - IMPLEMENT_QUERY_INTERFACE( DeviceContextD3D11Impl, IID_DeviceContextD3D11, TDeviceContextBase ) +void DeviceContextD3D11Impl::SetPipelineState(IPipelineState* pPipelineState) +{ + auto* pPipelineStateD3D11 = ValidatedCast(pPipelineState); + if (PipelineStateD3D11Impl::IsSameObject(m_pPipelineState, pPipelineStateD3D11)) + return; - void DeviceContextD3D11Impl::SetPipelineState(IPipelineState* pPipelineState) + TDeviceContextBase::SetPipelineState(pPipelineStateD3D11, 0 /*Dummy*/); + auto& Desc = pPipelineStateD3D11->GetDesc(); + if (Desc.IsComputePipeline) { - auto* pPipelineStateD3D11 = ValidatedCast(pPipelineState); - if (PipelineStateD3D11Impl::IsSameObject(m_pPipelineState, pPipelineStateD3D11)) + auto* pd3d11CS = pPipelineStateD3D11->GetD3D11ComputeShader(); + if (pd3d11CS == nullptr) + { + LOG_ERROR("Compute shader is not set in the pipeline"); return; + } - TDeviceContextBase::SetPipelineState( pPipelineStateD3D11, 0 /*Dummy*/ ); - auto& Desc = pPipelineStateD3D11->GetDesc(); - if (Desc.IsComputePipeline) - { - auto* pd3d11CS = pPipelineStateD3D11->GetD3D11ComputeShader(); - if (pd3d11CS == nullptr) - { - LOG_ERROR("Compute shader is not set in the pipeline"); - return; - } +#define COMMIT_SHADER(SN, ShaderName) \ + do \ + { \ + auto* pd3d11Shader = pPipelineStateD3D11->GetD3D11##ShaderName(); \ + if (m_CommittedD3DShaders[SN##Ind] != pd3d11Shader) \ + { \ + m_CommittedD3DShaders[SN##Ind] = pd3d11Shader; \ + m_pd3d11DeviceContext->SN##SetShader(pd3d11Shader, nullptr, 0); \ + } \ + } while (false) -#define COMMIT_SHADER(SN, ShaderName)\ - { \ - auto* pd3d11Shader = pPipelineStateD3D11->GetD3D11##ShaderName(); \ - if (m_CommittedD3DShaders[SN##Ind] != pd3d11Shader) \ - { \ - m_CommittedD3DShaders[SN##Ind] = pd3d11Shader; \ - m_pd3d11DeviceContext->SN##SetShader(pd3d11Shader, nullptr, 0); \ - } \ - } + COMMIT_SHADER(CS, ComputeShader); + } + else + { + COMMIT_SHADER(VS, VertexShader); + COMMIT_SHADER(PS, PixelShader); + COMMIT_SHADER(GS, GeometryShader); + COMMIT_SHADER(HS, HullShader); + COMMIT_SHADER(DS, DomainShader); +#undef COMMIT_SHADER - COMMIT_SHADER(CS, ComputeShader); - } - else + m_pd3d11DeviceContext->OMSetBlendState(pPipelineStateD3D11->GetD3D11BlendState(), m_BlendFactors, Desc.GraphicsPipeline.SampleMask); + m_pd3d11DeviceContext->RSSetState(pPipelineStateD3D11->GetD3D11RasterizerState()); + m_pd3d11DeviceContext->OMSetDepthStencilState(pPipelineStateD3D11->GetD3D11DepthStencilState(), m_StencilRef); + + auto* pd3d11InputLayout = pPipelineStateD3D11->GetD3D11InputLayout(); + // It is safe to perform raw pointer comparison as the device context + // keeps bound input layout alive + if (m_CommittedD3D11InputLayout != pd3d11InputLayout) { - COMMIT_SHADER(VS, VertexShader); - COMMIT_SHADER(PS, PixelShader); - COMMIT_SHADER(GS, GeometryShader); - COMMIT_SHADER(HS, HullShader); - COMMIT_SHADER(DS, DomainShader); -#undef COMMIT_SHADER - - m_pd3d11DeviceContext->OMSetBlendState( pPipelineStateD3D11->GetD3D11BlendState(), m_BlendFactors, Desc.GraphicsPipeline.SampleMask ); - m_pd3d11DeviceContext->RSSetState( pPipelineStateD3D11->GetD3D11RasterizerState() ); - m_pd3d11DeviceContext->OMSetDepthStencilState( pPipelineStateD3D11->GetD3D11DepthStencilState(), m_StencilRef ); - - auto* pd3d11InputLayout = pPipelineStateD3D11->GetD3D11InputLayout(); - // It is safe to perform raw pointer comparison as the device context - // keeps bound input layout alive - if (m_CommittedD3D11InputLayout != pd3d11InputLayout) - { - m_pd3d11DeviceContext->IASetInputLayout( pd3d11InputLayout ); - m_CommittedD3D11InputLayout = pd3d11InputLayout; - } + m_pd3d11DeviceContext->IASetInputLayout(pd3d11InputLayout); + m_CommittedD3D11InputLayout = pd3d11InputLayout; + } - auto PrimTopology = Desc.GraphicsPipeline.PrimitiveTopology; - if (m_CommittedPrimitiveTopology != PrimTopology) - { - m_CommittedPrimitiveTopology = PrimTopology; - m_CommittedD3D11PrimTopology = TopologyToD3D11Topology(PrimTopology); - m_pd3d11DeviceContext->IASetPrimitiveTopology(m_CommittedD3D11PrimTopology); - } + auto PrimTopology = Desc.GraphicsPipeline.PrimitiveTopology; + if (m_CommittedPrimitiveTopology != PrimTopology) + { + m_CommittedPrimitiveTopology = PrimTopology; + m_CommittedD3D11PrimTopology = TopologyToD3D11Topology(PrimTopology); + m_pd3d11DeviceContext->IASetPrimitiveTopology(m_CommittedD3D11PrimTopology); } } +} + +// clang-format off /// Helper macro used to create an array of device context methods to /// set particular resource for every shader stage @@ -151,1939 +156,1950 @@ namespace Diligent &ID3D11DeviceContext::CSSetUnorderedAccessViews // CS }; - // http://diligentgraphics.com/diligent-engine/architecture/d3d11/committing-shader-resources-to-the-gpu-pipeline/ - template - void DeviceContextD3D11Impl::TransitionAndCommitShaderResources(IPipelineState* pPSO, IShaderResourceBinding* pShaderResourceBinding, bool VerifyStates) - { - VERIFY_EXPR(pPSO != nullptr); - static_assert(TransitionResources || CommitResources, "At least one of TransitionResources or CommitResources flags is expected to be true"); +// clang-format on - auto* pPipelineStateD3D11 = ValidatedCast(pPSO); +// http://diligentgraphics.com/diligent-engine/architecture/d3d11/committing-shader-resources-to-the-gpu-pipeline/ +template +void DeviceContextD3D11Impl::TransitionAndCommitShaderResources(IPipelineState* pPSO, IShaderResourceBinding* pShaderResourceBinding, bool VerifyStates) +{ + VERIFY_EXPR(pPSO != nullptr); + static_assert(TransitionResources || CommitResources, "At least one of TransitionResources or CommitResources flags is expected to be true"); - if (pShaderResourceBinding == nullptr) - { + auto* pPipelineStateD3D11 = ValidatedCast(pPSO); + + if (pShaderResourceBinding == nullptr) + { #ifdef DEVELOPMENT - bool ResourcesPresent = false; - for (Uint32 s = 0; s < pPipelineStateD3D11->GetNumShaders(); ++s) - { - auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); - if (pShaderD3D11->GetD3D11Resources()->GetTotalResources() > 0) - ResourcesPresent = true; - } - - if (ResourcesPresent) - { - LOG_ERROR_MESSAGE("Pipeline state '", pPSO->GetDesc().Name, "' requires shader resource binding object to ", - (CommitResources ? "commit" : "transition"), " resources, but none is provided."); - } -#endif - return; + bool ResourcesPresent = false; + for (Uint32 s = 0; s < pPipelineStateD3D11->GetNumShaders(); ++s) + { + auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); + if (pShaderD3D11->GetD3D11Resources()->GetTotalResources() > 0) + ResourcesPresent = true; } - - auto pShaderResBindingD3D11 = ValidatedCast(pShaderResourceBinding); -#ifdef DEVELOPMENT - if (pPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState())) + if (ResourcesPresent) { - LOG_ERROR_MESSAGE("Shader resource binding does not match Pipeline State"); - return; + LOG_ERROR_MESSAGE("Pipeline state '", pPSO->GetDesc().Name, "' requires shader resource binding object to ", + (CommitResources ? "commit" : "transition"), " resources, but none is provided."); } #endif + return; + } - auto NumShaders = pShaderResBindingD3D11->GetNumActiveShaders(); - VERIFY(NumShaders == pPipelineStateD3D11->GetNumShaders(), "Number of active shaders in shader resource binding is not consistent with the number of shaders in the pipeline state"); + auto pShaderResBindingD3D11 = ValidatedCast(pShaderResourceBinding); #ifdef DEVELOPMENT - bool StaticResourcesPresent = false; - for (Uint32 s = 0; s < NumShaders; ++s) - { - const auto& StaticResLayout = pPipelineStateD3D11->GetStaticResourceLayout(s); - if (StaticResLayout.GetTotalResourceCount() > 0) - StaticResourcesPresent = true; - } - // Static resource bindings are verified in BindStaticShaderResources() - if (StaticResourcesPresent && !pShaderResBindingD3D11->IsStaticResourcesBound()) - { - LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", pPSO->GetDesc().Name,"'. Please call IShaderResourceBinding::InitializeStaticResources()."); - } + if (pPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState())) + { + LOG_ERROR_MESSAGE("Shader resource binding does not match Pipeline State"); + return; + } #endif - bool ClearPixelShaderUAVs = m_NumCommittedUAVs[PSInd] > 0; - // First, commit all UAVs for all shader stages. This will unbind them from input - for (Uint32 s = 0; s < NumShaders; ++s) - { - auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); + auto NumShaders = pShaderResBindingD3D11->GetNumActiveShaders(); + VERIFY(NumShaders == pPipelineStateD3D11->GetNumShaders(), "Number of active shaders in shader resource binding is not consistent with the number of shaders in the pipeline state"); #ifdef DEVELOPMENT - auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); - VERIFY_EXPR( ShaderTypeInd == static_cast(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)) ); + bool StaticResourcesPresent = false; + for (Uint32 s = 0; s < NumShaders; ++s) + { + const auto& StaticResLayout = pPipelineStateD3D11->GetStaticResourceLayout(s); + if (StaticResLayout.GetTotalResourceCount() > 0) + StaticResourcesPresent = true; + } + // Static resource bindings are verified in BindStaticShaderResources() + if (StaticResourcesPresent && !pShaderResBindingD3D11->IsStaticResourcesBound()) + { + LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", pPSO->GetDesc().Name, "'. Please call IShaderResourceBinding::InitializeStaticResources()."); + } #endif - auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); - auto NumUAVs = Cache.GetUAVCount(); - if (NumUAVs) - { - ShaderResourceCacheD3D11::CachedResource* CachedUAVResources; - ID3D11UnorderedAccessView** d3d11UAVs; - Cache.GetUAVArrays(CachedUAVResources, d3d11UAVs); + bool ClearPixelShaderUAVs = m_NumCommittedUAVs[PSInd] > 0; + // First, commit all UAVs for all shader stages. This will unbind them from input + for (Uint32 s = 0; s < NumShaders; ++s) + { + auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); + +#ifdef DEVELOPMENT + auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); + VERIFY_EXPR(ShaderTypeInd == static_cast(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType))); +#endif + + auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); + auto NumUAVs = Cache.GetUAVCount(); + if (NumUAVs) + { + ShaderResourceCacheD3D11::CachedResource* CachedUAVResources; + ID3D11UnorderedAccessView** d3d11UAVs; + Cache.GetUAVArrays(CachedUAVResources, d3d11UAVs); - auto* CommittedD3D11UAVs = m_CommittedD3D11UAVs [ShaderTypeInd]; - auto* CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[ShaderTypeInd]; + auto* CommittedD3D11UAVs = m_CommittedD3D11UAVs[ShaderTypeInd]; + auto* CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[ShaderTypeInd]; - if (ShaderTypeInd == PSInd) - ClearPixelShaderUAVs = false; + if (ShaderTypeInd == PSInd) + ClearPixelShaderUAVs = false; - UINT MinSlot = UINT_MAX; - UINT MaxSlot = 0; + UINT MinSlot = UINT_MAX; + UINT MaxSlot = 0; - for (Uint32 uav=0; uav < NumUAVs; ++uav) + for (Uint32 uav = 0; uav < NumUAVs; ++uav) + { + VERIFY_EXPR(uav < Cache.GetUAVCount()); + auto& UAVRes = CachedUAVResources[uav]; + // WARNING! This code is not thread-safe. It is up to the application to make + // sure that multiple threads do not modify the texture state simultaneously. + if (TransitionResources) { - VERIFY_EXPR(uav < Cache.GetUAVCount()); - auto& UAVRes = CachedUAVResources[uav]; - // WARNING! This code is not thread-safe. It is up to the application to make - // sure that multiple threads do not modify the texture state simultaneously. - if (TransitionResources) + if (auto* pTexture = ValidatedCast(UAVRes.pTexture)) { - if (auto* pTexture = ValidatedCast(UAVRes.pTexture)) + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - if (pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) - UnbindTextureFromInput(pTexture, UAVRes.pd3d11Resource); - pTexture->SetState(RESOURCE_STATE_UNORDERED_ACCESS); - } + if (pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) + UnbindTextureFromInput(pTexture, UAVRes.pd3d11Resource); + pTexture->SetState(RESOURCE_STATE_UNORDERED_ACCESS); } - else if (auto* pBuffer = ValidatedCast(UAVRes.pBuffer)) + } + else if (auto* pBuffer = ValidatedCast(UAVRes.pBuffer)) + { + if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - if ((pBuffer->GetState() & RESOURCE_STATE_GENERIC_READ) != 0) - UnbindBufferFromInput(pBuffer, UAVRes.pd3d11Resource); - pBuffer->SetState(RESOURCE_STATE_UNORDERED_ACCESS); - } + if ((pBuffer->GetState() & RESOURCE_STATE_GENERIC_READ) != 0) + UnbindBufferFromInput(pBuffer, UAVRes.pd3d11Resource); + pBuffer->SetState(RESOURCE_STATE_UNORDERED_ACCESS); } } + } #ifdef DEVELOPMENT - else if (VerifyStates) + else if (VerifyStates) + { + if (const auto* pTexture = ValidatedCast(UAVRes.pTexture)) { - if (const auto* pTexture = ValidatedCast(UAVRes.pTexture)) + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pTexture->IsInKnownState () && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state."); - } + LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state."); } - else if (const auto* pBuffer = ValidatedCast(UAVRes.pBuffer)) + } + else if (const auto* pBuffer = ValidatedCast(UAVRes.pBuffer)) + { + if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name, "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); - } + LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name, "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); } } + } #endif - if (CommitResources) - { - bool IsNewUAV = CommittedD3D11UAVs[uav] != d3d11UAVs[uav]; - MinSlot = IsNewUAV ? std::min(MinSlot, uav) : MinSlot; - MaxSlot = IsNewUAV ? uav : MaxSlot; + if (CommitResources) + { + bool IsNewUAV = CommittedD3D11UAVs[uav] != d3d11UAVs[uav]; + MinSlot = IsNewUAV ? std::min(MinSlot, uav) : MinSlot; + MaxSlot = IsNewUAV ? uav : MaxSlot; - CommittedD3D11UAVRes[uav] = UAVRes.pd3d11Resource; - CommittedD3D11UAVs [uav] = d3d11UAVs[uav]; - } + CommittedD3D11UAVRes[uav] = UAVRes.pd3d11Resource; + CommittedD3D11UAVs[uav] = d3d11UAVs[uav]; } + } - if (CommitResources) + if (CommitResources) + { + if (MinSlot != UINT_MAX || ShaderTypeInd == PSInd && m_NumCommittedUAVs[PSInd] != NumUAVs) { - if (MinSlot != UINT_MAX || ShaderTypeInd == PSInd && m_NumCommittedUAVs[PSInd] != NumUAVs) + // Something has changed + if (ShaderTypeInd == PSInd) { - // Something has changed - if(ShaderTypeInd == PSInd) - { - // Pixel shader UAVs cannot be set independently; they all need to be set at the same time. - // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks - auto StartUAVSlot = m_NumBoundRenderTargets; - VERIFY(NumUAVs > StartUAVSlot, "Number of UAVs must be greater than the render target count"); - m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews( - D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, - StartUAVSlot, NumUAVs - StartUAVSlot, CommittedD3D11UAVs + StartUAVSlot, nullptr); - // Clear previously bound UAVs, but do not clear lower slots as if - // render target count reduces, we will bind these UAVs in CommitRenderTargets() - for(Uint32 uav = NumUAVs; uav < m_NumCommittedUAVs[ShaderTypeInd]; ++uav) - { - CommittedD3D11UAVRes[uav] = nullptr; - CommittedD3D11UAVs [uav] = nullptr; - } - m_NumCommittedUAVs[ShaderTypeInd] = static_cast(NumUAVs); - } - else + // Pixel shader UAVs cannot be set independently; they all need to be set at the same time. + // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks + auto StartUAVSlot = m_NumBoundRenderTargets; + VERIFY(NumUAVs > StartUAVSlot, "Number of UAVs must be greater than the render target count"); + m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, + StartUAVSlot, NumUAVs - StartUAVSlot, CommittedD3D11UAVs + StartUAVSlot, nullptr); + // Clear previously bound UAVs, but do not clear lower slots as if + // render target count reduces, we will bind these UAVs in CommitRenderTargets() + for (Uint32 uav = NumUAVs; uav < m_NumCommittedUAVs[ShaderTypeInd]; ++uav) { - // This can only be CS - auto SetUAVMethod = SetUAVMethods[ShaderTypeInd]; - (m_pd3d11DeviceContext->*SetUAVMethod)(MinSlot, MaxSlot-MinSlot+1, CommittedD3D11UAVs+MinSlot, nullptr); - m_NumCommittedUAVs[ShaderTypeInd] = std::max(m_NumCommittedUAVs[ShaderTypeInd], static_cast(NumUAVs)); + CommittedD3D11UAVRes[uav] = nullptr; + CommittedD3D11UAVs[uav] = nullptr; } + m_NumCommittedUAVs[ShaderTypeInd] = static_cast(NumUAVs); } - -#ifdef DEVELOPMENT - if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderTypeInd == CSInd) + else { - dbgVerifyCommittedUAVs(pShaderD3D11->GetDesc().ShaderType); + // This can only be CS + auto SetUAVMethod = SetUAVMethods[ShaderTypeInd]; + (m_pd3d11DeviceContext->*SetUAVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11UAVs + MinSlot, nullptr); + m_NumCommittedUAVs[ShaderTypeInd] = std::max(m_NumCommittedUAVs[ShaderTypeInd], static_cast(NumUAVs)); } -#endif } + +#ifdef DEVELOPMENT + if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderTypeInd == CSInd) + { + dbgVerifyCommittedUAVs(pShaderD3D11->GetDesc().ShaderType); + } +#endif } } + } - if (ClearPixelShaderUAVs) + if (ClearPixelShaderUAVs) + { + // If pixel shader stage is inactive or does not use UAVs, unbind all committed UAVs. + // This is important as UnbindPixelShaderUAV<> function may need to rebind + // existing UAVs and the UAVs pointed to by CommittedD3D11UAVRes must be alive + // (we do not keep strong references to d3d11 UAVs) + auto* CommittedD3D11UAVs = m_CommittedD3D11UAVs[PSInd]; + auto* CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[PSInd]; + auto& NumCommittedPixelShaderUAVs = m_NumCommittedUAVs[PSInd]; + for (Uint32 uav = 0; uav < NumCommittedPixelShaderUAVs; ++uav) { - // If pixel shader stage is inactive or does not use UAVs, unbind all committed UAVs. - // This is important as UnbindPixelShaderUAV<> function may need to rebind - // existing UAVs and the UAVs pointed to by CommittedD3D11UAVRes must be alive - // (we do not keep strong references to d3d11 UAVs) - auto* CommittedD3D11UAVs = m_CommittedD3D11UAVs [PSInd]; - auto* CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[PSInd]; - auto& NumCommittedPixelShaderUAVs = m_NumCommittedUAVs [PSInd]; - for (Uint32 uav = 0; uav < NumCommittedPixelShaderUAVs; ++uav) - { - CommittedD3D11UAVRes[uav] = nullptr; - CommittedD3D11UAVs [uav] = nullptr; - } - m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews( - D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, - 0, 0, nullptr, nullptr); - NumCommittedPixelShaderUAVs = 0; + CommittedD3D11UAVRes[uav] = nullptr; + CommittedD3D11UAVs[uav] = nullptr; } + m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, + 0, 0, nullptr, nullptr); + NumCommittedPixelShaderUAVs = 0; + } - // Commit input resources (CBs, SRVs and Samplers) - for (Uint32 s = 0; s < NumShaders; ++s) - { - auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); + // Commit input resources (CBs, SRVs and Samplers) + for (Uint32 s = 0; s < NumShaders; ++s) + { + auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s); #ifdef DEVELOPMENT - auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); - VERIFY_EXPR( ShaderTypeInd == static_cast(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)) ); + auto* pShaderD3D11 = pPipelineStateD3D11->GetShader(s); + VERIFY_EXPR(ShaderTypeInd == static_cast(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType))); #endif - auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); + auto& Cache = pShaderResBindingD3D11->GetResourceCache(s); + + // Transition and commit Constant Buffers + auto NumCBs = Cache.GetCBCount(); + if (NumCBs) + { + ShaderResourceCacheD3D11::CachedCB* CachedCBs; + ID3D11Buffer** d3d11CBs; + Cache.GetCBArrays(CachedCBs, d3d11CBs); - // Transition and commit Constant Buffers - auto NumCBs = Cache.GetCBCount(); - if (NumCBs) + auto* CommittedD3D11CBs = m_CommittedD3D11CBs[ShaderTypeInd]; + UINT MinSlot = UINT_MAX; + UINT MaxSlot = 0; + for (Uint32 cb = 0; cb < NumCBs; ++cb) { - ShaderResourceCacheD3D11::CachedCB* CachedCBs; - ID3D11Buffer** d3d11CBs; - Cache.GetCBArrays(CachedCBs, d3d11CBs); - - auto* CommittedD3D11CBs = m_CommittedD3D11CBs[ShaderTypeInd]; - UINT MinSlot = UINT_MAX; - UINT MaxSlot = 0; - for (Uint32 cb=0; cb < NumCBs; ++cb) + VERIFY_EXPR(cb < Cache.GetCBCount()); + + if (TransitionResources) { - VERIFY_EXPR(cb < Cache.GetCBCount()); - - if (TransitionResources) + auto& CB = CachedCBs[cb]; + if (auto* pBuff = CB.pBuff.RawPtr()) { - auto& CB = CachedCBs[cb]; - if (auto* pBuff = CB.pBuff.RawPtr()) + // WARNING! This code is not thread-safe. It is up to the application to make + // sure that multiple threads do not modify the buffer state simultaneously. + if (pBuff->IsInKnownState() && !pBuff->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) { - // WARNING! This code is not thread-safe. It is up to the application to make - // sure that multiple threads do not modify the buffer state simultaneously. - if (pBuff->IsInKnownState() && !pBuff->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) + if (pBuff->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pBuff->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - // Even though we have unbound resources from UAV, we only checked shader - // stages active in current PSO, so we still may need to unbind the resource - // from UAV (for instance, unbind resource from CS UAV when running draw command). - UnbindResourceFromUAV( pBuff, d3d11CBs[cb] ); - pBuff->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); - } - pBuff->AddState(RESOURCE_STATE_CONSTANT_BUFFER); + // Even though we have unbound resources from UAV, we only checked shader + // stages active in current PSO, so we still may need to unbind the resource + // from UAV (for instance, unbind resource from CS UAV when running draw command). + UnbindResourceFromUAV(pBuff, d3d11CBs[cb]); + pBuff->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); } + pBuff->AddState(RESOURCE_STATE_CONSTANT_BUFFER); } } + } #ifdef DEVELOPMENT - else if (VerifyStates) + else if (VerifyStates) + { + VERIFY_EXPR(CommitResources); + const auto& CB = CachedCBs[cb]; + if (auto* pBuff = CB.pBuff.RawPtr()) { - VERIFY_EXPR(CommitResources); - const auto& CB = CachedCBs[cb]; - if (auto* pBuff = CB.pBuff.RawPtr()) + if (pBuff->IsInKnownState() && !pBuff->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) { - if (pBuff->IsInKnownState() && !pBuff->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) - { - LOG_ERROR_MESSAGE("Buffer '", pBuff->GetDesc().Name, "' has not been transitioned to Constant Buffer state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); - } + LOG_ERROR_MESSAGE("Buffer '", pBuff->GetDesc().Name, "' has not been transitioned to Constant Buffer state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); } } + } #endif - if(CommitResources) - { - bool IsNewCB = CommittedD3D11CBs[cb] != d3d11CBs[cb]; - MinSlot = IsNewCB ? std::min(MinSlot, cb) : MinSlot; - MaxSlot = IsNewCB ? cb : MaxSlot; - CommittedD3D11CBs[cb] = d3d11CBs[cb]; - } - } - if (CommitResources) { - if (MinSlot != UINT_MAX) - { - auto SetCBMethod = SetCBMethods[ShaderTypeInd]; - (m_pd3d11DeviceContext->*SetCBMethod)(MinSlot, MaxSlot-MinSlot+1, CommittedD3D11CBs+MinSlot); - m_NumCommittedCBs[ShaderTypeInd] = std::max(m_NumCommittedCBs[ShaderTypeInd], static_cast(NumCBs)); - } + bool IsNewCB = CommittedD3D11CBs[cb] != d3d11CBs[cb]; + MinSlot = IsNewCB ? std::min(MinSlot, cb) : MinSlot; + MaxSlot = IsNewCB ? cb : MaxSlot; + CommittedD3D11CBs[cb] = d3d11CBs[cb]; + } + } + + if (CommitResources) + { + if (MinSlot != UINT_MAX) + { + auto SetCBMethod = SetCBMethods[ShaderTypeInd]; + (m_pd3d11DeviceContext->*SetCBMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11CBs + MinSlot); + m_NumCommittedCBs[ShaderTypeInd] = std::max(m_NumCommittedCBs[ShaderTypeInd], static_cast(NumCBs)); + } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedCBs(pShaderD3D11->GetDesc().ShaderType); - } -#endif + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedCBs(pShaderD3D11->GetDesc().ShaderType); } +#endif } + } - // Transition and commit Shader Resource Views - auto NumSRVs = Cache.GetSRVCount(); - if (NumSRVs) - { - ShaderResourceCacheD3D11::CachedResource* CachedSRVResources; - ID3D11ShaderResourceView** d3d11SRVs; - Cache.GetSRVArrays(CachedSRVResources, d3d11SRVs); + // Transition and commit Shader Resource Views + auto NumSRVs = Cache.GetSRVCount(); + if (NumSRVs) + { + ShaderResourceCacheD3D11::CachedResource* CachedSRVResources; + ID3D11ShaderResourceView** d3d11SRVs; + Cache.GetSRVArrays(CachedSRVResources, d3d11SRVs); - auto* CommittedD3D11SRVs = m_CommittedD3D11SRVs [ShaderTypeInd]; - auto* CommittedD3D11SRVRes = m_CommittedD3D11SRVResources[ShaderTypeInd]; + auto* CommittedD3D11SRVs = m_CommittedD3D11SRVs[ShaderTypeInd]; + auto* CommittedD3D11SRVRes = m_CommittedD3D11SRVResources[ShaderTypeInd]; - UINT MinSlot = UINT_MAX; - UINT MaxSlot = 0; + UINT MinSlot = UINT_MAX; + UINT MaxSlot = 0; - for (Uint32 srv=0; srv < NumSRVs; ++srv) + for (Uint32 srv = 0; srv < NumSRVs; ++srv) + { + VERIFY_EXPR(srv < Cache.GetSRVCount()); + auto& SRVRes = CachedSRVResources[srv]; + // WARNING! This code is not thread-safe. It is up to the application to make + // sure that multiple threads do not modify the texture state simultaneously. + if (TransitionResources) { - VERIFY_EXPR(srv < Cache.GetSRVCount()); - auto &SRVRes = CachedSRVResources[srv]; - // WARNING! This code is not thread-safe. It is up to the application to make - // sure that multiple threads do not modify the texture state simultaneously. - if (TransitionResources) + if (auto* pTexture = ValidatedCast(SRVRes.pTexture)) { - if (auto* pTexture = ValidatedCast(SRVRes.pTexture)) + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) { - if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) + if (pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - // Even though we have unbound resources from UAV, we only checked shader - // stages active in current PSO, so we still may need to unbind the resource - // from UAV (for instance, unbind resource from CS UAV when running draw command). - UnbindResourceFromUAV(pTexture, SRVRes.pd3d11Resource); - pTexture->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); - } - - if (pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET)) - UnbindTextureFromRenderTarget(pTexture); - - if (pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE)) - UnbindTextureFromDepthStencil(pTexture); - - pTexture->SetState(RESOURCE_STATE_SHADER_RESOURCE); + // Even though we have unbound resources from UAV, we only checked shader + // stages active in current PSO, so we still may need to unbind the resource + // from UAV (for instance, unbind resource from CS UAV when running draw command). + UnbindResourceFromUAV(pTexture, SRVRes.pd3d11Resource); + pTexture->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); } + + if (pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET)) + UnbindTextureFromRenderTarget(pTexture); + + if (pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE)) + UnbindTextureFromDepthStencil(pTexture); + + pTexture->SetState(RESOURCE_STATE_SHADER_RESOURCE); } - else if (auto* pBuffer = ValidatedCast(SRVRes.pBuffer)) + } + else if (auto* pBuffer = ValidatedCast(SRVRes.pBuffer)) + { + if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) { - if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) + if (pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - UnbindResourceFromUAV( pBuffer, SRVRes.pd3d11Resource ); - pBuffer->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); - } - pBuffer->AddState(RESOURCE_STATE_SHADER_RESOURCE); + UnbindResourceFromUAV(pBuffer, SRVRes.pd3d11Resource); + pBuffer->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); } + pBuffer->AddState(RESOURCE_STATE_SHADER_RESOURCE); } } + } #ifdef DEVELOPMENT - else if (VerifyStates) + else if (VerifyStates) + { + VERIFY_EXPR(CommitResources); + if (const auto* pTexture = ValidatedCast(SRVRes.pTexture)) { - VERIFY_EXPR(CommitResources); - if (const auto* pTexture = ValidatedCast(SRVRes.pTexture)) + if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) { - if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) - { - LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state."); - } + LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state."); } - else if (const auto* pBuffer = ValidatedCast(SRVRes.pBuffer)) + } + else if (const auto* pBuffer = ValidatedCast(SRVRes.pBuffer)) + { + if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) { - if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) - { - LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name, "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); - } + LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name, "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state."); } } + } #endif - if (CommitResources) - { - bool IsNewSRV = CommittedD3D11SRVs[srv] != d3d11SRVs[srv]; - MinSlot = IsNewSRV ? std::min(MinSlot, srv) : MinSlot; - MaxSlot = IsNewSRV ? srv : MaxSlot; + if (CommitResources) + { + bool IsNewSRV = CommittedD3D11SRVs[srv] != d3d11SRVs[srv]; + MinSlot = IsNewSRV ? std::min(MinSlot, srv) : MinSlot; + MaxSlot = IsNewSRV ? srv : MaxSlot; - CommittedD3D11SRVRes[srv] = SRVRes.pd3d11Resource; - CommittedD3D11SRVs[srv] = d3d11SRVs[srv]; - } + CommittedD3D11SRVRes[srv] = SRVRes.pd3d11Resource; + CommittedD3D11SRVs[srv] = d3d11SRVs[srv]; } + } - if (CommitResources) + if (CommitResources) + { + if (MinSlot != UINT_MAX) { - if (MinSlot != UINT_MAX) - { - auto SetSRVMethod = SetSRVMethods[ShaderTypeInd]; - (m_pd3d11DeviceContext->*SetSRVMethod)(MinSlot, MaxSlot-MinSlot+1, CommittedD3D11SRVs+MinSlot); - m_NumCommittedSRVs[ShaderTypeInd] = std::max(m_NumCommittedSRVs[ShaderTypeInd], static_cast(NumSRVs)); - } + auto SetSRVMethod = SetSRVMethods[ShaderTypeInd]; + (m_pd3d11DeviceContext->*SetSRVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11SRVs + MinSlot); + m_NumCommittedSRVs[ShaderTypeInd] = std::max(m_NumCommittedSRVs[ShaderTypeInd], static_cast(NumSRVs)); + } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedSRVs(pShaderD3D11->GetDesc().ShaderType); - } -#endif + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedSRVs(pShaderD3D11->GetDesc().ShaderType); } +#endif } + } - // Commit samplers (no transitions for samplers) - if (CommitResources) + // Commit samplers (no transitions for samplers) + if (CommitResources) + { + auto NumSamplers = Cache.GetSamplerCount(); + if (NumSamplers) { - auto NumSamplers = Cache.GetSamplerCount(); - if (NumSamplers) + ShaderResourceCacheD3D11::CachedSampler* CachedSamplers; + ID3D11SamplerState** d3d11Samplers; + Cache.GetSamplerArrays(CachedSamplers, d3d11Samplers); + + auto* CommittedD3D11Samplers = m_CommittedD3D11Samplers[ShaderTypeInd]; + UINT MinSlot = std::numeric_limits::max(); + UINT MaxSlot = 0; + for (Uint32 sam = 0; sam < NumSamplers; ++sam) { - ShaderResourceCacheD3D11::CachedSampler* CachedSamplers; - ID3D11SamplerState** d3d11Samplers; - Cache.GetSamplerArrays(CachedSamplers, d3d11Samplers); - - auto *CommittedD3D11Samplers = m_CommittedD3D11Samplers[ShaderTypeInd]; - UINT MinSlot = std::numeric_limits::max(); - UINT MaxSlot = 0; - for (Uint32 sam=0; sam < NumSamplers; ++sam) - { - VERIFY_EXPR(sam < Cache.GetSamplerCount()); + VERIFY_EXPR(sam < Cache.GetSamplerCount()); - bool IsNewSam = CommittedD3D11Samplers[sam] != d3d11Samplers[sam]; - MinSlot = IsNewSam ? std::min(MinSlot, sam) : MinSlot; - MaxSlot = IsNewSam ? sam : MaxSlot; + bool IsNewSam = CommittedD3D11Samplers[sam] != d3d11Samplers[sam]; + MinSlot = IsNewSam ? std::min(MinSlot, sam) : MinSlot; + MaxSlot = IsNewSam ? sam : MaxSlot; - CommittedD3D11Samplers[sam] = d3d11Samplers[sam]; - } + CommittedD3D11Samplers[sam] = d3d11Samplers[sam]; + } - if (MinSlot != UINT_MAX) - { - auto SetSamplerMethod = SetSamplerMethods[ShaderTypeInd]; - (m_pd3d11DeviceContext->*SetSamplerMethod)(MinSlot, MaxSlot-MinSlot+1, CommittedD3D11Samplers+MinSlot); - m_NumCommittedSamplers[ShaderTypeInd] = std::max(m_NumCommittedSamplers[ShaderTypeInd], static_cast(NumSamplers)); - } + if (MinSlot != UINT_MAX) + { + auto SetSamplerMethod = SetSamplerMethods[ShaderTypeInd]; + (m_pd3d11DeviceContext->*SetSamplerMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11Samplers + MinSlot); + m_NumCommittedSamplers[ShaderTypeInd] = std::max(m_NumCommittedSamplers[ShaderTypeInd], static_cast(NumSamplers)); + } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedSamplers(pShaderD3D11->GetDesc().ShaderType); - } -#endif + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedSamplers(pShaderD3D11->GetDesc().ShaderType); } +#endif } + } #ifdef DEVELOPMENT - if (CommitResources && (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_SHADER_RESOURCES) != 0) - { - // Use full resource layout to verify that all required resources are committed - pShaderD3D11->GetD3D11Resources()->dvpVerifyCommittedResources( - m_CommittedD3D11CBs[ShaderTypeInd], - m_CommittedD3D11SRVs[ShaderTypeInd], - m_CommittedD3D11SRVResources[ShaderTypeInd], - m_CommittedD3D11Samplers[ShaderTypeInd], - m_CommittedD3D11UAVs[ShaderTypeInd], - m_CommittedD3D11UAVResources[ShaderTypeInd], - Cache); - } -#endif + if (CommitResources && (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_SHADER_RESOURCES) != 0) + { + // Use full resource layout to verify that all required resources are committed + pShaderD3D11->GetD3D11Resources()->dvpVerifyCommittedResources( + m_CommittedD3D11CBs[ShaderTypeInd], + m_CommittedD3D11SRVs[ShaderTypeInd], + m_CommittedD3D11SRVResources[ShaderTypeInd], + m_CommittedD3D11Samplers[ShaderTypeInd], + m_CommittedD3D11UAVs[ShaderTypeInd], + m_CommittedD3D11UAVResources[ShaderTypeInd], + Cache); } +#endif } +} - void DeviceContextD3D11Impl::TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) - { - DEV_CHECK_ERR(pPipelineState != nullptr, "Pipeline state must not be null"); - DEV_CHECK_ERR(pShaderResourceBinding != nullptr, "Shader resource binding must not be null"); - TransitionAndCommitShaderResources(pPipelineState, pShaderResourceBinding, false); - } +void DeviceContextD3D11Impl::TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) +{ + DEV_CHECK_ERR(pPipelineState != nullptr, "Pipeline state must not be null"); + DEV_CHECK_ERR(pShaderResourceBinding != nullptr, "Shader resource binding must not be null"); + TransitionAndCommitShaderResources(pPipelineState, pShaderResourceBinding, false); +} - void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) - { - if (!DeviceContextBase::CommitShaderResources(pShaderResourceBinding, StateTransitionMode, 0 /*Dummy*/)) - return; +void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + if (!DeviceContextBase::CommitShaderResources(pShaderResourceBinding, StateTransitionMode, 0 /*Dummy*/)) + return; - if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) - TransitionAndCommitShaderResources(m_pPipelineState, pShaderResourceBinding, false); - else - TransitionAndCommitShaderResources(m_pPipelineState, pShaderResourceBinding, StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY); - } + if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) + TransitionAndCommitShaderResources(m_pPipelineState, pShaderResourceBinding, false); + else + TransitionAndCommitShaderResources(m_pPipelineState, pShaderResourceBinding, StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY); +} - void DeviceContextD3D11Impl::SetStencilRef(Uint32 StencilRef) +void DeviceContextD3D11Impl::SetStencilRef(Uint32 StencilRef) +{ + if (TDeviceContextBase::SetStencilRef(StencilRef, 0)) { - if (TDeviceContextBase::SetStencilRef(StencilRef, 0)) - { - ID3D11DepthStencilState* pd3d11DSS = - m_pPipelineState ? m_pPipelineState->GetD3D11DepthStencilState() : nullptr; - m_pd3d11DeviceContext->OMSetDepthStencilState( pd3d11DSS, m_StencilRef ); - } + ID3D11DepthStencilState* pd3d11DSS = + m_pPipelineState ? m_pPipelineState->GetD3D11DepthStencilState() : nullptr; + m_pd3d11DeviceContext->OMSetDepthStencilState(pd3d11DSS, m_StencilRef); } +} - void DeviceContextD3D11Impl::SetBlendFactors(const float* pBlendFactors) +void DeviceContextD3D11Impl::SetBlendFactors(const float* pBlendFactors) +{ + if (TDeviceContextBase::SetBlendFactors(pBlendFactors, 0)) { - if (TDeviceContextBase::SetBlendFactors(pBlendFactors, 0)) + Uint32 SampleMask = 0xFFFFFFFF; + ID3D11BlendState* pd3d11BS = nullptr; + if (m_pPipelineState) { - Uint32 SampleMask = 0xFFFFFFFF; - ID3D11BlendState* pd3d11BS = nullptr; - if (m_pPipelineState) - { - SampleMask = m_pPipelineState->GetDesc().GraphicsPipeline.SampleMask; - pd3d11BS = m_pPipelineState->GetD3D11BlendState(); - } - m_pd3d11DeviceContext->OMSetBlendState(pd3d11BS, m_BlendFactors, SampleMask); + SampleMask = m_pPipelineState->GetDesc().GraphicsPipeline.SampleMask; + pd3d11BS = m_pPipelineState->GetD3D11BlendState(); } + m_pd3d11DeviceContext->OMSetBlendState(pd3d11BS, m_BlendFactors, SampleMask); + } +} + +void DeviceContextD3D11Impl::CommitD3D11IndexBuffer(VALUE_TYPE IndexType) +{ + if (!m_pIndexBuffer) + { + LOG_ERROR_MESSAGE("Index buffer is not set up for indexed draw command"); + return; } - void DeviceContextD3D11Impl::CommitD3D11IndexBuffer(VALUE_TYPE IndexType) + BufferD3D11Impl* pBuffD3D11 = m_pIndexBuffer.RawPtr(); + if (m_CommittedD3D11IndexBuffer != pBuffD3D11->m_pd3d11Buffer || + m_CommittedIBFormat != IndexType || + m_CommittedD3D11IndexDataStartOffset != m_IndexDataStartOffset) { - if (!m_pIndexBuffer) + DXGI_FORMAT D3D11IndexFmt = DXGI_FORMAT_UNKNOWN; + if (IndexType == VT_UINT32) + D3D11IndexFmt = DXGI_FORMAT_R32_UINT; + else if (IndexType == VT_UINT16) + D3D11IndexFmt = DXGI_FORMAT_R16_UINT; + else { - LOG_ERROR_MESSAGE( "Index buffer is not set up for indexed draw command" ); + LOG_ERROR_MESSAGE("Unsupported index format. Only R16_UINT and R32_UINT are allowed."); return; } - BufferD3D11Impl* pBuffD3D11 = m_pIndexBuffer.RawPtr(); - if( m_CommittedD3D11IndexBuffer != pBuffD3D11->m_pd3d11Buffer || - m_CommittedIBFormat != IndexType || - m_CommittedD3D11IndexDataStartOffset != m_IndexDataStartOffset ) - { - DXGI_FORMAT D3D11IndexFmt = DXGI_FORMAT_UNKNOWN; - if (IndexType == VT_UINT32) - D3D11IndexFmt = DXGI_FORMAT_R32_UINT; - else if (IndexType == VT_UINT16) - D3D11IndexFmt = DXGI_FORMAT_R16_UINT; - else - { - LOG_ERROR_MESSAGE( "Unsupported index format. Only R16_UINT and R32_UINT are allowed." ); - return; - } + m_CommittedD3D11IndexBuffer = pBuffD3D11->m_pd3d11Buffer; + m_CommittedIBFormat = IndexType; + m_CommittedD3D11IndexDataStartOffset = m_IndexDataStartOffset; + m_pd3d11DeviceContext->IASetIndexBuffer(pBuffD3D11->m_pd3d11Buffer, D3D11IndexFmt, m_IndexDataStartOffset); + } - m_CommittedD3D11IndexBuffer = pBuffD3D11->m_pd3d11Buffer; - m_CommittedIBFormat = IndexType; - m_CommittedD3D11IndexDataStartOffset = m_IndexDataStartOffset; - m_pd3d11DeviceContext->IASetIndexBuffer( pBuffD3D11->m_pd3d11Buffer, D3D11IndexFmt, m_IndexDataStartOffset ); - } + pBuffD3D11->AddState(RESOURCE_STATE_INDEX_BUFFER); + m_bCommittedD3D11IBUpToDate = true; +} - pBuffD3D11->AddState(RESOURCE_STATE_INDEX_BUFFER); - m_bCommittedD3D11IBUpToDate = true; - } +void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pPipelineStateD3D11) +{ + VERIFY(m_NumVertexStreams <= MaxBufferSlots, "Too many buffers are being set"); + UINT NumBuffersToSet = std::max(m_NumVertexStreams, m_NumCommittedD3D11VBs); - void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pPipelineStateD3D11) - { - VERIFY( m_NumVertexStreams <= MaxBufferSlots, "Too many buffers are being set" ); - UINT NumBuffersToSet = std::max(m_NumVertexStreams, m_NumCommittedD3D11VBs ); + bool BindVBs = m_NumVertexStreams != m_NumCommittedD3D11VBs; - bool BindVBs = m_NumVertexStreams != m_NumCommittedD3D11VBs; + for (UINT Slot = 0; Slot < m_NumVertexStreams; ++Slot) + { + auto& CurrStream = m_VertexStreams[Slot]; + auto* pBuffD3D11Impl = CurrStream.pBuffer.RawPtr(); + ID3D11Buffer* pd3d11Buffer = pBuffD3D11Impl ? pBuffD3D11Impl->m_pd3d11Buffer : nullptr; + auto Stride = pPipelineStateD3D11->GetBufferStride(Slot); + auto Offset = CurrStream.Offset; - for (UINT Slot = 0; Slot < m_NumVertexStreams; ++Slot) + // It is safe to perform raw pointer check because device context keeps + // all buffers alive. + if (m_CommittedD3D11VertexBuffers[Slot] != pd3d11Buffer || + m_CommittedD3D11VBStrides[Slot] != Stride || + m_CommittedD3D11VBOffsets[Slot] != Offset) { - auto& CurrStream = m_VertexStreams[Slot]; - auto* pBuffD3D11Impl = CurrStream.pBuffer.RawPtr(); - ID3D11Buffer* pd3d11Buffer = pBuffD3D11Impl ? pBuffD3D11Impl->m_pd3d11Buffer : nullptr; - auto Stride = pPipelineStateD3D11->GetBufferStride(Slot); - auto Offset = CurrStream.Offset; - - // It is safe to perform raw pointer check because device context keeps - // all buffers alive. - if (m_CommittedD3D11VertexBuffers[Slot] != pd3d11Buffer || - m_CommittedD3D11VBStrides[Slot] != Stride || - m_CommittedD3D11VBOffsets[Slot] != Offset) - { - BindVBs = true; + BindVBs = true; - m_CommittedD3D11VertexBuffers[Slot] = pd3d11Buffer; - m_CommittedD3D11VBStrides[Slot] = Stride; - m_CommittedD3D11VBOffsets[Slot] = Offset; + m_CommittedD3D11VertexBuffers[Slot] = pd3d11Buffer; + m_CommittedD3D11VBStrides[Slot] = Stride; + m_CommittedD3D11VBOffsets[Slot] = Offset; - if (pBuffD3D11Impl) - pBuffD3D11Impl->AddState(RESOURCE_STATE_VERTEX_BUFFER); - } + if (pBuffD3D11Impl) + pBuffD3D11Impl->AddState(RESOURCE_STATE_VERTEX_BUFFER); } + } - // Unbind all buffers at the end - for (Uint32 Slot = m_NumVertexStreams; Slot < m_NumCommittedD3D11VBs; ++Slot) - { - m_CommittedD3D11VertexBuffers[Slot] = nullptr; - m_CommittedD3D11VBStrides[Slot] = 0; - m_CommittedD3D11VBOffsets[Slot] = 0; - } + // Unbind all buffers at the end + for (Uint32 Slot = m_NumVertexStreams; Slot < m_NumCommittedD3D11VBs; ++Slot) + { + m_CommittedD3D11VertexBuffers[Slot] = nullptr; + m_CommittedD3D11VBStrides[Slot] = 0; + m_CommittedD3D11VBOffsets[Slot] = 0; + } - m_NumCommittedD3D11VBs = m_NumVertexStreams; - - if( BindVBs ) - { - m_pd3d11DeviceContext->IASetVertexBuffers( 0, NumBuffersToSet, m_CommittedD3D11VertexBuffers, m_CommittedD3D11VBStrides, m_CommittedD3D11VBOffsets ); - } + m_NumCommittedD3D11VBs = m_NumVertexStreams; - m_bCommittedD3D11VBsUpToDate = true; + if (BindVBs) + { + m_pd3d11DeviceContext->IASetVertexBuffers(0, NumBuffersToSet, m_CommittedD3D11VertexBuffers, m_CommittedD3D11VBStrides, m_CommittedD3D11VBOffsets); } - void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags) - { + m_bCommittedD3D11VBsUpToDate = true; +} + +void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags) +{ #ifdef DEVELOPMENT - if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) - DvpVerifyRenderTargets(); + if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) + DvpVerifyRenderTargets(); #endif - auto* pd3d11InputLayout = m_pPipelineState->GetD3D11InputLayout(); - if (pd3d11InputLayout != nullptr && !m_bCommittedD3D11VBsUpToDate) - { - DEV_CHECK_ERR( m_NumVertexStreams >= m_pPipelineState->GetNumBufferSlotsUsed(), "Currently bound pipeline state '", m_pPipelineState->GetDesc().Name, "' expects ", m_pPipelineState->GetNumBufferSlotsUsed(), " input buffer slots, but only ", m_NumVertexStreams, " is bound"); - CommitD3D11VertexBuffers(m_pPipelineState); - } + auto* pd3d11InputLayout = m_pPipelineState->GetD3D11InputLayout(); + if (pd3d11InputLayout != nullptr && !m_bCommittedD3D11VBsUpToDate) + { + DEV_CHECK_ERR(m_NumVertexStreams >= m_pPipelineState->GetNumBufferSlotsUsed(), "Currently bound pipeline state '", m_pPipelineState->GetDesc().Name, "' expects ", m_pPipelineState->GetNumBufferSlotsUsed(), " input buffer slots, but only ", m_NumVertexStreams, " is bound"); + CommitD3D11VertexBuffers(m_pPipelineState); + } #ifdef DEVELOPMENT - if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0) + if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0) + { + for (UINT Slot = 0; Slot < m_NumVertexStreams; ++Slot) { - for (UINT Slot = 0; Slot < m_NumVertexStreams; ++Slot) + if (auto* pBuffD3D11Impl = m_VertexStreams[Slot].pBuffer.RawPtr()) { - if (auto* pBuffD3D11Impl = m_VertexStreams[Slot].pBuffer.RawPtr()) + if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11Impl->GetDesc().Name, "' used as vertex buffer at slot ", Slot, " is in RESOURCE_STATE_UNORDERED_ACCESS state. " - "Use appropriate transition mode or explicitly transition the buffer to RESOURCE_STATE_VERTEX_BUFFER state."); - } + LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11Impl->GetDesc().Name, "' used as vertex buffer at slot ", Slot, " is in RESOURCE_STATE_UNORDERED_ACCESS state. " + "Use appropriate transition mode or explicitly transition the buffer to RESOURCE_STATE_VERTEX_BUFFER state."); } } } - - if(m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - // Verify bindings after all resources are set - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - dbgVerifyCommittedVertexBuffers(); - dbgVerifyCommittedIndexBuffer(); - dbgVerifyCommittedShaders(); - } -#endif } - void DeviceContextD3D11Impl::PrepareForIndexedDraw(DRAW_FLAGS Flags, VALUE_TYPE IndexType) + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) { - if (m_CommittedIBFormat != IndexType) - m_bCommittedD3D11IBUpToDate = false; - if (!m_bCommittedD3D11IBUpToDate) - { - CommitD3D11IndexBuffer(IndexType); - } + // Verify bindings after all resources are set + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + dbgVerifyCommittedVertexBuffers(); + dbgVerifyCommittedIndexBuffer(); + dbgVerifyCommittedShaders(); + } +#endif +} + +void DeviceContextD3D11Impl::PrepareForIndexedDraw(DRAW_FLAGS Flags, VALUE_TYPE IndexType) +{ + if (m_CommittedIBFormat != IndexType) + m_bCommittedD3D11IBUpToDate = false; + if (!m_bCommittedD3D11IBUpToDate) + { + CommitD3D11IndexBuffer(IndexType); + } #ifdef DEVELOPMENT - if (Flags & DRAW_FLAG_VERIFY_STATES) + if (Flags & DRAW_FLAG_VERIFY_STATES) + { + if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - LOG_ERROR_MESSAGE("Buffer '", m_pIndexBuffer->GetDesc().Name, "' used as index buffer is in RESOURCE_STATE_UNORDERED_ACCESS state." - " Use appropriate state transition mode or explicitly transition the buffer to RESOURCE_STATE_INDEX_BUFFER state."); - - } + LOG_ERROR_MESSAGE("Buffer '", m_pIndexBuffer->GetDesc().Name, + "' used as index buffer is in RESOURCE_STATE_UNORDERED_ACCESS state." + " Use appropriate state transition mode or explicitly transition the buffer to RESOURCE_STATE_INDEX_BUFFER state."); } -#endif - // We need to commit index buffer first because PrepareForDraw - // may verify committed resources. - PrepareForDraw(Flags); } +#endif + // We need to commit index buffer first because PrepareForDraw + // may verify committed resources. + PrepareForDraw(Flags); +} - void DeviceContextD3D11Impl::Draw(const DrawAttribs& Attribs) - { - if (!DvpVerifyDrawArguments(Attribs)) - return; +void DeviceContextD3D11Impl::Draw(const DrawAttribs& Attribs) +{ + if (!DvpVerifyDrawArguments(Attribs)) + return; - PrepareForDraw(Attribs.Flags); + PrepareForDraw(Attribs.Flags); - if (Attribs.NumInstances > 1 || Attribs.FirstInstanceLocation != 0) - m_pd3d11DeviceContext->DrawInstanced(Attribs.NumVertices, Attribs.NumInstances, Attribs.StartVertexLocation, Attribs.FirstInstanceLocation); - else - m_pd3d11DeviceContext->Draw(Attribs.NumVertices, Attribs.StartVertexLocation); - } + if (Attribs.NumInstances > 1 || Attribs.FirstInstanceLocation != 0) + m_pd3d11DeviceContext->DrawInstanced(Attribs.NumVertices, Attribs.NumInstances, Attribs.StartVertexLocation, Attribs.FirstInstanceLocation); + else + m_pd3d11DeviceContext->Draw(Attribs.NumVertices, Attribs.StartVertexLocation); +} - void DeviceContextD3D11Impl::DrawIndexed(const DrawIndexedAttribs& Attribs) - { - if (!DvpVerifyDrawIndexedArguments(Attribs)) - return; +void DeviceContextD3D11Impl::DrawIndexed(const DrawIndexedAttribs& Attribs) +{ + if (!DvpVerifyDrawIndexedArguments(Attribs)) + return; - PrepareForIndexedDraw(Attribs.Flags, Attribs.IndexType); + PrepareForIndexedDraw(Attribs.Flags, Attribs.IndexType); - if (Attribs.NumInstances > 1 || Attribs.FirstInstanceLocation != 0) - m_pd3d11DeviceContext->DrawIndexedInstanced(Attribs.NumIndices, Attribs.NumInstances, Attribs.FirstIndexLocation, Attribs.BaseVertex, Attribs.FirstInstanceLocation); - else - m_pd3d11DeviceContext->DrawIndexed(Attribs.NumIndices, Attribs.FirstIndexLocation, Attribs.BaseVertex); - } + if (Attribs.NumInstances > 1 || Attribs.FirstInstanceLocation != 0) + m_pd3d11DeviceContext->DrawIndexedInstanced(Attribs.NumIndices, Attribs.NumInstances, Attribs.FirstIndexLocation, Attribs.BaseVertex, Attribs.FirstInstanceLocation); + else + m_pd3d11DeviceContext->DrawIndexed(Attribs.NumIndices, Attribs.FirstIndexLocation, Attribs.BaseVertex); +} - void DeviceContextD3D11Impl::DrawIndirect(const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) - { - if (!DvpVerifyDrawIndirectArguments(Attribs, pAttribsBuffer)) - return; +void DeviceContextD3D11Impl::DrawIndirect(const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) +{ + if (!DvpVerifyDrawIndirectArguments(Attribs, pAttribsBuffer)) + return; - PrepareForDraw(Attribs.Flags); - - auto* pIndirectDrawAttribsD3D11 = ValidatedCast(pAttribsBuffer); - ID3D11Buffer* pd3d11ArgsBuff = pIndirectDrawAttribsD3D11->m_pd3d11Buffer; - m_pd3d11DeviceContext->DrawInstancedIndirect( pd3d11ArgsBuff, Attribs.IndirectDrawArgsOffset ); - } + PrepareForDraw(Attribs.Flags); + auto* pIndirectDrawAttribsD3D11 = ValidatedCast(pAttribsBuffer); + ID3D11Buffer* pd3d11ArgsBuff = pIndirectDrawAttribsD3D11->m_pd3d11Buffer; + m_pd3d11DeviceContext->DrawInstancedIndirect(pd3d11ArgsBuff, Attribs.IndirectDrawArgsOffset); +} - void DeviceContextD3D11Impl::DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) - { - if (!DvpVerifyDrawIndexedIndirectArguments(Attribs, pAttribsBuffer)) - return; - PrepareForIndexedDraw(Attribs.Flags, Attribs.IndexType); - - auto* pIndirectDrawAttribsD3D11 = ValidatedCast(pAttribsBuffer); - ID3D11Buffer* pd3d11ArgsBuff = pIndirectDrawAttribsD3D11->m_pd3d11Buffer; - m_pd3d11DeviceContext->DrawIndexedInstancedIndirect( pd3d11ArgsBuff, Attribs.IndirectDrawArgsOffset ); - } +void DeviceContextD3D11Impl::DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) +{ + if (!DvpVerifyDrawIndexedIndirectArguments(Attribs, pAttribsBuffer)) + return; - void DeviceContextD3D11Impl::DispatchCompute(const DispatchComputeAttribs& Attribs) - { - if (!DvpVerifyDispatchArguments(Attribs)) - return; + PrepareForIndexedDraw(Attribs.Flags, Attribs.IndexType); + + auto* pIndirectDrawAttribsD3D11 = ValidatedCast(pAttribsBuffer); + ID3D11Buffer* pd3d11ArgsBuff = pIndirectDrawAttribsD3D11->m_pd3d11Buffer; + m_pd3d11DeviceContext->DrawIndexedInstancedIndirect(pd3d11ArgsBuff, Attribs.IndirectDrawArgsOffset); +} + +void DeviceContextD3D11Impl::DispatchCompute(const DispatchComputeAttribs& Attribs) +{ + if (!DvpVerifyDispatchArguments(Attribs)) + return; #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - // Verify bindings - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - dbgVerifyCommittedShaders(); - } + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + // Verify bindings + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + dbgVerifyCommittedShaders(); + } #endif - m_pd3d11DeviceContext->Dispatch(Attribs.ThreadGroupCountX, Attribs.ThreadGroupCountY, Attribs.ThreadGroupCountZ); - } + m_pd3d11DeviceContext->Dispatch(Attribs.ThreadGroupCountX, Attribs.ThreadGroupCountY, Attribs.ThreadGroupCountZ); +} - void DeviceContextD3D11Impl::DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) - { - if (!DvpVerifyDispatchIndirectArguments(Attribs, pAttribsBuffer)) - return; +void DeviceContextD3D11Impl::DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) +{ + if (!DvpVerifyDispatchIndirectArguments(Attribs, pAttribsBuffer)) + return; #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - // Verify bindings - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - dbgVerifyCommittedShaders(); - } + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + // Verify bindings + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + dbgVerifyCommittedShaders(); + } #endif - auto* pd3d11Buff = ValidatedCast(pAttribsBuffer)->GetD3D11Buffer(); - m_pd3d11DeviceContext->DispatchIndirect(pd3d11Buff, Attribs.DispatchArgsByteOffset); - } + auto* pd3d11Buff = ValidatedCast(pAttribsBuffer)->GetD3D11Buffer(); + m_pd3d11DeviceContext->DispatchIndirect(pd3d11Buff, Attribs.DispatchArgsByteOffset); +} - void DeviceContextD3D11Impl::ClearDepthStencil(ITextureView* pView, - CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, - float fDepth, - Uint8 Stencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +void DeviceContextD3D11Impl::ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + if (pView == nullptr) { - if (pView == nullptr) + if (m_pSwapChain) { - if (m_pSwapChain) - { - pView = m_pSwapChain->GetDepthBufferDSV(); - if (pView == nullptr) - { - LOG_WARNING_MESSAGE("Depth buffer is not initialized in the swap chain. Clear operation will be ignored."); - return; - } - } - else + pView = m_pSwapChain->GetDepthBufferDSV(); + if (pView == nullptr) { - LOG_ERROR("Failed to clear default depth stencil buffer: swap chain is not initialized in the device context"); + LOG_WARNING_MESSAGE("Depth buffer is not initialized in the swap chain. Clear operation will be ignored."); return; } } + else + { + LOG_ERROR("Failed to clear default depth stencil buffer: swap chain is not initialized in the device context"); + return; + } + } #ifdef DEVELOPMENT - const auto& ViewDesc = pView->GetDesc(); - VERIFY( ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" ); + const auto& ViewDesc = pView->GetDesc(); + VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected"); #endif - auto* pViewD3D11 = ValidatedCast(pView); - auto* pd3d11DSV = static_cast(pViewD3D11->GetD3D11View()); - - UINT32 d3d11ClearFlags = 0; - if( ClearFlags & CLEAR_DEPTH_FLAG ) d3d11ClearFlags |= D3D11_CLEAR_DEPTH; - if( ClearFlags & CLEAR_STENCIL_FLAG ) d3d11ClearFlags |= D3D11_CLEAR_STENCIL; - // The full extent of the resource view is always cleared. - // Viewport and scissor settings are not applied. - m_pd3d11DeviceContext->ClearDepthStencilView( pd3d11DSV, d3d11ClearFlags, fDepth, Stencil ); - } + auto* pViewD3D11 = ValidatedCast(pView); + auto* pd3d11DSV = static_cast(pViewD3D11->GetD3D11View()); + + UINT32 d3d11ClearFlags = 0; + if (ClearFlags & CLEAR_DEPTH_FLAG) d3d11ClearFlags |= D3D11_CLEAR_DEPTH; + if (ClearFlags & CLEAR_STENCIL_FLAG) d3d11ClearFlags |= D3D11_CLEAR_STENCIL; + // The full extent of the resource view is always cleared. + // Viewport and scissor settings are not applied. + m_pd3d11DeviceContext->ClearDepthStencilView(pd3d11DSV, d3d11ClearFlags, fDepth, Stencil); +} - void DeviceContextD3D11Impl::ClearRenderTarget( ITextureView* pView, const float *RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) +void DeviceContextD3D11Impl::ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + if (pView == nullptr) { - if (pView == nullptr) + if (m_pSwapChain != nullptr) { - if (m_pSwapChain != nullptr) - { - pView = m_pSwapChain->GetCurrentBackBufferRTV(); - } - else - { - LOG_ERROR("Failed to clear default render target: swap chain is not initialized in the device context"); - return; - } + pView = m_pSwapChain->GetCurrentBackBufferRTV(); } + else + { + LOG_ERROR("Failed to clear default render target: swap chain is not initialized in the device context"); + return; + } + } #ifdef DEVELOPMENT - const auto& ViewDesc = pView->GetDesc(); - VERIFY( ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" ); + const auto& ViewDesc = pView->GetDesc(); + VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected"); #endif - auto* pViewD3D11 = ValidatedCast(pView); - auto* pd3d11RTV = static_cast(pViewD3D11->GetD3D11View()); - - static const float Zero[4] = { 0.f, 0.f, 0.f, 0.f }; - if( RGBA == nullptr ) - RGBA = Zero; - - // The full extent of the resource view is always cleared. - // Viewport and scissor settings are not applied. - m_pd3d11DeviceContext->ClearRenderTargetView( pd3d11RTV, RGBA ); - } + auto* pViewD3D11 = ValidatedCast(pView); + auto* pd3d11RTV = static_cast(pViewD3D11->GetD3D11View()); - void DeviceContextD3D11Impl::Flush() - { - m_pd3d11DeviceContext->Flush(); - } + static const float Zero[4] = {0.f, 0.f, 0.f, 0.f}; + if (RGBA == nullptr) + RGBA = Zero; - void DeviceContextD3D11Impl::UpdateBuffer(IBuffer* pBuffer, - Uint32 Offset, - Uint32 Size, - const PVoid pData, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) - { - TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData, StateTransitionMode); - - auto* pBufferD3D11Impl = ValidatedCast( pBuffer ); - - D3D11_BOX DstBox; - DstBox.left = Offset; - DstBox.right = Offset + Size; - DstBox.top = 0; - DstBox.bottom = 1; - DstBox.front = 0; - DstBox.back = 1; - auto* pDstBox = (Offset == 0 && Size == pBufferD3D11Impl->GetDesc().uiSizeInBytes) ? nullptr : &DstBox; - m_pd3d11DeviceContext->UpdateSubresource(pBufferD3D11Impl->m_pd3d11Buffer, 0, pDstBox, pData, 0, 0); - } + // The full extent of the resource view is always cleared. + // Viewport and scissor settings are not applied. + m_pd3d11DeviceContext->ClearRenderTargetView(pd3d11RTV, RGBA); +} - void DeviceContextD3D11Impl::CopyBuffer(IBuffer* pSrcBuffer, - Uint32 SrcOffset, - RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, - IBuffer* pDstBuffer, - Uint32 DstOffset, - Uint32 Size, - RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) - { - TDeviceContextBase::CopyBuffer(pSrcBuffer, SrcOffset, SrcBufferTransitionMode, pDstBuffer, DstOffset, Size, DstBufferTransitionMode); +void DeviceContextD3D11Impl::Flush() +{ + m_pd3d11DeviceContext->Flush(); +} - auto* pSrcBufferD3D11Impl = ValidatedCast( pSrcBuffer ); - auto* pDstBufferD3D11Impl = ValidatedCast( pDstBuffer ); - - D3D11_BOX SrcBox; - SrcBox.left = SrcOffset; - SrcBox.right = SrcOffset + Size; - SrcBox.top = 0; - SrcBox.bottom = 1; - SrcBox.front = 0; - SrcBox.back = 1; - m_pd3d11DeviceContext->CopySubresourceRegion(pDstBufferD3D11Impl->m_pd3d11Buffer, 0, DstOffset, 0, 0, pSrcBufferD3D11Impl->m_pd3d11Buffer, 0, &SrcBox); - } +void DeviceContextD3D11Impl::UpdateBuffer(IBuffer* pBuffer, + Uint32 Offset, + Uint32 Size, + const PVoid pData, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData, StateTransitionMode); + + auto* pBufferD3D11Impl = ValidatedCast(pBuffer); + + D3D11_BOX DstBox; + DstBox.left = Offset; + DstBox.right = Offset + Size; + DstBox.top = 0; + DstBox.bottom = 1; + DstBox.front = 0; + DstBox.back = 1; + auto* pDstBox = (Offset == 0 && Size == pBufferD3D11Impl->GetDesc().uiSizeInBytes) ? nullptr : &DstBox; + m_pd3d11DeviceContext->UpdateSubresource(pBufferD3D11Impl->m_pd3d11Buffer, 0, pDstBox, pData, 0, 0); +} +void DeviceContextD3D11Impl::CopyBuffer(IBuffer* pSrcBuffer, + Uint32 SrcOffset, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + IBuffer* pDstBuffer, + Uint32 DstOffset, + Uint32 Size, + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) +{ + TDeviceContextBase::CopyBuffer(pSrcBuffer, SrcOffset, SrcBufferTransitionMode, pDstBuffer, DstOffset, Size, DstBufferTransitionMode); + + auto* pSrcBufferD3D11Impl = ValidatedCast(pSrcBuffer); + auto* pDstBufferD3D11Impl = ValidatedCast(pDstBuffer); + + D3D11_BOX SrcBox; + SrcBox.left = SrcOffset; + SrcBox.right = SrcOffset + Size; + SrcBox.top = 0; + SrcBox.bottom = 1; + SrcBox.front = 0; + SrcBox.back = 1; + m_pd3d11DeviceContext->CopySubresourceRegion(pDstBufferD3D11Impl->m_pd3d11Buffer, 0, DstOffset, 0, 0, pSrcBufferD3D11Impl->m_pd3d11Buffer, 0, &SrcBox); +} - void DeviceContextD3D11Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) - { - TDeviceContextBase::MapBuffer(pBuffer, MapType, MapFlags, pMappedData); - auto* pBufferD3D11 = ValidatedCast(pBuffer); - D3D11_MAP d3d11MapType = static_cast(0); - UINT d3d11MapFlags = 0; - MapParamsToD3D11MapParams(MapType, MapFlags, d3d11MapType, d3d11MapFlags); +void DeviceContextD3D11Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) +{ + TDeviceContextBase::MapBuffer(pBuffer, MapType, MapFlags, pMappedData); - D3D11_MAPPED_SUBRESOURCE MappedBuff; - HRESULT hr = m_pd3d11DeviceContext->Map(pBufferD3D11->m_pd3d11Buffer, 0, d3d11MapType, d3d11MapFlags, &MappedBuff); - DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to map buffer '", pBufferD3D11->GetDesc().Name, "'"); - pMappedData = SUCCEEDED(hr) ? MappedBuff.pData : nullptr; - } + auto* pBufferD3D11 = ValidatedCast(pBuffer); + D3D11_MAP d3d11MapType = static_cast(0); + UINT d3d11MapFlags = 0; + MapParamsToD3D11MapParams(MapType, MapFlags, d3d11MapType, d3d11MapFlags); - void DeviceContextD3D11Impl::UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) - { - TDeviceContextBase::UnmapBuffer(pBuffer, MapType); - auto* pBufferD3D11 = ValidatedCast(pBuffer); - m_pd3d11DeviceContext->Unmap(pBufferD3D11->m_pd3d11Buffer, 0); - } + D3D11_MAPPED_SUBRESOURCE MappedBuff; + HRESULT hr = m_pd3d11DeviceContext->Map(pBufferD3D11->m_pd3d11Buffer, 0, d3d11MapType, d3d11MapFlags, &MappedBuff); + DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to map buffer '", pBufferD3D11->GetDesc().Name, "'"); + pMappedData = SUCCEEDED(hr) ? MappedBuff.pData : nullptr; +} - void DeviceContextD3D11Impl::UpdateTexture(ITexture* pTexture, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData, - RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, - RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode) - { - TDeviceContextBase::UpdateTexture( pTexture, MipLevel, Slice, DstBox, SubresData, SrcBufferTransitionMode, DstTextureTransitionMode ); +void DeviceContextD3D11Impl::UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) +{ + TDeviceContextBase::UnmapBuffer(pBuffer, MapType); + auto* pBufferD3D11 = ValidatedCast(pBuffer); + m_pd3d11DeviceContext->Unmap(pBufferD3D11->m_pd3d11Buffer, 0); +} - auto* pTexD3D11 = ValidatedCast(pTexture); - const auto& Desc = pTexD3D11->GetDesc(); +void DeviceContextD3D11Impl::UpdateTexture(ITexture* pTexture, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode) +{ + TDeviceContextBase::UpdateTexture(pTexture, MipLevel, Slice, DstBox, SubresData, SrcBufferTransitionMode, DstTextureTransitionMode); - // OpenGL backend uses UpdateData() to initialize textures, so we can't check the usage in ValidateUpdateTextureParams() - DEV_CHECK_ERR( Desc.Usage == USAGE_DEFAULT, "Only USAGE_DEFAULT textures should be updated with UpdateData()" ); + auto* pTexD3D11 = ValidatedCast(pTexture); + const auto& Desc = pTexD3D11->GetDesc(); - if (SubresData.pSrcBuffer != nullptr) - { - LOG_ERROR("D3D11 does not support updating texture subresource from a GPU buffer"); - return; - } + // OpenGL backend uses UpdateData() to initialize textures, so we can't check the usage in ValidateUpdateTextureParams() + DEV_CHECK_ERR(Desc.Usage == USAGE_DEFAULT, "Only USAGE_DEFAULT textures should be updated with UpdateData()"); - D3D11_BOX D3D11Box; - D3D11Box.left = DstBox.MinX; - D3D11Box.right = DstBox.MaxX; - D3D11Box.top = DstBox.MinY; - D3D11Box.bottom = DstBox.MaxY; - D3D11Box.front = DstBox.MinZ; - D3D11Box.back = DstBox.MaxZ; - const auto& FmtAttribs = GetTextureFormatAttribs(Desc.Format); - if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) - { - // Align update region by the compressed block size - VERIFY( (D3D11Box.left % FmtAttribs.BlockWidth) == 0, "Update region min X coordinate (", D3D11Box.left, ") must be multiple of a compressed block width (", Uint32{FmtAttribs.BlockWidth}, ")"); - VERIFY( (FmtAttribs.BlockWidth & (FmtAttribs.BlockWidth-1)) == 0, "Compressed block width (", Uint32{FmtAttribs.BlockWidth}, ") is expected to be power of 2"); - D3D11Box.right = (D3D11Box.right + FmtAttribs.BlockWidth-1) & ~(FmtAttribs.BlockWidth-1); - - VERIFY( (D3D11Box.top % FmtAttribs.BlockHeight) == 0, "Update region min Y coordinate (", D3D11Box.top, ") must be multiple of a compressed block height (", Uint32{FmtAttribs.BlockHeight}, ")"); - VERIFY( (FmtAttribs.BlockHeight & (FmtAttribs.BlockHeight-1)) == 0, "Compressed block height (", Uint32{FmtAttribs.BlockHeight}, ") is expected to be power of 2"); - D3D11Box.bottom = (D3D11Box.bottom + FmtAttribs.BlockHeight-1) & ~(FmtAttribs.BlockHeight-1); - } - auto SubresIndex = D3D11CalcSubresource(MipLevel, Slice, Desc.MipLevels); - m_pd3d11DeviceContext->UpdateSubresource(pTexD3D11->GetD3D11Texture(), SubresIndex, &D3D11Box, SubresData.pData, SubresData.Stride, SubresData.DepthStride); + if (SubresData.pSrcBuffer != nullptr) + { + LOG_ERROR("D3D11 does not support updating texture subresource from a GPU buffer"); + return; } - void DeviceContextD3D11Impl::CopyTexture(const CopyTextureAttribs& CopyAttribs) + D3D11_BOX D3D11Box; + D3D11Box.left = DstBox.MinX; + D3D11Box.right = DstBox.MaxX; + D3D11Box.top = DstBox.MinY; + D3D11Box.bottom = DstBox.MaxY; + D3D11Box.front = DstBox.MinZ; + D3D11Box.back = DstBox.MaxZ; + const auto& FmtAttribs = GetTextureFormatAttribs(Desc.Format); + if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) { - TDeviceContextBase::CopyTexture( CopyAttribs ); + // Align update region by the compressed block size + VERIFY((D3D11Box.left % FmtAttribs.BlockWidth) == 0, "Update region min X coordinate (", D3D11Box.left, ") must be multiple of a compressed block width (", Uint32{FmtAttribs.BlockWidth}, ")"); + VERIFY((FmtAttribs.BlockWidth & (FmtAttribs.BlockWidth - 1)) == 0, "Compressed block width (", Uint32{FmtAttribs.BlockWidth}, ") is expected to be power of 2"); + D3D11Box.right = (D3D11Box.right + FmtAttribs.BlockWidth - 1) & ~(FmtAttribs.BlockWidth - 1); - auto* pSrcTexD3D11 = ValidatedCast( CopyAttribs.pSrcTexture ); - auto* pDstTexD3D11 = ValidatedCast( CopyAttribs.pDstTexture ); - - D3D11_BOX D3D11SrcBox,* pD3D11SrcBox = nullptr; - if (const auto* pSrcBox = CopyAttribs.pSrcBox) - { - D3D11SrcBox.left = pSrcBox->MinX; - D3D11SrcBox.right = pSrcBox->MaxX; - D3D11SrcBox.top = pSrcBox->MinY; - D3D11SrcBox.bottom = pSrcBox->MaxY; - D3D11SrcBox.front = pSrcBox->MinZ; - D3D11SrcBox.back = pSrcBox->MaxZ; - pD3D11SrcBox = &D3D11SrcBox; - } - auto SrcSubRes = D3D11CalcSubresource(CopyAttribs.SrcMipLevel, CopyAttribs.SrcSlice, pSrcTexD3D11->GetDesc().MipLevels); - auto DstSubRes = D3D11CalcSubresource(CopyAttribs.DstMipLevel, CopyAttribs.DstSlice, pDstTexD3D11->GetDesc().MipLevels); - m_pd3d11DeviceContext->CopySubresourceRegion(pDstTexD3D11->GetD3D11Texture(), DstSubRes, CopyAttribs.DstX, CopyAttribs.DstY, CopyAttribs.DstZ, - pSrcTexD3D11->GetD3D11Texture(), SrcSubRes, pD3D11SrcBox); + VERIFY((D3D11Box.top % FmtAttribs.BlockHeight) == 0, "Update region min Y coordinate (", D3D11Box.top, ") must be multiple of a compressed block height (", Uint32{FmtAttribs.BlockHeight}, ")"); + VERIFY((FmtAttribs.BlockHeight & (FmtAttribs.BlockHeight - 1)) == 0, "Compressed block height (", Uint32{FmtAttribs.BlockHeight}, ") is expected to be power of 2"); + D3D11Box.bottom = (D3D11Box.bottom + FmtAttribs.BlockHeight - 1) & ~(FmtAttribs.BlockHeight - 1); } + auto SubresIndex = D3D11CalcSubresource(MipLevel, Slice, Desc.MipLevels); + m_pd3d11DeviceContext->UpdateSubresource(pTexD3D11->GetD3D11Texture(), SubresIndex, &D3D11Box, SubresData.pData, SubresData.Stride, SubresData.DepthStride); +} +void DeviceContextD3D11Impl::CopyTexture(const CopyTextureAttribs& CopyAttribs) +{ + TDeviceContextBase::CopyTexture(CopyAttribs); + + auto* pSrcTexD3D11 = ValidatedCast(CopyAttribs.pSrcTexture); + auto* pDstTexD3D11 = ValidatedCast(CopyAttribs.pDstTexture); + + D3D11_BOX D3D11SrcBox, *pD3D11SrcBox = nullptr; + if (const auto* pSrcBox = CopyAttribs.pSrcBox) + { + D3D11SrcBox.left = pSrcBox->MinX; + D3D11SrcBox.right = pSrcBox->MaxX; + D3D11SrcBox.top = pSrcBox->MinY; + D3D11SrcBox.bottom = pSrcBox->MaxY; + D3D11SrcBox.front = pSrcBox->MinZ; + D3D11SrcBox.back = pSrcBox->MaxZ; + pD3D11SrcBox = &D3D11SrcBox; + } + auto SrcSubRes = D3D11CalcSubresource(CopyAttribs.SrcMipLevel, CopyAttribs.SrcSlice, pSrcTexD3D11->GetDesc().MipLevels); + auto DstSubRes = D3D11CalcSubresource(CopyAttribs.DstMipLevel, CopyAttribs.DstSlice, pDstTexD3D11->GetDesc().MipLevels); + m_pd3d11DeviceContext->CopySubresourceRegion(pDstTexD3D11->GetD3D11Texture(), DstSubRes, CopyAttribs.DstX, CopyAttribs.DstY, CopyAttribs.DstZ, + pSrcTexD3D11->GetD3D11Texture(), SrcSubRes, pD3D11SrcBox); +} - void DeviceContextD3D11Impl::MapTextureSubresource( ITexture* pTexture, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - MAP_FLAGS MapFlags, - const Box* pMapRegion, - MappedTextureSubresource& MappedData ) - { - TDeviceContextBase::MapTextureSubresource(pTexture, MipLevel, ArraySlice, MapType, MapFlags, pMapRegion, MappedData); - auto* pTexD3D11 = ValidatedCast(pTexture); - const auto& TexDesc = pTexD3D11->GetDesc(); - D3D11_MAP d3d11MapType = static_cast(0); - UINT d3d11MapFlags = 0; - MapParamsToD3D11MapParams(MapType, MapFlags, d3d11MapType, d3d11MapFlags); +void DeviceContextD3D11Impl::MapTextureSubresource(ITexture* pTexture, + Uint32 MipLevel, + Uint32 ArraySlice, + MAP_TYPE MapType, + MAP_FLAGS MapFlags, + const Box* pMapRegion, + MappedTextureSubresource& MappedData) +{ + TDeviceContextBase::MapTextureSubresource(pTexture, MipLevel, ArraySlice, MapType, MapFlags, pMapRegion, MappedData); - auto Subresource = D3D11CalcSubresource(MipLevel, ArraySlice, TexDesc.MipLevels); - D3D11_MAPPED_SUBRESOURCE MappedTex; - auto hr = m_pd3d11DeviceContext->Map(pTexD3D11->GetD3D11Texture(), Subresource, d3d11MapType, d3d11MapFlags, &MappedTex); - if( FAILED(hr) ) - { - VERIFY_EXPR( hr == DXGI_ERROR_WAS_STILL_DRAWING ); - MappedData = MappedTextureSubresource(); - } - else - { - MappedData.pData = MappedTex.pData; - MappedData.Stride = MappedTex.RowPitch; - MappedData.DepthStride = MappedTex.DepthPitch; - } - } + auto* pTexD3D11 = ValidatedCast(pTexture); + const auto& TexDesc = pTexD3D11->GetDesc(); + D3D11_MAP d3d11MapType = static_cast(0); + UINT d3d11MapFlags = 0; + MapParamsToD3D11MapParams(MapType, MapFlags, d3d11MapType, d3d11MapFlags); - void DeviceContextD3D11Impl::UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) + auto Subresource = D3D11CalcSubresource(MipLevel, ArraySlice, TexDesc.MipLevels); + D3D11_MAPPED_SUBRESOURCE MappedTex; + auto hr = m_pd3d11DeviceContext->Map(pTexD3D11->GetD3D11Texture(), Subresource, d3d11MapType, d3d11MapFlags, &MappedTex); + if (FAILED(hr)) { - TDeviceContextBase::UnmapTextureSubresource( pTexture, MipLevel, ArraySlice); - - auto* pTexD3D11 = ValidatedCast(pTexture); - const auto& TexDesc = pTexD3D11->GetDesc(); - auto Subresource = D3D11CalcSubresource(MipLevel, ArraySlice, TexDesc.MipLevels); - m_pd3d11DeviceContext->Unmap(pTexD3D11->GetD3D11Texture(), Subresource); + VERIFY_EXPR(hr == DXGI_ERROR_WAS_STILL_DRAWING); + MappedData = MappedTextureSubresource(); } - - void DeviceContextD3D11Impl::GenerateMips(ITextureView* pTextureView) + else { - TDeviceContextBase::GenerateMips(pTextureView); - auto& TexViewD3D11 = *ValidatedCast(pTextureView); - auto* pd3d11SRV = static_cast( TexViewD3D11.GetD3D11View() ); - m_pd3d11DeviceContext->GenerateMips(pd3d11SRV); + MappedData.pData = MappedTex.pData; + MappedData.Stride = MappedTex.RowPitch; + MappedData.DepthStride = MappedTex.DepthPitch; } +} - void DeviceContextD3D11Impl::FinishFrame() - { - } +void DeviceContextD3D11Impl::UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) +{ + TDeviceContextBase::UnmapTextureSubresource(pTexture, MipLevel, ArraySlice); - void DeviceContextD3D11Impl::SetVertexBuffers( Uint32 StartSlot, - Uint32 NumBuffersSet, - IBuffer** ppBuffers, - Uint32* pOffsets, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, - SET_VERTEX_BUFFERS_FLAGS Flags ) - { - TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pOffsets, StateTransitionMode, Flags ); - for (Uint32 Slot = 0; Slot < m_NumVertexStreams; ++Slot) - { - auto& CurrStream = m_VertexStreams[Slot]; - if (auto* pBuffD3D11Impl = CurrStream.pBuffer.RawPtr()) - { - if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) - { - if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - UnbindResourceFromUAV(pBuffD3D11Impl, pBuffD3D11Impl->m_pd3d11Buffer); - pBuffD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); - } - } -#ifdef DEVELOPMENT - else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) - { - if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - { - LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11Impl->GetDesc().Name, "' used as vertex buffer at slot ", Slot, " is in RESOURCE_STATE_UNORDERED_ACCESS state. " - "Use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to RESOURCE_STATE_VERTEX_BUFFER state."); - } - } -#endif - } - } + auto* pTexD3D11 = ValidatedCast(pTexture); + const auto& TexDesc = pTexD3D11->GetDesc(); + auto Subresource = D3D11CalcSubresource(MipLevel, ArraySlice, TexDesc.MipLevels); + m_pd3d11DeviceContext->Unmap(pTexD3D11->GetD3D11Texture(), Subresource); +} - m_bCommittedD3D11VBsUpToDate = false; - } +void DeviceContextD3D11Impl::GenerateMips(ITextureView* pTextureView) +{ + TDeviceContextBase::GenerateMips(pTextureView); + auto& TexViewD3D11 = *ValidatedCast(pTextureView); + auto* pd3d11SRV = static_cast(TexViewD3D11.GetD3D11View()); + m_pd3d11DeviceContext->GenerateMips(pd3d11SRV); +} - void DeviceContextD3D11Impl::SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) - { - TDeviceContextBase::SetIndexBuffer( pIndexBuffer, ByteOffset, StateTransitionMode ); +void DeviceContextD3D11Impl::FinishFrame() +{ +} - if (m_pIndexBuffer) +void DeviceContextD3D11Impl::SetVertexBuffers(Uint32 StartSlot, + Uint32 NumBuffersSet, + IBuffer** ppBuffers, + Uint32* pOffsets, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, + SET_VERTEX_BUFFERS_FLAGS Flags) +{ + TDeviceContextBase::SetVertexBuffers(StartSlot, NumBuffersSet, ppBuffers, pOffsets, StateTransitionMode, Flags); + for (Uint32 Slot = 0; Slot < m_NumVertexStreams; ++Slot) + { + auto& CurrStream = m_VertexStreams[Slot]; + if (auto* pBuffD3D11Impl = CurrStream.pBuffer.RawPtr()) { if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { - if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - UnbindResourceFromUAV(m_pIndexBuffer, m_pIndexBuffer->m_pd3d11Buffer); - m_pIndexBuffer->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + UnbindResourceFromUAV(pBuffD3D11Impl, pBuffD3D11Impl->m_pd3d11Buffer); + pBuffD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); } } #ifdef DEVELOPMENT else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) { - if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) { - LOG_ERROR_MESSAGE("Buffer '", m_pIndexBuffer->GetDesc().Name, "' used as index buffer is in RESOURCE_STATE_UNORDERED_ACCESS state." - " Use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to RESOURCE_STATE_INDEX_BUFFER state."); - + LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11Impl->GetDesc().Name, "' used as vertex buffer at slot ", Slot, " is in RESOURCE_STATE_UNORDERED_ACCESS state. " + "Use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to RESOURCE_STATE_VERTEX_BUFFER state."); } } #endif } - - m_bCommittedD3D11IBUpToDate = false; } - void DeviceContextD3D11Impl::SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight ) + m_bCommittedD3D11VBsUpToDate = false; +} + +void DeviceContextD3D11Impl::SetIndexBuffer(IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + TDeviceContextBase::SetIndexBuffer(pIndexBuffer, ByteOffset, StateTransitionMode); + + if (m_pIndexBuffer) { - static_assert(MaxViewports >= D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, "MaxViewports constant must be greater than D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE"); - TDeviceContextBase::SetViewports( NumViewports, pViewports, RTWidth, RTHeight ); - - D3D11_VIEWPORT d3d11Viewports[MaxViewports]; - VERIFY( NumViewports == m_NumViewports, "Unexpected number of viewports" ); - for( Uint32 vp = 0; vp < m_NumViewports; ++vp ) + if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { - d3d11Viewports[vp].TopLeftX = m_Viewports[vp].TopLeftX; - d3d11Viewports[vp].TopLeftY = m_Viewports[vp].TopLeftY; - d3d11Viewports[vp].Width = m_Viewports[vp].Width; - d3d11Viewports[vp].Height = m_Viewports[vp].Height; - d3d11Viewports[vp].MinDepth = m_Viewports[vp].MinDepth; - d3d11Viewports[vp].MaxDepth = m_Viewports[vp].MaxDepth; + if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + { + UnbindResourceFromUAV(m_pIndexBuffer, m_pIndexBuffer->m_pd3d11Buffer); + m_pIndexBuffer->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + } + } +#ifdef DEVELOPMENT + else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) + { + if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + { + LOG_ERROR_MESSAGE("Buffer '", m_pIndexBuffer->GetDesc().Name, "' used as index buffer is in RESOURCE_STATE_UNORDERED_ACCESS state." + " Use RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to RESOURCE_STATE_INDEX_BUFFER state."); + } } - // All viewports must be set atomically as one operation. - // Any viewports not defined by the call are disabled. - m_pd3d11DeviceContext->RSSetViewports( NumViewports, d3d11Viewports ); +#endif } - void DeviceContextD3D11Impl::SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight ) - { - static_assert(MaxViewports >= D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, "MaxViewports constant must be greater than D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE"); - TDeviceContextBase::SetScissorRects(NumRects, pRects, RTWidth, RTHeight); + m_bCommittedD3D11IBUpToDate = false; +} - D3D11_RECT d3d11ScissorRects[MaxViewports]; - VERIFY( NumRects == m_NumScissorRects, "Unexpected number of scissor rects" ); - for( Uint32 sr = 0; sr < NumRects; ++sr ) - { - d3d11ScissorRects[sr].left = m_ScissorRects[sr].left; - d3d11ScissorRects[sr].top = m_ScissorRects[sr].top; - d3d11ScissorRects[sr].right = m_ScissorRects[sr].right; - d3d11ScissorRects[sr].bottom = m_ScissorRects[sr].bottom; - } +void DeviceContextD3D11Impl::SetViewports(Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight) +{ + static_assert(MaxViewports >= D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, "MaxViewports constant must be greater than D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE"); + TDeviceContextBase::SetViewports(NumViewports, pViewports, RTWidth, RTHeight); + + D3D11_VIEWPORT d3d11Viewports[MaxViewports]; + VERIFY(NumViewports == m_NumViewports, "Unexpected number of viewports"); + for (Uint32 vp = 0; vp < m_NumViewports; ++vp) + { + d3d11Viewports[vp].TopLeftX = m_Viewports[vp].TopLeftX; + d3d11Viewports[vp].TopLeftY = m_Viewports[vp].TopLeftY; + d3d11Viewports[vp].Width = m_Viewports[vp].Width; + d3d11Viewports[vp].Height = m_Viewports[vp].Height; + d3d11Viewports[vp].MinDepth = m_Viewports[vp].MinDepth; + d3d11Viewports[vp].MaxDepth = m_Viewports[vp].MaxDepth; + } + // All viewports must be set atomically as one operation. + // Any viewports not defined by the call are disabled. + m_pd3d11DeviceContext->RSSetViewports(NumViewports, d3d11Viewports); +} - // All scissor rects must be set atomically as one operation. - // Any scissor rects not defined by the call are disabled. - m_pd3d11DeviceContext->RSSetScissorRects( NumRects, d3d11ScissorRects ); - } +void DeviceContextD3D11Impl::SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight) +{ + static_assert(MaxViewports >= D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE, "MaxViewports constant must be greater than D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE"); + TDeviceContextBase::SetScissorRects(NumRects, pRects, RTWidth, RTHeight); - void DeviceContextD3D11Impl::CommitRenderTargets() + D3D11_RECT d3d11ScissorRects[MaxViewports]; + VERIFY(NumRects == m_NumScissorRects, "Unexpected number of scissor rects"); + for (Uint32 sr = 0; sr < NumRects; ++sr) { - const Uint32 MaxD3D11RTs = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; - Uint32 NumRenderTargets = m_NumBoundRenderTargets; - VERIFY( NumRenderTargets <= MaxD3D11RTs, "D3D11 only allows 8 simultaneous render targets" ); - NumRenderTargets = std::min( MaxD3D11RTs, NumRenderTargets ); + d3d11ScissorRects[sr].left = m_ScissorRects[sr].left; + d3d11ScissorRects[sr].top = m_ScissorRects[sr].top; + d3d11ScissorRects[sr].right = m_ScissorRects[sr].right; + d3d11ScissorRects[sr].bottom = m_ScissorRects[sr].bottom; + } + + // All scissor rects must be set atomically as one operation. + // Any scissor rects not defined by the call are disabled. + m_pd3d11DeviceContext->RSSetScissorRects(NumRects, d3d11ScissorRects); +} + +void DeviceContextD3D11Impl::CommitRenderTargets() +{ + const Uint32 MaxD3D11RTs = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; + Uint32 NumRenderTargets = m_NumBoundRenderTargets; + VERIFY(NumRenderTargets <= MaxD3D11RTs, "D3D11 only allows 8 simultaneous render targets"); + NumRenderTargets = std::min(MaxD3D11RTs, NumRenderTargets); - // Do not waste time setting RTVs to null - ID3D11RenderTargetView* pd3d11RTs[MaxD3D11RTs]; - ID3D11DepthStencilView* pd3d11DSV = nullptr; + // Do not waste time setting RTVs to null + ID3D11RenderTargetView* pd3d11RTs[MaxD3D11RTs]; + ID3D11DepthStencilView* pd3d11DSV = nullptr; - if (m_IsDefaultFramebufferBound) + if (m_IsDefaultFramebufferBound) + { + if (m_pSwapChain) { - if (m_pSwapChain) + NumRenderTargets = 1; + auto* pSwapChainD3D11 = m_pSwapChain.RawPtr(); + auto* pBackBufferViewD3D11 = pSwapChainD3D11->GetCurrentBackBufferRTV(); + pd3d11RTs[0] = static_cast(pBackBufferViewD3D11->GetD3D11View()); + VERIFY_EXPR(pd3d11RTs[0] != nullptr); + if (auto* pDepthBufferViewD3D11 = pSwapChainD3D11->GetDepthBufferDSV()) { - NumRenderTargets = 1; - auto* pSwapChainD3D11 = m_pSwapChain.RawPtr(); - auto* pBackBufferViewD3D11 = pSwapChainD3D11->GetCurrentBackBufferRTV(); - pd3d11RTs[0] = static_cast(pBackBufferViewD3D11->GetD3D11View()); - VERIFY_EXPR(pd3d11RTs[0] != nullptr); - if (auto* pDepthBufferViewD3D11 = pSwapChainD3D11->GetDepthBufferDSV()) - { - pd3d11DSV = static_cast(pDepthBufferViewD3D11->GetD3D11View()); - VERIFY_EXPR(pd3d11DSV != nullptr); - } - } - else - { - LOG_ERROR("Failed to commit default render target and depth stencil: swap chain is not initialized in the device context"); - return; + pd3d11DSV = static_cast(pDepthBufferViewD3D11->GetD3D11View()); + VERIFY_EXPR(pd3d11DSV != nullptr); } } else { - for (Uint32 rt = 0; rt < NumRenderTargets; ++rt) - { - auto* pViewD3D11 = m_pBoundRenderTargets[rt].RawPtr(); - pd3d11RTs[rt] = pViewD3D11 != nullptr ? static_cast(pViewD3D11->GetD3D11View()) : nullptr; - } - - if (m_pBoundDepthStencil != nullptr) - { - pd3d11DSV = static_cast(m_pBoundDepthStencil->GetD3D11View()); - } + LOG_ERROR("Failed to commit default render target and depth stencil: swap chain is not initialized in the device context"); + return; } - - auto& NumCommittedPixelShaderUAVs = m_NumCommittedUAVs[PSInd]; - if (NumCommittedPixelShaderUAVs > 0) + } + else + { + for (Uint32 rt = 0; rt < NumRenderTargets; ++rt) { - m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(NumRenderTargets, pd3d11RTs, pd3d11DSV, - 0, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr); - - auto CommittedD3D11UAVs = m_CommittedD3D11UAVs [PSInd]; - auto CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[PSInd]; - for(Uint32 slot = 0; slot < NumRenderTargets; ++slot) - { - CommittedD3D11UAVs [slot] = nullptr; - CommittedD3D11UAVRes[slot] = nullptr; - } - if (NumRenderTargets >= NumCommittedPixelShaderUAVs) - NumCommittedPixelShaderUAVs = 0; + auto* pViewD3D11 = m_pBoundRenderTargets[rt].RawPtr(); + pd3d11RTs[rt] = pViewD3D11 != nullptr ? static_cast(pViewD3D11->GetD3D11View()) : nullptr; } - else + + if (m_pBoundDepthStencil != nullptr) { - m_pd3d11DeviceContext->OMSetRenderTargets(NumRenderTargets, pd3d11RTs, pd3d11DSV); + pd3d11DSV = static_cast(m_pBoundDepthStencil->GetD3D11View()); } } - - void UnbindView( ID3D11DeviceContext* pContext, TSetShaderResourcesType SetSRVMethod, UINT Slot ) + auto& NumCommittedPixelShaderUAVs = m_NumCommittedUAVs[PSInd]; + if (NumCommittedPixelShaderUAVs > 0) { - ID3D11ShaderResourceView* ppNullView[] = { nullptr }; - (pContext->*SetSRVMethod)(Slot, 1, ppNullView); - } + m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(NumRenderTargets, pd3d11RTs, pd3d11DSV, + 0, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr); - void UnbindView( ID3D11DeviceContext* pContext, TSetUnorderedAccessViewsType SetUAVMethod, UINT Slot ) - { - ID3D11UnorderedAccessView* ppNullView[] = { nullptr }; - (pContext->*SetUAVMethod)(Slot, 1, ppNullView, nullptr); + auto CommittedD3D11UAVs = m_CommittedD3D11UAVs[PSInd]; + auto CommittedD3D11UAVRes = m_CommittedD3D11UAVResources[PSInd]; + for (Uint32 slot = 0; slot < NumRenderTargets; ++slot) + { + CommittedD3D11UAVs[slot] = nullptr; + CommittedD3D11UAVRes[slot] = nullptr; + } + if (NumRenderTargets >= NumCommittedPixelShaderUAVs) + NumCommittedPixelShaderUAVs = 0; } - - template - bool UnbindPixelShaderUAV(ID3D11DeviceContext* pDeviceCtx, - TD3D11ResourceViewType* CommittedD3D11Resources[], - Uint32 NumCommittedSlots, - Uint32 NumCommittedRenderTargets, - TSetD3D11View SetD3D11ViewMethod) + else { - // For other resource view types do nothing - return false; + m_pd3d11DeviceContext->OMSetRenderTargets(NumRenderTargets, pd3d11RTs, pd3d11DSV); } +} - template<> - bool UnbindPixelShaderUAV( - ID3D11DeviceContext* pDeviceCtx, - ID3D11UnorderedAccessView* CommittedD3D11UAVs[], - Uint32 NumCommittedUAVs, - Uint32 NumCommittedRenderTargets, - TSetUnorderedAccessViewsType SetD3D11UAVMethod) + +void UnbindView(ID3D11DeviceContext* pContext, TSetShaderResourcesType SetSRVMethod, UINT Slot) +{ + ID3D11ShaderResourceView* ppNullView[] = {nullptr}; + (pContext->*SetSRVMethod)(Slot, 1, ppNullView); +} + +void UnbindView(ID3D11DeviceContext* pContext, TSetUnorderedAccessViewsType SetUAVMethod, UINT Slot) +{ + ID3D11UnorderedAccessView* ppNullView[] = {nullptr}; + (pContext->*SetUAVMethod)(Slot, 1, ppNullView, nullptr); +} + +template +bool UnbindPixelShaderUAV(ID3D11DeviceContext* pDeviceCtx, + TD3D11ResourceViewType* CommittedD3D11Resources[], + Uint32 NumCommittedSlots, + Uint32 NumCommittedRenderTargets, + TSetD3D11View SetD3D11ViewMethod) +{ + // For other resource view types do nothing + return false; +} + +template <> +bool UnbindPixelShaderUAV( + ID3D11DeviceContext* pDeviceCtx, + ID3D11UnorderedAccessView* CommittedD3D11UAVs[], + Uint32 NumCommittedUAVs, + Uint32 NumCommittedRenderTargets, + TSetUnorderedAccessViewsType SetD3D11UAVMethod) +{ + if (SetD3D11UAVMethod == reinterpret_cast(&ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews)) { - if (SetD3D11UAVMethod == reinterpret_cast(&ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews)) - { - // Pixel shader UAVs are bound in a special way simulatneously with the render targets - auto UAVStartSlot = NumCommittedRenderTargets; - // UAVs cannot be set independently; they all need to be set at the same time. - // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks - - // There is potential problem here: since device context does not keep strong references to - // UAVs, there is no guarantee the objects are alive - pDeviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, - UAVStartSlot, NumCommittedUAVs - UAVStartSlot, CommittedD3D11UAVs + UAVStartSlot, nullptr); - return true; - } + // Pixel shader UAVs are bound in a special way simulatneously with the render targets + auto UAVStartSlot = NumCommittedRenderTargets; + // UAVs cannot be set independently; they all need to be set at the same time. + // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks - return false; + // There is potential problem here: since device context does not keep strong references to + // UAVs, there is no guarantee the objects are alive + pDeviceCtx->OMSetRenderTargetsAndUnorderedAccessViews(D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, + UAVStartSlot, NumCommittedUAVs - UAVStartSlot, + CommittedD3D11UAVs + UAVStartSlot, nullptr); + return true; } + return false; +} + - /// \tparam TD3D11ResourceViewType - Type of the D3D11 resource view (ID3D11ShaderResourceView or ID3D11UnorderedAccessView) - /// \tparam TSetD3D11View - Type of the D3D11 device context method used to set the D3D11 view - /// \param CommittedResourcesArr - Pointer to the array of strong references to currently bound - /// shader resources, for each shader stage - /// \param CommittedD3D11ResourcesArr - Pointer to the array of currently bound D3D11 - /// shader resources, for each shader stage - /// \param pd3d11ResToUndind - D3D11 resource to unbind - /// \param SetD3D11ViewMethods - Array of pointers to device context methods used to set the view, - /// for every shader stage - template - void DeviceContextD3D11Impl::UnbindResourceView( TD3D11ResourceViewType CommittedD3D11ViewsArr[][NumSlots], - ID3D11Resource* CommittedD3D11ResourcesArr[][NumSlots], - Uint8 NumCommittedResourcesArr[], - ID3D11Resource* pd3d11ResToUndind, - TSetD3D11View SetD3D11ViewMethods[]) +/// \tparam TD3D11ResourceViewType - Type of the D3D11 resource view (ID3D11ShaderResourceView or ID3D11UnorderedAccessView) +/// \tparam TSetD3D11View - Type of the D3D11 device context method used to set the D3D11 view +/// \param CommittedResourcesArr - Pointer to the array of strong references to currently bound +/// shader resources, for each shader stage +/// \param CommittedD3D11ResourcesArr - Pointer to the array of currently bound D3D11 +/// shader resources, for each shader stage +/// \param pd3d11ResToUndind - D3D11 resource to unbind +/// \param SetD3D11ViewMethods - Array of pointers to device context methods used to set the view, +/// for every shader stage +template +void DeviceContextD3D11Impl::UnbindResourceView(TD3D11ResourceViewType CommittedD3D11ViewsArr[][NumSlots], + ID3D11Resource* CommittedD3D11ResourcesArr[][NumSlots], + Uint8 NumCommittedResourcesArr[], + ID3D11Resource* pd3d11ResToUndind, + TSetD3D11View SetD3D11ViewMethods[]) +{ + for (Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd) { - for (Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd) - { - auto *CommittedD3D11Views = CommittedD3D11ViewsArr[ShaderTypeInd]; - auto *CommittedD3D11Resources = CommittedD3D11ResourcesArr[ShaderTypeInd]; - auto &NumCommittedSlots = NumCommittedResourcesArr[ShaderTypeInd]; + auto* CommittedD3D11Views = CommittedD3D11ViewsArr[ShaderTypeInd]; + auto* CommittedD3D11Resources = CommittedD3D11ResourcesArr[ShaderTypeInd]; + auto& NumCommittedSlots = NumCommittedResourcesArr[ShaderTypeInd]; - for (Uint32 Slot = 0; Slot < NumCommittedSlots; ++Slot) + for (Uint32 Slot = 0; Slot < NumCommittedSlots; ++Slot) + { + if (CommittedD3D11Resources[Slot] == pd3d11ResToUndind) { - if (CommittedD3D11Resources[Slot] == pd3d11ResToUndind) + CommittedD3D11Resources[Slot] = nullptr; + CommittedD3D11Views[Slot] = nullptr; + + auto SetViewMethod = SetD3D11ViewMethods[ShaderTypeInd]; + VERIFY(SetViewMethod != nullptr, "No appropriate ID3D11DeviceContext method"); + + // Pixel shader UAVs require special handling + if (!UnbindPixelShaderUAV(m_pd3d11DeviceContext, CommittedD3D11Views, NumCommittedSlots, m_NumBoundRenderTargets, SetViewMethod)) { - CommittedD3D11Resources[Slot] = nullptr; - CommittedD3D11Views [Slot] = nullptr; - - auto SetViewMethod = SetD3D11ViewMethods[ShaderTypeInd]; - VERIFY(SetViewMethod != nullptr, "No appropriate ID3D11DeviceContext method"); - - // Pixel shader UAVs require special handling - if (!UnbindPixelShaderUAV(m_pd3d11DeviceContext, CommittedD3D11Views, NumCommittedSlots, m_NumBoundRenderTargets, SetViewMethod)) - { - UnbindView( m_pd3d11DeviceContext, SetViewMethod, Slot ); - } + UnbindView(m_pd3d11DeviceContext, SetViewMethod, Slot); } } + } - // Pop null resources from the end of arrays - while (NumCommittedSlots > 0 && CommittedD3D11Resources[NumCommittedSlots-1] == nullptr) - { - VERIFY( CommittedD3D11Views[NumSlots-1] == nullptr, "Unexpected non-null resource view" ); - --NumCommittedSlots; - } + // Pop null resources from the end of arrays + while (NumCommittedSlots > 0 && CommittedD3D11Resources[NumCommittedSlots - 1] == nullptr) + { + VERIFY(CommittedD3D11Views[NumSlots - 1] == nullptr, "Unexpected non-null resource view"); + --NumCommittedSlots; } } +} - void DeviceContextD3D11Impl::UnbindTextureFromInput( TextureBaseD3D11* pTexture, ID3D11Resource* pd3d11Resource ) - { - VERIFY( pTexture, "Null texture provided" ); - if( !pTexture )return; +void DeviceContextD3D11Impl::UnbindTextureFromInput(TextureBaseD3D11* pTexture, ID3D11Resource* pd3d11Resource) +{ + VERIFY(pTexture, "Null texture provided"); + if (!pTexture) return; + + UnbindResourceView(m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, pd3d11Resource, SetSRVMethods); + pTexture->ClearState(RESOURCE_STATE_SHADER_RESOURCE); +} + +void DeviceContextD3D11Impl::UnbindBufferFromInput(BufferD3D11Impl* pBuffer, ID3D11Resource* pd3d11Buffer) +{ + VERIFY(pBuffer, "Null buffer provided"); + if (!pBuffer || !pBuffer->IsInKnownState()) return; - UnbindResourceView( m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, pd3d11Resource, SetSRVMethods ); - pTexture->ClearState(RESOURCE_STATE_SHADER_RESOURCE); + if (pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) + { + UnbindResourceView(m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, pd3d11Buffer, SetSRVMethods); + pBuffer->ClearState(RESOURCE_STATE_SHADER_RESOURCE); } - void DeviceContextD3D11Impl::UnbindBufferFromInput( BufferD3D11Impl* pBuffer, ID3D11Resource* pd3d11Buffer ) + if (pBuffer->CheckState(RESOURCE_STATE_INDEX_BUFFER)) { - VERIFY( pBuffer, "Null buffer provided" ); - if (!pBuffer || !pBuffer->IsInKnownState())return; - - if (pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) + auto pd3d11IndBuffer = ValidatedCast(pBuffer)->GetD3D11Buffer(); + if (pd3d11IndBuffer == m_CommittedD3D11IndexBuffer) { - UnbindResourceView( m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, pd3d11Buffer, SetSRVMethods ); - pBuffer->ClearState(RESOURCE_STATE_SHADER_RESOURCE); + // Only unbind D3D11 buffer from the context! + // m_pIndexBuffer.Release(); + m_CommittedD3D11IndexBuffer.Release(); + m_CommittedIBFormat = VT_UNDEFINED; + m_CommittedD3D11IndexDataStartOffset = 0; + m_bCommittedD3D11IBUpToDate = false; + m_pd3d11DeviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R32_UINT, m_CommittedD3D11IndexDataStartOffset); } - - if (pBuffer->CheckState(RESOURCE_STATE_INDEX_BUFFER)) - { - auto pd3d11IndBuffer = ValidatedCast( pBuffer )->GetD3D11Buffer(); - if (pd3d11IndBuffer == m_CommittedD3D11IndexBuffer) - { - // Only unbind D3D11 buffer from the context! - // m_pIndexBuffer.Release(); - m_CommittedD3D11IndexBuffer.Release(); - m_CommittedIBFormat = VT_UNDEFINED; - m_CommittedD3D11IndexDataStartOffset = 0; - m_bCommittedD3D11IBUpToDate = false; - m_pd3d11DeviceContext->IASetIndexBuffer( nullptr, DXGI_FORMAT_R32_UINT, m_CommittedD3D11IndexDataStartOffset ); - } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedIndexBuffer(); - } -#endif - pBuffer->ClearState(RESOURCE_STATE_INDEX_BUFFER); + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedIndexBuffer(); } +#endif + pBuffer->ClearState(RESOURCE_STATE_INDEX_BUFFER); + } - if (pBuffer->CheckState(RESOURCE_STATE_VERTEX_BUFFER)) + if (pBuffer->CheckState(RESOURCE_STATE_VERTEX_BUFFER)) + { + auto pd3d11VB = ValidatedCast(pBuffer)->GetD3D11Buffer(); + for (Uint32 Slot = 0; Slot < m_NumCommittedD3D11VBs; ++Slot) { - auto pd3d11VB = ValidatedCast( pBuffer )->GetD3D11Buffer(); - for (Uint32 Slot = 0; Slot < m_NumCommittedD3D11VBs; ++Slot) + auto& CommittedD3D11VB = m_CommittedD3D11VertexBuffers[Slot]; + if (CommittedD3D11VB == pd3d11VB) { - auto& CommittedD3D11VB = m_CommittedD3D11VertexBuffers[Slot]; - if (CommittedD3D11VB == pd3d11VB) - { - // Unbind only D3D11 buffer - //*VertStream = VertexStreamInfo(); - ID3D11Buffer* ppNullBuffer[] = { nullptr }; - const UINT Zero[] = { 0 }; - m_CommittedD3D11VertexBuffers[Slot] = nullptr; - m_CommittedD3D11VBStrides[Slot] = 0; - m_CommittedD3D11VBOffsets[Slot] = 0; - m_bCommittedD3D11VBsUpToDate = false; - m_pd3d11DeviceContext->IASetVertexBuffers( Slot, _countof( ppNullBuffer ), ppNullBuffer, Zero, Zero ); - } + // Unbind only D3D11 buffer + //*VertStream = VertexStreamInfo(); + ID3D11Buffer* ppNullBuffer[] = {nullptr}; + const UINT Zero[] = {0}; + m_CommittedD3D11VertexBuffers[Slot] = nullptr; + m_CommittedD3D11VBStrides[Slot] = 0; + m_CommittedD3D11VBOffsets[Slot] = 0; + m_bCommittedD3D11VBsUpToDate = false; + m_pd3d11DeviceContext->IASetVertexBuffers(Slot, _countof(ppNullBuffer), ppNullBuffer, Zero, Zero); } + } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedVertexBuffers(); - } -#endif - pBuffer->ClearState(RESOURCE_STATE_VERTEX_BUFFER); + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedVertexBuffers(); } +#endif + pBuffer->ClearState(RESOURCE_STATE_VERTEX_BUFFER); + } - if (pBuffer->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) + if (pBuffer->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) + { + for (Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd) { - for (Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd) + auto* CommittedD3D11CBs = m_CommittedD3D11CBs[ShaderTypeInd]; + auto NumSlots = m_NumCommittedCBs[ShaderTypeInd]; + for (Uint32 Slot = 0; Slot < NumSlots; ++Slot) { - auto* CommittedD3D11CBs = m_CommittedD3D11CBs[ShaderTypeInd]; - auto NumSlots = m_NumCommittedCBs[ShaderTypeInd]; - for (Uint32 Slot = 0; Slot < NumSlots; ++Slot) + if (CommittedD3D11CBs[Slot] == pd3d11Buffer) { - if (CommittedD3D11CBs[Slot] == pd3d11Buffer) - { - CommittedD3D11CBs[Slot] = nullptr; - auto SetCBMethod = SetCBMethods[ShaderTypeInd]; - ID3D11Buffer* ppNullBuffer[] = { nullptr }; - (m_pd3d11DeviceContext->*SetCBMethod)(Slot, 1, ppNullBuffer); - } + CommittedD3D11CBs[Slot] = nullptr; + auto SetCBMethod = SetCBMethods[ShaderTypeInd]; + ID3D11Buffer* ppNullBuffer[] = {nullptr}; + (m_pd3d11DeviceContext->*SetCBMethod)(Slot, 1, ppNullBuffer); } } + } #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedCBs(); - } -#endif - pBuffer->ClearState(RESOURCE_STATE_CONSTANT_BUFFER); + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + dbgVerifyCommittedCBs(); } +#endif + pBuffer->ClearState(RESOURCE_STATE_CONSTANT_BUFFER); } +} - void DeviceContextD3D11Impl::UnbindResourceFromUAV( IDeviceObject* pResource, ID3D11Resource* pd3d11Resource ) - { - VERIFY( pResource, "Null resource provided" ); - if( !pResource )return; +void DeviceContextD3D11Impl::UnbindResourceFromUAV(IDeviceObject* pResource, ID3D11Resource* pd3d11Resource) +{ + VERIFY(pResource, "Null resource provided"); + if (!pResource) return; - UnbindResourceView( m_CommittedD3D11UAVs, m_CommittedD3D11UAVResources, m_NumCommittedUAVs, pd3d11Resource, SetUAVMethods ); - } + UnbindResourceView(m_CommittedD3D11UAVs, m_CommittedD3D11UAVResources, m_NumCommittedUAVs, pd3d11Resource, SetUAVMethods); +} - void DeviceContextD3D11Impl::UnbindTextureFromRenderTarget( TextureBaseD3D11* pTexture ) - { - VERIFY( pTexture, "Null resource provided" ); - if( !pTexture )return; +void DeviceContextD3D11Impl::UnbindTextureFromRenderTarget(TextureBaseD3D11* pTexture) +{ + VERIFY(pTexture, "Null resource provided"); + if (!pTexture) return; - bool bCommitRenderTargets = false; - for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) + bool bCommitRenderTargets = false; + for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt) + { + if (auto* pTexView = m_pBoundRenderTargets[rt].RawPtr()) { - if (auto* pTexView = m_pBoundRenderTargets[rt].RawPtr()) + if (pTexView->GetTexture() == pTexture) { - if (pTexView->GetTexture() == pTexture) - { - m_pBoundRenderTargets[rt].Release(); - bCommitRenderTargets = true; - } + m_pBoundRenderTargets[rt].Release(); + bCommitRenderTargets = true; } } - - if (bCommitRenderTargets) - { - while(m_NumBoundRenderTargets > 0 && !m_pBoundRenderTargets[m_NumBoundRenderTargets-1]) - --m_NumBoundRenderTargets; - - CommitRenderTargets(); - } - - pTexture->ClearState(RESOURCE_STATE_RENDER_TARGET); } - void DeviceContextD3D11Impl::UnbindTextureFromDepthStencil(TextureBaseD3D11* pTexD3D11) + if (bCommitRenderTargets) { - VERIFY( pTexD3D11, "Null resource provided" ); - if( !pTexD3D11 )return; - - if (m_pBoundDepthStencil && m_pBoundDepthStencil->GetTexture() == pTexD3D11) - { - m_pBoundDepthStencil.Release(); - CommitRenderTargets(); - } - pTexD3D11->ClearState(RESOURCE_STATE_DEPTH_WRITE); + while (m_NumBoundRenderTargets > 0 && !m_pBoundRenderTargets[m_NumBoundRenderTargets - 1]) + --m_NumBoundRenderTargets; + + CommitRenderTargets(); } - void DeviceContextD3D11Impl::ResetRenderTargets() + pTexture->ClearState(RESOURCE_STATE_RENDER_TARGET); +} + +void DeviceContextD3D11Impl::UnbindTextureFromDepthStencil(TextureBaseD3D11* pTexD3D11) +{ + VERIFY(pTexD3D11, "Null resource provided"); + if (!pTexD3D11) return; + + if (m_pBoundDepthStencil && m_pBoundDepthStencil->GetTexture() == pTexD3D11) { - TDeviceContextBase::ResetRenderTargets(); - m_pd3d11DeviceContext->OMSetRenderTargets(0, nullptr, nullptr); + m_pBoundDepthStencil.Release(); + CommitRenderTargets(); } + pTexD3D11->ClearState(RESOURCE_STATE_DEPTH_WRITE); +} - void DeviceContextD3D11Impl::SetRenderTargets(Uint32 NumRenderTargets, - ITextureView* ppRenderTargets[], - ITextureView* pDepthStencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +void DeviceContextD3D11Impl::ResetRenderTargets() +{ + TDeviceContextBase::ResetRenderTargets(); + m_pd3d11DeviceContext->OMSetRenderTargets(0, nullptr, nullptr); +} + +void DeviceContextD3D11Impl::SetRenderTargets(Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) +{ + if (TDeviceContextBase::SetRenderTargets(NumRenderTargets, ppRenderTargets, pDepthStencil)) { - if (TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil)) + for (Uint32 RT = 0; RT < NumRenderTargets; ++RT) { - for (Uint32 RT = 0; RT < NumRenderTargets; ++RT) + if (ppRenderTargets[RT]) { - if (ppRenderTargets[RT]) - { - auto* pTex = ValidatedCast(ppRenderTargets[RT]->GetTexture()); - if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) - { - UnbindTextureFromInput( pTex, pTex->GetD3D11Texture() ); - if (pTex->IsInKnownState()) - pTex->SetState(RESOURCE_STATE_RENDER_TARGET); - } -#ifdef DEVELOPMENT - else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) - { - DvpVerifyTextureState(*pTex, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D11Impl::SetRenderTargets)"); - } -#endif - } - } - - if (pDepthStencil) - { - auto* pTex = ValidatedCast(pDepthStencil->GetTexture()); + auto* pTex = ValidatedCast(ppRenderTargets[RT]->GetTexture()); if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { - UnbindTextureFromInput( pTex, pTex->GetD3D11Texture() ); + UnbindTextureFromInput(pTex, pTex->GetD3D11Texture()); if (pTex->IsInKnownState()) - pTex->SetState(RESOURCE_STATE_DEPTH_WRITE); + pTex->SetState(RESOURCE_STATE_RENDER_TARGET); } #ifdef DEVELOPMENT - else if(StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) + else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) { - DvpVerifyTextureState(*pTex, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D11Impl::SetRenderTargets)"); + DvpVerifyTextureState(*pTex, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D11Impl::SetRenderTargets)"); } #endif } + } + + if (pDepthStencil) + { + auto* pTex = ValidatedCast(pDepthStencil->GetTexture()); + if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) + { + UnbindTextureFromInput(pTex, pTex->GetD3D11Texture()); + if (pTex->IsInKnownState()) + pTex->SetState(RESOURCE_STATE_DEPTH_WRITE); + } +#ifdef DEVELOPMENT + else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) + { + DvpVerifyTextureState(*pTex, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D11Impl::SetRenderTargets)"); + } +#endif + } - CommitRenderTargets(); + CommitRenderTargets(); - // Set the viewport to match the render target size - SetViewports(1, nullptr, 0, 0); - } + // Set the viewport to match the render target size + SetViewports(1, nullptr, 0, 0); } +} - template - void SetD3D11ResourcesHelper(ID3D11DeviceContext* pDeviceCtx, - TSetD3D11ResMethodType SetD3D11ResMethod, - UINT StartSlot, UINT NumSlots, - TD3D11ResourceType **ppResources) - { - (pDeviceCtx->*SetD3D11ResMethod)(StartSlot, NumSlots, ppResources); - } +template +void SetD3D11ResourcesHelper(ID3D11DeviceContext* pDeviceCtx, + TSetD3D11ResMethodType SetD3D11ResMethod, + UINT StartSlot, + UINT NumSlots, + TD3D11ResourceType** ppResources) +{ + (pDeviceCtx->*SetD3D11ResMethod)(StartSlot, NumSlots, ppResources); +} - template<> - void SetD3D11ResourcesHelper(ID3D11DeviceContext* pDeviceCtx, - TSetUnorderedAccessViewsType SetD3D11UAVMethod, - UINT StartSlot, UINT NumSlots, - ID3D11UnorderedAccessView **ppUAVs) - { - (pDeviceCtx->*SetD3D11UAVMethod)(StartSlot, NumSlots, ppUAVs, nullptr); - } +template <> +void SetD3D11ResourcesHelper(ID3D11DeviceContext* pDeviceCtx, + TSetUnorderedAccessViewsType SetD3D11UAVMethod, + UINT StartSlot, + UINT NumSlots, + ID3D11UnorderedAccessView** ppUAVs) +{ + (pDeviceCtx->*SetD3D11UAVMethod)(StartSlot, NumSlots, ppUAVs, nullptr); +} - template - void ReleaseCommittedShaderResourcesHelper(TD3D11ResourceType CommittedD3D11Res[], - Uint8 NumCommittedResources, - TSetD3D11ResMethodType SetD3D11ResMethod, - ID3D11DeviceContext* pDeviceCtx) +template +void ReleaseCommittedShaderResourcesHelper(TD3D11ResourceType CommittedD3D11Res[], + Uint8 NumCommittedResources, + TSetD3D11ResMethodType SetD3D11ResMethod, + ID3D11DeviceContext* pDeviceCtx) +{ + if (NumCommittedResources > 0) { - if( NumCommittedResources > 0) - { - memset( CommittedD3D11Res, 0, NumCommittedResources * sizeof( CommittedD3D11Res[0] ) ); - SetD3D11ResourcesHelper( pDeviceCtx, SetD3D11ResMethod, 0, NumCommittedResources, CommittedD3D11Res ); - } + memset(CommittedD3D11Res, 0, NumCommittedResources * sizeof(CommittedD3D11Res[0])); + SetD3D11ResourcesHelper(pDeviceCtx, SetD3D11ResMethod, 0, NumCommittedResources, CommittedD3D11Res); } +} - void ReleaseCommittedPSUAVs(ID3D11UnorderedAccessView* CommittedD3D11UAVs[], - Uint8 NumCommittedResources, - ID3D11DeviceContext* pDeviceCtx) +void ReleaseCommittedPSUAVs(ID3D11UnorderedAccessView* CommittedD3D11UAVs[], + Uint8 NumCommittedResources, + ID3D11DeviceContext* pDeviceCtx) +{ + if (NumCommittedResources > 0) { - if( NumCommittedResources > 0) - { - memset( CommittedD3D11UAVs, 0, NumCommittedResources * sizeof( CommittedD3D11UAVs[0] ) ); - pDeviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( - D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, - 0, 0, nullptr, nullptr); - } + memset(CommittedD3D11UAVs, 0, NumCommittedResources * sizeof(CommittedD3D11UAVs[0])); + pDeviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, + 0, 0, nullptr, nullptr); } +} - void DeviceContextD3D11Impl::ReleaseCommittedShaderResources() +void DeviceContextD3D11Impl::ReleaseCommittedShaderResources() +{ + for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) { - for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) - { - ReleaseCommittedShaderResourcesHelper( m_CommittedD3D11CBs [ShaderType], m_NumCommittedCBs [ShaderType], SetCBMethods[ShaderType], m_pd3d11DeviceContext); - ReleaseCommittedShaderResourcesHelper( m_CommittedD3D11SRVs [ShaderType], m_NumCommittedSRVs [ShaderType], SetSRVMethods[ShaderType], m_pd3d11DeviceContext); - ReleaseCommittedShaderResourcesHelper( m_CommittedD3D11Samplers[ShaderType], m_NumCommittedSamplers[ShaderType], SetSamplerMethods[ShaderType], m_pd3d11DeviceContext); - if (ShaderType == PSInd) - ReleaseCommittedPSUAVs( m_CommittedD3D11UAVs[ShaderType], m_NumCommittedUAVs[ShaderType], m_pd3d11DeviceContext); - else - ReleaseCommittedShaderResourcesHelper( m_CommittedD3D11UAVs [ShaderType], m_NumCommittedUAVs [ShaderType], SetUAVMethods[ShaderType], m_pd3d11DeviceContext); - memset(m_CommittedD3D11SRVResources[ShaderType], 0, sizeof(m_CommittedD3D11SRVResources[ShaderType][0])*m_NumCommittedSRVs[ShaderType] ); - memset(m_CommittedD3D11UAVResources[ShaderType], 0, sizeof(m_CommittedD3D11UAVResources[ShaderType][0])*m_NumCommittedUAVs[ShaderType] ); - m_NumCommittedCBs[ShaderType] = 0; - m_NumCommittedSRVs[ShaderType] = 0; - m_NumCommittedSamplers[ShaderType] = 0; - m_NumCommittedUAVs[ShaderType] = 0; - } + // clang-format off + ReleaseCommittedShaderResourcesHelper(m_CommittedD3D11CBs[ShaderType], m_NumCommittedCBs[ShaderType], SetCBMethods[ShaderType], m_pd3d11DeviceContext); + ReleaseCommittedShaderResourcesHelper(m_CommittedD3D11SRVs[ShaderType], m_NumCommittedSRVs[ShaderType], SetSRVMethods[ShaderType], m_pd3d11DeviceContext); + ReleaseCommittedShaderResourcesHelper(m_CommittedD3D11Samplers[ShaderType], m_NumCommittedSamplers[ShaderType], SetSamplerMethods[ShaderType], m_pd3d11DeviceContext); + // clang-format on -#ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - } -#endif - // We do not unbind vertex buffers and index buffer as this can explicitly - // be done by the user - } + if (ShaderType == PSInd) + ReleaseCommittedPSUAVs(m_CommittedD3D11UAVs[ShaderType], m_NumCommittedUAVs[ShaderType], m_pd3d11DeviceContext); + else + ReleaseCommittedShaderResourcesHelper(m_CommittedD3D11UAVs[ShaderType], m_NumCommittedUAVs[ShaderType], SetUAVMethods[ShaderType], m_pd3d11DeviceContext); + memset(m_CommittedD3D11SRVResources[ShaderType], 0, sizeof(m_CommittedD3D11SRVResources[ShaderType][0]) * m_NumCommittedSRVs[ShaderType]); + memset(m_CommittedD3D11UAVResources[ShaderType], 0, sizeof(m_CommittedD3D11UAVResources[ShaderType][0]) * m_NumCommittedUAVs[ShaderType]); + m_NumCommittedCBs[ShaderType] = 0; + m_NumCommittedSRVs[ShaderType] = 0; + m_NumCommittedSamplers[ShaderType] = 0; + m_NumCommittedUAVs[ShaderType] = 0; + } - void DeviceContextD3D11Impl::FinishCommandList(ICommandList **ppCommandList) +#ifdef DEVELOPMENT + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) { - CComPtr pd3d11CmdList; - m_pd3d11DeviceContext->FinishCommandList( - FALSE, // A Boolean flag that determines whether the runtime saves deferred context state before it - // executes FinishCommandList and restores it afterwards. - // * TRUE indicates that the runtime needs to save and restore the state. - // * FALSE indicates that the runtime will not save or restore any state. - // In this case, the deferred context will return to its default state - // after the call to FinishCommandList() completes as if - // ID3D11DeviceContext::ClearState() was called. - &pd3d11CmdList); + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + } +#endif + // We do not unbind vertex buffers and index buffer as this can explicitly + // be done by the user +} - CommandListD3D11Impl* pCmdListD3D11( NEW_RC_OBJ(m_CmdListAllocator, "CommandListD3D11Impl instance", CommandListD3D11Impl)(m_pDevice, pd3d11CmdList) ); - pCmdListD3D11->QueryInterface( IID_CommandList, reinterpret_cast(ppCommandList) ); - // Device context is now in default state - InvalidateState(); +void DeviceContextD3D11Impl::FinishCommandList(ICommandList** ppCommandList) +{ + CComPtr pd3d11CmdList; + m_pd3d11DeviceContext->FinishCommandList( + FALSE, // A Boolean flag that determines whether the runtime saves deferred context state before it + // executes FinishCommandList and restores it afterwards. + // * TRUE indicates that the runtime needs to save and restore the state. + // * FALSE indicates that the runtime will not save or restore any state. + // In this case, the deferred context will return to its default state + // after the call to FinishCommandList() completes as if + // ID3D11DeviceContext::ClearState() was called. + &pd3d11CmdList); + + CommandListD3D11Impl* pCmdListD3D11(NEW_RC_OBJ(m_CmdListAllocator, "CommandListD3D11Impl instance", CommandListD3D11Impl)(m_pDevice, pd3d11CmdList)); + pCmdListD3D11->QueryInterface(IID_CommandList, reinterpret_cast(ppCommandList)); + + // Device context is now in default state + InvalidateState(); #ifdef DEVELOPMENT - if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - // Verify bindings - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - dbgVerifyCommittedVertexBuffers(); - dbgVerifyCommittedIndexBuffer(); - dbgVerifyCommittedShaders(); - } -#endif + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) + { + // Verify bindings + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + dbgVerifyCommittedVertexBuffers(); + dbgVerifyCommittedIndexBuffer(); + dbgVerifyCommittedShaders(); } +#endif +} - void DeviceContextD3D11Impl::ExecuteCommandList(ICommandList* pCommandList) +void DeviceContextD3D11Impl::ExecuteCommandList(ICommandList* pCommandList) +{ + if (m_bIsDeferred) { - if (m_bIsDeferred) - { - LOG_ERROR("Only immediate context can execute command list"); - return; - } + LOG_ERROR("Only immediate context can execute command list"); + return; + } - CommandListD3D11Impl* pCmdListD3D11 = ValidatedCast(pCommandList); - auto* pd3d11CmdList = pCmdListD3D11->GetD3D11CommandList(); - m_pd3d11DeviceContext->ExecuteCommandList(pd3d11CmdList, - FALSE // A Boolean flag that determines whether the target context state is - // saved prior to and restored after the execution of a command list. - // * TRUE indicates that the runtime needs to save and restore the state. - // * FALSE indicate that no state shall be saved or restored, which causes the - // target context to return to its default state after the command list executes as if - // ID3D11DeviceContext::ClearState() was called. - ); + CommandListD3D11Impl* pCmdListD3D11 = ValidatedCast(pCommandList); + auto* pd3d11CmdList = pCmdListD3D11->GetD3D11CommandList(); + m_pd3d11DeviceContext->ExecuteCommandList(pd3d11CmdList, + FALSE // A Boolean flag that determines whether the target context state is + // saved prior to and restored after the execution of a command list. + // * TRUE indicates that the runtime needs to save and restore the state. + // * FALSE indicate that no state shall be saved or restored, which causes the + // target context to return to its default state after the command list executes as if + // ID3D11DeviceContext::ClearState() was called. + ); - // Device context is now in default state - InvalidateState(); + // Device context is now in default state + InvalidateState(); #ifdef DEVELOPMENT - if(m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) - { - // Verify bindings - dbgVerifyCommittedSRVs(); - dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); - dbgVerifyCommittedSamplers(); - dbgVerifyCommittedCBs(); - dbgVerifyCommittedVertexBuffers(); - dbgVerifyCommittedIndexBuffer(); - dbgVerifyCommittedShaders(); - } -#endif - } - - - static CComPtr CreateD3D11QueryEvent(ID3D11Device* pd3d11Device) + if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) { - D3D11_QUERY_DESC QueryDesc = {}; - QueryDesc.Query = D3D11_QUERY_EVENT; // Determines whether or not the GPU is finished processing commands. - // When the GPU is finished processing commands ID3D11DeviceContext::GetData will - // return S_OK, and pData will point to a BOOL with a value of TRUE. When using this - // type of query, ID3D11DeviceContext::Begin is disabled. - QueryDesc.MiscFlags = 0; - - CComPtr pd3d11Query; - auto hr = pd3d11Device->CreateQuery(&QueryDesc, &pd3d11Query); - DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to create D3D11 query"); - VERIFY_EXPR(pd3d11Query); - return pd3d11Query; + // Verify bindings + dbgVerifyCommittedSRVs(); + dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE); + dbgVerifyCommittedSamplers(); + dbgVerifyCommittedCBs(); + dbgVerifyCommittedVertexBuffers(); + dbgVerifyCommittedIndexBuffer(); + dbgVerifyCommittedShaders(); } +#endif +} - void DeviceContextD3D11Impl::SignalFence(IFence* pFence, Uint64 Value) - { - VERIFY(!m_bIsDeferred, "Fence can only be signaled from immediate context"); - auto* pd3d11Device = m_pDevice->GetD3D11Device(); - CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); - m_pd3d11DeviceContext->End(pd3d11Query); - auto* pFenceD3D11Impl = ValidatedCast(pFence); - pFenceD3D11Impl->AddPendingQuery(m_pd3d11DeviceContext, std::move(pd3d11Query), Value); - } - void DeviceContextD3D11Impl::WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext) +static CComPtr CreateD3D11QueryEvent(ID3D11Device* pd3d11Device) +{ + D3D11_QUERY_DESC QueryDesc = {}; + QueryDesc.Query = D3D11_QUERY_EVENT; // Determines whether or not the GPU is finished processing commands. + // When the GPU is finished processing commands ID3D11DeviceContext::GetData will + // return S_OK, and pData will point to a BOOL with a value of TRUE. When using this + // type of query, ID3D11DeviceContext::Begin is disabled. + QueryDesc.MiscFlags = 0; + + CComPtr pd3d11Query; + auto hr = pd3d11Device->CreateQuery(&QueryDesc, &pd3d11Query); + DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to create D3D11 query"); + VERIFY_EXPR(pd3d11Query); + return pd3d11Query; +} + +void DeviceContextD3D11Impl::SignalFence(IFence* pFence, Uint64 Value) +{ + VERIFY(!m_bIsDeferred, "Fence can only be signaled from immediate context"); + auto* pd3d11Device = m_pDevice->GetD3D11Device(); + CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); + m_pd3d11DeviceContext->End(pd3d11Query); + auto* pFenceD3D11Impl = ValidatedCast(pFence); + pFenceD3D11Impl->AddPendingQuery(m_pd3d11DeviceContext, std::move(pd3d11Query), Value); +} + +void DeviceContextD3D11Impl::WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext) +{ + VERIFY(!m_bIsDeferred, "Fence can only be waited from immediate context"); + if (FlushContext) + Flush(); + auto* pFenceD3D11Impl = ValidatedCast(pFence); + pFenceD3D11Impl->Wait(Value, FlushContext); +} + +void DeviceContextD3D11Impl::WaitForIdle() +{ + VERIFY(!m_bIsDeferred, "Only immediate contexts can be idled"); + Flush(); + auto* pd3d11Device = m_pDevice->GetD3D11Device(); + CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); + m_pd3d11DeviceContext->End(pd3d11Query); + BOOL Data; + while (m_pd3d11DeviceContext->GetData(pd3d11Query, &Data, sizeof(Data), 0) != S_OK) + std::this_thread::yield(); +} + +void DeviceContextD3D11Impl::ClearStateCache() +{ + TDeviceContextBase::ClearStateCache(); + + for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) { - VERIFY(!m_bIsDeferred, "Fence can only be waited from immediate context"); - if (FlushContext) - Flush(); - auto* pFenceD3D11Impl = ValidatedCast(pFence); - pFenceD3D11Impl->Wait(Value, FlushContext); + // clang-format off + memset(m_CommittedD3D11CBs[ShaderType], 0, sizeof(m_CommittedD3D11CBs[ShaderType][0]) * m_NumCommittedCBs[ShaderType]); + memset(m_CommittedD3D11SRVs[ShaderType], 0, sizeof(m_CommittedD3D11SRVs[ShaderType][0]) * m_NumCommittedSRVs[ShaderType]); + memset(m_CommittedD3D11Samplers[ShaderType], 0, sizeof(m_CommittedD3D11Samplers[ShaderType][0]) * m_NumCommittedSamplers[ShaderType]); + memset(m_CommittedD3D11UAVs[ShaderType], 0, sizeof(m_CommittedD3D11UAVs[ShaderType][0]) * m_NumCommittedUAVs[ShaderType]); + memset(m_CommittedD3D11SRVResources[ShaderType], 0, sizeof(m_CommittedD3D11SRVResources[ShaderType][0]) * m_NumCommittedSRVs[ShaderType]); + memset(m_CommittedD3D11UAVResources[ShaderType], 0, sizeof(m_CommittedD3D11UAVResources[ShaderType][0]) * m_NumCommittedUAVs[ShaderType]); + // clang-format on + + m_NumCommittedCBs[ShaderType] = 0; + m_NumCommittedSRVs[ShaderType] = 0; + m_NumCommittedSamplers[ShaderType] = 0; + m_NumCommittedUAVs[ShaderType] = 0; + + m_CommittedD3DShaders[ShaderType].Release(); } - void DeviceContextD3D11Impl::WaitForIdle() + for (Uint32 vb = 0; vb < m_NumCommittedD3D11VBs; ++vb) { - VERIFY(!m_bIsDeferred, "Only immediate contexts can be idled"); - Flush(); - auto* pd3d11Device = m_pDevice->GetD3D11Device(); - CComPtr pd3d11Query = CreateD3D11QueryEvent(pd3d11Device); - m_pd3d11DeviceContext->End(pd3d11Query); - BOOL Data; - while (m_pd3d11DeviceContext->GetData(pd3d11Query, &Data, sizeof(Data), 0) != S_OK) - std::this_thread::yield(); + m_CommittedD3D11VertexBuffers[vb] = nullptr; + m_CommittedD3D11VBStrides[vb] = 0; + m_CommittedD3D11VBOffsets[vb] = 0; } + m_NumCommittedD3D11VBs = 0; + m_bCommittedD3D11VBsUpToDate = false; - void DeviceContextD3D11Impl::ClearStateCache() - { - TDeviceContextBase::ClearStateCache(); - - for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) - { - memset(m_CommittedD3D11CBs [ShaderType], 0, sizeof(m_CommittedD3D11CBs [ShaderType][0])*m_NumCommittedCBs [ShaderType] ); - memset(m_CommittedD3D11SRVs [ShaderType], 0, sizeof(m_CommittedD3D11SRVs [ShaderType][0])*m_NumCommittedSRVs [ShaderType] ); - memset(m_CommittedD3D11Samplers[ShaderType], 0, sizeof(m_CommittedD3D11Samplers[ShaderType][0])*m_NumCommittedSamplers[ShaderType] ); - memset(m_CommittedD3D11UAVs [ShaderType], 0, sizeof(m_CommittedD3D11UAVs [ShaderType][0])*m_NumCommittedUAVs [ShaderType] ); - memset(m_CommittedD3D11SRVResources[ShaderType], 0, sizeof(m_CommittedD3D11SRVResources[ShaderType][0])*m_NumCommittedSRVs[ShaderType] ); - memset(m_CommittedD3D11UAVResources[ShaderType], 0, sizeof(m_CommittedD3D11UAVResources[ShaderType][0])*m_NumCommittedUAVs[ShaderType] ); - - m_NumCommittedCBs [ShaderType] = 0; - m_NumCommittedSRVs [ShaderType] = 0; - m_NumCommittedSamplers[ShaderType] = 0; - m_NumCommittedUAVs [ShaderType] = 0; - - m_CommittedD3DShaders[ShaderType].Release(); - } + m_CommittedD3D11InputLayout = nullptr; + + m_CommittedD3D11IndexBuffer.Release(); + m_CommittedIBFormat = VT_UNDEFINED; + m_CommittedD3D11IndexDataStartOffset = 0; + m_bCommittedD3D11IBUpToDate = false; + + m_CommittedD3D11PrimTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; + m_CommittedPrimitiveTopology = PRIMITIVE_TOPOLOGY_UNDEFINED; +} - for (Uint32 vb=0; vb < m_NumCommittedD3D11VBs; ++vb) +void DeviceContextD3D11Impl::InvalidateState() +{ + TDeviceContextBase::InvalidateState(); + + ReleaseCommittedShaderResources(); + for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) + m_CommittedD3DShaders[ShaderType].Release(); + m_pd3d11DeviceContext->VSSetShader(nullptr, nullptr, 0); + m_pd3d11DeviceContext->GSSetShader(nullptr, nullptr, 0); + m_pd3d11DeviceContext->PSSetShader(nullptr, nullptr, 0); + m_pd3d11DeviceContext->HSSetShader(nullptr, nullptr, 0); + m_pd3d11DeviceContext->DSSetShader(nullptr, nullptr, 0); + m_pd3d11DeviceContext->CSSetShader(nullptr, nullptr, 0); + ID3D11RenderTargetView* d3d11NullRTV[] = {nullptr}; + m_pd3d11DeviceContext->OMSetRenderTargets(1, d3d11NullRTV, nullptr); + + if (m_NumCommittedD3D11VBs > 0) + { + for (Uint32 vb = 0; vb < m_NumCommittedD3D11VBs; ++vb) { m_CommittedD3D11VertexBuffers[vb] = nullptr; - m_CommittedD3D11VBStrides [vb] = 0; - m_CommittedD3D11VBOffsets [vb] = 0; + m_CommittedD3D11VBStrides[vb] = 0; + m_CommittedD3D11VBOffsets[vb] = 0; } + m_pd3d11DeviceContext->IASetVertexBuffers(0, m_NumCommittedD3D11VBs, m_CommittedD3D11VertexBuffers, m_CommittedD3D11VBStrides, m_CommittedD3D11VBOffsets); m_NumCommittedD3D11VBs = 0; - m_bCommittedD3D11VBsUpToDate = false; - - m_CommittedD3D11InputLayout = nullptr; - - m_CommittedD3D11IndexBuffer.Release(); - m_CommittedIBFormat = VT_UNDEFINED; - m_CommittedD3D11IndexDataStartOffset = 0; - m_bCommittedD3D11IBUpToDate = false; - - m_CommittedD3D11PrimTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; - m_CommittedPrimitiveTopology = PRIMITIVE_TOPOLOGY_UNDEFINED; } - void DeviceContextD3D11Impl::InvalidateState() - { - TDeviceContextBase::InvalidateState(); + m_bCommittedD3D11VBsUpToDate = false; - ReleaseCommittedShaderResources(); - for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType) - m_CommittedD3DShaders[ShaderType].Release(); - m_pd3d11DeviceContext->VSSetShader(nullptr, nullptr, 0); - m_pd3d11DeviceContext->GSSetShader(nullptr, nullptr, 0); - m_pd3d11DeviceContext->PSSetShader(nullptr, nullptr, 0); - m_pd3d11DeviceContext->HSSetShader(nullptr, nullptr, 0); - m_pd3d11DeviceContext->DSSetShader(nullptr, nullptr, 0); - m_pd3d11DeviceContext->CSSetShader(nullptr, nullptr, 0); - ID3D11RenderTargetView *d3d11NullRTV[] = {nullptr}; - m_pd3d11DeviceContext->OMSetRenderTargets(1, d3d11NullRTV, nullptr); + if (m_CommittedD3D11InputLayout != nullptr) + { + m_pd3d11DeviceContext->IASetInputLayout(nullptr); + m_CommittedD3D11InputLayout = nullptr; + } - if (m_NumCommittedD3D11VBs > 0) - { - for (Uint32 vb = 0; vb < m_NumCommittedD3D11VBs; ++vb) - { - m_CommittedD3D11VertexBuffers[vb] = nullptr; - m_CommittedD3D11VBStrides[vb] = 0; - m_CommittedD3D11VBOffsets[vb] = 0; - } - m_pd3d11DeviceContext->IASetVertexBuffers(0, m_NumCommittedD3D11VBs, m_CommittedD3D11VertexBuffers, m_CommittedD3D11VBStrides, m_CommittedD3D11VBOffsets); - m_NumCommittedD3D11VBs = 0; - } - - m_bCommittedD3D11VBsUpToDate = false; - - if (m_CommittedD3D11InputLayout != nullptr) - { - m_pd3d11DeviceContext->IASetInputLayout(nullptr); - m_CommittedD3D11InputLayout = nullptr; - } - - if (m_CommittedD3D11IndexBuffer) - { - m_pd3d11DeviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R32_UINT, 0); - m_CommittedD3D11IndexBuffer.Release(); - } + if (m_CommittedD3D11IndexBuffer) + { + m_pd3d11DeviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R32_UINT, 0); + m_CommittedD3D11IndexBuffer.Release(); + } - m_CommittedIBFormat = VT_UNDEFINED; - m_CommittedD3D11IndexDataStartOffset = 0; - m_bCommittedD3D11IBUpToDate = false; + m_CommittedIBFormat = VT_UNDEFINED; + m_CommittedD3D11IndexDataStartOffset = 0; + m_bCommittedD3D11IBUpToDate = false; - m_CommittedD3D11PrimTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; - m_CommittedPrimitiveTopology = PRIMITIVE_TOPOLOGY_UNDEFINED; - } + m_CommittedD3D11PrimTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; + m_CommittedPrimitiveTopology = PRIMITIVE_TOPOLOGY_UNDEFINED; +} - void DeviceContextD3D11Impl::TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) +void DeviceContextD3D11Impl::TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) +{ + for (Uint32 i = 0; i < BarrierCount; ++i) { - for (Uint32 i=0; i < BarrierCount; ++i) - { - const auto& Barrier = pResourceBarriers[i]; + const auto& Barrier = pResourceBarriers[i]; #ifdef DEVELOPMENT - DvpVerifyStateTransitionDesc(Barrier); + DvpVerifyStateTransitionDesc(Barrier); #endif - DEV_CHECK_ERR((Barrier.pTexture != nullptr) ^ (Barrier.pBuffer != nullptr), "Exactly one of pTexture or pBuffer must not be null"); - DEV_CHECK_ERR(Barrier.NewState != RESOURCE_STATE_UNKNOWN, "New resource state can't be unknown"); + DEV_CHECK_ERR((Barrier.pTexture != nullptr) ^ (Barrier.pBuffer != nullptr), "Exactly one of pTexture or pBuffer must not be null"); + DEV_CHECK_ERR(Barrier.NewState != RESOURCE_STATE_UNKNOWN, "New resource state can't be unknown"); - if (Barrier.TransitionType == STATE_TRANSITION_TYPE_BEGIN) - { - // Skip begin-split barriers - VERIFY(!Barrier.UpdateResourceState, "Resource state can't be updated in begin-split barrier"); - continue; - } - VERIFY(Barrier.TransitionType == STATE_TRANSITION_TYPE_IMMEDIATE || Barrier.TransitionType == STATE_TRANSITION_TYPE_END, "Unexpected barrier type"); + if (Barrier.TransitionType == STATE_TRANSITION_TYPE_BEGIN) + { + // Skip begin-split barriers + VERIFY(!Barrier.UpdateResourceState, "Resource state can't be updated in begin-split barrier"); + continue; + } + VERIFY(Barrier.TransitionType == STATE_TRANSITION_TYPE_IMMEDIATE || Barrier.TransitionType == STATE_TRANSITION_TYPE_END, "Unexpected barrier type"); - if (Barrier.pTexture) + if (Barrier.pTexture) + { + auto* pTextureD3D11Impl = ValidatedCast(Barrier.pTexture); + auto OldState = Barrier.OldState; + if (OldState == RESOURCE_STATE_UNKNOWN) { - auto* pTextureD3D11Impl = ValidatedCast(Barrier.pTexture); - auto OldState = Barrier.OldState; - if (OldState == RESOURCE_STATE_UNKNOWN) + if (pTextureD3D11Impl->IsInKnownState()) { - if (pTextureD3D11Impl->IsInKnownState()) - { - OldState = pTextureD3D11Impl->GetState(); - } - else - { - LOG_ERROR_MESSAGE("Failed to transition the state of texture '", pTextureD3D11Impl->GetDesc().Name, "' because the buffer state is unknown and is not explicitly specified"); - continue; - } + OldState = pTextureD3D11Impl->GetState(); } else { - if (pTextureD3D11Impl->IsInKnownState() && pTextureD3D11Impl->GetState() != OldState) - { - LOG_ERROR_MESSAGE("The state ", GetResourceStateString(pTextureD3D11Impl->GetState()), " of texture '", - pTextureD3D11Impl->GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState), - " specified by the barrier"); - } + LOG_ERROR_MESSAGE("Failed to transition the state of texture '", pTextureD3D11Impl->GetDesc().Name, "' because the buffer state is unknown and is not explicitly specified"); + continue; } - - if ((Barrier.NewState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) + } + else + { + if (pTextureD3D11Impl->IsInKnownState() && pTextureD3D11Impl->GetState() != OldState) { - DEV_CHECK_ERR((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) == 0, "Unordered access state is not compatible with any input state"); - UnbindTextureFromInput(pTextureD3D11Impl, pTextureD3D11Impl->GetD3D11Texture()); + LOG_ERROR_MESSAGE("The state ", GetResourceStateString(pTextureD3D11Impl->GetState()), " of texture '", + pTextureD3D11Impl->GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState), + " specified by the barrier"); } + } - if ((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) != 0) - { - if ((OldState & RESOURCE_STATE_RENDER_TARGET) !=0 ) - UnbindTextureFromRenderTarget(pTextureD3D11Impl); + if ((Barrier.NewState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) + { + DEV_CHECK_ERR((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) == 0, "Unordered access state is not compatible with any input state"); + UnbindTextureFromInput(pTextureD3D11Impl, pTextureD3D11Impl->GetD3D11Texture()); + } - if ((OldState & RESOURCE_STATE_DEPTH_WRITE) !=0 ) - UnbindTextureFromDepthStencil(pTextureD3D11Impl); + if ((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) != 0) + { + if ((OldState & RESOURCE_STATE_RENDER_TARGET) != 0) + UnbindTextureFromRenderTarget(pTextureD3D11Impl); - if ((OldState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) - { - UnbindResourceFromUAV(pTextureD3D11Impl, pTextureD3D11Impl->GetD3D11Texture()); - pTextureD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); - } - } + if ((OldState & RESOURCE_STATE_DEPTH_WRITE) != 0) + UnbindTextureFromDepthStencil(pTextureD3D11Impl); - if (Barrier.UpdateResourceState) + if ((OldState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) { - pTextureD3D11Impl->SetState(Barrier.NewState); + UnbindResourceFromUAV(pTextureD3D11Impl, pTextureD3D11Impl->GetD3D11Texture()); + pTextureD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); } } - else + + if (Barrier.UpdateResourceState) + { + pTextureD3D11Impl->SetState(Barrier.NewState); + } + } + else + { + VERIFY_EXPR(Barrier.pBuffer); + auto* pBufferD3D11Impl = ValidatedCast(Barrier.pBuffer); + auto OldState = Barrier.OldState; + if (OldState == RESOURCE_STATE_UNKNOWN) { - VERIFY_EXPR(Barrier.pBuffer); - auto* pBufferD3D11Impl = ValidatedCast(Barrier.pBuffer); - auto OldState = Barrier.OldState; - if (OldState == RESOURCE_STATE_UNKNOWN) + if (pBufferD3D11Impl->IsInKnownState()) { - if (pBufferD3D11Impl->IsInKnownState()) - { - OldState = pBufferD3D11Impl->GetState(); - } - else - { - LOG_ERROR_MESSAGE("Failed to transition the state of buffer '", pBufferD3D11Impl->GetDesc().Name, "' because the buffer state is unknown and is not explicitly specified"); - continue; - } + OldState = pBufferD3D11Impl->GetState(); } else { - if (pBufferD3D11Impl->IsInKnownState() && pBufferD3D11Impl->GetState() != OldState) - { - LOG_ERROR_MESSAGE("The state ", GetResourceStateString(pBufferD3D11Impl->GetState()), " of buffer '", - pBufferD3D11Impl->GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState), - " specified by the barrier"); - } + LOG_ERROR_MESSAGE("Failed to transition the state of buffer '", pBufferD3D11Impl->GetDesc().Name, "' because the buffer state is unknown and is not explicitly specified"); + continue; } - - if ((Barrier.NewState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) + } + else + { + if (pBufferD3D11Impl->IsInKnownState() && pBufferD3D11Impl->GetState() != OldState) { - DEV_CHECK_ERR((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) == 0, "Unordered access state is not compatible with any input state"); - UnbindBufferFromInput(pBufferD3D11Impl, pBufferD3D11Impl->m_pd3d11Buffer); + LOG_ERROR_MESSAGE("The state ", GetResourceStateString(pBufferD3D11Impl->GetState()), " of buffer '", + pBufferD3D11Impl->GetDesc().Name, "' does not match the old state ", GetResourceStateString(OldState), + " specified by the barrier"); } + } - if ((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) != 0) - { - UnbindResourceFromUAV(pBufferD3D11Impl, pBufferD3D11Impl->m_pd3d11Buffer); - } + if ((Barrier.NewState & RESOURCE_STATE_UNORDERED_ACCESS) != 0) + { + DEV_CHECK_ERR((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) == 0, "Unordered access state is not compatible with any input state"); + UnbindBufferFromInput(pBufferD3D11Impl, pBufferD3D11Impl->m_pd3d11Buffer); + } - if (Barrier.UpdateResourceState) - { - pBufferD3D11Impl->SetState(Barrier.NewState); - } + if ((Barrier.NewState & RESOURCE_STATE_GENERIC_READ) != 0) + { + UnbindResourceFromUAV(pBufferD3D11Impl, pBufferD3D11Impl->m_pd3d11Buffer); + } + + if (Barrier.UpdateResourceState) + { + pBufferD3D11Impl->SetState(Barrier.NewState); } } } +} - void DeviceContextD3D11Impl::ResolveTextureSubresource(ITexture* pSrcTexture, - ITexture* pDstTexture, - const ResolveTextureSubresourceAttribs& ResolveAttribs) - { - TDeviceContextBase::ResolveTextureSubresource(pSrcTexture, pDstTexture, ResolveAttribs); +void DeviceContextD3D11Impl::ResolveTextureSubresource(ITexture* pSrcTexture, + ITexture* pDstTexture, + const ResolveTextureSubresourceAttribs& ResolveAttribs) +{ + TDeviceContextBase::ResolveTextureSubresource(pSrcTexture, pDstTexture, ResolveAttribs); - auto* pSrcTexD3D11 = ValidatedCast(pSrcTexture); - auto* pDstTexD3D11 = ValidatedCast(pDstTexture); - const auto& SrcTexDesc = pSrcTexD3D11->GetDesc(); - const auto& DstTexDesc = pDstTexD3D11->GetDesc(); + auto* pSrcTexD3D11 = ValidatedCast(pSrcTexture); + auto* pDstTexD3D11 = ValidatedCast(pDstTexture); + const auto& SrcTexDesc = pSrcTexD3D11->GetDesc(); + const auto& DstTexDesc = pDstTexD3D11->GetDesc(); - auto Format = ResolveAttribs.Format; - if (Format == TEX_FORMAT_UNKNOWN) + auto Format = ResolveAttribs.Format; + if (Format == TEX_FORMAT_UNKNOWN) + { + const auto& SrcFmtAttribs = GetTextureFormatAttribs(SrcTexDesc.Format); + if (!SrcFmtAttribs.IsTypeless) { - const auto& SrcFmtAttribs = GetTextureFormatAttribs(SrcTexDesc.Format); - if (!SrcFmtAttribs.IsTypeless) - { - Format = SrcTexDesc.Format; - } - else - { - const auto& DstFmtAttribs = GetTextureFormatAttribs(DstTexDesc.Format); - DEV_CHECK_ERR(!DstFmtAttribs.IsTypeless, "Resolve operation format can't be typeless when both source and destination textures are typeless"); - Format = DstFmtAttribs.Format; - } + Format = SrcTexDesc.Format; + } + else + { + const auto& DstFmtAttribs = GetTextureFormatAttribs(DstTexDesc.Format); + DEV_CHECK_ERR(!DstFmtAttribs.IsTypeless, "Resolve operation format can't be typeless when both source and destination textures are typeless"); + Format = DstFmtAttribs.Format; } - - auto DXGIFmt = TexFormatToDXGI_Format(Format); - auto SrcSubresIndex = D3D11CalcSubresource(ResolveAttribs.SrcMipLevel, ResolveAttribs.SrcSlice, SrcTexDesc.MipLevels); - auto DstSubresIndex = D3D11CalcSubresource(ResolveAttribs.DstMipLevel, ResolveAttribs.DstSlice, DstTexDesc.MipLevels); - m_pd3d11DeviceContext->ResolveSubresource(pDstTexD3D11->GetD3D11Texture(), DstSubresIndex, pSrcTexD3D11->GetD3D11Texture(), SrcSubresIndex, DXGIFmt); } + auto DXGIFmt = TexFormatToDXGI_Format(Format); + auto SrcSubresIndex = D3D11CalcSubresource(ResolveAttribs.SrcMipLevel, ResolveAttribs.SrcSlice, SrcTexDesc.MipLevels); + auto DstSubresIndex = D3D11CalcSubresource(ResolveAttribs.DstMipLevel, ResolveAttribs.DstSlice, DstTexDesc.MipLevels); + m_pd3d11DeviceContext->ResolveSubresource(pDstTexD3D11->GetD3D11Texture(), DstSubresIndex, pSrcTexD3D11->GetD3D11Texture(), SrcSubresIndex, DXGIFmt); +} + +// clang-format off #ifdef VERIFY_CONTEXT_BINDINGS DEFINE_D3D11CTX_FUNC_POINTERS(GetCBMethods, GetConstantBuffers) DEFINE_D3D11CTX_FUNC_POINTERS(GetSRVMethods, GetShaderResources) @@ -2099,204 +2115,205 @@ namespace Diligent nullptr, &ID3D11DeviceContext::CSGetUnorderedAccessViews }; - - /// \tparam MaxResources - Maximum number of resources that can be bound to D3D11 context - /// \tparam TD3D11ResourceType - Type of D3D11 resource being checked (ID3D11ShaderResourceView, - /// ID3D11UnorderedAccessView, ID3D11Buffer or ID3D11SamplerState). - /// \tparam TGetD3D11ResourcesType - Type of the device context method used to get the bound - /// resources - /// \param CommittedD3D11ResourcesArr - Pointer to the array of currently bound D3D11 - /// resources, for each shader stage - /// \param GetD3D11ResMethods - Pointer to the array of device context methods to get the bound - /// resources, for each shader stage - /// \param ResourceName - Resource name - /// \param ShaderType - Shader type for which to check the resources. If Diligent::SHADER_TYPE_UNKNOWN - /// is provided, all shader stages will be checked - template - void DeviceContextD3D11Impl::dbgVerifyCommittedResources(TD3D11ResourceType CommittedD3D11ResourcesArr[][MaxResources], - Uint8 NumCommittedResourcesArr[], - TGetD3D11ResourcesType GetD3D11ResMethods[], - const Char *ResourceName, - SHADER_TYPE ShaderType) - { - int iStartInd = 0, iEndInd = NumShaderTypes; - if (ShaderType != SHADER_TYPE_UNKNOWN) +// clang-format on + +/// \tparam MaxResources - Maximum number of resources that can be bound to D3D11 context +/// \tparam TD3D11ResourceType - Type of D3D11 resource being checked (ID3D11ShaderResourceView, +/// ID3D11UnorderedAccessView, ID3D11Buffer or ID3D11SamplerState). +/// \tparam TGetD3D11ResourcesType - Type of the device context method used to get the bound +/// resources +/// \param CommittedD3D11ResourcesArr - Pointer to the array of currently bound D3D11 +/// resources, for each shader stage +/// \param GetD3D11ResMethods - Pointer to the array of device context methods to get the bound +/// resources, for each shader stage +/// \param ResourceName - Resource name +/// \param ShaderType - Shader type for which to check the resources. If Diligent::SHADER_TYPE_UNKNOWN +/// is provided, all shader stages will be checked +template +void DeviceContextD3D11Impl::dbgVerifyCommittedResources(TD3D11ResourceType CommittedD3D11ResourcesArr[][MaxResources], + Uint8 NumCommittedResourcesArr[], + TGetD3D11ResourcesType GetD3D11ResMethods[], + const Char* ResourceName, + SHADER_TYPE ShaderType) +{ + int iStartInd = 0, iEndInd = NumShaderTypes; + if (ShaderType != SHADER_TYPE_UNKNOWN) + { + iStartInd = GetShaderTypeIndex(ShaderType); + iEndInd = iStartInd + 1; + } + for (int iShaderTypeInd = iStartInd; iShaderTypeInd < iEndInd; ++iShaderTypeInd) + { + const auto ShaderName = GetShaderTypeLiteralName(GetShaderTypeFromIndex(iShaderTypeInd)); + TD3D11ResourceType pctxResources[MaxResources] = {}; + auto GetResMethod = GetD3D11ResMethods[iShaderTypeInd]; + if (GetResMethod) { - iStartInd = GetShaderTypeIndex(ShaderType); - iEndInd = iStartInd + 1; + (m_pd3d11DeviceContext->*GetResMethod)(0, _countof(pctxResources), pctxResources); } - for (int iShaderTypeInd = iStartInd; iShaderTypeInd < iEndInd; ++iShaderTypeInd) + const auto* CommittedResources = CommittedD3D11ResourcesArr[iShaderTypeInd]; + auto NumCommittedResources = NumCommittedResourcesArr[iShaderTypeInd]; + for (Uint32 Slot = 0; Slot < _countof(pctxResources); ++Slot) { - const auto ShaderName = GetShaderTypeLiteralName( GetShaderTypeFromIndex(iShaderTypeInd) ); - TD3D11ResourceType pctxResources[MaxResources] = {}; - auto GetResMethod = GetD3D11ResMethods[iShaderTypeInd]; - if (GetResMethod) + if (Slot < NumCommittedResources) { - (m_pd3d11DeviceContext->*GetResMethod)(0, _countof( pctxResources ), pctxResources); + VERIFY(CommittedResources[Slot] == pctxResources[Slot], ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot); } - const auto* CommittedResources = CommittedD3D11ResourcesArr[iShaderTypeInd]; - auto NumCommittedResources = NumCommittedResourcesArr[iShaderTypeInd]; - for (Uint32 Slot = 0; Slot < _countof( pctxResources ); ++Slot) + else { - if( Slot < NumCommittedResources ) - { - VERIFY( CommittedResources[Slot] == pctxResources[Slot], ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot ); - } - else - { - VERIFY( pctxResources[Slot] == nullptr, ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot ); - VERIFY( CommittedResources[Slot] == nullptr, ResourceName, " unexpected non-null resource found for ", ShaderName, " shader type at slot ", Slot ); - } - - if( pctxResources[Slot] ) - pctxResources[Slot]->Release(); + VERIFY(pctxResources[Slot] == nullptr, ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot); + VERIFY(CommittedResources[Slot] == nullptr, ResourceName, " unexpected non-null resource found for ", ShaderName, " shader type at slot ", Slot); } + + if (pctxResources[Slot]) + pctxResources[Slot]->Release(); } } +} - template - void DeviceContextD3D11Impl::dbgVerifyViewConsistency(TD3D11ViewType CommittedD3D11ViewArr[][MaxResources], - ID3D11Resource* CommittedD3D11ResourcesArr[][MaxResources], - Uint8 NumCommittedResourcesArr[], - const Char *ResourceName, - SHADER_TYPE ShaderType) +template +void DeviceContextD3D11Impl::dbgVerifyViewConsistency(TD3D11ViewType CommittedD3D11ViewArr[][MaxResources], + ID3D11Resource* CommittedD3D11ResourcesArr[][MaxResources], + Uint8 NumCommittedResourcesArr[], + const Char* ResourceName, + SHADER_TYPE ShaderType) +{ + int iStartInd = 0, iEndInd = NumShaderTypes; + if (ShaderType != SHADER_TYPE_UNKNOWN) { - int iStartInd = 0, iEndInd = NumShaderTypes; - if (ShaderType != SHADER_TYPE_UNKNOWN) - { - iStartInd = GetShaderTypeIndex(ShaderType); - iEndInd = iStartInd + 1; - } - for (int iShaderTypeInd = iStartInd; iShaderTypeInd < iEndInd; ++iShaderTypeInd) + iStartInd = GetShaderTypeIndex(ShaderType); + iEndInd = iStartInd + 1; + } + for (int iShaderTypeInd = iStartInd; iShaderTypeInd < iEndInd; ++iShaderTypeInd) + { + const auto ShaderName = GetShaderTypeLiteralName(GetShaderTypeFromIndex(iShaderTypeInd)); + auto* Views = CommittedD3D11ViewArr[iShaderTypeInd]; + auto* Resources = CommittedD3D11ResourcesArr[iShaderTypeInd]; + auto NumCommittedResources = NumCommittedResourcesArr[iShaderTypeInd]; + for (Uint32 Slot = 0; Slot < NumCommittedResources; ++Slot) { - const auto ShaderName = GetShaderTypeLiteralName( GetShaderTypeFromIndex(iShaderTypeInd) ); - auto* Views = CommittedD3D11ViewArr[iShaderTypeInd]; - auto* Resources = CommittedD3D11ResourcesArr[iShaderTypeInd]; - auto NumCommittedResources = NumCommittedResourcesArr[iShaderTypeInd]; - for (Uint32 Slot = 0; Slot < NumCommittedResources; ++Slot) + if (Views[Slot] != nullptr) { - if (Views[Slot] != nullptr) - { - CComPtr pRefRes; - Views[Slot]->GetResource(&pRefRes); - VERIFY( pRefRes == Resources[Slot], "Inconsistent ", ResourceName, " detected at slot ", Slot, " in shader ", ShaderName, ". The resource in the view does not match cached D3D11 resource" ); - } + CComPtr pRefRes; + Views[Slot]->GetResource(&pRefRes); + VERIFY(pRefRes == Resources[Slot], "Inconsistent ", ResourceName, " detected at slot ", Slot, " in shader ", ShaderName, ". The resource in the view does not match cached D3D11 resource"); } } } +} - void DeviceContextD3D11Impl::dbgVerifyCommittedSRVs(SHADER_TYPE ShaderType) - { - dbgVerifyCommittedResources( m_CommittedD3D11SRVs, m_NumCommittedSRVs, GetSRVMethods, "SRV", ShaderType ); - dbgVerifyViewConsistency( m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, "SRV", ShaderType ); - } +void DeviceContextD3D11Impl::dbgVerifyCommittedSRVs(SHADER_TYPE ShaderType) +{ + dbgVerifyCommittedResources(m_CommittedD3D11SRVs, m_NumCommittedSRVs, GetSRVMethods, "SRV", ShaderType); + dbgVerifyViewConsistency(m_CommittedD3D11SRVs, m_CommittedD3D11SRVResources, m_NumCommittedSRVs, "SRV", ShaderType); +} - void DeviceContextD3D11Impl::dbgVerifyCommittedUAVs(SHADER_TYPE ShaderType) - { - dbgVerifyCommittedResources( m_CommittedD3D11UAVs, m_NumCommittedUAVs, GetUAVMethods, "UAV", ShaderType ); - dbgVerifyViewConsistency( m_CommittedD3D11UAVs, m_CommittedD3D11UAVResources, m_NumCommittedUAVs, "UAV", ShaderType ); - } +void DeviceContextD3D11Impl::dbgVerifyCommittedUAVs(SHADER_TYPE ShaderType) +{ + dbgVerifyCommittedResources(m_CommittedD3D11UAVs, m_NumCommittedUAVs, GetUAVMethods, "UAV", ShaderType); + dbgVerifyViewConsistency(m_CommittedD3D11UAVs, m_CommittedD3D11UAVResources, m_NumCommittedUAVs, "UAV", ShaderType); +} - void DeviceContextD3D11Impl::dbgVerifyCommittedSamplers(SHADER_TYPE ShaderType) - { - dbgVerifyCommittedResources( m_CommittedD3D11Samplers, m_NumCommittedSamplers, GetSamplerMethods, "Sampler", ShaderType ); - } +void DeviceContextD3D11Impl::dbgVerifyCommittedSamplers(SHADER_TYPE ShaderType) +{ + dbgVerifyCommittedResources(m_CommittedD3D11Samplers, m_NumCommittedSamplers, GetSamplerMethods, "Sampler", ShaderType); +} - void DeviceContextD3D11Impl::dbgVerifyCommittedCBs(SHADER_TYPE ShaderType) - { - dbgVerifyCommittedResources( m_CommittedD3D11CBs, m_NumCommittedCBs, GetCBMethods, "Constant buffer", ShaderType ); - } +void DeviceContextD3D11Impl::dbgVerifyCommittedCBs(SHADER_TYPE ShaderType) +{ + dbgVerifyCommittedResources(m_CommittedD3D11CBs, m_NumCommittedCBs, GetCBMethods, "Constant buffer", ShaderType); +} - void DeviceContextD3D11Impl::dbgVerifyCommittedIndexBuffer() - { - RefCntAutoPtr pctxIndexBuffer; - DXGI_FORMAT Fmt = DXGI_FORMAT_UNKNOWN; - UINT Offset = 0; - m_pd3d11DeviceContext->IAGetIndexBuffer( &pctxIndexBuffer, &Fmt, &Offset ); - if (m_CommittedD3D11IndexBuffer && !pctxIndexBuffer) - UNEXPECTED( "D3D11 index buffer is not bound to the context" ); - if (!m_CommittedD3D11IndexBuffer && pctxIndexBuffer) - UNEXPECTED( "Unexpected D3D11 index buffer is bound to the context" ); +void DeviceContextD3D11Impl::dbgVerifyCommittedIndexBuffer() +{ + RefCntAutoPtr pctxIndexBuffer; + DXGI_FORMAT Fmt = DXGI_FORMAT_UNKNOWN; + UINT Offset = 0; + m_pd3d11DeviceContext->IAGetIndexBuffer(&pctxIndexBuffer, &Fmt, &Offset); + if (m_CommittedD3D11IndexBuffer && !pctxIndexBuffer) + UNEXPECTED("D3D11 index buffer is not bound to the context"); + if (!m_CommittedD3D11IndexBuffer && pctxIndexBuffer) + UNEXPECTED("Unexpected D3D11 index buffer is bound to the context"); - if (m_CommittedD3D11IndexBuffer && pctxIndexBuffer) + if (m_CommittedD3D11IndexBuffer && pctxIndexBuffer) + { + VERIFY(m_CommittedD3D11IndexBuffer == pctxIndexBuffer, "Index buffer binding mismatch detected"); + if (Fmt == DXGI_FORMAT_R32_UINT) { - VERIFY(m_CommittedD3D11IndexBuffer == pctxIndexBuffer, "Index buffer binding mismatch detected"); - if (Fmt==DXGI_FORMAT_R32_UINT) - { - VERIFY(m_CommittedIBFormat == VT_UINT32, "Index buffer format mismatch detected"); - } - else if (Fmt==DXGI_FORMAT_R16_UINT) - { - VERIFY(m_CommittedIBFormat == VT_UINT16, "Index buffer format mismatch detected"); - } - VERIFY(m_CommittedD3D11IndexDataStartOffset == Offset, "Index buffer offset mismatch detected"); + VERIFY(m_CommittedIBFormat == VT_UINT32, "Index buffer format mismatch detected"); + } + else if (Fmt == DXGI_FORMAT_R16_UINT) + { + VERIFY(m_CommittedIBFormat == VT_UINT16, "Index buffer format mismatch detected"); } + VERIFY(m_CommittedD3D11IndexDataStartOffset == Offset, "Index buffer offset mismatch detected"); } +} - void DeviceContextD3D11Impl::dbgVerifyCommittedVertexBuffers() - { - CComPtr pInputLayout; - m_pd3d11DeviceContext->IAGetInputLayout(&pInputLayout); - VERIFY( pInputLayout == m_CommittedD3D11InputLayout, "Inconsistent input layout" ); - - const Uint32 MaxVBs = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; - ID3D11Buffer* pVBs[MaxVBs]; - UINT Strides[MaxVBs]; - UINT Offsets[MaxVBs]; - m_pd3d11DeviceContext->IAGetVertexBuffers( 0, MaxVBs, pVBs, Strides, Offsets ); - auto NumBoundVBs = m_NumCommittedD3D11VBs; - for (Uint32 Slot = 0; Slot < MaxVBs; ++Slot) - { - if (Slot < NumBoundVBs) - { - const auto &BoundD3D11VB = m_CommittedD3D11VertexBuffers[Slot]; - auto BoundVBStride = m_CommittedD3D11VBStrides[Slot]; - auto BoundVBOffset = m_CommittedD3D11VBOffsets[Slot]; - if(BoundD3D11VB && !pVBs[Slot] ) - VERIFY( pVBs[Slot] == nullptr, "Missing D3D11 buffer detected at slot ", Slot ); - if(!BoundD3D11VB && pVBs[Slot] ) - VERIFY( pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot ); - if( BoundD3D11VB && pVBs[Slot] ) - { - VERIFY( BoundD3D11VB == pVBs[Slot], "Vertex buffer mismatch detected at slot ", Slot ); - VERIFY( BoundVBOffset == Offsets[Slot], "Offset mismatch detected at slot ", Slot ); - VERIFY( BoundVBStride == Strides[Slot], "Stride mismatch detected at slot ", Slot ); - } - } - else +void DeviceContextD3D11Impl::dbgVerifyCommittedVertexBuffers() +{ + CComPtr pInputLayout; + m_pd3d11DeviceContext->IAGetInputLayout(&pInputLayout); + VERIFY(pInputLayout == m_CommittedD3D11InputLayout, "Inconsistent input layout"); + + const Uint32 MaxVBs = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; + ID3D11Buffer* pVBs[MaxVBs]; + UINT Strides[MaxVBs]; + UINT Offsets[MaxVBs]; + m_pd3d11DeviceContext->IAGetVertexBuffers(0, MaxVBs, pVBs, Strides, Offsets); + auto NumBoundVBs = m_NumCommittedD3D11VBs; + for (Uint32 Slot = 0; Slot < MaxVBs; ++Slot) + { + if (Slot < NumBoundVBs) + { + const auto& BoundD3D11VB = m_CommittedD3D11VertexBuffers[Slot]; + auto BoundVBStride = m_CommittedD3D11VBStrides[Slot]; + auto BoundVBOffset = m_CommittedD3D11VBOffsets[Slot]; + if (BoundD3D11VB && !pVBs[Slot]) + VERIFY(pVBs[Slot] == nullptr, "Missing D3D11 buffer detected at slot ", Slot); + if (!BoundD3D11VB && pVBs[Slot]) + VERIFY(pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot); + if (BoundD3D11VB && pVBs[Slot]) { - VERIFY( pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot ); + VERIFY(BoundD3D11VB == pVBs[Slot], "Vertex buffer mismatch detected at slot ", Slot); + VERIFY(BoundVBOffset == Offsets[Slot], "Offset mismatch detected at slot ", Slot); + VERIFY(BoundVBStride == Strides[Slot], "Stride mismatch detected at slot ", Slot); } - - if (pVBs[Slot]) - pVBs[Slot]->Release(); } - } + else + { + VERIFY(pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot); + } - template - void dbgVerifyCommittedShadersHelper(SHADER_TYPE ShaderType, - const CComPtr BoundD3DShaders[], - ID3D11DeviceContext* pCtx, - TGetShaderMethodType GetShaderMethod) - { - RefCntAutoPtr pctxShader; - (pCtx->*GetShaderMethod)(&pctxShader, nullptr, nullptr); - const auto &BoundShader = BoundD3DShaders[GetShaderTypeIndex( ShaderType )]; - VERIFY( BoundShader == pctxShader, GetShaderTypeLiteralName(ShaderType), " binding mismatch detected" ); - } - void DeviceContextD3D11Impl::dbgVerifyCommittedShaders() - { -#define VERIFY_SHADER(NAME, Name, N) dbgVerifyCommittedShadersHelper(SHADER_TYPE_##NAME, m_CommittedD3DShaders, m_pd3d11DeviceContext, &ID3D11DeviceContext::N##SGetShader ) - // These shaders which are not set will be unbound from the D3D11 device context - VERIFY_SHADER( VERTEX, Vertex, V ); - VERIFY_SHADER( PIXEL, Pixel, P ); - VERIFY_SHADER( GEOMETRY, Geometry, G ); - VERIFY_SHADER( DOMAIN, Domain, D ); - VERIFY_SHADER( HULL, Hull, H ); - VERIFY_SHADER( COMPUTE, Compute, C ); + if (pVBs[Slot]) + pVBs[Slot]->Release(); } +} -#endif // VERIFY_CONTEXT_BINDINGS +template +void dbgVerifyCommittedShadersHelper(SHADER_TYPE ShaderType, + const CComPtr BoundD3DShaders[], + ID3D11DeviceContext* pCtx, + TGetShaderMethodType GetShaderMethod) +{ + RefCntAutoPtr pctxShader; + (pCtx->*GetShaderMethod)(&pctxShader, nullptr, nullptr); + const auto& BoundShader = BoundD3DShaders[GetShaderTypeIndex(ShaderType)]; + VERIFY(BoundShader == pctxShader, GetShaderTypeLiteralName(ShaderType), " binding mismatch detected"); } +void DeviceContextD3D11Impl::dbgVerifyCommittedShaders() +{ +# define VERIFY_SHADER(NAME, Name, N) dbgVerifyCommittedShadersHelper(SHADER_TYPE_##NAME, m_CommittedD3DShaders, m_pd3d11DeviceContext, &ID3D11DeviceContext::N##SGetShader) + // These shaders which are not set will be unbound from the D3D11 device context + VERIFY_SHADER(VERTEX, Vertex, V); + VERIFY_SHADER(PIXEL, Pixel, P); + VERIFY_SHADER(GEOMETRY, Geometry, G); + VERIFY_SHADER(DOMAIN, Domain, D); + VERIFY_SHADER(HULL, Hull, H); + VERIFY_SHADER(COMPUTE, Compute, C); +} + +#endif // VERIFY_CONTEXT_BINDINGS +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp index 01e8e913..6ffb2731 100644 --- a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp @@ -47,29 +47,29 @@ public: static EngineFactoryD3D11Impl TheFactory; return &TheFactory; } - + using TBase = EngineFactoryD3DBase; EngineFactoryD3D11Impl() : - TBase(IID_EngineFactoryD3D11) + TBase{IID_EngineFactoryD3D11} {} - void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts)override final; - - void CreateSwapChainD3D11(IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SCDesc, - const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, - ISwapChain** ppSwapChain)override final; - - void AttachToD3D11Device(void* pd3d11NativeDevice, - void* pd3d11ImmediateContext, - const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts)override final; + void CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts) override final; + + void CreateSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pImmediateContext, + const SwapChainDesc& SCDesc, + const FullScreenModeDesc& FSDesc, + void* pNativeWndHandle, + ISwapChain** ppSwapChain) override final; + + void AttachToD3D11Device(void* pd3d11NativeDevice, + void* pd3d11ImmediateContext, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts) override final; }; @@ -77,27 +77,27 @@ public: // Check for SDK Layer support. inline bool SdkLayersAvailable() { - HRESULT hr = D3D11CreateDevice( - nullptr, - D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device. - 0, - D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers. - nullptr, // Any feature level will do. - 0, - D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. - nullptr, // No need to keep the D3D device reference. - nullptr, // No need to know the feature level. - nullptr // No need to keep the D3D device context reference. - ); - - return SUCCEEDED(hr); + HRESULT hr = D3D11CreateDevice( + nullptr, + D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device. + 0, + D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers. + nullptr, // Any feature level will do. + 0, + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. + nullptr, // No need to keep the D3D device reference. + nullptr, // No need to know the feature level. + nullptr // No need to keep the D3D device context reference. + ); + + return SUCCEEDED(hr); } #endif -void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, - IDeviceContext** ppContexts) +void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, + IDeviceContext** ppContexts) { if (EngineCI.APIVersion != DILIGENT_API_VERSION) LOG_ERROR_AND_THROW("Diligent Engine runtime (", EngineCI.APIVersion, ") is not compatible with the client API version (", DILIGENT_API_VERSION, ")"); @@ -105,8 +105,8 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11Creat if (EngineCI.DebugMessageCallback != nullptr) SetDebugMessageCallback(EngineCI.DebugMessageCallback); - VERIFY( ppDevice && ppContexts, "Null pointer provided" ); - if( !ppDevice || !ppContexts ) + VERIFY(ppDevice && ppContexts, "Null pointer provided"); + if (!ppDevice || !ppContexts) return; if (EngineCI.MinimumFeatureLevel >= DIRECT3D_FEATURE_LEVEL_12_0) @@ -115,17 +115,17 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11Creat *ppDevice = nullptr; memset(ppContexts, 0, sizeof(*ppContexts) * (1 + EngineCI.NumDeferredContexts)); - // This flag adds support for surfaces with a different color channel ordering - // than the API default. It is required for compatibility with Direct2D. + // This flag adds support for surfaces with a different color channel ordering + // than the API default. It is required for compatibility with Direct2D. // D3D11_CREATE_DEVICE_BGRA_SUPPORT; UINT creationFlags = 0; #if defined(DEVELOPMENT) - if ((EngineCI.DebugFlags & D3D11_DEBUG_FLAG_CREATE_DEBUG_DEVICE) != 0 && SdkLayersAvailable()) - { - // If the project is in a debug build, enable debugging via SDK Layers with this flag. - creationFlags |= D3D11_CREATE_DEVICE_DEBUG; - } + if ((EngineCI.DebugFlags & D3D11_DEBUG_FLAG_CREATE_DEBUG_DEVICE) != 0 && SdkLayersAvailable()) + { + // If the project is in a debug build, enable debugging via SDK Layers with this flag. + creationFlags |= D3D11_CREATE_DEVICE_DEBUG; + } #endif CComPtr SpecificAdapter; @@ -140,24 +140,24 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11Creat } } - // Create the Direct3D 11 API device object and a corresponding context. - CComPtr pd3d11Device; - CComPtr pd3d11Context; + // Create the Direct3D 11 API device object and a corresponding context. + CComPtr pd3d11Device; + CComPtr pd3d11Context; for (int adapterType = 0; adapterType < 2 && !pd3d11Device; ++adapterType) { IDXGIAdapter* adapter = nullptr; D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_UNKNOWN; - switch(adapterType) + switch (adapterType) { case 0: adapter = SpecificAdapter; driverType = SpecificAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE; - break; + break; case 1: driverType = D3D_DRIVER_TYPE_WARP; - break; + break; default: UNEXPECTED("Unexpected adapter type"); @@ -168,21 +168,21 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11Creat // runtime installed, this function immediately fails with E_INVALIDARG. // To avoid failure in this case we will try one feature level at a time constexpr auto MaxFeatureLevel = DIRECT3D_FEATURE_LEVEL_11_1; - for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= EngineCI.MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel}-1)) + for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= EngineCI.MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel} - 1)) { auto d3dFeatureLevel = GetD3DFeatureLevel(FeatureLevel); - auto hr = D3D11CreateDevice( - adapter, // Specify nullptr to use the default adapter. - driverType, // If no adapter specified, request hardware graphics driver. - 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. - creationFlags, // Set debug and Direct2D compatibility flags. - &d3dFeatureLevel, // List of feature levels this app can support. - 1, // Size of the list above. - D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. - &pd3d11Device, // Returns the Direct3D device created. - nullptr, // Returns feature level of device created. - &pd3d11Context // Returns the device immediate context. - ); + auto hr = D3D11CreateDevice( + adapter, // Specify nullptr to use the default adapter. + driverType, // If no adapter specified, request hardware graphics driver. + 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. + creationFlags, // Set debug and Direct2D compatibility flags. + &d3dFeatureLevel, // List of feature levels this app can support. + 1, // Size of the list above. + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. + &pd3d11Device, // Returns the Direct3D device created. + nullptr, // Returns feature level of device created. + &pd3d11Context // Returns the device immediate context. + ); if (SUCCEEDED(hr)) { @@ -199,10 +199,10 @@ void EngineFactoryD3D11Impl::CreateDeviceAndContextsD3D11(const EngineD3D11Creat } -void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d11NativeDevice, +void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd3d11NativeDevice, void* pd3d11ImmediateContext, - const EngineD3D11CreateInfo& EngineCI, - IRenderDevice** ppDevice, + const EngineD3D11CreateInfo& EngineCI, + IRenderDevice** ppDevice, IDeviceContext** ppContexts) { if (EngineCI.APIVersion != DILIGENT_API_VERSION) @@ -211,23 +211,21 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd if (EngineCI.DebugMessageCallback != nullptr) SetDebugMessageCallback(EngineCI.DebugMessageCallback); - VERIFY( ppDevice && ppContexts, "Null pointer provided" ); - if( !ppDevice || !ppContexts ) + VERIFY(ppDevice && ppContexts, "Null pointer provided"); + if (!ppDevice || !ppContexts) return; try { - ID3D11Device* pd3d11Device = reinterpret_cast(pd3d11NativeDevice); - ID3D11DeviceContext* pd3d11ImmediateCtx = reinterpret_cast(pd3d11ImmediateContext); + ID3D11Device* pd3d11Device = reinterpret_cast(pd3d11NativeDevice); + ID3D11DeviceContext* pd3d11ImmediateCtx = reinterpret_cast(pd3d11ImmediateContext); SetRawAllocator(EngineCI.pRawMemAllocator); - auto& RawAlloctor = GetRawAllocator(); - RenderDeviceD3D11Impl* pRenderDeviceD3D11(NEW_RC_OBJ(RawAlloctor, "RenderDeviceD3D11Impl instance", RenderDeviceD3D11Impl) - (RawAlloctor, this, EngineCI, pd3d11Device, EngineCI.NumDeferredContexts)); + auto& RawAlloctor = GetRawAllocator(); + RenderDeviceD3D11Impl* pRenderDeviceD3D11(NEW_RC_OBJ(RawAlloctor, "RenderDeviceD3D11Impl instance", RenderDeviceD3D11Impl)(RawAlloctor, this, EngineCI, pd3d11Device, EngineCI.NumDeferredContexts)); pRenderDeviceD3D11->QueryInterface(IID_RenderDevice, reinterpret_cast(ppDevice)); - RefCntAutoPtr pDeviceContextD3D11(NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl) - (RawAlloctor, pRenderDeviceD3D11, pd3d11ImmediateCtx, EngineCI, false)); + RefCntAutoPtr pDeviceContextD3D11(NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl)(RawAlloctor, pRenderDeviceD3D11, pd3d11ImmediateCtx, EngineCI, false)); // We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D11 will // keep a weak reference to the context pDeviceContextD3D11->QueryInterface(IID_DeviceContext, reinterpret_cast(ppContexts)); @@ -236,47 +234,48 @@ void EngineFactoryD3D11Impl::AttachToD3D11Device(void* pd for (Uint32 DeferredCtx = 0; DeferredCtx < EngineCI.NumDeferredContexts; ++DeferredCtx) { CComPtr pd3d11DeferredCtx; + HRESULT hr = pd3d11Device->CreateDeferredContext(0, &pd3d11DeferredCtx); CHECK_D3D_RESULT_THROW(hr, "Failed to create D3D11 deferred context"); + RefCntAutoPtr pDeferredCtxD3D11( - NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl) - (RawAlloctor, pRenderDeviceD3D11, pd3d11DeferredCtx, EngineCI, true)); + NEW_RC_OBJ(RawAlloctor, "DeviceContextD3D11Impl instance", DeviceContextD3D11Impl)(RawAlloctor, pRenderDeviceD3D11, pd3d11DeferredCtx, EngineCI, true)); // We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D12 will // keep a weak reference to the context pDeferredCtxD3D11->QueryInterface(IID_DeviceContext, reinterpret_cast(ppContexts + 1 + DeferredCtx)); pRenderDeviceD3D11->SetDeferredContext(DeferredCtx, pDeferredCtxD3D11); } } - catch( const std::runtime_error & ) + catch (const std::runtime_error&) { - if( *ppDevice ) + if (*ppDevice) { (*ppDevice)->Release(); *ppDevice = nullptr; } - for(Uint32 ctx=0; ctx < 1 + EngineCI.NumDeferredContexts; ++ctx) + for (Uint32 ctx = 0; ctx < 1 + EngineCI.NumDeferredContexts; ++ctx) { - if( ppContexts[ctx] != nullptr ) + if (ppContexts[ctx] != nullptr) { ppContexts[ctx]->Release(); ppContexts[ctx] = nullptr; } } - LOG_ERROR( "Failed to initialize D3D11 device and contexts" ); + LOG_ERROR("Failed to initialize D3D11 device and contexts"); } } -void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDevice, - IDeviceContext* pImmediateContext, - const SwapChainDesc& SCDesc, +void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDevice, + IDeviceContext* pImmediateContext, + const SwapChainDesc& SCDesc, const FullScreenModeDesc& FSDesc, - void* pNativeWndHandle, + void* pNativeWndHandle, ISwapChain** ppSwapChain) { - VERIFY( ppSwapChain, "Null pointer provided" ); - if( !ppSwapChain ) + VERIFY(ppSwapChain, "Null pointer provided"); + if (!ppSwapChain) return; *ppSwapChain = nullptr; @@ -293,9 +292,8 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDev "There must only be one primary swap chain."); } - auto* pSwapChainD3D11 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D11Impl instance", SwapChainD3D11Impl) - (SCDesc, FSDesc, pDeviceD3D11, pDeviceContextD3D11, pNativeWndHandle); - pSwapChainD3D11->QueryInterface( IID_SwapChain, reinterpret_cast(ppSwapChain) ); + auto* pSwapChainD3D11 = NEW_RC_OBJ(RawMemAllocator, "SwapChainD3D11Impl instance", SwapChainD3D11Impl)(SCDesc, FSDesc, pDeviceD3D11, pDeviceContextD3D11, pNativeWndHandle); + pSwapChainD3D11->QueryInterface(IID_SwapChain, reinterpret_cast(ppSwapChain)); if (SCDesc.IsPrimary) { @@ -310,7 +308,7 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDev { if (auto pDeferredCtx = pDeviceD3D11->GetDeferredContext(ctx)) { - auto *pDeferredCtxD3D11 = pDeferredCtx.RawPtr(); + auto* pDeferredCtxD3D11 = pDeferredCtx.RawPtr(); pDeferredCtxD3D11->SetSwapChain(pSwapChainD3D11); // Do not bind default render target and viewport to be // consistent with D3D12 @@ -322,15 +320,15 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDev } } } - catch( const std::runtime_error & ) + catch (const std::runtime_error&) { - if( *ppSwapChain ) + if (*ppSwapChain) { (*ppSwapChain)->Release(); *ppSwapChain = nullptr; } - LOG_ERROR( "Failed to create the swap chain" ); + LOG_ERROR("Failed to create the swap chain"); } } @@ -344,10 +342,10 @@ void EngineFactoryD3D11Impl::CreateSwapChainD3D11(IRenderDevice* pDev /// x86 | GraphicsEngineD3D11_32d.dll | GraphicsEngineD3D11_32r.dll /// x64 | GraphicsEngineD3D11_64d.dll | GraphicsEngineD3D11_64r.dll /// -void LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type &GetFactoryFunc) +void LoadGraphicsEngineD3D11(GetEngineFactoryD3D11Type& GetFactoryFunc) { - // This function is only required because DoxyGen refuses to generate documentation for a static function when SHOW_FILES==NO - #error This function must never be compiled; +// This function is only required because DoxyGen refuses to generate documentation for a static function when SHOW_FILES==NO +# error This function must never be compiled; } #endif @@ -357,4 +355,4 @@ IEngineFactoryD3D11* GetEngineFactoryD3D11() return EngineFactoryD3D11Impl::GetInstance(); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp index f63185f5..201f1b1f 100644 --- a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp @@ -29,26 +29,26 @@ namespace Diligent { - -FenceD3D11Impl :: FenceD3D11Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - const FenceDesc& Desc) : + +FenceD3D11Impl::FenceD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + const FenceDesc& Desc) : TFenceBase{pRefCounters, pDevice, Desc} { } -FenceD3D11Impl :: ~FenceD3D11Impl() +FenceD3D11Impl::~FenceD3D11Impl() { } -Uint64 FenceD3D11Impl :: GetCompletedValue() +Uint64 FenceD3D11Impl::GetCompletedValue() { while (!m_PendingQueries.empty()) { auto& QueryData = m_PendingQueries.front(); - BOOL Data; - auto res = QueryData.pd3d11Ctx->GetData(QueryData.pd3d11Query, &Data, sizeof(Data), D3D11_ASYNC_GETDATA_DONOTFLUSH); - if(res == S_OK) + BOOL Data; + auto res = QueryData.pd3d11Ctx->GetData(QueryData.pd3d11Query, &Data, sizeof(Data), D3D11_ASYNC_GETDATA_DONOTFLUSH); + if (res == S_OK) { VERIFY_EXPR(Data == TRUE); if (QueryData.Value > m_LastCompletedFenceValue) @@ -64,7 +64,7 @@ Uint64 FenceD3D11Impl :: GetCompletedValue() return m_LastCompletedFenceValue; } -void FenceD3D11Impl :: Wait(Uint64 Value, bool FlushCommands) +void FenceD3D11Impl::Wait(Uint64 Value, bool FlushCommands) { while (!m_PendingQueries.empty()) { @@ -84,11 +84,11 @@ void FenceD3D11Impl :: Wait(Uint64 Value, bool FlushCommands) } } -void FenceD3D11Impl :: Reset(Uint64 Value) +void FenceD3D11Impl::Reset(Uint64 Value) { DEV_CHECK_ERR(Value >= m_LastCompletedFenceValue, "Resetting fence '", m_Desc.Name, "' to the value (", Value, ") that is smaller than the last completed value (", m_LastCompletedFenceValue, ")"); if (Value > m_LastCompletedFenceValue) m_LastCompletedFenceValue = Value; } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index d913faaa..c0df34de 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -34,7 +34,8 @@ namespace Diligent PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCounters, RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const PipelineStateDesc& PipelineDesc) : + const PipelineStateDesc& PipelineDesc) : + // clang-format off TPipelineStateBase { pRefCounters, @@ -43,11 +44,12 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun }, m_SRBMemAllocator{GetRawAllocator()}, m_StaticSamplers {STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector")} +// clang-format on { if (PipelineDesc.IsComputePipeline) { auto* pCS = ValidatedCast(PipelineDesc.ComputePipeline.pCS); - m_pCS = pCS; + m_pCS = pCS; if (m_pCS == nullptr) { LOG_ERROR_AND_THROW("Compute shader is null"); @@ -62,17 +64,18 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun else { -#define INIT_SHADER(ShortName, ExpectedType)\ - { \ - auto* pShader = ValidatedCast(PipelineDesc.GraphicsPipeline.p##ShortName); \ - m_p##ShortName = pShader; \ - if (m_p##ShortName && m_p##ShortName->GetDesc().ShaderType != ExpectedType) \ - { \ - LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(ExpectedType), " shader is expeceted while ", GetShaderTypeLiteralName(m_p##ShortName->GetDesc().ShaderType)," provided" ); \ - } \ - if(pShader!=nullptr) \ - HashCombine(m_ShaderResourceLayoutHash, pShader->GetD3D11Resources()->GetHash() ); \ - } +#define INIT_SHADER(ShortName, ExpectedType) \ + do \ + { \ + auto* pShader = ValidatedCast(PipelineDesc.GraphicsPipeline.p##ShortName); \ + m_p##ShortName = pShader; \ + if (m_p##ShortName && m_p##ShortName->GetDesc().ShaderType != ExpectedType) \ + { \ + LOG_ERROR_AND_THROW(GetShaderTypeLiteralName(ExpectedType), " shader is expeceted while ", GetShaderTypeLiteralName(m_p##ShortName->GetDesc().ShaderType), " provided"); \ + } \ + if (pShader != nullptr) \ + HashCombine(m_ShaderResourceLayoutHash, pShader->GetD3D11Resources()->GetHash()); \ + } while (false) INIT_SHADER(VS, SHADER_TYPE_VERTEX); INIT_SHADER(PS, SHADER_TYPE_PIXEL); @@ -87,39 +90,40 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun } auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + D3D11_BLEND_DESC D3D11BSDesc = {}; BlendStateDesc_To_D3D11_BLEND_DESC(PipelineDesc.GraphicsPipeline.BlendDesc, D3D11BSDesc); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateBlendState( &D3D11BSDesc, &m_pd3d11BlendState ), - "Failed to create D3D11 blend state object" ); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateBlendState(&D3D11BSDesc, &m_pd3d11BlendState), + "Failed to create D3D11 blend state object"); D3D11_RASTERIZER_DESC D3D11RSDesc = {}; RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(PipelineDesc.GraphicsPipeline.RasterizerDesc, D3D11RSDesc); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRasterizerState( &D3D11RSDesc, &m_pd3d11RasterizerState ), - "Failed to create D3D11 rasterizer state" ); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateRasterizerState(&D3D11RSDesc, &m_pd3d11RasterizerState), + "Failed to create D3D11 rasterizer state"); D3D11_DEPTH_STENCIL_DESC D3D11DSSDesc = {}; DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(PipelineDesc.GraphicsPipeline.DepthStencilDesc, D3D11DSSDesc); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilState( &D3D11DSSDesc, &m_pd3d11DepthStencilState ), - "Failed to create D3D11 depth stencil state" ); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateDepthStencilState(&D3D11DSSDesc, &m_pd3d11DepthStencilState), + "Failed to create D3D11 depth stencil state"); // Create input layout const auto& InputLayout = m_Desc.GraphicsPipeline.InputLayout; - if (InputLayout.NumElements > 0) + if (InputLayout.NumElements > 0) { - std::vector > d311InputElements(STD_ALLOCATOR_RAW_MEM(D3D11_INPUT_ELEMENT_DESC, GetRawAllocator(), "Allocator for vector") ); + std::vector> d311InputElements(STD_ALLOCATOR_RAW_MEM(D3D11_INPUT_ELEMENT_DESC, GetRawAllocator(), "Allocator for vector")); LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(InputLayout, d311InputElements); ID3DBlob* pVSByteCode = m_pVS.RawPtr()->GetBytecode(); - if( !pVSByteCode ) - LOG_ERROR_AND_THROW( "Vertex Shader byte code does not exist" ); + if (!pVSByteCode) + LOG_ERROR_AND_THROW("Vertex Shader byte code does not exist"); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateInputLayout(d311InputElements.data(), static_cast(d311InputElements.size()), pVSByteCode->GetBufferPointer(), pVSByteCode->GetBufferSize(), &m_pd3d11InputLayout ), - "Failed to create the Direct3D11 input layout"); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateInputLayout(d311InputElements.data(), static_cast(d311InputElements.size()), pVSByteCode->GetBufferPointer(), pVSByteCode->GetBufferSize(), &m_pd3d11InputLayout), + "Failed to create the Direct3D11 input layout"); } } m_pStaticResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumShaders); - m_pStaticResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumShaders); + m_pStaticResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumShaders); const auto& ResourceLayout = PipelineDesc.ResourceLayout; @@ -135,19 +139,20 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun } #endif - decltype(m_StaticSamplers) StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector")); + decltype(m_StaticSamplers) StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector")); std::array ShaderResLayoutDataSizes = {}; std::array ShaderResCacheDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { - auto* pShader = GetShader(s); + auto* pShader = GetShader(s); const auto& ShaderResources = *pShader->GetD3D11Resources(); - new (m_pStaticResourceCaches+s) ShaderResourceCacheD3D11; + new (m_pStaticResourceCaches + s) ShaderResourceCacheD3D11; // Do not initialize the cache as this will be performed by the resource layout // Shader resource layout will only contain dynamic and mutable variables const SHADER_RESOURCE_VARIABLE_TYPE StaticVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; + // clang-format off new (m_pStaticResourceLayouts + s) ShaderResourceLayoutD3D11 { @@ -160,16 +165,17 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun GetRawAllocator(), GetRawAllocator() }; + // clang-format on // Initialize static samplers - for(Uint32 sam = 0; sam < ShaderResources.GetNumSamplers(); ++sam) + for (Uint32 sam = 0; sam < ShaderResources.GetNumSamplers(); ++sam) { - const auto& SamplerAttribs = ShaderResources.GetSampler(sam); + const auto& SamplerAttribs = ShaderResources.GetSampler(sam); constexpr bool LogStaticSamplerArrayError = true; - auto SrcStaticSamplerInd = ShaderResources.FindStaticSampler(SamplerAttribs, ResourceLayout, LogStaticSamplerArrayError); + auto SrcStaticSamplerInd = ShaderResources.FindStaticSampler(SamplerAttribs, ResourceLayout, LogStaticSamplerArrayError); if (SrcStaticSamplerInd >= 0) { - const auto& SrcStaticSamplerInfo = ResourceLayout.StaticSamplers[SrcStaticSamplerInd]; + const auto& SrcStaticSamplerInfo = ResourceLayout.StaticSamplers[SrcStaticSamplerInd]; RefCntAutoPtr pStaticSampler; pRenderDeviceD3D11->CreateSampler(SrcStaticSamplerInfo.Desc, &pStaticSampler); StaticSamplers.emplace_back(SamplerAttribs, std::move(pStaticSampler)); @@ -179,12 +185,12 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun if (PipelineDesc.SRBAllocationGranularity > 1) { - const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = { SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC }; - ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); - ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); + const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; + ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); + ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); } - - auto ShaderInd = GetShaderTypeIndex(pShader->GetDesc().ShaderType); + + auto ShaderInd = GetShaderTypeIndex(pShader->GetDesc().ShaderType); m_ResourceLayoutIndex[ShaderInd] = static_cast(s); } @@ -194,7 +200,7 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun } m_StaticSamplers.reserve(StaticSamplers.size()); - for(auto& Sam : StaticSamplers) + for (auto& Sam : StaticSamplers) m_StaticSamplers.emplace_back(std::move(Sam)); for (Uint32 s = 0; s < m_NumShaders; ++s) @@ -221,7 +227,7 @@ PipelineStateD3D11Impl::~PipelineStateD3D11Impl() GetRawAllocator().Free(m_pStaticResourceLayouts); } -IMPLEMENT_QUERY_INTERFACE( PipelineStateD3D11Impl, IID_PipelineStateD3D11, TPipelineStateBase ) +IMPLEMENT_QUERY_INTERFACE(PipelineStateD3D11Impl, IID_PipelineStateD3D11, TPipelineStateBase) ID3D11BlendState* PipelineStateD3D11Impl::GetD3D11BlendState() @@ -246,21 +252,21 @@ ID3D11InputLayout* PipelineStateD3D11Impl::GetD3D11InputLayout() void PipelineStateD3D11Impl::CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) { - auto* pRenderDeviceD3D11 = ValidatedCast( GetDevice() ); - auto &SRBAllocator = pRenderDeviceD3D11->GetSRBAllocator(); - auto pShaderResBinding = NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingD3D11Impl instance", ShaderResourceBindingD3D11Impl)(this, false); + auto* pRenderDeviceD3D11 = ValidatedCast(GetDevice()); + auto& SRBAllocator = pRenderDeviceD3D11->GetSRBAllocator(); + auto pShaderResBinding = NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingD3D11Impl instance", ShaderResourceBindingD3D11Impl)(this, false); if (InitStaticResources) pShaderResBinding->InitializeStaticResources(nullptr); pShaderResBinding->QueryInterface(IID_ShaderResourceBinding, reinterpret_cast(static_cast(ppShaderResourceBinding))); } -bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState* pPSO)const +bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState* pPSO) const { VERIFY_EXPR(pPSO != nullptr); if (pPSO == this) return true; - + const PipelineStateD3D11Impl* pPSOD3D11 = ValidatedCast(pPSO); if (m_ShaderResourceLayoutHash != pPSOD3D11->m_ShaderResourceLayoutHash) return false; @@ -279,48 +285,48 @@ bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState* pPSO)const if (!Res0.IsCompatibleWith(Res1)) return false; } - + return true; } ID3D11VertexShader* PipelineStateD3D11Impl::GetD3D11VertexShader() { - if(!m_pVS)return nullptr; + if (!m_pVS) return nullptr; auto* pVSD3D11 = m_pVS.RawPtr(); return static_cast(pVSD3D11->GetD3D11Shader()); } ID3D11PixelShader* PipelineStateD3D11Impl::GetD3D11PixelShader() { - if(!m_pPS)return nullptr; + if (!m_pPS) return nullptr; auto* pPSD3D11 = m_pPS.RawPtr(); return static_cast(pPSD3D11->GetD3D11Shader()); } ID3D11GeometryShader* PipelineStateD3D11Impl::GetD3D11GeometryShader() { - if(!m_pGS)return nullptr; + if (!m_pGS) return nullptr; auto* pGSD3D11 = m_pGS.RawPtr(); return static_cast(pGSD3D11->GetD3D11Shader()); } ID3D11DomainShader* PipelineStateD3D11Impl::GetD3D11DomainShader() { - if(!m_pDS)return nullptr; + if (!m_pDS) return nullptr; auto* pDSD3D11 = m_pDS.RawPtr(); return static_cast(pDSD3D11->GetD3D11Shader()); } ID3D11HullShader* PipelineStateD3D11Impl::GetD3D11HullShader() { - if(!m_pHS)return nullptr; + if (!m_pHS) return nullptr; auto* pHSD3D11 = m_pHS.RawPtr(); return static_cast(pHSD3D11->GetD3D11Shader()); } ID3D11ComputeShader* PipelineStateD3D11Impl::GetD3D11ComputeShader() { - if(!m_pCS)return nullptr; + if (!m_pCS) return nullptr; auto* pCSD3D11 = m_pCS.RawPtr(); return static_cast(pCSD3D11->GetD3D11Shader()); } @@ -328,10 +334,10 @@ ID3D11ComputeShader* PipelineStateD3D11Impl::GetD3D11ComputeShader() void PipelineStateD3D11Impl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) { - for (Uint32 s=0; s < m_NumShaders; ++s) + for (Uint32 s = 0; s < m_NumShaders; ++s) { auto& StaticResLayout = m_pStaticResourceLayouts[s]; - if ( (ShaderFlags & StaticResLayout.GetShaderType()) != 0 ) + if ((ShaderFlags & StaticResLayout.GetShaderType()) != 0) StaticResLayout.BindResources(pResourceMapping, Flags, m_pStaticResourceCaches[s]); } } @@ -363,19 +369,19 @@ IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticVariableByIndex(SHADER return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Index); } -void PipelineStateD3D11Impl::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const +void PipelineStateD3D11Impl::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd) const { auto NumCachedSamplers = ResourceCache.GetSamplerCount(); - for (Uint32 s = m_StaticSamplerOffsets[ShaderInd]; s < m_StaticSamplerOffsets[ShaderInd+1]; ++s) + for (Uint32 s = m_StaticSamplerOffsets[ShaderInd]; s < m_StaticSamplerOffsets[ShaderInd + 1]; ++s) { - auto& SamplerInfo = m_StaticSamplers[s]; - const auto& SamAttribs = SamplerInfo.Attribs; - auto* pSamplerD3D11Impl = SamplerInfo.pSampler.RawPtr(); + auto& SamplerInfo = m_StaticSamplers[s]; + const auto& SamAttribs = SamplerInfo.Attribs; + auto* pSamplerD3D11Impl = SamplerInfo.pSampler.RawPtr(); // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache - auto EndBindPoint = std::min( static_cast(SamAttribs.BindPoint) + SamAttribs.BindCount, NumCachedSamplers); - for (Uint32 BindPoint = SamAttribs.BindPoint; BindPoint < EndBindPoint; ++BindPoint ) + auto EndBindPoint = std::min(static_cast(SamAttribs.BindPoint) + SamAttribs.BindCount, NumCachedSamplers); + for (Uint32 BindPoint = SamAttribs.BindPoint; BindPoint < EndBindPoint; ++BindPoint) ResourceCache.SetSampler(BindPoint, pSamplerD3D11Impl); } } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp index c6868207..26ff378b 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp @@ -40,12 +40,13 @@ namespace Diligent { -RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRefCounters, - IMemoryAllocator& RawMemAllocator, - IEngineFactory* pEngineFactory, - const EngineD3D11CreateInfo& EngineAttribs, - ID3D11Device* pd3d11Device, - Uint32 NumDeferredContexts) : +RenderDeviceD3D11Impl ::RenderDeviceD3D11Impl(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + IEngineFactory* pEngineFactory, + const EngineD3D11CreateInfo& EngineAttribs, + ID3D11Device* pd3d11Device, + Uint32 NumDeferredContexts) : + // clang-format off TRenderDeviceBase { pRefCounters, @@ -67,22 +68,23 @@ RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRef }, m_EngineAttribs{EngineAttribs}, m_pd3d11Device {pd3d11Device } +// clang-format on { m_DeviceCaps.DevType = DeviceType::D3D11; - auto FeatureLevel = m_pd3d11Device->GetFeatureLevel(); + auto FeatureLevel = m_pd3d11Device->GetFeatureLevel(); switch (FeatureLevel) { case D3D_FEATURE_LEVEL_11_0: case D3D_FEATURE_LEVEL_11_1: m_DeviceCaps.MajorVersion = 11; m_DeviceCaps.MinorVersion = FeatureLevel == D3D_FEATURE_LEVEL_11_1 ? 1 : 0; - break; - + break; + case D3D_FEATURE_LEVEL_10_0: case D3D_FEATURE_LEVEL_10_1: m_DeviceCaps.MajorVersion = 10; m_DeviceCaps.MinorVersion = FeatureLevel == D3D_FEATURE_LEVEL_10_1 ? 1 : 0; - break; + break; default: UNEXPECTED("Unexpected D3D feature level"); @@ -96,23 +98,24 @@ RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRef m_DeviceCaps.bBindlessSupported = False; } -void RenderDeviceD3D11Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) +void RenderDeviceD3D11Impl::TestTextureFormat(TEXTURE_FORMAT TexFormat) { - auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat]; - VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); + auto& TexFormatInfo = m_TextureFormatsInfo[TexFormat]; + VERIFY(TexFormatInfo.Supported, "Texture format is not supported"); auto DXGIFormat = TexFormatToDXGI_Format(TexFormat); - + UINT FormatSupport = 0; - auto hr = m_pd3d11Device->CheckFormatSupport(DXGIFormat, &FormatSupport); + auto hr = m_pd3d11Device->CheckFormatSupport(DXGIFormat, &FormatSupport); if (FAILED(hr)) { LOG_ERROR_MESSAGE("CheckFormatSupport() failed for format ", DXGIFormat); return; } - TexFormatInfo.Filterable = ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0) || - ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON) != 0); + TexFormatInfo.Filterable = + ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) != 0) || + ((FormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON) != 0); TexFormatInfo.ColorRenderable = (FormatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) != 0; TexFormatInfo.DepthRenderable = (FormatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) != 0; TexFormatInfo.Tex1DFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE1D) != 0; @@ -121,57 +124,51 @@ void RenderDeviceD3D11Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) TexFormatInfo.TexCubeFmt = (FormatSupport & D3D11_FORMAT_SUPPORT_TEXTURECUBE) != 0; TexFormatInfo.SampleCounts = 0x0; - for(Uint32 SampleCount = 1; SampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; SampleCount *= 2) + for (Uint32 SampleCount = 1; SampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT; SampleCount *= 2) { UINT QualityLevels = 0; - hr = m_pd3d11Device->CheckMultisampleQualityLevels(DXGIFormat, SampleCount, &QualityLevels); - if(SUCCEEDED(hr) && QualityLevels > 0) + hr = m_pd3d11Device->CheckMultisampleQualityLevels(DXGIFormat, SampleCount, &QualityLevels); + if (SUCCEEDED(hr) && QualityLevels > 0) TexFormatInfo.SampleCounts |= SampleCount; } } -IMPLEMENT_QUERY_INTERFACE( RenderDeviceD3D11Impl, IID_RenderDeviceD3D11, TRenderDeviceBase ) +IMPLEMENT_QUERY_INTERFACE(RenderDeviceD3D11Impl, IID_RenderDeviceD3D11, TRenderDeviceBase) -void RenderDeviceD3D11Impl :: CreateBufferFromD3DResource(ID3D11Buffer* pd3d11Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) +void RenderDeviceD3D11Impl ::CreateBufferFromD3DResource(ID3D11Buffer* pd3d11Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) { - CreateDeviceObject("buffer", BuffDesc, ppBuffer, - [&]() - { - BufferD3D11Impl* pBufferD3D11( NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D11Impl instance", BufferD3D11Impl) - (m_BuffViewObjAllocator, this, BuffDesc, InitialState, pd3d11Buffer ) ); - pBufferD3D11->QueryInterface( IID_Buffer, reinterpret_cast(ppBuffer) ); - pBufferD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pBufferD3D11 ); - } - ); + CreateDeviceObject("buffer", BuffDesc, ppBuffer, + [&]() // clang-format off + { // clang-format on + BufferD3D11Impl* pBufferD3D11(NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D11Impl instance", BufferD3D11Impl)(m_BuffViewObjAllocator, this, BuffDesc, InitialState, pd3d11Buffer)); + pBufferD3D11->QueryInterface(IID_Buffer, reinterpret_cast(ppBuffer)); + pBufferD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pBufferD3D11); + }); } -void RenderDeviceD3D11Impl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer) +void RenderDeviceD3D11Impl ::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer) { - CreateDeviceObject("buffer", BuffDesc, ppBuffer, - [&]() - { - BufferD3D11Impl* pBufferD3D11( NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D11Impl instance", BufferD3D11Impl) - (m_BuffViewObjAllocator, this, BuffDesc, pBuffData ) ); - pBufferD3D11->QueryInterface( IID_Buffer, reinterpret_cast(ppBuffer) ); - pBufferD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pBufferD3D11 ); - } - ); + CreateDeviceObject("buffer", BuffDesc, ppBuffer, + [&]() // clang-format off + { // clang-format on + BufferD3D11Impl* pBufferD3D11(NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D11Impl instance", BufferD3D11Impl)(m_BuffViewObjAllocator, this, BuffDesc, pBuffData)); + pBufferD3D11->QueryInterface(IID_Buffer, reinterpret_cast(ppBuffer)); + pBufferD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pBufferD3D11); + }); } -void RenderDeviceD3D11Impl :: CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader) +void RenderDeviceD3D11Impl ::CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader) { - CreateDeviceObject( "shader", ShaderCI.Desc, ppShader, - [&]() - { - ShaderD3D11Impl* pShaderD3D11( NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D11Impl instance", ShaderD3D11Impl) - (this, ShaderCI) ); - pShaderD3D11->QueryInterface( IID_Shader, reinterpret_cast(ppShader) ); + CreateDeviceObject("shader", ShaderCI.Desc, ppShader, + [&]() // clang-format off + { // clang-format on + ShaderD3D11Impl* pShaderD3D11(NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D11Impl instance", ShaderD3D11Impl)(this, ShaderCI)); + pShaderD3D11->QueryInterface(IID_Shader, reinterpret_cast(ppShader)); - OnCreateDeviceObject( pShaderD3D11 ); - } - ); + OnCreateDeviceObject(pShaderD3D11); + }); } void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture1D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) @@ -181,16 +178,14 @@ void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture1D* pd3d11 TextureDesc TexDesc; TexDesc.Name = "Texture1D from native d3d11 texture"; - CreateDeviceObject( "texture", TexDesc, ppTexture, - [&]() - { - TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_D3D11 instance", Texture1D_D3D11) - (m_TexViewObjAllocator, this, InitialState, pd3d11Texture); - pTextureD3D11->QueryInterface( IID_Texture, reinterpret_cast(ppTexture) ); - pTextureD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pTextureD3D11 ); - } - ); + CreateDeviceObject("texture", TexDesc, ppTexture, + [&]() // clang-format off + { // clang-format on + TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_D3D11 instance", Texture1D_D3D11)(m_TexViewObjAllocator, this, InitialState, pd3d11Texture); + pTextureD3D11->QueryInterface(IID_Texture, reinterpret_cast(ppTexture)); + pTextureD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pTextureD3D11); + }); } void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture2D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) @@ -200,16 +195,14 @@ void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture2D* pd3d11 TextureDesc TexDesc; TexDesc.Name = "Texture2D from native d3d11 texture"; - CreateDeviceObject( "texture", TexDesc, ppTexture, - [&]() - { - TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_D3D11 instance", Texture2D_D3D11) - (m_TexViewObjAllocator, this, InitialState, pd3d11Texture); - pTextureD3D11->QueryInterface( IID_Texture, reinterpret_cast(ppTexture) ); - pTextureD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pTextureD3D11 ); - } - ); + CreateDeviceObject("texture", TexDesc, ppTexture, + [&]() // clang-format off + { // clang-format on + TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_D3D11 instance", Texture2D_D3D11)(m_TexViewObjAllocator, this, InitialState, pd3d11Texture); + pTextureD3D11->QueryInterface(IID_Texture, reinterpret_cast(ppTexture)); + pTextureD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pTextureD3D11); + }); } void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture3D* pd3d11Texture, RESOURCE_STATE InitialState, ITexture** ppTexture) @@ -219,97 +212,85 @@ void RenderDeviceD3D11Impl::CreateTextureFromD3DResource(ID3D11Texture3D* pd3d11 TextureDesc TexDesc; TexDesc.Name = "Texture3D from native d3d11 texture"; - CreateDeviceObject( "texture", TexDesc, ppTexture, - [&]() - { - TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_D3D11 instance", Texture3D_D3D11) - (m_TexViewObjAllocator, this, InitialState, pd3d11Texture); - pTextureD3D11->QueryInterface( IID_Texture, reinterpret_cast(ppTexture) ); - pTextureD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pTextureD3D11 ); - } - ); + CreateDeviceObject("texture", TexDesc, ppTexture, + [&]() // clang-format off + { // clang-format on + TextureBaseD3D11* pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_D3D11 instance", Texture3D_D3D11)(m_TexViewObjAllocator, this, InitialState, pd3d11Texture); + pTextureD3D11->QueryInterface(IID_Texture, reinterpret_cast(ppTexture)); + pTextureD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pTextureD3D11); + }); } -void RenderDeviceD3D11Impl :: CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture) +void RenderDeviceD3D11Impl ::CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture) { - CreateDeviceObject( "texture", TexDesc, ppTexture, - [&]() - { - TextureBaseD3D11* pTextureD3D11 = nullptr; - switch( TexDesc.Type ) - { - case RESOURCE_DIM_TEX_1D: - case RESOURCE_DIM_TEX_1D_ARRAY: - pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_D3D11 instance", Texture1D_D3D11) - (m_TexViewObjAllocator, this, TexDesc, pData ); - break; - - case RESOURCE_DIM_TEX_2D: - case RESOURCE_DIM_TEX_2D_ARRAY: - case RESOURCE_DIM_TEX_CUBE: - case RESOURCE_DIM_TEX_CUBE_ARRAY: - pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_D3D11 instance", Texture2D_D3D11) - (m_TexViewObjAllocator, this, TexDesc, pData ); - break; - - case RESOURCE_DIM_TEX_3D: - pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_D3D11 instance", Texture3D_D3D11) - (m_TexViewObjAllocator, this, TexDesc, pData ); - break; - - default: LOG_ERROR_AND_THROW( "Unknown texture type. (Did you forget to initialize the Type member of TextureDesc structure?)" ); - } - pTextureD3D11->QueryInterface( IID_Texture, reinterpret_cast(ppTexture) ); - pTextureD3D11->CreateDefaultViews(); - OnCreateDeviceObject( pTextureD3D11 ); - } - ); + CreateDeviceObject("texture", TexDesc, ppTexture, + [&]() // clang-format off + { // clang-format on + TextureBaseD3D11* pTextureD3D11 = nullptr; + switch (TexDesc.Type) + { + case RESOURCE_DIM_TEX_1D: + case RESOURCE_DIM_TEX_1D_ARRAY: + pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture1D_D3D11 instance", Texture1D_D3D11)(m_TexViewObjAllocator, this, TexDesc, pData); + break; + + case RESOURCE_DIM_TEX_2D: + case RESOURCE_DIM_TEX_2D_ARRAY: + case RESOURCE_DIM_TEX_CUBE: + case RESOURCE_DIM_TEX_CUBE_ARRAY: + pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture2D_D3D11 instance", Texture2D_D3D11)(m_TexViewObjAllocator, this, TexDesc, pData); + break; + + case RESOURCE_DIM_TEX_3D: + pTextureD3D11 = NEW_RC_OBJ(m_TexObjAllocator, "Texture3D_D3D11 instance", Texture3D_D3D11)(m_TexViewObjAllocator, this, TexDesc, pData); + break; + + default: LOG_ERROR_AND_THROW("Unknown texture type. (Did you forget to initialize the Type member of TextureDesc structure?)"); + } + pTextureD3D11->QueryInterface(IID_Texture, reinterpret_cast(ppTexture)); + pTextureD3D11->CreateDefaultViews(); + OnCreateDeviceObject(pTextureD3D11); + }); } -void RenderDeviceD3D11Impl :: CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) +void RenderDeviceD3D11Impl ::CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) { - CreateDeviceObject( "sampler", SamplerDesc, ppSampler, - [&]() - { - m_SamplersRegistry.Find( SamplerDesc, reinterpret_cast(ppSampler) ); - if(* ppSampler == nullptr ) - { - SamplerD3D11Impl* pSamplerD3D11( NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerD3D11Impl instance", SamplerD3D11Impl) - (this, SamplerDesc ) ); - pSamplerD3D11->QueryInterface( IID_Sampler, reinterpret_cast(ppSampler) ); - OnCreateDeviceObject( pSamplerD3D11 ); - m_SamplersRegistry.Add( SamplerDesc,* ppSampler ); - } - } - ); + CreateDeviceObject("sampler", SamplerDesc, ppSampler, + [&]() // clang-format off + { // clang-format on + m_SamplersRegistry.Find(SamplerDesc, reinterpret_cast(ppSampler)); + if (*ppSampler == nullptr) + { + SamplerD3D11Impl* pSamplerD3D11(NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerD3D11Impl instance", SamplerD3D11Impl)(this, SamplerDesc)); + pSamplerD3D11->QueryInterface(IID_Sampler, reinterpret_cast(ppSampler)); + OnCreateDeviceObject(pSamplerD3D11); + m_SamplersRegistry.Add(SamplerDesc, *ppSampler); + } + }); } void RenderDeviceD3D11Impl::CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState) { - CreateDeviceObject( "Pipeline state", PipelineDesc, ppPipelineState, - [&]() - { - PipelineStateD3D11Impl* pPipelineStateD3D11( NEW_RC_OBJ(m_PSOAllocator, "PipelineStateD3D11Impl instance", PipelineStateD3D11Impl) - (this, PipelineDesc ) ); - pPipelineStateD3D11->QueryInterface( IID_PipelineState, reinterpret_cast(ppPipelineState) ); - OnCreateDeviceObject( pPipelineStateD3D11 ); - } - ); + CreateDeviceObject("Pipeline state", PipelineDesc, ppPipelineState, + [&]() // clang-format off + { // clang-format on + PipelineStateD3D11Impl* pPipelineStateD3D11(NEW_RC_OBJ(m_PSOAllocator, "PipelineStateD3D11Impl instance", PipelineStateD3D11Impl)(this, PipelineDesc)); + pPipelineStateD3D11->QueryInterface(IID_PipelineState, reinterpret_cast(ppPipelineState)); + OnCreateDeviceObject(pPipelineStateD3D11); + }); } void RenderDeviceD3D11Impl::CreateFence(const FenceDesc& Desc, IFence** ppFence) { - CreateDeviceObject( "Fence", Desc, ppFence, - [&]() - { - FenceD3D11Impl* pFenceD3D11( NEW_RC_OBJ(m_FenceAllocator, "FenceD3D11Impl instance", FenceD3D11Impl) - (this, Desc) ); - pFenceD3D11->QueryInterface( IID_Fence, reinterpret_cast(ppFence) ); - OnCreateDeviceObject( pFenceD3D11 ); - } - ); + CreateDeviceObject("Fence", Desc, ppFence, + [&]() // clang-format off + { // clang-format on + FenceD3D11Impl* pFenceD3D11(NEW_RC_OBJ(m_FenceAllocator, "FenceD3D11Impl instance", FenceD3D11Impl)(this, Desc)); + pFenceD3D11->QueryInterface(IID_Fence, reinterpret_cast(ppFence)); + OnCreateDeviceObject(pFenceD3D11); + }); } void RenderDeviceD3D11Impl::IdleGPU() @@ -320,4 +301,4 @@ void RenderDeviceD3D11Impl::IdleGPU() } } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp index ee727278..312acd38 100644 --- a/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp @@ -29,39 +29,41 @@ namespace Diligent { -SamplerD3D11Impl::SamplerD3D11Impl(IReferenceCounters* pRefCounters, +SamplerD3D11Impl::SamplerD3D11Impl(IReferenceCounters* pRefCounters, RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const SamplerDesc& SamplerDesc) : + const SamplerDesc& SamplerDesc) : + // clang-format off TSamplerBase { pRefCounters, pRenderDeviceD3D11, SamplerDesc } +// clang-format on { - auto *pd3d11Device = pRenderDeviceD3D11->GetD3D11Device(); - D3D11_SAMPLER_DESC D3D11SamplerDesc = - { - FilterTypeToD3D11Filter(SamplerDesc.MinFilter, SamplerDesc.MagFilter, SamplerDesc.MipFilter), - TexAddressModeToD3D11AddressMode(SamplerDesc.AddressU), - TexAddressModeToD3D11AddressMode(SamplerDesc.AddressV), - TexAddressModeToD3D11AddressMode(SamplerDesc.AddressW), - SamplerDesc.MipLODBias, - SamplerDesc.MaxAnisotropy, - ComparisonFuncToD3D11ComparisonFunc(SamplerDesc.ComparisonFunc), - {SamplerDesc.BorderColor[0], SamplerDesc.BorderColor[1], SamplerDesc.BorderColor[2], SamplerDesc.BorderColor[3]}, - SamplerDesc.MinLOD, - SamplerDesc.MaxLOD - }; - CHECK_D3D_RESULT_THROW( pd3d11Device->CreateSamplerState(&D3D11SamplerDesc, &m_pd3dSampler), - "Failed to create the Direct3D11 sampler"); + auto* pd3d11Device = pRenderDeviceD3D11->GetD3D11Device(); + D3D11_SAMPLER_DESC D3D11SamplerDesc = + { + FilterTypeToD3D11Filter(SamplerDesc.MinFilter, SamplerDesc.MagFilter, SamplerDesc.MipFilter), + TexAddressModeToD3D11AddressMode(SamplerDesc.AddressU), + TexAddressModeToD3D11AddressMode(SamplerDesc.AddressV), + TexAddressModeToD3D11AddressMode(SamplerDesc.AddressW), + SamplerDesc.MipLODBias, + SamplerDesc.MaxAnisotropy, + ComparisonFuncToD3D11ComparisonFunc(SamplerDesc.ComparisonFunc), + {SamplerDesc.BorderColor[0], SamplerDesc.BorderColor[1], SamplerDesc.BorderColor[2], SamplerDesc.BorderColor[3]}, + SamplerDesc.MinLOD, + SamplerDesc.MaxLOD // clang-format off + }; // clang-format on + + CHECK_D3D_RESULT_THROW(pd3d11Device->CreateSamplerState(&D3D11SamplerDesc, &m_pd3dSampler), + "Failed to create the Direct3D11 sampler"); } SamplerD3D11Impl::~SamplerD3D11Impl() { - } -IMPLEMENT_QUERY_INTERFACE( SamplerD3D11Impl, IID_SamplerD3D11, TSamplerBase ) +IMPLEMENT_QUERY_INTERFACE(SamplerD3D11Impl, IID_SamplerD3D11, TSamplerBase) -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index 18d8b8bc..ae70f26d 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -36,8 +36,9 @@ static const std::string HLSLVersionToShaderModelString(const ShaderCreateInfo:: if (Version.Major > MaxMajorRevision || Version.Major == MaxMajorRevision && Version.Minor > MaxMinorRevision) { ModelStr = std::to_string(Uint32{MaxMajorRevision}) + '_' + std::to_string(Uint32{MaxMinorRevision}); - LOG_ERROR_MESSAGE("Shader model ", Uint32{Version.Major}, "_", Uint32{Version.Minor}, " is not supported by this device. " - "Maximum supported model: ", ModelStr, ". Attempting to use ", ModelStr, '.'); + LOG_ERROR_MESSAGE("Shader model ", Uint32{Version.Major}, "_", Uint32{Version.Minor}, + " is not supported by this device. Maximum supported model: ", + ModelStr, ". Attempting to use ", ModelStr, '.'); } else { @@ -49,27 +50,30 @@ static const std::string HLSLVersionToShaderModelString(const ShaderCreateInfo:: static const std::string GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const ShaderCreateInfo::ShaderVersion& HLSLVersion) { auto d3dDeviceFeatureLevel = pd3d11Device->GetFeatureLevel(); - switch(d3dDeviceFeatureLevel) + switch (d3dDeviceFeatureLevel) { // Direct3D11 only supports shader model 5.0 even if the device feature level is // above 11.0 (for example, 11.1 or 12.0). // https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-devices-downlevel-intro#overview-for-each-feature-level -#if defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT >=_WIN32_WINNT_WIN10) +#if defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT >= _WIN32_WINNT_WIN10) case D3D_FEATURE_LEVEL_12_1: case D3D_FEATURE_LEVEL_12_0: #endif case D3D_FEATURE_LEVEL_11_1: case D3D_FEATURE_LEVEL_11_0: return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"5_0"} : HLSLVersionToShaderModelString(HLSLVersion, 5, 0); + std::string{"5_0"} : + HLSLVersionToShaderModelString(HLSLVersion, 5, 0); case D3D_FEATURE_LEVEL_10_1: - return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"4_1"} : HLSLVersionToShaderModelString(HLSLVersion, 4, 1); + return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? + std::string{"4_1"} : + HLSLVersionToShaderModelString(HLSLVersion, 4, 1); case D3D_FEATURE_LEVEL_10_0: - return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"4_0"} : HLSLVersionToShaderModelString(HLSLVersion, 4, 0); + return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? + std::string{"4_0"} : + HLSLVersionToShaderModelString(HLSLVersion, 4, 0); default: UNEXPECTED("Unexpected D3D feature level ", static_cast(d3dDeviceFeatureLevel)); @@ -77,9 +81,10 @@ static const std::string GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const S } } -ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const ShaderCreateInfo& ShaderCI) : +ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const ShaderCreateInfo& ShaderCI) : + // clang-format off TShaderBase { pRefCounters, @@ -87,36 +92,37 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, ShaderCI.Desc }, ShaderD3DBase{ShaderCI, GetD3D11ShaderModel(pRenderDeviceD3D11->GetD3D11Device(), ShaderCI.HLSLVersion).c_str()} +// clang-format on { - auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); switch (ShaderCI.Desc.ShaderType) { -#define CREATE_SHADER(SHADER_NAME, ShaderName)\ - case SHADER_TYPE_##SHADER_NAME: \ - { \ - ID3D11##ShaderName##Shader *pShader; \ - HRESULT hr = pDeviceD3D11->Create##ShaderName##Shader( m_pShaderByteCode->GetBufferPointer(), m_pShaderByteCode->GetBufferSize(), NULL, &pShader ); \ - CHECK_D3D_RESULT_THROW( hr, "Failed to create D3D11 shader" ); \ - if( SUCCEEDED(hr) ) \ - { \ - pShader->QueryInterface( __uuidof(ID3D11DeviceChild), reinterpret_cast( static_cast(&m_pShader) ) ); \ - pShader->Release(); \ - } \ - break; \ - } - - CREATE_SHADER(VERTEX, Vertex) - CREATE_SHADER(PIXEL, Pixel) +#define CREATE_SHADER(SHADER_NAME, ShaderName) \ + case SHADER_TYPE_##SHADER_NAME: \ + { \ + ID3D11##ShaderName##Shader* pShader; \ + HRESULT hr = pDeviceD3D11->Create##ShaderName##Shader(m_pShaderByteCode->GetBufferPointer(), m_pShaderByteCode->GetBufferSize(), NULL, &pShader); \ + CHECK_D3D_RESULT_THROW(hr, "Failed to create D3D11 shader"); \ + if (SUCCEEDED(hr)) \ + { \ + pShader->QueryInterface(__uuidof(ID3D11DeviceChild), reinterpret_cast(static_cast(&m_pShader))); \ + pShader->Release(); \ + } \ + break; \ + } + + CREATE_SHADER(VERTEX, Vertex) + CREATE_SHADER(PIXEL, Pixel) CREATE_SHADER(GEOMETRY, Geometry) - CREATE_SHADER(DOMAIN, Domain) - CREATE_SHADER(HULL, Hull) - CREATE_SHADER(COMPUTE, Compute) + CREATE_SHADER(DOMAIN, Domain) + CREATE_SHADER(HULL, Hull) + CREATE_SHADER(COMPUTE, Compute) - default: UNEXPECTED( "Unknown shader type" ); + default: UNEXPECTED("Unknown shader type"); } - - if(!m_pShader) + + if (!m_pShader) LOG_ERROR_AND_THROW("Failed to create the shader from the byte code"); if (*m_Desc.Name != 0) @@ -126,13 +132,13 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, } // Load shader resources - auto& Allocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D11, 1); + auto& Allocator = GetRawAllocator(); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D11, 1); auto* pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr); m_pShaderResources.reset(pResources, STDDeleterRawMem(Allocator)); // Byte code is only required for the vertex shader to create input layout - if( ShaderCI.Desc.ShaderType != SHADER_TYPE_VERTEX ) + if (ShaderCI.Desc.ShaderType != SHADER_TYPE_VERTEX) m_pShaderByteCode.Release(); } @@ -151,8 +157,8 @@ void ShaderD3D11Impl::QueryInterface(const INTERFACE_ID& IID, IObject** ppInterf } else { - TShaderBase::QueryInterface( IID, ppInterface ); + TShaderBase::QueryInterface(IID, ppInterface); } } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index a29b4864..21864460 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -31,9 +31,10 @@ namespace Diligent { -ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounters* pRefCounters, - PipelineStateD3D11Impl* pPSO, - bool IsInternal) : +ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounters* pRefCounters, + PipelineStateD3D11Impl* pPSO, + bool IsInternal) : + // clang-format off TBase { pRefCounters, @@ -41,33 +42,37 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte IsInternal }, m_bIsStaticResourcesBound{false} +// clang-format on { m_NumActiveShaders = static_cast(pPSO->GetNumShaders()); + // clang-format off m_pResourceLayouts = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceLayoutD3D11", ShaderResourceLayoutD3D11, m_NumActiveShaders); m_pBoundResourceCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", ShaderResourceCacheD3D11, m_NumActiveShaders); - + // clang-format on + const auto& PSODesc = pPSO->GetDesc(); // Reserve memory for resource layouts for (Uint8 s = 0; s < m_NumActiveShaders; ++s) { auto* pShaderD3D11 = pPSO->GetShader(s); - auto ShaderInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); + auto ShaderInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); - auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator(); - auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s); + auto& SRBMemAllocator = pPSO->GetSRBMemoryAllocator(); + auto& ResCacheDataAllocator = SRBMemAllocator.GetResourceCacheDataAllocator(s); auto& ResLayoutDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s); - + // Initialize resource cache to have enough space to contain all shader resources, including static ones // Static resources are copied before resources are committed const auto& Resources = *pShaderD3D11->GetD3D11Resources(); - new (m_pBoundResourceCaches+s) ShaderResourceCacheD3D11; + new (m_pBoundResourceCaches + s) ShaderResourceCacheD3D11; m_pBoundResourceCaches[s].Initialize(Resources, ResCacheDataAllocator); // Shader resource layout will only contain dynamic and mutable variables // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; + // clang-format off new (m_pResourceLayouts + s) ShaderResourceLayoutD3D11 { @@ -80,15 +85,16 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte ResCacheDataAllocator, ResLayoutDataAllocator }; + // clang-format on m_ResourceLayoutIndex[ShaderInd] = s; - m_ShaderTypeIndex[s] = static_cast(ShaderInd); + m_ShaderTypeIndex[s] = static_cast(ShaderInd); } } ShaderResourceBindingD3D11Impl::~ShaderResourceBindingD3D11Impl() { - auto *pPSOD3D11Impl = ValidatedCast(m_pPSO); + auto* pPSOD3D11Impl = ValidatedCast(m_pPSO); for (Uint32 s = 0; s < m_NumActiveShaders; ++s) { auto& Allocator = pPSOD3D11Impl->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(s); @@ -97,21 +103,21 @@ ShaderResourceBindingD3D11Impl::~ShaderResourceBindingD3D11Impl() } GetRawAllocator().Free(m_pBoundResourceCaches); - for(Int32 l = 0; l < m_NumActiveShaders; ++l) + for (Int32 l = 0; l < m_NumActiveShaders; ++l) { m_pResourceLayouts[l].~ShaderResourceLayoutD3D11(); } GetRawAllocator().Free(m_pResourceLayouts); } -IMPLEMENT_QUERY_INTERFACE( ShaderResourceBindingD3D11Impl, IID_ShaderResourceBindingD3D11, TBase ) +IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingD3D11Impl, IID_ShaderResourceBindingD3D11, TBase) void ShaderResourceBindingD3D11Impl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) { - for(Uint32 ResLayoutInd = 0; ResLayoutInd < m_NumActiveShaders; ++ResLayoutInd) + for (Uint32 ResLayoutInd = 0; ResLayoutInd < m_NumActiveShaders; ++ResLayoutInd) { auto& ResLayout = m_pResourceLayouts[ResLayoutInd]; - if(ShaderFlags & ResLayout.GetShaderType()) + if (ShaderFlags & ResLayout.GetShaderType()) { ResLayout.BindResources(pResMapping, Flags, m_pBoundResourceCaches[ResLayoutInd]); } @@ -135,29 +141,30 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt DEV_CHECK_ERR(pPipelineState->IsCompatibleWith(GetPipelineState()), "The pipeline state is not compatible with this SRB"); } - const auto* pPSOD3D11 = ValidatedCast(pPipelineState); - auto ppShaders = pPSOD3D11->GetShaders(); - auto NumShaders = pPSOD3D11->GetNumShaders(); + const auto* pPSOD3D11 = ValidatedCast(pPipelineState); + auto ppShaders = pPSOD3D11->GetShaders(); + auto NumShaders = pPSOD3D11->GetNumShaders(); VERIFY_EXPR(NumShaders == m_NumActiveShaders); for (Uint32 shader = 0; shader < NumShaders; ++shader) { const auto& StaticResLayout = pPSOD3D11->GetStaticResourceLayout(shader); - auto* pShaderD3D11 = ValidatedCast(ppShaders[shader]); + auto* pShaderD3D11 = ValidatedCast(ppShaders[shader]); #ifdef DEVELOPMENT if (!StaticResLayout.dvpVerifyBindings()) { - LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSOD3D11->GetDesc().Name, "' will not be successfully initialized " - "because not all static resource bindings in shader '", pShaderD3D11->GetDesc().Name, "' are valid. " - "Please make sure you bind all static resources to PSO before calling InitializeStaticResources() " + LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSOD3D11->GetDesc().Name, + "' will not be successfully initialized because not all static resource bindings in shader '", + pShaderD3D11->GetDesc().Name, + "' are valid. Please make sure you bind all static resources to PSO before calling InitializeStaticResources() " "directly or indirectly by passing InitStaticResources=true to CreateShaderResourceBinding() method."); } #endif #ifdef _DEBUG - auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); + auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType); auto ResourceLayoutInd = m_ResourceLayoutIndex[ShaderTypeInd]; - VERIFY_EXPR(ResourceLayoutInd == static_cast(shader) ); + VERIFY_EXPR(ResourceLayoutInd == static_cast(shader)); #endif StaticResLayout.CopyResources(m_pBoundResourceCaches[shader]); pPSOD3D11->SetStaticSamplers(m_pBoundResourceCaches[shader], shader); @@ -171,10 +178,11 @@ IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADE auto Ind = GetShaderTypeIndex(ShaderType); VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if( ResLayoutIndex < 0 ) + if (ResLayoutIndex < 0) { - LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); + LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", + GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", + m_pPSO->GetDesc().Name, "'"); return nullptr; } @@ -186,10 +194,11 @@ Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) auto Ind = GetShaderTypeIndex(ShaderType); VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if( ResLayoutIndex < 0 ) + if (ResLayoutIndex < 0) { - LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); + LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", + GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", + m_pPSO->GetDesc().Name, "'"); return 0; } @@ -201,14 +210,15 @@ IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByIndex(SHAD auto Ind = GetShaderTypeIndex(ShaderType); VERIFY_EXPR(Ind >= 0 && Ind < _countof(m_ResourceLayoutIndex)); auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; - if( ResLayoutIndex < 0 ) + if (ResLayoutIndex < 0) { - LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); + LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", + GetShaderTypeLiteralName(ShaderType), " is inactive in Pipeline State '", + m_pPSO->GetDesc().Name, "'"); return nullptr; } return m_pResourceLayouts[ResLayoutIndex].GetShaderVariable(Index); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp index 68092405..d960221a 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp @@ -32,272 +32,279 @@ namespace Diligent { - size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const ShaderResourcesD3D11& Resources) +size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const ShaderResourcesD3D11& Resources) +{ + // clang-format off + auto CBCount = Resources.GetMaxCBBindPoint() + 1; + auto SRVCount = Resources.GetMaxSRVBindPoint() + 1; + auto SamplerCount = Resources.GetMaxSamplerBindPoint()+ 1; + auto UAVCount = Resources.GetMaxUAVBindPoint() + 1; + auto MemSize = + (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * CBCount + + (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * SRVCount + + (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * SamplerCount + + (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount; + // clang-format on + return MemSize; +} + +void ShaderResourceCacheD3D11::Initialize(const ShaderResourcesD3D11& Resources, IMemoryAllocator& MemAllocator) +{ + // clang-format off + auto CBCount = Resources.GetMaxCBBindPoint() + 1; + auto SRVCount = Resources.GetMaxSRVBindPoint() + 1; + auto SamplerCount = Resources.GetMaxSamplerBindPoint()+ 1; + auto UAVCount = Resources.GetMaxUAVBindPoint() + 1; + // clang-format on + Initialize(CBCount, SRVCount, SamplerCount, UAVCount, MemAllocator); +} + +void ShaderResourceCacheD3D11::Initialize(Uint32 CBCount, Uint32 SRVCount, Uint32 SamplerCount, Uint32 UAVCount, IMemoryAllocator& MemAllocator) +{ + // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache/ + if (IsInitialized()) { - auto CBCount = Resources.GetMaxCBBindPoint() + 1; - auto SRVCount = Resources.GetMaxSRVBindPoint() + 1; - auto SamplerCount = Resources.GetMaxSamplerBindPoint()+ 1; - auto UAVCount = Resources.GetMaxUAVBindPoint() + 1; - auto MemSize = - (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * CBCount + - (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * SRVCount + - (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * SamplerCount + - (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount; - return MemSize; + LOG_ERROR_MESSAGE("Resource cache is already intialized"); + return; } - void ShaderResourceCacheD3D11::Initialize(const ShaderResourcesD3D11& Resources, IMemoryAllocator& MemAllocator) + // clang-format off + VERIFY(CBCount <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, "Constant buffer count ", CBCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT ); + VERIFY(SRVCount <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, "SRV count ", SRVCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT ); + VERIFY(SamplerCount <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, "Sampler count ", SamplerCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT ); + VERIFY(UAVCount <= D3D11_PS_CS_UAV_REGISTER_COUNT, "UAV count ", UAVCount, " exceeds D3D11 limit ", D3D11_PS_CS_UAV_REGISTER_COUNT ); + + // m_CBOffset = 0 + m_SRVOffset = static_cast(m_CBOffset + CBCount * (sizeof(CachedCB) + sizeof(ID3D11Buffer*))); + m_SamplerOffset = static_cast(m_SRVOffset + SRVCount * (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*))); + m_UAVOffset = static_cast(m_SamplerOffset + SamplerCount * (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*))); + m_MemoryEndOffset = static_cast(m_UAVOffset + UAVCount * (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*))); + + VERIFY_EXPR(GetCBCount() == static_cast(CBCount)); + VERIFY_EXPR(GetSRVCount() == static_cast(SRVCount)); + VERIFY_EXPR(GetSamplerCount() == static_cast(SamplerCount)); + VERIFY_EXPR(GetUAVCount() == static_cast(UAVCount)); + + VERIFY_EXPR(m_pResourceData == nullptr); + size_t BufferSize = m_MemoryEndOffset; + + VERIFY_EXPR( BufferSize == + (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * CBCount + + (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * SRVCount + + (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * SamplerCount + + (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount ); + // clang-format on + +#ifdef _DEBUG + m_pdbgMemoryAllocator = &MemAllocator; +#endif + if (BufferSize > 0) { - auto CBCount = Resources.GetMaxCBBindPoint() + 1; - auto SRVCount = Resources.GetMaxSRVBindPoint() + 1; - auto SamplerCount = Resources.GetMaxSamplerBindPoint()+ 1; - auto UAVCount = Resources.GetMaxUAVBindPoint() + 1; - Initialize(CBCount, SRVCount, SamplerCount, UAVCount, MemAllocator); + m_pResourceData = ALLOCATE(MemAllocator, "Shader resource cache data buffer", Uint8, BufferSize); + memset(m_pResourceData, 0, BufferSize); } - void ShaderResourceCacheD3D11::Initialize(Uint32 CBCount, Uint32 SRVCount, Uint32 SamplerCount, Uint32 UAVCount, IMemoryAllocator& MemAllocator) + // Explicitly construct all objects + if (CBCount != 0) { - // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache/ - if (IsInitialized()) - { - LOG_ERROR_MESSAGE("Resource cache is already intialized"); - return; - } - - VERIFY(CBCount <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, "Constant buffer count ", CBCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT ); - VERIFY(SRVCount <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, "SRV count ", SRVCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT ); - VERIFY(SamplerCount <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, "Sampler count ", SamplerCount, " exceeds D3D11 limit ", D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT ); - VERIFY(UAVCount <= D3D11_PS_CS_UAV_REGISTER_COUNT, "UAV count ", UAVCount, " exceeds D3D11 limit ", D3D11_PS_CS_UAV_REGISTER_COUNT ); - - // m_CBOffset = 0 - m_SRVOffset = static_cast(m_CBOffset + CBCount * (sizeof(CachedCB) + sizeof(ID3D11Buffer*))); - m_SamplerOffset = static_cast(m_SRVOffset + SRVCount * (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*))); - m_UAVOffset = static_cast(m_SamplerOffset + SamplerCount * (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*))); - m_MemoryEndOffset = static_cast(m_UAVOffset + UAVCount * (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*))); + CachedCB* CBs = nullptr; + ID3D11Buffer** d3d11CBs = nullptr; + GetCBArrays(CBs, d3d11CBs); + for (Uint32 cb = 0; cb < CBCount; ++cb) + new (CBs + cb) CachedCB; + } - VERIFY_EXPR(GetCBCount() == static_cast(CBCount)); - VERIFY_EXPR(GetSRVCount() == static_cast(SRVCount)); - VERIFY_EXPR(GetSamplerCount() == static_cast(SamplerCount)); - VERIFY_EXPR(GetUAVCount() == static_cast(UAVCount)); + if (SRVCount != 0) + { + CachedResource* SRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; + GetSRVArrays(SRVResources, d3d11SRVs); + for (Uint32 srv = 0; srv < SRVCount; ++srv) + new (SRVResources + srv) CachedResource; + } - VERIFY_EXPR(m_pResourceData == nullptr); - size_t BufferSize = m_MemoryEndOffset; + if (SamplerCount != 0) + { + CachedSampler* Samplers = nullptr; + ID3D11SamplerState** d3d11Samplers = nullptr; + GetSamplerArrays(Samplers, d3d11Samplers); + for (Uint32 sam = 0; sam < SamplerCount; ++sam) + new (Samplers + sam) CachedSampler; + } - VERIFY_EXPR( BufferSize == - (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * CBCount + - (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * SRVCount + - (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * SamplerCount + - (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount ); + if (UAVCount != 0) + { + CachedResource* UAVResources = nullptr; + ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + GetUAVArrays(UAVResources, d3d11UAVs); + for (Uint32 uav = 0; uav < UAVCount; ++uav) + new (UAVResources + uav) CachedResource; + } +} -#ifdef _DEBUG - m_pdbgMemoryAllocator = &MemAllocator; -#endif - if( BufferSize > 0 ) - { - m_pResourceData = ALLOCATE(MemAllocator, "Shader resource cache data buffer", Uint8, BufferSize); - memset(m_pResourceData, 0, BufferSize); - } +void ShaderResourceCacheD3D11::Destroy(IMemoryAllocator& MemAllocator) +{ + VERIFY(IsInitialized(), "Resource cache is not initialized"); + VERIFY(m_pdbgMemoryAllocator == &MemAllocator, "The allocator does not match the one used to create resources"); - // Explicitly construct all objects + if (IsInitialized()) + { + // Explicitly destory all objects + auto CBCount = GetCBCount(); if (CBCount != 0) { CachedCB* CBs = nullptr; ID3D11Buffer** d3d11CBs = nullptr; GetCBArrays(CBs, d3d11CBs); - for (Uint32 cb = 0; cb < CBCount; ++cb) - new(CBs+cb)CachedCB; + for (size_t cb = 0; cb < CBCount; ++cb) + CBs[cb].~CachedCB(); } + auto SRVCount = GetSRVCount(); if (SRVCount != 0) { - CachedResource* SRVResources = nullptr; - ID3D11ShaderResourceView** d3d11SRVs = nullptr; + CachedResource* SRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; GetSRVArrays(SRVResources, d3d11SRVs); - for (Uint32 srv = 0; srv < SRVCount; ++srv) - new(SRVResources+srv)CachedResource; + for (size_t srv = 0; srv < SRVCount; ++srv) + SRVResources[srv].~CachedResource(); } + auto SamplerCount = GetSamplerCount(); if (SamplerCount != 0) { CachedSampler* Samplers = nullptr; ID3D11SamplerState** d3d11Samplers = nullptr; - GetSamplerArrays(Samplers, d3d11Samplers); - for (Uint32 sam = 0; sam < SamplerCount; ++sam) - new(Samplers+sam)CachedSampler; + GetSamplerArrays(Samplers, d3d11Samplers); + for (size_t sam = 0; sam < SamplerCount; ++sam) + Samplers[sam].~CachedSampler(); } + auto UAVCount = GetUAVCount(); if (UAVCount != 0) { CachedResource* UAVResources = nullptr; ID3D11UnorderedAccessView** d3d11UAVs = nullptr; - GetUAVArrays (UAVResources, d3d11UAVs); - for (Uint32 uav = 0; uav < UAVCount; ++uav) - new(UAVResources+uav)CachedResource; + GetUAVArrays(UAVResources, d3d11UAVs); + for (size_t uav = 0; uav < UAVCount; ++uav) + UAVResources[uav].~CachedResource(); } - } - void ShaderResourceCacheD3D11::Destroy(IMemoryAllocator& MemAllocator) - { - VERIFY( IsInitialized(), "Resource cache is not initialized"); - VERIFY( m_pdbgMemoryAllocator == &MemAllocator, "The allocator does not match the one used to create resources"); + m_SRVOffset = InvalidResourceOffset; + m_SamplerOffset = InvalidResourceOffset; + m_UAVOffset = InvalidResourceOffset; + m_MemoryEndOffset = InvalidResourceOffset; - if( IsInitialized() ) - { - // Explicitly destory all objects - auto CBCount = GetCBCount(); - if (CBCount != 0) - { - CachedCB* CBs = nullptr; - ID3D11Buffer** d3d11CBs = nullptr; - GetCBArrays (CBs, d3d11CBs); - for (size_t cb = 0; cb < CBCount; ++cb) - CBs[cb].~CachedCB(); - } + if (m_pResourceData != nullptr) + MemAllocator.Free(m_pResourceData); + m_pResourceData = nullptr; + } +} - auto SRVCount = GetSRVCount(); - if (SRVCount != 0) - { - CachedResource* SRVResources = nullptr; - ID3D11ShaderResourceView** d3d11SRVs = nullptr; - GetSRVArrays (SRVResources, d3d11SRVs); - for (size_t srv = 0; srv < SRVCount; ++srv) - SRVResources[srv].~CachedResource(); - } +ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() +{ + VERIFY(!IsInitialized(), "Shader resource cache memory must be released with ShaderResourceCacheD3D11::Destroy()"); +} - auto SamplerCount = GetSamplerCount(); - if (SamplerCount != 0) +void dbgVerifyResource(ShaderResourceCacheD3D11::CachedResource& Res, ID3D11View* pd3d11View, const char* ViewType) +{ + if (pd3d11View != nullptr) + { + VERIFY(Res.pView != nullptr, "Resource view is not initialized"); + VERIFY(Res.pBuffer == nullptr && Res.pTexture != nullptr || Res.pBuffer != nullptr && Res.pTexture == nullptr, + "Texture and buffer resources are mutually exclusive"); + VERIFY(Res.pd3d11Resource != nullptr, "D3D11 resource is missing"); + + CComPtr pd3d11ActualResource; + pd3d11View->GetResource(&pd3d11ActualResource); + VERIFY(pd3d11ActualResource == Res.pd3d11Resource, "Inconsistent D3D11 resource"); + if (Res.pBuffer) + { + VERIFY(pd3d11ActualResource == Res.pBuffer->GetD3D11Buffer(), "Inconsistent buffer ", ViewType); + if (Res.pView) { - CachedSampler* Samplers = nullptr; - ID3D11SamplerState** d3d11Samplers = nullptr; - GetSamplerArrays(Samplers, d3d11Samplers); - for (size_t sam = 0; sam < SamplerCount; ++sam) - Samplers[sam].~CachedSampler(); + RefCntAutoPtr pBufView(Res.pView, IID_BufferViewD3D11); + VERIFY(pBufView != nullptr, "Provided resource view is not D3D11 buffer view"); + if (pBufView) + VERIFY(pBufView->GetBuffer() == Res.pBuffer, "Provided resource view is not a view of the buffer"); } - - auto UAVCount = GetUAVCount(); - if (UAVCount != 0) + } + else if (Res.pTexture) + { + VERIFY(pd3d11ActualResource == Res.pTexture->GetD3D11Texture(), "Inconsistent texture ", ViewType); + if (Res.pView) { - CachedResource* UAVResources = nullptr; - ID3D11UnorderedAccessView** d3d11UAVs = nullptr; - GetUAVArrays (UAVResources, d3d11UAVs); - for (size_t uav = 0; uav < UAVCount; ++uav) - UAVResources[uav].~CachedResource(); + RefCntAutoPtr pTexView(Res.pView, IID_TextureViewD3D11); + VERIFY(pTexView != nullptr, "Provided resource view is not D3D11 texture view"); + if (pTexView) + VERIFY(pTexView->GetTexture() == Res.pTexture, "Provided resource view is not a view of the texture"); } - - m_SRVOffset = InvalidResourceOffset; - m_SamplerOffset = InvalidResourceOffset; - m_UAVOffset = InvalidResourceOffset; - m_MemoryEndOffset = InvalidResourceOffset; - - if (m_pResourceData != nullptr) - MemAllocator.Free(m_pResourceData); - m_pResourceData = nullptr; } } - - ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() + else { - VERIFY( !IsInitialized(), "Shader resource cache memory must be released with ShaderResourceCacheD3D11::Destroy()" ); + VERIFY(Res.pView == nullptr, "Resource view is unexpected"); + VERIFY(Res.pBuffer == nullptr && Res.pTexture == nullptr, "Niether texture nor buffer resource is expected"); + VERIFY(Res.pd3d11Resource == nullptr, "Unexepected D3D11 resource"); } +} - void dbgVerifyResource(ShaderResourceCacheD3D11::CachedResource& Res, ID3D11View* pd3d11View, const char* ViewType) +void ShaderResourceCacheD3D11::dbgVerifyCacheConsistency() +{ + VERIFY(IsInitialized(), "Cache is not initialized"); + + CachedCB* CBs = nullptr; + ID3D11Buffer** d3d11CBs = nullptr; + CachedResource* SRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; + CachedSampler* Samplers = nullptr; + ID3D11SamplerState** d3d11Samplers = nullptr; + CachedResource* UAVResources = nullptr; + ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + + GetCBArrays(CBs, d3d11CBs); + GetSRVArrays(SRVResources, d3d11SRVs); + GetSamplerArrays(Samplers, d3d11Samplers); + GetUAVArrays(UAVResources, d3d11UAVs); + + auto CBCount = GetCBCount(); + for (size_t cb = 0; cb < CBCount; ++cb) { - if (pd3d11View != nullptr) + auto& pBuff = CBs[cb].pBuff; + auto* pd3d11Buff = d3d11CBs[cb]; + VERIFY(pBuff == nullptr && pd3d11Buff == nullptr || pBuff != nullptr && pd3d11Buff != nullptr, "CB resource and d3d11 buffer must be set/unset atomically"); + if (pBuff != nullptr && pd3d11Buff != nullptr) { - VERIFY(Res.pView != nullptr, "Resource view is not initialized"); - VERIFY(Res.pBuffer==nullptr && Res.pTexture!=nullptr || Res.pBuffer!=nullptr && Res.pTexture==nullptr, "Texture and buffer resources are mutually exclusive"); - VERIFY(Res.pd3d11Resource!=nullptr, "D3D11 resource is missing"); - - CComPtr pd3d11ActualResource; - pd3d11View->GetResource(&pd3d11ActualResource); - VERIFY(pd3d11ActualResource == Res.pd3d11Resource, "Inconsistent D3D11 resource"); - if (Res.pBuffer) - { - VERIFY(pd3d11ActualResource == Res.pBuffer->GetD3D11Buffer(), "Inconsistent buffer ", ViewType); - if (Res.pView) - { - RefCntAutoPtr pBufView(Res.pView, IID_BufferViewD3D11); - VERIFY(pBufView != nullptr, "Provided resource view is not D3D11 buffer view"); - if(pBufView) - VERIFY(pBufView->GetBuffer() == Res.pBuffer, "Provided resource view is not a view of the buffer"); - } - } - else if(Res.pTexture) - { - VERIFY(pd3d11ActualResource == Res.pTexture->GetD3D11Texture(), "Inconsistent texture ", ViewType); - if (Res.pView) - { - RefCntAutoPtr pTexView(Res.pView, IID_TextureViewD3D11); - VERIFY(pTexView != nullptr, "Provided resource view is not D3D11 texture view"); - if(pTexView) - VERIFY(pTexView->GetTexture() == Res.pTexture, "Provided resource view is not a view of the texture"); - } - } + VERIFY(pd3d11Buff == pBuff->GetD3D11Buffer(), "Inconsistent D3D11 buffer"); } - else - { - VERIFY(Res.pView==nullptr, "Resource view is unexpected"); - VERIFY(Res.pBuffer==nullptr && Res.pTexture==nullptr, "Niether texture nor buffer resource is expected"); - VERIFY(Res.pd3d11Resource==nullptr, "Unexepected D3D11 resource"); - } } - void ShaderResourceCacheD3D11::dbgVerifyCacheConsistency() + auto SRVCount = GetSRVCount(); + for (size_t srv = 0; srv < SRVCount; ++srv) { - VERIFY(IsInitialized(), "Cache is not initialized"); - - CachedCB* CBs = nullptr; - ID3D11Buffer** d3d11CBs = nullptr; - CachedResource* SRVResources = nullptr; - ID3D11ShaderResourceView** d3d11SRVs = nullptr; - CachedSampler* Samplers = nullptr; - ID3D11SamplerState** d3d11Samplers = nullptr; - CachedResource* UAVResources = nullptr; - ID3D11UnorderedAccessView** d3d11UAVs = nullptr; - - GetCBArrays (CBs, d3d11CBs); - GetSRVArrays (SRVResources, d3d11SRVs); - GetSamplerArrays(Samplers, d3d11Samplers); - GetUAVArrays (UAVResources, d3d11UAVs); - - auto CBCount = GetCBCount(); - for (size_t cb = 0; cb < CBCount; ++cb) - { - auto &pBuff = CBs[cb].pBuff; - auto *pd3d11Buff = d3d11CBs[cb]; - VERIFY(pBuff==nullptr && pd3d11Buff==nullptr || pBuff!=nullptr && pd3d11Buff!=nullptr, "CB resource and d3d11 buffer must be set/unset atomically"); - if(pBuff != nullptr && pd3d11Buff != nullptr ) - { - VERIFY(pd3d11Buff == pBuff->GetD3D11Buffer(), "Inconsistent D3D11 buffer"); - } - } - - auto SRVCount = GetSRVCount(); - for (size_t srv = 0; srv < SRVCount; ++srv) - { - auto &Res = SRVResources[srv]; - auto *pd3d11SRV = d3d11SRVs[srv]; - dbgVerifyResource(Res, pd3d11SRV, "SRV"); - } + auto& Res = SRVResources[srv]; + auto* pd3d11SRV = d3d11SRVs[srv]; + dbgVerifyResource(Res, pd3d11SRV, "SRV"); + } - auto UAVCount = GetUAVCount(); - for (size_t uav = 0; uav < UAVCount; ++uav) - { - auto &Res = UAVResources[uav]; - auto *pd3d11UAV = d3d11UAVs[uav]; - dbgVerifyResource(Res, pd3d11UAV, "UAV"); - } + auto UAVCount = GetUAVCount(); + for (size_t uav = 0; uav < UAVCount; ++uav) + { + auto& Res = UAVResources[uav]; + auto* pd3d11UAV = d3d11UAVs[uav]; + dbgVerifyResource(Res, pd3d11UAV, "UAV"); + } - auto SamplerCount = GetSamplerCount(); - for (size_t sam = 0; sam < SamplerCount; ++sam) + auto SamplerCount = GetSamplerCount(); + for (size_t sam = 0; sam < SamplerCount; ++sam) + { + auto& pSampler = Samplers[sam].pSampler; + auto* pd3d11Sampler = d3d11Samplers[sam]; + VERIFY(pSampler == nullptr && pd3d11Sampler == nullptr || pSampler != nullptr && pd3d11Sampler != nullptr, "CB resource and d3d11 buffer must be set/unset atomically"); + if (pSampler != nullptr && pd3d11Sampler != nullptr) { - auto &pSampler = Samplers[sam].pSampler; - auto *pd3d11Sampler = d3d11Samplers[sam]; - VERIFY(pSampler==nullptr && pd3d11Sampler==nullptr || pSampler!=nullptr && pd3d11Sampler!=nullptr, "CB resource and d3d11 buffer must be set/unset atomically"); - if(pSampler!=nullptr && pd3d11Sampler!=nullptr) - { - VERIFY(pd3d11Sampler==pSampler->GetD3D11SamplerState(), "Inconsistent D3D11 sampler"); - } + VERIFY(pd3d11Sampler == pSampler->GetD3D11SamplerState(), "Inconsistent D3D11 sampler"); } } } +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index d61019bd..4378b419 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -41,8 +41,9 @@ namespace Diligent ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11() { + // clang-format off HandleResources( - [&](ConstBuffBindInfo& cb) + [&](ConstBuffBindInfo& cb) { cb.~ConstBuffBindInfo(); }, @@ -72,23 +73,26 @@ ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11() sam.~SamplerBindInfo(); } ); + // clang-format on } -size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, +size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes) { // Skip static samplers as they are initialized directly in the resource cache by the PSO - constexpr bool CountStaticSamplers = false; - auto ResCounters = SrcResources.CountResources(ResourceLayout, AllowedVarTypes, NumAllowedTypes, CountStaticSamplers); + constexpr bool CountStaticSamplers = false; + auto ResCounters = SrcResources.CountResources(ResourceLayout, AllowedVarTypes, NumAllowedTypes, CountStaticSamplers); + // clang-format off auto MemSize = ResCounters.NumCBs * sizeof(ConstBuffBindInfo) + ResCounters.NumTexSRVs * sizeof(TexSRVBindInfo) + ResCounters.NumTexUAVs * sizeof(TexUAVBindInfo) + ResCounters.NumBufSRVs * sizeof(BuffSRVBindInfo) + ResCounters.NumBufUAVs * sizeof(BuffUAVBindInfo) + ResCounters.NumSamplers * sizeof(SamplerBindInfo); + // clang-format on return MemSize; } @@ -96,14 +100,16 @@ size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Owner, std::shared_ptr pSrcResources, const PipelineResourceLayoutDesc& ResourceLayout, - const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, + Uint32 NumVarTypes, ShaderResourceCacheD3D11& ResourceCache, IMemoryAllocator& ResCacheDataAllocator, IMemoryAllocator& ResLayoutDataAllocator) : + // clang-format off m_Owner {Owner}, m_pResources {std::move(pSrcResources)}, m_ResourceCache {ResourceCache} +// clang-format on { // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-layout#Shader-Resource-Layout-Initialization @@ -111,13 +117,14 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& // Count total number of resources of allowed types // Skip static samplers as they are initialized directly in the resource cache by the PSO - constexpr bool CountStaticSamplers = false; - auto ResCounters = m_pResources->CountResources(ResourceLayout, VarTypes, NumVarTypes, CountStaticSamplers); + constexpr bool CountStaticSamplers = false; + auto ResCounters = m_pResources->CountResources(ResourceLayout, VarTypes, NumVarTypes, CountStaticSamplers); // Initialize offsets size_t CurrentOffset = 0; - auto AdvanceOffset = [&CurrentOffset](size_t NumBytes) - { + + auto AdvanceOffset = [&CurrentOffset](size_t NumBytes) // clang-format off + { // clang-format on constexpr size_t MaxOffset = std::numeric_limits::max(); VERIFY(CurrentOffset <= MaxOffset, "Current offser (", CurrentOffset, ") exceeds max allowed value (", MaxOffset, ")"); auto Offset = static_cast(CurrentOffset); @@ -125,6 +132,7 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& return Offset; }; + // clang-format off auto CBOffset = AdvanceOffset(ResCounters.NumCBs * sizeof(ConstBuffBindInfo)); (void)CBOffset; // To suppress warning m_TexSRVsOffset = AdvanceOffset(ResCounters.NumTexSRVs * sizeof(TexSRVBindInfo) ); m_TexUAVsOffset = AdvanceOffset(ResCounters.NumTexUAVs * sizeof(TexUAVBindInfo) ); @@ -132,21 +140,24 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& m_BuffUAVsOffset = AdvanceOffset(ResCounters.NumBufUAVs * sizeof(BuffUAVBindInfo) ); m_SamplerOffset = AdvanceOffset(ResCounters.NumSamplers * sizeof(SamplerBindInfo) ); m_MemorySize = AdvanceOffset(0); + // clang-format on VERIFY_EXPR(m_MemorySize == GetRequiredMemorySize(*m_pResources, ResourceLayout, VarTypes, NumVarTypes)); if (m_MemorySize) { - auto* pRawMem = ALLOCATE_RAW(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize); - m_ResourceBuffer = std::unique_ptr >(pRawMem, ResLayoutDataAllocator); + auto* pRawMem = ALLOCATE_RAW(ResLayoutDataAllocator, "Raw memory buffer for shader resource layout resources", m_MemorySize); + m_ResourceBuffer = std::unique_ptr>(pRawMem, ResLayoutDataAllocator); } + // clang-format off VERIFY_EXPR(ResCounters.NumCBs == GetNumCBs() ); VERIFY_EXPR(ResCounters.NumTexSRVs == GetNumTexSRVs() ); VERIFY_EXPR(ResCounters.NumTexUAVs == GetNumTexUAVs() ); VERIFY_EXPR(ResCounters.NumBufSRVs == GetNumBufSRVs() ); VERIFY_EXPR(ResCounters.NumBufUAVs == GetNumBufUAVs() ); VERIFY_EXPR(ResCounters.NumSamplers== GetNumSamplers()); + // clang-format on // Current resource index for every resource type Uint32 cb = 0; @@ -156,13 +167,13 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Uint32 bufUav = 0; Uint32 sam = 0; - Uint32 NumCBSlots = 0; - Uint32 NumSRVSlots = 0; + Uint32 NumCBSlots = 0; + Uint32 NumSRVSlots = 0; Uint32 NumSamplerSlots = 0; - Uint32 NumUAVSlots = 0; + Uint32 NumUAVSlots = 0; m_pResources->ProcessResources( - [&](const D3DShaderResourceAttribs& CB, Uint32) - { + [&](const D3DShaderResourceAttribs& CB, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(CB, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -172,14 +183,14 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& } }, - [&](const D3DShaderResourceAttribs& Sampler, Uint32) - { + [&](const D3DShaderResourceAttribs& Sampler, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(Sampler, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) { // Constructor of PipelineStateD3D11Impl initializes static samplers and will log the error, if any constexpr bool LogStaticSamplerArrayError = false; - auto StaticSamplerInd = m_pResources->FindStaticSampler(Sampler, ResourceLayout, LogStaticSamplerArrayError); + auto StaticSamplerInd = m_pResources->FindStaticSampler(Sampler, ResourceLayout, LogStaticSamplerArrayError); if (StaticSamplerInd >= 0) { // Skip static samplers as they are initialized directly in the resource cache by the PSO @@ -191,8 +202,8 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& } }, - [&](const D3DShaderResourceAttribs& TexSRV, Uint32) - { + [&](const D3DShaderResourceAttribs& TexSRV, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(TexSRV, ResourceLayout); if (!IsAllowedType(VarType, AllowedTypeBits)) return; @@ -204,19 +215,19 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& if (TexSRV.IsCombinedWithSampler()) { const auto& AssignedSamplerAttribs = m_pResources->GetCombinedSampler(TexSRV); - auto AssignedSamplerType = m_pResources->FindVariableType(AssignedSamplerAttribs, ResourceLayout); + auto AssignedSamplerType = m_pResources->FindVariableType(AssignedSamplerAttribs, ResourceLayout); VERIFY(AssignedSamplerType == VarType, - "The type (", GetShaderVariableTypeLiteralName(VarType),") of texture SRV variable '", TexSRV.Name, + "The type (", GetShaderVariableTypeLiteralName(VarType), ") of texture SRV variable '", TexSRV.Name, "' is not consistent with the type (", GetShaderVariableTypeLiteralName(AssignedSamplerType), - ") of the sampler '", AssignedSamplerAttribs.Name, "' that is assigned to it. " - "This should never happen as when combined texture samplers are used, the type of the sampler " - "is derived from the type of the texture it is assigned to SRV."); - + ") of the sampler '", AssignedSamplerAttribs.Name, + "' that is assigned to it. This should never happen as when combined texture samplers are used, " + "the type of the sampler is derived from the type of the texture it is assigned to SRV."); + bool SamplerFound = false; for (AssignedSamplerIndex = 0; AssignedSamplerIndex < NumSamplers; ++AssignedSamplerIndex) { const auto& Sampler = GetResource(AssignedSamplerIndex); - SamplerFound = strcmp(Sampler.m_Attribs.Name, AssignedSamplerAttribs.Name) == 0; + SamplerFound = strcmp(Sampler.m_Attribs.Name, AssignedSamplerAttribs.Name) == 0; if (SamplerFound) break; // Otherwise AssignedSamplerIndex will be incremented } @@ -251,8 +262,8 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& NumSRVSlots = std::max(NumSRVSlots, Uint32{TexSRV.BindPoint} + Uint32{TexSRV.BindCount}); }, - [&](const D3DShaderResourceAttribs& TexUAV, Uint32) - { + [&](const D3DShaderResourceAttribs& TexUAV, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(TexUAV, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -262,8 +273,8 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& } }, - [&](const D3DShaderResourceAttribs& BuffSRV, Uint32) - { + [&](const D3DShaderResourceAttribs& BuffSRV, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(BuffSRV, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -273,8 +284,8 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& } }, - [&](const D3DShaderResourceAttribs& BuffUAV, Uint32) - { + [&](const D3DShaderResourceAttribs& BuffUAV, Uint32) // clang-format off + { // clang-format on auto VarType = m_pResources->FindVariableType(BuffUAV, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) { @@ -282,18 +293,19 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& new (&GetResource(bufUav++)) BuffUAVBindInfo(BuffUAV, *this, VarType); NumUAVSlots = std::max(NumUAVSlots, Uint32{BuffUAV.BindPoint} + Uint32{BuffUAV.BindCount}); } - } - ); + }); + // clang-format off VERIFY(cb == GetNumCBs(), "Not all CBs are initialized which will cause a crash when dtor is called"); VERIFY(texSrv == GetNumTexSRVs(), "Not all Tex SRVs are initialized which will cause a crash when dtor is called"); VERIFY(texUav == GetNumTexUAVs(), "Not all Tex UAVs are initialized which will cause a crash when dtor is called"); VERIFY(bufSrv == GetNumBufSRVs(), "Not all Buf SRVs are initialized which will cause a crash when dtor is called"); VERIFY(bufUav == GetNumBufUAVs(), "Not all Buf UAVs are initialized which will cause a crash when dtor is called"); VERIFY(sam == GetNumSamplers(), "Not all samplers are initialized which will cause a crash when dtor is called"); + // clang-format on // Shader resource cache in the SRB is initialized by the constructor of ShaderResourceBindingD3D11Impl to - // hold all variable types. The corresponding layout in the SRB is initialized to keep mutable and dynamic + // hold all variable types. The corresponding layout in the SRB is initialized to keep mutable and dynamic // variables only // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache#Shader-Resource-Cache-Initialization if (!m_ResourceCache.IsInitialized()) @@ -303,25 +315,29 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& } } -void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache)const +void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache) const { + // clang-format off VERIFY( DstCache.GetCBCount() >= m_ResourceCache.GetCBCount(), "Dst cache is not large enough to contain all CBs" ); VERIFY( DstCache.GetSRVCount() >= m_ResourceCache.GetSRVCount(), "Dst cache is not large enough to contain all SRVs" ); VERIFY( DstCache.GetSamplerCount() >= m_ResourceCache.GetSamplerCount(), "Dst cache is not large enough to contain all samplers" ); VERIFY( DstCache.GetUAVCount() >= m_ResourceCache.GetUAVCount(), "Dst cache is not large enough to contain all UAVs" ); + // clang-format on ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; ID3D11Buffer** d3d11CBs = nullptr; ShaderResourceCacheD3D11::CachedResource* CachedSRVResources = nullptr; ID3D11ShaderResourceView** d3d11SRVs = nullptr; - ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr; - ID3D11SamplerState** d3d11Samplers = nullptr; + ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr; + ID3D11SamplerState** d3d11Samplers = nullptr; ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr; ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + // clang-format off m_ResourceCache.GetCBArrays (CachedCBs, d3d11CBs); m_ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs); m_ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers); m_ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs); + // clang-format on ShaderResourceCacheD3D11::CachedCB* DstCBs = nullptr; @@ -332,79 +348,80 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache ID3D11SamplerState** DstD3D11Samplers = nullptr; ShaderResourceCacheD3D11::CachedResource* DstUAVResources = nullptr; ID3D11UnorderedAccessView** DstD3D11UAVs = nullptr; + // clang-format off DstCache.GetCBArrays (DstCBs, DstD3D11CBs); DstCache.GetSRVArrays (DstSRVResources, DstD3D11SRVs); DstCache.GetSamplerArrays(DstSamplers, DstD3D11Samplers); DstCache.GetUAVArrays (DstUAVResources, DstD3D11UAVs); + // clang-format on HandleConstResources( - [&](const ConstBuffBindInfo& cb) - { - for (auto CBSlot = cb.m_Attribs.BindPoint; CBSlot < cb.m_Attribs.BindPoint+cb.m_Attribs.BindCount; ++CBSlot) + [&](const ConstBuffBindInfo& cb) // clang-format off + { // clang-format on + for (auto CBSlot = cb.m_Attribs.BindPoint; CBSlot < cb.m_Attribs.BindPoint + cb.m_Attribs.BindCount; ++CBSlot) { VERIFY_EXPR(CBSlot < m_ResourceCache.GetCBCount() && CBSlot < DstCache.GetCBCount()); - DstCBs [CBSlot] = CachedCBs[CBSlot]; - DstD3D11CBs[CBSlot] = d3d11CBs [CBSlot]; + DstCBs[CBSlot] = CachedCBs[CBSlot]; + DstD3D11CBs[CBSlot] = d3d11CBs[CBSlot]; } }, - [&](const TexSRVBindInfo& ts) - { + [&](const TexSRVBindInfo& ts) // clang-format off + { // clang-format on for (auto SRVSlot = ts.m_Attribs.BindPoint; SRVSlot < ts.m_Attribs.BindPoint + ts.m_Attribs.BindCount; ++SRVSlot) { VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount()); DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot]; - DstD3D11SRVs [SRVSlot] = d3d11SRVs [SRVSlot]; + DstD3D11SRVs[SRVSlot] = d3d11SRVs[SRVSlot]; } }, - [&](const TexUAVBindInfo& uav) - { + [&](const TexUAVBindInfo& uav) // clang-format off + { // clang-format on for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) { VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount()); DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot]; - DstD3D11UAVs [UAVSlot] = d3d11UAVs [UAVSlot]; + DstD3D11UAVs[UAVSlot] = d3d11UAVs[UAVSlot]; } }, - [&](const BuffSRVBindInfo& srv) - { + [&](const BuffSRVBindInfo& srv) // clang-format off + { // clang-format on for (auto SRVSlot = srv.m_Attribs.BindPoint; SRVSlot < srv.m_Attribs.BindPoint + srv.m_Attribs.BindCount; ++SRVSlot) { VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount()); DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot]; - DstD3D11SRVs [SRVSlot] = d3d11SRVs [SRVSlot]; + DstD3D11SRVs[SRVSlot] = d3d11SRVs[SRVSlot]; } }, - [&](const BuffUAVBindInfo& uav) - { + [&](const BuffUAVBindInfo& uav) // clang-format off + { // clang-format on for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) { VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount()); DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot]; - DstD3D11UAVs [UAVSlot] = d3d11UAVs [UAVSlot]; + DstD3D11UAVs[UAVSlot] = d3d11UAVs[UAVSlot]; } }, - [&](const SamplerBindInfo& sam) - { + [&](const SamplerBindInfo& sam) // clang-format off + { // clang-format on //VERIFY(!sam.IsStaticSampler, "Variables are not created for static samplers"); for (auto SamSlot = sam.m_Attribs.BindPoint; SamSlot < sam.m_Attribs.BindPoint + sam.m_Attribs.BindCount; ++SamSlot) { VERIFY_EXPR(SamSlot < m_ResourceCache.GetSamplerCount() && SamSlot < DstCache.GetSamplerCount()); - DstSamplers [SamSlot] = CachedSamplers[SamSlot]; - DstD3D11Samplers[SamSlot] = d3d11Samplers [SamSlot]; + DstSamplers[SamSlot] = CachedSamplers[SamSlot]; + DstD3D11Samplers[SamSlot] = d3d11Samplers[SamSlot]; } - } - ); + }); } void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* pBuffer, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount - 1); // We cannot use ValidatedCast<> here as the resource retrieved from the // resource mapping can be of wrong type @@ -415,14 +432,14 @@ void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* p VerifyConstantBufferBinding(m_Attribs, GetType(), ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(), m_ParentResLayout.GetShaderName()); } #endif - m_ParentResLayout.m_ResourceCache.SetCB(m_Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) ); + m_ParentResLayout.m_ResourceCache.SetCB(m_Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl)); } void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount - 1); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -434,7 +451,7 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, CachedSRV.pView.RawPtr(), m_ParentResLayout.GetShaderName()); } #endif - + if (ValidSamplerAssigned()) { auto& Sampler = m_ParentResLayout.GetResource(SamplerIndex); @@ -449,10 +466,10 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie #ifdef DEVELOPMENT if (pSamplerD3D11Impl == nullptr) { - if(Sampler.m_Attribs.BindCount > 1) - LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "[", ArrayIndex,"]'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" ); + if (Sampler.m_Attribs.BindCount > 1) + LOG_ERROR_MESSAGE("Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "[", ArrayIndex, "]'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'"); else - LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" ); + LOG_ERROR_MESSAGE("Failed to bind sampler to variable '", Sampler.m_Attribs.Name, "'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'"); } #endif } @@ -463,12 +480,12 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl) { auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType()); - LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Sampler.m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE("Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Sampler.m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic."); } } #endif ResourceCache.SetSampler(SamplerBindPoint, pSamplerD3D11Impl); - } + } ResourceCache.SetTexSRV(m_Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11)); } @@ -476,7 +493,9 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSampler, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, + "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, + "'. Max allowed index: ", m_Attribs.BindCount - 1); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; //VERIFY(!IsStaticSampler, "Cannot bind sampler to a static sampler"); @@ -488,22 +507,27 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa if (pSampler && !pSamplerD3D11) { LOG_ERROR_MESSAGE("Failed to bind object '", pSampler->GetDesc().Name, "' to variable '", m_Attribs.GetPrintName(ArrayIndex), - "' in shader '", m_ParentResLayout.GetShaderName(), "'. Incorect object type: sampler is expected."); + "' in shader '", m_ParentResLayout.GetShaderName(), "'. Incorect object type: sampler is expected."); } if (m_Attribs.IsCombinedWithTexSRV()) { auto* TexSRVName = m_ParentResLayout.m_pResources->GetCombinedTextureSRV(m_Attribs).Name; - LOG_WARNING_MESSAGE("Texture sampler sampler '", m_Attribs.Name, "' is assigned to texture SRV '", TexSRVName, "' and should not be accessed directly. The sampler is initialized when texture SRV is set to '", TexSRVName, "' variable."); + LOG_WARNING_MESSAGE("Texture sampler sampler '", m_Attribs.Name, "' is assigned to texture SRV '", + TexSRVName, "' and should not be accessed directly. The sampler is initialized when texture SRV is set to '", + TexSRVName, "' variable."); } if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { auto& CachedSampler = ResourceCache.GetSampler(m_Attribs.BindPoint + ArrayIndex); - if( CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11) + if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType()); - LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE("Non-null sampler is already bound to ", VarTypeStr, " shader variable '", + m_Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), + "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. " + "Use another shader resource binding instance or label the variable as dynamic."); } } #endif @@ -514,7 +538,8 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", + m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount - 1); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -533,7 +558,8 @@ void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pVi void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", + m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount - 1); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -552,7 +578,8 @@ void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVie void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex) { - DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount-1); + DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", + m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount - 1); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -574,25 +601,25 @@ class BindResourceHelper { public: BindResourceHelper(IResourceMapping& RM, Uint32 Fl) : - ResourceMapping(RM), - Flags(Fl) + ResourceMapping{RM}, + Flags{Fl} { } - template - void Bind( ResourceType& Res) + template + void Bind(ResourceType& Res) { - if ( (Flags & (1 << Res.GetType())) == 0 ) + if ((Flags & (1 << Res.GetType())) == 0) return; - for (Uint16 elem=0; elem < Res.m_Attribs.BindCount; ++elem) + for (Uint16 elem = 0; elem < Res.m_Attribs.BindCount; ++elem) { - if ( (Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Res.IsBound(elem) ) + if ((Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Res.IsBound(elem)) continue; - const auto* VarName = Res.m_Attribs.Name; + const auto* VarName = Res.m_Attribs.Name; RefCntAutoPtr pRes; - ResourceMapping.GetResource( VarName, &pRes, elem ); + ResourceMapping.GetResource(VarName, &pRes, elem); if (pRes) { // Call non-virtual function @@ -600,8 +627,11 @@ public: } else { - if ( (Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Res.IsBound(elem) ) - LOG_ERROR_MESSAGE( "Unable to bind resource to shader variable '", VarName, "': resource is not found in the resource mapping" ); + if ((Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Res.IsBound(elem)) + { + LOG_ERROR_MESSAGE("Unable to bind resource to shader variable '", VarName, + "': resource is not found in the resource mapping"); + } } } } @@ -611,21 +641,24 @@ private: const Uint32 Flags; }; -void ShaderResourceLayoutD3D11::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache ) +void ShaderResourceLayoutD3D11::BindResources(IResourceMapping* pResourceMapping, + Uint32 Flags, + const ShaderResourceCacheD3D11& dbgResourceCache) { VERIFY(&dbgResourceCache == &m_ResourceCache, "Resource cache does not match the cache provided at initialization"); if (pResourceMapping == nullptr) { - LOG_ERROR_MESSAGE( "Failed to bind resources in shader '", GetShaderName(), "': resource mapping is null" ); + LOG_ERROR_MESSAGE("Failed to bind resources in shader '", GetShaderName(), "': resource mapping is null"); return; } - - if ( (Flags & BIND_SHADER_RESOURCES_UPDATE_ALL) == 0 ) + + if ((Flags & BIND_SHADER_RESOURCES_UPDATE_ALL) == 0) Flags |= BIND_SHADER_RESOURCES_UPDATE_ALL; BindResourceHelper BindResHelper(*pResourceMapping, Flags); + // clang-format off HandleResources( [&](ConstBuffBindInfo& cb) { @@ -658,10 +691,11 @@ void ShaderResourceLayoutD3D11::BindResources( IResourceMapping* pResourceMappin BindResHelper.Bind(sam); } ); + // clang-format on } -template -IShaderResourceVariable* ShaderResourceLayoutD3D11::GetResourceByName( const Char* Name ) +template +IShaderResourceVariable* ShaderResourceLayoutD3D11::GetResourceByName(const Char* Name) { auto NumResources = GetNumResources(); for (Uint32 res = 0; res < NumResources; ++res) @@ -704,12 +738,14 @@ IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char class ShaderVariableIndexLocator { public: - ShaderVariableIndexLocator(const ShaderResourceLayoutD3D11& _Layout, const ShaderResourceLayoutD3D11::ShaderVariableD3D11Base& Variable) : - Layout (_Layout), + ShaderVariableIndexLocator(const ShaderResourceLayoutD3D11& _Layout, const ShaderResourceLayoutD3D11::ShaderVariableD3D11Base& Variable) : + // clang-format off + Layout {_Layout}, VarOffset(reinterpret_cast(&Variable) - reinterpret_cast(_Layout.m_ResourceBuffer.get())) + // clang-format on {} - template + template bool TryResource(ShaderResourceLayoutD3D11::OffsetType NextResourceTypeOffset) { #ifdef _DEBUG @@ -720,7 +756,7 @@ public: if (VarOffset < NextResourceTypeOffset) { auto RelativeOffset = VarOffset - Layout.GetResourceOffset(); - DEV_CHECK_ERR( RelativeOffset % sizeof(ResourceType) == 0, "Offset is not multiple of resource type (", sizeof(ResourceType), ")"); + DEV_CHECK_ERR(RelativeOffset % sizeof(ResourceType) == 0, "Offset is not multiple of resource type (", sizeof(ResourceType), ")"); Index += static_cast(RelativeOffset / sizeof(ResourceType)); return true; } @@ -731,25 +767,25 @@ public: } } - Uint32 GetIndex() const {return Index;} + Uint32 GetIndex() const { return Index; } private: const ShaderResourceLayoutD3D11& Layout; - const size_t VarOffset; - Uint32 Index = 0; + const size_t VarOffset; + Uint32 Index = 0; #ifdef _DEBUG Uint32 dbgPreviousResourceOffset = 0; #endif }; -Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base& Variable)const +Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base& Variable) const { if (!m_ResourceBuffer) { LOG_ERROR("This shader resource layout does not have resources"); return static_cast(-1); } - + ShaderVariableIndexLocator IdxLocator(*this, Variable); if (IdxLocator.TryResource(m_TexSRVsOffset)) return IdxLocator.GetIndex(); @@ -779,13 +815,15 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base class ShaderVariableLocator { public: - ShaderVariableLocator(ShaderResourceLayoutD3D11& _Layout, Uint32 _Index) : - Layout(_Layout), - Index (_Index) + ShaderVariableLocator(ShaderResourceLayoutD3D11& _Layout, Uint32 _Index) : + // clang-format off + Layout{_Layout}, + Index {_Index } + // clang-format on { } - template + template IShaderResourceVariable* TryResource() { #ifdef _DEBUG @@ -804,37 +842,37 @@ public: private: ShaderResourceLayoutD3D11& Layout; - Uint32 Index; + Uint32 Index = 0; #ifdef _DEBUG Uint32 dbgPreviousResourceOffset = 0; #endif }; -IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 Index ) +IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable(Uint32 Index) { ShaderVariableLocator VarLocator(*this, Index); - if(auto* pCB = VarLocator.TryResource()) + if (auto* pCB = VarLocator.TryResource()) return pCB; - if(auto* pTexSRV = VarLocator.TryResource()) + if (auto* pTexSRV = VarLocator.TryResource()) return pTexSRV; - if(auto* pTexUAV = VarLocator.TryResource()) + if (auto* pTexUAV = VarLocator.TryResource()) return pTexUAV; - if(auto* pBuffSRV = VarLocator.TryResource()) + if (auto* pBuffSRV = VarLocator.TryResource()) return pBuffSRV; - if(auto* pBuffUAV = VarLocator.TryResource()) + if (auto* pBuffUAV = VarLocator.TryResource()) return pBuffUAV; if (!m_pResources->IsUsingCombinedTextureSamplers()) { - if(auto* pSampler = VarLocator.TryResource()) + if (auto* pSampler = VarLocator.TryResource()) return pSampler; } - + auto TotalResCount = GetTotalResourceCount(); LOG_ERROR(Index, " is not a valid variable index. Total resource count: ", TotalResCount); return nullptr; @@ -842,41 +880,42 @@ IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 In #ifdef DEVELOPMENT -bool ShaderResourceLayoutD3D11::dvpVerifyBindings()const +bool ShaderResourceLayoutD3D11::dvpVerifyBindings() const { -#define LOG_MISSING_BINDING(VarType, Attrs, BindPt)\ -do{ \ - if (Attrs.BindCount == 1) \ - LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable '", Attrs.Name, "' in shader '", GetShaderName(), "'" ); \ - else \ - LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable '", Attrs.Name, "[", BindPt-Attrs.BindPoint, "]' in shader '", GetShaderName(), "'" );\ -}while(false) +# define LOG_MISSING_BINDING(VarType, Attrs, BindPt) \ + do \ + { \ + if (Attrs.BindCount == 1) \ + LOG_ERROR_MESSAGE("No resource is bound to ", VarType, " variable '", Attrs.Name, "' in shader '", GetShaderName(), "'"); \ + else \ + LOG_ERROR_MESSAGE("No resource is bound to ", VarType, " variable '", Attrs.Name, "[", BindPt - Attrs.BindPoint, "]' in shader '", GetShaderName(), "'"); \ + } while (false) m_ResourceCache.dbgVerifyCacheConsistency(); - + bool BindingsOK = true; HandleConstResources( - [&](const ConstBuffBindInfo& cb) - { + [&](const ConstBuffBindInfo& cb) // clang-format off + { // clang-format on for (Uint32 BindPoint = cb.m_Attribs.BindPoint; BindPoint < Uint32{cb.m_Attribs.BindPoint} + cb.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsCBBound(BindPoint)) { LOG_MISSING_BINDING("constant buffer", cb.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } } }, - [&](const TexSRVBindInfo& ts) - { + [&](const TexSRVBindInfo& ts) // clang-format off + { // clang-format on for (Uint32 BindPoint = ts.m_Attribs.BindPoint; BindPoint < Uint32{ts.m_Attribs.BindPoint} + ts.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsSRVBound(BindPoint, true)) { LOG_MISSING_BINDING("texture", ts.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } if (ts.ValidSamplerAssigned()) @@ -904,7 +943,7 @@ do{ \ auto* pSampler = pTexView->GetSampler(); if (pSampler != nullptr && pSampler != CachedSampler.pSampler.RawPtr()) { - LOG_ERROR_MESSAGE( "All elements of texture array '", ts.m_Attribs.Name, "' in shader '", GetShaderName(), "' share the same sampler. However, the sampler set in view for element ", BindPoint - ts.m_Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." ); + LOG_ERROR_MESSAGE("All elements of texture array '", ts.m_Attribs.Name, "' in shader '", GetShaderName(), "' share the same sampler. However, the sampler set in view for element ", BindPoint - ts.m_Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform."); } } } @@ -912,58 +951,58 @@ do{ \ } }, - [&](const TexUAVBindInfo& uav) - { + [&](const TexUAVBindInfo& uav) // clang-format off + { // clang-format on for (Uint32 BindPoint = uav.m_Attribs.BindPoint; BindPoint < Uint32{uav.m_Attribs.BindPoint} + uav.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsUAVBound(BindPoint, true)) { LOG_MISSING_BINDING("texture UAV", uav.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } } }, - [&](const BuffSRVBindInfo& buf) - { + [&](const BuffSRVBindInfo& buf) // clang-format off + { // clang-format on for (Uint32 BindPoint = buf.m_Attribs.BindPoint; BindPoint < Uint32{buf.m_Attribs.BindPoint} + buf.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsSRVBound(BindPoint, false)) { LOG_MISSING_BINDING("buffer", buf.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } } }, - [&](const BuffUAVBindInfo& uav) - { + [&](const BuffUAVBindInfo& uav) // clang-format off + { // clang-format on for (Uint32 BindPoint = uav.m_Attribs.BindPoint; BindPoint < Uint32{uav.m_Attribs.BindPoint} + uav.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsUAVBound(BindPoint, false)) { LOG_MISSING_BINDING("buffer UAV", uav.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } } }, - [&](const SamplerBindInfo& sam) - { + [&](const SamplerBindInfo& sam) // clang-format off + { // clang-format on for (Uint32 BindPoint = sam.m_Attribs.BindPoint; BindPoint < Uint32{sam.m_Attribs.BindPoint} + sam.m_Attribs.BindCount; ++BindPoint) { if (!m_ResourceCache.IsSamplerBound(BindPoint)) { LOG_MISSING_BINDING("sampler", sam.m_Attribs, BindPoint); - BindingsOK = false; + BindingsOK = false; } } - } - ); -#undef LOG_MISSING_BINDING + } // clang-format off + ); // clang-format on +# undef LOG_MISSING_BINDING return BindingsOK; } #endif -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index 7bc7d4bb..7c3f9942 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -45,47 +45,49 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im NewResourceHandler(RenderDeviceD3D11Impl* const _pDeviceD3D11Impl, const ShaderDesc& _ShdrDesc, const char* _CombinedSamplerSuffix, - ShaderResourcesD3D11& _Resources) : - pDeviceD3D11Impl (_pDeviceD3D11Impl), - ShdrDesc (_ShdrDesc), - CombinedSamplerSuffix(_CombinedSamplerSuffix), - Resources (_Resources) + ShaderResourcesD3D11& _Resources) : + // clang-format off + pDeviceD3D11Impl {_pDeviceD3D11Impl }, + ShdrDesc {_ShdrDesc }, + CombinedSamplerSuffix{_CombinedSamplerSuffix}, + Resources {_Resources } + // clang-format on {} void OnNewCB(const D3DShaderResourceAttribs& CBAttribs) { - VERIFY( CBAttribs.BindPoint + CBAttribs.BindCount-1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range" ); - Resources.m_MaxCBBindPoint = std::max(Resources.m_MaxCBBindPoint, static_cast(CBAttribs.BindPoint + CBAttribs.BindCount-1)); + VERIFY(CBAttribs.BindPoint + CBAttribs.BindCount - 1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range"); + Resources.m_MaxCBBindPoint = std::max(Resources.m_MaxCBBindPoint, static_cast(CBAttribs.BindPoint + CBAttribs.BindCount - 1)); } - void OnNewTexUAV (const D3DShaderResourceAttribs& TexUAV) + void OnNewTexUAV(const D3DShaderResourceAttribs& TexUAV) { - VERIFY( TexUAV.BindPoint + TexUAV.BindCount-1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range" ); - Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(TexUAV.BindPoint + TexUAV.BindCount-1)); + VERIFY(TexUAV.BindPoint + TexUAV.BindCount - 1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range"); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(TexUAV.BindPoint + TexUAV.BindCount - 1)); } void OnNewBuffUAV(const D3DShaderResourceAttribs& BuffUAV) { - VERIFY( BuffUAV.BindPoint + BuffUAV.BindCount-1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range" ); - Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(BuffUAV.BindPoint + BuffUAV.BindCount-1)); + VERIFY(BuffUAV.BindPoint + BuffUAV.BindCount - 1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range"); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(BuffUAV.BindPoint + BuffUAV.BindCount - 1)); } void OnNewBuffSRV(const D3DShaderResourceAttribs& BuffSRV) { - VERIFY( BuffSRV.BindPoint + BuffSRV.BindCount-1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range" ); - Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(BuffSRV.BindPoint + BuffSRV.BindCount-1)); + VERIFY(BuffSRV.BindPoint + BuffSRV.BindCount - 1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range"); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(BuffSRV.BindPoint + BuffSRV.BindCount - 1)); } void OnNewSampler(const D3DShaderResourceAttribs& SamplerAttribs) { - VERIFY( SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range" ); - Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1)); + VERIFY(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range"); + Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1)); } - + void OnNewTexSRV(const D3DShaderResourceAttribs& TexAttribs) { - VERIFY( TexAttribs.BindPoint + TexAttribs.BindCount-1 <= MaxAllowedBindPoint, "Tex SRV bind point exceeds supported range" ); - Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(TexAttribs.BindPoint + TexAttribs.BindCount-1)); + VERIFY(TexAttribs.BindPoint + TexAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Tex SRV bind point exceeds supported range"); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(TexAttribs.BindPoint + TexAttribs.BindCount - 1)); } ~NewResourceHandler() @@ -115,8 +117,8 @@ ShaderResourcesD3D11::~ShaderResourcesD3D11() #ifdef DEVELOPMENT static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint) { - VERIFY( BindPoint >= (Uint32)Attr.BindPoint && BindPoint < (Uint32)Attr.BindPoint + Attr.BindCount, "Bind point is out of allowed range"); - if(Attr.BindCount == 1) + VERIFY(BindPoint >= Uint32{Attr.BindPoint} && BindPoint < Uint32{Attr.BindPoint} + Attr.BindCount, "Bind point is out of allowed range"); + if (Attr.BindCount == 1) return Attr.Name; else return String(Attr.Name) + '[' + std::to_string(BindPoint - Attr.BindPoint) + ']'; @@ -128,7 +130,7 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* ID3D11SamplerState* CommittedD3D11Samplers[], ID3D11UnorderedAccessView* CommittedD3D11UAVs[], ID3D11Resource* CommittedD3D11UAVResources[], - ShaderResourceCacheD3D11 &ResourceCache)const + ShaderResourceCacheD3D11& ResourceCache) const { ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; ID3D11Buffer** d3d11CBs = nullptr; @@ -138,116 +140,140 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* ID3D11SamplerState** d3d11Samplers = nullptr; ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr; ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + // clang-format off ResourceCache.GetCBArrays (CachedCBs, d3d11CBs); ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs); ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers); ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs); + // clang-format on ProcessResources( - [&](const D3DShaderResourceAttribs& cb, Uint32) - { + [&](const D3DShaderResourceAttribs& cb, Uint32) // clang-format off + { // clang-format on for (auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetCBCount()) { - LOG_ERROR_MESSAGE( "Unable to find constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount(), " CB slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount(), + " CB slots only. This should never happen and may be the result of using wrong resource cache."); continue; } auto& CB = CachedCBs[BindPoint]; if (CB.pBuff == nullptr) { - LOG_ERROR_MESSAGE( "Constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ", + BindPoint, ") is not initialized in the resource cache."); continue; } if (!(CB.pBuff->GetDesc().BindFlags & BIND_UNIFORM_BUFFER)) { - LOG_ERROR_MESSAGE( "Buffer '", CB.pBuff->GetDesc().Name, "' committed in the device context as constant buffer to variable '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNIFORM_BUFFER flag" ); + LOG_ERROR_MESSAGE("Buffer '", CB.pBuff->GetDesc().Name, + "' committed in the device context as constant buffer to variable '", + DbgMakeResourceName(cb, BindPoint), "' (slot ", BindPoint, + ") in shader '", GetShaderName(), "' was not created with BIND_UNIFORM_BUFFER flag"); continue; } VERIFY_EXPR(d3d11CBs[BindPoint] == CB.pBuff->GetD3D11Buffer()); - if (CommittedD3D11CBs[BindPoint] == nullptr ) + if (CommittedD3D11CBs[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); continue; } - if (CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint] ) + if (CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); continue; } } }, - [&](const D3DShaderResourceAttribs& sam, Uint32) - { + [&](const D3DShaderResourceAttribs& sam, Uint32) // clang-format off + { // clang-format on for (auto BindPoint = sam.BindPoint; BindPoint < sam.BindPoint + sam.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetSamplerCount()) { - LOG_ERROR_MESSAGE( "Unable to find sampler '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount()," Sampler slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount(), + " Sampler slots only. This should never happen and may be the result of using wrong resource cache."); continue; } auto& Sam = CachedSamplers[BindPoint]; if (Sam.pSampler == nullptr) { - LOG_ERROR_MESSAGE( "Sampler '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); continue; } VERIFY_EXPR(d3d11Samplers[BindPoint] == Sam.pSampler->GetD3D11SamplerState()); - if (CommittedD3D11Samplers[BindPoint] == nullptr ) + if (CommittedD3D11Samplers[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 sampler committed to variable '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); continue; } if (CommittedD3D11Samplers[BindPoint] != d3d11Samplers[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 sampler committed to variable '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); continue; } } }, - [&](const D3DShaderResourceAttribs& tex, Uint32) - { - for(auto BindPoint = tex.BindPoint; BindPoint < tex.BindPoint + tex.BindCount; ++BindPoint) + [&](const D3DShaderResourceAttribs& tex, Uint32) // clang-format off + { // clang-format on + for (auto BindPoint = tex.BindPoint; BindPoint < tex.BindPoint + tex.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetSRVCount()) { - LOG_ERROR_MESSAGE( "Unable to find texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find texture SRV '", DbgMakeResourceName(tex, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(), + " SRV slots only. This should never happen and may be the result of using wrong resource cache."); continue; } - auto &SRVRes = CachedSRVResources[BindPoint]; + auto& SRVRes = CachedSRVResources[BindPoint]; if (SRVRes.pBuffer != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, "). Texture is expected." ); + LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(tex, BindPoint), "' (slot ", + BindPoint, "). Texture is expected."); continue; } if (SRVRes.pTexture == nullptr) { - LOG_ERROR_MESSAGE( "Texture '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(tex, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); continue; } if (!(SRVRes.pTexture->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) { - LOG_ERROR_MESSAGE( "Texture '", SRVRes.pTexture->GetDesc().Name, "' committed in the device context as SRV to variable '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag" ); + LOG_ERROR_MESSAGE("Texture '", SRVRes.pTexture->GetDesc().Name, + "' committed in the device context as SRV to variable '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag"); } - if (CommittedD3D11SRVs[BindPoint] == nullptr ) + if (CommittedD3D11SRVs[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); continue; } - if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); continue; } } @@ -260,128 +286,153 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* } }, - [&](const D3DShaderResourceAttribs& uav, Uint32) - { + [&](const D3DShaderResourceAttribs& uav, Uint32) // clang-format off + { // clang-format on for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetUAVCount()) { - LOG_ERROR_MESSAGE( "Unable to find texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find texture UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(), + " UAV slots only. This should never happen and may be the result of using wrong resource cache."); continue; } - auto &UAVRes = CachedUAVResources[BindPoint]; + auto& UAVRes = CachedUAVResources[BindPoint]; if (UAVRes.pBuffer != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, "). Texture is expected." ); + LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, "). Texture is expected."); continue; } if (UAVRes.pTexture == nullptr) { - LOG_ERROR_MESSAGE( "Texture '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); continue; } if (!(UAVRes.pTexture->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) { - LOG_ERROR_MESSAGE( "Texture '", UAVRes.pTexture->GetDesc().Name, "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag" ); + LOG_ERROR_MESSAGE("Texture '", UAVRes.pTexture->GetDesc().Name, + "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag"); } - if (CommittedD3D11UAVs[BindPoint] == nullptr ) + if (CommittedD3D11UAVs[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); continue; } - if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); continue; } } }, - [&](const D3DShaderResourceAttribs& buf, Uint32) - { + [&](const D3DShaderResourceAttribs& buf, Uint32) // clang-format off + { // clang-format on for (auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetSRVCount()) { - LOG_ERROR_MESSAGE( "Unable to find buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find buffer SRV '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(), + " SRV slots only. This should never happen and may be the result of using wrong resource cache."); continue; } auto& SRVRes = CachedSRVResources[BindPoint]; if (SRVRes.pTexture != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected texture bound to variable '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, "). Buffer is expected." ); + LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, "). Buffer is expected."); continue; } if (SRVRes.pBuffer == nullptr) { - LOG_ERROR_MESSAGE( "Buffer '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Buffer '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); continue; } if (!(SRVRes.pBuffer->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) { - LOG_ERROR_MESSAGE( "Buffer '", SRVRes.pBuffer->GetDesc().Name, "' committed in the device context as SRV to variable '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag" ); + LOG_ERROR_MESSAGE("Buffer '", SRVRes.pBuffer->GetDesc().Name, + "' committed in the device context as SRV to variable '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' was not created with BIND_SHADER_RESOURCE flag"); } - if (CommittedD3D11SRVs[BindPoint] == nullptr ) + if (CommittedD3D11SRVs[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); continue; } - if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); continue; } } }, - [&](const D3DShaderResourceAttribs& uav, Uint32) - { - for(auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) + [&](const D3DShaderResourceAttribs& uav, Uint32) // clang-format off + { // clang-format on + for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetUAVCount()) { - LOG_ERROR_MESSAGE( "Unable to find buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE("Unable to find buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(), + " UAV slots only. This should never happen and may be the result of using wrong resource cache."); continue; } - auto &UAVRes = CachedUAVResources[BindPoint]; + auto& UAVRes = CachedUAVResources[BindPoint]; if (UAVRes.pTexture != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected texture bound to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, "). Buffer is expected." ); + LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, "). Buffer is expected."); return; } if (UAVRes.pBuffer == nullptr) { - LOG_ERROR_MESSAGE( "Buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE("Buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); return; } if (!(UAVRes.pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) { - LOG_ERROR_MESSAGE( "Buffer '", UAVRes.pBuffer->GetDesc().Name, "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag" ); + LOG_ERROR_MESSAGE("Buffer '", UAVRes.pBuffer->GetDesc().Name, + "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag"); } - if (CommittedD3D11UAVs[BindPoint] == nullptr ) + if (CommittedD3D11UAVs[BindPoint] == nullptr) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); + LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); return; } - if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE("D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); return; } } - } - ); + } // clang-format off + ); // clang-format on } #endif -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp index e62889ec..003c70c4 100644 --- a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp @@ -31,11 +31,12 @@ namespace Diligent { SwapChainD3D11Impl::SwapChainD3D11Impl(IReferenceCounters* pRefCounters, - const SwapChainDesc& SCDesc, + const SwapChainDesc& SCDesc, const FullScreenModeDesc& FSDesc, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - DeviceContextD3D11Impl* pDeviceContextD3D11, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + DeviceContextD3D11Impl* pDeviceContextD3D11, void* pNativeWndHandle) : + // clang-format off TSwapChainBase { pRefCounters, @@ -45,6 +46,7 @@ SwapChainD3D11Impl::SwapChainD3D11Impl(IReferenceCounters* pRefCounters, FSDesc, pNativeWndHandle } +// clang-format on { auto* pd3d11Device = pRenderDeviceD3D11->GetD3D11Device(); CreateDXGISwapChain(pd3d11Device); @@ -58,16 +60,16 @@ SwapChainD3D11Impl::~SwapChainD3D11Impl() void SwapChainD3D11Impl::CreateRTVandDSV() { auto* pRenderDeviceD3D11Impl = m_pRenderDevice.RawPtr(); - + m_pRenderTargetView.Release(); m_pDepthStencilView.Release(); // Create a render target view CComPtr pd3dBackBuffer; - CHECK_D3D_RESULT_THROW( m_pSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), reinterpret_cast( static_cast(&pd3dBackBuffer) ) ), - "Failed to get back buffer from swap chain" ); + CHECK_D3D_RESULT_THROW(m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast(static_cast(&pd3dBackBuffer))), + "Failed to get back buffer from swap chain"); static const char BackBufferName[] = "Main back buffer"; - auto hr = pd3dBackBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, _countof(BackBufferName)-1, BackBufferName); + auto hr = pd3dBackBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, _countof(BackBufferName) - 1, BackBufferName); DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to set back buffer name"); RefCntAutoPtr pBackBuffer; @@ -79,7 +81,7 @@ void SwapChainD3D11Impl::CreateRTVandDSV() RefCntAutoPtr pRTV; pBackBuffer->CreateView(RTVDesc, &pRTV); m_pRenderTargetView = RefCntAutoPtr(pRTV, IID_TextureViewD3D11); - + if (m_SwapChainDesc.DepthBufferFormat != TEX_FORMAT_UNKNOWN) { // Create depth buffer @@ -99,23 +101,23 @@ void SwapChainD3D11Impl::CreateRTVandDSV() RefCntAutoPtr ptex2DDepthBuffer; m_pRenderDevice->CreateTexture(DepthBufferDesc, nullptr, &ptex2DDepthBuffer); - auto pDSV = ptex2DDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); + auto pDSV = ptex2DDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); m_pDepthStencilView = RefCntAutoPtr(pDSV, IID_TextureViewD3D11); } } -IMPLEMENT_QUERY_INTERFACE( SwapChainD3D11Impl, IID_SwapChainD3D11, TSwapChainBase ) +IMPLEMENT_QUERY_INTERFACE(SwapChainD3D11Impl, IID_SwapChainD3D11, TSwapChainBase) void SwapChainD3D11Impl::Present(Uint32 SyncInterval) { #if PLATFORM_UNIVERSAL_WINDOWS - SyncInterval = 1; // Interval 0 is not supported on Windows Phone + SyncInterval = 1; // Interval 0 is not supported on Windows Phone #endif auto pDeviceContext = m_wpDeviceContext.Lock(); if (!pDeviceContext) { - LOG_ERROR_MESSAGE( "Immediate context has been released" ); + LOG_ERROR_MESSAGE("Immediate context has been released"); return; } @@ -136,7 +138,7 @@ void SwapChainD3D11Impl::Present(Uint32 SyncInterval) if (m_SwapChainDesc.IsPrimary) { - // A successful Present call for DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL SwapChains unbinds + // A successful Present call for DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL SwapChains unbinds // backbuffer 0 from all GPU writeable bind points. // We need to rebind all render targets to make sure that // the back buffer is not unbound @@ -148,16 +150,16 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew) { // When switching to full screen mode, WM_SIZE is send to the window // and Resize() is called before the new swap chain is created - if(!m_pSwapChain) + if (!m_pSwapChain) return; auto pDeviceContext = m_wpDeviceContext.Lock(); VERIFY(pDeviceContext, "Immediate context has been released"); if (pDeviceContext) { - auto* pImmediateCtxD3D11 = pDeviceContext.RawPtr(); - ITextureView* pBackBufferRTVs[] = {m_pRenderTargetView}; - bool RebindRenderTargets = UnbindRenderTargets(pImmediateCtxD3D11, pBackBufferRTVs, 1, m_pDepthStencilView); + auto* pImmediateCtxD3D11 = pDeviceContext.RawPtr(); + ITextureView* pBackBufferRTVs[] = {m_pRenderTargetView}; + bool RebindRenderTargets = UnbindRenderTargets(pImmediateCtxD3D11, pBackBufferRTVs, 1, m_pDepthStencilView); // Swap chain cannot be resized until all references are released m_pRenderTargetView.Release(); @@ -165,13 +167,13 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew) try { - if(CreateNew) + if (CreateNew) { m_pSwapChain.Release(); // Only one flip presentation model swap chain can be associated with an HWND. // We must make sure that the swap chain is actually released by D3D11 before creating a new one. - // To force the destruction, we need to ensure no views are bound to pipeline state, and then call Flush + // To force the destruction, we need to ensure no views are bound to pipeline state, and then call Flush // on the immediate context. Dstruction must be forced before calling IDXGIFactory2::CreateSwapChainForHwnd(), or // IDXGIFactory2::CreateSwapChainForCoreWindow() again to create a new swap chain. // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476425(v=vs.85).aspx#Defer_Issues_with_Flip @@ -186,10 +188,10 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew) memset(&SCDes, 0, sizeof(SCDes)); m_pSwapChain->GetDesc(&SCDes); CHECK_D3D_RESULT_THROW(m_pSwapChain->ResizeBuffers(SCDes.BufferCount, m_SwapChainDesc.Width, - m_SwapChainDesc.Height, SCDes.BufferDesc.Format, - SCDes.Flags), - "Failed to resize the DXGI swap chain"); - + m_SwapChainDesc.Height, SCDes.BufferDesc.Format, + SCDes.Flags), + "Failed to resize the DXGI swap chain"); + // Call flush to release resources pImmediateCtxD3D11->Flush(); } @@ -203,19 +205,19 @@ void SwapChainD3D11Impl::UpdateSwapChain(bool CreateNew) pImmediateCtxD3D11->SetViewports(1, nullptr, 0, 0); } } - catch (const std::runtime_error &) + catch (const std::runtime_error&) { LOG_ERROR("Failed to resize the swap chain"); } } } -void SwapChainD3D11Impl::Resize( Uint32 NewWidth, Uint32 NewHeight ) +void SwapChainD3D11Impl::Resize(Uint32 NewWidth, Uint32 NewHeight) { - if( TSwapChainBase::Resize(NewWidth, NewHeight) ) + if (TSwapChainBase::Resize(NewWidth, NewHeight)) { UpdateSwapChain(false); } } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp index 63c64240..d8898956 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp @@ -29,11 +29,12 @@ namespace Diligent { -Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/) : +Texture1D_D3D11 ::Texture1D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/) : + // clang-format off TextureBaseD3D11 { pRefCounters, @@ -42,14 +43,16 @@ Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters* pRefCounters, TexDesc, pInitData } +// clang-format on { - auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); - auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); - auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); - auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); - UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); - auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); - + auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); + auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); + auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); + auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); + UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); + auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + + // clang-format off D3D11_TEXTURE1D_DESC Tex1DDesc = { m_Desc.Width, @@ -61,14 +64,15 @@ Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters* pRefCounters, D3D11CPUAccessFlags, MiscFlags }; + // clang-format on - std::vector> D3D11InitData( STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector") ); + std::vector> D3D11InitData(STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector")); PrepareD3D11InitData(pInitData, Tex1DDesc.ArraySize * Tex1DDesc.MipLevels, D3D11InitData); - ID3D11Texture1D *ptex1D = nullptr; - HRESULT hr = pDeviceD3D11->CreateTexture1D(&Tex1DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex1D); + ID3D11Texture1D* ptex1D = nullptr; + HRESULT hr = pDeviceD3D11->CreateTexture1D(&Tex1DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex1D); m_pd3d11Texture.Attach(ptex1D); - CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture1D" ); + CHECK_D3D_RESULT_THROW(hr, "Failed to create the Direct3D11 Texture1D"); if (*m_Desc.Name != 0) { @@ -83,18 +87,18 @@ namespace class TexDescFromD3D11Texture1D { public: - TextureDesc operator() (ID3D11Texture1D* pd3d11Texture) + TextureDesc operator()(ID3D11Texture1D* pd3d11Texture) { D3D11_TEXTURE1D_DESC D3D11TexDesc; pd3d11Texture->GetDesc(&D3D11TexDesc); - + TextureDesc TexDesc; UINT DataSize = 0; pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, nullptr); if (DataSize > 0) { - ObjectName.resize(DataSize+1); // Null terminator is not reported in DataSize + ObjectName.resize(DataSize + 1); // Null terminator is not reported in DataSize pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, ObjectName.data()); TexDesc.Name = ObjectName.data(); } @@ -120,32 +124,32 @@ private: std::vector ObjectName; }; -} +} // namespace -Texture1D_D3D11 :: Texture1D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pDeviceD3D11, - RESOURCE_STATE InitialState, - ID3D11Texture1D* pd3d11Texture) : - TextureBaseD3D11(pRefCounters, TexViewObjAllocator, pDeviceD3D11, TexDescFromD3D11Texture1D{}(pd3d11Texture), nullptr) +Texture1D_D3D11 ::Texture1D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pDeviceD3D11, + RESOURCE_STATE InitialState, + ID3D11Texture1D* pd3d11Texture) : + TextureBaseD3D11{pRefCounters, TexViewObjAllocator, pDeviceD3D11, TexDescFromD3D11Texture1D{}(pd3d11Texture), nullptr} { m_pd3d11Texture = pd3d11Texture; SetState(InitialState); } -Texture1D_D3D11 :: ~Texture1D_D3D11() +Texture1D_D3D11 ::~Texture1D_D3D11() { } -void Texture1D_D3D11::CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV ) +void Texture1D_D3D11::CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) { - VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" ); - - VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" ); - if( !(SRVDesc.TextureDim == RESOURCE_DIM_TEX_1D || SRVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY) ) - LOG_ERROR_AND_THROW( "Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed" ); - - if( SRVDesc.Format == TEX_FORMAT_UNKNOWN ) + VERIFY(ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object"); + + VERIFY(SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected"); + if (!(SRVDesc.TextureDim == RESOURCE_DIM_TEX_1D || SRVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY)) + LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed"); + + if (SRVDesc.Format == TEX_FORMAT_UNKNOWN) { SRVDesc.Format = m_Desc.Format; } @@ -153,20 +157,20 @@ void Texture1D_D3D11::CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceV D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc; TextureViewDesc_to_D3D11_SRV_DESC(SRVDesc, D3D11_SRVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ), - "Failed to create D3D11 shader resource view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateShaderResourceView(m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV), + "Failed to create D3D11 shader resource view"); } -void Texture1D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV ) +void Texture1D_D3D11::CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) { - VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" ); - - VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" ); - if( !(RTVDesc.TextureDim == RESOURCE_DIM_TEX_1D || RTVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY ) ) - LOG_ERROR_AND_THROW( "Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed" ); + VERIFY(ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object"); + + VERIFY(RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected"); + if (!(RTVDesc.TextureDim == RESOURCE_DIM_TEX_1D || RTVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY)) + LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed"); - if( RTVDesc.Format == TEX_FORMAT_UNKNOWN ) + if (RTVDesc.Format == TEX_FORMAT_UNKNOWN) { RTVDesc.Format = m_Desc.Format; } @@ -174,20 +178,20 @@ void Texture1D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetVie D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc; TextureViewDesc_to_D3D11_RTV_DESC(RTVDesc, D3D11_RTVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ), - "Failed to create D3D11 render target view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateRenderTargetView(m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV), + "Failed to create D3D11 render target view"); } -void Texture1D_D3D11::CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV ) +void Texture1D_D3D11::CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) { - VERIFY( ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object"); - VERIFY( DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" ); - if( !(DSVDesc.TextureDim == RESOURCE_DIM_TEX_1D || DSVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY) ) + VERIFY(DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected"); + if (!(DSVDesc.TextureDim == RESOURCE_DIM_TEX_1D || DSVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY)) LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed"); - if( DSVDesc.Format == TEX_FORMAT_UNKNOWN ) + if (DSVDesc.Format == TEX_FORMAT_UNKNOWN) { DSVDesc.Format = m_Desc.Format; } @@ -195,20 +199,20 @@ void Texture1D_D3D11::CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilVie D3D11_DEPTH_STENCIL_VIEW_DESC D3D11_DSVDesc; TextureViewDesc_to_D3D11_DSV_DESC(DSVDesc, D3D11_DSVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilView( m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV ), - "Failed to create D3D11 depth stencil view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateDepthStencilView(m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV), + "Failed to create D3D11 depth stencil view"); } -void Texture1D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ) +void Texture1D_D3D11::CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) { - VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object"); - VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" ); - if( !(UAVDesc.TextureDim == RESOURCE_DIM_TEX_1D || UAVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY) ) + VERIFY(UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected"); + if (!(UAVDesc.TextureDim == RESOURCE_DIM_TEX_1D || UAVDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY)) LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_1D or RESOURCE_DIM_TEX_1D_ARRAY is allowed"); - - if( UAVDesc.Format == TEX_FORMAT_UNKNOWN ) + + if (UAVDesc.Format == TEX_FORMAT_UNKNOWN) { UAVDesc.Format = m_Desc.Format; } @@ -216,9 +220,9 @@ void Texture1D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccess D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc; TextureViewDesc_to_D3D11_UAV_DESC(UAVDesc, D3D11_UAVDesc); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ), - "Failed to create D3D11 unordered access view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateUnorderedAccessView(m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV), + "Failed to create D3D11 unordered access view"); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp index 072af44f..e60ab2a2 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp @@ -29,11 +29,12 @@ namespace Diligent { -Texture2D_D3D11 :: Texture2D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/) : +Texture2D_D3D11 ::Texture2D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/) : + // clang-format off TextureBaseD3D11 { pRefCounters, @@ -42,20 +43,22 @@ Texture2D_D3D11 :: Texture2D_D3D11(IReferenceCounters* pRefCounters, TexDesc, pInitData } +// clang-format on { - auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); - auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); + auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); + auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); - auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); - UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); + auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); + UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); if (MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) D3D11BindFlags |= D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - if(m_Desc.Type == RESOURCE_DIM_TEX_CUBE || m_Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + if (m_Desc.Type == RESOURCE_DIM_TEX_CUBE || m_Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; DXGI_SAMPLE_DESC D3D11SampleDesc = {m_Desc.SampleCount, 0}; - auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + // clang-format off D3D11_TEXTURE2D_DESC Tex2DDesc = { m_Desc.Width, @@ -69,14 +72,15 @@ Texture2D_D3D11 :: Texture2D_D3D11(IReferenceCounters* pRefCounters, D3D11CPUAccessFlags, MiscFlags }; - - std::vector> D3D11InitData( STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector") ); + // clang-format on + + std::vector> D3D11InitData(STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector")); PrepareD3D11InitData(pInitData, Tex2DDesc.ArraySize * Tex2DDesc.MipLevels, D3D11InitData); - ID3D11Texture2D *ptex2D = nullptr; - HRESULT hr = pDeviceD3D11->CreateTexture2D(&Tex2DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex2D); + ID3D11Texture2D* ptex2D = nullptr; + HRESULT hr = pDeviceD3D11->CreateTexture2D(&Tex2DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex2D); m_pd3d11Texture.Attach(ptex2D); - CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture2D" ); + CHECK_D3D_RESULT_THROW(hr, "Failed to create the Direct3D11 Texture2D"); if (*m_Desc.Name != 0) { @@ -91,17 +95,17 @@ namespace class TexDescFromD3D11Texture2D { public: - TextureDesc operator ()(ID3D11Texture2D* pd3d11Texture) + TextureDesc operator()(ID3D11Texture2D* pd3d11Texture) { D3D11_TEXTURE2D_DESC D3D11TexDesc; pd3d11Texture->GetDesc(&D3D11TexDesc); TextureDesc TexDesc; - UINT DataSize = 0; + UINT DataSize = 0; pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, nullptr); if (DataSize > 0) { - ObjectName.resize(DataSize+1); // Null terminator is not reported in DataSize + ObjectName.resize(DataSize + 1); // Null terminator is not reported in DataSize pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, ObjectName.data()); TexDesc.Name = ObjectName.data(); } @@ -127,13 +131,14 @@ private: std::vector ObjectName; }; -} +} // namespace -Texture2D_D3D11 :: Texture2D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pDeviceD3D11, - RESOURCE_STATE InitialState, - ID3D11Texture2D* pd3d11Texture) : +Texture2D_D3D11 ::Texture2D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pDeviceD3D11, + RESOURCE_STATE InitialState, + ID3D11Texture2D* pd3d11Texture) : + // clang-format off TextureBaseD3D11 { pRefCounters, @@ -142,25 +147,26 @@ Texture2D_D3D11 :: Texture2D_D3D11(IReferenceCounters* pRefCounters, TexDescFromD3D11Texture2D{}(pd3d11Texture), nullptr } +// clang-format on { m_pd3d11Texture = pd3d11Texture; SetState(InitialState); } -Texture2D_D3D11 :: ~Texture2D_D3D11() +Texture2D_D3D11 ::~Texture2D_D3D11() { } -void Texture2D_D3D11::CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV ) +void Texture2D_D3D11::CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) { - VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object"); - VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" ); - if( !(SRVDesc.TextureDim == RESOURCE_DIM_TEX_2D || SRVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY || - SRVDesc.TextureDim == RESOURCE_DIM_TEX_CUBE || SRVDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY) ) + VERIFY(SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected"); + if (!(SRVDesc.TextureDim == RESOURCE_DIM_TEX_2D || SRVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY || + SRVDesc.TextureDim == RESOURCE_DIM_TEX_CUBE || SRVDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY)) LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_2D, RESOURCE_DIM_TEX_2D_ARRAY, RESOURCE_DIM_TEX_CUBE, or RESOURCE_DIM_TEX_CUBE_ARRAY is allowed"); - if( SRVDesc.Format == TEX_FORMAT_UNKNOWN ) + if (SRVDesc.Format == TEX_FORMAT_UNKNOWN) { SRVDesc.Format = m_Desc.Format; } @@ -168,20 +174,20 @@ void Texture2D_D3D11::CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceV D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc; TextureViewDesc_to_D3D11_SRV_DESC(SRVDesc, D3D11_SRVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ), - "Failed to create D3D11 shader resource view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateShaderResourceView(m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV), + "Failed to create D3D11 shader resource view"); } -void Texture2D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV ) +void Texture2D_D3D11::CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) { - VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object"); + + VERIFY(RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected"); + if (!(RTVDesc.TextureDim == RESOURCE_DIM_TEX_2D || RTVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY)) + LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_2D or RESOURCE_DIM_TEX_2D_ARRAY is allowed"); - VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" ); - if( !(RTVDesc.TextureDim == RESOURCE_DIM_TEX_2D || RTVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY) ) - LOG_ERROR_AND_THROW( "Unsupported texture type. Only RESOURCE_DIM_TEX_2D or RESOURCE_DIM_TEX_2D_ARRAY is allowed" ); - - if( RTVDesc.Format == TEX_FORMAT_UNKNOWN ) + if (RTVDesc.Format == TEX_FORMAT_UNKNOWN) { RTVDesc.Format = m_Desc.Format; } @@ -189,20 +195,20 @@ void Texture2D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetVie D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc; TextureViewDesc_to_D3D11_RTV_DESC(RTVDesc, D3D11_RTVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ), - "Failed to create D3D11 render target view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateRenderTargetView(m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV), + "Failed to create D3D11 render target view"); } -void Texture2D_D3D11::CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV ) +void Texture2D_D3D11::CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) { - VERIFY( ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object" ); - - VERIFY( DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" ); - if( !(DSVDesc.TextureDim == RESOURCE_DIM_TEX_2D || DSVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY) ) + VERIFY(ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object"); + + VERIFY(DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected"); + if (!(DSVDesc.TextureDim == RESOURCE_DIM_TEX_2D || DSVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY)) LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_2D or RESOURCE_DIM_TEX_2D_ARRAY is allowed"); - - if( DSVDesc.Format == TEX_FORMAT_UNKNOWN ) + + if (DSVDesc.Format == TEX_FORMAT_UNKNOWN) { DSVDesc.Format = m_Desc.Format; } @@ -210,23 +216,23 @@ void Texture2D_D3D11::CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilVie D3D11_DEPTH_STENCIL_VIEW_DESC D3D11_DSVDesc; TextureViewDesc_to_D3D11_DSV_DESC(DSVDesc, D3D11_DSVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilView( m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV ), - "Failed to create D3D11 depth stencil view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateDepthStencilView(m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV), + "Failed to create D3D11 depth stencil view"); } -void Texture2D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ) +void Texture2D_D3D11::CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) { - VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object"); - if( m_Desc.SampleCount > 1 ) + if (m_Desc.SampleCount > 1) LOG_ERROR_AND_THROW("UAVs are not allowed for multisampled resources"); - VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" ); - if( !(UAVDesc.TextureDim == RESOURCE_DIM_TEX_2D || UAVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY) ) - LOG_ERROR_AND_THROW( "Unsupported texture type. Only RESOURCE_DIM_TEX_2D or RESOURCE_DIM_TEX_2D_ARRAY is allowed" ); + VERIFY(UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected"); + if (!(UAVDesc.TextureDim == RESOURCE_DIM_TEX_2D || UAVDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY)) + LOG_ERROR_AND_THROW("Unsupported texture type. Only RESOURCE_DIM_TEX_2D or RESOURCE_DIM_TEX_2D_ARRAY is allowed"); - if( UAVDesc.Format == TEX_FORMAT_UNKNOWN ) + if (UAVDesc.Format == TEX_FORMAT_UNKNOWN) { UAVDesc.Format = m_Desc.Format; } @@ -234,9 +240,9 @@ void Texture2D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccess D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc; TextureViewDesc_to_D3D11_UAV_DESC(UAVDesc, D3D11_UAVDesc); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ), - "Failed to create D3D11 unordered access view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateUnorderedAccessView(m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV), + "Failed to create D3D11 unordered access view"); } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp index 8b9153c3..65dbaf46 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp @@ -29,11 +29,12 @@ namespace Diligent { -Texture3D_D3D11 :: Texture3D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/) : +Texture3D_D3D11 ::Texture3D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/) : + // clang-format off TextureBaseD3D11 { pRefCounters, @@ -42,14 +43,16 @@ Texture3D_D3D11 :: Texture3D_D3D11(IReferenceCounters* pRefCounters, TexDesc, pInitData } +// clang-format on { - auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); - auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); - auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); - auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); - UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); - auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); - + auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags); + auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags); + auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags); + auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage); + UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags); + auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); + + // clang-format off D3D11_TEXTURE3D_DESC Tex3DDesc = { m_Desc.Width, @@ -62,14 +65,15 @@ Texture3D_D3D11 :: Texture3D_D3D11(IReferenceCounters* pRefCounters, D3D11CPUAccessFlags, MiscFlags }; + // clang-format on - std::vector> D3D11InitData( STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector") ); + std::vector> D3D11InitData(STD_ALLOCATOR_RAW_MEM(D3D11_SUBRESOURCE_DATA, GetRawAllocator(), "Allocator for vector")); PrepareD3D11InitData(pInitData, Tex3DDesc.MipLevels, D3D11InitData); - ID3D11Texture3D *ptex3D = nullptr; - HRESULT hr = pDeviceD3D11->CreateTexture3D(&Tex3DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex3D); + ID3D11Texture3D* ptex3D = nullptr; + HRESULT hr = pDeviceD3D11->CreateTexture3D(&Tex3DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex3D); m_pd3d11Texture.Attach(ptex3D); - CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture3D" ); + CHECK_D3D_RESULT_THROW(hr, "Failed to create the Direct3D11 Texture3D"); if (*m_Desc.Name != 0) { @@ -84,17 +88,17 @@ namespace class TexDescFromD3D11Texture3D { public: - TextureDesc operator() (ID3D11Texture3D* pd3d11Texture) + TextureDesc operator()(ID3D11Texture3D* pd3d11Texture) { D3D11_TEXTURE3D_DESC D3D11TexDesc; pd3d11Texture->GetDesc(&D3D11TexDesc); TextureDesc TexDesc; - UINT DataSize = 0; + UINT DataSize = 0; pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, nullptr); if (DataSize > 0) { - ObjectName.resize(DataSize+1); // Null terminator is not reported in + ObjectName.resize(DataSize + 1); // Null terminator is not reported in pd3d11Texture->GetPrivateData(WKPDID_D3DDebugObjectName, &DataSize, ObjectName.data()); TexDesc.Name = ObjectName.data(); } @@ -115,17 +119,19 @@ public: return TexDesc; } + private: std::vector ObjectName; }; -} +} // namespace -Texture3D_D3D11 :: Texture3D_D3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pDeviceD3D11, - RESOURCE_STATE InitialState, - ID3D11Texture3D* pd3d11Texture) : +Texture3D_D3D11 ::Texture3D_D3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pDeviceD3D11, + RESOURCE_STATE InitialState, + ID3D11Texture3D* pd3d11Texture) : + // clang-format off TextureBaseD3D11 { pRefCounters, @@ -134,20 +140,21 @@ Texture3D_D3D11 :: Texture3D_D3D11(IReferenceCounters* pRefCounters, TexDescFromD3D11Texture3D{}(pd3d11Texture), nullptr } +// clang-format on { m_pd3d11Texture = pd3d11Texture; SetState(InitialState); } -void Texture3D_D3D11::CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV ) +void Texture3D_D3D11::CreateSRV(TextureViewDesc& SRVDesc, ID3D11ShaderResourceView** ppD3D11SRV) { - VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" ); - - VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" ); - if( SRVDesc.TextureDim != RESOURCE_DIM_TEX_3D ) + VERIFY(ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object"); + + VERIFY(SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected"); + if (SRVDesc.TextureDim != RESOURCE_DIM_TEX_3D) LOG_ERROR_AND_THROW("Unsupported texture view type. Only RESOURCE_DIM_TEX_3D is allowed"); - - if( SRVDesc.Format == TEX_FORMAT_UNKNOWN ) + + if (SRVDesc.Format == TEX_FORMAT_UNKNOWN) { SRVDesc.Format = m_Desc.Format; } @@ -155,20 +162,20 @@ void Texture3D_D3D11::CreateSRV( TextureViewDesc& SRVDesc, ID3D11ShaderResourceV D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc; TextureViewDesc_to_D3D11_SRV_DESC(SRVDesc, D3D11_SRVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ), - "Failed to create D3D11 shader resource view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateShaderResourceView(m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV), + "Failed to create D3D11 shader resource view"); } -void Texture3D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV ) +void Texture3D_D3D11::CreateRTV(TextureViewDesc& RTVDesc, ID3D11RenderTargetView** ppD3D11RTV) { - VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object"); - VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" ); - if( RTVDesc.TextureDim != RESOURCE_DIM_TEX_3D ) - LOG_ERROR_AND_THROW( "Unsupported texture view type. Only RESOURCE_DIM_TEX_3D is allowed" ); - - if( RTVDesc.Format == TEX_FORMAT_UNKNOWN ) + VERIFY(RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected"); + if (RTVDesc.TextureDim != RESOURCE_DIM_TEX_3D) + LOG_ERROR_AND_THROW("Unsupported texture view type. Only RESOURCE_DIM_TEX_3D is allowed"); + + if (RTVDesc.Format == TEX_FORMAT_UNKNOWN) { RTVDesc.Format = m_Desc.Format; } @@ -176,25 +183,25 @@ void Texture3D_D3D11::CreateRTV( TextureViewDesc& RTVDesc, ID3D11RenderTargetVie D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc; TextureViewDesc_to_D3D11_RTV_DESC(RTVDesc, D3D11_RTVDesc, m_Desc.SampleCount); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ), - "Failed to create D3D11 render target view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateRenderTargetView(m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV), + "Failed to create D3D11 render target view"); } -void Texture3D_D3D11::CreateDSV( TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV ) +void Texture3D_D3D11::CreateDSV(TextureViewDesc& DSVDesc, ID3D11DepthStencilView** ppD3D11DSV) { LOG_ERROR_AND_THROW("Depth stencil views are not supported for 3D textures"); } -void Texture3D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV ) +void Texture3D_D3D11::CreateUAV(TextureViewDesc& UAVDesc, ID3D11UnorderedAccessView** ppD3D11UAV) { - VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" ); + VERIFY(ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object"); - VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" ); - if( UAVDesc.TextureDim != RESOURCE_DIM_TEX_3D ) + VERIFY(UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected"); + if (UAVDesc.TextureDim != RESOURCE_DIM_TEX_3D) LOG_ERROR_AND_THROW("Unsupported texture view type. Only RESOURCE_DIM_TEX_3D is allowed"); - - if( UAVDesc.Format == TEX_FORMAT_UNKNOWN ) + + if (UAVDesc.Format == TEX_FORMAT_UNKNOWN) { UAVDesc.Format = m_Desc.Format; } @@ -202,14 +209,14 @@ void Texture3D_D3D11::CreateUAV( TextureViewDesc& UAVDesc, ID3D11UnorderedAccess D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc; TextureViewDesc_to_D3D11_UAV_DESC(UAVDesc, D3D11_UAVDesc); - auto *pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); - CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ), - "Failed to create D3D11 unordered access view"); + auto* pDeviceD3D11 = static_cast(GetDevice())->GetD3D11Device(); + CHECK_D3D_RESULT_THROW(pDeviceD3D11->CreateUnorderedAccessView(m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV), + "Failed to create D3D11 unordered access view"); } -Texture3D_D3D11 :: ~Texture3D_D3D11() +Texture3D_D3D11 ::~Texture3D_D3D11() { } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp index b35132aa..3ffb65bd 100644 --- a/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp @@ -32,11 +32,12 @@ namespace Diligent { -TextureBaseD3D11 :: TextureBaseD3D11(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const TextureDesc& TexDesc, - const TextureData* pInitData /*= nullptr*/) : +TextureBaseD3D11 ::TextureBaseD3D11(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceD3D11Impl* pRenderDeviceD3D11, + const TextureDesc& TexDesc, + const TextureData* pInitData /*= nullptr*/) : + // clang-format off TTextureBase { pRefCounters, @@ -44,6 +45,7 @@ TextureBaseD3D11 :: TextureBaseD3D11(IReferenceCounters* pRefCounters, pRenderDeviceD3D11, TexDesc } +// clang-format on { if (m_Desc.Usage == USAGE_STATIC && (pInitData == nullptr || pInitData->pSubResources == nullptr)) LOG_ERROR_AND_THROW("Static textures must be initialized with data at creation time: pInitData can't be null"); @@ -51,109 +53,108 @@ TextureBaseD3D11 :: TextureBaseD3D11(IReferenceCounters* pRefCounters, SetState(RESOURCE_STATE_UNDEFINED); } -IMPLEMENT_QUERY_INTERFACE( TextureBaseD3D11, IID_TextureD3D11, TTextureBase ) +IMPLEMENT_QUERY_INTERFACE(TextureBaseD3D11, IID_TextureD3D11, TTextureBase) -void TextureBaseD3D11::CreateViewInternal( const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView ) +void TextureBaseD3D11::CreateViewInternal(const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView) { - VERIFY( ppView != nullptr, "View pointer address is null" ); - if( !ppView )return; - VERIFY(* ppView == nullptr, "Overwriting reference to existing object may cause memory leaks" ); - - *ppView = nullptr; + VERIFY(ppView != nullptr, "View pointer address is null"); + if (!ppView) return; + VERIFY(*ppView == nullptr, "Overwriting reference to existing object may cause memory leaks"); + + *ppView = nullptr; try { auto UpdatedViewDesc = ViewDesc; - CorrectTextureViewDesc( UpdatedViewDesc ); + CorrectTextureViewDesc(UpdatedViewDesc); RefCntAutoPtr pD3D11View; - switch( ViewDesc.ViewType ) + switch (ViewDesc.ViewType) { case TEXTURE_VIEW_SHADER_RESOURCE: { - VERIFY( m_Desc.BindFlags & BIND_SHADER_RESOURCE, "BIND_SHADER_RESOURCE flag is not set" ); + VERIFY(m_Desc.BindFlags & BIND_SHADER_RESOURCE, "BIND_SHADER_RESOURCE flag is not set"); ID3D11ShaderResourceView* pSRV = nullptr; - CreateSRV( UpdatedViewDesc, &pSRV ); - pD3D11View.Attach( pSRV ); + CreateSRV(UpdatedViewDesc, &pSRV); + pD3D11View.Attach(pSRV); } break; case TEXTURE_VIEW_RENDER_TARGET: { - VERIFY( m_Desc.BindFlags & BIND_RENDER_TARGET, "BIND_RENDER_TARGET flag is not set" ); + VERIFY(m_Desc.BindFlags & BIND_RENDER_TARGET, "BIND_RENDER_TARGET flag is not set"); ID3D11RenderTargetView* pRTV = nullptr; - CreateRTV( UpdatedViewDesc, &pRTV ); - pD3D11View.Attach( pRTV ); + CreateRTV(UpdatedViewDesc, &pRTV); + pD3D11View.Attach(pRTV); } break; case TEXTURE_VIEW_DEPTH_STENCIL: { - VERIFY( m_Desc.BindFlags & BIND_DEPTH_STENCIL, "BIND_DEPTH_STENCIL is not set" ); + VERIFY(m_Desc.BindFlags & BIND_DEPTH_STENCIL, "BIND_DEPTH_STENCIL is not set"); ID3D11DepthStencilView* pDSV = nullptr; - CreateDSV( UpdatedViewDesc, &pDSV ); - pD3D11View.Attach( pDSV ); + CreateDSV(UpdatedViewDesc, &pDSV); + pD3D11View.Attach(pDSV); } break; case TEXTURE_VIEW_UNORDERED_ACCESS: { - VERIFY( m_Desc.BindFlags & BIND_UNORDERED_ACCESS, "BIND_UNORDERED_ACCESS flag is not set" ); + VERIFY(m_Desc.BindFlags & BIND_UNORDERED_ACCESS, "BIND_UNORDERED_ACCESS flag is not set"); ID3D11UnorderedAccessView* pUAV = nullptr; - CreateUAV( UpdatedViewDesc, &pUAV ); - pD3D11View.Attach( pUAV ); + CreateUAV(UpdatedViewDesc, &pUAV); + pD3D11View.Attach(pUAV); } break; - default: UNEXPECTED( "Unknown view type" ); break; + default: UNEXPECTED("Unknown view type"); break; } auto* pDeviceD3D11Impl = ValidatedCast(GetDevice()); - auto &TexViewAllocator = pDeviceD3D11Impl->GetTexViewObjAllocator(); - VERIFY( &TexViewAllocator == &m_dbgTexViewObjAllocator, "Texture view allocator does not match allocator provided during texture initialization" ); + auto& TexViewAllocator = pDeviceD3D11Impl->GetTexViewObjAllocator(); + VERIFY(&TexViewAllocator == &m_dbgTexViewObjAllocator, "Texture view allocator does not match allocator provided during texture initialization"); - auto pViewD3D11 = NEW_RC_OBJ(TexViewAllocator, "TextureViewD3D11Impl instance", TextureViewD3D11Impl, bIsDefaultView ? this : nullptr) - (pDeviceD3D11Impl, UpdatedViewDesc, this, pD3D11View, bIsDefaultView ); - VERIFY( pViewD3D11->GetDesc().ViewType == ViewDesc.ViewType, "Incorrect view type" ); + auto pViewD3D11 = NEW_RC_OBJ(TexViewAllocator, "TextureViewD3D11Impl instance", TextureViewD3D11Impl, bIsDefaultView ? this : nullptr)(pDeviceD3D11Impl, UpdatedViewDesc, this, pD3D11View, bIsDefaultView); + VERIFY(pViewD3D11->GetDesc().ViewType == ViewDesc.ViewType, "Incorrect view type"); - if( bIsDefaultView ) - * ppView = pViewD3D11; + if (bIsDefaultView) + *ppView = pViewD3D11; else - pViewD3D11->QueryInterface(IID_TextureView, reinterpret_cast(ppView) ); + pViewD3D11->QueryInterface(IID_TextureView, reinterpret_cast(ppView)); } - catch( const std::runtime_error & ) + catch (const std::runtime_error&) { - const auto *ViewTypeName = GetTexViewTypeLiteralName(ViewDesc.ViewType); - LOG_ERROR("Failed to create view \"", ViewDesc.Name ? ViewDesc.Name : "", "\" (", ViewTypeName, ") for texture \"", m_Desc.Name ? m_Desc.Name : "", "\"" ); + const auto* ViewTypeName = GetTexViewTypeLiteralName(ViewDesc.ViewType); + LOG_ERROR("Failed to create view \"", ViewDesc.Name ? ViewDesc.Name : "", "\" (", ViewTypeName, ") for texture \"", m_Desc.Name ? m_Desc.Name : "", "\""); } } -void TextureBaseD3D11 :: PrepareD3D11InitData(const TextureData* pInitData, - Uint32 NumSubresources, - std::vector > & D3D11InitData) +void TextureBaseD3D11 ::PrepareD3D11InitData(const TextureData* pInitData, + Uint32 NumSubresources, + std::vector>& D3D11InitData) { if (pInitData != nullptr && pInitData->pSubResources != nullptr) { - if( NumSubresources == pInitData->NumSubresources ) + if (NumSubresources == pInitData->NumSubresources) { D3D11InitData.resize(NumSubresources); - for(UINT Subres=0; Subres < NumSubresources; ++Subres) + for (UINT Subres = 0; Subres < NumSubresources; ++Subres) { - auto &CurrSubres = pInitData->pSubResources[Subres]; - D3D11InitData[Subres].pSysMem = CurrSubres.pData; - D3D11InitData[Subres].SysMemPitch = CurrSubres.Stride; + auto& CurrSubres = pInitData->pSubResources[Subres]; + D3D11InitData[Subres].pSysMem = CurrSubres.pData; + D3D11InitData[Subres].SysMemPitch = CurrSubres.Stride; D3D11InitData[Subres].SysMemSlicePitch = CurrSubres.DepthStride; } } else { - UNEXPECTED( "Incorrect number of subrsources" ); + UNEXPECTED("Incorrect number of subrsources"); } } } -TextureBaseD3D11 :: ~TextureBaseD3D11() +TextureBaseD3D11 ::~TextureBaseD3D11() { } -} +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp index 362ed080..e5bd34fd 100644 --- a/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp @@ -28,12 +28,13 @@ namespace Diligent { -TextureViewD3D11Impl::TextureViewD3D11Impl( IReferenceCounters* pRefCounters, - RenderDeviceD3D11Impl* pDevice, - const TextureViewDesc& ViewDesc, - ITexture* pTexture, - ID3D11View* pD3D11View, - bool bIsDefaultView ) : +TextureViewD3D11Impl::TextureViewD3D11Impl(IReferenceCounters* pRefCounters, + RenderDeviceD3D11Impl* pDevice, + const TextureViewDesc& ViewDesc, + ITexture* pTexture, + ID3D11View* pD3D11View, + bool bIsDefaultView) : + // clang-format off TTextureViewBase { pRefCounters, @@ -43,6 +44,7 @@ TextureViewD3D11Impl::TextureViewD3D11Impl( IReferenceCounters* pRefCounters, bIsDefaultView }, m_pD3D11View{pD3D11View} +// clang-format on { if (*m_Desc.Name != 0) { @@ -51,6 +53,6 @@ TextureViewD3D11Impl::TextureViewD3D11Impl( IReferenceCounters* pRefCounters, } } -IMPLEMENT_QUERY_INTERFACE( TextureViewD3D11Impl, IID_TextureViewD3D11, TTextureViewBase ) +IMPLEMENT_QUERY_INTERFACE(TextureViewD3D11Impl, IID_TextureViewD3D11, TTextureViewBase) -} +} // namespace Diligent -- cgit v1.2.3