1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2003 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "pipe/p_context.h" 29bf215546Sopenharmony_ci#include "pipe/p_state.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "i915_context.h" 32bf215546Sopenharmony_ci#include "i915_reg.h" 33bf215546Sopenharmony_ci#include "i915_resource.h" 34bf215546Sopenharmony_ci#include "i915_state.h" 35bf215546Sopenharmony_ci#include "i915_state_inlines.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci/* 38bf215546Sopenharmony_ci * A note about min_lod & max_lod. 39bf215546Sopenharmony_ci * 40bf215546Sopenharmony_ci * There is a circular dependancy between the sampler state 41bf215546Sopenharmony_ci * and the map state to be submitted to hw. 42bf215546Sopenharmony_ci * 43bf215546Sopenharmony_ci * Two condition must be meet: 44bf215546Sopenharmony_ci * min_lod =< max_lod == true 45bf215546Sopenharmony_ci * max_lod =< last_level == true 46bf215546Sopenharmony_ci * 47bf215546Sopenharmony_ci * 48bf215546Sopenharmony_ci * This is all fine and dandy if it were for the fact that max_lod 49bf215546Sopenharmony_ci * is set on the map state instead of the sampler state. That is 50bf215546Sopenharmony_ci * the max_lod we submit on map is: 51bf215546Sopenharmony_ci * max_lod = MIN2(last_level, max_lod); 52bf215546Sopenharmony_ci * 53bf215546Sopenharmony_ci * So we need to update the map state when we change samplers and 54bf215546Sopenharmony_ci * we need to change the sampler state when map state is changed. 55bf215546Sopenharmony_ci * The first part is done by calling update_texture in update_samplers 56bf215546Sopenharmony_ci * and the second part is done else where in code tracking the state 57bf215546Sopenharmony_ci * changes. 58bf215546Sopenharmony_ci */ 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci/*********************************************************************** 61bf215546Sopenharmony_ci * Samplers 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci/** 65bf215546Sopenharmony_ci * Compute i915 texture sampling state. 66bf215546Sopenharmony_ci * 67bf215546Sopenharmony_ci * Recalculate all state from scratch. Perhaps not the most 68bf215546Sopenharmony_ci * efficient, but this has gotten complex enough that we need 69bf215546Sopenharmony_ci * something which is understandable and reliable. 70bf215546Sopenharmony_ci * \param state returns the 3 words of compute state 71bf215546Sopenharmony_ci */ 72bf215546Sopenharmony_cistatic void 73bf215546Sopenharmony_ciupdate_sampler(struct i915_context *i915, uint32_t unit, 74bf215546Sopenharmony_ci const struct i915_sampler_state *sampler, 75bf215546Sopenharmony_ci const struct i915_texture *tex, unsigned state[3]) 76bf215546Sopenharmony_ci{ 77bf215546Sopenharmony_ci const struct pipe_resource *pt = &tex->b; 78bf215546Sopenharmony_ci unsigned minlod, lastlod; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci state[0] = sampler->state[0]; 81bf215546Sopenharmony_ci state[1] = sampler->state[1]; 82bf215546Sopenharmony_ci state[2] = sampler->state[2]; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci if (pt->format == PIPE_FORMAT_UYVY || pt->format == PIPE_FORMAT_YUYV) 85bf215546Sopenharmony_ci state[0] |= SS2_COLORSPACE_CONVERSION; 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci if (util_format_is_srgb(pt->format)) { 88bf215546Sopenharmony_ci state[0] |= SS2_REVERSE_GAMMA_ENABLE; 89bf215546Sopenharmony_ci } 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci /* There is no HW support for 1D textures, so we just make them 2D textures 92bf215546Sopenharmony_ci * with h=1, but that means we need to make the Y coordinate not contribute 93bf215546Sopenharmony_ci * to bringing any border color in. Clearing it sets it to WRAP. 94bf215546Sopenharmony_ci */ 95bf215546Sopenharmony_ci if (pt->target == PIPE_TEXTURE_1D) { 96bf215546Sopenharmony_ci state[1] &= ~SS3_TCY_ADDR_MODE_MASK; 97bf215546Sopenharmony_ci } 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci /* The GLES2 spec says textures are incomplete (return 0,0,0,1) if: 100bf215546Sopenharmony_ci * 101bf215546Sopenharmony_ci * "A cube map sampler is called, any of the corresponding texture images are 102bf215546Sopenharmony_ci * non-power-of-two images, and either the texture wrap mode is not 103bf215546Sopenharmony_ci * CLAMP_TO_EDGE, or the minification filter is neither NEAREST nor LINEAR." 104bf215546Sopenharmony_ci * 105bf215546Sopenharmony_ci * while the i915 spec says: 106bf215546Sopenharmony_ci * 107bf215546Sopenharmony_ci * "When using cube map texture coordinates, only TEXCOORDMODE_CLAMP and * 108bf215546Sopenharmony_ci * TEXCOORDMODE_CUBE settings are valid, and each TC component must have the 109bf215546Sopenharmony_ci * same Address Control mode. TEXCOORDMODE_CUBE is not valid unless the 110bf215546Sopenharmony_ci * width and height of the cube map are power-of-2." 111bf215546Sopenharmony_ci * 112bf215546Sopenharmony_ci * We don't expose support for the seamless cube map extension, so always use 113bf215546Sopenharmony_ci * edge clamping. 114bf215546Sopenharmony_ci */ 115bf215546Sopenharmony_ci if (pt->target == PIPE_TEXTURE_CUBE) { 116bf215546Sopenharmony_ci state[1] &= ~(SS3_TCX_ADDR_MODE_MASK | SS3_TCY_ADDR_MODE_MASK | 117bf215546Sopenharmony_ci SS3_TCZ_ADDR_MODE_MASK); 118bf215546Sopenharmony_ci state[1] |= (TEXCOORDMODE_CLAMP_EDGE << SS3_TCX_ADDR_MODE_SHIFT); 119bf215546Sopenharmony_ci state[1] |= (TEXCOORDMODE_CLAMP_EDGE << SS3_TCY_ADDR_MODE_SHIFT); 120bf215546Sopenharmony_ci state[1] |= (TEXCOORDMODE_CLAMP_EDGE << SS3_TCZ_ADDR_MODE_SHIFT); 121bf215546Sopenharmony_ci } 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci /* 3D textures don't seem to respect the border color. 124bf215546Sopenharmony_ci * Fallback if there's ever a danger that they might refer to 125bf215546Sopenharmony_ci * it. 126bf215546Sopenharmony_ci * 127bf215546Sopenharmony_ci * Effectively this means fallback on 3D clamp or 128bf215546Sopenharmony_ci * clamp_to_border. 129bf215546Sopenharmony_ci * 130bf215546Sopenharmony_ci * XXX: Check if this is true on i945. 131bf215546Sopenharmony_ci * XXX: Check if this bug got fixed in release silicon. 132bf215546Sopenharmony_ci */ 133bf215546Sopenharmony_ci#if 0 134bf215546Sopenharmony_ci { 135bf215546Sopenharmony_ci const unsigned ws = sampler->templ->wrap_s; 136bf215546Sopenharmony_ci const unsigned wt = sampler->templ->wrap_t; 137bf215546Sopenharmony_ci const unsigned wr = sampler->templ->wrap_r; 138bf215546Sopenharmony_ci if (pt->target == PIPE_TEXTURE_3D && 139bf215546Sopenharmony_ci (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || 140bf215546Sopenharmony_ci sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && 141bf215546Sopenharmony_ci (ws == PIPE_TEX_WRAP_CLAMP || 142bf215546Sopenharmony_ci wt == PIPE_TEX_WRAP_CLAMP || 143bf215546Sopenharmony_ci wr == PIPE_TEX_WRAP_CLAMP || 144bf215546Sopenharmony_ci ws == PIPE_TEX_WRAP_CLAMP_TO_BORDER || 145bf215546Sopenharmony_ci wt == PIPE_TEX_WRAP_CLAMP_TO_BORDER || 146bf215546Sopenharmony_ci wr == PIPE_TEX_WRAP_CLAMP_TO_BORDER)) { 147bf215546Sopenharmony_ci if (i915->conformance_mode > 0) { 148bf215546Sopenharmony_ci assert(0); 149bf215546Sopenharmony_ci /* sampler->fallback = true; */ 150bf215546Sopenharmony_ci /* TODO */ 151bf215546Sopenharmony_ci } 152bf215546Sopenharmony_ci } 153bf215546Sopenharmony_ci } 154bf215546Sopenharmony_ci#endif 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci /* See note at the top of file */ 157bf215546Sopenharmony_ci minlod = sampler->minlod; 158bf215546Sopenharmony_ci lastlod = pt->last_level << 4; 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci if (lastlod < minlod) { 161bf215546Sopenharmony_ci minlod = lastlod; 162bf215546Sopenharmony_ci } 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci state[1] |= (sampler->minlod << SS3_MIN_LOD_SHIFT); 165bf215546Sopenharmony_ci state[1] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT); 166bf215546Sopenharmony_ci} 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci/*********************************************************************** 169bf215546Sopenharmony_ci * Sampler views 170bf215546Sopenharmony_ci */ 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_cistatic uint32_t 173bf215546Sopenharmony_citranslate_texture_format(enum pipe_format pipeFormat, 174bf215546Sopenharmony_ci const struct pipe_sampler_view *view) 175bf215546Sopenharmony_ci{ 176bf215546Sopenharmony_ci if ((view->swizzle_r != PIPE_SWIZZLE_X || 177bf215546Sopenharmony_ci view->swizzle_g != PIPE_SWIZZLE_Y || 178bf215546Sopenharmony_ci view->swizzle_b != PIPE_SWIZZLE_Z || 179bf215546Sopenharmony_ci view->swizzle_a != PIPE_SWIZZLE_W) && 180bf215546Sopenharmony_ci pipeFormat != PIPE_FORMAT_Z24_UNORM_S8_UINT && 181bf215546Sopenharmony_ci pipeFormat != PIPE_FORMAT_Z24X8_UNORM) 182bf215546Sopenharmony_ci debug_printf("i915: unsupported texture swizzle for format %d\n", 183bf215546Sopenharmony_ci pipeFormat); 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci switch (pipeFormat) { 186bf215546Sopenharmony_ci case PIPE_FORMAT_L8_UNORM: 187bf215546Sopenharmony_ci return MAPSURF_8BIT | MT_8BIT_L8; 188bf215546Sopenharmony_ci case PIPE_FORMAT_I8_UNORM: 189bf215546Sopenharmony_ci return MAPSURF_8BIT | MT_8BIT_I8; 190bf215546Sopenharmony_ci case PIPE_FORMAT_A8_UNORM: 191bf215546Sopenharmony_ci return MAPSURF_8BIT | MT_8BIT_A8; 192bf215546Sopenharmony_ci case PIPE_FORMAT_L8A8_UNORM: 193bf215546Sopenharmony_ci return MAPSURF_16BIT | MT_16BIT_AY88; 194bf215546Sopenharmony_ci case PIPE_FORMAT_B5G6R5_UNORM: 195bf215546Sopenharmony_ci return MAPSURF_16BIT | MT_16BIT_RGB565; 196bf215546Sopenharmony_ci case PIPE_FORMAT_B5G5R5A1_UNORM: 197bf215546Sopenharmony_ci return MAPSURF_16BIT | MT_16BIT_ARGB1555; 198bf215546Sopenharmony_ci case PIPE_FORMAT_B4G4R4A4_UNORM: 199bf215546Sopenharmony_ci return MAPSURF_16BIT | MT_16BIT_ARGB4444; 200bf215546Sopenharmony_ci case PIPE_FORMAT_B10G10R10A2_UNORM: 201bf215546Sopenharmony_ci return MAPSURF_32BIT | MT_32BIT_ARGB2101010; 202bf215546Sopenharmony_ci case PIPE_FORMAT_B8G8R8A8_UNORM: 203bf215546Sopenharmony_ci case PIPE_FORMAT_B8G8R8A8_SRGB: 204bf215546Sopenharmony_ci return MAPSURF_32BIT | MT_32BIT_ARGB8888; 205bf215546Sopenharmony_ci case PIPE_FORMAT_B8G8R8X8_UNORM: 206bf215546Sopenharmony_ci return MAPSURF_32BIT | MT_32BIT_XRGB8888; 207bf215546Sopenharmony_ci case PIPE_FORMAT_R8G8B8A8_UNORM: 208bf215546Sopenharmony_ci return MAPSURF_32BIT | MT_32BIT_ABGR8888; 209bf215546Sopenharmony_ci case PIPE_FORMAT_R8G8B8X8_UNORM: 210bf215546Sopenharmony_ci return MAPSURF_32BIT | MT_32BIT_XBGR8888; 211bf215546Sopenharmony_ci case PIPE_FORMAT_YUYV: 212bf215546Sopenharmony_ci return (MAPSURF_422 | MT_422_YCRCB_NORMAL); 213bf215546Sopenharmony_ci case PIPE_FORMAT_UYVY: 214bf215546Sopenharmony_ci return (MAPSURF_422 | MT_422_YCRCB_SWAPY); 215bf215546Sopenharmony_ci case PIPE_FORMAT_FXT1_RGB: 216bf215546Sopenharmony_ci case PIPE_FORMAT_FXT1_RGBA: 217bf215546Sopenharmony_ci return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); 218bf215546Sopenharmony_ci case PIPE_FORMAT_Z16_UNORM: 219bf215546Sopenharmony_ci return (MAPSURF_16BIT | MT_16BIT_L16); 220bf215546Sopenharmony_ci case PIPE_FORMAT_DXT1_RGB: 221bf215546Sopenharmony_ci case PIPE_FORMAT_DXT1_SRGB: 222bf215546Sopenharmony_ci return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1_RGB); 223bf215546Sopenharmony_ci case PIPE_FORMAT_DXT1_RGBA: 224bf215546Sopenharmony_ci case PIPE_FORMAT_DXT1_SRGBA: 225bf215546Sopenharmony_ci return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); 226bf215546Sopenharmony_ci case PIPE_FORMAT_DXT3_RGBA: 227bf215546Sopenharmony_ci case PIPE_FORMAT_DXT3_SRGBA: 228bf215546Sopenharmony_ci return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); 229bf215546Sopenharmony_ci case PIPE_FORMAT_DXT5_RGBA: 230bf215546Sopenharmony_ci case PIPE_FORMAT_DXT5_SRGBA: 231bf215546Sopenharmony_ci return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); 232bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 233bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: { 234bf215546Sopenharmony_ci if (view->swizzle_r == PIPE_SWIZZLE_X && 235bf215546Sopenharmony_ci view->swizzle_g == PIPE_SWIZZLE_X && 236bf215546Sopenharmony_ci view->swizzle_b == PIPE_SWIZZLE_X && 237bf215546Sopenharmony_ci view->swizzle_a == PIPE_SWIZZLE_1) 238bf215546Sopenharmony_ci return (MAPSURF_32BIT | MT_32BIT_xL824); 239bf215546Sopenharmony_ci if (view->swizzle_r == PIPE_SWIZZLE_X && 240bf215546Sopenharmony_ci view->swizzle_g == PIPE_SWIZZLE_X && 241bf215546Sopenharmony_ci view->swizzle_b == PIPE_SWIZZLE_X && 242bf215546Sopenharmony_ci view->swizzle_a == PIPE_SWIZZLE_X) 243bf215546Sopenharmony_ci return (MAPSURF_32BIT | MT_32BIT_xI824); 244bf215546Sopenharmony_ci if (view->swizzle_r == PIPE_SWIZZLE_0 && 245bf215546Sopenharmony_ci view->swizzle_g == PIPE_SWIZZLE_0 && 246bf215546Sopenharmony_ci view->swizzle_b == PIPE_SWIZZLE_0 && 247bf215546Sopenharmony_ci view->swizzle_a == PIPE_SWIZZLE_X) 248bf215546Sopenharmony_ci return (MAPSURF_32BIT | MT_32BIT_xA824); 249bf215546Sopenharmony_ci debug_printf("i915: unsupported depth swizzle %d %d %d %d\n", 250bf215546Sopenharmony_ci view->swizzle_r, view->swizzle_g, view->swizzle_b, 251bf215546Sopenharmony_ci view->swizzle_a); 252bf215546Sopenharmony_ci return (MAPSURF_32BIT | MT_32BIT_xL824); 253bf215546Sopenharmony_ci } 254bf215546Sopenharmony_ci default: 255bf215546Sopenharmony_ci debug_printf("i915: translate_texture_format() bad image format %x\n", 256bf215546Sopenharmony_ci pipeFormat); 257bf215546Sopenharmony_ci assert(0); 258bf215546Sopenharmony_ci return 0; 259bf215546Sopenharmony_ci } 260bf215546Sopenharmony_ci} 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_cistatic inline uint32_t 263bf215546Sopenharmony_cims3_tiling_bits(enum i915_winsys_buffer_tile tiling) 264bf215546Sopenharmony_ci{ 265bf215546Sopenharmony_ci uint32_t tiling_bits = 0; 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci switch (tiling) { 268bf215546Sopenharmony_ci case I915_TILE_Y: 269bf215546Sopenharmony_ci tiling_bits |= MS3_TILE_WALK_Y; 270bf215546Sopenharmony_ci FALLTHROUGH; 271bf215546Sopenharmony_ci case I915_TILE_X: 272bf215546Sopenharmony_ci tiling_bits |= MS3_TILED_SURFACE; 273bf215546Sopenharmony_ci FALLTHROUGH; 274bf215546Sopenharmony_ci case I915_TILE_NONE: 275bf215546Sopenharmony_ci break; 276bf215546Sopenharmony_ci } 277bf215546Sopenharmony_ci 278bf215546Sopenharmony_ci return tiling_bits; 279bf215546Sopenharmony_ci} 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_cistatic void 282bf215546Sopenharmony_ciupdate_map(struct i915_context *i915, uint32_t unit, 283bf215546Sopenharmony_ci const struct i915_texture *tex, 284bf215546Sopenharmony_ci const struct i915_sampler_state *sampler, 285bf215546Sopenharmony_ci const struct pipe_sampler_view *view, uint32_t state[3]) 286bf215546Sopenharmony_ci{ 287bf215546Sopenharmony_ci const struct pipe_resource *pt = &tex->b; 288bf215546Sopenharmony_ci uint32_t width = pt->width0, height = pt->height0, depth = pt->depth0; 289bf215546Sopenharmony_ci int first_level = view->u.tex.first_level; 290bf215546Sopenharmony_ci const uint32_t num_levels = pt->last_level - first_level; 291bf215546Sopenharmony_ci unsigned max_lod = num_levels * 4; 292bf215546Sopenharmony_ci bool is_npot = (!util_is_power_of_two_or_zero(pt->width0) || 293bf215546Sopenharmony_ci !util_is_power_of_two_or_zero(pt->height0)); 294bf215546Sopenharmony_ci uint32_t format, pitch; 295bf215546Sopenharmony_ci 296bf215546Sopenharmony_ci /* 297bf215546Sopenharmony_ci * This is a bit messy. i915 doesn't support NPOT with mipmaps, but we can 298bf215546Sopenharmony_ci * still texture from a single level. This is useful to make u_blitter work. 299bf215546Sopenharmony_ci */ 300bf215546Sopenharmony_ci if (is_npot) { 301bf215546Sopenharmony_ci width = u_minify(width, first_level); 302bf215546Sopenharmony_ci height = u_minify(height, first_level); 303bf215546Sopenharmony_ci max_lod = 1; 304bf215546Sopenharmony_ci } 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_ci assert(tex); 307bf215546Sopenharmony_ci assert(width); 308bf215546Sopenharmony_ci assert(height); 309bf215546Sopenharmony_ci assert(depth); 310bf215546Sopenharmony_ci 311bf215546Sopenharmony_ci format = translate_texture_format(pt->format, view); 312bf215546Sopenharmony_ci pitch = tex->stride; 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci assert(format); 315bf215546Sopenharmony_ci assert(pitch); 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_ci /* MS3 state */ 318bf215546Sopenharmony_ci state[0] = 319bf215546Sopenharmony_ci (((height - 1) << MS3_HEIGHT_SHIFT) | ((width - 1) << MS3_WIDTH_SHIFT) | 320bf215546Sopenharmony_ci format | ms3_tiling_bits(tex->tiling)); 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci /* 323bf215546Sopenharmony_ci * XXX When min_filter != mag_filter and there's just one mipmap level, 324bf215546Sopenharmony_ci * set max_lod = 1 to make sure i915 chooses between min/mag filtering. 325bf215546Sopenharmony_ci */ 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci /* See note at the top of file */ 328bf215546Sopenharmony_ci if (max_lod > (sampler->maxlod >> 2)) 329bf215546Sopenharmony_ci max_lod = sampler->maxlod >> 2; 330bf215546Sopenharmony_ci 331bf215546Sopenharmony_ci /* MS4 state */ 332bf215546Sopenharmony_ci state[1] = ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) | MS4_CUBE_FACE_ENA_MASK | 333bf215546Sopenharmony_ci ((max_lod) << MS4_MAX_LOD_SHIFT) | 334bf215546Sopenharmony_ci ((depth - 1) << MS4_VOLUME_DEPTH_SHIFT)); 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci if (is_npot) 337bf215546Sopenharmony_ci state[2] = i915_texture_offset(tex, first_level, 0); 338bf215546Sopenharmony_ci else 339bf215546Sopenharmony_ci state[2] = 0; 340bf215546Sopenharmony_ci} 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_cistatic void 343bf215546Sopenharmony_ciupdate_samplers(struct i915_context *i915) 344bf215546Sopenharmony_ci{ 345bf215546Sopenharmony_ci uint32_t unit; 346bf215546Sopenharmony_ci 347bf215546Sopenharmony_ci i915->current.sampler_enable_nr = 0; 348bf215546Sopenharmony_ci i915->current.sampler_enable_flags = 0x0; 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ci for (unit = 0; 351bf215546Sopenharmony_ci unit < i915->num_fragment_sampler_views && unit < i915->num_samplers; 352bf215546Sopenharmony_ci unit++) { 353bf215546Sopenharmony_ci /* determine unit enable/disable by looking for a bound texture */ 354bf215546Sopenharmony_ci /* could also examine the fragment program? */ 355bf215546Sopenharmony_ci if (i915->fragment_sampler_views[unit]) { 356bf215546Sopenharmony_ci struct i915_texture *texture = 357bf215546Sopenharmony_ci i915_texture(i915->fragment_sampler_views[unit]->texture); 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_ci update_sampler(i915, unit, 360bf215546Sopenharmony_ci i915->fragment_sampler[unit], /* sampler state */ 361bf215546Sopenharmony_ci texture, /* texture */ 362bf215546Sopenharmony_ci i915->current.sampler[unit]); /* the result */ 363bf215546Sopenharmony_ci update_map(i915, unit, texture, /* texture */ 364bf215546Sopenharmony_ci i915->fragment_sampler[unit], /* sampler state */ 365bf215546Sopenharmony_ci i915->fragment_sampler_views[unit], /* sampler view */ 366bf215546Sopenharmony_ci i915->current.texbuffer[unit]); /* the result */ 367bf215546Sopenharmony_ci 368bf215546Sopenharmony_ci i915->current.sampler_enable_nr++; 369bf215546Sopenharmony_ci i915->current.sampler_enable_flags |= (1 << unit); 370bf215546Sopenharmony_ci } 371bf215546Sopenharmony_ci } 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_ci i915->hardware_dirty |= I915_HW_SAMPLER | I915_HW_MAP; 374bf215546Sopenharmony_ci} 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_cistruct i915_tracked_state i915_hw_samplers = { 377bf215546Sopenharmony_ci "samplers", update_samplers, I915_NEW_SAMPLER | I915_NEW_SAMPLER_VIEW}; 378