Sign in to follow this  
Mace

Constantly changing VertexBuffer size?

Recommended Posts

Hey :) I recently implemented a bitmapped font renderer in MDX 1.1 and have a question about the way i handle the vertexbuffer for all rendered characters (which are made out of quads). I havent found a way to make my vertex buffer change its size dynamically to adjust itself to the number of characters rendered on screen for each update. Since there can be different number of characters on screen for each frame, i currently have to make sure that the buffer is big enough to hold all characters or else it will crash. A temporary solution to this is to simply have a huge buffer but then.. not all of it might ever be used which would be a waste of memory. This is how i currently setup my vertex buffer where maxCharacters is the variable to adjust how many characters i can draw on screen at once. vertexBuffer = new VertexBuffer( device, (maxCharacters * 4) * CustomVertex.TransformedTextured.StrideSize, Usage.Dynamic | Usage.WriteOnly, CustomVertex.TransformedTextured.Format, Pool.Default); Any suggestions on how to make it more dynamic and flexible?

Share this post


Link to post
Share on other sites
How many possible characters can you have on screen? Something around 2k? You think a 2k vb of memory vs. resizing a vertexbuffer and stalling your graphics card is more or less efficient? I would stick with the fixed size and move on to something more important. Then if you later start running out of memory because you allocated this buffer, then you can look at resizing it. If you were to erase and resize this buffer it would definitely incur a speed hit, there is always a tradeof with speed vs. memory, and in this case i think you have to just waste the memory and stick with the speed and ease of use of the code.

Share this post


Link to post
Share on other sites
Alternatively, you could fill the vertex buffer until it is full, then send it off to be rendered with a draw call, then clear it and start filling it again, until you either run out of quads to render or flush and start writing again. This is assuming that you are using a dynamic vertex buffer to store your quads per frame.

I know this way you will possibly be sending more draw calls, but surely that is better than the program crashing?

Hope this helps.

Share this post


Link to post
Share on other sites
Understanding OS-level memory management strategies can be very useful knowledge here. Most good OS textbooks cover this sort of thing in detail and I'm sure your preferred search engine will find some stuff [wink]

Creating an oversized buffer is a reasonable option given that vertex storage is relatively cheap. Although this is only reasonable to a point.

Using a vector (as in the container type, not the mathematical vector) approach works well. Create it of size N and when you run out of space you recreate it as 2*N in size and copy the contents across.

Have you any usage statistics on the length of your text? For example, is it always between 10-30 characters? If so, having a ready-made pool of vertex buffers might work well.

To offset any chances of stalling the pipeline due to (re-)creating and/or modifying resources you can try the double/triple buffering approach (aka "bounded buffer").

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by Ready4Dis
You think a 2k vb of memory vs. resizing a vertexbuffer and stalling your graphics card is more or less efficient? I would stick with the fixed size and move on to something more important.


Im asking because i want to hear all the alternatives for how this is handled.
Thanks (everyone) for the input, i will probably go for what i have (for now) but take a look at Muhammad´s link later on. It seems to be in the flexible fashion id like things to be kept.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this