brw_wm_sampler_state.c revision 241b7bc0a3e6277e15bb45887ad5533ffe692428
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining
79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the
89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including
99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish,
109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to
119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to
129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions:
139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the
159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial
169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software.
179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  *   Keith Whitwell <keith@tungstengraphics.com>
309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  */
319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_defines.h"
369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "macros.h"
389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Samplers aren't strictly wm state from the hardware's perspective,
429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * but that is the only situation in which we use them in this driver.
439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* The brw (and related graphics cores) do not support GL_CLAMP.  The
489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * Intel drivers for "other operating systems" implement GL_CLAMP as
499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * GL_CLAMP_TO_EDGE, so the same is done here.
509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLuint translate_wrap_mode( GLenum wrap )
529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch( wrap ) {
549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_REPEAT:
559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return BRW_TEXCOORDMODE_WRAP;
569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_CLAMP:
57ab999608582534bb5187a786b2ea437167f2d8a4Xiang, Haihao      return BRW_TEXCOORDMODE_CLAMP;
589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_CLAMP_TO_EDGE:
599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return BRW_TEXCOORDMODE_CLAMP; /* conform likes it this way */
609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_CLAMP_TO_BORDER:
619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return BRW_TEXCOORDMODE_CLAMP_BORDER;
629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_MIRRORED_REPEAT:
639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return BRW_TEXCOORDMODE_MIRROR;
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return BRW_TEXCOORDMODE_WRAP;
669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLuint U_FIXED(GLfloat value, GLuint frac_bits)
719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   value *= (1<<frac_bits);
739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   return value < 0 ? 0 : value;
749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLint S_FIXED(GLfloat value, GLuint frac_bits)
779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   return value * (1<<frac_bits);
799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLuint upload_default_color( struct brw_context *brw,
839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				    const GLfloat *color )
849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_sampler_default_color sdc;
869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   COPY_4V(sdc.color, color);
889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   return brw_cache_data( &brw->cache[BRW_SAMPLER_DEFAULT_COLOR], &sdc );
909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void brw_update_sampler_state( struct gl_texture_unit *texUnit,
969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				      struct gl_texture_object *texObj,
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				      GLuint sdc_gs_offset,
989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				      struct brw_sampler_state *sampler)
999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   _mesa_memset(sampler, 0, sizeof(*sampler));
1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (texObj->MinFilter) {
1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_NEAREST:
1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST;
1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_NONE;
1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINEAR:
1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
1099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_NONE;
1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_NEAREST_MIPMAP_NEAREST:
1129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST;
1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST;
1149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINEAR_MIPMAP_NEAREST:
1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST;
1189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_NEAREST_MIPMAP_LINEAR:
1209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST;
1219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR;
1229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case GL_LINEAR_MIPMAP_LINEAR:
1249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
1259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR;
1269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
1289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      break;
1299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Set Anisotropy:
1329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if ( texObj->MaxAnisotropy > 1.0 ) {
1349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC;
1359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC;
1369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (texObj->MaxAnisotropy > 2.0) {
1389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 sampler->ss3.max_aniso = MAX2((texObj->MaxAnisotropy - 2) / 2,
1399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				       BRW_ANISORATIO_16);
1409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   else {
1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      switch (texObj->MagFilter) {
1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      case GL_NEAREST:
1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
1469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 break;
1479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      case GL_LINEAR:
1489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
1499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 break;
1509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      default:
1519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 break;
1529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
1539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss1.r_wrap_mode = translate_wrap_mode(texObj->WrapR);
1569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss1.s_wrap_mode = translate_wrap_mode(texObj->WrapS);
1579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss1.t_wrap_mode = translate_wrap_mode(texObj->WrapT);
1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Fulsim complains if I don't do this.  Hardware doesn't mind:
1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#if 0
1629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (texObj->Target == GL_TEXTURE_CUBE_MAP_ARB) {
1639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CUBE;
1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CUBE;
1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CUBE;
1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#endif
1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Set shadow function:
1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (texObj->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) {
1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      /* Shadowing is "enabled" by emitting a particular sampler
1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt       * message (sample_c).  So need to recompile WM program when
1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt       * shadow comparison is enabled on each/any texture unit.
1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt       */
1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      sampler->ss0.shadow_function = intel_translate_compare_func(texObj->CompareFunc);
1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Set LOD bias:
1809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
181241b7bc0a3e6277e15bb45887ad5533ffe692428Xiang, Haihao   sampler->ss0.lod_bias = S_FIXED(CLAMP(texUnit->LodBias + texObj->LodBias, -16, 15), 6);
1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss0.lod_preclamp = 1; /* OpenGL mode */
1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */
1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Set BaseMipLevel, MaxLOD, MinLOD:
1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    *
1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * XXX: I don't think that using firstLevel, lastLevel works,
1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * because we always setup the surface state as if firstLevel ==
1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * level zero.  Probably have to subtract firstLevel from each of
1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    * these:
1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss0.base_level = U_FIXED(0, 1);
1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
19522bc3cdd49eb81d48ad4b8f06be0b9a9de624c91Xiang, Haihao   sampler->ss1.max_lod = U_FIXED(MIN2(MAX2(texObj->MaxLod, 0), 13), 6);
19622bc3cdd49eb81d48ad4b8f06be0b9a9de624c91Xiang, Haihao   sampler->ss1.min_lod = U_FIXED(MIN2(MAX2(texObj->MinLod, 0), 13), 6);
1979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   sampler->ss2.default_color_pointer = sdc_gs_offset >> 5;
1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* All samplers must be uploaded in a single contiguous array, which
2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * complicates various things.  However, this is still too confusing -
2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * FIXME: simplify all the different new texture state flags.
2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */
2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void upload_wm_samplers( struct brw_context *brw )
2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
2099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint unit;
2109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint sampler_count = 0;
2119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_TEXTURE */
2139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   for (unit = 0; unit < BRW_MAX_TEX_UNIT; unit++) {
2149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (brw->attribs.Texture->Unit[unit]._ReallyEnabled) {
2159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 struct gl_texture_unit *texUnit = &brw->attribs.Texture->Unit[unit];
2169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 struct gl_texture_object *texObj = texUnit->_Current;
2179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 GLuint sdc_gs_offset = upload_default_color(brw, texObj->BorderColor);
2199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_update_sampler_state(texUnit,
2219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				  texObj,
2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				  sdc_gs_offset,
2239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				  &brw->wm.sampler[unit]);
2249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 sampler_count = unit + 1;
2269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
2279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (brw->wm.sampler_count != sampler_count) {
2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw->wm.sampler_count = sampler_count;
2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw->wm.sampler_gs_offset = 0;
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   if (brw->wm.sampler_count)
2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw->wm.sampler_gs_offset =
2389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 brw_cache_data_sz(&brw->cache[BRW_SAMPLER],
2399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			   brw->wm.sampler,
2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt			   sizeof(struct brw_sampler_state) * brw->wm.sampler_count);
2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_samplers = {
2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
2469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa = _NEW_TEXTURE,
2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .brw = 0,
2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .cache = 0
2499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .update = upload_wm_samplers
2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
254