From fc7842952342fd1281526940fe999fe6363f3b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 16 Jan 2021 07:16:08 -0500 Subject: [PATCH] mesa: optimize draw index type checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Zoltán Böszörményi Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/draw_validate.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/mesa/main/draw_validate.c b/src/mesa/main/draw_validate.c index 09ed37ec5be..84897bd5dbc 100644 --- a/src/mesa/main/draw_validate.c +++ b/src/mesa/main/draw_validate.c @@ -636,17 +636,21 @@ _mesa_valid_prim_mode(struct gl_context *ctx, GLenum mode, const char *name) static bool valid_elements_type(struct gl_context *ctx, GLenum type, const char *name) { - switch (type) { - case GL_UNSIGNED_BYTE: - case GL_UNSIGNED_SHORT: - case GL_UNSIGNED_INT: - return true; - - default: + /* GL_UNSIGNED_BYTE = 0x1401 + * GL_UNSIGNED_SHORT = 0x1403 + * GL_UNSIGNED_INT = 0x1405 + * + * The trick is that bit 1 and bit 2 mean USHORT and UINT, respectively. + * After clearing those two bits (with ~6), we should get UBYTE. + * Both bits can't be set, because the enum would be greater than UINT. + */ + if (!(type <= GL_UNSIGNED_INT && (type & ~6) == GL_UNSIGNED_BYTE)) { _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", name, _mesa_enum_to_string(type)); return false; } + + return true; } static bool