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_render.h"
66 #include "r300_vertprog.h"
68 #include "drirenderbuffer.h"
70 static void r300BlendColor(GLcontext
* ctx
, const GLfloat cf
[4])
72 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
74 R300_STATECHANGE(rmesa
, blend_color
);
76 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
) {
77 GLuint r
= IROUND(cf
[0]*1023.0f
);
78 GLuint g
= IROUND(cf
[1]*1023.0f
);
79 GLuint b
= IROUND(cf
[2]*1023.0f
);
80 GLuint a
= IROUND(cf
[3]*1023.0f
);
82 rmesa
->hw
.blend_color
.cmd
[1] = r
| (a
<< 16);
83 rmesa
->hw
.blend_color
.cmd
[2] = b
| (g
<< 16);
86 CLAMPED_FLOAT_TO_UBYTE(color
[0], cf
[0]);
87 CLAMPED_FLOAT_TO_UBYTE(color
[1], cf
[1]);
88 CLAMPED_FLOAT_TO_UBYTE(color
[2], cf
[2]);
89 CLAMPED_FLOAT_TO_UBYTE(color
[3], cf
[3]);
91 rmesa
->hw
.blend_color
.cmd
[1] = PACK_COLOR_8888(color
[3], color
[0],
97 * Calculate the hardware blend factor setting. This same function is used
98 * for source and destination of both alpha and RGB.
101 * The hardware register value for the specified blend factor. This value
102 * will need to be shifted into the correct position for either source or
103 * destination factor.
106 * Since the two cases where source and destination are handled differently
107 * are essentially error cases, they should never happen. Determine if these
108 * cases can be removed.
110 static int blend_factor(GLenum factor
, GLboolean is_src
)
114 return R300_BLEND_GL_ZERO
;
117 return R300_BLEND_GL_ONE
;
120 return R300_BLEND_GL_DST_COLOR
;
122 case GL_ONE_MINUS_DST_COLOR
:
123 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
126 return R300_BLEND_GL_SRC_COLOR
;
128 case GL_ONE_MINUS_SRC_COLOR
:
129 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
132 return R300_BLEND_GL_SRC_ALPHA
;
134 case GL_ONE_MINUS_SRC_ALPHA
:
135 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
138 return R300_BLEND_GL_DST_ALPHA
;
140 case GL_ONE_MINUS_DST_ALPHA
:
141 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
143 case GL_SRC_ALPHA_SATURATE
:
144 return (is_src
) ? R300_BLEND_GL_SRC_ALPHA_SATURATE
:
147 case GL_CONSTANT_COLOR
:
148 return R300_BLEND_GL_CONST_COLOR
;
150 case GL_ONE_MINUS_CONSTANT_COLOR
:
151 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
153 case GL_CONSTANT_ALPHA
:
154 return R300_BLEND_GL_CONST_ALPHA
;
156 case GL_ONE_MINUS_CONSTANT_ALPHA
:
157 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
160 fprintf(stderr
, "unknown blend factor %x\n", factor
);
161 return (is_src
) ? R300_BLEND_GL_ONE
: R300_BLEND_GL_ZERO
;
167 * Sets both the blend equation and the blend function.
168 * This is done in a single
169 * function because some blend equations (i.e., \c GL_MIN and \c GL_MAX)
170 * change the interpretation of the blend function.
171 * Also, make sure that blend function and blend equation are set to their
172 * default value if color blending is not enabled, since at least blend
173 * equations GL_MIN and GL_FUNC_REVERSE_SUBTRACT will cause wrong results
174 * otherwise for unknown reasons.
177 /* helper function */
178 static void r300SetBlendCntl(r300ContextPtr r300
, int func
, int eqn
,
179 int cbits
, int funcA
, int eqnA
)
181 GLuint new_ablend
, new_cblend
;
185 "eqnA=%08x funcA=%08x eqn=%08x func=%08x cbits=%08x\n",
186 eqnA
, funcA
, eqn
, func
, cbits
);
188 new_ablend
= eqnA
| funcA
;
189 new_cblend
= eqn
| func
;
191 /* Some blend factor combinations don't seem to work when the
192 * BLEND_NO_SEPARATE bit is set.
194 * Especially problematic candidates are the ONE_MINUS_* flags,
195 * but I can't see a real pattern.
198 if (new_ablend
== new_cblend
) {
199 new_cblend
|= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0
;
204 if ((new_ablend
!= r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
]) ||
205 (new_cblend
!= r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
])) {
206 R300_STATECHANGE(r300
, bld
);
207 r300
->hw
.bld
.cmd
[R300_BLD_ABLEND
] = new_ablend
;
208 r300
->hw
.bld
.cmd
[R300_BLD_CBLEND
] = new_cblend
;
212 static void r300SetBlendState(GLcontext
* ctx
)
214 r300ContextPtr r300
= R300_CONTEXT(ctx
);
215 int func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
216 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
217 int eqn
= R300_COMB_FCN_ADD_CLAMP
;
218 int funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
219 (R300_BLEND_GL_ZERO
<< R300_DST_BLEND_SHIFT
);
220 int eqnA
= R300_COMB_FCN_ADD_CLAMP
;
222 if (RGBA_LOGICOP_ENABLED(ctx
) || !ctx
->Color
.BlendEnabled
) {
223 r300SetBlendCntl(r300
, func
, eqn
, 0, func
, eqn
);
228 (blend_factor(ctx
->Color
.BlendSrcRGB
, GL_TRUE
) <<
229 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstRGB
,
231 R300_DST_BLEND_SHIFT
);
233 switch (ctx
->Color
.BlendEquationRGB
) {
235 eqn
= R300_COMB_FCN_ADD_CLAMP
;
238 case GL_FUNC_SUBTRACT
:
239 eqn
= R300_COMB_FCN_SUB_CLAMP
;
242 case GL_FUNC_REVERSE_SUBTRACT
:
243 eqn
= R300_COMB_FCN_RSUB_CLAMP
;
247 eqn
= R300_COMB_FCN_MIN
;
248 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
249 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
253 eqn
= R300_COMB_FCN_MAX
;
254 func
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
255 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
260 "[%s:%u] Invalid RGB blend equation (0x%04x).\n",
261 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationRGB
);
266 (blend_factor(ctx
->Color
.BlendSrcA
, GL_TRUE
) <<
267 R300_SRC_BLEND_SHIFT
) | (blend_factor(ctx
->Color
.BlendDstA
,
269 R300_DST_BLEND_SHIFT
);
271 switch (ctx
->Color
.BlendEquationA
) {
273 eqnA
= R300_COMB_FCN_ADD_CLAMP
;
276 case GL_FUNC_SUBTRACT
:
277 eqnA
= R300_COMB_FCN_SUB_CLAMP
;
280 case GL_FUNC_REVERSE_SUBTRACT
:
281 eqnA
= R300_COMB_FCN_RSUB_CLAMP
;
285 eqnA
= R300_COMB_FCN_MIN
;
286 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
287 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
291 eqnA
= R300_COMB_FCN_MAX
;
292 funcA
= (R300_BLEND_GL_ONE
<< R300_SRC_BLEND_SHIFT
) |
293 (R300_BLEND_GL_ONE
<< R300_DST_BLEND_SHIFT
);
298 "[%s:%u] Invalid A blend equation (0x%04x).\n",
299 __FUNCTION__
, __LINE__
, ctx
->Color
.BlendEquationA
);
303 r300SetBlendCntl(r300
,
305 (R300_SEPARATE_ALPHA_ENABLE
|
307 R300_ALPHA_BLEND_ENABLE
), funcA
, eqnA
);
310 static void r300BlendEquationSeparate(GLcontext
* ctx
,
311 GLenum modeRGB
, GLenum modeA
)
313 r300SetBlendState(ctx
);
316 static void r300BlendFuncSeparate(GLcontext
* ctx
,
317 GLenum sfactorRGB
, GLenum dfactorRGB
,
318 GLenum sfactorA
, GLenum dfactorA
)
320 r300SetBlendState(ctx
);
324 * Translate LogicOp enums into hardware representation.
325 * Both use a very logical bit-wise layout, but unfortunately the order
326 * of bits is reversed.
328 static GLuint
translate_logicop(GLenum logicop
)
330 GLuint bits
= logicop
- GL_CLEAR
;
331 bits
= ((bits
& 1) << 3) | ((bits
& 2) << 1) | ((bits
& 4) >> 1) | ((bits
& 8) >> 3);
332 return bits
<< R300_RB3D_ROPCNTL_ROP_SHIFT
;
336 * Used internally to update the r300->hw hardware state to match the
337 * current OpenGL state.
339 static void r300SetLogicOpState(GLcontext
*ctx
)
341 r300ContextPtr r300
= R300_CONTEXT(ctx
);
342 R300_STATECHANGE(r300
, rop
);
343 if (RGBA_LOGICOP_ENABLED(ctx
)) {
344 r300
->hw
.rop
.cmd
[1] = R300_RB3D_ROPCNTL_ROP_ENABLE
|
345 translate_logicop(ctx
->Color
.LogicOp
);
347 r300
->hw
.rop
.cmd
[1] = 0;
352 * Called by Mesa when an application program changes the LogicOp state
355 static void r300LogicOpcode(GLcontext
*ctx
, GLenum logicop
)
357 if (RGBA_LOGICOP_ENABLED(ctx
))
358 r300SetLogicOpState(ctx
);
361 static void r300ClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
)
363 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
367 /* no VAP UCP on non-TCL chipsets */
368 if (!rmesa
->options
.hw_tcl_enabled
)
371 p
= (GLint
) plane
- (GLint
) GL_CLIP_PLANE0
;
372 ip
= (GLint
*)ctx
->Transform
._ClipUserPlane
[p
];
374 R300_STATECHANGE( rmesa
, vpucp
[p
] );
375 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_X
] = ip
[0];
376 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Y
] = ip
[1];
377 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_Z
] = ip
[2];
378 rmesa
->hw
.vpucp
[p
].cmd
[R300_VPUCP_W
] = ip
[3];
381 static void r300SetClipPlaneState(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
383 r300ContextPtr r300
= R300_CONTEXT(ctx
);
386 /* no VAP UCP on non-TCL chipsets */
387 if (!r300
->options
.hw_tcl_enabled
)
390 p
= cap
- GL_CLIP_PLANE0
;
391 R300_STATECHANGE(r300
, vap_clip_cntl
);
393 r300
->hw
.vap_clip_cntl
.cmd
[1] |= (R300_VAP_UCP_ENABLE_0
<< p
);
394 r300ClipPlane(ctx
, cap
, NULL
);
396 r300
->hw
.vap_clip_cntl
.cmd
[1] &= ~(R300_VAP_UCP_ENABLE_0
<< p
);
401 * Update our tracked culling state based on Mesa's state.
403 static void r300UpdateCulling(GLcontext
* ctx
)
405 r300ContextPtr r300
= R300_CONTEXT(ctx
);
408 if (ctx
->Polygon
.CullFlag
) {
409 switch (ctx
->Polygon
.CullFaceMode
) {
411 val
= R300_CULL_FRONT
;
414 val
= R300_CULL_BACK
;
416 case GL_FRONT_AND_BACK
:
417 val
= R300_CULL_FRONT
| R300_CULL_BACK
;
424 switch (ctx
->Polygon
.FrontFace
) {
426 val
|= R300_FRONT_FACE_CW
;
429 val
|= R300_FRONT_FACE_CCW
;
435 /* Winding is inverted when rendering to FBO */
436 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->Name
)
437 val
^= R300_FRONT_FACE_CW
;
439 R300_STATECHANGE(r300
, cul
);
440 r300
->hw
.cul
.cmd
[R300_CUL_CULL
] = val
;
443 static void r300SetPolygonOffsetState(GLcontext
* ctx
, GLboolean state
)
445 r300ContextPtr r300
= R300_CONTEXT(ctx
);
447 R300_STATECHANGE(r300
, occlusion_cntl
);
449 r300
->hw
.occlusion_cntl
.cmd
[1] |= (3 << 0);
451 r300
->hw
.occlusion_cntl
.cmd
[1] &= ~(3 << 0);
455 static GLboolean
current_fragment_program_writes_depth(GLcontext
* ctx
)
457 r300ContextPtr r300
= R300_CONTEXT(ctx
);
459 return ctx
->FragmentProgram
._Current
&& r300
->selected_fp
->code
.writes_depth
;
462 static void r300SetEarlyZState(GLcontext
* ctx
)
464 r300ContextPtr r300
= R300_CONTEXT(ctx
);
465 GLuint topZ
= R300_ZTOP_ENABLE
;
466 GLuint w_fmt
, fgdepthsrc
;
468 if (ctx
->Color
.AlphaEnabled
&& ctx
->Color
.AlphaFunc
!= GL_ALWAYS
)
469 topZ
= R300_ZTOP_DISABLE
;
470 else if (current_fragment_program_writes_depth(ctx
))
471 topZ
= R300_ZTOP_DISABLE
;
472 else if (ctx
->FragmentProgram
._Current
&& ctx
->FragmentProgram
._Current
->UsesKill
)
473 topZ
= R300_ZTOP_DISABLE
;
475 if (topZ
!= r300
->hw
.zstencil_format
.cmd
[2]) {
476 /* Note: This completely reemits the stencil format.
477 * I have not tested whether this is strictly necessary,
478 * or if emitting a write to ZB_ZTOP is enough.
480 R300_STATECHANGE(r300
, zstencil_format
);
481 r300
->hw
.zstencil_format
.cmd
[2] = topZ
;
484 /* w_fmt value is set to get best performance
485 * see p.130 R5xx 3D acceleration guide v1.3 */
486 if (current_fragment_program_writes_depth(ctx
)) {
487 fgdepthsrc
= R300_FG_DEPTH_SRC_SHADER
;
488 w_fmt
= R300_W_FMT_W24
| R300_W_SRC_US
;
490 fgdepthsrc
= R300_FG_DEPTH_SRC_SCAN
;
491 w_fmt
= R300_W_FMT_W0
| R300_W_SRC_US
;
494 if (w_fmt
!= r300
->hw
.us_out_fmt
.cmd
[5]) {
495 R300_STATECHANGE(r300
, us_out_fmt
);
496 r300
->hw
.us_out_fmt
.cmd
[5] = w_fmt
;
499 if (fgdepthsrc
!= r300
->hw
.fg_depth_src
.cmd
[1]) {
500 R300_STATECHANGE(r300
, fg_depth_src
);
501 r300
->hw
.fg_depth_src
.cmd
[1] = fgdepthsrc
;
505 static void r300SetAlphaState(GLcontext
* ctx
)
507 r300ContextPtr r300
= R300_CONTEXT(ctx
);
509 uint32_t pp_misc
= 0x0;
510 GLboolean really_enabled
= ctx
->Color
.AlphaEnabled
;
512 CLAMPED_FLOAT_TO_UBYTE(refByte
, ctx
->Color
.AlphaRef
);
514 switch (ctx
->Color
.AlphaFunc
) {
516 pp_misc
|= R300_FG_ALPHA_FUNC_NEVER
;
519 pp_misc
|= R300_FG_ALPHA_FUNC_LESS
;
522 pp_misc
|= R300_FG_ALPHA_FUNC_EQUAL
;
525 pp_misc
|= R300_FG_ALPHA_FUNC_LE
;
528 pp_misc
|= R300_FG_ALPHA_FUNC_GREATER
;
531 pp_misc
|= R300_FG_ALPHA_FUNC_NOTEQUAL
;
534 pp_misc
|= R300_FG_ALPHA_FUNC_GE
;
537 /*pp_misc |= FG_ALPHA_FUNC_ALWAYS; */
538 really_enabled
= GL_FALSE
;
542 if (really_enabled
) {
543 pp_misc
|= R300_FG_ALPHA_FUNC_ENABLE
;
544 pp_misc
|= R500_FG_ALPHA_FUNC_8BIT
;
545 pp_misc
|= (refByte
& R300_FG_ALPHA_FUNC_VAL_MASK
);
550 R300_STATECHANGE(r300
, at
);
551 r300
->hw
.at
.cmd
[R300_AT_ALPHA_TEST
] = pp_misc
;
552 r300
->hw
.at
.cmd
[R300_AT_UNKNOWN
] = 0;
555 static void r300AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
)
559 r300SetAlphaState(ctx
);
562 static int translate_func(int func
)
566 return R300_ZS_NEVER
;
570 return R300_ZS_EQUAL
;
572 return R300_ZS_LEQUAL
;
574 return R300_ZS_GREATER
;
576 return R300_ZS_NOTEQUAL
;
578 return R300_ZS_GEQUAL
;
580 return R300_ZS_ALWAYS
;
585 static void r300SetDepthState(GLcontext
* ctx
)
587 r300ContextPtr r300
= R300_CONTEXT(ctx
);
589 R300_STATECHANGE(r300
, zs
);
590 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &= R300_STENCIL_ENABLE
|R300_STENCIL_FRONT_BACK
;
591 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~(R300_ZS_MASK
<< R300_Z_FUNC_SHIFT
);
593 if (ctx
->Depth
.Test
) {
594 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_Z_ENABLE
;
596 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_Z_WRITE_ENABLE
;
597 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
598 translate_func(ctx
->Depth
.Func
) << R300_Z_FUNC_SHIFT
;
602 static void r300CatchStencilFallback(GLcontext
*ctx
)
604 const unsigned back
= ctx
->Stencil
._BackFace
;
606 if (ctx
->Stencil
._Enabled
&& (ctx
->Stencil
.Ref
[0] != ctx
->Stencil
.Ref
[back
]
607 || ctx
->Stencil
.ValueMask
[0] != ctx
->Stencil
.ValueMask
[back
]
608 || ctx
->Stencil
.WriteMask
[0] != ctx
->Stencil
.WriteMask
[back
])) {
609 r300SwitchFallback(ctx
, R300_FALLBACK_STENCIL_TWOSIDE
, GL_TRUE
);
611 r300SwitchFallback(ctx
, R300_FALLBACK_STENCIL_TWOSIDE
, GL_FALSE
);
615 static void r300SetStencilState(GLcontext
* ctx
, GLboolean state
)
617 r300ContextPtr r300
= R300_CONTEXT(ctx
);
618 GLboolean hw_stencil
= GL_FALSE
;
620 r300CatchStencilFallback(ctx
);
622 if (ctx
->DrawBuffer
) {
623 struct radeon_renderbuffer
*rrbStencil
624 = radeon_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_STENCIL
);
625 hw_stencil
= (rrbStencil
&& rrbStencil
->bo
);
629 R300_STATECHANGE(r300
, zs
);
631 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |=
634 r300
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] &=
635 ~R300_STENCIL_ENABLE
;
640 static void r300UpdatePolygonMode(GLcontext
* ctx
)
642 r300ContextPtr r300
= R300_CONTEXT(ctx
);
643 uint32_t hw_mode
= R300_GA_POLY_MODE_DISABLE
;
645 /* Only do something if a polygon mode is wanted, default is GL_FILL */
646 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
647 ctx
->Polygon
.BackMode
!= GL_FILL
) {
650 /* Handle GL_CW (clock wise and GL_CCW (counter clock wise)
651 * correctly by selecting the correct front and back face
653 if (ctx
->Polygon
.FrontFace
== GL_CCW
) {
654 f
= ctx
->Polygon
.FrontMode
;
655 b
= ctx
->Polygon
.BackMode
;
657 f
= ctx
->Polygon
.BackMode
;
658 b
= ctx
->Polygon
.FrontMode
;
661 /* Enable polygon mode */
662 hw_mode
|= R300_GA_POLY_MODE_DUAL
;
666 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_LINE
;
669 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_POINT
;
672 hw_mode
|= R300_GA_POLY_MODE_FRONT_PTYPE_TRI
;
678 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_LINE
;
681 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_POINT
;
684 hw_mode
|= R300_GA_POLY_MODE_BACK_PTYPE_TRI
;
689 if (r300
->hw
.polygon_mode
.cmd
[1] != hw_mode
) {
690 R300_STATECHANGE(r300
, polygon_mode
);
691 r300
->hw
.polygon_mode
.cmd
[1] = hw_mode
;
694 r300
->hw
.polygon_mode
.cmd
[2] = 0x00000001;
695 r300
->hw
.polygon_mode
.cmd
[3] = 0x00000000;
699 * Change the culling mode.
701 * \note Mesa already filters redundant calls to this function.
703 static void r300CullFace(GLcontext
* ctx
, GLenum mode
)
707 r300UpdateCulling(ctx
);
711 * Change the polygon orientation.
713 * \note Mesa already filters redundant calls to this function.
715 static void r300FrontFace(GLcontext
* ctx
, GLenum mode
)
719 r300UpdateCulling(ctx
);
720 r300UpdatePolygonMode(ctx
);
724 * Change the depth testing function.
726 * \note Mesa already filters redundant calls to this function.
728 static void r300DepthFunc(GLcontext
* ctx
, GLenum func
)
731 r300SetDepthState(ctx
);
735 * Enable/Disable depth writing.
737 * \note Mesa already filters redundant calls to this function.
739 static void r300DepthMask(GLcontext
* ctx
, GLboolean mask
)
742 r300SetDepthState(ctx
);
746 * Handle glColorMask()
748 static void r300ColorMask(GLcontext
* ctx
,
749 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
)
751 r300ContextPtr r300
= R300_CONTEXT(ctx
);
752 int mask
= (r
? RB3D_COLOR_CHANNEL_MASK_RED_MASK0
: 0) |
753 (g
? RB3D_COLOR_CHANNEL_MASK_GREEN_MASK0
: 0) |
754 (b
? RB3D_COLOR_CHANNEL_MASK_BLUE_MASK0
: 0) |
755 (a
? RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK0
: 0);
757 if (mask
!= r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
]) {
758 R300_STATECHANGE(r300
, cmk
);
759 r300
->hw
.cmk
.cmd
[R300_CMK_COLORMASK
] = mask
;
763 /* =============================================================
766 static void r300PointSize(GLcontext
* ctx
, GLfloat size
)
768 r300ContextPtr r300
= R300_CONTEXT(ctx
);
770 /* We need to clamp to user defined range here, because
771 * the HW clamping happens only for per vertex point size. */
772 size
= CLAMP(size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
774 /* same size limits for AA, non-AA points */
775 size
= CLAMP(size
, ctx
->Const
.MinPointSize
, ctx
->Const
.MaxPointSize
);
777 R300_STATECHANGE(r300
, ps
);
778 r300
->hw
.ps
.cmd
[R300_PS_POINTSIZE
] =
779 ((int)(size
* 6) << R300_POINTSIZE_X_SHIFT
) |
780 ((int)(size
* 6) << R300_POINTSIZE_Y_SHIFT
);
783 static void r300PointParameter(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
)
785 r300ContextPtr r300
= R300_CONTEXT(ctx
);
788 case GL_POINT_SIZE_MIN
:
789 R300_STATECHANGE(r300
, ga_point_minmax
);
790 r300
->hw
.ga_point_minmax
.cmd
[1] &= ~R300_GA_POINT_MINMAX_MIN_MASK
;
791 r300
->hw
.ga_point_minmax
.cmd
[1] |= (GLuint
)(ctx
->Point
.MinSize
* 6.0);
793 case GL_POINT_SIZE_MAX
:
794 R300_STATECHANGE(r300
, ga_point_minmax
);
795 r300
->hw
.ga_point_minmax
.cmd
[1] &= ~R300_GA_POINT_MINMAX_MAX_MASK
;
796 r300
->hw
.ga_point_minmax
.cmd
[1] |= (GLuint
)(ctx
->Point
.MaxSize
* 6.0)
797 << R300_GA_POINT_MINMAX_MAX_SHIFT
;
799 case GL_POINT_DISTANCE_ATTENUATION
:
801 case GL_POINT_FADE_THRESHOLD_SIZE
:
808 /* =============================================================
811 static void r300LineWidth(GLcontext
* ctx
, GLfloat widthf
)
813 r300ContextPtr r300
= R300_CONTEXT(ctx
);
815 widthf
= CLAMP(widthf
,
816 ctx
->Const
.MinPointSize
,
817 ctx
->Const
.MaxPointSize
);
818 R300_STATECHANGE(r300
, lcntl
);
819 r300
->hw
.lcntl
.cmd
[1] =
820 R300_LINE_CNT_HO
| R300_LINE_CNT_VE
| (int)(widthf
* 6.0);
823 static void r300PolygonMode(GLcontext
* ctx
, GLenum face
, GLenum mode
)
828 r300UpdatePolygonMode(ctx
);
831 /* =============================================================
835 static int translate_stencil_op(int op
)
843 return R300_ZS_REPLACE
;
848 case GL_INCR_WRAP_EXT
:
849 return R300_ZS_INCR_WRAP
;
850 case GL_DECR_WRAP_EXT
:
851 return R300_ZS_DECR_WRAP
;
853 return R300_ZS_INVERT
;
855 WARN_ONCE("Do not know how to translate stencil op");
861 static void r300ShadeModel(GLcontext
* ctx
, GLenum mode
)
863 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
865 R300_STATECHANGE(rmesa
, shade
);
866 rmesa
->hw
.shade
.cmd
[1] = 0x00000002;
867 R300_STATECHANGE(rmesa
, shade2
);
870 rmesa
->hw
.shade2
.cmd
[1] = R300_RE_SHADE_MODEL_FLAT
;
873 rmesa
->hw
.shade2
.cmd
[1] = R300_RE_SHADE_MODEL_SMOOTH
;
878 rmesa
->hw
.shade2
.cmd
[2] = 0x00000000;
879 rmesa
->hw
.shade2
.cmd
[3] = 0x00000000;
882 static void r300StencilFuncSeparate(GLcontext
* ctx
, GLenum face
,
883 GLenum func
, GLint ref
, GLuint mask
)
885 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
888 const unsigned back
= ctx
->Stencil
._BackFace
;
890 r300CatchStencilFallback(ctx
);
892 refmask
= ((ctx
->Stencil
.Ref
[0] & 0xff) << R300_STENCILREF_SHIFT
)
893 | ((ctx
->Stencil
.ValueMask
[0] & 0xff) << R300_STENCILMASK_SHIFT
);
895 R300_STATECHANGE(rmesa
, zs
);
896 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_0
] |= R300_STENCIL_FRONT_BACK
;
897 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &= ~((R300_ZS_MASK
<<
898 R300_S_FRONT_FUNC_SHIFT
)
900 R300_S_BACK_FUNC_SHIFT
));
902 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
903 ~((R300_STENCILREF_MASK
<< R300_STENCILREF_SHIFT
) |
904 (R300_STENCILREF_MASK
<< R300_STENCILMASK_SHIFT
));
906 flag
= translate_func(ctx
->Stencil
.Function
[0]);
907 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
908 (flag
<< R300_S_FRONT_FUNC_SHIFT
);
910 flag
= translate_func(ctx
->Stencil
.Function
[back
]);
912 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
913 (flag
<< R300_S_BACK_FUNC_SHIFT
);
914 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |= refmask
;
917 static void r300StencilMaskSeparate(GLcontext
* ctx
, GLenum face
, GLuint mask
)
919 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
921 r300CatchStencilFallback(ctx
);
923 R300_STATECHANGE(rmesa
, zs
);
924 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] &=
925 ~(R300_STENCILREF_MASK
<<
926 R300_STENCILWRITEMASK_SHIFT
);
927 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_2
] |=
929 WriteMask
[0] & R300_STENCILREF_MASK
) <<
930 R300_STENCILWRITEMASK_SHIFT
;
933 static void r300StencilOpSeparate(GLcontext
* ctx
, GLenum face
,
934 GLenum fail
, GLenum zfail
, GLenum zpass
)
936 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
937 const unsigned back
= ctx
->Stencil
._BackFace
;
939 r300CatchStencilFallback(ctx
);
941 R300_STATECHANGE(rmesa
, zs
);
942 /* It is easier to mask what's left.. */
943 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] &=
944 (R300_ZS_MASK
<< R300_Z_FUNC_SHIFT
) |
945 (R300_ZS_MASK
<< R300_S_FRONT_FUNC_SHIFT
) |
946 (R300_ZS_MASK
<< R300_S_BACK_FUNC_SHIFT
);
948 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
949 (translate_stencil_op(ctx
->Stencil
.FailFunc
[0]) <<
950 R300_S_FRONT_SFAIL_OP_SHIFT
)
951 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[0]) <<
952 R300_S_FRONT_ZFAIL_OP_SHIFT
)
953 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[0]) <<
954 R300_S_FRONT_ZPASS_OP_SHIFT
);
956 rmesa
->hw
.zs
.cmd
[R300_ZS_CNTL_1
] |=
957 (translate_stencil_op(ctx
->Stencil
.FailFunc
[back
]) <<
958 R300_S_BACK_SFAIL_OP_SHIFT
)
959 | (translate_stencil_op(ctx
->Stencil
.ZFailFunc
[back
]) <<
960 R300_S_BACK_ZFAIL_OP_SHIFT
)
961 | (translate_stencil_op(ctx
->Stencil
.ZPassFunc
[back
]) <<
962 R300_S_BACK_ZPASS_OP_SHIFT
);
965 /* =============================================================
966 * Window position and viewport transformation
969 static void r300UpdateWindow(GLcontext
* ctx
)
971 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
972 __DRIdrawablePrivate
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
973 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
974 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
975 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
976 const GLfloat depthScale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
977 const GLboolean render_to_fbo
= (ctx
->DrawBuffer
->Name
!= 0);
978 GLfloat y_scale
, y_bias
;
988 GLfloat sx
= v
[MAT_SX
];
989 GLfloat tx
= v
[MAT_TX
] + xoffset
;
990 GLfloat sy
= v
[MAT_SY
] * y_scale
;
991 GLfloat ty
= (v
[MAT_TY
] * y_scale
) + y_bias
;
992 GLfloat sz
= v
[MAT_SZ
] * depthScale
;
993 GLfloat tz
= v
[MAT_TZ
] * depthScale
;
995 R300_STATECHANGE(rmesa
, vpt
);
997 rmesa
->hw
.vpt
.cmd
[R300_VPT_XSCALE
] = r300PackFloat32(sx
);
998 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
999 rmesa
->hw
.vpt
.cmd
[R300_VPT_YSCALE
] = r300PackFloat32(sy
);
1000 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1001 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZSCALE
] = r300PackFloat32(sz
);
1002 rmesa
->hw
.vpt
.cmd
[R300_VPT_ZOFFSET
] = r300PackFloat32(tz
);
1005 static void r300Viewport(GLcontext
* ctx
, GLint x
, GLint y
,
1006 GLsizei width
, GLsizei height
)
1008 /* Don't pipeline viewport changes, conflict with window offset
1009 * setting below. Could apply deltas to rescue pipelined viewport
1010 * values, or keep the originals hanging around.
1012 r300UpdateWindow(ctx
);
1014 radeon_viewport(ctx
, x
, y
, width
, height
);
1017 static void r300DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
)
1019 r300UpdateWindow(ctx
);
1022 void r300UpdateViewportOffset(GLcontext
* ctx
)
1024 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1025 __DRIdrawablePrivate
*dPriv
= radeon_get_drawable(&rmesa
->radeon
);
1026 GLfloat xoffset
= (GLfloat
) dPriv
->x
;
1027 GLfloat yoffset
= (GLfloat
) dPriv
->y
+ dPriv
->h
;
1028 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
1030 GLfloat tx
= v
[MAT_TX
] + xoffset
;
1031 GLfloat ty
= (-v
[MAT_TY
]) + yoffset
;
1033 if (rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] != r300PackFloat32(tx
) ||
1034 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] != r300PackFloat32(ty
)) {
1035 /* Note: this should also modify whatever data the context reset
1038 R300_STATECHANGE(rmesa
, vpt
);
1039 rmesa
->hw
.vpt
.cmd
[R300_VPT_XOFFSET
] = r300PackFloat32(tx
);
1040 rmesa
->hw
.vpt
.cmd
[R300_VPT_YOFFSET
] = r300PackFloat32(ty
);
1044 radeonUpdateScissor(ctx
);
1048 * Update R300's own internal state parameters.
1049 * For now just STATE_R300_WINDOW_DIMENSION
1051 static void r300UpdateStateParameters(GLcontext
* ctx
, GLuint new_state
)
1053 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1054 struct gl_program_parameter_list
*paramList
;
1056 if (!(new_state
& (_NEW_BUFFERS
| _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
)))
1059 if (!ctx
->FragmentProgram
._Current
|| !rmesa
->selected_fp
)
1062 paramList
= ctx
->FragmentProgram
._Current
->Base
.Parameters
;
1067 _mesa_load_state_parameters(ctx
, paramList
);
1070 /* =============================================================
1073 static void r300PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
)
1075 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1076 GLfloat constant
= units
;
1078 switch (ctx
->Visual
.depthBits
) {
1089 /* fprintf(stderr, "%s f:%f u:%f\n", __FUNCTION__, factor, constant); */
1091 R300_STATECHANGE(rmesa
, zbs
);
1092 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_FACTOR
] = r300PackFloat32(factor
);
1093 rmesa
->hw
.zbs
.cmd
[R300_ZBS_T_CONSTANT
] = r300PackFloat32(constant
);
1094 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_FACTOR
] = r300PackFloat32(factor
);
1095 rmesa
->hw
.zbs
.cmd
[R300_ZBS_W_CONSTANT
] = r300PackFloat32(constant
);
1098 /* Routing and texture-related */
1100 /* r300 doesnt handle GL_CLAMP and GL_MIRROR_CLAMP_EXT correctly when filter is NEAREST.
1101 * Since texwrap produces same results for GL_CLAMP and GL_CLAMP_TO_EDGE we use them instead.
1102 * We need to recalculate wrap modes whenever filter mode is changed because someone might do:
1103 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1104 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1105 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1106 * Since r300 completely ignores R300_TX_CLAMP when either min or mag is nearest it cant handle
1107 * combinations where only one of them is nearest.
1109 static unsigned long gen_fixed_filter(unsigned long f
)
1111 unsigned long mag
, min
, needs_fixing
= 0;
1114 /* We ignore MIRROR bit so we dont have to do everything twice */
1115 if ((f
& ((7 - 1) << R300_TX_WRAP_S_SHIFT
)) ==
1116 (R300_TX_CLAMP
<< R300_TX_WRAP_S_SHIFT
)) {
1119 if ((f
& ((7 - 1) << R300_TX_WRAP_T_SHIFT
)) ==
1120 (R300_TX_CLAMP
<< R300_TX_WRAP_T_SHIFT
)) {
1123 if ((f
& ((7 - 1) << R300_TX_WRAP_R_SHIFT
)) ==
1124 (R300_TX_CLAMP
<< R300_TX_WRAP_R_SHIFT
)) {
1131 mag
= f
& R300_TX_MAG_FILTER_MASK
;
1132 min
= f
& (R300_TX_MIN_FILTER_MASK
|R300_TX_MIN_FILTER_MIP_MASK
);
1134 /* TODO: Check for anisto filters too */
1135 if ((mag
!= R300_TX_MAG_FILTER_NEAREST
)
1136 && (min
!= R300_TX_MIN_FILTER_NEAREST
))
1139 /* r300 cant handle these modes hence we force nearest to linear */
1140 if ((mag
== R300_TX_MAG_FILTER_NEAREST
)
1141 && (min
!= R300_TX_MIN_FILTER_NEAREST
)) {
1142 f
&= ~R300_TX_MAG_FILTER_NEAREST
;
1143 f
|= R300_TX_MAG_FILTER_LINEAR
;
1147 if ((min
== R300_TX_MIN_FILTER_NEAREST
)
1148 && (mag
!= R300_TX_MAG_FILTER_NEAREST
)) {
1149 f
&= ~R300_TX_MIN_FILTER_NEAREST
;
1150 f
|= R300_TX_MIN_FILTER_LINEAR
;
1154 /* Both are nearest */
1155 if (needs_fixing
& 1) {
1156 f
&= ~((7 - 1) << R300_TX_WRAP_S_SHIFT
);
1157 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_S_SHIFT
;
1159 if (needs_fixing
& 2) {
1160 f
&= ~((7 - 1) << R300_TX_WRAP_T_SHIFT
);
1161 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_T_SHIFT
;
1163 if (needs_fixing
& 4) {
1164 f
&= ~((7 - 1) << R300_TX_WRAP_R_SHIFT
);
1165 f
|= R300_TX_CLAMP_TO_EDGE
<< R300_TX_WRAP_R_SHIFT
;
1170 static void r300SetupFragmentShaderTextures(GLcontext
*ctx
, int *tmu_mappings
)
1172 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1174 struct r300_fragment_program_code
*code
= &r300
->selected_fp
->code
.code
.r300
;
1176 R300_STATECHANGE(r300
, fpt
);
1178 for (i
= 0; i
< code
->tex
.length
; i
++) {
1183 unit
= code
->tex
.inst
[i
] >> R300_TEX_ID_SHIFT
;
1186 val
= code
->tex
.inst
[i
];
1187 val
&= ~R300_TEX_ID_MASK
;
1190 (val
& R300_TEX_INST_MASK
) >> R300_TEX_INST_SHIFT
;
1191 if (opcode
== R300_TEX_OP_KIL
) {
1192 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1194 if (tmu_mappings
[unit
] >= 0) {
1196 tmu_mappings
[unit
] <<
1198 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1200 // We get here when the corresponding texture image is incomplete
1201 // (e.g. incomplete mipmaps etc.)
1202 r300
->hw
.fpt
.cmd
[R300_FPT_INSTR_0
+ i
] = val
;
1207 r300
->hw
.fpt
.cmd
[R300_FPT_CMD_0
] =
1208 cmdpacket0(r300
->radeon
.radeonScreen
,
1209 R300_US_TEX_INST_0
, code
->tex
.length
);
1212 static void r500SetupFragmentShaderTextures(GLcontext
*ctx
, int *tmu_mappings
)
1214 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1216 struct r500_fragment_program_code
*code
= &r300
->selected_fp
->code
.code
.r500
;
1218 /* find all the texture instructions and relocate the texture units */
1219 for (i
= 0; i
< code
->inst_end
+ 1; i
++) {
1220 if ((code
->inst
[i
].inst0
& 0x3) == R500_INST_TYPE_TEX
) {
1222 int unit
, opcode
, new_unit
;
1224 val
= code
->inst
[i
].inst1
;
1226 unit
= (val
>> 16) & 0xf;
1228 val
&= ~(0xf << 16);
1230 opcode
= val
& (0x7 << 22);
1231 if (opcode
== R500_TEX_INST_TEXKILL
) {
1234 if (tmu_mappings
[unit
] >= 0) {
1235 new_unit
= tmu_mappings
[unit
];
1240 val
|= R500_TEX_ID(new_unit
);
1241 code
->inst
[i
].inst1
= val
;
1246 static GLuint
translate_lod_bias(GLfloat bias
)
1248 GLint b
= (int)(bias
*32);
1251 else if (b
< -(1 << 9))
1253 return (((GLuint
)b
) << R300_LOD_BIAS_SHIFT
) & R300_LOD_BIAS_MASK
;
1256 static void r300SetupTextures(GLcontext
* ctx
)
1259 struct radeon_tex_obj
*t
;
1260 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1262 int last_hw_tmu
= -1; /* -1 translates into no setup costs for fields */
1263 int tmu_mappings
[R300_MAX_TEXTURE_UNITS
] = { -1, };
1265 R300_STATECHANGE(r300
, txe
);
1266 R300_STATECHANGE(r300
, tex
.filter
);
1267 R300_STATECHANGE(r300
, tex
.filter_1
);
1268 R300_STATECHANGE(r300
, tex
.size
);
1269 R300_STATECHANGE(r300
, tex
.format
);
1270 R300_STATECHANGE(r300
, tex
.pitch
);
1271 R300_STATECHANGE(r300
, tex
.offset
);
1272 R300_STATECHANGE(r300
, tex
.chroma_key
);
1273 R300_STATECHANGE(r300
, tex
.border_color
);
1275 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] = 0x0;
1277 mtu
= r300
->radeon
.glCtx
->Const
.MaxTextureUnits
;
1278 if (RADEON_DEBUG
& DEBUG_STATE
)
1279 fprintf(stderr
, "mtu=%d\n", mtu
);
1281 if (mtu
> R300_MAX_TEXTURE_UNITS
) {
1283 "Aiiee ! mtu=%d is greater than R300_MAX_TEXTURE_UNITS=%d\n",
1284 mtu
, R300_MAX_TEXTURE_UNITS
);
1288 /* We cannot let disabled tmu offsets pass DRM */
1289 for (i
= 0; i
< mtu
; i
++) {
1290 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
1291 tmu_mappings
[i
] = hw_tmu
;
1293 t
= radeon_tex_obj(ctx
->Texture
.Unit
[i
]._Current
);
1297 if ((t
->pp_txformat
& 0xffffff00) == 0xffffff00) {
1299 ("unknown texture format (entry %x) encountered. Help me !\n",
1300 t
->pp_txformat
& 0xff);
1303 if (RADEON_DEBUG
& DEBUG_STATE
)
1305 "Activating texture unit %d\n", i
);
1307 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= (1 << hw_tmu
);
1309 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
+
1311 gen_fixed_filter(t
->pp_txfilter
) | (hw_tmu
<< 28);
1312 /* Note: There is a LOD bias per texture unit and a LOD bias
1313 * per texture object. We add them here to get the correct behaviour.
1314 * (The per-texture object LOD bias was introduced in OpenGL 1.4
1315 * and is not present in the EXT_texture_object extension).
1317 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1319 translate_lod_bias(ctx
->Texture
.Unit
[i
].LodBias
+ t
->base
.LodBias
);
1320 r300
->hw
.tex
.size
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1322 r300
->hw
.tex
.format
.cmd
[R300_TEX_VALUE_0
+
1323 hw_tmu
] = t
->pp_txformat
;
1324 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_VALUE_0
+ hw_tmu
] =
1326 r300
->hw
.textures
[hw_tmu
] = t
;
1328 if (t
->tile_bits
& R300_TXO_MACRO_TILE
) {
1329 WARN_ONCE("macro tiling enabled!\n");
1332 if (t
->tile_bits
& R300_TXO_MICRO_TILE
) {
1333 WARN_ONCE("micro tiling enabled!\n");
1336 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_VALUE_0
+
1338 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_VALUE_0
+
1342 last_hw_tmu
= hw_tmu
;
1348 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1349 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER0_0
, last_hw_tmu
+ 1);
1350 r300
->hw
.tex
.filter_1
.cmd
[R300_TEX_CMD_0
] =
1351 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER1_0
, last_hw_tmu
+ 1);
1352 r300
->hw
.tex
.size
.cmd
[R300_TEX_CMD_0
] =
1353 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_SIZE_0
, last_hw_tmu
+ 1);
1354 r300
->hw
.tex
.format
.cmd
[R300_TEX_CMD_0
] =
1355 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FORMAT_0
, last_hw_tmu
+ 1);
1356 r300
->hw
.tex
.pitch
.cmd
[R300_TEX_CMD_0
] =
1357 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FORMAT2_0
, last_hw_tmu
+ 1);
1358 r300
->hw
.tex
.offset
.cmd
[R300_TEX_CMD_0
] =
1359 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_OFFSET_0
, last_hw_tmu
+ 1);
1360 r300
->hw
.tex
.chroma_key
.cmd
[R300_TEX_CMD_0
] =
1361 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_CHROMA_KEY_0
, last_hw_tmu
+ 1);
1362 r300
->hw
.tex
.border_color
.cmd
[R300_TEX_CMD_0
] =
1363 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_BORDER_COLOR_0
, last_hw_tmu
+ 1);
1365 if (r300
->radeon
.radeonScreen
->chip_family
< CHIP_FAMILY_RV515
) {
1366 if (ctx
->FragmentProgram
._Current
->UsesKill
&& last_hw_tmu
< 0) {
1367 // The KILL operation requires the first texture unit
1369 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
] |= 1;
1370 r300
->hw
.tex
.filter
.cmd
[R300_TEX_VALUE_0
] = 0;
1371 r300
->hw
.tex
.filter
.cmd
[R300_TEX_CMD_0
] =
1372 cmdpacket0(r300
->radeon
.radeonScreen
, R300_TX_FILTER0_0
, 1);
1375 r300
->vtbl
.SetupFragmentShaderTextures(ctx
, tmu_mappings
);
1377 if (RADEON_DEBUG
& DEBUG_STATE
)
1378 fprintf(stderr
, "TX_ENABLE: %08x last_hw_tmu=%d\n",
1379 r300
->hw
.txe
.cmd
[R300_TXE_ENABLE
], last_hw_tmu
);
1382 union r300_outputs_written
{
1383 GLuint vp_outputs
; /* hw_tcl_on */
1384 DECLARE_RENDERINPUTS(index_bitset
); /* !hw_tcl_on */
1387 #define R300_OUTPUTS_WRITTEN_TEST(ow, vp_result, tnl_attrib) \
1388 ((hw_tcl_on) ? (ow).vp_outputs & (1 << (vp_result)) : \
1389 RENDERINPUTS_TEST( (ow.index_bitset), (tnl_attrib) ))
1391 static void r300SetupRSUnit(GLcontext
* ctx
)
1393 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1394 union r300_outputs_written OutputsWritten
;
1396 int fp_reg
, high_rr
;
1398 int rs_tex_count
= 0;
1399 int i
, col_fmt
, hw_tcl_on
;
1401 hw_tcl_on
= r300
->options
.hw_tcl_enabled
;
1404 OutputsWritten
.vp_outputs
= r300
->selected_vp
->code
.OutputsWritten
;
1406 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->render_inputs_bitset
);
1408 InputsRead
= r300
->selected_fp
->InputsRead
;
1410 R300_STATECHANGE(r300
, ri
);
1411 R300_STATECHANGE(r300
, rc
);
1412 R300_STATECHANGE(r300
, rr
);
1414 fp_reg
= col_ip
= tex_ip
= col_fmt
= 0;
1416 r300
->hw
.rc
.cmd
[1] = 0;
1417 r300
->hw
.rc
.cmd
[2] = 0;
1418 for (i
=0; i
<R300_RR_CMDSIZE
-1; ++i
)
1419 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ i
] = 0;
1421 for (i
=0; i
<R300_RI_CMDSIZE
-1; ++i
)
1422 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0;
1425 if (InputsRead
& FRAG_BIT_COL0
) {
1426 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1427 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
);
1428 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
);
1429 InputsRead
&= ~FRAG_BIT_COL0
;
1433 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1437 if (InputsRead
& FRAG_BIT_COL1
) {
1438 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1439 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
);
1440 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
);
1441 InputsRead
&= ~FRAG_BIT_COL1
;
1445 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1449 /* We always route 4 texcoord components */
1450 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1451 if (! ( InputsRead
& FRAG_BIT_TEX(i
) ) )
1454 if (!R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1455 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1459 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
);
1460 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
);
1461 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1467 /* Setup default color if no color or tex was set */
1468 if (rs_tex_count
== 0 && col_ip
== 0) {
1469 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] = R300_RS_INST_COL_ID(0) | R300_RS_INST_COL_ADDR(0);
1470 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
] = R300_RS_COL_PTR(0) | R300_RS_COL_FMT(R300_RS_COL_FMT_0001
);
1474 high_rr
= (col_ip
> tex_ip
) ? col_ip
: tex_ip
;
1475 r300
->hw
.rc
.cmd
[1] |= (rs_tex_count
<< R300_IT_COUNT_SHIFT
) | (col_ip
<< R300_IC_COUNT_SHIFT
) | R300_HIRES_EN
;
1476 r300
->hw
.rc
.cmd
[2] |= high_rr
- 1;
1478 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R300_RS_INST_0
, high_rr
);
1479 r300
->hw
.ri
.cmd
[R300_RI_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R300_RS_IP_0
, high_rr
);
1482 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1485 static void r500SetupRSUnit(GLcontext
* ctx
)
1487 r300ContextPtr r300
= R300_CONTEXT(ctx
);
1488 union r300_outputs_written OutputsWritten
;
1490 int fp_reg
, high_rr
;
1492 int rs_tex_count
= 0;
1493 int i
, col_fmt
, hw_tcl_on
;
1495 hw_tcl_on
= r300
->options
.hw_tcl_enabled
;
1498 OutputsWritten
.vp_outputs
= r300
->selected_vp
->code
.OutputsWritten
;
1500 RENDERINPUTS_COPY(OutputsWritten
.index_bitset
, r300
->render_inputs_bitset
);
1502 InputsRead
= r300
->selected_fp
->InputsRead
;
1504 R300_STATECHANGE(r300
, ri
);
1505 R300_STATECHANGE(r300
, rc
);
1506 R300_STATECHANGE(r300
, rr
);
1508 fp_reg
= col_ip
= tex_ip
= col_fmt
= 0;
1510 r300
->hw
.rc
.cmd
[1] = 0;
1511 r300
->hw
.rc
.cmd
[2] = 0;
1512 for (i
=0; i
<R300_RR_CMDSIZE
-1; ++i
)
1513 r300
->hw
.rr
.cmd
[R300_RR_INST_0
+ i
] = 0;
1515 for (i
=0; i
<R500_RI_CMDSIZE
-1; ++i
)
1516 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ i
] = 0;
1519 if (InputsRead
& FRAG_BIT_COL0
) {
1520 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL0
, _TNL_ATTRIB_COLOR0
)) {
1521 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
);
1522 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
);
1523 InputsRead
&= ~FRAG_BIT_COL0
;
1527 WARN_ONCE("fragprog wants col0, vp doesn't provide it\n");
1531 if (InputsRead
& FRAG_BIT_COL1
) {
1532 if (R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_COL1
, _TNL_ATTRIB_COLOR1
)) {
1533 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
);
1534 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
);
1535 InputsRead
&= ~FRAG_BIT_COL1
;
1539 WARN_ONCE("fragprog wants col1, vp doesn't provide it\n");
1543 /* We always route 4 texcoord components */
1544 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
1545 if (! ( InputsRead
& FRAG_BIT_TEX(i
) ) )
1548 if (!R300_OUTPUTS_WRITTEN_TEST(OutputsWritten
, VERT_RESULT_TEX0
+ i
, _TNL_ATTRIB_TEX(i
))) {
1549 WARN_ONCE("fragprog wants coords for tex%d, vp doesn't provide them!\n", i
);
1553 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
+ tex_ip
] |= ((rs_tex_count
+ 0) << R500_RS_IP_TEX_PTR_S_SHIFT
) |
1554 ((rs_tex_count
+ 1) << R500_RS_IP_TEX_PTR_T_SHIFT
) |
1555 ((rs_tex_count
+ 2) << R500_RS_IP_TEX_PTR_R_SHIFT
) |
1556 ((rs_tex_count
+ 3) << R500_RS_IP_TEX_PTR_Q_SHIFT
);
1558 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
);
1559 InputsRead
&= ~(FRAG_BIT_TEX0
<< i
);
1565 /* Setup default color if no color or tex was set */
1566 if (rs_tex_count
== 0 && col_ip
== 0) {
1567 r300
->hw
.rr
.cmd
[R300_RR_INST_0
] = R500_RS_INST_COL_ID(0) | R500_RS_INST_COL_ADDR(0);
1568 r300
->hw
.ri
.cmd
[R300_RI_INTERP_0
] = R500_RS_COL_PTR(0) | R500_RS_COL_FMT(R300_RS_COL_FMT_0001
);
1572 high_rr
= (col_ip
> tex_ip
) ? col_ip
: tex_ip
;
1573 r300
->hw
.rc
.cmd
[1] = (rs_tex_count
<< R300_IT_COUNT_SHIFT
) | (col_ip
<< R300_IC_COUNT_SHIFT
) | R300_HIRES_EN
;
1574 r300
->hw
.rc
.cmd
[2] = 0xC0 | (high_rr
- 1);
1576 r300
->hw
.rr
.cmd
[R300_RR_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R500_RS_INST_0
, high_rr
);
1577 r300
->hw
.ri
.cmd
[R300_RI_CMD_0
] = cmdpacket0(r300
->radeon
.radeonScreen
, R500_RS_IP_0
, high_rr
);
1580 WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead
);
1583 #define MIN3(a, b, c) ((a) < (b) ? MIN2(a, c) : MIN2(b, c))
1585 void r300VapCntl(r300ContextPtr rmesa
, GLuint input_count
,
1586 GLuint output_count
, GLuint temp_count
)
1592 /* Flush PVS engine before changing PVS_NUM_SLOTS, PVS_NUM_CNTRLS.
1593 * See r500 docs 6.5.2 - done in emit */
1595 /* avoid division by zero */
1596 if (input_count
== 0) input_count
= 1;
1597 if (output_count
== 0) output_count
= 1;
1598 if (temp_count
== 0) temp_count
= 1;
1600 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
1605 pvs_num_slots
= MIN3(10, vtx_mem_size
/input_count
, vtx_mem_size
/output_count
);
1606 pvs_num_cntrls
= MIN2(6, vtx_mem_size
/temp_count
);
1608 R300_STATECHANGE(rmesa
, vap_cntl
);
1609 if (rmesa
->options
.hw_tcl_enabled
) {
1610 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] =
1611 (pvs_num_slots
<< R300_PVS_NUM_SLOTS_SHIFT
) |
1612 (pvs_num_cntrls
<< R300_PVS_NUM_CNTLRS_SHIFT
) |
1613 (12 << R300_VF_MAX_VTX_NUM_SHIFT
);
1614 if (rmesa
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
)
1615 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= R500_TCL_STATE_OPTIMIZATION
;
1617 /* not sure about non-tcl */
1618 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] = ((10 << R300_PVS_NUM_SLOTS_SHIFT
) |
1619 (5 << R300_PVS_NUM_CNTLRS_SHIFT
) |
1620 (5 << R300_VF_MAX_VTX_NUM_SHIFT
));
1622 if (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV515
)
1623 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (2 << R300_PVS_NUM_FPUS_SHIFT
);
1624 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV530
) ||
1625 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV560
) ||
1626 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV570
))
1627 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (5 << R300_PVS_NUM_FPUS_SHIFT
);
1628 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_RV410
) ||
1629 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R420
))
1630 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (6 << R300_PVS_NUM_FPUS_SHIFT
);
1631 else if ((rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R520
) ||
1632 (rmesa
->radeon
.radeonScreen
->chip_family
== CHIP_FAMILY_R580
))
1633 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (8 << R300_PVS_NUM_FPUS_SHIFT
);
1635 rmesa
->hw
.vap_cntl
.cmd
[R300_VAP_CNTL_INSTR
] |= (4 << R300_PVS_NUM_FPUS_SHIFT
);
1640 * Enable/Disable states.
1642 * \note Mesa already filters redundant calls to this function.
1644 static void r300Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
1646 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1647 if (RADEON_DEBUG
& DEBUG_STATE
)
1648 fprintf(stderr
, "%s( %s = %s )\n", __FUNCTION__
,
1649 _mesa_lookup_enum_by_nr(cap
),
1650 state
? "GL_TRUE" : "GL_FALSE");
1654 r300SetAlphaState(ctx
);
1656 case GL_COLOR_LOGIC_OP
:
1657 r300SetLogicOpState(ctx
);
1658 /* fall-through, because logic op overrides blending */
1660 r300SetBlendState(ctx
);
1662 case GL_CLIP_PLANE0
:
1663 case GL_CLIP_PLANE1
:
1664 case GL_CLIP_PLANE2
:
1665 case GL_CLIP_PLANE3
:
1666 case GL_CLIP_PLANE4
:
1667 case GL_CLIP_PLANE5
:
1668 r300SetClipPlaneState(ctx
, cap
, state
);
1671 r300UpdateCulling(ctx
);
1674 r300SetDepthState(ctx
);
1676 case GL_LINE_SMOOTH
:
1677 if (rmesa
->options
.conformance_mode
)
1678 r300SwitchFallback(ctx
, R300_FALLBACK_LINE_SMOOTH
, ctx
->Line
.SmoothFlag
);
1680 case GL_LINE_STIPPLE
:
1681 if (rmesa
->options
.conformance_mode
)
1682 r300SwitchFallback(ctx
, R300_FALLBACK_LINE_STIPPLE
, ctx
->Line
.StippleFlag
);
1684 case GL_POINT_SMOOTH
:
1685 if (rmesa
->options
.conformance_mode
)
1686 r300SwitchFallback(ctx
, R300_FALLBACK_POINT_SMOOTH
, ctx
->Point
.SmoothFlag
);
1688 case GL_POLYGON_SMOOTH
:
1689 if (rmesa
->options
.conformance_mode
)
1690 r300SwitchFallback(ctx
, R300_FALLBACK_POLYGON_SMOOTH
, ctx
->Polygon
.SmoothFlag
);
1692 case GL_POLYGON_STIPPLE
:
1693 if (rmesa
->options
.conformance_mode
)
1694 r300SwitchFallback(ctx
, R300_FALLBACK_POLYGON_STIPPLE
, ctx
->Polygon
.StippleFlag
);
1696 case GL_POLYGON_OFFSET_POINT
:
1697 case GL_POLYGON_OFFSET_LINE
:
1698 case GL_POLYGON_OFFSET_FILL
:
1699 r300SetPolygonOffsetState(ctx
, state
);
1701 case GL_SCISSOR_TEST
:
1702 radeon_firevertices(&rmesa
->radeon
);
1703 rmesa
->radeon
.state
.scissor
.enabled
= state
;
1704 radeonUpdateScissor( ctx
);
1706 case GL_STENCIL_TEST
:
1707 r300SetStencilState(ctx
, state
);
1715 * Completely recalculates hardware state based on the Mesa state.
1717 static void r300ResetHwState(r300ContextPtr r300
)
1719 GLcontext
*ctx
= r300
->radeon
.glCtx
;
1722 has_tcl
= r300
->options
.hw_tcl_enabled
;
1724 if (RADEON_DEBUG
& DEBUG_STATE
)
1725 fprintf(stderr
, "%s\n", __FUNCTION__
);
1727 radeon_firevertices(&r300
->radeon
);
1730 ctx
->Color
.ColorMask
[RCOMP
],
1731 ctx
->Color
.ColorMask
[GCOMP
],
1732 ctx
->Color
.ColorMask
[BCOMP
], ctx
->Color
.ColorMask
[ACOMP
]);
1734 r300Enable(ctx
, GL_DEPTH_TEST
, ctx
->Depth
.Test
);
1735 r300DepthMask(ctx
, ctx
->Depth
.Mask
);
1736 r300DepthFunc(ctx
, ctx
->Depth
.Func
);
1739 r300Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
._Enabled
);
1740 r300StencilMaskSeparate(ctx
, 0, ctx
->Stencil
.WriteMask
[0]);
1741 r300StencilFuncSeparate(ctx
, 0, ctx
->Stencil
.Function
[0],
1742 ctx
->Stencil
.Ref
[0], ctx
->Stencil
.ValueMask
[0]);
1743 r300StencilOpSeparate(ctx
, 0, ctx
->Stencil
.FailFunc
[0],
1744 ctx
->Stencil
.ZFailFunc
[0],
1745 ctx
->Stencil
.ZPassFunc
[0]);
1747 r300UpdateCulling(ctx
);
1749 r300SetBlendState(ctx
);
1750 r300SetLogicOpState(ctx
);
1752 r300AlphaFunc(ctx
, ctx
->Color
.AlphaFunc
, ctx
->Color
.AlphaRef
);
1753 r300Enable(ctx
, GL_ALPHA_TEST
, ctx
->Color
.AlphaEnabled
);
1755 r300
->hw
.vte
.cmd
[1] = R300_VPORT_X_SCALE_ENA
1756 | R300_VPORT_X_OFFSET_ENA
1757 | R300_VPORT_Y_SCALE_ENA
1758 | R300_VPORT_Y_OFFSET_ENA
1759 | R300_VPORT_Z_SCALE_ENA
1760 | R300_VPORT_Z_OFFSET_ENA
| R300_VTX_W0_FMT
;
1761 r300
->hw
.vte
.cmd
[2] = 0x00000008;
1763 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[1] = 0x00FFFFFF;
1764 r300
->hw
.vap_vf_max_vtx_indx
.cmd
[2] = 0x00000000;
1766 #ifdef MESA_LITTLE_ENDIAN
1767 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_NO_SWAP
;
1769 r300
->hw
.vap_cntl_status
.cmd
[1] = R300_VC_32BIT_SWAP
;
1772 /* disable VAP/TCL on non-TCL capable chips */
1774 r300
->hw
.vap_cntl_status
.cmd
[1] |= R300_VAP_TCL_BYPASS
;
1776 r300
->hw
.vap_psc_sgn_norm_cntl
.cmd
[1] = 0xAAAAAAAA;
1778 /* XXX: Other families? */
1780 r300
->hw
.vap_clip_cntl
.cmd
[1] = R300_PS_UCP_MODE_DIST_COP
;
1782 r300
->hw
.vap_clip
.cmd
[1] = r300PackFloat32(1.0); /* X */
1783 r300
->hw
.vap_clip
.cmd
[2] = r300PackFloat32(1.0); /* X */
1784 r300
->hw
.vap_clip
.cmd
[3] = r300PackFloat32(1.0); /* Y */
1785 r300
->hw
.vap_clip
.cmd
[4] = r300PackFloat32(1.0); /* Y */
1787 switch (r300
->radeon
.radeonScreen
->chip_family
) {
1788 case CHIP_FAMILY_R300
:
1789 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_R300
;
1792 r300
->hw
.vap_pvs_vtx_timeout_reg
.cmd
[1] = R300_2288_RV350
;
1797 r300
->hw
.gb_enable
.cmd
[1] = R300_GB_POINT_STUFF_ENABLE
1798 | R300_GB_LINE_STUFF_ENABLE
1799 | R300_GB_TRIANGLE_STUFF_ENABLE
;
1801 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_0
] = 0x66666666;
1802 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_MSPOS_1
] = 0x06666666;
1804 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] =
1805 R300_GB_TILE_ENABLE
| R300_GB_TILE_SIZE_16
/*| R300_GB_SUBPIXEL_1_16*/;
1806 switch (r300
->radeon
.radeonScreen
->num_gb_pipes
) {
1809 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1810 R300_GB_TILE_PIPE_COUNT_RV300
;
1813 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1814 R300_GB_TILE_PIPE_COUNT_R300
;
1817 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1818 R300_GB_TILE_PIPE_COUNT_R420_3P
;
1821 r300
->hw
.gb_misc
.cmd
[R300_GB_MISC_TILE_CONFIG
] |=
1822 R300_GB_TILE_PIPE_COUNT_R420
;
1826 /* XXX: Enable anti-aliasing? */
1827 r300
->hw
.gb_misc2
.cmd
[R300_GB_MISC2_AA_CONFIG
] = GB_AA_CONFIG_AA_DISABLE
;
1828 r300
->hw
.gb_misc2
.cmd
[R300_GB_MISC2_SELECT
] = 0;
1830 r300
->hw
.ga_point_s0
.cmd
[1] = r300PackFloat32(0.0);
1831 r300
->hw
.ga_point_s0
.cmd
[2] = r300PackFloat32(0.0);
1832 r300
->hw
.ga_point_s0
.cmd
[3] = r300PackFloat32(1.0);
1833 r300
->hw
.ga_point_s0
.cmd
[4] = r300PackFloat32(1.0);
1835 r300
->hw
.ga_triangle_stipple
.cmd
[1] = 0x00050005;
1837 r300PointSize(ctx
, 1.0);
1839 r300
->hw
.ga_point_minmax
.cmd
[1] = 0x18000006;
1840 r300
->hw
.ga_point_minmax
.cmd
[2] = 0x00020006;
1841 r300
->hw
.ga_point_minmax
.cmd
[3] = r300PackFloat32(1.0 / 192.0);
1843 r300LineWidth(ctx
, 1.0);
1845 r300
->hw
.ga_line_stipple
.cmd
[1] = 0;
1846 r300
->hw
.ga_line_stipple
.cmd
[2] = r300PackFloat32(0.0);
1847 r300
->hw
.ga_line_stipple
.cmd
[3] = r300PackFloat32(1.0);
1849 r300ShadeModel(ctx
, ctx
->Light
.ShadeModel
);
1851 r300PolygonMode(ctx
, GL_FRONT
, ctx
->Polygon
.FrontMode
);
1852 r300PolygonMode(ctx
, GL_BACK
, ctx
->Polygon
.BackMode
);
1853 r300
->hw
.zbias_cntl
.cmd
[1] = 0x00000000;
1855 r300PolygonOffset(ctx
, ctx
->Polygon
.OffsetFactor
,
1856 ctx
->Polygon
.OffsetUnits
);
1857 r300Enable(ctx
, GL_POLYGON_OFFSET_POINT
, ctx
->Polygon
.OffsetPoint
);
1858 r300Enable(ctx
, GL_POLYGON_OFFSET_LINE
, ctx
->Polygon
.OffsetLine
);
1859 r300Enable(ctx
, GL_POLYGON_OFFSET_FILL
, ctx
->Polygon
.OffsetFill
);
1861 r300
->hw
.su_depth_scale
.cmd
[1] = 0x4B7FFFFF;
1862 r300
->hw
.su_depth_scale
.cmd
[2] = 0x00000000;
1864 r300
->hw
.sc_hyperz
.cmd
[1] = 0x0000001C;
1865 r300
->hw
.sc_hyperz
.cmd
[2] = 0x2DA49525;
1867 r300
->hw
.sc_screendoor
.cmd
[1] = 0x00FFFFFF;
1869 r300
->hw
.us_out_fmt
.cmd
[1] = R500_OUT_FMT_C4_8
|
1870 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1871 r300
->hw
.us_out_fmt
.cmd
[2] = R500_OUT_FMT_UNUSED
|
1872 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1873 r300
->hw
.us_out_fmt
.cmd
[3] = R500_OUT_FMT_UNUSED
|
1874 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1875 r300
->hw
.us_out_fmt
.cmd
[4] = R500_OUT_FMT_UNUSED
|
1876 R500_C0_SEL_B
| R500_C1_SEL_G
| R500_C2_SEL_R
| R500_C3_SEL_A
;
1877 r300
->hw
.us_out_fmt
.cmd
[5] = R300_W_FMT_W0
| R300_W_SRC_US
;
1879 /* disable fog unit */
1880 r300
->hw
.fogs
.cmd
[R300_FOGS_STATE
] = 0;
1881 r300
->hw
.fg_depth_src
.cmd
[1] = R300_FG_DEPTH_SRC_SCAN
;
1883 r300
->hw
.rb3d_cctl
.cmd
[1] = 0;
1885 r300BlendColor(ctx
, ctx
->Color
.BlendColor
);
1887 r300
->hw
.rb3d_dither_ctl
.cmd
[1] = 0;
1888 r300
->hw
.rb3d_dither_ctl
.cmd
[2] = 0;
1889 r300
->hw
.rb3d_dither_ctl
.cmd
[3] = 0;
1890 r300
->hw
.rb3d_dither_ctl
.cmd
[4] = 0;
1891 r300
->hw
.rb3d_dither_ctl
.cmd
[5] = 0;
1892 r300
->hw
.rb3d_dither_ctl
.cmd
[6] = 0;
1893 r300
->hw
.rb3d_dither_ctl
.cmd
[7] = 0;
1894 r300
->hw
.rb3d_dither_ctl
.cmd
[8] = 0;
1895 r300
->hw
.rb3d_dither_ctl
.cmd
[9] = 0;
1897 r300
->hw
.rb3d_aaresolve_ctl
.cmd
[1] = 0;
1899 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[1] = 0x00000000;
1900 r300
->hw
.rb3d_discard_src_pixel_lte_threshold
.cmd
[2] = 0xffffffff;
1902 r300
->hw
.zb_depthclearvalue
.cmd
[1] = 0;
1904 r300
->hw
.zstencil_format
.cmd
[2] = R300_ZTOP_DISABLE
;
1905 r300
->hw
.zstencil_format
.cmd
[3] = 0x00000003;
1906 r300
->hw
.zstencil_format
.cmd
[4] = 0x00000000;
1907 r300SetEarlyZState(ctx
);
1909 r300
->hw
.zb_zmask
.cmd
[1] = 0;
1910 r300
->hw
.zb_zmask
.cmd
[2] = 0;
1912 r300
->hw
.zb_hiz_offset
.cmd
[1] = 0;
1914 r300
->hw
.zb_hiz_pitch
.cmd
[1] = 0;
1916 r300VapCntl(r300
, 0, 0, 0);
1918 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_0
] = 0;
1919 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_1
] = 0;
1920 r300
->hw
.vps
.cmd
[R300_VPS_POINTSIZE
] = r300PackFloat32(1.0);
1921 r300
->hw
.vps
.cmd
[R300_VPS_ZERO_3
] = 0;
1924 r300
->radeon
.hw
.all_dirty
= GL_TRUE
;
1927 void r300UpdateShaders(r300ContextPtr rmesa
)
1929 GLcontext
*ctx
= rmesa
->radeon
.glCtx
;
1931 /* should only happenen once, just after context is created */
1932 /* TODO: shouldn't we fallback to sw here? */
1933 if (!ctx
->FragmentProgram
._Current
) {
1934 _mesa_fprintf(stderr
, "No ctx->FragmentProgram._Current!!\n");
1939 struct r300_fragment_program
*fp
;
1941 fp
= r300SelectAndTranslateFragmentShader(ctx
);
1943 r300SwitchFallback(ctx
, R300_FALLBACK_FRAGMENT_PROGRAM
, fp
->error
);
1946 if (rmesa
->options
.hw_tcl_enabled
) {
1947 struct r300_vertex_program
*vp
;
1949 if (rmesa
->radeon
.NewGLState
) {
1951 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
1952 rmesa
->temp_attrib
[i
] =
1953 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
1954 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
1955 &rmesa
->dummy_attrib
[i
];
1958 _tnl_UpdateFixedFunctionProgram(ctx
);
1960 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++) {
1961 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] =
1962 rmesa
->temp_attrib
[i
];
1966 vp
= r300SelectAndTranslateVertexShader(ctx
);
1968 r300SwitchFallback(ctx
, R300_FALLBACK_VERTEX_PROGRAM
, vp
->error
);
1971 r300UpdateStateParameters(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
1972 rmesa
->radeon
.NewGLState
= 0;
1975 static const GLfloat
*get_fragmentprogram_constant(GLcontext
*ctx
, GLuint index
, GLfloat
* buffer
)
1977 static const GLfloat dummy
[4] = { 0, 0, 0, 0 };
1978 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
1979 struct rc_constant
* rcc
= &rmesa
->selected_fp
->code
.constants
.Constants
[index
];
1982 case RC_CONSTANT_EXTERNAL
:
1983 return ctx
->FragmentProgram
._Current
->Base
.Parameters
->ParameterValues
[rcc
->u
.External
];
1984 case RC_CONSTANT_IMMEDIATE
:
1985 return rcc
->u
.Immediate
;
1986 case RC_CONSTANT_STATE
:
1987 switch(rcc
->u
.State
[0]) {
1988 case RC_STATE_SHADOW_AMBIENT
: {
1989 const int unit
= (int) rcc
->u
.State
[1];
1990 const struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[unit
]._Current
;
1995 buffer
[3] = texObj
->CompareFailValue
;
2000 case RC_STATE_R300_WINDOW_DIMENSION
: {
2001 __DRIdrawablePrivate
* drawable
= radeon_get_drawable(&rmesa
->radeon
);
2002 buffer
[0] = drawable
->w
* 0.5f
; /* width*0.5 */
2003 buffer
[1] = drawable
->h
* 0.5f
; /* height*0.5 */
2004 buffer
[2] = 0.5F
; /* for moving range [-1 1] -> [0 1] */
2005 buffer
[3] = 1.0F
; /* not used */
2009 case RC_STATE_R300_TEXRECT_FACTOR
: {
2010 struct gl_texture_object
*t
=
2011 ctx
->Texture
.Unit
[rcc
->u
.State
[1]].CurrentTex
[TEXTURE_RECT_INDEX
];
2013 if (t
&& t
->Image
[0][t
->BaseLevel
]) {
2014 struct gl_texture_image
*image
=
2015 t
->Image
[0][t
->BaseLevel
];
2016 buffer
[0] = 1.0 / image
->Width2
;
2017 buffer
[1] = 1.0 / image
->Height2
;
2033 static void r300SetupPixelShader(GLcontext
*ctx
)
2035 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2036 struct r300_fragment_program
*fp
= rmesa
->selected_fp
;
2037 struct r300_fragment_program_code
*code
;
2040 code
= &fp
->code
.code
.r300
;
2042 R300_STATECHANGE(rmesa
, fpi
[0]);
2043 R300_STATECHANGE(rmesa
, fpi
[1]);
2044 R300_STATECHANGE(rmesa
, fpi
[2]);
2045 R300_STATECHANGE(rmesa
, fpi
[3]);
2046 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_RGB_INST_0
, code
->alu
.length
);
2047 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_RGB_ADDR_0
, code
->alu
.length
);
2048 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_ALPHA_INST_0
, code
->alu
.length
);
2049 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_US_ALU_ALPHA_ADDR_0
, code
->alu
.length
);
2050 for (i
= 0; i
< code
->alu
.length
; i
++) {
2051 rmesa
->hw
.fpi
[0].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].rgb_inst
;
2052 rmesa
->hw
.fpi
[1].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].rgb_addr
;
2053 rmesa
->hw
.fpi
[2].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].alpha_inst
;
2054 rmesa
->hw
.fpi
[3].cmd
[R300_FPI_INSTR_0
+ i
] = code
->alu
.inst
[i
].alpha_addr
;
2057 R300_STATECHANGE(rmesa
, fp
);
2058 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL0
] = code
->config
;
2059 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL1
] = code
->pixsize
;
2060 rmesa
->hw
.fp
.cmd
[R300_FP_CNTL2
] = code
->code_offset
;
2061 for (i
= 0; i
< 4; i
++)
2062 rmesa
->hw
.fp
.cmd
[R300_FP_NODE0
+ i
] = code
->code_addr
[i
];
2064 R300_STATECHANGE(rmesa
, fpp
);
2065 rmesa
->hw
.fpp
.cmd
[R300_FPP_CMD_0
] = cmdpacket0(rmesa
->radeon
.radeonScreen
, R300_PFS_PARAM_0_X
, fp
->code
.constants
.Count
* 4);
2066 for (i
= 0; i
< fp
->code
.constants
.Count
; i
++) {
2068 const GLfloat
*constant
= get_fragmentprogram_constant(ctx
, i
, buffer
);
2069 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat24(constant
[0]);
2070 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat24(constant
[1]);
2071 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat24(constant
[2]);
2072 rmesa
->hw
.fpp
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat24(constant
[3]);
2076 #define bump_r500fp_count(ptr, new_count) do{\
2077 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2078 int _nc=(new_count)/6; \
2079 assert(_nc < 256); \
2080 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2083 #define bump_r500fp_const_count(ptr, new_count) do{\
2084 drm_r300_cmd_header_t* _p=((drm_r300_cmd_header_t*)(ptr));\
2085 int _nc=(new_count)/4; \
2086 assert(_nc < 256); \
2087 if(_nc>_p->r500fp.count)_p->r500fp.count=_nc;\
2090 static void r500SetupPixelShader(GLcontext
*ctx
)
2092 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
2093 struct r300_fragment_program
*fp
= rmesa
->selected_fp
;
2095 struct r500_fragment_program_code
*code
;
2097 ((drm_r300_cmd_header_t
*) rmesa
->hw
.r500fp
.cmd
)->r500fp
.count
= 0;
2098 ((drm_r300_cmd_header_t
*) rmesa
->hw
.r500fp_const
.cmd
)->r500fp
.count
= 0;
2100 code
= &fp
->code
.code
.r500
;
2102 R300_STATECHANGE(rmesa
, fp
);
2103 rmesa
->hw
.fp
.cmd
[R500_FP_PIXSIZE
] = code
->max_temp_idx
;
2105 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_ADDR
] =
2106 R500_US_CODE_START_ADDR(0) |
2107 R500_US_CODE_END_ADDR(code
->inst_end
);
2108 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_RANGE
] =
2109 R500_US_CODE_RANGE_ADDR(0) |
2110 R500_US_CODE_RANGE_SIZE(code
->inst_end
);
2111 rmesa
->hw
.fp
.cmd
[R500_FP_CODE_OFFSET
] =
2112 R500_US_CODE_OFFSET_ADDR(0);
2114 R300_STATECHANGE(rmesa
, r500fp
);
2115 /* Emit our shader... */
2116 for (i
= 0; i
< code
->inst_end
+1; i
++) {
2117 rmesa
->hw
.r500fp
.cmd
[i
*6+1] = code
->inst
[i
].inst0
;
2118 rmesa
->hw
.r500fp
.cmd
[i
*6+2] = code
->inst
[i
].inst1
;
2119 rmesa
->hw
.r500fp
.cmd
[i
*6+3] = code
->inst
[i
].inst2
;
2120 rmesa
->hw
.r500fp
.cmd
[i
*6+4] = code
->inst
[i
].inst3
;
2121 rmesa
->hw
.r500fp
.cmd
[i
*6+5] = code
->inst
[i
].inst4
;
2122 rmesa
->hw
.r500fp
.cmd
[i
*6+6] = code
->inst
[i
].inst5
;
2125 bump_r500fp_count(rmesa
->hw
.r500fp
.cmd
, (code
->inst_end
+ 1) * 6);
2127 R300_STATECHANGE(rmesa
, r500fp_const
);
2128 for (i
= 0; i
< fp
->code
.constants
.Count
; i
++) {
2130 const GLfloat
*constant
= get_fragmentprogram_constant(ctx
, i
, buffer
);
2131 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 0] = r300PackFloat32(constant
[0]);
2132 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 1] = r300PackFloat32(constant
[1]);
2133 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 2] = r300PackFloat32(constant
[2]);
2134 rmesa
->hw
.r500fp_const
.cmd
[R300_FPP_PARAM_0
+ 4 * i
+ 3] = r300PackFloat32(constant
[3]);
2136 bump_r500fp_const_count(rmesa
->hw
.r500fp_const
.cmd
, fp
->code
.constants
.Count
* 4);
2139 void r300SetupVAP(GLcontext
*ctx
, GLuint InputsRead
, GLuint OutputsWritten
)
2141 r300ContextPtr rmesa
= R300_CONTEXT( ctx
);
2142 struct vertex_attribute
*attrs
= rmesa
->vbuf
.attribs
;
2143 int i
, j
, reg_count
;
2144 uint32_t *vir0
= &rmesa
->hw
.vir
[0].cmd
[1];
2145 uint32_t *vir1
= &rmesa
->hw
.vir
[1].cmd
[1];
2147 for (i
= 0; i
< R300_VIR_CMDSIZE
-1; ++i
)
2148 vir0
[i
] = vir1
[i
] = 0;
2150 for (i
= 0, j
= 0; i
< rmesa
->vbuf
.num_attribs
; ++i
) {
2153 tmp
= attrs
[i
].data_type
| (attrs
[i
].dst_loc
<< R300_DST_VEC_LOC_SHIFT
);
2154 if (attrs
[i
]._signed
)
2156 if (attrs
[i
].normalize
)
2157 tmp
|= R300_NORMALIZE
;
2160 vir0
[j
] = tmp
<< R300_DATA_TYPE_0_SHIFT
;
2161 vir1
[j
] = attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
);
2163 vir0
[j
] |= tmp
<< R300_DATA_TYPE_1_SHIFT
;
2164 vir1
[j
] |= (attrs
[i
].swizzle
| (attrs
[i
].write_mask
<< R300_WRITE_ENA_SHIFT
)) << R300_SWIZZLE1_SHIFT
;
2169 reg_count
= (rmesa
->vbuf
.num_attribs
+ 1) >> 1;
2170 if (rmesa
->vbuf
.num_attribs
% 2 != 0) {
2171 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_0_SHIFT
;
2173 vir0
[reg_count
-1] |= R300_LAST_VEC
<< R300_DATA_TYPE_1_SHIFT
;
2176 R300_STATECHANGE(rmesa
, vir
[0]);
2177 R300_STATECHANGE(rmesa
, vir
[1]);
2178 R300_STATECHANGE(rmesa
, vof
);
2179 R300_STATECHANGE(rmesa
, vic
);
2181 if (rmesa
->radeon
.radeonScreen
->kernel_mm
) {
2182 rmesa
->hw
.vir
[0].cmd
[0] &= 0xC000FFFF;
2183 rmesa
->hw
.vir
[1].cmd
[0] &= 0xC000FFFF;
2184 rmesa
->hw
.vir
[0].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
2185 rmesa
->hw
.vir
[1].cmd
[0] |= (reg_count
& 0x3FFF) << 16;
2187 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[0].cmd
)->packet0
.count
= reg_count
;
2188 ((drm_r300_cmd_header_t
*) rmesa
->hw
.vir
[1].cmd
)->packet0
.count
= reg_count
;
2191 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_0
] = r300VAPInputCntl0(ctx
, InputsRead
);
2192 rmesa
->hw
.vic
.cmd
[R300_VIC_CNTL_1
] = r300VAPInputCntl1(ctx
, InputsRead
);
2193 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_0
] = r300VAPOutputCntl0(ctx
, OutputsWritten
);
2194 rmesa
->hw
.vof
.cmd
[R300_VOF_CNTL_1
] = r300VAPOutputCntl1(ctx
, OutputsWritten
);
2197 void r300UpdateShaderStates(r300ContextPtr rmesa
)
2200 ctx
= rmesa
->radeon
.glCtx
;
2202 /* should only happenen once, just after context is created */
2203 if (!ctx
->FragmentProgram
._Current
)
2206 r300SetEarlyZState(ctx
);
2208 r300SetupTextures(ctx
);
2210 rmesa
->vtbl
.SetupPixelShader(ctx
);
2212 rmesa
->vtbl
.SetupRSUnit(ctx
);
2214 if (rmesa
->options
.hw_tcl_enabled
) {
2215 r300SetupVertexProgram(rmesa
);
2220 * Called by Mesa after an internal state update.
2222 static void r300InvalidateState(GLcontext
* ctx
, GLuint new_state
)
2224 r300ContextPtr r300
= R300_CONTEXT(ctx
);
2226 _swrast_InvalidateState(ctx
, new_state
);
2227 _swsetup_InvalidateState(ctx
, new_state
);
2228 _vbo_InvalidateState(ctx
, new_state
);
2229 _tnl_InvalidateState(ctx
, new_state
);
2231 if (new_state
& _NEW_BUFFERS
) {
2232 _mesa_update_framebuffer(ctx
);
2233 /* this updates the DrawBuffer's Width/Height if it's a FBO */
2234 _mesa_update_draw_buffer_bounds(ctx
);
2236 R300_STATECHANGE(r300
, cb
);
2239 r300
->radeon
.NewGLState
|= new_state
;
2243 * Calculate initial hardware state and register state functions.
2244 * Assumes that the command buffer and state atoms have been
2245 * initialized already.
2247 void r300InitState(r300ContextPtr r300
)
2249 r300ResetHwState(r300
);
2252 static void r300RenderMode(GLcontext
* ctx
, GLenum mode
)
2254 r300SwitchFallback(ctx
, R300_FALLBACK_RENDER_MODE
, ctx
->RenderMode
!= GL_RENDER
);
2258 * Initialize driver's state callback functions
2260 void r300InitStateFuncs(struct dd_function_table
*functions
)
2263 functions
->UpdateState
= r300InvalidateState
;
2264 functions
->AlphaFunc
= r300AlphaFunc
;
2265 functions
->BlendColor
= r300BlendColor
;
2266 functions
->BlendEquationSeparate
= r300BlendEquationSeparate
;
2267 functions
->BlendFuncSeparate
= r300BlendFuncSeparate
;
2268 functions
->Enable
= r300Enable
;
2269 functions
->ColorMask
= r300ColorMask
;
2270 functions
->DepthFunc
= r300DepthFunc
;
2271 functions
->DepthMask
= r300DepthMask
;
2272 functions
->CullFace
= r300CullFace
;
2273 functions
->FrontFace
= r300FrontFace
;
2274 functions
->ShadeModel
= r300ShadeModel
;
2275 functions
->LogicOpcode
= r300LogicOpcode
;
2277 /* ARB_point_parameters */
2278 functions
->PointParameterfv
= r300PointParameter
;
2280 /* Stencil related */
2281 functions
->StencilFuncSeparate
= r300StencilFuncSeparate
;
2282 functions
->StencilMaskSeparate
= r300StencilMaskSeparate
;
2283 functions
->StencilOpSeparate
= r300StencilOpSeparate
;
2285 /* Viewport related */
2286 functions
->Viewport
= r300Viewport
;
2287 functions
->DepthRange
= r300DepthRange
;
2288 functions
->PointSize
= r300PointSize
;
2289 functions
->LineWidth
= r300LineWidth
;
2291 functions
->PolygonOffset
= r300PolygonOffset
;
2292 functions
->PolygonMode
= r300PolygonMode
;
2294 functions
->RenderMode
= r300RenderMode
;
2296 functions
->ClipPlane
= r300ClipPlane
;
2297 functions
->Scissor
= radeonScissor
;
2299 functions
->DrawBuffer
= radeonDrawBuffer
;
2300 functions
->ReadBuffer
= radeonReadBuffer
;
2303 void r300InitShaderFunctions(r300ContextPtr r300
)
2305 if (r300
->radeon
.radeonScreen
->chip_family
>= CHIP_FAMILY_RV515
) {
2306 r300
->vtbl
.SetupRSUnit
= r500SetupRSUnit
;
2307 r300
->vtbl
.SetupPixelShader
= r500SetupPixelShader
;
2308 r300
->vtbl
.SetupFragmentShaderTextures
= r500SetupFragmentShaderTextures
;
2310 r300
->vtbl
.SetupRSUnit
= r300SetupRSUnit
;
2311 r300
->vtbl
.SetupPixelShader
= r300SetupPixelShader
;
2312 r300
->vtbl
.SetupFragmentShaderTextures
= r300SetupFragmentShaderTextures
;