[Piglit] [PATCH 3/4] util: Add u/byte, u/short and half support to [vertex data]

Andres Gomez agomez at igalia.com
Thu Jun 9 21:27:04 UTC 2016


This allows to set data of u/byte, u/short and half types for
attributes with the shader runner.

For example:
attname0/byte/int attname1/ushort/uint attname3/half/float

The syntax has been extended so the recommended way has replaced the
old COUNT field in the [vertex data] header line with the
corresponding GLSL type for the old TYPE field.

In any case, the extended syntax is backward compatible so it is still
possible to specify a vec3 attribute like:
attname/float/3

In addition to the now recommended format:
attname/float/vec3

Due to this, the arb_vertex_attrib_64bit input tests generator has
been also adapted to the new syntax.

Signed-off-by: Andres Gomez <agomez at igalia.com>
---
 generated_tests/gen_vs_in_fp64.py                  | 266 +++++++++++++---
 .../gen_vs_in_fp64/columns.shader_test.mako        |  20 +-
 .../gen_vs_in_fp64/regular.shader_test.mako        |  31 +-
 tests/util/piglit-dispatch.h                       |   1 +
 tests/util/piglit-vbo.cpp                          | 340 +++++++++++++++------
 5 files changed, 489 insertions(+), 169 deletions(-)

diff --git a/generated_tests/gen_vs_in_fp64.py b/generated_tests/gen_vs_in_fp64.py
index fcc87f5..879f0f6 100644
--- a/generated_tests/gen_vs_in_fp64.py
+++ b/generated_tests/gen_vs_in_fp64.py
@@ -71,47 +71,165 @@ DOUBLE_NORMAL_VALUES   = ['0xffefffffffffffff', # Negative maximum normalized
                           '0x4b1e35ed24eb6496', # +7.23401345e+53
                           '0x7fefffffffffffff'] # Positive maximum normalized
 
-DSCALAR_TYPES          = ['double']
-
-DVEC_TYPES             = ['dvec2', 'dvec3', 'dvec4']
-
-DMAT_TYPES             = ['dmat2', 'dmat2x3', 'dmat2x4',
+FLOAT_POS_ZERO         = ['0x00000000'] #  0.0
+
+FLOAT_NORMAL_VALUES    = ['0xc21620c5', # -3.7532
+                          '0x75bc289b', #  4.7703e32
+                          '0x54c1c081', #  6.6572e12
+                          '0x878218f8', # -1.9575e-34
+                          '0x7e0857ed', #  4.5307886e37
+                          '0x2bb561bf', #  1.2887954e-12
+                          '0xff7fffff', # Negative maximum normalized
+                          '0xcb800000', # -16777216.0
+                          '0xc0a00000', # -5.0
+                          '0xbff92e73', # -1.9467300
+                          '0x80800000', # Negative minimum normalized
+                          '0x00800000', # Positive minimum normalized
+                          '0x3ff92e73', #  1.9467300
+                          '0x40a00000', #  5.0
+                          '0x4b800000', #  16777216.0
+                          '0x7f7fffff'] # Positive maximum normalized
+
+UBYTE_VALUES           = ['0', # Minimum
+                          '127', # Signed byte low frontier
+                          '128', # Signed byte up frontier
+                          '255', # Maximum
+                          '1',
+                          '5',
+                          '14',
+                          '23',
+                          '58',
+                          '91',
+                          '113',
+                          '135',
+                          '179',
+                          '185',
+                          '205',
+                          '207',
+                          '212']
+
+BYTE_VALUES            = ['-128', # Minimum
+                          '-5',
+                          '-1',
+                          '0',
+                          '1',
+                          '5',
+                          '127', # Maximum
+                          '-125',
+                          '-120',
+                          '-117',
+                          '-69',
+                          '-24',
+                          '-20',
+                          '21',
+                          '89',
+                          '106',
+                          '119']
+
+USHORT_VALUES          = ['0', # Minimum
+                          '32767', # Signed short low frontier
+                          '32768', # Signed short up frontier
+                          '65535', # Maximum
+                          '1',
+                          '5',
+                          '12610',
+                          '17110',
+                          '19962',
+                          '23589',
+                          '37265',
+                          '41792',
+                          '45699',
+                          '47934',
+                          '55916',
+                          '56412',
+                          '65142']
+
+SHORT_VALUES           = ['-32768', # Minimum
+                          '-5',
+                          '-1',
+                          '0',
+                          '1',
+                          '5',
+                          '32767', # Maximum
+                          '-16255',
+                          '-12480',
+                          '-12360',
+                          '1706',
+                          '5386',
+                          '7315',
+                          '18137',
+                          '25871',
+                          '26255',
+                          '26472']
+
+UINT_VALUES            = ['0', # Minimum
+                          '2147483647', # Signed int low frontier
+                          '2147483648', # Signed int up frontier
+                          '4294967295', # Maximum
+                          '1',
+                          '5',
+                          '1073294963',
+                          '1084227584',
+                          '1266679808',
+                          '1421983873',
+                          '2114476013',
+                          '2273450232',
+                          '3220778611',
+                          '3231711232',
+                          '3256230085',
+                          '3414163456',
+                          '4294967294']
+
+INT_VALUES             = ['-2147483648', # Minimum
+                          '-5',
+                          '-1',
+                          '0',
+                          '1',
+                          '5',
+                          '2147483647', # Maximum
+                          '-1038737211',
+                          '-1063256064',
+                          '-1074188685',
+                          '-880803840',
+                          '1073294963',
+                          '1084227584',
+                          '1266679808',
+                          '1421983873',
+                          '1975265435',
+                          '2114476013']
+
+GL_TYPES_VALUES        = {'double': DOUBLE_NORMAL_VALUES + DOUBLE_POS_ZERO,
+                          'float': FLOAT_NORMAL_VALUES + FLOAT_POS_ZERO,
+                          'ubyte': UBYTE_VALUES,
+                          'byte': BYTE_VALUES,
+                          'ushort': USHORT_VALUES,
+                          'short': SHORT_VALUES,
+                          'uint': UINT_VALUES,
+                          'int': INT_VALUES}
+
+GLSL_DSCALAR_TYPES     = ['double']
+
+GLSL_DVEC_TYPES        = ['dvec2', 'dvec3', 'dvec4']
+
+GLSL_DMAT_TYPES        = ['dmat2', 'dmat2x3', 'dmat2x4',
                           'dmat3x2', 'dmat3', 'dmat3x4',
                           'dmat4x2', 'dmat4x3', 'dmat4']
 
-FSCALAR_TYPES          = ['float']
+GLSL_FSCALAR_TYPES     = ['float']
 
-FVEC_TYPES             = ['vec2', 'vec3', 'vec4']
+GLSL_FVEC_TYPES        = ['vec2', 'vec3', 'vec4']
 
-FMAT_TYPES             = ['mat2', 'mat2x3', 'mat2x4',
+GLSL_FMAT_TYPES        = ['mat2', 'mat2x3', 'mat2x4',
                           'mat3x2', 'mat3', 'mat3x4',
                           'mat4x2', 'mat4x3', 'mat4']
 
-ISCALAR_TYPES          = ['int']
-
-IVEC_TYPES             = ['ivec2', 'ivec3', 'ivec4']
+GLSL_ISCALAR_TYPES     = ['int']
 
-USCALAR_TYPES          = ['uint']
+GLSL_IVEC_TYPES        = ['ivec2', 'ivec3', 'ivec4']
 
-UVEC_TYPES             = ['uvec2', 'uvec3', 'uvec4']
+GLSL_USCALAR_TYPES     = ['uint']
 
-HEX_VALUES_32BIT       = ['0xc21620c5', # -3.7532        float, -1038737211 int, 3256230085 uint
-                          '0x75bc289b', #  4.7703e32     float,  1975265435 int, 1975265435 uint
-                          '0x54c1c081', #  6.6572e12     float,  1421983873 int, 1421983873 uint
-                          '0x878218f8', # -1.9575e-34    float, -1038737211 int, 2273450232 uint
-                          '0x7e0857ed', #  4.5307886e+37 float,  2114476013 int, 2114476013 uint
-                          '0x2bb561bf', #  1.2887954e-12 float,   733307327 int,  733307327 uint
-                          '0xff7fffff', # -3.4028235e+38 float,    -8388609 int, 4286578687 uint
-                          '0xcb800000', # -16777216.0    float,  -880803840 int, 3414163456 uint
-                          '0xc0a00000', # -5.0           float, -1063256064 int, 3231711232 uint
-                          '0xbff92e73', # -1.9467300     float, -1074188685 int, 3220778611 uint
-                          '0x80800000', # -1.1754944e-38 float, -2139095040 int, 2155872256 uint
-                          '0x00000000', #  0.0           float,           0 int,          0 uint
-                          '0x00800000', #  1.1754944e-38 float,     8388608 int,    8388608 uint
-                          '0x3ff92e73', #  1.9467300     float,  1073294963 int, 1073294963 uint
-                          '0x40a00000', #  5.0           float,  1084227584 int, 1084227584 uint
-                          '0x4b800000', #  16777216.0    float,  1266679808 int, 1266679808 uint
-                          '0x7f7fffff'] #  3.4028235e+38 float,  2139095039 int, 2139095039 uint
+GLSL_UVEC_TYPES        = ['uvec2', 'uvec3', 'uvec4']
 
 
 # pylint: enable=bad-whitespace,line-too-long
@@ -174,15 +292,18 @@ class RegularTestTuple(TestTuple):
     @staticmethod
     def create_in_types_array(*types_arrays):
         """Creates vertex input combinations."""
+
         for product_item in itertools.product(*types_arrays):
             yield product_item
 
     @staticmethod
-    def create_tests(glsl_vers, in_types_array, position_orders, arrays_array, names_only):
+    def create_tests(glsl_vers, in_types_array, gl_types,
+                     position_orders, arrays_array, names_only):
         """Creates combinations for flat qualifier tests."""
 
         assert isinstance(glsl_vers, list)
         assert isinstance(in_types_array, types.GeneratorType)
+        assert isinstance(gl_types, list)
         assert isinstance(position_orders, list)
         assert isinstance(arrays_array, list)
         assert isinstance(names_only, bool)
@@ -210,7 +331,7 @@ class RegularTestTuple(TestTuple):
             if num_vs_in > MAX_VERTEX_ATTRIBS:
                 continue
 
-            yield ver, in_types, position_order, arrays, num_vs_in, names_only
+            yield ver, in_types, gl_types, position_order, arrays, num_vs_in, names_only
 
     @staticmethod
     def all_tests(names_only):
@@ -224,10 +345,29 @@ class RegularTestTuple(TestTuple):
         for test_args in RegularTestTuple.create_tests(
                 ['GL_ARB_vertex_attrib_64bit', '410'],
                 RegularTestTuple.create_in_types_array(
-                    itertools.chain(DSCALAR_TYPES, DVEC_TYPES, DMAT_TYPES),
-                    itertools.chain(FSCALAR_TYPES, FVEC_TYPES, FMAT_TYPES,
-                                    ISCALAR_TYPES, IVEC_TYPES,
-                                    USCALAR_TYPES, UVEC_TYPES)),
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
+                    itertools.chain(GLSL_FSCALAR_TYPES, GLSL_FVEC_TYPES, GLSL_FMAT_TYPES)),
+                ['double', 'float'],
+                [1, 2, 3],
+                [[1, 1], [1, 3], [5, 1], [5, 3]],
+                names_only):
+            yield RegularTestTuple(*test_args)
+        for test_args in RegularTestTuple.create_tests(
+                ['GL_ARB_vertex_attrib_64bit', '410'],
+                RegularTestTuple.create_in_types_array(
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
+                    itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES)),
+                ['double', 'int'],
+                [1, 2, 3],
+                [[1, 1], [1, 3], [5, 1], [5, 3]],
+                names_only):
+            yield RegularTestTuple(*test_args)
+        for test_args in RegularTestTuple.create_tests(
+                ['GL_ARB_vertex_attrib_64bit', '410'],
+                RegularTestTuple.create_in_types_array(
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
+                    itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES)),
+                ['double', 'uint'],
                 [1, 2, 3],
                 [[1, 1], [1, 3], [5, 1], [5, 3]],
                 names_only):
@@ -235,10 +375,9 @@ class RegularTestTuple(TestTuple):
         for test_args in RegularTestTuple.create_tests(
                 ['GL_ARB_vertex_attrib_64bit', '410'],
                 RegularTestTuple.create_in_types_array(
-                    itertools.chain(FSCALAR_TYPES, FVEC_TYPES, FMAT_TYPES,
-                                    ISCALAR_TYPES, IVEC_TYPES,
-                                    USCALAR_TYPES, UVEC_TYPES),
-                    itertools.chain(DSCALAR_TYPES, DVEC_TYPES, DMAT_TYPES)),
+                    itertools.chain(GLSL_FSCALAR_TYPES, GLSL_FVEC_TYPES, GLSL_FMAT_TYPES),
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
+                ['float', 'double'],
                 [1, 2, 3],
                 [[1, 1], [1, 2], [3, 1], [3, 2]],
                 names_only):
@@ -246,8 +385,9 @@ class RegularTestTuple(TestTuple):
         for test_args in RegularTestTuple.create_tests(
                 ['GL_ARB_vertex_attrib_64bit', '410'],
                 RegularTestTuple.create_in_types_array(
-                    itertools.chain(DSCALAR_TYPES, DVEC_TYPES, DMAT_TYPES),
-                    itertools.chain(DSCALAR_TYPES, DVEC_TYPES, DMAT_TYPES)),
+                    itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES),
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
+                ['int', 'double'],
                 [1, 2, 3],
                 [[1, 1], [1, 2], [3, 1], [3, 2]],
                 names_only):
@@ -255,15 +395,38 @@ class RegularTestTuple(TestTuple):
         for test_args in RegularTestTuple.create_tests(
                 ['GL_ARB_vertex_attrib_64bit', '410'],
                 RegularTestTuple.create_in_types_array(
-                    itertools.chain(DSCALAR_TYPES, DVEC_TYPES, DMAT_TYPES)),
+                    itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES),
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
+                ['uint', 'double'],
+                [1, 2, 3],
+                [[1, 1], [1, 2], [3, 1], [3, 2]],
+                names_only):
+            yield RegularTestTuple(*test_args)
+        for test_args in RegularTestTuple.create_tests(
+                ['GL_ARB_vertex_attrib_64bit', '410'],
+                RegularTestTuple.create_in_types_array(
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
+                ['double', 'double'],
+                [1, 2, 3],
+                [[1, 1], [1, 2], [3, 1], [3, 2]],
+                names_only):
+            yield RegularTestTuple(*test_args)
+        for test_args in RegularTestTuple.create_tests(
+                ['GL_ARB_vertex_attrib_64bit', '410'],
+                RegularTestTuple.create_in_types_array(
+                    itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
+                ['double'],
                 [1, 2],
                 [[1], [5]],
                 names_only):
             yield RegularTestTuple(*test_args)
 
-    def __init__(self, ver, in_types, position_order, arrays, num_vs_in, names_only):
+    def __init__(self, ver, in_types, gl_types, position_order, arrays, num_vs_in, names_only):
         assert ver in ('GL_ARB_vertex_attrib_64bit', '410', '420')
         assert isinstance(in_types, tuple)
+        assert isinstance(gl_types, list)
+        assert len(gl_types) == len(in_types)
         assert isinstance(position_order, int)
         assert (position_order > 0) and (position_order - 1 <= len(in_types))
         assert isinstance(arrays, list)
@@ -271,6 +434,7 @@ class RegularTestTuple(TestTuple):
         super(RegularTestTuple, self).__init__(ver, names_only)
 
         self._in_types = in_types
+        self._gl_types = gl_types
         self._position_order = position_order
         self._arrays = arrays
         self._num_vs_in = num_vs_in
@@ -282,8 +446,8 @@ class RegularTestTuple(TestTuple):
         for idx, in_type in enumerate(self._in_types):
             if idx == self._position_order - 1:
                 filename += '-position'
-            filename += '-{}{}'.format(
-                in_type, '-array{}'.format(
+            filename += '-{}_{}{}'.format(
+                self._gl_types[idx], in_type, '_array{}'.format(
                     self._arrays[idx]) if self._arrays[idx] - 1 else '')
         if self._position_order > len(self._in_types):
             filename += '-position'
@@ -295,11 +459,12 @@ class RegularTestTuple(TestTuple):
                     'regular.shader_test.mako').render_unicode(
                         ver=self._ver,
                         in_types=self._in_types,
+                        gl_types=self._gl_types,
                         position_order=self._position_order,
                         arrays=self._arrays,
                         num_vs_in=self._num_vs_in,
-                        dvalues=DOUBLE_NORMAL_VALUES + DOUBLE_POS_ZERO,
-                        hvalues=HEX_VALUES_32BIT))
+                        gl_types_values=GL_TYPES_VALUES))
+
         print(filename)
 
 
@@ -319,7 +484,7 @@ class ColumnsTestTuple(TestTuple):
             for ver in glsl_vers:
                 utils.safe_makedirs(TestTuple.get_dir_name(ver))
 
-        for mat in DMAT_TYPES:
+        for mat in GLSL_DMAT_TYPES:
             for columns in itertools.product(range(2), repeat=TestTuple.cols(mat)):
                 if (0 not in columns) or (1 not in columns):
                     continue
@@ -350,7 +515,8 @@ class ColumnsTestTuple(TestTuple):
                         ver=self._ver,
                         mat=self._mat,
                         columns=self._columns,
-                        dvalues=DOUBLE_NORMAL_VALUES + DOUBLE_POS_ZERO))
+                        dvalues=GL_TYPES_VALUES['double']))
+
         print(filename)
 
 
diff --git a/generated_tests/templates/gen_vs_in_fp64/columns.shader_test.mako b/generated_tests/templates/gen_vs_in_fp64/columns.shader_test.mako
index 0da2678..6b159d6 100644
--- a/generated_tests/templates/gen_vs_in_fp64/columns.shader_test.mako
+++ b/generated_tests/templates/gen_vs_in_fp64/columns.shader_test.mako
@@ -33,19 +33,19 @@
       return (glsl_version, glsl_version_int)
 
 
-  def cols(in_type):
-      if 'mat' in in_type:
-          if 'x' in in_type:
-              return int(in_type[-3:][:1])
+  def cols(glsl_type):
+      if 'mat' in glsl_type:
+          if 'x' in glsl_type:
+              return int(glsl_type[-3:][:1])
           else:
-              return int(in_type[-1:])
+              return int(glsl_type[-1:])
       else:
           return 1
 
 
-  def rows(in_type):
-      if 'vec' in in_type or 'mat' in in_type:
-          return int(in_type[-1:])
+  def rows(glsl_type):
+      if 'vec' in glsl_type or 'mat' in glsl_type:
+          return int(glsl_type[-1:])
       else:
           return 1
 
@@ -102,9 +102,9 @@ void main()
 }
 
 [vertex data]
-piglit_vertex/vec3/3\
+piglit_vertex/float/vec3\
   % for i in range(cols(mat)):
-   value/${mat}/${rows(mat)}${'/{}'.format(i) if cols(mat) > 1 else ''}\
+   value/double/${mat}${'/{}'.format(i) if cols(mat) > 1 else ''}\
   % endfor
 
 % for d in range(len(dvalues)):
diff --git a/generated_tests/templates/gen_vs_in_fp64/regular.shader_test.mako b/generated_tests/templates/gen_vs_in_fp64/regular.shader_test.mako
index b727b5e..9d85a6f 100644
--- a/generated_tests/templates/gen_vs_in_fp64/regular.shader_test.mako
+++ b/generated_tests/templates/gen_vs_in_fp64/regular.shader_test.mako
@@ -33,19 +33,19 @@
       return (glsl_version, glsl_version_int)
 
 
-  def cols(in_type):
-      if 'mat' in in_type:
-          if 'x' in in_type:
-              return int(in_type[-3:][:1])
+  def cols(glsl_type):
+      if 'mat' in glsl_type:
+          if 'x' in glsl_type:
+              return int(glsl_type[-3:][:1])
           else:
-              return int(in_type[-1:])
+              return int(glsl_type[-1:])
       else:
           return 1
 
 
-  def rows(in_type):
-      if 'vec' in in_type or 'mat' in in_type:
-          return int(in_type[-1:])
+  def rows(glsl_type):
+      if 'vec' in glsl_type or 'mat' in glsl_type:
+          return int(glsl_type[-1:])
       else:
           return 1
 
@@ -106,19 +106,19 @@ void main()
 [vertex data]
 % for idx, in_type in enumerate(in_types):
   % if idx == position_order - 1:
-    piglit_vertex/vec3/3 \
+    piglit_vertex/float/vec3 \
   % endif
   % for i in range(arrays[idx]):
     % for j in range(cols(in_type)):
-    value${idx}${'[{}]'.format(i) if arrays[idx] > 1 else ''}/${in_type}/${rows(in_type)}${'/{}'.format(j) if cols(in_type) > 1 else ''} \
+    value${idx}${'[{}]'.format(i) if arrays[idx] > 1 else ''}/${gl_types[idx]}/${in_type}${'/{}'.format(j) if cols(in_type) > 1 else ''} \
     % endfor
   % endfor
 % endfor
 % if position_order > len(in_types):
-  piglit_vertex/vec3/3\
+  piglit_vertex/float/vec3\
 % endif
 
-% for d in range(len(dvalues)):
+% for d in range(len(gl_types_values['double'])):
   % for vertex in ('-1.0 -1.0  0.0', ' 1.0 -1.0  0.0', ' 1.0  1.0  0.0', '-1.0  1.0  0.0'):
     % for idx, in_type in enumerate(in_types):
       % if idx == position_order - 1:
@@ -127,7 +127,7 @@ void main()
       % for i in range(arrays[idx]):
         % for j in range(cols(in_type)):
           % for k in range(rows(in_type)):
-            ${dvalues[(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(dvalues)] if in_type.startswith('d') else hvalues[(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(hvalues)]}  \
+            ${gl_types_values[gl_types[idx]][(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(gl_types_values[gl_types[idx]])]}  \
           % endfor
          \
         % endfor
@@ -141,14 +141,15 @@ void main()
 % endfor
 
 [test]
-% for d in range(len(dvalues)):
+% for d in range(len(gl_types_values['double'])):
 
   % for idx, in_type in enumerate(in_types):
     % for i in range(arrays[idx]):
       uniform ${in_type} expected${idx}${'[{}]'.format(i) if arrays[idx] > 1 else ''}\
       % for j in range(cols(in_type)):
         % for k in range(rows(in_type)):
-         ${dvalues[(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(dvalues)] if in_type.startswith('d') else hvalues[(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(hvalues)]}\
+	  ## Careful: these are the values for the VBO type, not the uniform type. If we use the hex format they should match or the run will fail.
+          ${gl_types_values[gl_types[idx]][(d + (i * cols(in_type) + j) * rows(in_type) + k) % len(gl_types_values[gl_types[idx]])]}\
         % endfor
       % endfor
 
diff --git a/tests/util/piglit-dispatch.h b/tests/util/piglit-dispatch.h
index cca7d59..f28ce4d 100644
--- a/tests/util/piglit-dispatch.h
+++ b/tests/util/piglit-dispatch.h
@@ -92,6 +92,7 @@ typedef short GLshort;
 typedef unsigned char GLubyte;
 typedef unsigned short GLushort;
 typedef unsigned long GLulong;
+typedef unsigned short GLhalf;
 typedef float GLfloat;
 typedef float GLclampf;
 typedef double GLdouble;
diff --git a/tests/util/piglit-vbo.cpp b/tests/util/piglit-vbo.cpp
index 274779f..6744b1e 100644
--- a/tests/util/piglit-vbo.cpp
+++ b/tests/util/piglit-vbo.cpp
@@ -28,7 +28,7 @@
  * tests using a columnar text format, for example:
  *
  *   \verbatim
- *   vertex/vec3/3	foo/uint/1	bar[0]/int/1	bar[1]/int/1
+ *   vertex/double/vec3	foo/uint/uint	bar[0]/int/int	bar[1]/int/int
  *   0.0 0.0 0.0	10		0		0	# comment
  *   0.0 1.0 0.0	 5		1		1
  *   1.0 1.0 0.0	 0		0		1
@@ -36,22 +36,21 @@
  *
  * The format consists of a row of column headers followed by any
  * number of rows of data.  Each column header has the form
- * "ATTRNAME[ARRAY_INDEX]/TYPE/COUNT/MATRIX_COLUMN", where ATTRNAME is
- * the name of the vertex attribute to be bound to this column,
- * ARRAY_INDEX is the index, TYPE is the GLSL type of data that
- * follows ("float", "double", "int", "uint" or any derived type like
- * vec2, dmat4, etc.), COUNT is the vector length of the data
- * (e.g. "3" for vec3 data or "2" for mat4x2) and MATRIX_COLUMN is the
- * column number of the data in case of being a matrix. [ARRAY_INDEX]
- * is optional and needs to be specified only in case of array
- * attributes. COUNT is a redundant value that is already specified in
- * the data type but that has been kept for backward
- * compatibility. MATRIX_COLUMN doesn't need to be specified if it is
- * not a matrix column as in the example before. So another example,
- * if you want to specify the data of a mat2x3:
+ * "ATTRNAME[ARRAY_INDEX]/GL_TYPE/GLSL_TYPE/MATRIX_COLUMN", where
+ * ATTRNAME is the name of the vertex attribute to be bound to this
+ * column, ARRAY_INDEX is the index, GL_TYPE is the GL type of data
+ * that follows ("half", "float", "double", "byte", "ubyte", "short",
+ * "ushort", "int" or "uint"), GLSL_TYPE is the GLSL type of the data
+ * ("int", "uint", "float", "double", "ivec"*, "uvec"*, "vec"*,
+ * "dvec"*, "mat"*, "dmat"*) and MATRIX_COLUMN is the column number of
+ * the data in case of being a matrix. [ARRAY_INDEX] is optional and
+ * needs to be specified only in case of array
+ * attributes. MATRIX_COLUMN doesn't need to be specified if it is not
+ * a matrix column as in the example before. So another example, if
+ * you want to specify the data of a mat2x3:
  *
  *   \verbatim
- *   foomatrix/mat2x3/3/0	foomatrix/mat2x3/3/1
+ *   foomatrix/float/mat2x3/0	foomatrix/float/mat2x3/1
  *   0.0 1.0 2.0		3.0 4.0 5.0
  *   6.0 7.0 8.0		9.0 10.0 11.0
  *   \endverbatim
@@ -130,76 +129,136 @@
 #include <string>
 #include <vector>
 #include <errno.h>
+#include <limits.h>
 #include <ctype.h>
 
 #include "piglit-util.h"
 #include "piglit-util-gl.h"
 #include "piglit-vbo.h"
 
+
 /**
- * Currently all the attribute types we support (int, uint, and float)
- * are 4 bytes in width.
+ * Convert a type name string to a GLenum.
  */
-const int ATTRIBUTE_SIZE = 4;
+static bool
+decode_type(const char *type,
+	    GLenum *gl_type, size_t *gl_type_size, GLenum *glsl_type)
+{
+	assert(type);
+	assert(gl_type);
+	assert(gl_type_size);
+
+	static struct type_table_entry {
+		const char *type; /* NULL means end of table */
+		GLenum gl_type;
+		size_t gl_type_size;
+		GLenum glsl_type;
+	} const type_table[] = {
+		{ "byte",    GL_BYTE,		1,	GL_INT		},
+		{ "ubyte",   GL_UNSIGNED_BYTE,	1,	GL_UNSIGNED_INT	},
+		{ "short",   GL_SHORT,		2,	GL_INT		},
+		{ "ushort",  GL_UNSIGNED_SHORT,	2,	GL_UNSIGNED_INT	},
+		{ "int",     GL_INT,		4,	GL_INT		},
+		{ "uint",    GL_UNSIGNED_INT,	4,	GL_UNSIGNED_INT	},
+		{ "half",    GL_HALF_FLOAT,	2,	GL_FLOAT	},
+		{ "float",   GL_FLOAT,		4,	GL_FLOAT	},
+		{ "double",  GL_DOUBLE,		8,	GL_DOUBLE	},
+		{ NULL,      0,			0,	0		},
+	};
+
+
+	for (int i = 0; type_table[i].type; ++i) {
+		if (0 == strcmp(type, type_table[i].type)) {
+			*gl_type = type_table[i].gl_type;
+			*gl_type_size = type_table[i].gl_type_size;
+			if (glsl_type)
+				*glsl_type = type_table[i].glsl_type;
+			return true;
+		}
+	}
+
+	return false;
+}
 
 
 /**
- * Convert a type name string to a GLenum.
+ * Convert a GLSL type name string to its basic GLenum type.
  */
-GLenum
-decode_type(const char *type, size_t *rows, size_t *cols)
+static bool
+decode_glsl_type(const char *type,
+		 GLenum *glsl_type, size_t *rows, size_t *cols, char **endptr)
 {
+	assert(glsl_type);
+	assert(rows);
+	assert(cols);
+	assert(endptr);
+
+	if (isdigit(type[0])) {
+		*rows = strtoul(type, endptr, 10);
+		*cols = 1;
+		*glsl_type = 0;
+		return true;
+	}
+
 	static struct type_table_entry {
 		const char *type; /* NULL means end of table */
-		GLenum enum_value;
+		GLenum glsl_type;
 	} const type_table[] = {
-		{ "int",     GL_INT            },
-		{ "uint",    GL_UNSIGNED_INT   },
-		{ "float",   GL_FLOAT          },
-		{ "double",  GL_DOUBLE         },
-		{ "ivec",    GL_INT            },
-		{ "uvec",    GL_UNSIGNED_INT   },
-		{ "vec",     GL_FLOAT          },
-		{ "dvec",    GL_DOUBLE         },
-		{ "mat",     GL_FLOAT          },
-		{ "dmat",    GL_DOUBLE         },
-		{ NULL,      0                 }
+		{ "int",	GL_INT		},
+		{ "uint",	GL_UNSIGNED_INT	},
+		{ "float",	GL_FLOAT	},
+		{ "double",	GL_DOUBLE	},
+		{ "ivec",	GL_INT		},
+		{ "uvec",	GL_UNSIGNED_INT	},
+		{ "vec",	GL_FLOAT	},
+		{ "dvec",	GL_DOUBLE	},
+		{ "mat",	GL_FLOAT	},
+		{ "dmat",	GL_DOUBLE	},
+		{ NULL,		0		}
 	};
 
-
 	for (int i = 0; type_table[i].type; ++i) {
-		if (0 == strncmp(type, type_table[i].type, strlen(type_table[i].type))) {
+		const size_t type_len = strlen(type_table[i].type);
+		if (0 == strncmp(type, type_table[i].type, type_len)) {
+			*endptr = const_cast<char *>(&type[type_len]);
+
 			/* In case of vectors or matrices, let's
-			 * calculate rows and columns, if needed.
+			 * calculate rows and columns.
 			 */
-			if (i > 3 && (rows || cols)) {
-				size_t type_len = strlen(type);
-				size_t the_rows = type[type_len - 1] - '0';
-				if (rows)
-					*rows = the_rows;
-				if (cols) {
-					/* In case of matrices, let's
-					 * calculate the columns.
-					 */
-					if (i > 7)
-						*cols = type[type_len - 2] == 'x' ?
-							type[type_len - 3] - '0' : the_rows;
-					else
-						*cols = 1;
+			if (i > 3) {
+				if (!isdigit(**endptr))
+					goto cleanup;
+				*rows = **endptr - '0';
+				++*endptr;
+
+				/* In case of matrices, let's
+				 * calculate the rows.
+				 */
+				if (i > 7) {
+					*cols = *rows;
+				        if (**endptr == 'x') {
+						if (!isdigit(*(++*endptr)))
+							goto cleanup;
+						*rows = **endptr - '0';
+						++*endptr;
+					}
+				} else {
+					*cols = 1;
 				}
 			} else {
-				if (rows)
-					*rows = 1;
-				if (cols)
-					*cols = 1;
+				*rows = 1;
+				*cols = 1;
 			}
-			return type_table[i].enum_value;
+			*glsl_type = type_table[i].glsl_type;
+			return true;
 		}
 	}
 
-	printf("Unrecognized type: %s\n", type);
-	piglit_report_result(PIGLIT_FAIL);
-	return 0;
+cleanup:
+
+	*glsl_type = 0;
+	*endptr = const_cast<char *>(type);
+	return false;
 }
 
 
@@ -214,29 +273,39 @@ public:
 	void setup(size_t *offset, size_t stride) const;
 
 	/**
-	 * Data type of this attribute.
+	 * GL data type of this attribute.
 	 */
 	GLenum data_type;
 
 	/**
-	 * Number of columns in the data type of this attribute.
+	 * Size of the GL data type of this attribute.
 	 */
-	size_t data_type_cols;
+	size_t data_type_size;
 
 	/**
-	 * Vector length of this attribute.
+	 * GLSL data type of this attribute.
 	 */
-	size_t count;
+	GLenum glsl_data_type;
 
 	/**
-	 * Index of the matrix column for this attribute.
+	 * Index of the array for this attribute.
 	 */
-	size_t matrix_index;
+	size_t array_index;
 
 	/**
-	 * Index of the array for this attribute.
+	 * Number of columns of the GLSL data type of this attribute.
 	 */
-	size_t array_index;
+	size_t cols;
+
+	/**
+	 * Number of rows of the GLSL data type of this attribute.
+	 */
+	size_t rows;
+
+	/**
+	 * Index of the matrix column for this attribute.
+	 */
+	size_t matrix_index;
 
 	/**
 	 * Index of this vertex attribute in the linked program.
@@ -248,7 +317,7 @@ public:
 /**
  * Build a vertex_attrib_description from a column header, by looking
  * up the vertex attribute in the linked program and interpreting the
- * type and count parts of the header.
+ * type, dimensions and mattrix_column parts of the header.
  *
  * If there is a parse failure, print a description of the problem and
  * then exit with PIGLIT_FAIL.
@@ -257,12 +326,12 @@ vertex_attrib_description::vertex_attrib_description(GLuint prog,
 						     const char *text)
 {
 	/* Split the column header into
-	 * name[array_index]/type/count/matrix_column fields.
+	 * name[array_index]/type/dimensions/matrix_column fields.
 	 */
 	const char *first_slash = strchr(text, '/');
 	if (first_slash == NULL) {
 		printf("Column headers must be in the form"
-		       " name[array_index]/type/count/matrix_column.\n"
+		       " name[array_index]/type/dimensions/matrix_column.\n"
 		       "Note: [array_index] and matrix_column are optional.\n"
 		       "Got: %s\n",
 		       text);
@@ -291,17 +360,32 @@ vertex_attrib_description::vertex_attrib_description(GLuint prog,
 	const char *second_slash = strchr(first_slash + 1, '/');
 	if (second_slash == NULL) {
 		printf("Column headers must be in the form"
-		       " name[array_index]/type/count/matrix_column.\n"
+		       " name[array_index]/type/dimensions/matrix_column.\n"
 		       "Note: [array_index] and matrix_column are optional.\n"
 		       "Got: %s\n",
 		       text);
 		piglit_report_result(PIGLIT_FAIL);
 	}
-	std::string type_str(first_slash + 1, second_slash);
-	this->data_type = decode_type(type_str.c_str(),
-				      &this->count, &this->data_type_cols);
+
 	char *endptr;
-	this->count = strtoul(second_slash + 1, &endptr, 10);
+	if (!decode_glsl_type(second_slash + 1,
+			      &this->glsl_data_type,
+			      &this->rows, &this->cols,
+			      &endptr)) {
+		printf("Unrecognized GLSL type: %s\n", second_slash + 1);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	std::string type_str(first_slash + 1, second_slash);
+	GLenum *glsl_data_type = this->glsl_data_type ? 0
+		: &this->glsl_data_type;
+
+	if (!decode_type(type_str.c_str(),
+			 &this->data_type, &this->data_type_size,
+			 glsl_data_type)) {
+		printf("Unrecognized GL type: %s\n", type_str.c_str());
+		piglit_report_result(PIGLIT_FAIL);
+	}
 
 	if (*endptr != '\0') {
 		const char *third_slash = strchr(second_slash + 1, '/');
@@ -315,7 +399,7 @@ vertex_attrib_description::vertex_attrib_description(GLuint prog,
 
 		if (*endptr != '\0') {
 			printf("Column headers must be in the form"
-			       " name[array_index]/type/count/matrix_column.\n"
+			       " name[array_index]/type/dimensions/matrix_column.\n"
 			       "Note: [array_index] and matrix_column are optional.\n"
 			       "Got: %s\n",
 			       text);
@@ -338,7 +422,7 @@ vertex_attrib_description::vertex_attrib_description(GLuint prog,
 	 * (b) skip itself if integer vertex attribute support is not
 	 * present.
 	 */
-	if (this->data_type != GL_FLOAT &&
+	if (this->glsl_data_type != GL_FLOAT &&
 	    (piglit_is_gles() ||
 	    (piglit_get_gl_version() < 30 &&
 		!piglit_is_extension_supported("GL_EXT_gpu_shader4")))) {
@@ -347,8 +431,15 @@ vertex_attrib_description::vertex_attrib_description(GLuint prog,
 		piglit_report_result(PIGLIT_FAIL);
 	}
 
-	if (this->count < 1 || this->count > 4) {
-		printf("Count must be between 1 and 4.  Got: %lu\n", (unsigned long) count);
+	if (this->rows < 1 || this->rows > 4) {
+		printf("Rows must be between 1 and 4.  Got: %lu\n",
+		       (unsigned long) this->rows);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	if (this->cols < 1 || this->cols > 4) {
+		printf("Columns must be between 1 and 4.  Got: %lu\n",
+		       (unsigned long) this->cols);
 		piglit_report_result(PIGLIT_FAIL);
 	}
 }
@@ -368,6 +459,15 @@ vertex_attrib_description::parse_datum(const char **text, void *data) const
 	char *endptr;
 	errno = 0;
 	switch (this->data_type) {
+	case GL_HALF_FLOAT: {
+		unsigned short value = strtohf_hex(*text, &endptr);
+		if (errno == ERANGE) {
+			printf("Could not parse as half float\n");
+			return false;
+		}
+		*((GLhalf *) data) = value;
+		break;
+	}
 	case GL_FLOAT: {
 		float value = strtof_hex(*text, &endptr);
 		if (errno == ERANGE) {
@@ -386,6 +486,42 @@ vertex_attrib_description::parse_datum(const char **text, void *data) const
 		*((GLdouble *) data) = value;
 		break;
 	}
+	case GL_BYTE: {
+		long value = strtol_hex(*text, &endptr);
+		if (errno == ERANGE || value < SCHAR_MIN || value > SCHAR_MAX) {
+			printf("Could not parse as signed byte\n");
+			return false;
+		}
+		*((GLbyte *) data) = (GLbyte) value;
+		break;
+	}
+	case GL_UNSIGNED_BYTE: {
+		unsigned long value = strtoul(*text, &endptr, 0);
+		if (errno == ERANGE || value > UCHAR_MAX) {
+			printf("Could not parse as unsigned byte\n");
+			return false;
+		}
+		*((GLubyte *) data) = (GLubyte) value;
+		break;
+	}
+	case GL_SHORT: {
+		long value = strtol_hex(*text, &endptr);
+		if (errno == ERANGE || value < SHRT_MIN || value > SHRT_MAX) {
+			printf("Could not parse as signed short\n");
+			return false;
+		}
+		*((GLshort *) data) = (GLshort) value;
+		break;
+	}
+	case GL_UNSIGNED_SHORT: {
+		unsigned long value = strtoul(*text, &endptr, 0);
+		if (errno == ERANGE || value > USHRT_MAX) {
+			printf("Could not parse as unsigned short\n");
+			return false;
+		}
+		*((GLushort *) data) = (GLushort) value;
+		break;
+	}
 	case GL_INT: {
 		long value = strtol_hex(*text, &endptr);
 		if (errno == ERANGE) {
@@ -420,37 +556,56 @@ vertex_attrib_description::parse_datum(const char **text, void *data) const
 void
 vertex_attrib_description::setup(size_t *offset, size_t stride) const
 {
-	int attribute_size = ATTRIBUTE_SIZE;
 	GLuint actual_index = this->index + this->matrix_index
-		+ this->array_index * this->data_type_cols;
-	switch (this->data_type) {
+		+ this->array_index * this->cols;
+	switch (this->glsl_data_type) {
 	case GL_FLOAT:
-		glVertexAttribPointer(actual_index, this->count,
+		glVertexAttribPointer(actual_index, this->rows,
 				      this->data_type, GL_FALSE, stride,
 				      (void *) *offset);
 		break;
 	case GL_DOUBLE:
-		if (!piglit_is_extension_supported("GL_ARB_vertex_attrib_64bit")) {
+		if (piglit_is_gles()
+		    || !piglit_is_extension_supported("GL_ARB_vertex_attrib_64bit")) {
 			fprintf(stderr,"vertex_attrib_description fail. no 64-bit float support\n");
 			return;
 		}
-		glVertexAttribLPointer(actual_index, this->count,
+		if (this->data_type != GL_DOUBLE) {
+			fprintf(stderr,"vertex_attrib_description fail. the GL"
+				" type must be 'GL_DOUBLE' and it is '%s'\n",
+				piglit_get_prim_name(this->data_type));
+			return;
+		}
+		glVertexAttribLPointer(actual_index, this->rows,
 				       this->data_type, stride,
 				       (void *) *offset);
-		attribute_size *= 2;
 		break;
 	default:
 		if (piglit_is_gles() && piglit_get_gl_version() < 30) {
 			fprintf(stderr,"vertex_attrib_description fail. no int support\n");
 			return;
 		}
-		glVertexAttribIPointer(actual_index, this->count,
+		switch (this->data_type) {
+		case GL_BYTE:
+		case GL_UNSIGNED_BYTE:
+		case GL_SHORT:
+		case GL_UNSIGNED_SHORT:
+		case GL_INT:
+		case GL_UNSIGNED_INT:
+			break;
+		default:
+			fprintf(stderr,"vertex_attrib_description fail. the GL"
+				" type '%s' is incompatible\n",
+				piglit_get_prim_name(this->data_type));
+			return;
+		}
+		glVertexAttribIPointer(actual_index, this->rows,
 				       this->data_type, stride,
 				       (void *) *offset);
 		break;
 	}
 	glEnableVertexAttribArray(actual_index);
-	*offset += attribute_size * this->count;
+	*offset += this->rows * this->data_type_size;
 }
 
 
@@ -526,7 +681,6 @@ vbo_data::parse_header_line(const std::string &line, GLuint prog)
 			++pos;
 		} else {
 			size_t column_header_end = pos;
-			int mul;
 			while (column_header_end < line.size() &&
 			       !isspace(line[column_header_end]))
 				++column_header_end;
@@ -535,8 +689,7 @@ vbo_data::parse_header_line(const std::string &line, GLuint prog)
 			vertex_attrib_description desc(
 				prog, column_header.c_str());
 			attribs.push_back(desc);
-			mul = (desc.data_type == GL_DOUBLE) ? 2 : 1;
-			this->stride += ATTRIBUTE_SIZE * desc.count * mul;
+			this->stride += desc.rows * desc.data_type_size;
 			pos = column_header_end + 1;
 		}
 	}
@@ -559,8 +712,7 @@ vbo_data::parse_data_line(const std::string &line, unsigned int line_num)
 
 	const char *line_ptr = line.c_str();
 	for (size_t i = 0; i < this->attribs.size(); ++i) {
-		for (size_t j = 0; j < this->attribs[i].count; ++j) {
-			int mul = (this->attribs[i].data_type == GL_DOUBLE) ? 2 : 1;
+		for (size_t j = 0; j < this->attribs[i].rows; ++j) {
 			if (!this->attribs[i].parse_datum(&line_ptr,
 							  data_ptr)) {
 				printf("At line %u of [vertex data] section\n",
@@ -568,7 +720,7 @@ vbo_data::parse_data_line(const std::string &line, unsigned int line_num)
 				printf("Offending text: %s\n", line_ptr);
 				piglit_report_result(PIGLIT_FAIL);
 			}
-			data_ptr += ATTRIBUTE_SIZE * mul;
+			data_ptr += this->attribs[i].data_type_size;
 		}
 	}
 
-- 
2.8.1



More information about the Piglit mailing list