2 * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
27 #include "main/glheader.h"
28 #include "main/mtypes.h"
29 #include "main/state.h"
30 #include "main/imports.h"
31 #include "main/enums.h"
32 #include "main/macros.h"
34 #include "main/simple_list.h"
37 #include "tnl/t_pipeline.h"
38 #include "tnl/t_vp_build.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "main/api_arrayelt.h"
42 #include "main/state.h"
43 #include "main/framebuffer.h"
45 #include "shader/prog_parameter.h"
46 #include "shader/prog_statevars.h"
48 #include "main/texformat.h"
50 #include "r600_context.h"
52 #include "r700_chip.h"
53 #include "r700_state.h"
55 #if 0 /* to be enabled */
56 #include "r700_fragprog.h"
57 #include "r700_vertprog.h"
58 #endif /* to be enabled */
60 void r700SetDefaultStates(context_t
*context
) //--------------------
65 void r700UpdateShaders (GLcontext
* ctx
) //----------------------------------
67 context_t
*context
= R700_CONTEXT(ctx
);
69 GLvector4f dummy_attrib
[_TNL_ATTRIB_MAX
];
70 GLvector4f
*temp_attrib
[_TNL_ATTRIB_MAX
];
71 #if 0 /* to be enabled */
72 struct r700_vertex_program
*vp
;
75 if (context
->NewGLState
)
77 context
->NewGLState
= 0;
79 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++)
81 /* mat states from state var not array for sw */
82 dummy_attrib
[i
].stride
= 0;
84 temp_attrib
[i
] = TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
];
85 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] = &(dummy_attrib
[i
]);
88 _tnl_UpdateFixedFunctionProgram(ctx
);
90 for (i
= _TNL_FIRST_MAT
; i
<= _TNL_LAST_MAT
; i
++)
92 TNL_CONTEXT(ctx
)->vb
.AttribPtr
[i
] = temp_attrib
[i
];
95 r700SelectVertexShader(ctx
);
96 vp
= (struct r700_vertex_program
*)ctx
->VertexProgram
._Current
;
98 if (vp
->translated
== GL_FALSE
)
101 //fprintf(stderr, "Failing back to sw-tcl\n");
102 //hw_tcl_on = future_hw_tcl_on = 0;
103 //r300ResetHwState(rmesa);
105 r700UpdateStateParameters(ctx
, _NEW_PROGRAM
);
110 r700UpdateStateParameters(ctx
, _NEW_PROGRAM
);
111 #endif /* to be enabled */
115 * To correctly position primitives:
117 void r700UpdateViewportOffset(GLcontext
* ctx
) //------------------
122 * Tell the card where to render (offset, pitch).
123 * Effected by glDrawBuffer, etc
125 void r700UpdateDrawBuffer(GLcontext
* ctx
) /* TODO */ //---------------------
127 #if 0 /* to be enabled */
128 context_t
*context
= R700_CONTEXT(ctx
);
130 switch (ctx
->DrawBuffer
->_ColorDrawBufferIndexes
[0])
132 case BUFFER_FRONT_LEFT
:
133 context
->target
.rt
= context
->screen
->frontBuffer
;
135 case BUFFER_BACK_LEFT
:
136 context
->target
.rt
= context
->screen
->backBuffer
;
139 memset (&context
->target
.rt
, sizeof(context
->target
.rt
), 0);
141 #endif /* to be enabled */
144 static void r700FetchStateParameter(GLcontext
* ctx
,
145 const gl_state_index state
[STATE_LENGTH
],
148 context_t
*context
= R700_CONTEXT(ctx
);
153 void r700UpdateStateParameters(GLcontext
* ctx
, GLuint new_state
) //--------------------
155 #if 0 /* to be enabled */
156 struct r700_fragment_program
*fp
;
157 struct gl_program_parameter_list
*paramList
;
160 if (!(new_state
& (_NEW_BUFFERS
| _NEW_PROGRAM
)))
163 fp
= (struct r700_fragment_program
*)ctx
->FragmentProgram
._Current
;
169 paramList
= fp
->mesa_program
.Base
.Parameters
;
176 for (i
= 0; i
< paramList
->NumParameters
; i
++)
178 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
)
180 r700FetchStateParameter(ctx
,
181 paramList
->Parameters
[i
].
183 paramList
->ParameterValues
[i
]);
186 #endif /* to be enabled */
190 * Called by Mesa after an internal state update.
192 static void r700InvalidateState(GLcontext
* ctx
, GLuint new_state
) //-------------------
194 #if 0 /* to be enabled */
195 context_t
*context
= R700_CONTEXT(ctx
);
197 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(context
->chipobj
.pvChipObj
);
199 _swrast_InvalidateState(ctx
, new_state
);
200 _swsetup_InvalidateState(ctx
, new_state
);
201 _vbo_InvalidateState(ctx
, new_state
);
202 _tnl_InvalidateState(ctx
, new_state
);
203 _ae_invalidate_state(ctx
, new_state
);
205 if (new_state
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
))
207 r700UpdateDrawBuffer(ctx
);
210 r700UpdateStateParameters(ctx
, new_state
);
212 if(GL_TRUE
== context
->bEnablePerspective
)
214 /* Do scale XY and Z by 1/W0 for perspective correction on pos. For orthogonal case, set both to one. */
215 CLEARbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_XY_FMT_bit
);
216 CLEARbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_Z_FMT_bit
);
218 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_W0_FMT_bit
);
220 CLEARbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, PERSP_GRADIENT_ENA_bit
);
221 SETbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, LINEAR_GRADIENT_ENA_bit
);
225 /* For orthogonal case. */
226 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_XY_FMT_bit
);
227 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_Z_FMT_bit
);
229 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_W0_FMT_bit
);
231 SETbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, PERSP_GRADIENT_ENA_bit
);
232 CLEARbit(r700
->SPI_PS_IN_CONTROL_0
.u32All
, LINEAR_GRADIENT_ENA_bit
);
235 context
->NewGLState
|= new_state
;
236 #endif /* to be enabled */
239 static void r700SetDepthState(GLcontext
* ctx
)
241 context_t
*context
= R700_CONTEXT(ctx
);
243 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(context
->chipobj
.pvChipObj
);
247 SETbit(r700
->DB_DEPTH_CONTROL
.u32All
, Z_ENABLE_bit
);
250 SETbit(r700
->DB_DEPTH_CONTROL
.u32All
, Z_WRITE_ENABLE_bit
);
254 CLEARbit(r700
->DB_DEPTH_CONTROL
.u32All
, Z_WRITE_ENABLE_bit
);
257 switch (ctx
->Depth
.Func
)
260 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_NEVER
,
261 ZFUNC_shift
, ZFUNC_mask
);
264 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_LESS
,
265 ZFUNC_shift
, ZFUNC_mask
);
268 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_EQUAL
,
269 ZFUNC_shift
, ZFUNC_mask
);
272 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_LEQUAL
,
273 ZFUNC_shift
, ZFUNC_mask
);
276 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_GREATER
,
277 ZFUNC_shift
, ZFUNC_mask
);
280 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_NOTEQUAL
,
281 ZFUNC_shift
, ZFUNC_mask
);
284 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_GEQUAL
,
285 ZFUNC_shift
, ZFUNC_mask
);
288 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_ALWAYS
,
289 ZFUNC_shift
, ZFUNC_mask
);
292 SETfield(r700
->DB_DEPTH_CONTROL
.u32All
, FRAG_ALWAYS
,
293 ZFUNC_shift
, ZFUNC_mask
);
299 CLEARbit(r700
->DB_DEPTH_CONTROL
.u32All
, Z_ENABLE_bit
);
300 CLEARbit(r700
->DB_DEPTH_CONTROL
.u32All
, Z_WRITE_ENABLE_bit
);
304 static void r700AlphaFunc(GLcontext
* ctx
, GLenum func
, GLfloat ref
) //---------------
309 static void r700BlendColor(GLcontext
* ctx
, const GLfloat cf
[4]) //----------------
313 static void r700BlendEquationSeparate(GLcontext
* ctx
,
314 GLenum modeRGB
, GLenum modeA
) //-----------------
318 static void r700BlendFuncSeparate(GLcontext
* ctx
,
319 GLenum sfactorRGB
, GLenum dfactorRGB
,
320 GLenum sfactorA
, GLenum dfactorA
) //------------------------
324 static void r700UpdateCulling(GLcontext
* ctx
)
326 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(R700_CONTEXT(ctx
)->chipobj
.pvChipObj
);
328 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, FACE_bit
);
329 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_FRONT_bit
);
330 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_BACK_bit
);
332 if (ctx
->Polygon
.CullFlag
)
334 switch (ctx
->Polygon
.CullFaceMode
)
337 SETbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_FRONT_bit
);
338 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_BACK_bit
);
341 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_FRONT_bit
);
342 SETbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_BACK_bit
);
344 case GL_FRONT_AND_BACK
:
345 SETbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_FRONT_bit
);
346 SETbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_BACK_bit
);
349 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_FRONT_bit
);
350 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, CULL_BACK_bit
);
355 switch (ctx
->Polygon
.FrontFace
)
358 SETbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, FACE_bit
);
361 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, FACE_bit
);
364 CLEARbit(r700
->PA_SU_SC_MODE_CNTL
.u32All
, FACE_bit
); /* default: ccw */
369 static void r700Enable(GLcontext
* ctx
, GLenum cap
, GLboolean state
) //------------------
381 case GL_COLOR_LOGIC_OP
:
392 r700SetDepthState(ctx
);
394 case GL_STENCIL_TEST
:
397 r700UpdateCulling(ctx
);
399 case GL_POLYGON_OFFSET_POINT
:
400 case GL_POLYGON_OFFSET_LINE
:
401 case GL_POLYGON_OFFSET_FILL
:
409 * Handle glColorMask()
411 static void r700ColorMask(GLcontext
* ctx
,
412 GLboolean r
, GLboolean g
, GLboolean b
, GLboolean a
) //------------------
417 * Change the depth testing function.
419 * \note Mesa already filters redundant calls to this function.
421 static void r700DepthFunc(GLcontext
* ctx
, GLenum func
) //--------------------
423 r700SetDepthState(ctx
);
427 * Enable/Disable depth writing.
429 * \note Mesa already filters redundant calls to this function.
431 static void r700DepthMask(GLcontext
* ctx
, GLboolean mask
) //------------------
433 r700SetDepthState(ctx
);
437 * Change the culling mode.
439 * \note Mesa already filters redundant calls to this function.
441 static void r700CullFace(GLcontext
* ctx
, GLenum mode
) //-----------------
443 r700UpdateCulling(ctx
);
446 /* =============================================================
449 static void r700Fogfv(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
) //--------------
454 * Change the polygon orientation.
456 * \note Mesa already filters redundant calls to this function.
458 static void r700FrontFace(GLcontext
* ctx
, GLenum mode
) //------------------
460 r700UpdateCulling(ctx
);
463 static void r700ShadeModel(GLcontext
* ctx
, GLenum mode
) //--------------------
467 static void r700PointParameter(GLcontext
* ctx
, GLenum pname
, const GLfloat
* param
) //---------------
471 static void r700StencilFuncSeparate(GLcontext
* ctx
, GLenum face
,
472 GLenum func
, GLint ref
, GLuint mask
) //---------------------
477 static void r700StencilMaskSeparate(GLcontext
* ctx
, GLenum face
, GLuint mask
) //--------------
481 static void r700StencilOpSeparate(GLcontext
* ctx
, GLenum face
,
482 GLenum fail
, GLenum zfail
, GLenum zpass
) //--------------------
486 #define SUBPIXEL_X 0.125
487 #define SUBPIXEL_Y 0.125
489 static void r700Viewport(GLcontext
* ctx
,
493 GLsizei height
) //--------------------
495 #if 0 /* to be enabled */
496 context_t
*context
= R700_CONTEXT(ctx
);
498 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(context
->chipobj
.pvChipObj
);
500 context
->vport_x
= x
;
501 context
->vport_y
= y
;
502 context
->vport_width
= width
;
503 context
->vport_height
= height
;
505 __DRIdrawablePrivate
*dPriv
= context
->currentDraw
;
507 GLfloat xoffset
= dPriv
? (GLfloat
) dPriv
->x
: 0;
508 GLfloat yoffset
= dPriv
? (GLfloat
) dPriv
->y
+ dPriv
->h
: 0;
510 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
512 GLfloat sx
, tx
, sy
, ty
, sz
, tz
;
515 switch (ctx
->Visual
.depthBits
)
518 scale
= 1.0 / (GLfloat
) 0xffff;
521 scale
= 1.0 / (GLfloat
) 0xffffff;
524 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
525 ctx
->Visual
.depthBits
);
530 tx
= v
[MAT_TX
] + xoffset
+ SUBPIXEL_X
;
532 ty
= (-v
[MAT_TY
]) + yoffset
+ SUBPIXEL_Y
;
533 sz
= v
[MAT_SZ
] * scale
;
534 tz
= v
[MAT_TZ
] * scale
;
536 /* TODO : Need DMA flush as well. */
538 if(context
->cmdbuf
.count_used
> 0)
540 (context
->chipobj
.FlushCmdBuffer
)(context
);
543 r700
->PA_CL_VPORT_XSCALE
.u32All
= *((unsigned int*)(&sx
));
544 r700
->PA_CL_VPORT_XOFFSET
.u32All
= *((unsigned int*)(&tx
));
546 r700
->PA_CL_VPORT_YSCALE
.u32All
= *((unsigned int*)(&sy
));
547 r700
->PA_CL_VPORT_YOFFSET
.u32All
= *((unsigned int*)(&ty
));
549 r700
->PA_CL_VPORT_ZSCALE
.u32All
= *((unsigned int*)(&sz
));
550 r700
->PA_CL_VPORT_ZOFFSET
.u32All
= *((unsigned int*)(&tz
));
551 #endif /* to be enabled */
555 static void r700DepthRange(GLcontext
* ctx
, GLclampd nearval
, GLclampd farval
) //-------------
559 static void r700PointSize(GLcontext
* ctx
, GLfloat size
) //-------------------
563 static void r700LineWidth(GLcontext
* ctx
, GLfloat widthf
) //---------------
567 static void r700PolygonOffset(GLcontext
* ctx
, GLfloat factor
, GLfloat units
) //--------------
572 static void r700PolygonMode(GLcontext
* ctx
, GLenum face
, GLenum mode
) //------------------
576 static void r700RenderMode(GLcontext
* ctx
, GLenum mode
) //---------------------
580 static void r700ClipPlane( GLcontext
*ctx
, GLenum plane
, const GLfloat
*eq
) //-----------------
584 static void r700Scissor(GLcontext
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
) //---------------
586 if (ctx
->Scissor
.Enabled
)
588 /* We don't pipeline cliprect changes */
589 /* r700Flush(ctx); */
591 //__DRIdrawablePrivate *dPriv = radeon->dri.drawable;
592 //int x1 = dPriv->x + ctx->Scissor.X;
593 //int y1 = dPriv->y + dPriv->h - (ctx->Scissor.Y + ctx->Scissor.Height);
595 //radeon->state.scissor.rect.x1 = x1;
596 //radeon->state.scissor.rect.y1 = y1;
597 //radeon->state.scissor.rect.x2 = x1 + ctx->Scissor.Width;
598 //radeon->state.scissor.rect.y2 = y1 + ctx->Scissor.Height;
599 /* radeonRecalcScissorRects(radeon); */
605 * Calculate initial hardware state and register state functions.
606 * Assumes that the command buffer and state atoms have been
607 * initialized already.
609 void r700InitState(GLcontext
* ctx
) //-------------------
611 #if 0 /* to be enabled */
612 context_t
*context
= R700_CONTEXT(ctx
);
614 R700_CHIP_CONTEXT
*r700
= (R700_CHIP_CONTEXT
*)(context
->chipobj
.pvChipObj
);
616 if(context
->ctx
->Visual
.doubleBufferMode
&& context
->sarea
->pfCurrentPage
== 0)
618 context
->target
.rt
= context
->screen
->backBuffer
;
622 context
->target
.rt
= context
->screen
->frontBuffer
;
625 SETfield(r700
->CB_TARGET_MASK
.u32All
, 0xF, TARGET0_ENABLE_shift
, TARGET0_ENABLE_mask
);
626 SETfield(r700
->CB_SHADER_MASK
.u32All
, 0xF, OUTPUT0_ENABLE_shift
, OUTPUT0_ENABLE_mask
);
629 r700
->PA_SC_SCREEN_SCISSOR_TL
.u32All
= 0x0;
630 SETfield(r700
->PA_SC_SCREEN_SCISSOR_BR
.u32All
, context
->screen
->width
,
631 PA_SC_SCREEN_SCISSOR_BR__BR_X_shift
, PA_SC_SCREEN_SCISSOR_BR__BR_X_mask
);
632 SETfield(r700
->PA_SC_SCREEN_SCISSOR_BR
.u32All
, context
->screen
->height
,
633 PA_SC_SCREEN_SCISSOR_BR__BR_Y_shift
, PA_SC_SCREEN_SCISSOR_BR__BR_Y_mask
);
636 SETbit(r700
->PA_SC_WINDOW_SCISSOR_TL
.u32All
, WINDOW_OFFSET_DISABLE_bit
);
637 SETfield(r700
->PA_SC_WINDOW_SCISSOR_TL
.u32All
, context
->currentDraw
->x
,
638 PA_SC_WINDOW_SCISSOR_TL__TL_X_shift
, PA_SC_WINDOW_SCISSOR_TL__TL_X_mask
);
639 SETfield(r700
->PA_SC_WINDOW_SCISSOR_TL
.u32All
, context
->currentDraw
->y
,
640 PA_SC_WINDOW_SCISSOR_TL__TL_Y_shift
, PA_SC_WINDOW_SCISSOR_TL__TL_Y_mask
);
642 SETfield(r700
->PA_SC_WINDOW_SCISSOR_BR
.u32All
, context
->currentDraw
->x
+ context
->currentDraw
->w
,
643 PA_SC_WINDOW_SCISSOR_BR__BR_X_shift
, PA_SC_WINDOW_SCISSOR_BR__BR_X_mask
);
644 SETfield(r700
->PA_SC_WINDOW_SCISSOR_BR
.u32All
, context
->currentDraw
->y
+ context
->currentDraw
->h
,
645 PA_SC_WINDOW_SCISSOR_BR__BR_Y_shift
, PA_SC_WINDOW_SCISSOR_BR__BR_Y_mask
);
647 /* 4 clip rectangles */ /* TODO : set these clip rects according to context->currentDraw->numClipRects */
648 r700
->PA_SC_CLIPRECT_RULE
.u32All
= 0x0000FFFF;
650 SETfield(r700
->PA_SC_CLIPRECT_0_TL
.u32All
, context
->currentDraw
->x
,
651 PA_SC_CLIPRECT_0_TL__TL_X_shift
, PA_SC_CLIPRECT_0_TL__TL_X_mask
);
652 SETfield(r700
->PA_SC_CLIPRECT_0_TL
.u32All
, context
->currentDraw
->y
,
653 PA_SC_CLIPRECT_0_TL__TL_Y_shift
, PA_SC_CLIPRECT_0_TL__TL_Y_mask
);
654 SETfield(r700
->PA_SC_CLIPRECT_0_BR
.u32All
, context
->currentDraw
->x
+ context
->currentDraw
->w
,
655 PA_SC_CLIPRECT_0_BR__BR_X_shift
, PA_SC_CLIPRECT_0_BR__BR_X_mask
);
656 SETfield(r700
->PA_SC_CLIPRECT_0_BR
.u32All
, context
->currentDraw
->y
+ context
->currentDraw
->h
,
657 PA_SC_CLIPRECT_0_BR__BR_Y_shift
, PA_SC_CLIPRECT_0_BR__BR_Y_mask
);
659 r700
->PA_SC_CLIPRECT_1_TL
.u32All
= r700
->PA_SC_CLIPRECT_0_TL
.u32All
;
660 r700
->PA_SC_CLIPRECT_1_BR
.u32All
= r700
->PA_SC_CLIPRECT_0_BR
.u32All
;
661 r700
->PA_SC_CLIPRECT_2_TL
.u32All
= r700
->PA_SC_CLIPRECT_0_TL
.u32All
;
662 r700
->PA_SC_CLIPRECT_2_BR
.u32All
= r700
->PA_SC_CLIPRECT_0_BR
.u32All
;
663 r700
->PA_SC_CLIPRECT_3_TL
.u32All
= r700
->PA_SC_CLIPRECT_0_TL
.u32All
;
664 r700
->PA_SC_CLIPRECT_3_BR
.u32All
= r700
->PA_SC_CLIPRECT_0_BR
.u32All
;
666 /* more....2d clip */
667 SETbit(r700
->PA_SC_GENERIC_SCISSOR_TL
.u32All
, WINDOW_OFFSET_DISABLE_bit
);
668 SETfield(r700
->PA_SC_GENERIC_SCISSOR_TL
.u32All
, context
->currentDraw
->x
,
669 PA_SC_GENERIC_SCISSOR_TL__TL_X_shift
, PA_SC_GENERIC_SCISSOR_TL__TL_X_mask
);
670 SETfield(r700
->PA_SC_GENERIC_SCISSOR_TL
.u32All
, context
->currentDraw
->y
,
671 PA_SC_GENERIC_SCISSOR_TL__TL_Y_shift
, PA_SC_GENERIC_SCISSOR_TL__TL_Y_mask
);
672 SETfield(r700
->PA_SC_GENERIC_SCISSOR_BR
.u32All
, context
->currentDraw
->x
+ context
->currentDraw
->w
,
673 PA_SC_GENERIC_SCISSOR_BR__BR_X_shift
, PA_SC_GENERIC_SCISSOR_BR__BR_X_mask
);
674 SETfield(r700
->PA_SC_GENERIC_SCISSOR_BR
.u32All
, context
->currentDraw
->y
+ context
->currentDraw
->h
,
675 PA_SC_GENERIC_SCISSOR_BR__BR_Y_shift
, PA_SC_GENERIC_SCISSOR_BR__BR_Y_mask
);
677 SETbit(r700
->PA_SC_VPORT_SCISSOR_0_TL
.u32All
, WINDOW_OFFSET_DISABLE_bit
);
678 SETfield(r700
->PA_SC_VPORT_SCISSOR_0_TL
.u32All
, context
->currentDraw
->x
,
679 PA_SC_VPORT_SCISSOR_0_TL__TL_X_shift
, PA_SC_VPORT_SCISSOR_0_TL__TL_X_mask
);
680 SETfield(r700
->PA_SC_VPORT_SCISSOR_0_TL
.u32All
, context
->currentDraw
->y
,
681 PA_SC_VPORT_SCISSOR_0_TL__TL_Y_shift
, PA_SC_VPORT_SCISSOR_0_TL__TL_Y_mask
);
682 SETfield(r700
->PA_SC_VPORT_SCISSOR_0_BR
.u32All
, context
->currentDraw
->x
+ context
->currentDraw
->w
,
683 PA_SC_VPORT_SCISSOR_0_BR__BR_X_shift
, PA_SC_VPORT_SCISSOR_0_BR__BR_X_mask
);
684 SETfield(r700
->PA_SC_VPORT_SCISSOR_0_BR
.u32All
, context
->currentDraw
->y
+ context
->currentDraw
->h
,
685 PA_SC_VPORT_SCISSOR_0_BR__BR_Y_shift
, PA_SC_VPORT_SCISSOR_0_BR__BR_Y_mask
);
687 SETbit(r700
->PA_SC_VPORT_SCISSOR_1_TL
.u32All
, WINDOW_OFFSET_DISABLE_bit
);
688 SETfield(r700
->PA_SC_VPORT_SCISSOR_1_TL
.u32All
, context
->currentDraw
->x
,
689 PA_SC_VPORT_SCISSOR_0_TL__TL_X_shift
, PA_SC_VPORT_SCISSOR_0_TL__TL_X_mask
);
690 SETfield(r700
->PA_SC_VPORT_SCISSOR_1_TL
.u32All
, context
->currentDraw
->y
,
691 PA_SC_VPORT_SCISSOR_0_TL__TL_Y_shift
, PA_SC_VPORT_SCISSOR_0_TL__TL_Y_mask
);
692 SETfield(r700
->PA_SC_VPORT_SCISSOR_1_BR
.u32All
, context
->currentDraw
->x
+ context
->currentDraw
->w
,
693 PA_SC_VPORT_SCISSOR_0_BR__BR_X_shift
, PA_SC_VPORT_SCISSOR_0_BR__BR_X_mask
);
694 SETfield(r700
->PA_SC_VPORT_SCISSOR_1_BR
.u32All
, context
->currentDraw
->y
+ context
->currentDraw
->h
,
695 PA_SC_VPORT_SCISSOR_0_BR__BR_Y_shift
, PA_SC_VPORT_SCISSOR_0_BR__BR_Y_mask
);
701 context
->currentDraw
->w
,
702 context
->currentDraw
->h
);
704 /* Turn off vgt reuse */
705 r700
->VGT_REUSE_OFF
.u32All
= 0;
706 SETbit(r700
->VGT_REUSE_OFF
.u32All
, REUSE_OFF_bit
);
708 /* Specify offsetting and clamp values for vertices */
709 r700
->VGT_MAX_VTX_INDX
.u32All
= 0xFFFFFF;
710 r700
->VGT_MIN_VTX_INDX
.u32All
= 0;
711 r700
->VGT_INDX_OFFSET
.u32All
= 0;
713 /* Specify the number of instances */
714 r700
->VGT_DMA_NUM_INSTANCES
.u32All
= 1;
716 /* not alpha blend */
717 CLEARfield(r700
->SX_ALPHA_TEST_CONTROL
.u32All
, ALPHA_FUNC_mask
);
718 CLEARbit(r700
->SX_ALPHA_TEST_CONTROL
.u32All
, ALPHA_TEST_ENABLE_bit
);
720 /* defualt shader connections. */
721 r700
->SPI_VS_OUT_ID_0
.u32All
= 0x03020100;
722 r700
->SPI_VS_OUT_ID_1
.u32All
= 0x07060504;
724 r700
->SPI_PS_INPUT_CNTL_0
.u32All
= 0x00000800;
725 r700
->SPI_PS_INPUT_CNTL_1
.u32All
= 0x00000801;
726 r700
->SPI_PS_INPUT_CNTL_2
.u32All
= 0x00000802;
728 SETfield(r700
->CB_COLOR_CONTROL
.u32All
, 0xCC, ROP3_shift
, ROP3_mask
);
729 CLEARbit(r700
->CB_COLOR_CONTROL
.u32All
, PER_MRT_BLEND_bit
);
730 CLEARfield(r700
->CB_BLEND0_CONTROL
.u32All
, COLOR_SRCBLEND_mask
); /* no dst blend */
731 CLEARfield(r700
->CB_BLEND0_CONTROL
.u32All
, ALPHA_SRCBLEND_mask
); /* no dst blend */
733 r700
->DB_SHADER_CONTROL
.u32All
= 0;
734 SETbit(r700
->DB_SHADER_CONTROL
.u32All
, DUAL_EXPORT_ENABLE_bit
);
736 /* Set up the culling control register */
737 SETfield(r700
->PA_SU_SC_MODE_CNTL
.u32All
, X_DRAW_TRIANGLES
,
738 POLYMODE_FRONT_PTYPE_shift
, POLYMODE_FRONT_PTYPE_mask
);
739 SETfield(r700
->PA_SU_SC_MODE_CNTL
.u32All
, X_DRAW_TRIANGLES
,
740 POLYMODE_BACK_PTYPE_shift
, POLYMODE_BACK_PTYPE_mask
);
742 /* Do scale XY and Z by 1/W0. */
743 context
->bEnablePerspective
= GL_TRUE
;
744 CLEARbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_XY_FMT_bit
);
745 CLEARbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_Z_FMT_bit
);
746 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VTX_W0_FMT_bit
);
748 /* Enable viewport scaling for all three axis */
749 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_X_SCALE_ENA_bit
);
750 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_X_OFFSET_ENA_bit
);
751 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_Y_SCALE_ENA_bit
);
752 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_Y_OFFSET_ENA_bit
);
753 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_Z_SCALE_ENA_bit
);
754 SETbit(r700
->PA_CL_VTE_CNTL
.u32All
, VPORT_Z_OFFSET_ENA_bit
);
756 /* Set up point sizes and min/max values */
757 SETfield(r700
->PA_SU_POINT_SIZE
.u32All
, 0x8,
758 PA_SU_POINT_SIZE__HEIGHT_shift
, PA_SU_POINT_SIZE__HEIGHT_mask
);
759 SETfield(r700
->PA_SU_POINT_SIZE
.u32All
, 0x8,
760 PA_SU_POINT_SIZE__WIDTH_shift
, PA_SU_POINT_SIZE__WIDTH_mask
);
761 CLEARfield(r700
->PA_SU_POINT_MINMAX
.u32All
, MIN_SIZE_mask
);
762 SETfield(r700
->PA_SU_POINT_MINMAX
.u32All
, 0x8000, MAX_SIZE_shift
, MAX_SIZE_mask
);
764 /* Set up line control */
765 SETfield(r700
->PA_SU_LINE_CNTL
.u32All
, 0x8,
766 PA_SU_LINE_CNTL__WIDTH_shift
, PA_SU_LINE_CNTL__WIDTH_mask
);
768 r700
->PA_SC_LINE_CNTL
.u32All
= 0;
769 CLEARbit(r700
->PA_SC_LINE_CNTL
.u32All
, EXPAND_LINE_WIDTH_bit
);
770 SETbit(r700
->PA_SC_LINE_CNTL
.u32All
, LAST_PIXEL_bit
);
772 /* Set up vertex control */
773 r700
->PA_SU_VTX_CNTL
.u32All
= 0;
774 CLEARfield(r700
->PA_SU_VTX_CNTL
.u32All
, QUANT_MODE_mask
);
775 SETbit(r700
->PA_SU_VTX_CNTL
.u32All
, PIX_CENTER_bit
);
776 SETfield(r700
->PA_SU_VTX_CNTL
.u32All
, X_ROUND_TO_EVEN
,
777 PA_SU_VTX_CNTL__ROUND_MODE_shift
, PA_SU_VTX_CNTL__ROUND_MODE_mask
);
779 /* to 1.0 = no guard band */
780 r700
->PA_CL_GB_VERT_CLIP_ADJ
.u32All
= 0x3F800000; /* 1.0 */
781 r700
->PA_CL_GB_VERT_DISC_ADJ
.u32All
= 0x3F800000;
782 r700
->PA_CL_GB_HORZ_CLIP_ADJ
.u32All
= 0x3F800000;
783 r700
->PA_CL_GB_HORZ_DISC_ADJ
.u32All
= 0x3F800000;
785 /* Disble color compares */
786 SETfield(r700
->CB_CLRCMP_CONTROL
.u32All
, CLRCMP_DRAW_ALWAYS
,
787 CLRCMP_FCN_SRC_shift
, CLRCMP_FCN_SRC_mask
);
788 SETfield(r700
->CB_CLRCMP_CONTROL
.u32All
, CLRCMP_DRAW_ALWAYS
,
789 CLRCMP_FCN_DST_shift
, CLRCMP_FCN_DST_mask
);
790 SETfield(r700
->CB_CLRCMP_CONTROL
.u32All
, CLRCMP_SEL_SRC
,
791 CLRCMP_FCN_SEL_shift
, CLRCMP_FCN_SEL_mask
);
793 /* Zero out source */
794 r700
->CB_CLRCMP_SRC
.u32All
= 0x00000000;
796 /* Put a compare color in for error checking */
797 r700
->CB_CLRCMP_DST
.u32All
= 0x000000FF;
799 /* Set up color compare mask */
800 r700
->CB_CLRCMP_MSK
.u32All
= 0xFFFFFFFF;
802 /* Enable all samples for multi-sample anti-aliasing */
803 r700
->PA_SC_AA_MASK
.u32All
= 0xFFFFFFFF;
805 r700
->PA_SC_AA_CONFIG
.u32All
= 0;
807 SETfield(r700
->VGT_OUT_DEALLOC_CNTL
.u32All
, 16, DEALLOC_DIST_shift
, DEALLOC_DIST_mask
);
808 SETfield(r700
->VGT_VERTEX_REUSE_BLOCK_CNTL
.u32All
, 14, VTX_REUSE_DEPTH_shift
, VTX_REUSE_DEPTH_mask
);
810 r700
->SX_MISC
.u32All
= 0;
813 r700
->DB_DEPTH_SIZE
.u32All
= 0;
814 SETfield(r700
->DB_DEPTH_SIZE
.u32All
, (context
->screen
->depthBuffer
.pitch
/8)-1,
815 PITCH_TILE_MAX_shift
, PITCH_TILE_MAX_mask
);
816 SETfield(r700
->DB_DEPTH_SIZE
.u32All
, ( (context
->screen
->depthBuffer
.size
/ context
->screen
->cpp
)/64 )-1,
817 SLICE_TILE_MAX_shift
, SLICE_TILE_MAX_mask
); /* size in pixel / 64 - 1 */
818 r700
->DB_DEPTH_BASE
.u32All
= context
->screen
->depthBuffer
.gpu
>> 8;
819 r700
->DB_DEPTH_INFO
.u32All
= 0;
820 if(4 == context
->screen
->cpp
) /* TODO : in scrren create, gives z its own format alloc. */
822 switch (ctx
->Visual
.depthBits
)
826 SETfield(r700
->DB_DEPTH_INFO
.u32All
, DEPTH_8_24
,
827 DB_DEPTH_INFO__FORMAT_shift
, DB_DEPTH_INFO__FORMAT_mask
);
830 fprintf(stderr
, "Error: Unsupported depth %d... exiting\n",
831 ctx
->Visual
.depthBits
);
837 SETfield(r700
->DB_DEPTH_INFO
.u32All
, DEPTH_16
,
838 DB_DEPTH_INFO__FORMAT_shift
, DB_DEPTH_INFO__FORMAT_mask
);
840 SETfield(r700
->DB_DEPTH_INFO
.u32All
, ARRAY_2D_TILED_THIN1
,
841 DB_DEPTH_INFO__ARRAY_MODE_shift
, DB_DEPTH_INFO__ARRAY_MODE_mask
);
842 /* r700->DB_PREFETCH_LIMIT.bits.DEPTH_HEIGHT_TILE_MAX = (context->currentDraw->h >> 3) - 1; */ /* z buffer sie may much bigger than what need, so use actual used h. */
843 r700
->DB_DEPTH_CONTROL
.u32All
= 0;
844 r700
->DB_DEPTH_CLEAR
.u32All
= 0x3F800000;
845 r700
->DB_DEPTH_VIEW
.u32All
= 0;
846 r700
->DB_RENDER_CONTROL
.u32All
= 0;
847 r700
->DB_RENDER_OVERRIDE
.u32All
= 0;
848 SETfield(r700
->DB_RENDER_OVERRIDE
.u32All
, FORCE_DISABLE
, FORCE_HIZ_ENABLE_shift
, FORCE_HIZ_ENABLE_mask
);
849 SETfield(r700
->DB_RENDER_OVERRIDE
.u32All
, FORCE_DISABLE
, FORCE_HIS_ENABLE0_shift
, FORCE_HIS_ENABLE0_mask
);
850 SETfield(r700
->DB_RENDER_OVERRIDE
.u32All
, FORCE_DISABLE
, FORCE_HIS_ENABLE1_shift
, FORCE_HIS_ENABLE1_mask
);
853 SETfield(r700
->CB_COLOR0_SIZE
.u32All
, (context
->screen
->frontBuffer
.pitch
/8)-1,
854 PITCH_TILE_MAX_shift
, PITCH_TILE_MAX_mask
);
855 SETfield(r700
->CB_COLOR0_SIZE
.u32All
, ( (context
->screen
->frontBuffer
.size
/ context
->screen
->cpp
)/64 )-1,
856 SLICE_TILE_MAX_shift
, SLICE_TILE_MAX_mask
);
857 r700
->CB_COLOR0_BASE
.u32All
= context
->screen
->frontBuffer
.gpu
>> 8;
858 SETfield(r700
->CB_COLOR0_INFO
.u32All
, ENDIAN_NONE
, ENDIAN_shift
, ENDIAN_mask
);
859 SETfield(r700
->CB_COLOR0_INFO
.u32All
, ARRAY_LINEAR_GENERAL
,
860 CB_COLOR0_INFO__ARRAY_MODE_shift
, CB_COLOR0_INFO__ARRAY_MODE_mask
);
861 if(4 == context
->screen
->cpp
)
863 SETfield(r700
->CB_COLOR0_INFO
.u32All
, COLOR_8_8_8_8
,
864 CB_COLOR0_INFO__FORMAT_shift
, CB_COLOR0_INFO__FORMAT_mask
);
865 SETfield(r700
->CB_COLOR0_INFO
.u32All
, SWAP_ALT
, COMP_SWAP_shift
, COMP_SWAP_mask
);
869 SETfield(r700
->CB_COLOR0_INFO
.u32All
, COLOR_5_6_5
,
870 CB_COLOR0_INFO__FORMAT_shift
, CB_COLOR0_INFO__FORMAT_mask
);
871 SETfield(r700
->CB_COLOR0_INFO
.u32All
, SWAP_ALT_REV
,
872 COMP_SWAP_shift
, COMP_SWAP_mask
);
874 SETbit(r700
->CB_COLOR0_INFO
.u32All
, SOURCE_FORMAT_bit
);
875 SETbit(r700
->CB_COLOR0_INFO
.u32All
, BLEND_CLAMP_bit
);
876 SETfield(r700
->CB_COLOR0_INFO
.u32All
, NUMBER_UNORM
, NUMBER_TYPE_shift
, NUMBER_TYPE_mask
);
877 r700
->CB_COLOR0_VIEW
.u32All
= 0;
878 r700
->CB_COLOR0_TILE
.u32All
= 0;
879 r700
->CB_COLOR0_FRAG
.u32All
= 0;
880 r700
->CB_COLOR0_MASK
.u32All
= 0;
882 r700
->PA_SC_VPORT_ZMAX_0
.u32All
= 0x3F800000;
883 #endif /* to be enabled */
886 void r700InitStateFuncs(struct dd_function_table
*functions
) //-----------------
888 functions
->UpdateState
= r700InvalidateState
;
889 functions
->AlphaFunc
= r700AlphaFunc
;
890 functions
->BlendColor
= r700BlendColor
;
891 functions
->BlendEquationSeparate
= r700BlendEquationSeparate
;
892 functions
->BlendFuncSeparate
= r700BlendFuncSeparate
;
893 functions
->Enable
= r700Enable
;
894 functions
->ColorMask
= r700ColorMask
;
895 functions
->DepthFunc
= r700DepthFunc
;
896 functions
->DepthMask
= r700DepthMask
;
897 functions
->CullFace
= r700CullFace
;
898 functions
->Fogfv
= r700Fogfv
;
899 functions
->FrontFace
= r700FrontFace
;
900 functions
->ShadeModel
= r700ShadeModel
;
902 /* ARB_point_parameters */
903 functions
->PointParameterfv
= r700PointParameter
;
905 /* Stencil related */
906 functions
->StencilFuncSeparate
= r700StencilFuncSeparate
;
907 functions
->StencilMaskSeparate
= r700StencilMaskSeparate
;
908 functions
->StencilOpSeparate
= r700StencilOpSeparate
;
910 /* Viewport related */
911 functions
->Viewport
= r700Viewport
;
912 functions
->DepthRange
= r700DepthRange
;
913 functions
->PointSize
= r700PointSize
;
914 functions
->LineWidth
= r700LineWidth
;
916 functions
->PolygonOffset
= r700PolygonOffset
;
917 functions
->PolygonMode
= r700PolygonMode
;
919 functions
->RenderMode
= r700RenderMode
;
921 functions
->ClipPlane
= r700ClipPlane
;
923 functions
->Scissor
= r700Scissor
;