mesa: add const flags to skip MaxVarying and MaxUniform linker checks (v2)
authorMarek Olšák <maraeo@gmail.com>
Sat, 10 Dec 2011 03:14:46 +0000 (04:14 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 13 Dec 2011 16:49:00 +0000 (17:49 +0100)
This is only temporary until a better solution is available.

v2: print warnings and add gallium CAPs

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/r300/r300_screen.c
src/gallium/include/pipe/p_defines.h
src/glsl/linker.cpp
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_extensions.c

index e734ff291d163c3eac552347465f05c4265fa37e..0bae065176a0c262c92cc52a476dc352ea4361d0 100644 (file)
@@ -100,6 +100,8 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
         case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
         case PIPE_CAP_CONDITIONAL_RENDER:
         case PIPE_CAP_TEXTURE_BARRIER:
+        case PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS:
+        case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
             return 1;
 
         /* r300 cannot do swizzling of compressed textures. Supported otherwise. */
index f00077cb8aae1381d6060aa14f3b7ffff4f16191..30f1d7fb96445b0943ac3e86262fd19734eb3020 100644 (file)
@@ -465,7 +465,9 @@ enum pipe_cap {
    PIPE_CAP_MIN_TEXEL_OFFSET = 50,
    PIPE_CAP_MAX_TEXEL_OFFSET = 51,
    PIPE_CAP_CONDITIONAL_RENDER = 52,
-   PIPE_CAP_TEXTURE_BARRIER = 53
+   PIPE_CAP_TEXTURE_BARRIER = 53,
+   PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS = 54, /* temporary */
+   PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS = 55 /* temporary */
 };
 
 /**
index 35270881af5960d9e2d3bae6adcf16385285af93..b8a7126e3f6c6fe2d389448af713598866b5b9ea 100644 (file)
@@ -1815,18 +1815,34 @@ assign_varying_locations(struct gl_context *ctx,
 
    if (ctx->API == API_OPENGLES2 || prog->Version == 100) {
       if (varying_vectors > ctx->Const.MaxVarying) {
-        linker_error(prog, "shader uses too many varying vectors "
-                     "(%u > %u)\n",
-                     varying_vectors, ctx->Const.MaxVarying);
-        return false;
+         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+            linker_warning(prog, "shader uses too many varying vectors "
+                           "(%u > %u), but the driver will try to optimize "
+                           "them out; this is non-portable out-of-spec "
+                           "behavior\n",
+                           varying_vectors, ctx->Const.MaxVarying);
+         } else {
+            linker_error(prog, "shader uses too many varying vectors "
+                         "(%u > %u)\n",
+                         varying_vectors, ctx->Const.MaxVarying);
+            return false;
+         }
       }
    } else {
       const unsigned float_components = varying_vectors * 4;
       if (float_components > ctx->Const.MaxVarying * 4) {
-        linker_error(prog, "shader uses too many varying components "
-                     "(%u > %u)\n",
-                     float_components, ctx->Const.MaxVarying * 4);
-        return false;
+         if (ctx->Const.GLSLSkipStrictMaxVaryingLimitCheck) {
+            linker_warning(prog, "shader uses too many varying components "
+                           "(%u > %u), but the driver will try to optimize "
+                           "them out; this is non-portable out-of-spec "
+                           "behavior\n",
+                           float_components, ctx->Const.MaxVarying * 4);
+         } else {
+            linker_error(prog, "shader uses too many varying components "
+                         "(%u > %u)\n",
+                         float_components, ctx->Const.MaxVarying * 4);
+            return false;
+         }
       }
    }
 
@@ -1960,8 +1976,15 @@ check_resources(struct gl_context *ctx, struct gl_shader_program *prog)
       }
 
       if (sh->num_uniform_components > max_uniform_components[i]) {
-         linker_error(prog, "Too many %s shader uniform components",
-                     shader_names[i]);
+         if (ctx->Const.GLSLSkipStrictMaxUniformLimitCheck) {
+            linker_warning(prog, "Too many %s shader uniform components, "
+                           "but the driver will try to optimize them out; "
+                           "this is non-portable out-of-spec behavior\n",
+                           shader_names[i]);
+         } else {
+            linker_error(prog, "Too many %s shader uniform components",
+                         shader_names[i]);
+         }
       }
    }
 
index 1e06cd55c6b5a0ce829ed34b2860df6d42582c51..19343497689cc0749175978b11904651cdc6f24e 100644 (file)
@@ -2830,6 +2830,15 @@ struct gl_constants
     * Texture borders are deprecated in GL 3.0.
     **/
    GLboolean StripTextureBorder;
+
+   /**
+    * For drivers which can do a better job at eliminating unused varyings
+    * and uniforms than the GLSL compiler.
+    *
+    * XXX Remove these as soon as a better solution is available.
+    */
+   GLboolean GLSLSkipStrictMaxVaryingLimitCheck;
+   GLboolean GLSLSkipStrictMaxUniformLimitCheck;
 };
 
 
index 9e39729e9d4b0247083e71559e6a67cb72090f94..457d5d62a8e19e338583243d53bf8a977775f202 100644 (file)
@@ -222,6 +222,12 @@ void st_init_limits(struct st_context *st)
    c->UniformBooleanTrue = ~0;
 
    c->StripTextureBorder = GL_TRUE;
+
+   c->GLSLSkipStrictMaxUniformLimitCheck =
+      screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS);
+
+   c->GLSLSkipStrictMaxVaryingLimitCheck =
+      screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS);
 }