[Mesa-dev] [PATCH] initial ARB_texture_rgb10_a2ui test (v2)
Dave Airlie
airlied at gmail.com
Sun Nov 27 11:16:37 PST 2011
From: Dave Airlie <airlied at redhat.com>
This test tries to upload the texture in RGBA/BGRA and 10_10_10_2/2_10_10_10_REV
type/format combinations.
v2: improve test to be less cut-n-paste from older tests and make it a lot
easier to read.
v2 passes on nvidia binary (joi on #nouveau tested it for me), and fails miserably on fglrx on r600 hw.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
tests/spec/CMakeLists.txt | 1 +
.../spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt | 17 ++
tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt | 1 +
.../arb_texture_rgb10_a2ui/texture-rgb10a2ui.c | 263 ++++++++++++++++++++
4 files changed, 282 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
create mode 100644 tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
create mode 100644 tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 863d583..778fec8 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -37,3 +37,4 @@ add_subdirectory (ext_texture_integer)
add_subdirectory (arb_draw_buffers)
add_subdirectory (oes_draw_texture)
add_subdirectory (arb_blend_func_extended)
+add_subdirectory (arb_texture_rgb10_a2ui)
diff --git a/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
new file mode 100644
index 0000000..683c075
--- /dev/null
+++ b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
@@ -0,0 +1,17 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+ ${GLUT_INCLUDE_DIR}
+ ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+ piglitutil
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+ ${GLUT_glut_LIBRARY}
+)
+
+add_executable (arb_texture_rgb10_a2ui-texture texture-rgb10a2ui.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c b/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
new file mode 100644
index 0000000..dcea88c
--- /dev/null
+++ b/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2011 Dave Airlie
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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
+ * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
+ * 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
+ * Tests GL_ARB_texture_rgb10_a2ui formats/upload paths.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static const char *TestName = "texture-integer";
+
+static GLint TexWidth = 16, TexHeight = 16;
+static GLuint Texture;
+
+static GLint BiasUniform = -1, TexUniform = -1;
+
+struct format_info
+{
+ const char *Name;
+ GLenum IntFormat, BaseFormat, Type;
+};
+
+static const struct format_info Formats[] = {
+ { "GL_RGB10_A2UI", GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT_10_10_10_2 },
+ { "GL_RGB10_A2UI (rev)", GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT_2_10_10_10_REV },
+ { "GL_RGB10_A2UI (bgra)", GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, GL_UNSIGNED_INT_10_10_10_2 },
+ { "GL_RGB10_A2UI (bgra-rev)", GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, GL_UNSIGNED_INT_2_10_10_10_REV },
+};
+
+static const char *FragShaderText =
+ "#version 130\n"
+ "uniform vec4 bias; \n"
+ "uniform isampler2D tex; \n"
+ "void main() \n"
+ "{ \n"
+ " vec4 t = vec4(texture(tex, gl_TexCoord[0].xy)); \n"
+ " gl_FragColor = t + bias; \n"
+ "} \n";
+
+static GLuint FragShader, Program;
+
+static void
+fill_array(int comps, int texels, void *buf, int type,
+ const int val[4])
+{
+ int i;
+ GLuint *b = (GLuint *)buf;
+
+ if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
+ for (i = 0; i < texels; i++) {
+ b[i] = (val[0] & 0x3ff) << 0 |
+ (val[1] & 0x3ff) << 10 |
+ (val[2] & 0x3ff) << 20 |
+ (val[3] & 0x3) << 30;
+ }
+ } else if (type == GL_UNSIGNED_INT_10_10_10_2) {
+ for (i = 0; i < texels; i++) {
+ b[i] = (val[3] & 0x3) << 0 |
+ (val[2] & 0x3ff) << 2 |
+ (val[1] & 0x3ff) << 12 |
+ (val[0] & 0x3ff) << 22;
+ }
+ }
+}
+
+static GLboolean
+check_error(const char *file, int line)
+{
+ GLenum err = glGetError();
+ if (err) {
+ fprintf(stderr, "%s: error 0x%x at %s:%d\n",
+ TestName, err, file, line);
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+
+/** \return GL_TRUE for pass, GL_FALSE for fail */
+static GLboolean
+test_format(const struct format_info *info)
+{
+ const int max = 1023;
+ const int comps = 4;
+ const int texels = TexWidth * TexHeight;
+ const int w = piglit_width / 10;
+ const int h = piglit_height / 10;
+ const float error = 2.0 / 255.0; /* XXX fix */
+ GLfloat expected[4];
+ void *buf;
+ int value[4];
+ GLfloat result[4], bias[4];
+ GLint f;
+ GLfloat temp;
+
+ /* don't use random values, just pick some */
+ value[0] = 355 % max;
+ value[1] = 768 % max;
+ value[2] = 423 % max;
+ value[3] = 1;
+
+ /* alloc, fill texture image */
+ buf = malloc(texels * 4);
+ fill_array(comps, texels, buf, info->Type, value);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
+ info->BaseFormat, info->Type, buf);
+
+ if (check_error(__FILE__, __LINE__))
+ return GL_FALSE;
+
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
+ &f);
+ /*
+ assert(f == info->IntFormat);
+ */
+
+ /* setup expected polygon color */
+ expected[0] = 0.25;
+ expected[1] = 0.50;
+ expected[2] = 0.75;
+ expected[3] = 1.00;
+
+ switch (info->BaseFormat) {
+ case GL_BGRA_INTEGER_EXT:
+ expected[2] = 0.25;
+ expected[0] = 0.75;
+ temp = value[2];
+ value[2] = value[0];
+ value[0] = temp;
+ break;
+ case GL_RGBA_INTEGER_EXT:
+ default:
+ break;
+ }
+
+ /* compute, set test bias */
+ bias[0] = expected[0] - value[0];
+ bias[1] = expected[1] - value[1];
+ bias[2] = expected[2] - value[2];
+ bias[3] = expected[3] - value[3];
+ glUniform4fv(BiasUniform, 1, bias);
+
+ /* draw */
+ glClearColor(0, 1, 1, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex2f(0, 0);
+ glTexCoord2f(1, 0); glVertex2f(w, 0);
+ glTexCoord2f(1, 1); glVertex2f(w, h);
+ glTexCoord2f(0, 1); glVertex2f(0, h);
+ glEnd();
+
+ if (check_error(__FILE__, __LINE__))
+ return GL_FALSE;
+
+ /* test */
+ glReadPixels(w/2, h/2, 1, 1, GL_RGBA, GL_FLOAT, result);
+
+ if (check_error(__FILE__, __LINE__))
+ return GL_FALSE;
+
+ if (fabsf(result[0] - expected[0]) > error ||
+ fabsf(result[1] - expected[1]) > error ||
+ fabsf(result[2] - expected[2]) > error ||
+ fabsf(result[3] - expected[3]) > error) {
+ fprintf(stderr, "%s: failure with format %s:\n",
+ TestName, info->Name);
+ fprintf(stderr, " texture color = %d, %d, %d, %d\n",
+ value[0], value[1], value[2], value[3]);
+ fprintf(stderr, " expected color = %g, %g, %g, %g\n",
+ expected[0], expected[1], expected[2], expected[3]);
+ fprintf(stderr, " result color = %g, %g, %g, %g\n",
+ result[0], result[1], result[2], result[3]);
+ return GL_FALSE;
+ }
+
+ piglit_present_results();
+
+ free(buf);
+
+ return GL_TRUE;
+}
+
+
+static GLboolean
+test_general_formats(void)
+{
+ int f;
+ GLboolean ret = GL_TRUE;
+
+ for (f = 0; f < ARRAY_SIZE(Formats); f++) {
+ if (!test_format(&Formats[f]))
+ ret = GL_FALSE;
+ }
+ return ret;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ if (!test_general_formats())
+ return PIGLIT_FAIL;
+
+ return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_extension("GL_ARB_texture_rgb10_a2ui");
+ piglit_require_GLSL_version(130);
+
+ FragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+ FragShaderText);
+ assert(FragShader);
+
+ Program = piglit_link_simple_program(0, FragShader);
+
+ glUseProgram(Program);
+
+ BiasUniform = glGetUniformLocation(Program, "bias");
+ TexUniform = glGetUniformLocation(Program, "tex");
+
+ glUniform1i(TexUniform, 0); /* tex unit zero */
+
+ (void) check_error(__FILE__, __LINE__);
+
+ glGenTextures(1, &Texture);
+ glBindTexture(GL_TEXTURE_2D, Texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ (void) check_error(__FILE__, __LINE__);
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
--
1.7.1
More information about the mesa-dev
mailing list