Use static assert in Clay engine to ensure struct alignment

This commit is contained in:
Sergey Sharybin 2017-05-12 11:56:19 +02:00
parent 20881a7794
commit 3a5501d168
2 changed files with 4 additions and 0 deletions

View File

@ -674,6 +674,9 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
# define BLI_STATIC_ASSERT(a, msg)
#endif
#define BLI_STATIC_ASSERT_ALIGN(st, align) \
BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned")
/* hints for branch prediction, only use in code that runs a _lot_ where */
#ifdef __GNUC__
# define LIKELY(x) __builtin_expect(!!(x), 1)

View File

@ -57,6 +57,7 @@ typedef struct CLAY_UBO_Material {
float matcap_rot[2];
float pad[2]; /* ensure 16 bytes alignement */
} CLAY_UBO_Material; /* 48 bytes */
BLI_STATIC_ASSERT_ALIGN(CLAY_UBO_Material, 16);
#define MAX_CLAY_MAT 512 /* 512 = 9 bit material id */