brw_wm_sampler_state.c revision a82a43e8d99e1715dd11c9c091b5ab734079b6a6
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 */ 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 695c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtstatic void 705c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtupload_default_color(struct brw_context *brw, struct gl_sampler_object *sampler, 715c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int unit) 729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 7330f25a10190632a971e2b214c443e54afa463eadEric Anholt struct intel_context *intel = &brw->intel; 745c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_context *ctx = &intel->ctx; 755c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; 765c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_object *texObj = texUnit->_Current; 775c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_image *firstImage = texObj->Image[0][texObj->BaseLevel]; 785c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt float color[4]; 795c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 805c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (firstImage->_BaseFormat == GL_DEPTH_COMPONENT) { 815c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt /* GL specs that border color for depth textures is taken from the 825c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt * R channel, while the hardware uses A. Spam R into all the 835c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt * channels for safety. 845c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt */ 855c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[0] = sampler->BorderColor.f[0]; 865c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[1] = sampler->BorderColor.f[0]; 875c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[2] = sampler->BorderColor.f[0]; 885c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[3] = sampler->BorderColor.f[0]; 895c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else { 905c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[0] = sampler->BorderColor.f[0]; 915c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[1] = sampler->BorderColor.f[1]; 925c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[2] = sampler->BorderColor.f[2]; 935c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt color[3] = sampler->BorderColor.f[3]; 945c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } 959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 9630f25a10190632a971e2b214c443e54afa463eadEric Anholt if (intel->gen >= 5) { 975c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gen5_sampler_default_color *sdc; 9830f25a10190632a971e2b214c443e54afa463eadEric Anholt 995c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc = brw_state_batch(brw, sizeof(*sdc), 32, &brw->wm.sdc_offset[unit]); 10030f25a10190632a971e2b214c443e54afa463eadEric Anholt 1015c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt memset(sdc, 0, sizeof(*sdc)); 1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1035c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[0], color[0]); 1045c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[1], color[1]); 1055c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[2], color[2]); 1065c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_UBYTE(sdc->ub[3], color[3]); 1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1085c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[0], color[0]); 1095c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[1], color[1]); 1105c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[2], color[2]); 1115c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_USHORT(sdc->us[3], color[3]); 1123e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 1135c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[0], color[0]); 1145c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[1], color[1]); 1155c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[2], color[2]); 1165c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt UNCLAMPED_FLOAT_TO_SHORT(sdc->s[3], color[3]); 117e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 1185c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[0] = _mesa_float_to_half(color[0]); 1195c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[1] = _mesa_float_to_half(color[1]); 1205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[2] = _mesa_float_to_half(color[2]); 1215c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->hf[3] = _mesa_float_to_half(color[3]); 1225c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1235c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[0] = sdc->s[0] >> 8; 1245c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[1] = sdc->s[1] >> 8; 1255c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[2] = sdc->s[2] >> 8; 1265c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->b[3] = sdc->s[3] >> 8; 1275c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1285c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[0] = color[0]; 1295c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[1] = color[1]; 1305c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[2] = color[2]; 1315c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc->f[3] = color[3]; 1325c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else { 1335c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct brw_sampler_default_color *sdc; 1345c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1355c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sdc = brw_state_batch(brw, sizeof(*sdc), 32, &brw->wm.sdc_offset[unit]); 1365c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 1375c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt COPY_4V(sdc->color, color); 1385c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } 1395c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt} 1403e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 1413e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt/** 1423e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * Sets the sampler state for a single unit based off of the sampler key 1433e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * entry. 1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 145956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wangstatic void brw_update_sampler_state(struct brw_context *brw, 1465c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int unit, 1473e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt struct brw_sampler_state *sampler) 1483e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt{ 149956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang struct intel_context *intel = &brw->intel; 1505c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_context *ctx = &intel->ctx; 1515c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; 1525c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_texture_object *texObj = texUnit->_Current; 1535c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct gl_sampler_object *gl_sampler = _mesa_get_samplerobj(ctx, unit); 154956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang 1555c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt switch (gl_sampler->MinFilter) { 1569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST: 1579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NONE; 1599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR: 1619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NONE; 1639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST_MIPMAP_NEAREST: 1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST; 1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR_MIPMAP_NEAREST: 1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST; 1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST_MIPMAP_LINEAR: 1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST; 1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR; 1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR_MIPMAP_LINEAR: 1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR; 1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR; 1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 1819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set Anisotropy: 1859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1865c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->MaxAnisotropy > 1.0) { 1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC; 1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC; 1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1905c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->MaxAnisotropy > 2.0) { 1915c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss3.max_aniso = MIN2((gl_sampler->MaxAnisotropy - 2) / 2, 1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_ANISORATIO_16); 1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else { 1965c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt switch (gl_sampler->MagFilter) { 1979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_NEAREST: 1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST; 1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case GL_LINEAR: 2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR; 2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2085c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.r_wrap_mode = translate_wrap_mode(gl_sampler->WrapR); 2095c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.s_wrap_mode = translate_wrap_mode(gl_sampler->WrapS); 2105c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.t_wrap_mode = translate_wrap_mode(gl_sampler->WrapT); 211e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 212956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang if (intel->gen >= 6 && 213956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang sampler->ss0.min_filter != sampler->ss0.mag_filter) 214956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang sampler->ss0.min_mag_neq = 1; 215956f866030f7bea5fc4a2de28c72e60bdc3a5b3dZhenyu Wang 216e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick /* Cube-maps on 965 and later must use the same wrap mode for all 3 217e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick * coordinate dimensions. Futher, only CUBE and CLAMP are valid. 218e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick */ 2195c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (texObj->Target == GL_TEXTURE_CUBE_MAP) { 2205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.CubeMapSeamless && 2215c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt (gl_sampler->MinFilter != GL_NEAREST || 2225c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt gl_sampler->MagFilter != GL_NEAREST)) { 223e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CUBE; 224e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CUBE; 225e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CUBE; 226e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick } else { 227e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 228e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 229e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP; 230e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick } 2315c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt } else if (texObj->Target == GL_TEXTURE_1D) { 232ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison /* There's a bug in 1D texture sampling - it actually pays 233ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * attention to the wrap_t value, though it should not. 234ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * Override the wrap_t value here to GL_REPEAT to keep 235ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison * any nonexistent border pixels from floating in. 236ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison */ 237ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_WRAP; 238ab6c4fa582972e25f8800c77b5dd5b3a83afc996Robert Ellison } 239e304c65a2b9c1005d6216e91d90a99001549a63dIan Romanick 2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set shadow function: 2429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2435c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (gl_sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { 2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Shadowing is "enabled" by emitting a particular sampler 2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * message (sample_c). So need to recompile WM program when 2469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * shadow comparison is enabled on each/any texture unit. 2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2483e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt sampler->ss0.shadow_function = 2495c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt intel_translate_shadow_compare_func(gl_sampler->CompareFunc); 2509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Set LOD bias: 2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2545c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss0.lod_bias = S_FIXED(CLAMP(texUnit->LodBias + 2555c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt gl_sampler->LodBias, -16, 15), 6); 2569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.lod_preclamp = 1; /* OpenGL mode */ 2589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */ 2599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2605b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt /* Set BaseMipLevel, MaxLOD, MinLOD: 2615b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * 2625b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * XXX: I don't think that using firstLevel, lastLevel works, 2635b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * because we always setup the surface state as if firstLevel == 2645b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * level zero. Probably have to subtract firstLevel from each of 2655b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt * these: 2665b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt */ 2675b3eb7538cd9ceb967b6e9e765896183e7c2c4d4Eric Anholt sampler->ss0.base_level = U_FIXED(0, 1); 2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2695c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.max_lod = U_FIXED(CLAMP(gl_sampler->MaxLod, 0, 13), 6); 2705c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt sampler->ss1.min_lod = U_FIXED(CLAMP(gl_sampler->MinLod, 0, 13), 6); 2719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2725c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt upload_default_color(brw, gl_sampler, unit); 2738c093a1fb0843e152d2a515c5127ccd5999b0d94Brian Paul 274a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt if (intel->gen >= 6) { 275a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt sampler->ss2.default_color_pointer = brw->wm.sdc_offset[unit] >> 5; 276a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt } else { 277a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt /* reloc */ 278a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt sampler->ss2.default_color_pointer = (intel->batch.bo->offset + 279a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt brw->wm.sdc_offset[unit]) >> 5; 280a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt 281a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt drm_intel_bo_emit_reloc(intel->batch.bo, 282a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt brw->wm.sampler_offset + 283a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt unit * sizeof(struct brw_sampler_state) + 284a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt offsetof(struct brw_sampler_state, ss2), 285a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt intel->batch.bo, brw->wm.sdc_offset[unit], 286a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt I915_GEM_DOMAIN_SAMPLER, 0); 287a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt } 2883e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt} 2893e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 2905c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 2913e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt/* All samplers must be uploaded in a single contiguous array, which 2923e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * complicates various things. However, this is still too confusing - 2933e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt * FIXME: simplify all the different new texture state flags. 2943e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt */ 2955c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtstatic void 2965c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholtprepare_wm_samplers(struct brw_context *brw) 2973e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt{ 298f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &brw->intel.ctx; 2995c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt struct brw_sampler_state *samplers; 3005c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt int i; 3013e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3025c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->wm.sampler_count = 0; 3035c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt for (i = 0; i < BRW_MAX_TEX_UNIT; i++) { 3045c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.Unit[i]._ReallyEnabled) 3055c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->wm.sampler_count = i + 1; 3069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 3079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3083e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt if (brw->wm.sampler_count == 0) 309f75843a517bd188639e6866db2a7b04de3524e16Dave Airlie return; 3103e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3115c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt samplers = brw_state_batch(brw, brw->wm.sampler_count * sizeof(*samplers), 3125c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 32, &brw->wm.sampler_offset); 3135c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt memset(samplers, 0, brw->wm.sampler_count * sizeof(*samplers)); 3143e3644c6e8f3559fd5bcd862d5edb627aceb3ecaEric Anholt 3155c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt for (i = 0; i < brw->wm.sampler_count; i++) { 3165c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt if (ctx->Texture.Unit[i]._ReallyEnabled) 3175c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw_update_sampler_state(brw, i, &samplers[i]); 31838bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt } 3195c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt 3205c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt brw->state.dirty.cache |= CACHE_NEW_SAMPLER; 32138bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt} 3229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_samplers = { 3249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 3259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .mesa = _NEW_TEXTURE, 3265c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt .brw = BRW_NEW_BATCH, 3279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .cache = 0 3289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 3295c742ea1ee0cea031cb99651155d0c7521f42b4eEric Anholt .prepare = prepare_wm_samplers, 3309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 3319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 333