intel_mipmap_tree.c revision 8db761409dadc2e899d4e7107eff3aa07b07aa11
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,
1208db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				   mt->cpp,
1218db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				   mt->pitch,
1228db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				   mt->total_height,
1238db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				   mt->pitch);
1246d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
12577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!mt->region) {
1266d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg       free(mt);
1276d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg       return NULL;
1286d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   }
1296d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1306d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   return mt;
1316d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg}
1326d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1336d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergstruct intel_mipmap_tree *
1346d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsbergintel_miptree_create_for_region(struct intel_context *intel,
1356d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum target,
1366d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLenum internal_format,
1376d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint first_level,
1386d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint last_level,
1396d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				struct intel_region *region,
1406d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint depth0,
1416d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				GLuint compress_byte)
1426d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg{
1436d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   struct intel_mipmap_tree *mt;
1446d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1456d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt = intel_miptree_create_internal(intel, target, internal_format,
1466d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      first_level, last_level,
1478db761409dadc2e899d4e7107eff3aa07b07aa11Eric Anholt				      region->width, region->height, 1,
1486d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg				      region->cpp, compress_byte);
1496d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (!mt)
1506d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      return mt;
1516d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#if 0
1526d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   if (mt->pitch != region->pitch) {
1536d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg      fprintf(stderr,
1546d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg	      "region pitch (%d) doesn't match mipmap tree pitch (%d)\n",
1556d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg	      region->pitch, mt->pitch);
15677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(mt);
15777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return NULL;
15877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
1596d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#else
1606d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   /* The mipmap tree pitch is aligned to 64 bytes to make sure render
1616d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    * to texture works, but we don't need that for texturing from a
1626d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg    * pixmap.  Just override it here. */
1636d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt->pitch = region->pitch;
1646d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg#endif
1656d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg
1666d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg   mt->region = region;
16777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
16877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return mt;
1696d48779c7e5c9002d1bec4b1266ca05a474218efKristian Høgsberg }
17077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
171a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard/**
172a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * intel_miptree_pitch_align:
173a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
174a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @intel: intel context pointer
175a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
176a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @mt: the miptree to compute pitch alignment for
177a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
178a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * @pitch: the natural pitch value
179a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard *
180a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * Given @pitch, compute a larger value which accounts for
181a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard * any necessary alignment required by the device
182a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard */
183a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
184a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packardint intel_miptree_pitch_align (struct intel_context *intel,
185a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       struct intel_mipmap_tree *mt,
186a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard			       int pitch)
187a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard{
18836c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg#ifdef I915
1899bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai   GLcontext *ctx = &intel->ctx;
19036c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg#endif
19136c26d321b5d17902f0e8f531654dfb2fe2bdd2dKristian Høgsberg
192a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   if (!mt->compressed) {
193a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      int pitch_align;
194a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
195a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      if (intel->ttm) {
196a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 /* XXX: Align pitch to multiple of 64 bytes for now to allow
197a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * render-to-texture to work in all cases. This should probably be
198a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * replaced at some point by some scheme to only do this when really
199a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  * necessary.
200a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	  */
201a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch_align = 64;
202a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      } else {
203a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch_align = 4;
204a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      }
205a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
206a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      pitch = ALIGN(pitch * mt->cpp, pitch_align);
207a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
208a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard#ifdef I915
209a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      /* XXX: At least the i915 seems very upset when the pitch is a multiple
210a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       * of 1024 and sometimes 512 bytes - performance can drop by several
211a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       * times. Go to the next multiple of the required alignment for now.
212a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard       */
2139bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai      if (!(pitch & 511) &&
2149bd2cb7f90ac434ec5be7d388f899976bf902dc1Zou Nan hai	 (pitch + pitch_align) < (1 << ctx->Const.MaxTextureLevels))
215a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard	 pitch += pitch_align;
216a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard#endif
217a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard
218a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard      pitch /= mt->cpp;
219a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   }
220a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard   return pitch;
221a183efc132c8db1bb42525ac177ffff96f69a59bKeith Packard}
22277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
22377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
22477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_reference(struct intel_mipmap_tree **dst,
22577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        struct intel_mipmap_tree *src)
22677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
22777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   src->refcount++;
22877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *dst = src;
22977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s %p refcount now %d\n", __FUNCTION__, src, src->refcount);
23077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
23177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
23277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
23377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_release(struct intel_context *intel,
23477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                      struct intel_mipmap_tree **mt)
23577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
23677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (!*mt)
23777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return;
23877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
23977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s %p refcount will be %d\n", __FUNCTION__, *mt, (*mt)->refcount - 1);
24077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (--(*mt)->refcount <= 0) {
24177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      GLuint i;
24277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      DBG("%s deleting %p\n", __FUNCTION__, *mt);
24477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      intel_region_release(&((*mt)->region));
24677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
24777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      for (i = 0; i < MAX_TEXTURE_LEVELS; i++)
24877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt         if ((*mt)->level[i].image_offset)
24977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt            free((*mt)->level[i].image_offset);
25077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(*mt);
25277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
25377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   *mt = NULL;
25477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
25577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
25977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Can the image be pulled into a unified mipmap tree.  This mirrors
26077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * the completeness test in a lot of ways.
26177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
26277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Not sure whether I want to pass gl_texture_image here.
26377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
26477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLboolean
26577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_match_image(struct intel_mipmap_tree *mt,
26677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          struct gl_texture_image *image,
26777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          GLuint face, GLuint level)
26877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
26977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Images with borders are never pulled into mipmap trees.
27077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
271b4b7326717d3253656f9702fc04f06f8d210a6aaXiang, Haihao   if (image->Border ||
272b4b7326717d3253656f9702fc04f06f8d210a6aaXiang, Haihao       ((image->_BaseFormat == GL_DEPTH_COMPONENT) &&
273b4b7326717d3253656f9702fc04f06f8d210a6aaXiang, Haihao        ((image->TexObject->WrapS == GL_CLAMP_TO_BORDER) ||
274b4b7326717d3253656f9702fc04f06f8d210a6aaXiang, Haihao         (image->TexObject->WrapT == GL_CLAMP_TO_BORDER))))
27577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
27677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
27777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (image->InternalFormat != mt->internal_format ||
27877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->IsCompressed != mt->compressed)
27977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
28077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
281d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao   if (!image->IsCompressed &&
282d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao       !mt->compressed &&
283d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao       image->TexFormat->TexelBytes != mt->cpp)
284d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao      return GL_FALSE;
285d12fa3511da23d8285f3ea1a51a1f328cdbb1462Xiang, Haihao
28677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Test image dimensions against the base level image adjusted for
28777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * minification.  This will also catch images not present in the
28877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    * tree, changed targets, etc.
28977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
29077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (image->Width != mt->level[level].width ||
29177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->Height != mt->level[level].height ||
29277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       image->Depth != mt->level[level].depth)
29377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return GL_FALSE;
29477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   return GL_TRUE;
29677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
29777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
29977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
30077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_level_info(struct intel_mipmap_tree *mt,
301659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint level,
302659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint nr_images,
303659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint x, GLuint y,
304659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			     GLuint w, GLuint h, GLuint d)
30577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
30677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].width = w;
30777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].height = h;
30877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].depth = d;
30977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].level_offset = (x + y * mt->pitch) * mt->cpp;
31077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].nr_images = nr_images;
31177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
31377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       level, w, h, d, x, y, mt->level[level].level_offset);
31477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
31577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   /* Not sure when this would happen, but anyway:
31677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt    */
31777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->level[level].image_offset) {
31877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      free(mt->level[level].image_offset);
31977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      mt->level[level].image_offset = NULL;
32077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
32177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   assert(nr_images);
32377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].image_offset = malloc(nr_images * sizeof(GLuint));
32577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   mt->level[level].image_offset[0] = 0;
32677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
32777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
32977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
33177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
332659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			       GLuint level, GLuint img,
333659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			       GLuint x, GLuint y)
33477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
33577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (img == 0 && level == 0)
33677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      assert(x == 0 && y == 0);
33777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
33877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   assert(img < mt->level[level].nr_images);
33977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
340e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   mt->level[level].image_offset[img] = (x + y * mt->pitch) * mt->cpp;
34177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s level %d img %d pos %d,%d image_offset %x\n",
34377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       __FUNCTION__, level, img, x, y, mt->level[level].image_offset[img]);
34477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
34577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
34777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Although we use the image_offset[] array to store relative offsets
34877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * to cube faces, Mesa doesn't know anything about this and expects
34977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * each cube face to be treated as a separate image.
35077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt *
35177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * These functions present that view to mesa:
35277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
35377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtconst GLuint *
35477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_depth_offsets(struct intel_mipmap_tree *mt, GLuint level)
35577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
35677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   static const GLuint zero = 0;
35777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
35877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->target != GL_TEXTURE_3D || mt->level[level].nr_images == 1)
35977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return &zero;
36077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else
36177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return mt->level[level].image_offset;
36277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
36377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
36577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLuint
366659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholtintel_miptree_image_offset(struct intel_mipmap_tree *mt,
367659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			   GLuint face, GLuint level)
36877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
36977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (mt->target == GL_TEXTURE_CUBE_MAP_ARB)
37077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return (mt->level[level].level_offset +
371e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	      mt->level[level].image_offset[face]);
37277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   else
37377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      return mt->level[level].level_offset;
37477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
37577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
37677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
37777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
37877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/**
37977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * Map a teximage in a mipmap tree.
38077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \param row_stride  returns row stride in bytes
38177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \param image_stride  returns image stride in bytes (for 3D textures).
382e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt * \param image_offsets pointer to array of pixel offsets from the returned
383e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt *	  pointer to each depth image
38477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt * \return address of mapping
38577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
38677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric AnholtGLubyte *
38777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_map(struct intel_context * intel,
38877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        struct intel_mipmap_tree * mt,
38977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint face,
39077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint level,
39177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        GLuint * row_stride, GLuint * image_offsets)
39277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
39377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s \n", __FUNCTION__);
39477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
39577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (row_stride)
39677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      *row_stride = mt->pitch * mt->cpp;
39777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
398e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   if (mt->target == GL_TEXTURE_3D) {
399e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      int i;
400e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt
401e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      for (i = 0; i < mt->level[level].depth; i++)
402e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	 image_offsets[i] = mt->level[level].image_offset[i] / mt->cpp;
403e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt   } else {
404e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      assert(mt->level[level].depth == 1);
405e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      assert(mt->target == GL_TEXTURE_CUBE_MAP ||
406e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt	     mt->level[level].image_offset[0] == 0);
407e5f50f2fa32c50807da3a8f13733f0fbc7868f94Eric Anholt      image_offsets[0] = 0;
4081d14da9a89e8d7f49b754ca1f24cb062a261a7e7Zou Nan hai   }
40977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
4107c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt   return (intel_region_map(intel, mt->region) +
41177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt           intel_miptree_image_offset(mt, face, level));
41277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
41377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
41477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
41577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_unmap(struct intel_context *intel,
41677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                          struct intel_mipmap_tree *mt)
41777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
41877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   DBG("%s\n", __FUNCTION__);
4197c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt   intel_region_unmap(intel, mt->region);
42077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
42177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
42277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
42377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
42477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Upload data for a particular image.
42577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
42677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
42777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_data(struct intel_context *intel,
428659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 struct intel_mipmap_tree *dst,
429659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint face,
430659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint level,
431659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 void *src,
432659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint src_row_pitch,
433659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			 GLuint src_image_pitch)
43477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
43577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint depth = dst->level[level].depth;
43677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
43777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
43877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint i;
43977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint height = 0;
44077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
441101abee6c4fc2c9284ff2ba6f9f9138327d6963dEric Anholt   DBG("%s: %d/%d\n", __FUNCTION__, face, level);
44277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   for (i = 0; i < depth; i++) {
44377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      height = dst->level[level].height;
44477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      if(dst->compressed)
4450da03c0aa9ed120fe5ff781a365b503b8ed70e0cZou Nan hai	 height = (height + 3) / 4;
446659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt      intel_region_data(intel,
447659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			dst->region,
448e438827dec5a3aafa04e13caf5988f359c004249Henri Verbeet			dst_offset + dst_depth_offset[i], /* dst_offset */
449659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			0, 0,                             /* dstx, dsty */
450659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			src,
451659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			src_row_pitch,
452659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			0, 0,                             /* source x, y */
453659baa3f25275b622dad626992af60f3c9ea6d66Eric Anholt			dst->level[level].width, height); /* width, height */
45477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
45577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt      src += src_image_pitch * dst->cpp;
45677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
45777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
45877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
45977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtextern GLuint intel_compressed_alignment(GLenum);
46077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt/* Copy mipmap image between trees
46177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt */
46277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtvoid
46377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholtintel_miptree_image_copy(struct intel_context *intel,
46477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         struct intel_mipmap_tree *dst,
46577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         GLuint face, GLuint level,
46677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                         struct intel_mipmap_tree *src)
46777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt{
46877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint width = src->level[level].width;
46977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint height = src->level[level].height;
47077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint depth = src->level[level].depth;
47177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
47277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint src_offset = intel_miptree_image_offset(src, face, level);
47377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
47477a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   const GLuint *src_depth_offset = intel_miptree_depth_offsets(src, level);
47577a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   GLuint i;
47677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
47777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   if (dst->compressed) {
47877a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       GLuint alignment = intel_compressed_alignment(dst->internal_format);
47977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       height = (height + 3) / 4;
48077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt       width = ((width + alignment - 1) & ~(alignment - 1));
48177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
48277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
48377a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   for (i = 0; i < depth; i++) {
4847c71ef3a3d0cf2620525f468960cdc76a0fb0d33Eric Anholt      intel_region_copy(intel,
485e438827dec5a3aafa04e13caf5988f359c004249Henri Verbeet                        dst->region, dst_offset + dst_depth_offset[i],
48677a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0,
48777a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0,
488e438827dec5a3aafa04e13caf5988f359c004249Henri Verbeet                        src->region, src_offset + src_depth_offset[i],
48977a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt                        0, 0, width, height);
49077a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt   }
49177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt
49277a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt}
493