compiler/glsl_types: add glsl_get_word_size_align_bytes

this alignment matches what nir_lower_scratch_to_var wants. this is not
correctness bearing but it mitigates stats regressions.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32529>
This commit is contained in:
Alyssa Rosenzweig 2024-12-11 11:56:19 -05:00 committed by Marge Bot
parent bd89279dd4
commit 923e6361d1
2 changed files with 55 additions and 0 deletions

View file

@ -3769,6 +3769,60 @@ glsl_get_natural_size_align_bytes(const glsl_type *type,
}
}
/**
* Returns a byte size/alignment for a type where each array element or struct
* field is aligned to 16 bytes.
*/
void
glsl_get_word_size_align_bytes(const glsl_type *type,
unsigned *size, unsigned *align)
{
switch (type->base_type) {
case GLSL_TYPE_BOOL:
/* We special-case Booleans to 32 bits to not cause heartburn for
* drivers that suddenly get an 8-bit load.
*/
*size = 4 * glsl_get_components(type);
*align = 4;
break;
case GLSL_TYPE_UINT8:
case GLSL_TYPE_INT8:
case GLSL_TYPE_UINT16:
case GLSL_TYPE_INT16:
case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64: {
unsigned N = glsl_get_bit_size(type) / 8;
*size = 16 * (type->matrix_columns - 1) + N * type->vector_elements;
*align = 4;
break;
}
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_STRUCT:
glsl_size_align_handle_array_and_structs(type,
glsl_get_word_size_align_bytes,
size, align);
break;
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE:
case GLSL_TYPE_COOPERATIVE_MATRIX:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
unreachable("type does not make sense for glsl_get_vec4_size_align_bytes()");
}
}
/**
* Returns a byte size/alignment for a type where each array element or struct
* field is aligned to 16 bytes.

View file

@ -1341,6 +1341,7 @@ void glsl_size_align_handle_array_and_structs(const glsl_type *type,
glsl_type_size_align_func size_align,
unsigned *size, unsigned *align);
void glsl_get_natural_size_align_bytes(const glsl_type *t, unsigned *size, unsigned *align);
void glsl_get_word_size_align_bytes(const glsl_type *type, unsigned *size, unsigned *align);
void glsl_get_vec4_size_align_bytes(const glsl_type *type, unsigned *size, unsigned *align);
#ifdef __cplusplus