Explorar o código

Importer changes

Panagiotis Christopoulos Charitos %!s(int64=2) %!d(string=hai) anos
pai
achega
7711f076cf

+ 14 - 12
AnKi/Importer/Common.h

@@ -3,6 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma once
+
 #include <AnKi/Util/Logger.h>
 #include <AnKi/Util/MemoryPool.h>
 #include <AnKi/Util/HashMap.h>
@@ -18,21 +20,21 @@ namespace anki {
 #define ANKI_IMPORTER_LOGW(...) ANKI_LOG("IMPR", kWarning, __VA_ARGS__)
 #define ANKI_IMPORTER_LOGF(...) ANKI_LOG("IMPR", kFatal, __VA_ARGS__)
 
-using ImporterString = BaseString<MemoryPoolPtrWrapper<BaseMemoryPool>>;
-using ImporterStringList = BaseStringList<MemoryPoolPtrWrapper<BaseMemoryPool>>;
-
-template<typename TKey, typename TValue>
-using ImporterHashMap = HashMap<TKey, TValue, DefaultHasher<TKey>, MemoryPoolPtrWrapper<BaseMemoryPool>>;
-
-template<typename T>
-using ImporterDynamicArray = DynamicArray<T, MemoryPoolPtrWrapper<BaseMemoryPool>, U32>;
+class ImporterMemoryPool : public HeapMemoryPool, public MakeSingleton<ImporterMemoryPool>
+{
+	template<typename>
+	friend class MakeSingleton;
 
-template<typename T>
-using ImporterDynamicArrayLarge = DynamicArray<T, MemoryPoolPtrWrapper<BaseMemoryPool>, PtrSize>;
+private:
+	ImporterMemoryPool(AllocAlignedCallback allocCb, void* allocCbUserData)
+		: HeapMemoryPool(allocCb, allocCbUserData, "ImporterMemPool")
+	{
+	}
 
-template<typename T>
-using ImporterList = List<T, MemoryPoolPtrWrapper<BaseMemoryPool>>;
+	~ImporterMemoryPool() = default;
+};
 
+ANKI_DEFINE_SUBMODULE_UTIL_CONTAINERS(Importer, ImporterMemoryPool)
 /// @}
 
 } // end namespace anki

+ 98 - 71
AnKi/Importer/GltfImporter.cpp

@@ -149,8 +149,7 @@ static Bool stringsExist(const ImporterHashMap<CString, ImporterString>& map, co
 	return false;
 }
 
-GltfImporter::GltfImporter(BaseMemoryPool* pool)
-	: m_pool(pool)
+GltfImporter::GltfImporter()
 {
 }
 
@@ -162,7 +161,7 @@ GltfImporter::~GltfImporter()
 		m_gltf = nullptr;
 	}
 
-	deleteInstance(*m_pool, m_jobManager);
+	deleteInstance(ImporterMemoryPool::getSingleton(), m_jobManager);
 }
 
 Error GltfImporter::init(const GltfImporterInitInfo& initInfo)
@@ -211,7 +210,7 @@ Error GltfImporter::init(const GltfImporterInitInfo& initInfo)
 	if(initInfo.m_threadCount > 0)
 	{
 		const U32 threadCount = min(getCpuCoresCount(), initInfo.m_threadCount);
-		m_jobManager = newInstance<ThreadJobManager>(*m_pool, threadCount, true);
+		m_jobManager = newInstance<ThreadJobManager>(ImporterMemoryPool::getSingleton(), threadCount, true);
 	}
 
 	m_importTextures = initInfo.m_importTextures;
@@ -223,7 +222,7 @@ Error GltfImporter::writeAll()
 {
 	populateNodePtrToIdx();
 
-	ImporterString sceneFname(m_pool);
+	ImporterString sceneFname;
 	sceneFname.sprintf("%sScene.lua", m_outDir.cstr());
 	ANKI_CHECK(m_sceneFile.open(sceneFname.toCString(), FileOpenFlag::kWrite));
 	ANKI_CHECK(m_sceneFile.writeTextf("-- Generated by: %s\n", m_comment.cstr()));
@@ -234,7 +233,7 @@ Error GltfImporter::writeAll()
 	{
 		for(cgltf_node* const* node = scene->nodes; node < scene->nodes + scene->nodes_count; ++node)
 		{
-			ANKI_CHECK(visitNode(*(*node), Transform::getIdentity(), ImporterHashMap<CString, ImporterString>(m_pool)));
+			ANKI_CHECK(visitNode(*(*node), Transform::getIdentity(), ImporterHashMap<CString, ImporterString>()));
 		}
 	}
 
@@ -357,7 +356,7 @@ Error GltfImporter::writeAll()
 	return Error::kNone;
 }
 
-Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CString, ImporterString>& out) const
+Error GltfImporter::appendExtras(const cgltf_extras& extras, ImporterHashMap<CString, ImporterString>& out) const
 {
 	cgltf_size extrasSize;
 	cgltf_copy_extras_json(m_gltf, &extras, nullptr, &extrasSize);
@@ -366,7 +365,7 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CStrin
 		return Error::kNone;
 	}
 
-	ImporterDynamicArrayLarge<char> json(m_pool);
+	ImporterDynamicArrayLarge<char> json;
 	json.resize(extrasSize + 1);
 	cgltf_result res = cgltf_copy_extras_json(m_gltf, &extras, &json[0], &extrasSize);
 	if(res != cgltf_result_success)
@@ -387,14 +386,14 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CStrin
 		return Error::kNone;
 	}
 
-	ImporterDynamicArray<jsmntok_t> tokens(m_pool);
+	ImporterDynamicArray<jsmntok_t> tokens;
 	tokens.resize(U32(tokenCount));
 
 	// Get tokens
 	jsmn_init(&parser);
 	jsmn_parse(&parser, jsonTxt.cstr(), jsonTxt.getLength(), &tokens[0], tokens.getSize());
 
-	ImporterStringList tokenStrings(m_pool);
+	ImporterStringList tokenStrings;
 	for(const jsmntok_t& token : tokens)
 	{
 		if(token.type != JSMN_STRING && token.type != JSMN_PRIMITIVE)
@@ -402,14 +401,14 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CStrin
 			continue;
 		}
 
-		ImporterString tokenStr(&jsonTxt[token.start], &jsonTxt[token.end], m_pool);
+		ImporterString tokenStr(&jsonTxt[token.start], &jsonTxt[token.end]);
 		tokenStrings.pushBack(tokenStr.toCString());
 	}
 
 	if((tokenStrings.getSize() % 2) != 0)
 	{
-		ANKI_IMPORTER_LOGE("Unable to parse: %s", jsonTxt.cstr());
-		return Error::kFunctionFailed;
+		ANKI_IMPORTER_LOGV("Ignoring: %s", jsonTxt.cstr());
+		return Error::kNone;
 	}
 
 	// Write them to the map
@@ -419,7 +418,7 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CStrin
 		auto it2 = it;
 		++it2;
 
-		out.emplace(it->toCString(), ImporterString(it2->toCString(), m_pool));
+		out.emplace(it->toCString(), ImporterString(it2->toCString()));
 		++it;
 		++it;
 	}
@@ -427,6 +426,15 @@ Error GltfImporter::getExtras(const cgltf_extras& extras, ImporterHashMap<CStrin
 	return Error::kNone;
 }
 
+static void appendExtrasMap(const ImporterHashMap<CString, ImporterString>& in, ImporterHashMap<CString, ImporterString>& out)
+{
+	auto& outs = out.getSparseArray();
+	for(auto it = in.getBegin(); it != in.getEnd(); ++it)
+	{
+		outs.emplace(it.getKey(), *it);
+	}
+}
+
 void GltfImporter::populateNodePtrToIdxInternal(const cgltf_node& node, U32& idx)
 {
 	m_nodePtrToIdx.emplace(&node, idx++);
@@ -452,7 +460,7 @@ void GltfImporter::populateNodePtrToIdx()
 
 ImporterString GltfImporter::getNodeName(const cgltf_node& node) const
 {
-	ImporterString out(m_pool);
+	ImporterString out;
 
 	if(node.name)
 	{
@@ -470,7 +478,7 @@ ImporterString GltfImporter::getNodeName(const cgltf_node& node) const
 
 Error GltfImporter::parseArrayOfNumbers(CString str, ImporterDynamicArray<F64>& out, const U32* expectedArraySize)
 {
-	ImporterStringList list(m_pool);
+	ImporterStringList list;
 	list.splitString(str, ' ');
 
 	out.resize(U32(list.getSize()));
@@ -508,10 +516,15 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 		return threadErr;
 	}
 
-	ImporterHashMap<CString, ImporterString> outExtras(m_pool);
+	ImporterHashMap<CString, ImporterString> outExtras;
 	if(node.light)
 	{
-		ANKI_CHECK(writeLight(node, parentExtras));
+		ImporterHashMap<CString, ImporterString> extras;
+		ANKI_CHECK(appendExtras(node.light->extras, extras));
+		ANKI_CHECK(appendExtras(node.extras, extras));
+		appendExtrasMap(parentExtras, extras);
+
+		ANKI_CHECK(writeLight(node, extras));
 
 		Transform localTrf;
 		ANKI_CHECK(getNodeTransform(node, localTrf));
@@ -520,7 +533,12 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 	}
 	else if(node.camera)
 	{
-		ANKI_CHECK(writeCamera(node, parentExtras));
+		ImporterHashMap<CString, ImporterString> extras;
+		ANKI_CHECK(appendExtras(node.camera->extras, extras));
+		ANKI_CHECK(appendExtras(node.extras, extras));
+		appendExtrasMap(parentExtras, extras);
+
+		ANKI_CHECK(writeCamera(node, extras));
 
 		Transform localTrf;
 		ANKI_CHECK(getNodeTransform(node, localTrf));
@@ -530,9 +548,10 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 	else if(node.mesh)
 	{
 		// Handle special nodes
-		ImporterHashMap<CString, ImporterString> extras(parentExtras);
-		ANKI_CHECK(getExtras(node.mesh->extras, extras));
-		ANKI_CHECK(getExtras(node.extras, extras));
+		ImporterHashMap<CString, ImporterString> extras;
+		ANKI_CHECK(appendExtras(node.mesh->extras, extras));
+		ANKI_CHECK(appendExtras(node.extras, extras));
+		appendExtrasMap(parentExtras, extras);
 
 		ImporterHashMap<CString, ImporterString>::Iterator it;
 
@@ -568,7 +587,7 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 
 			if((it = extras.find("skybox_solid_color")) != extras.getEnd())
 			{
-				ImporterStringList tokens(m_pool);
+				ImporterStringList tokens;
 				tokens.splitString(*it, ' ');
 				if(tokens.getSize() != 3)
 				{
@@ -699,13 +718,13 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 		}
 		else if((it = extras.find("decal")) != extras.getEnd() && (*it == "true" || *it == "1"))
 		{
-			ImporterString diffuseAtlas(m_pool);
+			ImporterString diffuseAtlas;
 			if((it = extras.find("decal_diffuse_atlas")) != extras.getEnd())
 			{
 				diffuseAtlas = *it;
 			}
 
-			ImporterString diffuseSubtexture(m_pool);
+			ImporterString diffuseSubtexture;
 			if((it = extras.find("decal_diffuse_sub_texture")) != extras.getEnd())
 			{
 				diffuseSubtexture = *it;
@@ -717,13 +736,13 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 				ANKI_CHECK(it->toNumber(diffuseFactor));
 			}
 
-			ImporterString specularRougnessMetallicAtlas(m_pool);
+			ImporterString specularRougnessMetallicAtlas;
 			if((it = extras.find("decal_specular_roughness_metallic_atlas")) != extras.getEnd())
 			{
 				specularRougnessMetallicAtlas = *it;
 			}
 
-			ImporterString specularRougnessMetallicSubtexture(m_pool);
+			ImporterString specularRougnessMetallicSubtexture;
 			if((it = extras.find("decal_specular_roughness_metallic_sub_texture")) != extras.getEnd())
 			{
 				specularRougnessMetallicSubtexture = *it;
@@ -761,44 +780,52 @@ Error GltfImporter::visitNode(const cgltf_node& node, const Transform& parentTrf
 
 			const Bool skipRt = (it = extras.find("no_rt")) != extras.getEnd() && (*it == "true" || *it == "1");
 
-			addRequest<const cgltf_mesh*>(node.mesh, m_meshImportRequests);
-			for(U32 i = 0; i < node.mesh->primitives_count; ++i)
-			{
-				const MaterialImportRequest req = {node.mesh->primitives[i].material, !skipRt};
-				addRequest<MaterialImportRequest>(req, m_materialImportRequests);
-			}
+			Transform localTrf;
+			const Error err = getNodeTransform(node, localTrf);
 
-			if(node.skin)
+			if(err)
 			{
-				addRequest<const cgltf_skin*>(node.skin, m_skinImportRequests);
+				ANKI_IMPORTER_LOGE("Will skip node: %s", getNodeName(node).cstr());
 			}
+			else
+			{
+				addRequest<const cgltf_mesh*>(node.mesh, m_meshImportRequests);
+				for(U32 i = 0; i < node.mesh->primitives_count; ++i)
+				{
+					const MaterialImportRequest req = {node.mesh->primitives[i].material, !skipRt};
+					addRequest<MaterialImportRequest>(req, m_materialImportRequests);
+				}
 
-			addRequest<const cgltf_mesh*>(node.mesh, m_modelImportRequests);
+				if(node.skin)
+				{
+					addRequest<const cgltf_skin*>(node.skin, m_skinImportRequests);
+				}
 
-			ImporterHashMap<CString, ImporterString>::Iterator it2;
-			const Bool selfCollision = (it2 = extras.find("collision_mesh")) != extras.getEnd() && *it2 == "self";
+				addRequest<const cgltf_mesh*>(node.mesh, m_modelImportRequests);
 
-			ANKI_CHECK(writeModelNode(node, parentExtras));
+				ImporterHashMap<CString, ImporterString>::Iterator it2;
+				const Bool selfCollision = (it2 = extras.find("collision_mesh")) != extras.getEnd() && *it2 == "self";
 
-			Transform localTrf;
-			ANKI_CHECK(getNodeTransform(node, localTrf));
-			ANKI_CHECK(writeTransform(parentTrf.combineTransformations(localTrf)));
+				ANKI_CHECK(writeModelNode(node, parentExtras));
 
-			if(selfCollision)
-			{
-				ANKI_CHECK(m_sceneFile.writeText("comp = node:newBodyComponent()\n"));
+				ANKI_CHECK(writeTransform(parentTrf.combineTransformations(localTrf)));
 
-				const ImporterString meshFname = computeMeshResourceFilename(*node.mesh);
+				if(selfCollision)
+				{
+					ANKI_CHECK(m_sceneFile.writeText("comp = node:newBodyComponent()\n"));
+
+					const ImporterString meshFname = computeMeshResourceFilename(*node.mesh);
 
-				ANKI_CHECK(m_sceneFile.writeText("comp:setMeshFromModelComponent()\n"));
-				ANKI_CHECK(m_sceneFile.writeText("comp:teleportTo(trf)\n"));
+					ANKI_CHECK(m_sceneFile.writeText("comp:setMeshFromModelComponent()\n"));
+					ANKI_CHECK(m_sceneFile.writeText("comp:teleportTo(trf)\n"));
+				}
 			}
 		}
 	}
 	else
 	{
 		ANKI_IMPORTER_LOGV("Ignoring node %s. Assuming transform node", getNodeName(node).cstr());
-		ANKI_CHECK(getExtras(node.extras, outExtras));
+		ANKI_CHECK(appendExtras(node.extras, outExtras));
 	}
 
 	// Visit children
@@ -843,11 +870,11 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh) const
 	const ImporterString modelFname = computeModelResourceFilename(mesh);
 	ANKI_IMPORTER_LOGV("Importing model %s", modelFname.cstr());
 
-	ImporterHashMap<CString, ImporterString> extras(m_pool);
-	ANKI_CHECK(getExtras(mesh.extras, extras));
+	ImporterHashMap<CString, ImporterString> extras;
+	ANKI_CHECK(appendExtras(mesh.extras, extras));
 
 	File file;
-	ImporterString modelFullFname(m_pool);
+	ImporterString modelFullFname;
 	modelFullFname.sprintf("%s/%s", m_outDir.cstr(), modelFname.cstr());
 	ANKI_CHECK(file.open(modelFullFname, FileOpenFlag::kWrite));
 
@@ -868,8 +895,8 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh) const
 			ANKI_CHECK(file.writeTextf("\t\t\t<mesh subMeshIndex=\"%u\">%s%s</mesh>\n", primIdx, m_rpath.cstr(), meshFname.cstr()));
 		}
 
-		ImporterHashMap<CString, ImporterString> materialExtras(m_pool);
-		ANKI_CHECK(getExtras(mesh.primitives[primIdx].material->extras, materialExtras));
+		ImporterHashMap<CString, ImporterString> materialExtras;
+		ANKI_CHECK(appendExtras(mesh.primitives[primIdx].material->extras, materialExtras));
 		auto mtlOverride = materialExtras.find("material_override");
 		if(mtlOverride != materialExtras.getEnd())
 		{
@@ -893,12 +920,12 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh) const
 
 Error GltfImporter::writeSkeleton(const cgltf_skin& skin) const
 {
-	ImporterString fname(m_pool);
+	ImporterString fname;
 	fname.sprintf("%s%s", m_outDir.cstr(), computeSkeletonResourceFilename(skin).cstr());
 	ANKI_IMPORTER_LOGV("Importing skeleton %s", fname.cstr());
 
 	// Get matrices
-	ImporterDynamicArray<Mat4> boneMats(m_pool);
+	ImporterDynamicArray<Mat4> boneMats;
 	readAccessor(*skin.inverse_bind_matrices, boneMats);
 	if(boneMats.getSize() != skin.joints_count)
 	{
@@ -917,7 +944,7 @@ Error GltfImporter::writeSkeleton(const cgltf_skin& skin) const
 	{
 		const cgltf_node& boneNode = *skin.joints[i];
 
-		ImporterString parent(m_pool);
+		ImporterString parent;
 
 		// Name & parent
 		ANKI_CHECK(file.writeTextf("\t\t<bone name=\"%s\" ", getNodeName(boneNode).cstr()));
@@ -964,8 +991,8 @@ Error GltfImporter::writeLight(const cgltf_node& node, const ImporterHashMap<CSt
 	ANKI_IMPORTER_LOGV("Importing light %s", nodeName.cstr());
 
 	ImporterHashMap<CString, ImporterString> extras(parentExtras);
-	ANKI_CHECK(getExtras(light.extras, extras));
-	ANKI_CHECK(getExtras(node.extras, extras));
+	ANKI_CHECK(appendExtras(light.extras, extras));
+	ANKI_CHECK(appendExtras(node.extras, extras));
 
 	CString lightTypeStr;
 	switch(light.type)
@@ -1049,7 +1076,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const ImporterHashMap<CSt
 
 		if(lsSpriteSize != extras.getEnd())
 		{
-			ImporterDynamicArray<F64> numbers(m_pool);
+			ImporterDynamicArray<F64> numbers;
 			const U32 count = 2;
 			ANKI_CHECK(parseArrayOfNumbers(lsSpriteSize->toCString(), numbers, &count));
 
@@ -1058,7 +1085,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const ImporterHashMap<CSt
 
 		if(lsColor != extras.getEnd())
 		{
-			ImporterDynamicArray<F64> numbers(m_pool);
+			ImporterDynamicArray<F64> numbers;
 			const U32 count = 4;
 			ANKI_CHECK(parseArrayOfNumbers(lsColor->toCString(), numbers, &count));
 
@@ -1075,7 +1102,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const ImporterHashMap<CSt
 
 		if(lightEventIntensity != extras.getEnd())
 		{
-			ImporterDynamicArray<F64> numbers(m_pool);
+			ImporterDynamicArray<F64> numbers;
 			const U32 count = 4;
 			ANKI_CHECK(parseArrayOfNumbers(lightEventIntensity->toCString(), numbers, &count));
 			ANKI_CHECK(
@@ -1084,7 +1111,7 @@ Error GltfImporter::writeLight(const cgltf_node& node, const ImporterHashMap<CSt
 
 		if(lightEventFrequency != extras.getEnd())
 		{
-			ImporterDynamicArray<F64> numbers(m_pool);
+			ImporterDynamicArray<F64> numbers;
 			const U32 count = 2;
 			ANKI_CHECK(parseArrayOfNumbers(lightEventFrequency->toCString(), numbers, &count));
 			ANKI_CHECK(m_sceneFile.writeTextf("event:setFrequency(%f, %f)\n", numbers[0], numbers[1]));
@@ -1120,7 +1147,7 @@ Error GltfImporter::writeModelNode(const cgltf_node& node, const ImporterHashMap
 	ANKI_IMPORTER_LOGV("Importing model node %s", getNodeName(node).cstr());
 
 	ImporterHashMap<CString, ImporterString> extras(parentExtras);
-	ANKI_CHECK(getExtras(node.extras, extras));
+	ANKI_CHECK(appendExtras(node.extras, extras));
 
 	const ImporterString modelFname = computeModelResourceFilename(*node.mesh);
 
@@ -1138,7 +1165,7 @@ Error GltfImporter::writeModelNode(const cgltf_node& node, const ImporterHashMap
 
 ImporterString GltfImporter::computeModelResourceFilename(const cgltf_mesh& mesh) const
 {
-	ImporterStringList list(m_pool);
+	ImporterStringList list;
 
 	list.pushBack(mesh.name);
 
@@ -1148,12 +1175,12 @@ ImporterString GltfImporter::computeModelResourceFilename(const cgltf_mesh& mesh
 		list.pushBackSprintf("_%s", mtlName);
 	}
 
-	ImporterString joined(m_pool);
+	ImporterString joined;
 	list.join("", joined);
 
 	const U64 hash = computeHash(joined.getBegin(), joined.getLength());
 
-	ImporterString out(m_pool);
+	ImporterString out;
 	out.sprintf("%.64s_%" PRIx64 ".ankimdl", joined.cstr(), hash); // Limit the filename size
 
 	return out;
@@ -1162,7 +1189,7 @@ ImporterString GltfImporter::computeModelResourceFilename(const cgltf_mesh& mesh
 ImporterString GltfImporter::computeMeshResourceFilename(const cgltf_mesh& mesh) const
 {
 	const U64 hash = computeHash(mesh.name, strlen(mesh.name));
-	ImporterString out(m_pool);
+	ImporterString out;
 	out.sprintf("%.64s_%" PRIx64 ".ankimesh", mesh.name, hash); // Limit the filename size
 	return out;
 }
@@ -1171,7 +1198,7 @@ ImporterString GltfImporter::computeMaterialResourceFilename(const cgltf_materia
 {
 	const U64 hash = computeHash(mtl.name, strlen(mtl.name));
 
-	ImporterString out(m_pool);
+	ImporterString out;
 
 	out.sprintf("%.64s_%" PRIx64 ".ankimtl", mtl.name, hash); // Limit the filename size
 
@@ -1182,7 +1209,7 @@ ImporterString GltfImporter::computeAnimationResourceFilename(const cgltf_animat
 {
 	const U64 hash = computeHash(anim.name, strlen(anim.name));
 
-	ImporterString out(m_pool);
+	ImporterString out;
 
 	out.sprintf("%.64s_%" PRIx64 ".ankianim", anim.name, hash); // Limit the filename size
 
@@ -1193,7 +1220,7 @@ ImporterString GltfImporter::computeSkeletonResourceFilename(const cgltf_skin& s
 {
 	const U64 hash = computeHash(skin.name, strlen(skin.name));
 
-	ImporterString out(m_pool);
+	ImporterString out;
 
 	out.sprintf("%.64s_%" PRIx64 ".ankiskel", skin.name, hash); // Limit the filename size
 

+ 15 - 15
AnKi/Importer/GltfImporter.h

@@ -41,7 +41,7 @@ public:
 class GltfImporter
 {
 public:
-	GltfImporter(BaseMemoryPool* pool);
+	GltfImporter();
 
 	~GltfImporter();
 
@@ -51,12 +51,10 @@ public:
 
 private:
 	// Data
-	mutable BaseMemoryPool* m_pool = nullptr;
-
-	ImporterString m_inputFname = {m_pool};
-	ImporterString m_outDir = {m_pool};
-	ImporterString m_rpath = {m_pool};
-	ImporterString m_texrpath = {m_pool};
+	ImporterString m_inputFname;
+	ImporterString m_outDir;
+	ImporterString m_rpath;
+	ImporterString m_texrpath;
 
 	cgltf_data* m_gltf = nullptr;
 
@@ -68,14 +66,14 @@ private:
 
 	mutable Atomic<I32> m_errorInThread = {0};
 
-	ImporterHashMap<const void*, U32> m_nodePtrToIdx = {m_pool}; ///< Need an index for the unnamed nodes.
+	ImporterHashMap<const void*, U32> m_nodePtrToIdx; ///< Need an index for the unnamed nodes.
 
 	F32 m_lodFactor = 1.0f;
 	U32 m_lodCount = 1;
 	F32 m_lightIntensityScale = 1.0f;
 	Bool m_optimizeMeshes = false;
 	Bool m_optimizeAnimations = false;
-	ImporterString m_comment = {m_pool};
+	ImporterString m_comment;
 
 	/// Don't generate LODs for meshes with less vertices than this number.
 	U32 m_skipLodVertexCountThreshold = 256;
@@ -102,10 +100,10 @@ private:
 		}
 	};
 
-	ImporterDynamicArray<ImportRequest<const cgltf_mesh*>> m_meshImportRequests = {m_pool};
-	ImporterDynamicArray<ImportRequest<MaterialImportRequest>> m_materialImportRequests = {m_pool};
-	ImporterDynamicArray<ImportRequest<const cgltf_skin*>> m_skinImportRequests = {m_pool};
-	ImporterDynamicArray<ImportRequest<const cgltf_mesh*>> m_modelImportRequests = {m_pool};
+	ImporterDynamicArray<ImportRequest<const cgltf_mesh*>> m_meshImportRequests;
+	ImporterDynamicArray<ImportRequest<MaterialImportRequest>> m_materialImportRequests;
+	ImporterDynamicArray<ImportRequest<const cgltf_skin*>> m_skinImportRequests;
+	ImporterDynamicArray<ImportRequest<const cgltf_mesh*>> m_modelImportRequests;
 
 	// Misc
 	template<typename T>
@@ -129,7 +127,7 @@ private:
 		}
 	}
 
-	Error getExtras(const cgltf_extras& extras, ImporterHashMap<CString, ImporterString>& out) const;
+	Error appendExtras(const cgltf_extras& extras, ImporterHashMap<CString, ImporterString>& out) const;
 	Error parseArrayOfNumbers(CString str, ImporterDynamicArray<F64>& out, const U32* expectedArraySize = nullptr);
 	void populateNodePtrToIdx();
 	void populateNodePtrToIdxInternal(const cgltf_node& node, U32& idx);
@@ -148,7 +146,7 @@ private:
 
 	ImporterString fixFilename(CString in) const
 	{
-		ImporterString out(in, m_pool);
+		ImporterString out = in;
 		out.replaceAll("|", "_");
 		out.replaceAll(" ", "_");
 		return out;
@@ -176,7 +174,9 @@ private:
 
 	// Resources
 	Error writeMesh(const cgltf_mesh& mesh) const;
+	Error writeMeshInternal(const cgltf_mesh& mesh) const;
 	Error writeMaterial(const cgltf_material& mtl, Bool writeRayTracing) const;
+	Error writeMaterialInternal(const cgltf_material& mtl, Bool writeRayTracing) const;
 	Error writeModel(const cgltf_mesh& mesh) const;
 	Error writeAnimation(const cgltf_animation& anim);
 	Error writeSkeleton(const cgltf_skin& skin) const;

+ 11 - 19
AnKi/Importer/GltfImporterAnimation.cpp

@@ -24,14 +24,6 @@ public:
 	ImporterDynamicArray<GltfAnimKey<Quat>> m_rotations;
 	ImporterDynamicArray<GltfAnimKey<F32>> m_scales;
 	const cgltf_node* m_targetNode;
-
-	GltfAnimChannel(BaseMemoryPool* pool)
-		: m_name(pool)
-		, m_positions(pool)
-		, m_rotations(pool)
-		, m_scales(pool)
-	{
-	}
 };
 
 /// Optimize out same animation keys.
@@ -48,7 +40,7 @@ static void optimizeChannel(ImporterDynamicArray<GltfAnimKey<T>>& arr, const T&
 			break;
 		}
 
-		ImporterDynamicArray<GltfAnimKey<T>> newArr(&arr.getMemoryPool());
+		ImporterDynamicArray<GltfAnimKey<T>> newArr;
 		U32 it = 0;
 		while(true)
 		{
@@ -115,14 +107,14 @@ static void optimizeChannel(ImporterDynamicArray<GltfAnimKey<T>>& arr, const T&
 
 Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 {
-	ImporterString fname(m_pool);
+	ImporterString fname;
 	ImporterString animFname = computeAnimationResourceFilename(anim);
 	fname.sprintf("%s%s", m_outDir.cstr(), animFname.cstr());
 	fname = fixFilename(fname);
 	ANKI_IMPORTER_LOGV("Importing animation %s", fname.cstr());
 
 	// Gather the channels
-	ImporterHashMap<CString, Array<const cgltf_animation_channel*, 3>> channelMap(m_pool);
+	ImporterHashMap<CString, Array<const cgltf_animation_channel*, 3>> channelMap;
 	U32 channelCount = 0;
 	for(U i = 0; i < anim.channels_count; ++i)
 	{
@@ -161,8 +153,8 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 	}
 
 	// Gather the keys
-	ImporterDynamicArray<GltfAnimChannel> tempChannels(m_pool);
-	tempChannels.resize(channelCount, m_pool);
+	ImporterDynamicArray<GltfAnimChannel> tempChannels;
+	tempChannels.resize(channelCount);
 	channelCount = 0;
 	for(auto it = channelMap.getBegin(); it != channelMap.getEnd(); ++it)
 	{
@@ -177,9 +169,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[0])
 		{
 			const cgltf_animation_channel& channel = *arr[0];
-			ImporterDynamicArray<F32> keys(m_pool);
+			ImporterDynamicArray<F32> keys;
 			readAccessor(*channel.sampler->input, keys);
-			ImporterDynamicArray<Vec3> positions(m_pool);
+			ImporterDynamicArray<Vec3> positions;
 			readAccessor(*channel.sampler->output, positions);
 			if(keys.getSize() != positions.getSize())
 			{
@@ -201,9 +193,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[1])
 		{
 			const cgltf_animation_channel& channel = *arr[1];
-			ImporterDynamicArray<F32> keys(m_pool);
+			ImporterDynamicArray<F32> keys;
 			readAccessor(*channel.sampler->input, keys);
-			ImporterDynamicArray<Quat> rotations(m_pool);
+			ImporterDynamicArray<Quat> rotations;
 			readAccessor(*channel.sampler->output, rotations);
 			if(keys.getSize() != rotations.getSize())
 			{
@@ -225,9 +217,9 @@ Error GltfImporter::writeAnimation(const cgltf_animation& anim)
 		if(arr[2])
 		{
 			const cgltf_animation_channel& channel = *arr[2];
-			ImporterDynamicArray<F32> keys(m_pool);
+			ImporterDynamicArray<F32> keys;
 			readAccessor(*channel.sampler->input, keys);
-			ImporterDynamicArray<Vec3> scales(m_pool);
+			ImporterDynamicArray<Vec3> scales;
 			readAccessor(*channel.sampler->output, scales);
 			if(keys.getSize() != scales.getSize())
 			{

+ 56 - 46
AnKi/Importer/GltfImporterMaterial.cpp

@@ -52,18 +52,20 @@ inline constexpr const Char* kRtMaterialTemplate = R"(
 		</shaderProgram>
 )";
 
-static CString getTextureUri(const cgltf_texture_view& view)
+static ImporterString getTextureUri(const cgltf_texture_view& view)
 {
 	ANKI_ASSERT(view.texture);
 	ANKI_ASSERT(view.texture->image);
 	ANKI_ASSERT(view.texture->image->uri);
-	return view.texture->image->uri;
+	ImporterString out = view.texture->image->uri;
+	out.replaceAll("%20", " ");
+	return out;
 }
 
 /// Read the texture and find out if
-static Error findConstantColorsInImage(CString fname, Vec4& constantColor, BaseMemoryPool& pool)
+static Error findConstantColorsInImage(CString fname, Vec4& constantColor)
 {
-	ImageLoader iloader(&pool);
+	ImageLoader iloader(&ImporterMemoryPool::getSingleton());
 	ANKI_CHECK(iloader.load(fname));
 	ANKI_ASSERT(iloader.getColorFormat() == ImageBinaryColorFormat::kRgba8);
 	ANKI_ASSERT(iloader.getCompression() == ImageBinaryDataCompression::kRaw);
@@ -100,12 +102,10 @@ static Error findConstantColorsInImage(CString fname, Vec4& constantColor, BaseM
 	return Error::kNone;
 }
 
-static Error importImage(BaseMemoryPool& pool, CString in, CString out, Bool alpha)
+static Error importImage(CString in, CString out, Bool alpha)
 {
 	ImageImporterConfig config;
 
-	config.m_pool = &pool;
-
 	Array<CString, 1> inputFnames = {in};
 	config.m_inputFilenames = inputFnames;
 
@@ -150,7 +150,18 @@ static void fixImageUri(ImporterString& uri)
 
 Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracing) const
 {
-	ImporterString fname(m_pool);
+	const Error err = writeMaterialInternal(mtl, writeRayTracing);
+	if(err)
+	{
+		ANKI_IMPORTER_LOGE("Failed to import material: %s", mtl.name);
+	}
+
+	return err;
+}
+
+Error GltfImporter::writeMaterialInternal(const cgltf_material& mtl, Bool writeRayTracing) const
+{
+	ImporterString fname;
 	fname.sprintf("%s%s", m_outDir.cstr(), computeMaterialResourceFilename(mtl).cstr());
 	ANKI_IMPORTER_LOGV("Importing material %s", fname.cstr());
 
@@ -160,10 +171,10 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		return Error::kUserData;
 	}
 
-	ImporterHashMap<CString, ImporterString> extras(m_pool);
-	ANKI_CHECK(getExtras(mtl.extras, extras));
+	ImporterHashMap<CString, ImporterString> extras;
+	ANKI_CHECK(appendExtras(mtl.extras, extras));
 
-	ImporterString xml(m_pool);
+	ImporterString xml;
 	xml += XmlDocument<MemoryPoolPtrWrapper<BaseMemoryPool>>::kXmlHeader;
 	xml += "\n";
 	xml += kMaterialTemplate;
@@ -177,16 +188,16 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	Bool alphaTested = false;
 	if(mtl.pbr_metallic_roughness.base_color_texture.texture)
 	{
-		const CString fname = getTextureUri(mtl.pbr_metallic_roughness.base_color_texture);
+		const ImporterString fname = getTextureUri(mtl.pbr_metallic_roughness.base_color_texture);
 
-		ImporterString uri(m_pool);
+		ImporterString uri;
 		uri.sprintf("%s%s", m_texrpath.cstr(), fname.cstr());
 
-		xml.replaceAll("%diff%", ImporterString(m_pool).sprintf("<input name=\"m_diffTex\" value=\"%s\"/>", uri.cstr()));
+		xml.replaceAll("%diff%", ImporterString().sprintf("<input name=\"m_diffTex\" value=\"%s\"/>", uri.cstr()));
 		xml.replaceAll("%diffTexMutator%", "1");
 
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, *m_pool));
+		ANKI_CHECK(findConstantColorsInImage(fname, constantColor));
 
 		const Bool constantAlpha = constantColor.w() >= 0.0f;
 		xml.replaceAll("%alphaTestMutator%", (constantAlpha) ? "0" : "1");
@@ -197,15 +208,14 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 			ImporterString out = m_outDir;
 			out += fname;
 			fixImageUri(out);
-			ANKI_CHECK(importImage(*m_pool, fname, out, !constantAlpha));
+			ANKI_CHECK(importImage(fname, out, !constantAlpha));
 		}
 	}
 	else
 	{
 		const F32* diffCol = &mtl.pbr_metallic_roughness.base_color_factor[0];
 
-		xml.replaceAll("%diff%",
-					   ImporterString(m_pool).sprintf("<input name=\"m_diffColor\" value=\"%f %f %f\"/>", diffCol[0], diffCol[1], diffCol[2]));
+		xml.replaceAll("%diff%", ImporterString().sprintf("<input name=\"m_diffColor\" value=\"%f %f %f\"/>", diffCol[0], diffCol[1], diffCol[2]));
 
 		xml.replaceAll("%diffTexMutator%", "0");
 		xml.replaceAll("%alphaTestMutator%", "0");
@@ -219,7 +229,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		auto it = extras.find("specular");
 		if(it != extras.getEnd())
 		{
-			ImporterStringList tokens(m_pool);
+			ImporterStringList tokens;
 			tokens.splitString(it->toCString(), ' ');
 			if(tokens.getSize() != 3)
 			{
@@ -240,7 +250,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		}
 
 		xml.replaceAll("%spec%",
-					   ImporterString(m_pool).sprintf("<input name=\"m_specColor\" value=\"%f %f %f\"/>", specular.x(), specular.y(), specular.z()));
+					   ImporterString().sprintf("<input name=\"m_specColor\" value=\"%f %f %f\"/>", specular.x(), specular.y(), specular.z()));
 
 		xml.replaceAll("%specTexMutator%", "0");
 	}
@@ -249,10 +259,10 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	F32 constantMetaliness = -1.0f, constantRoughness = -1.0f;
 	if(mtl.pbr_metallic_roughness.metallic_roughness_texture.texture)
 	{
-		const CString fname = getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture);
+		const ImporterString fname = getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture);
 
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(fname, constantColor, *m_pool));
+		ANKI_CHECK(findConstantColorsInImage(fname, constantColor));
 		constantRoughness = constantColor.y();
 		constantMetaliness = constantColor.z();
 	}
@@ -261,10 +271,10 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	Bool bRoughnessMetalicTexture = false;
 	if(mtl.pbr_metallic_roughness.metallic_roughness_texture.texture && constantRoughness < 0.0f)
 	{
-		ImporterString uri(m_pool);
+		ImporterString uri;
 		uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture).cstr());
 
-		xml.replaceAll("%roughness%", ImporterString(m_pool).sprintf("<input name=\"m_roughnessTex\" value=\"%s\"/>", uri.cstr()));
+		xml.replaceAll("%roughness%", ImporterString().sprintf("<input name=\"m_roughnessTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%roughnessTexMutator%", "1");
 
@@ -275,7 +285,7 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		const F32 roughness = (constantRoughness >= 0.0f) ? constantRoughness * mtl.pbr_metallic_roughness.roughness_factor
 														  : mtl.pbr_metallic_roughness.roughness_factor;
 
-		xml.replaceAll("%roughness%", ImporterString(m_pool).sprintf("<input name=\"m_roughness\" value=\"%f\"/>", roughness));
+		xml.replaceAll("%roughness%", ImporterString().sprintf("<input name=\"m_roughness\" value=\"%f\"/>", roughness));
 
 		xml.replaceAll("%roughnessTexMutator%", "0");
 	}
@@ -283,10 +293,10 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	// Metallic
 	if(mtl.pbr_metallic_roughness.metallic_roughness_texture.texture && constantMetaliness < 0.0f)
 	{
-		ImporterString uri(m_pool);
+		ImporterString uri;
 		uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture).cstr());
 
-		xml.replaceAll("%metallic%", ImporterString(m_pool).sprintf("<input name=\"m_metallicTex\" value=\"%s\"/>", uri.cstr()));
+		xml.replaceAll("%metallic%", ImporterString().sprintf("<input name=\"m_metallicTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%metalTexMutator%", "1");
 
@@ -297,41 +307,41 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 		const F32 metalines = (constantMetaliness >= 0.0f) ? constantMetaliness * mtl.pbr_metallic_roughness.metallic_factor
 														   : mtl.pbr_metallic_roughness.metallic_factor;
 
-		xml.replaceAll("%metallic%", ImporterString(m_pool).sprintf("<input name=\"m_metallic\" value=\"%f\"/>", metalines));
+		xml.replaceAll("%metallic%", ImporterString().sprintf("<input name=\"m_metallic\" value=\"%f\"/>", metalines));
 
 		xml.replaceAll("%metalTexMutator%", "0");
 	}
 
 	if(bRoughnessMetalicTexture && m_importTextures)
 	{
-		CString in = getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture);
+		const ImporterString in = getTextureUri(mtl.pbr_metallic_roughness.metallic_roughness_texture);
 		ImporterString out = m_outDir;
 		out += in;
 		fixImageUri(out);
-		ANKI_CHECK(importImage(*m_pool, in, out, false));
+		ANKI_CHECK(importImage(in, out, false));
 	}
 
 	// Normal texture
 	if(mtl.normal_texture.texture)
 	{
 		Vec4 constantColor;
-		ANKI_CHECK(findConstantColorsInImage(getTextureUri(mtl.normal_texture).cstr(), constantColor, *m_pool));
+		ANKI_CHECK(findConstantColorsInImage(getTextureUri(mtl.normal_texture).cstr(), constantColor));
 		if(constantColor.xyz() == -1.0f)
 		{
-			ImporterString uri(m_pool);
+			ImporterString uri;
 			uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.normal_texture).cstr());
 
-			xml.replaceAll("%normal%", ImporterString(m_pool).sprintf("<input name=\"m_normalTex\" value=\"%s\"/>", uri.cstr()));
+			xml.replaceAll("%normal%", ImporterString().sprintf("<input name=\"m_normalTex\" value=\"%s\"/>", uri.cstr()));
 
 			xml.replaceAll("%normalTexMutator%", "1");
 
 			if(m_importTextures)
 			{
-				CString in = getTextureUri(mtl.normal_texture);
+				const ImporterString in = getTextureUri(mtl.normal_texture);
 				ImporterString out = m_outDir;
 				out += in;
 				fixImageUri(out);
-				ANKI_CHECK(importImage(*m_pool, in, out, false));
+				ANKI_CHECK(importImage(in, out, false));
 			}
 		}
 		else
@@ -349,28 +359,28 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 	// Emissive texture
 	if(mtl.emissive_texture.texture)
 	{
-		ImporterString uri(m_pool);
+		ImporterString uri;
 		uri.sprintf("%s%s", m_texrpath.cstr(), getTextureUri(mtl.emissive_texture).cstr());
 
-		xml.replaceAll("%emission%", ImporterString(m_pool).sprintf("<input name=\"m_emissiveTex\" value=\"%s\"/>", uri.cstr()));
+		xml.replaceAll("%emission%", ImporterString().sprintf("<input name=\"m_emissiveTex\" value=\"%s\"/>", uri.cstr()));
 
 		xml.replaceAll("%emissiveTexMutator%", "1");
 
 		if(m_importTextures)
 		{
-			CString in = getTextureUri(mtl.emissive_texture);
+			const ImporterString in = getTextureUri(mtl.emissive_texture);
 			ImporterString out = m_outDir;
 			out += in;
 			fixImageUri(out);
-			ANKI_CHECK(importImage(*m_pool, in, out, false));
+			ANKI_CHECK(importImage(in, out, false));
 		}
 	}
 	else
 	{
 		const F32* emissionCol = &mtl.emissive_factor[0];
 
-		xml.replaceAll("%emission%", ImporterString(m_pool).sprintf("<input name=\"m_emission\" value=\"%f %f %f\"/>", emissionCol[0], emissionCol[1],
-																	emissionCol[2]));
+		xml.replaceAll("%emission%",
+					   ImporterString().sprintf("<input name=\"m_emission\" value=\"%f %f %f\"/>", emissionCol[0], emissionCol[1], emissionCol[2]));
 
 		xml.replaceAll("%emissiveTexMutator%", "0");
 	}
@@ -388,19 +398,19 @@ Error GltfImporter::writeMaterial(const cgltf_material& mtl, Bool writeRayTracin
 			subsurface = 0.0f;
 		}
 
-		xml.replaceAll("%subsurface%", ImporterString(m_pool).sprintf("<input name=\"m_subsurface\" value=\"%f\"/>", subsurface));
+		xml.replaceAll("%subsurface%", ImporterString().sprintf("<input name=\"m_subsurface\" value=\"%f\"/>", subsurface));
 	}
 
 	// Height texture
 	auto it = extras.find("height_map");
 	if(it != extras.getEnd())
 	{
-		ImporterString uri(m_pool);
+		ImporterString uri;
 		uri.sprintf("%s%s", m_texrpath.cstr(), it->cstr());
 
-		xml.replaceAll("%height%", ImporterString(m_pool).sprintf("<input name=\"m_heightTex\" value=\"%s\" \"/>\n"
-																  "\t\t<input name=\"m_heightmapScale\" value=\"0.05\"/>",
-																  uri.cstr()));
+		xml.replaceAll("%height%", ImporterString().sprintf("<input name=\"m_heightTex\" value=\"%s\" \"/>\n"
+															"\t\t<input name=\"m_heightmapScale\" value=\"0.05\"/>",
+															uri.cstr()));
 
 		xml.replaceAll("%parallaxMutator%", "1");
 	}

+ 47 - 44
AnKi/Importer/GltfImporterMesh.cpp

@@ -145,29 +145,21 @@ public:
 
 	Vec3 m_sphereCenter;
 	F32 m_sphereRadius = 0.0f;
-
-	SubMesh(BaseMemoryPool* pool)
-		: m_verts(pool)
-		, m_indices(pool)
-		, m_meshlets(pool)
-		, m_localIndices(pool)
-	{
-	}
 };
 
-static void reindexSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
+static void reindexSubmesh(SubMesh& submesh)
 {
 	const U32 vertSize = sizeof(submesh.m_verts[0]);
 
-	ImporterDynamicArray<U32> remap(pool);
+	ImporterDynamicArray<U32> remap;
 	remap.resize(submesh.m_verts.getSize(), 0);
 
 	const U32 vertCount = U32(meshopt_generateVertexRemap(&remap[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &submesh.m_verts[0],
 														  submesh.m_verts.getSize(), vertSize));
 
-	ImporterDynamicArray<U32> newIdxArray(pool);
+	ImporterDynamicArray<U32> newIdxArray;
 	newIdxArray.resize(submesh.m_indices.getSize(), 0);
-	ImporterDynamicArray<TempVertex> newVertArray(pool);
+	ImporterDynamicArray<TempVertex> newVertArray;
 	newVertArray.resize(vertCount);
 
 	meshopt_remapIndexBuffer(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &remap[0]);
@@ -178,13 +170,13 @@ static void reindexSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 }
 
 /// Optimize a submesh using meshoptimizer.
-static void optimizeSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
+static void optimizeSubmesh(SubMesh& submesh)
 {
 	const PtrSize vertSize = sizeof(submesh.m_verts[0]);
 
 	// Vert cache
 	{
-		ImporterDynamicArray<U32> newIdxArray(pool);
+		ImporterDynamicArray<U32> newIdxArray;
 		newIdxArray.resize(submesh.m_indices.getSize(), 0);
 
 		meshopt_optimizeVertexCache(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(), submesh.m_verts.getSize());
@@ -194,7 +186,7 @@ static void optimizeSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 
 	// Overdraw
 	{
-		ImporterDynamicArray<U32> newIdxArray(pool);
+		ImporterDynamicArray<U32> newIdxArray;
 		newIdxArray.resize(submesh.m_indices.getSize(), 0);
 
 		meshopt_optimizeOverdraw(&newIdxArray[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &submesh.m_verts[0].m_position.x(),
@@ -205,7 +197,7 @@ static void optimizeSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 
 	// Vert fetch
 	{
-		ImporterDynamicArray<TempVertex> newVertArray(pool);
+		ImporterDynamicArray<TempVertex> newVertArray;
 		newVertArray.resize(submesh.m_verts.getSize());
 
 		const U32 newVertCount =
@@ -224,7 +216,7 @@ static void optimizeSubmesh(SubMesh& submesh, BaseMemoryPool* pool)
 }
 
 /// Decimate a submesh using meshoptimizer.
-static void decimateSubmesh(F32 factor, SubMesh& submesh, BaseMemoryPool* pool)
+static void decimateSubmesh(F32 factor, SubMesh& submesh)
 {
 	ANKI_ASSERT(factor > 0.0f && factor < 1.0f);
 	const PtrSize targetIndexCount = PtrSize(F32(submesh.m_indices.getSize() / 3) * factor) * 3;
@@ -234,15 +226,15 @@ static void decimateSubmesh(F32 factor, SubMesh& submesh, BaseMemoryPool* pool)
 	}
 
 	// Decimate
-	ImporterDynamicArray<U32> newIndices(pool);
+	ImporterDynamicArray<U32> newIndices;
 	newIndices.resize(submesh.m_indices.getSize());
 	newIndices.resize(U32(meshopt_simplify(&newIndices[0], &submesh.m_indices[0], submesh.m_indices.getSize(), &submesh.m_verts[0].m_position.x(),
 										   submesh.m_verts.getSize(), sizeof(TempVertex), targetIndexCount, 1e-2f)));
 
 	// Re-pack
-	ImporterDynamicArray<U32> reindexedIndices(pool);
-	ImporterDynamicArray<TempVertex> newVerts(pool);
-	ImporterHashMap<U32, U32> vertexStored(pool);
+	ImporterDynamicArray<U32> reindexedIndices;
+	ImporterDynamicArray<TempVertex> newVerts;
+	ImporterHashMap<U32, U32> vertexStored;
 	for(U32 idx = 0; idx < newIndices.getSize(); ++idx)
 	{
 		U32 newIdx;
@@ -360,13 +352,13 @@ static void generateMeshlets(SubMesh& submesh)
 	// Allocate the arrays
 	const U32 maxMeshlets = U32(meshopt_buildMeshletsBound(submesh.m_indices.getSize(), kMaxVerticesPerMeshlet, kMaxPrimitivesPerMeshlet));
 
-	ImporterDynamicArray<U32> indicesToVertexBuffer(&submesh.m_verts.getMemoryPool());
+	ImporterDynamicArray<U32> indicesToVertexBuffer;
 	indicesToVertexBuffer.resize(maxMeshlets * kMaxVerticesPerMeshlet);
 
-	ImporterDynamicArray<U8> localIndices(&submesh.m_verts.getMemoryPool());
+	ImporterDynamicArray<U8> localIndices;
 	localIndices.resize(maxMeshlets * kMaxPrimitivesPerMeshlet * 3);
 
-	ImporterDynamicArray<meshopt_Meshlet> meshlets(&submesh.m_verts.getMemoryPool());
+	ImporterDynamicArray<meshopt_Meshlet> meshlets;
 	meshlets.resize(maxMeshlets);
 
 	// Meshletize
@@ -387,8 +379,8 @@ static void generateMeshlets(SubMesh& submesh)
 	submesh.m_meshlets.resize(meshletCount);
 	submesh.m_localIndices.destroy();
 
-	ImporterDynamicArray<U32> newIndexBuffer(&submesh.m_verts.getMemoryPool());
-	ImporterDynamicArray<TempVertex> newVertexBuffer(&submesh.m_verts.getMemoryPool());
+	ImporterDynamicArray<U32> newIndexBuffer;
+	ImporterDynamicArray<TempVertex> newVertexBuffer;
 
 	for(U32 meshletIdx = 0; meshletIdx < meshletCount; ++meshletIdx)
 	{
@@ -400,7 +392,7 @@ static void generateMeshlets(SubMesh& submesh)
 		outMeshlet.m_firstVertex = newVertexBuffer.getSize();
 		outMeshlet.m_vertexCount = inMeshlet.vertex_count;
 
-		ImporterHashMap<U8, U32> localIndexToNewGlobalIndex(&submesh.m_verts.getMemoryPool());
+		ImporterHashMap<U8, U32> localIndexToNewGlobalIndex;
 
 		for(U32 tri = 0; tri < inMeshlet.triangle_count; ++tri)
 		{
@@ -499,17 +491,28 @@ U32 GltfImporter::getMeshTotalVertexCount(const cgltf_mesh& mesh)
 }
 
 Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
+{
+	const Error err = writeMeshInternal(mesh);
+	if(err)
+	{
+		ANKI_IMPORTER_LOGE("Failed to write mesh: %s", mesh.name);
+	}
+
+	return err;
+}
+
+Error GltfImporter::writeMeshInternal(const cgltf_mesh& mesh) const
 {
 	const ImporterString meshName = computeMeshResourceFilename(mesh);
-	ImporterString fname(m_pool);
+	ImporterString fname;
 	fname.sprintf("%s%s", m_outDir.cstr(), meshName.cstr());
 	ANKI_IMPORTER_LOGV("Importing mesh (%s): %s", (m_optimizeMeshes) ? "optimize" : "WON'T optimize", fname.cstr());
 
-	Array<ImporterList<SubMesh>, kMaxLodCount> submeshes = {{{m_pool}, {m_pool}, {m_pool}}};
+	Array<ImporterList<SubMesh>, kMaxLodCount> submeshes;
 	Vec3 aabbMin(kMaxF32);
 	Vec3 aabbMax(kMinF32);
 	Bool hasBoneWeights = false;
-	ImporterDynamicArray<Vec3> allPositions(m_pool); // Used to calculate the overall bounding sphere
+	ImporterDynamicArray<Vec3> allPositions; // Used to calculate the overall bounding sphere
 
 	// Iterate primitives. Every primitive is a submesh
 	for(const cgltf_primitive* primitive = mesh.primitives; primitive < mesh.primitives + mesh.primitives_count; ++primitive)
@@ -520,7 +523,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 			return Error::kUserData;
 		}
 
-		SubMesh& submesh = *submeshes[0].emplaceBack(m_pool);
+		SubMesh& submesh = *submeshes[0].emplaceBack();
 
 		// All attributes should have the same vertex count
 		U minVertCount = kMaxU;
@@ -654,14 +657,14 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		// Re-index meshes now
 		if(m_optimizeMeshes)
 		{
-			reindexSubmesh(submesh, m_pool);
+			reindexSubmesh(submesh);
 			vertCount = submesh.m_verts.getSize();
 		}
 
 		// Optimize
 		if(m_optimizeMeshes)
 		{
-			optimizeSubmesh(submesh, m_pool);
+			optimizeSubmesh(submesh);
 		}
 
 		// Finalize
@@ -684,10 +687,10 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 
 		for(const SubMesh& lod0Submesh : submeshes[0])
 		{
-			SubMesh& newSubmesh = *submeshes[lod].pushBack(m_pool);
+			SubMesh& newSubmesh = *submeshes[lod].emplaceBack();
 			newSubmesh = lod0Submesh; // Copy LOD0 data to new submesh
 
-			decimateSubmesh(computeLodFactor(lod), newSubmesh, m_pool);
+			decimateSubmesh(computeLodFactor(lod), newSubmesh);
 		}
 
 		maxLod = lod;
@@ -743,7 +746,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 	}
 
 	// Write sub meshes
-	ImporterDynamicArray<MeshBinarySubMesh> outSubmeshes(m_pool);
+	ImporterDynamicArray<MeshBinarySubMesh> outSubmeshes;
 	outSubmeshes.resize(U32(submeshes[0].getSize()));
 
 	for(U32 submeshIdx = 0; submeshIdx < outSubmeshes.getSize(); ++submeshIdx)
@@ -785,7 +788,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		U32 vertCount = 0;
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<U16> indices(m_pool);
+			ImporterDynamicArray<U16> indices;
 			indices.resize(submesh.m_indices.getSize());
 			for(U32 i = 0; i < indices.getSize(); ++i)
 			{
@@ -806,7 +809,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		// Write positions
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<U16Vec4> positions(m_pool);
+			ImporterDynamicArray<U16Vec4> positions;
 			positions.resize(submesh.m_verts.getSize());
 			for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 			{
@@ -823,7 +826,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		// Write normals
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<U32> normals(m_pool);
+			ImporterDynamicArray<U32> normals;
 			normals.resize(submesh.m_verts.getSize());
 			for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 			{
@@ -836,7 +839,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		// Write UV
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<Vec2> uvs(m_pool);
+			ImporterDynamicArray<Vec2> uvs;
 			uvs.resize(submesh.m_verts.getSize());
 			for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 			{
@@ -851,7 +854,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 			// Bone IDs
 			for(const SubMesh& submesh : submeshes[lod])
 			{
-				ImporterDynamicArray<U8Vec4> boneids(m_pool);
+				ImporterDynamicArray<U8Vec4> boneids;
 				boneids.resize(submesh.m_verts.getSize());
 				for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 				{
@@ -864,7 +867,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 			// Bone weights
 			for(const SubMesh& submesh : submeshes[lod])
 			{
-				ImporterDynamicArray<U32> boneWeights(m_pool);
+				ImporterDynamicArray<U32> boneWeights;
 				boneWeights.resize(submesh.m_verts.getSize());
 				for(U32 v = 0; v < submesh.m_verts.getSize(); ++v)
 				{
@@ -880,7 +883,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		U32 vertCount2 = 0;
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<MeshBinaryMeshlet> meshlets(m_pool);
+			ImporterDynamicArray<MeshBinaryMeshlet> meshlets;
 			meshlets.resize(submesh.m_meshlets.getSize());
 
 			for(U32 v = 0; v < submesh.m_meshlets.getSize(); ++v)
@@ -914,7 +917,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh) const
 		// Write local indices
 		for(const SubMesh& submesh : submeshes[lod])
 		{
-			ImporterDynamicArray<U8> localIndices(m_pool);
+			ImporterDynamicArray<U8> localIndices;
 			localIndices.resize(submesh.m_localIndices.getSize() / 3 * sizeof(U8Vec4));
 
 			U32 count = 0;

+ 26 - 53
AnKi/Importer/ImageImporter.cpp

@@ -23,13 +23,6 @@ public:
 	ImporterDynamicArrayLarge<U8> m_pixels;
 	ImporterDynamicArrayLarge<U8> m_s3tcPixels;
 	ImporterDynamicArrayLarge<U8> m_astcPixels;
-
-	SurfaceOrVolumeData(BaseMemoryPool* pool)
-		: m_pixels(pool)
-		, m_s3tcPixels(pool)
-		, m_astcPixels(pool)
-	{
-	}
 };
 
 class Mipmap
@@ -37,11 +30,6 @@ class Mipmap
 public:
 	/// One surface for each layer ore one per face or a single volume if it's a 3D texture.
 	ImporterDynamicArray<SurfaceOrVolumeData> m_surfacesOrVolume;
-
-	Mipmap(BaseMemoryPool* pool)
-		: m_surfacesOrVolume(pool)
-	{
-	}
 };
 
 /// Image importer context.
@@ -57,16 +45,6 @@ public:
 	U32 m_channelCount = 0;
 	U32 m_pixelSize = 0; ///< Texel size of an uncompressed image.
 	Bool m_hdr = false;
-
-	ImageImporterContext(BaseMemoryPool* pool)
-		: m_mipmaps(pool)
-	{
-	}
-
-	BaseMemoryPool& getMemoryPool()
-	{
-		return m_mipmaps.getMemoryPool();
-	}
 };
 
 class DdsPixelFormat
@@ -241,8 +219,7 @@ static Error checkInputImages(const ImageImporterConfig& config, U32& width, U32
 	return Error::kNone;
 }
 
-static Error resizeImage(CString inImageFilename, U32 outWidth, U32 outHeight, CString tempDirectory, BaseMemoryPool& pool,
-						 ImporterString& tmpFilename)
+static Error resizeImage(CString inImageFilename, U32 outWidth, U32 outHeight, CString tempDirectory, ImporterString& tmpFilename)
 {
 	U32 inWidth, inHeight, channelCount;
 	Bool hdr;
@@ -269,7 +246,7 @@ static Error resizeImage(CString inImageFilename, U32 outWidth, U32 outHeight, C
 
 	// Resize
 	I ok;
-	ImporterDynamicArray<U8> outPixels(&pool);
+	ImporterDynamicArray<U8> outPixels;
 	if(!hdr)
 	{
 		outPixels.resize(outWidth * outHeight * channelCount);
@@ -389,19 +366,17 @@ static void applyScaleAndBias(WeakArray<Vec3> pixels, Vec3 scale, Vec3 bias)
 
 static Error loadFirstMipmap(const ImageImporterConfig& config, ImageImporterContext& ctx)
 {
-	BaseMemoryPool& pool = ctx.getMemoryPool();
-
-	ctx.m_mipmaps.emplaceBack(&pool);
+	ctx.m_mipmaps.emplaceBack();
 	Mipmap& mip0 = ctx.m_mipmaps[0];
 
 	if(ctx.m_depth > 1)
 	{
-		mip0.m_surfacesOrVolume.resize(1, &pool);
+		mip0.m_surfacesOrVolume.resize(1);
 		mip0.m_surfacesOrVolume[0].m_pixels.resize(ctx.m_pixelSize * ctx.m_width * ctx.m_height * ctx.m_depth);
 	}
 	else
 	{
-		mip0.m_surfacesOrVolume.resize(ctx.m_faceCount * ctx.m_layerCount, &pool);
+		mip0.m_surfacesOrVolume.resize(ctx.m_faceCount * ctx.m_layerCount);
 		ANKI_ASSERT(mip0.m_surfacesOrVolume.getSize() == config.m_inputFilenames.getSize());
 
 		for(U32 f = 0; f < ctx.m_faceCount; ++f)
@@ -559,15 +534,15 @@ static void generateSurfaceMipmap(ConstWeakArray<U8, PtrSize> inBuffer, U32 inWi
 	}
 }
 
-static Error compressS3tc(BaseMemoryPool& pool, CString tempDirectory, CString compressonatorFilename, ConstWeakArray<U8, PtrSize> inPixels,
-						  U32 inWidth, U32 inHeight, U32 channelCount, Bool hdr, WeakArray<U8, PtrSize> outPixels)
+static Error compressS3tc(CString tempDirectory, CString compressonatorFilename, ConstWeakArray<U8, PtrSize> inPixels, U32 inWidth, U32 inHeight,
+						  U32 channelCount, Bool hdr, WeakArray<U8, PtrSize> outPixels)
 {
 	ANKI_ASSERT(inPixels.getSizeInBytes() == PtrSize(inWidth) * inHeight * channelCount * ((hdr) ? sizeof(F32) : sizeof(U8)));
 	ANKI_ASSERT(inWidth > 0 && isPowerOfTwo(inWidth) && inHeight > 0 && isPowerOfTwo(inHeight));
 	ANKI_ASSERT(outPixels.getSizeInBytes() == PtrSize((hdr || channelCount == 4) ? 16 : 8) * (inWidth / 4) * (inHeight / 4));
 
 	// Create a PNG image to feed to the compressor
-	ImporterString tmpFilename(&pool);
+	ImporterString tmpFilename;
 	tmpFilename.sprintf("%s/AnKiImageImporter_%u.%s", tempDirectory.cstr(), g_tempFileIndex.fetchAdd(1), (hdr) ? "exr" : "png");
 	ANKI_IMPORTER_LOGV("Will store: %s", tmpFilename.cstr());
 	Bool saveTmpImageOk = false;
@@ -590,7 +565,7 @@ static Error compressS3tc(BaseMemoryPool& pool, CString tempDirectory, CString c
 	CleanupFile tmpCleanup(tmpFilename);
 
 	// Invoke the compressor process
-	ImporterString ddsFilename(&pool);
+	ImporterString ddsFilename;
 	ddsFilename.sprintf("%s/AnKiImageImporter_%u.dds", tempDirectory.cstr(), g_tempFileIndex.fetchAdd(1));
 	Process proc;
 	Array<CString, 5> args;
@@ -667,8 +642,8 @@ static Error compressS3tc(BaseMemoryPool& pool, CString tempDirectory, CString c
 	return Error::kNone;
 }
 
-static Error compressAstc(BaseMemoryPool& pool, CString tempDirectory, CString astcencFilename, ConstWeakArray<U8, PtrSize> inPixels, U32 inWidth,
-						  U32 inHeight, U32 inChannelCount, UVec2 blockSize, Bool hdr, WeakArray<U8, PtrSize> outPixels)
+static Error compressAstc(CString tempDirectory, CString astcencFilename, ConstWeakArray<U8, PtrSize> inPixels, U32 inWidth, U32 inHeight,
+						  U32 inChannelCount, UVec2 blockSize, Bool hdr, WeakArray<U8, PtrSize> outPixels)
 {
 	[[maybe_unused]] const PtrSize blockBytes = 16;
 	ANKI_ASSERT(inPixels.getSizeInBytes() == PtrSize(inWidth) * inHeight * inChannelCount * ((hdr) ? sizeof(F32) : sizeof(U8)));
@@ -676,7 +651,7 @@ static Error compressAstc(BaseMemoryPool& pool, CString tempDirectory, CString a
 	ANKI_ASSERT(outPixels.getSizeInBytes() == blockBytes * (inWidth / blockSize.x()) * (inHeight / blockSize.y()));
 
 	// Create a BMP image to feed to the astcebc
-	ImporterString tmpFilename(&pool);
+	ImporterString tmpFilename;
 	tmpFilename.sprintf("%s/AnKiImageImporter_%u.%s", tempDirectory.cstr(), g_tempFileIndex.fetchAdd(1), (hdr) ? "exr" : "png");
 	ANKI_IMPORTER_LOGV("Will store: %s", tmpFilename.cstr());
 	Bool saveTmpImageOk = false;
@@ -699,9 +674,9 @@ static Error compressAstc(BaseMemoryPool& pool, CString tempDirectory, CString a
 	CleanupFile pngCleanup(tmpFilename);
 
 	// Invoke the compressor process
-	ImporterString astcFilename(&pool);
+	ImporterString astcFilename;
 	astcFilename.sprintf("%s/AnKiImageImporter_%u.astc", tempDirectory.cstr(), g_tempFileIndex.fetchAdd(1));
-	ImporterString blockStr(&pool);
+	ImporterString blockStr;
 	blockStr.sprintf("%ux%u", blockSize.x(), blockSize.y());
 	Process proc;
 	Array<CString, 5> args;
@@ -872,7 +847,6 @@ static Error storeAnkiImage(const ImageImporterConfig& config, const ImageImport
 
 static Error importImageInternal(const ImageImporterConfig& configOriginal)
 {
-	BaseMemoryPool& pool = *configOriginal.m_pool;
 	ImageImporterConfig config = configOriginal;
 
 	config.m_minMipmapDimension = max(config.m_minMipmapDimension, 4u);
@@ -889,9 +863,9 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 	ANKI_CHECK(checkInputImages(config, width, height, channelCount, isHdr));
 
 	// Resize
-	ImporterDynamicArray<ImporterString> newFilenames(&pool);
-	ImporterDynamicArray<CString> newFilenamesCString(&pool);
-	ImporterDynamicArray<CleanupFile> resizedImagesCleanup(&pool);
+	ImporterDynamicArray<ImporterString> newFilenames;
+	ImporterDynamicArray<CString> newFilenamesCString;
+	ImporterDynamicArray<CleanupFile> resizedImagesCleanup;
 	if(width < config.m_minMipmapDimension || height < config.m_minMipmapDimension)
 	{
 		const U32 newWidth = max(width, config.m_minMipmapDimension);
@@ -899,12 +873,12 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 
 		ANKI_IMPORTER_LOGV("Image is smaller than the min mipmap dimension. Will resize it to %ux%u", newWidth, newHeight);
 
-		newFilenames.resize(config.m_inputFilenames.getSize(), ImporterString(&pool));
+		newFilenames.resize(config.m_inputFilenames.getSize());
 		newFilenamesCString.resize(config.m_inputFilenames.getSize());
 
 		for(U32 i = 0; i < config.m_inputFilenames.getSize(); ++i)
 		{
-			ANKI_CHECK(resizeImage(config.m_inputFilenames[i], newWidth, newHeight, config.m_tempDirectory, pool, newFilenames[i]));
+			ANKI_CHECK(resizeImage(config.m_inputFilenames[i], newWidth, newHeight, config.m_tempDirectory, newFilenames[i]));
 
 			newFilenamesCString[i] = newFilenames[i];
 			resizedImagesCleanup.emplaceBack(newFilenames[i]);
@@ -917,7 +891,7 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 	}
 
 	// Init image
-	ImageImporterContext ctx(&pool);
+	ImageImporterContext ctx;
 
 	ctx.m_width = width;
 	ctx.m_height = height;
@@ -975,11 +949,11 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 													   : computeMaxMipmapCount2d(width, height, config.m_minMipmapDimension));
 	for(U32 mip = 1; mip < mipCount; ++mip)
 	{
-		ctx.m_mipmaps.emplaceBack(&pool);
+		ctx.m_mipmaps.emplaceBack();
 
 		if(config.m_type != ImageBinaryType::k3D)
 		{
-			ctx.m_mipmaps[mip].m_surfacesOrVolume.resize(ctx.m_faceCount * ctx.m_layerCount, &pool);
+			ctx.m_mipmaps[mip].m_surfacesOrVolume.resize(ctx.m_faceCount * ctx.m_layerCount);
 			for(U32 l = 0; l < ctx.m_layerCount; ++l)
 			{
 				for(U32 f = 0; f < ctx.m_faceCount; ++f)
@@ -1047,9 +1021,8 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 
 					surface.m_s3tcPixels.resize(s3tcImageSize);
 
-					ANKI_CHECK(compressS3tc(pool, config.m_tempDirectory, config.m_compressonatorFilename,
-											ConstWeakArray<U8, PtrSize>(surface.m_pixels), width, height, ctx.m_channelCount, ctx.m_hdr,
-											WeakArray<U8, PtrSize>(surface.m_s3tcPixels)));
+					ANKI_CHECK(compressS3tc(config.m_tempDirectory, config.m_compressonatorFilename, ConstWeakArray<U8, PtrSize>(surface.m_pixels),
+											width, height, ctx.m_channelCount, ctx.m_hdr, WeakArray<U8, PtrSize>(surface.m_s3tcPixels)));
 				}
 			}
 		}
@@ -1075,8 +1048,8 @@ static Error importImageInternal(const ImageImporterConfig& configOriginal)
 
 					surface.m_astcPixels.resize(astcImageSize);
 
-					ANKI_CHECK(compressAstc(pool, config.m_tempDirectory, config.m_astcencFilename, ConstWeakArray<U8, PtrSize>(surface.m_pixels),
-											width, height, ctx.m_channelCount, config.m_astcBlockSize, ctx.m_hdr,
+					ANKI_CHECK(compressAstc(config.m_tempDirectory, config.m_astcencFilename, ConstWeakArray<U8, PtrSize>(surface.m_pixels), width,
+											height, ctx.m_channelCount, config.m_astcBlockSize, ctx.m_hdr,
 											WeakArray<U8, PtrSize>(surface.m_astcPixels)));
 				}
 			}

+ 0 - 1
AnKi/Importer/ImageImporter.h

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

+ 2 - 0
AnKi/Util/Forward.h

@@ -83,6 +83,8 @@ class XmlDocument;
 	using submoduleName##String = BaseString<submoduleName##MemPoolWrapper>; \
 	template<typename T, typename TSize = U32> \
 	using submoduleName##DynamicArray = DynamicArray<T, submoduleName##MemPoolWrapper, TSize>; \
+	template<typename T, typename TSize = PtrSize> \
+	using submoduleName##DynamicArrayLarge = DynamicArray<T, submoduleName##MemPoolWrapper, TSize>; \
 	template<typename TKey, typename TValue, typename THasher = DefaultHasher<TKey>> \
 	using submoduleName##HashMap = HashMap<TKey, TValue, THasher, submoduleName##MemPoolWrapper, HashMapSparseArrayConfig>; \
 	template<typename T> \

+ 5 - 0
AnKi/Util/HashMap.h

@@ -204,6 +204,11 @@ public:
 		return m_sparseArr.find(hash);
 	}
 
+	SparseArrayType& getSparseArray()
+	{
+		return m_sparseArr;
+	}
+
 protected:
 	SparseArrayType m_sparseArr;
 };

+ 2 - 3
AnKi/Util/SparseArray.h

@@ -22,10 +22,9 @@ class SparseArrayIterator
 	template<typename, typename, typename>
 	friend class SparseArray;
 
-private:
+public:
 	using Index = typename RemovePointer<TSparseArrayPtr>::Type::Index;
 
-public:
 	/// Default constructor.
 	SparseArrayIterator()
 		: m_array(nullptr)
@@ -135,7 +134,7 @@ public:
 		return !(*this == b);
 	}
 
-	U32 getKey() const
+	Index getKey() const
 	{
 		check();
 		return m_elementIdx;

BIN=BIN
Samples/SkeletalAnimation/Assets/Mesh_e891faf0733c881d.ankimesh


+ 1 - 1
Samples/SkeletalAnimation/Assets/Scene.lua

@@ -1,4 +1,4 @@
--- Generated by: C:\src\anki\out\build\x64-Debug\Binaries\GltfImporter.exe E:/etc/blender/characters/animated_droid/gltf/droid.gltf C:/src/anki/Samples/SkeletalAnimation/Assets/ -rpath Assets -texrpath Assets -v -import-textures 1
+-- Generated by: C:\src\anki\out\build\x64-Release\Binaries\GltfImporter.exe E:/etc/blender/characters/animated_droid/gltf/droid.gltf C:/src/anki/Samples/SkeletalAnimation/Assets/ -rpath Assets -texrpath Assets -v
 local scene = getSceneGraph()
 local events = getEventManager()
 

BIN=BIN
Samples/SkeletalAnimation/Assets/room.001_82c13d2071184ecf.ankimesh


BIN=BIN
Samples/SkeletalAnimation/Assets/room.002_9aeac5bb7f16c0a7.ankimesh


BIN=BIN
Samples/SkeletalAnimation/Assets/room.003_225a06b3faa52c4c.ankimesh


BIN=BIN
Samples/SkeletalAnimation/Assets/room_bb0180d3054a4db3.ankimesh


+ 1 - 1
Sandbox/Main.cpp

@@ -357,7 +357,7 @@ Error MyApp::userMainLoop(Bool& quit, Second elapsedTime)
 
 	if(in.getKey(KeyCode::kH) == 1)
 	{
-		renderer.setCurrentDebugRenderTarget((renderer.getCurrentDebugRenderTarget() == "GBufferNormals") ? "" : "GBufferNormals");
+		renderer.setCurrentDebugRenderTarget((renderer.getCurrentDebugRenderTarget() == "GBufferAlbedo") ? "" : "GBufferAlbedo");
 	}
 
 	/*if(in.getKey(KeyCode::J) == 1)

+ 5 - 1
Tools/GltfImporter/Main.cpp

@@ -226,10 +226,12 @@ int myMain(int argc, char** argv)
 		~Cleanup()
 		{
 			DefaultMemoryPool::freeSingleton();
+			ImporterMemoryPool::freeSingleton();
 		}
 	} cleanup;
 
 	DefaultMemoryPool::allocateSingleton(allocAligned, nullptr);
+	ImporterMemoryPool::allocateSingleton(allocAligned, nullptr);
 
 	CmdLineArgs cmdArgs;
 	if(parseCommandLineArgs(argc, argv, cmdArgs))
@@ -270,7 +272,7 @@ int myMain(int argc, char** argv)
 	initInfo.m_comment = comment;
 	initInfo.m_importTextures = cmdArgs.m_importTextures;
 
-	GltfImporter importer(&DefaultMemoryPool::getSingleton());
+	GltfImporter importer;
 	if(importer.init(initInfo))
 	{
 		return 1;
@@ -281,5 +283,7 @@ int myMain(int argc, char** argv)
 		return 1;
 	}
 
+	ANKI_IMPORTER_LOGI("File written: %s", cmdArgs.m_inputFname.cstr());
+
 	return 0;
 }

+ 2 - 2
Tools/Image/ImageImporterMain.cpp

@@ -304,14 +304,14 @@ int myMain(int argc, char** argv)
 		~Cleanup2()
 		{
 			DefaultMemoryPool::freeSingleton();
+			ImporterMemoryPool::freeSingleton();
 		}
 	} cleanup2;
 
 	DefaultMemoryPool::allocateSingleton(allocAligned, nullptr);
+	ImporterMemoryPool::allocateSingleton(allocAligned, nullptr);
 
-	HeapMemoryPool pool(allocAligned, nullptr);
 	ImageImporterConfig config;
-	config.m_pool = &pool;
 	Cleanup cleanup;
 	if(parseCommandLineArgs(argc, argv, config, cleanup))
 	{