Surface Benchmarking

Blitz3D Forums/Blitz3D Programming/Surface Benchmarking

Jeremy Alessi(Posted 2003) [#1]
After reading the surface count thread I went and attempted to make a benchmark. I have it rendering 225 spheres each with 8 segments or 224 polygons. All together it's 50,400 polygons. My machine (Athlon 1GHz, GeForce 3 Ti 200, 512 MB RAM) runs this at 121 FPS whether AddMesh() and Freeentity(sphere) are commented out or not. So I don't know if that means all these spheres use the same surface since there are no textures and they're materials are the same or that surface count doesn't matter. Draw your own conclusions.

Oh and the camera is positioned pretty high which would rule out fill rate issues.

screen_width=640
screen_height=480
Graphics3D(screen_width,screen_height,16,1)

camera=CreateCamera()
PositionEntity(camera,75,400,75)
RotateEntity(camera,90,0,0)

mesh=CreateMesh()

For i=1 To 150 Step 10
	For j=1 To 150 Step 10
		sphere=CreateSphere(8)
		PositionMesh(sphere,i,0,j)
		AddMesh(sphere,mesh)
		FreeEntity(sphere)
	Next
Next

While KeyDown(1)=0
	RenderWorld
	Gosub Framerate
	Flip
Wend

;====== FRAMERATE ========================================================
.Framerate
fps_counter=fps_counter+1
If framecounter_time=0 Then framecounter_time=MilliSecs()
If framecounter_time+1001<MilliSecs()
	framerate=fps_counter
	machine_framerate=framerate
	fps_counter=0
	framecounter_time=MilliSecs()
	last_framerate=framerate
EndIf
Text ((screen_width*280)/640),((screen_height*430)/480),"Polygons "+TrisRendered()
Text ((screen_width*280)/640),((screen_height*450)/480),"FPS-- "+framerate
Return
;=========================================================================



Anthony Flack(Posted 2003) [#2]
Yup, I only got 61 FPS out of my GF2... but it was the same regardless of whether addmesh and freeentity were in or not.


sswift(Posted 2003) [#3]
Addmesh creates a new surface in the destination mesh and adds the mesh to it.

You have to use my addmeshtosurface function in the code archives to add the spheres to the SAME surface in a mesh to do a real test.


Jeremy Alessi(Posted 2003) [#4]
OK, using that function I was able to notice maybe 10 FPS difference by using more polygons since my machine seems to cap at 121 FPS. Using the AddSufaceToMesh() I got 121 still (without the second mesh, which I added since you can only have so many verts per mesh). Without it I got 108-110 FPS. If I add the second mesh called mesh_two and surface_two to jump the polygons up to 114,000 I get about 63 FPS using AddSurfaceToMesh() and about 57 normally.

It seems to me that the surface count may only make big differences on older video cards. I'm running a GeForce 3 Ti 200 and while there is a difference, it isn't huge.

Check this out:

screen_width=640
screen_height=480
Graphics3D(screen_width,screen_height,16,1)

camera=CreateCamera()
PositionEntity(camera,80,150,80)
RotateEntity(camera,90,0,0)

mesh=CreateMesh()
surface=CreateSurface(mesh)

mesh_two=CreateMesh()
surface_two=CreateSurface(mesh_two)

For i=1 To 160 Step 10
	For j=1 To 160 Step 10
		sphere=CreateSphere(8)
		PositionMesh(sphere,i,0,j)
		;AddMeshToSurface(sphere,mesh,surface)
		;FreeEntity(sphere)
		sphere=CreateSphere(8)
		PositionMesh(sphere,i,0,j)
		;AddMeshToSurface(sphere,mesh_two,surface_two)
		;FreeEntity(sphere)
	Next
Next

While KeyDown(1)=0
	RenderWorld
	Gosub Framerate
	Flip
Wend

;====== FRAMERATE ========================================================
.Framerate
fps_counter=fps_counter+1
If framecounter_time=0 Then framecounter_time=MilliSecs()
If framecounter_time+1001<MilliSecs()
	framerate=fps_counter
	machine_framerate=framerate
	fps_counter=0
	framecounter_time=MilliSecs()
	last_framerate=framerate
EndIf
Text ((screen_width*280)/640),((screen_height*430)/480),"Polygons "+TrisRendered()
Text ((screen_width*280)/640),((screen_height*450)/480),"FPS-- "+framerate
Return
;=========================================================================

;====== ADD MESH TO SURFACE ==============================================
Function AddMeshToSurface(SrcMesh, DestMesh, DestSurface, Voffsetx#=0, Voffsety#=0, Voffsetz#=0, Vpitch#=0, Vyaw#=0, Vroll#=0, Vscalex#=1, Vscaley#=1, VscaleZ#=1)

	; Determine if we can optimize the mesh copying.
	TransformVertices = True
	If (Vpitch#=0) And (Vyaw#=0) And (Vroll#=0) 
		TransformVertices = False
	EndIf


	; Make sure there's a surface to copy, because the mesh might be empty.
	If CountSurfaces(SrcMesh) > 0

		SrcSurface = GetSurface(SrcMesh, 1)

		DestVerts  = CountVertices(DestSurface)
		SrcVerts   = CountVertices(SrcSurface)
			
		; If we need to transform the vertices in a complex way...
		If TransformVertices

			; Do slower copy method because we need to rotate the vertices.

			; Create a pivot to do the transformations with.
			ThisPivot = CreatePivot()
			PositionEntity ThisPivot, Voffsetx#, Voffsety#, Voffsetz#, True
			RotateEntity ThisPivot, Vpitch#, Vyaw#, Vroll#, True
			ScaleEntity ThisPivot, Vscalex#, Vscaley#, Vscalez#

			; Copy all the vertices from the source mesh to the destination surface.
			For VertLoop = 0 To SrcVerts-1
					
				Vu#  = VertexU#(SrcSurface, VertLoop)
				Vv#  = VertexV#(SrcSurface, VertLoop)		
				Vw#  = VertexW#(SrcSurface, VertLoop)
				Vr   = VertexRed(SrcSurface, VertLoop)
				Vg   = VertexGreen(SrcSurface, VertLoop)
				Vb   = VertexBlue(SrcSurface, VertLoop)
			
				TFormPoint VertexX#(SrcSurface, VertLoop), VertexY#(SrcSurface, VertLoop), VertexZ#(SrcSurface, VertLoop), ThisPivot, 0
				Vx# = TFormedX#()
				Vy# = TFormedY#()
				Vz# = TFormedZ#()

				TFormNormal VertexNX#(SrcSurface, VertLoop), VertexNY#(SrcSurface, VertLoop), VertexNZ#(SrcSurface, VertLoop), ThisPivot, 0
				Vnx# = TFormedX#()
				Vny# = TFormedY#()
				Vnz# = TFormedZ#()
			
				AddVertex(DestSurface, Vx#, Vy#, Vz#, Vu#, Vv#, Vw#)
				VertexNormal(DestSurface, VertLoop+DestVerts, Vnx#, Vny#, Vnz#)
				VertexColor(DestSurface, VertLoop+DestVerts, Vr, Vg, Vb) 
	
			Next

			FreeEntity ThisPivot

		Else

			; Do the fast copy.
			; Fast copy can do offset and scaling, but not rotation.

			; Copy all the vertices from the source mesh to the destination surface.
			For VertLoop = 0 To SrcVerts-1

					
				Vx#  = VertexX#(SrcSurface, VertLoop)
				Vy#  = VertexY#(SrcSurface, VertLoop)
				Vz#  = VertexZ#(SrcSurface, VertLoop)
				Vu#  = VertexU#(SrcSurface, VertLoop)
				Vv#  = VertexV#(SrcSurface, VertLoop)		
				Vw#  = VertexW#(SrcSurface, VertLoop)
				Vnx# = VertexNX#(SrcSurface, VertLoop)
				Vny# = VertexNY#(SrcSurface, VertLoop)
				Vnz# = VertexNZ#(SrcSurface, VertLoop)						
				Vr   = VertexRed(SrcSurface, VertLoop)
				Vg   = VertexGreen(SrcSurface, VertLoop)
				Vb   = VertexBlue(SrcSurface, VertLoop)
		
				AddVertex(DestSurface, (Vx#*Vscalex#)+Voffsetx#, (Vy#*Vscaley#)+Voffsety#, (Vz#*Vscalez#)+Voffsetz#, Vu#, Vv#, Vw#)
				VertexNormal(DestSurface, VertLoop+DestVerts, Vnx#, Vny#, Vnz#)
				VertexColor(DestSurface, VertLoop+DestVerts, Vr, Vg, Vb) 
	
			Next

		EndIf


		; Copy all triangles from the source surface to the destination surface.	
		SrcTris  = CountTriangles(SrcSurface)
		For TriLoop = 0 To SrcTris-1
	
			V0 = TriangleVertex(SrcSurface, TriLoop, 0)
			V1 = TriangleVertex(SrcSurface, TriLoop, 1)
			V2 = TriangleVertex(SrcSurface, TriLoop, 2)
		
			AddTriangle(DestSurface, V0+DestVerts, V1+DestVerts, V2+DestVerts)
	
		Next
		
	EndIf

			
End Function
;=========================================================================



sswift(Posted 2003) [#5]
You have to use Flip False to get a true FPS reading. The cap at 120fps is because of that I would assume.


DJWoodgate(Posted 2003) [#6]

Addmesh creates a new surface in the destination mesh and adds the mesh to it.



Not necessarily. Surfaces painted with the same brush may well be merged.


sswift(Posted 2003) [#7]
I did some tests a while back, so perhaps things have changed, or something here is different from my test.


GNS(Posted 2003) [#8]
My tests all used brushes and PaintMesh. If I use EntityTexture the entities lose their texture after AddMesh is called.


smilertoo(Posted 2003) [#9]
I get 627 fps on the first source, and 94 fps on the 2nd.


Anthony Flack(Posted 2003) [#10]
Ha, sswift is dead right; I never even thought to check... bad benchmark!

With flip false, I get 61 FPS with seperate objects and 100 fps with merged. Quite a difference.


smilertoo(Posted 2003) [#11]
When i use the merge thing the 2nd test jumps to 302 fps.


Rob Farley(Posted 2003) [#12]
I get 17 fps unmerged and 20 merged.

Athlon 900, GeForce 3 Ti200


Jeremy Alessi(Posted 2003) [#13]
OK, using flip false and 114,000 polygons I get 56-57 FPS with seperate entities and I get 88-89 FPS using the addmeshtosurface(). Nice increase there. What are the negatives to using flip false which increases the framerate for me by about 25 FPS?


Hotcakes(Posted 2003) [#14]
The only negative to using Flip False is that your display is no longer synced with your monitor. = No One Cares


Michael Reitzenstein(Posted 2003) [#15]
Flip false also causes tearing issues. They wouldn't *have* VSync if it wasn't useful.


jhocking(Posted 2003) [#16]
Besides, increasing your framerate from 56 to 88 doesn't matter much except for the developer (ie. you) benchmarking the game.


Anthony Flack(Posted 2003) [#17]
Benchmarking aside, running your game at a higher FPS than your monitor is pointless. It can only look worse. Never better.


Jeremy Alessi(Posted 2003) [#18]
The strange thing about that is my monitor can run up to 120 FPS. Why in this test do the FPS increase?


jhocking(Posted 2003) [#19]
Wait, I must have misread. Did you ever say what framerate you were getting without Flip False? You give us before and after figures relative to addmeshtosurface (which is where the extra 25 fps is coming from) but you didn't give a comparison relative to Flip False.


Jeremy Alessi(Posted 2003) [#20]
Without Flip False but using the addmeshtosurface still I only got 63 FPS. Just by changing to Flip False I got an extra 25 FPS.