[Mesa-dev] [PATCH 2/5] glsl_compiler: Set max GLSL version on the command line
Kenneth Graunke
kenneth at whitecape.org
Sun Oct 6 20:06:02 PDT 2013
On 09/27/2013 11:58 AM, Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Infer whether or not to use ES based on the GLSL version (100 or 300 are
> for ES). This replaces the --glsl-es command line option. Set various
> compiler limits based on the minimums required for the specified GLSL
> version.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
> src/glsl/main.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 173 insertions(+), 12 deletions(-)
>
> diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
> index bc15835..8f59ada 100644
> --- a/src/glsl/main.cpp
> +++ b/src/glsl/main.cpp
> @@ -38,6 +38,8 @@
> #include "loop_analysis.h"
> #include "standalone_scaffolding.h"
>
> +static int glsl_version = 330;
> +
> static void
> initialize_context(struct gl_context *ctx, gl_api api)
> {
> @@ -46,16 +48,150 @@ initialize_context(struct gl_context *ctx, gl_api api)
> /* The standalone compiler needs to claim support for almost
> * everything in order to compile the built-in functions.
> */
> - ctx->Const.GLSLVersion = 330;
> + ctx->Const.GLSLVersion = glsl_version;
> ctx->Extensions.ARB_ES3_compatibility = true;
>
> - ctx->Const.MaxClipPlanes = 8;
> - ctx->Const.MaxDrawBuffers = 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;
> + switch (ctx->Const.GLSLVersion) {
> + case 100:
> + ctx->Const.MaxClipPlanes = 0;
> + ctx->Const.MaxCombinedTextureImageUnits = 8;
> + ctx->Const.MaxDrawBuffers = 2;
> + ctx->Const.MinProgramTexelOffset = 0;
> + ctx->Const.MaxProgramTexelOffset = 0;
> + ctx->Const.MaxLights = 0;
> + ctx->Const.MaxTextureCoordUnits = 0;
> + ctx->Const.MaxTextureUnits = 8;
> +
> + ctx->Const.VertexProgram.MaxAttribs = 8;
> + ctx->Const.VertexProgram.MaxTextureImageUnits = 0;
> + ctx->Const.VertexProgram.MaxUniformComponents = 128 * 4;
> + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */
> + ctx->Const.VertexProgram.MaxOutputComponents = 32;
> +
> + ctx->Const.FragmentProgram.MaxTextureImageUnits =
> + ctx->Const.MaxCombinedTextureImageUnits;
> + ctx->Const.FragmentProgram.MaxUniformComponents = 16 * 4;
> + ctx->Const.FragmentProgram.MaxInputComponents =
> + ctx->Const.VertexProgram.MaxOutputComponents;
> + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */
> +
> + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4;
> + break;
> + case 110:
> + case 120:
> + ctx->Const.MaxClipPlanes = 6;
> + ctx->Const.MaxCombinedTextureImageUnits = 2;
> + ctx->Const.MaxDrawBuffers = 1;
> + ctx->Const.MinProgramTexelOffset = 0;
> + ctx->Const.MaxProgramTexelOffset = 0;
> + ctx->Const.MaxLights = 8;
> + ctx->Const.MaxTextureCoordUnits = 2;
> + ctx->Const.MaxTextureUnits = 2;
> +
> + ctx->Const.VertexProgram.MaxAttribs = 16;
> + ctx->Const.VertexProgram.MaxTextureImageUnits = 0;
> + ctx->Const.VertexProgram.MaxUniformComponents = 512;
> + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */
> + ctx->Const.VertexProgram.MaxOutputComponents = 32;
> +
> + ctx->Const.FragmentProgram.MaxTextureImageUnits =
> + ctx->Const.MaxCombinedTextureImageUnits;
> + ctx->Const.FragmentProgram.MaxUniformComponents = 64;
> + ctx->Const.FragmentProgram.MaxInputComponents =
> + ctx->Const.VertexProgram.MaxOutputComponents;
> + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */
> +
> + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4;
> + break;
> + case 130:
> + case 140:
> + ctx->Const.MaxClipPlanes = 8;
> + ctx->Const.MaxCombinedTextureImageUnits = 16;
> + ctx->Const.MaxDrawBuffers = 8;
> + ctx->Const.MinProgramTexelOffset = -8;
> + ctx->Const.MaxProgramTexelOffset = 7;
> + ctx->Const.MaxLights = 8;
> + ctx->Const.MaxTextureCoordUnits = 8;
> + ctx->Const.MaxTextureUnits = 2;
> +
> + ctx->Const.VertexProgram.MaxAttribs = 16;
> + ctx->Const.VertexProgram.MaxTextureImageUnits = 16;
> + ctx->Const.VertexProgram.MaxUniformComponents = 1024;
> + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */
> + ctx->Const.VertexProgram.MaxOutputComponents = 64;
> +
> + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16;
> + ctx->Const.FragmentProgram.MaxUniformComponents = 1024;
> + ctx->Const.FragmentProgram.MaxInputComponents =
> + ctx->Const.VertexProgram.MaxOutputComponents;
> + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */
> +
> + ctx->Const.MaxVarying = ctx->Const.VertexProgram.MaxOutputComponents / 4;
> + break;
> + case 150:
> + case 330:
> + ctx->Const.MaxClipPlanes = 8;
> + ctx->Const.MaxDrawBuffers = 8;
> + ctx->Const.MinProgramTexelOffset = -8;
> + ctx->Const.MaxProgramTexelOffset = 7;
> + ctx->Const.MaxLights = 8;
> + ctx->Const.MaxTextureCoordUnits = 8;
> + ctx->Const.MaxTextureUnits = 2;
> +
> + ctx->Const.VertexProgram.MaxAttribs = 16;
> + ctx->Const.VertexProgram.MaxTextureImageUnits = 16;
> + ctx->Const.VertexProgram.MaxUniformComponents = 1024;
> + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */
> + ctx->Const.VertexProgram.MaxOutputComponents = 64;
> +
> + ctx->Const.GeometryProgram.MaxTextureImageUnits = 16;
> + ctx->Const.GeometryProgram.MaxUniformComponents = 1024;
> + ctx->Const.GeometryProgram.MaxInputComponents =
> + ctx->Const.VertexProgram.MaxOutputComponents;
> + ctx->Const.GeometryProgram.MaxOutputComponents = 128;
> +
> + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16;
> + ctx->Const.FragmentProgram.MaxUniformComponents = 1024;
> + ctx->Const.FragmentProgram.MaxInputComponents =
> + ctx->Const.GeometryProgram.MaxOutputComponents;
> + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */
> +
> + ctx->Const.MaxCombinedTextureImageUnits =
> + ctx->Const.VertexProgram.MaxTextureImageUnits
> + + ctx->Const.GeometryProgram.MaxTextureImageUnits
> + + ctx->Const.FragmentProgram.MaxTextureImageUnits;
> +
> + ctx->Const.MaxGeometryOutputVertices = 256;
> + ctx->Const.MaxGeometryTotalOutputComponents = 1024;
> +
> +// ctx->Const.MaxGeometryVaryingComponents = 64;
> +
> + ctx->Const.MaxVarying = 60 / 4;
> + break;
> + case 300:
> + ctx->Const.MaxClipPlanes = 8;
> + ctx->Const.MaxCombinedTextureImageUnits = 32;
> + ctx->Const.MaxDrawBuffers = 4;
> + ctx->Const.MinProgramTexelOffset = -8;
> + ctx->Const.MaxProgramTexelOffset = 7;
> + ctx->Const.MaxLights = 0;
> + ctx->Const.MaxTextureCoordUnits = 0;
> + ctx->Const.MaxTextureUnits = 0;
> +
> + ctx->Const.VertexProgram.MaxAttribs = 16;
> + ctx->Const.VertexProgram.MaxTextureImageUnits = 16;
> + ctx->Const.VertexProgram.MaxUniformComponents = 1024;
> + ctx->Const.VertexProgram.MaxInputComponents = 0; /* not used */
> + ctx->Const.VertexProgram.MaxOutputComponents = 16 * 4;
> +
> + ctx->Const.FragmentProgram.MaxTextureImageUnits = 16;
> + ctx->Const.FragmentProgram.MaxUniformComponents = 224;
> + ctx->Const.FragmentProgram.MaxInputComponents = 15 * 4;
> + ctx->Const.FragmentProgram.MaxOutputComponents = 0; /* not used */
> +
> + ctx->Const.MaxVarying = ctx->Const.FragmentProgram.MaxInputComponents / 4;
> + break;
> + }
>
> ctx->Driver.NewShader = _mesa_new_shader;
> }
> @@ -103,18 +239,17 @@ load_text_file(void *ctx, const char *file_name)
> return text;
> }
>
> -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", no_argument, &glsl_es, 1 },
> { "dump-ast", no_argument, &dump_ast, 1 },
> { "dump-hir", no_argument, &dump_hir, 1 },
> { "dump-lir", no_argument, &dump_lir, 1 },
> { "link", no_argument, &do_link, 1 },
> + { "version", required_argument, NULL, 'v' },
> { NULL, 0, NULL, 0 }
> };
>
> @@ -159,11 +294,37 @@ main(int argc, char **argv)
> int status = EXIT_SUCCESS;
> struct gl_context local_ctx;
> struct gl_context *ctx = &local_ctx;
> + bool glsl_es = false;
>
> int c;
> int idx = 0;
> - while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1)
> - /* empty */ ;
> + while ((c = getopt_long(argc, argv, "", compiler_opts, &idx)) != -1) {
> + switch (c) {
> + case 'v':
> + glsl_version = strtol(optarg, NULL, 10);
> + switch (glsl_version) {
> + case 100:
> + case 300:
> + glsl_es = true;
> + break;
> + case 110:
> + case 120:
> + case 130:
> + case 140:
> + case 150:
> + case 330:
> + glsl_es = false;
> + break;
> + default:
> + fprintf(stderr, "Unrecognized GLSL version `%s'\n", optarg);
> + usage_fail(argv[0]);
> + break;
> + }
> + break;
> + default:
> + break;
> + }
> + }
You're using mixed tabs and spaces here. Probably ought to be just
spaces. But I'm not going to be picky.
This patch is:
Acked-by: Kenneth Graunke <kenneth at whitecape.org>
because I didn't check the limits, but I like the idea.
The rest of the series is:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
More information about the mesa-dev
mailing list