On 24 August 2012 16:09, Stuart Abercrombie <span dir="ltr"><<a href="mailto:sabercrombie@chromium.org" target="_blank">sabercrombie@chromium.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
Added ES GLSL version string parsing.<br></blockquote><div><br>I like where you're going with this. A few comments before we get into the patch itself:<br><br>1. "ESSL" is a nonstandard name for the GLES shading language. Let's use "GLSL ES".<br>
<br>2. How to we want the two different builds of shader_runner to handle the following four possible requirements sections?<br><br>(a)<br>GLSL >= 130<br><br>(b)<br>GLSL ES >= 300<br><br>(c)<br>GLSL >= 130<br>GLSL ES >= 300<br>
<br>(d) (no versions specified)<br><br>My expectation would be:<br>- test (a) should only be run when desktop GLSL version 130 or above is available, and should be skipped when testing GLES.<br>- test (b) should only be run when GLSL ES version 300 or above is available, and should be skipped when testing desktop GL*.<br>
- test (c) should be run with GLSL version 130 when testing desktop GL, and GLSL ES version 300 when testing GLES*.<br>- test (d) should produce an error message regardless of whether desktop GL or GLSL ES is being tested.<br>
<br>*At a later date we will probably also to be able to run the GLSL ES tests under desktop GL using the ARB_ES{2,3}_compatibility extension, but I'm happy not to worry about that yet :)<br><br>As written, the patch will run test (a) when desktop GLSL version 130 or above is available, as expected, but it will aso run test (a) when testing GLES, which is unlikely to be the test author's intention. Vice versa for test (b). Test (c) will work as I would expect. Test (d) will be run on all implementations, which I again think is unlikely to be the author's intention (because in this case the author probably just forgot to include the version annotation).<br>
<br>3. A lot of the complexity of the patch has to do with the fact that the version string is inserted into element 0 of the shader_strings array, so the code has to treat it specially, and the special treatment that was previously given to shader_strings[0] has to be shifted over to shader_strings[1]. I don't think we actually have to introduce this kind of complication, because it turns out that the only reason that shader_strings is an array in the first place is to support a feature that is never used (the ability to specify multiple files in a single "[vertex shader file]" or "[fragment shader file]" and have them concatenated). I've talked to Ian about this and we both agree that this feature isn't necessary.<br>
<br>4. It seems inconvenient for every test to have to specify both "GLSL >= xxx" and "GLSL_#version xxx" in the requirements section. My recommendation would be to compute the version string based on the "GLSL >= xxx" line, and add logic that suppresses autogeneration of a "#version" line if a "#version" line is already present. Note that if we do this we have to decide how to handle requirements of the form "GLSL > xxx", "GLSL < xxx" and "GLSL != xxx". I think for now we could just reject those constructs (they aren't used anyhow), and if later they turn out to be needed we can figure out what to do when we get to that.<br>
<br>(Note: eventually Chad and I would like shader_runner to be able to run a "GLSL >= 1.10" test on *all* GLSL versions instead of just one, but I think we can leave that for a later task).<br><br>So I would recommend breaking this into 5 patches:<br>
<br>1. Get rid of the ability to specify multiple files in a single "[vertex shader file]" or "[fragment shader file]", and replace the shader_strings array with a single shader_string.<br>2. Make shader_runner able to generate a "#version" line (if none is already present).<br>
3. If there are any tests that don't have a version requirement line, add a "GLSL >= 1.10" requirement (though I don't think there are any). <br>4. Make shader_runner produce an error if there is no version requirement line.<br>
5. Make shader_runner support "GLSL ES >= xxx" version requirements.<br><br>A few more specific comments follow.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
tests/shaders/shader_runner.c | 85 +++++++++++++++++++++++++++++-----------<br>
1 files changed, 61 insertions(+), 24 deletions(-)<br>
<br>
diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c<br>
index aa60a62..b9d506a 100644<br>
--- a/tests/shaders/shader_runner.c<br>
+++ b/tests/shaders/shader_runner.c<br>
@@ -48,6 +48,7 @@ extern float piglit_tolerance[4];<br>
<br>
static float gl_version = 0.0;<br>
static float glsl_version = 0.0;<br>
+static float glsl_pound_version = 0.0;<br>
static int gl_max_fragment_uniform_components;<br>
static int gl_max_vertex_uniform_components;<br>
<br>
@@ -69,6 +70,7 @@ GLuint *uniform_block_bos;<br>
* Some test script sections, such as "[vertex shader file]", can supply shader<br>
* source code from multiple disk files. This array stores those strings.<br>
*/<br>
+char shader_ver_string[100];<br>
char *shader_strings[256];<br>
GLsizei shader_string_sizes[256];<br>
unsigned num_shader_strings = 0;<br>
@@ -129,6 +131,16 @@ compile_glsl(GLenum target, bool release_text)<br>
break;<br>
}<br>
<br>
+ // Insert version string, if there is one<br>
+ if (glsl_pound_version != 0.0f) {<br>
+ sprintf(shader_ver_string, "#version %d\n",<br>
+ (int)(100.0f * glsl_pound_version));<br></blockquote><div><br>Two minor problems here:<br><br>1. This is going to cause rounding errors. For example, 4.1 represented as a float is actually 4.0999999, so when you multiply by 100.0 and take the integer part you'll get 409 instead of 410. I'd recommend using round().<br>
<br>2. The correct version string for GLSL ES 1.00 is "#version 100", but the correct version string for GLSL ES 3.00 is "#version 300 es". I think it's reasonable to assume that all future versions of GLSL ES will use the "es" suffix on the version string as well.<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ } else {<br>
+ sprintf(shader_ver_string, "\n");<br>
+ }<br>
+ shader_strings[0] = shader_ver_string;<br>
+ shader_string_sizes[0] = strlen(shader_strings[0]);<br>
+<br>
piglit_ShaderSource(shader, num_shader_strings,<br>
(const GLchar **) shader_strings,<br>
shader_string_sizes);<br>
@@ -155,7 +167,7 @@ compile_glsl(GLenum target, bool release_text)<br>
}<br>
<br>
if (release_text) {<br>
- for (i = 0; i < num_shader_strings; i++)<br>
+ for (i = 1; i < num_shader_strings; i++)<br>
free(shader_strings[i]);<br>
}<br>
<br>
@@ -419,11 +431,15 @@ process_requirement(const char *line)<br>
} else if (string_match("!GL_", line)) {<br>
strcpy_to_space(buffer, line + 1);<br>
piglit_require_not_extension(buffer);<br>
- } else if (string_match("GLSL", line)) {<br>
+#if defined USE_OPENGL<br>
+ } else if (string_match("GLSL ", line)) {<br>
+#else<br>
+ } else if (string_match("ESSL ", line)) {<br>
+#endif<br>
enum comparison cmp;<br>
float version;<br>
<br>
- line = eat_whitespace(line + 4);<br>
+ line = eat_whitespace(line + 5);<br>
<br>
line = process_comparison(line, &cmp);<br>
<br>
@@ -435,12 +451,22 @@ process_requirement(const char *line)<br>
version,<br>
glsl_version);<br>
piglit_report_result(PIGLIT_SKIP);<br>
- }<br>
- } else if (string_match("GL", line)) {<br>
+ }<br>
+#if defined USE_OPENGL<br>
+ } else if (string_match("GLSL_#version", line)) {<br>
+#else<br>
+ } else if (string_match("ESSL_#version", line)) {<br>
+#endif<br>
+ line = eat_whitespace(line + 14);<br>
+<br>
+ glsl_pound_version = strtod(line, NULL);<br>
+<br>
+ printf("GLSL #version= %f\n", glsl_pound_version);<br>
+ } else if (string_match("GL ", line)) {<br>
enum comparison cmp;<br>
float version;<br>
<br>
- line = eat_whitespace(line + 2);<br>
+ line = eat_whitespace(line + 3);<br>
<br>
line = process_comparison(line, &cmp);<br>
<br>
@@ -481,8 +507,8 @@ leave_state(enum states state, const char *line)<br>
break;<br>
<br>
case vertex_shader:<br>
- shader_string_sizes[0] = line - shader_strings[0];<br>
- num_shader_strings = 1;<br>
+ shader_string_sizes[1] = line - shader_strings[1];<br>
+ num_shader_strings = 2;<br>
compile_glsl(GL_VERTEX_SHADER, false);<br>
break;<br>
<br>
@@ -492,8 +518,8 @@ leave_state(enum states state, const char *line)<br>
<br>
case vertex_program:<br>
compile_and_bind_program(GL_VERTEX_PROGRAM_ARB,<br>
- shader_strings[0],<br>
- line - shader_strings[0]);<br>
+ shader_strings[1],<br>
+ line - shader_strings[1]);<br>
break;<br>
<br>
case geometry_shader:<br>
@@ -503,8 +529,8 @@ leave_state(enum states state, const char *line)<br>
break;<br>
<br>
case fragment_shader:<br>
- shader_string_sizes[0] = line - shader_strings[0];<br>
- num_shader_strings = 1;<br>
+ shader_string_sizes[1] = line - shader_strings[1];<br>
+ num_shader_strings = 2;<br>
compile_glsl(GL_FRAGMENT_SHADER, false);<br>
break;<br>
<br>
@@ -514,8 +540,8 @@ leave_state(enum states state, const char *line)<br>
<br>
case fragment_program:<br>
compile_and_bind_program(GL_FRAGMENT_PROGRAM_ARB,<br>
- shader_strings[0],<br>
- line - shader_strings[0]);<br>
+ shader_strings[1],<br>
+ line - shader_strings[1]);<br>
break;<br>
<br>
case vertex_data:<br>
@@ -629,24 +655,24 @@ process_test_script(const char *script_name)<br>
state = requirements;<br>
} else if (string_match("[vertex shader]", line)) {<br>
state = vertex_shader;<br>
- shader_strings[0] = NULL;<br>
+ shader_strings[1] = NULL;<br>
} else if (string_match("[vertex program]", line)) {<br>
state = vertex_program;<br>
- shader_strings[0] = NULL;<br>
+ shader_strings[1] = NULL;<br>
} else if (string_match("[vertex shader file]", line)) {<br>
state = vertex_shader_file;<br>
- shader_strings[0] = NULL;<br>
- num_shader_strings = 0;<br>
+ shader_strings[1] = NULL;<br>
+ num_shader_strings = 1;<br>
} else if (string_match("[fragment shader]", line)) {<br>
state = fragment_shader;<br>
- shader_strings[0] = NULL;<br>
+ shader_strings[1] = NULL;<br>
} else if (string_match("[fragment program]", line)) {<br>
state = fragment_program;<br>
- shader_strings[0] = NULL;<br>
+ shader_strings[1] = NULL;<br>
} else if (string_match("[fragment shader file]", line)) {<br>
state = fragment_shader_file;<br>
- shader_strings[0] = NULL;<br>
- num_shader_strings = 0;<br>
+ shader_strings[1] = NULL;<br>
+ num_shader_strings = 1;<br>
} else if (string_match("[vertex data]", line)) {<br>
state = vertex_data;<br>
vertex_data_start = NULL;<br>
@@ -671,8 +697,8 @@ process_test_script(const char *script_name)<br>
case geometry_program:<br>
case fragment_shader:<br>
case fragment_program:<br>
- if (shader_strings[0] == NULL)<br>
- shader_strings[0] = (char *) line;<br>
+ if (shader_strings[1] == NULL)<br>
+ shader_strings[1] = (char *) line;<br>
break;<br>
<br>
case vertex_shader_file:<br>
@@ -1542,6 +1568,7 @@ piglit_display(void)<br>
void<br>
piglit_init(int argc, char **argv)<br>
{<br>
+ const char es_glsl_skip[] = "OpenGL ES GLSL ES ";<br>
const char *glsl_version_string;<br>
<br>
piglit_require_GLSL();<br>
@@ -1550,8 +1577,18 @@ piglit_init(int argc, char **argv)<br>
<br>
glsl_version_string = (char *)<br>
glGetString(GL_SHADING_LANGUAGE_VERSION);<br>
+<br>
+#if defined USE_OPENGL<br>
glsl_version = (glsl_version_string == NULL)<br>
? 0.0 : strtod(glsl_version_string, NULL);<br>
+#else<br>
+ if (glsl_version_string == NULL ||<br>
+ strlen(glsl_version_string) <= strlen(es_glsl_skip)) {<br>
+ glsl_version = 0.0;<br>
+ } else {<br>
+ glsl_version = strtod(&glsl_version_string[strlen(es_glsl_skip)], NULL);<br>
+ }<br>
+#endif<br>
<br>
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS,<br>
&gl_max_fragment_uniform_components);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.7.3<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br>