diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/glsl/glsl_parser_extras.cpp | 35 | ||||
-rw-r--r-- | src/glsl/glsl_parser_extras.h | 3 | ||||
-rw-r--r-- | src/glsl/link_varyings.cpp | 15 | ||||
-rw-r--r-- | src/glsl/linker.cpp | 4 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_shader.cpp | 9 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.c | 17 | ||||
-rw-r--r-- | src/mesa/main/uniform_query.cpp | 9 | ||||
-rw-r--r-- | src/mesa/program/ir_to_mesa.cpp | 5 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 7 |
9 files changed, 61 insertions, 43 deletions
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 98627145a5b..7b827bad6f1 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -302,6 +302,41 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version, } } +extern "C" { + +/** + * The most common use of _mesa_glsl_shader_target_name(), which is + * shared with C code in Mesa core to translate a GLenum to a short + * shader stage name in debug printouts. + * + * It recognizes the PROGRAM variants of the names so it can be used + * with a struct gl_program->Target, not just a struct + * gl_shader->Type. + */ +const char * +_mesa_glsl_shader_target_name(GLenum type) +{ + switch (type) { + case GL_VERTEX_SHADER: + case GL_VERTEX_PROGRAM_ARB: + return "vertex"; + case GL_FRAGMENT_SHADER: + case GL_FRAGMENT_PROGRAM_ARB: + return "fragment"; + case GL_GEOMETRY_SHADER: + return "geometry"; + default: + assert(!"Should not get here."); + return "unknown"; + } +} + +} /* extern "C" */ + +/** + * Overloaded C++ variant usable within the compiler for translating + * our internal enum into short stage names. + */ const char * _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target) { diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h index 95918de720b..7f478df8062 100644 --- a/src/glsl/glsl_parser_extras.h +++ b/src/glsl/glsl_parser_extras.h @@ -371,6 +371,9 @@ _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target); extern "C" { #endif +extern const char * +_mesa_glsl_shader_target_name(GLenum type); + extern int glcpp_preprocess(void *ctx, const char **shader, char **info_log, const struct gl_extensions *extensions, struct gl_context *gl_ctx); diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp index 34e3440d67d..4fdbdc19942 100644 --- a/src/glsl/link_varyings.cpp +++ b/src/glsl/link_varyings.cpp @@ -31,6 +31,7 @@ #include "main/mtypes.h" #include "glsl_symbol_table.h" +#include "glsl_parser_extras.h" #include "ir_optimization.h" #include "linker.h" #include "link_varyings.h" @@ -47,9 +48,10 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog, gl_shader *producer, gl_shader *consumer) { glsl_symbol_table parameters; - /* FINISHME: Figure these out dynamically. */ - const char *const producer_stage = "vertex"; - const char *const consumer_stage = "fragment"; + const char *const producer_stage = + _mesa_glsl_shader_target_name(producer->Type); + const char *const consumer_stage = + _mesa_glsl_shader_target_name(consumer->Type); /* Find all shader outputs in the "producer" stage. */ @@ -1135,8 +1137,11 @@ assign_varying_locations(struct gl_context *ctx, * "glsl1-varying read but not written" in piglit. */ - linker_error(prog, "fragment shader varying %s not written " - "by vertex shader\n.", var->name); + linker_error(prog, "%s shader varying %s not written " + "by %s shader\n.", + _mesa_glsl_shader_target_name(consumer->Type), + var->name, + _mesa_glsl_shader_target_name(producer->Type)); } /* An 'in' variable is only really a shader input if its diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index cd8d680aec4..c168e47e0c8 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -66,6 +66,7 @@ #include "main/core.h" #include "glsl_symbol_table.h" +#include "glsl_parser_extras.h" #include "ir.h" #include "program.h" #include "program/hash_table.h" @@ -1009,8 +1010,7 @@ link_intrastage_shaders(void *mem_ctx, if (main == NULL) { linker_error(prog, "%s shader lacks `main'\n", - (shader_list[0]->Type == GL_VERTEX_SHADER) - ? "vertex" : "fragment"); + _mesa_glsl_shader_target_name(shader_list[0]->Type)); return NULL; } diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp index 65df9316506..12986cc403d 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.cpp +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp @@ -28,6 +28,7 @@ extern "C" { } #include "brw_fs.h" #include "glsl/ir_optimization.h" +#include "glsl/glsl_parser_extras.h" struct gl_shader * brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type) @@ -112,8 +113,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg) struct brw_context *brw = brw_context(ctx); struct intel_context *intel = &brw->intel; unsigned int stage; - static const char *target_strings[] - = { "vertex", "fragment", "geometry" }; for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders); stage++) { struct brw_shader *shader = @@ -262,8 +261,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", target_strings[stage], - shProg->Name); + printf("GLSL IR for linked %s program %d:\n", + _mesa_glsl_shader_target_name(shader->base.Type), shProg->Name); _mesa_print_ir(shader->base.ir, NULL); printf("\n"); } @@ -276,7 +275,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", - target_strings[_mesa_shader_type_to_index(sh->Type)], + _mesa_glsl_shader_target_name(sh->Type), i, shProg->Name); printf("%s", sh->Source); diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 8cb02760b20..88518caa53b 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -816,21 +816,8 @@ print_shader_info(const struct gl_shader_program *shProg) printf("Mesa: glUseProgram(%u)\n", shProg->Name); for (i = 0; i < shProg->NumShaders; i++) { - const char *s; - switch (shProg->Shaders[i]->Type) { - case GL_VERTEX_SHADER: - s = "vertex"; - break; - case GL_FRAGMENT_SHADER: - s = "fragment"; - break; - case GL_GEOMETRY_SHADER: - s = "geometry"; - break; - default: - s = ""; - } - printf(" %s shader %u, checksum %u\n", s, + printf(" %s shader %u, checksum %u\n", + _mesa_glsl_shader_target_name(shProg->Shaders[i]->Type), shProg->Shaders[i]->Name, shProg->Shaders[i]->SourceChecksum); } diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index 296f80f17bf..3c460042eee 100644 --- a/src/mesa/main/uniform_query.cpp +++ b/src/mesa/main/uniform_query.cpp @@ -33,6 +33,7 @@ #include "program/hash_table.h" #include "../glsl/program.h" #include "../glsl/ir_uniform.h" +#include "../glsl/glsl_parser_extras.h" #include "main/shaderapi.h" #include "main/shaderobj.h" #include "uniforms.h" @@ -434,12 +435,6 @@ log_uniform(const void *values, enum glsl_base_type basicType, static void log_program_parameters(const struct gl_shader_program *shProg) { - static const char *stages[] = { - "vertex", "fragment", "geometry" - }; - - assert(Elements(stages) == MESA_SHADER_TYPES); - for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { if (shProg->_LinkedShaders[i] == NULL) continue; @@ -447,7 +442,7 @@ log_program_parameters(const struct gl_shader_program *shProg) const struct gl_program *const prog = shProg->_LinkedShaders[i]->Program; printf("Program %d %s shader parameters:\n", - shProg->Name, stages[i]); + shProg->Name, _mesa_glsl_shader_target_name(prog->Target)); for (unsigned j = 0; j < prog->Parameters->NumParameters; j++) { printf("%s: %p %f %f %f %f\n", prog->Parameters->Parameters[j].Name, diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 191e2911912..2739df72577 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2810,22 +2810,19 @@ get_mesa_program(struct gl_context *ctx, int i; struct gl_program *prog; GLenum target; - const char *target_string; + const char *target_string = _mesa_glsl_shader_target_name(shader->Type); struct gl_shader_compiler_options *options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)]; switch (shader->Type) { case GL_VERTEX_SHADER: target = GL_VERTEX_PROGRAM_ARB; - target_string = "vertex"; break; case GL_FRAGMENT_SHADER: target = GL_FRAGMENT_PROGRAM_ARB; - target_string = "fragment"; break; case GL_GEOMETRY_SHADER: target = GL_GEOMETRY_PROGRAM_NV; - target_string = "geometry"; break; default: assert(!"should not be reached"); diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 4a68882603f..32bc2b37b10 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -4994,7 +4994,6 @@ get_mesa_program(struct gl_context *ctx, glsl_to_tgsi_visitor* v; struct gl_program *prog; GLenum target; - const char *target_string; bool progress; struct gl_shader_compiler_options *options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)]; @@ -5005,17 +5004,14 @@ get_mesa_program(struct gl_context *ctx, case GL_VERTEX_SHADER: target = GL_VERTEX_PROGRAM_ARB; ptarget = PIPE_SHADER_VERTEX; - target_string = "vertex"; break; case GL_FRAGMENT_SHADER: target = GL_FRAGMENT_PROGRAM_ARB; ptarget = PIPE_SHADER_FRAGMENT; - target_string = "fragment"; break; case GL_GEOMETRY_SHADER: target = GL_GEOMETRY_PROGRAM_NV; ptarget = PIPE_SHADER_GEOMETRY; - target_string = "geometry"; break; default: assert(!"should not be reached"); @@ -5105,7 +5101,8 @@ get_mesa_program(struct gl_context *ctx, if (ctx->Shader.Flags & GLSL_DUMP) { printf("\n"); - printf("GLSL IR for linked %s program %d:\n", target_string, + printf("GLSL IR for linked %s program %d:\n", + _mesa_glsl_shader_target_name(shader->Type), shader_program->Name); _mesa_print_ir(shader->ir, NULL); printf("\n"); |