Revert "i965/wm: use proper API buffer size for the surfaces."
[mesa.git] / src / mesa / drivers / dri / i965 / intel_buffer_objects.c
index a7242b0ee6402f6542c05ba71a43c6c6c0af2456..7a5b3fca595e3f3db46eb97553d75d37fc015d5f 100644 (file)
@@ -1,5 +1,4 @@
-/**************************************************************************
- *
+/*
  * Copyright 2003 VMware, Inc.
  * All Rights Reserved.
  *
@@ -7,7 +6,7 @@
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
+ * distribute, sublicense, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
  *
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
+ */
 
 /**
  * @file intel_buffer_objects.c
@@ -81,12 +79,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 +88,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,8 +96,8 @@ 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);
@@ -111,13 +105,15 @@ intel_bufferobj_alloc_buffer(struct brw_context *brw,
    /* the buffer might be bound as a uniform buffer, need to update it
     */
    if (intel_obj->Base.UsageHistory & USAGE_UNIFORM_BUFFER)
-      brw->state.dirty.brw |= BRW_NEW_UNIFORM_BUFFER;
+      brw->ctx.NewDriverState |= BRW_NEW_UNIFORM_BUFFER;
+   if (intel_obj->Base.UsageHistory & USAGE_SHADER_STORAGE_BUFFER)
+      brw->ctx.NewDriverState |= BRW_NEW_UNIFORM_BUFFER;
    if (intel_obj->Base.UsageHistory & USAGE_TEXTURE_BUFFER)
-      brw->state.dirty.brw |= BRW_NEW_TEXTURE_BUFFER;
+      brw->ctx.NewDriverState |= BRW_NEW_TEXTURE_BUFFER;
    if (intel_obj->Base.UsageHistory & USAGE_ATOMIC_COUNTER_BUFFER)
-      brw->state.dirty.brw |= BRW_NEW_ATOMIC_BUFFER;
+      brw->ctx.NewDriverState |= BRW_NEW_ATOMIC_BUFFER;
 
-   intel_bufferobj_mark_inactive(intel_obj);
+   mark_buffer_inactive(intel_obj);
 }
 
 static void
@@ -138,7 +134,7 @@ 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)
+brw_new_buffer_object(struct gl_context * ctx, GLuint name)
 {
    struct intel_buffer_object *obj = CALLOC_STRUCT(intel_buffer_object);
    if (!obj) {
@@ -158,7 +154,7 @@ intel_bufferobj_alloc(struct gl_context * ctx, GLuint name)
  * 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);
 
@@ -186,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);
@@ -212,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;
 
@@ -234,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);
@@ -257,9 +254,9 @@ intel_bufferobj_subdata(struct gl_context * ctx,
     * (otherwise, an app that might occasionally stall but mostly not will end
     * up with blitting all the time, at the cost of bandwidth)
     */
-   if (brw->has_llc) {
-      if (offset + size <= intel_obj->gpu_active_start ||
-          intel_obj->gpu_active_end <= offset) {
+   if (offset + size <= intel_obj->gpu_active_start ||
+       intel_obj->gpu_active_end <= offset) {
+      if (brw->has_llc) {
          drm_intel_gem_bo_map_unsynchronized(intel_obj->buffer);
          memcpy(intel_obj->buffer->virtual + offset, data, size);
          drm_intel_bo_unmap(intel_obj->buffer);
@@ -267,6 +264,8 @@ intel_bufferobj_subdata(struct gl_context * ctx,
          if (intel_obj->gpu_active_end > intel_obj->gpu_active_start)
             intel_obj->prefer_stall_to_blit = true;
          return;
+      } else {
+         perf_debug("BufferSubData could be unsynchronized, but !LLC doesn't support it yet\n");
       }
    }
 
@@ -278,7 +277,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 "
@@ -310,7 +309,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);
 }
 
 
@@ -321,10 +320,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);
@@ -335,7 +335,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);
 }
 
 
@@ -358,10 +358,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);
@@ -392,7 +392,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");
@@ -401,7 +401,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,16 +439,20 @@ intel_bufferobj_map_range(struct gl_context * ctx,
       return obj->Mappings[index].Pointer;
    }
 
-   if (access & GL_MAP_UNSYNCHRONIZED_BIT)
+   if (access & GL_MAP_UNSYNCHRONIZED_BIT) {
+      if (!brw->has_llc && brw->perf_debug &&
+          drm_intel_bo_busy(intel_obj->buffer)) {
+         perf_debug("MapBufferRange with GL_MAP_UNSYNCHRONIZED_BIT stalling (it's actually synchronized on non-LLC platforms)\n");
+      }
       drm_intel_gem_bo_map_unsynchronized(intel_obj->buffer);
-   else if (!brw->has_llc && (!(access & GL_MAP_READ_BIT) ||
+   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;
@@ -469,10 +473,10 @@ 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);
@@ -517,9 +521,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);
 }
 
 
@@ -529,8 +533,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);
@@ -546,8 +551,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
@@ -555,7 +560,7 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj,
        * flush.  Once again, we wish for a domain tracker in libdrm to cover
        * usage inside of a batchbuffer.
        */
-      intel_batchbuffer_emit_mi_flush(brw);
+      brw_emit_mi_flush(brw);
 
       drm_intel_bo_unreference(intel_obj->range_map_bo[index]);
       intel_obj->range_map_bo[index] = NULL;
@@ -586,9 +591,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;
 }
@@ -601,11 +606,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);
@@ -627,19 +632,19 @@ intel_bufferobj_copy_subdata(struct gl_context *ctx,
     * flush.  Once again, we wish for a domain tracker in libdrm to cover
     * usage inside of a batchbuffer.
     */
-   intel_batchbuffer_emit_mi_flush(brw);
+   brw_emit_mi_flush(brw);
 }
 
 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;
 }