Fix GEM execbuf ioctl argument.
[mesa.git] / src / mesa / drivers / dri / intel / intel_regions.c
index a5de01a3a844718d308fe6a92a1963c9b0c44a0f..7d78e4eca7222bdc3e921a7bb9e2eb9b2036ce8f 100644 (file)
@@ -44,7 +44,7 @@
 #include "intel_blit.h"
 #include "intel_buffer_objects.h"
 #include "dri_bufmgr.h"
-#include "intel_bufmgr_ttm.h"
+#include "intel_bufmgr_gem.h"
 #include "intel_batchbuffer.h"
 
 #define FILE_DEBUG_FLAG DEBUG_REGION
@@ -76,24 +76,57 @@ intel_region_unmap(struct intel_context *intel, struct intel_region *region)
    }
 }
 
-struct intel_region *
-intel_region_alloc(struct intel_context *intel,
-                   GLuint cpp, GLuint pitch, GLuint height)
+static struct intel_region *
+intel_region_alloc_internal(struct intel_context *intel,
+                           GLuint cpp, GLuint pitch, GLuint height,
+                           GLuint tiled, dri_bo *buffer)
 {
-   struct intel_region *region = calloc(sizeof(*region), 1);
+   struct intel_region *region;
 
    DBG("%s\n", __FUNCTION__);
 
+   if (buffer == NULL)
+      return NULL;
+
+   region = calloc(sizeof(*region), 1);
    region->cpp = cpp;
    region->pitch = pitch;
    region->height = height;     /* needed? */
    region->refcount = 1;
+   region->tiled = tiled;
+   region->buffer = buffer;
 
-   region->buffer = dri_bo_alloc(intel->bufmgr, "region",
-                                pitch * cpp * height, 64, DRM_BO_FLAG_MEM_TT);
    return region;
 }
 
+struct intel_region *
+intel_region_alloc(struct intel_context *intel,
+                   GLuint cpp, GLuint pitch, GLuint height)
+{
+   dri_bo *buffer;
+
+   buffer = dri_bo_alloc(intel->bufmgr, "region",
+                        pitch * cpp * height, 64,
+                        DRM_BO_FLAG_MEM_LOCAL |
+                        DRM_BO_FLAG_CACHED |
+                        DRM_BO_FLAG_CACHED_MAPPED);
+
+   return intel_region_alloc_internal(intel, cpp, pitch, height, 0, buffer);
+}
+
+struct intel_region *
+intel_region_alloc_for_handle(struct intel_context *intel,
+                             GLuint cpp, GLuint pitch, GLuint height,
+                             GLuint tiled, GLuint handle)
+{
+   dri_bo *buffer;
+
+   buffer = intel_gem_bo_create_from_handle(intel->bufmgr, "region", handle);
+
+   return intel_region_alloc_internal(intel,
+                                     cpp, pitch, height, tiled, buffer);
+}
+
 void
 intel_region_reference(struct intel_region **dst, struct intel_region *src)
 {
@@ -130,7 +163,7 @@ intel_region_release(struct intel_region **region)
 /*
  * XXX Move this into core Mesa?
  */
-static void
+void
 _mesa_copy_rect(GLubyte * dst,
                 GLuint cpp,
                 GLuint dst_pitch,
@@ -322,7 +355,10 @@ intel_region_release_pbo(struct intel_context *intel,
 
    region->buffer = dri_bo_alloc(intel->bufmgr, "region",
                                 region->pitch * region->cpp * region->height,
-                                64, DRM_BO_FLAG_MEM_TT);
+                                64,
+                                DRM_BO_FLAG_MEM_LOCAL |
+                                DRM_BO_FLAG_CACHED |
+                                DRM_BO_FLAG_CACHED_MAPPED);
 }
 
 /* Break the COW tie to the pbo.  Both the pbo and the region end up
@@ -394,21 +430,24 @@ intel_recreate_static(struct intel_context *intel,
       region->refcount = 1;
    }
 
-   region->cpp = intelScreen->cpp;
-   region->pitch = region_desc->pitch / intelScreen->cpp;
+   if (intel->ctx.Visual.rgbBits == 24)
+      region->cpp = 4;
+   else
+      region->cpp = intel->ctx.Visual.rgbBits / 8;
+   region->pitch = intelScreen->pitch;
    region->height = intelScreen->height;     /* needed? */
    region->tiled = region_desc->tiled;
 
    if (intel->ttm) {
       assert(region_desc->bo_handle != -1);
-      region->buffer = intel_ttm_bo_create_from_handle(intel->bufmgr,
+      region->buffer = intel_gem_bo_create_from_handle(intel->bufmgr,
                                                       name,
                                                       region_desc->bo_handle);
    } else {
       region->buffer = dri_bo_alloc_static(intel->bufmgr,
                                           name,
                                           region_desc->offset,
-                                          region_desc->pitch *
+                                          intelScreen->pitch *
                                           intelScreen->height,
                                           region_desc->map,
                                           DRM_BO_FLAG_MEM_TT);