mesa,glsl,nir: reduce gl_state_index size to 2 bytes

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

This helps reduce the size of gl_program_parameter.

Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Marek Olšák 2017-11-16 04:29:35 +01:00
parent a7882013d3
commit e149a0253c
27 changed files with 63 additions and 63 deletions

View File

@ -397,7 +397,7 @@ depth_layout_string(ir_depth_layout layout);
* \sa ir_variable::state_slots
*/
struct ir_state_slot {
int tokens[5];
gl_state_index16 tokens[5];
int swizzle;
};

View File

@ -975,7 +975,7 @@ 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);

View File

@ -100,13 +100,13 @@ _mesa_new_shader(GLuint name, gl_shader_stage stage)
}
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;
}

View File

@ -69,11 +69,11 @@ _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)

View File

@ -89,7 +89,7 @@ struct nir_instr;
* \sa nir_variable::state_slots
*/
typedef struct {
int tokens[5];
gl_state_index16 tokens[5];
int swizzle;
} nir_state_slot;
@ -2653,7 +2653,7 @@ 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;
@ -2665,9 +2665,9 @@ bool nir_lower_wpos_ytransform(nir_shader *shader,
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;

View File

@ -67,7 +67,8 @@ get_texcoord(lower_drawpixels_state *state)
}
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,

View File

@ -48,6 +48,8 @@ typedef enum
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);
/**

View File

@ -319,8 +319,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
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);
}
}
}

View File

@ -40,7 +40,7 @@ brw_nir_setup_glsl_builtin_uniform(nir_variable *var,
* 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

View File

@ -127,7 +127,7 @@ brw_create_nir(struct brw_context *brw,
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);
}
}

View File

@ -456,7 +456,7 @@ static GLboolean r200_translate_vertex_program(struct gl_context *ctx, struct r2
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);
}

View File

@ -413,7 +413,7 @@ static struct ureg register_param5(struct tnl_program *p,
GLint s3,
GLint s4)
{
gl_state_index tokens[STATE_LENGTH];
gl_state_index16 tokens[STATE_LENGTH];
GLint idx;
tokens[0] = s0;
tokens[1] = s1;

View File

@ -30,7 +30,7 @@
TEST(program_state_string, depth_range)
{
const gl_state_index state[STATE_LENGTH] = {
const gl_state_index16 state[STATE_LENGTH] = {
STATE_DEPTH_RANGE
};

View File

@ -505,7 +505,7 @@ _mesa_flush_vertices_for_uniforms(struct gl_context *ctx,
struct gl_builtin_uniform_element {
const char *field;
int tokens[STATE_LENGTH];
gl_state_index16 tokens[STATE_LENGTH];
int swizzle;
};

View File

@ -663,7 +663,7 @@ ir_to_mesa_visitor::visit(ir_variable *ir)
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) {

View File

@ -232,7 +232,7 @@ _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])
{
assert(0 < size && size <=4);
const GLuint oldNum = paramList->NumParameters;
@ -352,7 +352,7 @@ _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList,
*/
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;
@ -361,15 +361,15 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList,
/* 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() */

View File

@ -72,7 +72,7 @@ struct gl_program_parameter
/**
* A sequence of STATE_* tokens and integers to identify GL state.
*/
gl_state_index StateIndexes[STATE_LENGTH];
gl_state_index16 StateIndexes[STATE_LENGTH];
};
@ -108,7 +108,7 @@ _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,
@ -126,7 +126,7 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
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

View File

@ -54,7 +54,7 @@
* 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;
@ -628,7 +628,7 @@ _mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[],
* 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:
@ -948,7 +948,7 @@ append_index(char *dst, GLint index)
* 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];

View File

@ -138,18 +138,17 @@ typedef enum gl_state_index_ {
} 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]);

View File

@ -45,13 +45,13 @@ 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,
@ -136,7 +136,7 @@ static struct asm_instruction *asm_instruction_copy_ctor(
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;
@ -2299,7 +2299,7 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
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;
@ -2320,10 +2320,10 @@ int add_state_reference(struct gl_program_parameter_list *param_list,
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));
@ -2372,10 +2372,10 @@ initialize_symbol_from_state(struct gl_program *prog,
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));

View File

@ -57,7 +57,7 @@ insert_mvp_dp4_code(struct gl_context *ctx, struct gl_program *vprog)
* 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] */
@ -125,7 +125,7 @@ insert_mvp_mad_code(struct gl_context *ctx, struct gl_program *vprog)
* 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 },
@ -247,9 +247,9 @@ 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;

View File

@ -544,9 +544,9 @@ st_init_atifs_prog(struct gl_context *ctx, struct gl_program *prog)
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;

View File

@ -247,7 +247,7 @@ st_nir_assign_uniform_locations(struct gl_program *prog,
else
loc = imageidx++;
} 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.
*/
@ -365,7 +365,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
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);
}
}
}
@ -598,7 +598,7 @@ st_link_nir(struct gl_context *ctx,
/* fragment shaders may need : */
if (nir->info.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 } };

View File

@ -1135,7 +1135,6 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
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);
if (storage->file == PROGRAM_STATE_VAR) {
@ -1497,7 +1496,7 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
* 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 =
@ -2115,7 +2114,7 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
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 =
@ -6866,7 +6865,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
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
};

View File

@ -622,7 +622,7 @@ emit_wpos_adjustment(struct gl_context *ctx,
* 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

View File

@ -100,7 +100,7 @@ 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));
@ -126,7 +126,7 @@ get_variable(lower_builtin_state *state, nir_deref_var *deref,
}
}
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) {

View File

@ -1013,11 +1013,11 @@ st_create_fp_variant(struct st_context *st,
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)