From: Kristian Høgsberg Kristensen <kristian.h.kristen...@intel.com>
--- tests/all.py | 15 ++ tests/spec/CMakeLists.txt | 1 + .../arb_shader_draw_parameters/CMakeLists.gl.txt | 14 ++ .../spec/arb_shader_draw_parameters/CMakeLists.txt | 1 + tests/spec/arb_shader_draw_parameters/basevertex.c | 176 +++++++++++++++++ .../arb_shader_draw_parameters/drawid-indirect.c | 216 +++++++++++++++++++++ tests/spec/arb_shader_draw_parameters/drawid.c | 173 +++++++++++++++++ 7 files changed, 596 insertions(+) create mode 100644 tests/spec/arb_shader_draw_parameters/CMakeLists.gl.txt create mode 100644 tests/spec/arb_shader_draw_parameters/CMakeLists.txt create mode 100644 tests/spec/arb_shader_draw_parameters/basevertex.c create mode 100644 tests/spec/arb_shader_draw_parameters/drawid-indirect.c create mode 100644 tests/spec/arb_shader_draw_parameters/drawid.c diff --git a/tests/all.py b/tests/all.py index f61ff15..a5cd236 100644 --- a/tests/all.py +++ b/tests/all.py @@ -4552,5 +4552,20 @@ with profile.group_manager( for sample_count in (str(x) for x in MSAA_SAMPLE_COUNTS): g(['ext_shader_samples_identical', sample_count]) +# Group ARR_shader_draw_parameters +with profile.group_manager( + PiglitGLTest, + grouptools.join('spec', 'ARB_shader_draw_parameters')) as g: + g(['arb_shader_draw_parameters-drawid', 'drawid'], 'drawid') + g(['arb_shader_draw_parameters-drawid', 'vertexid'], 'drawid-vertexid') + g(['arb_shader_draw_parameters-basevertex', 'basevertex'], 'basevertex') + g(['arb_shader_draw_parameters-basevertex', 'baseinstance'], 'baseinstance') + g(['arb_shader_draw_parameters-basevertex', 'basevertex-baseinstance'], 'basevertex-baseinstance') + g(['arb_shader_draw_parameters-basevertex', 'vertexid-zerobased'], 'vertexid-zerobased') + g(['arb_shader_draw_parameters-drawid-indirect', 'drawid'], 'drawid-indirect') + g(['arb_shader_draw_parameters-drawid-indirect', 'basevertex'], 'drawid-indirect-basevertex') + g(['arb_shader_draw_parameters-drawid-indirect', 'baseinstance'], 'drawid-indirect-baseinstance') + g(['arb_shader_draw_parameters-drawid-indirect', 'baseinstance'], 'drawid-indirect-vertexid') + if platform.system() is 'Windows': profile.filter_tests(lambda p, _: not p.startswith('glx')) diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt index 57ac541..b499cd8 100644 --- a/tests/spec/CMakeLists.txt +++ b/tests/spec/CMakeLists.txt @@ -139,3 +139,4 @@ add_subdirectory (ext_framebuffer_blit) add_subdirectory (mesa_pack_invert) add_subdirectory (ext_texture_format_bgra8888) add_subdirectory (oes_draw_elements_base_vertex) +add_subdirectory (arb_shader_draw_parameters) diff --git a/tests/spec/arb_shader_draw_parameters/CMakeLists.gl.txt b/tests/spec/arb_shader_draw_parameters/CMakeLists.gl.txt new file mode 100644 index 0000000..f711e2c --- /dev/null +++ b/tests/spec/arb_shader_draw_parameters/CMakeLists.gl.txt @@ -0,0 +1,14 @@ +include_directories( + ${GLEXT_INCLUDE_DIR} + ${OPENGL_INCLUDE_PATH} + ${piglit_SOURCE_DIR}/tests/mesa/util +) + +link_libraries ( + piglitutil_${piglit_target_api} + ${OPENGL_gl_LIBRARY} +) + +piglit_add_executable (arb_shader_draw_parameters-basevertex basevertex.c) +piglit_add_executable (arb_shader_draw_parameters-drawid drawid.c) +piglit_add_executable (arb_shader_draw_parameters-drawid-indirect drawid-indirect.c) diff --git a/tests/spec/arb_shader_draw_parameters/CMakeLists.txt b/tests/spec/arb_shader_draw_parameters/CMakeLists.txt new file mode 100644 index 0000000..144a306 --- /dev/null +++ b/tests/spec/arb_shader_draw_parameters/CMakeLists.txt @@ -0,0 +1 @@ +piglit_include_target_api() diff --git a/tests/spec/arb_shader_draw_parameters/basevertex.c b/tests/spec/arb_shader_draw_parameters/basevertex.c new file mode 100644 index 0000000..343c38c --- /dev/null +++ b/tests/spec/arb_shader_draw_parameters/basevertex.c @@ -0,0 +1,176 @@ +/* + * Copyright © 2015 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 basevertex.c + * + * Test that gl_BaseVertexARB has the correct values. Draw left side + * of window with a non-base-vertex draw call to verify + * gl_BaseVertexARB is 0 in that case, then draw other half with base + * vertex 4 and verifies that that works. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_core_version = 31; + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +static const char vs_template[] = + "#version 330\n" + "#extension GL_ARB_shader_draw_parameters: require\n" + "\n" + "layout(location = 0) in vec2 pos;\n" + "layout(location = 1) in ivec4 ref;\n" + "out vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = vec4(pos, 0.0, 1.0);\n" + " if (%s)\n" + " color = vec4(0, 1, 0, 1);\n" + " else\n" + " color = vec4(1, 0, 0, 1);\n" + "}\n"; + +static const char fs_text[] = + "#version 130\n" + "\n" + "in vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = color;\n" + "}\n"; + +void +piglit_init(int argc, char **argv) +{ + GLuint prog; + char *vs_text; + + if (strcmp(argv[1], "basevertex") == 0) { + asprintf(&vs_text, vs_template, + "ref.x == gl_BaseVertexARB"); + } else if (strcmp(argv[1], "baseinstance") == 0) { + asprintf(&vs_text, vs_template, + "ref.y == gl_BaseInstanceARB"); + } else if (strcmp(argv[1], "basevertex-baseinstance") == 0) { + asprintf(&vs_text, vs_template, + "ref.xy == ivec2(gl_BaseVertexARB, gl_BaseInstanceARB)"); + } else if (strcmp(argv[1], "vertexid-zerobased") == 0) { + asprintf(&vs_text, vs_template, + "ref.z == gl_VertexID - gl_BaseVertexARB"); + } else { + printf("Unknown subtest: %s\n", argv[1]); + piglit_report_result(PIGLIT_FAIL); + } + + piglit_require_GLSL_version(130); + + piglit_require_extension("GL_ARB_shader_draw_parameters"); + piglit_require_extension("GL_ARB_base_instance"); + + prog = piglit_build_simple_program(vs_text, fs_text); + + glUseProgram(prog); +} + +enum piglit_result +piglit_display() +{ + bool pass; + + static const float vertex_array[16] = { + -1, -1, + 0, -1, + 0, 1, + -1, 1, + + 0, -1, + 1, -1, + 1, 1, + 0, 1, + }; + + static const int reference_array[32] = { + 0, 0, 0, 0, + 0, 0, 1, 0, + 0, 0, 2, 0, + 0, 0, 3, 0, + 4, 7, 0, 0, + 4, 7, 1, 0, + 4, 7, 2, 0, + 4, 7, 3, 0, + }; + + const int indices[6] = { + 0, 1, 2, + 0, 2, 3, + }; + + float green[] = { 0, 1, 0, 1 }; + + GLuint vao, vbo; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, 2048, NULL, GL_STATIC_DRAW); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), 0); + glVertexAttribIPointer(1, 4, GL_UNSIGNED_INT, 4 * sizeof(int), (void *) 1024); + + /* Enable the attributes */ + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertex_array), vertex_array); + glBufferSubData(GL_ARRAY_BUFFER, 1024, sizeof(reference_array), reference_array); + + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); + + /* We use this monster to draw the right half of the + * window. Base vertex so that we can reuse the indices to + * draw with vertices and colors 4-7, base instance so that we + * can verify that the value presented in the shader is + * correct. We only draw one instance so the only effect of + * instancing is that gl_BaseInstanceARB is 7. + */ + glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, 6, + GL_UNSIGNED_INT, + indices, 1, + 4, /* basevertex */ + 7 /* baseinstance */); + + pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, + green); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} diff --git a/tests/spec/arb_shader_draw_parameters/drawid-indirect.c b/tests/spec/arb_shader_draw_parameters/drawid-indirect.c new file mode 100644 index 0000000..839b271 --- /dev/null +++ b/tests/spec/arb_shader_draw_parameters/drawid-indirect.c @@ -0,0 +1,216 @@ +/* + * Copyright © 2015 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 drawid.c + * + * Test for gl_DrawIDARB with indirect multi-draw. For mesa, this is + * interesting because this is the only mode where we actually get + * multiple _mesa_prim into the backend in one call. This tests that + * we properly reemit state to update gl_DrawIDARB between rendering, + * which on i965 involves reemitting vertex buffer state. + * + * Also, on i965, we source the vertex and instance ID from an + * internal vertex buffer for direct rdraw, but point the vertex + * buffer the parameter buffer for indirect draws. The baseinstance + * subtest verifies that this all works right. Conversely, the + * vertexid subtest doesn't reference gl_DrawIDARB and is useful for + * validating that we don't reemit vertex buffer state between multi + * draw calls. We can't test for that with this test, of course, but + * we can inspect the generate command stream from the driver. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_core_version = 31; + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +static const char vs_template[] = + "#version 330\n" + "#extension GL_ARB_shader_draw_parameters: require\n" + "\n" + "layout(location = 0) in vec2 pos;\n" + "layout(location = 1) in ivec4 ref;\n" + "out vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = vec4(pos, 0.0, 1.0);\n" + " if (%s)\n" + " color = vec4(0, 1, 0, 1);\n" + " else\n" + " color = vec4(1, 0, 0, 1);\n" + "}\n"; + +static const char fs_text[] = + "#version 130\n" + "\n" + "in vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = color;\n" + "}\n"; + +void +piglit_init(int argc, char **argv) +{ + GLuint prog; + char *vs_text; + + if (strcmp(argv[1], "drawid") == 0) { + asprintf(&vs_text, vs_template, + "ref.x == gl_DrawIDARB"); + } else if (strcmp(argv[1], "basevertex") == 0) { + asprintf(&vs_text, vs_template, + "ref.xy == ivec2(gl_DrawIDARB, gl_BaseVertexARB)"); + } else if (strcmp(argv[1], "baseinstance") == 0) { + asprintf(&vs_text, vs_template, + "ref.xz == ivec2(gl_DrawIDARB, gl_BaseInstanceARB)"); + } else if (strcmp(argv[1], "vertexid") == 0) { + asprintf(&vs_text, vs_template, + "ref.w == gl_VertexID"); + } else { + printf("Unknown subtest: %s\n", argv[1]); + piglit_report_result(PIGLIT_FAIL); + } + + piglit_require_GLSL_version(130); + + piglit_require_extension("GL_ARB_shader_draw_parameters"); + piglit_require_extension("GL_ARB_base_instance"); + + prog = piglit_build_simple_program(vs_text, fs_text); + + glUseProgram(prog); +} + +struct cmd { + uint count; + uint instanceCount; + uint firstIndex; + uint baseVertex; + uint baseInstance; +}; + +enum piglit_result +piglit_display() +{ + bool pass; + + struct { + float vertex_array[16]; + int reference_array[32]; + int indices[6]; + } geometry = { + .vertex_array = { + -1, -1, + 0, -1, + 0, 1, + -1, 1, + + 0, -1, + 1, -1, + 1, 1, + 0, 1, + }, + .reference_array = { + 0, 0, 0, 0, + 0, 0, 0, 1, + 0, 0, 0, 2, + 0, 0, 0, 3, + + 1, 4, 7, 4, + 1, 4, 7, 5, + 1, 4, 7, 6, + 1, 4, 7, 7, + } + }; + + const int indices[12] = { + 0, 1, 2, + 0, 2, 3, + }; + + float green[] = {0, 1, 0, 1}; + + GLuint vao, vbo, ibo, dbo; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(geometry), &geometry, GL_STATIC_DRAW); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(GLfloat), + (void *) ((char *) &geometry.vertex_array - (char *) &geometry)); + + glVertexAttribIPointer(1, 4, GL_UNSIGNED_INT, + 4 * sizeof(int), + (void *) ((char *) &geometry.reference_array - (char *) &geometry)); + + /* Enable the attributes */ + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + glGenBuffers(1, &ibo); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + + struct cmd cmds[] = { + { + .count = 6, + .instanceCount = 1, + .firstIndex = 0, + .baseVertex = 0, + .baseInstance = 0 + }, + { + .count = 6, + .instanceCount = 1, + .firstIndex = 0, + .baseVertex = 4, + .baseInstance = 7 + } + }; + + glGenBuffers(1, &dbo); + glBindBuffer(GL_DRAW_INDIRECT_BUFFER, dbo); + glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(cmds), cmds, GL_STATIC_DRAW); + + glMultiDrawElementsIndirect(GL_TRIANGLES, + GL_UNSIGNED_INT, + 0, 2, 0); + + pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, + green); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} diff --git a/tests/spec/arb_shader_draw_parameters/drawid.c b/tests/spec/arb_shader_draw_parameters/drawid.c new file mode 100644 index 0000000..8e79998 --- /dev/null +++ b/tests/spec/arb_shader_draw_parameters/drawid.c @@ -0,0 +1,173 @@ +/* + * Copyright © 2015 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 drawid.c + * + * Basic test for gl_DrawIDARB. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_core_version = 31; + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +static const char vs_template[] = + "#version 330\n" + "#extension GL_ARB_shader_draw_parameters: require\n" + "\n" + "/* This is floating point so we can use immediate mode */\n" + "layout(location = 0) in vec2 pos;\n" + "layout(location = 1) in ivec2 ref;\n" + "out vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_Position = vec4(pos, 0.0, 1.0);\n" + " if (%s)\n" + " color = vec4(0, 1, 0, 1);\n" + " else\n" + " color = vec4(1, 0, 0, 1);\n" + "}\n"; + +static const char fs_text[] = + "#version 130\n" + "\n" + "in vec4 color;\n" + "\n" + "void main()\n" + "{\n" + " gl_FragColor = color;\n" + "}\n"; + +void +piglit_init(int argc, char **argv) +{ + GLuint prog; + char *vs_text; + + if (strcmp(argv[1], "drawid") == 0) { + asprintf(&vs_text, vs_template, + "ref.x == gl_DrawIDARB"); + } else if (strcmp(argv[1], "vertexid") == 0) { + asprintf(&vs_text, vs_template, + "ref.x == gl_DrawIDARB && ref.y == gl_VertexID"); + } else { + printf("Unknown subtest: %s\n", argv[1]); + piglit_report_result(PIGLIT_FAIL); + } + + piglit_require_GLSL_version(130); + + piglit_require_extension("GL_ARB_shader_draw_parameters"); + piglit_require_extension("GL_ARB_base_instance"); + + prog = piglit_build_simple_program(vs_text, fs_text); + + glUseProgram(prog); +} + +enum piglit_result +piglit_display() +{ + bool pass; + + struct { + float vertex_array[16]; + int reference_array[16]; + int indices[6]; + } geometry = { + .vertex_array = { + -1, -1, + 0, -1, + 0, 1, + -1, 1, + + 0, -1, + 1, -1, + 1, 1, + 0, 1, + }, + .reference_array = { + 0, 0, + 0, 1, + 0, 2, + 0, 3, + + 1, 4, + 1, 5, + 1, 6, + 1, 7, + } + }; + + const int indices[12] = { + 0, 1, 2, + 0, 2, 3, + + 4, 5, 6, + 4, 6, 7, + }; + + float green[] = {0, 1, 0, 1}; + + GLuint vao, vbo; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(geometry), &geometry, GL_STATIC_DRAW); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, + 2 * sizeof(GLfloat), + (void *) ((char *) &geometry.vertex_array - (char *) &geometry)); + + glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT, + 2 * sizeof(int), + (void *) ((char *) &geometry.reference_array - (char *) &geometry)); + + /* Enable the attributes */ + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + GLsizei counts[2] = { 6, 6 }; + const int *indices_array[2] = { &indices[0], &indices[6] }; + + glMultiDrawElements(GL_TRIANGLES, + counts, + GL_UNSIGNED_INT, + (const void **) indices_array, + 2); + + pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, + green); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} -- 2.5.0 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit