[Piglit] [PATCH 2/3] fast-clear: Test enabling GL_FRAMEBUFFER_SRGB

Neil Roberts neil at linux.intel.com
Wed Nov 25 03:22:36 PST 2015


If ‘enable-fb-srgb’ is given on the command line to either of the two
fast clear tests they will now enable GL_FRAMEBUFFER_SRGB before
clearing the buffer. This should cause the clear color to be converted
from SRGB to linear before being written to the framebuffer. The
expected color is therefore converted to match. This exposes a bug on
SKL in the i965 driver when clearing SRGB MSRTs.
---
 tests/all.py                                       |  6 +++
 tests/fbo/fbo-fast-clear.c                         | 56 ++++++++++++++++++----
 .../spec/ext_framebuffer_multisample/fast-clear.c  | 56 ++++++++++++++++++----
 3 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/tests/all.py b/tests/all.py
index f5252f4..1893ccc 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2041,6 +2041,12 @@ with profile.group_manager(
     g(['framebuffer-srgb'], run_concurrent=False)
     g(['arb_framebuffer_srgb-clear'])
     g(['arb_framebuffer_srgb-pushpop'])
+    g(['ext_framebuffer_multisample-fast-clear',
+       'GL_EXT_texture_sRGB',
+       'enable-fb-srgb'],
+      'msaa-fast-clear')
+    g(['fbo-fast-clear', 'GL_EXT_texture_sRGB', 'enable-fb-srgb'],
+      'fbo-fast-clear')
 
 with profile.group_manager(
         PiglitGLTest,
diff --git a/tests/fbo/fbo-fast-clear.c b/tests/fbo/fbo-fast-clear.c
index 95c6ebe..3c6c121 100644
--- a/tests/fbo/fbo-fast-clear.c
+++ b/tests/fbo/fbo-fast-clear.c
@@ -104,6 +104,36 @@ clear_colors[][4] = {
 };
 
 static GLuint prog_float, prog_int, prog_uint;
+static bool enable_fb_srgb = false;
+
+static void
+convert_srgb_color(const struct format_desc *format,
+		   float *color)
+{
+	int i;
+
+	/* If the texture is not an sRGB format then no conversion is
+	 * needed regardless of the sRGB settings.
+	 */
+	if (strstr(format->name, "SRGB") == NULL &&
+	    strstr(format->name, "SLUMINANCE") == NULL)
+		return;
+
+	/* If GL_FRAMEBUFFER_SRGB was enabled when we did the clear
+	 * then the clear color would have been converted to SRGB
+	 * before being written. When it is sampled it will be
+	 * converted back to linear. The two conversions cancel each
+	 * other out so we don't need to do anything.
+	 */
+	if (enable_fb_srgb)
+		return;
+
+	/* Otherwise we need to compensate for the color being
+	 * converted to linear when sampled.
+	 */
+	for (i = 0; i < 3; i++)
+		color[i] = piglit_srgb_to_linear(color[i]);
+}
 
 static enum piglit_result
 test_color(GLuint fbo,
@@ -114,10 +144,12 @@ test_color(GLuint fbo,
 {
 	float expected_color[4];
 	float alpha_override;
-	int i;
 
 	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
+	if (enable_fb_srgb)
+		glEnable(GL_FRAMEBUFFER_SRGB);
+
 	switch (clear_type) {
 	case GL_INT: {
 		GLint clear_color_int[4] = {
@@ -162,6 +194,9 @@ test_color(GLuint fbo,
 		break;
 	}
 
+	if (enable_fb_srgb)
+		glDisable(GL_FRAMEBUFFER_SRGB);
+
 	memcpy(expected_color, clear_color, sizeof expected_color);
 
 	switch (format->base_internal_format) {
@@ -199,13 +234,7 @@ test_color(GLuint fbo,
 		break;
 	}
 
-	if (strstr(format->name, "SRGB") ||
-	    strstr(format->name, "SLUMINANCE")) {
-		for (i = 0; i < 3; i++) {
-			expected_color[i] =
-				piglit_srgb_to_linear(expected_color[i]);
-		}
-	}
+	convert_srgb_color(format, expected_color);
 
 	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
 	piglit_draw_rect(offset * 16 * 2.0f / piglit_width - 1.0f,
@@ -381,9 +410,16 @@ piglit_init(int argc, char **argv)
 	int test_set_index = 0;
 	int glsl_major, glsl_minor;
 	bool es;
+	int i;
 
-	if (argc >= 2)
-		test_set_index = fbo_lookup_test_set(argv[1]);
+	for (i = 1; i < argc; i++) {
+		if (!strcmp(argv[i], "enable-fb-srgb")) {
+			enable_fb_srgb = true;
+			piglit_require_extension("GL_ARB_framebuffer_sRGB");
+		} else {
+			test_set_index = fbo_lookup_test_set(argv[i]);
+		}
+	}
 
 	test_set = test_set + test_set_index;
 
diff --git a/tests/spec/ext_framebuffer_multisample/fast-clear.c b/tests/spec/ext_framebuffer_multisample/fast-clear.c
index b3b57bf..322e190 100644
--- a/tests/spec/ext_framebuffer_multisample/fast-clear.c
+++ b/tests/spec/ext_framebuffer_multisample/fast-clear.c
@@ -109,6 +109,36 @@ clear_colors[][4] = {
 };
 
 static GLuint prog_float, prog_int, prog_uint;
+static bool enable_fb_srgb = false;
+
+static void
+convert_srgb_color(const struct format_desc *format,
+		   float *color)
+{
+	int i;
+
+	/* If the texture is not an sRGB format then no conversion is
+	 * needed regardless of the sRGB settings.
+	 */
+	if (strstr(format->name, "SRGB") == NULL &&
+	    strstr(format->name, "SLUMINANCE") == NULL)
+		return;
+
+	/* If GL_FRAMEBUFFER_SRGB was enabled when we did the clear
+	 * then the clear color would have been converted to SRGB
+	 * before being written. When it is sampled it will be
+	 * converted back to linear. The two conversions cancel each
+	 * other out so we don't need to do anything.
+	 */
+	if (enable_fb_srgb)
+		return;
+
+	/* Otherwise we need to compensate for the color being
+	 * converted to linear when sampled.
+	 */
+	for (i = 0; i < 3; i++)
+		color[i] = piglit_srgb_to_linear(color[i]);
+}
 
 static enum piglit_result
 test_color(GLuint fbo,
@@ -119,10 +149,12 @@ test_color(GLuint fbo,
 {
 	float expected_color[4];
 	float alpha_override;
-	int i;
 
 	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
+	if (enable_fb_srgb)
+		glEnable(GL_FRAMEBUFFER_SRGB);
+
 	switch (clear_type) {
 	case GL_INT: {
 		GLint clear_color_int[4] = {
@@ -167,6 +199,9 @@ test_color(GLuint fbo,
 		break;
 	}
 
+	if (enable_fb_srgb)
+		glDisable(GL_FRAMEBUFFER_SRGB);
+
 	memcpy(expected_color, clear_color, sizeof expected_color);
 
 	switch (format->base_internal_format) {
@@ -204,13 +239,7 @@ test_color(GLuint fbo,
 		break;
 	}
 
-	if (strstr(format->name, "SRGB") ||
-	    strstr(format->name, "SLUMINANCE")) {
-		for (i = 0; i < 3; i++) {
-			expected_color[i] =
-				piglit_srgb_to_linear(expected_color[i]);
-		}
-	}
+	convert_srgb_color(format, expected_color);
 
 	glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
 	piglit_draw_rect(offset * 16 * 2.0f / piglit_width - 1.0f,
@@ -395,9 +424,16 @@ piglit_init(int argc, char **argv)
 	int test_set_index = 0;
 	int glsl_major, glsl_minor;
 	bool es;
+	int i;
 
-	if (argc >= 2)
-		test_set_index = fbo_lookup_test_set(argv[1]);
+	for (i = 1; i < argc; i++) {
+		if (!strcmp(argv[i], "enable-fb-srgb")) {
+			enable_fb_srgb = true;
+			piglit_require_extension("GL_ARB_framebuffer_sRGB");
+		} else {
+			test_set_index = fbo_lookup_test_set(argv[i]);
+		}
+	}
 
 	piglit_require_extension("GL_ARB_texture_multisample");
 
-- 
1.9.3



More information about the Piglit mailing list