[Piglit] [PATCH] glsl-es-3.00: test for 'invariant(all)' usage in a fragment shader

Wang, Shuo shuo.wang at intel.com
Fri Nov 7 00:55:36 PST 2014


	Since "#version 300 es" is necessary by Spec and below is the content of page 9 of Spec " The OpenGL ES® Shading Language Language Version: 3.00 Document Revision: 3 11 July 2012"
	"The directive "#version 300 es" is required in any shader that uses version 3.00 of the language. Any number representing a version of the language a compiler does not support will cause an error to be
generated. Version 1.00 of the language does not require shaders to include this directive, and shaders that do not include a #version directive will be treated as targeting version 1.00."

	I suppose Ian and DyIan mean the infrastructure will add the token "#version 300 es" automatically if the GLSL ES30 shader do not contain it. 
	So I write a patch to add the feature as below(the same as attachment):

Signed-off-by: Wang Shuo <shuo.wang at intel.com>
---
 framework/test/glsl_parser_test.py | 71 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/framework/test/glsl_parser_test.py b/framework/test/glsl_parser_test.py
index 2c48888..8deeb01 100644
--- a/framework/test/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -94,6 +94,7 @@ class GLSLParserTest(PiglitBaseTest):
 
         # a set that stores a list of keys that have been found already
         self.__found_keys = set()
+        is_glsles30_version_exist = 1
 
         # Parse the config file and get the config section, then write this
         # section to a StringIO and pass that to ConfigParser
@@ -104,6 +105,20 @@ class GLSLParserTest(PiglitBaseTest):
                 print(e.message, file=sys.stderr)
                 sys.exit(1)
 
+        # Check if the shader of GLSL ES 300 contained #version 300 es
+        # If not, return 0
+        # If ture, return 1
+        if config['glsl_version'] == "3.00":
+            with open(filepath, 'r') as testfileread:
+                try:
+                    is_glsles30_version_exist = self.__parserglsles3(testfileread, filepath)
+                except GLSLParserException as e:
+                    print(e.message, file=sys.stderr)
+                    sys.exit(1)
+
+        # If the shader of GLSL ES 300 do not contained #version 300 es, add it at the first line of shader
+        if( is_glsles30_version_exist == 0):
+            self.__addglsles3version(filepath)
         command = self.__get_command(config, filepath)
         super(GLSLParserTest, self).__init__(command, run_concurrent=True)
 
@@ -213,6 +228,62 @@ class GLSLParserTest(PiglitBaseTest):
 
         return keys
 
+    def __parserglsles3(self, testfile, filepath):
+        """ Private helper that parses the GLSL ES 300 shader file
+
+        This method parses the lines of GLSL ES 300 shader file. If the shader contain 
+        #version 300 es, return 1. Else, return 0
+
+        It will raise GLSLParserExceptions if any part of the parsing
+        fails.
+
+        """
+
+        # Text of shader section.
+        # Create a generator that iterates over the lines in the shader file.
+        # This allows us to run the loop until we find the #version es 300, if we find it, return 1
+        # or return 0
+        #raise GLSLParserException(filepath)
+        lines = (l.strip() for l in testfile)
+
+        is_glsles30_head_contained = re.compile(r'\s*#version\s300\ses')
+        tmp_is_glsles30_head_contained = 0
+        for line in lines:
+                match = is_glsles30_head_contained.match(line)
+                if match:
+                        tmp_is_glsles30_head_contained = 1
+                        break
+        
+
+        if tmp_is_glsles30_head_contained == 0:
+            return 0
+
+        return 1
+
+
+    def __addglsles3version(self, filepath):
+        """ Private helper that add the #version 300 es to the certain shader file
+
+        This method add #version 300 es to the certain shader file which is based on GLSL ES 30
+        and not contained a #version 300 es
+
+        It will raise GLSLParserExceptions if any part of the parsing
+        fails.
+
+        """
+
+        # Text of shader section.
+        # Add #version 300 es to the first line of GLSL ES 30 shader which is not contained it
+        fp = file(filepath)
+        s = fp.read()
+        fp.close()
+        a = s.split('\n')
+        a.insert(0, '#version 300 es')
+        s = '\n'.join(a)
+        fp = file(filepath, 'w')
+        fp.write(s)
+        fp.close()
+
 
 class GLSLParserException(Exception):
     pass
-- 
1.8.3.2

Thanks,
Shuo

-----Original Message-----
From: Piglit [mailto:piglit-bounces at lists.freedesktop.org] On Behalf Of Dylan Baker
Sent: Friday, November 7, 2014 7:19 AM
To: piglit at lists.freedesktop.org
Subject: Re: [Piglit] [PATCH] glsl-es-3.00: test for 'invariant(all)' usage in a fragment shader

On Thursday, November 06, 2014 02:40:28 PM Ian Romanick wrote:
> The test looks fine enough, but could you add a spec quotation to defend it?
> 
> On 11/04/2014 04:19 AM, Tapani Pälli wrote:
> > Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> > ---
> >  tests/spec/glsl-es-3.00/compiler/invariant_all.frag | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >  create mode 100644 tests/spec/glsl-es-3.00/compiler/invariant_all.frag
> > 
> > diff --git a/tests/spec/glsl-es-3.00/compiler/invariant_all.frag b/tests/spec/glsl-es-3.00/compiler/invariant_all.frag
> > new file mode 100644
> > index 0000000..37031cf
> > --- /dev/null
> > +++ b/tests/spec/glsl-es-3.00/compiler/invariant_all.frag
> > @@ -0,0 +1,12 @@
> > +#version 300 es
> 
> The #version shouldn't be necessary with the current infrastructure, right?

Actually, we do. I think this is a bug.

> 
> > +// [config]
> > +// expect_result: fail
> > +// glsl_version: 3.00
> > +// [end config]
> > +//
> > +// Check that 'invariant(all)' cannot be used in fragment shader
> > +
> > +#pragma STDGL invariant(all)
> > +void main()
> > +{
> > +}
> > 
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-version-300-es-to-the-first-line-of-shader-based.patch
Type: application/octet-stream
Size: 4143 bytes
Desc: 0001-Add-version-300-es-to-the-first-line-of-shader-based.patch
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20141107/6610f425/attachment.obj>


More information about the Piglit mailing list