Skip to main content
GameDev.net gamedev.net
🔒 Locked

Updating constant buffers?

Started by jdub Aug 29, 2013 at 12:56 AM 5 replies 9.5k views
Original Post
jdub
jdub

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?

J.W.
MrCodeSushi
MrCodeSushi

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.

ongamex92
ongamex92

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

MrCodeSushi
MrCodeSushi

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?

MJP
MJP

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.

MJP
MJP

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.

Topic Locked

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

Sign in to reply to this topic.