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 #define bump_vpu_count(ptr, new_count) do{\
1607 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1608 int _nc=(new_count)/4; \
1609 assert(_nc < 256); \
1610 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1613 static inline void r300SetupVertexProgramFragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1617 if (vsf
->length
== 0)
1620 if (vsf
->length
& 0x3) {
1621 fprintf(stderr
, "VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1625 switch ((dest
>> 8) & 0xf) {
1627 R300_STATECHANGE(r300
, vpi
);
1628 for (i
= 0; i
< vsf
->length
; i
++)
1629 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1630 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1634 R300_STATECHANGE(r300
, vpp
);
1635 for (i
= 0; i
< vsf
->length
; i
++)
1636 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1637 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1640 R300_STATECHANGE(r300
, vps
);
1641 for (i
= 0; i
< vsf
->length
; i
++)
1642 r300
->hw
.vps
.cmd
[1 + i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1643 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1646 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1651 /* FIXME: move near the MIN2 define. */
1652 #define MIN3(a, b, c) ((a) < (b) ? MIN2(a, c) : MIN2(b, c))
1654 /* FIXME: need to add a structure for per-card/chipset values; they are
1655 * currently hard-coded. */
1656 static void r300VapCntl(r300ContextPtr rmesa
, GLuint input_count
,
1657 GLuint output_count
, GLuint temp_count
)
1659 int cmd_reserved
= 0;
1660 int cmd_written
= 0;
1661 drm_radeon_cmd_header_t
*cmd
= NULL
;
1663 int vtx_mem_size
= 72; /* FIXME: R3XX vs R5XX */
1665 /* Flush PVS engine before changing PVS_NUM_SLOTS, PVS_NUM_CNTRLS.
1666 * See r500 docs 6.5.2 */
1667 reg_start(R300_VAP_PVS_WAITIDLE
, 0);
1670 /* avoid division by zero */
1671 if (input_count
== 0)
1673 if (output_count
== 0)
1675 if (temp_count
== 0)
1679 MIN3(10, vtx_mem_size
/ input_count
, vtx_mem_size
/ output_count
);
1680 int pvs_num_cntrls
= MIN2(6, vtx_mem_size
/ temp_count
);
1682 R300_STATECHANGE(rmesa
, vap_cntl
);
1683 rmesa
->hw
.vap_cntl
.cmd
[1] =
1684 (pvs_num_slots
<< R300_VAP_CNTL__PVS_NUM_SLOTS__SHIFT
) |
1685 (pvs_num_cntrls
<< R300_VAP_CNTL__PVS_NUM_CNTRLS__SHIFT
) |
1686 (4 << R300_VAP_CNTL__PVS_NUM_FPUS__SHIFT
) |
1687 (12 << R300_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT
) |
1688 R500_VAP_CNTL__TCL_STATE_OPTIMIZATION
;
1691 static void r300SetupDefaultVertexProgram(r300ContextPtr rmesa
)
1693 struct r300_vertex_shader_state
*prog
= &(rmesa
->state
.vertex_shader
);
1698 int param_count
= 0;
1699 int program_end
= 0;
1701 for (i
= VERT_ATTRIB_POS
; i
< VERT_ATTRIB_MAX
; i
++) {
1702 if (rmesa
->state
.sw_tcl_inputs
[i
] != -1) {
1703 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
);
1704 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
);
1705 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
);
1706 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
);
1712 prog
->program
.length
= program_end
;
1714 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
,
1716 inst_count
= (prog
->program
.length
/ 4) - 1;
1718 r300VapCntl(rmesa
, i_reg
, o_reg
, 0);
1720 R300_STATECHANGE(rmesa
, pvs
);
1721 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1722 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1723 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1724 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1725 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1726 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1727 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1728 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1729 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1730 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1733 static int r300BitCount(int x
)
1735 x
= ((x
& 0xaaaaaaaaU
) >> 1) + (x
& 0x55555555U
);
1736 x
= ((x
& 0xccccccccU
) >> 2) + (x
& 0x33333333U
);
1737 x
= (x
>> 16) + (x
& 0xffff);
1738 x
= ((x
& 0xf0f0) >> 4) + (x
& 0x0f0f);
1739 return (x
>> 8) + (x
& 0x00ff);
1742 static void r300SetupRealVertexProgram(r300ContextPtr rmesa
)
1744 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1745 struct r300_vertex_program
*prog
= (struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
1747 int param_count
= 0;
1749 /* FIXME: r300SetupVertexProgramFragment */
1750 R300_STATECHANGE(rmesa
, vpp
);
1752 r300VertexProgUpdateParams(ctx
,
1753 (struct r300_vertex_program_cont
*)
1754 ctx
->VertexProgram
._Current
,
1755 (float *)&rmesa
->hw
.vpp
.
1756 cmd
[R300_VPP_PARAM_0
]);
1757 bump_vpu_count(rmesa
->hw
.vpp
.cmd
, param_count
);
1760 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
, &(prog
->program
));
1761 inst_count
= (prog
->program
.length
/ 4) - 1;
1763 r300VapCntl(rmesa
, r300BitCount(prog
->key
.InputsRead
),
1764 r300BitCount(prog
->key
.OutputsWritten
),
1765 prog
->num_temporaries
);
1767 R300_STATECHANGE(rmesa
, pvs
);
1768 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1769 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1770 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1771 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1772 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1773 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1774 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1775 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1776 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1777 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1780 static void r300SetupVertexProgram(r300ContextPtr rmesa
)
1782 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1784 /* Reset state, in case we don't use something */
1785 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1786 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1787 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1789 /* Not sure why this doesnt work...
1790 0x400 area might have something to do with pixel shaders as it appears right after pfs programming.
1791 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. */
1792 //setup_vertex_shader_fragment(rmesa, 0x406, &unk4);
1793 if (hw_tcl_on
&& ((struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
))->translated
) {
1794 r300SetupRealVertexProgram(rmesa
);
1796 /* FIXME: This needs to be replaced by vertex shader generation code. */
1797 r300SetupDefaultVertexProgram(rmesa
);
1803 * Enable/Disable states.
1805 * \note Mesa already filters redundant calls to this function.
1807 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1809 if (RADEON_DEBUG
& DEBUG_STATE
)
1810 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1811 _mesa_lookup_enum_by_nr(cap
),
1812 state
? "GL_TRUE" : "GL_FALSE");
1821 r300SetFogState(ctx
, state
);
1824 r300SetAlphaState(ctx
);
1827 case GL_COLOR_LOGIC_OP
:
1828 r300SetBlendState(ctx
);
1830 case GL_CLIP_PLANE0
:
1831 case GL_CLIP_PLANE1
:
1832 case GL_CLIP_PLANE2
:
1833 case GL_CLIP_PLANE3
:
1834 case GL_CLIP_PLANE4
:
1835 case GL_CLIP_PLANE5
:
1836 r300SetClipPlaneState(ctx
, cap
, state
);
1839 r300SetDepthState(ctx
);
1841 case GL_STENCIL_TEST
:
1842 r300SetStencilState(ctx
, state
);
1845 r300UpdateCulling(ctx
);
1847 case GL_POLYGON_OFFSET_POINT
:
1848 case GL_POLYGON_OFFSET_LINE
:
1849 case GL_POLYGON_OFFSET_FILL
:
1850 r300SetPolygonOffsetState(ctx
, state
);
1853 radeonEnable(ctx
, cap
, state
);
1859 * Completely recalculates hardware state based on the Mesa state.
1861 static void r300ResetHwState(r300ContextPtr r300
)
1863 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1866 if (!(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
1869 if (RADEON_DEBUG
& DEBUG_STATE
)
1870 fprintf(stderr
, "%s\n", __FUNCTION__
);
1872 r300UpdateWindow(ctx
);
1875 ctx
->Color
.ColorMask
[RCOMP
],
1876 ctx
->Color
.ColorMask
[GCOMP
],
1877 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1879 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1880 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1881 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1884 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
1885 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1886 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1887 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1888 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1889 ctx
->Stencil
.ZFailFunc
[0],
1890 ctx
->Stencil
.ZPassFunc
[0]);
1892 r300UpdateCulling(ctx
);
1894 r300UpdateTextureState(ctx
);
1896 r300SetBlendState(ctx
);
1898 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1899 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1901 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1902 | R300_VPORT_X_OFFSET_ENA
1903 | R300_VPORT_Y_SCALE_ENA
1904 | R300_VPORT_Y_OFFSET_ENA
1905 | R300_VPORT_Z_SCALE_ENA
1906 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
1907 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1909 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[1] = 0x00FFFFFF;
1910 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[2] = 0x00000000;
1912 #ifdef MESA_LITTLE_ENDIAN
1913 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
1915 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
1918 /* disable VAP/TCL on non-TCL capable chips */
1920 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
1922 r300
->hw
.vap_psc_sgn_norm_cntl
.cmd
[1] = 0xAAAAAAAA;
1924 /* XXX: Other families? */
1926 r300
->hw
.vap_clip_cntl
.cmd
[1] = R300_221C_NORMAL
;
1928 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
1929 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
1930 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
1931 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
1933 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1934 case CHIP_FAMILY_R300
:
1935 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_R300
;
1938 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_RV350
;
1943 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
1944 | R300_GB_LINE_STUFF_ENABLE
1945 | R300_GB_TRIANGLE_STUFF_ENABLE
;
1947 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
1948 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
1950 /* XXX: Other families? */
1951 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
1952 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
;
1953 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1954 case CHIP_FAMILY_R300
:
1955 case CHIP_FAMILY_R350
:
1956 case CHIP_FAMILY_RV410
:
1957 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1958 R300_GB_TILE_PIPE_COUNT_R300
;
1960 case CHIP_FAMILY_R420
:
1961 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1962 R300_GB_TILE_PIPE_COUNT_R420
;
1965 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1966 R300_GB_TILE_DISABLE
; /* TODO: This disables tiling totally. I guess it happened accidentially. */
1970 /* XXX: set to 0 when fog is disabled? */
1971 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = R300_GB_FOG_SELECT_1_1_W
;
1973 /* XXX: Enable anti-aliasing? */
1974 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = GB_AA_CONFIG_AA_DISABLE
;
1976 r300
->hw
.ga_point_s0
.cmd
[1] = r300PackFloat32(0.0);
1977 r300
->hw
.ga_point_s0
.cmd
[2] = r300PackFloat32(0.0);
1978 r300
->hw
.ga_point_s0
.cmd
[3] = r300PackFloat32(1.0);
1979 r300
->hw
.ga_point_s0
.cmd
[4] = r300PackFloat32(1.0);
1981 r300
->hw
.ga_triangle_stipple
.cmd
[1] = 0x00050005;
1983 r300PointSize(ctx
, 1.0);
1985 r300
->hw
.ga_point_minmax
.cmd
[1] = 0x18000006;
1986 r300
->hw
.ga_point_minmax
.cmd
[2] = 0x00020006;
1987 r300
->hw
.ga_point_minmax
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
1989 r300LineWidth(ctx
, 1.0);
1991 r300
->hw
.ga_line_stipple
.cmd
[1] = 0;
1992 r300
->hw
.ga_line_stipple
.cmd
[2] = r300PackFloat32(0.0);
1993 r300
->hw
.ga_line_stipple
.cmd
[3] = r300PackFloat32(1.0);
1995 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
1997 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
1998 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
1999 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
2001 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
2002 ctx
->Polygon
.OffsetUnits
);
2003 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
2004 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
2005 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
2007 r300
->hw
.su_depth_scale
.cmd
[1] = 0x4B7FFFFF;
2008 r300
->hw
.su_depth_scale
.cmd
[2] = 0x00000000;
2010 r300
->hw
.sc_hyperz
.cmd
[1] = 0x0000001C;
2011 r300
->hw
.sc_hyperz
.cmd
[2] = 0x2DA49525;
2013 r300
->hw
.sc_screendoor
.cmd
[1] = 0x00FFFFFF;
2015 r300
->hw
.us_out_fmt
.cmd
[1] = 0x00001B01;
2016 r300
->hw
.us_out_fmt
.cmd
[2] = 0x00001B0F;
2017 r300
->hw
.us_out_fmt
.cmd
[3] = 0x00001B0F;
2018 r300
->hw
.us_out_fmt
.cmd
[4] = 0x00001B0F;
2019 r300
->hw
.us_out_fmt
.cmd
[5] = 0x00000001;
2021 r300Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
2022 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
2023 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
2024 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
2025 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
2026 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
2027 r300Fogfv(ctx
, GL_FOG_COORDINATE_SOURCE_EXT
, NULL
);
2029 r300
->hw
.fg_depth_src
.cmd
[1] = 0;
2031 r300
->hw
.rb3d_cctl
.cmd
[1] = 0;
2033 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
2035 /* Again, r300ClearBuffer uses this */
2036 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] =
2037 r300
->radeon
.state
.color
.drawOffset
+
2038 r300
->radeon
.radeonScreen
->fbLocation
;
2039 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.state
.color
.drawPitch
;
2041 if (r300
->radeon
.radeonScreen
->cpp
== 4)
2042 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
2044 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
2046 if (r300
->radeon
.sarea
->tiling_enabled
)
2047 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
2049 r300
->hw
.rb3d_dither_ctl
.cmd
[1] = 0;
2050 r300
->hw
.rb3d_dither_ctl
.cmd
[2] = 0;
2051 r300
->hw
.rb3d_dither_ctl
.cmd
[3] = 0;
2052 r300
->hw
.rb3d_dither_ctl
.cmd
[4] = 0;
2053 r300
->hw
.rb3d_dither_ctl
.cmd
[5] = 0;
2054 r300
->hw
.rb3d_dither_ctl
.cmd
[6] = 0;
2055 r300
->hw
.rb3d_dither_ctl
.cmd
[7] = 0;
2056 r300
->hw
.rb3d_dither_ctl
.cmd
[8] = 0;
2057 r300
->hw
.rb3d_dither_ctl
.cmd
[9] = 0;
2059 r300
->hw
.rb3d_aaresolve_ctl
.cmd
[1] = 0;
2061 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[1] = 0x00000000;
2062 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[2] = 0xffffffff;
2064 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
2065 r300
->radeon
.radeonScreen
->depthOffset
+
2066 r300
->radeon
.radeonScreen
->fbLocation
;
2067 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
2069 if (r300
->radeon
.sarea
->tiling_enabled
) {
2070 /* XXX: Turn off when clearing buffers ? */
2071 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= ZB_DEPTHPITCH_DEPTHMACROTILE_ENABLE
;
2073 if (ctx
->Visual
.depthBits
== 24)
2074 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |=
2075 ZB_DEPTHPITCH_DEPTHMICROTILE_TILED
;
2078 r300
->hw
.zb_depthclearvalue
.cmd
[1] = 0;
2080 r300
->hw
.unk4F30
.cmd
[1] = 0;
2081 r300
->hw
.unk4F30
.cmd
[2] = 0;
2083 r300
->hw
.zb_hiz_offset
.cmd
[1] = 0;
2085 r300
->hw
.zb_hiz_pitch
.cmd
[1] = 0;
2088 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
2089 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
2090 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
2091 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
2094 r300
->hw
.all_dirty
= GL_TRUE
;
2097 void r300UpdateShaders(r300ContextPtr rmesa
)
2100 struct r300_vertex_program
*vp
;
2103 ctx
= rmesa
->radeon
.glCtx
;
2105 if (rmesa
->NewGLState
&& hw_tcl_on
) {
2106 rmesa
->NewGLState
= 0;
2108 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2109 rmesa
->temp_attrib
[i
] =
2110 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
2111 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2112 &rmesa
->dummy_attrib
[i
];
2115 _tnl_UpdateFixedFunctionProgram(ctx
);
2117 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2118 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2119 rmesa
->temp_attrib
[i
];
2122 r300SelectVertexShader(rmesa
);
2123 vp
= (struct r300_vertex_program
*)
2124 CURRENT_VERTEX_SHADER(ctx
);
2125 /*if (vp->translated == GL_FALSE)
2126 r300TranslateVertexShader(vp); */
2127 if (vp
->translated
== GL_FALSE
) {
2128 fprintf(stderr
, "Failing back to sw-tcl\n");
2129 hw_tcl_on
= future_hw_tcl_on
= 0;
2130 r300ResetHwState(rmesa
);
2132 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
);
2136 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
);
2139 static void r300SetupPixelShader(r300ContextPtr rmesa
)
2141 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2142 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2143 (char *)ctx
->FragmentProgram
._Current
;
2146 if (!fp
) /* should only happenen once, just after context is created */
2149 r300TranslateFragmentShader(rmesa
, fp
);
2150 if (!fp
->translated
) {
2151 fprintf(stderr
, "%s: No valid fragment shader, exiting\n",
2156 R300_STATECHANGE(rmesa
, fpi
[0]);
2157 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR0_0
, fp
->alu_end
+ 1);
2158 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2159 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst0
;
2162 R300_STATECHANGE(rmesa
, fpi
[1]);
2163 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR1_0
, fp
->alu_end
+ 1);
2164 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2165 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst1
;
2168 R300_STATECHANGE(rmesa
, fpi
[2]);
2169 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR2_0
, fp
->alu_end
+ 1);
2170 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2171 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst2
;
2174 R300_STATECHANGE(rmesa
, fpi
[3]);
2175 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR3_0
, fp
->alu_end
+ 1);
2176 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2177 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst3
;
2180 R300_STATECHANGE(rmesa
, fp
);
2181 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = fp
->cur_node
| (fp
->first_node_has_tex
<< 3);
2182 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = fp
->max_temp_idx
;
2183 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] =
2184 (fp
->alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
) |
2185 (fp
->alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
) |
2186 (fp
->tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
) |
2187 (fp
->tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
2188 /* I just want to say, the way these nodes are stored.. weird.. */
2189 for (i
= 0, k
= (4 - (fp
->cur_node
+ 1)); i
< 4; i
++, k
++) {
2190 if (i
< (fp
->cur_node
+ 1)) {
2191 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ k
] =
2192 (fp
->node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
) |
2193 (fp
->node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
) |
2194 (fp
->node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
) |
2195 (fp
->node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
) |
2198 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ (3 - i
)] = 0;
2202 R300_STATECHANGE(rmesa
, fpp
);
2203 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(R300_PFS_PARAM_0_X
, fp
->const_nr
* 4);
2204 for (i
= 0; i
< fp
->const_nr
; i
++) {
2205 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(fp
->constant
[i
][0]);
2206 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(fp
->constant
[i
][1]);
2207 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(fp
->constant
[i
][2]);
2208 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(fp
->constant
[i
][3]);
2212 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2215 ctx
= rmesa
->radeon
.glCtx
;
2217 r300UpdateTextureState(ctx
);
2219 r300SetupPixelShader(rmesa
);
2220 r300SetupTextures(ctx
);
2222 if ((rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
2223 r300SetupVertexProgram(rmesa
);
2224 r300SetupRSUnit(ctx
);
2228 * Called by Mesa after an internal state update.
2230 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2232 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2234 _swrast_InvalidateState(ctx
, new_state
);
2235 _swsetup_InvalidateState(ctx
, new_state
);
2236 _vbo_InvalidateState(ctx
, new_state
);
2237 _tnl_InvalidateState(ctx
, new_state
);
2238 _ae_invalidate_state(ctx
, new_state
);
2240 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
2241 r300UpdateDrawBuffer(ctx
);
2244 r300UpdateStateParameters(ctx
, new_state
);
2246 r300
->NewGLState
|= new_state
;
2250 * Calculate initial hardware state and register state functions.
2251 * Assumes that the command buffer and state atoms have been
2252 * initialized already.
2254 void r300InitState(r300ContextPtr r300
)
2256 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2259 radeonInitState(&r300
->radeon
);
2261 switch (ctx
->Visual
.depthBits
) {
2263 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2264 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_16BIT_INT_Z
;
2265 r300
->state
.stencil
.clear
= 0x00000000;
2268 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2269 depth_fmt
= ZB_FORMAR_DEPTHFORMAT_24BIT_INT_Z
;
2270 r300
->state
.stencil
.clear
= 0x00ff0000;
2273 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2274 ctx
->Visual
.depthBits
);
2278 /* Only have hw stencil when depth buffer is 24 bits deep */
2279 r300
->state
.stencil
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2280 ctx
->Visual
.depthBits
== 24);
2282 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2284 r300ResetHwState(r300
);
2287 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2289 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2294 void r300UpdateClipPlanes( GLcontext
*ctx
)
2296 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2299 for (p
= 0; p
< ctx
->Const
.MaxClipPlanes
; p
++) {
2300 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << p
)) {
2301 GLint
*ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
2303 R300_STATECHANGE( rmesa
, vpucp
[p
] );
2304 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
2305 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
2306 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
2307 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
2313 * Initialize driver's state callback functions
2315 void r300InitStateFuncs(struct dd_function_table
*functions
)
2317 radeonInitStateFuncs(functions
);
2319 functions
->UpdateState
= r300InvalidateState
;
2320 functions
->AlphaFunc
= r300AlphaFunc
;
2321 functions
->BlendColor
= r300BlendColor
;
2322 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2323 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2324 functions
->Enable
= r300Enable
;
2325 functions
->ColorMask
= r300ColorMask
;
2326 functions
->DepthFunc
= r300DepthFunc
;
2327 functions
->DepthMask
= r300DepthMask
;
2328 functions
->CullFace
= r300CullFace
;
2329 functions
->Fogfv
= r300Fogfv
;
2330 functions
->FrontFace
= r300FrontFace
;
2331 functions
->ShadeModel
= r300ShadeModel
;
2333 /* Stencil related */
2334 functions
->ClearStencil
= r300ClearStencil
;
2335 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2336 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2337 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2339 /* Viewport related */
2340 functions
->Viewport
= r300Viewport
;
2341 functions
->DepthRange
= r300DepthRange
;
2342 functions
->PointSize
= r300PointSize
;
2343 functions
->LineWidth
= r300LineWidth
;
2345 functions
->PolygonOffset
= r300PolygonOffset
;
2346 functions
->PolygonMode
= r300PolygonMode
;
2348 functions
->RenderMode
= r300RenderMode
;
2350 functions
->ClipPlane
= r300ClipPlane
;