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 **************************************************************************/
34 * Nicolai Haehnle <prefect_@gmx.net>
44 #include "simple_list.h"
46 #include "api_arrayelt.h"
47 #include "swrast/swrast.h"
48 #include "swrast_setup/swrast_setup.h"
49 #include "array_cache/acache.h"
51 #include "texformat.h"
53 #include "radeon_ioctl.h"
54 #include "radeon_state.h"
55 #include "r300_context.h"
56 #include "r300_ioctl.h"
57 #include "r300_state.h"
59 #include "r300_program.h"
60 #include "r300_emit.h"
61 #include "r300_fixed_pipelines.h"
64 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
66 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
67 int pp_misc
= rmesa
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
];
70 CLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
72 R300_STATECHANGE(rmesa
, at
);
74 pp_misc
&= ~(R300_ALPHA_TEST_OP_MASK
| R300_REF_ALPHA_MASK
);
75 pp_misc
|= (refByte
& R300_REF_ALPHA_MASK
);
79 pp_misc
|= R300_ALPHA_TEST_FAIL
;
82 pp_misc
|= R300_ALPHA_TEST_LESS
;
85 pp_misc
|= R300_ALPHA_TEST_EQUAL
;
88 pp_misc
|= R300_ALPHA_TEST_LEQUAL
;
91 pp_misc
|= R300_ALPHA_TEST_GREATER
;
94 pp_misc
|= R300_ALPHA_TEST_NEQUAL
;
97 pp_misc
|= R300_ALPHA_TEST_GEQUAL
;
100 pp_misc
|= R300_ALPHA_TEST_PASS
;
101 //pp_misc &= ~R300_ALPHA_TEST_ENABLE;
105 rmesa
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
108 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
111 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
113 R300_STATECHANGE(rmesa
, unk4E10
);
115 /* Ordering might be wrong */
116 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
117 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
118 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
119 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
121 rmesa
->hw
.unk4E10
.cmd
[1]=radeonPackColor(4, color
[0], color
[1], color
[2], color
[3]);
122 //fprintf(stderr, "%s:%s is not implemented yet. Fixme !\n", __FILE__, __FUNCTION__);
124 R200_STATECHANGE(rmesa
, ctx
);
125 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
126 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
127 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
128 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
129 if (rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
)
130 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCOLOR
] =
131 radeonPackColor(4, color
[0], color
[1], color
[2], color
[3]);
136 * Calculate the hardware blend factor setting. This same function is used
137 * for source and destination of both alpha and RGB.
140 * The hardware register value for the specified blend factor. This value
141 * will need to be shifted into the correct position for either source or
142 * destination factor.
145 * Since the two cases where source and destination are handled differently
146 * are essentially error cases, they should never happen. Determine if these
147 * cases can be removed.
149 static int blend_factor(GLenum factor
, GLboolean is_src
)
155 func
= R200_BLEND_GL_ZERO
;
158 func
= R200_BLEND_GL_ONE
;
161 func
= R200_BLEND_GL_DST_COLOR
;
163 case GL_ONE_MINUS_DST_COLOR
:
164 func
= R200_BLEND_GL_ONE_MINUS_DST_COLOR
;
167 func
= R200_BLEND_GL_SRC_COLOR
;
169 case GL_ONE_MINUS_SRC_COLOR
:
170 func
= R200_BLEND_GL_ONE_MINUS_SRC_COLOR
;
173 func
= R200_BLEND_GL_SRC_ALPHA
;
175 case GL_ONE_MINUS_SRC_ALPHA
:
176 func
= R200_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
179 func
= R200_BLEND_GL_DST_ALPHA
;
181 case GL_ONE_MINUS_DST_ALPHA
:
182 func
= R200_BLEND_GL_ONE_MINUS_DST_ALPHA
;
184 case GL_SRC_ALPHA_SATURATE
:
186 (is_src
) ? R200_BLEND_GL_SRC_ALPHA_SATURATE
:
189 case GL_CONSTANT_COLOR
:
190 func
= R200_BLEND_GL_CONST_COLOR
;
192 case GL_ONE_MINUS_CONSTANT_COLOR
:
193 func
= R200_BLEND_GL_ONE_MINUS_CONST_COLOR
;
195 case GL_CONSTANT_ALPHA
:
196 func
= R200_BLEND_GL_CONST_ALPHA
;
198 case GL_ONE_MINUS_CONSTANT_ALPHA
:
199 func
= R200_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
202 func
= (is_src
) ? R200_BLEND_GL_ONE
: R200_BLEND_GL_ZERO
;
208 * Sets both the blend equation and the blend function.
209 * This is done in a single
210 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
211 * change the interpretation of the blend function.
212 * Also, make sure that blend function and blend equation are set to their default
213 * value if color blending is not enabled, since at least blend equations GL_MIN
214 * and GL_FUNC_REVERSE_SUBTRACT will cause wrong results otherwise for
218 /* helper function */
219 static void r300_set_blend_cntl(r300ContextPtr rmesa
, int func
, int eqn
, int cbits
, int funcA
, int eqnA
)
221 GLuint new_ablend
, new_cblend
;
224 fprintf(stderr
, "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n", eqnA
, funcA
, eqn
, func
, cbits
);
226 new_ablend
= eqnA
| funcA
;
227 new_cblend
= eqn
| func
;
229 new_cblend
|= R300_BLEND_NO_SEPARATE
;
233 if((new_ablend
!= rmesa
->hw
.bld
.cmd
[R300_BLD_ABLEND
])
234 || (new_cblend
!= rmesa
->hw
.bld
.cmd
[R300_BLD_CBLEND
])){
235 R300_STATECHANGE(rmesa
, bld
);
236 rmesa
->hw
.bld
.cmd
[R300_BLD_ABLEND
]=new_ablend
;
237 rmesa
->hw
.bld
.cmd
[R300_BLD_CBLEND
]=new_cblend
;
241 static void r300_set_blend_state(GLcontext
* ctx
)
243 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
245 GLuint cntl
= rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] &
246 ~(R300_ROP_ENABLE
| R300_ALPHA_BLEND_ENABLE
|
247 R300_SEPARATE_ALPHA_ENABLE
);
250 int func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
251 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
252 int eqn
= R200_COMB_FCN_ADD_CLAMP
;
253 int funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
254 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
255 int eqnA
= R200_COMB_FCN_ADD_CLAMP
;
258 if (rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
) {
259 if (ctx
->Color
._LogicOpEnabled
) {
261 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] =
262 cntl
| R300_ROP_ENABLE
;
264 r300_set_blend_cntl(rmesa
,
268 } else if (ctx
->Color
.BlendEnabled
) {
270 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] =
271 cntl
| R300_ALPHA_BLEND_ENABLE
|
272 R300_SEPARATE_ALPHA_ENABLE
;
276 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
;
278 r300_set_blend_cntl(rmesa
,
284 if (ctx
->Color
._LogicOpEnabled
) {
286 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] =
287 cntl
| R300_ROP_ENABLE
;
288 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
291 } else if (ctx
->Color
.BlendEnabled
) {
293 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] =
294 cntl
| R300_ALPHA_BLEND_ENABLE
;
298 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_CNTL
] = cntl
;
299 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
301 r300_set_blend_cntl(rmesa
,
309 (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) <<
310 R200_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstRGB
,
312 R200_DST_BLEND_SHIFT
);
314 switch (ctx
->Color
.BlendEquationRGB
) {
316 eqn
= R300_COMB_FCN_ADD_CLAMP
;
319 case GL_FUNC_SUBTRACT
:
320 eqn
= R300_COMB_FCN_SUB_CLAMP
;
323 case GL_FUNC_REVERSE_SUBTRACT
:
324 eqn
= R200_COMB_FCN_RSUB_CLAMP
;
328 eqn
= R200_COMB_FCN_MIN
;
329 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
330 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
334 eqn
= R200_COMB_FCN_MAX
;
335 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
336 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
341 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
342 __func__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
346 if (!rmesa
->radeon
.radeonScreen
->drmSupportsBlendColor
) {
348 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_BLENDCNTL
] = eqn
| func
;
354 (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) <<
355 R200_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstA
,
357 R200_DST_BLEND_SHIFT
);
359 switch (ctx
->Color
.BlendEquationA
) {
361 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
364 case GL_FUNC_SUBTRACT
:
365 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
368 case GL_FUNC_REVERSE_SUBTRACT
:
369 eqnA
= R200_COMB_FCN_RSUB_CLAMP
;
373 eqnA
= R200_COMB_FCN_MIN
;
374 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
375 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
379 eqnA
= R200_COMB_FCN_MAX
;
380 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
381 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
385 fprintf(stderr
, "[%s:%u] Invalid A blend equation (0x%04x).\n",
386 __func__
, __LINE__
, ctx
->Color
.BlendEquationA
);
390 r300_set_blend_cntl(rmesa
,
391 func
, eqn
, R300_BLEND_UNKNOWN
| R300_BLEND_ENABLE
,
393 r300_set_blend_cntl(rmesa
,
394 func
, eqn
, R300_BLEND_UNKNOWN
| R300_BLEND_ENABLE
,
398 static void r300BlendEquationSeparate(GLcontext
* ctx
,
399 GLenum modeRGB
, GLenum modeA
)
401 r300_set_blend_state(ctx
);
404 static void r300BlendFuncSeparate(GLcontext
* ctx
,
405 GLenum sfactorRGB
, GLenum dfactorRGB
,
406 GLenum sfactorA
, GLenum dfactorA
)
408 r300_set_blend_state(ctx
);
412 * Update our tracked culling state based on Mesa's state.
414 static void r300UpdateCulling(GLcontext
* ctx
)
416 r300ContextPtr r300
= R300_CONTEXT(ctx
);
419 R300_STATECHANGE(r300
, cul
);
420 if (ctx
->Polygon
.CullFlag
) {
421 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
422 val
= R300_CULL_FRONT
|R300_CULL_BACK
;
423 else if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
)
424 val
= R300_CULL_FRONT
;
426 val
= R300_CULL_BACK
;
428 if (ctx
->Polygon
.FrontFace
== GL_CW
)
429 val
|= R300_FRONT_FACE_CW
;
431 val
|= R300_FRONT_FACE_CCW
;
433 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
438 * Handle glEnable()/glDisable().
440 * \note Mesa already filters redundant calls to glEnable/glDisable.
442 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
444 r300ContextPtr r300
= R300_CONTEXT(ctx
);
447 if (RADEON_DEBUG
& DEBUG_STATE
)
448 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
449 _mesa_lookup_enum_by_nr(cap
),
450 state
? "GL_TRUE" : "GL_FALSE");
453 /* Fast track this one...
461 R200_STATECHANGE(r300
, at
);
463 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] |=
464 R300_ALPHA_TEST_ENABLE
;
466 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] |=
467 ~R300_ALPHA_TEST_ENABLE
;
472 case GL_COLOR_LOGIC_OP
:
473 r300_set_blend_state(ctx
);
477 R300_STATECHANGE(r300
, zs
);
481 newval
= R300_RB3D_Z_TEST_AND_WRITE
;
483 newval
= R300_RB3D_Z_TEST
;
487 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] = newval
;
490 case GL_STENCIL_TEST
:
492 WARN_ONCE("Do not know how to enable stencil. Help me !\n");
494 if (r300
->state
.hw_stencil
) {
495 //fprintf(stderr, "Stencil %s\n", state ? "enabled" : "disabled");
496 R300_STATECHANGE(r300
, zs
);
498 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
499 R300_RB3D_STENCIL_ENABLE
;
501 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
502 ~R300_RB3D_STENCIL_ENABLE
;
505 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_STENCIL
, state
);
510 r300UpdateCulling(ctx
);
513 case GL_POLYGON_OFFSET_POINT
:
514 case GL_POLYGON_OFFSET_LINE
:
515 WARN_ONCE("Don't know how to enable polygon offset point/line. Help me !\n");
517 /* Something is apparently blocking these from working */
518 R300_STATECHANGE(r300
, unk42B4
);
520 r300
->hw
.unk42B4
.cmd
[1] |= ~(3<<0);
522 r300
->hw
.unk42B4
.cmd
[1] &= (3<<0);
526 case GL_POLYGON_OFFSET_FILL
:
527 R300_STATECHANGE(r300
, unk42B4
);
529 r300
->hw
.unk42B4
.cmd
[1] |= (3<<0);
531 r300
->hw
.unk42B4
.cmd
[1] &= ~(3<<0);
535 case GL_VERTEX_PROGRAM_ARB
:
536 //TCL_FALLBACK(rmesa->glCtx, R200_TCL_FALLBACK_TCL_DISABLE, state);
540 radeonEnable(ctx
, cap
, state
);
547 * Change the culling mode.
549 * \note Mesa already filters redundant calls to this function.
551 static void r300CullFace(GLcontext
* ctx
, GLenum mode
)
555 r300UpdateCulling(ctx
);
560 * Change the polygon orientation.
562 * \note Mesa already filters redundant calls to this function.
564 static void r300FrontFace(GLcontext
* ctx
, GLenum mode
)
568 r300UpdateCulling(ctx
);
573 * Change the depth testing function.
575 * \note Mesa already filters redundant calls to this function.
577 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
579 r300ContextPtr r300
= R300_CONTEXT(ctx
);
581 R300_STATECHANGE(r300
, zs
);
583 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
);
587 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_NEVER
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
590 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_LESS
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
593 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_EQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
596 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_LEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
599 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_GREATER
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
602 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_NOTEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
605 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_GEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
608 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_ALWAYS
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
616 * Enable/Disable depth writing.
618 * \note Mesa already filters redundant calls to this function.
620 static void r300DepthMask(GLcontext
* ctx
, GLboolean mask
)
622 r300ContextPtr r300
= R300_CONTEXT(ctx
);
624 if (!ctx
->Depth
.Test
)
627 R300_STATECHANGE(r300
, zs
);
628 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] = mask
629 ? R300_RB3D_Z_TEST_AND_WRITE
: R300_RB3D_Z_TEST
;
634 * Handle glColorMask()
636 static void r300ColorMask(GLcontext
* ctx
,
637 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
639 r300ContextPtr r300
= R300_CONTEXT(ctx
);
640 int mask
= (b
<< 0) | (g
<< 1) | (r
<< 2) | (a
<< 3);
642 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
643 R300_STATECHANGE(r300
, cmk
);
644 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
648 /* =============================================================
651 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
653 r300ContextPtr r300
= R300_CONTEXT(ctx
);
655 size
= ctx
->Point
._Size
;
657 R300_STATECHANGE(r300
, ps
);
658 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
659 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
660 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
662 #if 0 /* r200 reg? */
663 /* This might need fixing later */
664 R300_STATECHANGE(r300
, vps
);
665 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
669 /* =============================================================
672 static void r300LineWidth(GLcontext
*ctx
, GLfloat widthf
)
674 r300ContextPtr r300
= R300_CONTEXT(ctx
);
676 widthf
= ctx
->Line
._Width
;
678 R300_STATECHANGE(r300
, lcntl
);
679 r300
->hw
.lcntl
.cmd
[1] = (int)(widthf
* 6.0);
680 /* Doesnt look very good without this... */
681 r300
->hw
.lcntl
.cmd
[1] |= R300_LINE_CNT_UNK1
;
686 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); : 00000091 ( 1001 0001)
687 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); : 00000001 ( 1)
689 glPolygonMode(GL_FRONT, GL_LINE); : 00000111 (1 0001 0001)
690 glPolygonMode(GL_FRONT, GL_POINT); : 00000101 (1 0000 0001)
692 glPolygonMode(GL_BACK, GL_LINE); : 000000a1 ( 1010 0001)
693 glPolygonMode(GL_BACK, GL_POINT); : 00000021 ( 10 0001)
698 #define PM_NOT_BACK (1<<8)
699 #define PM_NOT_FRONT (1<<5)
701 #define PM_FRONT_LINE (1<<4)
702 #define PM_BACK_LINE (1<<7)
704 static void r300PolygonMode(GLcontext
*ctx
, GLenum face
, GLenum mode
)
706 r300ContextPtr r300
= R300_CONTEXT(ctx
);
707 unsigned long hw_mode
=0;
709 //hw_mode=r300->hw.unk4288.cmd[1];
710 hw_mode
|= 1; /* enables point mode by default */
712 switch (ctx
->Polygon
.FrontMode
) {
714 hw_mode
&= ~PM_NOT_FRONT
;
715 hw_mode
|= PM_FRONT_LINE
;
718 hw_mode
&= ~PM_NOT_FRONT
;
719 hw_mode
&= ~PM_FRONT_LINE
;
721 /* I dont think fgl properly handles these... In any case, test program is needed */
726 switch (ctx
->Polygon
.BackMode
) {
728 hw_mode
&= ~PM_NOT_BACK
;
729 hw_mode
|= PM_BACK_LINE
;
732 hw_mode
&= ~PM_NOT_BACK
;
733 hw_mode
&= ~PM_BACK_LINE
;
745 //fprintf(stderr, "front\n");
746 hw_mode
&= ~PM_NOT_FRONT
;
749 hw_mode
|= PM_FRONT_LINE
;
752 hw_mode
&= ~PM_FRONT_LINE
;
760 //fprintf(stderr, "back\n");
761 hw_mode
&= ~PM_NOT_BACK
;
764 hw_mode
|= PM_BACK_LINE
;
767 hw_mode
&= ~PM_BACK_LINE
;
774 case GL_FRONT_AND_BACK
:
775 //fprintf(stderr, "front and back\n");
776 hw_mode
&= ~PM_NOT_FRONT
;
777 hw_mode
&= ~PM_NOT_BACK
;
780 hw_mode
|= PM_FRONT_LINE
;
781 hw_mode
|= PM_BACK_LINE
;
784 hw_mode
&= ~PM_FRONT_LINE
;
785 hw_mode
&= ~PM_BACK_LINE
;
795 //if( front and back fill) hw_mode=0;
797 if(r300
->hw
.unk4288
.cmd
[1] != hw_mode
){
798 R300_STATECHANGE(r300
, unk4288
);
799 r300
->hw
.unk4288
.cmd
[1] = hw_mode
;
803 /* =============================================================
807 static int translate_stencil_func(int func
)
811 return R300_ZS_NEVER
;
817 return R300_ZS_EQUAL
;
820 return R300_ZS_LEQUAL
;
823 return R300_ZS_GREATER
;
826 return R300_ZS_NOTEQUAL
;
829 return R300_ZS_GEQUAL
;
832 return R300_ZS_ALWAYS
;
838 static int translate_stencil_op(int op
)
846 return R300_ZS_REPLACE
;
851 case GL_INCR_WRAP_EXT
:
852 return R300_ZS_INCR_WRAP
;
853 case GL_DECR_WRAP_EXT
:
854 return R300_ZS_DECR_WRAP
;
856 return R300_ZS_INVERT
;
858 WARN_ONCE("Do not know how to translate stencil op");
863 static void r300StencilFunc(GLcontext
* ctx
, GLenum func
,
864 GLint ref
, GLuint mask
)
866 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
867 GLuint refmask
= ((ctx
->Stencil
.Ref
[0] << R300_RB3D_ZS2_STENCIL_REF_SHIFT
) |
869 ValueMask
[0] << R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
872 R300_STATECHANGE(rmesa
, zs
);
874 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(
875 (R300_ZS_MASK
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
876 | (R300_ZS_MASK
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
));
877 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &= ~((R300_ZS_MASK
<< R300_RB3D_ZS2_STENCIL_REF_SHIFT
) |
878 (R300_ZS_MASK
<< R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
880 flag
= translate_stencil_func(ctx
->Stencil
.Function
[0]);
882 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= (flag
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
883 | (flag
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
884 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
887 static void r300StencilMask(GLcontext
* ctx
, GLuint mask
)
889 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
891 R300_STATECHANGE(rmesa
, zs
);
892 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &= ~(R300_ZS_MASK
<< R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
);
893 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= ctx
->Stencil
.WriteMask
[0] << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
;
897 static void r300StencilOp(GLcontext
* ctx
, GLenum fail
,
898 GLenum zfail
, GLenum zpass
)
900 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
902 R300_STATECHANGE(rmesa
, zs
);
903 /* It is easier to mask what's left.. */
904 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= (R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
);
906 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
907 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) << R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT
)
908 |(translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT
)
909 |(translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT
)
910 |(translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) << R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
911 |(translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
912 |(translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
916 static void r300ClearStencil(GLcontext
* ctx
, GLint s
)
918 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
920 /* Not sure whether this is correct.. */
921 R300_STATECHANGE(rmesa
, zs
);
922 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] =
923 ((GLuint
) ctx
->Stencil
.Clear
|
924 (0xff << R200_STENCIL_MASK_SHIFT
) |
925 (ctx
->Stencil
.WriteMask
[0] << R200_STENCIL_WRITEMASK_SHIFT
));
928 /* =============================================================
929 * Window position and viewport transformation
933 * To correctly position primitives:
935 #define SUBPIXEL_X 0.125
936 #define SUBPIXEL_Y 0.125
938 void r300UpdateWindow(GLcontext
* ctx
)
940 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
941 __DRIdrawablePrivate
*dPriv
= rmesa
->radeon
.dri
.drawable
;
942 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
943 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
944 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
946 GLfloat sx
= v
[MAT_SX
];
947 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
948 GLfloat sy
= -v
[MAT_SY
];
949 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
950 GLfloat sz
= v
[MAT_SZ
] * rmesa
->state
.depth
.scale
;
951 GLfloat tz
= v
[MAT_TZ
] * rmesa
->state
.depth
.scale
;
953 R300_FIREVERTICES(rmesa
);
954 R300_STATECHANGE(rmesa
, vpt
);
956 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
957 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
958 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
959 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
960 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
961 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
964 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
965 GLsizei width
, GLsizei height
)
967 /* Don't pipeline viewport changes, conflict with window offset
968 * setting below. Could apply deltas to rescue pipelined viewport
969 * values, or keep the originals hanging around.
971 R300_FIREVERTICES(R300_CONTEXT(ctx
));
972 r300UpdateWindow(ctx
);
975 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
977 r300UpdateWindow(ctx
);
980 /* =============================================================
983 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
985 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
986 GLfloat constant
= units
* /*rmesa->state.depth.scale*/4;
990 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
992 R300_STATECHANGE(rmesa
, zbs
);
993 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
994 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
995 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
996 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
999 /* Routing and texture-related */
1001 void r300_setup_routing(GLcontext
*ctx
, GLboolean immediate
)
1003 int i
, count
=0,reg
=0;
1005 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
1006 struct vertex_buffer
*VB
= &tnl
->vb
;
1007 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1010 /* Stage 1 - input to VAP */
1012 /* Assign register number automatically, retaining it in rmesa->state.reg */
1014 /* Note: immediate vertex data includes all coordinates.
1015 To save bandwidth use either VBUF or state-based vertex generation */
1017 #define CONFIGURE_AOS(v, o, r, f) \
1019 if (RADEON_DEBUG & DEBUG_STATE)fprintf(stderr, "Enabling "#r "\n"); \
1020 r300->state.aos[count].aos_size=4; \
1021 r300->state.aos[count].aos_stride=4; \
1022 r300->state.aos[count].aos_offset=o; \
1023 r300->state.aos[count].aos_reg=reg; \
1024 r300->state.aos[count].aos_format=(f); \
1025 r300->state.vap_reg.r=reg; \
1030 /* All offsets are 0 - for use by immediate mode.
1031 Should change later to handle vertex buffers */
1032 if(r300
->current_vp
!=NULL
){
1034 /* VERT_ATTRIB_WEIGHT, VERT_ATTRIB_SIX, VERT_ATTRIB_SEVEN, VERT_ATTRIB_GENERIC0,
1035 VERT_ATTRIB_GENERIC1, VERT_ATTRIB_GENERIC2, VERT_ATTRIB_GENERIC3 */
1036 r300
->state
.render_inputs
= 0;
1038 if(r300
->current_vp
->inputs
[VERT_ATTRIB_POS
] != -1){
1039 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_POS
];
1040 CONFIGURE_AOS(VB
->ObjPtr
, 0, i_coords
, AOS_FORMAT_FLOAT
);
1041 r300
->state
.render_inputs
|= _TNL_BIT_POS
;
1043 if(r300
->current_vp
->inputs
[VERT_ATTRIB_NORMAL
] != -1){
1044 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_NORMAL
];
1045 CONFIGURE_AOS(VB
->NormalPtr
, 0, i_normal
, AOS_FORMAT_FLOAT
);
1046 r300
->state
.render_inputs
|= _TNL_BIT_NORMAL
;
1048 if(r300
->current_vp
->inputs
[VERT_ATTRIB_COLOR0
] != -1){
1049 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_COLOR0
];
1050 CONFIGURE_AOS(VB
->ColorPtr
[0], 0, i_color
[0], AOS_FORMAT_FLOAT_COLOR
);
1051 r300
->state
.render_inputs
|= _TNL_BIT_COLOR0
;
1053 if(r300
->current_vp
->inputs
[VERT_ATTRIB_COLOR1
] != -1){
1054 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_COLOR1
];
1055 CONFIGURE_AOS(VB
->SecondaryColorPtr
[0], 0, i_color
[1], AOS_FORMAT_FLOAT_COLOR
);
1056 r300
->state
.render_inputs
|= _TNL_BIT_COLOR1
;
1058 if(r300
->current_vp
->inputs
[VERT_ATTRIB_FOG
] != -1){
1059 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_FOG
];
1060 CONFIGURE_AOS(VB
->FogCoordPtr
, 0, i_fog
, AOS_FORMAT_FLOAT
);
1061 r300
->state
.render_inputs
|= _TNL_BIT_FOG
;
1063 for(i
=0;i
< ctx
->Const
.MaxTextureUnits
;i
++) // tex 7 is last
1064 if(r300
->current_vp
->inputs
[VERT_ATTRIB_TEX0
+i
] != -1){
1065 reg
=r300
->current_vp
->inputs
[VERT_ATTRIB_TEX0
+i
];
1066 CONFIGURE_AOS(VB
->TexCoordPtr
[i
], 0, i_tex
[i
], AOS_FORMAT_FLOAT
);
1067 r300
->state
.render_inputs
|= _TNL_BIT_TEX0
<<i
;
1070 if((tnl
->render_inputs
& _TNL_BIT_INDEX
))
1071 CONFIGURE_AOS(VB
->IndexPtr
[0], 0, i_index
, AOS_FORMAT_FLOAT
);
1073 if((tnl
->render_inputs
& _TNL_BIT_POINTSIZE
))
1074 CONFIGURE_AOS(VB
->PointSizePtr
, 0, i_pointsize
, AOS_FORMAT_FLOAT
);
1078 r300
->state
.render_inputs
= tnl
->render_inputs
;
1080 if(tnl
->render_inputs
& _TNL_BIT_POS
)
1081 CONFIGURE_AOS(VB
->ObjPtr
, 0, i_coords
, AOS_FORMAT_FLOAT
);
1082 if(tnl
->render_inputs
& _TNL_BIT_NORMAL
)
1083 CONFIGURE_AOS(VB
->NormalPtr
, 0, i_normal
, AOS_FORMAT_FLOAT
);
1085 if(tnl
->render_inputs
& _TNL_BIT_COLOR0
)
1086 CONFIGURE_AOS(VB
->ColorPtr
[0], 0, i_color
[0], AOS_FORMAT_FLOAT_COLOR
);
1087 if(tnl
->render_inputs
& _TNL_BIT_COLOR1
)
1088 CONFIGURE_AOS(VB
->SecondaryColorPtr
[0], 0, i_color
[1], AOS_FORMAT_FLOAT_COLOR
);
1090 /*if(tnl->render_inputs & _TNL_BIT_FOG) // Causes lock ups when immediate mode is on
1091 CONFIGURE_AOS(VB->FogCoordPtr, 0, i_fog, AOS_FORMAT_FLOAT);*/
1093 for(i
=0;i
< ctx
->Const
.MaxTextureUnits
;i
++)
1094 if(tnl
->render_inputs
& (_TNL_BIT_TEX0
<<i
))
1095 CONFIGURE_AOS(VB
->TexCoordPtr
[i
], 0, i_tex
[i
], AOS_FORMAT_FLOAT
);
1097 if(tnl
->render_inputs
& _TNL_BIT_INDEX
)
1098 CONFIGURE_AOS(VB
->IndexPtr
[0], 0, i_index
, AOS_FORMAT_FLOAT
);
1099 if(tnl
->render_inputs
& _TNL_BIT_POINTSIZE
)
1100 CONFIGURE_AOS(VB
->PointSizePtr
, 0, i_pointsize
, AOS_FORMAT_FLOAT
);
1103 r300
->state
.aos_count
=count
;
1105 if (RADEON_DEBUG
& DEBUG_STATE
)
1106 fprintf(stderr
, "aos_count=%d render_inputs=%08x\n", count
, r300
->state
.render_inputs
);
1109 if(count
>R300_MAX_AOS_ARRAYS
){
1110 fprintf(stderr
, "Aieee ! AOS array count exceeded !\n");
1116 /* setup INPUT_ROUTE */
1117 R300_STATECHANGE(r300
, vir
[0]);
1118 for(i
=0;i
+1<count
;i
+=2){
1119 dw
=(r300
->state
.aos
[i
].aos_size
-1)
1120 | ((r300
->state
.aos
[i
].aos_reg
)<<8)
1121 | (r300
->state
.aos
[i
].aos_format
<<14)
1122 | (((r300
->state
.aos
[i
+1].aos_size
-1)
1123 | ((r300
->state
.aos
[i
+1].aos_reg
)<<8)
1124 | (r300
->state
.aos
[i
+1].aos_format
<<14))<<16);
1129 r300
->hw
.vir
[0].cmd
[R300_VIR_CNTL_0
+(i
>>1)]=dw
;
1132 dw
=(r300
->state
.aos
[count
-1].aos_size
-1)
1133 | (r300
->state
.aos
[count
-1].aos_format
<<14)
1134 | ((r300
->state
.aos
[count
-1].aos_reg
)<<8)
1136 r300
->hw
.vir
[0].cmd
[R300_VIR_CNTL_0
+(count
>>1)]=dw
;
1137 //fprintf(stderr, "vir0 dw=%08x\n", dw);
1139 /* Set the rest of INPUT_ROUTE_0 to 0 */
1140 //for(i=((count+1)>>1); i<8; i++)r300->hw.vir[0].cmd[R300_VIR_CNTL_0+i]=(0x0);
1141 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[0].cmd
)->unchecked_state
.count
= (count
+1)>>1;
1144 /* Mesa assumes that all missing components are from (0, 0, 0, 1) */
1145 #define ALL_COMPONENTS ((R300_INPUT_ROUTE_SELECT_X<<R300_INPUT_ROUTE_X_SHIFT) \
1146 | (R300_INPUT_ROUTE_SELECT_Y<<R300_INPUT_ROUTE_Y_SHIFT) \
1147 | (R300_INPUT_ROUTE_SELECT_Z<<R300_INPUT_ROUTE_Z_SHIFT) \
1148 | (R300_INPUT_ROUTE_SELECT_W<<R300_INPUT_ROUTE_W_SHIFT))
1150 #define ALL_DEFAULT ((R300_INPUT_ROUTE_SELECT_ZERO<<R300_INPUT_ROUTE_X_SHIFT) \
1151 | (R300_INPUT_ROUTE_SELECT_ZERO<<R300_INPUT_ROUTE_Y_SHIFT) \
1152 | (R300_INPUT_ROUTE_SELECT_ZERO<<R300_INPUT_ROUTE_Z_SHIFT) \
1153 | (R300_INPUT_ROUTE_SELECT_ONE<<R300_INPUT_ROUTE_W_SHIFT))
1155 R300_STATECHANGE(r300
, vir
[1]);
1157 for(i
=0;i
+1<count
;i
+=2){
1159 mask
=(1<<(r300
->state
.aos
[i
].aos_size
*3))-1;
1160 dw
=(ALL_COMPONENTS
& mask
)
1161 | (ALL_DEFAULT
& ~mask
)
1162 | R300_INPUT_ROUTE_ENABLE
;
1165 mask
=(1<<(r300
->state
.aos
[i
+1].aos_size
*3))-1;
1167 (ALL_COMPONENTS
& mask
)
1168 | (ALL_DEFAULT
& ~mask
)
1169 | R300_INPUT_ROUTE_ENABLE
1172 r300
->hw
.vir
[1].cmd
[R300_VIR_CNTL_0
+(i
>>1)]=dw
;
1175 mask
=(1<<(r300
->state
.aos
[count
-1].aos_size
*3))-1;
1176 dw
=(ALL_COMPONENTS
& mask
)
1177 | (ALL_DEFAULT
& ~mask
)
1178 | R300_INPUT_ROUTE_ENABLE
;
1179 r300
->hw
.vir
[1].cmd
[R300_VIR_CNTL_0
+(count
>>1)]=dw
;
1180 //fprintf(stderr, "vir1 dw=%08x\n", dw);
1182 /* Set the rest of INPUT_ROUTE_1 to 0 */
1183 //for(i=((count+1)>>1); i<8; i++)r300->hw.vir[1].cmd[R300_VIR_CNTL_0+i]=0x0;
1184 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[1].cmd
)->unchecked_state
.count
= (count
+1)>>1;
1186 /* Set up input_cntl */
1188 R300_STATECHANGE(r300
, vic
);
1189 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_0
]=0x5555; /* Hard coded value, no idea what it means */
1191 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_1
]=0;
1193 if(r300
->state
.render_inputs
& _TNL_BIT_POS
)
1194 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_1
]|=R300_INPUT_CNTL_POS
;
1196 if(r300
->state
.render_inputs
& _TNL_BIT_NORMAL
)
1197 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_1
]|=R300_INPUT_CNTL_NORMAL
;
1199 if(r300
->state
.render_inputs
& _TNL_BIT_COLOR0
)
1200 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_1
]|=R300_INPUT_CNTL_COLOR
;
1202 for(i
=0;i
< ctx
->Const
.MaxTextureUnits
;i
++)
1203 if(r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
))
1204 r300
->hw
.vic
.cmd
[R300_VIC_CNTL_1
]|=(R300_INPUT_CNTL_TC0
<<i
);
1206 /* Stage 3: VAP output */
1207 R300_STATECHANGE(r300
, vof
);
1208 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_0
]=R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT
1209 | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT
;
1211 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_1
]=0;
1212 for(i
=0;i
< ctx
->Const
.MaxTextureUnits
;i
++)
1213 if(r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
))
1214 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_1
]|=(4<<(3*i
));
1218 static r300TexObj default_tex_obj
={
1219 filter
:R300_TX_MAG_FILTER_LINEAR
| R300_TX_MIN_FILTER_LINEAR
,
1221 size
: (0xff << R300_TX_WIDTHMASK_SHIFT
)
1222 | (0xff << R300_TX_HEIGHTMASK_SHIFT
)
1223 | (0x8 << R300_TX_SIZE_SHIFT
),
1230 /* there is probably a system to these value, but, for now,
1231 we just try by hand */
1233 static int inline translate_src(int src
)
1242 case GL_PRIMARY_COLOR
:
1259 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
1260 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
1261 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
1262 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1263 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1264 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1265 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
1266 * combinations where only one of them is nearest.
1268 static unsigned long gen_fixed_filter(unsigned long f
)
1270 unsigned long mag
, min
, needs_fixing
=0;
1273 /* We ignore MIRROR bit so we dont have to do everything twice */
1274 if((f
& ((7-1) << R300_TX_WRAP_S_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)){
1277 if((f
& ((7-1) << R300_TX_WRAP_T_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)){
1280 if((f
& ((7-1) << R300_TX_WRAP_Q_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_Q_SHIFT
)){
1287 mag
=f
& R300_TX_MAG_FILTER_MASK
;
1288 min
=f
& R300_TX_MIN_FILTER_MASK
;
1290 /* TODO: Check for anisto filters too */
1291 if((mag
!= R300_TX_MAG_FILTER_NEAREST
) && (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
) && (min
!= R300_TX_MIN_FILTER_NEAREST
)){
1296 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
1297 f
|= R300_TX_MAG_FILTER_LINEAR
;
1301 if((min
== R300_TX_MIN_FILTER_NEAREST
) && (mag
!= R300_TX_MAG_FILTER_NEAREST
)){
1302 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
1303 f
|= R300_TX_MIN_FILTER_LINEAR
;
1307 /* Both are nearest */
1308 if(needs_fixing
& 1){
1309 f
&= ~((7-1) << R300_TX_WRAP_S_SHIFT
);
1310 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1312 if(needs_fixing
& 2){
1313 f
&= ~((7-1) << R300_TX_WRAP_T_SHIFT
);
1314 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1316 if(needs_fixing
& 4){
1317 f
&= ~((7-1) << R300_TX_WRAP_Q_SHIFT
);
1318 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_Q_SHIFT
;
1323 void r300_setup_textures(GLcontext
*ctx
)
1326 struct r300_tex_obj
*t
;
1327 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1328 int max_texture_unit
=-1; /* -1 translates into no setup costs for fields */
1329 struct gl_texture_unit
*texUnit
;
1331 R300_STATECHANGE(r300
, txe
);
1332 R300_STATECHANGE(r300
, tex
.filter
);
1333 R300_STATECHANGE(r300
, tex
.unknown1
);
1334 R300_STATECHANGE(r300
, tex
.size
);
1335 R300_STATECHANGE(r300
, tex
.format
);
1336 R300_STATECHANGE(r300
, tex
.offset
);
1337 R300_STATECHANGE(r300
, tex
.unknown4
);
1338 R300_STATECHANGE(r300
, tex
.border_color
);
1340 r300
->state
.texture
.tc_count
=0;
1342 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
]=0x0;
1344 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1345 if (RADEON_DEBUG
& DEBUG_STATE
)
1346 fprintf(stderr
, "mtu=%d\n", mtu
);
1348 if(mtu
>R300_MAX_TEXTURE_UNITS
){
1349 fprintf(stderr
, "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1350 mtu
, R300_MAX_TEXTURE_UNITS
);
1354 if( ((r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
))!=0) != ((ctx
->Texture
.Unit
[i
].Enabled
)!=0) ) {
1355 WARN_ONCE("Mismatch between render_inputs and ctx->Texture.Unit[i].Enabled value.\n");
1357 if(r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
)){
1358 t
=r300
->state
.texture
.unit
[i
].texobj
;
1359 //fprintf(stderr, "format=%08x\n", r300->state.texture.unit[i].format);
1360 r300
->state
.texture
.tc_count
++;
1362 fprintf(stderr
, "Texture unit %d enabled, but corresponding texobj is NULL, using default object.\n", i
);
1366 //fprintf(stderr, "t->format=%08x\n", t->format);
1367 if((t
->format
& 0xffffff00)==0xffffff00){
1368 WARN_ONCE("unknown texture format (entry %x) encountered. Help me !\n", t
->format
& 0xff);
1369 //fprintf(stderr, "t->format=%08x\n", t->format);
1371 if (RADEON_DEBUG
& DEBUG_STATE
)
1372 fprintf(stderr
, "Activating texture unit %d\n", i
);
1374 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
]|=(1<<i
);
1376 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+i
]=gen_fixed_filter(t
->filter
);
1377 /* No idea why linear filtered textures shake when puting random data */
1378 /*r300->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+i]=(rand()%0xffffffff) & (~0x1fff);*/
1379 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+i
]=t
->size
;
1380 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+i
]=t
->format
;
1381 //fprintf(stderr, "t->format=%08x\n", t->format);
1382 r300
->hw
.tex
.offset
.cmd
[R300_TEX_VALUE_0
+i
]=r300
->radeon
.radeonScreen
->fbLocation
+t
->offset
;
1383 r300
->hw
.tex
.unknown4
.cmd
[R300_TEX_VALUE_0
+i
]=0x0;
1384 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+i
]=t
->pp_border_color
;
1387 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.filter
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1388 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.unknown1
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1389 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.size
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1390 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.format
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1391 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.offset
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1392 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.unknown4
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1393 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.border_color
.cmd
)->unchecked_state
.count
= max_texture_unit
+1;
1395 if (RADEON_DEBUG
& DEBUG_STATE
)
1396 fprintf(stderr
, "TX_ENABLE: %08x max_texture_unit=%d\n", r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], max_texture_unit
);
1399 void r300_setup_rs_unit(GLcontext
*ctx
)
1401 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1404 /* This needs to be rewritten - it is a hack at best */
1406 R300_STATECHANGE(r300
, ri
);
1407 R300_STATECHANGE(r300
, rc
);
1408 R300_STATECHANGE(r300
, rr
);
1410 for(i
= 1; i
<= 8; ++i
)
1411 r300
->hw
.ri
.cmd
[i
] = 0x00d10000;
1412 r300
->hw
.ri
.cmd
[R300_RI_INTERP_1
] |= R300_RS_INTERP_1_UNKNOWN
;
1413 r300
->hw
.ri
.cmd
[R300_RI_INTERP_2
] |= R300_RS_INTERP_2_UNKNOWN
;
1414 r300
->hw
.ri
.cmd
[R300_RI_INTERP_3
] |= R300_RS_INTERP_3_UNKNOWN
;
1417 for(i
= 2; i
<= 8; ++i
)
1418 r300
->hw
.ri
.cmd
[i
] |= 4;
1421 for(i
= 1; i
<= 8; ++i
)
1422 r300
->hw
.rr
.cmd
[i
] = 0;
1423 /* textures enabled ? */
1424 if(r300
->state
.texture
.tc_count
>0){
1426 /* This code only really works with one set of texture coordinates */
1428 /* The second constant is needed to get glxgears display anything .. */
1429 r300
->hw
.rc
.cmd
[1] = R300_RS_CNTL_0_UNKNOWN_7
1430 | R300_RS_CNTL_0_UNKNOWN_18
1431 | (r300
->state
.texture
.tc_count
<<R300_RS_CNTL_TC_CNT_SHIFT
);
1432 r300
->hw
.rc
.cmd
[2] = 0xc0;
1435 ((drm_r300_cmd_header_t
*)r300
->hw
.rr
.cmd
)->unchecked_state
.count
= 1;
1436 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] = 0x24008;
1440 /* The second constant is needed to get glxgears display anything .. */
1441 r300
->hw
.rc
.cmd
[1] = R300_RS_CNTL_0_UNKNOWN_7
| R300_RS_CNTL_0_UNKNOWN_18
;
1442 r300
->hw
.rc
.cmd
[2] = 0;
1444 ((drm_r300_cmd_header_t
*)r300
->hw
.rr
.cmd
)->unchecked_state
.count
= 1;
1445 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] = 0x4000;
1450 #define vpucount(ptr) (((drm_r300_cmd_header_t*)(ptr))->vpu.count)
1452 #define bump_vpu_count(ptr, new_count) do{\
1453 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1454 int _nc=(new_count)/4; \
1455 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1458 void static inline setup_vertex_shader_fragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1462 if(vsf
->length
==0)return;
1464 if(vsf
->length
& 0x3){
1465 fprintf(stderr
,"VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1469 switch((dest
>>8) & 0xf){
1471 R300_STATECHANGE(r300
, vpi
);
1472 for(i
=0;i
<vsf
->length
;i
++)
1473 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1474 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+4*(dest
& 0xff));
1478 R300_STATECHANGE(r300
, vpp
);
1479 for(i
=0;i
<vsf
->length
;i
++)
1480 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1481 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+4*(dest
& 0xff));
1484 R300_STATECHANGE(r300
, vps
);
1485 for(i
=0;i
<vsf
->length
;i
++)
1486 r300
->hw
.vps
.cmd
[1+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1487 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+4*(dest
& 0xff));
1490 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1495 void r300SetupVertexProgram(r300ContextPtr rmesa
);
1497 void r300SetupVertexShader(r300ContextPtr rmesa
)
1499 GLcontext
* ctx
= rmesa
->radeon
.glCtx
;
1501 if(rmesa
->current_vp
!= NULL
){
1502 r300SetupVertexProgram(rmesa
);
1506 /* Reset state, in case we don't use something */
1507 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1508 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1509 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1512 /* This needs to be replaced by vertex shader generation code */
1515 /* textures enabled ? */
1516 if(rmesa
->state
.texture
.tc_count
>0){
1517 rmesa
->state
.vertex_shader
=SINGLE_TEXTURE_VERTEX_SHADER
;
1519 rmesa
->state
.vertex_shader
=FLAT_COLOR_VERTEX_SHADER
;
1523 rmesa
->state
.vertex_shader
.matrix
[0].length
=16;
1524 memcpy(rmesa
->state
.vertex_shader
.matrix
[0].body
.f
, ctx
->_ModelProjectMatrix
.m
, 16*4);
1526 setup_vertex_shader_fragment(rmesa
, VSF_DEST_PROGRAM
, &(rmesa
->state
.vertex_shader
.program
));
1528 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX0
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1530 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX1
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1531 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX2
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1533 setup_vertex_shader_fragment(rmesa
, VSF_DEST_VECTOR0
, &(rmesa
->state
.vertex_shader
.vector
[0]));
1534 setup_vertex_shader_fragment(rmesa
, VSF_DEST_VECTOR1
, &(rmesa
->state
.vertex_shader
.vector
[1]));
1538 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN1
, &(rmesa
->state
.vertex_shader
.unknown1
));
1539 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN2
, &(rmesa
->state
.vertex_shader
.unknown2
));
1542 R300_STATECHANGE(rmesa
, pvs
);
1543 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
]=(rmesa
->state
.vertex_shader
.program_start
<< R300_PVS_CNTL_1_PROGRAM_START_SHIFT
)
1544 | (rmesa
->state
.vertex_shader
.unknown_ptr1
<< R300_PVS_CNTL_1_UNKNOWN_SHIFT
)
1545 | (rmesa
->state
.vertex_shader
.program_end
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1546 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
]=(rmesa
->state
.vertex_shader
.param_offset
<< R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
)
1547 | (rmesa
->state
.vertex_shader
.param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1548 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
]=(rmesa
->state
.vertex_shader
.unknown_ptr2
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
)
1549 | (rmesa
->state
.vertex_shader
.unknown_ptr3
<< 0);
1551 /* This is done for vertex shader fragments, but also needs to be done for vap_pvs,
1552 so I leave it as a reminder */
1554 reg_start(R300_VAP_PVS_WAITIDLE
,0);
1559 void r300SetupVertexProgram(r300ContextPtr rmesa
)
1561 GLcontext
* ctx
= rmesa
->radeon
.glCtx
;
1565 /* Reset state, in case we don't use something */
1566 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1567 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1568 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1570 r300VertexProgUpdateParams(ctx
, rmesa
->current_vp
);
1572 setup_vertex_shader_fragment(rmesa
, VSF_DEST_PROGRAM
, &(rmesa
->current_vp
->program
));
1574 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX0
, &(rmesa
->current_vp
->params
));
1577 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN1
, &(rmesa
->state
.vertex_shader
.unknown1
));
1578 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN2
, &(rmesa
->state
.vertex_shader
.unknown2
));
1581 inst_count
=rmesa
->current_vp
->program
.length
/4 - 1;
1582 param_count
=rmesa
->current_vp
->params
.length
/4;
1584 R300_STATECHANGE(rmesa
, pvs
);
1585 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
]=(0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
)
1586 | (inst_count
/*0*/ << R300_PVS_CNTL_1_UNKNOWN_SHIFT
)
1587 | (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1588 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
]=(0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
)
1589 | (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1590 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
]=(0/*rmesa->state.vertex_shader.unknown_ptr2*/ << R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
)
1591 | ((inst_count
-rmesa
->current_vp
->t2rs
) /*rmesa->state.vertex_shader.unknown_ptr3*/ << 0);
1593 /* This is done for vertex shader fragments, but also needs to be done for vap_pvs,
1594 so I leave it as a reminder */
1596 reg_start(R300_VAP_PVS_WAITIDLE
,0);
1602 /* just a skeleton for now.. */
1603 void r300GenerateTexturePixelShader(r300ContextPtr r300
)
1606 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1609 int tex_inst
=0, alu_inst
=0;
1612 /* No need to proliferate {} */
1613 if(! (r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
)))continue;
1615 envMode
= r300
->radeon
.glCtx
->Texture
.Unit
[i
].EnvMode
;
1616 //fprintf(stderr, "envMode=%s\n", _mesa_lookup_enum_by_nr(envMode));
1618 /* Fetch textured pixel */
1620 r300
->state
.pixel_shader
.program
.tex
.inst
[tex_inst
]=0x00018000;
1623 switch(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeRGB
){
1625 WARN_ONCE("ModeA==GL_REPLACE is possibly broken.\n");
1626 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1627 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, ONE
, ZERO
);
1629 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1630 EASY_PFS_INSTR1(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1633 WARN_ONCE("ModeRGB==GL_MODULATE is possibly broken.\n");
1634 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1635 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, SRC1C_XYZ
, ZERO
);
1637 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1638 EASY_PFS_INSTR1(0, 0, 1, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1642 fprintf(stderr
, "ModeRGB=%s is not implemented yet !\n",
1643 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeRGB
));
1645 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1646 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, ONE
, ZERO
);
1648 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1649 EASY_PFS_INSTR1(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1651 switch(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeA
){
1653 WARN_ONCE("ModeA==GL_REPLACE is possibly broken.\n");
1654 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1655 EASY_PFS_INSTR2(MAD
, SRC0A
, ONE
, ZERO
);
1657 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1658 EASY_PFS_INSTR3(0, 0, 0| PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, OUTPUT
);
1661 fprintf(stderr
, "numArgsA=%d sourceA[0]=%s op=%d\n",
1662 r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->_NumArgsA
,
1663 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->SourceA
[0]),
1664 r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->OperandA
[0]-GL_SRC_ALPHA
);
1668 WARN_ONCE("ModeA==GL_MODULATE is possibly broken.\n");
1670 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1671 EASY_PFS_INSTR2(MAD
, SRC0A
, SRC1A
, ZERO
);
1673 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1674 EASY_PFS_INSTR3(0, 0, 1, 0 | PFS_FLAG_CONST
, OUTPUT
);
1678 fprintf(stderr
, "ModeA=%s is not implemented yet !\n",
1679 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeA
));
1681 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1682 EASY_PFS_INSTR2(MAD
, SRC0A
, ONE
, ZERO
);
1684 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1685 EASY_PFS_INSTR3(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, OUTPUT
);
1692 r300
->state
.pixel_shader
.program
.tex
.length
=tex_inst
;
1693 r300
->state
.pixel_shader
.program
.tex_offset
=0;
1694 r300
->state
.pixel_shader
.program
.tex_end
=tex_inst
-1;
1697 /* saturate last instruction, like i915 driver does */
1698 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
-1].inst0
|=R300_FPI0_OUTC_SAT
;
1699 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
-1].inst2
|=R300_FPI2_OUTA_SAT
;
1702 r300
->state
.pixel_shader
.program
.alu
.length
=alu_inst
;
1703 r300
->state
.pixel_shader
.program
.alu_offset
=0;
1704 r300
->state
.pixel_shader
.program
.alu_end
=alu_inst
-1;
1707 void r300SetupPixelShader(r300ContextPtr rmesa
)
1711 /* This needs to be replaced by pixel shader generation code */
1713 /* textures enabled ? */
1714 if(rmesa
->state
.texture
.tc_count
>0){
1715 rmesa
->state
.pixel_shader
=SINGLE_TEXTURE_PIXEL_SHADER
;
1716 r300GenerateTexturePixelShader(rmesa
);
1718 rmesa
->state
.pixel_shader
=FLAT_COLOR_PIXEL_SHADER
;
1721 R300_STATECHANGE(rmesa
, fpt
);
1722 for(i
=0;i
<rmesa
->state
.pixel_shader
.program
.tex
.length
;i
++)
1723 rmesa
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+i
]=rmesa
->state
.pixel_shader
.program
.tex
.inst
[i
];
1724 rmesa
->hw
.fpt
.cmd
[R300_FPT_CMD_0
]=cmducs(R300_PFS_TEXI_0
, rmesa
->state
.pixel_shader
.program
.tex
.length
);
1726 #define OUTPUT_FIELD(st, reg, field) \
1727 R300_STATECHANGE(rmesa, st); \
1728 for(i=0;i<rmesa->state.pixel_shader.program.alu.length;i++) \
1729 rmesa->hw.st.cmd[R300_FPI_INSTR_0+i]=rmesa->state.pixel_shader.program.alu.inst[i].field;\
1730 rmesa->hw.st.cmd[R300_FPI_CMD_0]=cmducs(reg, rmesa->state.pixel_shader.program.alu.length);
1732 OUTPUT_FIELD(fpi
[0], R300_PFS_INSTR0_0
, inst0
);
1733 OUTPUT_FIELD(fpi
[1], R300_PFS_INSTR1_0
, inst1
);
1734 OUTPUT_FIELD(fpi
[2], R300_PFS_INSTR2_0
, inst2
);
1735 OUTPUT_FIELD(fpi
[3], R300_PFS_INSTR3_0
, inst3
);
1738 R300_STATECHANGE(rmesa
, fp
);
1740 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+i
]=
1741 (rmesa
->state
.pixel_shader
.program
.node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
)
1742 | (rmesa
->state
.pixel_shader
.program
.node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
)
1743 | (rmesa
->state
.pixel_shader
.program
.node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
)
1744 | (rmesa
->state
.pixel_shader
.program
.node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
)
1745 | ( (i
==3) ? R300_PFS_NODE_LAST_NODE
: 0);
1749 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
]=
1750 (rmesa
->state
.pixel_shader
.program
.active_nodes
-1)
1751 | (rmesa
->state
.pixel_shader
.program
.first_node_has_tex
<<3);
1753 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
]=rmesa
->state
.pixel_shader
.program
.temp_register_count
;
1755 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
]=
1756 (rmesa
->state
.pixel_shader
.program
.alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
)
1757 | (rmesa
->state
.pixel_shader
.program
.alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
)
1758 | (rmesa
->state
.pixel_shader
.program
.tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
)
1759 | (rmesa
->state
.pixel_shader
.program
.tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
1761 R300_STATECHANGE(rmesa
, fpp
);
1762 for(i
=0;i
<rmesa
->state
.pixel_shader
.param_length
;i
++){
1763 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+0]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].x
);
1764 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+1]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].y
);
1765 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+2]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].z
);
1766 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+3]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].w
);
1768 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
]=cmducs(R300_PFS_PARAM_0_X
, rmesa
->state
.pixel_shader
.param_length
);
1773 * Called by Mesa after an internal state update.
1775 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
1777 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1779 _swrast_InvalidateState(ctx
, new_state
);
1780 _swsetup_InvalidateState(ctx
, new_state
);
1781 _ac_InvalidateState(ctx
, new_state
);
1782 _tnl_InvalidateState(ctx
, new_state
);
1783 _ae_invalidate_state(ctx
, new_state
);
1785 /* Go inefficiency! */
1786 r300ResetHwState(r300
);
1789 void update_zbias(GLcontext
* ctx
, int prim
);
1792 * Completely recalculates hardware state based on the Mesa state.
1794 void r300ResetHwState(r300ContextPtr r300
)
1796 GLcontext
* ctx
= r300
->radeon
.glCtx
;
1799 if (RADEON_DEBUG
& DEBUG_STATE
)
1800 fprintf(stderr
, "%s\n", __FUNCTION__
);
1802 /* This is a place to initialize registers which
1803 have bitfields accessed by different functions
1804 and not all bits are used */
1806 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] = 0;
1807 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] = 0;
1808 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] = 0xffff00;
1811 /* go and compute register values from GL state */
1813 r300UpdateWindow(ctx
);
1816 ctx
->Color
.ColorMask
[RCOMP
],
1817 ctx
->Color
.ColorMask
[GCOMP
],
1818 ctx
->Color
.ColorMask
[BCOMP
],
1819 ctx
->Color
.ColorMask
[ACOMP
]);
1821 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1822 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1823 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1825 r300UpdateCulling(ctx
);
1827 r300UpdateTextureState(ctx
);
1829 // r300_setup_routing(ctx, GL_TRUE);
1830 r300EmitArrays(ctx
, GL_TRUE
); /* Just do the routing */
1831 r300_setup_textures(ctx
);
1832 r300_setup_rs_unit(ctx
);
1834 r300SetupVertexShader(r300
);
1835 r300SetupPixelShader(r300
);
1837 r300_set_blend_state(ctx
);
1838 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1840 /* Initialize magic registers
1841 TODO : learn what they really do, or get rid of
1842 those we don't have to touch */
1843 r300
->hw
.unk2080
.cmd
[1] = 0x0030045A;
1845 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1846 | R300_VPORT_X_OFFSET_ENA
1847 | R300_VPORT_Y_SCALE_ENA
1848 | R300_VPORT_Y_OFFSET_ENA
1849 | R300_VPORT_Z_SCALE_ENA
1850 | R300_VPORT_Z_OFFSET_ENA
1852 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1854 r300
->hw
.unk2134
.cmd
[1] = 0x00FFFFFF;
1855 r300
->hw
.unk2134
.cmd
[2] = 0x00000000;
1856 #ifdef MESA_BIG_ENDIAN
1857 r300
->hw
.unk2140
.cmd
[1] = 0x00000002;
1859 r300
->hw
.unk2140
.cmd
[1] = 0x00000000;
1862 #if 0 /* Done in setup routing */
1863 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[0].cmd
)->unchecked_state
.count
= 1;
1864 r300
->hw
.vir
[0].cmd
[1] = 0x21030003;
1866 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[1].cmd
)->unchecked_state
.count
= 1;
1867 r300
->hw
.vir
[1].cmd
[1] = 0xF688F688;
1869 r300
->hw
.vic
.cmd
[R300_VIR_CNTL_0
] = 0x00000001;
1870 r300
->hw
.vic
.cmd
[R300_VIR_CNTL_1
] = 0x00000405;
1873 r300
->hw
.unk21DC
.cmd
[1] = 0xAAAAAAAA;
1875 r300
->hw
.unk221C
.cmd
[1] = R300_221C_NORMAL
;
1877 r300
->hw
.unk2220
.cmd
[1] = r300PackFloat32(1.0);
1878 r300
->hw
.unk2220
.cmd
[2] = r300PackFloat32(1.0);
1879 r300
->hw
.unk2220
.cmd
[3] = r300PackFloat32(1.0);
1880 r300
->hw
.unk2220
.cmd
[4] = r300PackFloat32(1.0);
1882 if (GET_CHIP(r300
->radeon
.radeonScreen
) == RADEON_CHIP_R300
)
1883 r300
->hw
.unk2288
.cmd
[1] = R300_2288_R300
;
1885 r300
->hw
.unk2288
.cmd
[1] = R300_2288_RV350
;
1888 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT
1889 | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT
;
1890 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = 0; /* no textures */
1893 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] = 0;
1894 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] = 0;
1895 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] = 0;
1898 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
1899 | R300_GB_LINE_STUFF_ENABLE
1900 | R300_GB_TRIANGLE_STUFF_ENABLE
;
1902 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
1903 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
1904 if (GET_CHIP(r300
->radeon
.radeonScreen
) == RADEON_CHIP_R300
)
1905 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] = R300_GB_TILE_ENABLE
1906 | R300_GB_TILE_PIPE_COUNT_R300
1907 | R300_GB_TILE_SIZE_16
;
1909 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] = R300_GB_TILE_ENABLE
1910 | R300_GB_TILE_PIPE_COUNT_RV300
1911 | R300_GB_TILE_SIZE_16
;
1912 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = 0x00000000;
1913 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = 0x00000000; /* No antialiasing */
1915 //r300->hw.txe.cmd[R300_TXE_ENABLE] = 0;
1917 r300
->hw
.unk4200
.cmd
[1] = r300PackFloat32(0.0);
1918 r300
->hw
.unk4200
.cmd
[2] = r300PackFloat32(0.0);
1919 r300
->hw
.unk4200
.cmd
[3] = r300PackFloat32(1.0);
1920 r300
->hw
.unk4200
.cmd
[4] = r300PackFloat32(1.0);
1922 r300
->hw
.unk4214
.cmd
[1] = 0x00050005;
1924 r300PointSize(ctx
, 0.0);
1926 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] = (6 << R300_POINTSIZE_X_SHIFT
) |
1927 (6 << R300_POINTSIZE_Y_SHIFT
);
1930 r300
->hw
.unk4230
.cmd
[1] = 0x01800000;
1931 r300
->hw
.unk4230
.cmd
[2] = 0x00020006;
1932 r300
->hw
.unk4230
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
1934 r300LineWidth(ctx
, 0.0);
1937 static int foobar
=0;
1938 r300
->hw
.lsf
.cmd
[1] = foobar
++; //0x3a088889;
1940 r300
->hw
.unk4260
.cmd
[1] = 0;
1941 r300
->hw
.unk4260
.cmd
[2] = r300PackFloat32(0.0);
1942 r300
->hw
.unk4260
.cmd
[3] = r300PackFloat32(1.0);
1944 r300
->hw
.unk4274
.cmd
[1] = 0x00000002;
1945 r300
->hw
.unk4274
.cmd
[2] = 0x0003AAAA;
1946 r300
->hw
.unk4274
.cmd
[3] = 0x00000000;
1947 r300
->hw
.unk4274
.cmd
[4] = 0x00000000;
1949 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
1950 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
1952 r300
->hw
.unk4288
.cmd
[1] = 0x00000000;
1954 r300
->hw
.unk4288
.cmd
[2] = 0x00000001;
1955 r300
->hw
.unk4288
.cmd
[3] = 0x00000000;
1956 r300
->hw
.unk4288
.cmd
[4] = 0x00000000;
1957 r300
->hw
.unk4288
.cmd
[5] = 0x00000000;
1959 r300
->hw
.unk42A0
.cmd
[1] = 0x00000000;
1961 update_zbias(ctx
, GL_TRIANGLES
);/* FIXME */
1963 r300
->hw
.unk42B4
.cmd
[1] = 0x00000000;
1965 r300
->hw
.unk42C0
.cmd
[1] = 0x4B7FFFFF;
1966 r300
->hw
.unk42C0
.cmd
[2] = 0x00000000;
1969 r300
->hw
.unk43A4
.cmd
[1] = 0x0000001C;
1970 r300
->hw
.unk43A4
.cmd
[2] = 0x2DA49525;
1972 r300
->hw
.unk43E8
.cmd
[1] = 0x00FFFFFF;
1975 r300
->hw
.fp
.cmd
[R300_FP_CNTL0
] = 0;
1976 r300
->hw
.fp
.cmd
[R300_FP_CNTL1
] = 0;
1977 r300
->hw
.fp
.cmd
[R300_FP_CNTL2
] = 0;
1978 r300
->hw
.fp
.cmd
[R300_FP_NODE0
] = 0;
1979 r300
->hw
.fp
.cmd
[R300_FP_NODE1
] = 0;
1980 r300
->hw
.fp
.cmd
[R300_FP_NODE2
] = 0;
1981 r300
->hw
.fp
.cmd
[R300_FP_NODE3
] = 0;
1984 r300
->hw
.unk46A4
.cmd
[1] = 0x00001B01;
1985 r300
->hw
.unk46A4
.cmd
[2] = 0x00001B0F;
1986 r300
->hw
.unk46A4
.cmd
[3] = 0x00001B0F;
1987 r300
->hw
.unk46A4
.cmd
[4] = 0x00001B0F;
1988 r300
->hw
.unk46A4
.cmd
[5] = 0x00000001;
1991 for(i
= 1; i
<= 64; ++i
) {
1992 /* create NOP instructions */
1993 r300
->hw
.fpi
[0].cmd
[i
] = FP_INSTRC(MAD
, FP_ARGC(SRC0C_XYZ
), FP_ARGC(ONE
), FP_ARGC(ZERO
));
1994 r300
->hw
.fpi
[1].cmd
[i
] = FP_SELC(0,XYZ
,NO
,FP_TMP(0),0,0);
1995 r300
->hw
.fpi
[2].cmd
[i
] = FP_INSTRA(MAD
, FP_ARGA(SRC0A
), FP_ARGA(ONE
), FP_ARGA(ZERO
));
1996 r300
->hw
.fpi
[3].cmd
[i
] = FP_SELA(0,W
,NO
,FP_TMP(0),0,0);
2000 r300
->hw
.unk4BC0
.cmd
[1] = 0;
2002 r300
->hw
.unk4BC8
.cmd
[1] = 0;
2003 r300
->hw
.unk4BC8
.cmd
[2] = 0;
2004 r300
->hw
.unk4BC8
.cmd
[3] = 0;
2006 //r300AlphaFunc(ctx, ctx->Color.AlphaFunc, ctx->Color.AlphaRef);
2008 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = 0;
2011 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
2012 r300
->hw
.unk4BD8
.cmd
[1] = 0;
2014 r300
->hw
.unk4E00
.cmd
[1] = 0;
2017 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = 0;
2018 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = 0;
2021 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
2023 r300
->hw
.unk4E10
.cmd
[1] = 0;
2025 r300
->hw
.unk4E10
.cmd
[2] = 0;
2026 r300
->hw
.unk4E10
.cmd
[3] = 0;
2028 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] =
2029 r300
->radeon
.radeonScreen
->backOffset
+
2030 r300
->radeon
.radeonScreen
->fbLocation
;
2031 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.radeonScreen
->backPitch
2032 | R300_COLOR_UNKNOWN_22_23
;
2034 r300
->hw
.unk4E50
.cmd
[1] = 0;
2035 r300
->hw
.unk4E50
.cmd
[2] = 0;
2036 r300
->hw
.unk4E50
.cmd
[3] = 0;
2037 r300
->hw
.unk4E50
.cmd
[4] = 0;
2038 r300
->hw
.unk4E50
.cmd
[5] = 0;
2039 r300
->hw
.unk4E50
.cmd
[6] = 0;
2040 r300
->hw
.unk4E50
.cmd
[7] = 0;
2041 r300
->hw
.unk4E50
.cmd
[8] = 0;
2042 r300
->hw
.unk4E50
.cmd
[9] = 0;
2044 r300
->hw
.unk4E88
.cmd
[1] = 0;
2046 r300
->hw
.unk4EA0
.cmd
[1] = 0x00000000;
2047 r300
->hw
.unk4EA0
.cmd
[2] = 0xffffffff;
2049 r300
->hw
.unk4F10
.cmd
[1] = 0x00000002; // depthbuffer format?
2050 r300
->hw
.unk4F10
.cmd
[2] = 0x00000000;
2051 r300
->hw
.unk4F10
.cmd
[3] = 0x00000003;
2052 r300
->hw
.unk4F10
.cmd
[4] = 0x00000000;
2054 /* experiment a bit */
2055 r300
->hw
.unk4F10
.cmd
[2] = 0x00000001; // depthbuffer format?
2057 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
2058 r300
->radeon
.radeonScreen
->depthOffset
+
2059 r300
->radeon
.radeonScreen
->fbLocation
;
2060 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
2062 r300
->hw
.unk4F28
.cmd
[1] = 0;
2064 r300
->hw
.unk4F30
.cmd
[1] = 0;
2065 r300
->hw
.unk4F30
.cmd
[2] = 0;
2067 r300
->hw
.unk4F44
.cmd
[1] = 0;
2069 r300
->hw
.unk4F54
.cmd
[1] = 0;
2072 ((drm_r300_cmd_header_t
*)r300
->hw
.vpi
.cmd
)->vpu
.count
= 0;
2073 for(i
= 1; i
< R300_VPI_CMDSIZE
; i
+= 4) {
2075 r300
->hw
.vpi
.cmd
[i
+0] = VP_OUT(ADD
,TMP
,0,XYZW
);
2076 r300
->hw
.vpi
.cmd
[i
+1] = VP_IN(TMP
,0);
2077 r300
->hw
.vpi
.cmd
[i
+2] = VP_ZERO();
2078 r300
->hw
.vpi
.cmd
[i
+3] = VP_ZERO();
2081 ((drm_r300_cmd_header_t
*)r300
->hw
.vpp
.cmd
)->vpu
.count
= 0;
2082 for(i
= 1; i
< R300_VPP_CMDSIZE
; ++i
)
2083 r300
->hw
.vpp
.cmd
[i
] = 0;
2086 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
2087 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
2088 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
2089 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
2093 r300
->hw
.all_dirty
= GL_TRUE
;
2099 * Calculate initial hardware state and register state functions.
2100 * Assumes that the command buffer and state atoms have been
2101 * initialized already.
2103 void r300InitState(r300ContextPtr r300
)
2105 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2108 radeonInitState(&r300
->radeon
);
2110 switch (ctx
->Visual
.depthBits
) {
2112 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2113 depth_fmt
= R200_DEPTH_FORMAT_16BIT_INT_Z
;
2114 //r300->state.stencil.clear = 0x00000000;
2117 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2118 depth_fmt
= R200_DEPTH_FORMAT_24BIT_INT_Z
;
2119 //r300->state.stencil.clear = 0xff000000;
2122 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2123 ctx
->Visual
.depthBits
);
2127 /* Only have hw stencil when depth buffer is 24 bits deep */
2128 r300
->state
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2129 ctx
->Visual
.depthBits
== 24);
2131 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2133 r300ResetHwState(r300
);
2138 * Initialize driver's state callback functions
2140 void r300InitStateFuncs(struct dd_function_table
* functions
)
2142 radeonInitStateFuncs(functions
);
2144 functions
->UpdateState
= r300InvalidateState
;
2145 functions
->AlphaFunc
= r300AlphaFunc
;
2146 functions
->BlendColor
= r300BlendColor
;
2147 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2148 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2149 functions
->Enable
= r300Enable
;
2150 functions
->ColorMask
= r300ColorMask
;
2151 functions
->DepthFunc
= r300DepthFunc
;
2152 functions
->DepthMask
= r300DepthMask
;
2153 functions
->CullFace
= r300CullFace
;
2154 functions
->FrontFace
= r300FrontFace
;
2156 /* Stencil related */
2157 functions
->ClearStencil
= r300ClearStencil
;
2158 functions
->StencilFunc
= r300StencilFunc
;
2159 functions
->StencilMask
= r300StencilMask
;
2160 functions
->StencilOp
= r300StencilOp
;
2162 /* Viewport related */
2163 functions
->Viewport
= r300Viewport
;
2164 functions
->DepthRange
= r300DepthRange
;
2165 functions
->PointSize
= r300PointSize
;
2166 functions
->LineWidth
= r300LineWidth
;
2168 functions
->PolygonOffset
= r300PolygonOffset
;
2169 functions
->PolygonMode
= r300PolygonMode
;