StackGpuMemoryPool.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/Common.h>
  7. #include <AnKi/Util/StackAllocatorBuilder.h>
  8. namespace anki {
  9. /// @addtogroup graphics
  10. /// @{
  11. /// Stack memory pool for GPU usage.
  12. class StackGpuMemoryPool
  13. {
  14. public:
  15. StackGpuMemoryPool() = default;
  16. StackGpuMemoryPool(const StackGpuMemoryPool&) = delete; // Non-copyable
  17. ~StackGpuMemoryPool();
  18. StackGpuMemoryPool& operator=(const StackGpuMemoryPool&) = delete; // Non-copyable
  19. void init(PtrSize initialSize, F64 nextChunkGrowScale, PtrSize nextChunkGrowBias, U32 alignment, BufferUsageBit bufferUsage,
  20. BufferMapAccessBit bufferMapping, Bool allowToGrow, CString bufferName);
  21. /// @note It's thread-safe against other allocate()
  22. void allocate(PtrSize size, PtrSize& outOffset, Buffer*& buffer)
  23. {
  24. void* dummyMapped = nullptr;
  25. allocate(size, outOffset, buffer, dummyMapped);
  26. }
  27. /// @note It's thread-safe against other allocate()
  28. void allocate(PtrSize size, PtrSize& outOffset, Buffer*& buffer, void*& mappedMemory);
  29. void reset();
  30. private:
  31. class Chunk;
  32. class BuilderInterface;
  33. using Builder = StackAllocatorBuilder<Chunk, BuilderInterface, Mutex>;
  34. Builder* m_builder = nullptr;
  35. };
  36. /// @}
  37. } // end namespace anki