177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**************************************************************************
277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * All Rights Reserved.
577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * copy of this software and associated documentation files (the
877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * "Software"), to deal in the Software without restriction, including
977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * without limitation the rights to use, copy, modify, merge, publish,
1077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * distribute, sub license, and/or sell copies of the Software, and to
1177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * permit persons to whom the Software is furnished to do so, subject to
1277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the following conditions:
1377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
1477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * The above copyright notice and this permission notice (including the
1577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * next paragraph) shall be included in all copies or substantial portions
1677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * of the Software.
1777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
1877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
2677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt **************************************************************************/
2777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28f4873babdc27f697df9f4642209eca21a02ac476Chad Versace#include <GL/gl.h>
29f4873babdc27f697df9f4642209eca21a02ac476Chad Versace#include <GL/internal/dri_interface.h>
30f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
313eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace#include "intel_batchbuffer.h"
3277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_context.h"
3377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_mipmap_tree.h"
3477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_regions.h"
352945abea338031cbe90665df60152982bfca6177Chad Versace#include "intel_resolve_map.h"
363eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace#include "intel_span.h"
373732d0a77d2cbae50874f5a4ebdb3d8f06021a57Brian Paul#include "intel_tex_layout.h"
386dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt#include "intel_tex.h"
39b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt#include "intel_blit.h"
403eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
41d3746354fbfadf821dc108e072d86b5329737444Chad Versace#ifndef I915
42d3746354fbfadf821dc108e072d86b5329737444Chad Versace#include "brw_blorp.h"
43d3746354fbfadf821dc108e072d86b5329737444Chad Versace#endif
44d3746354fbfadf821dc108e072d86b5329737444Chad Versace
45ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h"
46c374487a54aca2dd1053645092367c1cf0414ef7Eric Anholt#include "main/formats.h"
478b762ebd72c1bb1a9827a667ad55ba9516505adfBrian Paul#include "main/glformats.h"
48a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace#include "main/texcompress_etc.h"
49b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt#include "main/teximage.h"
5077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#define FILE_DEBUG_FLAG DEBUG_MIPTREE
5277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLenum
5477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholttarget_to_target(GLenum target)
5577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
5677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   switch (target) {
5777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
5877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
5977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
6077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
6177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
6277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
6377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_TEXTURE_CUBE_MAP_ARB;
6477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   default:
6577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return target;
6677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
6777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
6877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
697e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace/**
707e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace * @param for_region Indicates that the caller is
717e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace *        intel_miptree_create_for_region(). If true, then do not create
727e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace *        \c stencil_mt.
737e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace */
746d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstatic struct intel_mipmap_tree *
756d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_internal(struct intel_context *intel,
766d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLenum target,
77d5809115b568d8b74f47316607dce0730964517aEric Anholt			      gl_format format,
785b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt			      GLuint first_level,
795b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt			      GLuint last_level,
806d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint width0,
816d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint height0,
827e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace			      GLuint depth0,
8319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry			      bool for_region,
84455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry                              GLuint num_samples,
851bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                              enum intel_msaa_layout msaa_layout)
8677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
8777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1);
886dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt   int compress_byte = 0;
8977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
905b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt   DBG("%s target %s format %s level %d..%d <-- %p\n", __FUNCTION__,
9177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       _mesa_lookup_enum_by_nr(target),
929a523a48af05118424714f0a34ca3dda6861186aEric Anholt       _mesa_get_format_name(format),
935b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt       first_level, last_level, mt);
9477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
956dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt   if (_mesa_is_format_compressed(format))
966dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt      compress_byte = intel_compressed_num_bytes(format);
976dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt
9877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->target = target_to_target(target);
99d5809115b568d8b74f47316607dce0730964517aEric Anholt   mt->format = format;
1005b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt   mt->first_level = first_level;
1015b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt   mt->last_level = last_level;
10277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->width0 = width0;
10377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->height0 = height0;
104f94fef83db10f0c9327bd3dd43510ad31c94d82aEric Anholt   mt->cpp = compress_byte ? compress_byte : _mesa_get_format_bytes(mt->format);
10519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry   mt->num_samples = num_samples;
10677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->compressed = compress_byte ? 1 : 0;
1071bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   mt->msaa_layout = msaa_layout;
10877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->refcount = 1;
10977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
1101bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /* array_spacing_lod0 is only used for non-IMS MSAA surfaces.  TODO: can we
1111bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry    * use it elsewhere?
112455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry    */
1131bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   switch (msaa_layout) {
1141bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   case INTEL_MSAA_LAYOUT_NONE:
1151bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   case INTEL_MSAA_LAYOUT_IMS:
1161bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      mt->array_spacing_lod0 = false;
1171bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      break;
1181bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   case INTEL_MSAA_LAYOUT_UMS:
1191bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   case INTEL_MSAA_LAYOUT_CMS:
1201bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      mt->array_spacing_lod0 = true;
1211bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      break;
1221bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   }
123455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
124d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   if (target == GL_TEXTURE_CUBE_MAP) {
125d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      assert(depth0 == 1);
126d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      mt->depth0 = 6;
127d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   } else {
128d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      mt->depth0 = depth0;
129d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   }
130d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace
1317e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace   if (!for_region &&
1327e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace       _mesa_is_depthstencil_format(_mesa_get_format_base_format(format)) &&
1335c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt       (intel->must_use_separate_stencil ||
1345c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt	(intel->has_separate_stencil &&
1355c9a55665d78b96bfb8ce8eab43b5558dd656a6dEric Anholt	 intel->vtbl.is_hiz_depth_format(intel, format)))) {
1361bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      /* MSAA stencil surfaces always use IMS layout. */
1371bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      enum intel_msaa_layout msaa_layout =
13897fc89c6cbaa3b5ef7f678d2dc2c7d5bbba05315Paul Berry         num_samples > 1 ? INTEL_MSAA_LAYOUT_IMS : INTEL_MSAA_LAYOUT_NONE;
1393eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace      mt->stencil_mt = intel_miptree_create(intel,
1403eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->target,
1413eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            MESA_FORMAT_S8,
1423eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->first_level,
1433eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->last_level,
1443eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->width0,
1453eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->height0,
1463eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                                            mt->depth0,
14719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                            true,
148455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry                                            num_samples,
1491bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                                            msaa_layout);
1503eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace      if (!mt->stencil_mt) {
1513eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace	 intel_miptree_release(&mt);
1523eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace	 return NULL;
1533eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace      }
154fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt
155fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt      /* Fix up the Z miptree format for how we're splitting out separate
156fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt       * stencil.  Gen7 expects there to be no stencil bits in its depth buffer.
157fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt       */
158fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt      if (mt->format == MESA_FORMAT_S8_Z24) {
159fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt	 mt->format = MESA_FORMAT_X8_Z24;
1604790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt      } else if (mt->format == MESA_FORMAT_Z32_FLOAT_X24S8) {
1614790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt	 mt->format = MESA_FORMAT_Z32_FLOAT;
1624790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt	 mt->cpp = 4;
163fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt      } else {
1644790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt	 _mesa_problem(NULL, "Unknown format %s in separate stencil mt\n",
165fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt		       _mesa_get_format_name(mt->format));
166fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt      }
1673eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace   }
1683eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
1694790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt   intel_get_texture_alignment_unit(intel, mt->format,
1704790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt				    &mt->align_w, &mt->align_h);
1714790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt
1724790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#ifdef I915
1734790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt   (void) intel;
1744790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt   if (intel->is_945)
1754790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt      i945_miptree_layout(mt);
1764790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt   else
1774790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt      i915_miptree_layout(mt);
1784790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#else
1794790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt   brw_miptree_layout(intel, mt);
1804790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt#endif
1814790c4ae2489b8c72e6d98f3f80b5a9e7f799203Eric Anholt
1826d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   return mt;
1836d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg}
1846d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
18547a7535f413d6467082de224f64eecc046227406Brian Paul
1866d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
1876d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create(struct intel_context *intel,
1886d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLenum target,
189d5809115b568d8b74f47316607dce0730964517aEric Anholt		     gl_format format,
1905b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt		     GLuint first_level,
1915b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt		     GLuint last_level,
1926d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint width0,
1936d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint height0,
194f94fef83db10f0c9327bd3dd43510ad31c94d82aEric Anholt		     GLuint depth0,
19519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry		     bool expect_accelerated_upload,
196455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry                     GLuint num_samples,
1971bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                     enum intel_msaa_layout msaa_layout)
1986d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{
1996d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   struct intel_mipmap_tree *mt;
200453f0b1f243b26e02b371293e9c8bbf09362c14aEric Anholt   uint32_t tiling = I915_TILING_NONE;
201a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   GLenum base_format;
202a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   bool wraps_etc1 = false;
2035db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry   GLuint total_width, total_height;
204a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
205a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   if (format == MESA_FORMAT_ETC1_RGB8) {
206a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace      format = MESA_FORMAT_RGBX8888_REV;
207a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace      wraps_etc1 = true;
208a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   }
209a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
210a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   base_format = _mesa_get_format_base_format(format);
2111ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt
2126dcc398ac0837025cf60b4d6a056fa3b0a16466fEric Anholt   if (intel->use_texture_tiling && !_mesa_is_format_compressed(format)) {
213caf3038123d6d29afd7d1f0cd6db98a2282c3ca1Eric Anholt      if (intel->gen >= 4 &&
2149c0ba017c8ff7caafc3ff94da3c035e687231596Eric Anholt	  (base_format == GL_DEPTH_COMPONENT ||
2159c0ba017c8ff7caafc3ff94da3c035e687231596Eric Anholt	   base_format == GL_DEPTH_STENCIL_EXT))
216bd10f0e84f1491363d76d92dcbd410ab5cc43dbeEric Anholt	 tiling = I915_TILING_Y;
2171bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      else if (msaa_layout != INTEL_MSAA_LAYOUT_NONE) {
21819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry         /* From p82 of the Sandy Bridge PRM, dw3[1] of SURFACE_STATE ("Tiled
21919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * Surface"):
22019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          *
22119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          *   [DevSNB+]: For multi-sample render targets, this field must be
22219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          *   1. MSRTs can only be tiled.
22319e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          *
22419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * Our usual reason for preferring X tiling (fast blits using the
22519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * blitting engine) doesn't apply to MSAA, since we'll generally be
22619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * downsampling or upsampling when blitting between the MSAA buffer
22719e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * and another buffer, and the blitting engine doesn't support that.
22819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          * So use Y tiling, since it makes better use of the cache.
22919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry          */
23019e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry         tiling = I915_TILING_Y;
23119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry      } else if (width0 >= 64)
232bd10f0e84f1491363d76d92dcbd410ab5cc43dbeEric Anholt	 tiling = I915_TILING_X;
233453f0b1f243b26e02b371293e9c8bbf09362c14aEric Anholt   }
2346d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
2359a523a48af05118424714f0a34ca3dda6861186aEric Anholt   mt = intel_miptree_create_internal(intel, target, format,
2365b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt				      first_level, last_level, width0,
2377e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace				      height0, depth0,
2381bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry				      false, num_samples, msaa_layout);
2397ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao   /*
2408b69c42b356d51c3a37bc0af41738b016c2adc5bXiang, Haihao    * pitch == 0 || height == 0  indicates the null texture
2417ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao    */
2421a662e7c18cab98f1b122f6766faf338725de673Yuanhan Liu   if (!mt || !mt->total_width || !mt->total_height) {
243747f0307626ef5bcf2f889ab66bcc95ab8eda2c8Chad Versace      intel_miptree_release(&mt);
2446d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return NULL;
245a7d0665c00053839065592c339bfb298187a82beVinson Lee   }
2466d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
2475db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry   total_width = mt->total_width;
2485db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry   total_height = mt->total_height;
2495db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry
2505db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry   if (format == MESA_FORMAT_S8) {
2515db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry      /* The stencil buffer is W tiled. However, we request from the kernel a
2525db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry       * non-tiled buffer because the GTT is incapable of W fencing.  So round
2535db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry       * up the width and height to match the size of W tiles (64x64).
2545db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry       */
2555db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry      tiling = I915_TILING_NONE;
2565db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry      total_width = ALIGN(total_width, 64);
2575db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry      total_height = ALIGN(total_height, 64);
2585db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry   }
2595db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry
260a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   mt->wraps_etc1 = wraps_etc1;
2619087ba128089ed0dc00e6eb38f37126fb7557d3bKristian Høgsberg   mt->region = intel_region_alloc(intel->intelScreen,
2621ba96651e12b3c74fb9c8f5a61b183ef36a27b1eEric Anholt				   tiling,
2638db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				   mt->cpp,
2645db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry				   total_width,
2655db1deab5118a986167ea6e8f8c7c196c74457c1Paul Berry				   total_height,
26640dd024be618d805b3744e15d25e115018641324Eric Anholt				   expect_accelerated_upload);
26702ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg   mt->offset = 0;
2686d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
26977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!mt->region) {
270747f0307626ef5bcf2f889ab66bcc95ab8eda2c8Chad Versace       intel_miptree_release(&mt);
2716d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg       return NULL;
2726d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   }
2736d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
2746d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   return mt;
2756d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg}
2766d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
27747a7535f413d6467082de224f64eecc046227406Brian Paul
2786d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
2796d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_for_region(struct intel_context *intel,
2806d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum target,
281d5809115b568d8b74f47316607dce0730964517aEric Anholt				gl_format format,
2826f23d9b637602d9997896c6ca5cba0dfe36a092eIan Romanick				struct intel_region *region)
2836d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{
2846d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   struct intel_mipmap_tree *mt;
2856d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
2869a523a48af05118424714f0a34ca3dda6861186aEric Anholt   mt = intel_miptree_create_internal(intel, target, format,
2875b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt				      0, 0,
2887e08bf08d13228001f6306800b5bd69b89b1bb6fChad Versace				      region->width, region->height, 1,
289455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry				      true, 0 /* num_samples */,
2901bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                                      INTEL_MSAA_LAYOUT_NONE);
2916d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (!mt)
2926d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return mt;
293da011faf48155a5c02ebc1fe1fa20a4f54b8c657Eric Anholt
294e72a44215312ae1f3c812ba28e47b4aec3589de9Pierre Willenbrock   intel_region_reference(&mt->region, region);
29577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return mt;
29747a7535f413d6467082de224f64eecc046227406Brian Paul}
29847a7535f413d6467082de224f64eecc046227406Brian Paul
299455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry/**
3001bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * Determine which MSAA layout should be used by the MSAA surface being
3011bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry * created, based on the chip generation and the surface type.
302455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry */
3031bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berrystatic enum intel_msaa_layout
3041bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berrycompute_msaa_layout(struct intel_context *intel, gl_format format)
305455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry{
3061bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /* Prior to Gen7, all MSAA surfaces used IMS layout. */
307455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   if (intel->gen < 7)
3081bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      return INTEL_MSAA_LAYOUT_IMS;
309455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
3101bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /* In Gen7, IMS layout is only used for depth and stencil buffers. */
311455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   switch (_mesa_get_format_base_format(format)) {
312455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   case GL_DEPTH_COMPONENT:
313455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   case GL_STENCIL_INDEX:
314455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   case GL_DEPTH_STENCIL:
3151bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      return INTEL_MSAA_LAYOUT_IMS;
316455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   default:
31733202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry      /* From the Ivy Bridge PRM, Vol4 Part1 p77 ("MCS Enable"):
31833202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       *
31933202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       *   This field must be set to 0 for all SINT MSRTs when all RT channels
32033202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       *   are not written
32133202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       *
32233202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       * In practice this means that we have to disable MCS for all signed
32333202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       * integer MSAA buffers.  The alternative, to disable MCS only when one
32433202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       * of the render target channels is disabled, is impractical because it
32533202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       * would require converting between CMS and UMS MSAA layouts on the fly,
32633202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       * which is expensive.
32733202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry       */
32833202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry      if (_mesa_get_format_datatype(format) == GL_INT) {
32933202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry         /* TODO: is this workaround needed for future chipsets? */
33033202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry         assert(intel->gen == 7);
33133202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry         return INTEL_MSAA_LAYOUT_UMS;
33233202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry      } else {
33333202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry         return INTEL_MSAA_LAYOUT_CMS;
33433202b4876a88b6f54ca7022eadd2875a2d3508aPaul Berry      }
335455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   }
336455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry}
337455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
338f4873babdc27f697df9f4642209eca21a02ac476Chad Versace/**
339f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * For a singlesample DRI2 buffer, this simply wraps the given region with a miptree.
340f4873babdc27f697df9f4642209eca21a02ac476Chad Versace *
341f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * For a multisample DRI2 buffer, this wraps the given region with
342f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * a singlesample miptree, then creates a multisample miptree into which the
343f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * singlesample miptree is embedded as a child.
344f4873babdc27f697df9f4642209eca21a02ac476Chad Versace */
345f4873babdc27f697df9f4642209eca21a02ac476Chad Versacestruct intel_mipmap_tree*
346f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_create_for_dri2_buffer(struct intel_context *intel,
347f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     unsigned dri_attachment,
348f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     gl_format format,
349f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     uint32_t num_samples,
350f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                     struct intel_region *region)
351f4873babdc27f697df9f4642209eca21a02ac476Chad Versace{
352f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   struct intel_mipmap_tree *singlesample_mt = NULL;
353f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   struct intel_mipmap_tree *multisample_mt = NULL;
354f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   GLenum base_format = _mesa_get_format_base_format(format);
355f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
356f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   /* Only the front and back buffers, which are color buffers, are shared
357f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    * through DRI2.
358f4873babdc27f697df9f4642209eca21a02ac476Chad Versace    */
359f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   assert(dri_attachment == __DRI_BUFFER_BACK_LEFT ||
360f4873babdc27f697df9f4642209eca21a02ac476Chad Versace          dri_attachment == __DRI_BUFFER_FRONT_LEFT ||
361f4873babdc27f697df9f4642209eca21a02ac476Chad Versace          dri_attachment == __DRI_BUFFER_FAKE_FRONT_LEFT);
362f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   assert(base_format == GL_RGB || base_format == GL_RGBA);
363f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
364f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   singlesample_mt = intel_miptree_create_for_region(intel, GL_TEXTURE_2D,
365f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                                     format, region);
366f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   if (!singlesample_mt)
367f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      return NULL;
368f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
369f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   if (num_samples == 0)
370f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      return singlesample_mt;
371f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
372f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   multisample_mt = intel_miptree_create_for_renderbuffer(intel,
373f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                                          format,
374f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                                          region->width,
375f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                                          region->height,
376f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                                                          num_samples);
377f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   if (!multisample_mt) {
378f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      intel_miptree_release(&singlesample_mt);
379f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      return NULL;
380f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   }
381f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
382f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   multisample_mt->singlesample_mt = singlesample_mt;
383f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   multisample_mt->need_downsample = false;
384f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
385f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   if (intel->is_front_buffer_rendering &&
386f4873babdc27f697df9f4642209eca21a02ac476Chad Versace       (dri_attachment == __DRI_BUFFER_FRONT_LEFT ||
387f4873babdc27f697df9f4642209eca21a02ac476Chad Versace        dri_attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)) {
388f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      intel_miptree_upsample(intel, multisample_mt);
389f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   }
390f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
391f4873babdc27f697df9f4642209eca21a02ac476Chad Versace   return multisample_mt;
392f4873babdc27f697df9f4642209eca21a02ac476Chad Versace}
393f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
394005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versacestruct intel_mipmap_tree*
395005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versaceintel_miptree_create_for_renderbuffer(struct intel_context *intel,
396005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace                                      gl_format format,
397005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace                                      uint32_t width,
39819e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                      uint32_t height,
39919e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                      uint32_t num_samples)
400005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace{
401005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace   struct intel_mipmap_tree *mt;
402455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry   uint32_t depth = 1;
4031bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   enum intel_msaa_layout msaa_layout = INTEL_MSAA_LAYOUT_NONE;
404e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   const uint32_t singlesample_width = width;
405e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   const uint32_t singlesample_height = height;
4064eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   bool ok;
407455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry
40897fc89c6cbaa3b5ef7f678d2dc2c7d5bbba05315Paul Berry   if (num_samples > 1) {
409455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry      /* Adjust width/height/depth for MSAA */
4101bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      msaa_layout = compute_msaa_layout(intel, format);
4111bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry      if (msaa_layout == INTEL_MSAA_LAYOUT_IMS) {
412455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         /* In the Sandy Bridge PRM, volume 4, part 1, page 31, it says:
413455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
414455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *     "Any of the other messages (sample*, LOD, load4) used with a
415455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (4x) multisampled surface will in-effect sample a surface with
416455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      double the height and width as that indicated in the surface
417455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      state. Each pixel position on the original-sized surface is
418455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      replaced with a 2x2 of samples with the following arrangement:
419455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
420455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *         sample 0 sample 2
421455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *         sample 1 sample 3"
422455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
423455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * Thus, when sampling from a multisampled texture, it behaves as
424455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * though the layout in memory for (x,y,sample) is:
425455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
426455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,0,0) (0,0,2)   (1,0,0) (1,0,2)
427455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,0,1) (0,0,3)   (1,0,1) (1,0,3)
428455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
429455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,1,0) (0,1,2)   (1,1,0) (1,1,2)
430455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,1,1) (0,1,3)   (1,1,1) (1,1,3)
431455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
432455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * However, the actual layout of multisampled data in memory is:
433455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
434455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,0,0) (1,0,0)   (0,0,1) (1,0,1)
435455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,1,0) (1,1,0)   (0,1,1) (1,1,1)
436455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
437455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,0,2) (1,0,2)   (0,0,3) (1,0,3)
438455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *      (0,1,2) (1,1,2)   (0,1,3) (1,1,3)
439455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
440455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * This pattern repeats for each 2x2 pixel block.
441455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          *
442455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * As a result, when calculating the size of our 4-sample buffer for
443455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * an odd width or height, we have to align before scaling up because
444455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          * sample 3 is in that bottom right 2x2 block.
445455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry          */
446455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         switch (num_samples) {
447455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         case 4:
448455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            width = ALIGN(width, 2) * 2;
449455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            height = ALIGN(height, 2) * 2;
450455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            break;
451455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         case 8:
452455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            width = ALIGN(width, 2) * 4;
453455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            height = ALIGN(height, 2) * 2;
454455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            break;
455455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         default:
45697fc89c6cbaa3b5ef7f678d2dc2c7d5bbba05315Paul Berry            /* num_samples should already have been quantized to 0, 1, 4, or
457455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry             * 8.
458455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry             */
459455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry            assert(false);
460455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         }
461455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry      } else {
462455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         /* Non-interleaved */
463455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry         depth = num_samples;
464455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry      }
46519e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry   }
46619e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry
467f22068d5be7c829d3768154845ef3c5a2986fed4Eric Anholt   mt = intel_miptree_create(intel, GL_TEXTURE_2D, format, 0, 0,
468455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry			     width, height, depth, true, num_samples,
4691bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                             msaa_layout);
4704eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   if (!mt)
4714eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace      goto fail;
4724eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace
4734eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   if (intel->vtbl.is_hiz_depth_format(intel, format)) {
4744eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace      ok = intel_miptree_alloc_hiz(intel, mt, num_samples);
4754eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace      if (!ok)
4764eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace         goto fail;
4774eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   }
4784eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace
4794eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   if (mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS) {
4804eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace      ok = intel_miptree_alloc_mcs(intel, mt, num_samples);
4814eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace      if (!ok)
4824eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace         goto fail;
4834eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   }
484005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace
485e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   mt->singlesample_width0 = singlesample_width;
486e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   mt->singlesample_height0 = singlesample_height;
487e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
488005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace   return mt;
4894eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace
4904eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versacefail:
4914eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   intel_miptree_release(&mt);
4924eba67285fb6b5d2dd4927e8dc4b3e2945435309Chad Versace   return NULL;
493005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace}
494005149d5860ad55c5e58e2de8a138e3a763f2036Chad Versace
49577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
49677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_reference(struct intel_mipmap_tree **dst,
49777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        struct intel_mipmap_tree *src)
49877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
49932fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt   if (*dst == src)
50032fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt      return;
50132fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt
50232fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt   intel_miptree_release(dst);
50332fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt
50432fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt   if (src) {
50532fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt      src->refcount++;
50632fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt      DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount);
50732fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt   }
50832fe506ae14efa055f4773f422e2edd9fd1cffeeEric Anholt
50977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *dst = src;
51077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
51177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
51247a7535f413d6467082de224f64eecc046227406Brian Paul
51377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
514db3ada6055814a4bd5aa95fc9505fc101864391dEric Anholtintel_miptree_release(struct intel_mipmap_tree **mt)
51577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
51677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!*mt)
51777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return;
51877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
51977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s %p refcount will be %d\n", __FUNCTION__, *mt, (*mt)->refcount - 1);
52077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (--(*mt)->refcount <= 0) {
52177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLuint i;
52277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
52377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      DBG("%s deleting %p\n", __FUNCTION__, *mt);
52477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
52577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intel_region_release(&((*mt)->region));
5263eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace      intel_miptree_release(&(*mt)->stencil_mt);
527a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace      intel_miptree_release(&(*mt)->hiz_mt);
528ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry      intel_miptree_release(&(*mt)->mcs_mt);
529f4873babdc27f697df9f4642209eca21a02ac476Chad Versace      intel_miptree_release(&(*mt)->singlesample_mt);
5302945abea338031cbe90665df60152982bfca6177Chad Versace      intel_resolve_map_clear(&(*mt)->hiz_map);
53177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5322d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt      for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
533c2ddde70daece24d1eb7185946032158993a9e4dChad Versace	 free((*mt)->level[i].slice);
5342d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt      }
53577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
53677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(*mt);
53777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
53877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *mt = NULL;
53977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
54077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
541fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtvoid
542fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholtintel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
543fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt                                       int *width, int *height, int *depth)
544fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt{
545fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   switch (image->TexObject->Target) {
546fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   case GL_TEXTURE_1D_ARRAY:
547fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *width = image->Width;
548fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *height = 1;
549fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *depth = image->Height;
550fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      break;
551fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   default:
552fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *width = image->Width;
553fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *height = image->Height;
554fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      *depth = image->Depth;
555fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt      break;
556fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   }
557fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt}
55877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
55947a7535f413d6467082de224f64eecc046227406Brian Paul/**
56047a7535f413d6467082de224f64eecc046227406Brian Paul * Can the image be pulled into a unified mipmap tree?  This mirrors
56177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the completeness test in a lot of ways.
56277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
56377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Not sure whether I want to pass gl_texture_image here.
56477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
5652e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkebool
56677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_match_image(struct intel_mipmap_tree *mt,
5678f30ceaaefc33401b08739a16ce1c5638d6432faEric Anholt                          struct gl_texture_image *image)
56877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
5698f30ceaaefc33401b08739a16ce1c5638d6432faEric Anholt   struct intel_texture_image *intelImage = intel_texture_image(image);
570fa2c886863492cc3eeee6d2059ae24edc1cb2bffBrian Paul   GLuint level = intelImage->base.Base.Level;
571fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   int width, height, depth;
572b6bdafdf2cf1110b4a5ca7cf9e1c3dcb124b800fBrian Paul
573ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt   if (target_to_target(image->TexObject->Target) != mt->target)
574ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt      return false;
575ab7794cada02f3b3b5e3a642c20eeedeb17b65a6Eric Anholt
576fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt   if (image->TexFormat != mt->format &&
577fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt       !(image->TexFormat == MESA_FORMAT_S8_Z24 &&
578fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt	 mt->format == MESA_FORMAT_X8_Z24 &&
579fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt	 mt->stencil_mt)) {
5802e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke      return false;
581fdf18b323156098ba5fb2881aa1a7888d2e0667fEric Anholt   }
582d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao
583fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   intel_miptree_get_dimensions_for_image(image, &width, &height, &depth);
584fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt
5857f854a5028ef00a0e041e78a770456204dc58eefEric Anholt   if (mt->target == GL_TEXTURE_CUBE_MAP)
5867f854a5028ef00a0e041e78a770456204dc58eefEric Anholt      depth = 6;
5877f854a5028ef00a0e041e78a770456204dc58eefEric Anholt
58877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Test image dimensions against the base level image adjusted for
58977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * minification.  This will also catch images not present in the
59077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * tree, changed targets, etc.
59177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
592fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt   if (width != mt->level[level].width ||
593fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt       height != mt->level[level].height ||
594fd99cd0e10849205749aad580fea8c970fb46a31Eric Anholt       depth != mt->level[level].depth)
5952e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke      return false;
59677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
5972e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   return true;
59877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
59977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
60077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
60177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
60277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_level_info(struct intel_mipmap_tree *mt,
603659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint level,
604659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint x, GLuint y,
605659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint w, GLuint h, GLuint d)
60677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
60777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].width = w;
60877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].height = h;
60977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].depth = d;
6102d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   mt->level[level].level_x = x;
6112d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   mt->level[level].level_y = y;
61277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
6130c51390e4b5e04b992e50fcbed751024e6c329deEric Anholt   DBG("%s level %d size: %d,%d,%d offset %d,%d\n", __FUNCTION__,
6140c51390e4b5e04b992e50fcbed751024e6c329deEric Anholt       level, w, h, d, x, y);
61577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
616c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   assert(mt->level[level].slice == NULL);
61777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
618221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   mt->level[level].slice = calloc(d, sizeof(*mt->level[0].slice));
619c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   mt->level[level].slice[0].x_offset = mt->level[level].level_x;
620c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   mt->level[level].slice[0].y_offset = mt->level[level].level_y;
62177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
62277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
62377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
62477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
6252d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtintel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
6262d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt			       GLuint level, GLuint img,
6272d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt			       GLuint x, GLuint y)
62877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
62977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (img == 0 && level == 0)
63077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      assert(x == 0 && y == 0);
63177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
632d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   assert(img < mt->level[level].depth);
63377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
634c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   mt->level[level].slice[img].x_offset = mt->level[level].level_x + x;
635c2ddde70daece24d1eb7185946032158993a9e4dChad Versace   mt->level[level].slice[img].y_offset = mt->level[level].level_y + y;
63677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
6372d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   DBG("%s level %d img %d pos %d,%d\n",
6382d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt       __FUNCTION__, level, img,
639c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       mt->level[level].slice[img].x_offset,
640c2ddde70daece24d1eb7185946032158993a9e4dChad Versace       mt->level[level].slice[img].y_offset);
64177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
64277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
64347a7535f413d6467082de224f64eecc046227406Brian Paul
644d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace/**
645d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * For cube map textures, either the \c face parameter can be used, of course,
646d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * or the cube face can be interpreted as a depth layer and the \c layer
647d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace * parameter used.
648d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace */
6492995bf0d68f1b28ba68b81e9dc79e3ab52bc2795Xiang, Haihaovoid
6502d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholtintel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
651d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace			       GLuint level, GLuint face, GLuint layer,
6522d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt			       GLuint *x, GLuint *y)
65377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
654d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   int slice;
655d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace
656d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   if (face > 0) {
657d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      assert(mt->target == GL_TEXTURE_CUBE_MAP);
658d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      assert(face < 6);
659d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      assert(layer == 0);
660d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      slice = face;
661d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   } else {
662d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      /* This branch may be taken even if the texture target is a cube map. In
663d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace       * that case, the caller chose to interpret each cube face as a layer.
664d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace       */
665d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      assert(face == 0);
666d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace      slice = layer;
6672d17dbfb5346b6d75e87c839148cbe125bf5cd6dEric Anholt   }
668d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace
669d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   *x = mt->level[level].slice[slice].x_offset;
670d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   *y = mt->level[level].slice[slice].y_offset;
67177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
67277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
673278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versacestatic void
674278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versaceintel_miptree_copy_slice(struct intel_context *intel,
675278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			 struct intel_mipmap_tree *dst_mt,
676278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			 struct intel_mipmap_tree *src_mt,
677278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			 int level,
678278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			 int face,
679278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			 int depth)
680278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
681278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace{
682278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   gl_format format = src_mt->format;
683278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   uint32_t width = src_mt->level[level].width;
684278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   uint32_t height = src_mt->level[level].height;
685278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
686278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   assert(depth < src_mt->level[level].depth);
687278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
688278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   if (dst_mt->compressed) {
689017c13d55b5b086774d6afea2ca754482c624c6aChad Versace      height = ALIGN(height, dst_mt->align_h) / dst_mt->align_h;
690017c13d55b5b086774d6afea2ca754482c624c6aChad Versace      width = ALIGN(width, dst_mt->align_w);
691278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   }
692278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
693278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   uint32_t dst_x, dst_y, src_x, src_y;
694278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   intel_miptree_get_image_offset(dst_mt, level, face, depth,
695278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace				  &dst_x, &dst_y);
696278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   intel_miptree_get_image_offset(src_mt, level, face, depth,
697278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace				  &src_x, &src_y);
698278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
699278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   DBG("validate blit mt %p %d,%d/%d -> mt %p %d,%d/%d (%dx%d)\n",
700278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace       src_mt, src_x, src_y, src_mt->region->pitch * src_mt->region->cpp,
701278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace       dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp,
702278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace       width, height);
703278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
704278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   if (!intelEmitCopyBlit(intel,
705278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  dst_mt->region->cpp,
706278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  src_mt->region->pitch, src_mt->region->bo,
707278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  0, src_mt->region->tiling,
708278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  dst_mt->region->pitch, dst_mt->region->bo,
709278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  0, dst_mt->region->tiling,
710278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  src_x, src_y,
711278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  dst_x, dst_y,
712278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  width, height,
713278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace			  GL_COPY)) {
714278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
715278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      fallback_debug("miptree validate blit for %s failed\n",
716278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		     _mesa_get_format_name(format));
717278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      void *dst = intel_region_map(intel, dst_mt->region, GL_MAP_WRITE_BIT);
718278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      void *src = intel_region_map(intel, src_mt->region, GL_MAP_READ_BIT);
719278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
720278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      _mesa_copy_rect(dst,
721278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      dst_mt->cpp,
722278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      dst_mt->region->pitch,
723278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      dst_x, dst_y,
724278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      width, height,
725278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      src, src_mt->region->pitch,
726278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace		      src_x, src_y);
727278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
728278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      intel_region_unmap(intel, dst_mt->region);
729278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      intel_region_unmap(intel, src_mt->region);
730278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   }
7313eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace
7323eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace   if (src_mt->stencil_mt) {
7333eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace      intel_miptree_copy_slice(intel,
7343eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                               dst_mt->stencil_mt, src_mt->stencil_mt,
7353eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace                               level, face, depth);
7363eb12dfaeed03f77e31943eea164acb03e86bbc9Chad Versace   }
737278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace}
738278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
73977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
740b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt * Copies the image's current data to the given miptree, and associates that
741b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt * miptree with the image.
74277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
74377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
744b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholtintel_miptree_copy_teximage(struct intel_context *intel,
745b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt			    struct intel_texture_image *intelImage,
746b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt			    struct intel_mipmap_tree *dst_mt)
74777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
748b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt   struct intel_mipmap_tree *src_mt = intelImage->mt;
749b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt   int level = intelImage->base.Base.Level;
750b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt   int face = intelImage->base.Base.Face;
751d7b33309fe160212f2eb73f471f3aedcb5d0b5c1Chad Versace   GLuint depth = intelImage->base.Base.Depth;
752b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt
753278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace   for (int slice = 0; slice < depth; slice++) {
754278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace      intel_miptree_copy_slice(intel, dst_mt, src_mt, level, face, slice);
75577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
75677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
757b07c78bfe94c17e6fccba70923b03a29c751fde1Eric Anholt   intel_miptree_reference(&intelImage->mt, dst_mt);
75877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
759278e77a1192d5251c5b70a555e676f72b446e8e1Chad Versace
760a2e44b0813e956440c451c107cf5564b56cbe98eChad Versacebool
761ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berryintel_miptree_alloc_mcs(struct intel_context *intel,
762ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                        struct intel_mipmap_tree *mt,
763ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                        GLuint num_samples)
764ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry{
765ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   assert(mt->mcs_mt == NULL);
766ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   assert(intel->gen >= 7); /* MCS only used on Gen7+ */
767728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry
768728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   /* Choose the correct format for the MCS buffer.  All that really matters
769728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry    * is that we allocate the right buffer size, since we'll always be
770728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry    * accessing this miptree using MCS-specific hardware mechanisms, which
771728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry    * infer the correct format based on num_samples.
772728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry    */
773728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   gl_format format;
774728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   switch (num_samples) {
775728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   case 4:
776728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      /* 8 bits/pixel are required for MCS data when using 4x MSAA (2 bits for
777728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry       * each sample).
778728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry       */
779ee9f6a34ccf7f51111b21bba8d8f9d03cc0a2c74Paul Berry      format = MESA_FORMAT_R8;
780728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      break;
781728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   case 8:
782728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      /* 32 bits/pixel are required for MCS data when using 8x MSAA (3 bits
783728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry       * for each sample, plus 8 padding bits).
784728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry       */
785728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      format = MESA_FORMAT_R_UINT32;
786728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      break;
787728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   default:
788728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      assert(!"Unrecognized sample count in intel_miptree_alloc_mcs");
789728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry      break;
790728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry   };
791ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
792ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   /* From the Ivy Bridge PRM, Vol4 Part1 p76, "MCS Base Address":
793ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
794ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *     "The MCS surface must be stored as Tile Y."
795ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
796ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * We set msaa_format to INTEL_MSAA_LAYOUT_CMS to force
797ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * intel_miptree_create() to use Y tiling.  msaa_format is otherwise
798ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * ignored for the MCS miptree.
799ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    */
800ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   mt->mcs_mt = intel_miptree_create(intel,
801ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->target,
802728561271303baa6aaeb5bdd953e62b117feba4dPaul Berry                                     format,
803ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->first_level,
804ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->last_level,
805ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->width0,
806ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->height0,
807ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     mt->depth0,
808ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     true,
809ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     0 /* num_samples */,
810ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry                                     INTEL_MSAA_LAYOUT_CMS);
811ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
812ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   /* From the Ivy Bridge PRM, Vol 2 Part 1 p326:
813ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
814ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *     When MCS buffer is enabled and bound to MSRT, it is required that it
815ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *     is cleared prior to any rendering.
816ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
817ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * Since we don't use the MCS buffer for any purpose other than rendering,
818ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * it makes sense to just clear it immediately upon allocation.
819ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    *
820ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    * Note: the clear value for MCS buffers is all 1's, so we memset to 0xff.
821ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry    */
822ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   void *data = intel_region_map(intel, mt->mcs_mt->region, 0);
823ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   memset(data, 0xff, mt->mcs_mt->region->bo->size);
824ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   intel_region_unmap(intel, mt->mcs_mt->region);
825ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
826ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry   return mt->mcs_mt;
827ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry}
828ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berry
829ccae1b1cd7b89102a9d9bfc29eb1e7e48aad8969Paul Berrybool
830a2e44b0813e956440c451c107cf5564b56cbe98eChad Versaceintel_miptree_alloc_hiz(struct intel_context *intel,
83119e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry			struct intel_mipmap_tree *mt,
83219e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                        GLuint num_samples)
833a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace{
834a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace   assert(mt->hiz_mt == NULL);
8351bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry   /* MSAA HiZ surfaces always use IMS layout. */
836a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace   mt->hiz_mt = intel_miptree_create(intel,
837a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->target,
838a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     MESA_FORMAT_X8_Z24,
839a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->first_level,
840a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->last_level,
841a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->width0,
842a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->height0,
843a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace                                     mt->depth0,
84419e9b24626c2b9d7abef054d57bb2a52106c545bPaul Berry                                     true,
845455ac562722f60ac9fb0c3d3c697fa339fa011adPaul Berry                                     num_samples,
8461bd4d456cdecf7bea55f4e3dac574af54efad994Paul Berry                                     INTEL_MSAA_LAYOUT_IMS);
8473d760664e6349c72624aa6d54d40df0233995c8eChad Versace
8483d760664e6349c72624aa6d54d40df0233995c8eChad Versace   if (!mt->hiz_mt)
8493d760664e6349c72624aa6d54d40df0233995c8eChad Versace      return false;
8503d760664e6349c72624aa6d54d40df0233995c8eChad Versace
8513d760664e6349c72624aa6d54d40df0233995c8eChad Versace   /* Mark that all slices need a HiZ resolve. */
8523d760664e6349c72624aa6d54d40df0233995c8eChad Versace   struct intel_resolve_map *head = &mt->hiz_map;
8533d760664e6349c72624aa6d54d40df0233995c8eChad Versace   for (int level = mt->first_level; level <= mt->last_level; ++level) {
8543d760664e6349c72624aa6d54d40df0233995c8eChad Versace      for (int layer = 0; layer < mt->level[level].depth; ++layer) {
8553d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head->next = malloc(sizeof(*head->next));
8563d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head->next->prev = head;
8573d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head->next->next = NULL;
8583d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head = head->next;
8593d760664e6349c72624aa6d54d40df0233995c8eChad Versace
8603d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head->level = level;
8613d760664e6349c72624aa6d54d40df0233995c8eChad Versace	 head->layer = layer;
862072634da4a6ee5eafb5f5df26ca5f988209e6d40Eric Anholt	 head->need = GEN6_HIZ_OP_HIZ_RESOLVE;
8633d760664e6349c72624aa6d54d40df0233995c8eChad Versace      }
8643d760664e6349c72624aa6d54d40df0233995c8eChad Versace   }
8653d760664e6349c72624aa6d54d40df0233995c8eChad Versace
8663d760664e6349c72624aa6d54d40df0233995c8eChad Versace   return true;
867a2e44b0813e956440c451c107cf5564b56cbe98eChad Versace}
8682945abea338031cbe90665df60152982bfca6177Chad Versace
8692945abea338031cbe90665df60152982bfca6177Chad Versacevoid
8702945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_hiz_resolve(struct intel_mipmap_tree *mt,
8712945abea338031cbe90665df60152982bfca6177Chad Versace					  uint32_t level,
8722945abea338031cbe90665df60152982bfca6177Chad Versace					  uint32_t layer)
8732945abea338031cbe90665df60152982bfca6177Chad Versace{
8742945abea338031cbe90665df60152982bfca6177Chad Versace   intel_miptree_check_level_layer(mt, level, layer);
8752945abea338031cbe90665df60152982bfca6177Chad Versace
8762945abea338031cbe90665df60152982bfca6177Chad Versace   if (!mt->hiz_mt)
8772945abea338031cbe90665df60152982bfca6177Chad Versace      return;
8782945abea338031cbe90665df60152982bfca6177Chad Versace
8792945abea338031cbe90665df60152982bfca6177Chad Versace   intel_resolve_map_set(&mt->hiz_map,
880072634da4a6ee5eafb5f5df26ca5f988209e6d40Eric Anholt			 level, layer, GEN6_HIZ_OP_HIZ_RESOLVE);
8812945abea338031cbe90665df60152982bfca6177Chad Versace}
8822945abea338031cbe90665df60152982bfca6177Chad Versace
8832945abea338031cbe90665df60152982bfca6177Chad Versace
8842945abea338031cbe90665df60152982bfca6177Chad Versacevoid
8852945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_set_needs_depth_resolve(struct intel_mipmap_tree *mt,
8862945abea338031cbe90665df60152982bfca6177Chad Versace                                            uint32_t level,
8872945abea338031cbe90665df60152982bfca6177Chad Versace                                            uint32_t layer)
8882945abea338031cbe90665df60152982bfca6177Chad Versace{
8892945abea338031cbe90665df60152982bfca6177Chad Versace   intel_miptree_check_level_layer(mt, level, layer);
8902945abea338031cbe90665df60152982bfca6177Chad Versace
8912945abea338031cbe90665df60152982bfca6177Chad Versace   if (!mt->hiz_mt)
8922945abea338031cbe90665df60152982bfca6177Chad Versace      return;
8932945abea338031cbe90665df60152982bfca6177Chad Versace
8942945abea338031cbe90665df60152982bfca6177Chad Versace   intel_resolve_map_set(&mt->hiz_map,
895072634da4a6ee5eafb5f5df26ca5f988209e6d40Eric Anholt			 level, layer, GEN6_HIZ_OP_DEPTH_RESOLVE);
8962945abea338031cbe90665df60152982bfca6177Chad Versace}
8972945abea338031cbe90665df60152982bfca6177Chad Versace
8982945abea338031cbe90665df60152982bfca6177Chad Versacestatic bool
8992945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve(struct intel_context *intel,
9002945abea338031cbe90665df60152982bfca6177Chad Versace			    struct intel_mipmap_tree *mt,
9012945abea338031cbe90665df60152982bfca6177Chad Versace			    uint32_t level,
9022945abea338031cbe90665df60152982bfca6177Chad Versace			    uint32_t layer,
90354308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt			    enum gen6_hiz_op need)
9042945abea338031cbe90665df60152982bfca6177Chad Versace{
9052945abea338031cbe90665df60152982bfca6177Chad Versace   intel_miptree_check_level_layer(mt, level, layer);
9062945abea338031cbe90665df60152982bfca6177Chad Versace
9072945abea338031cbe90665df60152982bfca6177Chad Versace   struct intel_resolve_map *item =
9082945abea338031cbe90665df60152982bfca6177Chad Versace	 intel_resolve_map_get(&mt->hiz_map, level, layer);
9092945abea338031cbe90665df60152982bfca6177Chad Versace
9102945abea338031cbe90665df60152982bfca6177Chad Versace   if (!item || item->need != need)
9112945abea338031cbe90665df60152982bfca6177Chad Versace      return false;
9122945abea338031cbe90665df60152982bfca6177Chad Versace
91354308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt   intel_hiz_exec(intel, mt, level, layer, need);
9142945abea338031cbe90665df60152982bfca6177Chad Versace   intel_resolve_map_remove(item);
9152945abea338031cbe90665df60152982bfca6177Chad Versace   return true;
9162945abea338031cbe90665df60152982bfca6177Chad Versace}
9172945abea338031cbe90665df60152982bfca6177Chad Versace
9182945abea338031cbe90665df60152982bfca6177Chad Versacebool
9192945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_hiz(struct intel_context *intel,
9202945abea338031cbe90665df60152982bfca6177Chad Versace				struct intel_mipmap_tree *mt,
9212945abea338031cbe90665df60152982bfca6177Chad Versace				uint32_t level,
9222945abea338031cbe90665df60152982bfca6177Chad Versace				uint32_t layer)
9232945abea338031cbe90665df60152982bfca6177Chad Versace{
9242945abea338031cbe90665df60152982bfca6177Chad Versace   return intel_miptree_slice_resolve(intel, mt, level, layer,
92554308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt				      GEN6_HIZ_OP_HIZ_RESOLVE);
9262945abea338031cbe90665df60152982bfca6177Chad Versace}
9272945abea338031cbe90665df60152982bfca6177Chad Versace
9282945abea338031cbe90665df60152982bfca6177Chad Versacebool
9292945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_slice_resolve_depth(struct intel_context *intel,
9302945abea338031cbe90665df60152982bfca6177Chad Versace				  struct intel_mipmap_tree *mt,
9312945abea338031cbe90665df60152982bfca6177Chad Versace				  uint32_t level,
9322945abea338031cbe90665df60152982bfca6177Chad Versace				  uint32_t layer)
9332945abea338031cbe90665df60152982bfca6177Chad Versace{
9342945abea338031cbe90665df60152982bfca6177Chad Versace   return intel_miptree_slice_resolve(intel, mt, level, layer,
93554308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt				      GEN6_HIZ_OP_DEPTH_RESOLVE);
9362945abea338031cbe90665df60152982bfca6177Chad Versace}
9372945abea338031cbe90665df60152982bfca6177Chad Versace
9382945abea338031cbe90665df60152982bfca6177Chad Versacestatic bool
9392945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve(struct intel_context *intel,
9402945abea338031cbe90665df60152982bfca6177Chad Versace				 struct intel_mipmap_tree *mt,
94154308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt				 enum gen6_hiz_op need)
9422945abea338031cbe90665df60152982bfca6177Chad Versace{
9432945abea338031cbe90665df60152982bfca6177Chad Versace   bool did_resolve = false;
9440ed11e333147e280208d9d0b3ff3f39970547643Anuj Phogat   struct intel_resolve_map *i, *next;
9452945abea338031cbe90665df60152982bfca6177Chad Versace
9460ed11e333147e280208d9d0b3ff3f39970547643Anuj Phogat   for (i = mt->hiz_map.next; i; i = next) {
947a0a0a909f21acfcddaab603079ba98266e8daf0eKenneth Graunke      next = i->next;
9482945abea338031cbe90665df60152982bfca6177Chad Versace      if (i->need != need)
9492945abea338031cbe90665df60152982bfca6177Chad Versace	 continue;
95054308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt
95154308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt      intel_hiz_exec(intel, mt, i->level, i->layer, need);
9522945abea338031cbe90665df60152982bfca6177Chad Versace      intel_resolve_map_remove(i);
9532945abea338031cbe90665df60152982bfca6177Chad Versace      did_resolve = true;
9542945abea338031cbe90665df60152982bfca6177Chad Versace   }
9552945abea338031cbe90665df60152982bfca6177Chad Versace
9562945abea338031cbe90665df60152982bfca6177Chad Versace   return did_resolve;
9572945abea338031cbe90665df60152982bfca6177Chad Versace}
9582945abea338031cbe90665df60152982bfca6177Chad Versace
9592945abea338031cbe90665df60152982bfca6177Chad Versacebool
9602945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_hiz(struct intel_context *intel,
9612945abea338031cbe90665df60152982bfca6177Chad Versace				     struct intel_mipmap_tree *mt)
9622945abea338031cbe90665df60152982bfca6177Chad Versace{
9632945abea338031cbe90665df60152982bfca6177Chad Versace   return intel_miptree_all_slices_resolve(intel, mt,
96454308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt					   GEN6_HIZ_OP_HIZ_RESOLVE);
9652945abea338031cbe90665df60152982bfca6177Chad Versace}
9662945abea338031cbe90665df60152982bfca6177Chad Versace
9672945abea338031cbe90665df60152982bfca6177Chad Versacebool
9682945abea338031cbe90665df60152982bfca6177Chad Versaceintel_miptree_all_slices_resolve_depth(struct intel_context *intel,
9692945abea338031cbe90665df60152982bfca6177Chad Versace				       struct intel_mipmap_tree *mt)
9702945abea338031cbe90665df60152982bfca6177Chad Versace{
9712945abea338031cbe90665df60152982bfca6177Chad Versace   return intel_miptree_all_slices_resolve(intel, mt,
97254308f78a2f8675bfd854761f9cd8a6b71e119d0Eric Anholt					   GEN6_HIZ_OP_DEPTH_RESOLVE);
9732945abea338031cbe90665df60152982bfca6177Chad Versace}
974b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
975d3746354fbfadf821dc108e072d86b5329737444Chad Versacestatic void
976d3746354fbfadf821dc108e072d86b5329737444Chad Versaceintel_miptree_updownsample(struct intel_context *intel,
977d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           struct intel_mipmap_tree *src,
978d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           struct intel_mipmap_tree *dst,
979d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           unsigned width,
980d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           unsigned height)
981d3746354fbfadf821dc108e072d86b5329737444Chad Versace{
982d3746354fbfadf821dc108e072d86b5329737444Chad Versace#ifndef I915
983d3746354fbfadf821dc108e072d86b5329737444Chad Versace   int src_x0 = 0;
984d3746354fbfadf821dc108e072d86b5329737444Chad Versace   int src_y0 = 0;
985d3746354fbfadf821dc108e072d86b5329737444Chad Versace   int dst_x0 = 0;
986d3746354fbfadf821dc108e072d86b5329737444Chad Versace   int dst_y0 = 0;
987d3746354fbfadf821dc108e072d86b5329737444Chad Versace
988d3746354fbfadf821dc108e072d86b5329737444Chad Versace   intel_miptree_slice_resolve_depth(intel, src, 0, 0);
989d3746354fbfadf821dc108e072d86b5329737444Chad Versace   intel_miptree_slice_resolve_depth(intel, dst, 0, 0);
990d3746354fbfadf821dc108e072d86b5329737444Chad Versace
991d3746354fbfadf821dc108e072d86b5329737444Chad Versace   brw_blorp_blit_miptrees(intel,
992e87174cf4b499c8e9558438e70b0da5f0f38f54aPaul Berry                           src, 0 /* level */, 0 /* layer */,
993e87174cf4b499c8e9558438e70b0da5f0f38f54aPaul Berry                           dst, 0 /* level */, 0 /* layer */,
994d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           src_x0, src_y0,
995d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           dst_x0, dst_y0,
996d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           width, height,
997d3746354fbfadf821dc108e072d86b5329737444Chad Versace                           false, false /*mirror x, y*/);
998d3746354fbfadf821dc108e072d86b5329737444Chad Versace
999d3746354fbfadf821dc108e072d86b5329737444Chad Versace   if (src->stencil_mt) {
1000d3746354fbfadf821dc108e072d86b5329737444Chad Versace      brw_blorp_blit_miptrees(intel,
1001e87174cf4b499c8e9558438e70b0da5f0f38f54aPaul Berry                              src->stencil_mt, 0 /* level */, 0 /* layer */,
1002e87174cf4b499c8e9558438e70b0da5f0f38f54aPaul Berry                              dst->stencil_mt, 0 /* level */, 0 /* layer */,
1003d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              src_x0, src_y0,
1004d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              dst_x0, dst_y0,
1005d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              width, height,
1006d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              false, false /*mirror x, y*/);
1007d3746354fbfadf821dc108e072d86b5329737444Chad Versace   }
1008d3746354fbfadf821dc108e072d86b5329737444Chad Versace#endif /* I915 */
1009d3746354fbfadf821dc108e072d86b5329737444Chad Versace}
1010d3746354fbfadf821dc108e072d86b5329737444Chad Versace
1011d3746354fbfadf821dc108e072d86b5329737444Chad Versacestatic void
1012d3746354fbfadf821dc108e072d86b5329737444Chad Versaceassert_is_flat(struct intel_mipmap_tree *mt)
1013d3746354fbfadf821dc108e072d86b5329737444Chad Versace{
1014d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert(mt->target == GL_TEXTURE_2D);
1015d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert(mt->first_level == 0);
1016d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert(mt->last_level == 0);
1017d3746354fbfadf821dc108e072d86b5329737444Chad Versace}
1018d3746354fbfadf821dc108e072d86b5329737444Chad Versace
1019f4873babdc27f697df9f4642209eca21a02ac476Chad Versace/**
1020f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * \brief Downsample from mt to mt->singlesample_mt.
1021f4873babdc27f697df9f4642209eca21a02ac476Chad Versace *
1022f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * If the miptree needs no downsample, then skip.
1023f4873babdc27f697df9f4642209eca21a02ac476Chad Versace */
1024f4873babdc27f697df9f4642209eca21a02ac476Chad Versacevoid
1025f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_downsample(struct intel_context *intel,
1026f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                         struct intel_mipmap_tree *mt)
1027f4873babdc27f697df9f4642209eca21a02ac476Chad Versace{
1028d3746354fbfadf821dc108e072d86b5329737444Chad Versace   /* Only flat, renderbuffer-like miptrees are supported. */
1029d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert_is_flat(mt);
1030d3746354fbfadf821dc108e072d86b5329737444Chad Versace
1031d3746354fbfadf821dc108e072d86b5329737444Chad Versace   if (!mt->need_downsample)
1032d3746354fbfadf821dc108e072d86b5329737444Chad Versace      return;
1033d3746354fbfadf821dc108e072d86b5329737444Chad Versace   intel_miptree_updownsample(intel,
1034d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt, mt->singlesample_mt,
1035d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt->singlesample_mt->width0,
1036d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt->singlesample_mt->height0);
1037d3746354fbfadf821dc108e072d86b5329737444Chad Versace   mt->need_downsample = false;
1038d3746354fbfadf821dc108e072d86b5329737444Chad Versace
1039d3746354fbfadf821dc108e072d86b5329737444Chad Versace   /* Strictly speaking, after a downsample on a depth miptree, a hiz
1040d3746354fbfadf821dc108e072d86b5329737444Chad Versace    * resolve is needed on the singlesample miptree. However, since the
1041d3746354fbfadf821dc108e072d86b5329737444Chad Versace    * singlesample miptree is never rendered to, the hiz resolve will never
1042d3746354fbfadf821dc108e072d86b5329737444Chad Versace    * occur. Therefore we do not mark the needed hiz resolve after
1043d3746354fbfadf821dc108e072d86b5329737444Chad Versace    * downsampling.
1044d3746354fbfadf821dc108e072d86b5329737444Chad Versace    */
1045f4873babdc27f697df9f4642209eca21a02ac476Chad Versace}
1046f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
1047f4873babdc27f697df9f4642209eca21a02ac476Chad Versace/**
1048f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * \brief Upsample from mt->singlesample_mt to mt.
1049f4873babdc27f697df9f4642209eca21a02ac476Chad Versace *
1050f4873babdc27f697df9f4642209eca21a02ac476Chad Versace * The upsample is done unconditionally.
1051f4873babdc27f697df9f4642209eca21a02ac476Chad Versace */
1052f4873babdc27f697df9f4642209eca21a02ac476Chad Versacevoid
1053f4873babdc27f697df9f4642209eca21a02ac476Chad Versaceintel_miptree_upsample(struct intel_context *intel,
1054f4873babdc27f697df9f4642209eca21a02ac476Chad Versace                       struct intel_mipmap_tree *mt)
1055f4873babdc27f697df9f4642209eca21a02ac476Chad Versace{
1056d3746354fbfadf821dc108e072d86b5329737444Chad Versace   /* Only flat, renderbuffer-like miptrees are supported. */
1057d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert_is_flat(mt);
1058d3746354fbfadf821dc108e072d86b5329737444Chad Versace   assert(!mt->need_downsample);
1059d3746354fbfadf821dc108e072d86b5329737444Chad Versace
1060d3746354fbfadf821dc108e072d86b5329737444Chad Versace   intel_miptree_updownsample(intel,
1061d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt->singlesample_mt, mt,
1062d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt->singlesample_mt->width0,
1063d3746354fbfadf821dc108e072d86b5329737444Chad Versace                              mt->singlesample_mt->height0);
1064d3746354fbfadf821dc108e072d86b5329737444Chad Versace   intel_miptree_slice_set_needs_hiz_resolve(mt, 0, 0);
1065f4873babdc27f697df9f4642209eca21a02ac476Chad Versace}
1066f4873babdc27f697df9f4642209eca21a02ac476Chad Versace
1067baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtstatic void
1068baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtintel_miptree_map_gtt(struct intel_context *intel,
1069baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt		      struct intel_mipmap_tree *mt,
1070baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt		      struct intel_miptree_map *map,
1071baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt		      unsigned int level, unsigned int slice)
1072b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt{
1073b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   unsigned int bw, bh;
1074b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   void *base;
1075b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   unsigned int image_x, image_y;
1076baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   int x = map->x;
1077baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   int y = map->y;
1078221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
1079b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   /* For compressed formats, the stride is the number of bytes per
1080b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt    * row of blocks.  intel_miptree_get_image_offset() already does
1081b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt    * the divide.
1082b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt    */
1083b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   _mesa_get_format_block_size(mt->format, &bw, &bh);
1084b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   assert(y % bh == 0);
1085b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   y /= bh;
1086b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
1087baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   base = intel_region_map(intel, mt->region, map->mode);
1088b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
1089cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat   if (base == NULL)
1090cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      map->ptr = NULL;
1091cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat   else {
1092cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      /* Note that in the case of cube maps, the caller must have passed the
1093cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat       * slice number referencing the face.
1094cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      */
1095cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
1096cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      x += image_x;
1097cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      y += image_y;
1098cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat
1099cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      map->stride = mt->region->pitch * mt->cpp;
1100cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat      map->ptr = base + y * map->stride + x * mt->cpp;
1101cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat   }
1102221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
1103b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__,
1104221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt       map->x, map->y, map->w, map->h,
1105b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt       mt, _mesa_get_format_name(mt->format),
1106221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt       x, y, map->ptr, map->stride);
1107b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt}
1108b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
1109baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtstatic void
1110baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholtintel_miptree_unmap_gtt(struct intel_context *intel,
1111baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt			struct intel_mipmap_tree *mt,
1112baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt			struct intel_miptree_map *map,
1113baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt			unsigned int level,
1114baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt			unsigned int slice)
1115baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt{
1116baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   intel_region_unmap(intel, mt->region);
1117baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt}
1118baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
1119b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtstatic void
11205655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtintel_miptree_map_blit(struct intel_context *intel,
11215655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt		       struct intel_mipmap_tree *mt,
11225655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt		       struct intel_miptree_map *map,
11235655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt		       unsigned int level, unsigned int slice)
11245655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt{
11255655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   unsigned int image_x, image_y;
11265655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   int x = map->x;
11275655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   int y = map->y;
11285655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   int ret;
11295655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11305655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   /* The blitter requires the pitch to be aligned to 4. */
11315655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   map->stride = ALIGN(map->w * mt->region->cpp, 4);
11325655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11335655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   map->bo = drm_intel_bo_alloc(intel->bufmgr, "intel_miptree_map_blit() temp",
11345655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt				map->stride * map->h, 4096);
11355655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   if (!map->bo) {
11365655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      fprintf(stderr, "Failed to allocate blit temporary\n");
11375655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      goto fail;
11385655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   }
11395655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11405655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
11415655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   x += image_x;
11425655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   y += image_y;
11435655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11445655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   if (!intelEmitCopyBlit(intel,
11455655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  mt->region->cpp,
11465655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  mt->region->pitch, mt->region->bo,
11475655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  0, mt->region->tiling,
11485655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  map->stride / mt->region->cpp, map->bo,
11495655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  0, I915_TILING_NONE,
11505655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  x, y,
11515655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  0, 0,
11525655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  map->w, map->h,
11535655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			  GL_COPY)) {
11545655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      fprintf(stderr, "Failed to blit\n");
11555655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      goto fail;
11565655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   }
11575655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11585655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   intel_batchbuffer_flush(intel);
11595655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   ret = drm_intel_bo_map(map->bo, (map->mode & GL_MAP_WRITE_BIT) != 0);
11605655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   if (ret) {
11615655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      fprintf(stderr, "Failed to map blit temporary\n");
11625655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      goto fail;
11635655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   }
11645655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11655655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   map->ptr = map->bo->virtual;
11665655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11675655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__,
11685655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt       map->x, map->y, map->w, map->h,
11695655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt       mt, _mesa_get_format_name(mt->format),
11705655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt       x, y, map->ptr, map->stride);
11715655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11725655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   return;
11735655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11745655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtfail:
11755655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   drm_intel_bo_unreference(map->bo);
11765655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   map->ptr = NULL;
11775655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   map->stride = 0;
11785655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt}
11795655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11805655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtstatic void
11815655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtintel_miptree_unmap_blit(struct intel_context *intel,
11825655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			 struct intel_mipmap_tree *mt,
11835655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			 struct intel_miptree_map *map,
11845655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			 unsigned int level,
11855655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt			 unsigned int slice)
11865655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt{
11875655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   assert(!(map->mode & GL_MAP_WRITE_BIT));
11885655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11895655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   drm_intel_bo_unmap(map->bo);
11905655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   drm_intel_bo_unreference(map->bo);
11915655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt}
11925655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt
11935655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholtstatic void
1194b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtintel_miptree_map_s8(struct intel_context *intel,
1195b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		     struct intel_mipmap_tree *mt,
1196b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		     struct intel_miptree_map *map,
1197b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		     unsigned int level, unsigned int slice)
1198b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt{
1199b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   map->stride = map->w;
1200b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   map->buffer = map->ptr = malloc(map->stride * map->h);
1201b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   if (!map->buffer)
1202b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      return;
1203b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1204b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   /* One of either READ_BIT or WRITE_BIT or both is set.  READ_BIT implies no
1205b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt    * INVALIDATE_RANGE_BIT.  WRITE_BIT needs the original values read in unless
1206b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt    * invalidate is set, since we'll be writing the whole rectangle from our
1207b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt    * temporary buffer back out.
1208b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt    */
1209b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {
1210b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      uint8_t *untiled_s8_map = map->ptr;
1211b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      uint8_t *tiled_s8_map = intel_region_map(intel, mt->region,
1212b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt					       GL_MAP_READ_BIT);
1213b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      unsigned int image_x, image_y;
1214b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1215b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
1216b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1217b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      for (uint32_t y = 0; y < map->h; y++) {
1218b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	 for (uint32_t x = 0; x < map->w; x++) {
1219b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	    ptrdiff_t offset = intel_offset_S8(mt->region->pitch,
1220b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	                                       x + image_x + map->x,
1221f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter	                                       y + image_y + map->y,
1222f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter					       intel->has_swizzling);
1223b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	    untiled_s8_map[y * map->w + x] = tiled_s8_map[offset];
1224b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	 }
1225b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      }
1226b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1227b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_region_unmap(intel, mt->region);
1228b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1229b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      DBG("%s: %d,%d %dx%d from mt %p %d,%d = %p/%d\n", __FUNCTION__,
1230b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	  map->x, map->y, map->w, map->h,
1231b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	  mt, map->x + image_x, map->y + image_y, map->ptr, map->stride);
1232b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   } else {
1233b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__,
1234b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	  map->x, map->y, map->w, map->h,
1235b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	  mt, map->ptr, map->stride);
1236b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   }
1237b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt}
1238b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1239b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtstatic void
1240b48c3bca87b30003f9e117d299011380e743aec9Eric Anholtintel_miptree_unmap_s8(struct intel_context *intel,
1241b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		       struct intel_mipmap_tree *mt,
1242b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		       struct intel_miptree_map *map,
1243b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		       unsigned int level,
1244b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt		       unsigned int slice)
1245b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt{
1246b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   if (map->mode & GL_MAP_WRITE_BIT) {
1247b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      unsigned int image_x, image_y;
1248b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      uint8_t *untiled_s8_map = map->ptr;
1249b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      uint8_t *tiled_s8_map = intel_region_map(intel, mt->region, map->mode);
1250b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1251b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
1252b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1253b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      for (uint32_t y = 0; y < map->h; y++) {
1254b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	 for (uint32_t x = 0; x < map->w; x++) {
1255b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	    ptrdiff_t offset = intel_offset_S8(mt->region->pitch,
1256b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	                                       x + map->x,
1257f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter	                                       y + map->y,
1258f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter					       intel->has_swizzling);
1259b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	    tiled_s8_map[offset] = untiled_s8_map[y * map->w + x];
1260b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt	 }
1261b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      }
1262b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1263b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_region_unmap(intel, mt->region);
1264b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   }
1265b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1266b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   free(map->buffer);
1267b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt}
1268b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt
1269a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versacestatic void
1270a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versaceintel_miptree_map_etc1(struct intel_context *intel,
1271a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                       struct intel_mipmap_tree *mt,
1272a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                       struct intel_miptree_map *map,
1273a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                       unsigned int level,
1274a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                       unsigned int slice)
1275a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace{
1276a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   /* For justification of these invariants,
1277a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    * see intel_mipmap_tree:wraps_etc1.
1278a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    */
1279a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(mt->wraps_etc1);
1280a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(mt->format == MESA_FORMAT_RGBX8888_REV);
1281a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1282a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   /* From the GL_OES_compressed_ETC1_RGB8_texture spec:
1283a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    *   INVALID_OPERATION is generated by CompressedTexSubImage2D,
1284a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    *   TexSubImage2D, or CopyTexSubImage2D if the texture image <level>
1285a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    *   bound to <target> has internal format ETC1_RGB8_OES.
1286a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    *
1287a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    * This implies that intel_miptree_map_etc1() can only be called from
1288a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    * glCompressedTexImage2D, and hence the assertions below hold.
1289a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace    */
1290a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(map->mode & GL_MAP_WRITE_BIT);
1291a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(map->mode & GL_MAP_INVALIDATE_RANGE_BIT);
1292a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(map->x == 0);
1293a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   assert(map->y == 0);
1294a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1295a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   /* Each ETC1 block contains 4x4 pixels in 8 bytes. */
1296a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   map->stride = 2 * map->w;
1297a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   map->buffer = map->ptr = malloc(map->stride * map->h);
1298a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace}
1299a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1300a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versacestatic void
1301a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versaceintel_miptree_unmap_etc1(struct intel_context *intel,
1302a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                         struct intel_mipmap_tree *mt,
1303a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                         struct intel_miptree_map *map,
1304a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                         unsigned int level,
1305a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                         unsigned int slice)
1306a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace{
1307a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   uint32_t image_x;
1308a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   uint32_t image_y;
1309a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
1310a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1311a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   uint8_t *xbgr = intel_region_map(intel, mt->region, map->mode)
1312a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                 + image_y * mt->region->pitch * mt->region->cpp
1313a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                 + image_x * mt->region->cpp;
1314a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1315a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   _mesa_etc1_unpack_rgba8888(xbgr, mt->region->pitch * mt->region->cpp,
1316a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                              map->ptr, map->stride,
1317a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace                              map->w, map->h);
1318a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1319a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   intel_region_unmap(intel, mt->region);
1320a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   free(map->buffer);
1321a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace}
1322a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace
1323ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt/**
1324ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * Mapping function for packed depth/stencil miptrees backed by real separate
1325ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * miptrees for depth and stencil.
1326ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt *
1327ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * On gen7, and to support HiZ pre-gen7, we have to have the stencil buffer
1328ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * separate from the depth buffer.  Yet at the GL API level, we have to expose
1329ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * packed depth/stencil textures and FBO attachments, and Mesa core expects to
1330ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * be able to map that memory for texture storage and glReadPixels-type
1331ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * operations.  We give Mesa core that access by mallocing a temporary and
1332ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt * copying the data between the actual backing store and the temporary.
1333ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt */
1334ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtstatic void
1335ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtintel_miptree_map_depthstencil(struct intel_context *intel,
1336ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt			       struct intel_mipmap_tree *mt,
1337ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt			       struct intel_miptree_map *map,
1338ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt			       unsigned int level, unsigned int slice)
1339ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt{
1340ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   struct intel_mipmap_tree *z_mt = mt;
1341ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   struct intel_mipmap_tree *s_mt = mt->stencil_mt;
1342353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt   bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z32_FLOAT;
1343353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt   int packed_bpp = map_z32f_x24s8 ? 8 : 4;
1344ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1345ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   map->stride = map->w * packed_bpp;
1346ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   map->buffer = map->ptr = malloc(map->stride * map->h);
1347ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   if (!map->buffer)
1348ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      return;
1349ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1350ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   /* One of either READ_BIT or WRITE_BIT or both is set.  READ_BIT implies no
1351ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt    * INVALIDATE_RANGE_BIT.  WRITE_BIT needs the original values read in unless
1352ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt    * invalidate is set, since we'll be writing the whole rectangle from our
1353ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt    * temporary buffer back out.
1354ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt    */
1355ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   if (!(map->mode & GL_MAP_INVALIDATE_RANGE_BIT)) {
1356ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint32_t *packed_map = map->ptr;
1357ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint8_t *s_map = intel_region_map(intel, s_mt->region, GL_MAP_READ_BIT);
1358ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint32_t *z_map = intel_region_map(intel, z_mt->region, GL_MAP_READ_BIT);
1359ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      unsigned int s_image_x, s_image_y;
1360ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      unsigned int z_image_x, z_image_y;
1361ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1362ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_get_image_offset(s_mt, level, 0, slice,
1363ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				     &s_image_x, &s_image_y);
1364ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_get_image_offset(z_mt, level, 0, slice,
1365ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				     &z_image_x, &z_image_y);
1366ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1367ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      for (uint32_t y = 0; y < map->h; y++) {
1368ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	 for (uint32_t x = 0; x < map->w; x++) {
1369ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    int map_x = map->x + x, map_y = map->y + y;
1370ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch,
1371ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt						 map_x + s_image_x,
1372f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter						 map_y + s_image_y,
1373f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter						 intel->has_swizzling);
1374ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    ptrdiff_t z_offset = ((map_y + z_image_y) * z_mt->region->pitch +
1375ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				  (map_x + z_image_x));
1376ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    uint8_t s = s_map[s_offset];
1377ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    uint32_t z = z_map[z_offset];
1378ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1379353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    if (map_z32f_x24s8) {
1380353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       packed_map[(y * map->w + x) * 2 + 0] = z;
1381353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       packed_map[(y * map->w + x) * 2 + 1] = s;
1382353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    } else {
1383353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       packed_map[y * map->w + x] = (s << 24) | (z & 0x00ffffff);
1384353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    }
1385ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	 }
1386ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      }
1387ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1388ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_region_unmap(intel, s_mt->region);
1389ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_region_unmap(intel, z_mt->region);
1390ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1391ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      DBG("%s: %d,%d %dx%d from z mt %p %d,%d, s mt %p %d,%d = %p/%d\n",
1392ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  __FUNCTION__,
1393ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->x, map->y, map->w, map->h,
1394ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  z_mt, map->x + z_image_x, map->y + z_image_y,
1395ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  s_mt, map->x + s_image_x, map->y + s_image_y,
1396ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->ptr, map->stride);
1397ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   } else {
1398ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      DBG("%s: %d,%d %dx%d from mt %p = %p/%d\n", __FUNCTION__,
1399ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->x, map->y, map->w, map->h,
1400ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  mt, map->ptr, map->stride);
1401ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   }
1402ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt}
1403ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1404ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtstatic void
1405ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholtintel_miptree_unmap_depthstencil(struct intel_context *intel,
1406ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				 struct intel_mipmap_tree *mt,
1407ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				 struct intel_miptree_map *map,
1408ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				 unsigned int level,
1409ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				 unsigned int slice)
1410ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt{
1411ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   struct intel_mipmap_tree *z_mt = mt;
1412ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   struct intel_mipmap_tree *s_mt = mt->stencil_mt;
1413353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt   bool map_z32f_x24s8 = mt->format == MESA_FORMAT_Z32_FLOAT;
1414ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1415ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   if (map->mode & GL_MAP_WRITE_BIT) {
1416ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint32_t *packed_map = map->ptr;
1417ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint8_t *s_map = intel_region_map(intel, s_mt->region, map->mode);
1418ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      uint32_t *z_map = intel_region_map(intel, z_mt->region, map->mode);
1419ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      unsigned int s_image_x, s_image_y;
1420ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      unsigned int z_image_x, z_image_y;
1421ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1422ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_get_image_offset(s_mt, level, 0, slice,
1423ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				     &s_image_x, &s_image_y);
1424ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_get_image_offset(z_mt, level, 0, slice,
1425ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				     &z_image_x, &z_image_y);
1426ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1427ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      for (uint32_t y = 0; y < map->h; y++) {
1428ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	 for (uint32_t x = 0; x < map->w; x++) {
1429ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    ptrdiff_t s_offset = intel_offset_S8(s_mt->region->pitch,
1430ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt						 x + s_image_x + map->x,
1431f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter						 y + s_image_y + map->y,
1432f172eae8b23d0612865895c52af745021ae20a4cDaniel Vetter						 intel->has_swizzling);
1433ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	    ptrdiff_t z_offset = ((y + z_image_y) * z_mt->region->pitch +
1434ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt				  (x + z_image_x));
1435ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1436353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    if (map_z32f_x24s8) {
1437353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       z_map[z_offset] = packed_map[(y * map->w + x) * 2 + 0];
1438353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       s_map[s_offset] = packed_map[(y * map->w + x) * 2 + 1];
1439353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    } else {
1440353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       uint32_t packed = packed_map[y * map->w + x];
1441353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       s_map[s_offset] = packed >> 24;
1442353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	       z_map[z_offset] = packed;
1443353f7ba4abbfd15d1e4e4b7a38f88e64ce85f6a2Eric Anholt	    }
1444ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	 }
1445ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      }
1446ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1447ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_region_unmap(intel, s_mt->region);
1448ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_region_unmap(intel, z_mt->region);
1449ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1450ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      DBG("%s: %d,%d %dx%d from z mt %p (%s) %d,%d, s mt %p %d,%d = %p/%d\n",
1451ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  __FUNCTION__,
1452ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->x, map->y, map->w, map->h,
1453ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  z_mt, _mesa_get_format_name(z_mt->format),
1454ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->x + z_image_x, map->y + z_image_y,
1455ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  s_mt, map->x + s_image_x, map->y + s_image_y,
1456ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt	  map->ptr, map->stride);
1457ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   }
1458ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
1459ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   free(map->buffer);
1460ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt}
1461ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt
14624c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace/**
14634c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace * Create and attach a map to the miptree at (level, slice). Return the
14644c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace * attached map.
14654c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace */
14664c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versacestatic struct intel_miptree_map*
14674c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versaceintel_miptree_attach_map(struct intel_mipmap_tree *mt,
14684c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int level,
14694c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int slice,
14704c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int x,
14714c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int y,
14724c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int w,
14734c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int h,
14744c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         GLbitfield mode)
14754c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace{
14764c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   struct intel_miptree_map *map = calloc(1, sizeof(*map));
14774c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
14784c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   if (!map)
14794c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace      return NULL;
14804c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
14814c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   assert(mt->level[level].slice[slice].map == NULL);
14824c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   mt->level[level].slice[slice].map = map;
14834c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
14844c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map->mode = mode;
14854c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map->x = x;
14864c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map->y = y;
14874c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map->w = w;
14884c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map->h = h;
14894c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
14904c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   return map;
14914c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace}
14924c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
14934c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace/**
14944c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace * Release the map at (level, slice).
14954c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace */
14964c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versacestatic void
14974c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versaceintel_miptree_release_map(struct intel_mipmap_tree *mt,
14984c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int level,
14994c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace                         unsigned int slice)
15004c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace{
15014c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   struct intel_miptree_map **map;
15024c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
15034c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map = &mt->level[level].slice[slice].map;
15044c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   free(*map);
15054c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   *map = NULL;
15064c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace}
15074c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace
150881980958d0d3def26741cfe78b7c23f6635f826aChad Versacestatic void
150981980958d0d3def26741cfe78b7c23f6635f826aChad Versaceintel_miptree_map_singlesample(struct intel_context *intel,
151081980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               struct intel_mipmap_tree *mt,
151181980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int level,
151281980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int slice,
151381980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int x,
151481980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int y,
151581980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int w,
151681980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               unsigned int h,
151781980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               GLbitfield mode,
151881980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               void **out_ptr,
151981980958d0d3def26741cfe78b7c23f6635f826aChad Versace                               int *out_stride)
1520baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt{
1521baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   struct intel_miptree_map *map;
1522baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
152381980958d0d3def26741cfe78b7c23f6635f826aChad Versace   assert(mt->num_samples <= 1);
152481980958d0d3def26741cfe78b7c23f6635f826aChad Versace
15254c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   map = intel_miptree_attach_map(mt, level, slice, x, y, w, h, mode);
1526baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   if (!map){
1527baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt      *out_ptr = NULL;
1528baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt      *out_stride = 0;
1529baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt      return;
1530baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   }
1531baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
1532baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   intel_miptree_slice_resolve_depth(intel, mt, level, slice);
1533baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   if (map->mode & GL_MAP_WRITE_BIT) {
1534baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt      intel_miptree_slice_set_needs_hiz_resolve(mt, level, slice);
1535baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   }
1536baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
1537b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   if (mt->format == MESA_FORMAT_S8) {
1538b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_map_s8(intel, mt, map, level, slice);
1539a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   } else if (mt->wraps_etc1) {
1540a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace      intel_miptree_map_etc1(intel, mt, map, level, slice);
1541ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   } else if (mt->stencil_mt) {
1542ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_map_depthstencil(intel, mt, map, level, slice);
154384e5f1c635899c657da58ca51d5e841354e9de9cEugeni Dodonov   } else if (intel->has_llc &&
15445655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt	      !(mode & GL_MAP_WRITE_BIT) &&
15455655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt	      !mt->compressed &&
15465655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt	      mt->region->tiling == I915_TILING_X) {
15475655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      intel_miptree_map_blit(intel, mt, map, level, slice);
1548b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   } else {
1549b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_map_gtt(intel, mt, map, level, slice);
1550b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   }
1551baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
1552baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   *out_ptr = map->ptr;
1553baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt   *out_stride = map->stride;
1554cdcfd5d1d60179e60e3a0a47dda71bfe91083105Anuj Phogat
15554c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   if (map->ptr == NULL)
15564c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace      intel_miptree_release_map(mt, level, slice);
1557baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt}
1558baeaa062e92afbec47fad73fd3d464a1e7d1fe08Eric Anholt
155981980958d0d3def26741cfe78b7c23f6635f826aChad Versacestatic void
156081980958d0d3def26741cfe78b7c23f6635f826aChad Versaceintel_miptree_unmap_singlesample(struct intel_context *intel,
156181980958d0d3def26741cfe78b7c23f6635f826aChad Versace                                 struct intel_mipmap_tree *mt,
156281980958d0d3def26741cfe78b7c23f6635f826aChad Versace                                 unsigned int level,
156381980958d0d3def26741cfe78b7c23f6635f826aChad Versace                                 unsigned int slice)
1564b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt{
1565221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   struct intel_miptree_map *map = mt->level[level].slice[slice].map;
1566221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
156781980958d0d3def26741cfe78b7c23f6635f826aChad Versace   assert(mt->num_samples <= 1);
156881980958d0d3def26741cfe78b7c23f6635f826aChad Versace
1569221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt   if (!map)
1570221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt      return;
1571221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
1572b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt   DBG("%s: mt %p (%s) level %d slice %d\n", __FUNCTION__,
1573b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt       mt, _mesa_get_format_name(mt->format), level, slice);
1574b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt
1575b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   if (mt->format == MESA_FORMAT_S8) {
1576b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_unmap_s8(intel, mt, map, level, slice);
1577a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace   } else if (mt->wraps_etc1) {
1578a5a34b153d494ad4374e7b2c8ea13b1073a887e2Chad Versace      intel_miptree_unmap_etc1(intel, mt, map, level, slice);
1579ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt   } else if (mt->stencil_mt) {
1580ed3aeb56ec3fde24c2fc69515c0b5d348b41caf3Eric Anholt      intel_miptree_unmap_depthstencil(intel, mt, map, level, slice);
15815655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt   } else if (map->bo) {
15825655ebf4664b2e9a50b976612f8a1aeb26275311Eric Anholt      intel_miptree_unmap_blit(intel, mt, map, level, slice);
1583b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   } else {
1584b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt      intel_miptree_unmap_gtt(intel, mt, map, level, slice);
1585b48c3bca87b30003f9e117d299011380e743aec9Eric Anholt   }
1586221a36514b4ecffdaa3be5c43e67c75cc8c30ab8Eric Anholt
15874c0ccc13bd3ec149c4a51c4937811894fbe713f0Chad Versace   intel_miptree_release_map(mt, level, slice);
1588b75291c61c40a3a690b08f8aa013ad2d3d2deda8Eric Anholt}
158981980958d0d3def26741cfe78b7c23f6635f826aChad Versace
1590e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versacestatic void
1591e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versaceintel_miptree_map_multisample(struct intel_context *intel,
1592e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              struct intel_mipmap_tree *mt,
1593e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int level,
1594e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int slice,
1595e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int x,
1596e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int y,
1597e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int w,
1598e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              unsigned int h,
1599e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              GLbitfield mode,
1600e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              void **out_ptr,
1601e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                              int *out_stride)
1602e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace{
1603e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   struct intel_miptree_map *map;
1604e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1605e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   assert(mt->num_samples > 1);
1606e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1607e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   /* Only flat, renderbuffer-like miptrees are supported. */
1608e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (mt->target != GL_TEXTURE_2D ||
1609e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace       mt->first_level != 0 ||
1610e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace       mt->last_level != 0) {
1611e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      _mesa_problem(&intel->ctx, "attempt to map a multisample miptree for "
1612e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                    "which (target, first_level, last_level != "
1613e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                    "(GL_TEXTURE_2D, 0, 0)");
1614e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      goto fail;
1615e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   }
1616e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1617e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   map = intel_miptree_attach_map(mt, level, slice, x, y, w, h, mode);
1618e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (!map)
1619e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      goto fail;
1620e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1621e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (!mt->singlesample_mt) {
1622e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      mt->singlesample_mt =
1623e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace         intel_miptree_create_for_renderbuffer(intel,
1624e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                               mt->format,
1625e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                               mt->singlesample_width0,
1626e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                               mt->singlesample_height0,
1627e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                               0 /*num_samples*/);
1628e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      if (!mt->singlesample_mt)
1629e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace         goto fail;
1630e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1631e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      map->singlesample_mt_is_tmp = true;
1632e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      mt->need_downsample = true;
1633e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   }
1634e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1635e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   intel_miptree_downsample(intel, mt);
1636e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   intel_miptree_map_singlesample(intel, mt->singlesample_mt,
1637e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                  level, slice,
1638e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                  x, y, w, h,
1639e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                  mode,
1640e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                  out_ptr, out_stride);
1641e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   return;
1642e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1643e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versacefail:
1644e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   intel_miptree_release_map(mt, level, slice);
1645e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   *out_ptr = NULL;
1646e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   *out_stride = 0;
1647e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace}
1648e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1649e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versacestatic void
1650e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versaceintel_miptree_unmap_multisample(struct intel_context *intel,
1651e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                struct intel_mipmap_tree *mt,
1652e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                unsigned int level,
1653e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                unsigned int slice)
1654e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace{
1655e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   struct intel_miptree_map *map = mt->level[level].slice[slice].map;
1656e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1657e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   assert(mt->num_samples > 1);
1658e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1659e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (!map)
1660e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      return;
1661e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1662e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   intel_miptree_unmap_singlesample(intel, mt->singlesample_mt, level, slice);
1663e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1664e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   mt->need_downsample = false;
1665e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (map->mode & GL_MAP_WRITE_BIT)
1666e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_upsample(intel, mt);
1667e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1668e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (map->singlesample_mt_is_tmp)
1669e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_release(&mt->singlesample_mt);
1670e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
1671e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   intel_miptree_release_map(mt, level, slice);
1672e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace}
1673e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace
167481980958d0d3def26741cfe78b7c23f6635f826aChad Versacevoid
167581980958d0d3def26741cfe78b7c23f6635f826aChad Versaceintel_miptree_map(struct intel_context *intel,
167681980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  struct intel_mipmap_tree *mt,
167781980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int level,
167881980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int slice,
167981980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int x,
168081980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int y,
168181980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int w,
168281980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  unsigned int h,
168381980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  GLbitfield mode,
168481980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  void **out_ptr,
168581980958d0d3def26741cfe78b7c23f6635f826aChad Versace		  int *out_stride)
168681980958d0d3def26741cfe78b7c23f6635f826aChad Versace{
1687e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (mt->num_samples <= 1)
1688e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_map_singlesample(intel, mt,
1689e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                     level, slice,
1690e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                     x, y, w, h,
1691e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                     mode,
1692e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                     out_ptr, out_stride);
1693e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   else
1694e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_map_multisample(intel, mt,
1695e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                    level, slice,
1696e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                    x, y, w, h,
1697e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                    mode,
1698e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace                                    out_ptr, out_stride);
169981980958d0d3def26741cfe78b7c23f6635f826aChad Versace}
170081980958d0d3def26741cfe78b7c23f6635f826aChad Versace
170181980958d0d3def26741cfe78b7c23f6635f826aChad Versacevoid
170281980958d0d3def26741cfe78b7c23f6635f826aChad Versaceintel_miptree_unmap(struct intel_context *intel,
170381980958d0d3def26741cfe78b7c23f6635f826aChad Versace		    struct intel_mipmap_tree *mt,
170481980958d0d3def26741cfe78b7c23f6635f826aChad Versace		    unsigned int level,
170581980958d0d3def26741cfe78b7c23f6635f826aChad Versace		    unsigned int slice)
170681980958d0d3def26741cfe78b7c23f6635f826aChad Versace{
1707e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   if (mt->num_samples <= 1)
1708e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_unmap_singlesample(intel, mt, level, slice);
1709e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace   else
1710e88cfbb95f631ca1275a5cef4ccc5aaffb70aabaChad Versace      intel_miptree_unmap_multisample(intel, mt, level, slice);
171181980958d0d3def26741cfe78b7c23f6635f826aChad Versace}
1712