Module: Mesa
Branch: 9.2
Commit: 872c09586c32de71839ced89f8bbf71ca61df866
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=872c09586c32de71839ced89f8bbf71ca61df866

Author: Ian Romanick <[email protected]>
Date:   Fri Aug  9 13:32:40 2013 -0700

glsl: Emit better warnings for things that look like default precision 
statements

Previously we would emit a warning for empty declarations like

float;

We would also emit the same warning for things like

highp float;

However, this second case is most likely the application trying to set
the default precision.  This makes the compiler generate a stronger
warning with some suggestion of a fix.

It really seems like this should be an error.  I'll bet that 100% of the
time someone writes 'highp float;' the actually meant 'precision highp
float;'.  Alas, both AMD and NVIDIA accept this syntax, and the spec
doesn't explicitly forbid it.

This makes piglit's precision-05.vert generate the following warnings:

0:12(11): warning: empty declaration with precision qualifier, to set the 
default precision, use `precision lowp float;'
0:13(12): warning: empty declaration with precision qualifier, to set the 
default precision, use `precision mediump int;'

v2: Add { } around a one-line if body and fix a comment.  Suggested by
Ken.

Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Cc: "9.2" <[email protected]>
(cherry picked from commit 830f4df993b41fc90c776b19f77f77a29ce0e7f4)

---

 src/glsl/ast_to_hir.cpp |   44 +++++++++++++++++++++++++++++++-------------
 1 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 992195c..870ea3d 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2614,6 +2614,11 @@ ast_declarator_list::hir(exec_list *instructions,
        *   name of a known structure type.  This is both invalid and weird.
        *   Emit an error.
        *
+       * - The program text contained something like 'mediump float;'
+       *   when the programmer probably meant 'precision mediump
+       *   float;' Emit a warning with a description of what they
+       *   probably meant to do.
+       *
        * Note that if decl_type is NULL and there is a structure involved,
        * there must have been some sort of error with the structure.  In this
        * case we assume that an error was already generated on this line of
@@ -2622,20 +2627,33 @@ ast_declarator_list::hir(exec_list *instructions,
        */
       assert(this->type->specifier->structure == NULL || decl_type != NULL
             || state->error);
-      if (this->type->specifier->structure == NULL) {
-        if (decl_type != NULL) {
-           _mesa_glsl_warning(&loc, state, "empty declaration");
-        } else {
-           _mesa_glsl_error(&loc, state,
-                            "invalid type `%s' in empty declaration",
-                            type_name);
-        }
-      }
 
-      if (this->type->qualifier.precision != ast_precision_none &&
-          this->type->specifier->structure != NULL) {
-         _mesa_glsl_error(&loc, state, "Precision qualifiers can't be applied "
-                          "to structures.\n");
+      if (decl_type == NULL) {
+         _mesa_glsl_error(&loc, state,
+                          "invalid type `%s' in empty declaration",
+                          type_name);
+      } else if (this->type->qualifier.precision != ast_precision_none) {
+         if (this->type->specifier->structure != NULL) {
+            _mesa_glsl_error(&loc, state,
+                             "precision qualifiers can't be applied "
+                             "to structures");
+         } else {
+            static const char *const precision_names[] = {
+               "highp",
+               "highp",
+               "mediump",
+               "lowp"
+            };
+
+            _mesa_glsl_warning(&loc, state,
+                               "empty declaration with precision qualifier, "
+                               "to set the default precision, use "
+                               "`precision %s %s;'",
+                               
precision_names[this->type->qualifier.precision],
+                               type_name);
+         }
+      } else {
+         _mesa_glsl_warning(&loc, state, "empty declaration");
       }
    }
 

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to