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

DX11 VSSetConstantBuffers - Send more than one array

Started by Veiled Glitch Jan 27, 2013 at 7:13 PM 1 replies 3.8k views
Original Post
Veiled Glitch
Veiled Glitch

Hi guys,

right now I'm having a small problem, in the command from the device context called VSSetConstantBuffers, the parameters are as following:


void VSSetConstantBuffers(
  [in]  UINT StartSlot,
  [in]  UINT NumBuffers,
  [in]  ID3D11Buffer *const *ppConstantBuffers
);

Now the number of buffers is easy when you have two arrays of constant buffers, but the ID3D11Buffer *const *ppConstantBuffers isn't so easy. My first approach was to combine the two arrays of ID3D11Buffer*(s), but that could become quite slow as this is called quite frequent. So is there a quick way to send two arrays of buffers, maybe call the function twice and change the startslot?huh.png

So how can i do this?

Thank You

Jason Z
Jason Z

I think you already stated the best way to do the call - just make two calls to the function with a different start slot to put everything where you need them. However, it would probably be best to try it out both ways to see what is more expensive. Essentially you are trading a memcpy for an API call, and there are lots of variables that could help or hurt either method. Most likely the difference between the two calls is not going to be noticeable, since the heavy costs are likely to be elsewhere in your frame.

You should also ensure that you are doing all of the optimizations you can, such as ensuring that any buffers that can be reused between calls are allowed to remain there, and to make sure you are using as few of buffers as you can. I would be curious to hear if you detect any significant difference between the two methods.

Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
e.s.
e.s.

Here is some code that I used to bind multiple buffers at once... Granted, your situation is a bit different with the constant buffer, but the syntax should be close.

TBH, I prefer to push one buffer at a time, (I set the constant buffer in one activity, then set the static vertexbuffer data, then set instance buffer data every frame or so).

HTH


/******************************************************************/
void ModelRenderer::BindInitialBuffer()
{


unsigned int offsets[2] = {0,0};
unsigned int strides[2];

ID3D11Buffer* bufferPointers[2];

strides[0] = sizeof(NS::Vertex);
strides[1] = sizeof(Position);

bufferPointers[0] = ModelRenderer::StaticBuffer.Get();
bufferPointers[1] = ModelRenderer::InstanceBuffer.Get();

DeviceManager::DeviceContext->IASetVertexBuffers(
0, // First Input Slot for Binding
2, // Number of Buffers
bufferPointers, // Buffer Pointer(s)
strides, // Stride(s)
offsets // Offset(s)
);

DeviceManager::DeviceContext->IASetInputLayout(ModelRenderer::InitialLayout.Get());
DeviceManager::DeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

}

Topic Locked

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

Sign in to reply to this topic.