Commit e31de330 authored by Chad Versace's avatar Chad Versace

util: Generate piglit_get_gl_enum_name() and friends

This patch removes the files "piglit-util-gl*-enum.c" and replaces them
with a single file "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: default avatarChad Versace <chad.versace@linux.intel.com>
parent 0caf33e1
......@@ -27,6 +27,7 @@ file(MAKE_DIRECTORY ${piglit_dispatch_gen_output_dir})
set(piglit_dispatch_gen_outputs
${piglit_dispatch_gen_output_dir}/piglit-dispatch-gen.c
${piglit_dispatch_gen_output_dir}/piglit-dispatch-gen.h
${piglit_dispatch_gen_output_dir}/piglit-util-gl-enum-gen.c
)
set(piglit_dispatch_gen_depends
......@@ -36,6 +37,7 @@ set(piglit_dispatch_gen_depends
${CMAKE_SOURCE_DIR}/tests/util/gen_dispatch.py
${CMAKE_SOURCE_DIR}/tests/util/piglit-dispatch-gen.c.mako
${CMAKE_SOURCE_DIR}/tests/util/piglit-dispatch-gen.h.mako
${CMAKE_SOURCE_DIR}/tests/util/piglit-util-gl-enum-gen.c.mako
)
add_custom_command(
......
config.h
piglit-dispatch-gen.[ch]
piglit-util-gl-enum-gen.c
......@@ -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}
......
set(UTIL_GL_SOURCES
${UTIL_GL_SOURCES}
piglit-util-gl-enum.c
piglit-util-gles.c
)
......
......@@ -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
)
......
......@@ -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
)
......
......@@ -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)
......
......@@ -27,6 +27,7 @@ Generate C source code from Khronos XML.
from __future__ import print_function
import argparse
import functools
import mako.runtime
import mako.template
import os.path
......@@ -40,7 +41,7 @@ PIGLIT_TOP_DIR = os.path.join(os.path.dirname(__file__), '..', '..')
sys.path.append(PIGLIT_TOP_DIR)
import registry.gl
from registry.gl import OrderedKeyedSet, ImmutableOrderedKeyedSet
from registry.gl import Extension, OrderedKeyedSet, ImmutableOrderedKeyedSet
debug = False
......@@ -65,6 +66,7 @@ def main():
gl_registry = registry.gl.parse()
DispatchCode.emit(args.out_dir, gl_registry)
EnumCode.emit(args.out_dir, gl_registry)
class DispatchCode(object):
......@@ -125,5 +127,75 @@ def render_template(filename, out_dir, **context_vars):
template.render_context(ctx)
class EnumCode(object):
C_TEMPLATE = 'piglit-util-gl-enum-gen.c.mako'
@classmethod
def emit(cls, out_dir, gl_registry):
assert(isinstance(gl_registry, registry.gl.Registry))
enums = cls.get_unique_enums_in_default_namespace(gl_registry)
render_template(
cls.C_TEMPLATE,
out_dir,
gl_registry=gl_registry,
sorted_unique_enums_in_default_namespace=enums)
@classmethod
def get_unique_enums_in_default_namespace(cls, gl_registry):
def cmp_enums(x, y):
# Sort enums by numerical value, then by vendor namespace, then by
# full name. Given a set of synonymous names for a given enum
# value, this sort order ensures that names provided by core
# specifications precede those provided by ratified extensions,
# which precede thos provided by unratified extensions.
#
# For example, GL_RED will precede GL_RED_EXT will precede
# GL_RED_INTEL.
#
c = cmp(x.num_value, y.num_value)
if c != 0:
return c
c = cmp(y.vendor_namespace is None,
x.vendor_namespace is None)
if c != 0:
return c
c = cmp(y.vendor_namespace in Extension.RATIFIED_NAMESPACES,
x.vendor_namespace in Extension.RATIFIED_NAMESPACES)
if c != 0:
return c
c = cmp(y.vendor_namespace == 'EXT',
x.vendor_namespace == 'EXT')
if c != 0:
return c
c = cmp(x.name, y.name)
if c != 0:
return c
return cmp(x.api, y.api)
def append_enum_if_new_value(enum_list, enum):
diff = cmp(enum_list[-1].num_value, enum.num_value)
assert(diff <= 0)
if diff < 0:
enum_list.append(enum)
return enum_list
enums = (
enum
for enum_group in gl_registry.enum_groups
if enum_group.type == 'default_namespace'
for enum in enum_group.enums
)
enums = sorted(enums, cmp=cmp_enums)
enums = reduce(append_enum_if_new_value, enums[1:], [enums[0]])
return enums
if __name__ == '__main__':
main()
/**
* ${warning}
*
* Copyright 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
<%block filter='fake_whitespace'>\
#include "piglit-util-gl-common.h"
const char*
piglit_get_gl_enum_name(GLenum param)
{
>-------switch (param) {
% for enum in sorted_unique_enums_in_default_namespace:
>-------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 sorted_unique_enums_in_default_namespace:
% if enum.num_value <= gl_patches.num_value:
>-------case ${enum.c_num_literal}: return "${enum.name}";
% endif
% endfor
>-------default: return "(unrecognized enum)";
>-------}
}
</%block>\
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment