aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r--mesalib/src/glsl/SConscript4
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-lex.l49
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-parse.y61
-rw-r--r--mesalib/src/glsl/glcpp/glcpp.h5
-rw-r--r--mesalib/src/glsl/glcpp/pp.c38
-rw-r--r--mesalib/src/glsl/ir.h2
-rw-r--r--mesalib/src/glsl/ir_set_program_inouts.cpp6
-rw-r--r--mesalib/src/glsl/linker.cpp28
8 files changed, 133 insertions, 60 deletions
diff --git a/mesalib/src/glsl/SConscript b/mesalib/src/glsl/SConscript
index f8e872368..2fc57c6dd 100644
--- a/mesalib/src/glsl/SConscript
+++ b/mesalib/src/glsl/SConscript
@@ -14,8 +14,8 @@ env.Prepend(CPPPATH = [
'#src/glsl/glcpp',
])
-# Make glcpp/glcpp-parse.h and glsl_parser.h reacheable from the include path
-env.Append(CPPPATH = [Dir('.').abspath])
+# Make glcpp-parse.h and glsl_parser.h reachable from the include path.
+env.Append(CPPPATH = [Dir('.').abspath, Dir('glcpp').abspath])
env.Append(YACCFLAGS = '-d')
diff --git a/mesalib/src/glsl/glcpp/glcpp-lex.l b/mesalib/src/glsl/glcpp/glcpp-lex.l
index b34f2c0e9..7ab58cb28 100644
--- a/mesalib/src/glsl/glcpp/glcpp-lex.l
+++ b/mesalib/src/glsl/glcpp/glcpp-lex.l
@@ -40,12 +40,18 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner);
#define YY_NO_INPUT
-#define YY_USER_ACTION \
- do { \
- yylloc->first_column = yycolumn + 1; \
- yylloc->first_line = yylineno; \
- yycolumn += yyleng; \
- } while(0);
+#define YY_USER_ACTION \
+ do { \
+ if (parser->has_new_line_number) \
+ yylineno = parser->new_line_number; \
+ if (parser->has_new_source_number) \
+ yylloc->source = parser->new_source_number; \
+ yylloc->first_column = yycolumn + 1; \
+ yylloc->first_line = yylineno; \
+ yycolumn += yyleng; \
+ parser->has_new_line_number = 0; \
+ parser->has_new_source_number = 0; \
+ } while(0);
#define YY_USER_INIT \
do { \
@@ -129,35 +135,8 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
return OTHER;
}
-{HASH}line{HSPACE}+{DIGITS}{HSPACE}+{DIGITS}{HSPACE}*$ {
- /* Eat characters until the first digit is
- * encountered
- */
- char *ptr = yytext;
- while (!isdigit(*ptr))
- ptr++;
-
- /* Subtract one from the line number because
- * yylineno is zero-based instead of
- * one-based.
- */
- yylineno = strtol(ptr, &ptr, 0) - 1;
- yylloc->source = strtol(ptr, NULL, 0);
-}
-
-{HASH}line{HSPACE}+{DIGITS}{HSPACE}*$ {
- /* Eat characters until the first digit is
- * encountered
- */
- char *ptr = yytext;
- while (!isdigit(*ptr))
- ptr++;
-
- /* Subtract one from the line number because
- * yylineno is zero-based instead of
- * one-based.
- */
- yylineno = strtol(ptr, &ptr, 0) - 1;
+{HASH}line {
+ return HASH_LINE;
}
<SKIP,INITIAL>{
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y
index 9e8f9b2d6..cc4af1689 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.y
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.y
@@ -105,9 +105,15 @@ _parser_active_list_pop (glcpp_parser_t *parser);
static int
_parser_active_list_contains (glcpp_parser_t *parser, const char *identifier);
+/* Expand list, and begin lexing from the result (after first
+ * prefixing a token of type 'head_token_type').
+ */
static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
+_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
+ int head_token_type,
+ token_list_t *list);
+/* Perform macro expansion in-place on the given list. */
static void
_glcpp_parser_expand_token_list (glcpp_parser_t *parser,
token_list_t *list);
@@ -156,7 +162,7 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
%lex-param {glcpp_parser_t *parser}
%expect 0
-%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING NEWLINE OTHER PLACEHOLDER SPACE
+%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE_FUNC HASH_DEFINE_OBJ HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_LINE HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE
%token PASTE
%type <ival> expression INTEGER operator SPACE integer_constant
%type <str> IDENTIFIER INTEGER_STRING OTHER
@@ -202,6 +208,24 @@ expanded_line:
| ELIF_EXPANDED expression NEWLINE {
_glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2);
}
+| LINE_EXPANDED integer_constant NEWLINE {
+ parser->has_new_line_number = 1;
+ parser->new_line_number = $2;
+ ralloc_asprintf_rewrite_tail (&parser->output,
+ &parser->output_length,
+ "#line %" PRIiMAX,
+ $2);
+ }
+| LINE_EXPANDED integer_constant integer_constant NEWLINE {
+ parser->has_new_line_number = 1;
+ parser->new_line_number = $2;
+ parser->has_new_source_number = 1;
+ parser->new_source_number = $3;
+ ralloc_asprintf_rewrite_tail (&parser->output,
+ &parser->output_length,
+ "#line %" PRIiMAX " %" PRIiMAX,
+ $2, $3);
+ }
;
control_line:
@@ -222,6 +246,14 @@ control_line:
}
ralloc_free ($2);
}
+| HASH_LINE pp_tokens NEWLINE {
+ if (parser->skip_stack == NULL ||
+ parser->skip_stack->type == SKIP_NO_SKIP)
+ {
+ _glcpp_parser_expand_and_lex_from (parser,
+ LINE_EXPANDED, $2);
+ }
+ }
| HASH_IF conditional_tokens NEWLINE {
/* Be careful to only evaluate the 'if' expression if
* we are not skipping. When we are skipping, we
@@ -233,7 +265,8 @@ control_line:
if (parser->skip_stack == NULL ||
parser->skip_stack->type == SKIP_NO_SKIP)
{
- _glcpp_parser_expand_if (parser, IF_EXPANDED, $2);
+ _glcpp_parser_expand_and_lex_from (parser,
+ IF_EXPANDED, $2);
}
else
{
@@ -272,7 +305,8 @@ control_line:
if (parser->skip_stack &&
parser->skip_stack->type == SKIP_TO_ELSE)
{
- _glcpp_parser_expand_if (parser, ELIF_EXPANDED, $2);
+ _glcpp_parser_expand_and_lex_from (parser,
+ ELIF_EXPANDED, $2);
}
else
{
@@ -341,6 +375,9 @@ integer_constant:
expression:
integer_constant
+| IDENTIFIER {
+ $$ = 0;
+ }
| expression OR expression {
$$ = $1 || $3;
}
@@ -1109,6 +1146,11 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
parser->info_log_length = 0;
parser->error = 0;
+ parser->has_new_line_number = 0;
+ parser->new_line_number = 1;
+ parser->has_new_source_number = 0;
+ parser->new_source_number = 0;
+
/* Add pre-defined macros. */
add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
@@ -1269,14 +1311,21 @@ _token_list_create_with_one_space (void *ctx)
return list;
}
+/* Perform macro expansion on 'list', placing the resulting tokens
+ * into a new list which is initialized with a first token of type
+ * 'head_token_type'. Then begin lexing from the resulting list,
+ * (return to the current lexing source when this list is exhausted).
+ */
static void
-_glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
+_glcpp_parser_expand_and_lex_from (glcpp_parser_t *parser,
+ int head_token_type,
+ token_list_t *list)
{
token_list_t *expanded;
token_t *token;
expanded = _token_list_create (parser);
- token = _token_create_ival (parser, type, type);
+ token = _token_create_ival (parser, head_token_type, head_token_type);
_token_list_append (expanded, token);
_glcpp_parser_expand_token_list (parser, list);
_token_list_append_list (expanded, list);
diff --git a/mesalib/src/glsl/glcpp/glcpp.h b/mesalib/src/glsl/glcpp/glcpp.h
index 2d7cad2e6..a13ade69e 100644
--- a/mesalib/src/glsl/glcpp/glcpp.h
+++ b/mesalib/src/glsl/glcpp/glcpp.h
@@ -25,6 +25,7 @@
#define GLCPP_H
#include <stdint.h>
+#include <stdbool.h>
#include "../ralloc.h"
@@ -177,6 +178,10 @@ struct glcpp_parser {
size_t output_length;
size_t info_log_length;
int error;
+ bool has_new_line_number;
+ int new_line_number;
+ bool has_new_source_number;
+ int new_source_number;
};
struct gl_extensions;
diff --git a/mesalib/src/glsl/glcpp/pp.c b/mesalib/src/glsl/glcpp/pp.c
index 3640896a2..9170d14a3 100644
--- a/mesalib/src/glsl/glcpp/pp.c
+++ b/mesalib/src/glsl/glcpp/pp.c
@@ -33,15 +33,20 @@ glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
va_list ap;
parser->error = 1;
- ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
- "preprocessor error: ",
- locp->source,
- locp->first_line,
- locp->first_column);
+ ralloc_asprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length,
+ "%u:%u(%u): "
+ "preprocessor error: ",
+ locp->source,
+ locp->first_line,
+ locp->first_column);
va_start(ap, fmt);
- ralloc_vasprintf_append(&parser->info_log, fmt, ap);
+ ralloc_vasprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length,
+ fmt, ap);
va_end(ap);
- ralloc_strcat(&parser->info_log, "\n");
+ ralloc_asprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length, "\n");
}
void
@@ -49,15 +54,20 @@ glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
{
va_list ap;
- ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
- "preprocessor warning: ",
- locp->source,
- locp->first_line,
- locp->first_column);
+ ralloc_asprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length,
+ "%u:%u(%u): "
+ "preprocessor warning: ",
+ locp->source,
+ locp->first_line,
+ locp->first_column);
va_start(ap, fmt);
- ralloc_vasprintf_append(&parser->info_log, fmt, ap);
+ ralloc_vasprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length,
+ fmt, ap);
va_end(ap);
- ralloc_strcat(&parser->info_log, "\n");
+ ralloc_asprintf_rewrite_tail(&parser->info_log,
+ &parser->info_log_length, "\n");
}
/* Searches backwards for '^ *#' from a given starting point. */
diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h
index 014f3630d..505d2e74b 100644
--- a/mesalib/src/glsl/ir.h
+++ b/mesalib/src/glsl/ir.h
@@ -353,7 +353,7 @@ public:
const struct glsl_type *type;
/**
- * Delcared name of the variable
+ * Declared name of the variable
*/
const char *name;
diff --git a/mesalib/src/glsl/ir_set_program_inouts.cpp b/mesalib/src/glsl/ir_set_program_inouts.cpp
index 8f3edb969..a7415c7e3 100644
--- a/mesalib/src/glsl/ir_set_program_inouts.cpp
+++ b/mesalib/src/glsl/ir_set_program_inouts.cpp
@@ -26,7 +26,8 @@
*
* Sets the InputsRead and OutputsWritten of Mesa programs.
*
- * Additionally, for fragment shaders, sets the InterpQualifier array.
+ * Additionally, for fragment shaders, sets the InterpQualifier array and
+ * IsCentroid bitfield.
*
* Mesa programs (gl_program, not gl_shader_program) have a set of
* flags indicating which varyings are read and written. Computing
@@ -88,6 +89,8 @@ mark(struct gl_program *prog, ir_variable *var, int offset, int len,
gl_fragment_program *fprog = (gl_fragment_program *) prog;
fprog->InterpQualifier[var->location + var->index + offset + i] =
(glsl_interp_qualifier) var->interpolation;
+ if (var->centroid)
+ fprog->IsCentroid |= bitfield;
}
} else if (var->mode == ir_var_system_value) {
prog->SystemValuesRead |= bitfield;
@@ -178,6 +181,7 @@ do_set_program_inouts(exec_list *instructions, struct gl_program *prog,
if (is_fragment_shader) {
memset(((gl_fragment_program *) prog)->InterpQualifier, 0,
sizeof(((gl_fragment_program *) prog)->InterpQualifier));
+ ((gl_fragment_program *) prog)->IsCentroid = 0;
}
visit_list_elements(&v, instructions);
}
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index bdab499f0..310944752 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -1859,6 +1859,32 @@ assign_varying_location(ir_variable *input_var, ir_variable *output_var,
/**
+ * Is the given variable a varying variable to be counted against the
+ * limit in ctx->Const.MaxVarying?
+ * This includes variables such as texcoords, colors and generic
+ * varyings, but excludes variables such as gl_FrontFacing and gl_FragCoord.
+ */
+static bool
+is_varying_var(GLenum shaderType, const ir_variable *var)
+{
+ /* Only fragment shaders will take a varying variable as an input */
+ if (shaderType == GL_FRAGMENT_SHADER &&
+ var->mode == ir_var_in &&
+ var->explicit_location) {
+ switch (var->location) {
+ case FRAG_ATTRIB_WPOS:
+ case FRAG_ATTRIB_FACE:
+ case FRAG_ATTRIB_PNTC:
+ return false;
+ default:
+ return true;
+ }
+ }
+ return false;
+}
+
+
+/**
* Assign locations for all variables that are produced in one pipeline stage
* (the "producer") and consumed in the next stage (the "consumer").
*
@@ -1966,7 +1992,7 @@ assign_varying_locations(struct gl_context *ctx,
* value is written by the previous stage.
*/
var->mode = ir_var_auto;
- } else {
+ } else if (is_varying_var(consumer->Type, var)) {
/* The packing rules are used for vertex shader inputs are also
* used for fragment shader inputs.
*/