[Intel-gfx] [intel-gfx][PATCH] intel: add a new interface drm_intel_bo_alloc_direct

Xiang, Haihao haihao.xiang at intel.com
Tue May 25 07:06:50 CEST 2010


This interface is the same as drm_intel_bo_alloc except the allocated
size isn't rounded up, so it bypasses the cache bucket.

The size of the BO created by drm_intel_bo_alloc for a 1920x800,4:2:0 YUV
planar surface is 4M, it is about 2.2M if using drm_intel_bo_alloc_direct.

Signed-off-by: Xiang, Haihao <haihao.xiang at intel.com>
---
 intel/intel_bufmgr.c      |    9 +++++++++
 intel/intel_bufmgr.h      |    3 +++
 intel/intel_bufmgr_gem.c  |   21 ++++++++++++++++++---
 intel/intel_bufmgr_priv.h |    8 ++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/intel/intel_bufmgr.c b/intel/intel_bufmgr.c
index 9144fdd..1188253 100644
--- a/intel/intel_bufmgr.c
+++ b/intel/intel_bufmgr.c
@@ -50,6 +50,15 @@ drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
 	return bufmgr->bo_alloc(bufmgr, name, size, alignment);
 }
 
+drm_intel_bo *drm_intel_bo_alloc_direct(drm_intel_bufmgr *bufmgr, const char *name,
+					unsigned long size, unsigned int alignment)
+{
+	if (bufmgr->bo_alloc_direct)
+		return bufmgr->bo_alloc_direct(bufmgr, name, size, alignment);
+
+	return NULL;
+}
+
 drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr,
 					    const char *name,
 					    unsigned long size,
diff --git a/intel/intel_bufmgr.h b/intel/intel_bufmgr.h
index cbcddb6..9dd0443 100644
--- a/intel/intel_bufmgr.h
+++ b/intel/intel_bufmgr.h
@@ -78,9 +78,12 @@ struct _drm_intel_bo {
 };
 
 #define BO_ALLOC_FOR_RENDER (1<<0)
+#define BO_ALLOC_DIRECT     (1<<1)
 
 drm_intel_bo *drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
 				 unsigned long size, unsigned int alignment);
+drm_intel_bo *drm_intel_bo_alloc_direct(drm_intel_bufmgr *bufmgr, const char *name,
+					unsigned long size, unsigned int alignment);
 drm_intel_bo *drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr,
 					    const char *name,
 					    unsigned long size,
diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
index b76fd7e..a16cd16 100644
--- a/intel/intel_bufmgr_gem.c
+++ b/intel/intel_bufmgr_gem.c
@@ -556,17 +556,22 @@ drm_intel_gem_bo_alloc_internal(drm_intel_bufmgr *bufmgr,
 	drm_intel_bo_gem *bo_gem;
 	unsigned int page_size = getpagesize();
 	int ret;
-	struct drm_intel_gem_bo_bucket *bucket;
+	struct drm_intel_gem_bo_bucket *bucket = NULL;
 	int alloc_from_cache;
 	unsigned long bo_size;
 	int for_render = 0;
+	int reusable = 1;
 
 	if (flags & BO_ALLOC_FOR_RENDER)
 		for_render = 1;
 
 	/* Round the allocated size up to a power of two number of pages. */
-	bucket = drm_intel_gem_bo_bucket_for_size(bufmgr_gem, size);
+	if (!(flags & BO_ALLOC_DIRECT))
+		bucket = drm_intel_gem_bo_bucket_for_size(bufmgr_gem, size);
 
+	if (bucket == NULL)
+		reusable = 0;
+ 
 	/* If we don't have caching at this size, don't actually round the
 	 * allocation up.
 	 */
@@ -653,7 +658,7 @@ retry:
 	bo_gem->has_error = 0;
 	bo_gem->tiling_mode = I915_TILING_NONE;
 	bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
-	bo_gem->reusable = 1;
+	bo_gem->reusable = reusable;
 
 	drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem);
 
@@ -683,6 +688,15 @@ drm_intel_gem_bo_alloc(drm_intel_bufmgr *bufmgr,
 }
 
 static drm_intel_bo *
+drm_intel_gem_bo_alloc_direct(drm_intel_bufmgr *bufmgr,
+				const char *name,
+				unsigned long size,
+				unsigned int alignment)
+{
+	return drm_intel_gem_bo_alloc_internal(bufmgr, name, size, BO_ALLOC_DIRECT);
+}
+
+static drm_intel_bo *
 drm_intel_gem_bo_alloc_tiled(drm_intel_bufmgr *bufmgr, const char *name,
 			     int x, int y, int cpp, uint32_t *tiling_mode,
 			     unsigned long *pitch, unsigned long flags)
@@ -2058,6 +2072,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
 	bufmgr_gem->max_relocs = batch_size / sizeof(uint32_t) / 2 - 2;
 
 	bufmgr_gem->bufmgr.bo_alloc = drm_intel_gem_bo_alloc;
+	bufmgr_gem->bufmgr.bo_alloc_direct = drm_intel_gem_bo_alloc_direct;
 	bufmgr_gem->bufmgr.bo_alloc_for_render =
 	    drm_intel_gem_bo_alloc_for_render;
 	bufmgr_gem->bufmgr.bo_alloc_tiled = drm_intel_gem_bo_alloc_tiled;
diff --git a/intel/intel_bufmgr_priv.h b/intel/intel_bufmgr_priv.h
index f987d97..47277f4 100644
--- a/intel/intel_bufmgr_priv.h
+++ b/intel/intel_bufmgr_priv.h
@@ -51,6 +51,14 @@ struct _drm_intel_bufmgr {
 				   unsigned long size, unsigned int alignment);
 
 	/**
+	 * Allocate a buffer object.
+	 *
+	 * This is the same as bo_alloc except it bypasses the cache bucket
+	 */
+	drm_intel_bo *(*bo_alloc_direct) (drm_intel_bufmgr *bufmgr, const char *name,
+					unsigned long size, unsigned int alignment);
+
+	/**
 	 * Allocate a buffer object, hinting that it will be used as a
 	 * render target.
 	 *
-- 
1.6.3.3




More information about the Intel-gfx mailing list