i965/miptree: Allocate mt earlier in update winsys
authorBen Widawsky <ben@bwidawsk.net>
Tue, 30 May 2017 11:53:58 +0000 (17:23 +0530)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 13 Jul 2017 04:15:46 +0000 (21:15 -0700)
Later commits require intel_update_image_buffer() to have control over
the miptree creation.   However, intel_update_winsys_renderbuffer_miptree()
currently  creates it based on the given buffer object. This patch moves
the creation to the caller side.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
Reviewed-by: Chad Versace <chadversary@chromium.org>
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.h

index 9d108fe31d894e39c9386cbf2316cdfde49170c1..c1a429bfcbee5fa85105cfa82264932fb8a4add2 100644 (file)
@@ -1504,10 +1504,26 @@ intel_process_dri2_buffer(struct brw_context *brw,
       return;
    }
 
-   if (!intel_update_winsys_renderbuffer_miptree(brw, rb, bo,
+   struct intel_mipmap_tree *mt =
+      intel_miptree_create_for_bo(brw,
+                                  bo,
+                                  intel_rb_format(rb),
+                                  0,
+                                  drawable->w,
+                                  drawable->h,
+                                  1,
+                                  buffer->pitch,
+                                  MIPTREE_LAYOUT_FOR_SCANOUT);
+   if (!mt) {
+      brw_bo_unreference(bo);
+      return;
+   }
+
+   if (!intel_update_winsys_renderbuffer_miptree(brw, rb, mt,
                                                  drawable->w, drawable->h,
                                                  buffer->pitch)) {
       brw_bo_unreference(bo);
+      intel_miptree_release(&mt);
       return;
    }
 
@@ -1565,10 +1581,25 @@ intel_update_image_buffer(struct brw_context *intel,
    if (last_mt && last_mt->bo == buffer->bo)
       return;
 
-   if (!intel_update_winsys_renderbuffer_miptree(intel, rb, buffer->bo,
+   struct intel_mipmap_tree *mt =
+      intel_miptree_create_for_bo(intel,
+                                  buffer->bo,
+                                  intel_rb_format(rb),
+                                  0,
+                                  buffer->width,
+                                  buffer->height,
+                                  1,
+                                  buffer->pitch,
+                                  MIPTREE_LAYOUT_FOR_SCANOUT);
+   if (!mt)
+      return;
+
+   if (!intel_update_winsys_renderbuffer_miptree(intel, rb, mt,
                                                  buffer->width, buffer->height,
-                                                 buffer->pitch))
+                                                 buffer->pitch)) {
+      intel_miptree_release(&mt);
       return;
+   }
 
    if (_mesa_is_front_buffer_drawing(fb) &&
        buffer_type == __DRI_IMAGE_BUFFER_FRONT &&
index c018c7f6a87254ceaef420f8f8530d864fee91ad..f1ac074fb506d1b87c73860de072265d3a563a76 100644 (file)
@@ -1115,11 +1115,10 @@ intel_miptree_create_for_dri_image(struct brw_context *brw,
 bool
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
                                          struct intel_renderbuffer *irb,
-                                         struct brw_bo *bo,
+                                         struct intel_mipmap_tree *singlesample_mt,
                                          uint32_t width, uint32_t height,
                                          uint32_t pitch)
 {
-   struct intel_mipmap_tree *singlesample_mt = NULL;
    struct intel_mipmap_tree *multisample_mt = NULL;
    struct gl_renderbuffer *rb = &irb->Base.Base;
    mesa_format format = rb->Format;
@@ -1131,17 +1130,7 @@ intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
    assert(_mesa_get_format_base_format(format) == GL_RGB ||
           _mesa_get_format_base_format(format) == GL_RGBA);
 
-   singlesample_mt = intel_miptree_create_for_bo(intel,
-                                                 bo,
-                                                 format,
-                                                 0,
-                                                 width,
-                                                 height,
-                                                 1,
-                                                 pitch,
-                                                 MIPTREE_LAYOUT_FOR_SCANOUT);
-   if (!singlesample_mt)
-      goto fail;
+   assert(singlesample_mt);
 
    if (num_samples == 0) {
       intel_miptree_release(&irb->mt);
@@ -1171,7 +1160,6 @@ intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
    return true;
 
 fail:
-   intel_miptree_release(&irb->singlesample_mt);
    intel_miptree_release(&irb->mt);
    return false;
 }
index c588f255d1b1a47159318ad3d397564895478517..4cc5c3539ff518b6746ebc2dbf88062b1ad6524d 100644 (file)
@@ -694,7 +694,7 @@ intel_miptree_create_for_dri_image(struct brw_context *brw,
 bool
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
                                          struct intel_renderbuffer *irb,
-                                         struct brw_bo *bo,
+                                         struct intel_mipmap_tree *singlesample_mt,
                                          uint32_t width, uint32_t height,
                                          uint32_t pitch);