Mesa (master): mesa: sort and tightly pack STATE_* enums to generate better switch code

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 21 22:16:31 UTC 2021


Module: Mesa
Branch: master
Commit: 23729a783996545ff2e56605f7c025a36ac8ba35
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=23729a783996545ff2e56605f7c025a36ac8ba35

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sat Dec 12 13:20:20 2020 -0500

mesa: sort and tightly pack STATE_* enums to generate better switch code

The enums are sorted by their occurence in fetch_state.

Reviewed-by: Zoltán Böszörményi <zboszor at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8183>

---

 src/mesa/program/prog_statevars.h | 74 ++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 36 deletions(-)

diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
index 43e7516dcec..ae1acf81d62 100644
--- a/src/mesa/program/prog_statevars.h
+++ b/src/mesa/program/prog_statevars.h
@@ -53,7 +53,7 @@ struct gl_program_parameter_list;
 typedef enum gl_state_index_ {
    STATE_NOT_STATE_VAR = 0,
 
-   STATE_MATERIAL = 100,  /* start at 100 so small ints are seen as ints */
+   STATE_MATERIAL,
 
    STATE_LIGHT,         /* One gl_light attribute. */
    STATE_LIGHT_ARRAY, /* Multiple gl_light attributes loaded at once. */
@@ -62,6 +62,7 @@ typedef enum gl_state_index_ {
    STATE_LIGHTPROD,
 
    STATE_TEXGEN,
+   STATE_TEXENV_COLOR,
 
    STATE_FOG_COLOR,
    STATE_FOG_PARAMS,
@@ -96,52 +97,23 @@ typedef enum gl_state_index_ {
    STATE_PROGRAM_MATRIX_TRANSPOSE,
    STATE_PROGRAM_MATRIX_INVTRANS,
 
-   /* These 8 enums must be in the same order as the gl_light union members,
-    * which should also match the order of gl_LightSource members.
-    */
-   STATE_AMBIENT,
-   STATE_DIFFUSE,
-   STATE_SPECULAR,
-   STATE_POSITION,       /**< xyzw = position */
-   STATE_HALF_VECTOR,
-   STATE_SPOT_DIRECTION, /**< xyz = direction, w = cos(cutoff) */
-   STATE_ATTENUATION,    /**< xyz = attenuation, w = spot exponent */
-   STATE_SPOT_CUTOFF,    /**< x = cutoff, yzw = undefined */
-
-   STATE_EMISSION,
-   STATE_SHININESS,
-
-   /* These 8 enums must be in the same order as the memory layout of
-    * gl_fixedfunc_texture_unit::EyePlane/ObjectPlane.
-    */
-   STATE_TEXGEN_EYE_S,
-   STATE_TEXGEN_EYE_T,
-   STATE_TEXGEN_EYE_R,
-   STATE_TEXGEN_EYE_Q,
-   STATE_TEXGEN_OBJECT_S,
-   STATE_TEXGEN_OBJECT_T,
-   STATE_TEXGEN_OBJECT_R,
-   STATE_TEXGEN_OBJECT_Q,
-
-   STATE_TEXENV_COLOR,
-
    STATE_NUM_SAMPLES,    /* An integer, not a float like the other state vars */
 
    STATE_DEPTH_RANGE,
 
-   STATE_VERTEX_PROGRAM_ENV,
-   STATE_VERTEX_PROGRAM_ENV_ARRAY,
-   STATE_VERTEX_PROGRAM_LOCAL,
-   STATE_VERTEX_PROGRAM_LOCAL_ARRAY,
    STATE_FRAGMENT_PROGRAM_ENV,
    STATE_FRAGMENT_PROGRAM_ENV_ARRAY,
    STATE_FRAGMENT_PROGRAM_LOCAL,
    STATE_FRAGMENT_PROGRAM_LOCAL_ARRAY,
+   STATE_VERTEX_PROGRAM_ENV,
+   STATE_VERTEX_PROGRAM_ENV_ARRAY,
+   STATE_VERTEX_PROGRAM_LOCAL,
+   STATE_VERTEX_PROGRAM_LOCAL_ARRAY,
 
+   STATE_NORMAL_SCALE_EYESPACE,
    STATE_CURRENT_ATTRIB,        /* ctx->Current vertex attrib value */
    STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED,        /* ctx->Current vertex attrib value after passthrough vertex processing */
    STATE_NORMAL_SCALE,
-   STATE_NORMAL_SCALE_EYESPACE,
    STATE_FOG_PARAMS_OPTIMIZED,  /* for faster fog calc */
    STATE_POINT_SIZE_CLAMPED,    /* includes implementation dependent size clamp */
    STATE_LIGHT_SPOT_DIR_NORMALIZED,   /* pre-normalized spot dir */
@@ -163,7 +135,37 @@ typedef enum gl_state_index_ {
    STATE_ALPHA_REF,        /* alpha-test reference value */
    STATE_CLIP_INTERNAL,    /* similar to STATE_CLIPPLANE, but in clip-space */
 
-   STATE_INTERNAL_DRIVER	/* first available state index for drivers (must be last) */
+   STATE_INTERNAL_DRIVER,	/* first available state index for drivers (must be last) */
+
+
+   /** All enums below don't occur in state[0]. **/
+
+   /* These 8 enums must be in the same order as the gl_light union members,
+    * which should also match the order of gl_LightSource members.
+    */
+   STATE_AMBIENT,
+   STATE_DIFFUSE,
+   STATE_SPECULAR,
+   STATE_POSITION,       /**< xyzw = position */
+   STATE_HALF_VECTOR,
+   STATE_SPOT_DIRECTION, /**< xyz = direction, w = cos(cutoff) */
+   STATE_ATTENUATION,    /**< xyz = attenuation, w = spot exponent */
+   STATE_SPOT_CUTOFF,    /**< x = cutoff, yzw = undefined */
+
+   STATE_EMISSION,
+   STATE_SHININESS,
+
+   /* These 8 enums must be in the same order as the memory layout of
+    * gl_fixedfunc_texture_unit::EyePlane/ObjectPlane.
+    */
+   STATE_TEXGEN_EYE_S,
+   STATE_TEXGEN_EYE_T,
+   STATE_TEXGEN_EYE_R,
+   STATE_TEXGEN_EYE_Q,
+   STATE_TEXGEN_OBJECT_S,
+   STATE_TEXGEN_OBJECT_T,
+   STATE_TEXGEN_OBJECT_R,
+   STATE_TEXGEN_OBJECT_Q,
 } gl_state_index;
 
 



More information about the mesa-commit mailing list