i965/fs: Add support for translating ir_triop_fma into MAD.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_buffer_objects.c
index 0b4782b894d1fd7d28d7c192d5728ae3888551aa..663cc29898498f448c9db404f5e3ebb847d19811 100644 (file)
  * 
  **************************************************************************/
 
+/**
+ * @file intel_buffer_objects.c
+ *
+ * This provides core GL buffer object functionality.
+ */
 
 #include "main/imports.h"
 #include "main/mtypes.h"
 #include "intel_blit.h"
 #include "intel_buffer_objects.h"
 #include "intel_batchbuffer.h"
-#include "intel_fbo.h"
-#include "intel_mipmap_tree.h"
-#include "intel_regions.h"
-
-#include "brw_context.h"
 
 static GLboolean
 intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj);
@@ -66,6 +66,10 @@ release_buffer(struct intel_buffer_object *intel_obj)
 }
 
 /**
+ * The NewBufferObject() driver hook.
+ *
+ * Allocates a new intel_buffer_object structure and initializes it.
+ *
  * There is some duplication between mesa's bufferobjects and our
  * bufmgr buffers.  Both have an integer handle and a hashtable to
  * lookup an opaque structure.  It would be nice if the handles and
@@ -84,8 +88,9 @@ intel_bufferobj_alloc(struct gl_context * ctx, GLuint name, GLenum target)
 }
 
 /**
- * Deallocate/free a vertex/pixel buffer object.
- * Called via glDeleteBuffersARB().
+ * The DeleteBuffer() driver hook.
+ *
+ * Deletes a single OpenGL buffer object.  Used by glDeleteBuffers().
  */
 static void
 intel_bufferobj_free(struct gl_context * ctx, struct gl_buffer_object *obj)
@@ -106,12 +111,14 @@ intel_bufferobj_free(struct gl_context * ctx, struct gl_buffer_object *obj)
 }
 
 
-
 /**
- * Allocate space for and store data in a buffer object.  Any data that was
- * previously stored in the buffer object is lost.  If data is NULL,
- * memory will be allocated, but no copy will occur.
- * Called via ctx->Driver.BufferData().
+ * The BufferData() driver hook.
+ *
+ * Implements glBufferData(), which recreates a buffer object's data store
+ * and populates it with the given data, if present.
+ *
+ * Any data that was previously stored in the buffer object is lost.
+ *
  * \return true for success, false if out of memory
  */
 static GLboolean
@@ -150,10 +157,13 @@ intel_bufferobj_data(struct gl_context * ctx,
 
 
 /**
- * Replace data in a subrange of buffer object.  If the data range
- * specified by size + offset extends beyond the end of the buffer or
- * if data is NULL, no copy is performed.
- * Called via glBufferSubDataARB().
+ * The BufferSubData() driver hook.
+ *
+ * Implements glBufferSubData(), which replaces a portion of the data in a
+ * buffer object.
+ *
+ * If the data range specified by (size + offset) extends beyond the end of
+ * the buffer or if data is NULL, no copy is performed.
  */
 static void
 intel_bufferobj_subdata(struct gl_context * ctx,
@@ -203,7 +213,10 @@ intel_bufferobj_subdata(struct gl_context * ctx,
 
 
 /**
- * Called via glGetBufferSubDataARB().
+ * The GetBufferSubData() driver hook.
+ *
+ * Implements glGetBufferSubData(), which copies a subrange of a buffer
+ * object into user memory.
  */
 static void
 intel_bufferobj_get_subdata(struct gl_context * ctx,
@@ -222,9 +235,10 @@ intel_bufferobj_get_subdata(struct gl_context * ctx,
 }
 
 
-
 /**
- * Called via glMapBufferRange and glMapBuffer
+ * The MapBufferRange() driver hook.
+ *
+ * This implements both glMapBufferRange() and glMapBuffer().
  *
  * The goal of this extension is to allow apps to accumulate their rendering
  * at the same time as they accumulate their buffer object.  Without it,
@@ -323,7 +337,15 @@ intel_bufferobj_map_range(struct gl_context * ctx,
    return obj->Pointer;
 }
 
-/* Ideally we'd use a BO to avoid taking up cache space for the temporary
+/**
+ * The FlushMappedBufferRange() driver hook.
+ *
+ * Implements glFlushMappedBufferRange(), which signifies that modifications
+ * have been made to a range of a mapped buffer, and it should be flushed.
+ *
+ * This is only used for buffers mapped with GL_MAP_FLUSH_EXPLICIT_BIT.
+ *
+ * Ideally we'd use a BO to avoid taking up cache space for the temporary
  * data, but FlushMappedBufferRange may be followed by further writes to
  * the pointer, so we would have to re-map after emitting our blit, which
  * would defeat the point.
@@ -360,7 +382,9 @@ intel_bufferobj_flush_mapped_range(struct gl_context *ctx,
 
 
 /**
- * Called via glUnmapBuffer().
+ * The UnmapBuffer() driver hook.
+ *
+ * Implements glUnmapBuffer().
  */
 static GLboolean
 intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
@@ -417,139 +441,6 @@ intel_bufferobj_buffer(struct brw_context *brw,
    return intel_obj->buffer;
 }
 
-#define INTEL_UPLOAD_SIZE (64*1024)
-
-void
-intel_upload_finish(struct brw_context *brw)
-{
-   if (!brw->upload.bo)
-          return;
-
-   if (brw->upload.buffer_len) {
-          drm_intel_bo_subdata(brw->upload.bo,
-                               brw->upload.buffer_offset,
-                               brw->upload.buffer_len,
-                               brw->upload.buffer);
-          brw->upload.buffer_len = 0;
-   }
-
-   drm_intel_bo_unreference(brw->upload.bo);
-   brw->upload.bo = NULL;
-}
-
-static void wrap_buffers(struct brw_context *brw, GLuint size)
-{
-   intel_upload_finish(brw);
-
-   if (size < INTEL_UPLOAD_SIZE)
-      size = INTEL_UPLOAD_SIZE;
-
-   brw->upload.bo = drm_intel_bo_alloc(brw->bufmgr, "upload", size, 0);
-   brw->upload.offset = 0;
-}
-
-void intel_upload_data(struct brw_context *brw,
-                      const void *ptr, GLuint size, GLuint align,
-                      drm_intel_bo **return_bo,
-                      GLuint *return_offset)
-{
-   GLuint base, delta;
-
-   base = (brw->upload.offset + align - 1) / align * align;
-   if (brw->upload.bo == NULL || base + size > brw->upload.bo->size) {
-      wrap_buffers(brw, size);
-      base = 0;
-   }
-
-   drm_intel_bo_reference(brw->upload.bo);
-   *return_bo = brw->upload.bo;
-   *return_offset = base;
-
-   delta = base - brw->upload.offset;
-   if (brw->upload.buffer_len &&
-       brw->upload.buffer_len + delta + size > sizeof(brw->upload.buffer))
-   {
-      drm_intel_bo_subdata(brw->upload.bo,
-                          brw->upload.buffer_offset,
-                          brw->upload.buffer_len,
-                          brw->upload.buffer);
-      brw->upload.buffer_len = 0;
-   }
-
-   if (size < sizeof(brw->upload.buffer))
-   {
-      if (brw->upload.buffer_len == 0)
-        brw->upload.buffer_offset = base;
-      else
-        brw->upload.buffer_len += delta;
-
-      memcpy(brw->upload.buffer + brw->upload.buffer_len, ptr, size);
-      brw->upload.buffer_len += size;
-   }
-   else
-   {
-      drm_intel_bo_subdata(brw->upload.bo, base, size, ptr);
-   }
-
-   brw->upload.offset = base + size;
-}
-
-void *intel_upload_map(struct brw_context *brw, GLuint size, GLuint align)
-{
-   GLuint base, delta;
-   char *ptr;
-
-   base = (brw->upload.offset + align - 1) / align * align;
-   if (brw->upload.bo == NULL || base + size > brw->upload.bo->size) {
-      wrap_buffers(brw, size);
-      base = 0;
-   }
-
-   delta = base - brw->upload.offset;
-   if (brw->upload.buffer_len &&
-       brw->upload.buffer_len + delta + size > sizeof(brw->upload.buffer))
-   {
-      drm_intel_bo_subdata(brw->upload.bo,
-                          brw->upload.buffer_offset,
-                          brw->upload.buffer_len,
-                          brw->upload.buffer);
-      brw->upload.buffer_len = 0;
-   }
-
-   if (size <= sizeof(brw->upload.buffer)) {
-      if (brw->upload.buffer_len == 0)
-        brw->upload.buffer_offset = base;
-      else
-        brw->upload.buffer_len += delta;
-
-      ptr = brw->upload.buffer + brw->upload.buffer_len;
-      brw->upload.buffer_len += size;
-   } else
-      ptr = malloc(size);
-
-   return ptr;
-}
-
-void intel_upload_unmap(struct brw_context *brw,
-                       const void *ptr, GLuint size, GLuint align,
-                       drm_intel_bo **return_bo,
-                       GLuint *return_offset)
-{
-   GLuint base;
-
-   base = (brw->upload.offset + align - 1) / align * align;
-   if (size > sizeof(brw->upload.buffer)) {
-      drm_intel_bo_subdata(brw->upload.bo, base, size, ptr);
-      free((void*)ptr);
-   }
-
-   drm_intel_bo_reference(brw->upload.bo);
-   *return_bo = brw->upload.bo;
-   *return_offset = base;
-
-   brw->upload.offset = base + size;
-}
-
 drm_intel_bo *
 intel_bufferobj_source(struct brw_context *brw,
                        struct intel_buffer_object *intel_obj,
@@ -559,6 +450,13 @@ intel_bufferobj_source(struct brw_context *brw,
    return intel_obj->buffer;
 }
 
+/**
+ * The CopyBufferSubData() driver hook.
+ *
+ * Implements glCopyBufferSubData(), which copies a portion of one buffer
+ * object's data to another.  Independent source and destination offsets
+ * are allowed.
+ */
 static void
 intel_bufferobj_copy_subdata(struct gl_context *ctx,
                             struct gl_buffer_object *src,
@@ -590,129 +488,6 @@ intel_bufferobj_copy_subdata(struct gl_context *ctx,
    intel_batchbuffer_emit_mi_flush(brw);
 }
 
-static GLenum
-intel_buffer_purgeable(drm_intel_bo *buffer)
-{
-   int retained = 0;
-
-   if (buffer != NULL)
-      retained = drm_intel_bo_madvise (buffer, I915_MADV_DONTNEED);
-
-   return retained ? GL_VOLATILE_APPLE : GL_RELEASED_APPLE;
-}
-
-static GLenum
-intel_buffer_object_purgeable(struct gl_context * ctx,
-                              struct gl_buffer_object *obj,
-                              GLenum option)
-{
-   struct intel_buffer_object *intel_obj = intel_buffer_object (obj);
-
-   if (intel_obj->buffer != NULL)
-      return intel_buffer_purgeable(intel_obj->buffer);
-
-   if (option == GL_RELEASED_APPLE) {
-      return GL_RELEASED_APPLE;
-   } else {
-      /* XXX Create the buffer and madvise(MADV_DONTNEED)? */
-      struct brw_context *brw = brw_context(ctx);
-      drm_intel_bo *bo = intel_bufferobj_buffer(brw, intel_obj, INTEL_READ);
-
-      return intel_buffer_purgeable(bo);
-   }
-}
-
-static GLenum
-intel_texture_object_purgeable(struct gl_context * ctx,
-                               struct gl_texture_object *obj,
-                               GLenum option)
-{
-   struct intel_texture_object *intel;
-
-   (void) ctx;
-   (void) option;
-
-   intel = intel_texture_object(obj);
-   if (intel->mt == NULL || intel->mt->region == NULL)
-      return GL_RELEASED_APPLE;
-
-   return intel_buffer_purgeable(intel->mt->region->bo);
-}
-
-static GLenum
-intel_render_object_purgeable(struct gl_context * ctx,
-                              struct gl_renderbuffer *obj,
-                              GLenum option)
-{
-   struct intel_renderbuffer *intel;
-
-   (void) ctx;
-   (void) option;
-
-   intel = intel_renderbuffer(obj);
-   if (intel->mt == NULL)
-      return GL_RELEASED_APPLE;
-
-   return intel_buffer_purgeable(intel->mt->region->bo);
-}
-
-static GLenum
-intel_buffer_unpurgeable(drm_intel_bo *buffer)
-{
-   int retained;
-
-   retained = 0;
-   if (buffer != NULL)
-      retained = drm_intel_bo_madvise (buffer, I915_MADV_WILLNEED);
-
-   return retained ? GL_RETAINED_APPLE : GL_UNDEFINED_APPLE;
-}
-
-static GLenum
-intel_buffer_object_unpurgeable(struct gl_context * ctx,
-                                struct gl_buffer_object *obj,
-                                GLenum option)
-{
-   (void) ctx;
-   (void) option;
-
-   return intel_buffer_unpurgeable(intel_buffer_object (obj)->buffer);
-}
-
-static GLenum
-intel_texture_object_unpurgeable(struct gl_context * ctx,
-                                 struct gl_texture_object *obj,
-                                 GLenum option)
-{
-   struct intel_texture_object *intel;
-
-   (void) ctx;
-   (void) option;
-
-   intel = intel_texture_object(obj);
-   if (intel->mt == NULL || intel->mt->region == NULL)
-      return GL_UNDEFINED_APPLE;
-
-   return intel_buffer_unpurgeable(intel->mt->region->bo);
-}
-
-static GLenum
-intel_render_object_unpurgeable(struct gl_context * ctx,
-                                struct gl_renderbuffer *obj,
-                                GLenum option)
-{
-   struct intel_renderbuffer *intel;
-
-   (void) ctx;
-   (void) option;
-
-   intel = intel_renderbuffer(obj);
-   if (intel->mt == NULL)
-      return GL_UNDEFINED_APPLE;
-
-   return intel_buffer_unpurgeable(intel->mt->region->bo);
-}
-
 void
 intelInitBufferObjectFuncs(struct dd_function_table *functions)
 {
@@ -725,12 +500,4 @@ intelInitBufferObjectFuncs(struct dd_function_table *functions)
    functions->FlushMappedBufferRange = intel_bufferobj_flush_mapped_range;
    functions->UnmapBuffer = intel_bufferobj_unmap;
    functions->CopyBufferSubData = intel_bufferobj_copy_subdata;
-
-   functions->BufferObjectPurgeable = intel_buffer_object_purgeable;
-   functions->TextureObjectPurgeable = intel_texture_object_purgeable;
-   functions->RenderObjectPurgeable = intel_render_object_purgeable;
-
-   functions->BufferObjectUnpurgeable = intel_buffer_object_unpurgeable;
-   functions->TextureObjectUnpurgeable = intel_texture_object_unpurgeable;
-   functions->RenderObjectUnpurgeable = intel_render_object_unpurgeable;
 }