more dead code removal
[mesa.git] / src / mesa / pipe / i915simple / i915_state_sampler.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "pipe/p_context.h"
29 #include "pipe/p_state.h"
30 #include "pipe/p_util.h"
31
32 #include "i915_state_inlines.h"
33 #include "i915_context.h"
34 #include "i915_reg.h"
35 #include "i915_state.h"
36
37
38 /**
39 * Compute i915 texture sampling state.
40 *
41 * Recalculate all state from scratch. Perhaps not the most
42 * efficient, but this has gotten complex enough that we need
43 * something which is understandable and reliable.
44 * \param state returns the 3 words of compute state
45 */
46 static void update_sampler(struct i915_context *i915,
47 uint unit,
48 const struct i915_sampler_state *sampler,
49 const struct pipe_mipmap_tree *mt,
50 unsigned state[3] )
51 {
52 /* Need to do this after updating the maps, which call the
53 * intel_finalize_mipmap_tree and hence can update firstLevel:
54 */
55 state[0] = sampler->state[0];
56 state[1] = sampler->state[1];
57 state[2] = sampler->state[2];
58
59 if (mt->format == PIPE_FORMAT_YCBCR ||
60 mt->format == PIPE_FORMAT_YCBCR_REV)
61 state[0] |= SS2_COLORSPACE_CONVERSION;
62
63 /* 3D textures don't seem to respect the border color.
64 * Fallback if there's ever a danger that they might refer to
65 * it.
66 *
67 * Effectively this means fallback on 3D clamp or
68 * clamp_to_border.
69 *
70 * XXX: Check if this is true on i945.
71 * XXX: Check if this bug got fixed in release silicon.
72 */
73 #if 0
74 {
75 const unsigned ws = sampler->templ->wrap_s;
76 const unsigned wt = sampler->templ->wrap_t;
77 const unsigned wr = sampler->templ->wrap_r;
78 if (mt->target == PIPE_TEXTURE_3D &&
79 (sampler->templ->min_img_filter != PIPE_TEX_FILTER_NEAREST ||
80 sampler->templ->mag_img_filter != PIPE_TEX_FILTER_NEAREST) &&
81 (ws == PIPE_TEX_WRAP_CLAMP ||
82 wt == PIPE_TEX_WRAP_CLAMP ||
83 wr == PIPE_TEX_WRAP_CLAMP ||
84 ws == PIPE_TEX_WRAP_CLAMP_TO_BORDER ||
85 wt == PIPE_TEX_WRAP_CLAMP_TO_BORDER ||
86 wr == PIPE_TEX_WRAP_CLAMP_TO_BORDER)) {
87 if (i915->strict_conformance) {
88 assert(0);
89 /* sampler->fallback = true; */
90 /* TODO */
91 }
92 }
93 }
94 #endif
95
96 state[1] |= (unit << SS3_TEXTUREMAP_INDEX_SHIFT);
97 }
98
99
100 void i915_update_samplers( struct i915_context *i915 )
101 {
102 uint unit;
103
104 i915->current.sampler_enable_nr = 0;
105 i915->current.sampler_enable_flags = 0x0;
106
107 for (unit = 0; unit < I915_TEX_UNITS; unit++) {
108 /* determine unit enable/disable by looking for a bound mipmap tree */
109 /* could also examine the fragment program? */
110 if (i915->texture[unit]) {
111 update_sampler( i915,
112 unit,
113 i915->sampler[unit], /* sampler state */
114 i915->texture[unit], /* mipmap tree */
115 i915->current.sampler[unit] /* the result */
116 );
117
118 i915->current.sampler_enable_nr++;
119 i915->current.sampler_enable_flags |= (1 << unit);
120 }
121 }
122
123 i915->hardware_dirty |= I915_HW_SAMPLER;
124 }
125
126
127 static uint
128 translate_texture_format(uint pipeFormat)
129 {
130 switch (pipeFormat) {
131 case PIPE_FORMAT_U_L8:
132 return MAPSURF_8BIT | MT_8BIT_L8;
133 case PIPE_FORMAT_U_I8:
134 return MAPSURF_8BIT | MT_8BIT_I8;
135 case PIPE_FORMAT_U_A8:
136 return MAPSURF_8BIT | MT_8BIT_A8;
137 case PIPE_FORMAT_U_A8_L8:
138 return MAPSURF_16BIT | MT_16BIT_AY88;
139 case PIPE_FORMAT_U_R5_G6_B5:
140 return MAPSURF_16BIT | MT_16BIT_RGB565;
141 case PIPE_FORMAT_U_A1_R5_G5_B5:
142 return MAPSURF_16BIT | MT_16BIT_ARGB1555;
143 case PIPE_FORMAT_U_A4_R4_G4_B4:
144 return MAPSURF_16BIT | MT_16BIT_ARGB4444;
145 case PIPE_FORMAT_U_A8_R8_G8_B8:
146 return MAPSURF_32BIT | MT_32BIT_ARGB8888;
147 case PIPE_FORMAT_YCBCR_REV:
148 return (MAPSURF_422 | MT_422_YCRCB_NORMAL);
149 case PIPE_FORMAT_YCBCR:
150 return (MAPSURF_422 | MT_422_YCRCB_SWAPY);
151 #if 0
152 case PIPE_FORMAT_RGB_FXT1:
153 case PIPE_FORMAT_RGBA_FXT1:
154 return (MAPSURF_COMPRESSED | MT_COMPRESS_FXT1);
155 #endif
156 case PIPE_FORMAT_U_Z16:
157 return (MAPSURF_16BIT | MT_16BIT_L16);
158 #if 0
159 case PIPE_FORMAT_RGBA_DXT1:
160 case PIPE_FORMAT_RGB_DXT1:
161 return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT1);
162 case PIPE_FORMAT_RGBA_DXT3:
163 return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT2_3);
164 case PIPE_FORMAT_RGBA_DXT5:
165 return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5);
166 #endif
167 case PIPE_FORMAT_S8_Z24:
168 return (MAPSURF_32BIT | MT_32BIT_xL824);
169 default:
170 fprintf(stderr, "i915: translate_texture_format() bad image format %x\n",
171 pipeFormat);
172 assert(0);
173 return 0;
174 }
175 }
176
177
178 static void
179 i915_update_texture(struct i915_context *i915, uint unit,
180 uint state[6])
181 {
182 const struct pipe_mipmap_tree *mt = i915->texture[unit];
183 uint format, pitch;
184 const uint width = mt->width0, height = mt->height0, depth = mt->depth0;
185 const uint num_levels = mt->last_level - mt->first_level;
186
187 assert(mt);
188 assert(width);
189 assert(height);
190 assert(depth);
191
192 format = translate_texture_format(mt->format);
193 pitch = mt->pitch * mt->cpp;
194
195 assert(format);
196 assert(pitch);
197
198 /* MS3 state */
199 state[0] =
200 (((height - 1) << MS3_HEIGHT_SHIFT)
201 | ((width - 1) << MS3_WIDTH_SHIFT)
202 | format
203 | MS3_USE_FENCE_REGS);
204
205 /* MS4 state */
206 state[1] =
207 ((((pitch / 4) - 1) << MS4_PITCH_SHIFT)
208 | MS4_CUBE_FACE_ENA_MASK
209 | ((num_levels * 4) << MS4_MAX_LOD_SHIFT)
210 | ((depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
211 }
212
213
214 void
215 i915_update_textures(struct i915_context *i915)
216 {
217 uint unit;
218
219 for (unit = 0; unit < I915_TEX_UNITS; unit++) {
220 /* determine unit enable/disable by looking for a bound mipmap tree */
221 /* could also examine the fragment program? */
222 if (i915->texture[unit]) {
223 i915_update_texture(i915, unit, i915->current.texbuffer[unit]);
224 }
225 }
226
227 i915->hardware_dirty |= I915_HW_MAP;
228 }