summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/intel/intel_screen.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2008-09-04 22:16:31 +0100
committerEric Anholt <eric@anholt.net>2008-09-10 13:59:45 -0700
commit7e0bbdcf033981282978554c2e68ce48b55aa291 (patch)
treed604788e8770df7d2bc2853473e18045a9a74cdf /src/mesa/drivers/dri/intel/intel_screen.c
parent11d694b1bb0cb384d802d7e0e252cf5119febb98 (diff)
downloadexternal_mesa3d-7e0bbdcf033981282978554c2e68ce48b55aa291.zip
external_mesa3d-7e0bbdcf033981282978554c2e68ce48b55aa291.tar.gz
external_mesa3d-7e0bbdcf033981282978554c2e68ce48b55aa291.tar.bz2
intel: Move the bufmgr back to the screen.
Mesa requires that we be able to share objects between contexts, which means that the objects need to be created by the same bufmgr, and the bufmgr internally requires pthread protection for thread safety. Rely on the bufmgr having appropriate locking.
Diffstat (limited to 'src/mesa/drivers/dri/intel/intel_screen.c')
-rw-r--r--src/mesa/drivers/dri/intel/intel_screen.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index c193830..5cfb893 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -552,6 +552,96 @@ intelFillInModes(__DRIscreenPrivate *psp,
}
+/** Driver-specific fence emit implementation for the fake memory manager. */
+static unsigned int
+intel_fence_emit(void *private)
+{
+ intelScreenPrivate *intelScreen = (intelScreenPrivate *)private;
+ unsigned int fence;
+
+ /* XXX: Need to emit a flush, if we haven't already (at least with the
+ * current batchbuffer implementation, we have).
+ */
+
+ fence = intelEmitIrqLocked(intelScreen);
+
+ return fence;
+}
+
+/** Driver-specific fence wait implementation for the fake memory manager. */
+static int
+intel_fence_wait(void *private, unsigned int cookie)
+{
+ intelScreenPrivate *intelScreen = (intelScreenPrivate *)private;
+
+ intelWaitIrq(intelScreen, cookie);
+
+ return 0;
+}
+
+static GLboolean
+intel_init_bufmgr(intelScreenPrivate *intelScreen)
+{
+ GLboolean gem_disable = getenv("INTEL_NO_GEM") != NULL;
+ int gem_kernel = 0;
+ GLboolean gem_supported;
+ struct drm_i915_getparam gp;
+ __DRIscreenPrivate *spriv = intelScreen->driScrnPriv;
+
+ intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
+
+ gp.param = I915_PARAM_HAS_GEM;
+ gp.value = &gem_kernel;
+
+ (void) drmCommandWriteRead(spriv->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
+
+ /* If we've got a new enough DDX that's initializing GEM and giving us
+ * object handles for the shared buffers, use that.
+ */
+ intelScreen->ttm = GL_FALSE;
+ if (intelScreen->driScrnPriv->dri2.enabled)
+ gem_supported = GL_TRUE;
+ else if (intelScreen->driScrnPriv->ddx_version.minor >= 9 &&
+ gem_kernel &&
+ intelScreen->front.bo_handle != -1)
+ gem_supported = GL_TRUE;
+ else
+ gem_supported = GL_FALSE;
+
+ if (!gem_disable && gem_supported) {
+ intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
+ if (intelScreen->bufmgr != NULL)
+ intelScreen->ttm = GL_TRUE;
+ }
+ /* Otherwise, use the classic buffer manager. */
+ if (intelScreen->bufmgr == NULL) {
+ if (gem_disable) {
+ fprintf(stderr, "GEM disabled. Using classic.\n");
+ } else {
+ fprintf(stderr, "Failed to initialize GEM. "
+ "Falling back to classic.\n");
+ }
+
+ if (intelScreen->tex.size == 0) {
+ fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
+ __func__, __LINE__);
+ return GL_FALSE;
+ }
+
+ intelScreen->bufmgr = intel_bufmgr_fake_init(intelScreen->tex.offset,
+ intelScreen->tex.map,
+ intelScreen->tex.size,
+ intel_fence_emit,
+ intel_fence_wait,
+ intelScreen);
+ }
+
+ /* XXX bufmgr should be per-screen, not per-context */
+ intelScreen->ttm = intelScreen->ttm;
+
+ return GL_TRUE;
+}
+
/**
* This is the driver specific part of the createNewScreen entry point.
* Called when using legacy DRI.
@@ -562,6 +652,7 @@ intelFillInModes(__DRIscreenPrivate *psp,
*/
static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
{
+ intelScreenPrivate *intelScreen;
#ifdef I915
static const __DRIversion ddx_expected = { 1, 5, 0 };
#else
@@ -595,6 +686,10 @@ static const __DRIconfig **intelInitScreen(__DRIscreenPrivate *psp)
psp->extensions = intelScreenExtensions;
+ intelScreen = psp->private;
+ if (!intel_init_bufmgr(intelScreen))
+ return GL_FALSE;
+
return (const __DRIconfig **)
intelFillInModes(psp, dri_priv->cpp * 8,
(dri_priv->cpp == 2) ? 16 : 24,
@@ -659,6 +754,9 @@ __DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
&intelScreen->deviceID))
return GL_FALSE;
+ if (!intel_init_bufmgr(intelScreen))
+ return GL_FALSE;
+
intelScreen->irq_active = 1;
psp->extensions = intelScreenExtensions;