extern "C" {
#include <talloc.h>
-#include "main/mtypes.h"
+#include "main/core.h" /* for struct __GLcontextRec */
}
#include "ast.h"
#include "glsl_parser_extras.h"
#include "glsl_parser.h"
#include "ir_optimization.h"
+#include "loop_analysis.h"
_mesa_glsl_parse_state::_mesa_glsl_parse_state(struct __GLcontextRec *ctx,
GLenum target, void *mem_ctx)
this->info_log = talloc_strdup(mem_ctx, "");
this->error = false;
this->loop_or_switch_nesting = NULL;
- this->ARB_texture_rectangle_enable = true;
-
- if (ctx != NULL) {
- this->extensions = &ctx->Extensions;
-
- this->Const.MaxLights = ctx->Const.MaxLights;
- this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
- this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
- this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
- this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
- this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
- this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
- this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
- this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
- this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
- this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
-
- this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
- } else {
- /* If there is no GL context (standalone compiler), fill in constants
- * with the minimum required values.
- */
- static struct gl_extensions null_extensions;
- memset(&null_extensions, 0, sizeof(null_extensions));
- null_extensions.ARB_draw_buffers = GL_TRUE;
- null_extensions.ARB_fragment_coord_conventions = GL_TRUE;
- null_extensions.EXT_texture_array = GL_TRUE;
- null_extensions.NV_texture_rectangle = GL_TRUE;
-
- this->extensions = &null_extensions;
+ /* Set default language version and extensions */
+ this->language_version = 110;
+ this->es_shader = false;
+ this->ARB_texture_rectangle_enable = true;
- /* 1.10 minimums. */
- this->Const.MaxLights = 8;
- this->Const.MaxClipPlanes = 8;
- this->Const.MaxTextureUnits = 2;
+ /* OpenGL ES 2.0 has different defaults from desktop GL. */
+ if (ctx->API == API_OPENGLES2) {
+ this->language_version = 100;
+ this->es_shader = true;
+ this->ARB_texture_rectangle_enable = false;
+ }
- /* More than the 1.10 minimum to appease parser tests taken from
- * apps that (hopefully) already checked the number of coords.
- */
- this->Const.MaxTextureCoords = 4;
+ this->extensions = &ctx->Extensions;
- this->Const.MaxVertexAttribs = 16;
- this->Const.MaxVertexUniformComponents = 512;
- this->Const.MaxVaryingFloats = 32;
- this->Const.MaxVertexTextureImageUnits = 0;
- this->Const.MaxCombinedTextureImageUnits = 2;
- this->Const.MaxTextureImageUnits = 2;
- this->Const.MaxFragmentUniformComponents = 64;
+ this->Const.MaxLights = ctx->Const.MaxLights;
+ this->Const.MaxClipPlanes = ctx->Const.MaxClipPlanes;
+ this->Const.MaxTextureUnits = ctx->Const.MaxTextureUnits;
+ this->Const.MaxTextureCoords = ctx->Const.MaxTextureCoordUnits;
+ this->Const.MaxVertexAttribs = ctx->Const.VertexProgram.MaxAttribs;
+ this->Const.MaxVertexUniformComponents = ctx->Const.VertexProgram.MaxUniformComponents;
+ this->Const.MaxVaryingFloats = ctx->Const.MaxVarying * 4;
+ this->Const.MaxVertexTextureImageUnits = ctx->Const.MaxVertexTextureImageUnits;
+ this->Const.MaxCombinedTextureImageUnits = ctx->Const.MaxCombinedTextureImageUnits;
+ this->Const.MaxTextureImageUnits = ctx->Const.MaxTextureImageUnits;
+ this->Const.MaxFragmentUniformComponents = ctx->Const.FragmentProgram.MaxUniformComponents;
- this->Const.MaxDrawBuffers = 2;
- }
+ this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
}
const char *
}
bool
-do_common_optimization(exec_list *ir, bool linked)
+do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iterations)
{
GLboolean progress = GL_FALSE;
progress = do_swizzle_swizzle(ir) || progress;
progress = do_noop_swizzle(ir) || progress;
+ loop_state *ls = analyze_loop_variables(ir);
+ progress = set_loop_controls(ir, ls) || progress;
+ progress = unroll_loops(ir, ls, max_unroll_iterations) || progress;
+ delete ls;
+
return progress;
}
+
+extern "C" {
+
+/**
+ * To be called at GL teardown time, this frees compiler datastructures.
+ *
+ * After calling this, any previously compiled shaders and shader
+ * programs would be invalid. So this should happen at approximately
+ * program exit.
+ */
+void
+_mesa_destroy_shader_compiler(void)
+{
+ _mesa_destroy_shader_compiler_caches();
+
+ _mesa_glsl_release_types();
+}
+
+/**
+ * Releases compiler caches to trade off performance for memory.
+ *
+ * Intended to be used with glReleaseShaderCompiler().
+ */
+void
+_mesa_destroy_shader_compiler_caches(void)
+{
+ _mesa_glsl_release_functions();
+}
+
+}