Selaa lähdekoodia

Remove the allocator from resource and input

Panagiotis Christopoulos Charitos 3 vuotta sitten
vanhempi
sitoutus
64f2a0525e
41 muutettua tiedostoa jossa 380 lisäystä ja 369 poistoa
  1. 2 2
      AnKi/Input/Input.h
  2. 29 13
      AnKi/Input/InputSdl.cpp
  3. 0 9
      AnKi/Input/InputSdl.h
  4. 2 1
      AnKi/Physics/PhysicsObject.h
  5. 1 1
      AnKi/Physics/PhysicsWorld.h
  6. 11 11
      AnKi/Resource/AnimationResource.cpp
  7. 6 6
      AnKi/Resource/AnimationResource.h
  8. 5 4
      AnKi/Resource/AsyncLoader.cpp
  9. 5 5
      AnKi/Resource/AsyncLoader.h
  10. 2 2
      AnKi/Resource/Common.cpp
  11. 0 7
      AnKi/Resource/Common.h
  12. 4 4
      AnKi/Resource/CpuMeshResource.cpp
  13. 4 4
      AnKi/Resource/DummyResource.h
  14. 2 2
      AnKi/Resource/GenericResource.cpp
  15. 2 1
      AnKi/Resource/GenericResource.h
  16. 5 5
      AnKi/Resource/ImageAtlasResource.cpp
  17. 34 34
      AnKi/Resource/ImageLoader.cpp
  18. 11 10
      AnKi/Resource/ImageLoader.h
  19. 7 7
      AnKi/Resource/ImageResource.cpp
  20. 44 44
      AnKi/Resource/MaterialResource.cpp
  21. 5 5
      AnKi/Resource/MaterialResource.h
  22. 5 5
      AnKi/Resource/MeshBinaryLoader.cpp
  23. 5 4
      AnKi/Resource/MeshBinaryLoader.h
  24. 12 12
      AnKi/Resource/MeshResource.cpp
  25. 7 9
      AnKi/Resource/ModelResource.cpp
  26. 1 1
      AnKi/Resource/ParticleEmitterResource.cpp
  27. 24 24
      AnKi/Resource/ResourceFilesystem.cpp
  28. 10 8
      AnKi/Resource/ResourceFilesystem.h
  29. 18 18
      AnKi/Resource/ResourceManager.cpp
  30. 13 12
      AnKi/Resource/ResourceManager.h
  31. 7 8
      AnKi/Resource/ResourceObject.cpp
  32. 3 3
      AnKi/Resource/ResourceObject.h
  33. 3 3
      AnKi/Resource/ScriptResource.cpp
  34. 14 14
      AnKi/Resource/ShaderProgramResource.cpp
  35. 27 27
      AnKi/Resource/ShaderProgramResourceSystem.cpp
  36. 10 10
      AnKi/Resource/ShaderProgramResourceSystem.h
  37. 8 8
      AnKi/Resource/SkeletonResource.cpp
  38. 4 4
      AnKi/Resource/SkeletonResource.h
  39. 14 13
      AnKi/Resource/TransferGpuAllocator.cpp
  40. 9 9
      AnKi/Resource/TransferGpuAllocator.h
  41. 5 0
      AnKi/Util/Xml.h

+ 2 - 2
AnKi/Input/Input.h

@@ -29,7 +29,7 @@ enum class InputEvent : U8
 /// @note All positions are in NDC space
 /// @note All positions are in NDC space
 class Input
 class Input
 {
 {
-	ANKI_FRIEND_ALLOCATOR
+	ANKI_FRIEND_CALL_CONSTRUCTOR
 
 
 public:
 public:
 	static Error newInstance(AllocAlignedCallback allocCallback, void* allocCallbackUserData,
 	static Error newInstance(AllocAlignedCallback allocCallback, void* allocCallbackUserData,
@@ -136,7 +136,7 @@ public:
 
 
 protected:
 protected:
 	NativeWindow* m_nativeWindow = nullptr;
 	NativeWindow* m_nativeWindow = nullptr;
-	HeapAllocator<U8> m_alloc;
+	HeapMemoryPool m_pool;
 
 
 	/// Shows the current key state
 	/// Shows the current key state
 	/// - 0 times: unpressed
 	/// - 0 times: unpressed

+ 29 - 13
AnKi/Input/InputSdl.cpp

@@ -31,22 +31,40 @@ static MouseButton sdlMouseButtonToAnKi(const U32 sdl)
 	return out;
 	return out;
 }
 }
 
 
+static KeyCode sdlKeytoAnKi(SDL_Keycode sdlk)
+{
+	KeyCode akk = KeyCode::kUnknown;
+	switch(sdlk)
+	{
+#define ANKI_KEY_CODE(ak, sdl) \
+	case SDLK_##sdl: \
+		akk = KeyCode::k##ak; \
+		break;
+#include <AnKi/Input/KeyCode.defs.h>
+#undef ANKI_KEY_CODE
+	}
+
+	ANKI_ASSERT(akk != KeyCode::kUnknown);
+	return akk;
+}
+
 Error Input::newInstance(AllocAlignedCallback allocCallback, void* allocCallbackUserData, NativeWindow* nativeWindow,
 Error Input::newInstance(AllocAlignedCallback allocCallback, void* allocCallbackUserData, NativeWindow* nativeWindow,
 						 Input*& input)
 						 Input*& input)
 {
 {
 	ANKI_ASSERT(allocCallback && nativeWindow);
 	ANKI_ASSERT(allocCallback && nativeWindow);
 
 
-	HeapAllocator<U8> alloc(allocCallback, allocCallbackUserData, "Input");
-	InputSdl* sdlinput = alloc.newInstance<InputSdl>(alloc);
+	InputSdl* sdlinput =
+		static_cast<InputSdl*>(allocCallback(allocCallbackUserData, nullptr, sizeof(InputSdl), alignof(InputSdl)));
+	callConstructor(*sdlinput);
 
 
-	sdlinput->m_alloc = alloc;
+	sdlinput->m_pool.init(allocCallback, allocCallbackUserData);
 	sdlinput->m_nativeWindow = nativeWindow;
 	sdlinput->m_nativeWindow = nativeWindow;
 
 
 	const Error err = sdlinput->init();
 	const Error err = sdlinput->init();
 	if(err)
 	if(err)
 	{
 	{
-		sdlinput->~InputSdl();
-		alloc.getMemoryPool().free(sdlinput);
+		callDestructor(*sdlinput);
+		allocCallback(allocCallbackUserData, sdlinput, 0, 0);
 		input = nullptr;
 		input = nullptr;
 		return err;
 		return err;
 	}
 	}
@@ -62,8 +80,10 @@ void Input::deleteInstance(Input* input)
 	if(input)
 	if(input)
 	{
 	{
 		InputSdl* self = static_cast<InputSdl*>(input);
 		InputSdl* self = static_cast<InputSdl*>(input);
-		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);
 	}
 	}
 }
 }
 
 
@@ -106,10 +126,6 @@ Error InputSdl::init()
 {
 {
 	ANKI_ASSERT(m_nativeWindow);
 	ANKI_ASSERT(m_nativeWindow);
 
 
-#define ANKI_KEY_CODE(ak, sdl) m_sdlToAnki[SDLK_##sdl] = KeyCode::k##ak;
-#include <AnKi/Input/KeyCode.defs.h>
-#undef ANKI_KEY_CODE
-
 	// Call once to clear first events
 	// Call once to clear first events
 	return handleEvents();
 	return handleEvents();
 }
 }
@@ -144,11 +160,11 @@ Error InputSdl::handleEventsInternal()
 		switch(event.type)
 		switch(event.type)
 		{
 		{
 		case SDL_KEYDOWN:
 		case SDL_KEYDOWN:
-			akkey = m_sdlToAnki[event.key.keysym.sym];
+			akkey = sdlKeytoAnKi(event.key.keysym.sym);
 			m_keys[akkey] = 1;
 			m_keys[akkey] = 1;
 			break;
 			break;
 		case SDL_KEYUP:
 		case SDL_KEYUP:
-			akkey = m_sdlToAnki[event.key.keysym.sym];
+			akkey = sdlKeytoAnKi(event.key.keysym.sym);
 			m_keys[akkey] = 0;
 			m_keys[akkey] = 0;
 			break;
 			break;
 		case SDL_MOUSEBUTTONDOWN:
 		case SDL_MOUSEBUTTONDOWN:

+ 0 - 9
AnKi/Input/InputSdl.h

@@ -16,15 +16,6 @@ namespace anki {
 class InputSdl : public Input
 class InputSdl : public Input
 {
 {
 public:
 public:
-	std::unordered_map<SDL_Keycode, KeyCode, std::hash<SDL_Keycode>, std::equal_to<SDL_Keycode>,
-					   HeapAllocator<std::pair<const SDL_Keycode, KeyCode>>>
-		m_sdlToAnki;
-
-	InputSdl(HeapAllocator<std::pair<const SDL_Keycode, KeyCode>> alloc)
-		: m_sdlToAnki(10, std::hash<SDL_Keycode>(), std::equal_to<SDL_Keycode>(), alloc)
-	{
-	}
-
 	Error init();
 	Error init();
 	Error handleEventsInternal();
 	Error handleEventsInternal();
 };
 };

+ 2 - 1
AnKi/Physics/PhysicsObject.h

@@ -34,7 +34,8 @@ ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(PhysicsObjectType)
 	friend class PhysicsWorld; \
 	friend class PhysicsWorld; \
 	friend class PhysicsPtrDeleter; \
 	friend class PhysicsPtrDeleter; \
 	template<typename T, typename TDeleter> \
 	template<typename T, typename TDeleter> \
-	friend class IntrusivePtr;
+	friend class IntrusivePtr; \
+	ANKI_FRIEND_CALL_CONSTRUCTOR
 
 
 #define ANKI_PHYSICS_OBJECT(type) \
 #define ANKI_PHYSICS_OBJECT(type) \
 	ANKI_PHYSICS_OBJECT_FRIENDS \
 	ANKI_PHYSICS_OBJECT_FRIENDS \

+ 1 - 1
AnKi/Physics/PhysicsWorld.h

@@ -49,7 +49,7 @@ public:
 	PhysicsPtr<T> newInstance(TArgs&&... args)
 	PhysicsPtr<T> newInstance(TArgs&&... args)
 	{
 	{
 		T* obj = static_cast<T*>(m_pool.allocate(sizeof(T), alignof(T)));
 		T* obj = static_cast<T*>(m_pool.allocate(sizeof(T), alignof(T)));
-		callConstructor(&obj, this, std::forward<TArgs>(args)...);
+		callConstructor(*obj, this, std::forward<TArgs>(args)...);
 		{
 		{
 			LockGuard<Mutex> lock(m_markedMtx);
 			LockGuard<Mutex> lock(m_markedMtx);
 			m_markedForCreation.pushBack(obj);
 			m_markedForCreation.pushBack(obj);

+ 11 - 11
AnKi/Resource/AnimationResource.cpp

@@ -17,10 +17,10 @@ AnimationResource::~AnimationResource()
 {
 {
 	for(AnimationChannel& ch : m_channels)
 	for(AnimationChannel& ch : m_channels)
 	{
 	{
-		ch.destroy(getAllocator());
+		ch.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_channels.destroy(getAllocator());
+	m_channels.destroy(getMemoryPool());
 }
 }
 
 
 Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
@@ -31,7 +31,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 	Second maxTime = kMinSecond;
 	Second maxTime = kMinSecond;
 
 
 	// Document
 	// Document
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	XmlElement rootel;
 	XmlElement rootel;
 	ANKI_CHECK(doc.getChildElement("animation", rootel));
 	ANKI_CHECK(doc.getChildElement("animation", rootel));
@@ -55,7 +55,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 		ANKI_RESOURCE_LOGE("Didn't found any channels");
 		ANKI_RESOURCE_LOGE("Didn't found any channels");
 		return Error::kUserData;
 		return Error::kUserData;
 	}
 	}
-	m_channels.create(getAllocator(), channelCount);
+	m_channels.create(getMemoryPool(), channelCount);
 
 
 	// For all channels
 	// For all channels
 	channelCount = 0;
 	channelCount = 0;
@@ -66,7 +66,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 		// <name>
 		// <name>
 		CString strtmp;
 		CString strtmp;
 		ANKI_CHECK(chEl.getAttributeText("name", strtmp));
 		ANKI_CHECK(chEl.getAttributeText("name", strtmp));
-		ch.m_name.create(getAllocator(), strtmp);
+		ch.m_name.create(getMemoryPool(), strtmp);
 
 
 		XmlElement keysEl, keyEl;
 		XmlElement keysEl, keyEl;
 
 
@@ -79,7 +79,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 			U32 count = 0;
 			U32 count = 0;
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			++count;
 			++count;
-			ch.m_positions.create(getAllocator(), count);
+			ch.m_positions.create(getMemoryPool(), count);
 
 
 			count = 0;
 			count = 0;
 			do
 			do
@@ -114,7 +114,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 			U32 count = 0;
 			U32 count = 0;
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			++count;
 			++count;
-			ch.m_rotations.create(getAllocator(), count);
+			ch.m_rotations.create(getMemoryPool(), count);
 
 
 			count = 0;
 			count = 0;
 			do
 			do
@@ -149,7 +149,7 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 			U32 count = 0;
 			U32 count = 0;
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			ANKI_CHECK(keyEl.getSiblingElementsCount(count));
 			++count;
 			++count;
-			ch.m_scales.create(getAllocator(), count);
+			ch.m_scales.create(getMemoryPool(), count);
 
 
 			count = 0;
 			count = 0;
 			do
 			do
@@ -179,17 +179,17 @@ Error AnimationResource::load(const ResourceFilename& filename, [[maybe_unused]]
 		// Remove identity vectors
 		// Remove identity vectors
 		if(identPosCount == ch.m_positions.getSize())
 		if(identPosCount == ch.m_positions.getSize())
 		{
 		{
-			ch.m_positions.destroy(getAllocator());
+			ch.m_positions.destroy(getMemoryPool());
 		}
 		}
 
 
 		if(identRotCount == ch.m_rotations.getSize())
 		if(identRotCount == ch.m_rotations.getSize())
 		{
 		{
-			ch.m_rotations.destroy(getAllocator());
+			ch.m_rotations.destroy(getMemoryPool());
 		}
 		}
 
 
 		if(identScaleCount == ch.m_scales.getSize())
 		if(identScaleCount == ch.m_scales.getSize())
 		{
 		{
-			ch.m_scales.destroy(getAllocator());
+			ch.m_scales.destroy(getMemoryPool());
 		}
 		}
 
 
 		// Move to next channel
 		// Move to next channel

+ 6 - 6
AnKi/Resource/AnimationResource.h

@@ -53,13 +53,13 @@ public:
 	DynamicArray<AnimationKeyframe<F32>> m_scales;
 	DynamicArray<AnimationKeyframe<F32>> m_scales;
 	DynamicArray<AnimationKeyframe<F32>> m_cameraFovs;
 	DynamicArray<AnimationKeyframe<F32>> m_cameraFovs;
 
 
-	void destroy(ResourceAllocator<U8> alloc)
+	void destroy(HeapMemoryPool& pool)
 	{
 	{
-		m_name.destroy(alloc);
-		m_positions.destroy(alloc);
-		m_rotations.destroy(alloc);
-		m_scales.destroy(alloc);
-		m_cameraFovs.destroy(alloc);
+		m_name.destroy(pool);
+		m_positions.destroy(pool);
+		m_rotations.destroy(pool);
+		m_scales.destroy(pool);
+		m_cameraFovs.destroy(pool);
 	}
 	}
 };
 };
 
 

+ 5 - 4
AnKi/Resource/AsyncLoader.cpp

@@ -26,14 +26,15 @@ AsyncLoader::~AsyncLoader()
 		{
 		{
 			AsyncLoaderTask* task = &m_taskQueue.getFront();
 			AsyncLoaderTask* task = &m_taskQueue.getFront();
 			m_taskQueue.popFront();
 			m_taskQueue.popFront();
-			m_alloc.deleteInstance(task);
+			deleteInstance(*m_pool, task);
 		}
 		}
 	}
 	}
 }
 }
 
 
-void AsyncLoader::init(const HeapAllocator<U8>& alloc)
+void AsyncLoader::init(HeapMemoryPool* pool)
 {
 {
-	m_alloc = alloc;
+	ANKI_ASSERT(pool);
+	m_pool = pool;
 	m_thread.start(this, threadCallback);
 	m_thread.start(this, threadCallback);
 }
 }
 
 
@@ -145,7 +146,7 @@ Error AsyncLoader::threadWorker()
 			else
 			else
 			{
 			{
 				// Delete the task
 				// Delete the task
-				m_alloc.deleteInstance(task);
+				deleteInstance(*m_pool, task);
 			}
 			}
 
 
 			if(ctx.m_pause)
 			if(ctx.m_pause)

+ 5 - 5
AnKi/Resource/AsyncLoader.h

@@ -46,7 +46,7 @@ public:
 
 
 	~AsyncLoader();
 	~AsyncLoader();
 
 
-	void init(const HeapAllocator<U8>& alloc);
+	void init(HeapMemoryPool* pool);
 
 
 	/// Submit a task.
 	/// Submit a task.
 	void submitTask(AsyncLoaderTask* task);
 	void submitTask(AsyncLoaderTask* task);
@@ -55,7 +55,7 @@ public:
 	template<typename TTask, typename... TArgs>
 	template<typename TTask, typename... TArgs>
 	TTask* newTask(TArgs&&... args)
 	TTask* newTask(TArgs&&... args)
 	{
 	{
-		return m_alloc.template newInstance<TTask>(std::forward<TArgs>(args)...);
+		return newInstance<TTask>(*m_pool, std::forward<TArgs>(args)...);
 	}
 	}
 
 
 	/// Create and submit a new asynchronous loading task.
 	/// Create and submit a new asynchronous loading task.
@@ -72,9 +72,9 @@ public:
 	/// Resume the async loading.
 	/// Resume the async loading.
 	void resume();
 	void resume();
 
 
-	HeapAllocator<U8> getAllocator() const
+	HeapMemoryPool& getMemoryPool() const
 	{
 	{
-		return m_alloc;
+		return *m_pool;
 	}
 	}
 
 
 	/// Get the total number of completed tasks.
 	/// Get the total number of completed tasks.
@@ -84,7 +84,7 @@ public:
 	}
 	}
 
 
 private:
 private:
-	HeapAllocator<U8> m_alloc;
+	mutable HeapMemoryPool* m_pool = nullptr;
 	Thread m_thread;
 	Thread m_thread;
 	Barrier m_barrier = {2};
 	Barrier m_barrier = {2};
 
 

+ 2 - 2
AnKi/Resource/Common.cpp

@@ -14,8 +14,8 @@ template<typename T>
 void ResourcePtrDeleter<T>::operator()(T* ptr)
 void ResourcePtrDeleter<T>::operator()(T* ptr)
 {
 {
 	ptr->getManager().unregisterResource(ptr);
 	ptr->getManager().unregisterResource(ptr);
-	auto alloc = ptr->getAllocator();
-	alloc.deleteInstance(ptr);
+	HeapMemoryPool& pool = ptr->getMemoryPool();
+	deleteInstance(pool, ptr);
 }
 }
 
 
 #define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) template void ResourcePtrDeleter<rsrc_>::operator()(rsrc_* ptr);
 #define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) template void ResourcePtrDeleter<rsrc_>::operator()(rsrc_* ptr);

+ 0 - 7
AnKi/Resource/Common.h

@@ -5,7 +5,6 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <AnKi/Util/Allocator.h>
 #include <AnKi/Util/DynamicArray.h>
 #include <AnKi/Util/DynamicArray.h>
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/String.h>
 #include <AnKi/Util/Ptr.h>
 #include <AnKi/Util/Ptr.h>
@@ -54,12 +53,6 @@ using ResourcePtr = IntrusivePtr<T, ResourcePtrDeleter<T>>;
 #undef ANKI_INSTANTIATE_RESOURCE
 #undef ANKI_INSTANTIATE_RESOURCE
 #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
 #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
 
 
-template<typename T>
-using ResourceAllocator = HeapAllocator<T>;
-
-template<typename T>
-using TempResourceAllocator = StackAllocator<T>;
-
 /// An alias that denotes a ResourceFilesystem path.
 /// An alias that denotes a ResourceFilesystem path.
 using ResourceFilename = CString;
 using ResourceFilename = CString;
 /// @}
 /// @}

+ 4 - 4
AnKi/Resource/CpuMeshResource.cpp

@@ -17,8 +17,8 @@ CpuMeshResource::CpuMeshResource(ResourceManager* manager)
 
 
 CpuMeshResource::~CpuMeshResource()
 CpuMeshResource::~CpuMeshResource()
 {
 {
-	m_indices.destroy(getAllocator());
-	m_positions.destroy(getAllocator());
+	m_indices.destroy(getMemoryPool());
+	m_positions.destroy(getMemoryPool());
 }
 }
 
 
 Error CpuMeshResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error CpuMeshResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
@@ -27,8 +27,8 @@ Error CpuMeshResource::load(const ResourceFilename& filename, [[maybe_unused]] B
 
 
 	ANKI_CHECK(loader.load(filename));
 	ANKI_CHECK(loader.load(filename));
 
 
-	DynamicArrayRaii<Vec3> tempPositions(getAllocator());
-	DynamicArrayRaii<U32> tempIndices(getAllocator());
+	DynamicArrayRaii<Vec3> tempPositions(&getMemoryPool());
+	DynamicArrayRaii<U32> tempIndices(&getMemoryPool());
 
 
 	ANKI_CHECK(loader.storeIndicesAndPosition(tempIndices, tempPositions));
 	ANKI_CHECK(loader.storeIndicesAndPosition(tempIndices, tempPositions));
 
 

+ 4 - 4
AnKi/Resource/DummyResource.h

@@ -25,7 +25,7 @@ public:
 	{
 	{
 		if(m_memory)
 		if(m_memory)
 		{
 		{
-			getAllocator().deallocate(m_memory, 128);
+			getMemoryPool().free(m_memory);
 		}
 		}
 	}
 	}
 
 
@@ -34,10 +34,10 @@ public:
 		Error err = Error::kNone;
 		Error err = Error::kNone;
 		if(filename.find("error") == CString::kNpos)
 		if(filename.find("error") == CString::kNpos)
 		{
 		{
-			m_memory = getAllocator().allocate(128);
-			void* tempMem = getTempAllocator().allocate(128);
+			m_memory = getMemoryPool().allocate(128, 1);
+			void* tempMem = getTempMemoryPool().allocate(128, 1);
 
 
-			getTempAllocator().deallocate(tempMem, 128);
+			getTempMemoryPool().free(tempMem);
 		}
 		}
 		else
 		else
 		{
 		{

+ 2 - 2
AnKi/Resource/GenericResource.cpp

@@ -14,7 +14,7 @@ GenericResource::GenericResource(ResourceManager* manager)
 
 
 GenericResource::~GenericResource()
 GenericResource::~GenericResource()
 {
 {
-	m_data.destroy(getAllocator());
+	m_data.destroy(getMemoryPool());
 }
 }
 
 
 Error GenericResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error GenericResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
@@ -23,7 +23,7 @@ Error GenericResource::load(const ResourceFilename& filename, [[maybe_unused]] B
 	ANKI_CHECK(openFile(filename, file));
 	ANKI_CHECK(openFile(filename, file));
 
 
 	const U32 size = U32(file->getSize());
 	const U32 size = U32(file->getSize());
-	m_data.create(getAllocator(), size);
+	m_data.create(getMemoryPool(), size);
 	ANKI_CHECK(file->read(&m_data[0], size));
 	ANKI_CHECK(file->read(&m_data[0], size));
 
 
 	return Error::kNone;
 	return Error::kNone;

+ 2 - 1
AnKi/Resource/GenericResource.h

@@ -6,6 +6,7 @@
 #pragma once
 #pragma once
 
 
 #include <AnKi/Resource/ResourceObject.h>
 #include <AnKi/Resource/ResourceObject.h>
+#include <AnKi/Util/WeakArray.h>
 
 
 namespace anki {
 namespace anki {
 
 
@@ -22,7 +23,7 @@ public:
 
 
 	Error load(const ResourceFilename& filename, Bool async);
 	Error load(const ResourceFilename& filename, Bool async);
 
 
-	const DynamicArray<U8>& getData() const
+	ConstWeakArray<U8> getData() const
 	{
 	{
 		return m_data;
 		return m_data;
 	}
 	}

+ 5 - 5
AnKi/Resource/ImageAtlasResource.cpp

@@ -16,13 +16,13 @@ ImageAtlasResource::ImageAtlasResource(ResourceManager* manager)
 
 
 ImageAtlasResource::~ImageAtlasResource()
 ImageAtlasResource::~ImageAtlasResource()
 {
 {
-	m_subTexes.destroy(getAllocator());
-	m_subTexNames.destroy(getAllocator());
+	m_subTexes.destroy(getMemoryPool());
+	m_subTexNames.destroy(getMemoryPool());
 }
 }
 
 
 Error ImageAtlasResource::load(const ResourceFilename& filename, Bool async)
 Error ImageAtlasResource::load(const ResourceFilename& filename, Bool async)
 {
 {
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 
 
 	XmlElement rootel, el;
 	XmlElement rootel, el;
@@ -85,8 +85,8 @@ Error ImageAtlasResource::load(const ResourceFilename& filename, Bool async)
 	} while(subTexEl);
 	} while(subTexEl);
 
 
 	// Allocate
 	// Allocate
-	m_subTexNames.create(getAllocator(), namesSize);
-	m_subTexes.create(getAllocator(), subTexesCount);
+	m_subTexNames.create(getMemoryPool(), namesSize);
+	m_subTexes.create(getMemoryPool(), subTexesCount);
 
 
 	// Iterate again and populate
 	// Iterate again and populate
 	subTexesCount = 0;
 	subTexesCount = 0;

+ 34 - 34
AnKi/Resource/ImageLoader.cpp

@@ -10,8 +10,8 @@
 
 
 namespace anki {
 namespace anki {
 
 
-inline constexpr U8 TGA_HEADER_UNCOMPRESSED[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-inline constexpr U8 TGA_HEADER_COMPRESSED[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+inline constexpr U8 kTgaHeaderUncompressed[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+inline constexpr U8 kTgaHeaderCompressed[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
 
 static PtrSize calcRawTexelSize(const ImageBinaryColorFormat cf)
 static PtrSize calcRawTexelSize(const ImageBinaryColorFormat cf)
 {
 {
@@ -234,7 +234,7 @@ public:
 };
 };
 
 
 Error ImageLoader::loadUncompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
 Error ImageLoader::loadUncompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
-									   DynamicArray<U8, PtrSize>& data, GenericMemoryPoolAllocator<U8>& alloc)
+									   DynamicArray<U8, PtrSize>& data, BaseMemoryPool& pool)
 {
 {
 	Array<U8, 6> header6;
 	Array<U8, 6> header6;
 
 
@@ -254,7 +254,7 @@ Error ImageLoader::loadUncompressedTga(FileInterface& fs, U32& width, U32& heigh
 	// Read the data
 	// Read the data
 	const PtrSize bytesPerPxl = (bpp / 8);
 	const PtrSize bytesPerPxl = (bpp / 8);
 	const PtrSize imageSize = bytesPerPxl * width * height;
 	const PtrSize imageSize = bytesPerPxl * width * height;
-	data.create(alloc, imageSize);
+	data.create(pool, imageSize);
 
 
 	ANKI_CHECK(fs.read(reinterpret_cast<char*>(&data[0]), imageSize));
 	ANKI_CHECK(fs.read(reinterpret_cast<char*>(&data[0]), imageSize));
 
 
@@ -270,7 +270,7 @@ Error ImageLoader::loadUncompressedTga(FileInterface& fs, U32& width, U32& heigh
 }
 }
 
 
 Error ImageLoader::loadCompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
 Error ImageLoader::loadCompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
-									 DynamicArray<U8, PtrSize>& data, GenericMemoryPoolAllocator<U8>& alloc)
+									 DynamicArray<U8, PtrSize>& data, BaseMemoryPool& pool)
 {
 {
 	Array<U8, 6> header6;
 	Array<U8, 6> header6;
 	ANKI_CHECK(fs.read(&header6[0], sizeof(header6)));
 	ANKI_CHECK(fs.read(&header6[0], sizeof(header6)));
@@ -287,7 +287,7 @@ Error ImageLoader::loadCompressedTga(FileInterface& fs, U32& width, U32& height,
 
 
 	const PtrSize bytesPerPxl = (bpp / 8);
 	const PtrSize bytesPerPxl = (bpp / 8);
 	const PtrSize imageSize = bytesPerPxl * width * height;
 	const PtrSize imageSize = bytesPerPxl * width * height;
-	data.create(alloc, imageSize);
+	data.create(pool, imageSize);
 
 
 	const PtrSize pixelCount = height * width;
 	const PtrSize pixelCount = height * width;
 	PtrSize currentPixel = 0;
 	PtrSize currentPixel = 0;
@@ -348,7 +348,7 @@ Error ImageLoader::loadCompressedTga(FileInterface& fs, U32& width, U32& height,
 				if(currentPixel > pixelCount)
 				if(currentPixel > pixelCount)
 				{
 				{
 					ANKI_RESOURCE_LOGE("Too many pixels read");
 					ANKI_RESOURCE_LOGE("Too many pixels read");
-					data.destroy(alloc);
+					data.destroy(pool);
 					return Error::kUserData;
 					return Error::kUserData;
 				}
 				}
 			}
 			}
@@ -359,19 +359,19 @@ Error ImageLoader::loadCompressedTga(FileInterface& fs, U32& width, U32& height,
 }
 }
 
 
 Error ImageLoader::loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray<U8, PtrSize>& data,
 Error ImageLoader::loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray<U8, PtrSize>& data,
-						   GenericMemoryPoolAllocator<U8>& alloc)
+						   BaseMemoryPool& pool)
 {
 {
 	Array<Char, 12> myTgaHeader;
 	Array<Char, 12> myTgaHeader;
 
 
 	ANKI_CHECK(fs.read(&myTgaHeader[0], sizeof(myTgaHeader)));
 	ANKI_CHECK(fs.read(&myTgaHeader[0], sizeof(myTgaHeader)));
 
 
-	if(memcmp(TGA_HEADER_UNCOMPRESSED, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
+	if(memcmp(kTgaHeaderUncompressed, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
 	{
 	{
-		ANKI_CHECK(loadUncompressedTga(fs, width, height, bpp, data, alloc));
+		ANKI_CHECK(loadUncompressedTga(fs, width, height, bpp, data, pool));
 	}
 	}
-	else if(std::memcmp(TGA_HEADER_COMPRESSED, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
+	else if(std::memcmp(kTgaHeaderCompressed, &myTgaHeader[0], sizeof(myTgaHeader)) == 0)
 	{
 	{
-		ANKI_CHECK(loadCompressedTga(fs, width, height, bpp, data, alloc));
+		ANKI_CHECK(loadCompressedTga(fs, width, height, bpp, data, pool));
 	}
 	}
 	else
 	else
 	{
 	{
@@ -391,9 +391,9 @@ Error ImageLoader::loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
 Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 								 ImageBinaryDataCompression& preferredCompression,
 								 ImageBinaryDataCompression& preferredCompression,
 								 DynamicArray<ImageLoaderSurface>& surfaces, DynamicArray<ImageLoaderVolume>& volumes,
 								 DynamicArray<ImageLoaderSurface>& surfaces, DynamicArray<ImageLoaderVolume>& volumes,
-								 GenericMemoryPoolAllocator<U8>& alloc, U32& width, U32& height, U32& depth,
-								 U32& layerCount, U32& mipCount, ImageBinaryType& imageType,
-								 ImageBinaryColorFormat& colorFormat, UVec2& astcBlockSize)
+								 BaseMemoryPool& pool, U32& width, U32& height, U32& depth, U32& layerCount,
+								 U32& mipCount, ImageBinaryType& imageType, ImageBinaryColorFormat& colorFormat,
+								 UVec2& astcBlockSize)
 {
 {
 	//
 	//
 	// Read and check the header
 	// Read and check the header
@@ -571,11 +571,11 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 					// Check if this mipmap can be skipped because of size
 					// Check if this mipmap can be skipped because of size
 					if(max(mipWidth, mipHeight) <= maxImageSize || mip == header.m_mipmapCount - 1)
 					if(max(mipWidth, mipHeight) <= maxImageSize || mip == header.m_mipmapCount - 1)
 					{
 					{
-						ImageLoaderSurface& surf = *surfaces.emplaceBack(alloc);
+						ImageLoaderSurface& surf = *surfaces.emplaceBack(pool);
 						surf.m_width = mipWidth;
 						surf.m_width = mipWidth;
 						surf.m_height = mipHeight;
 						surf.m_height = mipHeight;
 
 
-						surf.m_data.create(alloc, dataSize);
+						surf.m_data.create(pool, dataSize);
 						ANKI_CHECK(file.read(&surf.m_data[0], dataSize));
 						ANKI_CHECK(file.read(&surf.m_data[0], dataSize));
 
 
 						mipCount = max(header.m_mipmapCount - mip, mipCount);
 						mipCount = max(header.m_mipmapCount - mip, mipCount);
@@ -608,12 +608,12 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 			// Check if this mipmap can be skipped because of size
 			// Check if this mipmap can be skipped because of size
 			if(max(max(mipWidth, mipHeight), mipDepth) <= maxImageSize || mip == header.m_mipmapCount - 1)
 			if(max(max(mipWidth, mipHeight), mipDepth) <= maxImageSize || mip == header.m_mipmapCount - 1)
 			{
 			{
-				ImageLoaderVolume& vol = *volumes.emplaceBack(alloc);
+				ImageLoaderVolume& vol = *volumes.emplaceBack(pool);
 				vol.m_width = mipWidth;
 				vol.m_width = mipWidth;
 				vol.m_height = mipHeight;
 				vol.m_height = mipHeight;
 				vol.m_depth = mipDepth;
 				vol.m_depth = mipDepth;
 
 
-				vol.m_data.create(alloc, dataSize);
+				vol.m_data.create(pool, dataSize);
 				ANKI_CHECK(file.read(&vol.m_data[0], dataSize));
 				ANKI_CHECK(file.read(&vol.m_data[0], dataSize));
 
 
 				mipCount = max(header.m_mipmapCount - mip, mipCount);
 				mipCount = max(header.m_mipmapCount - mip, mipCount);
@@ -637,10 +637,10 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 }
 }
 
 
 Error ImageLoader::loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& height, DynamicArray<U8, PtrSize>& data,
 Error ImageLoader::loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& height, DynamicArray<U8, PtrSize>& data,
-						   GenericMemoryPoolAllocator<U8>& alloc)
+						   BaseMemoryPool& pool)
 {
 {
 	// Read the file
 	// Read the file
-	DynamicArrayRaii<U8, PtrSize> fileData(alloc);
+	DynamicArrayRaii<U8, PtrSize> fileData(&pool);
 	const PtrSize fileSize = fs.getSize();
 	const PtrSize fileSize = fs.getSize();
 	fileData.create(fileSize);
 	fileData.create(fileSize);
 	ANKI_CHECK(fs.read(&fileData[0], fileSize));
 	ANKI_CHECK(fs.read(&fileData[0], fileSize));
@@ -668,7 +668,7 @@ Error ImageLoader::loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& hei
 	width = U32(stbw);
 	width = U32(stbw);
 	height = U32(stbh);
 	height = U32(stbh);
 	const U32 componentSize = (isFloat) ? sizeof(F32) : sizeof(U8);
 	const U32 componentSize = (isFloat) ? sizeof(F32) : sizeof(U8);
-	data.create(alloc, width * height * 4 * componentSize);
+	data.create(pool, width * height * 4 * componentSize);
 	memcpy(&data[0], stbdata, data.getSize());
 	memcpy(&data[0], stbdata, data.getSize());
 
 
 	// Cleanup
 	// Cleanup
@@ -708,7 +708,7 @@ Error ImageLoader::load(const CString& filename, U32 maxImageSize)
 Error ImageLoader::loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize)
 Error ImageLoader::loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize)
 {
 {
 	// get the extension
 	// get the extension
-	StringRaii ext(m_alloc);
+	StringRaii ext(m_pool);
 	getFilepathExtension(filename, ext);
 	getFilepathExtension(filename, ext);
 
 
 	if(ext.isEmpty())
 	if(ext.isEmpty())
@@ -723,13 +723,13 @@ Error ImageLoader::loadInternal(FileInterface& file, const CString& filename, U3
 
 
 	if(ext == "tga")
 	if(ext == "tga")
 	{
 	{
-		m_surfaces.create(m_alloc, 1);
+		m_surfaces.create(*m_pool, 1);
 
 
 		m_mipmapCount = 1;
 		m_mipmapCount = 1;
 		m_depth = 1;
 		m_depth = 1;
 		m_layerCount = 1;
 		m_layerCount = 1;
 		U32 bpp = 0;
 		U32 bpp = 0;
-		ANKI_CHECK(loadTga(file, m_surfaces[0].m_width, m_surfaces[0].m_height, bpp, m_surfaces[0].m_data, m_alloc));
+		ANKI_CHECK(loadTga(file, m_surfaces[0].m_width, m_surfaces[0].m_height, bpp, m_surfaces[0].m_data, *m_pool));
 
 
 		m_width = m_surfaces[0].m_width;
 		m_width = m_surfaces[0].m_width;
 		m_height = m_surfaces[0].m_height;
 		m_height = m_surfaces[0].m_height;
@@ -755,33 +755,33 @@ Error ImageLoader::loadInternal(FileInterface& file, const CString& filename, U3
 		m_compression = ImageBinaryDataCompression::kS3tc;
 		m_compression = ImageBinaryDataCompression::kS3tc;
 #endif
 #endif
 
 
-		ANKI_CHECK(loadAnkiImage(file, maxImageSize, m_compression, m_surfaces, m_volumes, m_alloc, m_width, m_height,
+		ANKI_CHECK(loadAnkiImage(file, maxImageSize, m_compression, m_surfaces, m_volumes, *m_pool, m_width, m_height,
 								 m_depth, m_layerCount, m_mipmapCount, m_imageType, m_colorFormat, m_astcBlockSize));
 								 m_depth, m_layerCount, m_mipmapCount, m_imageType, m_colorFormat, m_astcBlockSize));
 	}
 	}
 	else if(ext == "png" || ext == "jpg")
 	else if(ext == "png" || ext == "jpg")
 	{
 	{
-		m_surfaces.create(m_alloc, 1);
+		m_surfaces.create(*m_pool, 1);
 
 
 		m_mipmapCount = 1;
 		m_mipmapCount = 1;
 		m_depth = 1;
 		m_depth = 1;
 		m_layerCount = 1;
 		m_layerCount = 1;
 		m_colorFormat = ImageBinaryColorFormat::kRgba8;
 		m_colorFormat = ImageBinaryColorFormat::kRgba8;
 
 
-		ANKI_CHECK(loadStb(false, file, m_surfaces[0].m_width, m_surfaces[0].m_height, m_surfaces[0].m_data, m_alloc));
+		ANKI_CHECK(loadStb(false, file, m_surfaces[0].m_width, m_surfaces[0].m_height, m_surfaces[0].m_data, *m_pool));
 
 
 		m_width = m_surfaces[0].m_width;
 		m_width = m_surfaces[0].m_width;
 		m_height = m_surfaces[0].m_height;
 		m_height = m_surfaces[0].m_height;
 	}
 	}
 	else if(ext == "hdr")
 	else if(ext == "hdr")
 	{
 	{
-		m_surfaces.create(m_alloc, 1);
+		m_surfaces.create(*m_pool, 1);
 
 
 		m_mipmapCount = 1;
 		m_mipmapCount = 1;
 		m_depth = 1;
 		m_depth = 1;
 		m_layerCount = 1;
 		m_layerCount = 1;
 		m_colorFormat = ImageBinaryColorFormat::kRgbaFloat;
 		m_colorFormat = ImageBinaryColorFormat::kRgbaFloat;
 
 
-		ANKI_CHECK(loadStb(true, file, m_surfaces[0].m_width, m_surfaces[0].m_height, m_surfaces[0].m_data, m_alloc));
+		ANKI_CHECK(loadStb(true, file, m_surfaces[0].m_width, m_surfaces[0].m_height, m_surfaces[0].m_data, *m_pool));
 
 
 		m_width = m_surfaces[0].m_width;
 		m_width = m_surfaces[0].m_width;
 		m_height = m_surfaces[0].m_height;
 		m_height = m_surfaces[0].m_height;
@@ -833,17 +833,17 @@ void ImageLoader::destroy()
 {
 {
 	for(ImageLoaderSurface& surf : m_surfaces)
 	for(ImageLoaderSurface& surf : m_surfaces)
 	{
 	{
-		surf.m_data.destroy(m_alloc);
+		surf.m_data.destroy(*m_pool);
 	}
 	}
 
 
-	m_surfaces.destroy(m_alloc);
+	m_surfaces.destroy(*m_pool);
 
 
 	for(ImageLoaderVolume& v : m_volumes)
 	for(ImageLoaderVolume& v : m_volumes)
 	{
 	{
-		v.m_data.destroy(m_alloc);
+		v.m_data.destroy(*m_pool);
 	}
 	}
 
 
-	m_volumes.destroy(m_alloc);
+	m_volumes.destroy(*m_pool);
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 11 - 10
AnKi/Resource/ImageLoader.h

@@ -36,9 +36,10 @@ public:
 class ImageLoader
 class ImageLoader
 {
 {
 public:
 public:
-	ImageLoader(GenericMemoryPoolAllocator<U8> alloc)
-		: m_alloc(alloc)
+	ImageLoader(BaseMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(pool);
 	}
 	}
 
 
 	~ImageLoader()
 	~ImageLoader()
@@ -114,7 +115,7 @@ private:
 	class RsrcFile;
 	class RsrcFile;
 	class SystemFile;
 	class SystemFile;
 
 
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 
 
 	/// [mip][depth or face or layer]. Loader doesn't support cube arrays ATM so face and layer won't be used at the
 	/// [mip][depth or face or layer]. Loader doesn't support cube arrays ATM so face and layer won't be used at the
 	/// same time.
 	/// same time.
@@ -135,22 +136,22 @@ private:
 	void destroy();
 	void destroy();
 
 
 	static Error loadUncompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
 	static Error loadUncompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
-									 DynamicArray<U8, PtrSize>& data, GenericMemoryPoolAllocator<U8>& alloc);
+									 DynamicArray<U8, PtrSize>& data, BaseMemoryPool& pool);
 
 
 	static Error loadCompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
 	static Error loadCompressedTga(FileInterface& fs, U32& width, U32& height, U32& bpp,
-								   DynamicArray<U8, PtrSize>& data, GenericMemoryPoolAllocator<U8>& alloc);
+								   DynamicArray<U8, PtrSize>& data, BaseMemoryPool& pool);
 
 
 	static Error loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray<U8, PtrSize>& data,
 	static Error loadTga(FileInterface& fs, U32& width, U32& height, U32& bpp, DynamicArray<U8, PtrSize>& data,
-						 GenericMemoryPoolAllocator<U8>& alloc);
+						 BaseMemoryPool& pool);
 
 
 	static Error loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& height, DynamicArray<U8, PtrSize>& data,
 	static Error loadStb(Bool isFloat, FileInterface& fs, U32& width, U32& height, DynamicArray<U8, PtrSize>& data,
-						 GenericMemoryPoolAllocator<U8>& alloc);
+						 BaseMemoryPool& pool);
 
 
 	static Error loadAnkiImage(FileInterface& file, U32 maxImageSize, ImageBinaryDataCompression& preferredCompression,
 	static Error loadAnkiImage(FileInterface& file, U32 maxImageSize, ImageBinaryDataCompression& preferredCompression,
 							   DynamicArray<ImageLoaderSurface>& surfaces, DynamicArray<ImageLoaderVolume>& volumes,
 							   DynamicArray<ImageLoaderSurface>& surfaces, DynamicArray<ImageLoaderVolume>& volumes,
-							   GenericMemoryPoolAllocator<U8>& alloc, U32& width, U32& height, U32& depth,
-							   U32& layerCount, U32& mipCount, ImageBinaryType& imageType,
-							   ImageBinaryColorFormat& colorFormat, UVec2& astcBlockSize);
+							   BaseMemoryPool& pool, U32& width, U32& height, U32& depth, U32& layerCount,
+							   U32& mipCount, ImageBinaryType& imageType, ImageBinaryColorFormat& colorFormat,
+							   UVec2& astcBlockSize);
 
 
 	Error loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize);
 	Error loadInternal(FileInterface& file, const CString& filename, U32 maxImageSize);
 };
 };

+ 7 - 7
AnKi/Resource/ImageResource.cpp

@@ -23,8 +23,8 @@ public:
 	TextureType m_texType;
 	TextureType m_texType;
 	TexturePtr m_tex;
 	TexturePtr m_tex;
 
 
-	LoadingContext(GenericMemoryPoolAllocator<U8> alloc)
-		: m_loader(alloc)
+	LoadingContext(BaseMemoryPool* pool)
+		: m_loader(pool)
 	{
 	{
 	}
 	}
 };
 };
@@ -35,8 +35,8 @@ class ImageResource::TexUploadTask : public AsyncLoaderTask
 public:
 public:
 	ImageResource::LoadingContext m_ctx;
 	ImageResource::LoadingContext m_ctx;
 
 
-	TexUploadTask(GenericMemoryPoolAllocator<U8> alloc)
-		: m_ctx(alloc)
+	TexUploadTask(BaseMemoryPool* pool)
+		: m_ctx(pool)
 	{
 	{
 	}
 	}
 
 
@@ -54,11 +54,11 @@ Error ImageResource::load(const ResourceFilename& filename, Bool async)
 {
 {
 	TexUploadTask* task;
 	TexUploadTask* task;
 	LoadingContext* ctx;
 	LoadingContext* ctx;
-	LoadingContext localCtx(getTempAllocator());
+	LoadingContext localCtx(&getTempMemoryPool());
 
 
 	if(async)
 	if(async)
 	{
 	{
-		task = getManager().getAsyncLoader().newTask<TexUploadTask>(getManager().getAsyncLoader().getAllocator());
+		task = getManager().getAsyncLoader().newTask<TexUploadTask>(&getManager().getAsyncLoader().getMemoryPool());
 		ctx = &task->m_ctx;
 		ctx = &task->m_ctx;
 	}
 	}
 	else
 	else
@@ -68,7 +68,7 @@ Error ImageResource::load(const ResourceFilename& filename, Bool async)
 	}
 	}
 	ImageLoader& loader = ctx->m_loader;
 	ImageLoader& loader = ctx->m_loader;
 
 
-	StringRaii filenameExt(getTempAllocator());
+	StringRaii filenameExt(&getTempMemoryPool());
 	getFilepathFilename(filename, filenameExt);
 	getFilepathFilename(filename, filenameExt);
 
 
 	TextureInitInfo init(filenameExt);
 	TextureInitInfo init(filenameExt);

+ 44 - 44
AnKi/Resource/MaterialResource.cpp

@@ -10,10 +10,10 @@
 
 
 namespace anki {
 namespace anki {
 
 
-inline constexpr Array<CString, U32(BuiltinMutatorId::kCount)> BUILTIN_MUTATOR_NAMES = {
+inline constexpr Array<CString, U32(BuiltinMutatorId::kCount)> kBuiltinMutatorNames = {
 	{"NONE", "ANKI_TECHNIQUE", "ANKI_LOD", "ANKI_BONES", "ANKI_VELOCITY"}};
 	{"NONE", "ANKI_TECHNIQUE", "ANKI_LOD", "ANKI_BONES", "ANKI_VELOCITY"}};
 
 
-inline constexpr Array<CString, U(RenderingTechnique::kCount)> TECHNIQUE_NAMES = {
+inline constexpr Array<CString, U(RenderingTechnique::kCount)> kTechniqueNames = {
 	{"GBuffer", "GBufferEarlyZ", "Shadow", "Forward", "RtShadow"}};
 	{"GBuffer", "GBufferEarlyZ", "Shadow", "Forward", "RtShadow"}};
 
 
 // This is some trickery to select calling between XmlElement::getAttributeNumber and XmlElement::getAttributeNumbers
 // This is some trickery to select calling between XmlElement::getAttributeNumber and XmlElement::getAttributeNumbers
@@ -127,20 +127,20 @@ MaterialResource::~MaterialResource()
 {
 {
 	for(Program& p : m_programs)
 	for(Program& p : m_programs)
 	{
 	{
-		p.m_partialMutation.destroy(getAllocator());
+		p.m_partialMutation.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_textures.destroy(getAllocator());
+	m_textures.destroy(getMemoryPool());
 
 
 	for(MaterialVariable& var : m_vars)
 	for(MaterialVariable& var : m_vars)
 	{
 	{
-		var.m_name.destroy(getAllocator());
+		var.m_name.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_vars.destroy(getAllocator());
-	m_programs.destroy(getAllocator());
+	m_vars.destroy(getMemoryPool());
+	m_programs.destroy(getMemoryPool());
 
 
-	getAllocator().deallocate(m_prefilledLocalUniforms, 0);
+	getMemoryPool().free(m_prefilledLocalUniforms);
 }
 }
 
 
 const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name) const
 const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name) const
@@ -158,7 +158,7 @@ const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name)
 
 
 Error MaterialResource::load(const ResourceFilename& filename, Bool async)
 Error MaterialResource::load(const ResourceFilename& filename, Bool async)
 {
 {
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	XmlElement el;
 	XmlElement el;
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 
 
@@ -217,10 +217,10 @@ Error MaterialResource::parseShaderProgram(XmlElement shaderProgramEl, Bool asyn
 		return Error::kNone;
 		return Error::kNone;
 	}
 	}
 
 
-	StringRaii fname(getTempAllocator());
+	StringRaii fname(&getTempMemoryPool());
 	fname.sprintf("ShaderBinaries/%s.ankiprogbin", shaderName.cstr());
 	fname.sprintf("ShaderBinaries/%s.ankiprogbin", shaderName.cstr());
 
 
-	Program& prog = *m_programs.emplaceBack(getAllocator());
+	Program& prog = *m_programs.emplaceBack(getMemoryPool());
 	ANKI_CHECK(getManager().loadResource(fname, prog.m_prog, async));
 	ANKI_CHECK(getManager().loadResource(fname, prog.m_prog, async));
 
 
 	// <mutation>
 	// <mutation>
@@ -336,8 +336,8 @@ Error MaterialResource::createVars(Program& prog)
 				}
 				}
 
 
 				// All good, add it
 				// All good, add it
-				var = m_vars.emplaceBack(getAllocator());
-				var->m_name.create(getAllocator(), memberName);
+				var = m_vars.emplaceBack(getMemoryPool());
+				var->m_name.create(getMemoryPool(), memberName);
 				var->m_offsetInLocalUniforms = offsetof;
 				var->m_offsetInLocalUniforms = offsetof;
 				var->m_dataType = member.m_type;
 				var->m_dataType = member.m_type;
 
 
@@ -359,7 +359,7 @@ Error MaterialResource::createVars(Program& prog)
 	Array<const ShaderProgramResourceMutator*, U(BuiltinMutatorId::kCount)> mutatorPtrs = {};
 	Array<const ShaderProgramResourceMutator*, U(BuiltinMutatorId::kCount)> mutatorPtrs = {};
 	for(BuiltinMutatorId id : EnumIterable<BuiltinMutatorId>())
 	for(BuiltinMutatorId id : EnumIterable<BuiltinMutatorId>())
 	{
 	{
-		mutatorPtrs[id] = prog.m_prog->tryFindMutator(BUILTIN_MUTATOR_NAMES[id]);
+		mutatorPtrs[id] = prog.m_prog->tryFindMutator(kBuiltinMutatorNames[id]);
 	}
 	}
 
 
 #define ANKI_LOOP(builtIn) \
 #define ANKI_LOOP(builtIn) \
@@ -376,10 +376,10 @@ Error MaterialResource::createVars(Program& prog)
 
 
 #define ANKI_LOOP_END() }
 #define ANKI_LOOP_END() }
 
 
-	ANKI_LOOP(TECHNIQUE)
-	ANKI_LOOP(LOD)
-	ANKI_LOOP(BONES)
-	ANKI_LOOP(VELOCITY)
+	ANKI_LOOP(kTechnique)
+	ANKI_LOOP(kLod)
+	ANKI_LOOP(kBones)
+	ANKI_LOOP(kVelocity)
 	{
 	{
 		const ShaderProgramResourceVariant* variant;
 		const ShaderProgramResourceVariant* variant;
 		prog.m_prog->getOrCreateVariant(initInfo, variant);
 		prog.m_prog->getOrCreateVariant(initInfo, variant);
@@ -428,8 +428,8 @@ Error MaterialResource::createVars(Program& prog)
 				}
 				}
 
 
 				// All good, add it
 				// All good, add it
-				var = m_vars.emplaceBack(getAllocator());
-				var->m_name.create(getAllocator(), opaqueName);
+				var = m_vars.emplaceBack(getMemoryPool());
+				var->m_name.create(getMemoryPool(), opaqueName);
 				var->m_opaqueBinding = opaque.m_binding;
 				var->m_opaqueBinding = opaque.m_binding;
 				var->m_dataType = opaque.m_type;
 				var->m_dataType = opaque.m_type;
 			}
 			}
@@ -455,7 +455,7 @@ Error MaterialResource::parseMutators(XmlElement mutatorsEl, Program& prog)
 	ANKI_CHECK(mutatorEl.getSiblingElementsCount(mutatorCount));
 	ANKI_CHECK(mutatorEl.getSiblingElementsCount(mutatorCount));
 	++mutatorCount;
 	++mutatorCount;
 	ANKI_ASSERT(mutatorCount > 0);
 	ANKI_ASSERT(mutatorCount > 0);
-	prog.m_partialMutation.create(getAllocator(), mutatorCount);
+	prog.m_partialMutation.create(getMemoryPool(), mutatorCount);
 	mutatorCount = 0;
 	mutatorCount = 0;
 
 
 	do
 	do
@@ -473,12 +473,12 @@ Error MaterialResource::parseMutators(XmlElement mutatorsEl, Program& prog)
 
 
 		for(BuiltinMutatorId id : EnumIterable<BuiltinMutatorId>())
 		for(BuiltinMutatorId id : EnumIterable<BuiltinMutatorId>())
 		{
 		{
-			if(id == BuiltinMutatorId::NONE)
+			if(id == BuiltinMutatorId::kNone)
 			{
 			{
 				continue;
 				continue;
 			}
 			}
 
 
-			if(mutatorName == BUILTIN_MUTATOR_NAMES[id])
+			if(mutatorName == kBuiltinMutatorNames[id])
 			{
 			{
 				ANKI_RESOURCE_LOGE("Materials shouldn't list builtin mutators: %s", mutatorName.cstr());
 				ANKI_RESOURCE_LOGE("Materials shouldn't list builtin mutators: %s", mutatorName.cstr());
 				return Error::kUserData;
 				return Error::kUserData;
@@ -524,7 +524,7 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 	U builtinMutatorCount = 0;
 	U builtinMutatorCount = 0;
 
 
 	// ANKI_TECHNIQUE
 	// ANKI_TECHNIQUE
-	CString techniqueMutatorName = BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::TECHNIQUE];
+	CString techniqueMutatorName = kBuiltinMutatorNames[BuiltinMutatorId::kTechnique];
 	const ShaderProgramResourceMutator* techniqueMutator = prog.m_prog->tryFindMutator(techniqueMutatorName);
 	const ShaderProgramResourceMutator* techniqueMutator = prog.m_prog->tryFindMutator(techniqueMutatorName);
 	if(techniqueMutator)
 	if(techniqueMutator)
 	{
 	{
@@ -545,14 +545,14 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 			const RenderingTechniqueBit mask = RenderingTechniqueBit(1 << techniqueId);
 			const RenderingTechniqueBit mask = RenderingTechniqueBit(1 << techniqueId);
 			if(!!(m_techniquesMask & mask))
 			if(!!(m_techniquesMask & mask))
 			{
 			{
-				ANKI_RESOURCE_LOGE("The %s technique appeared more than once", TECHNIQUE_NAMES[mvalue].cstr());
+				ANKI_RESOURCE_LOGE("The %s technique appeared more than once", kTechniqueNames[mvalue].cstr());
 				return Error::kUserData;
 				return Error::kUserData;
 			}
 			}
 			m_techniquesMask |= mask;
 			m_techniquesMask |= mask;
 		}
 		}
 
 
 		++builtinMutatorCount;
 		++builtinMutatorCount;
-		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::TECHNIQUE);
+		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kTechnique);
 	}
 	}
 	else
 	else
 	{
 	{
@@ -562,7 +562,7 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 	}
 	}
 
 
 	// ANKI_LOD
 	// ANKI_LOD
-	CString lodMutatorName = BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::LOD];
+	CString lodMutatorName = kBuiltinMutatorNames[BuiltinMutatorId::kLod];
 	const ShaderProgramResourceMutator* lodMutator = prog.m_prog->tryFindMutator(lodMutatorName);
 	const ShaderProgramResourceMutator* lodMutator = prog.m_prog->tryFindMutator(lodMutatorName);
 	if(lodMutator)
 	if(lodMutator)
 	{
 	{
@@ -585,11 +585,11 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 
 
 		prog.m_lodCount = U8(lodMutator->m_values.getSize());
 		prog.m_lodCount = U8(lodMutator->m_values.getSize());
 		++builtinMutatorCount;
 		++builtinMutatorCount;
-		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::LOD);
+		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kLod);
 	}
 	}
 
 
 	// ANKI_BONES
 	// ANKI_BONES
-	CString bonesMutatorName = BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::BONES];
+	CString bonesMutatorName = kBuiltinMutatorNames[BuiltinMutatorId::kBones];
 	const ShaderProgramResourceMutator* bonesMutator = prog.m_prog->tryFindMutator(bonesMutatorName);
 	const ShaderProgramResourceMutator* bonesMutator = prog.m_prog->tryFindMutator(bonesMutatorName);
 	if(bonesMutator)
 	if(bonesMutator)
 	{
 	{
@@ -633,11 +633,11 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 		}
 		}
 
 
 		m_supportsSkinning = true;
 		m_supportsSkinning = true;
-		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::BONES);
+		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kBones);
 	}
 	}
 
 
 	// VELOCITY
 	// VELOCITY
-	CString velocityMutatorName = BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::VELOCITY];
+	CString velocityMutatorName = kBuiltinMutatorNames[BuiltinMutatorId::kVelocity];
 	const ShaderProgramResourceMutator* velocityMutator = prog.m_prog->tryFindMutator(velocityMutatorName);
 	const ShaderProgramResourceMutator* velocityMutator = prog.m_prog->tryFindMutator(velocityMutatorName);
 	if(velocityMutator)
 	if(velocityMutator)
 	{
 	{
@@ -658,7 +658,7 @@ Error MaterialResource::findBuiltinMutators(Program& prog)
 		}
 		}
 
 
 		++builtinMutatorCount;
 		++builtinMutatorCount;
-		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::VELOCITY);
+		prog.m_presentBuildinMutators |= U32(1 << BuiltinMutatorId::kVelocity);
 	}
 	}
 
 
 	if(prog.m_partialMutation.getSize() + builtinMutatorCount != prog.m_prog->getMutators().getSize())
 	if(prog.m_partialMutation.getSize() + builtinMutatorCount != prog.m_prog->getMutators().getSize())
@@ -700,7 +700,7 @@ Error MaterialResource::parseInput(XmlElement inputEl, Bool async, BitSet<128>&
 		ANKI_CHECK(inputEl.getAttributeText("value", texfname));
 		ANKI_CHECK(inputEl.getAttributeText("value", texfname));
 		ANKI_CHECK(getManager().loadResource(texfname, foundVar->m_image, async));
 		ANKI_CHECK(getManager().loadResource(texfname, foundVar->m_image, async));
 
 
-		m_textures.emplaceBack(getAllocator(), foundVar->m_image->getTexture());
+		m_textures.emplaceBack(getMemoryPool(), foundVar->m_image->getTexture());
 	}
 	}
 	else if(foundVar->m_dataType == ShaderVariableDataType::kU32)
 	else if(foundVar->m_dataType == ShaderVariableDataType::kU32)
 	{
 	{
@@ -758,7 +758,7 @@ void MaterialResource::prefillLocalUniforms()
 		return;
 		return;
 	}
 	}
 
 
-	m_prefilledLocalUniforms = getAllocator().allocate(m_localUniformsSize, 1);
+	m_prefilledLocalUniforms = getMemoryPool().allocate(m_localUniformsSize, 1);
 	memset(m_prefilledLocalUniforms, 0, m_localUniformsSize);
 	memset(m_prefilledLocalUniforms, 0, m_localUniformsSize);
 
 
 	for(const MaterialVariable& var : m_vars)
 	for(const MaterialVariable& var : m_vars)
@@ -799,14 +799,14 @@ const MaterialVariant& MaterialResource::getOrCreateVariant(const RenderingKey&
 		key.setLod(0);
 		key.setLod(0);
 	}
 	}
 
 
-	if(!(prog.m_presentBuildinMutators & U32(BuiltinMutatorId::VELOCITY)) && key.getVelocity())
+	if(!(prog.m_presentBuildinMutators & U32(BuiltinMutatorId::kVelocity)) && key.getVelocity())
 	{
 	{
 		// Particles set their own velocity
 		// Particles set their own velocity
 		key.setVelocity(false);
 		key.setVelocity(false);
 	}
 	}
 
 
-	ANKI_ASSERT(!key.getSkinned() || !!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::BONES)));
-	ANKI_ASSERT(!key.getVelocity() || !!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::VELOCITY)));
+	ANKI_ASSERT(!key.getSkinned() || !!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::kBones)));
+	ANKI_ASSERT(!key.getVelocity() || !!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::kVelocity)));
 
 
 	MaterialVariant& variant =
 	MaterialVariant& variant =
 		prog.m_variantMatrix[key.getRenderingTechnique()][key.getLod()][key.getSkinned()][key.getVelocity()];
 		prog.m_variantMatrix[key.getRenderingTechnique()][key.getLod()][key.getSkinned()][key.getVelocity()];
@@ -836,21 +836,21 @@ const MaterialVariant& MaterialResource::getOrCreateVariant(const RenderingKey&
 		initInfo.addMutation(m.m_mutator->m_name, m.m_value);
 		initInfo.addMutation(m.m_mutator->m_name, m.m_value);
 	}
 	}
 
 
-	initInfo.addMutation(BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::TECHNIQUE], MutatorValue(key.getRenderingTechnique()));
+	initInfo.addMutation(kBuiltinMutatorNames[BuiltinMutatorId::kTechnique], MutatorValue(key.getRenderingTechnique()));
 
 
-	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::LOD)))
+	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::kLod)))
 	{
 	{
-		initInfo.addMutation(BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::LOD], MutatorValue(key.getLod()));
+		initInfo.addMutation(kBuiltinMutatorNames[BuiltinMutatorId::kLod], MutatorValue(key.getLod()));
 	}
 	}
 
 
-	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::BONES)))
+	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::kBones)))
 	{
 	{
-		initInfo.addMutation(BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::BONES], MutatorValue(key.getSkinned()));
+		initInfo.addMutation(kBuiltinMutatorNames[BuiltinMutatorId::kBones], MutatorValue(key.getSkinned()));
 	}
 	}
 
 
-	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::VELOCITY)))
+	if(!!(prog.m_presentBuildinMutators & U32(1 << BuiltinMutatorId::kVelocity)))
 	{
 	{
-		initInfo.addMutation(BUILTIN_MUTATOR_NAMES[BuiltinMutatorId::VELOCITY], MutatorValue(key.getVelocity()));
+		initInfo.addMutation(kBuiltinMutatorNames[BuiltinMutatorId::kVelocity], MutatorValue(key.getVelocity()));
 	}
 	}
 
 
 	const ShaderProgramResourceVariant* progVariant;
 	const ShaderProgramResourceVariant* progVariant;

+ 5 - 5
AnKi/Resource/MaterialResource.h

@@ -24,11 +24,11 @@ class XmlElement;
 /// The ID of builtin mutators.
 /// The ID of builtin mutators.
 enum class BuiltinMutatorId : U8
 enum class BuiltinMutatorId : U8
 {
 {
-	NONE = 0,
-	TECHNIQUE,
-	LOD,
-	BONES,
-	VELOCITY,
+	kNone = 0,
+	kTechnique,
+	kLod,
+	kBones,
+	kVelocity,
 
 
 	kCount,
 	kCount,
 	kFirst = 0
 	kFirst = 0

+ 5 - 5
AnKi/Resource/MeshBinaryLoader.cpp

@@ -9,18 +9,18 @@
 namespace anki {
 namespace anki {
 
 
 MeshBinaryLoader::MeshBinaryLoader(ResourceManager* manager)
 MeshBinaryLoader::MeshBinaryLoader(ResourceManager* manager)
-	: MeshBinaryLoader(manager, manager->getTempAllocator())
+	: MeshBinaryLoader(manager, &manager->getTempMemoryPool())
 {
 {
 }
 }
 
 
 MeshBinaryLoader::~MeshBinaryLoader()
 MeshBinaryLoader::~MeshBinaryLoader()
 {
 {
-	m_subMeshes.destroy(m_alloc);
+	m_subMeshes.destroy(*m_pool);
 }
 }
 
 
 Error MeshBinaryLoader::load(const ResourceFilename& filename)
 Error MeshBinaryLoader::load(const ResourceFilename& filename)
 {
 {
-	auto& alloc = m_alloc;
+	BaseMemoryPool& pool = *m_pool;
 
 
 	// Load header
 	// Load header
 	ANKI_CHECK(m_manager->getFilesystem().openFile(filename, m_file));
 	ANKI_CHECK(m_manager->getFilesystem().openFile(filename, m_file));
@@ -29,7 +29,7 @@ Error MeshBinaryLoader::load(const ResourceFilename& filename)
 
 
 	// Read submesh info
 	// Read submesh info
 	{
 	{
-		m_subMeshes.create(alloc, m_header.m_subMeshCount);
+		m_subMeshes.create(pool, m_header.m_subMeshCount);
 		ANKI_CHECK(m_file->read(&m_subMeshes[0], m_subMeshes.getSizeInBytes()));
 		ANKI_CHECK(m_file->read(&m_subMeshes[0], m_subMeshes.getSizeInBytes()));
 
 
 		// Checks
 		// Checks
@@ -261,7 +261,7 @@ Error MeshBinaryLoader::storeIndicesAndPosition(DynamicArrayRaii<U32>& indices,
 		indices.resize(m_header.m_totalIndexCount);
 		indices.resize(m_header.m_totalIndexCount);
 
 
 		// Store to staging buff
 		// Store to staging buff
-		DynamicArrayRaii<U8, PtrSize> staging(m_alloc);
+		DynamicArrayRaii<U8, PtrSize> staging(m_pool);
 		staging.create(getIndexBufferSize());
 		staging.create(getIndexBufferSize());
 		ANKI_CHECK(storeIndexBuffer(&staging[0], staging.getSizeInBytes()));
 		ANKI_CHECK(storeIndexBuffer(&staging[0], staging.getSizeInBytes()));
 
 

+ 5 - 4
AnKi/Resource/MeshBinaryLoader.h

@@ -21,10 +21,11 @@ class MeshBinaryLoader
 public:
 public:
 	MeshBinaryLoader(ResourceManager* manager);
 	MeshBinaryLoader(ResourceManager* manager);
 
 
-	MeshBinaryLoader(ResourceManager* manager, GenericMemoryPoolAllocator<U8> alloc)
+	MeshBinaryLoader(ResourceManager* manager, BaseMemoryPool* pool)
 		: m_manager(manager)
 		: m_manager(manager)
-		, m_alloc(alloc)
+		, m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(manager && pool);
 	}
 	}
 
 
 	~MeshBinaryLoader();
 	~MeshBinaryLoader();
@@ -56,8 +57,8 @@ public:
 	}
 	}
 
 
 private:
 private:
-	ResourceManager* m_manager;
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	ResourceManager* m_manager = nullptr;
+	BaseMemoryPool* m_pool = nullptr;
 	ResourceFilePtr m_file;
 	ResourceFilePtr m_file;
 
 
 	MeshBinaryHeader m_header;
 	MeshBinaryHeader m_header;

+ 12 - 12
AnKi/Resource/MeshResource.cpp

@@ -19,9 +19,9 @@ public:
 	MeshResourcePtr m_mesh;
 	MeshResourcePtr m_mesh;
 	MeshBinaryLoader m_loader;
 	MeshBinaryLoader m_loader;
 
 
-	LoadContext(const MeshResourcePtr& mesh, GenericMemoryPoolAllocator<U8> alloc)
+	LoadContext(const MeshResourcePtr& mesh, BaseMemoryPool* pool)
 		: m_mesh(mesh)
 		: m_mesh(mesh)
-		, m_loader(&mesh->getManager(), alloc)
+		, m_loader(&mesh->getManager(), pool)
 	{
 	{
 	}
 	}
 };
 };
@@ -33,7 +33,7 @@ public:
 	MeshResource::LoadContext m_ctx;
 	MeshResource::LoadContext m_ctx;
 
 
 	LoadTask(const MeshResourcePtr& mesh)
 	LoadTask(const MeshResourcePtr& mesh)
-		: m_ctx(mesh, mesh->getManager().getAsyncLoader().getAllocator())
+		: m_ctx(mesh, &mesh->getManager().getAsyncLoader().getMemoryPool())
 	{
 	{
 	}
 	}
 
 
@@ -42,9 +42,9 @@ public:
 		return m_ctx.m_mesh->loadAsync(m_ctx.m_loader);
 		return m_ctx.m_mesh->loadAsync(m_ctx.m_loader);
 	}
 	}
 
 
-	GenericMemoryPoolAllocator<U8> getAllocator() const
+	BaseMemoryPool& getMemoryPool() const
 	{
 	{
-		return m_ctx.m_mesh->getManager().getAsyncLoader().getAllocator();
+		return m_ctx.m_mesh->getManager().getAsyncLoader().getMemoryPool();
 	}
 	}
 };
 };
 
 
@@ -56,8 +56,8 @@ MeshResource::MeshResource(ResourceManager* manager)
 
 
 MeshResource::~MeshResource()
 MeshResource::~MeshResource()
 {
 {
-	m_subMeshes.destroy(getAllocator());
-	m_vertexBufferInfos.destroy(getAllocator());
+	m_subMeshes.destroy(getMemoryPool());
+	m_vertexBufferInfos.destroy(getMemoryPool());
 
 
 	if(m_vertexBuffersOffset != kMaxPtrSize)
 	if(m_vertexBuffersOffset != kMaxPtrSize)
 	{
 	{
@@ -80,9 +80,9 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 {
 {
 	UniquePtr<LoadTask> task;
 	UniquePtr<LoadTask> task;
 	LoadContext* ctx;
 	LoadContext* ctx;
-	LoadContext localCtx(MeshResourcePtr(this), getTempAllocator());
+	LoadContext localCtx(MeshResourcePtr(this), &getTempMemoryPool());
 
 
-	StringRaii basename(getTempAllocator());
+	StringRaii basename(&getTempMemoryPool());
 	getFilepathFilename(filename, basename);
 	getFilepathFilename(filename, basename);
 
 
 	const Bool rayTracingEnabled = getManager().getGrManager().getDeviceCapabilities().m_rayTracingEnabled;
 	const Bool rayTracingEnabled = getManager().getGrManager().getDeviceCapabilities().m_rayTracingEnabled;
@@ -106,7 +106,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 	//
 	//
 	// Submeshes
 	// Submeshes
 	//
 	//
-	m_subMeshes.create(getAllocator(), header.m_subMeshCount);
+	m_subMeshes.create(getMemoryPool(), header.m_subMeshCount);
 	for(U32 i = 0; i < m_subMeshes.getSize(); ++i)
 	for(U32 i = 0; i < m_subMeshes.getSize(); ++i)
 	{
 	{
 		m_subMeshes[i].m_firstIndex = loader.getSubMeshes()[i].m_firstIndex;
 		m_subMeshes[i].m_firstIndex = loader.getSubMeshes()[i].m_firstIndex;
@@ -129,7 +129,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 	// Vertex stuff
 	// Vertex stuff
 	//
 	//
 	m_vertexCount = header.m_totalVertexCount;
 	m_vertexCount = header.m_totalVertexCount;
-	m_vertexBufferInfos.create(getAllocator(), header.m_vertexBufferCount);
+	m_vertexBufferInfos.create(getMemoryPool(), header.m_vertexBufferCount);
 
 
 	m_vertexBuffersSize = 0;
 	m_vertexBuffersSize = 0;
 	for(U32 i = 0; i < header.m_vertexBufferCount; ++i)
 	for(U32 i = 0; i < header.m_vertexBufferCount; ++i)
@@ -194,7 +194,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 	//
 	//
 	if(rayTracingEnabled)
 	if(rayTracingEnabled)
 	{
 	{
-		AccelerationStructureInitInfo inf(StringRaii(getTempAllocator()).sprintf("%s_%s", "Blas", basename.cstr()));
+		AccelerationStructureInitInfo inf(StringRaii(&getTempMemoryPool()).sprintf("%s_%s", "Blas", basename.cstr()));
 		inf.m_type = AccelerationStructureType::kBottomLevel;
 		inf.m_type = AccelerationStructureType::kBottomLevel;
 
 
 		inf.m_bottomLevel.m_indexBuffer = m_vertexBuffer;
 		inf.m_bottomLevel.m_indexBuffer = m_vertexBuffer;

+ 7 - 9
AnKi/Resource/ModelResource.cpp

@@ -123,11 +123,11 @@ Error ModelPatch::init(ModelResource* model, ConstWeakArray<CString> meshFNames,
 	// Gather the material refs
 	// Gather the material refs
 	if(m_mtl->getAllTextures().getSize())
 	if(m_mtl->getAllTextures().getSize())
 	{
 	{
-		m_grObjectRefs.resizeStorage(model->getAllocator(), m_mtl->getAllTextures().getSize());
+		m_grObjectRefs.resizeStorage(model->getMemoryPool(), m_mtl->getAllTextures().getSize());
 
 
 		for(U32 i = 0; i < m_mtl->getAllTextures().getSize(); ++i)
 		for(U32 i = 0; i < m_mtl->getAllTextures().getSize(); ++i)
 		{
 		{
-			m_grObjectRefs.emplaceBack(model->getAllocator(), m_mtl->getAllTextures()[i]);
+			m_grObjectRefs.emplaceBack(model->getMemoryPool(), m_mtl->getAllTextures()[i]);
 		}
 		}
 	}
 	}
 
 
@@ -243,24 +243,22 @@ ModelResource::ModelResource(ResourceManager* manager)
 
 
 ModelResource::~ModelResource()
 ModelResource::~ModelResource()
 {
 {
-	auto alloc = getAllocator();
-
 	for(ModelPatch& patch : m_modelPatches)
 	for(ModelPatch& patch : m_modelPatches)
 	{
 	{
-		patch.m_grObjectRefs.destroy(alloc);
+		patch.m_grObjectRefs.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_modelPatches.destroy(alloc);
+	m_modelPatches.destroy(getMemoryPool());
 }
 }
 
 
 Error ModelResource::load(const ResourceFilename& filename, Bool async)
 Error ModelResource::load(const ResourceFilename& filename, Bool async)
 {
 {
-	auto alloc = getAllocator();
+	HeapMemoryPool& pool = getMemoryPool();
 
 
 	// Load
 	// Load
 	//
 	//
 	XmlElement el;
 	XmlElement el;
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 
 
 	XmlElement rootEl;
 	XmlElement rootEl;
@@ -289,7 +287,7 @@ Error ModelResource::load(const ResourceFilename& filename, Bool async)
 		return Error::kUserData;
 		return Error::kUserData;
 	}
 	}
 
 
-	m_modelPatches.create(alloc, count);
+	m_modelPatches.create(pool, count);
 
 
 	count = 0;
 	count = 0;
 	ANKI_CHECK(modelPatchesEl.getChildElement("modelPatch", modelPatchEl));
 	ANKI_CHECK(modelPatchesEl.getChildElement("modelPatch", modelPatchEl));

+ 1 - 1
AnKi/Resource/ParticleEmitterResource.cpp

@@ -35,7 +35,7 @@ ParticleEmitterResource::~ParticleEmitterResource()
 
 
 Error ParticleEmitterResource::load(const ResourceFilename& filename, Bool async)
 Error ParticleEmitterResource::load(const ResourceFilename& filename, Bool async)
 {
 {
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	XmlElement rootEl; // Root element
 	XmlElement rootEl; // Root element
 	ANKI_CHECK(doc.getChildElement("particleEmitter", rootEl));
 	ANKI_CHECK(doc.getChildElement("particleEmitter", rootEl));

+ 24 - 24
AnKi/Resource/ResourceFilesystem.cpp

@@ -20,8 +20,8 @@ class CResourceFile final : public ResourceFile
 public:
 public:
 	File m_file;
 	File m_file;
 
 
-	CResourceFile(GenericMemoryPoolAllocator<U8> alloc)
-		: ResourceFile(alloc)
+	CResourceFile(HeapMemoryPool* pool)
+		: ResourceFile(pool)
 	{
 	{
 	}
 	}
 
 
@@ -67,8 +67,8 @@ public:
 	unzFile m_archive = nullptr;
 	unzFile m_archive = nullptr;
 	PtrSize m_size = 0;
 	PtrSize m_size = 0;
 
 
-	ZipResourceFile(GenericMemoryPoolAllocator<U8> alloc)
-		: ResourceFile(alloc)
+	ZipResourceFile(HeapMemoryPool* pool)
+		: ResourceFile(pool)
 	{
 	{
 	}
 	}
 
 
@@ -199,30 +199,30 @@ ResourceFilesystem::~ResourceFilesystem()
 {
 {
 	for(Path& p : m_paths)
 	for(Path& p : m_paths)
 	{
 	{
-		p.m_files.destroy(m_alloc);
-		p.m_path.destroy(m_alloc);
+		p.m_files.destroy(*m_pool);
+		p.m_path.destroy(*m_pool);
 	}
 	}
 
 
-	m_paths.destroy(m_alloc);
-	m_cacheDir.destroy(m_alloc);
+	m_paths.destroy(*m_pool);
+	m_cacheDir.destroy(*m_pool);
 }
 }
 
 
 Error ResourceFilesystem::init(const ConfigSet& config)
 Error ResourceFilesystem::init(const ConfigSet& config)
 {
 {
-	StringListAuto paths(m_alloc);
+	StringListRaii paths(m_pool);
 	paths.splitString(config.getRsrcDataPaths(), ':');
 	paths.splitString(config.getRsrcDataPaths(), ':');
 
 
-	StringListAuto excludedStrings(m_alloc);
+	StringListRaii excludedStrings(m_pool);
 	excludedStrings.splitString(config.getRsrcDataPathExcludedStrings(), ':');
 	excludedStrings.splitString(config.getRsrcDataPathExcludedStrings(), ':');
 
 
 	// Workaround the fact that : is used in drives in Windows
 	// Workaround the fact that : is used in drives in Windows
 #if ANKI_OS_WINDOWS
 #if ANKI_OS_WINDOWS
-	StringListAuto paths2(m_alloc);
-	StringListAuto::Iterator it = paths.getBegin();
+	StringListRaii paths2(m_pool);
+	StringListRaii::Iterator it = paths.getBegin();
 	while(it != paths.getEnd())
 	while(it != paths.getEnd())
 	{
 	{
 		const String& s = *it;
 		const String& s = *it;
-		StringListAuto::Iterator it2 = it + 1;
+		StringListRaii::Iterator it2 = it + 1;
 		if(s.getLength() == 1 && (s[0] >= 'a' && s[0] <= 'z') || (s[0] >= 'A' && s[0] <= 'Z') && it2 != paths.getEnd())
 		if(s.getLength() == 1 && (s[0] >= 'a' && s[0] <= 'z') || (s[0] >= 'A' && s[0] <= 'Z') && it2 != paths.getEnd())
 		{
 		{
 			paths2.pushBackSprintf("%s:%s", s.cstr(), it2->cstr());
 			paths2.pushBackSprintf("%s:%s", s.cstr(), it2->cstr());
@@ -259,7 +259,7 @@ Error ResourceFilesystem::init(const ConfigSet& config)
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
-Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListAuto& excludedStrings)
+Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListRaii& excludedStrings)
 {
 {
 	ANKI_RESOURCE_LOGV("Adding new resource path: %s", filepath.cstr());
 	ANKI_RESOURCE_LOGV("Adding new resource path: %s", filepath.cstr());
 
 
@@ -315,7 +315,7 @@ Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListAu
 			const Bool itsADir = info.uncompressed_size == 0;
 			const Bool itsADir = info.uncompressed_size == 0;
 			if(!itsADir && !rejectPath(&filename[0]))
 			if(!itsADir && !rejectPath(&filename[0]))
 			{
 			{
-				path.m_files.pushBackSprintf(m_alloc, "%s", &filename[0]);
+				path.m_files.pushBackSprintf(*m_pool, "%s", &filename[0]);
 				++fileCount;
 				++fileCount;
 			}
 			}
 		} while(unzGoToNextFile(zfile) == UNZ_OK);
 		} while(unzGoToNextFile(zfile) == UNZ_OK);
@@ -328,10 +328,10 @@ Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListAu
 	{
 	{
 		// It's simple directory
 		// It's simple directory
 
 
-		ANKI_CHECK(walkDirectoryTree(filepath, m_alloc, [&, this](const CString& fname, Bool isDir) -> Error {
+		ANKI_CHECK(walkDirectoryTree(filepath, *m_pool, [&, this](const CString& fname, Bool isDir) -> Error {
 			if(!isDir && !rejectPath(fname))
 			if(!isDir && !rejectPath(fname))
 			{
 			{
-				path.m_files.pushBackSprintf(m_alloc, "%s", fname.cstr());
+				path.m_files.pushBackSprintf(*m_pool, "%s", fname.cstr());
 				++fileCount;
 				++fileCount;
 			}
 			}
 
 
@@ -346,8 +346,8 @@ Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListAu
 	}
 	}
 	else
 	else
 	{
 	{
-		path.m_path.sprintf(m_alloc, "%s", &filepath[0]);
-		m_paths.emplaceFront(m_alloc, std::move(path));
+		path.m_path.sprintf(*m_pool, "%s", &filepath[0]);
+		m_paths.emplaceFront(*m_pool, std::move(path));
 
 
 		ANKI_RESOURCE_LOGI("Added new data path \"%s\" that contains %u files", &filepath[0], fileCount);
 		ANKI_RESOURCE_LOGI("Added new data path \"%s\" that contains %u files", &filepath[0], fileCount);
 	}
 	}
@@ -371,7 +371,7 @@ Error ResourceFilesystem::openFile(const ResourceFilename& filename, ResourceFil
 	if(err)
 	if(err)
 	{
 	{
 		ANKI_RESOURCE_LOGE("Resource file not found: %s", filename.cstr());
 		ANKI_RESOURCE_LOGE("Resource file not found: %s", filename.cstr());
-		m_alloc.deleteInstance(rfile);
+		deleteInstance(*m_pool, rfile);
 	}
 	}
 	else
 	else
 	{
 	{
@@ -399,17 +399,17 @@ Error ResourceFilesystem::openFileInternal(const ResourceFilename& filename, Res
 			// Found
 			// Found
 			if(p.m_isArchive)
 			if(p.m_isArchive)
 			{
 			{
-				ZipResourceFile* file = m_alloc.newInstance<ZipResourceFile>(m_alloc);
+				ZipResourceFile* file = newInstance<ZipResourceFile>(*m_pool, m_pool);
 				rfile = file;
 				rfile = file;
 
 
 				ANKI_CHECK(file->open(p.m_path.toCString(), filename));
 				ANKI_CHECK(file->open(p.m_path.toCString(), filename));
 			}
 			}
 			else
 			else
 			{
 			{
-				StringRaii newFname(m_alloc);
+				StringRaii newFname(m_pool);
 				newFname.sprintf("%s/%s", &p.m_path[0], &filename[0]);
 				newFname.sprintf("%s/%s", &p.m_path[0], &filename[0]);
 
 
-				CResourceFile* file = m_alloc.newInstance<CResourceFile>(m_alloc);
+				CResourceFile* file = newInstance<CResourceFile>(*m_pool, m_pool);
 				rfile = file;
 				rfile = file;
 				ANKI_CHECK(file->m_file.open(newFname, FileOpenFlag::kRead));
 				ANKI_CHECK(file->m_file.open(newFname, FileOpenFlag::kRead));
 
 
@@ -428,7 +428,7 @@ Error ResourceFilesystem::openFileInternal(const ResourceFilename& filename, Res
 	// File not found? On Win/Linux try to find it outside the resource dirs. On Android try the archive
 	// File not found? On Win/Linux try to find it outside the resource dirs. On Android try the archive
 	if(!rfile)
 	if(!rfile)
 	{
 	{
-		CResourceFile* file = m_alloc.newInstance<CResourceFile>(m_alloc);
+		CResourceFile* file = newInstance<CResourceFile>(*m_pool, m_pool);
 		rfile = file;
 		rfile = file;
 
 
 		FileOpenFlag openFlags = FileOpenFlag::kRead;
 		FileOpenFlag openFlags = FileOpenFlag::kRead;

+ 10 - 8
AnKi/Resource/ResourceFilesystem.h

@@ -23,9 +23,10 @@ class ConfigSet;
 class ResourceFile
 class ResourceFile
 {
 {
 public:
 public:
-	ResourceFile(GenericMemoryPoolAllocator<U8> alloc)
-		: m_alloc(alloc)
+	ResourceFile(HeapMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(pool);
 	}
 	}
 
 
 	ResourceFile(const ResourceFile&) = delete; // Non-copyable
 	ResourceFile(const ResourceFile&) = delete; // Non-copyable
@@ -66,13 +67,13 @@ public:
 		return m_refcount.fetchSub(1);
 		return m_refcount.fetchSub(1);
 	}
 	}
 
 
-	GenericMemoryPoolAllocator<U8> getAllocator() const
+	HeapMemoryPool& getMemoryPool() const
 	{
 	{
-		return m_alloc;
+		return *m_pool;
 	}
 	}
 
 
 private:
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	mutable HeapMemoryPool* m_pool = nullptr;
 	mutable Atomic<I32> m_refcount = {0};
 	mutable Atomic<I32> m_refcount = {0};
 };
 };
 
 
@@ -83,9 +84,10 @@ using ResourceFilePtr = IntrusivePtr<ResourceFile>;
 class ResourceFilesystem
 class ResourceFilesystem
 {
 {
 public:
 public:
-	ResourceFilesystem(GenericMemoryPoolAllocator<U8> alloc)
-		: m_alloc(alloc)
+	ResourceFilesystem(HeapMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(pool);
 	}
 	}
 
 
 	ResourceFilesystem(const ResourceFilesystem&) = delete; // Non-copyable
 	ResourceFilesystem(const ResourceFilesystem&) = delete; // Non-copyable
@@ -143,7 +145,7 @@ private:
 		}
 		}
 	};
 	};
 
 
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	List<Path> m_paths;
 	List<Path> m_paths;
 	String m_cacheDir;
 	String m_cacheDir;
 
 

+ 18 - 18
AnKi/Resource/ResourceManager.cpp

@@ -33,9 +33,9 @@ ResourceManager::~ResourceManager()
 {
 {
 	ANKI_RESOURCE_LOGI("Destroying resource manager");
 	ANKI_RESOURCE_LOGI("Destroying resource manager");
 
 
-	m_alloc.deleteInstance(m_asyncLoader);
-	m_alloc.deleteInstance(m_shaderProgramSystem);
-	m_alloc.deleteInstance(m_transferGpuAlloc);
+	deleteInstance(m_pool, m_asyncLoader);
+	deleteInstance(m_pool, m_shaderProgramSystem);
+	deleteInstance(m_pool, m_transferGpuAlloc);
 }
 }
 
 
 Error ResourceManager::init(ResourceManagerInitInfo& init)
 Error ResourceManager::init(ResourceManagerInitInfo& init)
@@ -47,26 +47,26 @@ Error ResourceManager::init(ResourceManagerInitInfo& init)
 	m_fs = init.m_resourceFs;
 	m_fs = init.m_resourceFs;
 	m_config = init.m_config;
 	m_config = init.m_config;
 	m_vertexMem = init.m_vertexMemory;
 	m_vertexMem = init.m_vertexMemory;
-	m_alloc = ResourceAllocator<U8>(init.m_allocCallback, init.m_allocCallbackData, "Resources");
 
 
-	m_tmpAlloc = TempResourceAllocator<U8>(init.m_allocCallback, init.m_allocCallbackData, 10_MB);
+	m_pool.init(init.m_allocCallback, init.m_allocCallbackData, "Resources");
+	m_tmpPool.init(init.m_allocCallback, init.m_allocCallbackData, 10_MB);
 
 
 	// Init type resource managers
 	// Init type resource managers
-#define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) TypeResourceManager<rsrc_>::init(m_alloc);
+#define ANKI_INSTANTIATE_RESOURCE(rsrc_, ptr_) TypeResourceManager<rsrc_>::init(&m_pool);
 #define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 #define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 #include <AnKi/Resource/InstantiationMacros.h>
 #include <AnKi/Resource/InstantiationMacros.h>
 #undef ANKI_INSTANTIATE_RESOURCE
 #undef ANKI_INSTANTIATE_RESOURCE
 #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
 #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
 
 
 	// Init the thread
 	// Init the thread
-	m_asyncLoader = m_alloc.newInstance<AsyncLoader>();
-	m_asyncLoader->init(m_alloc);
+	m_asyncLoader = newInstance<AsyncLoader>(m_pool);
+	m_asyncLoader->init(&m_pool);
 
 
-	m_transferGpuAlloc = m_alloc.newInstance<TransferGpuAllocator>();
-	ANKI_CHECK(m_transferGpuAlloc->init(m_config->getRsrcTransferScratchMemorySize(), m_gr, m_alloc));
+	m_transferGpuAlloc = newInstance<TransferGpuAllocator>(m_pool);
+	ANKI_CHECK(m_transferGpuAlloc->init(m_config->getRsrcTransferScratchMemorySize(), m_gr, &m_pool));
 
 
 	// Init the programs
 	// Init the programs
-	m_shaderProgramSystem = m_alloc.newInstance<ShaderProgramResourceSystem>(m_alloc);
+	m_shaderProgramSystem = newInstance<ShaderProgramResourceSystem>(m_pool, &m_pool);
 	ANKI_CHECK(m_shaderProgramSystem->init(*m_fs, *m_gr));
 	ANKI_CHECK(m_shaderProgramSystem->init(*m_fs, *m_gr));
 
 
 	return Error::kNone;
 	return Error::kNone;
@@ -95,27 +95,27 @@ Error ResourceManager::loadResource(const CString& filename, ResourcePtr<T>& out
 	else
 	else
 	{
 	{
 		// Allocate ptr
 		// Allocate ptr
-		T* ptr = m_alloc.newInstance<T>(this);
+		T* ptr = newInstance<T>(m_pool, this);
 		ANKI_ASSERT(ptr->getRefcount() == 0);
 		ANKI_ASSERT(ptr->getRefcount() == 0);
 
 
 		// Increment the refcount in that case where async jobs increment it and decrement it in the scope of a load()
 		// Increment the refcount in that case where async jobs increment it and decrement it in the scope of a load()
 		ptr->retain();
 		ptr->retain();
 
 
 		// Populate the ptr. Use a block to cleanup temp_pool allocations
 		// Populate the ptr. Use a block to cleanup temp_pool allocations
-		auto& pool = m_tmpAlloc.getMemoryPool();
+		StackMemoryPool& tmpPool = m_tmpPool;
 
 
 		{
 		{
-			[[maybe_unused]] const U allocsCountBefore = pool.getAllocationCount();
+			[[maybe_unused]] const U allocsCountBefore = tmpPool.getAllocationCount();
 
 
 			err = ptr->load(filename, async);
 			err = ptr->load(filename, async);
 			if(err)
 			if(err)
 			{
 			{
 				ANKI_RESOURCE_LOGE("Failed to load resource: %s", &filename[0]);
 				ANKI_RESOURCE_LOGE("Failed to load resource: %s", &filename[0]);
-				m_alloc.deleteInstance(ptr);
+				deleteInstance(m_pool, ptr);
 				return err;
 				return err;
 			}
 			}
 
 
-			ANKI_ASSERT(pool.getAllocationCount() == allocsCountBefore && "Forgot to deallocate");
+			ANKI_ASSERT(tmpPool.getAllocationCount() == allocsCountBefore && "Forgot to deallocate");
 		}
 		}
 
 
 		ptr->setFilename(filename);
 		ptr->setFilename(filename);
@@ -123,9 +123,9 @@ Error ResourceManager::loadResource(const CString& filename, ResourcePtr<T>& out
 
 
 		// Reset the memory pool if no-one is using it.
 		// Reset the memory pool if no-one is using it.
 		// NOTE: Check because resources load other resources
 		// NOTE: Check because resources load other resources
-		if(pool.getAllocationCount() == 0)
+		if(tmpPool.getAllocationCount() == 0)
 		{
 		{
-			pool.reset();
+			tmpPool.reset();
 		}
 		}
 
 
 		// Register resource
 		// Register resource

+ 13 - 12
AnKi/Resource/ResourceManager.h

@@ -38,7 +38,7 @@ protected:
 	~TypeResourceManager()
 	~TypeResourceManager()
 	{
 	{
 		ANKI_ASSERT(m_ptrs.isEmpty() && "Forgot to delete some resources");
 		ANKI_ASSERT(m_ptrs.isEmpty() && "Forgot to delete some resources");
-		m_ptrs.destroy(m_alloc);
+		m_ptrs.destroy(*m_pool);
 	}
 	}
 
 
 	Type* findLoadedResource(const CString& filename)
 	Type* findLoadedResource(const CString& filename)
@@ -50,25 +50,26 @@ protected:
 	void registerResource(Type* ptr)
 	void registerResource(Type* ptr)
 	{
 	{
 		ANKI_ASSERT(find(ptr->getFilename()) == m_ptrs.getEnd());
 		ANKI_ASSERT(find(ptr->getFilename()) == m_ptrs.getEnd());
-		m_ptrs.pushBack(m_alloc, ptr);
+		m_ptrs.pushBack(*m_pool, ptr);
 	}
 	}
 
 
 	void unregisterResource(Type* ptr)
 	void unregisterResource(Type* ptr)
 	{
 	{
 		auto it = find(ptr->getFilename());
 		auto it = find(ptr->getFilename());
 		ANKI_ASSERT(it != m_ptrs.end());
 		ANKI_ASSERT(it != m_ptrs.end());
-		m_ptrs.erase(m_alloc, it);
+		m_ptrs.erase(*m_pool, it);
 	}
 	}
 
 
-	void init(ResourceAllocator<U8> alloc)
+	void init(HeapMemoryPool* pool)
 	{
 	{
-		m_alloc = std::move(alloc);
+		ANKI_ASSERT(pool);
+		m_pool = pool;
 	}
 	}
 
 
 private:
 private:
 	using Container = List<Type*>;
 	using Container = List<Type*>;
 
 
-	ResourceAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	Container m_ptrs;
 	Container m_ptrs;
 
 
 	typename Container::Iterator find(const CString& filename)
 	typename Container::Iterator find(const CString& filename)
@@ -129,14 +130,14 @@ public:
 
 
 	// Internals:
 	// Internals:
 
 
-	ANKI_INTERNAL ResourceAllocator<U8>& getAllocator()
+	ANKI_INTERNAL HeapMemoryPool& getMemoryPool() const
 	{
 	{
-		return m_alloc;
+		return m_pool;
 	}
 	}
 
 
-	ANKI_INTERNAL TempResourceAllocator<U8>& getTempAllocator()
+	ANKI_INTERNAL StackMemoryPool& getTempMemoryPool() const
 	{
 	{
-		return m_tmpAlloc;
+		return m_tmpPool;
 	}
 	}
 
 
 	ANKI_INTERNAL GrManager& getGrManager()
 	ANKI_INTERNAL GrManager& getGrManager()
@@ -217,8 +218,8 @@ private:
 	PhysicsWorld* m_physics = nullptr;
 	PhysicsWorld* m_physics = nullptr;
 	ResourceFilesystem* m_fs = nullptr;
 	ResourceFilesystem* m_fs = nullptr;
 	ConfigSet* m_config = nullptr;
 	ConfigSet* m_config = nullptr;
-	ResourceAllocator<U8> m_alloc;
-	TempResourceAllocator<U8> m_tmpAlloc;
+	mutable HeapMemoryPool m_pool; ///< Mutable because it's thread-safe and is may be called by const methods.
+	mutable StackMemoryPool m_tmpPool; ///< Same as above.
 	AsyncLoader* m_asyncLoader = nullptr; ///< Async loading thread
 	AsyncLoader* m_asyncLoader = nullptr; ///< Async loading thread
 	ShaderProgramResourceSystem* m_shaderProgramSystem = nullptr;
 	ShaderProgramResourceSystem* m_shaderProgramSystem = nullptr;
 	VertexGpuMemoryPool* m_vertexMem = nullptr;
 	VertexGpuMemoryPool* m_vertexMem = nullptr;

+ 7 - 8
AnKi/Resource/ResourceObject.cpp

@@ -17,17 +17,17 @@ ResourceObject::ResourceObject(ResourceManager* manager)
 
 
 ResourceObject::~ResourceObject()
 ResourceObject::~ResourceObject()
 {
 {
-	m_fname.destroy(getAllocator());
+	m_fname.destroy(getMemoryPool());
 }
 }
 
 
-ResourceAllocator<U8> ResourceObject::getAllocator() const
+HeapMemoryPool& ResourceObject::getMemoryPool() const
 {
 {
-	return m_manager->getAllocator();
+	return m_manager->getMemoryPool();
 }
 }
 
 
-TempResourceAllocator<U8> ResourceObject::getTempAllocator() const
+StackMemoryPool& ResourceObject::getTempMemoryPool() const
 {
 {
-	return m_manager->getTempAllocator();
+	return m_manager->getTempMemoryPool();
 }
 }
 
 
 Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
 Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
@@ -42,7 +42,6 @@ Error ResourceObject::openFileReadAllText(const CString& filename, StringRaii& t
 	ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
 	ANKI_CHECK(m_manager->getFilesystem().openFile(filename, file));
 
 
 	// Read string
 	// Read string
-	text = StringRaii(getTempAllocator());
 	ANKI_CHECK(file->readAllText(text));
 	ANKI_CHECK(file->readAllText(text));
 
 
 	return Error::kNone;
 	return Error::kNone;
@@ -50,10 +49,10 @@ Error ResourceObject::openFileReadAllText(const CString& filename, StringRaii& t
 
 
 Error ResourceObject::openFileParseXml(const CString& filename, XmlDocument& xml)
 Error ResourceObject::openFileParseXml(const CString& filename, XmlDocument& xml)
 {
 {
-	StringRaii txt(getTempAllocator());
+	StringRaii txt(&xml.getMemoryPool());
 	ANKI_CHECK(openFileReadAllText(filename, txt));
 	ANKI_CHECK(openFileReadAllText(filename, txt));
 
 
-	ANKI_CHECK(xml.parse(txt.toCString(), getTempAllocator()));
+	ANKI_CHECK(xml.parse(txt.toCString()));
 
 
 	return Error::kNone;
 	return Error::kNone;
 }
 }

+ 3 - 3
AnKi/Resource/ResourceObject.h

@@ -34,8 +34,8 @@ public:
 		return *m_manager;
 		return *m_manager;
 	}
 	}
 
 
-	ResourceAllocator<U8> getAllocator() const;
-	TempResourceAllocator<U8> getTempAllocator() const;
+	HeapMemoryPool& getMemoryPool() const;
+	StackMemoryPool& getTempMemoryPool() const;
 
 
 	void retain() const
 	void retain() const
 	{
 	{
@@ -65,7 +65,7 @@ public:
 	ANKI_INTERNAL void setFilename(const CString& fname)
 	ANKI_INTERNAL void setFilename(const CString& fname)
 	{
 	{
 		ANKI_ASSERT(m_fname.isEmpty());
 		ANKI_ASSERT(m_fname.isEmpty());
-		m_fname.create(getAllocator(), fname);
+		m_fname.create(getMemoryPool(), fname);
 	}
 	}
 
 
 	ANKI_INTERNAL void setUuid(U64 uuid)
 	ANKI_INTERNAL void setUuid(U64 uuid)

+ 3 - 3
AnKi/Resource/ScriptResource.cpp

@@ -10,7 +10,7 @@ namespace anki {
 
 
 ScriptResource::~ScriptResource()
 ScriptResource::~ScriptResource()
 {
 {
-	m_source.destroy(getAllocator());
+	m_source.destroy(getMemoryPool());
 }
 }
 
 
 Error ScriptResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error ScriptResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
@@ -18,9 +18,9 @@ Error ScriptResource::load(const ResourceFilename& filename, [[maybe_unused]] Bo
 	ResourceFilePtr file;
 	ResourceFilePtr file;
 	ANKI_CHECK(openFile(filename, file));
 	ANKI_CHECK(openFile(filename, file));
 
 
-	StringRaii src(getAllocator());
+	StringRaii src(&getMemoryPool());
 	ANKI_CHECK(file->readAllText(src));
 	ANKI_CHECK(file->readAllText(src));
-	m_source.create(getAllocator(), src);
+	m_source = std::move(src);
 
 
 	return Error::kNone;
 	return Error::kNone;
 }
 }

+ 14 - 14
AnKi/Resource/ShaderProgramResource.cpp

@@ -25,27 +25,27 @@ ShaderProgramResourceVariant::~ShaderProgramResourceVariant()
 
 
 ShaderProgramResource::ShaderProgramResource(ResourceManager* manager)
 ShaderProgramResource::ShaderProgramResource(ResourceManager* manager)
 	: ResourceObject(manager)
 	: ResourceObject(manager)
-	, m_binary(getAllocator())
+	, m_binary(&getMemoryPool())
 {
 {
 }
 }
 
 
 ShaderProgramResource::~ShaderProgramResource()
 ShaderProgramResource::~ShaderProgramResource()
 {
 {
-	m_mutators.destroy(getAllocator());
+	m_mutators.destroy(getMemoryPool());
 
 
 	for(ShaderProgramResourceConstant& c : m_consts)
 	for(ShaderProgramResourceConstant& c : m_consts)
 	{
 	{
-		c.m_name.destroy(getAllocator());
+		c.m_name.destroy(getMemoryPool());
 	}
 	}
-	m_consts.destroy(getAllocator());
-	m_constBinaryMapping.destroy(getAllocator());
+	m_consts.destroy(getMemoryPool());
+	m_constBinaryMapping.destroy(getMemoryPool());
 
 
 	for(auto it : m_variants)
 	for(auto it : m_variants)
 	{
 	{
 		ShaderProgramResourceVariant* variant = &(*it);
 		ShaderProgramResourceVariant* variant = &(*it);
-		getAllocator().deleteInstance(variant);
+		deleteInstance(getMemoryPool(), variant);
 	}
 	}
-	m_variants.destroy(getAllocator());
+	m_variants.destroy(getMemoryPool());
 }
 }
 
 
 Error ShaderProgramResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error ShaderProgramResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
@@ -59,7 +59,7 @@ Error ShaderProgramResource::load(const ResourceFilename& filename, [[maybe_unus
 	// Create the mutators
 	// Create the mutators
 	if(binary.m_mutators.getSize() > 0)
 	if(binary.m_mutators.getSize() > 0)
 	{
 	{
-		m_mutators.create(getAllocator(), binary.m_mutators.getSize());
+		m_mutators.create(getMemoryPool(), binary.m_mutators.getSize());
 
 
 		for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
 		for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
 		{
 		{
@@ -91,7 +91,7 @@ Error ShaderProgramResource::load(const ResourceFilename& filename, [[maybe_unus
 			mapping.m_constsIdx = m_consts.getSize();
 			mapping.m_constsIdx = m_consts.getSize();
 		}
 		}
 
 
-		m_constBinaryMapping.emplaceBack(getAllocator(), mapping);
+		m_constBinaryMapping.emplaceBack(getMemoryPool(), mapping);
 
 
 		// Skip if const is there
 		// Skip if const is there
 		if(componentIdx > 0)
 		if(componentIdx > 0)
@@ -100,8 +100,8 @@ Error ShaderProgramResource::load(const ResourceFilename& filename, [[maybe_unus
 		}
 		}
 
 
 		// Create new one
 		// Create new one
-		ShaderProgramResourceConstant& in = *m_consts.emplaceBack(getAllocator());
-		in.m_name.create(getAllocator(), name);
+		ShaderProgramResourceConstant& in = *m_consts.emplaceBack(getMemoryPool());
+		in.m_name.create(getMemoryPool(), name);
 		in.m_index = m_consts.getSize() - 1;
 		in.m_index = m_consts.getSize() - 1;
 
 
 		if(componentCount == 1)
 		if(componentCount == 1)
@@ -254,7 +254,7 @@ void ShaderProgramResource::getOrCreateVariant(const ShaderProgramResourceVarian
 	ShaderProgramResourceVariant* v = createNewVariant(info);
 	ShaderProgramResourceVariant* v = createNewVariant(info);
 	if(v)
 	if(v)
 	{
 	{
-		m_variants.emplace(getAllocator(), hash, v);
+		m_variants.emplace(getMemoryPool(), hash, v);
 	}
 	}
 	variant = v;
 	variant = v;
 }
 }
@@ -295,7 +295,7 @@ ShaderProgramResource::createNewVariant(const ShaderProgramResourceVariantInitIn
 		binaryVariant = &binary.m_variants[0];
 		binaryVariant = &binary.m_variants[0];
 	}
 	}
 	ANKI_ASSERT(binaryVariant);
 	ANKI_ASSERT(binaryVariant);
-	ShaderProgramResourceVariant* variant = getAllocator().newInstance<ShaderProgramResourceVariant>();
+	ShaderProgramResourceVariant* variant = newInstance<ShaderProgramResourceVariant>(getMemoryPool());
 	variant->m_binaryVariant = binaryVariant;
 	variant->m_binaryVariant = binaryVariant;
 
 
 	// Set the constant values
 	// Set the constant values
@@ -372,7 +372,7 @@ ShaderProgramResource::createNewVariant(const ShaderProgramResourceVariantInitIn
 	if(!!(m_shaderStages & (ShaderTypeBit::kAllGraphics | ShaderTypeBit::kCompute)))
 	if(!!(m_shaderStages & (ShaderTypeBit::kAllGraphics | ShaderTypeBit::kCompute)))
 	{
 	{
 		// Create the program name
 		// Create the program name
-		StringRaii progName(getTempAllocator());
+		StringRaii progName(&getTempMemoryPool());
 		getFilepathFilename(getFilename(), progName);
 		getFilepathFilename(getFilename(), progName);
 		char* cprogName = const_cast<char*>(progName.cstr());
 		char* cprogName = const_cast<char*>(progName.cstr());
 		if(progName.getLength() > kMaxGrObjectNameLength)
 		if(progName.getLength() > kMaxGrObjectNameLength)

+ 27 - 27
AnKi/Resource/ShaderProgramResourceSystem.cpp

@@ -17,10 +17,10 @@
 namespace anki {
 namespace anki {
 
 
 U64 ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(CString resourceFilename, U64 mutationHash,
 U64 ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(CString resourceFilename, U64 mutationHash,
-																 GenericMemoryPoolAllocator<U8> alloc)
+																 HeapMemoryPool& pool)
 {
 {
 	ANKI_ASSERT(resourceFilename.getLength() > 0);
 	ANKI_ASSERT(resourceFilename.getLength() > 0);
-	StringRaii basename(alloc);
+	StringRaii basename(&pool);
 	getFilepathFilename(resourceFilename, basename);
 	getFilepathFilename(resourceFilename, basename);
 	const U64 hash = appendHash(basename.cstr(), basename.getLength(), mutationHash);
 	const U64 hash = appendHash(basename.cstr(), basename.getLength(), mutationHash);
 	return hash;
 	return hash;
@@ -28,7 +28,7 @@ U64 ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(CString resourc
 
 
 ShaderProgramResourceSystem::~ShaderProgramResourceSystem()
 ShaderProgramResourceSystem::~ShaderProgramResourceSystem()
 {
 {
-	m_rtLibraries.destroy(m_alloc);
+	m_rtLibraries.destroy(*m_pool);
 }
 }
 
 
 Error ShaderProgramResourceSystem::init(ResourceFilesystem& fs, GrManager& gr)
 Error ShaderProgramResourceSystem::init(ResourceFilesystem& fs, GrManager& gr)
@@ -39,7 +39,7 @@ Error ShaderProgramResourceSystem::init(ResourceFilesystem& fs, GrManager& gr)
 	}
 	}
 
 
 	// Create RT pipeline libraries
 	// Create RT pipeline libraries
-	const Error err = createRayTracingPrograms(fs, gr, m_alloc, m_rtLibraries);
+	const Error err = createRayTracingPrograms(fs, gr, *m_pool, m_rtLibraries);
 	if(err)
 	if(err)
 	{
 	{
 		ANKI_RESOURCE_LOGE("Failed to create ray tracing programs");
 		ANKI_RESOURCE_LOGE("Failed to create ray tracing programs");
@@ -48,8 +48,7 @@ Error ShaderProgramResourceSystem::init(ResourceFilesystem& fs, GrManager& gr)
 	return err;
 	return err;
 }
 }
 
 
-Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem& fs, GrManager& gr,
-															GenericMemoryPoolAllocator<U8>& alloc,
+Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem& fs, GrManager& gr, HeapMemoryPool& pool,
 															DynamicArray<ShaderProgramRaytracingLibrary>& outLibs)
 															DynamicArray<ShaderProgramRaytracingLibrary>& outLibs)
 {
 {
 	ANKI_RESOURCE_LOGI("Creating ray tracing programs");
 	ANKI_RESOURCE_LOGI("Creating ray tracing programs");
@@ -75,11 +74,11 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 	class Lib
 	class Lib
 	{
 	{
 	public:
 	public:
-		GenericMemoryPoolAllocator<U8> m_alloc;
+		HeapMemoryPool* m_pool = nullptr;
 		GrManager* m_gr;
 		GrManager* m_gr;
-		StringRaii m_name{m_alloc};
-		DynamicArrayRaii<Shader> m_shaders{m_alloc};
-		DynamicArrayRaii<ShaderGroup> m_shaderGroups{m_alloc};
+		StringRaii m_name = {m_pool};
+		DynamicArrayRaii<Shader> m_shaders = {m_pool};
+		DynamicArrayRaii<ShaderGroup> m_shaderGroups = {m_pool};
 		ShaderTypeBit m_presentStages = ShaderTypeBit::kNone;
 		ShaderTypeBit m_presentStages = ShaderTypeBit::kNone;
 		U32 m_rayTypeCount = 0;
 		U32 m_rayTypeCount = 0;
 		BitSet<64> m_rayTypeMask = {false};
 		BitSet<64> m_rayTypeMask = {false};
@@ -87,10 +86,11 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 		U32 m_missShaderGroupCount = 0;
 		U32 m_missShaderGroupCount = 0;
 		U32 m_hitShaderGroupCount = 0;
 		U32 m_hitShaderGroupCount = 0;
 
 
-		Lib(GenericMemoryPoolAllocator<U8> alloc, GrManager* gr)
-			: m_alloc(alloc)
+		Lib(HeapMemoryPool* pool, GrManager* gr)
+			: m_pool(pool)
 			, m_gr(gr)
 			, m_gr(gr)
 		{
 		{
+			ANKI_ASSERT(pool);
 		}
 		}
 
 
 		U32 addShader(const ShaderProgramBinaryCodeBlock& codeBlock, CString progName, ShaderType shaderType)
 		U32 addShader(const ShaderProgramBinaryCodeBlock& codeBlock, CString progName, ShaderType shaderType)
@@ -124,7 +124,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 		void addGroup(CString filename, U64 mutationHash, U32 rayGen, U32 miss, U32 chit, U32 ahit)
 		void addGroup(CString filename, U64 mutationHash, U32 rayGen, U32 miss, U32 chit, U32 ahit)
 		{
 		{
 			const U64 groupHash =
 			const U64 groupHash =
-				ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(filename, mutationHash, m_alloc);
+				ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(filename, mutationHash, *m_pool);
 #if ANKI_ENABLE_ASSERTIONS
 #if ANKI_ENABLE_ASSERTIONS
 			for(const ShaderGroup& group : m_shaderGroups)
 			for(const ShaderGroup& group : m_shaderGroups)
 			{
 			{
@@ -156,11 +156,11 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 		}
 		}
 	};
 	};
 
 
-	DynamicArrayRaii<Lib> libs(alloc);
+	DynamicArrayRaii<Lib> libs(&pool);
 
 
 	ANKI_CHECK(fs.iterateAllFilenames([&](CString filename) -> Error {
 	ANKI_CHECK(fs.iterateAllFilenames([&](CString filename) -> Error {
 		// Check file extension
 		// Check file extension
-		StringRaii extension(alloc);
+		StringRaii extension(&pool);
 		getFilepathExtension(filename, extension);
 		getFilepathExtension(filename, extension);
 		const Char binExtension[] = "ankiprogbin";
 		const Char binExtension[] = "ankiprogbin";
 		if(extension.getLength() != sizeof(binExtension) - 1 || extension != binExtension)
 		if(extension.getLength() != sizeof(binExtension) - 1 || extension != binExtension)
@@ -177,7 +177,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 		// Get the binary
 		// Get the binary
 		ResourceFilePtr file;
 		ResourceFilePtr file;
 		ANKI_CHECK(fs.openFile(filename, file));
 		ANKI_CHECK(fs.openFile(filename, file));
-		ShaderProgramBinaryWrapper binaryw(alloc);
+		ShaderProgramBinaryWrapper binaryw(&pool);
 		ANKI_CHECK(binaryw.deserializeFromAnyFile(*file));
 		ANKI_CHECK(binaryw.deserializeFromAnyFile(*file));
 		const ShaderProgramBinary& binary = binaryw.getBinary();
 		const ShaderProgramBinary& binary = binaryw.getBinary();
 
 
@@ -194,7 +194,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 		}
 		}
 
 
 		// Create the program name
 		// Create the program name
-		StringRaii progName(alloc);
+		StringRaii progName(&pool);
 		getFilepathFilename(filename, progName);
 		getFilepathFilename(filename, progName);
 
 
 		// Find or create the lib
 		// Find or create the lib
@@ -211,7 +211,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 
 
 			if(lib == nullptr)
 			if(lib == nullptr)
 			{
 			{
-				libs.emplaceBack(alloc, &gr);
+				libs.emplaceBack(&pool, &gr);
 				lib = &libs.getBack();
 				lib = &libs.getBack();
 				lib->m_name.create(CString(&binary.m_libraryName[0]));
 				lib->m_name.create(CString(&binary.m_libraryName[0]));
 			}
 			}
@@ -371,14 +371,14 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 	// See the ShaderProgram class for info.
 	// See the ShaderProgram class for info.
 	if(libs.getSize() != 0)
 	if(libs.getSize() != 0)
 	{
 	{
-		outLibs.create(alloc, libs.getSize());
+		outLibs.create(pool, libs.getSize());
 
 
 		for(U32 libIdx = 0; libIdx < libs.getSize(); ++libIdx)
 		for(U32 libIdx = 0; libIdx < libs.getSize(); ++libIdx)
 		{
 		{
 			ShaderProgramRaytracingLibrary& outLib = outLibs[libIdx];
 			ShaderProgramRaytracingLibrary& outLib = outLibs[libIdx];
 			const Lib& inLib = libs[libIdx];
 			const Lib& inLib = libs[libIdx];
 
 
-			outLib.m_alloc = alloc;
+			outLib.m_pool = &pool;
 
 
 			if(inLib.m_presentStages
 			if(inLib.m_presentStages
 			   != (ShaderTypeBit::kRayGen | ShaderTypeBit::kMiss | ShaderTypeBit::kClosestHit | ShaderTypeBit::kAnyHit))
 			   != (ShaderTypeBit::kRayGen | ShaderTypeBit::kMiss | ShaderTypeBit::kClosestHit | ShaderTypeBit::kAnyHit))
@@ -393,12 +393,12 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 				return Error::kUserData;
 				return Error::kUserData;
 			}
 			}
 
 
-			outLib.m_libraryName.create(alloc, inLib.m_name);
+			outLib.m_libraryName.create(pool, inLib.m_name);
 			outLib.m_rayTypeCount = inLib.m_rayTypeCount;
 			outLib.m_rayTypeCount = inLib.m_rayTypeCount;
 
 
-			DynamicArrayRaii<RayTracingHitGroup> initInfoHitGroups(alloc);
-			DynamicArrayRaii<ShaderPtr> missShaders(alloc);
-			DynamicArrayRaii<ShaderPtr> rayGenShaders(alloc);
+			DynamicArrayRaii<RayTracingHitGroup> initInfoHitGroups(&pool);
+			DynamicArrayRaii<ShaderPtr> missShaders(&pool);
+			DynamicArrayRaii<ShaderPtr> rayGenShaders(&pool);
 
 
 			// Add the hitgroups to the init info
 			// Add the hitgroups to the init info
 			for(U32 shaderGroupIdx = 0; shaderGroupIdx < inLib.m_shaderGroups.getSize(); ++shaderGroupIdx)
 			for(U32 shaderGroupIdx = 0; shaderGroupIdx < inLib.m_shaderGroups.getSize(); ++shaderGroupIdx)
@@ -426,7 +426,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 					// The hit shaders are after ray gen and miss shaders
 					// The hit shaders are after ray gen and miss shaders
 					const U32 idx =
 					const U32 idx =
 						inLib.m_rayGenShaderGroupCount + inLib.m_missShaderGroupCount + initInfoHitGroups.getSize() - 1;
 						inLib.m_rayGenShaderGroupCount + inLib.m_missShaderGroupCount + initInfoHitGroups.getSize() - 1;
-					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(alloc, inShaderGroup.m_hitGroupHash, idx);
+					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(pool, inShaderGroup.m_hitGroupHash, idx);
 				}
 				}
 				else if(inShaderGroup.m_miss < kMaxU32)
 				else if(inShaderGroup.m_miss < kMaxU32)
 				{
 				{
@@ -439,7 +439,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 
 
 					// The miss shaders are after ray gen
 					// The miss shaders are after ray gen
 					const U32 idx = inLib.m_rayGenShaderGroupCount + missShaders.getSize() - 1;
 					const U32 idx = inLib.m_rayGenShaderGroupCount + missShaders.getSize() - 1;
-					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(alloc, inShaderGroup.m_hitGroupHash, idx);
+					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(pool, inShaderGroup.m_hitGroupHash, idx);
 				}
 				}
 				else
 				else
 				{
 				{
@@ -452,7 +452,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceFilesystem&
 
 
 					// Ray gen shaders are first
 					// Ray gen shaders are first
 					const U32 idx = rayGenShaders.getSize() - 1;
 					const U32 idx = rayGenShaders.getSize() - 1;
-					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(alloc, inShaderGroup.m_hitGroupHash, idx);
+					outLib.m_resourceHashToShaderGroupHandleIndex.emplace(pool, inShaderGroup.m_hitGroupHash, idx);
 				}
 				}
 			} // end for all groups
 			} // end for all groups
 
 

+ 10 - 10
AnKi/Resource/ShaderProgramResourceSystem.h

@@ -24,8 +24,8 @@ class ShaderProgramRaytracingLibrary
 public:
 public:
 	~ShaderProgramRaytracingLibrary()
 	~ShaderProgramRaytracingLibrary()
 	{
 	{
-		m_libraryName.destroy(m_alloc);
-		m_resourceHashToShaderGroupHandleIndex.destroy(m_alloc);
+		m_libraryName.destroy(*m_pool);
+		m_resourceHashToShaderGroupHandleIndex.destroy(*m_pool);
 	}
 	}
 
 
 	CString getLibraryName() const
 	CString getLibraryName() const
@@ -48,19 +48,18 @@ public:
 	/// handle index.
 	/// handle index.
 	U32 getShaderGroupHandleIndex(CString resourceFilename, U64 mutationHash) const
 	U32 getShaderGroupHandleIndex(CString resourceFilename, U64 mutationHash) const
 	{
 	{
-		return getIndex(generateShaderGroupGroupHash(resourceFilename, mutationHash, m_alloc));
+		return getIndex(generateShaderGroupGroupHash(resourceFilename, mutationHash, *m_pool));
 	}
 	}
 
 
 private:
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	String m_libraryName;
 	String m_libraryName;
 	U32 m_rayTypeCount = kMaxU32;
 	U32 m_rayTypeCount = kMaxU32;
 	ShaderProgramPtr m_program;
 	ShaderProgramPtr m_program;
 	HashMap<U64, U32> m_resourceHashToShaderGroupHandleIndex;
 	HashMap<U64, U32> m_resourceHashToShaderGroupHandleIndex;
 
 
 	/// Given the filename of a program (that contains ray tracing shaders) and a specific mutation get a hash back.
 	/// Given the filename of a program (that contains ray tracing shaders) and a specific mutation get a hash back.
-	static U64 generateShaderGroupGroupHash(CString resourceFilename, U64 mutationHash,
-											GenericMemoryPoolAllocator<U8> alloc);
+	static U64 generateShaderGroupGroupHash(CString resourceFilename, U64 mutationHash, HeapMemoryPool& pool);
 
 
 	/// The hash generated by generateShaderGroupGroupHash() can be used to retrieve the group position in the
 	/// The hash generated by generateShaderGroupGroupHash() can be used to retrieve the group position in the
 	/// m_program.
 	/// m_program.
@@ -76,9 +75,10 @@ private:
 class ShaderProgramResourceSystem
 class ShaderProgramResourceSystem
 {
 {
 public:
 public:
-	ShaderProgramResourceSystem(const GenericMemoryPoolAllocator<U8>& alloc)
-		: m_alloc(alloc)
+	ShaderProgramResourceSystem(HeapMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(pool);
 	}
 	}
 
 
 	~ShaderProgramResourceSystem();
 	~ShaderProgramResourceSystem();
@@ -91,10 +91,10 @@ public:
 	}
 	}
 
 
 private:
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	DynamicArray<ShaderProgramRaytracingLibrary> m_rtLibraries;
 	DynamicArray<ShaderProgramRaytracingLibrary> m_rtLibraries;
 
 
-	static Error createRayTracingPrograms(ResourceFilesystem& fs, GrManager& gr, GenericMemoryPoolAllocator<U8>& alloc,
+	static Error createRayTracingPrograms(ResourceFilesystem& fs, GrManager& gr, HeapMemoryPool& pool,
 										  DynamicArray<ShaderProgramRaytracingLibrary>& outLibs);
 										  DynamicArray<ShaderProgramRaytracingLibrary>& outLibs);
 };
 };
 /// @}
 /// @}

+ 8 - 8
AnKi/Resource/SkeletonResource.cpp

@@ -13,15 +13,15 @@ SkeletonResource::~SkeletonResource()
 {
 {
 	for(Bone& b : m_bones)
 	for(Bone& b : m_bones)
 	{
 	{
-		b.destroy(getAllocator());
+		b.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_bones.destroy(getAllocator());
+	m_bones.destroy(getMemoryPool());
 }
 }
 
 
 Error SkeletonResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 Error SkeletonResource::load(const ResourceFilename& filename, [[maybe_unused]] Bool async)
 {
 {
-	XmlDocument doc;
+	XmlDocument doc(&getTempMemoryPool());
 	ANKI_CHECK(openFileParseXml(filename, doc));
 	ANKI_CHECK(openFileParseXml(filename, doc));
 
 
 	XmlElement rootEl;
 	XmlElement rootEl;
@@ -37,9 +37,9 @@ Error SkeletonResource::load(const ResourceFilename& filename, [[maybe_unused]]
 	ANKI_CHECK(boneEl.getSiblingElementsCount(boneCount));
 	ANKI_CHECK(boneEl.getSiblingElementsCount(boneCount));
 	++boneCount;
 	++boneCount;
 
 
-	m_bones.create(getAllocator(), boneCount);
+	m_bones.create(getMemoryPool(), boneCount);
 
 
-	StringListRaii boneParents(getAllocator());
+	StringListRaii boneParents(&getMemoryPool());
 
 
 	// Load every bone
 	// Load every bone
 	boneCount = 0;
 	boneCount = 0;
@@ -51,7 +51,7 @@ Error SkeletonResource::load(const ResourceFilename& filename, [[maybe_unused]]
 		// name
 		// name
 		CString name;
 		CString name;
 		ANKI_CHECK(boneEl.getAttributeText("name", name));
 		ANKI_CHECK(boneEl.getAttributeText("name", name));
-		bone.m_name.create(getAllocator(), name);
+		bone.m_name.create(getMemoryPool(), name);
 
 
 		// transform
 		// transform
 		ANKI_CHECK(boneEl.getAttributeNumbers("transform", bone.m_transform));
 		ANKI_CHECK(boneEl.getAttributeNumbers("transform", bone.m_transform));
@@ -109,10 +109,10 @@ Error SkeletonResource::load(const ResourceFilename& filename, [[maybe_unused]]
 				return Error::kUserData;
 				return Error::kUserData;
 			}
 			}
 
 
-			if(bone.m_parent->m_childrenCount >= MAX_CHILDREN_PER_BONE)
+			if(bone.m_parent->m_childrenCount >= kMaxChildrenPerBone)
 			{
 			{
 				ANKI_RESOURCE_LOGE("Bone \"%s\" cannot have more that %u children", &bone.m_parent->m_name[0],
 				ANKI_RESOURCE_LOGE("Bone \"%s\" cannot have more that %u children", &bone.m_parent->m_name[0],
-								   MAX_CHILDREN_PER_BONE);
+								   kMaxChildrenPerBone);
 				return Error::kUserData;
 				return Error::kUserData;
 			}
 			}
 
 

+ 4 - 4
AnKi/Resource/SkeletonResource.h

@@ -14,7 +14,7 @@ namespace anki {
 /// @addtogroup resource
 /// @addtogroup resource
 /// @{
 /// @{
 
 
-const U32 MAX_CHILDREN_PER_BONE = 8;
+constexpr U32 kMaxChildrenPerBone = 8;
 
 
 /// Skeleton bone
 /// Skeleton bone
 class Bone
 class Bone
@@ -65,12 +65,12 @@ private:
 	U32 m_idx;
 	U32 m_idx;
 
 
 	Bone* m_parent = nullptr;
 	Bone* m_parent = nullptr;
-	Array<Bone*, MAX_CHILDREN_PER_BONE> m_children = {};
+	Array<Bone*, kMaxChildrenPerBone> m_children = {};
 	U8 m_childrenCount = 0;
 	U8 m_childrenCount = 0;
 
 
-	void destroy(ResourceAllocator<U8> alloc)
+	void destroy(HeapMemoryPool& pool)
 	{
 	{
-		m_name.destroy(alloc);
+		m_name.destroy(pool);
 	}
 	}
 };
 };
 
 

+ 14 - 13
AnKi/Resource/TransferGpuAllocator.cpp

@@ -13,7 +13,7 @@ namespace anki {
 
 
 Error TransferGpuAllocator::StackAllocatorBuilderInterface::allocateChunk(PtrSize size, Chunk*& out)
 Error TransferGpuAllocator::StackAllocatorBuilderInterface::allocateChunk(PtrSize size, Chunk*& out)
 {
 {
-	out = m_parent->m_alloc.newInstance<Chunk>();
+	out = newInstance<Chunk>(*m_parent->m_pool);
 
 
 	BufferInitInfo bufferInit(size, BufferUsageBit::kTransferSource, BufferMapAccessBit::kWrite, "Transfer");
 	BufferInitInfo bufferInit(size, BufferUsageBit::kTransferSource, BufferMapAccessBit::kWrite, "Transfer");
 	out->m_buffer = m_parent->m_gr->newBuffer(bufferInit);
 	out->m_buffer = m_parent->m_gr->newBuffer(bufferInit);
@@ -29,7 +29,7 @@ void TransferGpuAllocator::StackAllocatorBuilderInterface::freeChunk(Chunk* chun
 
 
 	chunk->m_buffer->unmap();
 	chunk->m_buffer->unmap();
 
 
-	m_parent->m_alloc.deleteInstance(chunk);
+	deleteInstance(*m_parent->m_pool, chunk);
 }
 }
 
 
 TransferGpuAllocator::TransferGpuAllocator()
 TransferGpuAllocator::TransferGpuAllocator()
@@ -41,16 +41,17 @@ TransferGpuAllocator::~TransferGpuAllocator()
 	for(Pool& pool : m_pools)
 	for(Pool& pool : m_pools)
 	{
 	{
 		ANKI_ASSERT(pool.m_pendingReleases == 0);
 		ANKI_ASSERT(pool.m_pendingReleases == 0);
-		pool.m_fences.destroy(m_alloc);
+		pool.m_fences.destroy(*m_pool);
 	}
 	}
 }
 }
 
 
-Error TransferGpuAllocator::init(PtrSize maxSize, GrManager* gr, ResourceAllocator<U8> alloc)
+Error TransferGpuAllocator::init(PtrSize maxSize, GrManager* gr, HeapMemoryPool* pool)
 {
 {
-	m_alloc = std::move(alloc);
+	ANKI_ASSERT(pool);
+	m_pool = pool;
 	m_gr = gr;
 	m_gr = gr;
 
 
-	m_maxAllocSize = getAlignedRoundUp(CHUNK_INITIAL_SIZE * POOL_COUNT, maxSize);
+	m_maxAllocSize = getAlignedRoundUp(kChunkInitialSize * kPoolCount, maxSize);
 	ANKI_RESOURCE_LOGI("Will use %zuMB of memory for transfer scratch", m_maxAllocSize / PtrSize(1_MB));
 	ANKI_RESOURCE_LOGI("Will use %zuMB of memory for transfer scratch", m_maxAllocSize / PtrSize(1_MB));
 
 
 	for(Pool& pool : m_pools)
 	for(Pool& pool : m_pools)
@@ -65,7 +66,7 @@ Error TransferGpuAllocator::allocate(PtrSize size, TransferGpuAllocatorHandle& h
 {
 {
 	ANKI_TRACE_SCOPED_EVENT(RSRC_ALLOCATE_TRANSFER);
 	ANKI_TRACE_SCOPED_EVENT(RSRC_ALLOCATE_TRANSFER);
 
 
-	const PtrSize poolSize = m_maxAllocSize / POOL_COUNT;
+	const PtrSize poolSize = m_maxAllocSize / kPoolCount;
 
 
 	LockGuard<Mutex> lock(m_mtx);
 	LockGuard<Mutex> lock(m_mtx);
 
 
@@ -80,7 +81,7 @@ Error TransferGpuAllocator::allocate(PtrSize size, TransferGpuAllocatorHandle& h
 	{
 	{
 		// Don't have enough space. Wait for one pool used in the past
 		// Don't have enough space. Wait for one pool used in the past
 
 
-		m_crntPool = U8((m_crntPool + 1) % POOL_COUNT);
+		m_crntPool = U8((m_crntPool + 1) % kPoolCount);
 		pool = &m_pools[m_crntPool];
 		pool = &m_pools[m_crntPool];
 
 
 		{
 		{
@@ -97,10 +98,10 @@ Error TransferGpuAllocator::allocate(PtrSize size, TransferGpuAllocatorHandle& h
 			{
 			{
 				FencePtr fence = pool->m_fences.getFront();
 				FencePtr fence = pool->m_fences.getFront();
 
 
-				const Bool done = fence->clientWait(MAX_FENCE_WAIT_TIME);
+				const Bool done = fence->clientWait(kMaxFenceWaitTime);
 				if(done)
 				if(done)
 				{
 				{
-					pool->m_fences.popFront(m_alloc);
+					pool->m_fences.popFront(*m_pool);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -111,7 +112,7 @@ Error TransferGpuAllocator::allocate(PtrSize size, TransferGpuAllocatorHandle& h
 
 
 	Chunk* chunk;
 	Chunk* chunk;
 	PtrSize offset;
 	PtrSize offset;
-	[[maybe_unused]] const Error err = pool->m_stackAlloc.allocate(size, GPU_BUFFER_ALIGNMENT, chunk, offset);
+	[[maybe_unused]] const Error err = pool->m_stackAlloc.allocate(size, kGpuBufferAlignment, chunk, offset);
 	ANKI_ASSERT(!err);
 	ANKI_ASSERT(!err);
 
 
 	handle.m_buffer = chunk->m_buffer;
 	handle.m_buffer = chunk->m_buffer;
@@ -134,7 +135,7 @@ Error TransferGpuAllocator::allocate(PtrSize size, TransferGpuAllocatorHandle& h
 			if(fenceDone)
 			if(fenceDone)
 			{
 			{
 				auto nextIt = it + 1;
 				auto nextIt = it + 1;
-				p.m_fences.erase(m_alloc, it);
+				p.m_fences.erase(*m_pool, it);
 				it = nextIt;
 				it = nextIt;
 			}
 			}
 			else
 			else
@@ -157,7 +158,7 @@ void TransferGpuAllocator::release(TransferGpuAllocatorHandle& handle, FencePtr
 	{
 	{
 		LockGuard<Mutex> lock(m_mtx);
 		LockGuard<Mutex> lock(m_mtx);
 
 
-		pool.m_fences.pushBack(m_alloc, fence);
+		pool.m_fences.pushBack(*m_pool, fence);
 
 
 		ANKI_ASSERT(pool.m_pendingReleases > 0);
 		ANKI_ASSERT(pool.m_pendingReleases > 0);
 		--pool.m_pendingReleases;
 		--pool.m_pendingReleases;

+ 9 - 9
AnKi/Resource/TransferGpuAllocator.h

@@ -101,17 +101,17 @@ class TransferGpuAllocator
 public:
 public:
 	/// Choose an alignment that satisfies 16 bytes and 3 bytes. RGB8 formats require 3 bytes alignment for the source
 	/// Choose an alignment that satisfies 16 bytes and 3 bytes. RGB8 formats require 3 bytes alignment for the source
 	/// of the buffer to image copies.
 	/// of the buffer to image copies.
-	static constexpr U32 GPU_BUFFER_ALIGNMENT = 16 * 3;
+	static constexpr U32 kGpuBufferAlignment = 16 * 3;
 
 
-	static constexpr U32 POOL_COUNT = 2;
-	static constexpr PtrSize CHUNK_INITIAL_SIZE = 64_MB;
-	static constexpr Second MAX_FENCE_WAIT_TIME = 500.0_ms;
+	static constexpr U32 kPoolCount = 2;
+	static constexpr PtrSize kChunkInitialSize = 64_MB;
+	static constexpr Second kMaxFenceWaitTime = 500.0_ms;
 
 
 	TransferGpuAllocator();
 	TransferGpuAllocator();
 
 
 	~TransferGpuAllocator();
 	~TransferGpuAllocator();
 
 
-	Error init(PtrSize maxSize, GrManager* gr, ResourceAllocator<U8> alloc);
+	Error init(PtrSize maxSize, GrManager* gr, HeapMemoryPool* pool);
 
 
 	/// Allocate some transfer memory. If there is not enough memory it will block until some is releaced. It's
 	/// Allocate some transfer memory. If there is not enough memory it will block until some is releaced. It's
 	/// threadsafe.
 	/// threadsafe.
@@ -151,12 +151,12 @@ private:
 
 
 		constexpr PtrSize getMaxAlignment()
 		constexpr PtrSize getMaxAlignment()
 		{
 		{
-			return GPU_BUFFER_ALIGNMENT;
+			return kGpuBufferAlignment;
 		}
 		}
 
 
 		constexpr PtrSize getInitialChunkSize() const
 		constexpr PtrSize getInitialChunkSize() const
 		{
 		{
-			return CHUNK_INITIAL_SIZE;
+			return kChunkInitialSize;
 		}
 		}
 
 
 		constexpr F64 getNextChunkGrowScale() const
 		constexpr F64 getNextChunkGrowScale() const
@@ -210,13 +210,13 @@ private:
 		U32 m_pendingReleases = 0;
 		U32 m_pendingReleases = 0;
 	};
 	};
 
 
-	ResourceAllocator<U8> m_alloc;
+	HeapMemoryPool* m_pool = nullptr;
 	GrManager* m_gr = nullptr;
 	GrManager* m_gr = nullptr;
 	PtrSize m_maxAllocSize = 0;
 	PtrSize m_maxAllocSize = 0;
 
 
 	Mutex m_mtx; ///< Protect all members bellow.
 	Mutex m_mtx; ///< Protect all members bellow.
 	ConditionVariable m_condVar;
 	ConditionVariable m_condVar;
-	Array<Pool, POOL_COUNT> m_pools;
+	Array<Pool, kPoolCount> m_pools;
 	U8 m_crntPool = 0;
 	U8 m_crntPool = 0;
 	PtrSize m_crntPoolAllocatedSize = 0;
 	PtrSize m_crntPoolAllocatedSize = 0;
 };
 };

+ 5 - 0
AnKi/Util/Xml.h

@@ -210,6 +210,11 @@ public:
 
 
 	Error getChildElementOptional(CString name, XmlElement& out) const;
 	Error getChildElementOptional(CString name, XmlElement& out) const;
 
 
+	BaseMemoryPool& getMemoryPool()
+	{
+		return *m_pool;
+	}
+
 private:
 private:
 	tinyxml2::XMLDocument m_doc;
 	tinyxml2::XMLDocument m_doc;
 	BaseMemoryPool* m_pool = nullptr;
 	BaseMemoryPool* m_pool = nullptr;