Browse Source

Some bug fixes

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
3f6f147742

+ 4 - 2
AnKi/Gr/Vulkan/MicroObjectRecycler.h

@@ -47,7 +47,8 @@ public:
 	void recycle(T* s);
 	void recycle(T* s);
 
 
 	/// Destroy those objects that their fence is done. It's thread-safe.
 	/// Destroy those objects that their fence is done. It's thread-safe.
-	void trimCache();
+	/// @param objectsToNotDestroy The number of objects to keep alive for future recycling.
+	void trimCache(U32 objectsToNotDestroy = 0);
 
 
 private:
 private:
 	GrAllocator<U8> m_alloc;
 	GrAllocator<U8> m_alloc;
@@ -57,7 +58,8 @@ private:
 	U32 m_createdAndNotRecycled = 0;
 	U32 m_createdAndNotRecycled = 0;
 #endif
 #endif
 
 
-	void releaseFences();
+	/// @return The number of objects that could be deleted.
+	U32 releaseFences();
 };
 };
 /// @}
 /// @}
 
 

+ 9 - 4
AnKi/Gr/Vulkan/MicroObjectRecycler.inl.h

@@ -30,16 +30,20 @@ inline void MicroObjectRecycler<T>::destroy()
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline void MicroObjectRecycler<T>::releaseFences()
+inline U32 MicroObjectRecycler<T>::releaseFences()
 {
 {
+	U32 objectsThatCanBeDestroyed = 0;
 	for(U32 i = 0; i < m_objects.getSize(); ++i)
 	for(U32 i = 0; i < m_objects.getSize(); ++i)
 	{
 	{
 		T& obj = *m_objects[i];
 		T& obj = *m_objects[i];
 		if(obj.getFence() && obj.getFence()->done())
 		if(obj.getFence() && obj.getFence()->done())
 		{
 		{
 			obj.getFence().reset(nullptr);
 			obj.getFence().reset(nullptr);
+			++objectsThatCanBeDestroyed;
 		}
 		}
 	}
 	}
+
+	return objectsThatCanBeDestroyed;
 }
 }
 
 
 template<typename T>
 template<typename T>
@@ -90,11 +94,11 @@ inline void MicroObjectRecycler<T>::recycle(T* s)
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline void MicroObjectRecycler<T>::trimCache()
+inline void MicroObjectRecycler<T>::trimCache(U32 objectsToNotDestroy)
 {
 {
 	LockGuard<Mutex> lock(m_mtx);
 	LockGuard<Mutex> lock(m_mtx);
 
 
-	releaseFences();
+	U32 objectsThatCoultBeDeletedCount = releaseFences();
 
 
 	DynamicArray<T*> aliveObjects;
 	DynamicArray<T*> aliveObjects;
 
 
@@ -104,7 +108,7 @@ inline void MicroObjectRecycler<T>::trimCache()
 		ANKI_ASSERT(obj);
 		ANKI_ASSERT(obj);
 		ANKI_ASSERT(obj->getRefcount().getNonAtomically() == 0);
 		ANKI_ASSERT(obj->getRefcount().getNonAtomically() == 0);
 
 
-		if(obj->getFence())
+		if(obj->getFence() || objectsThatCoultBeDeletedCount <= objectsToNotDestroy)
 		{
 		{
 			// Can't delete it
 			// Can't delete it
 			aliveObjects.emplaceBack(m_alloc, obj);
 			aliveObjects.emplaceBack(m_alloc, obj);
@@ -113,6 +117,7 @@ inline void MicroObjectRecycler<T>::trimCache()
 		{
 		{
 			auto alloc = obj->getAllocator();
 			auto alloc = obj->getAllocator();
 			alloc.deleteInstance(obj);
 			alloc.deleteInstance(obj);
+			--objectsThatCoultBeDeletedCount;
 #if ANKI_EXTRA_CHECKS
 #if ANKI_EXTRA_CHECKS
 			--m_createdAndNotRecycled;
 			--m_createdAndNotRecycled;
 #endif
 #endif

+ 2 - 0
AnKi/Resource/MaterialResource.cpp

@@ -89,6 +89,8 @@ MaterialResource::~MaterialResource()
 
 
 	m_vars.destroy(getAllocator());
 	m_vars.destroy(getAllocator());
 	m_programs.destroy(getAllocator());
 	m_programs.destroy(getAllocator());
+
+	getAllocator().deallocate(m_prefilledLocalUniforms, 0);
 }
 }
 
 
 const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name) const
 const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name) const

+ 1 - 1
AnKi/Resource/ResourceManager.cpp

@@ -48,7 +48,7 @@ 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);
+	m_alloc = ResourceAllocator<U8>(init.m_allocCallback, init.m_allocCallbackData, "Resources");
 
 
 	m_tmpAlloc = TempResourceAllocator<U8>(init.m_allocCallback, init.m_allocCallbackData, 10_MB);
 	m_tmpAlloc = TempResourceAllocator<U8>(init.m_allocCallback, init.m_allocCallbackData, 10_MB);
 
 

+ 4 - 4
AnKi/ShaderCompiler/ShaderProgramDump.cpp

@@ -187,14 +187,14 @@ void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringAuto& huma
 		StringAuto newGlsl(alloc);
 		StringAuto newGlsl(alloc);
 		sourceLines.join("\n" ANKI_TAB ANKI_TAB, newGlsl);
 		sourceLines.join("\n" ANKI_TAB ANKI_TAB, newGlsl);
 
 
-		lines.pushBackSprintf(ANKI_TAB "#%u \n" ANKI_TAB ANKI_TAB "%s\n", count++, newGlsl.cstr());
+		lines.pushBackSprintf(ANKI_TAB "#bin%05u \n" ANKI_TAB ANKI_TAB "%s\n", count++, newGlsl.cstr());
 	}
 	}
 
 
 	lines.pushBack("\n**SHADER VARIANTS**\n");
 	lines.pushBack("\n**SHADER VARIANTS**\n");
 	count = 0;
 	count = 0;
 	for(const ShaderProgramBinaryVariant& variant : binary.m_variants)
 	for(const ShaderProgramBinaryVariant& variant : binary.m_variants)
 	{
 	{
-		lines.pushBackSprintf(ANKI_TAB "#%u\n", count++);
+		lines.pushBackSprintf(ANKI_TAB "#var%05u\n", count++);
 
 
 		// Uniform blocks
 		// Uniform blocks
 		if(variant.m_uniformBlocks.getSize() > 0)
 		if(variant.m_uniformBlocks.getSize() > 0)
@@ -274,7 +274,7 @@ void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringAuto& huma
 		{
 		{
 			if(variant.m_codeBlockIndices[shaderType] < MAX_U32)
 			if(variant.m_codeBlockIndices[shaderType] < MAX_U32)
 			{
 			{
-				lines.pushBackSprintf("%u", variant.m_codeBlockIndices[shaderType]);
+				lines.pushBackSprintf("#bin%05u", variant.m_codeBlockIndices[shaderType]);
 			}
 			}
 			else
 			else
 			{
 			{
@@ -294,7 +294,7 @@ void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringAuto& huma
 	count = 0;
 	count = 0;
 	for(const ShaderProgramBinaryMutation& mutation : binary.m_mutations)
 	for(const ShaderProgramBinaryMutation& mutation : binary.m_mutations)
 	{
 	{
-		lines.pushBackSprintf(ANKI_TAB "#%-4u variantIndex %5u values (", count++, mutation.m_variantIndex);
+		lines.pushBackSprintf(ANKI_TAB "#mut%-4u variantIndex #var%05u values (", count++, mutation.m_variantIndex);
 		if(mutation.m_values.getSize() > 0)
 		if(mutation.m_values.getSize() > 0)
 		{
 		{
 			for(U32 i = 0; i < mutation.m_values.getSize(); ++i)
 			for(U32 i = 0; i < mutation.m_values.getSize(); ++i)

+ 2 - 2
AnKi/Util/Memory.cpp

@@ -174,7 +174,7 @@ HeapMemoryPool::~HeapMemoryPool()
 	const U32 count = m_allocationCount.load();
 	const U32 count = m_allocationCount.load();
 	if(count != 0)
 	if(count != 0)
 	{
 	{
-		ANKI_UTIL_LOGW("Memory pool destroyed before all memory being released (%u deallocations missed): %s", count,
+		ANKI_UTIL_LOGE("Memory pool destroyed before all memory being released (%u deallocations missed): %s", count,
 					   getName());
 					   getName());
 	}
 	}
 }
 }
@@ -351,7 +351,7 @@ ChainMemoryPool::~ChainMemoryPool()
 {
 {
 	if(m_allocationCount.load() != 0)
 	if(m_allocationCount.load() != 0)
 	{
 	{
-		ANKI_UTIL_LOGW("Memory pool destroyed before all memory being released");
+		ANKI_UTIL_LOGE("Memory pool destroyed before all memory being released");
 	}
 	}
 
 
 	Chunk* ch = m_headChunk;
 	Chunk* ch = m_headChunk;