[Mesa-dev] [PATCH 04/29] i965: Move a bunch of code from intelInitContext to brwCreateContext.

Kenneth Graunke kenneth at whitecape.org
Fri Sep 27 16:45:43 PDT 2013


Now that intelInitContext isn't shared between i915 and i965, the split
is fairly arbitrary.  This patch moves a bunch of the basic context
creation and generation checking code up to the top-level function
(and slightly earlier).

More will follow.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_context.c   | 47 +++++++++++++++++++++++++++++--
 src/mesa/drivers/dri/i965/intel_context.c | 47 -------------------------------
 2 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 75034d3..7a7acec 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -31,6 +31,7 @@
 
 
 #include "main/api_exec.h"
+#include "main/context.h"
 #include "main/imports.h"
 #include "main/macros.h"
 #include "main/points.h"
@@ -285,8 +286,10 @@ brwCreateContext(int api,
 	         void *sharedContextPrivate)
 {
    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
+   struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
    struct intel_screen *screen = sPriv->driverPrivate;
    struct dd_function_table functions;
+   struct gl_config visual;
 
    struct brw_context *brw = rzalloc(NULL, struct brw_context);
    if (!brw) {
@@ -295,17 +298,55 @@ brwCreateContext(int api,
       return false;
    }
 
-   /* brwInitVtbl needs to know the chipset generation so that it can set the
-    * right pointers.
-    */
+   driContextPriv->driverPrivate = brw;
+   brw->driContext = driContextPriv;
+   brw->intelScreen = screen;
+   brw->bufmgr = screen->bufmgr;
    brw->gen = screen->gen;
 
+   const int devID = screen->deviceID;
+   if (IS_SNB_GT1(devID) || IS_IVB_GT1(devID) || IS_HSW_GT1(devID))
+      brw->gt = 1;
+   else if (IS_SNB_GT2(devID) || IS_IVB_GT2(devID) || IS_HSW_GT2(devID))
+      brw->gt = 2;
+   else if (IS_HSW_GT3(devID))
+      brw->gt = 3;
+   else
+      brw->gt = 0;
+
+   if (IS_HASWELL(devID)) {
+      brw->is_haswell = true;
+   } else if (IS_BAYTRAIL(devID)) {
+      brw->is_baytrail = true;
+      brw->gt = 1;
+   } else if (IS_G4X(devID)) {
+      brw->is_g4x = true;
+   }
+
+   brw->has_separate_stencil = screen->hw_has_separate_stencil;
+   brw->must_use_separate_stencil = screen->hw_must_use_separate_stencil;
+   brw->has_hiz = brw->gen >= 6;
+   brw->has_llc = screen->hw_has_llc;
+   brw->has_swizzling = screen->hw_has_swizzling;
+
    brwInitVtbl( brw );
 
    brwInitDriverFunctions(screen, &functions);
 
    struct gl_context *ctx = &brw->ctx;
 
+   if (mesaVis == NULL) {
+      memset(&visual, 0, sizeof visual);
+      mesaVis = &visual;
+   }
+
+   if (!_mesa_initialize_context(ctx, api, mesaVis, shareCtx, &functions)) {
+      *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
+      printf("%s: failed to init mesa context\n", __FUNCTION__);
+      intelDestroyContext(driContextPriv);
+      return false;
+   }
+
    if (!intelInitContext( brw, api, major_version, minor_version,
                           mesaVis, driContextPriv,
 			  sharedContextPrivate, &functions,
diff --git a/src/mesa/drivers/dri/i965/intel_context.c b/src/mesa/drivers/dri/i965/intel_context.c
index 850b18c..430967b 100644
--- a/src/mesa/drivers/dri/i965/intel_context.c
+++ b/src/mesa/drivers/dri/i965/intel_context.c
@@ -367,11 +367,9 @@ intelInitContext(struct brw_context *brw,
                  unsigned *dri_ctx_error)
 {
    struct gl_context *ctx = &brw->ctx;
-   struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
    struct intel_screen *intelScreen = sPriv->driverPrivate;
    int bo_reuse_mode;
-   struct gl_config visual;
 
    /* GLX uses DRI2 invalidate events to handle window resizing.
     * Unfortunately, EGL does not - libEGL is written in XCB (not Xlib),
@@ -385,51 +383,6 @@ intelInitContext(struct brw_context *brw,
       functions->Viewport = intel_viewport;
    }
 
-   if (mesaVis == NULL) {
-      memset(&visual, 0, sizeof visual);
-      mesaVis = &visual;
-   }
-
-   brw->intelScreen = intelScreen;
-   brw->bufmgr = intelScreen->bufmgr;
-
-   driContextPriv->driverPrivate = brw;
-   brw->driContext = driContextPriv;
-
-   if (!_mesa_initialize_context(&brw->ctx, api, mesaVis, shareCtx,
-                                 functions)) {
-      *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
-      printf("%s: failed to init mesa context\n", __FUNCTION__);
-      return false;
-   }
-
-   brw->gen = intelScreen->gen;
-
-   const int devID = intelScreen->deviceID;
-   if (IS_SNB_GT1(devID) || IS_IVB_GT1(devID) || IS_HSW_GT1(devID))
-      brw->gt = 1;
-   else if (IS_SNB_GT2(devID) || IS_IVB_GT2(devID) || IS_HSW_GT2(devID))
-      brw->gt = 2;
-   else if (IS_HSW_GT3(devID))
-      brw->gt = 3;
-   else
-      brw->gt = 0;
-
-   if (IS_HASWELL(devID)) {
-      brw->is_haswell = true;
-   } else if (IS_BAYTRAIL(devID)) {
-      brw->is_baytrail = true;
-      brw->gt = 1;
-   } else if (IS_G4X(devID)) {
-      brw->is_g4x = true;
-   }
-
-   brw->has_separate_stencil = brw->intelScreen->hw_has_separate_stencil;
-   brw->must_use_separate_stencil = brw->intelScreen->hw_must_use_separate_stencil;
-   brw->has_hiz = brw->gen >= 6;
-   brw->has_llc = brw->intelScreen->hw_has_llc;
-   brw->has_swizzling = brw->intelScreen->hw_has_swizzling;
-
    memset(&ctx->TextureFormatSupported,
 	  0, sizeof(ctx->TextureFormatSupported));
 
-- 
1.8.3.4



More information about the mesa-dev mailing list