summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/all.py4
-rw-r--r--tests/spec/arb_stencil_texturing/CMakeLists.gl.txt1
-rw-r--r--tests/spec/arb_stencil_texturing/draw_layered_miptree.c267
3 files changed, 272 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py
index b5d5f63ba..dc42c5cad 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1849,6 +1849,10 @@ with profile.group_manager(
grouptools.join('spec', 'ARB_stencil_texturing')) as g:
g(['arb_stencil_texturing-draw', 'texture'], 'draw-texture')
g(['arb_stencil_texturing-draw', 'texelFetch'], 'draw-texelFetch')
+ g(['arb_stencil_texturing-draw_layered_miptree',
+ '128', '64', '7', 'texture'], 'draw-layered-texture')
+ g(['arb_stencil_texturing-draw_layered_miptree',
+ '128', '64', '7', 'texelFetch'], 'draw-layered-texelFetch')
with profile.group_manager(
PiglitGLTest,
diff --git a/tests/spec/arb_stencil_texturing/CMakeLists.gl.txt b/tests/spec/arb_stencil_texturing/CMakeLists.gl.txt
index c9fb0abd7..186703a48 100644
--- a/tests/spec/arb_stencil_texturing/CMakeLists.gl.txt
+++ b/tests/spec/arb_stencil_texturing/CMakeLists.gl.txt
@@ -10,3 +10,4 @@ link_libraries (
piglit_add_executable (arb_stencil_texturing-blit_corrupts_state blit_corrupts_state.c)
piglit_add_executable (arb_stencil_texturing-draw draw.c)
+piglit_add_executable (arb_stencil_texturing-draw_layered_miptree draw_layered_miptree.c)
diff --git a/tests/spec/arb_stencil_texturing/draw_layered_miptree.c b/tests/spec/arb_stencil_texturing/draw_layered_miptree.c
new file mode 100644
index 000000000..89aa5d2de
--- /dev/null
+++ b/tests/spec/arb_stencil_texturing/draw_layered_miptree.c
@@ -0,0 +1,267 @@
+/*
+ * Copyright © 2016 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 draw_layered_miptree.c
+ *
+ * A more complex drawing test for GL_ARB_stencil_texturing which ensures that
+ * sampling occurs from the right position in the texture when the texture has
+ * full miptree with two layers. Miplevels for layer zero have a horizontal
+ * gradient (0 -> 255) while levels for layer one have corresponding vertical
+ * gradient.
+ *
+ * The expected output is layers zero and one side-by-side for each level
+ * separated by a blue border. Level zero is at the bottom of the framebuffer,
+ * level one on top of it and so on.
+ */
+
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#include "piglit-util-gl.h"
+
+#define MAX_TEX_BASE_WIDTH 256
+#define MAX_TEX_BASE_HEIGHT 256
+#define MAX_NUM_LEVELS 8
+#define BORDER_WIDTH 2
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+ config.window_width = MAX_TEX_BASE_WIDTH * 2 + BORDER_WIDTH;
+ config.window_height = MAX_TEX_BASE_HEIGHT * 2 +
+ (MAX_NUM_LEVELS - 1) * BORDER_WIDTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+unsigned tex_width;
+unsigned tex_height;
+unsigned num_levels;
+int loc_level;
+int loc_layer;
+int loc_width;
+int loc_height;
+
+static unsigned
+get_level_draw_offset(unsigned level)
+{
+ unsigned offset = 0;
+
+ while (level--)
+ offset += ((MAX_TEX_BASE_HEIGHT >> level) + BORDER_WIDTH);
+
+ return offset;
+}
+
+static bool
+draw_level_and_probe(unsigned level)
+{
+ const unsigned y = get_level_draw_offset(level);
+ const unsigned w = tex_width >> level;
+ const unsigned h = tex_height >> level;
+ float *horiz_expected = calloc(w * h, 3 * sizeof(float));
+ float *vert_expected = calloc(w * h, 3 * sizeof(float));
+ bool pass = true;
+ int i, j;
+
+ for (i = 0; i < h; i++) {
+ for (j = 0; j < w; j++) {
+ horiz_expected[(i * w + j) * 3] = (float)j / w;
+ vert_expected[(i * w + j) * 3] = (float)i / h;
+ }
+ }
+
+ glUniform1i(loc_level, level);
+ glUniform1i(loc_width, w);
+ glUniform1i(loc_height, h);
+
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, level);
+
+ glUniform1i(loc_layer, 0);
+ glViewport(0, y, w, h);
+ piglit_draw_rect(-1, -1, 2, 2);
+ if (!piglit_probe_image_rgb(0, y, w, h, horiz_expected)) {
+ printf(" FAIL: (level %u, layer 0).\n", level);
+ pass = false;
+ }
+
+ glUniform1i(loc_layer, 1);
+ glViewport(MAX_TEX_BASE_WIDTH + BORDER_WIDTH, y, w, h);
+ piglit_draw_rect(-1, -1, 2, 2);
+ if (!piglit_probe_image_rgb(MAX_TEX_BASE_WIDTH + BORDER_WIDTH, y,
+ w, h, vert_expected)) {
+ printf(" FAIL: (level %u, layer 1).\n", level);
+ pass = false;
+ }
+
+ free(horiz_expected);
+ free(vert_expected);
+
+ return pass;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ unsigned i;
+ bool pass = true;
+
+ glClearColor(0.0, 0.0, 1.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (i = 0; i < num_levels; ++i)
+ pass = draw_level_and_probe(i) && pass;
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+static void
+setup_texture(unsigned w, unsigned h)
+{
+ GLuint tex = piglit_depth_texture(GL_TEXTURE_2D_ARRAY,
+ GL_DEPTH24_STENCIL8,
+ w, h, 2, GL_TRUE,
+ DEPTH_GRAD_X,
+ DEPTH_GRAD_EVEN_LAYER_X_ODD_Y);
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+
+ glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_DEPTH_STENCIL_TEXTURE_MODE,
+ GL_STENCIL_INDEX);
+}
+
+static void
+setup_shader(const char *tex_func)
+{
+ char *fs;
+ int loc;
+ GLint prog;
+
+ const char *vs =
+ "#version 130\n"
+ "uniform int layer;\n"
+ "out vec3 texcoords;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ " texcoords[0] = (gl_Vertex.x + 1.0) / 2.0;\n"
+ " texcoords[1] = (gl_Vertex.y + 1.0) / 2.0;\n"
+ " texcoords[2] = float(layer);\n"
+ "}\n";
+
+ const char *fs_tmpl =
+ "#version 130\n"
+ "#extension GL_EXT_texture_array : enable\n"
+ "in vec3 texcoords;\n"
+ "ivec3 texelcoords;\n"
+ "uniform int level;\n"
+ "uniform int width;\n"
+ "uniform int height;\n"
+ "uniform usampler2DArray tex;\n"
+ "void main()\n"
+ "{\n"
+ " texelcoords[0] = int(texcoords[0] * width);\n"
+ " texelcoords[1] = int(texcoords[1] * height);\n"
+ " texelcoords[2] = int(texcoords[2]);\n"
+ " uint stencil = %s.x;\n"
+ " gl_FragColor = vec4(float(stencil) / 255.0, 0, 0, 1);\n"
+ "}\n";
+
+ asprintf(&fs, fs_tmpl, tex_func);
+ prog = piglit_build_simple_program(vs, fs);
+ free(fs);
+
+ loc = glGetUniformLocation(prog, "tex");
+ loc_level = glGetUniformLocation(prog, "level");
+ loc_layer = glGetUniformLocation(prog, "layer");
+ loc_width = glGetUniformLocation(prog, "width");
+ loc_height = glGetUniformLocation(prog, "height");
+
+ glUseProgram(prog);
+ glUniform1i(loc, 0);
+}
+
+void
+parse_args(int argc, char **argv,
+ unsigned *w, unsigned *h, unsigned *n, const char **f)
+{
+ if (argc != 5) {
+ printf("Usage: %s <width> <height> <num_levels> <tex_func>\n"
+ " where <tex_func> is a glsl texture function:\n"
+ " texture\n"
+ " texelFetch\n",
+ argv[0]);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ *w = strtoul(argv[1], NULL, 0);
+ if (!*w || *w > MAX_TEX_BASE_WIDTH) {
+ printf("invalid width=%u [1,%u]\n", *w, MAX_TEX_BASE_WIDTH);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ *h = strtoul(argv[2], NULL, 0);
+ if (!*h || *h > MAX_TEX_BASE_HEIGHT) {
+ printf("invalid height=%u [1,%u]\n", *h, MAX_TEX_BASE_HEIGHT);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ *n = strtoul(argv[3], NULL, 0);
+ if (!*n || *n > MAX_NUM_LEVELS) {
+ printf("invalid width=%u [1,%u]\n", *n, MAX_NUM_LEVELS);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ *f = NULL;
+ if (strcmp(argv[4], "texture") == 0)
+ *f = "texture(tex, texcoords)";
+
+ if (strcmp(argv[4], "texelFetch") == 0)
+ *f = "texelFetch(tex, texelcoords, 0)";
+
+ if (!*f) {
+ printf("%s is not supported\n", argv[4]);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ const char *tex_func;
+
+ piglit_require_extension("GL_ARB_stencil_texturing");
+ piglit_require_extension("GL_EXT_texture_array");
+ piglit_require_GLSL_version(130); /* for usampler2D */
+
+ parse_args(argc, argv,
+ &tex_width, &tex_height, &num_levels, &tex_func);
+
+ setup_texture(tex_width, tex_height);
+ setup_shader(tex_func);
+}