intel_mipmap_tree.c revision e5f50f2fa32c50807da3a8f13733f0fbc7868f94
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
2877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_context.h"
2977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_mipmap_tree.h"
3077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "intel_regions.h"
31d913a15898fc8edc68ee673e2ae038cf2d7e8af9Eric Anholt#include "intel_chipset.h"
3277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#include "enums.h"
3377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
3477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#define FILE_DEBUG_FLAG DEBUG_MIPTREE
3577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
3677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtstatic GLenum
3777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholttarget_to_target(GLenum target)
3877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
3977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   switch (target) {
4077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
4177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
4277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
4377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
4477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
4577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
4677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_TEXTURE_CUBE_MAP_ARB;
4777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   default:
4877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return target;
4977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
5077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
5177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
526d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstatic struct intel_mipmap_tree *
536d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_internal(struct intel_context *intel,
546d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLenum target,
556d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLenum internal_format,
566d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint first_level,
576d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint last_level,
586d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint width0,
596d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint height0,
606d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg			      GLuint depth0, GLuint cpp, GLuint compress_byte)
6177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
6277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLboolean ok;
6377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   struct intel_mipmap_tree *mt = calloc(sizeof(*mt), 1);
6477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
6577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s target %s format %s level %d..%d\n", __FUNCTION__,
6677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       _mesa_lookup_enum_by_nr(target),
6777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       _mesa_lookup_enum_by_nr(internal_format), first_level, last_level);
6877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
6977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->target = target_to_target(target);
7077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->internal_format = internal_format;
7177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->first_level = first_level;
7277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->last_level = last_level;
7377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->width0 = width0;
7477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->height0 = height0;
7577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->depth0 = depth0;
7677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->cpp = compress_byte ? compress_byte : cpp;
7777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->compressed = compress_byte ? 1 : 0;
7877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->refcount = 1;
79a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   mt->pitch = 0;
8077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
81c0b4257aa9ba783674ccf7162799385734dff211Eric Anholt#ifdef I915
82c0b4257aa9ba783674ccf7162799385734dff211Eric Anholt   if (IS_945(intel->intelScreen->deviceID))
83a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      ok = i945_miptree_layout(intel, mt);
84c0b4257aa9ba783674ccf7162799385734dff211Eric Anholt   else
85a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      ok = i915_miptree_layout(intel, mt);
86c0b4257aa9ba783674ccf7162799385734dff211Eric Anholt#else
87a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   ok = brw_miptree_layout(intel, mt);
88c0b4257aa9ba783674ccf7162799385734dff211Eric Anholt#endif
8977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
906d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (!ok) {
916d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      free(mt);
926d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return NULL;
9377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
9477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
956d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   return mt;
966d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg}
976d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
986d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
996d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create(struct intel_context *intel,
1006d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLenum target,
1016d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLenum internal_format,
1026d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint first_level,
1036d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint last_level,
1046d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint width0,
1056d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint height0,
1066d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg		     GLuint depth0, GLuint cpp, GLuint compress_byte)
1076d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{
1086d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   struct intel_mipmap_tree *mt;
1096d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1106d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt = intel_miptree_create_internal(intel, target, internal_format,
1116d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      first_level, last_level, width0,
1126d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      height0, depth0, cpp, compress_byte);
1137ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao   /*
1147ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao    * pitch == 0 indicates the null texture
1157ed1fd5d8438e55fe24091844cdfccb0881306bcXiang, Haihao    */
1164a556bcb17b8b0dd9ba4ef6eccbb3cfb2ad6a025Xiang, Haihao   if (!mt || !mt->pitch)
1176d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return NULL;
1186d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1196d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt->region = intel_region_alloc(intel,
1206d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				   mt->cpp, mt->pitch, mt->total_height);
1216d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
12277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!mt->region) {
1236d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg       free(mt);
1246d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg       return NULL;
1256d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   }
1266d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1276d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   return mt;
1286d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg}
1296d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1306d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
1316d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_for_region(struct intel_context *intel,
1326d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum target,
1336d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum internal_format,
1346d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint first_level,
1356d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint last_level,
1366d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				struct intel_region *region,
1376d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint depth0,
1386d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint compress_byte)
1396d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{
1406d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   struct intel_mipmap_tree *mt;
1416d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1426d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt = intel_miptree_create_internal(intel, target, internal_format,
1436d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      first_level, last_level,
1446d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      region->pitch, region->height, depth0,
1456d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      region->cpp, compress_byte);
1466d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (!mt)
1476d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return mt;
1486d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#if 0
1496d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (mt->pitch != region->pitch) {
1506d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      fprintf(stderr,
1516d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg	      "region pitch (%d) doesn't match mipmap tree pitch (%d)\n",
1526d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg	      region->pitch, mt->pitch);
15377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(mt);
15477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return NULL;
15577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
1566d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#else
1576d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   /* The mipmap tree pitch is aligned to 64 bytes to make sure render
1586d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    * to texture works, but we don't need that for texturing from a
1596d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    * pixmap.  Just override it here. */
1606d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt->pitch = region->pitch;
1616d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#endif
1626d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1636d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt->region = region;
16477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
16577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return mt;
1666d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg }
16777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
168a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard/**
169a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * intel_miptree_pitch_align:
170a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
171a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @intel: intel context pointer
172a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
173a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @mt: the miptree to compute pitch alignment for
174a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
175a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @pitch: the natural pitch value
176a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
177a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * Given @pitch, compute a larger value which accounts for
178a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * any necessary alignment required by the device
179a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard */
180a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
181a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packardint intel_miptree_pitch_align (struct intel_context *intel,
182a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       struct intel_mipmap_tree *mt,
183a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       int pitch)
184a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard{
18536c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg#ifdef I915
1869bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai   GLcontext *ctx = &intel->ctx;
18736c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg#endif
18836c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg
189a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   if (!mt->compressed) {
190a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      int pitch_align;
191a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
192a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      if (intel->ttm) {
193a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 /* XXX: Align pitch to multiple of 64 bytes for now to allow
194a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * render-to-texture to work in all cases. This should probably be
195a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * replaced at some point by some scheme to only do this when really
196a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * necessary.
197a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  */
198a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch_align = 64;
199a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      } else {
200a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch_align = 4;
201a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      }
202a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
203a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      pitch = ALIGN(pitch * mt->cpp, pitch_align);
204a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
205a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard#ifdef I915
206a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      /* XXX: At least the i915 seems very upset when the pitch is a multiple
207a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       * of 1024 and sometimes 512 bytes - performance can drop by several
208a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       * times. Go to the next multiple of the required alignment for now.
209a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       */
2109bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai      if (!(pitch & 511) &&
2119bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai	 (pitch + pitch_align) < (1 << ctx->Const.MaxTextureLevels))
212a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch += pitch_align;
213a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard#endif
214a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
215a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      pitch /= mt->cpp;
216a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   }
217a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   return pitch;
218a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard}
21977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
22077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
22177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_reference(struct intel_mipmap_tree **dst,
22277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        struct intel_mipmap_tree *src)
22377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
22477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   src->refcount++;
22577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *dst = src;
22677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount);
22777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
22877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
22977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
23077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_release(struct intel_context *intel,
23177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                      struct intel_mipmap_tree **mt)
23277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
23377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!*mt)
23477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return;
23577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
23677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s %p refcount will be %d\n", __FUNCTION__, *mt, (*mt)->refcount - 1);
23777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (--(*mt)->refcount <= 0) {
23877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLuint i;
23977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      DBG("%s deleting %p\n", __FUNCTION__, *mt);
24177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intel_region_release(&((*mt)->region));
24377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      for (i = 0; i < MAX_TEXTURE_LEVELS; i++)
24577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         if ((*mt)->level[i].image_offset)
24677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt            free((*mt)->level[i].image_offset);
24777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(*mt);
24977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
25077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *mt = NULL;
25177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
25277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Can the image be pulled into a unified mipmap tree.  This mirrors
25777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the completeness test in a lot of ways.
25877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
25977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Not sure whether I want to pass gl_texture_image here.
26077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
26177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLboolean
26277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_match_image(struct intel_mipmap_tree *mt,
26377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          struct gl_texture_image *image,
26477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          GLuint face, GLuint level)
26577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
26677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Images with borders are never pulled into mipmap trees.
26777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
26877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (image->Border)
26977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
27077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
27177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (image->InternalFormat != mt->internal_format ||
27277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->IsCompressed != mt->compressed)
27377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
27477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
27577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Test image dimensions against the base level image adjusted for
27677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * minification.  This will also catch images not present in the
27777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * tree, changed targets, etc.
27877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
27977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (image->Width != mt->level[level].width ||
28077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->Height != mt->level[level].height ||
28177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->Depth != mt->level[level].depth)
28277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
28377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return GL_TRUE;
28577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
28677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
28877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
28977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_level_info(struct intel_mipmap_tree *mt,
290659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint level,
291659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint nr_images,
292659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint x, GLuint y,
293659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint w, GLuint h, GLuint d)
29477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
29577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].width = w;
29677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].height = h;
29777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].depth = d;
29877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp;
29977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].nr_images = nr_images;
30077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
30177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
30277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       level, w, h, d, x, y, mt->level[level].level_offset);
30377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
30477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Not sure when this would happen, but anyway:
30577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
30677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->level[level].image_offset) {
30777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(mt->level[level].image_offset);
30877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      mt->level[level].image_offset = NULL;
30977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
31077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   assert(nr_images);
31277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].image_offset = malloc(nr_images * sizeof(GLuint));
31477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].image_offset[0] = 0;
31577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
31677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
32077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
321659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			       GLuint level, GLuint img,
322659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			       GLuint x, GLuint y)
32377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
32477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (img == 0 && level == 0)
32577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      assert(x == 0 && y == 0);
32677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   assert(img < mt->level[level].nr_images);
32877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
329e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   mt->level[level].image_offset[img] = (x + y * mt->pitch) * mt->cpp;
33077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s level %d img %d pos %d,%d image_offset %x\n",
33277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]);
33377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
33477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Although we use the image_offset[] array to store relative offsets
33777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * to cube faces, Mesa doesn't know anything about this and expects
33877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * each cube face to be treated as a separate image.
33977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
34077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * These functions present that view to mesa:
34177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
34277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtconst GLuint *
34377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_depth_offsets(struct intel_mipmap_tree *mt, GLuint level)
34477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
34577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const GLuint zero = 0;
34677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->target != GL_TEXTURE_3D || mt->level[level].nr_images == 1)
34877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return &zero;
34977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else
35077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return mt->level[level].image_offset;
35177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
35277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
35377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
35477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLuint
355659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholtintel_miptree_image_offset(struct intel_mipmap_tree *mt,
356659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			   GLuint face, GLuint level)
35777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
35877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->target == GL_TEXTURE_CUBE_MAP_ARB)
35977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return (mt->level[level].level_offset +
360e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	      mt->level[level].image_offset[face]);
36177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else
36277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return mt->level[level].level_offset;
36377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
36477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
36877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Map a teximage in a mipmap tree.
36977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \param row_stride  returns row stride in bytes
37077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \param image_stride  returns image stride in bytes (for 3D textures).
371e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt * \param image_offsets pointer to array of pixel offsets from the returned
372e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt *	  pointer to each depth image
37377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \return address of mapping
37477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
37577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLubyte *
37677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_map(struct intel_context * intel,
37777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        struct intel_mipmap_tree * mt,
37877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint face,
37977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint level,
38077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint * row_stride, GLuint * image_offsets)
38177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
38277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s \n", __FUNCTION__);
38377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
38477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (row_stride)
38577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      *row_stride = mt->pitch * mt->cpp;
38677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
387e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   if (mt->target == GL_TEXTURE_3D) {
388e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      int i;
389e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt
390e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      for (i = 0; i < mt->level[level].depth; i++)
391e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	 image_offsets[i] = mt->level[level].image_offset[i] / mt->cpp;
392e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   } else {
393e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      assert(mt->level[level].depth == 1);
394e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      assert(mt->target == GL_TEXTURE_CUBE_MAP ||
395e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	     mt->level[level].image_offset[0] == 0);
396e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      image_offsets[0] = 0;
3971d14da9a89e8d7f49b754ca1f24cb062a261a7e7Zou Nan hai   }
39877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
3997c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt   return (intel_region_map(intel, mt->region) +
40077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intel_miptree_image_offset(mt, face, level));
40177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
40277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
40377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
40477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_unmap(struct intel_context *intel,
40577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          struct intel_mipmap_tree *mt)
40677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
40777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s\n", __FUNCTION__);
4087c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt   intel_region_unmap(intel, mt->region);
40977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
41077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
41177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
41277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
41377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Upload data for a particular image.
41477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
41577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
41677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_data(struct intel_context *intel,
417659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 struct intel_mipmap_tree *dst,
418659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint face,
419659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint level,
420659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 void *src,
421659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint src_row_pitch,
422659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint src_image_pitch)
42377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
42477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint depth = dst->level[level].depth;
42577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
42677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
42777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint i;
42877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint height = 0;
42977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
430101abee6c4fc2c9284ff2ba6f9f9138327d6963dEric Anholt   DBG("%s: %d/%d\n", __FUNCTION__, face, level);
43177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   for (i = 0; i < depth; i++) {
43277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      height = dst->level[level].height;
43377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if(dst->compressed)
4340da03c0aa9ed120fe5ff781a365b503b8ed70e0cZou Nan hai	 height = (height + 3) / 4;
435659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt      intel_region_data(intel,
436659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			dst->region,
4373956597962dcf6c8082541199ebac58e0d84f6bcRoland Scheidegger			dst_offset + dst_depth_offset[i] * dst->cpp, /* dst_offset */
438659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			0, 0,                             /* dstx, dsty */
439659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			src,
440659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			src_row_pitch,
441659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			0, 0,                             /* source x, y */
442659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			dst->level[level].width, height); /* width, height */
44377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
44477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      src += src_image_pitch * dst->cpp;
44577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
44677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
44777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
44877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtextern GLuint intel_compressed_alignment(GLenum);
44977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Copy mipmap image between trees
45077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
45177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
45277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_copy(struct intel_context *intel,
45377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         struct intel_mipmap_tree *dst,
45477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         GLuint face, GLuint level,
45577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         struct intel_mipmap_tree *src)
45677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
45777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint width = src->level[level].width;
45877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint height = src->level[level].height;
45977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint depth = src->level[level].depth;
46077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
46177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint src_offset = intel_miptree_image_offset(src, face, level);
46277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
46377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *src_depth_offset = intel_miptree_depth_offsets(src, level);
46477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint i;
46577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
46677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (dst->compressed) {
46777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       GLuint alignment = intel_compressed_alignment(dst->internal_format);
46877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       height = (height + 3) / 4;
46977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       width = ((width + alignment - 1) & ~(alignment - 1));
47077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
47177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
47277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   for (i = 0; i < depth; i++) {
4737c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt      intel_region_copy(intel,
4743956597962dcf6c8082541199ebac58e0d84f6bcRoland Scheidegger                        dst->region, dst_offset + dst_depth_offset[i] * dst->cpp,
47577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0,
47677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0,
4773956597962dcf6c8082541199ebac58e0d84f6bcRoland Scheidegger                        src->region, src_offset + src_depth_offset[i] * src->cpp,
47877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0, 0, width, height);
47977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
48077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
48177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
482