16b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/************************************************************************** 26b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 36b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 46b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * All Rights Reserved. 56b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 66b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 76b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * copy of this software and associated documentation files (the 86b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * "Software"), to deal in the Software without restriction, including 96b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the following conditions: 136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * The above copyright notice and this permission notice (including the 156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * of the Software. 176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * 266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell **************************************************************************/ 276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 28ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/mtypes.h" 29ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/enums.h" 30ee64347979b4e22976910cb97869887f7de4241cEric Anholt#include "main/colormac.h" 31973e821a633031fe5a8608b50beabb10af21430eEric Anholt#include "main/macros.h" 321f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt#include "main/samplerobj.h" 336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "intel_mipmap_tree.h" 3550b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie#include "intel_tex.h" 366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_context.h" 386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#include "i830_reg.h" 39973e821a633031fe5a8608b50beabb10af21430eEric Anholt#include "intel_chipset.h" 406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 43afbe605eff5af3739a76705a04a3c97a53c81b0dEric Anholttranslate_texture_format(GLuint mesa_format) 446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (mesa_format) { 466b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_L8: 476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_8BIT | MT_8BIT_L8; 486b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_I8: 496b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_8BIT | MT_8BIT_I8; 506b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_A8: 516b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_8BIT | MT_8BIT_I8; /* Kludge! */ 526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_AL88: 536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_16BIT | MT_16BIT_AY88; 546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGB565: 556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_16BIT | MT_16BIT_RGB565; 566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_ARGB1555: 576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_16BIT | MT_16BIT_ARGB1555; 586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_ARGB4444: 596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return MAPSURF_16BIT | MT_16BIT_ARGB4444; 606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_ARGB8888: 61e624b77eb2d594cde053c73a530836e05227126aIan Romanick return MAPSURF_32BIT | MT_32BIT_ARGB8888; 624a253431abf43a0638afb43605b44a8742b72a60Brian Paul case MESA_FORMAT_XRGB8888: 634a253431abf43a0638afb43605b44a8742b72a60Brian Paul return MAPSURF_32BIT | MT_32BIT_XRGB8888; 646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_YCBCR_REV: 656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_422 | MT_422_YCRCB_NORMAL); 666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_YCBCR: 676b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_422 | MT_422_YCRCB_SWAPY); 686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGB_FXT1: 696b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGBA_FXT1: 706b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); 716b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGBA_DXT1: 726b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGB_DXT1: 736b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); 746b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGBA_DXT3: 756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); 766b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case MESA_FORMAT_RGBA_DXT5: 776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); 786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 799a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt fprintf(stderr, "%s: bad image format %s\n", __FUNCTION__, 809a82d89a8fafde1b65c0843e022e99864b6d56b1Eric Anholt _mesa_get_format_name(mesa_format)); 816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell abort(); 826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return 0; 836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* The i915 (and related graphics cores) do not support GL_CLAMP. The 906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * Intel drivers for "other operating systems" implement GL_CLAMP as 916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * GL_CLAMP_TO_EDGE, so the same is done here. 926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellstatic GLuint 946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelltranslate_wrap_mode(GLenum wrap) 956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (wrap) { 976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_REPEAT: 986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXCOORDMODE_WRAP; 996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_CLAMP: 1006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_CLAMP_TO_EDGE: 1016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXCOORDMODE_CLAMP; /* not really correct */ 1026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_CLAMP_TO_BORDER: 1036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXCOORDMODE_CLAMP_BORDER; 1046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_MIRRORED_REPEAT: 1056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXCOORDMODE_MIRROR; 1066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 1076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell return TEXCOORDMODE_WRAP; 1086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 1106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell/* Recalculate all state from scratch. Perhaps not the most 1136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * efficient, but this has gotten complex enough that we need 1146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * something which is understandable and reliable. 1156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1162e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunkestatic bool 1176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3) 1186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 119f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &intel->ctx; 1206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(ctx); 121d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao struct gl_texture_unit *tUnit = &ctx->Texture.Unit[unit]; 122d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao struct gl_texture_object *tObj = tUnit->_Current; 1236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct intel_texture_object *intelObj = intel_texture_object(tObj); 1246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct gl_texture_image *firstImage; 1251f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); 126e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer GLuint *state = i830->state.Tex[unit], format, pitch; 127d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao GLint lodbias; 12879c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul GLubyte border[4]; 129a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt GLuint dst_x, dst_y; 1306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 131735070c45b403a9631415b09e9fd519f601f0229Chad Versace memset(state, 0, sizeof(*state)); 1326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 13350b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie /*We need to refcount these. */ 13450b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie 13550b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie if (i830->state.tex_buffer[unit] != NULL) { 13634474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(i830->state.tex_buffer[unit]); 13750b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie i830->state.tex_buffer[unit] = NULL; 13850b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie } 13950b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie 140a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt if (!intel_finalize_mipmap_tree(intel, unit)) 1412e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 1426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* Get first image here, since intelObj->firstLevel will get set in 1446b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * the intel_finalize_mipmap_tree() call above. 1456b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 1461b18b45d79e065e4e05a1e89e9d756d96258ded5Eric Anholt firstImage = tObj->Image[0][tObj->BaseLevel]; 1476b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1481b18b45d79e065e4e05a1e89e9d756d96258ded5Eric Anholt intel_miptree_get_image_offset(intelObj->mt, tObj->BaseLevel, 0, 0, 149a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt &dst_x, &dst_y); 150a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt 1518004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt drm_intel_bo_reference(intelObj->mt->region->bo); 1528004a1cb95b8a195f3f4bbaa8d39d2f3297167deEric Anholt i830->state.tex_buffer[unit] = intelObj->mt->region->bo; 153362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt pitch = intelObj->mt->region->pitch * intelObj->mt->cpp; 154362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt 155a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt /* XXX: This calculation is probably broken for tiled images with 156a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt * a non-page-aligned offset. 157a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt */ 158362c1bf75eb74de5b4655c481b74f79718ed4a34Eric Anholt i830->state.tex_offset[unit] = dst_x * intelObj->mt->cpp + dst_y * pitch; 159a232cc59e3f8ac8462c23b1a83e0ba60b451e681Eric Anholt 160afbe605eff5af3739a76705a04a3c97a53c81b0dEric Anholt format = translate_texture_format(firstImage->TexFormat); 1616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_TM0LI] = (_3DSTATE_LOAD_STATE_IMMEDIATE_2 | 1636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (LOAD_TEXTURE_MAP0 << unit) | 4); 1646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_TM0S1] = 1666b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (((firstImage->Height - 1) << TM0S1_HEIGHT_SHIFT) | 167e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer ((firstImage->Width - 1) << TM0S1_WIDTH_SHIFT) | format); 1686b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 169165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt if (intelObj->mt->region->tiling != I915_TILING_NONE) { 170165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[I830_TEXREG_TM0S1] |= TM0S1_TILED_SURFACE; 171165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt if (intelObj->mt->region->tiling == I915_TILING_Y) 172165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt state[I830_TEXREG_TM0S1] |= TM0S1_TILE_WALK; 173165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt } 174165ae5e2fb57bdb64b4cf01271b4effeb811f675Eric Anholt 1756b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_TM0S2] = 176e0885b84a0e10d6a3c976c8dc52a5fdc175635bbMichel Dänzer ((((pitch / 4) - 1) << TM0S2_PITCH_SHIFT) | TM0S2_CUBE_FACE_ENA_MASK); 1776b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell { 1796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (tObj->Target == GL_TEXTURE_CUBE_MAP) 1806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_CUBE] = (_3DSTATE_MAP_CUBE | MAP_UNIT(unit) | 1816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CUBE_NEGX_ENABLE | 1826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CUBE_POSX_ENABLE | 1836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CUBE_NEGY_ENABLE | 1846b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CUBE_POSY_ENABLE | 1856b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell CUBE_NEGZ_ENABLE | CUBE_POSZ_ENABLE); 1866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else 1876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_CUBE] = (_3DSTATE_MAP_CUBE | MAP_UNIT(unit)); 1886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 1896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1916b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell { 1946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint minFilt, mipFilt, magFilt; 195973e821a633031fe5a8608b50beabb10af21430eEric Anholt float maxlod; 196973e821a633031fe5a8608b50beabb10af21430eEric Anholt uint32_t minlod_fixed, maxlod_fixed; 1976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 1981f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt switch (sampler->MinFilter) { 1996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_NEAREST: 2006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_NEAREST; 2016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_NONE; 2026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINEAR: 2046b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_LINEAR; 2056b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_NONE; 2066b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2076b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_NEAREST_MIPMAP_NEAREST: 2086b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_NEAREST; 2096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_NEAREST; 2106b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2116b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINEAR_MIPMAP_NEAREST: 2126b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_LINEAR; 2136b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_NEAREST; 2146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2156b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_NEAREST_MIPMAP_LINEAR: 2166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_NEAREST; 2176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_LINEAR; 2186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINEAR_MIPMAP_LINEAR: 2206b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_LINEAR; 2216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell mipFilt = MIPFILTER_LINEAR; 2226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2242e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 2256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2271f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt if (sampler->MaxAnisotropy > 1.0) { 2286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell minFilt = FILTER_ANISOTROPIC; 2296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell magFilt = FILTER_ANISOTROPIC; 2306b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell else { 2321f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt switch (sampler->MagFilter) { 2336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_NEAREST: 2346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell magFilt = FILTER_NEAREST; 2356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case GL_LINEAR: 2376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell magFilt = FILTER_LINEAR; 2386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 2396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 2402e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 2416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2436b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2441f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt lodbias = (int) ((tUnit->LodBias + sampler->LodBias) * 16.0); 245d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao if (lodbias < -64) 246d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao lodbias = -64; 247d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao if (lodbias > 63) 248d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao lodbias = 63; 249d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao 250d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao state[I830_TEXREG_TM0S3] = ((lodbias << TM0S3_LOD_BIAS_SHIFT) & 251d30d9e42b758db452bfdb482b619a5f4c6d01037Xiang, Haihao TM0S3_LOD_BIAS_MASK); 2526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#if 0 2536b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* YUV conversion: 2546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR || 2566b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell firstImage->TexFormat->MesaFormat == MESA_FORMAT_YCBCR_REV) 2576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_TM0S3] |= SS2_COLORSPACE_CONVERSION; 2586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell#endif 2596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 260973e821a633031fe5a8608b50beabb10af21430eEric Anholt /* We get one field with fraction bits for the maximum 261973e821a633031fe5a8608b50beabb10af21430eEric Anholt * addressable (smallest resolution) LOD. Use it to cover both 262973e821a633031fe5a8608b50beabb10af21430eEric Anholt * MAX_LEVEL and MAX_LOD. 263973e821a633031fe5a8608b50beabb10af21430eEric Anholt */ 2641f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt minlod_fixed = U_FIXED(CLAMP(sampler->MinLod, 0.0, 11), 4); 2651f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt maxlod = MIN2(sampler->MaxLod, tObj->_MaxLevel - tObj->BaseLevel); 266973e821a633031fe5a8608b50beabb10af21430eEric Anholt if (intel->intelScreen->deviceID == PCI_CHIP_I855_GM || 267973e821a633031fe5a8608b50beabb10af21430eEric Anholt intel->intelScreen->deviceID == PCI_CHIP_I865_G) { 268973e821a633031fe5a8608b50beabb10af21430eEric Anholt maxlod_fixed = U_FIXED(CLAMP(maxlod, 0.0, 11.75), 2); 269973e821a633031fe5a8608b50beabb10af21430eEric Anholt maxlod_fixed = MAX2(maxlod_fixed, (minlod_fixed + 3) >> 2); 270973e821a633031fe5a8608b50beabb10af21430eEric Anholt state[I830_TEXREG_TM0S3] |= maxlod_fixed << TM0S3_MIN_MIP_SHIFT; 27139cc0ee3eaf0d0cae70d91ae33961053782662c8Eric Anholt state[I830_TEXREG_TM0S2] |= TM0S2_LOD_PRECLAMP; 272973e821a633031fe5a8608b50beabb10af21430eEric Anholt } else { 273973e821a633031fe5a8608b50beabb10af21430eEric Anholt maxlod_fixed = U_FIXED(CLAMP(maxlod, 0.0, 11), 0); 274973e821a633031fe5a8608b50beabb10af21430eEric Anholt maxlod_fixed = MAX2(maxlod_fixed, (minlod_fixed + 15) >> 4); 275973e821a633031fe5a8608b50beabb10af21430eEric Anholt state[I830_TEXREG_TM0S3] |= maxlod_fixed << TM0S3_MIN_MIP_SHIFT_830; 276973e821a633031fe5a8608b50beabb10af21430eEric Anholt } 277973e821a633031fe5a8608b50beabb10af21430eEric Anholt state[I830_TEXREG_TM0S3] |= minlod_fixed << TM0S3_MAX_MIP_SHIFT; 2786b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_TM0S3] |= ((minFilt << TM0S3_MIN_FILTER_SHIFT) | 2796b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (mipFilt << TM0S3_MIP_FILTER_SHIFT) | 2806b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (magFilt << TM0S3_MAG_FILTER_SHIFT)); 2816b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 2826b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2836b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell { 2841f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt GLenum ws = sampler->WrapS; 2851f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt GLenum wt = sampler->WrapT; 2866b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2876b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2886b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* 3D textures not available on i830 2896b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 2906b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (tObj->Target == GL_TEXTURE_3D) 2912e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return false; 2926b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 2936b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell state[I830_TEXREG_MCS] = (_3DSTATE_MAP_COORD_SET_CMD | 2946b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell MAP_UNIT(unit) | 2956b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_TEXCOORD_PARAMS | 2966b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ss3 | 2976b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ENABLE_ADDR_V_CNTL | 2986b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXCOORD_ADDR_V_MODE(translate_wrap_mode(wt)) 2996b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell | ENABLE_ADDR_U_CNTL | 3006b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell TEXCOORD_ADDR_U_MODE(translate_wrap_mode 3016b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell (ws))); 3026b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3036b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 30479c55e55f808d77cb0dff7cda826719d5fda3c7dBrian Paul /* convert border color from float to ubyte */ 3051f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt CLAMPED_FLOAT_TO_UBYTE(border[0], sampler->BorderColor.f[0]); 3061f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt CLAMPED_FLOAT_TO_UBYTE(border[1], sampler->BorderColor.f[1]); 3071f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt CLAMPED_FLOAT_TO_UBYTE(border[2], sampler->BorderColor.f[2]); 3081f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt CLAMPED_FLOAT_TO_UBYTE(border[3], sampler->BorderColor.f[3]); 3096b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 310ee64347979b4e22976910cb97869887f7de4241cEric Anholt state[I830_TEXREG_TM0S4] = PACK_COLOR_8888(border[3], 311ee64347979b4e22976910cb97869887f7de4241cEric Anholt border[0], 312ee64347979b4e22976910cb97869887f7de4241cEric Anholt border[1], 313ee64347979b4e22976910cb97869887f7de4241cEric Anholt border[2]); 3146b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3152e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke I830_ACTIVESTATE(i830, I830_UPLOAD_TEX(unit), true); 3166b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell /* memcmp was already disabled, but definitely won't work as the 3176b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell * region might now change and that wouldn't be detected: 3186b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell */ 3196b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell I830_STATECHANGE(i830, I830_UPLOAD_TEX(unit)); 3202e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke return true; 3216b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 3226b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3236b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3246b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3256b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3266b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwellvoid 3276b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwelli830UpdateTextureState(struct intel_context *intel) 3286b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell{ 3296b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell struct i830_context *i830 = i830_context(&intel->ctx); 3302e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke bool ok = true; 3316b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell GLuint i; 3326b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3336b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell for (i = 0; i < I830_TEX_UNITS && ok; i++) { 3346b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell switch (intel->ctx.Texture.Unit[i]._ReallyEnabled) { 3356b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXTURE_1D_BIT: 3366b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXTURE_2D_BIT: 3376b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXTURE_CUBE_BIT: 3386b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ok = i830_update_tex_unit(intel, i, TEXCOORDS_ARE_NORMAL); 3396b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3406b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXTURE_RECT_BIT: 3416b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell ok = i830_update_tex_unit(intel, i, TEXCOORDS_ARE_IN_TEXELUNITS); 3426b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 34350b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie case 0:{ 34450b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie struct i830_context *i830 = i830_context(&intel->ctx); 34550b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie if (i830->state.active & I830_UPLOAD_TEX(i)) 3462e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke I830_ACTIVESTATE(i830, I830_UPLOAD_TEX(i), false); 34750b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie 34850b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie if (i830->state.tex_buffer[i] != NULL) { 34934474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(i830->state.tex_buffer[i]); 35050b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie i830->state.tex_buffer[i] = NULL; 35150b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie } 3526b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 35350b3f5654e24f0848cda5dc60f21b2c3256b9437Dave Airlie } 3546b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell case TEXTURE_3D_BIT: 3556b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell default: 3562e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke ok = false; 3576b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell break; 3586b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3596b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell } 3606b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3616b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell FALLBACK(intel, I830_FALLBACK_TEXTURE, !ok); 3626b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell 3636b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell if (ok) 3646b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell i830EmitTextureBlend(i830); 3656b9e31f3eb3dbe20cbc8493b963bbc6530e392c6Keith Whitwell} 366