[Piglit] [PATCH 1/6] util: support instancing with piglit_draw_rect_custom

Marek Olšák maraeo at gmail.com
Sun Apr 30 14:58:34 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 tests/shaders/shader_runner.c                      |  4 +--
 .../rendezvous_by_location-5-stages.c              |  2 +-
 tests/spec/arb_texture_multisample/texelfetch.c    |  2 +-
 tests/spec/arb_texture_view/common.c               |  2 +-
 .../spec/ext_shader_samples_identical/simple-fs.c  |  2 +-
 tests/util/piglit-util-gl.c                        | 31 +++++++++++++++-------
 tests/util/piglit-util-gl.h                        |  4 +--
 7 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 2047d6c..b2eeba8 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -2975,34 +2975,34 @@ piglit_display(void)
 			piglit_draw_rect_tex(c[0], c[1], c[2], c[3],
 					     c[4], c[5], c[6], c[7]);
 		} else if (parse_str(line, "draw rect ortho patch ", &rest)) {
 			result = program_must_be_in_use();
 			program_subroutine_uniforms();
 			parse_floats(rest, c, 4, NULL);
 
 			piglit_draw_rect_custom(-1.0 + 2.0 * (c[0] / piglit_width),
 						-1.0 + 2.0 * (c[1] / piglit_height),
 						2.0 * (c[2] / piglit_width),
-						2.0 * (c[3] / piglit_height), true);
+						2.0 * (c[3] / piglit_height), true, 1);
 		} else if (parse_str(line, "draw rect ortho ", &rest)) {
 			result = program_must_be_in_use();
 			program_subroutine_uniforms();
 			parse_floats(rest, c, 4, NULL);
 
 			piglit_draw_rect(-1.0 + 2.0 * (c[0] / piglit_width),
 					 -1.0 + 2.0 * (c[1] / piglit_height),
 					 2.0 * (c[2] / piglit_width),
 					 2.0 * (c[3] / piglit_height));
 		} else if (parse_str(line, "draw rect patch ", &rest)) {
 			result = program_must_be_in_use();
 			parse_floats(rest, c, 4, NULL);
-			piglit_draw_rect_custom(c[0], c[1], c[2], c[3], true);
+			piglit_draw_rect_custom(c[0], c[1], c[2], c[3], true, 1);
 		} else if (parse_str(line, "draw rect ", &rest)) {
 			result = program_must_be_in_use();
 			program_subroutine_uniforms();
 			parse_floats(rest, c, 4, NULL);
 			piglit_draw_rect(c[0], c[1], c[2], c[3]);
 		} else if (parse_str(line, "draw instanced rect ", &rest)) {
 			int primcount;
 
 			result = program_must_be_in_use();
 			sscanf(rest, "%d %f %f %f %f",
diff --git a/tests/spec/arb_separate_shader_objects/rendezvous_by_location-5-stages.c b/tests/spec/arb_separate_shader_objects/rendezvous_by_location-5-stages.c
index 26a9c4e..9d72cb4 100644
--- a/tests/spec/arb_separate_shader_objects/rendezvous_by_location-5-stages.c
+++ b/tests/spec/arb_separate_shader_objects/rendezvous_by_location-5-stages.c
@@ -160,21 +160,21 @@ piglit_display(void)
 {
 	static const float expected[] = {
 		0.28, 0.675, 0.14, 0.405
 	};
 	bool pass;
 
 	glClearColor(0.1f, 0.1f, 0.1f, 0.1f);
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	glBindProgramPipeline(pipeline);
-	piglit_draw_rect_custom(-1, -1, 2, 2, true);
+	piglit_draw_rect_custom(-1, -1, 2, 2, true, 1);
 
 	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
 				      expected);
 
 	piglit_present_results();
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
 void piglit_init(int argc, char **argv)
 {
diff --git a/tests/spec/arb_texture_multisample/texelfetch.c b/tests/spec/arb_texture_multisample/texelfetch.c
index 981e3c6..1f1a2f9 100644
--- a/tests/spec/arb_texture_multisample/texelfetch.c
+++ b/tests/spec/arb_texture_multisample/texelfetch.c
@@ -120,21 +120,21 @@ piglit_display(void)
 
 	glViewport(0, 0, 32, 32);
 
 	/* Draw triangle into MSAA texture */
 	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 	glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
 	glClear(GL_COLOR_BUFFER_BIT);
 	piglit_check_gl_error(GL_NO_ERROR);
 
 	glUseProgram(draw_prog);
-	piglit_draw_rect_from_arrays(quad_verts, NULL, false);
+	piglit_draw_rect_from_arrays(quad_verts, NULL, false, 1);
 
 	piglit_check_gl_error(GL_NO_ERROR);
 
 	/* Read back samples:
 	 * Draw textured quad into main framebuffer using texture samples
 	 * from the MSAA texture.  Then use glReadPixels to get the samples.
 	 */
 	glBindFramebuffer(GL_FRAMEBUFFER, 0);
 	glClearColor(0.25, 0.25, 0.25, 0);
 	glClear(GL_COLOR_BUFFER_BIT);
diff --git a/tests/spec/arb_texture_view/common.c b/tests/spec/arb_texture_view/common.c
index 10d3708..fc18bbc 100644
--- a/tests/spec/arb_texture_view/common.c
+++ b/tests/spec/arb_texture_view/common.c
@@ -106,12 +106,12 @@ draw_3d_depth(float x, float y, float w, float h, int depth)
 {
 	const GLfloat vertices[16] =  {x, y, depth, 0.0,
 				 x+w, y, depth, 0.0,
 				 x+w, y+h, depth, 0.0,
 				 x, y+h, depth, 0.0};
 	const GLfloat texcoords[8] = {0.0, 0.0,
 				 1.0, 0.0,
 				 1.0, 1.0,
 				 0.0, 1.0};
 
-	piglit_draw_rect_from_arrays(vertices, texcoords, false);
+	piglit_draw_rect_from_arrays(vertices, texcoords, false, 1);
 }
diff --git a/tests/spec/ext_shader_samples_identical/simple-fs.c b/tests/spec/ext_shader_samples_identical/simple-fs.c
index e7de7b4..e26a2be 100644
--- a/tests/spec/ext_shader_samples_identical/simple-fs.c
+++ b/tests/spec/ext_shader_samples_identical/simple-fs.c
@@ -137,21 +137,21 @@ piglit_display(void)
 	bool pass = true;
 
 	glViewport(0, 0, 32, 32);
 
 	/* Draw triangle into MSAA texture */
 	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 	glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	glUseProgram(draw_prog);
-	piglit_draw_rect_from_arrays(quad_verts, NULL, false);
+	piglit_draw_rect_from_arrays(quad_verts, NULL, false, 1);
 
 	/* Scan the previous render.  Draw green if the samples are all
 	 * (verifiably) the same, blue if there may be differences, and red if
 	 * there were differences but textureSamplesIdentical said there were
 	 * not.
 	 */
 	glBindFramebuffer(GL_FRAMEBUFFER, 0);
 	glClearColor(0.25, 0.25, 0.25, 0);
 	glClear(GL_COLOR_BUFFER_BIT);
 	glUseProgram(readback_prog);
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index d94a40f..5ff13fe 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -656,21 +656,21 @@ required_gl_version_from_glsl_version(unsigned glsl_version)
  *   float verts[4][4];
  *
  * if not NULL; tex is expected to be
  *
  *   float tex[4][2];
  *
  * if not NULL.
  */
 void
 piglit_draw_rect_from_arrays(const void *verts, const void *tex,
-			     bool use_patches)
+			     bool use_patches, unsigned instance_count)
 {
 	bool use_fixed_function_attributes;
 
 	bool gles = piglit_is_gles();
 	int version = piglit_get_gl_version();
 
 	if (gles) {
 		use_fixed_function_attributes = (version < 20);
 	}  else if (version >= 20 ||
 		    piglit_is_extension_supported("GL_ARB_shader_objects")) {
@@ -705,21 +705,24 @@ piglit_draw_rect_from_arrays(const void *verts, const void *tex,
 		if (verts) {
 			glVertexPointer(4, GL_FLOAT, 0, verts);
 			glEnableClientState(GL_VERTEX_ARRAY);
 		}
 
 		if (tex) {
 			glTexCoordPointer(2, GL_FLOAT, 0, tex);
 			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 		}
 
-		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+		if (instance_count > 1)
+			glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, instance_count);
+		else
+			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
 		if (verts)
 			glDisableClientState(GL_VERTEX_ARRAY);
 		if (tex)
 			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	} else {
 		GLuint buf = 0;
 		GLuint old_buf = 0;
 		GLuint vao = 0;
 		GLuint old_vao = 0;
@@ -772,76 +775,84 @@ piglit_draw_rect_from_arrays(const void *verts, const void *tex,
 					      GL_FALSE, 0,
 					      BUFFER_OFFSET(sizeof(GLfloat) * 4 * 4));
 			glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
 		}
 
 		if (use_patches) {
 			GLint old_patch_vertices;
 
 			glGetIntegerv(GL_PATCH_VERTICES, &old_patch_vertices);
 			glPatchParameteri(GL_PATCH_VERTICES, 4);
-			glDrawArrays(GL_PATCHES, 0, 4);
+			if (instance_count > 1)
+				glDrawArraysInstanced(GL_PATCHES, 0, 4, instance_count);
+			else
+				glDrawArrays(GL_PATCHES, 0, 4);
 			glPatchParameteri(GL_PATCH_VERTICES, old_patch_vertices);
 		}
-		else
-			glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+		else {
+			if (instance_count > 1)
+				glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, instance_count);
+			else
+				glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+		}
 
 		if (verts)
 			glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
 		if (tex)
 			glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX);
 
 		glBindBuffer(GL_ARRAY_BUFFER, old_buf);
 		glDeleteBuffers(1, &buf);
 
 		if (vao != 0) {
 			glBindVertexArray(old_vao);
 			glDeleteVertexArrays(1, &vao);
 		}
 	}
 }
 
 /**
  * Convenience function to draw an axis-aligned rectangle.
  */
 GLvoid
-piglit_draw_rect_custom(float x, float y, float w, float h, bool use_patches)
+piglit_draw_rect_custom(float x, float y, float w, float h, bool use_patches,
+			unsigned instance_count)
 {
 	float verts[4][4];
 
 	verts[0][0] = x;
 	verts[0][1] = y;
 	verts[0][2] = 0.0;
 	verts[0][3] = 1.0;
 	verts[1][0] = x + w;
 	verts[1][1] = y;
 	verts[1][2] = 0.0;
 	verts[1][3] = 1.0;
 	verts[2][0] = x;
 	verts[2][1] = y + h;
 	verts[2][2] = 0.0;
 	verts[2][3] = 1.0;
 	verts[3][0] = x + w;
 	verts[3][1] = y + h;
 	verts[3][2] = 0.0;
 	verts[3][3] = 1.0;
 
-	piglit_draw_rect_from_arrays(verts, NULL, use_patches);
+	piglit_draw_rect_from_arrays(verts, NULL, use_patches, instance_count);
 }
 
 /**
  * Convenience function to draw an axis-aligned rectangle.
  */
 GLvoid
 piglit_draw_rect(float x, float y, float w, float h)
 {
-	piglit_draw_rect_custom(x, y, w, h, false);
+	piglit_draw_rect_custom(x, y, w, h, false, 1);
 }
 
 /**
  * Convenience function to draw an axis-aligned rectangle.
  */
 GLvoid
 piglit_draw_rect_z(float z, float x, float y, float w, float h)
 {
 	float verts[4][4];
 
@@ -855,21 +866,21 @@ piglit_draw_rect_z(float z, float x, float y, float w, float h)
 	verts[1][3] = 1.0;
 	verts[2][0] = x;
 	verts[2][1] = y + h;
 	verts[2][2] = z;
 	verts[2][3] = 1.0;
 	verts[3][0] = x + w;
 	verts[3][1] = y + h;
 	verts[3][2] = z;
 	verts[3][3] = 1.0;
 
-	piglit_draw_rect_from_arrays(verts, NULL, false);
+	piglit_draw_rect_from_arrays(verts, NULL, false, 1);
 }
 
 /**
  * Convenience function to draw an axis-aligned rectangle
  * with texture coordinates.
  */
 GLvoid
 piglit_draw_rect_tex(float x, float y, float w, float h,
                      float tx, float ty, float tw, float th)
 {
@@ -894,21 +905,21 @@ piglit_draw_rect_tex(float x, float y, float w, float h,
 	verts[2][3] = 1.0;
 	tex[2][0] = tx;
 	tex[2][1] = ty + th;
 	verts[3][0] = x + w;
 	verts[3][1] = y + h;
 	verts[3][2] = 0.0;
 	verts[3][3] = 1.0;
 	tex[3][0] = tx + tw;
 	tex[3][1] = ty + th;
 
-	piglit_draw_rect_from_arrays(verts, tex, false);
+	piglit_draw_rect_from_arrays(verts, tex, false, 1);
 }
 
 unsigned
 piglit_num_components(GLenum format)
 {
 	switch (format) {
 	case GL_ALPHA:
 	case GL_DEPTH_COMPONENT:
 	case GL_INTENSITY:
 	case GL_LUMINANCE:
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 4fc6c57..3bb0ee8 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -229,28 +229,28 @@ bool piglit_probe_buffer_doubles(GLuint buf, GLenum target, const char *label,
 int piglit_use_fragment_program(void);
 int piglit_use_vertex_program(void);
 void piglit_require_fragment_program(void);
 void piglit_require_vertex_program(void);
 GLuint piglit_compile_program(GLenum target, const char* text);
 GLvoid piglit_draw_triangle(float x1, float y1, float x2, float y2,
 			    float x3, float y3);
 GLvoid piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2,
 			      float x3, float y3);
 GLvoid piglit_draw_rect_custom(float x, float y, float w, float h,
-			       bool use_patches);
+			       bool use_patches, unsigned instance_count);
 GLvoid piglit_draw_rect(float x, float y, float w, float h);
 GLvoid piglit_draw_rect_z(float z, float x, float y, float w, float h);
 GLvoid piglit_draw_rect_tex(float x, float y, float w, float h,
                             float tx, float ty, float tw, float th);
 GLvoid piglit_draw_rect_back(float x, float y, float w, float h);
 void piglit_draw_rect_from_arrays(const void *verts, const void *tex,
-				  bool use_patches);
+				  bool use_patches, unsigned instance_count);
 
 unsigned short piglit_half_from_float(float val);
 
 /**
  * Wrapper for piglit_half_from_float() which allows using an exact
  * hex bit pattern to generate a half float value.
  */
 static inline unsigned short
 strtohf_hex(const char *nptr, char **endptr)
 {
-- 
2.7.4



More information about the Piglit mailing list