16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#ifndef INTEL_MIPMAP_TREE_H
296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#define INTEL_MIPMAP_TREE_H
306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3173540690f71280a2bdda51b45203fd4ed43a1760Chad Versace#include <assert.h>
3273540690f71280a2bdda51b45203fd4ed43a1760Chad Versace
336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_regions.h"
34cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace#include "intel_resolve_map.h"
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
36434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#ifdef __cplusplus
37434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berryextern "C" {
38434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#endif
39434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* A layer on top of the intel_regions code which adds:
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Code to size and layout a region to hold a set of mipmaps.
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - Query to determine if a new image fits in an existing tree.
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - More refcounting
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *     - maybe able to remove refcounting from intel_region?
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * - ?
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The fixed mipmap layout of intel hardware where one offset
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * specifies the position of all images in a mipmap hierachy
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * complicates the implementation of GL texture image commands,
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * compared to hardware where each image is specified with an
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * independent offset.
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * In an ideal world, each texture object would be associated with a
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * single bufmgr buffer or 2d intel_region, and all the images within
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the texture object would slot into the tree as they arrive.  The
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * reality can be a little messier, as images can arrive from the user
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * with sizes that don't fit in the existing tree, or in an order
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * where the tree layout cannot be guessed immediately.
606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * This structure encodes an idealized mipmap tree.  The GL image
626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * commands build these where possible, otherwise store the images in
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * temporary system buffers.
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
66cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versacestruct intel_resolve_map;
67b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholtstruct intel_texture_image;
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
69221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholtstruct intel_miptree_map {
70221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   /** Bitfield of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT, GL_MAP_INVALIDATE_BIT */
71221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   GLbitfield mode;
72221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   /** Region of interest for the map. */
73221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   int x, y, w, h;
74221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   /** Possibly malloced temporary buffer for the mapping. */
75221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   void *buffer;
765655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   /** Possible pointer to a BO temporary for the mapping. */
775655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   drm_intel_bo *bo;
78221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   /** Pointer to the start of (map_x, map_y) returned by the mapping. */
79221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   void *ptr;
80221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   /** Stride of the mapping. */
81221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   int stride;
82e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
83e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   /**
84e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * intel_mipmap_tree::singlesample_mt is temporary storage that persists
85e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * only for the duration of the map.
86e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    */
87e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   bool singlesample_mt_is_tmp;
88221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt};
89221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Describes the location of each texture image within a texture region.
926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_mipmap_level
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
952d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   /** Offset to this miptree level, used in computing x_offset. */
962d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   GLuint level_x;
972d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   /** Offset to this miptree level, used in computing y_offset. */
982d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   GLuint level_y;
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint width;
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint height;
101d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace
102d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   /**
103d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    * \brief Number of 2D slices in this miplevel.
104d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *
105d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    * The exact semantics of depth varies according to the texture target:
106d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *    - For GL_TEXTURE_CUBE_MAP, depth is 6.
107d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *    - For GL_TEXTURE_2D_ARRAY, depth is the number of array slices. It is
108d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *      identical for all miplevels in the texture.
109d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *    - For GL_TEXTURE_3D, it is the texture's depth at this miplevel. Its
110d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *      value, like width and height, varies with miplevel.
111d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    *    - For other texture types, depth is 1.
112d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    */
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint depth;
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
115c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   /**
116c2ddde70daece24d1eb7185946032158993a9e4dChad Versace    * \brief List of 2D images in this mipmap level.
117e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt    *
118c2ddde70daece24d1eb7185946032158993a9e4dChad Versace    * This may be a list of cube faces, array slices in 2D array texture, or
119d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace    * layers in a 3D texture. The list's length is \c depth.
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
121c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   struct intel_mipmap_slice {
122c2ddde70daece24d1eb7185946032158993a9e4dChad Versace      /**
123c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * \name Offset to slice
124c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * \{
125c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       *
126c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * Hardware formats are so diverse that that there is no unified way to
127c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * compute the slice offsets, so we store them in this table.
128c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       *
129c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * The (x, y) offset to slice \c s at level \c l relative the miptrees
130c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * base address is
131c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       * \code
132c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       *     x = mt->level[l].slice[s].x_offset
133c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       *     y = mt->level[l].slice[s].y_offset
134c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       */
135c2ddde70daece24d1eb7185946032158993a9e4dChad Versace      GLuint x_offset;
136c2ddde70daece24d1eb7185946032158993a9e4dChad Versace      GLuint y_offset;
137c2ddde70daece24d1eb7185946032158993a9e4dChad Versace      /** \} */
138221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
139221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt      /**
1407a2e40ed283b70e1da8ea762959ca7462b0f2fc3Chad Versace       * Mapping information. Persistent for the duration of
1417a2e40ed283b70e1da8ea762959ca7462b0f2fc3Chad Versace       * intel_miptree_map/unmap on this slice.
142221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt       */
143221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt      struct intel_miptree_map *map;
144c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   } *slice;
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1471bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry/**
1481bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * Enum for keeping track of the different MSAA layouts supported by Gen7.
1491bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry */
1501bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berryenum intel_msaa_layout
1511bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry{
1521bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /**
1531bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * Ordinary surface with no MSAA.
1541bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    */
1551bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   INTEL_MSAA_LAYOUT_NONE,
1561bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry
1571bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /**
1581bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * Interleaved Multisample Surface.  The additional samples are
1591bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * accommodated by scaling up the width and the height of the surface so
1601bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * that all the samples corresponding to a pixel are located at nearby
1611bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * memory locations.
1621bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    */
1631bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   INTEL_MSAA_LAYOUT_IMS,
1641bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry
1651bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /**
1661bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * Uncompressed Multisample Surface.  The surface is stored as a 2D array,
1671bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * with array slice n containing all pixel data for sample n.
1681bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    */
1691bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   INTEL_MSAA_LAYOUT_UMS,
1701bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry
1711bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /**
1721bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * Compressed Multisample Surface.  The surface is stored as in
1731bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * INTEL_MSAA_LAYOUT_UMS, but there is an additional buffer called the MCS
1741bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * (Multisample Control Surface) buffer.  Each pixel in the MCS buffer
1751bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * indicates the mapping from sample number to array slice.  This allows
1761bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * the common case (where all samples constituting a pixel have the same
1771bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * color value) to be stored efficiently by just using a single array
1781bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * slice.
1791bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    */
1801bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   INTEL_MSAA_LAYOUT_CMS,
1811bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry};
1821bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry
1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_mipmap_tree
1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Effectively the key:
1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLenum target;
1885b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt
1895b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt   /**
1905b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * Generally, this is just the same as the gl_texture_image->TexFormat or
1915b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * gl_renderbuffer->Format.
1925b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    *
1935b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * However, for textures and renderbuffers with packed depth/stencil formats
1945b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * on hardware where we want or need to use separate stencil, there will be
1955b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * two miptrees for storing the data.  If the depthstencil texture or rb is
1965b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * MESA_FORMAT_Z32_FLOAT_X24S8, then mt->format will be
1975b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * MESA_FORMAT_Z32_FLOAT, otherwise for MESA_FORMAT_S8_Z24 objects it will be
198fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt    * MESA_FORMAT_X8_Z24.
199a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    *
200a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    * For ETC1 textures, this is MESA_FORMAT_RGBX8888_REV if the hardware
201a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    * lacks support for ETC1. See @ref wraps_etc1.
2025b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    */
203d5809115b568d8b74f47316607dce0730964517aEric Anholt   gl_format format;
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
205017c13d55b5b086774d6afea2ca754482c624c6aChad Versace   /**
206017c13d55b5b086774d6afea2ca754482c624c6aChad Versace    * The X offset of each image in the miptree must be aligned to this. See
207017c13d55b5b086774d6afea2ca754482c624c6aChad Versace    * the "Alignment Unit Size" section of the BSpec.
208017c13d55b5b086774d6afea2ca754482c624c6aChad Versace    */
209017c13d55b5b086774d6afea2ca754482c624c6aChad Versace   unsigned int align_w;
210017c13d55b5b086774d6afea2ca754482c624c6aChad Versace   unsigned int align_h; /**< \see align_w */
211017c13d55b5b086774d6afea2ca754482c624c6aChad Versace
2125b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt   GLuint first_level;
2135b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt   GLuint last_level;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint width0, height0, depth0; /**< Level zero image dimensions */
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint cpp;
21719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry   GLuint num_samples;
2182e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   bool compressed;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
220455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   /**
221e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * If num_samples > 0, then singlesample_width0 is the value that width0
222e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * would have if instead a singlesample miptree were created. Note that,
223e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * for non-interleaved msaa layouts, the two values are the same.
224e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    *
225e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    * If num_samples == 0, then singlesample_width0 is undefined.
226e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace    */
227e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   uint32_t singlesample_width0;
228e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
229e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   /** \see singlesample_width0 */
230e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   uint32_t singlesample_height0;
231e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
232e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   /**
233455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    * For 1D array, 2D array, cube, and 2D multisampled surfaces on Gen7: true
234455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    * if the surface only contains LOD 0, and hence no space is for LOD's
235455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    * other than 0 in between array slices.
236455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    *
237455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    * Corresponds to the surface_array_spacing bit in gen7_surface_state.
238455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    */
239455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   bool array_spacing_lod0;
240455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
241455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   /**
2421bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * MSAA layout used by this buffer.
243455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    */
2441bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   enum intel_msaa_layout msaa_layout;
245455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Derived from the above:
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
248362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt   GLuint total_width;
2496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint total_height;
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
25168216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt   /* The 3DSTATE_CLEAR_PARAMS value associated with the last depth clear to
25268216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt    * this depth mipmap tree, if any.
25368216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt    */
25468216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt   uint32_t depth_clear_value;
25568216f35814ab8d292f37b8c0fa0a5f181b7f20dEric Anholt
2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Includes image offset tables:
2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_mipmap_level level[MAX_TEXTURE_LEVELS];
2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* The data is held here:
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_region *region;
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
26402ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg   /* Offset into region bo where miptree starts:
26502ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg    */
26602ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg   uint32_t offset;
26702ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg
268c270f1a628a625ccc9f6d931f2921e3d92c31818Chad Versace   /**
269f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * \brief Singlesample miptree.
270f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
271f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * This is used under two cases.
272f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
273f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * --- Case 1: As persistent singlesample storage for multisample window
274f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *  system front and back buffers ---
275f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
276f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * Suppose that the window system FBO was created with a multisample
277f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * config.  Let `back_irb` be the `intel_renderbuffer` for the FBO's back
278f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * buffer. Then `back_irb` contains two miptrees: a parent multisample
279f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * miptree (back_irb->mt) and a child singlesample miptree
280f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * (back_irb->mt->singlesample_mt).  The DRM buffer shared with DRI2
281f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * belongs to `back_irb->mt->singlesample_mt` and contains singlesample
282f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * data.  The singlesample miptree is created at the same time as and
283f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * persists for the lifetime of its parent multisample miptree.
284f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
285f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * When access to the singlesample data is needed, such as at
286f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * eglSwapBuffers and glReadPixels, an automatic downsample occurs from
287f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * `back_rb->mt` to `back_rb->mt->singlesample_mt` when necessary.
288f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
289f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * This description of the back buffer applies analogously to the front
290f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * buffer.
291f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
292f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
293f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * --- Case 2: As temporary singlesample storage for mapping multisample
294f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *  miptrees ---
295f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    *
296f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * Suppose the intel_miptree_map is called on a multisample miptree, `mt`,
297f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * for which case 1 does not apply (that is, `mt` does not belong to
298f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * a front or back buffer).  Then `mt->singlesample_mt` is null at the
299f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * start of the call. intel_miptree_map will create a temporary
300f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * singlesample miptree, store it at `mt->singlesample_mt`, downsample from
301f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * `mt` to `mt->singlesample_mt` if necessary, then map
302f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * `mt->singlesample_mt`. The temporary miptree is later deleted during
303f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * intel_miptree_unmap.
304f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    */
305f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   struct intel_mipmap_tree *singlesample_mt;
306f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
307f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   /**
308f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * \brief A downsample is needed from this miptree to singlesample_mt.
309f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    */
310f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   bool need_downsample;
311f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
312f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   /**
313a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace    * \brief HiZ miptree
314c270f1a628a625ccc9f6d931f2921e3d92c31818Chad Versace    *
315a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace    * This is non-null only if HiZ is enabled for this miptree.
316c270f1a628a625ccc9f6d931f2921e3d92c31818Chad Versace    *
317a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace    * \see intel_miptree_alloc_hiz()
318c270f1a628a625ccc9f6d931f2921e3d92c31818Chad Versace    */
319a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace   struct intel_mipmap_tree *hiz_mt;
320c270f1a628a625ccc9f6d931f2921e3d92c31818Chad Versace
3213eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace   /**
322cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    * \brief Map of miptree slices to needed resolves.
323cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    *
324cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    * This is used only when the miptree has a child HiZ miptree.
325cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    *
326cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    * Let \c mt be a depth miptree with HiZ enabled. Then the resolve map is
327cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c
328cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    * mt->hiz_mt->hiz_map, is unused.
329cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace    */
330cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace   struct intel_resolve_map hiz_map;
331cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace
332cf5e08c8e41473467a8732fc834cec52f8b10dc8Chad Versace   /**
3333eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace    * \brief Stencil miptree for depthstencil textures.
3343eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace    *
3355b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * This miptree is used for depthstencil textures and renderbuffers that
3365b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * require separate stencil.  It always has the true copy of the stencil
3375b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * bits, regardless of mt->format.
3383eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace    *
3395b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * \see intel_miptree_map_depthstencil()
3405b27e44652119fd01fe93759e2c82348f4b6d707Eric Anholt    * \see intel_miptree_unmap_depthstencil()
3413eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace    */
3423eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace   struct intel_mipmap_tree *stencil_mt;
3433eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
344ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   /**
345ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * \brief MCS miptree for multisampled textures.
346ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
347ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * This miptree contains the "multisample control surface", which stores
348ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * the necessary information to implement compressed MSAA on Gen7+
349ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * (INTEL_MSAA_FORMAT_CMS).
350ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    */
351ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   struct intel_mipmap_tree *mcs_mt;
352ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
3538dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace   /**
3548dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    * \brief The miptree contains RGBX data that was originally ETC1 data.
3558dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    *
3568dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    * On hardware that lacks support for ETC1 textures, we do the
3578dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    * following on calls to glCompressedTexImage2D(GL_ETC1_RGB8_OES):
3588dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    *   1. Create a miptree whose format is MESA_FORMAT_RGBX8888_REV with
3598dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    *      the wraps_etc1 flag set.
3608dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    *   2. Translate the ETC1 data into RGBX.
3618dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    *   3. Store the RGBX data into the miptree and discard the ETC1 data.
3628dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace    */
3638dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace   bool wraps_etc1;
3648dc074cd92dfc2f80f6c69f80f0d169ad5bb10aaChad Versace
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* These are also refcounted:
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint refcount;
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell};
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstruct intel_mipmap_tree *intel_miptree_create(struct intel_context *intel,
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               GLenum target,
374d5809115b568d8b74f47316607dce0730964517aEric Anholt					       gl_format format,
3755b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt                                               GLuint first_level,
3765b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt                                               GLuint last_level,
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               GLuint width0,
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               GLuint height0,
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                               GLuint depth0,
38019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry					       bool expect_accelerated_upload,
381455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry                                               GLuint num_samples,
3821bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                                               enum intel_msaa_layout msaa_layout);
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3846d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
3856d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_for_region(struct intel_context *intel,
3866d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum target,
387d5809115b568d8b74f47316607dce0730964517aEric Anholt				gl_format format,
3886f23d9b637602d9997896c6ca5cba0dfe36a092eIan Romanick				struct intel_region *region);
3896d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
390f4873babdc27f697df9f4642209eca21a02ac476Chad Versacestruct intel_mipmap_tree*
391f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_create_for_dri2_buffer(struct intel_context *intel,
392f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     unsigned dri_attachment,
393f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     gl_format format,
394f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     uint32_t num_samples,
395f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     struct intel_region *region);
396f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
397005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace/**
398005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace * Create a miptree appropriate as the storage for a non-texture renderbuffer.
399005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace * The miptree has the following properties:
400005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace *     - The target is GL_TEXTURE_2D.
401005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace *     - There are no levels other than the base level 0.
402005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace *     - Depth is 1.
403005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace */
404005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versacestruct intel_mipmap_tree*
405005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versaceintel_miptree_create_for_renderbuffer(struct intel_context *intel,
406005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace                                      gl_format format,
407005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace                                      uint32_t width,
40819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                      uint32_t height,
40919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                      uint32_t num_samples);
410005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace
41173540690f71280a2bdda51b45203fd4ed43a1760Chad Versace/** \brief Assert that the level and layer are valid for the miptree. */
41273540690f71280a2bdda51b45203fd4ed43a1760Chad Versacestatic inline void
41373540690f71280a2bdda51b45203fd4ed43a1760Chad Versaceintel_miptree_check_level_layer(struct intel_mipmap_tree *mt,
41473540690f71280a2bdda51b45203fd4ed43a1760Chad Versace                                uint32_t level,
41573540690f71280a2bdda51b45203fd4ed43a1760Chad Versace                                uint32_t layer)
41673540690f71280a2bdda51b45203fd4ed43a1760Chad Versace{
41773540690f71280a2bdda51b45203fd4ed43a1760Chad Versace   assert(level >= mt->first_level);
41873540690f71280a2bdda51b45203fd4ed43a1760Chad Versace   assert(level <= mt->last_level);
41973540690f71280a2bdda51b45203fd4ed43a1760Chad Versace   assert(layer < mt->level[level].depth);
42073540690f71280a2bdda51b45203fd4ed43a1760Chad Versace}
42173540690f71280a2bdda51b45203fd4ed43a1760Chad Versace
422a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packardint intel_miptree_pitch_align (struct intel_context *intel,
423a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       struct intel_mipmap_tree *mt,
4241ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt			       uint32_t tiling,
425a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       int pitch);
426a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
4276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_miptree_reference(struct intel_mipmap_tree **dst,
4286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                             struct intel_mipmap_tree *src);
4296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
430db3ada6055814a4bd5aa95fc9505fc101864391dEric Anholtvoid intel_miptree_release(struct intel_mipmap_tree **mt);
4316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Check if an image fits an existing mipmap tree layout
4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
4342e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkebool intel_miptree_match_image(struct intel_mipmap_tree *mt,
4358f30ceaaefc33401b08739a16ce1c5638d6432faEric Anholt                                    struct gl_texture_image *image);
4366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4372d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtvoid
4382d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtintel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
4392d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt			       GLuint level, GLuint face, GLuint depth,
4402d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt			       GLuint *x, GLuint *y);
4416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
442fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtvoid
443fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtintel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
444fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt                                       int *width, int *height, int *depth);
445fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt
4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                  GLuint level,
4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                  GLuint x, GLuint y,
4496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                  GLuint w, GLuint h, GLuint d);
4506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
4526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                    GLuint level,
4536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                    GLuint img, GLuint x, GLuint y);
4546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
455b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholtvoid
456b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholtintel_miptree_copy_teximage(struct intel_context *intel,
457b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt                            struct intel_texture_image *intelImage,
458b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt                            struct intel_mipmap_tree *dst_mt);
4596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4603eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace/**
4613eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * Copy the stencil data from \c mt->stencil_mt->region to \c mt->region for
4623eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * the given miptree slice.
4633eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace *
4643eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * \see intel_mipmap_tree::stencil_mt
4653eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace */
4663eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versacevoid
4673eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versaceintel_miptree_s8z24_scatter(struct intel_context *intel,
4683eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                            struct intel_mipmap_tree *mt,
4693eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                            uint32_t level,
4703eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                            uint32_t slice);
4713eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
4723eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace/**
4733eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * Copy the stencil data in \c mt->stencil_mt->region to \c mt->region for the
4743eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * given miptree slice.
4753eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace *
4763eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace * \see intel_mipmap_tree::stencil_mt
4773eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace */
4783eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versacevoid
4793eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versaceintel_miptree_s8z24_gather(struct intel_context *intel,
4803eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                           struct intel_mipmap_tree *mt,
4813eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                           uint32_t level,
4823eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                           uint32_t layer);
4833eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
484ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berrybool
485ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berryintel_miptree_alloc_mcs(struct intel_context *intel,
486ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                        struct intel_mipmap_tree *mt,
487ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                        GLuint num_samples);
488ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
489a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace/**
4902945abea338031cbe90665df60152982bfca6177Chad Versace * \name Miptree HiZ functions
4912945abea338031cbe90665df60152982bfca6177Chad Versace * \{
4922945abea338031cbe90665df60152982bfca6177Chad Versace *
4932945abea338031cbe90665df60152982bfca6177Chad Versace * It is safe to call the "slice_set_need_resolve" and "slice_resolve"
4942945abea338031cbe90665df60152982bfca6177Chad Versace * functions on a miptree without HiZ. In that case, each function is a no-op.
4952945abea338031cbe90665df60152982bfca6177Chad Versace */
4962945abea338031cbe90665df60152982bfca6177Chad Versace
4972945abea338031cbe90665df60152982bfca6177Chad Versace/**
498a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace * \brief Allocate the miptree's embedded HiZ miptree.
499a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace * \see intel_mipmap_tree:hiz_mt
500a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace * \return false if allocation failed
501a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace */
5022945abea338031cbe90665df60152982bfca6177Chad Versace
503a2e44b0813e956440c451c107cf5564b56cbe98eChad Versacebool
504a2e44b0813e956440c451c107cf5564b56cbe98eChad Versaceintel_miptree_alloc_hiz(struct intel_context *intel,
50519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry			struct intel_mipmap_tree *mt,
50619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                        GLuint num_samples);
507a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace
5082945abea338031cbe90665df60152982bfca6177Chad Versacevoid
5092945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt,
5102945abea338031cbe90665df60152982bfca6177Chad Versace                                          uint32_t level,
5112945abea338031cbe90665df60152982bfca6177Chad Versace					  uint32_t depth);
5122945abea338031cbe90665df60152982bfca6177Chad Versacevoid
5132945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt,
5142945abea338031cbe90665df60152982bfca6177Chad Versace                                            uint32_t level,
5152945abea338031cbe90665df60152982bfca6177Chad Versace					    uint32_t depth);
5162945abea338031cbe90665df60152982bfca6177Chad Versacevoid
5172945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_set_need_hiz_resolve(struct intel_mipmap_tree *mt);
5182945abea338031cbe90665df60152982bfca6177Chad Versace
5192945abea338031cbe90665df60152982bfca6177Chad Versacevoid
5202945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_set_need_depth_resolve(struct intel_mipmap_tree *mt);
5212945abea338031cbe90665df60152982bfca6177Chad Versace
5222945abea338031cbe90665df60152982bfca6177Chad Versace/**
5232945abea338031cbe90665df60152982bfca6177Chad Versace * \return false if no resolve was needed
5242945abea338031cbe90665df60152982bfca6177Chad Versace */
5252945abea338031cbe90665df60152982bfca6177Chad Versacebool
5262945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_hiz(struct intel_context *intel,
5272945abea338031cbe90665df60152982bfca6177Chad Versace				struct intel_mipmap_tree *mt,
5282945abea338031cbe90665df60152982bfca6177Chad Versace				unsigned int level,
5292945abea338031cbe90665df60152982bfca6177Chad Versace				unsigned int depth);
5302945abea338031cbe90665df60152982bfca6177Chad Versace
5312945abea338031cbe90665df60152982bfca6177Chad Versace/**
5322945abea338031cbe90665df60152982bfca6177Chad Versace * \return false if no resolve was needed
5332945abea338031cbe90665df60152982bfca6177Chad Versace */
5342945abea338031cbe90665df60152982bfca6177Chad Versacebool
5352945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_depth(struct intel_context *intel,
5362945abea338031cbe90665df60152982bfca6177Chad Versace				  struct intel_mipmap_tree *mt,
5372945abea338031cbe90665df60152982bfca6177Chad Versace				  unsigned int level,
5382945abea338031cbe90665df60152982bfca6177Chad Versace				  unsigned int depth);
5392945abea338031cbe90665df60152982bfca6177Chad Versace
5402945abea338031cbe90665df60152982bfca6177Chad Versace/**
5412945abea338031cbe90665df60152982bfca6177Chad Versace * \return false if no resolve was needed
5422945abea338031cbe90665df60152982bfca6177Chad Versace */
5432945abea338031cbe90665df60152982bfca6177Chad Versacebool
5442945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_hiz(struct intel_context *intel,
5452945abea338031cbe90665df60152982bfca6177Chad Versace				     struct intel_mipmap_tree *mt);
5462945abea338031cbe90665df60152982bfca6177Chad Versace
5472945abea338031cbe90665df60152982bfca6177Chad Versace/**
5482945abea338031cbe90665df60152982bfca6177Chad Versace * \return false if no resolve was needed
5492945abea338031cbe90665df60152982bfca6177Chad Versace */
5502945abea338031cbe90665df60152982bfca6177Chad Versacebool
5512945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_depth(struct intel_context *intel,
5522945abea338031cbe90665df60152982bfca6177Chad Versace				       struct intel_mipmap_tree *mt);
5532945abea338031cbe90665df60152982bfca6177Chad Versace
5542945abea338031cbe90665df60152982bfca6177Chad Versace/**\}*/
5552945abea338031cbe90665df60152982bfca6177Chad Versace
556f4873babdc27f697df9f4642209eca21a02ac476Chad Versacevoid
557f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_downsample(struct intel_context *intel,
558f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                         struct intel_mipmap_tree *mt);
559f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
560f4873babdc27f697df9f4642209eca21a02ac476Chad Versacevoid
561f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_upsample(struct intel_context *intel,
562f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                       struct intel_mipmap_tree *mt);
563f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
5646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* i915_mipmap_tree.c:
5656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
566d7cdbc3c5415d2dd5eee58834b13714a89eacf2bKenneth Graunkevoid i915_miptree_layout(struct intel_mipmap_tree *mt);
567d7cdbc3c5415d2dd5eee58834b13714a89eacf2bKenneth Graunkevoid i945_miptree_layout(struct intel_mipmap_tree *mt);
568d7cdbc3c5415d2dd5eee58834b13714a89eacf2bKenneth Graunkevoid brw_miptree_layout(struct intel_context *intel,
569d7cdbc3c5415d2dd5eee58834b13714a89eacf2bKenneth Graunke			struct intel_mipmap_tree *mt);
5706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
571b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtvoid
572b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtintel_miptree_map(struct intel_context *intel,
573b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  struct intel_mipmap_tree *mt,
574b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int level,
575b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int slice,
576b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int x,
577b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int y,
578b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int w,
579b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  unsigned int h,
580b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  GLbitfield mode,
581b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  void **out_ptr,
582b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		  int *out_stride);
583b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
584b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtvoid
585b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholtintel_miptree_unmap(struct intel_context *intel,
586b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		    struct intel_mipmap_tree *mt,
587b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		    unsigned int level,
588b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt		    unsigned int slice);
589b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
5905b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt#ifdef I915
5915b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholtstatic inline void
5925b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholtintel_hiz_exec(struct intel_context *intel, struct intel_mipmap_tree *mt,
5935b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt	       unsigned int level, unsigned int layer, enum gen6_hiz_op op)
5945b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt{
5955b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt   /* Stub on i915.  It would be nice if we didn't execute resolve code at all
5965b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt    * there.
5975b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt    */
5985b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt}
5995b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt#else
6005b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholtvoid
6015b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholtintel_hiz_exec(struct intel_context *intel, struct intel_mipmap_tree *mt,
6025b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt	       unsigned int level, unsigned int layer, enum gen6_hiz_op op);
6035b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt#endif
6045b226ad603302554f38e6b12a93bd2cf443d4b56Eric Anholt
605434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#ifdef __cplusplus
606434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry}
607434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry#endif
608434fc8bde41f07687ad8941ceba03c4b3e0e75bbPaul Berry
6096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
610