From cb880cc7bfbe8c62799bebfb36027328518c1a69 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Wed, 1 Jun 2011 21:42:43 -0700 Subject: hiz: Add tests for depth and stencil test simulatnesouly enabled for various FBO's Add the following tests: hiz-depth-stencil-test-fbo-d0-s8 hiz-depth-stencil-test-fbo-d24-s0 hiz-depth-stencil-test-fbo-d24-s8 hiz-depth-stencil-test-fbo-d24s8 These tests' goal is to check for for undefined GPU behavior when stencil read/writes are accidentally enabled in hardware when no stencil buffer is present, and analogously for depth read/writes when no depth buffer is present. Signed-off-by: Chad Versace --- tests/hiz/CMakeLists.gl.txt | 4 + tests/hiz/hiz-depth-stencil-test-fbo-d0-s8.c | 68 ++++++++++++++ tests/hiz/hiz-depth-stencil-test-fbo-d24-s0.c | 68 ++++++++++++++ tests/hiz/hiz-depth-stencil-test-fbo-d24-s8.c | 69 ++++++++++++++ tests/hiz/hiz-depth-stencil-test-fbo-d24s8.c | 68 ++++++++++++++ tests/hiz/hiz-util.c | 129 ++++++++++++++++++++++++++ tests/hiz/hiz-util.h | 19 ++++ 7 files changed, 425 insertions(+) create mode 100644 tests/hiz/hiz-depth-stencil-test-fbo-d0-s8.c create mode 100644 tests/hiz/hiz-depth-stencil-test-fbo-d24-s0.c create mode 100644 tests/hiz/hiz-depth-stencil-test-fbo-d24-s8.c create mode 100644 tests/hiz/hiz-depth-stencil-test-fbo-d24s8.c (limited to 'tests/hiz') diff --git a/tests/hiz/CMakeLists.gl.txt b/tests/hiz/CMakeLists.gl.txt index 98222c58..ddc301df 100644 --- a/tests/hiz/CMakeLists.gl.txt +++ b/tests/hiz/CMakeLists.gl.txt @@ -24,6 +24,10 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") link_libraries(pthread X11) ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +add_executable(hiz-depth-stencil-test-fbo-d0-s8 hiz-depth-stencil-test-fbo-d0-s8.c) +add_executable(hiz-depth-stencil-test-fbo-d24-s0 hiz-depth-stencil-test-fbo-d24-s0.c) +add_executable(hiz-depth-stencil-test-fbo-d24-s8 hiz-depth-stencil-test-fbo-d24-s8.c) +add_executable(hiz-depth-stencil-test-fbo-d24s8 hiz-depth-stencil-test-fbo-d24s8.c) add_executable(hiz-depth-test-fbo-d24 hiz-depth-test-fbo-d24.c) add_executable(hiz-depth-test-fbo-d24-s8 hiz-depth-test-fbo-d24-s8.c) add_executable(hiz-depth-test-fbo-d24s8 hiz-depth-test-fbo-d24s8.c) diff --git a/tests/hiz/hiz-depth-stencil-test-fbo-d0-s8.c b/tests/hiz/hiz-depth-stencil-test-fbo-d0-s8.c new file mode 100644 index 00000000..b980e031 --- /dev/null +++ b/tests/hiz/hiz-depth-stencil-test-fbo-d0-s8.c @@ -0,0 +1,68 @@ +/* + * 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. + * + * Authors: + * Chad Versace + */ + +/** + * \file hiz-depth-stencil-test-fbo-d0-s8.c + * + * Check that rendering to an FBO works correctly when depth and stencil test + * are simultaneously enabled and the following attachments are present: + * - GL_COLOR_ATTACHMENT0: GL_RGBA + * - GL_STENCIL_ATTACHMENT: GL_STENCIL_INDEX8 + * + * This test probes only the color buffer; it does not probe the stencil + * nor the depth buffer. + * + * \author Chad Versace + */ + +#include "piglit-util.h" +#include "hiz/hiz-util.h" + +int piglit_width = 400; +int piglit_height = 400; +int piglit_window_mode = GLUT_RGB; + +struct hiz_fbo_options fbo_options = { + GL_RGBA, + 0, + GL_STENCIL_INDEX8, + 0, +}; + +void +piglit_init(int argc, char **argv) +{ + /* empty */ +} + +enum piglit_result +piglit_display() +{ + if (hiz_run_test_depth_stencil_test_fbo(&fbo_options)) + return PIGLIT_PASS; + else + return PIGLIT_FAIL; +} diff --git a/tests/hiz/hiz-depth-stencil-test-fbo-d24-s0.c b/tests/hiz/hiz-depth-stencil-test-fbo-d24-s0.c new file mode 100644 index 00000000..dae48e9b --- /dev/null +++ b/tests/hiz/hiz-depth-stencil-test-fbo-d24-s0.c @@ -0,0 +1,68 @@ +/* + * 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. + * + * Authors: + * Chad Versace + */ + +/** + * \file hiz-depth-stencil-test-fbo-d24-s0.c + * + * Check that rendering to an FBO works correctly when depth and stencil test + * are simultaneously enabled and the following attachments are present: + * - GL_COLOR_ATTACHMENT0: GL_RGBA + * - GL_DEPTH_ATTACHMENT: GL_DEPTH_COMPONENT24 + * + * This test probes only the color buffer; it does not probe the stencil + * nor the depth buffer. + * + * \author Chad Versace + */ + +#include "piglit-util.h" +#include "hiz/hiz-util.h" + +int piglit_width = 400; +int piglit_height = 400; +int piglit_window_mode = GLUT_RGB; + +struct hiz_fbo_options fbo_options = { + GL_RGBA, + GL_DEPTH_COMPONENT24, + 0, + 0, +}; + +void +piglit_init(int argc, char **argv) +{ + /* empty */ +} + +enum piglit_result +piglit_display() +{ + if (hiz_run_test_depth_stencil_test_fbo(&fbo_options)) + return PIGLIT_PASS; + else + return PIGLIT_FAIL; +} diff --git a/tests/hiz/hiz-depth-stencil-test-fbo-d24-s8.c b/tests/hiz/hiz-depth-stencil-test-fbo-d24-s8.c new file mode 100644 index 00000000..9dd74bb6 --- /dev/null +++ b/tests/hiz/hiz-depth-stencil-test-fbo-d24-s8.c @@ -0,0 +1,69 @@ +/* + * 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. + * + * Authors: + * Chad Versace + */ + +/** + * \file hiz-depth-stencil-test-fbo-d24-s8.c + * + * Check that rendering to an FBO works correctly when depth and stencil test + * are simultaneously enabled and the following attachments are present: + * - GL_COLOR_ATTACHMENT0: GL_RGBA + * - GL_DEPTH_ATTACHMENT: GL_DEPTH_COMPONENT24 + * - GL_STENCIL_ATTACHMENT: GL_STENCIL_INDEX8 + * + * This test probes only the color buffer; it does not probe the stencil + * nor the depth buffer. + * + * \author Chad Versace + */ + +#include "piglit-util.h" +#include "hiz/hiz-util.h" + +int piglit_width = 400; +int piglit_height = 400; +int piglit_window_mode = GLUT_RGB; + +struct hiz_fbo_options fbo_options = { + GL_RGBA, + GL_DEPTH_COMPONENT24, + GL_STENCIL_INDEX8, + 0, +}; + +void +piglit_init(int argc, char **argv) +{ + /* empty */ +} + +enum piglit_result +piglit_display() +{ + if (hiz_run_test_depth_stencil_test_fbo(&fbo_options)) + return PIGLIT_PASS; + else + return PIGLIT_FAIL; +} diff --git a/tests/hiz/hiz-depth-stencil-test-fbo-d24s8.c b/tests/hiz/hiz-depth-stencil-test-fbo-d24s8.c new file mode 100644 index 00000000..cc6f1333 --- /dev/null +++ b/tests/hiz/hiz-depth-stencil-test-fbo-d24s8.c @@ -0,0 +1,68 @@ +/* + * 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. + * + * Authors: + * Chad Versace + */ + +/** + * \file hiz-depth-stencil-test-fbo-d24s8.c + * + * Check that rendering to an FBO works correctly when depth and stencil test + * are simultaneously enabled and the following attachments are present: + * - GL_COLOR_ATTACHMENT0: GL_RGBA + * - GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH24_STENCIL8 + * + * This test probes only the color buffer; it does not probe the stencil + * nor the depth buffer. + * + * \author Chad Versace + */ + +#include "piglit-util.h" +#include "hiz/hiz-util.h" + +int piglit_width = 400; +int piglit_height = 400; +int piglit_window_mode = GLUT_RGB; + +struct hiz_fbo_options fbo_options = { + GL_RGBA, + 0, + 0, + GL_DEPTH24_STENCIL8, +}; + +void +piglit_init(int argc, char **argv) +{ + /* empty */ +} + +enum piglit_result +piglit_display() +{ + if (hiz_run_test_depth_stencil_test_fbo(&fbo_options)) + return PIGLIT_PASS; + else + return PIGLIT_FAIL; +} diff --git a/tests/hiz/hiz-util.c b/tests/hiz/hiz-util.c index 0ef382e1..7c2b9d49 100644 --- a/tests/hiz/hiz-util.c +++ b/tests/hiz/hiz-util.c @@ -542,3 +542,132 @@ hiz_run_test_stencil_read_window() } /** \} */ + +bool +hiz_run_test_depth_stencil_test_fbo(const struct hiz_fbo_options *fbo_options) +{ + bool pass = true; + + GLuint fbo = 0; + bool has_depth_buffer = fbo_options->depth_format + || fbo_options->depth_stencil_format; + bool has_stencil_buffer = fbo_options->stencil_format + || fbo_options->depth_stencil_format; + + const float dx = piglit_width / 3.0; + const float dy = piglit_height / 3.0; + + static const float *expected_colors = NULL; + + static const float *expected_colors_d1s0[9] = { + hiz_green, + hiz_green, + hiz_grey, + + hiz_green, + hiz_green, + hiz_blue, + + hiz_grey, + hiz_blue, + hiz_blue, + }; + + static const float *expected_colors_d0s1[9] = { + hiz_green, + hiz_green, + hiz_grey, + + hiz_green, + hiz_blue, + hiz_grey, + + hiz_grey, + hiz_blue, + hiz_grey, + }; + + static const float *expected_colors_d1s1[9] = { + hiz_green, + hiz_green, + hiz_grey, + + hiz_green, + hiz_green, + hiz_grey, + + hiz_grey, + hiz_blue, + hiz_grey, + }; + + if (has_depth_buffer && !has_stencil_buffer) + expected_colors = expected_colors_d1s0; + else if (!has_depth_buffer && has_stencil_buffer) + expected_colors = expected_colors_d0s1; + else if (has_depth_buffer && has_stencil_buffer) + expected_colors = expected_colors_d1s1; + + piglit_require_extension("GL_ARB_framebuffer_object"); + + /* Create and bind FBO. */ + fbo = hiz_make_fbo(fbo_options); + assert(fbo != 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); + + /* Set up depth state. */ + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glClearDepth(hiz_clear_z); + + /* Set up stencil state. */ + glEnable(GL_STENCIL_TEST); + glClearStencil(3); /* 3 is a good canary. */ + glStencilFunc(GL_LESS, 3, ~0); + glStencilOp(GL_INCR, GL_INCR, GL_INCR); + + glClearColor(hiz_grey[0], hiz_grey[1], hiz_grey[2], hiz_grey[3]); + glClear(GL_COLOR_BUFFER_BIT + | GL_DEPTH_BUFFER_BIT + | GL_STENCIL_BUFFER_BIT); + + glViewport(0, 0, piglit_width, piglit_height); + piglit_ortho_projection(piglit_width, piglit_height, false); + + /* Draw rect 1. */ + glColor4fv(hiz_grey); + glDepthRange(hiz_clear_z, hiz_clear_z); + piglit_draw_rect(0 * dx, 0 * dy, /* x, y */ + 2 * dx, 3 * dy); /* w, h */ + + /* Draw rect 2. */ + glColor4fv(hiz_green); + glDepthRange(hiz_green_z, hiz_green_z); + piglit_draw_rect(0 * dx, 0 * dy, /* x, y */ + 2 * dx, 2 * dy); /* w, h */ + + /* Draw rect 3. */ + glColor4fv(hiz_blue); + glDepthRange(hiz_blue_z, hiz_blue_z); + piglit_draw_rect(1 * dx, 1 * dy, /* x, y */ + 2 * dx, 2 * dy); /* w, h */ + + assert(!glGetError()); + + pass = hiz_probe_color_buffer(expected_colors); + + if (!piglit_automatic) { + /* Blit the FBO to the window FB so we can see the results. */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBlitFramebuffer(0, 0, piglit_width, piglit_height, + 0, 0, piglit_width, piglit_height, + GL_COLOR_BUFFER_BIT, GL_NEAREST); + glutSwapBuffers(); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); + } + + hiz_delete_fbo(fbo); + + return pass; +} diff --git a/tests/hiz/hiz-util.h b/tests/hiz/hiz-util.h index d2281e48..f83903b8 100644 --- a/tests/hiz/hiz-util.h +++ b/tests/hiz/hiz-util.h @@ -149,3 +149,22 @@ bool hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *options); * \see hiz_run_test_stencil_read_fbo() */ bool hiz_run_test_stencil_read_window(); + +/** + * Check that rendering to an FBO works correctly when depth and stencil test + * are simultaneously enabled. + * + * This test probes only the color buffer; it does not probe the stencil + * nor the depth buffer. + * + * Superficially, this test appears to simply be hiz_run_test_depth_test_fbo() + * and hiz_run_test_stencil_test_fbo() amalgamated. But, this test's purpose is + * more sinister than the sum of its parts. It tests for undefined GPU behavior + * when stencil read/writes are accidentally enabled in hardware when no + * stencil buffer is present, and analogously for depth read/writes when no + * depth buffer is present. + * + * \param options Perform the test with an FBO with the given formats. + * \return True if test passed. + */ +bool hiz_run_test_depth_stencil_test_fbo(const struct hiz_fbo_options *options); -- cgit v1.2.3