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>
38 #include "main/glheader.h"
39 #include "main/state.h"
40 #include "main/imports.h"
41 #include "main/enums.h"
42 #include "main/macros.h"
43 #include "main/context.h"
45 #include "main/framebuffer.h"
46 #include "main/simple_list.h"
47 #include "main/api_arrayelt.h"
48 #include "main/texformat.h"
50 #include "swrast/swrast.h"
51 #include "swrast_setup/swrast_setup.h"
52 #include "shader/prog_parameter.h"
53 #include "shader/prog_statevars.h"
56 #include "tnl/t_vp_build.h"
58 #include "r300_context.h"
59 #include "r300_ioctl.h"
60 #include "r300_state.h"
62 #include "r300_emit.h"
64 #include "r300_fragprog_common.h"
65 #include "r300_fragprog.h"
66 #include "r500_fragprog.h"
67 #include "r300_render.h"
68 #include "r300_vertprog.h"
70 #include "drirenderbuffer.h"
72 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
74 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
76 R300_STATECHANGE(rmesa
, blend_color
);
78 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
) {
79 GLuint r
= IROUND(cf
[0]*1023.0f
);
80 GLuint g
= IROUND(cf
[1]*1023.0f
);
81 GLuint b
= IROUND(cf
[2]*1023.0f
);
82 GLuint a
= IROUND(cf
[3]*1023.0f
);
84 rmesa
->hw
.blend_color
.cmd
[1] = r
| (a
<< 16);
85 rmesa
->hw
.blend_color
.cmd
[2] = b
| (g
<< 16);
88 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
89 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
90 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
91 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
93 rmesa
->hw
.blend_color
.cmd
[1] = PACK_COLOR_8888(color
[3], color
[0],
99 * Calculate the hardware blend factor setting. This same function is used
100 * for source and destination of both alpha and RGB.
103 * The hardware register value for the specified blend factor. This value
104 * will need to be shifted into the correct position for either source or
105 * destination factor.
108 * Since the two cases where source and destination are handled differently
109 * are essentially error cases, they should never happen. Determine if these
110 * cases can be removed.
112 static int blend_factor(GLenum factor
, GLboolean is_src
)
116 return R300_BLEND_GL_ZERO
;
119 return R300_BLEND_GL_ONE
;
122 return R300_BLEND_GL_DST_COLOR
;
124 case GL_ONE_MINUS_DST_COLOR
:
125 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
128 return R300_BLEND_GL_SRC_COLOR
;
130 case GL_ONE_MINUS_SRC_COLOR
:
131 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
134 return R300_BLEND_GL_SRC_ALPHA
;
136 case GL_ONE_MINUS_SRC_ALPHA
:
137 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
140 return R300_BLEND_GL_DST_ALPHA
;
142 case GL_ONE_MINUS_DST_ALPHA
:
143 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
145 case GL_SRC_ALPHA_SATURATE
:
146 return (is_src
) ? R300_BLEND_GL_SRC_ALPHA_SATURATE
:
149 case GL_CONSTANT_COLOR
:
150 return R300_BLEND_GL_CONST_COLOR
;
152 case GL_ONE_MINUS_CONSTANT_COLOR
:
153 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
155 case GL_CONSTANT_ALPHA
:
156 return R300_BLEND_GL_CONST_ALPHA
;
158 case GL_ONE_MINUS_CONSTANT_ALPHA
:
159 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
162 fprintf(stderr
, "unknown blend factor %x\n", factor
);
163 return (is_src
) ? R300_BLEND_GL_ONE
: R300_BLEND_GL_ZERO
;
169 * Sets both the blend equation and the blend function.
170 * This is done in a single
171 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
172 * change the interpretation of the blend function.
173 * Also, make sure that blend function and blend equation are set to their
174 * default value if color blending is not enabled, since at least blend
175 * equations GL_MIN and GL_FUNC_REVERSE_SUBTRACT will cause wrong results
176 * otherwise for unknown reasons.
179 /* helper function */
180 static void r300SetBlendCntl(r300ContextPtr r300
, int func
, int eqn
,
181 int cbits
, int funcA
, int eqnA
)
183 GLuint new_ablend
, new_cblend
;
187 "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n",
188 eqnA
, funcA
, eqn
, func
, cbits
);
190 new_ablend
= eqnA
| funcA
;
191 new_cblend
= eqn
| func
;
193 /* Some blend factor combinations don't seem to work when the
194 * BLEND_NO_SEPARATE bit is set.
196 * Especially problematic candidates are the ONE_MINUS_* flags,
197 * but I can't see a real pattern.
200 if (new_ablend
== new_cblend
) {
201 new_cblend
|= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0
;
206 if ((new_ablend
!= r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]) ||
207 (new_cblend
!= r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
])) {
208 R300_STATECHANGE(r300
, bld
);
209 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = new_ablend
;
210 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = new_cblend
;
214 static void r300SetBlendState(GLcontext
* ctx
)
216 r300ContextPtr r300
= R300_CONTEXT(ctx
);
217 int func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
218 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
219 int eqn
= R300_COMB_FCN_ADD_CLAMP
;
220 int funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
221 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
222 int eqnA
= R300_COMB_FCN_ADD_CLAMP
;
224 if (RGBA_LOGICOP_ENABLED(ctx
) || !ctx
->Color
.BlendEnabled
) {
225 r300SetBlendCntl(r300
, func
, eqn
, 0, func
, eqn
);
230 (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) <<
231 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstRGB
,
233 R300_DST_BLEND_SHIFT
);
235 switch (ctx
->Color
.BlendEquationRGB
) {
237 eqn
= R300_COMB_FCN_ADD_CLAMP
;
240 case GL_FUNC_SUBTRACT
:
241 eqn
= R300_COMB_FCN_SUB_CLAMP
;
244 case GL_FUNC_REVERSE_SUBTRACT
:
245 eqn
= R300_COMB_FCN_RSUB_CLAMP
;
249 eqn
= R300_COMB_FCN_MIN
;
250 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
251 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
255 eqn
= R300_COMB_FCN_MAX
;
256 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
257 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
262 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
263 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
268 (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) <<
269 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstA
,
271 R300_DST_BLEND_SHIFT
);
273 switch (ctx
->Color
.BlendEquationA
) {
275 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
278 case GL_FUNC_SUBTRACT
:
279 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
282 case GL_FUNC_REVERSE_SUBTRACT
:
283 eqnA
= R300_COMB_FCN_RSUB_CLAMP
;
287 eqnA
= R300_COMB_FCN_MIN
;
288 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
289 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
293 eqnA
= R300_COMB_FCN_MAX
;
294 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
295 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
300 "[%s:%u] Invalid A blend equation (0x%04x).\n",
301 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
305 r300SetBlendCntl(r300
,
307 (R300_SEPARATE_ALPHA_ENABLE
|
309 R300_ALPHA_BLEND_ENABLE
), funcA
, eqnA
);
312 static void r300BlendEquationSeparate(GLcontext
* ctx
,
313 GLenum modeRGB
, GLenum modeA
)
315 r300SetBlendState(ctx
);
318 static void r300BlendFuncSeparate(GLcontext
* ctx
,
319 GLenum sfactorRGB
, GLenum dfactorRGB
,
320 GLenum sfactorA
, GLenum dfactorA
)
322 r300SetBlendState(ctx
);
326 * Translate LogicOp enums into hardware representation.
327 * Both use a very logical bit-wise layout, but unfortunately the order
328 * of bits is reversed.
330 static GLuint
translate_logicop(GLenum logicop
)
332 GLuint bits
= logicop
- GL_CLEAR
;
333 bits
= ((bits
& 1) << 3) | ((bits
& 2) << 1) | ((bits
& 4) >> 1) | ((bits
& 8) >> 3);
334 return bits
<< R300_RB3D_ROPCNTL_ROP_SHIFT
;
338 * Used internally to update the r300->hw hardware state to match the
339 * current OpenGL state.
341 static void r300SetLogicOpState(GLcontext
*ctx
)
343 r300ContextPtr r300
= R300_CONTEXT(ctx
);
344 R300_STATECHANGE(r300
, rop
);
345 if (RGBA_LOGICOP_ENABLED(ctx
)) {
346 r300
->hw
.rop
.cmd
[1] = R300_RB3D_ROPCNTL_ROP_ENABLE
|
347 translate_logicop(ctx
->Color
.LogicOp
);
349 r300
->hw
.rop
.cmd
[1] = 0;
354 * Called by Mesa when an application program changes the LogicOp state
357 static void r300LogicOpcode(GLcontext
*ctx
, GLenum logicop
)
359 if (RGBA_LOGICOP_ENABLED(ctx
))
360 r300SetLogicOpState(ctx
);
363 static void r300ClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
365 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
369 /* no VAP UCP on non-TCL chipsets */
370 if (!rmesa
->options
.hw_tcl_enabled
)
373 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
374 ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
376 R300_STATECHANGE( rmesa
, vpucp
[p
] );
377 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
378 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
379 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
380 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
383 static void r300SetClipPlaneState(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
385 r300ContextPtr r300
= R300_CONTEXT(ctx
);
388 /* no VAP UCP on non-TCL chipsets */
389 if (!r300
->options
.hw_tcl_enabled
)
392 p
= cap
- GL_CLIP_PLANE0
;
393 R300_STATECHANGE(r300
, vap_clip_cntl
);
395 r300
->hw
.vap_clip_cntl
.cmd
[1] |= (R300_VAP_UCP_ENABLE_0
<< p
);
396 r300ClipPlane(ctx
, cap
, NULL
);
398 r300
->hw
.vap_clip_cntl
.cmd
[1] &= ~(R300_VAP_UCP_ENABLE_0
<< p
);
403 * Update our tracked culling state based on Mesa's state.
405 static void r300UpdateCulling(GLcontext
* ctx
)
407 r300ContextPtr r300
= R300_CONTEXT(ctx
);
410 if (ctx
->Polygon
.CullFlag
) {
411 switch (ctx
->Polygon
.CullFaceMode
) {
413 val
= R300_CULL_FRONT
;
416 val
= R300_CULL_BACK
;
418 case GL_FRONT_AND_BACK
:
419 val
= R300_CULL_FRONT
| R300_CULL_BACK
;
426 switch (ctx
->Polygon
.FrontFace
) {
428 val
|= R300_FRONT_FACE_CW
;
431 val
|= R300_FRONT_FACE_CCW
;
437 /* Winding is inverted when rendering to FBO */
438 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->Name
)
439 val
^= R300_FRONT_FACE_CW
;
441 R300_STATECHANGE(r300
, cul
);
442 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
445 static void r300SetPolygonOffsetState(GLcontext
* ctx
, GLboolean state
)
447 r300ContextPtr r300
= R300_CONTEXT(ctx
);
449 R300_STATECHANGE(r300
, occlusion_cntl
);
451 r300
->hw
.occlusion_cntl
.cmd
[1] |= (3 << 0);
453 r300
->hw
.occlusion_cntl
.cmd
[1] &= ~(3 << 0);
457 static GLboolean
current_fragment_program_writes_depth(GLcontext
* ctx
)
459 r300ContextPtr r300
= R300_CONTEXT(ctx
);
461 return ctx
->FragmentProgram
._Current
&& r300
->selected_fp
->writes_depth
;
464 static void r300SetEarlyZState(GLcontext
* ctx
)
466 r300ContextPtr r300
= R300_CONTEXT(ctx
);
467 GLuint topZ
= R300_ZTOP_ENABLE
;
468 GLuint w_fmt
, fgdepthsrc
;
470 if (ctx
->Color
.AlphaEnabled
&& ctx
->Color
.AlphaFunc
!= GL_ALWAYS
)
471 topZ
= R300_ZTOP_DISABLE
;
472 else if (current_fragment_program_writes_depth(ctx
))
473 topZ
= R300_ZTOP_DISABLE
;
474 else if (ctx
->FragmentProgram
._Current
&& ctx
->FragmentProgram
._Current
->UsesKill
)
475 topZ
= R300_ZTOP_DISABLE
;
477 if (topZ
!= r300
->hw
.zstencil_format
.cmd
[2]) {
478 /* Note: This completely reemits the stencil format.
479 * I have not tested whether this is strictly necessary,
480 * or if emitting a write to ZB_ZTOP is enough.
482 R300_STATECHANGE(r300
, zstencil_format
);
483 r300
->hw
.zstencil_format
.cmd
[2] = topZ
;
486 /* w_fmt value is set to get best performance
487 * see p.130 R5xx 3D acceleration guide v1.3 */
488 if (current_fragment_program_writes_depth(ctx
)) {
489 fgdepthsrc
= R300_FG_DEPTH_SRC_SHADER
;
490 w_fmt
= R300_W_FMT_W24
| R300_W_SRC_US
;
492 fgdepthsrc
= R300_FG_DEPTH_SRC_SCAN
;
493 w_fmt
= R300_W_FMT_W0
| R300_W_SRC_US
;
496 if (w_fmt
!= r300
->hw
.us_out_fmt
.cmd
[5]) {
497 R300_STATECHANGE(r300
, us_out_fmt
);
498 r300
->hw
.us_out_fmt
.cmd
[5] = w_fmt
;
501 if (fgdepthsrc
!= r300
->hw
.fg_depth_src
.cmd
[1]) {
502 R300_STATECHANGE(r300
, fg_depth_src
);
503 r300
->hw
.fg_depth_src
.cmd
[1] = fgdepthsrc
;
507 static void r300SetAlphaState(GLcontext
* ctx
)
509 r300ContextPtr r300
= R300_CONTEXT(ctx
);
511 uint32_t pp_misc
= 0x0;
512 GLboolean really_enabled
= ctx
->Color
.AlphaEnabled
;
514 CLAMPED_FLOAT_TO_UBYTE(refByte
, ctx
->Color
.AlphaRef
);
516 switch (ctx
->Color
.AlphaFunc
) {
518 pp_misc
|= R300_FG_ALPHA_FUNC_NEVER
;
521 pp_misc
|= R300_FG_ALPHA_FUNC_LESS
;
524 pp_misc
|= R300_FG_ALPHA_FUNC_EQUAL
;
527 pp_misc
|= R300_FG_ALPHA_FUNC_LE
;
530 pp_misc
|= R300_FG_ALPHA_FUNC_GREATER
;
533 pp_misc
|= R300_FG_ALPHA_FUNC_NOTEQUAL
;
536 pp_misc
|= R300_FG_ALPHA_FUNC_GE
;
539 /*pp_misc |= FG_ALPHA_FUNC_ALWAYS; */
540 really_enabled
= GL_FALSE
;
544 if (really_enabled
) {
545 pp_misc
|= R300_FG_ALPHA_FUNC_ENABLE
;
546 pp_misc
|= R500_FG_ALPHA_FUNC_8BIT
;
547 pp_misc
|= (refByte
& R300_FG_ALPHA_FUNC_VAL_MASK
);
552 R300_STATECHANGE(r300
, at
);
553 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
554 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
557 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
561 r300SetAlphaState(ctx
);
564 static int translate_func(int func
)
568 return R300_ZS_NEVER
;
572 return R300_ZS_EQUAL
;
574 return R300_ZS_LEQUAL
;
576 return R300_ZS_GREATER
;
578 return R300_ZS_NOTEQUAL
;
580 return R300_ZS_GEQUAL
;
582 return R300_ZS_ALWAYS
;
587 static void r300SetDepthState(GLcontext
* ctx
)
589 r300ContextPtr r300
= R300_CONTEXT(ctx
);
591 R300_STATECHANGE(r300
, zs
);
592 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &= R300_STENCIL_ENABLE
|R300_STENCIL_FRONT_BACK
;
593 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(R300_ZS_MASK
<< R300_Z_FUNC_SHIFT
);
595 if (ctx
->Depth
.Test
) {
596 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_Z_ENABLE
;
598 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_Z_WRITE_ENABLE
;
599 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
600 translate_func(ctx
->Depth
.Func
) << R300_Z_FUNC_SHIFT
;
604 static void r300CatchStencilFallback(GLcontext
*ctx
)
606 const unsigned back
= ctx
->Stencil
._BackFace
;
608 if (ctx
->Stencil
._Enabled
&& (ctx
->Stencil
.Ref
[0] != ctx
->Stencil
.Ref
[back
]
609 || ctx
->Stencil
.ValueMask
[0] != ctx
->Stencil
.ValueMask
[back
]
610 || ctx
->Stencil
.WriteMask
[0] != ctx
->Stencil
.WriteMask
[back
])) {
611 r300SwitchFallback(ctx
, R300_FALLBACK_STENCIL_TWOSIDE
, GL_TRUE
);
613 r300SwitchFallback(ctx
, R300_FALLBACK_STENCIL_TWOSIDE
, GL_FALSE
);
617 static void r300SetStencilState(GLcontext
* ctx
, GLboolean state
)
619 r300ContextPtr r300
= R300_CONTEXT(ctx
);
620 GLboolean hw_stencil
= GL_FALSE
;
622 r300CatchStencilFallback(ctx
);
624 if (ctx
->DrawBuffer
) {
625 struct radeon_renderbuffer
*rrbStencil
626 = radeon_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_STENCIL
);
627 hw_stencil
= (rrbStencil
&& rrbStencil
->bo
);
631 R300_STATECHANGE(r300
, zs
);
633 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
636 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
637 ~R300_STENCIL_ENABLE
;
642 static void r300UpdatePolygonMode(GLcontext
* ctx
)
644 r300ContextPtr r300
= R300_CONTEXT(ctx
);
645 uint32_t hw_mode
= R300_GA_POLY_MODE_DISABLE
;
647 /* Only do something if a polygon mode is wanted, default is GL_FILL */
648 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
649 ctx
->Polygon
.BackMode
!= GL_FILL
) {
652 /* Handle GL_CW (clock wise and GL_CCW (counter clock wise)
653 * correctly by selecting the correct front and back face
655 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
656 f
= ctx
->Polygon
.FrontMode
;
657 b
= ctx
->Polygon
.BackMode
;
659 f
= ctx
->Polygon
.BackMode
;
660 b
= ctx
->Polygon
.FrontMode
;
663 /* Enable polygon mode */
664 hw_mode
|= R300_GA_POLY_MODE_DUAL
;
668 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_LINE
;
671 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_POINT
;
674 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_TRI
;
680 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_LINE
;
683 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_POINT
;
686 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_TRI
;
691 if (r300
->hw
.polygon_mode
.cmd
[1] != hw_mode
) {
692 R300_STATECHANGE(r300
, polygon_mode
);
693 r300
->hw
.polygon_mode
.cmd
[1] = hw_mode
;
696 r300
->hw
.polygon_mode
.cmd
[2] = 0x00000001;
697 r300
->hw
.polygon_mode
.cmd
[3] = 0x00000000;
701 * Change the culling mode.
703 * \note Mesa already filters redundant calls to this function.
705 static void r300CullFace(GLcontext
* ctx
, GLenum mode
)
709 r300UpdateCulling(ctx
);
713 * Change the polygon orientation.
715 * \note Mesa already filters redundant calls to this function.
717 static void r300FrontFace(GLcontext
* ctx
, GLenum mode
)
721 r300UpdateCulling(ctx
);
722 r300UpdatePolygonMode(ctx
);
726 * Change the depth testing function.
728 * \note Mesa already filters redundant calls to this function.
730 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
733 r300SetDepthState(ctx
);
737 * Enable/Disable depth writing.
739 * \note Mesa already filters redundant calls to this function.
741 static void r300DepthMask(GLcontext
* ctx
, GLboolean mask
)
744 r300SetDepthState(ctx
);
748 * Handle glColorMask()
750 static void r300ColorMask(GLcontext
* ctx
,
751 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
753 r300ContextPtr r300
= R300_CONTEXT(ctx
);
754 int mask
= (r
? RB3D_COLOR_CHANNEL_MASK_RED_MASK0
: 0) |
755 (g
? RB3D_COLOR_CHANNEL_MASK_GREEN_MASK0
: 0) |
756 (b
? RB3D_COLOR_CHANNEL_MASK_BLUE_MASK0
: 0) |
757 (a
? RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK0
: 0);
759 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
760 R300_STATECHANGE(r300
, cmk
);
761 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
765 /* =============================================================
768 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
770 r300ContextPtr r300
= R300_CONTEXT(ctx
);
772 /* We need to clamp to user defined range here, because
773 * the HW clamping happens only for per vertex point size. */
774 size
= CLAMP(size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
776 /* same size limits for AA, non-AA points */
777 size
= CLAMP(size
, ctx
->Const
.MinPointSize
, ctx
->Const
.MaxPointSize
);
779 R300_STATECHANGE(r300
, ps
);
780 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
781 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
782 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
785 static void r300PointParameter(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
)
787 r300ContextPtr r300
= R300_CONTEXT(ctx
);
790 case GL_POINT_SIZE_MIN
:
791 R300_STATECHANGE(r300
, ga_point_minmax
);
792 r300
->hw
.ga_point_minmax
.cmd
[1] &= ~R300_GA_POINT_MINMAX_MIN_MASK
;
793 r300
->hw
.ga_point_minmax
.cmd
[1] |= (GLuint
)(ctx
->Point
.MinSize
* 6.0);
795 case GL_POINT_SIZE_MAX
:
796 R300_STATECHANGE(r300
, ga_point_minmax
);
797 r300
->hw
.ga_point_minmax
.cmd
[1] &= ~R300_GA_POINT_MINMAX_MAX_MASK
;
798 r300
->hw
.ga_point_minmax
.cmd
[1] |= (GLuint
)(ctx
->Point
.MaxSize
* 6.0)
799 << R300_GA_POINT_MINMAX_MAX_SHIFT
;
801 case GL_POINT_DISTANCE_ATTENUATION
:
803 case GL_POINT_FADE_THRESHOLD_SIZE
:
810 /* =============================================================
813 static void r300LineWidth(GLcontext
* ctx
, GLfloat widthf
)
815 r300ContextPtr r300
= R300_CONTEXT(ctx
);
817 widthf
= CLAMP(widthf
,
818 ctx
->Const
.MinPointSize
,
819 ctx
->Const
.MaxPointSize
);
820 R300_STATECHANGE(r300
, lcntl
);
821 r300
->hw
.lcntl
.cmd
[1] =
822 R300_LINE_CNT_HO
| R300_LINE_CNT_VE
| (int)(widthf
* 6.0);
825 static void r300PolygonMode(GLcontext
* ctx
, GLenum face
, GLenum mode
)
830 r300UpdatePolygonMode(ctx
);
833 /* =============================================================
837 static int translate_stencil_op(int op
)
845 return R300_ZS_REPLACE
;
850 case GL_INCR_WRAP_EXT
:
851 return R300_ZS_INCR_WRAP
;
852 case GL_DECR_WRAP_EXT
:
853 return R300_ZS_DECR_WRAP
;
855 return R300_ZS_INVERT
;
857 WARN_ONCE("Do not know how to translate stencil op");
863 static void r300ShadeModel(GLcontext
* ctx
, GLenum mode
)
865 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
867 R300_STATECHANGE(rmesa
, shade
);
868 rmesa
->hw
.shade
.cmd
[1] = 0x00000002;
869 R300_STATECHANGE(rmesa
, shade2
);
872 rmesa
->hw
.shade2
.cmd
[1] = R300_RE_SHADE_MODEL_FLAT
;
875 rmesa
->hw
.shade2
.cmd
[1] = R300_RE_SHADE_MODEL_SMOOTH
;
880 rmesa
->hw
.shade2
.cmd
[2] = 0x00000000;
881 rmesa
->hw
.shade2
.cmd
[3] = 0x00000000;
884 static void r300StencilFuncSeparate(GLcontext
* ctx
, GLenum face
,
885 GLenum func
, GLint ref
, GLuint mask
)
887 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
890 const unsigned back
= ctx
->Stencil
._BackFace
;
892 r300CatchStencilFallback(ctx
);
894 refmask
= ((ctx
->Stencil
.Ref
[0] & 0xff) << R300_STENCILREF_SHIFT
)
895 | ((ctx
->Stencil
.ValueMask
[0] & 0xff) << R300_STENCILMASK_SHIFT
);
897 R300_STATECHANGE(rmesa
, zs
);
898 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_STENCIL_FRONT_BACK
;
899 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~((R300_ZS_MASK
<<
900 R300_S_FRONT_FUNC_SHIFT
)
902 R300_S_BACK_FUNC_SHIFT
));
904 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
905 ~((R300_STENCILREF_MASK
<< R300_STENCILREF_SHIFT
) |
906 (R300_STENCILREF_MASK
<< R300_STENCILMASK_SHIFT
));
908 flag
= translate_func(ctx
->Stencil
.Function
[0]);
909 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
910 (flag
<< R300_S_FRONT_FUNC_SHIFT
);
912 flag
= translate_func(ctx
->Stencil
.Function
[back
]);
914 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
915 (flag
<< R300_S_BACK_FUNC_SHIFT
);
916 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
919 static void r300StencilMaskSeparate(GLcontext
* ctx
, GLenum face
, GLuint mask
)
921 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
923 r300CatchStencilFallback(ctx
);
925 R300_STATECHANGE(rmesa
, zs
);
926 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
927 ~(R300_STENCILREF_MASK
<<
928 R300_STENCILWRITEMASK_SHIFT
);
929 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |=
931 WriteMask
[0] & R300_STENCILREF_MASK
) <<
932 R300_STENCILWRITEMASK_SHIFT
;
935 static void r300StencilOpSeparate(GLcontext
* ctx
, GLenum face
,
936 GLenum fail
, GLenum zfail
, GLenum zpass
)
938 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
939 const unsigned back
= ctx
->Stencil
._BackFace
;
941 r300CatchStencilFallback(ctx
);
943 R300_STATECHANGE(rmesa
, zs
);
944 /* It is easier to mask what's left.. */
945 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
946 (R300_ZS_MASK
<< R300_Z_FUNC_SHIFT
) |
947 (R300_ZS_MASK
<< R300_S_FRONT_FUNC_SHIFT
) |
948 (R300_ZS_MASK
<< R300_S_BACK_FUNC_SHIFT
);
950 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
951 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
952 R300_S_FRONT_SFAIL_OP_SHIFT
)
953 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
954 R300_S_FRONT_ZFAIL_OP_SHIFT
)
955 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
956 R300_S_FRONT_ZPASS_OP_SHIFT
);
958 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
959 (translate_stencil_op(ctx
->Stencil
.FailFunc
[back
]) <<
960 R300_S_BACK_SFAIL_OP_SHIFT
)
961 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[back
]) <<
962 R300_S_BACK_ZFAIL_OP_SHIFT
)
963 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[back
]) <<
964 R300_S_BACK_ZPASS_OP_SHIFT
);
967 /* =============================================================
968 * Window position and viewport transformation
971 static void r300UpdateWindow(GLcontext
* ctx
)
973 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
974 __DRIdrawablePrivate
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
975 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
976 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
977 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
978 const GLfloat depthScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
979 const GLboolean render_to_fbo
= (ctx
->DrawBuffer
->Name
!= 0);
980 GLfloat y_scale
, y_bias
;
990 GLfloat sx
= v
[MAT_SX
];
991 GLfloat tx
= v
[MAT_TX
] + xoffset
;
992 GLfloat sy
= v
[MAT_SY
] * y_scale
;
993 GLfloat ty
= (v
[MAT_TY
] * y_scale
) + y_bias
;
994 GLfloat sz
= v
[MAT_SZ
] * depthScale
;
995 GLfloat tz
= v
[MAT_TZ
] * depthScale
;
997 R300_STATECHANGE(rmesa
, vpt
);
999 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
1000 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
1001 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
1002 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1003 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
1004 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
1007 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
1008 GLsizei width
, GLsizei height
)
1010 /* Don't pipeline viewport changes, conflict with window offset
1011 * setting below. Could apply deltas to rescue pipelined viewport
1012 * values, or keep the originals hanging around.
1014 r300UpdateWindow(ctx
);
1016 radeon_viewport(ctx
, x
, y
, width
, height
);
1019 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
1021 r300UpdateWindow(ctx
);
1024 void r300UpdateViewportOffset(GLcontext
* ctx
)
1026 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1027 __DRIdrawablePrivate
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
1028 GLfloat xoffset
= (GLfloat
) dPriv
->x
;
1029 GLfloat yoffset
= (GLfloat
) dPriv
->y
+ dPriv
->h
;
1030 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1032 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1033 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
;
1035 if (rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] != r300PackFloat32(tx
) ||
1036 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] != r300PackFloat32(ty
)) {
1037 /* Note: this should also modify whatever data the context reset
1040 R300_STATECHANGE(rmesa
, vpt
);
1041 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
1042 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1046 radeonUpdateScissor(ctx
);
1050 r300FetchStateParameter(GLcontext
* ctx
,
1051 const gl_state_index state
[STATE_LENGTH
],
1054 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1057 case STATE_INTERNAL
:
1059 case STATE_R300_WINDOW_DIMENSION
: {
1060 __DRIdrawablePrivate
* drawable
= radeon_get_drawable(&r300
->radeon
);
1061 value
[0] = drawable
->w
* 0.5f
; /* width*0.5 */
1062 value
[1] = drawable
->h
* 0.5f
; /* height*0.5 */
1063 value
[2] = 0.5F
; /* for moving range [-1 1] -> [0 1] */
1064 value
[3] = 1.0F
; /* not used */
1068 case STATE_R300_TEXRECT_FACTOR
:{
1069 struct gl_texture_object
*t
=
1070 ctx
->Texture
.Unit
[state
[2]].CurrentTex
[TEXTURE_RECT_INDEX
];
1072 if (t
&& t
->Image
[0][t
->BaseLevel
]) {
1073 struct gl_texture_image
*image
=
1074 t
->Image
[0][t
->BaseLevel
];
1075 value
[0] = 1.0 / image
->Width2
;
1076 value
[1] = 1.0 / image
->Height2
;
1097 * Update R300's own internal state parameters.
1098 * For now just STATE_R300_WINDOW_DIMENSION
1100 static void r300UpdateStateParameters(GLcontext
* ctx
, GLuint new_state
)
1102 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1103 struct gl_program_parameter_list
*paramList
;
1106 if (!(new_state
& (_NEW_BUFFERS
| _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
)))
1109 if (!ctx
->FragmentProgram
._Current
|| !rmesa
->selected_fp
)
1112 paramList
= rmesa
->selected_fp
->Base
->Parameters
;
1117 _mesa_load_state_parameters(ctx
, paramList
);
1119 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1120 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1121 r300FetchStateParameter(ctx
,
1122 paramList
->Parameters
[i
].
1124 paramList
->ParameterValues
[i
]);
1129 /* =============================================================
1132 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
1134 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1135 GLfloat constant
= units
;
1137 switch (ctx
->Visual
.depthBits
) {
1148 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
1150 R300_STATECHANGE(rmesa
, zbs
);
1151 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
1152 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
1153 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
1154 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
1157 /* Routing and texture-related */
1159 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
1160 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
1161 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
1162 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1163 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1164 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1165 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
1166 * combinations where only one of them is nearest.
1168 static unsigned long gen_fixed_filter(unsigned long f
)
1170 unsigned long mag
, min
, needs_fixing
= 0;
1173 /* We ignore MIRROR bit so we dont have to do everything twice */
1174 if ((f
& ((7 - 1) << R300_TX_WRAP_S_SHIFT
)) ==
1175 (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)) {
1178 if ((f
& ((7 - 1) << R300_TX_WRAP_T_SHIFT
)) ==
1179 (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)) {
1182 if ((f
& ((7 - 1) << R300_TX_WRAP_R_SHIFT
)) ==
1183 (R300_TX_CLAMP
<< R300_TX_WRAP_R_SHIFT
)) {
1190 mag
= f
& R300_TX_MAG_FILTER_MASK
;
1191 min
= f
& (R300_TX_MIN_FILTER_MASK
|R300_TX_MIN_FILTER_MIP_MASK
);
1193 /* TODO: Check for anisto filters too */
1194 if ((mag
!= R300_TX_MAG_FILTER_NEAREST
)
1195 && (min
!= R300_TX_MIN_FILTER_NEAREST
))
1198 /* r300 cant handle these modes hence we force nearest to linear */
1199 if ((mag
== R300_TX_MAG_FILTER_NEAREST
)
1200 && (min
!= R300_TX_MIN_FILTER_NEAREST
)) {
1201 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
1202 f
|= R300_TX_MAG_FILTER_LINEAR
;
1206 if ((min
== R300_TX_MIN_FILTER_NEAREST
)
1207 && (mag
!= R300_TX_MAG_FILTER_NEAREST
)) {
1208 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
1209 f
|= R300_TX_MIN_FILTER_LINEAR
;
1213 /* Both are nearest */
1214 if (needs_fixing
& 1) {
1215 f
&= ~((7 - 1) << R300_TX_WRAP_S_SHIFT
);
1216 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1218 if (needs_fixing
& 2) {
1219 f
&= ~((7 - 1) << R300_TX_WRAP_T_SHIFT
);
1220 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1222 if (needs_fixing
& 4) {
1223 f
&= ~((7 - 1) << R300_TX_WRAP_R_SHIFT
);
1224 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_R_SHIFT
;
1229 static void r300SetupFragmentShaderTextures(GLcontext
*ctx
, int *tmu_mappings
)
1231 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1233 struct r300_fragment_program_code
*code
= &r300
->selected_fp
->code
.r300
;
1235 R300_STATECHANGE(r300
, fpt
);
1237 for (i
= 0; i
< code
->tex
.length
; i
++) {
1242 unit
= code
->tex
.inst
[i
] >> R300_TEX_ID_SHIFT
;
1245 val
= code
->tex
.inst
[i
];
1246 val
&= ~R300_TEX_ID_MASK
;
1249 (val
& R300_TEX_INST_MASK
) >> R300_TEX_INST_SHIFT
;
1250 if (opcode
== R300_TEX_OP_KIL
) {
1251 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1253 if (tmu_mappings
[unit
] >= 0) {
1255 tmu_mappings
[unit
] <<
1257 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1259 // We get here when the corresponding texture image is incomplete
1260 // (e.g. incomplete mipmaps etc.)
1261 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1266 r300
->hw
.fpt
.cmd
[R300_FPT_CMD_0
] =
1267 cmdpacket0(r300
->radeon
.radeonScreen
,
1268 R300_US_TEX_INST_0
, code
->tex
.length
);
1271 static void r500SetupFragmentShaderTextures(GLcontext
*ctx
, int *tmu_mappings
)
1273 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1275 struct r500_fragment_program_code
*code
= &r300
->selected_fp
->code
.r500
;
1277 /* find all the texture instructions and relocate the texture units */
1278 for (i
= 0; i
< code
->inst_end
+ 1; i
++) {
1279 if ((code
->inst
[i
].inst0
& 0x3) == R500_INST_TYPE_TEX
) {
1281 int unit
, opcode
, new_unit
;
1283 val
= code
->inst
[i
].inst1
;
1285 unit
= (val
>> 16) & 0xf;
1287 val
&= ~(0xf << 16);
1289 opcode
= val
& (0x7 << 22);
1290 if (opcode
== R500_TEX_INST_TEXKILL
) {
1293 if (tmu_mappings
[unit
] >= 0) {
1294 new_unit
= tmu_mappings
[unit
];
1299 val
|= R500_TEX_ID(new_unit
);
1300 code
->inst
[i
].inst1
= val
;
1305 static GLuint
translate_lod_bias(GLfloat bias
)
1307 GLint b
= (int)(bias
*32);
1310 else if (b
< -(1 << 9))
1312 return (((GLuint
)b
) << R300_LOD_BIAS_SHIFT
) & R300_LOD_BIAS_MASK
;
1315 static void r300SetupTextures(GLcontext
* ctx
)
1318 struct radeon_tex_obj
*t
;
1319 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1321 int last_hw_tmu
= -1; /* -1 translates into no setup costs for fields */
1322 int tmu_mappings
[R300_MAX_TEXTURE_UNITS
] = { -1, };
1324 R300_STATECHANGE(r300
, txe
);
1325 R300_STATECHANGE(r300
, tex
.filter
);
1326 R300_STATECHANGE(r300
, tex
.filter_1
);
1327 R300_STATECHANGE(r300
, tex
.size
);
1328 R300_STATECHANGE(r300
, tex
.format
);
1329 R300_STATECHANGE(r300
, tex
.pitch
);
1330 R300_STATECHANGE(r300
, tex
.offset
);
1331 R300_STATECHANGE(r300
, tex
.chroma_key
);
1332 R300_STATECHANGE(r300
, tex
.border_color
);
1334 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] = 0x0;
1336 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1337 if (RADEON_DEBUG
& DEBUG_STATE
)
1338 fprintf(stderr
, "mtu=%d\n", mtu
);
1340 if (mtu
> R300_MAX_TEXTURE_UNITS
) {
1342 "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1343 mtu
, R300_MAX_TEXTURE_UNITS
);
1347 /* We cannot let disabled tmu offsets pass DRM */
1348 for (i
= 0; i
< mtu
; i
++) {
1349 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
1350 tmu_mappings
[i
] = hw_tmu
;
1352 t
= radeon_tex_obj(ctx
->Texture
.Unit
[i
]._Current
);
1356 if ((t
->pp_txformat
& 0xffffff00) == 0xffffff00) {
1358 ("unknown texture format (entry %x) encountered. Help me !\n",
1359 t
->pp_txformat
& 0xff);
1362 if (RADEON_DEBUG
& DEBUG_STATE
)
1364 "Activating texture unit %d\n", i
);
1366 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= (1 << hw_tmu
);
1368 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+
1370 gen_fixed_filter(t
->pp_txfilter
) | (hw_tmu
<< 28);
1371 /* Note: There is a LOD bias per texture unit and a LOD bias
1372 * per texture object. We add them here to get the correct behaviour.
1373 * (The per-texture object LOD bias was introduced in OpenGL 1.4
1374 * and is not present in the EXT_texture_object extension).
1376 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1378 translate_lod_bias(ctx
->Texture
.Unit
[i
].LodBias
+ t
->base
.LodBias
);
1379 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1381 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+
1382 hw_tmu
] = t
->pp_txformat
;
1383 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1385 r300
->hw
.textures
[hw_tmu
] = t
;
1387 if (t
->tile_bits
& R300_TXO_MACRO_TILE
) {
1388 WARN_ONCE("macro tiling enabled!\n");
1391 if (t
->tile_bits
& R300_TXO_MICRO_TILE
) {
1392 WARN_ONCE("micro tiling enabled!\n");
1395 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_VALUE_0
+
1397 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+
1401 last_hw_tmu
= hw_tmu
;
1407 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1408 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER0_0
, last_hw_tmu
+ 1);
1409 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_CMD_0
] =
1410 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER1_0
, last_hw_tmu
+ 1);
1411 r300
->hw
.tex
.size
.cmd
[R300_TEX_CMD_0
] =
1412 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_SIZE_0
, last_hw_tmu
+ 1);
1413 r300
->hw
.tex
.format
.cmd
[R300_TEX_CMD_0
] =
1414 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FORMAT_0
, last_hw_tmu
+ 1);
1415 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_CMD_0
] =
1416 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FORMAT2_0
, last_hw_tmu
+ 1);
1417 r300
->hw
.tex
.offset
.cmd
[R300_TEX_CMD_0
] =
1418 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_OFFSET_0
, last_hw_tmu
+ 1);
1419 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_CMD_0
] =
1420 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_CHROMA_KEY_0
, last_hw_tmu
+ 1);
1421 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_CMD_0
] =
1422 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_BORDER_COLOR_0
, last_hw_tmu
+ 1);
1424 if (r300
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV515
) {
1425 if (ctx
->FragmentProgram
._Current
->UsesKill
&& last_hw_tmu
< 0) {
1426 // The KILL operation requires the first texture unit
1428 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= 1;
1429 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
] = 0;
1430 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1431 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER0_0
, 1);
1434 r300
->vtbl
.SetupFragmentShaderTextures(ctx
, tmu_mappings
);
1436 if (RADEON_DEBUG
& DEBUG_STATE
)
1437 fprintf(stderr
, "TX_ENABLE: %08x last_hw_tmu=%d\n",
1438 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], last_hw_tmu
);
1441 union r300_outputs_written
{
1442 GLuint vp_outputs
; /* hw_tcl_on */
1443 DECLARE_RENDERINPUTS(index_bitset
); /* !hw_tcl_on */
1446 #define R300_OUTPUTS_WRITTEN_TEST(ow, vp_result, tnl_attrib) \
1447 ((hw_tcl_on) ? (ow).vp_outputs & (1 << (vp_result)) : \
1448 RENDERINPUTS_TEST( (ow.index_bitset), (tnl_attrib) ))
1450 static void r300SetupRSUnit(GLcontext
* ctx
)
1452 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1453 union r300_outputs_written OutputsWritten
;
1455 int fp_reg
, high_rr
;
1457 int rs_tex_count
= 0;
1458 int i
, col_fmt
, hw_tcl_on
;
1460 hw_tcl_on
= r300
->options
.hw_tcl_enabled
;
1463 OutputsWritten
.vp_outputs
= r300
->selected_vp
->Base
->Base
.OutputsWritten
;
1465 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->render_inputs_bitset
);
1467 InputsRead
= r300
->selected_fp
->Base
->InputsRead
;
1469 R300_STATECHANGE(r300
, ri
);
1470 R300_STATECHANGE(r300
, rc
);
1471 R300_STATECHANGE(r300
, rr
);
1473 fp_reg
= col_ip
= tex_ip
= col_fmt
= 0;
1475 r300
->hw
.rc
.cmd
[1] = 0;
1476 r300
->hw
.rc
.cmd
[2] = 0;
1477 for (i
=0; i
<R300_RR_CMDSIZE
-1; ++i
)
1478 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ i
] = 0;
1480 for (i
=0; i
<R300_RI_CMDSIZE
-1; ++i
)
1481 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0;
1484 if (InputsRead
& FRAG_BIT_COL0
) {
1485 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1486 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ col_ip
] = R300_RS_COL_PTR(col_ip
) | R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA
);
1487 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ col_ip
] = R300_RS_INST_COL_ID(col_ip
) | R300_RS_INST_COL_CN_WRITE
| R300_RS_INST_COL_ADDR(fp_reg
);
1488 InputsRead
&= ~FRAG_BIT_COL0
;
1492 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1496 if (InputsRead
& FRAG_BIT_COL1
) {
1497 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1498 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ col_ip
] = R300_RS_COL_PTR(col_ip
) | R300_RS_COL_FMT(R300_RS_COL_FMT_RGBA
);
1499 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ col_ip
] = R300_RS_INST_COL_ID(col_ip
) | R300_RS_INST_COL_CN_WRITE
| R300_RS_INST_COL_ADDR(fp_reg
);
1500 InputsRead
&= ~FRAG_BIT_COL1
;
1504 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1508 /* We always route 4 texcoord components */
1509 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1510 if (! ( InputsRead
& FRAG_BIT_TEX(i
) ) )
1513 if (!R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1514 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1518 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ tex_ip
] |= R300_RS_SEL_S(0) | R300_RS_SEL_T(1) | R300_RS_SEL_R(2) | R300_RS_SEL_Q(3) | R300_RS_TEX_PTR(rs_tex_count
);
1519 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ tex_ip
] |= R300_RS_INST_TEX_ID(tex_ip
) | R300_RS_INST_TEX_CN_WRITE
| R300_RS_INST_TEX_ADDR(fp_reg
);
1520 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1526 /* Setup default color if no color or tex was set */
1527 if (rs_tex_count
== 0 && col_ip
== 0) {
1528 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] = R300_RS_INST_COL_ID(0) | R300_RS_INST_COL_ADDR(0);
1529 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
] = R300_RS_COL_PTR(0) | R300_RS_COL_FMT(R300_RS_COL_FMT_0001
);
1533 high_rr
= (col_ip
> tex_ip
) ? col_ip
: tex_ip
;
1534 r300
->hw
.rc
.cmd
[1] |= (rs_tex_count
<< R300_IT_COUNT_SHIFT
) | (col_ip
<< R300_IC_COUNT_SHIFT
) | R300_HIRES_EN
;
1535 r300
->hw
.rc
.cmd
[2] |= high_rr
- 1;
1537 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R300_RS_INST_0
, high_rr
);
1538 r300
->hw
.ri
.cmd
[R300_RI_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R300_RS_IP_0
, high_rr
);
1541 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1544 static void r500SetupRSUnit(GLcontext
* ctx
)
1546 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1547 union r300_outputs_written OutputsWritten
;
1549 int fp_reg
, high_rr
;
1551 int rs_tex_count
= 0;
1552 int i
, col_fmt
, hw_tcl_on
;
1554 hw_tcl_on
= r300
->options
.hw_tcl_enabled
;
1557 OutputsWritten
.vp_outputs
= r300
->selected_vp
->Base
->Base
.OutputsWritten
;
1559 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->render_inputs_bitset
);
1561 InputsRead
= r300
->selected_fp
->Base
->InputsRead
;
1563 R300_STATECHANGE(r300
, ri
);
1564 R300_STATECHANGE(r300
, rc
);
1565 R300_STATECHANGE(r300
, rr
);
1567 fp_reg
= col_ip
= tex_ip
= col_fmt
= 0;
1569 r300
->hw
.rc
.cmd
[1] = 0;
1570 r300
->hw
.rc
.cmd
[2] = 0;
1571 for (i
=0; i
<R300_RR_CMDSIZE
-1; ++i
)
1572 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ i
] = 0;
1574 for (i
=0; i
<R500_RI_CMDSIZE
-1; ++i
)
1575 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0;
1578 if (InputsRead
& FRAG_BIT_COL0
) {
1579 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1580 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ col_ip
] = R500_RS_COL_PTR(col_ip
) | R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA
);
1581 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ col_ip
] = R500_RS_INST_COL_ID(col_ip
) | R500_RS_INST_COL_CN_WRITE
| R500_RS_INST_COL_ADDR(fp_reg
);
1582 InputsRead
&= ~FRAG_BIT_COL0
;
1586 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1590 if (InputsRead
& FRAG_BIT_COL1
) {
1591 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1592 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ col_ip
] = R500_RS_COL_PTR(col_ip
) | R500_RS_COL_FMT(R300_RS_COL_FMT_RGBA
);
1593 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ col_ip
] = R500_RS_INST_COL_ID(col_ip
) | R500_RS_INST_COL_CN_WRITE
| R500_RS_INST_COL_ADDR(fp_reg
);
1594 InputsRead
&= ~FRAG_BIT_COL1
;
1598 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1602 /* We always route 4 texcoord components */
1603 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1604 if (! ( InputsRead
& FRAG_BIT_TEX(i
) ) )
1607 if (!R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1608 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1612 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ tex_ip
] |= ((rs_tex_count
+ 0) << R500_RS_IP_TEX_PTR_S_SHIFT
) |
1613 ((rs_tex_count
+ 1) << R500_RS_IP_TEX_PTR_T_SHIFT
) |
1614 ((rs_tex_count
+ 2) << R500_RS_IP_TEX_PTR_R_SHIFT
) |
1615 ((rs_tex_count
+ 3) << R500_RS_IP_TEX_PTR_Q_SHIFT
);
1617 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ tex_ip
] |= R500_RS_INST_TEX_ID(tex_ip
) | R500_RS_INST_TEX_CN_WRITE
| R500_RS_INST_TEX_ADDR(fp_reg
);
1618 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1624 /* Setup default color if no color or tex was set */
1625 if (rs_tex_count
== 0 && col_ip
== 0) {
1626 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] = R500_RS_INST_COL_ID(0) | R500_RS_INST_COL_ADDR(0);
1627 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
] = R500_RS_COL_PTR(0) | R500_RS_COL_FMT(R300_RS_COL_FMT_0001
);
1631 high_rr
= (col_ip
> tex_ip
) ? col_ip
: tex_ip
;
1632 r300
->hw
.rc
.cmd
[1] = (rs_tex_count
<< R300_IT_COUNT_SHIFT
) | (col_ip
<< R300_IC_COUNT_SHIFT
) | R300_HIRES_EN
;
1633 r300
->hw
.rc
.cmd
[2] = 0xC0 | (high_rr
- 1);
1635 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R500_RS_INST_0
, high_rr
);
1636 r300
->hw
.ri
.cmd
[R300_RI_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R500_RS_IP_0
, high_rr
);
1639 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1642 #define MIN3(a, b, c) ((a) < (b) ? MIN2(a, c) : MIN2(b, c))
1644 void r300VapCntl(r300ContextPtr rmesa
, GLuint input_count
,
1645 GLuint output_count
, GLuint temp_count
)
1651 /* Flush PVS engine before changing PVS_NUM_SLOTS, PVS_NUM_CNTRLS.
1652 * See r500 docs 6.5.2 - done in emit */
1654 /* avoid division by zero */
1655 if (input_count
== 0) input_count
= 1;
1656 if (output_count
== 0) output_count
= 1;
1657 if (temp_count
== 0) temp_count
= 1;
1659 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
1664 pvs_num_slots
= MIN3(10, vtx_mem_size
/input_count
, vtx_mem_size
/output_count
);
1665 pvs_num_cntrls
= MIN2(6, vtx_mem_size
/temp_count
);
1667 R300_STATECHANGE(rmesa
, vap_cntl
);
1668 if (rmesa
->options
.hw_tcl_enabled
) {
1669 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] =
1670 (pvs_num_slots
<< R300_PVS_NUM_SLOTS_SHIFT
) |
1671 (pvs_num_cntrls
<< R300_PVS_NUM_CNTLRS_SHIFT
) |
1672 (12 << R300_VF_MAX_VTX_NUM_SHIFT
);
1673 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
1674 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= R500_TCL_STATE_OPTIMIZATION
;
1676 /* not sure about non-tcl */
1677 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] = ((10 << R300_PVS_NUM_SLOTS_SHIFT
) |
1678 (5 << R300_PVS_NUM_CNTLRS_SHIFT
) |
1679 (5 << R300_VF_MAX_VTX_NUM_SHIFT
));
1681 if (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV515
)
1682 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (2 << R300_PVS_NUM_FPUS_SHIFT
);
1683 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV530
) ||
1684 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV560
) ||
1685 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV570
))
1686 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (5 << R300_PVS_NUM_FPUS_SHIFT
);
1687 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV410
) ||
1688 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R420
))
1689 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (6 << R300_PVS_NUM_FPUS_SHIFT
);
1690 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R520
) ||
1691 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R580
))
1692 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (8 << R300_PVS_NUM_FPUS_SHIFT
);
1694 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (4 << R300_PVS_NUM_FPUS_SHIFT
);
1699 * Enable/Disable states.
1701 * \note Mesa already filters redundant calls to this function.
1703 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1705 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1706 if (RADEON_DEBUG
& DEBUG_STATE
)
1707 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1708 _mesa_lookup_enum_by_nr(cap
),
1709 state
? "GL_TRUE" : "GL_FALSE");
1713 r300SetAlphaState(ctx
);
1715 case GL_COLOR_LOGIC_OP
:
1716 r300SetLogicOpState(ctx
);
1717 /* fall-through, because logic op overrides blending */
1719 r300SetBlendState(ctx
);
1721 case GL_CLIP_PLANE0
:
1722 case GL_CLIP_PLANE1
:
1723 case GL_CLIP_PLANE2
:
1724 case GL_CLIP_PLANE3
:
1725 case GL_CLIP_PLANE4
:
1726 case GL_CLIP_PLANE5
:
1727 r300SetClipPlaneState(ctx
, cap
, state
);
1730 r300UpdateCulling(ctx
);
1733 r300SetDepthState(ctx
);
1735 case GL_LINE_SMOOTH
:
1736 if (rmesa
->options
.conformance_mode
)
1737 r300SwitchFallback(ctx
, R300_FALLBACK_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
1739 case GL_LINE_STIPPLE
:
1740 if (rmesa
->options
.conformance_mode
)
1741 r300SwitchFallback(ctx
, R300_FALLBACK_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
1743 case GL_POINT_SMOOTH
:
1744 if (rmesa
->options
.conformance_mode
)
1745 r300SwitchFallback(ctx
, R300_FALLBACK_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
1747 case GL_POLYGON_SMOOTH
:
1748 if (rmesa
->options
.conformance_mode
)
1749 r300SwitchFallback(ctx
, R300_FALLBACK_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
1751 case GL_POLYGON_STIPPLE
:
1752 if (rmesa
->options
.conformance_mode
)
1753 r300SwitchFallback(ctx
, R300_FALLBACK_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
1755 case GL_POLYGON_OFFSET_POINT
:
1756 case GL_POLYGON_OFFSET_LINE
:
1757 case GL_POLYGON_OFFSET_FILL
:
1758 r300SetPolygonOffsetState(ctx
, state
);
1760 case GL_SCISSOR_TEST
:
1761 radeon_firevertices(&rmesa
->radeon
);
1762 rmesa
->radeon
.state
.scissor
.enabled
= state
;
1763 radeonUpdateScissor( ctx
);
1765 case GL_STENCIL_TEST
:
1766 r300SetStencilState(ctx
, state
);
1774 * Completely recalculates hardware state based on the Mesa state.
1776 static void r300ResetHwState(r300ContextPtr r300
)
1778 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1781 has_tcl
= r300
->options
.hw_tcl_enabled
;
1783 if (RADEON_DEBUG
& DEBUG_STATE
)
1784 fprintf(stderr
, "%s\n", __FUNCTION__
);
1786 radeon_firevertices(&r300
->radeon
);
1789 ctx
->Color
.ColorMask
[RCOMP
],
1790 ctx
->Color
.ColorMask
[GCOMP
],
1791 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1793 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1794 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1795 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1798 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
._Enabled
);
1799 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1800 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1801 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1802 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1803 ctx
->Stencil
.ZFailFunc
[0],
1804 ctx
->Stencil
.ZPassFunc
[0]);
1806 r300UpdateCulling(ctx
);
1808 r300SetBlendState(ctx
);
1809 r300SetLogicOpState(ctx
);
1811 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1812 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1814 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1815 | R300_VPORT_X_OFFSET_ENA
1816 | R300_VPORT_Y_SCALE_ENA
1817 | R300_VPORT_Y_OFFSET_ENA
1818 | R300_VPORT_Z_SCALE_ENA
1819 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
1820 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1822 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[1] = 0x00FFFFFF;
1823 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[2] = 0x00000000;
1825 #ifdef MESA_LITTLE_ENDIAN
1826 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
1828 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
1831 /* disable VAP/TCL on non-TCL capable chips */
1833 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
1835 r300
->hw
.vap_psc_sgn_norm_cntl
.cmd
[1] = 0xAAAAAAAA;
1837 /* XXX: Other families? */
1839 r300
->hw
.vap_clip_cntl
.cmd
[1] = R300_PS_UCP_MODE_DIST_COP
;
1841 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
1842 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
1843 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
1844 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
1846 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1847 case CHIP_FAMILY_R300
:
1848 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_R300
;
1851 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_RV350
;
1856 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
1857 | R300_GB_LINE_STUFF_ENABLE
1858 | R300_GB_TRIANGLE_STUFF_ENABLE
;
1860 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
1861 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
1863 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
1864 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
/*| R300_GB_SUBPIXEL_1_16*/;
1865 switch (r300
->radeon
.radeonScreen
->num_gb_pipes
) {
1868 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1869 R300_GB_TILE_PIPE_COUNT_RV300
;
1872 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1873 R300_GB_TILE_PIPE_COUNT_R300
;
1876 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1877 R300_GB_TILE_PIPE_COUNT_R420_3P
;
1880 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1881 R300_GB_TILE_PIPE_COUNT_R420
;
1885 /* XXX: Enable anti-aliasing? */
1886 r300
->hw
.gb_misc2
.cmd
[R300_GB_MISC2_AA_CONFIG
] = GB_AA_CONFIG_AA_DISABLE
;
1887 r300
->hw
.gb_misc2
.cmd
[R300_GB_MISC2_SELECT
] = 0;
1889 r300
->hw
.ga_point_s0
.cmd
[1] = r300PackFloat32(0.0);
1890 r300
->hw
.ga_point_s0
.cmd
[2] = r300PackFloat32(0.0);
1891 r300
->hw
.ga_point_s0
.cmd
[3] = r300PackFloat32(1.0);
1892 r300
->hw
.ga_point_s0
.cmd
[4] = r300PackFloat32(1.0);
1894 r300
->hw
.ga_triangle_stipple
.cmd
[1] = 0x00050005;
1896 r300PointSize(ctx
, 1.0);
1898 r300
->hw
.ga_point_minmax
.cmd
[1] = 0x18000006;
1899 r300
->hw
.ga_point_minmax
.cmd
[2] = 0x00020006;
1900 r300
->hw
.ga_point_minmax
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
1902 r300LineWidth(ctx
, 1.0);
1904 r300
->hw
.ga_line_stipple
.cmd
[1] = 0;
1905 r300
->hw
.ga_line_stipple
.cmd
[2] = r300PackFloat32(0.0);
1906 r300
->hw
.ga_line_stipple
.cmd
[3] = r300PackFloat32(1.0);
1908 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
1910 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
1911 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
1912 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
1914 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
1915 ctx
->Polygon
.OffsetUnits
);
1916 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
1917 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
1918 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
1920 r300
->hw
.su_depth_scale
.cmd
[1] = 0x4B7FFFFF;
1921 r300
->hw
.su_depth_scale
.cmd
[2] = 0x00000000;
1923 r300
->hw
.sc_hyperz
.cmd
[1] = 0x0000001C;
1924 r300
->hw
.sc_hyperz
.cmd
[2] = 0x2DA49525;
1926 r300
->hw
.sc_screendoor
.cmd
[1] = 0x00FFFFFF;
1928 r300
->hw
.us_out_fmt
.cmd
[1] = R500_OUT_FMT_C4_8
|
1929 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1930 r300
->hw
.us_out_fmt
.cmd
[2] = R500_OUT_FMT_UNUSED
|
1931 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1932 r300
->hw
.us_out_fmt
.cmd
[3] = R500_OUT_FMT_UNUSED
|
1933 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1934 r300
->hw
.us_out_fmt
.cmd
[4] = R500_OUT_FMT_UNUSED
|
1935 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1936 r300
->hw
.us_out_fmt
.cmd
[5] = R300_W_FMT_W0
| R300_W_SRC_US
;
1938 /* disable fog unit */
1939 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] = 0;
1940 r300
->hw
.fg_depth_src
.cmd
[1] = R300_FG_DEPTH_SRC_SCAN
;
1942 r300
->hw
.rb3d_cctl
.cmd
[1] = 0;
1944 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
1946 r300
->hw
.rb3d_dither_ctl
.cmd
[1] = 0;
1947 r300
->hw
.rb3d_dither_ctl
.cmd
[2] = 0;
1948 r300
->hw
.rb3d_dither_ctl
.cmd
[3] = 0;
1949 r300
->hw
.rb3d_dither_ctl
.cmd
[4] = 0;
1950 r300
->hw
.rb3d_dither_ctl
.cmd
[5] = 0;
1951 r300
->hw
.rb3d_dither_ctl
.cmd
[6] = 0;
1952 r300
->hw
.rb3d_dither_ctl
.cmd
[7] = 0;
1953 r300
->hw
.rb3d_dither_ctl
.cmd
[8] = 0;
1954 r300
->hw
.rb3d_dither_ctl
.cmd
[9] = 0;
1956 r300
->hw
.rb3d_aaresolve_ctl
.cmd
[1] = 0;
1958 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[1] = 0x00000000;
1959 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[2] = 0xffffffff;
1961 r300
->hw
.zb_depthclearvalue
.cmd
[1] = 0;
1963 r300
->hw
.zstencil_format
.cmd
[2] = R300_ZTOP_DISABLE
;
1964 r300
->hw
.zstencil_format
.cmd
[3] = 0x00000003;
1965 r300
->hw
.zstencil_format
.cmd
[4] = 0x00000000;
1966 r300SetEarlyZState(ctx
);
1968 r300
->hw
.zb_zmask
.cmd
[1] = 0;
1969 r300
->hw
.zb_zmask
.cmd
[2] = 0;
1971 r300
->hw
.zb_hiz_offset
.cmd
[1] = 0;
1973 r300
->hw
.zb_hiz_pitch
.cmd
[1] = 0;
1975 r300VapCntl(r300
, 0, 0, 0);
1977 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
1978 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
1979 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
1980 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
1983 r300
->radeon
.hw
.all_dirty
= GL_TRUE
;
1986 void r300UpdateShaders(r300ContextPtr rmesa
)
1988 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1990 /* should only happenen once, just after context is created */
1991 /* TODO: shouldn't we fallback to sw here? */
1992 if (!ctx
->FragmentProgram
._Current
) {
1993 _mesa_fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1998 struct r300_fragment_program
*fp
;
2000 fp
= r300SelectFragmentShader(ctx
);
2001 if (!fp
->translated
)
2002 r300TranslateFragmentShader(ctx
, fp
);
2004 r300SwitchFallback(ctx
, R300_FALLBACK_FRAGMENT_PROGRAM
, fp
->error
);
2007 if (rmesa
->options
.hw_tcl_enabled
) {
2008 struct r300_vertex_program
*vp
;
2010 if (rmesa
->radeon
.NewGLState
) {
2012 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2013 rmesa
->temp_attrib
[i
] =
2014 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
2015 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2016 &rmesa
->dummy_attrib
[i
];
2019 _tnl_UpdateFixedFunctionProgram(ctx
);
2021 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
2022 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
2023 rmesa
->temp_attrib
[i
];
2027 vp
= r300SelectVertexShader(ctx
);
2028 if (!vp
->translated
)
2029 r300TranslateVertexShader(vp
);
2031 r300SwitchFallback(ctx
, R300_FALLBACK_VERTEX_PROGRAM
, vp
->error
);
2034 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
2035 rmesa
->radeon
.NewGLState
= 0;
2038 static const GLfloat
*get_fragmentprogram_constant(GLcontext
*ctx
,
2039 struct gl_program
*program
, struct prog_src_register srcreg
)
2041 static const GLfloat dummy
[4] = { 0, 0, 0, 0 };
2043 switch(srcreg
.File
) {
2044 case PROGRAM_LOCAL_PARAM
:
2045 return program
->LocalParams
[srcreg
.Index
];
2046 case PROGRAM_ENV_PARAM
:
2047 return ctx
->FragmentProgram
.Parameters
[srcreg
.Index
];
2048 case PROGRAM_STATE_VAR
:
2049 case PROGRAM_NAMED_PARAM
:
2050 case PROGRAM_CONSTANT
:
2051 return program
->Parameters
->ParameterValues
[srcreg
.Index
];
2053 _mesa_problem(ctx
, "get_fragmentprogram_constant: Unknown\n");
2059 static void r300SetupPixelShader(GLcontext
*ctx
)
2061 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2062 struct r300_fragment_program
*fp
= rmesa
->selected_fp
;
2063 struct r300_fragment_program_code
*code
;
2066 code
= &fp
->code
.r300
;
2068 R300_STATECHANGE(rmesa
, fpi
[0]);
2069 R300_STATECHANGE(rmesa
, fpi
[1]);
2070 R300_STATECHANGE(rmesa
, fpi
[2]);
2071 R300_STATECHANGE(rmesa
, fpi
[3]);
2072 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_RGB_INST_0
, code
->alu
.length
);
2073 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_RGB_ADDR_0
, code
->alu
.length
);
2074 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_ALPHA_INST_0
, code
->alu
.length
);
2075 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_ALPHA_ADDR_0
, code
->alu
.length
);
2076 for (i
= 0; i
< code
->alu
.length
; i
++) {
2077 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].inst0
;
2078 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].inst1
;
2079 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].inst2
;
2080 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].inst3
;
2083 R300_STATECHANGE(rmesa
, fp
);
2084 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = code
->cur_node
| (code
->first_node_has_tex
<< 3);
2085 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = code
->max_temp_idx
;
2086 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] =
2087 (0 << R300_PFS_CNTL_ALU_OFFSET_SHIFT
) |
2088 ((code
->alu
.length
-1) << R300_PFS_CNTL_ALU_END_SHIFT
) |
2089 (0 << R300_PFS_CNTL_TEX_OFFSET_SHIFT
) |
2090 ((code
->tex
.length
? code
->tex
.length
-1 : 0) << R300_PFS_CNTL_TEX_END_SHIFT
);
2091 /* I just want to say, the way these nodes are stored.. weird.. */
2092 for (i
= 0, k
= (4 - (code
->cur_node
+ 1)); i
< 4; i
++, k
++) {
2093 if (i
< (code
->cur_node
+ 1)) {
2094 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ k
] =
2095 (code
->node
[i
].alu_offset
<< R300_ALU_START_SHIFT
) |
2096 (code
->node
[i
].alu_end
<< R300_ALU_SIZE_SHIFT
) |
2097 (code
->node
[i
].tex_offset
<< R300_TEX_START_SHIFT
) |
2098 (code
->node
[i
].tex_end
<< R300_TEX_SIZE_SHIFT
) |
2099 code
->node
[i
].flags
;
2101 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ (3 - i
)] = 0;
2105 R300_STATECHANGE(rmesa
, fpp
);
2106 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_PFS_PARAM_0_X
, code
->const_nr
* 4);
2107 for (i
= 0; i
< code
->const_nr
; i
++) {
2108 const GLfloat
*constant
= get_fragmentprogram_constant(ctx
, fp
->Base
, code
->constant
[i
]);
2109 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(constant
[0]);
2110 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(constant
[1]);
2111 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(constant
[2]);
2112 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(constant
[3]);
2116 #define bump_r500fp_count(ptr, new_count) do{\
2117 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2118 int _nc=(new_count)/6; \
2119 assert(_nc < 256); \
2120 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2123 #define bump_r500fp_const_count(ptr, new_count) do{\
2124 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2125 int _nc=(new_count)/4; \
2126 assert(_nc < 256); \
2127 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2130 static void r500SetupPixelShader(GLcontext
*ctx
)
2132 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2133 struct r300_fragment_program
*fp
= rmesa
->selected_fp
;
2135 struct r500_fragment_program_code
*code
;
2137 ((drm_r300_cmd_header_t
*) rmesa
->hw
.r500fp
.cmd
)->r500fp
.count
= 0;
2138 ((drm_r300_cmd_header_t
*) rmesa
->hw
.r500fp_const
.cmd
)->r500fp
.count
= 0;
2140 code
= &fp
->code
.r500
;
2142 R300_STATECHANGE(rmesa
, fp
);
2143 rmesa
->hw
.fp
.cmd
[R500_FP_PIXSIZE
] = code
->max_temp_idx
;
2145 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_ADDR
] =
2146 R500_US_CODE_START_ADDR(code
->inst_offset
) |
2147 R500_US_CODE_END_ADDR(code
->inst_end
);
2148 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_RANGE
] =
2149 R500_US_CODE_RANGE_ADDR(code
->inst_offset
) |
2150 R500_US_CODE_RANGE_SIZE(code
->inst_end
);
2151 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_OFFSET
] =
2152 R500_US_CODE_OFFSET_ADDR(0); /* FIXME when we add flow control */
2154 R300_STATECHANGE(rmesa
, r500fp
);
2155 /* Emit our shader... */
2156 for (i
= 0; i
< code
->inst_end
+1; i
++) {
2157 rmesa
->hw
.r500fp
.cmd
[i
*6+1] = code
->inst
[i
].inst0
;
2158 rmesa
->hw
.r500fp
.cmd
[i
*6+2] = code
->inst
[i
].inst1
;
2159 rmesa
->hw
.r500fp
.cmd
[i
*6+3] = code
->inst
[i
].inst2
;
2160 rmesa
->hw
.r500fp
.cmd
[i
*6+4] = code
->inst
[i
].inst3
;
2161 rmesa
->hw
.r500fp
.cmd
[i
*6+5] = code
->inst
[i
].inst4
;
2162 rmesa
->hw
.r500fp
.cmd
[i
*6+6] = code
->inst
[i
].inst5
;
2165 bump_r500fp_count(rmesa
->hw
.r500fp
.cmd
, (code
->inst_end
+ 1) * 6);
2167 R300_STATECHANGE(rmesa
, r500fp_const
);
2168 for (i
= 0; i
< code
->const_nr
; i
++) {
2169 const GLfloat
*constant
= get_fragmentprogram_constant(ctx
, fp
->Base
, code
->constant
[i
]);
2170 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat32(constant
[0]);
2171 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat32(constant
[1]);
2172 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat32(constant
[2]);
2173 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat32(constant
[3]);
2175 bump_r500fp_const_count(rmesa
->hw
.r500fp_const
.cmd
, code
->const_nr
* 4);
2178 void r300SetupVAP(GLcontext
*ctx
, GLuint InputsRead
, GLuint OutputsWritten
)
2180 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
2181 struct vertex_attribute
*attrs
= rmesa
->vbuf
.attribs
;
2182 int i
, j
, reg_count
;
2183 uint32_t *vir0
= &rmesa
->hw
.vir
[0].cmd
[1];
2184 uint32_t *vir1
= &rmesa
->hw
.vir
[1].cmd
[1];
2186 for (i
= 0; i
< R300_VIR_CMDSIZE
-1; ++i
)
2187 vir0
[i
] = vir1
[i
] = 0;
2189 for (i
= 0, j
= 0; i
< rmesa
->vbuf
.num_attribs
; ++i
) {
2192 tmp
= attrs
[i
].data_type
| (attrs
[i
].dst_loc
<< R300_DST_VEC_LOC_SHIFT
);
2193 if (attrs
[i
]._signed
)
2195 if (attrs
[i
].normalize
)
2196 tmp
|= R300_NORMALIZE
;
2199 vir0
[j
] = tmp
<< R300_DATA_TYPE_0_SHIFT
;
2200 vir1
[j
] = attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
);
2202 vir0
[j
] |= tmp
<< R300_DATA_TYPE_1_SHIFT
;
2203 vir1
[j
] |= (attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
)) << R300_SWIZZLE1_SHIFT
;
2208 reg_count
= (rmesa
->vbuf
.num_attribs
+ 1) >> 1;
2209 if (rmesa
->vbuf
.num_attribs
% 2 != 0) {
2210 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_0_SHIFT
;
2212 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_1_SHIFT
;
2215 R300_STATECHANGE(rmesa
, vir
[0]);
2216 R300_STATECHANGE(rmesa
, vir
[1]);
2217 R300_STATECHANGE(rmesa
, vof
);
2218 R300_STATECHANGE(rmesa
, vic
);
2220 if (rmesa
->radeon
.radeonScreen
->kernel_mm
) {
2221 rmesa
->hw
.vir
[0].cmd
[0] &= 0xC000FFFF;
2222 rmesa
->hw
.vir
[1].cmd
[0] &= 0xC000FFFF;
2223 rmesa
->hw
.vir
[0].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
2224 rmesa
->hw
.vir
[1].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
2226 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
= reg_count
;
2227 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
= reg_count
;
2230 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
2231 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
2232 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
2233 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = r300VAPOutputCntl1(ctx
, OutputsWritten
);
2236 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2239 ctx
= rmesa
->radeon
.glCtx
;
2241 /* should only happenen once, just after context is created */
2242 if (!ctx
->FragmentProgram
._Current
)
2245 r300SetEarlyZState(ctx
);
2247 r300SetupTextures(ctx
);
2249 rmesa
->vtbl
.SetupPixelShader(ctx
);
2251 rmesa
->vtbl
.SetupRSUnit(ctx
);
2253 if (rmesa
->options
.hw_tcl_enabled
) {
2254 r300SetupVertexProgram(rmesa
);
2259 * Called by Mesa after an internal state update.
2261 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2263 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2265 _swrast_InvalidateState(ctx
, new_state
);
2266 _swsetup_InvalidateState(ctx
, new_state
);
2267 _vbo_InvalidateState(ctx
, new_state
);
2268 _tnl_InvalidateState(ctx
, new_state
);
2270 if (new_state
& _NEW_BUFFERS
) {
2271 _mesa_update_framebuffer(ctx
);
2272 /* this updates the DrawBuffer's Width/Height if it's a FBO */
2273 _mesa_update_draw_buffer_bounds(ctx
);
2275 R300_STATECHANGE(r300
, cb
);
2278 r300
->radeon
.NewGLState
|= new_state
;
2282 * Calculate initial hardware state and register state functions.
2283 * Assumes that the command buffer and state atoms have been
2284 * initialized already.
2286 void r300InitState(r300ContextPtr r300
)
2288 r300ResetHwState(r300
);
2291 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2293 r300SwitchFallback(ctx
, R300_FALLBACK_RENDER_MODE
, ctx
->RenderMode
!= GL_RENDER
);
2297 * Initialize driver's state callback functions
2299 void r300InitStateFuncs(struct dd_function_table
*functions
)
2302 functions
->UpdateState
= r300InvalidateState
;
2303 functions
->AlphaFunc
= r300AlphaFunc
;
2304 functions
->BlendColor
= r300BlendColor
;
2305 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2306 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2307 functions
->Enable
= r300Enable
;
2308 functions
->ColorMask
= r300ColorMask
;
2309 functions
->DepthFunc
= r300DepthFunc
;
2310 functions
->DepthMask
= r300DepthMask
;
2311 functions
->CullFace
= r300CullFace
;
2312 functions
->FrontFace
= r300FrontFace
;
2313 functions
->ShadeModel
= r300ShadeModel
;
2314 functions
->LogicOpcode
= r300LogicOpcode
;
2316 /* ARB_point_parameters */
2317 functions
->PointParameterfv
= r300PointParameter
;
2319 /* Stencil related */
2320 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2321 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2322 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2324 /* Viewport related */
2325 functions
->Viewport
= r300Viewport
;
2326 functions
->DepthRange
= r300DepthRange
;
2327 functions
->PointSize
= r300PointSize
;
2328 functions
->LineWidth
= r300LineWidth
;
2330 functions
->PolygonOffset
= r300PolygonOffset
;
2331 functions
->PolygonMode
= r300PolygonMode
;
2333 functions
->RenderMode
= r300RenderMode
;
2335 functions
->ClipPlane
= r300ClipPlane
;
2336 functions
->Scissor
= radeonScissor
;
2338 functions
->DrawBuffer
= radeonDrawBuffer
;
2339 functions
->ReadBuffer
= radeonReadBuffer
;
2342 void r300InitShaderFunctions(r300ContextPtr r300
)
2344 if (r300
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
) {
2345 r300
->vtbl
.SetupRSUnit
= r500SetupRSUnit
;
2346 r300
->vtbl
.SetupPixelShader
= r500SetupPixelShader
;
2347 r300
->vtbl
.SetupFragmentShaderTextures
= r500SetupFragmentShaderTextures
;
2348 r300
->vtbl
.BuildFragmentProgramHwCode
= r500BuildFragmentProgramHwCode
;
2349 r300
->vtbl
.FragmentProgramDump
= r500FragmentProgramDump
;
2351 r300
->vtbl
.SetupRSUnit
= r300SetupRSUnit
;
2352 r300
->vtbl
.SetupPixelShader
= r300SetupPixelShader
;
2353 r300
->vtbl
.SetupFragmentShaderTextures
= r300SetupFragmentShaderTextures
;
2354 r300
->vtbl
.BuildFragmentProgramHwCode
= r300BuildFragmentProgramHwCode
;
2355 r300
->vtbl
.FragmentProgramDump
= r300FragmentProgramDump
;