git.s-ol.nu forks/DiligentCore / 09b9f1d
Renamed _DEBUG and DEVELOPMENT macros to DILGENT_DEBUG and DILIGENT_DEVELOPMENT assiduous 2 years ago
109 changed file(s) with 480 addition(s) and 462 deletion(s). Raw diff Collapse all Expand all
228228 # target_compile_options(Diligent-BuildSettings INTERFACE "$<$<CONFIG:RELEASE>:/Ot>")
229229 # does not work as expected
230230
231 set(DEBUG_MACROS DEVELOPMENT)
231 set(DEBUG_MACROS DILIGENT_DEVELOPMENT DILIGENT_DEBUG)
232232 target_compile_definitions(Diligent-BuildSettings INTERFACE "$<$<CONFIG:DEBUG>:${DEBUG_MACROS}>")
233233 else()
234234 # Todo: use __attribute__((always_inline)), but it needs to be defined in a header file
235235 target_compile_definitions(Diligent-BuildSettings INTERFACE __forceinline=inline)
236236
237 set(DEBUG_MACROS _DEBUG DEBUG DEVELOPMENT)
237 set(DEBUG_MACROS _DEBUG DEBUG DILIGENT_DEVELOPMENT DILIGENT_DEBUG)
238238 set(RELEASE_MACROS NDEBUG)
239239
240240 foreach(DBG_CONFIG ${DEBUG_CONFIGURATIONS})
156156 return SampleInfo;
157157 }
158158
159 #ifdef _DEBUG
159 #ifdef DILIGENT_DEBUG
160160 template <TEXTURE_ADDRESS_MODE AddressMode>
161161 void _DbgVerifyFilterInfo(const LinearTexFilterSampleInfo& FilterInfo, Uint32 Width, const char* Direction, float u)
162162 {
202202 auto UFilterInfo = GetLinearTexFilterSampleInfo<AddressModeU, IsNormalizedCoord>(Width, u);
203203 auto VFilterInfo = GetLinearTexFilterSampleInfo<AddressModeV, IsNormalizedCoord>(Height, v);
204204
205 #ifdef _DEBUG
205 #ifdef DILIGENT_DEBUG
206206 {
207207 _DbgVerifyFilterInfo<AddressModeU>(UFilterInfo, Width, "horizontal", u);
208208 _DbgVerifyFilterInfo<AddressModeV>(VFilterInfo, Height, "horizontal", v);
4242 namespace Diligent
4343 {
4444
45 #ifdef _DEBUG
45 #ifdef DILIGENT_DEBUG
4646 inline void FillWithDebugPattern(void* ptr, Uint8 Pattern, size_t NumBytes)
4747 {
4848 memset(ptr, Pattern, NumBytes);
127127 return reinterpret_cast<Uint8*>(m_pPageStart) + BlockIndex * m_pOwnerAllocator->m_BlockSize;
128128 }
129129
130 #ifdef _DEBUG
130 #ifdef DILIGENT_DEBUG
131131 void dbgVerifyAddress(const void* pBlockAddr) const
132132 {
133133 size_t Delta = reinterpret_cast<const Uint8*>(pBlockAddr) - reinterpret_cast<Uint8*>(m_pPageStart);
240240 public:
241241 static void SetRawAllocator(IMemoryAllocator& Allocator)
242242 {
243 #ifdef _DEBUG
243 #ifdef DILIGENT_DEBUG
244244 if (m_bPoolInitialized && m_pRawAllocator != &Allocator)
245245 {
246246 LOG_WARNING_MESSAGE("Setting pool raw allocator after the pool has been initialized has no effect");
250250 }
251251 static void SetPageSize(Uint32 NumAllocationsInPage)
252252 {
253 #ifdef _DEBUG
253 #ifdef DILIGENT_DEBUG
254254 if (m_bPoolInitialized && m_NumAllocationsInPage != NumAllocationsInPage)
255255 {
256256 LOG_WARNING_MESSAGE("Setting pool page size after the pool has been initialized has no effect");
261261 static ObjectPool& GetPool()
262262 {
263263 static ObjectPool ThePool;
264 #ifdef _DEBUG
264 #ifdef DILIGENT_DEBUG
265265 m_bPoolInitialized = true;
266266 #endif
267267 return ThePool;
298298 ObjectPool() :
299299 m_FixedBlockAlloctor(m_pRawAllocator ? *m_pRawAllocator : GetRawAllocator(), sizeof(ObjectType), m_NumAllocationsInPage)
300300 {}
301 #ifdef _DEBUG
301 #ifdef DILIGENT_DEBUG
302302 static bool m_bPoolInitialized;
303303 #endif
304304 FixedBlockMemoryAllocator m_FixedBlockAlloctor;
309309 template <typename ObjectType>
310310 IMemoryAllocator* ObjectPool<ObjectType>::m_pRawAllocator = nullptr;
311311
312 #ifdef _DEBUG
312 #ifdef DILIGENT_DEBUG
313313 template <typename ObjectType>
314314 bool ObjectPool<ObjectType>::m_bPoolInitialized = false;
315315 #endif
219219 {
220220 m_lNumStrongReferences = 0;
221221 m_lNumWeakReferences = 0;
222 #ifdef _DEBUG
222 #ifdef DILIGENT_DEBUG
223223 memset(m_ObjectWrapperBuffer, 0, sizeof(m_ObjectWrapperBuffer));
224224 #endif
225225 }
355355 // | - Increment m_lNumStrongReferences
356356 // | 5. Decrement m_lNumStrongReferences
357357
358 #ifdef _DEBUG
359 Atomics::Long NumStrongRefs = m_lNumStrongReferences;
360 VERIFY(NumStrongRefs == 0 || NumStrongRefs == 1, "Num strong references (", NumStrongRefs, ") is expected to be 0 or 1");
358 #ifdef DILIGENT_DEBUG
359 {
360 Atomics::Long NumStrongRefs = m_lNumStrongReferences;
361 VERIFY(NumStrongRefs == 0 || NumStrongRefs == 1, "Num strong references (", NumStrongRefs, ") is expected to be 0 or 1");
362 }
361363 #endif
362364
363365 // Acquire the lock.
391393 size_t ObjectWrapperBufferCopy[ObjectWrapperBufferSize];
392394 for (size_t i = 0; i < ObjectWrapperBufferSize; ++i)
393395 ObjectWrapperBufferCopy[i] = m_ObjectWrapperBuffer[i];
394 #ifdef _DEBUG
396 #ifdef DILIGENT_DEBUG
395397 memset(m_ObjectWrapperBuffer, 0, sizeof(m_ObjectWrapperBuffer));
396398 #endif
397399 auto* pWrapper = reinterpret_cast<ObjectWrapperBase*>(ObjectWrapperBufferCopy);
613615 // clang-format off
614616 m_pAllocator{&Allocator},
615617 m_pOwner{pOwner}
616 #ifdef DEVELOPMENT
618 #ifdef DILIGENT_DEVELOPMENT
617619 , m_dvpDescription{Description}
618620 , m_dvpFileName {FileName }
619621 , m_dvpLineNumber {LineNumber }
626628 // clang-format off
627629 m_pAllocator {nullptr},
628630 m_pOwner {pOwner }
629 #ifdef DEVELOPMENT
631 #ifdef DILIGENT_DEVELOPMENT
630632 , m_dvpDescription{nullptr}
631633 , m_dvpFileName {nullptr}
632634 , m_dvpLineNumber {0 }
658660 ObjectType* pObj = nullptr;
659661 try
660662 {
661 #ifndef DEVELOPMENT
663 #ifndef DILIGENT_DEVELOPMENT
662664 static constexpr const char* m_dvpDescription = "<Unavailable in release build>";
663665 static constexpr const char* m_dvpFileName = "<Unavailable in release build>";
664666 static constexpr Int32 m_dvpLineNumber = -1;
685687 AllocatorType* const m_pAllocator;
686688 IObject* const m_pOwner;
687689
688 #ifdef DEVELOPMENT
690 #ifdef DILIGENT_DEVELOPMENT
689691 const Char* const m_dvpDescription;
690692 const char* const m_dvpFileName;
691693 Int32 const m_dvpLineNumber;
6262 STDAllocator(AllocatorType& Allocator, const Char* Description, const Char* FileName, const Int32 LineNumber) noexcept :
6363 // clang-format off
6464 m_Allocator {Allocator}
65 #ifdef DEVELOPMENT
65 #ifdef DILIGENT_DEVELOPMENT
6666 , m_dvpDescription{Description}
6767 , m_dvpFileName {FileName }
6868 , m_dvpLineNumber {LineNumber }
7575 STDAllocator(const STDAllocator<U, AllocatorType>& other) noexcept :
7676 // clang-format off
7777 m_Allocator {other.m_Allocator}
78 #ifdef DEVELOPMENT
78 #ifdef DILIGENT_DEVELOPMENT
7979 , m_dvpDescription{other.m_dvpDescription}
8080 , m_dvpFileName {other.m_dvpFileName }
8181 , m_dvpLineNumber {other.m_dvpLineNumber }
8888 STDAllocator(STDAllocator<U, AllocatorType>&& other) noexcept :
8989 // clang-format off
9090 m_Allocator {other.m_Allocator}
91 #ifdef DEVELOPMENT
91 #ifdef DILIGENT_DEVELOPMENT
9292 , m_dvpDescription{other.m_dvpDescription}
9393 , m_dvpFileName {other.m_dvpFileName }
9494 , m_dvpLineNumber {other.m_dvpLineNumber }
104104 // There is no default constructor to create null allocator, so all fields must be
105105 // initialized.
106106 DEV_CHECK_ERR(&m_Allocator == &other.m_Allocator, "Inconsistent allocators");
107 #ifdef DEVELOPMENT
107 #ifdef DILIGENT_DEVELOPMENT
108108 DEV_CHECK_ERR(m_dvpDescription == other.m_dvpDescription, "Incosistent allocator descriptions");
109109 DEV_CHECK_ERR(m_dvpFileName == other.m_dvpFileName, "Incosistent allocator file names");
110110 DEV_CHECK_ERR(m_dvpLineNumber == other.m_dvpLineNumber, "Incosistent allocator line numbers");
119119
120120 T* allocate(std::size_t count)
121121 {
122 #ifndef DEVELOPMENT
122 #ifndef DILIGENT_DEVELOPMENT
123123 static constexpr const char* m_dvpDescription = "<Unavailable in release build>";
124124 static constexpr const char* m_dvpFileName = "<Unavailable in release build>";
125125 static constexpr Int32 m_dvpLineNumber = -1;
153153 }
154154
155155 AllocatorType& m_Allocator;
156 #ifdef DEVELOPMENT
156 #ifdef DILIGENT_DEVELOPMENT
157157 const Char* const m_dvpDescription;
158158 const Char* const m_dvpFileName;
159159 Int32 const m_dvpLineNumber;
3131 template <typename DstType, typename SrcType>
3232 DstType* ValidatedCast(SrcType* Ptr)
3333 {
34 #ifdef _DEBUG
34 #ifdef DILIGENT_DEBUG
3535 if (Ptr != nullptr)
3636 {
3737 CHECK_DYNAMIC_TYPE(DstType, Ptr);
3636
3737 void* DefaultRawMemoryAllocator::Allocate(size_t Size, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
3838 {
39 #ifdef _DEBUG
40 return new Uint8[Size + 16] + 16;
41 #else
4239 return new Uint8[Size];
43 #endif
4440 }
4541
4642 void DefaultRawMemoryAllocator::Free(void* Ptr)
4743 {
48 #ifdef _DEBUG
49 delete[](reinterpret_cast<Uint8*>(Ptr) - 16);
50 #else
5144 delete[] reinterpret_cast<Uint8*>(Ptr);
52 #endif
5345 }
5446
5547 DefaultRawMemoryAllocator& DefaultRawMemoryAllocator::GetAllocator()
5555
5656 FixedBlockMemoryAllocator::~FixedBlockMemoryAllocator()
5757 {
58 #ifdef _DEBUG
58 #ifdef DILIGENT_DEBUG
5959 for (size_t p = 0; p < m_PagePool.size(); ++p)
6060 {
6161 VERIFY(!m_PagePool[p].HasAllocations(), "Memory leak detected: memory page has allocated block");
449449 SamplerInd);
450450 if (ResType == SPIRVShaderResourceAttribs::ResourceType::SeparateImage && pNewSepImg->IsValidSepSamplerAssigned())
451451 {
452 #ifdef DEVELOPMENT
452 #ifdef DILIGENT_DEVELOPMENT
453453 const auto& SepSmplr = GetSepSmplr(pNewSepImg->GetAssignedSepSamplerInd());
454454 DEV_CHECK_ERR(SepSmplr.ArraySize == 1 || SepSmplr.ArraySize == pNewSepImg->ArraySize,
455455 "Array size (", SepSmplr.ArraySize, ") of separate sampler variable '",
487487
488488 //LOG_INFO_MESSAGE(DumpResources());
489489
490 #ifdef DEVELOPMENT
490 #ifdef DILIGENT_DEVELOPMENT
491491 if (CombinedSamplerSuffix != nullptr)
492492 {
493493 for (Uint32 n = 0; n < GetNumSepSmplrs(); ++n)
179179 // See http://diligentgraphics.com/diligent-engine/architecture/d3d12/managing-resource-lifetimes/
180180 void FinishCurrentFrame(Uint64 FenceValue)
181181 {
182 #ifdef _DEBUG
182 #ifdef DILIGENT_DEBUG
183183 if (!m_CompletedFrameHeads.empty())
184184 VERIFY(FenceValue >= m_CompletedFrameHeads.back().FenceValue, "Current frame fence value (", FenceValue, ") is lower than the fence value of the previous frame (", m_CompletedFrameHeads.back().FenceValue, ")");
185185 #endif
207207
208208 if (IsEmpty())
209209 {
210 #ifdef _DEBUG
210 #ifdef DILIGENT_DEBUG
211211 VERIFY(m_CompletedFrameHeads.empty(), "Zero-size heads are not added to the list, and since the buffer is empty, there must be no heads in the list");
212212 for (const auto& head : m_CompletedFrameHeads)
213213 VERIFY(head.Size == 0, "Non zero-size head found");
107107 AddNewBlock(0, m_MaxSize);
108108 ResetCurrAlignment();
109109
110 #ifdef _DEBUG
110 #ifdef DILIGENT_DEBUG
111111 DbgVerifyList();
112112 #endif
113113 }
114114
115115 ~VariableSizeAllocationsManager()
116116 {
117 #ifdef _DEBUG
117 #ifdef DILIGENT_DEBUG
118118 if (!m_FreeBlocksByOffset.empty() || !m_FreeBlocksBySize.empty())
119119 {
120120 VERIFY(m_FreeBlocksByOffset.size() == 1, "Single free block is expected");
235235 }
236236 }
237237
238 #ifdef _DEBUG
238 #ifdef DILIGENT_DEBUG
239239 DbgVerifyList();
240240 #endif
241241 return Allocation{Offset, AdjustedSize};
255255 // upper_bound() returns an iterator pointing to the first element in the
256256 // container whose key is considered to go after k.
257257 auto NextBlockIt = m_FreeBlocksByOffset.upper_bound(Offset);
258 #ifdef _DEBUG
258 #ifdef DILIGENT_DEBUG
259259 {
260260 auto LowBnd = m_FreeBlocksByOffset.lower_bound(Offset); // First element whose offset is >=
261261 // Since zero-size allocations are not allowed, lower bound must always be equal to the upper bound
338338 ResetCurrAlignment();
339339 }
340340
341 #ifdef _DEBUG
341 #ifdef DILIGENT_DEBUG
342342 DbgVerifyList();
343343 #endif
344344 }
371371 {}
372372 }
373373
374 #ifdef _DEBUG
374 #ifdef DILIGENT_DEBUG
375375 void DbgVerifyList()
376376 {
377377 OffsetType TotalFreeSize = 0;
381381 // clang-format on
382382 static_assert(TEX_FORMAT_NUM_FORMATS == TEX_FORMAT_BC7_UNORM_SRGB + 1, "Not all texture formats initialized.");
383383
384 #ifdef _DEBUG
384 #ifdef DILIGENT_DEBUG
385385 for (Uint32 Fmt = TEX_FORMAT_UNKNOWN; Fmt < TEX_FORMAT_NUM_FORMATS; ++Fmt)
386386 VERIFY(FmtAttribs[Fmt].Format == static_cast<TEXTURE_FORMAT>(Fmt), "Uninitialized format");
387387 #endif
7070 const BufferDesc& BuffDesc,
7171 bool bIsDeviceInternal) :
7272 TDeviceObjectBase{pRefCounters, pDevice, BuffDesc, bIsDeviceInternal},
73 #ifdef _DEBUG
73 #ifdef DILIGENT_DEBUG
7474 m_dbgBuffViewAllocator{BuffViewObjAllocator},
7575 #endif
7676 m_pDefaultUAV{nullptr, STDDeleter<BufferViewImplType, TBuffViewObjAllocator>(BuffViewObjAllocator)},
163163 /// Corrects buffer view description and validates view parameters.
164164 void CorrectBufferViewDesc(struct BufferViewDesc& ViewDesc);
165165
166 #ifdef _DEBUG
166 #ifdef DILIGENT_DEBUG
167167 TBuffViewObjAllocator& m_dbgBuffViewAllocator;
168168 #endif
169169
224224
225225 bool EndQuery(IQuery* pQuery, int);
226226
227 #ifdef DEVELOPMENT
227 #ifdef DILIGENT_DEVELOPMENT
228228 // clang-format off
229229 bool DvpVerifyDrawArguments (const DrawAttribs& Attribs)const;
230230 bool DvpVerifyDrawIndexedArguments (const DrawIndexedAttribs& Attribs)const;
310310
311311 const bool m_bIsDeferred = false;
312312
313 #ifdef _DEBUG
313 #ifdef DILIGENT_DEBUG
314314 // std::unordered_map is unbelievably slow. Keeping track of mapped buffers
315315 // in release builds is not feasible
316316 struct DbgMappedBufferInfo
331331 RESOURCE_STATE_TRANSITION_MODE StateTransitionMode,
332332 SET_VERTEX_BUFFERS_FLAGS Flags)
333333 {
334 #ifdef DEVELOPMENT
334 #ifdef DILIGENT_DEVELOPMENT
335335 if (StartSlot >= MAX_BUFFER_SLOTS)
336336 {
337337 LOG_ERROR_MESSAGE("Start vertex buffer slot ", StartSlot, " is out of allowed range [0, ", MAX_BUFFER_SLOTS - 1, "].");
363363 auto& CurrStream = m_VertexStreams[StartSlot + Buff];
364364 CurrStream.pBuffer = ppBuffers ? ValidatedCast<BufferImplType>(ppBuffers[Buff]) : nullptr;
365365 CurrStream.Offset = pOffsets ? pOffsets[Buff] : 0;
366 #ifdef DEVELOPMENT
366 #ifdef DILIGENT_DEVELOPMENT
367367 if (CurrStream.pBuffer)
368368 {
369369 const auto& BuffDesc = CurrStream.pBuffer->GetDesc();
390390 inline bool DeviceContextBase<BaseInterface, ImplementationTraits>::
391391 CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, int)
392392 {
393 #ifdef DEVELOPMENT
393 #ifdef DILIGENT_DEVELOPMENT
394394 if (!m_pPipelineState)
395395 {
396396 LOG_ERROR_MESSAGE("No pipeline state is bound to the pipeline");
421421 {
422422 m_pIndexBuffer = ValidatedCast<BufferImplType>(pIndexBuffer);
423423 m_IndexDataStartOffset = ByteOffset;
424 #ifdef DEVELOPMENT
424 #ifdef DILIGENT_DEVELOPMENT
425425 if (m_pIndexBuffer)
426426 {
427427 const auto& BuffDesc = m_pIndexBuffer->GetDesc();
568568 if (pRTView)
569569 {
570570 const auto& RTVDesc = pRTView->GetDesc();
571 #ifdef DEVELOPMENT
571 #ifdef DILIGENT_DEVELOPMENT
572572 if (RTVDesc.ViewType != TEXTURE_VIEW_RENDER_TARGET)
573573 LOG_ERROR("Texture view object named '", RTVDesc.Name ? RTVDesc.Name : "", "' has incorrect view type (", GetTexViewTypeLiteralName(RTVDesc.ViewType), "). Render target view is expected");
574574 #endif
583583 }
584584 else
585585 {
586 #ifdef DEVELOPMENT
586 #ifdef DILIGENT_DEVELOPMENT
587587 const auto& TexDesc = pRTView->GetTexture()->GetDesc();
588588 if (m_FramebufferWidth != std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U))
589589 LOG_ERROR("Render target width (", std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
608608 if (pDepthStencil != nullptr)
609609 {
610610 const auto& DSVDesc = pDepthStencil->GetDesc();
611 #ifdef DEVELOPMENT
611 #ifdef DILIGENT_DEVELOPMENT
612612 if (DSVDesc.ViewType != TEXTURE_VIEW_DEPTH_STENCIL)
613613 LOG_ERROR("Texture view object named '", DSVDesc.Name ? DSVDesc.Name : "", "' has incorrect view type (", GetTexViewTypeLiteralName(DSVDesc.ViewType), "). Depth stencil view is expected");
614614 #endif
624624 }
625625 else
626626 {
627 #ifdef DEVELOPMENT
627 #ifdef DILIGENT_DEVELOPMENT
628628 const auto& TexDesc = pDepthStencil->GetTexture()->GetDesc();
629629 if (m_FramebufferWidth != std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U))
630630 LOG_ERROR("Depth-stencil target width (", std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
687687 {
688688 for (Uint32 stream = 0; stream < m_NumVertexStreams; ++stream)
689689 m_VertexStreams[stream] = VertexStreamInfo<BufferImplType>{};
690 #ifdef _DEBUG
690 #ifdef DILIGENT_DEBUG
691691 for (Uint32 stream = m_NumVertexStreams; stream < _countof(m_VertexStreams); ++stream)
692692 {
693693 VERIFY(m_VertexStreams[stream].pBuffer == nullptr, "Unexpected non-null buffer");
800800 {
801801 for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt)
802802 m_pBoundRenderTargets[rt].Release();
803 #ifdef _DEBUG
803 #ifdef DILIGENT_DEBUG
804804 for (Uint32 rt = m_NumBoundRenderTargets; rt < _countof(m_pBoundRenderTargets); ++rt)
805805 {
806806 VERIFY(m_pBoundRenderTargets[rt] == nullptr, "Non-null render target found");
824824 return false;
825825 }
826826
827 #ifdef DEVELOPMENT
827 #ifdef DILIGENT_DEVELOPMENT
828828 {
829829 const auto& ViewDesc = pView->GetDesc();
830830 if (ViewDesc.ViewType != TEXTURE_VIEW_DEPTH_STENCIL)
866866 return false;
867867 }
868868
869 #ifdef DEVELOPMENT
869 #ifdef DILIGENT_DEVELOPMENT
870870 {
871871 const auto& ViewDesc = pView->GetDesc();
872872 if (ViewDesc.ViewType != TEXTURE_VIEW_RENDER_TARGET)
956956 UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const void* pData, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode)
957957 {
958958 VERIFY(pBuffer != nullptr, "Buffer must not be null");
959 #ifdef DEVELOPMENT
960 const auto& BuffDesc = ValidatedCast<BufferImplType>(pBuffer)->GetDesc();
961 DEV_CHECK_ERR(BuffDesc.Usage == USAGE_DEFAULT, "Unable to update buffer '", BuffDesc.Name, "': only USAGE_DEFAULT buffers can be updated with UpdateData()");
962 DEV_CHECK_ERR(Offset < BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': offset (", Offset, ") exceeds the buffer size (", BuffDesc.uiSizeInBytes, ")");
963 DEV_CHECK_ERR(Size + Offset <= BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,", BuffDesc.uiSizeInBytes, ")");
959 #ifdef DILIGENT_DEVELOPMENT
960 {
961 const auto& BuffDesc = ValidatedCast<BufferImplType>(pBuffer)->GetDesc();
962 DEV_CHECK_ERR(BuffDesc.Usage == USAGE_DEFAULT, "Unable to update buffer '", BuffDesc.Name, "': only USAGE_DEFAULT buffers can be updated with UpdateData()");
963 DEV_CHECK_ERR(Offset < BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': offset (", Offset, ") exceeds the buffer size (", BuffDesc.uiSizeInBytes, ")");
964 DEV_CHECK_ERR(Size + Offset <= BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,", BuffDesc.uiSizeInBytes, ")");
965 }
964966 #endif
965967 }
966968
976978 {
977979 VERIFY(pSrcBuffer != nullptr, "Source buffer must not be null");
978980 VERIFY(pDstBuffer != nullptr, "Destination buffer must not be null");
979 #ifdef DEVELOPMENT
980 const auto& SrcBufferDesc = ValidatedCast<BufferImplType>(pSrcBuffer)->GetDesc();
981 const auto& DstBufferDesc = ValidatedCast<BufferImplType>(pDstBuffer)->GetDesc();
982 DEV_CHECK_ERR(DstOffset + Size <= DstBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,", DstBufferDesc.uiSizeInBytes, ")");
983 DEV_CHECK_ERR(SrcOffset + Size <= SrcBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,", SrcBufferDesc.uiSizeInBytes, ")");
981 #ifdef DILIGENT_DEVELOPMENT
982 {
983 const auto& SrcBufferDesc = ValidatedCast<BufferImplType>(pSrcBuffer)->GetDesc();
984 const auto& DstBufferDesc = ValidatedCast<BufferImplType>(pDstBuffer)->GetDesc();
985 DEV_CHECK_ERR(DstOffset + Size <= DstBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,", DstBufferDesc.uiSizeInBytes, ")");
986 DEV_CHECK_ERR(SrcOffset + Size <= SrcBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,", SrcBufferDesc.uiSizeInBytes, ")");
987 }
984988 #endif
985989 }
986990
992996
993997 const auto& BuffDesc = pBuffer->GetDesc();
994998
995 #ifdef _DEBUG
996 VERIFY(m_DbgMappedBuffers.find(pBuffer) == m_DbgMappedBuffers.end(), "Buffer '", BuffDesc.Name, "' has already been mapped");
997 m_DbgMappedBuffers[pBuffer] = DbgMappedBufferInfo{MapType};
999 #ifdef DILIGENT_DEBUG
1000 {
1001 VERIFY(m_DbgMappedBuffers.find(pBuffer) == m_DbgMappedBuffers.end(), "Buffer '", BuffDesc.Name, "' has already been mapped");
1002 m_DbgMappedBuffers[pBuffer] = DbgMappedBufferInfo{MapType};
1003 }
9981004 #endif
9991005
10001006 pMappedData = nullptr;
10391045 UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType)
10401046 {
10411047 VERIFY(pBuffer, "pBuffer must not be null");
1042 #ifdef _DEBUG
1043 auto MappedBufferIt = m_DbgMappedBuffers.find(pBuffer);
1044 VERIFY(MappedBufferIt != m_DbgMappedBuffers.end(), "Buffer '", pBuffer->GetDesc().Name, "' has not been mapped.");
1045 VERIFY(MappedBufferIt->second.MapType == MapType, "MapType (", MapType, ") does not match the map type that was used to map the buffer ", MappedBufferIt->second.MapType);
1046 m_DbgMappedBuffers.erase(MappedBufferIt);
1048 #ifdef DILIGENT_DEBUG
1049 {
1050 auto MappedBufferIt = m_DbgMappedBuffers.find(pBuffer);
1051 VERIFY(MappedBufferIt != m_DbgMappedBuffers.end(), "Buffer '", pBuffer->GetDesc().Name, "' has not been mapped.");
1052 VERIFY(MappedBufferIt->second.MapType == MapType, "MapType (", MapType, ") does not match the map type that was used to map the buffer ", MappedBufferIt->second.MapType);
1053 m_DbgMappedBuffers.erase(MappedBufferIt);
1054 }
10471055 #endif
10481056 }
10491057
10931101 GenerateMips(ITextureView* pTexView)
10941102 {
10951103 VERIFY(pTexView != nullptr, "pTexView must not be null");
1096 #ifdef DEVELOPMENT
1097 const auto& ViewDesc = pTexView->GetDesc();
1098 DEV_CHECK_ERR(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Shader resource view '", ViewDesc.Name,
1099 "' can't be used to generate mipmaps because its type is ", GetTexViewTypeLiteralName(ViewDesc.ViewType), ". Required view type: TEXTURE_VIEW_SHADER_RESOURCE.");
1100 DEV_CHECK_ERR((ViewDesc.Flags & TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION) != 0, "Shader resource view '", ViewDesc.Name,
1101 "' was not created with TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION flag and can't be used to generate mipmaps.");
1104 #ifdef DILIGENT_DEVELOPMENT
1105 {
1106 const auto& ViewDesc = pTexView->GetDesc();
1107 DEV_CHECK_ERR(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Shader resource view '", ViewDesc.Name,
1108 "' can't be used to generate mipmaps because its type is ", GetTexViewTypeLiteralName(ViewDesc.ViewType), ". Required view type: TEXTURE_VIEW_SHADER_RESOURCE.");
1109 DEV_CHECK_ERR((ViewDesc.Flags & TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION) != 0, "Shader resource view '", ViewDesc.Name,
1110 "' was not created with TEXTURE_VIEW_FLAG_ALLOW_MIP_MAP_GENERATION flag and can't be used to generate mipmaps.");
1111 }
11021112 #endif
11031113 }
11041114
11091119 ITexture* pDstTexture,
11101120 const ResolveTextureSubresourceAttribs& ResolveAttribs)
11111121 {
1112 #ifdef DEVELOPMENT
1122 #ifdef DILIGENT_DEVELOPMENT
11131123 VERIFY_EXPR(pSrcTexture != nullptr && pDstTexture != nullptr);
11141124 const auto& SrcTexDesc = pSrcTexture->GetDesc();
11151125 const auto& DstTexDesc = pDstTexture->GetDesc();
11501160 #endif
11511161 }
11521162
1153 #ifdef DEVELOPMENT
1163 #ifdef DILIGENT_DEVELOPMENT
11541164 template <typename BaseInterface, typename ImplementationTraits>
11551165 inline bool DeviceContextBase<BaseInterface, ImplementationTraits>::
11561166 DvpVerifyDrawArguments(const DrawAttribs& Attribs) const
15211531 return true;
15221532 }
15231533
1524 #endif // DEVELOPMENT
1534 #endif // DILIGENT_DEVELOPMENT
15251535
15261536 } // namespace Diligent
121121 for (Uint32 i = 0; i < SrcLayout.NumStaticSamplers; ++i)
122122 {
123123 VERIFY(SrcLayout.StaticSamplers[i].SamplerOrTextureName != nullptr, "Static sampler or texture name can't be null");
124 #ifdef DEVELOPMENT
125 const auto& BorderColor = SrcLayout.StaticSamplers[i].Desc.BorderColor;
126 if (!((BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 0) ||
127 (BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 1) ||
128 (BorderColor[0] == 1 && BorderColor[1] == 1 && BorderColor[2] == 1 && BorderColor[3] == 1)))
129 {
130 LOG_WARNING_MESSAGE("Static sampler for variable \"", SrcLayout.StaticSamplers[i].SamplerOrTextureName, "\" specifies border color (",
131 BorderColor[0], ", ", BorderColor[1], ", ", BorderColor[2], ", ", BorderColor[3],
132 "). D3D12 static samplers only allow transparent black (0,0,0,0), opaque black (0,0,0,1) or opaque white (1,1,1,1) as border colors");
124 #ifdef DILIGENT_DEVELOPMENT
125 {
126 const auto& BorderColor = SrcLayout.StaticSamplers[i].Desc.BorderColor;
127 if (!((BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 0) ||
128 (BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 1) ||
129 (BorderColor[0] == 1 && BorderColor[1] == 1 && BorderColor[2] == 1 && BorderColor[3] == 1)))
130 {
131 LOG_WARNING_MESSAGE("Static sampler for variable \"", SrcLayout.StaticSamplers[i].SamplerOrTextureName, "\" specifies border color (",
132 BorderColor[0], ", ", BorderColor[1], ", ", BorderColor[2], ", ", BorderColor[3],
133 "). D3D12 static samplers only allow transparent black (0,0,0,0), opaque black (0,0,0,1) or opaque white (1,1,1,1) as border colors");
134 }
133135 }
134136 #endif
135137
5252
5353 Int32 ShaderIndex = PlatformMisc::GetLSB(Type);
5454
55 #ifdef _DEBUG
55 #ifdef DILIGENT_DEBUG
5656 switch (Type)
5757 {
5858 // clang-format off
8383 const TextureDesc& Desc,
8484 bool bIsDeviceInternal = false) :
8585 TDeviceObjectBase(pRefCounters, pDevice, Desc, bIsDeviceInternal),
86 #ifdef _DEBUG
86 #ifdef DILIGENT_DEBUG
8787 m_dbgTexViewObjAllocator(TexViewObjAllocator),
8888 #endif
8989 m_pDefaultSRV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)),
199199 /// Pure virtual function that creates texture view for the specific engine implementation.
200200 virtual void CreateViewInternal(const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView) = 0;
201201
202 #ifdef _DEBUG
202 #ifdef DILIGENT_DEBUG
203203 TTexViewObjAllocator& m_dbgTexViewObjAllocator;
204204 #endif
205205 // WARNING! We cannot use ITextureView here, because ITextureView has no virtual dtor!
7878 /// Implementation of ITextureView::SetSampler()
7979 virtual void DILIGENT_CALL_TYPE SetSampler(ISampler* pSampler) override final
8080 {
81 #ifdef DEVELOPMENT
81 #ifdef DILIGENT_DEVELOPMENT
8282 if (this->m_Desc.ViewType != TEXTURE_VIEW_SHADER_RESOURCE)
8383 LOG_ERROR("Texture view \"", this->m_Desc.Name, "\": a sampler can be attached to a shader resource view only. The view type is ", GetTexViewTypeLiteralName(this->m_Desc.ViewType));
8484 #endif
141141 } \
142142 } while (false)
143143
144 #ifdef DEVELOPMENT
144 #ifdef DILIGENT_DEVELOPMENT
145145 VERIFY_TEX_PARAMS(MipLevel < TexDesc.MipLevels, "Mip level (", MipLevel, ") is out of allowed range [0, ", TexDesc.MipLevels - 1, "]");
146146 VERIFY_TEX_PARAMS(Box.MinX < Box.MaxX, "Invalid X range: ", Box.MinX, "..", Box.MaxX);
147147 VERIFY_TEX_PARAMS(Box.MinY < Box.MaxY, "Invalid Y range: ", Box.MinY, "..", Box.MaxY);
207207 VERIFY((SubresData.pData != nullptr) ^ (SubresData.pSrcBuffer != nullptr), "Either CPU data pointer (pData) or GPU buffer (pSrcBuffer) must not be null, but not both");
208208 ValidateTextureRegion(TexDesc, MipLevel, Slice, DstBox);
209209
210 #ifdef DEVELOPMENT
210 #ifdef DILIGENT_DEVELOPMENT
211211 VERIFY_TEX_PARAMS(TexDesc.SampleCount == 1, "Only non-multisampled textures can be updated with UpdateData()");
212212 VERIFY_TEX_PARAMS((SubresData.Stride & 0x03) == 0, "Texture data stride (", SubresData.Stride, ") must be at least 32-bit aligned");
213213 VERIFY_TEX_PARAMS((SubresData.DepthStride & 0x03) == 0, "Texture data depth stride (", SubresData.DepthStride, ") must be at least 32-bit aligned");
3838 #include "QueryD3D11Impl.hpp"
3939 #include "DisjointQueryPool.hpp"
4040
41 #ifdef _DEBUG
41 #ifdef DILIGENT_DEBUG
4242 # define VERIFY_CONTEXT_BINDINGS
4343 #endif
4444
2626
2727 #pragma once
2828
29 #ifdef _DEBUG
29 #ifdef DILIGENT_DEBUG
3030 # define VERIFY_SHADER_BINDINGS
3131 #endif
326326
327327 Uint8* m_pResourceData = nullptr;
328328
329 #ifdef _DEBUG
329 #ifdef DILIGENT_DEBUG
330330 IMemoryAllocator* m_pdbgMemoryAllocator = nullptr;
331331 #endif
332332 };
258258 // while Layout is alive
259259 void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache);
260260
261 #ifdef DEVELOPMENT
261 #ifdef DILIGENT_DEVELOPMENT
262262 bool dvpVerifyBindings() const;
263263 #endif
264264
110110 __forceinline Int32 GetMaxUAVBindPoint() const { return m_MaxUAVBindPoint; }
111111 // clang-format on
112112
113 #ifdef DEVELOPMENT
113 #ifdef DILIGENT_DEVELOPMENT
114114 void dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[],
115115 ID3D11ShaderResourceView* CommittedD3D11SRVs[],
116116 ID3D11Resource* CommittedD3D11SRVResources[],
172172
173173 if (pShaderResourceBinding == nullptr)
174174 {
175 #ifdef DEVELOPMENT
175 #ifdef DILIGENT_DEVELOPMENT
176176 bool ResourcesPresent = false;
177177 for (Uint32 s = 0; s < pPipelineStateD3D11->GetNumShaders(); ++s)
178178 {
192192
193193
194194 auto pShaderResBindingD3D11 = ValidatedCast<ShaderResourceBindingD3D11Impl>(pShaderResourceBinding);
195 #ifdef DEVELOPMENT
195 #ifdef DILIGENT_DEVELOPMENT
196196 if (pPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState()))
197197 {
198198 LOG_ERROR_MESSAGE("Shader resource binding does not match Pipeline State");
203203 auto NumShaders = pShaderResBindingD3D11->GetNumActiveShaders();
204204 VERIFY(NumShaders == pPipelineStateD3D11->GetNumShaders(), "Number of active shaders in shader resource binding is not consistent with the number of shaders in the pipeline state");
205205
206 #ifdef DEVELOPMENT
207 bool StaticResourcesPresent = false;
208 for (Uint32 s = 0; s < NumShaders; ++s)
209 {
210 const auto& StaticResLayout = pPipelineStateD3D11->GetStaticResourceLayout(s);
211 if (StaticResLayout.GetTotalResourceCount() > 0)
212 StaticResourcesPresent = true;
213 }
214 // Static resource bindings are verified in BindStaticShaderResources()
215 if (StaticResourcesPresent && !pShaderResBindingD3D11->IsStaticResourcesBound())
216 {
217 LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", pPSO->GetDesc().Name, "'. Please call IShaderResourceBinding::InitializeStaticResources().");
206 #ifdef DILIGENT_DEVELOPMENT
207 {
208 bool StaticResourcesPresent = false;
209 for (Uint32 s = 0; s < NumShaders; ++s)
210 {
211 const auto& StaticResLayout = pPipelineStateD3D11->GetStaticResourceLayout(s);
212 if (StaticResLayout.GetTotalResourceCount() > 0)
213 StaticResourcesPresent = true;
214 }
215 // Static resource bindings are verified in BindStaticShaderResources()
216 if (StaticResourcesPresent && !pShaderResBindingD3D11->IsStaticResourcesBound())
217 {
218 LOG_ERROR_MESSAGE("Static resources have not been initialized in the shader resource binding object being committed for PSO '", pPSO->GetDesc().Name, "'. Please call IShaderResourceBinding::InitializeStaticResources().");
219 }
218220 }
219221 #endif
220222
224226 {
225227 auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s);
226228
227 #ifdef DEVELOPMENT
229 #ifdef DILIGENT_DEVELOPMENT
228230 auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s);
229231 VERIFY_EXPR(ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)));
230232 #endif
273275 }
274276 }
275277 }
276 #ifdef DEVELOPMENT
278 #ifdef DILIGENT_DEVELOPMENT
277279 else if (VerifyStates)
278280 {
279281 if (const auto* pTexture = ValidatedCast<TextureBaseD3D11>(UAVRes.pTexture))
335337 }
336338 }
337339
338 #ifdef DEVELOPMENT
340 #ifdef DILIGENT_DEVELOPMENT
339341 if ((m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE) != 0 && ShaderTypeInd == CSInd)
340342 {
341343 dbgVerifyCommittedUAVs(pShaderD3D11->GetDesc().ShaderType);
370372 {
371373 auto ShaderTypeInd = pShaderResBindingD3D11->GetActiveShaderTypeIndex(s);
372374
373 #ifdef DEVELOPMENT
375 #ifdef DILIGENT_DEVELOPMENT
374376 auto* pShaderD3D11 = pPipelineStateD3D11->GetShader<ShaderD3D11Impl>(s);
375377 VERIFY_EXPR(ShaderTypeInd == static_cast<Int32>(GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType)));
376378 #endif
413415 }
414416 }
415417 }
416 #ifdef DEVELOPMENT
418 #ifdef DILIGENT_DEVELOPMENT
417419 else if (VerifyStates)
418420 {
419421 VERIFY_EXPR(CommitResources);
445447 (m_pd3d11DeviceContext->*SetCBMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11CBs + MinSlot);
446448 m_NumCommittedCBs[ShaderTypeInd] = std::max(m_NumCommittedCBs[ShaderTypeInd], static_cast<Uint8>(NumCBs));
447449 }
448 #ifdef DEVELOPMENT
450 #ifdef DILIGENT_DEVELOPMENT
449451 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
450452 {
451453 dbgVerifyCommittedCBs(pShaderD3D11->GetDesc().ShaderType);
512514 }
513515 }
514516 }
515 #ifdef DEVELOPMENT
517 #ifdef DILIGENT_DEVELOPMENT
516518 else if (VerifyStates)
517519 {
518520 VERIFY_EXPR(CommitResources);
552554 (m_pd3d11DeviceContext->*SetSRVMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11SRVs + MinSlot);
553555 m_NumCommittedSRVs[ShaderTypeInd] = std::max(m_NumCommittedSRVs[ShaderTypeInd], static_cast<Uint8>(NumSRVs));
554556 }
555 #ifdef DEVELOPMENT
557 #ifdef DILIGENT_DEVELOPMENT
556558 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
557559 {
558560 dbgVerifyCommittedSRVs(pShaderD3D11->GetDesc().ShaderType);
592594 (m_pd3d11DeviceContext->*SetSamplerMethod)(MinSlot, MaxSlot - MinSlot + 1, CommittedD3D11Samplers + MinSlot);
593595 m_NumCommittedSamplers[ShaderTypeInd] = std::max(m_NumCommittedSamplers[ShaderTypeInd], static_cast<Uint8>(NumSamplers));
594596 }
595 #ifdef DEVELOPMENT
597 #ifdef DILIGENT_DEVELOPMENT
596598 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
597599 {
598600 dbgVerifyCommittedSamplers(pShaderD3D11->GetDesc().ShaderType);
603605
604606
605607
606 #ifdef DEVELOPMENT
608 #ifdef DILIGENT_DEVELOPMENT
607609 if (CommitResources && (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_SHADER_RESOURCES) != 0)
608610 {
609611 // Use full resource layout to verify that all required resources are committed
750752
751753 void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags)
752754 {
753 #ifdef DEVELOPMENT
755 #ifdef DILIGENT_DEVELOPMENT
754756 if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
755757 DvpVerifyRenderTargets();
756758 #endif
762764 CommitD3D11VertexBuffers(m_pPipelineState);
763765 }
764766
765 #ifdef DEVELOPMENT
767 #ifdef DILIGENT_DEVELOPMENT
766768 if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0)
767769 {
768770 for (UINT Slot = 0; Slot < m_NumVertexStreams; ++Slot)
800802 {
801803 CommitD3D11IndexBuffer(IndexType);
802804 }
803 #ifdef DEVELOPMENT
805 #ifdef DILIGENT_DEVELOPMENT
804806 if (Flags & DRAW_FLAG_VERIFY_STATES)
805807 {
806808 if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
872874 if (!DvpVerifyDispatchArguments(Attribs))
873875 return;
874876
875 #ifdef DEVELOPMENT
877 #ifdef DILIGENT_DEVELOPMENT
876878 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
877879 {
878880 // Verify bindings
892894 if (!DvpVerifyDispatchIndirectArguments(Attribs, pAttribsBuffer))
893895 return;
894896
895 #ifdef DEVELOPMENT
897 #ifdef DILIGENT_DEVELOPMENT
896898 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
897899 {
898900 // Verify bindings
11771179 pBuffD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS);
11781180 }
11791181 }
1180 #ifdef DEVELOPMENT
1182 #ifdef DILIGENT_DEVELOPMENT
11811183 else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
11821184 {
11831185 if (pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
12071209 m_pIndexBuffer->ClearState(RESOURCE_STATE_UNORDERED_ACCESS);
12081210 }
12091211 }
1210 #ifdef DEVELOPMENT
1212 #ifdef DILIGENT_DEVELOPMENT
12111213 else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
12121214 {
12131215 if (m_pIndexBuffer->IsInKnownState() && m_pIndexBuffer->CheckState(RESOURCE_STATE_UNORDERED_ACCESS))
14431445 m_bCommittedD3D11IBUpToDate = false;
14441446 m_pd3d11DeviceContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R32_UINT, m_CommittedD3D11IndexDataStartOffset);
14451447 }
1446 #ifdef DEVELOPMENT
1448 #ifdef DILIGENT_DEVELOPMENT
14471449 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
14481450 {
14491451 dbgVerifyCommittedIndexBuffer();
14711473 m_pd3d11DeviceContext->IASetVertexBuffers(Slot, _countof(ppNullBuffer), ppNullBuffer, Zero, Zero);
14721474 }
14731475 }
1474 #ifdef DEVELOPMENT
1476 #ifdef DILIGENT_DEVELOPMENT
14751477 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
14761478 {
14771479 dbgVerifyCommittedVertexBuffers();
14971499 }
14981500 }
14991501 }
1500 #ifdef DEVELOPMENT
1502 #ifdef DILIGENT_DEVELOPMENT
15011503 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
15021504 {
15031505 dbgVerifyCommittedCBs();
15811583 if (pTex->IsInKnownState())
15821584 pTex->SetState(RESOURCE_STATE_RENDER_TARGET);
15831585 }
1584 #ifdef DEVELOPMENT
1586 #ifdef DILIGENT_DEVELOPMENT
15851587 else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
15861588 {
15871589 DvpVerifyTextureState(*pTex, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D11Impl::SetRenderTargets)");
15991601 if (pTex->IsInKnownState())
16001602 pTex->SetState(RESOURCE_STATE_DEPTH_WRITE);
16011603 }
1602 #ifdef DEVELOPMENT
1604 #ifdef DILIGENT_DEVELOPMENT
16031605 else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
16041606 {
16051607 DvpVerifyTextureState(*pTex, RESOURCE_STATE_DEPTH_WRITE, "Setting depth-stencil buffer (DeviceContextD3D11Impl::SetRenderTargets)");
16831685 m_NumCommittedUAVs[ShaderType] = 0;
16841686 }
16851687
1686 #ifdef DEVELOPMENT
1688 #ifdef DILIGENT_DEVELOPMENT
16871689 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
16881690 {
16891691 dbgVerifyCommittedSRVs();
17161718 // Device context is now in default state
17171719 InvalidateState();
17181720
1719 #ifdef DEVELOPMENT
1721 #ifdef DILIGENT_DEVELOPMENT
17201722 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
17211723 {
17221724 // Verify bindings
17531755 // Device context is now in default state
17541756 InvalidateState();
17551757
1756 #ifdef DEVELOPMENT
1758 #ifdef DILIGENT_DEVELOPMENT
17571759 if (m_DebugFlags & D3D11_DEBUG_FLAG_VERIFY_COMMITTED_RESOURCE_RELEVANCE)
17581760 {
17591761 // Verify bindings
19441946 for (Uint32 i = 0; i < BarrierCount; ++i)
19451947 {
19461948 const auto& Barrier = pResourceBarriers[i];
1947 #ifdef DEVELOPMENT
1949 #ifdef DILIGENT_DEVELOPMENT
19481950 DvpVerifyStateTransitionDesc(Barrier);
19491951 #endif
19501952 DEV_CHECK_ERR((Barrier.pTexture != nullptr) ^ (Barrier.pBuffer != nullptr), "Exactly one of pTexture or pBuffer must not be null");
7676 };
7777
7878
79 #if defined(_DEBUG)
79 #if defined(DILIGENT_DEVELOPMENT)
8080 // Check for SDK Layer support.
8181 inline bool SdkLayersAvailable()
8282 {
129129 // D3D11_CREATE_DEVICE_BGRA_SUPPORT;
130130 UINT creationFlags = 0;
131131
132 #if defined(DEVELOPMENT)
132 #if defined(DILIGENT_DEVELOPMENT)
133133 if ((EngineCI.DebugFlags & D3D11_DEBUG_FLAG_CREATE_DEBUG_DEVICE) != 0 && SdkLayersAvailable())
134134 {
135135 // If the project is in a debug build, enable debugging via SDK Layers with this flag.
130130
131131 const auto& ResourceLayout = m_Desc.ResourceLayout;
132132
133 #ifdef DEVELOPMENT
133 #ifdef DILIGENT_DEVELOPMENT
134134 {
135135 const ShaderResources* pResources[MAX_SHADERS_IN_PIPELINE] = {};
136136 for (Uint32 s = 0; s < m_NumShaders; ++s)
153153 {
154154 const auto& StaticResLayout = pPSOD3D11->GetStaticResourceLayout(shader);
155155 auto* pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(ppShaders[shader]);
156 #ifdef DEVELOPMENT
156 #ifdef DILIGENT_DEVELOPMENT
157157 if (!StaticResLayout.dvpVerifyBindings())
158158 {
159159 LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSOD3D11->GetDesc().Name,
164164 }
165165 #endif
166166
167 #ifdef _DEBUG
168 auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType);
169 auto ResourceLayoutInd = m_ResourceLayoutIndex[ShaderTypeInd];
170 VERIFY_EXPR(ResourceLayoutInd == static_cast<Int8>(shader));
167 #ifdef DILIGENT_DEBUG
168 {
169 auto ShaderTypeInd = GetShaderTypeIndex(pShaderD3D11->GetDesc().ShaderType);
170 auto ResourceLayoutInd = m_ResourceLayoutIndex[ShaderTypeInd];
171 VERIFY_EXPR(ResourceLayoutInd == static_cast<Int8>(shader));
172 }
171173 #endif
172174 StaticResLayout.CopyResources(m_pBoundResourceCaches[shader]);
173175 pPSOD3D11->SetStaticSamplers(m_pBoundResourceCaches[shader], shader);
9898 (sizeof(CachedResource) + sizeof(ID3D11UnorderedAccessView*)) * UAVCount );
9999 // clang-format on
100100
101 #ifdef _DEBUG
101 #ifdef DILIGENT_DEBUG
102102 m_pdbgMemoryAllocator = &MemAllocator;
103103 #endif
104104 if (BufferSize > 0)
238238 if (!SamplerFound)
239239 {
240240 AssignedSamplerIndex = TexSRVBindInfo::InvalidSamplerIndex;
241 #ifdef _DEBUG
241 #ifdef DILIGENT_DEBUG
242242 // Shader error will be logged by the PipelineStateD3D11Impl
243243 constexpr bool LogStaticSamplerArrayError = false;
244244 if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout, LogStaticSamplerArrayError) < 0)
249249 }
250250 else
251251 {
252 #ifdef _DEBUG
252 #ifdef DILIGENT_DEBUG
253253 // Shader error will be logged by the PipelineStateD3D11Impl
254254 constexpr bool LogStaticSamplerArrayError = false;
255255 if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout, LogStaticSamplerArrayError) >= 0)
429429 // We cannot use ValidatedCast<> here as the resource retrieved from the
430430 // resource mapping can be of wrong type
431431 RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl(pBuffer, IID_BufferD3D11);
432 #ifdef DEVELOPMENT
432 #ifdef DILIGENT_DEVELOPMENT
433433 {
434434 auto& CachedCB = m_ParentResLayout.m_ResourceCache.GetCB(m_Attribs.BindPoint + ArrayIndex);
435435 VerifyConstantBufferBinding(m_Attribs, GetType(), ArrayIndex, pBuffer, pBuffD3D11Impl.RawPtr(), CachedCB.pBuff.RawPtr(), m_ParentResLayout.GetShaderName());
448448 // We cannot use ValidatedCast<> here as the resource retrieved from the
449449 // resource mapping can be of wrong type
450450 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11(pView, IID_TextureViewD3D11);
451 #ifdef DEVELOPMENT
451 #ifdef DILIGENT_DEVELOPMENT
452452 {
453453 auto& CachedSRV = ResourceCache.GetSRV(m_Attribs.BindPoint + ArrayIndex);
454454 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, CachedSRV.pView.RawPtr(), m_ParentResLayout.GetShaderName());
466466 if (pViewD3D11)
467467 {
468468 pSamplerD3D11Impl = ValidatedCast<SamplerD3D11Impl>(pViewD3D11->GetSampler());
469 #ifdef DEVELOPMENT
469 #ifdef DILIGENT_DEVELOPMENT
470470 if (pSamplerD3D11Impl == nullptr)
471471 {
472472 if (Sampler.m_Attribs.BindCount > 1)
476476 }
477477 #endif
478478 }
479 #ifdef DEVELOPMENT
479 #ifdef DILIGENT_DEVELOPMENT
480480 if (Sampler.GetType() != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC)
481481 {
482482 auto& CachedSampler = ResourceCache.GetSampler(SamplerBindPoint);
506506 // resource mapping can be of wrong type
507507 RefCntAutoPtr<SamplerD3D11Impl> pSamplerD3D11(pSampler, IID_SamplerD3D11);
508508
509 #ifdef DEVELOPMENT
509 #ifdef DILIGENT_DEVELOPMENT
510510 if (pSampler && !pSamplerD3D11)
511511 {
512512 LOG_ERROR_MESSAGE("Failed to bind object '", pSampler->GetDesc().Name, "' to variable '", m_Attribs.GetPrintName(ArrayIndex),
548548 // We cannot use ValidatedCast<> here as the resource retrieved from the
549549 // resource mapping can be of wrong type
550550 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11(pView, IID_BufferViewD3D11);
551 #ifdef DEVELOPMENT
551 #ifdef DILIGENT_DEVELOPMENT
552552 {
553553 auto& CachedSRV = ResourceCache.GetSRV(m_Attribs.BindPoint + ArrayIndex);
554554 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE}, CachedSRV.pView.RawPtr(), m_ParentResLayout.GetShaderName());
568568 // We cannot use ValidatedCast<> here as the resource retrieved from the
569569 // resource mapping can be of wrong type
570570 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11(pView, IID_TextureViewD3D11);
571 #ifdef DEVELOPMENT
571 #ifdef DILIGENT_DEVELOPMENT
572572 {
573573 auto& CachedUAV = ResourceCache.GetUAV(m_Attribs.BindPoint + ArrayIndex);
574574 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewD3D11.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS}, CachedUAV.pView.RawPtr(), m_ParentResLayout.GetShaderName());
588588 // We cannot use ValidatedCast<> here as the resource retrieved from the
589589 // resource mapping can be of wrong type
590590 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11(pView, IID_BufferViewD3D11);
591 #ifdef DEVELOPMENT
591 #ifdef DILIGENT_DEVELOPMENT
592592 {
593593 auto& CachedUAV = ResourceCache.GetUAV(m_Attribs.BindPoint + ArrayIndex);
594594 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewD3D11.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS}, CachedUAV.pView.RawPtr(), m_ParentResLayout.GetShaderName());
751751 template <typename ResourceType>
752752 bool TryResource(ShaderResourceLayoutD3D11::OffsetType NextResourceTypeOffset)
753753 {
754 #ifdef _DEBUG
755 VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!");
756 dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>();
757 VERIFY_EXPR(NextResourceTypeOffset >= Layout.GetResourceOffset<ResourceType>());
754 #ifdef DILIGENT_DEBUG
755 {
756 VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!");
757 dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>();
758 VERIFY_EXPR(NextResourceTypeOffset >= Layout.GetResourceOffset<ResourceType>());
759 }
758760 #endif
759761 if (VarOffset < NextResourceTypeOffset)
760762 {
776778 const ShaderResourceLayoutD3D11& Layout;
777779 const size_t VarOffset;
778780 Uint32 Index = 0;
779 #ifdef _DEBUG
781 #ifdef DILIGENT_DEBUG
780782 Uint32 dbgPreviousResourceOffset = 0;
781783 #endif
782784 };
829831 template <typename ResourceType>
830832 IShaderResourceVariable* TryResource()
831833 {
832 #ifdef _DEBUG
833 VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!");
834 dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>();
834 #ifdef DILIGENT_DEBUG
835 {
836 VERIFY(Layout.GetResourceOffset<ResourceType>() >= dbgPreviousResourceOffset, "Resource types are processed out of order!");
837 dbgPreviousResourceOffset = Layout.GetResourceOffset<ResourceType>();
838 }
835839 #endif
836840 auto NumResources = Layout.GetNumResources<ResourceType>();
837841 if (Index < NumResources)
846850 private:
847851 ShaderResourceLayoutD3D11& Layout;
848852 Uint32 Index = 0;
849 #ifdef _DEBUG
853 #ifdef DILIGENT_DEBUG
850854 Uint32 dbgPreviousResourceOffset = 0;
851855 #endif
852856 };
882886 }
883887
884888
885 #ifdef DEVELOPMENT
889 #ifdef DILIGENT_DEVELOPMENT
886890 bool ShaderResourceLayoutD3D11::dvpVerifyBindings() const
887891 {
888892
117117 }
118118
119119
120 #ifdef DEVELOPMENT
120 #ifdef DILIGENT_DEVELOPMENT
121121 static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint)
122122 {
123123 VERIFY(BindPoint >= Uint32{Attr.BindPoint} && BindPoint < Uint32{Attr.BindPoint} + Attr.BindCount, "Bind point is out of allowed range");
6464
6565 virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final;
6666
67 #ifdef DEVELOPMENT
67 #ifdef DILIGENT_DEVELOPMENT
6868 void DvpVerifyDynamicAllocation(class DeviceContextD3D12Impl* pCtx) const;
6969 #endif
7070
9191 {
9292 if (m_Desc.Usage == USAGE_DYNAMIC)
9393 {
94 #ifdef DEVELOPMENT
94 #ifdef DILIGENT_DEVELOPMENT
9595 DvpVerifyDynamicAllocation(pCtx);
9696 #endif
9797 return m_DynamicData[ContextId].GPUAddress;
412412
413413 inline void CommandContext::SetDescriptorHeaps(ShaderDescriptorHeaps& Heaps)
414414 {
415 #ifdef _DEBUG
415 #ifdef DILIGENT_DEBUG
416416 VERIFY(Heaps.pSrvCbvUavHeap != nullptr || Heaps.pSamplerHeap != nullptr, "At least one heap is expected to be set");
417417 VERIFY(Heaps.pSrvCbvUavHeap == nullptr || Heaps.pSrvCbvUavHeap->GetDesc().Type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, "Invalid heap type provided in pSrvCbvUavHeap");
418418 VERIFY(Heaps.pSamplerHeap == nullptr || Heaps.pSamplerHeap->GetDesc().Type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, "Invalid heap type provided in pSamplerHeap");
5757 // allocator
5858 void FreeAllocator(CComPtr<ID3D12CommandAllocator>&& Allocator);
5959
60 #ifdef DEVELOPMENT
60 #ifdef DILIGENT_DEVELOPMENT
6161 Atomics::Long GetAllocatorCounter() const
6262 {
6363 return m_AllocatorCounter;
7272
7373 Atomics::AtomicLong m_NumAllocators = 0; // For debug purposes only
7474
75 #ifdef DEVELOPMENT
75 #ifdef DILIGENT_DEVELOPMENT
7676 Atomics::AtomicLong m_AllocatorCounter = 0;
7777 #endif
7878 };
4444 Uint64 _Size,
4545 void* _CPUAddress,
4646 D3D12_GPU_VIRTUAL_ADDRESS _GPUAddress
47 #ifdef DEVELOPMENT
47 #ifdef DILIGENT_DEVELOPMENT
4848 ,
4949 Uint64 _DvpCtxFrameNumber
5050 #endif
5555 Size {_Size },
5656 CPUAddress {_CPUAddress },
5757 GPUAddress {_GPUAddress }
58 #ifdef DEVELOPMENT
58 #ifdef DILIGENT_DEVELOPMENT
5959 , DvpCtxFrameNumber(_DvpCtxFrameNumber)
6060 #endif
6161 // clang-format on
6666 Uint64 Size = 0; // Reserved size of this allocation
6767 void* CPUAddress = nullptr; // The CPU-writeable address
6868 D3D12_GPU_VIRTUAL_ADDRESS GPUAddress = 0; // The GPU-visible address
69 #ifdef DEVELOPMENT
69 #ifdef DILIGENT_DEVELOPMENT
7070 Uint64 DvpCtxFrameNumber = static_cast<Uint64>(-1);
7171 #endif
7272 };
140140
141141 D3D12DynamicPage AllocatePage(Uint64 SizeInBytes);
142142
143 #ifdef DEVELOPMENT
143 #ifdef DILIGENT_DEVELOPMENT
144144 int32_t GetAllocatedPageCounter() const
145145 {
146146 return m_AllocatedPageCounter;
154154 using AvailablePagesMapElemType = std::pair<const Uint64, D3D12DynamicPage>;
155155 std::multimap<Uint64, D3D12DynamicPage, std::less<Uint64>, STDAllocatorRawMem<AvailablePagesMapElemType>> m_AvailablePages;
156156
157 #ifdef DEVELOPMENT
157 #ifdef DILIGENT_DEVELOPMENT
158158 std::atomic_int32_t m_AllocatedPageCounter = 0;
159159 #endif
160160 };
272272 rhs.m_FirstCPUHandle.ptr = 0;
273273 rhs.m_FirstGPUHandle.ptr = 0;
274274 rhs.m_MaxAllocatedSize = 0;
275 #ifdef DEVELOPMENT
275 #ifdef DILIGENT_DEVELOPMENT
276276 m_AllocationsCounter.store(rhs.m_AllocationsCounter.load());
277277 rhs.m_AllocationsCounter = 0;
278278 #endif
297297 size_t GetMaxAllocatedSize() const { return m_MaxAllocatedSize; }
298298 // clang-format on
299299
300 #ifdef DEVELOPMENT
300 #ifdef DILIGENT_DEVELOPMENT
301301 int32_t DvpGetAllocationsCounter() const
302302 {
303303 return m_AllocationsCounter;
336336
337337 size_t m_MaxAllocatedSize = 0;
338338
339 #ifdef DEVELOPMENT
339 #ifdef DILIGENT_DEVELOPMENT
340340 std::atomic_int32_t m_AllocationsCounter = 0;
341341 #endif
342342
383383 virtual void Free(DescriptorHeapAllocation&& Allocation, Uint64 CmdQueueMask) override final;
384384 virtual Uint32 GetDescriptorSize() const override final { return m_DescriptorSize; }
385385
386 #ifdef DEVELOPMENT
386 #ifdef DILIGENT_DEVELOPMENT
387387 int32_t DvpGetTotalAllocationCount();
388388 #endif
389389
482482 Uint32 GetMaxStaticDescriptors() const { return m_HeapAllocationManager.GetMaxDescriptors(); }
483483 Uint32 GetMaxDynamicDescriptors() const { return m_DynamicAllocationsManager.GetMaxDescriptors(); }
484484
485 #ifdef DEVELOPMENT
485 #ifdef DILIGENT_DEVELOPMENT
486486 int32_t DvpGetTotalAllocationCount() const
487487 {
488488 return m_HeapAllocationManager.DvpGetAllocationsCounter() +
160160
161161 std::mutex m_ContextPoolMutex;
162162 std::vector<PooledCommandContext, STDAllocatorRawMem<PooledCommandContext>> m_ContextPool;
163 #ifdef DEVELOPMENT
163 #ifdef DILIGENT_DEVELOPMENT
164164 Atomics::AtomicLong m_AllocatedCtxCounter = 0;
165165 #endif
166166
9898 m_RootParam.ShaderVisibility = Visibility;
9999 m_RootParam.DescriptorTable.NumDescriptorRanges = NumRanges;
100100 m_RootParam.DescriptorTable.pDescriptorRanges = pRanges;
101 #ifdef _DEBUG
101 #ifdef DILIGENT_DEBUG
102102 for (Uint32 r = 0; r < NumRanges; ++r)
103103 pRanges[r].RangeType = static_cast<D3D12_DESCRIPTOR_RANGE_TYPE>(-1);
104104 #endif
132132 DstTbl.pDescriptorRanges = pRanges;
133133 const auto& SrcTbl = RP.m_RootParam.DescriptorTable;
134134 memcpy(pRanges, SrcTbl.pDescriptorRanges, SrcTbl.NumDescriptorRanges * sizeof(D3D12_DESCRIPTOR_RANGE));
135 #ifdef _DEBUG
135 #ifdef DILIGENT_DEBUG
136136 {
137137 Uint32 dbgTableSize = 0;
138138 for (Uint32 r = 0; r < SrcTbl.NumDescriptorRanges; ++r)
374374 }
375375
376376 private:
377 #ifdef _DEBUG
377 #ifdef DILIGENT_DEBUG
378378 void dbgVerifyRootParameters() const;
379379 #endif
380380
381 #ifdef DEVELOPMENT
381 #ifdef DILIGENT_DEVELOPMENT
382382 static void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res,
383383 D3D12_DESCRIPTOR_RANGE_TYPE RangeType);
384384 #endif
532532 auto RootInd = RootView.GetRootIndex();
533533
534534 SHADER_TYPE dbgShaderType = SHADER_TYPE_UNKNOWN;
535 #ifdef _DEBUG
535 #ifdef DILIGENT_DEBUG
536536 {
537537 auto& Param = static_cast<const D3D12_ROOT_PARAMETER&>(RootView);
538538 VERIFY_EXPR(Param.ParameterType == D3D12_ROOT_PARAMETER_TYPE_CBV);
548548 {
549549 if (IsDynamic)
550550 {
551 #ifdef _DEBUG
551 #ifdef DILIGENT_DEBUG
552552 if (pBuffToTransition->IsInKnownState())
553553 {
554554 VERIFY(pBuffToTransition->CheckState(RESOURCE_STATE_CONSTANT_BUFFER),
565565 CmdCtx.TransitionResource(pBuffToTransition, RESOURCE_STATE_CONSTANT_BUFFER);
566566 }
567567 }
568 #ifdef DEVELOPMENT
568 #ifdef DILIGENT_DEVELOPMENT
569569 else if (ValidateStates)
570570 {
571571
6666
6767 ShaderResourceCacheD3D12& GetResourceCache() { return m_ShaderResourceCache; }
6868
69 #ifdef DEVELOPMENT
69 #ifdef DILIGENT_DEVELOPMENT
7070 void dvpVerifyResourceBindings(const PipelineStateD3D12Impl* pPSO) const;
7171 #endif
7272
111111
112112 ShaderResourceCacheD3D12(DbgCacheContentType dbgContentType)
113113 // clang-format off
114 #ifdef _DEBUG
114 #ifdef DILIGENT_DEBUG
115115 : m_DbgContentType
116116 {
117117 dbgContentType
182182 // Offset from the start of the descriptor heap allocation to the start of the table
183183 Uint32 m_TableStartOffset = InvalidDescriptorOffset;
184184
185 #ifdef _DEBUG
185 #ifdef DILIGENT_DEBUG
186186 void SetDebugAttribs(Uint32 MaxOffset,
187187 const D3D12_DESCRIPTOR_HEAP_TYPE dbgDescriptorHeapType,
188188 const SHADER_TYPE dbgRefShaderType)
198198 const Uint32 m_NumResources = 0;
199199
200200 private:
201 #ifdef _DEBUG
201 #ifdef DILIGENT_DEBUG
202202 D3D12_DESCRIPTOR_HEAP_TYPE m_dbgHeapType = D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
203203 SHADER_TYPE m_dbgShaderType = SHADER_TYPE_UNKNOWN;
204204 #endif
222222 void SetDescriptorHeapSpace(DescriptorHeapAllocation&& CbcSrvUavHeapSpace, DescriptorHeapAllocation&& SamplerHeapSpace)
223223 {
224224 VERIFY(m_SamplerHeapSpace.GetCpuHandle().ptr == 0 && m_CbvSrvUavHeapSpace.GetCpuHandle().ptr == 0, "Space has already been allocated in GPU descriptor heaps");
225 #ifdef _DEBUG
225 #ifdef DILIGENT_DEBUG
226226 Uint32 NumSamplerDescriptors = 0, NumSrvCbvUavDescriptors = 0;
227227 for (Uint32 rt = 0; rt < m_NumTables; ++rt)
228228 {
318318 // Returns the number of dynamic constant buffers bound in the cache regardless of their variable types
319319 Uint32 GetNumDynamicCBsBound() const { return m_NumDynamicCBsBound; }
320320
321 #ifdef _DEBUG
321 #ifdef DILIGENT_DEBUG
322322 // Only for debug purposes: indicates what types of resources are stored in the cache
323323 DbgCacheContentType DbgGetContentType() const { return m_DbgContentType; }
324324 void DbgVerifyBoundDynamicCBsCounter() const;
344344 // The number of the dynamic buffers bound in the resource cache regardless of their variable type
345345 Uint32 m_NumDynamicCBsBound = 0;
346346
347 #ifdef _DEBUG
347 #ifdef DILIGENT_DEBUG
348348 // Only for debug purposes: indicates what types of resources are stored in the cache
349349 const DbgCacheContentType m_DbgContentType;
350350 #endif
238238 const ShaderResourceLayoutD3D12& DstLayout,
239239 ShaderResourceCacheD3D12& DstCache) const;
240240
241 #ifdef DEVELOPMENT
241 #ifdef DILIGENT_DEVELOPMENT
242242 bool dvpVerifyBindings(const ShaderResourceCacheD3D12& ResourceCache) const;
243243 #endif
244244
118118 ShaderVariableD3D12Impl* m_pVariables = nullptr;
119119 Uint32 m_NumVariables = 0;
120120
121 #ifdef _DEBUG
121 #ifdef DILIGENT_DEBUG
122122 IMemoryAllocator& m_DbgAllocator;
123123 #endif
124124 // clang-format on
387387 {
388388 VERIFY(m_Desc.Usage == USAGE_DYNAMIC, "Dynamic buffer is expected");
389389 auto* pCtxD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pContext);
390 #ifdef DEVELOPMENT
390 #ifdef DILIGENT_DEVELOPMENT
391391 DvpVerifyDynamicAllocation(pCtxD3D12);
392392 #endif
393393 auto ContextId = pCtxD3D12->GetContextId();
396396 }
397397 }
398398
399 #ifdef DEVELOPMENT
399 #ifdef DILIGENT_DEVELOPMENT
400400 void BufferD3D12Impl::DvpVerifyDynamicAllocation(DeviceContextD3D12Impl* pCtx) const
401401 {
402402 auto ContextId = pCtx->GetContextId();
166166 pd3d12Resource = pBufferD3D12Impl->GetD3D12Resource();
167167 OldState = pBufferD3D12Impl->GetState();
168168
169 #ifdef DEVELOPMENT
169 #ifdef DILIGENT_DEVELOPMENT
170170 // Dynamic buffers wtih no SRV/UAV bind flags are suballocated in
171171 // the upload heap when Map() is called and must always be in
172172 // D3D12_RESOURCE_STATE_GENERIC_READ state
8080 swprintf(AllocatorName, _countof(AllocatorName), L"Cmd list allocator %ld", Atomics::AtomicIncrement(m_NumAllocators) - 1);
8181 (*ppAllocator)->SetName(AllocatorName);
8282 }
83 #ifdef DEVELOPMENT
83 #ifdef DILIGENT_DEVELOPMENT
8484 Atomics::AtomicIncrement(m_AllocatorCounter);
8585 #endif
8686 }
124124 {
125125 std::lock_guard<std::mutex> LockGuard(m_AllocatorMutex);
126126 m_FreeAllocators.emplace_back(std::move(Allocator));
127 #ifdef DEVELOPMENT
127 #ifdef DILIGENT_DEVELOPMENT
128128 Atomics::AtomicDecrement(m_AllocatorCounter);
129129 #endif
130130 }
9191 D3D12DynamicPage D3D12DynamicMemoryManager::AllocatePage(Uint64 SizeInBytes)
9292 {
9393 std::lock_guard<std::mutex> AvailablePagesLock(m_AvailablePagesMtx);
94 #ifdef DEVELOPMENT
94 #ifdef DILIGENT_DEVELOPMENT
9595 ++m_AllocatedPageCounter;
9696 #endif
9797 auto PageIt = m_AvailablePages.lower_bound(SizeInBytes); // Returns an iterator pointing to the first element that is not less than key
139139 if (Mgr != nullptr)
140140 {
141141 std::lock_guard<std::mutex> Lock{Mgr->m_AvailablePagesMtx};
142 #ifdef DEVELOPMENT
142 #ifdef DILIGENT_DEVELOPMENT
143143 --Mgr->m_AllocatedPageCounter;
144144 #endif
145145 auto PageSize = Page.GetSize();
237237 SizeInBytes,
238238 CurrPage.GetCPUAddress(AlignedOffset),
239239 CurrPage.GetGPUAddress(AlignedOffset)
240 #ifdef DEVELOPMENT
240 #ifdef DILIGENT_DEVELOPMENT
241241 , DvpCtxFrameNumber
242242 #endif
243243 };
121121
122122 m_MaxAllocatedSize = std::max(m_MaxAllocatedSize, m_FreeBlockManager.GetUsedSize());
123123
124 #ifdef DEVELOPMENT
124 #ifdef DILIGENT_DEVELOPMENT
125125 ++m_AllocationsCounter;
126126 #endif
127127
143143
144144 // Clear the allocation
145145 Allocation.Reset();
146 #ifdef DEVELOPMENT
146 #ifdef DILIGENT_DEVELOPMENT
147147 --m_AllocationsCounter;
148148 #endif
149149 }
195195 " (", std::fixed, std::setprecision(2), m_MaxSize * 100.0 / std::max(TotalDescriptors, 1u), "%).");
196196 }
197197
198 #ifdef DEVELOPMENT
198 #ifdef DILIGENT_DEVELOPMENT
199199 int32_t CPUDescriptorHeap::DvpGetTotalAllocationCount()
200200 {
201201 int32_t AllocationCount = 0;
316316 //GraphicsCtx.AddReferencedObject(pd3d12Resource);
317317
318318 bool IsDynamic = m_pIndexBuffer->GetDesc().Usage == USAGE_DYNAMIC;
319 #ifdef DEVELOPMENT
319 #ifdef DILIGENT_DEVELOPMENT
320320 if (IsDynamic)
321321 m_pIndexBuffer->DvpVerifyDynamicAllocation(this);
322322 #endif
358358 if (pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC)
359359 {
360360 DynamicBufferPresent = true;
361 #ifdef DEVELOPMENT
361 #ifdef DILIGENT_DEVELOPMENT
362362 pBufferD3D12->DvpVerifyDynamicAllocation(this);
363363 #endif
364364 }
389389
390390 void DeviceContextD3D12Impl::PrepareForDraw(GraphicsContext& GraphCtx, DRAW_FLAGS Flags)
391391 {
392 #ifdef DEVELOPMENT
392 #ifdef DILIGENT_DEVELOPMENT
393393 if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
394394 DvpVerifyRenderTargets();
395395 #endif
399399 CommitD3D12VertexBuffers(GraphCtx);
400400 }
401401
402 #ifdef DEVELOPMENT
402 #ifdef DILIGENT_DEVELOPMENT
403403 if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0)
404404 {
405405 for (Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff)
439439 }
440440 }
441441 }
442 #ifdef DEVELOPMENT
442 #ifdef DILIGENT_DEVELOPMENT
443443 else
444444 {
445445 if (m_pPipelineState->ContainsShaderResources())
457457 {
458458 CommitD3D12IndexBuffer(GraphCtx, IndexType);
459459 }
460 #ifdef DEVELOPMENT
460 #ifdef DILIGENT_DEVELOPMENT
461461 if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0)
462462 {
463463 DvpVerifyBufferState(*m_pIndexBuffer, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw (DeviceContextD3D12Impl::Draw())");
496496 DEV_CHECK_ERR(pAttribsBuffer != nullptr, "Indirect draw attribs buffer must not be null");
497497
498498 auto* pIndirectDrawAttribsD3D12 = ValidatedCast<BufferD3D12Impl>(pAttribsBuffer);
499 #ifdef DEVELOPMENT
499 #ifdef DILIGENT_DEVELOPMENT
500500 if (pIndirectDrawAttribsD3D12->GetDesc().Usage == USAGE_DYNAMIC)
501501 pIndirectDrawAttribsD3D12->DvpVerifyDynamicAllocation(this);
502502 #endif
562562 );
563563 }
564564 }
565 #ifdef DEVELOPMENT
565 #ifdef DILIGENT_DEVELOPMENT
566566 else
567567 {
568568 if (m_pPipelineState->ContainsShaderResources())
592592
593593 auto* pBufferD3D12 = ValidatedCast<BufferD3D12Impl>(pAttribsBuffer);
594594
595 #ifdef DEVELOPMENT
595 #ifdef DILIGENT_DEVELOPMENT
596596 if (pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC)
597597 pBufferD3D12->DvpVerifyDynamicAllocation(this);
598598 #endif
711711
712712 void DeviceContextD3D12Impl::FinishFrame()
713713 {
714 #ifdef _DEBUG
714 #ifdef DILIGENT_DEBUG
715715 for (const auto& MappedBuffIt : m_DbgMappedBuffers)
716716 {
717717 const auto& BuffDesc = MappedBuffIt.first->GetDesc();
13011301 {
13021302 StateTransitionRequired = TextureD3D12.IsInKnownState() && !TextureD3D12.CheckState(RESOURCE_STATE_COPY_DEST);
13031303 }
1304 #ifdef DEVELOPMENT
1304 #ifdef DILIGENT_DEVELOPMENT
13051305 else if (TextureTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
13061306 {
13071307 DvpVerifyTextureState(TextureD3D12, RESOURCE_STATE_COPY_DEST, "Using texture as copy destination (DeviceContextD3D12Impl::CopyTextureRegion)");
13361336
13371337 Footprint.Footprint.RowPitch = static_cast<UINT>(SrcStride);
13381338
1339 #ifdef _DEBUG
1339 #ifdef DILIGENT_DEBUG
13401340 {
13411341 const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format);
13421342 const Uint32 RowCount = std::max((Footprint.Footprint.Height / FmtAttribs.BlockHeight), 1u);
13871387 if (pBufferD3D12->IsInKnownState() && pBufferD3D12->GetState() != RESOURCE_STATE_GENERIC_READ)
13881388 GetCmdContext().TransitionResource(pBufferD3D12, RESOURCE_STATE_GENERIC_READ);
13891389 }
1390 #ifdef DEVELOPMENT
1390 #ifdef DILIGENT_DEVELOPMENT
13911391 else if (BufferTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
13921392 {
13931393 DvpVerifyBufferState(*pBufferD3D12, RESOURCE_STATE_COPY_SOURCE, "Using buffer as copy source (DeviceContextD3D12Impl::CopyTextureRegion)");
14461446 const auto& TexDesc = TextureD3D12.GetDesc();
14471447 auto UploadSpace = AllocateTextureUploadSpace(TexDesc.Format, DstBox);
14481448 auto UpdateRegionDepth = DstBox.MaxZ - DstBox.MinZ;
1449 #ifdef _DEBUG
1449 #ifdef DILIGENT_DEBUG
14501450 {
14511451 VERIFY(SrcStride >= UploadSpace.RowSize, "Source data stride (", SrcStride, ") is below the image row size (", UploadSpace.RowSize, ")");
14521452 const Uint32 PlaneSize = SrcStride * UploadSpace.RowCount;
17311731 auto& CmdCtx = GetCmdContext();
17321732 for (Uint32 i = 0; i < BarrierCount; ++i)
17331733 {
1734 #ifdef DEVELOPMENT
1734 #ifdef DILIGENT_DEVELOPMENT
17351735 DvpVerifyStateTransitionDesc(pResourceBarriers[i]);
17361736 #endif
17371737 CmdCtx.TransitionResource(pResourceBarriers[i]);
17491749 if (Buffer.IsInKnownState() && !Buffer.CheckState(RequiredState))
17501750 CmdCtx.TransitionResource(&Buffer, RequiredState);
17511751 }
1752 #ifdef DEVELOPMENT
1752 #ifdef DILIGENT_DEVELOPMENT
17531753 else if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
17541754 {
17551755 DvpVerifyBufferState(Buffer, RequiredState, OperationName);
17681768 if (Texture.IsInKnownState() && !Texture.CheckState(RequiredState))
17691769 CmdCtx.TransitionResource(&Texture, RequiredState);
17701770 }
1771 #ifdef DEVELOPMENT
1771 #ifdef DILIGENT_DEVELOPMENT
17721772 else if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
17731773 {
17741774 DvpVerifyTextureState(Texture, RequiredState, OperationName);
9191 m_pStaticVarManagers = ALLOCATE(ShaderVarMgrAllocator, "Raw memory for ShaderVariableManagerD3D12", ShaderVariableManagerD3D12, m_NumShaders);
9292 }
9393
94 #ifdef DEVELOPMENT
94 #ifdef DILIGENT_DEVELOPMENT
9595 {
9696 const ShaderResources* pResources[MAX_SHADERS_IN_PIPELINE] = {};
9797 for (Uint32 s = 0; s < m_NumShaders; ++s)
347347
348348 auto IsSameRootSignature = m_RootSig.IsSameAs(pPSOD3D12->m_RootSig);
349349
350 #ifdef _DEBUG
350 #ifdef DILIGENT_DEBUG
351351 {
352352 bool IsCompatibleShaders = true;
353353 if (m_NumShaders != pPSOD3D12->m_NumShaders)
386386 class CommandContext& CmdCtx,
387387 CommitAndTransitionResourcesAttribs& Attrib) const
388388 {
389 #ifdef DEVELOPMENT
389 #ifdef DILIGENT_DEVELOPMENT
390390 if (Attrib.pShaderResourceBinding == nullptr && ContainsShaderResources())
391391 {
392392 LOG_ERROR_MESSAGE("Pipeline state '", m_Desc.Name, "' requires shader resource binding object to ",
407407 return nullptr;
408408 }
409409
410 #ifdef DEVELOPMENT
410 #ifdef DILIGENT_DEVELOPMENT
411411 if (IsIncompatibleWith(pResBindingD3D12Impl->GetPipelineState()))
412412 {
413413 LOG_ERROR_MESSAGE("Shader resource binding is incompatible with the pipeline state '", m_Desc.Name, "'. Operation will be ignored.");
182182
183183 auto& HeapInfo = m_Heaps[Type];
184184 VERIFY(Index < HeapInfo.HeapSize, "Query index ", Index, " is out of range");
185 #ifdef _DEBUG
185 #ifdef DILIGENT_DEBUG
186186 for (const auto& ind : HeapInfo.AvailableQueries)
187187 {
188188 VERIFY(ind != Index, "Index ", Index, " already present in available queries list");
206206 IdleGPU();
207207 ReleaseStaleResources(true);
208208
209 #ifdef DEVELOPMENT
209 #ifdef DILIGENT_DEVELOPMENT
210210 for (auto i = 0; i < _countof(m_CPUDescriptorHeaps); ++i)
211211 {
212212 DEV_CHECK_ERR(m_CPUDescriptorHeaps[i].DvpGetTotalAllocationCount() == 0, "All CPU descriptor heap allocations must be released");
239239 {
240240 std::lock_guard<std::mutex> LockGuard(m_ContextPoolMutex);
241241 m_ContextPool.emplace_back(std::move(Ctx));
242 #ifdef DEVELOPMENT
242 #ifdef DILIGENT_DEVELOPMENT
243243 Atomics::AtomicDecrement(m_AllocatedCtxCounter);
244244 #endif
245245 }
338338 m_ContextPool.pop_back();
339339 Ctx->Reset(m_CmdListManager);
340340 Ctx->SetID(ID);
341 #ifdef DEVELOPMENT
341 #ifdef DILIGENT_DEVELOPMENT
342342 Atomics::AtomicIncrement(m_AllocatedCtxCounter);
343343 #endif
344344 return Ctx;
349349 auto* pRawMem = ALLOCATE(CmdCtxAllocator, "CommandContext instance", CommandContext, 1);
350350 auto pCtx = new (pRawMem) CommandContext(m_CmdListManager);
351351 pCtx->SetID(ID);
352 #ifdef DEVELOPMENT
352 #ifdef DILIGENT_DEVELOPMENT
353353 Atomics::AtomicIncrement(m_AllocatedCtxCounter);
354354 #endif
355355 return PooledCommandContext(pCtx, CmdCtxAllocator);
188188 {
189189 auto ShaderInd = GetShaderTypeIndex(ShaderType);
190190 auto ShaderVisibility = ShaderTypeInd2ShaderVisibilityMap[ShaderInd];
191 #ifdef _DEBUG
191 #ifdef DILIGENT_DEBUG
192192 switch (ShaderType)
193193 {
194194 // clang-format off
221221 {
222222 VERIFY_EXPR(ShaderVisibility >= D3D12_SHADER_VISIBILITY_ALL && ShaderVisibility <= D3D12_SHADER_VISIBILITY_PIXEL);
223223 auto ShaderType = ShaderVisibility2ShaderTypeMap[ShaderVisibility];
224 #ifdef _DEBUG
224 #ifdef DILIGENT_DEBUG
225225 switch (ShaderVisibility)
226226 {
227227 // clang-format off
253253 VERIFY_EXPR(RangeType >= D3D12_DESCRIPTOR_RANGE_TYPE_SRV && RangeType <= D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER);
254254 auto HeapType = RangeType2HeapTypeMap[RangeType];
255255
256 #ifdef _DEBUG
256 #ifdef DILIGENT_DEBUG
257257 switch (RangeType)
258258 {
259259 // clang-format off
366366 }
367367
368368
369 #ifdef _DEBUG
369 #ifdef DILIGENT_DEBUG
370370 void RootSignature::dbgVerifyRootParameters() const
371371 {
372372 Uint32 dbgTotalSrvCbvUavSlots = 0;
472472 ++m_TotalRootViews[RootView.GetShaderVariableType()];
473473 }
474474
475 #ifdef _DEBUG
475 #ifdef DILIGENT_DEBUG
476476 dbgVerifyRootParameters();
477477 #endif
478478
644644 auto& RootTableCache = ResourceCache.GetRootTable(RootParam.GetRootIndex());
645645
646646 SHADER_TYPE dbgShaderType = SHADER_TYPE_UNKNOWN;
647 #ifdef _DEBUG
647 #ifdef DILIGENT_DEBUG
648648 dbgShaderType = ShaderTypeFromShaderVisibility(D3D12RootParam.ShaderVisibility);
649649 #endif
650650 VERIFY_EXPR(D3D12RootParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE);
654654
655655 auto HeapType = HeapTypeFromRangeType(D3D12RootParam.DescriptorTable.pDescriptorRanges[0].RangeType);
656656
657 #ifdef _DEBUG
657 #ifdef DILIGENT_DEBUG
658658 RootTableCache.SetDebugAttribs(TableSize, HeapType, dbgShaderType);
659659 #endif
660660
678678 }
679679 }
680680
681 #ifdef _DEBUG
681 #ifdef DILIGENT_DEBUG
682682 for (Uint32 rv = 0; rv < m_RootParams.GetNumRootViews(); ++rv)
683683 {
684684 auto& RootParam = m_RootParams.GetRootView(rv);
775775 }
776776
777777
778 #ifdef DEVELOPMENT
778 #ifdef DILIGENT_DEVELOPMENT
779779 void RootSignature::DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res,
780780 D3D12_DESCRIPTOR_RANGE_TYPE RangeType)
781781 {
871871 VERIFY(Res.pObject == nullptr && Res.CPUDescriptorHandle.ptr == 0, "Bound resource is unexpected");
872872 }
873873 }
874 #endif // DEVELOPMENT
874 #endif // DILIGENT_DEVELOPMENT
875875
876876 template <class TOperation>
877877 __forceinline void RootSignature::RootParamsManager::ProcessRootTables(TOperation Operation) const
888888 VERIFY(d3d12Table.NumDescriptorRanges > 0 && RootTable.GetDescriptorTableSize() > 0, "Unexepected empty descriptor table");
889889 bool IsResourceTable = d3d12Table.pDescriptorRanges[0].RangeType != D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
890890 D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType = D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
891 #ifdef _DEBUG
891 #ifdef DILIGENT_DEBUG
892892 dbgHeapType = IsResourceTable ? D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV : D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
893893 #endif
894894 Operation(RootInd, RootTable, D3D12Param, IsResourceTable, dbgHeapType);
908908 for (UINT d = 0; d < range.NumDescriptors; ++d)
909909 {
910910 SHADER_TYPE dbgShaderType = SHADER_TYPE_UNKNOWN;
911 #ifdef _DEBUG
911 #ifdef DILIGENT_DEBUG
912912 dbgShaderType = ShaderTypeFromShaderVisibility(D3D12Param.ShaderVisibility);
913913 VERIFY(dbgHeapType == HeapTypeFromRangeType(range.RangeType), "Mistmatch between descriptor heap type and descriptor range type");
914914 #endif
10151015 {
10161016 TransitionResource(Ctx, Res, range.RangeType);
10171017 }
1018 #ifdef DEVELOPMENT
1018 #ifdef DILIGENT_DEVELOPMENT
10191019 else if (ValidateStates)
10201020 {
10211021 DvpVerifyResourceState(Res, range.RangeType);
10321032 {
10331033 pd3d12Device->CopyDescriptorsSimple(1, DynamicCbvSrvUavDescriptors.GetCpuHandle(DynamicCbvSrvUavTblOffset), Res.CPUDescriptorHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
10341034 }
1035 #ifdef DEVELOPMENT
1035 #ifdef DILIGENT_DEVELOPMENT
10361036 else
10371037 {
10381038 LOG_ERROR_MESSAGE("No valid CbvSrvUav descriptor handle found for root parameter ", RootInd, ", descriptor slot ", OffsetFromTableStart);
10491049 {
10501050 pd3d12Device->CopyDescriptorsSimple(1, DynamicSamplerDescriptors.GetCpuHandle(DynamicSamplerTblOffset), Res.CPUDescriptorHandle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
10511051 }
1052 #ifdef DEVELOPMENT
1052 #ifdef DILIGENT_DEVELOPMENT
10531053 else
10541054 {
10551055 LOG_ERROR_MESSAGE("No valid sampler descriptor handle found for root parameter ", RootInd, ", descriptor slot ", OffsetFromTableStart);
11071107 } //
11081108 );
11091109 }
1110 #ifdef DEVELOPMENT
1110 #ifdef DILIGENT_DEVELOPMENT
11111111 else if (ValidateStates)
11121112 {
11131113 ProcessCachedTableResources(
154154 }
155155
156156
157 #ifdef DEVELOPMENT
157 #ifdef DILIGENT_DEVELOPMENT
158158 void ShaderResourceBindingD3D12Impl::dvpVerifyResourceBindings(const PipelineStateD3D12Impl* pPSO) const
159159 {
160160 auto* pRefPSO = GetPipelineState<const PipelineStateD3D12Impl>();
169169 const auto& ShaderResLayout = pRefPSO->GetShaderResLayout(l);
170170 ShaderResLayout.dvpVerifyBindings(m_ShaderResourceCache);
171171 }
172 # ifdef _DEBUG
172 # ifdef DILIGENT_DEBUG
173173 m_ShaderResourceCache.DbgVerifyBoundDynamicCBsCounter();
174174 # endif
175175 }
202202 const auto& ShaderResLayout = pPSO12->GetShaderResLayout(s);
203203 auto& StaticResLayout = pPSO12->GetStaticShaderResLayout(s);
204204 auto& StaticResCache = pPSO12->GetStaticShaderResCache(s);
205 #ifdef DEVELOPMENT
205 #ifdef DILIGENT_DEVELOPMENT
206206 if (!StaticResLayout.dvpVerifyBindings(StaticResCache))
207207 {
208208 auto* pShader = pPSO12->GetShader<ShaderD3D12Impl>(s);
216216 StaticResLayout.CopyStaticResourceDesriptorHandles(StaticResCache, ShaderResLayout, m_ShaderResourceCache);
217217 }
218218
219 #ifdef _DEBUG
219 #ifdef DILIGENT_DEBUG
220220 m_ShaderResourceCache.DbgVerifyBoundDynamicCBsCounter();
221221 #endif
222222
9898 }
9999 }
100100
101 #ifdef _DEBUG
101 #ifdef DILIGENT_DEBUG
102102 void ShaderResourceCacheD3D12::DbgVerifyBoundDynamicCBsCounter() const
103103 {
104104 Uint32 NumDynamicCBsBound = 0;
292292 if (StaticSamplerInd >= 0)
293293 {
294294 // Static samplers are never copied, and SamplerId == InvalidSamplerId
295 #ifdef _DEBUG
295 #ifdef DILIGENT_DEBUG
296296 auto SamplerCount = GetTotalSamplerCount();
297297 for (Uint32 s = 0; s < SamplerCount; ++s)
298298 {
345345 } //
346346 );
347347
348 #ifdef _DEBUG
348 #ifdef DILIGENT_DEBUG
349349 for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1))
350350 {
351351 VERIFY(CurrCbvSrvUav[VarType] == CbvSrvUavCount[VarType], "Not all Srv/Cbv/Uavs are initialized, which result in a crash when dtor is called");
360360 // http://diligentgraphics.com/diligent-engine/architecture/d3d12/shader-resource-cache#Initializing-Shader-Objects
361361 VERIFY_EXPR(pRootSig == nullptr);
362362 pResourceCache->Initialize(GetRawAllocator(), _countof(StaticResCacheTblSizes), StaticResCacheTblSizes);
363 #ifdef _DEBUG
363 #ifdef DILIGENT_DEBUG
364364 pResourceCache->GetRootTable(D3D12_DESCRIPTOR_RANGE_TYPE_SRV).SetDebugAttribs(StaticResCacheTblSizes[D3D12_DESCRIPTOR_RANGE_TYPE_SRV], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_pResources->GetShaderType());
365365 pResourceCache->GetRootTable(D3D12_DESCRIPTOR_RANGE_TYPE_UAV).SetDebugAttribs(StaticResCacheTblSizes[D3D12_DESCRIPTOR_RANGE_TYPE_UAV], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_pResources->GetShaderType());
366366 pResourceCache->GetRootTable(D3D12_DESCRIPTOR_RANGE_TYPE_CBV).SetDebugAttribs(StaticResCacheTblSizes[D3D12_DESCRIPTOR_RANGE_TYPE_CBV], D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, m_pResources->GetShaderType());
381381 // We cannot use ValidatedCast<> here as the resource retrieved from the
382382 // resource mapping can be of wrong type
383383 RefCntAutoPtr<BufferD3D12Impl> pBuffD3D12(pBuffer, IID_BufferD3D12);
384 #ifdef DEVELOPMENT
384 #ifdef DILIGENT_DEVELOPMENT
385385 VerifyConstantBufferBinding(Attribs, GetVariableType(), ArrayInd, pBuffer, pBuffD3D12.RawPtr(), DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName());
386386 #endif
387387 if (pBuffD3D12)
450450 // We cannot use ValidatedCast<> here as the resource retrieved from the
451451 // resource mapping can be of wrong type
452452 RefCntAutoPtr<TResourceViewType> pViewD3D12(pView, ResourceViewTraits<TResourceViewType>::IID);
453 #ifdef DEVELOPMENT
453 #ifdef DILIGENT_DEVELOPMENT
454454 VerifyResourceViewBinding(Attribs, GetVariableType(), ArrayIndex, pView, pViewD3D12.RawPtr(), {dbgExpectedViewType}, DstRes.pObject.RawPtr(), ParentResLayout.GetShaderName());
455455 #endif
456456 if (pViewD3D12)
562562 ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(RootIndex, OffsetFromTableStart + ArrayIndex) :
563563 ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV>(RootIndex, OffsetFromTableStart + ArrayIndex);
564564
565 #ifdef _DEBUG
565 #ifdef DILIGENT_DEBUG
566566 {
567567 if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources)
568568 {
612612 auto ShdrVisibleSamplerHeapCPUDescriptorHandle = ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(Sam.RootIndex, Sam.OffsetFromTableStart + SamplerArrInd);
613613
614614 auto& DstSam = ResourceCache.GetRootTable(Sam.RootIndex).GetResource(Sam.OffsetFromTableStart + SamplerArrInd, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, ParentResLayout.m_pResources->GetShaderType());
615 #ifdef _DEBUG
615 #ifdef DILIGENT_DEBUG
616616 {
617617 if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources)
618618 {
827827 }
828828
829829
830 #ifdef DEVELOPMENT
830 #ifdef DILIGENT_DEVELOPMENT
831831 bool ShaderResourceLayoutD3D12::dvpVerifyBindings(const ShaderResourceCacheD3D12& ResourceCache) const
832832 {
833833 bool BindingsOK = true;
873873 }
874874 }
875875
876 # ifdef _DEBUG
876 # ifdef DILIGENT_DEBUG
877877 {
878878 const auto ShdrVisibleHeapCPUDescriptorHandle = ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV>(res.RootIndex, res.OffsetFromTableStart + ArrInd);
879879 if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources)
922922 BindingsOK = false;
923923 }
924924
925 # ifdef _DEBUG
925 # ifdef DILIGENT_DEBUG
926926 {
927927 const auto ShdrVisibleHeapCPUDescriptorHandle = ResourceCache.GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(SamInfo.RootIndex, SamInfo.OffsetFromTableStart + ArrInd);
928928 if (ResourceCache.DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::StaticShaderResources)
6262 // clang-format off
6363 m_Owner {Owner},
6464 m_ResourceCache {ResourceCache}
65 #ifdef _DEBUG
65 #ifdef DILIGENT_DEBUG
6666 , m_DbgAllocator {Allocator}
6767 #endif
6868 // clang-format on
126126 Name.erase(OpenBracketPos, Name.length() - OpenBracketPos);
127127 // Name == "g_tex2DDiffuse"
128128 VERIFY_EXPR(Name.length() == OpenBracketPos);
129 #ifdef _DEBUG
129 #ifdef DILIGENT_DEBUG
130130 for (const auto& ExistingRes : Resources)
131131 {
132132 VERIFY(Name.compare(ExistingRes.Name) != 0, "Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another");
127127 SamplerOrTexSRVId {_SamplerId}
128128 // clang-format on
129129 {
130 #ifdef _DEBUG
130 #ifdef DILIGENT_DEBUG
131131 // clang-format off
132132 VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range");
133133 VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range");
375375 const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
376376 Uint32 NumAllowedTypes,
377377 bool CountStaticSamplers) const noexcept;
378 #ifdef DEVELOPMENT
378 #ifdef DILIGENT_DEVELOPMENT
379379 static void DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ResourceLayout,
380380 const ShaderResources* const pShaderResources[],
381381 Uint32 NumShaders);
539539 {
540540 m_SamplerSuffix = m_ResourceNames.CopyString(CombinedSamplerSuffix);
541541
542 #ifdef DEVELOPMENT
542 #ifdef DILIGENT_DEVELOPMENT
543543 for (Uint32 n = 0; n < GetNumSamplers(); ++n)
544544 {
545545 const auto& Sampler = GetSampler(n);
9191 ID3DBlob** ppCompilerOutput)
9292 {
9393 DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
94 #if defined(DEBUG) || defined(_DEBUG)
94 #if defined(DILIGENT_DEBUG)
9595 // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
9696 // Setting this flag improves the shader debugging experience, but still allows
9797 // the shaders to be optimized and to run exactly the way they will run in
212212 return Counters;
213213 }
214214
215 #ifdef DEVELOPMENT
215 #ifdef DILIGENT_DEVELOPMENT
216216 void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ResourceLayout,
217217 const ShaderResources* const pShaderResources[],
218218 Uint32 NumShaders)
104104 Uint32 Size) :
105105 m_AllocationsMgr{Size, Allocator}
106106 {
107 #ifdef DEVELOPMENT
107 #ifdef DILIGENT_DEVELOPMENT
108108 m_MasterBlockCounter = 0;
109109 #endif
110110 }
154154 if (Mgr != nullptr)
155155 {
156156 std::lock_guard<std::mutex> Lock{Mgr->m_AllocationsMgrMtx};
157 #ifdef DEVELOPMENT
157 #ifdef DILIGENT_DEVELOPMENT
158158 --Mgr->m_MasterBlockCounter;
159159 #endif
160160 Mgr->m_AllocationsMgr.Free(std::move(Block));
173173 OffsetType GetUsedSize() const { return m_AllocationsMgr.GetUsedSize();}
174174 // clang-format on
175175
176 #ifdef DEVELOPMENT
176 #ifdef DILIGENT_DEVELOPMENT
177177 int32_t GetMasterBlockCounter() const
178178 {
179179 return m_MasterBlockCounter;
185185 {
186186 std::lock_guard<std::mutex> Lock{m_AllocationsMgrMtx};
187187 auto NewBlock = m_AllocationsMgr.Allocate(SizeInBytes, Alignment);
188 #ifdef DEVELOPMENT
188 #ifdef DILIGENT_DEVELOPMENT
189189 if (NewBlock.IsValid())
190190 {
191191 ++m_MasterBlockCounter;
198198 std::mutex m_AllocationsMgrMtx;
199199 VariableSizeAllocationsManager m_AllocationsMgr;
200200
201 #ifdef DEVELOPMENT
201 #ifdef DILIGENT_DEVELOPMENT
202202 std::atomic_int32_t m_MasterBlockCounter;
203203 #endif
204204 };
282282 // while Layout is alive
283283 void BindResources(SHADER_TYPE ShaderStage, IResourceMapping* pResourceMapping, Uint32 Flags, const GLProgramResourceCache& dbgResourceCache);
284284
285 #ifdef DEVELOPMENT
285 #ifdef DILIGENT_DEVELOPMENT
286286 bool dvpVerifyBindings(const GLProgramResourceCache& ResourceCache) const;
287287 #endif
288288
267267
268268 Uint8* m_pResourceData = nullptr;
269269
270 #ifdef _DEBUG
270 #ifdef DILIGENT_DEBUG
271271 IMemoryAllocator* m_pdbgMemoryAllocator = nullptr;
272272 #endif
273273 };
141141 LogError<true>(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__, "\nGL Error Code: ", err); \
142142 } while (false)
143143
144 #ifdef DEVELOPMENT
144 #ifdef DILIGENT_DEVELOPMENT
145145 # define DEV_CHECK_GL_ERROR CHECK_GL_ERROR
146146 #else
147147 # define DEV_CHECK_GL_ERROR(...) \
341341 void BufferGLImpl::BufferMemoryBarrier(Uint32 RequiredBarriers, GLContextState& GLContextState)
342342 {
343343 #if GL_ARB_shader_image_load_store
344 # ifdef _DEBUG
344 # ifdef DILIGENT_DEBUG
345345 {
346346 // clang-format off
347347 constexpr Uint32 BufferBarriers =
415415
416416 auto* pShaderResBindingGL = ValidatedCast<ShaderResourceBindingGLImpl>(pResBinding);
417417 const auto& ResourceCache = pShaderResBindingGL->GetResourceCache(m_pPipelineState);
418 #ifdef DEVELOPMENT
418 #ifdef DILIGENT_DEVELOPMENT
419419 m_pPipelineState->GetResourceLayout().dvpVerifyBindings(ResourceCache);
420420 #endif
421421
516516 m_BoundWritableTextures.push_back(pTextureGL);
517517 }
518518
519 # ifdef _DEBUG
519 # ifdef DILIGENT_DEBUG
520520 // Check that the texure being bound has immutable storage
521521 {
522522 m_ContextState.BindTexture(-1, pTexViewGL->GetBindTarget(), pTexViewGL->GetHandle());
654654
655655 void DeviceContextGLImpl::PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenum& GlTopology)
656656 {
657 #ifdef DEVELOPMENT
657 #ifdef DILIGENT_DEVELOPMENT
658658 if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
659659 DvpVerifyRenderTargets();
660660 #endif
185185 if (DSVDesc.Format == TEX_FORMAT_D32_FLOAT ||
186186 DSVDesc.Format == TEX_FORMAT_D16_UNORM)
187187 {
188 #ifdef _DEBUG
188 #ifdef DILIGENT_DEBUG
189189 {
190190 const auto GLTexFmt = pDepthTexGL->GetGLTexFormat();
191191 VERIFY(GLTexFmt == GL_DEPTH_COMPONENT32F || GLTexFmt == GL_DEPTH_COMPONENT16,
198198 else if (DSVDesc.Format == TEX_FORMAT_D32_FLOAT_S8X24_UINT ||
199199 DSVDesc.Format == TEX_FORMAT_D24_UNORM_S8_UINT)
200200 {
201 #ifdef _DEBUG
201 #ifdef DILIGENT_DEBUG
202202 {
203203 const auto GLTexFmt = pDepthTexGL->GetGLTexFormat();
204204 VERIFY(GLTexFmt == GL_DEPTH24_STENCIL8 || GLTexFmt == GL_DEPTH32F_STENCIL8,
206206 0, 0 //
207207 };
208208
209 #ifdef _DEBUG
209 #ifdef DILIGENT_DEBUG
210210 attribs[5] |= WGL_CONTEXT_DEBUG_BIT_ARB;
211211 #endif
212212
118118 Uint32 ImageBindingSlots = 0;
119119 Uint32 SSBOBindingSlots = 0;
120120
121 #ifdef _DEBUG
121 #ifdef DILIGENT_DEBUG
122122 const Uint32 DbgAllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
123123 #endif
124124 for (Uint32 prog = 0; prog < NumPrograms; ++prog)
255255 // We cannot use ValidatedCast<> here as the resource retrieved from the
256256 // resource mapping can be of wrong type
257257 RefCntAutoPtr<BufferGLImpl> pBuffGLImpl(pBuffer, IID_BufferGL);
258 #ifdef DEVELOPMENT
258 #ifdef DILIGENT_DEVELOPMENT
259259 {
260260 const auto& CachedUB = ResourceCache.GetConstUB(m_Attribs.Binding + ArrayIndex);
261261 VerifyConstantBufferBinding(m_Attribs, GetType(), ArrayIndex, pBuffer, pBuffGLImpl.RawPtr(), CachedUB.pBuffer.RawPtr());
282282 // We cannot use ValidatedCast<> here as the resource retrieved from the
283283 // resource mapping can be of wrong type
284284 RefCntAutoPtr<TextureViewGLImpl> pViewGL(pView, IID_TextureViewGL);
285 #ifdef DEVELOPMENT
285 #ifdef DILIGENT_DEVELOPMENT
286286 {
287287 auto& CachedTexSampler = ResourceCache.GetConstSampler(m_Attribs.Binding + ArrayIndex);
288288 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewGL.RawPtr(), {TEXTURE_VIEW_SHADER_RESOURCE}, CachedTexSampler.pView.RawPtr());
299299 // We cannot use ValidatedCast<> here as the resource retrieved from the
300300 // resource mapping can be of wrong type
301301 RefCntAutoPtr<BufferViewGLImpl> pViewGL(pView, IID_BufferViewGL);
302 #ifdef DEVELOPMENT
302 #ifdef DILIGENT_DEVELOPMENT
303303 {
304304 auto& CachedBuffSampler = ResourceCache.GetConstSampler(m_Attribs.Binding + ArrayIndex);
305305 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewGL.RawPtr(), {BUFFER_VIEW_SHADER_RESOURCE}, CachedBuffSampler.pView.RawPtr());
326326 // We cannot use ValidatedCast<> here as the resource retrieved from the
327327 // resource mapping can be of wrong type
328328 RefCntAutoPtr<TextureViewGLImpl> pViewGL(pView, IID_TextureViewGL);
329 #ifdef DEVELOPMENT
329 #ifdef DILIGENT_DEVELOPMENT
330330 {
331331 auto& CachedUAV = ResourceCache.GetConstImage(m_Attribs.Binding + ArrayIndex);
332332 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewGL.RawPtr(), {TEXTURE_VIEW_UNORDERED_ACCESS}, CachedUAV.pView.RawPtr());
339339 // We cannot use ValidatedCast<> here as the resource retrieved from the
340340 // resource mapping can be of wrong type
341341 RefCntAutoPtr<BufferViewGLImpl> pViewGL(pView, IID_BufferViewGL);
342 #ifdef DEVELOPMENT
342 #ifdef DILIGENT_DEVELOPMENT
343343 {
344344 auto& CachedUAV = ResourceCache.GetConstImage(m_Attribs.Binding + ArrayIndex);
345345 VerifyResourceViewBinding(m_Attribs, GetType(), ArrayIndex, pView, pViewGL.RawPtr(), {BUFFER_VIEW_UNORDERED_ACCESS}, CachedUAV.pView.RawPtr());
366366 // We cannot use ValidatedCast<> here as the resource retrieved from the
367367 // resource mapping can be of wrong type
368368 RefCntAutoPtr<BufferViewGLImpl> pViewGL(pView, IID_BufferViewGL);
369 #ifdef DEVELOPMENT
369 #ifdef DILIGENT_DEVELOPMENT
370370 {
371371 auto& CachedSSBO = ResourceCache.GetConstSSBO(m_Attribs.Binding + ArrayIndex);
372372 // HLSL structured buffers are mapped to SSBOs in GLSL
520520 VariableEndOffset.NumStorageBlocks - VariableStartOffset.NumStorageBlocks;
521521 // clang-format on
522522
523 #ifdef _DEBUG
523 #ifdef DILIGENT_DEBUG
524524 {
525525 Uint32 DbgNumVars = 0;
526526 auto CountVar = [&](const GLVariableBase& Var) {
720720 );
721721 }
722722
723 #ifdef DEVELOPMENT
723 #ifdef DILIGENT_DEVELOPMENT
724724 bool GLPipelineResourceLayout::dvpVerifyBindings(const GLProgramResourceCache& ResourceCache) const
725725 {
726726 # define LOG_MISSING_BINDING(VarType, BindInfo, BindPt) LOG_ERROR_MESSAGE("No resource is bound to ", VarType, " variable '", BindInfo.m_Attribs.GetPrintName(BindPt - BindInfo.m_Attribs.Binding), "'")
6161
6262 VERIFY_EXPR(BufferSize == GetRequriedMemorySize(UBCount, SamplerCount, ImageCount, SSBOCount));
6363
64 #ifdef _DEBUG
64 #ifdef DILIGENT_DEBUG
6565 m_pdbgMemoryAllocator = &MemAllocator;
6666 #endif
6767 if (BufferSize > 0)
510510 }
511511 else
512512 {
513 #ifdef _DEBUG
513 #ifdef DILIGENT_DEBUG
514514 for (const auto& ub : UniformBlocks)
515515 VERIFY(strcmp(ub.Name, Name.data()) != 0, "Uniform block with the name '", ub.Name, "' has already been enumerated");
516516 #endif
566566 }
567567 else
568568 {
569 # ifdef _DEBUG
569 # ifdef DILIGENT_DEBUG
570570 for (const auto& sb : StorageBlocks)
571571 VERIFY(strcmp(sb.Name, Name.data()) != 0, "Storage block with the name \"", sb.Name, "\" has already been enumerated");
572572 # endif
638638 FLAG_FORMAT(TEX_FORMAT_BC7_UNORM_SRGB, bBPTC );
639639 // clang-format on
640640
641 #ifdef _DEBUG
641 #ifdef DILIGENT_DEBUG
642642 bool bGL43OrAbove = DeviceCaps.DevType == RENDER_DEVICE_TYPE_GL &&
643643 (DeviceCaps.MajorVersion >= 5 || (DeviceCaps.MajorVersion == 4 && DeviceCaps.MinorVersion >= 3));
644644
8484
8585 const GLProgramResourceCache& ShaderResourceBindingGLImpl::GetResourceCache(PipelineStateGLImpl* pdbgPSO)
8686 {
87 #ifdef _DEBUG
87 #ifdef DILIGENT_DEBUG
8888 if (pdbgPSO->IsIncompatibleWith(GetPipelineState()))
8989 {
9090 LOG_ERROR("Shader resource binding is incompatible with the currently bound pipeline state.");
113113 const auto* pPSOGL = ValidatedCast<const PipelineStateGLImpl>(pPipelineState);
114114 const auto& StaticResLayout = pPSOGL->GetStaticResourceLayout();
115115
116 #ifdef DEVELOPMENT
116 #ifdef DILIGENT_DEVELOPMENT
117117 if (!StaticResLayout.dvpVerifyBindings(pPSOGL->GetStaticResourceCache()))
118118 {
119119 LOG_ERROR_MESSAGE("Static resources in SRB of PSO '", pPSOGL->GetDesc().Name,
185185 ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) &&
186186 ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight),
187187 "Compressed texture update region must be 4 pixel-aligned");
188 #ifdef _DEBUG
188 #ifdef DILIGENT_DEBUG
189189 {
190190 const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format);
191191 auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize};
207207 ((DstBox.MaxX % 4) == 0 || DstBox.MaxX == MipWidth) &&
208208 ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight),
209209 "Compressed texture update region must be 4 pixel-aligned");
210 #ifdef _DEBUG
210 #ifdef DILIGENT_DEBUG
211211 {
212212 const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format);
213213 auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize};
516516 }
517517
518518 auto* pRenderDeviceGL = ValidatedCast<RenderDeviceGLImpl>(GetDevice());
519 #ifdef _DEBUG
519 #ifdef DILIGENT_DEBUG
520520 {
521521 auto& TexViewObjAllocator = pRenderDeviceGL->GetTexViewObjAllocator();
522522 VERIFY(&TexViewObjAllocator == &m_dbgTexViewObjAllocator, "Texture view allocator does not match allocator provided during texture initialization");
581581 void TextureBaseGL::TextureMemoryBarrier(Uint32 RequiredBarriers, GLContextState& GLContextState)
582582 {
583583 #if GL_ARB_shader_image_load_store
584 # ifdef _DEBUG
584 # ifdef DILIGENT_DEBUG
585585 {
586586 // clang-format off
587587 constexpr Uint32 TextureBarriers =
602602
603603 void TextureBaseGL::SetDefaultGLParameters()
604604 {
605 #ifdef _DEBUG
606 GLint BoundTex;
607 GLint TextureBinding = 0;
608 switch (m_BindTarget)
609 {
610 // clang-format off
611 case GL_TEXTURE_1D: TextureBinding = GL_TEXTURE_BINDING_1D; break;
612 case GL_TEXTURE_1D_ARRAY: TextureBinding = GL_TEXTURE_BINDING_1D_ARRAY; break;
613 case GL_TEXTURE_2D: TextureBinding = GL_TEXTURE_BINDING_2D; break;
614 case GL_TEXTURE_2D_ARRAY: TextureBinding = GL_TEXTURE_BINDING_2D_ARRAY; break;
615 case GL_TEXTURE_2D_MULTISAMPLE: TextureBinding = GL_TEXTURE_BINDING_2D_MULTISAMPLE; break;
616 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: TextureBinding = GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY; break;
617 case GL_TEXTURE_3D: TextureBinding = GL_TEXTURE_BINDING_3D; break;
618 case GL_TEXTURE_CUBE_MAP: TextureBinding = GL_TEXTURE_BINDING_CUBE_MAP; break;
619 case GL_TEXTURE_CUBE_MAP_ARRAY: TextureBinding = GL_TEXTURE_BINDING_CUBE_MAP_ARRAY; break;
620 default: UNEXPECTED("Unknown bind target");
621 // clang-format on
622 }
623 glGetIntegerv(TextureBinding, &BoundTex);
624 CHECK_GL_ERROR("Failed to set GL_TEXTURE_MIN_FILTER texture parameter");
625 VERIFY(static_cast<GLuint>(BoundTex) == m_GlTexture, "Current texture is not bound to GL context");
605 #ifdef DILIGENT_DEBUG
606 {
607 GLint BoundTex;
608 GLint TextureBinding = 0;
609 switch (m_BindTarget)
610 {
611 // clang-format off
612 case GL_TEXTURE_1D: TextureBinding = GL_TEXTURE_BINDING_1D; break;
613 case GL_TEXTURE_1D_ARRAY: TextureBinding = GL_TEXTURE_BINDING_1D_ARRAY; break;
614 case GL_TEXTURE_2D: TextureBinding = GL_TEXTURE_BINDING_2D; break;
615 case GL_TEXTURE_2D_ARRAY: TextureBinding = GL_TEXTURE_BINDING_2D_ARRAY; break;
616 case GL_TEXTURE_2D_MULTISAMPLE: TextureBinding = GL_TEXTURE_BINDING_2D_MULTISAMPLE; break;
617 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: TextureBinding = GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY; break;
618 case GL_TEXTURE_3D: TextureBinding = GL_TEXTURE_BINDING_3D; break;
619 case GL_TEXTURE_CUBE_MAP: TextureBinding = GL_TEXTURE_BINDING_CUBE_MAP; break;
620 case GL_TEXTURE_CUBE_MAP_ARRAY: TextureBinding = GL_TEXTURE_BINDING_CUBE_MAP_ARRAY; break;
621 default: UNEXPECTED("Unknown bind target");
622 // clang-format on
623 }
624 glGetIntegerv(TextureBinding, &BoundTex);
625 CHECK_GL_ERROR("Failed to set GL_TEXTURE_MIN_FILTER texture parameter");
626 VERIFY(static_cast<GLuint>(BoundTex) == m_GlTexture, "Current texture is not bound to GL context");
627 }
626628 #endif
627629
628630 if (m_BindTarget != GL_TEXTURE_2D_MULTISAMPLE &&
175175 ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight),
176176 "Compressed texture update region must be 4 pixel-aligned");
177177 // clang-format on
178 #ifdef _DEBUG
178 #ifdef DILIGENT_DEBUG
179179 {
180180 const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format);
181181 auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize};
192192 ((DstBox.MaxY % 4) == 0 || DstBox.MaxY == MipHeight),
193193 "Compressed texture update region must be 4 pixel-aligned" );
194194 // clang-format on
195 #ifdef _DEBUG
195 #ifdef DILIGENT_DEBUG
196196 {
197197 const auto& FmtAttribs = GetTextureFormatAttribs(m_Desc.Format);
198198 auto BlockBytesInRow = ((DstBox.MaxX - DstBox.MinX + 3) / 4) * Uint32{FmtAttribs.ComponentSize};
6767
6868 virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override;
6969
70 #ifdef DEVELOPMENT
70 #ifdef DILIGENT_DEVELOPMENT
7171 void DvpVerifyDynamicAllocation(DeviceContextVkImpl* pCtx) const;
7272 #endif
7373
8181 {
8282 VERIFY(m_Desc.Usage == USAGE_DYNAMIC, "Dynamic buffer is expected");
8383 VERIFY_EXPR(!m_DynamicAllocations.empty());
84 #ifdef DEVELOPMENT
84 #ifdef DILIGENT_DEVELOPMENT
8585 DvpVerifyDynamicAllocation(pCtx);
8686 #endif
8787 auto& DynAlloc = m_DynamicAllocations[CtxId];
6161
6262 void DestroyPools();
6363
64 #ifdef DEVELOPMENT
64 #ifdef DILIGENT_DEVELOPMENT
6565 int32_t GetAllocatedPoolCount() const
6666 {
6767 return m_AllocatedPoolCounter;
8080 std::mutex m_Mutex;
8181 std::deque<VulkanUtilities::CommandPoolWrapper, STDAllocatorRawMem<VulkanUtilities::CommandPoolWrapper>> m_CmdPools;
8282
83 #ifdef DEVELOPMENT
83 #ifdef DILIGENT_DEVELOPMENT
8484 std::atomic_int32_t m_AllocatedPoolCounter;
8585 #endif
8686 };
143143 m_MaxSets {MaxSets },
144144 m_AllowFreeing{AllowFreeing }
145145 {
146 #ifdef DEVELOPMENT
146 #ifdef DILIGENT_DEVELOPMENT
147147 m_AllocatedPoolCounter = 0;
148148 #endif
149149 }
161161
162162 RenderDeviceVkImpl& GetDeviceVkImpl() { return m_DeviceVkImpl; }
163163
164 #ifdef DEVELOPMENT
164 #ifdef DILIGENT_DEVELOPMENT
165165 int32_t GetAllocatedPoolCounter() const
166166 {
167167 return m_AllocatedPoolCounter;
184184 private:
185185 void FreePool(VulkanUtilities::DescriptorPoolWrapper&& Pool);
186186
187 #ifdef DEVELOPMENT
187 #ifdef DILIGENT_DEVELOPMENT
188188 std::atomic_int32_t m_AllocatedPoolCounter;
189189 #endif
190190 };
212212 }
213213 // clang-format on
214214 {
215 #ifdef DEVELOPMENT
215 #ifdef DILIGENT_DEVELOPMENT
216216 m_AllocatedSetCounter = 0;
217217 #endif
218218 }
221221
222222 DescriptorSetAllocation Allocate(Uint64 CommandQueueMask, VkDescriptorSetLayout SetLayout, const char* DebugName = "");
223223
224 #ifdef DEVELOPMENT
224 #ifdef DILIGENT_DEVELOPMENT
225225 int32_t GetAllocatedDescriptorSetCounter() const
226226 {
227227 return m_AllocatedSetCounter;
231231 private:
232232 void FreeDescriptorSet(VkDescriptorSet Set, VkDescriptorPool Pool, Uint64 QueueMask);
233233
234 #ifdef DEVELOPMENT
234 #ifdef DILIGENT_DEVELOPMENT
235235 std::atomic_int32_t m_AllocatedSetCounter;
236236 #endif
237237 };
101101 Uint32 DynamicOffsetCount = 0;
102102 bool DynamicBuffersPresent = false;
103103 bool DynamicDescriptorsBound = false;
104 #ifdef _DEBUG
104 #ifdef DILIGENT_DEBUG
105105 const PipelineLayout* pDbgPipelineLayout = nullptr;
106106 #endif
107107 DescriptorSetBindInfo() :
121121 DynamicBuffersPresent = false;
122122 DynamicDescriptorsBound = false;
123123
124 #ifdef _DEBUG
124 #ifdef DILIGENT_DEBUG
125125 // In release mode, do not clear vectors as this causes unnecessary work
126126 vkSets.clear();
127127 DynamicOffsets.clear();
234234 VERIFY(BindInfo.DynamicOffsetCount > 0, "This function should only be called for pipelines that contain dynamic descriptors");
235235
236236 VERIFY_EXPR(BindInfo.pResourceCache != nullptr);
237 #ifdef _DEBUG
237 #ifdef DILIGENT_DEBUG
238238 Uint32 TotalDynamicDescriptors = 0;
239239 for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE; VarType <= SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1))
240240 {
7575
7676 // clang-format off
7777 ShaderResourceCacheVk(DbgCacheContentType dbgContentType)
78 #ifdef _DEBUG
78 #ifdef DILIGENT_DEBUG
7979 : m_DbgContentType{dbgContentType}
8080 #endif
8181 {
185185
186186 Uint16& GetDynamicBuffersCounter() { return m_NumDynamicBuffers; }
187187
188 #ifdef _DEBUG
188 #ifdef DILIGENT_DEBUG
189189 // Only for debug purposes: indicates what types of resources are stored in the cache
190190 DbgCacheContentType DbgGetContentType() const { return m_DbgContentType; }
191191 void DbgVerifyResourceInitialization() const;
214214 Uint16 m_NumDynamicBuffers = 0;
215215 Uint32 m_TotalResources = 0;
216216
217 #ifdef _DEBUG
217 #ifdef DILIGENT_DEBUG
218218 // Only for debug purposes: indicates what types of resources are stored in the cache
219219 const DbgCacheContentType m_DbgContentType;
220220 // Debug array that stores flags indicating if resources in the cache have been initialized
268268 ++res;
269269 }
270270
271 #ifdef _DEBUG
271 #ifdef DILIGENT_DEBUG
272272 for (; res < DescrSet.GetSize(); ++res)
273273 {
274274 const auto& Res = DescrSet.GetResource(res);
269269 const ShaderResourceCacheVk& SrcResourceCache,
270270 ShaderResourceCacheVk& DstResourceCache) const;
271271
272 #ifdef DEVELOPMENT
272 #ifdef DILIGENT_DEVELOPMENT
273273 bool dvpVerifyBindings(const ShaderResourceCacheVk& ResourceCache) const;
274274 static void dvpVerifyResourceLayoutDesc(Uint32 NumShaders,
275275 const std::shared_ptr<const SPIRVShaderResources> pShaderResources[],
113113 ShaderVariableVkImpl* m_pVariables = nullptr;
114114 Uint32 m_NumVariables = 0;
115115
116 #ifdef _DEBUG
116 #ifdef DILIGENT_DEBUG
117117 IMemoryAllocator& m_DbgAllocator;
118118 #endif
119119 };
6464 pDynamicMemMgr{rhs.pDynamicMemMgr},
6565 AlignedOffset {rhs.AlignedOffset },
6666 Size {rhs.Size }
67 #ifdef DEVELOPMENT
67 #ifdef DILIGENT_DEVELOPMENT
6868 , dvpFrameNumber{rhs.dvpFrameNumber}
6969 #endif
7070 {
7171 rhs.pDynamicMemMgr = nullptr;
7272 rhs.AlignedOffset = 0;
7373 rhs.Size = 0;
74 #ifdef DEVELOPMENT
74 #ifdef DILIGENT_DEVELOPMENT
7575 rhs.dvpFrameNumber = 0;
7676 #endif
7777 }
8585 rhs.pDynamicMemMgr = nullptr;
8686 rhs.AlignedOffset = 0;
8787 rhs.Size = 0;
88 #ifdef DEVELOPMENT
88 #ifdef DILIGENT_DEVELOPMENT
8989 dvpFrameNumber = rhs.dvpFrameNumber;
9090 rhs.dvpFrameNumber = 0;
9191 #endif
9595 VulkanDynamicMemoryManager* pDynamicMemMgr = nullptr;
9696 size_t AlignedOffset = 0; // Offset from the start of the buffer
9797 size_t Size = 0; // Reserved size of this allocation
98 #ifdef DEVELOPMENT
98 #ifdef DILIGENT_DEVELOPMENT
9999 Int64 dvpFrameNumber = 0;
100100 #endif
101101 };
5959
6060 CommandPoolWrapper&& Release();
6161
62 #ifdef DEVELOPMENT
62 #ifdef DILIGENT_DEVELOPMENT
6363 int32_t DvpGetBufferCounter() const
6464 {
6565 return m_BuffCounter;
7373
7474 std::mutex m_Mutex;
7575 std::deque<VkCommandBuffer> m_CmdBuffers;
76 #ifdef DEVELOPMENT
76 #ifdef DILIGENT_DEVELOPMENT
7777 std::atomic_int32_t m_BuffCounter;
7878 #endif
7979 };
159159 RESOURCE_STATE_INDIRECT_ARGUMENT);
160160 SetState(State);
161161
162 #ifdef _DEBUG
162 #ifdef DILIGENT_DEBUG
163163 {
164164 VkAccessFlags AccessFlags =
165165 VK_ACCESS_INDIRECT_COMMAND_READ_BIT |
404404 return ResourceStateFlagsToVkAccessFlags(GetState());
405405 }
406406
407 #ifdef DEVELOPMENT
407 #ifdef DILIGENT_DEVELOPMENT
408408 void BufferVkImpl::DvpVerifyDynamicAllocation(DeviceContextVkImpl* pCtx) const
409409 {
410410 auto ContextId = pCtx->GetContextId();
4343 m_CmdPools (STD_ALLOCATOR_RAW_MEM(VulkanUtilities::CommandPoolWrapper, GetRawAllocator(), "Allocator for deque<VulkanUtilities::CommandPoolWrapper>"))
4444 // clang-format on
4545 {
46 #ifdef DEVELOPMENT
46 #ifdef DILIGENT_DEVELOPMENT
4747 m_AllocatedPoolCounter = 0;
4848 #endif
4949 }
7575
7676 LogicalDevice.ResetCommandPool(CmdPool);
7777
78 #ifdef DEVELOPMENT
78 #ifdef DILIGENT_DEVELOPMENT
7979 ++m_AllocatedPoolCounter;
8080 #endif
8181 return std::move(CmdPool);
129129 void CommandPoolManager::FreeCommandPool(VulkanUtilities::CommandPoolWrapper&& CmdPool)
130130 {
131131 std::lock_guard<std::mutex> LockGuard(m_Mutex);
132 #ifdef DEVELOPMENT
132 #ifdef DILIGENT_DEVELOPMENT
133133 --m_AllocatedPoolCounter;
134134 #endif
135135 m_CmdPools.emplace_back(std::move(CmdPool));
6767 VulkanUtilities::DescriptorPoolWrapper DescriptorPoolManager::GetPool(const char* DebugName)
6868 {
6969 std::lock_guard<std::mutex> Lock{m_Mutex};
70 #ifdef DEVELOPMENT
70 #ifdef DILIGENT_DEVELOPMENT
7171 ++m_AllocatedPoolCounter;
7272 #endif
7373 if (m_Pools.empty())
127127 std::lock_guard<std::mutex> Lock{m_Mutex};
128128 m_DeviceVkImpl.GetLogicalDevice().ResetDescriptorPool(Pool);
129129 m_Pools.emplace_back(std::move(Pool));
130 #ifdef DEVELOPMENT
130 #ifdef DILIGENT_DEVELOPMENT
131131 --m_AllocatedPoolCounter;
132132 #endif
133133 }
176176 std::swap(*it, m_Pools.front());
177177 }
178178
179 #ifdef DEVELOPMENT
179 #ifdef DILIGENT_DEVELOPMENT
180180 ++m_AllocatedSetCounter;
181181 #endif
182182 return {Set, Pool, CommandQueueMask, *this};
191191 auto Set = AllocateDescriptorSet(LogicalDevice, NewPool, SetLayout, DebugName);
192192 DEV_CHECK_ERR(Set != VK_NULL_HANDLE, "Failed to allocate descriptor set");
193193
194 #ifdef DEVELOPMENT
194 #ifdef DILIGENT_DEVELOPMENT
195195 ++m_AllocatedSetCounter;
196196 #endif
197197
233233 {
234234 std::lock_guard<std::mutex> Lock{Allocator->m_Mutex};
235235 Allocator->m_DeviceVkImpl.GetLogicalDevice().FreeDescriptorSet(Pool, Set);
236 #ifdef DEVELOPMENT
236 #ifdef DILIGENT_DEVELOPMENT
237237 --Allocator->m_AllocatedSetCounter;
238238 #endif
239239 }
326326
327327 void DeviceContextVkImpl::CommitVkVertexBuffers()
328328 {
329 #ifdef DEVELOPMENT
329 #ifdef DILIGENT_DEVELOPMENT
330330 if (m_NumVertexStreams < m_pPipelineState->GetNumBufferSlotsUsed())
331331 LOG_ERROR("Currently bound pipeline state '", m_pPipelineState->GetDesc().Name, "' expects ", m_pPipelineState->GetNumBufferSlotsUsed(), " input buffer slots, but only ", m_NumVertexStreams, " is bound");
332332 #endif
343343 if (pBufferVk->GetDesc().Usage == USAGE_DYNAMIC)
344344 {
345345 DynamicBufferPresent = true;
346 #ifdef DEVELOPMENT
346 #ifdef DILIGENT_DEVELOPMENT
347347 pBufferVk->DvpVerifyDynamicAllocation(this);
348348 #endif
349349 }
413413
414414 void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags)
415415 {
416 #ifdef DEVELOPMENT
416 #ifdef DILIGENT_DEVELOPMENT
417417 if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
418418 DvpVerifyRenderTargets();
419419 #endif
425425 CommitVkVertexBuffers();
426426 }
427427
428 #ifdef DEVELOPMENT
428 #ifdef DILIGENT_DEVELOPMENT
429429 if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0)
430430 {
431431 for (Uint32 slot = 0; slot < m_NumVertexStreams; ++slot)
450450 }
451451 }
452452 #if 0
453 # ifdef _DEBUG
453 # ifdef DILIGENT_DEBUG
454454 else
455455 {
456456 if ( m_pPipelineState->dbgContainsShaderResources() )
459459 # endif
460460 #endif
461461
462 #ifdef DEVELOPMENT
462 #ifdef DILIGENT_DEVELOPMENT
463463 if (m_pPipelineState->GetVkRenderPass() != m_RenderPass)
464464 {
465465 DvpLogRenderPass_PSOMismatch();
474474 DEV_CHECK_ERR(pAttribsBuffer, "Indirect draw attribs buffer must not be null");
475475 auto* pIndirectDrawAttribsVk = ValidatedCast<BufferVkImpl>(pAttribsBuffer);
476476
477 #ifdef DEVELOPMENT
477 #ifdef DILIGENT_DEVELOPMENT
478478 if (pIndirectDrawAttribsVk->GetDesc().Usage == USAGE_DYNAMIC)
479479 pIndirectDrawAttribsVk->DvpVerifyDynamicAllocation(this);
480480 #endif
489489 {
490490 PrepareForDraw(Flags);
491491
492 #ifdef DEVELOPMENT
492 #ifdef DILIGENT_DEVELOPMENT
493493 if ((Flags & DRAW_FLAG_VERIFY_STATES) != 0)
494494 {
495495 DvpVerifyBufferState(*m_pIndexBuffer, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw call (DeviceContextVkImpl::Draw)");
569569 }
570570 }
571571 #if 0
572 # ifdef _DEBUG
572 # ifdef DILIGENT_DEBUG
573573 else
574574 {
575575 if ( m_pPipelineState->dbgContainsShaderResources() )
598598
599599 auto* pBufferVk = ValidatedCast<BufferVkImpl>(pAttribsBuffer);
600600
601 #ifdef DEVELOPMENT
601 #ifdef DILIGENT_DEVELOPMENT
602602 if (pBufferVk->GetDesc().Usage == USAGE_DYNAMIC)
603603 pBufferVk->DvpVerifyDynamicAllocation(this);
604604 #endif
802802
803803 void DeviceContextVkImpl::FinishFrame()
804804 {
805 #ifdef _DEBUG
805 #ifdef DILIGENT_DEBUG
806806 for (const auto& MappedBuffIt : m_DbgMappedBuffers)
807807 {
808808 const auto& BuffDesc = MappedBuffIt.first->GetDesc();
11061106 if (m_Framebuffer != VK_NULL_HANDLE)
11071107 {
11081108 VERIFY_EXPR(m_RenderPass != VK_NULL_HANDLE);
1109 #ifdef DEVELOPMENT
1109 #ifdef DILIGENT_DEVELOPMENT
11101110 if (VerifyStates)
11111111 {
11121112 TransitionRenderTargets(RESOURCE_STATE_TRANSITION_MODE_VERIFY);
11961196 Uint64 SrcOffset,
11971197 RESOURCE_STATE_TRANSITION_MODE TransitionMode)
11981198 {
1199 #ifdef DEVELOPMENT
1199 #ifdef DILIGENT_DEVELOPMENT
12001200 if (DstOffset + NumBytes > pBuffVk->GetDesc().uiSizeInBytes)
12011201 {
12021202 LOG_ERROR("Update region is out of buffer bounds which will result in an undefined behavior");
12271227 // be resource barrier issues in the cmd list in the device context
12281228 auto* pBuffVk = ValidatedCast<BufferVkImpl>(pBuffer);
12291229
1230 #ifdef DEVELOPMENT
1230 #ifdef DILIGENT_DEVELOPMENT
12311231 if (pBuffVk->GetDesc().Usage == USAGE_DYNAMIC)
12321232 {
12331233 LOG_ERROR("Dynamic buffers must be updated via Map()");
12571257 auto* pSrcBuffVk = ValidatedCast<BufferVkImpl>(pSrcBuffer);
12581258 auto* pDstBuffVk = ValidatedCast<BufferVkImpl>(pDstBuffer);
12591259
1260 #ifdef DEVELOPMENT
1260 #ifdef DILIGENT_DEVELOPMENT
12611261 if (pDstBuffVk->GetDesc().Usage == USAGE_DYNAMIC)
12621262 {
12631263 LOG_ERROR("Dynamic buffers cannot be copy destinations");
16331633 // pages will be discarded
16341634 VERIFY((Allocation.AlignedOffset % BufferOffsetAlignment) == 0, "Allocation offset must be at least 32-bit algined");
16351635
1636 #ifdef _DEBUG
1636 #ifdef DILIGENT_DEBUG
16371637 {
16381638 VERIFY(SrcStride >= CopyInfo.RowSize, "Source data stride (", SrcStride, ") is below the image row size (", CopyInfo.RowSize, ")");
16391639 const Uint32 PlaneSize = SrcStride * CopyInfo.RowCount;
22042204 VERIFY_EXPR(Texture.GetLayout() == ExpectedLayout);
22052205 }
22062206 }
2207 #ifdef DEVELOPMENT
2207 #ifdef DILIGENT_DEVELOPMENT
22082208 else if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
22092209 {
22102210 DvpVerifyTextureState(Texture, RequiredState, OperationName);
23002300 VERIFY_EXPR(Buffer.CheckAccessFlags(ExpectedAccessFlags));
23012301 }
23022302 }
2303 #ifdef DEVELOPMENT
2303 #ifdef DILIGENT_DEVELOPMENT
23042304 else if (TransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
23052305 {
23062306 DvpVerifyBufferState(Buffer, RequiredState, OperationName);
23112311 VulkanDynamicAllocation DeviceContextVkImpl::AllocateDynamicSpace(Uint32 SizeInBytes, Uint32 Alignment)
23122312 {
23132313 auto DynAlloc = m_DynamicHeap.Allocate(SizeInBytes, Alignment);
2314 #ifdef DEVELOPMENT
2314 #ifdef DILIGENT_DEVELOPMENT
23152315 DynAlloc.dvpFrameNumber = m_ContextFrameNumber;
23162316 #endif
23172317 return DynAlloc;
23272327 for (Uint32 i = 0; i < BarrierCount; ++i)
23282328 {
23292329 const auto& Barrier = pResourceBarriers[i];
2330 #ifdef DEVELOPMENT
2330 #ifdef DILIGENT_DEVELOPMENT
23312331 DvpVerifyStateTransitionDesc(Barrier);
23322332 #endif
23332333 if (Barrier.TransitionType == STATE_TRANSITION_TYPE_BEGIN)
145145 }
146146 VERIFY_EXPR(((NumBindings & (NumBindings - 1)) == 0) && NumBindings == MemSize || NumBindings < MemSize);
147147
148 #ifdef _DEBUG
148 #ifdef DILIGENT_DEBUG
149149 static constexpr size_t MinMemSize = 1;
150150 #else
151151 static constexpr size_t MinMemSize = 16;
441441 if (StaticAndMutSet.SetIndex >= 0)
442442 {
443443 const char* DescrSetName = "Static/Mutable Descriptor Set";
444 #ifdef DEVELOPMENT
444 #ifdef DILIGENT_DEVELOPMENT
445445 std::string _DescrSetName(DbgPipelineName);
446446 _DescrSetName.append(" - static/mutable set");
447447 DescrSetName = _DescrSetName.c_str();
457457 DescriptorSetBindInfo& BindInfo,
458458 VkDescriptorSet VkDynamicDescrSet) const
459459 {
460 #ifdef _DEBUG
460 #ifdef DILIGENT_DEBUG
461461 BindInfo.vkSets.clear();
462462 #endif
463463
490490 TotalDynamicDescriptors += Set.NumDynamicDescriptors;
491491 }
492492
493 #ifdef _DEBUG
493 #ifdef DILIGENT_DEBUG
494494 for (const auto& set : BindInfo.vkSets)
495495 VERIFY(set != VK_NULL_HANDLE, "Descriptor set must not be null");
496496 #endif
500500 BindInfo.DynamicOffsets.resize(TotalDynamicDescriptors);
501501 BindInfo.BindPoint = IsCompute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS;
502502 BindInfo.pResourceCache = &ResourceCache;
503 #ifdef _DEBUG
503 #ifdef DILIGENT_DEBUG
504504 BindInfo.pDbgPipelineLayout = this;
505505 #endif
506506 BindInfo.DynamicBuffersPresent = ResourceCache.GetNumDynamicBuffers() > 0;
270270
271271 PipelineCI.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
272272 PipelineCI.pNext = nullptr;
273 #ifdef _DEBUG
273 #ifdef DILIGENT_DEBUG
274274 PipelineCI.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
275275 #endif
276276 PipelineCI.basePipelineHandle = VK_NULL_HANDLE; // a pipeline to derive from
298298
299299 PipelineCI.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
300300 PipelineCI.pNext = nullptr;
301 #ifdef _DEBUG
301 #ifdef DILIGENT_DEBUG
302302 PipelineCI.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
303303 #endif
304304
511511
512512 auto IsSamePipelineLayout = m_PipelineLayout.IsSameAs(pPSOVk->m_PipelineLayout);
513513
514 #ifdef _DEBUG
514 #ifdef DILIGENT_DEBUG
515515 {
516516 bool IsCompatibleShaders = true;
517517 if (m_NumShaders != pPSOVk->m_NumShaders)
558558 if (!m_HasStaticResources && !m_HasNonStaticResources)
559559 return;
560560
561 #ifdef DEVELOPMENT
561 #ifdef DILIGENT_DEVELOPMENT
562562 if (pShaderResourceBinding == nullptr)
563563 {
564564 LOG_ERROR_MESSAGE("Pipeline state '", m_Desc.Name, "' requires shader resource binding object to ",
569569
570570 auto* pResBindingVkImpl = ValidatedCast<ShaderResourceBindingVkImpl>(pShaderResourceBinding);
571571
572 #ifdef DEVELOPMENT
572 #ifdef DILIGENT_DEVELOPMENT
573573 {
574574 auto* pRefPSO = pResBindingVkImpl->GetPipelineState();
575575 if (IsIncompatibleWith(pRefPSO))
587587
588588 auto& ResourceCache = pResBindingVkImpl->GetResourceCache();
589589
590 #ifdef DEVELOPMENT
590 #ifdef DILIGENT_DEVELOPMENT
591591 for (Uint32 s = 0; s < m_NumShaders; ++s)
592592 {
593593 m_ShaderResourceLayouts[s].dvpVerifyBindings(ResourceCache);
594594 }
595595 #endif
596 #ifdef _DEBUG
596 #ifdef DILIGENT_DEBUG
597597 ResourceCache.DbgVerifyDynamicBuffersCounter();
598598 #endif
599599
601601 {
602602 ResourceCache.TransitionResources<false>(pCtxVkImpl);
603603 }
604 #ifdef DEVELOPMENT
604 #ifdef DILIGENT_DEVELOPMENT
605605 else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY)
606606 {
607607 ResourceCache.TransitionResources<true>(pCtxVkImpl);
615615 if (DynamicDescriptorSetVkLayout != VK_NULL_HANDLE)
616616 {
617617 const char* DynamicDescrSetName = "Dynamic Descriptor Set";
618 #ifdef DEVELOPMENT
618 #ifdef DILIGENT_DEVELOPMENT
619619 std::string _DynamicDescrSetName(m_Desc.Name);
620620 _DynamicDescrSetName.append(" - dynamic set");
621621 DynamicDescrSetName = _DynamicDescrSetName.c_str();
688688 {
689689 const auto& StaticResLayout = GetStaticShaderResLayout(s);
690690 const auto& StaticResCache = GetStaticResCache(s);
691 #ifdef DEVELOPMENT
691 #ifdef DILIGENT_DEVELOPMENT
692692 if (!StaticResLayout.dvpVerifyBindings(StaticResCache))
693693 {
694694 const auto* pShaderVk = GetShader<const ShaderVkImpl>(s);
702702 const auto& ShaderResourceLayouts = GetShaderResLayout(s);
703703 ShaderResourceLayouts.InitializeStaticResources(StaticResLayout, StaticResCache, ResourceCache);
704704 }
705 #ifdef _DEBUG
705 #ifdef DILIGENT_DEBUG
706706 ResourceCache.DbgVerifyDynamicBuffersCounter();
707707 #endif
708708 }
185185
186186 auto& HeapInfo = m_Heaps[Type];
187187 VERIFY(Index < HeapInfo.PoolSize, "Query index ", Index, " is out of range");
188 #ifdef _DEBUG
188 #ifdef DILIGENT_DEBUG
189189 for (const auto& ind : HeapInfo.AvailableQueries)
190190 {
191191 VERIFY(ind != Index, "Index ", Index, " already present in available queries list");
5858 SamplerCI.addressModeW = AddressModeToVkAddressMode(m_Desc.AddressW);
5959 SamplerCI.mipLodBias = m_Desc.MipLODBias;
6060 SamplerCI.anisotropyEnable = IsAnisotropicFilter(m_Desc.MinFilter);
61 #ifdef DEVELOPMENT
61 #ifdef DILIGENT_DEVELOPMENT
6262 if (!((SamplerCI.anisotropyEnable && IsAnisotropicFilter(m_Desc.MagFilter)) ||
6363 (!SamplerCI.anisotropyEnable && !IsAnisotropicFilter(m_Desc.MagFilter))))
6464 {
6868
6969