[Piglit] [PATCH] add textureSamples tests
Ian Romanick
idr at freedesktop.org
Thu Sep 10 15:41:14 PDT 2015
On 08/11/2015 06:49 PM, Ilia Mirkin wrote:
> ---
> tests/all.py | 10 +
> tests/texturing/shaders/CMakeLists.gl.txt | 1 +
> tests/texturing/shaders/textureSamples.c | 358 ++++++++++++++++++++++++++++++
> 3 files changed, 369 insertions(+)
> create mode 100644 tests/texturing/shaders/textureSamples.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 07cf557..d0e78e6 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -1425,6 +1425,16 @@ for stage in ['vs', 'gs', 'fs']:
> PiglitGLTest(['texelFetch', stage, '{}sampler2DArray'.format(type),
> 'b0r1'])
>
> + for type in ('i', 'u', ''):
> + for sampler in ('sampler2DMS', 'sampler2DMSArray'):
> + for samples in map(str, (2, 4, 8)):
> + stype = '{}{}'.format(type, sampler)
> + profile.test_list[grouptools.join(
> + 'spec', 'arb_shader_texture_image_samples',
> + 'textureSamples', '{}-{}-{}'.format(stage, stype, samples))
> + ] = PiglitGLTest([
> + 'textureSamples', stage, stype, samples])
> +
> with profile.group_manager(
> PiglitGLTest,
> grouptools.join('spec', 'glsl-1.30')) as g:
> diff --git a/tests/texturing/shaders/CMakeLists.gl.txt b/tests/texturing/shaders/CMakeLists.gl.txt
> index 6e4e9a7..8dcb865 100644
> --- a/tests/texturing/shaders/CMakeLists.gl.txt
> +++ b/tests/texturing/shaders/CMakeLists.gl.txt
> @@ -13,3 +13,4 @@ link_libraries (
> piglit_add_executable (textureSize textureSize.c common.c)
> piglit_add_executable (texelFetch texelFetch.c common.c)
> piglit_add_executable (textureGather textureGather.c)
> +piglit_add_executable (textureSamples textureSamples.c common.c)
> diff --git a/tests/texturing/shaders/textureSamples.c b/tests/texturing/shaders/textureSamples.c
> new file mode 100644
> index 0000000..fcf2098
> --- /dev/null
> +++ b/tests/texturing/shaders/textureSamples.c
> @@ -0,0 +1,358 @@
> +/*
> + * Copyright © 2015 Ilia Mirkin
> + *
> + * 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.
> + *
> + * Heavily based on textureSize.c
> + */
> +
> +/**
> + * \file textureSamples.c
> + *
> + * Tests the ARB_shader_texture_image_samples textureSamples() built-in.
> + *
> + * The test covers:
> + * - All pipeline stages (VS, GS, FS)
> + * - Sampler data types (floating point, signed integer, unsigned integer)
> + * - Sampler dimensionality (2DMS, 2DMSArray)
> + *
> + * The "textureSamples" binary takes three arguments:
> + * shader stage
> + * sampler type
> + * number of samples
> + *
> + * For example:
> + * ./bin/textureSamples fs sampler2DMS 4
> + * ./bin/textureSamples vs usampler2DMSArray 2
> + */
> +#include "common.h"
> +
> +void
> +parse_args(int argc, char **argv);
> +static enum shader_target test_stage = UNKNOWN;
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> + piglit_gl_process_args(&argc, argv, &config);
> +
> + parse_args(argc, argv);
> + if (test_stage == GS) {
> + config.supports_gl_compat_version = 32;
> + config.supports_gl_core_version = 32;
> + } else {
> + config.supports_gl_compat_version = 30;
> + config.supports_gl_core_version = 31;
> + }
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static int vertex_location;
> +
> +enum piglit_result
> +piglit_display()
> +{
> + bool pass = true;
> + static const float verts[] = {
> + -1, -1,
> + -1, 1,
> + 1, 1,
> + 1, -1,
> + };
> + GLuint vbo;
> +
> + glClearColor(0.5, 0.5, 0.5, 1.0);
> + glClear(GL_COLOR_BUFFER_BIT);
> +
> + /* For GL core, we need to have a vertex array object bound.
> + * Otherwise, we don't particularly have to. Always use a
> + * vertex buffer object, though.
> + */
> + if (piglit_get_gl_version() >= 31) {
> + GLuint vao;
> + glGenVertexArrays(1, &vao);
> + glBindVertexArray(vao);
> + }
> + glGenBuffers(1, &vbo);
> + glBindBuffer(GL_ARRAY_BUFFER, vbo);
> + glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
> +
> + glVertexAttribPointer(vertex_location, 2, GL_FLOAT, GL_FALSE, 0, 0);
> + glEnableVertexAttribArray(vertex_location);
> +
> + float expected_color[4] = {0, 1, 0};
> + glViewport(0, 0, piglit_width, piglit_height);
> + glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
It seems like all of the above could just be
piglit_draw_rect(-1, -1, 2, 2);
That means you'll need to name your VS input piglit_vertex.
> +
> + pass &= piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,
> + expected_color);
> +
> + glDisableVertexAttribArray(vertex_location);
> + piglit_present_results();
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +generate_texture()
> +{
> + GLuint tex;
> + GLint samples = 0;
> + const GLenum target = sampler.target;
> +
> + glActiveTexture(GL_TEXTURE0);
> +
> + glGenTextures(1, &tex);
> + glBindTexture(target, tex);
> +
> + if (target == GL_TEXTURE_2D_MULTISAMPLE)
> + glTexImage2DMultisample(target, sample_count, GL_RGBA8,
> + 32, 32, GL_TRUE);
> + else
> + glTexImage3DMultisample(target, sample_count, GL_RGBA8,
> + 32, 32, 32, GL_TRUE);
> +
> + glGetTexLevelParameteriv(target, 0, GL_TEXTURE_SAMPLES, &samples);
> + if (samples != sample_count) {
> + printf("Sample count of %d not supported, got %d samples\n",
> + sample_count, samples);
> + piglit_report_result(PIGLIT_SKIP);
> + }
> +}
> +
> +int
> +generate_GLSL(enum shader_target test_stage)
> +{
> + int vs, gs = 0, fs;
> + int prog;
> +
> + static char *vs_code;
> + static char *gs_code = NULL;
> + static char *fs_code;
> +
> + switch (test_stage) {
> + case VS:
> + asprintf(&vs_code,
> + "#version %d\n"
> + "#extension GL_ARB_texture_multisample: enable\n"
> + "#extension GL_ARB_shader_texture_image_samples: enable\n"
> + "uniform %s tex;\n"
> + "in vec4 vertex;\n"
> + "flat out int samples;\n"
> + "void main()\n"
> + "{\n"
> + " samples = textureSamples(tex);\n"
> + " gl_Position = vertex;\n"
> + "}\n",
> + shader_version, sampler.name);
> + asprintf(&fs_code,
> + "#version %d\n"
> + "flat in int samples;\n"
> + "out vec4 color;\n"
> + "void main()\n"
> + "{\n"
> + " if (samples == %d) color = vec4(0,1,0,1);\n"
> + " else color = vec4(1,0,0,1);\n"
I'd be tempted to do this as
color = (samples == %d) ? vec4(0,1,0,1) : vec4(1,0,0,1);
but, meh.
Since this shader code and the fragment shader code for the GS are the
same, it seems like you ought to just use one string for both.
> + "}\n",
> + shader_version, sample_count);
> + break;
> + case GS:
> + asprintf(&vs_code,
> + "#version %d\n"
> + "in vec4 vertex;\n"
> + "out vec4 pos_to_gs;\n"
> + "void main()\n"
> + "{\n"
> + " pos_to_gs = vertex;\n"
> + "}\n",
> + shader_version);
> + asprintf(&gs_code,
> + "#version %d\n"
> + "#extension GL_ARB_texture_multisample: enable\n"
> + "#extension GL_ARB_shader_texture_image_samples: enable\n"
> + "layout(triangles) in;\n"
> + "layout(triangle_strip, max_vertices = 3) out;\n"
> + "uniform %s tex;\n"
> + "in vec4 pos_to_gs[3];\n"
> + "flat out int samples;\n"
> + "void main()\n"
> + "{\n"
> + " for (int i = 0; i < 3; i++) {\n"
> + " samples = textureSamples(tex);\n"
> + " gl_Position = pos_to_gs[i];\n"
> + " EmitVertex();\n"
> + " }\n"
> + "}\n",
> + shader_version, sampler.name);
> + asprintf(&fs_code,
> + "#version %d\n"
> + "flat in int samples;\n"
> + "out vec4 color;\n"
> + "void main()\n"
> + "{\n"
> + " if (samples == %d) color = vec4(0,1,0,1);\n"
> + " else color = vec4(1,0,0,1);\n"
> + "}\n",
> + shader_version, sample_count);
> + break;
> + case FS:
> + asprintf(&vs_code,
> + "#version %d\n"
> + "in vec4 vertex;\n"
> + "void main()\n"
> + "{\n"
> + " gl_Position = vertex;\n"
> + "}\n",
> + shader_version);
> + asprintf(&fs_code,
> + "#version %d\n"
> + "#extension GL_ARB_texture_multisample: enable\n"
> + "#extension GL_ARB_shader_texture_image_samples: enable\n"
> + "uniform %s tex;\n"
> + "out vec4 color;\n"
> + "void main()\n"
> + "{\n"
> + " if (textureSamples(tex) == %d) color = vec4(0,1,0,1);\n"
> + " else color = vec4(1,0,0,1);\n"
> + "}\n",
> + shader_version, sampler.name, sample_count);
> + break;
> + default:
> + assert(!"Should not get here.");
> + break;
> + }
> +
> + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
> + if (gs_code) {
> + gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_code);
> + }
> + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
> +
> + if (!vs || (gs_code && !gs) || !fs)
> + return 0;
> +
> + prog = glCreateProgram();
> + glAttachShader(prog, vs);
> + if (gs_code)
> + glAttachShader(prog, gs);
> + glAttachShader(prog, fs);
> + glLinkProgram(prog);
> + if (!piglit_link_check_status(prog))
> + piglit_report_result(PIGLIT_FAIL);
> +
> + return prog;
> +}
> +
> +void
> +fail_and_show_usage()
> +{
> + printf("Usage: textureSize <vs|gs|fs> <sampler type> <sample_count> [piglit args...]\n");
> + piglit_report_result(PIGLIT_SKIP);
> +}
> +
> +
> +void
> +parse_args(int argc, char **argv)
> +{
> + int i;
> + bool sampler_found = false;
> +
> + for (i = 1; i < argc; i++) {
> + if (test_stage == UNKNOWN) {
> + /* Maybe it's the shader stage? */
> + if (strcmp(argv[i], "vs") == 0) {
> + test_stage = VS;
> + continue;
> + } else if (strcmp(argv[i], "gs") == 0) {
> + test_stage = GS;
> + continue;
> + } else if (strcmp(argv[i], "fs") == 0) {
> + test_stage = FS;
> + continue;
> + }
> + }
> +
> + /* Maybe it's the sampler type? */
> + if (!sampler_found && (sampler_found = select_sampler(argv[i])))
> + continue;
> +
> + /* Maybe it's the sample count? */
> + if (sampler_found && !sample_count) {
> + sample_count = atoi(argv[i]);
> + continue;
> + }
> +
> + fail_and_show_usage();
> + }
> +
> + if (test_stage == UNKNOWN || !sampler_found)
> + fail_and_show_usage();
> +
> + if (test_stage == GS && shader_version < 150)
> + shader_version = 150;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + int prog;
> + int tex_location;
> +
> + piglit_require_extension("GL_ARB_shader_texture_image_samples");
> + require_GL_features(test_stage);
> +
> + if (sample_count) {
> + /* check it */
> + GLint max_samples;
> +
> + if (sampler.data_type == GL_INT ||
> + sampler.data_type == GL_UNSIGNED_INT) {
> + glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &max_samples);
> + if (sample_count > max_samples) {
> + printf("Sample count of %d not supported,"
> + " >MAX_INTEGER_SAMPLES\n",
> + sample_count);
> + piglit_report_result(PIGLIT_SKIP);
> + }
> + } else {
> + glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
> + if (sample_count > max_samples) {
> + printf("Sample count of %d not supported,"
> + " >MAX_SAMPLES\n",
> + sample_count);
> + piglit_report_result(PIGLIT_SKIP);
> + }
> + }
> + }
> +
> + prog = generate_GLSL(test_stage);
> + if (!prog)
> + piglit_report_result(PIGLIT_FAIL);
> +
> + tex_location = glGetUniformLocation(prog, "tex");
> + vertex_location = glGetAttribLocation(prog, "vertex");
> + glUseProgram(prog);
> + glUniform1i(tex_location, 0);
If you're only ever going to set this to zero, you don't need to set it.
Zero is the default value for all uniforms.
> +
> + compute_miplevel_info();
> + generate_texture();
> +}
More information about the Piglit
mailing list