[Mesa-dev] [PATCH] mesa: add glsl version query

Brian Paul brianp at vmware.com
Tue Feb 6 17:29:44 UTC 2018


On 02/06/2018 09:32 AM, Vadym Shovkoplias wrote:
> From: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
> 
> Add support for GL_NUM_SHADING_LANGUAGE_VERSIONS
> and glGetStringi for GL_SHADING_LANGUAGE_VERSION
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104915
> Signed-off-by: Andriy Khulap <andriy.khulap at globallogic.com>
> Signed-off-by: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
> ---
>   src/mapi/glapi/gen/GL4x.xml      |  1 +
>   src/mesa/main/get.c              | 31 ++++++++++++++++++++++
>   src/mesa/main/get_hash_params.py |  3 +++
>   src/mesa/main/getstring.c        | 56 ++++++++++++++++++++++++++++++++++++++++
>   4 files changed, 91 insertions(+)
> 
> diff --git a/src/mapi/glapi/gen/GL4x.xml b/src/mapi/glapi/gen/GL4x.xml
> index cd2e3b831e..2116286b35 100644
> --- a/src/mapi/glapi/gen/GL4x.xml
> +++ b/src/mapi/glapi/gen/GL4x.xml
> @@ -42,6 +42,7 @@
>   
>   <category name="4.3">
>     <enum name="SHADER_STORAGE_BARRIER_BIT"                value="0x2000" />
> +  <enum name="NUM_SHADING_LANGUAGE_VERSIONS"             value="0x82E9" />
>     <enum name="MAX_COMBINED_SHADER_OUTPUT_RESOURCES"      value="0x8F39" />
>     <enum name="SHADER_STORAGE_BUFFER"                     value="0x90D2"/>
>     <enum name="SHADER_STORAGE_BUFFER_BINDING"             value="0x90D3"/>
> diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
> index 516e8d174c..958bb62dc6 100644
> --- a/src/mesa/main/get.c
> +++ b/src/mesa/main/get.c
> @@ -1084,6 +1084,37 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
>            v->value_int = 0;
>         }
>         break;
> +   /* GL_NUM_SHADING_LANGUAGE_VERSIONS */

I think that a more useful comment would be /* GL 4.3 */


> +   case GL_NUM_SHADING_LANGUAGE_VERSIONS:
> +      {
> +         int num = 0;
> +         /* GLSL es */
> +         if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
> +            num++;
> +         if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
> +            num++;
> +         if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
> +            num++;
> +         if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
> +              ctx->Extensions.ARB_ES3_2_compatibility)
> +            num++;
> +         /* GLSL core */
> +         if (ctx->Const.GLSLVersion >= 120) num++;
> +         if (ctx->Const.GLSLVersion >= 130) num++;
> +         if (ctx->Const.GLSLVersion >= 140) num++;
> +         if (ctx->Const.GLSLVersion >= 150) num++;
> +         if (ctx->Const.GLSLVersion >= 330) num++;
> +         if (ctx->Const.GLSLVersion >= 400) num++;
> +         if (ctx->Const.GLSLVersion >= 410) num++;
> +         if (ctx->Const.GLSLVersion >= 420) num++;
> +         if (ctx->Const.GLSLVersion >= 430) num++;
> +         if (ctx->Const.GLSLVersion >= 440) num++;
> +         if (ctx->Const.GLSLVersion >= 450) num++;
> +         if (ctx->Const.GLSLVersion >= 460) num++;

It would be nice if that code could be combined with the 
shading_language_version_index() code below so that when a new SL 
version comes along, only one function would have to be updated instead 
of two.  You're already computing the number of versions there too.


> +
> +         v->value_int = num;
> +      }
> +      break;
>      /* GL_ARB_draw_indirect */
>      case GL_DRAW_INDIRECT_BUFFER_BINDING:
>         v->value_int = ctx->DrawIndirectBuffer->Name;
> diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
> index df082af207..be716f6f6e 100644
> --- a/src/mesa/main/get_hash_params.py
> +++ b/src/mesa/main/get_hash_params.py
> @@ -543,6 +543,9 @@ descriptor=[
>   
>     # GL_ARB_texture_cube_map_array
>     [ "TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB", "LOC_CUSTOM, TYPE_INT, TEXTURE_CUBE_ARRAY_INDEX, extra_ARB_texture_cube_map_array_OES_texture_cube_map_array" ],
> +
> +  # GL_NUM_SHADING_LANGUAGE_VERSIONS
> +  [ "NUM_SHADING_LANGUAGE_VERSIONS", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
>   ]},
>   
>   # Enums in OpenGL Core profile and ES 3.0
> diff --git a/src/mesa/main/getstring.c b/src/mesa/main/getstring.c
> index 931f6a476c..50136b91b3 100644
> --- a/src/mesa/main/getstring.c
> +++ b/src/mesa/main/getstring.c
> @@ -99,6 +99,60 @@ shading_language_version(struct gl_context *ctx)
>   }
>   
>   
> +/**
> + * Return the string for a glGetStringi(GL_SHADING_LANGUAGE_VERSION) query.
> + */
> +static const GLubyte *
> +shading_language_version_index(struct gl_context *ctx, GLuint index)
> +{
> +   char *supported_versions[17];
> +   int num_supported = 0;
> +
> +   /* Reversed order */
> +   /* GLSL es */
> +   if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
> +      supported_versions[num_supported++] = "100";
> +   if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
> +      supported_versions[num_supported++] = "300 es";
> +   if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
> +      supported_versions[num_supported++] = "310 es";
> +   if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
> +       ctx->Extensions.ARB_ES3_2_compatibility)
> +      supported_versions[num_supported++] = "320 es";
> +
> +   /* GLSL core */
> +   if (ctx->Const.GLSLVersion >= 120)
> +      supported_versions[num_supported++] = "120";
> +   if (ctx->Const.GLSLVersion >= 130)
> +      supported_versions[num_supported++] = "130";
> +   if (ctx->Const.GLSLVersion >= 140)
> +      supported_versions[num_supported++] = "140";
> +   if (ctx->Const.GLSLVersion >= 150)
> +      supported_versions[num_supported++] = "150";
> +   if (ctx->Const.GLSLVersion >= 330)
> +      supported_versions[num_supported++] = "330";
> +   if (ctx->Const.GLSLVersion >= 400)
> +      supported_versions[num_supported++] = "400";
> +   if (ctx->Const.GLSLVersion >= 410)
> +      supported_versions[num_supported++] = "410";
> +   if (ctx->Const.GLSLVersion >= 420)
> +      supported_versions[num_supported++] = "420";
> +   if (ctx->Const.GLSLVersion >= 430)
> +      supported_versions[num_supported++] = "430";
> +   if (ctx->Const.GLSLVersion >= 440)
> +      supported_versions[num_supported++] = "440";
> +   if (ctx->Const.GLSLVersion >= 450)
> +      supported_versions[num_supported++] = "450";
> +   if (ctx->Const.GLSLVersion >= 460)
> +      supported_versions[num_supported++] = "460";
> +
> +   if (index < num_supported)
> +      return (const GLubyte *) supported_versions[num_supported - index - 1];
 > +   else
 > +      return (const GLubyte *) 0;
 > +}
 > +
 > +

So, how about something like this instead:

/**
  * Get the i-th GLSL version string.  If index=0, return the most recent
  * supported version.
  * \param index  which version string to return, or -1 if none
  * \return total number of shading language versions.
  */
static int
get_shading_language_version(const struct gl_context *ctx,
                              int index,
			     char **versionOut)
{
    int n = 0;

#define VERSION(S) \
    if (n++ == index) \
       *versionOut = S

    if (ctx->Const.GLSLVersion >= 460)
       VERSION("460");

    // ... other versions here ...

    if (ctx->Const.GLSLVersion >= 120)
       VERSION("120");

    if ((ctx->API == API_OPENGLES2 && ctx->Version >= 32) ||
        ctx->Extensions.ARB_ES3_2_compatibility)
       VERSION("320 es");

    if (_mesa_is_gles31(ctx) || ctx->Extensions.ARB_ES3_1_compatibility)
       VERSION("310 es");

    if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility)
       VERSION("300 es");

    if (ctx->API == API_OPENGLES2 || ctx->Extensions.ARB_ES2_compatibility)
       VERSION("100");

    // XXX the spec also says to return the empty string for GLSL 1.10
#undef VERSION

    return n;
}


Then, to get the number of version:

    int num = get_shading_language_versions(ctx, -1, NULL);

And to get the i-th version:

    char *version;
    int num = get_shading_language_version(ctx, index, &version);
    if (index >= num) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glGetStringi(GL_SHADING_LANGUAGE_VERSION, index=%d", 
index);
       return NULL;
    }
    return version;

This would be somewhat similar to the code which queries the texture 
compression formats.

-Brian


>   /**
>    * Query string-valued state.  The return value should _not_ be freed by
>    * the caller.
> @@ -186,6 +240,8 @@ _mesa_GetStringi(GLenum name, GLuint index)
>            return (const GLubyte *) 0;
>         }
>         return _mesa_get_enabled_extension(ctx, index);
> +   case GL_SHADING_LANGUAGE_VERSION:
> +      return shading_language_version_index(ctx, index);
>      default:
>         _mesa_error(ctx, GL_INVALID_ENUM, "glGetStringi");
>         return (const GLubyte *) 0;
> 



More information about the mesa-dev mailing list