GpuReadbackMemoryPool.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <AnKi/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. if(!GrManager::getSingleton().getDeviceCapabilities().m_structuredBufferNaturalAlignment)
  15. {
  16. m_structuredBufferAlignment = GrManager::getSingleton().getDeviceCapabilities().m_structuredBufferBindOffsetAlignment;
  17. }
  18. }
  19. GpuReadbackMemoryPool ::~GpuReadbackMemoryPool()
  20. {
  21. }
  22. GpuReadbackMemoryAllocation GpuReadbackMemoryPool::allocate(PtrSize size, U32 alignment)
  23. {
  24. GpuReadbackMemoryAllocation out;
  25. m_pool.allocate(size, alignment, out.m_token);
  26. out.m_buffer = &m_pool.getGpuBuffer();
  27. out.m_mappedMemory = static_cast<U8*>(m_pool.getGpuBufferMappedMemory()) + out.m_token.m_offset;
  28. return out;
  29. }
  30. void GpuReadbackMemoryPool::deferredFree(GpuReadbackMemoryAllocation& allocation)
  31. {
  32. m_pool.deferredFree(allocation.m_token);
  33. ::new(&allocation) GpuReadbackMemoryAllocation();
  34. }
  35. void GpuReadbackMemoryPool::endFrame()
  36. {
  37. m_pool.endFrame();
  38. }
  39. } // end namespace anki