[v2] egl: doesn't allow egl to create a forward-compatible context with req ver < 3

Submitted by andrey simiklit on Oct. 12, 2018, 12:11 p.m.

Details

Message ID 20181012121101.20994-1-asimiklit.work@gmail.com
State New
Headers show
Series "egl: doesn't allow egl to create a forward-compatible context with req ver < 3" ( rev: 2 ) in Piglit

Not browsing as part of any series.

Commit Message

andrey simiklit Oct. 12, 2018, 12:11 p.m.
From: Andrii Simiklit <andrii.simiklit@globallogic.com>

EGL_KHR_create_context spec says:
	   "The default values for EGL_CONTEXT_MAJOR_VERSION_KHR and
        EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0 respectively."

		requesting a forward-compatible context for OpenGL
        versions less than 3.0 will generate an error.

	 "* If an OpenGL context is requested and the values for attributes
        EGL_CONTEXT_MAJOR_VERSION_KHR and EGL_CONTEXT_MINOR_VERSION_KHR,
        when considered together with the value for attribute
        EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, specify an OpenGL
        version and feature set that are not defined, than an
        EGL_BAD_MATCH error is generated.

        The defined versions of OpenGL at the time of writing are OpenGL
        1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.1,
        4.2, and 4.3. Feature deprecation was introduced with OpenGL
        3.0, so forward-compatible contexts may only be requested for
        OpenGL 3.0 and above. Thus, examples of invalid combinations of
        attributes include:

          - Major version < 1 or > 4
          - Major version == 1 and minor version < 0 or > 5
          - Major version == 2 and minor version < 0 or > 1
          - Major version == 3 and minor version < 0 or > 2
          - Major version == 4 and minor version < 0 or > 3
          - Forward-compatible flag set and major version < 3

        Because the purpose of forward-compatible contexts is to allow
        application development on a specific OpenGL version with the
        knowledge that the app will run on a future version, context
        creation will fail if
        EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR is set and the
        context version returned cannot implement exactly the requested
        version."

v2: (Matt Turner) - The 'piglit_report_result' calls are moved to 'main'
                  - The variable oresult => result
                  - Fixed whitespace errors
                  - Fixed missing spaces after 'for'

Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
---
 .../valid-flag-forward-compatible-gl.c        | 74 +++++++++++++++----
 1 file changed, 59 insertions(+), 15 deletions(-)

Patch hide | download patch | download mbox

diff --git a/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c b/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
index 42feb54d6..6d2bd0d9f 100644
--- a/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
+++ b/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
@@ -23,16 +23,30 @@ 
 #include "piglit-util-egl.h"
 #include "common.h"
 
-int gl_version;
+int gl_version = 0;
 
-static bool try_flag(int flag)
+static bool try_flag(int req_version, int flag)
 {
-	const EGLint attribs[] = {
-		EGL_CONTEXT_FLAGS_KHR, flag,
-		EGL_NONE
-	};
+	bool result = true;
+	const unsigned vidx = req_version < 0 ? 0 : (req_version == 0) ? 1 : 2;
+	const bool is_forward_compatible =
+			(0 != (flag & EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR));
 
-	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
+	const EGLint attribs[][5] = {
+		/*------------req_version-before-case------------*/
+		{ EGL_CONTEXT_MAJOR_VERSION_KHR, abs(req_version),
+		  EGL_CONTEXT_FLAGS_KHR, flag,
+		  EGL_NONE },
+		/*------------no-req_version-case----------------*/
+		{ EGL_CONTEXT_FLAGS_KHR, flag,
+		  EGL_NONE },
+		/*------------req_version-after-case-------------*/
+		{ EGL_CONTEXT_FLAGS_KHR, flag,
+		  EGL_CONTEXT_MAJOR_VERSION_KHR, abs(req_version),
+		  EGL_NONE }
+	};
+	assert(vidx < 3);
+	ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs[vidx]);
 	if (ctx != NULL) {
 		/* Get GL version in order to know whether we can test
 		 * EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR.
@@ -47,6 +61,17 @@  static bool try_flag(int flag)
 
 			gl_version = piglit_get_gl_version();
 		}
+		if (abs(req_version) < 3 && is_forward_compatible) {
+			/* The EGL_KHR_create_context spec says:
+			 *
+			 * requesting a forward-compatible context for OpenGL
+			 *   versions less than 3.0 will generate an error
+			 *
+			 *   The default values for EGL_CONTEXT_MAJOR_VERSION_KHR and
+			 *   EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0 respectively
+			 */
+			result = false;
+		}
 		eglDestroyContext(egl_dpy, ctx);
 	} else if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
 		/* The EGL_KHR_create_context spec says:
@@ -57,15 +82,17 @@  static bool try_flag(int flag)
 		 *        where these attributes are supported), then an EGL_BAD_MATCH
 		 *        error is generated.
 		 */
-		piglit_report_result(PIGLIT_FAIL);
+		result = false;
 	}
 
-	return true;
+	return result;
 }
 
 int main(int argc, char **argv)
 {
 	bool pass = true;
+	bool skip = false;
+	int req_version;
 
 	if (!EGL_KHR_create_context_setup(EGL_OPENGL_BIT)) {
 		fprintf(stderr, "Desktop GL not available.\n");
@@ -77,16 +104,33 @@  int main(int argc, char **argv)
 	 *
 	 *    "The default value of EGL_CONTEXT_FLAGS_KHR is zero."
 	 */
-	pass = pass && try_flag(0);
-	if (gl_version >= 30) {
-		pass = pass && try_flag(EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
-	} else {
-		piglit_report_result(PIGLIT_SKIP);
+	for (req_version = 0; req_version < 4 && pass && !skip; ++req_version) {
+		pass = pass && try_flag(req_version, 0);
+		if (gl_version >= 30) {
+			pass = pass && try_flag(req_version,
+									EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
+		} else {
+			skip = true;
+			break;
+		}
+	}
+	/* The sign of a req_version is used to specifay EGL_CONTEXT_MAJOR_VERSION_KHR
+	 * flag before or after of EGL_CONTEXT_FLAGS_KHR
+	 **/
+	for (req_version = 0; req_version > -4 && pass && !skip; --req_version) {
+		pass = pass && try_flag(req_version, 0);
+		if (gl_version >= 30) {
+			pass = pass && try_flag(req_version,
+									EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
+		} else {
+			skip = true;
+			break;
+		}
 	}
 
 	EGL_KHR_create_context_teardown();
 
-	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+	piglit_report_result(pass ? (skip ? PIGLIT_SKIP : PIGLIT_PASS) : PIGLIT_FAIL);
 
 	return EXIT_SUCCESS;
 }

Comments

Hello,

Any updates here? :-)
This test is needed to check issue which should be fixed by the following
mesa patch:
https://patchwork.freedesktop.org/patch/256063/

This issue mentioned in this bug by Ian Romanick <idr@freedesktop.org>:
https://bugzilla.freedesktop.org/show_bug.cgi?id=92552#c9

Regards,
Andrii.

On Fri, Oct 12, 2018 at 3:11 PM <asimiklit.work@gmail.com> wrote:

> From: Andrii Simiklit <andrii.simiklit@globallogic.com>
>
> EGL_KHR_create_context spec says:
>            "The default values for EGL_CONTEXT_MAJOR_VERSION_KHR and
>         EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0 respectively."
>
>                 requesting a forward-compatible context for OpenGL
>         versions less than 3.0 will generate an error.
>
>          "* If an OpenGL context is requested and the values for attributes
>         EGL_CONTEXT_MAJOR_VERSION_KHR and EGL_CONTEXT_MINOR_VERSION_KHR,
>         when considered together with the value for attribute
>         EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, specify an OpenGL
>         version and feature set that are not defined, than an
>         EGL_BAD_MATCH error is generated.
>
>         The defined versions of OpenGL at the time of writing are OpenGL
>         1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0, 3.1, 3.2, 4.0, 4.1,
>         4.2, and 4.3. Feature deprecation was introduced with OpenGL
>         3.0, so forward-compatible contexts may only be requested for
>         OpenGL 3.0 and above. Thus, examples of invalid combinations of
>         attributes include:
>
>           - Major version < 1 or > 4
>           - Major version == 1 and minor version < 0 or > 5
>           - Major version == 2 and minor version < 0 or > 1
>           - Major version == 3 and minor version < 0 or > 2
>           - Major version == 4 and minor version < 0 or > 3
>           - Forward-compatible flag set and major version < 3
>
>         Because the purpose of forward-compatible contexts is to allow
>         application development on a specific OpenGL version with the
>         knowledge that the app will run on a future version, context
>         creation will fail if
>         EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR is set and the
>         context version returned cannot implement exactly the requested
>         version."
>
> v2: (Matt Turner) - The 'piglit_report_result' calls are moved to 'main'
>                   - The variable oresult => result
>                   - Fixed whitespace errors
>                   - Fixed missing spaces after 'for'
>
> Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com>
> ---
>  .../valid-flag-forward-compatible-gl.c        | 74 +++++++++++++++----
>  1 file changed, 59 insertions(+), 15 deletions(-)
>
> diff --git
> a/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
> b/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
> index 42feb54d6..6d2bd0d9f 100644
> ---
> a/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
> +++
> b/tests/egl/spec/egl_khr_create_context/valid-flag-forward-compatible-gl.c
> @@ -23,16 +23,30 @@
>  #include "piglit-util-egl.h"
>  #include "common.h"
>
> -int gl_version;
> +int gl_version = 0;
>
> -static bool try_flag(int flag)
> +static bool try_flag(int req_version, int flag)
>  {
> -       const EGLint attribs[] = {
> -               EGL_CONTEXT_FLAGS_KHR, flag,
> -               EGL_NONE
> -       };
> +       bool result = true;
> +       const unsigned vidx = req_version < 0 ? 0 : (req_version == 0) ? 1
> : 2;
> +       const bool is_forward_compatible =
> +                       (0 != (flag &
> EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR));
>
> -       ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT, attribs);
> +       const EGLint attribs[][5] = {
> +               /*------------req_version-before-case------------*/
> +               { EGL_CONTEXT_MAJOR_VERSION_KHR, abs(req_version),
> +                 EGL_CONTEXT_FLAGS_KHR, flag,
> +                 EGL_NONE },
> +               /*------------no-req_version-case----------------*/
> +               { EGL_CONTEXT_FLAGS_KHR, flag,
> +                 EGL_NONE },
> +               /*------------req_version-after-case-------------*/
> +               { EGL_CONTEXT_FLAGS_KHR, flag,
> +                 EGL_CONTEXT_MAJOR_VERSION_KHR, abs(req_version),
> +                 EGL_NONE }
> +       };
> +       assert(vidx < 3);
> +       ctx = eglCreateContext(egl_dpy, cfg, EGL_NO_CONTEXT,
> attribs[vidx]);
>         if (ctx != NULL) {
>                 /* Get GL version in order to know whether we can test
>                  * EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR.
> @@ -47,6 +61,17 @@ static bool try_flag(int flag)
>
>                         gl_version = piglit_get_gl_version();
>                 }
> +               if (abs(req_version) < 3 && is_forward_compatible) {
> +                       /* The EGL_KHR_create_context spec says:
> +                        *
> +                        * requesting a forward-compatible context for
> OpenGL
> +                        *   versions less than 3.0 will generate an error
> +                        *
> +                        *   The default values for
> EGL_CONTEXT_MAJOR_VERSION_KHR and
> +                        *   EGL_CONTEXT_MINOR_VERSION_KHR are 1 and 0
> respectively
> +                        */
> +                       result = false;
> +               }
>                 eglDestroyContext(egl_dpy, ctx);
>         } else if (!piglit_check_egl_error(EGL_BAD_MATCH)) {
>                 /* The EGL_KHR_create_context spec says:
> @@ -57,15 +82,17 @@ static bool try_flag(int flag)
>                  *        where these attributes are supported), then an
> EGL_BAD_MATCH
>                  *        error is generated.
>                  */
> -               piglit_report_result(PIGLIT_FAIL);
> +               result = false;
>         }
>
> -       return true;
> +       return result;
>  }
>
>  int main(int argc, char **argv)
>  {
>         bool pass = true;
> +       bool skip = false;
> +       int req_version;
>
>         if (!EGL_KHR_create_context_setup(EGL_OPENGL_BIT)) {
>                 fprintf(stderr, "Desktop GL not available.\n");
> @@ -77,16 +104,33 @@ int main(int argc, char **argv)
>          *
>          *    "The default value of EGL_CONTEXT_FLAGS_KHR is zero."
>          */
> -       pass = pass && try_flag(0);
> -       if (gl_version >= 30) {
> -               pass = pass &&
> try_flag(EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
> -       } else {
> -               piglit_report_result(PIGLIT_SKIP);
> +       for (req_version = 0; req_version < 4 && pass && !skip;
> ++req_version) {
> +               pass = pass && try_flag(req_version, 0);
> +               if (gl_version >= 30) {
> +                       pass = pass && try_flag(req_version,
> +
>  EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
> +               } else {
> +                       skip = true;
> +                       break;
> +               }
> +       }
> +       /* The sign of a req_version is used to specifay
> EGL_CONTEXT_MAJOR_VERSION_KHR
> +        * flag before or after of EGL_CONTEXT_FLAGS_KHR
> +        **/
> +       for (req_version = 0; req_version > -4 && pass && !skip;
> --req_version) {
> +               pass = pass && try_flag(req_version, 0);
> +               if (gl_version >= 30) {
> +                       pass = pass && try_flag(req_version,
> +
>  EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR);
> +               } else {
> +                       skip = true;
> +                       break;
> +               }
>         }
>
>         EGL_KHR_create_context_teardown();
>
> -       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +       piglit_report_result(pass ? (skip ? PIGLIT_SKIP : PIGLIT_PASS) :
> PIGLIT_FAIL);
>
>         return EXIT_SUCCESS;
>  }
> --
> 2.17.1
>
>