Archived

This topic is now archived and is closed to further replies.

d000hg

Is this why my app is slow?

Recommended Posts

My terrain engine is drawing a 128x128 map, with one texture applied (only 6/7 calls to setTexture & Lock per frame). So thats 32768 polys per frame. Thing is on my GF2MX, I get only 20fps which is only just over .5M Tris/s. I''m guessing that it''s slow because I''m building each vertex dynamically from a heightmap and lightmap type thing. So for each vertex, I''m calling this function:
void Terrain::GenerateMAPVERTEX1(MAPVERTEX1 *p,UINT x,UINT y,short z,float u,float v,BYTE c)
{
	BYTE r,g,b;
	r=(BYTE)min( (255.0f*Light.Ambient.r + c*Light.Diffuse.r),255.0f);
	g=(BYTE)min( (255.0f*Light.Ambient.g + c*Light.Diffuse.g),255.0f);
	b=(BYTE)min( (255.0f*Light.Ambient.b + c*Light.Diffuse.b),255.0f);
	p->Diffuse=D3DCOLOR_XRGB(r,g,b);
	p->u=u;
	p->v=v;
	p->x=x*Space;
	p->y=y*Space;
	p->z=z*Hspace;
}
 
Now, what I''m doing is kind of the way it''s needed (storing all the MAPVERT1s would make that map take about 10X more memory), but how might I optimise it? I guess calling this func 32768*3 (~100K) times per frame is slowing me down. I''m only using a triangle list, but will be changing to indexed list soon. Would inlining make any appreciable difference? The other thing is, I''m writing directly to the Vertex buffer, would it be better to batch maybe 100polys worth of MAPVERT1s, then memcopy them to the VB rather than setting each one individually?
Read about my game, project #1 NEW: see my progress from last week - join the mailing list to get this and other updates every week!
John 3:16

Share this post


Link to post
Share on other sites
My first suggestion is to get yourself a profiler and profile your code. There''s no point optimizing this function if there''s something which is taking even more time.

If it is this function, and your terrain is pretty static, then I''d store your vertex buffer between frames. It''s usually not that big a deal, especially for the (relatively) small map you''ve got.

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
quote:
Original post by d000hg
It''s only a small map for testing, in the end they''ll be maybe 2000x2000 or so.



Read about my game, project #1

NEW: see my progress from last week - join the mailing list to get this and other updates every week!



John 3:16


dude, a 2000x2000 map, considering you have this fvf (a simple one)
struct avertex{
float x, y, z;
float nx, ny, nz;
float tx, ty;
};
thats like 64 megs of video mem!!! and i imagine that there is more in your fvf than that!!! the MAX i will ever go with my terrain is 512x512, but i don''t think it can handle that. right now its at 256x256 and its plenty big for what i need.

Share this post


Link to post
Share on other sites
Yeah, that's why I don't store it all in FVF form. I have a 2d heightmap of short ints (2 bytes), which can be multiplied by a float resolution thing to get the actual height, a lightmap of bytes (1 byte) which is basically the dot product of the light with the normal of a vertex. This means all lighting is pre-stored so no normals are needed ever. Then I have a texture index (1 byte) which says which texture to use.

So that's 4 bytes per vertex. See why I don't use FVFs - 2000x2000 map is 16Mb. And I don't quite do it like that - I split the map into chunks and use a quadtree, and rectangles for the area covered by each texture.

btw, what use is a 256x256 map for a game? Unless you have points like 4m apart your maps are tiny. My last version ran a 1024x1024 map at 40fps.



Read about my game, project #1

NEW: see my progress from last week - join the mailing list to get this and other updates every week!



John 3:16

[edited by - d000hg on July 29, 2002 6:27:46 AM]

[edited by - d000hg on July 29, 2002 6:28:48 AM]

Share this post


Link to post
Share on other sites
If I have understood, you call this function for all your vertex of the terrain... But I think you don''t display ALL the terrain?
So call the function only for the vertex that are displayed...
( If I have not understood, sorry )

Share this post


Link to post
Share on other sites
quote:
Original post by d000hg
Yeah, that''s why I don''t store it all in FVF form. I have a 2d heightmap of short ints (2 bytes), which can be multiplied by a float resolution thing to get the actual height, a lightmap of bytes (1 byte) which is basically the dot product of the light with the normal of a vertex. This means all lighting is pre-stored so no normals are needed ever. Then I have a texture index (1 byte) which says which texture to use.

So that''s 4 bytes per vertex. See why I don''t use FVFs - 2000x2000 map is 16Mb. And I don''t quite do it like that - I split the map into chunks and use a quadtree, and rectangles for the area covered by each texture.

btw, what use is a 256x256 map for a game? Unless you have points like 4m apart your maps are tiny. My last version ran a 1024x1024 map at 40fps.



Read about my game, project #1

NEW: see my progress from last week - join the mailing list to get this and other updates every week!



John 3:16

[edited by - d000hg on July 29, 2002 6:27:46 AM]

[edited by - d000hg on July 29, 2002 6:28:48 AM]


its a racing game, so they don''t need to be jammed together. but it has three textures blended, so i take quite the performance hit. i guess i traded polycounts for blending textures. but i think it will pay off, as it looks good already with only two textures. and it appears to be plenty big. if the hummers take up one square of the terrain, that makes the terrain out to be about one mile. since its an offroad game, you won''t be going more than 40 mph, and the tracks loop around quite a bit. so they are plenty big, all with three textures, mmm...

Share this post


Link to post
Share on other sites
quote:
Original post by d000hg
You''re doing a racer too? This just gets better Well I guess the race is on to finish first (pun most certainly intended!)


you ARE?!?!?! what kind is yours? i take it if your using 2000x2000 heightmaps, it must be some kind of speedracing. i will definitely finish last, as this is my first C++ and first D3D app. done a lot of C though.

Share this post


Link to post
Share on other sites
quote:
Original post by billybob

you ARE?!?!?! what kind is yours? i take it if your using 2000x2000 heightmaps, it must be some kind of speedracing. i will definitely finish last, as this is my first C++ and first D3D app. done a lot of C though.




Some kind of off-roady type thing, but higher paced than yours by the sound of it. Check the site in my sig for more details.




Read about my game, project #1

NEW: see my progress from last week - join the mailing list to get this and other updates every week!



John 3:16

Share this post


Link to post
Share on other sites
make sure you dont read from vram. thats slow. also that should not be a function. instead you should make the function handle generating the entire map for drawing. i assume the lock/unlock handles 1000s of vertices.

aslo try caching the vertices instead of rebuilding the entire list every frame. instead rebuild only the sections that need to be rebuilt.

Share this post


Link to post
Share on other sites