UnifiedGeometryBuffer.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/UnifiedGeometryBuffer.h>
  6. #include <AnKi/Gr/GrManager.h>
  7. namespace anki {
  8. inline StatCounter g_unifiedGeomBufferAllocatedSizeStatVar(StatCategory::kGpuMem, "UGB allocated", StatFlag::kBytes | StatFlag::kMainThreadUpdates);
  9. inline StatCounter g_unifiedGeomBufferTotalStatVar(StatCategory::kGpuMem, "UGB total", StatFlag::kBytes | StatFlag::kMainThreadUpdates);
  10. inline StatCounter g_unifiedGeomBufferFragmentationStatVar(StatCategory::kGpuMem, "UGB fragmentation",
  11. StatFlag::kFloat | StatFlag::kMainThreadUpdates);
  12. void UnifiedGeometryBuffer::init()
  13. {
  14. const PtrSize poolSize = g_unifiedGometryBufferSizeCvar;
  15. const Array classes = {1_KB, 8_KB, 32_KB, 128_KB, 512_KB, 4_MB, 8_MB, 16_MB, poolSize};
  16. BufferUsageBit buffUsage = BufferUsageBit::kVertexOrIndex | BufferUsageBit::kCopyDestination | BufferUsageBit::kAllSrv;
  17. if(GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled)
  18. {
  19. buffUsage |= BufferUsageBit::kAccelerationStructureBuild;
  20. }
  21. m_pool.init(buffUsage, classes, poolSize, "UnifiedGeometry", false);
  22. // Allocate something dummy to force creating the GPU buffer
  23. UnifiedGeometryBufferAllocation alloc = allocate(16, 4);
  24. deferredFree(alloc);
  25. }
  26. void UnifiedGeometryBuffer::updateStats() const
  27. {
  28. F32 externalFragmentation;
  29. PtrSize userAllocatedSize, totalSize;
  30. m_pool.getStats(externalFragmentation, userAllocatedSize, totalSize);
  31. g_unifiedGeomBufferAllocatedSizeStatVar.set(userAllocatedSize);
  32. g_unifiedGeomBufferTotalStatVar.set(totalSize);
  33. g_unifiedGeomBufferFragmentationStatVar.set(externalFragmentation);
  34. }
  35. } // end namespace anki