[Mesa-dev] [PATCH 15/20] mesa, glsl, nir: reduce gl_state_index size to 2 bytes

Marek Olšák maraeo at gmail.com
Tue Nov 21 18:01:57 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

Let's use the new gl_state_index16 type everywhere and remove
the typecasts.

This helps reduce the size of gl_program_parameter.
---
 src/compiler/glsl/ir.h                         |  2 +-
 src/compiler/glsl/shader_cache.cpp             |  2 +-
 src/compiler/glsl/standalone_scaffolding.cpp   |  4 ++--
 src/compiler/glsl/standalone_scaffolding.h     |  4 ++--
 src/compiler/nir/nir.h                         | 10 +++++-----
 src/compiler/nir/nir_lower_drawpixels.c        |  3 ++-
 src/compiler/shader_enums.h                    |  2 ++
 src/mesa/drivers/dri/i965/brw_link.cpp         |  3 +--
 src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_program.c        |  2 +-
 src/mesa/drivers/dri/r200/r200_vertprog.c      |  2 +-
 src/mesa/main/ffvertex_prog.c                  |  2 +-
 src/mesa/main/tests/program_state_string.cpp   |  2 +-
 src/mesa/main/uniforms.h                       |  2 +-
 src/mesa/program/ir_to_mesa.cpp                |  2 +-
 src/mesa/program/prog_parameter.c              | 10 +++++-----
 src/mesa/program/prog_parameter.h              |  6 +++---
 src/mesa/program/prog_statevars.c              |  6 +++---
 src/mesa/program/prog_statevars.h              |  5 ++---
 src/mesa/program/program_parse.y               | 18 +++++++++---------
 src/mesa/program/programopt.c                  |  8 ++++----
 src/mesa/state_tracker/st_atifs_to_tgsi.c      |  4 ++--
 src/mesa/state_tracker/st_glsl_to_nir.cpp      |  6 +++---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp     |  8 ++++----
 src/mesa/state_tracker/st_mesa_to_tgsi.c       |  2 +-
 src/mesa/state_tracker/st_nir_lower_builtin.c  |  4 ++--
 src/mesa/state_tracker/st_program.c            |  6 +++---
 27 files changed, 64 insertions(+), 63 deletions(-)

diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index d5a255e..b849c93 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -390,21 +390,21 @@ enum ir_depth_layout {
  */
 const char*
 depth_layout_string(ir_depth_layout layout);
 
 /**
  * Description of built-in state associated with a uniform
  *
  * \sa ir_variable::state_slots
  */
 struct ir_state_slot {
-   int tokens[5];
+   gl_state_index16 tokens[5];
    int swizzle;
 };
 
 
 /**
  * Get the string value for an interpolation qualifier
  *
  * \return The string that would be used in a shader to specify \c
  * mode will be returned.
  *
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index da1c72d..7590160 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -991,21 +991,21 @@ write_shader_parameters(struct blob *metadata,
    blob_write_bytes(metadata, params->ParameterValues,
                     sizeof(gl_constant_value) * 4 * params->NumParameters);
 
    blob_write_uint32(metadata, params->StateFlags);
 }
 
 static void
 read_shader_parameters(struct blob_reader *metadata,
                        struct gl_program_parameter_list *params)
 {
-   gl_state_index state_indexes[STATE_LENGTH];
+   gl_state_index16 state_indexes[STATE_LENGTH];
    uint32_t i = 0;
    uint32_t num_parameters = blob_read_uint32(metadata);
 
    _mesa_reserve_parameter_storage(params, num_parameters);
    while (i < num_parameters) {
       gl_register_file type = (gl_register_file) blob_read_uint32(metadata);
       const char *name = blob_read_string(metadata);
       unsigned size = blob_read_uint32(metadata);
       unsigned data_type = blob_read_uint32(metadata);
       blob_copy_bytes(metadata, (uint8_t *) state_indexes,
diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp
index 34065a9..caaddc0 100644
--- a/src/compiler/glsl/standalone_scaffolding.cpp
+++ b/src/compiler/glsl/standalone_scaffolding.cpp
@@ -93,27 +93,27 @@ _mesa_new_shader(GLuint name, gl_shader_stage stage)
    shader = rzalloc(NULL, struct gl_shader);
    if (shader) {
       shader->Stage = stage;
       shader->Name = name;
       shader->RefCount = 1;
    }
    return shader;
 }
 
 GLbitfield
-_mesa_program_state_flags(UNUSED const gl_state_index state[STATE_LENGTH])
+_mesa_program_state_flags(UNUSED const gl_state_index16 state[STATE_LENGTH])
 {
    return 0;
 }
 
 char *
-_mesa_program_state_string(UNUSED const gl_state_index state[STATE_LENGTH])
+_mesa_program_state_string(UNUSED const gl_state_index16 state[STATE_LENGTH])
 {
    return NULL;
 }
 
 void
 _mesa_delete_shader(struct gl_context *, struct gl_shader *sh)
 {
    free((void *)sh->Source);
    free(sh->Label);
    ralloc_free(sh);
diff --git a/src/compiler/glsl/standalone_scaffolding.h b/src/compiler/glsl/standalone_scaffolding.h
index 7532d08..c8d9059 100644
--- a/src/compiler/glsl/standalone_scaffolding.h
+++ b/src/compiler/glsl/standalone_scaffolding.h
@@ -62,25 +62,25 @@ _mesa_delete_linked_shader(struct gl_context *ctx,
 
 extern "C" void
 _mesa_clear_shader_program_data(struct gl_context *ctx,
                                 struct gl_shader_program *);
 
 extern "C" void
 _mesa_shader_debug(struct gl_context *ctx, GLenum type, GLuint *id,
                    const char *msg);
 
 extern "C" GLbitfield
-_mesa_program_state_flags(const gl_state_index state[STATE_LENGTH]);
+_mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH]);
 
 
 extern "C" char *
-_mesa_program_state_string(const gl_state_index state[STATE_LENGTH]);
+_mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH]);
 
 static inline gl_shader_stage
 _mesa_shader_enum_to_shader_stage(GLenum v)
 {
    switch (v) {
    case GL_VERTEX_SHADER:
       return MESA_SHADER_VERTEX;
    case GL_FRAGMENT_SHADER:
       return MESA_SHADER_FRAGMENT;
    case GL_GEOMETRY_SHADER:
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index f46f614..6dddeb8 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -82,21 +82,21 @@ struct nir_function;
 struct nir_shader;
 struct nir_instr;
 
 
 /**
  * Description of built-in state associated with a uniform
  *
  * \sa nir_variable::state_slots
  */
 typedef struct {
-   int tokens[5];
+   gl_state_index16 tokens[5];
    int swizzle;
 } nir_state_slot;
 
 typedef enum {
    nir_var_shader_in       = (1 << 0),
    nir_var_shader_out      = (1 << 1),
    nir_var_global          = (1 << 2),
    nir_var_local           = (1 << 3),
    nir_var_uniform         = (1 << 4),
    nir_var_shader_storage  = (1 << 5),
@@ -2596,35 +2596,35 @@ bool nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables);
 bool nir_lower_clip_cull_distance_arrays(nir_shader *nir);
 
 void nir_lower_two_sided_color(nir_shader *shader);
 
 bool nir_lower_clamp_color_outputs(nir_shader *shader);
 
 void nir_lower_passthrough_edgeflags(nir_shader *shader);
 void nir_lower_tes_patch_vertices(nir_shader *tes, unsigned patch_vertices);
 
 typedef struct nir_lower_wpos_ytransform_options {
-   int state_tokens[5];
+   gl_state_index16 state_tokens[5];
    bool fs_coord_origin_upper_left :1;
    bool fs_coord_origin_lower_left :1;
    bool fs_coord_pixel_center_integer :1;
    bool fs_coord_pixel_center_half_integer :1;
 } nir_lower_wpos_ytransform_options;
 
 bool nir_lower_wpos_ytransform(nir_shader *shader,
                                const nir_lower_wpos_ytransform_options *options);
 bool nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading);
 
 typedef struct nir_lower_drawpixels_options {
-   int texcoord_state_tokens[5];
-   int scale_state_tokens[5];
-   int bias_state_tokens[5];
+   gl_state_index16 texcoord_state_tokens[5];
+   gl_state_index16 scale_state_tokens[5];
+   gl_state_index16 bias_state_tokens[5];
    unsigned drawpix_sampler;
    unsigned pixelmap_sampler;
    bool pixel_maps :1;
    bool scale_and_bias :1;
 } nir_lower_drawpixels_options;
 
 void nir_lower_drawpixels(nir_shader *shader,
                           const nir_lower_drawpixels_options *options);
 
 typedef struct nir_lower_bitmap_options {
diff --git a/src/compiler/nir/nir_lower_drawpixels.c b/src/compiler/nir/nir_lower_drawpixels.c
index acec944..4d43f42 100644
--- a/src/compiler/nir/nir_lower_drawpixels.c
+++ b/src/compiler/nir/nir_lower_drawpixels.c
@@ -60,21 +60,22 @@ get_texcoord(lower_drawpixels_state *state)
                                         "gl_TexCoord");
          texcoord->data.location = VARYING_SLOT_TEX0;
       }
 
       state->texcoord = texcoord;
    }
    return nir_load_var(&state->b, state->texcoord);
 }
 
 static nir_variable *
-create_uniform(nir_shader *shader, const char *name, const int state_tokens[5])
+create_uniform(nir_shader *shader, const char *name,
+               const gl_state_index16 state_tokens[5])
 {
    nir_variable *var = nir_variable_create(shader,
                                            nir_var_uniform,
                                            glsl_vec4_type(),
                                            name);
    var->num_state_slots = 1;
    var->state_slots = ralloc_array(var, nir_state_slot, 1);
    memcpy(var->state_slots[0].tokens, state_tokens,
           sizeof(var->state_slots[0].tokens));
    return var;
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index ffe551a..be348a0 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -41,20 +41,22 @@ typedef enum
 {
    MESA_SHADER_NONE = -1,
    MESA_SHADER_VERTEX = 0,
    MESA_SHADER_TESS_CTRL = 1,
    MESA_SHADER_TESS_EVAL = 2,
    MESA_SHADER_GEOMETRY = 3,
    MESA_SHADER_FRAGMENT = 4,
    MESA_SHADER_COMPUTE = 5,
 } gl_shader_stage;
 
+typedef short gl_state_index16; /* see enum gl_state_index */
+
 const char *gl_shader_stage_name(gl_shader_stage stage);
 
 /**
  * Translate a gl_shader_stage to a short shader stage name for debug
  * printouts and error messages.
  */
 const char *_mesa_shader_stage_to_string(unsigned stage);
 
 /**
  * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index d18521e..c5b672c 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -321,22 +321,21 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
        * used for rendering.  Waiting until then to generate the parameters is
        * too late.  At that point, the values for the built-in uniforms won't
        * get sent to the shader.
        */
       nir_foreach_variable(var, &prog->nir->uniforms) {
          if (strncmp(var->name, "gl_", 3) == 0) {
             const nir_state_slot *const slots = var->state_slots;
             assert(var->state_slots != NULL);
 
             for (unsigned int i = 0; i < var->num_state_slots; i++) {
-               _mesa_add_state_reference(prog->Parameters,
-                                         (gl_state_index *)slots[i].tokens);
+               _mesa_add_state_reference(prog->Parameters, slots[i].tokens);
             }
          }
       }
    }
 
    /* The linker tries to dead code eliminate unused varying components,
     * and make sure interfaces match.  But it isn't able to do so in all
     * cases.  So, explicitly make the interfaces match by OR'ing together
     * the inputs_read/outputs_written bitfields of adjacent stages.
     */
diff --git a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp
index 9e135cb..2b421c5 100644
--- a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp
+++ b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp
@@ -33,21 +33,21 @@ brw_nir_setup_glsl_builtin_uniform(nir_variable *var,
 {
    const nir_state_slot *const slots = var->state_slots;
    assert(var->state_slots != NULL);
 
    unsigned uniform_index = var->data.driver_location / 4;
    for (unsigned int i = 0; i < var->num_state_slots; i++) {
       /* This state reference has already been setup by ir_to_mesa, but we'll
        * get the same index back here.
        */
       int index = _mesa_add_state_reference(prog->Parameters,
-					    (gl_state_index *)slots[i].tokens);
+					    slots[i].tokens);
 
       /* Add each of the unique swizzles of the element as a parameter.
        * This'll end up matching the expected layout of the
        * array/matrix/structure we're trying to fill in.
        */
       int last_swiz = -1;
       for (unsigned j = 0; j < 4; j++) {
          int swiz = GET_SWZ(slots[i].swizzle, j);
 
          /* If we hit a pair of identical swizzles, this means we've hit the
diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c
index 755d497..f2d390d 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -93,21 +93,21 @@ brw_create_nir(struct brw_context *brw,
       static const struct nir_lower_wpos_ytransform_options wpos_options = {
          .state_tokens = {STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0},
          .fs_coord_pixel_center_integer = 1,
          .fs_coord_origin_upper_left = 1,
       };
 
       bool progress = false;
       NIR_PASS(progress, nir, nir_lower_wpos_ytransform, &wpos_options);
       if (progress) {
          _mesa_add_state_reference(prog->Parameters,
-                                   (gl_state_index *) wpos_options.state_tokens);
+                                   wpos_options.state_tokens);
       }
    }
 
    NIR_PASS_V(nir, brw_nir_lower_uniforms, is_scalar);
 
    return nir;
 }
 
 void
 brw_shader_gather_info(nir_shader *nir, struct gl_program *prog)
diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c b/src/mesa/drivers/dri/r200/r200_vertprog.c
index c3606b5..8599e47 100644
--- a/src/mesa/drivers/dri/r200/r200_vertprog.c
+++ b/src/mesa/drivers/dri/r200/r200_vertprog.c
@@ -449,21 +449,21 @@ static GLboolean r200_translate_vertex_program(struct gl_context *ctx, struct r2
       /* make sure we only do this once */
        !(mesa_vp->info.outputs_written & (1 << VARYING_SLOT_POS))) {
 	 _mesa_insert_mvp_code(ctx, mesa_vp);
       }
 
    /* for fogc, can't change mesa_vp, as it would hose swtnl, and exp with
       base e isn't directly available neither. */
    if ((mesa_vp->info.outputs_written & (1 << VARYING_SLOT_FOGC)) &&
        !vp->fogpidx) {
       struct gl_program_parameter_list *paramList;
-      gl_state_index tokens[STATE_LENGTH] = { STATE_FOG_PARAMS, 0, 0, 0, 0 };
+      gl_state_index16 tokens[STATE_LENGTH] = { STATE_FOG_PARAMS, 0, 0, 0, 0 };
       paramList = mesa_vp->Parameters;
       vp->fogpidx = _mesa_add_state_reference(paramList, tokens);
    }
 
    vp->pos_end = 0;
    mesa_vp->arb.NumNativeInstructions = 0;
    if (mesa_vp->Parameters)
       mesa_vp->arb.NumNativeParameters = mesa_vp->Parameters->NumParameters;
    else
       mesa_vp->arb.NumNativeParameters = 0;
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index 3c998eb..c9c9646 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -414,21 +414,21 @@ static void release_temps( struct tnl_program *p )
 }
 
 
 static struct ureg register_param5(struct tnl_program *p,
 				   GLint s0,
 				   GLint s1,
 				   GLint s2,
 				   GLint s3,
                                    GLint s4)
 {
-   gl_state_index tokens[STATE_LENGTH];
+   gl_state_index16 tokens[STATE_LENGTH];
    GLint idx;
    tokens[0] = s0;
    tokens[1] = s1;
    tokens[2] = s2;
    tokens[3] = s3;
    tokens[4] = s4;
    idx = _mesa_add_state_reference(p->program->Parameters, tokens );
    return make_ureg(PROGRAM_STATE_VAR, idx);
 }
 
diff --git a/src/mesa/main/tests/program_state_string.cpp b/src/mesa/main/tests/program_state_string.cpp
index ddfdb49..6ec84e0 100644
--- a/src/mesa/main/tests/program_state_string.cpp
+++ b/src/mesa/main/tests/program_state_string.cpp
@@ -24,21 +24,21 @@
 #include <gtest/gtest.h>
 
 #include "GL/gl.h"
 #include "GL/glext.h"
 #include "main/compiler.h"
 
 #include "program/prog_statevars.h"
 
 TEST(program_state_string, depth_range)
 {
-   const gl_state_index state[STATE_LENGTH] = {
+   const gl_state_index16 state[STATE_LENGTH] = {
       STATE_DEPTH_RANGE
    };
 
    char *str = _mesa_program_state_string(state);
 
    ASSERT_NE((void *) 0, str);
    EXPECT_STREQ("state.depth.range", str);
 
    free(str);
 }
diff --git a/src/mesa/main/uniforms.h b/src/mesa/main/uniforms.h
index 9236db9..819cf90 100644
--- a/src/mesa/main/uniforms.h
+++ b/src/mesa/main/uniforms.h
@@ -498,21 +498,21 @@ _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
 				 char *errMsg, size_t errMsgLength);
 extern bool
 _mesa_sampler_uniforms_pipeline_are_valid(struct gl_pipeline_object *);
 
 extern void
 _mesa_flush_vertices_for_uniforms(struct gl_context *ctx,
                                   const struct gl_uniform_storage *uni);
 
 struct gl_builtin_uniform_element {
    const char *field;
-   int tokens[STATE_LENGTH];
+   gl_state_index16 tokens[STATE_LENGTH];
    int swizzle;
 };
 
 struct gl_builtin_uniform_desc {
    const char *name;
    const struct gl_builtin_uniform_element *elements;
    unsigned int num_elements;
 };
 
 #ifdef __cplusplus
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 327fd61..9e74b70 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -654,21 +654,21 @@ ir_to_mesa_visitor::visit(ir_variable *ir)
 						 this->next_temp);
 	 this->variables.push_tail(storage);
 	 this->next_temp += type_size(ir->type);
 
 	 dst = dst_reg(src_reg(PROGRAM_TEMPORARY, storage->index, NULL));
       }
 
 
       for (unsigned int i = 0; i < ir->get_num_state_slots(); i++) {
 	 int index = _mesa_add_state_reference(this->prog->Parameters,
-					       (gl_state_index *)slots[i].tokens);
+					       slots[i].tokens);
 
 	 if (storage->file == PROGRAM_STATE_VAR) {
 	    if (storage->index == -1) {
 	       storage->index = index;
 	    } else {
 	       assert(index == storage->index + (int)i);
 	    }
 	 } else {
 	    src_reg src(PROGRAM_STATE_VAR, index, NULL);
 	    src.swizzle = slots[i].swizzle;
diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index 40bc47d..d3e382c 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -225,21 +225,21 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
  * \param datatype  GL_FLOAT, GL_FLOAT_VECx, GL_INT, GL_INT_VECx or GL_NONE.
  * \param values  initial parameter value, up to 4 gl_constant_values, or NULL
  * \param state  state indexes, or NULL
  * \return  index of new parameter in the list, or -1 if error (out of mem)
  */
 GLint
 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
                     gl_register_file type, const char *name,
                     GLuint size, GLenum datatype,
                     const gl_constant_value *values,
-                    const gl_state_index state[STATE_LENGTH])
+                    const gl_state_index16 state[STATE_LENGTH])
 {
    const GLuint oldNum = paramList->NumParameters;
    const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
 
    assert(size > 0);
 
    _mesa_reserve_parameter_storage(paramList, sz4);
 
    if (!paramList->Parameters ||
        !paramList->ParameterValues) {
@@ -356,35 +356,35 @@ _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
  * Add a new state reference to the parameter list.
  * This will be used when the program contains something like this:
  *    PARAM ambient = state.material.front.ambient;
  *
  * \param paramList  the parameter list
  * \param stateTokens  an array of 5 (STATE_LENGTH) state tokens
  * \return index of the new parameter.
  */
 GLint
 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
-                          const gl_state_index stateTokens[STATE_LENGTH])
+                          const gl_state_index16 stateTokens[STATE_LENGTH])
 {
    const GLuint size = 4; /* XXX fix */
    char *name;
    GLint index;
 
    /* Check if the state reference is already in the list */
    for (index = 0; index < (GLint) paramList->NumParameters; index++) {
       if (!memcmp(paramList->Parameters[index].StateIndexes,
-                  stateTokens, STATE_LENGTH * sizeof(gl_state_index))) {
+                  stateTokens,
+                  sizeof(paramList->Parameters[index].StateIndexes))) {
          return index;
       }
    }
 
    name = _mesa_program_state_string(stateTokens);
    index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name,
-                               size, GL_NONE,
-                               NULL, (gl_state_index *) stateTokens);
+                               size, GL_NONE, NULL, stateTokens);
    paramList->StateFlags |= _mesa_program_state_flags(stateTokens);
 
    /* free name string here since we duplicated it in add_parameter() */
    free(name);
 
    return index;
 }
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index f50e99c..ce5d2cb 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -65,21 +65,21 @@ struct gl_program_parameter
    /**
     * Number of components (1..4), or more.
     * If the number of components is greater than 4,
     * this parameter is part of a larger uniform like a GLSL matrix or array.
     * The next program parameter's Size will be Size-4 of this parameter.
     */
    GLuint Size;
    /**
     * A sequence of STATE_* tokens and integers to identify GL state.
     */
-   gl_state_index StateIndexes[STATE_LENGTH];
+   gl_state_index16 StateIndexes[STATE_LENGTH];
 };
 
 
 /**
  * List of gl_program_parameter instances.
  */
 struct gl_program_parameter_list
 {
    GLuint Size;           /**< allocated size of Parameters, ParameterValues */
    GLuint NumParameters;  /**< number of parameters in arrays */
@@ -101,39 +101,39 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
 
 extern void
 _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList,
                                 unsigned reserve_slots);
 
 extern GLint
 _mesa_add_parameter(struct gl_program_parameter_list *paramList,
                     gl_register_file type, const char *name,
                     GLuint size, GLenum datatype,
                     const gl_constant_value *values,
-                    const gl_state_index state[STATE_LENGTH]);
+                    const gl_state_index16 state[STATE_LENGTH]);
 
 extern GLint
 _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
                            const gl_constant_value values[4], GLuint size,
                            GLenum datatype, GLuint *swizzleOut);
 
 static inline GLint
 _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
                            const gl_constant_value values[4], GLuint size,
                            GLuint *swizzleOut)
 {
    return _mesa_add_typed_unnamed_constant(paramList, values, size, GL_NONE,
                                            swizzleOut);
 }
 
 extern GLint
 _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
-                          const gl_state_index stateTokens[STATE_LENGTH]);
+                          const gl_state_index16 stateTokens[]);
 
 
 static inline GLint
 _mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
                              const char *name)
 {
    if (!paramList)
       return -1;
 
    /* name must be null-terminated */
diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index f627037..d7db0d2 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -47,21 +47,21 @@
 
 
 /**
  * Use the list of tokens in the state[] array to find global GL state
  * and return it in <value>.  Usually, four values are returned in <value>
  * but matrix queries may return as many as 16 values.
  * This function is used for ARB vertex/fragment programs.
  * The program parser will produce the state[] values.
  */
 static void
-_mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
+_mesa_fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
                   gl_constant_value *val)
 {
    GLfloat *value = &val->f;
 
    switch (state[0]) {
    case STATE_MATERIAL:
       {
          /* state[1] is either 0=front or 1=back side */
          const GLuint face = (GLuint) state[1];
          const struct gl_material *mat = &ctx->Light.Material;
@@ -620,21 +620,21 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
 
 
 /**
  * Return a bitmask of the Mesa state flags (_NEW_* values) which would
  * indicate that the given context state may have changed.
  * The bitmask is used during validation to determine if we need to update
  * vertex/fragment program parameters (like "state.material.color") when
  * some GL state has changed.
  */
 GLbitfield
-_mesa_program_state_flags(const gl_state_index state[STATE_LENGTH])
+_mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH])
 {
    switch (state[0]) {
    case STATE_MATERIAL:
    case STATE_LIGHTPROD:
    case STATE_LIGHTMODEL_SCENECOLOR:
       /* these can be effected by glColor when colormaterial mode is used */
       return _NEW_LIGHT | _NEW_CURRENT_ATTRIB;
 
    case STATE_LIGHT:
    case STATE_LIGHTMODEL_AMBIENT:
@@ -940,21 +940,21 @@ append_index(char *dst, GLint index)
    sprintf(s, "[%d]", index);
    append(dst, s);
 }
 
 /**
  * Make a string from the given state vector.
  * For example, return "state.matrix.texture[2].inverse".
  * Use free() to deallocate the string.
  */
 char *
-_mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
+_mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH])
 {
    char str[1000] = "";
    char tmp[30];
 
    append(str, "state.");
    append_token(str, state[0]);
 
    switch (state[0]) {
    case STATE_MATERIAL:
       append_face(str, state[1]);
diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
index 3fdb413..6d3cc94 100644
--- a/src/mesa/program/prog_statevars.h
+++ b/src/mesa/program/prog_statevars.h
@@ -131,30 +131,29 @@ typedef enum gl_state_index_ {
    STATE_TES_PATCH_VERTICES_IN, /**< gl_PatchVerticesIn for TES (integer) */
    /**
     * A single enum gl_blend_support_qualifier value representing the
     * currently active advanced blending equation, or zero if disabled.
     */
    STATE_ADVANCED_BLENDING_MODE,
    STATE_INTERNAL_DRIVER	/* first available state index for drivers (must be last) */
 } gl_state_index;
 
 
-
 extern void
 _mesa_load_state_parameters(struct gl_context *ctx,
                             struct gl_program_parameter_list *paramList);
 
 
 extern GLbitfield
-_mesa_program_state_flags(const gl_state_index state[STATE_LENGTH]);
+_mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH]);
 
 
 extern char *
-_mesa_program_state_string(const gl_state_index state[STATE_LENGTH]);
+_mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH]);
 
 
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* PROG_STATEVARS_H */
diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y
index 04ec18d..3e71323 100644
--- a/src/mesa/program/program_parse.y
+++ b/src/mesa/program/program_parse.y
@@ -38,27 +38,27 @@
 #include "program/symbol_table.h"
 #include "program/program_parser.h"
 
 extern void *yy_scan_string(char *);
 extern void yy_delete_buffer(void *);
 
 static struct asm_symbol *declare_variable(struct asm_parser_state *state,
     char *name, enum asm_type t, struct YYLTYPE *locp);
 
 static int add_state_reference(struct gl_program_parameter_list *param_list,
-    const gl_state_index tokens[STATE_LENGTH]);
+    const gl_state_index16 tokens[STATE_LENGTH]);
 
 static int initialize_symbol_from_state(struct gl_program *prog,
-    struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
+    struct asm_symbol *param_var, const gl_state_index16 tokens[STATE_LENGTH]);
 
 static int initialize_symbol_from_param(struct gl_program *prog,
-    struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
+    struct asm_symbol *param_var, const gl_state_index16 tokens[STATE_LENGTH]);
 
 static int initialize_symbol_from_const(struct gl_program *prog,
     struct asm_symbol *param_var, const struct asm_vector *vec,
     GLboolean allowSwizzle);
 
 static int yyparse(struct asm_parser_state *state);
 
 static char *make_error_string(const char *fmt, ...);
 
 static void yyerror(struct YYLTYPE *locp, struct asm_parser_state *state,
@@ -129,21 +129,21 @@ static struct asm_instruction *asm_instruction_copy_ctor(
    struct asm_symbol temp_sym;
    struct asm_swizzle_mask swiz_mask;
    struct asm_src_register src_reg;
    struct prog_dst_register dst_reg;
    struct prog_instruction temp_inst;
    char *string;
    unsigned result;
    unsigned attrib;
    int integer;
    float real;
-   gl_state_index state[STATE_LENGTH];
+   gl_state_index16 state[STATE_LENGTH];
    int negate;
    struct asm_vector vector;
    enum prog_opcode opcode;
 
    struct {
       unsigned swz;
       unsigned rgba_valid:1;
       unsigned xyzw_valid:1;
       unsigned negate:1;
    } ext_swizzle;
@@ -2292,45 +2292,45 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
       _mesa_symbol_table_add_symbol(state->st, s->name, s);
       s->next = state->sym;
       state->sym = s;
    }
 
    return s;
 }
 
 
 int add_state_reference(struct gl_program_parameter_list *param_list,
-			const gl_state_index tokens[STATE_LENGTH])
+			const gl_state_index16 tokens[STATE_LENGTH])
 {
    const GLuint size = 4; /* XXX fix */
    char *name;
    GLint index;
 
    name = _mesa_program_state_string(tokens);
    index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name,
                                size, GL_NONE, NULL, tokens);
    param_list->StateFlags |= _mesa_program_state_flags(tokens);
 
    /* free name string here since we duplicated it in add_parameter() */
    free(name);
 
    return index;
 }
 
 
 int
 initialize_symbol_from_state(struct gl_program *prog,
 			     struct asm_symbol *param_var, 
-			     const gl_state_index tokens[STATE_LENGTH])
+			     const gl_state_index16 tokens[STATE_LENGTH])
 {
    int idx = -1;
-   gl_state_index state_tokens[STATE_LENGTH];
+   gl_state_index16 state_tokens[STATE_LENGTH];
 
 
    memcpy(state_tokens, tokens, sizeof(state_tokens));
 
    param_var->type = at_param;
    param_var->param_binding_type = PROGRAM_STATE_VAR;
 
    /* If we are adding a STATE_MATRIX that has multiple rows, we need to
     * unroll it and call add_state_reference() for each row
     */
@@ -2365,24 +2365,24 @@ initialize_symbol_from_state(struct gl_program *prog,
       param_var->param_binding_length++;
    }
 
    return idx;
 }
 
 
 int
 initialize_symbol_from_param(struct gl_program *prog,
 			     struct asm_symbol *param_var, 
-			     const gl_state_index tokens[STATE_LENGTH])
+			     const gl_state_index16 tokens[STATE_LENGTH])
 {
    int idx = -1;
-   gl_state_index state_tokens[STATE_LENGTH];
+   gl_state_index16 state_tokens[STATE_LENGTH];
 
 
    memcpy(state_tokens, tokens, sizeof(state_tokens));
 
    assert((state_tokens[0] == STATE_VERTEX_PROGRAM)
 	  || (state_tokens[0] == STATE_FRAGMENT_PROGRAM));
    assert((state_tokens[1] == STATE_ENV)
 	  || (state_tokens[1] == STATE_LOCAL));
 
    /*
diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c
index f560bce..a9c0beb 100644
--- a/src/mesa/program/programopt.c
+++ b/src/mesa/program/programopt.c
@@ -50,21 +50,21 @@ insert_mvp_dp4_code(struct gl_context *ctx, struct gl_program *vprog)
 {
    struct prog_instruction *newInst;
    const GLuint origLen = vprog->arb.NumInstructions;
    const GLuint newLen = origLen + 4;
    GLuint i;
 
    /*
     * Setup state references for the modelview/projection matrix.
     * XXX we should check if these state vars are already declared.
     */
-   static const gl_state_index mvpState[4][STATE_LENGTH] = {
+   static const gl_state_index16 mvpState[4][STATE_LENGTH] = {
       { STATE_MVP_MATRIX, 0, 0, 0, 0 },  /* state.matrix.mvp.row[0] */
       { STATE_MVP_MATRIX, 0, 1, 1, 0 },  /* state.matrix.mvp.row[1] */
       { STATE_MVP_MATRIX, 0, 2, 2, 0 },  /* state.matrix.mvp.row[2] */
       { STATE_MVP_MATRIX, 0, 3, 3, 0 },  /* state.matrix.mvp.row[3] */
    };
    GLint mvpRef[4];
 
    for (i = 0; i < 4; i++) {
       mvpRef[i] = _mesa_add_state_reference(vprog->Parameters, mvpState[i]);
    }
@@ -118,21 +118,21 @@ insert_mvp_mad_code(struct gl_context *ctx, struct gl_program *vprog)
    struct prog_instruction *newInst;
    const GLuint origLen = vprog->arb.NumInstructions;
    const GLuint newLen = origLen + 4;
    GLuint hposTemp;
    GLuint i;
 
    /*
     * Setup state references for the modelview/projection matrix.
     * XXX we should check if these state vars are already declared.
     */
-   static const gl_state_index mvpState[4][STATE_LENGTH] = {
+   static const gl_state_index16 mvpState[4][STATE_LENGTH] = {
       { STATE_MVP_MATRIX, 0, 0, 0, STATE_MATRIX_TRANSPOSE },
       { STATE_MVP_MATRIX, 0, 1, 1, STATE_MATRIX_TRANSPOSE },
       { STATE_MVP_MATRIX, 0, 2, 2, STATE_MATRIX_TRANSPOSE },
       { STATE_MVP_MATRIX, 0, 3, 3, STATE_MATRIX_TRANSPOSE },
    };
    GLint mvpRef[4];
 
    for (i = 0; i < 4; i++) {
       mvpRef[i] = _mesa_add_state_reference(vprog->Parameters, mvpState[i]);
    }
@@ -240,23 +240,23 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_program *vprog)
  * \note
  * This function sets \c VARYING_BIT_FOGC in \c fprog->info.inputs_read.
  *
  * \todo With a little work, this function could be adapted to add fog code
  * to vertex programs too.
  */
 void
 _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog,
                       GLenum fog_mode, GLboolean saturate)
 {
-   static const gl_state_index fogPStateOpt[STATE_LENGTH]
+   static const gl_state_index16 fogPStateOpt[STATE_LENGTH]
       = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 };
-   static const gl_state_index fogColorState[STATE_LENGTH]
+   static const gl_state_index16 fogColorState[STATE_LENGTH]
       = { STATE_FOG_COLOR, 0, 0, 0, 0};
    struct prog_instruction *newInst, *inst;
    const GLuint origLen = fprog->arb.NumInstructions;
    const GLuint newLen = origLen + 5;
    GLuint i;
    GLint fogPRefOpt, fogColorRef; /* state references */
    GLuint colorTemp, fogFactorTemp; /* temporary registerss */
 
    if (fog_mode == GL_NONE) {
       _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program"
diff --git a/src/mesa/state_tracker/st_atifs_to_tgsi.c b/src/mesa/state_tracker/st_atifs_to_tgsi.c
index 8affbdc..76236cf 100644
--- a/src/mesa/state_tracker/st_atifs_to_tgsi.c
+++ b/src/mesa/state_tracker/st_atifs_to_tgsi.c
@@ -537,23 +537,23 @@ out:
  */
 void
 st_init_atifs_prog(struct gl_context *ctx, struct gl_program *prog)
 {
    /* we know this is st_fragment_program, because of st_new_ati_fs() */
    struct st_fragment_program *stfp = (struct st_fragment_program *) prog;
    struct ati_fragment_shader *atifs = stfp->ati_fs;
 
    unsigned pass, i, r, optype, arg;
 
-   static const gl_state_index fog_params_state[STATE_LENGTH] =
+   static const gl_state_index16 fog_params_state[STATE_LENGTH] =
       {STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0};
-   static const gl_state_index fog_color[STATE_LENGTH] =
+   static const gl_state_index16 fog_color[STATE_LENGTH] =
       {STATE_FOG_COLOR, 0, 0, 0, 0};
 
    prog->info.inputs_read = 0;
    prog->info.outputs_written = BITFIELD64_BIT(FRAG_RESULT_COLOR);
    prog->SamplersUsed = 0;
    prog->Parameters = _mesa_new_parameter_list();
 
    /* fill in inputs_read, SamplersUsed, TexturesUsed */
    for (pass = 0; pass < atifs->NumPasses; pass++) {
       for (r = 0; r < MAX_NUM_FRAGMENT_REGISTERS_ATI; r++) {
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index dd4b05d..67af4d1 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -196,21 +196,21 @@ st_nir_assign_uniform_locations(struct gl_program *prog,
             loc = shaderidx++;
          else
             loc = imageidx++;
          assert(found);
          (void) found; /* silence unused var warning */
          /* this ensure that nir_lower_samplers looks at the correct
           * shader_program->UniformStorage[location]:
           */
          uniform->data.location = val;
       } else if (strncmp(uniform->name, "gl_", 3) == 0) {
-         const gl_state_index *const stateTokens = (gl_state_index *)uniform->state_slots[0].tokens;
+         const gl_state_index16 *const stateTokens = uniform->state_slots[0].tokens;
          /* This state reference has already been setup by ir_to_mesa, but we'll
           * get the same index back here.
           */
          loc = _mesa_add_state_reference(prog->Parameters, stateTokens);
       } else {
          loc = st_nir_lookup_parameter_index(prog->Parameters, uniform->name);
       }
 
       uniform->data.driver_location = loc;
 
@@ -253,21 +253,21 @@ st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
     * too late.  At that point, the values for the built-in uniforms won't
     * get sent to the shader.
     */
    nir_foreach_variable(var, &nir->uniforms) {
       if (strncmp(var->name, "gl_", 3) == 0) {
          const nir_state_slot *const slots = var->state_slots;
          assert(var->state_slots != NULL);
 
          for (unsigned int i = 0; i < var->num_state_slots; i++) {
             _mesa_add_state_reference(prog->Parameters,
-                                      (gl_state_index *)slots[i].tokens);
+                                      slots[i].tokens);
          }
       }
    }
 
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
     */
    _mesa_reserve_parameter_storage(prog->Parameters, 8);
 
@@ -279,21 +279,21 @@ st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
 
    NIR_PASS_V(nir, nir_lower_io_to_temporaries,
          nir_shader_get_entrypoint(nir),
          true, true);
    NIR_PASS_V(nir, nir_lower_global_vars_to_local);
    NIR_PASS_V(nir, nir_split_var_copies);
    NIR_PASS_V(nir, nir_lower_var_copies);
 
    /* fragment shaders may need : */
    if (stage == MESA_SHADER_FRAGMENT) {
-      static const gl_state_index wposTransformState[STATE_LENGTH] = {
+      static const gl_state_index16 wposTransformState[STATE_LENGTH] = {
          STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM
       };
       nir_lower_wpos_ytransform_options wpos_options = { { 0 } };
       struct pipe_screen *pscreen = st->pipe->screen;
 
       memcpy(wpos_options.state_tokens, wposTransformState,
              sizeof(wpos_options.state_tokens));
       wpos_options.fs_coord_origin_upper_left =
          pscreen->get_param(pscreen, PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT);
       wpos_options.fs_coord_origin_lower_left =
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 0772b73..629fbe5 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1108,21 +1108,21 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
 
          storage = new(mem_ctx) variable_storage(ir, dst.file, dst.index,
                                                  dst.array_id);
 
          _mesa_hash_table_insert(this->variables, ir, storage);
       }
 
 
       for (unsigned int i = 0; i < ir->get_num_state_slots(); i++) {
          int index = _mesa_add_state_reference(this->prog->Parameters,
-                                               (gl_state_index *)slots[i].tokens);
+                                               slots[i].tokens);
 
          if (storage->file == PROGRAM_STATE_VAR) {
             if (storage->index == -1) {
                storage->index = index;
             } else {
                assert(index == storage->index + (int)i);
             }
          } else {
             /* We use GLSL_TYPE_FLOAT here regardless of the actual type of
              * the data being moved since MOV does not care about the type of
@@ -1439,21 +1439,21 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
       emit_asm(ir, TGSI_OPCODE_DDX_FINE, result_dst, op[0]);
       break;
    case ir_unop_dFdy:
    case ir_unop_dFdy_coarse:
    case ir_unop_dFdy_fine:
    {
       /* The X component contains 1 or -1 depending on whether the framebuffer
        * is a FBO or the window system buffer, respectively.
        * It is then multiplied with the source operand of DDY.
        */
-      static const gl_state_index transform_y_state[STATE_LENGTH]
+      static const gl_state_index16 transform_y_state[STATE_LENGTH]
          = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM };
 
       unsigned transform_y_index =
          _mesa_add_state_reference(this->prog->Parameters,
                                    transform_y_state);
 
       st_src_reg transform_y = st_src_reg(PROGRAM_STATE_VAR,
                                           transform_y_index,
                                           glsl_type::vec4_type);
       transform_y.swizzle = SWIZZLE_XXXX;
@@ -2046,21 +2046,21 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
       if (have_fma)
          emit_asm(ir, TGSI_OPCODE_FMA, result_dst, op[0], op[1], op[2]);
       else
          emit_asm(ir, TGSI_OPCODE_MAD, result_dst, op[0], op[1], op[2]);
       break;
    case ir_unop_interpolate_at_centroid:
       emit_asm(ir, TGSI_OPCODE_INTERP_CENTROID, result_dst, op[0]);
       break;
    case ir_binop_interpolate_at_offset: {
       /* The y coordinate needs to be flipped for the default fb */
-      static const gl_state_index transform_y_state[STATE_LENGTH]
+      static const gl_state_index16 transform_y_state[STATE_LENGTH]
          = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM };
 
       unsigned transform_y_index =
          _mesa_add_state_reference(this->prog->Parameters,
                                    transform_y_state);
 
       st_src_reg transform_y = st_src_reg(PROGRAM_STATE_VAR,
                                           transform_y_index,
                                           glsl_type::vec4_type);
       transform_y.swizzle = SWIZZLE_XXXX;
@@ -6768,21 +6768,21 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    count_resources(v, prog);
 
    /* The GLSL IR won't be needed anymore. */
    ralloc_free(shader->ir);
    shader->ir = NULL;
 
    /* This must be done before the uniform storage is associated. */
    if (shader->Stage == MESA_SHADER_FRAGMENT &&
        (prog->info.inputs_read & VARYING_BIT_POS ||
         prog->info.system_values_read & (1 << SYSTEM_VALUE_FRAG_COORD))) {
-      static const gl_state_index wposTransformState[STATE_LENGTH] = {
+      static const gl_state_index16 wposTransformState[STATE_LENGTH] = {
          STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM
       };
 
       v->wpos_transform_const = _mesa_add_state_reference(prog->Parameters,
                                                           wposTransformState);
    }
 
    /* Avoid reallocation of the program parameter list, because the uniform
     * storage is only associated with the original parameter list.
     * This should be enough for Bitmap and DrawPixels constants.
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index 75825c3..c76180a 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -615,21 +615,21 @@ emit_wpos_adjustment(struct gl_context *ctx,
                      const struct gl_program *program,
                      boolean invert,
                      GLfloat adjX, GLfloat adjY[2])
 {
    struct ureg_program *ureg = t->ureg;
 
    /* Fragment program uses fragment position input.
     * Need to replace instances of INPUT[WPOS] with temp T
     * where T = INPUT[WPOS] by y is inverted.
     */
-   static const gl_state_index wposTransformState[STATE_LENGTH]
+   static const gl_state_index16 wposTransformState[STATE_LENGTH]
       = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0 };
 
    /* XXX: note we are modifying the incoming shader here!  Need to
     * do this before emitting the constant decls below, or this
     * will be missed:
     */
    unsigned wposTransConst = _mesa_add_state_reference(program->Parameters,
                                                        wposTransformState);
 
    struct ureg_src wpostrans = ureg_DECL_constant(ureg, wposTransConst);
diff --git a/src/mesa/state_tracker/st_nir_lower_builtin.c b/src/mesa/state_tracker/st_nir_lower_builtin.c
index 19a8ac0..fca0bef 100644
--- a/src/mesa/state_tracker/st_nir_lower_builtin.c
+++ b/src/mesa/state_tracker/st_nir_lower_builtin.c
@@ -93,21 +93,21 @@ get_element(const struct gl_builtin_uniform_desc *desc, nir_deref_var *deref)
    assert(deref_struct->index < desc->num_elements);
 
    return &desc->elements[deref_struct->index];
 }
 
 static nir_variable *
 get_variable(lower_builtin_state *state, nir_deref_var *deref,
              const struct gl_builtin_uniform_element *element)
 {
    nir_shader *shader = state->shader;
-   int tokens[STATE_LENGTH];
+   gl_state_index16 tokens[STATE_LENGTH];
 
    memcpy(tokens, element->tokens, sizeof(tokens));
 
    if (deref->deref.child->deref_type == nir_deref_type_array) {
       nir_deref_array *darr = nir_deref_as_array(deref->deref.child);
 
       assert(darr->deref_array_type == nir_deref_array_type_direct);
 
       /* we need to fixup the array index slot: */
       switch (tokens[0]) {
@@ -119,21 +119,21 @@ get_variable(lower_builtin_state *state, nir_deref_var *deref,
       case STATE_LIGHT:
       case STATE_LIGHTPROD:
       case STATE_TEXGEN:
       case STATE_TEXENV_COLOR:
       case STATE_CLIPPLANE:
          tokens[1] = darr->base_offset;
          break;
       }
    }
 
-   char *name = _mesa_program_state_string((gl_state_index *)tokens);
+   char *name = _mesa_program_state_string(tokens);
 
    nir_foreach_variable(var, &shader->uniforms) {
       if (strcmp(var->name, name) == 0) {
          free(name);
          return var;
       }
    }
 
    /* variable doesn't exist yet, so create it: */
    nir_variable *var =
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 5c0a581..47e859c 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1006,25 +1006,25 @@ st_translate_fragment_program(struct st_context *st,
 
 static struct st_fp_variant *
 st_create_fp_variant(struct st_context *st,
                      struct st_fragment_program *stfp,
                      const struct st_fp_variant_key *key)
 {
    struct pipe_context *pipe = st->pipe;
    struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
    struct pipe_shader_state tgsi = {0};
    struct gl_program_parameter_list *params = stfp->Base.Parameters;
-   static const gl_state_index texcoord_state[STATE_LENGTH] =
+   static const gl_state_index16 texcoord_state[STATE_LENGTH] =
       { STATE_INTERNAL, STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 };
-   static const gl_state_index scale_state[STATE_LENGTH] =
+   static const gl_state_index16 scale_state[STATE_LENGTH] =
       { STATE_INTERNAL, STATE_PT_SCALE };
-   static const gl_state_index bias_state[STATE_LENGTH] =
+   static const gl_state_index16 bias_state[STATE_LENGTH] =
       { STATE_INTERNAL, STATE_PT_BIAS };
 
    if (!variant)
       return NULL;
 
    if (stfp->tgsi.type == PIPE_SHADER_IR_NIR) {
       tgsi.type = PIPE_SHADER_IR_NIR;
       tgsi.ir.nir = nir_shader_clone(NULL, stfp->tgsi.ir.nir);
 
       if (key->clamp_color)
-- 
2.7.4



More information about the mesa-dev mailing list