i915g: Implement surface_buffer_create for softpipe
authorJakob Bornecrantz <jakob@vmware.com>
Tue, 11 Aug 2009 17:37:09 +0000 (18:37 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Tue, 11 Aug 2009 17:37:09 +0000 (18:37 +0100)
In order to run softpipe on st/xorg we need this function

src/gallium/winsys/drm/intel/gem/intel_be_device.c

index 512bd41d648a18a724981b93d8a6c487e3a3ee7e..5312865a039ef9d20b03ffc2ac1baacb9ca94849 100644 (file)
@@ -7,6 +7,7 @@
 #include "pipe/p_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_debug.h"
+#include "util/u_math.h"
 
 #include "intel_be_fence.h"
 
@@ -174,6 +175,40 @@ err:
        return NULL;
 }
 
+static struct pipe_buffer *
+intel_be_surface_buffer_create(struct pipe_winsys *winsys,
+                               unsigned width, unsigned height,
+                               enum pipe_format format,
+                               unsigned usage,
+                               unsigned tex_usage,
+                               unsigned *stride)
+{
+       struct pipe_format_block block;
+       unsigned buf_usage = 0;
+       unsigned buf_stride = 0;
+       unsigned buf_size = 0;
+
+       pf_get_block(format, &block);
+       buf_stride = pf_get_stride(&block, width);
+       buf_stride = align(buf_stride, 64);
+
+       if (tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) {
+               /* TODO more checks */
+               assert(buf_stride <= 2048*4);
+               assert(height % 8 == 0);
+               buf_stride = 2048 * 4;
+               buf_usage |= I915_BUFFER_USAGE_SCANOUT;
+       }
+
+       buf_size = buf_stride * height;
+       *stride = buf_stride;
+
+       return intel_be_buffer_create(winsys,
+                                     0,
+                                     buf_usage,
+                                     buf_size);
+}
+
 boolean
 intel_be_get_texture_buffer(struct drm_api *api,
                             struct pipe_texture *texture,
@@ -257,6 +292,7 @@ intel_be_global_handle_from_buffer(struct drm_api *api,
        *handle = buf->flink;
        return TRUE;
 }
+
 /*
  * Fence
  */
@@ -328,8 +364,8 @@ intel_be_init_device(struct intel_be_device *dev, int fd, unsigned id)
        dev->base.buffer_unmap = intel_be_buffer_unmap;
        dev->base.buffer_destroy = intel_be_buffer_destroy;
 
-       /* Not used anymore */
-       dev->base.surface_buffer_create = NULL;
+       /* Used by softpipe */
+       dev->base.surface_buffer_create = intel_be_surface_buffer_create;
 
        dev->base.fence_reference = intel_be_fence_refunref;
        dev->base.fence_signalled = intel_be_fence_signalled;