Commits

davep committed 1c19045

SH-2038 Potential fix for a myriad of performance problems concering VBO usage.

Comments (0)

Files changed (8)

indra/llrender/llvertexbuffer.cpp

 			LLMemType mt_v(LLMemType::MTYPE_VERTEX_MAP_BUFFER_VERTICES);
 			setBuffer(0, type);
 			mVertexLocked = TRUE;
+			sMappedCount++;
 			stop_glerror();	
 
 			if(sDisableVBOMapping)
 					llerrs << "memory allocation for vertex data failed." << llendl ;
 				}
 			}
-			sMappedCount++;
 		}
 	}
 	else
 
 			setBuffer(0, TYPE_INDEX);
 			mIndexLocked = TRUE;
+			sMappedCount++;
 			stop_glerror();	
 
 			if(sDisableVBOMapping)
 				llerrs << "memory allocation for Index data failed. " << llendl ;
 			}
 		}
-
-		sMappedCount++;
 	}
 	else
 	{

indra/newview/featuretable.txt

-version 30
+version 31
 
 // NOTE: This is mostly identical to featuretable_mac.txt with a few differences
 // Should be combined into one table
 RenderShadowDetail			0	0
 
 //
-// No GL_ARB_map_buffer_range
+// GL_ARB_map_buffer_range exists
 //
-list NoMapBufferRange
+list MapBufferRange
 RenderVBOMappingDisable		1	0
 
 

indra/newview/featuretable_linux.txt

-version 25
+version 26
 
 // NOTE: This is mostly identical to featuretable_mac.txt with a few differences
 // Should be combined into one table
 RenderShadowDetail			0	0
 
 //
-// No GL_ARB_map_buffer_range
+// GL_ARB_map_buffer_range exists
 //
-list NoMapBufferRange
+list MapBufferRange
 RenderVBOMappingDisable		1	0
 
 

indra/newview/featuretable_mac.txt

-version 26
+version 27
 
 // NOTE: This is mostly identical to featuretable_mac.txt with a few differences
 // Should be combined into one table
 RenderTreeLODFactor				1	1.0
 RenderUseImpostors				1	1
 RenderVBOEnable					1	1
-RenderVBOMappingDisable		1	1
+RenderVBOMappingDisable		1	0
 RenderVolumeLODFactor			1	2.0
 UseStartScreen				1	1
 UseOcclusion					1	1
 RenderShadowDetail			0	0
 
 //
-// No GL_ARB_map_buffer_range
-//
-list NoMapBufferRange
-RenderVBOMappingDisable		1	0
-
-
-//
 // "Default" setups for safe, low, medium, high
 //
 list safe

indra/newview/featuretable_xp.txt

-version 30
+version 31
 
 // NOTE: This is mostly identical to featuretable_mac.txt with a few differences
 // Should be combined into one table
 RenderShadowDetail			0	0
 
 //
-// No GL_ARB_map_buffer_range
+// GL_ARB_map_buffer_range exists
 //
-list NoMapBufferRange
+list MapBufferRange
 RenderVBOMappingDisable		1	0
 
 

indra/newview/llface.cpp

 	S32 num_vertices = (S32)vf.mNumVertices;
 	S32 num_indices = (S32) vf.mNumIndices;
 	
+	bool map_range = gGLManager.mHasMapBufferRange;
+
 	if (mVertexBuffer.notNull())
 	{
 		if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices())
 	// INDICES
 	if (full_rebuild)
 	{
-		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount, true);
+		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount, map_range);
 
 		__m128i* dst = (__m128i*) indicesp.get();
 		__m128i* src = (__m128i*) vf.mIndices;
 			indicesp[i] = vf.mIndices[i]+index_offset;
 		}
 
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 	
 	LLMatrix4a mat_normal;
 				}
 			}
 
-			mVertexBuffer->setBuffer(0);
+			if (map_range)
+			{
+				mVertexBuffer->setBuffer(0);
+			}
 		}
 		else
 		{ //either bump mapped or in atlas, just do the whole expensive loop
-			mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex, mGeomCount, true);
+			mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex, mGeomCount, map_range);
 
 			std::vector<LLVector2> bump_tc;
 		
 				}
 			}
 
-			mVertexBuffer->setBuffer(0);
-
+			if (map_range)
+			{
+				mVertexBuffer->setBuffer(0);
+			}
 
 			if (do_bump)
 			{
-				mVertexBuffer->getTexCoord1Strider(tex_coords2, mGeomIndex, mGeomCount, true);
+				mVertexBuffer->getTexCoord1Strider(tex_coords2, mGeomIndex, mGeomCount, map_range);
 		
 				for (S32 i = 0; i < num_vertices; i++)
 				{
 					*tex_coords2++ = tc;
 				}
 
-				mVertexBuffer->setBuffer(0);
+				if (map_range)
+				{
+					mVertexBuffer->setBuffer(0);
+				}
 			}
 		}
 	}
 
 	if (rebuild_pos)
 	{
-		mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount, true);
+		mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount, map_range);
 		vertices = (LLVector4a*) vert.get();
 	
 		LLMatrix4a mat_vert;
 		}
 		while (index_dst < index_end);
 
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 		
 	if (rebuild_normal)
 	{
-		mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount, true);
+		mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount, map_range);
 		normals = (LLVector4a*) norm.get();
 	
 		for (S32 i = 0; i < num_vertices; i++)
 			normals[i] = normal;
 		}
 
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 		
 	if (rebuild_binormal)
 	{
-		mVertexBuffer->getBinormalStrider(binorm, mGeomIndex, mGeomCount, true);
+		mVertexBuffer->getBinormalStrider(binorm, mGeomIndex, mGeomCount, map_range);
 		binormals = (LLVector4a*) binorm.get();
 		
 		for (S32 i = 0; i < num_vertices; i++)
 			binormals[i] = binormal;
 		}
 
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 	
 	if (rebuild_weights && vf.mWeights)
 	{
-		mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount, true);
+		mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount, map_range);
 		weights = (LLVector4a*) wght.get();
 		LLVector4a::memcpyNonAliased16((F32*) weights, (F32*) vf.mWeights, num_vertices*4*sizeof(F32));
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 
 	if (rebuild_color)
 	{
-		mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount, true);
+		mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount, map_range);
 
 		LLVector4a src;
 
 			dst[i] = src;
 		}
 
-		mVertexBuffer->setBuffer(0);
+		if (map_range)
+		{
+			mVertexBuffer->setBuffer(0);
+		}
 	}
 
 	if (rebuild_tcoord)

indra/newview/llfeaturemanager.cpp

 	{
 		maskFeatures("TexUnit8orLess");
 	}
+	if (gGLManager.mHasMapBufferRange)
+	{
+		maskFeatures("MapBufferRange");
+	}
 
 	// now mask by gpu string
 	// Replaces ' ' with '_' in mGPUString to deal with inability for parser to handle spaces

indra/newview/llvovolume.cpp

 
 		group->mBuilt = 1.f;
 		
+		std::set<LLVertexBuffer*> mapped_buffers;
+
 		for (LLSpatialGroup::element_iter drawable_iter = group->getData().begin(); drawable_iter != group->getData().end(); ++drawable_iter)
 		{
 			LLFastTimer t(FTM_VOLUME_GEOM_PARTIAL);
 				for (S32 i = 0; i < drawablep->getNumFaces(); ++i)
 				{
 					LLFace* face = drawablep->getFace(i);
-					if (face && face->getVertexBuffer())
+					if (face)
 					{
-						face->getGeometryVolume(*volume, face->getTEOffset(), 
-							vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), face->getGeomIndex());
+						LLVertexBuffer* buff = face->getVertexBuffer();
+						if (buff)
+						{
+							face->getGeometryVolume(*volume, face->getTEOffset(), 
+								vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), face->getGeomIndex());
+
+							if (buff->isLocked())
+							{
+								mapped_buffers.insert(buff);
+							}
+						}
 					}
 				}
-
+				
 				drawablep->clearState(LLDrawable::REBUILD_ALL);
 			}
 		}
 		
-		//unmap all the buffers
-		for (LLSpatialGroup::buffer_map_t::iterator i = group->mBufferMap.begin(); i != group->mBufferMap.end(); ++i)
+		for (std::set<LLVertexBuffer*>::iterator iter = mapped_buffers.begin(); iter != mapped_buffers.end(); ++iter)
 		{
-			LLSpatialGroup::buffer_texture_map_t& map = i->second;
-			for (LLSpatialGroup::buffer_texture_map_t::iterator j = map.begin(); j != map.end(); ++j)
-			{
-				LLSpatialGroup::buffer_list_t& list = j->second;
-				for (LLSpatialGroup::buffer_list_t::iterator k = list.begin(); k != list.end(); ++k)
-				{
-					LLVertexBuffer* buffer = *k;
-					if (buffer->isLocked())
-					{
-						buffer->setBuffer(0);
-					}
-				}
-			}
+			(*iter)->setBuffer(0);
 		}
-		
+
 		// don't forget alpha
 		if(group != NULL && 
 		   !group->mVertexBuffer.isNull() &&