[Piglit] [PATCH] arb_texture_view: convert sampling-2d-array-* to GLES compatibility

Ilia Mirkin imirkin at alum.mit.edu
Sun Sep 18 05:13:58 UTC 2016


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 tests/all.py                                       |  6 ++
 tests/spec/arb_texture_view/CMakeLists.gles3.txt   |  3 +
 .../sampling-2d-array-as-2d-layer.c                | 72 +++++++++++++---------
 .../sampling-2d-array-as-cubemap-array.c           | 63 ++++++++++++-------
 .../sampling-2d-array-as-cubemap.c                 | 59 +++++++++++-------
 5 files changed, 129 insertions(+), 74 deletions(-)

diff --git a/tests/all.py b/tests/all.py
index 4a5b3e6..f57be72 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2595,6 +2595,12 @@ with profile.group_manager(
     g(['arb_texture_view-rendering-layers_gles3'], 'rendering-layers')
     g(['arb_texture_view-rendering-levels_gles3'], 'rendering-levels')
     g(['arb_texture_view-rendering-target_gles3'], 'rendering-target')
+    g(['arb_texture_view-sampling-2d-array-as-cubemap_gles3'],
+      'sampling-2d-array-as-cubemap')
+    g(['arb_texture_view-sampling-2d-array-as-cubemap-array_gles3'],
+      'sampling-2d-array-as-cubemap-array')
+    g(['arb_texture_view-sampling-2d-array-as-2d-layer_gles3'],
+      'sampling-2d-array-as-2d-layer')
 
 with profile.group_manager(
         PiglitGLTest,
diff --git a/tests/spec/arb_texture_view/CMakeLists.gles3.txt b/tests/spec/arb_texture_view/CMakeLists.gles3.txt
index 02ce468..2096f20 100644
--- a/tests/spec/arb_texture_view/CMakeLists.gles3.txt
+++ b/tests/spec/arb_texture_view/CMakeLists.gles3.txt
@@ -4,3 +4,6 @@ piglit_add_executable(arb_texture_view-rendering-formats_gles3 rendering-formats
 piglit_add_executable(arb_texture_view-rendering-layers_gles3 rendering_layers.c common.c)
 piglit_add_executable(arb_texture_view-rendering-levels_gles3 rendering_levels.c common.c)
 piglit_add_executable(arb_texture_view-rendering-target_gles3 rendering_target.c common.c)
+piglit_add_executable(arb_texture_view-sampling-2d-array-as-2d-layer_gles3 sampling-2d-array-as-2d-layer.c)
+piglit_add_executable(arb_texture_view-sampling-2d-array-as-cubemap_gles3 sampling-2d-array-as-cubemap.c)
+piglit_add_executable(arb_texture_view-sampling-2d-array-as-cubemap-array_gles3 sampling-2d-array-as-cubemap-array.c)
diff --git a/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c b/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
index 8189044..e6b49d1 100644
--- a/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
+++ b/tests/spec/arb_texture_view/sampling-2d-array-as-2d-layer.c
@@ -33,13 +33,14 @@
 
 PIGLIT_GL_TEST_CONFIG_BEGIN
 	config.supports_gl_compat_version = 30;
-//	config.supports_gl_core_version = 32;
+	config.supports_gl_es_version = 31;
 	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
 
-static const float green[] = {0, 1, 0, 1};
-static const float red[] = {1, 0, 0, 1};
+static const GLubyte green[] = {0, 255, 0, 255};
+static const float greenf[] = {0, 1.0f, 0, 1.0f};
+static const GLubyte red[] = {255, 0, 0, 255};
 
 typedef struct Params {
 	int num_layers;
@@ -62,9 +63,9 @@ static const Params testparams[] = {
 	{ 3, 35, 67, "35x67" }
 };
 
-static float *makesolidimage(int w, int h, const float color[4])
+static GLubyte *makesolidimage(int w, int h, const GLubyte color[4])
 {
-	float *p = malloc(w * h * 4 * sizeof(GLfloat));
+	GLubyte *p = malloc(w * h * 4 * sizeof(GLubyte));
 	size_t n;
 	assert(p);
 	for (n = 0; n < w * h; n++) {
@@ -82,7 +83,7 @@ test_single_layer(const Params* p, int layer)
 	int l;
 	GLuint tex_src, tex_view;
 	GLboolean pass;
-	GLfloat *image;
+	GLubyte *image;
 
 	assert(layer < p->num_layers);
 
@@ -95,14 +96,14 @@ test_single_layer(const Params* p, int layer)
 	image = makesolidimage(p->width, p->height, red);
 	for (l = 0; l < p->num_layers; l++) {
 		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
-				p->width, p->height, 1, GL_RGBA, GL_FLOAT, image);
+				p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
 	}
 
 	/* make layer to check red, but green for pixel at (0,0) which should be the only one sampled */
 	memcpy(image, green, sizeof(green));
 
 	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, layer,
-			p->width, p->height, 1, GL_RGBA, GL_FLOAT, image);
+			p->width, p->height, 1, GL_RGBA, GL_UNSIGNED_BYTE, image);
 
 	free(image);
 
@@ -120,7 +121,7 @@ test_single_layer(const Params* p, int layer)
 	/* draw it! */
 	piglit_draw_rect(-1, -1, 2, 2);
 
-	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
+	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf);
 	if (!pass) {
 		printf("layer %d failed\n", layer);
 	}
@@ -158,35 +159,48 @@ piglit_display(void)
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
+#ifdef PIGLIT_USE_OPENGL
+#define GLSL_VERSION "130"
+#else
+#define GLSL_VERSION "310 es"
+#endif
+
+static const char *vs =
+	"#version " GLSL_VERSION "\n"
+	"in vec4 piglit_vertex;\n"
+	"void main() { \n"
+	"	gl_Position = piglit_vertex;\n"
+	"}\n";
+
+static const char *fs =
+	"#version " GLSL_VERSION "\n"
+	"#ifdef GL_ES\n"
+	"precision highp float;\n"
+	"precision highp sampler2D;\n"
+	"#endif\n"
+	"uniform sampler2D tex;\n"
+	"out vec4 color;\n"
+	"void main() { \n"
+	"	ivec2 size = textureSize(tex, 0);\n"
+	/* texel in (0,0) should be the only green texel in the entire texture */
+	"	vec2 offset = vec2(0.5/float(size.x), 0.5/float(size.y));\n"
+	"	color = vec4(texture(tex, offset).xyz, 1.0);\n"
+	"}\n";
+
 void
 piglit_init(int argc, char **argv)
 {
 	int tex_loc_view, prog_view;
-	char *vsCode;
-	char *fsCode;
 
+#ifdef PIGLIT_USE_OPENGL
 	piglit_require_extension("GL_ARB_texture_view");
 	piglit_require_extension("GL_ARB_texture_storage");
+#else
+	piglit_require_extension("GL_OES_texture_view");
+#endif
 
 	/* setup shaders and program object for texture rendering */
-	vsCode =
-		 "#version 130\n"
-		 "void main()\n"
-		 "{\n"
-		 "    gl_Position = gl_Vertex;\n"
-		 "}\n";
-	fsCode =
-		 "#version 130\n"
-		 "uniform sampler2D tex;\n"
-		 "void main()\n"
-		 "{\n"
-		 "   ivec2 size = textureSize(tex, 0);\n"
-		 /* texel in (0,0) should be the only green texel in the entire texture */
-		 "   vec2 offset = vec2(0.5/float(size.x), 0.5/float(size.y));\n"
-		 "   vec4 color	= texture(tex, offset);\n"
-		 "   gl_FragColor = vec4(color.xyz, 1.0);\n"
-		 "}\n";
-	prog_view = piglit_build_simple_program(vsCode, fsCode);
+	prog_view = piglit_build_simple_program(vs, fs);
 	tex_loc_view = glGetUniformLocation(prog_view, "tex");
 
 	glUseProgram(prog_view);
diff --git a/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap-array.c b/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap-array.c
index 52d6328..6d7574c 100644
--- a/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap-array.c
+++ b/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap-array.c
@@ -34,12 +34,14 @@
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	config.supports_gl_compat_version = 30;
+	config.supports_gl_es_version = 31;
 	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
 
-static float green[] = {0, 1, 0, 1};
-static float red[] = {1, 0, 0, 1};
+static const GLubyte green[] = {0, 255, 0, 255};
+static const float greenf[] = {0, 1.0f, 0, 1.0f};
+static const GLubyte red[] = {255, 0, 0, 255};
 
 enum piglit_result
 piglit_display(void)
@@ -52,41 +54,56 @@ piglit_display(void)
 
 	piglit_draw_rect(-1, -1, 2, 2);
 
-	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
+	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf);
 
 	piglit_present_results();
 
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
+#ifdef PIGLIT_USE_OPENGL
+#define GLSL_VERSION "130"
+#else
+#define GLSL_VERSION "310 es"
+#endif
+
+static const char *vs =
+	"#version " GLSL_VERSION "\n"
+	"in vec4 piglit_vertex;\n"
+	"void main() { \n"
+	"	gl_Position = piglit_vertex;\n"
+	"}\n";
+
+static const char *fs =
+	"#version " GLSL_VERSION "\n"
+	"#extension GL_ARB_texture_cube_map_array: enable\n"
+	"#extension GL_OES_texture_cube_map_array: enable\n"
+	"#ifdef GL_ES\n"
+	"precision highp float;\n"
+	"precision highp samplerCubeArray;\n"
+	"#endif\n"
+	"uniform samplerCubeArray tex;\n"
+	"out vec4 color;\n"
+	"void main() { \n"
+	"	color = vec4(texture(tex, vec4(-1, 0, 0, 1)).xyz, 1.0);\n"
+	"}\n";
+
 void
 piglit_init(int argc, char **argv)
 {
-	char *vsCode;
-	char *fsCode;
 	int tex_loc_cube, prog_cube, l;
 	GLuint tex_2DArray, tex_Cube;
 
+#ifdef PIGLIT_USE_OPENGL
 	piglit_require_extension("GL_ARB_texture_view");
 	piglit_require_extension("GL_ARB_texture_cube_map_array");
+#else
+	piglit_require_extension("GL_OES_texture_view");
+	piglit_require_extension("GL_OES_texture_cube_map_array");
+#endif
 
 	/* setup shaders and program object for Cube rendering */
-	(void)!asprintf(&vsCode,
-		 "void main()\n"
-		 "{\n"
-		 "    gl_Position = gl_Vertex;\n"
-		 "}\n");
-	(void)!asprintf(&fsCode,
-		 "#extension GL_ARB_texture_cube_map_array: require\n"
-		 "uniform samplerCubeArray tex;\n"
-		 "void main()\n"
-		 "{\n"
-		 "   vec4 color	= texture(tex, vec4(-1, 0, 0, 1));\n"
-		 "   gl_FragColor = vec4(color.xyz, 1.0);\n"
-		 "}\n");
-	prog_cube = piglit_build_simple_program(vsCode, fsCode);
-	free(fsCode);
-	free(vsCode);
+	prog_cube = piglit_build_simple_program(vs, fs);
 	tex_loc_cube = glGetUniformLocation(prog_cube, "tex");
 
 	glGenTextures(1, &tex_2DArray);
@@ -97,11 +114,11 @@ piglit_init(int argc, char **argv)
 	/* load each array layer with red */
 	for (l = 0; l < 16; l++) {
 		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
-				1, 1, 1, GL_RGBA, GL_FLOAT, red);
+				1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red);
 	}
 	/* make array layer 9 have green */
 	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 9,
-			1, 1, 1, GL_RGBA, GL_FLOAT, green);
+			1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green);
 
 	glGenTextures(1, &tex_Cube);
 	/* the texture view starts at layer 2, so face 1 (-X) of
diff --git a/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap.c b/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap.c
index eaee0a0..fbfe99a 100644
--- a/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap.c
+++ b/tests/spec/arb_texture_view/sampling-2d-array-as-cubemap.c
@@ -34,12 +34,14 @@
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	config.supports_gl_compat_version = 30;
+	config.supports_gl_es_version = 31;
 	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
 
-static float green[] = {0, 1, 0, 1};
-static float red[] = {1, 0, 0, 1};
+static const GLubyte green[] = {0, 255, 0, 255};
+static const float greenf[] = {0, 1.0f, 0, 1.0f};
+static const GLubyte red[] = {255, 0, 0, 255};
 
 enum piglit_result
 piglit_display(void)
@@ -52,39 +54,52 @@ piglit_display(void)
 
 	piglit_draw_rect(-1, -1, 2, 2);
 
-	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
+	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, greenf);
 
 	piglit_present_results();
 
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
+#ifdef PIGLIT_USE_OPENGL
+#define GLSL_VERSION "130"
+#else
+#define GLSL_VERSION "310 es"
+#endif
+
+static const char *vs =
+	"#version " GLSL_VERSION "\n"
+	"in vec4 piglit_vertex;\n"
+	"void main() { \n"
+	"	gl_Position = piglit_vertex;\n"
+	"}\n";
+
+static const char *fs =
+	"#version " GLSL_VERSION "\n"
+	"#ifdef GL_ES\n"
+	"precision highp float;\n"
+	"precision highp samplerCube;\n"
+	"#endif\n"
+	"uniform samplerCube tex;\n"
+	"out vec4 color;\n"
+	"void main() { \n"
+	"	color = vec4(texture(tex, vec3(-1, 0, 0)).xyz, 1.0);\n"
+	"}\n";
+
 void
 piglit_init(int argc, char **argv)
 {
-	char *vsCode;
-	char *fsCode;
 	int tex_loc_cube, prog_cube, l;
 	GLuint tex_2DArray, tex_Cube;
 
+#ifdef PIGLIT_USE_OPENGL
 	piglit_require_extension("GL_ARB_texture_view");
+#else
+	piglit_require_extension("GL_OES_texture_view");
+#endif
 
 	/* setup shaders and program object for Cube rendering */
-	(void)!asprintf(&vsCode,
-		 "void main()\n"
-		 "{\n"
-		 "    gl_Position = gl_Vertex;\n"
-		 "}\n");
-	(void)!asprintf(&fsCode,
-		 "uniform samplerCube tex;\n"
-		 "void main()\n"
-		 "{\n"
-		 "   vec4 color	= textureCube(tex, vec3(-1, 0, 0));\n"
-		 "   gl_FragColor = vec4(color.xyz, 1.0);\n"
-		 "}\n");
-	prog_cube = piglit_build_simple_program(vsCode, fsCode);
-	free(fsCode);
-	free(vsCode);
+	prog_cube = piglit_build_simple_program(vs, fs);
 	tex_loc_cube = glGetUniformLocation(prog_cube, "tex");
 
 	glGenTextures(1, &tex_2DArray);
@@ -95,11 +110,11 @@ piglit_init(int argc, char **argv)
 	/* load each array layer with red */
 	for (l = 0; l < 8; l++) {
 		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, l,
-				1, 1, 1, GL_RGBA, GL_FLOAT, red);
+				1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, red);
 	}
 	/* make array layer 3 have green */
 	glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 3,
-			1, 1, 1, GL_RGBA, GL_FLOAT, green);
+			1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, green);
 
 	glGenTextures(1, &tex_Cube);
 	/* the texture view starts at layer 2, so face 1 (-X) will have green */
-- 
2.7.3



More information about the Piglit mailing list