diff options
| author | azhirnov <zh1dron@gmail.com> | 2021-03-10 18:42:03 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:21 +0000 |
| commit | 8f85ab43928dfbbfea5630d5419049e6015c2d29 (patch) | |
| tree | a7c6a64dee52c7cc84487f24e0b3f6e6c037b8b5 /Graphics/GraphicsEngineD3D11 | |
| parent | Direct3D11: added resource signature (diff) | |
| download | DiligentCore-8f85ab43928dfbbfea5630d5419049e6015c2d29.tar.gz DiligentCore-8f85ab43928dfbbfea5630d5419049e6015c2d29.zip | |
Direct3D11: added BindPointsD3D11 instead of TBindPoints and TBindPointsAndActiveBits,
GetShaderResourceTypeAndFlags moved to D3DBase,
added DvpVerifySRBResources() and DvpValidateCommittedResource()
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
11 files changed, 470 insertions, 616 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp index ad5ae8c1..33dc96e4 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp @@ -49,7 +49,67 @@ enum DESCRIPTOR_RANGE : Uint32 }; DESCRIPTOR_RANGE ShaderResourceToDescriptorRange(SHADER_RESOURCE_TYPE Type); -// sizeof(PipelineResourceAttribsD3D11) == 4, x64 + +// sizeof(BindPointsD3D11) == 8, x64 +struct BindPointsD3D11 +{ + /// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute) + static constexpr Uint32 NumShaderTypes = 6; + + static constexpr Uint8 InvalidBindPoint = 0xFF; + + BindPointsD3D11() noexcept {} + BindPointsD3D11(const BindPointsD3D11&) noexcept = default; + + // clang-format off + Uint32 GetActiveBits() const { return m_ActiveBits; } + bool IsValid(Uint32 index) const { return m_Bindings[index] != InvalidBindPoint; } + Uint8 operator[](Uint32 index) const { return m_Bindings[index]; } + // clang-format on + + void Set(Uint32 Index, Uint32 BindPoint) + { + VERIFY_EXPR(Index < NumShaderTypes); + VERIFY_EXPR(BindPoint < InvalidBindPoint); + m_ActiveBits = static_cast<Uint8>(m_ActiveBits | (1u << Index)); + m_Bindings[Index] = static_cast<Uint8>(BindPoint); + } + + size_t GetHash() const + { + size_t Hash = 0; + for (Uint32 i = 0; i < NumShaderTypes; ++i) + HashCombine(Hash, m_Bindings[i]); + return Hash; + } + + bool operator==(const BindPointsD3D11& rhs) const + { + return m_Bindings == rhs.m_Bindings; + } + + BindPointsD3D11 operator+(Uint32 value) const + { + BindPointsD3D11 Result{*this}; + for (Uint32 Bits = Result.m_ActiveBits; Bits != 0;) + { + auto Index = PlatformMisc::GetLSB(Bits); + Bits &= ~(1u << Index); + + auto NewBindPoint = Result.m_Bindings[Index] + value; + VERIFY_EXPR(NewBindPoint < InvalidBindPoint); + Result.m_Bindings[Index] = static_cast<Uint8>(NewBindPoint); + } + return Result; + } + +private: + Uint8 m_ActiveBits = 0; + std::array<Uint8, NumShaderTypes> m_Bindings = {InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint}; +}; + + +// sizeof(PipelineResourceAttribsD3D11) == 12, x64 struct PipelineResourceAttribsD3D11 { private: @@ -61,18 +121,11 @@ public: static constexpr Uint32 InvalidCacheOffset = (1u << _CacheOffsetBits) - 1; static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1; - /// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute) - static constexpr Uint32 NumShaderTypes = 6; - - using TBindPoints = std::array<Uint8, NumShaderTypes>; - static constexpr Uint8 InvalidBindPoint = 0xFF; - static constexpr TBindPoints InvalidBindPoints = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - // clang-format off - const Uint32 CacheOffset : _CacheOffsetBits; // SRB and Signature has the same cache offsets for static resources. - const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources. - const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag. - TBindPoints BindPoints = InvalidBindPoints; + const Uint32 CacheOffset : _CacheOffsetBits; // SRB and Signature has the same cache offsets for static resources. + const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources. + const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag. + BindPointsD3D11 BindPoints; // clang-format on PipelineResourceAttribsD3D11(Uint32 _CacheOffset, @@ -93,22 +146,16 @@ public: bool IsCompatibleWith(const PipelineResourceAttribsD3D11& rhs) const { - // Ignore sampler index. + // Ignore cache offset and sampler index. // clang-format off - return CacheOffset == rhs.CacheOffset && - IsImmutableSamplerAssigned() == rhs.IsImmutableSamplerAssigned() && + return IsImmutableSamplerAssigned() == rhs.IsImmutableSamplerAssigned() && BindPoints == rhs.BindPoints; // clang-format on } size_t GetHash() const { - Uint64 h = 0; - for (Uint32 i = 0; i < NumShaderTypes; ++i) - { - h |= (BindPoints[i] << (i * 8)); - } - return ComputeHash(h); + return ComputeHash(IsImmutableSamplerAssigned(), BindPoints.GetHash()); } }; diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp index fc6233be..7deb0a11 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp @@ -59,12 +59,8 @@ public: bool bIsDeviceInternal = false); ~PipelineResourceSignatureD3D11Impl(); - using ResourceAttribs = PipelineResourceAttribsD3D11; - using TBindPoints = PipelineResourceAttribsD3D11::TBindPoints; - - static constexpr auto NumShaderTypes = ResourceAttribs::NumShaderTypes; - static constexpr auto InvalidBindPoint = ResourceAttribs::InvalidBindPoint; - static constexpr auto InvalidBindPoints = ResourceAttribs::InvalidBindPoints; + using ResourceAttribs = PipelineResourceAttribsD3D11; + static constexpr auto NumShaderTypes = BindPointsD3D11::NumShaderTypes; const ResourceAttribs& GetResourceAttribs(Uint32 ResIndex) const { @@ -72,7 +68,7 @@ public: return m_pResourceAttribs[ResIndex]; } - // sizeof(ImmutableSamplerAttribs) == 16, x64 + // sizeof(ImmutableSamplerAttribs) == 24, x64 struct ImmutableSamplerAttribs { private: @@ -86,10 +82,9 @@ public: // clang-format off RefCntAutoPtr<ISampler> pSampler; - TBindPoints BindPoints = InvalidBindPoints; - TBindPoints LastBindPoints = InvalidBindPoints; // array size for each stage may be different - Uint32 CacheOffset : _CacheOffsetBits; - Uint32 ArraySize : _ArraySizeBits; + Uint32 CacheOffset : _CacheOffsetBits; + Uint32 ArraySize : _ArraySizeBits; + BindPointsD3D11 BindPoints; // clang-format on ImmutableSamplerAttribs() : @@ -110,7 +105,18 @@ public: using TBindings = ShaderResourceCacheD3D11::TResourceCount; using TBindingsPerStage = ShaderResourceCacheD3D11::TBindingsPerStage; - void AddBindings(TBindingsPerStage& Bindings) const; + __forceinline void ShiftBindings(TBindingsPerStage& Bindings) const + { + for (Uint32 s = 0; s < Bindings.size(); ++s) + { + for (Uint32 i = 0; i < Bindings[s].size(); ++i) + { + Uint32 Count = Bindings[s][i] + m_BindingCountPerStage[s][i]; + VERIFY_EXPR(Count < std::numeric_limits<Uint8>::max()); + Bindings[s][i] = static_cast<Uint8>(Count); + } + } + } void InitSRBResourceCache(ShaderResourceCacheD3D11& ResourceCache); @@ -122,8 +128,6 @@ public: #ifdef DILIGENT_DEVELOPMENT /// Verifies committed resource attribs using the SPIRV resource attributes from the PSO. bool DvpValidateCommittedResource(const D3DShaderResourceAttribs& D3DAttribs, - RESOURCE_DIMENSION ResourceDim, - bool IsMultisample, Uint32 ResIndex, const ShaderResourceCacheD3D11& ResourceCache, const char* ShaderName, @@ -143,18 +147,4 @@ private: ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers] }; - -__forceinline void PipelineResourceSignatureD3D11Impl::AddBindings(TBindingsPerStage& Bindings) const -{ - for (Uint32 s = 0; s < Bindings.size(); ++s) - { - for (Uint32 i = 0; i < Bindings[s].size(); ++i) - { - Uint32 Count = Bindings[s][i] + m_BindingCountPerStage[s][i]; - VERIFY_EXPR(Count < std::numeric_limits<Uint8>::max()); - Bindings[s][i] = static_cast<Uint8>(Count); - } - } -} - } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp index f473416f..d2617cad 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp @@ -92,6 +92,11 @@ public: Uint32 GetNumShaders() const { return m_NumShaders; } SHADER_TYPE GetShaderStageType(Uint32 Index) const; +#ifdef DILIGENT_DEVELOPMENT + using TBindingsPerStage = PipelineResourceSignatureD3D11Impl::TBindingsPerStage; + void DvpVerifySRBResources(class ShaderResourceBindingD3D11Impl* pSRBs[], const TBindingsPerStage BaseBindings[], Uint32 NumSRBs) const; +#endif + private: template <typename PSOCreateInfoType> void InitInternalObjects(const PSOCreateInfoType& CreateInfo, diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp index 7f208182..cb39652d 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp @@ -75,7 +75,7 @@ public: void TransitionResourceStates(DeviceContextD3D11Impl& Ctx, StateTransitionMode Mode); - static constexpr int NumShaderTypes = PipelineResourceAttribsD3D11::NumShaderTypes; + static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes; struct TCommittedResources { @@ -205,45 +205,40 @@ public: void Initialize(const TResourceCount& ResCount, IMemoryAllocator& MemAllocator); - - using TBindPoints = PipelineResourceAttribsD3D11::TBindPoints; - using TBindPointsAndActiveBits = std::array<Uint8, NumShaderTypes + 1>; // ActiveBits [0], TBindPoints [1..6] - static constexpr auto InvalidBindPoint = PipelineResourceAttribsD3D11::InvalidBindPoint; - - __forceinline void SetCB(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, RefCntAutoPtr<BufferD3D11Impl>&& pBuffD3D11Impl) + __forceinline void SetCB(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl>&& pBuffD3D11Impl) { auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr; - SetD3D11ResourceInternal<CachedCB>(CacheOffset, ArrayIndex, GetCBCount(), BindPoints, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff); + SetD3D11ResourceInternal<CachedCB>(CacheOffset, GetCBCount(), BindPoints, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff); } - __forceinline void SetTexSRV(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView) + __forceinline void SetTexSRV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView) { auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(CacheOffset, ArrayIndex, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV); + SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV); } - __forceinline void SetBufSRV(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView) + __forceinline void SetBufSRV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView) { auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(CacheOffset, ArrayIndex, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV); + SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV); } - __forceinline void SetTexUAV(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView) + __forceinline void SetTexUAV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView) { auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(CacheOffset, ArrayIndex, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV); + SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV); } - __forceinline void SetBufUAV(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView) + __forceinline void SetBufUAV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView) { auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr; - SetD3D11ResourceInternal<CachedResource>(CacheOffset, ArrayIndex, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV); + SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV); } - __forceinline void SetSampler(Uint32 CacheOffset, Uint32 ArrayIndex, TBindPoints BindPoints, SamplerD3D11Impl* pSampler) + __forceinline void SetSampler(Uint32 CacheOffset, BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler) { auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr; - SetD3D11ResourceInternal<CachedSampler>(CacheOffset, ArrayIndex, GetSamplerCount(), BindPoints, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); + SetD3D11ResourceInternal<CachedSampler>(CacheOffset, GetSamplerCount(), BindPoints, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); } @@ -252,7 +247,7 @@ public: VERIFY(CacheOffset < GetCBCount(), "CB slot is out of range"); ShaderResourceCacheD3D11::CachedCB* CBs; ID3D11Buffer** pd3d11CBs; - TBindPointsAndActiveBits* bindPoints; + BindPointsD3D11* bindPoints; const_cast<ShaderResourceCacheD3D11*>(this)->GetCBArrays(CBs, pd3d11CBs, bindPoints); return CBs[CacheOffset]; } @@ -262,7 +257,7 @@ public: VERIFY(CacheOffset < GetSRVCount(), "SRV slot is out of range"); ShaderResourceCacheD3D11::CachedResource* SRVResources; ID3D11ShaderResourceView** pd3d11SRVs; - TBindPointsAndActiveBits* bindPoints; + BindPointsD3D11* bindPoints; const_cast<ShaderResourceCacheD3D11*>(this)->GetSRVArrays(SRVResources, pd3d11SRVs, bindPoints); return SRVResources[CacheOffset]; } @@ -272,7 +267,7 @@ public: VERIFY(CacheOffset < GetUAVCount(), "UAV slot is out of range"); ShaderResourceCacheD3D11::CachedResource* UAVResources; ID3D11UnorderedAccessView** pd3d11UAVs; - TBindPointsAndActiveBits* bindPoints; + BindPointsD3D11* bindPoints; const_cast<ShaderResourceCacheD3D11*>(this)->GetUAVArrays(UAVResources, pd3d11UAVs, bindPoints); return UAVResources[CacheOffset]; } @@ -282,7 +277,7 @@ public: VERIFY(CacheOffset < GetSamplerCount(), "Sampler slot is out of range"); ShaderResourceCacheD3D11::CachedSampler* Samplers; ID3D11SamplerState** pd3d11Samplers; - TBindPointsAndActiveBits* bindPoints; + BindPointsD3D11* bindPoints; const_cast<ShaderResourceCacheD3D11*>(this)->GetSamplerArrays(Samplers, pd3d11Samplers, bindPoints); return Samplers[CacheOffset]; } @@ -290,9 +285,9 @@ public: __forceinline bool IsCBBound(Uint32 CacheOffset) const { - CachedCB const* CBs; - ID3D11Buffer* const* d3d11CBs; - TBindPointsAndActiveBits const* bindPoints; + CachedCB const* CBs; + ID3D11Buffer* const* d3d11CBs; + BindPointsD3D11 const* bindPoints; GetConstCBArrays(CBs, d3d11CBs, bindPoints); if (CacheOffset < GetCBCount() && d3d11CBs[CacheOffset] != nullptr) { @@ -306,7 +301,7 @@ public: { CachedResource const* SRVResources; ID3D11ShaderResourceView* const* d3d11SRVs; - TBindPointsAndActiveBits const* bindPoints; + BindPointsD3D11 const* bindPoints; GetConstSRVArrays(SRVResources, d3d11SRVs, bindPoints); if (CacheOffset < GetSRVCount() && d3d11SRVs[CacheOffset] != nullptr) { @@ -321,7 +316,7 @@ public: { CachedResource const* UAVResources; ID3D11UnorderedAccessView* const* d3d11UAVs; - TBindPointsAndActiveBits const* bindPoints; + BindPointsD3D11 const* bindPoints; GetConstUAVArrays(UAVResources, d3d11UAVs, bindPoints); if (CacheOffset < GetUAVCount() && d3d11UAVs[CacheOffset] != nullptr) { @@ -334,9 +329,9 @@ public: __forceinline bool IsSamplerBound(Uint32 CacheOffset) const { - CachedSampler const* Samplers; - ID3D11SamplerState* const* d3d11Samplers; - TBindPointsAndActiveBits const* bindPoints; + CachedSampler const* Samplers; + ID3D11SamplerState* const* d3d11Samplers; + BindPointsD3D11 const* bindPoints; GetConstSamplerArrays(Samplers, d3d11Samplers, bindPoints); if (CacheOffset < GetSamplerCount() && d3d11Samplers[CacheOffset] != nullptr) { @@ -357,68 +352,68 @@ public: __forceinline Uint32 GetUAVCount() const { return m_UAVCount; } // clang-format on - __forceinline void GetCBArrays(CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs, TBindPointsAndActiveBits*& pBindPoints) + __forceinline void GetCBArrays(CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs, BindPointsD3D11*& pBindPoints) { VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); CBs = reinterpret_cast<CachedCB*>(m_pResourceData + m_CBOffset); pd3d11CBs = reinterpret_cast<ID3D11Buffer**>(CBs + GetCBCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits*>(pd3d11CBs + GetCBCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11CBs + GetCBCount()); } - __forceinline void GetSRVArrays(CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs, TBindPointsAndActiveBits*& pBindPoints) + __forceinline void GetSRVArrays(CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs, BindPointsD3D11*& pBindPoints) { VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); SRVResources = reinterpret_cast<CachedResource*>(m_pResourceData + m_SRVOffset); d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView**>(SRVResources + GetSRVCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits*>(d3d11SRVs + GetSRVCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11*>(d3d11SRVs + GetSRVCount()); } - __forceinline void GetSamplerArrays(CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers, TBindPointsAndActiveBits*& pBindPoints) + __forceinline void GetSamplerArrays(CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers, BindPointsD3D11*& pBindPoints) { VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); Samplers = reinterpret_cast<CachedSampler*>(m_pResourceData + m_SamplerOffset); pd3d11Samplers = reinterpret_cast<ID3D11SamplerState**>(Samplers + GetSamplerCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits*>(pd3d11Samplers + GetSamplerCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11Samplers + GetSamplerCount()); } - __forceinline void GetUAVArrays(CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs, TBindPointsAndActiveBits*& pBindPoints) + __forceinline void GetUAVArrays(CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs, BindPointsD3D11*& pBindPoints) { VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); UAVResources = reinterpret_cast<CachedResource*>(m_pResourceData + m_UAVOffset); pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView**>(UAVResources + GetUAVCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits*>(pd3d11UAVs + GetUAVCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11UAVs + GetUAVCount()); } - __forceinline void GetConstCBArrays(CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs, TBindPointsAndActiveBits const*& pBindPoints) const + __forceinline void GetConstCBArrays(CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs, BindPointsD3D11 const*& pBindPoints) const { VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); CBs = reinterpret_cast<CachedCB const*>(m_pResourceData + m_CBOffset); pd3d11CBs = reinterpret_cast<ID3D11Buffer* const*>(CBs + GetCBCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits const*>(pd3d11CBs + GetCBCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11CBs + GetCBCount()); } - __forceinline void GetConstSRVArrays(CachedResource const*& SRVResources, ID3D11ShaderResourceView* const*& d3d11SRVs, TBindPointsAndActiveBits const*& pBindPoints) const + __forceinline void GetConstSRVArrays(CachedResource const*& SRVResources, ID3D11ShaderResourceView* const*& d3d11SRVs, BindPointsD3D11 const*& pBindPoints) const { VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); SRVResources = reinterpret_cast<CachedResource const*>(m_pResourceData + m_SRVOffset); d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView* const*>(SRVResources + GetSRVCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits const*>(d3d11SRVs + GetSRVCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(d3d11SRVs + GetSRVCount()); } - __forceinline void GetConstSamplerArrays(CachedSampler const*& Samplers, ID3D11SamplerState* const*& pd3d11Samplers, TBindPointsAndActiveBits const*& pBindPoints) const + __forceinline void GetConstSamplerArrays(CachedSampler const*& Samplers, ID3D11SamplerState* const*& pd3d11Samplers, BindPointsD3D11 const*& pBindPoints) const { VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); Samplers = reinterpret_cast<CachedSampler const*>(m_pResourceData + m_SamplerOffset); pd3d11Samplers = reinterpret_cast<ID3D11SamplerState* const*>(Samplers + GetSamplerCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits const*>(pd3d11Samplers + GetSamplerCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11Samplers + GetSamplerCount()); } - __forceinline void GetConstUAVArrays(CachedResource const*& UAVResources, ID3D11UnorderedAccessView* const*& pd3d11UAVs, TBindPointsAndActiveBits const*& pBindPoints) const + __forceinline void GetConstUAVArrays(CachedResource const*& UAVResources, ID3D11UnorderedAccessView* const*& pd3d11UAVs, BindPointsD3D11 const*& pBindPoints) const { VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned"); UAVResources = reinterpret_cast<CachedResource const*>(m_pResourceData + m_UAVOffset); pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView* const*>(UAVResources + GetUAVCount()); - pBindPoints = reinterpret_cast<TBindPointsAndActiveBits const*>(pd3d11UAVs + GetUAVCount()); + pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11UAVs + GetUAVCount()); } __forceinline bool IsInitialized() const @@ -430,39 +425,17 @@ public: private: template <typename TCachedResourceType, typename TGetResourceArraysFunc, typename TSrcResourceType, typename TD3D11ResourceType> - __forceinline void SetD3D11ResourceInternal(Uint32 CacheOffset, Uint32 ArrayIndex, Uint32 Size, TBindPoints SrcBindPoints, TGetResourceArraysFunc GetArrays, TSrcResourceType&& pResource, TD3D11ResourceType* pd3d11Resource) + __forceinline void SetD3D11ResourceInternal(Uint32 CacheOffset, Uint32 Size, BindPointsD3D11 BindPoints, TGetResourceArraysFunc GetArrays, TSrcResourceType&& pResource, TD3D11ResourceType* pd3d11Resource) { - CacheOffset += ArrayIndex; - - TBindPointsAndActiveBits BindPointsAndActiveBits; - auto& ActiveBits = BindPointsAndActiveBits[0]; - auto* BindPoints = &BindPointsAndActiveBits[1]; - - ActiveBits = 0; - for (Uint32 i = 0; i < SrcBindPoints.size(); ++i) - { - if (SrcBindPoints[i] != InvalidBindPoint) - { - auto BindPoint = SrcBindPoints[i] + ArrayIndex; - VERIFY_EXPR(BindPoint < InvalidBindPoint); - BindPoints[i] = static_cast<Uint8>(BindPoint); - ActiveBits |= static_cast<Uint8>(1u << i); - } - else - { - BindPoints[i] = InvalidBindPoint; - } - } - VERIFY(CacheOffset < 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; - TBindPointsAndActiveBits* bindPoints; + TCachedResourceType* Resources; + TD3D11ResourceType** d3d11ResArr; + BindPointsD3D11* bindPoints; (this->*GetArrays)(Resources, d3d11ResArr, bindPoints); Resources[CacheOffset].Set(std::forward<TSrcResourceType>(pResource)); - bindPoints[CacheOffset] = BindPointsAndActiveBits; + bindPoints[CacheOffset] = BindPoints; d3d11ResArr[CacheOffset] = pd3d11Resource; } @@ -487,7 +460,7 @@ private: using OffsetType = Uint16; static constexpr size_t MaxAlignment = std::max(std::max(std::max(alignof(CachedCB), alignof(CachedResource)), - std::max(alignof(CachedSampler), alignof(TBindPoints))), + std::max(alignof(CachedSampler), alignof(BindPointsD3D11))), std::max(std::max(alignof(ID3D11Buffer*), alignof(ID3D11ShaderResourceView*)), std::max(alignof(ID3D11SamplerState*), alignof(ID3D11UnorderedAccessView*)))); diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp index d7febdb0..90962c2f 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp @@ -43,7 +43,7 @@ namespace Diligent { /// Diligent::ShaderVariableManagerD3D11 class -// sizeof(ShaderVariableManagerD3D11) == AZ TODO (Release, x64) +// sizeof(ShaderVariableManagerD3D11) == 56, (Release, x64) class ShaderVariableManagerD3D11 { public: @@ -83,12 +83,12 @@ public: const ResourceAttribs& GetAttribs(Uint32 Index) const; - struct ShaderVariableD3D11Base : ShaderVariableBase<ShaderVariableManagerD3D11, IShaderResourceVariableD3D> + template <typename ThisImplType> + struct ShaderVariableD3D11Base : ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D> { public: ShaderVariableD3D11Base(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableBase<ShaderVariableManagerD3D11, IShaderResourceVariableD3D>{ParentLayout}, - m_ResIndex{ResIndex} + ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D>{ParentLayout, ResIndex} {} // clang-format off @@ -114,57 +114,22 @@ public: } } - virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final - { - return GetDesc().VarType; - } - - virtual void DILIGENT_CALL_TYPE GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final - { - const auto& Desc = GetDesc(); - ResourceDesc.Name = Desc.Name; - ResourceDesc.Type = Desc.ResourceType; - ResourceDesc.ArraySize = Desc.ArraySize; - } - - virtual Uint32 DILIGENT_CALL_TYPE GetIndex() const override final - { - return m_ParentManager.GetVariableIndex(*this); - } - virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const override final { - // AZ TODO + GetResourceDesc(HLSLResDesc); + HLSLResDesc.ShaderRegister = GetAttribs().BindPoints[m_ParentManager.m_ShaderTypeIndex]; } - - private: - const Uint32 m_ResIndex; }; - struct ConstBuffBindInfo final : ShaderVariableD3D11Base + struct ConstBuffBindInfo final : ShaderVariableD3D11Base<ConstBuffBindInfo> { ConstBuffBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<ConstBuffBindInfo>{ParentLayout, ResIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -172,30 +137,15 @@ public: } }; - struct TexSRVBindInfo final : ShaderVariableD3D11Base + struct TexSRVBindInfo final : ShaderVariableD3D11Base<TexSRVBindInfo> { TexSRVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<TexSRVBindInfo>{ParentLayout, ResIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -203,30 +153,15 @@ public: } }; - struct TexUAVBindInfo final : ShaderVariableD3D11Base + struct TexUAVBindInfo final : ShaderVariableD3D11Base<TexUAVBindInfo> { TexUAVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<TexUAVBindInfo>{ParentLayout, ResIndex} {} // Provide non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - __forceinline virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -234,30 +169,15 @@ public: } }; - struct BuffUAVBindInfo final : ShaderVariableD3D11Base + struct BuffUAVBindInfo final : ShaderVariableD3D11Base<BuffUAVBindInfo> { BuffUAVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<BuffUAVBindInfo>{ParentLayout, ResIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -265,30 +185,15 @@ public: } }; - struct BuffSRVBindInfo final : ShaderVariableD3D11Base + struct BuffSRVBindInfo final : ShaderVariableD3D11Base<BuffSRVBindInfo> { BuffSRVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<BuffSRVBindInfo>{ParentLayout, ResIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -296,30 +201,15 @@ public: } }; - struct SamplerBindInfo final : ShaderVariableD3D11Base + struct SamplerBindInfo final : ShaderVariableD3D11Base<SamplerBindInfo> { SamplerBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) : - ShaderVariableD3D11Base{ParentLayout, ResIndex} + ShaderVariableD3D11Base<SamplerBindInfo>{ParentLayout, ResIndex} {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, - Uint32 FirstElement, - Uint32 NumElements) override final - { - const auto& Desc = GetDesc(); - VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final { VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize); @@ -329,10 +219,6 @@ public: void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags); -#ifdef DILIGENT_DEVELOPMENT - bool dvpVerifyBindings() const; -#endif - IShaderResourceVariable* GetVariable(const Char* Name) const; IShaderResourceVariable* GetVariable(Uint32 Index) const; @@ -340,7 +226,7 @@ public: Uint32 GetVariableCount() const; - Uint32 GetVariableIndex(const ShaderVariableD3D11Base& Variable) const; + Uint32 GetVariableIndex(const IShaderResourceVariable& Variable) const; // clang-format off Uint32 GetNumCBs() const { return (m_TexSRVsOffset - 0 ) / sizeof(ConstBuffBindInfo);} @@ -366,13 +252,6 @@ private: SHADER_TYPE ShaderType, D3DShaderResourceCounters& Counters); - template <typename HandlerType> - static void ProcessSignatureResources(const PipelineResourceSignatureD3D11Impl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderType, - HandlerType Handler); - // clang-format off using OffsetType = Uint16; template<typename ResourceType> OffsetType GetResourceOffset()const; @@ -488,6 +367,8 @@ private: OffsetType m_SamplerOffset = 0; OffsetType m_MemorySize = 0; + Uint8 m_ShaderTypeIndex = 0; + #ifdef DILIGENT_DEBUG IMemoryAllocator* m_pDbgAllocator = nullptr; #endif diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index a517a59e..6c62dc89 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -295,7 +295,7 @@ void DeviceContextD3D11Impl::BindShaderResources() #endif pSRB->GetResourceCache().BindResources(*this, Bindings, MinMaxSlot, m_CommittedRes, ActiveStages); } - pSRB->GetSignature()->AddBindings(Bindings); + pSRB->GetSignature()->ShiftBindings(Bindings); } m_BindInfo.StaleSRBMask &= ~m_BindInfo.ActiveSRBMask; @@ -448,8 +448,7 @@ void DeviceContextD3D11Impl::DvpValidateCommittedShaderResources() if (m_BindInfo.CommittedResourcesValidated) return; - // AZ TODO - //m_pPipelineState->DvpVerifySRBResources(m_BindInfo.SRBs.data(), m_BindInfo.BoundResOffsets.data(), static_cast<Uint32>(m_BindInfo.SRBs.size())); + m_pPipelineState->DvpVerifySRBResources(m_BindInfo.SRBs.data(), m_BindInfo.BoundResOffsets.data(), static_cast<Uint32>(m_BindInfo.SRBs.size())); m_BindInfo.CommittedResourcesValidated = true; } #endif @@ -608,6 +607,10 @@ void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags) } } #endif + +#ifdef DILIGENT_DEVELOPMENT + DvpValidateCommittedShaderResources(); +#endif } void DeviceContextD3D11Impl::PrepareForIndexedDraw(DRAW_FLAGS Flags, VALUE_TYPE IndexType) @@ -713,6 +716,9 @@ void DeviceContextD3D11Impl::DispatchCompute(const DispatchComputeAttribs& Attri DvpVerifyCommittedShaders(); } #endif +#ifdef DILIGENT_DEVELOPMENT + DvpValidateCommittedShaderResources(); +#endif m_pd3d11DeviceContext->Dispatch(Attribs.ThreadGroupCountX, Attribs.ThreadGroupCountY, Attribs.ThreadGroupCountZ); } @@ -735,6 +741,9 @@ void DeviceContextD3D11Impl::DispatchComputeIndirect(const DispatchComputeIndire DvpVerifyCommittedShaders(); } #endif +#ifdef DILIGENT_DEVELOPMENT + DvpValidateCommittedShaderResources(); +#endif auto* pd3d11Buff = ValidatedCast<BufferD3D11Impl>(pAttribsBuffer)->GetD3D11Buffer(); m_pd3d11DeviceContext->DispatchIndirect(pd3d11Buff, Attribs.DispatchArgsByteOffset); diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp index aab59266..4e3fdea4 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp @@ -175,15 +175,14 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout() TBindings32 ResourceCount = {}; TBindingsPerStage32 BindingPerStage = {}; - const auto AllocBindPoints = [&BindingPerStage](TBindPoints& BindPoints, SHADER_TYPE ShaderStages, Uint32 ArraySize, DESCRIPTOR_RANGE Range) // + const auto AllocBindPoints = [&BindingPerStage](BindPointsD3D11& BindPoints, SHADER_TYPE ShaderStages, Uint32 ArraySize, DESCRIPTOR_RANGE Range) // { while (ShaderStages != 0) { auto Stage = ExtractLSB(ShaderStages); Uint32 ShaderInd = GetShaderTypeIndex(Stage); - BindPoints[ShaderInd] = static_cast<Uint8>(BindingPerStage[ShaderInd][Range]); - VERIFY_EXPR(BindPoints[ShaderInd] == BindingPerStage[ShaderInd][Range]); + BindPoints.Set(ShaderInd, BindingPerStage[ShaderInd][Range]); BindingPerStage[ShaderInd][Range] += ArraySize; } }; @@ -340,7 +339,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache if (!SrcCachedRes.pBuff) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); - DstResourceCache.SetCB(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<BufferD3D11Impl>{SrcCachedRes.pBuff}); + DstResourceCache.SetCB(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferD3D11Impl>{SrcCachedRes.pBuff}); } break; case DESCRIPTOR_RANGE_SRV: @@ -351,9 +350,9 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); if (SrcCachedRes.pTexture) - DstResourceCache.SetTexSRV(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()}); + DstResourceCache.SetTexSRV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()}); else - DstResourceCache.SetBufSRV(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()}); + DstResourceCache.SetBufSRV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()}); } break; case DESCRIPTOR_RANGE_SAMPLER: @@ -366,7 +365,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache if (!SrcCachedRes.pSampler) LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); - DstResourceCache.SetSampler(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<SamplerD3D11Impl>{SrcCachedRes.pSampler}); + DstResourceCache.SetSampler(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<SamplerD3D11Impl>{SrcCachedRes.pSampler}); } } break; @@ -378,9 +377,9 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'."); if (SrcCachedRes.pTexture) - DstResourceCache.SetTexUAV(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()}); + DstResourceCache.SetTexUAV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()}); else - DstResourceCache.SetBufUAV(ResAttr.CacheOffset, ArrInd, ResAttr.BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()}); + DstResourceCache.SetBufUAV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()}); } break; default: @@ -405,7 +404,7 @@ void PipelineResourceSignatureD3D11Impl::InitSRBResourceCache(ShaderResourceCach VERIFY_EXPR(ImtblSampAttr.ArraySize > 0); for (Uint32 ArrInd = 0; ArrInd < ImtblSampAttr.ArraySize; ++ArrInd) - ResourceCache.SetSampler(ImtblSampAttr.CacheOffset, ArrInd, ImtblSampAttr.BindPoints, pSampler); + ResourceCache.SetSampler(ImtblSampAttr.CacheOffset + ArrInd, ImtblSampAttr.BindPoints + ArrInd, pSampler); } } } @@ -423,7 +422,7 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource if ((ResDesc.ShaderStages & ShaderStage) != 0) { - VERIFY_EXPR(ResAttr.BindPoints[ShaderInd] != InvalidBindPoint); + VERIFY_EXPR(ResAttr.BindPoints.IsValid(ShaderInd)); ResourceBinding::BindInfo BindInfo // { Uint32{BaseBindings[ShaderInd][Range]} + ResAttr.BindPoints[ShaderInd], @@ -446,7 +445,7 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource if ((ImtblSam.ShaderStages & ShaderStage) != 0 && SampAttr.IsAllocated()) { - VERIFY_EXPR(SampAttr.BindPoints[ShaderInd] != InvalidBindPoint); + VERIFY_EXPR(SampAttr.BindPoints.IsValid(ShaderInd)); String SampName{ImtblSam.SamplerOrTextureName}; if (IsUsingCombinedSamplers()) @@ -473,16 +472,92 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource } } -// AZ TODO -#if 0 //def DILIGENT_DEVELOPMENT -bool PipelineResourceSignatureGLImpl::DvpValidateCommittedResource(const D3DShaderResourceAttribs& D3DAttribs, - RESOURCE_DIMENSION ResourceDim, - bool IsMultisample, - Uint32 ResIndex, - const ShaderResourceCacheD3D11& ResourceCache, - const char* ShaderName, - const char* PSOName) const +#ifdef DILIGENT_DEVELOPMENT +bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DShaderResourceAttribs& D3DAttribs, + Uint32 ResIndex, + const ShaderResourceCacheD3D11& ResourceCache, + const char* ShaderName, + const char* PSOName) const { + VERIFY_EXPR(ResIndex < m_Desc.NumResources); + const auto& ResDesc = m_Desc.Resources[ResIndex]; + const auto& ResAttr = m_pResourceAttribs[ResIndex]; + VERIFY(strcmp(ResDesc.Name, D3DAttribs.Name) == 0, "Inconsistent resource names"); + + VERIFY_EXPR(D3DAttribs.BindCount <= ResDesc.ArraySize); + + bool BindingsOK = true; + switch (ShaderResourceToDescriptorRange(ResDesc.ResourceType)) + { + case DESCRIPTOR_RANGE_CBV: + for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) + { + if (!ResourceCache.IsCBBound(ResAttr.CacheOffset + ArrInd)) + { + LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), + "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); + BindingsOK = false; + } + } + break; + + case DESCRIPTOR_RANGE_SAMPLER: + for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) + { + if (!ResourceCache.IsSamplerBound(ResAttr.CacheOffset + ArrInd)) + { + LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), + "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); + BindingsOK = false; + } + } + break; + + case DESCRIPTOR_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.CacheOffset + ArrInd, IsTexView)) + { + LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), + "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); + BindingsOK = false; + continue; + } + + const auto& SRV = ResourceCache.GetSRV(ResAttr.CacheOffset + ArrInd); + if (SRV.pTexture) + ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, SRV.pView.RawPtr<ITextureView>(), D3DAttribs.GetResourceDimension(), D3DAttribs.IsMultisample()); + else + ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, SRV.pView.RawPtr<IBufferView>(), D3DAttribs.GetResourceDimension(), D3DAttribs.IsMultisample()); + } + break; + + case DESCRIPTOR_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.CacheOffset + ArrInd, IsTexView)) + { + LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd), + "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); + BindingsOK = false; + continue; + } + + const auto& UAV = ResourceCache.GetUAV(ResAttr.CacheOffset + ArrInd); + if (UAV.pTexture) + ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, UAV.pView.RawPtr<ITextureView>(), D3DAttribs.GetResourceDimension(), D3DAttribs.IsMultisample()); + else + ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, UAV.pView.RawPtr<IBufferView>(), D3DAttribs.GetResourceDimension(), D3DAttribs.IsMultisample()); + } + break; + + default: + UNEXPECTED("Unsupported descriptor range type."); + } + + return BindingsOK; } #endif // DILIGENT_DEVELOPMENT diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 2cedc96a..bd74ea9b 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -39,60 +39,6 @@ namespace Diligent { namespace { -void GetShaderResourceTypeAndFlags(const D3DShaderResourceAttribs& Attribs, - SHADER_RESOURCE_TYPE& OutType, - PIPELINE_RESOURCE_FLAGS& OutFlags) -{ - OutFlags = PIPELINE_RESOURCE_FLAG_UNKNOWN; - - switch (int{Attribs.GetInputType()}) - { - case D3D_SIT_CBUFFER: - OutType = SHADER_RESOURCE_TYPE_CONSTANT_BUFFER; - break; - case D3D_SIT_TBUFFER: - UNSUPPORTED("TBuffers are not supported"); - OutType = SHADER_RESOURCE_TYPE_TEXTURE_SRV; - break; - case D3D_SIT_TEXTURE: - if (Attribs.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER) - { - OutType = SHADER_RESOURCE_TYPE_BUFFER_SRV; - OutFlags = PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER; - } - else - OutType = SHADER_RESOURCE_TYPE_TEXTURE_SRV; - break; - case D3D_SIT_SAMPLER: - OutType = SHADER_RESOURCE_TYPE_SAMPLER; - break; - case D3D_SIT_UAV_RWTYPED: - if (Attribs.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER) - { - OutType = SHADER_RESOURCE_TYPE_BUFFER_UAV; - OutFlags = PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER; - } - else - OutType = SHADER_RESOURCE_TYPE_TEXTURE_UAV; - break; - case D3D_SIT_STRUCTURED: - case D3D_SIT_BYTEADDRESS: - OutType = SHADER_RESOURCE_TYPE_BUFFER_SRV; - break; - case D3D_SIT_UAV_RWSTRUCTURED: - case D3D_SIT_UAV_RWBYTEADDRESS: - case D3D_SIT_UAV_APPEND_STRUCTURED: - case D3D_SIT_UAV_CONSUME_STRUCTURED: - case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER: - OutType = SHADER_RESOURCE_TYPE_BUFFER_UAV; - break; - default: - UNEXPECTED("Unknown HLSL resource type"); - OutType = SHADER_RESOURCE_TYPE_UNKNOWN; - break; - } -} - void VerifyResourceMerge(const PipelineStateDesc& PSODesc, const D3DShaderResourceAttribs& ExistingRes, const D3DShaderResourceAttribs& NewResAttribs) @@ -267,7 +213,7 @@ void PipelineStateD3D11Impl::InitResourceLayouts(const PipelineStateCreateInfo& VERIFY_EXPR(pSignature->GetDesc().BindingIndex == sign); pSignature->UpdateShaderResourceBindingMap(ResourceMap, ShaderType, BindingsPerStage); - pSignature->AddBindings(BindingsPerStage); + pSignature->ShiftBindings(BindingsPerStage); } ValidateShaderResources(pShader); @@ -292,7 +238,7 @@ void PipelineStateD3D11Impl::InitResourceLayouts(const PipelineStateCreateInfo& { const auto& pSignature = m_Signatures[sign]; if (pSignature != nullptr) - pSignature->AddBindings(BindingsPerStage); + pSignature->ShiftBindings(BindingsPerStage); } for (Uint32 s = 0; s < BindingsPerStage.size(); ++s) @@ -571,4 +517,69 @@ void PipelineStateD3D11Impl::ValidateShaderResources(const ShaderD3D11Impl* pSha ); } +#ifdef DILIGENT_DEVELOPMENT +void PipelineStateD3D11Impl::DvpVerifySRBResources(class ShaderResourceBindingD3D11Impl* pSRBs[], const TBindingsPerStage BaseBindings[], Uint32 NumSRBs) const +{ + // Verify SRB compatibility with this pipeline + const auto SignCount = GetResourceSignatureCount(); + TBindingsPerStage Bindings = {}; + + if (m_Desc.IsAnyGraphicsPipeline()) + Bindings[GetShaderTypeIndex(SHADER_TYPE_PIXEL)][DESCRIPTOR_RANGE_UAV] = static_cast<Uint8>(GetGraphicsPipelineDesc().NumRenderTargets); + + for (Uint32 sign = 0; sign < SignCount; ++sign) + { + // Get resource signature from the root signature + const auto* pSignature = GetResourceSignature(sign); + if (pSignature == nullptr || pSignature->GetTotalResourceCount() == 0) + continue; // Skip null and empty signatures + + VERIFY_EXPR(pSignature->GetDesc().BindingIndex == sign); + const auto* const pSRB = pSRBs[sign]; + if (pSRB == nullptr) + { + LOG_ERROR_MESSAGE("Pipeline state '", m_Desc.Name, "' requires SRB at index ", sign, " but none is bound in the device context."); + continue; + } + + const auto* const pSRBSign = pSRB->GetSignature(); + if (!pSignature->IsCompatibleWith(pSRBSign)) + { + LOG_ERROR_MESSAGE("Shader resource binding at index ", sign, " with signature '", pSRBSign->GetDesc().Name, + "' is not compatible with pipeline layout in current pipeline '", m_Desc.Name, "'."); + } + + DEV_CHECK_ERR(Bindings == BaseBindings[sign], + "Bound resources has incorrect base binding indices, this may indicate a bug in resource signature compatibility comparison."); + + pSignature->ShiftBindings(Bindings); + } + + auto attrib_it = m_ResourceAttibutions.begin(); + for (const auto& pResources : m_ShaderResources) + { + pResources->ProcessResources( + [&](const D3DShaderResourceAttribs& Attribs, Uint32) // + { + if (*attrib_it && !attrib_it->IsImmutableSampler()) + { + if (attrib_it->SignatureIndex >= NumSRBs || pSRBs[attrib_it->SignatureIndex] == nullptr) + { + LOG_ERROR_MESSAGE("No resource is bound to variable '", Attribs.Name, "' in shader '", pResources->GetShaderName(), + "' of PSO '", m_Desc.Name, "': SRB at index ", attrib_it->SignatureIndex, " is not bound in the context."); + return; + } + + const auto& SRBCache = pSRBs[attrib_it->SignatureIndex]->GetResourceCache(); + attrib_it->pSignature->DvpValidateCommittedResource(Attribs, attrib_it->ResourceIndex, SRBCache, pResources->GetShaderName(), m_Desc.Name); + } + ++attrib_it; + } // + ); + } + VERIFY_EXPR(attrib_it == m_ResourceAttibutions.end()); +} + +#endif // DILIGENT_DEVELOPMENT + } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp index 9985c56d..52b2e638 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp @@ -45,10 +45,10 @@ size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TResourceCount& Res auto SamplerCount = ResCount[DESCRIPTOR_RANGE_SAMPLER];
auto UAVCount = ResCount[DESCRIPTOR_RANGE_UAV];
size_t MemSize = 0;
- MemSize = Align(MemSize + (sizeof(CachedCB) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment);
- MemSize = Align(MemSize + (sizeof(CachedResource) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment);
- MemSize = Align(MemSize + (sizeof(CachedSampler) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment);
- MemSize = Align(MemSize + (sizeof(CachedResource) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment);
+ MemSize = Align(MemSize + (sizeof(CachedCB) + sizeof(BindPointsD3D11) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment);
+ MemSize = Align(MemSize + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment);
+ MemSize = Align(MemSize + (sizeof(CachedSampler) + sizeof(BindPointsD3D11) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment);
+ MemSize = Align(MemSize + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment);
// clang-format on
VERIFY(MemSize < InvalidResourceOffset, "Memory size exeed the maximum allowed size.");
return MemSize;
@@ -80,10 +80,10 @@ void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemor VERIFY(UAVCount == m_UAVCount, "UAVs count (", UAVCount, ") exceeds maximum representable value");
// m_CBOffset = 0
- m_SRVOffset = static_cast<OffsetType>(Align(m_CBOffset + (sizeof(CachedCB) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment));
- m_SamplerOffset = static_cast<OffsetType>(Align(m_SRVOffset + (sizeof(CachedResource) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment));
- m_UAVOffset = static_cast<OffsetType>(Align(m_SamplerOffset + (sizeof(CachedSampler) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment));
- size_t BufferSize = static_cast<OffsetType>(Align(m_UAVOffset + (sizeof(CachedResource) + sizeof(TBindPointsAndActiveBits) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment));
+ m_SRVOffset = static_cast<OffsetType>(Align(m_CBOffset + (sizeof(CachedCB) + sizeof(BindPointsD3D11) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment));
+ m_SamplerOffset = static_cast<OffsetType>(Align(m_SRVOffset + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment));
+ m_UAVOffset = static_cast<OffsetType>(Align(m_SamplerOffset + (sizeof(CachedSampler) + sizeof(BindPointsD3D11) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment));
+ size_t BufferSize = static_cast<OffsetType>(Align(m_UAVOffset + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment));
// clang-format on
VERIFY_EXPR(m_pResourceData == nullptr);
@@ -96,19 +96,17 @@ void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemor m_pAllocator = &MemAllocator;
}
- const TBindPointsAndActiveBits InvalidBindPoints = {0, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint, InvalidBindPoint};
-
// Explicitly construct all objects
if (CBCount != 0)
{
- CachedCB* CBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ CachedCB* CBs = nullptr;
+ ID3D11Buffer** d3d11CBs = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetCBArrays(CBs, d3d11CBs, bindPoints);
for (Uint32 cb = 0; cb < CBCount; ++cb)
{
new (CBs + cb) CachedCB{};
- bindPoints[cb] = InvalidBindPoints;
+ new (bindPoints + cb) BindPointsD3D11{};
}
}
@@ -116,25 +114,25 @@ void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemor {
CachedResource* SRVResources = nullptr;
ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
for (Uint32 srv = 0; srv < SRVCount; ++srv)
{
new (SRVResources + srv) CachedResource{};
- bindPoints[srv] = InvalidBindPoints;
+ new (bindPoints + srv) BindPointsD3D11{};
}
}
if (SamplerCount != 0)
{
- CachedSampler* Samplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ CachedSampler* Samplers = nullptr;
+ ID3D11SamplerState** d3d11Samplers = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetSamplerArrays(Samplers, d3d11Samplers, bindPoints);
for (Uint32 sam = 0; sam < SamplerCount; ++sam)
{
new (Samplers + sam) CachedSampler{};
- bindPoints[sam] = InvalidBindPoints;
+ new (bindPoints + sam) BindPointsD3D11{};
}
}
@@ -142,12 +140,12 @@ void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemor {
CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
for (Uint32 uav = 0; uav < UAVCount; ++uav)
{
new (UAVResources + uav) CachedResource{};
- bindPoints[uav] = InvalidBindPoints;
+ new (bindPoints + uav) BindPointsD3D11{};
}
}
}
@@ -160,9 +158,9 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() auto CBCount = GetCBCount();
if (CBCount != 0)
{
- CachedCB* CBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ CachedCB* CBs = nullptr;
+ ID3D11Buffer** d3d11CBs = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetCBArrays(CBs, d3d11CBs, bindPoints);
for (size_t cb = 0; cb < CBCount; ++cb)
CBs[cb].~CachedCB();
@@ -173,7 +171,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedResource* SRVResources = nullptr;
ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
for (size_t srv = 0; srv < SRVCount; ++srv)
SRVResources[srv].~CachedResource();
@@ -182,9 +180,9 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() auto SamplerCount = GetSamplerCount();
if (SamplerCount != 0)
{
- CachedSampler* Samplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ CachedSampler* Samplers = nullptr;
+ ID3D11SamplerState** d3d11Samplers = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetSamplerArrays(Samplers, d3d11Samplers, bindPoints);
for (size_t sam = 0; sam < SamplerCount; ++sam)
Samplers[sam].~CachedSampler();
@@ -195,7 +193,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11() {
CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
for (size_t uav = 0; uav < UAVCount; ++uav)
UAVResources[uav].~CachedResource();
@@ -276,7 +274,7 @@ void ShaderResourceCacheD3D11::DvpVerifyCacheConsistency() ID3D11SamplerState** d3d11Samplers = nullptr;
CachedResource* UAVResources = nullptr;
ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- TBindPointsAndActiveBits* bindPoints = nullptr;
+ BindPointsD3D11* bindPoints = nullptr;
GetCBArrays(CBs, d3d11CBs, bindPoints);
GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
@@ -331,28 +329,28 @@ void ShaderResourceCacheD3D11::ProcessResources(THandleResource HandleResources) {
ShaderResourceCacheD3D11::CachedCB* CachedCBs;
ID3D11Buffer** d3d11CBs;
- TBindPointsAndActiveBits* bindPoints;
+ BindPointsD3D11* bindPoints;
GetCBArrays(CachedCBs, d3d11CBs, bindPoints);
HandleResources(GetCBCount(), CachedCBs, d3d11CBs);
}
{
ShaderResourceCacheD3D11::CachedResource* CachedSRVResources;
ID3D11ShaderResourceView** d3d11SRVs;
- TBindPointsAndActiveBits* bindPoints;
+ BindPointsD3D11* bindPoints;
GetSRVArrays(CachedSRVResources, d3d11SRVs, bindPoints);
HandleResources(GetSRVCount(), CachedSRVResources, d3d11SRVs);
}
{
ShaderResourceCacheD3D11::CachedSampler* CachedSamplers;
ID3D11SamplerState** d3d11Samplers;
- TBindPointsAndActiveBits* bindPoints;
+ BindPointsD3D11* bindPoints;
GetSamplerArrays(CachedSamplers, d3d11Samplers, bindPoints);
HandleResources(GetSamplerCount(), CachedSamplers, d3d11Samplers);
}
{
ShaderResourceCacheD3D11::CachedResource* CachedUAVResources;
ID3D11UnorderedAccessView** d3d11UAVs;
- TBindPointsAndActiveBits* bindPoints;
+ BindPointsD3D11* bindPoints;
GetUAVArrays(CachedUAVResources, d3d11UAVs, bindPoints);
HandleResources(GetUAVCount(), CachedUAVResources, d3d11UAVs);
}
@@ -553,19 +551,19 @@ void ShaderResourceCacheD3D11::BindResources(DeviceContextD3D11Impl& Ctx, const const auto Range = DESCRIPTOR_RANGE_CBV;
ShaderResourceCacheD3D11::CachedCB const* CBs;
ID3D11Buffer* const* d3d11CBs;
- TBindPointsAndActiveBits const* bindPoints;
+ BindPointsD3D11 const* bindPoints;
GetConstCBArrays(CBs, d3d11CBs, bindPoints);
for (Uint32 cb = 0; cb < CBCount; ++cb)
{
- Uint32 ActiveBits = bindPoints[cb][0] & ActiveStages;
- const auto* BindPoints = &bindPoints[cb][1];
+ const auto& BindPoints = bindPoints[cb];
+ Uint32 ActiveBits = BindPoints.GetActiveBits() & ActiveStages;
VERIFY(ActiveBits != 0, "resource is not initialized");
while (ActiveBits != 0)
{
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- VERIFY_EXPR(BindPoints[ShaderInd] != InvalidBindPoint);
+ VERIFY_EXPR(BindPoints.IsValid(ShaderInd));
auto* CommittedD3D11CBs = CommittedRes.D3D11CBs[ShaderInd];
UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
@@ -588,19 +586,19 @@ void ShaderResourceCacheD3D11::BindResources(DeviceContextD3D11Impl& Ctx, const const auto Range = DESCRIPTOR_RANGE_SRV;
ShaderResourceCacheD3D11::CachedResource const* SRVResources;
ID3D11ShaderResourceView* const* d3d11SRVs;
- TBindPointsAndActiveBits const* bindPoints;
+ BindPointsD3D11 const* bindPoints;
GetConstSRVArrays(SRVResources, d3d11SRVs, bindPoints);
for (Uint32 srv = 0; srv < SRVCount; ++srv)
{
- Uint32 ActiveBits = bindPoints[srv][0] & ActiveStages;
- const auto* BindPoints = &bindPoints[srv][1];
+ const auto& BindPoints = bindPoints[srv];
+ Uint32 ActiveBits = BindPoints.GetActiveBits() & ActiveStages;
VERIFY(ActiveBits != 0, "resource is not initialized");
while (ActiveBits != 0)
{
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- VERIFY_EXPR(BindPoints[ShaderInd] != InvalidBindPoint);
+ VERIFY_EXPR(BindPoints.IsValid(ShaderInd));
auto* CommittedD3D11SRVs = CommittedRes.D3D11SRVs[ShaderInd];
auto* CommittedD3D11SRVRes = CommittedRes.D3D11SRVResources[ShaderInd];
@@ -625,19 +623,19 @@ void ShaderResourceCacheD3D11::BindResources(DeviceContextD3D11Impl& Ctx, const const auto Range = DESCRIPTOR_RANGE_SAMPLER;
ShaderResourceCacheD3D11::CachedSampler const* Samplers;
ID3D11SamplerState* const* d3d11Samplers;
- TBindPointsAndActiveBits const* bindPoints;
+ BindPointsD3D11 const* bindPoints;
GetConstSamplerArrays(Samplers, d3d11Samplers, bindPoints);
for (Uint32 sam = 0; sam < SamplerCount; ++sam)
{
- Uint32 ActiveBits = bindPoints[sam][0] & ActiveStages;
- const auto* BindPoints = &bindPoints[sam][1];
+ const auto& BindPoints = bindPoints[sam];
+ Uint32 ActiveBits = BindPoints.GetActiveBits() & ActiveStages;
VERIFY(ActiveBits != 0, "resource is not initialized");
while (ActiveBits != 0)
{
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- VERIFY_EXPR(BindPoints[ShaderInd] != InvalidBindPoint);
+ VERIFY_EXPR(BindPoints.IsValid(ShaderInd));
auto* CommittedD3D11Samplers = CommittedRes.D3D11Samplers[ShaderInd];
UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
@@ -660,19 +658,19 @@ void ShaderResourceCacheD3D11::BindResources(DeviceContextD3D11Impl& Ctx, const const auto Range = DESCRIPTOR_RANGE_UAV;
ShaderResourceCacheD3D11::CachedResource const* UAVResources;
ID3D11UnorderedAccessView* const* d3d11UAVs;
- TBindPointsAndActiveBits const* bindPoints;
+ BindPointsD3D11 const* bindPoints;
GetConstUAVArrays(UAVResources, d3d11UAVs, bindPoints);
for (Uint32 uav = 0; uav < UAVCount; ++uav)
{
- Uint32 ActiveBits = bindPoints[uav][0] & ActiveStages;
- const auto* BindPoints = &bindPoints[uav][1];
+ const auto& BindPoints = bindPoints[uav];
+ Uint32 ActiveBits = BindPoints.GetActiveBits() & ActiveStages;
VERIFY(ActiveBits != 0, "resource is not initialized");
while (ActiveBits != 0)
{
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- VERIFY_EXPR(BindPoints[ShaderInd] != InvalidBindPoint);
+ VERIFY_EXPR(BindPoints.IsValid(ShaderInd));
auto* CommittedD3D11UAVs = CommittedRes.D3D11UAVs[ShaderInd];
auto* CommittedD3D11UAVRes = CommittedRes.D3D11UAVResources[ShaderInd];
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index 1b5f3b17..707a4aeb 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -146,23 +146,20 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* ID3D11Resource* CommittedD3D11UAVResources[], ShaderResourceCacheD3D11& ResourceCache) const { - ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; - ID3D11Buffer** d3d11CBs = nullptr; - ShaderResourceCacheD3D11::CachedResource* CachedSRVResources = nullptr; - ID3D11ShaderResourceView** d3d11SRVs = nullptr; - ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr; - ID3D11SamplerState** d3d11Samplers = nullptr; - ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr; - ID3D11UnorderedAccessView** d3d11UAVs = nullptr; - ShaderResourceCacheD3D11::TBindPointsAndActiveBits* CBBindPoints = nullptr; - ShaderResourceCacheD3D11::TBindPointsAndActiveBits* SRVBindPoints = nullptr; - ShaderResourceCacheD3D11::TBindPointsAndActiveBits* SampBindPoints = nullptr; - ShaderResourceCacheD3D11::TBindPointsAndActiveBits* UAVBindPoints = nullptr; + ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; + ID3D11Buffer** d3d11CBs = nullptr; + ShaderResourceCacheD3D11::CachedResource* CachedSRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; + ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr; + ID3D11SamplerState** d3d11Samplers = nullptr; + ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr; + ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + BindPointsD3D11* BindPoints = nullptr; // clang-format off - ResourceCache.GetCBArrays (CachedCBs, d3d11CBs, CBBindPoints); - ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs, SRVBindPoints); - ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers, SampBindPoints); - ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs, UAVBindPoints); + ResourceCache.GetCBArrays (CachedCBs, d3d11CBs, BindPoints); + ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs, BindPoints); + ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers, BindPoints); + ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs, BindPoints); // clang-format on ProcessResources( diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp index 79fdb94a..62e6a845 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp @@ -42,6 +42,30 @@ namespace Diligent { +namespace +{ +template <typename HandlerType> +void ProcessSignatureResources(const PipelineResourceSignatureD3D11Impl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler) +{ + const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers(); + Signature.ProcessResources(AllowedVarTypes, NumAllowedTypes, ShaderStages, + [&](const PipelineResourceDesc& ResDesc, Uint32 Index) // + { + const auto& ResAttr = Signature.GetResourceAttribs(Index); + + // Skip samplers combined with textures and immutable samplers + if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && + (UsingCombinedSamplers || ResAttr.IsImmutableSamplerAssigned())) + return; + + Handler(Index); + }); +} +} // namespace ShaderVariableManagerD3D11::~ShaderVariableManagerD3D11() { @@ -121,43 +145,6 @@ void ShaderVariableManagerD3D11::CountResources(const PipelineResourceSignatureD }); } -template <typename HandlerType> -void ShaderVariableManagerD3D11::ProcessSignatureResources(const PipelineResourceSignatureD3D11Impl& Signature, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderType, - HandlerType Handler) -{ - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers(); - - for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type) - { - const auto VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(var_type); - if (IsAllowedType(VarType, AllowedTypeBits)) - { - const auto ResIdxRange = Signature.GetResourceIndexRange(VarType); - for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r) - { - const auto& Res = Signature.GetResourceDesc(r); - const auto& Attr = Signature.GetResourceAttribs(r); - VERIFY_EXPR(Res.VarType == VarType); - - if ((Res.ShaderStages & ShaderType) == 0) - continue; - - // When using HLSL-style combined image samplers, we need to skip separate samplers. - // Also always skip immutable separate samplers. - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned())) - continue; - - Handler(r); - } - } - } -} - size_t ShaderVariableManagerD3D11::GetRequiredMemorySize(const PipelineResourceSignatureD3D11Impl& Signature, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, @@ -191,7 +178,8 @@ void ShaderVariableManagerD3D11::Initialize(const PipelineResourceSignatureD3D11 D3DShaderResourceCounters ResCounters; CountResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, ResCounters); - m_pSignature = &Signature; + m_pSignature = &Signature; + m_ShaderTypeIndex = static_cast<Uint8>(GetShaderTypeIndex(ShaderType)); // Initialize offsets size_t CurrentOffset = 0; @@ -319,10 +307,11 @@ void ShaderVariableManagerD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* #ifdef DILIGENT_DEVELOPMENT { const auto& CachedCB = ResourceCache.GetCB(Attr.CacheOffset + ArrayIndex); - VerifyConstantBufferBinding(Desc.Name, Desc.ArraySize, Desc.VarType, Desc.Flags, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr()); + VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); } #endif - ResourceCache.SetCB(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pBuffD3D11Impl)); + ResourceCache.SetCB(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pBuffD3D11Impl)); } @@ -342,9 +331,10 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi #ifdef DILIGENT_DEVELOPMENT { auto& CachedSRV = ResourceCache.GetSRV(Attr.CacheOffset + ArrayIndex); - VerifyResourceViewBinding(Desc.Name, Desc.ArraySize, Desc.VarType, ArrayIndex, + VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, - RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr()); + RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); } #endif @@ -383,9 +373,9 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi } } #endif - ResourceCache.SetSampler(SampAttr.CacheOffset, SampArrayIndex, SampAttr.BindPoints, pSamplerD3D11Impl); + ResourceCache.SetSampler(SampAttr.CacheOffset + SampArrayIndex, SampAttr.BindPoints + SampArrayIndex, pSamplerD3D11Impl); } - ResourceCache.SetTexSRV(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pViewD3D11)); + ResourceCache.SetTexSRV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11)); } void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSampler, Uint32 ArrayIndex) @@ -408,9 +398,9 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS "''. Incorect object type: sampler is expected."); } - if (Attr.IsSamplerAssigned()) + if (Attr.IsSamplerAssigned() && !Attr.IsImmutableSamplerAssigned()) { - auto* TexSRVName = m_ParentManager.GetResourceDesc(Attr.SamplerInd).Name; // AZ TODO: check + auto* TexSRVName = m_ParentManager.GetResourceDesc(Attr.SamplerInd).Name; LOG_WARNING_MESSAGE("Texture sampler sampler '", Desc.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."); @@ -429,7 +419,7 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS } #endif - ResourceCache.SetSampler(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pSamplerD3D11)); + ResourceCache.SetSampler(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pSamplerD3D11)); } void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex) @@ -447,12 +437,14 @@ void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pV #ifdef DILIGENT_DEVELOPMENT { auto& CachedSRV = ResourceCache.GetSRV(Attr.CacheOffset + ArrayIndex); - VerifyResourceViewBinding(Desc.Name, Desc.ArraySize, Desc.VarType, ArrayIndex, + VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE}, - RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr()); + RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); + ValidateBufferMode(Desc, ArrayIndex, pViewD3D11.RawPtr()); } #endif - ResourceCache.SetBufSRV(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pViewD3D11)); + ResourceCache.SetBufSRV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11)); } @@ -471,12 +463,13 @@ void ShaderVariableManagerD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVi #ifdef DILIGENT_DEVELOPMENT { auto& CachedUAV = ResourceCache.GetUAV(Attr.CacheOffset + ArrayIndex); - VerifyResourceViewBinding(Desc.Name, Desc.ArraySize, Desc.VarType, ArrayIndex, + VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS}, - RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr()); + RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); } #endif - ResourceCache.SetTexUAV(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pViewD3D11)); + ResourceCache.SetTexUAV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11)); } @@ -495,12 +488,14 @@ void ShaderVariableManagerD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pV #ifdef DILIGENT_DEVELOPMENT { auto& CachedUAV = ResourceCache.GetUAV(Attr.CacheOffset + ArrayIndex); - VerifyResourceViewBinding(Desc.Name, Desc.ArraySize, Desc.VarType, ArrayIndex, + VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS}, - RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr()); + RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); + ValidateBufferMode(Desc, ArrayIndex, pViewD3D11.RawPtr()); } #endif - ResourceCache.SetBufUAV(Attr.CacheOffset, ArrayIndex, Attr.BindPoints, std::move(pViewD3D11)); + ResourceCache.SetBufUAV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11)); } void ShaderVariableManagerD3D11::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) @@ -516,22 +511,22 @@ void ShaderVariableManagerD3D11::BindResources(IResourceMapping* pResourceMappin HandleResources( [&](ConstBuffBindInfo& cb) { - cb.BindResources<ConstBuffBindInfo>(pResourceMapping, Flags); + cb.BindResources(pResourceMapping, Flags); }, [&](TexSRVBindInfo& ts) { - ts.BindResources<TexSRVBindInfo>(pResourceMapping, Flags); + ts.BindResources(pResourceMapping, Flags); }, [&](TexUAVBindInfo& uav) { - uav.BindResources<TexUAVBindInfo>(pResourceMapping, Flags); + uav.BindResources(pResourceMapping, Flags); }, [&](BuffSRVBindInfo& srv) { - srv.BindResources<BuffSRVBindInfo>(pResourceMapping, Flags); + srv.BindResources(pResourceMapping, Flags); }, [&](BuffUAVBindInfo& uav) { - uav.BindResources<BuffUAVBindInfo>(pResourceMapping, Flags); + uav.BindResources(pResourceMapping, Flags); }, [&](SamplerBindInfo& sam) { - sam.BindResources<SamplerBindInfo>(pResourceMapping, Flags); + sam.BindResources(pResourceMapping, Flags); }); } @@ -579,10 +574,10 @@ IShaderResourceVariable* ShaderVariableManagerD3D11::GetVariable(const Char* Nam class ShaderVariableIndexLocator { public: - ShaderVariableIndexLocator(const ShaderVariableManagerD3D11& _Layout, const ShaderVariableManagerD3D11::ShaderVariableD3D11Base& Variable) : + ShaderVariableIndexLocator(const ShaderVariableManagerD3D11& _Mgr, const IShaderResourceVariable& Variable) : // clang-format off - Layout {_Layout}, - VarOffset(reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<const Uint8*>(_Layout.m_ResourceBuffer)) + Mgr {_Mgr}, + VarOffset(reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<const Uint8*>(_Mgr.m_ResourceBuffer)) // clang-format on {} @@ -591,21 +586,21 @@ public: { #ifdef DILIGENT_DEBUG { - VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!"); - dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>(); - VERIFY_EXPR(NextResourceTypeOffset >= Layout.GetResourceOffset<ResourceType>()); + VERIFY(Mgr.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!"); + dbgPreviousResourceOffset = Mgr.GetResourceOffset<ResourceType>(); + VERIFY_EXPR(NextResourceTypeOffset >= Mgr.GetResourceOffset<ResourceType>()); } #endif if (VarOffset < NextResourceTypeOffset) { - auto RelativeOffset = VarOffset - Layout.GetResourceOffset<ResourceType>(); + auto RelativeOffset = VarOffset - Mgr.GetResourceOffset<ResourceType>(); DEV_CHECK_ERR(RelativeOffset % sizeof(ResourceType) == 0, "Offset is not multiple of resource type (", sizeof(ResourceType), ")"); Index += static_cast<Uint32>(RelativeOffset / sizeof(ResourceType)); return true; } else { - Index += Layout.GetNumResources<ResourceType>(); + Index += Mgr.GetNumResources<ResourceType>(); return false; } } @@ -613,7 +608,7 @@ public: Uint32 GetIndex() const { return Index; } private: - const ShaderVariableManagerD3D11& Layout; + const ShaderVariableManagerD3D11& Mgr; const size_t VarOffset; Uint32 Index = 0; #ifdef DILIGENT_DEBUG @@ -621,7 +616,7 @@ private: #endif }; -Uint32 ShaderVariableManagerD3D11::GetVariableIndex(const ShaderVariableD3D11Base& Variable) const +Uint32 ShaderVariableManagerD3D11::GetVariableIndex(const IShaderResourceVariable& Variable) const { if (m_ResourceBuffer == nullptr) { @@ -658,9 +653,9 @@ Uint32 ShaderVariableManagerD3D11::GetVariableIndex(const ShaderVariableD3D11Bas class ShaderVariableLocator { public: - ShaderVariableLocator(const ShaderVariableManagerD3D11& _Layout, Uint32 _Index) : + ShaderVariableLocator(const ShaderVariableManagerD3D11& _Mgr, Uint32 _Index) : // clang-format off - Layout{_Layout}, + Mgr {_Mgr}, Index {_Index } // clang-format on { @@ -671,13 +666,13 @@ public: { #ifdef DILIGENT_DEBUG { - VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!"); - dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>(); + VERIFY(Mgr.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!"); + dbgPreviousResourceOffset = Mgr.GetResourceOffset<ResourceType>(); } #endif - auto NumResources = Layout.GetNumResources<ResourceType>(); + auto NumResources = Mgr.GetNumResources<ResourceType>(); if (Index < NumResources) - return &Layout.GetResource<ResourceType>(Index); + return &Mgr.GetResource<ResourceType>(Index); else { Index -= NumResources; @@ -686,7 +681,7 @@ public: } private: - ShaderVariableManagerD3D11 const& Layout; + ShaderVariableManagerD3D11 const& Mgr; Uint32 Index = 0; #ifdef DILIGENT_DEBUG Uint32 dbgPreviousResourceOffset = 0; @@ -727,131 +722,4 @@ Uint32 ShaderVariableManagerD3D11::GetVariableCount() const return GetNumCBs() + GetNumTexSRVs() + GetNumTexUAVs() + GetNumBufSRVs() + GetNumBufUAVs() + GetNumSamplers(); } -// AZ TODO -#if 0 //def DILIGENT_DEVELOPMENT -bool ShaderVariableManagerD3D11::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) - - m_ResourceCache.DvpVerifyCacheConsistency(); - - bool BindingsOK = true; - HandleConstResources( - [&](const ConstBuffBindInfo& cb) // - { - 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; - } - } - }, - - [&](const TexSRVBindInfo& ts) // - { - 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; - } - - if (ts.ValidSamplerAssigned()) - { - const auto& Sampler = GetConstResource<SamplerBindInfo>(ts.SamplerIndex); - VERIFY_EXPR(Sampler.m_Attribs.BindCount == ts.m_Attribs.BindCount || Sampler.m_Attribs.BindCount == 1); - - // Verify that if single sampler is used for all texture array elements, all samplers set in the resource views are consistent - if (ts.m_Attribs.BindCount > 1 && Sampler.m_Attribs.BindCount == 1) - { - ShaderResourceCacheD3D11::CachedSampler* pCachedSamplers = nullptr; - ID3D11SamplerState** ppCachedD3D11Samplers = nullptr; - m_ResourceCache.GetSamplerArrays(pCachedSamplers, ppCachedD3D11Samplers); - VERIFY_EXPR(Sampler.m_Attribs.BindPoint < m_ResourceCache.GetSamplerCount()); - const auto& CachedSampler = pCachedSamplers[Sampler.m_Attribs.BindPoint]; - - ShaderResourceCacheD3D11::CachedResource* pCachedResources = nullptr; - ID3D11ShaderResourceView** ppCachedD3D11Resources = nullptr; - m_ResourceCache.GetSRVArrays(pCachedResources, ppCachedD3D11Resources); - VERIFY_EXPR(BindPoint < m_ResourceCache.GetSRVCount()); - auto& CachedResource = pCachedResources[BindPoint]; - if (CachedResource.pView) - { - auto* pTexView = CachedResource.pView.RawPtr<ITextureView>(); - 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."); - } - } - } - } - } - }, - - [&](const TexUAVBindInfo& uav) // - { - 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; - } - } - }, - - [&](const BuffSRVBindInfo& buf) // - { - 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; - } - } - }, - - [&](const BuffUAVBindInfo& uav) // - { - 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; - } - } - }, - - [&](const SamplerBindInfo& sam) // - { - 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; - } - } - } // clang-format off - ); // clang-format on -# undef LOG_MISSING_BINDING - - return BindingsOK; -} - -#endif } // namespace Diligent |
