Browse Source

Make most things compile

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
7c10dea66d
46 changed files with 416 additions and 426 deletions
  1. 57 56
      AnKi/Core/App.cpp
  2. 4 23
      AnKi/Core/App.h
  3. 4 4
      AnKi/Core/ConfigSet.cpp
  4. 3 3
      AnKi/Core/ConfigSet.h
  5. 23 20
      AnKi/Core/CoreTracer.cpp
  6. 2 2
      AnKi/Core/CoreTracer.h
  7. 9 10
      AnKi/Core/DeveloperConsole.cpp
  8. 1 2
      AnKi/Core/DeveloperConsole.h
  9. 14 13
      AnKi/Core/GpuMemoryPools.cpp
  10. 10 8
      AnKi/Core/GpuMemoryPools.h
  11. 5 4
      AnKi/Core/MaliHwCounters.cpp
  12. 2 2
      AnKi/Core/MaliHwCounters.h
  13. 1 1
      AnKi/Core/NativeWindow.h
  14. 13 9
      AnKi/Core/NativeWindowSdl.cpp
  15. 1 1
      AnKi/Core/NativeWindowSdl.h
  16. 1 1
      AnKi/Core/StatsUi.cpp
  17. 8 8
      AnKi/Core/StdinListener.cpp
  18. 2 2
      AnKi/Core/StdinListener.h
  19. 37 37
      AnKi/Importer/GltfImporter.cpp
  20. 9 9
      AnKi/Importer/GltfImporter.h
  21. 14 14
      AnKi/Importer/GltfImporterAnimation.cpp
  22. 32 32
      AnKi/Importer/GltfImporterMaterial.cpp
  23. 27 27
      AnKi/Importer/GltfImporterMesh.cpp
  24. 43 43
      AnKi/Importer/ImageImporter.cpp
  25. 1 1
      AnKi/Importer/ImageImporter.h
  26. 8 8
      AnKi/Renderer/ClusterBinning.cpp
  27. 1 1
      AnKi/Renderer/Drawer.cpp
  28. 2 2
      AnKi/Renderer/RendererObject.h
  29. 1 1
      AnKi/Scene/Components/GpuParticleEmitterComponent.cpp
  30. 1 1
      AnKi/Scene/Components/ParticleEmitterComponent.cpp
  31. 2 2
      AnKi/Scene/Components/RenderComponent.cpp
  32. 9 9
      AnKi/Scene/DebugDrawer.cpp
  33. 2 2
      AnKi/Scene/ModelNode.cpp
  34. 0 3
      AnKi/Script/Common.h
  35. 11 11
      AnKi/Script/LuaBinder.cpp
  36. 4 5
      AnKi/Script/LuaBinder.h
  37. 1 1
      AnKi/Script/ScriptEnvironment.cpp
  38. 2 2
      AnKi/Script/ScriptManager.cpp
  39. 3 3
      AnKi/Script/ScriptManager.h
  40. 2 2
      AnKi/Ui/Canvas.cpp
  41. 10 7
      AnKi/Util/BuddyAllocatorBuilder.h
  42. 24 24
      AnKi/Util/BuddyAllocatorBuilder.inl.h
  43. 2 2
      AnKi/Util/FilesystemWindows.cpp
  44. 2 2
      AnKi/Util/String.h
  45. 4 4
      Samples/Common/SampleApp.cpp
  46. 2 2
      Tests/Gr/Gr.cpp

+ 57 - 56
AnKi/Core/App.cpp

@@ -116,27 +116,27 @@ void App::cleanup()
 	m_statsUi.reset(nullptr);
 	m_console.reset(nullptr);
 
-	m_heapAlloc.deleteInstance(m_scene);
+	deleteInstance(m_mainPool, m_scene);
 	m_scene = nullptr;
-	m_heapAlloc.deleteInstance(m_script);
+	deleteInstance(m_mainPool, m_script);
 	m_script = nullptr;
-	m_heapAlloc.deleteInstance(m_renderer);
+	deleteInstance(m_mainPool, m_renderer);
 	m_renderer = nullptr;
-	m_heapAlloc.deleteInstance(m_ui);
+	deleteInstance(m_mainPool, m_ui);
 	m_ui = nullptr;
-	m_heapAlloc.deleteInstance(m_resources);
+	deleteInstance(m_mainPool, m_resources);
 	m_resources = nullptr;
-	m_heapAlloc.deleteInstance(m_resourceFs);
+	deleteInstance(m_mainPool, m_resourceFs);
 	m_resourceFs = nullptr;
-	m_heapAlloc.deleteInstance(m_physics);
+	deleteInstance(m_mainPool, m_physics);
 	m_physics = nullptr;
-	m_heapAlloc.deleteInstance(m_stagingMem);
+	deleteInstance(m_mainPool, m_stagingMem);
 	m_stagingMem = nullptr;
-	m_heapAlloc.deleteInstance(m_vertexMem);
+	deleteInstance(m_mainPool, m_vertexMem);
 	m_vertexMem = nullptr;
-	m_heapAlloc.deleteInstance(m_threadHive);
+	deleteInstance(m_mainPool, m_threadHive);
 	m_threadHive = nullptr;
-	m_heapAlloc.deleteInstance(m_maliHwCounters);
+	deleteInstance(m_mainPool, m_maliHwCounters);
 	m_maliHwCounters = nullptr;
 	GrManager::deleteInstance(m_gr);
 	m_gr = nullptr;
@@ -150,8 +150,8 @@ void App::cleanup()
 	m_coreTracer = nullptr;
 #endif
 
-	m_settingsDir.destroy(m_heapAlloc);
-	m_cacheDir.destroy(m_heapAlloc);
+	m_settingsDir.destroy(m_mainPool);
+	m_cacheDir.destroy(m_mainPool);
 }
 
 Error App::init(ConfigSet* config, AllocAlignedCallback allocCb, void* allocCbUserData)
@@ -175,7 +175,7 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	setSignalHandlers();
 
 	initMemoryCallbacks(allocCb, allocCbUserData);
-	m_heapAlloc = HeapAllocator<U8>(m_allocCb, m_allocCbData, "Core");
+	m_mainPool.init(allocCb, allocCbUserData, "Core");
 
 	ANKI_CHECK(initDirs());
 
@@ -233,8 +233,8 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	// Window
 	//
 	NativeWindowInitInfo nwinit;
-	nwinit.m_allocCallback = m_allocCb;
-	nwinit.m_allocCallbackUserData = m_allocCbData;
+	nwinit.m_allocCallback = m_mainPool.getAllocationCallback();
+	nwinit.m_allocCallbackUserData = m_mainPool.getAllocationCallbackUserData();
 	nwinit.m_width = m_config->getWidth();
 	nwinit.m_height = m_config->getHeight();
 	nwinit.m_depthBits = 0;
@@ -246,19 +246,20 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	//
 	// Input
 	//
-	ANKI_CHECK(Input::newInstance(m_allocCb, m_allocCbData, m_window, m_input));
+	ANKI_CHECK(Input::newInstance(m_mainPool.getAllocationCallback(), m_mainPool.getAllocationCallbackUserData(),
+								  m_window, m_input));
 
 	//
 	// ThreadPool
 	//
-	m_threadHive = m_heapAlloc.newInstance<ThreadHive>(m_config->getCoreJobThreadCount(), m_heapAlloc, true);
+	m_threadHive = newInstance<ThreadHive>(m_mainPool, m_config->getCoreJobThreadCount(), &m_mainPool, true);
 
 	//
 	// Graphics API
 	//
 	GrManagerInitInfo grInit;
-	grInit.m_allocCallback = m_allocCb;
-	grInit.m_allocCallbackUserData = m_allocCbData;
+	grInit.m_allocCallback = m_mainPool.getAllocationCallback();
+	grInit.m_allocCallbackUserData = m_mainPool.getAllocationCallbackUserData();
 	grInit.m_cacheDirectory = m_cacheDir.toCString();
 	grInit.m_config = m_config;
 	grInit.m_window = m_window;
@@ -270,41 +271,40 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	//
 	if(m_gr->getDeviceCapabilities().m_gpuVendor == GpuVendor::kArm && m_config->getCoreMaliHwCounters())
 	{
-		m_maliHwCounters = m_heapAlloc.newInstance<MaliHwCounters>(m_heapAlloc);
+		m_maliHwCounters = newInstance<MaliHwCounters>(m_mainPool, &m_mainPool);
 	}
 
 	//
 	// GPU mem
 	//
-	m_vertexMem = m_heapAlloc.newInstance<VertexGpuMemoryPool>();
-	ANKI_CHECK(m_vertexMem->init(m_heapAlloc, m_gr, *m_config));
+	m_vertexMem = newInstance<VertexGpuMemoryPool>(m_mainPool);
+	ANKI_CHECK(m_vertexMem->init(&m_mainPool, m_gr, *m_config));
 
-	m_stagingMem = m_heapAlloc.newInstance<StagingGpuMemoryPool>();
+	m_stagingMem = newInstance<StagingGpuMemoryPool>(m_mainPool);
 	ANKI_CHECK(m_stagingMem->init(m_gr, *m_config));
 
 	//
 	// Physics
 	//
-	m_physics = m_heapAlloc.newInstance<PhysicsWorld>();
-
-	ANKI_CHECK(m_physics->init(m_allocCb, m_allocCbData));
+	m_physics = newInstance<PhysicsWorld>(m_mainPool);
+	ANKI_CHECK(m_physics->init(m_mainPool.getAllocationCallback(), m_mainPool.getAllocationCallbackUserData()));
 
 	//
 	// Resource FS
 	//
 #if !ANKI_OS_ANDROID
 	// Add the location of the executable where the shaders are supposed to be
-	StringRaii executableFname(m_heapAlloc);
+	StringRaii executableFname(&m_mainPool);
 	ANKI_CHECK(getApplicationPath(executableFname));
 	ANKI_CORE_LOGI("Executable path is: %s", executableFname.cstr());
-	StringRaii shadersPath(m_heapAlloc);
+	StringRaii shadersPath(&m_mainPool);
 	getParentFilepath(executableFname, shadersPath);
 	shadersPath.append(":");
 	shadersPath.append(m_config->getRsrcDataPaths());
 	m_config->setRsrcDataPaths(shadersPath);
 #endif
 
-	m_resourceFs = m_heapAlloc.newInstance<ResourceFilesystem>(m_heapAlloc);
+	m_resourceFs = newInstance<ResourceFilesystem>(m_mainPool, &m_mainPool);
 	ANKI_CHECK(m_resourceFs->init(*m_config));
 
 	//
@@ -316,25 +316,26 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	rinit.m_resourceFs = m_resourceFs;
 	rinit.m_vertexMemory = m_vertexMem;
 	rinit.m_config = m_config;
-	rinit.m_allocCallback = m_allocCb;
-	rinit.m_allocCallbackData = m_allocCbData;
-	m_resources = m_heapAlloc.newInstance<ResourceManager>();
+	rinit.m_allocCallback = m_mainPool.getAllocationCallback();
+	rinit.m_allocCallbackData = m_mainPool.getAllocationCallbackUserData();
+	m_resources = newInstance<ResourceManager>(m_mainPool);
 
 	ANKI_CHECK(m_resources->init(rinit));
 
 	//
 	// UI
 	//
-	m_ui = m_heapAlloc.newInstance<UiManager>();
-	ANKI_CHECK(m_ui->init(m_allocCb, m_allocCbData, m_resources, m_gr, m_stagingMem, m_input));
+	m_ui = newInstance<UiManager>(m_mainPool);
+	ANKI_CHECK(m_ui->init(m_mainPool.getAllocationCallback(), m_mainPool.getAllocationCallbackUserData(), m_resources,
+						  m_gr, m_stagingMem, m_input));
 
 	//
 	// Renderer
 	//
 	MainRendererInitInfo renderInit;
 	renderInit.m_swapchainSize = UVec2(m_window->getWidth(), m_window->getHeight());
-	renderInit.m_allocCallback = m_allocCb;
-	renderInit.m_allocCallbackUserData = m_allocCbData;
+	renderInit.m_allocCallback = m_mainPool.getAllocationCallback();
+	renderInit.m_allocCallbackUserData = m_mainPool.getAllocationCallbackUserData();
 	renderInit.m_threadHive = m_threadHive;
 	renderInit.m_resourceManager = m_resources;
 	renderInit.m_gr = m_gr;
@@ -342,22 +343,22 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	renderInit.m_ui = m_ui;
 	renderInit.m_config = m_config;
 	renderInit.m_globTimestamp = &m_globalTimestamp;
-	m_renderer = m_heapAlloc.newInstance<MainRenderer>();
+	m_renderer = newInstance<MainRenderer>(m_mainPool);
 	ANKI_CHECK(m_renderer->init(renderInit));
 
 	//
 	// Script
 	//
-	m_script = m_heapAlloc.newInstance<ScriptManager>();
-	ANKI_CHECK(m_script->init(m_allocCb, m_allocCbData));
+	m_script = newInstance<ScriptManager>(m_mainPool);
+	ANKI_CHECK(m_script->init(m_mainPool.getAllocationCallback(), m_mainPool.getAllocationCallbackUserData()));
 
 	//
 	// Scene
 	//
-	m_scene = m_heapAlloc.newInstance<SceneGraph>();
+	m_scene = newInstance<SceneGraph>(m_mainPool);
 
-	ANKI_CHECK(m_scene->init(m_allocCb, m_allocCbData, m_threadHive, m_resources, m_input, m_script, m_ui, m_config,
-							 &m_globalTimestamp));
+	ANKI_CHECK(m_scene->init(m_mainPool.getAllocationCallback(), m_mainPool.getAllocationCallbackUserData(),
+							 m_threadHive, m_resources, m_input, m_script, m_ui, m_config, &m_globalTimestamp));
 
 	// Inform the script engine about some subsystems
 	m_script->setRenderer(m_renderer);
@@ -367,7 +368,7 @@ Error App::initInternal(AllocAlignedCallback allocCb, void* allocCbUserData)
 	// Misc
 	//
 	ANKI_CHECK(m_ui->newInstance<StatsUi>(m_statsUi));
-	ANKI_CHECK(m_ui->newInstance<DeveloperConsole>(m_console, m_allocCb, m_allocCbData, m_script));
+	ANKI_CHECK(m_ui->newInstance<DeveloperConsole>(m_console, m_script));
 
 	ANKI_CORE_LOGI("Application initialized");
 
@@ -378,12 +379,12 @@ Error App::initDirs()
 {
 	// Settings path
 #if !ANKI_OS_ANDROID
-	StringRaii home(m_heapAlloc);
+	StringRaii home(&m_mainPool);
 	ANKI_CHECK(getHomeDirectory(home));
 
-	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", &home[0]);
+	m_settingsDir.sprintf(m_mainPool, "%s/.anki", &home[0]);
 #else
-	m_settingsDir.sprintf(m_heapAlloc, "%s/.anki", g_androidApp->activity->internalDataPath);
+	m_settingsDir.sprintf(m_mainPool, "%s/.anki", g_androidApp->activity->internalDataPath);
 #endif
 
 	if(!directoryExists(m_settingsDir.toCString()))
@@ -397,13 +398,13 @@ Error App::initDirs()
 	}
 
 	// Cache
-	m_cacheDir.sprintf(m_heapAlloc, "%s/cache", &m_settingsDir[0]);
+	m_cacheDir.sprintf(m_mainPool, "%s/cache", &m_settingsDir[0]);
 
 	const Bool cacheDirExists = directoryExists(m_cacheDir.toCString());
 	if(m_config->getCoreClearCaches() && cacheDirExists)
 	{
 		ANKI_CORE_LOGI("Will delete the cache dir and start fresh: %s", &m_cacheDir[0]);
-		ANKI_CHECK(removeDirectory(m_cacheDir.toCString(), m_heapAlloc));
+		ANKI_CHECK(removeDirectory(m_cacheDir.toCString(), m_mainPool));
 		ANKI_CHECK(createDirectory(m_cacheDir.toCString()));
 	}
 	else if(!cacheDirExists)
@@ -444,7 +445,7 @@ Error App::mainLoop()
 			m_scene->doVisibilityTests(rqueue);
 
 			// Inject stats UI
-			DynamicArrayRaii<UiQueueElement> newUiElementArr(m_heapAlloc);
+			DynamicArrayRaii<UiQueueElement> newUiElementArr(&m_mainPool);
 			injectUiElements(newUiElementArr, rqueue);
 
 			// Render
@@ -580,20 +581,19 @@ void App::injectUiElements(DynamicArrayRaii<UiQueueElement>& newUiElementArr, Re
 	}
 }
 
-void App::initMemoryCallbacks(AllocAlignedCallback allocCb, void* allocCbUserData)
+void App::initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData)
 {
 	if(m_config->getCoreDisplayStats() > 1)
 	{
 		m_memStats.m_originalAllocCallback = allocCb;
 		m_memStats.m_originalUserData = allocCbUserData;
 
-		m_allocCb = MemStats::allocCallback;
-		m_allocCbData = &m_memStats;
+		allocCb = MemStats::allocCallback;
+		allocCbUserData = &m_memStats;
 	}
 	else
 	{
-		m_allocCb = allocCb;
-		m_allocCbData = allocCbUserData;
+		// Leave the default
 	}
 }
 
@@ -629,7 +629,8 @@ void App::setSignalHandlers()
 
 		U32 count = 0;
 		printf("Backtrace:\n");
-		backtrace(HeapAllocator<U8>(allocAligned, nullptr), [&count](CString symbol) {
+		HeapMemoryPool pool(allocAligned, nullptr);
+		backtrace(pool, [&count](CString symbol) {
 			printf("%.2u: %s\n", count++, symbol.cstr());
 		});
 

+ 4 - 23
AnKi/Core/App.h

@@ -6,7 +6,6 @@
 #pragma once
 
 #include <AnKi/Core/Common.h>
-#include <AnKi/Util/Allocator.h>
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/Ptr.h>
 #include <AnKi/Ui/UiImmediateModeBuilder.h>
@@ -54,24 +53,14 @@ public:
 		return m_cacheDir;
 	}
 
-	AllocAlignedCallback getAllocationCallback() const
-	{
-		return m_allocCb;
-	}
-
-	void* getAllocationCallbackData() const
-	{
-		return m_allocCbData;
-	}
-
 	ThreadHive& getThreadHive()
 	{
 		return *m_threadHive;
 	}
 
-	HeapAllocator<U8>& getAllocator()
+	HeapMemoryPool& getMemoryPool()
 	{
-		return m_heapAlloc;
+		return m_mainPool;
 	}
 
 	Timestamp getGlobalTimestamp() const
@@ -134,11 +123,6 @@ public:
 		return *m_window;
 	}
 
-	HeapAllocator<U8> getAllocator() const
-	{
-		return m_heapAlloc;
-	}
-
 	void setDisplayDeveloperConsole(Bool display)
 	{
 		m_consoleEnabled = display;
@@ -150,10 +134,7 @@ public:
 	}
 
 private:
-	// Allocation
-	AllocAlignedCallback m_allocCb;
-	void* m_allocCbData;
-	HeapAllocator<U8> m_heapAlloc;
+	HeapMemoryPool m_mainPool;
 
 	// Sybsystems
 	ConfigSet* m_config = nullptr;
@@ -197,7 +178,7 @@ private:
 		static void* allocCallback(void* userData, void* ptr, PtrSize size, PtrSize alignment);
 	} m_memStats;
 
-	void initMemoryCallbacks(AllocAlignedCallback allocCb, void* allocCbUserData);
+	void initMemoryCallbacks(AllocAlignedCallback& allocCb, void*& allocCbUserData);
 
 	Error initInternal(AllocAlignedCallback allocCb, void* allocCbUserData);
 

+ 4 - 4
AnKi/Core/ConfigSet.cpp

@@ -19,7 +19,7 @@ ConfigSet::~ConfigSet()
 #define ANKI_CONFIG_VAR_STRING(name, defaultValue, description) \
 	if(m_##name.m_value) \
 	{ \
-		m_alloc.getMemoryPool().free(m_##name.m_value); \
+		m_pool.free(m_##name.m_value); \
 	}
 #include <AnKi/Core/AllConfigVars.defs.h>
 
@@ -37,7 +37,7 @@ ConfigSet::~ConfigSet()
 void ConfigSet::init(AllocAlignedCallback allocCb, void* allocCbUserData)
 {
 	ANKI_ASSERT(!isInitialized());
-	m_alloc = HeapAllocator<U8>(allocCb, allocCbUserData);
+	m_pool.init(allocCb, allocCbUserData);
 
 #define ANKI_CONFIG_VAR_NUMERIC(name, defaultValue, minValue, maxValue, description) \
 	ANKI_ASSERT(minValue <= maxValue && defaultValue >= minValue && defaultValue <= maxValue); \
@@ -106,8 +106,8 @@ Error ConfigSet::loadFromFile(CString filename)
 	ANKI_ASSERT(isInitialized());
 
 	ANKI_CORE_LOGI("Loading config file %s", filename.cstr());
-	XmlDocument xml;
-	ANKI_CHECK(xml.loadFile(filename, m_alloc));
+	XmlDocument xml(&m_pool);
+	ANKI_CHECK(xml.loadFile(filename));
 
 	XmlElement rootel;
 	ANKI_CHECK(xml.getChildElement("config", rootel));

+ 3 - 3
AnKi/Core/ConfigSet.h

@@ -133,7 +133,7 @@ private:
 		Bool m_value;
 	};
 
-	HeapAllocator<U8> m_alloc;
+	HeapMemoryPool m_pool;
 	IntrusiveList<Var> m_vars;
 
 #define ANKI_CONFIG_VAR_U8(name, defaultValue, minValue, maxValue, description) NumberVar<U8> m_##name;
@@ -168,9 +168,9 @@ private:
 
 	void setStringVar(CString val, StringVar& var)
 	{
-		m_alloc.getMemoryPool().free(var.m_value);
+		m_pool.free(var.m_value);
 		const U32 len = val.getLength();
-		var.m_value = static_cast<Char*>(m_alloc.getMemoryPool().allocate(len + 1, alignof(Char)));
+		var.m_value = static_cast<Char*>(m_pool.allocate(len + 1, alignof(Char)));
 		memcpy(var.m_value, val.getBegin(), len + 1);
 	}
 };

+ 23 - 20
AnKi/Core/CoreTracer.cpp

@@ -38,9 +38,9 @@ public:
 	ThreadId m_tid;
 	U64 m_frame;
 
-	ThreadWorkItem(GenericMemoryPoolAllocator<U8>& alloc)
-		: m_events(alloc)
-		, m_counters(alloc)
+	ThreadWorkItem(HeapMemoryPool* pool)
+		: m_events(pool)
+		, m_counters(pool)
 	{
 	}
 };
@@ -51,8 +51,8 @@ public:
 	DynamicArrayRaii<TracerCounter> m_counters;
 	U64 m_frame;
 
-	PerFrameCounters(GenericMemoryPoolAllocator<U8>& alloc)
-		: m_counters(alloc)
+	PerFrameCounters(HeapMemoryPool* pool)
+		: m_counters(pool)
 	{
 	}
 };
@@ -85,46 +85,49 @@ CoreTracer::~CoreTracer()
 	while(!m_frameCounters.isEmpty())
 	{
 		PerFrameCounters* frame = m_frameCounters.popBack();
-		m_alloc.deleteInstance(frame);
+		deleteInstance(*m_pool, frame);
 	}
 
 	while(!m_workItems.isEmpty())
 	{
 		ThreadWorkItem* item = m_workItems.popBack();
-		m_alloc.deleteInstance(item);
+		deleteInstance(*m_pool, item);
 	}
 
 	for(String& s : m_counterNames)
 	{
-		s.destroy(m_alloc);
+		s.destroy(*m_pool);
 	}
-	m_counterNames.destroy(m_alloc);
+	m_counterNames.destroy(*m_pool);
 
 	// Destroy the tracer
 	TracerSingleton::destroy();
 }
 
-Error CoreTracer::init(GenericMemoryPoolAllocator<U8> alloc, CString directory)
+Error CoreTracer::init(HeapMemoryPool* pool, CString directory)
 {
-	TracerSingleton::init(alloc);
+	ANKI_ASSERT(pool);
+	m_pool = pool;
+
+	TracerSingleton::init(m_pool);
 	const Bool enableTracer = getenv("ANKI_CORE_TRACER_ENABLED") && getenv("ANKI_CORE_TRACER_ENABLED")[0] == '1';
 	TracerSingleton::get().setEnabled(enableTracer);
 	ANKI_CORE_LOGI("Tracing is %s from the beginning", (enableTracer) ? "enabled" : "disabled");
 
-	m_alloc = alloc;
 	m_thread.start(this, [](ThreadCallbackInfo& info) -> Error {
 		return static_cast<CoreTracer*>(info.m_userData)->threadWorker();
 	});
 
 	std::tm tm = getLocalTime();
-	StringRaii fname(m_alloc);
+	StringRaii fname(m_pool);
 	fname.sprintf("%s/%d%02d%02d-%02d%02d_", directory.cstr(), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
 				  tm.tm_min);
 
-	ANKI_CHECK(m_traceJsonFile.open(StringRaii(alloc).sprintf("%strace.json", fname.cstr()), FileOpenFlag::kWrite));
+	ANKI_CHECK(m_traceJsonFile.open(StringRaii(m_pool).sprintf("%strace.json", fname.cstr()), FileOpenFlag::kWrite));
 	ANKI_CHECK(m_traceJsonFile.writeText("[\n"));
 
-	ANKI_CHECK(m_countersCsvFile.open(StringRaii(alloc).sprintf("%scounters.csv", fname.cstr()), FileOpenFlag::kWrite));
+	ANKI_CHECK(
+		m_countersCsvFile.open(StringRaii(m_pool).sprintf("%scounters.csv", fname.cstr()), FileOpenFlag::kWrite));
 
 	return Error::kNone;
 }
@@ -168,7 +171,7 @@ Error CoreTracer::threadWorker()
 				gatherCounters(*item);
 			}
 
-			m_alloc.deleteInstance(item);
+			deleteInstance(*m_pool, item);
 		}
 	}
 
@@ -211,7 +214,7 @@ void CoreTracer::gatherCounters(ThreadWorkItem& item)
 	});
 
 	// Merge same
-	DynamicArrayRaii<TracerCounter> mergedCounters(m_alloc);
+	DynamicArrayRaii<TracerCounter> mergedCounters(m_pool);
 	for(U32 i = 0; i < item.m_counters.getSize(); ++i)
 	{
 		if(mergedCounters.getSize() == 0 || mergedCounters.getBack().m_name != item.m_counters[i].m_name)
@@ -245,7 +248,7 @@ void CoreTracer::gatherCounters(ThreadWorkItem& item)
 
 		if(!found)
 		{
-			m_counterNames.emplaceBack(m_alloc, m_alloc, counter.m_name);
+			m_counterNames.emplaceBack(*m_pool, *m_pool, counter.m_name);
 			addedCounterName = true;
 		}
 	}
@@ -259,7 +262,7 @@ void CoreTracer::gatherCounters(ThreadWorkItem& item)
 	if(m_frameCounters.isEmpty() || m_frameCounters.getBack().m_frame != item.m_frame)
 	{
 		// Create new frame
-		PerFrameCounters* newPerFrame = m_alloc.newInstance<PerFrameCounters>(m_alloc);
+		PerFrameCounters* newPerFrame = newInstance<PerFrameCounters>(*m_pool, m_pool);
 		newPerFrame->m_counters = std::move(mergedCounters);
 		newPerFrame->m_frame = item.m_frame;
 		m_frameCounters.pushBack(newPerFrame);
@@ -307,7 +310,7 @@ void CoreTracer::flushFrame(U64 frame)
 			Ctx& ctx = *static_cast<Ctx*>(ud);
 			CoreTracer& self = *ctx.m_self;
 
-			ThreadWorkItem* item = self.m_alloc.newInstance<ThreadWorkItem>(self.m_alloc);
+			ThreadWorkItem* item = newInstance<ThreadWorkItem>(*self.m_pool, self.m_pool);
 			item->m_tid = tid;
 			item->m_frame = ctx.m_frame;
 

+ 2 - 2
AnKi/Core/CoreTracer.h

@@ -25,7 +25,7 @@ public:
 	~CoreTracer();
 
 	/// @param directory The directory to store the trace and counters.
-	Error init(GenericMemoryPoolAllocator<U8> alloc, CString directory);
+	Error init(HeapMemoryPool* pool, CString directory);
 
 	/// It will flush everything.
 	void flushFrame(U64 frame);
@@ -34,7 +34,7 @@ private:
 	class ThreadWorkItem;
 	class PerFrameCounters;
 
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 
 	Thread m_thread;
 	ConditionVariable m_cvar;

+ 9 - 10
AnKi/Core/DeveloperConsole.cpp

@@ -15,15 +15,14 @@ DeveloperConsole::~DeveloperConsole()
 	{
 		LogItem* item = &m_logItems.getFront();
 		m_logItems.popFront();
-		item->m_threadName.destroy(m_alloc);
-		item->m_msg.destroy(m_alloc);
-		m_alloc.deleteInstance(item);
+		item->m_threadName.destroy(getMemoryPool());
+		item->m_msg.destroy(getMemoryPool());
+		deleteInstance(getMemoryPool(), item);
 	}
 }
 
-Error DeveloperConsole::init(AllocAlignedCallback allocCb, void* allocCbUserData, ScriptManager* scriptManager)
+Error DeveloperConsole::init(ScriptManager* scriptManager)
 {
-	m_alloc = HeapAllocator<U8>(allocCb, allocCbUserData, "DeveloperConsole");
 	zeroMemory(m_inputText);
 
 	ANKI_CHECK(m_manager->newInstance(m_font, "EngineAssets/UbuntuMonoRegular.ttf", Array<U32, 1>{16}));
@@ -123,8 +122,8 @@ void DeveloperConsole::newLogItem(const LoggerMessageInfo& inf)
 		LogItem* first = &m_logItems.getFront();
 		m_logItems.popFront();
 
-		first->m_msg.destroy(m_alloc);
-		first->m_threadName.destroy(m_alloc);
+		first->m_msg.destroy(getMemoryPool());
+		first->m_threadName.destroy(getMemoryPool());
 
 		// Re-use the log item
 		newLogItem = first;
@@ -132,15 +131,15 @@ void DeveloperConsole::newLogItem(const LoggerMessageInfo& inf)
 	}
 	else
 	{
-		newLogItem = m_alloc.newInstance<LogItem>();
+		newLogItem = newInstance<LogItem>(getMemoryPool());
 	}
 
 	// Create the new item
 	newLogItem->m_file = inf.m_file;
 	newLogItem->m_func = inf.m_func;
 	newLogItem->m_subsystem = inf.m_subsystem;
-	newLogItem->m_threadName.create(m_alloc, inf.m_threadName);
-	newLogItem->m_msg.create(m_alloc, inf.m_msg);
+	newLogItem->m_threadName.create(getMemoryPool(), inf.m_threadName);
+	newLogItem->m_msg.create(getMemoryPool(), inf.m_msg);
 	newLogItem->m_line = inf.m_line;
 	newLogItem->m_type = inf.m_type;
 

+ 1 - 2
AnKi/Core/DeveloperConsole.h

@@ -26,7 +26,7 @@ public:
 
 	~DeveloperConsole();
 
-	Error init(AllocAlignedCallback allocCb, void* allocCbUserData, ScriptManager* scriptManager);
+	Error init(ScriptManager* scriptManager);
 
 	void build(CanvasPtr ctx) override;
 
@@ -45,7 +45,6 @@ private:
 		LoggerMessageType m_type;
 	};
 
-	HeapAllocator<U8> m_alloc;
 	FontPtr m_font;
 	IntrusiveList<LogItem> m_logItems;
 	U32 m_logItemCount = 0;

+ 14 - 13
AnKi/Core/GpuMemoryPools.cpp

@@ -15,8 +15,9 @@ VertexGpuMemoryPool::~VertexGpuMemoryPool()
 	// Do nothing
 }
 
-Error VertexGpuMemoryPool::init(GenericMemoryPoolAllocator<U8> alloc, GrManager* gr, const ConfigSet& cfg)
+Error VertexGpuMemoryPool::init(HeapMemoryPool* pool, GrManager* gr, const ConfigSet& cfg)
 {
+	ANKI_ASSERT(pool && gr);
 	m_gr = gr;
 
 	// Create the GPU buffer.
@@ -37,7 +38,7 @@ Error VertexGpuMemoryPool::init(GenericMemoryPoolAllocator<U8> alloc, GrManager*
 	m_vertBuffer = gr->newBuffer(bufferInit);
 
 	// Init the rest
-	m_buddyAllocator.init(alloc, __builtin_ctzll(bufferInit.m_size));
+	m_buddyAllocator.init(pool, __builtin_ctzll(bufferInit.m_size));
 
 	return Error::kNone;
 }
@@ -81,23 +82,23 @@ Error StagingGpuMemoryPool::init(GrManager* gr, const ConfigSet& cfg)
 {
 	m_gr = gr;
 
-	m_perFrameBuffers[StagingGpuMemoryType::UNIFORM].m_size = cfg.getCoreUniformPerFrameMemorySize();
-	m_perFrameBuffers[StagingGpuMemoryType::STORAGE].m_size = cfg.getCoreStoragePerFrameMemorySize();
-	m_perFrameBuffers[StagingGpuMemoryType::VERTEX].m_size = cfg.getCoreVertexPerFrameMemorySize();
-	m_perFrameBuffers[StagingGpuMemoryType::TEXTURE].m_size = cfg.getCoreTextureBufferPerFrameMemorySize();
+	m_perFrameBuffers[StagingGpuMemoryType::kUniform].m_size = cfg.getCoreUniformPerFrameMemorySize();
+	m_perFrameBuffers[StagingGpuMemoryType::kStorage].m_size = cfg.getCoreStoragePerFrameMemorySize();
+	m_perFrameBuffers[StagingGpuMemoryType::kVertex].m_size = cfg.getCoreVertexPerFrameMemorySize();
+	m_perFrameBuffers[StagingGpuMemoryType::kTexture].m_size = cfg.getCoreTextureBufferPerFrameMemorySize();
 
-	initBuffer(StagingGpuMemoryType::UNIFORM, gr->getDeviceCapabilities().m_uniformBufferBindOffsetAlignment,
+	initBuffer(StagingGpuMemoryType::kUniform, gr->getDeviceCapabilities().m_uniformBufferBindOffsetAlignment,
 			   gr->getDeviceCapabilities().m_uniformBufferMaxRange, BufferUsageBit::kAllUniform, *gr);
 
-	initBuffer(StagingGpuMemoryType::STORAGE,
+	initBuffer(StagingGpuMemoryType::kStorage,
 			   max(gr->getDeviceCapabilities().m_storageBufferBindOffsetAlignment,
 				   gr->getDeviceCapabilities().m_sbtRecordAlignment),
 			   gr->getDeviceCapabilities().m_storageBufferMaxRange, BufferUsageBit::kAllStorage | BufferUsageBit::kSBT,
 			   *gr);
 
-	initBuffer(StagingGpuMemoryType::VERTEX, 16, kMaxU32, BufferUsageBit::kVertex | BufferUsageBit::kIndex, *gr);
+	initBuffer(StagingGpuMemoryType::kVertex, 16, kMaxU32, BufferUsageBit::kVertex | BufferUsageBit::kIndex, *gr);
 
-	initBuffer(StagingGpuMemoryType::TEXTURE, gr->getDeviceCapabilities().m_textureBufferBindOffsetAlignment,
+	initBuffer(StagingGpuMemoryType::kTexture, gr->getDeviceCapabilities().m_textureBufferBindOffsetAlignment,
 			   gr->getDeviceCapabilities().m_textureBufferMaxRange, BufferUsageBit::kAllTexture, *gr);
 
 	return Error::kNone;
@@ -149,7 +150,7 @@ void* StagingGpuMemoryPool::tryAllocateFrame(PtrSize size, StagingGpuMemoryType
 
 void StagingGpuMemoryPool::endFrame()
 {
-	for(StagingGpuMemoryType usage = StagingGpuMemoryType::UNIFORM; usage < StagingGpuMemoryType::COUNT; ++usage)
+	for(StagingGpuMemoryType usage : EnumIterable<StagingGpuMemoryType>())
 	{
 		PerFrameBuffer& buff = m_perFrameBuffers[usage];
 
@@ -158,10 +159,10 @@ void StagingGpuMemoryPool::endFrame()
 			// Increase the counters
 			switch(usage)
 			{
-			case StagingGpuMemoryType::UNIFORM:
+			case StagingGpuMemoryType::kUniform:
 				ANKI_TRACE_INC_COUNTER(STAGING_UNIFORMS_SIZE, buff.m_alloc.getUnallocatedMemorySize());
 				break;
-			case StagingGpuMemoryType::STORAGE:
+			case StagingGpuMemoryType::kStorage:
 				ANKI_TRACE_INC_COUNTER(STAGING_STORAGE_SIZE, buff.m_alloc.getUnallocatedMemorySize());
 				break;
 			default:

+ 10 - 8
AnKi/Core/GpuMemoryPools.h

@@ -30,7 +30,7 @@ public:
 
 	VertexGpuMemoryPool& operator=(const VertexGpuMemoryPool&) = delete; // Non-copyable
 
-	Error init(GenericMemoryPoolAllocator<U8> alloc, GrManager* gr, const ConfigSet& cfg);
+	Error init(HeapMemoryPool* pool, GrManager* gr, const ConfigSet& cfg);
 
 	Error allocate(PtrSize size, PtrSize& offset);
 
@@ -54,11 +54,13 @@ private:
 
 enum class StagingGpuMemoryType : U8
 {
-	UNIFORM,
-	STORAGE,
-	VERTEX,
-	TEXTURE,
-	COUNT
+	kUniform,
+	kStorage,
+	kVertex,
+	kTexture,
+
+	kCount,
+	kFirst = 0,
 };
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(StagingGpuMemoryType)
 
@@ -69,7 +71,7 @@ public:
 	BufferPtr m_buffer;
 	PtrSize m_offset = 0;
 	PtrSize m_range = 0;
-	StagingGpuMemoryType m_type = StagingGpuMemoryType::COUNT;
+	StagingGpuMemoryType m_type = StagingGpuMemoryType::kCount;
 
 	StagingGpuMemoryToken() = default;
 
@@ -126,7 +128,7 @@ private:
 	};
 
 	GrManager* m_gr = nullptr;
-	Array<PerFrameBuffer, U(StagingGpuMemoryType::COUNT)> m_perFrameBuffers;
+	Array<PerFrameBuffer, U(StagingGpuMemoryType::kCount)> m_perFrameBuffers;
 
 	void initBuffer(StagingGpuMemoryType type, U32 alignment, PtrSize maxAllocSize, BufferUsageBit usage,
 					GrManager& gr);

+ 5 - 4
AnKi/Core/MaliHwCounters.cpp

@@ -13,11 +13,12 @@
 
 namespace anki {
 
-MaliHwCounters::MaliHwCounters(GenericMemoryPoolAllocator<U8> alloc)
-	: m_alloc(alloc)
+MaliHwCounters::MaliHwCounters(BaseMemoryPool* pool)
+	: m_pool(pool)
 {
+	ANKI_ASSERT(pool);
 #if ANKI_HWCPIPE_ENABLE
-	hwcpipe::HWCPipe* hwc = m_alloc.newInstance<hwcpipe::HWCPipe>();
+	hwcpipe::HWCPipe* hwc = newInstance<hwcpipe::HWCPipe>(*m_pool);
 	hwc->set_enabled_gpu_counters({hwcpipe::GpuCounter::GpuCycles, hwcpipe::GpuCounter::ExternalMemoryWriteBytes,
 								   hwcpipe::GpuCounter::ExternalMemoryReadBytes});
 
@@ -34,7 +35,7 @@ MaliHwCounters::~MaliHwCounters()
 #if ANKI_HWCPIPE_ENABLE
 	hwcpipe::HWCPipe* hwc = static_cast<hwcpipe::HWCPipe*>(m_impl);
 	hwc->stop();
-	m_alloc.deleteInstance(hwc);
+	deleteInstance(*m_pool, hwc);
 	m_impl = nullptr;
 #endif
 }

+ 2 - 2
AnKi/Core/MaliHwCounters.h

@@ -27,7 +27,7 @@ public:
 class MaliHwCounters
 {
 public:
-	MaliHwCounters(GenericMemoryPoolAllocator<U8> alloc);
+	MaliHwCounters(BaseMemoryPool* pool);
 
 	MaliHwCounters(const MaliHwCounters&) = delete; // Non-copyable
 
@@ -38,7 +38,7 @@ public:
 	void sample(MaliHwCountersOut& out);
 
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	void* m_impl = nullptr;
 };
 /// @}

+ 1 - 1
AnKi/Core/NativeWindow.h

@@ -63,7 +63,7 @@ protected:
 	U32 m_width = 0;
 	U32 m_height = 0;
 
-	HeapAllocator<U8> m_alloc;
+	HeapMemoryPool m_pool;
 
 	NativeWindow()
 	{

+ 13 - 9
AnKi/Core/NativeWindowSdl.cpp

@@ -13,15 +13,15 @@ namespace anki {
 
 Error NativeWindow::newInstance(const NativeWindowInitInfo& initInfo, NativeWindow*& nativeWindow)
 {
-	HeapAllocator<U8> alloc(initInfo.m_allocCallback, initInfo.m_allocCallbackUserData, "NativeWindow");
-	NativeWindowSdl* sdlwin = alloc.newInstance<NativeWindowSdl>();
-
-	sdlwin->m_alloc = alloc;
+	NativeWindowSdl* sdlwin = static_cast<NativeWindowSdl*>(initInfo.m_allocCallback(
+		initInfo.m_allocCallbackUserData, nullptr, sizeof(NativeWindowSdl), alignof(NativeWindowSdl)));
+	callConstructor(*sdlwin);
 
 	const Error err = sdlwin->init(initInfo);
 	if(err)
 	{
-		alloc.deleteInstance(sdlwin);
+		callDestructor(*sdlwin);
+		initInfo.m_allocCallback(initInfo.m_allocCallbackUserData, sdlwin, 0, 0);
 		nativeWindow = nullptr;
 		return err;
 	}
@@ -37,8 +37,10 @@ void NativeWindow::deleteInstance(NativeWindow* window)
 	if(window)
 	{
 		NativeWindowSdl* self = static_cast<NativeWindowSdl*>(window);
-		HeapAllocator<U8> alloc = self->m_alloc;
-		alloc.deleteInstance(self);
+		AllocAlignedCallback callback = self->m_pool.getAllocationCallback();
+		void* userData = self->m_pool.getAllocationCallbackUserData();
+		callDestructor(*self);
+		callback(userData, self, 0, 0);
 	}
 }
 
@@ -55,13 +57,15 @@ NativeWindowSdl::~NativeWindowSdl()
 		SDL_DestroyWindow(m_window);
 	}
 
-	SDL_QuitSubSystem(INIT_SUBSYSTEMS);
+	SDL_QuitSubSystem(kInitSubsystems);
 	SDL_Quit();
 }
 
 Error NativeWindowSdl::init(const NativeWindowInitInfo& init)
 {
-	if(SDL_Init(INIT_SUBSYSTEMS) != 0)
+	m_pool.init(init.m_allocCallback, init.m_allocCallbackUserData);
+
+	if(SDL_Init(kInitSubsystems) != 0)
 	{
 		ANKI_CORE_LOGE("SDL_Init() failed: %s", SDL_GetError());
 		return Error::kFunctionFailed;

+ 1 - 1
AnKi/Core/NativeWindowSdl.h

@@ -21,7 +21,7 @@ public:
 	Error init(const NativeWindowInitInfo& init);
 
 private:
-	static constexpr U32 INIT_SUBSYSTEMS =
+	static constexpr U32 kInitSubsystems =
 		SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
 };
 

+ 1 - 1
AnKi/Core/StatsUi.cpp

@@ -36,7 +36,7 @@ void StatsUi::labelBytes(PtrSize val, CString name) const
 
 	b = val;
 
-	StringRaii timestamp(getAllocator());
+	StringRaii timestamp(&getMemoryPool());
 	if(gb)
 	{
 		timestamp.sprintf("%s: %zu,%04zu,%04zu,%04zu", name.cstr(), gb, mb, kb, b);

+ 8 - 8
AnKi/Core/StdinListener.cpp

@@ -21,15 +21,16 @@ StdinListener::~StdinListener()
 
 	for(String& s : m_q)
 	{
-		s.destroy(m_alloc);
+		s.destroy(*m_pool);
 	}
 
-	m_q.destroy(m_alloc);
+	m_q.destroy(*m_pool);
 }
 
-Error StdinListener::create(HeapAllocator<String>& alloc)
+Error StdinListener::create(HeapMemoryPool* pool)
 {
-	m_alloc = alloc;
+	ANKI_ASSERT(pool);
+	m_pool = pool;
 	m_thrd.start(this, workingFunc);
 
 	return Error::kNone;
@@ -46,10 +47,9 @@ Error StdinListener::workingFunc(ThreadCallbackInfo& info)
 		buff[m] = '\0';
 
 		LockGuard<Mutex>(self.m_mtx);
-		auto alloc = self.m_alloc;
-		self.m_q.emplaceBack(self.m_alloc);
+		self.m_q.emplaceBack(*self.m_pool);
 
-		self.m_q.getBack().create(alloc, &buff[0]);
+		self.m_q.getBack().create(*self.m_pool, &buff[0]);
 	}
 
 	return Error::kNone;
@@ -63,7 +63,7 @@ String StdinListener::getLine()
 	if(!m_q.isEmpty())
 	{
 		ret = std::move(m_q.getFront());
-		m_q.popFront(m_alloc);
+		m_q.popFront(*m_pool);
 	}
 
 	m_mtx.unlock();

+ 2 - 2
AnKi/Core/StdinListener.h

@@ -26,13 +26,13 @@ public:
 
 	~StdinListener();
 
-	Error create(HeapAllocator<String>& alloc);
+	Error create(HeapMemoryPool* pool);
 
 	/// Get line from the queue or return an empty string
 	String getLine();
 
 private:
-	HeapAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	List<String> m_q;
 	Mutex m_mtx; ///< Protect the queue
 	Thread m_thrd; ///< The thread

+ 37 - 37
AnKi/Importer/GltfImporter.cpp

@@ -149,8 +149,8 @@ static Bool stringsExist(const HashMapRaii<CString, StringRaii>& map, const std:
 	return false;
 }
 
-GltfImporter::GltfImporter(GenericMemoryPoolAllocator<U8> alloc)
-	: m_alloc(alloc)
+GltfImporter::GltfImporter(BaseMemoryPool* pool)
+	: m_pool(pool)
 {
 }
 
@@ -162,7 +162,7 @@ GltfImporter::~GltfImporter()
 		m_gltf = nullptr;
 	}
 
-	m_alloc.deleteInstance(m_hive);
+	deleteInstance(*m_pool, m_hive);
 }
 
 Error GltfImporter::init(const GltfImporterInitInfo& initInfo)
@@ -211,7 +211,7 @@ Error GltfImporter::init(const GltfImporterInitInfo& initInfo)
 	if(initInfo.m_threadCount > 0)
 	{
 		const U32 threadCount = min(getCpuCoresCount(), initInfo.m_threadCount);
-		m_hive = m_alloc.newInstance<ThreadHive>(threadCount, m_alloc, true);
+		m_hive = newInstance<ThreadHive>(*m_pool, threadCount, m_pool, true);
 	}
 
 	return Error::kNone;
@@ -221,7 +221,7 @@ Error GltfImporter::writeAll()
 {
 	populateNodePtrToIdx();
 
-	StringRaii sceneFname(m_alloc);
+	StringRaii sceneFname(m_pool);
 	sceneFname.sprintf("%sScene.lua", m_outDir.cstr());
 	ANKI_CHECK(m_sceneFile.open(sceneFname.toCString(), FileOpenFlag::kWrite));
 	ANKI_CHECK(m_sceneFile.writeTextf("-- Generated by: %s\n", m_comment.cstr()));
@@ -233,7 +233,7 @@ Error GltfImporter::writeAll()
 	{
 		for(cgltf_node* const* node = scene->nodes; node < scene->nodes + scene->nodes_count && !err; ++node)
 		{
-			err = visitNode(*(*node), Transform::getIdentity(), HashMapRaii<CString, StringRaii>(m_alloc));
+			err = visitNode(*(*node), Transform::getIdentity(), HashMapRaii<CString, StringRaii>(m_pool));
 		}
 	}
 
@@ -273,7 +273,7 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, HashMapRaii<CString, S
 		return Error::kNone;
 	}
 
-	DynamicArrayRaii<char, PtrSize> json(m_alloc);
+	DynamicArrayRaii<char, PtrSize> json(m_pool);
 	json.create(extrasSize + 1);
 	cgltf_result res = cgltf_copy_extras_json(m_gltf, &extras, &json[0], &extrasSize);
 	if(res != cgltf_result_success)
@@ -294,14 +294,14 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, HashMapRaii<CString, S
 		return Error::kNone;
 	}
 
-	DynamicArrayRaii<jsmntok_t> tokens(m_alloc);
+	DynamicArrayRaii<jsmntok_t> tokens(m_pool);
 	tokens.create(U32(tokenCount));
 
 	// Get tokens
 	jsmn_init(&parser);
 	jsmn_parse(&parser, jsonTxt.cstr(), jsonTxt.getLength(), &tokens[0], tokens.getSize());
 
-	StringListRaii tokenStrings(m_alloc);
+	StringListRaii tokenStrings(m_pool);
 	for(const jsmntok_t& token : tokens)
 	{
 		if(token.type != JSMN_STRING && token.type != JSMN_PRIMITIVE)
@@ -309,7 +309,7 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, HashMapRaii<CString, S
 			continue;
 		}
 
-		StringRaii tokenStr(m_alloc);
+		StringRaii tokenStr(m_pool);
 		tokenStr.create(&jsonTxt[token.start], &jsonTxt[token.end]);
 		tokenStrings.pushBack(tokenStr.toCString());
 	}
@@ -327,7 +327,7 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, HashMapRaii<CString, S
 		auto it2 = it;
 		++it2;
 
-		out.emplace(it->toCString(), StringRaii(m_alloc, it2->toCString()));
+		out.emplace(it->toCString(), StringRaii(m_pool, it2->toCString()));
 		++it;
 		++it;
 	}
@@ -360,7 +360,7 @@ void GltfImporter::populateNodePtrToIdx()
 
 StringRaii GltfImporter::getNodeName(const cgltf_node& node)
 {
-	StringRaii out(m_alloc);
+	StringRaii out(m_pool);
 
 	if(node.name)
 	{
@@ -378,7 +378,7 @@ StringRaii GltfImporter::getNodeName(const cgltf_node& node)
 
 Error GltfImporter::parseArrayOfNumbers(CString str, DynamicArrayRaii<F64>& out, const U32* expectedArraySize)
 {
-	StringListRaii list(m_alloc);
+	StringListRaii list(m_pool);
 	list.splitString(str, ' ');
 
 	out.create(U32(list.getSize()));
@@ -418,7 +418,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 		return threadErr;
 	}
 
-	HashMapRaii<CString, StringRaii> outExtras(m_alloc);
+	HashMapRaii<CString, StringRaii> outExtras(m_pool);
 	if(node.light)
 	{
 		ANKI_CHECK(writeLight(node, parentExtras));
@@ -479,7 +479,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 
 			if((it = extras.find("skybox_solid_color")) != extras.getEnd())
 			{
-				StringListRaii tokens(m_alloc);
+				StringListRaii tokens(m_pool);
 				tokens.splitString(*it, ' ');
 				if(tokens.getSize() != 3)
 				{
@@ -616,13 +616,13 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 		}
 		else if((it = extras.find("decal")) != extras.getEnd() && (*it == "true" || *it == "1"))
 		{
-			StringRaii diffuseAtlas(m_alloc);
+			StringRaii diffuseAtlas(m_pool);
 			if((it = extras.find("decal_diffuse_atlas")) != extras.getEnd())
 			{
 				diffuseAtlas.create(it->toCString());
 			}
 
-			StringRaii diffuseSubtexture(m_alloc);
+			StringRaii diffuseSubtexture(m_pool);
 			if((it = extras.find("decal_diffuse_sub_texture")) != extras.getEnd())
 			{
 				diffuseSubtexture.create(it->toCString());
@@ -634,13 +634,13 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 				ANKI_CHECK(it->toNumber(diffuseFactor));
 			}
 
-			StringRaii specularRougnessMetallicAtlas(m_alloc);
+			StringRaii specularRougnessMetallicAtlas(m_pool);
 			if((it = extras.find("decal_specular_roughness_metallic_atlas")) != extras.getEnd())
 			{
 				specularRougnessMetallicAtlas.create(it->toCString());
 			}
 
-			StringRaii specularRougnessMetallicSubtexture(m_alloc);
+			StringRaii specularRougnessMetallicSubtexture(m_pool);
 			if((it = extras.find("decal_specular_roughness_metallic_sub_texture")) != extras.getEnd())
 			{
 				specularRougnessMetallicSubtexture.create(it->toCString());
@@ -688,7 +688,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 				const cgltf_skin* m_skin;
 				Bool m_rayTracing;
 			};
-			Ctx* ctx = m_alloc.newInstance<Ctx>();
+			Ctx* ctx = newInstance<Ctx>(*m_pool);
 			ctx->m_importer = this;
 			ctx->m_mesh = node.mesh;
 			for(U32 i = 0; i < node.mesh->primitives_count; ++i)
@@ -756,7 +756,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 					self.m_importer->m_errorInThread.store(err._getCode());
 				}
 
-				self.m_importer->m_alloc.deleteInstance(&self);
+				deleteInstance(*self.m_importer->m_pool, &self);
 			};
 
 			if(m_hive != nullptr)
@@ -838,11 +838,11 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh)
 	const StringRaii modelFname = computeModelResourceFilename(mesh);
 	ANKI_IMPORTER_LOGV("Importing model %s", modelFname.cstr());
 
-	HashMapRaii<CString, StringRaii> extras(m_alloc);
+	HashMapRaii<CString, StringRaii> extras(m_pool);
 	ANKI_CHECK(getExtras(mesh.extras, extras));
 
 	File file;
-	StringRaii modelFullFname(m_alloc);
+	StringRaii modelFullFname(m_pool);
 	modelFullFname.sprintf("%s/%s", m_outDir.cstr(), modelFname.cstr());
 	ANKI_CHECK(file.open(modelFullFname, FileOpenFlag::kWrite));
 
@@ -877,7 +877,7 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh)
 			ANKI_CHECK(file.writeTextf("\t\t\t<mesh2>%s%s</mesh2>\n", m_rpath.cstr(), meshFname.cstr()));
 		}
 
-		HashMapRaii<CString, StringRaii> materialExtras(m_alloc);
+		HashMapRaii<CString, StringRaii> materialExtras(m_pool);
 		ANKI_CHECK(getExtras(mesh.primitives[primIdx].material->extras, materialExtras));
 		auto mtlOverride = materialExtras.find("material_override");
 		if(mtlOverride != materialExtras.getEnd())
@@ -902,12 +902,12 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh)
 
 Error GltfImporter::writeSkeleton(const cgltf_skin& skin)
 {
-	StringRaii fname(m_alloc);
+	StringRaii fname(m_pool);
 	fname.sprintf("%s%s", m_outDir.cstr(), computeSkeletonResourceFilename(skin).cstr());
 	ANKI_IMPORTER_LOGV("Importing skeleton %s", fname.cstr());
 
 	// Get matrices
-	DynamicArrayRaii<Mat4> boneMats(m_alloc);
+	DynamicArrayRaii<Mat4> boneMats(m_pool);
 	readAccessor(*skin.inverse_bind_matrices, boneMats);
 	if(boneMats.getSize() != skin.joints_count)
 	{
@@ -926,7 +926,7 @@ Error GltfImporter::writeSkeleton(const cgltf_skin& skin)
 	{
 		const cgltf_node& boneNode = *skin.joints[i];
 
-		StringRaii parent(m_alloc);
+		StringRaii parent(m_pool);
 
 		// Name & parent
 		ANKI_CHECK(file.writeTextf("\t\t<bone name=\"%s\" ", getNodeName(boneNode).cstr()));
@@ -1059,7 +1059,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const HashMapRaii<CString
 
 		if(lsSpriteSize != extras.getEnd())
 		{
-			DynamicArrayRaii<F64> numbers(m_alloc);
+			DynamicArrayRaii<F64> numbers(m_pool);
 			const U32 count = 2;
 			ANKI_CHECK(parseArrayOfNumbers(lsSpriteSize->toCString(), numbers, &count));
 
@@ -1068,7 +1068,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const HashMapRaii<CString
 
 		if(lsColor != extras.getEnd())
 		{
-			DynamicArrayRaii<F64> numbers(m_alloc);
+			DynamicArrayRaii<F64> numbers(m_pool);
 			const U32 count = 4;
 			ANKI_CHECK(parseArrayOfNumbers(lsColor->toCString(), numbers, &count));
 
@@ -1085,7 +1085,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const HashMapRaii<CString
 
 		if(lightEventIntensity != extras.getEnd())
 		{
-			DynamicArrayRaii<F64> numbers(m_alloc);
+			DynamicArrayRaii<F64> numbers(m_pool);
 			const U32 count = 4;
 			ANKI_CHECK(parseArrayOfNumbers(lightEventIntensity->toCString(), numbers, &count));
 			ANKI_CHECK(m_sceneFile.writeTextf("event:setIntensityMultiplier(Vec4.new(%f, %f, %f, %f))\n", numbers[0],
@@ -1094,7 +1094,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const HashMapRaii<CString
 
 		if(lightEventFrequency != extras.getEnd())
 		{
-			DynamicArrayRaii<F64> numbers(m_alloc);
+			DynamicArrayRaii<F64> numbers(m_pool);
 			const U32 count = 2;
 			ANKI_CHECK(parseArrayOfNumbers(lightEventFrequency->toCString(), numbers, &count));
 			ANKI_CHECK(m_sceneFile.writeTextf("event:setFrequency(%f, %f)\n", numbers[0], numbers[1]));
@@ -1152,7 +1152,7 @@ Error GltfImporter::writeModelNode(const cgltf_node& node, const HashMapRaii<CSt
 
 StringRaii GltfImporter::computeModelResourceFilename(const cgltf_mesh& mesh) const
 {
-	StringListRaii list(m_alloc);
+	StringListRaii list(m_pool);
 
 	list.pushBack(mesh.name);
 
@@ -1162,7 +1162,7 @@ StringRaii GltfImporter::computeModelResourceFilename(const cgltf_mesh& mesh) co
 		list.pushBackSprintf("_%s", mtlName);
 	}
 
-	StringRaii joined(m_alloc);
+	StringRaii joined(m_pool);
 	list.join("", joined);
 
 	const U64 hash = computeHash(joined.getBegin(), joined.getLength());
@@ -1177,7 +1177,7 @@ StringRaii GltfImporter::computeMeshResourceFilename(const cgltf_mesh& mesh, U32
 {
 	const U64 hash = computeHash(mesh.name, strlen(mesh.name));
 
-	StringRaii out(m_alloc);
+	StringRaii out(m_pool);
 
 	out.sprintf("%.64s_lod%u_%" PRIx64 ".ankimesh", mesh.name, lod, hash); // Limit the filename size
 
@@ -1188,7 +1188,7 @@ StringRaii GltfImporter::computeMaterialResourceFilename(const cgltf_material& m
 {
 	const U64 hash = computeHash(mtl.name, strlen(mtl.name));
 
-	StringRaii out(m_alloc);
+	StringRaii out(m_pool);
 
 	out.sprintf("%.64s_%" PRIx64 ".ankimtl", mtl.name, hash); // Limit the filename size
 
@@ -1199,7 +1199,7 @@ StringRaii GltfImporter::computeAnimationResourceFilename(const cgltf_animation&
 {
 	const U64 hash = computeHash(anim.name, strlen(anim.name));
 
-	StringRaii out(m_alloc);
+	StringRaii out(m_pool);
 
 	out.sprintf("%.64s_%" PRIx64 ".ankianim", anim.name, hash); // Limit the filename size
 
@@ -1210,7 +1210,7 @@ StringRaii GltfImporter::computeSkeletonResourceFilename(const cgltf_skin& skin)
 {
 	const U64 hash = computeHash(skin.name, strlen(skin.name));
 
-	StringRaii out(m_alloc);
+	StringRaii out(m_pool);
 
 	out.sprintf("%.64s_%" PRIx64 ".ankiskel", skin.name, hash); // Limit the filename size
 

+ 9 - 9
AnKi/Importer/GltfImporter.h

@@ -40,7 +40,7 @@ public:
 class GltfImporter
 {
 public:
-	GltfImporter(GenericMemoryPoolAllocator<U8> alloc);
+	GltfImporter(BaseMemoryPool* pool);
 
 	~GltfImporter();
 
@@ -59,12 +59,12 @@ private:
 	};
 
 	// Data
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 
-	StringRaii m_inputFname = {m_alloc};
-	StringRaii m_outDir = {m_alloc};
-	StringRaii m_rpath = {m_alloc};
-	StringRaii m_texrpath = {m_alloc};
+	StringRaii m_inputFname = {m_pool};
+	StringRaii m_outDir = {m_pool};
+	StringRaii m_rpath = {m_pool};
+	StringRaii m_texrpath = {m_pool};
 
 	cgltf_data* m_gltf = nullptr;
 
@@ -76,14 +76,14 @@ private:
 
 	Atomic<I32> m_errorInThread{0};
 
-	HashMapRaii<const void*, U32, PtrHasher> m_nodePtrToIdx{m_alloc}; ///< Need an index for the unnamed nodes.
+	HashMapRaii<const void*, U32, PtrHasher> m_nodePtrToIdx = {m_pool}; ///< Need an index for the unnamed nodes.
 
 	F32 m_lodFactor = 1.0f;
 	U32 m_lodCount = 1;
 	F32 m_lightIntensityScale = 1.0f;
 	Bool m_optimizeMeshes = false;
 	Bool m_optimizeAnimations = false;
-	StringRaii m_comment{m_alloc};
+	StringRaii m_comment = {m_pool};
 
 	/// Don't generate LODs for meshes with less vertices than this number.
 	U32 m_skipLodVertexCountThreshold = 256;
@@ -108,7 +108,7 @@ private:
 
 	StringRaii fixFilename(CString in) const
 	{
-		StringRaii out(m_alloc, in);
+		StringRaii out(m_pool, in);
 		out.replaceAll("|", "_");
 		out.replaceAll(" ", "_");
 		return out;

+ 14 - 14
AnKi/Importer/GltfImporterAnimation.cpp

@@ -25,11 +25,11 @@ public:
 	DynamicArrayRaii<GltfAnimKey<F32>> m_scales;
 	const cgltf_node* m_targetNode;
 
-	GltfAnimChannel(GenericMemoryPoolAllocator<U8> alloc)
-		: m_name(alloc)
-		, m_positions(alloc)
-		, m_rotations(alloc)
-		, m_scales(alloc)
+	GltfAnimChannel(BaseMemoryPool* pool)
+		: m_name(pool)
+		, m_positions(pool)
+		, m_rotations(pool)
+		, m_scales(pool)
 	{
 	}
 };
@@ -106,14 +106,14 @@ static void optimizeChannel(DynamicArrayRaii<GltfAnimKey<T>>& arr, const T& iden
 
 Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 {
-	StringRaii fname(m_alloc);
+	StringRaii fname(m_pool);
 	StringRaii animFname = computeAnimationResourceFilename(anim);
 	fname.sprintf("%s%s", m_outDir.cstr(), animFname.cstr());
 	fname = fixFilename(fname);
 	ANKI_IMPORTER_LOGV("Importing animation %s", fname.cstr());
 
 	// Gather the channels
-	HashMapRaii<CString, Array<const cgltf_animation_channel*, 3>> channelMap(m_alloc);
+	HashMapRaii<CString, Array<const cgltf_animation_channel*, 3>> channelMap(m_pool);
 	U32 channelCount = 0;
 	for(U i = 0; i < anim.channels_count; ++i)
 	{
@@ -152,7 +152,7 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 	}
 
 	// Gather the keys
-	DynamicArrayRaii<GltfAnimChannel> tempChannels(m_alloc, channelCount, m_alloc);
+	DynamicArrayRaii<GltfAnimChannel> tempChannels(m_pool, channelCount, m_pool);
 	channelCount = 0;
 	for(auto it = channelMap.getBegin(); it != channelMap.getEnd(); ++it)
 	{
@@ -167,9 +167,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[0])
 		{
 			const cgltf_animation_channel& channel = *arr[0];
-			DynamicArrayRaii<F32> keys(m_alloc);
+			DynamicArrayRaii<F32> keys(m_pool);
 			readAccessor(*channel.sampler->input, keys);
-			DynamicArrayRaii<Vec3> positions(m_alloc);
+			DynamicArrayRaii<Vec3> positions(m_pool);
 			readAccessor(*channel.sampler->output, positions);
 			if(keys.getSize() != positions.getSize())
 			{
@@ -191,9 +191,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[1])
 		{
 			const cgltf_animation_channel& channel = *arr[1];
-			DynamicArrayRaii<F32> keys(m_alloc);
+			DynamicArrayRaii<F32> keys(m_pool);
 			readAccessor(*channel.sampler->input, keys);
-			DynamicArrayRaii<Quat> rotations(m_alloc);
+			DynamicArrayRaii<Quat> rotations(m_pool);
 			readAccessor(*channel.sampler->output, rotations);
 			if(keys.getSize() != rotations.getSize())
 			{
@@ -215,9 +215,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[2])
 		{
 			const cgltf_animation_channel& channel = *arr[2];
-			DynamicArrayRaii<F32> keys(m_alloc);
+			DynamicArrayRaii<F32> keys(m_pool);
 			readAccessor(*channel.sampler->input, keys);
-			DynamicArrayRaii<Vec3> scales(m_alloc);
+			DynamicArrayRaii<Vec3> scales(m_pool);
 			readAccessor(*channel.sampler->output, scales);
 			if(keys.getSize() != scales.getSize())
 			{

+ 32 - 32
AnKi/Importer/GltfImporterMaterial.cpp

@@ -59,9 +59,9 @@ static CString getTextureUri(const cgltf_texture_view& view)
 }
 
 /// Read the texture and find out if
-static Error findConstantColorsInImage(CString fname, Vec4& constantColor, GenericMemoryPoolAllocator<U8>& alloc)
+static Error findConstantColorsInImage(CString fname, Vec4& constantColor, BaseMemoryPool& pool)
 {
-	ImageLoader iloader(alloc);
+	ImageLoader iloader(&pool);
 	ANKI_CHECK(iloader.load(fname));
 	ANKI_ASSERT(iloader.getColorFormat() == ImageBinaryColorFormat::kRgba8);
 	ANKI_ASSERT(iloader.getCompression() == ImageBinaryDataCompression::kRaw);
@@ -100,7 +100,7 @@ static Error findConstantColorsInImage(CString fname, Vec4& constantColor, Gener
 
 Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracing)
 {
-	StringRaii fname(m_alloc);
+	StringRaii fname(m_pool);
 	fname.sprintf("%s%s", m_outDir.cstr(), computeMaterialResourceFilename(mtl).cstr());
 	ANKI_IMPORTER_LOGV("Importing material %s", fname.cstr());
 
@@ -110,10 +110,10 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		return Error::kUserData;
 	}
 
-	HashMapRaii<CString, StringRaii> extras(m_alloc);
+	HashMapRaii<CString, StringRaii> extras(m_pool);
 	ANKI_CHECK(getExtras(mtl.extras, extras));
 
-	StringRaii xml(m_alloc);
+	StringRaii xml(m_pool);
 	xml.append(XmlDocument::kXmlHeader);
 	xml.append("\n");
 	xml.append(kMaterialTemplate);
@@ -128,14 +128,14 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	{
 		const CString fname = getTextureUri(mtl.pbr_metallic_roughness.base_color_texture);
 
-		StringRaii uri(m_alloc);
+		StringRaii uri(m_pool);
 		uri.sprintf("%s%s", m_texrpath.cstr(), fname.cstr());
 
-		xml.replaceAll("%diff%", StringRaii(m_alloc).sprintf("<input name=\"m_diffTex\" value=\"%s\"/>", uri.cstr()));
+		xml.replaceAll("%diff%", StringRaii(m_pool).sprintf("<input name=\"m_diffTex\" value=\"%s\"/>", uri.cstr()));
 		xml.replaceAll("%diffTexMutator%", "1");
 
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, m_alloc));
+		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, *m_pool));
 
 		const Bool constantAlpha = constantColor.w() >= 0.0f;
 		xml.replaceAll("%alphaTestMutator%", (constantAlpha) ? "0" : "1");
@@ -144,8 +144,8 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	{
 		const F32* diffCol = &mtl.pbr_metallic_roughness.base_color_factor[0];
 
-		xml.replaceAll("%diff%", StringRaii(m_alloc).sprintf("<input name=\"m_diffColor\" value=\"%f %f %f\"/>",
-															 diffCol[0], diffCol[1], diffCol[2]));
+		xml.replaceAll("%diff%", StringRaii(m_pool).sprintf("<input name=\"m_diffColor\" value=\"%f %f %f\"/>",
+															diffCol[0], diffCol[1], diffCol[2]));
 
 		xml.replaceAll("%diffTexMutator%", "0");
 		xml.replaceAll("%alphaTestMutator%", "0");
@@ -157,7 +157,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		auto it = extras.find("specular");
 		if(it != extras.getEnd())
 		{
-			StringListRaii tokens(m_alloc);
+			StringListRaii tokens(m_pool);
 			tokens.splitString(it->toCString(), ' ');
 			if(tokens.getSize() != 3)
 			{
@@ -177,8 +177,8 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 			specular = Vec3(0.04f);
 		}
 
-		xml.replaceAll("%spec%", StringRaii(m_alloc).sprintf("<input name=\"m_specColor\" value=\"%f %f %f\"/>",
-															 specular.x(), specular.y(), specular.z()));
+		xml.replaceAll("%spec%", StringRaii(m_pool).sprintf("<input name=\"m_specColor\" value=\"%f %f %f\"/>",
+															specular.x(), specular.y(), specular.z()));
 
 		xml.replaceAll("%specTexMutator%", "0");
 	}
@@ -190,7 +190,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		const CString fname = getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture);
 
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, m_alloc));
+		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, *m_pool));
 		constantRoughness = constantColor.y();
 		constantMetaliness = constantColor.z();
 	}
@@ -198,12 +198,12 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	// Roughness
 	if(mtl.pbr_metallic_roughness.metallic_roughness_texture.texture && constantRoughness < 0.0f)
 	{
-		StringRaii uri(m_alloc);
+		StringRaii uri(m_pool);
 		uri.sprintf("%s%s", m_texrpath.cstr(),
 					getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture).cstr());
 
 		xml.replaceAll("%roughness%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_roughnessTex\" value=\"%s\"/>", uri.cstr()));
+					   StringRaii(m_pool).sprintf("<input name=\"m_roughnessTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%roughnessTexMutator%", "1");
 	}
@@ -214,7 +214,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 								  : mtl.pbr_metallic_roughness.roughness_factor;
 
 		xml.replaceAll("%roughness%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_roughness\" value=\"%f\"/>", roughness));
+					   StringRaii(m_pool).sprintf("<input name=\"m_roughness\" value=\"%f\"/>", roughness));
 
 		xml.replaceAll("%roughnessTexMutator%", "0");
 	}
@@ -222,12 +222,12 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	// Metallic
 	if(mtl.pbr_metallic_roughness.metallic_roughness_texture.texture && constantMetaliness < 0.0f)
 	{
-		StringRaii uri(m_alloc);
+		StringRaii uri(m_pool);
 		uri.sprintf("%s%s", m_texrpath.cstr(),
 					getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture).cstr());
 
 		xml.replaceAll("%metallic%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_metallicTex\" value=\"%s\"/>", uri.cstr()));
+					   StringRaii(m_pool).sprintf("<input name=\"m_metallicTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%metalTexMutator%", "1");
 	}
@@ -238,7 +238,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 								  : mtl.pbr_metallic_roughness.metallic_factor;
 
 		xml.replaceAll("%metallic%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_metallic\" value=\"%f\"/>", metalines));
+					   StringRaii(m_pool).sprintf("<input name=\"m_metallic\" value=\"%f\"/>", metalines));
 
 		xml.replaceAll("%metalTexMutator%", "0");
 	}
@@ -247,14 +247,14 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	if(mtl.normal_texture.texture)
 	{
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(getTextureUri(mtl.normal_texture).cstr(), constantColor, m_alloc));
+		ANKI_CHECK(findConstantColorsInImage(getTextureUri(mtl.normal_texture).cstr(), constantColor, *m_pool));
 		if(constantColor.xyz() == -1.0f)
 		{
-			StringRaii uri(m_alloc);
+			StringRaii uri(m_pool);
 			uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.normal_texture).cstr());
 
 			xml.replaceAll("%normal%",
-						   StringRaii(m_alloc).sprintf("<input name=\"m_normalTex\" value=\"%s\"/>", uri.cstr()));
+						   StringRaii(m_pool).sprintf("<input name=\"m_normalTex\" value=\"%s\"/>", uri.cstr()));
 
 			xml.replaceAll("%normalTexMutator%", "1");
 		}
@@ -273,11 +273,11 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	// Emissive texture
 	if(mtl.emissive_texture.texture)
 	{
-		StringRaii uri(m_alloc);
+		StringRaii uri(m_pool);
 		uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.emissive_texture).cstr());
 
 		xml.replaceAll("%emission%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_emissiveTex\" value=\"%s\"/>", uri.cstr()));
+					   StringRaii(m_pool).sprintf("<input name=\"m_emissiveTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%emissiveTexMutator%", "1");
 	}
@@ -285,8 +285,8 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	{
 		const F32* emissionCol = &mtl.emissive_factor[0];
 
-		xml.replaceAll("%emission%", StringRaii(m_alloc).sprintf("<input name=\"m_emission\" value=\"%f %f %f\"/>",
-																 emissionCol[0], emissionCol[1], emissionCol[2]));
+		xml.replaceAll("%emission%", StringRaii(m_pool).sprintf("<input name=\"m_emission\" value=\"%f %f %f\"/>",
+																emissionCol[0], emissionCol[1], emissionCol[2]));
 
 		xml.replaceAll("%emissiveTexMutator%", "0");
 	}
@@ -305,19 +305,19 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		}
 
 		xml.replaceAll("%subsurface%",
-					   StringRaii(m_alloc).sprintf("<input name=\"m_subsurface\" value=\"%f\"/>", subsurface));
+					   StringRaii(m_pool).sprintf("<input name=\"m_subsurface\" value=\"%f\"/>", subsurface));
 	}
 
 	// Height texture
 	auto it = extras.find("height_map");
 	if(it != extras.getEnd())
 	{
-		StringRaii uri(m_alloc);
+		StringRaii uri(m_pool);
 		uri.sprintf("%s%s", m_texrpath.cstr(), it->cstr());
 
-		xml.replaceAll("%height%", StringRaii(m_alloc).sprintf("<input name=\"m_heightTex\" value=\"%s\" \"/>\n"
-															   "\t\t<input name=\"m_heightmapScale\" value=\"0.05\"/>",
-															   uri.cstr()));
+		xml.replaceAll("%height%", StringRaii(m_pool).sprintf("<input name=\"m_heightTex\" value=\"%s\" \"/>\n"
+															  "\t\t<input name=\"m_heightmapScale\" value=\"0.05\"/>",
+															  uri.cstr()));
 
 		xml.replaceAll("%parallaxMutator%", "1");
 	}

+ 27 - 27
AnKi/Importer/GltfImporterMesh.cpp

@@ -139,26 +139,26 @@ public:
 	U32 m_firstIdx = kMaxU32;
 	U32 m_idxCount = kMaxU32;
 
-	SubMesh(GenericMemoryPoolAllocator<U8>& alloc)
-		: m_verts(alloc)
-		, m_indices(alloc)
+	SubMesh(BaseMemoryPool* pool)
+		: m_verts(pool)
+		, m_indices(pool)
 	{
 	}
 };
 
-static void reindexSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> alloc)
+static void reindexSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 {
 	const U32 vertSize = sizeof(submesh.m_verts[0]);
 
-	DynamicArrayRaii<U32> remap(alloc);
+	DynamicArrayRaii<U32> remap(pool);
 	remap.create(submesh.m_verts.getSize(), 0);
 
 	const U32 vertCount = U32(meshopt_generateVertexRemap(&remap[0], &submesh.m_indices[0], submesh.m_indices.getSize(),
 														  &submesh.m_verts[0], submesh.m_verts.getSize(), vertSize));
 
-	DynamicArrayRaii<U32> newIdxArray(alloc);
+	DynamicArrayRaii<U32> newIdxArray(pool);
 	newIdxArray.create(submesh.m_indices.getSize(), 0);
-	DynamicArrayRaii<TempVertex> newVertArray(alloc);
+	DynamicArrayRaii<TempVertex> newVertArray(pool);
 	newVertArray.create(vertCount);
 
 	meshopt_remapIndexBuffer(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &remap[0]);
@@ -169,13 +169,13 @@ static void reindexSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> allo
 }
 
 /// Optimize a submesh using meshoptimizer.
-static void optimizeSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> alloc)
+static void optimizeSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 {
 	const PtrSize vertSize = sizeof(submesh.m_verts[0]);
 
 	// Vert cache
 	{
-		DynamicArrayRaii<U32> newIdxArray(alloc);
+		DynamicArrayRaii<U32> newIdxArray(pool);
 		newIdxArray.create(submesh.m_indices.getSize(), 0);
 
 		meshopt_optimizeVertexCache(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(),
@@ -186,7 +186,7 @@ static void optimizeSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> all
 
 	// Overdraw
 	{
-		DynamicArrayRaii<U32> newIdxArray(alloc);
+		DynamicArrayRaii<U32> newIdxArray(pool);
 		newIdxArray.create(submesh.m_indices.getSize(), 0);
 
 		meshopt_optimizeOverdraw(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(),
@@ -197,7 +197,7 @@ static void optimizeSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> all
 
 	// Vert fetch
 	{
-		DynamicArrayRaii<TempVertex> newVertArray(alloc);
+		DynamicArrayRaii<TempVertex> newVertArray(pool);
 		newVertArray.create(submesh.m_verts.getSize());
 
 		const U32 newVertCount = U32(meshopt_optimizeVertexFetch(&newVertArray[0],
@@ -216,7 +216,7 @@ static void optimizeSubmesh(SubMesh& submesh, GenericMemoryPoolAllocator<U8> all
 }
 
 /// Decimate a submesh using meshoptimizer.
-static void decimateSubmesh(F32 factor, SubMesh& submesh, GenericMemoryPoolAllocator<U8> alloc)
+static void decimateSubmesh(F32 factor, SubMesh& submesh, BaseMemoryPool* pool)
 {
 	ANKI_ASSERT(factor > 0.0f && factor < 1.0f);
 	const PtrSize targetIndexCount = PtrSize(F32(submesh.m_indices.getSize() / 3) * factor) * 3;
@@ -226,15 +226,15 @@ static void decimateSubmesh(F32 factor, SubMesh& submesh, GenericMemoryPoolAlloc
 	}
 
 	// Decimate
-	DynamicArrayRaii<U32> newIndices(alloc, submesh.m_indices.getSize());
+	DynamicArrayRaii<U32> newIndices(pool, submesh.m_indices.getSize());
 	newIndices.resize(U32(meshopt_simplify(&newIndices[0], &submesh.m_indices[0], submesh.m_indices.getSize(),
 										   &submesh.m_verts[0].m_position.x(), submesh.m_verts.getSize(),
 										   sizeof(TempVertex), targetIndexCount, 1e-2f)));
 
 	// Re-pack
-	DynamicArrayRaii<U32> reindexedIndices(alloc);
-	DynamicArrayRaii<TempVertex> newVerts(alloc);
-	HashMapRaii<U32, U32> vertexStored(alloc);
+	DynamicArrayRaii<U32> reindexedIndices(pool);
+	DynamicArrayRaii<TempVertex> newVerts(pool);
+	HashMapRaii<U32, U32> vertexStored(pool);
 	for(U32 idx = 0; idx < newIndices.getSize(); ++idx)
 	{
 		U32 newIdx;
@@ -276,12 +276,12 @@ U32 GltfImporter::getMeshTotalVertexCount(const cgltf_mesh& mesh)
 
 Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFactor)
 {
-	StringRaii fname(m_alloc);
+	StringRaii fname(m_pool);
 	fname.sprintf("%s%s", m_outDir.cstr(), computeMeshResourceFilename(mesh, lod).cstr());
 	ANKI_IMPORTER_LOGV("Importing mesh (%s, decimate factor %f): %s",
 					   (m_optimizeMeshes) ? "optimize" : "WON'T optimize", decimateFactor, fname.cstr());
 
-	ListAuto<SubMesh> submeshes(m_alloc);
+	ListRaii<SubMesh> submeshes(m_pool);
 	U32 totalIndexCount = 0;
 	U32 totalVertexCount = 0;
 	Vec3 aabbMin(kMaxF32);
@@ -300,7 +300,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 			return Error::kUserData;
 		}
 
-		SubMesh& submesh = *submeshes.emplaceBack(m_alloc);
+		SubMesh& submesh = *submeshes.emplaceBack(m_pool);
 
 		U minVertCount = kMaxU;
 		U maxVertCount = kMinU;
@@ -465,7 +465,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 		// - after normal fix because that will create verts with same attributes
 		if(m_optimizeMeshes || decimateFactor < 1.0f)
 		{
-			reindexSubmesh(submesh, m_alloc);
+			reindexSubmesh(submesh, m_pool);
 			vertCount = submesh.m_verts.getSize();
 		}
 
@@ -473,7 +473,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 		// Compute tangent
 		//
 		{
-			DynamicArrayRaii<Vec3> bitangents(m_alloc);
+			DynamicArrayRaii<Vec3> bitangents(m_pool);
 			bitangents.create(vertCount, Vec3(0.0f));
 
 			for(U32 i = 0; i < submesh.m_indices.getSize(); i += 3)
@@ -556,13 +556,13 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 		// Optimize
 		if(m_optimizeMeshes)
 		{
-			optimizeSubmesh(submesh, m_alloc);
+			optimizeSubmesh(submesh, m_pool);
 		}
 
 		// Simplify
 		if(decimateFactor < 1.0f)
 		{
-			decimateSubmesh(decimateFactor, submesh, m_alloc);
+			decimateSubmesh(decimateFactor, submesh, m_pool);
 		}
 
 		// Finalize
@@ -740,7 +740,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 	U32 vertCount = 0;
 	for(const SubMesh& submesh : submeshes)
 	{
-		DynamicArrayRaii<U16> indices(m_alloc);
+		DynamicArrayRaii<U16> indices(m_pool);
 		indices.create(submesh.m_indices.getSize());
 		for(U32 i = 0; i < indices.getSize(); ++i)
 		{
@@ -763,7 +763,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 	// Write position vert buffer
 	for(const SubMesh& submesh : submeshes)
 	{
-		DynamicArrayRaii<Vec3> positions(m_alloc);
+		DynamicArrayRaii<Vec3> positions(m_pool);
 		positions.create(submesh.m_verts.getSize());
 		for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 		{
@@ -777,7 +777,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 	// Write the 2nd vert buffer
 	for(const SubMesh& submesh : submeshes)
 	{
-		DynamicArrayRaii<MainVertex> verts(m_alloc);
+		DynamicArrayRaii<MainVertex> verts(m_pool);
 		verts.create(submesh.m_verts.getSize());
 
 		for(U32 i = 0; i < verts.getSize(); ++i)
@@ -801,7 +801,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, U32 lod, F32 decimateFacto
 	{
 		for(const SubMesh& submesh : submeshes)
 		{
-			DynamicArrayRaii<BoneInfoVertex> verts(m_alloc);
+			DynamicArrayRaii<BoneInfoVertex> verts(m_pool);
 			verts.create(submesh.m_verts.getSize());
 
 			for(U32 i = 0; i < verts.getSize(); ++i)

+ 43 - 43
AnKi/Importer/ImageImporter.cpp

@@ -22,10 +22,10 @@ public:
 	DynamicArrayRaii<U8, PtrSize> m_s3tcPixels;
 	DynamicArrayRaii<U8, PtrSize> m_astcPixels;
 
-	SurfaceOrVolumeData(GenericMemoryPoolAllocator<U8> alloc)
-		: m_pixels(alloc)
-		, m_s3tcPixels(alloc)
-		, m_astcPixels(alloc)
+	SurfaceOrVolumeData(BaseMemoryPool* pool)
+		: m_pixels(pool)
+		, m_s3tcPixels(pool)
+		, m_astcPixels(pool)
 	{
 	}
 };
@@ -36,8 +36,8 @@ public:
 	/// One surface for each layer ore one per face or a single volume if it's a 3D texture.
 	DynamicArrayRaii<SurfaceOrVolumeData> m_surfacesOrVolume;
 
-	Mipmap(GenericMemoryPoolAllocator<U8> alloc)
-		: m_surfacesOrVolume(alloc)
+	Mipmap(BaseMemoryPool* pool)
+		: m_surfacesOrVolume(pool)
 	{
 	}
 };
@@ -56,14 +56,14 @@ public:
 	U32 m_pixelSize = 0; ///< Texel size of an uncompressed image.
 	Bool m_hdr = false;
 
-	ImageImporterContext(GenericMemoryPoolAllocator<U8> alloc)
-		: m_mipmaps(alloc)
+	ImageImporterContext(BaseMemoryPool* pool)
+		: m_mipmaps(pool)
 	{
 	}
 
-	GenericMemoryPoolAllocator<U8> getAllocator() const
+	BaseMemoryPool& getMemoryPool()
 	{
-		return m_mipmaps.getAllocator();
+		return m_mipmaps.getMemoryPool();
 	}
 };
 
@@ -138,8 +138,8 @@ class CleanupFile
 public:
 	StringRaii m_fileToDelete;
 
-	CleanupFile(GenericMemoryPoolAllocator<U8> alloc, CString filename)
-		: m_fileToDelete(alloc, filename)
+	CleanupFile(BaseMemoryPool* pool, CString filename)
+		: m_fileToDelete(pool, filename)
 	{
 	}
 
@@ -272,7 +272,7 @@ static Error checkInputImages(const ImageImporterConfig& config, U32& width, U32
 }
 
 static Error resizeImage(CString inImageFilename, U32 outWidth, U32 outHeight, CString tempDirectory,
-						 GenericMemoryPoolAllocator<U8> alloc, StringRaii& tmpFilename)
+						 BaseMemoryPool& pool, StringRaii& tmpFilename)
 {
 	U32 inWidth, inHeight, channelCount;
 	Bool hdr;
@@ -299,7 +299,7 @@ static Error resizeImage(CString inImageFilename, U32 outWidth, U32 outHeight, C
 
 	// Resize
 	I ok;
-	DynamicArrayRaii<U8> outPixels(alloc);
+	DynamicArrayRaii<U8> outPixels(&pool);
 	if(!hdr)
 	{
 		outPixels.resize(outWidth * outHeight * channelCount);
@@ -421,19 +421,19 @@ static void applyScaleAndBias(WeakArray<Vec3> pixels, Vec3 scale, Vec3 bias)
 
 static Error loadFirstMipmap(const ImageImporterConfig& config, ImageImporterContext& ctx)
 {
-	GenericMemoryPoolAllocator<U8> alloc = ctx.getAllocator();
+	BaseMemoryPool& pool = ctx.getMemoryPool();
 
-	ctx.m_mipmaps.emplaceBack(alloc);
+	ctx.m_mipmaps.emplaceBack(pool);
 	Mipmap& mip0 = ctx.m_mipmaps[0];
 
 	if(ctx.m_depth > 1)
 	{
-		mip0.m_surfacesOrVolume.create(1, alloc);
+		mip0.m_surfacesOrVolume.create(1, &pool);
 		mip0.m_surfacesOrVolume[0].m_pixels.create(ctx.m_pixelSize * ctx.m_width * ctx.m_height * ctx.m_depth);
 	}
 	else
 	{
-		mip0.m_surfacesOrVolume.create(ctx.m_faceCount * ctx.m_layerCount, alloc);
+		mip0.m_surfacesOrVolume.create(ctx.m_faceCount * ctx.m_layerCount, &pool);
 		ANKI_ASSERT(mip0.m_surfacesOrVolume.getSize() == config.m_inputFilenames.getSize());
 
 		for(U32 f = 0; f < ctx.m_faceCount; ++f)
@@ -603,7 +603,7 @@ static void generateSurfaceMipmap(ConstWeakArray<U8, PtrSize> inBuffer, U32 inWi
 	}
 }
 
-static Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc, CString tempDirectory, CString compressonatorFilename,
+static Error compressS3tc(BaseMemoryPool& pool, CString tempDirectory, CString compressonatorFilename,
 						  ConstWeakArray<U8, PtrSize> inPixels, U32 inWidth, U32 inHeight, U32 channelCount, Bool hdr,
 						  WeakArray<U8, PtrSize> outPixels)
 {
@@ -614,7 +614,7 @@ static Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 				== PtrSize((hdr || channelCount == 4) ? 16 : 8) * (inWidth / 4) * (inHeight / 4));
 
 	// Create a PNG image to feed to the compressor
-	StringRaii tmpFilename(alloc);
+	StringRaii tmpFilename(&pool);
 	tmpFilename.sprintf("%s/AnKiImageImporter_%u.%s", tempDirectory.cstr(), U32(std::rand()), (hdr) ? "exr" : "png");
 	ANKI_IMPORTER_LOGV("Will store: %s", tmpFilename.cstr());
 	Bool saveTmpImageOk = false;
@@ -635,10 +635,10 @@ static Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 		ANKI_IMPORTER_LOGE("Failed to create: %s", tmpFilename.cstr());
 		return Error::kFunctionFailed;
 	}
-	CleanupFile tmpCleanup(alloc, tmpFilename);
+	CleanupFile tmpCleanup(&pool, tmpFilename);
 
 	// Invoke the compressor process
-	StringRaii ddsFilename(alloc);
+	StringRaii ddsFilename(&pool);
 	ddsFilename.sprintf("%s/AnKiImageImporter_%u.dds", tempDirectory.cstr(), U32(std::rand()));
 	Process proc;
 	Array<CString, 5> args;
@@ -652,14 +652,14 @@ static Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 	ANKI_IMPORTER_LOGV("Will invoke process: compressonatorcli %s %s %s %s %s", args[0].cstr(), args[1].cstr(),
 					   args[2].cstr(), args[3].cstr(), args[4].cstr());
 	ANKI_CHECK(proc.start(compressonatorFilename, args));
-	CleanupFile ddsCleanup(alloc, ddsFilename);
+	CleanupFile ddsCleanup(&pool, ddsFilename);
 	ProcessStatus status;
 	I32 exitCode;
 	ANKI_CHECK(proc.wait(60.0_sec, &status, &exitCode));
 
 	if(!(status == ProcessStatus::kNotRunning && exitCode == 0))
 	{
-		StringRaii errStr(alloc);
+		StringRaii errStr(&pool);
 		if(exitCode != 0)
 		{
 			ANKI_CHECK(proc.readFromStdout(errStr));
@@ -715,7 +715,7 @@ static Error compressS3tc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 	return Error::kNone;
 }
 
-static Error compressAstc(GenericMemoryPoolAllocator<U8> alloc, CString tempDirectory, CString astcencFilename,
+static Error compressAstc(BaseMemoryPool& pool, CString tempDirectory, CString astcencFilename,
 						  ConstWeakArray<U8, PtrSize> inPixels, U32 inWidth, U32 inHeight, U32 inChannelCount,
 						  UVec2 blockSize, Bool hdr, WeakArray<U8, PtrSize> outPixels)
 {
@@ -726,7 +726,7 @@ static Error compressAstc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 	ANKI_ASSERT(outPixels.getSizeInBytes() == blockBytes * (inWidth / blockSize.x()) * (inHeight / blockSize.y()));
 
 	// Create a BMP image to feed to the astcebc
-	StringRaii tmpFilename(alloc);
+	StringRaii tmpFilename(&pool);
 	tmpFilename.sprintf("%s/AnKiImageImporter_%u.%s", tempDirectory.cstr(), U32(std::rand()), (hdr) ? "exr" : "png");
 	ANKI_IMPORTER_LOGV("Will store: %s", tmpFilename.cstr());
 	Bool saveTmpImageOk = false;
@@ -747,12 +747,12 @@ static Error compressAstc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 		ANKI_IMPORTER_LOGE("Failed to create: %s", tmpFilename.cstr());
 		return Error::kFunctionFailed;
 	}
-	CleanupFile pngCleanup(alloc, tmpFilename);
+	CleanupFile pngCleanup(&pool, tmpFilename);
 
 	// Invoke the compressor process
-	StringRaii astcFilename(alloc);
+	StringRaii astcFilename(&pool);
 	astcFilename.sprintf("%s/AnKiImageImporter_%u.astc", tempDirectory.cstr(), U32(std::rand()));
-	StringRaii blockStr(alloc);
+	StringRaii blockStr(&pool);
 	blockStr.sprintf("%ux%u", blockSize.x(), blockSize.y());
 	Process proc;
 	Array<CString, 5> args;
@@ -767,14 +767,14 @@ static Error compressAstc(GenericMemoryPoolAllocator<U8> alloc, CString tempDire
 					   args[2].cstr(), args[3].cstr(), args[4].cstr());
 	ANKI_CHECK(proc.start(astcencFilename, args));
 
-	CleanupFile astcCleanup(alloc, astcFilename);
+	CleanupFile astcCleanup(&pool, astcFilename);
 	ProcessStatus status;
 	I32 exitCode;
 	ANKI_CHECK(proc.wait(60.0_sec, &status, &exitCode));
 
 	if(!(status == ProcessStatus::kNotRunning && exitCode == 0))
 	{
-		StringRaii errStr(alloc);
+		StringRaii errStr(&pool);
 		if(exitCode != 0)
 		{
 			ANKI_CHECK(proc.readFromStdout(errStr));
@@ -925,7 +925,7 @@ static Error storeAnkiImage(const ImageImporterConfig& config, const ImageImport
 
 static Error importImageInternal(const ImageImporterConfig& configOriginal)
 {
-	GenericMemoryPoolAllocator<U8> alloc = configOriginal.m_allocator;
+	BaseMemoryPool& pool = *configOriginal.m_pool;
 	ImageImporterConfig config = configOriginal;
 
 	config.m_minMipmapDimension = max(config.m_minMipmapDimension, 4u);
@@ -942,9 +942,9 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 	ANKI_CHECK(checkInputImages(config, width, height, channelCount, isHdr));
 
 	// Resize
-	DynamicArrayRaii<StringRaii> newFilenames(alloc);
-	DynamicArrayRaii<CString> newFilenamesCString(alloc);
-	DynamicArrayRaii<CleanupFile> resizedImagesCleanup(alloc);
+	DynamicArrayRaii<StringRaii> newFilenames(&pool);
+	DynamicArrayRaii<CString> newFilenamesCString(&pool);
+	DynamicArrayRaii<CleanupFile> resizedImagesCleanup(&pool);
 	if(width < config.m_minMipmapDimension || height < config.m_minMipmapDimension)
 	{
 		const U32 newWidth = max(width, config.m_minMipmapDimension);
@@ -953,16 +953,16 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 		ANKI_IMPORTER_LOGV("Image is smaller than the min mipmap dimension. Will resize it to %ux%u", newWidth,
 						   newHeight);
 
-		newFilenames.resize(config.m_inputFilenames.getSize(), StringRaii(alloc));
+		newFilenames.resize(config.m_inputFilenames.getSize(), StringRaii(&pool));
 		newFilenamesCString.resize(config.m_inputFilenames.getSize());
 
 		for(U32 i = 0; i < config.m_inputFilenames.getSize(); ++i)
 		{
-			ANKI_CHECK(resizeImage(config.m_inputFilenames[i], newWidth, newHeight, config.m_tempDirectory, alloc,
+			ANKI_CHECK(resizeImage(config.m_inputFilenames[i], newWidth, newHeight, config.m_tempDirectory, pool,
 								   newFilenames[i]));
 
 			newFilenamesCString[i] = newFilenames[i];
-			resizedImagesCleanup.emplaceBack(alloc, newFilenames[i]);
+			resizedImagesCleanup.emplaceBack(pool, newFilenames[i]);
 		}
 
 		// Override config
@@ -972,7 +972,7 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 	}
 
 	// Init image
-	ImageImporterContext ctx(alloc);
+	ImageImporterContext ctx(&pool);
 
 	ctx.m_width = width;
 	ctx.m_height = height;
@@ -1031,11 +1031,11 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 									  : computeMaxMipmapCount2d(width, height, config.m_minMipmapDimension));
 	for(U32 mip = 1; mip < mipCount; ++mip)
 	{
-		ctx.m_mipmaps.emplaceBack(alloc);
+		ctx.m_mipmaps.emplaceBack(&pool);
 
 		if(config.m_type != ImageBinaryType::k3D)
 		{
-			ctx.m_mipmaps[mip].m_surfacesOrVolume.create(ctx.m_faceCount * ctx.m_layerCount, alloc);
+			ctx.m_mipmaps[mip].m_surfacesOrVolume.create(ctx.m_faceCount * ctx.m_layerCount, &pool);
 			for(U32 l = 0; l < ctx.m_layerCount; ++l)
 			{
 				for(U32 f = 0; f < ctx.m_faceCount; ++f)
@@ -1107,7 +1107,7 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 
 					surface.m_s3tcPixels.create(s3tcImageSize);
 
-					ANKI_CHECK(compressS3tc(alloc, config.m_tempDirectory, config.m_compressonatorFilename,
+					ANKI_CHECK(compressS3tc(pool, config.m_tempDirectory, config.m_compressonatorFilename,
 											ConstWeakArray<U8, PtrSize>(surface.m_pixels), width, height,
 											ctx.m_channelCount, ctx.m_hdr,
 											WeakArray<U8, PtrSize>(surface.m_s3tcPixels)));
@@ -1137,7 +1137,7 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 
 					surface.m_astcPixels.create(astcImageSize);
 
-					ANKI_CHECK(compressAstc(alloc, config.m_tempDirectory, config.m_astcencFilename,
+					ANKI_CHECK(compressAstc(pool, config.m_tempDirectory, config.m_astcencFilename,
 											ConstWeakArray<U8, PtrSize>(surface.m_pixels), width, height,
 											ctx.m_channelCount, config.m_astcBlockSize, ctx.m_hdr,
 											WeakArray<U8, PtrSize>(surface.m_astcPixels)));

+ 1 - 1
AnKi/Importer/ImageImporter.h

@@ -18,7 +18,7 @@ namespace anki {
 class ImageImporterConfig
 {
 public:
-	GenericMemoryPoolAllocator<U8> m_allocator;
+	BaseMemoryPool* m_pool = nullptr;
 	ConstWeakArray<CString> m_inputFilenames;
 	CString m_outFilename;
 	ImageBinaryType m_type = ImageBinaryType::k2D;

+ 8 - 8
AnKi/Renderer/ClusterBinning.cpp

@@ -151,12 +151,12 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	StagingGpuMemoryPool& stagingMem = m_r->getStagingGpuMemory();
 
 	cs.m_clusteredShadingUniformsAddress = stagingMem.allocateFrame(
-		sizeof(ClusteredShadingUniforms), StagingGpuMemoryType::UNIFORM, cs.m_clusteredShadingUniformsToken);
+		sizeof(ClusteredShadingUniforms), StagingGpuMemoryType::kUniform, cs.m_clusteredShadingUniformsToken);
 
 	if(rqueue.m_pointLights.getSize())
 	{
 		cs.m_pointLightsAddress = stagingMem.allocateFrame(rqueue.m_pointLights.getSize() * sizeof(PointLight),
-														   StagingGpuMemoryType::UNIFORM, cs.m_pointLightsToken);
+														   StagingGpuMemoryType::kUniform, cs.m_pointLightsToken);
 	}
 	else
 	{
@@ -166,7 +166,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	if(rqueue.m_spotLights.getSize())
 	{
 		cs.m_spotLightsAddress = stagingMem.allocateFrame(rqueue.m_spotLights.getSize() * sizeof(SpotLight),
-														  StagingGpuMemoryType::UNIFORM, cs.m_spotLightsToken);
+														  StagingGpuMemoryType::kUniform, cs.m_spotLightsToken);
 	}
 	else
 	{
@@ -177,7 +177,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	{
 		cs.m_reflectionProbesAddress =
 			stagingMem.allocateFrame(rqueue.m_reflectionProbes.getSize() * sizeof(ReflectionProbe),
-									 StagingGpuMemoryType::UNIFORM, cs.m_reflectionProbesToken);
+									 StagingGpuMemoryType::kUniform, cs.m_reflectionProbesToken);
 	}
 	else
 	{
@@ -187,7 +187,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	if(rqueue.m_decals.getSize())
 	{
 		cs.m_decalsAddress = stagingMem.allocateFrame(rqueue.m_decals.getSize() * sizeof(Decal),
-													  StagingGpuMemoryType::UNIFORM, cs.m_decalsToken);
+													  StagingGpuMemoryType::kUniform, cs.m_decalsToken);
 	}
 	else
 	{
@@ -198,7 +198,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	{
 		cs.m_fogDensityVolumesAddress =
 			stagingMem.allocateFrame(rqueue.m_fogDensityVolumes.getSize() * sizeof(FogDensityVolume),
-									 StagingGpuMemoryType::UNIFORM, cs.m_fogDensityVolumesToken);
+									 StagingGpuMemoryType::kUniform, cs.m_fogDensityVolumesToken);
 	}
 	else
 	{
@@ -209,7 +209,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	{
 		cs.m_globalIlluminationProbesAddress =
 			stagingMem.allocateFrame(rqueue.m_giProbes.getSize() * sizeof(GlobalIlluminationProbe),
-									 StagingGpuMemoryType::UNIFORM, cs.m_globalIlluminationProbesToken);
+									 StagingGpuMemoryType::kUniform, cs.m_globalIlluminationProbesToken);
 	}
 	else
 	{
@@ -217,7 +217,7 @@ void ClusterBinning::writeClustererBuffers(RenderingContext& ctx)
 	}
 
 	cs.m_clustersAddress =
-		stagingMem.allocateFrame(sizeof(Cluster) * m_clusterCount, StagingGpuMemoryType::STORAGE, cs.m_clustersToken);
+		stagingMem.allocateFrame(sizeof(Cluster) * m_clusterCount, StagingGpuMemoryType::kStorage, cs.m_clustersToken);
 }
 
 void ClusterBinning::writeClusterBuffersAsync()

+ 1 - 1
AnKi/Renderer/Drawer.cpp

@@ -50,7 +50,7 @@ void RenderableDrawer::drawRange(RenderingTechnique technique, const RenderableD
 		StagingGpuMemoryToken globalUniformsToken;
 		MaterialGlobalUniforms* globalUniforms =
 			static_cast<MaterialGlobalUniforms*>(m_r->getStagingGpuMemory().allocateFrame(
-				sizeof(MaterialGlobalUniforms), StagingGpuMemoryType::UNIFORM, globalUniformsToken));
+				sizeof(MaterialGlobalUniforms), StagingGpuMemoryType::kUniform, globalUniformsToken));
 
 		globalUniforms->m_viewProjectionMatrix = args.m_viewProjectionMatrix;
 		globalUniforms->m_previousViewProjectionMatrix = args.m_previousViewProjectionMatrix;

+ 2 - 2
AnKi/Renderer/RendererObject.h

@@ -83,7 +83,7 @@ protected:
 	template<typename TPtr>
 	TPtr allocateUniforms(PtrSize size, StagingGpuMemoryToken& token)
 	{
-		return static_cast<TPtr>(allocateFrameStagingMemory(size, StagingGpuMemoryType::UNIFORM, token));
+		return static_cast<TPtr>(allocateFrameStagingMemory(size, StagingGpuMemoryType::kUniform, token));
 	}
 
 	void bindUniforms(CommandBufferPtr& cmdb, U32 set, U32 binding, const StagingGpuMemoryToken& token) const;
@@ -100,7 +100,7 @@ protected:
 	template<typename TPtr>
 	TPtr allocateStorage(PtrSize size, StagingGpuMemoryToken& token)
 	{
-		return static_cast<TPtr>(allocateFrameStagingMemory(size, StagingGpuMemoryType::STORAGE, token));
+		return static_cast<TPtr>(allocateFrameStagingMemory(size, StagingGpuMemoryType::kStorage, token));
 	}
 
 	void bindStorage(CommandBufferPtr& cmdb, U32 set, U32 binding, const StagingGpuMemoryToken& token) const;

+ 1 - 1
AnKi/Scene/Components/GpuParticleEmitterComponent.cpp

@@ -175,7 +175,7 @@ void GpuParticleEmitterComponent::simulate(GenericGpuComputeJobQueueElementConte
 	StagingGpuMemoryToken token;
 	GpuParticleSimulationState* unis =
 		static_cast<GpuParticleSimulationState*>(ctx.m_stagingGpuAllocator->allocateFrame(
-			sizeof(GpuParticleSimulationState), StagingGpuMemoryType::UNIFORM, token));
+			sizeof(GpuParticleSimulationState), StagingGpuMemoryType::kUniform, token));
 
 	unis->m_viewProjMat = ctx.m_viewProjectionMatrix;
 	unis->m_unprojectionParams = ctx.m_projectionMatrix.extractPerspectiveUnprojectionParams();

+ 1 - 1
AnKi/Scene/Components/ParticleEmitterComponent.cpp

@@ -393,7 +393,7 @@ void ParticleEmitterComponent::draw(RenderQueueDrawContext& ctx) const
 		// Load verts
 		StagingGpuMemoryToken token;
 		void* gpuStorage = ctx.m_stagingGpuAllocator->allocateFrame(m_aliveParticleCount * kVertexSize,
-																	StagingGpuMemoryType::VERTEX, token);
+																	StagingGpuMemoryType::kVertex, token);
 		memcpy(gpuStorage, m_verts, m_aliveParticleCount * kVertexSize);
 
 		// Program

+ 2 - 2
AnKi/Scene/Components/RenderComponent.cpp

@@ -31,7 +31,7 @@ void RenderComponent::allocateAndSetupUniforms(const MaterialResourcePtr& mtl, c
 	{
 		StagingGpuMemoryToken token;
 		RenderableGpuView* renderableGpuViews = static_cast<RenderableGpuView*>(
-			alloc.allocateFrame(renderableGpuViewsUboSize, StagingGpuMemoryType::UNIFORM, token));
+			alloc.allocateFrame(renderableGpuViewsUboSize, StagingGpuMemoryType::kUniform, token));
 		ANKI_ASSERT(isAligned(alignof(RenderableGpuView), renderableGpuViews));
 
 		cmdb->bindUniformBuffer(set, MATERIAL_BINDING_RENDERABLE_GPU_VIEW, token.m_buffer, token.m_offset,
@@ -53,7 +53,7 @@ void RenderComponent::allocateAndSetupUniforms(const MaterialResourcePtr& mtl, c
 	StagingGpuMemoryToken token;
 	U8* const localUniformsBegin =
 		(localUniformsUboSize != 0)
-			? static_cast<U8*>(alloc.allocateFrame(localUniformsUboSize, StagingGpuMemoryType::STORAGE, token))
+			? static_cast<U8*>(alloc.allocateFrame(localUniformsUboSize, StagingGpuMemoryType::kStorage, token))
 			: nullptr;
 
 	if(localUniformsUboSize)

+ 9 - 9
AnKi/Scene/DebugDrawer.cpp

@@ -17,7 +17,7 @@ void allocateAndPopulateDebugBox(StagingGpuMemoryPool& stagingGpuAllocator, Stag
 								 StagingGpuMemoryToken& indicesToken, U32& indexCount)
 {
 	Vec3* verts = static_cast<Vec3*>(
-		stagingGpuAllocator.allocateFrame(sizeof(Vec3) * 8, StagingGpuMemoryType::VERTEX, vertsToken));
+		stagingGpuAllocator.allocateFrame(sizeof(Vec3) * 8, StagingGpuMemoryType::kVertex, vertsToken));
 
 	constexpr F32 kSize = 1.0f;
 	verts[0] = Vec3(kSize, kSize, kSize); // front top right
@@ -31,7 +31,7 @@ void allocateAndPopulateDebugBox(StagingGpuMemoryPool& stagingGpuAllocator, Stag
 
 	constexpr U kIndexCount = 12 * 2;
 	U16* indices = static_cast<U16*>(
-		stagingGpuAllocator.allocateFrame(sizeof(U16) * kIndexCount, StagingGpuMemoryType::VERTEX, indicesToken));
+		stagingGpuAllocator.allocateFrame(sizeof(U16) * kIndexCount, StagingGpuMemoryType::kVertex, indicesToken));
 
 	U c = 0;
 	indices[c++] = 0;
@@ -144,7 +144,7 @@ void DebugDrawer2::drawCubes(ConstWeakArray<Mat4> mvps, const Vec4& color, F32 l
 	// Set the uniforms
 	StagingGpuMemoryToken unisToken;
 	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize() + sizeof(Vec4),
-																	   StagingGpuMemoryType::UNIFORM, unisToken));
+																	   StagingGpuMemoryType::kUniform, unisToken));
 
 	if(cubeSideSize == 2.0f)
 	{
@@ -188,13 +188,13 @@ void DebugDrawer2::drawLines(ConstWeakArray<Mat4> mvps, const Vec4& color, F32 l
 	// Verts
 	StagingGpuMemoryToken vertsToken;
 	Vec3* verts = static_cast<Vec3*>(stagingGpuAllocator.allocateFrame(sizeof(Vec3) * linePositions.getSize(),
-																	   StagingGpuMemoryType::VERTEX, vertsToken));
+																	   StagingGpuMemoryType::kVertex, vertsToken));
 	memcpy(verts, linePositions.getBegin(), linePositions.getSizeInBytes());
 
 	// Set the uniforms
 	StagingGpuMemoryToken unisToken;
 	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize() + sizeof(Vec4),
-																	   StagingGpuMemoryType::UNIFORM, unisToken));
+																	   StagingGpuMemoryType::kUniform, unisToken));
 
 	memcpy(pmvps, &mvps[0], mvps.getSizeInBytes());
 	Vec4* pcolor = reinterpret_cast<Vec4*>(pmvps + mvps.getSize());
@@ -225,7 +225,7 @@ void DebugDrawer2::drawBillboardTextures(const Mat4& projMat, const Mat3x4& view
 {
 	StagingGpuMemoryToken positionsToken;
 	Vec3* verts = static_cast<Vec3*>(
-		stagingGpuAllocator.allocateFrame(sizeof(Vec3) * 4, StagingGpuMemoryType::VERTEX, positionsToken));
+		stagingGpuAllocator.allocateFrame(sizeof(Vec3) * 4, StagingGpuMemoryType::kVertex, positionsToken));
 
 	verts[0] = Vec3(-0.5f, -0.5f, 0.0f);
 	verts[1] = Vec3(+0.5f, -0.5f, 0.0f);
@@ -233,8 +233,8 @@ void DebugDrawer2::drawBillboardTextures(const Mat4& projMat, const Mat3x4& view
 	verts[3] = Vec3(+0.5f, +0.5f, 0.0f);
 
 	StagingGpuMemoryToken uvsToken;
-	Vec2* uvs =
-		static_cast<Vec2*>(stagingGpuAllocator.allocateFrame(sizeof(Vec2) * 4, StagingGpuMemoryType::VERTEX, uvsToken));
+	Vec2* uvs = static_cast<Vec2*>(
+		stagingGpuAllocator.allocateFrame(sizeof(Vec2) * 4, StagingGpuMemoryType::kVertex, uvsToken));
 
 	uvs[0] = Vec2(0.0f, 0.0f);
 	uvs[1] = Vec2(1.0f, 0.0f);
@@ -244,7 +244,7 @@ void DebugDrawer2::drawBillboardTextures(const Mat4& projMat, const Mat3x4& view
 	// Set the uniforms
 	StagingGpuMemoryToken unisToken;
 	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(
-		sizeof(Mat4) * positions.getSize() + sizeof(Vec4), StagingGpuMemoryType::UNIFORM, unisToken));
+		sizeof(Mat4) * positions.getSize() + sizeof(Vec4), StagingGpuMemoryType::kUniform, unisToken));
 
 	const Mat4 camTrf = Mat4(viewMat, Vec4(0.0f, 0.0f, 0.0f, 1.0f)).getInverse();
 	const Vec3 zAxis = camTrf.getZAxis().xyz().getNormalized();

+ 2 - 2
AnKi/Scene/ModelNode.cpp

@@ -239,10 +239,10 @@ void ModelNode::draw(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData
 			const U32 boneCount = skinc.getBoneTransforms().getSize();
 			StagingGpuMemoryToken token, tokenPrev;
 			void* trfs = ctx.m_stagingGpuAllocator->allocateFrame(boneCount * sizeof(Mat4),
-																  StagingGpuMemoryType::STORAGE, token);
+																  StagingGpuMemoryType::kStorage, token);
 			memcpy(trfs, &skinc.getBoneTransforms()[0], boneCount * sizeof(Mat4));
 
-			trfs = ctx.m_stagingGpuAllocator->allocateFrame(boneCount * sizeof(Mat4), StagingGpuMemoryType::STORAGE,
+			trfs = ctx.m_stagingGpuAllocator->allocateFrame(boneCount * sizeof(Mat4), StagingGpuMemoryType::kStorage,
 															tokenPrev);
 			memcpy(trfs, &skinc.getPreviousFrameBoneTransforms()[0], boneCount * sizeof(Mat4));
 

+ 0 - 3
AnKi/Script/Common.h

@@ -5,7 +5,6 @@
 
 #pragma once
 
-#include <AnKi/Util/Allocator.h>
 #include <AnKi/Util/Ptr.h>
 
 namespace anki {
@@ -20,6 +19,4 @@ class ScriptEnvironment;
 #define ANKI_SCRIPT_LOGW(...) ANKI_LOG("SCRI", kWarning, __VA_ARGS__)
 #define ANKI_SCRIPT_LOGF(...) ANKI_LOG("SCRI", kFatal, __VA_ARGS__)
 
-using ScriptAllocator = HeapAllocator<U8>;
-
 } // end namespace anki

+ 11 - 11
AnKi/Script/LuaBinder.cpp

@@ -43,14 +43,14 @@ LuaBinder::~LuaBinder()
 	{
 		lua_close(m_l);
 	}
-	m_userDataSigToDataInfo.destroy(m_alloc);
+	m_userDataSigToDataInfo.destroy(*m_pool);
 }
 
-Error LuaBinder::init(ScriptAllocator alloc, LuaBinderOtherSystems* otherSystems)
+Error LuaBinder::init(HeapMemoryPool* pool, LuaBinderOtherSystems* otherSystems)
 {
-	ANKI_ASSERT(otherSystems);
+	ANKI_ASSERT(otherSystems && pool);
 	m_otherSystems = otherSystems;
-	m_alloc = std::move(alloc);
+	m_pool = pool;
 
 	m_l = lua_newstate(luaAllocCallback, this);
 	luaL_openlibs(m_l);
@@ -73,7 +73,7 @@ void* LuaBinder::luaAllocCallback(void* userData, void* ptr, PtrSize osize, PtrS
 	{
 		if(ptr != nullptr)
 		{
-			binder.m_alloc.getMemoryPool().free(ptr);
+			binder.m_pool->free(ptr);
 		}
 	}
 	else
@@ -82,7 +82,7 @@ void* LuaBinder::luaAllocCallback(void* userData, void* ptr, PtrSize osize, PtrS
 
 		if(ptr == nullptr)
 		{
-			out = binder.m_alloc.getMemoryPool().allocate(nsize, 16);
+			out = binder.m_pool->allocate(nsize, 16);
 		}
 		else if(nsize <= osize)
 		{
@@ -92,9 +92,9 @@ void* LuaBinder::luaAllocCallback(void* userData, void* ptr, PtrSize osize, PtrS
 		{
 			// realloc
 
-			out = binder.m_alloc.getMemoryPool().allocate(nsize, 16);
+			out = binder.m_pool->allocate(nsize, 16);
 			memcpy(out, ptr, osize);
-			binder.m_alloc.getMemoryPool().free(ptr);
+			binder.m_pool->free(ptr);
 		}
 	}
 #else
@@ -146,7 +146,7 @@ void LuaBinder::createClass(lua_State* l, const LuaUserDataTypeInfo* typeInfo)
 	lua_getallocf(l, &ud);
 	ANKI_ASSERT(ud);
 	LuaBinder& binder = *static_cast<LuaBinder*>(ud);
-	binder.m_userDataSigToDataInfo.emplace(binder.m_alloc, typeInfo->m_signature, typeInfo);
+	binder.m_userDataSigToDataInfo.emplace(*binder.m_pool, typeInfo->m_signature, typeInfo);
 }
 
 void LuaBinder::pushLuaCFuncMethod(lua_State* l, const char* name, lua_CFunction luafunc)
@@ -260,7 +260,7 @@ void* LuaBinder::luaAlloc(lua_State* l, size_t size, U32 alignment)
 	ANKI_ASSERT(ud);
 	LuaBinder* binder = static_cast<LuaBinder*>(ud);
 
-	return binder->m_alloc.getMemoryPool().allocate(size, alignment);
+	return binder->m_pool->allocate(size, alignment);
 }
 
 void LuaBinder::luaFree(lua_State* l, void* ptr)
@@ -270,7 +270,7 @@ void LuaBinder::luaFree(lua_State* l, void* ptr)
 	ANKI_ASSERT(ud);
 	LuaBinder* binder = static_cast<LuaBinder*>(ud);
 
-	binder->m_alloc.getMemoryPool().free(ptr);
+	binder->m_pool->free(ptr);
 }
 
 void LuaBinder::serializeGlobals(lua_State* l, LuaBinderSerializeGlobalsCallback& callback)

+ 4 - 5
AnKi/Script/LuaBinder.h

@@ -8,7 +8,6 @@
 #include <AnKi/Script/Common.h>
 #include <AnKi/Util/Assert.h>
 #include <AnKi/Util/StdTypes.h>
-#include <AnKi/Util/Allocator.h>
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/Functions.h>
 #include <AnKi/Util/HashMap.h>
@@ -159,7 +158,7 @@ public:
 
 	LuaBinder& operator=(const LuaBinder&) = delete; // Non-copyable
 
-	Error init(ScriptAllocator alloc, LuaBinderOtherSystems* otherSystems);
+	Error init(HeapMemoryPool* pool, LuaBinderOtherSystems* otherSystems);
 
 	lua_State* getLuaState()
 	{
@@ -167,9 +166,9 @@ public:
 		return m_l;
 	}
 
-	ScriptAllocator getAllocator() const
+	HeapMemoryPool& getMemoryPool() const
 	{
-		return m_alloc;
+		return *m_pool;
 	}
 
 	LuaBinderOtherSystems& getOtherSystems()
@@ -259,7 +258,7 @@ public:
 
 private:
 	LuaBinderOtherSystems* m_otherSystems;
-	ScriptAllocator m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	lua_State* m_l = nullptr;
 	HashMap<I64, const LuaUserDataTypeInfo*> m_userDataSigToDataInfo;
 

+ 1 - 1
AnKi/Script/ScriptEnvironment.cpp

@@ -13,7 +13,7 @@ Error ScriptEnvironment::init(ScriptManager* manager)
 	ANKI_ASSERT(!isInitialized());
 	ANKI_ASSERT(manager);
 	m_manager = manager;
-	return m_thread.init(m_manager->getAllocator(), &m_manager->getOtherSystems());
+	return m_thread.init(&m_manager->getMemoryPool(), &m_manager->getOtherSystems());
 }
 
 } // end namespace anki

+ 2 - 2
AnKi/Script/ScriptManager.cpp

@@ -22,9 +22,9 @@ Error ScriptManager::init(AllocAlignedCallback allocCb, void* allocCbData)
 {
 	ANKI_SCRIPT_LOGI("Initializing scripting engine...");
 
-	m_alloc = ScriptAllocator(allocCb, allocCbData);
+	m_pool.init(allocCb, allocCbData);
 
-	ANKI_CHECK(m_lua.init(m_alloc, &m_otherSystems));
+	ANKI_CHECK(m_lua.init(&m_pool, &m_otherSystems));
 
 	return Error::kNone;
 }

+ 3 - 3
AnKi/Script/ScriptManager.h

@@ -61,14 +61,14 @@ public:
 		return m_lua;
 	}
 
-	ANKI_INTERNAL ScriptAllocator getAllocator() const
+	ANKI_INTERNAL HeapMemoryPool& getMemoryPool() const
 	{
-		return m_alloc;
+		return m_pool;
 	}
 
 private:
 	LuaBinderOtherSystems m_otherSystems;
-	ScriptAllocator m_alloc;
+	mutable HeapMemoryPool m_pool;
 	LuaBinder m_lua;
 	Mutex n_luaMtx;
 };

+ 2 - 2
AnKi/Ui/Canvas.cpp

@@ -217,9 +217,9 @@ void Canvas::appendToCommandBufferInternal(CommandBufferPtr& cmdb)
 		}
 
 		ImDrawVert* verts = static_cast<ImDrawVert*>(
-			m_manager->getStagingGpuMemory().allocateFrame(verticesSize, StagingGpuMemoryType::VERTEX, vertsToken));
+			m_manager->getStagingGpuMemory().allocateFrame(verticesSize, StagingGpuMemoryType::kVertex, vertsToken));
 		ImDrawIdx* indices = static_cast<ImDrawIdx*>(
-			m_manager->getStagingGpuMemory().allocateFrame(indicesSize, StagingGpuMemoryType::VERTEX, indicesToken));
+			m_manager->getStagingGpuMemory().allocateFrame(indicesSize, StagingGpuMemoryType::kVertex, indicesToken));
 
 		for(I n = 0; n < drawData.CmdListsCount; ++n)
 		{

+ 10 - 7
AnKi/Util/BuddyAllocatorBuilder.h

@@ -25,21 +25,24 @@ public:
 /// This is a generic implementation of a buddy allocator.
 /// @tparam kMaxMemoryRangeLog2 The max memory to allocate.
 /// @tparam TLock This an optional lock. Can be a Mutex or SpinLock or some dummy class.
-template<U32 kMaxMemoryRangeLog2, typename TLock>
+/// @tparam TMemPool The type of the pool to be used in internal CPU allocations.
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool = MemoryPoolPtrWrapper<HeapMemoryPool>>
 class BuddyAllocatorBuilder
 {
 public:
 	/// The type of the address.
 	using Address = std::conditional_t<(kMaxMemoryRangeLog2 > 32), PtrSize, U32>;
 
+	using InternalMemoryPool = TMemPool;
+
 	BuddyAllocatorBuilder()
 	{
 	}
 
 	/// @copydoc init
-	BuddyAllocatorBuilder(GenericMemoryPoolAllocator<U8> alloc, U32 maxMemoryRangeLog2)
+	BuddyAllocatorBuilder(InternalMemoryPool pool, U32 maxMemoryRangeLog2)
 	{
-		init(alloc, maxMemoryRangeLog2);
+		init(pool, maxMemoryRangeLog2);
 	}
 
 	BuddyAllocatorBuilder(const BuddyAllocatorBuilder&) = delete; // Non-copyable
@@ -52,9 +55,9 @@ public:
 	BuddyAllocatorBuilder& operator=(const BuddyAllocatorBuilder&) = delete; // Non-copyable
 
 	/// Init the allocator.
-	/// @param alloc The allocator used for internal structures of the BuddyAllocatorBuilder.
+	/// @param pool The memory pool to be used for internal structures of the BuddyAllocatorBuilder.
 	/// @param maxMemoryRangeLog2 The max memory to allocate.
-	void init(GenericMemoryPoolAllocator<U8> alloc, U32 maxMemoryRangeLog2);
+	void init(InternalMemoryPool pool, U32 maxMemoryRangeLog2);
 
 	/// Destroy the allocator.
 	void destroy();
@@ -92,7 +95,7 @@ private:
 	}
 
 	using FreeList = DynamicArray<Address, PtrSize>;
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	InternalMemoryPool m_pool;
 	DynamicArray<FreeList> m_freeLists;
 	PtrSize m_maxMemoryRange = 0;
 	PtrSize m_userAllocatedSize = 0; ///< The total ammount of memory requested by the user.
@@ -108,7 +111,7 @@ private:
 	{
 		ANKI_ASSERT(m_freeLists[order].getSize() > 0);
 		const PtrSize address = m_freeLists[order].getBack();
-		m_freeLists[order].popBack(m_alloc);
+		m_freeLists[order].popBack(m_pool);
 		ANKI_ASSERT(address < m_maxMemoryRange);
 		return address;
 	}

+ 24 - 24
AnKi/Util/BuddyAllocatorBuilder.inl.h

@@ -7,9 +7,8 @@
 
 namespace anki {
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::init(GenericMemoryPoolAllocator<U8> alloc,
-															 U32 maxMemoryRangeLog2)
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::init(InternalMemoryPool pool, U32 maxMemoryRangeLog2)
 {
 	ANKI_ASSERT(maxMemoryRangeLog2 >= 1 && maxMemoryRangeLog2 <= kMaxMemoryRangeLog2);
 	ANKI_ASSERT(m_freeLists.getSize() == 0 && m_userAllocatedSize == 0 && m_realAllocatedSize == 0);
@@ -17,22 +16,23 @@ void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::init(GenericMemoryPoolAl
 	const U32 orderCount = maxMemoryRangeLog2 + 1;
 	m_maxMemoryRange = pow2<PtrSize>(maxMemoryRangeLog2);
 
-	m_alloc = std::move(alloc);
-	m_freeLists.create(m_alloc, orderCount);
+	m_pool = pool;
+	m_freeLists.create(m_pool, orderCount);
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::destroy()
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::destroy()
 {
 	ANKI_ASSERT(m_userAllocatedSize == 0 && "Forgot to free all memory");
-	m_freeLists.destroy(m_alloc);
+	m_freeLists.destroy(m_pool);
 	m_maxMemoryRange = 0;
 	m_userAllocatedSize = 0;
 	m_realAllocatedSize = 0;
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-Bool BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::allocate(PtrSize size, PtrSize alignment, Address& outAddress)
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+Bool BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::allocate(PtrSize size, PtrSize alignment,
+																		   Address& outAddress)
 {
 	ANKI_ASSERT(size > 0 && size <= m_maxMemoryRange);
 
@@ -59,7 +59,7 @@ Bool BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::allocate(PtrSize size, P
 	if(m_userAllocatedSize == 0)
 	{
 		const Address startingAddress = 0;
-		m_freeLists.getBack().create(m_alloc, 1, startingAddress);
+		m_freeLists.getBack().create(m_pool, 1, startingAddress);
 	}
 
 	// Find the order to start the search
@@ -88,7 +88,7 @@ Bool BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::allocate(PtrSize size, P
 		ANKI_ASSERT(buddyAddress < m_maxMemoryRange && buddyAddress <= getMaxNumericLimit<Address>());
 
 		ANKI_ASSERT(order > 0);
-		m_freeLists[order - 1].emplaceBack(m_alloc, Address(buddyAddress));
+		m_freeLists[order - 1].emplaceBack(m_pool, Address(buddyAddress));
 
 		--order;
 	}
@@ -108,8 +108,8 @@ Bool BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::allocate(PtrSize size, P
 	return true;
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::free(Address address, PtrSize size, PtrSize alignment)
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::free(Address address, PtrSize size, PtrSize alignment)
 {
 	PtrSize alignedSize = nextPowerOfTwo(size);
 	U32 order = log2(alignedSize);
@@ -146,8 +146,8 @@ void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::free(Address address, Pt
 	}
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::freeInternal(PtrSize address, PtrSize size)
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::freeInternal(PtrSize address, PtrSize size)
 {
 	ANKI_ASSERT(size);
 	ANKI_ASSERT(isPowerOfTwo(size));
@@ -180,7 +180,7 @@ void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::freeInternal(PtrSize add
 	{
 		if(m_freeLists[order][i] == buddyAddress)
 		{
-			m_freeLists[order].erase(m_alloc, m_freeLists[order].getBegin() + i);
+			m_freeLists[order].erase(m_pool, m_freeLists[order].getBegin() + i);
 
 			freeInternal((buddyIsLeft) ? buddyAddress : address, size * 2);
 			buddyFound = true;
@@ -191,17 +191,17 @@ void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::freeInternal(PtrSize add
 	if(!buddyFound)
 	{
 		ANKI_ASSERT(address <= getMaxNumericLimit<Address>());
-		m_freeLists[order].emplaceBack(m_alloc, Address(address));
+		m_freeLists[order].emplaceBack(m_pool, Address(address));
 	}
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::debugPrint() const
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::debugPrint() const
 {
 	constexpr PtrSize kMaxMemoryRange = pow2<PtrSize>(kMaxMemoryRangeLog2);
 
 	// Allocate because we can't possibly have that in the stack
-	BitSet<kMaxMemoryRange>* freeBytes = m_alloc.newInstance<BitSet<kMaxMemoryRange>>(false);
+	BitSet<kMaxMemoryRange>* freeBytes = newInstance<BitSet<kMaxMemoryRange>>(m_pool, false);
 
 	LockGuard<TLock> lock(m_mutex);
 
@@ -226,11 +226,11 @@ void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::debugPrint() const
 
 		printf("\n");
 	}
-	m_alloc.deleteInstance(freeBytes);
+	deleteInstance(m_pool, freeBytes);
 }
 
-template<U32 kMaxMemoryRangeLog2, typename TLock>
-void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock>::getStats(BuddyAllocatorBuilderStats& stats) const
+template<U32 kMaxMemoryRangeLog2, typename TLock, typename TMemPool>
+void BuddyAllocatorBuilder<kMaxMemoryRangeLog2, TLock, TMemPool>::getStats(BuddyAllocatorBuilderStats& stats) const
 {
 	LockGuard<TLock> lock(m_mutex);
 

+ 2 - 2
AnKi/Util/FilesystemWindows.cpp

@@ -26,7 +26,7 @@ Bool directoryExists(const CString& filename)
 	return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
 }
 
-Error removeDirectory(const CString& dirname, GenericMemoryPoolAllocator<U8> alloc)
+Error removeDirectory(const CString& dirname, [[maybe_unused]] BaseMemoryPool& pool)
 {
 	// For some reason dirname should be double null terminated
 	if(dirname.getLength() > MAX_PATH - 2)
@@ -199,7 +199,7 @@ Error walkDirectoryTreeInternal(const CString& dir, const Function<Error(const C
 
 Error getApplicationPath(StringRaii& out)
 {
-	DynamicArrayRaii<Char> buff(out.getAllocator(), 1024);
+	DynamicArrayRaii<Char> buff(&out.getMemoryPool(), 1024);
 
 	const DWORD result = GetModuleFileNameA(nullptr, &buff[0], buff.getSize());
 	DWORD lastError = GetLastError();

+ 2 - 2
AnKi/Util/String.h

@@ -742,7 +742,7 @@ public:
 
 	/// Internal don't use it.
 	template<typename TMemPool>
-	ANKI_INTERNAL void sprintf(TMemPool& pool, const Char* fmt, va_list& args)
+	void sprintfInternal(TMemPool& pool, const Char* fmt, va_list& args)
 	{
 		Array<Char, 512> buffer;
 
@@ -957,7 +957,7 @@ public:
 	{
 		va_list args;
 		va_start(args, fmt);
-		Base::sprintf(m_pool, fmt, args);
+		Base::sprintfInternal(m_pool, fmt, args);
 		va_end(args);
 		return *this;
 	}

+ 4 - 4
Samples/Common/SampleApp.cpp

@@ -9,15 +9,15 @@ using namespace anki;
 
 Error SampleApp::init(int argc, char** argv, CString sampleName)
 {
-	HeapAllocator<U32> alloc(allocAligned, nullptr);
+	HeapMemoryPool pool(allocAligned, nullptr);
 
 	// Init the super class
 	m_config.init(allocAligned, nullptr);
 	m_config.setWindowFullscreen(true);
 
 #if !ANKI_OS_ANDROID
-	StringRaii mainDataPath(alloc, ANKI_SOURCE_DIRECTORY);
-	StringRaii assetsDataPath(alloc);
+	StringRaii mainDataPath(&pool, ANKI_SOURCE_DIRECTORY);
+	StringRaii assetsDataPath(&pool);
 	assetsDataPath.sprintf("%s/Samples/%s", ANKI_SOURCE_DIRECTORY, sampleName.cstr());
 
 	if(!directoryExists(assetsDataPath))
@@ -28,7 +28,7 @@ Error SampleApp::init(int argc, char** argv, CString sampleName)
 	}
 	else
 	{
-		m_config.setRsrcDataPaths(StringRaii(alloc).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()));
+		m_config.setRsrcDataPaths(StringRaii(&pool).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()));
 	}
 #endif
 

+ 2 - 2
Tests/Gr/Gr.cpp

@@ -289,7 +289,7 @@ static Input* input = nullptr;
 static void* setUniforms(PtrSize size, CommandBufferPtr& cmdb, U32 set, U32 binding)
 {
 	StagingGpuMemoryToken token;
-	void* ptr = stagingMem->allocateFrame(size, StagingGpuMemoryType::UNIFORM, token);
+	void* ptr = stagingMem->allocateFrame(size, StagingGpuMemoryType::kUniform, token);
 	cmdb->bindUniformBuffer(set, binding, token.m_buffer, token.m_offset, token.m_range);
 	return ptr;
 }
@@ -297,7 +297,7 @@ static void* setUniforms(PtrSize size, CommandBufferPtr& cmdb, U32 set, U32 bind
 static void* setStorage(PtrSize size, CommandBufferPtr& cmdb, U32 set, U32 binding)
 {
 	StagingGpuMemoryToken token;
-	void* ptr = stagingMem->allocateFrame(size, StagingGpuMemoryType::STORAGE, token);
+	void* ptr = stagingMem->allocateFrame(size, StagingGpuMemoryType::kStorage, token);
 	cmdb->bindStorageBuffer(set, binding, token.m_buffer, token.m_offset, token.m_range);
 	return ptr;
 }