[Mesa-dev] [PATCH] glsl: Support GLSL ES in the standalone compiler

Chia-I Wu olvaffe at gmail.com
Wed Sep 8 04:00:09 PDT 2010


Hi Kenneth,

This patch series add GLSL ES support to the standalone compiler.

The first patch makes the standalone compiler to pass a dummy context to
_mesa_glsl_parse_state.  The second patch adds a new option, --glsl-es, to
enable GLSL ES mode.

-- 
olv at LunarG.com
-------------- next part --------------
From b36c0eefd7b1ae96eabf72dc537d69d389abe1d0 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olv at lunarg.com>
Date: Wed, 8 Sep 2010 18:48:12 +0800
Subject: [PATCH 1/2] glsl: Require a context in _mesa_glsl_parse_state.

Create a dummy context in the standalone compiler and pass it to
_mesa_glsl_parse_state.
---
 src/glsl/glsl_parser_extras.cpp |   77 +++++++++++----------------------------
 src/glsl/main.cpp               |   47 +++++++++++++++++++++---
 2 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index d6ad8cb..3dbec5d 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -57,63 +57,28 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct __GLcontextRec *ctx,
    this->es_shader = false;
    this->ARB_texture_rectangle_enable = true;
 
-   if (ctx != NULL) {
-      /* 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;
-      }
-
-      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;
-
-      /* 1.10 minimums. */
-      this->Const.MaxLights = 8;
-      this->Const.MaxClipPlanes = 8;
-      this->Const.MaxTextureUnits = 2;
-
-      /* 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->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.MaxDrawBuffers = 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;
    }
+
+   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;
 }
 
 const char *
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 2323a20..982562c 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -59,6 +59,41 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type)
    return shader;
 }
 
+static void
+initialize_context(GLcontext *ctx, gl_api api)
+{
+   memset(ctx, 0, sizeof(*ctx));
+
+   ctx->API = api;
+
+   ctx->Extensions.ARB_draw_buffers = GL_TRUE;
+   ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
+   ctx->Extensions.EXT_texture_array = GL_TRUE;
+   ctx->Extensions.NV_texture_rectangle = GL_TRUE;
+
+   /* 1.10 minimums. */
+   ctx->Const.MaxLights = 8;
+   ctx->Const.MaxClipPlanes = 8;
+   ctx->Const.MaxTextureUnits = 2;
+
+   /* More than the 1.10 minimum to appease parser tests taken from
+    * apps that (hopefully) already checked the number of coords.
+    */
+   ctx->Const.MaxTextureCoordUnits = 4;
+
+   ctx->Const.VertexProgram.MaxAttribs = 16;
+   ctx->Const.VertexProgram.MaxUniformComponents = 512;
+   ctx->Const.MaxVarying = 8;
+   ctx->Const.MaxVertexTextureImageUnits = 0;
+   ctx->Const.MaxCombinedTextureImageUnits = 2;
+   ctx->Const.MaxTextureImageUnits = 2;
+   ctx->Const.FragmentProgram.MaxUniformComponents = 64;
+
+   ctx->Const.MaxDrawBuffers = 2;
+
+   ctx->Driver.NewShader = _mesa_new_shader;
+}
+
 /* Returned string will have 'ctx' as its talloc owner. */
 static char *
 load_text_file(void *ctx, const char *file_name)
@@ -123,14 +158,14 @@ const struct option compiler_opts[] = {
 };
 
 void
-compile_shader(struct gl_shader *shader)
+compile_shader(GLcontext *ctx, struct gl_shader *shader)
 {
    struct _mesa_glsl_parse_state *state =
-      new(shader) _mesa_glsl_parse_state(NULL, shader->Type, shader);
+      new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);
 
    const char *source = shader->Source;
    state->error = preprocess(state, &source, &state->info_log,
-			     state->extensions, API_OPENGL);
+			     state->extensions, ctx->API);
 
    if (!state->error) {
       _mesa_glsl_lexer_ctor(state, source);
@@ -218,8 +253,6 @@ main(int argc, char **argv)
    GLcontext local_ctx;
    GLcontext *ctx = &local_ctx;
 
-   ctx->Driver.NewShader = _mesa_new_shader;
-
    int c;
    int idx = 0;
    while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
@@ -229,6 +262,8 @@ main(int argc, char **argv)
    if (argc <= optind)
       usage_fail(argv[0]);
 
+   initialize_context(ctx, API_OPENGL);
+
    struct gl_shader_program *whole_program;
 
    whole_program = talloc_zero (NULL, struct gl_shader_program);
@@ -265,7 +300,7 @@ main(int argc, char **argv)
 	 exit(EXIT_FAILURE);
       }
 
-      compile_shader(shader);
+      compile_shader(ctx, shader);
 
       if (!shader->CompileStatus) {
 	 printf("Info log for %s:\n%s\n", argv[optind], shader->InfoLog);
-- 
1.7.1
-------------- next part --------------
From 8bec9e392bb6209536eaf4f4a6e487fbe20a166e Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olv at lunarg.com>
Date: Wed, 8 Sep 2010 18:52:27 +0800
Subject: [PATCH 2/2] glsl: Support GLSL ES in the standalone compile.

GLSL ES mode is enabled when --glsl-es is passed to glsl_compiler.
---
 src/glsl/main.cpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 982562c..2a7a713 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -144,12 +144,14 @@ usage_fail(const char *name)
 }
 
 
+int glsl_es = 0;
 int dump_ast = 0;
 int dump_hir = 0;
 int dump_lir = 0;
 int do_link = 0;
 
 const struct option compiler_opts[] = {
+   { "glsl-es",  0, &glsl_es,  1 },
    { "dump-ast", 0, &dump_ast, 1 },
    { "dump-hir", 0, &dump_hir, 1 },
    { "dump-lir", 0, &dump_lir, 1 },
@@ -262,7 +264,7 @@ main(int argc, char **argv)
    if (argc <= optind)
       usage_fail(argv[0]);
 
-   initialize_context(ctx, API_OPENGL);
+   initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
 
    struct gl_shader_program *whole_program;
 
-- 
1.7.1


More information about the mesa-dev mailing list