2 Copyright (C) The Weather Channel, Inc. 2002.
3 Copyright (C) 2004 Nicolai Haehnle.
6 The Weather Channel (TM) funded Tungsten Graphics to develop the
7 initial release of the Radeon 8500 driver under the XFree86 license.
8 This notice must be preserved.
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial
20 portions of the Software.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
35 * \author Nicolai Haehnle <prefect_@gmx.net>
45 #include "simple_list.h"
47 #include "api_arrayelt.h"
48 #include "swrast/swrast.h"
49 #include "swrast_setup/swrast_setup.h"
50 #include "shader/prog_parameter.h"
51 #include "shader/prog_statevars.h"
54 #include "texformat.h"
56 #include "radeon_ioctl.h"
57 #include "radeon_state.h"
58 #include "r300_context.h"
59 #include "r300_ioctl.h"
60 #include "r300_state.h"
62 #include "r300_emit.h"
63 #include "r300_fragprog.h"
66 #include "drirenderbuffer.h"
68 extern int future_hw_tcl_on
;
69 extern void _tnl_UpdateFixedFunctionProgram(GLcontext
* ctx
);
71 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
74 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
76 R300_STATECHANGE(rmesa
, blend_color
);
78 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
79 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
80 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
81 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
83 rmesa
->hw
.blend_color
.cmd
[1] = PACK_COLOR_8888(color
[3], color
[0],
85 rmesa
->hw
.blend_color
.cmd
[2] = 0;
86 rmesa
->hw
.blend_color
.cmd
[3] = 0;
90 * Calculate the hardware blend factor setting. This same function is used
91 * for source and destination of both alpha and RGB.
94 * The hardware register value for the specified blend factor. This value
95 * will need to be shifted into the correct position for either source or
99 * Since the two cases where source and destination are handled differently
100 * are essentially error cases, they should never happen. Determine if these
101 * cases can be removed.
103 static int blend_factor(GLenum factor
, GLboolean is_src
)
107 return R300_BLEND_GL_ZERO
;
110 return R300_BLEND_GL_ONE
;
113 return R300_BLEND_GL_DST_COLOR
;
115 case GL_ONE_MINUS_DST_COLOR
:
116 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
119 return R300_BLEND_GL_SRC_COLOR
;
121 case GL_ONE_MINUS_SRC_COLOR
:
122 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
125 return R300_BLEND_GL_SRC_ALPHA
;
127 case GL_ONE_MINUS_SRC_ALPHA
:
128 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
131 return R300_BLEND_GL_DST_ALPHA
;
133 case GL_ONE_MINUS_DST_ALPHA
:
134 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
136 case GL_SRC_ALPHA_SATURATE
:
137 return (is_src
) ? R300_BLEND_GL_SRC_ALPHA_SATURATE
:
140 case GL_CONSTANT_COLOR
:
141 return R300_BLEND_GL_CONST_COLOR
;
143 case GL_ONE_MINUS_CONSTANT_COLOR
:
144 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
146 case GL_CONSTANT_ALPHA
:
147 return R300_BLEND_GL_CONST_ALPHA
;
149 case GL_ONE_MINUS_CONSTANT_ALPHA
:
150 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
153 fprintf(stderr
, "unknown blend factor %x\n", factor
);
154 return (is_src
) ? R300_BLEND_GL_ONE
: R300_BLEND_GL_ZERO
;
160 * Sets both the blend equation and the blend function.
161 * This is done in a single
162 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
163 * change the interpretation of the blend function.
164 * Also, make sure that blend function and blend equation are set to their
165 * default value if color blending is not enabled, since at least blend
166 * equations GL_MIN and GL_FUNC_REVERSE_SUBTRACT will cause wrong results
167 * otherwise for unknown reasons.
170 /* helper function */
171 static void r300SetBlendCntl(r300ContextPtr r300
, int func
, int eqn
,
172 int cbits
, int funcA
, int eqnA
)
174 GLuint new_ablend
, new_cblend
;
178 "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n",
179 eqnA
, funcA
, eqn
, func
, cbits
);
181 new_ablend
= eqnA
| funcA
;
182 new_cblend
= eqn
| func
;
184 /* Some blend factor combinations don't seem to work when the
185 * BLEND_NO_SEPARATE bit is set.
187 * Especially problematic candidates are the ONE_MINUS_* flags,
188 * but I can't see a real pattern.
191 if (new_ablend
== new_cblend
) {
192 new_cblend
|= R300_BLEND_NO_SEPARATE
;
197 if ((new_ablend
!= r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]) ||
198 (new_cblend
!= r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
])) {
199 R300_STATECHANGE(r300
, bld
);
200 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = new_ablend
;
201 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = new_cblend
;
205 static void r300SetBlendState(GLcontext
* ctx
)
207 r300ContextPtr r300
= R300_CONTEXT(ctx
);
208 int func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
209 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
210 int eqn
= R300_COMB_FCN_ADD_CLAMP
;
211 int funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
212 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
213 int eqnA
= R300_COMB_FCN_ADD_CLAMP
;
215 if (RGBA_LOGICOP_ENABLED(ctx
) || !ctx
->Color
.BlendEnabled
) {
216 r300SetBlendCntl(r300
, func
, eqn
, 0, func
, eqn
);
221 (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) <<
222 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstRGB
,
224 R300_DST_BLEND_SHIFT
);
226 switch (ctx
->Color
.BlendEquationRGB
) {
228 eqn
= R300_COMB_FCN_ADD_CLAMP
;
231 case GL_FUNC_SUBTRACT
:
232 eqn
= R300_COMB_FCN_SUB_CLAMP
;
235 case GL_FUNC_REVERSE_SUBTRACT
:
236 eqn
= R300_COMB_FCN_RSUB_CLAMP
;
240 eqn
= R300_COMB_FCN_MIN
;
241 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
242 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
246 eqn
= R300_COMB_FCN_MAX
;
247 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
248 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
253 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
254 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
259 (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) <<
260 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstA
,
262 R300_DST_BLEND_SHIFT
);
264 switch (ctx
->Color
.BlendEquationA
) {
266 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
269 case GL_FUNC_SUBTRACT
:
270 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
273 case GL_FUNC_REVERSE_SUBTRACT
:
274 eqnA
= R300_COMB_FCN_RSUB_CLAMP
;
278 eqnA
= R300_COMB_FCN_MIN
;
279 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
280 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
284 eqnA
= R300_COMB_FCN_MAX
;
285 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
286 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
291 "[%s:%u] Invalid A blend equation (0x%04x).\n",
292 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
296 r300SetBlendCntl(r300
,
298 R300_BLEND_UNKNOWN
| R300_BLEND_ENABLE
, funcA
, eqnA
);
301 static void r300BlendEquationSeparate(GLcontext
* ctx
,
302 GLenum modeRGB
, GLenum modeA
)
304 r300SetBlendState(ctx
);
307 static void r300BlendFuncSeparate(GLcontext
* ctx
,
308 GLenum sfactorRGB
, GLenum dfactorRGB
,
309 GLenum sfactorA
, GLenum dfactorA
)
311 r300SetBlendState(ctx
);
314 static void r300ClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
316 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
320 /* no VAP UCP on non-TCL chipsets */
321 if (!(rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
324 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
325 ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
327 R300_STATECHANGE( rmesa
, vpucp
[p
] );
328 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
329 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
330 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
331 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
334 static void r300SetClipPlaneState(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
336 r300ContextPtr r300
= R300_CONTEXT(ctx
);
339 /* no VAP UCP on non-TCL chipsets */
340 if (!(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
343 p
= cap
- GL_CLIP_PLANE0
;
344 R300_STATECHANGE(r300
, vap_clip_cntl
);
346 r300
->hw
.vap_clip_cntl
.cmd
[1] |= (R300_VAP_UCP_ENABLE_0
<< p
);
347 r300ClipPlane(ctx
, cap
, NULL
);
349 r300
->hw
.vap_clip_cntl
.cmd
[1] &= ~(R300_VAP_UCP_ENABLE_0
<< p
);
354 * Update our tracked culling state based on Mesa's state.
356 static void r300UpdateCulling(GLcontext
* ctx
)
358 r300ContextPtr r300
= R300_CONTEXT(ctx
);
361 if (ctx
->Polygon
.CullFlag
) {
362 switch (ctx
->Polygon
.CullFaceMode
) {
364 val
= R300_CULL_FRONT
;
367 val
= R300_CULL_BACK
;
369 case GL_FRONT_AND_BACK
:
370 val
= R300_CULL_FRONT
| R300_CULL_BACK
;
377 switch (ctx
->Polygon
.FrontFace
) {
379 val
|= R300_FRONT_FACE_CW
;
382 val
|= R300_FRONT_FACE_CCW
;
388 R300_STATECHANGE(r300
, cul
);
389 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
392 static void r300SetPolygonOffsetState(GLcontext
* ctx
, GLboolean state
)
394 r300ContextPtr r300
= R300_CONTEXT(ctx
);
396 R300_STATECHANGE(r300
, occlusion_cntl
);
398 r300
->hw
.occlusion_cntl
.cmd
[1] |= (3 << 0);
400 r300
->hw
.occlusion_cntl
.cmd
[1] &= ~(3 << 0);
404 static void r300SetEarlyZState(GLcontext
* ctx
)
406 /* updates register R300_RB3D_EARLY_Z (0x4F14)
407 if depth test is not enabled it should be R300_EARLY_Z_DISABLE
408 if depth is enabled and alpha not it should be R300_EARLY_Z_ENABLE
409 if depth and alpha is enabled it should be R300_EARLY_Z_DISABLE
411 r300ContextPtr r300
= R300_CONTEXT(ctx
);
413 R300_STATECHANGE(r300
, zstencil_format
);
414 switch (ctx
->Visual
.depthBits
) {
416 r300
->hw
.zstencil_format
.cmd
[1] = ZB_FORMAR_DEPTHFORMAT_16BIT_INT_Z
;
419 r300
->hw
.zstencil_format
.cmd
[1] = ZB_FORMAR_DEPTHFORMAT_24BIT_INT_Z
;
422 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n", ctx
->Visual
.depthBits
);
426 if (ctx
->Color
.AlphaEnabled
&& ctx
->Color
.AlphaFunc
!= GL_ALWAYS
)
427 /* disable early Z */
428 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_DISABLE
;
430 if (ctx
->Depth
.Test
&& ctx
->Depth
.Func
!= GL_NEVER
)
432 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_ENABLE
;
434 /* disable early Z */
435 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_DISABLE
;
438 r300
->hw
.zstencil_format
.cmd
[3] = 0x00000003;
439 r300
->hw
.zstencil_format
.cmd
[4] = 0x00000000;
442 static void r300SetAlphaState(GLcontext
* ctx
)
444 r300ContextPtr r300
= R300_CONTEXT(ctx
);
446 uint32_t pp_misc
= 0x0;
447 GLboolean really_enabled
= ctx
->Color
.AlphaEnabled
;
449 CLAMPED_FLOAT_TO_UBYTE(refByte
, ctx
->Color
.AlphaRef
);
451 switch (ctx
->Color
.AlphaFunc
) {
453 pp_misc
|= FG_ALPHA_FUNC_NEVER
;
456 pp_misc
|= FG_ALPHA_FUNC_LESS
;
459 pp_misc
|= FG_ALPHA_FUNC_EQUAL
;
462 pp_misc
|= FG_ALPHA_FUNC_LE
;
465 pp_misc
|= FG_ALPHA_FUNC_GREATER
;
468 pp_misc
|= FG_ALPHA_FUNC_NOTEQUAL
;
471 pp_misc
|= FG_ALPHA_FUNC_GE
;
474 /*pp_misc |= FG_ALPHA_FUNC_ALWAYS; */
475 really_enabled
= GL_FALSE
;
479 if (really_enabled
) {
480 pp_misc
|= FG_ALPHA_FUNC_ENABLE
;
481 pp_misc
|= (refByte
& R300_REF_ALPHA_MASK
);
486 R300_STATECHANGE(r300
, at
);
487 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
488 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
490 r300SetEarlyZState(ctx
);
493 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
497 r300SetAlphaState(ctx
);
500 static int translate_func(int func
)
504 return R300_ZS_NEVER
;
508 return R300_ZS_EQUAL
;
510 return R300_ZS_LEQUAL
;
512 return R300_ZS_GREATER
;
514 return R300_ZS_NOTEQUAL
;
516 return R300_ZS_GEQUAL
;
518 return R300_ZS_ALWAYS
;
523 static void r300SetDepthState(GLcontext
* ctx
)
525 r300ContextPtr r300
= R300_CONTEXT(ctx
);
527 R300_STATECHANGE(r300
, zs
);
528 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &= R300_RB3D_STENCIL_ENABLE
;
529 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
530 ~(R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
);
532 if (ctx
->Depth
.Test
&& ctx
->Depth
.Func
!= GL_NEVER
) {
534 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
535 R300_RB3D_Z_TEST_AND_WRITE
;
537 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_RB3D_Z_TEST
;
539 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
540 translate_func(ctx
->Depth
.
541 Func
) << R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
543 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_RB3D_Z_DISABLED_1
;
544 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
545 translate_func(GL_NEVER
) << R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
548 r300SetEarlyZState(ctx
);
551 static void r300SetStencilState(GLcontext
* ctx
, GLboolean state
)
553 r300ContextPtr r300
= R300_CONTEXT(ctx
);
555 if (r300
->state
.stencil
.hw_stencil
) {
556 R300_STATECHANGE(r300
, zs
);
558 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
559 R300_RB3D_STENCIL_ENABLE
;
561 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
562 ~R300_RB3D_STENCIL_ENABLE
;
566 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_STENCIL
, state
);
571 static void r300UpdatePolygonMode(GLcontext
* ctx
)
573 r300ContextPtr r300
= R300_CONTEXT(ctx
);
574 uint32_t hw_mode
= GA_POLY_MODE_DISABLE
;
576 /* Only do something if a polygon mode is wanted, default is GL_FILL */
577 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
578 ctx
->Polygon
.BackMode
!= GL_FILL
) {
581 /* Handle GL_CW (clock wise and GL_CCW (counter clock wise)
582 * correctly by selecting the correct front and back face
584 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
585 f
= ctx
->Polygon
.FrontMode
;
586 b
= ctx
->Polygon
.BackMode
;
588 f
= ctx
->Polygon
.BackMode
;
589 b
= ctx
->Polygon
.FrontMode
;
592 /* Enable polygon mode */
593 hw_mode
|= GA_POLY_MODE_DUAL
;
597 hw_mode
|= GA_POLY_MODE_FRONT_PTYPE_LINE
;
600 hw_mode
|= GA_POLY_MODE_FRONT_PTYPE_POINT
;
603 hw_mode
|= GA_POLY_MODE_FRONT_PTYPE_TRI
;
609 hw_mode
|= GA_POLY_MODE_BACK_PTYPE_LINE
;
612 hw_mode
|= GA_POLY_MODE_BACK_PTYPE_POINT
;
615 hw_mode
|= GA_POLY_MODE_BACK_PTYPE_TRI
;
620 if (r300
->hw
.polygon_mode
.cmd
[1] != hw_mode
) {
621 R300_STATECHANGE(r300
, polygon_mode
);
622 r300
->hw
.polygon_mode
.cmd
[1] = hw_mode
;
625 r300
->hw
.polygon_mode
.cmd
[2] = 0x00000001;
626 r300
->hw
.polygon_mode
.cmd
[3] = 0x00000000;
630 * Change the culling mode.
632 * \note Mesa already filters redundant calls to this function.
634 static void r300CullFace(GLcontext
* ctx
, GLenum mode
)
638 r300UpdateCulling(ctx
);
642 * Change the polygon orientation.
644 * \note Mesa already filters redundant calls to this function.
646 static void r300FrontFace(GLcontext
* ctx
, GLenum mode
)
650 r300UpdateCulling(ctx
);
651 r300UpdatePolygonMode(ctx
);
655 * Change the depth testing function.
657 * \note Mesa already filters redundant calls to this function.
659 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
662 r300SetDepthState(ctx
);
666 * Enable/Disable depth writing.
668 * \note Mesa already filters redundant calls to this function.
670 static void r300DepthMask(GLcontext
* ctx
, GLboolean mask
)
673 r300SetDepthState(ctx
);
677 * Handle glColorMask()
679 static void r300ColorMask(GLcontext
* ctx
,
680 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
682 r300ContextPtr r300
= R300_CONTEXT(ctx
);
683 int mask
= (r
? RB3D_COLOR_CHANNEL_MASK_RED_MASK0
: 0) |
684 (g
? RB3D_COLOR_CHANNEL_MASK_GREEN_MASK0
: 0) |
685 (b
? RB3D_COLOR_CHANNEL_MASK_BLUE_MASK0
: 0) |
686 (a
? RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK0
: 0);
688 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
689 R300_STATECHANGE(r300
, cmk
);
690 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
694 /* =============================================================
697 static void r300Fogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
)
699 r300ContextPtr r300
= R300_CONTEXT(ctx
);
703 } fogScale
, fogStart
;
707 fogScale
.i
= r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
];
708 fogStart
.i
= r300
->hw
.fogp
.cmd
[R300_FOGP_START
];
712 if (!ctx
->Fog
.Enabled
)
714 switch (ctx
->Fog
.Mode
) {
716 R300_STATECHANGE(r300
, fogs
);
717 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
719 cmd
[R300_FOGS_STATE
] & ~FG_FOG_BLEND_FN_MASK
) |
720 FG_FOG_BLEND_FN_LINEAR
;
722 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
727 1.0 / (ctx
->Fog
.End
- ctx
->Fog
.Start
);
729 -ctx
->Fog
.Start
/ (ctx
->Fog
.End
-
734 R300_STATECHANGE(r300
, fogs
);
735 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
737 cmd
[R300_FOGS_STATE
] & ~FG_FOG_BLEND_FN_MASK
) |
739 fogScale
.f
= 0.0933 * ctx
->Fog
.Density
;
743 R300_STATECHANGE(r300
, fogs
);
744 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
746 cmd
[R300_FOGS_STATE
] & ~FG_FOG_BLEND_FN_MASK
) |
747 FG_FOG_BLEND_FN_EXP2
;
748 fogScale
.f
= 0.3 * ctx
->Fog
.Density
;
755 switch (ctx
->Fog
.Mode
) {
757 fogScale
.f
= 0.0933 * ctx
->Fog
.Density
;
761 fogScale
.f
= 0.3 * ctx
->Fog
.Density
;
769 if (ctx
->Fog
.Mode
== GL_LINEAR
) {
770 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
775 1.0 / (ctx
->Fog
.End
- ctx
->Fog
.Start
);
777 -ctx
->Fog
.Start
/ (ctx
->Fog
.End
-
783 R300_STATECHANGE(r300
, fogc
);
784 r300
->hw
.fogc
.cmd
[R300_FOGC_R
] =
785 (GLuint
) (ctx
->Fog
.Color
[0] * 1023.0F
) & 0x3FF;
786 r300
->hw
.fogc
.cmd
[R300_FOGC_G
] =
787 (GLuint
) (ctx
->Fog
.Color
[1] * 1023.0F
) & 0x3FF;
788 r300
->hw
.fogc
.cmd
[R300_FOGC_B
] =
789 (GLuint
) (ctx
->Fog
.Color
[2] * 1023.0F
) & 0x3FF;
791 case GL_FOG_COORD_SRC
:
797 if (fogScale
.i
!= r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
] ||
798 fogStart
.i
!= r300
->hw
.fogp
.cmd
[R300_FOGP_START
]) {
799 R300_STATECHANGE(r300
, fogp
);
800 r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
] = fogScale
.i
;
801 r300
->hw
.fogp
.cmd
[R300_FOGP_START
] = fogStart
.i
;
805 static void r300SetFogState(GLcontext
* ctx
, GLboolean state
)
807 r300ContextPtr r300
= R300_CONTEXT(ctx
);
809 R300_STATECHANGE(r300
, fogs
);
811 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] |= FG_FOG_BLEND_ENABLE
;
813 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
814 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
815 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
816 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
817 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
819 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] &= ~FG_FOG_BLEND_ENABLE
;
823 /* =============================================================
826 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
828 r300ContextPtr r300
= R300_CONTEXT(ctx
);
829 /* same size limits for AA, non-AA points */
830 size
= CLAMP(size
, ctx
->Const
.MinPointSize
, ctx
->Const
.MaxPointSize
);
832 R300_STATECHANGE(r300
, ps
);
833 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
834 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
835 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
838 /* =============================================================
841 static void r300LineWidth(GLcontext
* ctx
, GLfloat widthf
)
843 r300ContextPtr r300
= R300_CONTEXT(ctx
);
845 widthf
= CLAMP(widthf
,
846 ctx
->Const
.MinPointSize
,
847 ctx
->Const
.MaxPointSize
);
848 R300_STATECHANGE(r300
, lcntl
);
849 r300
->hw
.lcntl
.cmd
[1] =
850 R300_LINE_CNT_HO
| R300_LINE_CNT_VE
| (int)(widthf
* 6.0);
853 static void r300PolygonMode(GLcontext
* ctx
, GLenum face
, GLenum mode
)
858 r300UpdatePolygonMode(ctx
);
861 /* =============================================================
865 static int translate_stencil_op(int op
)
873 return R300_ZS_REPLACE
;
878 case GL_INCR_WRAP_EXT
:
879 return R300_ZS_INCR_WRAP
;
880 case GL_DECR_WRAP_EXT
:
881 return R300_ZS_DECR_WRAP
;
883 return R300_ZS_INVERT
;
885 WARN_ONCE("Do not know how to translate stencil op");
891 static void r300ShadeModel(GLcontext
* ctx
, GLenum mode
)
893 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
895 R300_STATECHANGE(rmesa
, shade
);
896 rmesa
->hw
.shade
.cmd
[1] = 0x00000002;
899 rmesa
->hw
.shade
.cmd
[2] = R300_RE_SHADE_MODEL_FLAT
;
902 rmesa
->hw
.shade
.cmd
[2] = R300_RE_SHADE_MODEL_SMOOTH
;
907 rmesa
->hw
.shade
.cmd
[3] = 0x00000000;
908 rmesa
->hw
.shade
.cmd
[4] = 0x00000000;
911 static void r300StencilFuncSeparate(GLcontext
* ctx
, GLenum face
,
912 GLenum func
, GLint ref
, GLuint mask
)
914 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
917 Ref
[0] & 0xff) << ZB_STENCILREFMASK_STENCILREF_SHIFT
) | ((ctx
->
923 ZB_STENCILREFMASK_STENCILMASK_SHIFT
));
927 R300_STATECHANGE(rmesa
, zs
);
929 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~((R300_ZS_MASK
<<
930 R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
932 R300_RB3D_ZS1_BACK_FUNC_SHIFT
));
934 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
935 ~((ZB_STENCILREFMASK_STENCIL_MASK
<< ZB_STENCILREFMASK_STENCILREF_SHIFT
) |
936 (ZB_STENCILREFMASK_STENCIL_MASK
<< ZB_STENCILREFMASK_STENCILMASK_SHIFT
));
938 flag
= translate_func(ctx
->Stencil
.Function
[0]);
939 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
940 (flag
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
);
942 if (ctx
->Stencil
._TestTwoSide
)
943 flag
= translate_func(ctx
->Stencil
.Function
[1]);
945 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
946 (flag
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
947 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
950 static void r300StencilMaskSeparate(GLcontext
* ctx
, GLenum face
, GLuint mask
)
952 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
954 R300_STATECHANGE(rmesa
, zs
);
955 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
956 ~(ZB_STENCILREFMASK_STENCIL_MASK
<<
957 ZB_STENCILREFMASK_STENCILWRITEMASK_SHIFT
);
958 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |=
960 WriteMask
[0] & ZB_STENCILREFMASK_STENCIL_MASK
) <<
961 ZB_STENCILREFMASK_STENCILWRITEMASK_SHIFT
;
964 static void r300StencilOpSeparate(GLcontext
* ctx
, GLenum face
,
965 GLenum fail
, GLenum zfail
, GLenum zpass
)
967 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
969 R300_STATECHANGE(rmesa
, zs
);
970 /* It is easier to mask what's left.. */
971 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
972 (R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
) |
973 (R300_ZS_MASK
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
) |
974 (R300_ZS_MASK
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
976 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
977 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
978 R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT
)
979 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
980 R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT
)
981 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
982 R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT
);
984 if (ctx
->Stencil
._TestTwoSide
) {
985 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
986 (translate_stencil_op(ctx
->Stencil
.FailFunc
[1]) <<
987 R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
988 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[1]) <<
989 R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
990 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[1]) <<
991 R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
993 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
994 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
995 R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
996 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
997 R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
998 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
999 R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
1003 static void r300ClearStencil(GLcontext
* ctx
, GLint s
)
1005 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1007 rmesa
->state
.stencil
.clear
=
1008 ((GLuint
) (ctx
->Stencil
.Clear
& ZB_STENCILREFMASK_STENCIL_MASK
) |
1009 (ZB_STENCILREFMASK_STENCIL_MASK
<< ZB_STENCILREFMASK_STENCILMASK_SHIFT
) |
1010 ((ctx
->Stencil
.WriteMask
[0] & ZB_STENCILREFMASK_STENCIL_MASK
) <<
1011 ZB_STENCILREFMASK_STENCILMASK_SHIFT
));
1014 /* =============================================================
1015 * Window position and viewport transformation
1019 * To correctly position primitives:
1021 #define SUBPIXEL_X 0.125
1022 #define SUBPIXEL_Y 0.125
1024 static void r300UpdateWindow(GLcontext
* ctx
)
1026 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1027 __DRIdrawablePrivate
*dPriv
= rmesa
->radeon
.dri
.drawable
;
1028 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
1029 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
1030 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1032 GLfloat sx
= v
[MAT_SX
];
1033 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
1034 GLfloat sy
= -v
[MAT_SY
];
1035 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
1036 GLfloat sz
= v
[MAT_SZ
] * rmesa
->state
.depth
.scale
;
1037 GLfloat tz
= v
[MAT_TZ
] * rmesa
->state
.depth
.scale
;
1039 R300_FIREVERTICES(rmesa
);
1040 R300_STATECHANGE(rmesa
, vpt
);
1042 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
1043 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
1044 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
1045 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1046 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
1047 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
1050 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
1051 GLsizei width
, GLsizei height
)
1053 /* Don't pipeline viewport changes, conflict with window offset
1054 * setting below. Could apply deltas to rescue pipelined viewport
1055 * values, or keep the originals hanging around.
1057 r300UpdateWindow(ctx
);
1060 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
1062 r300UpdateWindow(ctx
);
1065 void r300UpdateViewportOffset(GLcontext
* ctx
)
1067 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1068 __DRIdrawablePrivate
*dPriv
= ((radeonContextPtr
) rmesa
)->dri
.drawable
;
1069 GLfloat xoffset
= (GLfloat
) dPriv
->x
;
1070 GLfloat yoffset
= (GLfloat
) dPriv
->y
+ dPriv
->h
;
1071 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1073 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
1074 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
1076 if (rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] != r300PackFloat32(tx
) ||
1077 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] != r300PackFloat32(ty
)) {
1078 /* Note: this should also modify whatever data the context reset
1081 R300_STATECHANGE(rmesa
, vpt
);
1082 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
1083 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1087 radeonUpdateScissor(ctx
);
1091 * Tell the card where to render (offset, pitch).
1092 * Effected by glDrawBuffer, etc
1094 void r300UpdateDrawBuffer(GLcontext
* ctx
)
1096 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1097 r300ContextPtr r300
= rmesa
;
1098 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1099 driRenderbuffer
*drb
;
1101 if (fb
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
) {
1104 (driRenderbuffer
*) fb
->Attachment
[BUFFER_FRONT_LEFT
].
1106 } else if (fb
->_ColorDrawBufferIndexes
[0] == BUFFER_BACK_LEFT
) {
1109 (driRenderbuffer
*) fb
->Attachment
[BUFFER_BACK_LEFT
].
1112 /* drawing to multiple buffers, or none */
1117 assert(drb
->flippedPitch
);
1119 R300_STATECHANGE(rmesa
, cb
);
1121 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] = drb
->flippedOffset
+ //r300->radeon.state.color.drawOffset +
1122 r300
->radeon
.radeonScreen
->fbLocation
;
1123 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = drb
->flippedPitch
; //r300->radeon.state.color.drawPitch;
1125 if (r300
->radeon
.radeonScreen
->cpp
== 4)
1126 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
1128 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
1130 if (r300
->radeon
.sarea
->tiling_enabled
)
1131 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
1133 R200_STATECHANGE(rmesa
, ctx
);
1135 /* Note: we used the (possibly) page-flipped values */
1136 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLOROFFSET
]
1137 = ((drb
->flippedOffset
+ rmesa
->r200Screen
->fbLocation
)
1138 & R200_COLOROFFSET_MASK
);
1139 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] = drb
->flippedPitch
;
1141 if (rmesa
->sarea
->tiling_enabled
) {
1142 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] |=
1143 R200_COLOR_TILE_ENABLE
;
1149 r300FetchStateParameter(GLcontext
* ctx
,
1150 const gl_state_index state
[STATE_LENGTH
],
1153 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1156 case STATE_INTERNAL
:
1158 case STATE_R300_WINDOW_DIMENSION
:
1159 value
[0] = r300
->radeon
.dri
.drawable
->w
* 0.5f
; /* width*0.5 */
1160 value
[1] = r300
->radeon
.dri
.drawable
->h
* 0.5f
; /* height*0.5 */
1161 value
[2] = 0.5F
; /* for moving range [-1 1] -> [0 1] */
1162 value
[3] = 1.0F
; /* not used */
1165 case STATE_R300_TEXRECT_FACTOR
:{
1166 struct gl_texture_object
*t
=
1167 ctx
->Texture
.Unit
[state
[2]].CurrentRect
;
1169 if (t
&& t
->Image
[0][t
->BaseLevel
]) {
1170 struct gl_texture_image
*image
=
1171 t
->Image
[0][t
->BaseLevel
];
1172 value
[0] = 1.0 / image
->Width2
;
1173 value
[1] = 1.0 / image
->Height2
;
1194 * Update R300's own internal state parameters.
1195 * For now just STATE_R300_WINDOW_DIMENSION
1197 void r300UpdateStateParameters(GLcontext
* ctx
, GLuint new_state
)
1199 struct r300_fragment_program
*fp
;
1200 struct gl_program_parameter_list
*paramList
;
1203 if (!(new_state
& (_NEW_BUFFERS
| _NEW_PROGRAM
)))
1206 fp
= (struct r300_fragment_program
*)ctx
->FragmentProgram
._Current
;
1210 paramList
= fp
->mesa_program
.Base
.Parameters
;
1215 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1216 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1217 r300FetchStateParameter(ctx
,
1218 paramList
->Parameters
[i
].
1220 paramList
->ParameterValues
[i
]);
1225 /* =============================================================
1228 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
1230 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1231 GLfloat constant
= units
;
1233 switch (ctx
->Visual
.depthBits
) {
1244 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
1246 R300_STATECHANGE(rmesa
, zbs
);
1247 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
1248 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
1249 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
1250 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
1253 /* Routing and texture-related */
1255 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
1256 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
1257 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
1258 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1259 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1260 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1261 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
1262 * combinations where only one of them is nearest.
1264 static unsigned long gen_fixed_filter(unsigned long f
)
1266 unsigned long mag
, min
, needs_fixing
= 0;
1269 /* We ignore MIRROR bit so we dont have to do everything twice */
1270 if ((f
& ((7 - 1) << R300_TX_WRAP_S_SHIFT
)) ==
1271 (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)) {
1274 if ((f
& ((7 - 1) << R300_TX_WRAP_T_SHIFT
)) ==
1275 (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)) {
1278 if ((f
& ((7 - 1) << R300_TX_WRAP_Q_SHIFT
)) ==
1279 (R300_TX_CLAMP
<< R300_TX_WRAP_Q_SHIFT
)) {
1286 mag
= f
& R300_TX_MAG_FILTER_MASK
;
1287 min
= f
& R300_TX_MIN_FILTER_MASK
;
1289 /* TODO: Check for anisto filters too */
1290 if ((mag
!= R300_TX_MAG_FILTER_NEAREST
)
1291 && (min
!= R300_TX_MIN_FILTER_NEAREST
))
1294 /* r300 cant handle these modes hence we force nearest to linear */
1295 if ((mag
== R300_TX_MAG_FILTER_NEAREST
)
1296 && (min
!= R300_TX_MIN_FILTER_NEAREST
)) {
1297 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
1298 f
|= R300_TX_MAG_FILTER_LINEAR
;
1302 if ((min
== R300_TX_MIN_FILTER_NEAREST
)
1303 && (mag
!= R300_TX_MAG_FILTER_NEAREST
)) {
1304 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
1305 f
|= R300_TX_MIN_FILTER_LINEAR
;
1309 /* Both are nearest */
1310 if (needs_fixing
& 1) {
1311 f
&= ~((7 - 1) << R300_TX_WRAP_S_SHIFT
);
1312 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1314 if (needs_fixing
& 2) {
1315 f
&= ~((7 - 1) << R300_TX_WRAP_T_SHIFT
);
1316 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1318 if (needs_fixing
& 4) {
1319 f
&= ~((7 - 1) << R300_TX_WRAP_Q_SHIFT
);
1320 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_Q_SHIFT
;
1325 static void r300SetupTextures(GLcontext
* ctx
)
1328 struct r300_tex_obj
*t
;
1329 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1331 int last_hw_tmu
= -1; /* -1 translates into no setup costs for fields */
1332 int tmu_mappings
[R300_MAX_TEXTURE_UNITS
] = { -1, };
1333 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
1334 (char *)ctx
->FragmentProgram
._Current
;
1336 R300_STATECHANGE(r300
, txe
);
1337 R300_STATECHANGE(r300
, tex
.filter
);
1338 R300_STATECHANGE(r300
, tex
.filter_1
);
1339 R300_STATECHANGE(r300
, tex
.size
);
1340 R300_STATECHANGE(r300
, tex
.format
);
1341 R300_STATECHANGE(r300
, tex
.pitch
);
1342 R300_STATECHANGE(r300
, tex
.offset
);
1343 R300_STATECHANGE(r300
, tex
.chroma_key
);
1344 R300_STATECHANGE(r300
, tex
.border_color
);
1346 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] = 0x0;
1348 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1349 if (RADEON_DEBUG
& DEBUG_STATE
)
1350 fprintf(stderr
, "mtu=%d\n", mtu
);
1352 if (mtu
> R300_MAX_TEXTURE_UNITS
) {
1354 "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1355 mtu
, R300_MAX_TEXTURE_UNITS
);
1359 /* We cannot let disabled tmu offsets pass DRM */
1360 for (i
= 0; i
< mtu
; i
++) {
1361 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
1363 #if 0 /* Enables old behaviour */
1366 tmu_mappings
[i
] = hw_tmu
;
1368 t
= r300
->state
.texture
.unit
[i
].texobj
;
1369 /* XXX questionable fix for bug 9170: */
1373 if ((t
->format
& 0xffffff00) == 0xffffff00) {
1375 ("unknown texture format (entry %x) encountered. Help me !\n",
1379 if (RADEON_DEBUG
& DEBUG_STATE
)
1381 "Activating texture unit %d\n", i
);
1383 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= (1 << hw_tmu
);
1385 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+
1387 gen_fixed_filter(t
->filter
) | (hw_tmu
<< 28);
1388 /* Currently disabled! */
1389 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] = 0x0; //0x20501f80;
1390 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1392 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+
1393 hw_tmu
] = t
->format
;
1394 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1396 r300
->hw
.tex
.offset
.cmd
[R300_TEX_VALUE_0
+
1397 hw_tmu
] = t
->offset
;
1399 if (t
->offset
& R300_TXO_MACRO_TILE
) {
1400 WARN_ONCE("macro tiling enabled!\n");
1403 if (t
->offset
& R300_TXO_MICRO_TILE
) {
1404 WARN_ONCE("micro tiling enabled!\n");
1407 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_VALUE_0
+
1409 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+
1413 last_hw_tmu
= hw_tmu
;
1419 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1420 cmdpacket0(R300_TX_FILTER0_0
, last_hw_tmu
+ 1);
1421 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_CMD_0
] =
1422 cmdpacket0(R300_TX_FILTER1_0
, last_hw_tmu
+ 1);
1423 r300
->hw
.tex
.size
.cmd
[R300_TEX_CMD_0
] =
1424 cmdpacket0(R300_TX_SIZE_0
, last_hw_tmu
+ 1);
1425 r300
->hw
.tex
.format
.cmd
[R300_TEX_CMD_0
] =
1426 cmdpacket0(R300_TX_FORMAT_0
, last_hw_tmu
+ 1);
1427 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_CMD_0
] =
1428 cmdpacket0(R300_TX_FORMAT2_0
, last_hw_tmu
+ 1);
1429 r300
->hw
.tex
.offset
.cmd
[R300_TEX_CMD_0
] =
1430 cmdpacket0(R300_TX_OFFSET_0
, last_hw_tmu
+ 1);
1431 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_CMD_0
] =
1432 cmdpacket0(R300_TX_CHROMA_KEY_0
, last_hw_tmu
+ 1);
1433 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_CMD_0
] =
1434 cmdpacket0(R300_TX_BORDER_COLOR_0
, last_hw_tmu
+ 1);
1436 if (!fp
) /* should only happenen once, just after context is created */
1440 if (r300
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV515
) {
1441 R300_STATECHANGE(r300
, fpt
);
1443 for (i
= 0; i
< fp
->tex
.length
; i
++) {
1448 unit
= fp
->tex
.inst
[i
] >> R300_FPITX_IMAGE_SHIFT
;
1451 val
= fp
->tex
.inst
[i
];
1452 val
&= ~R300_FPITX_IMAGE_MASK
;
1455 (val
& R300_FPITX_OPCODE_MASK
) >> R300_FPITX_OPCODE_SHIFT
;
1456 if (opcode
== R300_FPITX_OP_KIL
) {
1457 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1459 if (tmu_mappings
[unit
] >= 0) {
1461 tmu_mappings
[unit
] <<
1462 R300_FPITX_IMAGE_SHIFT
;
1463 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1465 // We get here when the corresponding texture image is incomplete
1466 // (e.g. incomplete mipmaps etc.)
1467 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1472 r300
->hw
.fpt
.cmd
[R300_FPT_CMD_0
] =
1473 cmdpacket0(R300_PFS_TEXI_0
, fp
->tex
.length
);
1476 if (RADEON_DEBUG
& DEBUG_STATE
)
1477 fprintf(stderr
, "TX_ENABLE: %08x last_hw_tmu=%d\n",
1478 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], last_hw_tmu
);
1481 union r300_outputs_written
{
1482 GLuint vp_outputs
; /* hw_tcl_on */
1483 DECLARE_RENDERINPUTS(index_bitset
); /* !hw_tcl_on */
1486 #define R300_OUTPUTS_WRITTEN_TEST(ow, vp_result, tnl_attrib) \
1487 ((hw_tcl_on) ? (ow).vp_outputs & (1 << (vp_result)) : \
1488 RENDERINPUTS_TEST( (ow.index_bitset), (tnl_attrib) ))
1490 static void r300SetupRSUnit(GLcontext
* ctx
)
1492 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1493 /* I'm still unsure if these are needed */
1494 GLuint interp_magic
[8] = {
1504 union r300_outputs_written OutputsWritten
;
1506 int fp_reg
, high_rr
;
1507 int in_texcoords
, col_interp_nr
;
1511 OutputsWritten
.vp_outputs
= CURRENT_VERTEX_SHADER(ctx
)->key
.OutputsWritten
;
1513 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->state
.render_inputs_bitset
);
1515 if (ctx
->FragmentProgram
._Current
)
1516 InputsRead
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
1518 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1519 return; /* This should only ever happen once.. */
1522 R300_STATECHANGE(r300
, ri
);
1523 R300_STATECHANGE(r300
, rc
);
1524 R300_STATECHANGE(r300
, rr
);
1526 fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1528 r300
->hw
.rr
.cmd
[R300_RR_INST_1
] = 0;
1530 if (InputsRead
& FRAG_BIT_WPOS
) {
1531 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
1532 if (!(InputsRead
& (FRAG_BIT_TEX0
<< i
)))
1535 if (i
== ctx
->Const
.MaxTextureUnits
) {
1536 fprintf(stderr
, "\tno free texcoord found...\n");
1540 InputsRead
|= (FRAG_BIT_TEX0
<< i
);
1541 InputsRead
&= ~FRAG_BIT_WPOS
;
1544 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1545 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0 | R300_RS_SEL_T(1) | R300_RS_SEL_R(2) | R300_RS_SEL_Q(3) | (in_texcoords
<< R300_RS_INTERP_SRC_SHIFT
)
1548 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] = 0;
1549 if (InputsRead
& (FRAG_BIT_TEX0
<< i
)) {
1550 //assert(r300->state.texture.tc_count != 0);
1551 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] |= R300_RS_INST_TEX_CN_WRITE
| i
/* source INTERP */
1552 | (fp_reg
<< R300_RS_INST_TEX_ADDR_SHIFT
);
1555 /* Passing invalid data here can lock the GPU. */
1556 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1557 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1560 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1563 /* Need to count all coords enabled at vof */
1564 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1569 if (InputsRead
& FRAG_BIT_COL0
) {
1570 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1571 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] |= R300_RS_INST_COL_ID(0) | R300_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R300_RS_INST_COL_ADDR_SHIFT
);
1572 InputsRead
&= ~FRAG_BIT_COL0
;
1575 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1579 if (InputsRead
& FRAG_BIT_COL1
) {
1580 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1581 r300
->hw
.rr
.cmd
[R300_RR_INST_1
] |= R300_RS_INST_COL_ID(1) | R300_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R300_RS_INST_COL_ADDR_SHIFT
);
1582 InputsRead
&= ~FRAG_BIT_COL1
;
1587 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1591 /* Need at least one. This might still lock as the values are undefined... */
1592 if (in_texcoords
== 0 && col_interp_nr
== 0) {
1593 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] |= R300_RS_INST_COL_ID(0) | R300_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R300_RS_INST_COL_ADDR_SHIFT
);
1597 r300
->hw
.rc
.cmd
[1] = 0 | ((in_texcoords
<< 2) << R300_IT_COUNT_SHIFT
)
1598 | (col_interp_nr
<< R300_IC_COUNT_SHIFT
)
1601 assert(high_rr
>= 0);
1602 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_INST_0
, high_rr
+ 1);
1603 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1606 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1609 static void r500SetupRSUnit(GLcontext
* ctx
)
1611 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1612 /* I'm still unsure if these are needed */
1613 GLuint interp_magic
[8] = {
1623 union r300_outputs_written OutputsWritten
;
1625 int fp_reg
, high_rr
;
1626 int in_texcoords
, col_interp_nr
;
1630 OutputsWritten
.vp_outputs
= CURRENT_VERTEX_SHADER(ctx
)->key
.OutputsWritten
;
1632 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->state
.render_inputs_bitset
);
1634 if (ctx
->FragmentProgram
._Current
)
1635 InputsRead
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
1637 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1638 return; /* This should only ever happen once.. */
1641 R300_STATECHANGE(r300
, ri
);
1642 R300_STATECHANGE(r300
, rc
);
1643 R300_STATECHANGE(r300
, rr
);
1645 fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1647 r300
->hw
.rr
.cmd
[R300_RR_INST_1
] = 0;
1649 if (InputsRead
& FRAG_BIT_WPOS
) {
1650 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
1651 if (!(InputsRead
& (FRAG_BIT_TEX0
<< i
)))
1654 if (i
== ctx
->Const
.MaxTextureUnits
) {
1655 fprintf(stderr
, "\tno free texcoord found...\n");
1659 InputsRead
|= (FRAG_BIT_TEX0
<< i
);
1660 InputsRead
&= ~FRAG_BIT_WPOS
;
1663 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1665 // r300->hw.ri.cmd[R300_RI_INTERP_0 + i] = 0 | R300_RS_SEL_T(1) | R300_RS_SEL_R(2) | R300_RS_SEL_Q(3) | (in_texcoords << R300_RS_INTERP_SRC_SHIFT)
1667 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = (0 << R500_RS_IP_TEX_PTR_S_SHIFT
) |
1668 (1 << R500_RS_IP_TEX_PTR_T_SHIFT
) |
1669 (2 << R500_RS_IP_TEX_PTR_R_SHIFT
) |
1670 (3 << R500_RS_IP_TEX_PTR_Q_SHIFT
) |
1671 (in_texcoords
<< 0) | interp_magic
[i
];
1673 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] = 0;
1674 if (InputsRead
& (FRAG_BIT_TEX0
<< i
)) {
1675 //assert(r300->state.texture.tc_count != 0);
1676 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] |= R500_RS_INST_TEX_CN_WRITE
| i
/* source INTERP */
1677 | (fp_reg
<< R500_RS_INST_TEX_ADDR_SHIFT
);
1680 /* Passing invalid data here can lock the GPU. */
1681 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1682 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1685 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1688 /* Need to count all coords enabled at vof */
1689 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1694 if (InputsRead
& FRAG_BIT_COL0
) {
1695 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1696 // r300->hw.rr.cmd[R300_RR_ROUTE_0] |= 0 | R300_RS_ROUTE_0_COLOR | (fp_reg++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT);
1697 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] |= 0 | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_ADDR_SHIFT
);
1698 InputsRead
&= ~FRAG_BIT_COL0
;
1701 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1705 if (InputsRead
& FRAG_BIT_COL1
) {
1706 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1707 // r300->hw.rr.cmd[R300_RR_ROUTE_1] |= R300_RS_ROUTE_1_UNKNOWN11 | R300_RS_ROUTE_1_COLOR1 | (fp_reg++ << R300_RS_ROUTE_1_COLOR1_DEST_SHIFT);
1708 r300
->hw
.rr
.cmd
[R300_RR_INST_1
] |= (1 << 12) | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_ADDR_SHIFT
);
1709 InputsRead
&= ~FRAG_BIT_COL1
;
1714 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1718 /* Need at least one. This might still lock as the values are undefined... */
1719 if (in_texcoords
== 0 && col_interp_nr
== 0) {
1720 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] |= 0 | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_ADDR_SHIFT
);
1724 r300
->hw
.rc
.cmd
[1] = 0 | ((in_texcoords
<< 2) << R300_IT_COUNT_SHIFT
)
1725 | (col_interp_nr
<< R300_IC_COUNT_SHIFT
)
1728 assert(high_rr
>= 0);
1729 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_INST_0
, high_rr
+ 1);
1730 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1733 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1739 #define bump_vpu_count(ptr, new_count) do{\
1740 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1741 int _nc=(new_count)/4; \
1742 assert(_nc < 256); \
1743 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1746 static inline void r300SetupVertexProgramFragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1750 if (vsf
->length
== 0)
1753 if (vsf
->length
& 0x3) {
1754 fprintf(stderr
, "VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1758 switch ((dest
>> 8) & 0xf) {
1760 R300_STATECHANGE(r300
, vpi
);
1761 for (i
= 0; i
< vsf
->length
; i
++)
1762 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1763 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1767 R300_STATECHANGE(r300
, vpp
);
1768 for (i
= 0; i
< vsf
->length
; i
++)
1769 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1770 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1773 R300_STATECHANGE(r300
, vps
);
1774 for (i
= 0; i
< vsf
->length
; i
++)
1775 r300
->hw
.vps
.cmd
[1 + i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1776 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1779 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1784 static void r300SetupDefaultVertexProgram(r300ContextPtr rmesa
)
1786 struct r300_vertex_shader_state
*prog
= &(rmesa
->state
.vertex_shader
);
1790 int param_count
= 0;
1791 int program_end
= 0;
1793 for (i
= VERT_ATTRIB_POS
; i
< VERT_ATTRIB_MAX
; i
++) {
1794 if (rmesa
->state
.sw_tcl_inputs
[i
] != -1) {
1795 prog
->program
.body
.i
[program_end
+ 0] = PVS_OP_DST_OPERAND(VE_MULTIPLY
, GL_FALSE
, GL_FALSE
, o_reg
++, VSF_FLAG_ALL
, PVS_DST_REG_OUT
);
1796 prog
->program
.body
.i
[program_end
+ 1] = PVS_SRC_OPERAND(rmesa
->state
.sw_tcl_inputs
[i
], PVS_SRC_SELECT_X
, PVS_SRC_SELECT_Y
, PVS_SRC_SELECT_Z
, PVS_SRC_SELECT_W
, PVS_SRC_REG_INPUT
, VSF_FLAG_NONE
);
1797 prog
->program
.body
.i
[program_end
+ 2] = PVS_SRC_OPERAND(rmesa
->state
.sw_tcl_inputs
[i
], PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_REG_INPUT
, VSF_FLAG_NONE
);
1798 prog
->program
.body
.i
[program_end
+ 3] = PVS_SRC_OPERAND(rmesa
->state
.sw_tcl_inputs
[i
], PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_SELECT_FORCE_1
, PVS_SRC_REG_INPUT
, VSF_FLAG_NONE
);
1803 prog
->program
.length
= program_end
;
1805 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
,
1807 inst_count
= (prog
->program
.length
/ 4) - 1;
1809 R300_STATECHANGE(rmesa
, pvs
);
1810 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1811 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1812 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1813 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1814 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1815 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1816 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1817 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1818 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1819 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1822 static void r300SetupRealVertexProgram(r300ContextPtr rmesa
)
1824 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1825 struct r300_vertex_program
*prog
= (struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
1827 int param_count
= 0;
1829 /* FIXME: r300SetupVertexProgramFragment */
1830 R300_STATECHANGE(rmesa
, vpp
);
1832 r300VertexProgUpdateParams(ctx
,
1833 (struct r300_vertex_program_cont
*)
1834 ctx
->VertexProgram
._Current
,
1835 (float *)&rmesa
->hw
.vpp
.
1836 cmd
[R300_VPP_PARAM_0
]);
1837 bump_vpu_count(rmesa
->hw
.vpp
.cmd
, param_count
);
1840 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
, &(prog
->program
));
1841 inst_count
= (prog
->program
.length
/ 4) - 1;
1843 R300_STATECHANGE(rmesa
, pvs
);
1844 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1845 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1846 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1847 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1848 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1849 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1850 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1851 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1852 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1853 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1856 static void r300SetupVertexProgram(r300ContextPtr rmesa
)
1858 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1860 /* Reset state, in case we don't use something */
1861 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1862 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1863 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1865 /* Not sure why this doesnt work...
1866 0x400 area might have something to do with pixel shaders as it appears right after pfs programming.
1867 0x406 is set to { 0.0, 0.0, 1.0, 0.0 } most of the time but should change with smooth points and in other rare cases. */
1868 //setup_vertex_shader_fragment(rmesa, 0x406, &unk4);
1869 if (hw_tcl_on
&& ((struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
))->translated
) {
1870 r300SetupRealVertexProgram(rmesa
);
1872 /* FIXME: This needs to be replaced by vertex shader generation code. */
1873 r300SetupDefaultVertexProgram(rmesa
);
1877 /* FIXME: This is done for vertex shader fragments, but also needs to be
1878 * done for vap_pvs, so I leave it as a reminder. */
1880 reg_start(R300_VAP_PVS_WAITIDLE
, 0);
1886 * Enable/Disable states.
1888 * \note Mesa already filters redundant calls to this function.
1890 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1892 if (RADEON_DEBUG
& DEBUG_STATE
)
1893 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1894 _mesa_lookup_enum_by_nr(cap
),
1895 state
? "GL_TRUE" : "GL_FALSE");
1904 r300SetFogState(ctx
, state
);
1907 r300SetAlphaState(ctx
);
1910 case GL_COLOR_LOGIC_OP
:
1911 r300SetBlendState(ctx
);
1913 case GL_CLIP_PLANE0
:
1914 case GL_CLIP_PLANE1
:
1915 case GL_CLIP_PLANE2
:
1916 case GL_CLIP_PLANE3
:
1917 case GL_CLIP_PLANE4
:
1918 case GL_CLIP_PLANE5
:
1919 r300SetClipPlaneState(ctx
, cap
, state
);
1922 r300SetDepthState(ctx
);
1924 case GL_STENCIL_TEST
:
1925 r300SetStencilState(ctx
, state
);
1928 r300UpdateCulling(ctx
);
1930 case GL_POLYGON_OFFSET_POINT
:
1931 case GL_POLYGON_OFFSET_LINE
:
1932 case GL_POLYGON_OFFSET_FILL
:
1933 r300SetPolygonOffsetState(ctx
, state
);
1936 radeonEnable(ctx
, cap
, state
);
1942 * Completely recalculates hardware state based on the Mesa state.
1944 static void r300ResetHwState(r300ContextPtr r300
)
1946 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1949 if (!(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
1952 if (RADEON_DEBUG
& DEBUG_STATE
)
1953 fprintf(stderr
, "%s\n", __FUNCTION__
);
1955 r300UpdateWindow(ctx
);
1958 ctx
->Color
.ColorMask
[RCOMP
],
1959 ctx
->Color
.ColorMask
[GCOMP
],
1960 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1962 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1963 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1964 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1967 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
1968 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1969 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1970 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1971 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1972 ctx
->Stencil
.ZFailFunc
[0],
1973 ctx
->Stencil
.ZPassFunc
[0]);
1975 r300UpdateCulling(ctx
);
1977 r300UpdateTextureState(ctx
);
1979 r300SetBlendState(ctx
);
1981 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1982 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1985 /* for tcl, PVS_NUM_SLOTS, PVS_NUM_CNTLRS, VF_MAX_VTX_NUM need to be adjusted
1986 * dynamically. PVS_NUM_FPUS is fixed based on asic
1989 r300
->hw
.vap_cntl
.cmd
[1] = ((10 << R300_PVS_NUM_SLOTS_SHIFT
) |
1990 (5 << R300_PVS_NUM_CNTLRS_SHIFT
) |
1991 (12 << R300_VF_MAX_VTX_NUM_SHIFT
));
1992 if (r300
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
1993 r300
->hw
.vap_cntl
.cmd
[1] |= R500_TCL_STATE_OPTIMIZATION
;
1995 r300
->hw
.vap_cntl
.cmd
[1] = ((10 << R300_PVS_NUM_SLOTS_SHIFT
) |
1996 (5 << R300_PVS_NUM_CNTLRS_SHIFT
) |
1997 (5 << R300_VF_MAX_VTX_NUM_SHIFT
));
1999 if (r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV515
)
2000 r300
->hw
.vap_cntl
.cmd
[1] |= (2 << R300_PVS_NUM_FPUS_SHIFT
);
2001 else if ((r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV530
) ||
2002 (r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV560
))
2003 r300
->hw
.vap_cntl
.cmd
[1] |= (5 << R300_PVS_NUM_FPUS_SHIFT
);
2004 else if (r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R420
)
2005 r300
->hw
.vap_cntl
.cmd
[1] |= (6 << R300_PVS_NUM_FPUS_SHIFT
);
2006 else if ((r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R520
) ||
2007 (r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R580
) ||
2008 (r300
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV570
))
2009 r300
->hw
.vap_cntl
.cmd
[1] |= (8 << R300_PVS_NUM_FPUS_SHIFT
);
2011 r300
->hw
.vap_cntl
.cmd
[1] |= (4 << R300_PVS_NUM_FPUS_SHIFT
);
2013 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
2014 | R300_VPORT_X_OFFSET_ENA
2015 | R300_VPORT_Y_SCALE_ENA
2016 | R300_VPORT_Y_OFFSET_ENA
2017 | R300_VPORT_Z_SCALE_ENA
2018 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
2019 r300
->hw
.vte
.cmd
[2] = 0x00000008;
2021 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[1] = 0x00FFFFFF;
2022 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[2] = 0x00000000;
2024 #ifdef MESA_LITTLE_ENDIAN
2025 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
2027 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
2030 /* disable VAP/TCL on non-TCL capable chips */
2032 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
2034 r300
->hw
.vap_psc_sgn_norm_cntl
.cmd
[1] = 0xAAAAAAAA;
2036 /* XXX: Other families? */
2038 r300
->hw
.vap_clip_cntl
.cmd
[1] = R300_PS_UCP_MODE_DIST_COP
;
2040 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
2041 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
2042 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
2043 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
2045 switch (r300
->radeon
.radeonScreen
->chip_family
) {
2046 case CHIP_FAMILY_R300
:
2047 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_R300
;
2050 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_RV350
;
2055 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
2056 | R300_GB_LINE_STUFF_ENABLE
2057 | R300_GB_TRIANGLE_STUFF_ENABLE
;
2059 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
2060 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
2062 /* num pipes needs to be read back from the GB_PIPE_SELECT register
2063 * on r4xx/r5xx/rs4xx/rs6xx
2064 * should move this to the drm
2066 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
2067 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
/*| R300_GB_SUBPIXEL_1_16*/;
2068 switch (r300
->radeon
.radeonScreen
->chip_family
) {
2069 case CHIP_FAMILY_R300
:
2070 case CHIP_FAMILY_R350
:
2071 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2072 R300_GB_TILE_PIPE_COUNT_R300
;
2074 case CHIP_FAMILY_RV350
:
2075 case CHIP_FAMILY_RV515
:
2076 case CHIP_FAMILY_RV530
:
2077 case CHIP_FAMILY_RV410
:
2078 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2079 R300_GB_TILE_PIPE_COUNT_RV300
;
2081 case CHIP_FAMILY_R420
:
2082 case CHIP_FAMILY_R520
:
2083 case CHIP_FAMILY_R580
:
2084 case CHIP_FAMILY_RV560
:
2085 case CHIP_FAMILY_RV570
:
2086 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2087 R300_GB_TILE_PIPE_COUNT_R420
;
2090 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2091 R300_GB_TILE_DISABLE
; /* TODO: This disables tiling totally. I guess it happened accidentially. */
2095 /* XXX: set to 0 when fog is disabled? */
2096 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = R300_GB_FOG_SELECT_1_1_W
;
2098 /* XXX: Enable anti-aliasing? */
2099 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = GB_AA_CONFIG_AA_DISABLE
;
2101 r300
->hw
.ga_point_s0
.cmd
[1] = r300PackFloat32(0.0);
2102 r300
->hw
.ga_point_s0
.cmd
[2] = r300PackFloat32(0.0);
2103 r300
->hw
.ga_point_s0
.cmd
[3] = r300PackFloat32(1.0);
2104 r300
->hw
.ga_point_s0
.cmd
[4] = r300PackFloat32(1.0);
2106 r300
->hw
.ga_triangle_stipple
.cmd
[1] = 0x00050005;
2108 r300PointSize(ctx
, 1.0);
2110 r300
->hw
.ga_point_minmax
.cmd
[1] = 0x18000006;
2111 r300
->hw
.ga_point_minmax
.cmd
[2] = 0x00020006;
2112 r300
->hw
.ga_point_minmax
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
2114 r300LineWidth(ctx
, 1.0);
2116 r300
->hw
.ga_line_stipple
.cmd
[1] = 0;
2117 r300
->hw
.ga_line_stipple
.cmd
[2] = r300PackFloat32(0.0);
2118 r300
->hw
.ga_line_stipple
.cmd
[3] = r300PackFloat32(1.0);
2120 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
2122 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
2123 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
2124 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
2126 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
2127 ctx
->Polygon
.OffsetUnits
);
2128 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
2129 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
2130 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
2132 r300
->hw
.su_depth_scale
.cmd
[1] = 0x4B7FFFFF;
2133 r300
->hw
.su_depth_scale
.cmd
[2] = 0x00000000;
2135 r300
->hw
.sc_hyperz
.cmd
[1] = 0x0000001C;
2136 r300
->hw
.sc_hyperz
.cmd
[2] = 0x2DA49525;
2138 r300
->hw
.sc_screendoor
.cmd
[1] = 0x00FFFFFF;
2140 r300
->hw
.us_out_fmt
.cmd
[1] = 0x00001B01;
2141 r300
->hw
.us_out_fmt
.cmd
[2] = 0x00001B0F;
2142 r300
->hw
.us_out_fmt
.cmd
[3] = 0x00001B0F;
2143 r300
->hw
.us_out_fmt
.cmd
[4] = 0x00001B0F;
2144 r300
->hw
.us_out_fmt
.cmd
[5] = 0x00000001;
2146 r300Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
2147 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
2148 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
2149 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
2150 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
2151 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
2152 r300Fogfv(ctx
, GL_FOG_COORDINATE_SOURCE_EXT
, NULL
);
2154 r300
->hw
.fg_depth_src
.cmd
[1] = 0;
2156 r300
->hw
.rb3d_cctl
.cmd
[1] = 0;
2158 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
2160 /* Again, r300ClearBuffer uses this */
2161 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] =
2162 r300
->radeon
.state
.color
.drawOffset
+
2163 r300
->radeon
.radeonScreen
->fbLocation
;
2164 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.state
.color
.drawPitch
;
2166 if (r300
->radeon
.radeonScreen
->cpp
== 4)
2167 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
2169 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
2171 if (r300
->radeon
.sarea
->tiling_enabled
)
2172 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
2174 r300
->hw
.rb3d_dither_ctl
.cmd
[1] = 0;
2175 r300
->hw
.rb3d_dither_ctl
.cmd
[2] = 0;
2176 r300
->hw
.rb3d_dither_ctl
.cmd
[3] = 0;
2177 r300
->hw
.rb3d_dither_ctl
.cmd
[4] = 0;
2178 r300
->hw
.rb3d_dither_ctl
.cmd
[5] = 0;
2179 r300
->hw
.rb3d_dither_ctl
.cmd
[6] = 0;
2180 r300
->hw
.rb3d_dither_ctl
.cmd
[7] = 0;
2181 r300
->hw
.rb3d_dither_ctl
.cmd
[8] = 0;
2182 r300
->hw
.rb3d_dither_ctl
.cmd
[9] = 0;
2184 r300
->hw
.rb3d_aaresolve_ctl
.cmd
[1] = 0;
2186 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[1] = 0x00000000;
2187 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[2] = 0xffffffff;
2189 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
2190 r300
->radeon
.radeonScreen
->depthOffset
+
2191 r300
->radeon
.radeonScreen
->fbLocation
;
2192 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
2194 if (r300
->radeon
.sarea
->tiling_enabled
) {
2195 /* XXX: Turn off when clearing buffers ? */
2196 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= ZB_DEPTHPITCH_DEPTHMACROTILE_ENABLE
;
2198 if (ctx
->Visual
.depthBits
== 24)
2199 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |=
2200 ZB_DEPTHPITCH_DEPTHMICROTILE_TILED
;
2203 r300
->hw
.zb_depthclearvalue
.cmd
[1] = 0;
2205 r300
->hw
.unk4F30
.cmd
[1] = 0;
2206 r300
->hw
.unk4F30
.cmd
[2] = 0;
2208 r300
->hw
.zb_hiz_offset
.cmd
[1] = 0;
2210 r300
->hw
.zb_hiz_pitch
.cmd
[1] = 0;
2213 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
2214 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
2215 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
2216 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
2219 r300
->hw
.all_dirty
= GL_TRUE
;
2222 void r300UpdateShaders(r300ContextPtr rmesa
)
2225 struct r300_vertex_program
*vp
;
2228 ctx
= rmesa
->radeon
.glCtx
;
2230 if (rmesa
->NewGLState
&& hw_tcl_on
) {
2231 rmesa
->NewGLState
= 0;
2233 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2234 rmesa
->temp_attrib
[i
] =
2235 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
2236 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2237 &rmesa
->dummy_attrib
[i
];
2240 _tnl_UpdateFixedFunctionProgram(ctx
);
2242 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2243 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2244 rmesa
->temp_attrib
[i
];
2247 r300SelectVertexShader(rmesa
);
2248 vp
= (struct r300_vertex_program
*)
2249 CURRENT_VERTEX_SHADER(ctx
);
2250 /*if (vp->translated == GL_FALSE)
2251 r300TranslateVertexShader(vp); */
2252 if (vp
->translated
== GL_FALSE
) {
2253 fprintf(stderr
, "Failing back to sw-tcl\n");
2254 hw_tcl_on
= future_hw_tcl_on
= 0;
2255 r300ResetHwState(rmesa
);
2259 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
);
2263 static void r300SetupPixelShader(r300ContextPtr rmesa
)
2265 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2266 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2267 (char *)ctx
->FragmentProgram
._Current
;
2270 if (!fp
) /* should only happenen once, just after context is created */
2273 r300TranslateFragmentShader(rmesa
, fp
);
2274 if (!fp
->translated
) {
2275 fprintf(stderr
, "%s: No valid fragment shader, exiting\n",
2280 R300_STATECHANGE(rmesa
, fpi
[0]);
2281 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR0_0
, fp
->alu_end
+ 1);
2282 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2283 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst0
;
2286 R300_STATECHANGE(rmesa
, fpi
[1]);
2287 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR1_0
, fp
->alu_end
+ 1);
2288 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2289 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst1
;
2292 R300_STATECHANGE(rmesa
, fpi
[2]);
2293 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR2_0
, fp
->alu_end
+ 1);
2294 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2295 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst2
;
2298 R300_STATECHANGE(rmesa
, fpi
[3]);
2299 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR3_0
, fp
->alu_end
+ 1);
2300 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2301 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst3
;
2304 R300_STATECHANGE(rmesa
, fp
);
2305 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = fp
->cur_node
| (fp
->first_node_has_tex
<< 3);
2306 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = fp
->max_temp_idx
;
2307 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] =
2308 (fp
->alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
) |
2309 (fp
->alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
) |
2310 (fp
->tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
) |
2311 (fp
->tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
2312 /* I just want to say, the way these nodes are stored.. weird.. */
2313 for (i
= 0, k
= (4 - (fp
->cur_node
+ 1)); i
< 4; i
++, k
++) {
2314 if (i
< (fp
->cur_node
+ 1)) {
2315 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ k
] =
2316 (fp
->node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
) |
2317 (fp
->node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
) |
2318 (fp
->node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
) |
2319 (fp
->node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
) |
2322 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ (3 - i
)] = 0;
2326 R300_STATECHANGE(rmesa
, fpp
);
2327 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(R300_PFS_PARAM_0_X
, fp
->const_nr
* 4);
2328 for (i
= 0; i
< fp
->const_nr
; i
++) {
2329 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(fp
->constant
[i
][0]);
2330 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(fp
->constant
[i
][1]);
2331 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(fp
->constant
[i
][2]);
2332 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(fp
->constant
[i
][3]);
2336 #define bump_r500fp_count(ptr, new_count) do{\
2337 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2338 int _nc=(new_count)/6; \
2339 assert(_nc < 256); \
2340 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2343 #define bump_r500fp_const_count(ptr, new_count) do{\
2344 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2345 int _nc=(new_count)/4; \
2346 assert(_nc < 256); \
2347 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2350 static void r500SetupPixelShader(r300ContextPtr rmesa
)
2352 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2353 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2354 (char *)ctx
->FragmentProgram
._Current
;
2357 if (!fp
) /* should only happenen once, just after context is created */
2360 /* emit the standard zero shader */
2361 R300_STATECHANGE(rmesa
, r500fp
);
2363 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_INST_TYPE_OUT
|
2364 R500_INST_TEX_SEM_WAIT
|
2366 R500_INST_RGB_OMASK_R
|
2367 R500_INST_RGB_OMASK_G
|
2368 R500_INST_RGB_OMASK_B
|
2369 R500_INST_ALPHA_OMASK
;
2371 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_RGB_ADDR0(0) |
2373 R500_RGB_ADDR1_CONST
|
2375 R500_RGB_ADDR2_CONST
|
2376 R500_RGB_SRCP_OP_1_MINUS_2RGB0
;
2377 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALPHA_ADDR0(0) |
2378 R500_ALPHA_ADDR1(0) |
2379 R500_ALPHA_ADDR1_CONST
|
2380 R500_ALPHA_ADDR2(0) |
2381 R500_ALPHA_ADDR2_CONST
|
2382 R500_ALPHA_SRCP_OP_1_MINUS_2A0
;
2383 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALU_RGB_SEL_A_SRC0
|
2384 R500_ALU_RGB_R_SWIZ_A_R
|
2385 R500_ALU_RGB_G_SWIZ_A_G
|
2386 R500_ALU_RGB_B_SWIZ_A_B
|
2387 R500_ALU_RGB_SEL_B_SRC0
|
2388 R500_ALU_RGB_R_SWIZ_B_1
|
2389 R500_ALU_RGB_B_SWIZ_B_1
|
2390 R500_ALU_RGB_G_SWIZ_B_1
;
2391 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALPHA_OP_MAD
|
2392 R500_ALPHA_SWIZ_A_A
|
2393 R500_ALPHA_SWIZ_B_1
;
2394 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALU_RGBA_OP_MAD
|
2395 R500_ALU_RGBA_R_SWIZ_0
|
2396 R500_ALU_RGBA_G_SWIZ_0
|
2397 R500_ALU_RGBA_B_SWIZ_0
|
2398 R500_ALU_RGBA_A_SWIZ_0
;
2400 bump_r500fp_count(rmesa
->hw
.r500fp
.cmd
, 6);
2402 R300_STATECHANGE(rmesa
, r500fp_const
);
2403 for (i
= 0; i
< fp
->const_nr
; i
++) {
2404 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(fp
->constant
[i
][0]);
2405 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(fp
->constant
[i
][1]);
2406 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(fp
->constant
[i
][2]);
2407 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(fp
->constant
[i
][3]);
2409 bump_r500fp_const_count(rmesa
->hw
.r500fp_const
.cmd
, fp
->const_nr
* 4);
2413 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2416 ctx
= rmesa
->radeon
.glCtx
;
2418 r300UpdateTextureState(ctx
);
2420 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
2421 r500SetupPixelShader(rmesa
);
2423 r300SetupPixelShader(rmesa
);
2424 r300SetupTextures(ctx
);
2426 if ((rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
2427 r300SetupVertexProgram(rmesa
);
2429 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
2430 r500SetupRSUnit(ctx
);
2432 r300SetupRSUnit(ctx
);
2436 * Called by Mesa after an internal state update.
2438 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2440 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2442 _swrast_InvalidateState(ctx
, new_state
);
2443 _swsetup_InvalidateState(ctx
, new_state
);
2444 _vbo_InvalidateState(ctx
, new_state
);
2445 _tnl_InvalidateState(ctx
, new_state
);
2446 _ae_invalidate_state(ctx
, new_state
);
2448 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
2449 r300UpdateDrawBuffer(ctx
);
2452 r300UpdateStateParameters(ctx
, new_state
);
2454 r300
->NewGLState
|= new_state
;
2458 * Calculate initial hardware state and register state functions.
2459 * Assumes that the command buffer and state atoms have been
2460 * initialized already.
2462 void r300InitState(r300ContextPtr r300
)
2464 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2467 radeonInitState(&r300
->radeon
);
2469 switch (ctx
->Visual
.depthBits
) {
2471 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2472 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_16BIT_INT_Z
;
2473 r300
->state
.stencil
.clear
= 0x00000000;
2476 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2477 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_24BIT_INT_Z
;
2478 r300
->state
.stencil
.clear
= 0x00ff0000;
2481 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2482 ctx
->Visual
.depthBits
);
2486 /* Only have hw stencil when depth buffer is 24 bits deep */
2487 r300
->state
.stencil
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2488 ctx
->Visual
.depthBits
== 24);
2490 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2492 r300ResetHwState(r300
);
2495 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2497 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2502 void r300UpdateClipPlanes( GLcontext
*ctx
)
2504 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2507 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
2508 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
2509 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
2511 R300_STATECHANGE( rmesa
, vpucp
[p
] );
2512 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
2513 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
2514 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
2515 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
2521 * Initialize driver's state callback functions
2523 void r300InitStateFuncs(struct dd_function_table
*functions
)
2525 radeonInitStateFuncs(functions
);
2527 functions
->UpdateState
= r300InvalidateState
;
2528 functions
->AlphaFunc
= r300AlphaFunc
;
2529 functions
->BlendColor
= r300BlendColor
;
2530 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2531 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2532 functions
->Enable
= r300Enable
;
2533 functions
->ColorMask
= r300ColorMask
;
2534 functions
->DepthFunc
= r300DepthFunc
;
2535 functions
->DepthMask
= r300DepthMask
;
2536 functions
->CullFace
= r300CullFace
;
2537 functions
->Fogfv
= r300Fogfv
;
2538 functions
->FrontFace
= r300FrontFace
;
2539 functions
->ShadeModel
= r300ShadeModel
;
2541 /* Stencil related */
2542 functions
->ClearStencil
= r300ClearStencil
;
2543 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2544 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2545 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2547 /* Viewport related */
2548 functions
->Viewport
= r300Viewport
;
2549 functions
->DepthRange
= r300DepthRange
;
2550 functions
->PointSize
= r300PointSize
;
2551 functions
->LineWidth
= r300LineWidth
;
2553 functions
->PolygonOffset
= r300PolygonOffset
;
2554 functions
->PolygonMode
= r300PolygonMode
;
2556 functions
->RenderMode
= r300RenderMode
;
2558 functions
->ClipPlane
= r300ClipPlane
;