Przeglądaj źródła

Some refactoring

Panagiotis Christopoulos Charitos 3 miesięcy temu
rodzic
commit
7e5e2d3423

+ 1 - 1
AnKi/Renderer/IndirectDiffuseProbes.cpp

@@ -151,7 +151,7 @@ void IndirectDiffuseProbes::populateRenderGraph(RenderingContext& rctx)
 	}
 
 	GlobalIlluminationProbeComponent* probeToRefresh = (bestCandidateProbe) ? bestCandidateProbe : secondBestCandidateProbe;
-	if(probeToRefresh == nullptr || ResourceManager::getSingleton().getAsyncLoader().getTasksInFlightCount() != 0) [[likely]]
+	if(probeToRefresh == nullptr || AsyncLoader::getSingleton().getTasksInFlightCount() != 0) [[likely]]
 	{
 		// Nothing to update or can't update right now, early exit
 		m_runCtx = {};

+ 1 - 1
AnKi/Renderer/ProbeReflections.cpp

@@ -97,7 +97,7 @@ void ProbeReflections::populateRenderGraph(RenderingContext& rctx)
 		}
 	}
 
-	if(probeToRefresh == nullptr || ResourceManager::getSingleton().getAsyncLoader().getTasksInFlightCount() != 0
+	if(probeToRefresh == nullptr || AsyncLoader::getSingleton().getTasksInFlightCount() != 0
 	   || getRenderer().getIndirectDiffuseProbes().hasCurrentlyRefreshedVolumeRt()) [[likely]]
 	{
 		// Nothing to update or can't update right now, early exit

+ 1 - 1
AnKi/Resource/AccelerationStructureScratchAllocator.h

@@ -15,7 +15,7 @@ namespace anki {
 /// @{
 
 /// Ring buffer used for AS scratch memory.
-class AccelerationStructureScratchAllocator
+class AccelerationStructureScratchAllocator : public MakeSingleton<AccelerationStructureScratchAllocator>
 {
 public:
 	static constexpr PtrSize kBufferSize = 64_MB;

+ 1 - 1
AnKi/Resource/AsyncLoader.h

@@ -36,7 +36,7 @@ public:
 };
 
 /// Asynchronous resource loader.
-class AsyncLoader
+class AsyncLoader : public MakeSingleton<AsyncLoader>
 {
 public:
 	AsyncLoader();

+ 4 - 4
AnKi/Resource/ImageResource.cpp

@@ -46,7 +46,7 @@ Error ImageResource::load(const ResourceFilename& filename, Bool async)
 
 	if(async)
 	{
-		task = ResourceManager::getSingleton().getAsyncLoader().newTask<TexUploadTask>();
+		task = AsyncLoader::getSingleton().newTask<TexUploadTask>();
 		ctx = &task->m_ctx;
 	}
 	else
@@ -220,7 +220,7 @@ Error ImageResource::load(const ResourceFilename& filename, Bool async)
 	// Upload the data
 	if(async)
 	{
-		ResourceManager::getSingleton().getAsyncLoader().submitTask(task);
+		AsyncLoader::getSingleton().submitTask(task);
 	}
 	else
 	{
@@ -291,7 +291,7 @@ Error ImageResource::load(LoadingContext& ctx)
 
 			ANKI_ASSERT(allocationSize >= surfOrVolSize);
 			TransferGpuAllocatorHandle& handle = handles[handleCount++];
-			ANKI_CHECK(ResourceManager::getSingleton().getTransferGpuAllocator().allocate(allocationSize, handle));
+			ANKI_CHECK(TransferGpuAllocator::getSingleton().allocate(allocationSize, handle));
 			void* data = handle.getMappedMemory();
 			ANKI_ASSERT(data);
 
@@ -321,7 +321,7 @@ Error ImageResource::load(LoadingContext& ctx)
 
 		for(U i = 0; i < handleCount; ++i)
 		{
-			ResourceManager::getSingleton().getTransferGpuAllocator().release(handles[i], fence);
+			TransferGpuAllocator::getSingleton().release(handles[i], fence);
 		}
 		cmdb.reset(nullptr);
 	}

+ 1 - 1
AnKi/Resource/MeshBinaryLoader.cpp

@@ -34,7 +34,7 @@ static Error checkBoundingVolume(const MeshBinaryBoundingVolume& vol)
 Error MeshBinaryLoader::load(const ResourceFilename& filename)
 {
 	// Load header + submeshes
-	ANKI_CHECK(ResourceManager::getSingleton().getFilesystem().openFile(filename, m_file));
+	ANKI_CHECK(ResourceFilesystem::getSingleton().openFile(filename, m_file));
 	ANKI_CHECK(m_file->read(&m_header, sizeof(m_header)));
 	ANKI_CHECK(checkHeader());
 	ANKI_CHECK(loadSubmeshes());

+ 5 - 5
AnKi/Resource/MeshResource.cpp

@@ -76,7 +76,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 
 	if(async)
 	{
-		task.reset(ResourceManager::getSingleton().getAsyncLoader().newTask<LoadTask>(this));
+		task.reset(AsyncLoader::getSingleton().newTask<LoadTask>(this));
 		ctx = &task->m_ctx;
 	}
 	else
@@ -230,7 +230,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 	// Submit the loading task
 	if(async)
 	{
-		ResourceManager::getSingleton().getAsyncLoader().submitTask(task.get());
+		AsyncLoader::getSingleton().submitTask(task.get());
 		LoadTask* pTask;
 		task.moveAndReset(pTask);
 	}
@@ -245,7 +245,7 @@ Error MeshResource::load(const ResourceFilename& filename, Bool async)
 Error MeshResource::loadAsync(MeshBinaryLoader& loader) const
 {
 	GrManager& gr = GrManager::getSingleton();
-	TransferGpuAllocator& transferAlloc = ResourceManager::getSingleton().getTransferGpuAllocator();
+	TransferGpuAllocator& transferAlloc = TransferGpuAllocator::getSingleton();
 
 	Array<TransferGpuAllocatorHandle, kMaxLodCount*(U32(VertexStreamId::kMeshRelatedCount) + 1 + 3)> handles;
 	U32 handleCount = 0;
@@ -395,8 +395,8 @@ Error MeshResource::loadAsync(MeshBinaryLoader& loader) const
 			for(U32 lodIdx = 0; lodIdx < m_lods.getSize(); ++lodIdx)
 			{
 				Bool addBarrier;
-				const BufferView scratchBuff = ResourceManager::getSingleton().getAccelerationStructureScratchAllocator().allocate(
-					submesh.m_blas[lodIdx]->getBuildScratchBufferSize(), addBarrier);
+				const BufferView scratchBuff =
+					AccelerationStructureScratchAllocator::getSingleton().allocate(submesh.m_blas[lodIdx]->getBuildScratchBufferSize(), addBarrier);
 
 				if(addBarrier)
 				{

+ 0 - 15
AnKi/Resource/ModelResource.cpp

@@ -45,21 +45,6 @@ void ModelPatch::getGeometryInfo(U32 lod, ModelPatchGeometryInfo& inf) const
 	}
 }
 
-void ModelPatch::getRayTracingInfo(const RenderingKey& key, ModelRayTracingInfo& info) const
-{
-	ANKI_ASSERT(!!(m_mtl->getRenderingTechniques() & RenderingTechniqueBit(1 << key.getRenderingTechnique())));
-
-	// Mesh
-	const U32 meshLod = min<U32>(key.getLod(), m_meshLodCount - 1);
-	info.m_bottomLevelAccelerationStructure = m_mesh->getBottomLevelAccelerationStructure(meshLod, m_submeshIdx);
-
-	info.m_indexUgbOffset = m_lodInfos[meshLod].m_indexUgbOffset;
-
-	// Material
-	const MaterialVariant& variant = m_mtl->getOrCreateVariant(key);
-	info.m_shaderGroupHandleIndex = variant.getRtShaderGroupHandleIndex();
-}
-
 Error ModelPatch::init([[maybe_unused]] ModelResource* model, CString meshFName, const CString& mtlFName, U32 subMeshIndex, Bool async)
 {
 #if ANKI_ASSERTIONS_ENABLED

+ 0 - 14
AnKi/Resource/ModelResource.h

@@ -17,17 +17,6 @@ namespace anki {
 /// @addtogroup resource
 /// @{
 
-/// Part of the information required to create a TLAS and a SBT.
-/// @memberof ModelResource
-class ModelRayTracingInfo
-{
-public:
-	AccelerationStructurePtr m_bottomLevelAccelerationStructure;
-	U32 m_shaderGroupHandleIndex;
-
-	PtrSize m_indexUgbOffset;
-};
-
 /// @memberof ModelResource
 /// Part of the information required render the model.
 class ModelPatchGeometryInfo
@@ -70,9 +59,6 @@ public:
 
 	void getGeometryInfo(U32 lod, ModelPatchGeometryInfo& inf) const;
 
-	/// Get the ray tracing info.
-	void getRayTracingInfo(const RenderingKey& key, ModelRayTracingInfo& info) const;
-
 private:
 	class Lod
 	{

+ 1 - 1
AnKi/Resource/ResourceFilesystem.h

@@ -84,7 +84,7 @@ public:
 using ResourceFilePtr = IntrusivePtr<ResourceFile, ResourceFileDeleter>;
 
 /// Resource filesystem.
-class ResourceFilesystem
+class ResourceFilesystem : public MakeSingleton<ResourceFilesystem>
 {
 public:
 	ResourceFilesystem() = default;

+ 13 - 13
AnKi/Resource/ResourceManager.cpp

@@ -34,17 +34,17 @@ ResourceManager::~ResourceManager()
 {
 	ANKI_RESOURCE_LOGI("Destroying resource manager");
 
-	deleteInstance(ResourceMemoryPool::getSingleton(), m_asyncLoader);
-	deleteInstance(ResourceMemoryPool::getSingleton(), m_shaderProgramSystem);
-	deleteInstance(ResourceMemoryPool::getSingleton(), m_transferGpuAlloc);
-	deleteInstance(ResourceMemoryPool::getSingleton(), m_fs);
+	AsyncLoader::freeSingleton();
+	ShaderProgramResourceSystem::freeSingleton();
+	TransferGpuAllocator::freeSingleton();
+	ResourceFilesystem::freeSingleton();
 
 #define ANKI_INSTANTIATE_RESOURCE(className) \
 	static_cast<TypeData<className>&>(m_allTypes).m_entries.destroy(); \
 	static_cast<TypeData<className>&>(m_allTypes).m_map.destroy();
 #include <AnKi/Resource/Resources.def.h>
 
-	deleteInstance(ResourceMemoryPool::getSingleton(), m_asScratchAlloc);
+	AccelerationStructureScratchAllocator::freeSingleton();
 
 	ResourceMemoryPool::freeSingleton();
 }
@@ -55,22 +55,22 @@ Error ResourceManager::init(AllocAlignedCallback allocCallback, void* allocCallb
 
 	ResourceMemoryPool::allocateSingleton(allocCallback, allocCallbackData);
 
-	m_fs = newInstance<ResourceFilesystem>(ResourceMemoryPool::getSingleton());
-	ANKI_CHECK(m_fs->init());
+	ResourceFilesystem::allocateSingleton();
+	ANKI_CHECK(ResourceFilesystem::getSingleton().init());
 
 	// Init the thread
-	m_asyncLoader = newInstance<AsyncLoader>(ResourceMemoryPool::getSingleton());
+	AsyncLoader::allocateSingleton();
 
-	m_transferGpuAlloc = newInstance<TransferGpuAllocator>(ResourceMemoryPool::getSingleton());
-	ANKI_CHECK(m_transferGpuAlloc->init(g_transferScratchMemorySizeCVar));
+	TransferGpuAllocator::allocateSingleton();
+	ANKI_CHECK(TransferGpuAllocator::getSingleton().init(g_transferScratchMemorySizeCVar));
 
 	// Init the programs
-	m_shaderProgramSystem = newInstance<ShaderProgramResourceSystem>(ResourceMemoryPool::getSingleton());
-	ANKI_CHECK(m_shaderProgramSystem->init());
+	ShaderProgramResourceSystem::allocateSingleton();
+	ANKI_CHECK(ShaderProgramResourceSystem::getSingleton().init());
 
 	if(GrManager::getSingleton().getDeviceCapabilities().m_rayTracingEnabled)
 	{
-		m_asScratchAlloc = newInstance<AccelerationStructureScratchAllocator>(ResourceMemoryPool::getSingleton());
+		AccelerationStructureScratchAllocator::allocateSingleton();
 	}
 
 	return Error::kNone;

+ 0 - 33
AnKi/Resource/ResourceManager.h

@@ -55,33 +55,6 @@ public:
 	template<typename T>
 	ANKI_INTERNAL void freeResource(T* ptr);
 
-	ANKI_INTERNAL TransferGpuAllocator& getTransferGpuAllocator()
-	{
-		return *m_transferGpuAlloc;
-	}
-
-	ANKI_INTERNAL AsyncLoader& getAsyncLoader()
-	{
-		return *m_asyncLoader;
-	}
-
-	/// Return the container of program libraries.
-	ANKI_INTERNAL const ShaderProgramResourceSystem& getShaderProgramResourceSystem() const
-	{
-		return *m_shaderProgramSystem;
-	}
-
-	ANKI_INTERNAL ResourceFilesystem& getFilesystem()
-	{
-		return *m_fs;
-	}
-
-	ANKI_INTERNAL AccelerationStructureScratchAllocator& getAccelerationStructureScratchAllocator()
-	{
-		ANKI_ASSERT(m_asScratchAlloc);
-		return *m_asScratchAlloc;
-	}
-
 private:
 	template<typename Type>
 	class TypeData
@@ -116,12 +89,6 @@ public \
 	{
 	};
 
-	ResourceFilesystem* m_fs = nullptr;
-	AsyncLoader* m_asyncLoader = nullptr; ///< Async loading thread
-	ShaderProgramResourceSystem* m_shaderProgramSystem = nullptr;
-	TransferGpuAllocator* m_transferGpuAlloc = nullptr;
-	AccelerationStructureScratchAllocator* m_asScratchAlloc = nullptr;
-
 	AllTypeData m_allTypes;
 
 	Atomic<U32> m_uuid = {1};

+ 2 - 2
AnKi/Resource/ResourceObject.cpp

@@ -11,14 +11,14 @@ namespace anki {
 
 Error ResourceObject::openFile(const CString& filename, ResourceFilePtr& file)
 {
-	return ResourceManager::getSingleton().getFilesystem().openFile(filename, file);
+	return ResourceFilesystem::getSingleton().openFile(filename, file);
 }
 
 Error ResourceObject::openFileReadAllText(const CString& filename, ResourceString& text)
 {
 	// Load file
 	ResourceFilePtr file;
-	ANKI_CHECK(ResourceManager::getSingleton().getFilesystem().openFile(filename, file));
+	ANKI_CHECK(ResourceFilesystem::getSingleton().openFile(filename, file));
 
 	// Read string
 	ANKI_CHECK(file->readAllText(text));

+ 1 - 1
AnKi/Resource/ShaderProgramResource.cpp

@@ -260,7 +260,7 @@ ShaderProgramResourceVariant* ShaderProgramResource::createNewVariant(const Shad
 		const CString libName = m_binary->m_techniques[techniqueIdx].m_name.getBegin();
 		ANKI_ASSERT(libName.getLength() > 0);
 
-		const ShaderProgramResourceSystem& progSystem = ResourceManager::getSingleton().getShaderProgramResourceSystem();
+		const ShaderProgramResourceSystem& progSystem = ShaderProgramResourceSystem::getSingleton();
 		const ShaderProgramRaytracingLibrary* foundLib = nullptr;
 		for(const ShaderProgramRaytracingLibrary& lib : progSystem.getRayTracingLibraries())
 		{

+ 2 - 2
AnKi/Resource/ShaderProgramResourceSystem.cpp

@@ -160,7 +160,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceDynamicArray
 
 	ResourceDynamicArray<Lib> libs;
 
-	const Error err = ResourceManager::getSingleton().getFilesystem().iterateAllFilenames([&](CString filename) -> Error {
+	const Error err = ResourceFilesystem::getSingleton().iterateAllFilenames([&](CString filename) -> Error {
 		// Check file extension
 		String extension;
 		getFilepathExtension(filename, extension);
@@ -172,7 +172,7 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(ResourceDynamicArray
 
 		// Get the binary
 		ResourceFilePtr file;
-		ANKI_CHECK(ResourceManager::getSingleton().getFilesystem().openFile(filename, file));
+		ANKI_CHECK(ResourceFilesystem::getSingleton().openFile(filename, file));
 		ShaderBinary* binary;
 		ANKI_CHECK(deserializeShaderBinaryFromAnyFile(*file, binary, ResourceMemoryPool::getSingleton()));
 

+ 1 - 1
AnKi/Resource/ShaderProgramResourceSystem.h

@@ -73,7 +73,7 @@ private:
 };
 
 /// A system that does some work on shader programs before resources start loading.
-class ShaderProgramResourceSystem
+class ShaderProgramResourceSystem : public MakeSingleton<ShaderProgramResourceSystem>
 {
 public:
 	ShaderProgramResourceSystem()

+ 0 - 5
AnKi/Resource/TransferGpuAllocator.cpp

@@ -45,11 +45,6 @@ Error TransferGpuAllocator::init(PtrSize maxSize)
 	m_maxAllocSize = getAlignedRoundUp(kChunkInitialSize * kPoolCount, maxSize);
 	ANKI_RESOURCE_LOGI("Will use %zuMB of memory for transfer scratch", m_maxAllocSize / PtrSize(1_MB));
 
-	for(Pool& pool : m_pools)
-	{
-		pool.m_stackAlloc.getInterface().m_parent = this;
-	}
-
 	return Error::kNone;
 }
 

+ 1 - 3
AnKi/Resource/TransferGpuAllocator.h

@@ -99,7 +99,7 @@ private:
 };
 
 /// GPU memory allocator for GPU buffers used in transfer operations.
-class TransferGpuAllocator
+class TransferGpuAllocator : public MakeSingleton<TransferGpuAllocator>
 {
 	friend class TransferGpuAllocatorHandle;
 
@@ -150,8 +150,6 @@ private:
 	class StackAllocatorBuilderInterface
 	{
 	public:
-		TransferGpuAllocator* m_parent = nullptr; // TODO glob: maybe rm
-
 		// The rest of the functions implement the StackAllocatorBuilder TInterface.
 
 		static constexpr PtrSize getInitialChunkSize()

+ 1 - 1
AnKi/Shaders/Include/GpuSceneTypes.h

@@ -77,7 +77,7 @@ struct GpuSceneMeshLod
 	F32 m_positionScale;
 
 	UVec2 m_blasAddress;
-	U32 m_tlasInstanceMask; ///< Mask that goes to AccelerationStructureInstance::m_instanceCustomIndex24_mask8
+	U32 m_tlasInstanceMask; ///< Mask that goes to AccelerationStructureInstance::m_mask
 	U32 m_padding3;
 };
 static_assert(sizeof(GpuSceneMeshLod) == sizeof(Vec4) * 5);

+ 1 - 1
AnKi/Ui/Font.cpp

@@ -26,7 +26,7 @@ Error Font::init(const CString& filename, ConstWeakArray<U32> fontHeights)
 
 	// Load font in memory
 	ResourceFilePtr file;
-	ANKI_CHECK(ResourceManager::getSingleton().getFilesystem().openFile(filename, file));
+	ANKI_CHECK(ResourceFilesystem::getSingleton().openFile(filename, file));
 	m_fontData.resize(U32(file->getSize()));
 	ANKI_CHECK(file->read(&m_fontData[0], file->getSize()));