@@ -385,7 +385,7 @@ struct decimation_info
385385 * @brief The bilinear contribution of the N weights that are interpolated for each texel.
386386 * Value is between 0 and 1, stored transposed to improve vectorization.
387387 */
388- alignas (ASTCENC_VECALIGN) float texel_weight_contribs_float_tr[4 ][BLOCK_MAX_TEXELS];
388+ ASTCENC_ALIGNAS float texel_weight_contribs_float_tr[4 ][BLOCK_MAX_TEXELS];
389389
390390 /* * @brief The number of texels that each stored weight contributes to. */
391391 uint8_t weight_texel_count[BLOCK_MAX_WEIGHTS];
@@ -400,7 +400,7 @@ struct decimation_info
400400 * @brief The bilinear contribution to the N texels that use each weight.
401401 * Value is between 0 and 1, stored transposed to improve vectorization.
402402 */
403- alignas (ASTCENC_VECALIGN) float weights_texel_contribs_tr[BLOCK_MAX_TEXELS][BLOCK_MAX_WEIGHTS];
403+ ASTCENC_ALIGNAS float weights_texel_contribs_tr[BLOCK_MAX_TEXELS][BLOCK_MAX_WEIGHTS];
404404
405405 /* *
406406 * @brief The bilinear contribution to the Nth texel that uses each weight.
@@ -580,7 +580,7 @@ struct block_size_descriptor
580580 decimation_mode decimation_modes[WEIGHTS_MAX_DECIMATION_MODES];
581581
582582 /* * @brief The active decimation tables, stored in low indices. */
583- alignas (ASTCENC_VECALIGN) decimation_info decimation_tables[WEIGHTS_MAX_DECIMATION_MODES];
583+ ASTCENC_ALIGNAS decimation_info decimation_tables[WEIGHTS_MAX_DECIMATION_MODES];
584584
585585 /* * @brief The packed block mode array index, or @c BLOCK_BAD_BLOCK_MODE if not active. */
586586 uint16_t block_mode_packed_index[WEIGHTS_MAX_BLOCK_MODES];
@@ -740,16 +740,16 @@ struct block_size_descriptor
740740struct image_block
741741{
742742 /* * @brief The input (compress) or output (decompress) data for the red color component. */
743- alignas (ASTCENC_VECALIGN) float data_r[BLOCK_MAX_TEXELS];
743+ ASTCENC_ALIGNAS float data_r[BLOCK_MAX_TEXELS];
744744
745745 /* * @brief The input (compress) or output (decompress) data for the green color component. */
746- alignas (ASTCENC_VECALIGN) float data_g[BLOCK_MAX_TEXELS];
746+ ASTCENC_ALIGNAS float data_g[BLOCK_MAX_TEXELS];
747747
748748 /* * @brief The input (compress) or output (decompress) data for the blue color component. */
749- alignas (ASTCENC_VECALIGN) float data_b[BLOCK_MAX_TEXELS];
749+ ASTCENC_ALIGNAS float data_b[BLOCK_MAX_TEXELS];
750750
751751 /* * @brief The input (compress) or output (decompress) data for the alpha color component. */
752- alignas (ASTCENC_VECALIGN) float data_a[BLOCK_MAX_TEXELS];
752+ ASTCENC_ALIGNAS float data_a[BLOCK_MAX_TEXELS];
753753
754754 /* * @brief The number of texels in the block. */
755755 uint8_t texel_count;
@@ -901,10 +901,10 @@ struct endpoints_and_weights
901901 endpoints ep;
902902
903903 /* * @brief The ideal weight for each texel; may be undecimated or decimated. */
904- alignas (ASTCENC_VECALIGN) float weights[BLOCK_MAX_TEXELS];
904+ ASTCENC_ALIGNAS float weights[BLOCK_MAX_TEXELS];
905905
906906 /* * @brief The ideal weight error scaling for each texel; may be undecimated or decimated. */
907- alignas (ASTCENC_VECALIGN) float weight_error_scale[BLOCK_MAX_TEXELS];
907+ ASTCENC_ALIGNAS float weight_error_scale[BLOCK_MAX_TEXELS];
908908};
909909
910910/* *
@@ -934,7 +934,7 @@ struct encoding_choice_errors
934934/* *
935935 * @brief Preallocated working buffers, allocated per thread during context creation.
936936 */
937- struct alignas (ASTCENC_VECALIGN) compression_working_buffers
937+ struct ASTCENC_ALIGNAS compression_working_buffers
938938{
939939 /* * @brief Ideal endpoints and weights for plane 1. */
940940 endpoints_and_weights ei1;
@@ -950,7 +950,7 @@ struct alignas(ASTCENC_VECALIGN) compression_working_buffers
950950 *
951951 * For two planes, second plane starts at @c WEIGHTS_PLANE2_OFFSET offsets.
952952 */
953- alignas (ASTCENC_VECALIGN) float dec_weights_ideal[WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
953+ ASTCENC_ALIGNAS float dec_weights_ideal[WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
954954
955955 /* *
956956 * @brief Decimated quantized weight values in the unquantized 0-64 range.
@@ -960,7 +960,7 @@ struct alignas(ASTCENC_VECALIGN) compression_working_buffers
960960 uint8_t dec_weights_uquant[WEIGHTS_MAX_BLOCK_MODES * BLOCK_MAX_WEIGHTS];
961961
962962 /* * @brief Error of the best encoding combination for each block mode. */
963- alignas (ASTCENC_VECALIGN) float errors_of_best_combination[WEIGHTS_MAX_BLOCK_MODES];
963+ ASTCENC_ALIGNAS float errors_of_best_combination[WEIGHTS_MAX_BLOCK_MODES];
964964
965965 /* * @brief The best color quant for each block mode. */
966966 uint8_t best_quant_levels[WEIGHTS_MAX_BLOCK_MODES];
@@ -2173,10 +2173,11 @@ Platform-specific functions.
21732173/* *
21742174 * @brief Allocate an aligned memory buffer.
21752175 *
2176- * Allocated memory must be freed by aligned_free;
2176+ * Allocated memory must be freed by aligned_free.
21772177 *
21782178 * @param size The desired buffer size.
2179- * @param align The desired buffer alignment; must be 2^N.
2179+ * @param align The desired buffer alignment; must be 2^N, may be increased
2180+ * by the implementation to a minimum allowable alignment.
21802181 *
21812182 * @return The memory buffer pointer or nullptr on allocation failure.
21822183 */
@@ -2186,10 +2187,14 @@ T* aligned_malloc(size_t size, size_t align)
21862187 void * ptr;
21872188 int error = 0 ;
21882189
2190+ // Don't allow this to under-align a type
2191+ size_t min_align = astc::max (alignof (T), sizeof (void *));
2192+ size_t real_align = astc::max (min_align, align);
2193+
21892194#if defined(_WIN32)
2190- ptr = _aligned_malloc (size, align );
2195+ ptr = _aligned_malloc (size, real_align );
21912196#else
2192- error = posix_memalign (&ptr, align , size);
2197+ error = posix_memalign (&ptr, real_align , size);
21932198#endif
21942199
21952200 if (error || (!ptr))
0 commit comments