Diligent Engine  v.2.4.g
ShaderResourceCacheD3D11.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
32 
33 #include <array>
34 #include <memory>
35 #include <utility>
36 
37 #include "MemoryAllocator.h"
40 
41 #include "TextureBaseD3D11.hpp"
42 #include "TextureViewD3D11Impl.hpp"
43 #include "BufferD3D11Impl.hpp"
44 #include "BufferViewD3D11Impl.hpp"
45 #include "SamplerD3D11Impl.hpp"
46 
47 namespace Diligent
48 {
49 
51 // All resources are stored in the continuous memory using the following layout:
52 //
53 // | CachedCB | ID3D11Buffer* || CachedResource | ID3D11ShaderResourceView* || CachedSampler | ID3D11SamplerState* || CachedResource | ID3D11UnorderedAccessView*||
54 // |---------------------------------------------------||--------------------------|---------------------------||------------------------------|-----------------------------||-------------------------|---------------------------||
55 // | 0 | 1 | ... | CBCount-1 | 0 | 1 | ...| CBCount-1 || 0 | 1 | ... | SRVCount-1 | 0 | 1 | ... | SRVCount-1 || 0 | 1 | ... | SamplerCount-1 | 0 | 1 | ...| SamplerCount-1 ||0 | 1 | ... | UAVCount-1 | 0 | 1 | ... | UAVCount-1 ||
56 // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
57 //
59 {
60 public:
61  explicit ShaderResourceCacheD3D11(ResourceCacheContentType ContentType) noexcept :
62  m_ContentType{ContentType}
63  {}
64 
66 
67  // clang-format off
72  // clang-format on
73 
75  struct CachedCB
76  {
79 
80  explicit operator bool() const
81  {
82  return pBuff;
83  }
84 
85  __forceinline void Set(RefCntAutoPtr<BufferD3D11Impl> _pBuff)
86  {
87  pBuff = std::move(_pBuff);
88  }
89  };
90 
93  {
96 
97  explicit operator bool() const
98  {
99  return pSampler;
100  }
101 
102  __forceinline void Set(SamplerD3D11Impl* pSam)
103  {
104  pSampler = pSam;
105  }
106  };
107 
110  {
117 
120 
121  // There is no need to keep strong reference to D3D11 resource as
122  // it is already kept by either pTexture or pBuffer
123  ID3D11Resource* pd3d11Resource = nullptr;
124 
125  CachedResource() noexcept {}
126 
127  explicit operator bool() const
128  {
129  VERIFY_EXPR((pView && pd3d11Resource != nullptr) || (!pView && pd3d11Resource == nullptr));
130  VERIFY_EXPR(pTexture == nullptr || pBuffer == nullptr);
131  VERIFY_EXPR((pView && (pTexture != nullptr || pBuffer != nullptr)) || (!pView && (pTexture == nullptr && pBuffer == nullptr)));
132  return pView;
133  }
134 
135  __forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
136  {
137  pBuffer = nullptr;
138  // Avoid unnecessary virtual function calls
139  pTexture = pTexView ? pTexView->GetTexture<TextureBaseD3D11>() : nullptr;
140  pView = std::move(pTexView);
141  pd3d11Resource = pTexture ? pTexture->TextureBaseD3D11::GetD3D11Texture() : nullptr;
142  }
143 
144  __forceinline void Set(RefCntAutoPtr<BufferViewD3D11Impl> pBufView)
145  {
146  pTexture = nullptr;
147  // Avoid unnecessary virtual function calls
148  pBuffer = pBufView ? pBufView->GetBuffer<BufferD3D11Impl>() : nullptr;
149  pView = std::move(pBufView);
150  pd3d11Resource = pBuffer ? pBuffer->BufferD3D11Impl::GetD3D11Buffer() : nullptr;
151  }
152  };
153 
154  template <D3D11_RESOURCE_RANGE>
156 
157  static size_t GetRequriedMemorySize(const D3D11ShaderResourceCounters& ResCount);
158 
159  void Initialize(const D3D11ShaderResourceCounters& ResCount, IMemoryAllocator& MemAllocator);
160 
161  __forceinline void SetCB(const D3D11ResourceBindPoints& BindPoints, RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl)
162  {
163  auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr;
164  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_CBV>(BindPoints, std::move(pBuffD3D11Impl), pd3d11Buff);
165  }
166 
167  __forceinline void SetTexSRV(const D3D11ResourceBindPoints& BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
168  {
169  auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
170  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SRV>(BindPoints, std::move(pTexView), pd3d11SRV);
171  }
172 
173  __forceinline void SetBufSRV(const D3D11ResourceBindPoints& BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
174  {
175  auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
176  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SRV>(BindPoints, std::move(pBuffView), pd3d11SRV);
177  }
178 
179  __forceinline void SetTexUAV(const D3D11ResourceBindPoints& BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
180  {
181  auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
182  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_UAV>(BindPoints, std::move(pTexView), pd3d11UAV);
183  }
184 
185  __forceinline void SetBufUAV(const D3D11ResourceBindPoints& BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
186  {
187  auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
188  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_UAV>(BindPoints, std::move(pBuffView), pd3d11UAV);
189  }
190 
191  __forceinline void SetSampler(const D3D11ResourceBindPoints& BindPoints, SamplerD3D11Impl* pSampler)
192  {
193  auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr;
194  SetD3D11ResourceInternal<D3D11_RESOURCE_RANGE_SAMPLER>(BindPoints, pSampler, pd3d11Sampler);
195  }
196 
197 
198  template <D3D11_RESOURCE_RANGE ResRange>
199  __forceinline const typename CachedResourceTraits<ResRange>::CachedResourceType& GetResource(const D3D11ResourceBindPoints& BindPoints) const
200  {
201  VERIFY(BindPoints.GetActiveStages() != SHADER_TYPE_UNKNOWN, "No active shader stage");
202  const auto ShaderInd = GetFirstShaderStageIndex(BindPoints.GetActiveStages());
203  const auto Offset = BindPoints[ShaderInd];
204  VERIFY(Offset < GetResourceCount<ResRange>(ShaderInd), "Resource slot is out of range");
205  const auto ResArrays = GetConstResourceArrays<ResRange>(ShaderInd);
206  return ResArrays.first[BindPoints[ShaderInd]];
207  }
208 
209  template <D3D11_RESOURCE_RANGE ResRange>
210  bool CopyResource(const ShaderResourceCacheD3D11& SrcCache, const D3D11ResourceBindPoints& BindPoints)
211  {
212  bool IsBound = true;
213  for (auto ActiveStages = BindPoints.GetActiveStages(); ActiveStages != SHADER_TYPE_UNKNOWN;)
214  {
215  const auto ShaderInd = ExtractFirstShaderStageIndex(ActiveStages);
216 
217  auto SrcResArrays = SrcCache.GetConstResourceArrays<ResRange>(ShaderInd);
218  auto DstResArrays = GetResourceArrays<ResRange>(ShaderInd);
219 
220  const Uint32 CacheOffset = BindPoints[ShaderInd];
221  VERIFY(CacheOffset < GetResourceCount<ResRange>(ShaderInd), "Index is out of range");
222  if (!SrcResArrays.first[CacheOffset])
223  IsBound = false;
224 
225  DstResArrays.first[CacheOffset] = SrcResArrays.first[CacheOffset];
226  DstResArrays.second[CacheOffset] = SrcResArrays.second[CacheOffset];
227  }
228  VERIFY_EXPR(IsBound == IsResourceBound<ResRange>(BindPoints));
229  return IsBound;
230  }
231 
232  template <D3D11_RESOURCE_RANGE ResRange>
233  __forceinline bool IsResourceBound(const D3D11ResourceBindPoints& BindPoints) const
234  {
235  if (BindPoints.IsEmpty())
236  return false;
237 
238  auto ActiveStages = BindPoints.GetActiveStages();
239  const auto FirstShaderInd = ExtractFirstShaderStageIndex(ActiveStages);
240  const bool IsBound = IsResourceBound<ResRange>(FirstShaderInd, BindPoints[FirstShaderInd]);
241 
242 #ifdef DILIGENT_DEBUG
243  while (ActiveStages != SHADER_TYPE_UNKNOWN)
244  {
245  const Uint32 ShaderInd = ExtractFirstShaderStageIndex(ActiveStages);
246  VERIFY_EXPR(IsBound == IsResourceBound<ResRange>(ShaderInd, BindPoints[ShaderInd]));
247  }
248 #endif
249 
250  return IsBound;
251  }
252 
253  // clang-format off
254  __forceinline Uint32 GetCBCount (Uint32 ShaderInd) const { return (m_Offsets[FirstCBOffsetIdx + ShaderInd + 1] - m_Offsets[FirstCBOffsetIdx + ShaderInd]) / (sizeof(CachedCB) + sizeof(ID3D11Buffer*)); }
255  __forceinline Uint32 GetSRVCount (Uint32 ShaderInd) const { return (m_Offsets[FirstSRVOffsetIdx + ShaderInd + 1] - m_Offsets[FirstSRVOffsetIdx + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11ShaderResourceView*)); }
256  __forceinline Uint32 GetSamplerCount(Uint32 ShaderInd) const { return (m_Offsets[FirstSamOffsetIdx + ShaderInd + 1] - m_Offsets[FirstSamOffsetIdx + ShaderInd]) / (sizeof(CachedSampler) + sizeof(ID3D11SamplerState*)); }
257  __forceinline Uint32 GetUAVCount (Uint32 ShaderInd) const { return (m_Offsets[FirstUAVOffsetIdx + ShaderInd + 1] - m_Offsets[FirstUAVOffsetIdx + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*));}
258  // clang-format on
259 
260  template <D3D11_RESOURCE_RANGE>
261  __forceinline Uint32 GetResourceCount(Uint32 ShaderInd) const;
262 
263  bool IsInitialized() const { return m_IsInitialized; }
264 
265  ResourceCacheContentType GetContentType() const { return m_ContentType; }
266 
267  struct MinMaxSlot
268  {
269  UINT MinSlot = UINT_MAX;
270  UINT MaxSlot = 0;
271 
272  void Add(UINT Slot)
273  {
274  MinSlot = std::min(MinSlot, Slot);
275 
276  VERIFY_EXPR(Slot >= MaxSlot);
277  MaxSlot = Slot;
278  }
279 
280  explicit operator bool() const
281  {
282  return MinSlot <= MaxSlot;
283  }
284  };
285 
286  template <D3D11_RESOURCE_RANGE Range>
287  inline MinMaxSlot BindResources(Uint32 ShaderInd,
288  typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Resources[],
289  const D3D11ShaderResourceCounters& BaseBindings) const;
290 
291  template <D3D11_RESOURCE_RANGE Range>
292  inline MinMaxSlot BindResourceViews(Uint32 ShaderInd,
293  typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Views[],
294  ID3D11Resource* CommittedD3D11Resources[],
295  const D3D11ShaderResourceCounters& BaseBindings) const;
296 
298  {
299  Transition,
300  Verify
301  };
302  // Transitions all resources in the cache
303  template <StateTransitionMode Mode>
305 
306 private:
307  template <D3D11_RESOURCE_RANGE>
308  __forceinline Uint32 GetResourceDataOffset(Uint32 ShaderInd) const;
309 
310  template <D3D11_RESOURCE_RANGE ResRange>
311  __forceinline std::pair<typename CachedResourceTraits<ResRange>::CachedResourceType*,
312  typename CachedResourceTraits<ResRange>::D3D11ResourceType**>
313  GetResourceArrays(Uint32 ShaderInd) const
314  {
315  using CachedResourceType = CachedResourceTraits<ResRange>::CachedResourceType;
316  using D3D11ResourceType = CachedResourceTraits<ResRange>::D3D11ResourceType;
317  static_assert(alignof(CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
318 
319  const auto DataOffset = GetResourceDataOffset<ResRange>(ShaderInd);
320  const auto ResCount = GetResourceCount<ResRange>(ShaderInd);
321  auto* const pResources = reinterpret_cast<CachedResourceType*>(m_pResourceData.get() + DataOffset);
322  auto* const pd3d11Resources = reinterpret_cast<D3D11ResourceType**>(pResources + ResCount);
323  return std::make_pair(pResources, pd3d11Resources);
324  }
325 
326  template <D3D11_RESOURCE_RANGE ResRange>
327  __forceinline std::pair<typename CachedResourceTraits<ResRange>::CachedResourceType const*,
328  typename CachedResourceTraits<ResRange>::D3D11ResourceType* const*>
329  GetConstResourceArrays(Uint32 ShaderInd) const
330  {
331  const auto ResArrays = GetResourceArrays<ResRange>(ShaderInd);
332  return std::make_pair(ResArrays.first, ResArrays.second);
333  }
334 
335  template <D3D11_RESOURCE_RANGE ResRange, typename TSrcResourceType, typename TD3D11ResourceType>
336  __forceinline void SetD3D11ResourceInternal(const D3D11ResourceBindPoints& BindPoints, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource)
337  {
338  VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr,
339  "Resource and D3D11 resource must be set/unset atomically");
340  for (auto ActiveStages = BindPoints.GetActiveStages(); ActiveStages != SHADER_TYPE_UNKNOWN;)
341  {
342  const Uint32 ShaderInd = ExtractFirstShaderStageIndex(ActiveStages);
343  const Uint32 CacheOffset = BindPoints[ShaderInd];
344  VERIFY(CacheOffset < GetResourceCount<ResRange>(ShaderInd), "Cache offset is out of range");
345 
346  auto ResArrays = GetResourceArrays<ResRange>(ShaderInd);
347  ResArrays.first[CacheOffset].Set(pResource);
348  ResArrays.second[CacheOffset] = pd3d11Resource;
349  }
350  }
351 
352  template <D3D11_RESOURCE_RANGE ResRange>
353  __forceinline bool IsResourceBound(Uint32 ShaderInd, Uint32 Offset) const
354  {
355  const auto ResCount = GetResourceCount<ResRange>(ShaderInd);
356  VERIFY(Offset < ResCount, "Offset is out of range");
357  const auto ResArrays = GetConstResourceArrays<ResRange>(ShaderInd);
358  return Offset < ResCount && ResArrays.first[Offset];
359  }
360 
361  // Transitions or verifies the resource state.
362  template <StateTransitionMode Mode>
363  void TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11Buffer* /*Selector*/) const;
364 
365  template <StateTransitionMode Mode>
366  void TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11ShaderResourceView* /*Selector*/) const;
367 
368  template <StateTransitionMode Mode>
369  void TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11SamplerState* /*Selector*/) const;
370 
371  template <StateTransitionMode Mode>
372  void TransitionResources(DeviceContextD3D11Impl& Ctx, const ID3D11UnorderedAccessView* /*Selector*/) const;
373 
374 private:
375  using OffsetType = Uint16;
376 
377  static constexpr size_t MaxAlignment = std::max(std::max(std::max(alignof(CachedCB), alignof(CachedResource)), alignof(CachedSampler)), alignof(IUnknown*));
378 
379  static constexpr int NumShaderTypes = D3D11ResourceBindPoints::NumShaderTypes;
380 
381  static constexpr Uint32 FirstCBOffsetIdx = 0;
382  static constexpr Uint32 FirstSRVOffsetIdx = FirstCBOffsetIdx + NumShaderTypes;
383  static constexpr Uint32 FirstSamOffsetIdx = FirstSRVOffsetIdx + NumShaderTypes;
384  static constexpr Uint32 FirstUAVOffsetIdx = FirstSamOffsetIdx + NumShaderTypes;
385  static constexpr Uint32 MaxOffsets = FirstUAVOffsetIdx + NumShaderTypes + 1;
386 
387  std::array<OffsetType, MaxOffsets> m_Offsets = {};
388 
389  bool m_IsInitialized = false;
390 
391  // Indicates what types of resources are stored in the cache
392  const ResourceCacheContentType m_ContentType;
393 
394  std::unique_ptr<Uint8, STDDeleter<Uint8, IMemoryAllocator>> m_pResourceData;
395 };
396 
397 static constexpr size_t ResCacheSize = sizeof(ShaderResourceCacheD3D11);
398 
399 
400 template <>
402 {
404  using D3D11ResourceType = ID3D11Buffer;
405 };
406 
407 template <>
409 {
411  using D3D11ResourceType = ID3D11SamplerState;
412 };
413 
414 template <>
416 {
418  using D3D11ResourceType = ID3D11ShaderResourceView;
419 };
420 
421 template <>
423 {
425  using D3D11ResourceType = ID3D11UnorderedAccessView;
426 };
427 
428 
429 template <>
430 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_CBV>(Uint32 ShaderInd) const
431 {
432  return GetCBCount(ShaderInd);
433 }
434 
435 template <>
436 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_SRV>(Uint32 ShaderInd) const
437 {
438  return GetSRVCount(ShaderInd);
439 }
440 
441 template <>
442 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_UAV>(Uint32 ShaderInd) const
443 {
444  return GetUAVCount(ShaderInd);
445 }
446 
447 template <>
448 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<D3D11_RESOURCE_RANGE_SAMPLER>(Uint32 ShaderInd) const
449 {
450  return GetSamplerCount(ShaderInd);
451 }
452 
453 
454 template <>
455 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_CBV>(Uint32 ShaderInd) const
456 {
457  return m_Offsets[FirstCBOffsetIdx + ShaderInd];
458 }
459 
460 template <>
461 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_SRV>(Uint32 ShaderInd) const
462 {
463  return m_Offsets[FirstSRVOffsetIdx + ShaderInd];
464 }
465 
466 template <>
467 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_SAMPLER>(Uint32 ShaderInd) const
468 {
469  return m_Offsets[FirstSamOffsetIdx + ShaderInd];
470 }
471 
472 template <>
473 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<D3D11_RESOURCE_RANGE_UAV>(Uint32 ShaderInd) const
474 {
475  return m_Offsets[FirstUAVOffsetIdx + ShaderInd];
476 }
477 
478 // Instantiate templates
479 template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Transition>(DeviceContextD3D11Impl& Ctx);
480 template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Verify>(DeviceContextD3D11Impl& Ctx);
481 
482 template <D3D11_RESOURCE_RANGE Range>
484  Uint32 ShaderInd,
485  typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Resources[],
486  const D3D11ShaderResourceCounters& BaseBindings) const
487 {
488  const auto ResCount = GetResourceCount<Range>(ShaderInd);
489  const auto ResArrays = GetConstResourceArrays<Range>(ShaderInd);
490  const Uint32 BaseBinding = BaseBindings[Range][ShaderInd];
491 
492  MinMaxSlot Slots;
493  for (Uint32 res = 0; res < ResCount; ++res)
494  {
495  const Uint32 Slot = BaseBinding + res;
496  if (CommittedD3D11Resources[Slot] != ResArrays.second[res])
497  Slots.Add(Slot);
498 
499  VERIFY_EXPR(ResArrays.second[res] != nullptr);
500  CommittedD3D11Resources[Slot] = ResArrays.second[res];
501  }
502 
503  return Slots;
504 }
505 
506 
507 template <D3D11_RESOURCE_RANGE Range>
509  Uint32 ShaderInd,
510  typename CachedResourceTraits<Range>::D3D11ResourceType* CommittedD3D11Views[],
511  ID3D11Resource* CommittedD3D11Resources[],
512  const D3D11ShaderResourceCounters& BaseBindings) const
513 {
514  const auto ResCount = GetResourceCount<Range>(ShaderInd);
515  const auto ResArrays = GetConstResourceArrays<Range>(ShaderInd);
516  const Uint32 BaseBinding = BaseBindings[Range][ShaderInd];
517 
518  MinMaxSlot Slots;
519  for (Uint32 res = 0; res < ResCount; ++res)
520  {
521  const Uint32 Slot = BaseBinding + res;
522  if (CommittedD3D11Views[Slot] != ResArrays.second[res])
523  Slots.Add(Slot);
524 
525  VERIFY_EXPR(ResArrays.second[res] != nullptr);
526  CommittedD3D11Resources[Slot] = ResArrays.first[res].pd3d11Resource;
527  CommittedD3D11Views[Slot] = ResArrays.second[res];
528  }
529 
530  return Slots;
531 }
532 
533 } // namespace Diligent
Diligent::ResourceCacheContentType
ResourceCacheContentType
The type of the content that is stored in the shader resource cache.
Definition: ShaderResourceCacheCommon.hpp:39
ShaderResourceCacheCommon.hpp
Diligent::D3D11ResourceBindPoints::IsEmpty
bool IsEmpty() const
Definition: PipelineResourceAttribsD3D11.hpp:76
Diligent::ShaderResourceCacheD3D11::MinMaxSlot
Definition: ShaderResourceCacheD3D11.hpp:267
Diligent::ExtractFirstShaderStageIndex
Int32 ExtractFirstShaderStageIndex(SHADER_TYPE &Stages)
Definition: GraphicsAccessories.hpp:450
Diligent::ShaderResourceCacheD3D11::GetRequriedMemorySize
static size_t GetRequriedMemorySize(const D3D11ShaderResourceCounters &ResCount)
Definition: ShaderResourceCacheD3D11.cpp:42
Diligent::ShaderResourceCacheD3D11::SetTexUAV
__forceinline void SetTexUAV(const D3D11ResourceBindPoints &BindPoints, RefCntAutoPtr< TextureViewD3D11Impl > pTexView)
Definition: ShaderResourceCacheD3D11.hpp:179
Diligent::ShaderResourceCacheD3D11::CachedResource::pBuffer
BufferD3D11Impl * pBuffer
Definition: ShaderResourceCacheD3D11.hpp:119
Diligent::ShaderResourceCacheD3D11::CachedSampler::pSampler
RefCntAutoPtr< SamplerD3D11Impl > pSampler
Strong reference to the sampler.
Definition: ShaderResourceCacheD3D11.hpp:95
Diligent::ShaderResourceCacheD3D11::CachedCB
Describes a resource associated with a cached constant buffer.
Definition: ShaderResourceCacheD3D11.hpp:75
Diligent::ShaderResourceCacheD3D11::StateTransitionMode::Transition
@ Transition
Diligent::ShaderResourceCacheD3D11::operator=
ShaderResourceCacheD3D11 & operator=(const ShaderResourceCacheD3D11 &)=delete
BufferViewD3D11Impl.hpp
Diligent::ShaderResourceCacheD3D11::IsInitialized
bool IsInitialized() const
Definition: ShaderResourceCacheD3D11.hpp:263
Diligent::DeviceContextD3D11Impl
Device context implementation in Direct3D11 backend.
Definition: DeviceContextD3D11Impl.hpp:56
SamplerD3D11Impl.hpp
Diligent::ShaderResourceCacheD3D11::GetUAVCount
__forceinline Uint32 GetUAVCount(Uint32 ShaderInd) const
Definition: ShaderResourceCacheD3D11.hpp:257
Diligent::ShaderResourceCacheD3D11::SetTexSRV
__forceinline void SetTexSRV(const D3D11ResourceBindPoints &BindPoints, RefCntAutoPtr< TextureViewD3D11Impl > pTexView)
Definition: ShaderResourceCacheD3D11.hpp:167
Diligent::ShaderResourceCacheD3D11::~ShaderResourceCacheD3D11
~ShaderResourceCacheD3D11()
Definition: ShaderResourceCacheD3D11.cpp:148
Diligent::D3D11_RESOURCE_RANGE_SAMPLER
@ D3D11_RESOURCE_RANGE_SAMPLER
Definition: PipelineResourceAttribsD3D11.hpp:47
Diligent::D3D11_RESOURCE_RANGE_SRV
@ D3D11_RESOURCE_RANGE_SRV
Definition: PipelineResourceAttribsD3D11.hpp:46
Diligent::ShaderResourceCacheD3D11::CachedCB::pBuff
RefCntAutoPtr< BufferD3D11Impl > pBuff
Strong reference to the buffer.
Definition: ShaderResourceCacheD3D11.hpp:78
Diligent::ShaderResourceCacheD3D11::SetCB
__forceinline void SetCB(const D3D11ResourceBindPoints &BindPoints, RefCntAutoPtr< BufferD3D11Impl > pBuffD3D11Impl)
Definition: ShaderResourceCacheD3D11.hpp:161
Diligent::D3D11_RESOURCE_RANGE_CBV
@ D3D11_RESOURCE_RANGE_CBV
Definition: PipelineResourceAttribsD3D11.hpp:45
Diligent::TextureBaseD3D11
Base implementation of a texture object in Direct3D11 backend.
Definition: TextureBaseD3D11.hpp:44
Diligent::ShaderResourceCacheD3D11::MinMaxSlot::MaxSlot
UINT MaxSlot
Definition: ShaderResourceCacheD3D11.hpp:270
Diligent::ShaderResourceCacheD3D11::CachedResourceTraits< D3D11_RESOURCE_RANGE_UAV >::D3D11ResourceType
ID3D11UnorderedAccessView D3D11ResourceType
Definition: ShaderResourceCacheD3D11.hpp:425
Diligent::ShaderResourceCacheD3D11::GetSamplerCount
__forceinline Uint32 GetSamplerCount(Uint32 ShaderInd) const
Definition: ShaderResourceCacheD3D11.hpp:256
std::min
Diligent::Vector2< T > min(const Diligent::Vector2< T > &Left, const Diligent::Vector2< T > &Right)
Definition: BasicMath.hpp:2289
Diligent::ShaderResourceCacheD3D11::CachedResource
Describes a resource associated with a cached SRV or a UAV.
Definition: ShaderResourceCacheD3D11.hpp:109
Diligent::ShaderResourceCacheD3D11::StateTransitionMode::Verify
@ Verify
Diligent::ShaderResourceCacheD3D11::Initialize
void Initialize(const D3D11ShaderResourceCounters &ResCount, IMemoryAllocator &MemAllocator)
Definition: ShaderResourceCacheD3D11.cpp:63
Diligent::SamplerD3D11Impl
Sampler implementation in Direct3D11 backend.
Definition: SamplerD3D11Impl.hpp:42
Diligent::ShaderResourceCacheD3D11::SetSampler
__forceinline void SetSampler(const D3D11ResourceBindPoints &BindPoints, SamplerD3D11Impl *pSampler)
Definition: ShaderResourceCacheD3D11.hpp:191
Diligent::ShaderResourceCacheD3D11::TransitionResourceStates
void TransitionResourceStates(DeviceContextD3D11Impl &Ctx)
Definition: ShaderResourceCacheD3D11.cpp:195
Diligent::ShaderResourceCacheD3D11::MinMaxSlot::Add
void Add(UINT Slot)
Definition: ShaderResourceCacheD3D11.hpp:272
Diligent::ShaderResourceCacheD3D11::CachedResource::pd3d11Resource
ID3D11Resource * pd3d11Resource
Definition: ShaderResourceCacheD3D11.hpp:123
Diligent::D3D11ShaderResourceCounters
std::array< D3D11ResourceRangeCounters, D3D11_RESOURCE_RANGE_COUNT > D3D11ShaderResourceCounters
Resource counters for all shader stages and all resource types.
Definition: PipelineResourceAttribsD3D11.hpp:271
PipelineResourceAttribsD3D11.hpp
Diligent::ShaderResourceCacheD3D11::BindResourceViews
MinMaxSlot BindResourceViews(Uint32 ShaderInd, typename CachedResourceTraits< Range >::D3D11ResourceType *CommittedD3D11Views[], ID3D11Resource *CommittedD3D11Resources[], const D3D11ShaderResourceCounters &BaseBindings) const
Definition: ShaderResourceCacheD3D11.hpp:508
Diligent::ShaderResourceCacheD3D11::SetBufUAV
__forceinline void SetBufUAV(const D3D11ResourceBindPoints &BindPoints, RefCntAutoPtr< BufferViewD3D11Impl > pBuffView)
Definition: ShaderResourceCacheD3D11.hpp:185
Diligent::ShaderResourceCacheD3D11::ShaderResourceCacheD3D11
ShaderResourceCacheD3D11(ResourceCacheContentType ContentType) noexcept
Definition: ShaderResourceCacheD3D11.hpp:61
Diligent::ShaderResourceCacheD3D11::CachedResource::pView
RefCntAutoPtr< IDeviceObject > pView
Wee keep strong reference to the view instead of the reference to the texture or buffer because this ...
Definition: ShaderResourceCacheD3D11.hpp:116
Diligent::ShaderResourceCacheD3D11::SetBufSRV
__forceinline void SetBufSRV(const D3D11ResourceBindPoints &BindPoints, RefCntAutoPtr< BufferViewD3D11Impl > pBuffView)
Definition: ShaderResourceCacheD3D11.hpp:173
Diligent::ShaderResourceCacheD3D11::CachedSampler
Describes a resource associated with a cached sampler.
Definition: ShaderResourceCacheD3D11.hpp:92
Diligent::RefCntAutoPtr
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
Diligent::ShaderResourceCacheD3D11::MinMaxSlot::MinSlot
UINT MinSlot
Definition: ShaderResourceCacheD3D11.hpp:269
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::ShaderResourceCacheD3D11::CachedResourceTraits< D3D11_RESOURCE_RANGE_CBV >::D3D11ResourceType
ID3D11Buffer D3D11ResourceType
Definition: ShaderResourceCacheD3D11.hpp:404
Diligent::ShaderResourceCacheD3D11::StateTransitionMode
StateTransitionMode
Definition: ShaderResourceCacheD3D11.hpp:297
Diligent::SHADER_TYPE_UNKNOWN
@ SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: GraphicsTypes.h:67
Diligent::ShaderResourceCacheD3D11::CachedResource::pTexture
TextureBaseD3D11 * pTexture
Definition: ShaderResourceCacheD3D11.hpp:118
Diligent::D3D11ResourceBindPoints
Resource binding points in all shader stages.
Definition: PipelineResourceAttribsD3D11.hpp:56
Diligent::D3D11ResourceBindPoints::GetActiveStages
SHADER_TYPE GetActiveStages() const
Definition: PipelineResourceAttribsD3D11.hpp:71
Diligent::BufferD3D11Impl
Buffer object implementation in Direct3D11 backend.
Definition: BufferD3D11Impl.hpp:42
Diligent::ShaderResourceCacheD3D11::CachedResourceTraits
Definition: ShaderResourceCacheD3D11.hpp:155
Diligent::GetFirstShaderStageIndex
Int32 GetFirstShaderStageIndex(SHADER_TYPE Stages)
Definition: GraphicsAccessories.hpp:440
Diligent::ShaderResourceCacheD3D11
The class implements a cache that holds resources bound to all shader stages.
Definition: ShaderResourceCacheD3D11.hpp:58
Diligent::ShaderResourceCacheD3D11::CachedCB::Set
__forceinline void Set(RefCntAutoPtr< BufferD3D11Impl > _pBuff)
Definition: ShaderResourceCacheD3D11.hpp:85
Diligent::ShaderResourceCacheD3D11::GetResourceCount
__forceinline Uint32 GetResourceCount(Uint32 ShaderInd) const
Diligent::IMemoryAllocator
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
Diligent::ShaderResourceCacheD3D11::CachedResourceTraits< D3D11_RESOURCE_RANGE_SRV >::D3D11ResourceType
ID3D11ShaderResourceView D3D11ResourceType
Definition: ShaderResourceCacheD3D11.hpp:418
TextureViewD3D11Impl.hpp
MemoryAllocator.h
Diligent::D3D11_RESOURCE_RANGE_UAV
@ D3D11_RESOURCE_RANGE_UAV
Definition: PipelineResourceAttribsD3D11.hpp:48
Diligent::Uint16
uint16_t Uint16
16-bit unsigned integer
Definition: BasicTypes.h:52
std::max
Diligent::Vector2< T > max(const Diligent::Vector2< T > &Left, const Diligent::Vector2< T > &Right)
Definition: BasicMath.hpp:2261
Diligent::ShaderResourceCacheD3D11::IsResourceBound
__forceinline bool IsResourceBound(const D3D11ResourceBindPoints &BindPoints) const
Definition: ShaderResourceCacheD3D11.hpp:233
TextureBaseD3D11.hpp
VERIFY_EXPR
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Diligent::ShaderResourceCacheD3D11::CachedSampler::Set
__forceinline void Set(SamplerD3D11Impl *pSam)
Definition: ShaderResourceCacheD3D11.hpp:102
Diligent::ShaderResourceCacheD3D11::CachedResourceTraits< D3D11_RESOURCE_RANGE_SAMPLER >::D3D11ResourceType
ID3D11SamplerState D3D11ResourceType
Definition: ShaderResourceCacheD3D11.hpp:411
VERIFY
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Diligent::D3D11ResourceBindPoints::NumShaderTypes
static constexpr Uint32 NumShaderTypes
The number of different shader types (Vertex, Pixel, Geometry, Hull, Domain, Compute)
Definition: PipelineResourceAttribsD3D11.hpp:59
Diligent::ShaderResourceCacheD3D11::GetContentType
ResourceCacheContentType GetContentType() const
Definition: ShaderResourceCacheD3D11.hpp:265
Diligent::ShaderResourceCacheD3D11::GetResource
const __forceinline CachedResourceTraits< ResRange >::CachedResourceType & GetResource(const D3D11ResourceBindPoints &BindPoints) const
Definition: ShaderResourceCacheD3D11.hpp:199
Diligent::ShaderResourceCacheD3D11::BindResources
MinMaxSlot BindResources(Uint32 ShaderInd, typename CachedResourceTraits< Range >::D3D11ResourceType *CommittedD3D11Resources[], const D3D11ShaderResourceCounters &BaseBindings) const
Definition: ShaderResourceCacheD3D11.hpp:483
Diligent::ShaderResourceCacheD3D11::CachedResource::Set
__forceinline void Set(RefCntAutoPtr< BufferViewD3D11Impl > pBufView)
Definition: ShaderResourceCacheD3D11.hpp:144
Diligent::ShaderResourceCacheD3D11::GetCBCount
__forceinline Uint32 GetCBCount(Uint32 ShaderInd) const
Definition: ShaderResourceCacheD3D11.hpp:254
Diligent::ShaderResourceCacheD3D11::CopyResource
bool CopyResource(const ShaderResourceCacheD3D11 &SrcCache, const D3D11ResourceBindPoints &BindPoints)
Definition: ShaderResourceCacheD3D11.hpp:210
BufferD3D11Impl.hpp
Diligent::ShaderResourceCacheD3D11::GetSRVCount
__forceinline Uint32 GetSRVCount(Uint32 ShaderInd) const
Definition: ShaderResourceCacheD3D11.hpp:255
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Diligent::ShaderResourceCacheD3D11::CachedResource::CachedResource
CachedResource() noexcept
Definition: ShaderResourceCacheD3D11.hpp:125
Diligent::ShaderResourceCacheD3D11::CachedResource::Set
__forceinline void Set(RefCntAutoPtr< TextureViewD3D11Impl > pTexView)
Definition: ShaderResourceCacheD3D11.hpp:135