intel: Set screen's api mask according to hw capabilities (v3)
authorChad Versace <chad.versace@linux.intel.com>
Wed, 21 Nov 2012 23:08:27 +0000 (15:08 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 15 Jan 2013 21:44:29 +0000 (13:44 -0800)
Before this patch, intelInitScreen2 set DRIScreen::api_mask with the hacky
heuristic below:

    if (gen >= 3)
        api_mask = GL | GLES1 | GLES2;
    else
        api_mask = 0;

This hack was likely broken on gen2 (i830), but I don't care enough to
properly investigate. It appears that every EGLConfig on i830 has
EGL_RENDERABLE_TYPE=0, and thus eglCreateContext will never succeed.
Anyway, moving on to living drivers...

With the arrival of EGL_OPENGL_ES3_BIT_KHR, this heuristic is now
insufficient. We must enable the GLES3 bit if and only if the driver is
capable of creating a GLES3 context. This requires us to determine the
maximum supported context version supported by the hardware/driver for
each api *during initialization of intel_screen*.

Therefore, this patch adds four new fields to intel_screen which indicate
the maximum supported context version for each api:
  max_gl_core_version
  max_gl_compat_version
  max_gl_es1_version
  max_gl_es2_version

The api mask is now correctly set as:

    api_mask = GL;
    if (max_gl_es1_version > 0)
        api_mask |= GLES1;
    if (max_gl_es2_version > 0)
        api_mask |= GLES2;

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.

v2:
  - Replace the if-tree on gen with a switch, for Ian.
  - Unconditionally enable the DRI_API_OPENGL bit, for Ian.

v3:
  - Drop max gl version to 1.4 on gen3 if !has_occlusion_query,
    because occlusion queries entered core in 1.5. For Ian.

v4:
  - Drop ES2 version back to 2.0 due to rebase (Ian).

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick.intel.com>
src/mesa/drivers/dri/intel/intel_screen.c
src/mesa/drivers/dri/intel/intel_screen.h

index 557f1af7aa85d5b908e85ccf474f8a6ef0397210..a001fddd962765bc28287320e95a3a8404f14dce 100644 (file)
@@ -1051,6 +1051,90 @@ intel_screen_make_configs(__DRIscreen *dri_screen)
    return configs;
 }
 
+static void
+set_max_gl_versions(struct intel_screen *screen)
+{
+#ifdef TEXTURE_FLOAT_ENABLED
+   bool has_texture_float = true;
+#else
+   bool has_texture_float = false;
+#endif
+
+   switch (screen->gen) {
+   case 7:
+      if (has_texture_float && screen->kernel_has_gen7_sol_reset) {
+         screen->max_gl_core_version = 31;
+         screen->max_gl_compat_version = 30;
+         screen->max_gl_es1_version = 11;
+         screen->max_gl_es2_version = 20;
+      } else {
+         screen->max_gl_core_version = 0;
+         screen->max_gl_compat_version = 21;
+         screen->max_gl_es1_version = 11;
+         screen->max_gl_es2_version = 20;
+      }
+      break;
+   case 6:
+      if (has_texture_float) {
+         screen->max_gl_core_version = 31;
+         screen->max_gl_compat_version = 30;
+         screen->max_gl_es1_version = 11;
+         screen->max_gl_es2_version = 20;
+      } else {
+         screen->max_gl_core_version = 0;
+         screen->max_gl_compat_version = 21;
+         screen->max_gl_es1_version = 11;
+         screen->max_gl_es2_version = 20;
+      }
+      break;
+   case 5:
+   case 4:
+      screen->max_gl_core_version = 0;
+      screen->max_gl_compat_version = 21;
+      screen->max_gl_es1_version = 11;
+      screen->max_gl_es2_version = 20;
+      break;
+   case 3: {
+      bool has_fragment_shader = driQueryOptionb(&screen->optionCache, "fragment_shader");
+      bool has_occlusion_query = driQueryOptionb(&screen->optionCache, "stub_occlusion_query");
+
+      screen->max_gl_core_version = 0;
+      screen->max_gl_es1_version = 11;
+
+      if (has_fragment_shader && has_occlusion_query) {
+         screen->max_gl_compat_version = 21;
+      } else {
+         screen->max_gl_compat_version = 14;
+      }
+
+      if (has_fragment_shader) {
+         screen->max_gl_es2_version = 20;
+      } else {
+         screen->max_gl_es2_version = 0;
+      }
+
+      break;
+   }
+   case 2:
+      screen->max_gl_core_version = 0;
+      screen->max_gl_compat_version = 13;
+      screen->max_gl_es1_version = 11;
+      screen->max_gl_es2_version = 0;
+      break;
+   default:
+      assert(!"unrecognized intel_screen::gen");
+      break;
+   }
+
+#ifndef FEATURE_ES1
+   screen->max_gl_es1_version = 0;
+#endif
+
+#ifndef FEATURE_ES2
+   screen->max_gl_es2_version = 0;
+#endif
+}
+
 /**
  * This is the driver specific part of the createNewScreen entry point.
  * Called when using DRI2.
@@ -1061,7 +1145,6 @@ static const
 __DRIconfig **intelInitScreen2(__DRIscreen *psp)
 {
    struct intel_screen *intelScreen;
-   unsigned int api_mask;
 
    if (psp->dri2.loader->base.version <= 2 ||
        psp->dri2.loader->getBuffersWithFormat == NULL) {
@@ -1120,18 +1203,15 @@ __DRIconfig **intelInitScreen2(__DRIscreen *psp)
 
    intel_override_separate_stencil(intelScreen);
 
-   api_mask = (1 << __DRI_API_OPENGL);
-#if FEATURE_ES1
-   api_mask |= (1 << __DRI_API_GLES);
-#endif
-#if FEATURE_ES2
-   api_mask |= (1 << __DRI_API_GLES2);
-#endif
+   intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen);
 
-   if (IS_9XX(intelScreen->deviceID) || IS_965(intelScreen->deviceID))
-      psp->api_mask = api_mask;
+   set_max_gl_versions(intelScreen);
 
-   intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen);
+   psp->api_mask = (1 << __DRI_API_OPENGL);
+   if (intelScreen->max_gl_es1_version > 0)
+      psp->api_mask |= (1 << __DRI_API_GLES);
+   if (intelScreen->max_gl_es2_version > 0)
+      psp->api_mask |= (1 << __DRI_API_GLES2);
 
    psp->extensions = intelScreenExtensions;
 
index 8a4a0a2d98c03064617f2a9434774d71b4381640..b9c96be5b3938791745c2019007436253e0a4b92 100644 (file)
@@ -40,6 +40,11 @@ struct intel_screen
    int deviceID;
    int gen;
 
+   int max_gl_core_version;
+   int max_gl_compat_version;
+   int max_gl_es1_version;
+   int max_gl_es2_version;
+
    int logTextureGranularity;
 
    __DRIscreen *driScrnPriv;