DiligentCore icon indicating copy to clipboard operation
DiligentCore copied to clipboard

Move dynamic allocations to device context

Open TheMostDiligent opened this issue 2 years ago • 0 comments

At the moment, each USAGE_DYNAMIC buffer internally keeps dynamic allocations for each device context. This is inefficient from multiple points of view:

  • Allocations may never be needed if the buffer is not mapped
  • Allocations are only temporary and only needed for the time while buffer is mapped, yet they are allocated permanently
  • Allocations are aligned up to the cache line size, which further increases memory consumption

The last point also creates UB sanitizer errors such as this one:

git/DiligentEngine/DiligentCore/Common/interface/STDAllocator.hpp:148:19: runtime error: constructor call on misaligned address 0x000173672da0 for type 'Diligent::BufferVkImpl::CtxDynamicData', which requires 64 byte alignment
0x000173672da0: note: pointer points here
 00 00 00 00  be be be be be be be be  be be be be be be be be  be be be be be be be be  be be be be

The solution is to keep dynamic allocations in the context directly. This requires using fast hash map as with std::unordered_map, the performance is unacceptable

TheMostDiligent avatar Jul 25 '23 00:07 TheMostDiligent