[Mesa-dev] [RFC] [PATCH 3/3] i965: implement driResourceSharing extension.

Zhigang Gong zhigang.gong at linux.intel.com
Sun Jul 14 22:46:10 PDT 2013


This patch implements the texture sharing.

Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
 src/mesa/drivers/dri/i965/Makefile.am              |    2 +
 src/mesa/drivers/dri/i965/Makefile.sources         |    1 +
 .../drivers/dri/i965/intel_dri_resource_share.c    |  192 ++++++++++++++++++++
 .../drivers/dri/i965/intel_dri_resource_share.h    |   36 ++++
 src/mesa/drivers/dri/i965/intel_screen.c           |    9 +-
 src/mesa/drivers/dri/i965/intel_screen.h           |   10 +
 6 files changed, 249 insertions(+), 1 deletion(-)
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.c
 create mode 100644 src/mesa/drivers/dri/i965/intel_dri_resource_share.h

diff --git a/src/mesa/drivers/dri/i965/Makefile.am b/src/mesa/drivers/dri/i965/Makefile.am
index 27c67d1..d456910 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -48,6 +48,8 @@ AM_CFLAGS += \
 	-DFEATURE_ES2=1
 endif
 
+include_HEADERS = intel_dri_resource_share.h
+
 AM_CXXFLAGS = $(AM_CFLAGS)
 
 dridir = $(DRI_DRIVER_INSTALL_DIR)
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources
index 1f401fe..695d9b3 100644
--- a/src/mesa/drivers/dri/i965/Makefile.sources
+++ b/src/mesa/drivers/dri/i965/Makefile.sources
@@ -14,6 +14,7 @@ i965_FILES = \
 	intel_regions.c \
 	intel_resolve_map.c \
 	intel_screen.c \
+        intel_dri_resource_share.c \
 	intel_pixel.c \
 	intel_pixel_bitmap.c \
 	intel_pixel_copy.c \
diff --git a/src/mesa/drivers/dri/i965/intel_dri_resource_share.c b/src/mesa/drivers/dri/i965/intel_dri_resource_share.c
new file mode 100644
index 0000000..ffcc5ce
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/intel_dri_resource_share.c
@@ -0,0 +1,192 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include <errno.h>
+#include <time.h>
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
+#include "main/texobj.h"
+#include "main/hash.h"
+#include "main/fbobject.h"
+#include "main/version.h"
+
+#include "utils.h"
+#include "xmlpool.h"
+
+#include "intel_batchbuffer.h"
+#include "intel_buffers.h"
+#include "intel_bufmgr.h"
+#include "intel_chipset.h"
+#include "intel_fbo.h"
+#include "intel_mipmap_tree.h"
+#include "intel_screen.h"
+#include "intel_tex.h"
+#include "intel_regions.h"
+#include "intel_context.h"
+
+#include "i915_drm.h"
+#include "intel_dri_resource_share.h"
+
+
+/**
+ * Sets up a DRIImage structure to point to our shared image in a region
+ */
+static GLboolean
+intel_setup_cl_region_from_mipmap_tree(struct intel_context *intel,
+                                       struct intel_mipmap_tree *mt,
+                                       GLuint level, GLuint zoffset,
+                                       struct _intel_dri_share_image_region *region)
+{
+   unsigned int draw_x, draw_y;
+   uint32_t mask_x, mask_y;
+   struct intel_region *null_region = (struct intel_region *)NULL;
+
+   intel_miptree_check_level_layer(mt, level, zoffset);
+
+   intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false);
+   intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y);
+
+   region->w = mt->level[level].width;
+   region->h = mt->level[level].height;
+   region->tile_x = draw_x & mask_x;
+   region->tile_y = draw_y & mask_y;
+   region->tiling = mt->region->tiling;
+   /* XXX hard code to 1 right now. */
+   region->depth = 1;
+   region->row_pitch = mt->region->pitch;
+
+   region->offset = intel_region_get_aligned_offset(mt->region,
+                                                    draw_x & ~mask_x,
+                                                    draw_y & ~mask_y,
+                                                    false);
+   if (!intel_region_flink(mt->region, &region->name))
+      return false;
+   intel_region_reference(&null_region, mt->region);
+   return true;
+}
+
+static struct gl_texture_object *
+intel_get_gl_obj_from_texture(struct intel_context *intel,
+                              GLenum target, GLint level,
+                              GLuint texture, GLuint face)
+{
+   struct gl_texture_object *obj;
+   obj = _mesa_lookup_texture(&intel->ctx, texture);
+   if (!obj || obj->Target != target) {
+      return NULL;
+   }
+
+   _mesa_test_texobj_completeness(&intel->ctx, obj);
+   if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
+      return NULL;
+   }
+
+   if (level < obj->BaseLevel || level > obj->_MaxLevel) {
+      return NULL;
+   }
+
+   return obj;
+}
+
+static GLenum
+get_cl_gl_format(gl_format format)
+{
+   switch (format) {
+   case MESA_FORMAT_RGBA8888:
+      return GL_RGBA;
+   case MESA_FORMAT_ARGB8888:
+      return GL_BGRA;
+   default:
+      return GL_BGRA;
+  }
+}
+
+GLboolean
+intelAcquireTexture(__DRIcontext *context, GLenum target,
+                    GLint level, GLuint texture, void *user_data)
+{
+   struct _intel_dri_share_image_region *region = intel_dri_share_image_region(user_data);
+   struct intel_context *intel = context->driverPrivate;
+   struct gl_texture_object *obj;
+   struct intel_texture_object *iobj;
+   /* XXX Always be face 0? */
+   GLuint face = 0;
+
+   obj = intel_get_gl_obj_from_texture(intel, target, level, texture, face);
+   if (obj == NULL)
+     return false;
+   iobj = intel_texture_object(obj);
+   region->gl_format = get_cl_gl_format(obj->Image[face][level]->TexFormat);
+   return intel_setup_cl_region_from_mipmap_tree(intel, iobj->mt, level, 0, region);
+}
+
+GLboolean
+intelReleaseTexture(__DRIcontext *context, GLenum target,
+                    GLint level, GLuint texture)
+{
+   struct intel_context *intel = context->driverPrivate;
+   struct gl_texture_object *obj;
+   struct intel_texture_object *iobj;
+   /* XXX Always be face 0? */
+   GLuint face = 0;
+
+   obj = intel_get_gl_obj_from_texture(intel, target, level, texture, face);
+   if (obj == NULL)
+     return false;
+
+   iobj = intel_texture_object(obj);
+   intel_region_release(&iobj->mt->region);
+   return true;
+}
+
+GLboolean
+intelAcquireBufferObj(__DRIcontext *driContextPriv,
+                      GLuint bufobj, void *user_data)
+{
+  return false;
+}
+
+GLboolean
+intelReleaseBufferObj(__DRIcontext *driContextPriv, GLuint bufobj)
+{
+  return false;
+}
+
+GLboolean
+intelAcquireRenderBuffer(__DRIcontext *driContextPriv,
+                         GLuint bufobj, void *user_data)
+{
+  return false;
+}
+
+GLboolean
+intelReleaseRenderBuffer(__DRIcontext *driContextPriv, GLuint bufobj)
+{
+  return false;
+}
diff --git a/src/mesa/drivers/dri/i965/intel_dri_resource_share.h b/src/mesa/drivers/dri/i965/intel_dri_resource_share.h
new file mode 100644
index 0000000..34f33a8
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/intel_dri_resource_share.h
@@ -0,0 +1,36 @@
+#ifndef __INTEL_DRI_RESOURCE_SHARE_H__
+#define __INTEL_DRI_RESOURCE_SHARE_H__
+
+struct _intel_dri_share_image_region {
+  unsigned int name;
+  size_t w;
+  size_t h;
+  size_t depth;
+  size_t pitch;
+  int tiling;
+  size_t offset;
+  size_t tile_x;
+  size_t tile_y;
+  unsigned int gl_format;
+  size_t row_pitch, slice_pitch;
+};
+
+struct _intel_dri_share_buffer_object {
+  unsigned int name;
+  size_t sz;
+  size_t offset;
+};
+
+inline static struct _intel_dri_share_image_region *
+intel_dri_share_image_region(void *user_data)
+{
+   return (struct _intel_dri_share_image_region *)user_data;
+}
+
+inline static struct _intel_dri_share_buffer_object *
+intel_dri_share_buffer_object(void *user_data)
+{
+   return (struct _intel_dri_share_buffer_object *)user_data;
+}
+
+#endif
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 252d356..751f681 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -753,6 +753,7 @@ static const __DRIextension *intelScreenExtensions[] = {
     &intelFlushExtension.base,
     &intelImageExtension.base,
     &dri2ConfigQueryExtension.base,
+    &driResourceShareExtension.base,
     NULL
 };
 
@@ -1318,7 +1319,13 @@ const struct __DriverAPIRec driDriverAPI = {
    .MakeCurrent		 = intelMakeCurrent,
    .UnbindContext	 = intelUnbindContext,
    .AllocateBuffer       = intelAllocateBuffer,
-   .ReleaseBuffer        = intelReleaseBuffer
+   .ReleaseBuffer        = intelReleaseBuffer,
+   .AcquireTexture       = intelAcquireTexture,
+   .ReleaseTexture       = intelReleaseTexture,
+   .AcquireBufferObj     = intelAcquireBufferObj,
+   .ReleaseBufferObj     = intelReleaseBufferObj,
+   .AcquireRenderBuffer  = intelAcquireRenderBuffer,
+   .ReleaseRenderBuffer  = intelReleaseRenderBuffer,
 };
 
 /* This is the table of extensions that the loader will dlsym() for. */
diff --git a/src/mesa/drivers/dri/i965/intel_screen.h b/src/mesa/drivers/dri/i965/intel_screen.h
index 3b99b82..c5c3875 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.h
+++ b/src/mesa/drivers/dri/i965/intel_screen.h
@@ -74,6 +74,16 @@ struct intel_screen
 };
 
 extern void intelDestroyContext(__DRIcontext * driContextPriv);
+extern GLboolean intelAcquireTexture(__DRIcontext *context, GLenum target,
+                                     GLint level, GLuint texture, void *user_data);
+extern GLboolean intelReleaseTexture(__DRIcontext *driContextPriv, GLenum target,
+                                     GLint level, GLuint tex);
+extern GLboolean intelAcquireBufferObj(__DRIcontext *driContextPriv,
+                                       GLuint bufobj, void *user_data);
+extern GLboolean intelReleaseBufferObj(__DRIcontext *driContextPriv, GLuint bufobj);
+extern GLboolean intelAcquireRenderBuffer(__DRIcontext *driContextPriv,
+                                          GLuint bufobj, void *user_data);
+extern GLboolean intelReleaseRenderBuffer(__DRIcontext *driContextPriv, GLuint bufobj);
 
 extern GLboolean intelUnbindContext(__DRIcontext * driContextPriv);
 
-- 
1.7.9.5



More information about the mesa-dev mailing list