brw_wm_sampler_state.c revision 3984372104ec6ac5986dedb07b8ca99d53dede18
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 37ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h" 381f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt#include "main/samplerobj.h" 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 */ 513984372104ec6ac5986dedb07b8ca99d53dede18Kenneth GraunkeGLuint 523984372104ec6ac5986dedb07b8ca99d53dede18Kenneth Graunketranslate_wrap_mode(GLenum wrap) 539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch( wrap ) { 559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_REPEAT: 569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return BRW_TEXCOORDMODE_WRAP; 579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_CLAMP: 58ab999608582534bb5187a786b2ea437167f2d8a4Xiang, Haihao return BRW_TEXCOORDMODE_CLAMP; 599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_CLAMP_TO_EDGE: 609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return BRW_TEXCOORDMODE_CLAMP; /* conform likes it this way */ 619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_CLAMP_TO_BORDER: 629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return BRW_TEXCOORDMODE_CLAMP_BORDER; 639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_MIRRORED_REPEAT: 649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return BRW_TEXCOORDMODE_MIRROR; 659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return BRW_TEXCOORDMODE_WRAP; 679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 703984372104ec6ac5986dedb07b8ca99d53dede18Kenneth Graunkevoid 715c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtupload_default_color(struct brw_context *brw, struct gl_sampler_object *sampler, 725c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int unit) 739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 7430f25a10190632a971e2b214c443e54afa463eadEric Anholt struct intel_context *intel = &brw->intel; 755c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_context *ctx = &intel->ctx; 765c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; 775c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_object *texObj = texUnit->_Current; 785c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_image *firstImage = texObj->Image[0][texObj->BaseLevel]; 795c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt float color[4]; 805c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 815c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) { 825c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt /* GL specs that border color for depth textures is taken from the 835c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt * R channel, while the hardware uses A. Spam R into all the 845c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt * channels for safety. 855c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt */ 865c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[0] = sampler->BorderColor.f[0]; 875c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[1] = sampler->BorderColor.f[0]; 885c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[2] = sampler->BorderColor.f[0]; 895c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[3] = sampler->BorderColor.f[0]; 905c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else { 915c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[0] = sampler->BorderColor.f[0]; 925c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[1] = sampler->BorderColor.f[1]; 935c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[2] = sampler->BorderColor.f[2]; 945c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[3] = sampler->BorderColor.f[3]; 955c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } 969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 9730f25a10190632a971e2b214c443e54afa463eadEric Anholt if (intel->gen >= 5) { 985c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gen5_sampler_default_color *sdc; 9930f25a10190632a971e2b214c443e54afa463eadEric Anholt 1005c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc = brw_state_batch(brw, sizeof(*sdc), 32, &brw->wm.sdc_offset[unit]); 10130f25a10190632a971e2b214c443e54afa463eadEric Anholt 1025c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt memset(sdc, 0, sizeof(*sdc)); 1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1045c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[0], color[0]); 1055c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[1], color[1]); 1065c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[2], color[2]); 1075c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[3], color[3]); 1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1095c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[0], color[0]); 1105c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[1], color[1]); 1115c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[2], color[2]); 1125c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[3], color[3]); 1133e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 1145c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[0], color[0]); 1155c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[1], color[1]); 1165c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[2], color[2]); 1175c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[3], color[3]); 118e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 1195c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[0] = _mesa_float_to_half(color[0]); 1205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[1] = _mesa_float_to_half(color[1]); 1215c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[2] = _mesa_float_to_half(color[2]); 1225c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[3] = _mesa_float_to_half(color[3]); 1235c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1245c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[0] = sdc->s[0] >> 8; 1255c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[1] = sdc->s[1] >> 8; 1265c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[2] = sdc->s[2] >> 8; 1275c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[3] = sdc->s[3] >> 8; 1285c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1295c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[0] = color[0]; 1305c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[1] = color[1]; 1315c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[2] = color[2]; 1325c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[3] = color[3]; 1335c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else { 1345c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct brw_sampler_default_color *sdc; 1355c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1365c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc = brw_state_batch(brw, sizeof(*sdc), 32, &brw->wm.sdc_offset[unit]); 1375c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1385c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt COPY_4V(sdc->color, color); 1395c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } 1405c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt} 1413e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 1423e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt/** 1433e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * Sets the sampler state for a single unit based off of the sampler key 1443e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * entry. 1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 146956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wangstatic void brw_update_sampler_state(struct brw_context *brw, 1475c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int unit, 1483e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt struct brw_sampler_state *sampler) 1493e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt{ 150956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang struct intel_context *intel = &brw->intel; 1515c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_context *ctx = &intel->ctx; 1525c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; 1535c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_object *texObj = texUnit->_Current; 1545c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_sampler_object *gl_sampler = _mesa_get_samplerobj(ctx, unit); 155956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang 1565c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt switch (gl_sampler->MinFilter) { 1579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST: 1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NONE; 1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR: 1629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NONE; 1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST_MIPMAP_NEAREST: 1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST; 1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR_MIPMAP_NEAREST: 1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST; 1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST_MIPMAP_LINEAR: 1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR; 1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR_MIPMAP_LINEAR: 1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR; 1809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set Anisotropy: 1869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1875c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->MaxAnisotropy > 1.0) { 1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC; 1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC; 1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1915c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->MaxAnisotropy > 2.0) { 1925c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss3.max_aniso = MIN2((gl_sampler->MaxAnisotropy - 2) / 2, 1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_ANISORATIO_16); 1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else { 1975c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt switch (gl_sampler->MagFilter) { 1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST: 1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST; 2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR: 2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR; 2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2095c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.r_wrap_mode = translate_wrap_mode(gl_sampler->WrapR); 2105c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.s_wrap_mode = translate_wrap_mode(gl_sampler->WrapS); 2115c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.t_wrap_mode = translate_wrap_mode(gl_sampler->WrapT); 212e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 213956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang if (intel->gen >= 6 && 214956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang sampler->ss0.min_filter != sampler->ss0.mag_filter) 215956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang sampler->ss0.min_mag_neq = 1; 216956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang 217e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick /* Cube-maps on 965 and later must use the same wrap mode for all 3 218e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick * coordinate dimensions. Futher, only CUBE and CLAMP are valid. 219e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick */ 2205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (texObj->Target == GL_TEXTURE_CUBE_MAP) { 2215c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.CubeMapSeamless && 2225c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt (gl_sampler->MinFilter != GL_NEAREST || 2235c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt gl_sampler->MagFilter != GL_NEAREST)) { 224e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CUBE; 225e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CUBE; 226e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CUBE; 227e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick } else { 228e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 229e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 230e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 231e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick } 2325c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else if (texObj->Target == GL_TEXTURE_1D) { 233ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison /* There's a bug in 1D texture sampling - it actually pays 234ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * attention to the wrap_t value, though it should not. 235ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * Override the wrap_t value here to GL_REPEAT to keep 236ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * any nonexistent border pixels from floating in. 237ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison */ 238ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_WRAP; 239ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison } 240e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set shadow function: 2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2445c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { 2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Shadowing is "enabled" by emitting a particular sampler 2469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * message (sample_c). So need to recompile WM program when 2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * shadow comparison is enabled on each/any texture unit. 2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2493e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt sampler->ss0.shadow_function = 2505c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt intel_translate_shadow_compare_func(gl_sampler->CompareFunc); 2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set LOD bias: 2549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2555c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss0.lod_bias = S_FIXED(CLAMP(texUnit->LodBias + 2565c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt gl_sampler->LodBias, -16, 15), 6); 2579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.lod_preclamp = 1; /* OpenGL mode */ 2599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */ 2609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2615b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt /* Set BaseMipLevel, MaxLOD, MinLOD: 2625b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * 2635b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * XXX: I don't think that using firstLevel, lastLevel works, 2645b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * because we always setup the surface state as if firstLevel == 2655b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * level zero. Probably have to subtract firstLevel from each of 2665b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * these: 2675b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt */ 2685b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt sampler->ss0.base_level = U_FIXED(0, 1); 2699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2705c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.max_lod = U_FIXED(CLAMP(gl_sampler->MaxLod, 0, 13), 6); 2715c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.min_lod = U_FIXED(CLAMP(gl_sampler->MinLod, 0, 13), 6); 2729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2735c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt upload_default_color(brw, gl_sampler, unit); 2748c093a1fb0843e152d2a515c5127ccd5999b0d94Brian Paul 275a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt if (intel->gen >= 6) { 276a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt sampler->ss2.default_color_pointer = brw->wm.sdc_offset[unit] >> 5; 277a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt } else { 278a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt /* reloc */ 279a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt sampler->ss2.default_color_pointer = (intel->batch.bo->offset + 280a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt brw->wm.sdc_offset[unit]) >> 5; 281a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt 282a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt drm_intel_bo_emit_reloc(intel->batch.bo, 283a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt brw->wm.sampler_offset + 284a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt unit * sizeof(struct brw_sampler_state) + 285a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt offsetof(struct brw_sampler_state, ss2), 286a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt intel->batch.bo, brw->wm.sdc_offset[unit], 287a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt I915_GEM_DOMAIN_SAMPLER, 0); 288a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt } 2893e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt} 2903e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 2915c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 2923e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt/* All samplers must be uploaded in a single contiguous array, which 2933e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * complicates various things. However, this is still too confusing - 2943e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * FIXME: simplify all the different new texture state flags. 2953e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt */ 2965c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtstatic void 2975c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtprepare_wm_samplers(struct brw_context *brw) 2983e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt{ 299f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &brw->intel.ctx; 3005c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct brw_sampler_state *samplers; 3015c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int i; 3023e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3035c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->wm.sampler_count = 0; 3045c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt for (i = 0; i < BRW_MAX_TEX_UNIT; i++) { 3055c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.Unit[i]._ReallyEnabled) 3065c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->wm.sampler_count = i + 1; 3079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 3089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3093e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt if (brw->wm.sampler_count == 0) 310f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie return; 3113e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3125c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt samplers = brw_state_batch(brw, brw->wm.sampler_count * sizeof(*samplers), 3135c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 32, &brw->wm.sampler_offset); 3145c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt memset(samplers, 0, brw->wm.sampler_count * sizeof(*samplers)); 3153e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3165c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt for (i = 0; i < brw->wm.sampler_count; i++) { 3175c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.Unit[i]._ReallyEnabled) 3185c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw_update_sampler_state(brw, i, &samplers[i]); 31938bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt } 3205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 3215c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->state.dirty.cache |= CACHE_NEW_SAMPLER; 32238bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt} 3239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_samplers = { 3259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 3269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .mesa = _NEW_TEXTURE, 3275c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt .brw = BRW_NEW_BATCH, 3289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .cache = 0 3299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 3305c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt .prepare = prepare_wm_samplers, 3319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 3329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 334