GpuReadbackMemoryPool.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include <AnKi/Core/GpuMemory/GpuReadbackMemoryPool.h>
  6. #include <AnKi/Gr/GrManager.h>
  7. namespace anki {
  8. GpuReadbackMemoryPool::GpuReadbackMemoryPool()
  9. {
  10. const Array classes = {64_B, 256_B, 1_MB, 5_MB};
  11. const BufferUsageBit buffUsage = BufferUsageBit::kAllUav;
  12. const BufferMapAccessBit mapAccess = BufferMapAccessBit::kRead;
  13. m_pool.init(buffUsage, classes, classes.getBack(), "GpuReadback", false, mapAccess);
  14. m_alignment = GrManager::getSingleton().getDeviceCapabilities().m_uavBufferBindOffsetAlignment;
  15. }
  16. GpuReadbackMemoryPool ::~GpuReadbackMemoryPool()
  17. {
  18. }
  19. GpuReadbackMemoryAllocation GpuReadbackMemoryPool::allocate(PtrSize size)
  20. {
  21. GpuReadbackMemoryAllocation out;
  22. m_pool.allocate(size, m_alignment, out.m_token);
  23. out.m_buffer = &m_pool.getGpuBuffer();
  24. out.m_mappedMemory = static_cast<U8*>(m_pool.getGpuBufferMappedMemory()) + out.m_token.m_offset;
  25. return out;
  26. }
  27. void GpuReadbackMemoryPool::deferredFree(GpuReadbackMemoryAllocation& allocation)
  28. {
  29. m_pool.deferredFree(allocation.m_token);
  30. ::new(&allocation) GpuReadbackMemoryAllocation();
  31. }
  32. void GpuReadbackMemoryPool::endFrame()
  33. {
  34. m_pool.endFrame();
  35. }
  36. } // end namespace anki