Browse Source

Minor optimizations

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
7f0e47f23b

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

@@ -21,6 +21,8 @@ enum class Counter
 	GL_SERVER_WAIT_TIME,
 	GL_DRAWCALLS_COUNT,
 	GL_VERTICES_COUNT,
+	GL_JOB_CHAINS_SIZE,
+	GL_CLIENT_BUFFERS_SIZE,
 
 	COUNT
 };

+ 5 - 0
include/anki/gl/GlJobChainHandle.h

@@ -8,6 +8,7 @@ namespace anki {
 
 // Forward
 class GlManager;
+class GlTextureHandle;
 
 /// @addtogroup opengl_other
 /// @{
@@ -123,6 +124,10 @@ public:
 
 	/// Enable/disable polygon offset
 	void enablePolygonOffset(Bool enable);
+
+	/// Bind many textures
+	void bindTextures(U32 first, 
+		const std::initializer_list<GlTextureHandle>& textures);
 	/// @}
 
 	/// @privatesection

+ 0 - 13
include/anki/renderer/Is.h

@@ -33,11 +33,6 @@ class Is: private RenderingPass
 public:
 	/// @privatesection
 	/// @{
-	const GlTextureHandle& _getRt() const
-	{
-		return m_rt;
-	}
-
 	GlTextureHandle& _getRt()
 	{
 		return m_rt;
@@ -54,14 +49,6 @@ private:
 		TILES_BLOCK_BINDING = 4
 	};
 
-	enum
-	{
-		MS_RT0_TEX_UNIT = 0,
-		MS_RT1_TEX_UNIT = 1,
-		MS_DEPTH_RT_TEX_UNIT = 2,
-		SM_ARRAY_TEX_UNIT = 3
-	};
-
 	/// The IS render target
 	GlTextureHandle m_rt;
 

+ 2 - 0
src/core/Counters.cpp

@@ -40,6 +40,8 @@ static const Array<CounterInfo, (U)Counter::COUNT> cinfo = {{
 	{"GL_SERVER_WAIT_TIME", CF_PER_FRAME | CF_PER_RUN | CF_F64},
 	{"GL_DRAWCALLS_COUNT", CF_PER_RUN | CF_U64},
 	{"GL_VERTICES_COUNT", CF_PER_FRAME | CF_PER_RUN | CF_U64},
+	{"GL_JOB_CHAINS_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64},
+	{"GL_CLIENT_BUFFERS_SIZE", CF_PER_FRAME | CF_PER_RUN | CF_U64}
 }};
 
 #define MAX_NAME "24"

+ 4 - 0
src/gl/GlClientBufferHandle.cpp

@@ -2,6 +2,7 @@
 #include "anki/gl/GlClientBuffer.h"
 #include "anki/gl/GlJobChainHandle.h"
 #include "anki/gl/GlManager.h"
+#include "anki/core/Counters.h"
 
 namespace anki {
 
@@ -37,6 +38,8 @@ GlClientBufferHandle::GlClientBufferHandle(
 			Deleter(),
 			alloc, 
 			size);
+
+		ANKI_COUNTER_INC(GL_CLIENT_BUFFERS_SIZE, U64(size));
 	}
 }
 
@@ -57,3 +60,4 @@ PtrSize GlClientBufferHandle::getSize() const
 }
 
 } // end namespace anki
+

+ 4 - 0
src/gl/GlJobChain.cpp

@@ -3,6 +3,7 @@
 #include "anki/gl/GlManager.h"
 #include "anki/gl/GlError.h"
 #include "anki/core/Logger.h"
+#include "anki/core/Counters.h"
 #include <cstring>
 
 namespace anki {
@@ -99,6 +100,9 @@ GlJobChainInitHints GlJobChain::computeInitHints() const
 	GlJobChainInitHints out;
 	out.m_chunkSize = m_alloc.getMemoryPool().getAllocatedSize() + 16;
 
+	ANKI_COUNTER_INC(GL_JOB_CHAINS_SIZE, 
+		U64(m_alloc.getMemoryPool().getAllocatedSize()));
+
 	return out;
 }
 

+ 48 - 0
src/gl/GlJobChainHandle.cpp

@@ -2,6 +2,10 @@
 #include "anki/gl/GlManager.h"
 #include "anki/gl/GlSyncHandles.h"
 #include "anki/gl/GlFramebuffer.h"
+#include "anki/gl/GlTextureHandle.h"
+#include "anki/gl/GlTexture.h"
+#include "anki/util/Vector.h"
+#include <utility>
 
 namespace anki {
 
@@ -379,4 +383,48 @@ void GlJobChainHandle::enablePolygonOffset(Bool enable)
 	ANKI_STATE_JOB_ENABLE(GL_POLYGON_OFFSET_FILL, enable);
 }
 
+//==============================================================================
+void GlJobChainHandle::bindTextures(U32 first, 
+	const std::initializer_list<GlTextureHandle>& textures)
+{
+	using Vec = Vector<GlTextureHandle, GlJobChainAllocator<GlTextureHandle>>;
+		
+	class Job: public GlJob
+	{
+	public:
+		Vec m_texes;
+		U32 m_first;
+
+		Job(Vec& texes, U32 first)
+			: m_first(first)
+		{
+			m_texes = std::move(texes);
+		}
+
+		void operator()(GlJobChain* jobs)
+		{
+			Array<GLuint, 16> names;
+
+			U count = 0;
+			for(GlTextureHandle& t : m_texes)
+			{
+				names[count++] = t._get().getGlName();
+			}
+
+			ANKI_ASSERT(count > 0);
+			glBindTextures(m_first, count, &names[0]);
+		}
+	};
+
+	Vec texes(_getAllocator());
+	texes.reserve(textures.size());
+
+	for(const GlTextureHandle& t : textures)
+	{
+		texes.push_back(t);
+	}
+
+	_pushBackNewJob<Job>(texes, first);
+}
+
 } // end namespace anki

+ 1 - 2
src/renderer/Hdr.cpp

@@ -142,8 +142,7 @@ void Hdr::run(GlJobChainHandle& jobs)
 	{
 		if(i == 0)
 		{
-			m_vblurRt.bind(jobs, 1); // H pass input
-			m_hblurRt.bind(jobs, 0); // V pass input
+			jobs.bindTextures(0, {m_hblurRt, m_vblurRt});
 		}
 
 		// hpass

+ 6 - 4
src/renderer/Is.cpp

@@ -728,10 +728,12 @@ void Is::lightPass(GlJobChainHandle& jobs)
 
 	m_tilesBuff.bindShaderBuffer(jobs, TILES_BLOCK_BINDING); 
 
-	m_r->getMs()._getRt0().bind(jobs, MS_RT0_TEX_UNIT);
-	m_r->getMs()._getRt1().bind(jobs, MS_RT1_TEX_UNIT);
-	m_r->getMs()._getDepthRt().bind(jobs, MS_DEPTH_RT_TEX_UNIT);
-	m_sm.m_sm2DArrayTex.bind(jobs, SM_ARRAY_TEX_UNIT);
+	// The binding points should much the shader
+	jobs.bindTextures(0, {
+		m_r->getMs()._getRt0(), 
+		m_r->getMs()._getRt1(), 
+		m_r->getMs()._getDepthRt(),
+		m_sm.m_sm2DArrayTex});
 
 	//
 	// Draw

+ 3 - 2
src/renderer/Lf.cpp

@@ -152,8 +152,9 @@ void Lf::run(GlJobChainHandle& jobs)
 
 	m_pseudoPpline.bind(jobs);
 
-	m_r->getPps().getHdr()._getRt().bind(jobs, 0);
-	m_lensDirtTex->getGlTexture().bind(jobs, 1);
+	jobs.bindTextures(0, {
+		m_r->getPps().getHdr()._getRt(), 
+		m_lensDirtTex->getGlTexture()});
 
 	m_r->drawQuad(jobs);
 

+ 6 - 5
src/renderer/Ssao.cpp

@@ -238,9 +238,11 @@ void Ssao::run(GlJobChainHandle& jobs)
 	m_ssaoPpline.bind(jobs);
 
 	m_uniformsBuff.bindShaderBuffer(jobs, 0);
-	m_r->getMs()._getSmallDepthRt().bind(jobs, 0); // Depth
-	m_r->getMs()._getRt1().bind(jobs, 1); // Normals
-	m_noiseTex.bind(jobs, 2);
+
+	jobs.bindTextures(0, {
+		m_r->getMs()._getSmallDepthRt(),
+		m_r->getMs()._getRt1(),
+		m_noiseTex});
 
 	// Write common block
 	if(m_commonUboUpdateTimestamp 
@@ -271,8 +273,7 @@ void Ssao::run(GlJobChainHandle& jobs)
 	{
 		if(i == 0)
 		{
-			m_vblurRt.bind(jobs, 1); // H pass input
-			m_hblurRt.bind(jobs, 0); // V pass input
+			jobs.bindTextures(0, {m_hblurRt, m_vblurRt});
 		}
 
 		// hpass

+ 6 - 3
src/renderer/Sslr.cpp

@@ -83,10 +83,13 @@ void Sslr::run(GlJobChainHandle& jobs)
 	jobs.setViewport(0, 0, m_width, m_height);
 
 	m_reflectionPpline.bind(jobs);
-	m_r->getIs()._getRt().bind(jobs, 0);
-	m_r->getMs()._getSmallDepthRt().bind(jobs, 1);
+
+	jobs.bindTextures(0	, {
+		m_r->getIs()._getRt(), // 0 
+		m_r->getMs()._getSmallDepthRt(), // 1
+		m_r->getMs()._getRt1()}); // 2
+
 	m_depthMapSampler.bind(jobs, 1);
-	m_r->getMs()._getRt1().bind(jobs, 2);
 	m_r->getPps().getSsao().m_uniformsBuff.bindShaderBuffer(jobs, 0);
 
 	m_r->drawQuad(jobs);