aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-01-11 08:22:46 +0100
committermarha <marha@users.sourceforge.net>2013-01-11 08:22:46 +0100
commit0e1adc84d471955eaabe26486154e8ec44e91dd4 (patch)
treee2363fb022bfa7b730b0032b4c35379aa2a997d6 /mesalib/src
parente59b1896b907c5ecfe184723d4c6adc2c20fa678 (diff)
parentddc05759f098f06bd93253a7bffe38640963dfb3 (diff)
downloadvcxsrv-0e1adc84d471955eaabe26486154e8ec44e91dd4.tar.gz
vcxsrv-0e1adc84d471955eaabe26486154e8ec44e91dd4.tar.bz2
vcxsrv-0e1adc84d471955eaabe26486154e8ec44e91dd4.zip
Merge remote-tracking branch 'origin/released'
* origin/released: fontconfig libX11 mesa mkfontscale xserver git update 11 jan 2013 Conflicts: mesalib/src/glsl/.gitignore mesalib/src/glsl/glcpp/.gitignore mesalib/src/mapi/glapi/gen/.gitignore mesalib/src/mesa/program/.gitignore
Diffstat (limited to 'mesalib/src')
-rw-r--r--mesalib/src/.gitignore3
-rw-r--r--mesalib/src/gallium/.gitignore1
-rw-r--r--mesalib/src/gallium/Automake.inc5
-rw-r--r--mesalib/src/gallium/Makefile.template73
-rw-r--r--mesalib/src/gallium/auxiliary/Makefile47
-rw-r--r--mesalib/src/gallium/auxiliary/Makefile.am51
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_pack_color.h2
-rwxr-xr-x[-rw-r--r--]mesalib/src/glsl/.gitignore1
-rw-r--r--mesalib/src/glsl/Makefile.sources1
-rw-r--r--mesalib/src/glsl/Makefile.template50
-rw-r--r--mesalib/src/glsl/ast_to_hir.cpp99
-rw-r--r--mesalib/src/glsl/builtin_compiler/.gitignore1
-rwxr-xr-x[-rw-r--r--]mesalib/src/glsl/glcpp/.gitignore2
-rw-r--r--mesalib/src/glsl/glsl_parser.yy1
-rw-r--r--mesalib/src/glsl/link_varyings.cpp1051
-rw-r--r--mesalib/src/glsl/link_varyings.h186
-rw-r--r--mesalib/src/glsl/linker.cpp1127
-rw-r--r--mesalib/src/glsl/linker.h9
-rw-r--r--mesalib/src/glsl/loop_controls.cpp8
-rw-r--r--mesalib/src/glsl/lower_packed_varyings.cpp95
-rw-r--r--mesalib/src/mapi/glapi/.gitignore1
-rw-r--r--mesalib/src/mapi/glapi/gen/.gitignore12
-rw-r--r--mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml23
-rw-r--r--mesalib/src/mapi/glapi/gen/GL3x.xml2
-rw-r--r--mesalib/src/mapi/glapi/gen/Makefile.am12
-rwxr-xr-xmesalib/src/mapi/glapi/gen/gl_API.xml14
-rw-r--r--mesalib/src/mesa/.gitignore1
-rw-r--r--mesalib/src/mesa/drivers/.gitignore1
-rw-r--r--mesalib/src/mesa/drivers/dri/.gitignore1
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/.gitignore1
-rw-r--r--mesalib/src/mesa/main/context.c3
-rw-r--r--mesalib/src/mesa/main/extensions.c3
-rw-r--r--mesalib/src/mesa/main/fbobject.c2
-rw-r--r--mesalib/src/mesa/main/get.c49
-rw-r--r--mesalib/src/mesa/main/get.h2
-rw-r--r--mesalib/src/mesa/main/get_hash_generator.py8
-rw-r--r--mesalib/src/mesa/main/get_hash_params.py122
-rw-r--r--mesalib/src/mesa/main/macros.h13
-rw-r--r--mesalib/src/mesa/main/mtypes.h12
-rwxr-xr-xmesalib/src/mesa/program/.gitignore1
-rw-r--r--mesalib/src/mesa/program/Makefile.am2
-rw-r--r--mesalib/src/mesa/state_tracker/Makefile2
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_texture.c4
-rw-r--r--mesalib/src/mesa/x86/.gitignore1
44 files changed, 1669 insertions, 1436 deletions
diff --git a/mesalib/src/.gitignore b/mesalib/src/.gitignore
deleted file mode 100644
index ddfb40586..000000000
--- a/mesalib/src/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/Makefile
-*.trs
-*.log
diff --git a/mesalib/src/gallium/.gitignore b/mesalib/src/gallium/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/gallium/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/gallium/Automake.inc b/mesalib/src/gallium/Automake.inc
new file mode 100644
index 000000000..fabc2af9a
--- /dev/null
+++ b/mesalib/src/gallium/Automake.inc
@@ -0,0 +1,5 @@
+GALLIUM_CFLAGS = \
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/src/gallium/include \
+ -I$(top_srcdir)/src/gallium/auxiliary \
+ $(DEFINES)
diff --git a/mesalib/src/gallium/Makefile.template b/mesalib/src/gallium/Makefile.template
deleted file mode 100644
index 036c11986..000000000
--- a/mesalib/src/gallium/Makefile.template
+++ /dev/null
@@ -1,73 +0,0 @@
-# src/gallium/Makefile.template
-
-# Template makefile for gallium libraries.
-#
-# Usage:
-# The minimum that the including makefile needs to define
-# is TOP, LIBNAME and one of of the *_SOURCES.
-#
-# Optional defines:
-# LIBRARY_INCLUDES are appended to the list of includes directories.
-# LIBRARY_DEFINES is not used for makedepend, but for compilation.
-
-### Basic defines ###
-
-OBJECTS = $(C_SOURCES:.c=.o) \
- $(CPP_SOURCES:.cpp=.o) \
- $(ASM_SOURCES:.S=.o)
-
-INCLUDES = \
- -I. \
- -I$(TOP)/src/gallium/include \
- -I$(TOP)/src/gallium/auxiliary \
- -I$(TOP)/src/gallium/drivers \
- $(LIBRARY_INCLUDES)
-
-ifeq ($(MESA_LLVM),1)
-LIBRARY_DEFINES += $(LLVM_CFLAGS)
-endif
-
-
-##### TARGETS #####
-
-default: depend lib$(LIBNAME).a $(PROGS)
-
-lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template
- $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS)
-
-depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES)
- rm -f depend
- touch depend
- $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null
-
-$(PROGS): % : %.o $(PROGS_DEPS)
- $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group
-
-# Emacs tags
-tags:
- etags `find . -name \*.[ch]` `find $(TOP)/src/gallium/include -name \*.h`
-
-# Remove .o and backup files
-clean:
- rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak $(CLEAN_EXTRA)
-
-# Dummy target
-install:
- @echo -n ""
-
-##### RULES #####
-
-%.s: %.c
- $(CC) -S $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.c
- $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.cpp
- $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-%.o: %.S
- $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
-
-sinclude depend
diff --git a/mesalib/src/gallium/auxiliary/Makefile b/mesalib/src/gallium/auxiliary/Makefile
deleted file mode 100644
index 72208f1a7..000000000
--- a/mesalib/src/gallium/auxiliary/Makefile
+++ /dev/null
@@ -1,47 +0,0 @@
-TOP = ../../..
-include $(TOP)/configs/current
-
-LIBNAME = gallium
-
-# get source lists
-include Makefile.sources
-
-C_SOURCES += $(GENERATED_SOURCES)
-
-ifeq ($(MESA_LLVM),1)
-C_SOURCES += \
- $(GALLIVM_SOURCES)
-CPP_SOURCES += \
- $(GALLIVM_CPP_SOURCES)
-
-# LLVM >= 3.2 requires -fno-rtti
-ifeq ($(shell expr `echo $(LLVM_VERSION) | sed -e 's/\([0-9]\)\.\([0-9]\)/\10\2/g'` \>= 302),1)
-CXXFLAGS += -fno-rtti
-endif
-endif
-
-
-include ../Makefile.template
-
-default install clean: %: subdirs-%
-
-subdirs-%:
- @for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE) $*) || exit 1; \
- fi \
- done
-
-indices/u_indices_gen.c: indices/u_indices_gen.py
- $(PYTHON2) $< > $@
-
-indices/u_unfilled_gen.c: indices/u_unfilled_gen.py
- $(PYTHON2) $< > $@
-
-util/u_format_srgb.c: util/u_format_srgb.py
- $(PYTHON2) $< > $@
-
-util/u_format_table.c: util/u_format_table.py util/u_format_pack.py util/u_format_parse.py util/u_format.csv
- $(PYTHON2) util/u_format_table.py util/u_format.csv > $@
-
-# DO NOT DELETE
diff --git a/mesalib/src/gallium/auxiliary/Makefile.am b/mesalib/src/gallium/auxiliary/Makefile.am
new file mode 100644
index 000000000..b8ac7c9dd
--- /dev/null
+++ b/mesalib/src/gallium/auxiliary/Makefile.am
@@ -0,0 +1,51 @@
+AUTOMAKE_OPTIONS = subdir-objects
+
+include Makefile.sources
+include $(top_srcdir)/src/gallium/Automake.inc
+
+noinst_LTLIBRARIES = libgallium.la
+
+AM_CFLAGS = \
+ -I$(top_srcdir)/src/gallium/auxiliary/util \
+ $(GALLIUM_CFLAGS)
+
+libgallium_la_SOURCES = \
+ $(C_SOURCES) \
+ $(GENERATED_SOURCES)
+
+if HAVE_MESA_LLVM
+
+AM_CFLAGS += \
+ $(LLVM_CFLAGS)
+
+AM_CXXFLAGS = \
+ $(GALLIUM_CFLAGS) \
+ $(LLVM_CXXFLAGS)
+
+if LLVM_NEEDS_FNORTTI
+
+AM_CXXFLAGS += -fno-rtti
+
+endif
+
+libgallium_la_SOURCES += \
+ $(GALLIVM_SOURCES) \
+ $(GALLIVM_CPP_SOURCES)
+
+endif
+
+indices/u_indices_gen.c: $(srcdir)/indices/u_indices_gen.py
+ $(AM_V_GEN) $(PYTHON2) $< > $@
+
+indices/u_unfilled_gen.c: $(srcdir)/indices/u_unfilled_gen.py
+ $(AM_V_GEN) $(PYTHON2) $< > $@
+
+util/u_format_srgb.c: $(srcdir)/util/u_format_srgb.py
+ $(AM_V_GEN) $(PYTHON2) $< > $@
+
+util/u_format_table.c: $(srcdir)/util/u_format_table.py $(srcdir)/util/u_format_pack.py $(srcdir)/util/u_format_parse.py $(srcdir)/util/u_format.csv
+ $(AM_V_GEN) $(PYTHON2) $(srcdir)/util/u_format_table.py $(srcdir)/util/u_format.csv > $@
+
+#XXX: Delete this when all targets are converted to automake.
+all-local: libgallium.la
+ ln -f $(builddir)/.libs/libgallium.a $(builddir)/libgallium.a
diff --git a/mesalib/src/gallium/auxiliary/util/u_pack_color.h b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
index 50ec226d8..6c6d9669c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_pack_color.h
+++ b/mesalib/src/gallium/auxiliary/util/u_pack_color.h
@@ -329,6 +329,8 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
/**
* Note rgba outside [0,1] will be clamped for int pixel formats.
+ * This will not work (and might not really be useful with float input)
+ * for pure integer formats (which lack the pack_rgba_float function).
*/
static INLINE void
util_pack_color(const float rgba[4], enum pipe_format format, union util_color *uc)
diff --git a/mesalib/src/glsl/.gitignore b/mesalib/src/glsl/.gitignore
index 9f6fbd69e..38e2117af 100644..100755
--- a/mesalib/src/glsl/.gitignore
+++ b/mesalib/src/glsl/.gitignore
@@ -5,4 +5,3 @@ glsl_parser.h
glsl_parser.output
builtin_function.cpp
glsl_test
-/Makefile
diff --git a/mesalib/src/glsl/Makefile.sources b/mesalib/src/glsl/Makefile.sources
index d984c5ca7..2227c5ef5 100644
--- a/mesalib/src/glsl/Makefile.sources
+++ b/mesalib/src/glsl/Makefile.sources
@@ -46,6 +46,7 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/link_functions.cpp \
$(GLSL_SRCDIR)/link_uniforms.cpp \
$(GLSL_SRCDIR)/link_uniform_initializers.cpp \
+ $(GLSL_SRCDIR)/link_varyings.cpp \
$(GLSL_SRCDIR)/loop_analysis.cpp \
$(GLSL_SRCDIR)/loop_controls.cpp \
$(GLSL_SRCDIR)/loop_unroll.cpp \
diff --git a/mesalib/src/glsl/Makefile.template b/mesalib/src/glsl/Makefile.template
deleted file mode 100644
index 974987a0a..000000000
--- a/mesalib/src/glsl/Makefile.template
+++ /dev/null
@@ -1,50 +0,0 @@
-# src/glsl/Makefile.template
-
-# Template makefile for glsl libraries.
-#
-# Usage:
-# The minimum that the including makefile needs to define
-# is TOP, LIBNAME and one of of the *_SOURCES.
-#
-# Optional defines:
-# LIBRARY_INCLUDES are appended to the list of includes directories.
-# LIBRARY_DEFINES is not used for makedepend, but for compilation.
-
-
-### Basic defines ###
-
-OBJECTS = $(C_SOURCES:.c=.o)
-
-INCLUDES = \
- -I. \
- $(LIBRARY_INCLUDES)
-
-
-##### TARGETS #####
-
-default: depend lib$(LIBNAME).a
-
-lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template
- $(MKLIB) -o $(LIBNAME) -static $(OBJECTS)
-
-depend: $(C_SOURCES)
- rm -f depend
- touch depend
- $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) 2> /dev/null
-
-# Remove .o and backup files
-clean:
- rm -f $(OBJECTS) lib$(LIBNAME).a depend depend.bak
-
-# Dummy target
-install:
- @echo -n ""
-
-
-##### RULES #####
-
-.c.o:
- $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@
-
--include depend
-
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index 94b63f682..f934c8e2d 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -1910,12 +1910,36 @@ ast_type_specifier::glsl_type(const char **name,
}
+/**
+ * Determine whether a toplevel variable declaration declares a varying. This
+ * function operates by examining the variable's mode and the shader target,
+ * so it correctly identifies linkage variables regardless of whether they are
+ * declared using the deprecated "varying" syntax or the new "in/out" syntax.
+ *
+ * Passing a non-toplevel variable declaration (e.g. a function parameter) to
+ * this function will produce undefined results.
+ */
+static bool
+is_varying_var(ir_variable *var, _mesa_glsl_parser_targets target)
+{
+ switch (target) {
+ case vertex_shader:
+ return var->mode == ir_var_out;
+ case fragment_shader:
+ return var->mode == ir_var_in;
+ default:
+ return var->mode == ir_var_out || var->mode == ir_var_in;
+ }
+}
+
+
static void
apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
ir_variable *var,
struct _mesa_glsl_parse_state *state,
YYLTYPE *loc,
- bool ubo_qualifiers_valid)
+ bool ubo_qualifiers_valid,
+ bool is_parameter)
{
if (qual->flags.q.invariant) {
if (var->used) {
@@ -1944,27 +1968,6 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
_mesa_glsl_shader_target_name(state->target));
}
- /* From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
- *
- * "The varying qualifier can be used only with the data types
- * float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
- * these."
- */
- if (qual->flags.q.varying) {
- const glsl_type *non_array_type;
-
- if (var->type && var->type->is_array())
- non_array_type = var->type->fields.array;
- else
- non_array_type = var->type;
-
- if (non_array_type && non_array_type->base_type != GLSL_TYPE_FLOAT) {
- var->type = glsl_type::error_type;
- _mesa_glsl_error(loc, state,
- "varying variables must be of base type float");
- }
- }
-
/* If there is no qualifier that changes the mode of the variable, leave
* the setting alone.
*/
@@ -1979,6 +1982,54 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
else if (qual->flags.q.uniform)
var->mode = ir_var_uniform;
+ if (!is_parameter && is_varying_var(var, state->target)) {
+ /* This variable is being used to link data between shader stages (in
+ * pre-glsl-1.30 parlance, it's a "varying"). Check that it has a type
+ * that is allowed for such purposes.
+ *
+ * From page 25 (page 31 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "The varying qualifier can be used only with the data types
+ * float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of
+ * these."
+ *
+ * This was relaxed in GLSL version 1.30 and GLSL ES version 3.00. From
+ * page 31 (page 37 of the PDF) of the GLSL 1.30 spec:
+ *
+ * "Fragment inputs can only be signed and unsigned integers and
+ * integer vectors, float, floating-point vectors, matrices, or
+ * arrays of these. Structures cannot be input.
+ *
+ * Similar text exists in the section on vertex shader outputs.
+ *
+ * Similar text exists in the GLSL ES 3.00 spec, except that the GLSL ES
+ * 3.00 spec claims to allow structs as well. However, this is likely
+ * an error, since section 11 of the spec ("Counting of Inputs and
+ * Outputs") enumerates all possible types of interstage linkage
+ * variables, and it does not mention structs.
+ */
+ switch (var->type->get_scalar_type()->base_type) {
+ case GLSL_TYPE_FLOAT:
+ /* Ok in all GLSL versions */
+ break;
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ if (state->is_version(130, 300))
+ break;
+ _mesa_glsl_error(loc, state,
+ "varying variables must be of base type float in %s",
+ state->get_version_string());
+ break;
+ case GLSL_TYPE_STRUCT:
+ _mesa_glsl_error(loc, state,
+ "varying variables may not be of type struct");
+ break;
+ default:
+ _mesa_glsl_error(loc, state, "illegal type for a varying variable");
+ break;
+ }
+ }
+
if (state->all_invariant && (state->current_function == NULL)) {
switch (state->target) {
case vertex_shader:
@@ -2626,7 +2677,7 @@ ast_declarator_list::hir(exec_list *instructions,
}
apply_type_qualifier_to_variable(& this->type->qualifier, var, state,
- & loc, this->ubo_qualifiers_valid);
+ & loc, this->ubo_qualifiers_valid, false);
if (this->type->qualifier.flags.q.invariant) {
if ((state->target == vertex_shader) && !(var->mode == ir_var_out ||
@@ -3065,7 +3116,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
* for function parameters the default mode is 'in'.
*/
apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc,
- false);
+ false, true);
/* From page 17 (page 23 of the PDF) of the GLSL 1.20 spec:
*
diff --git a/mesalib/src/glsl/builtin_compiler/.gitignore b/mesalib/src/glsl/builtin_compiler/.gitignore
index 40c551baa..ea7d5de9c 100644
--- a/mesalib/src/glsl/builtin_compiler/.gitignore
+++ b/mesalib/src/glsl/builtin_compiler/.gitignore
@@ -3,4 +3,3 @@ glcpp-lex.c
glcpp-parse.c
glcpp-parse.h
glcpp-parse.output
-/Makefile
diff --git a/mesalib/src/glsl/glcpp/.gitignore b/mesalib/src/glsl/glcpp/.gitignore
index c3f1f6e41..fc93edb36 100644..100755
--- a/mesalib/src/glsl/glcpp/.gitignore
+++ b/mesalib/src/glsl/glcpp/.gitignore
@@ -3,5 +3,3 @@ glcpp-lex.c
glcpp-parse.output
glcpp-parse.c
glcpp-parse.h
-tests/*.out
-/Makefile
diff --git a/mesalib/src/glsl/glsl_parser.yy b/mesalib/src/glsl/glsl_parser.yy
index d8494667b..88aae64d4 100644
--- a/mesalib/src/glsl/glsl_parser.yy
+++ b/mesalib/src/glsl/glsl_parser.yy
@@ -1542,7 +1542,6 @@ struct_declarator:
void *ctx = state;
$$ = new(ctx) ast_declaration($1, false, NULL, NULL);
$$->set_location(yylloc);
- state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
}
| any_identifier '[' constant_expression ']'
{
diff --git a/mesalib/src/glsl/link_varyings.cpp b/mesalib/src/glsl/link_varyings.cpp
new file mode 100644
index 000000000..5c27f231e
--- /dev/null
+++ b/mesalib/src/glsl/link_varyings.cpp
@@ -0,0 +1,1051 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file link_varyings.cpp
+ *
+ * Linker functions related specifically to linking varyings between shader
+ * stages.
+ */
+
+
+#include "main/mtypes.h"
+#include "glsl_symbol_table.h"
+#include "ir_optimization.h"
+#include "linker.h"
+#include "link_varyings.h"
+#include "main/macros.h"
+
+
+/**
+ * Validate that outputs from one stage match inputs of another
+ */
+bool
+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";
+
+ /* Find all shader outputs in the "producer" stage.
+ */
+ foreach_list(node, producer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ /* FINISHME: For geometry shaders, this should also look for inout
+ * FINISHME: variables.
+ */
+ if ((var == NULL) || (var->mode != ir_var_out))
+ continue;
+
+ parameters.add_variable(var);
+ }
+
+
+ /* Find all shader inputs in the "consumer" stage. Any variables that have
+ * matching outputs already in the symbol table must have the same type and
+ * qualifiers.
+ */
+ foreach_list(node, consumer->ir) {
+ ir_variable *const input = ((ir_instruction *) node)->as_variable();
+
+ /* FINISHME: For geometry shaders, this should also look for inout
+ * FINISHME: variables.
+ */
+ if ((input == NULL) || (input->mode != ir_var_in))
+ continue;
+
+ ir_variable *const output = parameters.get_variable(input->name);
+ if (output != NULL) {
+ /* Check that the types match between stages.
+ */
+ if (input->type != output->type) {
+ /* There is a bit of a special case for gl_TexCoord. This
+ * built-in is unsized by default. Applications that variable
+ * access it must redeclare it with a size. There is some
+ * language in the GLSL spec that implies the fragment shader
+ * and vertex shader do not have to agree on this size. Other
+ * driver behave this way, and one or two applications seem to
+ * rely on it.
+ *
+ * Neither declaration needs to be modified here because the array
+ * sizes are fixed later when update_array_sizes is called.
+ *
+ * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "Unlike user-defined varying variables, the built-in
+ * varying variables don't have a strict one-to-one
+ * correspondence between the vertex language and the
+ * fragment language."
+ */
+ if (!output->type->is_array()
+ || (strncmp("gl_", output->name, 3) != 0)) {
+ linker_error(prog,
+ "%s shader output `%s' declared as type `%s', "
+ "but %s shader input declared as type `%s'\n",
+ producer_stage, output->name,
+ output->type->name,
+ consumer_stage, input->type->name);
+ return false;
+ }
+ }
+
+ /* Check that all of the qualifiers match between stages.
+ */
+ if (input->centroid != output->centroid) {
+ linker_error(prog,
+ "%s shader output `%s' %s centroid qualifier, "
+ "but %s shader input %s centroid qualifier\n",
+ producer_stage,
+ output->name,
+ (output->centroid) ? "has" : "lacks",
+ consumer_stage,
+ (input->centroid) ? "has" : "lacks");
+ return false;
+ }
+
+ if (input->invariant != output->invariant) {
+ linker_error(prog,
+ "%s shader output `%s' %s invariant qualifier, "
+ "but %s shader input %s invariant qualifier\n",
+ producer_stage,
+ output->name,
+ (output->invariant) ? "has" : "lacks",
+ consumer_stage,
+ (input->invariant) ? "has" : "lacks");
+ return false;
+ }
+
+ if (input->interpolation != output->interpolation) {
+ linker_error(prog,
+ "%s shader output `%s' specifies %s "
+ "interpolation qualifier, "
+ "but %s shader input specifies %s "
+ "interpolation qualifier\n",
+ producer_stage,
+ output->name,
+ output->interpolation_string(),
+ consumer_stage,
+ input->interpolation_string());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+/**
+ * Initialize this object based on a string that was passed to
+ * glTransformFeedbackVaryings. If there is a parse error, the error is
+ * reported using linker_error(), and false is returned.
+ */
+bool
+tfeedback_decl::init(struct gl_context *ctx, struct gl_shader_program *prog,
+ const void *mem_ctx, const char *input)
+{
+ /* We don't have to be pedantic about what is a valid GLSL variable name,
+ * because any variable with an invalid name can't exist in the IR anyway.
+ */
+
+ this->location = -1;
+ this->orig_name = input;
+ this->is_clip_distance_mesa = false;
+ this->skip_components = 0;
+ this->next_buffer_separator = false;
+
+ if (ctx->Extensions.ARB_transform_feedback3) {
+ /* Parse gl_NextBuffer. */
+ if (strcmp(input, "gl_NextBuffer") == 0) {
+ this->next_buffer_separator = true;
+ return true;
+ }
+
+ /* Parse gl_SkipComponents. */
+ if (strcmp(input, "gl_SkipComponents1") == 0)
+ this->skip_components = 1;
+ else if (strcmp(input, "gl_SkipComponents2") == 0)
+ this->skip_components = 2;
+ else if (strcmp(input, "gl_SkipComponents3") == 0)
+ this->skip_components = 3;
+ else if (strcmp(input, "gl_SkipComponents4") == 0)
+ this->skip_components = 4;
+
+ if (this->skip_components)
+ return true;
+ }
+
+ /* Parse a declaration. */
+ const char *bracket = strrchr(input, '[');
+
+ if (bracket) {
+ this->var_name = ralloc_strndup(mem_ctx, input, bracket - input);
+ if (sscanf(bracket, "[%u]", &this->array_subscript) != 1) {
+ linker_error(prog, "Cannot parse transform feedback varying %s", input);
+ return false;
+ }
+ this->is_subscripted = true;
+ } else {
+ this->var_name = ralloc_strdup(mem_ctx, input);
+ this->is_subscripted = false;
+ }
+
+ /* For drivers that lower gl_ClipDistance to gl_ClipDistanceMESA, this
+ * class must behave specially to account for the fact that gl_ClipDistance
+ * is converted from a float[8] to a vec4[2].
+ */
+ if (ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerClipDistance &&
+ strcmp(this->var_name, "gl_ClipDistance") == 0) {
+ this->is_clip_distance_mesa = true;
+ }
+
+ return true;
+}
+
+
+/**
+ * Determine whether two tfeedback_decl objects refer to the same variable and
+ * array index (if applicable).
+ */
+bool
+tfeedback_decl::is_same(const tfeedback_decl &x, const tfeedback_decl &y)
+{
+ assert(x.is_varying() && y.is_varying());
+
+ if (strcmp(x.var_name, y.var_name) != 0)
+ return false;
+ if (x.is_subscripted != y.is_subscripted)
+ return false;
+ if (x.is_subscripted && x.array_subscript != y.array_subscript)
+ return false;
+ return true;
+}
+
+
+/**
+ * Assign a location for this tfeedback_decl object based on the location
+ * assignment in output_var.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+tfeedback_decl::assign_location(struct gl_context *ctx,
+ struct gl_shader_program *prog,
+ ir_variable *output_var)
+{
+ assert(this->is_varying());
+
+ if (output_var->type->is_array()) {
+ /* Array variable */
+ const unsigned matrix_cols =
+ output_var->type->fields.array->matrix_columns;
+ const unsigned vector_elements =
+ output_var->type->fields.array->vector_elements;
+ unsigned actual_array_size = this->is_clip_distance_mesa ?
+ prog->Vert.ClipDistanceArraySize : output_var->type->array_size();
+
+ if (this->is_subscripted) {
+ /* Check array bounds. */
+ if (this->array_subscript >= actual_array_size) {
+ linker_error(prog, "Transform feedback varying %s has index "
+ "%i, but the array size is %u.",
+ this->orig_name, this->array_subscript,
+ actual_array_size);
+ return false;
+ }
+ if (this->is_clip_distance_mesa) {
+ this->location =
+ output_var->location + this->array_subscript / 4;
+ this->location_frac = this->array_subscript % 4;
+ } else {
+ unsigned fine_location
+ = output_var->location * 4 + output_var->location_frac;
+ unsigned array_elem_size = vector_elements * matrix_cols;
+ fine_location += array_elem_size * this->array_subscript;
+ this->location = fine_location / 4;
+ this->location_frac = fine_location % 4;
+ }
+ this->size = 1;
+ } else {
+ this->location = output_var->location;
+ this->location_frac = output_var->location_frac;
+ this->size = actual_array_size;
+ }
+ this->vector_elements = vector_elements;
+ this->matrix_columns = matrix_cols;
+ if (this->is_clip_distance_mesa)
+ this->type = GL_FLOAT;
+ else
+ this->type = output_var->type->fields.array->gl_type;
+ } else {
+ /* Regular variable (scalar, vector, or matrix) */
+ if (this->is_subscripted) {
+ linker_error(prog, "Transform feedback varying %s requested, "
+ "but %s is not an array.",
+ this->orig_name, this->var_name);
+ return false;
+ }
+ this->location = output_var->location;
+ this->location_frac = output_var->location_frac;
+ this->size = 1;
+ this->vector_elements = output_var->type->vector_elements;
+ this->matrix_columns = output_var->type->matrix_columns;
+ this->type = output_var->type->gl_type;
+ }
+
+ /* From GL_EXT_transform_feedback:
+ * A program will fail to link if:
+ *
+ * * the total number of components to capture in any varying
+ * variable in <varyings> is greater than the constant
+ * MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT and the
+ * buffer mode is SEPARATE_ATTRIBS_EXT;
+ */
+ if (prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS &&
+ this->num_components() >
+ ctx->Const.MaxTransformFeedbackSeparateComponents) {
+ linker_error(prog, "Transform feedback varying %s exceeds "
+ "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.",
+ this->orig_name);
+ return false;
+ }
+
+ return true;
+}
+
+
+unsigned
+tfeedback_decl::get_num_outputs() const
+{
+ if (!this->is_varying()) {
+ return 0;
+ }
+
+ return (this->num_components() + this->location_frac + 3)/4;
+}
+
+
+/**
+ * Update gl_transform_feedback_info to reflect this tfeedback_decl.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
+ struct gl_transform_feedback_info *info,
+ unsigned buffer, const unsigned max_outputs) const
+{
+ assert(!this->next_buffer_separator);
+
+ /* Handle gl_SkipComponents. */
+ if (this->skip_components) {
+ info->BufferStride[buffer] += this->skip_components;
+ return true;
+ }
+
+ /* From GL_EXT_transform_feedback:
+ * A program will fail to link if:
+ *
+ * * the total number of components to capture is greater than
+ * the constant MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
+ * and the buffer mode is INTERLEAVED_ATTRIBS_EXT.
+ */
+ if (prog->TransformFeedback.BufferMode == GL_INTERLEAVED_ATTRIBS &&
+ info->BufferStride[buffer] + this->num_components() >
+ ctx->Const.MaxTransformFeedbackInterleavedComponents) {
+ linker_error(prog, "The MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS "
+ "limit has been exceeded.");
+ return false;
+ }
+
+ unsigned location = this->location;
+ unsigned location_frac = this->location_frac;
+ unsigned num_components = this->num_components();
+ while (num_components > 0) {
+ unsigned output_size = MIN2(num_components, 4 - location_frac);
+ assert(info->NumOutputs < max_outputs);
+ info->Outputs[info->NumOutputs].ComponentOffset = location_frac;
+ info->Outputs[info->NumOutputs].OutputRegister = location;
+ info->Outputs[info->NumOutputs].NumComponents = output_size;
+ info->Outputs[info->NumOutputs].OutputBuffer = buffer;
+ info->Outputs[info->NumOutputs].DstOffset = info->BufferStride[buffer];
+ ++info->NumOutputs;
+ info->BufferStride[buffer] += output_size;
+ num_components -= output_size;
+ location++;
+ location_frac = 0;
+ }
+
+ info->Varyings[info->NumVarying].Name = ralloc_strdup(prog, this->orig_name);
+ info->Varyings[info->NumVarying].Type = this->type;
+ info->Varyings[info->NumVarying].Size = this->size;
+ info->NumVarying++;
+
+ return true;
+}
+
+
+ir_variable *
+tfeedback_decl::find_output_var(gl_shader_program *prog,
+ gl_shader *producer) const
+{
+ const char *name = this->is_clip_distance_mesa
+ ? "gl_ClipDistanceMESA" : this->var_name;
+ ir_variable *var = producer->symbols->get_variable(name);
+ if (var && var->mode == ir_var_out)
+ return var;
+
+ /* From GL_EXT_transform_feedback:
+ * A program will fail to link if:
+ *
+ * * any variable name specified in the <varyings> array is not
+ * declared as an output in the geometry shader (if present) or
+ * the vertex shader (if no geometry shader is present);
+ */
+ linker_error(prog, "Transform feedback varying %s undeclared.",
+ this->orig_name);
+ return NULL;
+}
+
+
+/**
+ * Parse all the transform feedback declarations that were passed to
+ * glTransformFeedbackVaryings() and store them in tfeedback_decl objects.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
+ const void *mem_ctx, unsigned num_names,
+ char **varying_names, tfeedback_decl *decls)
+{
+ for (unsigned i = 0; i < num_names; ++i) {
+ if (!decls[i].init(ctx, prog, mem_ctx, varying_names[i]))
+ return false;
+
+ if (!decls[i].is_varying())
+ continue;
+
+ /* From GL_EXT_transform_feedback:
+ * A program will fail to link if:
+ *
+ * * any two entries in the <varyings> array specify the same varying
+ * variable;
+ *
+ * We interpret this to mean "any two entries in the <varyings> array
+ * specify the same varying variable and array index", since transform
+ * feedback of arrays would be useless otherwise.
+ */
+ for (unsigned j = 0; j < i; ++j) {
+ if (!decls[j].is_varying())
+ continue;
+
+ if (tfeedback_decl::is_same(decls[i], decls[j])) {
+ linker_error(prog, "Transform feedback varying %s specified "
+ "more than once.", varying_names[i]);
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+
+/**
+ * Store transform feedback location assignments into
+ * prog->LinkedTransformFeedback based on the data stored in tfeedback_decls.
+ *
+ * If an error occurs, the error is reported through linker_error() and false
+ * is returned.
+ */
+bool
+store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
+ unsigned num_tfeedback_decls,
+ tfeedback_decl *tfeedback_decls)
+{
+ bool separate_attribs_mode =
+ prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
+
+ ralloc_free(prog->LinkedTransformFeedback.Varyings);
+ ralloc_free(prog->LinkedTransformFeedback.Outputs);
+
+ memset(&prog->LinkedTransformFeedback, 0,
+ sizeof(prog->LinkedTransformFeedback));
+
+ prog->LinkedTransformFeedback.Varyings =
+ rzalloc_array(prog,
+ struct gl_transform_feedback_varying_info,
+ num_tfeedback_decls);
+
+ unsigned num_outputs = 0;
+ for (unsigned i = 0; i < num_tfeedback_decls; ++i)
+ num_outputs += tfeedback_decls[i].get_num_outputs();
+
+ prog->LinkedTransformFeedback.Outputs =
+ rzalloc_array(prog,
+ struct gl_transform_feedback_output,
+ num_outputs);
+
+ unsigned num_buffers = 0;
+
+ if (separate_attribs_mode) {
+ /* GL_SEPARATE_ATTRIBS */
+ for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+ if (!tfeedback_decls[i].store(ctx, prog, &prog->LinkedTransformFeedback,
+ num_buffers, num_outputs))
+ return false;
+
+ num_buffers++;
+ }
+ }
+ else {
+ /* GL_INVERLEAVED_ATTRIBS */
+ for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+ if (tfeedback_decls[i].is_next_buffer_separator()) {
+ num_buffers++;
+ continue;
+ }
+
+ if (!tfeedback_decls[i].store(ctx, prog,
+ &prog->LinkedTransformFeedback,
+ num_buffers, num_outputs))
+ return false;
+ }
+ num_buffers++;
+ }
+
+ assert(prog->LinkedTransformFeedback.NumOutputs == num_outputs);
+
+ prog->LinkedTransformFeedback.NumBuffers = num_buffers;
+ return true;
+}
+
+
+/**
+ * Data structure recording the relationship between outputs of one shader
+ * stage (the "producer") and inputs of another (the "consumer").
+ */
+class varying_matches
+{
+public:
+ varying_matches(bool disable_varying_packing);
+ ~varying_matches();
+ void record(ir_variable *producer_var, ir_variable *consumer_var);
+ unsigned assign_locations();
+ void store_locations(unsigned producer_base, unsigned consumer_base) const;
+
+private:
+ /**
+ * If true, this driver disables varying packing, so all varyings need to
+ * be aligned on slot boundaries, and take up a number of slots equal to
+ * their number of matrix columns times their array size.
+ */
+ const bool disable_varying_packing;
+
+ /**
+ * Enum representing the order in which varyings are packed within a
+ * packing class.
+ *
+ * Currently we pack vec4's first, then vec2's, then scalar values, then
+ * vec3's. This order ensures that the only vectors that are at risk of
+ * having to be "double parked" (split between two adjacent varying slots)
+ * are the vec3's.
+ */
+ enum packing_order_enum {
+ PACKING_ORDER_VEC4,
+ PACKING_ORDER_VEC2,
+ PACKING_ORDER_SCALAR,
+ PACKING_ORDER_VEC3,
+ };
+
+ static unsigned compute_packing_class(ir_variable *var);
+ static packing_order_enum compute_packing_order(ir_variable *var);
+ static int match_comparator(const void *x_generic, const void *y_generic);
+
+ /**
+ * Structure recording the relationship between a single producer output
+ * and a single consumer input.
+ */
+ struct match {
+ /**
+ * Packing class for this varying, computed by compute_packing_class().
+ */
+ unsigned packing_class;
+
+ /**
+ * Packing order for this varying, computed by compute_packing_order().
+ */
+ packing_order_enum packing_order;
+ unsigned num_components;
+
+ /**
+ * The output variable in the producer stage.
+ */
+ ir_variable *producer_var;
+
+ /**
+ * The input variable in the consumer stage.
+ */
+ ir_variable *consumer_var;
+
+ /**
+ * The location which has been assigned for this varying. This is
+ * expressed in multiples of a float, with the first generic varying
+ * (i.e. the one referred to by VERT_RESULT_VAR0 or FRAG_ATTRIB_VAR0)
+ * represented by the value 0.
+ */
+ unsigned generic_location;
+ } *matches;
+
+ /**
+ * The number of elements in the \c matches array that are currently in
+ * use.
+ */
+ unsigned num_matches;
+
+ /**
+ * The number of elements that were set aside for the \c matches array when
+ * it was allocated.
+ */
+ unsigned matches_capacity;
+};
+
+
+varying_matches::varying_matches(bool disable_varying_packing)
+ : disable_varying_packing(disable_varying_packing)
+{
+ /* Note: this initial capacity is rather arbitrarily chosen to be large
+ * enough for many cases without wasting an unreasonable amount of space.
+ * varying_matches::record() will resize the array if there are more than
+ * this number of varyings.
+ */
+ this->matches_capacity = 8;
+ this->matches = (match *)
+ malloc(sizeof(*this->matches) * this->matches_capacity);
+ this->num_matches = 0;
+}
+
+
+varying_matches::~varying_matches()
+{
+ free(this->matches);
+}
+
+
+/**
+ * Record the given producer/consumer variable pair in the list of variables
+ * that should later be assigned locations.
+ *
+ * It is permissible for \c consumer_var to be NULL (this happens if a
+ * variable is output by the producer and consumed by transform feedback, but
+ * not consumed by the consumer).
+ *
+ * If \c producer_var has already been paired up with a consumer_var, or
+ * producer_var is part of fixed pipeline functionality (and hence already has
+ * a location assigned), this function has no effect.
+ */
+void
+varying_matches::record(ir_variable *producer_var, ir_variable *consumer_var)
+{
+ if (!producer_var->is_unmatched_generic_inout) {
+ /* Either a location already exists for this variable (since it is part
+ * of fixed functionality), or it has already been recorded as part of a
+ * previous match.
+ */
+ return;
+ }
+
+ if (this->num_matches == this->matches_capacity) {
+ this->matches_capacity *= 2;
+ this->matches = (match *)
+ realloc(this->matches,
+ sizeof(*this->matches) * this->matches_capacity);
+ }
+ this->matches[this->num_matches].packing_class
+ = this->compute_packing_class(producer_var);
+ this->matches[this->num_matches].packing_order
+ = this->compute_packing_order(producer_var);
+ if (this->disable_varying_packing) {
+ unsigned slots = producer_var->type->is_array()
+ ? (producer_var->type->length
+ * producer_var->type->fields.array->matrix_columns)
+ : producer_var->type->matrix_columns;
+ this->matches[this->num_matches].num_components = 4 * slots;
+ } else {
+ this->matches[this->num_matches].num_components
+ = producer_var->type->component_slots();
+ }
+ this->matches[this->num_matches].producer_var = producer_var;
+ this->matches[this->num_matches].consumer_var = consumer_var;
+ this->num_matches++;
+ producer_var->is_unmatched_generic_inout = 0;
+ if (consumer_var)
+ consumer_var->is_unmatched_generic_inout = 0;
+}
+
+
+/**
+ * Choose locations for all of the variable matches that were previously
+ * passed to varying_matches::record().
+ */
+unsigned
+varying_matches::assign_locations()
+{
+ /* Sort varying matches into an order that makes them easy to pack. */
+ qsort(this->matches, this->num_matches, sizeof(*this->matches),
+ &varying_matches::match_comparator);
+
+ unsigned generic_location = 0;
+
+ for (unsigned i = 0; i < this->num_matches; i++) {
+ /* Advance to the next slot if this varying has a different packing
+ * class than the previous one, and we're not already on a slot
+ * boundary.
+ */
+ if (i > 0 &&
+ this->matches[i - 1].packing_class
+ != this->matches[i].packing_class) {
+ generic_location = ALIGN(generic_location, 4);
+ }
+
+ this->matches[i].generic_location = generic_location;
+
+ generic_location += this->matches[i].num_components;
+ }
+
+ return (generic_location + 3) / 4;
+}
+
+
+/**
+ * Update the producer and consumer shaders to reflect the locations
+ * assignments that were made by varying_matches::assign_locations().
+ */
+void
+varying_matches::store_locations(unsigned producer_base,
+ unsigned consumer_base) const
+{
+ for (unsigned i = 0; i < this->num_matches; i++) {
+ ir_variable *producer_var = this->matches[i].producer_var;
+ ir_variable *consumer_var = this->matches[i].consumer_var;
+ unsigned generic_location = this->matches[i].generic_location;
+ unsigned slot = generic_location / 4;
+ unsigned offset = generic_location % 4;
+
+ producer_var->location = producer_base + slot;
+ producer_var->location_frac = offset;
+ if (consumer_var) {
+ assert(consumer_var->location == -1);
+ consumer_var->location = consumer_base + slot;
+ consumer_var->location_frac = offset;
+ }
+ }
+}
+
+
+/**
+ * Compute the "packing class" of the given varying. This is an unsigned
+ * integer with the property that two variables in the same packing class can
+ * be safely backed into the same vec4.
+ */
+unsigned
+varying_matches::compute_packing_class(ir_variable *var)
+{
+ /* Without help from the back-end, there is no way to pack together
+ * variables with different interpolation types, because
+ * lower_packed_varyings must choose exactly one interpolation type for
+ * each packed varying it creates.
+ *
+ * However, we can safely pack together floats, ints, and uints, because:
+ *
+ * - varyings of base type "int" and "uint" must use the "flat"
+ * interpolation type, which can only occur in GLSL 1.30 and above.
+ *
+ * - On platforms that support GLSL 1.30 and above, lower_packed_varyings
+ * can store flat floats as ints without losing any information (using
+ * the ir_unop_bitcast_* opcodes).
+ *
+ * Therefore, the packing class depends only on the interpolation type.
+ */
+ unsigned packing_class = var->centroid ? 1 : 0;
+ packing_class *= 4;
+ packing_class += var->interpolation;
+ return packing_class;
+}
+
+
+/**
+ * Compute the "packing order" of the given varying. This is a sort key we
+ * use to determine when to attempt to pack the given varying relative to
+ * other varyings in the same packing class.
+ */
+varying_matches::packing_order_enum
+varying_matches::compute_packing_order(ir_variable *var)
+{
+ const glsl_type *element_type = var->type;
+
+ /* FINISHME: Support for "varying" records in GLSL 1.50. */
+ while (element_type->base_type == GLSL_TYPE_ARRAY) {
+ element_type = element_type->fields.array;
+ }
+
+ switch (element_type->vector_elements) {
+ case 1: return PACKING_ORDER_SCALAR;
+ case 2: return PACKING_ORDER_VEC2;
+ case 3: return PACKING_ORDER_VEC3;
+ case 4: return PACKING_ORDER_VEC4;
+ default:
+ assert(!"Unexpected value of vector_elements");
+ return PACKING_ORDER_VEC4;
+ }
+}
+
+
+/**
+ * Comparison function passed to qsort() to sort varyings by packing_class and
+ * then by packing_order.
+ */
+int
+varying_matches::match_comparator(const void *x_generic, const void *y_generic)
+{
+ const match *x = (const match *) x_generic;
+ const match *y = (const match *) y_generic;
+
+ if (x->packing_class != y->packing_class)
+ return x->packing_class - y->packing_class;
+ return x->packing_order - y->packing_order;
+}
+
+
+/**
+ * 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) {
+ 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").
+ *
+ * Variables produced by the producer may also be consumed by transform
+ * feedback.
+ *
+ * \param num_tfeedback_decls is the number of declarations indicating
+ * variables that may be consumed by transform feedback.
+ *
+ * \param tfeedback_decls is a pointer to an array of tfeedback_decl objects
+ * representing the result of parsing the strings passed to
+ * glTransformFeedbackVaryings(). assign_location() will be called for
+ * each of these objects that matches one of the outputs of the
+ * producer.
+ *
+ * When num_tfeedback_decls is nonzero, it is permissible for the consumer to
+ * be NULL. In this case, varying locations are assigned solely based on the
+ * requirements of transform feedback.
+ */
+bool
+assign_varying_locations(struct gl_context *ctx,
+ void *mem_ctx,
+ struct gl_shader_program *prog,
+ gl_shader *producer, gl_shader *consumer,
+ unsigned num_tfeedback_decls,
+ tfeedback_decl *tfeedback_decls)
+{
+ /* FINISHME: Set dynamically when geometry shader support is added. */
+ const unsigned producer_base = VERT_RESULT_VAR0;
+ const unsigned consumer_base = FRAG_ATTRIB_VAR0;
+ varying_matches matches(ctx->Const.DisableVaryingPacking);
+
+ /* Operate in a total of three passes.
+ *
+ * 1. Assign locations for any matching inputs and outputs.
+ *
+ * 2. Mark output variables in the producer that do not have locations as
+ * not being outputs. This lets the optimizer eliminate them.
+ *
+ * 3. Mark input variables in the consumer that do not have locations as
+ * not being inputs. This lets the optimizer eliminate them.
+ */
+
+ foreach_list(node, producer->ir) {
+ ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
+
+ if ((output_var == NULL) || (output_var->mode != ir_var_out))
+ continue;
+
+ ir_variable *input_var =
+ consumer ? consumer->symbols->get_variable(output_var->name) : NULL;
+
+ if (input_var && input_var->mode != ir_var_in)
+ input_var = NULL;
+
+ if (input_var) {
+ matches.record(output_var, input_var);
+ }
+ }
+
+ for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+ if (!tfeedback_decls[i].is_varying())
+ continue;
+
+ ir_variable *output_var
+ = tfeedback_decls[i].find_output_var(prog, producer);
+
+ if (output_var == NULL)
+ return false;
+
+ if (output_var->is_unmatched_generic_inout) {
+ matches.record(output_var, NULL);
+ }
+ }
+
+ const unsigned slots_used = matches.assign_locations();
+ matches.store_locations(producer_base, consumer_base);
+
+ for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
+ if (!tfeedback_decls[i].is_varying())
+ continue;
+
+ ir_variable *output_var
+ = tfeedback_decls[i].find_output_var(prog, producer);
+
+ if (!tfeedback_decls[i].assign_location(ctx, prog, output_var))
+ return false;
+ }
+
+ if (ctx->Const.DisableVaryingPacking) {
+ /* Transform feedback code assumes varyings are packed, so if the driver
+ * has disabled varying packing, make sure it does not support transform
+ * feedback.
+ */
+ assert(!ctx->Extensions.EXT_transform_feedback);
+ } else {
+ lower_packed_varyings(mem_ctx, producer_base, slots_used, ir_var_out,
+ producer);
+ if (consumer) {
+ lower_packed_varyings(mem_ctx, consumer_base, slots_used, ir_var_in,
+ consumer);
+ }
+ }
+
+ unsigned varying_vectors = 0;
+
+ if (consumer) {
+ foreach_list(node, consumer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if ((var == NULL) || (var->mode != ir_var_in))
+ continue;
+
+ if (var->is_unmatched_generic_inout) {
+ if (prog->Version <= 120) {
+ /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
+ *
+ * Only those varying variables used (i.e. read) in
+ * the fragment shader executable must be written to
+ * by the vertex shader executable; declaring
+ * superfluous varying variables in a vertex shader is
+ * permissible.
+ *
+ * We interpret this text as meaning that the VS must
+ * write the variable for the FS to read it. See
+ * "glsl1-varying read but not written" in piglit.
+ */
+
+ linker_error(prog, "fragment shader varying %s not written "
+ "by vertex shader\n.", var->name);
+ }
+
+ /* An 'in' variable is only really a shader input if its
+ * value is written by the previous stage.
+ */
+ var->mode = ir_var_auto;
+ } else if (is_varying_var(consumer->Type, var)) {
+ /* The packing rules are used for vertex shader inputs are also
+ * used for fragment shader inputs.
+ */
+ varying_vectors += count_attribute_slots(var->type);
+ }
+ }
+ }
+
+ if (ctx->API == API_OPENGLES2 || prog->IsES) {
+ if (varying_vectors > ctx->Const.MaxVarying) {
+ if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+ linker_warning(prog, "shader uses too many varying vectors "
+ "(%u > %u), but the driver will try to optimize "
+ "them out; this is non-portable out-of-spec "
+ "behavior\n",
+ varying_vectors, ctx->Const.MaxVarying);
+ } else {
+ linker_error(prog, "shader uses too many varying vectors "
+ "(%u > %u)\n",
+ varying_vectors, ctx->Const.MaxVarying);
+ return false;
+ }
+ }
+ } else {
+ const unsigned float_components = varying_vectors * 4;
+ if (float_components > ctx->Const.MaxVarying * 4) {
+ if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+ linker_warning(prog, "shader uses too many varying components "
+ "(%u > %u), but the driver will try to optimize "
+ "them out; this is non-portable out-of-spec "
+ "behavior\n",
+ float_components, ctx->Const.MaxVarying * 4);
+ } else {
+ linker_error(prog, "shader uses too many varying components "
+ "(%u > %u)\n",
+ float_components, ctx->Const.MaxVarying * 4);
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
diff --git a/mesalib/src/glsl/link_varyings.h b/mesalib/src/glsl/link_varyings.h
new file mode 100644
index 000000000..057e4b219
--- /dev/null
+++ b/mesalib/src/glsl/link_varyings.h
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+#ifndef GLSL_LINK_VARYINGS_H
+#define GLSL_LINK_VARYINGS_H
+
+/**
+ * \file link_varyings.h
+ *
+ * Linker functions related specifically to linking varyings between shader
+ * stages.
+ */
+
+
+#include "main/glheader.h"
+
+
+struct gl_shader_program;
+struct gl_shader;
+class ir_variable;
+
+
+/**
+ * Data structure tracking information about a transform feedback declaration
+ * during linking.
+ */
+class tfeedback_decl
+{
+public:
+ bool init(struct gl_context *ctx, struct gl_shader_program *prog,
+ const void *mem_ctx, const char *input);
+ static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
+ bool assign_location(struct gl_context *ctx, struct gl_shader_program *prog,
+ ir_variable *output_var);
+ unsigned get_num_outputs() const;
+ bool store(struct gl_context *ctx, struct gl_shader_program *prog,
+ struct gl_transform_feedback_info *info, unsigned buffer,
+ const unsigned max_outputs) const;
+ ir_variable *find_output_var(gl_shader_program *prog,
+ gl_shader *producer) const;
+
+ bool is_next_buffer_separator() const
+ {
+ return this->next_buffer_separator;
+ }
+
+ bool is_varying() const
+ {
+ return !this->next_buffer_separator && !this->skip_components;
+ }
+
+ /**
+ * The total number of varying components taken up by this variable. Only
+ * valid if assign_location() has been called.
+ */
+ unsigned num_components() const
+ {
+ if (this->is_clip_distance_mesa)
+ return this->size;
+ else
+ return this->vector_elements * this->matrix_columns * this->size;
+ }
+
+private:
+ /**
+ * The name that was supplied to glTransformFeedbackVaryings. Used for
+ * error reporting and glGetTransformFeedbackVarying().
+ */
+ const char *orig_name;
+
+ /**
+ * The name of the variable, parsed from orig_name.
+ */
+ const char *var_name;
+
+ /**
+ * True if the declaration in orig_name represents an array.
+ */
+ bool is_subscripted;
+
+ /**
+ * If is_subscripted is true, the subscript that was specified in orig_name.
+ */
+ unsigned array_subscript;
+
+ /**
+ * True if the variable is gl_ClipDistance and the driver lowers
+ * gl_ClipDistance to gl_ClipDistanceMESA.
+ */
+ bool is_clip_distance_mesa;
+
+ /**
+ * The vertex shader output location that the linker assigned for this
+ * variable. -1 if a location hasn't been assigned yet.
+ */
+ int location;
+
+ /**
+ * If non-zero, then this variable may be packed along with other variables
+ * into a single varying slot, so this offset should be applied when
+ * accessing components. For example, an offset of 1 means that the x
+ * component of this variable is actually stored in component y of the
+ * location specified by \c location.
+ *
+ * Only valid if location != -1.
+ */
+ unsigned location_frac;
+
+ /**
+ * If location != -1, the number of vector elements in this variable, or 1
+ * if this variable is a scalar.
+ */
+ unsigned vector_elements;
+
+ /**
+ * If location != -1, the number of matrix columns in this variable, or 1
+ * if this variable is not a matrix.
+ */
+ unsigned matrix_columns;
+
+ /** Type of the varying returned by glGetTransformFeedbackVarying() */
+ GLenum type;
+
+ /**
+ * If location != -1, the size that should be returned by
+ * glGetTransformFeedbackVarying().
+ */
+ unsigned size;
+
+ /**
+ * How many components to skip. If non-zero, this is
+ * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
+ */
+ unsigned skip_components;
+
+ /**
+ * Whether this is gl_NextBuffer from ARB_transform_feedback3.
+ */
+ bool next_buffer_separator;
+};
+
+
+bool
+cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
+ gl_shader *producer, gl_shader *consumer);
+
+bool
+parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
+ const void *mem_ctx, unsigned num_names,
+ char **varying_names, tfeedback_decl *decls);
+
+bool
+store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
+ unsigned num_tfeedback_decls,
+ tfeedback_decl *tfeedback_decls);
+
+bool
+assign_varying_locations(struct gl_context *ctx,
+ void *mem_ctx,
+ struct gl_shader_program *prog,
+ gl_shader *producer, gl_shader *consumer,
+ unsigned num_tfeedback_decls,
+ tfeedback_decl *tfeedback_decls);
+
+#endif /* GLSL_LINK_VARYINGS_H */
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index be08156e0..70f3d5bed 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -70,14 +70,13 @@
#include "program.h"
#include "program/hash_table.h"
#include "linker.h"
+#include "link_varyings.h"
#include "ir_optimization.h"
extern "C" {
#include "main/shaderobj.h"
}
-#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
-
/**
* Visitor that determines whether or not a variable is ever written.
*/
@@ -651,126 +650,6 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog)
return true;
}
-/**
- * Validate that outputs from one stage match inputs of another
- */
-bool
-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";
-
- /* Find all shader outputs in the "producer" stage.
- */
- foreach_list(node, producer->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- /* FINISHME: For geometry shaders, this should also look for inout
- * FINISHME: variables.
- */
- if ((var == NULL) || (var->mode != ir_var_out))
- continue;
-
- parameters.add_variable(var);
- }
-
-
- /* Find all shader inputs in the "consumer" stage. Any variables that have
- * matching outputs already in the symbol table must have the same type and
- * qualifiers.
- */
- foreach_list(node, consumer->ir) {
- ir_variable *const input = ((ir_instruction *) node)->as_variable();
-
- /* FINISHME: For geometry shaders, this should also look for inout
- * FINISHME: variables.
- */
- if ((input == NULL) || (input->mode != ir_var_in))
- continue;
-
- ir_variable *const output = parameters.get_variable(input->name);
- if (output != NULL) {
- /* Check that the types match between stages.
- */
- if (input->type != output->type) {
- /* There is a bit of a special case for gl_TexCoord. This
- * built-in is unsized by default. Applications that variable
- * access it must redeclare it with a size. There is some
- * language in the GLSL spec that implies the fragment shader
- * and vertex shader do not have to agree on this size. Other
- * driver behave this way, and one or two applications seem to
- * rely on it.
- *
- * Neither declaration needs to be modified here because the array
- * sizes are fixed later when update_array_sizes is called.
- *
- * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
- *
- * "Unlike user-defined varying variables, the built-in
- * varying variables don't have a strict one-to-one
- * correspondence between the vertex language and the
- * fragment language."
- */
- if (!output->type->is_array()
- || (strncmp("gl_", output->name, 3) != 0)) {
- linker_error(prog,
- "%s shader output `%s' declared as type `%s', "
- "but %s shader input declared as type `%s'\n",
- producer_stage, output->name,
- output->type->name,
- consumer_stage, input->type->name);
- return false;
- }
- }
-
- /* Check that all of the qualifiers match between stages.
- */
- if (input->centroid != output->centroid) {
- linker_error(prog,
- "%s shader output `%s' %s centroid qualifier, "
- "but %s shader input %s centroid qualifier\n",
- producer_stage,
- output->name,
- (output->centroid) ? "has" : "lacks",
- consumer_stage,
- (input->centroid) ? "has" : "lacks");
- return false;
- }
-
- if (input->invariant != output->invariant) {
- linker_error(prog,
- "%s shader output `%s' %s invariant qualifier, "
- "but %s shader input %s invariant qualifier\n",
- producer_stage,
- output->name,
- (output->invariant) ? "has" : "lacks",
- consumer_stage,
- (input->invariant) ? "has" : "lacks");
- return false;
- }
-
- if (input->interpolation != output->interpolation) {
- linker_error(prog,
- "%s shader output `%s' specifies %s "
- "interpolation qualifier, "
- "but %s shader input specifies %s "
- "interpolation qualifier\n",
- producer_stage,
- output->name,
- output->interpolation_string(),
- consumer_stage,
- input->interpolation_string());
- return false;
- }
- }
- }
-
- return true;
-}
-
/**
* Populates a shaders symbol table with all global declarations
@@ -1528,1010 +1407,6 @@ demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode)
/**
- * Data structure tracking information about a transform feedback declaration
- * during linking.
- */
-class tfeedback_decl
-{
-public:
- bool init(struct gl_context *ctx, struct gl_shader_program *prog,
- const void *mem_ctx, const char *input);
- static bool is_same(const tfeedback_decl &x, const tfeedback_decl &y);
- bool assign_location(struct gl_context *ctx, struct gl_shader_program *prog,
- ir_variable *output_var);
- unsigned get_num_outputs() const;
- bool store(struct gl_context *ctx, struct gl_shader_program *prog,
- struct gl_transform_feedback_info *info, unsigned buffer,
- const unsigned max_outputs) const;
- ir_variable *find_output_var(gl_shader_program *prog,
- gl_shader *producer) const;
-
- bool is_next_buffer_separator() const
- {
- return this->next_buffer_separator;
- }
-
- bool is_varying() const
- {
- return !this->next_buffer_separator && !this->skip_components;
- }
-
- /**
- * The total number of varying components taken up by this variable. Only
- * valid if assign_location() has been called.
- */
- unsigned num_components() const
- {
- if (this->is_clip_distance_mesa)
- return this->size;
- else
- return this->vector_elements * this->matrix_columns * this->size;
- }
-
-private:
- /**
- * The name that was supplied to glTransformFeedbackVaryings. Used for
- * error reporting and glGetTransformFeedbackVarying().
- */
- const char *orig_name;
-
- /**
- * The name of the variable, parsed from orig_name.
- */
- const char *var_name;
-
- /**
- * True if the declaration in orig_name represents an array.
- */
- bool is_subscripted;
-
- /**
- * If is_subscripted is true, the subscript that was specified in orig_name.
- */
- unsigned array_subscript;
-
- /**
- * True if the variable is gl_ClipDistance and the driver lowers
- * gl_ClipDistance to gl_ClipDistanceMESA.
- */
- bool is_clip_distance_mesa;
-
- /**
- * The vertex shader output location that the linker assigned for this
- * variable. -1 if a location hasn't been assigned yet.
- */
- int location;
-
- /**
- * If non-zero, then this variable may be packed along with other variables
- * into a single varying slot, so this offset should be applied when
- * accessing components. For example, an offset of 1 means that the x
- * component of this variable is actually stored in component y of the
- * location specified by \c location.
- *
- * Only valid if location != -1.
- */
- unsigned location_frac;
-
- /**
- * If location != -1, the number of vector elements in this variable, or 1
- * if this variable is a scalar.
- */
- unsigned vector_elements;
-
- /**
- * If location != -1, the number of matrix columns in this variable, or 1
- * if this variable is not a matrix.
- */
- unsigned matrix_columns;
-
- /** Type of the varying returned by glGetTransformFeedbackVarying() */
- GLenum type;
-
- /**
- * If location != -1, the size that should be returned by
- * glGetTransformFeedbackVarying().
- */
- unsigned size;
-
- /**
- * How many components to skip. If non-zero, this is
- * gl_SkipComponents{1,2,3,4} from ARB_transform_feedback3.
- */
- unsigned skip_components;
-
- /**
- * Whether this is gl_NextBuffer from ARB_transform_feedback3.
- */
- bool next_buffer_separator;
-};
-
-
-/**
- * Initialize this object based on a string that was passed to
- * glTransformFeedbackVaryings. If there is a parse error, the error is
- * reported using linker_error(), and false is returned.
- */
-bool
-tfeedback_decl::init(struct gl_context *ctx, struct gl_shader_program *prog,
- const void *mem_ctx, const char *input)
-{
- /* We don't have to be pedantic about what is a valid GLSL variable name,
- * because any variable with an invalid name can't exist in the IR anyway.
- */
-
- this->location = -1;
- this->orig_name = input;
- this->is_clip_distance_mesa = false;
- this->skip_components = 0;
- this->next_buffer_separator = false;
-
- if (ctx->Extensions.ARB_transform_feedback3) {
- /* Parse gl_NextBuffer. */
- if (strcmp(input, "gl_NextBuffer") == 0) {
- this->next_buffer_separator = true;
- return true;
- }
-
- /* Parse gl_SkipComponents. */
- if (strcmp(input, "gl_SkipComponents1") == 0)
- this->skip_components = 1;
- else if (strcmp(input, "gl_SkipComponents2") == 0)
- this->skip_components = 2;
- else if (strcmp(input, "gl_SkipComponents3") == 0)
- this->skip_components = 3;
- else if (strcmp(input, "gl_SkipComponents4") == 0)
- this->skip_components = 4;
-
- if (this->skip_components)
- return true;
- }
-
- /* Parse a declaration. */
- const char *bracket = strrchr(input, '[');
-
- if (bracket) {
- this->var_name = ralloc_strndup(mem_ctx, input, bracket - input);
- if (sscanf(bracket, "[%u]", &this->array_subscript) != 1) {
- linker_error(prog, "Cannot parse transform feedback varying %s", input);
- return false;
- }
- this->is_subscripted = true;
- } else {
- this->var_name = ralloc_strdup(mem_ctx, input);
- this->is_subscripted = false;
- }
-
- /* For drivers that lower gl_ClipDistance to gl_ClipDistanceMESA, this
- * class must behave specially to account for the fact that gl_ClipDistance
- * is converted from a float[8] to a vec4[2].
- */
- if (ctx->ShaderCompilerOptions[MESA_SHADER_VERTEX].LowerClipDistance &&
- strcmp(this->var_name, "gl_ClipDistance") == 0) {
- this->is_clip_distance_mesa = true;
- }
-
- return true;
-}
-
-
-/**
- * Determine whether two tfeedback_decl objects refer to the same variable and
- * array index (if applicable).
- */
-bool
-tfeedback_decl::is_same(const tfeedback_decl &x, const tfeedback_decl &y)
-{
- assert(x.is_varying() && y.is_varying());
-
- if (strcmp(x.var_name, y.var_name) != 0)
- return false;
- if (x.is_subscripted != y.is_subscripted)
- return false;
- if (x.is_subscripted && x.array_subscript != y.array_subscript)
- return false;
- return true;
-}
-
-
-/**
- * Assign a location for this tfeedback_decl object based on the location
- * assignment in output_var.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-bool
-tfeedback_decl::assign_location(struct gl_context *ctx,
- struct gl_shader_program *prog,
- ir_variable *output_var)
-{
- assert(this->is_varying());
-
- if (output_var->type->is_array()) {
- /* Array variable */
- const unsigned matrix_cols =
- output_var->type->fields.array->matrix_columns;
- const unsigned vector_elements =
- output_var->type->fields.array->vector_elements;
- unsigned actual_array_size = this->is_clip_distance_mesa ?
- prog->Vert.ClipDistanceArraySize : output_var->type->array_size();
-
- if (this->is_subscripted) {
- /* Check array bounds. */
- if (this->array_subscript >= actual_array_size) {
- linker_error(prog, "Transform feedback varying %s has index "
- "%i, but the array size is %u.",
- this->orig_name, this->array_subscript,
- actual_array_size);
- return false;
- }
- if (this->is_clip_distance_mesa) {
- this->location =
- output_var->location + this->array_subscript / 4;
- this->location_frac = this->array_subscript % 4;
- } else {
- unsigned fine_location
- = output_var->location * 4 + output_var->location_frac;
- unsigned array_elem_size = vector_elements * matrix_cols;
- fine_location += array_elem_size * this->array_subscript;
- this->location = fine_location / 4;
- this->location_frac = fine_location % 4;
- }
- this->size = 1;
- } else {
- this->location = output_var->location;
- this->location_frac = output_var->location_frac;
- this->size = actual_array_size;
- }
- this->vector_elements = vector_elements;
- this->matrix_columns = matrix_cols;
- if (this->is_clip_distance_mesa)
- this->type = GL_FLOAT;
- else
- this->type = output_var->type->fields.array->gl_type;
- } else {
- /* Regular variable (scalar, vector, or matrix) */
- if (this->is_subscripted) {
- linker_error(prog, "Transform feedback varying %s requested, "
- "but %s is not an array.",
- this->orig_name, this->var_name);
- return false;
- }
- this->location = output_var->location;
- this->location_frac = output_var->location_frac;
- this->size = 1;
- this->vector_elements = output_var->type->vector_elements;
- this->matrix_columns = output_var->type->matrix_columns;
- this->type = output_var->type->gl_type;
- }
-
- /* From GL_EXT_transform_feedback:
- * A program will fail to link if:
- *
- * * the total number of components to capture in any varying
- * variable in <varyings> is greater than the constant
- * MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT and the
- * buffer mode is SEPARATE_ATTRIBS_EXT;
- */
- if (prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS &&
- this->num_components() >
- ctx->Const.MaxTransformFeedbackSeparateComponents) {
- linker_error(prog, "Transform feedback varying %s exceeds "
- "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.",
- this->orig_name);
- return false;
- }
-
- return true;
-}
-
-
-unsigned
-tfeedback_decl::get_num_outputs() const
-{
- if (!this->is_varying()) {
- return 0;
- }
-
- return (this->num_components() + this->location_frac + 3)/4;
-}
-
-
-/**
- * Update gl_transform_feedback_info to reflect this tfeedback_decl.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-bool
-tfeedback_decl::store(struct gl_context *ctx, struct gl_shader_program *prog,
- struct gl_transform_feedback_info *info,
- unsigned buffer, const unsigned max_outputs) const
-{
- assert(!this->next_buffer_separator);
-
- /* Handle gl_SkipComponents. */
- if (this->skip_components) {
- info->BufferStride[buffer] += this->skip_components;
- return true;
- }
-
- /* From GL_EXT_transform_feedback:
- * A program will fail to link if:
- *
- * * the total number of components to capture is greater than
- * the constant MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
- * and the buffer mode is INTERLEAVED_ATTRIBS_EXT.
- */
- if (prog->TransformFeedback.BufferMode == GL_INTERLEAVED_ATTRIBS &&
- info->BufferStride[buffer] + this->num_components() >
- ctx->Const.MaxTransformFeedbackInterleavedComponents) {
- linker_error(prog, "The MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS "
- "limit has been exceeded.");
- return false;
- }
-
- unsigned location = this->location;
- unsigned location_frac = this->location_frac;
- unsigned num_components = this->num_components();
- while (num_components > 0) {
- unsigned output_size = MIN2(num_components, 4 - location_frac);
- assert(info->NumOutputs < max_outputs);
- info->Outputs[info->NumOutputs].ComponentOffset = location_frac;
- info->Outputs[info->NumOutputs].OutputRegister = location;
- info->Outputs[info->NumOutputs].NumComponents = output_size;
- info->Outputs[info->NumOutputs].OutputBuffer = buffer;
- info->Outputs[info->NumOutputs].DstOffset = info->BufferStride[buffer];
- ++info->NumOutputs;
- info->BufferStride[buffer] += output_size;
- num_components -= output_size;
- location++;
- location_frac = 0;
- }
-
- info->Varyings[info->NumVarying].Name = ralloc_strdup(prog, this->orig_name);
- info->Varyings[info->NumVarying].Type = this->type;
- info->Varyings[info->NumVarying].Size = this->size;
- info->NumVarying++;
-
- return true;
-}
-
-
-ir_variable *
-tfeedback_decl::find_output_var(gl_shader_program *prog,
- gl_shader *producer) const
-{
- const char *name = this->is_clip_distance_mesa
- ? "gl_ClipDistanceMESA" : this->var_name;
- ir_variable *var = producer->symbols->get_variable(name);
- if (var && var->mode == ir_var_out)
- return var;
-
- /* From GL_EXT_transform_feedback:
- * A program will fail to link if:
- *
- * * any variable name specified in the <varyings> array is not
- * declared as an output in the geometry shader (if present) or
- * the vertex shader (if no geometry shader is present);
- */
- linker_error(prog, "Transform feedback varying %s undeclared.",
- this->orig_name);
- return NULL;
-}
-
-
-/**
- * Parse all the transform feedback declarations that were passed to
- * glTransformFeedbackVaryings() and store them in tfeedback_decl objects.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-static bool
-parse_tfeedback_decls(struct gl_context *ctx, struct gl_shader_program *prog,
- const void *mem_ctx, unsigned num_names,
- char **varying_names, tfeedback_decl *decls)
-{
- for (unsigned i = 0; i < num_names; ++i) {
- if (!decls[i].init(ctx, prog, mem_ctx, varying_names[i]))
- return false;
-
- if (!decls[i].is_varying())
- continue;
-
- /* From GL_EXT_transform_feedback:
- * A program will fail to link if:
- *
- * * any two entries in the <varyings> array specify the same varying
- * variable;
- *
- * We interpret this to mean "any two entries in the <varyings> array
- * specify the same varying variable and array index", since transform
- * feedback of arrays would be useless otherwise.
- */
- for (unsigned j = 0; j < i; ++j) {
- if (!decls[j].is_varying())
- continue;
-
- if (tfeedback_decl::is_same(decls[i], decls[j])) {
- linker_error(prog, "Transform feedback varying %s specified "
- "more than once.", varying_names[i]);
- return false;
- }
- }
- }
- return true;
-}
-
-
-/**
- * Data structure recording the relationship between outputs of one shader
- * stage (the "producer") and inputs of another (the "consumer").
- */
-class varying_matches
-{
-public:
- varying_matches(bool disable_varying_packing);
- ~varying_matches();
- void record(ir_variable *producer_var, ir_variable *consumer_var);
- unsigned assign_locations();
- void store_locations(unsigned producer_base, unsigned consumer_base) const;
-
-private:
- /**
- * If true, this driver disables varying packing, so all varyings need to
- * be aligned on slot boundaries, and take up a number of slots equal to
- * their number of matrix columns times their array size.
- */
- const bool disable_varying_packing;
-
- /**
- * Enum representing the order in which varyings are packed within a
- * packing class.
- *
- * Currently we pack vec4's first, then vec2's, then scalar values, then
- * vec3's. This order ensures that the only vectors that are at risk of
- * having to be "double parked" (split between two adjacent varying slots)
- * are the vec3's.
- */
- enum packing_order_enum {
- PACKING_ORDER_VEC4,
- PACKING_ORDER_VEC2,
- PACKING_ORDER_SCALAR,
- PACKING_ORDER_VEC3,
- };
-
- static unsigned compute_packing_class(ir_variable *var);
- static packing_order_enum compute_packing_order(ir_variable *var);
- static int match_comparator(const void *x_generic, const void *y_generic);
-
- /**
- * Structure recording the relationship between a single producer output
- * and a single consumer input.
- */
- struct match {
- /**
- * Packing class for this varying, computed by compute_packing_class().
- */
- unsigned packing_class;
-
- /**
- * Packing order for this varying, computed by compute_packing_order().
- */
- packing_order_enum packing_order;
- unsigned num_components;
-
- /**
- * The output variable in the producer stage.
- */
- ir_variable *producer_var;
-
- /**
- * The input variable in the consumer stage.
- */
- ir_variable *consumer_var;
-
- /**
- * The location which has been assigned for this varying. This is
- * expressed in multiples of a float, with the first generic varying
- * (i.e. the one referred to by VERT_RESULT_VAR0 or FRAG_ATTRIB_VAR0)
- * represented by the value 0.
- */
- unsigned generic_location;
- } *matches;
-
- /**
- * The number of elements in the \c matches array that are currently in
- * use.
- */
- unsigned num_matches;
-
- /**
- * The number of elements that were set aside for the \c matches array when
- * it was allocated.
- */
- unsigned matches_capacity;
-};
-
-
-varying_matches::varying_matches(bool disable_varying_packing)
- : disable_varying_packing(disable_varying_packing)
-{
- /* Note: this initial capacity is rather arbitrarily chosen to be large
- * enough for many cases without wasting an unreasonable amount of space.
- * varying_matches::record() will resize the array if there are more than
- * this number of varyings.
- */
- this->matches_capacity = 8;
- this->matches = (match *)
- malloc(sizeof(*this->matches) * this->matches_capacity);
- this->num_matches = 0;
-}
-
-
-varying_matches::~varying_matches()
-{
- free(this->matches);
-}
-
-
-/**
- * Record the given producer/consumer variable pair in the list of variables
- * that should later be assigned locations.
- *
- * It is permissible for \c consumer_var to be NULL (this happens if a
- * variable is output by the producer and consumed by transform feedback, but
- * not consumed by the consumer).
- *
- * If \c producer_var has already been paired up with a consumer_var, or
- * producer_var is part of fixed pipeline functionality (and hence already has
- * a location assigned), this function has no effect.
- */
-void
-varying_matches::record(ir_variable *producer_var, ir_variable *consumer_var)
-{
- if (!producer_var->is_unmatched_generic_inout) {
- /* Either a location already exists for this variable (since it is part
- * of fixed functionality), or it has already been recorded as part of a
- * previous match.
- */
- return;
- }
-
- if (this->num_matches == this->matches_capacity) {
- this->matches_capacity *= 2;
- this->matches = (match *)
- realloc(this->matches,
- sizeof(*this->matches) * this->matches_capacity);
- }
- this->matches[this->num_matches].packing_class
- = this->compute_packing_class(producer_var);
- this->matches[this->num_matches].packing_order
- = this->compute_packing_order(producer_var);
- if (this->disable_varying_packing) {
- unsigned slots = producer_var->type->is_array()
- ? (producer_var->type->length
- * producer_var->type->fields.array->matrix_columns)
- : producer_var->type->matrix_columns;
- this->matches[this->num_matches].num_components = 4 * slots;
- } else {
- this->matches[this->num_matches].num_components
- = producer_var->type->component_slots();
- }
- this->matches[this->num_matches].producer_var = producer_var;
- this->matches[this->num_matches].consumer_var = consumer_var;
- this->num_matches++;
- producer_var->is_unmatched_generic_inout = 0;
- if (consumer_var)
- consumer_var->is_unmatched_generic_inout = 0;
-}
-
-
-/**
- * Choose locations for all of the variable matches that were previously
- * passed to varying_matches::record().
- */
-unsigned
-varying_matches::assign_locations()
-{
- /* Sort varying matches into an order that makes them easy to pack. */
- qsort(this->matches, this->num_matches, sizeof(*this->matches),
- &varying_matches::match_comparator);
-
- unsigned generic_location = 0;
-
- for (unsigned i = 0; i < this->num_matches; i++) {
- /* Advance to the next slot if this varying has a different packing
- * class than the previous one, and we're not already on a slot
- * boundary.
- */
- if (i > 0 &&
- this->matches[i - 1].packing_class
- != this->matches[i].packing_class) {
- generic_location = ALIGN(generic_location, 4);
- }
-
- this->matches[i].generic_location = generic_location;
-
- generic_location += this->matches[i].num_components;
- }
-
- return (generic_location + 3) / 4;
-}
-
-
-/**
- * Update the producer and consumer shaders to reflect the locations
- * assignments that were made by varying_matches::assign_locations().
- */
-void
-varying_matches::store_locations(unsigned producer_base,
- unsigned consumer_base) const
-{
- for (unsigned i = 0; i < this->num_matches; i++) {
- ir_variable *producer_var = this->matches[i].producer_var;
- ir_variable *consumer_var = this->matches[i].consumer_var;
- unsigned generic_location = this->matches[i].generic_location;
- unsigned slot = generic_location / 4;
- unsigned offset = generic_location % 4;
-
- producer_var->location = producer_base + slot;
- producer_var->location_frac = offset;
- if (consumer_var) {
- assert(consumer_var->location == -1);
- consumer_var->location = consumer_base + slot;
- consumer_var->location_frac = offset;
- }
- }
-}
-
-
-/**
- * Compute the "packing class" of the given varying. This is an unsigned
- * integer with the property that two variables in the same packing class can
- * be safely backed into the same vec4.
- */
-unsigned
-varying_matches::compute_packing_class(ir_variable *var)
-{
- /* In this initial implementation we conservatively assume that variables
- * can only be packed if their base type (float/int/uint/bool) matches and
- * their interpolation and centroid qualifiers match.
- *
- * TODO: relax these restrictions when the driver back-end permits.
- */
- unsigned packing_class = var->centroid ? 1 : 0;
- packing_class *= 4;
- packing_class += var->interpolation;
- packing_class *= GLSL_TYPE_ERROR;
- packing_class += var->type->get_scalar_type()->base_type;
- return packing_class;
-}
-
-
-/**
- * Compute the "packing order" of the given varying. This is a sort key we
- * use to determine when to attempt to pack the given varying relative to
- * other varyings in the same packing class.
- */
-varying_matches::packing_order_enum
-varying_matches::compute_packing_order(ir_variable *var)
-{
- const glsl_type *element_type = var->type;
-
- /* FINISHME: Support for "varying" records in GLSL 1.50. */
- while (element_type->base_type == GLSL_TYPE_ARRAY) {
- element_type = element_type->fields.array;
- }
-
- switch (element_type->vector_elements) {
- case 1: return PACKING_ORDER_SCALAR;
- case 2: return PACKING_ORDER_VEC2;
- case 3: return PACKING_ORDER_VEC3;
- case 4: return PACKING_ORDER_VEC4;
- default:
- assert(!"Unexpected value of vector_elements");
- return PACKING_ORDER_VEC4;
- }
-}
-
-
-/**
- * Comparison function passed to qsort() to sort varyings by packing_class and
- * then by packing_order.
- */
-int
-varying_matches::match_comparator(const void *x_generic, const void *y_generic)
-{
- const match *x = (const match *) x_generic;
- const match *y = (const match *) y_generic;
-
- if (x->packing_class != y->packing_class)
- return x->packing_class - y->packing_class;
- return x->packing_order - y->packing_order;
-}
-
-
-/**
- * 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) {
- 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").
- *
- * Variables produced by the producer may also be consumed by transform
- * feedback.
- *
- * \param num_tfeedback_decls is the number of declarations indicating
- * variables that may be consumed by transform feedback.
- *
- * \param tfeedback_decls is a pointer to an array of tfeedback_decl objects
- * representing the result of parsing the strings passed to
- * glTransformFeedbackVaryings(). assign_location() will be called for
- * each of these objects that matches one of the outputs of the
- * producer.
- *
- * When num_tfeedback_decls is nonzero, it is permissible for the consumer to
- * be NULL. In this case, varying locations are assigned solely based on the
- * requirements of transform feedback.
- */
-bool
-assign_varying_locations(struct gl_context *ctx,
- void *mem_ctx,
- struct gl_shader_program *prog,
- gl_shader *producer, gl_shader *consumer,
- unsigned num_tfeedback_decls,
- tfeedback_decl *tfeedback_decls)
-{
- /* FINISHME: Set dynamically when geometry shader support is added. */
- const unsigned producer_base = VERT_RESULT_VAR0;
- const unsigned consumer_base = FRAG_ATTRIB_VAR0;
- varying_matches matches(ctx->Const.DisableVaryingPacking);
-
- /* Operate in a total of three passes.
- *
- * 1. Assign locations for any matching inputs and outputs.
- *
- * 2. Mark output variables in the producer that do not have locations as
- * not being outputs. This lets the optimizer eliminate them.
- *
- * 3. Mark input variables in the consumer that do not have locations as
- * not being inputs. This lets the optimizer eliminate them.
- */
-
- foreach_list(node, producer->ir) {
- ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
-
- if ((output_var == NULL) || (output_var->mode != ir_var_out))
- continue;
-
- ir_variable *input_var =
- consumer ? consumer->symbols->get_variable(output_var->name) : NULL;
-
- if (input_var && input_var->mode != ir_var_in)
- input_var = NULL;
-
- if (input_var) {
- matches.record(output_var, input_var);
- }
- }
-
- for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
- if (!tfeedback_decls[i].is_varying())
- continue;
-
- ir_variable *output_var
- = tfeedback_decls[i].find_output_var(prog, producer);
-
- if (output_var == NULL)
- return false;
-
- if (output_var->is_unmatched_generic_inout) {
- matches.record(output_var, NULL);
- }
- }
-
- const unsigned slots_used = matches.assign_locations();
- matches.store_locations(producer_base, consumer_base);
-
- for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
- if (!tfeedback_decls[i].is_varying())
- continue;
-
- ir_variable *output_var
- = tfeedback_decls[i].find_output_var(prog, producer);
-
- if (!tfeedback_decls[i].assign_location(ctx, prog, output_var))
- return false;
- }
-
- if (ctx->Const.DisableVaryingPacking) {
- /* Transform feedback code assumes varyings are packed, so if the driver
- * has disabled varying packing, make sure it does not support transform
- * feedback.
- */
- assert(!ctx->Extensions.EXT_transform_feedback);
- } else {
- lower_packed_varyings(mem_ctx, producer_base, slots_used, ir_var_out,
- producer);
- if (consumer) {
- lower_packed_varyings(mem_ctx, consumer_base, slots_used, ir_var_in,
- consumer);
- }
- }
-
- unsigned varying_vectors = 0;
-
- if (consumer) {
- foreach_list(node, consumer->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
- if ((var == NULL) || (var->mode != ir_var_in))
- continue;
-
- if (var->is_unmatched_generic_inout) {
- if (prog->Version <= 120) {
- /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
- *
- * Only those varying variables used (i.e. read) in
- * the fragment shader executable must be written to
- * by the vertex shader executable; declaring
- * superfluous varying variables in a vertex shader is
- * permissible.
- *
- * We interpret this text as meaning that the VS must
- * write the variable for the FS to read it. See
- * "glsl1-varying read but not written" in piglit.
- */
-
- linker_error(prog, "fragment shader varying %s not written "
- "by vertex shader\n.", var->name);
- }
-
- /* An 'in' variable is only really a shader input if its
- * value is written by the previous stage.
- */
- var->mode = ir_var_auto;
- } else if (is_varying_var(consumer->Type, var)) {
- /* The packing rules are used for vertex shader inputs are also
- * used for fragment shader inputs.
- */
- varying_vectors += count_attribute_slots(var->type);
- }
- }
- }
-
- if (ctx->API == API_OPENGLES2 || prog->IsES) {
- if (varying_vectors > ctx->Const.MaxVarying) {
- if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
- linker_warning(prog, "shader uses too many varying vectors "
- "(%u > %u), but the driver will try to optimize "
- "them out; this is non-portable out-of-spec "
- "behavior\n",
- varying_vectors, ctx->Const.MaxVarying);
- } else {
- linker_error(prog, "shader uses too many varying vectors "
- "(%u > %u)\n",
- varying_vectors, ctx->Const.MaxVarying);
- return false;
- }
- }
- } else {
- const unsigned float_components = varying_vectors * 4;
- if (float_components > ctx->Const.MaxVarying * 4) {
- if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
- linker_warning(prog, "shader uses too many varying components "
- "(%u > %u), but the driver will try to optimize "
- "them out; this is non-portable out-of-spec "
- "behavior\n",
- float_components, ctx->Const.MaxVarying * 4);
- } else {
- linker_error(prog, "shader uses too many varying components "
- "(%u > %u)\n",
- float_components, ctx->Const.MaxVarying * 4);
- return false;
- }
- }
- }
-
- return true;
-}
-
-
-/**
- * Store transform feedback location assignments into
- * prog->LinkedTransformFeedback based on the data stored in tfeedback_decls.
- *
- * If an error occurs, the error is reported through linker_error() and false
- * is returned.
- */
-static bool
-store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
- unsigned num_tfeedback_decls,
- tfeedback_decl *tfeedback_decls)
-{
- bool separate_attribs_mode =
- prog->TransformFeedback.BufferMode == GL_SEPARATE_ATTRIBS;
-
- ralloc_free(prog->LinkedTransformFeedback.Varyings);
- ralloc_free(prog->LinkedTransformFeedback.Outputs);
-
- memset(&prog->LinkedTransformFeedback, 0,
- sizeof(prog->LinkedTransformFeedback));
-
- prog->LinkedTransformFeedback.Varyings =
- rzalloc_array(prog,
- struct gl_transform_feedback_varying_info,
- num_tfeedback_decls);
-
- unsigned num_outputs = 0;
- for (unsigned i = 0; i < num_tfeedback_decls; ++i)
- num_outputs += tfeedback_decls[i].get_num_outputs();
-
- prog->LinkedTransformFeedback.Outputs =
- rzalloc_array(prog,
- struct gl_transform_feedback_output,
- num_outputs);
-
- unsigned num_buffers = 0;
-
- if (separate_attribs_mode) {
- /* GL_SEPARATE_ATTRIBS */
- for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
- if (!tfeedback_decls[i].store(ctx, prog, &prog->LinkedTransformFeedback,
- num_buffers, num_outputs))
- return false;
-
- num_buffers++;
- }
- }
- else {
- /* GL_INVERLEAVED_ATTRIBS */
- for (unsigned i = 0; i < num_tfeedback_decls; ++i) {
- if (tfeedback_decls[i].is_next_buffer_separator()) {
- num_buffers++;
- continue;
- }
-
- if (!tfeedback_decls[i].store(ctx, prog,
- &prog->LinkedTransformFeedback,
- num_buffers, num_outputs))
- return false;
- }
- num_buffers++;
- }
-
- assert(prog->LinkedTransformFeedback.NumOutputs == num_outputs);
-
- prog->LinkedTransformFeedback.NumBuffers = num_buffers;
- return true;
-}
-
-/**
* Store the gl_FragDepth layout in the gl_shader_program struct.
*/
static void
diff --git a/mesalib/src/glsl/linker.h b/mesalib/src/glsl/linker.h
index 7d2e98a15..67c7f3488 100644
--- a/mesalib/src/glsl/linker.h
+++ b/mesalib/src/glsl/linker.h
@@ -91,4 +91,13 @@ private:
void recursion(const glsl_type *t, char **name, size_t name_length);
};
+void
+linker_error(gl_shader_program *prog, const char *fmt, ...);
+
+void
+linker_warning(gl_shader_program *prog, const char *fmt, ...);
+
+unsigned
+count_attribute_slots(const glsl_type *t);
+
#endif /* GLSL_LINKER_H */
diff --git a/mesalib/src/glsl/loop_controls.cpp b/mesalib/src/glsl/loop_controls.cpp
index 9acbadc50..79c820436 100644
--- a/mesalib/src/glsl/loop_controls.cpp
+++ b/mesalib/src/glsl/loop_controls.cpp
@@ -222,10 +222,10 @@ loop_control_visitor::visit_leave(ir_loop *ir)
limit = cond->operands[0]->as_constant();
switch (cmp) {
- case ir_binop_less: cmp = ir_binop_gequal; break;
- case ir_binop_greater: cmp = ir_binop_lequal; break;
- case ir_binop_lequal: cmp = ir_binop_greater; break;
- case ir_binop_gequal: cmp = ir_binop_less; break;
+ case ir_binop_less: cmp = ir_binop_greater; break;
+ case ir_binop_greater: cmp = ir_binop_less; break;
+ case ir_binop_lequal: cmp = ir_binop_gequal; break;
+ case ir_binop_gequal: cmp = ir_binop_lequal; break;
default: assert(!"Should not get here.");
}
}
diff --git a/mesalib/src/glsl/lower_packed_varyings.cpp b/mesalib/src/glsl/lower_packed_varyings.cpp
index 09c551c4e..9e7f274b7 100644
--- a/mesalib/src/glsl/lower_packed_varyings.cpp
+++ b/mesalib/src/glsl/lower_packed_varyings.cpp
@@ -66,6 +66,10 @@
* performance. However, hopefully in most cases the performance loss will
* either be absorbed by a later optimization pass, or it will be offset by
* memory bandwidth savings (because fewer varyings are used).
+ *
+ * This lowering pass also packs flat floats, ints, and uints together, by
+ * using ivec4 as the base type of flat "varyings", and using appropriate
+ * casts to convert floats and uints into ints.
*/
#include "glsl_symbol_table.h"
@@ -90,6 +94,8 @@ public:
void run(exec_list *instructions);
private:
+ ir_assignment *bitwise_assign_pack(ir_rvalue *lhs, ir_rvalue *rhs);
+ ir_assignment *bitwise_assign_unpack(ir_rvalue *lhs, ir_rvalue *rhs);
unsigned lower_rvalue(ir_rvalue *rvalue, unsigned fine_location,
ir_variable *unpacked_var, const char *name);
unsigned lower_arraylike(ir_rvalue *rvalue, unsigned array_size,
@@ -181,6 +187,75 @@ lower_packed_varyings_visitor::run(exec_list *instructions)
}
}
+
+/**
+ * Make an ir_assignment from \c rhs to \c lhs, performing appropriate
+ * bitcasts if necessary to match up types.
+ *
+ * This function is called when packing varyings.
+ */
+ir_assignment *
+lower_packed_varyings_visitor::bitwise_assign_pack(ir_rvalue *lhs,
+ ir_rvalue *rhs)
+{
+ if (lhs->type->base_type != rhs->type->base_type) {
+ /* Since we only mix types in flat varyings, and we always store flat
+ * varyings as type ivec4, we need only produce conversions from (uint
+ * or float) to int.
+ */
+ assert(lhs->type->base_type == GLSL_TYPE_INT);
+ switch (rhs->type->base_type) {
+ case GLSL_TYPE_UINT:
+ rhs = new(this->mem_ctx)
+ ir_expression(ir_unop_u2i, lhs->type, rhs);
+ break;
+ case GLSL_TYPE_FLOAT:
+ rhs = new(this->mem_ctx)
+ ir_expression(ir_unop_bitcast_f2i, lhs->type, rhs);
+ break;
+ default:
+ assert(!"Unexpected type conversion while lowering varyings");
+ break;
+ }
+ }
+ return new(this->mem_ctx) ir_assignment(lhs, rhs);
+}
+
+
+/**
+ * Make an ir_assignment from \c rhs to \c lhs, performing appropriate
+ * bitcasts if necessary to match up types.
+ *
+ * This function is called when unpacking varyings.
+ */
+ir_assignment *
+lower_packed_varyings_visitor::bitwise_assign_unpack(ir_rvalue *lhs,
+ ir_rvalue *rhs)
+{
+ if (lhs->type->base_type != rhs->type->base_type) {
+ /* Since we only mix types in flat varyings, and we always store flat
+ * varyings as type ivec4, we need only produce conversions from int to
+ * (uint or float).
+ */
+ assert(rhs->type->base_type == GLSL_TYPE_INT);
+ switch (lhs->type->base_type) {
+ case GLSL_TYPE_UINT:
+ rhs = new(this->mem_ctx)
+ ir_expression(ir_unop_i2u, lhs->type, rhs);
+ break;
+ case GLSL_TYPE_FLOAT:
+ rhs = new(this->mem_ctx)
+ ir_expression(ir_unop_bitcast_i2f, lhs->type, rhs);
+ break;
+ default:
+ assert(!"Unexpected type conversion while lowering varyings");
+ break;
+ }
+ }
+ return new(this->mem_ctx) ir_assignment(lhs, rhs);
+}
+
+
/**
* Recursively pack or unpack the given varying (or portion of a varying) by
* traversing all of its constituent vectors.
@@ -262,12 +337,12 @@ lower_packed_varyings_visitor::lower_rvalue(ir_rvalue *rvalue,
ir_swizzle *swizzle = new(this->mem_ctx)
ir_swizzle(packed_deref, swizzle_values, components);
if (this->mode == ir_var_out) {
- ir_assignment *assignment = new(this->mem_ctx)
- ir_assignment(swizzle, rvalue);
+ ir_assignment *assignment
+ = this->bitwise_assign_pack(swizzle, rvalue);
this->main_instructions->push_tail(assignment);
} else {
- ir_assignment *assignment = new(this->mem_ctx)
- ir_assignment(rvalue, swizzle);
+ ir_assignment *assignment
+ = this->bitwise_assign_unpack(rvalue, swizzle);
this->main_instructions->push_head(assignment);
}
return fine_location + components;
@@ -306,8 +381,9 @@ lower_packed_varyings_visitor::lower_arraylike(ir_rvalue *rvalue,
* If no packed varying has been created for the given varying location yet,
* create it and add it to the shader before returning it.
*
- * The newly created varying inherits its base type (float, uint, or int) and
- * interpolation parameters from \c unpacked_var.
+ * The newly created varying inherits its interpolation parameters from \c
+ * unpacked_var. Its base type is ivec4 if we are lowering a flat varying,
+ * vec4 otherwise.
*/
ir_variable *
lower_packed_varyings_visitor::get_packed_varying(unsigned location,
@@ -318,8 +394,11 @@ lower_packed_varyings_visitor::get_packed_varying(unsigned location,
assert(slot < locations_used);
if (this->packed_varyings[slot] == NULL) {
char *packed_name = ralloc_asprintf(this->mem_ctx, "packed:%s", name);
- const glsl_type *packed_type = glsl_type::get_instance(
- unpacked_var->type->get_scalar_type()->base_type, 4, 1);
+ const glsl_type *packed_type;
+ if (unpacked_var->interpolation == INTERP_QUALIFIER_FLAT)
+ packed_type = glsl_type::ivec4_type;
+ else
+ packed_type = glsl_type::vec4_type;
ir_variable *packed_var = new(this->mem_ctx)
ir_variable(packed_type, packed_name, this->mode);
packed_var->centroid = unpacked_var->centroid;
diff --git a/mesalib/src/mapi/glapi/.gitignore b/mesalib/src/mapi/glapi/.gitignore
index 25d3dfdcf..ecae56a3f 100644
--- a/mesalib/src/mapi/glapi/.gitignore
+++ b/mesalib/src/mapi/glapi/.gitignore
@@ -7,4 +7,3 @@ glapi_x86.S
glapitable.h
glapitemp.h
glprocs.h
-\Makefile
diff --git a/mesalib/src/mapi/glapi/gen/.gitignore b/mesalib/src/mapi/glapi/gen/.gitignore
index 906ce45d9..023e2856d 100644
--- a/mesalib/src/mapi/glapi/gen/.gitignore
+++ b/mesalib/src/mapi/glapi/gen/.gitignore
@@ -1,11 +1,5 @@
-enums.c
-glapi_mapi_tmp.h
-mapi_abi.py
-remap_helper.h
dispatch.h
-glapitable.h
-glapitemp.h
-glprocs.h
+enums.c
indirect.c
indirect.h
indirect_dispatch.c
@@ -19,5 +13,5 @@ indirect_size.h
indirect_size_get.c
indirect_size_get.h
indirect_table.c
-glapi_gentable.c
-/Makefile
+mapi_abi.py
+remap_helper.h
diff --git a/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml b/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml
new file mode 100644
index 000000000..3944bc7d8
--- /dev/null
+++ b/mesalib/src/mapi/glapi/gen/ARB_ES3_compatibility.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
+
+<OpenGLAPI>
+
+<category name="GL_ARB_ES3_compatibility" number="127">
+ <enum name="COMPRESSED_RGB8_ETC2" value="0x9274"/>
+ <enum name="COMPRESSED_SRGB8_ETC2" value="0x9275"/>
+ <enum name="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2" value="0x9276"/>
+ <enum name="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2" value="0x9277"/>
+ <enum name="COMPRESSED_RGBA8_ETC2_EAC" value="0x9278"/>
+ <enum name="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC" value="0x9279"/>
+ <enum name="COMPRESSED_R11_EAC" value="0x9270"/>
+ <enum name="COMPRESSED_SIGNED_R11_EAC" value="0x9271"/>
+ <enum name="COMPRESSED_RG11_EAC" value="0x9272"/>
+ <enum name="COMPRESSED_SIGNED_RG11_EAC" value="0x9273"/>
+ <enum name="PRIMITIVE_RESTART_FIXED_INDEX" value="0x8D69"/>
+ <enum name="ANY_SAMPLES_PASSED_CONSERVATIVE" value="0x8D6A"/>
+ <enum name="MAX_ELEMENT_INDEX" value="0x8D6B"/>
+ <enum name="TEXTURE_IMMUTABLE_LEVELS" value="0x82DF"/>
+</category>
+
+</OpenGLAPI>
diff --git a/mesalib/src/mapi/glapi/gen/GL3x.xml b/mesalib/src/mapi/glapi/gen/GL3x.xml
index 9ca3bbacb..1e959cc2b 100644
--- a/mesalib/src/mapi/glapi/gen/GL3x.xml
+++ b/mesalib/src/mapi/glapi/gen/GL3x.xml
@@ -599,7 +599,7 @@
<enum name="MAX_FRAGMENT_INPUT_COMPONENTS" value="0x9125"/>
<enum name="CONTEXT_PROFILE_MASK" value="0x9126"/>
- <function name="GetInteger64i_v" offset="assign" es2="3.0" exec="skip">
+ <function name="GetInteger64i_v" offset="assign" es2="3.0">
<param name="cap" type="GLenum"/>
<param name="index" type="GLuint"/>
<param name="data" type="GLint64 *"/>
diff --git a/mesalib/src/mapi/glapi/gen/Makefile.am b/mesalib/src/mapi/glapi/gen/Makefile.am
index 13943e839..ff22c8e0d 100644
--- a/mesalib/src/mapi/glapi/gen/Makefile.am
+++ b/mesalib/src/mapi/glapi/gen/Makefile.am
@@ -51,7 +51,7 @@ if HAVE_SPARC_ASM
MESA_GLAPI_ASM_OUTPUTS += $(MESA_GLAPI_DIR)/glapi_sparc.S
endif
-MESA_OUTPUTS = \
+BUILT_SOURCES = \
$(MESA_GLAPI_OUTPUTS) \
$(MESA_GLAPI_ASM_OUTPUTS) \
$(MESA_DIR)/main/enums.c \
@@ -63,6 +63,11 @@ MESA_OUTPUTS = \
$(MESA_GLX_DIR)/indirect_init.c \
$(MESA_GLX_DIR)/indirect_size.h \
$(MESA_GLX_DIR)/indirect_size.c
+EXTRA_DIST= \
+ $(BUILT_SOURCES) \
+ $(MESA_GLAPI_DIR)/glapi_x86.S \
+ $(MESA_GLAPI_DIR)/glapi_x86-64.S \
+ $(MESA_GLAPI_DIR)/glapi_sparc.S
######################################################################
@@ -101,6 +106,7 @@ API_XML = \
ARB_draw_elements_base_vertex.xml \
ARB_draw_instanced.xml \
ARB_ES2_compatibility.xml \
+ ARB_ES3_compatibility.xml \
ARB_framebuffer_object.xml \
ARB_geometry_shader4.xml \
ARB_instanced_arrays.xml \
@@ -144,6 +150,7 @@ COMMON = $(API_XML) \
gl_and_es_API.xml \
es_EXT.xml \
ARB_ES2_compatibility.xml \
+ ARB_ES3_compatibility.xml \
ARB_get_program_binary.xml \
OES_fixed_point.xml \
OES_single_precision.xml
@@ -154,8 +161,6 @@ PYTHON_GEN = $(AM_V_GEN) $(PYTHON2) $(PYTHON_FLAGS)
######################################################################
-all-local: $(MESA_OUTPUTS)
-
xorg: check-xorg-source $(XORG_OUTPUTS)
check-xorg-source:
@@ -169,7 +174,6 @@ check-xorg-source:
clean-local:
-rm -f *~ *.pyo
- -rm -f $(MESA_OUTPUTS)
######################################################################
diff --git a/mesalib/src/mapi/glapi/gen/gl_API.xml b/mesalib/src/mapi/glapi/gen/gl_API.xml
index cf973bbcd..4aa8b15e3 100755
--- a/mesalib/src/mapi/glapi/gen/gl_API.xml
+++ b/mesalib/src/mapi/glapi/gen/gl_API.xml
@@ -8277,7 +8277,11 @@
<xi:include href="ARB_robustness.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
-<!-- ARB extensions #106...#108 -->
+<!-- ARB extensions #106 -->
+
+<xi:include href="ARB_base_instance.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
+<!-- ARB extensions #108 -->
<category name="GL_ARB_transform_feedback_instanced" number="109">
<function name="DrawTransformFeedbackInstanced" offset="assign"
@@ -8304,10 +8308,14 @@
<!-- ARB extensions #114...#116 -->
-<xi:include href="ARB_base_instance.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
-
<xi:include href="ARB_texture_storage.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+<!-- ARB extensions #118...#126 -->
+
+<xi:include href="ARB_ES3_compatibility.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
+
+<!-- ARB extensions #128...#131 -->
+
<xi:include href="ARB_invalidate_subdata.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
<!-- Non-ARB extensions sorted by extension number. -->
diff --git a/mesalib/src/mesa/.gitignore b/mesalib/src/mesa/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/mesa/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/mesa/drivers/.gitignore b/mesalib/src/mesa/drivers/.gitignore
deleted file mode 100644
index 5fc607b9e..000000000
--- a/mesalib/src/mesa/drivers/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/Makefile
diff --git a/mesalib/src/mesa/drivers/dri/.gitignore b/mesalib/src/mesa/drivers/dri/.gitignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/mesalib/src/mesa/drivers/dri/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/mesalib/src/mesa/drivers/dri/swrast/.gitignore b/mesalib/src/mesa/drivers/dri/swrast/.gitignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/mesalib/src/mesa/drivers/dri/swrast/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c
index fc2db1271..561eb4685 100644
--- a/mesalib/src/mesa/main/context.c
+++ b/mesalib/src/mesa/main/context.c
@@ -656,6 +656,9 @@ _mesa_init_constants(struct gl_context *ctx)
/* PrimitiveRestart */
ctx->Const.PrimitiveRestartInSoftware = GL_FALSE;
+
+ /* ES 3.0 or ARB_ES3_compatibility */
+ ctx->Const.MaxElementIndex = 0xffffffffu;
}
diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c
index 98711b395..3486b65a4 100644
--- a/mesalib/src/mesa/main/extensions.c
+++ b/mesalib/src/mesa/main/extensions.c
@@ -34,11 +34,10 @@
#include "imports.h"
#include "context.h"
#include "extensions.h"
+#include "macros.h"
#include "mfeatures.h"
#include "mtypes.h"
-#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
-
enum {
DISABLE = 0,
GLL = 1 << API_OPENGL_COMPAT, /* GL Legacy / Compatibility */
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c
index 281cdd05c..50ad84c56 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -222,7 +222,7 @@ _mesa_get_attachment(struct gl_context *ctx, struct gl_framebuffer *fb,
}
return &fb->Attachment[BUFFER_COLOR0 + i];
case GL_DEPTH_STENCIL_ATTACHMENT:
- if (!_mesa_is_desktop_gl(ctx))
+ if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
return NULL;
/* fall-through */
case GL_DEPTH_ATTACHMENT_EXT:
diff --git a/mesalib/src/mesa/main/get.c b/mesalib/src/mesa/main/get.c
index 273a79f7f..7d922ca15 100644
--- a/mesalib/src/mesa/main/get.c
+++ b/mesalib/src/mesa/main/get.c
@@ -131,6 +131,7 @@ enum value_extra {
EXTRA_API_GL,
EXTRA_API_GL_CORE,
EXTRA_API_ES2,
+ EXTRA_API_ES3,
EXTRA_NEW_BUFFERS,
EXTRA_NEW_FRAG_CLAMP,
EXTRA_VALID_DRAW_BUFFER,
@@ -290,14 +291,30 @@ static const int extra_texture_buffer_object[] = {
EXTRA_END
};
+static const int extra_ARB_transform_feedback2_api_es3[] = {
+ EXT(ARB_transform_feedback2),
+ EXTRA_API_ES3,
+ EXTRA_END
+};
+
static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
EXT(ARB_uniform_buffer_object),
EXT(ARB_geometry_shader4),
EXTRA_END
};
+static const int extra_ARB_ES2_compatibility_api_es2[] = {
+ EXT(ARB_ES2_compatibility),
+ EXTRA_API_ES2,
+ EXTRA_END
+};
+
+static const int extra_ARB_ES3_compatibility_api_es3[] = {
+ EXT(ARB_ES3_compatibility),
+ EXTRA_API_ES3,
+ EXTRA_END
+};
-EXTRA_EXT(ARB_ES2_compatibility);
EXTRA_EXT(ARB_texture_cube_map);
EXTRA_EXT(MESA_texture_array);
EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
@@ -322,7 +339,6 @@ EXTRA_EXT(ARB_seamless_cube_map);
EXTRA_EXT(ARB_sync);
EXTRA_EXT(ARB_vertex_shader);
EXTRA_EXT(EXT_transform_feedback);
-EXTRA_EXT(ARB_transform_feedback2);
EXTRA_EXT(ARB_transform_feedback3);
EXTRA_EXT(EXT_pixel_buffer_object);
EXTRA_EXT(ARB_vertex_program);
@@ -348,6 +364,12 @@ static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
+static const int extra_gl30_es3[] = {
+ EXTRA_VERSION_30,
+ EXTRA_API_ES3,
+ EXTRA_END,
+};
+
static const int
extra_ARB_vertex_program_api_es2[] = {
EXT(ARB_vertex_program),
@@ -874,6 +896,12 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d
enabled++;
}
break;
+ case EXTRA_API_ES3:
+ if (_mesa_is_gles3(ctx)) {
+ total++;
+ enabled++;
+ }
+ break;
case EXTRA_API_GL:
if (_mesa_is_desktop_gl(ctx)) {
total++;
@@ -973,6 +1001,15 @@ find_value(const char *func, GLenum pname, void **p, union value *v)
int api;
api = ctx->API;
+ /* We index into the table_set[] list of per-API hash tables using the API's
+ * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
+ * value since it's compatible with GLES2 its entry in table_set[] is at the
+ * end.
+ */
+ STATIC_ASSERT(Elements(table_set) == API_OPENGL_LAST + 2);
+ if (_mesa_is_gles3(ctx)) {
+ api = API_OPENGL_LAST + 1;
+ }
mask = Elements(table(api)) - 1;
hash = (pname * prime_factor);
while (1) {
@@ -1626,7 +1663,7 @@ _mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
{
union value v;
enum value_type type =
- find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
+ find_value_indexed("glGetBooleani_v", pname, index, &v);
switch (type) {
case TYPE_INT:
@@ -1651,7 +1688,7 @@ _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
{
union value v;
enum value_type type =
- find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
+ find_value_indexed("glGetIntegeri_v", pname, index, &v);
switch (type) {
case TYPE_INT:
@@ -1672,11 +1709,11 @@ _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
}
void GLAPIENTRY
-_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
+_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
{
union value v;
enum value_type type =
- find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
+ find_value_indexed("glGetInteger64i_v", pname, index, &v);
switch (type) {
case TYPE_INT:
diff --git a/mesalib/src/mesa/main/get.h b/mesalib/src/mesa/main/get.h
index 4daa1aec1..6b0158f37 100644
--- a/mesalib/src/mesa/main/get.h
+++ b/mesalib/src/mesa/main/get.h
@@ -60,7 +60,7 @@ extern void GLAPIENTRY
_mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params );
extern void GLAPIENTRY
-_mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params );
+_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params );
extern void GLAPIENTRY
_mesa_GetPointerv( GLenum pname, GLvoid **params );
diff --git a/mesalib/src/mesa/main/get_hash_generator.py b/mesalib/src/mesa/main/get_hash_generator.py
index 4b3f5f490..04bf9ffe6 100644
--- a/mesalib/src/mesa/main/get_hash_generator.py
+++ b/mesalib/src/mesa/main/get_hash_generator.py
@@ -44,7 +44,7 @@ prime_factor = 89
prime_step = 281
hash_table_size = 1024
-gl_apis=set(["GL", "GL_CORE", "GLES", "GLES2"])
+gl_apis=set(["GL", "GL_CORE", "GLES", "GLES2", "GLES3"])
def print_header():
print "typedef const unsigned short table_t[%d];\n" % (hash_table_size)
@@ -67,6 +67,7 @@ api_enum = [
'GLES',
'GLES2',
'GL_CORE',
+ 'GLES3', # Not in gl_api enum in mtypes.h
]
def api_index(api):
@@ -166,6 +167,9 @@ def generate_hash_tables(enum_list, enabled_apis, param_descriptors):
for api in valid_apis:
add_to_hash_table(tables[api], hash_val, len(params))
+ # Also add GLES2 items to the GLES3 hash table
+ if api == "GLES2":
+ add_to_hash_table(tables["GLES3"], hash_val, len(params))
params.append(["GL_" + enum_name, param[1]])
@@ -183,6 +187,8 @@ def opt_to_apis(feature):
apis = set([_map[feature]])
if "GL" in apis:
apis.add("GL_CORE")
+ if "GLES2" in apis:
+ apis.add("GLES3")
return apis
diff --git a/mesalib/src/mesa/main/get_hash_params.py b/mesalib/src/mesa/main/get_hash_params.py
index ac9c79cea..3db820a77 100644
--- a/mesalib/src/mesa/main/get_hash_params.py
+++ b/mesalib/src/mesa/main/get_hash_params.py
@@ -204,12 +204,6 @@ descriptor=[
[ "TEXTURE_COORD_ARRAY_TYPE", "LOC_CUSTOM, TYPE_ENUM, offsetof(struct gl_client_array, Type), NO_EXTRA" ],
[ "TEXTURE_COORD_ARRAY_STRIDE", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Stride), NO_EXTRA" ],
-# GL_ARB_ES2_compatibility
- [ "SHADER_COMPILER", "CONST(1), extra_ARB_ES2_compatibility" ],
- [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), extra_ARB_ES2_compatibility" ],
- [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility" ],
- [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility" ],
-
# GL_ARB_multitexture
[ "MAX_TEXTURE_UNITS", "CONTEXT_INT(Const.MaxTextureUnits), NO_EXTRA" ],
[ "CLIENT_ACTIVE_TEXTURE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
@@ -232,15 +226,8 @@ descriptor=[
# GL_OES_point_sprite
[ "POINT_SPRITE_NV", "CONTEXT_BOOL(Point.PointSprite), extra_NV_point_sprite_ARB_point_sprite" ],
-# GL_ARB_fragment_shader
- [ "MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents), extra_ARB_fragment_shader" ],
-
# GL_ARB_vertex_shader
- [ "MAX_VERTEX_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.VertexProgram.MaxUniformComponents), extra_ARB_vertex_shader" ],
[ "MAX_VARYING_FLOATS_ARB", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_vertex_shader" ],
-
-# GL_EXT_texture_lod_bias
- [ "MAX_TEXTURE_LOD_BIAS_EXT", "CONTEXT_FLOAT(Const.MaxTextureLodBias), NO_EXTRA" ],
]},
@@ -317,6 +304,73 @@ descriptor=[
# GL_NV_read_buffer
[ "READ_BUFFER", "LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, extra_NV_read_buffer_api_gl" ],
+
+# GL_ARB_ES2_compatibility
+ [ "SHADER_COMPILER", "CONST(1), extra_ARB_ES2_compatibility_api_es2" ],
+ [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), extra_ARB_ES2_compatibility_api_es2" ],
+ [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility_api_es2" ],
+ [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_ES2_compatibility_api_es2" ],
+]},
+
+# GLES3 is not a typo.
+{ "apis": ["GL", "GLES", "GLES3", "GL_CORE"], "params": [
+# GL_EXT_texture_lod_bias
+ [ "MAX_TEXTURE_LOD_BIAS_EXT", "CONTEXT_FLOAT(Const.MaxTextureLodBias), NO_EXTRA" ],
+]},
+
+
+# Enums in OpenGL and ES 3.0
+{ "apis": ["GL", "GL_CORE", "GLES3"], "params": [
+# GL 3.0 / GLES3
+ [ "NUM_EXTENSIONS", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+ [ "MAJOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+ [ "MINOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_gl30_es3" ],
+
+# GL_ARB_ES3_compatibility
+ [ "MAX_ELEMENT_INDEX", "CONTEXT_INT64(Const.MaxElementIndex), extra_ARB_ES3_compatibility_api_es3"],
+
+# GL_ARB_fragment_shader
+ [ "MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents), extra_ARB_fragment_shader" ],
+
+# GL_ARB_framebuffer_object
+ [ "MAX_SAMPLES", "CONTEXT_INT(Const.MaxSamples), extra_ARB_framebuffer_object_EXT_framebuffer_multisample" ],
+
+# GL_ARB_sync
+ [ "MAX_SERVER_WAIT_TIMEOUT", "CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync" ],
+
+# GL_ARB_transform_feedback2
+ [ "TRANSFORM_FEEDBACK_BUFFER_PAUSED", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2_api_es3" ],
+ [ "TRANSFORM_FEEDBACK_BUFFER_ACTIVE", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2_api_es3" ],
+ [ "TRANSFORM_FEEDBACK_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_transform_feedback2_api_es3" ],
+
+# GL_ARB_uniform_buffer_object
+ [ "MAX_VERTEX_UNIFORM_BLOCKS", "CONTEXT_INT(Const.VertexProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_FRAGMENT_UNIFORM_BLOCKS", "CONTEXT_INT(Const.FragmentProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_COMBINED_UNIFORM_BLOCKS", "CONTEXT_INT(Const.MaxCombinedUniformBlocks), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_UNIFORM_BLOCK_SIZE", "CONTEXT_INT(Const.MaxUniformBlockSize), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_UNIFORM_BUFFER_BINDINGS", "CONTEXT_INT(Const.MaxUniformBufferBindings), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.VertexProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
+ [ "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.FragmentProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
+ [ "UNIFORM_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.UniformBufferOffsetAlignment), extra_ARB_uniform_buffer_object" ],
+ [ "UNIFORM_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_uniform_buffer_object" ],
+
+# GL_ARB_vertex_shader
+ [ "MAX_VERTEX_UNIFORM_COMPONENTS_ARB", "CONTEXT_INT(Const.VertexProgram.MaxUniformComponents), extra_ARB_vertex_shader" ],
+
+# GL_EXT_framebuffer_blit
+# NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT
+ [ "READ_FRAMEBUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_framebuffer_blit" ],
+
+# GL_EXT_pixel_buffer_object
+ [ "PIXEL_PACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
+ [ "PIXEL_UNPACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
+
+# GL_EXT_transform_feedback
+ [ "TRANSFORM_FEEDBACK_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_transform_feedback" ],
+ [ "RASTERIZER_DISCARD", "CONTEXT_BOOL(RasterDiscard), extra_EXT_transform_feedback" ],
+ [ "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents), extra_EXT_transform_feedback" ],
+ [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_EXT_transform_feedback" ],
+ [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents), extra_EXT_transform_feedback" ],
]},
{ "apis": ["GLES", "GLES2"], "params": [
@@ -327,10 +381,6 @@ descriptor=[
# Enums unique to OpenGL ES 2.0
{ "apis": ["GLES2"], "params": [
- [ "MAX_FRAGMENT_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
- [ "MAX_VARYING_VECTORS", "CONTEXT_INT(Const.MaxVarying), NO_EXTRA" ],
- [ "MAX_VERTEX_UNIFORM_VECTORS", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
- [ "SHADER_COMPILER", "CONST(1), NO_EXTRA" ],
# OES_get_program_binary
[ "NUM_SHADER_BINARY_FORMATS", "CONST(0), NO_EXTRA" ],
[ "SHADER_BINARY_FORMATS", "CONST(0), NO_EXTRA" ],
@@ -536,10 +586,6 @@ descriptor=[
[ "SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_COLOR1].BufferObj), NO_EXTRA" ],
[ "FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB", "LOC_CUSTOM, TYPE_INT, offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_FOG].BufferObj), NO_EXTRA" ],
-# GL_EXT_pixel_buffer_object
- [ "PIXEL_PACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
- [ "PIXEL_UNPACK_BUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_pixel_buffer_object" ],
-
# GL_ARB_vertex_program
# == GL_VERTEX_PROGRAM_NV
[ "VERTEX_PROGRAM_ARB", "CONTEXT_BOOL(VertexProgram.Enabled), extra_ARB_vertex_program" ],
@@ -580,38 +626,16 @@ descriptor=[
[ "NUM_LOOPBACK_COMPONENTS_ATI", "CONST(3), extra_ATI_fragment_shader" ],
[ "NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI", "CONST(3), extra_ATI_fragment_shader" ],
-# GL_EXT_framebuffer_blit
-# NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT
- [ "READ_FRAMEBUFFER_BINDING_EXT", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_framebuffer_blit" ],
-
# GL_EXT_provoking_vertex
[ "PROVOKING_VERTEX_EXT", "CONTEXT_ENUM(Light.ProvokingVertex), extra_EXT_provoking_vertex" ],
[ "QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT", "CONTEXT_BOOL(Const.QuadsFollowProvokingVertexConvention), extra_EXT_provoking_vertex" ],
-# GL_ARB_framebuffer_object
- [ "MAX_SAMPLES", "CONTEXT_INT(Const.MaxSamples), extra_ARB_framebuffer_object_EXT_framebuffer_multisample" ],
-
# GL_ARB_seamless_cube_map
[ "TEXTURE_CUBE_MAP_SEAMLESS", "CONTEXT_BOOL(Texture.CubeMapSeamless), extra_ARB_seamless_cube_map" ],
-# GL_ARB_sync
- [ "MAX_SERVER_WAIT_TIMEOUT", "CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync" ],
-
# GL_EXT_texture_integer
[ "RGBA_INTEGER_MODE_EXT", "BUFFER_BOOL(_IntegerColor), extra_EXT_texture_integer" ],
-# GL_EXT_transform_feedback
- [ "TRANSFORM_FEEDBACK_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_EXT_transform_feedback" ],
- [ "RASTERIZER_DISCARD", "CONTEXT_BOOL(RasterDiscard), extra_EXT_transform_feedback" ],
- [ "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents), extra_EXT_transform_feedback" ],
- [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_EXT_transform_feedback" ],
- [ "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents), extra_EXT_transform_feedback" ],
-
-# GL_ARB_transform_feedback2
- [ "TRANSFORM_FEEDBACK_BUFFER_PAUSED", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2" ],
- [ "TRANSFORM_FEEDBACK_BUFFER_ACTIVE", "LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_ARB_transform_feedback2" ],
- [ "TRANSFORM_FEEDBACK_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_transform_feedback2" ],
-
# GL_ARB_transform_feedback3
[ "MAX_TRANSFORM_FEEDBACK_BUFFERS", "CONTEXT_INT(Const.MaxTransformFeedbackBuffers), extra_ARB_transform_feedback3" ],
[ "MAX_VERTEX_STREAMS", "CONTEXT_INT(Const.MaxVertexStreams), extra_ARB_transform_feedback3" ],
@@ -642,9 +666,6 @@ descriptor=[
[ "SAMPLER_BINDING", "LOC_CUSTOM, TYPE_INT, GL_SAMPLER_BINDING, NO_EXTRA" ],
# GL 3.0
- [ "NUM_EXTENSIONS", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
- [ "MAJOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
- [ "MINOR_VERSION", "LOC_CUSTOM, TYPE_INT, 0, extra_version_30" ],
[ "CONTEXT_FLAGS", "CONTEXT_INT(Const.ContextFlags), extra_version_30" ],
# GL3.0 / GL_EXT_framebuffer_sRGB
@@ -671,17 +692,8 @@ descriptor=[
[ "MAX_DUAL_SOURCE_DRAW_BUFFERS", "CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended" ],
# GL_ARB_uniform_buffer_object
- [ "MAX_VERTEX_UNIFORM_BLOCKS", "CONTEXT_INT(Const.VertexProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
- [ "MAX_FRAGMENT_UNIFORM_BLOCKS", "CONTEXT_INT(Const.FragmentProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object" ],
[ "MAX_GEOMETRY_UNIFORM_BLOCKS", "CONTEXT_INT(Const.GeometryProgram.MaxUniformBlocks), extra_ARB_uniform_buffer_object_and_geometry_shader" ],
- [ "MAX_COMBINED_UNIFORM_BLOCKS", "CONTEXT_INT(Const.MaxCombinedUniformBlocks), extra_ARB_uniform_buffer_object" ],
- [ "MAX_UNIFORM_BLOCK_SIZE", "CONTEXT_INT(Const.MaxUniformBlockSize), extra_ARB_uniform_buffer_object" ],
- [ "MAX_UNIFORM_BUFFER_BINDINGS", "CONTEXT_INT(Const.MaxUniformBufferBindings), extra_ARB_uniform_buffer_object" ],
- [ "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.VertexProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
- [ "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.FragmentProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object" ],
[ "MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS", "CONTEXT_INT(Const.GeometryProgram.MaxCombinedUniformComponents), extra_ARB_uniform_buffer_object_and_geometry_shader" ],
- [ "UNIFORM_BUFFER_OFFSET_ALIGNMENT", "CONTEXT_INT(Const.UniformBufferOffsetAlignment), extra_ARB_uniform_buffer_object" ],
- [ "UNIFORM_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_uniform_buffer_object" ],
# GL_ARB_timer_query
[ "TIMESTAMP", "LOC_CUSTOM, TYPE_INT64, 0, extra_ARB_timer_query" ],
diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h
index 14a5d5fe1..d1e81fe08 100644
--- a/mesalib/src/mesa/main/macros.h
+++ b/mesalib/src/mesa/main/macros.h
@@ -656,6 +656,19 @@ INTERP_4F(GLfloat t, GLfloat dst[4], const GLfloat out[4], const GLfloat in[4])
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
+/**
+ * Align a value up to an alignment value
+ *
+ * If \c value is not already aligned to the requested alignment value, it
+ * will be rounded up.
+ *
+ * \param value Value to be rounded
+ * \param alignment Alignment value to be used. This must be a power of two.
+ *
+ * \sa ROUND_DOWN_TO()
+ */
+#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
+
/** Cross product of two 3-element vectors */
diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h
index 7c513a1c5..318dcb548 100644
--- a/mesalib/src/mesa/main/mtypes.h
+++ b/mesalib/src/mesa/main/mtypes.h
@@ -2962,6 +2962,17 @@ struct gl_constants
* Drivers that support transform feedback must set this value to GL_FALSE.
*/
GLboolean DisableVaryingPacking;
+
+ /*
+ * Maximum value supported for an index in DrawElements and friends.
+ *
+ * This must be at least (1ull<<24)-1. The default value is
+ * (1ull<<32)-1.
+ *
+ * \since ES 3.0 or GL_ARB_ES3_compatibility
+ * \sa _mesa_init_constants
+ */
+ GLuint64 MaxElementIndex;
};
@@ -3358,6 +3369,7 @@ typedef enum
API_OPENGLES,
API_OPENGLES2,
API_OPENGL_CORE,
+ API_OPENGL_LAST = API_OPENGL_CORE,
} gl_api;
/**
diff --git a/mesalib/src/mesa/program/.gitignore b/mesalib/src/mesa/program/.gitignore
index 9c23422f3..2f1601fcc 100755
--- a/mesalib/src/mesa/program/.gitignore
+++ b/mesalib/src/mesa/program/.gitignore
@@ -1,4 +1,3 @@
-/Makefile
lex.yy.c
program_parse.output
program_parse.tab.c
diff --git a/mesalib/src/mesa/program/Makefile.am b/mesalib/src/mesa/program/Makefile.am
index ea412f56f..1b8204658 100644
--- a/mesalib/src/mesa/program/Makefile.am
+++ b/mesalib/src/mesa/program/Makefile.am
@@ -35,7 +35,7 @@ DRICORE_LIB = libdricore_program.la
endif
noinst_LTLIBRARIES = $(DRICORE_LIB)
-if HAVE_GALLIUM
+if NEED_LIBPROGRAM
noinst_LTLIBRARIES += libprogram.la
else
check_LTLIBRARIES = libprogram.la
diff --git a/mesalib/src/mesa/state_tracker/Makefile b/mesalib/src/mesa/state_tracker/Makefile
deleted file mode 100644
index 0ab1dc6e6..000000000
--- a/mesalib/src/mesa/state_tracker/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-default:
- cd ../.. ; make \ No newline at end of file
diff --git a/mesalib/src/mesa/state_tracker/st_cb_texture.c b/mesalib/src/mesa/state_tracker/st_cb_texture.c
index 02fc675ae..7f07b741e 100644
--- a/mesalib/src/mesa/state_tracker/st_cb_texture.c
+++ b/mesalib/src/mesa/state_tracker/st_cb_texture.c
@@ -759,7 +759,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
struct st_context *st = st_context(ctx);
struct pipe_context *pipe = st->pipe;
struct pipe_transfer *src_trans;
- GLvoid *texDest;
+ GLubyte *texDest;
enum pipe_transfer_usage transfer_usage;
void *map;
unsigned dst_width = width;
@@ -884,7 +884,7 @@ fallback_copy_texsubimage(struct gl_context *ctx,
texImage->_BaseFormat,
texImage->TexFormat,
dstRowStride,
- (GLubyte **) &texDest,
+ &texDest,
width, height, 1,
GL_RGBA, GL_FLOAT, tempSrc, /* src */
&unpack);
diff --git a/mesalib/src/mesa/x86/.gitignore b/mesalib/src/mesa/x86/.gitignore
index ba7486c0b..ca3130d9f 100644
--- a/mesalib/src/mesa/x86/.gitignore
+++ b/mesalib/src/mesa/x86/.gitignore
@@ -1,3 +1,2 @@
-Makefile
gen_matypes
matypes.h