diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-17 00:45:46 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:24 +0000 |
| commit | d7dc6664dd6a3ad38d336b63cf6ade0d40dd8dd2 (patch) | |
| tree | c1a0d86d4770cc095f4d929aedb052f351acd128 /Graphics/GraphicsEngineD3D11 | |
| parent | Some updates to ShaderResourceCacheD3D11 (diff) | |
| download | DiligentCore-d7dc6664dd6a3ad38d336b63cf6ade0d40dd8dd2.tar.gz DiligentCore-d7dc6664dd6a3ad38d336b63cf6ade0d40dd8dd2.zip | |
Refactored ShaderResourceCacheD3D11
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
6 files changed, 256 insertions, 422 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp index 23fc8654..abc0b7e2 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp @@ -87,6 +87,11 @@ public: /// Strong reference to the buffer RefCntAutoPtr<BufferD3D11Impl> pBuff; + explicit operator bool() const + { + return pBuff; + } + private: friend class ShaderResourceCacheD3D11; __forceinline void Set(RefCntAutoPtr<BufferD3D11Impl> _pBuff) @@ -101,6 +106,11 @@ public: /// Strong reference to the sampler RefCntAutoPtr<SamplerD3D11Impl> pSampler; + explicit operator bool() const + { + return pSampler; + } + private: friend class ShaderResourceCacheD3D11; __forceinline void Set(SamplerD3D11Impl* pSam) @@ -128,6 +138,14 @@ public: CachedResource() noexcept {} + explicit operator bool() const + { + VERIFY_EXPR((pView && pd3d11Resource != nullptr) || (!pView && pd3d11Resource == nullptr)); + VERIFY_EXPR(pTexture == nullptr || pBuffer == nullptr); + VERIFY_EXPR((pView && (pTexture != nullptr || pBuffer != nullptr)) || (!pView && (pTexture == nullptr && pBuffer == nullptr))); + return pView; + } + private: friend class ShaderResourceCacheD3D11; __forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl> pTexView) @@ -149,6 +167,9 @@ public: } }; + template <typename D3D11ResourceType> + struct CachedResourceTraits; + static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes; using TBindingsPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>; @@ -159,136 +180,53 @@ public: __forceinline void SetCB(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl) { auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr; - SetD3D11ResourceInternal<CachedCB>(BindPoints, &ShaderResourceCacheD3D11::GetCBCount, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff); + SetD3D11ResourceInternal<CachedCB>(BindPoints, std::move(pBuffD3D11Impl), pd3d11Buff); } __forceinline void SetTexSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView) { auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV); + SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pTexView), pd3d11SRV); } __forceinline void SetBufSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView) { auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV); + SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pBuffView), pd3d11SRV); } __forceinline void SetTexUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView) { auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV); + SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pTexView), pd3d11UAV); } __forceinline void SetBufUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView) { auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV); + SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pBuffView), pd3d11UAV); } __forceinline void SetSampler(BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler) { auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr; - SetD3D11ResourceInternal<CachedSampler>(BindPoints, &ShaderResourceCacheD3D11::GetSamplerCount, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); - } - - - __forceinline CachedCB const& GetCB(BindPointsD3D11 BindPoints) const - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits()); - VERIFY(BindPoints[ShaderInd] < GetCBCount(ShaderInd), "CB slot is out of range"); - ShaderResourceCacheD3D11::CachedCB const* CBs; - ID3D11Buffer* const* pd3d11CBs; - GetConstCBArrays(ShaderInd, CBs, pd3d11CBs); - return CBs[BindPoints[ShaderInd]]; + SetD3D11ResourceInternal<CachedSampler>(BindPoints, pSampler, pd3d11Sampler); } - __forceinline CachedResource const& GetSRV(BindPointsD3D11 BindPoints) const - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits()); - VERIFY(BindPoints[ShaderInd] < GetSRVCount(ShaderInd), "SRV slot is out of range"); - ShaderResourceCacheD3D11::CachedResource const* SRVResources; - ID3D11ShaderResourceView* const* pd3d11SRVs; - GetConstSRVArrays(ShaderInd, SRVResources, pd3d11SRVs); - return SRVResources[BindPoints[ShaderInd]]; - } - __forceinline CachedResource const& GetUAV(BindPointsD3D11 BindPoints) const + template <typename D3D11ResourceType> + __forceinline const typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType& GetResource(BindPointsD3D11 BindPoints) const { const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits()); - VERIFY(BindPoints[ShaderInd] < GetUAVCount(ShaderInd), "UAV slot is out of range"); - ShaderResourceCacheD3D11::CachedResource const* UAVResources; - ID3D11UnorderedAccessView* const* pd3d11UAVs; - GetConstUAVArrays(ShaderInd, UAVResources, pd3d11UAVs); - return UAVResources[BindPoints[ShaderInd]]; - } - - __forceinline CachedSampler const& GetSampler(BindPointsD3D11 BindPoints) const - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits()); - VERIFY(BindPoints[ShaderInd] < GetSamplerCount(ShaderInd), "Sampler slot is out of range"); - ShaderResourceCacheD3D11::CachedSampler const* Samplers; - ID3D11SamplerState* const* pd3d11Samplers; - GetConstSamplerArrays(ShaderInd, Samplers, pd3d11Samplers); - return Samplers[BindPoints[ShaderInd]]; - } - - - __forceinline bool CopyCB(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints) - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - - CachedCB const* pSrcCBs; - ID3D11Buffer* const* pSrcd3d11CBs; - SrcCache.GetConstCBArrays(ShaderInd, pSrcCBs, pSrcd3d11CBs); - - CachedCB* pCBs; - ID3D11Buffer** pd3d11CBs; - GetCBArrays(ShaderInd, pCBs, pd3d11CBs); - - const Uint32 CacheOffset = BindPoints[ShaderInd]; - VERIFY(CacheOffset < GetCBCount(ShaderInd), "Index is out of range"); - if (pSrcCBs[CacheOffset].pBuff == nullptr) - IsBound = false; - - pCBs[CacheOffset] = pSrcCBs[CacheOffset]; - pd3d11CBs[CacheOffset] = pSrcd3d11CBs[CacheOffset]; - } - return IsBound; - } - - __forceinline bool CopySRV(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints) - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - - CachedResource const* pSrcSRVResources; - ID3D11ShaderResourceView* const* pSrcd3d11SRVs; - SrcCache.GetConstSRVArrays(ShaderInd, pSrcSRVResources, pSrcd3d11SRVs); - - CachedResource* pSRVResources; - ID3D11ShaderResourceView** pd3d11SRVs; - GetSRVArrays(ShaderInd, pSRVResources, pd3d11SRVs); - - const Uint32 CacheOffset = BindPoints[ShaderInd]; - VERIFY(CacheOffset < GetSRVCount(ShaderInd), "Index is out of range"); - if (pSrcSRVResources[CacheOffset].pBuffer == nullptr && pSrcSRVResources[CacheOffset].pTexture == nullptr) - IsBound = false; - - pSRVResources[CacheOffset] = pSrcSRVResources[CacheOffset]; - pd3d11SRVs[CacheOffset] = pSrcd3d11SRVs[CacheOffset]; - } - return IsBound; + VERIFY(BindPoints[ShaderInd] < GetResourceCount<D3D11ResourceType>(ShaderInd), "Resource slot is out of range"); + CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources; + D3D11ResourceType* const* pd3d11Resources; + GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources); + return CachedResources[BindPoints[ShaderInd]]; } - __forceinline bool CopyUAV(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints) + template <typename D3D11ResourceType> + bool CopyResource(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints) { bool IsBound = true; for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) @@ -296,99 +234,27 @@ public: const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); ActiveBits &= ~(1u << ShaderInd); - CachedResource const* pSrcUAVResources; - ID3D11UnorderedAccessView* const* pSrcd3d11UAVs; - SrcCache.GetConstUAVArrays(ShaderInd, pSrcUAVResources, pSrcd3d11UAVs); + CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* pSrcCachedResources; + D3D11ResourceType* const* pd3d11SrcResources; + SrcCache.GetConstResourceArrays(ShaderInd, pSrcCachedResources, pd3d11SrcResources); - CachedResource* pUAVResources; - ID3D11UnorderedAccessView** pd3d11UAVs; - GetUAVArrays(ShaderInd, pUAVResources, pd3d11UAVs); + CachedResourceTraits<D3D11ResourceType>::CachedResourceType* pDstCachedResources; + D3D11ResourceType** pd3d11DstResources; + GetResourceArrays(ShaderInd, pDstCachedResources, pd3d11DstResources); const Uint32 CacheOffset = BindPoints[ShaderInd]; - VERIFY(CacheOffset < GetUAVCount(ShaderInd), "Index is out of range"); - if (pSrcUAVResources[CacheOffset].pBuffer == nullptr && pSrcUAVResources[CacheOffset].pTexture == nullptr) + VERIFY(CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd), "Index is out of range"); + if (!pSrcCachedResources[CacheOffset]) IsBound = false; - pUAVResources[CacheOffset] = pSrcUAVResources[CacheOffset]; - pd3d11UAVs[CacheOffset] = pSrcd3d11UAVs[CacheOffset]; - } - return IsBound; - } - - __forceinline bool CopySampler(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints) - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - - CachedSampler const* pSrcSamplers; - ID3D11SamplerState* const* pSrcd3d11Samplers; - SrcCache.GetConstSamplerArrays(ShaderInd, pSrcSamplers, pSrcd3d11Samplers); - - CachedSampler* pSamplers; - ID3D11SamplerState** pd3d11Samplers; - GetSamplerArrays(ShaderInd, pSamplers, pd3d11Samplers); - - const Uint32 CacheOffset = BindPoints[ShaderInd]; - VERIFY(CacheOffset < GetSamplerCount(ShaderInd), "Index is out of range"); - if (pSrcSamplers[CacheOffset].pSampler == nullptr) - IsBound = false; - - pSamplers[CacheOffset] = pSrcSamplers[CacheOffset]; - pd3d11Samplers[CacheOffset] = pSrcd3d11Samplers[CacheOffset]; - } - return IsBound; - } - - - __forceinline bool IsCBBound(BindPointsD3D11 BindPoints) const - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - const Uint32 CacheOffset = BindPoints[ShaderInd]; - - CachedCB const* CBs; - ID3D11Buffer* const* d3d11CBs; - GetConstCBArrays(ShaderInd, CBs, d3d11CBs); - if (CacheOffset < GetCBCount(ShaderInd) && d3d11CBs[CacheOffset] != nullptr) - { - VERIFY(CBs[CacheOffset].pBuff != nullptr, "No relevant buffer resource"); - continue; - } - IsBound = false; - } - return IsBound; - } - - __forceinline bool IsSRVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - const Uint32 CacheOffset = BindPoints[ShaderInd]; - - CachedResource const* SRVResources; - ID3D11ShaderResourceView* const* d3d11SRVs; - GetConstSRVArrays(ShaderInd, SRVResources, d3d11SRVs); - if (CacheOffset < GetSRVCount(ShaderInd) && d3d11SRVs[CacheOffset] != nullptr) - { - VERIFY((dbgIsTextureView && SRVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && SRVResources[CacheOffset].pBuffer != nullptr), - "No relevant resource"); - continue; - } - IsBound = false; + pDstCachedResources[CacheOffset] = pSrcCachedResources[CacheOffset]; + pd3d11DstResources[CacheOffset] = pd3d11SrcResources[CacheOffset]; } return IsBound; } - __forceinline bool IsUAVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const + template <typename D3D11ResourceType> + __forceinline bool IsResourceBound(BindPointsD3D11 BindPoints) const { bool IsBound = true; for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) @@ -397,35 +263,11 @@ public: ActiveBits &= ~(1u << ShaderInd); const Uint32 CacheOffset = BindPoints[ShaderInd]; - CachedResource const* UAVResources; - ID3D11UnorderedAccessView* const* d3d11UAVs; - GetConstUAVArrays(ShaderInd, UAVResources, d3d11UAVs); - if (CacheOffset < GetUAVCount(ShaderInd) && d3d11UAVs[CacheOffset] != nullptr) + CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources; + D3D11ResourceType* const* pd3d11Resources; + GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources); + if (CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd) && CachedResources[CacheOffset]) { - VERIFY((dbgIsTextureView && UAVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && UAVResources[CacheOffset].pBuffer != nullptr), - "No relevant resource"); - continue; - } - IsBound = false; - } - return IsBound; - } - - __forceinline bool IsSamplerBound(BindPointsD3D11 BindPoints) const - { - bool IsBound = true; - for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;) - { - const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits); - ActiveBits &= ~(1u << ShaderInd); - const Uint32 CacheOffset = BindPoints[ShaderInd]; - - CachedSampler const* Samplers; - ID3D11SamplerState* const* d3d11Samplers; - GetConstSamplerArrays(ShaderInd, Samplers, d3d11Samplers); - if (CacheOffset < GetSamplerCount(ShaderInd) && d3d11Samplers[CacheOffset] != nullptr) - { - VERIFY(Samplers[CacheOffset].pSampler != nullptr, "No relevant sampler"); continue; } IsBound = false; @@ -444,60 +286,32 @@ public: __forceinline Uint32 GetUAVCount (Uint32 ShaderInd) const { return (m_Offsets[UAVOffset + ShaderInd + 1] - m_Offsets[UAVOffset + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)); } // clang-format on - __forceinline void GetCBArrays(Uint32 ShaderInd, CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs) const - { - VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - CBs = reinterpret_cast<CachedCB*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]); - pd3d11CBs = reinterpret_cast<ID3D11Buffer**>(CBs + GetCBCount(ShaderInd)); - } + template <typename D3D11ResourceType> + __forceinline Uint32 GetResourceCount(Uint32 ShaderInd) const; - __forceinline void GetSRVArrays(Uint32 ShaderInd, CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs) const + template <typename D3D11ResourceType> + __forceinline void GetResourceArrays( + Uint32 ShaderInd, + typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType*& pResources, + D3D11ResourceType**& pd3d11Resources) const { - VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - SRVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]); - d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView**>(SRVResources + GetSRVCount(ShaderInd)); - } + static_assert(alignof(CachedResourceTraits<D3D11ResourceType>::CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - __forceinline void GetSamplerArrays(Uint32 ShaderInd, CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers) const - { - VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - Samplers = reinterpret_cast<CachedSampler*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]); - pd3d11Samplers = reinterpret_cast<ID3D11SamplerState**>(Samplers + GetSamplerCount(ShaderInd)); + pResources = reinterpret_cast<CachedResourceTraits<D3D11ResourceType>::CachedResourceType*>(m_pResourceData.get() + GetResourceDataOffset<D3D11ResourceType>(ShaderInd)); + pd3d11Resources = reinterpret_cast<D3D11ResourceType**>(pResources + GetResourceCount<D3D11ResourceType>(ShaderInd)); } - __forceinline void GetUAVArrays(Uint32 ShaderInd, CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs) const - { - VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - UAVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]); - pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView**>(UAVResources + GetUAVCount(ShaderInd)); - } - __forceinline void GetConstCBArrays(Uint32 ShaderInd, CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs) const + template <typename D3D11ResourceType> + __forceinline void GetConstResourceArrays( + Uint32 ShaderInd, + typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType const*& pResources, + D3D11ResourceType* const*& pd3d11Resources) const { - VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - CBs = reinterpret_cast<CachedCB const*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]); - pd3d11CBs = reinterpret_cast<ID3D11Buffer* const*>(CBs + GetCBCount(ShaderInd)); - } + static_assert(alignof(CachedResourceTraits<D3D11ResourceType>::CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - __forceinline void GetConstSRVArrays(Uint32 ShaderInd, CachedResource const*& SRVResources, ID3D11ShaderResourceView* const*& d3d11SRVs) const - { - VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - SRVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]); - d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView* const*>(SRVResources + GetSRVCount(ShaderInd)); - } - - __forceinline void GetConstSamplerArrays(Uint32 ShaderInd, CachedSampler const*& Samplers, ID3D11SamplerState* const*& pd3d11Samplers) const - { - VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - Samplers = reinterpret_cast<CachedSampler const*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]); - pd3d11Samplers = reinterpret_cast<ID3D11SamplerState* const*>(Samplers + GetSamplerCount(ShaderInd)); - } - - __forceinline void GetConstUAVArrays(Uint32 ShaderInd, CachedResource const*& UAVResources, ID3D11UnorderedAccessView* const*& pd3d11UAVs) const - { - VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); - UAVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]); - pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView* const*>(UAVResources + GetUAVCount(ShaderInd)); + pResources = reinterpret_cast<CachedResourceTraits<D3D11ResourceType>::CachedResourceType const*>(m_pResourceData.get() + GetResourceDataOffset<D3D11ResourceType>(ShaderInd)); + pd3d11Resources = reinterpret_cast<D3D11ResourceType* const*>(pResources + GetResourceCount<D3D11ResourceType>(ShaderInd)); } bool IsInitialized() const { return m_IsInitialized; } @@ -523,27 +337,23 @@ public: } }; - MinMaxSlot BindCBs(Uint32 ShaderInd, - ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT], - Uint8& Binding) const; - - MinMaxSlot BindSRVs(Uint32 ShaderInd, - ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT], - ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT], - Uint8& Binding) const; - - MinMaxSlot BindSamplers(Uint32 ShaderInd, - ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT], - Uint8& Binding) const; + template <typename D3D11ResourceType> + MinMaxSlot BindResources(Uint32 ShaderInd, + D3D11ResourceType* CommittedD3D11Resources[], + Uint8& Binding) const; - MinMaxSlot BindUAVs(Uint32 ShaderInd, - ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT], - ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT], - Uint8& Binding) const; + template <typename D3D11ResourceViewType> + MinMaxSlot BindResourceViews(Uint32 ShaderInd, + D3D11ResourceViewType* CommittedD3D11Views[], + ID3D11Resource* CommittedD3D11Resources[], + Uint8& Binding) const; private: - template <typename TCachedResourceType, typename TGetResourceCount, typename TGetResourceArraysFunc, typename TSrcResourceType, typename TD3D11ResourceType> - __forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TGetResourceCount GetCount, TGetResourceArraysFunc GetArrays, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource) + template <typename D3D11ResourceTpye> + __forceinline Uint32 GetResourceDataOffset(Uint32 ShaderInd) const; + + template <typename TCachedResourceType, typename TSrcResourceType, typename TD3D11ResourceType> + __forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource) { VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr, "Resource and D3D11 resource must be set/unset atomically"); @@ -553,12 +363,12 @@ private: ActiveBits &= ~(1u << ShaderInd); const Uint32 CacheOffset = BindPoints[ShaderInd]; - const Uint32 ResCount = (this->*GetCount)(ShaderInd); + const Uint32 ResCount = GetResourceCount<TD3D11ResourceType>(ShaderInd); VERIFY(CacheOffset < ResCount, "Index is out of range"); TCachedResourceType* Resources; TD3D11ResourceType** d3d11ResArr; - (this->*GetArrays)(ShaderInd, Resources, d3d11ResArr); + GetResourceArrays(ShaderInd, Resources, d3d11ResArr); Resources[CacheOffset].Set(pResource); d3d11ResArr[CacheOffset] = pd3d11Resource; } @@ -602,8 +412,138 @@ private: static constexpr size_t ResCacheSize = sizeof(ShaderResourceCacheD3D11); + +template <> +struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11Buffer> +{ + using CachedResourceType = CachedCB; +}; + +template <> +struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11SamplerState> +{ + using CachedResourceType = CachedSampler; +}; + +template <> +struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11ShaderResourceView> +{ + using CachedResourceType = CachedResource; +}; + +template <> +struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11UnorderedAccessView> +{ + using CachedResourceType = CachedResource; +}; + + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11Buffer>(Uint32 ShaderInd) const +{ + return GetCBCount(ShaderInd); +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11ShaderResourceView>(Uint32 ShaderInd) const +{ + return GetSRVCount(ShaderInd); +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const +{ + return GetUAVCount(ShaderInd); +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11SamplerState>(Uint32 ShaderInd) const +{ + return GetSamplerCount(ShaderInd); +} + + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11Buffer>(Uint32 ShaderInd) const +{ + return m_Offsets[CBOffset + ShaderInd]; +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11ShaderResourceView>(Uint32 ShaderInd) const +{ + return m_Offsets[SRVOffset + ShaderInd]; +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11SamplerState>(Uint32 ShaderInd) const +{ + return m_Offsets[SampOffset + ShaderInd]; +} + +template <> +__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const +{ + return m_Offsets[UAVOffset + ShaderInd]; +} + // Instantiate templates template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Transition>(DeviceContextD3D11Impl& Ctx); template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Verify>(DeviceContextD3D11Impl& Ctx); + +template <typename D3D11ResourceType> +ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResources( + Uint32 ShaderInd, + D3D11ResourceType* CommittedD3D11Resources[], + Uint8& Binding) const +{ + CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources; + D3D11ResourceType* const* pd3d11Resources; + GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources); + + MinMaxSlot Slots; + + const auto ResCount = GetResourceCount<D3D11ResourceType>(ShaderInd); + for (Uint32 res = 0; res < ResCount; ++res) + { + const Uint32 Slot = Binding++; + if (CommittedD3D11Resources[Slot] != pd3d11Resources[res]) + Slots.Add(Slot); + + VERIFY_EXPR(pd3d11Resources[res] != nullptr); + CommittedD3D11Resources[Slot] = pd3d11Resources[res]; + } + + return Slots; +} + +template <typename D3D11ResourceViewType> +ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResourceViews( + Uint32 ShaderInd, + D3D11ResourceViewType* CommittedD3D11Views[], + ID3D11Resource* CommittedD3D11Resources[], + Uint8& Binding) const +{ + CachedResourceTraits<D3D11ResourceViewType>::CachedResourceType const* CachedResources; + D3D11ResourceViewType* const* pd3d11Views; + GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Views); + + MinMaxSlot Slots; + + const auto ResCount = GetResourceCount<D3D11ResourceViewType>(ShaderInd); + for (Uint32 res = 0; res < ResCount; ++res) + { + const Uint32 Slot = Binding++; + if (CommittedD3D11Views[Slot] != pd3d11Views[res]) + Slots.Add(Slot); + + VERIFY_EXPR(pd3d11Views[res] != nullptr); + CommittedD3D11Resources[Slot] = CachedResources[res].pd3d11Resource; + CommittedD3D11Views[Slot] = pd3d11Views[res]; + } + + return Slots; +} + } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp index 74bd96a2..545a124f 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp @@ -133,7 +133,7 @@ public: virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsCBBound(GetAttribs().BindPoints + ArrayIndex); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11Buffer>(GetAttribs().BindPoints + ArrayIndex); } }; @@ -149,7 +149,7 @@ public: virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, true); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex); } }; @@ -165,7 +165,7 @@ public: __forceinline virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, true); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex); } }; @@ -181,7 +181,7 @@ public: virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, false); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex); } }; @@ -197,7 +197,7 @@ public: virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, false); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex); } }; @@ -213,7 +213,7 @@ public: virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); - return m_ParentManager.m_ResourceCache.IsSamplerBound(GetAttribs().BindPoints + ArrayIndex); + return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11SamplerState>(GetAttribs().BindPoints + ArrayIndex); } }; diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index b35411e1..6b37902d 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -286,7 +286,7 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11& const auto ShaderInd = ShaderIndices[i]; auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderInd]; Uint8 Binding = BaseBindings[Range][ShaderInd]; - auto Slots = ResourceCache.BindCBs(ShaderInd, CommittedD3D11CBs, Binding); + auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11CBs, Binding); if (Slots) { @@ -310,7 +310,7 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11& auto* CommittedD3D11SRVs = m_CommittedRes.D3D11SRVs[ShaderInd]; auto* CommittedD3D11SRVRes = m_CommittedRes.D3D11SRVResources[ShaderInd]; Uint8 Binding = BaseBindings[Range][ShaderInd]; - auto Slots = ResourceCache.BindSRVs(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding); + auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding); if (Slots) { @@ -333,7 +333,7 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11& const auto ShaderInd = ShaderIndices[i]; auto* CommittedD3D11Samplers = m_CommittedRes.D3D11Samplers[ShaderInd]; Uint8 Binding = BaseBindings[Range][ShaderInd]; - auto Slots = ResourceCache.BindSamplers(ShaderInd, CommittedD3D11Samplers, Binding); + auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11Samplers, Binding); if (Slots) { @@ -358,7 +358,7 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11& auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[ShaderInd]; auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[ShaderInd]; Uint8 Binding = BaseBindings[Range][ShaderInd]; - auto Slots = ResourceCache.BindUAVs(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding); + auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding); if (Slots) { diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp index d8036c5f..ae706ebf 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp @@ -327,14 +327,14 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache case D3D11_RESOURCE_RANGE_CBV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!DstResourceCache.CopyCB(SrcResourceCache, ResAttr.BindPoints + ArrInd)) + if (!DstResourceCache.CopyResource<ID3D11Buffer>(SrcResourceCache, ResAttr.BindPoints + ArrInd)) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); } break; case D3D11_RESOURCE_RANGE_SRV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!DstResourceCache.CopySRV(SrcResourceCache, ResAttr.BindPoints + ArrInd)) + if (!DstResourceCache.CopyResource<ID3D11ShaderResourceView>(SrcResourceCache, ResAttr.BindPoints + ArrInd)) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); } break; @@ -344,7 +344,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache { for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!DstResourceCache.CopySampler(SrcResourceCache, ResAttr.BindPoints + ArrInd)) + if (!DstResourceCache.CopyResource<ID3D11SamplerState>(SrcResourceCache, ResAttr.BindPoints + ArrInd)) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); } } @@ -352,7 +352,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache case D3D11_RESOURCE_RANGE_UAV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!DstResourceCache.CopyUAV(SrcResourceCache, ResAttr.BindPoints + ArrInd)) + if (!DstResourceCache.CopyResource<ID3D11UnorderedAccessView>(SrcResourceCache, ResAttr.BindPoints + ArrInd)) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); } break; @@ -467,7 +467,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS case D3D11_RESOURCE_RANGE_CBV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!ResourceCache.IsCBBound(ResAttr.BindPoints + ArrInd)) + if (!ResourceCache.IsResourceBound<ID3D11Buffer>(ResAttr.BindPoints + ArrInd)) { LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); @@ -479,7 +479,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS case D3D11_RESOURCE_RANGE_SAMPLER: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - if (!ResourceCache.IsSamplerBound(ResAttr.BindPoints + ArrInd)) + if (!ResourceCache.IsResourceBound<ID3D11SamplerState>(ResAttr.BindPoints + ArrInd)) { LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); @@ -491,8 +491,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS case D3D11_RESOURCE_RANGE_SRV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - const bool IsTexView = (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT); - if (!ResourceCache.IsSRVBound(ResAttr.BindPoints + ArrInd, IsTexView)) + if (!ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(ResAttr.BindPoints + ArrInd)) { LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); @@ -512,8 +511,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS case D3D11_RESOURCE_RANGE_UAV: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { - const bool IsTexView = (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV); - if (!ResourceCache.IsUAVBound(ResAttr.BindPoints + ArrInd, IsTexView)) + if (!ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(ResAttr.BindPoints + ArrInd)) { LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp index 974a15ea..866298fa 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp @@ -114,7 +114,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe {
CachedCB* CBs = nullptr;
ID3D11Buffer** d3d11CBs = nullptr;
- GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ GetResourceArrays(ShaderInd, CBs, d3d11CBs);
for (Uint32 cb = 0; cb < CBCount; ++cb)
new (CBs + cb) CachedCB{};
}
@@ -124,7 +124,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe {
CachedResource* SRVResources = nullptr;
ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
for (Uint32 srv = 0; srv < SRVCount; ++srv)
new (SRVResources + srv) CachedResource{};
}
@@ -134,7 +134,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe {
CachedSampler* Samplers = nullptr;
ID3D11SamplerState** d3d11Samplers = nullptr;
- GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+ GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
for (Uint32 sam = 0; sam < SamplerCount; ++sam)
new (Samplers + sam) CachedSampler{};
}
@@ -144,7 +144,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe {
CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
for (Uint32 uav = 0; uav < UAVCount; ++uav)
new (UAVResources + uav) CachedResource{};
}
@@ -165,7 +165,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedCB* CBs = nullptr;
ID3D11Buffer** d3d11CBs = nullptr;
- GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ GetResourceArrays(ShaderInd, CBs, d3d11CBs);
for (size_t cb = 0; cb < CBCount; ++cb)
CBs[cb].~CachedCB();
}
@@ -175,7 +175,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedResource* SRVResources = nullptr;
ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
for (size_t srv = 0; srv < SRVCount; ++srv)
SRVResources[srv].~CachedResource();
}
@@ -185,7 +185,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedSampler* Samplers = nullptr;
ID3D11SamplerState** d3d11Samplers = nullptr;
- GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+ GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
for (size_t sam = 0; sam < SamplerCount; ++sam)
Samplers[sam].~CachedSampler();
}
@@ -195,7 +195,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
for (size_t uav = 0; uav < UAVCount; ++uav)
UAVResources[uav].~CachedResource();
}
@@ -271,10 +271,10 @@ void ShaderResourceCacheD3D11::DvpVerifyCacheConsistency() CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- GetCBArrays(ShaderInd, CBs, d3d11CBs);
- GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
- GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
- GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ GetResourceArrays(ShaderInd, CBs, d3d11CBs);
+ GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
+ GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
+ GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
auto CBCount = GetCBCount(ShaderInd);
for (size_t cb = 0; cb < CBCount; ++cb)
@@ -341,7 +341,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, CachedCB* CBs;
ID3D11Buffer** d3d11CBs;
- GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ GetResourceArrays(ShaderInd, CBs, d3d11CBs);
for (Uint32 i = 0; i < CBCount; ++i)
{
@@ -376,7 +376,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, CachedResource* SRVResources;
ID3D11ShaderResourceView** d3d11SRVs;
- GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
for (Uint32 i = 0; i < SRVCount; ++i)
{
@@ -433,7 +433,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, CachedResource* UAVResources;
ID3D11UnorderedAccessView** d3d11UAVs;
- GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
for (Uint32 i = 0; i < UAVCount; ++i)
{
@@ -474,108 +474,4 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, }
}
-ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindCBs(
- Uint32 ShaderInd,
- ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT],
- Uint8& Binding) const
-{
- CachedCB const* CBs;
- ID3D11Buffer* const* d3d11CBs;
- GetConstCBArrays(ShaderInd, CBs, d3d11CBs);
-
- MinMaxSlot Slots;
-
- const auto CBCount = GetCBCount(ShaderInd);
- for (Uint32 cb = 0; cb < CBCount; ++cb)
- {
- const Uint32 Slot = Binding++;
- if (CommittedD3D11CBs[Slot] != d3d11CBs[cb])
- Slots.Add(Slot);
-
- VERIFY_EXPR(d3d11CBs[cb] != nullptr);
- CommittedD3D11CBs[Slot] = d3d11CBs[cb];
- }
-
- return Slots;
-}
-
-ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindSRVs(
- Uint32 ShaderInd,
- ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
- ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
- Uint8& Binding) const
-{
- CachedResource const* SRVResources;
- ID3D11ShaderResourceView* const* d3d11SRVs;
- GetConstSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
-
- MinMaxSlot Slots;
-
- const auto SRVCount = GetSRVCount(ShaderInd);
- for (Uint32 srv = 0; srv < SRVCount; ++srv)
- {
- const Uint32 Slot = Binding++;
- if (CommittedD3D11SRVs[Slot] != d3d11SRVs[srv])
- Slots.Add(Slot);
-
- VERIFY_EXPR(d3d11SRVs[srv] != nullptr);
- CommittedD3D11SRVResources[Slot] = SRVResources[srv].pd3d11Resource;
- CommittedD3D11SRVs[Slot] = d3d11SRVs[srv];
- }
-
- return Slots;
-}
-
-ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindSamplers(
- Uint32 ShaderInd,
- ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT],
- Uint8& Binding) const
-{
- CachedSampler const* Samplers;
- ID3D11SamplerState* const* d3d11Samplers;
- GetConstSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
-
- MinMaxSlot Slots;
-
- const auto SamplerCount = GetSamplerCount(ShaderInd);
- for (Uint32 sam = 0; sam < SamplerCount; ++sam)
- {
- const Uint32 Slot = Binding++;
- if (CommittedD3D11Samplers[Slot] != d3d11Samplers[sam])
- Slots.Add(Slot);
-
- VERIFY_EXPR(d3d11Samplers[sam] != nullptr);
- CommittedD3D11Samplers[Slot] = d3d11Samplers[sam];
- }
-
- return Slots;
-}
-
-ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindUAVs(
- Uint32 ShaderInd,
- ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT],
- ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT],
- Uint8& Binding) const
-{
- CachedResource const* UAVResources;
- ID3D11UnorderedAccessView* const* d3d11UAVs;
- GetConstUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
-
- MinMaxSlot Slots;
-
- const auto UAVCount = GetUAVCount(ShaderInd);
- for (Uint32 uav = 0; uav < UAVCount; ++uav)
- {
- const Uint32 Slot = Binding++;
- if (CommittedD3D11UAVs[Slot] != d3d11UAVs[uav])
- Slots.Add(Slot);
-
- VERIFY_EXPR(d3d11UAVs[uav] != nullptr);
- CommittedD3D11UAVResources[Slot] = UAVResources[uav].pd3d11Resource;
- CommittedD3D11UAVs[Slot] = d3d11UAVs[uav];
- }
-
- return Slots;
-}
-
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp index b989d966..4ff053b9 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp @@ -295,7 +295,7 @@ void ShaderVariableManagerD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl{pBuffer, IID_BufferD3D11}; #ifdef DILIGENT_DEVELOPMENT { - const auto& CachedCB = ResourceCache.GetCB(Attr.BindPoints + ArrayIndex); + const auto& CachedCB = ResourceCache.GetResource<ID3D11Buffer>(Attr.BindPoints + ArrayIndex); VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(), m_ParentManager.m_pSignature->GetDesc().Name); } @@ -319,7 +319,7 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11}; #ifdef DILIGENT_DEVELOPMENT { - auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex); + auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr(), @@ -353,7 +353,7 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi #ifdef DILIGENT_DEVELOPMENT if (SampDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { - auto& CachedSampler = ResourceCache.GetSampler(SampAttr.BindPoints + SampArrayIndex); + auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(SampAttr.BindPoints + SampArrayIndex); if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl) { auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType()); @@ -397,7 +397,7 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { - auto& CachedSampler = ResourceCache.GetSampler(Attr.BindPoints + ArrayIndex); + auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(Attr.BindPoints + ArrayIndex); if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType()); @@ -425,7 +425,7 @@ void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pV RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11}; #ifdef DILIGENT_DEVELOPMENT { - auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex); + auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE}, RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr(), @@ -451,7 +451,7 @@ void ShaderVariableManagerD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVi RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11}; #ifdef DILIGENT_DEVELOPMENT { - auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex); + auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS}, RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr(), @@ -476,7 +476,7 @@ void ShaderVariableManagerD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pV RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11}; #ifdef DILIGENT_DEVELOPMENT { - auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex); + auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS}, RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr(), |
