[Intel-gfx] [PATCH] XvMC: pin XvMC buffers under KMS.

Xiang, Haihao haihao.xiang at intel.com
Wed Jul 22 09:33:43 CEST 2009


Under KMS, the buffer allocated by i830_allocate_memory
isn't pinned any more. However currently 915 XvMC needs
static offsets.

Fixes bug #22872
---
 src/i830.h        |    1 +
 src/i830_hwmc.c   |    2 +-
 src/i830_memory.c |   26 ++++++++++++++++++++++++--
 src/i915_hwmc.c   |   20 ++++++++++----------
 4 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/src/i830.h b/src/i830.h
index 21c98f5..58afe76 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -726,6 +726,7 @@ void i830_init_bufmgr(ScrnInfoPtr pScrn);
 #ifdef INTEL_XVMC
 Bool i830_allocate_xvmc_buffer(ScrnInfoPtr pScrn, const char *name,
                                i830_memory **buffer, unsigned long size, int flags);
+void i830_free_xvmc_buffer(ScrnInfoPtr pScrn, i830_memory *buffer);
 #endif
 extern uint32_t i830_create_new_fb(ScrnInfoPtr pScrn, int width, int height,
 				   int *pitch);
diff --git a/src/i830_hwmc.c b/src/i830_hwmc.c
index dee17ca..72385de 100644
--- a/src/i830_hwmc.c
+++ b/src/i830_hwmc.c
@@ -171,7 +171,7 @@ void intel_xvmc_fini_batch(ScrnInfoPtr pScrn)
         xvmc_driver->batch_handle = 0;
     }
     if (xvmc_driver->batch) {
-        i830_free_memory(pScrn, xvmc_driver->batch);
+        i830_free_xvmc_buffer(pScrn, xvmc_driver->batch);
         xvmc_driver->batch = NULL;
     }
 }
diff --git a/src/i830_memory.c b/src/i830_memory.c
index cc9d376..d3c9299 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1652,6 +1652,8 @@ Bool i830_allocate_xvmc_buffer(ScrnInfoPtr pScrn, const char *name,
                                i830_memory **buffer, unsigned long size,
                                int flags)
 {
+    I830Ptr pI830 = I830PTR(pScrn);
+
     *buffer = i830_allocate_memory(pScrn, name, size, PITCH_NONE,
                                    GTT_PAGE_SIZE, flags, TILE_NONE);
 
@@ -1661,11 +1663,31 @@ Bool i830_allocate_xvmc_buffer(ScrnInfoPtr pScrn, const char *name,
         return FALSE;
     }
 
-    if (!i830_bind_memory(pScrn, *buffer))
-	return FALSE;
+    if (pI830->use_drm_mode && (*buffer)->bo) {
+        if (drm_intel_bo_pin((*buffer)->bo, GTT_PAGE_SIZE)) {
+            i830_free_memory(pScrn, *buffer);
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "Failed to bind XvMC buffer bo!\n");
+            return FALSE;
+        }
+
+        (*buffer)->offset = (*buffer)->bo->offset;
+    }
 
     return TRUE;
 }
+
+void
+i830_free_xvmc_buffer(ScrnInfoPtr pScrn, i830_memory *buffer)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    if (pI830->use_drm_mode && buffer->bo)
+        drm_intel_bo_unpin(buffer->bo);
+
+    i830_free_memory(pScrn, buffer);
+}
+
 #endif
 
 void
diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 0723c80..6712caa 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -368,32 +368,32 @@ static Bool i915_allocate_xvmc_buffers(ScrnInfoPtr pScrn, I915XvMCContextPriv *c
 static void i915_free_xvmc_buffers(ScrnInfoPtr pScrn, I915XvMCContextPriv *ctxpriv)
 {
     if (ctxpriv->mcStaticIndirectState) {
-        i830_free_memory(pScrn, ctxpriv->mcStaticIndirectState);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcStaticIndirectState);
         ctxpriv->mcStaticIndirectState = NULL;
     }
 
     if (ctxpriv->mcSamplerState) {
-        i830_free_memory(pScrn, ctxpriv->mcSamplerState);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcSamplerState);
         ctxpriv->mcSamplerState = NULL;
     }
 
     if (ctxpriv->mcMapState) {
-        i830_free_memory(pScrn, ctxpriv->mcMapState);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcMapState);
         ctxpriv->mcMapState = NULL;
     }
 
     if (ctxpriv->mcPixelShaderProgram) {
-        i830_free_memory(pScrn, ctxpriv->mcPixelShaderProgram);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcPixelShaderProgram);
         ctxpriv->mcPixelShaderProgram = NULL;
     }
 
     if (ctxpriv->mcPixelShaderConstants) {
-        i830_free_memory(pScrn, ctxpriv->mcPixelShaderConstants);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcPixelShaderConstants);
         ctxpriv->mcPixelShaderConstants = NULL;
     }
 
     if (ctxpriv->mcCorrdata) {
-        i830_free_memory(pScrn, ctxpriv->mcCorrdata);
+        i830_free_xvmc_buffer(pScrn, ctxpriv->mcCorrdata);
         ctxpriv->mcCorrdata = NULL;
     }
 
@@ -606,7 +606,7 @@ static int i915_xvmc_create_surface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf,
                   (drmAddress)&sfpriv->surface_handle) < 0) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                    "[drm] drmAddMap(surface_handle) failed!\n");
-        i830_free_memory(pScrn, sfpriv->surface);
+        i830_free_xvmc_buffer(pScrn, sfpriv->surface);
         xfree(sfpriv);
         xfree(*priv);
         *priv = NULL;
@@ -694,7 +694,7 @@ static int i915_xvmc_create_subpict(ScrnInfoPtr pScrn, XvMCSubpicturePtr pSubp,
                   (drmAddress)&sfpriv->surface_handle) < 0) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                    "[drm] drmAddMap(surface_handle) failed!\n");
-        i830_free_memory(pScrn, sfpriv->surface);
+        i830_free_xvmc_buffer(pScrn, sfpriv->surface);
         xfree(sfpriv);
         xfree(*priv);
         *priv = NULL;
@@ -744,7 +744,7 @@ static void i915_xvmc_destroy_surface (ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf)
     for (i = 0; i < I915_XVMC_MAX_SURFACES; i++) {
         if (pXvMC->surfaces[i] == pSurf->surface_id) {
             drmRmMap(pI830->drmSubFD, pXvMC->sfprivs[i]->surface_handle);
-            i830_free_memory(pScrn, pXvMC->sfprivs[i]->surface);
+            i830_free_xvmc_buffer(pScrn, pXvMC->sfprivs[i]->surface);
             xfree(pXvMC->sfprivs[i]);
             pXvMC->nsurfaces--;
             pXvMC->sfprivs[i] = 0;
@@ -766,7 +766,7 @@ static void i915_xvmc_destroy_subpict (ScrnInfoPtr pScrn,
     for (i = 0; i < I915_XVMC_MAX_SURFACES; i++) {
         if (pXvMC->surfaces[i] == pSubp->subpicture_id) {
             drmRmMap(pI830->drmSubFD, pXvMC->sfprivs[i]->surface_handle);
-            i830_free_memory(pScrn, pXvMC->sfprivs[i]->surface);
+            i830_free_xvmc_buffer(pScrn, pXvMC->sfprivs[i]->surface);
             xfree(pXvMC->sfprivs[i]);
             pXvMC->nsurfaces--;
             pXvMC->sfprivs[i] = 0;
-- 
1.5.4.3




More information about the Intel-gfx mailing list