Advertisement

Constant Buffer binding ( how long does it remain )

Started by October 16, 2017 12:30 PM
3 comments, last by matt77hias 7 years, 3 months ago

hi,

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

or

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 )
updateSubresource(buffer_A)
vertexshader.setConstantbuffer ( buffer_A,  slot_A )

perform drawcall       ( buffer_A is used )

SetVertexShader ( VS_B )
updateSubresource(buffer_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

 

 

 

 

 

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.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Advertisement

 

many thanks for the qualified clear answer  !!

 

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).

 

🧙

This topic is closed to new replies.

Advertisement