aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2020-03-03 15:08:09 -0500
committerMarek Olšák <[email protected]>2020-03-04 19:54:43 -0500
commit7700ac3d80ae70d00e3cca52b6ea3d00122c7893 (patch)
treebb09bb49e2e81204a5f12fd26ebeb34a208e1df6
parent450152f8d85f9f54498ea5116561f2aefe7378dc (diff)
mesa: optimize get_index_size
Reviewed-by: Ian Romanick <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4052>
-rw-r--r--src/mesa/main/draw.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index b39d200c098..99a5afebd27 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -107,22 +107,15 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
static inline void
get_index_size(GLenum type, struct _mesa_index_buffer *ib)
{
- switch (type) {
- case GL_UNSIGNED_INT:
- ib->index_size_shift = 2;
- break;
- case GL_UNSIGNED_SHORT:
- ib->index_size_shift = 1;
- break;
- case GL_UNSIGNED_BYTE:
- ib->index_size_shift = 0;
- break;
- default:
- assert(!"unsupported index data type");
- /* In case assert is turned off */
- ib->index_size_shift = 0;
- break;
- }
+ /* 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.
+ */
+ ib->index_size_shift = (type - GL_UNSIGNED_BYTE) >> 1;
}
/**