i915_texstate.c revision 9a82d89a8fafde1b65c0843e022e99864b6d56b1
16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved.
56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the
86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including
96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions:
136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the
156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software.
176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/
276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
28ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h"
29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h"
30f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt#include "main/macros.h"
31ee64347979b4e22976910cb97869887f7de4241cEric Anholt#include "main/colormac.h"
321f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt#include "main/samplerobj.h"
336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_mipmap_tree.h"
356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_tex.h"
366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_context.h"
386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i915_reg.h"
396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
42afbe605eff5af3739a76705a04a3c97a53c81b0dEric Anholttranslate_texture_format(gl_format mesa_format, GLenum DepthMode)
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (mesa_format) {
456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_L8:
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_L8;
476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_I8:
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_I8;
496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_A8:
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_A8;
516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_AL88:
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_AY88;
536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB565:
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_RGB565;
556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB1555:
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB1555;
576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB4444:
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB4444;
596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_ARGB8888:
60e624b77eb2d594cde053c73a530836e05227126aIan Romanick      return MAPSURF_32BIT | MT_32BIT_ARGB8888;
614a253431abf43a0638afb43605b44a8742b72a60Brian Paul   case MESA_FORMAT_XRGB8888:
624a253431abf43a0638afb43605b44a8742b72a60Brian Paul      return MAPSURF_32BIT | MT_32BIT_XRGB8888;
636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR_REV:
646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR:
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_FXT1:
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_FXT1:
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_Z16:
719e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      if (DepthMode == GL_ALPHA)
729e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_A16);
739e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else if (DepthMode == GL_INTENSITY)
749e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_I16);
759e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else
769e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_L16);
776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT1:
786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_DXT1:
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT3:
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT5:
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
840adfd1021035e90995a25ec5f20b736e55075d92Xiang, Haihao   case MESA_FORMAT_S8_Z24:
854b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      if (DepthMode == GL_ALPHA)
864b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8A24);
874b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else if (DepthMode == GL_INTENSITY)
884b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8I24);
894b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else
904b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8L24);
916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
929a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt      fprintf(stderr, "%s: bad image format %s\n", __FUNCTION__,
939a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt	      _mesa_get_format_name(mesa_format));
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      abort();
956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return 0;
966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* The i915 (and related graphics cores) do not support GL_CLAMP.  The
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Intel drivers for "other operating systems" implement GL_CLAMP as
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_CLAMP_TO_EDGE, so the same is done here.
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelltranslate_wrap_mode(GLenum wrap)
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (wrap) {
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPEAT:
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP:
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;   /* not quite correct */
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_EDGE:
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_BORDER:
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_BORDER;
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIRRORED_REPEAT:
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_MIRROR;
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Recalculate all state from scratch.  Perhaps not the most
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * efficient, but this has gotten complex enough that we need
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * something which is understandable and reliable.
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLboolean
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
134f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i915_context *i915 = i915_context(ctx);
136d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_unit *tUnit = &ctx->Texture.Unit[unit];
137d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_object *tObj = tUnit->_Current;
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_texture_object *intelObj = intel_texture_object(tObj);
1396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct gl_texture_image *firstImage;
1401f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
141e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   GLuint *state = i915->state.Tex[unit], format, pitch;
142ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger   GLint lodbias, aniso = 0;
14379c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   GLubyte border[4];
1446785d6741db987469293d737e9b18f94d189b62eEric Anholt   GLfloat maxlod;
1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   memset(state, 0, sizeof(state));
1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /*We need to refcount these. */
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (i915->state.tex_buffer[unit] != NULL) {
15134474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt       drm_intel_bo_unreference(i915->state.tex_buffer[unit]);
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       i915->state.tex_buffer[unit] = NULL;
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
155a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   if (!intel_finalize_mipmap_tree(intel, unit))
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return GL_FALSE;
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Get first image here, since intelObj->firstLevel will get set in
1596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * the intel_finalize_mipmap_tree() call above.
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1611b18b45d79e065e4e05a1e89e9d756d96258ded5Eric Anholt   firstImage = tObj->Image[0][tObj->BaseLevel];
1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
16334474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt   drm_intel_bo_reference(intelObj->mt->region->buffer);
164a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   i915->state.tex_buffer[unit] = intelObj->mt->region->buffer;
165a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   i915->state.tex_offset[unit] = 0; /* Always the origin of the miptree */
166a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt
167a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   format = translate_texture_format(firstImage->TexFormat,
1681f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt				     sampler->DepthMode);
169362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt   pitch = intelObj->mt->region->pitch * intelObj->mt->cpp;
1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS3] =
1726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) |
173165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt       ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | format);
174165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt
175165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   if (intelObj->mt->region->tiling != I915_TILING_NONE) {
176165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      state[I915_TEXREG_MS3] |= MS3_TILED_SURFACE;
177165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      if (intelObj->mt->region->tiling == I915_TILING_Y)
178165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt	 state[I915_TEXREG_MS3] |= MS3_TILE_WALK;
179165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   }
1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
181b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt   /* We get one field with fraction bits for the maximum addressable
182b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * (lowest resolution) LOD.  Use it to cover both MAX_LEVEL and
183b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * MAX_LOD.
1846785d6741db987469293d737e9b18f94d189b62eEric Anholt    */
1851f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   maxlod = MIN2(sampler->MaxLod, tObj->_MaxLevel - tObj->BaseLevel);
1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS4] =
187f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt      ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) |
188f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       MS4_CUBE_FACE_ENA_MASK |
1896785d6741db987469293d737e9b18f94d189b62eEric Anholt       (U_FIXED(CLAMP(maxlod, 0.0, 11.0), 2) << MS4_MAX_LOD_SHIFT) |
190f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       ((firstImage->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint minFilt, mipFilt, magFilt;
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1961f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      switch (sampler->MinFilter) {
1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST:
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR:
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_NEAREST:
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_NEAREST:
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_LINEAR:
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_LINEAR:
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2251f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->MaxAnisotropy > 1.0) {
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_ANISOTROPIC;
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         magFilt = FILTER_ANISOTROPIC;
2281f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         if (sampler->MaxAnisotropy > 2.0)
229ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_4;
230ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         else
231ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_2;
2326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
2341f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         switch (sampler->MagFilter) {
2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_NEAREST:
2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_NEAREST;
2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_LINEAR:
2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_LINEAR;
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         default:
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            return GL_FALSE;
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2461f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      lodbias = (int) ((tUnit->LodBias + sampler->LodBias) * 16.0);
247d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias < -256)
248d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = -256;
249d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias > 255)
250d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = 255;
251d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      state[I915_TEXREG_SS2] = ((lodbias << SS2_LOD_BIAS_SHIFT) &
252d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao                                SS2_LOD_BIAS_MASK);
2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* YUV conversion:
2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2561f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul      if (firstImage->TexFormat == MESA_FORMAT_YCBCR ||
2571f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul          firstImage->TexFormat == MESA_FORMAT_YCBCR_REV)
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION;
2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Shadow:
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2621f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB &&
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          tObj->Target != GL_TEXTURE_3D) {
26475e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         if (tObj->Target == GL_TEXTURE_1D)
26575e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao            return GL_FALSE;
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |=
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (SS2_SHADOW_ENABLE |
2691f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt             intel_translate_shadow_compare_func(sampler->CompareFunc));
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
27175e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         minFilt = FILTER_4X4_FLAT;
27275e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         magFilt = FILTER_4X4_FLAT;
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 (mipFilt << SS2_MIP_FILTER_SHIFT) |
277ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 (magFilt << SS2_MAG_FILTER_SHIFT) |
278ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 aniso);
2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2821f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum ws = sampler->WrapS;
2831f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wt = sampler->WrapT;
2841f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wr = sampler->WrapR;
285b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      float minlod;
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2878a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      /* We program 1D textures as 2D textures, so the 2D texcoord could
2888a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * result in sampling border values if we don't set the T wrap to
2898a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * repeat.
2908a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       */
2918a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      if (tObj->Target == GL_TEXTURE_1D)
2928a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt	 wt = GL_REPEAT;
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* 3D textures don't seem to respect the border color.
2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Fallback if there's ever a danger that they might refer to
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * it.
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       *
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Effectively this means fallback on 3D clamp or
2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * clamp_to_border.
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->Target == GL_TEXTURE_3D &&
3021f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt          (sampler->MinFilter != GL_NEAREST ||
3031f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt           sampler->MagFilter != GL_NEAREST) &&
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (ws == GL_CLAMP ||
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP ||
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wr == GL_CLAMP ||
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           ws == GL_CLAMP_TO_BORDER ||
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP_TO_BORDER || wr == GL_CLAMP_TO_BORDER))
3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         return GL_FALSE;
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
311c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      /* Only support TEXCOORDMODE_CLAMP_EDGE and TEXCOORDMODE_CUBE (not
312c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       * used) when using cube map texture coordinates
313c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       */
314c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
315c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          (((ws != GL_CLAMP) && (ws != GL_CLAMP_TO_EDGE)) ||
316cb453244caa15342bf229ee5ae16a78d038b8bdcXiang, Haihao           ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
317c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          return GL_FALSE;
3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
3206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |=
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3261f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      minlod = MIN2(sampler->MinLod, tObj->_MaxLevel - tObj->BaseLevel);
3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
328b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      state[I915_TEXREG_SS3] |= (U_FIXED(CLAMP(minlod, 0.0, 11.0), 4) <<
329f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt				 SS3_MIN_LOD_SHIFT);
330f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt
3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
33379c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   /* convert border color from float to ubyte */
3341f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[0], sampler->BorderColor.f[0]);
3351f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[1], sampler->BorderColor.f[1]);
3361f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[2], sampler->BorderColor.f[2]);
3371f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[3], sampler->BorderColor.f[3]);
3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3399aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) {
3409aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt      /* GL specs that border color for depth textures is taken from the
3419aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * R channel, while the hardware uses A.  Spam R into all the channels
3429aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * for safety.
3439aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       */
344ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[0],
345ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
346ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
347ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0]);
3489aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   } else {
349ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[3],
350ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
351ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[1],
352ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[2]);
3539aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   }
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), GL_TRUE);
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* memcmp was already disabled, but definitely won't work as the
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * region might now change and that wouldn't be detected:
3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit));
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]);
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]);
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]);
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]);
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]);
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]);
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   return GL_TRUE;
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915UpdateTextureState(struct intel_context *intel)
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLboolean ok = GL_TRUE;
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I915_TEX_UNITS && ok; i++) {
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) {
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_1D_BIT:
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_2D_BIT:
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_CUBE_BIT:
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_3D_BIT:
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, SS3_NORMALIZED_COORDS);
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_RECT_BIT:
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, 0);
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case 0:{
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            struct i915_context *i915 = i915_context(&intel->ctx);
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (i915->state.active & I915_UPLOAD_TEX(i))
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell               I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), GL_FALSE);
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    if (i915->state.tex_buffer[i] != NULL) {
40134474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt	       drm_intel_bo_unreference(i915->state.tex_buffer[i]);
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       i915->state.tex_buffer[i] = NULL;
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    }
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = GL_FALSE;
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   FALLBACK(intel, I915_FALLBACK_TEXTURE, !ok);
4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
415