aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2017-06-10 22:34:34 +0200
committerMarek Olšák <[email protected]>2017-06-22 01:51:02 +0200
commit222a910a9bff5f4138794e0ef69775a1acdad35a (patch)
treefd8ca19eadf7bbca26cd6dd60fbabe7d604baeac /src/mesa/state_tracker
parent39ab9fb36c8c41ed06cd8f272d17285c6c5cd56b (diff)
st/mesa: optimize sampler state translation code
Reviewed-by: Timothy Arceri <[email protected]> Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom_sampler.c68
1 files changed, 20 insertions, 48 deletions
diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 1ce5769c8cd..2481a72a55b 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -58,71 +58,43 @@
static GLuint
gl_wrap_xlate(GLenum wrap)
{
- switch (wrap) {
- case GL_REPEAT:
- return PIPE_TEX_WRAP_REPEAT;
- case GL_CLAMP:
- return PIPE_TEX_WRAP_CLAMP;
- case GL_CLAMP_TO_EDGE:
- return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- case GL_CLAMP_TO_BORDER:
- return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
- case GL_MIRRORED_REPEAT:
- return PIPE_TEX_WRAP_MIRROR_REPEAT;
- case GL_MIRROR_CLAMP_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP;
- case GL_MIRROR_CLAMP_TO_EDGE_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
- case GL_MIRROR_CLAMP_TO_BORDER_EXT:
- return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
- default:
- assert(0);
- return 0;
- }
+ /* Take advantage of how the enums are defined. */
+ static const unsigned table[32] = {
+ [GL_REPEAT & 0x1f] = PIPE_TEX_WRAP_REPEAT,
+ [GL_CLAMP & 0x1f] = PIPE_TEX_WRAP_CLAMP,
+ [GL_CLAMP_TO_EDGE & 0x1f] = PIPE_TEX_WRAP_CLAMP_TO_EDGE,
+ [GL_CLAMP_TO_BORDER & 0x1f] = PIPE_TEX_WRAP_CLAMP_TO_BORDER,
+ [GL_MIRRORED_REPEAT & 0x1f] = PIPE_TEX_WRAP_MIRROR_REPEAT,
+ [GL_MIRROR_CLAMP_EXT & 0x1f] = PIPE_TEX_WRAP_MIRROR_CLAMP,
+ [GL_MIRROR_CLAMP_TO_EDGE & 0x1f] = PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE,
+ [GL_MIRROR_CLAMP_TO_BORDER_EXT & 0x1f] = PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER,
+ };
+
+ return table[wrap & 0x1f];
}
static GLuint
gl_filter_to_mip_filter(GLenum filter)
{
- switch (filter) {
- case GL_NEAREST:
- case GL_LINEAR:
+ /* Take advantage of how the enums are defined. */
+ if (filter <= GL_LINEAR)
return PIPE_TEX_MIPFILTER_NONE;
-
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_NEAREST:
+ if (filter <= GL_LINEAR_MIPMAP_NEAREST)
return PIPE_TEX_MIPFILTER_NEAREST;
- case GL_NEAREST_MIPMAP_LINEAR:
- case GL_LINEAR_MIPMAP_LINEAR:
- return PIPE_TEX_MIPFILTER_LINEAR;
-
- default:
- assert(0);
- return PIPE_TEX_MIPFILTER_NONE;
- }
+ return PIPE_TEX_MIPFILTER_LINEAR;
}
static GLuint
gl_filter_to_img_filter(GLenum filter)
{
- switch (filter) {
- case GL_NEAREST:
- case GL_NEAREST_MIPMAP_NEAREST:
- case GL_NEAREST_MIPMAP_LINEAR:
- return PIPE_TEX_FILTER_NEAREST;
-
- case GL_LINEAR:
- case GL_LINEAR_MIPMAP_NEAREST:
- case GL_LINEAR_MIPMAP_LINEAR:
+ /* Take advantage of how the enums are defined. */
+ if (filter & 1)
return PIPE_TEX_FILTER_LINEAR;
- default:
- assert(0);
- return PIPE_TEX_FILTER_NEAREST;
- }
+ return PIPE_TEX_FILTER_NEAREST;
}