2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/imports.h"
37 #include "main/context.h"
38 #include "main/macros.h"
39 #include "main/texformat.h"
40 #include "main/teximage.h"
41 #include "main/texobj.h"
42 #include "main/enums.h"
44 #include "radeon_common.h"
45 #include "radeon_mipmap_tree.h"
46 #include "r200_context.h"
47 #include "r200_state.h"
48 #include "r200_ioctl.h"
49 #include "r200_swtcl.h"
54 #define R200_TXFORMAT_A8 R200_TXFORMAT_I8
55 #define R200_TXFORMAT_L8 R200_TXFORMAT_I8
56 #define R200_TXFORMAT_AL88 R200_TXFORMAT_AI88
57 #define R200_TXFORMAT_YCBCR R200_TXFORMAT_YVYU422
58 #define R200_TXFORMAT_YCBCR_REV R200_TXFORMAT_VYUY422
59 #define R200_TXFORMAT_RGB_DXT1 R200_TXFORMAT_DXT1
60 #define R200_TXFORMAT_RGBA_DXT1 R200_TXFORMAT_DXT1
61 #define R200_TXFORMAT_RGBA_DXT3 R200_TXFORMAT_DXT23
62 #define R200_TXFORMAT_RGBA_DXT5 R200_TXFORMAT_DXT45
65 [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f, 0 }
66 #define _COLOR_REV(f) \
67 [ MESA_FORMAT_ ## f ## _REV ] = { R200_TXFORMAT_ ## f, 0 }
69 [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f | R200_TXFORMAT_ALPHA_IN_MAP, 0 }
70 #define _ALPHA_REV(f) \
71 [ MESA_FORMAT_ ## f ## _REV ] = { R200_TXFORMAT_ ## f | R200_TXFORMAT_ALPHA_IN_MAP, 0 }
73 [ MESA_FORMAT_ ## f ] = { R200_TXFORMAT_ ## f, R200_YUV_TO_RGB }
75 [ MESA_FORMAT_ ## f ] = { 0xffffffff, 0 }
76 #define VALID_FORMAT(f) ( ((f) <= MESA_FORMAT_RGBA_DXT5) \
77 && (tx_table_be[f].format != 0xffffffff) )
80 GLuint format
, filter
;
83 static const struct tx_table tx_table_be
[] =
85 [ MESA_FORMAT_RGBA8888
] = { R200_TXFORMAT_ABGR8888
| R200_TXFORMAT_ALPHA_IN_MAP
, 0 },
112 static const struct tx_table tx_table_le
[] =
115 [ MESA_FORMAT_RGBA8888_REV
] = { R200_TXFORMAT_ABGR8888
| R200_TXFORMAT_ALPHA_IN_MAP
, 0 },
117 _ALPHA_REV(ARGB8888
),
118 [ MESA_FORMAT_RGB888
] = { R200_TXFORMAT_ARGB8888
, 0 },
122 _ALPHA_REV(ARGB4444
),
124 _ALPHA_REV(ARGB1555
),
145 /* ================================================================
146 * Texture combine functions
149 /* GL_ARB_texture_env_combine support
152 /* The color tables have combine functions for GL_SRC_COLOR,
153 * GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA.
155 static GLuint r200_register_color
[][R200_MAX_TEXTURE_UNITS
] =
158 R200_TXC_ARG_A_R0_COLOR
,
159 R200_TXC_ARG_A_R1_COLOR
,
160 R200_TXC_ARG_A_R2_COLOR
,
161 R200_TXC_ARG_A_R3_COLOR
,
162 R200_TXC_ARG_A_R4_COLOR
,
163 R200_TXC_ARG_A_R5_COLOR
166 R200_TXC_ARG_A_R0_COLOR
| R200_TXC_COMP_ARG_A
,
167 R200_TXC_ARG_A_R1_COLOR
| R200_TXC_COMP_ARG_A
,
168 R200_TXC_ARG_A_R2_COLOR
| R200_TXC_COMP_ARG_A
,
169 R200_TXC_ARG_A_R3_COLOR
| R200_TXC_COMP_ARG_A
,
170 R200_TXC_ARG_A_R4_COLOR
| R200_TXC_COMP_ARG_A
,
171 R200_TXC_ARG_A_R5_COLOR
| R200_TXC_COMP_ARG_A
174 R200_TXC_ARG_A_R0_ALPHA
,
175 R200_TXC_ARG_A_R1_ALPHA
,
176 R200_TXC_ARG_A_R2_ALPHA
,
177 R200_TXC_ARG_A_R3_ALPHA
,
178 R200_TXC_ARG_A_R4_ALPHA
,
179 R200_TXC_ARG_A_R5_ALPHA
182 R200_TXC_ARG_A_R0_ALPHA
| R200_TXC_COMP_ARG_A
,
183 R200_TXC_ARG_A_R1_ALPHA
| R200_TXC_COMP_ARG_A
,
184 R200_TXC_ARG_A_R2_ALPHA
| R200_TXC_COMP_ARG_A
,
185 R200_TXC_ARG_A_R3_ALPHA
| R200_TXC_COMP_ARG_A
,
186 R200_TXC_ARG_A_R4_ALPHA
| R200_TXC_COMP_ARG_A
,
187 R200_TXC_ARG_A_R5_ALPHA
| R200_TXC_COMP_ARG_A
191 static GLuint r200_tfactor_color
[] =
193 R200_TXC_ARG_A_TFACTOR_COLOR
,
194 R200_TXC_ARG_A_TFACTOR_COLOR
| R200_TXC_COMP_ARG_A
,
195 R200_TXC_ARG_A_TFACTOR_ALPHA
,
196 R200_TXC_ARG_A_TFACTOR_ALPHA
| R200_TXC_COMP_ARG_A
199 static GLuint r200_tfactor1_color
[] =
201 R200_TXC_ARG_A_TFACTOR1_COLOR
,
202 R200_TXC_ARG_A_TFACTOR1_COLOR
| R200_TXC_COMP_ARG_A
,
203 R200_TXC_ARG_A_TFACTOR1_ALPHA
,
204 R200_TXC_ARG_A_TFACTOR1_ALPHA
| R200_TXC_COMP_ARG_A
207 static GLuint r200_primary_color
[] =
209 R200_TXC_ARG_A_DIFFUSE_COLOR
,
210 R200_TXC_ARG_A_DIFFUSE_COLOR
| R200_TXC_COMP_ARG_A
,
211 R200_TXC_ARG_A_DIFFUSE_ALPHA
,
212 R200_TXC_ARG_A_DIFFUSE_ALPHA
| R200_TXC_COMP_ARG_A
215 /* GL_ZERO table - indices 0-3
216 * GL_ONE table - indices 1-4
218 static GLuint r200_zero_color
[] =
221 R200_TXC_ARG_A_ZERO
| R200_TXC_COMP_ARG_A
,
223 R200_TXC_ARG_A_ZERO
| R200_TXC_COMP_ARG_A
,
227 /* The alpha tables only have GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA.
229 static GLuint r200_register_alpha
[][R200_MAX_TEXTURE_UNITS
] =
232 R200_TXA_ARG_A_R0_ALPHA
,
233 R200_TXA_ARG_A_R1_ALPHA
,
234 R200_TXA_ARG_A_R2_ALPHA
,
235 R200_TXA_ARG_A_R3_ALPHA
,
236 R200_TXA_ARG_A_R4_ALPHA
,
237 R200_TXA_ARG_A_R5_ALPHA
240 R200_TXA_ARG_A_R0_ALPHA
| R200_TXA_COMP_ARG_A
,
241 R200_TXA_ARG_A_R1_ALPHA
| R200_TXA_COMP_ARG_A
,
242 R200_TXA_ARG_A_R2_ALPHA
| R200_TXA_COMP_ARG_A
,
243 R200_TXA_ARG_A_R3_ALPHA
| R200_TXA_COMP_ARG_A
,
244 R200_TXA_ARG_A_R4_ALPHA
| R200_TXA_COMP_ARG_A
,
245 R200_TXA_ARG_A_R5_ALPHA
| R200_TXA_COMP_ARG_A
249 static GLuint r200_tfactor_alpha
[] =
251 R200_TXA_ARG_A_TFACTOR_ALPHA
,
252 R200_TXA_ARG_A_TFACTOR_ALPHA
| R200_TXA_COMP_ARG_A
255 static GLuint r200_tfactor1_alpha
[] =
257 R200_TXA_ARG_A_TFACTOR1_ALPHA
,
258 R200_TXA_ARG_A_TFACTOR1_ALPHA
| R200_TXA_COMP_ARG_A
261 static GLuint r200_primary_alpha
[] =
263 R200_TXA_ARG_A_DIFFUSE_ALPHA
,
264 R200_TXA_ARG_A_DIFFUSE_ALPHA
| R200_TXA_COMP_ARG_A
267 /* GL_ZERO table - indices 0-1
268 * GL_ONE table - indices 1-2
270 static GLuint r200_zero_alpha
[] =
273 R200_TXA_ARG_A_ZERO
| R200_TXA_COMP_ARG_A
,
278 /* Extract the arg from slot A, shift it into the correct argument slot
279 * and set the corresponding complement bit.
281 #define R200_COLOR_ARG( n, arg ) \
284 ((color_arg[n] & R200_TXC_ARG_A_MASK) \
285 << R200_TXC_ARG_##arg##_SHIFT); \
287 ((color_arg[n] >> R200_TXC_COMP_ARG_A_SHIFT) \
288 << R200_TXC_COMP_ARG_##arg##_SHIFT); \
291 #define R200_ALPHA_ARG( n, arg ) \
294 ((alpha_arg[n] & R200_TXA_ARG_A_MASK) \
295 << R200_TXA_ARG_##arg##_SHIFT); \
297 ((alpha_arg[n] >> R200_TXA_COMP_ARG_A_SHIFT) \
298 << R200_TXA_COMP_ARG_##arg##_SHIFT); \
302 /* ================================================================
303 * Texture unit state management
306 static GLboolean
r200UpdateTextureEnv( GLcontext
*ctx
, int unit
, int slot
, GLuint replaceargs
)
308 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
309 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
310 GLuint color_combine
, alpha_combine
;
311 GLuint color_scale
= rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXCBLEND2
] &
312 ~(R200_TXC_SCALE_MASK
| R200_TXC_OUTPUT_REG_MASK
| R200_TXC_TFACTOR_SEL_MASK
|
313 R200_TXC_TFACTOR1_SEL_MASK
);
314 GLuint alpha_scale
= rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXABLEND2
] &
315 ~(R200_TXA_DOT_ALPHA
| R200_TXA_SCALE_MASK
| R200_TXA_OUTPUT_REG_MASK
|
316 R200_TXA_TFACTOR_SEL_MASK
| R200_TXA_TFACTOR1_SEL_MASK
);
318 /* texUnit->_Current can be NULL if and only if the texture unit is
319 * not actually enabled.
321 assert( (texUnit
->_ReallyEnabled
== 0)
322 || (texUnit
->_Current
!= NULL
) );
324 if ( R200_DEBUG
& DEBUG_TEXTURE
) {
325 fprintf( stderr
, "%s( %p, %d )\n", __FUNCTION__
, (void *)ctx
, unit
);
328 /* Set the texture environment state. Isn't this nice and clean?
329 * The chip will automagically set the texture alpha to 0xff when
330 * the texture format does not include an alpha component. This
331 * reduces the amount of special-casing we have to do, alpha-only
332 * textures being a notable exception.
335 color_scale
|= ((rmesa
->state
.texture
.unit
[unit
].outputreg
+ 1) << R200_TXC_OUTPUT_REG_SHIFT
) |
336 (unit
<< R200_TXC_TFACTOR_SEL_SHIFT
) |
337 (replaceargs
<< R200_TXC_TFACTOR1_SEL_SHIFT
);
338 alpha_scale
|= ((rmesa
->state
.texture
.unit
[unit
].outputreg
+ 1) << R200_TXA_OUTPUT_REG_SHIFT
) |
339 (unit
<< R200_TXA_TFACTOR_SEL_SHIFT
) |
340 (replaceargs
<< R200_TXA_TFACTOR1_SEL_SHIFT
);
342 if ( !texUnit
->_ReallyEnabled
) {
344 color_combine
= R200_TXC_ARG_A_ZERO
| R200_TXC_ARG_B_ZERO
345 | R200_TXC_ARG_C_DIFFUSE_COLOR
| R200_TXC_OP_MADD
;
346 alpha_combine
= R200_TXA_ARG_A_ZERO
| R200_TXA_ARG_B_ZERO
347 | R200_TXA_ARG_C_DIFFUSE_ALPHA
| R200_TXA_OP_MADD
;
350 GLuint color_arg
[3], alpha_arg
[3];
352 const GLuint numColorArgs
= texUnit
->_CurrentCombine
->_NumArgsRGB
;
353 const GLuint numAlphaArgs
= texUnit
->_CurrentCombine
->_NumArgsA
;
354 GLuint RGBshift
= texUnit
->_CurrentCombine
->ScaleShiftRGB
;
355 GLuint Ashift
= texUnit
->_CurrentCombine
->ScaleShiftA
;
358 const GLint replaceoprgb
=
359 ctx
->Texture
.Unit
[replaceargs
]._CurrentCombine
->OperandRGB
[0] - GL_SRC_COLOR
;
360 const GLint replaceopa
=
361 ctx
->Texture
.Unit
[replaceargs
]._CurrentCombine
->OperandA
[0] - GL_SRC_ALPHA
;
364 * Extract the color and alpha combine function arguments.
366 for ( i
= 0 ; i
< numColorArgs
; i
++ ) {
367 GLint op
= texUnit
->_CurrentCombine
->OperandRGB
[i
] - GL_SRC_COLOR
;
368 const GLint srcRGBi
= texUnit
->_CurrentCombine
->SourceRGB
[i
];
373 color_arg
[i
] = r200_register_color
[op
][unit
];
376 color_arg
[i
] = r200_tfactor_color
[op
];
378 case GL_PRIMARY_COLOR
:
379 color_arg
[i
] = r200_primary_color
[op
];
382 if (replaceargs
!= unit
) {
383 const GLint srcRGBreplace
=
384 ctx
->Texture
.Unit
[replaceargs
]._CurrentCombine
->SourceRGB
[0];
386 op
= op
^ replaceopa
;
389 op
= op
^ replaceoprgb
;
391 switch (srcRGBreplace
) {
393 color_arg
[i
] = r200_register_color
[op
][replaceargs
];
396 color_arg
[i
] = r200_tfactor1_color
[op
];
398 case GL_PRIMARY_COLOR
:
399 color_arg
[i
] = r200_primary_color
[op
];
403 color_arg
[i
] = r200_primary_color
[op
];
405 color_arg
[i
] = r200_register_color
[op
]
406 [rmesa
->state
.texture
.unit
[replaceargs
- 1].outputreg
];
409 color_arg
[i
] = r200_zero_color
[op
];
412 color_arg
[i
] = r200_zero_color
[op
+1];
420 color_arg
[i
] = r200_register_color
[op
][srcRGBreplace
- GL_TEXTURE0
];
428 color_arg
[i
] = r200_primary_color
[op
];
430 color_arg
[i
] = r200_register_color
[op
]
431 [rmesa
->state
.texture
.unit
[unit
- 1].outputreg
];
435 color_arg
[i
] = r200_zero_color
[op
];
438 color_arg
[i
] = r200_zero_color
[op
+1];
446 color_arg
[i
] = r200_register_color
[op
][srcRGBi
- GL_TEXTURE0
];
453 for ( i
= 0 ; i
< numAlphaArgs
; i
++ ) {
454 GLint op
= texUnit
->_CurrentCombine
->OperandA
[i
] - GL_SRC_ALPHA
;
455 const GLint srcAi
= texUnit
->_CurrentCombine
->SourceA
[i
];
460 alpha_arg
[i
] = r200_register_alpha
[op
][unit
];
463 alpha_arg
[i
] = r200_tfactor_alpha
[op
];
465 case GL_PRIMARY_COLOR
:
466 alpha_arg
[i
] = r200_primary_alpha
[op
];
469 if (replaceargs
!= unit
) {
470 const GLint srcAreplace
=
471 ctx
->Texture
.Unit
[replaceargs
]._CurrentCombine
->SourceA
[0];
472 op
= op
^ replaceopa
;
473 switch (srcAreplace
) {
475 alpha_arg
[i
] = r200_register_alpha
[op
][replaceargs
];
478 alpha_arg
[i
] = r200_tfactor1_alpha
[op
];
480 case GL_PRIMARY_COLOR
:
481 alpha_arg
[i
] = r200_primary_alpha
[op
];
485 alpha_arg
[i
] = r200_primary_alpha
[op
];
487 alpha_arg
[i
] = r200_register_alpha
[op
]
488 [rmesa
->state
.texture
.unit
[replaceargs
- 1].outputreg
];
491 alpha_arg
[i
] = r200_zero_alpha
[op
];
494 alpha_arg
[i
] = r200_zero_alpha
[op
+1];
502 alpha_arg
[i
] = r200_register_alpha
[op
][srcAreplace
- GL_TEXTURE0
];
510 alpha_arg
[i
] = r200_primary_alpha
[op
];
512 alpha_arg
[i
] = r200_register_alpha
[op
]
513 [rmesa
->state
.texture
.unit
[unit
- 1].outputreg
];
517 alpha_arg
[i
] = r200_zero_alpha
[op
];
520 alpha_arg
[i
] = r200_zero_alpha
[op
+1];
528 alpha_arg
[i
] = r200_register_alpha
[op
][srcAi
- GL_TEXTURE0
];
536 * Build up the color and alpha combine functions.
538 switch ( texUnit
->_CurrentCombine
->ModeRGB
) {
540 color_combine
= (R200_TXC_ARG_A_ZERO
|
541 R200_TXC_ARG_B_ZERO
|
543 R200_COLOR_ARG( 0, C
);
546 color_combine
= (R200_TXC_ARG_C_ZERO
|
548 R200_COLOR_ARG( 0, A
);
549 R200_COLOR_ARG( 1, B
);
552 color_combine
= (R200_TXC_ARG_B_ZERO
|
553 R200_TXC_COMP_ARG_B
|
555 R200_COLOR_ARG( 0, A
);
556 R200_COLOR_ARG( 1, C
);
559 color_combine
= (R200_TXC_ARG_B_ZERO
|
560 R200_TXC_COMP_ARG_B
|
561 R200_TXC_BIAS_ARG_C
| /* new */
562 R200_TXC_OP_MADD
); /* was ADDSIGNED */
563 R200_COLOR_ARG( 0, A
);
564 R200_COLOR_ARG( 1, C
);
567 color_combine
= (R200_TXC_ARG_B_ZERO
|
568 R200_TXC_COMP_ARG_B
|
571 R200_COLOR_ARG( 0, A
);
572 R200_COLOR_ARG( 1, C
);
575 color_combine
= (R200_TXC_OP_LERP
);
576 R200_COLOR_ARG( 0, B
);
577 R200_COLOR_ARG( 1, A
);
578 R200_COLOR_ARG( 2, C
);
581 case GL_DOT3_RGB_EXT
:
582 case GL_DOT3_RGBA_EXT
:
583 /* The EXT version of the DOT3 extension does not support the
584 * scale factor, but the ARB version (and the version in OpenGL
592 /* DOT3 works differently on R200 than on R100. On R100, just
593 * setting the DOT3 mode did everything for you. On R200, the
594 * driver has to enable the biasing and scale in the inputs to
595 * put them in the proper [-1,1] range. This is what the 4x and
596 * the -0.5 in the DOT3 spec do. The post-scale is then set
600 color_combine
= (R200_TXC_ARG_C_ZERO
|
602 R200_TXC_BIAS_ARG_A
|
603 R200_TXC_BIAS_ARG_B
|
604 R200_TXC_SCALE_ARG_A
|
605 R200_TXC_SCALE_ARG_B
);
606 R200_COLOR_ARG( 0, A
);
607 R200_COLOR_ARG( 1, B
);
610 case GL_MODULATE_ADD_ATI
:
611 color_combine
= (R200_TXC_OP_MADD
);
612 R200_COLOR_ARG( 0, A
);
613 R200_COLOR_ARG( 1, C
);
614 R200_COLOR_ARG( 2, B
);
616 case GL_MODULATE_SIGNED_ADD_ATI
:
617 color_combine
= (R200_TXC_BIAS_ARG_C
| /* new */
618 R200_TXC_OP_MADD
); /* was ADDSIGNED */
619 R200_COLOR_ARG( 0, A
);
620 R200_COLOR_ARG( 1, C
);
621 R200_COLOR_ARG( 2, B
);
623 case GL_MODULATE_SUBTRACT_ATI
:
624 color_combine
= (R200_TXC_NEG_ARG_C
|
626 R200_COLOR_ARG( 0, A
);
627 R200_COLOR_ARG( 1, C
);
628 R200_COLOR_ARG( 2, B
);
634 switch ( texUnit
->_CurrentCombine
->ModeA
) {
636 alpha_combine
= (R200_TXA_ARG_A_ZERO
|
637 R200_TXA_ARG_B_ZERO
|
639 R200_ALPHA_ARG( 0, C
);
642 alpha_combine
= (R200_TXA_ARG_C_ZERO
|
644 R200_ALPHA_ARG( 0, A
);
645 R200_ALPHA_ARG( 1, B
);
648 alpha_combine
= (R200_TXA_ARG_B_ZERO
|
649 R200_TXA_COMP_ARG_B
|
651 R200_ALPHA_ARG( 0, A
);
652 R200_ALPHA_ARG( 1, C
);
655 alpha_combine
= (R200_TXA_ARG_B_ZERO
|
656 R200_TXA_COMP_ARG_B
|
657 R200_TXA_BIAS_ARG_C
| /* new */
658 R200_TXA_OP_MADD
); /* was ADDSIGNED */
659 R200_ALPHA_ARG( 0, A
);
660 R200_ALPHA_ARG( 1, C
);
663 alpha_combine
= (R200_TXA_ARG_B_ZERO
|
664 R200_TXA_COMP_ARG_B
|
667 R200_ALPHA_ARG( 0, A
);
668 R200_ALPHA_ARG( 1, C
);
671 alpha_combine
= (R200_TXA_OP_LERP
);
672 R200_ALPHA_ARG( 0, B
);
673 R200_ALPHA_ARG( 1, A
);
674 R200_ALPHA_ARG( 2, C
);
677 case GL_MODULATE_ADD_ATI
:
678 alpha_combine
= (R200_TXA_OP_MADD
);
679 R200_ALPHA_ARG( 0, A
);
680 R200_ALPHA_ARG( 1, C
);
681 R200_ALPHA_ARG( 2, B
);
683 case GL_MODULATE_SIGNED_ADD_ATI
:
684 alpha_combine
= (R200_TXA_BIAS_ARG_C
| /* new */
685 R200_TXA_OP_MADD
); /* was ADDSIGNED */
686 R200_ALPHA_ARG( 0, A
);
687 R200_ALPHA_ARG( 1, C
);
688 R200_ALPHA_ARG( 2, B
);
690 case GL_MODULATE_SUBTRACT_ATI
:
691 alpha_combine
= (R200_TXA_NEG_ARG_C
|
693 R200_ALPHA_ARG( 0, A
);
694 R200_ALPHA_ARG( 1, C
);
695 R200_ALPHA_ARG( 2, B
);
701 if ( (texUnit
->_CurrentCombine
->ModeRGB
== GL_DOT3_RGBA_EXT
)
702 || (texUnit
->_CurrentCombine
->ModeRGB
== GL_DOT3_RGBA
) ) {
703 alpha_scale
|= R200_TXA_DOT_ALPHA
;
708 * Apply the scale factor.
710 color_scale
|= (RGBshift
<< R200_TXC_SCALE_SHIFT
);
711 alpha_scale
|= (Ashift
<< R200_TXA_SCALE_SHIFT
);
717 if ( rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXCBLEND
] != color_combine
||
718 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXABLEND
] != alpha_combine
||
719 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXCBLEND2
] != color_scale
||
720 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXABLEND2
] != alpha_scale
) {
721 R200_STATECHANGE( rmesa
, pix
[slot
] );
722 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXCBLEND
] = color_combine
;
723 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXABLEND
] = alpha_combine
;
724 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXCBLEND2
] = color_scale
;
725 rmesa
->hw
.pix
[slot
].cmd
[PIX_PP_TXABLEND2
] = alpha_scale
;
731 void r200SetTexOffset(__DRIcontext
* pDRICtx
, GLint texname
,
732 unsigned long long offset
, GLint depth
, GLuint pitch
)
734 r200ContextPtr rmesa
= pDRICtx
->driverPrivate
;
735 struct gl_texture_object
*tObj
=
736 _mesa_lookup_texture(rmesa
->radeon
.glCtx
, texname
);
737 radeonTexObjPtr t
= radeon_tex_obj(tObj
);
742 t
->image_override
= GL_TRUE
;
748 t
->override_offset
= offset
;
749 t
->pp_txpitch
= pitch
- 32;
753 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_ARGB8888
].format
;
754 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_ARGB8888
].filter
;
758 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_RGB888
].format
;
759 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_RGB888
].filter
;
762 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_RGB565
].format
;
763 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_RGB565
].filter
;
768 void r200SetTexBuffer2(__DRIcontext
*pDRICtx
, GLint target
, GLint glx_texture_format
,
769 __DRIdrawable
*dPriv
)
771 struct gl_texture_unit
*texUnit
;
772 struct gl_texture_object
*texObj
;
773 struct gl_texture_image
*texImage
;
774 struct radeon_renderbuffer
*rb
;
775 radeon_texture_image
*rImage
;
776 radeonContextPtr radeon
;
777 r200ContextPtr rmesa
;
778 struct radeon_framebuffer
*rfb
;
781 uint32_t internalFormat
, type
, format
;
784 format
= GL_UNSIGNED_BYTE
;
785 internalFormat
= (glx_texture_format
== GLX_TEXTURE_FORMAT_RGB_EXT
? 3 : 4);
787 radeon
= pDRICtx
->driverPrivate
;
788 rmesa
= pDRICtx
->driverPrivate
;
790 rfb
= dPriv
->driverPrivate
;
791 texUnit
= &radeon
->glCtx
->Texture
.Unit
[radeon
->glCtx
->Texture
.CurrentUnit
];
792 texObj
= _mesa_select_tex_object(radeon
->glCtx
, texUnit
, target
);
793 texImage
= _mesa_get_tex_image(radeon
->glCtx
, texObj
, target
, 0);
795 rImage
= get_radeon_texture_image(texImage
);
796 t
= radeon_tex_obj(texObj
);
801 radeon_update_renderbuffers(pDRICtx
, dPriv
);
802 /* back & depth buffer are useless free them right away */
803 rb
= (void*)rfb
->base
.Attachment
[BUFFER_DEPTH
].Renderbuffer
;
805 radeon_bo_unref(rb
->bo
);
808 rb
= (void*)rfb
->base
.Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
810 radeon_bo_unref(rb
->bo
);
813 rb
= rfb
->color_rb
[0];
814 if (rb
->bo
== NULL
) {
815 /* Failed to BO for the buffer */
819 _mesa_lock_texture(radeon
->glCtx
, texObj
);
821 radeon_bo_unref(t
->bo
);
825 radeon_bo_unref(rImage
->bo
);
829 radeon_miptree_unreference(t
->mt
);
833 radeon_miptree_unreference(rImage
->mt
);
836 fprintf(stderr
,"settexbuf %d %dx%d@%d\n", rb
->pitch
, rb
->width
, rb
->height
, rb
->cpp
);
837 _mesa_init_teximage_fields(radeon
->glCtx
, target
, texImage
,
838 rb
->width
, rb
->height
, 1, 0, rb
->cpp
);
839 texImage
->RowStride
= rb
->pitch
/ rb
->cpp
;
840 texImage
->TexFormat
= radeonChooseTextureFormat(radeon
->glCtx
,
844 radeon_bo_ref(rImage
->bo
);
846 radeon_bo_ref(t
->bo
);
848 t
->image_override
= GL_TRUE
;
849 t
->override_offset
= 0;
850 t
->pp_txpitch
&= (1 << 13) -1;
851 pitch_val
= rb
->pitch
;
854 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_ARGB8888
].format
;
855 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_ARGB8888
].filter
;
859 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_RGB888
].format
;
860 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_RGB888
].filter
;
863 t
->pp_txformat
= tx_table_le
[MESA_FORMAT_RGB565
].format
;
864 t
->pp_txfilter
|= tx_table_le
[MESA_FORMAT_RGB565
].filter
;
867 t
->pp_txsize
= ((rb
->width
- 1) << RADEON_TEX_USIZE_SHIFT
)
868 | ((rb
->height
- 1) << RADEON_TEX_VSIZE_SHIFT
);
869 t
->pp_txformat
|= R200_TXFORMAT_NON_POWER2
;
870 t
->pp_txpitch
= pitch_val
;
873 t
->validated
= GL_TRUE
;
874 _mesa_unlock_texture(radeon
->glCtx
, texObj
);
879 void r200SetTexBuffer(__DRIcontext
*pDRICtx
, GLint target
, __DRIdrawable
*dPriv
)
881 r200SetTexBuffer2(pDRICtx
, target
, GLX_TEXTURE_FORMAT_RGBA_EXT
, dPriv
);
888 static GLboolean
r200UpdateAllTexEnv( GLcontext
*ctx
)
890 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
891 GLint i
, j
, currslot
;
892 GLint maxunitused
= -1;
893 GLboolean texregfree
[6] = {GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
};
894 GLubyte stageref
[7] = {0, 0, 0, 0, 0, 0, 0};
895 GLint nextunit
[R200_MAX_TEXTURE_UNITS
] = {0, 0, 0, 0, 0, 0};
896 GLint currentnext
= -1;
899 /* find highest used unit */
900 for ( j
= 0; j
< R200_MAX_TEXTURE_UNITS
; j
++) {
901 if (ctx
->Texture
.Unit
[j
]._ReallyEnabled
) {
905 stageref
[maxunitused
+ 1] = REF_COLOR
| REF_ALPHA
;
907 for ( j
= maxunitused
; j
>= 0; j
-- ) {
908 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[j
];
910 rmesa
->state
.texture
.unit
[j
].outputreg
= -1;
912 if (stageref
[j
+ 1]) {
914 /* use the lowest available reg. That gets us automatically reg0 for the last stage.
915 need this even for disabled units, as it may get referenced due to the replace
917 for ( i
= 0 ; i
< R200_MAX_TEXTURE_UNITS
; i
++ ) {
919 rmesa
->state
.texture
.unit
[j
].outputreg
= i
;
923 if (rmesa
->state
.texture
.unit
[j
].outputreg
== -1) {
924 /* no more free regs we can use. Need a fallback :-( */
928 nextunit
[j
] = currentnext
;
930 if (!texUnit
->_ReallyEnabled
) {
931 /* the not enabled stages are referenced "indirectly",
932 must not cut off the lower stages */
933 stageref
[j
] = REF_COLOR
| REF_ALPHA
;
938 const GLuint numColorArgs
= texUnit
->_CurrentCombine
->_NumArgsRGB
;
939 const GLuint numAlphaArgs
= texUnit
->_CurrentCombine
->_NumArgsA
;
940 const GLboolean isdot3rgba
= (texUnit
->_CurrentCombine
->ModeRGB
== GL_DOT3_RGBA
) ||
941 (texUnit
->_CurrentCombine
->ModeRGB
== GL_DOT3_RGBA_EXT
);
944 /* check if we need the color part, special case for dot3_rgba
945 as if only the alpha part is referenced later on it still is using the color part */
946 if ((stageref
[j
+ 1] & REF_COLOR
) || isdot3rgba
) {
947 for ( i
= 0 ; i
< numColorArgs
; i
++ ) {
948 const GLuint srcRGBi
= texUnit
->_CurrentCombine
->SourceRGB
[i
];
949 const GLuint op
= texUnit
->_CurrentCombine
->OperandRGB
[i
];
952 /* op 0/1 are referencing color, op 2/3 alpha */
953 stageref
[j
] |= (op
>> 1) + 1;
956 texregfree
[j
] = GL_FALSE
;
964 texregfree
[srcRGBi
- GL_TEXTURE0
] = GL_FALSE
;
966 default: /* don't care about other sources here */
972 /* alpha args are ignored for dot3_rgba */
973 if ((stageref
[j
+ 1] & REF_ALPHA
) && !isdot3rgba
) {
975 for ( i
= 0 ; i
< numAlphaArgs
; i
++ ) {
976 const GLuint srcAi
= texUnit
->_CurrentCombine
->SourceA
[i
];
979 stageref
[j
] |= REF_ALPHA
;
982 texregfree
[j
] = GL_FALSE
;
990 texregfree
[srcAi
- GL_TEXTURE0
] = GL_FALSE
;
992 default: /* don't care about other sources here */
1000 /* don't enable texture sampling for units if the result is not used */
1001 for (i
= 0; i
< R200_MAX_TEXTURE_UNITS
; i
++) {
1002 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&& !texregfree
[i
])
1003 rmesa
->state
.texture
.unit
[i
].unitneeded
= ctx
->Texture
.Unit
[i
]._ReallyEnabled
;
1004 else rmesa
->state
.texture
.unit
[i
].unitneeded
= 0;
1009 rmesa
->state
.envneeded
= 1;
1012 while ((i
<= maxunitused
) && (i
>= 0)) {
1013 /* only output instruction if the results are referenced */
1014 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
&& stageref
[i
+1]) {
1015 GLuint replaceunit
= i
;
1016 /* try to optimize GL_REPLACE away (only one level deep though) */
1017 if ( (ctx
->Texture
.Unit
[i
]._CurrentCombine
->ModeRGB
== GL_REPLACE
) &&
1018 (ctx
->Texture
.Unit
[i
]._CurrentCombine
->ModeA
== GL_REPLACE
) &&
1019 (ctx
->Texture
.Unit
[i
]._CurrentCombine
->ScaleShiftRGB
== 0) &&
1020 (ctx
->Texture
.Unit
[i
]._CurrentCombine
->ScaleShiftA
== 0) &&
1021 (nextunit
[i
] > 0) ) {
1022 /* yippie! can optimize it away! */
1027 /* need env instruction slot */
1028 rmesa
->state
.envneeded
|= 1 << currslot
;
1029 ok
= r200UpdateTextureEnv( ctx
, i
, currslot
, replaceunit
);
1030 if (!ok
) return GL_FALSE
;
1036 if (currslot
== 0) {
1037 /* need one stage at least */
1038 rmesa
->state
.texture
.unit
[0].outputreg
= 0;
1039 ok
= r200UpdateTextureEnv( ctx
, 0, 0, 0 );
1042 R200_STATECHANGE( rmesa
, ctx
);
1043 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] &= ~(R200_TEX_BLEND_ENABLE_MASK
| R200_MULTI_PASS_ENABLE
);
1044 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= rmesa
->state
.envneeded
<< R200_TEX_BLEND_0_ENABLE_SHIFT
;
1053 #define TEXOBJ_TXFILTER_MASK (R200_MAX_MIP_LEVEL_MASK | \
1054 R200_MIN_FILTER_MASK | \
1055 R200_MAG_FILTER_MASK | \
1056 R200_MAX_ANISO_MASK | \
1058 R200_YUV_TEMPERATURE_MASK | \
1059 R200_CLAMP_S_MASK | \
1060 R200_CLAMP_T_MASK | \
1061 R200_BORDER_MODE_D3D )
1063 #define TEXOBJ_TXFORMAT_MASK (R200_TXFORMAT_WIDTH_MASK | \
1064 R200_TXFORMAT_HEIGHT_MASK | \
1065 R200_TXFORMAT_FORMAT_MASK | \
1066 R200_TXFORMAT_F5_WIDTH_MASK | \
1067 R200_TXFORMAT_F5_HEIGHT_MASK | \
1068 R200_TXFORMAT_ALPHA_IN_MAP | \
1069 R200_TXFORMAT_CUBIC_MAP_ENABLE | \
1070 R200_TXFORMAT_NON_POWER2)
1072 #define TEXOBJ_TXFORMAT_X_MASK (R200_DEPTH_LOG2_MASK | \
1073 R200_TEXCOORD_MASK | \
1074 R200_CLAMP_Q_MASK | \
1075 R200_VOLUME_FILTER_MASK)
1078 static void disable_tex_obj_state( r200ContextPtr rmesa
,
1082 R200_STATECHANGE( rmesa
, vtx
);
1083 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_1
] &= ~(7 << (unit
* 3));
1085 if (rmesa
->radeon
.TclFallback
& (R200_TCL_FALLBACK_TEXGEN_0
<<unit
)) {
1086 TCL_FALLBACK( rmesa
->radeon
.glCtx
, (R200_TCL_FALLBACK_TEXGEN_0
<<unit
), GL_FALSE
);
1089 /* Actually want to keep all units less than max active texture
1090 * enabled, right? Fix this for >2 texunits.
1094 GLuint tmp
= rmesa
->TexGenEnabled
;
1096 rmesa
->TexGenEnabled
&= ~(R200_TEXGEN_TEXMAT_0_ENABLE
<<unit
);
1097 rmesa
->TexGenEnabled
&= ~(R200_TEXMAT_0_ENABLE
<<unit
);
1098 rmesa
->TexGenNeedNormals
[unit
] = GL_FALSE
;
1099 rmesa
->TexGenCompSel
&= ~(R200_OUTPUT_TEX_0
<< unit
);
1101 if (tmp
!= rmesa
->TexGenEnabled
) {
1102 rmesa
->recheck_texgen
[unit
] = GL_TRUE
;
1103 rmesa
->radeon
.NewGLState
|= _NEW_TEXTURE_MATRIX
;
1107 static void import_tex_obj_state( r200ContextPtr rmesa
,
1109 radeonTexObjPtr texobj
)
1111 /* do not use RADEON_DB_STATE to avoid stale texture caches */
1112 GLuint
*cmd
= &rmesa
->hw
.tex
[unit
].cmd
[TEX_CMD_0
];
1114 R200_STATECHANGE( rmesa
, tex
[unit
] );
1116 cmd
[TEX_PP_TXFILTER
] &= ~TEXOBJ_TXFILTER_MASK
;
1117 cmd
[TEX_PP_TXFILTER
] |= texobj
->pp_txfilter
& TEXOBJ_TXFILTER_MASK
;
1118 cmd
[TEX_PP_TXFORMAT
] &= ~TEXOBJ_TXFORMAT_MASK
;
1119 cmd
[TEX_PP_TXFORMAT
] |= texobj
->pp_txformat
& TEXOBJ_TXFORMAT_MASK
;
1120 cmd
[TEX_PP_TXFORMAT_X
] &= ~TEXOBJ_TXFORMAT_X_MASK
;
1121 cmd
[TEX_PP_TXFORMAT_X
] |= texobj
->pp_txformat_x
& TEXOBJ_TXFORMAT_X_MASK
;
1122 cmd
[TEX_PP_TXSIZE
] = texobj
->pp_txsize
; /* NPOT only! */
1123 cmd
[TEX_PP_TXPITCH
] = texobj
->pp_txpitch
; /* NPOT only! */
1124 cmd
[TEX_PP_BORDER_COLOR
] = texobj
->pp_border_color
;
1126 if (texobj
->base
.Target
== GL_TEXTURE_CUBE_MAP
) {
1127 GLuint
*cube_cmd
= &rmesa
->hw
.cube
[unit
].cmd
[CUBE_CMD_0
];
1129 R200_STATECHANGE( rmesa
, cube
[unit
] );
1130 cube_cmd
[CUBE_PP_CUBIC_FACES
] = texobj
->pp_cubic_faces
;
1131 if (rmesa
->radeon
.radeonScreen
->drmSupportsFragShader
) {
1132 /* that value is submitted twice. could change cube atom
1133 to not include that command when new drm is used */
1134 cmd
[TEX_PP_CUBIC_FACES
] = texobj
->pp_cubic_faces
;
1140 static void set_texgen_matrix( r200ContextPtr rmesa
,
1142 const GLfloat
*s_plane
,
1143 const GLfloat
*t_plane
,
1144 const GLfloat
*r_plane
,
1145 const GLfloat
*q_plane
)
1169 _math_matrix_loadf( &(rmesa
->TexGenMatrix
[unit
]), m
);
1170 _math_matrix_analyse( &(rmesa
->TexGenMatrix
[unit
]) );
1171 rmesa
->TexGenEnabled
|= R200_TEXMAT_0_ENABLE
<<unit
;
1175 static GLuint
r200_need_dis_texgen(const GLbitfield texGenEnabled
,
1176 const GLfloat
*planeS
,
1177 const GLfloat
*planeT
,
1178 const GLfloat
*planeR
,
1179 const GLfloat
*planeQ
)
1181 GLuint needtgenable
= 0;
1183 if (!(texGenEnabled
& S_BIT
)) {
1184 if (((texGenEnabled
& T_BIT
) && planeT
[0] != 0.0) ||
1185 ((texGenEnabled
& R_BIT
) && planeR
[0] != 0.0) ||
1186 ((texGenEnabled
& Q_BIT
) && planeQ
[0] != 0.0)) {
1187 needtgenable
|= S_BIT
;
1190 if (!(texGenEnabled
& T_BIT
)) {
1191 if (((texGenEnabled
& S_BIT
) && planeS
[1] != 0.0) ||
1192 ((texGenEnabled
& R_BIT
) && planeR
[1] != 0.0) ||
1193 ((texGenEnabled
& Q_BIT
) && planeQ
[1] != 0.0)) {
1194 needtgenable
|= T_BIT
;
1197 if (!(texGenEnabled
& R_BIT
)) {
1198 if (((texGenEnabled
& S_BIT
) && planeS
[2] != 0.0) ||
1199 ((texGenEnabled
& T_BIT
) && planeT
[2] != 0.0) ||
1200 ((texGenEnabled
& Q_BIT
) && planeQ
[2] != 0.0)) {
1201 needtgenable
|= R_BIT
;
1204 if (!(texGenEnabled
& Q_BIT
)) {
1205 if (((texGenEnabled
& S_BIT
) && planeS
[3] != 0.0) ||
1206 ((texGenEnabled
& T_BIT
) && planeT
[3] != 0.0) ||
1207 ((texGenEnabled
& R_BIT
) && planeR
[3] != 0.0)) {
1208 needtgenable
|= Q_BIT
;
1212 return needtgenable
;
1217 * Returns GL_FALSE if fallback required.
1219 static GLboolean
r200_validate_texgen( GLcontext
*ctx
, GLuint unit
)
1221 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1222 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
1223 GLuint inputshift
= R200_TEXGEN_0_INPUT_SHIFT
+ unit
*4;
1226 GLboolean mixed_fallback
= GL_FALSE
;
1227 static const GLfloat I
[16] = {
1232 static const GLfloat reflect
[16] = {
1238 rmesa
->TexGenCompSel
&= ~(R200_OUTPUT_TEX_0
<< unit
);
1239 rmesa
->TexGenEnabled
&= ~(R200_TEXGEN_TEXMAT_0_ENABLE
<<unit
);
1240 rmesa
->TexGenEnabled
&= ~(R200_TEXMAT_0_ENABLE
<<unit
);
1241 rmesa
->TexGenNeedNormals
[unit
] = GL_FALSE
;
1242 tgi
= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_1
] & ~(R200_TEXGEN_INPUT_MASK
<<
1244 tgcm
= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_2
] & ~(R200_TEXGEN_COMP_MASK
<<
1248 fprintf(stderr
, "%s unit %d\n", __FUNCTION__
, unit
);
1250 if (texUnit
->TexGenEnabled
& S_BIT
) {
1251 mode
= texUnit
->GenS
.Mode
;
1253 tgcm
|= R200_TEXGEN_COMP_S
<< (unit
* 4);
1256 if (texUnit
->TexGenEnabled
& T_BIT
) {
1257 if (texUnit
->GenT
.Mode
!= mode
)
1258 mixed_fallback
= GL_TRUE
;
1260 tgcm
|= R200_TEXGEN_COMP_T
<< (unit
* 4);
1262 if (texUnit
->TexGenEnabled
& R_BIT
) {
1263 if (texUnit
->GenR
.Mode
!= mode
)
1264 mixed_fallback
= GL_TRUE
;
1266 tgcm
|= R200_TEXGEN_COMP_R
<< (unit
* 4);
1269 if (texUnit
->TexGenEnabled
& Q_BIT
) {
1270 if (texUnit
->GenQ
.Mode
!= mode
)
1271 mixed_fallback
= GL_TRUE
;
1273 tgcm
|= R200_TEXGEN_COMP_Q
<< (unit
* 4);
1276 if (mixed_fallback
) {
1277 if (R200_DEBUG
& DEBUG_FALLBACKS
)
1278 fprintf(stderr
, "fallback mixed texgen, 0x%x (0x%x 0x%x 0x%x 0x%x)\n",
1279 texUnit
->TexGenEnabled
, texUnit
->GenS
.Mode
, texUnit
->GenT
.Mode
,
1280 texUnit
->GenR
.Mode
, texUnit
->GenQ
.Mode
);
1284 /* we CANNOT do mixed mode if the texgen mode requires a plane where the input
1285 is not enabled for texgen, since the planes are concatenated into texmat,
1286 and thus the input will come from texcoord rather than tex gen equation!
1287 Either fallback or just hope that those texcoords aren't really needed...
1288 Assuming the former will cause lots of unnecessary fallbacks, the latter will
1289 generate bogus results sometimes - it's pretty much impossible to really know
1290 when a fallback is needed, depends on texmat and what sort of texture is bound
1291 etc, - for now fallback if we're missing either S or T bits, there's a high
1292 probability we need the texcoords in that case.
1293 That's a lot of work for some obscure texgen mixed mode fixup - why oh why
1294 doesn't the chip just directly accept the plane parameters :-(. */
1296 case GL_OBJECT_LINEAR
: {
1297 GLuint needtgenable
= r200_need_dis_texgen( texUnit
->TexGenEnabled
,
1298 texUnit
->GenS
.ObjectPlane
,
1299 texUnit
->GenT
.ObjectPlane
,
1300 texUnit
->GenR
.ObjectPlane
,
1301 texUnit
->GenQ
.ObjectPlane
);
1302 if (needtgenable
& (S_BIT
| T_BIT
)) {
1303 if (R200_DEBUG
& DEBUG_FALLBACKS
)
1304 fprintf(stderr
, "fallback mixed texgen / obj plane, 0x%x\n",
1305 texUnit
->TexGenEnabled
);
1308 if (needtgenable
& (R_BIT
)) {
1309 tgcm
&= ~(R200_TEXGEN_COMP_R
<< (unit
* 4));
1311 if (needtgenable
& (Q_BIT
)) {
1312 tgcm
&= ~(R200_TEXGEN_COMP_Q
<< (unit
* 4));
1315 tgi
|= R200_TEXGEN_INPUT_OBJ
<< inputshift
;
1316 set_texgen_matrix( rmesa
, unit
,
1317 (texUnit
->TexGenEnabled
& S_BIT
) ? texUnit
->GenS
.ObjectPlane
: I
,
1318 (texUnit
->TexGenEnabled
& T_BIT
) ? texUnit
->GenT
.ObjectPlane
: I
+ 4,
1319 (texUnit
->TexGenEnabled
& R_BIT
) ? texUnit
->GenR
.ObjectPlane
: I
+ 8,
1320 (texUnit
->TexGenEnabled
& Q_BIT
) ? texUnit
->GenQ
.ObjectPlane
: I
+ 12);
1324 case GL_EYE_LINEAR
: {
1325 GLuint needtgenable
= r200_need_dis_texgen( texUnit
->TexGenEnabled
,
1326 texUnit
->GenS
.EyePlane
,
1327 texUnit
->GenT
.EyePlane
,
1328 texUnit
->GenR
.EyePlane
,
1329 texUnit
->GenQ
.EyePlane
);
1330 if (needtgenable
& (S_BIT
| T_BIT
)) {
1331 if (R200_DEBUG
& DEBUG_FALLBACKS
)
1332 fprintf(stderr
, "fallback mixed texgen / eye plane, 0x%x\n",
1333 texUnit
->TexGenEnabled
);
1336 if (needtgenable
& (R_BIT
)) {
1337 tgcm
&= ~(R200_TEXGEN_COMP_R
<< (unit
* 4));
1339 if (needtgenable
& (Q_BIT
)) {
1340 tgcm
&= ~(R200_TEXGEN_COMP_Q
<< (unit
* 4));
1342 tgi
|= R200_TEXGEN_INPUT_EYE
<< inputshift
;
1343 set_texgen_matrix( rmesa
, unit
,
1344 (texUnit
->TexGenEnabled
& S_BIT
) ? texUnit
->GenS
.EyePlane
: I
,
1345 (texUnit
->TexGenEnabled
& T_BIT
) ? texUnit
->GenT
.EyePlane
: I
+ 4,
1346 (texUnit
->TexGenEnabled
& R_BIT
) ? texUnit
->GenR
.EyePlane
: I
+ 8,
1347 (texUnit
->TexGenEnabled
& Q_BIT
) ? texUnit
->GenQ
.EyePlane
: I
+ 12);
1351 case GL_REFLECTION_MAP_NV
:
1352 rmesa
->TexGenNeedNormals
[unit
] = GL_TRUE
;
1353 tgi
|= R200_TEXGEN_INPUT_EYE_REFLECT
<< inputshift
;
1354 /* pretty weird, must only negate when lighting is enabled? */
1355 if (ctx
->Light
.Enabled
)
1356 set_texgen_matrix( rmesa
, unit
,
1357 (texUnit
->TexGenEnabled
& S_BIT
) ? reflect
: I
,
1358 (texUnit
->TexGenEnabled
& T_BIT
) ? reflect
+ 4 : I
+ 4,
1359 (texUnit
->TexGenEnabled
& R_BIT
) ? reflect
+ 8 : I
+ 8,
1363 case GL_NORMAL_MAP_NV
:
1364 rmesa
->TexGenNeedNormals
[unit
] = GL_TRUE
;
1365 tgi
|= R200_TEXGEN_INPUT_EYE_NORMAL
<<inputshift
;
1369 rmesa
->TexGenNeedNormals
[unit
] = GL_TRUE
;
1370 tgi
|= R200_TEXGEN_INPUT_SPHERE
<<inputshift
;
1374 /* All texgen units were disabled, so just pass coords through. */
1375 tgi
|= unit
<< inputshift
;
1379 /* Unsupported mode, fallback:
1381 if (R200_DEBUG
& DEBUG_FALLBACKS
)
1382 fprintf(stderr
, "fallback unsupported texgen, %d\n",
1383 texUnit
->GenS
.Mode
);
1387 rmesa
->TexGenEnabled
|= R200_TEXGEN_TEXMAT_0_ENABLE
<< unit
;
1388 rmesa
->TexGenCompSel
|= R200_OUTPUT_TEX_0
<< unit
;
1390 if (tgi
!= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_1
] ||
1391 tgcm
!= rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_2
])
1393 R200_STATECHANGE(rmesa
, tcg
);
1394 rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_1
] = tgi
;
1395 rmesa
->hw
.tcg
.cmd
[TCG_TEX_PROC_CTL_2
] = tgcm
;
1401 void set_re_cntl_d3d( GLcontext
*ctx
, int unit
, GLboolean use_d3d
)
1403 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1407 re_cntl
= rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] & ~(R200_VTX_STQ0_D3D
<< (2 * unit
));
1409 re_cntl
|= R200_VTX_STQ0_D3D
<< (2 * unit
);
1411 if ( re_cntl
!= rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] ) {
1412 R200_STATECHANGE( rmesa
, set
);
1413 rmesa
->hw
.set
.cmd
[SET_RE_CNTL
] = re_cntl
;
1418 * Compute the cached hardware register values for the given texture object.
1420 * \param rmesa Context pointer
1421 * \param t the r300 texture object
1423 static void setup_hardware_state(r200ContextPtr rmesa
, radeonTexObj
*t
)
1425 const struct gl_texture_image
*firstImage
=
1426 t
->base
.Image
[0][t
->mt
->firstLevel
];
1427 GLint log2Width
, log2Height
, log2Depth
, texelBytes
;
1433 log2Width
= firstImage
->WidthLog2
;
1434 log2Height
= firstImage
->HeightLog2
;
1435 log2Depth
= firstImage
->DepthLog2
;
1436 texelBytes
= firstImage
->TexFormat
->TexelBytes
;
1439 if (!t
->image_override
) {
1440 if (VALID_FORMAT(firstImage
->TexFormat
->MesaFormat
)) {
1441 const struct tx_table
*table
= _mesa_little_endian() ? tx_table_le
:
1444 t
->pp_txformat
&= ~(R200_TXFORMAT_FORMAT_MASK
|
1445 R200_TXFORMAT_ALPHA_IN_MAP
);
1446 t
->pp_txfilter
&= ~R200_YUV_TO_RGB
;
1448 t
->pp_txformat
|= table
[ firstImage
->TexFormat
->MesaFormat
].format
;
1449 t
->pp_txfilter
|= table
[ firstImage
->TexFormat
->MesaFormat
].filter
;
1451 _mesa_problem(NULL
, "unexpected texture format in %s",
1457 t
->pp_txfilter
&= ~R200_MAX_MIP_LEVEL_MASK
;
1458 t
->pp_txfilter
|= (t
->mt
->lastLevel
- t
->mt
->firstLevel
) << R200_MAX_MIP_LEVEL_SHIFT
;
1460 t
->pp_txformat
&= ~(R200_TXFORMAT_WIDTH_MASK
|
1461 R200_TXFORMAT_HEIGHT_MASK
|
1462 R200_TXFORMAT_CUBIC_MAP_ENABLE
|
1463 R200_TXFORMAT_F5_WIDTH_MASK
|
1464 R200_TXFORMAT_F5_HEIGHT_MASK
);
1465 t
->pp_txformat
|= ((log2Width
<< R200_TXFORMAT_WIDTH_SHIFT
) |
1466 (log2Height
<< R200_TXFORMAT_HEIGHT_SHIFT
));
1470 t
->pp_txformat_x
&= ~(R200_DEPTH_LOG2_MASK
| R200_TEXCOORD_MASK
);
1471 if (t
->base
.Target
== GL_TEXTURE_3D
) {
1472 t
->pp_txformat_x
|= (log2Depth
<< R200_DEPTH_LOG2_SHIFT
);
1473 t
->pp_txformat_x
|= R200_TEXCOORD_VOLUME
;
1476 else if (t
->base
.Target
== GL_TEXTURE_CUBE_MAP
) {
1477 ASSERT(log2Width
== log2Height
);
1478 t
->pp_txformat
|= ((log2Width
<< R200_TXFORMAT_F5_WIDTH_SHIFT
) |
1479 (log2Height
<< R200_TXFORMAT_F5_HEIGHT_SHIFT
) |
1480 /* don't think we need this bit, if it exists at all - fglrx does not set it */
1481 (R200_TXFORMAT_CUBIC_MAP_ENABLE
));
1482 t
->pp_txformat_x
|= R200_TEXCOORD_CUBIC_ENV
;
1483 t
->pp_cubic_faces
= ((log2Width
<< R200_FACE_WIDTH_1_SHIFT
) |
1484 (log2Height
<< R200_FACE_HEIGHT_1_SHIFT
) |
1485 (log2Width
<< R200_FACE_WIDTH_2_SHIFT
) |
1486 (log2Height
<< R200_FACE_HEIGHT_2_SHIFT
) |
1487 (log2Width
<< R200_FACE_WIDTH_3_SHIFT
) |
1488 (log2Height
<< R200_FACE_HEIGHT_3_SHIFT
) |
1489 (log2Width
<< R200_FACE_WIDTH_4_SHIFT
) |
1490 (log2Height
<< R200_FACE_HEIGHT_4_SHIFT
));
1493 /* If we don't in fact send enough texture coordinates, q will be 1,
1494 * making TEXCOORD_PROJ act like TEXCOORD_NONPROJ (Right?)
1496 t
->pp_txformat_x
|= R200_TEXCOORD_PROJ
;
1499 t
->pp_txsize
= (((firstImage
->Width
- 1) << R200_PP_TX_WIDTHMASK_SHIFT
)
1500 | ((firstImage
->Height
- 1) << R200_PP_TX_HEIGHTMASK_SHIFT
));
1502 if ( !t
->image_override
) {
1503 if (firstImage
->IsCompressed
)
1504 t
->pp_txpitch
= (firstImage
->Width
+ 63) & ~(63);
1506 t
->pp_txpitch
= ((firstImage
->Width
* texelBytes
) + 63) & ~(63);
1507 t
->pp_txpitch
-= 32;
1510 if (t
->base
.Target
== GL_TEXTURE_RECTANGLE_NV
) {
1511 t
->pp_txformat
|= R200_TXFORMAT_NON_POWER2
;
1516 static GLboolean
r200_validate_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
, int unit
)
1518 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1519 radeonTexObj
*t
= radeon_tex_obj(texObj
);
1521 if (!radeon_validate_texture_miptree(ctx
, texObj
))
1524 r200_validate_texgen(ctx
, unit
);
1525 /* Configure the hardware registers (more precisely, the cached version
1526 * of the hardware registers). */
1527 setup_hardware_state(rmesa
, t
);
1529 if (texObj
->Target
== GL_TEXTURE_RECTANGLE_NV
||
1530 texObj
->Target
== GL_TEXTURE_2D
||
1531 texObj
->Target
== GL_TEXTURE_1D
)
1532 set_re_cntl_d3d( ctx
, unit
, GL_FALSE
);
1534 set_re_cntl_d3d( ctx
, unit
, GL_TRUE
);
1535 R200_STATECHANGE( rmesa
, ctx
);
1536 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_TEX_0_ENABLE
<< unit
;
1538 R200_STATECHANGE( rmesa
, vtx
);
1539 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_1
] &= ~(7 << (unit
* 3));
1540 rmesa
->hw
.vtx
.cmd
[VTX_TCL_OUTPUT_VTXFMT_1
] |= 4 << (unit
* 3);
1542 rmesa
->recheck_texgen
[unit
] = GL_TRUE
;
1543 import_tex_obj_state( rmesa
, unit
, t
);
1545 if (rmesa
->recheck_texgen
[unit
]) {
1546 GLboolean fallback
= !r200_validate_texgen( ctx
, unit
);
1547 TCL_FALLBACK( ctx
, (R200_TCL_FALLBACK_TEXGEN_0
<<unit
), fallback
);
1548 rmesa
->recheck_texgen
[unit
] = 0;
1549 rmesa
->radeon
.NewGLState
|= _NEW_TEXTURE_MATRIX
;
1552 t
->validated
= GL_TRUE
;
1554 FALLBACK( rmesa
, RADEON_FALLBACK_BORDER_MODE
, t
->border_fallback
);
1556 return !t
->border_fallback
;
1559 static GLboolean
r200UpdateTextureUnit(GLcontext
*ctx
, int unit
)
1561 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1562 GLuint unitneeded
= rmesa
->state
.texture
.unit
[unit
].unitneeded
;
1565 /* disable the unit */
1566 disable_tex_obj_state(rmesa
, unit
);
1570 if (!r200_validate_texture(ctx
, ctx
->Texture
.Unit
[unit
]._Current
, unit
)) {
1572 "failed to validate texture for unit %d.\n",
1574 rmesa
->state
.texture
.unit
[unit
].texobj
= NULL
;
1578 rmesa
->state
.texture
.unit
[unit
].texobj
= radeon_tex_obj(ctx
->Texture
.Unit
[unit
]._Current
);
1583 void r200UpdateTextureState( GLcontext
*ctx
)
1585 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
1589 /* NOTE: must not manipulate rmesa->state.texture.unit[].unitneeded or
1590 rmesa->state.envneeded before a R200_STATECHANGE (or R200_NEWPRIM) since
1591 we use these to determine if we want to emit the corresponding state
1593 R200_NEWPRIM( rmesa
);
1595 if (ctx
->ATIFragmentShader
._Enabled
) {
1597 for (i
= 0; i
< R200_MAX_TEXTURE_UNITS
; i
++) {
1598 rmesa
->state
.texture
.unit
[i
].unitneeded
= ctx
->Texture
.Unit
[i
]._ReallyEnabled
;
1603 ok
= r200UpdateAllTexEnv( ctx
);
1606 ok
= (r200UpdateTextureUnit( ctx
, 0 ) &&
1607 r200UpdateTextureUnit( ctx
, 1 ) &&
1608 r200UpdateTextureUnit( ctx
, 2 ) &&
1609 r200UpdateTextureUnit( ctx
, 3 ) &&
1610 r200UpdateTextureUnit( ctx
, 4 ) &&
1611 r200UpdateTextureUnit( ctx
, 5 ));
1614 if (ok
&& ctx
->ATIFragmentShader
._Enabled
) {
1615 r200UpdateFragmentShader(ctx
);
1618 FALLBACK( rmesa
, R200_FALLBACK_TEXTURE
, !ok
);
1620 if (rmesa
->radeon
.TclFallback
)
1621 r200ChooseVertexState( ctx
);
1624 if (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R200
) {
1627 * T0 hang workaround -------------
1628 * not needed for r200 derivatives
1630 if ((rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] & R200_TEX_ENABLE_MASK
) == R200_TEX_0_ENABLE
&&
1631 (rmesa
->hw
.tex
[0].cmd
[TEX_PP_TXFILTER
] & R200_MIN_FILTER_MASK
) > R200_MIN_FILTER_LINEAR
) {
1633 R200_STATECHANGE(rmesa
, ctx
);
1634 R200_STATECHANGE(rmesa
, tex
[1]);
1635 rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] |= R200_TEX_1_ENABLE
;
1636 if (!(rmesa
->hw
.cst
.cmd
[CST_PP_CNTL_X
] & R200_PPX_TEX_1_ENABLE
))
1637 rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXFORMAT
] &= ~TEXOBJ_TXFORMAT_MASK
;
1638 rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXFORMAT
] |= R200_TXFORMAT_LOOKUP_DISABLE
;
1640 else if (!ctx
->ATIFragmentShader
._Enabled
) {
1641 if ((rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] & R200_TEX_1_ENABLE
) &&
1642 (rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXFORMAT
] & R200_TXFORMAT_LOOKUP_DISABLE
)) {
1643 R200_STATECHANGE(rmesa
, tex
[1]);
1644 rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXFORMAT
] &= ~R200_TXFORMAT_LOOKUP_DISABLE
;
1647 /* do the same workaround for the first pass of a fragment shader.
1648 * completely unknown if necessary / sufficient.
1650 if ((rmesa
->hw
.cst
.cmd
[CST_PP_CNTL_X
] & R200_PPX_TEX_ENABLE_MASK
) == R200_PPX_TEX_0_ENABLE
&&
1651 (rmesa
->hw
.tex
[0].cmd
[TEX_PP_TXFILTER
] & R200_MIN_FILTER_MASK
) > R200_MIN_FILTER_LINEAR
) {
1653 R200_STATECHANGE(rmesa
, cst
);
1654 R200_STATECHANGE(rmesa
, tex
[1]);
1655 rmesa
->hw
.cst
.cmd
[CST_PP_CNTL_X
] |= R200_PPX_TEX_1_ENABLE
;
1656 if (!(rmesa
->hw
.ctx
.cmd
[CTX_PP_CNTL
] & R200_TEX_1_ENABLE
))
1657 rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXFORMAT
] &= ~TEXOBJ_TXFORMAT_MASK
;
1658 rmesa
->hw
.tex
[1].cmd
[TEX_PP_TXMULTI_CTL
] |= R200_PASS1_TXFORMAT_LOOKUP_DISABLE
;
1661 /* maybe needs to be done pairwise due to 2 parallel (physical) tex units ?
1662 looks like that's not the case, if 8500/9100 owners don't complain remove this...
1663 for ( i = 0; i < ctx->Const.MaxTextureUnits; i += 2) {
1664 if (((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & ((R200_TEX_0_ENABLE |
1665 R200_TEX_1_ENABLE ) << i)) == (R200_TEX_0_ENABLE << i)) &&
1666 ((rmesa->hw.tex[i].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK) >
1667 R200_MIN_FILTER_LINEAR)) {
1668 R200_STATECHANGE(rmesa, ctx);
1669 R200_STATECHANGE(rmesa, tex[i+1]);
1670 rmesa->hw.ctx.cmd[CTX_PP_CNTL] |= (R200_TEX_1_ENABLE << i);
1671 rmesa->hw.tex[i+1].cmd[TEX_PP_TXFORMAT] &= ~TEXOBJ_TXFORMAT_MASK;
1672 rmesa->hw.tex[i+1].cmd[TEX_PP_TXFORMAT] |= 0x08000000;
1675 if ((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & (R200_TEX_1_ENABLE << i)) &&
1676 (rmesa->hw.tex[i+1].cmd[TEX_PP_TXFORMAT] & 0x08000000)) {
1677 R200_STATECHANGE(rmesa, tex[i+1]);
1678 rmesa->hw.tex[i+1].cmd[TEX_PP_TXFORMAT] &= ~0x08000000;
1684 * Texture cache LRU hang workaround -------------
1685 * not needed for r200 derivatives
1686 * hopefully this covers first pass of a shader as well
1689 /* While the cases below attempt to only enable the workaround in the
1690 * specific cases necessary, they were insufficient. See bugzilla #1519,
1691 * #729, #814. Tests with quake3 showed no impact on performance.
1696 if (((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & (R200_TEX_0_ENABLE )) &&
1697 ((((rmesa->hw.tex[0].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1699 ((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & R200_TEX_2_ENABLE) &&
1700 ((((rmesa->hw.tex[2].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1702 ((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & R200_TEX_4_ENABLE) &&
1703 ((((rmesa->hw.tex[4].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1709 if (((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & (R200_TEX_1_ENABLE )) &&
1710 ((((rmesa->hw.tex[1].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1712 ((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & R200_TEX_3_ENABLE) &&
1713 ((((rmesa->hw.tex[3].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1715 ((rmesa->hw.ctx.cmd[CTX_PP_CNTL] & R200_TEX_5_ENABLE) &&
1716 ((((rmesa->hw.tex[5].cmd[TEX_PP_TXFILTER] & R200_MIN_FILTER_MASK)) &
1722 if (dbg
!= rmesa
->hw
.tam
.cmd
[TAM_DEBUG3
]) {
1723 R200_STATECHANGE( rmesa
, tam
);
1724 rmesa
->hw
.tam
.cmd
[TAM_DEBUG3
] = dbg
;
1725 if (0) printf("TEXCACHE LRU HANG WORKAROUND %x\n", dbg
);