Browse Source

Make the MaliHwCounters singleton

Panagiotis Christopoulos Charitos 2 years ago
parent
commit
767d11110b
4 changed files with 15 additions and 18 deletions
  1. 4 5
      AnKi/Core/App.cpp
  2. 0 2
      AnKi/Core/App.h
  3. 3 5
      AnKi/Core/MaliHwCounters.cpp
  4. 8 6
      AnKi/Core/MaliHwCounters.h

+ 4 - 5
AnKi/Core/App.cpp

@@ -136,8 +136,7 @@ void App::cleanup()
 	UnifiedGeometryMemoryPool::freeSingleton();
 	UnifiedGeometryMemoryPool::freeSingleton();
 	GpuSceneMemoryPool::freeSingleton();
 	GpuSceneMemoryPool::freeSingleton();
 	CoreThreadHive::freeSingleton();
 	CoreThreadHive::freeSingleton();
-	deleteInstance(m_mainPool, m_maliHwCounters);
-	m_maliHwCounters = nullptr;
+	MaliHwCounters::freeSingleton();
 	GrManager::deleteInstance(m_gr);
 	GrManager::deleteInstance(m_gr);
 	m_gr = nullptr;
 	m_gr = nullptr;
 	Input::freeSingleton();
 	Input::freeSingleton();
@@ -278,7 +277,7 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	if(m_gr->getDeviceCapabilities().m_gpuVendor == GpuVendor::kArm
 	if(m_gr->getDeviceCapabilities().m_gpuVendor == GpuVendor::kArm
 	   && ConfigSet::getSingleton().getCoreMaliHwCounters())
 	   && ConfigSet::getSingleton().getCoreMaliHwCounters())
 	{
 	{
-		m_maliHwCounters = newInstance<MaliHwCounters>(m_mainPool, &m_mainPool);
+		MaliHwCounters::allocateSingleton();
 	}
 	}
 
 
 	//
 	//
@@ -562,10 +561,10 @@ Error App::mainLoop()
 
 
 				in.m_gpuFrameTime = m_renderer->getStats().m_renderingGpuTime;
 				in.m_gpuFrameTime = m_renderer->getStats().m_renderingGpuTime;
 
 
-				if(m_maliHwCounters)
+				if(MaliHwCounters::isAllocated())
 				{
 				{
 					MaliHwCountersOut out;
 					MaliHwCountersOut out;
-					m_maliHwCounters->sample(out);
+					MaliHwCounters::getSingleton().sample(out);
 					in.m_gpuActiveCycles = out.m_gpuActive;
 					in.m_gpuActiveCycles = out.m_gpuActive;
 					in.m_gpuReadBandwidth = out.m_readBandwidth;
 					in.m_gpuReadBandwidth = out.m_readBandwidth;
 					in.m_gpuWriteBandwidth = out.m_writeBandwidth;
 					in.m_gpuWriteBandwidth = out.m_writeBandwidth;

+ 0 - 2
AnKi/Core/App.h

@@ -22,7 +22,6 @@ class ResourceFilesystem;
 class UiManager;
 class UiManager;
 class UiQueueElement;
 class UiQueueElement;
 class RenderQueue;
 class RenderQueue;
-class MaliHwCounters;
 
 
 /// The core class of the engine.
 /// The core class of the engine.
 class App
 class App
@@ -99,7 +98,6 @@ private:
 
 
 	// Sybsystems
 	// Sybsystems
 	GrManager* m_gr = nullptr;
 	GrManager* m_gr = nullptr;
-	MaliHwCounters* m_maliHwCounters = nullptr;
 	ResourceFilesystem* m_resourceFs = nullptr;
 	ResourceFilesystem* m_resourceFs = nullptr;
 	ResourceManager* m_resources = nullptr;
 	ResourceManager* m_resources = nullptr;
 	UiManager* m_ui = nullptr;
 	UiManager* m_ui = nullptr;

+ 3 - 5
AnKi/Core/MaliHwCounters.cpp

@@ -13,16 +13,14 @@
 
 
 namespace anki {
 namespace anki {
 
 
-MaliHwCounters::MaliHwCounters(BaseMemoryPool* pool)
-	: m_pool(pool)
+MaliHwCounters::MaliHwCounters()
 {
 {
-	ANKI_ASSERT(pool);
 #if ANKI_HWCPIPE_ENABLE
 #if ANKI_HWCPIPE_ENABLE
 	const hwcpipe::CpuCounterSet cpuCounters;
 	const hwcpipe::CpuCounterSet cpuCounters;
 	const hwcpipe::GpuCounterSet gpuCounters = {hwcpipe::GpuCounter::GpuCycles,
 	const hwcpipe::GpuCounterSet gpuCounters = {hwcpipe::GpuCounter::GpuCycles,
 												hwcpipe::GpuCounter::ExternalMemoryWriteBytes,
 												hwcpipe::GpuCounter::ExternalMemoryWriteBytes,
 												hwcpipe::GpuCounter::ExternalMemoryReadBytes};
 												hwcpipe::GpuCounter::ExternalMemoryReadBytes};
-	hwcpipe::HWCPipe* hwc = newInstance<hwcpipe::HWCPipe>(*m_pool, cpuCounters, gpuCounters);
+	hwcpipe::HWCPipe* hwc = newInstance<hwcpipe::HWCPipe>(CoreMemoryPool::getSingleton(), cpuCounters, gpuCounters);
 
 
 	hwc->run();
 	hwc->run();
 
 
@@ -37,7 +35,7 @@ MaliHwCounters::~MaliHwCounters()
 #if ANKI_HWCPIPE_ENABLE
 #if ANKI_HWCPIPE_ENABLE
 	hwcpipe::HWCPipe* hwc = static_cast<hwcpipe::HWCPipe*>(m_impl);
 	hwcpipe::HWCPipe* hwc = static_cast<hwcpipe::HWCPipe*>(m_impl);
 	hwc->stop();
 	hwc->stop();
-	deleteInstance(*m_pool, hwc);
+	deleteInstance(CoreMemoryPool::getSingleton(), hwc);
 	m_impl = nullptr;
 	m_impl = nullptr;
 #endif
 #endif
 }
 }

+ 8 - 6
AnKi/Core/MaliHwCounters.h

@@ -24,22 +24,24 @@ public:
 };
 };
 
 
 /// Sample HW counters for Mali GPUs.
 /// Sample HW counters for Mali GPUs.
-class MaliHwCounters
+class MaliHwCounters : public MakeSingleton<MaliHwCounters>
 {
 {
-public:
-	MaliHwCounters(BaseMemoryPool* pool);
+	template<typename>
+	friend class MakeSingleton;
 
 
+public:
 	MaliHwCounters(const MaliHwCounters&) = delete; // Non-copyable
 	MaliHwCounters(const MaliHwCounters&) = delete; // Non-copyable
 
 
-	~MaliHwCounters();
-
 	MaliHwCounters& operator=(const MaliHwCounters&) = delete; // Non-copyable
 	MaliHwCounters& operator=(const MaliHwCounters&) = delete; // Non-copyable
 
 
 	void sample(MaliHwCountersOut& out);
 	void sample(MaliHwCountersOut& out);
 
 
 private:
 private:
-	BaseMemoryPool* m_pool = nullptr;
 	void* m_impl = nullptr;
 	void* m_impl = nullptr;
+
+	MaliHwCounters();
+
+	~MaliHwCounters();
 };
 };
 /// @}
 /// @}