summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-17 03:45:32 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:24 +0000
commit5566a3fc3c4532e0eab6082feba54784ce49385e (patch)
tree39699b52307a4eeb740bbb96e6d9e2792370bba0 /Graphics/GraphicsEngineD3D11
parentFew more updates to ShaderResourceCacheD3D11 (diff)
downloadDiligentCore-5566a3fc3c4532e0eab6082feba54784ce49385e.tar.gz
DiligentCore-5566a3fc3c4532e0eab6082feba54784ce49385e.zip
More updates to ShaderResourceCacheD3D11 and resource binding in D3D11
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp12
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp237
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp12
-rwxr-xr-xGraphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp252
-rw-r--r--Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp16
-rwxr-xr-xGraphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp42
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp14
7 files changed, 291 insertions, 294 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
index 712e82ff..95632eec 100644
--- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp
@@ -346,32 +346,32 @@ private:
/// An array of D3D11 constant buffers committed to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11Buffer* D3D11CBs [NumShaderTypes][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {};
+ ID3D11Buffer* d3d11CBs [NumShaderTypes][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {};
/// An array of D3D11 shader resource views committed to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11ShaderResourceView* D3D11SRVs [NumShaderTypes][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
+ ID3D11ShaderResourceView* d3d11SRVs [NumShaderTypes][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
/// An array of D3D11 samplers committed to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11SamplerState* D3D11Samplers[NumShaderTypes][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {};
+ ID3D11SamplerState* d3d11Samplers[NumShaderTypes][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {};
/// An array of D3D11 UAVs committed to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11UnorderedAccessView* D3D11UAVs [NumShaderTypes][D3D11_PS_CS_UAV_REGISTER_COUNT] = {};
+ ID3D11UnorderedAccessView* d3d11UAVs [NumShaderTypes][D3D11_PS_CS_UAV_REGISTER_COUNT] = {};
/// An array of D3D11 resources commited as SRV to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11Resource* D3D11SRVResources [NumShaderTypes][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
+ ID3D11Resource* d3d11SRVResources [NumShaderTypes][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {};
/// An array of D3D11 resources commited as UAV to D3D11 device context,
/// for each shader type. The context addref's all bound resources, so we do
/// not need to keep strong references.
- ID3D11Resource* D3D11UAVResources [NumShaderTypes][D3D11_PS_CS_UAV_REGISTER_COUNT] = {};
+ ID3D11Resource* d3d11UAVResources [NumShaderTypes][D3D11_PS_CS_UAV_REGISTER_COUNT] = {};
Uint8 NumCBs [NumShaderTypes] = {};
Uint8 NumSRVs [NumShaderTypes] = {};
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
index 8989f6ef..b734d689 100644
--- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp
@@ -47,7 +47,7 @@
namespace Diligent
{
-/// The class implements a cache that holds resources bound to a specific shader stage
+/// The class implements a cache that holds resources bound to all shader stages.
// All resources are stored in the continuous memory using the following layout:
//
// | CachedCB | ID3D11Buffer* || CachedResource | ID3D11ShaderResourceView* || CachedSampler | ID3D11SamplerState* || CachedResource | ID3D11UnorderedAccessView*||
@@ -73,15 +73,6 @@ public:
ShaderResourceCacheD3D11& operator = (ShaderResourceCacheD3D11&&) = delete;
// clang-format on
- enum class StateTransitionMode
- {
- Transition,
- Verify
- };
- // Transitions all resources in the cache
- template <StateTransitionMode Mode>
- void TransitionResourceStates(DeviceContextD3D11Impl& Ctx);
-
/// Describes a resource associated with a cached constant buffer
struct CachedCB
{
@@ -93,8 +84,6 @@ public:
return pBuff;
}
- private:
- friend class ShaderResourceCacheD3D11;
__forceinline void Set(RefCntAutoPtr<BufferD3D11Impl> _pBuff)
{
pBuff = std::move(_pBuff);
@@ -112,8 +101,6 @@ public:
return pSampler;
}
- private:
- friend class ShaderResourceCacheD3D11;
__forceinline void Set(SamplerD3D11Impl* pSam)
{
pSampler = pSam;
@@ -147,8 +134,6 @@ public:
return pView;
}
- private:
- friend class ShaderResourceCacheD3D11;
__forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
pBuffer = nullptr;
@@ -168,63 +153,65 @@ public:
}
};
- template <typename D3D11ResourceType>
+ template <D3D11_RESOURCE_RANGE>
struct CachedResourceTraits;
static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes;
- using TBindingsPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
+ using TResourcesPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
- static size_t GetRequriedMemorySize(const TBindingsPerStage& ResCount);
+ static size_t GetRequriedMemorySize(const TResourcesPerStage& ResCount);
- void Initialize(const TBindingsPerStage& ResCount, IMemoryAllocator& MemAllocator);
+ void Initialize(const TResourcesPerStage& ResCount, IMemoryAllocator& MemAllocator);
__forceinline void SetCB(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl)
{
auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr;
- SetD3D11ResourceInternal(BindPoints, std::move(pBuffD3D11Impl), pd3d11Buff);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_CBV>(BindPoints, std::move(pBuffD3D11Impl), pd3d11Buff);
}
__forceinline void SetTexSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal(BindPoints, std::move(pTexView), pd3d11SRV);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SRV>(BindPoints, std::move(pTexView), pd3d11SRV);
}
__forceinline void SetBufSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
{
auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal(BindPoints, std::move(pBuffView), pd3d11SRV);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SRV>(BindPoints, std::move(pBuffView), pd3d11SRV);
}
__forceinline void SetTexUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
{
auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal(BindPoints, std::move(pTexView), pd3d11UAV);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_UAV>(BindPoints, std::move(pTexView), pd3d11UAV);
}
__forceinline void SetBufUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
{
auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
- SetD3D11ResourceInternal(BindPoints, std::move(pBuffView), pd3d11UAV);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_UAV>(BindPoints, std::move(pBuffView), pd3d11UAV);
}
__forceinline void SetSampler(BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler)
{
auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr;
- SetD3D11ResourceInternal(BindPoints, pSampler, pd3d11Sampler);
+ SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SAMPLER>(BindPoints, pSampler, pd3d11Sampler);
}
- template <typename D3D11ResourceType>
- __forceinline const typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType& GetResource(BindPointsD3D11 BindPoints) const
+ template <D3D11_RESOURCE_RANGE ResRange>
+ __forceinline const typename CachedResourceTraits<ResRange>::CachedResourceType& GetResource(BindPointsD3D11 BindPoints) const
{
- const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
- VERIFY(BindPoints[ShaderInd] < GetResourceCount<D3D11ResourceType>(ShaderInd), "Resource slot is out of range");
- const auto ResArrays = GetConstResourceArrays<D3D11ResourceType>(ShaderInd);
+ VERIFY(BindPoints.GetActiveBits() != 0, "No active shader stage");
+ const auto ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
+ const auto Offset = BindPoints[ShaderInd];
+ VERIFY(Offset < GetResourceCount<ResRange>(ShaderInd), "Resource slot is out of range");
+ const auto ResArrays = GetConstResourceArrays<ResRange>(ShaderInd);
return ResArrays.first[BindPoints[ShaderInd]];
}
- template <typename D3D11ResourceType>
+ template <D3D11_RESOURCE_RANGE ResRange>
bool CopyResource(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
{
bool IsBound = true;
@@ -233,37 +220,41 @@ public:
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- auto SrcResArrays = SrcCache.GetConstResourceArrays<D3D11ResourceType>(ShaderInd);
- auto DstResArrays = GetResourceArrays<D3D11ResourceType>(ShaderInd);
+ auto SrcResArrays = SrcCache.GetConstResourceArrays<ResRange>(ShaderInd);
+ auto DstResArrays = GetResourceArrays<ResRange>(ShaderInd);
const Uint32 CacheOffset = BindPoints[ShaderInd];
- VERIFY(CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd), "Index is out of range");
+ VERIFY(CacheOffset < GetResourceCount<ResRange>(ShaderInd), "Index is out of range");
if (!SrcResArrays.first[CacheOffset])
IsBound = false;
DstResArrays.first[CacheOffset] = SrcResArrays.first[CacheOffset];
DstResArrays.second[CacheOffset] = SrcResArrays.second[CacheOffset];
}
+ VERIFY_EXPR(IsBound == IsResourceBound<ResRange>(BindPoints));
return IsBound;
}
- template <typename D3D11ResourceType>
+ template <D3D11_RESOURCE_RANGE ResRange>
__forceinline bool IsResourceBound(BindPointsD3D11 BindPoints) const
{
- bool IsBound = true;
- for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
+ Uint32 ActiveBits = BindPoints.GetActiveBits();
+ if (ActiveBits == 0)
+ return false;
+
+ const Uint32 FirstShaderInd = PlatformMisc::GetLSB(ActiveBits);
+ const bool IsBound = IsResourceBound<ResRange>(FirstShaderInd, BindPoints[FirstShaderInd]);
+
+#ifdef DILIGENT_DEBUG
+ ActiveBits &= ~(1u << FirstShaderInd);
+ while (ActiveBits != 0)
{
const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
ActiveBits &= ~(1u << ShaderInd);
- const Uint32 CacheOffset = BindPoints[ShaderInd];
-
- const auto ResArrays = GetConstResourceArrays<D3D11ResourceType>(ShaderInd);
- if (CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd) && ResArrays.first[CacheOffset])
- {
- continue;
- }
- IsBound = false;
+ VERIFY_EXPR(IsBound == IsResourceBound<ResRange>(ShaderInd, BindPoints[ShaderInd]));
}
+#endif
+
return IsBound;
}
@@ -272,13 +263,13 @@ public:
#endif
// clang-format off
- __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*)); }
+ __forceinline Uint32 GetCBCount (Uint32 ShaderInd) const { return (m_Offsets[FirstCBOffsetIdx + ShaderInd + 1] - m_Offsets[FirstCBOffsetIdx + ShaderInd]) / (sizeof(CachedCB) + sizeof(ID3D11Buffer*)); }
+ __forceinline Uint32 GetSRVCount (Uint32 ShaderInd) const { return (m_Offsets[FirstSRVOffsetIdx + ShaderInd + 1] - m_Offsets[FirstSRVOffsetIdx + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)); }
+ __forceinline Uint32 GetSamplerCount(Uint32 ShaderInd) const { return (m_Offsets[FirstSamOffsetIdx + ShaderInd + 1] - m_Offsets[FirstSamOffsetIdx + ShaderInd]) / (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)); }
+ __forceinline Uint32 GetUAVCount (Uint32 ShaderInd) const { return (m_Offsets[FirstUAVOffsetIdx + ShaderInd + 1] - m_Offsets[FirstUAVOffsetIdx + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*));}
// clang-format on
- template <typename D3D11ResourceType>
+ template <D3D11_RESOURCE_RANGE>
__forceinline Uint32 GetResourceCount(Uint32 ShaderInd) const;
bool IsInitialized() const { return m_IsInitialized; }
@@ -304,44 +295,56 @@ public:
}
};
- template <typename D3D11ResourceType>
- MinMaxSlot BindResources(Uint32 ShaderInd,
- D3D11ResourceType* CommittedD3D11Resources[],
- Uint8& Binding) const;
+ template <D3D11_RESOURCE_RANGE Range>
+ MinMaxSlot BindResources(Uint32 ShaderInd,
+ typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Resources[],
+ Uint8& Binding) const;
- template <typename D3D11ResourceViewType>
- MinMaxSlot BindResourceViews(Uint32 ShaderInd,
- D3D11ResourceViewType* CommittedD3D11Views[],
- ID3D11Resource* CommittedD3D11Resources[],
- Uint8& Binding) const;
+ template <D3D11_RESOURCE_RANGE Range>
+ MinMaxSlot BindResourceViews(Uint32 ShaderInd,
+ typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Views[],
+ ID3D11Resource* CommittedD3D11Resources[],
+ Uint8& Binding) const;
+
+ enum class StateTransitionMode
+ {
+ Transition,
+ Verify
+ };
+ // Transitions all resources in the cache
+ template <StateTransitionMode Mode>
+ void TransitionResourceStates(DeviceContextD3D11Impl& Ctx);
private:
- template <typename D3D11ResourceTpye>
+ template <D3D11_RESOURCE_RANGE>
__forceinline Uint32 GetResourceDataOffset(Uint32 ShaderInd) const;
- template <typename D3D11ResourceType>
- __forceinline std::pair<typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType*, D3D11ResourceType**>
+ template <D3D11_RESOURCE_RANGE ResRange>
+ __forceinline std::pair<typename CachedResourceTraits<ResRange>::CachedResourceType*,
+ typename CachedResourceTraits<ResRange>::D3D11ResourceType**>
GetResourceArrays(Uint32 ShaderInd) const
{
- static_assert(alignof(CachedResourceTraits<D3D11ResourceType>::CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
+ using CachedResourceType = CachedResourceTraits<ResRange>::CachedResourceType;
+ using D3D11ResourceType = CachedResourceTraits<ResRange>::D3D11ResourceType;
+ static_assert(alignof(CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
- using CachedResourceType = CachedResourceTraits<D3D11ResourceType>::CachedResourceType;
- const auto DataOffset = GetResourceDataOffset<D3D11ResourceType>(ShaderInd);
- const auto ResCount = GetResourceCount<D3D11ResourceType>(ShaderInd);
+ const auto DataOffset = GetResourceDataOffset<ResRange>(ShaderInd);
+ const auto ResCount = GetResourceCount<ResRange>(ShaderInd);
auto* const pResources = reinterpret_cast<CachedResourceType*>(m_pResourceData.get() + DataOffset);
auto* const pd3d11Resources = reinterpret_cast<D3D11ResourceType**>(pResources + ResCount);
return std::make_pair(pResources, pd3d11Resources);
}
- template <typename D3D11ResourceType>
- __forceinline std::pair<const typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType*, D3D11ResourceType* const*>
+ template <D3D11_RESOURCE_RANGE ResRange>
+ __forceinline std::pair<typename CachedResourceTraits<ResRange>::CachedResourceType const*,
+ typename CachedResourceTraits<ResRange>::D3D11ResourceType* const*>
GetConstResourceArrays(Uint32 ShaderInd) const
{
- const auto ResArrays = GetResourceArrays<D3D11ResourceType>(ShaderInd);
+ const auto ResArrays = GetResourceArrays<ResRange>(ShaderInd);
return std::make_pair(ResArrays.first, ResArrays.second);
}
- template <typename TSrcResourceType, typename TD3D11ResourceType>
+ template <D3D11_RESOURCE_RANGE ResRange, typename TSrcResourceType, typename TD3D11ResourceType>
__forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource)
{
VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr,
@@ -352,15 +355,23 @@ private:
ActiveBits &= ~(1u << ShaderInd);
const Uint32 CacheOffset = BindPoints[ShaderInd];
- const Uint32 ResCount = GetResourceCount<TD3D11ResourceType>(ShaderInd);
- VERIFY(CacheOffset < ResCount, "Index is out of range");
+ VERIFY(CacheOffset < GetResourceCount<ResRange>(ShaderInd), "Cache offset is out of range");
- auto ResArrays = GetResourceArrays<TD3D11ResourceType>(ShaderInd);
+ auto ResArrays = GetResourceArrays<ResRange>(ShaderInd);
ResArrays.first[CacheOffset].Set(pResource);
ResArrays.second[CacheOffset] = pd3d11Resource;
}
}
+ template <D3D11_RESOURCE_RANGE ResRange>
+ __forceinline bool IsResourceBound(Uint32 ShaderInd, Uint32 Offset) const
+ {
+ const auto ResCount = GetResourceCount<ResRange>(ShaderInd);
+ VERIFY(Offset < ResCount, "Offset is out of range");
+ const auto ResArrays = GetConstResourceArrays<ResRange>(ShaderInd);
+ return Offset < ResCount && ResArrays.first[Offset];
+ }
+
// Transitions or verifies the resource state.
template <StateTransitionMode Mode>
void TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11Buffer* /*Selector*/) const;
@@ -377,15 +388,13 @@ private:
private:
using OffsetType = Uint16;
- 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 size_t MaxAlignment = std::max(std::max(std::max(alignof(CachedCB), alignof(CachedResource)), alignof(CachedSampler)), alignof(IUnknown*));
- 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 Uint32 FirstCBOffsetIdx = 0;
+ static constexpr Uint32 FirstSRVOffsetIdx = FirstCBOffsetIdx + NumShaderTypes;
+ static constexpr Uint32 FirstSamOffsetIdx = FirstSRVOffsetIdx + NumShaderTypes;
+ static constexpr Uint32 FirstUAVOffsetIdx = FirstSamOffsetIdx + NumShaderTypes;
+ static constexpr Uint32 MaxOffsets = FirstUAVOffsetIdx + NumShaderTypes + 1;
std::array<OffsetType, MaxOffsets> m_Offsets = {};
@@ -401,92 +410,95 @@ static constexpr size_t ResCacheSize = sizeof(ShaderResourceCacheD3D11);
template <>
-struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11Buffer>
+struct ShaderResourceCacheD3D11::CachedResourceTraits<D3D11_RESOURCE_RANGE_CBV>
{
using CachedResourceType = CachedCB;
+ using D3D11ResourceType = ID3D11Buffer;
};
template <>
-struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11SamplerState>
+struct ShaderResourceCacheD3D11::CachedResourceTraits<D3D11_RESOURCE_RANGE_SAMPLER>
{
using CachedResourceType = CachedSampler;
+ using D3D11ResourceType = ID3D11SamplerState;
};
template <>
-struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11ShaderResourceView>
+struct ShaderResourceCacheD3D11::CachedResourceTraits<D3D11_RESOURCE_RANGE_SRV>
{
using CachedResourceType = CachedResource;
+ using D3D11ResourceType = ID3D11ShaderResourceView;
};
template <>
-struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11UnorderedAccessView>
+struct ShaderResourceCacheD3D11::CachedResourceTraits<D3D11_RESOURCE_RANGE_UAV>
{
using CachedResourceType = CachedResource;
+ using D3D11ResourceType = ID3D11UnorderedAccessView;
};
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11Buffer>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_CBV>(Uint32 ShaderInd) const
{
return GetCBCount(ShaderInd);
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11ShaderResourceView>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_SRV>(Uint32 ShaderInd) const
{
return GetSRVCount(ShaderInd);
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_UAV>(Uint32 ShaderInd) const
{
return GetUAVCount(ShaderInd);
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11SamplerState>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_SAMPLER>(Uint32 ShaderInd) const
{
return GetSamplerCount(ShaderInd);
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11Buffer>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_CBV>(Uint32 ShaderInd) const
{
- return m_Offsets[CBOffset + ShaderInd];
+ return m_Offsets[FirstCBOffsetIdx + ShaderInd];
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11ShaderResourceView>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_SRV>(Uint32 ShaderInd) const
{
- return m_Offsets[SRVOffset + ShaderInd];
+ return m_Offsets[FirstSRVOffsetIdx + ShaderInd];
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11SamplerState>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_SAMPLER>(Uint32 ShaderInd) const
{
- return m_Offsets[SampOffset + ShaderInd];
+ return m_Offsets[FirstSamOffsetIdx + ShaderInd];
}
template <>
-__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const
+__forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_UAV>(Uint32 ShaderInd) const
{
- return m_Offsets[UAVOffset + ShaderInd];
+ return m_Offsets[FirstUAVOffsetIdx + ShaderInd];
}
// Instantiate templates
template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Transition>(DeviceContextD3D11Impl& Ctx);
template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Verify>(DeviceContextD3D11Impl& Ctx);
-
-template <typename D3D11ResourceType>
+template <D3D11_RESOURCE_RANGE Range>
ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResources(
- Uint32 ShaderInd,
- D3D11ResourceType* CommittedD3D11Resources[],
- Uint8& Binding) const
+ Uint32 ShaderInd,
+ typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Resources[],
+ Uint8& Binding) const
{
- const auto ResCount = GetResourceCount<D3D11ResourceType>(ShaderInd);
- const auto ResArrays = GetConstResourceArrays<D3D11ResourceType>(ShaderInd);
+ const auto ResCount = GetResourceCount<Range>(ShaderInd);
+ const auto ResArrays = GetConstResourceArrays<Range>(ShaderInd);
MinMaxSlot Slots;
for (Uint32 res = 0; res < ResCount; ++res)
@@ -502,15 +514,16 @@ ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResources(
return Slots;
}
-template <typename D3D11ResourceViewType>
+
+template <D3D11_RESOURCE_RANGE Range>
ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResourceViews(
- Uint32 ShaderInd,
- D3D11ResourceViewType* CommittedD3D11Views[],
- ID3D11Resource* CommittedD3D11Resources[],
- Uint8& Binding) const
+ Uint32 ShaderInd,
+ typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Views[],
+ ID3D11Resource* CommittedD3D11Resources[],
+ Uint8& Binding) const
{
- const auto ResCount = GetResourceCount<D3D11ResourceViewType>(ShaderInd);
- const auto ResArrays = GetConstResourceArrays<D3D11ResourceViewType>(ShaderInd);
+ const auto ResCount = GetResourceCount<Range>(ShaderInd);
+ const auto ResArrays = GetConstResourceArrays<Range>(ShaderInd);
MinMaxSlot Slots;
for (Uint32 res = 0; res < ResCount; ++res)
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp
index 545a124f..38700fdf 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.IsResourceBound<ID3D11Buffer>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_CBV>(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.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SRV>(GetAttribs().BindPoints + ArrayIndex);
}
};
@@ -165,7 +165,7 @@ public:
__forceinline virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
- return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_UAV>(GetAttribs().BindPoints + ArrayIndex);
}
};
@@ -181,7 +181,7 @@ public:
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
- return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_UAV>(GetAttribs().BindPoints + ArrayIndex);
}
};
@@ -197,7 +197,7 @@ public:
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
- return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SRV>(GetAttribs().BindPoints + ArrayIndex);
}
};
@@ -213,7 +213,7 @@ public:
virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
- return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11SamplerState>(GetAttribs().BindPoints + ArrayIndex);
+ return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SAMPLER>(GetAttribs().BindPoints + ArrayIndex);
}
};
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
index 6b37902d..eac5d1ea 100755
--- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
@@ -268,142 +268,126 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11&
const TBindingsPerStage& BaseBindings,
SHADER_TYPE ActiveStages)
{
- Uint8 ShaderIndices[NumShaderTypes] = {};
- SHADER_TYPE ShaderTypes[NumShaderTypes] = {};
- Uint32 ShaderCount = 0;
-
- for (Uint32 Stages = ActiveStages; Stages != 0; ++ShaderCount)
- {
- const Uint32 ShaderInd = PlatformMisc::GetLSB(Stages);
- Stages &= ~(1u << ShaderInd);
- ShaderIndices[ShaderCount] = static_cast<Uint8>(ShaderInd);
- ShaderTypes[ShaderCount] = static_cast<SHADER_TYPE>(1u << ShaderInd);
- }
+ bool ClearPixelShaderUAVs = m_CommittedRes.NumUAVs[PSInd] > 0;
- for (Uint32 i = 0; i < ShaderCount; ++i)
+ while (ActiveStages != 0)
{
- constexpr auto Range = D3D11_RESOURCE_RANGE_CBV;
- const auto ShaderInd = ShaderIndices[i];
- auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderInd];
- Uint8 Binding = BaseBindings[Range][ShaderInd];
- auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11CBs, Binding);
+ const auto ShaderInd = PlatformMisc::GetLSB(ActiveStages);
+ const auto ShaderType = static_cast<SHADER_TYPE>(1u << ShaderInd);
+ ActiveStages &= ~ShaderType;
- if (Slots)
{
- auto SetCBMethod = SetCBMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetCBMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, CommittedD3D11CBs + Slots.MinSlot);
- m_CommittedRes.NumCBs[ShaderInd] = std::max(m_CommittedRes.NumCBs[ShaderInd], Binding);
- VERIFY_EXPR(Slots.MaxSlot < Binding);
- }
+ auto* d3d11CBs = m_CommittedRes.d3d11CBs[ShaderInd];
+ Uint8 Binding = BaseBindings[D3D11_RESOURCE_RANGE_CBV][ShaderInd];
+ auto Slots = ResourceCache.BindResources<D3D11_RESOURCE_RANGE_CBV>(ShaderInd, d3d11CBs, Binding);
+
+ if (Slots)
+ {
+ auto SetCBMethod = SetCBMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetCBMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, d3d11CBs + Slots.MinSlot);
+ m_CommittedRes.NumCBs[ShaderInd] = std::max(m_CommittedRes.NumCBs[ShaderInd], Binding);
+ VERIFY_EXPR(Slots.MaxSlot < Binding);
+ }
#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedCBs(ShaderTypes[i]);
- }
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
+ {
+ DvpVerifyCommittedCBs(ShaderType);
+ }
#endif
- }
-
- for (Uint32 i = 0; i < ShaderCount; ++i)
- {
- 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];
- auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding);
+ }
- if (Slots)
{
- auto SetSRVMethod = SetSRVMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetSRVMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, CommittedD3D11SRVs + Slots.MinSlot);
- m_CommittedRes.NumSRVs[ShaderInd] = std::max(m_CommittedRes.NumSRVs[ShaderInd], Binding);
- VERIFY_EXPR(Slots.MaxSlot <= Binding);
- }
+ auto* d3d11SRVs = m_CommittedRes.d3d11SRVs[ShaderInd];
+ auto* d3d11SRVRes = m_CommittedRes.d3d11SRVResources[ShaderInd];
+ Uint8 Binding = BaseBindings[D3D11_RESOURCE_RANGE_SRV][ShaderInd];
+ auto Slots = ResourceCache.BindResourceViews<D3D11_RESOURCE_RANGE_SRV>(ShaderInd, d3d11SRVs, d3d11SRVRes, Binding);
+
+ if (Slots)
+ {
+ auto SetSRVMethod = SetSRVMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetSRVMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, d3d11SRVs + Slots.MinSlot);
+ m_CommittedRes.NumSRVs[ShaderInd] = std::max(m_CommittedRes.NumSRVs[ShaderInd], Binding);
+ VERIFY_EXPR(Slots.MaxSlot <= Binding);
+ }
#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedSRVs(ShaderTypes[i]);
- }
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
+ {
+ DvpVerifyCommittedSRVs(ShaderType);
+ }
#endif
- }
-
- for (Uint32 i = 0; i < ShaderCount; ++i)
- {
- constexpr auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
- const auto ShaderInd = ShaderIndices[i];
- auto* CommittedD3D11Samplers = m_CommittedRes.D3D11Samplers[ShaderInd];
- Uint8 Binding = BaseBindings[Range][ShaderInd];
- auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11Samplers, Binding);
+ }
- if (Slots)
{
- auto SetSamplerMethod = SetSamplerMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetSamplerMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, CommittedD3D11Samplers + Slots.MinSlot);
- m_CommittedRes.NumSamplers[ShaderInd] = std::max(m_CommittedRes.NumSamplers[ShaderInd], Binding);
- VERIFY_EXPR(Slots.MaxSlot < Binding);
- }
+ auto* d3d11Samplers = m_CommittedRes.d3d11Samplers[ShaderInd];
+ Uint8 Binding = BaseBindings[D3D11_RESOURCE_RANGE_SAMPLER][ShaderInd];
+ auto Slots = ResourceCache.BindResources<D3D11_RESOURCE_RANGE_SAMPLER>(ShaderInd, d3d11Samplers, Binding);
+
+ if (Slots)
+ {
+ auto SetSamplerMethod = SetSamplerMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetSamplerMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, d3d11Samplers + Slots.MinSlot);
+ m_CommittedRes.NumSamplers[ShaderInd] = std::max(m_CommittedRes.NumSamplers[ShaderInd], Binding);
+ VERIFY_EXPR(Slots.MaxSlot < Binding);
+ }
#ifdef VERIFY_CONTEXT_BINDINGS
- if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
- {
- DvpVerifyCommittedSamplers(ShaderTypes[i]);
- }
+ if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
+ {
+ DvpVerifyCommittedSamplers(ShaderType);
+ }
#endif
- }
-
- 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];
- auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding);
+ }
- if (Slots)
{
- if (ShaderInd == PSInd)
- ClearPixelShaderUAVs = false;
+ auto* d3d11UAVs = m_CommittedRes.d3d11UAVs[ShaderInd];
+ auto* d3d11UAVRes = m_CommittedRes.d3d11UAVResources[ShaderInd];
+ Uint8 Binding = BaseBindings[D3D11_RESOURCE_RANGE_UAV][ShaderInd];
+ auto Slots = ResourceCache.BindResourceViews<D3D11_RESOURCE_RANGE_UAV>(ShaderInd, d3d11UAVs, d3d11UAVRes, Binding);
- // Something has changed
- if (ShaderInd == PSInd)
+ if (Slots)
{
- // 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)
+ if (ShaderInd == PSInd)
+ ClearPixelShaderUAVs = false;
+
+ // Something has changed
+ if (ShaderInd == PSInd)
{
- CommittedD3D11UAVRes[uav] = nullptr;
- CommittedD3D11UAVs[uav] = nullptr;
+ // 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, d3d11UAVs + 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)
+ {
+ d3d11UAVRes[uav] = nullptr;
+ d3d11UAVs[uav] = nullptr;
+ }
+ m_CommittedRes.NumUAVs[ShaderInd] = NumUAVSlot;
+ }
+ else if (ShaderInd == CSInd)
+ {
+ // This can only be CS
+ auto SetUAVMethod = SetUAVMethods[ShaderInd];
+ (m_pd3d11DeviceContext->*SetUAVMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, d3d11UAVs + Slots.MinSlot, nullptr);
+ m_CommittedRes.NumUAVs[ShaderInd] = std::max(m_CommittedRes.NumUAVs[ShaderInd], Binding);
+ VERIFY_EXPR(Slots.MaxSlot < Binding);
+ }
+ else
+ {
+ UNEXPECTED("UAV is not supported in shader that is not pixel or compute");
}
- m_CommittedRes.NumUAVs[ShaderInd] = NumUAVSlot;
- }
- else if (ShaderInd == CSInd)
- {
- // This can only be CS
- auto SetUAVMethod = SetUAVMethods[ShaderInd];
- (m_pd3d11DeviceContext->*SetUAVMethod)(Slots.MinSlot, Slots.MaxSlot - Slots.MinSlot + 1, CommittedD3D11UAVs + Slots.MinSlot, nullptr);
- m_CommittedRes.NumUAVs[ShaderInd] = std::max(m_CommittedRes.NumUAVs[ShaderInd], Binding);
- VERIFY_EXPR(Slots.MaxSlot < Binding);
}
- else
+#ifdef VERIFY_CONTEXT_BINDINGS
+ if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderInd == CSInd)
{
- UNEXPECTED("UAV is not supported in shader that is not pixel or compute");
+ DvpVerifyCommittedUAVs(ShaderType);
}
- }
-#ifdef VERIFY_CONTEXT_BINDINGS
- if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderInd == CSInd)
- {
- DvpVerifyCommittedUAVs(ShaderTypes[i]);
- }
#endif
+ }
}
if (ClearPixelShaderUAVs)
@@ -412,8 +396,8 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11&
// This is important as UnbindPixelShaderUAV<> function may need to rebind
// existing UAVs and the UAVs pointed to by CommittedD3D11UAVRes must be alive
// (we do not keep strong references to d3d11 UAVs)
- auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[PSInd];
- auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[PSInd];
+ auto* CommittedD3D11UAVs = m_CommittedRes.d3d11UAVs[PSInd];
+ auto* CommittedD3D11UAVRes = m_CommittedRes.d3d11UAVResources[PSInd];
auto& NumCommittedPixelShaderUAVs = m_CommittedRes.NumUAVs[PSInd];
for (Uint32 uav = 0; uav < NumCommittedPixelShaderUAVs; ++uav)
{
@@ -1165,8 +1149,8 @@ void DeviceContextD3D11Impl::CommitRenderTargets()
m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews(NumRenderTargets, NumRenderTargets > 0 ? pd3d11RTs : nullptr, pd3d11DSV,
0, D3D11_KEEP_UNORDERED_ACCESS_VIEWS, nullptr, nullptr);
- auto CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[PSInd];
- auto CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[PSInd];
+ auto CommittedD3D11UAVs = m_CommittedRes.d3d11UAVs[PSInd];
+ auto CommittedD3D11UAVRes = m_CommittedRes.d3d11UAVResources[PSInd];
for (Uint32 slot = 0; slot < NumRenderTargets; ++slot)
{
CommittedD3D11UAVs[slot] = nullptr;
@@ -1289,7 +1273,7 @@ void DeviceContextD3D11Impl::UnbindTextureFromInput(TextureBaseD3D11* pTexture,
VERIFY(pTexture, "Null texture provided");
if (!pTexture) return;
- UnbindResourceView(m_CommittedRes.D3D11SRVs, m_CommittedRes.D3D11SRVResources, m_CommittedRes.NumSRVs, pd3d11Resource, SetSRVMethods);
+ UnbindResourceView(m_CommittedRes.d3d11SRVs, m_CommittedRes.d3d11SRVResources, m_CommittedRes.NumSRVs, pd3d11Resource, SetSRVMethods);
pTexture->ClearState(RESOURCE_STATE_SHADER_RESOURCE | RESOURCE_STATE_INPUT_ATTACHMENT);
}
@@ -1300,7 +1284,7 @@ void DeviceContextD3D11Impl::UnbindBufferFromInput(BufferD3D11Impl* pBuffer, ID3
if (pBuffer->CheckState(RESOURCE_STATE_SHADER_RESOURCE))
{
- UnbindResourceView(m_CommittedRes.D3D11SRVs, m_CommittedRes.D3D11SRVResources, m_CommittedRes.NumSRVs, pd3d11Buffer, SetSRVMethods);
+ UnbindResourceView(m_CommittedRes.d3d11SRVs, m_CommittedRes.d3d11SRVResources, m_CommittedRes.NumSRVs, pd3d11Buffer, SetSRVMethods);
pBuffer->ClearState(RESOURCE_STATE_SHADER_RESOURCE);
}
@@ -1346,7 +1330,7 @@ void DeviceContextD3D11Impl::UnbindBufferFromInput(BufferD3D11Impl* pBuffer, ID3
{
for (Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd)
{
- auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderTypeInd];
+ auto* CommittedD3D11CBs = m_CommittedRes.d3d11CBs[ShaderTypeInd];
auto NumSlots = m_CommittedRes.NumCBs[ShaderTypeInd];
for (Uint32 Slot = 0; Slot < NumSlots; ++Slot)
{
@@ -1368,7 +1352,7 @@ void DeviceContextD3D11Impl::UnbindResourceFromUAV(IDeviceObject* pResource, ID3
VERIFY(pResource, "Null resource provided");
if (!pResource) return;
- UnbindResourceView(m_CommittedRes.D3D11UAVs, m_CommittedRes.D3D11UAVResources, m_CommittedRes.NumUAVs, pd3d11Resource, SetUAVMethods);
+ UnbindResourceView(m_CommittedRes.d3d11UAVs, m_CommittedRes.d3d11UAVResources, m_CommittedRes.NumUAVs, pd3d11Resource, SetUAVMethods);
}
void DeviceContextD3D11Impl::UnbindTextureFromRenderTarget(TextureBaseD3D11* pTexture)
@@ -1498,7 +1482,7 @@ void DeviceContextD3D11Impl::BeginSubpass()
if (auto* pTexView = FBDesc.ppAttachments[AttachmentRef.AttachmentIndex])
{
auto* pTexD3D11 = ValidatedCast<TextureBaseD3D11>(pTexView->GetTexture());
- UnbindResourceView(m_CommittedRes.D3D11SRVs, m_CommittedRes.D3D11SRVResources, m_CommittedRes.NumSRVs, pTexD3D11->GetD3D11Texture(), SetSRVMethods);
+ UnbindResourceView(m_CommittedRes.d3d11SRVs, m_CommittedRes.d3d11SRVResources, m_CommittedRes.NumSRVs, pTexD3D11->GetD3D11Texture(), SetSRVMethods);
}
}
};
@@ -1680,18 +1664,18 @@ void DeviceContextD3D11Impl::ReleaseCommittedShaderResources()
for (int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType)
{
// clang-format off
- ReleaseCommittedShaderResourcesHelper(m_CommittedRes.D3D11CBs[ShaderType], m_CommittedRes.NumCBs[ShaderType], SetCBMethods[ShaderType], m_pd3d11DeviceContext);
- ReleaseCommittedShaderResourcesHelper(m_CommittedRes.D3D11SRVs[ShaderType], m_CommittedRes.NumSRVs[ShaderType], SetSRVMethods[ShaderType], m_pd3d11DeviceContext);
- ReleaseCommittedShaderResourcesHelper(m_CommittedRes.D3D11Samplers[ShaderType], m_CommittedRes.NumSamplers[ShaderType], SetSamplerMethods[ShaderType], m_pd3d11DeviceContext);
+ ReleaseCommittedShaderResourcesHelper(m_CommittedRes.d3d11CBs[ShaderType], m_CommittedRes.NumCBs[ShaderType], SetCBMethods[ShaderType], m_pd3d11DeviceContext);
+ ReleaseCommittedShaderResourcesHelper(m_CommittedRes.d3d11SRVs[ShaderType], m_CommittedRes.NumSRVs[ShaderType], SetSRVMethods[ShaderType], m_pd3d11DeviceContext);
+ ReleaseCommittedShaderResourcesHelper(m_CommittedRes.d3d11Samplers[ShaderType], m_CommittedRes.NumSamplers[ShaderType], SetSamplerMethods[ShaderType], m_pd3d11DeviceContext);
// clang-format on
if (ShaderType == PSInd)
- ReleaseCommittedPSUAVs(m_CommittedRes.D3D11UAVs[ShaderType], m_CommittedRes.NumUAVs[ShaderType], m_pd3d11DeviceContext);
+ ReleaseCommittedPSUAVs(m_CommittedRes.d3d11UAVs[ShaderType], m_CommittedRes.NumUAVs[ShaderType], m_pd3d11DeviceContext);
else
- ReleaseCommittedShaderResourcesHelper(m_CommittedRes.D3D11UAVs[ShaderType], m_CommittedRes.NumUAVs[ShaderType], SetUAVMethods[ShaderType], m_pd3d11DeviceContext);
+ ReleaseCommittedShaderResourcesHelper(m_CommittedRes.d3d11UAVs[ShaderType], m_CommittedRes.NumUAVs[ShaderType], SetUAVMethods[ShaderType], m_pd3d11DeviceContext);
- memset(m_CommittedRes.D3D11SRVResources[ShaderType], 0, sizeof(m_CommittedRes.D3D11SRVResources[ShaderType][0]) * m_CommittedRes.NumSRVs[ShaderType]);
- memset(m_CommittedRes.D3D11UAVResources[ShaderType], 0, sizeof(m_CommittedRes.D3D11UAVResources[ShaderType][0]) * m_CommittedRes.NumUAVs[ShaderType]);
+ memset(m_CommittedRes.d3d11SRVResources[ShaderType], 0, sizeof(m_CommittedRes.d3d11SRVResources[ShaderType][0]) * m_CommittedRes.NumSRVs[ShaderType]);
+ memset(m_CommittedRes.d3d11UAVResources[ShaderType], 0, sizeof(m_CommittedRes.d3d11UAVResources[ShaderType][0]) * m_CommittedRes.NumUAVs[ShaderType]);
m_CommittedRes.NumCBs[ShaderType] = 0;
m_CommittedRes.NumSRVs[ShaderType] = 0;
m_CommittedRes.NumSamplers[ShaderType] = 0;
@@ -2270,24 +2254,24 @@ void DeviceContextD3D11Impl::DvpVerifyViewConsistency(TD3D11ViewType CommittedD
void DeviceContextD3D11Impl::DvpVerifyCommittedSRVs(SHADER_TYPE ShaderStages)
{
- DvpVerifyCommittedResources<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>(m_CommittedRes.D3D11SRVs, m_CommittedRes.NumSRVs, GetSRVMethods, "SRV", ShaderStages);
- DvpVerifyViewConsistency<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>(m_CommittedRes.D3D11SRVs, m_CommittedRes.D3D11SRVResources, m_CommittedRes.NumSRVs, "SRV", ShaderStages);
+ DvpVerifyCommittedResources<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>(m_CommittedRes.d3d11SRVs, m_CommittedRes.NumSRVs, GetSRVMethods, "SRV", ShaderStages);
+ DvpVerifyViewConsistency<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>(m_CommittedRes.d3d11SRVs, m_CommittedRes.d3d11SRVResources, m_CommittedRes.NumSRVs, "SRV", ShaderStages);
}
void DeviceContextD3D11Impl::DvpVerifyCommittedUAVs(SHADER_TYPE ShaderStages)
{
- DvpVerifyCommittedResources<D3D11_PS_CS_UAV_REGISTER_COUNT>(m_CommittedRes.D3D11UAVs, m_CommittedRes.NumUAVs, GetUAVMethods, "UAV", ShaderStages);
- DvpVerifyViewConsistency<D3D11_PS_CS_UAV_REGISTER_COUNT>(m_CommittedRes.D3D11UAVs, m_CommittedRes.D3D11UAVResources, m_CommittedRes.NumUAVs, "UAV", ShaderStages);
+ DvpVerifyCommittedResources<D3D11_PS_CS_UAV_REGISTER_COUNT>(m_CommittedRes.d3d11UAVs, m_CommittedRes.NumUAVs, GetUAVMethods, "UAV", ShaderStages);
+ DvpVerifyViewConsistency<D3D11_PS_CS_UAV_REGISTER_COUNT>(m_CommittedRes.d3d11UAVs, m_CommittedRes.d3d11UAVResources, m_CommittedRes.NumUAVs, "UAV", ShaderStages);
}
void DeviceContextD3D11Impl::DvpVerifyCommittedSamplers(SHADER_TYPE ShaderStages)
{
- DvpVerifyCommittedResources<D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>(m_CommittedRes.D3D11Samplers, m_CommittedRes.NumSamplers, GetSamplerMethods, "Sampler", ShaderStages);
+ DvpVerifyCommittedResources<D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>(m_CommittedRes.d3d11Samplers, m_CommittedRes.NumSamplers, GetSamplerMethods, "Sampler", ShaderStages);
}
void DeviceContextD3D11Impl::DvpVerifyCommittedCBs(SHADER_TYPE ShaderStages)
{
- DvpVerifyCommittedResources<D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>(m_CommittedRes.D3D11CBs, m_CommittedRes.NumCBs, GetCBMethods, "Constant buffer", ShaderStages);
+ DvpVerifyCommittedResources<D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>(m_CommittedRes.d3d11CBs, m_CommittedRes.NumCBs, GetCBMethods, "Constant buffer", ShaderStages);
}
void DeviceContextD3D11Impl::DvpVerifyCommittedIndexBuffer()
diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
index ae706ebf..21bedd54 100644
--- a/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp
@@ -327,14 +327,14 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
case D3D11_RESOURCE_RANGE_CBV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!DstResourceCache.CopyResource<ID3D11Buffer>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
+ if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_CBV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
}
break;
case D3D11_RESOURCE_RANGE_SRV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!DstResourceCache.CopyResource<ID3D11ShaderResourceView>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
+ if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_SRV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
}
break;
@@ -344,7 +344,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
{
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!DstResourceCache.CopyResource<ID3D11SamplerState>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
+ if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_SAMPLER>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
}
}
@@ -352,7 +352,7 @@ void PipelineResourceSignatureD3D11Impl::CopyStaticResources(ShaderResourceCache
case D3D11_RESOURCE_RANGE_UAV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!DstResourceCache.CopyResource<ID3D11UnorderedAccessView>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
+ if (!DstResourceCache.CopyResource<D3D11_RESOURCE_RANGE_UAV>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
}
break;
@@ -467,7 +467,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
case D3D11_RESOURCE_RANGE_CBV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!ResourceCache.IsResourceBound<ID3D11Buffer>(ResAttr.BindPoints + ArrInd))
+ if (!ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_CBV>(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
@@ -479,7 +479,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
case D3D11_RESOURCE_RANGE_SAMPLER:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!ResourceCache.IsResourceBound<ID3D11SamplerState>(ResAttr.BindPoints + ArrInd))
+ if (!ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SAMPLER>(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
@@ -491,7 +491,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
case D3D11_RESOURCE_RANGE_SRV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(ResAttr.BindPoints + ArrInd))
+ if (!ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SRV>(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
@@ -511,7 +511,7 @@ bool PipelineResourceSignatureD3D11Impl::DvpValidateCommittedResource(const D3DS
case D3D11_RESOURCE_RANGE_UAV:
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
{
- if (!ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(ResAttr.BindPoints + ArrInd))
+ if (!ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_UAV>(ResAttr.BindPoints + ArrInd))
{
LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
"' in shader '", ShaderName, "' of PSO '", PSOName, "'");
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
index 744484df..b16a5c6d 100755
--- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceCacheD3D11.cpp
@@ -39,7 +39,7 @@
namespace Diligent
{
-size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TBindingsPerStage& ResCount)
+size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TResourcesPerStage& ResCount)
{
size_t MemSize = 0;
// clang-format off
@@ -60,7 +60,7 @@ size_t ShaderResourceCacheD3D11::GetRequriedMemorySize(const TBindingsPerStage&
return MemSize;
}
-void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMemoryAllocator& MemAllocator)
+void ShaderResourceCacheD3D11::Initialize(const TResourcesPerStage& ResCount, IMemoryAllocator& MemAllocator)
{
// http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-cache/
VERIFY(!IsInitialized(), "Resource cache has already been intialized!");
@@ -68,25 +68,25 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe
size_t MemOffset = 0;
for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
{
- const Uint32 Idx = CBOffset + ShaderInd;
+ const Uint32 Idx = FirstCBOffsetIdx + 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;
+ const Uint32 Idx = FirstSRVOffsetIdx + 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;
+ const Uint32 Idx = FirstSamOffsetIdx + 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;
+ const Uint32 Idx = FirstUAVOffsetIdx + ShaderInd;
m_Offsets[Idx] = static_cast<OffsetType>(MemOffset);
MemOffset = AlignUp(MemOffset + (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * ResCount[D3D11_RESOURCE_RANGE_UAV][ShaderInd], MaxAlignment);
}
@@ -112,7 +112,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe
const auto CBCount = GetCBCount(ShaderInd);
if (CBCount != 0)
{
- auto CBArrays = GetResourceArrays<ID3D11Buffer>(ShaderInd);
+ auto CBArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_CBV>(ShaderInd);
for (Uint32 cb = 0; cb < CBCount; ++cb)
new (CBArrays.first + cb) CachedCB{};
}
@@ -120,7 +120,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe
const auto SRVCount = GetSRVCount(ShaderInd);
if (SRVCount != 0)
{
- auto SRVArrays = GetResourceArrays<ID3D11ShaderResourceView>(ShaderInd);
+ auto SRVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SRV>(ShaderInd);
for (Uint32 srv = 0; srv < SRVCount; ++srv)
new (SRVArrays.first + srv) CachedResource{};
}
@@ -128,7 +128,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe
const auto SamplerCount = GetSamplerCount(ShaderInd);
if (SamplerCount != 0)
{
- auto SamArrays = GetResourceArrays<ID3D11SamplerState>(ShaderInd);
+ auto SamArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SAMPLER>(ShaderInd);
for (Uint32 sam = 0; sam < SamplerCount; ++sam)
new (SamArrays.first + sam) CachedSampler{};
}
@@ -136,7 +136,7 @@ void ShaderResourceCacheD3D11::Initialize(const TBindingsPerStage& ResCount, IMe
const auto UAVCount = GetUAVCount(ShaderInd);
if (UAVCount != 0)
{
- auto UAVArrays = GetResourceArrays<ID3D11UnorderedAccessView>(ShaderInd);
+ auto UAVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_UAV>(ShaderInd);
for (Uint32 uav = 0; uav < UAVCount; ++uav)
new (UAVArrays.first + uav) CachedResource{};
}
@@ -155,7 +155,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
const auto CBCount = GetCBCount(ShaderInd);
if (CBCount != 0)
{
- auto CBArrays = GetResourceArrays<ID3D11Buffer>(ShaderInd);
+ auto CBArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_CBV>(ShaderInd);
for (size_t cb = 0; cb < CBCount; ++cb)
CBArrays.first[cb].~CachedCB();
}
@@ -163,7 +163,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
const auto SRVCount = GetSRVCount(ShaderInd);
if (SRVCount != 0)
{
- auto SRVArrays = GetResourceArrays<ID3D11ShaderResourceView>(ShaderInd);
+ auto SRVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SRV>(ShaderInd);
for (size_t srv = 0; srv < SRVCount; ++srv)
SRVArrays.first[srv].~CachedResource();
}
@@ -171,7 +171,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
const auto SamplerCount = GetSamplerCount(ShaderInd);
if (SamplerCount != 0)
{
- auto SamArrays = GetResourceArrays<ID3D11SamplerState>(ShaderInd);
+ auto SamArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SAMPLER>(ShaderInd);
for (size_t sam = 0; sam < SamplerCount; ++sam)
SamArrays.first[sam].~CachedSampler();
}
@@ -179,7 +179,7 @@ ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11()
const auto UAVCount = GetUAVCount(ShaderInd);
if (UAVCount != 0)
{
- auto UAVArrays = GetResourceArrays<ID3D11UnorderedAccessView>(ShaderInd);
+ auto UAVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_UAV>(ShaderInd);
for (size_t uav = 0; uav < UAVCount; ++uav)
UAVArrays.first[uav].~CachedResource();
}
@@ -246,10 +246,10 @@ void ShaderResourceCacheD3D11::DvpVerifyCacheConsistency()
for (Uint32 ShaderInd = 0; ShaderInd < NumShaderTypes; ++ShaderInd)
{
- const auto CBArrays = GetResourceArrays<ID3D11Buffer>(ShaderInd);
- const auto SRVArrays = GetResourceArrays<ID3D11ShaderResourceView>(ShaderInd);
- const auto SamArrays = GetResourceArrays<ID3D11SamplerState>(ShaderInd);
- const auto UAVArrays = GetResourceArrays<ID3D11UnorderedAccessView>(ShaderInd);
+ const auto CBArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_CBV>(ShaderInd);
+ const auto SRVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SRV>(ShaderInd);
+ const auto SamArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SAMPLER>(ShaderInd);
+ const auto UAVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_UAV>(ShaderInd);
auto CBCount = GetCBCount(ShaderInd);
for (size_t cb = 0; cb < CBCount; ++cb)
@@ -314,7 +314,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx,
if (CBCount == 0)
continue;
- auto CBArrays = GetResourceArrays<ID3D11Buffer>(ShaderInd);
+ auto CBArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_CBV>(ShaderInd);
for (Uint32 i = 0; i < CBCount; ++i)
{
if (auto* pBuffer = CBArrays.first[i].pBuff.RawPtr<BufferD3D11Impl>())
@@ -346,7 +346,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx,
if (SRVCount == 0)
continue;
- auto SRVArrays = GetResourceArrays<ID3D11ShaderResourceView>(ShaderInd);
+ auto SRVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_SRV>(ShaderInd);
for (Uint32 i = 0; i < SRVCount; ++i)
{
auto& SRVRes = SRVArrays.first[i];
@@ -400,7 +400,7 @@ void ShaderResourceCacheD3D11::TransitionResources(DeviceContextD3D11Impl& Ctx,
if (UAVCount == 0)
continue;
- auto UAVArrays = GetResourceArrays<ID3D11UnorderedAccessView>(ShaderInd);
+ auto UAVArrays = GetResourceArrays<D3D11_RESOURCE_RANGE_UAV>(ShaderInd);
for (Uint32 i = 0; i < UAVCount; ++i)
{
auto& UAVRes = UAVArrays.first[i];
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
index 4ff053b9..2479ab1a 100644
--- a/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp
@@ -295,7 +295,7 @@ void ShaderVariableManagerD3D11::ConstBuffBindInfo::BindResource(IDeviceObject*
RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl{pBuffer, IID_BufferD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- const auto& CachedCB = ResourceCache.GetResource<ID3D11Buffer>(Attr.BindPoints + ArrayIndex);
+ const auto& CachedCB = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_CBV>(Attr.BindPoints + ArrayIndex);
VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(),
m_ParentManager.m_pSignature->GetDesc().Name);
}
@@ -319,7 +319,7 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_SRV>(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE},
RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr(),
@@ -353,7 +353,7 @@ void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVi
#ifdef DILIGENT_DEVELOPMENT
if (SampDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(SampAttr.BindPoints + SampArrayIndex);
+ auto& CachedSampler = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_SAMPLER>(SampAttr.BindPoints + SampArrayIndex);
if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl)
{
auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
@@ -397,7 +397,7 @@ void ShaderVariableManagerD3D11::SamplerBindInfo::BindResource(IDeviceObject* pS
if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
{
- auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(Attr.BindPoints + ArrayIndex);
+ auto& CachedSampler = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_SAMPLER>(Attr.BindPoints + ArrayIndex);
if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11)
{
auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
@@ -425,7 +425,7 @@ void ShaderVariableManagerD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pV
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex);
+ auto& CachedSRV = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_SRV>(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE},
RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr(),
@@ -451,7 +451,7 @@ void ShaderVariableManagerD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVi
RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_UAV>(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS},
RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr(),
@@ -476,7 +476,7 @@ void ShaderVariableManagerD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pV
RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
#ifdef DILIGENT_DEVELOPMENT
{
- auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex);
+ auto& CachedUAV = ResourceCache.GetResource<D3D11_RESOURCE_RANGE_UAV>(Attr.BindPoints + ArrayIndex);
VerifyResourceViewBinding(Desc, ArrayIndex,
pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS},
RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr(),