compiler/types: Align struct type sizes to the struct alignment

Open Faith Ekstrand requested to merge gfxstrand/mesa:review/compiler-struct-align into main

This fixes an issue with OpenCL data layout in the case where we have a substruct followed by little stuff. For instance, consider the following case:

struct A {
   long l;
   int i;

struct B {
   struct A a;
   int j;

What is the offset of B::j? Previously, we didn't consider the alignment of struct A so we would place B::j at byte 12. However, throwing in the extra alignment, the presence of A::l causes the alignment of struct A to be 8 and B::j is at byte 16.

This solution is a bit scorched-earth as it applies to all explicit type layouts even if not strictly necessary. However, this restriction is imposed by std140 and std430 so it's probably not onerous to apply it to other things like driver-laid-out shared variables.

Merge request reports