i965/fs: add support for BRW_OPCODE_AVG in fs_generator
[mesa.git] / src / mesa / drivers / dri / i965 / intel_mipmap_tree.h
index 6dab092c8f3e6bcd6c199f194fb2e51332e65ddd..bc63a249d2a53f8a6f03934e35c1a79d0a2e0d8a 100644 (file)
@@ -1,8 +1,8 @@
 /**************************************************************************
- * 
- * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
+ *
+ * Copyright 2006 VMware, Inc.
  * All Rights Reserved.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * distribute, sub license, 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 above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
- * 
+ *
  * 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.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * 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.
- * 
+ *
  **************************************************************************/
 
 #ifndef INTEL_MIPMAP_TREE_H
@@ -32,6 +32,7 @@
 
 #include "intel_regions.h"
 #include "intel_resolve_map.h"
+#include <GL/internal/dri_interface.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -41,7 +42,7 @@ extern "C" {
  *
  * - Code to size and layout a region to hold a set of mipmaps.
  * - Query to determine if a new image fits in an existing tree.
- * - More refcounting 
+ * - More refcounting
  *     - maybe able to remove refcounting from intel_region?
  * - ?
  *
@@ -56,8 +57,8 @@ extern "C" {
  * the texture object would slot into the tree as they arrive.  The
  * reality can be a little messier, as images can arrive from the user
  * with sizes that don't fit in the existing tree, or in an order
- * where the tree layout cannot be guessed immediately.  
- * 
+ * where the tree layout cannot be guessed immediately.
+ *
  * This structure encodes an idealized mipmap tree.  The GL image
  * commands build these where possible, otherwise store the images in
  * temporary system buffers.
@@ -201,10 +202,9 @@ enum intel_msaa_layout
 };
 
 
-#ifndef I915
 /**
- * Enum for keeping track of the state of an MCS buffer associated with a
- * miptree.  This determines when fast clear related operations are needed.
+ * Enum for keeping track of the fast clear state of a buffer associated with
+ * a miptree.
  *
  * Fast clear works by deferring the memory writes that would be used to clear
  * the buffer, so that instead of performing them at the time of the clear
@@ -212,23 +212,18 @@ enum intel_msaa_layout
  * buffer is later accessed for rendering.  The MCS buffer keeps track of
  * which regions of the buffer still have pending clear writes.
  *
- * This enum keeps track of the driver's knowledge of the state of the MCS
- * buffer.
+ * This enum keeps track of the driver's knowledge of pending fast clears in
+ * the MCS buffer.
  *
  * MCS buffers only exist on Gen7+.
  */
-enum intel_mcs_state
+enum intel_fast_clear_state
 {
    /**
     * There is no MCS buffer for this miptree, and one should never be
     * allocated.
     */
-   INTEL_MCS_STATE_NONE,
-
-   /**
-    * An MCS buffer exists for this miptree, and it is used for MSAA purposes.
-    */
-   INTEL_MCS_STATE_MSAA,
+   INTEL_FAST_CLEAR_STATE_NO_MCS,
 
    /**
     * No deferred clears are pending for this miptree, and the contents of the
@@ -239,8 +234,11 @@ enum intel_mcs_state
     *
     * In this state, the color buffer can be used for purposes other than
     * rendering without needing a render target resolve.
+    *
+    * Since there is no such thing as a "fast color clear resolve" for MSAA
+    * buffers, an MSAA buffer will never be in this state.
     */
-   INTEL_MCS_STATE_RESOLVED,
+   INTEL_FAST_CLEAR_STATE_RESOLVED,
 
    /**
     * An MCS buffer exists for this miptree, and deferred clears are pending
@@ -248,25 +246,24 @@ enum intel_mcs_state
     * The contents of the color buffer are only correct for the regions where
     * the MCS buffer doesn't indicate a deferred clear.
     *
-    * In this state, a render target resolve must be performed before the
-    * color buffer can be used for purposes other than rendering.
+    * If a single-sample buffer is in this state, a render target resolve must
+    * be performed before it can be used for purposes other than rendering.
     */
-   INTEL_MCS_STATE_UNRESOLVED,
+   INTEL_FAST_CLEAR_STATE_UNRESOLVED,
 
    /**
     * An MCS buffer exists for this miptree, and deferred clears are pending
     * for the entire color buffer, and the contents of the MCS buffer reflect
     * this.  The contents of the color buffer are undefined.
     *
-    * In this state, a render target resolve must be performed before the
-    * color buffer can be used for purposes other than rendering.
+    * If a single-sample buffer is in this state, a render target resolve must
+    * be performed before it can be used for purposes other than rendering.
     *
     * If the client attempts to clear a buffer which is already in this state,
     * the clear can be safely skipped, since the buffer is already clear.
     */
-   INTEL_MCS_STATE_CLEAR,
+   INTEL_FAST_CLEAR_STATE_CLEAR,
 };
-#endif
 
 struct intel_mipmap_tree
 {
@@ -294,8 +291,8 @@ struct intel_mipmap_tree
    gl_format etc_format;
 
    /**
-    * The X offset of each image in the miptree must be aligned to this. See
-    * the "Alignment Unit Size" section of the BSpec.
+    * The X offset of each image in the miptree must be aligned to this.
+    * See the comments in brw_tex_layout.c.
     */
    unsigned int align_w;
    unsigned int align_h; /**< \see align_w */
@@ -336,6 +333,11 @@ struct intel_mipmap_tree
     */
    bool array_spacing_lod0;
 
+   /**
+    * The distance in rows between array slices.
+    */
+   uint32_t qpitch;
+
    /**
     * MSAA layout used by this buffer.
     */
@@ -441,7 +443,6 @@ struct intel_mipmap_tree
     */
    struct intel_mipmap_tree *stencil_mt;
 
-#ifndef I915
    /**
     * \brief MCS miptree.
     *
@@ -454,10 +455,9 @@ struct intel_mipmap_tree
    struct intel_mipmap_tree *mcs_mt;
 
    /**
-    * MCS state for this buffer.
+    * Fast clear state for this buffer.
     */
-   enum intel_mcs_state mcs_state;
-#endif
+   enum intel_fast_clear_state fast_clear_state;
 
    /**
     * The SURFACE_STATE bits associated with the last fast color clear to this
@@ -480,19 +480,19 @@ enum intel_miptree_tiling_mode {
 };
 
 bool
-intel_is_non_msrt_mcs_buffer_supported(struct intel_context *intel,
+intel_is_non_msrt_mcs_buffer_supported(struct brw_context *brw,
                                        struct intel_mipmap_tree *mt);
 
 void
-intel_get_non_msrt_mcs_alignment(struct intel_context *intel,
+intel_get_non_msrt_mcs_alignment(struct brw_context *brw,
                                  struct intel_mipmap_tree *mt,
                                  unsigned *width_px, unsigned *height);
 
 bool
-intel_miptree_alloc_non_msrt_mcs(struct intel_context *intel,
+intel_miptree_alloc_non_msrt_mcs(struct brw_context *brw,
                                  struct intel_mipmap_tree *mt);
 
-struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
+struct intel_mipmap_tree *intel_miptree_create(struct brw_context *brw,
                                                GLenum target,
                                               gl_format format,
                                                GLuint first_level,
@@ -505,7 +505,7 @@ struct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
                                                enum intel_miptree_tiling_mode);
 
 struct intel_mipmap_tree *
-intel_miptree_create_layout(struct intel_context *intel,
+intel_miptree_create_layout(struct brw_context *brw,
                             GLenum target,
                             gl_format format,
                             GLuint first_level,
@@ -517,7 +517,7 @@ intel_miptree_create_layout(struct intel_context *intel,
                             GLuint num_samples);
 
 struct intel_mipmap_tree *
-intel_miptree_create_for_bo(struct intel_context *intel,
+intel_miptree_create_for_bo(struct brw_context *brw,
                             drm_intel_bo *bo,
                             gl_format format,
                             uint32_t offset,
@@ -527,12 +527,19 @@ intel_miptree_create_for_bo(struct intel_context *intel,
                             uint32_t tiling);
 
 struct intel_mipmap_tree*
-intel_miptree_create_for_dri2_buffer(struct intel_context *intel,
+intel_miptree_create_for_dri2_buffer(struct brw_context *brw,
                                      unsigned dri_attachment,
                                      gl_format format,
                                      uint32_t num_samples,
                                      struct intel_region *region);
 
+struct intel_mipmap_tree*
+intel_miptree_create_for_image_buffer(struct brw_context *intel,
+                                     enum __DRIimageBufferMask buffer_type,
+                                     gl_format format,
+                                     uint32_t num_samples,
+                                     struct intel_region *region);
+
 /**
  * Create a miptree appropriate as the storage for a non-texture renderbuffer.
  * The miptree has the following properties:
@@ -541,7 +548,7 @@ intel_miptree_create_for_dri2_buffer(struct intel_context *intel,
  *     - Depth is 1.
  */
 struct intel_mipmap_tree*
-intel_miptree_create_for_renderbuffer(struct intel_context *intel,
+intel_miptree_create_for_renderbuffer(struct brw_context *brw,
                                       gl_format format,
                                       uint32_t width,
                                       uint32_t height,
@@ -558,11 +565,6 @@ intel_miptree_check_level_layer(struct intel_mipmap_tree *mt,
    assert(layer < mt->level[level].depth);
 }
 
-int intel_miptree_pitch_align (struct intel_context *intel,
-                              struct intel_mipmap_tree *mt,
-                              uint32_t tiling,
-                              int pitch);
-
 void intel_miptree_reference(struct intel_mipmap_tree **dst,
                              struct intel_mipmap_tree *src);
 
@@ -598,36 +600,12 @@ void intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
                                     GLuint img, GLuint x, GLuint y);
 
 void
-intel_miptree_copy_teximage(struct intel_context *intel,
+intel_miptree_copy_teximage(struct brw_context *brw,
                             struct intel_texture_image *intelImage,
                             struct intel_mipmap_tree *dst_mt, bool invalidate);
 
-/**
- * Copy the stencil data from \c mt->stencil_mt->region to \c mt->region for
- * the given miptree slice.
- *
- * \see intel_mipmap_tree::stencil_mt
- */
-void
-intel_miptree_s8z24_scatter(struct intel_context *intel,
-                            struct intel_mipmap_tree *mt,
-                            uint32_t level,
-                            uint32_t slice);
-
-/**
- * Copy the stencil data in \c mt->stencil_mt->region to \c mt->region for the
- * given miptree slice.
- *
- * \see intel_mipmap_tree::stencil_mt
- */
-void
-intel_miptree_s8z24_gather(struct intel_context *intel,
-                           struct intel_mipmap_tree *mt,
-                           uint32_t level,
-                           uint32_t layer);
-
 bool
-intel_miptree_alloc_mcs(struct intel_context *intel,
+intel_miptree_alloc_mcs(struct brw_context *brw,
                         struct intel_mipmap_tree *mt,
                         GLuint num_samples);
 
@@ -646,7 +624,7 @@ intel_miptree_alloc_mcs(struct intel_context *intel,
  */
 
 bool
-intel_miptree_alloc_hiz(struct intel_context *intel,
+intel_miptree_alloc_hiz(struct brw_context *brw,
                        struct intel_mipmap_tree *mt);
 
 bool
@@ -663,11 +641,15 @@ intel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt,
                                             uint32_t level,
                                            uint32_t depth);
 
+void
+intel_miptree_set_all_slices_need_depth_resolve(struct intel_mipmap_tree *mt,
+                                                uint32_t level);
+
 /**
  * \return false if no resolve was needed
  */
 bool
-intel_miptree_slice_resolve_hiz(struct intel_context *intel,
+intel_miptree_slice_resolve_hiz(struct brw_context *brw,
                                struct intel_mipmap_tree *mt,
                                unsigned int level,
                                unsigned int depth);
@@ -676,7 +658,7 @@ intel_miptree_slice_resolve_hiz(struct intel_context *intel,
  * \return false if no resolve was needed
  */
 bool
-intel_miptree_slice_resolve_depth(struct intel_context *intel,
+intel_miptree_slice_resolve_depth(struct brw_context *brw,
                                  struct intel_mipmap_tree *mt,
                                  unsigned int level,
                                  unsigned int depth);
@@ -685,14 +667,14 @@ intel_miptree_slice_resolve_depth(struct intel_context *intel,
  * \return false if no resolve was needed
  */
 bool
-intel_miptree_all_slices_resolve_hiz(struct intel_context *intel,
+intel_miptree_all_slices_resolve_hiz(struct brw_context *brw,
                                     struct intel_mipmap_tree *mt);
 
 /**
  * \return false if no resolve was needed
  */
 bool
-intel_miptree_all_slices_resolve_depth(struct intel_context *intel,
+intel_miptree_all_slices_resolve_depth(struct brw_context *brw,
                                       struct intel_mipmap_tree *mt);
 
 /**\}*/
@@ -704,51 +686,40 @@ intel_miptree_all_slices_resolve_depth(struct intel_context *intel,
 static inline void
 intel_miptree_used_for_rendering(struct intel_mipmap_tree *mt)
 {
-#ifdef I915
-   /* Nothing needs to be done for I915, since it doesn't support fast
-    * clear.
-    */
-#else
    /* If the buffer was previously in fast clear state, change it to
     * unresolved state, since it won't be guaranteed to be clear after
     * rendering occurs.
     */
-   if (mt->mcs_state == INTEL_MCS_STATE_CLEAR)
-      mt->mcs_state = INTEL_MCS_STATE_UNRESOLVED;
-#endif
+   if (mt->fast_clear_state == INTEL_FAST_CLEAR_STATE_CLEAR)
+      mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_UNRESOLVED;
 }
 
 void
-intel_miptree_resolve_color(struct intel_context *intel,
+intel_miptree_resolve_color(struct brw_context *brw,
                             struct intel_mipmap_tree *mt);
 
 void
-intel_miptree_make_shareable(struct intel_context *intel,
+intel_miptree_make_shareable(struct brw_context *brw,
                              struct intel_mipmap_tree *mt);
 
 void
-intel_miptree_downsample(struct intel_context *intel,
+intel_miptree_downsample(struct brw_context *brw,
                          struct intel_mipmap_tree *mt);
 
 void
-intel_miptree_upsample(struct intel_context *intel,
+intel_miptree_upsample(struct brw_context *brw,
                        struct intel_mipmap_tree *mt);
 
-/* i915_mipmap_tree.c:
- */
-void i915_miptree_layout(struct intel_mipmap_tree *mt);
-void i945_miptree_layout(struct intel_mipmap_tree *mt);
-void brw_miptree_layout(struct intel_context *intel,
-                       struct intel_mipmap_tree *mt);
+void brw_miptree_layout(struct brw_context *brw, struct intel_mipmap_tree *mt);
 
-void *intel_miptree_map_raw(struct intel_context *intel,
+void *intel_miptree_map_raw(struct brw_context *brw,
                             struct intel_mipmap_tree *mt);
 
-void intel_miptree_unmap_raw(struct intel_context *intel,
+void intel_miptree_unmap_raw(struct brw_context *brw,
                              struct intel_mipmap_tree *mt);
 
 void
-intel_miptree_map(struct intel_context *intel,
+intel_miptree_map(struct brw_context *brw,
                  struct intel_mipmap_tree *mt,
                  unsigned int level,
                  unsigned int slice,
@@ -761,25 +732,14 @@ intel_miptree_map(struct intel_context *intel,
                  int *out_stride);
 
 void
-intel_miptree_unmap(struct intel_context *intel,
+intel_miptree_unmap(struct brw_context *brw,
                    struct intel_mipmap_tree *mt,
                    unsigned int level,
                    unsigned int slice);
 
-#ifdef I915
-static inline void
-intel_hiz_exec(struct intel_context *intel, struct intel_mipmap_tree *mt,
-              unsigned int level, unsigned int layer, enum gen6_hiz_op op)
-{
-   /* Stub on i915.  It would be nice if we didn't execute resolve code at all
-    * there.
-    */
-}
-#else
 void
-intel_hiz_exec(struct intel_context *intel, struct intel_mipmap_tree *mt,
+intel_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,
               unsigned int level, unsigned int layer, enum gen6_hiz_op op);
-#endif
 
 #ifdef __cplusplus
 }