i915_state_sampler.c revision 4bc7b14224bfb9c5efe37e1505345fb90ba69d9e
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"
30d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell
31d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_state_inlines.h"
32d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_context.h"
33d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell#include "i915_reg.h"
34c990d0fd57a05301429b3af75b7fed0337621941Brian#include "i915_state.h"
35287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "i915_resource.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{
81287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   const struct pipe_resource *pt = &tex->b.b;
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
91b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   if (pt->format == PIPE_FORMAT_UYVY ||
92b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca       pt->format == PIPE_FORMAT_YUYV)
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
1481f5285f99771243b636deb9ae0a17c54f818fac6michal   for (unit = 0; unit < i915->num_fragment_sampler_views && 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? */
1521f5285f99771243b636deb9ae0a17c54f818fac6michal      if (i915->fragment_sampler_views[unit]) {
153287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell         struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture);
1541f5285f99771243b636deb9ae0a17c54f818fac6michal
155be673e9719593ee22c16e289fe4d154db3fb7805Brian	 update_sampler( i915,
156d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                 unit,
157d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                 i915->sampler[unit],       /* sampler state */
1581f5285f99771243b636deb9ae0a17c54f818fac6michal	                 texture,                    /* texture */
159d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                 i915->current.sampler[unit] /* the result */
160d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                 );
161d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	 i915_update_texture( i915,
162d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      unit,
1631f5285f99771243b636deb9ae0a17c54f818fac6michal	                      texture,                      /* texture */
164d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      i915->sampler[unit],          /* sampler state */
165d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      i915->current.texbuffer[unit] );
166d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz
167d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	 i915->current.sampler_enable_nr++;
168d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	 i915->current.sampler_enable_flags |= (1 << unit);
169d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell      }
170d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell   }
171d1fbf621dc48a488c0f860c5851332d269e6d637Keith Whitwell
172d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz   i915->hardware_dirty |= I915_HW_SAMPLER | I915_HW_MAP;
173be673e9719593ee22c16e289fe4d154db3fb7805Brian}
174c990d0fd57a05301429b3af75b7fed0337621941Brian
175c990d0fd57a05301429b3af75b7fed0337621941Brian
176c990d0fd57a05301429b3af75b7fed0337621941Brianstatic uint
17754fc80ab31f89520d3119196bfa9c6332b35fe2fBriantranslate_texture_format(enum pipe_format pipeFormat)
178c990d0fd57a05301429b3af75b7fed0337621941Brian{
179c990d0fd57a05301429b3af75b7fed0337621941Brian   switch (pipeFormat) {
18054f94a790e4488445347abcff9a636a9c440d7f9Brian Paul   case PIPE_FORMAT_L8_UNORM:
181c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_8BIT | MT_8BIT_L8;
18254f94a790e4488445347abcff9a636a9c440d7f9Brian Paul   case PIPE_FORMAT_I8_UNORM:
183c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_8BIT | MT_8BIT_I8;
18454f94a790e4488445347abcff9a636a9c440d7f9Brian Paul   case PIPE_FORMAT_A8_UNORM:
185c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_8BIT | MT_8BIT_A8;
186b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_L8A8_UNORM:
187c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_16BIT | MT_16BIT_AY88;
188b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_B5G6R5_UNORM:
189c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_16BIT | MT_16BIT_RGB565;
190b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_B5G5R5A1_UNORM:
191c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_16BIT | MT_16BIT_ARGB1555;
192b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_B4G4R4A4_UNORM:
193c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_16BIT | MT_16BIT_ARGB4444;
194b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_B8G8R8A8_UNORM:
195c990d0fd57a05301429b3af75b7fed0337621941Brian      return MAPSURF_32BIT | MT_32BIT_ARGB8888;
196b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz   case PIPE_FORMAT_B8G8R8X8_UNORM:
197b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz      return MAPSURF_32BIT | MT_32BIT_XRGB8888;
198b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz   case PIPE_FORMAT_R8G8B8A8_UNORM:
199b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz      return MAPSURF_32BIT | MT_32BIT_ABGR8888;
200b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz#if 0
201b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz   case PIPE_FORMAT_R8G8B8X8_UNORM:
202b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz      return MAPSURF_32BIT | MT_32BIT_XBGR8888;
203b4b4ac668116d974522df2ce56e30b74ecdfef77Jakob Bornecrantz#endif
204b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_YUYV:
205c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
206b2b1e899f64ed8a96ea2df6ed45accd430d44363José Fonseca   case PIPE_FORMAT_UYVY:
207c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
208c990d0fd57a05301429b3af75b7fed0337621941Brian#if 0
209c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGB_FXT1:
210c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGBA_FXT1:
211c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
212c990d0fd57a05301429b3af75b7fed0337621941Brian#endif
2132067eed9d30bb5b260920a5650655579c1988202Brian   case PIPE_FORMAT_Z16_UNORM:
214c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_16BIT | MT_16BIT_L16);
215c990d0fd57a05301429b3af75b7fed0337621941Brian#if 0
216c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGBA_DXT1:
217c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGB_DXT1:
218c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
219c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGBA_DXT3:
220c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
221c990d0fd57a05301429b3af75b7fed0337621941Brian   case PIPE_FORMAT_RGBA_DXT5:
222c990d0fd57a05301429b3af75b7fed0337621941Brian      return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
223c990d0fd57a05301429b3af75b7fed0337621941Brian#endif
2246fb364a1717858d8201b2caf234076ce5d4832acRoland Scheidegger   case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
2254bc7b14224bfb9c5efe37e1505345fb90ba69d9eRoland Scheidegger   case PIPE_FORMAT_Z24X8_UNORM:
226081c05605f1c308c35fcf4168aac09fbf3c0a108Jakob Bornecrantz      return (MAPSURF_32BIT | MT_32BIT_xI824);
227c990d0fd57a05301429b3af75b7fed0337621941Brian   default:
2289791d7f64c5a58b9c1bf32d00c71e0e031f54f70José Fonseca      debug_printf("i915: translate_texture_format() bad image format %x\n",
229c990d0fd57a05301429b3af75b7fed0337621941Brian              pipeFormat);
230c990d0fd57a05301429b3af75b7fed0337621941Brian      assert(0);
231c990d0fd57a05301429b3af75b7fed0337621941Brian      return 0;
232c990d0fd57a05301429b3af75b7fed0337621941Brian   }
233c990d0fd57a05301429b3af75b7fed0337621941Brian}
234c990d0fd57a05301429b3af75b7fed0337621941Brian
235c990d0fd57a05301429b3af75b7fed0337621941Brian
236c990d0fd57a05301429b3af75b7fed0337621941Brianstatic void
237d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantzi915_update_texture(struct i915_context *i915,
238d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz                    uint unit,
239d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz                    const struct i915_texture *tex,
240d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz                    const struct i915_sampler_state *sampler,
241c990d0fd57a05301429b3af75b7fed0337621941Brian                    uint state[6])
242c990d0fd57a05301429b3af75b7fed0337621941Brian{
243287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   const struct pipe_resource *pt = &tex->b.b;
244c990d0fd57a05301429b3af75b7fed0337621941Brian   uint format, pitch;
245683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell   const uint width = pt->width0, height = pt->height0, depth = pt->depth0;
2464da1cdf78fa3b954840650fa46cf72da5daf149fBrian   const uint num_levels = pt->last_level;
247d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz   unsigned max_lod = num_levels * 4;
248f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz   unsigned tiled = MS3_USE_FENCE_REGS;
249c990d0fd57a05301429b3af75b7fed0337621941Brian
250753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer   assert(tex);
251c990d0fd57a05301429b3af75b7fed0337621941Brian   assert(width);
252c990d0fd57a05301429b3af75b7fed0337621941Brian   assert(height);
253c990d0fd57a05301429b3af75b7fed0337621941Brian   assert(depth);
254c990d0fd57a05301429b3af75b7fed0337621941Brian
255753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer   format = translate_texture_format(pt->format);
2564ddd65967915ca4846f2831bc676c878a29dae4aJosé Fonseca   pitch = tex->stride;
257c990d0fd57a05301429b3af75b7fed0337621941Brian
258c990d0fd57a05301429b3af75b7fed0337621941Brian   assert(format);
259c990d0fd57a05301429b3af75b7fed0337621941Brian   assert(pitch);
260c990d0fd57a05301429b3af75b7fed0337621941Brian
261d2110064c2075a8537d4b7f87ba894ebaa6ccb33Jakob Bornecrantz   if (tex->sw_tiled) {
262f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz      assert(!((pitch - 1) & pitch));
263f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz      tiled = MS3_TILED_SURFACE;
264f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz   }
265f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz
266c990d0fd57a05301429b3af75b7fed0337621941Brian   /* MS3 state */
267c990d0fd57a05301429b3af75b7fed0337621941Brian   state[0] =
268c990d0fd57a05301429b3af75b7fed0337621941Brian      (((height - 1) << MS3_HEIGHT_SHIFT)
269c990d0fd57a05301429b3af75b7fed0337621941Brian       | ((width - 1) << MS3_WIDTH_SHIFT)
270c990d0fd57a05301429b3af75b7fed0337621941Brian       | format
271f52ab4cc22bfb6708724f3c3966ce734d605cdddJakob Bornecrantz       | tiled);
272c990d0fd57a05301429b3af75b7fed0337621941Brian
273b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian   /*
274d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz    * XXX When min_filter != mag_filter and there's just one mipmap level,
275b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian    * set max_lod = 1 to make sure i915 chooses between min/mag filtering.
276b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian    */
277b70a6babfbc035d64dbe35ac4bf9218e8232b435Brian
278d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz   /* See note at the top of file */
279d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz   if (max_lod > (sampler->maxlod >> 2))
280d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz      max_lod = sampler->maxlod >> 2;
281d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz
282c990d0fd57a05301429b3af75b7fed0337621941Brian   /* MS4 state */
283c990d0fd57a05301429b3af75b7fed0337621941Brian   state[1] =
284c990d0fd57a05301429b3af75b7fed0337621941Brian      ((((pitch / 4) - 1) << MS4_PITCH_SHIFT)
285c990d0fd57a05301429b3af75b7fed0337621941Brian       | MS4_CUBE_FACE_ENA_MASK
286d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz       | ((max_lod) << MS4_MAX_LOD_SHIFT)
287c990d0fd57a05301429b3af75b7fed0337621941Brian       | ((depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
288c990d0fd57a05301429b3af75b7fed0337621941Brian}
289c990d0fd57a05301429b3af75b7fed0337621941Brian
290c990d0fd57a05301429b3af75b7fed0337621941Brian
291c990d0fd57a05301429b3af75b7fed0337621941Brianvoid
292c990d0fd57a05301429b3af75b7fed0337621941Briani915_update_textures(struct i915_context *i915)
293c990d0fd57a05301429b3af75b7fed0337621941Brian{
294c990d0fd57a05301429b3af75b7fed0337621941Brian   uint unit;
295c990d0fd57a05301429b3af75b7fed0337621941Brian
2961f5285f99771243b636deb9ae0a17c54f818fac6michal   for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers;
2974528287e040415c2071012d02f20979ff995c754Keith Whitwell        unit++) {
298753db0d8407147393a7b0622ae3fa28f68d0353dMichel Dänzer      /* determine unit enable/disable by looking for a bound texture */
299c990d0fd57a05301429b3af75b7fed0337621941Brian      /* could also examine the fragment program? */
3001f5285f99771243b636deb9ae0a17c54f818fac6michal      if (i915->fragment_sampler_views[unit]) {
301287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell         struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture);
3021f5285f99771243b636deb9ae0a17c54f818fac6michal
303d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	 i915_update_texture( i915,
304d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      unit,
3051f5285f99771243b636deb9ae0a17c54f818fac6michal	                      texture,                      /* texture */
306d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      i915->sampler[unit],          /* sampler state */
307d9d1e39d95fef4a8da15147956ff0c3e0a188b5bJakob Bornecrantz	                      i915->current.texbuffer[unit] );
308c990d0fd57a05301429b3af75b7fed0337621941Brian      }
309c990d0fd57a05301429b3af75b7fed0337621941Brian   }
310c990d0fd57a05301429b3af75b7fed0337621941Brian
311c990d0fd57a05301429b3af75b7fed0337621941Brian   i915->hardware_dirty |= I915_HW_MAP;
312c990d0fd57a05301429b3af75b7fed0337621941Brian}
313