[Piglit] [PATCH] Add test to verify glTexSubImage2D() with depth formats

2014-08-05 Thread Anuj Phogat
This test verifies the bug fix in i965 drivers in mesa commit 984a02b.
Reproduces another bug in the driver with GL_DEPTH_COMPONENT16
internal format.

Signed-off-by: Anuj Phogat 
---
 tests/texturing/CMakeLists.gl.txt   |   1 +
 tests/texturing/texsubimage-depth-formats.c | 196 
 2 files changed, 197 insertions(+)
 create mode 100644 tests/texturing/texsubimage-depth-formats.c

diff --git a/tests/texturing/CMakeLists.gl.txt 
b/tests/texturing/CMakeLists.gl.txt
index b121163..d2fdef5 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -75,6 +75,7 @@ piglit_add_executable (texwrap texwrap.c)
 piglit_add_executable (depth-tex-modes  depth-tex-modes.c 
depth-tex-modes-common.c)
 piglit_add_executable (depth-tex-modes-rg   depth-tex-modes-rg.c 
depth-tex-modes-common.c)
 piglit_add_executable (depth-tex-modes-glsl depth-tex-modes-glsl.c)
+piglit_add_executable (texsubimage-depth-formats texsubimage-depth-formats.c)
 piglit_add_executable (depth-tex-compare depth-tex-compare.c)
 piglit_add_executable (depth-cube-map depth-cube-map.c)
 piglit_add_executable (sized-texture-format-channels 
sized-texture-format-channels.c)
diff --git a/tests/texturing/texsubimage-depth-formats.c 
b/tests/texturing/texsubimage-depth-formats.c
new file mode 100644
index 000..ed0508d
--- /dev/null
+++ b/tests/texturing/texsubimage-depth-formats.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright © 2014 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 texsubimage-depth-formats.c
+ *
+ * Test glTexSubimage2D() with different depth formats and X, Y offsets.
+ **/
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+   config.supports_gl_compat_version = 10;
+
+   config.window_width = 128;
+   config.window_height = 128;
+   config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static GLuint tex[4];
+struct size {
+   int width, height;
+};
+
+/* For ease of testing, use even dimensions. */
+static const struct size tex_size[] = {
+   {   6,  12 },
+   {   8,  14 },
+   {  12,  22 },
+   {  16,  32 },
+   { 130,  64 }
+};
+
+struct format_info {
+   const char *name;
+   GLenum internal_format, format, type;
+   int size;
+};
+static const struct format_info formats[] = {
+   { "GL_DEPTH_COMPONENT16",  GL_DEPTH_COMPONENT16,  GL_DEPTH_COMPONENT, 
GL_UNSIGNED_SHORT, sizeof(short) },
+   { "GL_DEPTH_COMPONENT32F", GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, 
GL_FLOAT,  sizeof(float) },
+   { "GL_DEPTH24_STENCIL8",   GL_DEPTH24_STENCIL8,   GL_DEPTH_STENCIL,   
GL_UNSIGNED_INT_24_8,  sizeof(int) },
+   { "GL_DEPTH32F_STENCIL8",  GL_DEPTH32F_STENCIL8,  GL_DEPTH_STENCIL,   
GL_FLOAT_32_UNSIGNED_INT_24_8_REV, sizeof(int) + sizeof(float) }
+};
+
+static void
+load_texture(int formats_idx, int tex_size_idx)
+{
+   unsigned i;
+   unsigned w_by_2 = tex_size[tex_size_idx].width / 2;
+   unsigned h_by_2 =  tex_size[tex_size_idx].height / 2;
+   unsigned n_pixels = w_by_2 * h_by_2;
+   unsigned buffer_size = n_pixels * formats[formats_idx].size;
+   void* texDepthData[4];
+
+   for (i = 0; i < 4; i++)
+   texDepthData[i] = malloc(buffer_size);
+
+   for (i = 0; i < n_pixels; i++) {
+   switch (formats[formats_idx].type) {
+   case GL_UNSIGNED_INT_24_8:
+   ((unsigned *)texDepthData[0])[i] = 0x40BB;
+   ((unsigned *)texDepthData[1])[i] = 0x7FBB;
+   ((unsigned *)texDepthData[2])[i] = 0xC0BB;
+   ((unsigned *)texDepthData[3])[i] = 0xFFBB;
+   break;
+   case GL_UNSIGNED_SHORT:
+   ((unsigned short *)tex

[Piglit] [PATCH] glsl-1.10/fragdepth: add new, simple test of gl_FragDepth

2014-08-05 Thread Brian Paul
---
 tests/all.py |1 +
 tests/spec/glsl-1.10/execution/CMakeLists.gl.txt |1 +
 tests/spec/glsl-1.10/execution/fragdepth.c   |  115 ++
 3 files changed, 117 insertions(+)
 create mode 100644 tests/spec/glsl-1.10/execution/fragdepth.c

diff --git a/tests/all.py b/tests/all.py
index 9d7a861..36436b8 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1002,6 +1002,7 @@ add_shader_test_dir(spec['glsl-1.10']['execution'],
 os.path.join(testsDir, 'spec', 'glsl-1.10', 'execution'),
 recursive=True)
 add_concurrent_test(spec['glsl-1.10']['execution'], 
'glsl-render-after-bad-attach')
+add_concurrent_test(spec['glsl-1.10']['execution'], 'glsl-1.10-fragdepth')
 spec['glsl-1.10']['execution']['clipping'] = {}
 for mode in ['fixed', 'pos_clipvert', 'clipvert_pos']:
 cmdline = 'clip-plane-transformation ' + mode
diff --git a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt 
b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
index 311fe01..0ddc221 100644
--- a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
+++ b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
@@ -12,3 +12,4 @@ link_libraries (
 )
 
 piglit_add_executable (glsl-render-after-bad-attach 
glsl-render-after-bad-attach.c)
+piglit_add_executable (glsl-1.10-fragdepth fragdepth.c)
diff --git a/tests/spec/glsl-1.10/execution/fragdepth.c 
b/tests/spec/glsl-1.10/execution/fragdepth.c
new file mode 100644
index 000..61521ca
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/fragdepth.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2014 VMware, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * Test GLSL gl_FragDepth output.
+ * We draw overlapping red and green quads.  The red quad is at Z=0
+ * while the green quad's fragment depths vary from left to right.
+ * Should see intersecting quads.
+ *
+ * Brian Paul
+ * 5 August 2014
+ */
+
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+   config.supports_gl_compat_version = 20;
+   config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const char *vs_text =
+   "varying float z; \n"
+   "void main() {\n"
+   "   gl_FrontColor = gl_Color; \n"
+   "   gl_Position = gl_Vertex;\n"
+   "   // convert Z from [-1, 1] to [0, 1] \n"
+   "   z = gl_Vertex.x * 0.5 + 0.5; \n"
+   "}\n";
+static const char *fs_text =
+   "varying float z; \n"
+   "void main() { \n"
+   "   gl_FragDepth = z; \n"
+   "   gl_FragColor = gl_Color; \n"
+   "}\n";
+
+static GLuint program;
+
+
+enum piglit_result
+piglit_display(void)
+{
+   static const float red[3] = {1.0, 0.0, 0.0};
+   static const float green[3] = {0.0, 1.0, 0.0};
+   int x = piglit_width / 2;
+   int y = piglit_height / 2;
+
+   glViewport(0, 0, piglit_width, piglit_height);
+   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+   /* Draw a red quad at z = 0 */
+   glUseProgram(0);
+   glColor3f(1, 0, 0);
+   glBegin(GL_TRIANGLE_FAN);
+   glVertex2f(-0.5, -0.5);
+   glVertex2f( 0.5, -0.5);
+   glVertex2f( 0.5,  0.5);
+   glVertex2f(-0.5,  0.5);
+   glEnd();
+
+   /* Draw green quad w/ fragment shader which writes gl_FragDepth*/
+   glUseProgram(program);
+   glColor3f(0, 1, 0);
+   glBegin(GL_TRIANGLE_FAN);
+   glVertex2f(-0.75, -0.25);
+   glVertex2f( 0.75, -0.25);
+   glVertex2f( 0.75,  0.25);
+   glVertex2f(-0.75,  0.25);
+   glEnd();
+
+   if (!piglit_probe_pixel_rgb(x-10, y, green)) {
+   return PIGLIT_FAIL;
+   }
+
+   if (!piglit_probe_pixel_rgb(x+10, y, red)) {
+   return PIGLIT_FAIL;
+   }
+
+   piglit_present_results();
+
+   return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+   piglit_require_G

Re: [Piglit] [PATCH 1/3] util: add piglit_array_texture() function

2014-08-05 Thread Brian Paul

On 08/05/2014 10:49 AM, Roland Scheidegger wrote:

Am 01.08.2014 17:07, schrieb Brian Paul:

For creating 1D/2D array textures.  Each slice of the array is a
solid color (red, green, blue, white, etc.)
---
  tests/util/piglit-util-gl.c |   97 ---
  tests/util/piglit-util-gl.h |1 +
  2 files changed, 92 insertions(+), 6 deletions(-)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 1a8ee18..bbea519 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -35,6 +35,13 @@
   */
  static const char **gl_extensions = NULL;

+static const float color_wheel[4][4] = {
+   {1, 0, 0, 1}, /* red */
+   {0, 1, 0, 1}, /* green */
+   {0, 0, 1, 1}, /* blue */
+   {1, 1, 1, 1}, /* white */
+};
+
  bool piglit_is_core_profile;

  bool piglit_is_gles(void)
@@ -2012,12 +2019,6 @@ piglit_miptree_texture()
GLfloat *data;
int size, i, level;
GLuint tex;
-   const float color_wheel[4][4] = {
-   {1, 0, 0, 1}, /* red */
-   {0, 1, 0, 1}, /* green */
-   {0, 0, 1, 1}, /* blue */
-   {1, 1, 1, 1}, /* white */
-   };

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
@@ -2376,6 +2377,90 @@ piglit_depth_texture(GLenum target, GLenum 
internalformat, int w, int h, int d,
  }

  /**
+ * Create 1D or 2D array texture in which each slice is a different color.
+ * the color pattern is red, green, blue, white, red, green, ...
+ */
+GLuint
+piglit_array_texture(GLenum target, GLenum internalformat,
+int w, int h, int d, GLboolean mip)
+{
+   float *data;
+   int size, i, level, layer;
+   GLuint tex;
+   GLenum type = GL_FLOAT, format = GL_RGBA;
+
+   if (target == GL_TEXTURE_1D_ARRAY) {
+   assert(h == 1);
+   }
+   else {
+   assert(target == GL_TEXTURE_2D_ARRAY);
+   }
+
+   glGenTextures(1, &tex);
+   glBindTexture(target, tex);
+   glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+   glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+   if (mip) {
+   glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
+   GL_LINEAR);
+   glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
+   GL_LINEAR_MIPMAP_NEAREST);
+   } else {
+   glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
+   GL_NEAREST);
+   glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
+   GL_NEAREST);
+   }

Is that on purpose that the mip case does linear filtering but the no
mip case does nearest filtering? Since it is a solid color though it
really shouldn't matter anyway.


I was just following the example of the other texture-builder functions.

-Brian




+   data = malloc(w * h * 4 * sizeof(GLfloat));
+
+   size = w > h ? w : h;
+
+   for (level = 0; size > 0; level++, size >>= 1) {
+
+   /* Create mipmap level */
+   if (target == GL_TEXTURE_1D_ARRAY) {
+   glTexImage2D(target, level, internalformat,
+w, d, 0, format, type, NULL);
+   }
+   else {
+   glTexImage3D(target, level, internalformat,
+w, h, d, 0, format, type, NULL);
+   }
+
+   for (layer = 0; layer < d; layer++) {
+   /* Set whole layer to one color */
+   for (i = 0; i < w * h; i++) {
+   memcpy(data + 4 * i,
+  color_wheel[layer %
+  ARRAY_SIZE(color_wheel)],
+  sizeof(color_wheel[0]));
+   }
+
+   if (target == GL_TEXTURE_1D_ARRAY) {
+   glTexSubImage2D(target, level,
+   0, layer, w, 1,
+   format, type, data);
+   }
+   else {
+   glTexSubImage3D(target, level,
+   0, 0, layer, w, h, 1,
+   format, type, data);
+   }
+   }
+
+   if (!mip)
+   break;
+
+   if (w > 1)
+   w >>= 1;
+   if (h > 1)
+   h >>= 1;
+   }
+   free(data);
+   return tex;
+}
+
+/**
   * Require transform feedback.
   *
   * Transform feedback may either be provided by GL 3.0 or
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 73b658e..fcd8988 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-u

Re: [Piglit] ideas for shader_runner subtesting

2014-08-05 Thread Ian Romanick
On 08/03/2014 08:39 PM, Dave Airlie wrote:
> Hi,
> 
> so I've written the FP64 test generator that spits out a test for GLSL
> 1.50 + GL_ARB_gpu_shader_fp64 but also spits out the same tests for
> GLSL 4.00
> 
> This in theory should make sure that when we do GLSL 4.00 that we have
> tests for that path as well. Now I'm sure ARB_gpu_shader5 also has a
> bunch of tests that will need to also run in a GLSL 4.00 context to
> test we get the GLSL compile enables all correct.
> 
> So I was thinking off possibly adding subtests to shader_runner, that
> if can add another section to it to run the same shader with a
> different set of #version + #extension tags,
> 
> Anyone looked into this before, or how did we handle this back in the
> GLSL 1.30 / GL3x days?

We dodged it altogether.  Mesa never supported EXT_gpu_shader4, so we
never worried about testing it.

In other cases, we usually just tested the extension, and a added few
extra tests for the core version.  UBOs are an example.  I think there
are some other cases where test generators would generate multiple
versions of the same test.  I don't think there's much of that.

I think Eric in particular was not excited about running the same 200
tests for an extension and for the indentical functionality in the core
version.  It doesn't add much coverages, but it does lengthen piglit
times.  I don't have a strong opinion either way.

> Dave.
> ___
> Piglit mailing list
> Piglit@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
> 

___
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit


Re: [Piglit] [PATCH 3/3] ext_texture_array: add simple 1D/2D array rendering tests

2014-08-05 Thread Charmaine Lee
Series looks good to me.

Reviewed-by: Charmaine Lee 


From: Piglit  on behalf of Brian Paul 

Sent: Friday, August 1, 2014 8:07 AM
To: piglit@lists.freedesktop.org
Subject: [Piglit] [PATCH 3/3] ext_texture_array: add simple 1D/2D array 
rendering tests

Check that we're sampling from the expected array slices.
---
 .../render-1darray-1slice.shader_test  |   35 +++
 .../ext_texture_array/render-1darray.shader_test   |   45 
 .../render-2darray-1slice.shader_test  |   34 +++
 .../ext_texture_array/render-2darray.shader_test   |   44 +++
 4 files changed, 158 insertions(+)
 create mode 100644 
tests/spec/ext_texture_array/render-1darray-1slice.shader_test
 create mode 100644 tests/spec/ext_texture_array/render-1darray.shader_test
 create mode 100644 
tests/spec/ext_texture_array/render-2darray-1slice.shader_test
 create mode 100644 tests/spec/ext_texture_array/render-2darray.shader_test

diff --git a/tests/spec/ext_texture_array/render-1darray-1slice.shader_test 
b/tests/spec/ext_texture_array/render-1darray-1slice.shader_test
new file mode 100644
index 000..f524c06
--- /dev/null
+++ b/tests/spec/ext_texture_array/render-1darray-1slice.shader_test
@@ -0,0 +1,35 @@
+# Test GL_TEXTURE_1D_ARRAY texture with just one layer
+[require]
+GLSL >= 1.10
+GL_EXT_texture_array
+
+[vertex shader]
+#version 110
+varying vec4 texcoords;
+void main() {
+   gl_Position = gl_Vertex;
+   texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+#version 110
+#extension GL_EXT_texture_array : enable
+varying vec4 texcoords;
+uniform sampler1DArray tex;
+uniform float layer;
+
+void main()
+{
+   vec2 p = vec2(texcoords.x, layer);
+   gl_FragColor = texture1DArray(tex, p);
+}
+
+[test]
+uniform int tex 0
+texture rgbw 1DArray 0 ( 64 , 1 )
+
+# layer=12 should get clamped to zero
+uniform float layer 12
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (1.0, 0.0, 0.0, 1.0)
+
diff --git a/tests/spec/ext_texture_array/render-1darray.shader_test 
b/tests/spec/ext_texture_array/render-1darray.shader_test
new file mode 100644
index 000..74b6154
--- /dev/null
+++ b/tests/spec/ext_texture_array/render-1darray.shader_test
@@ -0,0 +1,45 @@
+# Test GL_TEXTURE_1D_ARRAY texture with four layers
+[require]
+GLSL >= 1.10
+GL_EXT_texture_array
+
+[vertex shader]
+#version 110
+varying vec4 texcoords;
+void main() {
+   gl_Position = gl_Vertex;
+   texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+#version 110
+#extension GL_EXT_texture_array : enable
+varying vec4 texcoords;
+uniform sampler1DArray tex;
+uniform float layer;
+
+void main()
+{
+   vec2 p = vec2(texcoords.x, layer);
+   gl_FragColor = texture1DArray(tex, p);
+}
+
+[test]
+uniform int tex 0
+texture rgbw 1DArray 0 ( 64 , 4 )
+
+uniform float layer 0
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (1.0, 0.0, 0.0, 1.0)
+
+uniform float layer 1
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+
+uniform float layer 2
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (0.0, 0.0, 1.0, 1.0)
+
+uniform float layer 3
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (1.0, 1.0, 1.0, 1.0)
diff --git a/tests/spec/ext_texture_array/render-2darray-1slice.shader_test 
b/tests/spec/ext_texture_array/render-2darray-1slice.shader_test
new file mode 100644
index 000..335436d
--- /dev/null
+++ b/tests/spec/ext_texture_array/render-2darray-1slice.shader_test
@@ -0,0 +1,34 @@
+# Test GL_TEXTURE_2D_ARRAY with just one slice
+[require]
+GLSL >= 1.10
+GL_EXT_texture_array
+
+[vertex shader]
+#version 110
+varying vec4 texcoords;
+void main() {
+   gl_Position = gl_Vertex;
+   texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+#version 110
+#extension GL_EXT_texture_array : enable
+varying vec4 texcoords;
+uniform sampler2DArray tex;
+uniform float layer;
+
+void main()
+{
+   vec3 p = vec3(texcoords.xy, layer);
+   gl_FragColor = texture2DArray(tex, p);
+}
+
+[test]
+uniform int tex 0
+texture rgbw 2DArray 0 (32, 32, 1)
+
+# layer=12 should get clamped to zero
+uniform float layer 12
+draw rect -1 -1 2 2
+relative probe rgba (0.5, 0.5) (1.0, 0.0, 0.0, 1.0)
diff --git a/tests/spec/ext_texture_array/render-2darray.shader_test 
b/tests/spec/ext_texture_array/render-2darray.shader_test
new file mode 100644
index 000..189bb13
--- /dev/null
+++ b/tests/spec/ext_texture_array/render-2darray.shader_test
@@ -0,0 +1,44 @@
+[require]
+GLSL >= 1.10
+GL_EXT_texture_array
+
+[vertex shader]
+#version 110
+varying vec4 texcoords;
+void main() {
+   gl_Position = gl_Vertex;
+   texcoords = (gl_Vertex + 1.0) / 2.0;
+}
+
+[fragment shader]
+#version 110
+#extension GL_EXT_texture_array : enable
+varying vec4 texcoords;
+uniform sampler2DArray tex;
+uniform float layer;
+
+void main()
+{
+   vec3 p = vec3(texcoords.xy, layer);
+   gl_FragColor = texture2DArr

Re: [Piglit] [PATCH 1/3] util: add piglit_array_texture() function

2014-08-05 Thread Roland Scheidegger
Am 01.08.2014 17:07, schrieb Brian Paul:
> For creating 1D/2D array textures.  Each slice of the array is a
> solid color (red, green, blue, white, etc.)
> ---
>  tests/util/piglit-util-gl.c |   97 
> ---
>  tests/util/piglit-util-gl.h |1 +
>  2 files changed, 92 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 1a8ee18..bbea519 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -35,6 +35,13 @@
>   */
>  static const char **gl_extensions = NULL;
>  
> +static const float color_wheel[4][4] = {
> + {1, 0, 0, 1}, /* red */
> + {0, 1, 0, 1}, /* green */
> + {0, 0, 1, 1}, /* blue */
> + {1, 1, 1, 1}, /* white */
> +};
> +
>  bool piglit_is_core_profile;
>  
>  bool piglit_is_gles(void)
> @@ -2012,12 +2019,6 @@ piglit_miptree_texture()
>   GLfloat *data;
>   int size, i, level;
>   GLuint tex;
> - const float color_wheel[4][4] = {
> - {1, 0, 0, 1}, /* red */
> - {0, 1, 0, 1}, /* green */
> - {0, 0, 1, 1}, /* blue */
> - {1, 1, 1, 1}, /* white */
> - };
>  
>   glGenTextures(1, &tex);
>   glBindTexture(GL_TEXTURE_2D, tex);
> @@ -2376,6 +2377,90 @@ piglit_depth_texture(GLenum target, GLenum 
> internalformat, int w, int h, int d,
>  }
>  
>  /**
> + * Create 1D or 2D array texture in which each slice is a different color.
> + * the color pattern is red, green, blue, white, red, green, ...
> + */
> +GLuint
> +piglit_array_texture(GLenum target, GLenum internalformat,
> +  int w, int h, int d, GLboolean mip)
> +{
> + float *data;
> + int size, i, level, layer;
> + GLuint tex;
> + GLenum type = GL_FLOAT, format = GL_RGBA;
> +
> + if (target == GL_TEXTURE_1D_ARRAY) {
> + assert(h == 1);
> + }
> + else {
> + assert(target == GL_TEXTURE_2D_ARRAY);
> + }
> +
> + glGenTextures(1, &tex);
> + glBindTexture(target, tex);
> + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> + if (mip) {
> + glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
> + GL_LINEAR);
> + glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
> + GL_LINEAR_MIPMAP_NEAREST);
> + } else {
> + glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
> + GL_NEAREST);
> + glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
> + GL_NEAREST);
> + }
Is that on purpose that the mip case does linear filtering but the no
mip case does nearest filtering? Since it is a solid color though it
really shouldn't matter anyway.

> + data = malloc(w * h * 4 * sizeof(GLfloat));
> +
> + size = w > h ? w : h;
> +
> + for (level = 0; size > 0; level++, size >>= 1) {
> +
> + /* Create mipmap level */
> + if (target == GL_TEXTURE_1D_ARRAY) {
> + glTexImage2D(target, level, internalformat,
> +  w, d, 0, format, type, NULL);
> + }
> + else {
> + glTexImage3D(target, level, internalformat,
> +  w, h, d, 0, format, type, NULL);
> + }
> +
> + for (layer = 0; layer < d; layer++) {
> + /* Set whole layer to one color */
> + for (i = 0; i < w * h; i++) {
> + memcpy(data + 4 * i,
> +color_wheel[layer %
> +ARRAY_SIZE(color_wheel)],
> +sizeof(color_wheel[0]));
> + }
> +
> + if (target == GL_TEXTURE_1D_ARRAY) {
> + glTexSubImage2D(target, level,
> + 0, layer, w, 1,
> + format, type, data);
> + }
> + else {
> + glTexSubImage3D(target, level,
> + 0, 0, layer, w, h, 1,
> + format, type, data);
> + }
> + }
> +
> + if (!mip)
> + break;
> +
> + if (w > 1)
> + w >>= 1;
> + if (h > 1)
> + h >>= 1;
> + }
> + free(data);
> + return tex;
> +}
> +
> +/**
>   * Require transform feedback.
>   *
>   * Transform feedback may either be provided by GL 3.0 or
> diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
> index 73b658e..fcd8988 100644
> --- a/tests/util/piglit-util-gl.h
> +++ b/tests/util/piglit-util-gl.h
> @@ -203,6 +203,7 @@ GLfloat