Hi!
I have the following HLSL shader code:
struct Light
{
float4 positionWS;
//-------------------------- ( 16 bytes )
float4 directionWS;
//-------------------------- ( 16 bytes )
float4 positionVS;
//-------------------------- ( 16 bytes )
float4 directionVS;
//-------------------------- ( 16 bytes )
float4 color;
//-------------------------- ( 16 bytes )
float spotlightAngle;
float range;
float intensity;
uint type;
//-------------------------- ( 16 bytes )
bool enabled;
float3 padding1;
//-------------------------- ( 16 bytes )
//-------------------------- ( 16 * 7 = 112 bytes )
};
layout(set=0,binding=0) cbuffer cbPerRenderOperationData : register(b0)
{
Light gLights[MAX_LIGHT_COUNT];
};
MAX_LIGHT_COUNT is 16. On DX11/12 the code gets compiled to D3D bytecode, and on Vulkan I compile it to SPIR-V using the HLSL frontend for glslang. On DX everything works fine. Looking at the buffer in RenderDoc shows me that it occupies 112 * 16 = 1792 bytes as I would expect. However, on Vulkan only the first light is valid. The rest are garbage. RenderDoc shows that the uniform buffer occupies 2048 bytes rather than 1792, which suggests to me that the size of Light in SPIR-V is 128 and not 112.
Is there some power-of-two requirement in SPIR-V I am not aware of? So far I have just made sure every element in an array is a multiple of 16 bytes. Is that not enough?
Thanks!