mesa: Use gl_shader::Stage instead of gl_shader::Type where possible.

This reduces confusion since gl_shader::Type is sometimes
GL_SHADER_PROGRAM_MESA but is more frequently
GL_SHADER_{VERTEX,GEOMETRY,FRAGMENT}.  It also has the advantage that
when switching on gl_shader::Stage, the compiler will alert if one of
the possible enum types is unhandled.  Finally, many functions in
src/glsl (especially those dealing with linking) already use
gl_shader_stage to represent pipeline stages; using gl_shader::Stage
in those functions avoids the need for a conversion.

Note: in the process I changed _mesa_write_shader_to_file() so that if
it encounters an unexpected shader stage, it will use a file suffix of
"????" rather than "geom".

Reviewed-by: Brian Paul <brianp@vmware.com>

v2: Split from patch "mesa: Store gl_shader_stage enum in gl_shader objects."

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Paul Berry 2014-01-07 10:58:56 -08:00
parent 65511e5f22
commit e3b86f07da
11 changed files with 51 additions and 46 deletions

View file

@ -1448,7 +1448,7 @@ static void
set_shader_inout_layout(struct gl_shader *shader, set_shader_inout_layout(struct gl_shader *shader,
struct _mesa_glsl_parse_state *state) struct _mesa_glsl_parse_state *state)
{ {
if (shader->Type != GL_GEOMETRY_SHADER) { if (shader->Stage != MESA_SHADER_GEOMETRY) {
/* Should have been prevented by the parser. */ /* Should have been prevented by the parser. */
assert(!state->gs_input_prim_type_specified); assert(!state->gs_input_prim_type_specified);
assert(!state->out_qualifier->flags.i); assert(!state->out_qualifier->flags.i);
@ -1516,7 +1516,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
if (!state->error && !shader->ir->is_empty()) { if (!state->error && !shader->ir->is_empty()) {
struct gl_shader_compiler_options *options = struct gl_shader_compiler_options *options =
&ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)]; &ctx->ShaderCompilerOptions[shader->Stage];
/* Do some optimization at compile time to reduce shader IR size /* Do some optimization at compile time to reduce shader IR size
* and reduce later work if the same shader is linked multiple times * and reduce later work if the same shader is linked multiple times

View file

@ -313,7 +313,7 @@ validate_interstage_inout_blocks(struct gl_shader_program *prog,
const gl_shader *consumer) const gl_shader *consumer)
{ {
interface_block_definitions definitions; interface_block_definitions definitions;
const bool extra_array_level = consumer->Type == GL_GEOMETRY_SHADER; const bool extra_array_level = consumer->Stage == MESA_SHADER_GEOMETRY;
/* Add input interfaces from the consumer to the symbol table. */ /* Add input interfaces from the consumer to the symbol table. */
foreach_list(node, consumer->ir) { foreach_list(node, consumer->ir) {

View file

@ -1072,7 +1072,7 @@ assign_varying_locations(struct gl_context *ctx,
const unsigned producer_base = VARYING_SLOT_VAR0; const unsigned producer_base = VARYING_SLOT_VAR0;
const unsigned consumer_base = VARYING_SLOT_VAR0; const unsigned consumer_base = VARYING_SLOT_VAR0;
varying_matches matches(ctx->Const.DisableVaryingPacking, varying_matches matches(ctx->Const.DisableVaryingPacking,
consumer && consumer->Type == GL_FRAGMENT_SHADER); consumer && consumer->Stage == MESA_SHADER_FRAGMENT);
hash_table *tfeedback_candidates hash_table *tfeedback_candidates
= hash_table_ctor(0, hash_table_string_hash, hash_table_string_compare); = hash_table_ctor(0, hash_table_string_hash, hash_table_string_compare);
hash_table *consumer_inputs hash_table *consumer_inputs
@ -1217,9 +1217,9 @@ assign_varying_locations(struct gl_context *ctx,
linker_error(prog, "%s shader varying %s not written " linker_error(prog, "%s shader varying %s not written "
"by %s shader\n.", "by %s shader\n.",
_mesa_progshader_enum_to_string(consumer->Type), _mesa_shader_stage_to_string(consumer->Stage),
var->name, var->name,
_mesa_progshader_enum_to_string(producer->Type)); _mesa_shader_stage_to_string(producer->Stage));
} }
/* An 'in' variable is only really a shader input if its /* An 'in' variable is only really a shader input if its
@ -1250,14 +1250,14 @@ check_against_output_limit(struct gl_context *ctx,
} }
unsigned max_output_components; unsigned max_output_components;
switch (producer->Type) { switch (producer->Stage) {
case GL_VERTEX_SHADER: case MESA_SHADER_VERTEX:
max_output_components = ctx->Const.VertexProgram.MaxOutputComponents; max_output_components = ctx->Const.VertexProgram.MaxOutputComponents;
break; break;
case GL_GEOMETRY_SHADER: case MESA_SHADER_GEOMETRY:
max_output_components = ctx->Const.GeometryProgram.MaxOutputComponents; max_output_components = ctx->Const.GeometryProgram.MaxOutputComponents;
break; break;
case GL_FRAGMENT_SHADER: case MESA_SHADER_FRAGMENT:
default: default:
assert(!"Should not get here."); assert(!"Should not get here.");
return false; return false;
@ -1299,14 +1299,14 @@ check_against_input_limit(struct gl_context *ctx,
} }
unsigned max_input_components; unsigned max_input_components;
switch (consumer->Type) { switch (consumer->Stage) {
case GL_GEOMETRY_SHADER: case MESA_SHADER_GEOMETRY:
max_input_components = ctx->Const.GeometryProgram.MaxInputComponents; max_input_components = ctx->Const.GeometryProgram.MaxInputComponents;
break; break;
case GL_FRAGMENT_SHADER: case MESA_SHADER_FRAGMENT:
max_input_components = ctx->Const.FragmentProgram.MaxInputComponents; max_input_components = ctx->Const.FragmentProgram.MaxInputComponents;
break; break;
case GL_VERTEX_SHADER: case MESA_SHADER_VERTEX:
default: default:
assert(!"Should not get here."); assert(!"Should not get here.");
return false; return false;

View file

@ -438,7 +438,7 @@ analyze_clip_usage(struct gl_shader_program *prog,
if (clip_vertex.variable_found() && clip_distance.variable_found()) { if (clip_vertex.variable_found() && clip_distance.variable_found()) {
linker_error(prog, "%s shader writes to both `gl_ClipVertex' " linker_error(prog, "%s shader writes to both `gl_ClipVertex' "
"and `gl_ClipDistance'\n", "and `gl_ClipDistance'\n",
_mesa_progshader_enum_to_string(shader->Type)); _mesa_shader_stage_to_string(shader->Stage));
return; return;
} }
*UsesClipDistance = clip_distance.variable_found(); *UsesClipDistance = clip_distance.variable_found();
@ -1209,7 +1209,7 @@ link_gs_inout_layout_qualifiers(struct gl_shader_program *prog,
/* No in/out qualifiers defined for anything but GLSL 1.50+ /* No in/out qualifiers defined for anything but GLSL 1.50+
* geometry shaders so far. * geometry shaders so far.
*/ */
if (linked_shader->Type != GL_GEOMETRY_SHADER || prog->Version < 150) if (linked_shader->Stage != MESA_SHADER_GEOMETRY || prog->Version < 150)
return; return;
/* From the GLSL 1.50 spec, page 46: /* From the GLSL 1.50 spec, page 46:
@ -1376,7 +1376,7 @@ link_intrastage_shaders(void *mem_ctx,
if (main == NULL) { if (main == NULL) {
linker_error(prog, "%s shader lacks `main'\n", linker_error(prog, "%s shader lacks `main'\n",
_mesa_progshader_enum_to_string(shader_list[0]->Type)); _mesa_shader_stage_to_string(shader_list[0]->Stage));
return NULL; return NULL;
} }
@ -1450,7 +1450,7 @@ link_intrastage_shaders(void *mem_ctx,
validate_ir_tree(linked->ir); validate_ir_tree(linked->ir);
/* Set the size of geometry shader input arrays */ /* Set the size of geometry shader input arrays */
if (linked->Type == GL_GEOMETRY_SHADER) { if (linked->Stage == MESA_SHADER_GEOMETRY) {
unsigned num_vertices = vertices_per_prim(prog->Geom.InputType); unsigned num_vertices = vertices_per_prim(prog->Geom.InputType);
geom_array_resize_visitor input_resize_visitor(num_vertices, prog); geom_array_resize_visitor input_resize_visitor(num_vertices, prog);
foreach_iter(exec_list_iterator, iter, *linked->ir) { foreach_iter(exec_list_iterator, iter, *linked->ir) {
@ -2049,16 +2049,16 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
goto done; goto done;
} }
switch (prog->Shaders[i]->Type) { switch (prog->Shaders[i]->Stage) {
case GL_VERTEX_SHADER: case MESA_SHADER_VERTEX:
vert_shader_list[num_vert_shaders] = prog->Shaders[i]; vert_shader_list[num_vert_shaders] = prog->Shaders[i];
num_vert_shaders++; num_vert_shaders++;
break; break;
case GL_FRAGMENT_SHADER: case MESA_SHADER_FRAGMENT:
frag_shader_list[num_frag_shaders] = prog->Shaders[i]; frag_shader_list[num_frag_shaders] = prog->Shaders[i];
num_frag_shaders++; num_frag_shaders++;
break; break;
case GL_GEOMETRY_SHADER: case MESA_SHADER_GEOMETRY:
geom_shader_list[num_geom_shaders] = prog->Shaders[i]; geom_shader_list[num_geom_shaders] = prog->Shaders[i];
num_geom_shaders++; num_geom_shaders++;
break; break;

View file

@ -669,7 +669,7 @@ lower_packed_varyings(void *mem_ctx, unsigned location_base,
gs_input_vertices, &new_instructions); gs_input_vertices, &new_instructions);
visitor.run(instructions); visitor.run(instructions);
if (mode == ir_var_shader_out) { if (mode == ir_var_shader_out) {
if (shader->Type == GL_GEOMETRY_SHADER) { if (shader->Stage == MESA_SHADER_GEOMETRY) {
/* For geometry shaders, outputs need to be lowered before each call /* For geometry shaders, outputs need to be lowered before each call
* to EmitVertex() * to EmitVertex()
*/ */

View file

@ -512,7 +512,7 @@ do_dead_builtin_varyings(struct gl_context *ctx,
tfeedback_decl *tfeedback_decls) tfeedback_decl *tfeedback_decls)
{ {
/* Lower the gl_FragData array to separate variables. */ /* Lower the gl_FragData array to separate variables. */
if (consumer && consumer->Type == GL_FRAGMENT_SHADER) { if (consumer && consumer->Stage == MESA_SHADER_FRAGMENT) {
lower_fragdata_array(consumer->ir); lower_fragdata_array(consumer->ir);
} }
@ -574,7 +574,7 @@ do_dead_builtin_varyings(struct gl_context *ctx,
* This doesn't prevent elimination of the gl_TexCoord elements which * This doesn't prevent elimination of the gl_TexCoord elements which
* are not read by the fragment shader. We want to eliminate those anyway. * are not read by the fragment shader. We want to eliminate those anyway.
*/ */
if (consumer->Type == GL_FRAGMENT_SHADER) { if (consumer->Stage == MESA_SHADER_FRAGMENT) {
producer_info.texcoord_usage = (1 << MAX_TEXTURE_COORD_UNITS) - 1; producer_info.texcoord_usage = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
} }

View file

@ -262,7 +262,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
if (ctx->Shader.Flags & GLSL_DUMP) { if (ctx->Shader.Flags & GLSL_DUMP) {
printf("\n"); printf("\n");
printf("GLSL IR for linked %s program %d:\n", printf("GLSL IR for linked %s program %d:\n",
_mesa_progshader_enum_to_string(shader->base.Type), shProg->Name); _mesa_shader_stage_to_string(shader->base.Stage),
shProg->Name);
_mesa_print_ir(shader->base.ir, NULL); _mesa_print_ir(shader->base.ir, NULL);
printf("\n"); printf("\n");
} }
@ -275,7 +276,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
continue; continue;
printf("GLSL %s shader %d source for linked program %d:\n", printf("GLSL %s shader %d source for linked program %d:\n",
_mesa_progshader_enum_to_string(sh->Type), _mesa_shader_stage_to_string(sh->Stage),
i, i,
shProg->Name); shProg->Name);
printf("%s", sh->Source); printf("%s", sh->Source);

View file

@ -842,7 +842,7 @@ brw_upload_ubo_surfaces(struct brw_context *brw,
brw_create_constant_surface(brw, bo, binding->Offset, brw_create_constant_surface(brw, bo, binding->Offset,
bo->size - binding->Offset, bo->size - binding->Offset,
&surf_offsets[i], &surf_offsets[i],
shader->Type == GL_FRAGMENT_SHADER); shader->Stage == MESA_SHADER_FRAGMENT);
} }
if (shader->NumUniformBlocks) if (shader->NumUniformBlocks)

View file

@ -778,7 +778,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
if (!sh) if (!sh)
return; return;
options = &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(sh->Type)]; options = &ctx->ShaderCompilerOptions[sh->Stage];
/* set default pragma state for shader */ /* set default pragma state for shader */
sh->Pragmas = options->DefaultPragmas; sh->Pragmas = options->DefaultPragmas;
@ -791,7 +791,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
} else { } else {
if (ctx->Shader.Flags & GLSL_DUMP) { if (ctx->Shader.Flags & GLSL_DUMP) {
printf("GLSL source for %s shader %d:\n", printf("GLSL source for %s shader %d:\n",
_mesa_progshader_enum_to_string(sh->Type), sh->Name); _mesa_shader_stage_to_string(sh->Stage), sh->Name);
printf("%s\n", sh->Source); printf("%s\n", sh->Source);
} }
@ -823,7 +823,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
if (!sh->CompileStatus) { if (!sh->CompileStatus) {
if (ctx->Shader.Flags & GLSL_DUMP_ON_ERROR) { if (ctx->Shader.Flags & GLSL_DUMP_ON_ERROR) {
fprintf(stderr, "GLSL source for %s shader %d:\n", fprintf(stderr, "GLSL source for %s shader %d:\n",
_mesa_progshader_enum_to_string(sh->Type), sh->Name); _mesa_shader_stage_to_string(sh->Stage), sh->Name);
fprintf(stderr, "%s\n", sh->Source); fprintf(stderr, "%s\n", sh->Source);
fprintf(stderr, "Info Log:\n%s\n", sh->InfoLog); fprintf(stderr, "Info Log:\n%s\n", sh->InfoLog);
fflush(stderr); fflush(stderr);
@ -898,7 +898,7 @@ print_shader_info(const struct gl_shader_program *shProg)
printf("Mesa: glUseProgram(%u)\n", shProg->Name); printf("Mesa: glUseProgram(%u)\n", shProg->Name);
for (i = 0; i < shProg->NumShaders; i++) { for (i = 0; i < shProg->NumShaders; i++) {
printf(" %s shader %u, checksum %u\n", printf(" %s shader %u, checksum %u\n",
_mesa_progshader_enum_to_string(shProg->Shaders[i]->Type), _mesa_shader_stage_to_string(shProg->Shaders[i]->Stage),
shProg->Shaders[i]->Name, shProg->Shaders[i]->Name,
shProg->Shaders[i]->SourceChecksum); shProg->Shaders[i]->SourceChecksum);
} }

View file

@ -2493,8 +2493,7 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program
struct gl_program_parameter_list struct gl_program_parameter_list
*params) *params)
{ {
add_uniform_to_shader add(shader_program, params, add_uniform_to_shader add(shader_program, params, sh->Stage);
_mesa_shader_enum_to_shader_stage(sh->Type));
foreach_list(node, sh->ir) { foreach_list(node, sh->ir) {
ir_variable *var = ((ir_instruction *) node)->as_variable(); ir_variable *var = ((ir_instruction *) node)->as_variable();
@ -2801,18 +2800,18 @@ get_mesa_program(struct gl_context *ctx,
int i; int i;
struct gl_program *prog; struct gl_program *prog;
GLenum target; GLenum target;
const char *target_string = _mesa_progshader_enum_to_string(shader->Type); const char *target_string = _mesa_shader_stage_to_string(shader->Stage);
struct gl_shader_compiler_options *options = struct gl_shader_compiler_options *options =
&ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)]; &ctx->ShaderCompilerOptions[shader->Stage];
switch (shader->Type) { switch (shader->Stage) {
case GL_VERTEX_SHADER: case MESA_SHADER_VERTEX:
target = GL_VERTEX_PROGRAM_ARB; target = GL_VERTEX_PROGRAM_ARB;
break; break;
case GL_FRAGMENT_SHADER: case MESA_SHADER_FRAGMENT:
target = GL_FRAGMENT_PROGRAM_ARB; target = GL_FRAGMENT_PROGRAM_ARB;
break; break;
case GL_GEOMETRY_SHADER: case MESA_SHADER_GEOMETRY:
target = GL_GEOMETRY_PROGRAM_NV; target = GL_GEOMETRY_PROGRAM_NV;
break; break;
default: default:
@ -3007,7 +3006,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
bool progress; bool progress;
exec_list *ir = prog->_LinkedShaders[i]->ir; exec_list *ir = prog->_LinkedShaders[i]->ir;
const struct gl_shader_compiler_options *options = const struct gl_shader_compiler_options *options =
&ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(prog->_LinkedShaders[i]->Type)]; &ctx->ShaderCompilerOptions[prog->_LinkedShaders[i]->Stage];
do { do {
progress = false; progress = false;

View file

@ -1005,16 +1005,21 @@ _mesa_print_parameter_list(const struct gl_program_parameter_list *list)
void void
_mesa_write_shader_to_file(const struct gl_shader *shader) _mesa_write_shader_to_file(const struct gl_shader *shader)
{ {
const char *type; const char *type = "????";
char filename[100]; char filename[100];
FILE *f; FILE *f;
if (shader->Type == GL_FRAGMENT_SHADER) switch (shader->Stage) {
case MESA_SHADER_FRAGMENT:
type = "frag"; type = "frag";
else if (shader->Type == GL_VERTEX_SHADER) break;
case MESA_SHADER_VERTEX:
type = "vert"; type = "vert";
else break;
case MESA_SHADER_GEOMETRY:
type = "geom"; type = "geom";
break;
}
_mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type); _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
f = fopen(filename, "w"); f = fopen(filename, "w");
@ -1061,7 +1066,7 @@ _mesa_append_uniforms_to_file(const struct gl_shader *shader)
char filename[100]; char filename[100];
FILE *f; FILE *f;
if (shader->Type == GL_FRAGMENT_SHADER) if (shader->Stage == MESA_SHADER_FRAGMENT)
type = "frag"; type = "frag";
else else
type = "vert"; type = "vert";