[Mesa-dev] [PATCH] mesa: include mtypes.h less

Marek Olšák maraeo at gmail.com
Wed Apr 11 20:09:07 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

- remove mtypes.h from most header files
- add main/menums.h for often used definitions
- remove main/core.h
---
 src/compiler/glsl/ast_function.cpp                 |   2 +-
 src/compiler/glsl/ast_to_hir.cpp                   |   1 +
 src/compiler/glsl/builtin_functions.cpp            |   2 +-
 src/compiler/glsl/builtin_functions.h              |   2 +
 src/compiler/glsl/builtin_variables.cpp            |   2 +-
 src/compiler/glsl/glcpp/glcpp-parse.y              |   3 +-
 src/compiler/glsl/glcpp/glcpp.c                    |   1 -
 src/compiler/glsl/glcpp/glcpp.h                    |   4 +-
 src/compiler/glsl/glcpp/pp.c                       |   1 +
 src/compiler/glsl/glsl_parser_extras.cpp           |   1 -
 src/compiler/glsl/glsl_to_nir.cpp                  |   1 +
 src/compiler/glsl/ir.cpp                           |   1 -
 src/compiler/glsl/ir.h                             |   1 -
 src/compiler/glsl/ir_constant_expression.cpp       |   2 +-
 src/compiler/glsl/ir_function_detect_recursion.cpp |   1 -
 src/compiler/glsl/ir_optimization.h                |   3 +
 src/compiler/glsl/ir_set_program_inouts.cpp        |   2 +-
 src/compiler/glsl/ir_uniform.h                     |   2 +-
 src/compiler/glsl/link_atomics.cpp                 |   2 +
 src/compiler/glsl/link_functions.cpp               |   2 +-
 src/compiler/glsl/link_interface_blocks.cpp        |   1 +
 src/compiler/glsl/link_uniform_blocks.cpp          |   3 +-
 src/compiler/glsl/link_uniform_initializers.cpp    |   2 +-
 src/compiler/glsl/link_uniforms.cpp                |   2 +-
 src/compiler/glsl/link_varyings.cpp                |   1 +
 src/compiler/glsl/linker.cpp                       |   3 +-
 src/compiler/glsl/linker.h                         |   4 +
 .../glsl/lower_blend_equation_advanced.cpp         |   1 +
 src/compiler/glsl/lower_cs_derived.cpp             |   1 +
 src/compiler/glsl/lower_distance.cpp               |   1 +
 src/compiler/glsl/lower_named_interface_blocks.cpp |   1 +
 src/compiler/glsl/lower_packed_varyings.cpp        |   1 +
 src/compiler/glsl/lower_shared_reference.cpp       |   1 +
 src/compiler/glsl/lower_tess_level.cpp             |   1 +
 src/compiler/glsl/lower_ubo_reference.cpp          |   1 +
 src/compiler/glsl/lower_vector_derefs.cpp          |   1 +
 src/compiler/glsl/lower_vertex_id.cpp              |   1 +
 src/compiler/glsl/main.cpp                         |   2 +-
 src/compiler/glsl/opt_algebraic.cpp                |   1 +
 src/compiler/glsl/opt_dead_builtin_varyings.cpp    |   2 +-
 src/compiler/glsl/s_expression.cpp                 |   2 +
 src/compiler/glsl/s_expression.h                   |   1 -
 src/compiler/glsl/shader_cache.cpp                 |   2 +-
 src/compiler/glsl/shader_cache.h                   |   3 +
 src/compiler/glsl/standalone.cpp                   |   1 +
 src/compiler/glsl/standalone_scaffolding.cpp       |   1 +
 src/compiler/glsl/standalone_scaffolding.h         |   2 +-
 src/compiler/glsl_types.h                          |   7 +-
 src/compiler/nir/nir_constant_expressions.py       |   1 -
 src/compiler/nir/nir_gather_info.c                 |   2 +-
 src/compiler/nir/nir_lower_atomics.c               |   1 +
 src/compiler/nir/nir_lower_samplers.c              |   2 -
 src/compiler/nir/nir_lower_samplers_as_deref.c     |   2 -
 src/gallium/state_trackers/glx/xlib/glx_usefont.c  |   1 -
 src/gallium/state_trackers/glx/xlib/xm_api.h       |   2 +-
 src/intel/common/gen_urb_config.c                  |   1 +
 src/intel/compiler/brw_compiler.h                  |   1 +
 src/intel/compiler/brw_eu.h                        |   1 +
 src/mesa/Makefile.sources                          |   2 +-
 src/mesa/drivers/dri/common/dri_util.h             |   6 +-
 src/mesa/drivers/dri/i915/intel_context.h          |   1 +
 src/mesa/drivers/dri/i965/brw_context.h            |   1 +
 src/mesa/drivers/dri/r200/r200_state_init.c        |   1 +
 src/mesa/drivers/dri/r200/r200_vertprog.c          |   2 +
 src/mesa/drivers/dri/radeon/radeon_state.c         |   1 -
 src/mesa/drivers/dri/radeon/radeon_state_init.c    |   1 +
 src/mesa/main/api_arrayelt.h                       |   5 +-
 src/mesa/main/buffers.h                            |   2 +-
 src/mesa/main/colormac.h                           |   1 -
 src/mesa/main/context.h                            |   1 +
 src/mesa/main/copyimage.h                          |   2 +-
 src/mesa/main/core.h                               |  53 -----
 src/mesa/main/dd.h                                 |   6 +-
 src/mesa/main/debug.c                              |   1 +
 src/mesa/main/debug_output.h                       |   3 +-
 src/mesa/main/dlist.h                              |   2 +-
 src/mesa/main/drawtex.c                            |   1 +
 src/mesa/main/errors.h                             |   4 +-
 src/mesa/main/eval.h                               |   2 +-
 src/mesa/main/execmem.c                            |   2 +-
 src/mesa/main/extensions.h                         |   2 +-
 src/mesa/main/extensions_table.c                   |   1 -
 src/mesa/main/ffvertex_prog.c                      |   1 +
 src/mesa/main/format_pack.py                       |   2 +
 src/mesa/main/format_unpack.py                     |   1 +
 src/mesa/main/format_utils.c                       |   1 +
 src/mesa/main/format_utils.h                       |   1 +
 src/mesa/main/formats.c                            |   1 +
 src/mesa/main/glformats.h                          |   2 +
 src/mesa/main/glheader.h                           |   2 +
 src/mesa/main/glspirv.c                            |   1 +
 src/mesa/main/glspirv.h                            |   4 +-
 src/mesa/main/glthread.h                           |   3 +-
 src/mesa/main/hash.c                               |   1 +
 src/mesa/main/hash.h                               |   1 +
 src/mesa/main/imports.c                            |   1 -
 src/mesa/main/imports.h                            |   1 -
 src/mesa/main/menums.h                             | 213 ++++++++++++++++++++
 src/mesa/main/mipmap.c                             |   1 +
 src/mesa/main/mipmap.h                             |   5 +-
 src/mesa/main/mtypes.h                             | 215 +--------------------
 src/mesa/main/pack.c                               |   1 +
 src/mesa/main/pack.h                               |   4 +-
 src/mesa/main/pbo.c                                |   1 +
 src/mesa/main/pbo.h                                |   4 +-
 src/mesa/main/pixeltransfer.h                      |   4 +-
 src/mesa/main/querymatrix.c                        |   1 +
 src/mesa/main/querymatrix.h                        |   2 +-
 src/mesa/main/remap.c                              |   1 +
 src/mesa/main/renderbuffer.h                       |   2 +-
 src/mesa/main/shader_query.cpp                     |   1 -
 src/mesa/main/shaderapi.h                          |   7 +-
 src/mesa/main/shaderobj.h                          |   7 +-
 src/mesa/main/texcompress_bptc.c                   |   1 +
 src/mesa/main/texcompress_etc.c                    |   1 +
 src/mesa/main/texcompress_fxt1.c                   |   2 +
 src/mesa/main/texcompress_rgtc.c                   |   1 +
 src/mesa/main/texobj.h                             |   1 -
 src/mesa/main/texstore.c                           |   1 +
 src/mesa/main/texstore.h                           |   6 +-
 src/mesa/main/texturebindless.h                    |   4 +-
 src/mesa/main/uniform_query.cpp                    |   2 +-
 src/mesa/main/varray.h                             |   2 -
 src/mesa/main/version.h                            |   7 +-
 src/mesa/main/vtxfmt.h                             |   4 +-
 src/mesa/math/m_matrix.c                           |   1 +
 src/mesa/meson.build                               |   2 +-
 src/mesa/program/ir_to_mesa.h                      |   2 +
 src/mesa/program/prog_execute.c                    |   2 +
 src/mesa/program/prog_execute.h                    |   4 +-
 src/mesa/program/prog_instruction.c                |   2 +-
 src/mesa/program/prog_parameter.h                  |  33 +++-
 src/mesa/program/prog_print.h                      |   2 +-
 src/mesa/program/prog_to_nir.c                     |   1 +
 src/mesa/program/program.h                         |   2 +-
 src/mesa/program/program_parse.y                   |   1 +
 src/mesa/program/programopt.h                      |   5 +-
 src/mesa/program/symbol_table.c                    |   1 +
 src/mesa/state_tracker/st_atom_depth.c             |   1 -
 src/mesa/state_tracker/st_cb_bitmap.c              |   1 +
 src/mesa/state_tracker/st_cb_bufferobjects.c       |   1 +
 src/mesa/state_tracker/st_cb_clear.c               |   1 +
 src/mesa/state_tracker/st_cb_drawpixels.c          |   1 +
 src/mesa/state_tracker/st_cb_texture.c             |   1 +
 src/mesa/state_tracker/st_draw.c                   |   1 +
 src/mesa/state_tracker/st_gen_mipmap.c             |   1 +
 src/mesa/state_tracker/st_glsl_to_tgsi_private.h   |   9 +-
 src/mesa/state_tracker/st_manager.h                |   2 +-
 src/mesa/state_tracker/st_program.c                |   1 +
 src/mesa/swrast/s_context.c                        |   1 +
 src/mesa/swrast/s_fog.c                            |   1 +
 src/mesa/swrast/s_span.c                           |   1 +
 src/mesa/swrast/s_stencil.c                        |   1 -
 src/mesa/swrast/s_texfetch.c                       |   1 +
 src/mesa/swrast/s_zoom.c                           |   1 +
 src/mesa/tnl/t_rebase.c                            |   1 +
 src/mesa/tnl/t_vb_fog.c                            |   1 +
 src/mesa/tnl/t_vb_texgen.c                         |   1 +
 src/mesa/tnl/tnl.h                                 |   3 +
 src/mesa/vbo/vbo_attrib.h                          |   2 -
 src/mesa/vbo/vbo_context.c                         |   2 +-
 src/mesa/vbo/vbo_exec.c                            |   1 -
 src/mesa/vbo/vbo_exec.h                            |   3 +-
 src/mesa/vbo/vbo_noop.h                            |   4 +-
 src/mesa/vbo/vbo_primitive_restart.c               |   1 +
 src/mesa/vbo/vbo_private.h                         |   1 -
 src/mesa/vbo/vbo_save.c                            |   1 -
 src/mesa/vbo/vbo_save.h                            |   1 -
 src/mesa/vbo/vbo_save_draw.c                       |   1 -
 src/mesa/vbo/vbo_save_loopback.c                   |   1 -
 src/util/register_allocate.c                       |   1 -
 src/util/xmlconfig.h                               |   1 +
 172 files changed, 470 insertions(+), 367 deletions(-)
 delete mode 100644 src/mesa/main/core.h
 create mode 100644 src/mesa/main/menums.h

diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
index 94e0a16a9c0..22d58e48c64 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -18,21 +18,21 @@
  * 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.
  */
 
 #include "glsl_symbol_table.h"
 #include "ast.h"
 #include "compiler/glsl_types.h"
 #include "ir.h"
-#include "main/core.h" /* for MIN2 */
+#include "main/mtypes.h"
 #include "main/shaderobj.h"
 #include "builtin_functions.h"
 
 static ir_rvalue *
 convert_component(ir_rvalue *src, const glsl_type *desired_type);
 
 static unsigned
 process_parameters(exec_list *instructions, exec_list *actual_parameters,
                    exec_list *parameters,
                    struct _mesa_glsl_parse_state *state)
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 168ab7eec2f..94ce3c45d03 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -47,20 +47,21 @@
  *
  * As a result, my preference is to put as little C code as possible in the
  * parser (and lexer) sources.
  */
 
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ast.h"
 #include "compiler/glsl_types.h"
 #include "util/hash_table.h"
+#include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/shaderobj.h"
 #include "ir.h"
 #include "ir_builder.h"
 #include "builtin_functions.h"
 
 using namespace ir_builder;
 
 static void
 detect_conflicting_assignments(struct _mesa_glsl_parse_state *state,
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 5f772c9eaba..e1ee9943172 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -68,21 +68,21 @@
  */
 
 #if defined(__MINGW32__) && ((__GNUC__ * 100) + __GNUC_MINOR >= 407)
 #warning "disabling optimizations for this file to work around compiler bug"
 #pragma GCC optimize("O1")
 #endif
 
 
 #include <stdarg.h>
 #include <stdio.h>
-#include "main/core.h" /* for struct gl_shader */
+#include "main/mtypes.h"
 #include "main/shaderobj.h"
 #include "ir_builder.h"
 #include "glsl_parser_extras.h"
 #include "program/prog_instruction.h"
 #include <math.h>
 #include "builtin_functions.h"
 #include "util/hash_table.h"
 
 #define M_PIf   ((float) M_PI)
 #define M_PI_2f ((float) M_PI_2)
diff --git a/src/compiler/glsl/builtin_functions.h b/src/compiler/glsl/builtin_functions.h
index 89ec9b7d5dd..50f4f3b1494 100644
--- a/src/compiler/glsl/builtin_functions.h
+++ b/src/compiler/glsl/builtin_functions.h
@@ -17,20 +17,22 @@
  * 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.
  */
 
 #ifndef BULITIN_FUNCTIONS_H
 #define BULITIN_FUNCTIONS_H
 
+struct gl_shader;
+
 extern void
 _mesa_glsl_initialize_builtin_functions();
 
 extern ir_function_signature *
 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
                                  const char *name, exec_list *actual_parameters);
 
 extern bool
 _mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state,
                                 const char *name);
diff --git a/src/compiler/glsl/builtin_variables.cpp b/src/compiler/glsl/builtin_variables.cpp
index a1cdec597fa..78fccc4e195 100644
--- a/src/compiler/glsl/builtin_variables.cpp
+++ b/src/compiler/glsl/builtin_variables.cpp
@@ -19,21 +19,21 @@
  * 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.
  */
 
 #include "ir.h"
 #include "ir_builder.h"
 #include "linker.h"
 #include "glsl_parser_extras.h"
 #include "glsl_symbol_table.h"
-#include "main/core.h"
+#include "main/mtypes.h"
 #include "main/uniforms.h"
 #include "program/prog_statevars.h"
 #include "program/prog_instruction.h"
 #include "builtin_functions.h"
 
 using namespace ir_builder;
 
 static const struct gl_builtin_uniform_element gl_NumSamples_elements[] = {
    {NULL, {STATE_NUM_SAMPLES, 0, 0}, SWIZZLE_XXXX}
 };
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index 913bce1fde8..ccb3aa18d36 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -22,22 +22,21 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <inttypes.h>
 
 #include "glcpp.h"
-#include "main/core.h" /* for struct gl_extensions */
-#include "main/mtypes.h" /* for gl_api enum */
+#include "main/mtypes.h"
 
 static void
 yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
 
 static void
 _define_object_macro(glcpp_parser_t *parser,
                      YYLTYPE *loc,
                      const char *macro,
                      token_list_t *replacements);
 
diff --git a/src/compiler/glsl/glcpp/glcpp.c b/src/compiler/glsl/glcpp/glcpp.c
index f08b14427f4..89728ffc67a 100644
--- a/src/compiler/glsl/glcpp/glcpp.c
+++ b/src/compiler/glsl/glcpp/glcpp.c
@@ -20,21 +20,20 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <getopt.h>
 
 #include "glcpp.h"
-#include "main/mtypes.h"
 #include "main/shaderobj.h"
 #include "util/strtod.h"
 
 extern int glcpp_parser_debug;
 
 void
 _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
                        struct gl_shader *sh)
 {
    (void) ctx;
diff --git a/src/compiler/glsl/glcpp/glcpp.h b/src/compiler/glsl/glcpp/glcpp.h
index 9d997cd9240..c7e382ed30c 100644
--- a/src/compiler/glsl/glcpp/glcpp.h
+++ b/src/compiler/glsl/glcpp/glcpp.h
@@ -20,28 +20,30 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 #ifndef GLCPP_H
 #define GLCPP_H
 
 #include <stdint.h>
 #include <stdbool.h>
 
-#include "main/mtypes.h"
+#include "main/menums.h"
 
 #include "util/ralloc.h"
 
 #include "util/hash_table.h"
 
 #include "util/string_buffer.h"
 
+struct gl_context;
+
 #define yyscan_t void*
 
 /* Some data types used for parser values. */
 
 typedef struct expression_value {
 	intmax_t value;
 	char *undefined_macro;
 } expression_value_t;
    
 
diff --git a/src/compiler/glsl/glcpp/pp.c b/src/compiler/glsl/glcpp/pp.c
index fab52227a02..32dee11ee34 100644
--- a/src/compiler/glsl/glcpp/pp.c
+++ b/src/compiler/glsl/glcpp/pp.c
@@ -18,20 +18,21 @@
  * 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.
  */
 
 #include <assert.h>
 #include <string.h>
 #include <ctype.h>
 #include "glcpp.h"
+#include "main/mtypes.h"
 
 void
 glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
 {
 	va_list ap;
 
 	parser->error = 1;
 	_mesa_string_buffer_printf(parser->info_log,
 				   "%u:%u(%u): "
 				   "preprocessor error: ",
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 0cc57f5a887..9d0b7813feb 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -19,21 +19,20 @@
  * 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.
  */
 #include <inttypes.h> /* for PRIx64 macro */
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
 #include <assert.h>
 
-#include "main/core.h" /* for struct gl_context */
 #include "main/context.h"
 #include "main/debug_output.h"
 #include "main/formats.h"
 #include "main/shaderobj.h"
 #include "util/u_atomic.h" /* for p_atomic_cmpxchg */
 #include "util/ralloc.h"
 #include "util/disk_cache.h"
 #include "util/mesa-sha1.h"
 #include "ast.h"
 #include "glsl_parser_extras.h"
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index dbb58d82e8f..17d58acc4c2 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -25,20 +25,21 @@
  *
  */
 
 #include "glsl_to_nir.h"
 #include "ir_visitor.h"
 #include "ir_hierarchical_visitor.h"
 #include "ir.h"
 #include "compiler/nir/nir_control_flow.h"
 #include "compiler/nir/nir_builder.h"
 #include "main/imports.h"
+#include "main/mtypes.h"
 
 /*
  * pass to lower GLSL IR to NIR
  *
  * This will lower variable dereferences to loads/stores of corresponding
  * variables in NIR - the variables will be converted to registers in a later
  * pass.
  */
 
 namespace {
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 2c61dd9d64e..e3134eaa1c8 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -14,21 +14,20 @@
  *
  * 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.
  */
 #include <string.h>
-#include "main/core.h" /* for MAX2 */
 #include "ir.h"
 #include "compiler/glsl_types.h"
 #include "glsl_parser_extras.h"
 
 
 ir_rvalue::ir_rvalue(enum ir_node_type t)
    : ir_instruction(t)
 {
    this->type = glsl_type::error_type;
 }
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index 6d3ef89eb87..471d9e787a7 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -26,21 +26,20 @@
 #define IR_H
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include "util/ralloc.h"
 #include "compiler/glsl_types.h"
 #include "list.h"
 #include "ir_visitor.h"
 #include "ir_hierarchical_visitor.h"
-#include "main/mtypes.h"
 
 #ifdef __cplusplus
 
 /**
  * \defgroup IR Intermediate representation nodes
  *
  * @{
  */
 
 /**
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index fe9bd1d0b4a..4a0aff72c6f 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -27,26 +27,26 @@
  *
  * In GLSL, constant valued expressions are used in several places.  These
  * must be processed and evaluated very early in the compilation process.
  *
  *    * Sizes of arrays
  *    * Initializers for uniforms
  *    * Initializers for \c const variables
  */
 
 #include <math.h>
-#include "main/core.h" /* for MAX2, MIN2, CLAMP */
 #include "util/rounding.h" /* for _mesa_roundeven */
 #include "util/half_float.h"
 #include "ir.h"
 #include "compiler/glsl_types.h"
 #include "util/hash_table.h"
+#include "main/imports.h"
 
 static float
 dot_f(ir_constant *op0, ir_constant *op1)
 {
    assert(op0->type->is_float() && op1->type->is_float());
 
    float result = 0;
    for (unsigned c = 0; c < op0->type->components(); c++)
       result += op0->value.f[c] * op1->value.f[c];
 
diff --git a/src/compiler/glsl/ir_function_detect_recursion.cpp b/src/compiler/glsl/ir_function_detect_recursion.cpp
index 38e4357eff9..5b05274d001 100644
--- a/src/compiler/glsl/ir_function_detect_recursion.cpp
+++ b/src/compiler/glsl/ir_function_detect_recursion.cpp
@@ -113,21 +113,20 @@
  * which calls D, then this algorithm will report C as a function which "has
  * static recursion" even though it is not part of any cycle.
  *
  * A better algorithm for cycle detection that doesn't have this drawback can
  * be found here:
  *
  * http://en.wikipedia.org/wiki/Tarjan%E2%80%99s_strongly_connected_components_algorithm
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
-#include "main/core.h"
 #include "ir.h"
 #include "glsl_parser_extras.h"
 #include "linker.h"
 #include "util/hash_table.h"
 #include "program.h"
 
 namespace {
 
 struct call_node : public exec_node {
    class function *func;
diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 81049a479e8..b0e84608c58 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -23,20 +23,23 @@
 
 /**
  * \file ir_optimization.h
  *
  * Prototypes for optimization passes to be called by the compiler and drivers.
  */
 
 #ifndef GLSL_IR_OPTIMIZATION_H
 #define GLSL_IR_OPTIMIZATION_H
 
+struct gl_linked_shader;
+struct gl_shader_program;
+
 /* Operations for lower_instructions() */
 #define SUB_TO_ADD_NEG     0x01
 #define FDIV_TO_MUL_RCP    0x02
 #define EXP_TO_EXP2        0x04
 #define POW_TO_EXP2        0x08
 #define LOG_TO_LOG2        0x10
 #define MOD_TO_FLOOR       0x20
 #define INT_DIV_TO_MUL_RCP 0x40
 #define LDEXP_TO_ARITH     0x80
 #define CARRY_TO_ARITH     0x100
diff --git a/src/compiler/glsl/ir_set_program_inouts.cpp b/src/compiler/glsl/ir_set_program_inouts.cpp
index 1b6c8d750b9..ba1e44167c3 100644
--- a/src/compiler/glsl/ir_set_program_inouts.cpp
+++ b/src/compiler/glsl/ir_set_program_inouts.cpp
@@ -27,24 +27,24 @@
  * Sets the inputs_read and outputs_written of Mesa programs.
  *
  * Mesa programs (gl_program, not gl_shader_program) have a set of
  * flags indicating which varyings are read and written.  Computing
  * which are actually read from some sort of backend code can be
  * tricky when variable array indexing involved.  So this pass
  * provides support for setting inputs_read and outputs_written right
  * from the GLSL IR.
  */
 
-#include "main/core.h" /* for struct gl_program */
 #include "ir.h"
 #include "ir_visitor.h"
 #include "compiler/glsl_types.h"
+#include "main/mtypes.h"
 
 namespace {
 
 class ir_set_program_inouts_visitor : public ir_hierarchical_visitor {
 public:
    ir_set_program_inouts_visitor(struct gl_program *prog,
                                  gl_shader_stage shader_stage)
    {
       this->prog = prog;
       this->shader_stage = shader_stage;
diff --git a/src/compiler/glsl/ir_uniform.h b/src/compiler/glsl/ir_uniform.h
index 9545c4930c7..9770790cb26 100644
--- a/src/compiler/glsl/ir_uniform.h
+++ b/src/compiler/glsl/ir_uniform.h
@@ -21,21 +21,21 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
 #ifndef IR_UNIFORM_H
 #define IR_UNIFORM_H
 
 
 /* stdbool.h is necessary because this file is included in both C and C++ code.
  */
 #include <stdbool.h>
-
+#include "util/macros.h"
 #include "program/prog_parameter.h"  /* For union gl_constant_value. */
 
 /**
  * Used by GL_ARB_explicit_uniform_location extension code in the linker
  * and glUniform* functions to identify inactive explicit uniform locations.
  */
 #define INACTIVE_UNIFORM_EXPLICIT_LOCATION ((gl_uniform_storage *) -1)
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/compiler/glsl/link_atomics.cpp b/src/compiler/glsl/link_atomics.cpp
index d4a6eed639f..bc03d64633b 100644
--- a/src/compiler/glsl/link_atomics.cpp
+++ b/src/compiler/glsl/link_atomics.cpp
@@ -18,21 +18,23 @@
  * 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.
  */
 
 #include "glsl_parser_extras.h"
 #include "ir.h"
 #include "ir_uniform.h"
 #include "linker.h"
+#include "main/errors.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 
 namespace {
    /*
     * Atomic counter uniform as seen by the program.
     */
    struct active_atomic_counter_uniform {
       unsigned uniform_loc;
       ir_variable *var;
    };
 
diff --git a/src/compiler/glsl/link_functions.cpp b/src/compiler/glsl/link_functions.cpp
index 56d2933ff82..e73a72c86c9 100644
--- a/src/compiler/glsl/link_functions.cpp
+++ b/src/compiler/glsl/link_functions.cpp
@@ -14,28 +14,28 @@
  *
  * 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.
  */
 
-#include "main/core.h"
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ir.h"
 #include "program.h"
 #include "util/set.h"
 #include "util/hash_table.h"
 #include "linker.h"
+#include "main/mtypes.h"
 
 static ir_function_signature *
 find_matching_signature(const char *name, const exec_list *actual_parameters,
                         glsl_symbol_table *symbols);
 
 namespace {
 
 class call_link_visitor : public ir_hierarchical_visitor {
 public:
    call_link_visitor(gl_shader_program *prog, gl_linked_shader *linked,
diff --git a/src/compiler/glsl/link_interface_blocks.cpp b/src/compiler/glsl/link_interface_blocks.cpp
index ce90d916075..7c3037e8975 100644
--- a/src/compiler/glsl/link_interface_blocks.cpp
+++ b/src/compiler/glsl/link_interface_blocks.cpp
@@ -23,20 +23,21 @@
 
 /**
  * \file link_interface_blocks.cpp
  * Linker support for GLSL's interface blocks.
  */
 
 #include "ir.h"
 #include "glsl_symbol_table.h"
 #include "linker.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 #include "util/hash_table.h"
 
 
 namespace {
 
 /**
  * Return true if interface members mismatch and its not allowed by GLSL.
  */
 static bool
 interstage_member_mismatch(struct gl_shader_program *prog,
diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index 683b296e33b..e9e29d13a17 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -14,27 +14,28 @@
  *
  * 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.
  */
 
-#include "main/core.h"
 #include "ir.h"
 #include "linker.h"
 #include "ir_uniform.h"
 #include "link_uniform_block_active_visitor.h"
 #include "util/hash_table.h"
 #include "program.h"
+#include "main/errors.h"
+#include "main/mtypes.h"
 
 namespace {
 
 class ubo_visitor : public program_resource_visitor {
 public:
    ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
                unsigned num_variables, struct gl_shader_program *prog,
                bool use_std430_as_default)
       : index(0), offset(0), buffer_size(0), variables(variables),
         num_variables(num_variables), mem_ctx(mem_ctx),
diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index d6d63bd61fc..64f47f9913f 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -14,25 +14,25 @@
  *
  * 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.
  */
 
-#include "main/core.h"
 #include "ir.h"
 #include "linker.h"
 #include "ir_uniform.h"
 #include "string_to_uint_map.h"
+#include "main/mtypes.h"
 
 /* These functions are put in a "private" namespace instead of being marked
  * static so that the unit tests can access them.  See
  * http://code.google.com/p/googletest/wiki/AdvancedGuide#Testing_Private_Code
  */
 namespace linker {
 
 static gl_uniform_storage *
 get_storage(struct gl_shader_program *prog, const char *name)
 {
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index a73dcd47275..23ff7ec6728 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -14,28 +14,28 @@
  *
  * 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.
  */
 
-#include "main/core.h"
 #include "ir.h"
 #include "linker.h"
 #include "ir_uniform.h"
 #include "glsl_symbol_table.h"
 #include "program.h"
 #include "string_to_uint_map.h"
 #include "ir_array_refcount.h"
+#include "main/mtypes.h"
 
 /**
  * \file link_uniforms.cpp
  * Assign locations for GLSL uniforms.
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
 
 /**
  * Used by linker to indicate uniforms that have no location set.
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 1fdfcb877de..211633d9ee3 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -22,20 +22,21 @@
  */
 
 /**
  * \file link_varyings.cpp
  *
  * Linker functions related specifically to linking varyings between shader
  * stages.
  */
 
 
+#include "main/errors.h"
 #include "main/mtypes.h"
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ir_optimization.h"
 #include "linker.h"
 #include "link_varyings.h"
 #include "main/macros.h"
 #include "util/hash_table.h"
 #include "program.h"
 
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index af09b7d03ee..ecd267b24f3 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -59,40 +59,41 @@
  *     same name are verified to be the same.
  *   - Types and qualifiers of outputs defined in one stage are verified to
  *     be the same as the types and qualifiers of inputs defined with the same
  *     name in a later stage.
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
 
 #include <ctype.h>
 #include "util/strndup.h"
-#include "main/core.h"
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ir.h"
 #include "program.h"
 #include "program/prog_instruction.h"
 #include "program/program.h"
 #include "util/mesa-sha1.h"
 #include "util/set.h"
 #include "string_to_uint_map.h"
 #include "linker.h"
 #include "link_varyings.h"
 #include "ir_optimization.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_uniform.h"
 #include "builtin_functions.h"
 #include "shader_cache.h"
 
+#include "main/imports.h"
 #include "main/shaderobj.h"
 #include "main/enums.h"
+#include "main/mtypes.h"
 
 
 namespace {
 
 struct find_variable {
    const char *name;
    bool found;
 
    find_variable(const char *name) : name(name), found(false) {}
 };
diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
index 12a48e0dcd8..454b65aebdf 100644
--- a/src/compiler/glsl/linker.h
+++ b/src/compiler/glsl/linker.h
@@ -18,20 +18,24 @@
  * 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.
  */
 
 #ifndef GLSL_LINKER_H
 #define GLSL_LINKER_H
 
+struct gl_shader_program;
+struct gl_shader;
+struct gl_linked_shader;
+
 extern bool
 link_function_calls(gl_shader_program *prog, gl_linked_shader *main,
                     gl_shader **shader_list, unsigned num_shaders);
 
 extern void
 link_invalidate_variable_locations(exec_list *ir);
 
 extern void
 link_assign_uniform_locations(struct gl_shader_program *prog,
                               struct gl_context *ctx);
diff --git a/src/compiler/glsl/lower_blend_equation_advanced.cpp b/src/compiler/glsl/lower_blend_equation_advanced.cpp
index b05a2e0f0bb..c85b39bcaa3 100644
--- a/src/compiler/glsl/lower_blend_equation_advanced.cpp
+++ b/src/compiler/glsl/lower_blend_equation_advanced.cpp
@@ -22,20 +22,21 @@
  */
 
 #include "ir.h"
 #include "ir_builder.h"
 #include "ir_optimization.h"
 #include "ir_hierarchical_visitor.h"
 #include "program/prog_instruction.h"
 #include "program/prog_statevars.h"
 #include "util/bitscan.h"
 #include "builtin_functions.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 #define imm1(x) new(mem_ctx) ir_constant((float) (x), 1)
 #define imm3(x) new(mem_ctx) ir_constant((float) (x), 3)
 
 static ir_rvalue *
 blend_multiply(ir_variable *src, ir_variable *dst)
 {
    /* f(Cs,Cd) = Cs*Cd */
diff --git a/src/compiler/glsl/lower_cs_derived.cpp b/src/compiler/glsl/lower_cs_derived.cpp
index f7ec2a48b47..15534b0ac6b 100644
--- a/src/compiler/glsl/lower_cs_derived.cpp
+++ b/src/compiler/glsl/lower_cs_derived.cpp
@@ -36,20 +36,21 @@
  * This is meant to be run post-linking.
  */
 
 #include "glsl_symbol_table.h"
 #include "ir_hierarchical_visitor.h"
 #include "ir.h"
 #include "ir_builder.h"
 #include "linker.h"
 #include "program/prog_statevars.h"
 #include "builtin_functions.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 
 class lower_cs_derived_visitor : public ir_hierarchical_visitor {
 public:
    explicit lower_cs_derived_visitor(gl_linked_shader *shader)
       : progress(false),
         shader(shader),
diff --git a/src/compiler/glsl/lower_distance.cpp b/src/compiler/glsl/lower_distance.cpp
index 530f79d4dff..b4e730c64fb 100644
--- a/src/compiler/glsl/lower_distance.cpp
+++ b/src/compiler/glsl/lower_distance.cpp
@@ -43,20 +43,21 @@
  * Since some hardware may not internally represent gl_ClipDistance as a pair
  * of vec4's, this lowering pass is optional.  To enable it, set the
  * LowerCombinedClipCullDistance flag in gl_shader_compiler_options to true.
  */
 
 #include "main/macros.h"
 #include "glsl_symbol_table.h"
 #include "ir_rvalue_visitor.h"
 #include "ir.h"
 #include "program/prog_instruction.h" /* For WRITEMASK_* */
+#include "main/mtypes.h"
 
 #define GLSL_CLIP_VAR_NAME "gl_ClipDistanceMESA"
 
 namespace {
 
 class lower_distance_visitor : public ir_rvalue_visitor {
 public:
    explicit lower_distance_visitor(gl_shader_stage shader_stage,
                                    const char *in_name, int total_size,
                                    int offset)
diff --git a/src/compiler/glsl/lower_named_interface_blocks.cpp b/src/compiler/glsl/lower_named_interface_blocks.cpp
index 136352a131b..498954a33e5 100644
--- a/src/compiler/glsl/lower_named_interface_blocks.cpp
+++ b/src/compiler/glsl/lower_named_interface_blocks.cpp
@@ -57,20 +57,21 @@
  *
  * This modification to the ir allows our currently existing dead code
  * elimination to work with interface blocks without changes.
  */
 
 #include "glsl_symbol_table.h"
 #include "ir.h"
 #include "ir_optimization.h"
 #include "ir_rvalue_visitor.h"
 #include "util/hash_table.h"
+#include "main/mtypes.h"
 
 static const glsl_type *
 process_array_type(const glsl_type *type, unsigned idx)
 {
    const glsl_type *element_type = type->fields.array;
    if (element_type->is_array()) {
       const glsl_type *new_array_type = process_array_type(element_type, idx);
       return glsl_type::get_array_instance(new_array_type, type->length);
    } else {
       return glsl_type::get_array_instance(
diff --git a/src/compiler/glsl/lower_packed_varyings.cpp b/src/compiler/glsl/lower_packed_varyings.cpp
index c622f5ee7b7..5c1eed719f2 100644
--- a/src/compiler/glsl/lower_packed_varyings.cpp
+++ b/src/compiler/glsl/lower_packed_varyings.cpp
@@ -142,20 +142,21 @@
  *     arr[2].a[1] = packed5[2].zw;
  *     ...
  *   }
  */
 
 #include "glsl_symbol_table.h"
 #include "ir.h"
 #include "ir_builder.h"
 #include "ir_optimization.h"
 #include "program/prog_instruction.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 
 /**
  * Visitor that performs varying packing.  For each varying declared in the
  * shader, this visitor determines whether it needs to be packed.  If so, it
  * demotes it to an ordinary global, creates new packed varyings, and
  * generates assignments to convert between the original varying and the
diff --git a/src/compiler/glsl/lower_shared_reference.cpp b/src/compiler/glsl/lower_shared_reference.cpp
index 5de269fde82..a46d05419e5 100644
--- a/src/compiler/glsl/lower_shared_reference.cpp
+++ b/src/compiler/glsl/lower_shared_reference.cpp
@@ -30,20 +30,21 @@
  * This relieves drivers of the responsibility of allocating space for the
  * shared variables in the shared memory region.
  */
 
 #include "lower_buffer_access.h"
 #include "ir_builder.h"
 #include "linker.h"
 #include "main/macros.h"
 #include "util/list.h"
 #include "glsl_parser_extras.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 
 struct var_offset {
    struct list_head node;
    const ir_variable *var;
    unsigned offset;
 };
diff --git a/src/compiler/glsl/lower_tess_level.cpp b/src/compiler/glsl/lower_tess_level.cpp
index b0965eb562d..3e4c7f026ce 100644
--- a/src/compiler/glsl/lower_tess_level.cpp
+++ b/src/compiler/glsl/lower_tess_level.cpp
@@ -42,20 +42,21 @@
  *
  * Since some hardware may not internally represent gl_TessLevel* as a pair
  * of vec4's, this lowering pass is optional.  To enable it, set the
  * LowerTessLevel flag in gl_shader_compiler_options to true.
  */
 
 #include "glsl_symbol_table.h"
 #include "ir_rvalue_visitor.h"
 #include "ir.h"
 #include "program/prog_instruction.h" /* For WRITEMASK_* */
+#include "main/mtypes.h"
 
 namespace {
 
 class lower_tess_level_visitor : public ir_rvalue_visitor {
 public:
    explicit lower_tess_level_visitor(gl_shader_stage shader_stage)
       : progress(false), old_tess_level_outer_var(NULL),
         old_tess_level_inner_var(NULL), new_tess_level_outer_var(NULL),
         new_tess_level_inner_var(NULL), shader_stage(shader_stage)
    {
diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
index 1e35b44d5fe..453c0fa2b06 100644
--- a/src/compiler/glsl/lower_ubo_reference.cpp
+++ b/src/compiler/glsl/lower_ubo_reference.cpp
@@ -30,20 +30,21 @@
  *
  * This relieves drivers of the responsibility to deal with tricky UBO
  * layout issues like std140 structures and row_major matrices on
  * their own.
  */
 
 #include "lower_buffer_access.h"
 #include "ir_builder.h"
 #include "main/macros.h"
 #include "glsl_parser_extras.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 class lower_ubo_reference_visitor :
       public lower_buffer_access::lower_buffer_access {
 public:
    lower_ubo_reference_visitor(struct gl_linked_shader *shader,
                                bool clamp_block_indices,
                                bool use_std430_as_default)
diff --git a/src/compiler/glsl/lower_vector_derefs.cpp b/src/compiler/glsl/lower_vector_derefs.cpp
index a83658d20f7..7583d1fdd3e 100644
--- a/src/compiler/glsl/lower_vector_derefs.cpp
+++ b/src/compiler/glsl/lower_vector_derefs.cpp
@@ -17,20 +17,21 @@
  * 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.
  */
 #include "ir.h"
 #include "ir_builder.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_optimization.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 
 class vector_deref_visitor : public ir_rvalue_enter_visitor {
 public:
    vector_deref_visitor()
       : progress(false)
    {
diff --git a/src/compiler/glsl/lower_vertex_id.cpp b/src/compiler/glsl/lower_vertex_id.cpp
index 6b41fee055a..3b641caa01e 100644
--- a/src/compiler/glsl/lower_vertex_id.cpp
+++ b/src/compiler/glsl/lower_vertex_id.cpp
@@ -31,20 +31,21 @@
  * gl_VertexIDMESA+gl_BaseVertexMESA.
  */
 
 #include "glsl_symbol_table.h"
 #include "ir_hierarchical_visitor.h"
 #include "ir.h"
 #include "ir_builder.h"
 #include "linker.h"
 #include "program/prog_statevars.h"
 #include "builtin_functions.h"
+#include "main/mtypes.h"
 
 namespace {
 
 class lower_vertex_id_visitor : public ir_hierarchical_visitor {
 public:
    explicit lower_vertex_id_visitor(ir_function_signature *main_sig,
                                     exec_list *ir_list)
       : progress(false), VertexID(NULL), gl_VertexID(NULL),
         gl_BaseVertex(NULL), main_sig(main_sig), ir_list(ir_list)
    {
diff --git a/src/compiler/glsl/main.cpp b/src/compiler/glsl/main.cpp
index e082bd69757..a730c033917 100644
--- a/src/compiler/glsl/main.cpp
+++ b/src/compiler/glsl/main.cpp
@@ -14,33 +14,33 @@
  *
  * 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.
  */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <getopt.h>
 
 /** @file main.cpp
  *
  * This file is the main() routine and scaffolding for producing
  * builtin_compiler (which doesn't include builtins itself and is used
  * to generate the profile information for builtin_function.cpp), and
  * for glsl_compiler (which does include builtins and can be used to
  * offline compile GLSL code and examine the resulting GLSL IR.
  */
 
-#include "main/mtypes.h"
 #include "standalone.h"
 
 static struct standalone_options options;
 
 const struct option compiler_opts[] = {
    { "dump-ast", no_argument, &options.dump_ast, 1 },
    { "dump-hir", no_argument, &options.dump_hir, 1 },
    { "dump-lir", no_argument, &options.dump_lir, 1 },
    { "dump-builder", no_argument, &options.dump_builder, 1 },
    { "link",     no_argument, &options.do_link,  1 },
diff --git a/src/compiler/glsl/opt_algebraic.cpp b/src/compiler/glsl/opt_algebraic.cpp
index ce5f26559a7..1a8ee361652 100644
--- a/src/compiler/glsl/opt_algebraic.cpp
+++ b/src/compiler/glsl/opt_algebraic.cpp
@@ -27,20 +27,21 @@
  * Takes advantage of association, commutivity, and other algebraic
  * properties to simplify expressions.
  */
 
 #include "ir.h"
 #include "ir_visitor.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_optimization.h"
 #include "ir_builder.h"
 #include "compiler/glsl_types.h"
+#include "main/mtypes.h"
 
 using namespace ir_builder;
 
 namespace {
 
 /**
  * Visitor class for replacing expressions with ir_constant values.
  */
 
 class ir_algebraic_visitor : public ir_rvalue_visitor {
diff --git a/src/compiler/glsl/opt_dead_builtin_varyings.cpp b/src/compiler/glsl/opt_dead_builtin_varyings.cpp
index 4526f2bca00..0ce19218606 100644
--- a/src/compiler/glsl/opt_dead_builtin_varyings.cpp
+++ b/src/compiler/glsl/opt_dead_builtin_varyings.cpp
@@ -39,27 +39,27 @@
  * temporary variables, which creates dead code. It is recommended to run
  * a dead-code elimination pass after this.
  *
  * If any texture coordinate slots can be eliminated, the gl_TexCoord array is
  * broken down into separate vec4 variables with locations equal to
  * VARYING_SLOT_TEX0 + i.
  *
  * The same is done for the gl_FragData fragment shader output.
  */
 
-#include "main/core.h" /* for snprintf and ARRAY_SIZE */
 #include "ir.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_optimization.h"
 #include "ir_print_visitor.h"
 #include "compiler/glsl_types.h"
 #include "link_varyings.h"
+#include "main/mtypes.h"
 
 namespace {
 
 /**
  * This obtains detailed information about built-in varyings from shader code.
  */
 class varying_info_visitor : public ir_hierarchical_visitor {
 public:
    /* "mode" can be either ir_var_shader_in or ir_var_shader_out */
    varying_info_visitor(ir_variable_mode mode, bool find_frag_outputs = false)
diff --git a/src/compiler/glsl/s_expression.cpp b/src/compiler/glsl/s_expression.cpp
index f82e155a6b6..12baf1d3ed3 100644
--- a/src/compiler/glsl/s_expression.cpp
+++ b/src/compiler/glsl/s_expression.cpp
@@ -18,20 +18,22 @@
  * 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.
  */
 
 #include <assert.h>
 #include <stdio.h>
 #include <math.h>
+#include <string.h>
+#include <stdlib.h>
 #include "s_expression.h"
 
 s_symbol::s_symbol(const char *str, size_t n)
 {
    /* Assume the given string is already nul-terminated and in memory that
     * will live as long as this node.
     */
    assert(str[n] == '\0');
    this->str = str;
 }
diff --git a/src/compiler/glsl/s_expression.h b/src/compiler/glsl/s_expression.h
index 5456b6bab21..38caabbf89e 100644
--- a/src/compiler/glsl/s_expression.h
+++ b/src/compiler/glsl/s_expression.h
@@ -18,21 +18,20 @@
  * 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.
  */
 
 #ifndef S_EXPRESSION_H
 #define S_EXPRESSION_H
 
-#include "main/core.h" /* for Elements */
 #include "util/strtod.h"
 #include "list.h"
 
 /* Type-safe downcasting macros (also safe to pass NULL) */
 #define SX_AS_(t,x) ((x) && ((s_expression*) x)->is_##t()) ? ((s_##t*) (x)) \
                                                            : NULL
 #define SX_AS_LIST(x)   SX_AS_(list, x)
 #define SX_AS_SYMBOL(x) SX_AS_(symbol, x)
 #define SX_AS_NUMBER(x) SX_AS_(number, x)
 #define SX_AS_INT(x)    SX_AS_(int, x)
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index e43ed7aa675..042f3a60f5b 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -46,27 +46,27 @@
 
 #include "compiler/shader_info.h"
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "ir.h"
 #include "ir_optimization.h"
 #include "ir_rvalue_visitor.h"
 #include "ir_uniform.h"
 #include "linker.h"
 #include "link_varyings.h"
-#include "main/core.h"
 #include "nir.h"
 #include "program.h"
 #include "serialize.h"
 #include "shader_cache.h"
 #include "util/mesa-sha1.h"
 #include "string_to_uint_map.h"
+#include "main/mtypes.h"
 
 extern "C" {
 #include "main/enums.h"
 #include "main/shaderobj.h"
 #include "program/program.h"
 }
 
 static void
 compile_shaders(struct gl_context *ctx, struct gl_shader_program *prog) {
    for (unsigned i = 0; i < prog->NumShaders; i++) {
diff --git a/src/compiler/glsl/shader_cache.h b/src/compiler/glsl/shader_cache.h
index eeefb3aeb25..b3603d956d5 100644
--- a/src/compiler/glsl/shader_cache.h
+++ b/src/compiler/glsl/shader_cache.h
@@ -19,19 +19,22 @@
  * 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.
  */
 
 #ifndef SHADER_CACHE_H
 #define SHADER_CACHE_H
 
 #include "util/disk_cache.h"
 
+struct gl_context;
+struct gl_shader_program;
+
 void
 shader_cache_write_program_metadata(struct gl_context *ctx,
                                     struct gl_shader_program *prog);
 
 bool
 shader_cache_read_program_metadata(struct gl_context *ctx,
                                    struct gl_shader_program *prog);
 
 #endif /* SHADER_CACHE_H */
diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index c989aeff71a..c24a220a48d 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -36,20 +36,21 @@
 #include "loop_analysis.h"
 #include "standalone_scaffolding.h"
 #include "standalone.h"
 #include "string_to_uint_map.h"
 #include "util/set.h"
 #include "linker.h"
 #include "glsl_parser_extras.h"
 #include "ir_builder_print_visitor.h"
 #include "builtin_functions.h"
 #include "opt_add_neg_to_sub.h"
+#include "main/mtypes.h"
 
 class dead_variable_visitor : public ir_hierarchical_visitor {
 public:
    dead_variable_visitor()
    {
       variables = _mesa_set_create(NULL,
                                    _mesa_hash_pointer,
                                    _mesa_key_pointer_equal);
    }
 
diff --git a/src/compiler/glsl/standalone_scaffolding.cpp b/src/compiler/glsl/standalone_scaffolding.cpp
index caaddc028f7..ec5f28ae40c 100644
--- a/src/compiler/glsl/standalone_scaffolding.cpp
+++ b/src/compiler/glsl/standalone_scaffolding.cpp
@@ -27,20 +27,21 @@
  * compiling builtins).
  */
 
 #include "standalone_scaffolding.h"
 
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include "util/ralloc.h"
 #include "util/strtod.h"
+#include "main/mtypes.h"
 
 void
 _mesa_warning(struct gl_context *ctx, const char *fmt, ...)
 {
     va_list vargs;
     (void) ctx;
 
     va_start(vargs, fmt);
 
     /* This output is not thread-safe, but that's good enough for the
diff --git a/src/compiler/glsl/standalone_scaffolding.h b/src/compiler/glsl/standalone_scaffolding.h
index c8d90597ca0..7da76f06fef 100644
--- a/src/compiler/glsl/standalone_scaffolding.h
+++ b/src/compiler/glsl/standalone_scaffolding.h
@@ -24,21 +24,21 @@
 /* This file declares stripped-down versions of functions that
  * normally exist outside of the glsl folder, so that they can be used
  * when running the GLSL compiler standalone (for unit testing or
  * compiling builtins).
  */
 
 #ifndef STANDALONE_SCAFFOLDING_H
 #define STANDALONE_SCAFFOLDING_H
 
 #include <assert.h>
-#include "main/mtypes.h"
+#include "main/menums.h"
 #include "program/prog_statevars.h"
 
 extern "C" void
 _mesa_warning(struct gl_context *ctx, const char *fmtString, ... );
 
 extern "C" void
 _mesa_reference_shader_program_data(struct gl_context *ctx,
                                     struct gl_shader_program_data **ptr,
                                     struct gl_shader_program_data *data);
 
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 88f987fabee..efc63248656 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -23,20 +23,25 @@
  */
 
 #ifndef GLSL_TYPES_H
 #define GLSL_TYPES_H
 
 #include <string.h>
 #include <assert.h>
 
 #include "shader_enums.h"
 #include "blob.h"
+#include "c11/threads.h"
+
+#ifdef __cplusplus
+#include "main/config.h"
+#endif
 
 struct glsl_type;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct _mesa_glsl_parse_state;
 struct glsl_symbol_table;
 
@@ -139,21 +144,21 @@ enum glsl_matrix_layout {
 enum {
    GLSL_PRECISION_NONE = 0,
    GLSL_PRECISION_HIGH,
    GLSL_PRECISION_MEDIUM,
    GLSL_PRECISION_LOW
 };
 
 #ifdef __cplusplus
 #include "GL/gl.h"
 #include "util/ralloc.h"
-#include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */
+#include "main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
 
 struct glsl_type {
    GLenum gl_type;
    glsl_base_type base_type:8;
 
    glsl_base_type sampled_type:8; /**< Type of data returned using this
                                    * sampler or image.  Only \c
                                    * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
                                    * and \c GLSL_TYPE_UINT are valid.
                                    */
diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py
index ee92be51dbe..db5bde2b82d 100644
--- a/src/compiler/nir/nir_constant_expressions.py
+++ b/src/compiler/nir/nir_constant_expressions.py
@@ -69,21 +69,20 @@ template = """\
  * 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.
  *
  * Authors:
  *    Jason Ekstrand (jason at jlekstrand.net)
  */
 
 #include <math.h>
-#include "main/core.h"
 #include "util/rounding.h" /* for _mesa_roundeven */
 #include "util/half_float.h"
 #include "nir_constant_expressions.h"
 
 /**
  * Evaluate one component of packSnorm4x8.
  */
 static uint8_t
 pack_snorm_1x8(float x)
 {
diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c
index 5530009255d..eaf0ca68b0f 100644
--- a/src/compiler/nir/nir_gather_info.c
+++ b/src/compiler/nir/nir_gather_info.c
@@ -14,22 +14,22 @@
  *
  * 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.
  */
 
-#include "main/mtypes.h"
 #include "nir.h"
+#include "main/menums.h"
 
 static void
 set_io_mask(nir_shader *shader, nir_variable *var, int offset, int len,
             bool is_output_read)
 {
    for (int i = 0; i < len; i++) {
       assert(var->data.location != -1);
 
       int idx = var->data.location + offset + i;
       bool is_patch_generic = var->data.patch &&
diff --git a/src/compiler/nir/nir_lower_atomics.c b/src/compiler/nir/nir_lower_atomics.c
index 6b046bc426e..a76dd861faa 100644
--- a/src/compiler/nir/nir_lower_atomics.c
+++ b/src/compiler/nir/nir_lower_atomics.c
@@ -21,20 +21,21 @@
  * IN THE SOFTWARE.
  *
  * Authors:
  *    Connor Abbott (cwabbott0 at gmail.com)
  *
  */
 
 #include "compiler/glsl/ir_uniform.h"
 #include "nir.h"
 #include "main/config.h"
+#include "main/mtypes.h"
 #include <assert.h>
 
 /*
  * replace atomic counter intrinsics that use a variable with intrinsics
  * that directly store the buffer index and byte offset
  */
 
 static bool
 lower_instr(nir_intrinsic_instr *instr,
             const struct gl_shader_program *shader_program,
diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c
index 9aa4a9e967f..7690665de30 100644
--- a/src/compiler/nir/nir_lower_samplers.c
+++ b/src/compiler/nir/nir_lower_samplers.c
@@ -22,22 +22,20 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 #include "nir.h"
 #include "nir_builder.h"
 #include "compiler/glsl/ir_uniform.h"
 
 #include "main/compiler.h"
 #include "main/mtypes.h"
-#include "program/prog_parameter.h"
-#include "program/program.h"
 
 /* Calculate the sampler index based on array indicies and also
  * calculate the base uniform location for struct members.
  */
 static void
 calc_sampler_offsets(nir_deref *tail, nir_tex_instr *instr,
                      unsigned *array_elements, nir_ssa_def **indirect,
                      nir_builder *b, unsigned *location)
 {
    if (tail->child == NULL)
diff --git a/src/compiler/nir/nir_lower_samplers_as_deref.c b/src/compiler/nir/nir_lower_samplers_as_deref.c
index 2a2fb5b093f..cb0c827182c 100644
--- a/src/compiler/nir/nir_lower_samplers_as_deref.c
+++ b/src/compiler/nir/nir_lower_samplers_as_deref.c
@@ -54,22 +54,20 @@
  * and lower at s.tex has var->data.binding set to the base index as defined by
  * the opaque uniform mapping.
  */
 
 #include "nir.h"
 #include "nir_builder.h"
 #include "compiler/glsl/ir_uniform.h"
 
 #include "main/compiler.h"
 #include "main/mtypes.h"
-#include "program/prog_parameter.h"
-#include "program/program.h"
 
 struct lower_samplers_as_deref_state {
    nir_shader *shader;
    const struct gl_shader_program *shader_program;
    struct hash_table *remap_table;
 };
 
 static void
 remove_struct_derefs(nir_deref *tail,
                      struct lower_samplers_as_deref_state *state,
diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
index b3e9c79ce2c..819d2e320d8 100644
--- a/src/gallium/state_trackers/glx/xlib/glx_usefont.c
+++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c
@@ -24,21 +24,20 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 /**
  * Fake implementation of glXUseXFont().
  */
 
 
 #include <stdio.h>
-#include "main/core.h"
 #include <GL/glx.h>
 
 
 /* Some debugging info.  */
 
 #ifdef DEBUG
 #include <ctype.h>
 
 int debug_xfonts = 0;
 
diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h
index e420679313e..d2b57d6b9dd 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_api.h
+++ b/src/gallium/state_trackers/glx/xlib/xm_api.h
@@ -50,21 +50,21 @@ and create a window, you must do the following to use the X/Mesa interface:
 
 */
 
 
 
 
 #ifndef XMESA_H
 #define XMESA_H
 
 
-#include "main/core.h" /* for gl_config */
+#include "main/mtypes.h" /* for gl_config */
 #include "state_tracker/st_api.h"
 #include "os/os_thread.h"
 
 #include "state_tracker/xlibsw_api.h"
 
 # include <X11/Xlib.h>
 # include <X11/Xlibint.h>
 # include <X11/Xutil.h>
 
 struct hud_context;
diff --git a/src/intel/common/gen_urb_config.c b/src/intel/common/gen_urb_config.c
index 937163b50b0..0b632149cd9 100644
--- a/src/intel/common/gen_urb_config.c
+++ b/src/intel/common/gen_urb_config.c
@@ -19,20 +19,21 @@
  * 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.
  */
 
 #include <stdlib.h>
 #include <math.h>
 
 #include "util/macros.h"
 #include "main/macros.h"
+#include "compiler/shader_enums.h"
 
 #include "gen_l3_config.h"
 
 /**
  * The following diagram shows how we partition the URB:
  *
  *        16kb or 32kb               Rest of the URB space
  *   __________-__________   _________________-_________________
  *  /                     \ /                                   \
  * +-------------------------------------------------------------+
diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h
index d3ae6499b91..875b2936fd8 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -20,20 +20,21 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  * IN THE SOFTWARE.
  */
 
 #ifndef BRW_COMPILER_H
 #define BRW_COMPILER_H
 
 #include <stdio.h>
 #include "dev/gen_device_info.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 #include "util/ralloc.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct ra_regs;
 struct nir_shader;
 struct brw_program;
 
diff --git a/src/intel/compiler/brw_eu.h b/src/intel/compiler/brw_eu.h
index ca72666a55a..120a74f0357 100644
--- a/src/intel/compiler/brw_eu.h
+++ b/src/intel/compiler/brw_eu.h
@@ -27,20 +27,21 @@
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   */
 
 
 #ifndef BRW_EU_H
 #define BRW_EU_H
 
 #include <stdbool.h>
+#include <stdio.h>
 #include "brw_inst.h"
 #include "brw_eu_defines.h"
 #include "brw_reg.h"
 #include "brw_disasm_info.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #define BRW_EU_MAX_INSN_STACK 5
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index 92565ef8f5e..d78493ed9d7 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -48,21 +48,20 @@ MAIN_FILES = \
 	main/compiler.h \
 	main/condrender.c \
 	main/condrender.h \
 	main/config.h \
 	main/context.c \
 	main/context.h \
 	main/convolve.c \
 	main/convolve.h \
 	main/copyimage.c \
 	main/copyimage.h \
-	main/core.h \
 	main/cpuinfo.c \
 	main/cpuinfo.h \
 	main/dd.h \
 	main/debug.c \
 	main/debug.h \
 	main/debug_output.c \
 	main/debug_output.h \
 	main/depth.c \
 	main/depth.h \
 	main/dlist.c \
@@ -141,20 +140,21 @@ MAIN_FILES = \
 	main/marshal.c \
 	main/marshal.h \
 	main/marshal_generated.c \
 	main/marshal_generated.h \
 	main/matrix.c \
 	main/matrix.h \
 	main/mipmap.c \
 	main/mipmap.h \
 	main/mm.c \
 	main/mm.h \
+	main/menums.h \
 	main/mtypes.h \
 	main/multisample.c \
 	main/multisample.h \
 	main/objectlabel.c \
 	main/objectlabel.h \
 	main/objectpurge.c \
 	main/objectpurge.h \
 	main/pack.c \
 	main/pack.h \
 	main/pbo.c \
diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
index 5018f2fbf68..062c83f79ec 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -48,24 +48,28 @@
  * The following structs are shared between DRISW and DRI2, the DRISW structs
  * are essentially base classes of the DRI2 structs. DRISW needs to compile on
  * platforms without DRM, so keep the structs opaque to DRM.
  */
 
 #ifndef _DRI_UTIL_H_
 #define _DRI_UTIL_H_
 
 #include <GL/gl.h>
 #include <GL/internal/dri_interface.h>
-#include "main/mtypes.h"
+#include "main/menums.h"
+#include "main/formats.h"
 #include "util/xmlconfig.h"
 #include <stdbool.h>
 
+struct gl_config;
+struct gl_context;
+
 /**
  * Extensions.
  */
 extern const __DRIcoreExtension driCoreExtension;
 extern const __DRIswrastExtension driSWRastExtension;
 extern const __DRIdri2Extension driDRI2Extension;
 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
 extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
 extern const __DRI2flushControlExtension dri2FlushControlExtension;
 
diff --git a/src/mesa/drivers/dri/i915/intel_context.h b/src/mesa/drivers/dri/i915/intel_context.h
index 5361dcf5e34..a219c7fb1dc 100644
--- a/src/mesa/drivers/dri/i915/intel_context.h
+++ b/src/mesa/drivers/dri/i915/intel_context.h
@@ -25,20 +25,21 @@
  * 
  **************************************************************************/
 
 #ifndef INTELCONTEXT_INC
 #define INTELCONTEXT_INC
 
 
 #include <stdbool.h>
 #include <string.h>
 #include "main/mtypes.h"
+#include "main/errors.h"
 
 #include <drm.h>
 #include <intel_bufmgr.h>
 #include <i915_drm.h>
 
 #include "intel_screen.h"
 #include "intel_tex_obj.h"
 
 #include "tnl/t_vertex.h"
 
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index f049d086492..6d424019183 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -29,20 +29,21 @@
   *   Keith Whitwell <keithw at vmware.com>
   */
 
 
 #ifndef BRWCONTEXT_INC
 #define BRWCONTEXT_INC
 
 #include <stdbool.h>
 #include "main/macros.h"
 #include "main/mtypes.h"
+#include "main/errors.h"
 #include "vbo/vbo.h"
 #include "brw_structs.h"
 #include "brw_pipe_control.h"
 #include "compiler/brw_compiler.h"
 
 #include "isl/isl.h"
 #include "blorp/blorp.h"
 
 #include <brw_bufmgr.h>
 
diff --git a/src/mesa/drivers/dri/r200/r200_state_init.c b/src/mesa/drivers/dri/r200/r200_state_init.c
index 4b589cd8b83..41c3df710e5 100644
--- a/src/mesa/drivers/dri/r200/r200_state_init.c
+++ b/src/mesa/drivers/dri/r200/r200_state_init.c
@@ -24,20 +24,21 @@ IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
 */
 
 /*
  * Authors:
  *   Keith Whitwell <keithw at vmware.com>
  */
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/enums.h"
 #include "main/api_arrayelt.h"
 #include "main/state.h"
 
 #include "swrast/swrast.h"
 #include "vbo/vbo.h"
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
diff --git a/src/mesa/drivers/dri/r200/r200_vertprog.c b/src/mesa/drivers/dri/r200/r200_vertprog.c
index f69f4a0a1e2..7076ec0c7f3 100644
--- a/src/mesa/drivers/dri/r200/r200_vertprog.c
+++ b/src/mesa/drivers/dri/r200/r200_vertprog.c
@@ -23,20 +23,22 @@ 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.
 
 **************************************************************************/
 
 /*
  * Authors:
  *   Aapo Tahkola <aet at rasterburn.org>
  *   Roland Scheidegger <rscheidegger_lists at hispeed.ch>
  */
+
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/enums.h"
 #include "program/program.h"
 #include "program/prog_instruction.h"
 #include "program/prog_parameter.h"
 #include "program/prog_statevars.h"
 #include "program/programopt.h"
 #include "tnl/tnl.h"
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c b/src/mesa/drivers/dri/radeon/radeon_state.c
index 58d8fc54b79..8b72c98a3b2 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -34,21 +34,20 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/enums.h"
 #include "main/light.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
 #include "main/fbobject.h"
 #include "util/simple_list.h"
 #include "main/state.h"
-#include "main/core.h"
 #include "main/stencil.h"
 #include "main/viewport.h"
 
 #include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
 #include "drivers/common/meta.h"
 #include "util/bitscan.h"
 
diff --git a/src/mesa/drivers/dri/radeon/radeon_state_init.c b/src/mesa/drivers/dri/radeon/radeon_state_init.c
index b847be54c47..6a8cf606dcb 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state_init.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state_init.c
@@ -20,20 +20,21 @@
  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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.
  *
  * Authors:
  *    Gareth Hughes <gareth at valinux.com>
  *    Keith Whitwell <keithw at vmware.com>
  */
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/api_arrayelt.h"
 
 #include "swrast/swrast.h"
 #include "vbo/vbo.h"
 #include "tnl/t_pipeline.h"
 #include "swrast_setup/swrast_setup.h"
 
 #include "radeon_context.h"
diff --git a/src/mesa/main/api_arrayelt.h b/src/mesa/main/api_arrayelt.h
index 965e0ad3aea..6543a58f724 100644
--- a/src/mesa/main/api_arrayelt.h
+++ b/src/mesa/main/api_arrayelt.h
@@ -20,23 +20,24 @@
  * 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.
  */
 
 
 #ifndef API_ARRAYELT_H
 #define API_ARRAYELT_H
 
+#include <stdbool.h>
+#include "dd.h"
 
-#include "main/mtypes.h"
-
+struct _glapi_table;
 
 extern GLboolean _ae_create_context( struct gl_context *ctx );
 extern void _ae_destroy_context( struct gl_context *ctx );
 extern void _ae_invalidate_state(struct gl_context *ctx);
 extern bool _ae_is_state_dirty(struct gl_context *ctx);
 extern void GLAPIENTRY _ae_ArrayElement( GLint elt );
 
 /* May optionally be called before a batch of element calls:
  */
 extern void _ae_map_vbos( struct gl_context *ctx );
diff --git a/src/mesa/main/buffers.h b/src/mesa/main/buffers.h
index c43810752b0..913af7842fe 100644
--- a/src/mesa/main/buffers.h
+++ b/src/mesa/main/buffers.h
@@ -27,21 +27,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 
 #ifndef BUFFERS_H
 #define BUFFERS_H
 
 
 #include "glheader.h"
-#include "mtypes.h"
+#include "menums.h"
 
 struct gl_context;
 struct gl_framebuffer;
 
 
 void GLAPIENTRY
 _mesa_DrawBuffer_no_error(GLenum mode);
 
 extern void GLAPIENTRY
 _mesa_DrawBuffer( GLenum mode );
diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
index 33ca5af0731..8cd305cb31f 100644
--- a/src/mesa/main/colormac.h
+++ b/src/mesa/main/colormac.h
@@ -28,21 +28,20 @@
  * Color-related macros
  */
 
 
 #ifndef COLORMAC_H
 #define COLORMAC_H
 
 
 #include "config.h"
 #include "macros.h"
-#include "mtypes.h"
 
 
 /**
  * Convert four float values in [0,1] to ubytes in [0,255] with clamping.
  */
 static inline void
 _mesa_unclamped_float_rgba_to_ubyte(GLubyte dst[4], const GLfloat src[4])
 {
    int i;
    for (i = 0; i < 4; i++)
diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h
index 86be66f9e09..ef06540e9ba 100644
--- a/src/mesa/main/context.h
+++ b/src/mesa/main/context.h
@@ -42,20 +42,21 @@
  * are base classes which the device driver must derive from.
  *
  * The following functions create and destroy these data types.
  */
 
 
 #ifndef CONTEXT_H
 #define CONTEXT_H
 
 
+#include "errors.h"
 #include "imports.h"
 #include "extensions.h"
 #include "mtypes.h"
 #include "vbo/vbo.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
diff --git a/src/mesa/main/copyimage.h b/src/mesa/main/copyimage.h
index ea2f15b4352..7cebb30d997 100644
--- a/src/mesa/main/copyimage.h
+++ b/src/mesa/main/copyimage.h
@@ -22,21 +22,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Jason Ekstrand <jason.ekstrand at intel.com>
  */
 
 
 #ifndef COPYIMAGE_H
 #define COPYIMAGE_H
 
-#include "mtypes.h"
+#include "glheader.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 void GLAPIENTRY
 _mesa_CopyImageSubData_no_error(GLuint srcName, GLenum srcTarget, GLint srcLevel,
                                 GLint srcX, GLint srcY, GLint srcZ,
                                 GLuint destName, GLenum destTarget, GLint destLevel,
                                 GLint destX, GLint destY, GLint destZ,
diff --git a/src/mesa/main/core.h b/src/mesa/main/core.h
deleted file mode 100644
index 73ed01c259b..00000000000
--- a/src/mesa/main/core.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2010 LunarG Inc.
- *
- * 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 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.
- *
- * Authors:
- *    Chia-I Wu <olv at lunarg.com>
- */
-
-
-/**
- * \file core.h
- * The public header of core mesa.
- *
- * This file is the (only) public header of core mesa.  It is supposed to be
- * used by GLX, WGL, and GLSL.
- */
-
-
-#ifndef CORE_H
-#define CORE_H
-
-
-#include "main/glheader.h"
-#include "main/compiler.h"
-#include "main/imports.h"
-#include "main/macros.h"
-
-#include "main/mtypes.h"
-
-/* for GLSL */
-#include "program/prog_parameter.h"
-
-
-#endif /* CORE_H */
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index 09e9c41244e..64ddd818835 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -24,39 +24,41 @@
  * 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.
  */
 
 
 #ifndef DD_INCLUDED
 #define DD_INCLUDED
 
-/* THIS FILE ONLY INCLUDED BY mtypes.h !!!!! */
-
 #include "glheader.h"
+#include "formats.h"
+#include "menums.h"
 
 struct gl_bitmap_atlas;
 struct gl_buffer_object;
 struct gl_context;
 struct gl_display_list;
 struct gl_framebuffer;
 struct gl_image_unit;
 struct gl_pixelstore_attrib;
 struct gl_program;
 struct gl_renderbuffer;
 struct gl_renderbuffer_attachment;
 struct gl_shader;
 struct gl_shader_program;
 struct gl_texture_image;
 struct gl_texture_object;
 struct gl_memory_info;
+struct gl_transform_feedback_object;
+struct ati_fragment_shader;
 struct util_queue_monitoring;
 struct _mesa_prim;
 struct _mesa_index_buffer;
 
 /* GL_ARB_vertex_buffer_object */
 /* Modifies GL_MAP_UNSYNCHRONIZED_BIT to allow driver to fail (return
  * NULL) if buffer is unavailable for immediate mapping.
  *
  * Does GL_MAP_INVALIDATE_RANGE_BIT do this?  It seems so, but it
  * would require more book-keeping in the driver than seems necessary
diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index d7e0143a8f6..b1fa1f067ff 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -17,20 +17,21 @@
  * 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.
  */
 
 #include <stdio.h>
+#include "errors.h"
 #include "mtypes.h"
 #include "attrib.h"
 #include "enums.h"
 #include "formats.h"
 #include "hash.h"
 #include "imports.h"
 #include "macros.h"
 #include "debug.h"
 #include "get.h"
 #include "pixelstore.h"
diff --git a/src/mesa/main/debug_output.h b/src/mesa/main/debug_output.h
index 63e3e7b48e4..8a5eedc21f0 100644
--- a/src/mesa/main/debug_output.h
+++ b/src/mesa/main/debug_output.h
@@ -23,27 +23,28 @@
  */
 
 
 #ifndef DEBUG_OUTPUT_H
 #define DEBUG_OUTPUT_H
 
 
 #include <stdio.h>
 #include <stdarg.h>
 #include "glheader.h"
-#include "mtypes.h"
+#include "menums.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
 
 void
 _mesa_init_debug_output(struct gl_context *ctx);
 
 void
 _mesa_free_errors_data(struct gl_context *ctx);
 
 void
 _mesa_debug_get_id(GLuint *id);
 
diff --git a/src/mesa/main/dlist.h b/src/mesa/main/dlist.h
index 22b696f50c1..1ac17d5bb09 100644
--- a/src/mesa/main/dlist.h
+++ b/src/mesa/main/dlist.h
@@ -26,22 +26,22 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 
 #ifndef DLIST_H
 #define DLIST_H
 
 #include <stdio.h>
-#include "main/mtypes.h"
 
+struct gl_context;
 
 /**
  * Describes the location and size of a glBitmap image in a texture atlas.
  */
 struct gl_bitmap_glyph
 {
    unsigned short x, y, w, h;  /**< position and size in the texture */
    float xorig, yorig;         /**< bitmap origin */
    float xmove, ymove;         /**< rasterpos move */
 };
diff --git a/src/mesa/main/drawtex.c b/src/mesa/main/drawtex.c
index 9c4fdf90e3b..6114b3277b0 100644
--- a/src/mesa/main/drawtex.c
+++ b/src/mesa/main/drawtex.c
@@ -14,20 +14,21 @@
  *
  * 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.
  */
 
+#include "main/errors.h"
 #include "main/drawtex.h"
 #include "main/state.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 
 
 static void
 draw_texture(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
              GLfloat width, GLfloat height)
 {
diff --git a/src/mesa/main/errors.h b/src/mesa/main/errors.h
index b784b117761..5911da2956f 100644
--- a/src/mesa/main/errors.h
+++ b/src/mesa/main/errors.h
@@ -32,27 +32,29 @@
  */
 
 
 #ifndef ERRORS_H
 #define ERRORS_H
 
 
 #include <stdio.h>
 #include <stdarg.h>
 #include "glheader.h"
-#include "mtypes.h"
+#include "menums.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+
 extern void
 _mesa_warning( struct gl_context *gc, const char *fmtString, ... ) PRINTFLIKE(2, 3);
 
 extern void
 _mesa_problem( const struct gl_context *ctx, const char *fmtString, ... ) PRINTFLIKE(2, 3);
 
 extern void
 _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... ) PRINTFLIKE(3, 4);
 
 extern void
diff --git a/src/mesa/main/eval.h b/src/mesa/main/eval.h
index 5b2fce11948..938e3579b0e 100644
--- a/src/mesa/main/eval.h
+++ b/src/mesa/main/eval.h
@@ -30,21 +30,21 @@
  * 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.
  */
 
 
 #ifndef EVAL_H
 #define EVAL_H
 
 
-#include "main/mtypes.h"
+#include "dd.h"
 #include <stdbool.h>
 
 
 extern GLuint _mesa_evaluator_components( GLenum target );
 
 
 extern GLfloat *_mesa_copy_map_points1f( GLenum target,
                                       GLint ustride, GLint uorder,
                                       const GLfloat *points );
 
diff --git a/src/mesa/main/execmem.c b/src/mesa/main/execmem.c
index 21c5de7ad9d..2142b50a6e9 100644
--- a/src/mesa/main/execmem.c
+++ b/src/mesa/main/execmem.c
@@ -27,21 +27,21 @@
  * \file execmem.c
  * Functions for allocating executable memory.
  *
  * \author Keith Whitwell
  */
 
 
 #include <stdio.h>
 #include "imports.h"
 #include "execmem.h"
-
+#include "c11/threads.h"
 
 
 #if defined(__linux__) || defined(__OpenBSD__) || defined(_NetBSD__) || defined(__sun) || defined(__HAIKU__)
 
 /*
  * Allocate a large block of memory which can hold code then dole it out
  * in pieces by means of the generic memory manager code.
 */
 
 #include <unistd.h>
diff --git a/src/mesa/main/extensions.h b/src/mesa/main/extensions.h
index 159610b6e12..705d65dcdb5 100644
--- a/src/mesa/main/extensions.h
+++ b/src/mesa/main/extensions.h
@@ -29,21 +29,21 @@
  * 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.
  */
 
 
 #ifndef _EXTENSIONS_H_
 #define _EXTENSIONS_H_
 
-#include "glheader.h"
+#include "mtypes.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct gl_context;
 struct gl_extensions;
 
 extern void _mesa_enable_sw_extensions(struct gl_context *ctx);
 
diff --git a/src/mesa/main/extensions_table.c b/src/mesa/main/extensions_table.c
index 1e37fbcc462..6241705de13 100644
--- a/src/mesa/main/extensions_table.c
+++ b/src/mesa/main/extensions_table.c
@@ -16,21 +16,20 @@
  *
  * 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.
  */
 
-#include "main/mtypes.h"
 #include "main/extensions.h"
 
 /**
  * Given a member \c x of struct gl_extensions, return offset of
  * \c x in bytes.
  */
 #define o(x) offsetof(struct gl_extensions, x)
 
 /**
  * \brief Table of supported OpenGL extensions for all API's.
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c
index c7b639456cd..1c755592bd9 100644
--- a/src/mesa/main/ffvertex_prog.c
+++ b/src/mesa/main/ffvertex_prog.c
@@ -26,20 +26,21 @@
  **************************************************************************/
 
 /**
  * \file ffvertex_prog.c
  *
  * Create a vertex program to execute the current fixed function T&L pipeline.
  * \author Keith Whitwell
  */
 
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/enums.h"
 #include "main/ffvertex_prog.h"
 #include "program/program.h"
 #include "program/prog_cache.h"
 #include "program/prog_instruction.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 71c467f7e90..77ab16694ed 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -35,20 +35,22 @@ string = """/*
  *
  * There are both per-pixel and per-row packing functions:
  * - The former will be used by swrast to write values to the color, depth,
  *   stencil buffers when drawing points, lines and masked spans.
  * - The later will be used for image-oriented functions like glDrawPixels,
  *   glAccum, and glTexImage.
  */
 
 #include <stdint.h>
 
+#include "config.h"
+#include "errors.h"
 #include "format_pack.h"
 #include "format_utils.h"
 #include "macros.h"
 #include "util/format_rgb9e5.h"
 #include "util/format_r11g11b10f.h"
 #include "util/format_srgb.h"
 
 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
 
diff --git a/src/mesa/main/format_unpack.py b/src/mesa/main/format_unpack.py
index c8b1b24d169..87f64cc151a 100644
--- a/src/mesa/main/format_unpack.py
+++ b/src/mesa/main/format_unpack.py
@@ -35,20 +35,21 @@ string = """/*
  *
  * There are both per-pixel and per-row packing functions:
  * - The former will be used by swrast to write values to the color, depth,
  *   stencil buffers when drawing points, lines and masked spans.
  * - The later will be used for image-oriented functions like glDrawPixels,
  *   glAccum, and glTexImage.
  */
 
 #include <stdint.h>
 
+#include "errors.h"
 #include "format_unpack.h"
 #include "format_utils.h"
 #include "macros.h"
 #include "util/format_rgb9e5.h"
 #include "util/format_r11g11b10f.h"
 #include "util/format_srgb.h"
 
 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
 
 <%
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 31580750bd4..6959bf062a1 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -15,20 +15,21 @@
  *
  * 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.
  */
 
+#include "errors.h"
 #include "format_utils.h"
 #include "glformats.h"
 #include "format_pack.h"
 #include "format_unpack.h"
 
 const mesa_array_format RGBA32_FLOAT =
    MESA_ARRAY_FORMAT(4, 1, 1, 1, 4, 0, 1, 2, 3);
 
 const mesa_array_format RGBA8_UBYTE =
    MESA_ARRAY_FORMAT(1, 0, 0, 1, 4, 0, 1, 2, 3);
diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h
index 378997b38b2..78365cab533 100644
--- a/src/mesa/main/format_utils.h
+++ b/src/mesa/main/format_utils.h
@@ -24,20 +24,21 @@
  * 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.
  */
 
 #ifndef FORMAT_UTILS_H
 #define FORMAT_UTILS_H
 
+#include "formats.h"
 #include "imports.h"
 #include "macros.h"
 #include "util/rounding.h"
 #include "util/half_float.h"
 
 extern const mesa_array_format RGBA32_FLOAT;
 extern const mesa_array_format RGBA8_UBYTE;
 extern const mesa_array_format RGBA32_UINT;
 extern const mesa_array_format RGBA32_INT;
 
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 8d32757a879..fdb53afd570 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -17,20 +17,21 @@
  * 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.
  */
 
 
+#include "errors.h"
 #include "imports.h"
 #include "formats.h"
 #include "macros.h"
 #include "glformats.h"
 #include "c11/threads.h"
 #include "util/hash_table.h"
 
 /**
  * Information about texture formats.
  */
diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
index 5c9d8263ed1..844f1e270c0 100644
--- a/src/mesa/main/glformats.h
+++ b/src/mesa/main/glformats.h
@@ -29,20 +29,22 @@
 
 
 #include <stdbool.h>
 #include <GL/gl.h>
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+
 extern void
 _mesa_compute_component_mapping(GLenum inFormat, GLenum outFormat, GLubyte *map);
 
 extern GLboolean
 _mesa_type_is_packed(GLenum type);
 
 extern GLint
 _mesa_sizeof_type( GLenum type );
 
 extern GLint
diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h
index a6e6b6a2e64..16648820b1b 100644
--- a/src/mesa/main/glheader.h
+++ b/src/mesa/main/glheader.h
@@ -35,24 +35,26 @@
 
 #define GL_GLEXT_PROTOTYPES
 #include "GL/gl.h"
 #include "GL/glext.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+
 /* Custom Mesa types to save space. */
 typedef unsigned short GLenum16;
 typedef unsigned char GLbitfield8;
 typedef unsigned short GLbitfield16;
+typedef GLuint64 GLbitfield64;
 
 typedef int GLclampx;
 
 
 #ifndef GL_OES_EGL_image
 typedef void *GLeglImageOES;
 #endif
 
 
 #ifndef GL_OES_EGL_image_external
diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c
index 71dc9154ef2..c585bc51bbf 100644
--- a/src/mesa/main/glspirv.c
+++ b/src/mesa/main/glspirv.c
@@ -17,20 +17,21 @@
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
  */
 
 #include "glspirv.h"
 #include "errors.h"
 #include "shaderobj.h"
+#include "mtypes.h"
 
 #include "compiler/nir/nir.h"
 #include "compiler/spirv/nir_spirv.h"
 
 #include "program/program.h"
 
 #include "util/u_atomic.h"
 
 void
 _mesa_spirv_module_reference(struct gl_spirv_module **dest,
diff --git a/src/mesa/main/glspirv.h b/src/mesa/main/glspirv.h
index 81626ce75b5..cbcd3c0bcbc 100644
--- a/src/mesa/main/glspirv.h
+++ b/src/mesa/main/glspirv.h
@@ -18,26 +18,28 @@
  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
  */
 
 #ifndef GLSPIRV_H
 #define GLSPIRV_H
 
 #include "compiler/nir/nir.h"
-#include "mtypes.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+struct gl_shader;
+
 /**
  * A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
  *
  * It is reference-counted, because the same module can be attached to multiple
  * shader objects simultaneously.
  */
 struct gl_spirv_module {
    unsigned RefCount;
    GLint Length;
    char Binary[0];
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index 306246ca1c5..8cd5d022674 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -17,22 +17,20 @@
  * 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.
  */
 
 #ifndef _GLTHREAD_H
 #define _GLTHREAD_H
 
-#include "main/mtypes.h"
-
 /* The size of one batch and the maximum size of one call.
  *
  * This should be as low as possible, so that:
  * - multiple synchronizations within a frame don't slow us down much
  * - a smaller number of calls per frame can still get decent parallelism
  * - the memory footprint of the queue is low, and with that comes a lower
  *   chance of experiencing CPU cache thrashing
  * but it should be high enough so that u_queue overhead remains negligible.
  */
 #define MARSHAL_MAX_CMD_SIZE (8 * 1024)
@@ -43,20 +41,21 @@
  * waiting batches. There must be at least 1 slot for a waiting batch,
  * so the minimum number of batches is 3.
  */
 #define MARSHAL_MAX_BATCHES 8
 
 #include <inttypes.h>
 #include <stdbool.h>
 #include "util/u_queue.h"
 
 enum marshal_dispatch_cmd_id;
+struct gl_context;
 
 /** A single batch of commands queued up for execution. */
 struct glthread_batch
 {
    /** Batch fence for waiting for the execution to finish. */
    struct util_queue_fence fence;
 
    /** The worker thread will access the context with this. */
    struct gl_context *ctx;
 
diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index d0e575ea6b3..9a6d5ed5edb 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -27,20 +27,21 @@
  *
  * 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.
  */
 
+#include "errors.h"
 #include "glheader.h"
 #include "hash.h"
 #include "util/hash_table.h"
 
 
 /**
  * Create a new hash table.
  * 
  * \return pointer to a new, empty hash table.
  */
diff --git a/src/mesa/main/hash.h b/src/mesa/main/hash.h
index 02960e3b356..64f2962aba6 100644
--- a/src/mesa/main/hash.h
+++ b/src/mesa/main/hash.h
@@ -27,20 +27,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #ifndef HASH_H
 #define HASH_H
 
 
 #include "glheader.h"
 #include "imports.h"
+#include "c11/threads.h"
 
 /**
  * Magic GLuint object name that gets stored outside of the struct hash_table.
  *
  * The hash table needs a particular pointer to be the marker for a key that
  * was deleted from the table, along with NULL for the "never allocated in the
  * table" marker.  Legacy GL allows any GLuint to be used as a GL object name,
  * and we use a 1:1 mapping from GLuints to key pointers, so we need to be
  * able to track a GLuint that happens to match the deleted key outside of
  * struct hash_table.  We tell the hash table to use "1" as the deleted key
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index de4dd0e33d5..b4685b6dc35 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -41,21 +41,20 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include <stdio.h>
 #include <stdarg.h>
 #include "c99_math.h"
 #include "util/rounding.h" /* for _mesa_roundeven */
 #include "imports.h"
 #include "context.h"
-#include "mtypes.h"
 #include "version.h"
 
 #ifdef _GNU_SOURCE
 #include <locale.h>
 #ifdef __APPLE__
 #include <xlocale.h>
 #endif
 #endif
 
 
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index 51fa72cbc37..72ce8783ddb 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -34,21 +34,20 @@
 
 #ifndef IMPORTS_H
 #define IMPORTS_H
 
 
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
 #include "compiler.h"
 #include "glheader.h"
-#include "errors.h"
 #include "util/bitscan.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 /**********************************************************************/
 /** Memory macros */
 /*@{*/
diff --git a/src/mesa/main/menums.h b/src/mesa/main/menums.h
new file mode 100644
index 00000000000..40b16cb9cac
--- /dev/null
+++ b/src/mesa/main/menums.h
@@ -0,0 +1,213 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
+ * Copyright (C) 2018 Advanced Micro Devices, Inc.  All Rights Reserved.
+ *
+ * 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 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 menums.h
+ * Often used definitions and enums.
+ */
+
+#ifndef MENUMS_H
+#define MENUMS_H
+
+#include "util/macros.h"
+
+/**
+ * Enum for the OpenGL APIs we know about and may support.
+ *
+ * NOTE: This must match the api_enum table in
+ * src/mesa/main/get_hash_generator.py
+ */
+typedef enum
+{
+   API_OPENGL_COMPAT,      /* legacy / compatibility contexts */
+   API_OPENGLES,
+   API_OPENGLES2,
+   API_OPENGL_CORE,
+   API_OPENGL_LAST = API_OPENGL_CORE
+} gl_api;
+
+/**
+ * An index for each type of texture object.  These correspond to the GL
+ * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
+ * Note: the order is from highest priority to lowest priority.
+ */
+typedef enum
+{
+   TEXTURE_2D_MULTISAMPLE_INDEX,
+   TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX,
+   TEXTURE_CUBE_ARRAY_INDEX,
+   TEXTURE_BUFFER_INDEX,
+   TEXTURE_2D_ARRAY_INDEX,
+   TEXTURE_1D_ARRAY_INDEX,
+   TEXTURE_EXTERNAL_INDEX,
+   TEXTURE_CUBE_INDEX,
+   TEXTURE_3D_INDEX,
+   TEXTURE_RECT_INDEX,
+   TEXTURE_2D_INDEX,
+   TEXTURE_1D_INDEX,
+   NUM_TEXTURE_TARGETS
+} gl_texture_index;
+
+/**
+ * Remapped color logical operations
+ *
+ * With the exception of NVIDIA hardware, which consumes the OpenGL enumerants
+ * directly, everything wants this mapping of color logical operations.
+ *
+ * Fun fact: These values are just the bit-reverse of the low-nibble of the GL
+ * enumerant values (i.e., `GL_NOOP & 0x0f` is `b0101' while
+ * \c COLOR_LOGICOP_NOOP is `b1010`).
+ *
+ * Fun fact #2: These values are just an encoding of the operation as a table
+ * of bit values. The result of the logic op is:
+ *
+ *    result_bit = (logic_op >> (2 * src_bit + dst_bit)) & 1
+ *
+ * For the GL enums, the result is:
+ *
+ *    result_bit = logic_op & (1 << (2 * src_bit + dst_bit))
+ */
+enum PACKED gl_logicop_mode {
+   COLOR_LOGICOP_CLEAR = 0,
+   COLOR_LOGICOP_NOR = 1,
+   COLOR_LOGICOP_AND_INVERTED = 2,
+   COLOR_LOGICOP_COPY_INVERTED = 3,
+   COLOR_LOGICOP_AND_REVERSE = 4,
+   COLOR_LOGICOP_INVERT = 5,
+   COLOR_LOGICOP_XOR = 6,
+   COLOR_LOGICOP_NAND = 7,
+   COLOR_LOGICOP_AND = 8,
+   COLOR_LOGICOP_EQUIV = 9,
+   COLOR_LOGICOP_NOOP = 10,
+   COLOR_LOGICOP_OR_INVERTED = 11,
+   COLOR_LOGICOP_COPY = 12,
+   COLOR_LOGICOP_OR_REVERSE = 13,
+   COLOR_LOGICOP_OR = 14,
+   COLOR_LOGICOP_SET = 15
+};
+
+/**
+ * Indexes for all renderbuffers
+ */
+typedef enum
+{
+   /* the four standard color buffers */
+   BUFFER_FRONT_LEFT,
+   BUFFER_BACK_LEFT,
+   BUFFER_FRONT_RIGHT,
+   BUFFER_BACK_RIGHT,
+   BUFFER_DEPTH,
+   BUFFER_STENCIL,
+   BUFFER_ACCUM,
+   /* optional aux buffer */
+   BUFFER_AUX0,
+   /* generic renderbuffers */
+   BUFFER_COLOR0,
+   BUFFER_COLOR1,
+   BUFFER_COLOR2,
+   BUFFER_COLOR3,
+   BUFFER_COLOR4,
+   BUFFER_COLOR5,
+   BUFFER_COLOR6,
+   BUFFER_COLOR7,
+   BUFFER_COUNT,
+   BUFFER_NONE = -1,
+} gl_buffer_index;
+
+typedef enum
+{
+   MAP_USER,
+   MAP_INTERNAL,
+   MAP_COUNT
+} gl_map_buffer_index;
+
+/** @{
+ *
+ * These are a mapping of the GL_ARB_debug_output/GL_KHR_debug enums
+ * to small enums suitable for use as an array index.
+ */
+
+enum mesa_debug_source
+{
+   MESA_DEBUG_SOURCE_API,
+   MESA_DEBUG_SOURCE_WINDOW_SYSTEM,
+   MESA_DEBUG_SOURCE_SHADER_COMPILER,
+   MESA_DEBUG_SOURCE_THIRD_PARTY,
+   MESA_DEBUG_SOURCE_APPLICATION,
+   MESA_DEBUG_SOURCE_OTHER,
+   MESA_DEBUG_SOURCE_COUNT
+};
+
+enum mesa_debug_type
+{
+   MESA_DEBUG_TYPE_ERROR,
+   MESA_DEBUG_TYPE_DEPRECATED,
+   MESA_DEBUG_TYPE_UNDEFINED,
+   MESA_DEBUG_TYPE_PORTABILITY,
+   MESA_DEBUG_TYPE_PERFORMANCE,
+   MESA_DEBUG_TYPE_OTHER,
+   MESA_DEBUG_TYPE_MARKER,
+   MESA_DEBUG_TYPE_PUSH_GROUP,
+   MESA_DEBUG_TYPE_POP_GROUP,
+   MESA_DEBUG_TYPE_COUNT
+};
+
+enum mesa_debug_severity
+{
+   MESA_DEBUG_SEVERITY_LOW,
+   MESA_DEBUG_SEVERITY_MEDIUM,
+   MESA_DEBUG_SEVERITY_HIGH,
+   MESA_DEBUG_SEVERITY_NOTIFICATION,
+   MESA_DEBUG_SEVERITY_COUNT
+};
+
+/** @} */
+
+/** Set a single bit */
+#define BITFIELD_BIT(b)      (1u << (b))
+/** Set all bits up to excluding bit b */
+#define BITFIELD_MASK(b)      \
+   ((b) == 32 ? (~0u) : BITFIELD_BIT((b) % 32) - 1)
+/** Set count bits starting from bit b  */
+#define BITFIELD_RANGE(b, count) \
+   (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b))
+
+
+/**
+ * \name 64-bit extension of GLbitfield.
+ */
+/*@{*/
+
+/** Set a single bit */
+#define BITFIELD64_BIT(b)      (1ull << (b))
+/** Set all bits up to excluding bit b */
+#define BITFIELD64_MASK(b)      \
+   ((b) == 64 ? (~0ull) : BITFIELD64_BIT(b) - 1)
+/** Set count bits starting from bit b  */
+#define BITFIELD64_RANGE(b, count) \
+   (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
+
+#endif
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index 1ed82c52ab6..9b6eee41dbd 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -20,20 +20,21 @@
  * 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 mipmap.c  mipmap generation and teximage resizing functions.
  */
 
+#include "errors.h"
 #include "imports.h"
 #include "formats.h"
 #include "glformats.h"
 #include "mipmap.h"
 #include "mtypes.h"
 #include "teximage.h"
 #include "texobj.h"
 #include "texstore.h"
 #include "image.h"
 #include "macros.h"
diff --git a/src/mesa/main/mipmap.h b/src/mesa/main/mipmap.h
index 1f108f7e5d8..3ec99721743 100644
--- a/src/mesa/main/mipmap.h
+++ b/src/mesa/main/mipmap.h
@@ -19,21 +19,24 @@
  * 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.
  */
 
 
 #ifndef MIPMAP_H
 #define MIPMAP_H
 
-#include "mtypes.h"
+#include "glheader.h"
+
+struct gl_context;
+struct gl_texture_object;
 
 unsigned
 _mesa_compute_num_levels(struct gl_context *ctx,
                          struct gl_texture_object *texObj,
                          GLenum target);
 
 extern void
 _mesa_generate_mipmap_level(GLenum target,
                             GLenum datatype, GLuint comps,
                             GLint border,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b7a7b34a090..b65e7b2c3c2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -32,62 +32,36 @@
 
 #ifndef MTYPES_H
 #define MTYPES_H
 
 
 #include <stdint.h>             /* uint32_t */
 #include <stdbool.h>
 #include "c11/threads.h"
 
 #include "main/glheader.h"
+#include "main/menums.h"
 #include "main/config.h"
 #include "glapi/glapi.h"
 #include "math/m_matrix.h"	/* GLmatrix */
 #include "compiler/shader_enums.h"
 #include "compiler/shader_info.h"
 #include "main/formats.h"       /* MESA_FORMAT_COUNT */
 #include "compiler/glsl/list.h"
 #include "util/simple_mtx.h"
 #include "util/u_dynarray.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
-/** Set a single bit */
-#define BITFIELD_BIT(b)      ((GLbitfield)1 << (b))
-/** Set all bits up to excluding bit b */
-#define BITFIELD_MASK(b)      \
-   ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT((b) % 32) - 1)
-/** Set count bits starting from bit b  */
-#define BITFIELD_RANGE(b, count) \
-   (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b))
-
-
-/**
- * \name 64-bit extension of GLbitfield.
- */
-/*@{*/
-typedef GLuint64 GLbitfield64;
-
-/** Set a single bit */
-#define BITFIELD64_BIT(b)      ((GLbitfield64)1 << (b))
-/** Set all bits up to excluding bit b */
-#define BITFIELD64_MASK(b)      \
-   ((b) == 64 ? (~(GLbitfield64)0) : BITFIELD64_BIT(b) - 1)
-/** Set count bits starting from bit b  */
-#define BITFIELD64_RANGE(b, count) \
-   (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
-
-
 #define GET_COLORMASK_BIT(mask, buf, chan) (((mask) >> (4 * (buf) + (chan))) & 0x1)
 #define GET_COLORMASK(mask, buf) (((mask) >> (4 * (buf))) & 0xf)
 
 
 /**
  * \name Some forward type declarations
  */
 /*@{*/
 struct _mesa_HashTable;
 struct gl_attrib_node;
@@ -128,48 +102,20 @@ _mesa_varying_slot_in_fs(gl_varying_slot slot)
    case VARYING_SLOT_TESS_LEVEL_OUTER:
    case VARYING_SLOT_TESS_LEVEL_INNER:
    case VARYING_SLOT_BOUNDING_BOX0:
    case VARYING_SLOT_BOUNDING_BOX1:
       return GL_FALSE;
    default:
       return GL_TRUE;
    }
 }
 
-/**
- * Indexes for all renderbuffers
- */
-typedef enum
-{
-   /* the four standard color buffers */
-   BUFFER_FRONT_LEFT,
-   BUFFER_BACK_LEFT,
-   BUFFER_FRONT_RIGHT,
-   BUFFER_BACK_RIGHT,
-   BUFFER_DEPTH,
-   BUFFER_STENCIL,
-   BUFFER_ACCUM,
-   /* optional aux buffer */
-   BUFFER_AUX0,
-   /* generic renderbuffers */
-   BUFFER_COLOR0,
-   BUFFER_COLOR1,
-   BUFFER_COLOR2,
-   BUFFER_COLOR3,
-   BUFFER_COLOR4,
-   BUFFER_COLOR5,
-   BUFFER_COLOR6,
-   BUFFER_COLOR7,
-   BUFFER_COUNT,
-   BUFFER_NONE = -1,
-} gl_buffer_index;
-
 /**
  * Bit flags for all renderbuffers
  */
 #define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
 #define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
 #define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
 #define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
 #define BUFFER_BIT_AUX0         (1 << BUFFER_AUX0)
 #define BUFFER_BIT_AUX1         (1 << BUFFER_AUX1)
 #define BUFFER_BIT_AUX2         (1 << BUFFER_AUX2)
@@ -410,57 +356,20 @@ struct gl_accum_attrib
  * Used for storing clear color, texture border color, etc.
  * The float values are typically unclamped.
  */
 union gl_color_union
 {
    GLfloat f[4];
    GLint i[4];
    GLuint ui[4];
 };
 
-/**
- * Remapped color logical operations
- *
- * With the exception of NVIDIA hardware, which consumes the OpenGL enumerants
- * directly, everything wants this mapping of color logical operations.
- *
- * Fun fact: These values are just the bit-reverse of the low-nibble of the GL
- * enumerant values (i.e., `GL_NOOP & 0x0f` is `b0101' while
- * \c COLOR_LOGICOP_NOOP is `b1010`).
- *
- * Fun fact #2: These values are just an encoding of the operation as a table
- * of bit values. The result of the logic op is:
- *
- *    result_bit = (logic_op >> (2 * src_bit + dst_bit)) & 1
- *
- * For the GL enums, the result is:
- *
- *    result_bit = logic_op & (1 << (2 * src_bit + dst_bit))
- */
-enum PACKED gl_logicop_mode {
-   COLOR_LOGICOP_CLEAR = 0,
-   COLOR_LOGICOP_NOR = 1,
-   COLOR_LOGICOP_AND_INVERTED = 2,
-   COLOR_LOGICOP_COPY_INVERTED = 3,
-   COLOR_LOGICOP_AND_REVERSE = 4,
-   COLOR_LOGICOP_INVERT = 5,
-   COLOR_LOGICOP_XOR = 6,
-   COLOR_LOGICOP_NAND = 7,
-   COLOR_LOGICOP_AND = 8,
-   COLOR_LOGICOP_EQUIV = 9,
-   COLOR_LOGICOP_NOOP = 10,
-   COLOR_LOGICOP_OR_INVERTED = 11,
-   COLOR_LOGICOP_COPY = 12,
-   COLOR_LOGICOP_OR_REVERSE = 13,
-   COLOR_LOGICOP_OR = 14,
-   COLOR_LOGICOP_SET = 15
-};
 
 /**
  * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
  */
 struct gl_colorbuffer_attrib
 {
    GLuint ClearIndex;                      /**< Index for glClear */
    union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
    GLuint IndexMask;                       /**< Color index write mask */
 
@@ -910,43 +819,20 @@ struct gl_stencil_attrib
    GLenum16 FailFunc[3];	/**< Fail function */
    GLenum16 ZPassFunc[3];	/**< Depth buffer pass function */
    GLenum16 ZFailFunc[3];	/**< Depth buffer fail function */
    GLint Ref[3];		/**< Reference value */
    GLuint ValueMask[3];		/**< Value mask */
    GLuint WriteMask[3];		/**< Write mask */
    GLuint Clear;		/**< Clear value */
 };
 
 
-/**
- * An index for each type of texture object.  These correspond to the GL
- * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
- * Note: the order is from highest priority to lowest priority.
- */
-typedef enum
-{
-   TEXTURE_2D_MULTISAMPLE_INDEX,
-   TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX,
-   TEXTURE_CUBE_ARRAY_INDEX,
-   TEXTURE_BUFFER_INDEX,
-   TEXTURE_2D_ARRAY_INDEX,
-   TEXTURE_1D_ARRAY_INDEX,
-   TEXTURE_EXTERNAL_INDEX,
-   TEXTURE_CUBE_INDEX,
-   TEXTURE_3D_INDEX,
-   TEXTURE_RECT_INDEX,
-   TEXTURE_2D_INDEX,
-   TEXTURE_1D_INDEX,
-   NUM_TEXTURE_TARGETS
-} gl_texture_index;
-
-
 /**
  * Bit flags for each type of texture object
  */
 /*@{*/
 #define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
 #define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
 #define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
 #define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
 #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
 #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
@@ -1404,28 +1290,20 @@ struct gl_transform_attrib
  * Viewport attribute group (GL_VIEWPORT_BIT).
  */
 struct gl_viewport_attrib
 {
    GLfloat X, Y;		/**< position */
    GLfloat Width, Height;	/**< size */
    GLfloat Near, Far;		/**< Depth buffer range */
 };
 
 
-typedef enum
-{
-   MAP_USER,
-   MAP_INTERNAL,
-   MAP_COUNT
-} gl_map_buffer_index;
-
-
 /**
  * Fields describing a mapped buffer range.
  */
 struct gl_buffer_mapping
 {
    GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
    GLvoid *Pointer;        /**< User-space address of mapping */
    GLintptr Offset;        /**< Mapped offset */
    GLsizeiptr Length;      /**< Mapped length */
 };
@@ -1621,36 +1499,20 @@ struct gl_vertex_array_object
    gl_attribute_map_mode _AttributeMapMode;
 
    /** Mask of VERT_BIT_* values indicating changed/dirty arrays */
    GLbitfield NewArrays;
 
    /** The index buffer (also known as the element array buffer in OpenGL). */
    struct gl_buffer_object *IndexBufferObj;
 };
 
 
-/**
- * Enum for the OpenGL APIs we know about and may support.
- *
- * NOTE: This must match the api_enum table in
- * src/mesa/main/get_hash_generator.py
- */
-typedef enum
-{
-   API_OPENGL_COMPAT,      /* legacy / compatibility contexts */
-   API_OPENGLES,
-   API_OPENGLES2,
-   API_OPENGL_CORE,
-   API_OPENGL_LAST = API_OPENGL_CORE
-} gl_api;
-
-
 /**
  * Vertex array state
  */
 struct gl_array_attrib
 {
    /** Currently bound array object. */
    struct gl_vertex_array_object *VAO;
 
    /** The default vertex array object */
    struct gl_vertex_array_object *DefaultVAO;
@@ -2105,53 +1967,20 @@ struct gl_bindless_image
    GLboolean bound;
 
    /** Access qualifier (GL_READ_WRITE, GL_READ_ONLY, GL_WRITE_ONLY) */
    GLenum16 access;
 
    /** Pointer to the base of the data. */
    GLvoid *data;
 };
 
 
-/**
- * Names of the various vertex/fragment program register files, etc.
- *
- * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
- * All values should fit in a 4-bit field.
- *
- * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
- * considered to be "uniform" variables since they can only be set outside
- * glBegin/End.  They're also all stored in the same Parameters array.
- */
-typedef enum
-{
-   PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
-   PROGRAM_ARRAY,       /**< Arrays & Matrixes */
-   PROGRAM_INPUT,       /**< machine->Inputs[] */
-   PROGRAM_OUTPUT,      /**< machine->Outputs[] */
-   PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
-   PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
-   PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
-   PROGRAM_WRITE_ONLY,  /**< A dummy, write-only register */
-   PROGRAM_ADDRESS,     /**< machine->AddressReg */
-   PROGRAM_SAMPLER,     /**< for shader samplers, compile-time only */
-   PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
-   PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
-   PROGRAM_IMMEDIATE,   /**< Immediate value, used by TGSI */
-   PROGRAM_BUFFER,      /**< for shader buffers, compile-time only */
-   PROGRAM_MEMORY,      /**< for shared, global and local memory */
-   PROGRAM_IMAGE,       /**< for shader images, compile-time only */
-   PROGRAM_HW_ATOMIC,   /**< for hw atomic counters, compile-time only */
-   PROGRAM_FILE_MAX
-} gl_register_file;
-
-
 /**
  * Current vertex processing mode: fixed function vs. shader.
  * In reality, fixed function is probably implemented by a shader but that's
  * not what we care about here.
  */
 typedef enum
 {
    VP_MODE_FF,     /**< legacy / fixed function */
    VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
    VP_MODE_MAX     /**< for sizing arrays */
@@ -4524,62 +4353,20 @@ struct gl_dlist_state
    GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
 
    struct {
       /* State known to have been set by the currently-compiling display
        * list.  Used to eliminate some redundant state changes.
        */
       GLenum16 ShadeModel;
    } Current;
 };
 
-/** @{
- *
- * These are a mapping of the GL_ARB_debug_output/GL_KHR_debug enums
- * to small enums suitable for use as an array index.
- */
-
-enum mesa_debug_source
-{
-   MESA_DEBUG_SOURCE_API,
-   MESA_DEBUG_SOURCE_WINDOW_SYSTEM,
-   MESA_DEBUG_SOURCE_SHADER_COMPILER,
-   MESA_DEBUG_SOURCE_THIRD_PARTY,
-   MESA_DEBUG_SOURCE_APPLICATION,
-   MESA_DEBUG_SOURCE_OTHER,
-   MESA_DEBUG_SOURCE_COUNT
-};
-
-enum mesa_debug_type
-{
-   MESA_DEBUG_TYPE_ERROR,
-   MESA_DEBUG_TYPE_DEPRECATED,
-   MESA_DEBUG_TYPE_UNDEFINED,
-   MESA_DEBUG_TYPE_PORTABILITY,
-   MESA_DEBUG_TYPE_PERFORMANCE,
-   MESA_DEBUG_TYPE_OTHER,
-   MESA_DEBUG_TYPE_MARKER,
-   MESA_DEBUG_TYPE_PUSH_GROUP,
-   MESA_DEBUG_TYPE_POP_GROUP,
-   MESA_DEBUG_TYPE_COUNT
-};
-
-enum mesa_debug_severity
-{
-   MESA_DEBUG_SEVERITY_LOW,
-   MESA_DEBUG_SEVERITY_MEDIUM,
-   MESA_DEBUG_SEVERITY_HIGH,
-   MESA_DEBUG_SEVERITY_NOTIFICATION,
-   MESA_DEBUG_SEVERITY_COUNT
-};
-
-/** @} */
-
 /**
  * Driver-specific state flags.
  *
  * These are or'd with gl_context::NewDriverState to notify a driver about
  * a state change. The driver sets the flags at context creation and
  * the meaning of the bits set is opaque to core Mesa.
  */
 struct gl_driver_flags
 {
    /** gl_context::Array::_DrawArrays (vertex array state) */
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 94a6d285d8e..64ad115f8b5 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -35,20 +35,21 @@
  *
  * See also:
  * - http://msdn.microsoft.com/en-us/library/1yk3ydd7.aspx
  * - http://msdn.microsoft.com/en-us/library/chh3fb0k.aspx
  */
 #if defined(_MSC_VER) && defined(_M_X64)
 #  pragma optimize( "g", off )
 #endif
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "enums.h"
 #include "image.h"
 #include "imports.h"
 #include "macros.h"
 #include "mtypes.h"
 #include "pack.h"
 #include "pixeltransfer.h"
 #include "imports.h"
 #include "glformats.h"
diff --git a/src/mesa/main/pack.h b/src/mesa/main/pack.h
index ac0a099e391..8625a145fca 100644
--- a/src/mesa/main/pack.h
+++ b/src/mesa/main/pack.h
@@ -21,22 +21,24 @@
  * 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.
  */
 
 
 #ifndef PACK_H
 #define PACK_H
 
 
-#include "mtypes.h"
+#include "glheader.h"
 
+struct gl_context;
+struct gl_pixelstore_attrib;
 
 extern void
 _mesa_unpack_polygon_stipple(const GLubyte *pattern, GLuint dest[32],
                              const struct gl_pixelstore_attrib *unpacking);
 
 
 extern void
 _mesa_pack_polygon_stipple(const GLuint pattern[32], GLubyte *dest,
                            const struct gl_pixelstore_attrib *packing);
 
diff --git a/src/mesa/main/pbo.c b/src/mesa/main/pbo.c
index 7762324a4ae..cea55f2a0d2 100644
--- a/src/mesa/main/pbo.c
+++ b/src/mesa/main/pbo.c
@@ -24,20 +24,21 @@
  */
 
 
 /**
  * \file pbo.c
  * \brief Functions related to Pixel Buffer Objects.
  */
 
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "bufferobj.h"
 #include "glformats.h"
 #include "image.h"
 #include "imports.h"
 #include "mtypes.h"
 #include "pbo.h"
 
 
 
diff --git a/src/mesa/main/pbo.h b/src/mesa/main/pbo.h
index b3f24e62bd2..bc764175ff4 100644
--- a/src/mesa/main/pbo.h
+++ b/src/mesa/main/pbo.h
@@ -21,22 +21,24 @@
  * 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.
  */
 
 
 #ifndef PBO_H
 #define PBO_H
 
 
-#include "mtypes.h"
+#include "glheader.h"
 
+struct gl_context;
+struct gl_pixelstore_attrib;
 
 extern GLboolean
 _mesa_validate_pbo_access(GLuint dimensions,
                           const struct gl_pixelstore_attrib *pack,
                           GLsizei width, GLsizei height, GLsizei depth,
                           GLenum format, GLenum type, GLsizei clientMemSize,
                           const GLvoid *ptr);
 
 extern const GLvoid *
 _mesa_map_pbo_source(struct gl_context *ctx,
diff --git a/src/mesa/main/pixeltransfer.h b/src/mesa/main/pixeltransfer.h
index b0a301f2638..caa2911fcf1 100644
--- a/src/mesa/main/pixeltransfer.h
+++ b/src/mesa/main/pixeltransfer.h
@@ -21,21 +21,23 @@
  * 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.
  */
 
 
 #ifndef PIXELTRANSFER_H
 #define PIXELTRANSFER_H
 
 
-#include "mtypes.h"
+#include "glheader.h"
+
+struct gl_context;
 
 
 extern void
 _mesa_scale_and_bias_rgba(GLuint n, GLfloat rgba[][4],
                           GLfloat rScale, GLfloat gScale,
                           GLfloat bScale, GLfloat aScale,
                           GLfloat rBias, GLfloat gBias,
                           GLfloat bBias, GLfloat aBias);
 
 extern void
diff --git a/src/mesa/main/querymatrix.c b/src/mesa/main/querymatrix.c
index 18361c929fb..b80bae6a6d2 100644
--- a/src/mesa/main/querymatrix.c
+++ b/src/mesa/main/querymatrix.c
@@ -10,20 +10,21 @@
  * Code to implement GL_OES_query_matrix.  See the spec at:
  * http://www.khronos.org/registry/gles/extensions/OES/OES_query_matrix.txt
  */
 
 
 #include <stdlib.h>
 #include "c99_math.h"
 #include "glheader.h"
 #include "querymatrix.h"
 #include "main/get.h"
+#include "util/macros.h"
 
 
 /**
  * This is from the GL_OES_query_matrix extension specification:
  *
  *  GLbitfield glQueryMatrixxOES( GLfixed mantissa[16],
  *                                GLint   exponent[16] )
  *  mantissa[16] contains the contents of the current matrix in GLfixed
  *  format.  exponent[16] contains the unbiased exponents applied to the
  *  matrix components, so that the internal representation of component i
diff --git a/src/mesa/main/querymatrix.h b/src/mesa/main/querymatrix.h
index e08d843a963..64921891000 100644
--- a/src/mesa/main/querymatrix.h
+++ b/src/mesa/main/querymatrix.h
@@ -18,21 +18,21 @@
  * 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.
  */
 
 #ifndef QUERYMATRIX_H
 #define QUERYMATRIX_H
 
 
-#include "mtypes.h"
+#include "glheader.h"
 
 
 /*
  * API functions
  */
 
 extern GLbitfield GLAPIENTRY
 _mesa_QueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]);
 
 #endif
diff --git a/src/mesa/main/remap.c b/src/mesa/main/remap.c
index 6dc4235cba0..fa412c0c4f7 100644
--- a/src/mesa/main/remap.c
+++ b/src/mesa/main/remap.c
@@ -37,20 +37,21 @@
 
 #include <stdbool.h>
 #include "remap.h"
 #include "imports.h"
 #include "glapi/glapi.h"
 
 #define MAX_ENTRY_POINTS 16
 
 #define need_MESA_remap_table
 #include "main/remap_helper.h"
+#include "errors.h"
 
 
 /* this is global for quick access */
 int driDispatchRemapTable[driDispatchRemapTable_size];
 
 
 /**
  * Map a function by its spec.  The function will be added to glapi,
  * and the dispatch offset will be returned.
  *
diff --git a/src/mesa/main/renderbuffer.h b/src/mesa/main/renderbuffer.h
index f9a6462d536..3f568e1e7f1 100644
--- a/src/mesa/main/renderbuffer.h
+++ b/src/mesa/main/renderbuffer.h
@@ -20,21 +20,21 @@
  * 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.
  */
 
 
 #ifndef RENDERBUFFER_H
 #define RENDERBUFFER_H
 
 #include "glheader.h"
-#include "mtypes.h"
+#include "menums.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct gl_context;
 struct gl_framebuffer;
 struct gl_renderbuffer;
 
 extern void
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 6712bb45fb2..86064a98b97 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -22,21 +22,20 @@
  */
 
 /**
  * \file shader_query.cpp
  * C-to-C++ bridge functions to query GLSL shader data
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
 
 #include "main/context.h"
-#include "main/core.h"
 #include "main/enums.h"
 #include "main/shaderapi.h"
 #include "main/shaderobj.h"
 #include "main/uniforms.h"
 #include "compiler/glsl/glsl_symbol_table.h"
 #include "compiler/glsl/ir.h"
 #include "compiler/glsl/program.h"
 #include "compiler/glsl/string_to_uint_map.h"
 
 
diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h
index 7915248e391..dbfd68fd3a1 100644
--- a/src/mesa/main/shaderapi.h
+++ b/src/mesa/main/shaderapi.h
@@ -22,29 +22,34 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #ifndef SHADERAPI_H
 #define SHADERAPI_H
 
 
 #include "glheader.h"
-
+#include "compiler/shader_enums.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 struct _glapi_table;
 struct gl_context;
+struct gl_linked_shader;
+struct gl_pipeline_object;
+struct gl_program;
+struct gl_program_resource;
+struct gl_shader;
 struct gl_shader_program;
 
 extern GLbitfield
 _mesa_get_shader_flags(void);
 
 extern const char *
 _mesa_get_shader_capture_path(void);
 
 extern void
 _mesa_copy_string(GLchar *dst, GLsizei maxLength,
diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h
index fedb4dc3dec..c7ccc54afe4 100644
--- a/src/mesa/main/shaderobj.h
+++ b/src/mesa/main/shaderobj.h
@@ -21,28 +21,33 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #ifndef SHADEROBJ_H
 #define SHADEROBJ_H
 
 
 #include "main/glheader.h"
-#include "main/mtypes.h"
+#include "compiler/shader_enums.h"
 #include "program/ir_to_mesa.h"
+#include "util/macros.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_shader_program_data;
+struct gl_linked_shader;
+struct dd_function_table;
+struct gl_pipeline_object;
 
 /**
  * Internal functions
  */
 
 extern void
 _mesa_init_shader_state(struct gl_context * ctx);
 
 extern void
 _mesa_free_shader_state(struct gl_context *ctx);
diff --git a/src/mesa/main/texcompress_bptc.c b/src/mesa/main/texcompress_bptc.c
index 26e59158007..fd37be97f36 100644
--- a/src/mesa/main/texcompress_bptc.c
+++ b/src/mesa/main/texcompress_bptc.c
@@ -27,20 +27,21 @@
  */
 
 #include <stdbool.h>
 #include "texcompress.h"
 #include "texcompress_bptc.h"
 #include "util/format_srgb.h"
 #include "util/half_float.h"
 #include "texstore.h"
 #include "macros.h"
 #include "image.h"
+#include "mtypes.h"
 
 #define BLOCK_SIZE 4
 #define N_PARTITIONS 64
 #define BLOCK_BYTES 16
 
 struct bptc_unorm_mode {
    int n_subsets;
    int n_partition_bits;
    bool has_rotation_bits;
    bool has_index_selection_bit;
diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
index faeaae90937..099787b7f40 100644
--- a/src/mesa/main/texcompress_etc.c
+++ b/src/mesa/main/texcompress_etc.c
@@ -34,20 +34,21 @@
  * GL_COMPRESSED_SIGNED_R11_EAC
  * GL_COMPRESSED_SIGNED_RG11_EAC
  * MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1
  * MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1
  */
 
 #include <stdbool.h>
 #include "texcompress.h"
 #include "texcompress_etc.h"
 #include "texstore.h"
+#include "config.h"
 #include "macros.h"
 #include "format_unpack.h"
 #include "util/format_srgb.h"
 
 
 struct etc2_block {
    int distance;
    uint64_t pixel_indices[2];
    const int *modifier_tables[2];
    bool flipped;
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index c5646fbd7a3..19df6baf371 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -22,28 +22,30 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 /**
  * \file texcompress_fxt1.c
  * GL_3DFX_texture_compression_FXT1 support.
  */
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "imports.h"
 #include "image.h"
 #include "macros.h"
 #include "mipmap.h"
 #include "texcompress.h"
 #include "texcompress_fxt1.h"
 #include "texstore.h"
+#include "mtypes.h"
 
 
 static void
 fxt1_encode (GLuint width, GLuint height, GLint comps,
              const void *source, GLint srcRowStride,
              void *dest, GLint destRowStride);
 
 static void
 fxt1_decode_1 (const void *texture, GLint stride,
                GLint i, GLint j, GLubyte *rgba);
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
index 8cab7a56b1a..843b42e54e6 100644
--- a/src/mesa/main/texcompress_rgtc.c
+++ b/src/mesa/main/texcompress_rgtc.c
@@ -26,20 +26,21 @@
  * Author:
  *    Dave Airlie
  */
 
 /**
  * \file texcompress_rgtc.c
  * GL_EXT_texture_compression_rgtc support.
  */
 
 
+#include "config.h"
 #include "glheader.h"
 #include "imports.h"
 #include "image.h"
 #include "macros.h"
 #include "mipmap.h"
 #include "texcompress.h"
 #include "util/rgtc.h"
 #include "texcompress_rgtc.h"
 #include "texstore.h"
 
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index dbac1fe8cb8..743e6b73ddf 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -26,21 +26,20 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #ifndef TEXTOBJ_H
 #define TEXTOBJ_H
 
 
 #include "glheader.h"
-#include "mtypes.h"
 #include "samplerobj.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 /**
  * \name Internal functions
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 3314e557c0a..31163f67717 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -44,20 +44,21 @@
  * Texture image processing is actually kind of complicated.  We have to do:
  *    Format/type conversions
  *    pixel unpacking
  *    pixel transfer (scale, bais, lookup, etc)
  *
  * These functions can handle most everything, including processing full
  * images and sub-images.
  */
 
 
+#include "errors.h"
 #include "glheader.h"
 #include "bufferobj.h"
 #include "format_pack.h"
 #include "format_utils.h"
 #include "image.h"
 #include "macros.h"
 #include "mipmap.h"
 #include "mtypes.h"
 #include "pack.h"
 #include "pbo.h"
diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h
index b8281c51e2a..2fef7ba7d7d 100644
--- a/src/mesa/main/texstore.h
+++ b/src/mesa/main/texstore.h
@@ -29,23 +29,27 @@
  * Texture image storage routines.
  *
  * \author Brian Paul
  */
 
 
 #ifndef TEXSTORE_H
 #define TEXSTORE_H
 
 
-#include "mtypes.h"
+#include "glheader.h"
 #include "formats.h"
+#include "util/macros.h"
 
+struct gl_context;
+struct gl_pixelstore_attrib;
+struct gl_texture_image;
 
 /**
  * This macro defines the (many) parameters to the texstore functions.
  * \param dims  either 1 or 2 or 3
  * \param baseInternalFormat  user-specified base internal format
  * \param dstFormat  destination Mesa texture format
  * \param dstX/Y/Zoffset  destination x/y/z offset (ala TexSubImage), in texels
  * \param dstRowStride  destination image row stride, in bytes
  * \param dstSlices  array of addresses of image slices (for 3D, array texture)
  * \param srcWidth/Height/Depth  source image size, in pixels
diff --git a/src/mesa/main/texturebindless.h b/src/mesa/main/texturebindless.h
index 8a9fff6d57e..ac97e95e81c 100644
--- a/src/mesa/main/texturebindless.h
+++ b/src/mesa/main/texturebindless.h
@@ -17,26 +17,28 @@
  * 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.
  */
 
 #ifndef TEXTUREBINDLESS_H
 #define TEXTUREBINDLESS_H
 
-#include "mtypes.h"
+#include "glheader.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+
 /**
  * \name Internal functions
  */
 /*@{*/
 
 void
 _mesa_init_resident_handles(struct gl_context *ctx);
 void
 _mesa_free_resident_handles(struct gl_context *ctx);
 
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index f901fcb3e58..de594fcc3d7 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -19,22 +19,22 @@
  * 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.
  */
 
 #include <stdlib.h>
 #include <inttypes.h>  /* for PRIx64 macro */
+#include <math.h>
 
-#include "main/core.h"
 #include "main/context.h"
 #include "main/shaderapi.h"
 #include "main/shaderobj.h"
 #include "main/uniforms.h"
 #include "compiler/glsl/ir.h"
 #include "compiler/glsl/ir_uniform.h"
 #include "compiler/glsl/glsl_parser_extras.h"
 #include "compiler/glsl/program.h"
 #include "util/bitscan.h"
 
diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h
index 77027be8002..25d2a29e731 100644
--- a/src/mesa/main/varray.h
+++ b/src/mesa/main/varray.h
@@ -20,22 +20,20 @@
  * 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.
  */
 
 
 #ifndef VARRAY_H
 #define VARRAY_H
 
-
-#include "mtypes.h"
 #include "bufferobj.h"
 
 
 /**
  * Returns a pointer to the vertex attribute data in a client array,
  * or the offset into the vertex buffer for an array that resides in
  * a vertex buffer.
  */
 static inline const GLubyte *
 _mesa_vertex_attrib_address(const struct gl_array_attributes *array,
diff --git a/src/mesa/main/version.h b/src/mesa/main/version.h
index adfec6f8282..4469509c08e 100644
--- a/src/mesa/main/version.h
+++ b/src/mesa/main/version.h
@@ -20,22 +20,27 @@
  * 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.
  */
 
 
 #ifndef VERSION_H
 #define VERSION_H
 
-#include "mtypes.h"
+#include <stdbool.h>
+#include "glheader.h"
+#include "menums.h"
 
+struct gl_context;
+struct gl_constants;
+struct gl_extensions;
 
 extern GLuint
 _mesa_get_version(const struct gl_extensions *extensions,
                   struct gl_constants *consts, gl_api api);
 
 extern void
 _mesa_compute_version(struct gl_context *ctx);
 
 extern bool
 _mesa_override_gl_version_contextless(struct gl_constants *consts,
diff --git a/src/mesa/main/vtxfmt.h b/src/mesa/main/vtxfmt.h
index 4f8bc9cdf06..20fc4667019 100644
--- a/src/mesa/main/vtxfmt.h
+++ b/src/mesa/main/vtxfmt.h
@@ -26,25 +26,27 @@
  * 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.
  */
 
 
 #ifndef _VTXFMT_H_
 #define _VTXFMT_H_
 
-#include "mtypes.h"
+#include "dd.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+
 extern void _mesa_install_exec_vtxfmt( struct gl_context *ctx, const GLvertexformat *vfmt );
 extern void _mesa_install_save_vtxfmt( struct gl_context *ctx, const GLvertexformat *vfmt );
 extern void _mesa_initialize_vbo_vtxfmt(struct gl_context *ctx);
 
 #ifdef __cplusplus
 } // extern "C"
 #endif
 
 #endif /* _VTXFMT_H_ */
diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c
index 493d0e5cb27..57a49533de2 100644
--- a/src/mesa/math/m_matrix.c
+++ b/src/mesa/math/m_matrix.c
@@ -28,20 +28,21 @@
  * Matrix operations.
  *
  * \note
  * -# 4x4 transformation matrices are stored in memory in column major order.
  * -# Points/vertices are to be thought of as column vectors.
  * -# Transformation of a point p by a matrix M is: p' = M * p
  */
 
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/macros.h"
 
 #include "m_matrix.h"
 
 
 /**
  * \defgroup MatFlags MAT_FLAG_XXX-flags
  *
diff --git a/src/mesa/meson.build b/src/mesa/meson.build
index d2d058bfa3c..7bfd19690a9 100644
--- a/src/mesa/meson.build
+++ b/src/mesa/meson.build
@@ -99,21 +99,20 @@ files_libmesa_common = files(
   'main/compiler.h',
   'main/condrender.c',
   'main/condrender.h',
   'main/config.h',
   'main/context.c',
   'main/context.h',
   'main/convolve.c',
   'main/convolve.h',
   'main/copyimage.c',
   'main/copyimage.h',
-  'main/core.h',
   'main/cpuinfo.c',
   'main/cpuinfo.h',
   'main/dd.h',
   'main/debug.c',
   'main/debug.h',
   'main/debug_output.c',
   'main/debug_output.h',
   'main/depth.c',
   'main/depth.h',
   'main/dlist.c',
@@ -183,20 +182,21 @@ files_libmesa_common = files(
   'main/lines.h',
   'main/macros.h',
   'main/marshal.c',
   'main/marshal.h',
   'main/matrix.c',
   'main/matrix.h',
   'main/mipmap.c',
   'main/mipmap.h',
   'main/mm.c',
   'main/mm.h',
+  'main/menums.h',
   'main/mtypes.h',
   'main/multisample.c',
   'main/multisample.h',
   'main/objectlabel.c',
   'main/objectlabel.h',
   'main/objectpurge.c',
   'main/objectpurge.h',
   'main/pack.c',
   'main/pack.h',
   'main/pbo.c',
diff --git a/src/mesa/program/ir_to_mesa.h b/src/mesa/program/ir_to_mesa.h
index 9714f50443a..7a4911cd74a 100644
--- a/src/mesa/program/ir_to_mesa.h
+++ b/src/mesa/program/ir_to_mesa.h
@@ -26,20 +26,22 @@
 
 #include "main/glheader.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct gl_context;
 struct gl_shader;
 struct gl_shader_program;
+struct gl_linked_shader;
+struct gl_program_parameter_list;
 
 void _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
 GLboolean _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
 
 void
 _mesa_generate_parameters_list_for_uniforms(struct gl_context *ctx,
                                             struct gl_shader_program
 					    *shader_program,
 					    struct gl_linked_shader *sh,
 					    struct gl_program_parameter_list
diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c
index b5a7a692aeb..c50465dfc49 100644
--- a/src/mesa/program/prog_execute.c
+++ b/src/mesa/program/prog_execute.c
@@ -29,22 +29,24 @@
  */
 
 /*
  * NOTE: we do everything in single-precision floating point; we don't
  * currently observe the single/half/fixed-precision qualifiers.
  *
  */
 
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
+#include "main/mtypes.h"
 #include "prog_execute.h"
 #include "prog_instruction.h"
 #include "prog_parameter.h"
 #include "prog_print.h"
 #include "prog_noise.h"
 
 
 /* debug predicate */
 #define DEBUG_PROG 0
 
diff --git a/src/mesa/program/prog_execute.h b/src/mesa/program/prog_execute.h
index 3603e3bdddf..ef04087301e 100644
--- a/src/mesa/program/prog_execute.h
+++ b/src/mesa/program/prog_execute.h
@@ -19,22 +19,24 @@
  * 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.
  */
 
 #ifndef PROG_EXECUTE_H
 #define PROG_EXECUTE_H
 
 #include "main/config.h"
-#include "main/mtypes.h"
+#include "main/glheader.h"
+#include "compiler/shader_enums.h"
 
+struct gl_context;
 
 typedef void (*FetchTexelLodFunc)(struct gl_context *ctx, const GLfloat texcoord[4],
                                   GLfloat lambda, GLuint unit, GLfloat color[4]);
 
 typedef void (*FetchTexelDerivFunc)(struct gl_context *ctx, const GLfloat texcoord[4],
                                     const GLfloat texdx[4],
                                     const GLfloat texdy[4],
                                     GLfloat lodBias,
                                     GLuint unit, GLfloat color[4]);
 
diff --git a/src/mesa/program/prog_instruction.c b/src/mesa/program/prog_instruction.c
index 9f03867f0b0..91830d87f25 100644
--- a/src/mesa/program/prog_instruction.c
+++ b/src/mesa/program/prog_instruction.c
@@ -19,22 +19,22 @@
  * 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.
  */
 
 
 #include "main/glheader.h"
 #include "main/imports.h"
-#include "main/mtypes.h"
 #include "prog_instruction.h"
+#include "prog_parameter.h"
 
 
 /**
  * Initialize program instruction fields to defaults.
  * \param inst  first instruction to initialize
  * \param count  number of instructions to initialize
  */
 void
 _mesa_init_instructions(struct prog_instruction *inst, GLuint count)
 {
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index 8e36a1c5904..cc551c18910 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -24,29 +24,60 @@
 
 /**
  * \file prog_parameter.c
  * Program parameter lists and functions.
  * \author Brian Paul
  */
 
 #ifndef PROG_PARAMETER_H
 #define PROG_PARAMETER_H
 
-#include "main/mtypes.h"
 #include "prog_statevars.h"
 
 #include <string.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/**
+ * Names of the various vertex/fragment program register files, etc.
+ *
+ * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
+ * All values should fit in a 4-bit field.
+ *
+ * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
+ * considered to be "uniform" variables since they can only be set outside
+ * glBegin/End.  They're also all stored in the same Parameters array.
+ */
+typedef enum
+{
+   PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
+   PROGRAM_ARRAY,       /**< Arrays & Matrixes */
+   PROGRAM_INPUT,       /**< machine->Inputs[] */
+   PROGRAM_OUTPUT,      /**< machine->Outputs[] */
+   PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
+   PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
+   PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
+   PROGRAM_WRITE_ONLY,  /**< A dummy, write-only register */
+   PROGRAM_ADDRESS,     /**< machine->AddressReg */
+   PROGRAM_SAMPLER,     /**< for shader samplers, compile-time only */
+   PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
+   PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
+   PROGRAM_IMMEDIATE,   /**< Immediate value, used by TGSI */
+   PROGRAM_BUFFER,      /**< for shader buffers, compile-time only */
+   PROGRAM_MEMORY,      /**< for shared, global and local memory */
+   PROGRAM_IMAGE,       /**< for shader images, compile-time only */
+   PROGRAM_HW_ATOMIC,   /**< for hw atomic counters, compile-time only */
+   PROGRAM_FILE_MAX
+} gl_register_file;
+
 
 /**
  * Actual data for constant values of parameters.
  */
 typedef union gl_constant_value
 {
    GLfloat f;
    GLint b;
    GLint i;
    GLuint u;
diff --git a/src/mesa/program/prog_print.h b/src/mesa/program/prog_print.h
index 98a43e63a00..89fc42363cd 100644
--- a/src/mesa/program/prog_print.h
+++ b/src/mesa/program/prog_print.h
@@ -22,21 +22,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #ifndef PROG_PRINT_H
 #define PROG_PRINT_H
 
 #include <stdio.h>
 
 #include "main/glheader.h"
-#include "main/mtypes.h"
+#include "prog_parameter.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 
 struct gl_program;
 struct gl_program_parameter_list;
 struct gl_shader;
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index 3ee44ce489e..cd874e489f3 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -20,20 +20,21 @@
  * 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.
  */
 
 #include "compiler/nir/nir.h"
 #include "compiler/nir/nir_builder.h"
 #include "compiler/glsl/list.h"
 #include "main/imports.h"
+#include "main/mtypes.h"
 #include "util/ralloc.h"
 
 #include "prog_to_nir.h"
 #include "prog_instruction.h"
 #include "prog_parameter.h"
 #include "prog_print.h"
 #include "program.h"
 
 /**
  * \file prog_to_nir.c
diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h
index 659385f55b1..49e888e57df 100644
--- a/src/mesa/program/program.h
+++ b/src/mesa/program/program.h
@@ -33,21 +33,21 @@
  * \mainpage Mesa vertex and fragment program module
  *
  * This module or directory contains most of the code for vertex and
  * fragment programs and shaders, including state management, parsers,
  * and (some) software routines for executing programs
  */
 
 #ifndef PROGRAM_H
 #define PROGRAM_H
 
-#include "main/mtypes.h"
+#include "prog_parameter.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 extern struct gl_program _mesa_DummyProgram;
 
 
 extern void
diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y
index 9b63764f752..415ff2a28ec 100644
--- a/src/mesa/program/program_parse.y
+++ b/src/mesa/program/program_parse.y
@@ -20,20 +20,21 @@
  * 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.
  */
 
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "main/errors.h"
 #include "main/mtypes.h"
 #include "main/imports.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
 #include "program/prog_parameter_layout.h"
 #include "program/prog_statevars.h"
 #include "program/prog_instruction.h"
 
 #include "program/symbol_table.h"
 #include "program/program_parser.h"
diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h
index 5d70e57bc33..70a820ae0ea 100644
--- a/src/mesa/program/programopt.h
+++ b/src/mesa/program/programopt.h
@@ -19,27 +19,30 @@
  * 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.
  */
 
 
 #ifndef PROGRAMOPT_H
 #define PROGRAMOPT_H 1
 
-#include "main/mtypes.h"
+#include "main/glheader.h"
+#include "prog_parameter.h"
 
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct gl_context;
+struct gl_program;
 
 extern void
 _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_program *vprog);
 
 extern void
 _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog,
                       GLenum fog_mode, GLboolean saturate);
 
 extern void
 _mesa_count_texture_indirections(struct gl_program *prog);
diff --git a/src/mesa/program/symbol_table.c b/src/mesa/program/symbol_table.c
index f5dacbbf1ed..e01faa5c6e1 100644
--- a/src/mesa/program/symbol_table.c
+++ b/src/mesa/program/symbol_table.c
@@ -15,20 +15,21 @@
  * 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.
  */
 
 #include "main/imports.h"
+#include "main/errors.h"
 #include "symbol_table.h"
 #include "../../util/hash_table.h"
 #include "util/u_string.h"
 
 struct symbol {
    /** Symbol name. */
    char *name;
 
     /**
      * Link to the next symbol in the table with the same name
diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c
index 3b2beaf6ed7..6ddb8f525cf 100644
--- a/src/mesa/state_tracker/st_atom_depth.c
+++ b/src/mesa/state_tracker/st_atom_depth.c
@@ -34,21 +34,20 @@
  
 
 #include <assert.h>
 
 #include "st_context.h"
 #include "st_atom.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "cso_cache/cso_context.h"
 
-#include "main/core.h"
 #include "main/stencil.h"
 
 
 /**
  * Convert an OpenGL compare mode to a pipe tokens.
  */
 GLuint
 st_compare_func_to_pipe(GLenum func)
 {
    /* Same values, just biased */
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index c41ed2ba02b..b25ae5f80eb 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -23,20 +23,21 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
  **************************************************************************/
 
  /*
   * Authors:
   *   Brian Paul
   */
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/bufferobj.h"
 #include "main/dlist.h"
 #include "main/macros.h"
 #include "main/pbo.h"
 #include "program/program.h"
 #include "program/prog_print.h"
 
 #include "st_context.h"
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 044916b4dc8..5ebe94f4545 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -26,20 +26,21 @@
  **************************************************************************/
 
 
 /**
  * Functions for pixel buffer objects and vertex/element buffer objects.
  */
 
 
 #include <inttypes.h>  /* for PRId64 macro */
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "main/arrayobj.h"
 #include "main/bufferobj.h"
 
 #include "st_context.h"
 #include "st_cb_bufferobjects.h"
 #include "st_cb_memoryobjects.h"
 #include "st_debug.h"
 
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 68677182abf..fbc577a370c 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -26,20 +26,21 @@
  * 
  **************************************************************************/
 
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   *   Brian Paul
   *   Michel Dänzer
   */
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/accum.h"
 #include "main/formats.h"
 #include "main/framebuffer.h"
 #include "main/macros.h"
 #include "main/glformats.h"
 #include "program/prog_instruction.h"
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_cb_bitmap.h"
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 471eb196614..bb73644753a 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -23,20 +23,21 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
  **************************************************************************/
 
  /*
   * Authors:
   *   Brian Paul
   */
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/bufferobj.h"
 #include "main/blit.h"
 #include "main/format_pack.h"
 #include "main/framebuffer.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/pack.h"
 #include "main/pbo.h"
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 628e4af1e67..8cc8e08a623 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -21,20 +21,21 @@
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  * 
  **************************************************************************/
 
 #include <stdio.h>
 #include "main/bufferobj.h"
 #include "main/enums.h"
+#include "main/errors.h"
 #include "main/fbobject.h"
 #include "main/formats.h"
 #include "main/format_utils.h"
 #include "main/glformats.h"
 #include "main/image.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/mipmap.h"
 #include "main/pack.h"
 #include "main/pbo.h"
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 8011d0f25ca..6243659b50d 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -29,20 +29,21 @@
  * This file implements the st_draw_vbo() function which is called from
  * Mesa's VBO module.  All point/line/triangle rendering is done through
  * this function whether the user called glBegin/End, glDrawArrays,
  * glDrawElements, glEvalMesh, or glCalList, etc.
  *
  * Authors:
  *   Keith Whitwell <keithw at vmware.com>
  */
 
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/bufferobj.h"
 #include "main/macros.h"
 #include "main/varray.h"
 
 #include "compiler/glsl/ir_uniform.h"
 
 #include "vbo/vbo.h"
 
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index f2aa8005a03..3f105871a5e 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -19,20 +19,21 @@
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
  * 
  **************************************************************************/
 
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/mipmap.h"
 #include "main/teximage.h"
 
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_gen_mipmap.h"
 
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_private.h b/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
index 19dde16ed91..c482828eddb 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_private.h
@@ -19,24 +19,25 @@
  * 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.
  */
 
 #ifndef ST_GLSL_TO_TGSI_PRIVATE_H
 #define ST_GLSL_TO_TGSI_PRIVATE_H
 
-#include <mesa/main/mtypes.h>
-#include <compiler/glsl_types.h>
-#include <compiler/glsl/ir.h>
-#include <tgsi/tgsi_info.h>
+#include "mesa/main/mtypes.h"
+#include "program/prog_parameter.h"
+#include "compiler/glsl_types.h"
+#include "compiler/glsl/ir.h"
+#include "tgsi/tgsi_info.h"
 #include <ostream>
 
 int swizzle_for_size(int size);
 
 class st_dst_reg;
 /**
  * This struct is a corresponding struct to TGSI ureg_src.
  */
 class st_src_reg {
 public:
diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h
index 1a1ea79af8e..162dcc2ca57 100644
--- a/src/mesa/state_tracker/st_manager.h
+++ b/src/mesa/state_tracker/st_manager.h
@@ -21,21 +21,21 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Chia-I Wu <olv at lunarg.com>
  */
 
 #ifndef ST_MANAGER_H
 #define ST_MANAGER_H
 
-#include "main/mtypes.h"
+#include "main/menums.h"
 
 #include "pipe/p_compiler.h"
 
 struct st_context;
 struct st_framebuffer;
 struct st_framebuffer_interface;
 
 void
 st_manager_flush_frontbuffer(struct st_context *st);
 
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 3f8df31da18..fe72ddaf2c0 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -24,20 +24,21 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
  **************************************************************************/
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   *   Brian Paul
   */
 
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/hash.h"
 #include "main/mtypes.h"
 #include "program/prog_parameter.h"
 #include "program/prog_print.h"
 #include "program/programopt.h"
 
 #include "compiler/nir/nir.h"
 
 #include "pipe/p_context.h"
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 0c12a63ae0b..9480d9ec7a5 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -18,20 +18,21 @@
  * 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.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com> Brian Paul
  */
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/bufferobj.h"
 #include "main/mtypes.h"
 #include "main/samplerobj.h"
 #include "main/state.h"
 #include "main/stencil.h"
 #include "main/teximage.h"
 #include "program/prog_parameter.h"
 #include "program/prog_statevars.h"
 #include "swrast.h"
diff --git a/src/mesa/swrast/s_fog.c b/src/mesa/swrast/s_fog.c
index 8b0bdf8fa28..33da09b618d 100644
--- a/src/mesa/swrast/s_fog.c
+++ b/src/mesa/swrast/s_fog.c
@@ -17,20 +17,21 @@
  * 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.
  */
 
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 
 #include "s_context.h"
 #include "s_fog.h"
 
 
 /**
  * Used to convert current raster distance to a fog factor in [0,1].
  */
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 9bc1f227fe1..87b72e81970 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -25,20 +25,21 @@
 
 
 /**
  * \file swrast/s_span.c
  * \brief Span processing functions used by all rasterization functions.
  * This is where all the per-fragment tests are performed
  * \author Brian Paul
  */
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/format_pack.h"
 #include "main/format_unpack.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/samplerobj.h"
 #include "main/state.h"
 #include "main/stencil.h"
 #include "main/teximage.h"
diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c
index 294b593a20f..7a4dc45ae86 100644
--- a/src/mesa/swrast/s_stencil.c
+++ b/src/mesa/swrast/s_stencil.c
@@ -21,21 +21,20 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/imports.h"
 #include "main/format_pack.h"
 #include "main/format_unpack.h"
-#include "main/core.h"
 #include "main/stencil.h"
 
 #include "s_context.h"
 #include "s_depth.h"
 #include "s_stencil.h"
 #include "s_span.h"
 
 
 
 /* Stencil Logic:
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index e2c3c085b57..fec8728a7a1 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -26,20 +26,21 @@
 
 /**
  * \file s_texfetch.c
  *
  * Texel fetch/store functions
  *
  * \author Gareth Hughes
  */
 
 
+#include "main/errors.h"
 #include "main/macros.h"
 #include "main/texcompress.h"
 #include "main/texcompress_fxt1.h"
 #include "main/texcompress_s3tc.h"
 #include "main/texcompress_rgtc.h"
 #include "main/texcompress_etc.h"
 #include "main/teximage.h"
 #include "main/samplerobj.h"
 #include "s_context.h"
 #include "s_texfetch.h"
diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c
index 34b8eb19657..2472aa730f9 100644
--- a/src/mesa/swrast/s_zoom.c
+++ b/src/mesa/swrast/s_zoom.c
@@ -15,20 +15,21 @@
  *
  * 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.
  */
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/format_pack.h"
 
 #include "s_context.h"
 #include "s_span.h"
 #include "s_stencil.h"
 #include "s_zoom.h"
 
diff --git a/src/mesa/tnl/t_rebase.c b/src/mesa/tnl/t_rebase.c
index d28512423c3..09a8a3da720 100644
--- a/src/mesa/tnl/t_rebase.c
+++ b/src/mesa/tnl/t_rebase.c
@@ -41,20 +41,21 @@
  * incorrect as we tend to upload each set of vertex data to a new
  * region.  
  *
  * This file provides a helper to adjust the arrays, primitives and
  * indices of a draw call so that it can be re-issued with a min_index
  * of zero.
  */
 
 #include <stdio.h>
 #include "main/bufferobj.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "vbo/vbo.h"
 
 #include "t_rebase.h"
 
 
 #define REBASE(TYPE) 						\
 static void *rebase_##TYPE( const void *ptr,			\
diff --git a/src/mesa/tnl/t_vb_fog.c b/src/mesa/tnl/t_vb_fog.c
index 5489ed6857f..c224a4192a4 100644
--- a/src/mesa/tnl/t_vb_fog.c
+++ b/src/mesa/tnl/t_vb_fog.c
@@ -20,20 +20,21 @@
  * 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.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 
 #include "c99_math.h"
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 
 #include "math/m_xform.h"
 
 #include "t_context.h"
 #include "t_pipeline.h"
 
diff --git a/src/mesa/tnl/t_vb_texgen.c b/src/mesa/tnl/t_vb_texgen.c
index a13262d1db2..bd585324e2b 100644
--- a/src/mesa/tnl/t_vb_texgen.c
+++ b/src/mesa/tnl/t_vb_texgen.c
@@ -27,20 +27,21 @@
 
 /*
  * Regarding GL_NV_texgen_reflection:
  *
  * Portions of this software may use or implement intellectual
  * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
  * any and all warranties with respect to such intellectual property,
  * including any use thereof or modifications thereto.
  */
 
+#include "main/errors.h"
 #include "main/glheader.h"
 #include "main/macros.h"
 #include "main/imports.h"
 #include "main/mtypes.h"
 
 #include "math/m_xform.h"
 
 #include "t_context.h"
 #include "t_pipeline.h"
 
diff --git a/src/mesa/tnl/tnl.h b/src/mesa/tnl/tnl.h
index 45052a3a89c..e506aee6dfb 100644
--- a/src/mesa/tnl/tnl.h
+++ b/src/mesa/tnl/tnl.h
@@ -26,20 +26,23 @@
  */
 
 #ifndef _TNL_H
 #define _TNL_H
 
 #include "main/glheader.h"
 
 struct gl_vertex_array;
 struct gl_context;
 struct gl_program;
+struct gl_buffer_object;
+struct gl_transform_feedback_object;
+struct dd_function_table;
 
 
 /* These are the public-access functions exported from tnl.  (A few
  * more are currently hooked into dispatch directly by the module
  * itself.)
  */
 extern GLboolean
 _tnl_CreateContext( struct gl_context *ctx );
 
 extern void
diff --git a/src/mesa/vbo/vbo_attrib.h b/src/mesa/vbo/vbo_attrib.h
index 0592d845ba4..165734b30a6 100644
--- a/src/mesa/vbo/vbo_attrib.h
+++ b/src/mesa/vbo/vbo_attrib.h
@@ -25,22 +25,20 @@
  
  **********************************************************************/
  /*
   * Authors:
   *   Keith Whitwell <keithw at vmware.com>
   */
 
 #ifndef VBO_ATTRIB_H
 #define VBO_ATTRIB_H
 
-#include "main/mtypes.h"
-
 /*
  * Note: The first 32 attributes match the VERT_ATTRIB_* definitions.
  * However, we have extra attributes for storing per-vertex glMaterial
  * values.  The material attributes get shifted into the generic positions
  * at draw time.
  *
  * One reason we can't alias materials and generics here is display lists.
  * A display list might contain both generic attributes and material
  * attributes which are selected at draw time depending on whether we're
  * using fixed function or a shader.  <sigh>
diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c
index f698fd0f416..ada78ffd63b 100644
--- a/src/mesa/vbo/vbo_context.c
+++ b/src/mesa/vbo/vbo_context.c
@@ -19,21 +19,21 @@
  * 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.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 #include "c99_alloca.h"
-#include "main/mtypes.h"
+#include "main/errors.h"
 #include "main/bufferobj.h"
 #include "math/m_eval.h"
 #include "main/vtxfmt.h"
 #include "main/api_arrayelt.h"
 #include "main/arrayobj.h"
 #include "main/varray.h"
 #include "vbo.h"
 #include "vbo_private.h"
 
 
diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c
index b23747aa393..357ec1da767 100644
--- a/src/mesa/vbo/vbo_exec.c
+++ b/src/mesa/vbo/vbo_exec.c
@@ -21,21 +21,20 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 
 #include "main/glheader.h"
 #include "main/arrayobj.h"
-#include "main/mtypes.h"
 #include "main/api_arrayelt.h"
 #include "main/vtxfmt.h"
 #include "vbo_private.h"
 
 const GLubyte
 _vbo_attribute_alias_map[VP_MODE_MAX][VERT_ATTRIB_MAX] = {
    /* VP_MODE_FF: */
    {
       VBO_ATTRIB_POS,                 /* VERT_ATTRIB_POS */
       VBO_ATTRIB_NORMAL,              /* VERT_ATTRIB_NORMAL */
diff --git a/src/mesa/vbo/vbo_exec.h b/src/mesa/vbo/vbo_exec.h
index 853fc68c963..1170883f871 100644
--- a/src/mesa/vbo/vbo_exec.h
+++ b/src/mesa/vbo/vbo_exec.h
@@ -27,22 +27,21 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /*
  * Authors:
  *   Keith Whitwell <keithw at vmware.com>
  *
  */
 
 #ifndef VBO_EXEC_H
 #define VBO_EXEC_H
 
-
-#include "main/mtypes.h"
+#include "main/dd.h"
 #include "main/imports.h"
 #include "vbo.h"
 #include "vbo_attrib.h"
 
 
 /**
  * Max number of primitives (number of glBegin/End pairs) per VBO.
  */
 #define VBO_MAX_PRIM 64
 
diff --git a/src/mesa/vbo/vbo_noop.h b/src/mesa/vbo/vbo_noop.h
index 8aa17ce9ede..0ca1bfa8e1b 100644
--- a/src/mesa/vbo/vbo_noop.h
+++ b/src/mesa/vbo/vbo_noop.h
@@ -19,22 +19,22 @@
  * 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.
  */
 
 #ifndef VBO_NOOP_H
 #define VBO_NOOP_H
 
+#include "main/dd.h"
 
-#include "main/mtypes.h"
-
+struct _glapi_table;
 
 extern void
 _mesa_noop_vtxfmt_init(GLvertexformat *vfmt);
 
 extern GLboolean
 _mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch);
 
 
 #endif /* VBO_NOOP_H */
diff --git a/src/mesa/vbo/vbo_primitive_restart.c b/src/mesa/vbo/vbo_primitive_restart.c
index f170347fbe4..a3c65f422ba 100644
--- a/src/mesa/vbo/vbo_primitive_restart.c
+++ b/src/mesa/vbo/vbo_primitive_restart.c
@@ -21,20 +21,21 @@
  * 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.
  *
  * Authors:
  *    Jordan Justen <jordan.l.justen at intel.com>
  *
  */
 
+#include "main/errors.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/varray.h"
 
 #include "vbo.h"
 
 
 #define UPDATE_MIN2(a, b) (a) = MIN2((a), (b))
 #define UPDATE_MAX2(a, b) (a) = MAX2((a), (b))
 
diff --git a/src/mesa/vbo/vbo_private.h b/src/mesa/vbo/vbo_private.h
index 7cc64ecdbcf..589c61d675e 100644
--- a/src/mesa/vbo/vbo_private.h
+++ b/src/mesa/vbo/vbo_private.h
@@ -28,21 +28,20 @@
  */
 
 
 #ifndef VBO_PRIVATE_H
 #define VBO_PRIVATE_H
 
 
 #include "vbo/vbo_attrib.h"
 #include "vbo/vbo_exec.h"
 #include "vbo/vbo_save.h"
-#include "main/mtypes.h"
 #include "main/varray.h"
 
 
 struct _glapi_table;
 struct _mesa_prim;
 
 
 struct vbo_context {
    struct gl_vertex_buffer_binding binding;
    struct gl_array_attributes current[VBO_ATTRIB_MAX];
diff --git a/src/mesa/vbo/vbo_save.c b/src/mesa/vbo/vbo_save.c
index 361964195c3..73bc49a24bf 100644
--- a/src/mesa/vbo/vbo_save.c
+++ b/src/mesa/vbo/vbo_save.c
@@ -19,21 +19,20 @@
  * 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.
  *
  * Authors:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 
-#include "main/mtypes.h"
 #include "main/arrayobj.h"
 #include "main/bufferobj.h"
 
 #include "vbo_private.h"
 
 
 /**
  * Called at context creation time.
  */
 void vbo_save_init( struct gl_context *ctx )
diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h
index b158c077957..2a1922461dd 100644
--- a/src/mesa/vbo/vbo_save.h
+++ b/src/mesa/vbo/vbo_save.h
@@ -27,21 +27,20 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /*
  * Authors:
  *   Keith Whitwell <keithw at vmware.com>
  *
  */
 
 #ifndef VBO_SAVE_H
 #define VBO_SAVE_H
 
-#include "main/mtypes.h"
 #include "vbo.h"
 #include "vbo_attrib.h"
 
 
 struct vbo_save_copied_vtx {
    fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
    GLuint nr;
 };
 
 
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index 096e43c8169..f4b2c807480 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -25,21 +25,20 @@
 /* Author:
  *    Keith Whitwell <keithw at vmware.com>
  */
 
 #include <stdbool.h>
 #include "main/arrayobj.h"
 #include "main/glheader.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "main/imports.h"
-#include "main/mtypes.h"
 #include "main/macros.h"
 #include "main/light.h"
 #include "main/state.h"
 #include "main/varray.h"
 #include "util/bitscan.h"
 
 #include "vbo_private.h"
 
 
 static void
diff --git a/src/mesa/vbo/vbo_save_loopback.c b/src/mesa/vbo/vbo_save_loopback.c
index f1a93d6e434..36b1f71eb5f 100644
--- a/src/mesa/vbo/vbo_save_loopback.c
+++ b/src/mesa/vbo/vbo_save_loopback.c
@@ -23,21 +23,20 @@
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  **************************************************************************/
 
 #include <stdio.h>
 #include "main/context.h"
 #include "main/glheader.h"
 #include "main/enums.h"
 #include "main/imports.h"
-#include "main/mtypes.h"
 #include "main/dispatch.h"
 #include "glapi/glapi.h"
 
 #include "vbo_private.h"
 
 
 typedef void (*attr_func)(struct gl_context *ctx, GLint index, const GLfloat *);
 
 
 /* This file makes heavy use of the aliasing of NV vertex attributes
diff --git a/src/util/register_allocate.c b/src/util/register_allocate.c
index de8978bb93e..500540bfdd9 100644
--- a/src/util/register_allocate.c
+++ b/src/util/register_allocate.c
@@ -68,21 +68,20 @@
  * up front and stored in a 2-dimensional array, so that the cost of
  * coloring a node is constant with the number of registers.  We do
  * this during ra_set_finalize().
  */
 
 #include <stdbool.h>
 
 #include "ralloc.h"
 #include "main/imports.h"
 #include "main/macros.h"
-#include "main/mtypes.h"
 #include "util/bitset.h"
 #include "register_allocate.h"
 
 #define NO_REG ~0U
 
 struct ra_reg {
    BITSET_WORD *conflicts;
    unsigned int *conflict_list;
    unsigned int conflict_list_size;
    unsigned int num_conflicts;
diff --git a/src/util/xmlconfig.h b/src/util/xmlconfig.h
index 77aa14c20e0..f7683a650e0 100644
--- a/src/util/xmlconfig.h
+++ b/src/util/xmlconfig.h
@@ -25,20 +25,21 @@
  * \file xmlconfig.h
  * \brief Driver-independent client-side part of the XML configuration
  * \author Felix Kuehling
  */
 
 #ifndef __XMLCONFIG_H
 #define __XMLCONFIG_H
 
 #include "util/mesa-sha1.h"
 #include "util/ralloc.h"
+#include <string.h>
 
 #define STRING_CONF_MAXLEN 25
 
 /** \brief Option data types */
 typedef enum driOptionType {
     DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT, DRI_STRING
 } driOptionType;
 
 /** \brief Option value */
 typedef union driOptionValue {
-- 
2.15.1



More information about the mesa-dev mailing list