[Piglit] [PATCH 08/14] glapi: Add dispatch generation support for GLES APIs.

Eric Anholt eric at anholt.net
Wed Jun 5 16:14:25 PDT 2013


There's no incoming data yet to trigger this code, though.
---
 glapi/parse_glspec.py        | 30 ++++++++++++++++++++++++------
 tests/util/gen_dispatch.py   | 38 ++++++++++++++++++++++++++------------
 tests/util/piglit-dispatch.c |  4 +++-
 3 files changed, 53 insertions(+), 19 deletions(-)

diff --git a/glapi/parse_glspec.py b/glapi/parse_glspec.py
index 5b05e43..ef6143c 100644
--- a/glapi/parse_glspec.py
+++ b/glapi/parse_glspec.py
@@ -91,7 +91,7 @@
 # {
 #   "categories": {
 #     <category name>: {
-#       "kind": <"GL" for a GL version, "extension" for an extension>,
+#       "kind": <"GL" or "GLES" for a GL version, "extension" for an extension>,
 #       "gl_10x_version": <For a GL version, version number times 10>,
 #       "extension_name" <For an extension, name of the extension>
 #     }, ...
@@ -127,6 +127,7 @@ import sys
 GLSPEC_HEADER_REGEXP = re.compile(r'^(\w+)\((.*)\)$')
 GLSPEC_ATTRIBUTE_REGEXP = re.compile(r'^\s+(\w+)\s+(.*)$')
 GL_VERSION_REGEXP = re.compile('^VERSION_([0-9])_([0-9])(_DEPRECATED)?$')
+GLES_VERSION_REGEXP = re.compile('^GL_ES_VERSION_([0-9])_([0-9])(_DEPRECATED)?$')
 ENUM_REGEXP = re.compile(r'^\s+(\w+)\s+=\s+(\w+)$')
 
 
@@ -181,6 +182,9 @@ def filter_comments(f):
 # - "GL_VERSION_2_1" is converted into { 'kind': 'GL', 'gl_10x_version': 21 }
 #
 # - "ARB_foo" is converted into { 'kind': 'extension', 'extension_name': 'GL_ARB_foo' }
+#
+# - "GL_ES_VERSION_2_0" is converted into { 'kind': 'GLES', 'gl_10x_version': 20 }
+#   (this category is a piglit extension for local-gl.spec)
 def translate_category(category_name):
     m = GL_VERSION_REGEXP.match(category_name)
     if m:
@@ -190,13 +194,22 @@ def translate_category(category_name):
             'kind': 'GL',
             'gl_10x_version': 10 * ones + tenths
             }
-    else:
-        extension_name = 'GL_' + category_name
-        return extension_name, {
-            'kind': 'extension',
-            'extension_name': extension_name
+
+    m = GLES_VERSION_REGEXP.match(category_name)
+    if m:
+        ones = int(m.group(1))
+        tenths = int(m.group(2))
+        return 'GLES{0}.{1}'.format(ones, tenths), {
+            'kind': 'GLES',
+            'gl_10x_version': 10 * ones + tenths
             }
 
+    extension_name = 'GL_' + category_name
+    return extension_name, {
+        'kind': 'extension',
+        'extension_name': extension_name
+        }
+
 
 # Data structure keeping track of which function names are known, and
 # which names are synonymous with which other names.
@@ -277,6 +290,11 @@ class Api(object):
         #
         # '2.1': { 'kind': 'GL', 'gl_10x_version': 21 }
         #
+        # For categories representing a GLES version, the dict entry looks
+        # like this:
+        #
+        # 'GLES2.0': { 'kind': 'GLES', 'gl_10x_version': 20 }
+        #
         # For categories representing an extension, the dict entry
         # looks like this:
         #
diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
index 3a4179f..807f0f8 100644
--- a/tests/util/gen_dispatch.py
+++ b/tests/util/gen_dispatch.py
@@ -32,7 +32,7 @@
 # {
 #   "categories": {
 #     <category name>: {
-#       "kind": <"GL" for a GL version, "extension" for an extension>,
+#       "kind": <"GL" or "GLES" for a GL spec API, "extension" for an extension>,
 #       "gl_10x_version": <For a GL version, version number times 10>,
 #       "extension_name" <For an extension, name of the extension>
 #     }, ...
@@ -216,6 +216,9 @@ class Category(object):
         if self.kind == 'GL':
             return 'GL {0}.{1}'.format(
                 self.gl_10x_version // 10, self.gl_10x_version % 10)
+        if self.kind == 'GLES':
+            return 'GLES {0}.{1}'.format(
+                self.gl_10x_version // 10, self.gl_10x_version % 10)
         elif self.kind == 'extension':
             return self.extension_name
         else:
@@ -300,7 +303,7 @@ class Enum(object):
 #
 # - DispatchSet.cat_fn_pairs is a list of pairs (category, function)
 #   for each category this function is defined in.  The list is sorted
-#   by category, with categories of kind 'GL' appearing first.
+#   by category, with categories of kind 'GL' and then 'GLES' appearing first.
 class DispatchSet(object):
     # Initialize a dispatch set given a list of synonymous function
     # names.
@@ -349,8 +352,10 @@ class DispatchSet(object):
     def __sort_key(cat_fn_pair):
         if cat_fn_pair[0].kind == 'GL':
             return 0, cat_fn_pair[0].gl_10x_version
+        elif cat_fn_pair[0].kind == 'GLES':
+            return 1, cat_fn_pair[0].gl_10x_version
         elif cat_fn_pair[0].kind == 'extension':
-            return 1, cat_fn_pair[0].extension_name
+            return 2, cat_fn_pair[0].extension_name
         else:
             raise Exception(
                 'Unexpected category kind {0!r}'.format(cat_fn_pair[0].kind))
@@ -439,20 +444,29 @@ def generate_resolve_function(ds):
     # execute in each case.
     condition_code_pairs = []
     for category, f in ds.cat_fn_pairs:
-        if category.kind == 'GL':
+        if category.kind in ('GL', 'GLES'):
             getter = 'get_core_proc("{0}", {1})'.format(
                 f.gl_name, category.gl_10x_version)
-            if category.gl_10x_version == 10:
-                # Function has always been available--no need to check
-                # a condition.
-                condition = 'true'
+
+            condition = ''
+            api_base_version = 0;
+            if category.kind == 'GL':
+                condition = 'dispatch_api == PIGLIT_DISPATCH_GL'
+                api_base_version = 10
+            elif category.gl_10x_version >= 20:
+                condition = 'dispatch_api == PIGLIT_DISPATCH_ES2'
+                api_base_version = 20
             else:
-                condition = 'check_version({0})'.format(
-                    category.gl_10x_version)
+                condition = 'dispatch_api == PIGLIT_DISPATCH_ES'
+                api_base_version = 11
+
+            # Only check the version for functions that aren't part of the
+            # core for the PIGLIT_DISPATCH api.
+            if category.gl_10x_version != api_base_version:
+                condition = condition + ' && check_version({0})'.format(category.gl_10x_version)
         elif category.kind == 'extension':
             getter = 'get_ext_proc("{0}")'.format(f.gl_name)
-            condition = 'check_extension("{0}")'.format(
-                category.extension_name)
+            condition = 'check_extension("{0}")'.format(category.extension_name)
         else:
             raise Exception(
                 'Unexpected category type {0!r}'.format(category.kind))
diff --git a/tests/util/piglit-dispatch.c b/tests/util/piglit-dispatch.c
index 3ce89f7..1e05134 100644
--- a/tests/util/piglit-dispatch.c
+++ b/tests/util/piglit-dispatch.c
@@ -73,6 +73,8 @@ static int gl_version = 0;
  */
 static bool is_initialized = false;
 
+static piglit_dispatch_api dispatch_api;
+
 /**
  * Generated code calls this function to verify that the dispatch
  * mechanism has been properly initialized.
@@ -207,7 +209,7 @@ piglit_dispatch_init(piglit_dispatch_api api,
 		     piglit_error_function_ptr unsupported_proc,
 		     piglit_error_function_ptr failure_proc)
 {
-	(void) api; /* Not yet implemented--assume GL. */
+	dispatch_api = api;
 
 	get_core_proc_address = get_core_proc;
 	get_ext_proc_address = get_ext_proc;
-- 
1.8.3.rc0



More information about the Piglit mailing list