Sign in to follow this  
BattleMetalChris

Confused about Constant Buffers [DX10]

Recommended Posts

[font="Helv"][size="2"][font="Helv"][size="2"]I'm trying to get to grips with Directx 10 and shaders. I've written DX9 fixed-function pipeline stuff before but this is my first attempt with shaders.

I'm a little unsure of the role of and how to use constant buffers. I get the idea - you group data together so that it can be sent to the GPU in groups according to the frequency they need updating - so you'd have a constant buffer per frame, per shader, per object, etc - so you don't have to send the entire list of variables every draw call.

However, all the tutorials I've followed, although they group the data in the .fx file into constant buffers, the variables are set individually using GetVariableByName. Does this bypass the constant buffer completely, or is still using them and just abstracts the process? If this is the case, is it updating the whole buffer whenever a variable is updated (which would be a waste, and so a reason not to update variables this way) or using something clever to insert just that variable at the correct point in the GPU's memory?

[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
It still uses a constant buffer behind the scenes. The Effects framework should be smart enough to only update when needed. It will probably update whenever you call Begin if you have changed anything, and to update changed values between a Begin/End pair you call Commit. I'm not sure on the exact details of the updating though, but I guess it keeps a buffer in system memory and sends the entire buffer to the GPU on Begin/Commit.

Share this post


Link to post
Share on other sites
[quote name='BattleMetalChris' timestamp='1297863431' post='4774956']
[font="Helv"][size="2"][font="Helv"][size="2"]I'm trying to get to grips with Directx 10 and shaders. I've written DX9 fixed-function pipeline stuff before but this is my first attempt with shaders.

I'm a little unsure of the role of and how to use constant buffers. I get the idea - you group data together so that it can be sent to the GPU in groups according to the frequency they need updating - so you'd have a constant buffer per frame, per shader, per object, etc - so you don't have to send the entire list of variables every draw call.

However, all the tutorials I've followed, although they group the data in the .fx file into constant buffers, the variables are set individually using GetVariableByName. Does this bypass the constant buffer completely, or is still using them and just abstracts the process? If this is the case, is it updating the whole buffer whenever a variable is updated (which would be a waste, and so a reason not to update variables this way) or using something clever to insert just that variable at the correct point in the GPU's memory?

[/size][/font][/size][/font]
[/quote]

Under the assumption that Dx10 works similar to Dx11 (and you are using the effect framework) I'd have to say that GetVariableByName locks the buffer, set's the data at the variable's position and then unlocks it. Or perhaps instead, (since I don't use the effect framework myself) it keeps a local copy of the buffer in main memory and copy's to the constant buffer at some point. Regardless, Constant buffers are required to set constant data in the shader via PSSetConstantBuffers.

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