glsl: Allow invariant flags on sysvals, such as gl_PointCoord.
authorEmma Anholt <emma@anholt.net>
Wed, 10 May 2023 18:11:58 +0000 (11:11 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 1 Jun 2023 22:27:08 +0000 (22:27 +0000)
When you set PIPE_CAP_FS_POINT_IS_SYSVAL, we'd fall out of
is_allowed_invariant(), despite it being allowed on special builtins.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22950>

src/compiler/glsl/ast_to_hir.cpp
src/gallium/drivers/lima/ci/lima-fails.txt

index 7831d5a..ef41b8a 100644 (file)
@@ -2774,6 +2774,42 @@ is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state)
    if (is_varying_var(var, state->stage))
       return true;
 
+   /* ES2 says:
+    *
+    * "For the built-in special variables, gl_FragCoord can only be declared
+    *  invariant if and only if gl_Position is declared invariant. Similarly
+    *  gl_PointCoord can only be declared invariant if and only if gl_PointSize
+    *  is declared invariant. It is an error to declare gl_FrontFacing as
+    *  invariant. The invariance of gl_FrontFacing is the same as the invariance
+    *  of gl_Position."
+    *
+    * ES3.1 says about invariance:
+    *
+    * "How does this rule apply to the built-in special variables?
+    *
+    *  Option 1: It should be the same as for varyings. But gl_Position is used
+    *  internally by the rasterizer as well as for gl_FragCoord so there may be
+    *  cases where rasterization is required to be invariant but gl_FragCoord is
+    *  not.
+    *
+    *  RESOLUTION: Option 1."
+    *
+    * and the ES3 spec has similar text but the "RESOLUTION" is missing.
+    *
+    * Any system values should be from built-in special variables.
+    */
+   if (var->data.mode == ir_var_system_value) {
+      if (state->is_version(0, 300)) {
+         return true;
+      } else {
+         /* Note: We don't actually have a check that the VS's PointSize is
+          * invariant, even when it's treated as a varying.
+          */
+         if (var->data.location == SYSTEM_VALUE_POINT_COORD)
+            return true;
+      }
+   }
+
    /* From Section 4.6.1 ("The Invariant Qualifier") GLSL 1.20 spec:
     * "Only variables output from a vertex shader can be candidates
     * for invariance".
index 3392dd7..91f9add 100644 (file)
@@ -542,8 +542,6 @@ spec@glsl-1.20@execution@variable-indexing@vs-varying-mat4-col-row-wr,Fail
 spec@glsl-1.20@execution@variable-indexing@vs-varying-mat4-col-wr,Fail
 spec@glsl-1.20@execution@variable-indexing@vs-varying-mat4-row-wr,Fail
 spec@glsl-1.20@execution@variable-indexing@vs-varying-mat4-wr,Fail
-spec@glsl-es-1.00@linker@glsl-pcoord-invariant,Fail
-spec@glsl-es-1.00@linker@glsl-pcoord-invariant-pass,Fail
 spec@intel_performance_query@intel_performance_query-issue_2235,Fail
 spec@khr_texture_compression_astc@basic-gles,Fail
 spec@khr_texture_compression_astc@miptree-gles srgb,Fail