<p dir="ltr"><br>
On Aug 11, 2015 18:49, "Ilia Mirkin" <<a href="mailto:imirkin@alum.mit.edu">imirkin@alum.mit.edu</a>> wrote:<br>
><br>
> ---<br>
>  tests/all.py                              |  10 +<br>
>  tests/texturing/shaders/CMakeLists.gl.txt |   1 +<br>
>  tests/texturing/shaders/textureSamples.c  | 358 ++++++++++++++++++++++++++++++<br>
>  3 files changed, 369 insertions(+)<br>
>  create mode 100644 tests/texturing/shaders/textureSamples.c<br>
><br>
> diff --git a/tests/all.py b/tests/all.py<br>
> index 07cf557..d0e78e6 100644<br>
> --- a/tests/all.py<br>
> +++ b/tests/all.py<br>
> @@ -1425,6 +1425,16 @@ for stage in ['vs', 'gs', 'fs']:<br>
>              PiglitGLTest(['texelFetch', stage, '{}sampler2DArray'.format(type),<br>
>                            'b0r1'])<br>
><br>
> +    for type in ('i', 'u', ''):<br>
> +        for sampler in ('sampler2DMS', 'sampler2DMSArray'):<br>
> +            for samples in map(str, (2, 4, 8)):</p>
<p dir="ltr">Or maybe just ('2', '4', '8') ?</p>
<p dir="ltr">> +                stype = '{}{}'.format(type, sampler)<br>
> +                profile.test_list[grouptools.join(<br>
> +                    'spec', 'arb_shader_texture_image_samples',<br>
> +                    'textureSamples', '{}-{}-{}'.format(stage, stype, samples))<br>
> +                ] = PiglitGLTest([<br>
> +                    'textureSamples', stage, stype, samples])<br>
> +<br>
>  with profile.group_manager(<br>
>          PiglitGLTest,<br>
>          grouptools.join('spec', 'glsl-1.30')) as g:<br>
> diff --git a/tests/texturing/shaders/CMakeLists.gl.txt b/tests/texturing/shaders/CMakeLists.gl.txt<br>
> index 6e4e9a7..8dcb865 100644<br>
> --- a/tests/texturing/shaders/CMakeLists.gl.txt<br>
> +++ b/tests/texturing/shaders/CMakeLists.gl.txt<br>
> @@ -13,3 +13,4 @@ link_libraries (<br>
>  piglit_add_executable (textureSize textureSize.c common.c)<br>
>  piglit_add_executable (texelFetch texelFetch.c common.c)<br>
>  piglit_add_executable (textureGather textureGather.c)<br>
> +piglit_add_executable (textureSamples textureSamples.c common.c)<br>
> diff --git a/tests/texturing/shaders/textureSamples.c b/tests/texturing/shaders/textureSamples.c<br>
> new file mode 100644<br>
> index 0000000..fcf2098<br>
> --- /dev/null<br>
> +++ b/tests/texturing/shaders/textureSamples.c<br>
> @@ -0,0 +1,358 @@<br>
> +/*<br>
> + * Copyright © 2015 Ilia Mirkin<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Heavily based on textureSize.c<br>
> + */<br>
> +<br>
> +/**<br>
> + * \file textureSamples.c<br>
> + *<br>
> + * Tests the ARB_shader_texture_image_samples textureSamples() built-in.<br>
> + *<br>
> + * The test covers:<br>
> + * - All pipeline stages (VS, GS, FS)<br>
> + * - Sampler data types (floating point, signed integer, unsigned integer)<br>
> + * - Sampler dimensionality (2DMS, 2DMSArray)<br>
> + *<br>
> + * The "textureSamples" binary takes three arguments:<br>
> + *   shader stage<br>
> + *   sampler type<br>
> + *   number of samples<br>
> + *<br>
> + * For example:<br>
> + * ./bin/textureSamples fs sampler2DMS 4<br>
> + * ./bin/textureSamples vs usampler2DMSArray 2<br>
> + */<br>
> +#include "common.h"<br>
> +<br>
> +void<br>
> +parse_args(int argc, char **argv);<br>
> +static enum shader_target test_stage = UNKNOWN;<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_BEGIN<br>
> +<br>
> +       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
> +<br>
> +       piglit_gl_process_args(&argc, argv, &config);<br>
> +<br>
> +       parse_args(argc, argv);<br>
> +       if (test_stage == GS) {<br>
> +               config.supports_gl_compat_version = 32;<br>
> +               config.supports_gl_core_version = 32;<br>
> +       } else {<br>
> +               config.supports_gl_compat_version = 30;<br>
> +               config.supports_gl_core_version = 31;<br>
> +       }<br>
> +<br>
> +PIGLIT_GL_TEST_CONFIG_END<br>
> +<br>
> +static int vertex_location;<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display()<br>
> +{<br>
> +       bool pass = true;<br>
> +       static const float verts[] = {<br>
> +               -1, -1,<br>
> +               -1,  1,<br>
> +                1,  1,<br>
> +                1, -1,<br>
> +       };<br>
> +       GLuint vbo;<br>
> +<br>
> +       glClearColor(0.5, 0.5, 0.5, 1.0);<br>
> +       glClear(GL_COLOR_BUFFER_BIT);<br>
> +<br>
> +       /* For GL core, we need to have a vertex array object bound.<br>
> +        * Otherwise, we don't particularly have to.  Always use a<br>
> +        * vertex buffer object, though.<br>
> +        */<br>
> +       if (piglit_get_gl_version() >= 31) {<br>
> +               GLuint vao;<br>
> +               glGenVertexArrays(1, &vao);<br>
> +               glBindVertexArray(vao);<br>
> +       }<br>
> +       glGenBuffers(1, &vbo);<br>
> +       glBindBuffer(GL_ARRAY_BUFFER, vbo);<br>
> +       glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);<br>
> +<br>
> +       glVertexAttribPointer(vertex_location, 2, GL_FLOAT, GL_FALSE, 0, 0);<br>
> +       glEnableVertexAttribArray(vertex_location);<br>
> +<br>
> +       float expected_color[4] = {0, 1, 0};<br>
> +       glViewport(0, 0, piglit_width, piglit_height);<br>
> +       glDrawArrays(GL_TRIANGLE_FAN, 0, 4);<br>
> +<br>
> +       pass &= piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,<br>
> +                                     expected_color);<br>
> +<br>
> +       glDisableVertexAttribArray(vertex_location);<br>
> +       piglit_present_results();<br>
> +<br>
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
> +}<br>
> +<br>
> +void<br>
> +generate_texture()<br>
> +{<br>
> +       GLuint tex;<br>
> +       GLint samples = 0;<br>
> +       const GLenum target = sampler.target;<br>
> +<br>
> +       glActiveTexture(GL_TEXTURE0);<br>
> +<br>
> +       glGenTextures(1, &tex);<br>
> +       glBindTexture(target, tex);<br>
> +<br>
> +       if (target == GL_TEXTURE_2D_MULTISAMPLE)<br>
> +               glTexImage2DMultisample(target, sample_count, GL_RGBA8,<br>
> +                                       32, 32, GL_TRUE);<br>
> +       else<br>
> +               glTexImage3DMultisample(target, sample_count, GL_RGBA8,<br>
> +                                       32, 32, 32, GL_TRUE);<br>
> +<br>
> +       glGetTexLevelParameteriv(target, 0, GL_TEXTURE_SAMPLES, &samples);<br>
> +       if (samples != sample_count) {<br>
> +               printf("Sample count of %d not supported, got %d samples\n",<br>
> +                      sample_count, samples);<br>
> +               piglit_report_result(PIGLIT_SKIP);<br>
> +       }<br>
> +}<br>
> +<br>
> +int<br>
> +generate_GLSL(enum shader_target test_stage)<br>
> +{<br>
> +       int vs, gs = 0, fs;<br>
> +       int prog;<br>
> +<br>
> +       static char *vs_code;<br>
> +       static char *gs_code = NULL;<br>
> +       static char *fs_code;<br>
> +<br>
> +       switch (test_stage) {<br>
> +       case VS:<br>
> +               asprintf(&vs_code,<br>
> +                        "#version %d\n"<br>
> +                        "#extension GL_ARB_texture_multisample: enable\n"<br>
> +                        "#extension GL_ARB_shader_texture_image_samples: enable\n"<br>
> +                        "uniform %s tex;\n"<br>
> +                        "in vec4 vertex;\n"<br>
> +                        "flat out int samples;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "    samples = textureSamples(tex);\n"<br>
> +                        "    gl_Position = vertex;\n"<br>
> +                        "}\n",<br>
> +                        shader_version, <a href="http://sampler.name">sampler.name</a>);<br>
> +               asprintf(&fs_code,<br>
> +                        "#version %d\n"<br>
> +                        "flat in int samples;\n"<br>
> +                        "out vec4 color;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "  if (samples == %d) color = vec4(0,1,0,1);\n"<br>
> +                        "  else color = vec4(1,0,0,1);\n"<br>
> +                        "}\n",<br>
> +                        shader_version, sample_count);<br>
> +               break;<br>
> +       case GS:<br>
> +               asprintf(&vs_code,<br>
> +                        "#version %d\n"<br>
> +                        "in vec4 vertex;\n"<br>
> +                        "out vec4 pos_to_gs;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "    pos_to_gs = vertex;\n"<br>
> +                        "}\n",<br>
> +                        shader_version);<br>
> +               asprintf(&gs_code,<br>
> +                        "#version %d\n"<br>
> +                        "#extension GL_ARB_texture_multisample: enable\n"<br>
> +                        "#extension GL_ARB_shader_texture_image_samples: enable\n"<br>
> +                        "layout(triangles) in;\n"<br>
> +                        "layout(triangle_strip, max_vertices = 3) out;\n"<br>
> +                        "uniform %s tex;\n"<br>
> +                        "in vec4 pos_to_gs[3];\n"<br>
> +                        "flat out int samples;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "    for (int i = 0; i < 3; i++) {\n"<br>
> +                        "        samples = textureSamples(tex);\n"<br>
> +                        "        gl_Position = pos_to_gs[i];\n"<br>
> +                        "        EmitVertex();\n"<br>
> +                        "    }\n"<br>
> +                        "}\n",<br>
> +                        shader_version, <a href="http://sampler.name">sampler.name</a>);<br>
> +               asprintf(&fs_code,<br>
> +                        "#version %d\n"<br>
> +                        "flat in int samples;\n"<br>
> +                        "out vec4 color;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "  if (samples == %d) color = vec4(0,1,0,1);\n"<br>
> +                        "  else color = vec4(1,0,0,1);\n"<br>
> +                        "}\n",<br>
> +                        shader_version, sample_count);<br>
> +               break;<br>
> +       case FS:<br>
> +               asprintf(&vs_code,<br>
> +                        "#version %d\n"<br>
> +                        "in vec4 vertex;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "    gl_Position = vertex;\n"<br>
> +                        "}\n",<br>
> +                        shader_version);<br>
> +               asprintf(&fs_code,<br>
> +                        "#version %d\n"<br>
> +                        "#extension GL_ARB_texture_multisample: enable\n"<br>
> +                        "#extension GL_ARB_shader_texture_image_samples: enable\n"<br>
> +                        "uniform %s tex;\n"<br>
> +                        "out vec4 color;\n"<br>
> +                        "void main()\n"<br>
> +                        "{\n"<br>
> +                        "  if (textureSamples(tex) == %d) color = vec4(0,1,0,1);\n"<br>
> +                        "  else color = vec4(1,0,0,1);\n"<br>
> +                        "}\n",<br>
> +                        shader_version, <a href="http://sampler.name">sampler.name</a>, sample_count);<br>
> +               break;<br>
> +       default:<br>
> +               assert(!"Should not get here.");<br>
> +               break;<br>
> +       }<br>
> +<br>
> +       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);<br>
> +       if (gs_code) {<br>
> +               gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_code);<br>
> +       }<br>
> +       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);<br>
> +<br>
> +       if (!vs || (gs_code && !gs) || !fs)<br>
> +               return 0;<br>
> +<br>
> +       prog = glCreateProgram();<br>
> +       glAttachShader(prog, vs);<br>
> +       if (gs_code)<br>
> +               glAttachShader(prog, gs);<br>
> +       glAttachShader(prog, fs);<br>
> +       glLinkProgram(prog);<br>
> +       if (!piglit_link_check_status(prog))<br>
> +               piglit_report_result(PIGLIT_FAIL);<br>
> +<br>
> +       return prog;<br>
> +}<br>
> +<br>
> +void<br>
> +fail_and_show_usage()<br>
> +{<br>
> +       printf("Usage: textureSize <vs|gs|fs> <sampler type> <sample_count> [piglit args...]\n");<br>
> +       piglit_report_result(PIGLIT_SKIP);<br>
> +}<br>
> +<br>
> +<br>
> +void<br>
> +parse_args(int argc, char **argv)<br>
> +{<br>
> +       int i;<br>
> +       bool sampler_found = false;<br>
> +<br>
> +       for (i = 1; i < argc; i++) {<br>
> +               if (test_stage == UNKNOWN) {<br>
> +                       /* Maybe it's the shader stage? */<br>
> +                       if (strcmp(argv[i], "vs") == 0) {<br>
> +                               test_stage = VS;<br>
> +                               continue;<br>
> +                       } else if (strcmp(argv[i], "gs") == 0) {<br>
> +                               test_stage = GS;<br>
> +                               continue;<br>
> +                       } else if (strcmp(argv[i], "fs") == 0) {<br>
> +                               test_stage = FS;<br>
> +                               continue;<br>
> +                       }<br>
> +               }<br>
> +<br>
> +               /* Maybe it's the sampler type? */<br>
> +               if (!sampler_found && (sampler_found = select_sampler(argv[i])))<br>
> +                       continue;<br>
> +<br>
> +               /* Maybe it's the sample count? */<br>
> +               if (sampler_found && !sample_count) {<br>
> +                       sample_count = atoi(argv[i]);<br>
> +                       continue;<br>
> +               }<br>
> +<br>
> +               fail_and_show_usage();<br>
> +       }<br>
> +<br>
> +       if (test_stage == UNKNOWN || !sampler_found)<br>
> +               fail_and_show_usage();<br>
> +<br>
> +       if (test_stage == GS && shader_version < 150)<br>
> +               shader_version = 150;<br>
> +}<br>
> +<br>
> +<br>
> +void<br>
> +piglit_init(int argc, char **argv)<br>
> +{<br>
> +       int prog;<br>
> +       int tex_location;<br>
> +<br>
> +       piglit_require_extension("GL_ARB_shader_texture_image_samples");<br>
> +       require_GL_features(test_stage);<br>
> +<br>
> +       if (sample_count) {<br>
> +               /* check it */<br>
> +               GLint max_samples;<br>
> +<br>
> +               if (sampler.data_type == GL_INT ||<br>
> +                   sampler.data_type == GL_UNSIGNED_INT) {<br>
> +                       glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &max_samples);<br>
> +                       if (sample_count > max_samples) {<br>
> +                               printf("Sample count of %d not supported,"<br>
> +                                      " >MAX_INTEGER_SAMPLES\n",<br>
> +                                      sample_count);<br>
> +                               piglit_report_result(PIGLIT_SKIP);<br>
> +                       }<br>
> +               } else {<br>
> +                       glGetIntegerv(GL_MAX_SAMPLES, &max_samples);<br>
> +                       if (sample_count > max_samples) {<br>
> +                               printf("Sample count of %d not supported,"<br>
> +                                      " >MAX_SAMPLES\n",<br>
> +                                      sample_count);<br>
> +                               piglit_report_result(PIGLIT_SKIP);<br>
> +                       }<br>
> +               }<br>
> +       }<br>
> +<br>
> +       prog = generate_GLSL(test_stage);<br>
> +       if (!prog)<br>
> +               piglit_report_result(PIGLIT_FAIL);<br>
> +<br>
> +       tex_location = glGetUniformLocation(prog, "tex");<br>
> +       vertex_location = glGetAttribLocation(prog, "vertex");<br>
> +       glUseProgram(prog);<br>
> +       glUniform1i(tex_location, 0);<br>
> +<br>
> +       compute_miplevel_info();<br>
> +       generate_texture();<br>
> +}<br>
> --<br>
> 2.4.6<br>
><br>
> _______________________________________________<br>
> Piglit mailing list<br>
> <a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/piglit">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</p>