[Piglit] [PATCH 3/6] util: Generate piglit_get_gl_enum_name() and friends
Chad Versace
chad.versace at linux.intel.com
Mon Jun 16 09:04:59 PDT 2014
This patch removes the files piglit-util-gl*-enum.c and instead replaces
them with a single piglit-util-gl-enum-gen.c generated from the Khronos
XML.
The two functions now generated are:
piglit_get_gl_enum_name(GLenum param)
piglit_get_prim_name(GLenum prim)
Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
v2:
- Replace
| if cond: return stuff
with
| if cond:
| return stuff
- Still debating list comprehensions.
cmake/piglit_dispatch.cmake | 1 +
tests/util/.gitignore | 1 +
tests/util/CMakeLists.gl.txt | 3 +-
tests/util/CMakeLists.gles1.txt | 1 -
tests/util/CMakeLists.gles2.txt | 1 -
tests/util/CMakeLists.gles3.txt | 1 -
tests/util/CMakeLists.txt | 8 +
tests/util/gen_dispatch.py | 84 +
tests/util/piglit-util-gl-enum.c | 3046 -----------------------------------
tests/util/piglit-util-gles3-enum.c | 728 ---------
10 files changed, 95 insertions(+), 3779 deletions(-)
delete mode 100644 tests/util/piglit-util-gl-enum.c
delete mode 100644 tests/util/piglit-util-gles3-enum.c
diff --git a/cmake/piglit_dispatch.cmake b/cmake/piglit_dispatch.cmake
index b4ff2cf..2ef6a85 100644
--- a/cmake/piglit_dispatch.cmake
+++ b/cmake/piglit_dispatch.cmake
@@ -27,6 +27,7 @@ file(MAKE_DIRECTORY ${piglit_dispatch_gen_output_dir})
set(piglit_dispatch_gen_outputs
${piglit_dispatch_gen_output_dir}/generated_dispatch.c
${piglit_dispatch_gen_output_dir}/generated_dispatch.h
+ ${piglit_dispatch_gen_output_dir}/piglit-util-gl-enum-gen.c
)
set(piglit_dispatch_gen_inputs
diff --git a/tests/util/.gitignore b/tests/util/.gitignore
index 8fbd235..03b680d 100644
--- a/tests/util/.gitignore
+++ b/tests/util/.gitignore
@@ -1,3 +1,4 @@
config.h
generated_dispatch.c
generated_dispatch.h
+piglit-util-gl-enum-gen.c
diff --git a/tests/util/CMakeLists.gl.txt b/tests/util/CMakeLists.gl.txt
index 0a2cc25..d414dd9 100644
--- a/tests/util/CMakeLists.gl.txt
+++ b/tests/util/CMakeLists.gl.txt
@@ -5,7 +5,6 @@ set(UTIL_GL_SOURCES
piglit-matrix.c
piglit-shader.c
piglit-shader-gl.c
- piglit-util-gl-enum.c
piglit-util-gl.c
piglit-test-pattern.cpp
piglit-fbo.cpp
@@ -34,12 +33,12 @@ IF(PIGLIT_BUILD_GLX_TESTS)
piglit-shader.c
piglit-shader-gl.c
piglit-util-gl-common.c
- piglit-util-gl-enum.c
piglit-util-gl.c
piglit-glx-framework.c
piglit-glx-util.c
piglit-dispatch.c
piglit-dispatch-init.c
+ ${piglit_dispatch_gen_output_dir}/piglit-util-gl-enum-gen.c
)
target_link_libraries(piglitglxutil
piglitutil_${piglit_target_api}
diff --git a/tests/util/CMakeLists.gles1.txt b/tests/util/CMakeLists.gles1.txt
index 58cc67a..09dff85 100644
--- a/tests/util/CMakeLists.gles1.txt
+++ b/tests/util/CMakeLists.gles1.txt
@@ -1,6 +1,5 @@
set(UTIL_GL_SOURCES
${UTIL_GL_SOURCES}
- piglit-util-gl-enum.c
piglit-util-gles.c
)
diff --git a/tests/util/CMakeLists.gles2.txt b/tests/util/CMakeLists.gles2.txt
index d2501e3..a174112 100644
--- a/tests/util/CMakeLists.gles2.txt
+++ b/tests/util/CMakeLists.gles2.txt
@@ -5,7 +5,6 @@ set(UTIL_GL_SOURCES
piglit-dispatch-init.c
piglit-shader.c
piglit-shader-gles2.c
- piglit-util-gl-enum.c
piglit-util-gles.c
minmax-test.c
)
diff --git a/tests/util/CMakeLists.gles3.txt b/tests/util/CMakeLists.gles3.txt
index 1cb591f..59a4de7 100644
--- a/tests/util/CMakeLists.gles3.txt
+++ b/tests/util/CMakeLists.gles3.txt
@@ -5,7 +5,6 @@ list(APPEND UTIL_GL_SOURCES
piglit-shader.c
piglit-shader-gles2.c # Compatible with gles3.
piglit-util-gles.c
- piglit-util-gles3-enum.c
piglit-vbo.cpp
)
diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index 3a97daf..cf0aa6b 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -4,6 +4,13 @@ if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC AND HAVE_LIBRT)
link_libraries(rt)
endif()
+# CMake requires that source file properties be set in the same directory where
+# the property is used.
+set_source_files_properties(
+ ${piglit_dispatch_gen_outputs}
+ PROPERTIES GENERATED 1
+ )
+
set(UTIL_INCLUDES
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
@@ -28,6 +35,7 @@ set(UTIL_GL_SOURCES
piglit_ktx.c
rgb9e5.c
r11g11b10f.c
+ ${CMAKE_BINARY_DIR}/tests/util/piglit-util-gl-enum-gen.c
)
if(PIGLIT_USE_WAFFLE)
diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
index d445932..9b559cd 100644
--- a/tests/util/gen_dispatch.py
+++ b/tests/util/gen_dispatch.py
@@ -63,6 +63,10 @@ def main():
dispatch_h.close()
dispatch_c.close()
+ enum_c = open(os.path.join(args.out_dir, 'piglit-util-gl-enum-gen.c'), 'w')
+ EnumCode(gl_registry).emit(enum_c)
+ enum_c.close()
+
def log_debug(msg):
if debug:
sys.stderr.write('debug: {0}: {1}\n'.format(PROG_NAME, msg))
@@ -304,5 +308,85 @@ class DispatchCode(object):
)
template.render_context(ctx)
+class EnumCode(object):
+
+ c_template = Template(dedent('''\
+ ${copyright}
+
+ #include "piglit-util-gl-common.h"
+
+ const char*
+ piglit_get_gl_enum_name(GLenum param)
+ {
+ switch (param) {
+ % for enum in unique_default_namespace_enums:
+ case ${enum.c_num_literal}: return "${enum.name}";
+ % endfor
+ default: return "(unrecognized enum)";
+ }
+ }
+
+ const char*
+ piglit_get_prim_name(GLenum prim)
+ {
+ <% gl_patches = gl_registry.enums['GL_PATCHES'] %>\\
+ switch (prim) {
+ % for enum in unique_default_namespace_enums:
+ % if enum.num_value <= gl_patches.num_value:
+ case ${enum.c_num_literal}: return "${enum.name}";
+ % endif
+ % endfor
+ default: return "(unrecognized enum)";
+ }
+ }'''
+ ))
+
+ def __init__(self, gl_registry):
+ self.gl_registry = gl_registry
+ self.unique_default_namespace_enums = None
+ self.__gather_unique_default_namespace_enums()
+
+ def __gather_unique_default_namespace_enums(self):
+ duplicate_enums = [
+ enum
+ for enum_group in self.gl_registry.enum_groups
+ if enum_group.type == 'default_namespace'
+ for enum in enum_group.enums
+ if not enum.is_collider
+ ]
+
+ # Sort enums by numerical value then by name. This ensures that
+ # non-suffixed variants of an enum name precede the suffixed variant.
+ # For example, GL_RED will precede GL_RED_EXT.
+ def enum_cmp(x, y):
+ c = cmp(x.num_value, y.num_value)
+ if c != 0:
+ return c
+ c = cmp(x.name, y.name)
+ if c != 0:
+ return c
+ return 0
+
+ duplicate_enums.sort(enum_cmp)
+
+ # Copy duplicate_enums into unique_enums, filtering out duplicate
+ # values. The algorithm requires that dupliate_enums be sorted by
+ # value.
+ unique_enums = [duplicate_enums[0]]
+ for enum in duplicate_enums[1:]:
+ if enum.num_value > unique_enums[-1].num_value:
+ unique_enums.append(enum)
+
+ self.unique_default_namespace_enums = unique_enums
+
+ def emit(self, c_buf):
+ ctx = mako.runtime.Context(
+ buffer=c_buf,
+ copyright=copyright_block,
+ gl_registry=self.gl_registry,
+ unique_default_namespace_enums=self.unique_default_namespace_enums,
+ )
+ EnumCode.c_template.render_context(ctx)
+
if __name__ == '__main__':
main()
diff --git a/tests/util/piglit-util-gl-enum.c b/tests/util/piglit-util-gl-enum.c
deleted file mode 100644
index 8deb58f..0000000
diff --git a/tests/util/piglit-util-gles3-enum.c b/tests/util/piglit-util-gles3-enum.c
deleted file mode 100644
index 8b0fcdc..0000000
--
2.0.0.rc1
More information about the Piglit
mailing list