summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2009-08-27 16:53:50 -0700
committerEric Anholt <eric@anholt.net>2009-08-27 17:51:29 -0700
commit60b072d49fd2a1b2bf59442ae7209379152b1500 (patch)
treef7e99174dcbdb283d57c15223aa4aed971033128
parent812ccacabcc6af300cf476d7f82ecb75d4982cd6 (diff)
intel: Add support for ARB_copy_buffer.
Passes glean's bufferObject test for this extension.
-rw-r--r--src/mesa/drivers/dri/intel/intel_buffer_objects.c93
-rw-r--r--src/mesa/drivers/dri/intel/intel_extensions.c2
2 files changed, 93 insertions, 2 deletions
diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index 9600557f2cc..a7403979439 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -30,2 +30,3 @@
#include "main/mtypes.h"
+#include "main/macros.h"
#include "main/bufferobj.h"
@@ -33,2 +34,3 @@
#include "intel_context.h"
+#include "intel_blit.h"
#include "intel_buffer_objects.h"
@@ -245,4 +247,6 @@ intel_bufferobj_map(GLcontext * ctx,
- if (!read_only)
- intelFlush(ctx);
+ /* Flush any existing batchbuffer that might have written to this
+ * buffer.
+ */
+ intelFlush(ctx);
@@ -327,2 +331,86 @@ intel_bufferobj_buffer(struct intel_context *intel,
+static void
+intel_bufferobj_copy_subdata(GLcontext *ctx,
+ struct gl_buffer_object *src,
+ struct gl_buffer_object *dst,
+ GLintptr read_offset, GLintptr write_offset,
+ GLsizeiptr size)
+{
+ struct intel_context *intel = intel_context(ctx);
+ struct intel_buffer_object *intel_src = intel_buffer_object(src);
+ struct intel_buffer_object *intel_dst = intel_buffer_object(dst);
+ drm_intel_bo *src_bo, *dst_bo;
+ GLuint pitch, height;
+
+ if (size == 0)
+ return;
+
+ /* If we're in system memory, just map and memcpy. */
+ if (intel_src->sys_buffer || intel_dst->sys_buffer) {
+ /* The same buffer may be used, but note that regions copied may
+ * not overlap.
+ */
+ if (src == dst) {
+ char *ptr = intel_bufferobj_map(ctx, GL_COPY_WRITE_BUFFER,
+ GL_READ_WRITE, dst);
+ memcpy(ptr + write_offset, ptr + read_offset, size);
+ intel_bufferobj_unmap(ctx, GL_COPY_WRITE_BUFFER, dst);
+ } else {
+ const char *src_ptr;
+ char *dst_ptr;
+
+ src_ptr = intel_bufferobj_map(ctx, GL_COPY_READ_BUFFER,
+ GL_READ_ONLY, src);
+ dst_ptr = intel_bufferobj_map(ctx, GL_COPY_WRITE_BUFFER,
+ GL_WRITE_ONLY, dst);
+
+ memcpy(dst_ptr + write_offset, src_ptr + read_offset, size);
+
+ intel_bufferobj_unmap(ctx, GL_COPY_READ_BUFFER, src);
+ intel_bufferobj_unmap(ctx, GL_COPY_WRITE_BUFFER, dst);
+ }
+ }
+
+ /* Otherwise, we have real BOs, so blit them. We don't have a memmove-type
+ * blit like some other hardware, so we'll do a rectangular blit covering
+ * a large space, then emit a scanline blit at the end to cover the last
+ * if we need.
+ */
+
+ dst_bo = intel_bufferobj_buffer(intel, intel_dst, INTEL_WRITE_PART);
+ src_bo = intel_bufferobj_buffer(intel, intel_src, INTEL_READ);
+
+ /* The pitch is a signed value. */
+ pitch = MIN2(size, (1 << 15) - 1);
+ height = size / pitch;
+ intelEmitCopyBlit(intel, 1,
+ pitch, src_bo, read_offset, I915_TILING_NONE,
+ pitch, dst_bo, write_offset, I915_TILING_NONE,
+ 0, 0, /* src x/y */
+ 0, 0, /* dst x/y */
+ pitch, height, /* w, h */
+ GL_COPY);
+
+ read_offset += pitch * height;
+ write_offset += pitch * height;
+ size -= pitch * height;
+ assert (size < (1 << 15));
+ if (size != 0) {
+ intelEmitCopyBlit(intel, 1,
+ size, src_bo, read_offset, I915_TILING_NONE,
+ size, dst_bo, write_offset, I915_TILING_NONE,
+ 0, 0, /* src x/y */
+ 0, 0, /* dst x/y */
+ size, 1, /* w, h */
+ GL_COPY);
+ }
+
+ /* Since we've emitted some blits to buffers that will (likely) be used
+ * in rendering operations in other cache domains in this batch, emit a
+ * flush. Once again, we wish for a domain tracker in libdrm to cover
+ * usage inside of a batchbuffer.
+ */
+ intel_batchbuffer_emit_mi_flush(intel->batch);
+}
+
void
@@ -337,2 +425,3 @@ intelInitBufferObjectFuncs(struct dd_function_table *functions)
functions->UnmapBuffer = intel_bufferobj_unmap;
+ functions->CopyBufferSubData = intel_bufferobj_copy_subdata;
}
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 9f90ef0a697..ff9ad5acced 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -32,2 +32,3 @@
+#define need_GL_ARB_copy_buffer
#define need_GL_ARB_framebuffer_object
@@ -71,2 +72,3 @@
static const struct dri_extension card_extensions[] = {
+ { "GL_ARB_copy_buffer", GL_ARB_copy_buffer_functions },
{ "GL_ARB_half_float_pixel", NULL },