Sign in to follow this  
just_another_johnny

what's more expensive?

Recommended Posts

in a 2d engine using textured quads: locking a vertex buffer to edit the uv's of a single quad each time you want to draw a different (part of a) texture, or swapping a texture of size 32x32 pixels every time you wanna render a quad? i'm not sure of the underlying mechanics behind texture swapping and locking, however based on the amount of data that needs to be moved each time, i'd guess texture swapping is worse... is this correct? using dx9... thanks in advance

Share this post


Link to post
Share on other sites

If the texture are not too much, I perfer use swap texture.

Because
1.when you lock a vertex buffer and change it, data will be transfer from mem to gpu mem, although your data is small. But when using swap texture, the recent texture maybe stay in gpu mem already, so there will be just a texture switch cost.

2.For changing uv way, you need to put a large texture in gpu mem, but only few of it's part will be used in recent frames.

But I havn't perform the cost of both. You'd better implement both way and do performance test to decide witch way is better.

Share this post


Link to post
Share on other sites
What matters here is not so much the transfer, but the stalls (which you have in both cases). Stalls, on the other hand, are unavoidable to some extent and can be ignored for a good while, but will eventually kill your performance if there are too many.

Switching textures is relatively sure to cause a stall. I say "relatively sure", because the hardware has a small unknown number of texture binds that the driver can switch between without you knowing and without any way of finding out. As long as you use fewer textures than there are "slots" all is good, otherwise it will stall. The problem is you don't know.
Locking and changing a vertex buffer is guaranteed to cause a stall, there is no other way it could be, as the GPU must wait for the data to be copied.

Now what to do? It depends on the number of such quads that you draw per frame and whether they change etc.
If you talk about drawing 10-20 sprites per frame... forget about it and just do what you want, it will not matter at all.
If you talk about drawing 1000 tiles every frame, then make a vertex buffer with 1000 quads in it (with the respective UV, and at the correct position), upload that and draw them all in one batch. Or, consider putting the regular grid positions which never change into one buffer, and only update the UVs in another buffer, which is a little less traffic.

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