XNA Game Development Forums
2012/05/18 06:00:39 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Batching system !  (Read 6418 times)
SeeMe
Newbie
*
Offline Offline

Posts: 12


View Profile
« on: 2006/08/16 05:56:45 »

Hello,

while playing around with the Hazy Mind engine, I tried to duplicate 100 times a mesh.
Result -> My frameRate dropped like @"&#.

After reading from specilized forums, Nvidia? and Ati whitepaper, it seems that to be optimal an engine should batch "as much as possible".

I'm trying to implement a data buffering inside my engine but that's not an easy path at all.

It could be very nice if you could implement, the basis of a buffering system in Hazy Mind.
The aim could be : Trying to display as much as possible with as less as possible Draw call !

See you soon ! Smiley
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #1 on: 2006/08/16 11:59:01 »

Sounds like a great idea. I'll have to think about how something like that would be put together within the scene graph class when it becomes a bit more advanced. Anyone have some good hints about this one? Not sure how you would minimize Draw() calls when each mesh has to call it at least once as I haven't seen this "batching" method before.
Logged
SeeMe
Newbie
*
Offline Offline

Posts: 12


View Profile
« Reply #2 on: 2006/08/16 13:06:25 »

Hello,

I will try to explain what I have discovered so far.

First the root "problems" :
First :
Every call to your graphic card driver has a "cost", in number of cycle, the more cycle the worst.
Here is the average diff. api call cost : http://www.gamedev.net/community/forums/topic.asp?topic_id=260153
The aim here is to limit the number of calls in one single frame.
Second :
Our actual graphic cards are really powerful, if we don't give them enough work to do at once, its a waste of power : The GPU will be most of the time in Idle state waiting for data to process. We can call this problem "CPU or driver bound".

Let's take a quick and easy exemple :

We have 1 object composed of 2 squares (Quad1 and Quad2), each square has his own texture.
We want to render 500 times this object.

The "wrong" way :

Code:
Foreach (object in objectcollection)
{
      Device.SetStreamSource = object.Quad1.VertexBuffer
      Device.SetTexture = object.Quad1.Texture
      Draw call
     
      Device.SetStreamSource = object.Quad2.VertexBuffer
      Device.SetTexture = object.Quad2.Texture
      Draw call
}

Result for 500 objects : 1000 SetStreamSource, 1000 SetTexture, 1000 Draw call !

Now an exemple of static batching (static because, its good for objects that are not subject to move and state changes in the world space, like a terrain) :
Code:

At initialisation step :
Array MyQuadBufferObject
VertexBuffer myBigVertexBuffer

Foreach (object in objectcollection)
{
     MyQuadBufferObject.add(object.myQuad1);
     MyQuadBufferObject.add(object.myQuad2);
}
MyQuadBufferObject.sort by QuadType;
Send all objects into myBigVertexBuffer;

Processing step :

Device.SetStreamSource = myBigVertexBuffer.VertexBuffer

Foreach (object in MyQuadBufferObject)
{
    if (object is the same type as the previous one)
    {
          Count the number of objects;       
    }
   else
    {
         Device.SetTexture = Previousobject.Texture
         Draw call (With offseting in the myBigVertexBuffer)
    }
}

In this case, we should only have 1 SetStreamSource, 2 SetTextures and 2 Draw call. For the same result !!

For the moment I have put in place 2 type of batching :
Static one (Objects that are not moving or changing a lot)
Dynamic one (for object that are moving a lot)

It's a very interesting subject, and I think you should think of it before going too far with the engine (Could make you view of the structure of your engine change with the batching implementation).
I you want I can forward you my current project (not a lot done, but the base for static and dynamic buffer are in it, with your Hazy mind engine as base root).

ps : Sorry for my poor english Smiley

See you !
Logged
SeeMe
Newbie
*
Offline Offline

Posts: 12


View Profile
« Reply #3 on: 2006/08/17 00:00:11 »

Heps !

I found the ATI document concerning batching (Not a technical one, but most to introduce the idea), quite nice to read : http://www.ati.com/developer/gdc/D3DTutorial3_Pipeline_Performance.pdf
Logged
Ultrahead
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #4 on: 2007/01/16 12:28:00 »

... Anyone have some good hints about this one? Not sure how you would minimize Draw() calls when each mesh has to call it at least once as I haven't seen this "batching" method before.

Sorry for posting this late as I'm new to the forum, but maybe SeeMe is referring to "Instancing" which will be present in DX10. With that feature, you will be able to draw all of the instances of a mesh you want (with different sizes, textures, animations, etc.) with just one draw call.
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Effect System Hazy Mind XNA Engine Zwigby 1 1535 Last post 2007/03/27 07:14:04
by Arkcann
LOD system? Anyone? General Discussion XNASorcerer 1 1515 Last post 2007/05/19 17:19:42
by mikeschuld
Add .fx to the attachment system Forum Requests Chr0n1x 7 4671 Last post 2007/07/21 01:33:53
by Chr0n1x
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 3.855 seconds with 19 queries.