From b9c12500164180f0bf4b667c3e9a5ba09190fb2e Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 19 Sep 2011 14:59:04 -0700 Subject: Test proper behavior of gl_MaxClipDistances and gl_MaxClipPlanes. This patch adds a test to verify that if the implementation reports support for GLSL version 1.30, the values of gl_MaxClipDistances and gl_MaxClipPlanes (accessible via GLSL) match the values of MAX_CLIP_DISTANCES and MAX_CLIP_PLANES queried using glGetIntegerv. Furthermore, it checks that the value of MAX_CLIP_DISTANCES matches the value of MAX_CLIP_PLANES (since the latter is a deprecated name for the former), and that the value is at least 8 (since GLSL 1.30 requires at least 8 clip distances to be supported). Tested using the nVidia proprietary Linux driver. --- tests/all.tests | 1 + tests/spec/glsl-1.30/execution/CMakeLists.txt | 1 + .../glsl-1.30/execution/clipping/CMakeLists.gl.txt | 17 +++ .../glsl-1.30/execution/clipping/CMakeLists.txt | 1 + .../execution/clipping/max-clip-distances.c | 169 +++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 tests/spec/glsl-1.30/execution/clipping/CMakeLists.gl.txt create mode 100644 tests/spec/glsl-1.30/execution/clipping/CMakeLists.txt create mode 100644 tests/spec/glsl-1.30/execution/clipping/max-clip-distances.c diff --git a/tests/all.tests b/tests/all.tests index 0ec6ee33c..672c52854 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -847,6 +847,7 @@ add_shader_test_dir(spec['glsl-1.30']['execution'], spec['glsl-1.30']['linker'] = Group() spec['glsl-1.30']['linker']['clipping'] = Group() add_plain_test(spec['glsl-1.30']['linker']['clipping'], 'mixing-clip-distance-and-clip-vertex-disallowed') +add_plain_test(spec['glsl-1.30']['execution']['clipping'], 'max-clip-distances') # Group AMD_conservative_depth spec['AMD_conservative_depth'] = Group() diff --git a/tests/spec/glsl-1.30/execution/CMakeLists.txt b/tests/spec/glsl-1.30/execution/CMakeLists.txt index 144a306f4..a768d27f4 100644 --- a/tests/spec/glsl-1.30/execution/CMakeLists.txt +++ b/tests/spec/glsl-1.30/execution/CMakeLists.txt @@ -1 +1,2 @@ piglit_include_target_api() +add_subdirectory (clipping) diff --git a/tests/spec/glsl-1.30/execution/clipping/CMakeLists.gl.txt b/tests/spec/glsl-1.30/execution/clipping/CMakeLists.gl.txt new file mode 100644 index 000000000..aae66ee89 --- /dev/null +++ b/tests/spec/glsl-1.30/execution/clipping/CMakeLists.gl.txt @@ -0,0 +1,17 @@ + +include_directories( + ${GLEXT_INCLUDE_DIR} + ${OPENGL_INCLUDE_PATH} + ${GLUT_INCLUDE_DIR} + ${piglit_SOURCE_DIR}/tests/mesa/util + ${piglit_SOURCE_DIR}/tests/util +) + +link_libraries ( + piglitutil + ${OPENGL_gl_LIBRARY} + ${OPENGL_glu_LIBRARY} + ${GLUT_glut_LIBRARY} +) + +add_executable (max-clip-distances max-clip-distances.c) diff --git a/tests/spec/glsl-1.30/execution/clipping/CMakeLists.txt b/tests/spec/glsl-1.30/execution/clipping/CMakeLists.txt new file mode 100644 index 000000000..144a306f4 --- /dev/null +++ b/tests/spec/glsl-1.30/execution/clipping/CMakeLists.txt @@ -0,0 +1 @@ +piglit_include_target_api() diff --git a/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.c b/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.c new file mode 100644 index 000000000..f03366598 --- /dev/null +++ b/tests/spec/glsl-1.30/execution/clipping/max-clip-distances.c @@ -0,0 +1,169 @@ +/* + * Copyright © 2011 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. + */ + +/** + * \file max-clip-distances.c + * + * From the GLSL 1.30 spec, section 7.4 (Built-In Constants): + * + * "The following built-in constants are provided to vertex and + * fragment shaders. The actual values used are implementation + * dependent, but must be at least the value shown. + * + * ... + * + * const int gl_MaxClipDistances = 8; + * + * ... + * + * const int gl_MaxClipPlanes = 8; // deprecated" + * + * And from the GL 3.0 spec, section N.3 (Changed Tokens): + * + * "New token names are introduced to be used in place of old, + * inconsistent names. However, the old token names continue to be + * supported, for backwards compatibility with code written for + * previous versions of OpenGL. + * + * ... + * + * New Token Name Old Token Name + * ... + * MAX_CLIP_DISTANCES MAX_CLIP_PLANES + * + * This test verifies that glGetIntegerv() returns the same result for + * the tokens MAX_CLIP_DISTANCES and MAX_CLIP_PLANES, that this value + * matches the value of gl_MaxClipDistances and gl_MaxClipPlanes + * defined in the vertex and fragment shaders, and that this value is + * at least 8. + */ +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +static const char vert[] = + "#version 130\n" + "uniform int expected_value;\n" + "uniform bool test_distances;\n" + "uniform bool test_in_vs;\n" + "void main()\n" + "{\n" + " gl_Position = gl_Vertex;\n" + " if (test_in_vs) {\n" + " int value = test_distances ? gl_MaxClipDistances\n" + " : gl_MaxClipPlanes;\n" + " gl_FrontColor = (value == expected_value)\n" + " ? vec4(0.0, 1.0, 0.0, 1.0)\n" + " : vec4(1.0, 0.0, 0.0, 1.0);\n" + " }\n" + "}\n"; + +static const char frag[] = + "#version 130\n" + "uniform int expected_value;\n" + "uniform bool test_distances;\n" + "uniform bool test_in_vs;\n" + "void main()\n" + "{\n" + " if (test_in_vs) {\n" + " gl_FragColor = gl_Color;\n" + " } else {\n" + " int value = test_distances ? gl_MaxClipDistances\n" + " : gl_MaxClipPlanes;\n" + " gl_FragColor = (value == expected_value)\n" + " ? vec4(0.0, 1.0, 0.0, 1.0)\n" + " : vec4(1.0, 0.0, 0.0, 1.0);\n" + " }\n" + "}\n"; + +GLuint prog; + +enum piglit_result +piglit_display(void) +{ + GLint max_clip_planes, max_clip_distances, expected_value; + GLint test_distances, test_in_vs; + float green[] = { 0.0, 1.0, 0.0, 1.0 }; + GLint loc; + + enum piglit_result result = PIGLIT_PASS; + glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); + printf("GL_MAX_CLIP_PLANES = %d\n", max_clip_planes); + glGetIntegerv(GL_MAX_CLIP_DISTANCES, &max_clip_distances); + printf("GL_MAX_CLIP_DISTANCES = %d\n", max_clip_distances); + if (max_clip_planes != max_clip_distances) { + printf("GL_MAX_CLIP_PLANES != GL_MAX_CLIP_DISTANCES\n"); + piglit_report_result(PIGLIT_FAIL); + } + if (max_clip_distances < 8) { + printf("GL_MAX_CLIP_DISTANCES < 8\n"); + piglit_report_result(PIGLIT_FAIL); + } + + expected_value = max_clip_distances; + loc = piglit_GetUniformLocation(prog, "expected_value"); + piglit_Uniform1i(loc, expected_value); + + for (test_distances = 0; test_distances <= 1; ++test_distances) { + loc = piglit_GetUniformLocation(prog, "test_distances"); + piglit_Uniform1i(loc, test_distances); + for (test_in_vs = 0; test_in_vs <= 1; ++test_in_vs) { + bool pass; + loc = piglit_GetUniformLocation(prog, "test_in_vs"); + piglit_Uniform1i(loc, test_in_vs); + piglit_draw_rect(-1, -1, 2, 2); + pass = piglit_probe_rect_rgba(0, 0, piglit_width, + piglit_height, green); + printf("Checking that gl_MaxClip%s == %d in %s: %s\n", + test_distances ? "Distances" : "Planes", + expected_value, + test_in_vs ? "VS" : "FS", + pass ? "pass" : "fail"); + if (!pass) { + result = PIGLIT_FAIL; + } + } + } + + return result; +} + +void +piglit_init(int argc, char **argv) +{ + GLuint vs; + GLuint fs; + + piglit_require_GLSL(); + piglit_require_GLSL_version(130); + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert); + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag); + prog = piglit_CreateProgram(); + piglit_AttachShader(prog, vs); + piglit_AttachShader(prog, fs); + piglit_LinkProgram(prog); + piglit_DeleteShader(vs); + piglit_DeleteShader(fs); + piglit_UseProgram(prog); +} -- cgit v1.2.3