Browse Source

Remove the allocator from the shader compiler

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
658d0544db

+ 2 - 2
AnKi/Gr/Common.h

@@ -82,8 +82,8 @@ ANKI_GR_CLASS(GrUpscaler)
 	friend class GrManager; \
 	friend class GrManager; \
 	template<typename, typename> \
 	template<typename, typename> \
 	friend class IntrusivePtr; \
 	friend class IntrusivePtr; \
-	template<typename, typename> \
-	friend class GenericPoolAllocator;
+	template<typename T, typename... TArgs> \
+	friend void callConstructor(T& p, TArgs&&... args);
 
 
 /// Shader block information.
 /// Shader block information.
 class ShaderVariableBlockInfo
 class ShaderVariableBlockInfo

+ 3 - 8
AnKi/Gr/GrManager.h

@@ -89,14 +89,9 @@ public:
 
 
 	GrManagerStats getStats() const;
 	GrManagerStats getStats() const;
 
 
-	ANKI_INTERNAL GrAllocator<U8>& getAllocator()
+	ANKI_INTERNAL HeapMemoryPool& getMemoryPool()
 	{
 	{
-		return m_alloc;
-	}
-
-	ANKI_INTERNAL GrAllocator<U8> getAllocator() const
-	{
-		return m_alloc;
+		return m_pool;
 	}
 	}
 
 
 	ANKI_INTERNAL CString getCacheDirectory() const
 	ANKI_INTERNAL CString getCacheDirectory() const
@@ -120,7 +115,7 @@ public:
 	}
 	}
 
 
 protected:
 protected:
-	GrAllocator<U8> m_alloc; ///< Keep it first to get deleted last
+	HeapMemoryPool m_pool; ///< Keep it first to get deleted last
 	ConfigSet* m_config = nullptr;
 	ConfigSet* m_config = nullptr;
 	String m_cacheDir;
 	String m_cacheDir;
 	Atomic<U64> m_uuidIndex = {1};
 	Atomic<U64> m_uuidIndex = {1};

+ 4 - 4
AnKi/Gr/GrObject.cpp

@@ -19,7 +19,7 @@ GrObject::GrObject(GrManager* manager, GrObjectType type, CString name)
 		name = "N/A";
 		name = "N/A";
 	}
 	}
 
 
-	m_name = static_cast<Char*>(manager->getAllocator().getMemoryPool().allocate(name.getLength() + 1, alignof(Char)));
+	m_name = static_cast<Char*>(manager->getMemoryPool().allocate(name.getLength() + 1, alignof(Char)));
 	memcpy(m_name, &name[0], name.getLength() + 1);
 	memcpy(m_name, &name[0], name.getLength() + 1);
 }
 }
 
 
@@ -27,13 +27,13 @@ GrObject::~GrObject()
 {
 {
 	if(m_name)
 	if(m_name)
 	{
 	{
-		m_manager->getAllocator().getMemoryPool().free(m_name);
+		m_manager->getMemoryPool().free(m_name);
 	}
 	}
 }
 }
 
 
-GrAllocator<U8> GrObject::getAllocator() const
+HeapMemoryPool& GrObject::getMemoryPool()
 {
 {
-	return m_manager->getAllocator();
+	return m_manager->getMemoryPool();
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 1 - 1
AnKi/Gr/GrObject.h

@@ -62,7 +62,7 @@ public:
 		return *m_manager;
 		return *m_manager;
 	}
 	}
 
 
-	GrAllocator<U8> getAllocator() const;
+	HeapMemoryPool& getMemoryPool();
 
 
 	void retain() const
 	void retain() const
 	{
 	{

+ 106 - 108
AnKi/Gr/RenderGraph.cpp

@@ -149,7 +149,7 @@ public:
 class RenderGraph::BakeContext
 class RenderGraph::BakeContext
 {
 {
 public:
 public:
-	StackAllocator<U8> m_alloc;
+	StackMemoryPool* m_pool = nullptr;
 	DynamicArray<Pass> m_passes;
 	DynamicArray<Pass> m_passes;
 	BitSet<kMaxRenderGraphPasses, U64> m_passIsInBatch{false};
 	BitSet<kMaxRenderGraphPasses, U64> m_passIsInBatch{false};
 	DynamicArray<Batch> m_batches;
 	DynamicArray<Batch> m_batches;
@@ -161,8 +161,8 @@ public:
 
 
 	Bool m_gatherStatistics = false;
 	Bool m_gatherStatistics = false;
 
 
-	BakeContext(const StackAllocator<U8>& alloc)
-		: m_alloc(alloc)
+	BakeContext(StackMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
 	}
 	}
 };
 };
@@ -271,23 +271,23 @@ RenderGraph::~RenderGraph()
 	{
 	{
 		auto it = m_renderTargetCache.getBegin();
 		auto it = m_renderTargetCache.getBegin();
 		RenderTargetCacheEntry& entry = *it;
 		RenderTargetCacheEntry& entry = *it;
-		entry.m_textures.destroy(getAllocator());
-		m_renderTargetCache.erase(getAllocator(), it);
+		entry.m_textures.destroy(getMemoryPool());
+		m_renderTargetCache.erase(getMemoryPool(), it);
 	}
 	}
 
 
-	m_fbCache.destroy(getAllocator());
+	m_fbCache.destroy(getMemoryPool());
 
 
 	for(auto& it : m_importedRenderTargets)
 	for(auto& it : m_importedRenderTargets)
 	{
 	{
-		it.m_surfOrVolLastUsages.destroy(getAllocator());
+		it.m_surfOrVolLastUsages.destroy(getMemoryPool());
 	}
 	}
 
 
-	m_importedRenderTargets.destroy(getAllocator());
+	m_importedRenderTargets.destroy(getMemoryPool());
 }
 }
 
 
 RenderGraph* RenderGraph::newInstance(GrManager* manager)
 RenderGraph* RenderGraph::newInstance(GrManager* manager)
 {
 {
-	return manager->getAllocator().newInstance<RenderGraph>(manager, "N/A");
+	return anki::newInstance<RenderGraph>(manager->getMemoryPool(), manager, "N/A");
 }
 }
 
 
 void RenderGraph::reset()
 void RenderGraph::reset()
@@ -326,8 +326,8 @@ void RenderGraph::reset()
 			else
 			else
 			{
 			{
 				// Not found, create
 				// Not found, create
-				it = m_importedRenderTargets.emplace(getAllocator(), hash);
-				it->m_surfOrVolLastUsages.create(getAllocator(), surfOrVolumeCount);
+				it = m_importedRenderTargets.emplace(getMemoryPool(), hash);
+				it->m_surfOrVolLastUsages.create(getMemoryPool(), surfOrVolumeCount);
 			}
 			}
 
 
 			// Update the usage
 			// Update the usage
@@ -358,13 +358,12 @@ void RenderGraph::reset()
 	for(Pass& p : m_ctx->m_passes)
 	for(Pass& p : m_ctx->m_passes)
 	{
 	{
 		p.fb().reset(nullptr);
 		p.fb().reset(nullptr);
-		p.m_secondLevelCmdbs.destroy(m_ctx->m_alloc);
-		p.m_callback.destroy(m_ctx->m_alloc);
+		p.m_secondLevelCmdbs.destroy(*m_ctx->m_pool);
+		p.m_callback.destroy(*m_ctx->m_pool);
 	}
 	}
 
 
-	m_ctx->m_graphicsCmdbs.destroy(m_ctx->m_alloc);
+	m_ctx->m_graphicsCmdbs.destroy(*m_ctx->m_pool);
 
 
-	m_ctx->m_alloc = StackAllocator<U8>();
 	m_ctx = nullptr;
 	m_ctx = nullptr;
 	++m_version;
 	++m_version;
 }
 }
@@ -372,7 +371,6 @@ void RenderGraph::reset()
 TexturePtr RenderGraph::getOrCreateRenderTarget(const TextureInitInfo& initInf, U64 hash)
 TexturePtr RenderGraph::getOrCreateRenderTarget(const TextureInitInfo& initInf, U64 hash)
 {
 {
 	ANKI_ASSERT(hash);
 	ANKI_ASSERT(hash);
-	auto alloc = getManager().getAllocator();
 
 
 	// Find a cache entry
 	// Find a cache entry
 	RenderTargetCacheEntry* entry = nullptr;
 	RenderTargetCacheEntry* entry = nullptr;
@@ -381,7 +379,7 @@ TexturePtr RenderGraph::getOrCreateRenderTarget(const TextureInitInfo& initInf,
 	{
 	{
 		// Didn't found the entry, create a new one
 		// Didn't found the entry, create a new one
 
 
-		auto it2 = m_renderTargetCache.emplace(getAllocator(), hash);
+		auto it2 = m_renderTargetCache.emplace(getMemoryPool(), hash);
 		entry = &(*it2);
 		entry = &(*it2);
 	}
 	}
 	else
 	else
@@ -406,7 +404,7 @@ TexturePtr RenderGraph::getOrCreateRenderTarget(const TextureInitInfo& initInf,
 		tex = getManager().newTexture(initInf);
 		tex = getManager().newTexture(initInf);
 
 
 		ANKI_ASSERT(entry->m_texturesInUse == entry->m_textures.getSize());
 		ANKI_ASSERT(entry->m_texturesInUse == entry->m_textures.getSize());
-		entry->m_textures.resize(alloc, entry->m_textures.getSize() + 1);
+		entry->m_textures.resize(getMemoryPool(), entry->m_textures.getSize() + 1);
 		entry->m_textures[entry->m_textures.getSize() - 1] = tex;
 		entry->m_textures[entry->m_textures.getSize() - 1] = tex;
 		++entry->m_texturesInUse;
 		++entry->m_texturesInUse;
 	}
 	}
@@ -516,7 +514,7 @@ FramebufferPtr RenderGraph::getOrCreateFramebuffer(const FramebufferDescription&
 
 
 		// Create
 		// Create
 		fb = getManager().newFramebuffer(fbInit);
 		fb = getManager().newFramebuffer(fbInit);
-		m_fbCache.emplace(getAllocator(), hash, fb);
+		m_fbCache.emplace(getMemoryPool(), hash, fb);
 	}
 	}
 
 
 	return fb;
 	return fb;
@@ -687,13 +685,13 @@ Bool RenderGraph::passHasUnmetDependencies(const BakeContext& ctx, U32 passIdx)
 	return depends;
 	return depends;
 }
 }
 
 
-RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription& descr, StackAllocator<U8>& alloc)
+RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription& descr, StackMemoryPool& pool)
 {
 {
 	// Allocate
 	// Allocate
-	BakeContext* ctx = alloc.newInstance<BakeContext>(alloc);
+	BakeContext* ctx = anki::newInstance<BakeContext>(pool, &pool);
 
 
 	// Init the resources
 	// Init the resources
-	ctx->m_rts.create(alloc, descr.m_renderTargets.getSize());
+	ctx->m_rts.create(pool, descr.m_renderTargets.getSize());
 	for(U32 rtIdx = 0; rtIdx < ctx->m_rts.getSize(); ++rtIdx)
 	for(U32 rtIdx = 0; rtIdx < ctx->m_rts.getSize(); ++rtIdx)
 	{
 	{
 		RT& outRt = ctx->m_rts[rtIdx];
 		RT& outRt = ctx->m_rts[rtIdx];
@@ -723,7 +721,7 @@ RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription&
 
 
 		// Init the usage
 		// Init the usage
 		const U32 surfOrVolumeCount = getTextureSurfOrVolCount(outRt.m_texture);
 		const U32 surfOrVolumeCount = getTextureSurfOrVolCount(outRt.m_texture);
-		outRt.m_surfOrVolUsages.create(alloc, surfOrVolumeCount, TextureUsageBit::kNone);
+		outRt.m_surfOrVolUsages.create(pool, surfOrVolumeCount, TextureUsageBit::kNone);
 		if(imported && inRt.m_importedAndUndefinedUsage)
 		if(imported && inRt.m_importedAndUndefinedUsage)
 		{
 		{
 			// Get the usage from previous frames
 			// Get the usage from previous frames
@@ -750,12 +748,12 @@ RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription&
 			}
 			}
 		}
 		}
 
 
-		outRt.m_lastBatchThatTransitionedIt.create(alloc, surfOrVolumeCount, kMaxU16);
+		outRt.m_lastBatchThatTransitionedIt.create(pool, surfOrVolumeCount, kMaxU16);
 		outRt.m_imported = imported;
 		outRt.m_imported = imported;
 	}
 	}
 
 
 	// Buffers
 	// Buffers
-	ctx->m_buffers.create(alloc, descr.m_buffers.getSize());
+	ctx->m_buffers.create(pool, descr.m_buffers.getSize());
 	for(U32 buffIdx = 0; buffIdx < ctx->m_buffers.getSize(); ++buffIdx)
 	for(U32 buffIdx = 0; buffIdx < ctx->m_buffers.getSize(); ++buffIdx)
 	{
 	{
 		ctx->m_buffers[buffIdx].m_usage = descr.m_buffers[buffIdx].m_usage;
 		ctx->m_buffers[buffIdx].m_usage = descr.m_buffers[buffIdx].m_usage;
@@ -766,7 +764,7 @@ RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription&
 	}
 	}
 
 
 	// AS
 	// AS
-	ctx->m_as.create(alloc, descr.m_as.getSize());
+	ctx->m_as.create(pool, descr.m_as.getSize());
 	for(U32 i = 0; i < descr.m_as.getSize(); ++i)
 	for(U32 i = 0; i < descr.m_as.getSize(); ++i)
 	{
 	{
 		ctx->m_as[i].m_usage = descr.m_as[i].m_usage;
 		ctx->m_as[i].m_usage = descr.m_as[i].m_usage;
@@ -779,22 +777,22 @@ RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription&
 	return ctx;
 	return ctx;
 }
 }
 
 
-void RenderGraph::initRenderPassesAndSetDeps(const RenderGraphDescription& descr, StackAllocator<U8>& alloc)
+void RenderGraph::initRenderPassesAndSetDeps(const RenderGraphDescription& descr, StackMemoryPool& pool)
 {
 {
 	BakeContext& ctx = *m_ctx;
 	BakeContext& ctx = *m_ctx;
 	const U32 passCount = descr.m_passes.getSize();
 	const U32 passCount = descr.m_passes.getSize();
 	ANKI_ASSERT(passCount > 0);
 	ANKI_ASSERT(passCount > 0);
 
 
-	ctx.m_passes.create(alloc, passCount);
+	ctx.m_passes.create(pool, passCount);
 	for(U32 passIdx = 0; passIdx < passCount; ++passIdx)
 	for(U32 passIdx = 0; passIdx < passCount; ++passIdx)
 	{
 	{
 		const RenderPassDescriptionBase& inPass = *descr.m_passes[passIdx];
 		const RenderPassDescriptionBase& inPass = *descr.m_passes[passIdx];
 		Pass& outPass = ctx.m_passes[passIdx];
 		Pass& outPass = ctx.m_passes[passIdx];
 
 
-		outPass.m_callback.copy(inPass.m_callback, alloc);
+		outPass.m_callback.copy(inPass.m_callback, pool);
 
 
 		// Create consumer info
 		// Create consumer info
-		outPass.m_consumedTextures.resize(alloc, inPass.m_rtDeps.getSize());
+		outPass.m_consumedTextures.resize(pool, inPass.m_rtDeps.getSize());
 		for(U32 depIdx = 0; depIdx < inPass.m_rtDeps.getSize(); ++depIdx)
 		for(U32 depIdx = 0; depIdx < inPass.m_rtDeps.getSize(); ++depIdx)
 		{
 		{
 			const RenderPassDependency& inDep = inPass.m_rtDeps[depIdx];
 			const RenderPassDependency& inDep = inPass.m_rtDeps[depIdx];
@@ -838,7 +836,7 @@ void RenderGraph::initRenderPassesAndSetDeps(const RenderGraphDescription& descr
 			const RenderPassDescriptionBase& prevPass = *descr.m_passes[prevPassIdx];
 			const RenderPassDescriptionBase& prevPass = *descr.m_passes[prevPassIdx];
 			if(passADependsOnB(inPass, prevPass))
 			if(passADependsOnB(inPass, prevPass))
 			{
 			{
-				outPass.m_dependsOn.emplaceBack(alloc, prevPassIdx);
+				outPass.m_dependsOn.emplaceBack(pool, prevPassIdx);
 			}
 			}
 		}
 		}
 	}
 	}
@@ -854,7 +852,7 @@ void RenderGraph::initBatches()
 	Bool setTimestamp = m_ctx->m_gatherStatistics;
 	Bool setTimestamp = m_ctx->m_gatherStatistics;
 	while(passesAssignedToBatchCount < passCount)
 	while(passesAssignedToBatchCount < passCount)
 	{
 	{
-		m_ctx->m_batches.emplaceBack(m_ctx->m_alloc);
+		m_ctx->m_batches.emplaceBack(*m_ctx->m_pool);
 		Batch& batch = m_ctx->m_batches.getBack();
 		Batch& batch = m_ctx->m_batches.getBack();
 
 
 		Bool drawsToPresentable = false;
 		Bool drawsToPresentable = false;
@@ -865,7 +863,7 @@ void RenderGraph::initBatches()
 			{
 			{
 				// Add to the batch
 				// Add to the batch
 				++passesAssignedToBatchCount;
 				++passesAssignedToBatchCount;
-				batch.m_passIndices.emplaceBack(m_ctx->m_alloc, i);
+				batch.m_passIndices.emplaceBack(*m_ctx->m_pool, i);
 
 
 				// Will batch draw to the swapchain?
 				// Will batch draw to the swapchain?
 				drawsToPresentable = drawsToPresentable || m_ctx->m_passes[i].m_drawsToPresentable;
 				drawsToPresentable = drawsToPresentable || m_ctx->m_passes[i].m_drawsToPresentable;
@@ -881,7 +879,7 @@ void RenderGraph::initBatches()
 			cmdbInit.m_flags = CommandBufferFlag::kGeneralWork;
 			cmdbInit.m_flags = CommandBufferFlag::kGeneralWork;
 			CommandBufferPtr cmdb = getManager().newCommandBuffer(cmdbInit);
 			CommandBufferPtr cmdb = getManager().newCommandBuffer(cmdbInit);
 
 
-			m_ctx->m_graphicsCmdbs.emplaceBack(m_ctx->m_alloc, cmdb);
+			m_ctx->m_graphicsCmdbs.emplaceBack(*m_ctx->m_pool, cmdb);
 
 
 			batch.m_cmdb = cmdb.get();
 			batch.m_cmdb = cmdb.get();
 
 
@@ -911,7 +909,7 @@ void RenderGraph::initBatches()
 	}
 	}
 }
 }
 
 
-void RenderGraph::initGraphicsPasses(const RenderGraphDescription& descr, StackAllocator<U8>& alloc)
+void RenderGraph::initGraphicsPasses(const RenderGraphDescription& descr, StackMemoryPool& pool)
 {
 {
 	BakeContext& ctx = *m_ctx;
 	BakeContext& ctx = *m_ctx;
 	const U32 passCount = descr.m_passes.getSize();
 	const U32 passCount = descr.m_passes.getSize();
@@ -955,7 +953,7 @@ void RenderGraph::initGraphicsPasses(const RenderGraphDescription& descr, StackA
 				// Do some pre-work for the second level command buffers
 				// Do some pre-work for the second level command buffers
 				if(inPass.m_secondLevelCmdbsCount)
 				if(inPass.m_secondLevelCmdbsCount)
 				{
 				{
-					outPass.m_secondLevelCmdbs.create(alloc, inPass.m_secondLevelCmdbsCount);
+					outPass.m_secondLevelCmdbs.create(pool, inPass.m_secondLevelCmdbsCount);
 					CommandBufferInitInfo& cmdbInit = outPass.m_secondLevelCmdbInitInfo;
 					CommandBufferInitInfo& cmdbInit = outPass.m_secondLevelCmdbInitInfo;
 					cmdbInit.m_flags = CommandBufferFlag::kGeneralWork | CommandBufferFlag::kSecondLevel;
 					cmdbInit.m_flags = CommandBufferFlag::kGeneralWork | CommandBufferFlag::kSecondLevel;
 					ANKI_ASSERT(cmdbInit.m_framebuffer.isCreated());
 					ANKI_ASSERT(cmdbInit.m_framebuffer.isCreated());
@@ -1038,7 +1036,7 @@ void RenderGraph::setTextureBarrier(Batch& batch, const RenderPassDependency& de
 				{
 				{
 					// Create a new barrier for this surface
 					// Create a new barrier for this surface
 
 
-					batch.m_textureBarriersBefore.emplaceBack(ctx.m_alloc, rtIdx, crntUsage, depUsage, surf);
+					batch.m_textureBarriersBefore.emplaceBack(*ctx.m_pool, rtIdx, crntUsage, depUsage, surf);
 
 
 					crntUsage = depUsage;
 					crntUsage = depUsage;
 					rt.m_lastBatchThatTransitionedIt[surfOrVolIdx] = U16(batchIdx);
 					rt.m_lastBatchThatTransitionedIt[surfOrVolIdx] = U16(batchIdx);
@@ -1052,7 +1050,7 @@ void RenderGraph::setTextureBarrier(Batch& batch, const RenderPassDependency& de
 void RenderGraph::setBatchBarriers(const RenderGraphDescription& descr)
 void RenderGraph::setBatchBarriers(const RenderGraphDescription& descr)
 {
 {
 	BakeContext& ctx = *m_ctx;
 	BakeContext& ctx = *m_ctx;
-	const StackAllocator<U8>& alloc = ctx.m_alloc;
+	StackMemoryPool& pool = *ctx.m_pool;
 
 
 	// For all batches
 	// For all batches
 	for(Batch& batch : ctx.m_batches)
 	for(Batch& batch : ctx.m_batches)
@@ -1089,7 +1087,7 @@ void RenderGraph::setBatchBarriers(const RenderGraphDescription& descr)
 				{
 				{
 					// Buff hasn't had a barrier in this batch, add a new barrier
 					// Buff hasn't had a barrier in this batch, add a new barrier
 
 
-					batch.m_bufferBarriersBefore.emplaceBack(alloc, buffIdx, crntUsage, depUsage);
+					batch.m_bufferBarriersBefore.emplaceBack(pool, buffIdx, crntUsage, depUsage);
 
 
 					crntUsage = depUsage;
 					crntUsage = depUsage;
 					buffHasBarrierMask.set(buffIdx);
 					buffHasBarrierMask.set(buffIdx);
@@ -1132,7 +1130,7 @@ void RenderGraph::setBatchBarriers(const RenderGraphDescription& descr)
 				{
 				{
 					// AS doesn't have a barrier in this batch, create a new one
 					// AS doesn't have a barrier in this batch, create a new one
 
 
-					batch.m_asBarriersBefore.emplaceBack(alloc, asIdx, crntUsage, depUsage);
+					batch.m_asBarriersBefore.emplaceBack(pool, asIdx, crntUsage, depUsage);
 					crntUsage = depUsage;
 					crntUsage = depUsage;
 					asHasBarrierMask.set(asIdx);
 					asHasBarrierMask.set(asIdx);
 				}
 				}
@@ -1203,22 +1201,22 @@ void RenderGraph::setBatchBarriers(const RenderGraphDescription& descr)
 	} // For all batches
 	} // For all batches
 }
 }
 
 
-void RenderGraph::compileNewGraph(const RenderGraphDescription& descr, StackAllocator<U8>& alloc)
+void RenderGraph::compileNewGraph(const RenderGraphDescription& descr, StackMemoryPool& pool)
 {
 {
 	ANKI_TRACE_SCOPED_EVENT(GR_RENDER_GRAPH_COMPILE);
 	ANKI_TRACE_SCOPED_EVENT(GR_RENDER_GRAPH_COMPILE);
 
 
 	// Init the context
 	// Init the context
-	BakeContext& ctx = *newContext(descr, alloc);
+	BakeContext& ctx = *newContext(descr, pool);
 	m_ctx = &ctx;
 	m_ctx = &ctx;
 
 
 	// Init the passes and find the dependencies between passes
 	// Init the passes and find the dependencies between passes
-	initRenderPassesAndSetDeps(descr, alloc);
+	initRenderPassesAndSetDeps(descr, pool);
 
 
 	// Walk the graph and create pass batches
 	// Walk the graph and create pass batches
 	initBatches();
 	initBatches();
 
 
 	// Now that we know the batches every pass belongs init the graphics passes
 	// Now that we know the batches every pass belongs init the graphics passes
-	initGraphicsPasses(descr, alloc);
+	initGraphicsPasses(descr, pool);
 
 
 	// Create barriers between batches
 	// Create barriers between batches
 	setBatchBarriers(descr);
 	setBatchBarriers(descr);
@@ -1408,7 +1406,7 @@ void RenderGraph::periodicCleanup()
 			DynamicArray<TexturePtr> newArray;
 			DynamicArray<TexturePtr> newArray;
 			if(entry.m_texturesInUse > 0)
 			if(entry.m_texturesInUse > 0)
 			{
 			{
-				newArray.create(getAllocator(), entry.m_texturesInUse);
+				newArray.create(getMemoryPool(), entry.m_texturesInUse);
 			}
 			}
 
 
 			// Populate the new array
 			// Populate the new array
@@ -1418,7 +1416,7 @@ void RenderGraph::periodicCleanup()
 			}
 			}
 
 
 			// Destroy the old array and the rest of the textures
 			// Destroy the old array and the rest of the textures
-			entry.m_textures.destroy(getAllocator());
+			entry.m_textures.destroy(getMemoryPool());
 
 
 			// Move new array
 			// Move new array
 			entry.m_textures = std::move(newArray);
 			entry.m_textures = std::move(newArray);
@@ -1456,14 +1454,14 @@ void RenderGraph::getStatistics(RenderGraphStatistics& statistics) const
 }
 }
 
 
 #if ANKI_DBG_RENDER_GRAPH
 #if ANKI_DBG_RENDER_GRAPH
-StringRaii RenderGraph::textureUsageToStr(StackAllocator<U8>& alloc, TextureUsageBit usage)
+StringRaii RenderGraph::textureUsageToStr(StackMemoryPool& pool, TextureUsageBit usage)
 {
 {
 	if(!usage)
 	if(!usage)
 	{
 	{
-		return StringRaii(alloc, "None");
+		return StringRaii(&pool, "None");
 	}
 	}
 
 
-	StringListRaii slist(alloc);
+	StringListRaii slist(&pool);
 
 
 #	define ANKI_TEX_USAGE(u) \
 #	define ANKI_TEX_USAGE(u) \
 		if(!!(usage & TextureUsageBit::u)) \
 		if(!!(usage & TextureUsageBit::u)) \
@@ -1471,24 +1469,24 @@ StringRaii RenderGraph::textureUsageToStr(StackAllocator<U8>& alloc, TextureUsag
 			slist.pushBackSprintf("%s", #u); \
 			slist.pushBackSprintf("%s", #u); \
 		}
 		}
 
 
-	ANKI_TEX_USAGE(SAMPLED_GEOMETRY);
-	ANKI_TEX_USAGE(SAMPLED_FRAGMENT);
-	ANKI_TEX_USAGE(SAMPLED_COMPUTE);
-	ANKI_TEX_USAGE(SAMPLED_TRACE_RAYS);
-	ANKI_TEX_USAGE(IMAGE_GEOMETRY_READ);
-	ANKI_TEX_USAGE(IMAGE_GEOMETRY_WRITE);
-	ANKI_TEX_USAGE(IMAGE_FRAGMENT_READ);
-	ANKI_TEX_USAGE(IMAGE_FRAGMENT_WRITE);
-	ANKI_TEX_USAGE(IMAGE_COMPUTE_READ);
-	ANKI_TEX_USAGE(IMAGE_COMPUTE_WRITE);
-	ANKI_TEX_USAGE(IMAGE_TRACE_RAYS_READ);
-	ANKI_TEX_USAGE(IMAGE_TRACE_RAYS_WRITE);
-	ANKI_TEX_USAGE(FRAMEBUFFER_ATTACHMENT_READ);
-	ANKI_TEX_USAGE(FRAMEBUFFER_ATTACHMENT_WRITE);
-	ANKI_TEX_USAGE(TRANSFER_DESTINATION);
-	ANKI_TEX_USAGE(GENERATE_MIPMAPS);
-	ANKI_TEX_USAGE(PRESENT);
-	ANKI_TEX_USAGE(FRAMEBUFFER_SHADING_RATE);
+	ANKI_TEX_USAGE(kSampledGeometry);
+	ANKI_TEX_USAGE(kSampledFragment);
+	ANKI_TEX_USAGE(kSampledCompute);
+	ANKI_TEX_USAGE(kSampledTraceRays);
+	ANKI_TEX_USAGE(kImageGeometryRead);
+	ANKI_TEX_USAGE(kImageGeometryWrite);
+	ANKI_TEX_USAGE(kImageFragmentRead);
+	ANKI_TEX_USAGE(kImageFragmentWrite);
+	ANKI_TEX_USAGE(kImageComputeRead);
+	ANKI_TEX_USAGE(kImageComputeWrite);
+	ANKI_TEX_USAGE(kImageTraceRaysRead);
+	ANKI_TEX_USAGE(kImageTraceRaysWrite);
+	ANKI_TEX_USAGE(kFramebufferRead);
+	ANKI_TEX_USAGE(kFramebufferWrite);
+	ANKI_TEX_USAGE(kTransferDestination);
+	ANKI_TEX_USAGE(kGenerateMipmaps);
+	ANKI_TEX_USAGE(kPresent);
+	ANKI_TEX_USAGE(kFramebufferShadingRate);
 
 
 	if(!usage)
 	if(!usage)
 	{
 	{
@@ -1498,14 +1496,14 @@ StringRaii RenderGraph::textureUsageToStr(StackAllocator<U8>& alloc, TextureUsag
 #	undef ANKI_TEX_USAGE
 #	undef ANKI_TEX_USAGE
 
 
 	ANKI_ASSERT(!slist.isEmpty());
 	ANKI_ASSERT(!slist.isEmpty());
-	StringRaii str(alloc);
+	StringRaii str(&pool);
 	slist.join(" | ", str);
 	slist.join(" | ", str);
 	return str;
 	return str;
 }
 }
 
 
-StringRaii RenderGraph::bufferUsageToStr(StackAllocator<U8>& alloc, BufferUsageBit usage)
+StringRaii RenderGraph::bufferUsageToStr(StackMemoryPool& pool, BufferUsageBit usage)
 {
 {
-	StringListRaii slist(alloc);
+	StringListRaii slist(&pool);
 
 
 #	define ANKI_BUFF_USAGE(u) \
 #	define ANKI_BUFF_USAGE(u) \
 		if(!!(usage & BufferUsageBit::u)) \
 		if(!!(usage & BufferUsageBit::u)) \
@@ -1533,14 +1531,14 @@ StringRaii RenderGraph::bufferUsageToStr(StackAllocator<U8>& alloc, BufferUsageB
 	ANKI_BUFF_USAGE(kTextureComputeWrite);
 	ANKI_BUFF_USAGE(kTextureComputeWrite);
 	ANKI_BUFF_USAGE(kTextureTraceRaysRead);
 	ANKI_BUFF_USAGE(kTextureTraceRaysRead);
 	ANKI_BUFF_USAGE(kTextureTraceRaysWrite);
 	ANKI_BUFF_USAGE(kTextureTraceRaysWrite);
-	ANKI_BUFF_USAGE(INDEX);
-	ANKI_BUFF_USAGE(VERTEX);
-	ANKI_BUFF_USAGE(INDIRECT_COMPUTE);
-	ANKI_BUFF_USAGE(INDIRECT_DRAW);
-	ANKI_BUFF_USAGE(INDIRECT_TRACE_RAYS);
-	ANKI_BUFF_USAGE(TRANSFER_SOURCE);
-	ANKI_BUFF_USAGE(TRANSFER_DESTINATION);
-	ANKI_BUFF_USAGE(ACCELERATION_STRUCTURE_BUILD);
+	ANKI_BUFF_USAGE(kIndex);
+	ANKI_BUFF_USAGE(kVertex);
+	ANKI_BUFF_USAGE(kIndirectCompute);
+	ANKI_BUFF_USAGE(kIndirectDraw);
+	ANKI_BUFF_USAGE(kIndirectTraceRays);
+	ANKI_BUFF_USAGE(kTransferSource);
+	ANKI_BUFF_USAGE(kTransferDestination);
+	ANKI_BUFF_USAGE(kAccelerationStructureBuild);
 
 
 	if(!usage)
 	if(!usage)
 	{
 	{
@@ -1550,14 +1548,14 @@ StringRaii RenderGraph::bufferUsageToStr(StackAllocator<U8>& alloc, BufferUsageB
 #	undef ANKI_BUFF_USAGE
 #	undef ANKI_BUFF_USAGE
 
 
 	ANKI_ASSERT(!slist.isEmpty());
 	ANKI_ASSERT(!slist.isEmpty());
-	StringRaii str(alloc);
+	StringRaii str(&pool);
 	slist.join(" | ", str);
 	slist.join(" | ", str);
 	return str;
 	return str;
 }
 }
 
 
-StringRaii RenderGraph::asUsageToStr(StackAllocator<U8>& alloc, AccelerationStructureUsageBit usage)
+StringRaii RenderGraph::asUsageToStr(StackMemoryPool& pool, AccelerationStructureUsageBit usage)
 {
 {
-	StringListRaii slist(alloc);
+	StringListRaii slist(&pool);
 
 
 #	define ANKI_AS_USAGE(u) \
 #	define ANKI_AS_USAGE(u) \
 		if(!!(usage & AccelerationStructureUsageBit::u)) \
 		if(!!(usage & AccelerationStructureUsageBit::u)) \
@@ -1565,12 +1563,12 @@ StringRaii RenderGraph::asUsageToStr(StackAllocator<U8>& alloc, AccelerationStru
 			slist.pushBackSprintf("%s", #u); \
 			slist.pushBackSprintf("%s", #u); \
 		}
 		}
 
 
-	ANKI_AS_USAGE(BUILD);
-	ANKI_AS_USAGE(ATTACH);
-	ANKI_AS_USAGE(GEOMETRY_READ);
-	ANKI_AS_USAGE(FRAGMENT_READ);
-	ANKI_AS_USAGE(COMPUTE_READ);
-	ANKI_AS_USAGE(TRACE_RAYS_READ);
+	ANKI_AS_USAGE(kBuild);
+	ANKI_AS_USAGE(kAttach);
+	ANKI_AS_USAGE(kGeometryRead);
+	ANKI_AS_USAGE(kFragmentRead);
+	ANKI_AS_USAGE(kComputeRead);
+	ANKI_AS_USAGE(kTraceRaysRead);
 
 
 	if(!usage)
 	if(!usage)
 	{
 	{
@@ -1580,7 +1578,7 @@ StringRaii RenderGraph::asUsageToStr(StackAllocator<U8>& alloc, AccelerationStru
 #	undef ANKI_AS_USAGE
 #	undef ANKI_AS_USAGE
 
 
 	ANKI_ASSERT(!slist.isEmpty());
 	ANKI_ASSERT(!slist.isEmpty());
-	StringRaii str(alloc);
+	StringRaii str(&pool);
 	slist.join(" | ", str);
 	slist.join(" | ", str);
 	return str;
 	return str;
 }
 }
@@ -1591,8 +1589,8 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 	ANKI_GR_LOGW("Running with debug code");
 	ANKI_GR_LOGW("Running with debug code");
 
 
 	static constexpr Array<const char*, 5> COLORS = {"red", "green", "blue", "magenta", "cyan"};
 	static constexpr Array<const char*, 5> COLORS = {"red", "green", "blue", "magenta", "cyan"};
-	auto alloc = ctx.m_alloc;
-	StringListRaii slist(alloc);
+	StackMemoryPool& pool = *ctx.m_pool;
+	StringListRaii slist(&pool);
 
 
 	slist.pushBackSprintf("digraph {\n");
 	slist.pushBackSprintf("digraph {\n");
 	slist.pushBackSprintf("\t//splines = ortho;\nconcentrate = true;\n");
 	slist.pushBackSprintf("\t//splines = ortho;\nconcentrate = true;\n");
@@ -1614,7 +1612,7 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 
 
 			slist.pushBackSprintf(
 			slist.pushBackSprintf(
 				"\t\"%s\"[color=%s,style=%s,shape=box];\n", passName.cstr(), COLORS[batchIdx % COLORS.getSize()],
 				"\t\"%s\"[color=%s,style=%s,shape=box];\n", passName.cstr(), COLORS[batchIdx % COLORS.getSize()],
-				(descr.m_passes[passIdx]->m_type == RenderPassDescriptionBase::Type::GRAPHICS) ? "bold" : "dashed");
+				(descr.m_passes[passIdx]->m_type == RenderPassDescriptionBase::Type::kGraphics) ? "bold" : "dashed");
 
 
 			for(U32 depIdx : ctx.m_passes[passIdx].m_dependsOn)
 			for(U32 depIdx : ctx.m_passes[passIdx].m_dependsOn)
 			{
 			{
@@ -1641,27 +1639,27 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 
 
 	// Barriers
 	// Barriers
 	// slist.pushBackSprintf("subgraph cluster_1 {\n");
 	// slist.pushBackSprintf("subgraph cluster_1 {\n");
-	StringRaii prevBubble(ctx.m_alloc);
+	StringRaii prevBubble(&pool);
 	prevBubble.create("START");
 	prevBubble.create("START");
 	for(U32 batchIdx = 0; batchIdx < ctx.m_batches.getSize(); ++batchIdx)
 	for(U32 batchIdx = 0; batchIdx < ctx.m_batches.getSize(); ++batchIdx)
 	{
 	{
 		const Batch& batch = ctx.m_batches[batchIdx];
 		const Batch& batch = ctx.m_batches[batchIdx];
 
 
-		StringRaii batchName(ctx.m_alloc);
+		StringRaii batchName(&pool);
 		batchName.sprintf("batch%u", batchIdx);
 		batchName.sprintf("batch%u", batchIdx);
 
 
 		for(U32 barrierIdx = 0; barrierIdx < batch.m_textureBarriersBefore.getSize(); ++barrierIdx)
 		for(U32 barrierIdx = 0; barrierIdx < batch.m_textureBarriersBefore.getSize(); ++barrierIdx)
 		{
 		{
 			const TextureBarrier& barrier = batch.m_textureBarriersBefore[barrierIdx];
 			const TextureBarrier& barrier = batch.m_textureBarriersBefore[barrierIdx];
 
 
-			StringRaii barrierLabel(ctx.m_alloc);
+			StringRaii barrierLabel(&pool);
 			barrierLabel.sprintf("<b>%s</b> (mip,dp,f,l)=(%u,%u,%u,%u)<br/>%s <b>to</b> %s",
 			barrierLabel.sprintf("<b>%s</b> (mip,dp,f,l)=(%u,%u,%u,%u)<br/>%s <b>to</b> %s",
 								 &descr.m_renderTargets[barrier.m_idx].m_name[0], barrier.m_surface.m_level,
 								 &descr.m_renderTargets[barrier.m_idx].m_name[0], barrier.m_surface.m_level,
 								 barrier.m_surface.m_depth, barrier.m_surface.m_face, barrier.m_surface.m_layer,
 								 barrier.m_surface.m_depth, barrier.m_surface.m_face, barrier.m_surface.m_layer,
-								 textureUsageToStr(alloc, barrier.m_usageBefore).cstr(),
-								 textureUsageToStr(alloc, barrier.m_usageAfter).cstr());
+								 textureUsageToStr(pool, barrier.m_usageBefore).cstr(),
+								 textureUsageToStr(pool, barrier.m_usageAfter).cstr());
 
 
-			StringRaii barrierName(ctx.m_alloc);
+			StringRaii barrierName(&pool);
 			barrierName.sprintf("%s tex barrier%u", batchName.cstr(), barrierIdx);
 			barrierName.sprintf("%s tex barrier%u", batchName.cstr(), barrierIdx);
 
 
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
@@ -1675,12 +1673,12 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 		{
 		{
 			const BufferBarrier& barrier = batch.m_bufferBarriersBefore[barrierIdx];
 			const BufferBarrier& barrier = batch.m_bufferBarriersBefore[barrierIdx];
 
 
-			StringRaii barrierLabel(ctx.m_alloc);
+			StringRaii barrierLabel(&pool);
 			barrierLabel.sprintf("<b>%s</b><br/>%s <b>to</b> %s", &descr.m_buffers[barrier.m_idx].m_name[0],
 			barrierLabel.sprintf("<b>%s</b><br/>%s <b>to</b> %s", &descr.m_buffers[barrier.m_idx].m_name[0],
-								 bufferUsageToStr(alloc, barrier.m_usageBefore).cstr(),
-								 bufferUsageToStr(alloc, barrier.m_usageAfter).cstr());
+								 bufferUsageToStr(pool, barrier.m_usageBefore).cstr(),
+								 bufferUsageToStr(pool, barrier.m_usageAfter).cstr());
 
 
-			StringRaii barrierName(ctx.m_alloc);
+			StringRaii barrierName(&pool);
 			barrierName.sprintf("%s buff barrier%u", batchName.cstr(), barrierIdx);
 			barrierName.sprintf("%s buff barrier%u", batchName.cstr(), barrierIdx);
 
 
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
@@ -1694,12 +1692,12 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 		{
 		{
 			const ASBarrier& barrier = batch.m_asBarriersBefore[barrierIdx];
 			const ASBarrier& barrier = batch.m_asBarriersBefore[barrierIdx];
 
 
-			StringRaii barrierLabel(ctx.m_alloc);
+			StringRaii barrierLabel(&pool);
 			barrierLabel.sprintf("<b>%s</b><br/>%s <b>to</b> %s", descr.m_as[barrier.m_idx].m_name.getBegin(),
 			barrierLabel.sprintf("<b>%s</b><br/>%s <b>to</b> %s", descr.m_as[barrier.m_idx].m_name.getBegin(),
-								 asUsageToStr(alloc, barrier.m_usageBefore).cstr(),
-								 asUsageToStr(alloc, barrier.m_usageAfter).cstr());
+								 asUsageToStr(pool, barrier.m_usageBefore).cstr(),
+								 asUsageToStr(pool, barrier.m_usageAfter).cstr());
 
 
-			StringRaii barrierName(ctx.m_alloc);
+			StringRaii barrierName(&pool);
 			barrierName.sprintf("%s AS barrier%u", batchName.cstr(), barrierIdx);
 			barrierName.sprintf("%s AS barrier%u", batchName.cstr(), barrierIdx);
 
 
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold,shape=box,label=< %s >];\n", barrierName.cstr(),
@@ -1712,7 +1710,7 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 		for(U32 passIdx : batch.m_passIndices)
 		for(U32 passIdx : batch.m_passIndices)
 		{
 		{
 			const RenderPassDescriptionBase& pass = *descr.m_passes[passIdx];
 			const RenderPassDescriptionBase& pass = *descr.m_passes[passIdx];
-			StringRaii passName(alloc);
+			StringRaii passName(&pool);
 			passName.sprintf("%s pass", pass.m_name.cstr());
 			passName.sprintf("%s pass", pass.m_name.cstr());
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold];\n", passName.cstr(),
 			slist.pushBackSprintf("\t\"%s\"[color=%s,style=bold];\n", passName.cstr(),
 								  COLORS[batchIdx % COLORS.getSize()]);
 								  COLORS[batchIdx % COLORS.getSize()]);
@@ -1726,11 +1724,11 @@ Error RenderGraph::dumpDependencyDotFile(const RenderGraphDescription& descr, co
 	slist.pushBackSprintf("}");
 	slist.pushBackSprintf("}");
 
 
 	File file;
 	File file;
-	ANKI_CHECK(file.open(StringRaii(alloc).sprintf("%s/rgraph_%05u.dot", &path[0], m_version).toCString(),
+	ANKI_CHECK(file.open(StringRaii(&pool).sprintf("%s/rgraph_%05u.dot", &path[0], m_version).toCString(),
 						 FileOpenFlag::kWrite));
 						 FileOpenFlag::kWrite));
 	for(const String& s : slist)
 	for(const String& s : slist)
 	{
 	{
-		ANKI_CHECK(file.writeText("%s", &s[0]));
+		ANKI_CHECK(file.writeTextf("%s", &s[0]));
 	}
 	}
 
 
 	return Error::kNone;
 	return Error::kNone;

+ 25 - 29
AnKi/Gr/RenderGraph.h

@@ -321,18 +321,18 @@ class RenderPassDescriptionBase
 public:
 public:
 	virtual ~RenderPassDescriptionBase()
 	virtual ~RenderPassDescriptionBase()
 	{
 	{
-		m_name.destroy(m_alloc); // To avoid the assertion
-		m_rtDeps.destroy(m_alloc);
-		m_buffDeps.destroy(m_alloc);
-		m_asDeps.destroy(m_alloc);
-		m_callback.destroy(m_alloc);
+		m_name.destroy(*m_pool); // To avoid the assertion
+		m_rtDeps.destroy(*m_pool);
+		m_buffDeps.destroy(*m_pool);
+		m_asDeps.destroy(*m_pool);
+		m_callback.destroy(*m_pool);
 	}
 	}
 
 
 	template<typename TFunc>
 	template<typename TFunc>
 	void setWork(U32 secondLeveCmdbCount, TFunc func)
 	void setWork(U32 secondLeveCmdbCount, TFunc func)
 	{
 	{
 		ANKI_ASSERT(m_type == Type::kGraphics || secondLeveCmdbCount == 0);
 		ANKI_ASSERT(m_type == Type::kGraphics || secondLeveCmdbCount == 0);
-		m_callback.init(m_alloc, func);
+		m_callback.init(m_pool, func);
 		m_secondLevelCmdbsCount = secondLeveCmdbCount;
 		m_secondLevelCmdbsCount = secondLeveCmdbCount;
 	}
 	}
 
 
@@ -354,7 +354,7 @@ protected:
 
 
 	Type m_type;
 	Type m_type;
 
 
-	StackAllocator<U8> m_alloc;
+	StackMemoryPool* m_pool = nullptr;
 	RenderGraphDescription* m_descr;
 	RenderGraphDescription* m_descr;
 
 
 	Function<void(RenderPassWorkContext&)> m_callback;
 	Function<void(RenderPassWorkContext&)> m_callback;
@@ -382,7 +382,7 @@ protected:
 
 
 	void setName(CString name)
 	void setName(CString name)
 	{
 	{
-		m_name.create(m_alloc, (name.isEmpty()) ? "N/A" : name);
+		m_name.create(*m_pool, (name.isEmpty()) ? "N/A" : name);
 	}
 	}
 
 
 	void fixSubresource(RenderPassDependency& dep) const;
 	void fixSubresource(RenderPassDependency& dep) const;
@@ -438,10 +438,14 @@ class GraphicsRenderPassDescription : public RenderPassDescriptionBase
 {
 {
 	friend class RenderGraphDescription;
 	friend class RenderGraphDescription;
 	friend class RenderGraph;
 	friend class RenderGraph;
-	template<typename, typename>
-	friend class GenericPoolAllocator;
 
 
 public:
 public:
+	GraphicsRenderPassDescription(RenderGraphDescription* descr)
+		: RenderPassDescriptionBase(Type::kGraphics, descr)
+	{
+		memset(&m_rtHandles[0], 0xFF, sizeof(m_rtHandles));
+	}
+
 	void setFramebufferInfo(const FramebufferDescription& fbInfo,
 	void setFramebufferInfo(const FramebufferDescription& fbInfo,
 							ConstWeakArray<RenderTargetHandle> colorRenderTargetHandles,
 							ConstWeakArray<RenderTargetHandle> colorRenderTargetHandles,
 							RenderTargetHandle depthStencilRenderTargetHandle = {},
 							RenderTargetHandle depthStencilRenderTargetHandle = {},
@@ -459,12 +463,6 @@ private:
 	FramebufferDescription m_fbDescr;
 	FramebufferDescription m_fbDescr;
 	Array<U32, 4> m_fbRenderArea = {};
 	Array<U32, 4> m_fbRenderArea = {};
 
 
-	GraphicsRenderPassDescription(RenderGraphDescription* descr)
-		: RenderPassDescriptionBase(Type::kGraphics, descr)
-	{
-		memset(&m_rtHandles[0], 0xFF, sizeof(m_rtHandles));
-	}
-
 	Bool hasFramebuffer() const
 	Bool hasFramebuffer() const
 	{
 	{
 		return m_fbDescr.m_hash != 0;
 		return m_fbDescr.m_hash != 0;
@@ -476,10 +474,8 @@ private:
 class ComputeRenderPassDescription : public RenderPassDescriptionBase
 class ComputeRenderPassDescription : public RenderPassDescriptionBase
 {
 {
 	friend class RenderGraphDescription;
 	friend class RenderGraphDescription;
-	template<typename, typename>
-	friend class GenericPoolAllocator;
 
 
-private:
+public:
 	ComputeRenderPassDescription(RenderGraphDescription* descr)
 	ComputeRenderPassDescription(RenderGraphDescription* descr)
 		: RenderPassDescriptionBase(Type::kNoGraphics, descr)
 		: RenderPassDescriptionBase(Type::kNoGraphics, descr)
 	{
 	{
@@ -494,8 +490,8 @@ class RenderGraphDescription
 	friend class RenderPassDescriptionBase;
 	friend class RenderPassDescriptionBase;
 
 
 public:
 public:
-	RenderGraphDescription(const StackAllocator<U8>& alloc)
-		: m_alloc(alloc)
+	RenderGraphDescription(StackMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
 	}
 	}
 
 
@@ -572,7 +568,7 @@ private:
 		AccelerationStructureUsageBit m_usage;
 		AccelerationStructureUsageBit m_usage;
 	};
 	};
 
 
-	StackAllocator<U8> m_alloc;
+	StackMemoryPool* m_pool = nullptr;
 	DynamicArray<RenderPassDescriptionBase*> m_passes;
 	DynamicArray<RenderPassDescriptionBase*> m_passes;
 	DynamicArray<RT> m_renderTargets;
 	DynamicArray<RT> m_renderTargets;
 	DynamicArray<Buffer> m_buffers;
 	DynamicArray<Buffer> m_buffers;
@@ -628,7 +624,7 @@ public:
 
 
 	/// @name 1st step methods
 	/// @name 1st step methods
 	/// @{
 	/// @{
-	void compileNewGraph(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
+	void compileNewGraph(const RenderGraphDescription& descr, StackMemoryPool& pool);
 	/// @}
 	/// @}
 
 
 	/// @name 2nd step methods
 	/// @name 2nd step methods
@@ -715,10 +711,10 @@ private:
 
 
 	[[nodiscard]] static RenderGraph* newInstance(GrManager* manager);
 	[[nodiscard]] static RenderGraph* newInstance(GrManager* manager);
 
 
-	BakeContext* newContext(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
-	void initRenderPassesAndSetDeps(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
+	BakeContext* newContext(const RenderGraphDescription& descr, StackMemoryPool& pool);
+	void initRenderPassesAndSetDeps(const RenderGraphDescription& descr, StackMemoryPool& pool);
 	void initBatches();
 	void initBatches();
-	void initGraphicsPasses(const RenderGraphDescription& descr, StackAllocator<U8>& alloc);
+	void initGraphicsPasses(const RenderGraphDescription& descr, StackMemoryPool& pool);
 	void setBatchBarriers(const RenderGraphDescription& descr);
 	void setBatchBarriers(const RenderGraphDescription& descr);
 
 
 	TexturePtr getOrCreateRenderTarget(const TextureInitInfo& initInf, U64 hash);
 	TexturePtr getOrCreateRenderTarget(const TextureInitInfo& initInf, U64 hash);
@@ -745,9 +741,9 @@ private:
 	/// @name Dump the dependency graph into a file.
 	/// @name Dump the dependency graph into a file.
 	/// @{
 	/// @{
 	Error dumpDependencyDotFile(const RenderGraphDescription& descr, const BakeContext& ctx, CString path) const;
 	Error dumpDependencyDotFile(const RenderGraphDescription& descr, const BakeContext& ctx, CString path) const;
-	static StringRaii textureUsageToStr(StackAllocator<U8>& alloc, TextureUsageBit usage);
-	static StringRaii bufferUsageToStr(StackAllocator<U8>& alloc, BufferUsageBit usage);
-	static StringRaii asUsageToStr(StackAllocator<U8>& alloc, AccelerationStructureUsageBit usage);
+	static StringRaii textureUsageToStr(StackMemoryPool& pool, TextureUsageBit usage);
+	static StringRaii bufferUsageToStr(StackMemoryPool& pool, BufferUsageBit usage);
+	static StringRaii asUsageToStr(StackMemoryPool& pool, AccelerationStructureUsageBit usage);
 	/// @}
 	/// @}
 
 
 	TexturePtr getTexture(RenderTargetHandle handle) const;
 	TexturePtr getTexture(RenderTargetHandle handle) const;

+ 18 - 18
AnKi/Gr/RenderGraph.inl.h

@@ -113,7 +113,7 @@ inline void RenderPassDescriptionBase::newDependency(const RenderPassDependency&
 
 
 	if(dep.m_type == RenderPassDependency::Type::kTexture)
 	if(dep.m_type == RenderPassDependency::Type::kTexture)
 	{
 	{
-		m_rtDeps.emplaceBack(m_alloc, dep);
+		m_rtDeps.emplaceBack(*m_pool, dep);
 		fixSubresource(m_rtDeps.getBack());
 		fixSubresource(m_rtDeps.getBack());
 
 
 		if(!!(dep.m_texture.m_usage & TextureUsageBit::kAllRead))
 		if(!!(dep.m_texture.m_usage & TextureUsageBit::kAllRead))
@@ -131,7 +131,7 @@ inline void RenderPassDescriptionBase::newDependency(const RenderPassDependency&
 	}
 	}
 	else if(dep.m_type == RenderPassDependency::Type::kBuffer)
 	else if(dep.m_type == RenderPassDependency::Type::kBuffer)
 	{
 	{
-		m_buffDeps.emplaceBack(m_alloc, dep);
+		m_buffDeps.emplaceBack(*m_pool, dep);
 
 
 		if(!!(dep.m_buffer.m_usage & BufferUsageBit::kAllRead))
 		if(!!(dep.m_buffer.m_usage & BufferUsageBit::kAllRead))
 		{
 		{
@@ -146,7 +146,7 @@ inline void RenderPassDescriptionBase::newDependency(const RenderPassDependency&
 	else
 	else
 	{
 	{
 		ANKI_ASSERT(dep.m_type == RenderPassDependency::Type::kAccelerationStructure);
 		ANKI_ASSERT(dep.m_type == RenderPassDependency::Type::kAccelerationStructure);
-		m_asDeps.emplaceBack(m_alloc, dep);
+		m_asDeps.emplaceBack(*m_pool, dep);
 
 
 		if(!!(dep.m_as.m_usage & AccelerationStructureUsageBit::kAllRead))
 		if(!!(dep.m_as.m_usage & AccelerationStructureUsageBit::kAllRead))
 		{
 		{
@@ -224,29 +224,29 @@ inline RenderGraphDescription::~RenderGraphDescription()
 {
 {
 	for(RenderPassDescriptionBase* pass : m_passes)
 	for(RenderPassDescriptionBase* pass : m_passes)
 	{
 	{
-		m_alloc.deleteInstance(pass);
+		deleteInstance(*m_pool, pass);
 	}
 	}
-	m_passes.destroy(m_alloc);
-	m_renderTargets.destroy(m_alloc);
-	m_buffers.destroy(m_alloc);
-	m_as.destroy(m_alloc);
+	m_passes.destroy(*m_pool);
+	m_renderTargets.destroy(*m_pool);
+	m_buffers.destroy(*m_pool);
+	m_as.destroy(*m_pool);
 }
 }
 
 
 inline GraphicsRenderPassDescription& RenderGraphDescription::newGraphicsRenderPass(CString name)
 inline GraphicsRenderPassDescription& RenderGraphDescription::newGraphicsRenderPass(CString name)
 {
 {
-	GraphicsRenderPassDescription* pass = m_alloc.newInstance<GraphicsRenderPassDescription>(this);
-	pass->m_alloc = m_alloc;
+	GraphicsRenderPassDescription* pass = newInstance<GraphicsRenderPassDescription>(*m_pool, this);
+	pass->m_pool = m_pool;
 	pass->setName(name);
 	pass->setName(name);
-	m_passes.emplaceBack(m_alloc, pass);
+	m_passes.emplaceBack(*m_pool, pass);
 	return *pass;
 	return *pass;
 }
 }
 
 
 inline ComputeRenderPassDescription& RenderGraphDescription::newComputeRenderPass(CString name)
 inline ComputeRenderPassDescription& RenderGraphDescription::newComputeRenderPass(CString name)
 {
 {
-	ComputeRenderPassDescription* pass = m_alloc.newInstance<ComputeRenderPassDescription>(this);
-	pass->m_alloc = m_alloc;
+	ComputeRenderPassDescription* pass = newInstance<ComputeRenderPassDescription>(*m_pool, this);
+	pass->m_pool = m_pool;
 	pass->setName(name);
 	pass->setName(name);
-	m_passes.emplaceBack(m_alloc, pass);
+	m_passes.emplaceBack(*m_pool, pass);
 	return *pass;
 	return *pass;
 }
 }
 
 
@@ -257,7 +257,7 @@ inline RenderTargetHandle RenderGraphDescription::importRenderTarget(TexturePtr
 		ANKI_ASSERT(rt.m_importedTex != tex && "Already imported");
 		ANKI_ASSERT(rt.m_importedTex != tex && "Already imported");
 	}
 	}
 
 
-	RT& rt = *m_renderTargets.emplaceBack(m_alloc);
+	RT& rt = *m_renderTargets.emplaceBack(*m_pool);
 	rt.m_importedTex = tex;
 	rt.m_importedTex = tex;
 	rt.m_importedLastKnownUsage = usage;
 	rt.m_importedLastKnownUsage = usage;
 	rt.m_usageDerivedByDeps = TextureUsageBit::kNone;
 	rt.m_usageDerivedByDeps = TextureUsageBit::kNone;
@@ -280,7 +280,7 @@ inline RenderTargetHandle RenderGraphDescription::newRenderTarget(const RenderTa
 	ANKI_ASSERT(initInf.m_hash && "Forgot to call RenderTargetDescription::bake");
 	ANKI_ASSERT(initInf.m_hash && "Forgot to call RenderTargetDescription::bake");
 	ANKI_ASSERT(initInf.m_usage == TextureUsageBit::kNone
 	ANKI_ASSERT(initInf.m_usage == TextureUsageBit::kNone
 				&& "Don't need to supply the usage. Render grap will find it");
 				&& "Don't need to supply the usage. Render grap will find it");
-	RT& rt = *m_renderTargets.emplaceBack(m_alloc);
+	RT& rt = *m_renderTargets.emplaceBack(*m_pool);
 	rt.m_initInfo = initInf;
 	rt.m_initInfo = initInf;
 	rt.m_hash = initInf.m_hash;
 	rt.m_hash = initInf.m_hash;
 	rt.m_importedLastKnownUsage = TextureUsageBit::kNone;
 	rt.m_importedLastKnownUsage = TextureUsageBit::kNone;
@@ -311,7 +311,7 @@ inline BufferHandle RenderGraphDescription::importBuffer(BufferPtr buff, BufferU
 					&& "Range already imported");
 					&& "Range already imported");
 	}
 	}
 
 
-	Buffer& b = *m_buffers.emplaceBack(m_alloc);
+	Buffer& b = *m_buffers.emplaceBack(*m_pool);
 	b.setName(buff->getName());
 	b.setName(buff->getName());
 	b.m_usage = usage;
 	b.m_usage = usage;
 	b.m_importedBuff = std::move(buff);
 	b.m_importedBuff = std::move(buff);
@@ -331,7 +331,7 @@ RenderGraphDescription::importAccelerationStructure(AccelerationStructurePtr as,
 		ANKI_ASSERT(a.m_importedAs != as && "Already imported");
 		ANKI_ASSERT(a.m_importedAs != as && "Already imported");
 	}
 	}
 
 
-	AS& a = *m_as.emplaceBack(m_alloc);
+	AS& a = *m_as.emplaceBack(*m_pool);
 	a.setName(as->getName());
 	a.setName(as->getName());
 	a.m_importedAs = std::move(as);
 	a.m_importedAs = std::move(as);
 	a.m_usage = usage;
 	a.m_usage = usage;

+ 16 - 17
AnKi/ShaderCompiler/Glslang.cpp

@@ -198,17 +198,17 @@ static EShLanguage ankiToGlslangShaderType(ShaderType shaderType)
 }
 }
 
 
 /// Parse Glslang's error message for the line of the error.
 /// Parse Glslang's error message for the line of the error.
-static Error parseErrorLine(CString error, GenericMemoryPoolAllocator<U8> alloc, U32& lineNumber)
+static Error parseErrorLine(CString error, BaseMemoryPool& pool, U32& lineNumber)
 {
 {
 	lineNumber = kMaxU32;
 	lineNumber = kMaxU32;
 
 
-	StringListRaii lines(alloc);
+	StringListRaii lines(&pool);
 	lines.splitString(error, '\n');
 	lines.splitString(error, '\n');
 	for(String& line : lines)
 	for(String& line : lines)
 	{
 	{
 		if(line.find("ERROR: ") == 0)
 		if(line.find("ERROR: ") == 0)
 		{
 		{
-			StringListRaii tokens(alloc);
+			StringListRaii tokens(&pool);
 			tokens.splitString(line, ':');
 			tokens.splitString(line, ':');
 
 
 			if(tokens.getSize() < 3 || (tokens.getBegin() + 2)->toNumber(lineNumber) != Error::kNone)
 			if(tokens.getSize() < 3 || (tokens.getBegin() + 2)->toNumber(lineNumber) != Error::kNone)
@@ -227,18 +227,17 @@ static Error parseErrorLine(CString error, GenericMemoryPoolAllocator<U8> alloc,
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
-static void createErrorLog(CString glslangError, CString source, GenericMemoryPoolAllocator<U8> alloc,
-						   StringRaii& outError)
+static void createErrorLog(CString glslangError, CString source, BaseMemoryPool& pool, StringRaii& outError)
 {
 {
 	U32 errorLineNumberu = 0;
 	U32 errorLineNumberu = 0;
-	const Error err = parseErrorLine(glslangError, alloc, errorLineNumberu);
+	const Error err = parseErrorLine(glslangError, pool, errorLineNumberu);
 
 
 	const I32 errorLineNumber = (!err) ? I32(errorLineNumberu) : -1;
 	const I32 errorLineNumber = (!err) ? I32(errorLineNumberu) : -1;
 
 
 	constexpr I32 lineCountAroundError = 4;
 	constexpr I32 lineCountAroundError = 4;
 
 
-	StringRaii prettySrc(alloc);
-	StringListRaii lines(alloc);
+	StringRaii prettySrc(&pool);
+	StringListRaii lines(&pool);
 
 
 	lines.splitString(source, '\n', true);
 	lines.splitString(source, '\n', true);
 
 
@@ -249,7 +248,7 @@ static void createErrorLog(CString glslangError, CString source, GenericMemoryPo
 
 
 		if(lineno >= errorLineNumber - lineCountAroundError && lineno <= errorLineNumber + lineCountAroundError)
 		if(lineno >= errorLineNumber - lineCountAroundError && lineno <= errorLineNumber + lineCountAroundError)
 		{
 		{
-			prettySrc.append(StringRaii(alloc).sprintf("%s%s\n", (lineno == errorLineNumber) ? ">>  " : "    ",
+			prettySrc.append(StringRaii(&pool).sprintf("%s%s\n", (lineno == errorLineNumber) ? ">>  " : "    ",
 													   (it->isEmpty()) ? " " : (*it).cstr()));
 													   (it->isEmpty()) ? " " : (*it).cstr()));
 		}
 		}
 	}
 	}
@@ -277,8 +276,8 @@ Error preprocessGlsl(CString in, StringRaii& out)
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
-Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolAllocator<U8> tmpAlloc,
-						  DynamicArrayRaii<U8>& spirv, StringRaii& errorMessage)
+Error compilerGlslToSpirv(CString src, ShaderType shaderType, BaseMemoryPool& tmpPool, DynamicArrayRaii<U8>& spirv,
+						  StringRaii& errorMessage)
 {
 {
 #if ANKI_GLSLANG_DUMP
 #if ANKI_GLSLANG_DUMP
 	// Dump it
 	// Dump it
@@ -286,14 +285,14 @@ Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolA
 	{
 	{
 		File file;
 		File file;
 
 
-		StringRaii tmpDir(tmpAlloc);
+		StringRaii tmpDir(&tmpPool);
 		ANKI_CHECK(getTempDirectory(tmpDir));
 		ANKI_CHECK(getTempDirectory(tmpDir));
 
 
-		StringRaii fname(tmpAlloc);
+		StringRaii fname(&tmpPool);
 		fname.sprintf("%s/%u.glsl", tmpDir.cstr(), dumpFileCount);
 		fname.sprintf("%s/%u.glsl", tmpDir.cstr(), dumpFileCount);
 		ANKI_SHADER_COMPILER_LOGW("GLSL dumping is enabled: %s", fname.cstr());
 		ANKI_SHADER_COMPILER_LOGW("GLSL dumping is enabled: %s", fname.cstr());
 		ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite));
 		ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite));
-		ANKI_CHECK(file.writeText("%s", src.cstr()));
+		ANKI_CHECK(file.writeTextf("%s", src.cstr()));
 	}
 	}
 #endif
 #endif
 
 
@@ -307,7 +306,7 @@ Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolA
 	shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
 	shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
 	if(!shader.parse(&GLSLANG_LIMITS, 100, false, messages))
 	if(!shader.parse(&GLSLANG_LIMITS, 100, false, messages))
 	{
 	{
-		createErrorLog(shader.getInfoLog(), src, tmpAlloc, errorMessage);
+		createErrorLog(shader.getInfoLog(), src, tmpPool, errorMessage);
 		return Error::kUserData;
 		return Error::kUserData;
 	}
 	}
 
 
@@ -337,10 +336,10 @@ Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolA
 	{
 	{
 		File file;
 		File file;
 
 
-		StringRaii tmpDir(tmpAlloc);
+		StringRaii tmpDir(&tmpPool);
 		ANKI_CHECK(getTempDirectory(tmpDir));
 		ANKI_CHECK(getTempDirectory(tmpDir));
 
 
-		StringRaii fname(tmpAlloc);
+		StringRaii fname(&tmpPool);
 		fname.sprintf("%s/%u.spv", tmpDir.cstr(), dumpFileCount);
 		fname.sprintf("%s/%u.spv", tmpDir.cstr(), dumpFileCount);
 		ANKI_SHADER_COMPILER_LOGW("GLSL dumping is enabled: %s", fname.cstr());
 		ANKI_SHADER_COMPILER_LOGW("GLSL dumping is enabled: %s", fname.cstr());
 		ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite | FileOpenFlag::kBinary));
 		ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite | FileOpenFlag::kBinary));

+ 2 - 2
AnKi/ShaderCompiler/Glslang.h

@@ -17,8 +17,8 @@ namespace anki {
 Error preprocessGlsl(CString in, StringRaii& out);
 Error preprocessGlsl(CString in, StringRaii& out);
 
 
 /// Compile glsl to SPIR-V.
 /// Compile glsl to SPIR-V.
-Error compilerGlslToSpirv(CString src, ShaderType shaderType, GenericMemoryPoolAllocator<U8> tmpAlloc,
-						  DynamicArrayRaii<U8>& spirv, StringRaii& errorMessage);
+Error compilerGlslToSpirv(CString src, ShaderType shaderType, BaseMemoryPool& tmpPool, DynamicArrayRaii<U8>& spirv,
+						  StringRaii& errorMessage);
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki

+ 8 - 8
AnKi/ShaderCompiler/MaliOfflineCompiler.cpp

@@ -88,7 +88,7 @@ void MaliOfflineCompilerOut::toString(StringRaii& str) const
 }
 }
 
 
 static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString spirvFilename, ShaderType shaderType,
 static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString spirvFilename, ShaderType shaderType,
-											GenericMemoryPoolAllocator<U8> tmpAlloc, MaliOfflineCompilerOut& out)
+											BaseMemoryPool& tmpPool, MaliOfflineCompilerOut& out)
 {
 {
 	out = {};
 	out = {};
 
 
@@ -121,7 +121,7 @@ static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString sp
 	ANKI_CHECK(proc.wait(-1.0, &status, &exitCode));
 	ANKI_CHECK(proc.wait(-1.0, &status, &exitCode));
 	if(exitCode != 0)
 	if(exitCode != 0)
 	{
 	{
-		StringRaii stderre(tmpAlloc);
+		StringRaii stderre(&tmpPool);
 		const Error err = proc.readFromStderr(stderre);
 		const Error err = proc.readFromStderr(stderre);
 		ANKI_SHADER_COMPILER_LOGE("Mali offline compiler failed with exit code %d. Stderr: %s", exitCode,
 		ANKI_SHADER_COMPILER_LOGE("Mali offline compiler failed with exit code %d. Stderr: %s", exitCode,
 								  (err || stderre.isEmpty()) ? "<no text>" : stderre.cstr());
 								  (err || stderre.isEmpty()) ? "<no text>" : stderre.cstr());
@@ -129,7 +129,7 @@ static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString sp
 	}
 	}
 
 
 	// Get stdout
 	// Get stdout
-	StringRaii stdouts(tmpAlloc);
+	StringRaii stdouts(&tmpPool);
 	ANKI_CHECK(proc.readFromStdout(stdouts));
 	ANKI_CHECK(proc.readFromStdout(stdouts));
 	const std::string stdoutstl(stdouts.cstr());
 	const std::string stdoutstl(stdouts.cstr());
 
 
@@ -295,7 +295,7 @@ static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString sp
 	if(false)
 	if(false)
 	{
 	{
 		printf("%s\n", stdouts.cstr());
 		printf("%s\n", stdouts.cstr());
-		StringRaii str(tmpAlloc);
+		StringRaii str(&tmpPool);
 		out.toString(str);
 		out.toString(str);
 		printf("%s\n", str.cstr());
 		printf("%s\n", str.cstr());
 	}
 	}
@@ -304,14 +304,14 @@ static Error runMaliOfflineCompilerInternal(CString maliocExecutable, CString sp
 }
 }
 
 
 Error runMaliOfflineCompiler(CString maliocExecutable, ConstWeakArray<U8> spirv, ShaderType shaderType,
 Error runMaliOfflineCompiler(CString maliocExecutable, ConstWeakArray<U8> spirv, ShaderType shaderType,
-							 GenericMemoryPoolAllocator<U8> tmpAlloc, MaliOfflineCompilerOut& out)
+							 BaseMemoryPool& tmpPool, MaliOfflineCompilerOut& out)
 {
 {
 	ANKI_ASSERT(spirv.getSize() > 0);
 	ANKI_ASSERT(spirv.getSize() > 0);
 
 
 	// Create temp file to dump the spirv
 	// Create temp file to dump the spirv
-	StringRaii tmpDir(tmpAlloc);
+	StringRaii tmpDir(&tmpPool);
 	ANKI_CHECK(getTempDirectory(tmpDir));
 	ANKI_CHECK(getTempDirectory(tmpDir));
-	StringRaii spirvFilename(tmpAlloc);
+	StringRaii spirvFilename(&tmpPool);
 	spirvFilename.sprintf("%s/AnKiMaliocTmpSpirv_%" PRIu64 ".spv", tmpDir.cstr(), getRandom());
 	spirvFilename.sprintf("%s/AnKiMaliocTmpSpirv_%" PRIu64 ".spv", tmpDir.cstr(), getRandom());
 
 
 	File spirvFile;
 	File spirvFile;
@@ -322,7 +322,7 @@ Error runMaliOfflineCompiler(CString maliocExecutable, ConstWeakArray<U8> spirv,
 	// Call malioc
 	// Call malioc
 	if(!err)
 	if(!err)
 	{
 	{
-		err = runMaliOfflineCompilerInternal(maliocExecutable, spirvFilename, shaderType, tmpAlloc, out);
+		err = runMaliOfflineCompilerInternal(maliocExecutable, spirvFilename, shaderType, tmpPool, out);
 	}
 	}
 
 
 	// Cleanup
 	// Cleanup

+ 1 - 1
AnKi/ShaderCompiler/MaliOfflineCompiler.h

@@ -46,7 +46,7 @@ public:
 
 
 /// Run the mali offline compiler and get some info back.
 /// Run the mali offline compiler and get some info back.
 Error runMaliOfflineCompiler(CString maliocExecutable, ConstWeakArray<U8> spirv, ShaderType shaderType,
 Error runMaliOfflineCompiler(CString maliocExecutable, ConstWeakArray<U8> spirv, ShaderType shaderType,
-							 GenericMemoryPoolAllocator<U8> tmpAlloc, MaliOfflineCompilerOut& out);
+							 BaseMemoryPool& tmpPool, MaliOfflineCompilerOut& out);
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki

+ 88 - 94
AnKi/ShaderCompiler/ShaderProgramCompiler.cpp

@@ -20,10 +20,7 @@ Error ShaderProgramBinaryWrapper::serializeToFile(CString fname) const
 	ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite | FileOpenFlag::kBinary));
 	ANKI_CHECK(file.open(fname, FileOpenFlag::kWrite | FileOpenFlag::kBinary));
 
 
 	BinarySerializer serializer;
 	BinarySerializer serializer;
-	HeapAllocator<U8> tmpAlloc(m_alloc.getMemoryPool().getAllocationCallback(),
-							   m_alloc.getMemoryPool().getAllocationCallbackUserData(),
-							   "ShaderProgramBinaryWrapper temp");
-	ANKI_CHECK(serializer.serialize(*m_binary, tmpAlloc, file));
+	ANKI_CHECK(serializer.serialize(*m_binary, *m_pool, file));
 
 
 	return Error::kNone;
 	return Error::kNone;
 }
 }
@@ -43,7 +40,7 @@ void ShaderProgramBinaryWrapper::cleanup()
 		return;
 		return;
 	}
 	}
 
 
-	BaseMemoryPool& mempool = m_alloc.getMemoryPool();
+	BaseMemoryPool& mempool = *m_pool;
 
 
 	if(!m_singleAllocation)
 	if(!m_singleAllocation)
 	{
 	{
@@ -167,8 +164,8 @@ static Bool spinDials(DynamicArrayRaii<U32>& dials, ConstWeakArray<ShaderProgram
 }
 }
 
 
 static Error compileSpirv(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
 static Error compileSpirv(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
-						  GenericMemoryPoolAllocator<U8>& tmpAlloc,
-						  Array<DynamicArrayRaii<U8>, U32(ShaderType::kCount)>& spirv, StringRaii& errorLog)
+						  BaseMemoryPool& tempPool, Array<DynamicArrayRaii<U8>, U32(ShaderType::kCount)>& spirv,
+						  StringRaii& errorLog)
 {
 {
 	// Generate the source and the rest for the variant
 	// Generate the source and the rest for the variant
 	ShaderProgramParserVariant parserVariant;
 	ShaderProgramParserVariant parserVariant;
@@ -183,7 +180,7 @@ static Error compileSpirv(ConstWeakArray<MutatorValue> mutation, const ShaderPro
 		}
 		}
 
 
 		// Compile
 		// Compile
-		ANKI_CHECK(compilerGlslToSpirv(parserVariant.getSource(shaderType), shaderType, tmpAlloc, spirv[shaderType],
+		ANKI_CHECK(compilerGlslToSpirv(parserVariant.getSource(shaderType), shaderType, tempPool, spirv[shaderType],
 									   errorLog));
 									   errorLog));
 		ANKI_ASSERT(spirv[shaderType].getSize() > 0);
 		ANKI_ASSERT(spirv[shaderType].getSize() > 0);
 	}
 	}
@@ -194,18 +191,18 @@ static Error compileSpirv(ConstWeakArray<MutatorValue> mutation, const ShaderPro
 static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
 static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const ShaderProgramParser& parser,
 								ShaderProgramBinaryVariant& variant,
 								ShaderProgramBinaryVariant& variant,
 								DynamicArrayRaii<ShaderProgramBinaryCodeBlock>& codeBlocks,
 								DynamicArrayRaii<ShaderProgramBinaryCodeBlock>& codeBlocks,
-								DynamicArrayRaii<U64>& codeBlockHashes, GenericMemoryPoolAllocator<U8>& tmpAlloc,
-								GenericMemoryPoolAllocator<U8>& binaryAlloc,
-								ShaderProgramAsyncTaskInterface& taskManager, Mutex& mtx, Atomic<I32>& error)
+								DynamicArrayRaii<U64>& codeBlockHashes, BaseMemoryPool& tmpPool,
+								BaseMemoryPool& binaryPool, ShaderProgramAsyncTaskInterface& taskManager, Mutex& mtx,
+								Atomic<I32>& error)
 {
 {
 	variant = {};
 	variant = {};
 
 
 	class Ctx
 	class Ctx
 	{
 	{
 	public:
 	public:
-		GenericMemoryPoolAllocator<U8> m_tmpAlloc;
-		GenericMemoryPoolAllocator<U8> m_binaryAlloc;
-		DynamicArrayRaii<MutatorValue> m_mutation = {m_tmpAlloc};
+		BaseMemoryPool* m_tmpPool;
+		BaseMemoryPool* m_binaryPool;
+		DynamicArrayRaii<MutatorValue> m_mutation = {m_tmpPool};
 		const ShaderProgramParser* m_parser;
 		const ShaderProgramParser* m_parser;
 		ShaderProgramBinaryVariant* m_variant;
 		ShaderProgramBinaryVariant* m_variant;
 		DynamicArrayRaii<ShaderProgramBinaryCodeBlock>* m_codeBlocks;
 		DynamicArrayRaii<ShaderProgramBinaryCodeBlock>* m_codeBlocks;
@@ -213,14 +210,14 @@ static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const Sha
 		Mutex* m_mtx;
 		Mutex* m_mtx;
 		Atomic<I32>* m_err;
 		Atomic<I32>* m_err;
 
 
-		Ctx(GenericMemoryPoolAllocator<U8> tmpAlloc)
-			: m_tmpAlloc(tmpAlloc)
+		Ctx(BaseMemoryPool* tmpPool)
+			: m_tmpPool(tmpPool)
 		{
 		{
 		}
 		}
 	};
 	};
 
 
-	Ctx* ctx = tmpAlloc.newInstance<Ctx>(tmpAlloc);
-	ctx->m_binaryAlloc = binaryAlloc;
+	Ctx* ctx = newInstance<Ctx>(tmpPool, &tmpPool);
+	ctx->m_binaryPool = &binaryPool;
 	ctx->m_mutation.create(mutation.getSize());
 	ctx->m_mutation.create(mutation.getSize());
 	memcpy(ctx->m_mutation.getBegin(), mutation.getBegin(), mutation.getSizeInBytes());
 	memcpy(ctx->m_mutation.getBegin(), mutation.getBegin(), mutation.getSizeInBytes());
 	ctx->m_parser = &parser;
 	ctx->m_parser = &parser;
@@ -232,30 +229,30 @@ static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const Sha
 
 
 	auto callback = [](void* userData) {
 	auto callback = [](void* userData) {
 		Ctx& ctx = *static_cast<Ctx*>(userData);
 		Ctx& ctx = *static_cast<Ctx*>(userData);
-		GenericMemoryPoolAllocator<U8>& tmpAlloc = ctx.m_tmpAlloc;
+		BaseMemoryPool& tmpPool = *ctx.m_tmpPool;
 
 
 		if(ctx.m_err->load() != 0)
 		if(ctx.m_err->load() != 0)
 		{
 		{
 			// Cleanup and return
 			// Cleanup and return
-			tmpAlloc.deleteInstance(&ctx);
+			deleteInstance(tmpPool, &ctx);
 			return;
 			return;
 		}
 		}
 
 
 		// All good, compile the variant
 		// All good, compile the variant
-		Array<DynamicArrayRaii<U8>, U32(ShaderType::kCount)> spirvs = {{{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc},
-																		{tmpAlloc}}};
-		StringRaii errorLog(tmpAlloc);
-		const Error err = compileSpirv(ctx.m_mutation, *ctx.m_parser, tmpAlloc, spirvs, errorLog);
+		Array<DynamicArrayRaii<U8>, U32(ShaderType::kCount)> spirvs = {{{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool},
+																		{&tmpPool}}};
+		StringRaii errorLog(&tmpPool);
+		const Error err = compileSpirv(ctx.m_mutation, *ctx.m_parser, tmpPool, spirvs, errorLog);
 
 
 		if(!err)
 		if(!err)
 		{
 		{
@@ -290,7 +287,7 @@ static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const Sha
 				// Create it if not found
 				// Create it if not found
 				if(!found)
 				if(!found)
 				{
 				{
-					U8* code = ctx.m_binaryAlloc.allocate(spirv.getSizeInBytes());
+					U8* code = static_cast<U8*>(ctx.m_binaryPool->allocate(spirv.getSizeInBytes(), 1));
 					memcpy(code, &spirv[0], spirv.getSizeInBytes());
 					memcpy(code, &spirv[0], spirv.getSizeInBytes());
 
 
 					ShaderProgramBinaryCodeBlock block;
 					ShaderProgramBinaryCodeBlock block;
@@ -315,7 +312,7 @@ static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const Sha
 		}
 		}
 
 
 		// Cleanup
 		// Cleanup
-		tmpAlloc.deleteInstance(&ctx);
+		deleteInstance(tmpPool, &ctx);
 	};
 	};
 
 
 	taskManager.enqueueTask(callback, ctx);
 	taskManager.enqueueTask(callback, ctx);
@@ -324,46 +321,45 @@ static void compileVariantAsync(ConstWeakArray<MutatorValue> mutation, const Sha
 class Refl final : public ShaderReflectionVisitorInterface
 class Refl final : public ShaderReflectionVisitorInterface
 {
 {
 public:
 public:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	const StringList* m_symbolsToReflect = nullptr;
 	const StringList* m_symbolsToReflect = nullptr;
 
 
 	/// Will be stored in the binary
 	/// Will be stored in the binary
 	/// @{
 	/// @{
 
 
 	/// [blockType][blockIdx]
 	/// [blockType][blockIdx]
-	Array<DynamicArrayRaii<ShaderProgramBinaryBlock>, 3> m_blocks = {{m_alloc, m_alloc, m_alloc}};
+	Array<DynamicArrayRaii<ShaderProgramBinaryBlock>, 3> m_blocks = {{{m_pool}, {m_pool}, {m_pool}}};
 
 
 	/// [blockType][blockIdx][varIdx]
 	/// [blockType][blockIdx][varIdx]
-	Array<DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryVariable>>, 3> m_vars = {
-		{{m_alloc}, {m_alloc}, {m_alloc}}};
+	Array<DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryVariable>>, 3> m_vars = {{{m_pool}, {m_pool}, {m_pool}}};
 
 
-	DynamicArrayRaii<ShaderProgramBinaryOpaque> m_opaque = {m_alloc};
-	DynamicArrayRaii<ShaderProgramBinaryConstant> m_consts = {m_alloc};
+	DynamicArrayRaii<ShaderProgramBinaryOpaque> m_opaque = {m_pool};
+	DynamicArrayRaii<ShaderProgramBinaryConstant> m_consts = {m_pool};
 
 
-	DynamicArrayRaii<ShaderProgramBinaryStruct> m_structs = {m_alloc};
+	DynamicArrayRaii<ShaderProgramBinaryStruct> m_structs = {m_pool};
 	/// [structIndex][memberIndex]
 	/// [structIndex][memberIndex]
-	DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryStructMember>> m_structMembers = {m_alloc};
+	DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryStructMember>> m_structMembers = {m_pool};
 	/// @}
 	/// @}
 
 
 	/// Will be stored in a variant
 	/// Will be stored in a variant
 	/// @{
 	/// @{
 
 
 	/// [blockType][blockInstanceIdx]
 	/// [blockType][blockInstanceIdx]
-	Array<DynamicArrayRaii<ShaderProgramBinaryBlockInstance>, 3> m_blockInstances = {{m_alloc, m_alloc, m_alloc}};
+	Array<DynamicArrayRaii<ShaderProgramBinaryBlockInstance>, 3> m_blockInstances = {{{m_pool}, {m_pool}, {m_pool}}};
 
 
-	DynamicArrayRaii<ShaderProgramBinaryOpaqueInstance> m_opaqueInstances = {m_alloc};
-	DynamicArrayRaii<ShaderProgramBinaryConstantInstance> m_constInstances = {m_alloc};
+	DynamicArrayRaii<ShaderProgramBinaryOpaqueInstance> m_opaqueInstances = {m_pool};
+	DynamicArrayRaii<ShaderProgramBinaryConstantInstance> m_constInstances = {m_pool};
 
 
-	DynamicArrayRaii<ShaderProgramBinaryStructInstance> m_structInstances = {m_alloc};
+	DynamicArrayRaii<ShaderProgramBinaryStructInstance> m_structInstances = {m_pool};
 	/// [structInstance][memberInstance]
 	/// [structInstance][memberInstance]
-	DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryStructMemberInstance>> m_structMemberInstances = {m_alloc};
+	DynamicArrayRaii<DynamicArrayRaii<ShaderProgramBinaryStructMemberInstance>> m_structMemberInstances = {m_pool};
 
 
 	Array<U32, 3> m_workgroupSizes = {kMaxU32, kMaxU32, kMaxU32};
 	Array<U32, 3> m_workgroupSizes = {kMaxU32, kMaxU32, kMaxU32};
 	Array<U32, 3> m_workgroupSizesConstants = {kMaxU32, kMaxU32, kMaxU32};
 	Array<U32, 3> m_workgroupSizesConstants = {kMaxU32, kMaxU32, kMaxU32};
 	/// @}
 	/// @}
 
 
-	Refl(const GenericMemoryPoolAllocator<U8>& alloc, const StringList* symbolsToReflect)
-		: m_alloc(alloc)
+	Refl(BaseMemoryPool* pool, const StringList* symbolsToReflect)
+		: m_pool(pool)
 		, m_symbolsToReflect(symbolsToReflect)
 		, m_symbolsToReflect(symbolsToReflect)
 	{
 	{
 	}
 	}
@@ -416,7 +412,7 @@ public:
 		m_opaqueInstances.create(opaqueCount);
 		m_opaqueInstances.create(opaqueCount);
 		m_constInstances.create(constCount);
 		m_constInstances.create(constCount);
 		m_structInstances.create(structCount);
 		m_structInstances.create(structCount);
-		m_structMemberInstances.create(structCount, m_alloc);
+		m_structMemberInstances.create(structCount, {m_pool});
 		return Error::kNone;
 		return Error::kNone;
 	}
 	}
 
 
@@ -579,7 +575,7 @@ public:
 			ANKI_CHECK(setName(name, s.m_name));
 			ANKI_CHECK(setName(name, s.m_name));
 
 
 			// Allocate members
 			// Allocate members
-			m_structMembers.emplaceBack(m_alloc);
+			m_structMembers.emplaceBack(m_pool);
 			ANKI_ASSERT(m_structs.getSize() == m_structMembers.getSize());
 			ANKI_ASSERT(m_structs.getSize() == m_structMembers.getSize());
 		}
 		}
 
 
@@ -707,7 +703,7 @@ public:
 			blockIdx = m_blocks[blockType].getSize() - 1;
 			blockIdx = m_blocks[blockType].getSize() - 1;
 
 
 			// Create some storage for vars as well
 			// Create some storage for vars as well
-			m_vars[blockType].emplaceBack(m_alloc);
+			m_vars[blockType].emplaceBack(m_pool);
 			ANKI_ASSERT(m_vars[blockType].getSize() == m_blocks[blockType].getSize());
 			ANKI_ASSERT(m_vars[blockType].getSize() == m_blocks[blockType].getSize());
 		}
 		}
 
 
@@ -715,7 +711,7 @@ public:
 		ShaderProgramBinaryBlockInstance& instance = m_blockInstances[blockType][blockInstanceIdx];
 		ShaderProgramBinaryBlockInstance& instance = m_blockInstances[blockType][blockInstanceIdx];
 		instance.m_index = blockIdx;
 		instance.m_index = blockIdx;
 		instance.m_size = size;
 		instance.m_size = size;
-		m_alloc.newArray(varSize, instance.m_variableInstances);
+		newArray(*m_pool, varSize, instance.m_variableInstances);
 
 
 		return Error::kNone;
 		return Error::kNone;
 	}
 	}
@@ -765,11 +761,10 @@ public:
 
 
 static Error doGhostStructReflection(const StringList& symbolsToReflect,
 static Error doGhostStructReflection(const StringList& symbolsToReflect,
 									 ConstWeakArray<ShaderProgramParserGhostStruct> ghostStructs,
 									 ConstWeakArray<ShaderProgramParserGhostStruct> ghostStructs,
-									 ShaderProgramBinary& binary, GenericMemoryPoolAllocator<U8>& tmpAlloc,
-									 GenericMemoryPoolAllocator<U8>& binaryAlloc)
+									 ShaderProgramBinary& binary, BaseMemoryPool& tmpPool, BaseMemoryPool& binaryPool)
 {
 {
 	// Count reflectable ghost structs
 	// Count reflectable ghost structs
-	DynamicArrayRaii<U32> ghostStructIndices(tmpAlloc);
+	DynamicArrayRaii<U32> ghostStructIndices(&tmpPool);
 	for(U32 i = 0; i < ghostStructs.getSize(); ++i)
 	for(U32 i = 0; i < ghostStructs.getSize(); ++i)
 	{
 	{
 		for(const String& s : symbolsToReflect)
 		for(const String& s : symbolsToReflect)
@@ -789,7 +784,7 @@ static Error doGhostStructReflection(const StringList& symbolsToReflect,
 
 
 	// Add the ghost structs to binary structs
 	// Add the ghost structs to binary structs
 	const U32 nonGhostStructCount = binary.m_structs.getSize();
 	const U32 nonGhostStructCount = binary.m_structs.getSize();
-	DynamicArrayRaii<ShaderProgramBinaryStruct> structs(binaryAlloc,
+	DynamicArrayRaii<ShaderProgramBinaryStruct> structs(&binaryPool,
 														nonGhostStructCount + ghostStructIndices.getSize());
 														nonGhostStructCount + ghostStructIndices.getSize());
 
 
 	for(U32 i = 0; i < binary.m_structs.getSize(); ++i)
 	for(U32 i = 0; i < binary.m_structs.getSize(); ++i)
@@ -804,7 +799,7 @@ static Error doGhostStructReflection(const StringList& symbolsToReflect,
 
 
 		ANKI_CHECK(Refl::setName(in.m_name, out.m_name));
 		ANKI_CHECK(Refl::setName(in.m_name, out.m_name));
 
 
-		DynamicArrayRaii<ShaderProgramBinaryStructMember> members(binaryAlloc, in.m_members.getSize());
+		DynamicArrayRaii<ShaderProgramBinaryStructMember> members(&binaryPool, in.m_members.getSize());
 		for(U32 j = 0; j < in.m_members.getSize(); ++j)
 		for(U32 j = 0; j < in.m_members.getSize(); ++j)
 		{
 		{
 			const ShaderProgramParserMember& inMember = in.m_members[j];
 			const ShaderProgramParserMember& inMember = in.m_members[j];
@@ -819,18 +814,18 @@ static Error doGhostStructReflection(const StringList& symbolsToReflect,
 		members.moveAndReset(out.m_members);
 		members.moveAndReset(out.m_members);
 	}
 	}
 
 
-	binaryAlloc.deleteArray(binary.m_structs);
+	deleteArray(binaryPool, binary.m_structs);
 	structs.moveAndReset(binary.m_structs);
 	structs.moveAndReset(binary.m_structs);
 
 
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
-static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinary& binary,
-						  GenericMemoryPoolAllocator<U8>& tmpAlloc, GenericMemoryPoolAllocator<U8>& binaryAlloc)
+static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinary& binary, BaseMemoryPool& tmpPool,
+						  BaseMemoryPool& binaryPool)
 {
 {
 	ANKI_ASSERT(binary.m_variants.getSize() > 0);
 	ANKI_ASSERT(binary.m_variants.getSize() > 0);
 
 
-	Refl refl(binaryAlloc, &symbolsToReflect);
+	Refl refl(&binaryPool, &symbolsToReflect);
 
 
 	for(ShaderProgramBinaryVariant& variant : binary.m_variants)
 	for(ShaderProgramBinaryVariant& variant : binary.m_variants)
 	{
 	{
@@ -843,7 +838,7 @@ static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinar
 			}
 			}
 		}
 		}
 
 
-		ANKI_CHECK(performSpirvReflection(spirvs, tmpAlloc, refl));
+		ANKI_CHECK(performSpirvReflection(spirvs, tmpPool, refl));
 
 
 		// Store the instances
 		// Store the instances
 		if(refl.m_blockInstances[0].getSize())
 		if(refl.m_blockInstances[0].getSize())
@@ -991,21 +986,20 @@ static Error doReflection(const StringList& symbolsToReflect, ShaderProgramBinar
 
 
 Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
 Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
 								   ShaderProgramPostParseInterface* postParseCallback,
 								   ShaderProgramPostParseInterface* postParseCallback,
-								   ShaderProgramAsyncTaskInterface* taskManager_,
-								   GenericMemoryPoolAllocator<U8> tempAllocator,
+								   ShaderProgramAsyncTaskInterface* taskManager_, BaseMemoryPool& tempPool,
 								   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
 								   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
 {
 {
 	// Initialize the binary
 	// Initialize the binary
 	binaryW.cleanup();
 	binaryW.cleanup();
 	binaryW.m_singleAllocation = false;
 	binaryW.m_singleAllocation = false;
-	GenericMemoryPoolAllocator<U8> binaryAllocator = binaryW.m_alloc;
-	binaryW.m_binary = binaryAllocator.newInstance<ShaderProgramBinary>();
+	BaseMemoryPool& binaryPool = *binaryW.m_pool;
+	binaryW.m_binary = newInstance<ShaderProgramBinary>(binaryPool);
 	ShaderProgramBinary& binary = *binaryW.m_binary;
 	ShaderProgramBinary& binary = *binaryW.m_binary;
 	binary = {};
 	binary = {};
 	memcpy(&binary.m_magic[0], SHADER_BINARY_MAGIC, 8);
 	memcpy(&binary.m_magic[0], SHADER_BINARY_MAGIC, 8);
 
 
 	// Parse source
 	// Parse source
-	ShaderProgramParser parser(fname, &fsystem, tempAllocator, compilerOptions);
+	ShaderProgramParser parser(fname, &fsystem, &tempPool, compilerOptions);
 	ANKI_CHECK(parser.parse());
 	ANKI_CHECK(parser.parse());
 
 
 	if(postParseCallback && postParseCallback->skipCompilation(parser.getHash()))
 	if(postParseCallback && postParseCallback->skipCompilation(parser.getHash()))
@@ -1017,7 +1011,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 	U32 mutationCount = 0;
 	U32 mutationCount = 0;
 	if(parser.getMutators().getSize() > 0)
 	if(parser.getMutators().getSize() > 0)
 	{
 	{
-		binaryAllocator.newArray(parser.getMutators().getSize(), binary.m_mutators);
+		newArray(binaryPool, parser.getMutators().getSize(), binary.m_mutators);
 
 
 		for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
 		for(U32 i = 0; i < binary.m_mutators.getSize(); ++i)
 		{
 		{
@@ -1026,7 +1020,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 
 
 			ANKI_CHECK(Refl::setName(in.getName(), out.m_name));
 			ANKI_CHECK(Refl::setName(in.getName(), out.m_name));
 
 
-			binaryAllocator.newArray(in.getValues().getSize(), out.m_values);
+			newArray(binaryPool, in.getValues().getSize(), out.m_values);
 			memcpy(out.m_values.getBegin(), in.getValues().getBegin(), in.getValues().getSizeInBytes());
 			memcpy(out.m_values.getBegin(), in.getValues().getBegin(), in.getValues().getSizeInBytes());
 
 
 			// Update the count
 			// Update the count
@@ -1060,13 +1054,13 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 	if(parser.getMutators().getSize() > 0)
 	if(parser.getMutators().getSize() > 0)
 	{
 	{
 		// Initialize
 		// Initialize
-		DynamicArrayRaii<MutatorValue> mutationValues(tempAllocator, parser.getMutators().getSize());
-		DynamicArrayRaii<U32> dials(tempAllocator, parser.getMutators().getSize(), 0);
-		DynamicArrayRaii<ShaderProgramBinaryVariant> variants(binaryAllocator);
-		DynamicArrayRaii<ShaderProgramBinaryCodeBlock> codeBlocks(binaryAllocator);
-		DynamicArrayRaii<ShaderProgramBinaryMutation> mutations(binaryAllocator, mutationCount);
-		DynamicArrayRaii<U64> codeBlockHashes(tempAllocator);
-		HashMapRaii<U64, U32> mutationHashToIdx(tempAllocator);
+		DynamicArrayRaii<MutatorValue> mutationValues(&tempPool, parser.getMutators().getSize());
+		DynamicArrayRaii<U32> dials(&tempPool, parser.getMutators().getSize(), 0);
+		DynamicArrayRaii<ShaderProgramBinaryVariant> variants(&binaryPool);
+		DynamicArrayRaii<ShaderProgramBinaryCodeBlock> codeBlocks(&binaryPool);
+		DynamicArrayRaii<ShaderProgramBinaryMutation> mutations(&binaryPool, mutationCount);
+		DynamicArrayRaii<U64> codeBlockHashes(&tempPool);
+		HashMapRaii<U64, U32> mutationHashToIdx(&tempPool);
 
 
 		// Grow the storage of the variants array. Can't have it resize, threads will work on stale data
 		// Grow the storage of the variants array. Can't have it resize, threads will work on stale data
 		variants.resizeStorage(mutationCount);
 		variants.resizeStorage(mutationCount);
@@ -1086,7 +1080,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 			}
 			}
 
 
 			ShaderProgramBinaryMutation& mutation = mutations[mutationCount++];
 			ShaderProgramBinaryMutation& mutation = mutations[mutationCount++];
-			binaryAllocator.newArray(mutationValues.getSize(), mutation.m_values);
+			newArray(binaryPool, mutationValues.getSize(), mutation.m_values);
 			memcpy(mutation.m_values.getBegin(), mutationValues.getBegin(), mutationValues.getSizeInBytes());
 			memcpy(mutation.m_values.getBegin(), mutationValues.getBegin(), mutationValues.getSizeInBytes());
 
 
 			mutation.m_hash = computeHash(mutationValues.getBegin(), mutationValues.getSizeInBytes());
 			mutation.m_hash = computeHash(mutationValues.getBegin(), mutationValues.getSizeInBytes());
@@ -1103,8 +1097,8 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 				ShaderProgramBinaryVariant& variant = *variants.emplaceBack();
 				ShaderProgramBinaryVariant& variant = *variants.emplaceBack();
 				baseVariant = (baseVariant == nullptr) ? variants.getBegin() : baseVariant;
 				baseVariant = (baseVariant == nullptr) ? variants.getBegin() : baseVariant;
 
 
-				compileVariantAsync(mutationValues, parser, variant, codeBlocks, codeBlockHashes, tempAllocator,
-									binaryAllocator, taskManager, mtx, errorAtomic);
+				compileVariantAsync(mutationValues, parser, variant, codeBlocks, codeBlockHashes, tempPool, binaryPool,
+									taskManager, mtx, errorAtomic);
 
 
 				mutation.m_variantIndex = variants.getSize() - 1;
 				mutation.m_variantIndex = variants.getSize() - 1;
 
 
@@ -1136,14 +1130,14 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 	}
 	}
 	else
 	else
 	{
 	{
-		DynamicArrayRaii<MutatorValue> mutation(tempAllocator);
-		DynamicArrayRaii<ShaderProgramBinaryCodeBlock> codeBlocks(binaryAllocator);
-		DynamicArrayRaii<U64> codeBlockHashes(tempAllocator);
+		DynamicArrayRaii<MutatorValue> mutation(&tempPool);
+		DynamicArrayRaii<ShaderProgramBinaryCodeBlock> codeBlocks(&binaryPool);
+		DynamicArrayRaii<U64> codeBlockHashes(&tempPool);
 
 
-		binary.m_variants.setArray(binaryAllocator.newInstance<ShaderProgramBinaryVariant>(), 1);
+		binary.m_variants.setArray(newInstance<ShaderProgramBinaryVariant>(binaryPool), 1);
 
 
-		compileVariantAsync(mutation, parser, binary.m_variants[0], codeBlocks, codeBlockHashes, tempAllocator,
-							binaryAllocator, taskManager, mtx, errorAtomic);
+		compileVariantAsync(mutation, parser, binary.m_variants[0], codeBlocks, codeBlockHashes, tempPool, binaryPool,
+							taskManager, mtx, errorAtomic);
 
 
 		ANKI_CHECK(taskManager.joinTasks());
 		ANKI_CHECK(taskManager.joinTasks());
 		ANKI_CHECK(Error(errorAtomic.getNonAtomically()));
 		ANKI_CHECK(Error(errorAtomic.getNonAtomically()));
@@ -1155,7 +1149,7 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 		codeBlocks.moveAndReset(firstCodeBlock, size, storage);
 		codeBlocks.moveAndReset(firstCodeBlock, size, storage);
 		binary.m_codeBlocks.setArray(firstCodeBlock, size);
 		binary.m_codeBlocks.setArray(firstCodeBlock, size);
 
 
-		binary.m_mutations.setArray(binaryAllocator.newInstance<ShaderProgramBinaryMutation>(), 1);
+		binary.m_mutations.setArray(newInstance<ShaderProgramBinaryMutation>(binaryPool), 1);
 		binary.m_mutations[0].m_hash = 1;
 		binary.m_mutations[0].m_hash = 1;
 		binary.m_mutations[0].m_variantIndex = 0;
 		binary.m_mutations[0].m_variantIndex = 0;
 	}
 	}
@@ -1184,19 +1178,19 @@ Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterfa
 	binary.m_presentShaderTypes = parser.getShaderTypes();
 	binary.m_presentShaderTypes = parser.getShaderTypes();
 
 
 	// Reflection
 	// Reflection
-	ANKI_CHECK(doReflection(parser.getSymbolsToReflect(), binary, tempAllocator, binaryAllocator));
-	ANKI_CHECK(doGhostStructReflection(parser.getSymbolsToReflect(), parser.getGhostStructs(), binary, tempAllocator,
-									   binaryAllocator));
+	ANKI_CHECK(doReflection(parser.getSymbolsToReflect(), binary, tempPool, binaryPool));
+	ANKI_CHECK(
+		doGhostStructReflection(parser.getSymbolsToReflect(), parser.getGhostStructs(), binary, tempPool, binaryPool));
 
 
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
 						   ShaderProgramPostParseInterface* postParseCallback,
 						   ShaderProgramPostParseInterface* postParseCallback,
-						   ShaderProgramAsyncTaskInterface* taskManager, GenericMemoryPoolAllocator<U8> tempAllocator,
+						   ShaderProgramAsyncTaskInterface* taskManager, BaseMemoryPool& tempPool,
 						   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
 						   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binaryW)
 {
 {
-	const Error err = compileShaderProgramInternal(fname, fsystem, postParseCallback, taskManager, tempAllocator,
+	const Error err = compileShaderProgramInternal(fname, fsystem, postParseCallback, taskManager, tempPool,
 												   compilerOptions, binaryW);
 												   compilerOptions, binaryW);
 	if(err)
 	if(err)
 	{
 	{

+ 6 - 7
AnKi/ShaderCompiler/ShaderProgramCompiler.h

@@ -23,14 +23,13 @@ class ShaderProgramBinaryWrapper
 {
 {
 	friend Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
 	friend Error compileShaderProgramInternal(CString fname, ShaderProgramFilesystemInterface& fsystem,
 											  ShaderProgramPostParseInterface* postParseCallback,
 											  ShaderProgramPostParseInterface* postParseCallback,
-											  ShaderProgramAsyncTaskInterface* taskManager,
-											  GenericMemoryPoolAllocator<U8> tempAllocator,
+											  ShaderProgramAsyncTaskInterface* taskManager, BaseMemoryPool& tempPool,
 											  const ShaderCompilerOptions& compilerOptions,
 											  const ShaderCompilerOptions& compilerOptions,
 											  ShaderProgramBinaryWrapper& binary);
 											  ShaderProgramBinaryWrapper& binary);
 
 
 public:
 public:
-	ShaderProgramBinaryWrapper(GenericMemoryPoolAllocator<U8> alloc)
-		: m_alloc(alloc)
+	ShaderProgramBinaryWrapper(BaseMemoryPool* pool)
+		: m_pool(pool)
 	{
 	{
 	}
 	}
 
 
@@ -57,7 +56,7 @@ public:
 	}
 	}
 
 
 private:
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	ShaderProgramBinary* m_binary = nullptr;
 	ShaderProgramBinary* m_binary = nullptr;
 	Bool m_singleAllocation = false;
 	Bool m_singleAllocation = false;
 
 
@@ -69,7 +68,7 @@ Error ShaderProgramBinaryWrapper::deserializeFromAnyFile(TFile& file)
 {
 {
 	cleanup();
 	cleanup();
 	BinaryDeserializer deserializer;
 	BinaryDeserializer deserializer;
-	ANKI_CHECK(deserializer.deserialize(m_binary, m_alloc, file));
+	ANKI_CHECK(deserializer.deserialize(m_binary, *m_pool, file));
 
 
 	m_singleAllocation = true;
 	m_singleAllocation = true;
 
 
@@ -85,7 +84,7 @@ Error ShaderProgramBinaryWrapper::deserializeFromAnyFile(TFile& file)
 /// Takes an AnKi special shader program and spits a binary.
 /// Takes an AnKi special shader program and spits a binary.
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
 Error compileShaderProgram(CString fname, ShaderProgramFilesystemInterface& fsystem,
 						   ShaderProgramPostParseInterface* postParseCallback,
 						   ShaderProgramPostParseInterface* postParseCallback,
-						   ShaderProgramAsyncTaskInterface* taskManager, GenericMemoryPoolAllocator<U8> tempAllocator,
+						   ShaderProgramAsyncTaskInterface* taskManager, BaseMemoryPool& tempPool,
 						   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binary);
 						   const ShaderCompilerOptions& compilerOptions, ShaderProgramBinaryWrapper& binary);
 /// @}
 /// @}
 
 

+ 4 - 4
AnKi/ShaderCompiler/ShaderProgramDump.cpp

@@ -44,8 +44,8 @@ static void disassembleBlock(const ShaderProgramBinaryBlock& block, StringListRa
 
 
 void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringRaii& humanReadable)
 void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringRaii& humanReadable)
 {
 {
-	GenericMemoryPoolAllocator<U8> alloc = humanReadable.getAllocator();
-	StringListRaii lines(alloc);
+	BaseMemoryPool& pool = humanReadable.getMemoryPool();
+	StringListRaii lines(&pool);
 
 
 	if(binary.m_libraryName[0])
 	if(binary.m_libraryName[0])
 	{
 	{
@@ -182,9 +182,9 @@ void dumpShaderProgramBinary(const ShaderProgramBinary& binary, StringRaii& huma
 		compiler.set_common_options(options);
 		compiler.set_common_options(options);
 
 
 		std::string glsl = compiler.compile();
 		std::string glsl = compiler.compile();
-		StringListRaii sourceLines(alloc);
+		StringListRaii sourceLines(&pool);
 		sourceLines.splitString(glsl.c_str(), '\n');
 		sourceLines.splitString(glsl.c_str(), '\n');
-		StringRaii newGlsl(alloc);
+		StringRaii newGlsl(&pool);
 		sourceLines.join("\n" ANKI_TAB ANKI_TAB, newGlsl);
 		sourceLines.join("\n" ANKI_TAB ANKI_TAB, newGlsl);
 
 
 		lines.pushBackSprintf(ANKI_TAB "#bin%05u \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());

+ 22 - 23
AnKi/ShaderCompiler/ShaderProgramParser.cpp

@@ -280,11 +280,10 @@ Vec4 pow(Vec4 a, F32 b)
 
 
 static const U64 SHADER_HEADER_HASH = computeHash(SHADER_HEADER, sizeof(SHADER_HEADER));
 static const U64 SHADER_HEADER_HASH = computeHash(SHADER_HEADER, sizeof(SHADER_HEADER));
 
 
-ShaderProgramParser::ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem,
-										 GenericMemoryPoolAllocator<U8> alloc,
+ShaderProgramParser::ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, BaseMemoryPool* pool,
 										 const ShaderCompilerOptions& compilerOptions)
 										 const ShaderCompilerOptions& compilerOptions)
-	: m_alloc(alloc)
-	, m_fname(alloc, fname)
+	: m_pool(pool)
+	, m_fname(pool, fname)
 	, m_fsystem(fsystem)
 	, m_fsystem(fsystem)
 	, m_compilerOptions(compilerOptions)
 	, m_compilerOptions(compilerOptions)
 {
 {
@@ -298,7 +297,7 @@ void ShaderProgramParser::tokenizeLine(CString line, DynamicArrayRaii<StringRaii
 {
 {
 	ANKI_ASSERT(line.getLength() > 0);
 	ANKI_ASSERT(line.getLength() > 0);
 
 
-	StringRaii l(m_alloc, line);
+	StringRaii l(m_pool, line);
 
 
 	// Replace all tabs with spaces
 	// Replace all tabs with spaces
 	for(char& c : l)
 	for(char& c : l)
@@ -310,13 +309,13 @@ void ShaderProgramParser::tokenizeLine(CString line, DynamicArrayRaii<StringRaii
 	}
 	}
 
 
 	// Split
 	// Split
-	StringListAuto spaceTokens(m_alloc);
+	StringListRaii spaceTokens(m_pool);
 	spaceTokens.splitString(l, ' ', false);
 	spaceTokens.splitString(l, ' ', false);
 
 
 	// Create the array
 	// Create the array
 	for(const String& s : spaceTokens)
 	for(const String& s : spaceTokens)
 	{
 	{
-		tokens.emplaceBack(m_alloc, s);
+		tokens.emplaceBack(m_pool, s);
 	}
 	}
 }
 }
 
 
@@ -442,7 +441,7 @@ Error ShaderProgramParser::parsePragmaMutator(const StringRaii* begin, const Str
 		ANKI_PP_ERROR_MALFORMED();
 		ANKI_PP_ERROR_MALFORMED();
 	}
 	}
 
 
-	m_mutators.emplaceBack(m_alloc);
+	m_mutators.emplaceBack(m_pool);
 	Mutator& mutator = m_mutators.getBack();
 	Mutator& mutator = m_mutators.getBack();
 
 
 	// Name
 	// Name
@@ -580,7 +579,7 @@ Error ShaderProgramParser::parsePragmaSkipMutation(const StringRaii* begin, cons
 		ANKI_PP_ERROR_MALFORMED();
 		ANKI_PP_ERROR_MALFORMED();
 	}
 	}
 
 
-	PartialMutationSkip& skip = *m_skipMutations.emplaceBack(m_alloc);
+	PartialMutationSkip& skip = *m_skipMutations.emplaceBack(m_pool);
 	skip.m_partialMutation.create(m_mutators.getSize(), std::numeric_limits<MutatorValue>::max());
 	skip.m_partialMutation.create(m_mutators.getSize(), std::numeric_limits<MutatorValue>::max());
 
 
 	do
 	do
@@ -628,7 +627,7 @@ Error ShaderProgramParser::parseInclude(const StringRaii* begin, const StringRai
 										U32 depth)
 										U32 depth)
 {
 {
 	// Gather the path
 	// Gather the path
-	StringRaii path(m_alloc);
+	StringRaii path(m_pool);
 	for(; begin < end; ++begin)
 	for(; begin < end; ++begin)
 	{
 	{
 		path.append(*begin);
 		path.append(*begin);
@@ -645,7 +644,7 @@ Error ShaderProgramParser::parseInclude(const StringRaii* begin, const StringRai
 
 
 	if((firstChar == '\"' && lastChar == '\"') || (firstChar == '<' && lastChar == '>'))
 	if((firstChar == '\"' && lastChar == '\"') || (firstChar == '<' && lastChar == '>'))
 	{
 	{
-		StringRaii fname2(m_alloc);
+		StringRaii fname2(m_pool);
 		fname2.create(path.begin() + 1, path.begin() + path.getLength() - 1);
 		fname2.create(path.begin() + 1, path.begin() + path.getLength() - 1);
 
 
 		const Bool dontIgnore =
 		const Bool dontIgnore =
@@ -672,7 +671,7 @@ Error ShaderProgramParser::parseInclude(const StringRaii* begin, const StringRai
 Error ShaderProgramParser::parseLine(CString line, CString fname, Bool& foundPragmaOnce, U32 depth)
 Error ShaderProgramParser::parseLine(CString line, CString fname, Bool& foundPragmaOnce, U32 depth)
 {
 {
 	// Tokenize
 	// Tokenize
-	DynamicArrayRaii<StringRaii> tokens(m_alloc);
+	DynamicArrayRaii<StringRaii> tokens(m_pool);
 	tokenizeLine(line, tokens);
 	tokenizeLine(line, tokens);
 	ANKI_ASSERT(tokens.getSize() > 0);
 	ANKI_ASSERT(tokens.getSize() > 0);
 
 
@@ -810,7 +809,7 @@ Error ShaderProgramParser::parsePragmaStructBegin(const StringRaii* begin, const
 		ANKI_PP_ERROR_MALFORMED();
 		ANKI_PP_ERROR_MALFORMED();
 	}
 	}
 
 
-	GhostStruct& gstruct = *m_ghostStructs.emplaceBack(m_alloc);
+	GhostStruct& gstruct = *m_ghostStructs.emplaceBack(m_pool);
 	gstruct.m_name.create(*begin);
 	gstruct.m_name.create(*begin);
 
 
 	// Add a '_' to the struct name.
 	// Add a '_' to the struct name.
@@ -842,7 +841,7 @@ Error ShaderProgramParser::parsePragmaMember(const StringRaii* begin, const Stri
 		ANKI_PP_ERROR_MALFORMED();
 		ANKI_PP_ERROR_MALFORMED();
 	}
 	}
 
 
-	Member& member = *m_ghostStructs.getBack().m_members.emplaceBack(m_alloc);
+	Member& member = *m_ghostStructs.getBack().m_members.emplaceBack(m_pool);
 
 
 	// Relaxed
 	// Relaxed
 	Bool relaxed = false;
 	Bool relaxed = false;
@@ -1031,10 +1030,10 @@ Error ShaderProgramParser::parsePragmaStructEnd(const StringRaii* begin, const S
 		// #	define XXX_LOAD()
 		// #	define XXX_LOAD()
 		const Bool isIntegral = getShaderVariableDataTypeInfo(m.m_type).m_isIntegral;
 		const Bool isIntegral = getShaderVariableDataTypeInfo(m.m_type).m_isIntegral;
 		const U32 componentCount = getShaderVariableDataTypeInfo(m.m_type).m_size / sizeof(U32);
 		const U32 componentCount = getShaderVariableDataTypeInfo(m.m_type).m_size / sizeof(U32);
-		StringRaii values(m_alloc);
+		StringRaii values(m_pool);
 		for(U32 j = 0; j < componentCount; ++j)
 		for(U32 j = 0; j < componentCount; ++j)
 		{
 		{
-			StringRaii tmp(m_alloc);
+			StringRaii tmp(m_pool);
 			tmp.sprintf("%s(ssbo[%s_%s_OFFSETOF + offset + %uu])%s", (isIntegral) ? "" : "uintBitsToFloat",
 			tmp.sprintf("%s(ssbo[%s_%s_OFFSETOF + offset + %uu])%s", (isIntegral) ? "" : "uintBitsToFloat",
 						structName.cstr(), m.m_name.cstr(), j, (j != componentCount - 1) ? "," : "");
 						structName.cstr(), m.m_name.cstr(), j, (j != componentCount - 1) ? "," : "");
 
 
@@ -1085,10 +1084,10 @@ Error ShaderProgramParser::parseFile(CString fname, U32 depth)
 	Bool foundPragmaOnce = false;
 	Bool foundPragmaOnce = false;
 
 
 	// Load file in lines
 	// Load file in lines
-	StringRaii txt(m_alloc);
+	StringRaii txt(m_pool);
 	ANKI_CHECK(m_fsystem->readAllText(fname, txt));
 	ANKI_CHECK(m_fsystem->readAllText(fname, txt));
 
 
-	StringListAuto lines(m_alloc);
+	StringListRaii lines(m_pool);
 	lines.splitString(txt.toCString(), '\n');
 	lines.splitString(txt.toCString(), '\n');
 	if(lines.getSize() < 1)
 	if(lines.getSize() < 1)
 	{
 	{
@@ -1213,13 +1212,13 @@ Error ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation
 
 
 	// Init variant
 	// Init variant
 	::new(&variant) ShaderProgramParserVariant();
 	::new(&variant) ShaderProgramParserVariant();
-	variant.m_alloc = m_alloc;
+	variant.m_pool = m_pool;
 
 
 	// Create the mutator defines
 	// Create the mutator defines
-	StringRaii mutatorDefines(m_alloc);
+	StringRaii mutatorDefines(m_pool);
 	for(U32 i = 0; i < mutation.getSize(); ++i)
 	for(U32 i = 0; i < mutation.getSize(); ++i)
 	{
 	{
-		mutatorDefines.append(StringRaii(m_alloc).sprintf("#define %s %d\n", m_mutators[i].m_name.cstr(), mutation[i]));
+		mutatorDefines.append(StringRaii(m_pool).sprintf("#define %s %d\n", m_mutators[i].m_name.cstr(), mutation[i]));
 	}
 	}
 
 
 	// Generate souce per stage
 	// Generate souce per stage
@@ -1231,11 +1230,11 @@ Error ShaderProgramParser::generateVariant(ConstWeakArray<MutatorValue> mutation
 		}
 		}
 
 
 		// Create the header
 		// Create the header
-		StringRaii header(m_alloc);
+		StringRaii header(m_pool);
 		generateAnkiShaderHeader(shaderType, m_compilerOptions, header);
 		generateAnkiShaderHeader(shaderType, m_compilerOptions, header);
 
 
 		// Create the final source without the bindings
 		// Create the final source without the bindings
-		StringRaii finalSource(m_alloc);
+		StringRaii finalSource(m_pool);
 		finalSource.append(header);
 		finalSource.append(header);
 		finalSource.append(mutatorDefines);
 		finalSource.append(mutatorDefines);
 		finalSource.append(m_codeSource);
 		finalSource.append(m_codeSource);

+ 21 - 21
AnKi/ShaderCompiler/ShaderProgramParser.h

@@ -25,9 +25,9 @@ class ShaderProgramParserMutator
 	friend ShaderProgramParser;
 	friend ShaderProgramParser;
 
 
 public:
 public:
-	ShaderProgramParserMutator(GenericMemoryPoolAllocator<U8> alloc)
-		: m_name(alloc)
-		, m_values(alloc)
+	ShaderProgramParserMutator(BaseMemoryPool* pool)
+		: m_name(pool)
+		, m_values(pool)
 	{
 	{
 	}
 	}
 
 
@@ -55,8 +55,8 @@ public:
 	U32 m_dependentMutator = kMaxU32;
 	U32 m_dependentMutator = kMaxU32;
 	MutatorValue m_mutatorValue = 0;
 	MutatorValue m_mutatorValue = 0;
 
 
-	ShaderProgramParserMember(GenericMemoryPoolAllocator<U8> alloc)
-		: m_name(alloc)
+	ShaderProgramParserMember(BaseMemoryPool* pool)
+		: m_name(pool)
 	{
 	{
 	}
 	}
 };
 };
@@ -68,9 +68,9 @@ public:
 	DynamicArrayRaii<ShaderProgramParserMember> m_members;
 	DynamicArrayRaii<ShaderProgramParserMember> m_members;
 	StringRaii m_name;
 	StringRaii m_name;
 
 
-	ShaderProgramParserGhostStruct(GenericMemoryPoolAllocator<U8> alloc)
-		: m_members(alloc)
-		, m_name(alloc)
+	ShaderProgramParserGhostStruct(BaseMemoryPool* pool)
+		: m_members(pool)
+		, m_name(pool)
 	{
 	{
 	}
 	}
 };
 };
@@ -85,7 +85,7 @@ public:
 	{
 	{
 		for(String& s : m_sources)
 		for(String& s : m_sources)
 		{
 		{
-			s.destroy(m_alloc);
+			s.destroy(*m_pool);
 		}
 		}
 	}
 	}
 
 
@@ -95,7 +95,7 @@ public:
 	}
 	}
 
 
 private:
 private:
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	Array<String, U32(ShaderType::kCount)> m_sources;
 	Array<String, U32(ShaderType::kCount)> m_sources;
 };
 };
 
 
@@ -122,7 +122,7 @@ private:
 class ShaderProgramParser
 class ShaderProgramParser
 {
 {
 public:
 public:
-	ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, GenericMemoryPoolAllocator<U8> alloc,
+	ShaderProgramParser(CString fname, ShaderProgramFilesystemInterface* fsystem, BaseMemoryPool* pool,
 						const ShaderCompilerOptions& compilerOptions);
 						const ShaderCompilerOptions& compilerOptions);
 
 
 	ShaderProgramParser(const ShaderProgramParser&) = delete; // Non-copyable
 	ShaderProgramParser(const ShaderProgramParser&) = delete; // Non-copyable
@@ -190,35 +190,35 @@ private:
 	public:
 	public:
 		DynamicArrayRaii<MutatorValue> m_partialMutation;
 		DynamicArrayRaii<MutatorValue> m_partialMutation;
 
 
-		PartialMutationSkip(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_partialMutation(alloc)
+		PartialMutationSkip(BaseMemoryPool* pool)
+			: m_partialMutation(pool)
 		{
 		{
 		}
 		}
 	};
 	};
 
 
 	static constexpr U32 MAX_INCLUDE_DEPTH = 8;
 	static constexpr U32 MAX_INCLUDE_DEPTH = 8;
 
 
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	StringRaii m_fname;
 	StringRaii m_fname;
 	ShaderProgramFilesystemInterface* m_fsystem = nullptr;
 	ShaderProgramFilesystemInterface* m_fsystem = nullptr;
 
 
-	StringListRaii m_codeLines = {m_alloc}; ///< The code.
-	StringRaii m_codeSource = {m_alloc};
+	StringListRaii m_codeLines = {m_pool}; ///< The code.
+	StringRaii m_codeSource = {m_pool};
 	U64 m_codeSourceHash = 0;
 	U64 m_codeSourceHash = 0;
 
 
-	DynamicArrayRaii<Mutator> m_mutators = {m_alloc};
-	DynamicArrayRaii<PartialMutationSkip> m_skipMutations = {m_alloc};
+	DynamicArrayRaii<Mutator> m_mutators = {m_pool};
+	DynamicArrayRaii<PartialMutationSkip> m_skipMutations = {m_pool};
 
 
 	ShaderTypeBit m_shaderTypes = ShaderTypeBit::kNone;
 	ShaderTypeBit m_shaderTypes = ShaderTypeBit::kNone;
 	Bool m_insideShader = false;
 	Bool m_insideShader = false;
 	ShaderCompilerOptions m_compilerOptions;
 	ShaderCompilerOptions m_compilerOptions;
 
 
-	StringRaii m_libName = {m_alloc};
+	StringRaii m_libName = {m_pool};
 	U32 m_rayType = kMaxU32;
 	U32 m_rayType = kMaxU32;
 
 
-	StringListRaii m_symbolsToReflect = {m_alloc};
+	StringListRaii m_symbolsToReflect = {m_pool};
 
 
-	DynamicArrayRaii<GhostStruct> m_ghostStructs = {m_alloc};
+	DynamicArrayRaii<GhostStruct> m_ghostStructs = {m_pool};
 	Bool m_insideStruct = false;
 	Bool m_insideStruct = false;
 
 
 	Error parseFile(CString fname, U32 depth);
 	Error parseFile(CString fname, U32 depth);

+ 39 - 40
AnKi/ShaderCompiler/ShaderProgramReflection.cpp

@@ -56,16 +56,16 @@ static ShaderVariableDataType spirvcrossBaseTypeToAnki(spirv_cross::SPIRType::Ba
 class SpirvReflector : public spirv_cross::Compiler
 class SpirvReflector : public spirv_cross::Compiler
 {
 {
 public:
 public:
-	SpirvReflector(const U32* ir, PtrSize wordCount, const GenericMemoryPoolAllocator<U8>& tmpAlloc,
+	SpirvReflector(const U32* ir, PtrSize wordCount, BaseMemoryPool* tmpPool,
 				   ShaderReflectionVisitorInterface* interface)
 				   ShaderReflectionVisitorInterface* interface)
 		: spirv_cross::Compiler(ir, wordCount)
 		: spirv_cross::Compiler(ir, wordCount)
-		, m_alloc(tmpAlloc)
+		, m_pool(tmpPool)
 		, m_interface(interface)
 		, m_interface(interface)
 	{
 	{
 	}
 	}
 
 
 	[[nodiscard]] static Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
 	[[nodiscard]] static Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
-													  GenericMemoryPoolAllocator<U8> tmpAlloc,
+													  BaseMemoryPool& tmpPool,
 													  ShaderReflectionVisitorInterface& interface);
 													  ShaderReflectionVisitorInterface& interface);
 
 
 private:
 private:
@@ -76,8 +76,8 @@ private:
 		ShaderVariableBlockInfo m_blockInfo;
 		ShaderVariableBlockInfo m_blockInfo;
 		ShaderVariableDataType m_type = ShaderVariableDataType::kNone;
 		ShaderVariableDataType m_type = ShaderVariableDataType::kNone;
 
 
-		Var(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
+		Var(BaseMemoryPool* pool)
+			: m_name(pool)
 		{
 		{
 		}
 		}
 	};
 	};
@@ -91,9 +91,9 @@ private:
 		U32 m_set = kMaxU32;
 		U32 m_set = kMaxU32;
 		U32 m_size = kMaxU32;
 		U32 m_size = kMaxU32;
 
 
-		Block(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
-			, m_vars(alloc)
+		Block(BaseMemoryPool* pool)
+			: m_name(pool)
+			, m_vars(pool)
 		{
 		{
 		}
 		}
 	};
 	};
@@ -107,8 +107,8 @@ private:
 		U32 m_set = kMaxU32;
 		U32 m_set = kMaxU32;
 		U32 m_arraySize = kMaxU32;
 		U32 m_arraySize = kMaxU32;
 
 
-		Opaque(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
+		Opaque(BaseMemoryPool* pool)
+			: m_name(pool)
 		{
 		{
 		}
 		}
 	};
 	};
@@ -120,8 +120,8 @@ private:
 		ShaderVariableDataType m_type = ShaderVariableDataType::kNone;
 		ShaderVariableDataType m_type = ShaderVariableDataType::kNone;
 		U32 m_constantId = kMaxU32;
 		U32 m_constantId = kMaxU32;
 
 
-		Const(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
+		Const(BaseMemoryPool* pool)
+			: m_name(pool)
 		{
 		{
 		}
 		}
 	};
 	};
@@ -135,8 +135,8 @@ private:
 		U32 m_offset = kMaxU32;
 		U32 m_offset = kMaxU32;
 		U32 m_arraySize = kMaxU32;
 		U32 m_arraySize = kMaxU32;
 
 
-		StructMember(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
+		StructMember(BaseMemoryPool* pool)
+			: m_name(pool)
 		{
 		{
 		}
 		}
 	};
 	};
@@ -149,14 +149,14 @@ private:
 		U32 m_size = 0;
 		U32 m_size = 0;
 		U32 m_alignment = 0;
 		U32 m_alignment = 0;
 
 
-		Struct(const GenericMemoryPoolAllocator<U8>& alloc)
-			: m_name(alloc)
-			, m_members(alloc)
+		Struct(BaseMemoryPool* pool)
+			: m_name(pool)
+			, m_members(pool)
 		{
 		{
 		}
 		}
 	};
 	};
 
 
-	GenericMemoryPoolAllocator<U8> m_alloc;
+	BaseMemoryPool* m_pool = nullptr;
 	ShaderReflectionVisitorInterface* m_interface = nullptr;
 	ShaderReflectionVisitorInterface* m_interface = nullptr;
 
 
 	Error spirvTypeToAnki(const spirv_cross::SPIRType& type, ShaderVariableDataType& out) const;
 	Error spirvTypeToAnki(const spirv_cross::SPIRType& type, ShaderVariableDataType& out) const;
@@ -233,8 +233,8 @@ Error SpirvReflector::structReflection(uint32_t id, const spirv_cross::SPIRType&
 	}
 	}
 
 
 	// Create new struct
 	// Create new struct
-	GenericMemoryPoolAllocator<U8> alloc = structs.getAllocator();
-	Struct cstruct(alloc);
+	BaseMemoryPool& pool = structs.getMemoryPool();
+	Struct cstruct(&pool);
 	cstruct.m_name = name.c_str();
 	cstruct.m_name = name.c_str();
 	U32 membersOffset = 0;
 	U32 membersOffset = 0;
 	Bool aMemberWasSkipped = false;
 	Bool aMemberWasSkipped = false;
@@ -242,7 +242,7 @@ Error SpirvReflector::structReflection(uint32_t id, const spirv_cross::SPIRType&
 	// Members
 	// Members
 	for(U32 i = 0; i < type.member_types.size(); ++i)
 	for(U32 i = 0; i < type.member_types.size(); ++i)
 	{
 	{
-		StructMember& member = *cstruct.m_members.emplaceBack(alloc);
+		StructMember& member = *cstruct.m_members.emplaceBack(&pool);
 		const spirv_cross::SPIRType& memberType = get<spirv_cross::SPIRType>(type.member_types[i]);
 		const spirv_cross::SPIRType& memberType = get<spirv_cross::SPIRType>(type.member_types[i]);
 
 
 		// Get name
 		// Get name
@@ -352,7 +352,7 @@ Error SpirvReflector::structReflection(uint32_t id, const spirv_cross::SPIRType&
 
 
 		alignRoundUp(cstruct.m_alignment, cstruct.m_size);
 		alignRoundUp(cstruct.m_alignment, cstruct.m_size);
 
 
-		Struct& newStruct = *structs.emplaceBack(alloc);
+		Struct& newStruct = *structs.emplaceBack(&pool);
 		newStruct = std::move(cstruct);
 		newStruct = std::move(cstruct);
 	}
 	}
 	else
 	else
@@ -400,7 +400,7 @@ Error SpirvReflector::blockVariableReflection(const spirv_cross::SPIRType& type,
 
 
 	for(U32 i = 0; i < type.member_types.size(); ++i)
 	for(U32 i = 0; i < type.member_types.size(); ++i)
 	{
 	{
-		Var var(m_alloc);
+		Var var(m_pool);
 		const spirv_cross::SPIRType& memberType = get<spirv_cross::SPIRType>(type.member_types[i]);
 		const spirv_cross::SPIRType& memberType = get<spirv_cross::SPIRType>(type.member_types[i]);
 
 
 		// Name
 		// Name
@@ -481,7 +481,7 @@ Error SpirvReflector::blockVariableReflection(const spirv_cross::SPIRType& type,
 			{
 			{
 				for(U32 i = 0; i < U32(var.m_blockInfo.m_arraySize); ++i)
 				for(U32 i = 0; i < U32(var.m_blockInfo.m_arraySize); ++i)
 				{
 				{
-					StringRaii newName(m_alloc);
+					StringRaii newName(m_pool);
 					newName.sprintf("%s[%u]", var.m_name.getBegin(), i);
 					newName.sprintf("%s[%u]", var.m_name.getBegin(), i);
 					ANKI_CHECK(blockVariableReflection(
 					ANKI_CHECK(blockVariableReflection(
 						memberType, newName, var.m_blockInfo.m_offset + var.m_blockInfo.m_arrayStride * i, vars));
 						memberType, newName, var.m_blockInfo.m_offset + var.m_blockInfo.m_arrayStride * i, vars));
@@ -538,7 +538,7 @@ Error SpirvReflector::blockVariableReflection(const spirv_cross::SPIRType& type,
 Error SpirvReflector::blockReflection(const spirv_cross::Resource& res, [[maybe_unused]] Bool isStorage,
 Error SpirvReflector::blockReflection(const spirv_cross::Resource& res, [[maybe_unused]] Bool isStorage,
 									  DynamicArrayRaii<Block>& blocks) const
 									  DynamicArrayRaii<Block>& blocks) const
 {
 {
-	Block newBlock(m_alloc);
+	Block newBlock(m_pool);
 	const spirv_cross::SPIRType type = get_type(res.type_id);
 	const spirv_cross::SPIRType type = get_type(res.type_id);
 	const spirv_cross::Bitset decorationMask = get_decoration_bitset(res.id);
 	const spirv_cross::Bitset decorationMask = get_decoration_bitset(res.id);
 
 
@@ -616,7 +616,7 @@ Error SpirvReflector::blockReflection(const spirv_cross::Resource& res, [[maybe_
 #if ANKI_ENABLE_ASSERTIONS
 #if ANKI_ENABLE_ASSERTIONS
 	else
 	else
 	{
 	{
-		DynamicArrayRaii<Var> vars(m_alloc);
+		DynamicArrayRaii<Var> vars(m_pool);
 		ANKI_CHECK(blockVariablesReflection(res.base_type_id, vars));
 		ANKI_CHECK(blockVariablesReflection(res.base_type_id, vars));
 		ANKI_ASSERT(vars.getSize() == otherFound->m_vars.getSize() && "Expecting same vars");
 		ANKI_ASSERT(vars.getSize() == otherFound->m_vars.getSize() && "Expecting same vars");
 	}
 	}
@@ -666,7 +666,7 @@ Error SpirvReflector::spirvTypeToAnki(const spirv_cross::SPIRType& type, ShaderV
 
 
 Error SpirvReflector::opaqueReflection(const spirv_cross::Resource& res, DynamicArrayRaii<Opaque>& opaques) const
 Error SpirvReflector::opaqueReflection(const spirv_cross::Resource& res, DynamicArrayRaii<Opaque>& opaques) const
 {
 {
-	Opaque newOpaque(m_alloc);
+	Opaque newOpaque(m_pool);
 	const spirv_cross::SPIRType type = get_type(res.type_id);
 	const spirv_cross::SPIRType type = get_type(res.type_id);
 	const spirv_cross::Bitset decorationMask = get_decoration_bitset(res.id);
 	const spirv_cross::Bitset decorationMask = get_decoration_bitset(res.id);
 
 
@@ -752,7 +752,7 @@ Error SpirvReflector::constsReflection(DynamicArrayRaii<Const>& consts) const
 	spirv_cross::SmallVector<spirv_cross::SpecializationConstant> specConsts = get_specialization_constants();
 	spirv_cross::SmallVector<spirv_cross::SpecializationConstant> specConsts = get_specialization_constants();
 	for(const spirv_cross::SpecializationConstant& c : specConsts)
 	for(const spirv_cross::SpecializationConstant& c : specConsts)
 	{
 	{
-		Const newConst(m_alloc);
+		Const newConst(m_pool);
 
 
 		const spirv_cross::SPIRConstant cc = get<spirv_cross::SPIRConstant>(c.id);
 		const spirv_cross::SPIRConstant cc = get<spirv_cross::SPIRConstant>(c.id);
 		const spirv_cross::SPIRType type = get<spirv_cross::SPIRType>(cc.constant_type);
 		const spirv_cross::SPIRType type = get<spirv_cross::SPIRType>(cc.constant_type);
@@ -866,17 +866,16 @@ Error SpirvReflector::workgroupSizes(U32& sizex, U32& sizey, U32& sizez, U32& sp
 }
 }
 
 
 Error SpirvReflector::performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
 Error SpirvReflector::performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
-											 GenericMemoryPoolAllocator<U8> tmpAlloc,
-											 ShaderReflectionVisitorInterface& interface)
+											 BaseMemoryPool& tmpPool, ShaderReflectionVisitorInterface& interface)
 {
 {
-	DynamicArrayRaii<Block> uniformBlocks(tmpAlloc);
-	DynamicArrayRaii<Block> storageBlocks(tmpAlloc);
-	DynamicArrayRaii<Block> pushConstantBlock(tmpAlloc);
-	DynamicArrayRaii<Opaque> opaques(tmpAlloc);
-	DynamicArrayRaii<Const> specializationConstants(tmpAlloc);
+	DynamicArrayRaii<Block> uniformBlocks(&tmpPool);
+	DynamicArrayRaii<Block> storageBlocks(&tmpPool);
+	DynamicArrayRaii<Block> pushConstantBlock(&tmpPool);
+	DynamicArrayRaii<Opaque> opaques(&tmpPool);
+	DynamicArrayRaii<Const> specializationConstants(&tmpPool);
 	Array<U32, 3> workgroupSizes = {};
 	Array<U32, 3> workgroupSizes = {};
 	U32 workgroupSizeSpecConstMask = 0;
 	U32 workgroupSizeSpecConstMask = 0;
-	DynamicArrayRaii<Struct> structs(tmpAlloc);
+	DynamicArrayRaii<Struct> structs(&tmpPool);
 
 
 	// Perform reflection for each stage
 	// Perform reflection for each stage
 	for(const ShaderType type : EnumIterable<ShaderType>())
 	for(const ShaderType type : EnumIterable<ShaderType>())
@@ -888,7 +887,7 @@ Error SpirvReflector::performSpirvReflection(Array<ConstWeakArray<U8>, U32(Shade
 
 
 		// Parse SPIR-V
 		// Parse SPIR-V
 		const unsigned int* spvb = reinterpret_cast<const unsigned int*>(spirv[type].getBegin());
 		const unsigned int* spvb = reinterpret_cast<const unsigned int*>(spirv[type].getBegin());
-		SpirvReflector compiler(spvb, spirv[type].getSizeInBytes() / sizeof(unsigned int), tmpAlloc, &interface);
+		SpirvReflector compiler(spvb, spirv[type].getSizeInBytes() / sizeof(unsigned int), &tmpPool, &interface);
 
 
 		// Uniform blocks
 		// Uniform blocks
 		for(const spirv_cross::Resource& res : compiler.get_shader_resources().uniform_buffers)
 		for(const spirv_cross::Resource& res : compiler.get_shader_resources().uniform_buffers)
@@ -1021,10 +1020,10 @@ Error SpirvReflector::performSpirvReflection(Array<ConstWeakArray<U8>, U32(Shade
 	return Error::kNone;
 	return Error::kNone;
 }
 }
 
 
-Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
-							 GenericMemoryPoolAllocator<U8> tmpAlloc, ShaderReflectionVisitorInterface& interface)
+Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv, BaseMemoryPool& tmpPool,
+							 ShaderReflectionVisitorInterface& interface)
 {
 {
-	return SpirvReflector::performSpirvReflection(spirv, tmpAlloc, interface);
+	return SpirvReflector::performSpirvReflection(spirv, tmpPool, interface);
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 2 - 2
AnKi/ShaderCompiler/ShaderProgramReflection.h

@@ -52,8 +52,8 @@ public:
 };
 };
 
 
 /// Does reflection using SPIR-V.
 /// Does reflection using SPIR-V.
-Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv,
-							 GenericMemoryPoolAllocator<U8> tmpAlloc, ShaderReflectionVisitorInterface& interface);
+Error performSpirvReflection(Array<ConstWeakArray<U8>, U32(ShaderType::kCount)> spirv, BaseMemoryPool& tmpPool,
+							 ShaderReflectionVisitorInterface& interface);
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki

+ 13 - 1
AnKi/Util/CpuMemoryPools.h

@@ -343,25 +343,37 @@ template<typename TMemPool>
 class MemoryPoolPtrWrapper
 class MemoryPoolPtrWrapper
 {
 {
 public:
 public:
-	TMemPool* m_pool;
+	TMemPool* m_pool = nullptr;
+
+	MemoryPoolPtrWrapper() = default;
 
 
 	MemoryPoolPtrWrapper(TMemPool* pool)
 	MemoryPoolPtrWrapper(TMemPool* pool)
 		: m_pool(pool)
 		: m_pool(pool)
 	{
 	{
+		ANKI_ASSERT(pool);
 	}
 	}
 
 
 	TMemPool* operator&()
 	TMemPool* operator&()
 	{
 	{
+		ANKI_ASSERT(m_pool);
 		return m_pool;
 		return m_pool;
 	}
 	}
 
 
+	operator TMemPool&()
+	{
+		ANKI_ASSERT(m_pool);
+		return *m_pool;
+	}
+
 	void* allocate(PtrSize size, PtrSize alignmentBytes)
 	void* allocate(PtrSize size, PtrSize alignmentBytes)
 	{
 	{
+		ANKI_ASSERT(m_pool);
 		return m_pool->allocate(size, alignmentBytes);
 		return m_pool->allocate(size, alignmentBytes);
 	}
 	}
 
 
 	void free(void* ptr)
 	void free(void* ptr)
 	{
 	{
+		ANKI_ASSERT(m_pool);
 		m_pool->free(ptr);
 		m_pool->free(ptr);
 	}
 	}
 };
 };

+ 6 - 0
AnKi/Util/DynamicArray.h

@@ -498,6 +498,12 @@ public:
 		return m_pool;
 		return m_pool;
 	}
 	}
 
 
+	/// Get the pool.
+	MemoryPool& getMemoryPool()
+	{
+		return m_pool;
+	}
+
 private:
 private:
 	MemoryPool m_pool;
 	MemoryPool m_pool;
 };
 };

+ 4 - 0
AnKi/Util/Functions.h

@@ -371,6 +371,10 @@ void callConstructor(T& p, TArgs&&... args)
 	::new(&p) T(std::forward<TArgs>(args)...);
 	::new(&p) T(std::forward<TArgs>(args)...);
 }
 }
 
 
+#define ANKI_FRIEND_CALL_CONSTRUCTOR \
+	template<typename T, typename... TArgs> \
+	friend void callConstructor(T& p, TArgs&&... args);
+
 /// Call the destructor of an object.
 /// Call the destructor of an object.
 template<typename T>
 template<typename T>
 void callDestructor(T& p)
 void callDestructor(T& p)

+ 3 - 3
AnKi/Util/HashMap.h

@@ -275,19 +275,19 @@ public:
 	template<typename... TArgs>
 	template<typename... TArgs>
 	typename Base::Iterator emplace(const TKey& key, TArgs&&... args)
 	typename Base::Iterator emplace(const TKey& key, TArgs&&... args)
 	{
 	{
-		return Base::emplace(*m_pool, key, std::forward<TArgs>(args)...);
+		return Base::emplace(m_pool, key, std::forward<TArgs>(args)...);
 	}
 	}
 
 
 	/// Erase element.
 	/// Erase element.
 	void erase(typename Base::Iterator it)
 	void erase(typename Base::Iterator it)
 	{
 	{
-		Base::erase(*m_pool, it);
+		Base::erase(m_pool, it);
 	}
 	}
 
 
 	/// Clean up the map.
 	/// Clean up the map.
 	void destroy()
 	void destroy()
 	{
 	{
-		Base::destroy(*m_pool);
+		Base::destroy(m_pool);
 	}
 	}
 
 
 private:
 private:

+ 1 - 1
AnKi/Util/Ptr.h

@@ -253,7 +253,7 @@ class DefaultPtrDeleter
 public:
 public:
 	void operator()(T* x)
 	void operator()(T* x)
 	{
 	{
-		auto pool = x->getMemoryPool();
+		auto& pool = x->getMemoryPool();
 		deleteInstance<T>(pool, x);
 		deleteInstance<T>(pool, x);
 	}
 	}
 };
 };

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

@@ -56,7 +56,7 @@ Error BinarySerializer::serializeInternal(const T& x, BaseMemoryPool& tmpPool, F
 	}
 	}
 
 
 	// Write all pointers. Do that now and not while writing the actual shader in order to avoid the file seeks
 	// Write all pointers. Do that now and not while writing the actual shader in order to avoid the file seeks
-	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::BEGINNING));

+ 1 - 1
AnKi/Util/String.h

@@ -853,7 +853,7 @@ public:
 	}
 	}
 
 
 	/// Create with memory pool and data.
 	/// Create with memory pool and data.
-	BaseStringRaii(MemoryPool& pool, const CStringType& cstr)
+	BaseStringRaii(const MemoryPool& pool, const CStringType& cstr)
 		: Base()
 		: Base()
 		, m_pool(pool)
 		, m_pool(pool)
 	{
 	{