im having trouble with one constantbuffer:

struct CameraConstData
{
urd::Matrix projection; // 64 ( 16 floats)
urd::Matrix view;       // 64 ( 16 floats)
urd::Vec3 viewPosition; // 12 ( 3 floats)
urd::Vec3 viewDir;      // 12 ( 3 floats)

// 104 bytes (26 * 4)
float offset[26];
};


inside the shader its defined like:

// desc heap cbv
cbuffer CameraConstBuffer : register(b0)
{
float4x4 projectionMatrix;
float4x4 viewMatrix;
float3 viewPos;
float3 viewDir;

}


now viewdir is always filled with wrong buffer indices.

viewDir.x is the passed y value viewDir.y is the passed z value viewDir.z is 0.0

checked it in the shader like:

float3 vpos = normalize(float4(viewDir, 0.0)).xyz;
//float value = vpos.x; // uses the passed y value
//float value = vpos.y; // uses the passed z value
color = float4(vpos, 1.0);


GPU Debugging shows that the constant buffer looks fine:

i checked the vectors against the cpu side and they match.

• @anthom This solves the problem but is more of a workaround than a solution. The root of the problem is that HLSL default packing is not the same as C++ default packing. Most C++ compilers provide a mechanism to change packing, such as #pragma pack(16). See also this question. – MooseBoys Sep 23 '15 at 22:27