[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20550] branches/bb_dev: BGE: rasterizer performance improvements: eliminate matrix calculation when activating the mesh slots in GLSL.

Benoit Bolsee benoit.bolsee at online.be
Mon Jun 1 13:07:59 CEST 2009


Revision: 20550
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20550
Author:   ben2610
Date:     2009-06-01 13:07:59 +0200 (Mon, 01 Jun 2009)

Log Message:
-----------
BGE: rasterizer performance improvements: eliminate matrix calculation when activating the mesh slots in GLSL. Avoid unnecessary matrix format conversion. Avoid lamp dynamic vector update on each mesh slot. Plus several minor optimizations. More details when merging with trunks.

Modified Paths:
--------------
    branches/bb_dev/intern/moto/include/MT_CmMatrix4x4.h
    branches/bb_dev/intern/moto/include/MT_Matrix3x3.inl
    branches/bb_dev/intern/moto/intern/MT_CmMatrix4x4.cpp
    branches/bb_dev/projectfiles_vc9/gameengine/ketsji/KX_ketsji.vcproj
    branches/bb_dev/projectfiles_vc9/gameengine/rasterizer/RAS_rasterizer.vcproj
    branches/bb_dev/source/blender/gpu/GPU_material.h
    branches/bb_dev/source/blender/gpu/intern/gpu_draw.c
    branches/bb_dev/source/blender/gpu/intern/gpu_extensions.c
    branches/bb_dev/source/blender/gpu/intern/gpu_material.c
    branches/bb_dev/source/blender/src/drawview.c
    branches/bb_dev/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    branches/bb_dev/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
    branches/bb_dev/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
    branches/bb_dev/source/gameengine/Converter/BL_SkinMeshObject.cpp
    branches/bb_dev/source/gameengine/Converter/BL_SkinMeshObject.h
    branches/bb_dev/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
    branches/bb_dev/source/gameengine/GamePlayer/common/GPC_RenderTools.h
    branches/bb_dev/source/gameengine/Ketsji/BL_BlenderShader.cpp
    branches/bb_dev/source/gameengine/Ketsji/BL_Shader.cpp
    branches/bb_dev/source/gameengine/Ketsji/BL_Shader.h
    branches/bb_dev/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_GameObject.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_GameObject.h
    branches/bb_dev/source/gameengine/Ketsji/KX_Light.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_Light.h
    branches/bb_dev/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_Scene.cpp
    branches/bb_dev/source/gameengine/Ketsji/KX_Scene.h
    branches/bb_dev/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    branches/bb_dev/source/gameengine/Rasterizer/RAS_BucketManager.cpp
    branches/bb_dev/source/gameengine/Rasterizer/RAS_IRasterizer.h
    branches/bb_dev/source/gameengine/Rasterizer/RAS_IRenderTools.h
    branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
    branches/bb_dev/source/gameengine/Rasterizer/RAS_MaterialBucket.h
    branches/bb_dev/source/gameengine/Rasterizer/RAS_MeshObject.cpp
    branches/bb_dev/source/gameengine/Rasterizer/RAS_MeshObject.h
    branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
    branches/bb_dev/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h

Modified: branches/bb_dev/intern/moto/include/MT_CmMatrix4x4.h
===================================================================
--- branches/bb_dev/intern/moto/include/MT_CmMatrix4x4.h	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/intern/moto/include/MT_CmMatrix4x4.h	2009-06-01 11:07:59 UTC (rev 20550)
@@ -35,18 +35,18 @@
  * the matrix , the same as what you get if you transform {1,0,0,0}.
  * This makes it easy to transform stuff to OpenGl. Please note that the
  * the other MoTo matrices are row major.
- *
- * This class should be deprecated in favour of the more consistent
- * MT_Matrix4x4. Please do not start using this class.
  */
 
 #include "MT_Scalar.h"
+#include "MT_Matrix4x4.h"
 
 class MT_Point3;
 class MT_Vector3;
 
+
 class MT_CmMatrix4x4
 {
+	typedef float Vec4[4];
 
 public :
 
@@ -72,6 +72,12 @@
 		const MT_Vector3 up
 	);
 
+	const MT_CmMatrix4x4& operator=(
+		const MT_Matrix4x4& other
+	);
+
+	inline Vec4* ToMat4() const { return (Vec4*)m_V; }
+
 		void
 	Identity(
 	);
@@ -81,19 +87,14 @@
 		const MT_CmMatrix4x4 & other
 	);
 
-		double*
-	getPointer(
-	);
+	float* getPointer() { return &m_V[0][0];}
 
-	const
-		double*
-	getPointer(
-	) const;
+	const float* getPointer() const { return &m_V[0][0]; }
 
 		void
 	setElem(
 		int pos,
-		double newvalue
+		float newvalue
 	);
 
 		MT_Vector3
@@ -117,10 +118,18 @@
 		const MT_Vector3 & v
 	);
 
-		double&
+		void
+	SetScale(
+		const MT_Vector3 & v
+	);
+
+		float&
 	operator (
 	) (int row,int col)	{ return m_V[col][row]; }
 
+
+	friend MT_Vector4 operator*(const MT_CmMatrix4x4& m, const MT_Vector4& v);
+
 	static
 	    MT_CmMatrix4x4
     Perspective(
@@ -135,10 +144,12 @@
 protected:
 	union
 	{
-		double m_V[4][4];
-		double m_Vflat[16];
+		float m_V[4][4];
+		float m_Vflat[16];
 	};
 };
 
+MT_Vector4 operator*(const MT_CmMatrix4x4& m, const MT_Vector4& v);
+
 #endif //MT_CmMatrix4x4
 

Modified: branches/bb_dev/intern/moto/include/MT_Matrix3x3.inl
===================================================================
--- branches/bb_dev/intern/moto/include/MT_Matrix3x3.inl	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/intern/moto/include/MT_Matrix3x3.inl	2009-06-01 11:07:59 UTC (rev 20550)
@@ -66,7 +66,10 @@
 }
 
 GEN_INLINE void MT_Matrix3x3::transpose() {
-	*this = transposed();
+	MT_Scalar tmp;
+	tmp = m_el[0][1]; m_el[0][1] = m_el[1][0]; m_el[1][0] = tmp;
+	tmp = m_el[0][2]; m_el[0][2] = m_el[2][0]; m_el[2][0] = tmp;
+	tmp = m_el[1][2]; m_el[1][2] = m_el[2][1]; m_el[2][1] = tmp;
 }
 
 GEN_INLINE MT_Matrix3x3 MT_Matrix3x3::adjoint() const {

Modified: branches/bb_dev/intern/moto/intern/MT_CmMatrix4x4.cpp
===================================================================
--- branches/bb_dev/intern/moto/intern/MT_CmMatrix4x4.cpp	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/intern/moto/intern/MT_CmMatrix4x4.cpp	2009-06-01 11:07:59 UTC (rev 20550)
@@ -127,7 +127,25 @@
 	return MT_Point3(m_V[3][0], m_V[3][1], m_V[3][2]);
 }
 
+void MT_CmMatrix4x4::SetPos(const MT_Vector3 & v)
+{
+	m_V[3][0] = v[0];
+	m_V[3][1] = v[1];
+	m_V[3][2] = v[2];
+}
 
+void MT_CmMatrix4x4::SetScale(const MT_Vector3 & v)
+{
+	m_V[0][0] *= v[0];
+	m_V[0][1] *= v[0];
+	m_V[0][2] *= v[0];
+	m_V[1][0] *= v[1];
+	m_V[1][1] *= v[1];
+	m_V[1][2] *= v[1];
+	m_V[2][0] *= v[2];
+	m_V[2][1] *= v[2];
+	m_V[2][2] *= v[2];
+}
 
 void MT_CmMatrix4x4::Identity()
 {
@@ -138,31 +156,30 @@
 	} 
 }
 
-
-
-void MT_CmMatrix4x4::SetMatrix(const MT_CmMatrix4x4& other)
+const MT_CmMatrix4x4& MT_CmMatrix4x4::operator=(const MT_Matrix4x4& other)
 {
-	for (int i=0; i<16; i++)
-		m_Vflat[i] = other.m_Vflat[i];
+	other.getValue(m_Vflat);
+	return *this;
 }
 
-
-
-double*	MT_CmMatrix4x4::getPointer()
+MT_Vector4 operator*(const MT_CmMatrix4x4& m, const MT_Vector4& v)
 {
-	return &m_V[0][0];
+	return MT_Vector4(
+		m.m_V[0][0]*v[0]+m.m_V[1][0]*v[1]+m.m_V[2][0]*v[2]+m.m_V[3][0]*v[3],
+		m.m_V[0][1]*v[0]+m.m_V[1][1]*v[1]+m.m_V[2][1]*v[2]+m.m_V[3][1]*v[3],
+		m.m_V[0][2]*v[0]+m.m_V[1][2]*v[1]+m.m_V[2][2]*v[2]+m.m_V[3][2]*v[3],
+		m.m_V[0][3]*v[0]+m.m_V[1][3]*v[1]+m.m_V[2][3]*v[2]+m.m_V[3][3]*v[3]);
 }
 
 
-
-const double* MT_CmMatrix4x4::getPointer() const
+void MT_CmMatrix4x4::SetMatrix(const MT_CmMatrix4x4& other)
 {
-	return &m_V[0][0];
-}	
+	for (int i=0; i<16; i++)
+		m_Vflat[i] = other.m_Vflat[i];
+}
 
 
-
-void MT_CmMatrix4x4::setElem(int pos,double newvalue)
+void MT_CmMatrix4x4::setElem(int pos,float newvalue)
 {
 	m_Vflat[pos] = newvalue;
 }	

Modified: branches/bb_dev/projectfiles_vc9/gameengine/ketsji/KX_ketsji.vcproj
===================================================================
--- branches/bb_dev/projectfiles_vc9/gameengine/ketsji/KX_ketsji.vcproj	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/projectfiles_vc9/gameengine/ketsji/KX_ketsji.vcproj	2009-06-01 11:07:59 UTC (rev 20550)
@@ -542,6 +542,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Ketsji\KX_MatrixFactory.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Ketsji\KX_MeshProxy.cpp"
 				>
 			</File>
@@ -851,6 +855,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Ketsji\KX_MatrixFactory.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Ketsji\KX_MeshProxy.h"
 				>
 			</File>

Modified: branches/bb_dev/projectfiles_vc9/gameengine/rasterizer/RAS_rasterizer.vcproj
===================================================================
--- branches/bb_dev/projectfiles_vc9/gameengine/rasterizer/RAS_rasterizer.vcproj	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/projectfiles_vc9/gameengine/rasterizer/RAS_rasterizer.vcproj	2009-06-01 11:07:59 UTC (rev 20550)
@@ -543,6 +543,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\source\gameengine\Rasterizer\RAS_IMatrixFactory.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\source\gameengine\Rasterizer\RAS_IPolygonMaterial.h"
 				>
 			</File>

Modified: branches/bb_dev/source/blender/gpu/GPU_material.h
===================================================================
--- branches/bb_dev/source/blender/gpu/GPU_material.h	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/source/blender/gpu/GPU_material.h	2009-06-01 11:07:59 UTC (rev 20550)
@@ -125,9 +125,10 @@
 void GPU_materials_free();
 
 void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time);
-void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4]);
+void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float obinv[][4], float viewmat[][4], float viewinv[][4], float obcol[4]);
 void GPU_material_unbind(GPUMaterial *material);
 int GPU_material_bound(GPUMaterial *material);
+int GPU_material_needs_object_inverse(GPUMaterial *material);
 
 void GPU_material_vertex_attributes(GPUMaterial *material,
 	struct GPUVertexAttribs *attrib);
@@ -161,6 +162,7 @@
 void GPU_lamp_update(GPULamp *lamp, int lay, float obmat[][4]);
 void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy);
 int GPU_lamp_shadow_layer(GPULamp *lamp);
+void GPU_lamp_update_dyn(GPULamp *lamp, float viewmat[][4], float viewinv[][4]);
 
 #ifdef __cplusplus
 }

Modified: branches/bb_dev/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/bb_dev/source/blender/gpu/intern/gpu_draw.c	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/source/blender/gpu/intern/gpu_draw.c	2009-06-01 11:07:59 UTC (rev 20550)
@@ -947,11 +947,13 @@
 		if(gattribs && GMS.gmatbuf[nr]) {
 			/* bind glsl material and get attributes */
 			Material *mat = GMS.gmatbuf[nr];
-
+			float invmat[4][4];
 			gpumat = GPU_material_from_blender(GMS.gscene, mat);
 			GPU_material_vertex_attributes(gpumat, gattribs);
 			GPU_material_bind(gpumat, GMS.gob->lay, G.vd->lay, 1.0);
-			GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, G.vd->viewmat, G.vd->viewinv, GMS.gob->col);
+			if (GPU_material_needs_object_inverse(gpumat))
+				Mat4Invert(invmat, GMS.gob->obmat);
+			GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, invmat, G.vd->viewmat, G.vd->viewinv, GMS.gob->col);
 			GMS.gboundmat= mat;
 
 			if(GMS.alphapass) glDepthMask(1);

Modified: branches/bb_dev/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/bb_dev/source/blender/gpu/intern/gpu_extensions.c	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/source/blender/gpu/intern/gpu_extensions.c	2009-06-01 11:07:59 UTC (rev 20550)
@@ -832,12 +832,26 @@
 
 	GPU_print_error("Pre Uniform Vector");
 
-	if (length == 1) glUniform1fvARB(location, arraysize, value);
-	else if (length == 2) glUniform2fvARB(location, arraysize, value);
-	else if (length == 3) glUniform3fvARB(location, arraysize, value);
-	else if (length == 4) glUniform4fvARB(location, arraysize, value);
-	else if (length == 9) glUniformMatrix3fvARB(location, arraysize, 0, value);
-	else if (length == 16) glUniformMatrix4fvARB(location, arraysize, 0, value);
+	switch (length) {
+	case 1: 
+		glUniform1fvARB(location, arraysize, value);
+		break;
+	case 2:
+		glUniform2fvARB(location, arraysize, value);
+		break;
+	case 3:
+		glUniform3fvARB(location, arraysize, value);
+		break;
+	case 4:
+		glUniform4fvARB(location, arraysize, value);
+		break;
+	case 9:
+		glUniformMatrix3fvARB(location, arraysize, 0, value);
+		break;
+	case 16:
+		glUniformMatrix4fvARB(location, arraysize, 0, value);
+		break;
+	}
 
 	GPU_print_error("Post Uniform Vector");
 }

Modified: branches/bb_dev/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/bb_dev/source/blender/gpu/intern/gpu_material.c	2009-06-01 10:59:17 UTC (rev 20549)
+++ branches/bb_dev/source/blender/gpu/intern/gpu_material.c	2009-06-01 11:07:59 UTC (rev 20550)
@@ -145,6 +145,11 @@
 	return material;
 }
 
+int GPU_material_needs_object_inverse(GPUMaterial *material)
+{
+	return (material->builtins & GPU_INVERSE_OBJECT_MATRIX);
+}
+
 static void gpu_material_set_attrib_id(GPUMaterial *material)
 {
 	GPUVertexAttribs *attribs;
@@ -271,13 +276,13 @@
 	}
 }
 
-void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4])
+void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float invmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4])
 {
 	if(material->pass) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list