Stuffing Vertex Buffers

Started by
5 comments, last by Jiia 18 years, 10 months ago
I've read about pros and cons when dealing with many small vertex buffers rather than one large one. Most of the things I've read were concerning optimizing rendering speed. But in my case, I don't think that is an issue. What concerns me is the amount of memory that may become wasted due to padding issues or other such things. Is this something I should be worried about? That's all I need to know, but here's more specifics: I have somewhere between 1 to 16 seperate buffers (layers) per terrain section. Each layer is 33x33 vertices, but rarely will a single layer contain all of the vertices. The vertices are also very small and simple (32 bytes). So the size of a single layer is always less than 34kb, most often much less. I doubt I'm going to get any kind of speed boost by storing all layers of a terrain section in the same buffers, because I render layers based on textures. Rarely would two layers of one section be rendered in sequence, because they all use different textures. That means the stream source is going to keep changing, regardless. Thanks for any information.
Advertisement
Quote:Original post by Jiia
What concerns me is the amount of memory that may become wasted due to padding issues or other such things. Is this something I should be worried about?

Do you have any information indicating that you might be storage-limited on any of your target platforms? If not, it's not important.

Saving space is a good idea, but as with all optimization things you need to prioritise it based on if/how-much it's actually hurting you.

Quote:Original post by Jiia
I have somewhere between 1 to 16 seperate buffers (layers) per terrain section. Each layer is 33x33 vertices, but rarely will a single layer contain all of the vertices. The vertices are also very small and simple (32 bytes). So the size of a single layer is always less than 34kb, most often much less.

Are all of the vertices of the same FVF? If so, why not put them together? The only difference would be a few less SetStreamSource() and some changes to the offset in DrawPrimitive() calls.

More importantly, if they're closely related, is there any "sharing" involved that you could eliminate via indices?

Quote:Original post by Jiia
I doubt I'm going to get any kind of speed boost by storing all layers of a terrain section in the same buffers, because I render layers based on textures. Rarely would two layers of one section be rendered in sequence, because they all use different textures. That means the stream source is going to keep changing, regardless.

As mentioned above, if you have evidence that you are either transform or storage limited, you will see advantage by changing these things.

If they are not currently a problem, you might well want to ear-mark them for future work as/when it's necessary.

Much of this is down to the classic 80:20 rule.... "80% of your time is spent in 20% of your code". Invest your time where it'll make a difference.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks for the suggestions, much appreciated.

Quote:Original post by jollyjeffers
Much of this is down to the classic 80:20 rule.... "80% of your time is spent in 20% of your code". Invest your time where it'll make a difference.

I don't have a clue how much memory may actually be used to align the buffers, but it seems more logical to me to keep the buffers seperated. So I'm not trying to optimize, I just want to stay logical without being wasteful. I'll have to invest the same amount of time, either way I choose to write the routine. But I definitely don't want to go back and rewrite it later.

80% of my time is spent procrastinating on GameDev
Thanks again [smile]
Quote:Original post by Jiia
I don't have a clue how much memory may actually be used to align the buffers, but it seems more logical to me to keep the buffers seperated.

If you know the size required by your buffers (e.g. sizeof(vertex)*count) then you can subtract this from the values PIX sends out to determine how much wasted space there is.

I could be wrong, but having lots of small entries, each wasting a little bit in alignment could be worse than 1 large buffer wasting a bit more. Impossible to say for sure unless you get some profiling/statistics info.

Quote:Original post by Jiia
80% of my time is spent procrastinating on GameDev

[lol] Worryingly accurate for myself.

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:If you know the size required by your buffers (e.g. sizeof(vertex)*count) then you can subtract this from the values PIX sends out to determine how much wasted space there is.

At the risk of sounding dumb, what is PIX? [smile]

Quote:I could be wrong, but having lots of small entries, each wasting a little bit in alignment could be worse than 1 large buffer wasting a bit more.

Why would a large buffer waste more space? You mean if I had to leave empty buffer space in order to combine them all? If so, that's not the case. I could cram all of the layers into a single buffer with zero wasted memory. But I don't know how much space the card will waste. I don't really want to bother with it if the amount of space required to align the data is really small (like less than 1000 bytes). Can this information be requested from the device? I'll look and see.

Thanks man
PIX is the performance analysis tool for DirectX. It was originally an Xbox tool but it's available on Win32 now too, if you've got a reasonably recent version of the SDK. You can find it in your "DirectX Utilities" folder. You'll need to read the docs to learn how to use it, but it's a handy thing to have around.

-Mezz
Ahhh, I see. I rarely use the Start Menu, so I've never seen it before [smile]

Thanks :D

This topic is closed to new replies.

Advertisement