}
}
+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)
{
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);
#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"
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.
*/
* "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
#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"
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;
}
}
#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)
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 =
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");
}
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);
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);
}
#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"
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;
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,
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");
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)];
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");
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");