• Advertisement

Archived

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

Batching (renamed)

This topic is 5004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hya there, Basically I've got one index buffer for my entire terrain grid. I am using a quadtree to split my grid up and my index buffer is hierarchically done so that all the polygons in one quadtree segment are together. I am currently using texture splatting to render my terrain. I render each octree segment that is visible 5 times at the moment. I know I need to reduce the draw indexed primitive calls down and I've come up with how I think I should do it... 1. Cull using frustum culling on the quadtree (already used) to get a list of visible quadtree segments. 2. Create a new index buffer which contains only the visible geometry after culling. Hre I think I should produce an index buffer for every texture splat texture and each index buffer only contains the segments that are visible and have the texture on them. This would reduce fillrate significantely and reduce the draw indexed primitive calls. So that's my plan, firstly what does everyone think of that. And secondly how do I go about building the dynamic index buffers with only the visible data. Thanks for any help Matt [edited by - de_matt on June 11, 2004 8:14:19 AM]

Share this post


Link to post
Share on other sites
Advertisement
Actually I waffled on a bit there. Basically all I want is to know how to group data from lots of index buffers (or at different locations in one index buffer) in to one index buffer.

Thanks

Matt

Share this post


Link to post
Share on other sites
I''ve come up with this so far. Would this be right?

polycount = 0
for i = 1 to num_of_quad
lock ib1 ->ptr1 at quad(i).start of len quad(i).polycount
lock ib_batched ->ptr2 at polycount of len quad(i).polycount
memcopy from ptr1 to ptr2, ib(i).polycount
unlock ib_batched
unlock ib1
polycount = polycount + quad(i).polycount
next i

This seems like rather a lot of locking and unlocking to be fast to me.

Matt

Share this post


Link to post
Share on other sites
I am somewhat unsure of the cost of of copying from one buffer to another if the buffers are hardware resident. The cost should be minimal if they are managed or dynamic with the appropiate read/write hints.

Your best bet would be to test out the various buffer implemenations.

Or you could just parse a standard short[] array that you built to a managed/dynamic index buffer.

Again, try out the various means, but note: If your system is bottlenecking somewhere else you are unlikely to get true results. You best bet would be to locate where your bottlenecks are in both the gfx subsystem and you program (loop) and tackle them in order, before you worry too much about the dynamic indexing.
As a general rule though if you are going to alter your buffer frequently you should create them as dynamic and with the appropiate read/write hints.

Share this post


Link to post
Share on other sites
quote:
Original post by de_matt
I''ve come up with this so far. Would this be right?

polycount = 0
for i = 1 to num_of_quad
lock ib1 ->ptr1 at quad(i).start of len quad(i).polycount
lock ib_batched ->ptr2 at polycount of len quad(i).polycount
memcopy from ptr1 to ptr2, ib(i).polycount
unlock ib_batched
unlock ib1
polycount = polycount + quad(i).polycount
next i

This seems like rather a lot of locking and unlocking to be fast to me.

Matt


Oh yeah and you would probably be better of putting the lock/unlock calls outside of that loop there if you use it because lock/unlock have large overheads, especially if the array size you are transferring is small.

Share this post


Link to post
Share on other sites
So I would bin the current index buffer and instead store an array of indices instead which I put in the dynamic IB. I can think of two ways of doing that:

1.

create another array containing only the visible indices

lock ib
memcopy the array in to the ib
unlock

2.

for i = 1 to quadtree_count
lock ib
memcopy quadtree indices in to ib
unlock
next i

The second method seems tidier but of course there are a lot of lock / unlock calls.

Also of note, I''m thinking of doing a dynamic array for each texture splatt texture so the lock / unlock would be even worse.

Share this post


Link to post
Share on other sites
I use dynamic buffers for this sort of thing.

For each "texture" (not really what I''m doing, but close enough for this discussion), I add all the faces that use that "texture" into an index buffer (the indices that make up the faces are concocted at load time) by doing the following:

1.) Lock the buffer
2.) Add the vertices / indices
3.) Unlock the buffer

When the buffer is full (or when I complete the drawing of a particular "texture"), I call DrawPrimitive() (or DrawIndexedPrimitive())).

Share this post


Link to post
Share on other sites
Here is a great slideset on batching. You should really check it out, if you haven''t already seen it.

Share this post


Link to post
Share on other sites

  • Advertisement