16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/**************************************************************************
26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell *
3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2003 VMware, Inc.
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.
21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE 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
4271fe9437169cfdafda8814aa814bb85429fb6cfcMark Muellertranslate_texture_format(mesa_format mesa_format, GLenum DepthMode)
436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (mesa_format) {
4550a01d2acafb2a937e62b24258e2e777c0cd1489Mark Mueller   case MESA_FORMAT_L_UNORM8:
466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_L8;
4750a01d2acafb2a937e62b24258e2e777c0cd1489Mark Mueller   case MESA_FORMAT_I_UNORM8:
486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_I8;
4950a01d2acafb2a937e62b24258e2e777c0cd1489Mark Mueller   case MESA_FORMAT_A_UNORM8:
506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_8BIT | MT_8BIT_A8;
51eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_L8A8_UNORM:
526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_AY88;
53eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_B5G6R5_UNORM:
546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_RGB565;
55eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_B5G5R5A1_UNORM:
566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB1555;
57eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_B4G4R4A4_UNORM:
586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return MAPSURF_16BIT | MT_16BIT_ARGB4444;
59eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_B8G8R8A8_SRGB:
60ef145ba4ded6aafb28e3bda02fb348e6b8bff12aMark Mueller   case MESA_FORMAT_B8G8R8A8_UNORM:
61e624b77eb2d594cde053c73a530836e05227126aIan Romanick      return MAPSURF_32BIT | MT_32BIT_ARGB8888;
62ef145ba4ded6aafb28e3bda02fb348e6b8bff12aMark Mueller   case MESA_FORMAT_B8G8R8X8_UNORM:
634a253431abf43a0638afb43605b44a8742b72a60Brian Paul      return MAPSURF_32BIT | MT_32BIT_XRGB8888;
64ef145ba4ded6aafb28e3bda02fb348e6b8bff12aMark Mueller   case MESA_FORMAT_R8G8B8A8_UNORM:
659fe197c62611815ebe74248033271ad9fd07ae06Chia-I Wu      return MAPSURF_32BIT | MT_32BIT_ABGR8888;
666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR_REV:
676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_YCBCR:
696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_FXT1:
716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_FXT1:
726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
7350a01d2acafb2a937e62b24258e2e777c0cd1489Mark Mueller   case MESA_FORMAT_Z_UNORM16:
749e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      if (DepthMode == GL_ALPHA)
759e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_A16);
769e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else if (DepthMode == GL_INTENSITY)
779e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_I16);
789e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao      else
799e95fad02e1d8690deba91a8f30d722f039366ffXiang, Haihao          return (MAPSURF_16BIT | MT_16BIT_L16);
806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT1:
816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGB_DXT1:
824df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   case MESA_FORMAT_SRGB_DXT1:
834df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   case MESA_FORMAT_SRGBA_DXT1:
846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT3:
864df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   case MESA_FORMAT_SRGBA_DXT3:
876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case MESA_FORMAT_RGBA_DXT5:
894df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   case MESA_FORMAT_SRGBA_DXT5:
906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
91eeed49f5f290793870c60b5b635b977a732a1eb4Mark Mueller   case MESA_FORMAT_Z24_UNORM_S8_UINT:
92a487ef87fe4aa8c4b8e5c0d888bfb18727c8e570Kenneth Graunke   case MESA_FORMAT_Z24_UNORM_X8_UINT:
934b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      if (DepthMode == GL_ALPHA)
944b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8A24);
954b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else if (DepthMode == GL_INTENSITY)
964b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8I24);
974b377ae292f75645ef356bd3bfac407230faf73aEric Anholt      else
984b377ae292f75645ef356bd3bfac407230faf73aEric Anholt	 return (MAPSURF_32BIT | MT_32BIT_x8L24);
996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
100139e6c7c4a9c59be5f4b3f431ac393cc097326acMarius Predut      fprintf(stderr, "%s: bad image format %s\n", __func__,
1019a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt	      _mesa_get_format_name(mesa_format));
1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      abort();
1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return 0;
1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* The i915 (and related graphics cores) do not support GL_CLAMP.  The
1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Intel drivers for "other operating systems" implement GL_CLAMP as
1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_CLAMP_TO_EDGE, so the same is done here.
1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint
1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelltranslate_wrap_mode(GLenum wrap)
1166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   switch (wrap) {
1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_REPEAT:
1196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP:
1216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;   /* not quite correct */
1226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_EDGE:
1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_EDGE;
1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_CLAMP_TO_BORDER:
1256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_CLAMP_BORDER;
1266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   case GL_MIRRORED_REPEAT:
1276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_MIRROR;
1286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   default:
1296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      return TEXCOORDMODE_WRAP;
1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Recalculate all state from scratch.  Perhaps not the most
1366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * efficient, but this has gotten complex enough that we need
1376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * something which is understandable and reliable.
1386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */
1392e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool
1406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
1416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
142f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &intel->ctx;
1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct i915_context *i915 = i915_context(ctx);
144d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_unit *tUnit = &ctx->Texture.Unit[unit];
145d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao   struct gl_texture_object *tObj = tUnit->_Current;
1466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct intel_texture_object *intelObj = intel_texture_object(tObj);
1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   struct gl_texture_image *firstImage;
1481f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
14960894edeef973e86a73067276f658b72f84271b6Eric Anholt   GLuint *state = i915->state.Tex[unit], format;
150ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger   GLint lodbias, aniso = 0;
15179c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   GLubyte border[4];
1526785d6741db987469293d737e9b18f94d189b62eEric Anholt   GLfloat maxlod;
1536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
15410f214e5b248e5dd5f323c689549cd66d2f6ad22Vinson Lee   memset(state, 0, sizeof(*state));
1556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /*We need to refcount these. */
1576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   if (i915->state.tex_buffer[unit] != NULL) {
15934474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt       drm_intel_bo_unreference(i915->state.tex_buffer[unit]);
1606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       i915->state.tex_buffer[unit] = NULL;
1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
163a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   if (!intel_finalize_mipmap_tree(intel, unit))
1642e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke      return false;
1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* Get first image here, since intelObj->firstLevel will get set in
1676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * the intel_finalize_mipmap_tree() call above.
1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
1691b18b45d79e065e4e05a1e89e9d756d96258ded5Eric Anholt   firstImage = tObj->Image[0][tObj->BaseLevel];
1706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1718004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt   drm_intel_bo_reference(intelObj->mt->region->bo);
1728004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt   i915->state.tex_buffer[unit] = intelObj->mt->region->bo;
17302ebad900db4ef1ac42cbfb41b433919a4c857a2Kristian Høgsberg   i915->state.tex_offset[unit] = intelObj->mt->offset;
174a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt
175a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt   format = translate_texture_format(firstImage->TexFormat,
176c37efbfe4c415b6fd2d4f968220d7c9b62f11ecfPauli Nieminen				     tObj->DepthMode);
1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS3] =
1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) |
180165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt       ((firstImage->Width - 1) << MS3_WIDTH_SHIFT) | format);
181165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt
182165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   if (intelObj->mt->region->tiling != I915_TILING_NONE) {
183165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      state[I915_TEXREG_MS3] |= MS3_TILED_SURFACE;
184165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt      if (intelObj->mt->region->tiling == I915_TILING_Y)
185165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt	 state[I915_TEXREG_MS3] |= MS3_TILE_WALK;
186165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt   }
1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
188b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt   /* We get one field with fraction bits for the maximum addressable
189b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * (lowest resolution) LOD.  Use it to cover both MAX_LEVEL and
190b434a816d7a4b298e16a8b51b54e5a2d5ea28da8Eric Anholt    * MAX_LOD.
1916785d6741db987469293d737e9b18f94d189b62eEric Anholt    */
1921f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   maxlod = MIN2(sampler->MaxLod, tObj->_MaxLevel - tObj->BaseLevel);
1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   state[I915_TEXREG_MS4] =
19460894edeef973e86a73067276f658b72f84271b6Eric Anholt      ((((intelObj->mt->region->pitch / 4) - 1) << MS4_PITCH_SHIFT) |
195f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       MS4_CUBE_FACE_ENA_MASK |
1966785d6741db987469293d737e9b18f94d189b62eEric Anholt       (U_FIXED(CLAMP(maxlod, 0.0, 11.0), 2) << MS4_MAX_LOD_SHIFT) |
197f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt       ((firstImage->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
1986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      GLuint minFilt, mipFilt, magFilt;
2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2031f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      switch (sampler->MinFilter) {
2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST:
2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR:
2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NONE;
2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_NEAREST:
2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_NEAREST:
2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_NEAREST;
2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_NEAREST_MIPMAP_LINEAR:
2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_NEAREST;
2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      case GL_LINEAR_MIPMAP_LINEAR:
2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_LINEAR;
2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         mipFilt = MIPFILTER_LINEAR;
2276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         break;
2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      default:
2292e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke         return false;
2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2321f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->MaxAnisotropy > 1.0) {
2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         minFilt = FILTER_ANISOTROPIC;
2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         magFilt = FILTER_ANISOTROPIC;
2351f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         if (sampler->MaxAnisotropy > 2.0)
236ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_4;
237ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger         else
238ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger            aniso = SS2_MAX_ANISO_2;
2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      else {
2411f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt         switch (sampler->MagFilter) {
2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_NEAREST:
2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_NEAREST;
2446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         case GL_LINEAR:
2466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            magFilt = FILTER_LINEAR;
2476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
2486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         default:
2492e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke            return false;
2506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
2516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2531f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      lodbias = (int) ((tUnit->LodBias + sampler->LodBias) * 16.0);
254d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias < -256)
255d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = -256;
256d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      if (lodbias > 255)
257d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao          lodbias = 255;
258d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao      state[I915_TEXREG_SS2] = ((lodbias << SS2_LOD_BIAS_SHIFT) &
259d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao                                SS2_LOD_BIAS_MASK);
2606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* YUV conversion:
2626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2631f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul      if (firstImage->TexFormat == MESA_FORMAT_YCBCR ||
2641f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul          firstImage->TexFormat == MESA_FORMAT_YCBCR_REV)
2656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |= SS2_COLORSPACE_CONVERSION;
2666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* Shadow:
2686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
2691f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB &&
2706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          tObj->Target != GL_TEXTURE_3D) {
27175e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         if (tObj->Target == GL_TEXTURE_1D)
2722e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke            return false;
2736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         state[I915_TEXREG_SS2] |=
2756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            (SS2_SHADOW_ENABLE |
2761f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt             intel_translate_shadow_compare_func(sampler->CompareFunc));
2776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
27875e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         minFilt = FILTER_4X4_FLAT;
27975e4db18049f3284197c9a8deabd9dd74aa7920eXiang, Haihao         magFilt = FILTER_4X4_FLAT;
2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS2] |= ((minFilt << SS2_MIN_FILTER_SHIFT) |
2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell                                 (mipFilt << SS2_MIP_FILTER_SHIFT) |
284ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 (magFilt << SS2_MAG_FILTER_SHIFT) |
285ae69a046505d8c94cd3a59a9376310a904c35b3cRoland Scheidegger                                 aniso);
2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   {
2891f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum ws = sampler->WrapS;
2901f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wt = sampler->WrapT;
2911f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      GLenum wr = sampler->WrapR;
292b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      float minlod;
2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
2948a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      /* We program 1D textures as 2D textures, so the 2D texcoord could
2958a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * result in sampling border values if we don't set the T wrap to
2968a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       * repeat.
2978a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt       */
2988a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt      if (tObj->Target == GL_TEXTURE_1D)
2998a9afe71b8d89a2a967cb37f5b5b00d86de387bcEric Anholt	 wt = GL_REPEAT;
3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      /* 3D textures don't seem to respect the border color.
3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Fallback if there's ever a danger that they might refer to
3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * it.
3046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       *
3056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * Effectively this means fallback on 3D clamp or
3066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       * clamp_to_border.
3076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell       */
3086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      if (tObj->Target == GL_TEXTURE_3D &&
3091f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt          (sampler->MinFilter != GL_NEAREST ||
3101f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt           sampler->MagFilter != GL_NEAREST) &&
3116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (ws == GL_CLAMP ||
3126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP ||
3136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wr == GL_CLAMP ||
3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           ws == GL_CLAMP_TO_BORDER ||
3156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell           wt == GL_CLAMP_TO_BORDER || wr == GL_CLAMP_TO_BORDER))
3162e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke         return false;
3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
318c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      /* Only support TEXCOORDMODE_CLAMP_EDGE and TEXCOORDMODE_CUBE (not
319c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       * used) when using cube map texture coordinates
320c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao       */
321c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
322c8b505d8260cccf289c947c629471df8f5c81c0dXiang, Haihao          (((ws != GL_CLAMP) && (ws != GL_CLAMP_TO_EDGE)) ||
323cb453244caa15342bf229ee5ae16a78d038b8bdcXiang, Haihao           ((wt != GL_CLAMP) && (wt != GL_CLAMP_TO_EDGE))))
3242e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke          return false;
3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
32640c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu      /*
32740c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * According to 3DSTATE_MAP_STATE at page of 104 in Bspec
32840c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * Vol3d 3D Instructions:
32940c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       *   [DevGDG and DevAlv]: Must be a power of 2 for cube maps.
33040c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       *   [DevLPT, DevCST and DevBLB]: If not a power of 2, cube maps
33140c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       *      must have all faces enabled.
33240c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       *
33340c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * But, as I tested on pineview(DevBLB derived), the rendering is
33440c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * bad(you will find the color isn't samplered right in some
33540c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * fragments). After checking, it seems that the texture layout is
33640c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * wrong: making the width and height align of 4(although this
33740c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * doesn't make much sense) will fix this issue and also broke some
33840c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * others. Well, Bspec mentioned nothing about the layout alignment
33940c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * and layout for NPOT cube map.  I guess the Bspec just assume it's
34040c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * a POT cube map.
34140c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       *
34240c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       * Thus, I guess we need do this for other platforms as well.
34340c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu       */
34440c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu      if (tObj->Target == GL_TEXTURE_CUBE_MAP_ARB &&
3452484263fe97cebc9fa7a5c9de04c757dc6cc7713Anuj Phogat          !_mesa_is_pow_two(firstImage->Height))
34640c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu         return false;
34740c995c1fd7865f1b25765aa783fdadbf948b3ddYuanhan Liu
3486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] = ss3;     /* SS3_NORMALIZED_COORDS */
3496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |=
3516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) |
3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) |
3536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell          (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT));
3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3551f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt      minlod = MIN2(sampler->MinLod, tObj->_MaxLevel - tObj->BaseLevel);
3566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      state[I915_TEXREG_SS3] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
357b80a728f8a86cbd1efce9611d822ab73b5baeab9Eric Anholt      state[I915_TEXREG_SS3] |= (U_FIXED(CLAMP(minlod, 0.0, 11.0), 4) <<
358f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt				 SS3_MIN_LOD_SHIFT);
359f8f40b53a6a4551630e25bfd7f6e12334bb0f3f8Eric Anholt
3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3624df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   if (sampler->sRGBDecode == GL_DECODE_EXT &&
3634df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt       (_mesa_get_srgb_format_linear(firstImage->TexFormat) !=
3644df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt        firstImage->TexFormat)) {
3654df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt      state[I915_TEXREG_SS2] |= SS2_REVERSE_GAMMA_ENABLE;
3664df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt   }
3674df1b986d3e44dc035227054000a1d0e1846ef07Eric Anholt
36879c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul   /* convert border color from float to ubyte */
3691f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[0], sampler->BorderColor.f[0]);
3701f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[1], sampler->BorderColor.f[1]);
3711f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[2], sampler->BorderColor.f[2]);
3721f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt   CLAMPED_FLOAT_TO_UBYTE(border[3], sampler->BorderColor.f[3]);
3736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3749aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) {
3759aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt      /* GL specs that border color for depth textures is taken from the
3769aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * R channel, while the hardware uses A.  Spam R into all the channels
3779aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       * for safety.
3789aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt       */
379ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[0],
380ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
381ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
382ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0]);
3839aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   } else {
384ee64347979b4e22976910cb97869887f7de4241cEric Anholt      state[I915_TEXREG_SS4] = PACK_COLOR_8888(border[3],
385ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[0],
386ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[1],
387ee64347979b4e22976910cb97869887f7de4241cEric Anholt					       border[2]);
3889aec1288eeae8e87adc9a99f377be536892941b2Eric Anholt   }
3896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3912e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(unit), true);
3926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   /* memcmp was already disabled, but definitely won't work as the
3936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    * region might now change and that wouldn't be detected:
3946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell    */
3956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   I915_STATECHANGE(i915, I915_UPLOAD_TEX(unit));
3966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
3986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0
3996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS2] = 0x%x\n", state[I915_TEXREG_SS2]);
4006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS3] = 0x%x\n", state[I915_TEXREG_SS3]);
4016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_SS4] = 0x%x\n", state[I915_TEXREG_SS4]);
4026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS2] = 0x%x\n", state[I915_TEXREG_MS2]);
4036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS3] = 0x%x\n", state[I915_TEXREG_MS3]);
4046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   DBG(TEXTURE, "state[I915_TEXREG_MS4] = 0x%x\n", state[I915_TEXREG_MS4]);
4056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif
4066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4072e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   return true;
4086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
4096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid
4146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli915UpdateTextureState(struct intel_context *intel)
4156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{
4162e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke   bool ok = true;
4176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   GLuint i;
4186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   for (i = 0; i < I915_TEX_UNITS && ok; i++) {
42007b94c99a73481d08b285474db22106de1ca89fdEric Anholt      if (intel->ctx.Texture.Unit[i]._Current) {
42107b94c99a73481d08b285474db22106de1ca89fdEric Anholt         switch (intel->ctx.Texture.Unit[i]._Current->Target) {
42207b94c99a73481d08b285474db22106de1ca89fdEric Anholt         case GL_TEXTURE_1D:
42307b94c99a73481d08b285474db22106de1ca89fdEric Anholt         case GL_TEXTURE_2D:
42407b94c99a73481d08b285474db22106de1ca89fdEric Anholt         case GL_TEXTURE_CUBE_MAP:
42507b94c99a73481d08b285474db22106de1ca89fdEric Anholt         case GL_TEXTURE_3D:
42607b94c99a73481d08b285474db22106de1ca89fdEric Anholt            ok = i915_update_tex_unit(intel, i, SS3_NORMALIZED_COORDS);
42707b94c99a73481d08b285474db22106de1ca89fdEric Anholt            break;
42807b94c99a73481d08b285474db22106de1ca89fdEric Anholt         case GL_TEXTURE_RECTANGLE:
42907b94c99a73481d08b285474db22106de1ca89fdEric Anholt            ok = i915_update_tex_unit(intel, i, 0);
43007b94c99a73481d08b285474db22106de1ca89fdEric Anholt            break;
43107b94c99a73481d08b285474db22106de1ca89fdEric Anholt         default:
43207b94c99a73481d08b285474db22106de1ca89fdEric Anholt            ok = false;
4336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell            break;
4346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell         }
43507b94c99a73481d08b285474db22106de1ca89fdEric Anholt      } else {
43607b94c99a73481d08b285474db22106de1ca89fdEric Anholt         struct i915_context *i915 = i915_context(&intel->ctx);
43707b94c99a73481d08b285474db22106de1ca89fdEric Anholt         if (i915->state.active & I915_UPLOAD_TEX(i))
43807b94c99a73481d08b285474db22106de1ca89fdEric Anholt            I915_ACTIVESTATE(i915, I915_UPLOAD_TEX(i), false);
43907b94c99a73481d08b285474db22106de1ca89fdEric Anholt
44007b94c99a73481d08b285474db22106de1ca89fdEric Anholt         if (i915->state.tex_buffer[i] != NULL) {
44107b94c99a73481d08b285474db22106de1ca89fdEric Anholt            drm_intel_bo_unreference(i915->state.tex_buffer[i]);
44207b94c99a73481d08b285474db22106de1ca89fdEric Anholt            i915->state.tex_buffer[i] = NULL;
44307b94c99a73481d08b285474db22106de1ca89fdEric Anholt         }
4446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell      }
4456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   }
4466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell
4476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell   FALLBACK(intel, I915_FALLBACK_TEXTURE, !ok);
4486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell}
449