DX11 VSSetConstantBuffers - Send more than one array

Started by
1 comment, last by e.s. 11 years, 2 months ago

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

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

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.

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

}

This topic is closed to new replies.

Advertisement