diff options
author | Paul Berry <[email protected]> | 2014-01-07 10:58:56 -0800 |
---|---|---|
committer | Paul Berry <[email protected]> | 2014-01-08 07:31:45 -0800 |
commit | e3b86f07da4ba9a4db6b8aae4072af6f1638b7cc (patch) | |
tree | 1b3c89c2a65cdefd6c39974e19ac337962df42b9 /src/mesa | |
parent | 65511e5f22e2ba0a5ebd9210319a55d80ea5334e (diff) |
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 <[email protected]>
v2: Split from patch "mesa: Store gl_shader_stage enum in gl_shader objects."
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_shader.cpp | 5 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 2 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.c | 8 | ||||
-rw-r--r-- | src/mesa/program/ir_to_mesa.cpp | 17 | ||||
-rw-r--r-- | src/mesa/program/prog_print.c | 15 |
5 files changed, 26 insertions, 21 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp index c0d6aa27eeb..33197ebf105 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.cpp +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp @@ -262,7 +262,8 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg) if (ctx->Shader.Flags & GLSL_DUMP) { printf("\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); printf("\n"); } @@ -275,7 +276,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg) continue; 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, shProg->Name); printf("%s", sh->Source); diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index 5236eda0d9f..acb1a40e632 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -842,7 +842,7 @@ brw_upload_ubo_surfaces(struct brw_context *brw, brw_create_constant_surface(brw, bo, binding->Offset, bo->size - binding->Offset, &surf_offsets[i], - shader->Type == GL_FRAGMENT_SHADER); + shader->Stage == MESA_SHADER_FRAGMENT); } if (shader->NumUniformBlocks) diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index fc76f232eee..16a9a384c3b 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -778,7 +778,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj) if (!sh) return; - options = &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(sh->Type)]; + options = &ctx->ShaderCompilerOptions[sh->Stage]; /* set default pragma state for shader */ sh->Pragmas = options->DefaultPragmas; @@ -791,7 +791,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj) } else { if (ctx->Shader.Flags & GLSL_DUMP) { 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); } @@ -823,7 +823,7 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj) if (!sh->CompileStatus) { if (ctx->Shader.Flags & GLSL_DUMP_ON_ERROR) { 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, "Info Log:\n%s\n", sh->InfoLog); fflush(stderr); @@ -898,7 +898,7 @@ print_shader_info(const struct gl_shader_program *shProg) printf("Mesa: glUseProgram(%u)\n", shProg->Name); for (i = 0; i < shProg->NumShaders; i++) { 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]->SourceChecksum); } diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index ae4a6e2dec6..88e94fa014e 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2493,8 +2493,7 @@ _mesa_generate_parameters_list_for_uniforms(struct gl_shader_program struct gl_program_parameter_list *params) { - add_uniform_to_shader add(shader_program, params, - _mesa_shader_enum_to_shader_stage(sh->Type)); + add_uniform_to_shader add(shader_program, params, sh->Stage); foreach_list(node, sh->ir) { ir_variable *var = ((ir_instruction *) node)->as_variable(); @@ -2801,18 +2800,18 @@ get_mesa_program(struct gl_context *ctx, int i; struct gl_program *prog; 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 = - &ctx->ShaderCompilerOptions[_mesa_shader_enum_to_shader_stage(shader->Type)]; + &ctx->ShaderCompilerOptions[shader->Stage]; - switch (shader->Type) { - case GL_VERTEX_SHADER: + switch (shader->Stage) { + case MESA_SHADER_VERTEX: target = GL_VERTEX_PROGRAM_ARB; break; - case GL_FRAGMENT_SHADER: + case MESA_SHADER_FRAGMENT: target = GL_FRAGMENT_PROGRAM_ARB; break; - case GL_GEOMETRY_SHADER: + case MESA_SHADER_GEOMETRY: target = GL_GEOMETRY_PROGRAM_NV; break; default: @@ -3007,7 +3006,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) bool progress; exec_list *ir = prog->_LinkedShaders[i]->ir; 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 { progress = false; diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index fa120cc5e3a..9391e99ff62 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -1005,16 +1005,21 @@ _mesa_print_parameter_list(const struct gl_program_parameter_list *list) void _mesa_write_shader_to_file(const struct gl_shader *shader) { - const char *type; + const char *type = "????"; char filename[100]; FILE *f; - if (shader->Type == GL_FRAGMENT_SHADER) + switch (shader->Stage) { + case MESA_SHADER_FRAGMENT: type = "frag"; - else if (shader->Type == GL_VERTEX_SHADER) + break; + case MESA_SHADER_VERTEX: type = "vert"; - else + break; + case MESA_SHADER_GEOMETRY: type = "geom"; + break; + } _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type); f = fopen(filename, "w"); @@ -1061,7 +1066,7 @@ _mesa_append_uniforms_to_file(const struct gl_shader *shader) char filename[100]; FILE *f; - if (shader->Type == GL_FRAGMENT_SHADER) + if (shader->Stage == MESA_SHADER_FRAGMENT) type = "frag"; else type = "vert"; |