Browse Source

Adding some counters

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
24a7789beb

+ 1 - 0
include/anki/core/Counters.h

@@ -35,6 +35,7 @@ enum class Counter
 	GL_VERTICES_COUNT,
 	GL_QUEUES_SIZE,
 	GL_CLIENT_BUFFERS_SIZE,
+	GR_UNIFORM_SIZE,
 
 	COUNT
 };

+ 1 - 0
include/anki/gr/gl/GlState.h

@@ -78,6 +78,7 @@ public:
 	DArray<GLuint> m_globalUbos; ///< Multiple cause of the spec's UBO max size.
 	DArray<U8*> m_globalUboAddresses;
 	Atomic<U32> m_globalUboCurrentOffset = {0};
+	Atomic<U32> m_globalUboBytesUsaged = {0}; ///< Per frame
 	/// @}
 
 	GlState(GrManager* manager)

+ 1 - 1
include/anki/gr/gl/RenderingThread.h

@@ -99,7 +99,7 @@ private:
 	void prepare();
 	void finish();
 
-	void swapBuffersInternal();
+	void swapBuffersInternal(GlState& state);
 };
 /// @}
 

+ 2 - 1
src/core/Counters.cpp

@@ -47,7 +47,8 @@ static const Array<CounterInfo, (U)Counter::COUNT> cinfo = {{
 	{"GL_DRAWCALLS_COUNT", CF_PER_FRAME | CF_PER_RUN | CF_U64},
 	{"GL_VERTICES_COUNT", CF_PER_FRAME | CF_PER_RUN | CF_U64},
 	{"GL_QUEUES_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64},
-	{"GL_CLIENT_BUFFERS_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64}
+	{"GL_CLIENT_BUFFERS_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64},
+	{"GR_UNIFORM_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64}
 }};
 
 #define MAX_NAME "25"

+ 1 - 0
src/gr/gl/CommandBuffer.cpp

@@ -343,6 +343,7 @@ void CommandBuffer::updateDynamicUniformsInternal(U32 originalSize, void*& data)
 
 	// Get offset in the contiguous buffer
 	U size = getAlignedRoundUp(state.m_uniBuffOffsetAlignment, originalSize);
+	state.m_globalUboBytesUsaged.fetchAdd(size);
 	U offset = state.m_globalUboCurrentOffset.fetchAdd(size);
 	offset = offset % uboSize;
 

+ 10 - 3
src/gr/gl/RenderingThread.cpp

@@ -45,9 +45,9 @@ public:
 		: m_renderingThread(renderingThread)
 	{}
 
-	ANKI_USE_RESULT Error operator()(GlState&)
+	ANKI_USE_RESULT Error operator()(GlState& state)
 	{
-		m_renderingThread->swapBuffersInternal();
+		m_renderingThread->swapBuffersInternal(state);
 		return ErrorCode::NONE;
 	}
 };
@@ -284,7 +284,7 @@ void RenderingThread::syncClientServer()
 }
 
 //==============================================================================
-void RenderingThread::swapBuffersInternal()
+void RenderingThread::swapBuffersInternal(GlState& state)
 {
 	// Do the swap buffers
 	m_interface->swapBuffersCommand();
@@ -296,6 +296,13 @@ void RenderingThread::swapBuffersInternal()
 	}
 
 	m_frameCondVar.notifyOne();
+
+	auto bytesUsed = state.m_globalUboBytesUsaged.exchange(0);
+	ANKI_COUNTER_INC(GR_UNIFORM_SIZE, U64(bytesUsed));
+	if(bytesUsed >= state.m_globalUboSize / MAX_FRAMES_IN_FLIGHT)
+	{
+		ANKI_LOGW("Using too much uniform memory. Increase the limit");
+	}
 }
 
 //==============================================================================

+ 1 - 0
src/scene/ParticleEmitter.cpp

@@ -217,6 +217,7 @@ public:
 		Transform& trf) const override
 	{
 		hasTransform = true;
+		// The particles are already in world position
 		trf = Transform::getIdentity();
 	}
 };

+ 9 - 0
tests/resource/MaterialLoader.cpp

@@ -128,6 +128,15 @@ ANKI_TEST(Resource, MaterialLoader)
 		});
 		(void)err;
 	}
+
+	// Check block size
+	/*{
+		RenderingKey key(Pass::MS_FS, 1, false, 4);
+		loader.mutate(key);
+
+		ANKI_TEST_EXPECT_EQ(loader.getUniformBlockSize(),
+			16 * 4 * sizeof(F32) + 4 * sizeof(F32) + 3 * sizeof(F32));
+	}*/
 }
 
 } // end namespace anki