[Piglit] [PATCH 2/3] msaa: Add the ability to test computed depths.

Paul Berry stereotype441 at gmail.com
Thu Jul 12 17:53:12 PDT 2012


This patch modifies the common code for MSAA tests, so that when
testing depth buffer behaviour, we can choose to either output the
depth value from the vertex shader (using gl_Position) or from the
fragment shader (using gl_FragDepth).
---
 tests/spec/ext_framebuffer_multisample/common.cpp |   30 ++++++++++++++++-----
 tests/spec/ext_framebuffer_multisample/common.h   |   18 ++++++++++++-
 2 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp
index 12c9c82..7712926 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -1032,7 +1032,8 @@ void Points::draw(const float (*proj)[4])
 }
 
 Sunburst::Sunburst()
-	: out_type(GL_UNSIGNED_NORMALIZED)
+	: out_type(GL_UNSIGNED_NORMALIZED),
+	  compute_depth(false)
 {
 }
 
@@ -1081,7 +1082,7 @@ void Sunburst::compile()
 		"in vec3 in_barycentric_coords;\n"
 		"out vec3 barycentric_coords;\n"
 		"uniform float rotation;\n"
-		"uniform float depth;\n"
+		"uniform float vert_depth;\n"
 		"uniform mat4 proj;\n"
 		"\n"
 		"void main()\n"
@@ -1089,13 +1090,15 @@ void Sunburst::compile()
 		"  vec2 pos = pos_within_tri;\n"
 		"  pos = mat2(cos(rotation), sin(rotation),\n"
 		"             -sin(rotation), cos(rotation)) * pos;\n"
-		"  gl_Position = proj * vec4(pos, depth, 1.0);\n"
+		"  gl_Position = proj * vec4(pos, vert_depth, 1.0);\n"
 		"  barycentric_coords = in_barycentric_coords;\n"
 		"}\n";
 
 	static const char *frag_template =
 		"#version 130\n"
 		"#define OUT_TYPE %s\n"
+		"#define COMPUTE_DEPTH %s\n"
+		"uniform float frag_depth;\n"
 		"in vec3 barycentric_coords;\n"
 		"uniform mat3x4 draw_colors;\n"
 		"out OUT_TYPE frag_out;\n"
@@ -1103,6 +1106,9 @@ void Sunburst::compile()
 		"void main()\n"
 		"{\n"
 		"  frag_out = OUT_TYPE(draw_colors * barycentric_coords);\n"
+		"#if COMPUTE_DEPTH\n"
+		"  gl_FragDepth = (frag_depth + 1.0) / 2.0;\n"
+		"#endif\n"
 		"}\n";
 
 	/* Compile program */
@@ -1113,7 +1119,8 @@ void Sunburst::compile()
 	unsigned frag_alloc_len =
 		strlen(frag_template) + strlen(out_type_glsl) + 1;
 	char *frag = (char *) malloc(frag_alloc_len);
-	sprintf(frag, frag_template, out_type_glsl);
+	sprintf(frag, frag_template, out_type_glsl,
+		compute_depth ? "1" : "0");
 	GLint fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
 	free(frag);
 	glAttachShader(prog, fs);
@@ -1128,8 +1135,10 @@ void Sunburst::compile()
 	/* Set up uniforms */
 	glUseProgram(prog);
 	rotation_loc = glGetUniformLocation(prog, "rotation");
-	depth_loc = glGetUniformLocation(prog, "depth");
-	glUniform1f(depth_loc, 0.0);
+	vert_depth_loc = glGetUniformLocation(prog, "vert_depth");
+	frag_depth_loc = glGetUniformLocation(prog, "frag_depth");
+	glUniform1f(vert_depth_loc, 0.0);
+	glUniform1f(frag_depth_loc, 0.0);
 	proj_loc = glGetUniformLocation(prog, "proj");
 	draw_colors_loc = glGetUniformLocation(prog, "draw_colors");
 
@@ -1241,6 +1250,13 @@ StencilSunburst::draw(const float (*proj)[4])
 	glDisable(GL_STENCIL_TEST);
 }
 
+
+DepthSunburst::DepthSunburst(bool compute_depth)
+{
+	this->compute_depth = compute_depth;
+}
+
+
 void
 DepthSunburst::draw(const float (*proj)[4])
 {
@@ -1263,7 +1279,7 @@ DepthSunburst::draw(const float (*proj)[4])
 		 * triangles at depths of 3/4, 1/2, -1/4, 0, 1/4, 1/2,
 		 * and 3/4.
 		 */
-		glUniform1f(depth_loc,
+		glUniform1f(compute_depth ? frag_depth_loc : vert_depth_loc,
 			    float(num_tris - triangle_to_draw * 2 - 1)
 			    / (num_tris + 1));
 
diff --git a/tests/spec/ext_framebuffer_multisample/common.h b/tests/spec/ext_framebuffer_multisample/common.h
index 3caccaa..9d330b3 100644
--- a/tests/spec/ext_framebuffer_multisample/common.h
+++ b/tests/spec/ext_framebuffer_multisample/common.h
@@ -378,10 +378,19 @@ public:
 	 */
 	GLenum out_type;
 
+	/**
+	 * Whether or not the fragment shader should output a depth
+	 * value.
+	 *
+	 * Defaults to false.
+	 */
+	bool compute_depth;
+
 protected:
 	GLint prog;
 	GLint rotation_loc;
-	GLint depth_loc;
+	GLint vert_depth_loc;
+	GLint frag_depth_loc;
 	GLint proj_loc;
 	GLint draw_colors_loc;
 	GLuint vao;
@@ -435,10 +444,17 @@ public:
  * depth values, with depth testing enabled.  They are drawn in an
  * arbitrary non-consecutive order, to verify that depth testing
  * properly sorts the surfaces into front-to-back order.
+ *
+ * If the constructor parameter compute_depth is true, the depth value
+ * is determined using a fragment shader output.  If it is false, it
+ * is determined by the z value of the vertex shader gl_Position
+ * output.
  */
 class DepthSunburst : public Sunburst
 {
 public:
+	explicit DepthSunburst(bool compute_depth = false);
+
 	virtual void draw(const float (*proj)[4]);
 };
 
-- 
1.7.7.6



More information about the Piglit mailing list