Browse Source

Remove the allocator from UI

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
be66deba89

+ 3 - 3
AnKi/Resource/ImageLoader.cpp

@@ -544,7 +544,7 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 
 
 	if(skipSize)
 	if(skipSize)
 	{
 	{
-		ANKI_CHECK(file.seek(skipSize, FileSeekOrigin::CURRENT));
+		ANKI_CHECK(file.seek(skipSize, FileSeekOrigin::kCurrent));
 	}
 	}
 
 
 	//
 	//
@@ -582,7 +582,7 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 					}
 					}
 					else
 					else
 					{
 					{
-						ANKI_CHECK(file.seek(dataSize, FileSeekOrigin::CURRENT));
+						ANKI_CHECK(file.seek(dataSize, FileSeekOrigin::kCurrent));
 					}
 					}
 				}
 				}
 			}
 			}
@@ -620,7 +620,7 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 			}
 			}
 			else
 			else
 			{
 			{
-				ANKI_CHECK(file.seek(dataSize, FileSeekOrigin::CURRENT));
+				ANKI_CHECK(file.seek(dataSize, FileSeekOrigin::kCurrent));
 			}
 			}
 
 
 			mipWidth /= 2;
 			mipWidth /= 2;

+ 2 - 2
AnKi/Resource/MeshBinaryLoader.cpp

@@ -227,7 +227,7 @@ Error MeshBinaryLoader::storeIndexBuffer(void* ptr, PtrSize size)
 	ANKI_ASSERT(size == getIndexBufferSize());
 	ANKI_ASSERT(size == getIndexBufferSize());
 
 
 	const PtrSize seek = sizeof(m_header) + m_subMeshes.getSizeInBytes();
 	const PtrSize seek = sizeof(m_header) + m_subMeshes.getSizeInBytes();
-	ANKI_CHECK(m_file->seek(seek, FileSeekOrigin::BEGINNING));
+	ANKI_CHECK(m_file->seek(seek, FileSeekOrigin::kBeginning));
 	ANKI_CHECK(m_file->read(ptr, size));
 	ANKI_CHECK(m_file->read(ptr, size));
 
 
 	return Error::kNone;
 	return Error::kNone;
@@ -246,7 +246,7 @@ Error MeshBinaryLoader::storeVertexBuffer(U32 bufferIdx, void* ptr, PtrSize size
 		seek += getAlignedVertexBufferSize(i);
 		seek += getAlignedVertexBufferSize(i);
 	}
 	}
 
 
-	ANKI_CHECK(m_file->seek(seek, FileSeekOrigin::BEGINNING));
+	ANKI_CHECK(m_file->seek(seek, FileSeekOrigin::kBeginning));
 	ANKI_CHECK(m_file->read(ptr, size));
 	ANKI_CHECK(m_file->read(ptr, size));
 
 
 	return Error::kNone;
 	return Error::kNone;

+ 1 - 1
AnKi/Resource/ResourceFilesystem.cpp

@@ -167,7 +167,7 @@ public:
 	Error seek(PtrSize offset, FileSeekOrigin origin) override
 	Error seek(PtrSize offset, FileSeekOrigin origin) override
 	{
 	{
 		// Rewind if needed
 		// Rewind if needed
-		if(origin == FileSeekOrigin::BEGINNING)
+		if(origin == FileSeekOrigin::kBeginning)
 		{
 		{
 			if(unzCloseCurrentFile(m_archive) || unzOpenCurrentFile(m_archive))
 			if(unzCloseCurrentFile(m_archive) || unzOpenCurrentFile(m_archive))
 			{
 			{

+ 4 - 5
AnKi/Ui/Canvas.cpp

@@ -59,8 +59,7 @@ Error Canvas::init(FontPtr font, U32 fontHeight, U32 width, U32 height)
 	m_nearestNearestRepeatSampler = m_manager->getGrManager().newSampler(samplerInit);
 	m_nearestNearestRepeatSampler = m_manager->getGrManager().newSampler(samplerInit);
 
 
 	// Allocator
 	// Allocator
-	m_stackAlloc = StackAllocator<U8>(getAllocator().getMemoryPool().getAllocationCallback(),
-									  getAllocator().getMemoryPool().getAllocationCallbackUserData(), 512_B);
+	m_tempPool.init(getMemoryPool().getAllocationCallback(), getMemoryPool().getAllocationCallbackUserData(), 512_B);
 
 
 	// Create the context
 	// Create the context
 	setImAllocator();
 	setImAllocator();
@@ -185,7 +184,7 @@ void Canvas::beginBuilding()
 
 
 void Canvas::pushFont(const FontPtr& font, U32 fontHeight)
 void Canvas::pushFont(const FontPtr& font, U32 fontHeight)
 {
 {
-	m_references.pushBack(m_stackAlloc, IntrusivePtr<UiObject>(const_cast<Font*>(font.get())));
+	m_references.pushBack(m_tempPool, IntrusivePtr<UiObject>(const_cast<Font*>(font.get())));
 	ImGui::PushFont(&font->getImFont(fontHeight));
 	ImGui::PushFont(&font->getImFont(fontHeight));
 }
 }
 
 
@@ -196,8 +195,8 @@ void Canvas::appendToCommandBuffer(CommandBufferPtr cmdb)
 	// Done
 	// Done
 	ImGui::SetCurrentContext(nullptr);
 	ImGui::SetCurrentContext(nullptr);
 
 
-	m_references.destroy(m_stackAlloc);
-	m_stackAlloc.getMemoryPool().reset();
+	m_references.destroy(m_tempPool);
+	m_tempPool.reset();
 }
 }
 
 
 void Canvas::appendToCommandBufferInternal(CommandBufferPtr& cmdb)
 void Canvas::appendToCommandBufferInternal(CommandBufferPtr& cmdb)

+ 1 - 1
AnKi/Ui/Canvas.h

@@ -85,7 +85,7 @@ private:
 	SamplerPtr m_linearLinearRepeatSampler;
 	SamplerPtr m_linearLinearRepeatSampler;
 	SamplerPtr m_nearestNearestRepeatSampler;
 	SamplerPtr m_nearestNearestRepeatSampler;
 
 
-	StackAllocator<U8> m_stackAlloc;
+	StackMemoryPool m_tempPool;
 
 
 	List<IntrusivePtr<UiObject>> m_references;
 	List<IntrusivePtr<UiObject>> m_references;
 
 

+ 0 - 2
AnKi/Ui/Common.h

@@ -26,8 +26,6 @@ class UiManager;
 #define ANKI_UI_LOGW(...) ANKI_LOG("UI", kWarning, __VA_ARGS__)
 #define ANKI_UI_LOGW(...) ANKI_LOG("UI", kWarning, __VA_ARGS__)
 #define ANKI_UI_LOGF(...) ANKI_LOG("UI", kFatal, __VA_ARGS__)
 #define ANKI_UI_LOGF(...) ANKI_LOG("UI", kFatal, __VA_ARGS__)
 
 
-using UiAllocator = HeapAllocator<U8>;
-
 #define ANKI_UI_OBJECT_FW(name_) \
 #define ANKI_UI_OBJECT_FW(name_) \
 	class name_; \
 	class name_; \
 	using name_##Ptr = IntrusivePtr<name_>;
 	using name_##Ptr = IntrusivePtr<name_>;

+ 4 - 4
AnKi/Ui/Font.cpp

@@ -20,8 +20,8 @@ Font::~Font()
 	m_imFontAtlas.destroy();
 	m_imFontAtlas.destroy();
 	unsetImAllocator();
 	unsetImAllocator();
 
 
-	m_fonts.destroy(getAllocator());
-	m_fontData.destroy(getAllocator());
+	m_fonts.destroy(getMemoryPool());
+	m_fontData.destroy(getMemoryPool());
 }
 }
 
 
 Error Font::init(const CString& filename, ConstWeakArray<U32> fontHeights)
 Error Font::init(const CString& filename, ConstWeakArray<U32> fontHeights)
@@ -32,10 +32,10 @@ Error Font::init(const CString& filename, ConstWeakArray<U32> fontHeights)
 	// Load font in memory
 	// Load font in memory
 	ResourceFilePtr file;
 	ResourceFilePtr file;
 	ANKI_CHECK(m_manager->getResourceManager().getFilesystem().openFile(filename, file));
 	ANKI_CHECK(m_manager->getResourceManager().getFilesystem().openFile(filename, file));
-	m_fontData.create(getAllocator(), U32(file->getSize()));
+	m_fontData.create(getMemoryPool(), U32(file->getSize()));
 	ANKI_CHECK(file->read(&m_fontData[0], file->getSize()));
 	ANKI_CHECK(file->read(&m_fontData[0], file->getSize()));
 
 
-	m_fonts.create(getAllocator(), U32(fontHeights.getSize()));
+	m_fonts.create(getMemoryPool(), U32(fontHeights.getSize()));
 
 
 	// Bake font
 	// Bake font
 	ImFontConfig cfg;
 	ImFontConfig cfg;

+ 1 - 1
AnKi/Ui/UiManager.cpp

@@ -25,7 +25,7 @@ Error UiManager::init(AllocAlignedCallback allocCallback, void* allocCallbackUse
 	ANKI_ASSERT(gpuMem);
 	ANKI_ASSERT(gpuMem);
 	ANKI_ASSERT(input);
 	ANKI_ASSERT(input);
 
 
-	m_alloc = UiAllocator(allocCallback, allocCallbackUserData);
+	m_pool.init(allocCallback, allocCallbackUserData);
 	m_resources = resources;
 	m_resources = resources;
 	m_gr = gr;
 	m_gr = gr;
 	m_gpuMem = gpuMem;
 	m_gpuMem = gpuMem;

+ 5 - 5
AnKi/Ui/UiManager.h

@@ -29,9 +29,9 @@ public:
 	Error init(AllocAlignedCallback allocCallback, void* allocCallbackUserData, ResourceManager* resources,
 	Error init(AllocAlignedCallback allocCallback, void* allocCallbackUserData, ResourceManager* resources,
 			   GrManager* gr, StagingGpuMemoryPool* gpuMem, Input* input);
 			   GrManager* gr, StagingGpuMemoryPool* gpuMem, Input* input);
 
 
-	UiAllocator getAllocator() const
+	HeapMemoryPool& getMemoryPool() const
 	{
 	{
-		return m_alloc;
+		return m_pool;
 	}
 	}
 
 
 	ResourceManager& getResourceManager()
 	ResourceManager& getResourceManager()
@@ -62,7 +62,7 @@ public:
 	template<typename T, typename Y, typename... Args>
 	template<typename T, typename Y, typename... Args>
 	Error newInstance(IntrusivePtr<Y>& ptr, Args&&... args)
 	Error newInstance(IntrusivePtr<Y>& ptr, Args&&... args)
 	{
 	{
-		T* p = m_alloc.newInstance<T>(this);
+		T* p = anki::newInstance<T>(m_pool, this);
 		ptr.reset(static_cast<Y*>(p));
 		ptr.reset(static_cast<Y*>(p));
 		return p->init(args...);
 		return p->init(args...);
 	}
 	}
@@ -71,12 +71,12 @@ public:
 	template<typename T, typename... Args>
 	template<typename T, typename... Args>
 	Error newInstance(IntrusivePtr<T>& ptr, Args&&... args)
 	Error newInstance(IntrusivePtr<T>& ptr, Args&&... args)
 	{
 	{
-		ptr.reset(m_alloc.newInstance<T>(this));
+		ptr.reset(anki::newInstance<T>(m_pool, this));
 		return ptr->init(args...);
 		return ptr->init(args...);
 	}
 	}
 
 
 private:
 private:
-	UiAllocator m_alloc;
+	mutable HeapMemoryPool m_pool;
 	ResourceManager* m_resources = nullptr;
 	ResourceManager* m_resources = nullptr;
 	GrManager* m_gr = nullptr;
 	GrManager* m_gr = nullptr;
 	StagingGpuMemoryPool* m_gpuMem = nullptr;
 	StagingGpuMemoryPool* m_gpuMem = nullptr;

+ 2 - 2
AnKi/Ui/UiObject.cpp

@@ -8,9 +8,9 @@
 
 
 namespace anki {
 namespace anki {
 
 
-UiAllocator UiObject::getAllocator() const
+HeapMemoryPool& UiObject::getMemoryPool() const
 {
 {
-	return m_manager->getAllocator();
+	return m_manager->getMemoryPool();
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 2 - 2
AnKi/Ui/UiObject.h

@@ -24,7 +24,7 @@ public:
 
 
 	virtual ~UiObject() = default;
 	virtual ~UiObject() = default;
 
 
-	UiAllocator getAllocator() const;
+	HeapMemoryPool& getMemoryPool() const;
 
 
 	void retain() const
 	void retain() const
 	{
 	{
@@ -39,7 +39,7 @@ public:
 	/// Set the global IMGUI allocator.
 	/// Set the global IMGUI allocator.
 	void setImAllocator(BaseMemoryPool* pool = nullptr)
 	void setImAllocator(BaseMemoryPool* pool = nullptr)
 	{
 	{
-		pool = (pool) ? pool : &getAllocator().getMemoryPool();
+		pool = (pool) ? pool : &getMemoryPool();
 
 
 		auto allocCallback = [](size_t size, void* userData) -> void* {
 		auto allocCallback = [](size_t size, void* userData) -> void* {
 			BaseMemoryPool* pool = static_cast<BaseMemoryPool*>(userData);
 			BaseMemoryPool* pool = static_cast<BaseMemoryPool*>(userData);

+ 3 - 3
AnKi/Util/File.h

@@ -33,9 +33,9 @@ ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(FileOpenFlag)
 /// @memberof File
 /// @memberof File
 enum class FileSeekOrigin
 enum class FileSeekOrigin
 {
 {
-	BEGINNING = SEEK_SET,
-	CURRENT = SEEK_CUR,
-	END = SEEK_END
+	kBeginning = SEEK_SET,
+	kCurrent = SEEK_CUR,
+	kEnd = SEEK_END
 };
 };
 
 
 /// An abstraction over typical files and files in ziped archives. This class can read from regular C files, zip files
 /// An abstraction over typical files and files in ziped archives. This class can read from regular C files, zip files

+ 1 - 1
AnKi/Util/Serializer.cpp

@@ -32,7 +32,7 @@ Error BinarySerializer::doDynamicArrayBasicType(const void* arr, PtrSize size, U
 		m_pointerFilePositions.emplaceBack(*m_pool, pinfo);
 		m_pointerFilePositions.emplaceBack(*m_pool, pinfo);
 
 
 		// Write the array
 		// Write the array
-		ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::BEGINNING));
+		ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::kBeginning));
 		ANKI_CHECK(m_file->write(arr, size));
 		ANKI_CHECK(m_file->write(arr, size));
 	}
 	}
 
 

+ 5 - 5
AnKi/Util/Serializer.inl.h

@@ -59,7 +59,7 @@ Error BinarySerializer::serializeInternal(const T& x, BaseMemoryPool& tmpPool, F
 	DynamicArrayRaii<PtrSize> pointerFilePositions(&tmpPool);
 	DynamicArrayRaii<PtrSize> pointerFilePositions(&tmpPool);
 	for(const PointerInfo& pointer : m_pointerFilePositions)
 	for(const PointerInfo& pointer : m_pointerFilePositions)
 	{
 	{
-		ANKI_CHECK(m_file->seek(pointer.m_filePos, FileSeekOrigin::BEGINNING));
+		ANKI_CHECK(m_file->seek(pointer.m_filePos, FileSeekOrigin::kBeginning));
 		ANKI_CHECK(m_file->write(&pointer.m_value, sizeof(pointer.m_value)));
 		ANKI_CHECK(m_file->write(&pointer.m_value, sizeof(pointer.m_value)));
 
 
 		const PtrSize offsetAfterHeader = pointer.m_filePos - m_beginOfDataFilePos;
 		const PtrSize offsetAfterHeader = pointer.m_filePos - m_beginOfDataFilePos;
@@ -70,7 +70,7 @@ Error BinarySerializer::serializeInternal(const T& x, BaseMemoryPool& tmpPool, F
 	// Write the pointer offsets
 	// Write the pointer offsets
 	if(pointerFilePositions.getSize() > 0)
 	if(pointerFilePositions.getSize() > 0)
 	{
 	{
-		ANKI_CHECK(m_file->seek(m_eofPos, FileSeekOrigin::BEGINNING));
+		ANKI_CHECK(m_file->seek(m_eofPos, FileSeekOrigin::kBeginning));
 		ANKI_CHECK(m_file->write(&pointerFilePositions[0], pointerFilePositions.getSizeInBytes()));
 		ANKI_CHECK(m_file->write(&pointerFilePositions[0], pointerFilePositions.getSizeInBytes()));
 		header.m_pointerCount = pointerFilePositions.getSize();
 		header.m_pointerCount = pointerFilePositions.getSize();
 		header.m_pointerArrayFilePosition = m_eofPos;
 		header.m_pointerArrayFilePosition = m_eofPos;
@@ -79,7 +79,7 @@ Error BinarySerializer::serializeInternal(const T& x, BaseMemoryPool& tmpPool, F
 	// Write the header
 	// Write the header
 	memcpy(&header.m_magic[0], detail::kBinarySerializerMagic, sizeof(header.m_magic));
 	memcpy(&header.m_magic[0], detail::kBinarySerializerMagic, sizeof(header.m_magic));
 	header.m_dataSize = m_eofPos - dataFilePos;
 	header.m_dataSize = m_eofPos - dataFilePos;
-	ANKI_CHECK(m_file->seek(headerFilePos, FileSeekOrigin::BEGINNING));
+	ANKI_CHECK(m_file->seek(headerFilePos, FileSeekOrigin::kBeginning));
 	ANKI_CHECK(m_file->write(&header, sizeof(header)));
 	ANKI_CHECK(m_file->write(&header, sizeof(header)));
 
 
 	// Done
 	// Done
@@ -142,7 +142,7 @@ Error BinarySerializer::doDynamicArrayComplexType(const T* arr, PtrSize size, Pt
 		m_pointerFilePositions.emplaceBack(*m_pool, pinfo);
 		m_pointerFilePositions.emplaceBack(*m_pool, pinfo);
 
 
 		// Write the structures
 		// Write the structures
-		ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::BEGINNING));
+		ANKI_CHECK(m_file->seek(arrayFilePos, FileSeekOrigin::kBeginning));
 		ANKI_CHECK(m_file->write(&arr[0], sizeof(T) * size));
 		ANKI_CHECK(m_file->write(&arr[0], sizeof(T) * size));
 
 
 		// Basically serialize pointers
 		// Basically serialize pointers
@@ -201,7 +201,7 @@ Error BinaryDeserializer::deserialize(T*& x, BaseMemoryPool& pool, TFile& file)
 	// Fix pointers
 	// Fix pointers
 	if(header.m_pointerCount)
 	if(header.m_pointerCount)
 	{
 	{
-		ANKI_CHECK(file.seek(header.m_pointerArrayFilePosition, FileSeekOrigin::BEGINNING));
+		ANKI_CHECK(file.seek(header.m_pointerArrayFilePosition, FileSeekOrigin::kBeginning));
 		for(PtrSize i = 0; i < header.m_pointerCount; ++i)
 		for(PtrSize i = 0; i < header.m_pointerCount; ++i)
 		{
 		{
 			// Read the location of the pointer
 			// Read the location of the pointer