summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2021-03-15 21:44:29 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:23 +0000
commitefc9d06968997f431706680c154c18cca578e146 (patch)
tree644cfdf7d0c6601b42c5ba2a3d094e015faa2c79 /Graphics/GraphicsEngineD3D11
parentGL backend: fixed issue with immutable sampler stages in default signature wi... (diff)
downloadDiligentCore-efc9d06968997f431706680c154c18cca578e146.tar.gz
DiligentCore-efc9d06968997f431706680c154c18cca578e146.zip
Direct3D11: resource cache refactoring
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp11
-rw-r--r--Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp12
-rw-r--r--Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp40
-rw-r--r--Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp465
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp12
-rwxr-xr-xGraphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp418
-rw-r--r--Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp141
-rw-r--r--Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp26
-rwxr-xr-xGraphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp596
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp39
11 files changed, 914 insertions, 848 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
index 9345eacb..712e82ff 100644
--- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
@@ -387,17 +387,8 @@ private:
};
using TBindingsPerStage = PipelineResourceSignatureD3D11Impl::TBindingsPerStage;
- struct MinMaxSlot
- {
- UINT MinSlot = UINT_MAX;
- UINT MaxSlot = 0;
- };
- using TMinMaxSlotPerStage = std::array<std::array<MinMaxSlot, D3D11_RESOURCE_RANGE_COUNT>, NumShaderTypes>;
-
-
void BindCacheResources(const ShaderResourceCacheD3D11& ResourceCache,
- const TBindingsPerStage& Bindings,
- TMinMaxSlotPerStage& MinMaxSlot,
+ const TBindingsPerStage& BaseBindings,
SHADER_TYPE ActiveStages);
#ifdef DILIGENT_DEVELOPMENT
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp
index 1eb7875a..a422f4db 100644
--- a/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/PipelineResourceAttribsD3D11.hpp
@@ -62,6 +62,7 @@ struct BindPointsD3D11
BindPointsD3D11(const BindPointsD3D11&) noexcept = default;
// clang-format off
+ bool IsEmpty() const { return m_ActiveBits == 0; }
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]; }
@@ -113,32 +114,25 @@ private:
struct PipelineResourceAttribsD3D11
{
private:
- static constexpr Uint32 _CacheOffsetBits = 10;
static constexpr Uint32 _SamplerIndBits = 10;
static constexpr Uint32 _SamplerAssignedBits = 1;
public:
- static constexpr Uint32 InvalidCacheOffset = (1u << _CacheOffsetBits) - 1;
- static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1;
+ static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1;
// clang-format off
- const Uint32 CacheOffset : _CacheOffsetBits; // SRB and Signature have the same cache offsets for static resources
- // (thanks to sorting variables by type, where all static vars go first).
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,
- Uint32 _SamplerInd,
+ PipelineResourceAttribsD3D11(Uint32 _SamplerInd,
bool _ImtblSamplerAssigned) noexcept :
// clang-format off
- CacheOffset {_CacheOffset },
SamplerInd {_SamplerInd },
ImtblSamplerAssigned{_ImtblSamplerAssigned ? 1u : 0u}
// clang-format on
{
- VERIFY(CacheOffset == _CacheOffset, "Cache offset (", _CacheOffset, ") exceeds maximum representable value");
VERIFY(SamplerInd == _SamplerInd, "Sampler index (", _SamplerInd, ") exceeds maximum representable value");
}
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp
index 4e30df64..bad9096c 100644
--- a/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/PipelineResourceSignatureD3D11Impl.hpp
@@ -71,28 +71,14 @@ public:
// sizeof(ImmutableSamplerAttribs) == 24, x64
struct ImmutableSamplerAttribs
{
- private:
- static constexpr Uint32 _CacheOffsetBits = 10;
- static constexpr Uint32 _ArraySizeBits = 22;
-
public:
- static constexpr Uint32 InvalidCacheOffset = (1u << _CacheOffsetBits) - 1;
- static_assert(InvalidCacheOffset == ResourceAttribs::InvalidCacheOffset,
- "InvalidCacheOffset value mismatch between ResourceAttribs and ImmutableSamplerAttribs");
-
- // clang-format off
RefCntAutoPtr<ISampler> pSampler;
- Uint32 CacheOffset : _CacheOffsetBits;
- Uint32 ArraySize : _ArraySizeBits;
+ Uint32 ArraySize = 0;
BindPointsD3D11 BindPoints;
- // clang-format on
- ImmutableSamplerAttribs() :
- CacheOffset{InvalidCacheOffset},
- ArraySize{0}
- {}
+ ImmutableSamplerAttribs() noexcept {}
- bool IsAllocated() const { return CacheOffset != InvalidCacheOffset; }
+ bool IsAllocated() const { return !BindPoints.IsEmpty(); }
SamplerD3D11Impl* GetSamplerD3D11() const { return ValidatedCast<SamplerD3D11Impl>(pSampler.RawPtr<ISampler>()); }
};
@@ -102,20 +88,18 @@ public:
return m_ImmutableSamplers[SampIndex];
}
- using TBindings = ShaderResourceCacheD3D11::TResourceCount;
using TResourceCount = std::array<Uint8, D3D11_RESOURCE_RANGE_COUNT>;
- using TBindingsPerStage = std::array<TResourceCount, NumShaderTypes>;
-
+ using TBindingsPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
__forceinline void ShiftBindings(TBindingsPerStage& Bindings) const
{
- for (Uint32 s = 0; s < Bindings.size(); ++s)
+ for (Uint32 r = 0; r < Bindings.size(); ++r)
{
- for (Uint32 i = 0; i < Bindings[s].size(); ++i)
+ for (Uint32 s = 0; s < Bindings[r].size(); ++s)
{
- Uint32 Count = Bindings[s][i] + m_BindingCountPerStage[s][i];
+ Uint32 Count = Bindings[r][s] + m_BindingCountPerStage[r][s];
VERIFY_EXPR(Count < std::numeric_limits<Uint8>::max());
- Bindings[s][i] = static_cast<Uint8>(Count);
+ Bindings[r][s] = static_cast<Uint8>(Count);
}
}
}
@@ -142,11 +126,9 @@ private:
void Destruct();
private:
- TBindings m_ResourceCount = {};
- TBindingsPerStage m_BindingCountPerStage = {};
-
- ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources]
- ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers]
+ TBindingsPerStage m_BindingCountPerStage = {};
+ ResourceAttribs* m_pResourceAttribs = nullptr; // [m_Desc.NumResources]
+ ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers]
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp
index 7aaa4f2b..68dcb479 100644
--- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp
@@ -114,8 +114,6 @@ private:
void ValidateShaderResources(const ShaderD3D11Impl* pShader);
private:
- using SignaturePtr = RefCntAutoPtr<PipelineResourceSignatureD3D11Impl>;
-
std::array<Uint8, 5> m_ShaderTypes = {};
Uint8 m_NumShaders = 0;
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
index ddd0f736..a4112f8a 100644
--- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
@@ -89,7 +89,7 @@ public:
private:
friend class ShaderResourceCacheD3D11;
- __forceinline void Set(RefCntAutoPtr<BufferD3D11Impl>&& _pBuff)
+ __forceinline void Set(RefCntAutoPtr<BufferD3D11Impl> _pBuff)
{
pBuff = std::move(_pBuff);
}
@@ -130,7 +130,7 @@ public:
private:
friend class ShaderResourceCacheD3D11;
- __forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView)
+ __forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
pBuffer = nullptr;
// Avoid unnecessary virtual function calls
@@ -139,7 +139,7 @@ public:
pd3d11Resource = pTexture ? pTexture->TextureBaseD3D11::GetD3D11Texture() : nullptr;
}
- __forceinline void Set(RefCntAutoPtr<BufferViewD3D11Impl>&& pBufView)
+ __forceinline void Set(RefCntAutoPtr<BufferViewD3D11Impl> pBufView)
{
pTexture = nullptr;
// Avoid unnecessary virtual function calls
@@ -149,145 +149,288 @@ public:
}
};
- using TResourceCount = std::array<Uint8, D3D11_RESOURCE_RANGE_COUNT>;
- static size_t GetRequriedMemorySize(const TResourceCount& ResCount);
+ static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes;
+ using TBindingsPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
+
+ static size_t GetRequriedMemorySize(const TBindingsPerStage& ResCount);
- void Initialize(const TResourceCount& ResCount, IMemoryAllocator& MemAllocator);
+ void Initialize(const TBindingsPerStage& ResCount, IMemoryAllocator& MemAllocator);
- __forceinline void SetCB(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl>&& pBuffD3D11Impl)
+ __forceinline void SetCB(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl)
{
auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr;
- SetD3D11ResourceInternal<CachedCB>(CacheOffset, GetCBCount(), BindPoints, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff);
+ SetD3D11ResourceInternal<CachedCB>(BindPoints, &ShaderResourceCacheD3D11::GetCBCount, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff);
}
- __forceinline void SetTexSRV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView)
+ __forceinline void SetTexSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV);
+ SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV);
}
- __forceinline void SetBufSRV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView)
+ __forceinline void SetBufSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
{
auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetSRVCount(), BindPoints, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV);
+ SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV);
}
- __forceinline void SetTexUAV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl>&& pTexView)
+ __forceinline void SetTexUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV);
+ SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV);
}
- __forceinline void SetBufUAV(Uint32 CacheOffset, BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl>&& pBuffView)
+ __forceinline void SetBufUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
{
auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal<CachedResource>(CacheOffset, GetUAVCount(), BindPoints, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV);
+ SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV);
}
- __forceinline void SetSampler(Uint32 CacheOffset, BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler)
+ __forceinline void SetSampler(BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler)
{
auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr;
- SetD3D11ResourceInternal<CachedSampler>(CacheOffset, GetSamplerCount(), BindPoints, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler);
+ SetD3D11ResourceInternal<CachedSampler>(BindPoints, &ShaderResourceCacheD3D11::GetSamplerCount, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler);
}
- __forceinline CachedCB const& GetCB(Uint32 CacheOffset) const
+ __forceinline CachedCB const& GetCB(BindPointsD3D11 BindPoints) const
{
- VERIFY(CacheOffset < GetCBCount(), "CB slot is out of range");
- ShaderResourceCacheD3D11::CachedCB* CBs;
- ID3D11Buffer** pd3d11CBs;
- BindPointsD3D11* bindPoints;
- GetCBArrays(CBs, pd3d11CBs, bindPoints);
- return CBs[CacheOffset];
+ 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]];
}
- __forceinline CachedResource const& GetSRV(Uint32 CacheOffset) const
+ __forceinline CachedResource const& GetSRV(BindPointsD3D11 BindPoints) const
{
- VERIFY(CacheOffset < GetSRVCount(), "SRV slot is out of range");
- ShaderResourceCacheD3D11::CachedResource* SRVResources;
- ID3D11ShaderResourceView** pd3d11SRVs;
- BindPointsD3D11* bindPoints;
- GetSRVArrays(SRVResources, pd3d11SRVs, bindPoints);
- return SRVResources[CacheOffset];
+ 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
+ {
+ 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;
}
- __forceinline CachedResource const& GetUAV(Uint32 CacheOffset) const
+ __forceinline bool CopyUAV(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
{
- VERIFY(CacheOffset < GetUAVCount(), "UAV slot is out of range");
- ShaderResourceCacheD3D11::CachedResource* UAVResources;
- ID3D11UnorderedAccessView** pd3d11UAVs;
- BindPointsD3D11* bindPoints;
- GetUAVArrays(UAVResources, pd3d11UAVs, bindPoints);
- return UAVResources[CacheOffset];
+ bool IsBound = true;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
+ {
+ const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
+ ActiveBits &= ~(1u << ShaderInd);
+
+ CachedResource const* pSrcUAVResources;
+ ID3D11UnorderedAccessView* const* pSrcd3d11UAVs;
+ SrcCache.GetConstUAVArrays(ShaderInd, pSrcUAVResources, pSrcd3d11UAVs);
+
+ CachedResource* pUAVResources;
+ ID3D11UnorderedAccessView** pd3d11UAVs;
+ GetUAVArrays(ShaderInd, pUAVResources, pd3d11UAVs);
+
+ const Uint32 CacheOffset = BindPoints[ShaderInd];
+ VERIFY(CacheOffset < GetUAVCount(ShaderInd), "Index is out of range");
+ if (pSrcUAVResources[CacheOffset].pBuffer == nullptr && pSrcUAVResources[CacheOffset].pTexture == nullptr)
+ IsBound = false;
+
+ pUAVResources[CacheOffset] = pSrcUAVResources[CacheOffset];
+ pd3d11UAVs[CacheOffset] = pSrcd3d11UAVs[CacheOffset];
+ }
+ return IsBound;
}
- __forceinline CachedSampler const& GetSampler(Uint32 CacheOffset) const
+ __forceinline bool CopySampler(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
{
- VERIFY(CacheOffset < GetSamplerCount(), "Sampler slot is out of range");
- ShaderResourceCacheD3D11::CachedSampler* Samplers;
- ID3D11SamplerState** pd3d11Samplers;
- BindPointsD3D11* bindPoints;
- GetSamplerArrays(Samplers, pd3d11Samplers, bindPoints);
- return Samplers[CacheOffset];
+ 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(Uint32 CacheOffset) const
+ __forceinline bool IsCBBound(BindPointsD3D11 BindPoints) const
{
- CachedCB const* CBs;
- ID3D11Buffer* const* d3d11CBs;
- BindPointsD3D11 const* bindPoints;
- GetConstCBArrays(CBs, d3d11CBs, bindPoints);
- if (CacheOffset < GetCBCount() && d3d11CBs[CacheOffset] != nullptr)
+ bool IsBound = true;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
{
- VERIFY(CBs[CacheOffset].pBuff != nullptr, "No relevant buffer resource");
- return true;
+ 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 false;
+ return IsBound;
}
- __forceinline bool IsSRVBound(Uint32 CacheOffset, bool dbgIsTextureView) const
+ __forceinline bool IsSRVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const
{
- CachedResource const* SRVResources;
- ID3D11ShaderResourceView* const* d3d11SRVs;
- BindPointsD3D11 const* bindPoints;
- GetConstSRVArrays(SRVResources, d3d11SRVs, bindPoints);
- if (CacheOffset < GetSRVCount() && d3d11SRVs[CacheOffset] != nullptr)
+ bool IsBound = true;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
{
- VERIFY((dbgIsTextureView && SRVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && SRVResources[CacheOffset].pBuffer != nullptr),
- "No relevant resource");
- return true;
+ 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;
}
- return false;
+ return IsBound;
}
- __forceinline bool IsUAVBound(Uint32 CacheOffset, bool dbgIsTextureView) const
+ __forceinline bool IsUAVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const
{
- CachedResource const* UAVResources;
- ID3D11UnorderedAccessView* const* d3d11UAVs;
- BindPointsD3D11 const* bindPoints;
- GetConstUAVArrays(UAVResources, d3d11UAVs, bindPoints);
- if (CacheOffset < GetUAVCount() && d3d11UAVs[CacheOffset] != nullptr)
+ bool IsBound = true;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
{
- VERIFY((dbgIsTextureView && UAVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && UAVResources[CacheOffset].pBuffer != nullptr),
- "No relevant resource");
- return true;
+ const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
+ 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)
+ {
+ VERIFY((dbgIsTextureView && UAVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && UAVResources[CacheOffset].pBuffer != nullptr),
+ "No relevant resource");
+ continue;
+ }
+ IsBound = false;
}
- return false;
+ return IsBound;
}
- __forceinline bool IsSamplerBound(Uint32 CacheOffset) const
+ __forceinline bool IsSamplerBound(BindPointsD3D11 BindPoints) const
{
- CachedSampler const* Samplers;
- ID3D11SamplerState* const* d3d11Samplers;
- BindPointsD3D11 const* bindPoints;
- GetConstSamplerArrays(Samplers, d3d11Samplers, bindPoints);
- if (CacheOffset < GetSamplerCount() && d3d11Samplers[CacheOffset] != nullptr)
+ bool IsBound = true;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
{
- VERIFY(Samplers[CacheOffset].pSampler != nullptr, "No relevant sampler");
- return true;
+ 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;
}
- return false;
+ return IsBound;
}
#ifdef DILIGENT_DEVELOPMENT
@@ -295,97 +438,116 @@ public:
#endif
// clang-format off
- __forceinline Uint32 GetCBCount() const { return m_CBCount; }
- __forceinline Uint32 GetSRVCount() const { return m_SRVCount; }
- __forceinline Uint32 GetSamplerCount() const { return m_SamplerCount; }
- __forceinline Uint32 GetUAVCount() const { return m_UAVCount; }
+ __forceinline Uint32 GetCBCount (Uint32 ShaderInd) const { return (m_Offsets[CBOffset + ShaderInd + 1] - m_Offsets[CBOffset + ShaderInd]) / (sizeof(CachedCB) + sizeof(ID3D11Buffer*)); }
+ __forceinline Uint32 GetSRVCount (Uint32 ShaderInd) const { return (m_Offsets[SRVOffset + ShaderInd + 1] - m_Offsets[SRVOffset + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)); }
+ __forceinline Uint32 GetSamplerCount(Uint32 ShaderInd) const { return (m_Offsets[SampOffset + ShaderInd + 1] - m_Offsets[SampOffset + ShaderInd]) / (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)); }
+ __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(CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs, BindPointsD3D11*& pBindPoints) const
+ __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_CBOffset);
- pd3d11CBs = reinterpret_cast<ID3D11Buffer**>(CBs + GetCBCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11CBs + GetCBCount());
+ CBs = reinterpret_cast<CachedCB*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]);
+ pd3d11CBs = reinterpret_cast<ID3D11Buffer**>(CBs + GetCBCount(ShaderInd));
}
- __forceinline void GetSRVArrays(CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs, BindPointsD3D11*& pBindPoints) const
+ __forceinline void GetSRVArrays(Uint32 ShaderInd, CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs) 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_SRVOffset);
- d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView**>(SRVResources + GetSRVCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11*>(d3d11SRVs + GetSRVCount());
+ SRVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]);
+ d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView**>(SRVResources + GetSRVCount(ShaderInd));
}
- __forceinline void GetSamplerArrays(CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers, BindPointsD3D11*& pBindPoints) const
+ __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_SamplerOffset);
- pd3d11Samplers = reinterpret_cast<ID3D11SamplerState**>(Samplers + GetSamplerCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11Samplers + GetSamplerCount());
+ Samplers = reinterpret_cast<CachedSampler*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]);
+ pd3d11Samplers = reinterpret_cast<ID3D11SamplerState**>(Samplers + GetSamplerCount(ShaderInd));
}
- __forceinline void GetUAVArrays(CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs, BindPointsD3D11*& pBindPoints) const
+ __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_UAVOffset);
- pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView**>(UAVResources + GetUAVCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11*>(pd3d11UAVs + GetUAVCount());
+ UAVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]);
+ pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView**>(UAVResources + GetUAVCount(ShaderInd));
}
- __forceinline void GetConstCBArrays(CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs, BindPointsD3D11 const*& pBindPoints) const
+ __forceinline void GetConstCBArrays(Uint32 ShaderInd, CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs) 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_CBOffset);
- pd3d11CBs = reinterpret_cast<ID3D11Buffer* const*>(CBs + GetCBCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11CBs + GetCBCount());
+ CBs = reinterpret_cast<CachedCB const*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]);
+ pd3d11CBs = reinterpret_cast<ID3D11Buffer* const*>(CBs + GetCBCount(ShaderInd));
}
- __forceinline void GetConstSRVArrays(CachedResource const*& SRVResources, ID3D11ShaderResourceView* const*& d3d11SRVs, BindPointsD3D11 const*& pBindPoints) const
+ __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_SRVOffset);
- d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView* const*>(SRVResources + GetSRVCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(d3d11SRVs + GetSRVCount());
+ SRVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]);
+ d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView* const*>(SRVResources + GetSRVCount(ShaderInd));
}
- __forceinline void GetConstSamplerArrays(CachedSampler const*& Samplers, ID3D11SamplerState* const*& pd3d11Samplers, BindPointsD3D11 const*& pBindPoints) const
+ __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_SamplerOffset);
- pd3d11Samplers = reinterpret_cast<ID3D11SamplerState* const*>(Samplers + GetSamplerCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11Samplers + GetSamplerCount());
+ Samplers = reinterpret_cast<CachedSampler const*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]);
+ pd3d11Samplers = reinterpret_cast<ID3D11SamplerState* const*>(Samplers + GetSamplerCount(ShaderInd));
}
- __forceinline void GetConstUAVArrays(CachedResource const*& UAVResources, ID3D11UnorderedAccessView* const*& pd3d11UAVs, BindPointsD3D11 const*& pBindPoints) const
+ __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_UAVOffset);
- pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView* const*>(UAVResources + GetUAVCount());
- pBindPoints = reinterpret_cast<BindPointsD3D11 const*>(pd3d11UAVs + GetUAVCount());
+ UAVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]);
+ pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView* const*>(UAVResources + GetUAVCount(ShaderInd));
}
- __forceinline bool IsInitialized() const
- {
- return m_UAVOffset != InvalidResourceOffset;
- }
+ bool IsInitialized() const { return m_IsInitialized; }
ResourceCacheContentType GetContentType() const { return m_ContentType; }
+ void BindCBs(Uint32 ShaderInd,
+ ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const;
+ void BindSRVs(Uint32 ShaderInd,
+ ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
+ ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const;
+ void BindSamplers(Uint32 ShaderInd,
+ ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const;
+ void BindUAVs(Uint32 ShaderInd,
+ ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT],
+ ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const;
+
private:
- template <typename TCachedResourceType, typename TGetResourceArraysFunc, typename TSrcResourceType, typename TD3D11ResourceType>
- __forceinline void SetD3D11ResourceInternal(Uint32 CacheOffset, Uint32 Size, BindPointsD3D11 BindPoints, TGetResourceArraysFunc GetArrays, TSrcResourceType&& pResource, TD3D11ResourceType* pd3d11Resource)
+ template <typename TCachedResourceType, typename TGetResourceCount, typename TGetResourceArraysFunc, typename TSrcResourceType, typename TD3D11ResourceType>
+ __forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TGetResourceCount GetCount, TGetResourceArraysFunc GetArrays, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource)
{
- 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;
- BindPointsD3D11* bindPoints;
- (this->*GetArrays)(Resources, d3d11ResArr, bindPoints);
- Resources[CacheOffset].Set(std::forward<TSrcResourceType>(pResource));
- bindPoints[CacheOffset] = BindPoints;
- d3d11ResArr[CacheOffset] = pd3d11Resource;
+ for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
+ {
+ const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
+ ActiveBits &= ~(1u << ShaderInd);
+
+ const Uint32 CacheOffset = BindPoints[ShaderInd];
+ const Uint32 ResCount = (this->*GetCount)(ShaderInd);
+ VERIFY(CacheOffset < ResCount, "Index is out of range");
+
+ TCachedResourceType* Resources;
+ TD3D11ResourceType** d3d11ResArr;
+ (this->*GetArrays)(ShaderInd, Resources, d3d11ResArr);
+ Resources[CacheOffset].Set(pResource);
+ d3d11ResArr[CacheOffset] = pd3d11Resource;
+ }
}
// Transitions or verifies the resource state.
@@ -404,36 +566,19 @@ private:
private:
using OffsetType = Uint16;
- static constexpr size_t MaxAlignment = std::max(std::max(std::max(alignof(CachedCB), alignof(CachedResource)),
- std::max(alignof(CachedSampler), alignof(BindPointsD3D11))),
+ static constexpr size_t MaxAlignment = std::max(std::max(std::max(alignof(CachedCB), alignof(CachedResource)), alignof(CachedSampler)),
std::max(std::max(alignof(ID3D11Buffer*), alignof(ID3D11ShaderResourceView*)),
std::max(alignof(ID3D11SamplerState*), alignof(ID3D11UnorderedAccessView*))));
- static constexpr OffsetType InvalidResourceOffset = std::numeric_limits<OffsetType>::max();
+ static constexpr Uint32 CBOffset = 0;
+ static constexpr Uint32 SRVOffset = CBOffset + NumShaderTypes;
+ static constexpr Uint32 SampOffset = SRVOffset + NumShaderTypes;
+ static constexpr Uint32 UAVOffset = SampOffset + NumShaderTypes;
+ static constexpr Uint32 MaxOffsets = UAVOffset + NumShaderTypes + 1;
- static constexpr OffsetType m_CBOffset = 0;
- OffsetType m_SRVOffset = InvalidResourceOffset;
- OffsetType m_SamplerOffset = InvalidResourceOffset;
- OffsetType m_UAVOffset = InvalidResourceOffset;
+ std::array<OffsetType, MaxOffsets> m_Offsets = {};
- static constexpr Uint32 _CBCountBits = 7;
- static constexpr Uint32 _SRVCountBits = 10;
- static constexpr Uint32 _SampCountBits = 7;
- static constexpr Uint32 _UAVCountBits = 4;
-
- static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes;
-
- // clang-format off
- static_assert((1U << _CBCountBits) >= (D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT * NumShaderTypes), "Not enough bits to represent CB count");
- static_assert((1U << _SRVCountBits) >= (D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT * NumShaderTypes), "Not enough bits to represent SRV count");
- static_assert((1U << _SampCountBits) >= (D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT * NumShaderTypes), "Not enough bits to represent Sampler count");
- static_assert((1U << _UAVCountBits) >= D3D11_PS_CS_UAV_REGISTER_COUNT, "Not enough bits to represent UAV count");
-
- Uint32 m_CBCount : _CBCountBits;
- Uint32 m_SRVCount : _SRVCountBits;
- Uint32 m_SamplerCount : _SampCountBits;
- Uint32 m_UAVCount : _UAVCountBits;
- // clang-format on
+ bool m_IsInitialized = false;
// Indicates what types of resources are stored in the cache
const ResourceCacheContentType m_ContentType;
@@ -441,6 +586,8 @@ private:
std::unique_ptr<Uint8, STDDeleter<Uint8, IMemoryAllocator>> m_pResourceData;
};
+static constexpr size_t ResCacheSize = sizeof(ShaderResourceCacheD3D11);
+
// Instantiate templates
template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Transition>(DeviceContextD3D11Impl& Ctx);
template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Verify>(DeviceContextD3D11Impl& Ctx);
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp
index 90962c2f..74bd96a2 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().CacheOffset + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsCBBound(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().CacheOffset + ArrayIndex, true);
+ return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, true);
}
};
@@ -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().CacheOffset + ArrayIndex, true);
+ return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, true);
}
};
@@ -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().CacheOffset + ArrayIndex, false);
+ return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, false);
}
};
@@ -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().CacheOffset + ArrayIndex, false);
+ return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, false);
}
};
@@ -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().CacheOffset + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsSamplerBound(GetAttribs().BindPoints + ArrayIndex);
}
};
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
index a601da70..40ce63c9 100755
--- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
@@ -266,310 +266,160 @@ void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding* pShad
void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11& ResourceCache,
const TBindingsPerStage& BaseBindings,
- TMinMaxSlotPerStage& MinMaxSlot,
SHADER_TYPE ActiveStages)
{
- const auto CBCount = ResourceCache.GetCBCount();
- if (CBCount != 0)
+ struct MinMaxSlot
{
- constexpr auto Range = D3D11_RESOURCE_RANGE_CBV;
- ShaderResourceCacheD3D11::CachedCB const* CBs;
- ID3D11Buffer* const* d3d11CBs;
- BindPointsD3D11 const* bindPoints;
- ResourceCache.GetConstCBArrays(CBs, d3d11CBs, bindPoints);
+ UINT MinSlot = UINT_MAX;
+ UINT MaxSlot = 0;
+ };
+ using TMinMaxSlotPerStage = std::array<MinMaxSlot, NumShaderTypes>;
+ using TBindings = TBindingsPerStage::value_type;
- for (Uint32 cb = 0; cb < CBCount; ++cb)
- {
- 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.IsValid(ShaderInd));
-
- auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderInd];
- UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- UINT& MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- const UINT Slot = BaseBindings[ShaderInd][Range] + BindPoints[ShaderInd];
- const bool IsNewCB = CommittedD3D11CBs[Slot] != d3d11CBs[cb];
- MinSlot = IsNewCB ? std::min(MinSlot, Slot) : MinSlot;
- MaxSlot = IsNewCB ? Slot : MaxSlot;
-
- VERIFY_EXPR(!IsNewCB || (Slot >= MinSlot && Slot <= MaxSlot));
- VERIFY_EXPR(d3d11CBs[cb] != nullptr);
- CommittedD3D11CBs[Slot] = d3d11CBs[cb];
- }
- }
- }
+ Uint8 ShaderIndices[NumShaderTypes] = {};
+ SHADER_TYPE ShaderTypes[NumShaderTypes] = {};
+ Uint32 ShaderCount = 0;
- const auto SRVCount = ResourceCache.GetSRVCount();
- if (SRVCount != 0)
+ for (Uint32 Stages = ActiveStages; Stages != 0; ++ShaderCount)
{
- constexpr auto Range = D3D11_RESOURCE_RANGE_SRV;
- ShaderResourceCacheD3D11::CachedResource const* SRVResources;
- ID3D11ShaderResourceView* const* d3d11SRVs;
- BindPointsD3D11 const* bindPoints;
- ResourceCache.GetConstSRVArrays(SRVResources, d3d11SRVs, bindPoints);
-
- for (Uint32 srv = 0; srv < SRVCount; ++srv)
- {
- 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.IsValid(ShaderInd));
-
- auto* CommittedD3D11SRVs = m_CommittedRes.D3D11SRVs[ShaderInd];
- auto* CommittedD3D11SRVRes = m_CommittedRes.D3D11SRVResources[ShaderInd];
- UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- UINT& MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- const UINT Slot = BaseBindings[ShaderInd][Range] + BindPoints[ShaderInd];
- const bool IsNewSRV = CommittedD3D11SRVs[Slot] != d3d11SRVs[srv];
- MinSlot = IsNewSRV ? std::min(MinSlot, Slot) : MinSlot;
- MaxSlot = IsNewSRV ? Slot : MaxSlot;
-
- VERIFY_EXPR(!IsNewSRV || (Slot >= MinSlot && Slot <= MaxSlot));
- VERIFY_EXPR(d3d11SRVs[srv] != nullptr);
- CommittedD3D11SRVRes[Slot] = SRVResources[srv].pd3d11Resource;
- CommittedD3D11SRVs[Slot] = d3d11SRVs[srv];
- }
- }
+ const Uint32 ShaderInd = PlatformMisc::GetLSB(Stages);
+ Stages &= ~(1u << ShaderInd);
+ ShaderIndices[ShaderCount] = static_cast<Uint8>(ShaderInd);
+ ShaderTypes[ShaderCount] = static_cast<SHADER_TYPE>(1u << ShaderInd);
}
- const auto SamplerCount = ResourceCache.GetSamplerCount();
- if (SamplerCount != 0)
+ for (Uint32 i = 0; i < ShaderCount; ++i)
{
- constexpr auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
- ShaderResourceCacheD3D11::CachedSampler const* Samplers;
- ID3D11SamplerState* const* d3d11Samplers;
- BindPointsD3D11 const* bindPoints;
- ResourceCache.GetConstSamplerArrays(Samplers, d3d11Samplers, bindPoints);
+ constexpr auto Range = D3D11_RESOURCE_RANGE_CBV;
+ const auto ShaderInd = ShaderIndices[i];
+ auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderInd];
+ Uint8 Binding = BaseBindings[Range][ShaderInd];
+ Uint32 MinSlot = UINT_MAX;
+ Uint32 MaxSlot = 0;
+ ResourceCache.BindCBs(ShaderInd, CommittedD3D11CBs, Binding, MinSlot, MaxSlot);
- for (Uint32 sam = 0; sam < SamplerCount; ++sam)
+ if (MinSlot != UINT_MAX)
{
- 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.IsValid(ShaderInd));
-
- auto* CommittedD3D11Samplers = m_CommittedRes.D3D11Samplers[ShaderInd];
- UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- UINT& MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- const UINT Slot = BaseBindings[ShaderInd][Range] + BindPoints[ShaderInd];
- const bool IsNewSam = CommittedD3D11Samplers[Slot] != d3d11Samplers[sam];
- MinSlot = IsNewSam ? std::min(MinSlot, Slot) : MinSlot;
- MaxSlot = IsNewSam ? Slot : MaxSlot;
-
- VERIFY_EXPR(!IsNewSam || (Slot >= MinSlot && Slot <= MaxSlot));
- VERIFY_EXPR(d3d11Samplers[sam] != nullptr);
- CommittedD3D11Samplers[Slot] = d3d11Samplers[sam];
- }
+ auto SetCBMethod = SetCBMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetCBMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11CBs + MinSlot);
+ m_CommittedRes.NumCBs[ShaderInd] = std::max(m_CommittedRes.NumCBs[ShaderInd], Binding);
+ VERIFY_EXPR(MaxSlot < Binding);
}
- }
-
- const auto UAVCount = ResourceCache.GetUAVCount();
- if (UAVCount != 0)
- {
- constexpr auto Range = D3D11_RESOURCE_RANGE_UAV;
- ShaderResourceCacheD3D11::CachedResource const* UAVResources;
- ID3D11UnorderedAccessView* const* d3d11UAVs;
- BindPointsD3D11 const* bindPoints;
- ResourceCache.GetConstUAVArrays(UAVResources, d3d11UAVs, bindPoints);
-
- for (Uint32 uav = 0; uav < UAVCount; ++uav)
+#ifdef VERIFY_CONTEXT_BINDINGS
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
{
- 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.IsValid(ShaderInd));
-
- auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[ShaderInd];
- auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[ShaderInd];
- UINT& MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- UINT& MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- const UINT Slot = BaseBindings[ShaderInd][Range] + BindPoints[ShaderInd];
- const bool IsNewUAV = CommittedD3D11UAVs[Slot] != d3d11UAVs[uav];
- MinSlot = IsNewUAV ? std::min(MinSlot, Slot) : MinSlot;
- MaxSlot = IsNewUAV ? Slot : MaxSlot;
-
- VERIFY_EXPR(!IsNewUAV || (Slot >= MinSlot && Slot <= MaxSlot));
- VERIFY_EXPR(d3d11UAVs[uav] != nullptr);
- CommittedD3D11UAVRes[Slot] = UAVResources[uav].pd3d11Resource;
- CommittedD3D11UAVs[Slot] = d3d11UAVs[uav];
- }
+ DvpVerifyCommittedCBs(ShaderTypes[i]);
}
+#endif
}
-}
-
-void DeviceContextD3D11Impl::BindShaderResources()
-{
- if ((m_BindInfo.StaleSRBMask & m_BindInfo.ActiveSRBMask) == 0)
- return;
-
- TBindingsPerStage Bindings = {};
- TMinMaxSlotPerStage MinMaxSlot = {};
- const auto ActiveStages = m_BindInfo.ActiveStages;
-
- if (m_pPipelineState->GetDesc().IsAnyGraphicsPipeline())
- Bindings[GetShaderTypeIndex(SHADER_TYPE_PIXEL)][D3D11_RESOURCE_RANGE_UAV] = static_cast<Uint8>(m_pPipelineState->GetGraphicsPipelineDesc().NumRenderTargets);
-
- auto ActiveSRBMask = Uint32{m_BindInfo.ActiveSRBMask};
- while (ActiveSRBMask != 0)
+ for (Uint32 i = 0; i < ShaderCount; ++i)
{
- Uint32 sign = PlatformMisc::GetLSB(ActiveSRBMask);
- Uint32 SigBit = (1u << sign);
- VERIFY_EXPR(sign < m_pPipelineState->GetResourceSignatureCount());
-
- ActiveSRBMask &= ~SigBit;
-
- auto* pSRB = m_BindInfo.SRBs[sign];
- VERIFY_EXPR(pSRB);
+ constexpr auto Range = D3D11_RESOURCE_RANGE_SRV;
+ const auto ShaderInd = ShaderIndices[i];
+ auto* CommittedD3D11SRVs = m_CommittedRes.D3D11SRVs[ShaderInd];
+ auto* CommittedD3D11SRVRes = m_CommittedRes.D3D11SRVResources[ShaderInd];
+ Uint8 Binding = BaseBindings[Range][ShaderInd];
+ Uint32 MinSlot = UINT_MAX;
+ Uint32 MaxSlot = 0;
+ ResourceCache.BindSRVs(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding, MinSlot, MaxSlot);
- if (m_BindInfo.StaleSRBMask & SigBit)
+ if (MinSlot != UINT_MAX)
{
-#ifdef DILIGENT_DEVELOPMENT
- m_BindInfo.BoundResOffsets[sign] = Bindings;
-#endif
- BindCacheResources(pSRB->GetResourceCache(), Bindings, MinMaxSlot, ActiveStages);
+ auto SetSRVMethod = SetSRVMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetSRVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11SRVs + MinSlot);
+ m_CommittedRes.NumSRVs[ShaderInd] = std::max(m_CommittedRes.NumSRVs[ShaderInd], Binding);
+ VERIFY_EXPR(MaxSlot <= Binding);
}
- pSRB->GetSignature()->ShiftBindings(Bindings);
+#ifdef VERIFY_CONTEXT_BINDINGS
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
+ {
+ DvpVerifyCommittedSRVs(ShaderTypes[i]);
+ }
+#endif
}
- m_BindInfo.StaleSRBMask &= ~m_BindInfo.ActiveSRBMask;
- bool ClearPixelShaderUAVs = m_CommittedRes.NumUAVs[PSInd] > 0;
-
- for (Uint32 s = 0, ShaderCount = m_pPipelineState->GetNumShaders(); s < ShaderCount; ++s)
+ for (Uint32 i = 0; i < ShaderCount; ++i)
{
- const auto ShaderType = m_pPipelineState->GetShaderStageType(s);
- const Uint32 ShaderInd = GetShaderTypeIndex(ShaderType);
+ constexpr auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
+ const auto ShaderInd = ShaderIndices[i];
+ auto* CommittedD3D11Samplers = m_CommittedRes.D3D11Samplers[ShaderInd];
+ Uint8 Binding = BaseBindings[Range][ShaderInd];
+ Uint32 MinSlot = UINT_MAX;
+ Uint32 MaxSlot = 0;
+ ResourceCache.BindSamplers(ShaderInd, CommittedD3D11Samplers, Binding, MinSlot, MaxSlot);
- // CBV
+ if (MinSlot != UINT_MAX)
{
- const auto Range = D3D11_RESOURCE_RANGE_CBV;
- const UINT MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- const UINT MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- if (MinSlot != UINT_MAX)
- {
- auto SetCBMethod = SetCBMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetCBMethod)(MinSlot, MaxSlot - MinSlot + 1, m_CommittedRes.D3D11CBs[ShaderInd] + MinSlot);
- m_CommittedRes.NumCBs[ShaderInd] = std::max(m_CommittedRes.NumCBs[ShaderInd], Bindings[ShaderInd][Range]);
- VERIFY_EXPR(MaxSlot < Bindings[ShaderInd][Range]);
- }
-#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedCBs(ShaderType);
- }
-#endif
+ auto SetSamplerMethod = SetSamplerMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetSamplerMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11Samplers + MinSlot);
+ m_CommittedRes.NumSamplers[ShaderInd] = std::max(m_CommittedRes.NumSamplers[ShaderInd], Binding);
+ VERIFY_EXPR(MaxSlot < Binding);
}
-
- // SRV
- {
- const auto Range = D3D11_RESOURCE_RANGE_SRV;
- const UINT MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- const UINT MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- if (MinSlot != UINT_MAX)
- {
- auto SetSRVMethod = SetSRVMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetSRVMethod)(MinSlot, MaxSlot - MinSlot + 1, m_CommittedRes.D3D11SRVs[ShaderInd] + MinSlot);
- m_CommittedRes.NumSRVs[ShaderInd] = std::max(m_CommittedRes.NumSRVs[ShaderInd], Bindings[ShaderInd][Range]);
- VERIFY_EXPR(MaxSlot <= Bindings[ShaderInd][Range]);
- }
#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedSRVs(ShaderType);
- }
-#endif
- }
-
- // Sampler
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
{
- const auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
- const UINT MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- const UINT MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- if (MinSlot != UINT_MAX)
- {
- auto SetSamplerMethod = SetSamplerMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetSamplerMethod)(MinSlot, MaxSlot - MinSlot + 1, m_CommittedRes.D3D11Samplers[ShaderInd] + MinSlot);
- m_CommittedRes.NumSamplers[ShaderInd] = std::max(m_CommittedRes.NumSamplers[ShaderInd], Bindings[ShaderInd][Range]);
- VERIFY_EXPR(MaxSlot < Bindings[ShaderInd][Range]);
- }
-#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedSamplers(ShaderType);
- }
-#endif
+ DvpVerifyCommittedSamplers(ShaderTypes[i]);
}
+#endif
+ }
- // UAV
+ bool ClearPixelShaderUAVs = m_CommittedRes.NumUAVs[PSInd] > 0;
+ for (Uint32 i = 0; i < ShaderCount; ++i)
+ {
+ constexpr auto Range = D3D11_RESOURCE_RANGE_UAV;
+ const auto ShaderInd = ShaderIndices[i];
+ auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[ShaderInd];
+ auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[ShaderInd];
+ Uint8 Binding = BaseBindings[Range][ShaderInd];
+ Uint32 MinSlot = UINT_MAX;
+ Uint32 MaxSlot = 0;
+ ResourceCache.BindUAVs(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding, MinSlot, MaxSlot);
+
+ if (MinSlot != UINT_MAX)
{
- const auto Range = D3D11_RESOURCE_RANGE_UAV;
- const UINT MinSlot = MinMaxSlot[ShaderInd][Range].MinSlot;
- const UINT MaxSlot = MinMaxSlot[ShaderInd][Range].MaxSlot;
- if (MinSlot != UINT_MAX)
- {
- auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[ShaderInd];
- auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[ShaderInd];
-
- if (ShaderInd == PSInd)
- ClearPixelShaderUAVs = false;
+ if (ShaderInd == PSInd)
+ ClearPixelShaderUAVs = false;
- // Something has changed
- if (ShaderInd == PSInd)
- {
- // Pixel shader UAVs cannot be set independently; they all need to be set at the same time.
- // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks
- const auto StartUAVSlot = m_NumBoundRenderTargets;
- const auto NumUAVSlot = Bindings[ShaderInd][Range];
- VERIFY(NumUAVSlot > StartUAVSlot, "Number of UAVs must be greater than the render target count");
- m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(
- D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr,
- StartUAVSlot, NumUAVSlot - StartUAVSlot, CommittedD3D11UAVs + StartUAVSlot, nullptr);
- // Clear previously bound UAVs, but do not clear lower slots as if
- // render target count reduces, we will bind these UAVs in CommitRenderTargets()
- for (Uint32 uav = NumUAVSlot; uav < m_CommittedRes.NumUAVs[ShaderInd]; ++uav)
- {
- CommittedD3D11UAVRes[uav] = nullptr;
- CommittedD3D11UAVs[uav] = nullptr;
- }
- m_CommittedRes.NumUAVs[ShaderInd] = NumUAVSlot;
- }
- else if (ShaderInd == CSInd)
- {
- // This can only be CS
- auto SetUAVMethod = SetUAVMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetUAVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11UAVs + MinSlot, nullptr);
- m_CommittedRes.NumUAVs[ShaderInd] = std::max(m_CommittedRes.NumUAVs[ShaderInd], Bindings[ShaderInd][Range]);
- VERIFY_EXPR(MaxSlot < Bindings[ShaderInd][Range]);
- }
- else
+ // Something has changed
+ if (ShaderInd == PSInd)
+ {
+ // Pixel shader UAVs cannot be set independently; they all need to be set at the same time.
+ // https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/nf-d3d11-id3d11devicecontext-omsetrendertargetsandunorderedaccessviews#remarks
+ const auto StartUAVSlot = m_NumBoundRenderTargets;
+ const auto NumUAVSlot = Binding;
+ VERIFY(NumUAVSlot > StartUAVSlot, "Number of UAVs must be greater than the render target count");
+ m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(
+ D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr,
+ StartUAVSlot, NumUAVSlot - StartUAVSlot, CommittedD3D11UAVs + StartUAVSlot, nullptr);
+ // Clear previously bound UAVs, but do not clear lower slots as if
+ // render target count reduces, we will bind these UAVs in CommitRenderTargets()
+ for (Uint32 uav = NumUAVSlot; uav < m_CommittedRes.NumUAVs[ShaderInd]; ++uav)
{
- UNEXPECTED("UAV is not supported in shader that is not pixel or compute");
+ CommittedD3D11UAVRes[uav] = nullptr;
+ CommittedD3D11UAVs[uav] = nullptr;
}
+ m_CommittedRes.NumUAVs[ShaderInd] = NumUAVSlot;
}
-#ifdef VERIFY_CONTEXT_BINDINGS
- if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderInd == CSInd)
+ else if (ShaderInd == CSInd)
{
- DvpVerifyCommittedUAVs(ShaderType);
+ // This can only be CS
+ auto SetUAVMethod = SetUAVMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetUAVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11UAVs + MinSlot, nullptr);
+ m_CommittedRes.NumUAVs[ShaderInd] = std::max(m_CommittedRes.NumUAVs[ShaderInd], Binding);
+ VERIFY_EXPR(MaxSlot < Binding);
+ }
+ else
+ {
+ UNEXPECTED("UAV is not supported in shader that is not pixel or compute");
}
-#endif
}
+#ifdef VERIFY_CONTEXT_BINDINGS
+ if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderInd == CSInd)
+ {
+ DvpVerifyCommittedUAVs(ShaderTypes[i]);
+ }
+#endif
}
if (ClearPixelShaderUAVs)
@@ -593,6 +443,42 @@ void DeviceContextD3D11Impl::BindShaderResources()
}
}
+void DeviceContextD3D11Impl::BindShaderResources()
+{
+ if ((m_BindInfo.StaleSRBMask & m_BindInfo.ActiveSRBMask) == 0)
+ return;
+
+ TBindingsPerStage Bindings = {};
+ const auto ActiveStages = m_BindInfo.ActiveStages;
+
+ if (m_pPipelineState->GetDesc().IsAnyGraphicsPipeline())
+ Bindings[D3D11_RESOURCE_RANGE_UAV][GetShaderTypeIndex(SHADER_TYPE_PIXEL)] = static_cast<Uint8>(m_pPipelineState->GetGraphicsPipelineDesc().NumRenderTargets);
+
+ auto ActiveSRBMask = Uint32{m_BindInfo.ActiveSRBMask};
+ while (ActiveSRBMask != 0)
+ {
+ Uint32 sign = PlatformMisc::GetLSB(ActiveSRBMask);
+ Uint32 SigBit = (1u << sign);
+ VERIFY_EXPR(sign < m_pPipelineState->GetResourceSignatureCount());
+
+ ActiveSRBMask &= ~SigBit;
+
+ auto* pSRB = m_BindInfo.SRBs[sign];
+ VERIFY_EXPR(pSRB);
+
+ if (m_BindInfo.StaleSRBMask & SigBit)
+ {
+#ifdef DILIGENT_DEVELOPMENT
+ m_BindInfo.BoundResOffsets[sign] = Bindings;
+#endif
+ BindCacheResources(pSRB->GetResourceCache(), Bindings, ActiveStages);
+ }
+ pSRB->GetSignature()->ShiftBindings(Bindings);
+ }
+
+ m_BindInfo.StaleSRBMask &= ~m_BindInfo.ActiveSRBMask;
+}
+
#ifdef DILIGENT_DEVELOPMENT
void DeviceContextD3D11Impl::DvpValidateCommittedShaderResources()
{
diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
index 8aae6a01..d8036c5f 100644
--- a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
@@ -102,7 +102,7 @@ PipelineResourceSignatureD3D11Impl::PipelineResourceSignatureD3D11Impl(IReferenc
ShaderVariableDataSizes[s] = ShaderVariableManagerD3D11::GetRequiredMemorySize(*this, AllowedVarTypes, _countof(AllowedVarTypes), GetActiveShaderStageType(s));
}
- const size_t CacheMemorySize = ShaderResourceCacheD3D11::GetRequriedMemorySize(m_ResourceCount);
+ const size_t CacheMemorySize = ShaderResourceCacheD3D11::GetRequriedMemorySize(m_BindingCountPerStage);
m_SRBMemAllocator.Initialize(m_Desc.SRBAllocationGranularity, GetNumActiveShaderStages(), ShaderVariableDataSizes.data(), 1, &CacheMemorySize);
}
@@ -118,27 +118,45 @@ PipelineResourceSignatureD3D11Impl::PipelineResourceSignatureD3D11Impl(IReferenc
void PipelineResourceSignatureD3D11Impl::CreateLayout()
{
using TBindings32 = std::array<Uint32, D3D11_RESOURCE_RANGE_COUNT>;
- using TBindingsPerStage32 = std::array<TBindings32, NumShaderTypes>;
+ using TBindingsPerStage32 = std::array<std::array<Uint32, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
+
+ const auto AllocBindPoints = [](TBindingsPerStage32& BindingPerStage, BindPointsD3D11& BindPoints, SHADER_TYPE ShaderStages, Uint32 ArraySize, D3D11_RESOURCE_RANGE Range) //
+ {
+ while (ShaderStages != 0)
+ {
+ auto Stage = ExtractLSB(ShaderStages);
+ Uint32 ShaderInd = GetShaderTypeIndex(Stage);
+
+ BindPoints.Set(ShaderInd, BindingPerStage[Range][ShaderInd]);
+ BindingPerStage[Range][ShaderInd] += ArraySize;
+ }
+ };
if (m_pStaticResCache)
{
- TBindings32 StaticCounter32 = {};
- const auto ResIdxRange = GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
+ TBindingsPerStage32 StaticBindingsPerStage32 = {};
+ const auto ResIdxRange = GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r)
{
- const auto& ResDesc = m_Desc.Resources[r];
- const auto Range = ShaderResourceToDescriptorRange(ResDesc.ResourceType);
- StaticCounter32[Range] += ResDesc.ArraySize;
+ const auto& ResDesc = m_Desc.Resources[r];
+ const auto Range = ShaderResourceToDescriptorRange(ResDesc.ResourceType);
+ BindPointsD3D11 BindPoints;
+ AllocBindPoints(StaticBindingsPerStage32, BindPoints, ResDesc.ShaderStages, ResDesc.ArraySize, Range);
}
- TBindings StaticCounter8 = {};
- for (Uint32 i = 0; i < StaticCounter8.size(); ++i)
+ TBindingsPerStage StaticBindingsPerStage8 = {};
+ for (Uint32 r = 0; r < StaticBindingsPerStage32.size(); ++r)
{
- VERIFY_EXPR(StaticCounter8[i] < std::numeric_limits<Uint8>::max());
- StaticCounter8[i] = static_cast<Uint8>(StaticCounter32[i]);
+ for (Uint32 s = 0; s < StaticBindingsPerStage32[r].size(); ++s)
+ {
+ using T = std::remove_reference<decltype(StaticBindingsPerStage8[r][s])>::type;
+ VERIFY_EXPR(StaticBindingsPerStage32[r][s] < std::numeric_limits<T>::max());
+ StaticBindingsPerStage8[r][s] = static_cast<T>(StaticBindingsPerStage32[r][s]);
+ }
}
- m_pStaticResCache->Initialize(StaticCounter8, GetRawAllocator());
+ m_pStaticResCache->Initialize(StaticBindingsPerStage8, GetRawAllocator());
+ VERIFY_EXPR(m_pStaticResCache->IsInitialized());
}
// Index of the assigned sampler, for every texture SRV in m_Desc.Resources, or InvalidSamplerInd.
@@ -173,20 +191,7 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout()
}
}
- TBindings32 ResourceCount = {};
TBindingsPerStage32 BindingPerStage = {};
- const auto AllocBindPoints = [&BindingPerStage](BindPointsD3D11& BindPoints, SHADER_TYPE ShaderStages, Uint32 ArraySize, D3D11_RESOURCE_RANGE Range) //
- {
- while (ShaderStages != 0)
- {
- auto Stage = ExtractLSB(ShaderStages);
- Uint32 ShaderInd = GetShaderTypeIndex(Stage);
-
- BindPoints.Set(ShaderInd, BindingPerStage[ShaderInd][Range]);
- BindingPerStage[ShaderInd][Range] += ArraySize;
- }
- };
-
for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
{
const auto& ResDesc = m_Desc.Resources[i];
@@ -218,9 +223,7 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout()
if (!ImtblSampAttribs.IsAllocated())
{
- ImtblSampAttribs.CacheOffset = ResourceCount[D3D11_RESOURCE_RANGE_SAMPLER];
- AllocBindPoints(ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, D3D11_RESOURCE_RANGE_SAMPLER);
- ResourceCount[D3D11_RESOURCE_RANGE_SAMPLER] += ImtblSampAttribs.ArraySize;
+ AllocBindPoints(BindingPerStage, ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, D3D11_RESOURCE_RANGE_SAMPLER);
}
}
@@ -228,12 +231,10 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout()
{
auto* pAttrib = new (m_pResourceAttribs + i) ResourceAttribs //
{
- ResourceCount[Range],
AssignedSamplerInd,
SrcImmutableSamplerInd != InvalidImmutableSamplerIndex //
};
- AllocBindPoints(pAttrib->BindPoints, ResDesc.ShaderStages, ResDesc.ArraySize, Range);
- ResourceCount[Range] += ResDesc.ArraySize;
+ AllocBindPoints(BindingPerStage, pAttrib->BindPoints, ResDesc.ShaderStages, ResDesc.ArraySize, Range);
}
else
{
@@ -242,11 +243,11 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout()
auto& ImtblSampAttribs = m_ImmutableSamplers[SrcImmutableSamplerInd];
auto* pAttrib = new (m_pResourceAttribs + i) ResourceAttribs //
{
- ImtblSampAttribs.CacheOffset,
ResourceAttribs::InvalidSamplerInd,
SrcImmutableSamplerInd != InvalidImmutableSamplerIndex //
};
pAttrib->BindPoints = ImtblSampAttribs.BindPoints;
+ VERIFY_EXPR(!pAttrib->BindPoints.IsEmpty());
}
}
@@ -265,27 +266,18 @@ void PipelineResourceSignatureD3D11Impl::CreateLayout()
// Add as separate sampler.
if (!ImtblSampAttribs.IsAllocated())
{
- ImtblSampAttribs.ArraySize = 1;
- ImtblSampAttribs.CacheOffset = ResourceCount[Range];
- ResourceCount[Range] += ImtblSampAttribs.ArraySize;
- AllocBindPoints(ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, Range);
+ ImtblSampAttribs.ArraySize = 1;
+ AllocBindPoints(BindingPerStage, ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, Range);
}
}
- for (Uint32 i = 0; i < ResourceCount.size(); ++i)
- {
- using T = std::remove_reference<decltype(m_ResourceCount[i])>::type;
- VERIFY_EXPR(ResourceCount[i] < std::numeric_limits<T>::max());
- m_ResourceCount[i] = static_cast<T>(ResourceCount[i]);
- }
-
- for (Uint32 s = 0; s < BindingPerStage.size(); ++s)
+ for (Uint32 r = 0; r < BindingPerStage.size(); ++r)
{
- for (Uint32 i = 0; i < BindingPerStage[s].size(); ++i)
+ for (Uint32 s = 0; s < BindingPerStage[r].size(); ++s)
{
- using T = std::remove_reference<decltype(m_BindingCountPerStage[s][i])>::type;
- VERIFY_EXPR(BindingPerStage[s][i] < std::numeric_limits<T>::max());
- m_BindingCountPerStage[s][i] = static_cast<T>(BindingPerStage[s][i]);
+ using T = std::remove_reference<decltype(m_BindingCountPerStage[r][s])>::type;
+ VERIFY_EXPR(BindingPerStage[r][s] < std::numeric_limits<T>::max());
+ m_BindingCountPerStage[r][s] = static_cast<T>(BindingPerStage[r][s]);
}
}
}
@@ -335,24 +327,15 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
case D3D11_RESOURCE_RANGE_CBV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- const auto& SrcCachedRes = SrcResourceCache.GetCB(ResAttr.CacheOffset + ArrInd);
- if (!SrcCachedRes.pBuff)
+ if (!DstResourceCache.CopyCB(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, "'.");
-
- DstResourceCache.SetCB(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferD3D11Impl>{SrcCachedRes.pBuff});
}
break;
case D3D11_RESOURCE_RANGE_SRV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- const auto& SrcCachedRes = SrcResourceCache.GetSRV(ResAttr.CacheOffset + ArrInd);
- if (!SrcCachedRes.pBuffer && !SrcCachedRes.pTexture)
+ if (!DstResourceCache.CopySRV(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, "'.");
-
- if (SrcCachedRes.pTexture)
- DstResourceCache.SetTexSRV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()});
- else
- DstResourceCache.SetBufSRV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()});
}
break;
case D3D11_RESOURCE_RANGE_SAMPLER:
@@ -361,25 +344,16 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
{
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- const auto& SrcCachedRes = SrcResourceCache.GetSampler(ResAttr.CacheOffset + ArrInd);
- if (!SrcCachedRes.pSampler)
+ if (!DstResourceCache.CopySampler(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, "'.");
-
- DstResourceCache.SetSampler(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<SamplerD3D11Impl>{SrcCachedRes.pSampler});
}
}
break;
case D3D11_RESOURCE_RANGE_UAV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- const auto& SrcCachedRes = SrcResourceCache.GetUAV(ResAttr.CacheOffset + ArrInd);
- if (!SrcCachedRes.pBuffer && !SrcCachedRes.pTexture)
+ if (!DstResourceCache.CopyUAV(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, "'.");
-
- if (SrcCachedRes.pTexture)
- DstResourceCache.SetTexUAV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<TextureViewD3D11Impl>{SrcCachedRes.pView.RawPtr<TextureViewD3D11Impl>()});
- else
- DstResourceCache.SetBufUAV(ResAttr.CacheOffset + ArrInd, ResAttr.BindPoints + ArrInd, RefCntAutoPtr<BufferViewD3D11Impl>{SrcCachedRes.pView.RawPtr<BufferViewD3D11Impl>()});
}
break;
default:
@@ -390,7 +364,8 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
void PipelineResourceSignatureD3D11Impl::InitSRBResourceCache(ShaderResourceCacheD3D11& ResourceCache)
{
- ResourceCache.Initialize(m_ResourceCount, m_SRBMemAllocator.GetResourceCacheDataAllocator(0));
+ ResourceCache.Initialize(m_BindingCountPerStage, m_SRBMemAllocator.GetResourceCacheDataAllocator(0));
+ VERIFY_EXPR(ResourceCache.IsInitialized());
// Copy immutable samplers.
for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
@@ -404,7 +379,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 + ArrInd, pSampler);
+ ResourceCache.SetSampler(ImtblSampAttr.BindPoints + ArrInd, pSampler);
}
}
}
@@ -425,7 +400,7 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource
VERIFY_EXPR(ResAttr.BindPoints.IsValid(ShaderInd));
ResourceBinding::BindInfo BindInfo //
{
- Uint32{BaseBindings[ShaderInd][Range]} + ResAttr.BindPoints[ShaderInd],
+ Uint32{BaseBindings[Range][ShaderInd]} + ResAttr.BindPoints[ShaderInd],
0u, // register space is not supported
ResDesc.ArraySize,
ResDesc.ResourceType //
@@ -453,7 +428,7 @@ void PipelineResourceSignatureD3D11Impl::UpdateShaderResourceBindingMap(Resource
ResourceBinding::BindInfo BindInfo //
{
- Uint32{BaseBindings[ShaderInd][Range]} + SampAttr.BindPoints[ShaderInd],
+ Uint32{BaseBindings[Range][ShaderInd]} + SampAttr.BindPoints[ShaderInd],
0u, // register space is not supported
SampAttr.ArraySize,
SHADER_RESOURCE_TYPE_SAMPLER //
@@ -492,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.CacheOffset + ArrInd))
+ if (!ResourceCache.IsCBBound(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
@@ -504,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.CacheOffset + ArrInd))
+ if (!ResourceCache.IsSamplerBound(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
@@ -517,19 +492,20 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
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))
+ if (!ResourceCache.IsSRVBound(ResAttr.BindPoints + 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);
+ /*
+ const auto& SRV = ResourceCache.GetSRV(ResAttr.BindPoints + 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;
@@ -537,19 +513,20 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
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))
+ if (!ResourceCache.IsUAVBound(ResAttr.BindPoints + 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);
+ /*
+ const auto& UAV = ResourceCache.GetUAV(ResAttr.BindPoints + 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;
diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
index 4cb13e5a..2fa5b73a 100644
--- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp
@@ -202,7 +202,7 @@ void PipelineStateD3D11Impl::InitResourceLayouts(const PipelineStateCreateInfo&
PipelineResourceSignatureD3D11Impl::TBindingsPerStage BindingsPerStage = {};
if (m_Desc.IsAnyGraphicsPipeline())
- BindingsPerStage[PSInd][D3D11_RESOURCE_RANGE_UAV] = GetGraphicsPipelineDesc().NumRenderTargets;
+ BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
ResourceBinding::TMap ResourceMap;
for (Uint32 sign = 0; sign < m_SignatureCount; ++sign)
@@ -232,7 +232,7 @@ void PipelineStateD3D11Impl::InitResourceLayouts(const PipelineStateCreateInfo&
PipelineResourceSignatureD3D11Impl::TBindingsPerStage BindingsPerStage = {};
if (m_Desc.IsAnyGraphicsPipeline())
- BindingsPerStage[PSInd][D3D11_RESOURCE_RANGE_UAV] = GetGraphicsPipelineDesc().NumRenderTargets;
+ BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
for (Uint32 sign = 0; sign < m_SignatureCount; ++sign)
{
@@ -241,18 +241,16 @@ void PipelineStateD3D11Impl::InitResourceLayouts(const PipelineStateCreateInfo&
pSignature->ShiftBindings(BindingsPerStage);
}
- for (Uint32 s = 0; s < BindingsPerStage.size(); ++s)
+ for (Uint32 s = 0; s < PipelineResourceSignatureD3D11Impl::NumShaderTypes; ++s)
{
- const auto& BindCount = BindingsPerStage[s];
-
- DEV_CHECK_ERR(BindCount[D3D11_RESOURCE_RANGE_CBV] <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
- "Constant buffer count ", Uint32{BindCount[D3D11_RESOURCE_RANGE_CBV]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
- DEV_CHECK_ERR(BindCount[D3D11_RESOURCE_RANGE_SRV] <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
- "SRV count ", Uint32{BindCount[D3D11_RESOURCE_RANGE_SRV]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
- DEV_CHECK_ERR(BindCount[D3D11_RESOURCE_RANGE_SAMPLER] <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT,
- "Sampler count ", Uint32{BindCount[D3D11_RESOURCE_RANGE_SAMPLER]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT);
- DEV_CHECK_ERR(BindCount[D3D11_RESOURCE_RANGE_UAV] <= D3D11_PS_CS_UAV_REGISTER_COUNT,
- "UAV count ", Uint32{BindCount[D3D11_RESOURCE_RANGE_UAV]}, " exceeds D3D11 limit ", D3D11_PS_CS_UAV_REGISTER_COUNT);
+ DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_CBV][s] <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
+ "Constant buffer count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_CBV][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+ DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_SRV][s] <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
+ "SRV count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_SRV][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
+ DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_SAMPLER][s] <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT,
+ "Sampler count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_SAMPLER][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT);
+ DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][s] <= D3D11_PS_CS_UAV_REGISTER_COUNT,
+ "UAV count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][s]}, " exceeds D3D11 limit ", D3D11_PS_CS_UAV_REGISTER_COUNT);
}
#endif
}
@@ -525,7 +523,7 @@ void PipelineStateD3D11Impl::DvpVerifySRBResources(class ShaderResourceBindingD3
TBindingsPerStage Bindings = {};
if (m_Desc.IsAnyGraphicsPipeline())
- Bindings[GetShaderTypeIndex(SHADER_TYPE_PIXEL)][D3D11_RESOURCE_RANGE_UAV] = static_cast<Uint8>(GetGraphicsPipelineDesc().NumRenderTargets);
+ Bindings[D3D11_RESOURCE_RANGE_UAV][GetShaderTypeIndex(SHADER_TYPE_PIXEL)] = static_cast<Uint8>(GetGraphicsPipelineDesc().NumRenderTargets);
for (Uint32 sign = 0; sign < SignCount; ++sign)
{
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
index 0e874a78..377f0990 100755
--- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
@@ -39,50 +39,60 @@
namespace Diligent
{
-size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TResourceCount& ResCount)
+size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TBindingsPerStage& ResCount)
{
+ size_t MemSize = 0;
// clang-format off
- auto CBCount = ResCount[D3D11_RESOURCE_RANGE_CBV];
- auto SRVCount = ResCount[D3D11_RESOURCE_RANGE_SRV];
- auto SamplerCount = ResCount[D3D11_RESOURCE_RANGE_SAMPLER];
- auto UAVCount = ResCount[D3D11_RESOURCE_RANGE_UAV];
- size_t MemSize = 0;
- MemSize = AlignUp(MemSize + (sizeof(CachedCB) + sizeof(BindPointsD3D11) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment);
- MemSize = AlignUp(MemSize + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment);
- MemSize = AlignUp(MemSize + (sizeof(CachedSampler) + sizeof(BindPointsD3D11) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment);
- MemSize = AlignUp(MemSize + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment);
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ MemSize = AlignUp(MemSize + (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * ResCount[D3D11_RESOURCE_RANGE_CBV][ShaderInd], MaxAlignment);
+
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ MemSize = AlignUp(MemSize + (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * ResCount[D3D11_RESOURCE_RANGE_SRV][ShaderInd], MaxAlignment);
+
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ MemSize = AlignUp(MemSize + (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * ResCount[D3D11_RESOURCE_RANGE_SAMPLER][ShaderInd], MaxAlignment);
+
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ MemSize = AlignUp(MemSize + (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * ResCount[D3D11_RESOURCE_RANGE_UAV][ShaderInd], MaxAlignment);
// clang-format on
- VERIFY(MemSize < InvalidResourceOffset, "Memory size exeed the maximum allowed size.");
+
+ VERIFY(MemSize < std::numeric_limits<OffsetType>::max(), "Memory size exeed the maximum allowed size.");
return MemSize;
}
-void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemoryAllocator& MemAllocator)
+void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMemoryAllocator& MemAllocator)
{
// http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache/
VERIFY(!IsInitialized(), "Resource cache has already been intialized!");
- const Uint32 CBCount = ResCount[D3D11_RESOURCE_RANGE_CBV];
- const Uint32 SRVCount = ResCount[D3D11_RESOURCE_RANGE_SRV];
- const Uint32 SamplerCount = ResCount[D3D11_RESOURCE_RANGE_SAMPLER];
- const Uint32 UAVCount = ResCount[D3D11_RESOURCE_RANGE_UAV];
+ size_t MemOffset = 0;
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const Uint32 Idx = CBOffset + ShaderInd;
+ m_Offsets[Idx] = static_cast<OffsetType>(MemOffset);
+ MemOffset = AlignUp(MemOffset + (sizeof(CachedCB) + sizeof(ID3D11Buffer*)) * ResCount[D3D11_RESOURCE_RANGE_CBV][ShaderInd], MaxAlignment);
+ }
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const Uint32 Idx = SRVOffset + ShaderInd;
+ m_Offsets[Idx] = static_cast<OffsetType>(MemOffset);
+ MemOffset = AlignUp(MemOffset + (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)) * ResCount[D3D11_RESOURCE_RANGE_SRV][ShaderInd], MaxAlignment);
+ }
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const Uint32 Idx = SampOffset + ShaderInd;
+ m_Offsets[Idx] = static_cast<OffsetType>(MemOffset);
+ MemOffset = AlignUp(MemOffset + (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)) * ResCount[D3D11_RESOURCE_RANGE_SAMPLER][ShaderInd], MaxAlignment);
+ }
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const Uint32 Idx = UAVOffset + ShaderInd;
+ m_Offsets[Idx] = static_cast<OffsetType>(MemOffset);
+ MemOffset = AlignUp(MemOffset + (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * ResCount[D3D11_RESOURCE_RANGE_UAV][ShaderInd], MaxAlignment);
+ }
+ m_Offsets[MaxOffsets - 1] = static_cast<OffsetType>(MemOffset);
- // clang-format off
- m_CBCount = static_cast<decltype(m_CBCount )>(CBCount);
- m_SRVCount = static_cast<decltype(m_SRVCount )>(SRVCount);
- m_SamplerCount = static_cast<decltype(m_SamplerCount)>(SamplerCount);
- m_UAVCount = static_cast<decltype(m_UAVCount )>(UAVCount);
-
- VERIFY(CBCount == m_CBCount, "Constant buffer count (", CBCount, ") exceeds maximum representable value");
- VERIFY(SRVCount == m_SRVCount, "Shader resources count (", SRVCount, ") exceeds maximum representable value");
- VERIFY(SamplerCount == m_SamplerCount, "Sampler count (", SamplerCount, ") exceeds maximum representable value");
- VERIFY(UAVCount == m_UAVCount, "UAVs count (", UAVCount, ") exceeds maximum representable value");
-
- // m_CBOffset = 0
- m_SRVOffset = static_cast<OffsetType>(AlignUp(m_CBOffset + (sizeof(CachedCB) + sizeof(BindPointsD3D11) + sizeof(ID3D11Buffer*)) * CBCount, MaxAlignment));
- m_SamplerOffset = static_cast<OffsetType>(AlignUp(m_SRVOffset + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11ShaderResourceView*)) * SRVCount, MaxAlignment));
- m_UAVOffset = static_cast<OffsetType>(AlignUp(m_SamplerOffset + (sizeof(CachedSampler) + sizeof(BindPointsD3D11) + sizeof(ID3D11SamplerState*)) * SamplerCount, MaxAlignment));
- size_t BufferSize = static_cast<OffsetType>(AlignUp(m_UAVOffset + (sizeof(CachedResource) + sizeof(BindPointsD3D11) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount, MaxAlignment));
- // clang-format on
+ const size_t BufferSize = MemOffset;
VERIFY_EXPR(m_pResourceData == nullptr);
VERIFY_EXPR(BufferSize == GetRequriedMemorySize(ResCount));
@@ -97,57 +107,50 @@ void ShaderResourceCacheD3D11::Initialize(const TResourceCount& ResCount, IMemor
}
// Explicitly construct all objects
- if (CBCount != 0)
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
{
- CachedCB* CBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetCBArrays(CBs, d3d11CBs, bindPoints);
- for (Uint32 cb = 0; cb < CBCount; ++cb)
+ const auto CBCount = GetCBCount(ShaderInd);
+ if (CBCount != 0)
{
- new (CBs + cb) CachedCB{};
- new (bindPoints + cb) BindPointsD3D11{};
+ CachedCB* CBs = nullptr;
+ ID3D11Buffer** d3d11CBs = nullptr;
+ GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ for (Uint32 cb = 0; cb < CBCount; ++cb)
+ new (CBs + cb) CachedCB{};
}
- }
- if (SRVCount != 0)
- {
- CachedResource* SRVResources = nullptr;
- ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
- for (Uint32 srv = 0; srv < SRVCount; ++srv)
+ const auto SRVCount = GetSRVCount(ShaderInd);
+ if (SRVCount != 0)
{
- new (SRVResources + srv) CachedResource{};
- new (bindPoints + srv) BindPointsD3D11{};
+ CachedResource* SRVResources = nullptr;
+ ID3D11ShaderResourceView** d3d11SRVs = nullptr;
+ GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ for (Uint32 srv = 0; srv < SRVCount; ++srv)
+ new (SRVResources + srv) CachedResource{};
}
- }
- if (SamplerCount != 0)
- {
- CachedSampler* Samplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetSamplerArrays(Samplers, d3d11Samplers, bindPoints);
- for (Uint32 sam = 0; sam < SamplerCount; ++sam)
+ const auto SamplerCount = GetSamplerCount(ShaderInd);
+ if (SamplerCount != 0)
{
- new (Samplers + sam) CachedSampler{};
- new (bindPoints + sam) BindPointsD3D11{};
+ CachedSampler* Samplers = nullptr;
+ ID3D11SamplerState** d3d11Samplers = nullptr;
+ GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+ for (Uint32 sam = 0; sam < SamplerCount; ++sam)
+ new (Samplers + sam) CachedSampler{};
}
- }
- if (UAVCount != 0)
- {
- CachedResource* UAVResources = nullptr;
- ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
- for (Uint32 uav = 0; uav < UAVCount; ++uav)
+ const auto UAVCount = GetUAVCount(ShaderInd);
+ if (UAVCount != 0)
{
- new (UAVResources + uav) CachedResource{};
- new (bindPoints + uav) BindPointsD3D11{};
+ CachedResource* UAVResources = nullptr;
+ ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
+ GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ for (Uint32 uav = 0; uav < UAVCount; ++uav)
+ new (UAVResources + uav) CachedResource{};
}
}
+
+ m_IsInitialized = true;
}
ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
@@ -155,57 +158,50 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
if (IsInitialized())
{
// Explicitly destory all objects
- auto CBCount = GetCBCount();
- if (CBCount != 0)
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
{
- CachedCB* CBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetCBArrays(CBs, d3d11CBs, bindPoints);
- for (size_t cb = 0; cb < CBCount; ++cb)
- CBs[cb].~CachedCB();
- }
+ const auto CBCount = GetCBCount(ShaderInd);
+ if (CBCount != 0)
+ {
+ CachedCB* CBs = nullptr;
+ ID3D11Buffer** d3d11CBs = nullptr;
+ GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ for (size_t cb = 0; cb < CBCount; ++cb)
+ CBs[cb].~CachedCB();
+ }
- auto SRVCount = GetSRVCount();
- if (SRVCount != 0)
- {
- CachedResource* SRVResources = nullptr;
- ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
- for (size_t srv = 0; srv < SRVCount; ++srv)
- SRVResources[srv].~CachedResource();
- }
+ const auto SRVCount = GetSRVCount(ShaderInd);
+ if (SRVCount != 0)
+ {
+ CachedResource* SRVResources = nullptr;
+ ID3D11ShaderResourceView** d3d11SRVs = nullptr;
+ GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ for (size_t srv = 0; srv < SRVCount; ++srv)
+ SRVResources[srv].~CachedResource();
+ }
- auto SamplerCount = GetSamplerCount();
- if (SamplerCount != 0)
- {
- CachedSampler* Samplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetSamplerArrays(Samplers, d3d11Samplers, bindPoints);
- for (size_t sam = 0; sam < SamplerCount; ++sam)
- Samplers[sam].~CachedSampler();
- }
+ const auto SamplerCount = GetSamplerCount(ShaderInd);
+ if (SamplerCount != 0)
+ {
+ CachedSampler* Samplers = nullptr;
+ ID3D11SamplerState** d3d11Samplers = nullptr;
+ GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+ for (size_t sam = 0; sam < SamplerCount; ++sam)
+ Samplers[sam].~CachedSampler();
+ }
- auto UAVCount = GetUAVCount();
- if (UAVCount != 0)
- {
- CachedResource* UAVResources = nullptr;
- ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
- GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
- for (size_t uav = 0; uav < UAVCount; ++uav)
- UAVResources[uav].~CachedResource();
+ const auto UAVCount = GetUAVCount(ShaderInd);
+ if (UAVCount != 0)
+ {
+ CachedResource* UAVResources = nullptr;
+ ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
+ GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+ for (size_t uav = 0; uav < UAVCount; ++uav)
+ UAVResources[uav].~CachedResource();
+ }
}
-
- m_SRVOffset = InvalidResourceOffset;
- m_SamplerOffset = InvalidResourceOffset;
- m_UAVOffset = InvalidResourceOffset;
- m_CBCount = 0;
- m_SRVCount = 0;
- m_SamplerCount = 0;
- m_UAVCount = 0;
+ m_Offsets = {};
+ m_IsInitialized = false;
m_pResourceData.reset();
}
@@ -264,62 +260,64 @@ void ShaderResourceCacheD3D11::DvpVerifyCacheConsistency()
{
VERIFY(IsInitialized(), "Cache is not initialized");
- CachedCB* CBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- CachedResource* SRVResources = nullptr;
- ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- CachedSampler* Samplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- CachedResource* UAVResources = nullptr;
- ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- BindPointsD3D11* bindPoints = nullptr;
-
- GetCBArrays(CBs, d3d11CBs, bindPoints);
- GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
- GetSamplerArrays(Samplers, d3d11Samplers, bindPoints);
- GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
-
- auto CBCount = GetCBCount();
- for (size_t cb = 0; cb < CBCount; ++cb)
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
{
- auto& pBuff = CBs[cb].pBuff;
- auto* pd3d11Buff = d3d11CBs[cb];
- VERIFY(pBuff == nullptr && pd3d11Buff == nullptr || pBuff != nullptr && pd3d11Buff != nullptr, "CB resource and d3d11 buffer must be set/unset atomically");
- if (pBuff != nullptr && pd3d11Buff != nullptr)
+ CachedCB* CBs = nullptr;
+ ID3D11Buffer** d3d11CBs = nullptr;
+ CachedResource* SRVResources = nullptr;
+ ID3D11ShaderResourceView** d3d11SRVs = nullptr;
+ CachedSampler* Samplers = nullptr;
+ ID3D11SamplerState** d3d11Samplers = nullptr;
+ CachedResource* UAVResources = nullptr;
+ ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
+
+ GetCBArrays(ShaderInd, CBs, d3d11CBs);
+ GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+ GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+ GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+
+ auto CBCount = GetCBCount(ShaderInd);
+ for (size_t cb = 0; cb < CBCount; ++cb)
{
- VERIFY(pd3d11Buff == pBuff->GetD3D11Buffer(), "Inconsistent D3D11 buffer");
+ auto& pBuff = CBs[cb].pBuff;
+ auto* pd3d11Buff = d3d11CBs[cb];
+ VERIFY(pBuff == nullptr && pd3d11Buff == nullptr || pBuff != nullptr && pd3d11Buff != nullptr, "CB resource and d3d11 buffer must be set/unset atomically");
+ if (pBuff != nullptr && pd3d11Buff != nullptr)
+ {
+ VERIFY(pd3d11Buff == pBuff->GetD3D11Buffer(), "Inconsistent D3D11 buffer");
+ }
}
- }
- auto SRVCount = GetSRVCount();
- for (size_t srv = 0; srv < SRVCount; ++srv)
- {
- auto& Res = SRVResources[srv];
- auto* pd3d11SRV = d3d11SRVs[srv];
- DvpVerifyResource(Res, pd3d11SRV, "SRV");
- }
+ auto SRVCount = GetSRVCount(ShaderInd);
+ for (size_t srv = 0; srv < SRVCount; ++srv)
+ {
+ auto& Res = SRVResources[srv];
+ auto* pd3d11SRV = d3d11SRVs[srv];
+ DvpVerifyResource(Res, pd3d11SRV, "SRV");
+ }
- auto UAVCount = GetUAVCount();
- for (size_t uav = 0; uav < UAVCount; ++uav)
- {
- auto& Res = UAVResources[uav];
- auto* pd3d11UAV = d3d11UAVs[uav];
- DvpVerifyResource(Res, pd3d11UAV, "UAV");
- }
+ auto UAVCount = GetUAVCount(ShaderInd);
+ for (size_t uav = 0; uav < UAVCount; ++uav)
+ {
+ auto& Res = UAVResources[uav];
+ auto* pd3d11UAV = d3d11UAVs[uav];
+ DvpVerifyResource(Res, pd3d11UAV, "UAV");
+ }
- auto SamplerCount = GetSamplerCount();
- for (size_t sam = 0; sam < SamplerCount; ++sam)
- {
- auto& pSampler = Samplers[sam].pSampler;
- auto* pd3d11Sampler = d3d11Samplers[sam];
- VERIFY(pSampler == nullptr && pd3d11Sampler == nullptr || pSampler != nullptr && pd3d11Sampler != nullptr, "CB resource and d3d11 buffer must be set/unset atomically");
- if (pSampler != nullptr && pd3d11Sampler != nullptr)
+ auto SamplerCount = GetSamplerCount(ShaderInd);
+ for (size_t sam = 0; sam < SamplerCount; ++sam)
{
- VERIFY(pd3d11Sampler == pSampler->GetD3D11SamplerState(), "Inconsistent D3D11 sampler");
+ auto& pSampler = Samplers[sam].pSampler;
+ auto* pd3d11Sampler = d3d11Samplers[sam];
+ VERIFY(pSampler == nullptr && pd3d11Sampler == nullptr || pSampler != nullptr && pd3d11Sampler != nullptr, "CB resource and d3d11 buffer must be set/unset atomically");
+ if (pSampler != nullptr && pd3d11Sampler != nullptr)
+ {
+ VERIFY(pd3d11Sampler == pSampler->GetD3D11SamplerState(), "Inconsistent D3D11 sampler");
+ }
}
}
}
-#endif
+#endif // DILIGENT_DEVELOPMENT
template <ShaderResourceCacheD3D11::StateTransitionMode Mode>
void ShaderResourceCacheD3D11::TransitionResourceStates(DeviceContextD3D11Impl& Ctx)
@@ -335,30 +333,32 @@ void ShaderResourceCacheD3D11::TransitionResourceStates(DeviceContextD3D11Impl&
template <ShaderResourceCacheD3D11::StateTransitionMode Mode>
void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11Buffer* /*Selector*/) const
{
- const auto CBCount = GetCBCount();
- if (CBCount == 0)
- return;
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const auto CBCount = GetCBCount(ShaderInd);
+ if (CBCount == 0)
+ continue;
- CachedCB* CBs;
- ID3D11Buffer** d3d11CBs;
- BindPointsD3D11* bindPoints;
- GetCBArrays(CBs, d3d11CBs, bindPoints);
+ CachedCB* CBs;
+ ID3D11Buffer** d3d11CBs;
+ GetCBArrays(ShaderInd, CBs, d3d11CBs);
- for (Uint32 i = 0; i < CBCount; ++i)
- {
- if (auto* pBuffer = CBs[i].pBuff.RawPtr<BufferD3D11Impl>())
+ for (Uint32 i = 0; i < CBCount; ++i)
{
- if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_CONSTANT_BUFFER))
+ if (auto* pBuffer = CBs[i].pBuff.RawPtr<BufferD3D11Impl>())
{
- if (Mode == StateTransitionMode::Transition)
- {
- Ctx.TransitionResource(pBuffer, RESOURCE_STATE_CONSTANT_BUFFER);
- }
- else
+ if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_CONSTANT_BUFFER))
{
- LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
- "' has not been transitioned to Constant Buffer state. Call TransitionShaderResources(), use "
- "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ if (Mode == StateTransitionMode::Transition)
+ {
+ Ctx.TransitionResource(pBuffer, RESOURCE_STATE_CONSTANT_BUFFER);
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
+ "' has not been transitioned to Constant Buffer state. Call TransitionShaderResources(), use "
+ "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ }
}
}
}
@@ -368,47 +368,49 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx,
template <ShaderResourceCacheD3D11::StateTransitionMode Mode>
void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11ShaderResourceView* /*Selector*/) const
{
- const auto SRVCount = GetSRVCount();
- if (SRVCount == 0)
- return;
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const auto SRVCount = GetSRVCount(ShaderInd);
+ if (SRVCount == 0)
+ continue;
- CachedResource* SRVResources;
- ID3D11ShaderResourceView** d3d11SRVs;
- BindPointsD3D11* bindPoints;
- GetSRVArrays(SRVResources, d3d11SRVs, bindPoints);
+ CachedResource* SRVResources;
+ ID3D11ShaderResourceView** d3d11SRVs;
+ GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
- for (Uint32 i = 0; i < SRVCount; ++i)
- {
- auto& SRVRes = SRVResources[i];
- if (auto* pTexture = SRVRes.pTexture)
+ for (Uint32 i = 0; i < SRVCount; ++i)
{
- if (pTexture->IsInKnownState() && !pTexture->CheckAnyState(RESOURCE_STATE_SHADER_RESOURCE | RESOURCE_STATE_INPUT_ATTACHMENT))
+ auto& SRVRes = SRVResources[i];
+ if (auto* pTexture = SRVRes.pTexture)
{
- if (Mode == StateTransitionMode::Transition)
+ if (pTexture->IsInKnownState() && !pTexture->CheckAnyState(RESOURCE_STATE_SHADER_RESOURCE | RESOURCE_STATE_INPUT_ATTACHMENT))
{
- Ctx.TransitionResource(pTexture, RESOURCE_STATE_SHADER_RESOURCE);
- }
- else
- {
- LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name,
- "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use "
- "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state.");
+ if (Mode == StateTransitionMode::Transition)
+ {
+ Ctx.TransitionResource(pTexture, RESOURCE_STATE_SHADER_RESOURCE);
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name,
+ "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use "
+ "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state.");
+ }
}
}
- }
- else if (auto* pBuffer = SRVRes.pBuffer)
- {
- if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE))
+ else if (auto* pBuffer = SRVRes.pBuffer)
{
- if (Mode == StateTransitionMode::Transition)
+ if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE))
{
- Ctx.TransitionResource(pBuffer, RESOURCE_STATE_SHADER_RESOURCE);
- }
- else
- {
- LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
- "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use "
- "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ if (Mode == StateTransitionMode::Transition)
+ {
+ Ctx.TransitionResource(pBuffer, RESOURCE_STATE_SHADER_RESOURCE);
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
+ "' has not been transitioned to Shader Resource state. Call TransitionShaderResources(), use "
+ "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ }
}
}
}
@@ -423,51 +425,153 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx,
template <ShaderResourceCacheD3D11::StateTransitionMode Mode>
void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11UnorderedAccessView* /*Selector*/) const
{
- const auto UAVCount = GetUAVCount();
- if (UAVCount == 0)
- return;
+ for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
+ {
+ const auto UAVCount = GetUAVCount(ShaderInd);
+ if (UAVCount == 0)
+ continue;
- CachedResource* UAVResources;
- ID3D11UnorderedAccessView** d3d11UAVs;
- BindPointsD3D11* bindPoints;
- GetUAVArrays(UAVResources, d3d11UAVs, bindPoints);
+ CachedResource* UAVResources;
+ ID3D11UnorderedAccessView** d3d11UAVs;
+ GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
- for (Uint32 i = 0; i < UAVCount; ++i)
- {
- auto& UAVRes = UAVResources[i];
- if (auto* pTexture = UAVRes.pTexture)
+ for (Uint32 i = 0; i < UAVCount; ++i)
{
- if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
+ auto& UAVRes = UAVResources[i];
+ if (auto* pTexture = UAVRes.pTexture)
{
- if (Mode == StateTransitionMode::Transition)
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
{
- Ctx.TransitionResource(pTexture, RESOURCE_STATE_UNORDERED_ACCESS);
- }
- else
- {
- LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name,
- "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use "
- "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state.");
+ if (Mode == StateTransitionMode::Transition)
+ {
+ Ctx.TransitionResource(pTexture, RESOURCE_STATE_UNORDERED_ACCESS);
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name,
+ "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use "
+ "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the texture to required state.");
+ }
}
}
- }
- else if (auto* pBuffer = UAVRes.pBuffer)
- {
- if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
+ else if (auto* pBuffer = UAVRes.pBuffer)
{
- if (Mode == StateTransitionMode::Transition)
- {
- Ctx.TransitionResource(pBuffer, RESOURCE_STATE_UNORDERED_ACCESS);
- }
- else
+ if (pBuffer->IsInKnownState() && !pBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
{
- LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
- "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use "
- "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ if (Mode == StateTransitionMode::Transition)
+ {
+ Ctx.TransitionResource(pBuffer, RESOURCE_STATE_UNORDERED_ACCESS);
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Buffer '", pBuffer->GetDesc().Name,
+ "' has not been transitioned to Unordered Access state. Call TransitionShaderResources(), use "
+ "RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode or explicitly transition the buffer to required state.");
+ }
}
}
}
}
}
+void ShaderResourceCacheD3D11::BindCBs(Uint32 ShaderInd,
+ ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const
+{
+ CachedCB const* CBs;
+ ID3D11Buffer* const* d3d11CBs;
+ GetConstCBArrays(ShaderInd, CBs, d3d11CBs);
+
+ const auto CBCount = GetCBCount(ShaderInd);
+ for (Uint32 cb = 0; cb < CBCount; ++cb)
+ {
+ const Uint32 Slot = Binding++;
+ const bool IsNewCB = CommittedD3D11CBs[Slot] != d3d11CBs[cb];
+ MinSlot = IsNewCB ? std::min(MinSlot, Slot) : MinSlot;
+ MaxSlot = IsNewCB ? Slot : MaxSlot;
+
+ VERIFY_EXPR(!IsNewCB || (Slot >= MinSlot && Slot <= MaxSlot));
+ VERIFY_EXPR(d3d11CBs[cb] != nullptr);
+ CommittedD3D11CBs[Slot] = d3d11CBs[cb];
+ }
+}
+
+void ShaderResourceCacheD3D11::BindSRVs(Uint32 ShaderInd,
+ ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
+ ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const
+{
+ CachedResource const* SRVResources;
+ ID3D11ShaderResourceView* const* d3d11SRVs;
+ GetConstSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
+
+ const auto SRVCount = GetSRVCount(ShaderInd);
+ for (Uint32 srv = 0; srv < SRVCount; ++srv)
+ {
+ const Uint32 Slot = Binding++;
+ const bool IsNewSRV = CommittedD3D11SRVs[Slot] != d3d11SRVs[srv];
+ MinSlot = IsNewSRV ? std::min(MinSlot, Slot) : MinSlot;
+ MaxSlot = IsNewSRV ? Slot : MaxSlot;
+
+ VERIFY_EXPR(!IsNewSRV || (Slot >= MinSlot && Slot <= MaxSlot));
+ VERIFY_EXPR(d3d11SRVs[srv] != nullptr);
+ CommittedD3D11SRVResources[Slot] = SRVResources[srv].pd3d11Resource;
+ CommittedD3D11SRVs[Slot] = d3d11SRVs[srv];
+ }
+}
+
+void ShaderResourceCacheD3D11::BindSamplers(Uint32 ShaderInd,
+ ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const
+{
+ CachedSampler const* Samplers;
+ ID3D11SamplerState* const* d3d11Samplers;
+ GetConstSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
+
+ const auto SamplerCount = GetSamplerCount(ShaderInd);
+ for (Uint32 sam = 0; sam < SamplerCount; ++sam)
+ {
+ const Uint32 Slot = Binding++;
+ const bool IsNewSam = CommittedD3D11Samplers[Slot] != d3d11Samplers[sam];
+ MinSlot = IsNewSam ? std::min(MinSlot, Slot) : MinSlot;
+ MaxSlot = IsNewSam ? Slot : MaxSlot;
+
+ VERIFY_EXPR(!IsNewSam || (Slot >= MinSlot && Slot <= MaxSlot));
+ VERIFY_EXPR(d3d11Samplers[sam] != nullptr);
+ CommittedD3D11Samplers[Slot] = d3d11Samplers[sam];
+ }
+}
+
+void ShaderResourceCacheD3D11::BindUAVs(Uint32 ShaderInd,
+ ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT],
+ ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT],
+ Uint8& Binding,
+ Uint32& MinSlot,
+ Uint32& MaxSlot) const
+{
+ CachedResource const* UAVResources;
+ ID3D11UnorderedAccessView* const* d3d11UAVs;
+ GetConstUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
+
+ const auto UAVCount = GetUAVCount(ShaderInd);
+ for (Uint32 uav = 0; uav < UAVCount; ++uav)
+ {
+ const Uint32 Slot = Binding++;
+ const bool IsNewUAV = CommittedD3D11UAVs[Slot] != d3d11UAVs[uav];
+ MinSlot = IsNewUAV ? std::min(MinSlot, Slot) : MinSlot;
+ MaxSlot = IsNewUAV ? Slot : MaxSlot;
+
+ VERIFY_EXPR(!IsNewUAV || (Slot >= MinSlot && Slot <= MaxSlot));
+ VERIFY_EXPR(d3d11UAVs[uav] != nullptr);
+ CommittedD3D11UAVResources[Slot] = UAVResources[uav].pd3d11Resource;
+ CommittedD3D11UAVs[Slot] = d3d11UAVs[uav];
+ }
+}
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
index 62e6a845..b989d966 100644
--- a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
@@ -227,54 +227,43 @@ void ShaderVariableManagerD3D11::Initialize(const PipelineResourceSignatureD3D11
Uint32 bufUav = 0;
Uint32 sam = 0;
- Uint32 NumCBSlots = 0;
- Uint32 NumSRVSlots = 0;
- Uint32 NumSamplerSlots = 0;
- Uint32 NumUAVSlots = 0;
ProcessSignatureResources(
Signature, AllowedVarTypes, NumAllowedTypes, ShaderType,
[&](Uint32 Index) //
{
const auto& ResDesc = Signature.GetResourceDesc(Index);
- const auto& ResAttr = Signature.GetResourceAttribs(Index);
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource range");
switch (ResDesc.ResourceType)
{
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
// Initialize current CB in place, increment CB counter
new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo(*this, Index);
- NumCBSlots = std::max(NumCBSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
case SHADER_RESOURCE_TYPE_TEXTURE_SRV:
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT:
// Initialize tex SRV in place, increment counter of tex SRVs
new (&GetResource<TexSRVBindInfo>(texSrv++)) TexSRVBindInfo{*this, Index};
- NumSRVSlots = std::max(NumSRVSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
case SHADER_RESOURCE_TYPE_BUFFER_SRV:
// Initialize buff SRV in place, increment counter of buff SRVs
new (&GetResource<BuffSRVBindInfo>(bufSrv++)) BuffSRVBindInfo(*this, Index);
- NumSRVSlots = std::max(NumSRVSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
case SHADER_RESOURCE_TYPE_TEXTURE_UAV:
// Initialize tex UAV in place, increment counter of tex UAVs
new (&GetResource<TexUAVBindInfo>(texUav++)) TexUAVBindInfo(*this, Index);
- NumUAVSlots = std::max(NumUAVSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
case SHADER_RESOURCE_TYPE_BUFFER_UAV:
// Initialize buff UAV in place, increment counter of buff UAVs
new (&GetResource<BuffUAVBindInfo>(bufUav++)) BuffUAVBindInfo(*this, Index);
- NumUAVSlots = std::max(NumUAVSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
case SHADER_RESOURCE_TYPE_SAMPLER:
// Initialize current sampler in place, increment sampler counter
new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo(*this, Index);
- NumSamplerSlots = std::max(NumSamplerSlots, ResAttr.CacheOffset + ResDesc.ArraySize);
break;
default:
@@ -306,12 +295,12 @@ void ShaderVariableManagerD3D11::ConstBuffBindInfo::BindResource(IDeviceObject*
RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl{pBuffer, IID_BufferD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- const auto& CachedCB = ResourceCache.GetCB(Attr.CacheOffset + ArrayIndex);
+ const auto& CachedCB = ResourceCache.GetCB(Attr.BindPoints + ArrayIndex);
VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(),
m_ParentManager.m_pSignature->GetDesc().Name);
}
#endif
- ResourceCache.SetCB(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pBuffD3D11Impl));
+ ResourceCache.SetCB(Attr.BindPoints + ArrayIndex, std::move(pBuffD3D11Impl));
}
@@ -330,7 +319,7 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedSRV = ResourceCache.GetSRV(Attr.CacheOffset + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE},
RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr(),
@@ -364,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.CacheOffset + SampArrayIndex);
+ auto& CachedSampler = ResourceCache.GetSampler(SampAttr.BindPoints + SampArrayIndex);
if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl)
{
auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
@@ -373,9 +362,9 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi
}
}
#endif
- ResourceCache.SetSampler(SampAttr.CacheOffset + SampArrayIndex, SampAttr.BindPoints + SampArrayIndex, pSamplerD3D11Impl);
+ ResourceCache.SetSampler(SampAttr.BindPoints + SampArrayIndex, pSamplerD3D11Impl);
}
- ResourceCache.SetTexSRV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetTexSRV(Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
}
void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSampler, Uint32 ArrayIndex)
@@ -408,7 +397,7 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS
if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSampler = ResourceCache.GetSampler(Attr.CacheOffset + ArrayIndex);
+ auto& CachedSampler = ResourceCache.GetSampler(Attr.BindPoints + ArrayIndex);
if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11)
{
auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
@@ -419,7 +408,7 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS
}
#endif
- ResourceCache.SetSampler(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pSamplerD3D11));
+ ResourceCache.SetSampler(Attr.BindPoints + ArrayIndex, std::move(pSamplerD3D11));
}
void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pView, Uint32 ArrayIndex)
@@ -436,7 +425,7 @@ void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pV
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedSRV = ResourceCache.GetSRV(Attr.CacheOffset + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE},
RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr(),
@@ -444,7 +433,7 @@ void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pV
ValidateBufferMode(Desc, ArrayIndex, pViewD3D11.RawPtr());
}
#endif
- ResourceCache.SetBufSRV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetBufSRV(Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
}
@@ -462,14 +451,14 @@ void ShaderVariableManagerD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVi
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedUAV = ResourceCache.GetUAV(Attr.CacheOffset + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS},
RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr(),
m_ParentManager.m_pSignature->GetDesc().Name);
}
#endif
- ResourceCache.SetTexUAV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetTexUAV(Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
}
@@ -487,7 +476,7 @@ void ShaderVariableManagerD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pV
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedUAV = ResourceCache.GetUAV(Attr.CacheOffset + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS},
RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr(),
@@ -495,7 +484,7 @@ void ShaderVariableManagerD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pV
ValidateBufferMode(Desc, ArrayIndex, pViewD3D11.RawPtr());
}
#endif
- ResourceCache.SetBufUAV(Attr.CacheOffset + ArrayIndex, Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
+ ResourceCache.SetBufUAV(Attr.BindPoints + ArrayIndex, std::move(pViewD3D11));
}
void ShaderVariableManagerD3D11::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags)