How can I have constant buffer with array of floats?

Hi all,

I’m trying to set a constant buffer which contains an array of floats (the buffer is intended for holding weights of filter).

In the hlsl file I defined the constant buffer as follows:

cbuffer FilterParameters
{
float g_aFilterWeight[7];
};

When doing this, the array will never hold the values I inserted in the C++. why ?

In order to check it, I changed it as follows:

cbuffer FilterParameters
{
float g_aFilterWeight0;
float g_aFilterWeight1;
float g_aFilterWeight2;
float g_aFilterWeight3;
float g_aFilterWeight4;
float g_aFilterWeight5;
float g_aFilterWeight6;
};

In this case, the variables holds exactly the values I set through the c++ program, and everithing is ok.

Why the “array” form doesn’t work??

DX is a bit annoying in this regard, it allocates constants in multiples of float4s. If you use the effects framework it does the padding for you.

The correct syntax should be:

cbuffer FilterParameters
{
vector <float,7> g_aFilterWeight;
};