git.s-ol.nu ~forks/DiligentCore / d7dc666
Refactored ShaderResourceCacheD3D11 assiduous 6 months ago
6 changed file(s) with 271 addition(s) and 437 deletion(s). Raw diff Collapse all Expand all
8686 /// Strong reference to the buffer
8787 RefCntAutoPtr<BufferD3D11Impl> pBuff;
8888
89 explicit operator bool() const
90 {
91 return pBuff;
92 }
93
8994 private:
9095 friend class ShaderResourceCacheD3D11;
9196 __forceinline void Set(RefCntAutoPtr<BufferD3D11Impl> _pBuff)
99104 {
100105 /// Strong reference to the sampler
101106 RefCntAutoPtr<SamplerD3D11Impl> pSampler;
107
108 explicit operator bool() const
109 {
110 return pSampler;
111 }
102112
103113 private:
104114 friend class ShaderResourceCacheD3D11;
127137
128138 CachedResource() noexcept {}
129139
140 explicit operator bool() const
141 {
142 VERIFY_EXPR((pView && pd3d11Resource != nullptr) || (!pView && pd3d11Resource == nullptr));
143 VERIFY_EXPR(pTexture == nullptr || pBuffer == nullptr);
144 VERIFY_EXPR((pView && (pTexture != nullptr || pBuffer != nullptr)) || (!pView && (pTexture == nullptr && pBuffer == nullptr)));
145 return pView;
146 }
147
130148 private:
131149 friend class ShaderResourceCacheD3D11;
132150 __forceinline void Set(RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
148166 }
149167 };
150168
169 template <typename D3D11ResourceType>
170 struct CachedResourceTraits;
171
151172 static constexpr int NumShaderTypes = BindPointsD3D11::NumShaderTypes;
152173 using TBindingsPerStage = std::array<std::array<Uint8, NumShaderTypes>, D3D11_RESOURCE_RANGE_COUNT>;
153174
158179 __forceinline void SetCB(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl)
159180 {
160181 auto* pd3d11Buff = pBuffD3D11Impl ? pBuffD3D11Impl->BufferD3D11Impl::GetD3D11Buffer() : nullptr;
161 SetD3D11ResourceInternal<CachedCB>(BindPoints, &ShaderResourceCacheD3D11::GetCBCount, &ShaderResourceCacheD3D11::GetCBArrays, std::move(pBuffD3D11Impl), pd3d11Buff);
182 SetD3D11ResourceInternal<CachedCB>(BindPoints, std::move(pBuffD3D11Impl), pd3d11Buff);
162183 }
163184
164185 __forceinline void SetTexSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
165186 {
166187 auto* pd3d11SRV = pTexView ? static_cast<ID3D11ShaderResourceView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
167 SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pTexView), pd3d11SRV);
188 SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pTexView), pd3d11SRV);
168189 }
169190
170191 __forceinline void SetBufSRV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
171192 {
172193 auto* pd3d11SRV = pBuffView ? static_cast<ID3D11ShaderResourceView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
173 SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetSRVCount, &ShaderResourceCacheD3D11::GetSRVArrays, std::move(pBuffView), pd3d11SRV);
194 SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pBuffView), pd3d11SRV);
174195 }
175196
176197 __forceinline void SetTexUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<TextureViewD3D11Impl> pTexView)
177198 {
178199 auto* pd3d11UAV = pTexView ? static_cast<ID3D11UnorderedAccessView*>(pTexView->TextureViewD3D11Impl::GetD3D11View()) : nullptr;
179 SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pTexView), pd3d11UAV);
200 SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pTexView), pd3d11UAV);
180201 }
181202
182203 __forceinline void SetBufUAV(BindPointsD3D11 BindPoints, RefCntAutoPtr<BufferViewD3D11Impl> pBuffView)
183204 {
184205 auto* pd3d11UAV = pBuffView ? static_cast<ID3D11UnorderedAccessView*>(pBuffView->BufferViewD3D11Impl::GetD3D11View()) : nullptr;
185 SetD3D11ResourceInternal<CachedResource>(BindPoints, &ShaderResourceCacheD3D11::GetUAVCount, &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV);
206 SetD3D11ResourceInternal<CachedResource>(BindPoints, std::move(pBuffView), pd3d11UAV);
186207 }
187208
188209 __forceinline void SetSampler(BindPointsD3D11 BindPoints, SamplerD3D11Impl* pSampler)
189210 {
190211 auto* pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr;
191 SetD3D11ResourceInternal<CachedSampler>(BindPoints, &ShaderResourceCacheD3D11::GetSamplerCount, &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler);
192 }
193
194
195 __forceinline CachedCB const& GetCB(BindPointsD3D11 BindPoints) const
212 SetD3D11ResourceInternal<CachedSampler>(BindPoints, pSampler, pd3d11Sampler);
213 }
214
215
216 template <typename D3D11ResourceType>
217 __forceinline const typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType& GetResource(BindPointsD3D11 BindPoints) const
196218 {
197219 const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
198 VERIFY(BindPoints[ShaderInd] < GetCBCount(ShaderInd), "CB slot is out of range");
199 ShaderResourceCacheD3D11::CachedCB const* CBs;
200 ID3D11Buffer* const* pd3d11CBs;
201 GetConstCBArrays(ShaderInd, CBs, pd3d11CBs);
202 return CBs[BindPoints[ShaderInd]];
203 }
204
205 __forceinline CachedResource const& GetSRV(BindPointsD3D11 BindPoints) const
206 {
207 const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
208 VERIFY(BindPoints[ShaderInd] < GetSRVCount(ShaderInd), "SRV slot is out of range");
209 ShaderResourceCacheD3D11::CachedResource const* SRVResources;
210 ID3D11ShaderResourceView* const* pd3d11SRVs;
211 GetConstSRVArrays(ShaderInd, SRVResources, pd3d11SRVs);
212 return SRVResources[BindPoints[ShaderInd]];
213 }
214
215 __forceinline CachedResource const& GetUAV(BindPointsD3D11 BindPoints) const
216 {
217 const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
218 VERIFY(BindPoints[ShaderInd] < GetUAVCount(ShaderInd), "UAV slot is out of range");
219 ShaderResourceCacheD3D11::CachedResource const* UAVResources;
220 ID3D11UnorderedAccessView* const* pd3d11UAVs;
221 GetConstUAVArrays(ShaderInd, UAVResources, pd3d11UAVs);
222 return UAVResources[BindPoints[ShaderInd]];
223 }
224
225 __forceinline CachedSampler const& GetSampler(BindPointsD3D11 BindPoints) const
226 {
227 const Uint32 ShaderInd = PlatformMisc::GetLSB(BindPoints.GetActiveBits());
228 VERIFY(BindPoints[ShaderInd] < GetSamplerCount(ShaderInd), "Sampler slot is out of range");
229 ShaderResourceCacheD3D11::CachedSampler const* Samplers;
230 ID3D11SamplerState* const* pd3d11Samplers;
231 GetConstSamplerArrays(ShaderInd, Samplers, pd3d11Samplers);
232 return Samplers[BindPoints[ShaderInd]];
233 }
234
235
236 __forceinline bool CopyCB(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
220 VERIFY(BindPoints[ShaderInd] < GetResourceCount<D3D11ResourceType>(ShaderInd), "Resource slot is out of range");
221 CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources;
222 D3D11ResourceType* const* pd3d11Resources;
223 GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources);
224 return CachedResources[BindPoints[ShaderInd]];
225 }
226
227 template <typename D3D11ResourceType>
228 bool CopyResource(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
237229 {
238230 bool IsBound = true;
239231 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
241233 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
242234 ActiveBits &= ~(1u << ShaderInd);
243235
244 CachedCB const* pSrcCBs;
245 ID3D11Buffer* const* pSrcd3d11CBs;
246 SrcCache.GetConstCBArrays(ShaderInd, pSrcCBs, pSrcd3d11CBs);
247
248 CachedCB* pCBs;
249 ID3D11Buffer** pd3d11CBs;
250 GetCBArrays(ShaderInd, pCBs, pd3d11CBs);
236 CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* pSrcCachedResources;
237 D3D11ResourceType* const* pd3d11SrcResources;
238 SrcCache.GetConstResourceArrays(ShaderInd, pSrcCachedResources, pd3d11SrcResources);
239
240 CachedResourceTraits<D3D11ResourceType>::CachedResourceType* pDstCachedResources;
241 D3D11ResourceType** pd3d11DstResources;
242 GetResourceArrays(ShaderInd, pDstCachedResources, pd3d11DstResources);
251243
252244 const Uint32 CacheOffset = BindPoints[ShaderInd];
253 VERIFY(CacheOffset < GetCBCount(ShaderInd), "Index is out of range");
254 if (pSrcCBs[CacheOffset].pBuff == nullptr)
245 VERIFY(CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd), "Index is out of range");
246 if (!pSrcCachedResources[CacheOffset])
255247 IsBound = false;
256248
257 pCBs[CacheOffset] = pSrcCBs[CacheOffset];
258 pd3d11CBs[CacheOffset] = pSrcd3d11CBs[CacheOffset];
249 pDstCachedResources[CacheOffset] = pSrcCachedResources[CacheOffset];
250 pd3d11DstResources[CacheOffset] = pd3d11SrcResources[CacheOffset];
259251 }
260252 return IsBound;
261253 }
262254
263 __forceinline bool CopySRV(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
264 {
265 bool IsBound = true;
266 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
267 {
268 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
269 ActiveBits &= ~(1u << ShaderInd);
270
271 CachedResource const* pSrcSRVResources;
272 ID3D11ShaderResourceView* const* pSrcd3d11SRVs;
273 SrcCache.GetConstSRVArrays(ShaderInd, pSrcSRVResources, pSrcd3d11SRVs);
274
275 CachedResource* pSRVResources;
276 ID3D11ShaderResourceView** pd3d11SRVs;
277 GetSRVArrays(ShaderInd, pSRVResources, pd3d11SRVs);
278
279 const Uint32 CacheOffset = BindPoints[ShaderInd];
280 VERIFY(CacheOffset < GetSRVCount(ShaderInd), "Index is out of range");
281 if (pSrcSRVResources[CacheOffset].pBuffer == nullptr && pSrcSRVResources[CacheOffset].pTexture == nullptr)
282 IsBound = false;
283
284 pSRVResources[CacheOffset] = pSrcSRVResources[CacheOffset];
285 pd3d11SRVs[CacheOffset] = pSrcd3d11SRVs[CacheOffset];
286 }
287 return IsBound;
288 }
289
290 __forceinline bool CopyUAV(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
291 {
292 bool IsBound = true;
293 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
294 {
295 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
296 ActiveBits &= ~(1u << ShaderInd);
297
298 CachedResource const* pSrcUAVResources;
299 ID3D11UnorderedAccessView* const* pSrcd3d11UAVs;
300 SrcCache.GetConstUAVArrays(ShaderInd, pSrcUAVResources, pSrcd3d11UAVs);
301
302 CachedResource* pUAVResources;
303 ID3D11UnorderedAccessView** pd3d11UAVs;
304 GetUAVArrays(ShaderInd, pUAVResources, pd3d11UAVs);
305
306 const Uint32 CacheOffset = BindPoints[ShaderInd];
307 VERIFY(CacheOffset < GetUAVCount(ShaderInd), "Index is out of range");
308 if (pSrcUAVResources[CacheOffset].pBuffer == nullptr && pSrcUAVResources[CacheOffset].pTexture == nullptr)
309 IsBound = false;
310
311 pUAVResources[CacheOffset] = pSrcUAVResources[CacheOffset];
312 pd3d11UAVs[CacheOffset] = pSrcd3d11UAVs[CacheOffset];
313 }
314 return IsBound;
315 }
316
317 __forceinline bool CopySampler(const ShaderResourceCacheD3D11& SrcCache, BindPointsD3D11 BindPoints)
318 {
319 bool IsBound = true;
320 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
321 {
322 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
323 ActiveBits &= ~(1u << ShaderInd);
324
325 CachedSampler const* pSrcSamplers;
326 ID3D11SamplerState* const* pSrcd3d11Samplers;
327 SrcCache.GetConstSamplerArrays(ShaderInd, pSrcSamplers, pSrcd3d11Samplers);
328
329 CachedSampler* pSamplers;
330 ID3D11SamplerState** pd3d11Samplers;
331 GetSamplerArrays(ShaderInd, pSamplers, pd3d11Samplers);
332
333 const Uint32 CacheOffset = BindPoints[ShaderInd];
334 VERIFY(CacheOffset < GetSamplerCount(ShaderInd), "Index is out of range");
335 if (pSrcSamplers[CacheOffset].pSampler == nullptr)
336 IsBound = false;
337
338 pSamplers[CacheOffset] = pSrcSamplers[CacheOffset];
339 pd3d11Samplers[CacheOffset] = pSrcd3d11Samplers[CacheOffset];
340 }
341 return IsBound;
342 }
343
344
345 __forceinline bool IsCBBound(BindPointsD3D11 BindPoints) const
255 template <typename D3D11ResourceType>
256 __forceinline bool IsResourceBound(BindPointsD3D11 BindPoints) const
346257 {
347258 bool IsBound = true;
348259 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
351262 ActiveBits &= ~(1u << ShaderInd);
352263 const Uint32 CacheOffset = BindPoints[ShaderInd];
353264
354 CachedCB const* CBs;
355 ID3D11Buffer* const* d3d11CBs;
356 GetConstCBArrays(ShaderInd, CBs, d3d11CBs);
357 if (CacheOffset < GetCBCount(ShaderInd) && d3d11CBs[CacheOffset] != nullptr)
265 CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources;
266 D3D11ResourceType* const* pd3d11Resources;
267 GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources);
268 if (CacheOffset < GetResourceCount<D3D11ResourceType>(ShaderInd) && CachedResources[CacheOffset])
358269 {
359 VERIFY(CBs[CacheOffset].pBuff != nullptr, "No relevant buffer resource");
360 continue;
361 }
362 IsBound = false;
363 }
364 return IsBound;
365 }
366
367 __forceinline bool IsSRVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const
368 {
369 bool IsBound = true;
370 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
371 {
372 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
373 ActiveBits &= ~(1u << ShaderInd);
374 const Uint32 CacheOffset = BindPoints[ShaderInd];
375
376 CachedResource const* SRVResources;
377 ID3D11ShaderResourceView* const* d3d11SRVs;
378 GetConstSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
379 if (CacheOffset < GetSRVCount(ShaderInd) && d3d11SRVs[CacheOffset] != nullptr)
380 {
381 VERIFY((dbgIsTextureView && SRVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && SRVResources[CacheOffset].pBuffer != nullptr),
382 "No relevant resource");
383 continue;
384 }
385 IsBound = false;
386 }
387 return IsBound;
388 }
389
390 __forceinline bool IsUAVBound(BindPointsD3D11 BindPoints, bool dbgIsTextureView) const
391 {
392 bool IsBound = true;
393 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
394 {
395 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
396 ActiveBits &= ~(1u << ShaderInd);
397 const Uint32 CacheOffset = BindPoints[ShaderInd];
398
399 CachedResource const* UAVResources;
400 ID3D11UnorderedAccessView* const* d3d11UAVs;
401 GetConstUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
402 if (CacheOffset < GetUAVCount(ShaderInd) && d3d11UAVs[CacheOffset] != nullptr)
403 {
404 VERIFY((dbgIsTextureView && UAVResources[CacheOffset].pTexture != nullptr) || (!dbgIsTextureView && UAVResources[CacheOffset].pBuffer != nullptr),
405 "No relevant resource");
406 continue;
407 }
408 IsBound = false;
409 }
410 return IsBound;
411 }
412
413 __forceinline bool IsSamplerBound(BindPointsD3D11 BindPoints) const
414 {
415 bool IsBound = true;
416 for (Uint32 ActiveBits = BindPoints.GetActiveBits(); ActiveBits != 0;)
417 {
418 const Uint32 ShaderInd = PlatformMisc::GetLSB(ActiveBits);
419 ActiveBits &= ~(1u << ShaderInd);
420 const Uint32 CacheOffset = BindPoints[ShaderInd];
421
422 CachedSampler const* Samplers;
423 ID3D11SamplerState* const* d3d11Samplers;
424 GetConstSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
425 if (CacheOffset < GetSamplerCount(ShaderInd) && d3d11Samplers[CacheOffset] != nullptr)
426 {
427 VERIFY(Samplers[CacheOffset].pSampler != nullptr, "No relevant sampler");
428270 continue;
429271 }
430272 IsBound = false;
443285 __forceinline Uint32 GetUAVCount (Uint32 ShaderInd) const { return (m_Offsets[UAVOffset + ShaderInd + 1] - m_Offsets[UAVOffset + ShaderInd]) / (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)); }
444286 // clang-format on
445287
446 __forceinline void GetCBArrays(Uint32 ShaderInd, CachedCB*& CBs, ID3D11Buffer**& pd3d11CBs) const
447 {
448 VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
449 CBs = reinterpret_cast<CachedCB*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]);
450 pd3d11CBs = reinterpret_cast<ID3D11Buffer**>(CBs + GetCBCount(ShaderInd));
451 }
452
453 __forceinline void GetSRVArrays(Uint32 ShaderInd, CachedResource*& SRVResources, ID3D11ShaderResourceView**& d3d11SRVs) const
454 {
455 VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
456 SRVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]);
457 d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView**>(SRVResources + GetSRVCount(ShaderInd));
458 }
459
460 __forceinline void GetSamplerArrays(Uint32 ShaderInd, CachedSampler*& Samplers, ID3D11SamplerState**& pd3d11Samplers) const
461 {
462 VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
463 Samplers = reinterpret_cast<CachedSampler*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]);
464 pd3d11Samplers = reinterpret_cast<ID3D11SamplerState**>(Samplers + GetSamplerCount(ShaderInd));
465 }
466
467 __forceinline void GetUAVArrays(Uint32 ShaderInd, CachedResource*& UAVResources, ID3D11UnorderedAccessView**& pd3d11UAVs) const
468 {
469 VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
470 UAVResources = reinterpret_cast<CachedResource*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]);
471 pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView**>(UAVResources + GetUAVCount(ShaderInd));
472 }
473
474 __forceinline void GetConstCBArrays(Uint32 ShaderInd, CachedCB const*& CBs, ID3D11Buffer* const*& pd3d11CBs) const
475 {
476 VERIFY(alignof(CachedCB) == alignof(ID3D11Buffer*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
477 CBs = reinterpret_cast<CachedCB const*>(m_pResourceData.get() + m_Offsets[CBOffset + ShaderInd]);
478 pd3d11CBs = reinterpret_cast<ID3D11Buffer* const*>(CBs + GetCBCount(ShaderInd));
479 }
480
481 __forceinline void GetConstSRVArrays(Uint32 ShaderInd, CachedResource const*& SRVResources, ID3D11ShaderResourceView* const*& d3d11SRVs) const
482 {
483 VERIFY(alignof(CachedResource) == alignof(ID3D11ShaderResourceView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
484 SRVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[SRVOffset + ShaderInd]);
485 d3d11SRVs = reinterpret_cast<ID3D11ShaderResourceView* const*>(SRVResources + GetSRVCount(ShaderInd));
486 }
487
488 __forceinline void GetConstSamplerArrays(Uint32 ShaderInd, CachedSampler const*& Samplers, ID3D11SamplerState* const*& pd3d11Samplers) const
489 {
490 VERIFY(alignof(CachedSampler) == alignof(ID3D11SamplerState*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
491 Samplers = reinterpret_cast<CachedSampler const*>(m_pResourceData.get() + m_Offsets[SampOffset + ShaderInd]);
492 pd3d11Samplers = reinterpret_cast<ID3D11SamplerState* const*>(Samplers + GetSamplerCount(ShaderInd));
493 }
494
495 __forceinline void GetConstUAVArrays(Uint32 ShaderInd, CachedResource const*& UAVResources, ID3D11UnorderedAccessView* const*& pd3d11UAVs) const
496 {
497 VERIFY(alignof(CachedResource) == alignof(ID3D11UnorderedAccessView*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
498 UAVResources = reinterpret_cast<CachedResource const*>(m_pResourceData.get() + m_Offsets[UAVOffset + ShaderInd]);
499 pd3d11UAVs = reinterpret_cast<ID3D11UnorderedAccessView* const*>(UAVResources + GetUAVCount(ShaderInd));
288 template <typename D3D11ResourceType>
289 __forceinline Uint32 GetResourceCount(Uint32 ShaderInd) const;
290
291 template <typename D3D11ResourceType>
292 __forceinline void GetResourceArrays(
293 Uint32 ShaderInd,
294 typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType*& pResources,
295 D3D11ResourceType**& pd3d11Resources) const
296 {
297 static_assert(alignof(CachedResourceTraits<D3D11ResourceType>::CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
298
299 pResources = reinterpret_cast<CachedResourceTraits<D3D11ResourceType>::CachedResourceType*>(m_pResourceData.get() + GetResourceDataOffset<D3D11ResourceType>(ShaderInd));
300 pd3d11Resources = reinterpret_cast<D3D11ResourceType**>(pResources + GetResourceCount<D3D11ResourceType>(ShaderInd));
301 }
302
303
304 template <typename D3D11ResourceType>
305 __forceinline void GetConstResourceArrays(
306 Uint32 ShaderInd,
307 typename CachedResourceTraits<D3D11ResourceType>::CachedResourceType const*& pResources,
308 D3D11ResourceType* const*& pd3d11Resources) const
309 {
310 static_assert(alignof(CachedResourceTraits<D3D11ResourceType>::CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");
311
312 pResources = reinterpret_cast<CachedResourceTraits<D3D11ResourceType>::CachedResourceType const*>(m_pResourceData.get() + GetResourceDataOffset<D3D11ResourceType>(ShaderInd));
313 pd3d11Resources = reinterpret_cast<D3D11ResourceType* const*>(pResources + GetResourceCount<D3D11ResourceType>(ShaderInd));
500314 }
501315
502316 bool IsInitialized() const { return m_IsInitialized; }
522336 }
523337 };
524338
525 MinMaxSlot BindCBs(Uint32 ShaderInd,
526 ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT],
527 Uint8& Binding) const;
528
529 MinMaxSlot BindSRVs(Uint32 ShaderInd,
530 ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
531 ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
532 Uint8& Binding) const;
533
534 MinMaxSlot BindSamplers(Uint32 ShaderInd,
535 ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT],
536 Uint8& Binding) const;
537
538 MinMaxSlot BindUAVs(Uint32 ShaderInd,
539 ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT],
540 ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT],
541 Uint8& Binding) const;
339 template <typename D3D11ResourceType>
340 MinMaxSlot BindResources(Uint32 ShaderInd,
341 D3D11ResourceType* CommittedD3D11Resources[],
342 Uint8& Binding) const;
343
344 template <typename D3D11ResourceViewType>
345 MinMaxSlot BindResourceViews(Uint32 ShaderInd,
346 D3D11ResourceViewType* CommittedD3D11Views[],
347 ID3D11Resource* CommittedD3D11Resources[],
348 Uint8& Binding) const;
542349
543350 private:
544 template <typename TCachedResourceType, typename TGetResourceCount, typename TGetResourceArraysFunc, typename TSrcResourceType, typename TD3D11ResourceType>
545 __forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TGetResourceCount GetCount, TGetResourceArraysFunc GetArrays, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource)
351 template <typename D3D11ResourceTpye>
352 __forceinline Uint32 GetResourceDataOffset(Uint32 ShaderInd) const;
353
354 template <typename TCachedResourceType, typename TSrcResourceType, typename TD3D11ResourceType>
355 __forceinline void SetD3D11ResourceInternal(BindPointsD3D11 BindPoints, TSrcResourceType pResource, TD3D11ResourceType* pd3d11Resource)
546356 {
547357 VERIFY(pResource != nullptr && pd3d11Resource != nullptr || pResource == nullptr && pd3d11Resource == nullptr,
548358 "Resource and D3D11 resource must be set/unset atomically");
552362 ActiveBits &= ~(1u << ShaderInd);
553363
554364 const Uint32 CacheOffset = BindPoints[ShaderInd];
555 const Uint32 ResCount = (this->*GetCount)(ShaderInd);
365 const Uint32 ResCount = GetResourceCount<TD3D11ResourceType>(ShaderInd);
556366 VERIFY(CacheOffset < ResCount, "Index is out of range");
557367
558368 TCachedResourceType* Resources;
559369 TD3D11ResourceType** d3d11ResArr;
560 (this->*GetArrays)(ShaderInd, Resources, d3d11ResArr);
370 GetResourceArrays(ShaderInd, Resources, d3d11ResArr);
561371 Resources[CacheOffset].Set(pResource);
562372 d3d11ResArr[CacheOffset] = pd3d11Resource;
563373 }
601411
602412 static constexpr size_t ResCacheSize = sizeof(ShaderResourceCacheD3D11);
603413
414
415 template <>
416 struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11Buffer>
417 {
418 using CachedResourceType = CachedCB;
419 };
420
421 template <>
422 struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11SamplerState>
423 {
424 using CachedResourceType = CachedSampler;
425 };
426
427 template <>
428 struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11ShaderResourceView>
429 {
430 using CachedResourceType = CachedResource;
431 };
432
433 template <>
434 struct ShaderResourceCacheD3D11::CachedResourceTraits<ID3D11UnorderedAccessView>
435 {
436 using CachedResourceType = CachedResource;
437 };
438
439
440 template <>
441 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11Buffer>(Uint32 ShaderInd) const
442 {
443 return GetCBCount(ShaderInd);
444 }
445
446 template <>
447 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11ShaderResourceView>(Uint32 ShaderInd) const
448 {
449 return GetSRVCount(ShaderInd);
450 }
451
452 template <>
453 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const
454 {
455 return GetUAVCount(ShaderInd);
456 }
457
458 template <>
459 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceCount<ID3D11SamplerState>(Uint32 ShaderInd) const
460 {
461 return GetSamplerCount(ShaderInd);
462 }
463
464
465 template <>
466 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11Buffer>(Uint32 ShaderInd) const
467 {
468 return m_Offsets[CBOffset + ShaderInd];
469 }
470
471 template <>
472 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11ShaderResourceView>(Uint32 ShaderInd) const
473 {
474 return m_Offsets[SRVOffset + ShaderInd];
475 }
476
477 template <>
478 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11SamplerState>(Uint32 ShaderInd) const
479 {
480 return m_Offsets[SampOffset + ShaderInd];
481 }
482
483 template <>
484 __forceinline Uint32 ShaderResourceCacheD3D11::GetResourceDataOffset<ID3D11UnorderedAccessView>(Uint32 ShaderInd) const
485 {
486 return m_Offsets[UAVOffset + ShaderInd];
487 }
488
604489 // Instantiate templates
605490 template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Transition>(DeviceContextD3D11Impl& Ctx);
606491 template void ShaderResourceCacheD3D11::TransitionResourceStates<ShaderResourceCacheD3D11::StateTransitionMode::Verify>(DeviceContextD3D11Impl& Ctx);
607492
493
494 template <typename D3D11ResourceType>
495 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResources(
496 Uint32 ShaderInd,
497 D3D11ResourceType* CommittedD3D11Resources[],
498 Uint8& Binding) const
499 {
500 CachedResourceTraits<D3D11ResourceType>::CachedResourceType const* CachedResources;
501 D3D11ResourceType* const* pd3d11Resources;
502 GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Resources);
503
504 MinMaxSlot Slots;
505
506 const auto ResCount = GetResourceCount<D3D11ResourceType>(ShaderInd);
507 for (Uint32 res = 0; res < ResCount; ++res)
508 {
509 const Uint32 Slot = Binding++;
510 if (CommittedD3D11Resources[Slot] != pd3d11Resources[res])
511 Slots.Add(Slot);
512
513 VERIFY_EXPR(pd3d11Resources[res] != nullptr);
514 CommittedD3D11Resources[Slot] = pd3d11Resources[res];
515 }
516
517 return Slots;
518 }
519
520 template <typename D3D11ResourceViewType>
521 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindResourceViews(
522 Uint32 ShaderInd,
523 D3D11ResourceViewType* CommittedD3D11Views[],
524 ID3D11Resource* CommittedD3D11Resources[],
525 Uint8& Binding) const
526 {
527 CachedResourceTraits<D3D11ResourceViewType>::CachedResourceType const* CachedResources;
528 D3D11ResourceViewType* const* pd3d11Views;
529 GetConstResourceArrays(ShaderInd, CachedResources, pd3d11Views);
530
531 MinMaxSlot Slots;
532
533 const auto ResCount = GetResourceCount<D3D11ResourceViewType>(ShaderInd);
534 for (Uint32 res = 0; res < ResCount; ++res)
535 {
536 const Uint32 Slot = Binding++;
537 if (CommittedD3D11Views[Slot] != pd3d11Views[res])
538 Slots.Add(Slot);
539
540 VERIFY_EXPR(pd3d11Views[res] != nullptr);
541 CommittedD3D11Resources[Slot] = CachedResources[res].pd3d11Resource;
542 CommittedD3D11Views[Slot] = pd3d11Views[res];
543 }
544
545 return Slots;
546 }
547
608548 } // namespace Diligent
132132 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
133133 {
134134 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
135 return m_ParentManager.m_ResourceCache.IsCBBound(GetAttribs().BindPoints + ArrayIndex);
135 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11Buffer>(GetAttribs().BindPoints + ArrayIndex);
136136 }
137137 };
138138
148148 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
149149 {
150150 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
151 return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, true);
151 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex);
152152 }
153153 };
154154
164164 __forceinline virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
165165 {
166166 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
167 return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, true);
167 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex);
168168 }
169169 };
170170
180180 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
181181 {
182182 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
183 return m_ParentManager.m_ResourceCache.IsUAVBound(GetAttribs().BindPoints + ArrayIndex, false);
183 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(GetAttribs().BindPoints + ArrayIndex);
184184 }
185185 };
186186
196196 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
197197 {
198198 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
199 return m_ParentManager.m_ResourceCache.IsSRVBound(GetAttribs().BindPoints + ArrayIndex, false);
199 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(GetAttribs().BindPoints + ArrayIndex);
200200 }
201201 };
202202
212212 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
213213 {
214214 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
215 return m_ParentManager.m_ResourceCache.IsSamplerBound(GetAttribs().BindPoints + ArrayIndex);
215 return m_ParentManager.m_ResourceCache.IsResourceBound<ID3D11SamplerState>(GetAttribs().BindPoints + ArrayIndex);
216216 }
217217 };
218218
285285 const auto ShaderInd = ShaderIndices[i];
286286 auto* CommittedD3D11CBs = m_CommittedRes.D3D11CBs[ShaderInd];
287287 Uint8 Binding = BaseBindings[Range][ShaderInd];
288 auto Slots = ResourceCache.BindCBs(ShaderInd, CommittedD3D11CBs, Binding);
288 auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11CBs, Binding);
289289
290290 if (Slots)
291291 {
309309 auto* CommittedD3D11SRVs = m_CommittedRes.D3D11SRVs[ShaderInd];
310310 auto* CommittedD3D11SRVRes = m_CommittedRes.D3D11SRVResources[ShaderInd];
311311 Uint8 Binding = BaseBindings[Range][ShaderInd];
312 auto Slots = ResourceCache.BindSRVs(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding);
312 auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11SRVs, CommittedD3D11SRVRes, Binding);
313313
314314 if (Slots)
315315 {
332332 const auto ShaderInd = ShaderIndices[i];
333333 auto* CommittedD3D11Samplers = m_CommittedRes.D3D11Samplers[ShaderInd];
334334 Uint8 Binding = BaseBindings[Range][ShaderInd];
335 auto Slots = ResourceCache.BindSamplers(ShaderInd, CommittedD3D11Samplers, Binding);
335 auto Slots = ResourceCache.BindResources(ShaderInd, CommittedD3D11Samplers, Binding);
336336
337337 if (Slots)
338338 {
357357 auto* CommittedD3D11UAVs = m_CommittedRes.D3D11UAVs[ShaderInd];
358358 auto* CommittedD3D11UAVRes = m_CommittedRes.D3D11UAVResources[ShaderInd];
359359 Uint8 Binding = BaseBindings[Range][ShaderInd];
360 auto Slots = ResourceCache.BindUAVs(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding);
360 auto Slots = ResourceCache.BindResourceViews(ShaderInd, CommittedD3D11UAVs, CommittedD3D11UAVRes, Binding);
361361
362362 if (Slots)
363363 {
326326 case D3D11_RESOURCE_RANGE_CBV:
327327 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
328328 {
329 if (!DstResourceCache.CopyCB(SrcResourceCache, ResAttr.BindPoints + ArrInd))
329 if (!DstResourceCache.CopyResource<ID3D11Buffer>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
330330 LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
331331 }
332332 break;
333333 case D3D11_RESOURCE_RANGE_SRV:
334334 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
335335 {
336 if (!DstResourceCache.CopySRV(SrcResourceCache, ResAttr.BindPoints + ArrInd))
336 if (!DstResourceCache.CopyResource<ID3D11ShaderResourceView>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
337337 LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
338338 }
339339 break;
343343 {
344344 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
345345 {
346 if (!DstResourceCache.CopySampler(SrcResourceCache, ResAttr.BindPoints + ArrInd))
346 if (!DstResourceCache.CopyResource<ID3D11SamplerState>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
347347 LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
348348 }
349349 }
351351 case D3D11_RESOURCE_RANGE_UAV:
352352 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
353353 {
354 if (!DstResourceCache.CopyUAV(SrcResourceCache, ResAttr.BindPoints + ArrInd))
354 if (!DstResourceCache.CopyResource<ID3D11UnorderedAccessView>(SrcResourceCache, ResAttr.BindPoints + ArrInd))
355355 LOG_ERROR_MESSAGE("No resource is assigned to static shader variable '", GetShaderResourcePrintName(ResDesc, ArrInd), "' in pipeline resource signature '", m_Desc.Name, "'.");
356356 }
357357 break;
466466 case D3D11_RESOURCE_RANGE_CBV:
467467 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
468468 {
469 if (!ResourceCache.IsCBBound(ResAttr.BindPoints + ArrInd))
469 if (!ResourceCache.IsResourceBound<ID3D11Buffer>(ResAttr.BindPoints + ArrInd))
470470 {
471471 LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
472472 "' in shader '", ShaderName, "' of PSO '", PSOName, "'");
478478 case D3D11_RESOURCE_RANGE_SAMPLER:
479479 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
480480 {
481 if (!ResourceCache.IsSamplerBound(ResAttr.BindPoints + ArrInd))
481 if (!ResourceCache.IsResourceBound<ID3D11SamplerState>(ResAttr.BindPoints + ArrInd))
482482 {
483483 LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
484484 "' in shader '", ShaderName, "' of PSO '", PSOName, "'");
490490 case D3D11_RESOURCE_RANGE_SRV:
491491 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
492492 {
493 const bool IsTexView = (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT);
494 if (!ResourceCache.IsSRVBound(ResAttr.BindPoints + ArrInd, IsTexView))
493 if (!ResourceCache.IsResourceBound<ID3D11ShaderResourceView>(ResAttr.BindPoints + ArrInd))
495494 {
496495 LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
497496 "' in shader '", ShaderName, "' of PSO '", PSOName, "'");
511510 case D3D11_RESOURCE_RANGE_UAV:
512511 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
513512 {
514 const bool IsTexView = (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV || ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV);
515 if (!ResourceCache.IsUAVBound(ResAttr.BindPoints + ArrInd, IsTexView))
513 if (!ResourceCache.IsResourceBound<ID3D11UnorderedAccessView>(ResAttr.BindPoints + ArrInd))
516514 {
517515 LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(ResDesc, ArrInd),
518516 "' in shader '", ShaderName, "' of PSO '", PSOName, "'");
113113 {
114114 CachedCB* CBs = nullptr;
115115 ID3D11Buffer** d3d11CBs = nullptr;
116 GetCBArrays(ShaderInd, CBs, d3d11CBs);
116 GetResourceArrays(ShaderInd, CBs, d3d11CBs);
117117 for (Uint32 cb = 0; cb < CBCount; ++cb)
118118 new (CBs + cb) CachedCB{};
119119 }
123123 {
124124 CachedResource* SRVResources = nullptr;
125125 ID3D11ShaderResourceView** d3d11SRVs = nullptr;
126 GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
126 GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
127127 for (Uint32 srv = 0; srv < SRVCount; ++srv)
128128 new (SRVResources + srv) CachedResource{};
129129 }
133133 {
134134 CachedSampler* Samplers = nullptr;
135135 ID3D11SamplerState** d3d11Samplers = nullptr;
136 GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
136 GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
137137 for (Uint32 sam = 0; sam < SamplerCount; ++sam)
138138 new (Samplers + sam) CachedSampler{};
139139 }
143143 {
144144 CachedResource* UAVResources = nullptr;
145145 ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
146 GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
146 GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
147147 for (Uint32 uav = 0; uav < UAVCount; ++uav)
148148 new (UAVResources + uav) CachedResource{};
149149 }
164164 {
165165 CachedCB* CBs = nullptr;
166166 ID3D11Buffer** d3d11CBs = nullptr;
167 GetCBArrays(ShaderInd, CBs, d3d11CBs);
167 GetResourceArrays(ShaderInd, CBs, d3d11CBs);
168168 for (size_t cb = 0; cb < CBCount; ++cb)
169169 CBs[cb].~CachedCB();
170170 }
174174 {
175175 CachedResource* SRVResources = nullptr;
176176 ID3D11ShaderResourceView** d3d11SRVs = nullptr;
177 GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
177 GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
178178 for (size_t srv = 0; srv < SRVCount; ++srv)
179179 SRVResources[srv].~CachedResource();
180180 }
184184 {
185185 CachedSampler* Samplers = nullptr;
186186 ID3D11SamplerState** d3d11Samplers = nullptr;
187 GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
187 GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
188188 for (size_t sam = 0; sam < SamplerCount; ++sam)
189189 Samplers[sam].~CachedSampler();
190190 }
194194 {
195195 CachedResource* UAVResources = nullptr;
196196 ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
197 GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
197 GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
198198 for (size_t uav = 0; uav < UAVCount; ++uav)
199199 UAVResources[uav].~CachedResource();
200200 }
270270 CachedResource* UAVResources = nullptr;
271271 ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
272272
273 GetCBArrays(ShaderInd, CBs, d3d11CBs);
274 GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
275 GetSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
276 GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
273 GetResourceArrays(ShaderInd, CBs, d3d11CBs);
274 GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
275 GetResourceArrays(ShaderInd, Samplers, d3d11Samplers);
276 GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
277277
278278 auto CBCount = GetCBCount(ShaderInd);
279279 for (size_t cb = 0; cb < CBCount; ++cb)
340340
341341 CachedCB* CBs;
342342 ID3D11Buffer** d3d11CBs;
343 GetCBArrays(ShaderInd, CBs, d3d11CBs);
343 GetResourceArrays(ShaderInd, CBs, d3d11CBs);
344344
345345 for (Uint32 i = 0; i < CBCount; ++i)
346346 {
375375
376376 CachedResource* SRVResources;
377377 ID3D11ShaderResourceView** d3d11SRVs;
378 GetSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
378 GetResourceArrays(ShaderInd, SRVResources, d3d11SRVs);
379379
380380 for (Uint32 i = 0; i < SRVCount; ++i)
381381 {
432432
433433 CachedResource* UAVResources;
434434 ID3D11UnorderedAccessView** d3d11UAVs;
435 GetUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
435 GetResourceArrays(ShaderInd, UAVResources, d3d11UAVs);
436436
437437 for (Uint32 i = 0; i < UAVCount; ++i)
438438 {
473473 }
474474 }
475475
476 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindCBs(
477 Uint32 ShaderInd,
478 ID3D11Buffer* CommittedD3D11CBs[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT],
479 Uint8& Binding) const
480 {
481 CachedCB const* CBs;
482 ID3D11Buffer* const* d3d11CBs;
483 GetConstCBArrays(ShaderInd, CBs, d3d11CBs);
484
485 MinMaxSlot Slots;
486
487 const auto CBCount = GetCBCount(ShaderInd);
488 for (Uint32 cb = 0; cb < CBCount; ++cb)
489 {
490 const Uint32 Slot = Binding++;
491 if (CommittedD3D11CBs[Slot] != d3d11CBs[cb])
492 Slots.Add(Slot);
493
494 VERIFY_EXPR(d3d11CBs[cb] != nullptr);
495 CommittedD3D11CBs[Slot] = d3d11CBs[cb];
496 }
497
498 return Slots;
499 }
500
501 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindSRVs(
502 Uint32 ShaderInd,
503 ID3D11ShaderResourceView* CommittedD3D11SRVs[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
504 ID3D11Resource* CommittedD3D11SRVResources[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT],
505 Uint8& Binding) const
506 {
507 CachedResource const* SRVResources;
508 ID3D11ShaderResourceView* const* d3d11SRVs;
509 GetConstSRVArrays(ShaderInd, SRVResources, d3d11SRVs);
510
511 MinMaxSlot Slots;
512
513 const auto SRVCount = GetSRVCount(ShaderInd);
514 for (Uint32 srv = 0; srv < SRVCount; ++srv)
515 {
516 const Uint32 Slot = Binding++;
517 if (CommittedD3D11SRVs[Slot] != d3d11SRVs[srv])
518 Slots.Add(Slot);
519
520 VERIFY_EXPR(d3d11SRVs[srv] != nullptr);
521 CommittedD3D11SRVResources[Slot] = SRVResources[srv].pd3d11Resource;
522 CommittedD3D11SRVs[Slot] = d3d11SRVs[srv];
523 }
524
525 return Slots;
526 }
527
528 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindSamplers(
529 Uint32 ShaderInd,
530 ID3D11SamplerState* CommittedD3D11Samplers[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT],
531 Uint8& Binding) const
532 {
533 CachedSampler const* Samplers;
534 ID3D11SamplerState* const* d3d11Samplers;
535 GetConstSamplerArrays(ShaderInd, Samplers, d3d11Samplers);
536
537 MinMaxSlot Slots;
538
539 const auto SamplerCount = GetSamplerCount(ShaderInd);
540 for (Uint32 sam = 0; sam < SamplerCount; ++sam)
541 {
542 const Uint32 Slot = Binding++;
543 if (CommittedD3D11Samplers[Slot] != d3d11Samplers[sam])
544 Slots.Add(Slot);
545
546 VERIFY_EXPR(d3d11Samplers[sam] != nullptr);
547 CommittedD3D11Samplers[Slot] = d3d11Samplers[sam];
548 }
549
550 return Slots;
551 }
552
553 ShaderResourceCacheD3D11::MinMaxSlot ShaderResourceCacheD3D11::BindUAVs(
554 Uint32 ShaderInd,
555 ID3D11UnorderedAccessView* CommittedD3D11UAVs[D3D11_PS_CS_UAV_REGISTER_COUNT],
556 ID3D11Resource* CommittedD3D11UAVResources[D3D11_PS_CS_UAV_REGISTER_COUNT],
557 Uint8& Binding) const
558 {
559 CachedResource const* UAVResources;
560 ID3D11UnorderedAccessView* const* d3d11UAVs;
561 GetConstUAVArrays(ShaderInd, UAVResources, d3d11UAVs);
562
563 MinMaxSlot Slots;
564
565 const auto UAVCount = GetUAVCount(ShaderInd);
566 for (Uint32 uav = 0; uav < UAVCount; ++uav)
567 {
568 const Uint32 Slot = Binding++;
569 if (CommittedD3D11UAVs[Slot] != d3d11UAVs[uav])
570 Slots.Add(Slot);
571
572 VERIFY_EXPR(d3d11UAVs[uav] != nullptr);
573 CommittedD3D11UAVResources[Slot] = UAVResources[uav].pd3d11Resource;
574 CommittedD3D11UAVs[Slot] = d3d11UAVs[uav];
575 }
576
577 return Slots;
578 }
579
580476 } // namespace Diligent
294294 RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl{pBuffer, IID_BufferD3D11};
295295 #ifdef DILIGENT_DEVELOPMENT
296296 {
297 const auto& CachedCB = ResourceCache.GetCB(Attr.BindPoints + ArrayIndex);
297 const auto& CachedCB = ResourceCache.GetResource<ID3D11Buffer>(Attr.BindPoints + ArrayIndex);
298298 VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(),
299299 m_ParentManager.m_pSignature->GetDesc().Name);
300300 }
318318 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
319319 #ifdef DILIGENT_DEVELOPMENT
320320 {
321 auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex);
321 auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex);
322322 VerifyResourceViewBinding(Desc, ArrayIndex,
323323 pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE},
324324 RESOURCE_DIM_UNDEFINED, false, CachedSRV.pView.RawPtr(),
352352 #ifdef DILIGENT_DEVELOPMENT
353353 if (SampDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
354354 {
355 auto& CachedSampler = ResourceCache.GetSampler(SampAttr.BindPoints + SampArrayIndex);
355 auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(SampAttr.BindPoints + SampArrayIndex);
356356 if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl)
357357 {
358358 auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
396396
397397 if (GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
398398 {
399 auto& CachedSampler = ResourceCache.GetSampler(Attr.BindPoints + ArrayIndex);
399 auto& CachedSampler = ResourceCache.GetResource<ID3D11SamplerState>(Attr.BindPoints + ArrayIndex);
400400 if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11)
401401 {
402402 auto VarTypeStr = GetShaderVariableTypeLiteralName(GetType());
424424 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
425425 #ifdef DILIGENT_DEVELOPMENT
426426 {
427 auto& CachedSRV = ResourceCache.GetSRV(Attr.BindPoints + ArrayIndex);
427 auto& CachedSRV = ResourceCache.GetResource<ID3D11ShaderResourceView>(Attr.BindPoints + ArrayIndex);
428428 VerifyResourceViewBinding(Desc, ArrayIndex,
429429 pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE},
430430 RESOURCE_DIM_BUFFER, false, CachedSRV.pView.RawPtr(),
450450 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
451451 #ifdef DILIGENT_DEVELOPMENT
452452 {
453 auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex);
453 auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex);
454454 VerifyResourceViewBinding(Desc, ArrayIndex,
455455 pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS},
456456 RESOURCE_DIM_UNDEFINED, false, CachedUAV.pView.RawPtr(),
475475 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
476476 #ifdef DILIGENT_DEVELOPMENT
477477 {
478 auto& CachedUAV = ResourceCache.GetUAV(Attr.BindPoints + ArrayIndex);
478 auto& CachedUAV = ResourceCache.GetResource<ID3D11UnorderedAccessView>(Attr.BindPoints + ArrayIndex);
479479 VerifyResourceViewBinding(Desc, ArrayIndex,
480480 pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS},
481481 RESOURCE_DIM_BUFFER, false, CachedUAV.pView.RawPtr(),