Skip to main content
gamedev.net
🔒 Locked

D3D10: ConstantBuffer vs. EffectVariable

Started by B_old Apr 15, 2009 at 12:05 PM 5 replies 1.2k views
Original Post
B_old
B_old
Hi, I am curious what the benefits of the ConstantBuffer is compared to using EffectVariable. Is it faster somehow or is it just used when you don't use the ID3D10Effect interface?
Phobon
Phobon
Actually, the effect-framework uses ConstantBuffers internally.
(As you can easily see if you monitor your program with PIX for example.)
To get the maximum of speed, group your EffectVariables according to frequency of updates via
cbuffer OncePerFrame{ //some variables herre};cbuffer OncePerObject{ //you get the idea};//etc


and DirectX automatically creates and manages the corresponding ConstantBuffers for you.
B_old
B_old
Hm, that sounds interesting.
So there is no real reason to explicitly use ConstantBuffers if I use the ID3D10Effect interface? It maybe could decrease the overhead a little bit I guess...
jollyjeffers
jollyjeffers
Yup, you've pretty much clocked it - no requirement to use CB's but there could be a definite performance gain by grouping constants.

It's a simple case of the developer adding meta data to the code - that little extra hint that allows the runtime/compiler to better interpret the raw code we push in.


hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
B_old
B_old
I experienced a strange thing.
I grouped together 2 variables that only really need to be changed per material. (For me a material is an effect, some textures and specular-coef/pow variables).
Performance went *down* after grouping if while I was still uploading the 2 variables for every mesh.
After making a test whether the previously drawn mesh has used the same material and not re-uploading those to 2 variables again in that case, the performance went up again, even surpassing the initial result.
Checking for the previously drawn material made no performance difference without constant buffers.
At first I was under the impression, that I couldn't possibly lose by declaring some cbuffers in my shader. But now it seems that I have to be careful. If it weren't for the "materialtest" I would have gotten the impression that cbuffers slow rendering down, if you know what I mean.

[Edited by - B_old on April 16, 2009 5:29:09 AM]
jollyjeffers
jollyjeffers
Interesting findings, but not hugely surprising - for relatively small shaders I'd imagine the overhead might be dominant. The case where its likely to be a real win is bigger shaders where you might have 10's or 100's of constants - a vertex skinning shader for example or a deferred renderer etc..etc..

As with all these things, performance testing is indeed an important tool [smile]


Cheers,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
B_old
B_old
That makes sense I suppose.
Thanks for the feedback, everyone!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.