Revert "i965: Make the miptree clear color setter take a gl_color_union"
[mesa.git] / src / mesa / drivers / dri / i965 / intel_mipmap_tree.h
index 2179318413e7e5e7f419a9741e8f409106c7ccae..2d827afa534ac61fd89757b9bfb6f2b30827c7bd 100644 (file)
@@ -50,6 +50,7 @@
 #include "isl/isl.h"
 #include "blorp/blorp.h"
 #include "brw_bufmgr.h"
+#include "brw_context.h"
 #include <GL/internal/dri_interface.h>
 
 #ifdef __cplusplus
@@ -87,6 +88,12 @@ struct intel_miptree_map {
    void *ptr;
    /** Stride of the mapping. */
    int stride;
+
+   void (*unmap)(struct brw_context *brw,
+                 struct intel_mipmap_tree *mt,
+                 struct intel_miptree_map *map,
+                 unsigned int level,
+                 unsigned int slice);
 };
 
 /**
@@ -155,30 +162,21 @@ struct intel_miptree_aux_buffer
     */
    uint32_t offset;
 
-   /*
-    * Size of the MCS surface.
-    *
-    * This is needed when doing any gtt mapped operations on the buffer (which
-    * will be Y-tiled). It is possible that it will not be the same as bo->size
-    * when the drm allocator rounds up the requested size.
-    */
-   size_t size;
-
    /**
-    * Pitch in bytes.
+    * Buffer object containing the indirect clear color.
     *
-    * @see RENDER_SURFACE_STATE.AuxiliarySurfacePitch
-    * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfacePitch
+    * @see create_ccs_buf_for_image
+    * @see RENDER_SURFACE_STATE.ClearValueAddress
     */
-   uint32_t pitch;
+   struct brw_bo *clear_color_bo;
 
    /**
-    * The distance in rows between array slices.
+    * Offset into bo where the clear color can be found.
     *
-    * @see RENDER_SURFACE_STATE.AuxiliarySurfaceQPitch
-    * @see 3DSTATE_HIER_DEPTH_BUFFER.SurfaceQPitch
+    * @see create_ccs_buf_for_image
+    * @see RENDER_SURFACE_STATE.ClearValueAddress
     */
-   uint32_t qpitch;
+   uint32_t clear_color_offset;
 };
 
 struct intel_mipmap_tree
@@ -255,16 +253,6 @@ struct intel_mipmap_tree
     */
    uint32_t offset;
 
-   /**
-    * \brief HiZ aux buffer
-    *
-    * To allocate the hiz buffer, use intel_miptree_alloc_hiz().
-    *
-    * To determine if hiz is enabled, do not check this pointer. Instead, use
-    * intel_miptree_level_has_hiz().
-    */
-   struct intel_miptree_aux_buffer *hiz_buf;
-
    /**
     * \brief The type of auxiliary compression used by this miptree.
     *
@@ -318,15 +306,29 @@ struct intel_mipmap_tree
    bool r8stencil_needs_update;
 
    /**
-    * \brief MCS auxiliary buffer.
+    * \brief CCS, MCS, or HiZ auxiliary buffer.
+    *
+    * NULL if no auxiliary buffer is in use for this surface.
     *
-    * This buffer contains the "multisample control surface", which stores
-    * the necessary information to implement compressed MSAA
-    * (INTEL_MSAA_FORMAT_CMS) and "fast color clear" behaviour on Gen7+.
+    * For single-sampled color miptrees:
+    *    This buffer contains the Color Control Surface, which stores the
+    *    necessary information to implement lossless color compression (CCS_E)
+    *    and "fast color clear" (CCS_D) behaviour.
     *
-    * NULL if no MCS buffer is in use for this surface.
+    * For multi-sampled color miptrees:
+    *    This buffer contains the Multisample Control Surface, which stores the
+    *    necessary information to implement compressed MSAA
+    *    (INTEL_MSAA_FORMAT_CMS).
+    *
+    * For depth miptrees:
+    *    This buffer contains the Hierarchical Depth Buffer, which stores the
+    *    necessary information to implement lossless depth compression and fast
+    *    depth clear behavior.
+    *
+    *    To determine if HiZ is enabled, do not check this pointer. Instead,
+    *    use intel_miptree_level_has_hiz().
     */
-   struct intel_miptree_aux_buffer *mcs_buf;
+   struct intel_miptree_aux_buffer *aux_buf;
 
    /**
     * Planes 1 and 2 in case this is a planar surface.
@@ -339,28 +341,45 @@ struct intel_mipmap_tree
     */
    union isl_color_value fast_clear_color;
 
+   /**
+    * For external surfaces, this is DRM format modifier that was used to
+    * create or import the surface.  For internal surfaces, this will always
+    * be DRM_FORMAT_MOD_INVALID.
+    */
+   uint64_t drm_modifier;
+
    /* These are also refcounted:
     */
    GLuint refcount;
 };
 
 bool
-intel_miptree_alloc_ccs(struct brw_context *brw,
+intel_miptree_alloc_aux(struct brw_context *brw,
                         struct intel_mipmap_tree *mt);
 
-enum {
-   MIPTREE_LAYOUT_ACCELERATED_UPLOAD       = 1 << 0,
-   MIPTREE_LAYOUT_GEN6_HIZ_STENCIL         = 1 << 1,
-   MIPTREE_LAYOUT_FOR_BO                   = 1 << 2,
-   MIPTREE_LAYOUT_DISABLE_AUX              = 1 << 3,
-   MIPTREE_LAYOUT_FORCE_HALIGN16           = 1 << 4,
+enum intel_miptree_create_flags {
+   /** No miptree create flags */
+   MIPTREE_CREATE_DEFAULT  = 0,
 
-   MIPTREE_LAYOUT_TILING_Y                 = 1 << 5,
-   MIPTREE_LAYOUT_TILING_NONE              = 1 << 6,
-   MIPTREE_LAYOUT_TILING_ANY               = MIPTREE_LAYOUT_TILING_Y |
-                                             MIPTREE_LAYOUT_TILING_NONE,
+   /** Miptree creation should try to allocate a currently busy BO
+    *
+    * This may be advantageous if we know the next thing to touch the BO will
+    * be the GPU because the BO will likely already be in the GTT and maybe
+    * even in some caches.  If there is a chance that the next thing to touch
+    * the miptree BO will be the CPU, this flag should not be set.
+    */
+   MIPTREE_CREATE_BUSY     = 1 << 0,
+
+   /** Create a linear (not tiled) miptree */
+   MIPTREE_CREATE_LINEAR   = 1 << 1,
 
-   MIPTREE_LAYOUT_FOR_SCANOUT              = 1 << 7,
+   /** Create the miptree with auxiliary compression disabled
+    *
+    * This does not prevent the caller of intel_miptree_create from coming
+    * along later and turning auxiliary compression back on but it does mean
+    * that the miptree will be created with mt->aux_usage == NONE.
+    */
+   MIPTREE_CREATE_NO_AUX   = 1 << 2,
 };
 
 struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
@@ -372,7 +391,7 @@ struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
                                                GLuint height0,
                                                GLuint depth0,
                                                GLuint num_samples,
-                                               uint32_t flags);
+                                               enum intel_miptree_create_flags flags);
 
 struct intel_mipmap_tree *
 intel_miptree_create_for_bo(struct brw_context *brw,
@@ -383,13 +402,14 @@ intel_miptree_create_for_bo(struct brw_context *brw,
                             uint32_t height,
                             uint32_t depth,
                             int pitch,
-                            uint32_t layout_flags);
+                            enum isl_tiling tiling,
+                            enum intel_miptree_create_flags flags);
 
 struct intel_mipmap_tree *
 intel_miptree_create_for_dri_image(struct brw_context *brw,
                                    __DRIimage *image,
                                    GLenum target,
-                                   enum isl_colorspace colorspace,
+                                   mesa_format format,
                                    bool is_winsys_image);
 
 bool
@@ -450,10 +470,6 @@ enum isl_dim_layout
 get_isl_dim_layout(const struct gen_device_info *devinfo,
                    enum isl_tiling tiling, GLenum target);
 
-enum isl_aux_usage
-intel_miptree_get_aux_isl_usage(const struct brw_context *brw,
-                                const struct intel_mipmap_tree *mt);
-
 void
 intel_get_image_dims(struct gl_texture_image *image,
                      int *width, int *height, int *depth);
@@ -485,7 +501,7 @@ intel_miptree_copy_slice(struct brw_context *brw,
 void
 intel_miptree_copy_teximage(struct brw_context *brw,
                             struct intel_texture_image *intelImage,
-                            struct intel_mipmap_tree *dst_mt, bool invalidate);
+                            struct intel_mipmap_tree *dst_mt);
 
 /**
  * \name Miptree HiZ functions
@@ -495,15 +511,6 @@ intel_miptree_copy_teximage(struct brw_context *brw,
  * functions on a miptree without HiZ. In that case, each function is a no-op.
  */
 
-/**
- * \brief Allocate the miptree's embedded HiZ miptree.
- * \see intel_mipmap_tree:hiz_mt
- * \return false if allocation failed
- */
-bool
-intel_miptree_alloc_hiz(struct brw_context *brw,
-                       struct intel_mipmap_tree *mt);
-
 bool
 intel_miptree_level_has_hiz(const struct intel_mipmap_tree *mt, uint32_t level);
 
@@ -622,28 +629,28 @@ void
 intel_miptree_prepare_texture(struct brw_context *brw,
                               struct intel_mipmap_tree *mt,
                               enum isl_format view_format,
-                              bool *aux_supported_out);
+                              uint32_t start_level, uint32_t num_levels,
+                              uint32_t start_layer, uint32_t num_layers);
 void
 intel_miptree_prepare_image(struct brw_context *brw,
                             struct intel_mipmap_tree *mt);
-void
-intel_miptree_prepare_fb_fetch(struct brw_context *brw,
-                               struct intel_mipmap_tree *mt, uint32_t level,
-                               uint32_t start_layer, uint32_t num_layers);
+
 enum isl_aux_usage
 intel_miptree_render_aux_usage(struct brw_context *brw,
                                struct intel_mipmap_tree *mt,
-                               bool srgb_enabled, bool blend_enabled);
+                               enum isl_format render_format,
+                               bool blend_enabled,
+                               bool draw_aux_disabled);
 void
 intel_miptree_prepare_render(struct brw_context *brw,
                              struct intel_mipmap_tree *mt, uint32_t level,
                              uint32_t start_layer, uint32_t layer_count,
-                             bool srgb_enabled, bool blend_enabled);
+                             enum isl_aux_usage aux_usage);
 void
 intel_miptree_finish_render(struct brw_context *brw,
                             struct intel_mipmap_tree *mt, uint32_t level,
                             uint32_t start_layer, uint32_t layer_count,
-                            bool srgb_enabled, bool blend_enabled);
+                            enum isl_aux_usage aux_usage);
 void
 intel_miptree_prepare_depth(struct brw_context *brw,
                             struct intel_mipmap_tree *mt, uint32_t level,
@@ -653,6 +660,12 @@ intel_miptree_finish_depth(struct brw_context *brw,
                            struct intel_mipmap_tree *mt, uint32_t level,
                            uint32_t start_layer, uint32_t layer_count,
                            bool depth_written);
+void
+intel_miptree_prepare_external(struct brw_context *brw,
+                               struct intel_mipmap_tree *mt);
+void
+intel_miptree_finish_external(struct brw_context *brw,
+                              struct intel_mipmap_tree *mt);
 
 void
 intel_miptree_make_shareable(struct brw_context *brw,
@@ -667,11 +680,6 @@ void
 intel_update_r8stencil(struct brw_context *brw,
                        struct intel_mipmap_tree *mt);
 
-bool
-brw_miptree_layout(struct brw_context *brw,
-                   struct intel_mipmap_tree *mt,
-                   uint32_t layout_flags);
-
 void
 intel_miptree_map(struct brw_context *brw,
                  struct intel_mipmap_tree *mt,
@@ -695,6 +703,24 @@ bool
 intel_miptree_sample_with_hiz(struct brw_context *brw,
                               struct intel_mipmap_tree *mt);
 
+bool
+intel_miptree_set_clear_color(struct brw_context *brw,
+                              struct intel_mipmap_tree *mt,
+                              union isl_color_value clear_color);
+
+/* Get a clear color suitable for filling out an ISL surface state. */
+union isl_color_value
+intel_miptree_get_clear_color(const struct gen_device_info *devinfo,
+                              const struct intel_mipmap_tree *mt,
+                              enum isl_format view_format, bool sampling,
+                              struct brw_bo **clear_color_bo,
+                              uint32_t *clear_color_offset);
+
+bool
+intel_miptree_set_depth_clear_value(struct brw_context *brw,
+                                    struct intel_mipmap_tree *mt,
+                                    float clear_value);
+
 #ifdef __cplusplus
 }
 #endif