1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "pipe/p_context.h"
29 #include "pipe/p_state.h"
30 #include "pipe/p_util.h"
32 #include "i915_state_inlines.h"
33 #include "i915_context.h"
35 #include "i915_state.h"
39 * Compute i915 texture sampling state.
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
46 static void update_sampler(struct i915_context
*i915
,
48 const struct i915_sampler_state
*sampler
,
49 const struct i915_texture
*tex
,
52 const struct pipe_texture
*pt
= &tex
->base
;
54 /* Need to do this after updating the maps, which call the
55 * intel_finalize_mipmap_tree and hence can update firstLevel:
57 state
[0] = sampler
->state
[0];
58 state
[1] = sampler
->state
[1];
59 state
[2] = sampler
->state
[2];
61 if (pt
->format
== PIPE_FORMAT_YCBCR
||
62 pt
->format
== PIPE_FORMAT_YCBCR_REV
)
63 state
[0] |= SS2_COLORSPACE_CONVERSION
;
65 /* 3D textures don't seem to respect the border color.
66 * Fallback if there's ever a danger that they might refer to
69 * Effectively this means fallback on 3D clamp or
72 * XXX: Check if this is true on i945.
73 * XXX: Check if this bug got fixed in release silicon.
77 const unsigned ws
= sampler
->templ
->wrap_s
;
78 const unsigned wt
= sampler
->templ
->wrap_t
;
79 const unsigned wr
= sampler
->templ
->wrap_r
;
80 if (pt
->target
== PIPE_TEXTURE_3D
&&
81 (sampler
->templ
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
||
82 sampler
->templ
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
) &&
83 (ws
== PIPE_TEX_WRAP_CLAMP
||
84 wt
== PIPE_TEX_WRAP_CLAMP
||
85 wr
== PIPE_TEX_WRAP_CLAMP
||
86 ws
== PIPE_TEX_WRAP_CLAMP_TO_BORDER
||
87 wt
== PIPE_TEX_WRAP_CLAMP_TO_BORDER
||
88 wr
== PIPE_TEX_WRAP_CLAMP_TO_BORDER
)) {
89 if (i915
->strict_conformance
) {
91 /* sampler->fallback = true; */
98 state
[1] |= (unit
<< SS3_TEXTUREMAP_INDEX_SHIFT
);
102 void i915_update_samplers( struct i915_context
*i915
)
106 i915
->current
.sampler_enable_nr
= 0;
107 i915
->current
.sampler_enable_flags
= 0x0;
109 for (unit
= 0; unit
< i915
->num_textures
&& unit
< i915
->num_samplers
;
111 /* determine unit enable/disable by looking for a bound texture */
112 /* could also examine the fragment program? */
113 if (i915
->texture
[unit
]) {
114 update_sampler( i915
,
116 i915
->sampler
[unit
], /* sampler state */
117 i915
->texture
[unit
], /* texture */
118 i915
->current
.sampler
[unit
] /* the result */
121 i915
->current
.sampler_enable_nr
++;
122 i915
->current
.sampler_enable_flags
|= (1 << unit
);
126 i915
->hardware_dirty
|= I915_HW_SAMPLER
;
131 translate_texture_format(enum pipe_format pipeFormat
)
133 switch (pipeFormat
) {
134 case PIPE_FORMAT_U_L8
:
135 return MAPSURF_8BIT
| MT_8BIT_L8
;
136 case PIPE_FORMAT_U_I8
:
137 return MAPSURF_8BIT
| MT_8BIT_I8
;
138 case PIPE_FORMAT_U_A8
:
139 return MAPSURF_8BIT
| MT_8BIT_A8
;
140 case PIPE_FORMAT_U_A8_L8
:
141 return MAPSURF_16BIT
| MT_16BIT_AY88
;
142 case PIPE_FORMAT_R5G6B5_UNORM
:
143 return MAPSURF_16BIT
| MT_16BIT_RGB565
;
144 case PIPE_FORMAT_A1R5G5B5_UNORM
:
145 return MAPSURF_16BIT
| MT_16BIT_ARGB1555
;
146 case PIPE_FORMAT_A4R4G4B4_UNORM
:
147 return MAPSURF_16BIT
| MT_16BIT_ARGB4444
;
148 case PIPE_FORMAT_A8R8G8B8_UNORM
:
149 return MAPSURF_32BIT
| MT_32BIT_ARGB8888
;
150 case PIPE_FORMAT_YCBCR_REV
:
151 return (MAPSURF_422
| MT_422_YCRCB_NORMAL
);
152 case PIPE_FORMAT_YCBCR
:
153 return (MAPSURF_422
| MT_422_YCRCB_SWAPY
);
155 case PIPE_FORMAT_RGB_FXT1
:
156 case PIPE_FORMAT_RGBA_FXT1
:
157 return (MAPSURF_COMPRESSED
| MT_COMPRESS_FXT1
);
159 case PIPE_FORMAT_Z16_UNORM
:
160 return (MAPSURF_16BIT
| MT_16BIT_L16
);
162 case PIPE_FORMAT_RGBA_DXT1
:
163 case PIPE_FORMAT_RGB_DXT1
:
164 return (MAPSURF_COMPRESSED
| MT_COMPRESS_DXT1
);
165 case PIPE_FORMAT_RGBA_DXT3
:
166 return (MAPSURF_COMPRESSED
| MT_COMPRESS_DXT2_3
);
167 case PIPE_FORMAT_RGBA_DXT5
:
168 return (MAPSURF_COMPRESSED
| MT_COMPRESS_DXT4_5
);
170 case PIPE_FORMAT_S8Z24_UNORM
:
171 return (MAPSURF_32BIT
| MT_32BIT_xL824
);
173 debug_printf("i915: translate_texture_format() bad image format %x\n",
182 i915_update_texture(struct i915_context
*i915
, uint unit
,
185 const struct i915_texture
*tex
= i915
->texture
[unit
];
186 const struct pipe_texture
*pt
= &tex
->base
;
188 const uint width
= pt
->width
[0], height
= pt
->height
[0], depth
= pt
->depth
[0];
189 const uint num_levels
= pt
->last_level
;
196 format
= translate_texture_format(pt
->format
);
197 pitch
= tex
->pitch
* pt
->cpp
;
204 (((height
- 1) << MS3_HEIGHT_SHIFT
)
205 | ((width
- 1) << MS3_WIDTH_SHIFT
)
207 | MS3_USE_FENCE_REGS
);
210 * XXX sampler->max_lod should be used to program the MAX_LOD field below.
211 * Also, when min_filter != mag_filter and there's just one mipmap level,
212 * set max_lod = 1 to make sure i915 chooses between min/mag filtering.
217 ((((pitch
/ 4) - 1) << MS4_PITCH_SHIFT
)
218 | MS4_CUBE_FACE_ENA_MASK
219 | ((num_levels
* 4) << MS4_MAX_LOD_SHIFT
)
220 | ((depth
- 1) << MS4_VOLUME_DEPTH_SHIFT
));
225 i915_update_textures(struct i915_context
*i915
)
229 for (unit
= 0; unit
< i915
->num_textures
&& unit
< i915
->num_samplers
;
231 /* determine unit enable/disable by looking for a bound texture */
232 /* could also examine the fragment program? */
233 if (i915
->texture
[unit
]) {
234 i915_update_texture(i915
, unit
, i915
->current
.texbuffer
[unit
]);
238 i915
->hardware_dirty
|= I915_HW_MAP
;