UnifiedGeometryBuffer.cpp 2.1 KB

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