[Mesa-dev] [PATCH 2/5] (gles3) intel: Move validation of context version into intelInitContext

Chad Versace chad.versace at linux.intel.com
Wed Nov 21 17:43:36 PST 2012


Each driver (i830, i915, i965) used independent but similar code to
validate the requested context version. With the rececnt arrival of GLES3,
that logic has needed an update. Rather than apply identical updates to
each drivers validation code, let's just move the validation into the
shared routine intelInitContext.

This refactor required some incidental changes to functions
i830CreateContext and intelInitContext. For each function, this patch:
    - Adds context version parameters to the signature.
    - Adds a DRI_CTX_ERROR out param to the signature.
    - Sets the DRI_CTX_ERROR at each early return.

Tested against gen6 with piglit egl-create-context-verify-gl-flavor.
Verified that this patch does not change the set of exposed EGL context
flavors.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/drivers/dri/i915/i830_context.c   | 20 ++++++++---
 src/mesa/drivers/dri/i915/i830_context.h   |  6 +++-
 src/mesa/drivers/dri/i915/i915_context.c   | 32 +++--------------
 src/mesa/drivers/dri/i965/brw_context.c    | 47 +++----------------------
 src/mesa/drivers/dri/intel/intel_context.c | 56 ++++++++++++++++++++++++++++--
 src/mesa/drivers/dri/intel/intel_context.h | 13 ++++---
 src/mesa/drivers/dri/intel/intel_screen.c  | 31 +++++------------
 7 files changed, 100 insertions(+), 105 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i830_context.c b/src/mesa/drivers/dri/i915/i830_context.c
index e822660..288dfcc 100644
--- a/src/mesa/drivers/dri/i915/i830_context.c
+++ b/src/mesa/drivers/dri/i915/i830_context.c
@@ -52,23 +52,33 @@ i830InitDriverFunctions(struct dd_function_table *functions)
 extern const struct tnl_pipeline_stage *intel_pipeline[];
 
 bool
-i830CreateContext(const struct gl_config * mesaVis,
+i830CreateContext(int api,
+                  const struct gl_config * mesaVis,
                   __DRIcontext * driContextPriv,
+                  unsigned major_version,
+                  unsigned minor_version,
+                  unsigned *error,
                   void *sharedContextPrivate)
 {
    struct dd_function_table functions;
    struct i830_context *i830 = rzalloc(NULL, struct i830_context);
    struct intel_context *intel = &i830->intel;
    struct gl_context *ctx = &intel->ctx;
-   if (!i830)
+
+   if (!i830) {
+      *error = __DRI_CTX_ERROR_NO_MEMORY;
       return false;
+   }
 
    i830InitVtbl(i830);
    i830InitDriverFunctions(&functions);
 
-   if (!intelInitContext(intel, __DRI_API_OPENGL, mesaVis, driContextPriv,
-                         sharedContextPrivate, &functions)) {
-      free(i830);
+   if (!intelInitContext(intel, __DRI_API_OPENGL,
+                         major_version, minor_version,
+                         mesaVis, driContextPriv,
+                         sharedContextPrivate, &functions,
+                         error)) {
+      ralloc_free(i830);
       return false;
    }
 
diff --git a/src/mesa/drivers/dri/i915/i830_context.h b/src/mesa/drivers/dri/i915/i830_context.h
index d9e2fcf..ab6222b 100644
--- a/src/mesa/drivers/dri/i915/i830_context.h
+++ b/src/mesa/drivers/dri/i915/i830_context.h
@@ -178,8 +178,12 @@ i830_state_draw_region(struct intel_context *intel,
 /* i830_context.c
  */
 extern bool
-i830CreateContext(const struct gl_config * mesaVis,
+i830CreateContext(int api,
+                  const struct gl_config * mesaVis,
                   __DRIcontext * driContextPriv,
+                  unsigned major_version,
+                  unsigned minor_version,
+                  unsigned *error,
                   void *sharedContextPrivate);
 
 /* i830_tex.c, i830_texstate.c
diff --git a/src/mesa/drivers/dri/i915/i915_context.c b/src/mesa/drivers/dri/i915/i915_context.c
index 3ef4eca..75a1a2c 100644
--- a/src/mesa/drivers/dri/i915/i915_context.c
+++ b/src/mesa/drivers/dri/i915/i915_context.c
@@ -168,33 +168,11 @@ i915CreateContext(int api,
 
    i915InitDriverFunctions(&functions);
 
-   if (!intelInitContext(intel, api, mesaVis, driContextPriv,
-                         sharedContextPrivate, &functions)) {
-      *error = __DRI_CTX_ERROR_NO_MEMORY;
-      return false;
-   }
-
-   /* Now that the extension bits are known, filter against the requested API
-    * and version.
-    */
-   switch (api) {
-   case API_OPENGL: {
-      const unsigned max_version =
-         (ctx->Extensions.ARB_fragment_shader &&
-          ctx->Extensions.ARB_occlusion_query) ? 20 : 15;
-      const unsigned req_version = major_version * 10 + minor_version;
-
-      if (req_version > max_version) {
-         *error = __DRI_CTX_ERROR_BAD_VERSION;
-         return false;
-      }
-      break;
-   }
-   case API_OPENGLES:
-   case API_OPENGLES2:
-      break;
-   default:
-      *error = __DRI_CTX_ERROR_BAD_API;
+   if (!intelInitContext(intel, api, major_version, minor_version,
+                         mesaVis, driContextPriv,
+                         sharedContextPrivate, &functions,
+                         error)) {
+      ralloc_free(i915);
       return false;
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 6b04290..755a33a 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -87,47 +87,8 @@ brwCreateContext(int api,
    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
    struct intel_screen *screen = sPriv->driverPrivate;
    struct dd_function_table functions;
-   const unsigned req_version = major_version * 10 + minor_version;
-   unsigned max_supported_version = 0;
    unsigned i;
 
-#ifdef TEXTURE_FLOAT_ENABLED
-   bool has_texture_float = true;
-#else
-   bool has_texture_float = false;
-#endif
-
-   bool supports_gl30 = has_texture_float &&
-                        (screen->gen == 6 ||
-                         (screen->gen == 7 &&
-                          screen->kernel_has_gen7_sol_reset));
-
-   /* Determine max_supported_version. */
-   switch (api) {
-   case API_OPENGL:
-      max_supported_version = supports_gl30 ? 30 : 21;
-      break;
-   case API_OPENGLES:
-      max_supported_version = 11;
-      break;
-   case API_OPENGLES2:
-      max_supported_version = supports_gl30 ? 30 : 20;
-      break;
-   case API_OPENGL_CORE:
-      max_supported_version = supports_gl30 ? 31 : 0;
-      break;
-   default:
-      break;
-   }
-
-   if (max_supported_version == 0) {
-      *error = __DRI_CTX_ERROR_BAD_API;
-      return false;
-   } else if (req_version > max_supported_version) {
-      *error = __DRI_CTX_ERROR_BAD_VERSION;
-      return false;
-   }
-
    struct brw_context *brw = rzalloc(NULL, struct brw_context);
    if (!brw) {
       printf("%s: failed to alloc context\n", __FUNCTION__);
@@ -147,10 +108,12 @@ brwCreateContext(int api,
    struct intel_context *intel = &brw->intel;
    struct gl_context *ctx = &intel->ctx;
 
-   if (!intelInitContext( intel, api, mesaVis, driContextPriv,
-			  sharedContextPrivate, &functions )) {
+   if (!intelInitContext( intel, api, major_version, minor_version,
+                          mesaVis, driContextPriv,
+			  sharedContextPrivate, &functions,
+			  error)) {
       printf("%s: failed to init intel context\n", __FUNCTION__);
-      *error = __DRI_CTX_ERROR_NO_MEMORY;
+      ralloc_free(brw);
       return false;
    }
 
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 204609e..0018f44 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -577,13 +577,55 @@ intelInitDriverFunctions(struct dd_function_table *functions)
    intel_init_syncobj_functions(functions);
 }
 
+static bool
+validate_context_version(struct intel_screen *screen,
+                         int mesa_api,
+                         unsigned major_version,
+                         unsigned minor_version,
+                         unsigned *dri_ctx_error)
+{
+   unsigned req_version = 10 * major_version + minor_version;
+   unsigned max_version = 0;
+
+   switch (mesa_api) {
+   case API_OPENGL:
+      max_version = screen->max_gl_compat_version;
+      break;
+   case API_OPENGL_CORE:
+      max_version = screen->max_gl_core_version;
+      break;
+   case API_OPENGLES:
+      max_version = screen->max_gl_es1_version;
+      break;
+   case API_OPENGLES2:
+      max_version = screen->max_gl_es2_version;
+      break;
+   default:
+      max_version = 0;
+      break;
+   }
+
+   if (max_version == 0) {
+      *dri_ctx_error = __DRI_CTX_ERROR_BAD_API;
+      return false;
+   } else if (req_version > max_version) {
+      *dri_ctx_error = __DRI_CTX_ERROR_BAD_VERSION;
+      return false;
+   }
+
+   return true;
+}
+
 bool
 intelInitContext(struct intel_context *intel,
-		 int api,
+                 int api,
+                 unsigned major_version,
+                 unsigned minor_version,
                  const struct gl_config * mesaVis,
                  __DRIcontext * driContextPriv,
                  void *sharedContextPrivate,
-                 struct dd_function_table *functions)
+                 struct dd_function_table *functions,
+                 unsigned *dri_ctx_error)
 {
    struct gl_context *ctx = &intel->ctx;
    struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
@@ -593,7 +635,14 @@ intelInitContext(struct intel_context *intel,
    struct gl_config visual;
 
    /* we can't do anything without a connection to the device */
-   if (intelScreen->bufmgr == NULL)
+   if (intelScreen->bufmgr == NULL) {
+      *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
+      return false;
+   }
+
+   if (!validate_context_version(intelScreen,
+                                 api, major_version, minor_version,
+                                 dri_ctx_error))
       return false;
 
    /* Can't rely on invalidate events, fall back to glViewport hack */
@@ -609,6 +658,7 @@ intelInitContext(struct intel_context *intel,
 
    if (!_mesa_initialize_context(&intel->ctx, api, mesaVis, shareCtx,
                                  functions)) {
+      *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
       printf("%s: failed to init mesa context\n", __FUNCTION__);
       return false;
    }
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index eeefadf..df79eae 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -513,11 +513,14 @@ extern int INTEL_DEBUG;
  */
 
 extern bool intelInitContext(struct intel_context *intel,
-				  int api,
-                                  const struct gl_config * mesaVis,
-                                  __DRIcontext * driContextPriv,
-                                  void *sharedContextPrivate,
-                                  struct dd_function_table *functions);
+                             int api,
+                             unsigned major_version,
+                             unsigned minor_version,
+                             const struct gl_config * mesaVis,
+                             __DRIcontext * driContextPriv,
+                             void *sharedContextPrivate,
+                             struct dd_function_table *functions,
+                             unsigned *dri_ctx_error);
 
 extern void intelFinish(struct gl_context * ctx);
 extern void intel_flush_rendering_to_batch(struct gl_context *ctx);
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index b63e4f7..feca162 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -749,8 +749,12 @@ intelDestroyBuffer(__DRIdrawable * driDrawPriv)
  * functions.
  */
 extern bool
-i830CreateContext(const struct gl_config *mesaVis,
+i830CreateContext(int api,
+                  const struct gl_config *mesaVis,
 		  __DRIcontext *driContextPriv,
+		  unsigned major_version,
+		  unsigned minor_version,
+		  unsigned *error,
 		  void *sharedContextPrivate);
 
 extern bool
@@ -792,27 +796,10 @@ intelCreateContext(gl_api api,
                                   major_version, minor_version, error,
                                   sharedContextPrivate);
    } else {
-      switch (api) {
-      case API_OPENGL:
-         if (major_version > 1 || minor_version > 3) {
-            *error = __DRI_CTX_ERROR_BAD_VERSION;
-            success = false;
-         }
-         break;
-      case API_OPENGLES:
-         break;
-      default:
-         *error = __DRI_CTX_ERROR_BAD_API;
-         success = false;
-      }
-
-      if (success) {
-         intelScreen->no_vbo = true;
-         success = i830CreateContext(mesaVis, driContextPriv,
-                                     sharedContextPrivate);
-         if (!success)
-            *error = __DRI_CTX_ERROR_NO_MEMORY;
-      }
+      intelScreen->no_vbo = true;
+      success = i830CreateContext(api, mesaVis, driContextPriv,
+                                  major_version, minor_version, error,
+                                  sharedContextPrivate);
    }
 #else
    success = brwCreateContext(api, mesaVis,
-- 
1.7.11.7



More information about the mesa-dev mailing list