StackGpuMemoryPool.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2009-present, 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, BufferUsageBit bufferUsage, BufferMapAccessBit bufferMapping,
  20. Bool allowToGrow, CString bufferName);
  21. /// @note It's thread-safe against other allocate()
  22. void allocate(PtrSize size, PtrSize alignment, PtrSize& outOffset, Buffer*& buffer)
  23. {
  24. void* dummyMapped = nullptr;
  25. allocate(size, alignment, outOffset, buffer, dummyMapped);
  26. }
  27. /// @note It's thread-safe against other allocate()
  28. void allocate(PtrSize size, PtrSize alignment, PtrSize& outOffset, Buffer*& buffer, void*& mappedMemory);
  29. void reset();
  30. PtrSize getAllocatedMemory() const;
  31. private:
  32. class Chunk;
  33. class BuilderInterface;
  34. using Builder = StackAllocatorBuilder<Chunk, BuilderInterface, Mutex>;
  35. Builder* m_builder = nullptr;
  36. };
  37. /// @}
  38. } // end namespace anki