From 6771c5a0a17421693355ff40d9fd97e30e37ecb6 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 9 Nov 2012 17:58:10 -0800 Subject: shader_runner: Partially process the requirements section before creating the context A test script can require a specific GLSL version or a specific GL version. To satisfy this requirement, the piglit framework code needs to know about the requirement before creating the context. However, the requirements section can contain other requirements, such as minimum number of uniforms. The requirements section can't be fully processed until after the context is created, but the context can't be created until after the requirements section is processed. Do a quick can over the requirements section to find the GL and GLSL version requirements. Use these to guide context creation. v2: Use 3-digit GLSL versions as suggested by Eric. Signed-off-by: Ian Romanick Reviewed-by: Chad Versace Reviewed-by: Eric Anholt --- tests/shaders/shader_runner.c | 102 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c index d89abdb0..ffe1a6c7 100644 --- a/tests/shaders/shader_runner.c +++ b/tests/shaders/shader_runner.c @@ -39,9 +39,16 @@ #include "piglit-util-gl-common.h" #include "piglit-vbo.h" +static void +get_required_versions(const char *script_name, + struct piglit_gl_test_config *config); + PIGLIT_GL_TEST_CONFIG_BEGIN - config.supports_gl_compat_version = 10; + if (argc > 1) + get_required_versions(argv[1], &config); + else + config.supports_gl_compat_version = 10; config.window_width = 250; config.window_height = 250; @@ -741,6 +748,99 @@ process_test_script(const char *script_name) leave_state(state, line); } +/** + * Just determine the GLSL version required by the shader script. + * + * This function is a bit of a hack that is, unfortunately necessary. A test + * script can require a specific GLSL version or a specific GL version. To + * satisfy this requirement, the piglit framework code needs to know about the + * requirement before creating the context. However, the requirements section + * can contain other requirements, such as minimum number of uniforms. + * + * The requirements section can't be fully processed until after the context + * is created, but the context can't be created until after the requirements + * section is processed. Do a quick can over the requirements section to find + * the GL and GLSL version requirements. Use these to guide context creation. + */ +void +get_required_versions(const char *script_name, + struct piglit_gl_test_config *config) +{ + unsigned text_size; + char *text = piglit_load_text_file(script_name, &text_size); + const char *line = text; + unsigned requested_glsl_version = 110; + unsigned requested_gl_version = 10; + bool in_requirement_section = false; + + + if (line == NULL) { + printf("could not read file \"%s\"\n", script_name); + piglit_report_result(PIGLIT_FAIL); + } + + while (line[0] != '\0') { + if (line[0] == '[') + in_requirement_section = false; + + if (!in_requirement_section) { + if (string_match("[require]", line)) { + in_requirement_section = true; + } + } else { + if (string_match("GL_", line) + || string_match("!GL_", line)) { + /* empty */ + } else if (string_match("GLSL", line)) { + enum comparison cmp; + unsigned version; + + parse_version_comparison(line + 4, &cmp, + &version, true); + if (cmp == greater_equal) + requested_glsl_version = version; + + } else if (string_match("GL", line)) { + enum comparison cmp; + unsigned version; + + parse_version_comparison(line + 2, &cmp, + &version, false); + if (cmp == greater_equal + || cmp == greater + || cmp == equal) + requested_gl_version = version; + } + } + + line = strchrnul(line, '\n'); + if (line[0] != '\0') + line++; + } + + switch (requested_glsl_version) { + case 140: + case 150: + case 330: + if (requested_gl_version < 31) + requested_gl_version = 31; + break; + case 400: + case 410: + case 420: + if (requested_gl_version < 40) + requested_gl_version = 40; + break; + } + + if (requested_gl_version > 30) { + config->supports_gl_core_version = requested_gl_version; + config->supports_gl_compat_version = requested_gl_version; + } else { + config->supports_gl_core_version = 0; + config->supports_gl_compat_version = 10; + } +} void get_floats(const char *line, float *f, unsigned count) -- cgit v1.2.3