From 259a0a9aeb9d734cd51eef1f66878fb9c3708f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 7 Jan 2024 20:18:08 -0500 Subject: [PATCH] mesa: deduplicate get_index_size_shift code Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/draw.c | 20 +++----------------- src/mesa/main/draw.h | 14 ++++++++++++++ src/mesa/main/glthread_draw.c | 8 +------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c index f97f70e801d..0ceb3c496ce 100644 --- a/src/mesa/main/draw.c +++ b/src/mesa/main/draw.c @@ -1018,20 +1018,6 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao, } -static inline unsigned -get_index_size_shift(GLenum type) -{ - /* The type is already validated, so use a fast conversion. - * - * GL_UNSIGNED_BYTE - GL_UNSIGNED_BYTE = 0 - * GL_UNSIGNED_SHORT - GL_UNSIGNED_BYTE = 2 - * GL_UNSIGNED_INT - GL_UNSIGNED_BYTE = 4 - * - * Divide by 2 to get 0,1,2. - */ - return (type - GL_UNSIGNED_BYTE) >> 1; -} - /** * Examine the array's data for NaNs, etc. * For debug purposes; not normally used. @@ -1620,7 +1606,7 @@ _mesa_validated_drawrangeelements(struct gl_context *ctx, assert(end == ~0u); } - unsigned index_size_shift = get_index_size_shift(type); + unsigned index_size_shift = _mesa_get_index_size_shift(type); if (index_bo) { if (!indices_aligned(index_size_shift, indices)) @@ -2018,7 +2004,7 @@ _mesa_validated_multidrawelements(struct gl_context *ctx, if (primcount == 0) return; - unsigned index_size_shift = get_index_size_shift(type); + unsigned index_size_shift = _mesa_get_index_size_shift(type); min_index_ptr = (uintptr_t) indices[0]; max_index_ptr = 0; @@ -2531,7 +2517,7 @@ _mesa_MultiDrawElementsIndirect(GLenum mode, GLenum type, !_mesa_validate_DrawElements(ctx, mode, 1, type))) return; - unsigned index_size_shift = get_index_size_shift(type); + unsigned index_size_shift = _mesa_get_index_size_shift(type); struct pipe_draw_info info; info.mode = mode; diff --git a/src/mesa/main/draw.h b/src/mesa/main/draw.h index a0a1a0d2299..39cfb70ff89 100644 --- a/src/mesa/main/draw.h +++ b/src/mesa/main/draw.h @@ -100,6 +100,20 @@ _mesa_bitmap(struct gl_context *ctx, GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap, struct pipe_resource *tex); +static inline unsigned +_mesa_get_index_size_shift(GLenum type) +{ + /* The type is already validated, so use a fast conversion. + * + * GL_UNSIGNED_BYTE - GL_UNSIGNED_BYTE = 0 + * GL_UNSIGNED_SHORT - GL_UNSIGNED_BYTE = 2 + * GL_UNSIGNED_INT - GL_UNSIGNED_BYTE = 4 + * + * Divide by 2 to get 0,1,2. + */ + return (type - GL_UNSIGNED_BYTE) >> 1; +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/mesa/main/glthread_draw.c b/src/mesa/main/glthread_draw.c index cde43be7b35..8f393690cec 100644 --- a/src/mesa/main/glthread_draw.c +++ b/src/mesa/main/glthread_draw.c @@ -37,13 +37,7 @@ static inline unsigned get_index_size(GLenum type) { - /* GL_UNSIGNED_BYTE - GL_UNSIGNED_BYTE = 0 - * GL_UNSIGNED_SHORT - GL_UNSIGNED_BYTE = 2 - * GL_UNSIGNED_INT - GL_UNSIGNED_BYTE = 4 - * - * Divide by 2 to get n=0,1,2, then the index size is: 1 << n - */ - return 1 << ((type - GL_UNSIGNED_BYTE) >> 1); + return 1 << _mesa_get_index_size_shift(type); } static inline bool