From c7ba0fb04dbaa6896741b6aef1130166127a40f0 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 24 Jul 2021 17:45:38 -0400 Subject: [PATCH] agx: Add agx_format_shift routine Required to calculate alignments for vertex buffers correctly. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index fe5bc42..6e8b14a 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -118,6 +118,39 @@ enum agx_format { AGX_NUM_FORMATS, }; +/* Returns the number of bits at the bottom of the address required to be zero. + * That is, returns the base-2 logarithm of the minimum alignment for an + * agx_format, where the minimum alignment is 2^n where n is the result of this + * function. The offset argument to device_load is left-shifted by this amount + * in the hardware */ + +static inline unsigned +agx_format_shift(enum agx_format format) +{ + switch (format) { + case AGX_FORMAT_I8: + case AGX_FORMAT_U8NORM: + case AGX_FORMAT_S8NORM: + case AGX_FORMAT_SRGBA8: + return 0; + + case AGX_FORMAT_I16: + case AGX_FORMAT_F16: + case AGX_FORMAT_U16NORM: + case AGX_FORMAT_S16NORM: + return 1; + + case AGX_FORMAT_I32: + case AGX_FORMAT_RGB10A2: + case AGX_FORMAT_RG11B10F: + case AGX_FORMAT_RGB9E5: + return 2; + + default: + unreachable("invalid format"); + } +} + struct agx_attribute { uint32_t divisor; -- 2.7.4