i915_state_sampler.c revision 683e35f726a182ed9fc6b6d5cb07146eebe14dea
1d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell/************************************************************************** 2d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * 3d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 4d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * All Rights Reserved. 5d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * 6d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 7d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * copy of this software and associated documentation files (the 8d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * "Software"), to deal in the Software without restriction, including 9d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 10d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 11d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 12d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * the following conditions: 13d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * 14d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * The above copyright notice and this permission notice (including the 15d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 16d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * of the Software. 17d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * 18d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * 26d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell **************************************************************************/ 27d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 28d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "pipe/p_context.h" 29d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "pipe/p_state.h" 304f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 31d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 32d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_state_inlines.h" 33d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_context.h" 34d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_reg.h" 35c990d0fd57a05301429b3af75b7fed0337621941Brian#include "i915_state.h" 367e884c6f86621ca07ed31fc7ee3f4d891f0873daBrian 37d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 38d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz/* 39d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * A note about min_lod & max_lod. 40d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * 41d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * There is a circular dependancy between the sampler state 42d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * and the map state to be submitted to hw. 43d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * 44d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * Two condition must be meet: 45d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * min_lod =< max_lod == true 46d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * max_lod =< last_level == true 47d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * 48d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * 49d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * This is all fine and dandy if it where for the fact that max_lod 50d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * is set on the map state instead of the sampler state. That is 51d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * the max_lod we submit on map is: 52d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * max_lod = MIN2(last_level, max_lod); 53d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * 54d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * So we need to update the map state when we change samplers and 55d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * we need to be change the sampler state when map state is changed. 56d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * The first part is done by calling i915_update_texture in 57d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * i915_update_samplers and the second part is done else where in 58d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * code tracking the state changes. 59d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz */ 60d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz 61d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantzstatic void 62d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantzi915_update_texture(struct i915_context *i915, 63d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz uint unit, 64d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz const struct i915_texture *tex, 65d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz const struct i915_sampler_state *sampler, 66d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz uint state[6]); 67be673e9719593ee22c16e289fe4d154db3fb7805Brian/** 68be673e9719593ee22c16e289fe4d154db3fb7805Brian * Compute i915 texture sampling state. 69be673e9719593ee22c16e289fe4d154db3fb7805Brian * 70be673e9719593ee22c16e289fe4d154db3fb7805Brian * Recalculate all state from scratch. Perhaps not the most 71d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * efficient, but this has gotten complex enough that we need 72d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * something which is understandable and reliable. 73be673e9719593ee22c16e289fe4d154db3fb7805Brian * \param state returns the 3 words of compute state 74d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell */ 75be673e9719593ee22c16e289fe4d154db3fb7805Brianstatic void update_sampler(struct i915_context *i915, 76be673e9719593ee22c16e289fe4d154db3fb7805Brian uint unit, 77742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin const struct i915_sampler_state *sampler, 78753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer const struct i915_texture *tex, 79be673e9719593ee22c16e289fe4d154db3fb7805Brian unsigned state[3] ) 80d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell{ 81753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer const struct pipe_texture *pt = &tex->base; 82d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz unsigned minlod, lastlod; 83753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer 84d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell /* Need to do this after updating the maps, which call the 85d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell * intel_finalize_mipmap_tree and hence can update firstLevel: 86d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell */ 87742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin state[0] = sampler->state[0]; 88742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin state[1] = sampler->state[1]; 89742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin state[2] = sampler->state[2]; 90d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 91753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer if (pt->format == PIPE_FORMAT_YCBCR || 92753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer pt->format == PIPE_FORMAT_YCBCR_REV) 93d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell state[0] |= SS2_COLORSPACE_CONVERSION; 94d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 95be673e9719593ee22c16e289fe4d154db3fb7805Brian /* 3D textures don't seem to respect the border color. 96be673e9719593ee22c16e289fe4d154db3fb7805Brian * Fallback if there's ever a danger that they might refer to 97be673e9719593ee22c16e289fe4d154db3fb7805Brian * it. 98be673e9719593ee22c16e289fe4d154db3fb7805Brian * 99be673e9719593ee22c16e289fe4d154db3fb7805Brian * Effectively this means fallback on 3D clamp or 100be673e9719593ee22c16e289fe4d154db3fb7805Brian * clamp_to_border. 101be673e9719593ee22c16e289fe4d154db3fb7805Brian * 102be673e9719593ee22c16e289fe4d154db3fb7805Brian * XXX: Check if this is true on i945. 103be673e9719593ee22c16e289fe4d154db3fb7805Brian * XXX: Check if this bug got fixed in release silicon. 104be673e9719593ee22c16e289fe4d154db3fb7805Brian */ 105be673e9719593ee22c16e289fe4d154db3fb7805Brian#if 0 106742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin { 107742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin const unsigned ws = sampler->templ->wrap_s; 108742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin const unsigned wt = sampler->templ->wrap_t; 109742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin const unsigned wr = sampler->templ->wrap_r; 110753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer if (pt->target == PIPE_TEXTURE_3D && 111742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST || 112742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) && 113742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin (ws == PIPE_TEX_WRAP_CLAMP || 114742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin wt == PIPE_TEX_WRAP_CLAMP || 115742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin wr == PIPE_TEX_WRAP_CLAMP || 116742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin ws == PIPE_TEX_WRAP_CLAMP_TO_BORDER || 117742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin wt == PIPE_TEX_WRAP_CLAMP_TO_BORDER || 118742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin wr == PIPE_TEX_WRAP_CLAMP_TO_BORDER)) { 11934683150878e0af0859c94d0c1f0c4bf8395b042Robert Ellison if (i915->conformance_mode > 0) { 120742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin assert(0); 121742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin /* sampler->fallback = true; */ 122742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin /* TODO */ 123742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin } 124d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell } 125be673e9719593ee22c16e289fe4d154db3fb7805Brian } 126742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin#endif 127d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 128d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz /* See note at the top of file */ 129d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz minlod = sampler->minlod; 130d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz lastlod = pt->last_level << 4; 131d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz 132d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz if (lastlod < minlod) { 133d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz minlod = lastlod; 134d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz } 135d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz 136d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz state[1] |= (sampler->minlod << SS3_MIN_LOD_SHIFT); 137742e32a40bf5ef1bd90b23aa0f7d451b7b7f0ba3Zack Rusin state[1] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT); 138d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell} 139d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 140237429aa3b8c2025e11aaa23d04e7107cf6a838fBrian 141d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwellvoid i915_update_samplers( struct i915_context *i915 ) 142d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell{ 143be673e9719593ee22c16e289fe4d154db3fb7805Brian uint unit; 144be673e9719593ee22c16e289fe4d154db3fb7805Brian 145be673e9719593ee22c16e289fe4d154db3fb7805Brian i915->current.sampler_enable_nr = 0; 146be673e9719593ee22c16e289fe4d154db3fb7805Brian i915->current.sampler_enable_flags = 0x0; 147be673e9719593ee22c16e289fe4d154db3fb7805Brian 1484528287e040415c2071012d02f20979ff995c754Keith Whitwell for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; 1494528287e040415c2071012d02f20979ff995c754Keith Whitwell unit++) { 150753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer /* determine unit enable/disable by looking for a bound texture */ 151be673e9719593ee22c16e289fe4d154db3fb7805Brian /* could also examine the fragment program? */ 152be673e9719593ee22c16e289fe4d154db3fb7805Brian if (i915->texture[unit]) { 153be673e9719593ee22c16e289fe4d154db3fb7805Brian update_sampler( i915, 154d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz unit, 155d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->sampler[unit], /* sampler state */ 156d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->texture[unit], /* texture */ 157d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->current.sampler[unit] /* the result */ 158d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz ); 159d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915_update_texture( i915, 160d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz unit, 161d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->texture[unit], /* texture */ 162d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->sampler[unit], /* sampler state */ 163d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->current.texbuffer[unit] ); 164d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz 165d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->current.sampler_enable_nr++; 166d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->current.sampler_enable_flags |= (1 << unit); 167d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell } 168d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell } 169d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell 170d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->hardware_dirty |= I915_HW_SAMPLER | I915_HW_MAP; 171be673e9719593ee22c16e289fe4d154db3fb7805Brian} 172c990d0fd57a05301429b3af75b7fed0337621941Brian 173c990d0fd57a05301429b3af75b7fed0337621941Brian 174c990d0fd57a05301429b3af75b7fed0337621941Brianstatic uint 17554fc80ab31f89520d3119196bfa9c6332b35fe2fBriantranslate_texture_format(enum pipe_format pipeFormat) 176c990d0fd57a05301429b3af75b7fed0337621941Brian{ 177c990d0fd57a05301429b3af75b7fed0337621941Brian switch (pipeFormat) { 17854f94a790e4488445347abcff9a636a9c440d7f9Brian Paul case PIPE_FORMAT_L8_UNORM: 179c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_8BIT | MT_8BIT_L8; 18054f94a790e4488445347abcff9a636a9c440d7f9Brian Paul case PIPE_FORMAT_I8_UNORM: 181c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_8BIT | MT_8BIT_I8; 18254f94a790e4488445347abcff9a636a9c440d7f9Brian Paul case PIPE_FORMAT_A8_UNORM: 183c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_8BIT | MT_8BIT_A8; 18454f94a790e4488445347abcff9a636a9c440d7f9Brian Paul case PIPE_FORMAT_A8L8_UNORM: 185c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_16BIT | MT_16BIT_AY88; 1862067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_R5G6B5_UNORM: 187c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_16BIT | MT_16BIT_RGB565; 1882067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_A1R5G5B5_UNORM: 189c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_16BIT | MT_16BIT_ARGB1555; 1902067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_A4R4G4B4_UNORM: 191c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_16BIT | MT_16BIT_ARGB4444; 1922067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_A8R8G8B8_UNORM: 193c990d0fd57a05301429b3af75b7fed0337621941Brian return MAPSURF_32BIT | MT_32BIT_ARGB8888; 194c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_YCBCR_REV: 195c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_422 | MT_422_YCRCB_NORMAL); 196c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_YCBCR: 197c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_422 | MT_422_YCRCB_SWAPY); 198c990d0fd57a05301429b3af75b7fed0337621941Brian#if 0 199c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGB_FXT1: 200c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGBA_FXT1: 201c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1); 202c990d0fd57a05301429b3af75b7fed0337621941Brian#endif 2032067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_Z16_UNORM: 204c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_16BIT | MT_16BIT_L16); 205c990d0fd57a05301429b3af75b7fed0337621941Brian#if 0 206c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGBA_DXT1: 207c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGB_DXT1: 208c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1); 209c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGBA_DXT3: 210c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3); 211c990d0fd57a05301429b3af75b7fed0337621941Brian case PIPE_FORMAT_RGBA_DXT5: 212c990d0fd57a05301429b3af75b7fed0337621941Brian return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); 213c990d0fd57a05301429b3af75b7fed0337621941Brian#endif 2142067eed9d30bb5b260920a5650655579c1988202Brian case PIPE_FORMAT_S8Z24_UNORM: 215081c05605f1c308c35fcf4168aac09fbf3c0a108Jakob Bornecrantz return (MAPSURF_32BIT | MT_32BIT_xI824); 216c990d0fd57a05301429b3af75b7fed0337621941Brian default: 2179791d7f64c5a58b9c1bf32d00c71e0e031f54f70José Fonseca debug_printf("i915: translate_texture_format() bad image format %x\n", 218c990d0fd57a05301429b3af75b7fed0337621941Brian pipeFormat); 219c990d0fd57a05301429b3af75b7fed0337621941Brian assert(0); 220c990d0fd57a05301429b3af75b7fed0337621941Brian return 0; 221c990d0fd57a05301429b3af75b7fed0337621941Brian } 222c990d0fd57a05301429b3af75b7fed0337621941Brian} 223c990d0fd57a05301429b3af75b7fed0337621941Brian 224c990d0fd57a05301429b3af75b7fed0337621941Brian 225c990d0fd57a05301429b3af75b7fed0337621941Brianstatic void 226d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantzi915_update_texture(struct i915_context *i915, 227d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz uint unit, 228d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz const struct i915_texture *tex, 229d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz const struct i915_sampler_state *sampler, 230c990d0fd57a05301429b3af75b7fed0337621941Brian uint state[6]) 231c990d0fd57a05301429b3af75b7fed0337621941Brian{ 232753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer const struct pipe_texture *pt = &tex->base; 233c990d0fd57a05301429b3af75b7fed0337621941Brian uint format, pitch; 234683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell const uint width = pt->width0, height = pt->height0, depth = pt->depth0; 2354da1cdf78fa3b954840650fa46cf72da5daf149fBrian const uint num_levels = pt->last_level; 236d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz unsigned max_lod = num_levels * 4; 237f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz unsigned tiled = MS3_USE_FENCE_REGS; 238c990d0fd57a05301429b3af75b7fed0337621941Brian 239753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer assert(tex); 240c990d0fd57a05301429b3af75b7fed0337621941Brian assert(width); 241c990d0fd57a05301429b3af75b7fed0337621941Brian assert(height); 242c990d0fd57a05301429b3af75b7fed0337621941Brian assert(depth); 243c990d0fd57a05301429b3af75b7fed0337621941Brian 244753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer format = translate_texture_format(pt->format); 2454ddd65967915ca4846f2831bc676c878a29dae4aJosé Fonseca pitch = tex->stride; 246c990d0fd57a05301429b3af75b7fed0337621941Brian 247c990d0fd57a05301429b3af75b7fed0337621941Brian assert(format); 248c990d0fd57a05301429b3af75b7fed0337621941Brian assert(pitch); 249c990d0fd57a05301429b3af75b7fed0337621941Brian 250d2110064c2075a8537d4b7f87ba894ebaa6ccb33Jakob Bornecrantz if (tex->sw_tiled) { 251f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz assert(!((pitch - 1) & pitch)); 252f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz tiled = MS3_TILED_SURFACE; 253f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz } 254f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz 255c990d0fd57a05301429b3af75b7fed0337621941Brian /* MS3 state */ 256c990d0fd57a05301429b3af75b7fed0337621941Brian state[0] = 257c990d0fd57a05301429b3af75b7fed0337621941Brian (((height - 1) << MS3_HEIGHT_SHIFT) 258c990d0fd57a05301429b3af75b7fed0337621941Brian | ((width - 1) << MS3_WIDTH_SHIFT) 259c990d0fd57a05301429b3af75b7fed0337621941Brian | format 260f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz | tiled); 261c990d0fd57a05301429b3af75b7fed0337621941Brian 262b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian /* 263d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz * XXX When min_filter != mag_filter and there's just one mipmap level, 264b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian * set max_lod = 1 to make sure i915 chooses between min/mag filtering. 265b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian */ 266b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian 267d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz /* See note at the top of file */ 268d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz if (max_lod > (sampler->maxlod >> 2)) 269d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz max_lod = sampler->maxlod >> 2; 270d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz 271c990d0fd57a05301429b3af75b7fed0337621941Brian /* MS4 state */ 272c990d0fd57a05301429b3af75b7fed0337621941Brian state[1] = 273c990d0fd57a05301429b3af75b7fed0337621941Brian ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) 274c990d0fd57a05301429b3af75b7fed0337621941Brian | MS4_CUBE_FACE_ENA_MASK 275d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz | ((max_lod) << MS4_MAX_LOD_SHIFT) 276c990d0fd57a05301429b3af75b7fed0337621941Brian | ((depth - 1) << MS4_VOLUME_DEPTH_SHIFT)); 277c990d0fd57a05301429b3af75b7fed0337621941Brian} 278c990d0fd57a05301429b3af75b7fed0337621941Brian 279c990d0fd57a05301429b3af75b7fed0337621941Brian 280c990d0fd57a05301429b3af75b7fed0337621941Brianvoid 281c990d0fd57a05301429b3af75b7fed0337621941Briani915_update_textures(struct i915_context *i915) 282c990d0fd57a05301429b3af75b7fed0337621941Brian{ 283c990d0fd57a05301429b3af75b7fed0337621941Brian uint unit; 284c990d0fd57a05301429b3af75b7fed0337621941Brian 2854528287e040415c2071012d02f20979ff995c754Keith Whitwell for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; 2864528287e040415c2071012d02f20979ff995c754Keith Whitwell unit++) { 287753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer /* determine unit enable/disable by looking for a bound texture */ 288c990d0fd57a05301429b3af75b7fed0337621941Brian /* could also examine the fragment program? */ 289c990d0fd57a05301429b3af75b7fed0337621941Brian if (i915->texture[unit]) { 290d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915_update_texture( i915, 291d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz unit, 292d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->texture[unit], /* texture */ 293d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->sampler[unit], /* sampler state */ 294d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz i915->current.texbuffer[unit] ); 295c990d0fd57a05301429b3af75b7fed0337621941Brian } 296c990d0fd57a05301429b3af75b7fed0337621941Brian } 297c990d0fd57a05301429b3af75b7fed0337621941Brian 298c990d0fd57a05301429b3af75b7fed0337621941Brian i915->hardware_dirty |= I915_HW_MAP; 299c990d0fd57a05301429b3af75b7fed0337621941Brian} 300