I'm currently reading the book “Introduction to 3D game programming with DirectX 12” and got a little confused with HLSL on the Lighting chapter. So, I know about HLSL packing rules, but after I created the constant buffer like this:
cbuffer cbPass : register(b2)
{
// not perfectly padded stuff.
int iLightCount;
Light vLights[MAX_LIGHTS];
}
my vLights array had only the first float3 member of the Light struct copied right, other members (of the Light struct) had invalid values. After that, I thought that maybe the issue is in the padding and changed my cbuffer to this:
cbuffer cbPass : register(b2)
{
// perfectly padded stuff.
int iLightCount;
float3 pad2;
Light vLights[MAX_LIGHTS];
}
I also changed my C++ Light struct accordingly and now all members of the Light struct were copied correctly. I'm confused, why only the first 3-4 bytes of the struct was copied correctly without perfect padding.