2 Copyright (C) The Weather Channel, Inc. 2002.
3 Copyright (C) 2004 Nicolai Haehnle.
6 The Weather Channel (TM) funded Tungsten Graphics to develop the
7 initial release of the Radeon 8500 driver under the XFree86 license.
8 This notice must be preserved.
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial
20 portions of the Software.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
35 * \author Nicolai Haehnle <prefect_@gmx.net>
45 #include "simple_list.h"
47 #include "api_arrayelt.h"
48 #include "swrast/swrast.h"
49 #include "swrast_setup/swrast_setup.h"
50 #include "shader/prog_parameter.h"
51 #include "shader/prog_statevars.h"
54 #include "texformat.h"
56 #include "radeon_ioctl.h"
57 #include "radeon_state.h"
58 #include "r300_context.h"
59 #include "r300_ioctl.h"
60 #include "r300_state.h"
62 #include "r300_emit.h"
63 #include "r300_fragprog.h"
66 #include "drirenderbuffer.h"
68 extern int future_hw_tcl_on
;
69 extern void _tnl_UpdateFixedFunctionProgram(GLcontext
* ctx
);
71 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
74 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
76 R300_STATECHANGE(rmesa
, blend_color
);
78 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
79 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
80 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
81 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
83 rmesa
->hw
.blend_color
.cmd
[1] = PACK_COLOR_8888(color
[3], color
[0],
85 rmesa
->hw
.blend_color
.cmd
[2] = 0;
86 rmesa
->hw
.blend_color
.cmd
[3] = 0;
90 * Calculate the hardware blend factor setting. This same function is used
91 * for source and destination of both alpha and RGB.
94 * The hardware register value for the specified blend factor. This value
95 * will need to be shifted into the correct position for either source or
99 * Since the two cases where source and destination are handled differently
100 * are essentially error cases, they should never happen. Determine if these
101 * cases can be removed.
103 static int blend_factor(GLenum factor
, GLboolean is_src
)
107 return R300_BLEND_GL_ZERO
;
110 return R300_BLEND_GL_ONE
;
113 return R300_BLEND_GL_DST_COLOR
;
115 case GL_ONE_MINUS_DST_COLOR
:
116 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
119 return R300_BLEND_GL_SRC_COLOR
;
121 case GL_ONE_MINUS_SRC_COLOR
:
122 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
125 return R300_BLEND_GL_SRC_ALPHA
;
127 case GL_ONE_MINUS_SRC_ALPHA
:
128 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
131 return R300_BLEND_GL_DST_ALPHA
;
133 case GL_ONE_MINUS_DST_ALPHA
:
134 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
136 case GL_SRC_ALPHA_SATURATE
:
137 return (is_src
) ? R300_BLEND_GL_SRC_ALPHA_SATURATE
:
140 case GL_CONSTANT_COLOR
:
141 return R300_BLEND_GL_CONST_COLOR
;
143 case GL_ONE_MINUS_CONSTANT_COLOR
:
144 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
146 case GL_CONSTANT_ALPHA
:
147 return R300_BLEND_GL_CONST_ALPHA
;
149 case GL_ONE_MINUS_CONSTANT_ALPHA
:
150 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
153 fprintf(stderr
, "unknown blend factor %x\n", factor
);
154 return (is_src
) ? R300_BLEND_GL_ONE
: R300_BLEND_GL_ZERO
;
160 * Sets both the blend equation and the blend function.
161 * This is done in a single
162 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
163 * change the interpretation of the blend function.
164 * Also, make sure that blend function and blend equation are set to their
165 * default value if color blending is not enabled, since at least blend
166 * equations GL_MIN and GL_FUNC_REVERSE_SUBTRACT will cause wrong results
167 * otherwise for unknown reasons.
170 /* helper function */
171 static void r300SetBlendCntl(r300ContextPtr r300
, int func
, int eqn
,
172 int cbits
, int funcA
, int eqnA
)
174 GLuint new_ablend
, new_cblend
;
178 "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n",
179 eqnA
, funcA
, eqn
, func
, cbits
);
181 new_ablend
= eqnA
| funcA
;
182 new_cblend
= eqn
| func
;
184 /* Some blend factor combinations don't seem to work when the
185 * BLEND_NO_SEPARATE bit is set.
187 * Especially problematic candidates are the ONE_MINUS_* flags,
188 * but I can't see a real pattern.
191 if (new_ablend
== new_cblend
) {
192 new_cblend
|= R300_BLEND_NO_SEPARATE
;
197 if ((new_ablend
!= r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]) ||
198 (new_cblend
!= r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
])) {
199 R300_STATECHANGE(r300
, bld
);
200 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = new_ablend
;
201 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = new_cblend
;
205 static void r300SetBlendState(GLcontext
* ctx
)
207 r300ContextPtr r300
= R300_CONTEXT(ctx
);
208 int func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
209 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
210 int eqn
= R300_COMB_FCN_ADD_CLAMP
;
211 int funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
212 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
213 int eqnA
= R300_COMB_FCN_ADD_CLAMP
;
215 if (RGBA_LOGICOP_ENABLED(ctx
) || !ctx
->Color
.BlendEnabled
) {
216 r300SetBlendCntl(r300
, func
, eqn
, 0, func
, eqn
);
221 (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) <<
222 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstRGB
,
224 R300_DST_BLEND_SHIFT
);
226 switch (ctx
->Color
.BlendEquationRGB
) {
228 eqn
= R300_COMB_FCN_ADD_CLAMP
;
231 case GL_FUNC_SUBTRACT
:
232 eqn
= R300_COMB_FCN_SUB_CLAMP
;
235 case GL_FUNC_REVERSE_SUBTRACT
:
236 eqn
= R300_COMB_FCN_RSUB_CLAMP
;
240 eqn
= R300_COMB_FCN_MIN
;
241 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
242 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
246 eqn
= R300_COMB_FCN_MAX
;
247 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
248 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
253 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
254 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
259 (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) <<
260 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstA
,
262 R300_DST_BLEND_SHIFT
);
264 switch (ctx
->Color
.BlendEquationA
) {
266 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
269 case GL_FUNC_SUBTRACT
:
270 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
273 case GL_FUNC_REVERSE_SUBTRACT
:
274 eqnA
= R300_COMB_FCN_RSUB_CLAMP
;
278 eqnA
= R300_COMB_FCN_MIN
;
279 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
280 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
284 eqnA
= R300_COMB_FCN_MAX
;
285 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
286 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
291 "[%s:%u] Invalid A blend equation (0x%04x).\n",
292 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
296 r300SetBlendCntl(r300
,
298 R300_BLEND_UNKNOWN
| R300_BLEND_ENABLE
, funcA
, eqnA
);
301 static void r300BlendEquationSeparate(GLcontext
* ctx
,
302 GLenum modeRGB
, GLenum modeA
)
304 r300SetBlendState(ctx
);
307 static void r300BlendFuncSeparate(GLcontext
* ctx
,
308 GLenum sfactorRGB
, GLenum dfactorRGB
,
309 GLenum sfactorA
, GLenum dfactorA
)
311 r300SetBlendState(ctx
);
315 * Update our tracked culling state based on Mesa's state.
317 static void r300UpdateCulling(GLcontext
* ctx
)
319 r300ContextPtr r300
= R300_CONTEXT(ctx
);
322 if (ctx
->Polygon
.CullFlag
) {
323 switch (ctx
->Polygon
.CullFaceMode
) {
325 val
= R300_CULL_FRONT
;
328 val
= R300_CULL_BACK
;
330 case GL_FRONT_AND_BACK
:
331 val
= R300_CULL_FRONT
| R300_CULL_BACK
;
338 switch (ctx
->Polygon
.FrontFace
) {
340 val
|= R300_FRONT_FACE_CW
;
343 val
|= R300_FRONT_FACE_CCW
;
349 R300_STATECHANGE(r300
, cul
);
350 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
353 static void r300SetEarlyZState(GLcontext
* ctx
)
355 /* updates register R300_RB3D_EARLY_Z (0x4F14)
356 if depth test is not enabled it should be R300_EARLY_Z_DISABLE
357 if depth is enabled and alpha not it should be R300_EARLY_Z_ENABLE
358 if depth and alpha is enabled it should be R300_EARLY_Z_DISABLE
360 r300ContextPtr r300
= R300_CONTEXT(ctx
);
362 R300_STATECHANGE(r300
, zstencil_format
);
363 switch (ctx
->Visual
.depthBits
) {
365 r300
->hw
.zstencil_format
.cmd
[1] = R300_DEPTH_FORMAT_16BIT_INT_Z
;
368 r300
->hw
.zstencil_format
.cmd
[1] = R300_DEPTH_FORMAT_24BIT_INT_Z
;
371 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n", ctx
->Visual
.depthBits
);
375 // r300->hw.zstencil_format.cmd[1] |= R300_DEPTH_FORMAT_UNK32;
377 if (ctx
->Color
.AlphaEnabled
&& ctx
->Color
.AlphaFunc
!= GL_ALWAYS
)
378 /* disable early Z */
379 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_DISABLE
;
381 if (ctx
->Depth
.Test
&& ctx
->Depth
.Func
!= GL_NEVER
)
383 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_ENABLE
;
385 /* disable early Z */
386 r300
->hw
.zstencil_format
.cmd
[2] = R300_EARLY_Z_DISABLE
;
389 r300
->hw
.zstencil_format
.cmd
[3] = 0x00000003;
390 r300
->hw
.zstencil_format
.cmd
[4] = 0x00000000;
393 static void r300SetAlphaState(GLcontext
* ctx
)
395 r300ContextPtr r300
= R300_CONTEXT(ctx
);
397 uint32_t pp_misc
= 0x0;
398 GLboolean really_enabled
= ctx
->Color
.AlphaEnabled
;
400 CLAMPED_FLOAT_TO_UBYTE(refByte
, ctx
->Color
.AlphaRef
);
402 switch (ctx
->Color
.AlphaFunc
) {
404 pp_misc
|= R300_ALPHA_TEST_FAIL
;
407 pp_misc
|= R300_ALPHA_TEST_LESS
;
410 pp_misc
|= R300_ALPHA_TEST_EQUAL
;
413 pp_misc
|= R300_ALPHA_TEST_LEQUAL
;
416 pp_misc
|= R300_ALPHA_TEST_GREATER
;
419 pp_misc
|= R300_ALPHA_TEST_NEQUAL
;
422 pp_misc
|= R300_ALPHA_TEST_GEQUAL
;
425 /*pp_misc |= R300_ALPHA_TEST_PASS; */
426 really_enabled
= GL_FALSE
;
430 if (really_enabled
) {
431 pp_misc
|= R300_ALPHA_TEST_ENABLE
;
432 pp_misc
|= (refByte
& R300_REF_ALPHA_MASK
);
437 R300_STATECHANGE(r300
, at
);
438 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
439 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
441 r300SetEarlyZState(ctx
);
444 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
448 r300SetAlphaState(ctx
);
451 static int translate_func(int func
)
455 return R300_ZS_NEVER
;
459 return R300_ZS_EQUAL
;
461 return R300_ZS_LEQUAL
;
463 return R300_ZS_GREATER
;
465 return R300_ZS_NOTEQUAL
;
467 return R300_ZS_GEQUAL
;
469 return R300_ZS_ALWAYS
;
474 static void r300SetDepthState(GLcontext
* ctx
)
476 r300ContextPtr r300
= R300_CONTEXT(ctx
);
478 R300_STATECHANGE(r300
, zs
);
479 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &= R300_RB3D_STENCIL_ENABLE
;
480 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
481 ~(R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
);
483 if (ctx
->Depth
.Test
&& ctx
->Depth
.Func
!= GL_NEVER
) {
485 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
486 R300_RB3D_Z_TEST_AND_WRITE
;
488 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_RB3D_Z_TEST
;
490 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
491 translate_func(ctx
->Depth
.
492 Func
) << R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
494 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_RB3D_Z_DISABLED_1
;
495 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
496 translate_func(GL_NEVER
) << R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
;
499 r300SetEarlyZState(ctx
);
502 static void r300UpdatePolygonMode(GLcontext
* ctx
)
504 r300ContextPtr r300
= R300_CONTEXT(ctx
);
505 uint32_t hw_mode
= 0;
507 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
508 ctx
->Polygon
.BackMode
!= GL_FILL
) {
511 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
512 f
= ctx
->Polygon
.FrontMode
;
513 b
= ctx
->Polygon
.BackMode
;
515 f
= ctx
->Polygon
.BackMode
;
516 b
= ctx
->Polygon
.FrontMode
;
519 hw_mode
|= R300_PM_ENABLED
;
523 hw_mode
|= R300_PM_FRONT_LINE
;
525 case GL_POINT
: /* noop */
526 hw_mode
|= R300_PM_FRONT_POINT
;
529 hw_mode
|= R300_PM_FRONT_FILL
;
535 hw_mode
|= R300_PM_BACK_LINE
;
537 case GL_POINT
: /* noop */
538 hw_mode
|= R300_PM_BACK_POINT
;
541 hw_mode
|= R300_PM_BACK_FILL
;
546 if (r300
->hw
.polygon_mode
.cmd
[1] != hw_mode
) {
547 R300_STATECHANGE(r300
, polygon_mode
);
548 r300
->hw
.polygon_mode
.cmd
[1] = hw_mode
;
551 r300
->hw
.polygon_mode
.cmd
[2] = 0x00000001;
552 r300
->hw
.polygon_mode
.cmd
[3] = 0x00000000;
556 * Change the culling mode.
558 * \note Mesa already filters redundant calls to this function.
560 static void r300CullFace(GLcontext
* ctx
, GLenum mode
)
564 r300UpdateCulling(ctx
);
568 * Change the polygon orientation.
570 * \note Mesa already filters redundant calls to this function.
572 static void r300FrontFace(GLcontext
* ctx
, GLenum mode
)
576 r300UpdateCulling(ctx
);
577 r300UpdatePolygonMode(ctx
);
581 * Change the depth testing function.
583 * \note Mesa already filters redundant calls to this function.
585 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
588 r300SetDepthState(ctx
);
592 * Enable/Disable depth writing.
594 * \note Mesa already filters redundant calls to this function.
596 static void r300DepthMask(GLcontext
* ctx
, GLboolean mask
)
599 r300SetDepthState(ctx
);
603 * Handle glColorMask()
605 static void r300ColorMask(GLcontext
* ctx
,
606 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
608 r300ContextPtr r300
= R300_CONTEXT(ctx
);
609 int mask
= (r
? R300_COLORMASK0_R
: 0) |
610 (g
? R300_COLORMASK0_G
: 0) |
611 (b
? R300_COLORMASK0_B
: 0) | (a
? R300_COLORMASK0_A
: 0);
613 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
614 R300_STATECHANGE(r300
, cmk
);
615 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
619 /* =============================================================
622 static void r300Fogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
)
624 r300ContextPtr r300
= R300_CONTEXT(ctx
);
628 } fogScale
, fogStart
;
632 fogScale
.i
= r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
];
633 fogStart
.i
= r300
->hw
.fogp
.cmd
[R300_FOGP_START
];
637 if (!ctx
->Fog
.Enabled
)
639 switch (ctx
->Fog
.Mode
) {
641 R300_STATECHANGE(r300
, fogs
);
642 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
644 cmd
[R300_FOGS_STATE
] & ~R300_FOG_MODE_MASK
) |
645 R300_FOG_MODE_LINEAR
;
647 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
652 1.0 / (ctx
->Fog
.End
- ctx
->Fog
.Start
);
654 -ctx
->Fog
.Start
/ (ctx
->Fog
.End
-
659 R300_STATECHANGE(r300
, fogs
);
660 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
662 cmd
[R300_FOGS_STATE
] & ~R300_FOG_MODE_MASK
) |
664 fogScale
.f
= 0.0933 * ctx
->Fog
.Density
;
668 R300_STATECHANGE(r300
, fogs
);
669 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] =
671 cmd
[R300_FOGS_STATE
] & ~R300_FOG_MODE_MASK
) |
673 fogScale
.f
= 0.3 * ctx
->Fog
.Density
;
680 switch (ctx
->Fog
.Mode
) {
682 fogScale
.f
= 0.0933 * ctx
->Fog
.Density
;
686 fogScale
.f
= 0.3 * ctx
->Fog
.Density
;
694 if (ctx
->Fog
.Mode
== GL_LINEAR
) {
695 if (ctx
->Fog
.Start
== ctx
->Fog
.End
) {
700 1.0 / (ctx
->Fog
.End
- ctx
->Fog
.Start
);
702 -ctx
->Fog
.Start
/ (ctx
->Fog
.End
-
708 R300_STATECHANGE(r300
, fogc
);
709 r300
->hw
.fogc
.cmd
[R300_FOGC_R
] =
710 (GLuint
) (ctx
->Fog
.Color
[0] * 1023.0F
) & 0x3FF;
711 r300
->hw
.fogc
.cmd
[R300_FOGC_G
] =
712 (GLuint
) (ctx
->Fog
.Color
[1] * 1023.0F
) & 0x3FF;
713 r300
->hw
.fogc
.cmd
[R300_FOGC_B
] =
714 (GLuint
) (ctx
->Fog
.Color
[2] * 1023.0F
) & 0x3FF;
716 case GL_FOG_COORD_SRC
:
722 if (fogScale
.i
!= r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
] ||
723 fogStart
.i
!= r300
->hw
.fogp
.cmd
[R300_FOGP_START
]) {
724 R300_STATECHANGE(r300
, fogp
);
725 r300
->hw
.fogp
.cmd
[R300_FOGP_SCALE
] = fogScale
.i
;
726 r300
->hw
.fogp
.cmd
[R300_FOGP_START
] = fogStart
.i
;
730 /* =============================================================
733 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
735 r300ContextPtr r300
= R300_CONTEXT(ctx
);
736 /* same size limits for AA, non-AA points */
737 size
= CLAMP(size
, ctx
->Const
.MinPointSize
, ctx
->Const
.MaxPointSize
);
739 R300_STATECHANGE(r300
, ps
);
740 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
741 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
742 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
745 /* =============================================================
748 static void r300LineWidth(GLcontext
* ctx
, GLfloat widthf
)
750 r300ContextPtr r300
= R300_CONTEXT(ctx
);
752 widthf
= CLAMP(widthf
,
753 ctx
->Const
.MinPointSize
,
754 ctx
->Const
.MaxPointSize
);
755 R300_STATECHANGE(r300
, lcntl
);
756 r300
->hw
.lcntl
.cmd
[1] =
757 R300_LINE_CNT_HO
| R300_LINE_CNT_VE
| (int)(widthf
* 6.0);
760 static void r300PolygonMode(GLcontext
* ctx
, GLenum face
, GLenum mode
)
765 r300UpdatePolygonMode(ctx
);
768 /* =============================================================
772 static int translate_stencil_op(int op
)
780 return R300_ZS_REPLACE
;
785 case GL_INCR_WRAP_EXT
:
786 return R300_ZS_INCR_WRAP
;
787 case GL_DECR_WRAP_EXT
:
788 return R300_ZS_DECR_WRAP
;
790 return R300_ZS_INVERT
;
792 WARN_ONCE("Do not know how to translate stencil op");
798 static void r300ShadeModel(GLcontext
* ctx
, GLenum mode
)
800 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
802 R300_STATECHANGE(rmesa
, shade
);
803 rmesa
->hw
.shade
.cmd
[1] = 0x00000002;
806 rmesa
->hw
.shade
.cmd
[2] = R300_RE_SHADE_MODEL_FLAT
;
809 rmesa
->hw
.shade
.cmd
[2] = R300_RE_SHADE_MODEL_SMOOTH
;
814 rmesa
->hw
.shade
.cmd
[3] = 0x00000000;
815 rmesa
->hw
.shade
.cmd
[4] = 0x00000000;
818 static void r300StencilFuncSeparate(GLcontext
* ctx
, GLenum face
,
819 GLenum func
, GLint ref
, GLuint mask
)
821 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
824 Ref
[0] & 0xff) << R300_RB3D_ZS2_STENCIL_REF_SHIFT
) | ((ctx
->
830 R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
834 R300_STATECHANGE(rmesa
, zs
);
836 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~((R300_ZS_MASK
<<
837 R300_RB3D_ZS1_FRONT_FUNC_SHIFT
)
839 R300_RB3D_ZS1_BACK_FUNC_SHIFT
));
841 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
842 ~((R300_RB3D_ZS2_STENCIL_MASK
<<
843 R300_RB3D_ZS2_STENCIL_REF_SHIFT
) |
844 (R300_RB3D_ZS2_STENCIL_MASK
<< R300_RB3D_ZS2_STENCIL_MASK_SHIFT
));
846 flag
= translate_func(ctx
->Stencil
.Function
[0]);
847 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
848 (flag
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
);
850 if (ctx
->Stencil
._TestTwoSide
)
851 flag
= translate_func(ctx
->Stencil
.Function
[1]);
853 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
854 (flag
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
855 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
858 static void r300StencilMaskSeparate(GLcontext
* ctx
, GLenum face
, GLuint mask
)
860 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
862 R300_STATECHANGE(rmesa
, zs
);
863 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
864 ~(R300_RB3D_ZS2_STENCIL_MASK
<<
865 R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
);
866 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |=
868 WriteMask
[0] & 0xff) << R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
;
871 static void r300StencilOpSeparate(GLcontext
* ctx
, GLenum face
,
872 GLenum fail
, GLenum zfail
, GLenum zpass
)
874 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
876 R300_STATECHANGE(rmesa
, zs
);
877 /* It is easier to mask what's left.. */
878 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
879 (R300_ZS_MASK
<< R300_RB3D_ZS1_DEPTH_FUNC_SHIFT
) |
880 (R300_ZS_MASK
<< R300_RB3D_ZS1_FRONT_FUNC_SHIFT
) |
881 (R300_ZS_MASK
<< R300_RB3D_ZS1_BACK_FUNC_SHIFT
);
883 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
884 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
885 R300_RB3D_ZS1_FRONT_FAIL_OP_SHIFT
)
886 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
887 R300_RB3D_ZS1_FRONT_ZFAIL_OP_SHIFT
)
888 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
889 R300_RB3D_ZS1_FRONT_ZPASS_OP_SHIFT
);
891 if (ctx
->Stencil
._TestTwoSide
) {
892 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
893 (translate_stencil_op(ctx
->Stencil
.FailFunc
[1]) <<
894 R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
895 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[1]) <<
896 R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
897 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[1]) <<
898 R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
900 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
901 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
902 R300_RB3D_ZS1_BACK_FAIL_OP_SHIFT
)
903 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
904 R300_RB3D_ZS1_BACK_ZFAIL_OP_SHIFT
)
905 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
906 R300_RB3D_ZS1_BACK_ZPASS_OP_SHIFT
);
910 static void r300ClearStencil(GLcontext
* ctx
, GLint s
)
912 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
914 rmesa
->state
.stencil
.clear
=
915 ((GLuint
) (ctx
->Stencil
.Clear
& 0xff) |
916 (R300_RB3D_ZS2_STENCIL_MASK
<<
917 R300_RB3D_ZS2_STENCIL_MASK_SHIFT
) | ((ctx
->Stencil
.
918 WriteMask
[0] & 0xff) <<
919 R300_RB3D_ZS2_STENCIL_WRITE_MASK_SHIFT
));
922 /* =============================================================
923 * Window position and viewport transformation
927 * To correctly position primitives:
929 #define SUBPIXEL_X 0.125
930 #define SUBPIXEL_Y 0.125
932 static void r300UpdateWindow(GLcontext
* ctx
)
934 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
935 __DRIdrawablePrivate
*dPriv
= rmesa
->radeon
.dri
.drawable
;
936 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
937 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
938 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
940 GLfloat sx
= v
[MAT_SX
];
941 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
942 GLfloat sy
= -v
[MAT_SY
];
943 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
944 GLfloat sz
= v
[MAT_SZ
] * rmesa
->state
.depth
.scale
;
945 GLfloat tz
= v
[MAT_TZ
] * rmesa
->state
.depth
.scale
;
947 R300_FIREVERTICES(rmesa
);
948 R300_STATECHANGE(rmesa
, vpt
);
950 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
951 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
952 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
953 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
954 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
955 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
958 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
959 GLsizei width
, GLsizei height
)
961 /* Don't pipeline viewport changes, conflict with window offset
962 * setting below. Could apply deltas to rescue pipelined viewport
963 * values, or keep the originals hanging around.
965 r300UpdateWindow(ctx
);
968 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
970 r300UpdateWindow(ctx
);
973 void r300UpdateViewportOffset(GLcontext
* ctx
)
975 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
976 __DRIdrawablePrivate
*dPriv
= ((radeonContextPtr
) rmesa
)->dri
.drawable
;
977 GLfloat xoffset
= (GLfloat
) dPriv
->x
;
978 GLfloat yoffset
= (GLfloat
) dPriv
->y
+ dPriv
->h
;
979 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
981 GLfloat tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
982 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
984 if (rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] != r300PackFloat32(tx
) ||
985 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] != r300PackFloat32(ty
)) {
986 /* Note: this should also modify whatever data the context reset
989 R300_STATECHANGE(rmesa
, vpt
);
990 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
991 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
995 radeonUpdateScissor(ctx
);
999 * Tell the card where to render (offset, pitch).
1000 * Effected by glDrawBuffer, etc
1002 void r300UpdateDrawBuffer(GLcontext
* ctx
)
1004 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1005 r300ContextPtr r300
= rmesa
;
1006 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1007 driRenderbuffer
*drb
;
1009 if (fb
->_ColorDrawBufferMask
[0] == BUFFER_BIT_FRONT_LEFT
) {
1012 (driRenderbuffer
*) fb
->Attachment
[BUFFER_FRONT_LEFT
].
1014 } else if (fb
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
) {
1017 (driRenderbuffer
*) fb
->Attachment
[BUFFER_BACK_LEFT
].
1020 /* drawing to multiple buffers, or none */
1025 assert(drb
->flippedPitch
);
1027 R300_STATECHANGE(rmesa
, cb
);
1029 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] = drb
->flippedOffset
+ //r300->radeon.state.color.drawOffset +
1030 r300
->radeon
.radeonScreen
->fbLocation
;
1031 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = drb
->flippedPitch
; //r300->radeon.state.color.drawPitch;
1033 if (r300
->radeon
.radeonScreen
->cpp
== 4)
1034 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
1036 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
1038 if (r300
->radeon
.sarea
->tiling_enabled
)
1039 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
1041 R200_STATECHANGE(rmesa
, ctx
);
1043 /* Note: we used the (possibly) page-flipped values */
1044 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLOROFFSET
]
1045 = ((drb
->flippedOffset
+ rmesa
->r200Screen
->fbLocation
)
1046 & R200_COLOROFFSET_MASK
);
1047 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] = drb
->flippedPitch
;
1049 if (rmesa
->sarea
->tiling_enabled
) {
1050 rmesa
->hw
.ctx
.cmd
[CTX_RB3D_COLORPITCH
] |=
1051 R200_COLOR_TILE_ENABLE
;
1057 r300FetchStateParameter(GLcontext
* ctx
,
1058 const gl_state_index state
[STATE_LENGTH
],
1061 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1064 case STATE_INTERNAL
:
1066 case STATE_R300_WINDOW_DIMENSION
:
1067 value
[0] = r300
->radeon
.dri
.drawable
->w
* 0.5f
; /* width*0.5 */
1068 value
[1] = r300
->radeon
.dri
.drawable
->h
* 0.5f
; /* height*0.5 */
1069 value
[2] = 0.5F
; /* for moving range [-1 1] -> [0 1] */
1070 value
[3] = 1.0F
; /* not used */
1073 case STATE_R300_TEXRECT_FACTOR
:{
1074 struct gl_texture_object
*t
=
1075 ctx
->Texture
.Unit
[state
[2]].CurrentRect
;
1077 if (t
&& t
->Image
[0][t
->BaseLevel
]) {
1078 struct gl_texture_image
*image
=
1079 t
->Image
[0][t
->BaseLevel
];
1080 value
[0] = 1.0 / image
->Width2
;
1081 value
[1] = 1.0 / image
->Height2
;
1102 * Update R300's own internal state parameters.
1103 * For now just STATE_R300_WINDOW_DIMENSION
1105 void r300UpdateStateParameters(GLcontext
* ctx
, GLuint new_state
)
1107 struct r300_fragment_program
*fp
;
1108 struct gl_program_parameter_list
*paramList
;
1111 if (!(new_state
& (_NEW_BUFFERS
| _NEW_PROGRAM
)))
1114 fp
= (struct r300_fragment_program
*)ctx
->FragmentProgram
._Current
;
1118 paramList
= fp
->mesa_program
.Base
.Parameters
;
1123 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1124 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1125 r300FetchStateParameter(ctx
,
1126 paramList
->Parameters
[i
].
1128 paramList
->ParameterValues
[i
]);
1133 /* =============================================================
1136 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
1138 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1139 GLfloat constant
= units
;
1141 switch (ctx
->Visual
.depthBits
) {
1152 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
1154 R300_STATECHANGE(rmesa
, zbs
);
1155 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
1156 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
1157 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
1158 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
1161 /* Routing and texture-related */
1163 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
1164 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
1165 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
1166 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1167 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1168 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1169 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
1170 * combinations where only one of them is nearest.
1172 static unsigned long gen_fixed_filter(unsigned long f
)
1174 unsigned long mag
, min
, needs_fixing
= 0;
1177 /* We ignore MIRROR bit so we dont have to do everything twice */
1178 if ((f
& ((7 - 1) << R300_TX_WRAP_S_SHIFT
)) ==
1179 (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)) {
1182 if ((f
& ((7 - 1) << R300_TX_WRAP_T_SHIFT
)) ==
1183 (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)) {
1186 if ((f
& ((7 - 1) << R300_TX_WRAP_Q_SHIFT
)) ==
1187 (R300_TX_CLAMP
<< R300_TX_WRAP_Q_SHIFT
)) {
1194 mag
= f
& R300_TX_MAG_FILTER_MASK
;
1195 min
= f
& R300_TX_MIN_FILTER_MASK
;
1197 /* TODO: Check for anisto filters too */
1198 if ((mag
!= R300_TX_MAG_FILTER_NEAREST
)
1199 && (min
!= R300_TX_MIN_FILTER_NEAREST
))
1202 /* r300 cant handle these modes hence we force nearest to linear */
1203 if ((mag
== R300_TX_MAG_FILTER_NEAREST
)
1204 && (min
!= R300_TX_MIN_FILTER_NEAREST
)) {
1205 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
1206 f
|= R300_TX_MAG_FILTER_LINEAR
;
1210 if ((min
== R300_TX_MIN_FILTER_NEAREST
)
1211 && (mag
!= R300_TX_MAG_FILTER_NEAREST
)) {
1212 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
1213 f
|= R300_TX_MIN_FILTER_LINEAR
;
1217 /* Both are nearest */
1218 if (needs_fixing
& 1) {
1219 f
&= ~((7 - 1) << R300_TX_WRAP_S_SHIFT
);
1220 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1222 if (needs_fixing
& 2) {
1223 f
&= ~((7 - 1) << R300_TX_WRAP_T_SHIFT
);
1224 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1226 if (needs_fixing
& 4) {
1227 f
&= ~((7 - 1) << R300_TX_WRAP_Q_SHIFT
);
1228 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_Q_SHIFT
;
1233 static void r300SetupTextures(GLcontext
* ctx
)
1236 struct r300_tex_obj
*t
;
1237 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1239 int last_hw_tmu
= -1; /* -1 translates into no setup costs for fields */
1240 int tmu_mappings
[R300_MAX_TEXTURE_UNITS
] = { -1, };
1241 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
1242 (char *)ctx
->FragmentProgram
._Current
;
1244 R300_STATECHANGE(r300
, txe
);
1245 R300_STATECHANGE(r300
, tex
.filter
);
1246 R300_STATECHANGE(r300
, tex
.filter_1
);
1247 R300_STATECHANGE(r300
, tex
.size
);
1248 R300_STATECHANGE(r300
, tex
.format
);
1249 R300_STATECHANGE(r300
, tex
.pitch
);
1250 R300_STATECHANGE(r300
, tex
.offset
);
1251 R300_STATECHANGE(r300
, tex
.chroma_key
);
1252 R300_STATECHANGE(r300
, tex
.border_color
);
1254 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] = 0x0;
1256 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1257 if (RADEON_DEBUG
& DEBUG_STATE
)
1258 fprintf(stderr
, "mtu=%d\n", mtu
);
1260 if (mtu
> R300_MAX_TEXTURE_UNITS
) {
1262 "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1263 mtu
, R300_MAX_TEXTURE_UNITS
);
1267 /* We cannot let disabled tmu offsets pass DRM */
1268 for (i
= 0; i
< mtu
; i
++) {
1269 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
1271 #if 0 /* Enables old behaviour */
1274 tmu_mappings
[i
] = hw_tmu
;
1276 t
= r300
->state
.texture
.unit
[i
].texobj
;
1277 /* XXX questionable fix for bug 9170: */
1281 if ((t
->format
& 0xffffff00) == 0xffffff00) {
1283 ("unknown texture format (entry %x) encountered. Help me !\n",
1287 if (RADEON_DEBUG
& DEBUG_STATE
)
1289 "Activating texture unit %d\n", i
);
1291 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= (1 << hw_tmu
);
1293 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+
1295 gen_fixed_filter(t
->filter
) | (hw_tmu
<< 28);
1296 /* Currently disabled! */
1297 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] = 0x0; //0x20501f80;
1298 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1300 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+
1301 hw_tmu
] = t
->format
;
1302 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1304 r300
->hw
.tex
.offset
.cmd
[R300_TEX_VALUE_0
+
1305 hw_tmu
] = t
->offset
;
1307 if (t
->offset
& R300_TXO_MACRO_TILE
) {
1308 WARN_ONCE("macro tiling enabled!\n");
1311 if (t
->offset
& R300_TXO_MICRO_TILE
) {
1312 WARN_ONCE("micro tiling enabled!\n");
1315 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_VALUE_0
+
1317 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+
1321 last_hw_tmu
= hw_tmu
;
1327 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1328 cmdpacket0(R300_TX_FILTER_0
, last_hw_tmu
+ 1);
1329 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_CMD_0
] =
1330 cmdpacket0(R300_TX_FILTER1_0
, last_hw_tmu
+ 1);
1331 r300
->hw
.tex
.size
.cmd
[R300_TEX_CMD_0
] =
1332 cmdpacket0(R300_TX_SIZE_0
, last_hw_tmu
+ 1);
1333 r300
->hw
.tex
.format
.cmd
[R300_TEX_CMD_0
] =
1334 cmdpacket0(R300_TX_FORMAT_0
, last_hw_tmu
+ 1);
1335 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_CMD_0
] =
1336 cmdpacket0(R300_TX_PITCH_0
, last_hw_tmu
+ 1);
1337 r300
->hw
.tex
.offset
.cmd
[R300_TEX_CMD_0
] =
1338 cmdpacket0(R300_TX_OFFSET_0
, last_hw_tmu
+ 1);
1339 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_CMD_0
] =
1340 cmdpacket0(R300_TX_CHROMA_KEY_0
, last_hw_tmu
+ 1);
1341 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_CMD_0
] =
1342 cmdpacket0(R300_TX_BORDER_COLOR_0
, last_hw_tmu
+ 1);
1344 if (!fp
) /* should only happenen once, just after context is created */
1347 R300_STATECHANGE(r300
, fpt
);
1349 for (i
= 0; i
< fp
->tex
.length
; i
++) {
1354 unit
= fp
->tex
.inst
[i
] >> R300_FPITX_IMAGE_SHIFT
;
1357 val
= fp
->tex
.inst
[i
];
1358 val
&= ~R300_FPITX_IMAGE_MASK
;
1361 (val
& R300_FPITX_OPCODE_MASK
) >> R300_FPITX_OPCODE_SHIFT
;
1362 if (opcode
== R300_FPITX_OP_KIL
) {
1363 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1365 if (tmu_mappings
[unit
] >= 0) {
1367 tmu_mappings
[unit
] <<
1368 R300_FPITX_IMAGE_SHIFT
;
1369 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1371 // We get here when the corresponding texture image is incomplete
1372 // (e.g. incomplete mipmaps etc.)
1373 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1378 r300
->hw
.fpt
.cmd
[R300_FPT_CMD_0
] =
1379 cmdpacket0(R300_PFS_TEXI_0
, fp
->tex
.length
);
1381 if (RADEON_DEBUG
& DEBUG_STATE
)
1382 fprintf(stderr
, "TX_ENABLE: %08x last_hw_tmu=%d\n",
1383 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], last_hw_tmu
);
1386 union r300_outputs_written
{
1387 GLuint vp_outputs
; /* hw_tcl_on */
1388 DECLARE_RENDERINPUTS(index_bitset
); /* !hw_tcl_on */
1391 #define R300_OUTPUTS_WRITTEN_TEST(ow, vp_result, tnl_attrib) \
1392 ((hw_tcl_on) ? (ow).vp_outputs & (1 << (vp_result)) : \
1393 RENDERINPUTS_TEST( (ow.index_bitset), (tnl_attrib) ))
1395 static void r300SetupRSUnit(GLcontext
* ctx
)
1397 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1398 /* I'm still unsure if these are needed */
1399 GLuint interp_magic
[8] = {
1401 R300_RS_INTERP_1_UNKNOWN
,
1402 R300_RS_INTERP_2_UNKNOWN
,
1403 R300_RS_INTERP_3_UNKNOWN
,
1409 union r300_outputs_written OutputsWritten
;
1411 int fp_reg
, high_rr
;
1412 int in_texcoords
, col_interp_nr
;
1416 OutputsWritten
.vp_outputs
= CURRENT_VERTEX_SHADER(ctx
)->key
.OutputsWritten
;
1418 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->state
.render_inputs_bitset
);
1420 if (ctx
->FragmentProgram
._Current
)
1421 InputsRead
= ctx
->FragmentProgram
._Current
->Base
.InputsRead
;
1423 fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1424 return; /* This should only ever happen once.. */
1427 R300_STATECHANGE(r300
, ri
);
1428 R300_STATECHANGE(r300
, rc
);
1429 R300_STATECHANGE(r300
, rr
);
1431 fp_reg
= in_texcoords
= col_interp_nr
= high_rr
= 0;
1433 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] = 0;
1435 if (InputsRead
& FRAG_BIT_WPOS
) {
1436 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
1437 if (!(InputsRead
& (FRAG_BIT_TEX0
<< i
)))
1440 if (i
== ctx
->Const
.MaxTextureUnits
) {
1441 fprintf(stderr
, "\tno free texcoord found...\n");
1445 InputsRead
|= (FRAG_BIT_TEX0
<< i
);
1446 InputsRead
&= ~FRAG_BIT_WPOS
;
1449 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1450 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0 | R300_RS_INTERP_USED
| (in_texcoords
<< R300_RS_INTERP_SRC_SHIFT
)
1453 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ fp_reg
] = 0;
1454 if (InputsRead
& (FRAG_BIT_TEX0
<< i
)) {
1455 //assert(r300->state.texture.tc_count != 0);
1456 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
+ fp_reg
] |= R300_RS_ROUTE_ENABLE
| i
/* source INTERP */
1457 | (fp_reg
<< R300_RS_ROUTE_DEST_SHIFT
);
1460 /* Passing invalid data here can lock the GPU. */
1461 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1462 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1465 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1468 /* Need to count all coords enabled at vof */
1469 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1474 if (InputsRead
& FRAG_BIT_COL0
) {
1475 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1476 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0 | R300_RS_ROUTE_0_COLOR
| (fp_reg
++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT
);
1477 InputsRead
&= ~FRAG_BIT_COL0
;
1480 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1484 if (InputsRead
& FRAG_BIT_COL1
) {
1485 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1486 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_1
] |= R300_RS_ROUTE_1_UNKNOWN11
| R300_RS_ROUTE_1_COLOR1
| (fp_reg
++ << R300_RS_ROUTE_1_COLOR1_DEST_SHIFT
);
1487 InputsRead
&= ~FRAG_BIT_COL1
;
1492 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1496 /* Need at least one. This might still lock as the values are undefined... */
1497 if (in_texcoords
== 0 && col_interp_nr
== 0) {
1498 r300
->hw
.rr
.cmd
[R300_RR_ROUTE_0
] |= 0 | R300_RS_ROUTE_0_COLOR
| (fp_reg
++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT
);
1502 r300
->hw
.rc
.cmd
[1] = 0 | (in_texcoords
<< R300_RS_CNTL_TC_CNT_SHIFT
)
1503 | (col_interp_nr
<< R300_RS_CNTL_CI_CNT_SHIFT
)
1504 | R300_RS_CNTL_0_UNKNOWN_18
;
1506 assert(high_rr
>= 0);
1507 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(R300_RS_ROUTE_0
, high_rr
+ 1);
1508 r300
->hw
.rc
.cmd
[2] = 0xC0 | high_rr
;
1511 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1514 #define bump_vpu_count(ptr, new_count) do{\
1515 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
1516 int _nc=(new_count)/4; \
1517 assert(_nc < 256); \
1518 if(_nc>_p->vpu.count)_p->vpu.count=_nc;\
1521 static inline void r300SetupVertexProgramFragment(r300ContextPtr r300
, int dest
, struct r300_vertex_shader_fragment
*vsf
)
1525 if (vsf
->length
== 0)
1528 if (vsf
->length
& 0x3) {
1529 fprintf(stderr
, "VERTEX_SHADER_FRAGMENT must have length divisible by 4\n");
1533 switch ((dest
>> 8) & 0xf) {
1535 R300_STATECHANGE(r300
, vpi
);
1536 for (i
= 0; i
< vsf
->length
; i
++)
1537 r300
->hw
.vpi
.cmd
[R300_VPI_INSTR_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1538 bump_vpu_count(r300
->hw
.vpi
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1542 R300_STATECHANGE(r300
, vpp
);
1543 for (i
= 0; i
< vsf
->length
; i
++)
1544 r300
->hw
.vpp
.cmd
[R300_VPP_PARAM_0
+ i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1545 bump_vpu_count(r300
->hw
.vpp
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1548 R300_STATECHANGE(r300
, vps
);
1549 for (i
= 0; i
< vsf
->length
; i
++)
1550 r300
->hw
.vps
.cmd
[1 + i
+ 4 * (dest
& 0xff)] = (vsf
->body
.d
[i
]);
1551 bump_vpu_count(r300
->hw
.vps
.cmd
, vsf
->length
+ 4 * (dest
& 0xff));
1554 fprintf(stderr
, "%s:%s don't know how to handle dest %04x\n", __FILE__
, __FUNCTION__
, dest
);
1559 static void r300SetupDefaultVertexProgram(r300ContextPtr rmesa
)
1561 struct r300_vertex_shader_state
*prog
= &(rmesa
->state
.vertex_shader
);
1565 int param_count
= 0;
1566 int program_end
= 0;
1568 for (i
= VERT_ATTRIB_POS
; i
< VERT_ATTRIB_MAX
; i
++) {
1569 if (rmesa
->state
.sw_tcl_inputs
[i
] != -1) {
1570 prog
->program
.body
.i
[program_end
+ 0] = EASY_VSF_OP(MUL
, o_reg
++, ALL
, RESULT
);
1571 prog
->program
.body
.i
[program_end
+ 1] = VSF_REG(rmesa
->state
.sw_tcl_inputs
[i
]);
1572 prog
->program
.body
.i
[program_end
+ 2] = VSF_ATTR_UNITY(rmesa
->state
.sw_tcl_inputs
[i
]);
1573 prog
->program
.body
.i
[program_end
+ 3] = VSF_UNITY(rmesa
->state
.sw_tcl_inputs
[i
]);
1578 prog
->program
.length
= program_end
;
1580 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
,
1582 inst_count
= (prog
->program
.length
/ 4) - 1;
1584 R300_STATECHANGE(rmesa
, pvs
);
1585 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1586 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1587 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1588 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1589 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1590 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1591 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1592 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1593 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1594 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1597 static void r300SetupRealVertexProgram(r300ContextPtr rmesa
)
1599 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1600 struct r300_vertex_program
*prog
= (struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
);
1602 int param_count
= 0;
1604 /* FIXME: r300SetupVertexProgramFragment */
1605 R300_STATECHANGE(rmesa
, vpp
);
1607 r300VertexProgUpdateParams(ctx
,
1608 (struct r300_vertex_program_cont
*)
1609 ctx
->VertexProgram
._Current
,
1610 (float *)&rmesa
->hw
.vpp
.
1611 cmd
[R300_VPP_PARAM_0
]);
1612 bump_vpu_count(rmesa
->hw
.vpp
.cmd
, param_count
);
1615 r300SetupVertexProgramFragment(rmesa
, R300_PVS_UPLOAD_PROGRAM
, &(prog
->program
));
1616 inst_count
= (prog
->program
.length
/ 4) - 1;
1618 R300_STATECHANGE(rmesa
, pvs
);
1619 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_1
] =
1620 (0 << R300_PVS_CNTL_1_PROGRAM_START_SHIFT
) |
1621 (inst_count
<< R300_PVS_CNTL_1_POS_END_SHIFT
) |
1622 (inst_count
<< R300_PVS_CNTL_1_PROGRAM_END_SHIFT
);
1623 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_2
] =
1624 (0 << R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT
) |
1625 (param_count
<< R300_PVS_CNTL_2_PARAM_COUNT_SHIFT
);
1626 rmesa
->hw
.pvs
.cmd
[R300_PVS_CNTL_3
] =
1627 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN_SHIFT
) |
1628 (inst_count
<< R300_PVS_CNTL_3_PROGRAM_UNKNOWN2_SHIFT
);
1631 static void r300SetupVertexProgram(r300ContextPtr rmesa
)
1633 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1635 /* Reset state, in case we don't use something */
1636 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpp
.cmd
)->vpu
.count
= 0;
1637 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vpi
.cmd
)->vpu
.count
= 0;
1638 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vps
.cmd
)->vpu
.count
= 0;
1640 /* Not sure why this doesnt work...
1641 0x400 area might have something to do with pixel shaders as it appears right after pfs programming.
1642 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. */
1643 //setup_vertex_shader_fragment(rmesa, 0x406, &unk4);
1644 if (hw_tcl_on
&& ((struct r300_vertex_program
*)CURRENT_VERTEX_SHADER(ctx
))->translated
) {
1645 r300SetupRealVertexProgram(rmesa
);
1647 /* FIXME: This needs to be replaced by vertex shader generation code. */
1648 r300SetupDefaultVertexProgram(rmesa
);
1652 /* FIXME: This is done for vertex shader fragments, but also needs to be
1653 * done for vap_pvs, so I leave it as a reminder. */
1655 reg_start(R300_VAP_PVS_WAITIDLE
, 0);
1661 * Enable/Disable states.
1663 * \note Mesa already filters redundant calls to this function.
1665 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1667 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1669 if (RADEON_DEBUG
& DEBUG_STATE
)
1670 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1671 _mesa_lookup_enum_by_nr(cap
),
1672 state
? "GL_TRUE" : "GL_FALSE");
1675 /* Fast track this one...
1683 R300_STATECHANGE(r300
, fogs
);
1685 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] |= R300_FOG_ENABLE
;
1687 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
1688 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
1689 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
1690 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
1691 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
1693 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] &= ~R300_FOG_ENABLE
;
1699 r300SetAlphaState(ctx
);
1703 case GL_COLOR_LOGIC_OP
:
1704 r300SetBlendState(ctx
);
1708 r300SetDepthState(ctx
);
1711 case GL_STENCIL_TEST
:
1712 if (r300
->state
.stencil
.hw_stencil
) {
1713 R300_STATECHANGE(r300
, zs
);
1715 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
1716 R300_RB3D_STENCIL_ENABLE
;
1718 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
1719 ~R300_RB3D_STENCIL_ENABLE
;
1723 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_STENCIL
, state
);
1729 r300UpdateCulling(ctx
);
1732 case GL_POLYGON_OFFSET_POINT
:
1733 case GL_POLYGON_OFFSET_LINE
:
1734 case GL_POLYGON_OFFSET_FILL
:
1735 R300_STATECHANGE(r300
, occlusion_cntl
);
1737 r300
->hw
.occlusion_cntl
.cmd
[1] |= (3 << 0);
1739 r300
->hw
.occlusion_cntl
.cmd
[1] &= ~(3 << 0);
1743 radeonEnable(ctx
, cap
, state
);
1749 * Completely recalculates hardware state based on the Mesa state.
1751 static void r300ResetHwState(r300ContextPtr r300
)
1753 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1756 if (!(r300
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
1759 if (RADEON_DEBUG
& DEBUG_STATE
)
1760 fprintf(stderr
, "%s\n", __FUNCTION__
);
1762 r300UpdateWindow(ctx
);
1765 ctx
->Color
.ColorMask
[RCOMP
],
1766 ctx
->Color
.ColorMask
[GCOMP
],
1767 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1769 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1770 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1771 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1774 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
1775 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1776 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1777 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1778 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1779 ctx
->Stencil
.ZFailFunc
[0],
1780 ctx
->Stencil
.ZPassFunc
[0]);
1782 r300UpdateCulling(ctx
);
1784 r300UpdateTextureState(ctx
);
1786 r300SetBlendState(ctx
);
1788 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1789 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1792 r300
->hw
.vap_cntl
.cmd
[1] = 0x0014045a;
1794 r300
->hw
.vap_cntl
.cmd
[1] = 0x0030045A; //0x0030065a /* Dangerous */
1796 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1797 | R300_VPORT_X_OFFSET_ENA
1798 | R300_VPORT_Y_SCALE_ENA
1799 | R300_VPORT_Y_OFFSET_ENA
1800 | R300_VPORT_Z_SCALE_ENA
1801 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
1802 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1804 r300
->hw
.unk2134
.cmd
[1] = 0x00FFFFFF;
1805 r300
->hw
.unk2134
.cmd
[2] = 0x00000000;
1807 #ifdef MESA_LITTLE_ENDIAN
1808 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
1810 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
1813 /* disable VAP/TCL on non-TCL capable chips */
1815 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
1817 r300
->hw
.unk21DC
.cmd
[1] = 0xAAAAAAAA;
1819 r300
->hw
.unk221C
.cmd
[1] = R300_221C_NORMAL
;
1821 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
1822 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
1823 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
1824 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
1826 /* XXX: Other families? */
1828 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1829 case CHIP_FAMILY_R300
:
1830 r300
->hw
.unk2288
.cmd
[1] = R300_2288_R300
;
1833 r300
->hw
.unk2288
.cmd
[1] = R300_2288_RV350
;
1838 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
1839 | R300_GB_LINE_STUFF_ENABLE
1840 | R300_GB_TRIANGLE_STUFF_ENABLE
/*| R300_GB_UNK31 */ ;
1842 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
1843 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
1845 /* XXX: Other families? */
1846 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
1847 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
;
1848 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1849 case CHIP_FAMILY_R300
:
1850 case CHIP_FAMILY_R350
:
1851 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1852 R300_GB_TILE_PIPE_COUNT_R300
;
1854 case CHIP_FAMILY_RV410
:
1855 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1856 R300_GB_TILE_PIPE_COUNT_RV410
;
1858 case CHIP_FAMILY_R420
:
1859 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1860 R300_GB_TILE_PIPE_COUNT_R420
;
1863 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1864 R300_GB_TILE_PIPE_COUNT_RV300
;
1868 /* XXX: set to 0 when fog is disabled? */
1869 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_SELECT
] = R300_GB_FOG_SELECT_1_1_W
;
1871 /* XXX: Enable anti-aliasing? */
1872 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_AA_CONFIG
] = R300_AA_DISABLE
;
1874 r300
->hw
.unk4200
.cmd
[1] = r300PackFloat32(0.0);
1875 r300
->hw
.unk4200
.cmd
[2] = r300PackFloat32(0.0);
1876 r300
->hw
.unk4200
.cmd
[3] = r300PackFloat32(1.0);
1877 r300
->hw
.unk4200
.cmd
[4] = r300PackFloat32(1.0);
1879 r300
->hw
.unk4214
.cmd
[1] = 0x00050005;
1881 r300PointSize(ctx
, 1.0);
1883 r300
->hw
.unk4230
.cmd
[1] = 0x18000006;
1884 r300
->hw
.unk4230
.cmd
[2] = 0x00020006;
1885 r300
->hw
.unk4230
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
1887 r300LineWidth(ctx
, 1.0);
1889 r300
->hw
.unk4260
.cmd
[1] = 0;
1890 r300
->hw
.unk4260
.cmd
[2] = r300PackFloat32(0.0);
1891 r300
->hw
.unk4260
.cmd
[3] = r300PackFloat32(1.0);
1893 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
1895 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
1896 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
1897 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
1899 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
1900 ctx
->Polygon
.OffsetUnits
);
1901 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
1902 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
1903 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
1905 r300
->hw
.unk42C0
.cmd
[1] = 0x4B7FFFFF;
1906 r300
->hw
.unk42C0
.cmd
[2] = 0x00000000;
1908 r300
->hw
.unk43A4
.cmd
[1] = 0x0000001C;
1909 r300
->hw
.unk43A4
.cmd
[2] = 0x2DA49525;
1911 r300
->hw
.unk43E8
.cmd
[1] = 0x00FFFFFF;
1913 r300
->hw
.unk46A4
.cmd
[1] = 0x00001B01;
1914 r300
->hw
.unk46A4
.cmd
[2] = 0x00001B0F;
1915 r300
->hw
.unk46A4
.cmd
[3] = 0x00001B0F;
1916 r300
->hw
.unk46A4
.cmd
[4] = 0x00001B0F;
1917 r300
->hw
.unk46A4
.cmd
[5] = 0x00000001;
1919 r300Enable(ctx
, GL_FOG
, ctx
->Fog
.Enabled
);
1920 r300Fogfv(ctx
, GL_FOG_MODE
, NULL
);
1921 r300Fogfv(ctx
, GL_FOG_DENSITY
, &ctx
->Fog
.Density
);
1922 r300Fogfv(ctx
, GL_FOG_START
, &ctx
->Fog
.Start
);
1923 r300Fogfv(ctx
, GL_FOG_END
, &ctx
->Fog
.End
);
1924 r300Fogfv(ctx
, GL_FOG_COLOR
, ctx
->Fog
.Color
);
1925 r300Fogfv(ctx
, GL_FOG_COORDINATE_SOURCE_EXT
, NULL
);
1927 r300
->hw
.unk4BD8
.cmd
[1] = 0;
1929 r300
->hw
.unk4E00
.cmd
[1] = 0;
1931 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
1933 /* Again, r300ClearBuffer uses this */
1934 r300
->hw
.cb
.cmd
[R300_CB_OFFSET
] =
1935 r300
->radeon
.state
.color
.drawOffset
+
1936 r300
->radeon
.radeonScreen
->fbLocation
;
1937 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] = r300
->radeon
.state
.color
.drawPitch
;
1939 if (r300
->radeon
.radeonScreen
->cpp
== 4)
1940 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_ARGB8888
;
1942 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_FORMAT_RGB565
;
1944 if (r300
->radeon
.sarea
->tiling_enabled
)
1945 r300
->hw
.cb
.cmd
[R300_CB_PITCH
] |= R300_COLOR_TILE_ENABLE
;
1947 r300
->hw
.unk4E50
.cmd
[1] = 0;
1948 r300
->hw
.unk4E50
.cmd
[2] = 0;
1949 r300
->hw
.unk4E50
.cmd
[3] = 0;
1950 r300
->hw
.unk4E50
.cmd
[4] = 0;
1951 r300
->hw
.unk4E50
.cmd
[5] = 0;
1952 r300
->hw
.unk4E50
.cmd
[6] = 0;
1953 r300
->hw
.unk4E50
.cmd
[7] = 0;
1954 r300
->hw
.unk4E50
.cmd
[8] = 0;
1955 r300
->hw
.unk4E50
.cmd
[9] = 0;
1957 r300
->hw
.unk4E88
.cmd
[1] = 0;
1959 r300
->hw
.unk4EA0
.cmd
[1] = 0x00000000;
1960 r300
->hw
.unk4EA0
.cmd
[2] = 0xffffffff;
1962 r300
->hw
.zb
.cmd
[R300_ZB_OFFSET
] =
1963 r300
->radeon
.radeonScreen
->depthOffset
+
1964 r300
->radeon
.radeonScreen
->fbLocation
;
1965 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] = r300
->radeon
.radeonScreen
->depthPitch
;
1967 if (r300
->radeon
.sarea
->tiling_enabled
) {
1968 /* XXX: Turn off when clearing buffers ? */
1969 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |= R300_DEPTH_TILE_ENABLE
;
1971 if (ctx
->Visual
.depthBits
== 24)
1972 r300
->hw
.zb
.cmd
[R300_ZB_PITCH
] |=
1973 R300_DEPTH_MICROTILE_ENABLE
;
1976 r300
->hw
.unk4F28
.cmd
[1] = 0;
1978 r300
->hw
.unk4F30
.cmd
[1] = 0;
1979 r300
->hw
.unk4F30
.cmd
[2] = 0;
1981 r300
->hw
.unk4F44
.cmd
[1] = 0;
1983 r300
->hw
.unk4F54
.cmd
[1] = 0;
1986 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
1987 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
1988 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
1989 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
1992 r300
->hw
.all_dirty
= GL_TRUE
;
1995 void r300UpdateShaders(r300ContextPtr rmesa
)
1998 struct r300_vertex_program
*vp
;
2001 ctx
= rmesa
->radeon
.glCtx
;
2003 if (rmesa
->NewGLState
&& hw_tcl_on
) {
2004 rmesa
->NewGLState
= 0;
2006 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2007 rmesa
->temp_attrib
[i
] =
2008 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
2009 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2010 &rmesa
->dummy_attrib
[i
];
2013 _tnl_UpdateFixedFunctionProgram(ctx
);
2015 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2016 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2017 rmesa
->temp_attrib
[i
];
2020 r300SelectVertexShader(rmesa
);
2021 vp
= (struct r300_vertex_program
*)
2022 CURRENT_VERTEX_SHADER(ctx
);
2023 /*if (vp->translated == GL_FALSE)
2024 r300TranslateVertexShader(vp); */
2025 if (vp
->translated
== GL_FALSE
) {
2026 fprintf(stderr
, "Failing back to sw-tcl\n");
2027 hw_tcl_on
= future_hw_tcl_on
= 0;
2028 r300ResetHwState(rmesa
);
2032 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
);
2036 static void r300SetupPixelShader(r300ContextPtr rmesa
)
2038 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
2039 struct r300_fragment_program
*fp
= (struct r300_fragment_program
*)
2040 (char *)ctx
->FragmentProgram
._Current
;
2043 if (!fp
) /* should only happenen once, just after context is created */
2046 r300TranslateFragmentShader(rmesa
, fp
);
2047 if (!fp
->translated
) {
2048 fprintf(stderr
, "%s: No valid fragment shader, exiting\n",
2053 R300_STATECHANGE(rmesa
, fpi
[0]);
2054 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR0_0
, fp
->alu_end
+ 1);
2055 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2056 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst0
;
2059 R300_STATECHANGE(rmesa
, fpi
[1]);
2060 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR1_0
, fp
->alu_end
+ 1);
2061 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2062 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst1
;
2065 R300_STATECHANGE(rmesa
, fpi
[2]);
2066 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR2_0
, fp
->alu_end
+ 1);
2067 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2068 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst2
;
2071 R300_STATECHANGE(rmesa
, fpi
[3]);
2072 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(R300_PFS_INSTR3_0
, fp
->alu_end
+ 1);
2073 for (i
= 0; i
<= fp
->alu_end
; i
++) {
2074 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = fp
->alu
.inst
[i
].inst3
;
2077 R300_STATECHANGE(rmesa
, fp
);
2078 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = fp
->cur_node
| (fp
->first_node_has_tex
<< 3);
2079 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = fp
->max_temp_idx
;
2080 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] =
2081 (fp
->alu_offset
<< R300_PFS_CNTL_ALU_OFFSET_SHIFT
) |
2082 (fp
->alu_end
<< R300_PFS_CNTL_ALU_END_SHIFT
) |
2083 (fp
->tex_offset
<< R300_PFS_CNTL_TEX_OFFSET_SHIFT
) |
2084 (fp
->tex_end
<< R300_PFS_CNTL_TEX_END_SHIFT
);
2085 /* I just want to say, the way these nodes are stored.. weird.. */
2086 for (i
= 0, k
= (4 - (fp
->cur_node
+ 1)); i
< 4; i
++, k
++) {
2087 if (i
< (fp
->cur_node
+ 1)) {
2088 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ k
] =
2089 (fp
->node
[i
].alu_offset
<< R300_PFS_NODE_ALU_OFFSET_SHIFT
) |
2090 (fp
->node
[i
].alu_end
<< R300_PFS_NODE_ALU_END_SHIFT
) |
2091 (fp
->node
[i
].tex_offset
<< R300_PFS_NODE_TEX_OFFSET_SHIFT
) |
2092 (fp
->node
[i
].tex_end
<< R300_PFS_NODE_TEX_END_SHIFT
) |
2095 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ (3 - i
)] = 0;
2099 R300_STATECHANGE(rmesa
, fpp
);
2100 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(R300_PFS_PARAM_0_X
, fp
->const_nr
* 4);
2101 for (i
= 0; i
< fp
->const_nr
; i
++) {
2102 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(fp
->constant
[i
][0]);
2103 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(fp
->constant
[i
][1]);
2104 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(fp
->constant
[i
][2]);
2105 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(fp
->constant
[i
][3]);
2109 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2112 ctx
= rmesa
->radeon
.glCtx
;
2114 r300UpdateTextureState(ctx
);
2116 r300SetupPixelShader(rmesa
);
2117 r300SetupTextures(ctx
);
2119 if ((rmesa
->radeon
.radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
))
2120 r300SetupVertexProgram(rmesa
);
2121 r300SetupRSUnit(ctx
);
2125 * Called by Mesa after an internal state update.
2127 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2129 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2131 _swrast_InvalidateState(ctx
, new_state
);
2132 _swsetup_InvalidateState(ctx
, new_state
);
2133 _vbo_InvalidateState(ctx
, new_state
);
2134 _tnl_InvalidateState(ctx
, new_state
);
2135 _ae_invalidate_state(ctx
, new_state
);
2137 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
2138 r300UpdateDrawBuffer(ctx
);
2141 r300UpdateStateParameters(ctx
, new_state
);
2143 r300
->NewGLState
|= new_state
;
2147 * Calculate initial hardware state and register state functions.
2148 * Assumes that the command buffer and state atoms have been
2149 * initialized already.
2151 void r300InitState(r300ContextPtr r300
)
2153 GLcontext
*ctx
= r300
->radeon
.glCtx
;
2156 radeonInitState(&r300
->radeon
);
2158 switch (ctx
->Visual
.depthBits
) {
2160 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffff;
2161 depth_fmt
= R300_DEPTH_FORMAT_16BIT_INT_Z
;
2162 r300
->state
.stencil
.clear
= 0x00000000;
2165 r300
->state
.depth
.scale
= 1.0 / (GLfloat
) 0xffffff;
2166 depth_fmt
= R300_DEPTH_FORMAT_24BIT_INT_Z
;
2167 r300
->state
.stencil
.clear
= 0x00ff0000;
2170 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
2171 ctx
->Visual
.depthBits
);
2175 /* Only have hw stencil when depth buffer is 24 bits deep */
2176 r300
->state
.stencil
.hw_stencil
= (ctx
->Visual
.stencilBits
> 0 &&
2177 ctx
->Visual
.depthBits
== 24);
2179 memset(&(r300
->state
.texture
), 0, sizeof(r300
->state
.texture
));
2181 r300ResetHwState(r300
);
2184 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2186 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2192 * Initialize driver's state callback functions
2194 void r300InitStateFuncs(struct dd_function_table
*functions
)
2196 radeonInitStateFuncs(functions
);
2198 functions
->UpdateState
= r300InvalidateState
;
2199 functions
->AlphaFunc
= r300AlphaFunc
;
2200 functions
->BlendColor
= r300BlendColor
;
2201 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2202 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2203 functions
->Enable
= r300Enable
;
2204 functions
->ColorMask
= r300ColorMask
;
2205 functions
->DepthFunc
= r300DepthFunc
;
2206 functions
->DepthMask
= r300DepthMask
;
2207 functions
->CullFace
= r300CullFace
;
2208 functions
->Fogfv
= r300Fogfv
;
2209 functions
->FrontFace
= r300FrontFace
;
2210 functions
->ShadeModel
= r300ShadeModel
;
2212 /* Stencil related */
2213 functions
->ClearStencil
= r300ClearStencil
;
2214 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2215 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2216 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2218 /* Viewport related */
2219 functions
->Viewport
= r300Viewport
;
2220 functions
->DepthRange
= r300DepthRange
;
2221 functions
->PointSize
= r300PointSize
;
2222 functions
->LineWidth
= r300LineWidth
;
2224 functions
->PolygonOffset
= r300PolygonOffset
;
2225 functions
->PolygonMode
= r300PolygonMode
;
2227 functions
->RenderMode
= r300RenderMode
;