[Piglit] [PATCH 4/7] util: Add support for vertical gradient in piglit_depth_texture()

Topi Pohjolainen topi.pohjolainen at intel.com
Thu Apr 28 19:17:07 UTC 2016


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/fbo/fbo-generatemipmap-formats.c |  3 ++-
 tests/shaders/shader_runner.c          | 15 ++++++++----
 tests/util/piglit-util-gl.c            | 43 +++++++++++++++++++++++++++-------
 tests/util/piglit-util-gl.h            | 17 +++++++++++++-
 4 files changed, 63 insertions(+), 15 deletions(-)

diff --git a/tests/fbo/fbo-generatemipmap-formats.c b/tests/fbo/fbo-generatemipmap-formats.c
index 1075e78..a1b39aa 100644
--- a/tests/fbo/fbo-generatemipmap-formats.c
+++ b/tests/fbo/fbo-generatemipmap-formats.c
@@ -81,7 +81,8 @@ create_tex(GLenum internalformat, GLenum baseformat, GLenum basetype)
 
 	if ((baseformat == GL_DEPTH_COMPONENT) || (baseformat == GL_DEPTH_STENCIL)) {
 		tex = piglit_depth_texture(GL_TEXTURE_2D, internalformat,
-					   tex_width, tex_height, 1, GL_FALSE);
+					   tex_width, tex_height, 1, GL_FALSE,
+					   DEPTH_GRAD_X);
 		if (!piglit_check_gl_error(GL_NO_ERROR))
 		        piglit_report_result(PIGLIT_FAIL);
 		if (internalformat == GL_DEPTH32F_STENCIL8) {
diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index c72de83..c11a418 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -3169,7 +3169,8 @@ piglit_display(void)
 				  &tex, &w, &h) == 3) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_depth_texture(GL_TEXTURE_2D, GL_DEPTH_COMPONENT,
-					     w, h, 1, GL_FALSE);
+					     w, h, 1, GL_FALSE,
+					     DEPTH_GRAD_X);
 			glTexParameteri(GL_TEXTURE_2D,
 					GL_TEXTURE_COMPARE_MODE,
 					GL_COMPARE_R_TO_TEXTURE);
@@ -3184,7 +3185,8 @@ piglit_display(void)
 				  &tex, &w, &h) == 3) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_depth_texture(GL_TEXTURE_RECTANGLE, GL_DEPTH_COMPONENT,
-					     w, h, 1, GL_FALSE);
+					     w, h, 1, GL_FALSE,
+					     DEPTH_GRAD_X);
 			glTexParameteri(GL_TEXTURE_RECTANGLE,
 					GL_TEXTURE_COMPARE_MODE,
 					GL_COMPARE_R_TO_TEXTURE);
@@ -3196,7 +3198,8 @@ piglit_display(void)
 				  &tex, &w) == 2) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_depth_texture(GL_TEXTURE_1D, GL_DEPTH_COMPONENT,
-					     w, 1, 1, GL_FALSE);
+					     w, 1, 1, GL_FALSE,
+					     DEPTH_GRAD_X);
 			glTexParameteri(GL_TEXTURE_1D,
 					GL_TEXTURE_COMPARE_MODE,
 					GL_COMPARE_R_TO_TEXTURE);
@@ -3208,7 +3211,8 @@ piglit_display(void)
 				  &tex, &w, &l) == 3) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_depth_texture(GL_TEXTURE_1D_ARRAY, GL_DEPTH_COMPONENT,
-					     w, l, 1, GL_FALSE);
+					     w, l, 1, GL_FALSE,
+					     DEPTH_GRAD_X);
 			glTexParameteri(GL_TEXTURE_1D_ARRAY,
 					GL_TEXTURE_COMPARE_MODE,
 					GL_COMPARE_R_TO_TEXTURE);
@@ -3220,7 +3224,8 @@ piglit_display(void)
 				  &tex, &w, &h, &l) == 4) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_depth_texture(GL_TEXTURE_2D_ARRAY, GL_DEPTH_COMPONENT,
-					     w, h, l, GL_FALSE);
+					     w, h, l, GL_FALSE,
+					     DEPTH_GRAD_X);
 			glTexParameteri(GL_TEXTURE_2D_ARRAY,
 					GL_TEXTURE_COMPARE_MODE,
 					GL_COMPARE_R_TO_TEXTURE);
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index d09ce8e..9280d1a 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -2625,15 +2625,35 @@ GLuint piglit_integer_texture(GLenum internalFormat, int w, int h, int b, int a)
 }
 
 static void
-generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
+generate_depth_layer(GLenum internalformat, int w, int h,
+		     enum depth_value_base depth_base,
+		     int layer, void *data)
 {
 	int x, y;
 	float *f = data, *f2 = data;
 	unsigned int *i = data;
 
+	if (depth_base == DEPTH_GRAD_EVEN_LAYER_X_ODD_Y)
+		depth_base = layer % 2 ? DEPTH_GRAD_Y : DEPTH_GRAD_X;
+
 	for (y = 0; y < h; y++) {
 		for (x = 0; x < w; x++) {
-			float val = (float)(x) / (w - 1);
+			float val;
+
+			switch (depth_base) {
+			case DEPTH_CONST_ZERO:
+				val = 0;
+				break;
+			case DEPTH_GRAD_X:
+				val = (float)(x) / (w - 1);
+				break;
+			case DEPTH_GRAD_Y:
+				val = (float)(y) / (h - 1);
+				break;
+			case DEPTH_GRAD_EVEN_LAYER_X_ODD_Y:
+				assert(!"should be X or Y");
+				break;
+			};
 
 			if (internalformat == GL_DEPTH_STENCIL_EXT ||
 			    internalformat == GL_DEPTH24_STENCIL8_EXT) {
@@ -2649,14 +2669,17 @@ generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
 
 static void
 setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
-                  GLenum type, int w, int h, int d, int level)
+		  GLenum type, int w, int h, int d,
+		  enum depth_value_base depth_base,
+		  int level)
 {
 	int layer;
 	void *data = malloc(w * h * 4 * sizeof(GLfloat));
 
 	switch (target) {
 	case GL_TEXTURE_1D:
-		generate_depth_layer(internalformat, w, h, 0, data);
+		generate_depth_layer(internalformat, w, h,
+				     depth_base, 0, data);
 		glTexImage1D(target, level,
 			     internalformat,
 			     w, 0,
@@ -2666,7 +2689,8 @@ setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
 	case GL_TEXTURE_1D_ARRAY:
 	case GL_TEXTURE_2D:
 	case GL_TEXTURE_RECTANGLE:
-		generate_depth_layer(internalformat, w, h, 0, data);
+		generate_depth_layer(internalformat, w, h,
+				     depth_base, 0, data);
 		glTexImage2D(target, level,
 			     internalformat,
 			     w, h, 0,
@@ -2679,7 +2703,9 @@ setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
 			     w, h, d, 0,
 			     format, type, NULL);
 		for (layer = 0; layer < d; layer++) {
-			generate_depth_layer(internalformat, w, h, layer, data);
+			generate_depth_layer(internalformat, w, h,
+					     depth_base, layer,
+					     data);
 			glTexSubImage3D(target, level,
 					0, 0, layer, w, h, 1,
 					format, type, data);
@@ -2707,7 +2733,8 @@ setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
  * \return the new texture object id
  */
 GLuint
-piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d, GLboolean mip)
+piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d, 
+		     GLboolean mip, enum depth_value_base depth_base)
 {
 	int size, level;
 	GLuint tex;
@@ -2743,7 +2770,7 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 
 	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
 		setup_depth_level(target, internalformat, format, type,
-                                  w, h, d, level);
+                                  w, h, d, depth_base, level);
 
 		if (!mip)
 			break;
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 956804b..8a57610 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -46,6 +46,20 @@ extern const unsigned int fdo_bitmap_height;
 extern bool piglit_is_core_profile;
 
 /**
+ * Tells if the gradient content for depth texture is built vertically
+ * (DEPTH_GRAD_Y) or horizontally (DEPTH_GRAD_Y) - constant zero simply sets
+ * all the values to zero.
+ * Last option (DEPTH_GRAD_EVEN_LAYER_X_ODD_Y) varies the direction between
+ * layers allowing off-by-one layer accesses to be detected.
+ */
+enum depth_value_base {
+	DEPTH_CONST_ZERO,
+	DEPTH_GRAD_X,
+	DEPTH_GRAD_Y,
+	DEPTH_GRAD_EVEN_LAYER_X_ODD_Y
+};
+
+/**
  * Determine if the API is OpenGL ES.
  */
 bool piglit_is_gles(void);
@@ -263,7 +277,8 @@ GLubyte *piglit_rgbw_image_ubyte(int w, int h, GLboolean alpha);
 GLuint piglit_rgbw_texture(GLenum internalFormat, int w, int h, GLboolean mip,
 		    GLboolean alpha, GLenum basetype);
 GLuint piglit_integer_texture(GLenum internalFormat, int w, int h, int b, int a);
-GLuint piglit_depth_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
+GLuint piglit_depth_texture(GLenum target, GLenum format, int w, int h, int d,
+                            GLboolean mip, enum depth_value_base depth);
 GLuint piglit_array_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
 GLuint piglit_multisample_texture(GLenum target, GLenum tex,
 				  GLenum internalFormat,
-- 
2.5.5



More information about the Piglit mailing list