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 */
1439 R300_STATECHANGE(r300
, fpt
);
1441 for (i
= 0; i
< fp
->tex
.length
; i
++) {
1446 unit
= fp
->tex
.inst
[i
] >> R300_FPITX_IMAGE_SHIFT
;
1449 val
= fp
->tex
.inst
[i
];
1450 val
&= ~R300_FPITX_IMAGE_MASK
;
1453 (val
& R300_FPITX_OPCODE_MASK
) >> R300_FPITX_OPCODE_SHIFT
;
1454 if (opcode
== R300_FPITX_OP_KIL
) {
1455 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1457 if (tmu_mappings
[unit
] >= 0) {
1459 tmu_mappings
[unit
] <<
1460 R300_FPITX_IMAGE_SHIFT
;
1461 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1463 // We get here when the corresponding texture image is incomplete
1464 // (e.g. incomplete mipmaps etc.)
1465 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1470 r300
->hw
.fpt
.cmd
[R300_FPT_CMD_0
] =
1471 cmdpacket0(R300_PFS_TEXI_0
, fp
->tex
.length
);
1473 if (RADEON_DEBUG
& DEBUG_STATE
)
1474 fprintf(stderr
, "TX_ENABLE: %08x last_hw_tmu=%d\n",
1475 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], last_hw_tmu
);
1478 union r300_outputs_written
{
1479 GLuint vp_outputs
; /* hw_tcl_on */
1480 DECLARE_RENDERINPUTS(index_bitset
); /* !hw_tcl_on */
1483 #define R300_OUTPUTS_WRITTEN_TEST(ow, vp_result, tnl_attrib) \
1484 ((hw_tcl_on) ? (ow).vp_outputs & (1 << (vp_result)) : \
1485 RENDERINPUTS_TEST( (ow.index_bitset), (tnl_attrib) ))
1487 static void r300SetupRSUnit(GLcontext
* ctx
)
1489 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1490 /* I'm still unsure if these are needed */
1491 GLuint interp_magic
[8] = {
1501 union r300_outputs_written OutputsWritten
;
1503 int fp_reg
, high_rr
;
1504 int in_texcoords
, col_interp_nr
;
1508 OutputsWritten
.vp_outputs
= CURRENT_VERTEX_SHADER(ctx
)->key
.OutputsWritten
;
1510 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->state
.render_inputs_bitset
);
1512 if (ctx
->FragmentProgram
._Current
)
1513 InputsRead
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
1515 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1516 return; /* This should only ever happen once.. */
1519 R300_STATECHANGE(r300
, ri
);
1520 R300_STATECHANGE(r300
, rc
);
1521 R300_STATECHANGE(r300
, rr
);
1523 fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1525 r300
->hw
.rr
.cmd
[R300_RR_INST_1
] = 0;
1527 if (InputsRead
& FRAG_BIT_WPOS
) {
1528 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
1529 if (!(InputsRead
& (FRAG_BIT_TEX0
<< i
)))
1532 if (i
== ctx
->Const
.MaxTextureUnits
) {
1533 fprintf(stderr
, "\tno free texcoord found...\n");
1537 InputsRead
|= (FRAG_BIT_TEX0
<< i
);
1538 InputsRead
&= ~FRAG_BIT_WPOS
;
1541 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1542 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
)
1545 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] = 0;
1546 if (InputsRead
& (FRAG_BIT_TEX0
<< i
)) {
1547 //assert(r300->state.texture.tc_count != 0);
1548 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ fp_reg
] |= R300_RS_INST_TEX_CN_WRITE
| i
/* source INTERP */
1549 | (fp_reg
<< R300_RS_INST_TEX_ADDR_SHIFT
);
1552 /* Passing invalid data here can lock the GPU. */
1553 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1554 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1557 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1560 /* Need to count all coords enabled at vof */
1561 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1566 if (InputsRead
& FRAG_BIT_COL0
) {
1567 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1568 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
);
1569 InputsRead
&= ~FRAG_BIT_COL0
;
1572 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1576 if (InputsRead
& FRAG_BIT_COL1
) {
1577 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1578 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
);
1579 InputsRead
&= ~FRAG_BIT_COL1
;
1584 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1588 /* Need at least one. This might still lock as the values are undefined... */
1589 if (in_texcoords
== 0 && col_interp_nr
== 0) {
1590 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
);
1594 r300
->hw
.rc
.cmd
[1] = 0 | ((in_texcoords
<< 2) << R300_IT_COUNT_SHIFT
)
1595 | (col_interp_nr
<< R300_IC_COUNT_SHIFT
)
1598 assert(high_rr
>= 0);
1599 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_INST_0
, high_rr
+ 1);
1600 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1603 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1606 static void r500SetupRSUnit(GLcontext
* ctx
)
1608 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1609 /* I'm still unsure if these are needed */
1610 GLuint interp_magic
[8] = {
1620 union r300_outputs_written OutputsWritten
;
1622 int fp_reg
, high_rr
;
1623 int in_texcoords
, col_interp_nr
;
1627 OutputsWritten
.vp_outputs
= CURRENT_VERTEX_SHADER(ctx
)->key
.OutputsWritten
;
1629 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->state
.render_inputs_bitset
);
1631 if (ctx
->FragmentProgram
._Current
)
1632 InputsRead
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
1634 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1635 return; /* This should only ever happen once.. */
1638 R300_STATECHANGE(r300
, ri
);
1639 R300_STATECHANGE(r300
, rc
);
1640 R300_STATECHANGE(r300
, rr
);
1642 fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1644 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] = 0;
1646 if (InputsRead
& FRAG_BIT_WPOS
) {
1647 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
1648 if (!(InputsRead
& (FRAG_BIT_TEX0
<< i
)))
1651 if (i
== ctx
->Const
.MaxTextureUnits
) {
1652 fprintf(stderr
, "\tno free texcoord found...\n");
1656 InputsRead
|= (FRAG_BIT_TEX0
<< i
);
1657 InputsRead
&= ~FRAG_BIT_WPOS
;
1660 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1662 // 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)
1664 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = (0 << R500_RS_IP_TEX_PTR_S_SHIFT
) |
1665 (1 << R500_RS_IP_TEX_PTR_T_SHIFT
) |
1666 (2 << R500_RS_IP_TEX_PTR_R_SHIFT
) |
1667 (3 << R500_RS_IP_TEX_PTR_Q_SHIFT
) |
1668 (in_texcoords
<< 0) | interp_magic
[i
];
1670 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ fp_reg
] = 0;
1671 if (InputsRead
& (FRAG_BIT_TEX0
<< i
)) {
1672 //assert(r300->state.texture.tc_count != 0);
1673 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ fp_reg
] |= R500_RS_INST_TEX_CN_WRITE
| i
/* source INTERP */
1674 | (fp_reg
<< R500_RS_INST_TEX_ADDR_SHIFT
);
1677 /* Passing invalid data here can lock the GPU. */
1678 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1679 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1682 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1685 /* Need to count all coords enabled at vof */
1686 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1691 if (InputsRead
& FRAG_BIT_COL0
) {
1692 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1693 // r300->hw.rr.cmd[R300_RR_ROUTE_0] |= 0 | R300_RS_ROUTE_0_COLOR | (fp_reg++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT);
1694 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0 | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_COL_ADDR_SHIFT
);
1695 InputsRead
&= ~FRAG_BIT_COL0
;
1698 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1702 if (InputsRead
& FRAG_BIT_COL1
) {
1703 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1704 // 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);
1705 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] |= (1 << 12) | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_COL_ADDR_SHIFT
);
1706 InputsRead
&= ~FRAG_BIT_COL1
;
1711 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1715 /* Need at least one. This might still lock as the values are undefined... */
1716 if (in_texcoords
== 0 && col_interp_nr
== 0) {
1717 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0 | R500_RS_INST_COL_CN_WRITE
| (fp_reg
++ << R500_RS_INST_COL_COL_ADDR_SHIFT
);
1721 r300
->hw
.rc
.cmd
[1] = 0 | ((in_texcoords
<< 2) << R300_IT_COUNT_SHIFT
)
1722 | (col_interp_nr
<< R300_IC_COUNT_SHIFT
)
1725 assert(high_rr
>= 0);
1726 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_ROUTE_0
, high_rr
+ 1);
1727 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1730 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1736 #define bump_vpu_count(ptr, new_count) do{\
1737 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1738 int _nc=(new_count)/4; \
1739 assert(_nc < 256); \
1740 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1743 static inline void r300SetupVertexProgramFragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1747 if (vsf
->length
== 0)
1750 if (vsf
->length
& 0x3) {
1751 fprintf(stderr
, "VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1755 switch ((dest
>> 8) & 0xf) {
1757 R300_STATECHANGE(r300
, vpi
);
1758 for (i
= 0; i
< vsf
->length
; i
++)
1759 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1760 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1764 R300_STATECHANGE(r300
, vpp
);
1765 for (i
= 0; i
< vsf
->length
; i
++)
1766 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1767 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1770 R300_STATECHANGE(r300
, vps
);
1771 for (i
= 0; i
< vsf
->length
; i
++)
1772 r300
->hw
.vps
.cmd
[1 + i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1773 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1776 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1781 static void r300SetupDefaultVertexProgram(r300ContextPtr rmesa
)
1783 struct r300_vertex_shader_state
*prog
= &(rmesa
->state
.vertex_shader
);
1787 int param_count
= 0;
1788 int program_end
= 0;
1790 for (i
= VERT_ATTRIB_POS
; i
< VERT_ATTRIB_MAX
; i
++) {
1791 if (rmesa
->state
.sw_tcl_inputs
[i
] != -1) {
1792 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
);
1793 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
);
1794 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
);
1795 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
);
1800 prog
->program
.length
= program_end
;
1802 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
,
1804 inst_count
= (prog
->program
.length
/ 4) - 1;
1806 R300_STATECHANGE(rmesa
, pvs
);
1807 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1808 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1809 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1810 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1811 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1812 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1813 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1814 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1815 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1816 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1819 static void r300SetupRealVertexProgram(r300ContextPtr rmesa
)
1821 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1822 struct r300_vertex_program
*prog
= (struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
1824 int param_count
= 0;
1826 /* FIXME: r300SetupVertexProgramFragment */
1827 R300_STATECHANGE(rmesa
, vpp
);
1829 r300VertexProgUpdateParams(ctx
,
1830 (struct r300_vertex_program_cont
*)
1831 ctx
->VertexProgram
._Current
,
1832 (float *)&rmesa
->hw
.vpp
.
1833 cmd
[R300_VPP_PARAM_0
]);
1834 bump_vpu_count(rmesa
->hw
.vpp
.cmd
, param_count
);
1837 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
, &(prog
->program
));
1838 inst_count
= (prog
->program
.length
/ 4) - 1;
1840 R300_STATECHANGE(rmesa
, pvs
);
1841 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1842 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1843 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1844 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1845 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1846 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1847 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1848 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1849 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1850 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1853 static void r300SetupVertexProgram(r300ContextPtr rmesa
)
1855 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1857 /* Reset state, in case we don't use something */
1858 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1859 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1860 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1862 /* Not sure why this doesnt work...
1863 0x400 area might have something to do with pixel shaders as it appears right after pfs programming.
1864 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. */
1865 //setup_vertex_shader_fragment(rmesa, 0x406, &unk4);
1866 if (hw_tcl_on
&& ((struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
))->translated
) {
1867 r300SetupRealVertexProgram(rmesa
);
1869 /* FIXME: This needs to be replaced by vertex shader generation code. */
1870 r300SetupDefaultVertexProgram(rmesa
);
1874 /* FIXME: This is done for vertex shader fragments, but also needs to be
1875 * done for vap_pvs, so I leave it as a reminder. */
1877 reg_start(R300_VAP_PVS_WAITIDLE
, 0);
1883 * Enable/Disable states.
1885 * \note Mesa already filters redundant calls to this function.
1887 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1889 if (RADEON_DEBUG
& DEBUG_STATE
)
1890 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1891 _mesa_lookup_enum_by_nr(cap
),
1892 state
? "GL_TRUE" : "GL_FALSE");
1901 r300SetFogState(ctx
, state
);
1904 r300SetAlphaState(ctx
);
1907 case GL_COLOR_LOGIC_OP
:
1908 r300SetBlendState(ctx
);
1910 case GL_CLIP_PLANE0
:
1911 case GL_CLIP_PLANE1
:
1912 case GL_CLIP_PLANE2
:
1913 case GL_CLIP_PLANE3
:
1914 case GL_CLIP_PLANE4
:
1915 case GL_CLIP_PLANE5
:
1916 r300SetClipPlaneState(ctx
, cap
, state
);
1919 r300SetDepthState(ctx
);
1921 case GL_STENCIL_TEST
:
1922 r300SetStencilState(ctx
, state
);
1925 r300UpdateCulling(ctx
);
1927 case GL_POLYGON_OFFSET_POINT
:
1928 case GL_POLYGON_OFFSET_LINE
:
1929 case GL_POLYGON_OFFSET_FILL
:
1930 r300SetPolygonOffsetState(ctx
, state
);
1933 radeonEnable(ctx
, cap
, state
);
1939 * Completely recalculates hardware state based on the Mesa state.
1941 static void r300ResetHwState(r300ContextPtr r300
)
1943 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1946 if (!(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
1949 if (RADEON_DEBUG
& DEBUG_STATE
)
1950 fprintf(stderr
, "%s\n", __FUNCTION__
);
1952 r300UpdateWindow(ctx
);
1955 ctx
->Color
.ColorMask
[RCOMP
],
1956 ctx
->Color
.ColorMask
[GCOMP
],
1957 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1959 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1960 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1961 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1964 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
1965 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1966 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1967 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1968 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1969 ctx
->Stencil
.ZFailFunc
[0],
1970 ctx
->Stencil
.ZPassFunc
[0]);
1972 r300UpdateCulling(ctx
);
1974 r300UpdateTextureState(ctx
);
1976 r300SetBlendState(ctx
);
1978 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1979 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1982 r300
->hw
.vap_cntl
.cmd
[1] = 0x0014045a;
1984 r300
->hw
.vap_cntl
.cmd
[1] = 0x0030045A; //0x0030065a /* Dangerous */
1986 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1987 | R300_VPORT_X_OFFSET_ENA
1988 | R300_VPORT_Y_SCALE_ENA
1989 | R300_VPORT_Y_OFFSET_ENA
1990 | R300_VPORT_Z_SCALE_ENA
1991 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
1992 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1994 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[1] = 0x00FFFFFF;
1995 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[2] = 0x00000000;
1997 #ifdef MESA_LITTLE_ENDIAN
1998 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
2000 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
2003 /* disable VAP/TCL on non-TCL capable chips */
2005 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
2007 r300
->hw
.vap_psc_sgn_norm_cntl
.cmd
[1] = 0xAAAAAAAA;
2009 /* XXX: Other families? */
2011 r300
->hw
.vap_clip_cntl
.cmd
[1] = R300_221C_NORMAL
;
2013 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
2014 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
2015 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
2016 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
2018 switch (r300
->radeon
.radeonScreen
->chip_family
) {
2019 case CHIP_FAMILY_R300
:
2020 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_R300
;
2023 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_RV350
;
2028 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
2029 | R300_GB_LINE_STUFF_ENABLE
2030 | R300_GB_TRIANGLE_STUFF_ENABLE
;
2032 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
2033 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
2035 /* XXX: Other families? */
2036 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
2037 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
;
2038 switch (r300
->radeon
.radeonScreen
->chip_family
) {
2039 case CHIP_FAMILY_R300
:
2040 case CHIP_FAMILY_R350
:
2041 case CHIP_FAMILY_RV410
:
2042 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2043 R300_GB_TILE_PIPE_COUNT_R300
;
2045 case CHIP_FAMILY_R420
:
2046 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2047 R300_GB_TILE_PIPE_COUNT_R420
;
2050 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
2051 R300_GB_TILE_DISABLE
; /* TODO: This disables tiling totally. I guess it happened accidentially. */
2055 /* XXX: set to 0 when fog is disabled? */
2056 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = R300_GB_FOG_SELECT_1_1_W
;
2058 /* XXX: Enable anti-aliasing? */
2059 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = GB_AA_CONFIG_AA_DISABLE
;
2061 r300
->hw
.ga_point_s0
.cmd
[1] = r300PackFloat32(0.0);
2062 r300
->hw
.ga_point_s0
.cmd
[2] = r300PackFloat32(0.0);
2063 r300
->hw
.ga_point_s0
.cmd
[3] = r300PackFloat32(1.0);
2064 r300
->hw
.ga_point_s0
.cmd
[4] = r300PackFloat32(1.0);
2066 r300
->hw
.ga_triangle_stipple
.cmd
[1] = 0x00050005;
2068 r300PointSize(ctx
, 1.0);
2070 r300
->hw
.ga_point_minmax
.cmd
[1] = 0x18000006;
2071 r300
->hw
.ga_point_minmax
.cmd
[2] = 0x00020006;
2072 r300
->hw
.ga_point_minmax
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
2074 r300LineWidth(ctx
, 1.0);
2076 r300
->hw
.ga_line_stipple
.cmd
[1] = 0;
2077 r300
->hw
.ga_line_stipple
.cmd
[2] = r300PackFloat32(0.0);
2078 r300
->hw
.ga_line_stipple
.cmd
[3] = r300PackFloat32(1.0);
2080 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
2082 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
2083 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
2084 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
2086 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
2087 ctx
->Polygon
.OffsetUnits
);
2088 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
2089 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
2090 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
2092 r300
->hw
.su_depth_scale
.cmd
[1] = 0x4B7FFFFF;
2093 r300
->hw
.su_depth_scale
.cmd
[2] = 0x00000000;
2095 r300
->hw
.sc_hyperz
.cmd
[1] = 0x0000001C;
2096 r300
->hw
.sc_hyperz
.cmd
[2] = 0x2DA49525;
2098 r300
->hw
.sc_screendoor
.cmd
[1] = 0x00FFFFFF;
2100 r300
->hw
.us_out_fmt
.cmd
[1] = 0x00001B01;
2101 r300
->hw
.us_out_fmt
.cmd
[2] = 0x00001B0F;
2102 r300
->hw
.us_out_fmt
.cmd
[3] = 0x00001B0F;
2103 r300
->hw
.us_out_fmt
.cmd
[4] = 0x00001B0F;
2104 r300
->hw
.us_out_fmt
.cmd
[5] = 0x00000001;
2106 r300Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
2107 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
2108 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
2109 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
2110 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
2111 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
2112 r300Fogfv(ctx
, GL_FOG_COORDINATE_SOURCE_EXT
, NULL
);
2114 r300
->hw
.fg_depth_src
.cmd
[1] = 0;
2116 r300
->hw
.rb3d_cctl
.cmd
[1] = 0;
2118 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
2120 /* Again, r300ClearBuffer uses this */
2121 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] =
2122 r300
->radeon
.state
.color
.drawOffset
+
2123 r300
->radeon
.radeonScreen
->fbLocation
;
2124 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.state
.color
.drawPitch
;
2126 if (r300
->radeon
.radeonScreen
->cpp
== 4)
2127 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
2129 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
2131 if (r300
->radeon
.sarea
->tiling_enabled
)
2132 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
2134 r300
->hw
.rb3d_dither_ctl
.cmd
[1] = 0;
2135 r300
->hw
.rb3d_dither_ctl
.cmd
[2] = 0;
2136 r300
->hw
.rb3d_dither_ctl
.cmd
[3] = 0;
2137 r300
->hw
.rb3d_dither_ctl
.cmd
[4] = 0;
2138 r300
->hw
.rb3d_dither_ctl
.cmd
[5] = 0;
2139 r300
->hw
.rb3d_dither_ctl
.cmd
[6] = 0;
2140 r300
->hw
.rb3d_dither_ctl
.cmd
[7] = 0;
2141 r300
->hw
.rb3d_dither_ctl
.cmd
[8] = 0;
2142 r300
->hw
.rb3d_dither_ctl
.cmd
[9] = 0;
2144 r300
->hw
.rb3d_aaresolve_ctl
.cmd
[1] = 0;
2146 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[1] = 0x00000000;
2147 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[2] = 0xffffffff;
2149 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
2150 r300
->radeon
.radeonScreen
->depthOffset
+
2151 r300
->radeon
.radeonScreen
->fbLocation
;
2152 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
2154 if (r300
->radeon
.sarea
->tiling_enabled
) {
2155 /* XXX: Turn off when clearing buffers ? */
2156 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= ZB_DEPTHPITCH_DEPTHMACROTILE_ENABLE
;
2158 if (ctx
->Visual
.depthBits
== 24)
2159 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |=
2160 ZB_DEPTHPITCH_DEPTHMICROTILE_TILED
;
2163 r300
->hw
.zb_depthclearvalue
.cmd
[1] = 0;
2165 r300
->hw
.unk4F30
.cmd
[1] = 0;
2166 r300
->hw
.unk4F30
.cmd
[2] = 0;
2168 r300
->hw
.zb_hiz_offset
.cmd
[1] = 0;
2170 r300
->hw
.zb_hiz_pitch
.cmd
[1] = 0;
2173 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
2174 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
2175 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
2176 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
2179 r300
->hw
.all_dirty
= GL_TRUE
;
2182 void r300UpdateShaders(r300ContextPtr rmesa
)
2185 struct r300_vertex_program
*vp
;
2188 ctx
= rmesa
->radeon
.glCtx
;
2190 if (rmesa
->NewGLState
&& hw_tcl_on
) {
2191 rmesa
->NewGLState
= 0;
2193 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2194 rmesa
->temp_attrib
[i
] =
2195 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
2196 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2197 &rmesa
->dummy_attrib
[i
];
2200 _tnl_UpdateFixedFunctionProgram(ctx
);
2202 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2203 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2204 rmesa
->temp_attrib
[i
];
2207 r300SelectVertexShader(rmesa
);
2208 vp
= (struct r300_vertex_program
*)
2209 CURRENT_VERTEX_SHADER(ctx
);
2210 /*if (vp->translated == GL_FALSE)
2211 r300TranslateVertexShader(vp); */
2212 if (vp
->translated
== GL_FALSE
) {
2213 fprintf(stderr
, "Failing back to sw-tcl\n");
2214 hw_tcl_on
= future_hw_tcl_on
= 0;
2215 r300ResetHwState(rmesa
);
2219 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
);
2223 static void r300SetupPixelShader(r300ContextPtr rmesa
)
2225 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2226 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2227 (char *)ctx
->FragmentProgram
._Current
;
2230 if (!fp
) /* should only happenen once, just after context is created */
2233 r300TranslateFragmentShader(rmesa
, fp
);
2234 if (!fp
->translated
) {
2235 fprintf(stderr
, "%s: No valid fragment shader, exiting\n",
2240 R300_STATECHANGE(rmesa
, fpi
[0]);
2241 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR0_0
, fp
->alu_end
+ 1);
2242 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2243 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst0
;
2246 R300_STATECHANGE(rmesa
, fpi
[1]);
2247 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR1_0
, fp
->alu_end
+ 1);
2248 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2249 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst1
;
2252 R300_STATECHANGE(rmesa
, fpi
[2]);
2253 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR2_0
, fp
->alu_end
+ 1);
2254 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2255 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst2
;
2258 R300_STATECHANGE(rmesa
, fpi
[3]);
2259 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR3_0
, fp
->alu_end
+ 1);
2260 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2261 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst3
;
2264 R300_STATECHANGE(rmesa
, fp
);
2265 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = fp
->cur_node
| (fp
->first_node_has_tex
<< 3);
2266 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = fp
->max_temp_idx
;
2267 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] =
2268 (fp
->alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
) |
2269 (fp
->alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
) |
2270 (fp
->tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
) |
2271 (fp
->tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
2272 /* I just want to say, the way these nodes are stored.. weird.. */
2273 for (i
= 0, k
= (4 - (fp
->cur_node
+ 1)); i
< 4; i
++, k
++) {
2274 if (i
< (fp
->cur_node
+ 1)) {
2275 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ k
] =
2276 (fp
->node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
) |
2277 (fp
->node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
) |
2278 (fp
->node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
) |
2279 (fp
->node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
) |
2282 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ (3 - i
)] = 0;
2286 R300_STATECHANGE(rmesa
, fpp
);
2287 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(R300_PFS_PARAM_0_X
, fp
->const_nr
* 4);
2288 for (i
= 0; i
< fp
->const_nr
; i
++) {
2289 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(fp
->constant
[i
][0]);
2290 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(fp
->constant
[i
][1]);
2291 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(fp
->constant
[i
][2]);
2292 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(fp
->constant
[i
][3]);
2296 static void r500SetupPixelShader(r300ContextPtr rmesa
)
2298 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2299 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2300 (char *)ctx
->FragmentProgram
._Current
;
2303 if (!fp
) /* should only happenen once, just after context is created */
2306 /* emit the standard zero shader */
2307 R300_STATECHANGE(rmesa
, r500fp
);
2309 rmesa
->hw
.r500fp
.cmd
[i
++] = 0x7807;
2310 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_TEX_ID(0) | R500_TEX_INST_LD
| R500_TEX_SEM_ACQUIRE
| R500_TEX_IGNORE_UNCOVERED
;
2311 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_TEX_SRC_ADDR(0) | R500_TEX_SRC_S_SWIZ_R
|
2312 R500_TEX_SRC_T_SWIZ_G
|
2313 R500_TEX_DST_ADDR(0) |
2314 R500_TEX_DST_R_SWIZ_R
|
2315 R500_TEX_DST_G_SWIZ_G
|
2316 R500_TEX_DST_B_SWIZ_B
|
2317 R500_TEX_DST_A_SWIZ_A
;
2318 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_DX_ADDR(0) |
2328 rmesa
->hw
.r500fp
.cmd
[i
++] = 0x0;
2329 rmesa
->hw
.r500fp
.cmd
[i
++] = 0x0;
2331 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_INST_TYPE_OUT
|
2332 R500_INST_TEX_SEM_WAIT
|
2334 R500_INST_RGB_OMASK_R
|
2335 R500_INST_RGB_OMASK_G
|
2336 R500_INST_RGB_OMASK_B
|
2337 R500_INST_ALPHA_OMASK
;
2339 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_RGB_ADDR0(0) |
2341 R500_RGB_ADDR1_CONST
|
2343 R500_RGB_ADDR2_CONST
|
2344 R500_RGB_SRCP_OP_1_MINUS_2RGB0
;
2345 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALPHA_ADDR0(0) |
2346 R500_ALPHA_ADDR1(0) |
2347 R500_ALPHA_ADDR1_CONST
|
2348 R500_ALPHA_ADDR2(0) |
2349 R500_ALPHA_ADDR2_CONST
|
2350 R500_ALPHA_SRCP_OP_1_MINUS_2A0
;
2351 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALU_RGB_SEL_A_SRC0
|
2352 R500_ALU_RGB_R_SWIZ_A_R
|
2353 R500_ALU_RGB_G_SWIZ_A_G
|
2354 R500_ALU_RGB_B_SWIZ_A_B
|
2355 R500_ALU_RGB_SEL_B_SRC0
|
2356 R500_ALU_RGB_R_SWIZ_B_1
|
2357 R500_ALU_RGB_B_SWIZ_B_1
|
2358 R500_ALU_RGB_G_SWIZ_B_1
;
2359 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALPHA_OP_MAD
|
2360 R500_ALPHA_SWIZ_A_A
|
2361 R500_ALPHA_SWIZ_B_1
;
2362 rmesa
->hw
.r500fp
.cmd
[i
++] = R500_ALU_RGBA_OP_MAD
|
2363 R500_ALU_RGBA_R_SWIZ_0
|
2364 R500_ALU_RGBA_G_SWIZ_0
|
2365 R500_ALU_RGBA_B_SWIZ_0
|
2366 R500_ALU_RGBA_A_SWIZ_0
;
2371 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2374 ctx
= rmesa
->radeon
.glCtx
;
2376 r300UpdateTextureState(ctx
);
2378 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
2379 r500SetupPixelShader(rmesa
);
2381 r300SetupPixelShader(rmesa
);
2382 r300SetupTextures(ctx
);
2384 if ((rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
2385 r300SetupVertexProgram(rmesa
);
2387 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
2388 r500SetupRSUnit(ctx
);
2390 r300SetupRSUnit(ctx
);
2394 * Called by Mesa after an internal state update.
2396 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2398 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2400 _swrast_InvalidateState(ctx
, new_state
);
2401 _swsetup_InvalidateState(ctx
, new_state
);
2402 _vbo_InvalidateState(ctx
, new_state
);
2403 _tnl_InvalidateState(ctx
, new_state
);
2404 _ae_invalidate_state(ctx
, new_state
);
2406 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
2407 r300UpdateDrawBuffer(ctx
);
2410 r300UpdateStateParameters(ctx
, new_state
);
2412 r300
->NewGLState
|= new_state
;
2416 * Calculate initial hardware state and register state functions.
2417 * Assumes that the command buffer and state atoms have been
2418 * initialized already.
2420 void r300InitState(r300ContextPtr r300
)
2422 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2425 radeonInitState(&r300
->radeon
);
2427 switch (ctx
->Visual
.depthBits
) {
2429 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2430 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_16BIT_INT_Z
;
2431 r300
->state
.stencil
.clear
= 0x00000000;
2434 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2435 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_24BIT_INT_Z
;
2436 r300
->state
.stencil
.clear
= 0x00ff0000;
2439 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2440 ctx
->Visual
.depthBits
);
2444 /* Only have hw stencil when depth buffer is 24 bits deep */
2445 r300
->state
.stencil
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2446 ctx
->Visual
.depthBits
== 24);
2448 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2450 r300ResetHwState(r300
);
2453 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2455 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2460 void r300UpdateClipPlanes( GLcontext
*ctx
)
2462 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2465 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
2466 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
2467 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
2469 R300_STATECHANGE( rmesa
, vpucp
[p
] );
2470 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
2471 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
2472 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
2473 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
2479 * Initialize driver's state callback functions
2481 void r300InitStateFuncs(struct dd_function_table
*functions
)
2483 radeonInitStateFuncs(functions
);
2485 functions
->UpdateState
= r300InvalidateState
;
2486 functions
->AlphaFunc
= r300AlphaFunc
;
2487 functions
->BlendColor
= r300BlendColor
;
2488 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2489 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2490 functions
->Enable
= r300Enable
;
2491 functions
->ColorMask
= r300ColorMask
;
2492 functions
->DepthFunc
= r300DepthFunc
;
2493 functions
->DepthMask
= r300DepthMask
;
2494 functions
->CullFace
= r300CullFace
;
2495 functions
->Fogfv
= r300Fogfv
;
2496 functions
->FrontFace
= r300FrontFace
;
2497 functions
->ShadeModel
= r300ShadeModel
;
2499 /* Stencil related */
2500 functions
->ClearStencil
= r300ClearStencil
;
2501 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2502 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2503 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2505 /* Viewport related */
2506 functions
->Viewport
= r300Viewport
;
2507 functions
->DepthRange
= r300DepthRange
;
2508 functions
->PointSize
= r300PointSize
;
2509 functions
->LineWidth
= r300LineWidth
;
2511 functions
->PolygonOffset
= r300PolygonOffset
;
2512 functions
->PolygonMode
= r300PolygonMode
;
2514 functions
->RenderMode
= r300RenderMode
;
2516 functions
->ClipPlane
= r300ClipPlane
;