2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "texformat.h"
37 #include "intel_mipmap_tree.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_tex.h"
42 #include "brw_context.h"
43 #include "brw_state.h"
44 #include "brw_defines.h"
47 static GLuint
translate_tex_target( GLenum target
)
51 return BRW_SURFACE_1D
;
53 case GL_TEXTURE_RECTANGLE_NV
:
54 return BRW_SURFACE_2D
;
57 return BRW_SURFACE_2D
;
60 return BRW_SURFACE_3D
;
62 case GL_TEXTURE_CUBE_MAP
:
63 return BRW_SURFACE_CUBE
;
72 static GLuint
translate_tex_format( GLuint mesa_format
)
74 switch( mesa_format
) {
76 return BRW_SURFACEFORMAT_L8_UNORM
;
79 return BRW_SURFACEFORMAT_I8_UNORM
;
82 return BRW_SURFACEFORMAT_A8_UNORM
;
84 case MESA_FORMAT_AL88
:
85 return BRW_SURFACEFORMAT_L8A8_UNORM
;
87 case MESA_FORMAT_RGB888
:
88 assert(0); /* not supported for sampling */
89 return BRW_SURFACEFORMAT_R8G8B8_UNORM
;
91 case MESA_FORMAT_ARGB8888
:
92 return BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
94 case MESA_FORMAT_RGBA8888_REV
:
95 return BRW_SURFACEFORMAT_R8G8B8A8_UNORM
;
97 case MESA_FORMAT_RGB565
:
98 return BRW_SURFACEFORMAT_B5G6R5_UNORM
;
100 case MESA_FORMAT_ARGB1555
:
101 return BRW_SURFACEFORMAT_B5G5R5A1_UNORM
;
103 case MESA_FORMAT_ARGB4444
:
104 return BRW_SURFACEFORMAT_B4G4R4A4_UNORM
;
106 case MESA_FORMAT_YCBCR_REV
:
107 return BRW_SURFACEFORMAT_YCRCB_NORMAL
;
109 case MESA_FORMAT_YCBCR
:
110 return BRW_SURFACEFORMAT_YCRCB_SWAPUVY
;
112 case MESA_FORMAT_RGB_FXT1
:
113 case MESA_FORMAT_RGBA_FXT1
:
114 return BRW_SURFACEFORMAT_FXT1
;
116 case MESA_FORMAT_Z16
:
117 return BRW_SURFACEFORMAT_I16_UNORM
;
119 case MESA_FORMAT_RGB_DXT1
:
120 return BRW_SURFACEFORMAT_DXT1_RGB
;
122 case MESA_FORMAT_RGBA_DXT1
:
123 return BRW_SURFACEFORMAT_BC1_UNORM
;
125 case MESA_FORMAT_RGBA_DXT3
:
126 return BRW_SURFACEFORMAT_BC2_UNORM
;
128 case MESA_FORMAT_RGBA_DXT5
:
129 return BRW_SURFACEFORMAT_BC3_UNORM
;
131 case MESA_FORMAT_SRGBA8
:
132 return BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB
;
133 case MESA_FORMAT_SRGB_DXT1
:
134 return BRW_SURFACEFORMAT_BC1_UNORM_SRGB
;
143 void brw_update_texture_surface( GLcontext
*ctx
, GLuint unit
)
145 struct intel_context
*intel
= intel_context(ctx
);
146 struct brw_context
*brw
= brw_context(ctx
);
147 struct gl_texture_object
*tObj
= brw
->attribs
.Texture
->Unit
[unit
]._Current
;
148 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
149 struct gl_texture_image
*firstImage
= tObj
->Image
[0][intelObj
->firstLevel
];
150 struct brw_surface_state surf
;
152 memset(&surf
, 0, sizeof(surf
));
154 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
155 surf
.ss0
.surface_type
= translate_tex_target(tObj
->Target
);
156 surf
.ss0
.surface_format
= translate_tex_format(firstImage
->TexFormat
->MesaFormat
);
158 /* This is ok for all textures with channel width 8bit or less:
160 /* surf.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
163 surf
.ss1
.base_addr
= bmBufferOffset(intel
,
164 intelObj
->mt
->region
->buffer
);
166 surf
.ss2
.mip_count
= intelObj
->lastLevel
- intelObj
->firstLevel
;
167 surf
.ss2
.width
= firstImage
->Width
- 1;
168 surf
.ss2
.height
= firstImage
->Height
- 1;
170 surf
.ss3
.tile_walk
= BRW_TILEWALK_XMAJOR
;
171 surf
.ss3
.tiled_surface
= intelObj
->mt
->region
->tiled
; /* always zero */
172 surf
.ss3
.pitch
= (intelObj
->mt
->pitch
* intelObj
->mt
->cpp
) - 1;
173 surf
.ss3
.depth
= firstImage
->Depth
- 1;
175 surf
.ss4
.min_lod
= 0;
177 if (tObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
178 surf
.ss0
.cube_pos_x
= 1;
179 surf
.ss0
.cube_pos_y
= 1;
180 surf
.ss0
.cube_pos_z
= 1;
181 surf
.ss0
.cube_neg_x
= 1;
182 surf
.ss0
.cube_neg_y
= 1;
183 surf
.ss0
.cube_neg_z
= 1;
186 brw
->wm
.bind
.surf_ss_offset
[unit
+ 1] =
187 brw_cache_data( &brw
->cache
[BRW_SS_SURFACE
], &surf
);
192 #define OFFSET(TYPE, FIELD) ( (GLuint)&(((TYPE *)0)->FIELD) )
195 static void upload_wm_surfaces(struct brw_context
*brw
)
197 GLcontext
*ctx
= &brw
->intel
.ctx
;
198 struct intel_context
*intel
= &brw
->intel
;
199 struct brw_surface_binding_table bind
;
202 memcpy(&bind
, &brw
->wm
.bind
, sizeof(bind
));
205 struct brw_surface_state surf
;
206 struct intel_region
*region
= brw
->state
.draw_region
;
208 memset(&surf
, 0, sizeof(surf
));
210 if (region
->cpp
== 4)
211 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
213 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B5G6R5_UNORM
;
215 surf
.ss0
.surface_type
= BRW_SURFACE_2D
;
218 surf
.ss0
.color_blend
= (!brw
->attribs
.Color
->_LogicOpEnabled
&&
219 brw
->attribs
.Color
->BlendEnabled
);
222 surf
.ss0
.writedisable_red
= !brw
->attribs
.Color
->ColorMask
[0];
223 surf
.ss0
.writedisable_green
= !brw
->attribs
.Color
->ColorMask
[1];
224 surf
.ss0
.writedisable_blue
= !brw
->attribs
.Color
->ColorMask
[2];
225 surf
.ss0
.writedisable_alpha
= !brw
->attribs
.Color
->ColorMask
[3];
228 surf
.ss1
.base_addr
= bmBufferOffset(&brw
->intel
, region
->buffer
);
231 surf
.ss2
.width
= region
->pitch
- 1; /* XXX: not really! */
232 surf
.ss2
.height
= region
->height
- 1;
233 surf
.ss3
.tile_walk
= BRW_TILEWALK_XMAJOR
;
234 surf
.ss3
.tiled_surface
= region
->tiled
;
235 surf
.ss3
.pitch
= (region
->pitch
* region
->cpp
) - 1;
237 brw
->wm
.bind
.surf_ss_offset
[0] = brw_cache_data( &brw
->cache
[BRW_SS_SURFACE
], &surf
);
238 brw
->wm
.nr_surfaces
= 1;
242 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
243 struct gl_texture_unit
*texUnit
= &brw
->attribs
.Texture
->Unit
[i
];
245 /* _NEW_TEXTURE, BRW_NEW_TEXDATA
247 if (texUnit
->_ReallyEnabled
&&
248 intel_finalize_mipmap_tree(intel
,texUnit
->_Current
))
250 brw_update_texture_surface(ctx
, i
);
251 brw
->wm
.nr_surfaces
= i
+2;
253 else if( texUnit
->_ReallyEnabled
&&
254 texUnit
->_Current
== intel
->frame_buffer_texobj
)
256 brw
->wm
.bind
.surf_ss_offset
[i
+1] = brw
->wm
.bind
.surf_ss_offset
[0];
257 brw
->wm
.nr_surfaces
= i
+2;
260 brw
->wm
.bind
.surf_ss_offset
[i
+1] = 0;
264 brw
->wm
.bind_ss_offset
= brw_cache_data( &brw
->cache
[BRW_SS_SURF_BIND
],
268 const struct brw_tracked_state brw_wm_surfaces
= {
270 .mesa
= _NEW_COLOR
| _NEW_TEXTURE
| _NEW_BUFFERS
,
271 .brw
= (BRW_NEW_CONTEXT
|
272 BRW_NEW_LOCK
), /* required for bmBufferOffset */
275 .update
= upload_wm_surfaces