[Piglit] [PATCH] Add shader_runner GLSL version specification via requirements section.

Stuart Abercrombie sabercrombie at chromium.org
Fri Aug 24 16:09:03 PDT 2012


The idea is to allow different GLSL versions for GL vs GL ES.  There shouldn't be a functional change until shader scripts are altered too.

Added ES GLSL version string parsing.
---
 tests/shaders/shader_runner.c |   85 +++++++++++++++++++++++++++++-----------
 1 files changed, 61 insertions(+), 24 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index aa60a62..b9d506a 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -48,6 +48,7 @@ extern float piglit_tolerance[4];
 
 static float gl_version = 0.0;
 static float glsl_version = 0.0;
+static float glsl_pound_version = 0.0;
 static int gl_max_fragment_uniform_components;
 static int gl_max_vertex_uniform_components;
 
@@ -69,6 +70,7 @@ GLuint *uniform_block_bos;
  * Some test script sections, such as "[vertex shader file]", can supply shader
  * source code from multiple disk files.  This array stores those strings.
  */
+char shader_ver_string[100];
 char *shader_strings[256];
 GLsizei shader_string_sizes[256];
 unsigned num_shader_strings = 0;
@@ -129,6 +131,16 @@ compile_glsl(GLenum target, bool release_text)
 		break;
 	}
 
+    // Insert version string, if there is one
+    if (glsl_pound_version != 0.0f) {
+        sprintf(shader_ver_string, "#version %d\n",
+                (int)(100.0f * glsl_pound_version));
+    } else {
+        sprintf(shader_ver_string, "\n");
+    }
+    shader_strings[0] = shader_ver_string;
+    shader_string_sizes[0] = strlen(shader_strings[0]);
+
 	piglit_ShaderSource(shader, num_shader_strings,
 			    (const GLchar **) shader_strings,
 			    shader_string_sizes);
@@ -155,7 +167,7 @@ compile_glsl(GLenum target, bool release_text)
 	}
 
 	if (release_text) {
-		for (i = 0; i < num_shader_strings; i++)
+		for (i = 1; i < num_shader_strings; i++)
 			free(shader_strings[i]);
 	}
 
@@ -419,11 +431,15 @@ process_requirement(const char *line)
 	} else if (string_match("!GL_", line)) {
 		strcpy_to_space(buffer, line + 1);
 		piglit_require_not_extension(buffer);
-	} else if (string_match("GLSL", line)) {
+#if defined USE_OPENGL
+	} else if (string_match("GLSL ", line)) {
+#else
+	} else if (string_match("ESSL ", line)) {
+#endif
 		enum comparison cmp;
 		float version;
 
-		line = eat_whitespace(line + 4);
+		line = eat_whitespace(line + 5);
 
 		line = process_comparison(line, &cmp);
 
@@ -435,12 +451,22 @@ process_requirement(const char *line)
 			       version,
 			       glsl_version);
 			piglit_report_result(PIGLIT_SKIP);
-		}
-	} else if (string_match("GL", line)) {
+		}    
+#if defined USE_OPENGL
+	} else if (string_match("GLSL_#version", line)) {
+#else
+	} else if (string_match("ESSL_#version", line)) {
+#endif
+		line = eat_whitespace(line + 14);
+
+		glsl_pound_version = strtod(line, NULL);
+    
+        printf("GLSL #version= %f\n", glsl_pound_version);
+	} else if (string_match("GL ", line)) {
 		enum comparison cmp;
 		float version;
 
-		line = eat_whitespace(line + 2);
+		line = eat_whitespace(line + 3);
 
 		line = process_comparison(line, &cmp);
 
@@ -481,8 +507,8 @@ leave_state(enum states state, const char *line)
 		break;
 
 	case vertex_shader:
-		shader_string_sizes[0] = line - shader_strings[0];
-		num_shader_strings = 1;
+		shader_string_sizes[1] = line - shader_strings[1];
+		num_shader_strings = 2;
 		compile_glsl(GL_VERTEX_SHADER, false);
 		break;
 
@@ -492,8 +518,8 @@ leave_state(enum states state, const char *line)
 
 	case vertex_program:
 		compile_and_bind_program(GL_VERTEX_PROGRAM_ARB,
-					 shader_strings[0],
-					 line - shader_strings[0]);
+					 shader_strings[1],
+					 line - shader_strings[1]);
 		break;
 
 	case geometry_shader:
@@ -503,8 +529,8 @@ leave_state(enum states state, const char *line)
 		break;
 
 	case fragment_shader:
-		shader_string_sizes[0] = line - shader_strings[0];
-		num_shader_strings = 1;
+		shader_string_sizes[1] = line - shader_strings[1];
+		num_shader_strings = 2;
 		compile_glsl(GL_FRAGMENT_SHADER, false);
 		break;
 
@@ -514,8 +540,8 @@ leave_state(enum states state, const char *line)
 
 	case fragment_program:
 		compile_and_bind_program(GL_FRAGMENT_PROGRAM_ARB,
-					 shader_strings[0],
-					 line - shader_strings[0]);
+					 shader_strings[1],
+					 line - shader_strings[1]);
 		break;
 
 	case vertex_data:
@@ -629,24 +655,24 @@ process_test_script(const char *script_name)
 				state = requirements;
 			} else if (string_match("[vertex shader]", line)) {
 				state = vertex_shader;
-				shader_strings[0] = NULL;
+				shader_strings[1] = NULL;
 			} else if (string_match("[vertex program]", line)) {
 				state = vertex_program;
-				shader_strings[0] = NULL;
+				shader_strings[1] = NULL;
 			} else if (string_match("[vertex shader file]", line)) {
 				state = vertex_shader_file;
-				shader_strings[0] = NULL;
-				num_shader_strings = 0;
+				shader_strings[1] = NULL;
+				num_shader_strings = 1;
 			} else if (string_match("[fragment shader]", line)) {
 				state = fragment_shader;
-				shader_strings[0] = NULL;
+				shader_strings[1] = NULL;
 			} else if (string_match("[fragment program]", line)) {
 				state = fragment_program;
-				shader_strings[0] = NULL;
+				shader_strings[1] = NULL;
 			} else if (string_match("[fragment shader file]", line)) {
 				state = fragment_shader_file;
-				shader_strings[0] = NULL;
-				num_shader_strings = 0;
+				shader_strings[1] = NULL;
+				num_shader_strings = 1;
 			} else if (string_match("[vertex data]", line)) {
 				state = vertex_data;
 				vertex_data_start = NULL;
@@ -671,8 +697,8 @@ process_test_script(const char *script_name)
 			case geometry_program:
 			case fragment_shader:
 			case fragment_program:
-				if (shader_strings[0] == NULL)
-					shader_strings[0] = (char *) line;
+				if (shader_strings[1] == NULL)
+					shader_strings[1] = (char *) line;
 				break;
 
 			case vertex_shader_file:
@@ -1542,6 +1568,7 @@ piglit_display(void)
 void
 piglit_init(int argc, char **argv)
 {
+    const char es_glsl_skip[] = "OpenGL ES GLSL ES ";
 	const char *glsl_version_string;
 
 	piglit_require_GLSL();
@@ -1550,8 +1577,18 @@ piglit_init(int argc, char **argv)
 
 	glsl_version_string = (char *)
 		glGetString(GL_SHADING_LANGUAGE_VERSION);
+
+#if defined USE_OPENGL
 	glsl_version = (glsl_version_string == NULL)
 		? 0.0 : strtod(glsl_version_string, NULL);
+#else
+    if (glsl_version_string == NULL ||
+        strlen(glsl_version_string) <= strlen(es_glsl_skip)) {
+        glsl_version = 0.0;
+    } else {
+        glsl_version = strtod(&glsl_version_string[strlen(es_glsl_skip)], NULL);
+    }
+#endif
 
 	glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS,
 		      &gl_max_fragment_uniform_components);
-- 
1.7.7.3



More information about the Piglit mailing list