UnifiedGeometryBuffer.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/UnifiedGeometryBuffer.h>
  6. #include <AnKi/Core/ConfigSet.h>
  7. #include <AnKi/Core/StatsSet.h>
  8. #include <AnKi/Gr/GrManager.h>
  9. namespace anki {
  10. static StatCounter g_unifiedGeomBufferAllocatedSize(StatCategory::kGpuMem, "UGB allocated", StatFlag::kBytes);
  11. static StatCounter g_unifiedGeomBufferTotal(StatCategory::kGpuMem, "UGB total", StatFlag::kBytes);
  12. static StatCounter g_unifiedGeomBufferFragmentation(StatCategory::kGpuMem, "UGB fragmentation", StatFlag::kFloat);
  13. static NumericCVar<PtrSize> g_unifiedGometryBufferSizeCvar(CVarSubsystem::kCore, "UnifiedGeometryBufferSize", 128_MB, 16_MB, 2_GB,
  14. "Global index and vertex buffer size");
  15. void UnifiedGeometryBuffer::init()
  16. {
  17. const PtrSize poolSize = g_unifiedGometryBufferSizeCvar.get();
  18. const Array classes = {1_KB, 8_KB, 32_KB, 128_KB, 512_KB, 4_MB, 8_MB, 16_MB, poolSize};
  19. BufferUsageBit buffUsage = BufferUsageBit::kVertex | BufferUsageBit::kIndex | BufferUsageBit::kTransferDestination
  20. | (BufferUsageBit::kAllTexture & BufferUsageBit::kAllRead);
  21. if(GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled)
  22. {
  23. buffUsage |= BufferUsageBit::kAccelerationStructureBuild;
  24. }
  25. m_pool.init(buffUsage, classes, poolSize, "UnifiedGeometry", false);
  26. // Allocate something dummy to force creating the GPU buffer
  27. UnifiedGeometryBufferAllocation alloc;
  28. allocate(16, 4, alloc);
  29. deferredFree(alloc);
  30. }
  31. void UnifiedGeometryBuffer::updateStats() const
  32. {
  33. F32 externalFragmentation;
  34. PtrSize userAllocatedSize, totalSize;
  35. m_pool.getStats(externalFragmentation, userAllocatedSize, totalSize);
  36. g_unifiedGeomBufferAllocatedSize.set(userAllocatedSize);
  37. g_unifiedGeomBufferTotal.set(totalSize);
  38. g_unifiedGeomBufferFragmentation.set(externalFragmentation);
  39. }
  40. } // end namespace anki