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"
62 #include "r300_fragprog.h"
64 #include "r300_fixed_pipelines.h"
65 #include "r300_texprog.h"
68 #include "r300_maos.h"
70 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
72 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
73 int pp_misc
= rmesa
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
];
76 CLAMPED_FLOAT_TO_UBYTE(refByte
, ref
);
78 R300_STATECHANGE(rmesa
, at
);
80 pp_misc
&= ~(R300_ALPHA_TEST_OP_MASK
| R300_REF_ALPHA_MASK
);
81 pp_misc
|= (refByte
& R300_REF_ALPHA_MASK
);
85 pp_misc
|= R300_ALPHA_TEST_FAIL
;
88 pp_misc
|= R300_ALPHA_TEST_LESS
;
91 pp_misc
|= R300_ALPHA_TEST_EQUAL
;
94 pp_misc
|= R300_ALPHA_TEST_LEQUAL
;
97 pp_misc
|= R300_ALPHA_TEST_GREATER
;
100 pp_misc
|= R300_ALPHA_TEST_NEQUAL
;
103 pp_misc
|= R300_ALPHA_TEST_GEQUAL
;
106 pp_misc
|= R300_ALPHA_TEST_PASS
;
107 //pp_misc &= ~R300_ALPHA_TEST_ENABLE;
111 rmesa
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
114 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
117 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
119 R300_STATECHANGE(rmesa
, unk4E10
);
121 /* Ordering might be wrong */
122 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
123 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
124 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
125 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
127 rmesa
->hw
.unk4E10
.cmd
[1]=r300PackColor(4, color
[0], color
[1], color
[2], color
[3]);
131 * Calculate the hardware blend factor setting. This same function is used
132 * for source and destination of both alpha and RGB.
135 * The hardware register value for the specified blend factor. This value
136 * will need to be shifted into the correct position for either source or
137 * destination factor.
140 * Since the two cases where source and destination are handled differently
141 * are essentially error cases, they should never happen. Determine if these
142 * cases can be removed.
144 static int blend_factor(GLenum factor
, GLboolean is_src
)
150 func
= R200_BLEND_GL_ZERO
;
153 func
= R200_BLEND_GL_ONE
;
156 func
= R200_BLEND_GL_DST_COLOR
;
158 case GL_ONE_MINUS_DST_COLOR
:
159 func
= R200_BLEND_GL_ONE_MINUS_DST_COLOR
;
162 func
= R200_BLEND_GL_SRC_COLOR
;
164 case GL_ONE_MINUS_SRC_COLOR
:
165 func
= R200_BLEND_GL_ONE_MINUS_SRC_COLOR
;
168 func
= R200_BLEND_GL_SRC_ALPHA
;
170 case GL_ONE_MINUS_SRC_ALPHA
:
171 func
= R200_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
174 func
= R200_BLEND_GL_DST_ALPHA
;
176 case GL_ONE_MINUS_DST_ALPHA
:
177 func
= R200_BLEND_GL_ONE_MINUS_DST_ALPHA
;
179 case GL_SRC_ALPHA_SATURATE
:
181 (is_src
) ? R200_BLEND_GL_SRC_ALPHA_SATURATE
:
184 case GL_CONSTANT_COLOR
:
185 func
= R200_BLEND_GL_CONST_COLOR
;
187 case GL_ONE_MINUS_CONSTANT_COLOR
:
188 func
= R200_BLEND_GL_ONE_MINUS_CONST_COLOR
;
190 case GL_CONSTANT_ALPHA
:
191 func
= R200_BLEND_GL_CONST_ALPHA
;
193 case GL_ONE_MINUS_CONSTANT_ALPHA
:
194 func
= R200_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
197 func
= (is_src
) ? R200_BLEND_GL_ONE
: R200_BLEND_GL_ZERO
;
203 * Sets both the blend equation and the blend function.
204 * This is done in a single
205 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
206 * change the interpretation of the blend function.
207 * Also, make sure that blend function and blend equation are set to their default
208 * value if color blending is not enabled, since at least blend equations GL_MIN
209 * and GL_FUNC_REVERSE_SUBTRACT will cause wrong results otherwise for
213 /* helper function */
214 static void r300_set_blend_cntl(r300ContextPtr r300
, int func
, int eqn
, int cbits
, int funcA
, int eqnA
)
216 GLuint new_ablend
, new_cblend
;
219 fprintf(stderr
, "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n", eqnA
, funcA
, eqn
, func
, cbits
);
221 new_ablend
= eqnA
| funcA
;
222 new_cblend
= eqn
| func
;
224 /* Some blend factor combinations don't seem to work when the
225 * BLEND_NO_SEPARATE bit is set.
227 * Especially problematic candidates are the ONE_MINUS_* flags,
228 * but I can't see a real pattern.
231 if (new_ablend
== new_cblend
) {
232 new_cblend
|= R300_BLEND_NO_SEPARATE
;
237 if((new_ablend
!= r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]) ||
238 (new_cblend
!= r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
])) {
239 R300_STATECHANGE(r300
, bld
);
240 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]=new_ablend
;
241 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
]=new_cblend
;
246 static void r300_set_blend_state(GLcontext
* ctx
)
248 r300ContextPtr r300
= R300_CONTEXT(ctx
);
249 int func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
250 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
251 int eqn
= R200_COMB_FCN_ADD_CLAMP
;
252 int funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
253 (R200_BLEND_GL_ZERO
<< R200_DST_BLEND_SHIFT
);
254 int eqnA
= R200_COMB_FCN_ADD_CLAMP
;
256 if (ctx
->Color
._LogicOpEnabled
|| !ctx
->Color
.BlendEnabled
) {
257 r300_set_blend_cntl(r300
,
263 func
= (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) << R200_SRC_BLEND_SHIFT
) |
264 (blend_factor(ctx
->Color
.BlendDstRGB
, GL_FALSE
) << R200_DST_BLEND_SHIFT
);
266 switch (ctx
->Color
.BlendEquationRGB
) {
268 eqn
= R300_COMB_FCN_ADD_CLAMP
;
271 case GL_FUNC_SUBTRACT
:
272 eqn
= R300_COMB_FCN_SUB_CLAMP
;
275 case GL_FUNC_REVERSE_SUBTRACT
:
276 eqn
= R200_COMB_FCN_RSUB_CLAMP
;
280 eqn
= R200_COMB_FCN_MIN
;
281 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
282 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
286 eqn
= R200_COMB_FCN_MAX
;
287 func
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
288 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
293 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
294 __func__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
299 funcA
= (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) << R200_SRC_BLEND_SHIFT
) |
300 (blend_factor(ctx
->Color
.BlendDstA
, GL_FALSE
) << R200_DST_BLEND_SHIFT
);
302 switch (ctx
->Color
.BlendEquationA
) {
304 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
307 case GL_FUNC_SUBTRACT
:
308 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
311 case GL_FUNC_REVERSE_SUBTRACT
:
312 eqnA
= R200_COMB_FCN_RSUB_CLAMP
;
316 eqnA
= R200_COMB_FCN_MIN
;
317 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
318 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
322 eqnA
= R200_COMB_FCN_MAX
;
323 funcA
= (R200_BLEND_GL_ONE
<< R200_SRC_BLEND_SHIFT
) |
324 (R200_BLEND_GL_ONE
<< R200_DST_BLEND_SHIFT
);
328 fprintf(stderr
, "[%s:%u] Invalid A blend equation (0x%04x).\n",
329 __func__
, __LINE__
, ctx
->Color
.BlendEquationA
);
333 r300_set_blend_cntl(r300
,
334 func
, eqn
, R300_BLEND_UNKNOWN
| R300_BLEND_ENABLE
,
338 static void r300BlendEquationSeparate(GLcontext
* ctx
,
339 GLenum modeRGB
, GLenum modeA
)
341 r300_set_blend_state(ctx
);
344 static void r300BlendFuncSeparate(GLcontext
* ctx
,
345 GLenum sfactorRGB
, GLenum dfactorRGB
,
346 GLenum sfactorA
, GLenum dfactorA
)
348 r300_set_blend_state(ctx
);
352 * Update our tracked culling state based on Mesa's state.
354 static void r300UpdateCulling(GLcontext
* ctx
)
356 r300ContextPtr r300
= R300_CONTEXT(ctx
);
359 R300_STATECHANGE(r300
, cul
);
360 if (ctx
->Polygon
.CullFlag
) {
361 if (ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
362 val
= R300_CULL_FRONT
|R300_CULL_BACK
;
363 else if (ctx
->Polygon
.CullFaceMode
== GL_FRONT
)
364 val
= R300_CULL_FRONT
;
366 val
= R300_CULL_BACK
;
368 if (ctx
->Polygon
.FrontFace
== GL_CW
)
369 val
|= R300_FRONT_FACE_CW
;
371 val
|= R300_FRONT_FACE_CCW
;
373 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
376 static void update_early_z(GLcontext
* ctx
)
378 /* updates register 0x4f14
379 if depth test is not enabled it should be 0x00000000
380 if depth is enabled and alpha not it should be 0x00000001
381 if depth and alpha is enabled it should be 0x00000000
383 r300ContextPtr r300
= R300_CONTEXT(ctx
);
385 R300_STATECHANGE(r300
, unk4F10
);
386 if (ctx
->Color
.AlphaEnabled
)
387 /* disable early Z */
388 r300
->hw
.unk4F10
.cmd
[2] = 0x00000000;
392 r300
->hw
.unk4F10
.cmd
[2] = 0x00000001;
394 /* disable early Z */
395 r300
->hw
.unk4F10
.cmd
[2] = 0x00000000;
400 * Handle glEnable()/glDisable().
402 * \note Mesa already filters redundant calls to glEnable/glDisable.
404 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
406 r300ContextPtr r300
= R300_CONTEXT(ctx
);
409 if (RADEON_DEBUG
& DEBUG_STATE
)
410 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
411 _mesa_lookup_enum_by_nr(cap
),
412 state
? "GL_TRUE" : "GL_FALSE");
415 /* Fast track this one...
423 R300_STATECHANGE(r300
, at
);
425 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] |=
426 R300_ALPHA_TEST_ENABLE
;
428 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] &=
429 ~R300_ALPHA_TEST_ENABLE
;
435 case GL_COLOR_LOGIC_OP
:
436 r300_set_blend_state(ctx
);
440 R300_STATECHANGE(r300
, zs
);
444 newval
= R300_RB3D_Z_TEST_AND_WRITE
;
446 newval
= R300_RB3D_Z_TEST
;
448 newval
= R300_RB3D_Z_DISABLED_1
;
450 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &= R300_RB3D_STENCIL_ENABLE
;
451 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= newval
;
455 case GL_STENCIL_TEST
:
456 WARN_ONCE("TODO - double side stencil !\n");
457 if (r300
->state
.stencil
.hw_stencil
) {
458 R300_STATECHANGE(r300
, zs
);
460 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
461 R300_RB3D_STENCIL_ENABLE
;
463 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
464 ~R300_RB3D_STENCIL_ENABLE
;
468 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_STENCIL
, state
);
474 r300UpdateCulling(ctx
);
477 case GL_POLYGON_OFFSET_POINT
:
478 case GL_POLYGON_OFFSET_LINE
:
481 case GL_POLYGON_OFFSET_FILL
:
482 R300_STATECHANGE(r300
, unk42B4
);
484 r300
->hw
.unk42B4
.cmd
[1] |= (3<<0);
486 r300
->hw
.unk42B4
.cmd
[1] &= ~(3<<0);
490 radeonEnable(ctx
, cap
, state
);
496 static void r300UpdatePolygonMode(GLcontext
*ctx
)
498 r300ContextPtr r300
= R300_CONTEXT(ctx
);
501 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
502 ctx
->Polygon
.BackMode
!= GL_FILL
) {
505 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
506 f
= ctx
->Polygon
.FrontMode
;
507 b
= ctx
->Polygon
.BackMode
;
509 f
= ctx
->Polygon
.BackMode
;
510 b
= ctx
->Polygon
.FrontMode
;
513 hw_mode
|= R300_PM_ENABLED
;
517 hw_mode
|= R300_PM_FRONT_LINE
;
519 case GL_POINT
: /* noop */
520 hw_mode
|= R300_PM_FRONT_POINT
;
523 hw_mode
|= R300_PM_FRONT_FILL
;
529 hw_mode
|= R300_PM_BACK_LINE
;
531 case GL_POINT
: /* noop */
532 hw_mode
|= R300_PM_BACK_POINT
;
535 hw_mode
|= R300_PM_BACK_FILL
;
540 if (r300
->hw
.unk4288
.cmd
[1] != hw_mode
) {
541 R300_STATECHANGE(r300
, unk4288
);
542 r300
->hw
.unk4288
.cmd
[1] = hw_mode
;
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
);
569 r300UpdatePolygonMode(ctx
);
574 * Change the depth testing function.
576 * \note Mesa already filters redundant calls to this function.
578 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
580 r300ContextPtr r300
= R300_CONTEXT(ctx
);
582 R300_STATECHANGE(r300
, zs
);
584 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
);
588 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_NEVER
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
591 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_LESS
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
594 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_EQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
597 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_LEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
600 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_GREATER
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
603 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_NOTEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
606 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= R300_ZS_GEQUAL
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
609 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
] &= R300_RB3D_STENCIL_ENABLE
;
629 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= mask
630 ? R300_RB3D_Z_TEST_AND_WRITE
: R300_RB3D_Z_TEST
;
635 * Handle glColorMask()
637 static void r300ColorMask(GLcontext
* ctx
,
638 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
640 r300ContextPtr r300
= R300_CONTEXT(ctx
);
641 int mask
= (r
? R300_COLORMASK0_R
: 0) |
642 (g
? R300_COLORMASK0_G
: 0) |
643 (b
? R300_COLORMASK0_B
: 0) |
644 (a
? R300_COLORMASK0_A
: 0);
646 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
647 R300_STATECHANGE(r300
, cmk
);
648 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
652 /* =============================================================
655 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
657 r300ContextPtr r300
= R300_CONTEXT(ctx
);
659 size
= ctx
->Point
._Size
;
661 R300_STATECHANGE(r300
, ps
);
662 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
663 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
664 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
667 /* =============================================================
670 static void r300LineWidth(GLcontext
*ctx
, GLfloat widthf
)
672 r300ContextPtr r300
= R300_CONTEXT(ctx
);
674 widthf
= ctx
->Line
._Width
;
676 R300_STATECHANGE(r300
, lcntl
);
677 r300
->hw
.lcntl
.cmd
[1] = (int)(widthf
* 6.0);
678 r300
->hw
.lcntl
.cmd
[1] |= R300_LINE_CNT_VE
;
681 static void r300PolygonMode(GLcontext
*ctx
, GLenum face
, GLenum mode
)
686 r300UpdatePolygonMode(ctx
);
689 /* =============================================================
693 static int translate_stencil_func(int func
)
697 return R300_ZS_NEVER
;
701 return R300_ZS_EQUAL
;
703 return R300_ZS_LEQUAL
;
705 return R300_ZS_GREATER
;
707 return R300_ZS_NOTEQUAL
;
709 return R300_ZS_GEQUAL
;
711 return R300_ZS_ALWAYS
;
716 static int translate_stencil_op(int op
)
724 return R300_ZS_REPLACE
;
729 case GL_INCR_WRAP_EXT
:
730 return R300_ZS_INCR_WRAP
;
731 case GL_DECR_WRAP_EXT
:
732 return R300_ZS_DECR_WRAP
;
734 return R300_ZS_INVERT
;
736 WARN_ONCE("Do not know how to translate stencil op");
742 static void r300ShadeModel(GLcontext
* ctx
, GLenum mode
)
744 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
746 R300_STATECHANGE(rmesa
, unk4274
);
749 rmesa
->hw
.unk4274
.cmd
[2] = R300_RE_SHADE_MODEL_FLAT
;
752 rmesa
->hw
.unk4274
.cmd
[2] = R300_RE_SHADE_MODEL_SMOOTH
;
759 static void r300StencilFunc(GLcontext
* ctx
, GLenum func
,
760 GLint ref
, GLuint mask
)
762 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
763 GLuint refmask
= ((ctx
->Stencil
.Ref
[0] << R300_RB3D_ZS2_STENCIL_REF_SHIFT
) |
764 (ctx
->Stencil
.ValueMask
[0] << R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
768 R300_STATECHANGE(rmesa
, zs
);
770 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(
771 (R300_ZS_MASK
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
772 | (R300_ZS_MASK
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
));
774 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &= ~((R300_RB3D_ZS2_STENCIL_MASK
<< R300_RB3D_ZS2_STENCIL_REF_SHIFT
) |
775 (R300_RB3D_ZS2_STENCIL_MASK
<< R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
777 flag
= translate_stencil_func(ctx
->Stencil
.Function
[0]);
779 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |= (flag
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
780 | (flag
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
781 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
784 static void r300StencilMask(GLcontext
* ctx
, GLuint mask
)
786 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
788 R300_STATECHANGE(rmesa
, zs
);
789 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &= ~(R300_RB3D_ZS2_STENCIL_MASK
<< R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
);
790 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= ctx
->Stencil
.WriteMask
[0] << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
;
794 static void r300StencilOp(GLcontext
* ctx
, GLenum fail
,
795 GLenum zfail
, GLenum zpass
)
797 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
799 R300_STATECHANGE(rmesa
, zs
);
800 /* It is easier to mask what's left.. */
801 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
802 (R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
) |
803 (R300_ZS_MASK
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
) |
804 (R300_ZS_MASK
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
806 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
807 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) << R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT
)
808 |(translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT
)
809 |(translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT
)
810 |(translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) << R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
811 |(translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) << R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
812 |(translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) << R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
815 static void r300ClearStencil(GLcontext
* ctx
, GLint s
)
817 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
819 rmesa
->state
.stencil
.clear
=
820 ((GLuint
) ctx
->Stencil
.Clear
|
821 (R300_RB3D_ZS2_STENCIL_MASK
<< R300_RB3D_ZS2_STENCIL_MASK_SHIFT
) |
822 (ctx
->Stencil
.WriteMask
[0] << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
));
825 /* =============================================================
826 * Window position and viewport transformation
830 * To correctly position primitives:
832 #define SUBPIXEL_X 0.125
833 #define SUBPIXEL_Y 0.125
835 void r300UpdateWindow(GLcontext
* ctx
)
837 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
838 __DRIdrawablePrivate
*dPriv
= rmesa
->radeon
.dri
.drawable
;
839 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
840 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
841 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
843 GLfloat sx
= v
[MAT_SX
];
844 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
845 GLfloat sy
= -v
[MAT_SY
];
846 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
847 GLfloat sz
= v
[MAT_SZ
] * rmesa
->state
.depth
.scale
;
848 GLfloat tz
= v
[MAT_TZ
] * rmesa
->state
.depth
.scale
;
850 R300_FIREVERTICES(rmesa
);
851 R300_STATECHANGE(rmesa
, vpt
);
853 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
854 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
855 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
856 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
857 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
858 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
861 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
862 GLsizei width
, GLsizei height
)
864 /* Don't pipeline viewport changes, conflict with window offset
865 * setting below. Could apply deltas to rescue pipelined viewport
866 * values, or keep the originals hanging around.
868 R300_FIREVERTICES(R300_CONTEXT(ctx
));
869 r300UpdateWindow(ctx
);
872 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
874 r300UpdateWindow(ctx
);
877 /* =============================================================
880 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
882 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
883 GLfloat constant
= units
;
885 switch (ctx
->Visual
.depthBits
) {
896 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
898 R300_STATECHANGE(rmesa
, zbs
);
899 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
900 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
901 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
902 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
905 /* Routing and texture-related */
907 static r300TexObj default_tex_obj
={
908 filter
:R300_TX_MAG_FILTER_LINEAR
| R300_TX_MIN_FILTER_LINEAR
,
910 size
: (0xff << R300_TX_WIDTHMASK_SHIFT
)
911 | (0xff << R300_TX_HEIGHTMASK_SHIFT
)
912 | (0x8 << R300_TX_SIZE_SHIFT
),
919 /* there is probably a system to these value, but, for now,
920 we just try by hand */
922 static int inline translate_src(int src
)
931 case GL_PRIMARY_COLOR
:
948 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
949 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
950 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
951 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
952 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
953 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
954 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
955 * combinations where only one of them is nearest.
957 static unsigned long gen_fixed_filter(unsigned long f
)
959 unsigned long mag
, min
, needs_fixing
=0;
962 /* We ignore MIRROR bit so we dont have to do everything twice */
963 if((f
& ((7-1) << R300_TX_WRAP_S_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)){
966 if((f
& ((7-1) << R300_TX_WRAP_T_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)){
969 if((f
& ((7-1) << R300_TX_WRAP_Q_SHIFT
)) == (R300_TX_CLAMP
<< R300_TX_WRAP_Q_SHIFT
)){
976 mag
=f
& R300_TX_MAG_FILTER_MASK
;
977 min
=f
& R300_TX_MIN_FILTER_MASK
;
979 /* TODO: Check for anisto filters too */
980 if((mag
!= R300_TX_MAG_FILTER_NEAREST
) && (min
!= R300_TX_MIN_FILTER_NEAREST
))
983 /* r300 cant handle these modes hence we force nearest to linear */
984 if((mag
== R300_TX_MAG_FILTER_NEAREST
) && (min
!= R300_TX_MIN_FILTER_NEAREST
)){
985 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
986 f
|= R300_TX_MAG_FILTER_LINEAR
;
990 if((min
== R300_TX_MIN_FILTER_NEAREST
) && (mag
!= R300_TX_MAG_FILTER_NEAREST
)){
991 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
992 f
|= R300_TX_MIN_FILTER_LINEAR
;
996 /* Both are nearest */
997 if(needs_fixing
& 1){
998 f
&= ~((7-1) << R300_TX_WRAP_S_SHIFT
);
999 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1001 if(needs_fixing
& 2){
1002 f
&= ~((7-1) << R300_TX_WRAP_T_SHIFT
);
1003 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1005 if(needs_fixing
& 4){
1006 f
&= ~((7-1) << R300_TX_WRAP_Q_SHIFT
);
1007 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_Q_SHIFT
;
1012 void r300_setup_textures(GLcontext
*ctx
)
1015 struct r300_tex_obj
*t
;
1016 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1017 int max_texture_unit
=-1; /* -1 translates into no setup costs for fields */
1018 struct gl_texture_unit
*texUnit
;
1019 GLuint OutputsWritten
;
1022 OutputsWritten
= CURRENT_VERTEX_SHADER(ctx
)->OutputsWritten
;
1024 R300_STATECHANGE(r300
, txe
);
1025 R300_STATECHANGE(r300
, tex
.filter
);
1026 R300_STATECHANGE(r300
, tex
.unknown1
);
1027 R300_STATECHANGE(r300
, tex
.size
);
1028 R300_STATECHANGE(r300
, tex
.format
);
1029 R300_STATECHANGE(r300
, tex
.offset
);
1030 R300_STATECHANGE(r300
, tex
.unknown4
);
1031 R300_STATECHANGE(r300
, tex
.border_color
);
1033 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
]=0x0;
1035 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1036 if (RADEON_DEBUG
& DEBUG_STATE
)
1037 fprintf(stderr
, "mtu=%d\n", mtu
);
1039 if(mtu
> R300_MAX_TEXTURE_UNITS
) {
1040 fprintf(stderr
, "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1041 mtu
, R300_MAX_TEXTURE_UNITS
);
1045 for(i
=0; i
< mtu
; i
++) {
1046 /*if( ((r300->state.render_inputs & (_TNL_BIT_TEX0<<i))!=0) != ((ctx->Texture.Unit[i].Enabled)!=0) ) {
1047 WARN_ONCE("Mismatch between render_inputs and ctx->Texture.Unit[i].Enabled value(%d vs %d).\n",
1048 ((r300->state.render_inputs & (_TNL_BIT_TEX0<<i))!=0), ((ctx->Texture.Unit[i].Enabled)!=0));
1051 if(TMU_ENABLED(ctx
, i
)) {
1052 t
=r300
->state
.texture
.unit
[i
].texobj
;
1053 //fprintf(stderr, "format=%08x\n", r300->state.texture.unit[i].format);
1056 fprintf(stderr
, "Texture unit %d enabled, but corresponding texobj is NULL, using default object.\n", i
);
1061 //fprintf(stderr, "t->format=%08x\n", t->format);
1062 if((t
->format
& 0xffffff00)==0xffffff00) {
1063 WARN_ONCE("unknown texture format (entry %x) encountered. Help me !\n", t
->format
& 0xff);
1064 //fprintf(stderr, "t->format=%08x\n", t->format);
1067 if (RADEON_DEBUG
& DEBUG_STATE
)
1068 fprintf(stderr
, "Activating texture unit %d\n", i
);
1070 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
]|=(1<<i
);
1072 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+i
]=gen_fixed_filter(t
->filter
) | (i
<< 28);
1073 //r300->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+i]=0x0; /* move lod bias here? */
1075 /* No idea why linear filtered textures shake when puting random data */
1076 /*r300->hw.tex.unknown1.cmd[R300_TEX_VALUE_0+i]=(rand()%0xffffffff) & (~0x1fff);*/
1077 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+i
]=t
->size
;
1078 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+i
]=t
->format
;
1079 //fprintf(stderr, "t->format=%08x\n", t->format);
1080 r300
->hw
.tex
.offset
.cmd
[R300_TEX_VALUE_0
+i
]=t
->offset
;
1081 r300
->hw
.tex
.unknown4
.cmd
[R300_TEX_VALUE_0
+i
]=0x0;
1082 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+i
]=t
->pp_border_color
;
1086 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.filter
.cmd
)->packet0
.count
= max_texture_unit
+1;
1087 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.unknown1
.cmd
)->packet0
.count
= max_texture_unit
+1;
1088 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.size
.cmd
)->packet0
.count
= max_texture_unit
+1;
1089 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.format
.cmd
)->packet0
.count
= max_texture_unit
+1;
1090 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.offset
.cmd
)->packet0
.count
= max_texture_unit
+1;
1091 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.unknown4
.cmd
)->packet0
.count
= max_texture_unit
+1;
1092 ((drm_r300_cmd_header_t
*)r300
->hw
.tex
.border_color
.cmd
)->packet0
.count
= max_texture_unit
+1;
1094 if (RADEON_DEBUG
& DEBUG_STATE
)
1095 fprintf(stderr
, "TX_ENABLE: %08x max_texture_unit=%d\n", r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], max_texture_unit
);
1098 #if USE_ARB_F_P == 1
1099 void r300_setup_rs_unit(GLcontext
*ctx
)
1101 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1102 /* I'm still unsure if these are needed */
1103 GLuint interp_magic
[8] = {
1113 GLuint OutputsWritten
;
1115 int vp_reg
, fp_reg
, high_rr
;
1116 int in_texcoords
, col_interp_nr
;
1120 OutputsWritten
= CURRENT_VERTEX_SHADER(ctx
)->OutputsWritten
;
1122 OutputsWritten
= r300
->state
.render_inputs
;
1124 if (ctx
->FragmentProgram
._Current
)
1125 InputsRead
= ctx
->FragmentProgram
._Current
->InputsRead
;
1127 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1128 return; /* This should only ever happen once.. */
1131 R300_STATECHANGE(r300
, ri
);
1132 R300_STATECHANGE(r300
, rc
);
1133 R300_STATECHANGE(r300
, rr
);
1135 vp_reg
= fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1136 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] = 0;
1137 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] = 0;
1139 for (i
=0;i
<ctx
->Const
.MaxTextureUnits
;i
++) {
1140 if (OutputsWritten
& (hw_tcl_on
? (1 << (VERT_RESULT_TEX0
+i
)) : (_TNL_BIT_TEX0
<<i
)))
1143 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+i
] = 0
1144 | R300_RS_INTERP_USED
1145 | (vp_reg
<< R300_RS_INTERP_SRC_SHIFT
)
1148 if (InputsRead
& (FRAG_BIT_TEX0
<<i
)) {
1149 //assert(r300->state.texture.tc_count != 0);
1150 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ fp_reg
] = 0
1151 | R300_RS_ROUTE_ENABLE
1152 | i
/* source INTERP */
1153 | (fp_reg
<< R300_RS_ROUTE_DEST_SHIFT
);
1156 if (OutputsWritten
& (hw_tcl_on
? (1 << (VERT_RESULT_TEX0
+i
)) : (_TNL_BIT_TEX0
<<i
))) {
1159 /* Unsure of how to handle this situation, for now print errors and
1160 * the program will just recieve bogus data
1162 fprintf(stderr
, "fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1164 InputsRead
&= ~(FRAG_BIT_TEX0
<<i
);
1169 if (InputsRead
& FRAG_BIT_COL0
) {
1170 if (!(OutputsWritten
& (hw_tcl_on
? (1<<VERT_RESULT_COL0
) : _TNL_BIT_COLOR0
)))
1171 fprintf(stderr
, "fragprog wants col0, vp doesn't provide it\n");
1173 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0
1174 | R300_RS_ROUTE_0_COLOR
1175 | (fp_reg
++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT
);
1176 InputsRead
&= ~FRAG_BIT_COL0
;
1180 if (InputsRead
& FRAG_BIT_COL1
) {
1181 if (!(OutputsWritten
& (hw_tcl_on
? (1<<VERT_RESULT_COL1
) : _TNL_BIT_COLOR1
)))
1182 fprintf(stderr
, "fragprog wants col1, vp doesn't provide it\n");
1184 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] |= R300_RS_ROUTE_1_UNKNOWN11
1185 | R300_RS_ROUTE_1_COLOR1
1186 | (fp_reg
++ << R300_RS_ROUTE_1_COLOR1_DEST_SHIFT
);
1187 InputsRead
&= ~FRAG_BIT_COL1
;
1188 if (high_rr
< 1) high_rr
= 1;
1192 r300
->hw
.rc
.cmd
[1] = 0
1193 | (in_texcoords
<< R300_RS_CNTL_TC_CNT_SHIFT
)
1194 | (col_interp_nr
<< R300_RS_CNTL_CI_CNT_SHIFT
)
1195 | R300_RS_CNTL_0_UNKNOWN_18
;
1197 assert(high_rr
>= 0);
1198 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_ROUTE_0
, high_rr
+1);
1199 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1202 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1205 void r300_setup_rs_unit(GLcontext
*ctx
)
1207 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1209 /* I'm still unsure if these are needed */
1210 GLuint interp_magic
[8] = {
1220 GLuint OutputsWritten
;
1223 OutputsWritten
= CURRENT_VERTEX_SHADER(ctx
)->OutputsWritten
;
1225 /* This needs to be rewritten - it is a hack at best */
1227 R300_STATECHANGE(r300
, ri
);
1228 R300_STATECHANGE(r300
, rc
);
1229 R300_STATECHANGE(r300
, rr
);
1232 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] = 0;
1234 for (i
=0;i
<ctx
->Const
.MaxTextureUnits
;i
++) {
1235 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+i
] = 0
1236 | R300_RS_INTERP_USED
1237 | (cur_reg
<< R300_RS_INTERP_SRC_SHIFT
)
1239 // fprintf(stderr, "RS_INTERP[%d] = 0x%x\n", i, r300->hw.ri.cmd[R300_RI_INTERP_0+i]);
1241 if (TMU_ENABLED(ctx
, i
)) {
1242 assert(r300
->state
.texture
.tc_count
!= 0);
1243 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ cur_reg
] = 0
1244 | R300_RS_ROUTE_ENABLE
1245 | i
/* source INTERP */
1246 | (cur_reg
<< R300_RS_ROUTE_DEST_SHIFT
);
1247 // fprintf(stderr, "RS_ROUTE[%d] = 0x%x\n", cur_reg, r300->hw.rr.cmd[R300_RR_ROUTE_0 + cur_reg]);
1251 if (hw_tcl_on
? OutputsWritten
& (1<<VERT_RESULT_COL0
) : r300
->state
.render_inputs
& _TNL_BIT_COLOR0
)
1252 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0
1253 | R300_RS_ROUTE_0_COLOR
1254 | (cur_reg
<< R300_RS_ROUTE_0_COLOR_DEST_SHIFT
);
1256 // fprintf(stderr, "ADJ_RR0 = 0x%x\n", r300->hw.rr.cmd[R300_RR_ROUTE_0]);
1258 r300
->hw
.rc
.cmd
[1] = 0
1259 | (cur_reg
/* count */ << R300_RS_CNTL_TC_CNT_SHIFT
)
1260 | R300_RS_CNTL_0_UNKNOWN_7
1261 | R300_RS_CNTL_0_UNKNOWN_18
;
1263 if (r300
->state
.texture
.tc_count
> 0) {
1264 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_ROUTE_0
, cur_reg
);
1265 r300
->hw
.rc
.cmd
[2] = 0xC0 | (cur_reg
-1); /* index of highest */
1267 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_ROUTE_0
, 1);
1268 r300
->hw
.rc
.cmd
[2] = 0x0;
1272 // fprintf(stderr, "rendering with %d texture co-ordinate sets\n", cur_reg);
1274 #endif // USE_ARB_F_P
1276 #define vpucount(ptr) (((drm_r300_cmd_header_t*)(ptr))->vpu.count)
1278 #define bump_vpu_count(ptr, new_count) do{\
1279 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1280 int _nc=(new_count)/4; \
1281 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1284 void static inline setup_vertex_shader_fragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1288 if(vsf
->length
==0)return;
1290 if(vsf
->length
& 0x3){
1291 fprintf(stderr
,"VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1295 switch((dest
>>8) & 0xf){
1297 R300_STATECHANGE(r300
, vpi
);
1298 for(i
=0;i
<vsf
->length
;i
++)
1299 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1300 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+4*(dest
& 0xff));
1304 R300_STATECHANGE(r300
, vpp
);
1305 for(i
=0;i
<vsf
->length
;i
++)
1306 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1307 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+4*(dest
& 0xff));
1310 R300_STATECHANGE(r300
, vps
);
1311 for(i
=0;i
<vsf
->length
;i
++)
1312 r300
->hw
.vps
.cmd
[1+i
+4*(dest
& 0xff)]=(vsf
->body
.d
[i
]);
1313 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+4*(dest
& 0xff));
1316 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1321 void r300SetupVertexProgram(r300ContextPtr rmesa
);
1323 /* just a skeleton for now.. */
1325 /* Generate a vertex shader that simply transforms vertex and texture coordinates,
1326 while leaving colors intact. Nothing fancy (like lights)
1328 If implementing lights make a copy first, so it is easy to switch between the two versions */
1329 void r300GenerateSimpleVertexShader(r300ContextPtr r300
)
1334 /* Allocate parameters */
1335 r300
->state
.vap_param
.transform_offset
=0x0; /* transform matrix */
1336 r300
->state
.vertex_shader
.param_offset
=0x0;
1337 r300
->state
.vertex_shader
.param_count
=0x4; /* 4 vector values - 4x4 matrix */
1339 r300
->state
.vertex_shader
.program_start
=0x0;
1340 r300
->state
.vertex_shader
.unknown_ptr1
=0x4; /* magic value ? */
1341 r300
->state
.vertex_shader
.program_end
=0x0;
1343 r300
->state
.vertex_shader
.unknown_ptr2
=0x0; /* magic value */
1344 r300
->state
.vertex_shader
.unknown_ptr3
=0x4; /* magic value */
1346 /* Initialize matrix and vector parameters.. these should really be restructured */
1347 /* TODO: fix vertex_shader structure */
1348 r300
->state
.vertex_shader
.matrix
[0].length
=16;
1349 r300
->state
.vertex_shader
.matrix
[1].length
=0;
1350 r300
->state
.vertex_shader
.matrix
[2].length
=0;
1351 r300
->state
.vertex_shader
.vector
[0].length
=0;
1352 r300
->state
.vertex_shader
.vector
[1].length
=0;
1353 r300
->state
.vertex_shader
.unknown1
.length
=0;
1354 r300
->state
.vertex_shader
.unknown2
.length
=0;
1356 #define WRITE_OP(oper,source1,source2,source3) {\
1357 r300->state.vertex_shader.program.body.i[r300->state.vertex_shader.program_end].op=(oper); \
1358 r300->state.vertex_shader.program.body.i[r300->state.vertex_shader.program_end].src1=(source1); \
1359 r300->state.vertex_shader.program.body.i[r300->state.vertex_shader.program_end].src2=(source2); \
1360 r300->state.vertex_shader.program.body.i[r300->state.vertex_shader.program_end].src3=(source3); \
1361 r300->state.vertex_shader.program_end++; \
1364 /* Multiply vertex coordinates with transform matrix */
1367 EASY_VSF_OP(MUL
, 0, ALL
, TMP
),
1370 EASY_VSF_SOURCE(0, W
, W
, W
, W
, NONE
, NONE
)
1374 EASY_VSF_OP(MUL
, 1, ALL
, RESULT
),
1381 EASY_VSF_OP(MAD
, 0, ALL
, TMP
),
1388 EASY_VSF_OP(MAD
, 0, ALL
, TMP
),
1395 EASY_VSF_OP(MAD
, 0, ALL
, RESULT
),
1402 if (r300
->state
.render_inputs
& _TNL_BIT_COLOR1
) {
1404 EASY_VSF_OP(MUL
, o_reg
++, ALL
, RESULT
),
1405 VSF_REG(r300
->state
.vap_reg
.i_color
[1]),
1406 VSF_ATTR_UNITY(r300
->state
.vap_reg
.i_color
[1]),
1407 VSF_UNITY(r300
->state
.vap_reg
.i_color
[1])
1411 /* Pass through texture coordinates, if any */
1412 for(i
=0;i
< r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;i
++)
1413 if(r300
->state
.render_inputs
& (_TNL_BIT_TEX0
<<i
)){
1414 // fprintf(stderr, "i_tex[%d]=%d\n", i, r300->state.vap_reg.i_tex[i]);
1416 EASY_VSF_OP(MUL
, o_reg
++ /* 2+i */, ALL
, RESULT
),
1417 VSF_REG(r300
->state
.vap_reg
.i_tex
[i
]),
1418 VSF_ATTR_UNITY(r300
->state
.vap_reg
.i_tex
[i
]),
1419 VSF_UNITY(r300
->state
.vap_reg
.i_tex
[i
])
1423 r300
->state
.vertex_shader
.program_end
--; /* r300 wants program length to be one more - no idea why */
1424 r300
->state
.vertex_shader
.program
.length
=(r300
->state
.vertex_shader
.program_end
+1)*4;
1426 r300
->state
.vertex_shader
.unknown_ptr1
=r300
->state
.vertex_shader
.program_end
; /* magic value ? */
1427 r300
->state
.vertex_shader
.unknown_ptr2
=r300
->state
.vertex_shader
.program_end
; /* magic value ? */
1428 r300
->state
.vertex_shader
.unknown_ptr3
=r300
->state
.vertex_shader
.program_end
; /* magic value ? */
1433 void r300SetupVertexShader(r300ContextPtr rmesa
)
1435 GLcontext
* ctx
= rmesa
->radeon
.glCtx
;
1436 struct r300_vertex_shader_fragment unk4
={
1439 /*0.0*/(rand()%100)/10.0,
1440 /*0.0*/(rand()%100)/10.0,
1441 /*1.0*/(rand()%100)/10.0,
1442 /*0.0*/(rand()%100)/10.0
1447 /* Reset state, in case we don't use something */
1448 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1449 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1450 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1452 /* Not sure why this doesnt work...
1453 0x400 area might have something to do with pixel shaders as it appears right after pfs programming.
1454 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. */
1455 //setup_vertex_shader_fragment(rmesa, 0x406, &unk4);
1456 if(hw_tcl_on
&& ((struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
))->translated
){
1457 r300SetupVertexProgram(rmesa
);
1461 /* This needs to be replaced by vertex shader generation code */
1465 /* textures enabled ? */
1466 if(rmesa
->state
.texture
.tc_count
>0){
1467 rmesa
->state
.vertex_shader
=SINGLE_TEXTURE_VERTEX_SHADER
;
1469 rmesa
->state
.vertex_shader
=FLAT_COLOR_VERTEX_SHADER
;
1473 r300GenerateSimpleVertexShader(rmesa
);
1475 rmesa
->state
.vertex_shader
.matrix
[0].length
=16;
1476 memcpy(rmesa
->state
.vertex_shader
.matrix
[0].body
.f
, ctx
->_ModelProjectMatrix
.m
, 16*4);
1478 setup_vertex_shader_fragment(rmesa
, VSF_DEST_PROGRAM
, &(rmesa
->state
.vertex_shader
.program
));
1480 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX0
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1482 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX1
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1483 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX2
, &(rmesa
->state
.vertex_shader
.matrix
[0]));
1485 setup_vertex_shader_fragment(rmesa
, VSF_DEST_VECTOR0
, &(rmesa
->state
.vertex_shader
.vector
[0]));
1486 setup_vertex_shader_fragment(rmesa
, VSF_DEST_VECTOR1
, &(rmesa
->state
.vertex_shader
.vector
[1]));
1490 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN1
, &(rmesa
->state
.vertex_shader
.unknown1
));
1491 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN2
, &(rmesa
->state
.vertex_shader
.unknown2
));
1494 R300_STATECHANGE(rmesa
, pvs
);
1495 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
]=(rmesa
->state
.vertex_shader
.program_start
<< R300_PVS_CNTL_1_PROGRAM_START_SHIFT
)
1496 | (rmesa
->state
.vertex_shader
.unknown_ptr1
<< R300_PVS_CNTL_1_POS_END_SHIFT
)
1497 | (rmesa
->state
.vertex_shader
.program_end
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1498 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
]=(rmesa
->state
.vertex_shader
.param_offset
<< R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
)
1499 | (rmesa
->state
.vertex_shader
.param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1500 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
]=(rmesa
->state
.vertex_shader
.unknown_ptr2
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
)
1501 | (rmesa
->state
.vertex_shader
.unknown_ptr3
<< 0);
1503 /* This is done for vertex shader fragments, but also needs to be done for vap_pvs,
1504 so I leave it as a reminder */
1506 reg_start(R300_VAP_PVS_WAITIDLE
,0);
1511 void r300SetupVertexProgram(r300ContextPtr rmesa
)
1513 GLcontext
* ctx
= rmesa
->radeon
.glCtx
;
1517 struct r300_vertex_program
*prog
=(struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
1520 /* Reset state, in case we don't use something */
1521 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1522 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1523 ((drm_r300_cmd_header_t
*)rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1525 r300VertexProgUpdateParams(ctx
, prog
);
1527 setup_vertex_shader_fragment(rmesa
, VSF_DEST_PROGRAM
, &(prog
->program
));
1529 setup_vertex_shader_fragment(rmesa
, VSF_DEST_MATRIX0
, &(prog
->params
));
1532 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN1
, &(rmesa
->state
.vertex_shader
.unknown1
));
1533 setup_vertex_shader_fragment(rmesa
, VSF_DEST_UNKNOWN2
, &(rmesa
->state
.vertex_shader
.unknown2
));
1536 inst_count
=prog
->program
.length
/4 - 1;
1537 param_count
=prog
->params
.length
/4;
1539 R300_STATECHANGE(rmesa
, pvs
);
1540 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
]=(0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
)
1541 | (inst_count
/*pos_end*/ << R300_PVS_CNTL_1_POS_END_SHIFT
)
1542 | (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1543 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
]=(0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
)
1544 | (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1545 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
]=(0/*rmesa->state.vertex_shader.unknown_ptr2*/ << R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
)
1546 | (inst_count
/*rmesa->state.vertex_shader.unknown_ptr3*/ << 0);
1548 /* This is done for vertex shader fragments, but also needs to be done for vap_pvs,
1549 so I leave it as a reminder */
1551 reg_start(R300_VAP_PVS_WAITIDLE
,0);
1556 /* This is probably wrong for some values, I need to test this
1557 * some more. Range checking would be a good idea also..
1559 * But it works for most things. I'll fix it later if someone
1560 * else with a better clue doesn't
1562 unsigned int r300PackFloat24(float f
)
1566 unsigned int float24
= 0;
1568 if (f
== 0.0) return 0;
1570 mantissa
= frexpf(f
, &exponent
);
1575 mantissa
= mantissa
* -1.0;
1577 /* Handle exponent, bias of 63 */
1579 float24
|= (exponent
<< 16);
1580 /* Kill 7 LSB of mantissa */
1581 float24
|= (r300PackFloat32(mantissa
) & 0x7FFFFF) >> 7;
1586 #if USE_ARB_F_P == 1
1587 void r300SetupPixelShader(r300ContextPtr rmesa
)
1589 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1590 struct r300_fragment_program
*rp
= ctx
->FragmentProgram
._Current
;
1593 if (!rp
) /* should only happenen once, just after context is created */
1596 translate_fragment_shader(ctx
->FragmentProgram
._Current
);
1597 if (!rp
->translated
) {
1598 fprintf(stderr
, "%s: No valid fragment shader, exiting\n", __func__
);
1602 R300_STATECHANGE(rmesa
, fpt
);
1603 for(i
=0;i
<rp
->tex
.length
;i
++)
1604 rmesa
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+i
]=rp
->tex
.inst
[i
];
1605 rmesa
->hw
.fpt
.cmd
[R300_FPT_CMD_0
]=cmdpacket0(R300_PFS_TEXI_0
, rp
->tex
.length
);
1607 #define OUTPUT_FIELD(st, reg, field) \
1608 R300_STATECHANGE(rmesa, st); \
1609 for(i=0;i<=rp->alu_end;i++) \
1610 rmesa->hw.st.cmd[R300_FPI_INSTR_0+i]=rp->alu.inst[i].field;\
1611 rmesa->hw.st.cmd[R300_FPI_CMD_0]=cmdpacket0(reg, rp->alu_end+1);
1613 OUTPUT_FIELD(fpi
[0], R300_PFS_INSTR0_0
, inst0
);
1614 OUTPUT_FIELD(fpi
[1], R300_PFS_INSTR1_0
, inst1
);
1615 OUTPUT_FIELD(fpi
[2], R300_PFS_INSTR2_0
, inst2
);
1616 OUTPUT_FIELD(fpi
[3], R300_PFS_INSTR3_0
, inst3
);
1619 R300_STATECHANGE(rmesa
, fp
);
1620 /* I just want to say, the way these nodes are stored.. weird.. */
1621 for (i
=0,k
=(4-(rp
->cur_node
+1));i
<4;i
++,k
++) {
1622 if (i
<(rp
->cur_node
+1)) {
1623 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+k
]=
1624 (rp
->node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
)
1625 | (rp
->node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
)
1626 | (rp
->node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
)
1627 | (rp
->node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
)
1628 | ( (k
==3) ? R300_PFS_NODE_LAST_NODE
: 0);
1630 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+(3-i
)] = 0;
1635 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
]=
1637 | (rp
->first_node_has_tex
<<3);
1639 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
]=rp
->max_temp_idx
;
1641 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
]=
1642 (rp
->alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
)
1643 | (rp
->alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
)
1644 | (rp
->tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
)
1645 | (rp
->tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
1647 R300_STATECHANGE(rmesa
, fpp
);
1648 for(i
=0;i
<rp
->const_nr
;i
++){
1649 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+0]=r300PackFloat24(rp
->constant
[i
][0]);
1650 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+1]=r300PackFloat24(rp
->constant
[i
][1]);
1651 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+2]=r300PackFloat24(rp
->constant
[i
][2]);
1652 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+3]=r300PackFloat24(rp
->constant
[i
][3]);
1654 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
]=cmdpacket0(R300_PFS_PARAM_0_X
, rp
->const_nr
*4);
1657 /* just a skeleton for now.. */
1658 void r300GenerateTexturePixelShader(r300ContextPtr r300
)
1661 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1663 GLuint OutputsWritten
= CURRENT_VERTEX_SHADER(r300
->radeon
.glCtx
)->OutputsWritten
;
1665 int tex_inst
=0, alu_inst
=0;
1668 /* No need to proliferate {} */
1669 if(!TMU_ENABLED(r300
->radeon
.glCtx
, i
))continue;
1671 envMode
= r300
->radeon
.glCtx
->Texture
.Unit
[i
].EnvMode
;
1672 //fprintf(stderr, "envMode=%s\n", _mesa_lookup_enum_by_nr(envMode));
1674 /* Fetch textured pixel */
1676 r300
->state
.pixel_shader
.program
.tex
.inst
[tex_inst
]=0x00018000;
1679 switch(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeRGB
){
1681 WARN_ONCE("ModeA==GL_REPLACE is possibly broken.\n");
1682 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1683 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, ONE
, ZERO
);
1685 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1686 EASY_PFS_INSTR1(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1689 WARN_ONCE("ModeRGB==GL_MODULATE is possibly broken.\n");
1690 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1691 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, SRC1C_XYZ
, ZERO
);
1693 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1694 EASY_PFS_INSTR1(0, 0, 1, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1698 WARN_ONCE("ModeRGB=%s is not implemented yet !\n",
1699 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeRGB
));
1701 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst0
=
1702 EASY_PFS_INSTR0(MAD
, SRC0C_XYZ
, ONE
, ZERO
);
1704 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst1
=
1705 EASY_PFS_INSTR1(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, NONE
, ALL
);
1707 switch(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeA
){
1709 WARN_ONCE("ModeA==GL_REPLACE is possibly broken.\n");
1710 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1711 EASY_PFS_INSTR2(MAD
, SRC0A
, ONE
, ZERO
);
1713 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1714 EASY_PFS_INSTR3(0, 0, 0| PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, OUTPUT
);
1717 fprintf(stderr
, "numArgsA=%d sourceA[0]=%s op=%d\n",
1718 r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->_NumArgsA
,
1719 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->SourceA
[0]),
1720 r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->OperandA
[0]-GL_SRC_ALPHA
);
1724 WARN_ONCE("ModeA==GL_MODULATE is possibly broken.\n");
1726 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1727 EASY_PFS_INSTR2(MAD
, SRC0A
, SRC1A
, ZERO
);
1729 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1730 EASY_PFS_INSTR3(0, 0, 1, 0 | PFS_FLAG_CONST
, OUTPUT
);
1734 WARN_ONCE("ModeA=%s is not implemented yet !\n",
1735 _mesa_lookup_enum_by_nr(r300
->radeon
.glCtx
->Texture
.Unit
[i
]._CurrentCombine
->ModeA
));
1737 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst2
=
1738 EASY_PFS_INSTR2(MAD
, SRC0A
, ONE
, ZERO
);
1740 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
].inst3
=
1741 EASY_PFS_INSTR3(0, 0, 0 | PFS_FLAG_CONST
, 0 | PFS_FLAG_CONST
, OUTPUT
);
1748 r300
->state
.pixel_shader
.program
.tex
.length
=tex_inst
;
1749 r300
->state
.pixel_shader
.program
.tex_offset
=0;
1750 r300
->state
.pixel_shader
.program
.tex_end
=tex_inst
-1;
1753 /* saturate last instruction, like i915 driver does */
1754 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
-1].inst0
|=R300_FPI0_OUTC_SAT
;
1755 r300
->state
.pixel_shader
.program
.alu
.inst
[alu_inst
-1].inst2
|=R300_FPI2_OUTA_SAT
;
1758 r300
->state
.pixel_shader
.program
.alu
.length
=alu_inst
;
1759 r300
->state
.pixel_shader
.program
.alu_offset
=0;
1760 r300
->state
.pixel_shader
.program
.alu_end
=alu_inst
-1;
1763 void r300SetupPixelShader(r300ContextPtr rmesa
)
1767 /* This needs to be replaced by pixel shader generation code */
1769 /* textures enabled ? */
1770 if(rmesa
->state
.texture
.tc_count
>0){
1772 r300GenerateTextureFragmentShader(rmesa
);
1774 rmesa
->state
.pixel_shader
=SINGLE_TEXTURE_PIXEL_SHADER
;
1775 r300GenerateTexturePixelShader(rmesa
);
1778 rmesa
->state
.pixel_shader
=FLAT_COLOR_PIXEL_SHADER
;
1781 R300_STATECHANGE(rmesa
, fpt
);
1782 for(i
=0;i
<rmesa
->state
.pixel_shader
.program
.tex
.length
;i
++)
1783 rmesa
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+i
]=rmesa
->state
.pixel_shader
.program
.tex
.inst
[i
];
1784 rmesa
->hw
.fpt
.cmd
[R300_FPT_CMD_0
]=cmdpacket0(R300_PFS_TEXI_0
, rmesa
->state
.pixel_shader
.program
.tex
.length
);
1786 #define OUTPUT_FIELD(st, reg, field) \
1787 R300_STATECHANGE(rmesa, st); \
1788 for(i=0;i<rmesa->state.pixel_shader.program.alu.length;i++) \
1789 rmesa->hw.st.cmd[R300_FPI_INSTR_0+i]=rmesa->state.pixel_shader.program.alu.inst[i].field;\
1790 rmesa->hw.st.cmd[R300_FPI_CMD_0]=cmdpacket0(reg, rmesa->state.pixel_shader.program.alu.length);
1792 OUTPUT_FIELD(fpi
[0], R300_PFS_INSTR0_0
, inst0
);
1793 OUTPUT_FIELD(fpi
[1], R300_PFS_INSTR1_0
, inst1
);
1794 OUTPUT_FIELD(fpi
[2], R300_PFS_INSTR2_0
, inst2
);
1795 OUTPUT_FIELD(fpi
[3], R300_PFS_INSTR3_0
, inst3
);
1798 R300_STATECHANGE(rmesa
, fp
);
1800 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+i
]=
1801 (rmesa
->state
.pixel_shader
.program
.node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
)
1802 | (rmesa
->state
.pixel_shader
.program
.node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
)
1803 | (rmesa
->state
.pixel_shader
.program
.node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
)
1804 | (rmesa
->state
.pixel_shader
.program
.node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
)
1805 | ( (i
==3) ? R300_PFS_NODE_LAST_NODE
: 0);
1809 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
]=
1810 (rmesa
->state
.pixel_shader
.program
.active_nodes
-1)
1811 | (rmesa
->state
.pixel_shader
.program
.first_node_has_tex
<<3);
1813 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
]=rmesa
->state
.pixel_shader
.program
.temp_register_count
;
1815 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
]=
1816 (rmesa
->state
.pixel_shader
.program
.alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
)
1817 | (rmesa
->state
.pixel_shader
.program
.alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
)
1818 | (rmesa
->state
.pixel_shader
.program
.tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
)
1819 | (rmesa
->state
.pixel_shader
.program
.tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
1821 R300_STATECHANGE(rmesa
, fpp
);
1822 for(i
=0;i
<rmesa
->state
.pixel_shader
.param_length
;i
++){
1823 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+0]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].x
);
1824 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+1]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].y
);
1825 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+2]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].z
);
1826 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+4*i
+3]=r300PackFloat32(rmesa
->state
.pixel_shader
.param
[i
].w
);
1828 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
]=cmdpacket0(R300_PFS_PARAM_0_X
, rmesa
->state
.pixel_shader
.param_length
);
1834 * Called by Mesa after an internal state update.
1836 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
1838 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1840 _swrast_InvalidateState(ctx
, new_state
);
1841 _swsetup_InvalidateState(ctx
, new_state
);
1842 _ac_InvalidateState(ctx
, new_state
);
1843 _tnl_InvalidateState(ctx
, new_state
);
1844 _ae_invalidate_state(ctx
, new_state
);
1846 /* Go inefficiency! */
1847 r300ResetHwState(r300
);
1850 /* Checks that r300ResetHwState actually modifies all states.
1851 Should probably be burried in somewhere else as this file is getting longish. */
1852 void verify_r300ResetHwState(r300ContextPtr r300
, int stage
)
1854 struct r300_state_atom
* atom
;
1856 drm_r300_cmd_header_t cmd
;
1858 if(stage
){ /* mess around with states */
1859 unsigned long fp1
, cb1
;
1861 fp1
=r300
->hw
.fp
.cmd
[R300_FP_CMD_1
]; /* some special cases... */
1862 cb1
=r300
->hw
.cb
.cmd
[R300_CB_CMD_1
];
1864 fprintf(stderr
, "verify begin:\n");
1866 foreach(atom
, &r300
->hw
.atomlist
) {
1867 for(i
=1; i
< (*atom
->check
)(r300
, atom
); i
++)
1868 atom
->cmd
[i
]=0xdeadbeef;
1870 r300
->hw
.fp
.cmd
[R300_FP_CMD_1
]=fp1
;
1871 r300
->hw
.cb
.cmd
[R300_CB_CMD_1
]=cb1
;
1873 foreach(atom
, &r300
->hw
.atomlist
) {
1875 switch(cmd
.header
.cmd_type
){
1876 case R300_CMD_PACKET0
:
1878 case R300_CMD_PACKET3
:
1879 case R300_CMD_END3D
:
1880 case R300_CMD_CP_DELAY
:
1881 case R300_CMD_DMA_DISCARD
:
1883 default: fprintf(stderr
, "unknown cmd_type %d in atom %s\n",
1884 cmd
.header
.cmd_type
, atom
->name
);
1888 } else { /* check that they were set */
1889 foreach(atom
, &r300
->hw
.atomlist
) {
1890 for(i
=1; i
< (*atom
->check
)(r300
, atom
); i
++)
1891 if(atom
->cmd
[i
]==0xdeadbeef)
1892 fprintf(stderr
, "atom %s is untouched\n", atom
->name
);
1898 * Completely recalculates hardware state based on the Mesa state.
1900 void r300ResetHwState(r300ContextPtr r300
)
1902 GLcontext
* ctx
= r300
->radeon
.glCtx
;
1905 if (RADEON_DEBUG
& DEBUG_STATE
)
1906 fprintf(stderr
, "%s\n", __FUNCTION__
);
1908 //verify_r300ResetHwState(r300, 1);
1910 /* This is a place to initialize registers which
1911 have bitfields accessed by different functions
1912 and not all bits are used */
1914 /* initialize similiar to r200 */
1915 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] = 0;
1916 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] =
1917 (R300_ZS_ALWAYS
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
) |
1918 (R300_ZS_KEEP
<< R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT
) |
1919 (R300_ZS_KEEP
<< R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT
) |
1920 (R300_ZS_KEEP
<< R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT
) |
1921 (R300_ZS_ALWAYS
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
) |
1922 (R300_ZS_KEEP
<< R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
) |
1923 (R300_ZS_KEEP
<< R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
) |
1924 (R300_ZS_KEEP
<< R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
);
1925 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] = 0x00ffff00;
1928 /* go and compute register values from GL state */
1930 r300UpdateWindow(ctx
);
1933 ctx
->Color
.ColorMask
[RCOMP
],
1934 ctx
->Color
.ColorMask
[GCOMP
],
1935 ctx
->Color
.ColorMask
[BCOMP
],
1936 ctx
->Color
.ColorMask
[ACOMP
]);
1938 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1939 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1940 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1943 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
1944 r300StencilMask(ctx
, ctx
->Stencil
.WriteMask
[0]);
1945 r300StencilFunc(ctx
, ctx
->Stencil
.Function
[0], ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1946 r300StencilOp(ctx
, ctx
->Stencil
.FailFunc
[0], ctx
->Stencil
.ZFailFunc
[0], ctx
->Stencil
.ZPassFunc
[0]);
1948 r300UpdateCulling(ctx
);
1950 r300UpdateTextureState(ctx
);
1952 // r300_setup_routing(ctx, GL_TRUE);
1953 if(hw_tcl_on
== GL_FALSE
){
1954 r300EmitArrays(ctx
, GL_TRUE
); /* Just do the routing */
1955 r300_setup_textures(ctx
);
1956 r300_setup_rs_unit(ctx
);
1958 r300SetupVertexShader(r300
);
1959 r300SetupPixelShader(r300
);
1962 r300_set_blend_state(ctx
);
1964 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1965 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1967 /* Initialize magic registers
1968 TODO : learn what they really do, or get rid of
1969 those we don't have to touch */
1970 r300
->hw
.unk2080
.cmd
[1] = 0x0030045A; /* Dangerous */
1972 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1973 | R300_VPORT_X_OFFSET_ENA
1974 | R300_VPORT_Y_SCALE_ENA
1975 | R300_VPORT_Y_OFFSET_ENA
1976 | R300_VPORT_Z_SCALE_ENA
1977 | R300_VPORT_Z_OFFSET_ENA
1979 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1981 r300
->hw
.unk2134
.cmd
[1] = 0x00FFFFFF;
1982 r300
->hw
.unk2134
.cmd
[2] = 0x00000000;
1983 #ifdef MESA_BIG_ENDIAN
1984 r300
->hw
.unk2140
.cmd
[1] = 0x00000002;
1986 r300
->hw
.unk2140
.cmd
[1] = 0x00000000;
1989 #if 0 /* Done in setup routing */
1990 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[0].cmd
)->packet0
.count
= 1;
1991 r300
->hw
.vir
[0].cmd
[1] = 0x21030003;
1993 ((drm_r300_cmd_header_t
*)r300
->hw
.vir
[1].cmd
)->packet0
.count
= 1;
1994 r300
->hw
.vir
[1].cmd
[1] = 0xF688F688;
1996 r300
->hw
.vic
.cmd
[R300_VIR_CNTL_0
] = 0x00000001;
1997 r300
->hw
.vic
.cmd
[R300_VIR_CNTL_1
] = 0x00000405;
2000 r300
->hw
.unk21DC
.cmd
[1] = 0xAAAAAAAA;
2002 r300
->hw
.unk221C
.cmd
[1] = R300_221C_NORMAL
;
2004 r300
->hw
.unk2220
.cmd
[1] = r300PackFloat32(1.0);
2005 r300
->hw
.unk2220
.cmd
[2] = r300PackFloat32(1.0);
2006 r300
->hw
.unk2220
.cmd
[3] = r300PackFloat32(1.0);
2007 r300
->hw
.unk2220
.cmd
[4] = r300PackFloat32(1.0);
2009 if (GET_CHIP(r300
->radeon
.radeonScreen
) == RADEON_CHIP_R300
)
2010 r300
->hw
.unk2288
.cmd
[1] = R300_2288_R300
;
2012 r300
->hw
.unk2288
.cmd
[1] = R300_2288_RV350
;
2015 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT
2016 | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT
;
2017 r300
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = 0; /* no textures */
2020 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] = 0;
2021 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] = 0;
2022 r300
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] = 0;
2025 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
2026 | R300_GB_LINE_STUFF_ENABLE
2027 | R300_GB_TRIANGLE_STUFF_ENABLE
/*| R300_GB_UNK30*/;
2029 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
2030 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
2031 if (GET_CHIP(r300
->radeon
.radeonScreen
) == RADEON_CHIP_R300
)
2032 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] = R300_GB_TILE_ENABLE
2033 | R300_GB_TILE_PIPE_COUNT_R300
2034 | R300_GB_TILE_SIZE_16
;
2035 else if (GET_CHIP(r300
->radeon
.radeonScreen
) == RADEON_CHIP_R420
)
2036 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] = R300_GB_TILE_ENABLE
2037 | R300_GB_TILE_PIPE_COUNT_R420
2038 | R300_GB_TILE_SIZE_16
;
2040 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] = R300_GB_TILE_ENABLE
2041 | R300_GB_TILE_PIPE_COUNT_RV300
2042 | R300_GB_TILE_SIZE_16
;
2043 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = 0x00000000;
2044 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = 0x00000000; /* No antialiasing */
2046 //r300->hw.txe.cmd[R300_TXE_ENABLE] = 0;
2048 r300
->hw
.unk4200
.cmd
[1] = r300PackFloat32(0.0);
2049 r300
->hw
.unk4200
.cmd
[2] = r300PackFloat32(0.0);
2050 r300
->hw
.unk4200
.cmd
[3] = r300PackFloat32(1.0);
2051 r300
->hw
.unk4200
.cmd
[4] = r300PackFloat32(1.0);
2053 r300
->hw
.unk4214
.cmd
[1] = 0x00050005;
2055 r300PointSize(ctx
, 0.0);
2057 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] = (6 << R300_POINTSIZE_X_SHIFT
) |
2058 (6 << R300_POINTSIZE_Y_SHIFT
);
2061 r300
->hw
.unk4230
.cmd
[1] = 0x01800000;//18000006;
2062 r300
->hw
.unk4230
.cmd
[2] = 0x00020006;
2063 r300
->hw
.unk4230
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
2065 r300LineWidth(ctx
, 0.0);
2067 r300
->hw
.unk4260
.cmd
[1] = 0;
2068 r300
->hw
.unk4260
.cmd
[2] = r300PackFloat32(0.0);
2069 r300
->hw
.unk4260
.cmd
[3] = r300PackFloat32(1.0);
2071 r300
->hw
.unk4274
.cmd
[1] = 0x00000002;
2072 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
2073 r300
->hw
.unk4274
.cmd
[3] = 0x00000000;
2074 r300
->hw
.unk4274
.cmd
[4] = 0x00000000;
2076 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
2077 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
2078 r300
->hw
.unk4288
.cmd
[2] = 0x00000001;
2079 r300
->hw
.unk4288
.cmd
[3] = 0x00000000;
2080 r300
->hw
.unk4288
.cmd
[4] = 0x00000000;
2081 r300
->hw
.unk4288
.cmd
[5] = 0x00000000;
2083 r300
->hw
.unk42A0
.cmd
[1] = 0x00000000;
2085 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
, ctx
->Polygon
.OffsetUnits
);
2086 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
2088 r300
->hw
.unk42C0
.cmd
[1] = 0x4B7FFFFF;
2089 r300
->hw
.unk42C0
.cmd
[2] = 0x00000000;
2092 r300
->hw
.unk43A4
.cmd
[1] = 0x0000001C;
2093 r300
->hw
.unk43A4
.cmd
[2] = 0x2DA49525;
2095 r300
->hw
.unk43E8
.cmd
[1] = 0x00FFFFFF;
2098 r300
->hw
.fp
.cmd
[R300_FP_CNTL0
] = 0;
2099 r300
->hw
.fp
.cmd
[R300_FP_CNTL1
] = 0;
2100 r300
->hw
.fp
.cmd
[R300_FP_CNTL2
] = 0;
2101 r300
->hw
.fp
.cmd
[R300_FP_NODE0
] = 0;
2102 r300
->hw
.fp
.cmd
[R300_FP_NODE1
] = 0;
2103 r300
->hw
.fp
.cmd
[R300_FP_NODE2
] = 0;
2104 r300
->hw
.fp
.cmd
[R300_FP_NODE3
] = 0;
2107 r300
->hw
.unk46A4
.cmd
[1] = 0x00001B01;
2108 r300
->hw
.unk46A4
.cmd
[2] = 0x00001B0F;
2109 r300
->hw
.unk46A4
.cmd
[3] = 0x00001B0F;
2110 r300
->hw
.unk46A4
.cmd
[4] = 0x00001B0F;
2111 r300
->hw
.unk46A4
.cmd
[5] = 0x00000001;
2114 for(i
= 1; i
<= 64; ++i
) {
2115 /* create NOP instructions */
2116 r300
->hw
.fpi
[0].cmd
[i
] = FP_INSTRC(MAD
, FP_ARGC(SRC0C_XYZ
), FP_ARGC(ONE
), FP_ARGC(ZERO
));
2117 r300
->hw
.fpi
[1].cmd
[i
] = FP_SELC(0,XYZ
,NO
,FP_TMP(0),0,0);
2118 r300
->hw
.fpi
[2].cmd
[i
] = FP_INSTRA(MAD
, FP_ARGA(SRC0A
), FP_ARGA(ONE
), FP_ARGA(ZERO
));
2119 r300
->hw
.fpi
[3].cmd
[i
] = FP_SELA(0,W
,NO
,FP_TMP(0),0,0);
2123 r300
->hw
.unk4BC0
.cmd
[1] = 0;
2125 r300
->hw
.unk4BC8
.cmd
[1] = 0;
2126 r300
->hw
.unk4BC8
.cmd
[2] = 0;
2127 r300
->hw
.unk4BC8
.cmd
[3] = 0;
2130 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
2131 r300
->hw
.unk4BD8
.cmd
[1] = 0;
2133 r300
->hw
.unk4E00
.cmd
[1] = 0;
2136 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = 0;
2137 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = 0;
2140 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
2141 r300
->hw
.unk4E10
.cmd
[2] = 0;
2142 r300
->hw
.unk4E10
.cmd
[3] = 0;
2144 /* Again, r300ClearBuffer uses this */
2145 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] = r300
->radeon
.state
.color
.drawOffset
+
2146 r300
->radeon
.radeonScreen
->fbLocation
;
2147 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.state
.color
.drawPitch
;
2149 if (r300
->radeon
.radeonScreen
->cpp
== 4)
2150 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
2152 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
2154 if (r300
->radeon
.sarea
->tiling_enabled
)
2155 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
2157 r300
->hw
.unk4E50
.cmd
[1] = 0;
2158 r300
->hw
.unk4E50
.cmd
[2] = 0;
2159 r300
->hw
.unk4E50
.cmd
[3] = 0;
2160 r300
->hw
.unk4E50
.cmd
[4] = 0;
2161 r300
->hw
.unk4E50
.cmd
[5] = 0;
2162 r300
->hw
.unk4E50
.cmd
[6] = 0;
2163 r300
->hw
.unk4E50
.cmd
[7] = 0;
2164 r300
->hw
.unk4E50
.cmd
[8] = 0;
2165 r300
->hw
.unk4E50
.cmd
[9] = 0;
2167 r300
->hw
.unk4E88
.cmd
[1] = 0;
2169 r300
->hw
.unk4EA0
.cmd
[1] = 0x00000000;
2170 r300
->hw
.unk4EA0
.cmd
[2] = 0xffffffff;
2172 switch (ctx
->Visual
.depthBits
) {
2174 r300
->hw
.unk4F10
.cmd
[1] = R300_DEPTH_FORMAT_16BIT_INT_Z
;
2177 r300
->hw
.unk4F10
.cmd
[1] = R300_DEPTH_FORMAT_24BIT_INT_Z
;
2180 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2181 ctx
->Visual
.depthBits
);
2185 r300
->hw
.unk4F10
.cmd
[3] = 0x00000003;
2186 r300
->hw
.unk4F10
.cmd
[4] = 0x00000000;
2188 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
2189 r300
->radeon
.radeonScreen
->depthOffset
+
2190 r300
->radeon
.radeonScreen
->fbLocation
;
2191 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
2193 if (r300
->radeon
.sarea
->tiling_enabled
) {
2194 /* Turn off when clearing buffers ? */
2195 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= R300_DEPTH_TILE_ENABLE
;
2197 if (ctx
->Visual
.depthBits
== 24)
2198 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= R300_DEPTH_MICROTILE_ENABLE
;
2201 r300
->hw
.unk4F28
.cmd
[1] = 0;
2203 r300
->hw
.unk4F30
.cmd
[1] = 0;
2204 r300
->hw
.unk4F30
.cmd
[2] = 0;
2206 r300
->hw
.unk4F44
.cmd
[1] = 0;
2208 r300
->hw
.unk4F54
.cmd
[1] = 0;
2211 ((drm_r300_cmd_header_t
*)r300
->hw
.vpi
.cmd
)->vpu
.count
= 0;
2212 for(i
= 1; i
< R300_VPI_CMDSIZE
; i
+= 4) {
2214 r300
->hw
.vpi
.cmd
[i
+0] = VP_OUT(ADD
,TMP
,0,XYZW
);
2215 r300
->hw
.vpi
.cmd
[i
+1] = VP_IN(TMP
,0);
2216 r300
->hw
.vpi
.cmd
[i
+2] = VP_ZERO();
2217 r300
->hw
.vpi
.cmd
[i
+3] = VP_ZERO();
2220 ((drm_r300_cmd_header_t
*)r300
->hw
.vpp
.cmd
)->vpu
.count
= 0;
2221 for(i
= 1; i
< R300_VPP_CMDSIZE
; ++i
)
2222 r300
->hw
.vpp
.cmd
[i
] = 0;
2225 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
2226 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
2227 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
2228 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
2231 //verify_r300ResetHwState(r300, 0);
2232 r300
->hw
.all_dirty
= GL_TRUE
;
2238 * Calculate initial hardware state and register state functions.
2239 * Assumes that the command buffer and state atoms have been
2240 * initialized already.
2242 void r300InitState(r300ContextPtr r300
)
2244 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2247 radeonInitState(&r300
->radeon
);
2249 switch (ctx
->Visual
.depthBits
) {
2251 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2252 depth_fmt
= R200_DEPTH_FORMAT_16BIT_INT_Z
;
2253 r300
->state
.stencil
.clear
= 0x00000000;
2256 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2257 depth_fmt
= R200_DEPTH_FORMAT_24BIT_INT_Z
;
2258 r300
->state
.stencil
.clear
= 0x00ff0000;
2261 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2262 ctx
->Visual
.depthBits
);
2266 /* Only have hw stencil when depth buffer is 24 bits deep */
2267 r300
->state
.stencil
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2268 ctx
->Visual
.depthBits
== 24);
2270 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2272 r300ResetHwState(r300
);
2275 static void r300RenderMode( GLcontext
*ctx
, GLenum mode
)
2277 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2278 WARN_ONCE("TODO: fallback properly when rendering mode is not GL_RENDER\n"
2279 "\tThe way things are now neither selection nor feedback modes work\n")
2280 // FALLBACK( rmesa, R300_FALLBACK_RENDER_MODE, (mode != GL_RENDER) );
2284 * Initialize driver's state callback functions
2286 void r300InitStateFuncs(struct dd_function_table
* functions
)
2288 radeonInitStateFuncs(functions
);
2290 functions
->UpdateState
= r300InvalidateState
;
2291 functions
->AlphaFunc
= r300AlphaFunc
;
2292 functions
->BlendColor
= r300BlendColor
;
2293 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2294 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2295 functions
->Enable
= r300Enable
;
2296 functions
->ColorMask
= r300ColorMask
;
2297 functions
->DepthFunc
= r300DepthFunc
;
2298 functions
->DepthMask
= r300DepthMask
;
2299 functions
->CullFace
= r300CullFace
;
2300 functions
->FrontFace
= r300FrontFace
;
2301 functions
->ShadeModel
= r300ShadeModel
;
2303 /* Stencil related */
2304 functions
->ClearStencil
= r300ClearStencil
;
2305 functions
->StencilFunc
= r300StencilFunc
;
2306 functions
->StencilMask
= r300StencilMask
;
2307 functions
->StencilOp
= r300StencilOp
;
2309 /* Viewport related */
2310 functions
->Viewport
= r300Viewport
;
2311 functions
->DepthRange
= r300DepthRange
;
2312 functions
->PointSize
= r300PointSize
;
2313 functions
->LineWidth
= r300LineWidth
;
2315 functions
->PolygonOffset
= r300PolygonOffset
;
2316 functions
->PolygonMode
= r300PolygonMode
;
2318 functions
->RenderMode
= r300RenderMode
;