i965/vec4: Init mlen for several send from GRF instructions.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_buffer_objects.c
index 82e0744455062e3696ee8a1a1686a94e414b4e40..f2d2bcbe9964861c283510cfb61131b7e2d4c2ef 100644 (file)
@@ -81,12 +81,8 @@ brw_bo_map_gtt(struct brw_context *brw, drm_intel_bo *bo, const char *bo_name)
    return ret;
 }
 
-static GLboolean
-intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj,
-                      gl_map_buffer_index index);
-
 static void
-intel_bufferobj_mark_gpu_usage(struct intel_buffer_object *intel_obj,
+mark_buffer_gpu_usage(struct intel_buffer_object *intel_obj,
                                uint32_t offset, uint32_t size)
 {
    intel_obj->gpu_active_start = MIN2(intel_obj->gpu_active_start, offset);
@@ -94,7 +90,7 @@ intel_bufferobj_mark_gpu_usage(struct intel_buffer_object *intel_obj,
 }
 
 static void
-intel_bufferobj_mark_inactive(struct intel_buffer_object *intel_obj)
+mark_buffer_inactive(struct intel_buffer_object *intel_obj)
 {
    intel_obj->gpu_active_start = ~0;
    intel_obj->gpu_active_end = 0;
@@ -102,17 +98,22 @@ intel_bufferobj_mark_inactive(struct intel_buffer_object *intel_obj)
 
 /** Allocates a new drm_intel_bo to store the data for the buffer object. */
 static void
-intel_bufferobj_alloc_buffer(struct brw_context *brw,
-                            struct intel_buffer_object *intel_obj)
+alloc_buffer_object(struct brw_context *brw,
+                    struct intel_buffer_object *intel_obj)
 {
    intel_obj->buffer = drm_intel_bo_alloc(brw->bufmgr, "bufferobj",
                                          intel_obj->Base.Size, 64);
 
    /* the buffer might be bound as a uniform buffer, need to update it
     */
-   brw->state.dirty.brw |= BRW_NEW_UNIFORM_BUFFER;
-
-   intel_bufferobj_mark_inactive(intel_obj);
+   if (intel_obj->Base.UsageHistory & USAGE_UNIFORM_BUFFER)
+      brw->state.dirty.brw |= BRW_NEW_UNIFORM_BUFFER;
+   if (intel_obj->Base.UsageHistory & USAGE_TEXTURE_BUFFER)
+      brw->state.dirty.brw |= BRW_NEW_TEXTURE_BUFFER;
+   if (intel_obj->Base.UsageHistory & USAGE_ATOMIC_COUNTER_BUFFER)
+      brw->state.dirty.brw |= BRW_NEW_ATOMIC_BUFFER;
+
+   mark_buffer_inactive(intel_obj);
 }
 
 static void
@@ -133,14 +134,14 @@ release_buffer(struct intel_buffer_object *intel_obj)
  * internal structure where somehow shared.
  */
 static struct gl_buffer_object *
-intel_bufferobj_alloc(struct gl_context * ctx, GLuint name, GLenum target)
+brw_new_buffer_object(struct gl_context * ctx, GLuint name)
 {
    struct intel_buffer_object *obj = CALLOC_STRUCT(intel_buffer_object);
    if (!obj) {
       _mesa_error_no_memory(__func__);
    }
 
-   _mesa_initialize_buffer_object(ctx, &obj->Base, name, target);
+   _mesa_initialize_buffer_object(ctx, &obj->Base, name);
 
    obj->buffer = NULL;
 
@@ -153,7 +154,7 @@ intel_bufferobj_alloc(struct gl_context * ctx, GLuint name, GLenum target)
  * Deletes a single OpenGL buffer object.  Used by glDeleteBuffers().
  */
 static void
-intel_bufferobj_free(struct gl_context * ctx, struct gl_buffer_object *obj)
+brw_delete_buffer(struct gl_context * ctx, struct gl_buffer_object *obj)
 {
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
 
@@ -181,13 +182,13 @@ intel_bufferobj_free(struct gl_context * ctx, struct gl_buffer_object *obj)
  * \return true for success, false if out of memory
  */
 static GLboolean
-intel_bufferobj_data(struct gl_context * ctx,
-                     GLenum target,
-                     GLsizeiptrARB size,
-                     const GLvoid * data,
-                     GLenum usage,
-                     GLbitfield storageFlags,
-                     struct gl_buffer_object *obj)
+brw_buffer_data(struct gl_context *ctx,
+                GLenum target,
+                GLsizeiptrARB size,
+                const GLvoid *data,
+                GLenum usage,
+                GLbitfield storageFlags,
+                struct gl_buffer_object *obj)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
@@ -207,7 +208,7 @@ intel_bufferobj_data(struct gl_context * ctx,
       release_buffer(intel_obj);
 
    if (size != 0) {
-      intel_bufferobj_alloc_buffer(brw, intel_obj);
+      alloc_buffer_object(brw, intel_obj);
       if (!intel_obj->buffer)
          return false;
 
@@ -229,10 +230,11 @@ intel_bufferobj_data(struct gl_context * ctx,
  * the buffer or if data is NULL, no copy is performed.
  */
 static void
-intel_bufferobj_subdata(struct gl_context * ctx,
-                        GLintptrARB offset,
-                        GLsizeiptrARB size,
-                        const GLvoid * data, struct gl_buffer_object *obj)
+brw_buffer_subdata(struct gl_context *ctx,
+                   GLintptrARB offset,
+                   GLsizeiptrARB size,
+                   const GLvoid *data,
+                   struct gl_buffer_object *obj)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
@@ -273,7 +275,7 @@ intel_bufferobj_subdata(struct gl_context * ctx,
       if (size == intel_obj->Base.Size) {
         /* Replace the current busy bo so the subdata doesn't stall. */
         drm_intel_bo_unreference(intel_obj->buffer);
-        intel_bufferobj_alloc_buffer(brw, intel_obj);
+        alloc_buffer_object(brw, intel_obj);
       } else if (!intel_obj->prefer_stall_to_blit) {
          perf_debug("Using a blit copy to avoid stalling on "
                     "glBufferSubData(%ld, %ld) (%ldkb) to a busy "
@@ -305,7 +307,7 @@ intel_bufferobj_subdata(struct gl_context * ctx,
    }
 
    drm_intel_bo_subdata(intel_obj->buffer, offset, size, data);
-   intel_bufferobj_mark_inactive(intel_obj);
+   mark_buffer_inactive(intel_obj);
 }
 
 
@@ -316,10 +318,11 @@ intel_bufferobj_subdata(struct gl_context * ctx,
  * object into user memory.
  */
 static void
-intel_bufferobj_get_subdata(struct gl_context * ctx,
-                            GLintptrARB offset,
-                            GLsizeiptrARB size,
-                            GLvoid * data, struct gl_buffer_object *obj)
+brw_get_buffer_subdata(struct gl_context *ctx,
+                       GLintptrARB offset,
+                       GLsizeiptrARB size,
+                       GLvoid *data,
+                       struct gl_buffer_object *obj)
 {
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
    struct brw_context *brw = brw_context(ctx);
@@ -330,7 +333,7 @@ intel_bufferobj_get_subdata(struct gl_context * ctx,
    }
    drm_intel_bo_get_subdata(intel_obj->buffer, offset, size, data);
 
-   intel_bufferobj_mark_inactive(intel_obj);
+   mark_buffer_inactive(intel_obj);
 }
 
 
@@ -353,10 +356,10 @@ intel_bufferobj_get_subdata(struct gl_context * ctx,
  * and blit it into the real BO at unmap time.
  */
 static void *
-intel_bufferobj_map_range(struct gl_context * ctx,
-                         GLintptr offset, GLsizeiptr length,
-                         GLbitfield access, struct gl_buffer_object *obj,
-                          gl_map_buffer_index index)
+brw_map_buffer_range(struct gl_context *ctx,
+                     GLintptr offset, GLsizeiptr length,
+                     GLbitfield access, struct gl_buffer_object *obj,
+                     gl_map_buffer_index index)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
@@ -387,7 +390,7 @@ intel_bufferobj_map_range(struct gl_context * ctx,
       if (drm_intel_bo_references(brw->batch.bo, intel_obj->buffer)) {
         if (access & GL_MAP_INVALIDATE_BUFFER_BIT) {
            drm_intel_bo_unreference(intel_obj->buffer);
-           intel_bufferobj_alloc_buffer(brw, intel_obj);
+           alloc_buffer_object(brw, intel_obj);
         } else {
             perf_debug("Stalling on the GPU for mapping a busy buffer "
                        "object\n");
@@ -396,7 +399,7 @@ intel_bufferobj_map_range(struct gl_context * ctx,
       } else if (drm_intel_bo_busy(intel_obj->buffer) &&
                 (access & GL_MAP_INVALIDATE_BUFFER_BIT)) {
         drm_intel_bo_unreference(intel_obj->buffer);
-        intel_bufferobj_alloc_buffer(brw, intel_obj);
+        alloc_buffer_object(brw, intel_obj);
       }
    }
 
@@ -439,11 +442,11 @@ intel_bufferobj_map_range(struct gl_context * ctx,
    else if (!brw->has_llc && (!(access & GL_MAP_READ_BIT) ||
                               (access & GL_MAP_PERSISTENT_BIT))) {
       drm_intel_gem_bo_map_gtt(intel_obj->buffer);
-      intel_bufferobj_mark_inactive(intel_obj);
+      mark_buffer_inactive(intel_obj);
    } else {
       brw_bo_map(brw, intel_obj->buffer, (access & GL_MAP_WRITE_BIT) != 0,
                  "MapBufferRange");
-      intel_bufferobj_mark_inactive(intel_obj);
+      mark_buffer_inactive(intel_obj);
    }
 
    obj->Mappings[index].Pointer = intel_obj->buffer->virtual + offset;
@@ -464,16 +467,15 @@ intel_bufferobj_map_range(struct gl_context * ctx,
  * would defeat the point.
  */
 static void
-intel_bufferobj_flush_mapped_range(struct gl_context *ctx,
-                                  GLintptr offset, GLsizeiptr length,
-                                  struct gl_buffer_object *obj,
-                                   gl_map_buffer_index index)
+brw_flush_mapped_buffer_range(struct gl_context *ctx,
+                              GLintptr offset, GLsizeiptr length,
+                              struct gl_buffer_object *obj,
+                              gl_map_buffer_index index)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
-   GLbitfield access = obj->Mappings[index].AccessFlags;
 
-   assert(access & GL_MAP_FLUSH_EXPLICIT_BIT);
+   assert(obj->Mappings[index].AccessFlags & GL_MAP_FLUSH_EXPLICIT_BIT);
 
    /* If we gave a direct mapping of the buffer instead of using a temporary,
     * then there's nothing to do.
@@ -513,9 +515,9 @@ intel_bufferobj_flush_mapped_range(struct gl_context *ctx,
                          intel_obj->range_map_bo[index],
                           intel_obj->map_extra[index] + offset,
                          length);
-   intel_bufferobj_mark_gpu_usage(intel_obj,
-                                  obj->Mappings[index].Offset + offset,
-                                  length);
+   mark_buffer_gpu_usage(intel_obj,
+                         obj->Mappings[index].Offset + offset,
+                         length);
 }
 
 
@@ -525,8 +527,9 @@ intel_bufferobj_flush_mapped_range(struct gl_context *ctx,
  * Implements glUnmapBuffer().
  */
 static GLboolean
-intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj,
-                      gl_map_buffer_index index)
+brw_unmap_buffer(struct gl_context *ctx,
+                 struct gl_buffer_object *obj,
+                 gl_map_buffer_index index)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
@@ -542,8 +545,8 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj,
                                 intel_obj->range_map_bo[index],
                                 intel_obj->map_extra[index],
                                 obj->Mappings[index].Length);
-         intel_bufferobj_mark_gpu_usage(intel_obj, obj->Mappings[index].Offset,
-                                        obj->Mappings[index].Length);
+         mark_buffer_gpu_usage(intel_obj, obj->Mappings[index].Offset,
+                               obj->Mappings[index].Length);
       }
 
       /* Since we've emitted some blits to buffers that will (likely) be used
@@ -582,9 +585,9 @@ intel_bufferobj_buffer(struct brw_context *brw,
     * draw-time validation can just always get a BO from a GL buffer object.
     */
    if (intel_obj->buffer == NULL)
-      intel_bufferobj_alloc_buffer(brw, intel_obj);
+      alloc_buffer_object(brw, intel_obj);
 
-   intel_bufferobj_mark_gpu_usage(intel_obj, offset, size);
+   mark_buffer_gpu_usage(intel_obj, offset, size);
 
    return intel_obj->buffer;
 }
@@ -597,11 +600,11 @@ intel_bufferobj_buffer(struct brw_context *brw,
  * are allowed.
  */
 static void
-intel_bufferobj_copy_subdata(struct gl_context *ctx,
-                            struct gl_buffer_object *src,
-                            struct gl_buffer_object *dst,
-                            GLintptr read_offset, GLintptr write_offset,
-                            GLsizeiptr size)
+brw_copy_buffer_subdata(struct gl_context *ctx,
+                        struct gl_buffer_object *src,
+                        struct gl_buffer_object *dst,
+                        GLintptr read_offset, GLintptr write_offset,
+                        GLsizeiptr size)
 {
    struct brw_context *brw = brw_context(ctx);
    struct intel_buffer_object *intel_src = intel_buffer_object(src);
@@ -629,13 +632,13 @@ intel_bufferobj_copy_subdata(struct gl_context *ctx,
 void
 intelInitBufferObjectFuncs(struct dd_function_table *functions)
 {
-   functions->NewBufferObject = intel_bufferobj_alloc;
-   functions->DeleteBuffer = intel_bufferobj_free;
-   functions->BufferData = intel_bufferobj_data;
-   functions->BufferSubData = intel_bufferobj_subdata;
-   functions->GetBufferSubData = intel_bufferobj_get_subdata;
-   functions->MapBufferRange = intel_bufferobj_map_range;
-   functions->FlushMappedBufferRange = intel_bufferobj_flush_mapped_range;
-   functions->UnmapBuffer = intel_bufferobj_unmap;
-   functions->CopyBufferSubData = intel_bufferobj_copy_subdata;
+   functions->NewBufferObject = brw_new_buffer_object;
+   functions->DeleteBuffer = brw_delete_buffer;
+   functions->BufferData = brw_buffer_data;
+   functions->BufferSubData = brw_buffer_subdata;
+   functions->GetBufferSubData = brw_get_buffer_subdata;
+   functions->MapBufferRange = brw_map_buffer_range;
+   functions->FlushMappedBufferRange = brw_flush_mapped_buffer_range;
+   functions->UnmapBuffer = brw_unmap_buffer;
+   functions->CopyBufferSubData = brw_copy_buffer_subdata;
 }