Browse Source

Some refactoring

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
739f7ad220

+ 1 - 1
src/anki/scene/SceneNode.cpp

@@ -41,7 +41,7 @@ void SceneNode::setMarkedForDeletion()
 	// Mark for deletion only when it's not already marked because we don't want to increase the counter again
 	// Mark for deletion only when it's not already marked because we don't want to increase the counter again
 	if(!getMarkedForDeletion())
 	if(!getMarkedForDeletion())
 	{
 	{
-		m_flags.set(Flag::MARKED_FOR_DELETION);
+		m_markedForDeletion = true;
 		m_scene->increaseObjectsMarkedForDeletion();
 		m_scene->increaseObjectsMarkedForDeletion();
 	}
 	}
 
 

+ 5 - 12
src/anki/scene/SceneNode.h

@@ -59,7 +59,7 @@ public:
 
 
 	Bool getMarkedForDeletion() const
 	Bool getMarkedForDeletion() const
 	{
 	{
-		return m_flags.get(Flag::MARKED_FOR_DELETION);
+		return m_markedForDeletion;
 	}
 	}
 
 
 	void setMarkedForDeletion();
 	void setMarkedForDeletion();
@@ -219,23 +219,16 @@ protected:
 	ResourceManager& getResourceManager();
 	ResourceManager& getResourceManager();
 
 
 private:
 private:
-	enum class Flag : U8
-	{
-		MARKED_FOR_DELETION = 1 << 0
-	};
-	ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(Flag, friend)
-
 	SceneGraph* m_scene = nullptr;
 	SceneGraph* m_scene = nullptr;
-
-	DynamicArray<SceneComponent*> m_components;
-
+	U64 m_uuid;
 	String m_name; ///< A unique name
 	String m_name; ///< A unique name
-	BitMask<Flag> m_flags;
 
 
-	U64 m_uuid;
+	DynamicArray<SceneComponent*> m_components;
 
 
 	Timestamp m_maxComponentTimestamp = 0;
 	Timestamp m_maxComponentTimestamp = 0;
 
 
+	Bool8 m_markedForDeletion = false;
+
 	void cacheImportantComponents();
 	void cacheImportantComponents();
 };
 };
 /// @}
 /// @}

+ 18 - 28
src/anki/scene/Visibility.cpp

@@ -74,10 +74,10 @@ void VisibilityContext::submitNewWork(const FrustumComponent& frc, RenderQueue&
 	if(frc.visibilityTestsEnabled(FrustumComponentVisibilityTestFlag::OCCLUDERS) && frc.hasCoverageBuffer())
 	if(frc.visibilityTestsEnabled(FrustumComponentVisibilityTestFlag::OCCLUDERS) && frc.hasCoverageBuffer())
 	{
 	{
 		// Gather triangles task
 		// Gather triangles task
-		ThreadHiveTask fillDepthTask;
-		fillDepthTask.m_callback = FillRasterizerWithCoverageTask::callback;
-		fillDepthTask.m_argument = alloc.newInstance<FillRasterizerWithCoverageTask>(frcCtx);
-		fillDepthTask.m_signalSemaphore = hive.newSemaphore(1);
+		ThreadHiveTask fillDepthTask = ANKI_THREAD_HIVE_TASK({ self->fill(); },
+			alloc.newInstance<FillRasterizerWithCoverageTask>(frcCtx),
+			nullptr,
+			hive.newSemaphore(1));
 
 
 		hive.submitTasks(&fillDepthTask, 1);
 		hive.submitTasks(&fillDepthTask, 1);
 
 
@@ -90,22 +90,17 @@ void VisibilityContext::submitNewWork(const FrustumComponent& frc, RenderQueue&
 		rqueue.m_fillCoverageBufferCallbackUserData = static_cast<void*>(const_cast<FrustumComponent*>(&frc));
 		rqueue.m_fillCoverageBufferCallbackUserData = static_cast<void*>(const_cast<FrustumComponent*>(&frc));
 	}
 	}
 
 
-	// Gather visibles from the octree
-	ThreadHiveTask gatherTask;
-	gatherTask.m_callback = GatherVisiblesFromOctreeTask::callback;
-	gatherTask.m_argument = alloc.newInstance<GatherVisiblesFromOctreeTask>(frcCtx);
-	gatherTask.m_signalSemaphore = nullptr; // No need to signal anything because it will spawn new tasks
-	gatherTask.m_waitSemaphore = prepareRasterizerSem;
-
+	// Gather visibles from the octree. No need to signal anything because it will spawn new tasks
+	ThreadHiveTask gatherTask = ANKI_THREAD_HIVE_TASK({ self->gather(hive); },
+		alloc.newInstance<GatherVisiblesFromOctreeTask>(frcCtx),
+		prepareRasterizerSem,
+		nullptr);
 	hive.submitTasks(&gatherTask, 1);
 	hive.submitTasks(&gatherTask, 1);
 
 
 	// Combind results task
 	// Combind results task
-	ThreadHiveTask combineTask;
-	combineTask.m_callback = CombineResultsTask::callback;
-	combineTask.m_argument = alloc.newInstance<CombineResultsTask>(frcCtx);
 	ANKI_ASSERT(frcCtx->m_visTestsSignalSem);
 	ANKI_ASSERT(frcCtx->m_visTestsSignalSem);
-	combineTask.m_waitSemaphore = frcCtx->m_visTestsSignalSem;
-
+	ThreadHiveTask combineTask = ANKI_THREAD_HIVE_TASK(
+		{ self->combine(); }, alloc.newInstance<CombineResultsTask>(frcCtx), frcCtx->m_visTestsSignalSem, nullptr);
 	hive.submitTasks(&combineTask, 1);
 	hive.submitTasks(&combineTask, 1);
 }
 }
 
 
@@ -131,7 +126,7 @@ void FillRasterizerWithCoverageTask::fill()
 	m_frcCtx->m_r->fillDepthBuffer(depthBuff);
 	m_frcCtx->m_r->fillDepthBuffer(depthBuff);
 }
 }
 
 
-void GatherVisiblesFromOctreeTask::gather(ThreadHive& hive, ThreadHiveSemaphore& sem)
+void GatherVisiblesFromOctreeTask::gather(ThreadHive& hive)
 {
 {
 	ANKI_TRACE_SCOPED_EVENT(SCENE_VIS_OCTREE);
 	ANKI_TRACE_SCOPED_EVENT(SCENE_VIS_OCTREE);
 
 
@@ -158,22 +153,19 @@ void GatherVisiblesFromOctreeTask::gather(ThreadHive& hive, ThreadHiveSemaphore&
 
 
 			if(m_spatialCount == m_spatials.getSize())
 			if(m_spatialCount == m_spatials.getSize())
 			{
 			{
-				flush(hive, sem);
+				flush(hive);
 			}
 			}
 		});
 		});
 
 
 	// Flush the remaining
 	// Flush the remaining
-	flush(hive, sem);
+	flush(hive);
 
 
 	// Fire an additional dummy task to decrease the semaphore to zero
 	// Fire an additional dummy task to decrease the semaphore to zero
-	ThreadHiveTask task;
-	task.m_callback = dummyCallback;
-	task.m_argument = nullptr;
-	task.m_signalSemaphore = m_frcCtx->m_visTestsSignalSem;
+	ThreadHiveTask task = ANKI_THREAD_HIVE_TASK({}, this, nullptr, m_frcCtx->m_visTestsSignalSem);
 	hive.submitTasks(&task, 1);
 	hive.submitTasks(&task, 1);
 }
 }
 
 
-void GatherVisiblesFromOctreeTask::flush(ThreadHive& hive, ThreadHiveSemaphore& sem)
+void GatherVisiblesFromOctreeTask::flush(ThreadHive& hive)
 {
 {
 	if(m_spatialCount)
 	if(m_spatialCount)
 	{
 	{
@@ -187,10 +179,8 @@ void GatherVisiblesFromOctreeTask::flush(ThreadHive& hive, ThreadHiveSemaphore&
 		m_frcCtx->m_visTestsSignalSem->increaseSemaphore(1);
 		m_frcCtx->m_visTestsSignalSem->increaseSemaphore(1);
 
 
 		// Submit task
 		// Submit task
-		ThreadHiveTask task;
-		task.m_callback = VisibilityTestTask::callback;
-		task.m_argument = vis;
-		task.m_signalSemaphore = m_frcCtx->m_visTestsSignalSem;
+		ThreadHiveTask task =
+			ANKI_THREAD_HIVE_TASK({ self->test(hive, threadId); }, vis, nullptr, m_frcCtx->m_visTestsSignalSem);
 		hive.submitTasks(&task, 1);
 		hive.submitTasks(&task, 1);
 
 
 		// Clear count
 		// Clear count

+ 4 - 37
src/anki/scene/VisibilityInternal.h

@@ -167,14 +167,6 @@ public:
 		ANKI_ASSERT(m_frcCtx);
 		ANKI_ASSERT(m_frcCtx);
 	}
 	}
 
 
-	/// Thread hive task.
-	static void callback(void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* sem)
-	{
-		FillRasterizerWithCoverageTask& self = *static_cast<FillRasterizerWithCoverageTask*>(ud);
-		self.fill();
-	}
-
-private:
 	void fill();
 	void fill();
 };
 };
 static_assert(
 static_assert(
@@ -192,25 +184,14 @@ public:
 		ANKI_ASSERT(m_frcCtx);
 		ANKI_ASSERT(m_frcCtx);
 	}
 	}
 
 
-	/// Thread hive task.
-	static void callback(void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* sem)
-	{
-		GatherVisiblesFromOctreeTask& self = *static_cast<GatherVisiblesFromOctreeTask*>(ud);
-		self.gather(hive, *sem);
-	}
+	void gather(ThreadHive& hive);
 
 
 private:
 private:
 	Array<SpatialComponent*, MAX_SPATIALS_PER_VIS_TEST> m_spatials;
 	Array<SpatialComponent*, MAX_SPATIALS_PER_VIS_TEST> m_spatials;
 	U32 m_spatialCount = 0;
 	U32 m_spatialCount = 0;
 
 
-	void gather(ThreadHive& hive, ThreadHiveSemaphore& sem);
-
 	/// Submit tasks to test the m_spatials.
 	/// Submit tasks to test the m_spatials.
-	void flush(ThreadHive& hive, ThreadHiveSemaphore& sem);
-
-	static void dummyCallback(void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* sem)
-	{
-	}
+	void flush(ThreadHive& hive);
 };
 };
 static_assert(
 static_assert(
 	std::is_trivially_destructible<GatherVisiblesFromOctreeTask>::value == true, "Should be trivially destructible");
 	std::is_trivially_destructible<GatherVisiblesFromOctreeTask>::value == true, "Should be trivially destructible");
@@ -230,16 +211,9 @@ public:
 		ANKI_ASSERT(m_frcCtx);
 		ANKI_ASSERT(m_frcCtx);
 	}
 	}
 
 
-	/// Thread hive task.
-	static void callback(void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* sem)
-	{
-		VisibilityTestTask& self = *static_cast<VisibilityTestTask*>(ud);
-		self.test(hive, threadId);
-	}
-
-private:
 	void test(ThreadHive& hive, U32 taskId);
 	void test(ThreadHive& hive, U32 taskId);
 
 
+private:
 	ANKI_USE_RESULT Bool testAgainstRasterizer(const CollisionShape& cs, const Aabb& aabb) const
 	ANKI_USE_RESULT Bool testAgainstRasterizer(const CollisionShape& cs, const Aabb& aabb) const
 	{
 	{
 		return (m_frcCtx->m_r) ? m_frcCtx->m_r->visibilityTest(cs, aabb) : true;
 		return (m_frcCtx->m_r) ? m_frcCtx->m_r->visibilityTest(cs, aabb) : true;
@@ -259,16 +233,9 @@ public:
 		ANKI_ASSERT(m_frcCtx);
 		ANKI_ASSERT(m_frcCtx);
 	}
 	}
 
 
-	/// Thread hive task.
-	static void callback(void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* sem)
-	{
-		CombineResultsTask& self = *static_cast<CombineResultsTask*>(ud);
-		self.combine();
-	}
-
-private:
 	void combine();
 	void combine();
 
 
+private:
 	template<typename T>
 	template<typename T>
 	static void combineQueueElements(SceneFrameAllocator<U8>& alloc,
 	static void combineQueueElements(SceneFrameAllocator<U8>& alloc,
 		WeakArray<TRenderQueueElementStorage<T>> subStorages,
 		WeakArray<TRenderQueueElementStorage<T>> subStorages,

+ 1 - 0
src/anki/util/ThreadHive.h

@@ -67,6 +67,7 @@ public:
 	{ \
 	{ \
 		[](void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* signalSemaphore) { \
 		[](void* ud, U32 threadId, ThreadHive& hive, ThreadHiveSemaphore* signalSemaphore) { \
 			auto self = static_cast<decltype(argument_)>(ud); \
 			auto self = static_cast<decltype(argument_)>(ud); \
+			(void)self; \
 			callback_ \
 			callback_ \
 		}, \
 		}, \
 			argument_, waitSemaphore_, signalSemaphore_ \
 			argument_, waitSemaphore_, signalSemaphore_ \