i915_texstate.c revision 2e5a1a254ed81b1d3efa6064f48183eefac784d0
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;
639fe197c62611815ebe74248033271ad9fd07ae06Chia-I Wu   case MESA_FORMAT_RGBA8888_REV:
649fe197c62611815ebe74248033271ad9fd07ae06Chia-I Wu      return MAPSURF_32BIT | MT_32BIT_ABGR8888;
656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR_REV:
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR:
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_FXT1:
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_FXT1:
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_Z16:
739e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      if (DepthMode == GL_ALPHA)
749e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_A16);
759e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else if (DepthMode == GL_INTENSITY)
769e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_I16);
779e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else
789e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_L16);
796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT1:
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_DXT1:
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT3:
836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT5:
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
860adfd1021035e90995a25ec5f20b736e55075d92Xiang, Haihao   case MESA_FORMAT_S8_Z24:
876aae729d6ec3cb2d5677120742c1180e38815482Eric Anholt   case MESA_FORMAT_X8_Z24:
884b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      if (DepthMode == GL_ALPHA)
894b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8A24);
904b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else if (DepthMode == GL_INTENSITY)
914b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8I24);
924b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else
934b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8L24);
946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
959a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt      fprintf(stderr, "%s: bad image format %s\n", __FUNCTION__,
969a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt	      _mesa_get_format_name(mesa_format));
976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      abort();
986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return 0;
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* The i915 (and related graphics cores) do not support GL_CLAMP.  The
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Intel drivers for "other operating systems" implement GL_CLAMP as
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_CLAMP_TO_EDGE, so the same is done here.
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelltranslate_wrap_mode(GLenum wrap)
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (wrap) {
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPEAT:
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP:
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;   /* not quite correct */
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_EDGE:
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_BORDER:
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_BORDER;
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIRRORED_REPEAT:
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_MIRROR;
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Recalculate all state from scratch.  Perhaps not the most
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * efficient, but this has gotten complex enough that we need
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * something which is understandable and reliable.
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1342e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
137f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i915_context *i915 = i915_context(ctx);
139d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_unit *tUnit = &ctx->Texture.Unit[unit];
140d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_object *tObj = tUnit->_Current;
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_texture_object *intelObj = intel_texture_object(tObj);
1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct gl_texture_image *firstImage;
1431f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
144e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer   GLuint *state = i915->state.Tex[unit], format, pitch;
145ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger   GLint lodbias, aniso = 0;
14679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   GLubyte border[4];
1476785d6741db987469293d737e9b18f94d189b62eEric Anholt   GLfloat maxlod;
1486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   memset(state, 0, sizeof(state));
1506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /*We need to refcount these. */
1526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (i915->state.tex_buffer[unit] != NULL) {
15434474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt       drm_intel_bo_unreference(i915->state.tex_buffer[unit]);
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       i915->state.tex_buffer[unit] = NULL;
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
158a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   if (!intel_finalize_mipmap_tree(intel, unit))
1592e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke      return false;
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Get first image here, since intelObj->firstLevel will get set in
1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * the intel_finalize_mipmap_tree() call above.
1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1641b18b45d79e065e4e05a1e89e9d756d96258ded5Eric Anholt   firstImage = tObj->Image[0][tObj->BaseLevel];
1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1668004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt   drm_intel_bo_reference(intelObj->mt->region->bo);
1678004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt   i915->state.tex_buffer[unit] = intelObj->mt->region->bo;
168a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   i915->state.tex_offset[unit] = 0; /* Always the origin of the miptree */
169a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt
170a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   format = translate_texture_format(firstImage->TexFormat,
1711f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt				     sampler->DepthMode);
172362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt   pitch = intelObj->mt->region->pitch * intelObj->mt->cpp;
1736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS3] =
1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) |
176165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt       ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | format);
177165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt
178165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   if (intelObj->mt->region->tiling != I915_TILING_NONE) {
179165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      state[I915_TEXREG_MS3] |= MS3_TILED_SURFACE;
180165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      if (intelObj->mt->region->tiling == I915_TILING_Y)
181165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt	 state[I915_TEXREG_MS3] |= MS3_TILE_WALK;
182165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   }
1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
184b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt   /* We get one field with fraction bits for the maximum addressable
185b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * (lowest resolution) LOD.  Use it to cover both MAX_LEVEL and
186b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * MAX_LOD.
1876785d6741db987469293d737e9b18f94d189b62eEric Anholt    */
1881f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   maxlod = MIN2(sampler->MaxLod, tObj->_MaxLevel - tObj->BaseLevel);
1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS4] =
190f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt      ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) |
191f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       MS4_CUBE_FACE_ENA_MASK |
1926785d6741db987469293d737e9b18f94d189b62eEric Anholt       (U_FIXED(CLAMP(maxlod, 0.0, 11.0), 2) << MS4_MAX_LOD_SHIFT) |
193f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       ((firstImage->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint minFilt, mipFilt, magFilt;
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1991f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      switch (sampler->MinFilter) {
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST:
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR:
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_NEAREST:
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_NEAREST:
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_LINEAR:
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_LINEAR:
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
2252e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke         return false;
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2281f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->MaxAnisotropy > 1.0) {
2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_ANISOTROPIC;
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         magFilt = FILTER_ANISOTROPIC;
2311f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         if (sampler->MaxAnisotropy > 2.0)
232ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_4;
233ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         else
234ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_2;
2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
2371f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         switch (sampler->MagFilter) {
2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_NEAREST:
2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_NEAREST;
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_LINEAR:
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_LINEAR;
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         default:
2452e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke            return false;
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2491f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      lodbias = (int) ((tUnit->LodBias + sampler->LodBias) * 16.0);
250d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias < -256)
251d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = -256;
252d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias > 255)
253d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = 255;
254d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      state[I915_TEXREG_SS2] = ((lodbias << SS2_LOD_BIAS_SHIFT) &
255d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao                                SS2_LOD_BIAS_MASK);
2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* YUV conversion:
2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2591f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul      if (firstImage->TexFormat == MESA_FORMAT_YCBCR ||
2601f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul          firstImage->TexFormat == MESA_FORMAT_YCBCR_REV)
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION;
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Shadow:
2646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2651f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB &&
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          tObj->Target != GL_TEXTURE_3D) {
26775e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         if (tObj->Target == GL_TEXTURE_1D)
2682e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke            return false;
2696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |=
2716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (SS2_SHADOW_ENABLE |
2721f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt             intel_translate_shadow_compare_func(sampler->CompareFunc));
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
27475e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         minFilt = FILTER_4X4_FLAT;
27575e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         magFilt = FILTER_4X4_FLAT;
2766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 (mipFilt << SS2_MIP_FILTER_SHIFT) |
280ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 (magFilt << SS2_MAG_FILTER_SHIFT) |
281ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 aniso);
2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2851f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum ws = sampler->WrapS;
2861f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wt = sampler->WrapT;
2871f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wr = sampler->WrapR;
288b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      float minlod;
2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2908a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      /* We program 1D textures as 2D textures, so the 2D texcoord could
2918a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * result in sampling border values if we don't set the T wrap to
2928a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * repeat.
2938a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       */
2948a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      if (tObj->Target == GL_TEXTURE_1D)
2958a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt	 wt = GL_REPEAT;
2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* 3D textures don't seem to respect the border color.
2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Fallback if there's ever a danger that they might refer to
2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * it.
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       *
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Effectively this means fallback on 3D clamp or
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * clamp_to_border.
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->Target == GL_TEXTURE_3D &&
3051f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt          (sampler->MinFilter != GL_NEAREST ||
3061f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt           sampler->MagFilter != GL_NEAREST) &&
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (ws == GL_CLAMP ||
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP ||
3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wr == GL_CLAMP ||
3106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           ws == GL_CLAMP_TO_BORDER ||
3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP_TO_BORDER || wr == GL_CLAMP_TO_BORDER))
3122e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke         return false;
3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
314c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      /* Only support TEXCOORDMODE_CLAMP_EDGE and TEXCOORDMODE_CUBE (not
315c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       * used) when using cube map texture coordinates
316c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       */
317c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
318c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          (((ws != GL_CLAMP) && (ws != GL_CLAMP_TO_EDGE)) ||
319cb453244caa15342bf229ee5ae16a78d038b8bdcXiang, Haihao           ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
3202e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke          return false;
3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |=
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3291f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      minlod = MIN2(sampler->MinLod, tObj->_MaxLevel - tObj->BaseLevel);
3306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
331b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      state[I915_TEXREG_SS3] |= (U_FIXED(CLAMP(minlod, 0.0, 11.0), 4) <<
332f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt				 SS3_MIN_LOD_SHIFT);
333f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt
3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
33679c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   /* convert border color from float to ubyte */
3371f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[0], sampler->BorderColor.f[0]);
3381f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[1], sampler->BorderColor.f[1]);
3391f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[2], sampler->BorderColor.f[2]);
3401f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[3], sampler->BorderColor.f[3]);
3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3429aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) {
3439aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt      /* GL specs that border color for depth textures is taken from the
3449aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * R channel, while the hardware uses A.  Spam R into all the channels
3459aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * for safety.
3469aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       */
347ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[0],
348ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
349ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
350ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0]);
3519aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   } else {
352ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[3],
353ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
354ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[1],
355ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[2]);
3569aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   }
3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3592e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), true);
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* memcmp was already disabled, but definitely won't work as the
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * region might now change and that wouldn't be detected:
3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit));
3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0
3676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]);
3686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]);
3696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]);
3706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]);
3716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]);
3726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]);
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
3746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3752e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   return true;
3766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
3776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
3826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915UpdateTextureState(struct intel_context *intel)
3836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
3842e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   bool ok = true;
3856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
3866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I915_TEX_UNITS && ok; i++) {
3886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) {
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_1D_BIT:
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_2D_BIT:
3916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_CUBE_BIT:
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_3D_BIT:
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, SS3_NORMALIZED_COORDS);
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case TEXTURE_RECT_BIT:
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ok = i915_update_tex_unit(intel, i, 0);
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case 0:{
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            struct i915_context *i915 = i915_context(&intel->ctx);
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            if (i915->state.active & I915_UPLOAD_TEX(i))
4012e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke               I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), false);
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    if (i915->state.tex_buffer[i] != NULL) {
40434474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt	       drm_intel_bo_unreference(i915->state.tex_buffer[i]);
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	       i915->state.tex_buffer[i] = NULL;
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell	    }
4076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
4112e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke         ok = false;
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   FALLBACK(intel, I915_FALLBACK_TEXTURE, !ok);
4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
418