[Mesa-dev] [PATCH 08/13] i915g: add winsys function to create tiled buffers

Daniel Vetter daniel.vetter at ffwll.ch
Fri Nov 19 14:38:25 PST 2010


Different kernels have different restrictions for tiled buffers.
Hence use the libdrm abstraction to calculate the necessary
stride and height alignment requirements.

Not yet used.

Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 src/gallium/drivers/i915/i915_winsys.h        |    8 +++++
 src/gallium/winsys/i915/drm/i915_drm_buffer.c |   35 ++++++++++++++++++++++++-
 src/gallium/winsys/i915/sw/i915_sw_buffer.c   |   27 +++++++++++++++++++
 src/gallium/winsys/i915/sw/i915_sw_winsys.h   |    2 +
 4 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/src/gallium/drivers/i915/i915_winsys.h b/src/gallium/drivers/i915/i915_winsys.h
index 1058a0e..a071c5e 100644
--- a/src/gallium/drivers/i915/i915_winsys.h
+++ b/src/gallium/drivers/i915/i915_winsys.h
@@ -133,6 +133,14 @@ struct i915_winsys {
                        unsigned size);
 
    /**
+    * Create a tiled buffer.
+    */
+   struct i915_winsys_buffer *
+      (*buffer_create_tiled)(struct i915_winsys *iws,
+                       unsigned x, unsigned y,
+		       unsigned *tiling, unsigned *stride);
+
+   /**
     * Creates a buffer from a handle.
     * Used to implement pipe_screen::resource_from_handle.
     * Also provides the stride information needed for the
diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
index ffc1772..be87d28 100644
--- a/src/gallium/winsys/i915/drm/i915_drm_buffer.c
+++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c
@@ -11,7 +11,6 @@ i915_drm_buffer_create(struct i915_winsys *iws,
 {
    struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer);
    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
-   char *name;
 
    if (!buf)
       return NULL;
@@ -35,6 +34,39 @@ err:
 }
 
 static struct i915_winsys_buffer *
+i915_drm_buffer_create_tiled(struct i915_winsys *iws,
+			     unsigned x, unsigned y,
+			     unsigned *tiling, unsigned *stride)
+{
+   struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer);
+   struct i915_drm_winsys *idws = i915_drm_winsys(iws);
+   unsigned long pitch = *stride;
+   uint32_t tiling_mode = *tiling;
+
+   if (!buf)
+      return NULL;
+
+   buf->magic = 0xDEAD1337;
+   buf->flinked = FALSE;
+   buf->flink = 0;
+
+   buf->bo = drm_intel_bo_alloc_tiled(idws->gem_manager, "i915 gallium buffer",
+		   		      x, y, 1, &tiling_mode, &pitch, 0);
+
+   if (!buf->bo)
+      goto err;
+
+   *stride = pitch;
+   *tiling = tiling_mode;
+   return (struct i915_winsys_buffer *)buf;
+
+err:
+   assert(0);
+   FREE(buf);
+   return NULL;
+}
+
+static struct i915_winsys_buffer *
 i915_drm_buffer_from_handle(struct i915_winsys *iws,
                              struct winsys_handle *whandle,
                              unsigned *stride)
@@ -179,6 +211,7 @@ void
 i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws)
 {
    idws->base.buffer_create = i915_drm_buffer_create;
+   idws->base.buffer_create_tiled = i915_drm_buffer_create_tiled;
    idws->base.buffer_from_handle = i915_drm_buffer_from_handle;
    idws->base.buffer_get_handle = i915_drm_buffer_get_handle;
    idws->base.buffer_set_fence_reg = i915_drm_buffer_set_fence_reg;
diff --git a/src/gallium/winsys/i915/sw/i915_sw_buffer.c b/src/gallium/winsys/i915/sw/i915_sw_buffer.c
index a1c2deb..be8b9cb 100644
--- a/src/gallium/winsys/i915/sw/i915_sw_buffer.c
+++ b/src/gallium/winsys/i915/sw/i915_sw_buffer.c
@@ -26,6 +26,32 @@ err:
    return NULL;
 }
 
+static struct i915_winsys_buffer *
+i915_sw_buffer_create_tiled(struct i915_winsys *iws,
+                      unsigned x, unsigned y, unsigned *tiling, unsigned *stride)
+{
+   struct i915_sw_buffer *buf = CALLOC_STRUCT(i915_sw_buffer);
+
+   if (!buf)
+      return NULL;
+
+   buf->magic = 0xDEAD1337;
+   buf->name = "i915 gallium buffer";
+   buf->ptr = CALLOC(*stride * y, 1);
+   buf->tiling = *tiling;
+   buf->stride = *stride;
+
+   if (!buf->ptr)
+      goto err;
+
+   return (struct i915_winsys_buffer *)buf;
+
+err:
+   assert(0);
+   FREE(buf);
+   return NULL;
+}
+
 static int
 i915_sw_buffer_set_fence_reg(struct i915_winsys *iws,
                                struct i915_winsys_buffer *buffer,
@@ -94,6 +120,7 @@ void
 i915_sw_winsys_init_buffer_functions(struct i915_sw_winsys *isws)
 {
    isws->base.buffer_create = i915_sw_buffer_create;
+   isws->base.buffer_create_tiled = i915_sw_buffer_create_tiled;
    isws->base.buffer_set_fence_reg = i915_sw_buffer_set_fence_reg;
    isws->base.buffer_map = i915_sw_buffer_map;
    isws->base.buffer_unmap = i915_sw_buffer_unmap;
diff --git a/src/gallium/winsys/i915/sw/i915_sw_winsys.h b/src/gallium/winsys/i915/sw/i915_sw_winsys.h
index 666ea34..7d6e8fd 100644
--- a/src/gallium/winsys/i915/sw/i915_sw_winsys.h
+++ b/src/gallium/winsys/i915/sw/i915_sw_winsys.h
@@ -44,6 +44,8 @@ struct i915_sw_buffer {
    unsigned map_count;
    enum i915_winsys_buffer_tile tile;
    const char *name;
+   unsigned tiling;
+   unsigned stride;
 };
 
 static INLINE struct i915_sw_buffer *
-- 
1.7.1



More information about the mesa-dev mailing list