Pārlūkot izejas kodu

Small opt in visibility's rasterization tasks

Panagiotis Christopoulos Charitos 9 gadi atpakaļ
vecāks
revīzija
0a52a511d2

+ 5 - 10
include/anki/scene/VisibilityInternal.h

@@ -63,18 +63,13 @@ public:
 class GatherVisibleTrianglesTask
 {
 public:
-	class TriangleBatch : public IntrusiveListEnabled<TriangleBatch>
-	{
-	public:
-		const Vec3* m_begin = nullptr;
-		U32 m_count = 0;
-		U32 m_stride = 0;
-	};
-
 	WeakPtr<VisibilityContext> m_visCtx;
 	WeakPtr<FrustumComponent> m_frc;
-	IntrusiveList<TriangleBatch> m_batches;
-	U32 m_batchCount;
+
+	static const U TRIANGLES_INITIAL_SIZE = 10 * 3;
+	DynamicArray<Vec3> m_verts;
+	U32 m_vertCount;
+
 	SoftwareRasterizer m_r;
 
 	/// Thread hive task.

+ 2 - 2
shaders/MsCommonFrag.glsl

@@ -219,8 +219,8 @@ vec2 computeTextureCoordParalax(in sampler2D heightMap,
 {
 #if PASS == COLOR && LOD == 0
 	const uint MAX_SAMPLES = 25;
-	const uint MIN_SAMPLES = 3;
-	const float MAX_EFFECTIVE_DISTANCE = 10.0;
+	const uint MIN_SAMPLES = 1;
+	const float MAX_EFFECTIVE_DISTANCE = 8.0;
 
 	// Get that because we are sampling inside a loop
 	vec2 dPdx = dFdx(uv);

+ 27 - 14
src/scene/Visibility.cpp

@@ -69,7 +69,7 @@ void VisibilityContext::submitNewWork(FrustumComponent& frc, ThreadHive& hive)
 			alloc.newInstance<GatherVisibleTrianglesTask>();
 		gather->m_visCtx = this;
 		gather->m_frc = &frc;
-		gather->m_batchCount = 0;
+		gather->m_vertCount = 0;
 
 		r = &gather->m_r;
 
@@ -179,16 +179,29 @@ void GatherVisibleTrianglesTask::gather()
 	ANKI_TRACE_START_EVENT(SCENE_VISIBILITY_GATHER_TRIANGLES);
 
 	auto alloc = m_visCtx->m_scene->getFrameAllocator();
+	m_verts.create(alloc, TRIANGLES_INITIAL_SIZE);
 	SceneComponentLists& lists = m_visCtx->m_scene->getSceneComponentLists();
 
-	ANKI_ASSERT(m_batchCount == 0);
+	ANKI_ASSERT(m_vertCount == 0);
 	lists.iterateComponents<OccluderComponent>([&](OccluderComponent& comp) {
 		if(m_frc->insideFrustum(comp.getBoundingVolume()))
 		{
-			TriangleBatch* batch = alloc.newInstance<TriangleBatch>();
-			comp.getVertices(batch->m_begin, batch->m_count, batch->m_stride);
-			m_batches.pushBack(batch);
-			++m_batchCount;
+			U32 count, stride;
+			const Vec3* it;
+			comp.getVertices(it, count, stride);
+			while(count--)
+			{
+				// Grow the array
+				if(m_vertCount + 1 > m_verts.getSize())
+				{
+					m_verts.resize(alloc, m_verts.getSize() * 2);
+				}
+
+				m_verts[m_vertCount++] = *it;
+
+				it = reinterpret_cast<const Vec3*>(
+					reinterpret_cast<const U8*>(it) + stride);
+			}
 		}
 	});
 
@@ -207,17 +220,17 @@ void RasterizeTrianglesTask::rasterize()
 {
 	ANKI_TRACE_START_EVENT(SCENE_VISIBILITY_RASTERIZE);
 
-	PtrSize start, endi;
+	PtrSize start, end;
 	ThreadPoolTask::choseStartEnd(
-		m_taskIdx, m_taskCount, m_gatherTask->m_batchCount, start, endi);
+		m_taskIdx, m_taskCount, m_gatherTask->m_vertCount / 3, start, end);
 
-	auto it = m_gatherTask->m_batches.getBegin() + start;
-	auto end = m_gatherTask->m_batches.getBegin() + endi;
-	while(it != end)
+	if(start != end)
 	{
-		const F32* first = &it->m_begin[0][0];
-		m_gatherTask->m_r.draw(first, it->m_count, it->m_stride);
-		++it;
+		const Vec3* first = &m_gatherTask->m_verts[start * 3];
+		U count = (end - start) * 3;
+		ANKI_ASSERT(count <= m_gatherTask->m_vertCount);
+
+		m_gatherTask->m_r.draw(&first[0][0], count, sizeof(Vec3));
 	}
 
 	ANKI_TRACE_STOP_EVENT(SCENE_VISIBILITY_RASTERIZE);

+ 8 - 8
tests/util/HashMap.cpp

@@ -9,7 +9,7 @@
 #include "anki/util/DynamicArray.h"
 #include "anki/util/HighRezTimer.h"
 #include <unordered_map>
-#include <algorithm> 
+#include <algorithm>
 
 using namespace anki;
 
@@ -107,10 +107,10 @@ ANKI_TEST(Util, HashMap)
 
 	// Fuzzy test
 	{
-		const U MAX = 1000;	
+		const U MAX = 1000;
 		HashMap<int, int, Hasher, Compare> akMap;
 		std::vector<int> numbers;
-		
+
 		// Inserd random
 		for(U i = 0; i < MAX; ++i)
 		{
@@ -118,7 +118,7 @@ ANKI_TEST(Util, HashMap)
 			while(1)
 			{
 				num = rand();
-				if(std::find(numbers.begin(), numbers.end(), int(num)) 
+				if(std::find(numbers.begin(), numbers.end(), int(num))
 					== numbers.end())
 				{
 					// Not found
@@ -134,19 +134,19 @@ ANKI_TEST(Util, HashMap)
 				}
 			}
 		}
-		
+
 		// Remove randomly
 		U count = MAX;
 		while(count--)
 		{
 			U idx = rand() % (count + 1);
-			int num	= numbers[idx];
+			int num = numbers[idx];
 			numbers.erase(numbers.begin() + idx);
-			
+
 			auto it = akMap.find(num);
 			akMap.erase(alloc, it);
 		}
-		
+
 		akMap.destroy(alloc);
 	}