[DX11] Setting specific constant buffers without the effect framework

Started by
1 comment, last by n3Xus 13 years, 11 months ago
Hello, I'm making a shader system without the effect framework and I'm stuck setting the desired constant buffer. This is how my CB layout in the shader looks like: // World transform cbuffer cbWorldTransform: register (b0) { matrix g_matWorld; } // Camera cbuffer cbuffer cbCamera: register (b1) { // some camera matrices here }; I'm having problems setting just the camera cbuffer: whenever I want to set the camera CB the values go into the WorldTransform constant buffer instead. I thought this was controlled by the startSlot parameter in the VSSetConstantBuffers function, so if I wanted to set the camera CB I would write it like this: m_devContext->VSSetConstantBuffers(1,1,myBuffers) I thoughts that this startSlot param would index myBuffers AND the shader CBs, but it seems that it only indexes the buffers in myBuffers array. So now if I want to set the camera cbuffer I must also set the WorldTransform cbuffer, is there a way to set camera CB only? What am I missing?
Advertisement
Certainly you can set the constant buffers individually. Have you tried setting the buffer to the 0 slot instead of the 1 slot? Perhaps the locations are being switched on you by the compiler?

I typically load a shader, then perform the shader reflection to find out which parameters it has and what type they are, plus find the names of each parameter. This type of information is just cached and stored with the shader, and then gets used later on to ensure that the proper type of parameter is being set into the shader at runtime.

The reflection API is not the simplest beast around, but if you want the code I have developed it is available on codeplex (see link in the signature). If not, it shouldn't take too long to get working properly on your own as well.
Got it to work now: It works just the opposite as I expected: the start slot is for the shader CB index, while you must specify the buffer as a single element (I always passed in an entire array of ID3D11Buffers since I thought it would also automatically index them), so it was more of a normal programmatical error.

I do perform shader reflection, just as you do in your open source engine, I downloaded it a while ago to checked it out :D thanks for that, it proved quite helpful many times!
Thanks for the help - I got it.

1. Simply set up your D3D11_INPUT_ELEMENT_DESC() like this (note the slot# increasing each time)
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR0", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "float0", 0, DXGI_FORMAT_R32_FLOAT, 2, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },

2. Then register each position/color0/color1 buffer with DX like normal with CreateBuffer(),

3. Then, using an array of strides, offsets and the bufferObjects you created in step 2, do this:
UINT strides[3] = {12, 12, 4};
UINT offsets[3] = {0, 0, 0};
ID3D11Buffer** m_ppDXBufferObjects[3] = (buffer objects you created in step 2)

pImmediateContext->IASetVertexBuffers(0, 3, m_ppDXBufferObjects, strides, offsets);

This topic is closed to new replies.

Advertisement