Jump to content
  • Advertisement

DX11 Constant Buffer binding ( how long does it remain )

This topic is 393 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


i have read very much about the binding of a constantbuffer to a shader but something is still unclear to me.

e.g. when performing :   vertexshader.setConstantbuffer ( buffer,  slot )

 is the buffer bound

a.  to the VertexShaderStage


b. to the VertexShader that is currently set as the active VertexShader

Is it possible to bind a constantBuffer to a VertexShader e.g. VS_A and keep this binding even after the active VertexShader has changed ?
I mean i want to bind constantbuffer_A  to VS_A, an Constantbuffer_B to VS_B  and  only use updateSubresource without using setConstantBuffer command every time.

Look at this example:

SetVertexShader ( VS_A )
vertexshader.setConstantbuffer ( buffer_A,  slot_A )

perform drawcall       ( buffer_A is used )

SetVertexShader ( VS_B )
vertexshader.setConstantbuffer ( buffer_B,  slot_A )

perform drawcall   ( buffer_B is used )

SetVertexShader ( VS_A )
perform drawcall   (now which buffer is used ??? )


I ask this question because i have made a custom render engine an want to optimize to

the minimum  updateSubresource, and setConstantbuffer  calls






Share this post

Link to post
Share on other sites

Bindings of constant buffers are separate and unrelated to the currently bound Vertex Shader.

When you bind a constant buffer you are binding it to the "pipeline", not to the currently set Vertex Shader. For that reason, you are free to set a constant buffer once and then repeatedly update its contents and change Vertex Shader without needing to rebind the constant buffer.

Share this post

Link to post
Share on other sites

You must consider the pipeline as a huge finite state machine:

(vertex shader program, vertex shader c|t|s registers, hull shader program, hull shader c|t|s registers, ...)

Note that this state also includes non-shader-related components such as rasterizer state (RS), blend state (OM) and depth-stencil state (OM).

As long as you do not rebind a component of the state, the currently bound component is used. The shader program and shader registers are separate components of the state. So if you bind a constant buffer (c register), sampler state (s state), etc. to a shader stage and you do not rebind these slots, all bindings will be persistent (independent of which shader program is bound).


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!