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??
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??

#1
Posted 05/26/2010 09:22 AM   
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??
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??

#2
Posted 05/26/2010 09:22 AM   
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.
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.

#3
Posted 06/24/2010 01:42 PM   
The correct syntax should be:

cbuffer FilterParameters
{
vector <float,7> g_aFilterWeight;
};
The correct syntax should be:



cbuffer FilterParameters

{

vector <float,7> g_aFilterWeight;

};

#4
Posted 09/14/2011 09:29 PM   
Scroll To Top