Jump to content
  • Advertisement
Sign in to follow this  
jdub

Updating constant buffers?

This topic is 1730 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

Can I create a constant buffer (ID3D11Buffer) using D3D11_USAGE_DYNAMIC, pass it to the pipeline once using VSSetConstantBuffers() and then update the constant buffer by calling Map and then writing the desired value on the ID3D11Buffer object I created?

Is this possible or do I have to call VSSetConstantBuffers() every time I want to update constant buffers within my shader?

Share this post


Link to post
Share on other sites
Advertisement

If you're using the same constant buffer then you don't need to keep on re-binding them after the first bind every time you update the constant buffer since its already bound in the pipeline.

Share this post


Link to post
Share on other sites

Not quite true : http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx

 

Return value

Type: HRESULT

This method returns one of the Direct3D 11 Return Codes.

This method also returns DXGI_ERROR_WAS_STILL_DRAWING if MapFlags specifiesD3D11_MAP_FLAG_DO_NOT_WAIT and the GPU is not yet finished with the resource.

 

You cant just update an already binded constant buffer, that may cause unexpected behavior

Edited by imoogiBG

Share this post


Link to post
Share on other sites

Well that is untill you bind another shader off course or another buffer on the same slot.

lol funny i was actually thinking about that when i posted my answer. Then i realized i was sort of implicitly rebinding shader resources every time i bind a new shader in my engine.

 

 

Not quite true : http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx

 

Return value

Type: HRESULT

This method returns one of the Direct3D 11 Return Codes.

This method also returns DXGI_ERROR_WAS_STILL_DRAWING if MapFlags specifiesD3D11_MAP_FLAG_DO_NOT_WAIT and the GPU is not yet finished with the resource.

 

You cant just update an already binded constant buffer, that may cause unexpected behavior

Are there any reason or practical usage to create the buffer with the D3D11_MAP_FLAG_DO_NOT_WAIT flag?

Edited by BrentChua

Share this post


Link to post
Share on other sites

Well that is untill you bind another shader off course or another buffer on the same slot.

 

You can switch shaders, it doesn't affect the CB binding. If your shaders all share a constant buffer layout then you only need to bind that CB once.

Share this post


Link to post
Share on other sites

Not quite true : http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx

 

Return value

Type: HRESULT

This method returns one of the Direct3D 11 Return Codes.

This method also returns DXGI_ERROR_WAS_STILL_DRAWING if MapFlags specifiesD3D11_MAP_FLAG_DO_NOT_WAIT and the GPU is not yet finished with the resource.

 

You cant just update an already binded constant buffer, that may cause unexpected behavior

This doesn't apply to to DYNAMIC buffers that you map with DISCARD, since that causes the driver to use renaming to avoid having to wait for the GPU to be finished with the resource.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!