1/**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include "xorg-server.h"
33#include "xf86.h"
34#include "i830.h"
35
36#include "i830_reg.h"
37
38void I830EmitInvarientState( ScrnInfoPtr pScrn )
39{
40   I830Ptr pI830 = I830PTR(pScrn);
41
42   BEGIN_BATCH(58);
43
44   OUT_BATCH(_3DSTATE_MAP_CUBE | MAP_UNIT(0));
45   OUT_BATCH(_3DSTATE_MAP_CUBE | MAP_UNIT(1));
46   OUT_BATCH(_3DSTATE_MAP_CUBE | MAP_UNIT(2));
47   OUT_BATCH(_3DSTATE_MAP_CUBE | MAP_UNIT(3));
48
49   OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
50   OUT_BATCH(0);
51
52   OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD);
53   OUT_BATCH(0);
54
55   OUT_BATCH(_3DSTATE_DFLT_Z_CMD);
56   OUT_BATCH(0);
57
58   OUT_BATCH(_3DSTATE_FOG_MODE_CMD);
59   OUT_BATCH(FOGFUNC_ENABLE |
60	     FOG_LINEAR_CONST |
61	     FOGSRC_INDEX_Z |
62	     ENABLE_FOG_DENSITY);
63   OUT_BATCH(0);
64   OUT_BATCH(0);
65
66   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
67	     MAP_UNIT(0) |
68	     DISABLE_TEX_STREAM_BUMP |
69	     ENABLE_TEX_STREAM_COORD_SET |
70	     TEX_STREAM_COORD_SET(0) |
71	     ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(0));
72   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
73	     MAP_UNIT(1) |
74	     DISABLE_TEX_STREAM_BUMP |
75	     ENABLE_TEX_STREAM_COORD_SET |
76	     TEX_STREAM_COORD_SET(1) |
77	     ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(1));
78   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
79	     MAP_UNIT(2) |
80	     DISABLE_TEX_STREAM_BUMP |
81	     ENABLE_TEX_STREAM_COORD_SET |
82	     TEX_STREAM_COORD_SET(2) |
83	     ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(2));
84   OUT_BATCH(_3DSTATE_MAP_TEX_STREAM_CMD |
85	     MAP_UNIT(3) |
86	     DISABLE_TEX_STREAM_BUMP |
87	     ENABLE_TEX_STREAM_COORD_SET |
88	     TEX_STREAM_COORD_SET(3) |
89	     ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(3));
90
91   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
92   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(0));
93   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
94   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(1));
95   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
96   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(2));
97   OUT_BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
98   OUT_BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(3));
99
100   OUT_BATCH(_3DSTATE_RASTER_RULES_CMD |
101	     ENABLE_POINT_RASTER_RULE |
102	     OGL_POINT_RASTER_RULE |
103	     ENABLE_LINE_STRIP_PROVOKE_VRTX |
104	     ENABLE_TRI_FAN_PROVOKE_VRTX |
105	     ENABLE_TRI_STRIP_PROVOKE_VRTX |
106	     LINE_STRIP_PROVOKE_VRTX(1) |
107	     TRI_FAN_PROVOKE_VRTX(2) |
108	     TRI_STRIP_PROVOKE_VRTX(2));
109
110   OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD |
111	     DISABLE_SCISSOR_RECT);
112
113   OUT_BATCH(_3DSTATE_SCISSOR_RECT_0_CMD);
114   OUT_BATCH(0);
115   OUT_BATCH(0);
116
117   OUT_BATCH(_3DSTATE_VERTEX_TRANSFORM);
118   OUT_BATCH(DISABLE_VIEWPORT_TRANSFORM | DISABLE_PERSPECTIVE_DIVIDE);
119
120   OUT_BATCH(_3DSTATE_W_STATE_CMD);
121   OUT_BATCH(MAGIC_W_STATE_DWORD1);
122   OUT_BATCH(0x3f800000 /* 1.0 in IEEE float */ );
123
124   OUT_BATCH(_3DSTATE_COLOR_FACTOR_CMD);
125   OUT_BATCH(0x80808080);	/* .5 required in alpha for GL_DOT3_RGBA_EXT */
126
127   OUT_BATCH(_3DSTATE_MAP_COORD_SETBIND_CMD);
128   OUT_BATCH(TEXBIND_SET3(TEXCOORDSRC_VTXSET_3) |
129	     TEXBIND_SET2(TEXCOORDSRC_VTXSET_2) |
130	     TEXBIND_SET1(TEXCOORDSRC_VTXSET_1) |
131	     TEXBIND_SET0(TEXCOORDSRC_VTXSET_0));
132
133   /* copy from mesa */
134   OUT_BATCH(_3DSTATE_INDPT_ALPHA_BLEND_CMD |
135	     DISABLE_INDPT_ALPHA_BLEND |
136	     ENABLE_ALPHA_BLENDFUNC |
137	     ABLENDFUNC_ADD);
138
139   OUT_BATCH(_3DSTATE_FOG_COLOR_CMD |
140	     FOG_COLOR_RED(0) |
141	     FOG_COLOR_GREEN(0) |
142	     FOG_COLOR_BLUE(0));
143
144   OUT_BATCH(_3DSTATE_CONST_BLEND_COLOR_CMD);
145   OUT_BATCH(0);
146
147   OUT_BATCH(_3DSTATE_MODES_1_CMD |
148	     ENABLE_COLR_BLND_FUNC |
149	     BLENDFUNC_ADD |
150	     ENABLE_SRC_BLND_FACTOR |
151	     SRC_BLND_FACT(BLENDFACTOR_ONE) |
152	     ENABLE_DST_BLND_FACTOR |
153	     DST_BLND_FACT(BLENDFACTOR_ZERO));
154   OUT_BATCH(_3DSTATE_MODES_2_CMD |
155	     ENABLE_GLOBAL_DEPTH_BIAS |
156	     GLOBAL_DEPTH_BIAS(0) |
157	     ENABLE_ALPHA_TEST_FUNC|
158	     ALPHA_TEST_FUNC(0) | /* always */
159	     ALPHA_REF_VALUE(0));
160   OUT_BATCH(_3DSTATE_MODES_3_CMD |
161	     ENABLE_DEPTH_TEST_FUNC |
162	     DEPTH_TEST_FUNC(0x2) | /* COMPAREFUNC_LESS */
163	     ENABLE_ALPHA_SHADE_MODE |
164	     ALPHA_SHADE_MODE(SHADE_MODE_LINEAR) |
165	     ENABLE_FOG_SHADE_MODE |
166	     FOG_SHADE_MODE(SHADE_MODE_LINEAR) |
167	     ENABLE_SPEC_SHADE_MODE |
168	     SPEC_SHADE_MODE(SHADE_MODE_LINEAR) |
169	     ENABLE_COLOR_SHADE_MODE |
170	     COLOR_SHADE_MODE(SHADE_MODE_LINEAR) |
171	     ENABLE_CULL_MODE | CULLMODE_NONE);
172
173   OUT_BATCH(_3DSTATE_MODES_4_CMD |
174	     ENABLE_LOGIC_OP_FUNC |
175	     LOGIC_OP_FUNC(LOGICOP_COPY) |
176	     ENABLE_STENCIL_TEST_MASK |
177	     STENCIL_TEST_MASK(0xff) |
178	     ENABLE_STENCIL_WRITE_MASK |
179	     STENCIL_WRITE_MASK(0xff));
180
181   OUT_BATCH(_3DSTATE_STENCIL_TEST_CMD |
182	     ENABLE_STENCIL_PARMS |
183	     STENCIL_FAIL_OP(0) | /* STENCILOP_KEEP */
184	     STENCIL_PASS_DEPTH_FAIL_OP(0) | /* STENCILOP_KEEP */
185	     STENCIL_PASS_DEPTH_PASS_OP(0) | /* STENCILOP_KEEP */
186	     ENABLE_STENCIL_TEST_FUNC |
187	     STENCIL_TEST_FUNC(0) | /* COMPAREFUNC_ALWAYS */
188	     ENABLE_STENCIL_REF_VALUE |
189	     STENCIL_REF_VALUE(0));
190
191   OUT_BATCH(_3DSTATE_MODES_5_CMD |
192	     FLUSH_TEXTURE_CACHE |
193	     ENABLE_SPRITE_POINT_TEX |
194	     SPRITE_POINT_TEX_OFF |
195	     ENABLE_FIXED_LINE_WIDTH |
196	     FIXED_LINE_WIDTH(0x2) |       /* 1.0 */
197	     ENABLE_FIXED_POINT_WIDTH |
198	     FIXED_POINT_WIDTH(1));
199
200   OUT_BATCH(_3DSTATE_ENABLES_1_CMD |
201	     DISABLE_LOGIC_OP |
202	     DISABLE_STENCIL_TEST |
203	     DISABLE_DEPTH_BIAS |
204	     DISABLE_SPEC_ADD |
205	     DISABLE_FOG |
206	     DISABLE_ALPHA_TEST |
207	     ENABLE_COLOR_BLEND |
208	     DISABLE_DEPTH_TEST);
209   OUT_BATCH(_3DSTATE_ENABLES_2_CMD |
210	     DISABLE_STENCIL_WRITE |
211	     ENABLE_TEX_CACHE |
212	     DISABLE_DITHER |
213	     ENABLE_COLOR_MASK |
214	     ENABLE_COLOR_WRITE |
215	     DISABLE_DEPTH_WRITE);
216
217   OUT_BATCH(_3DSTATE_STIPPLE);
218
219   /* Set default blend state */
220   OUT_BATCH(_3DSTATE_MAP_BLEND_OP_CMD(0) |
221	     TEXPIPE_COLOR |
222	     ENABLE_TEXOUTPUT_WRT_SEL |
223	     TEXOP_OUTPUT_CURRENT |
224	     DISABLE_TEX_CNTRL_STAGE |
225	     TEXOP_SCALE_1X |
226	     TEXOP_MODIFY_PARMS |
227	     TEXOP_LAST_STAGE | TEXBLENDOP_ARG1);
228   OUT_BATCH(_3DSTATE_MAP_BLEND_OP_CMD(0) |
229	     TEXPIPE_ALPHA |
230	     ENABLE_TEXOUTPUT_WRT_SEL |
231	     TEXOP_OUTPUT_CURRENT |
232	     TEXOP_SCALE_1X |
233	     TEXOP_MODIFY_PARMS | TEXBLENDOP_ARG1);
234   OUT_BATCH(_3DSTATE_MAP_BLEND_ARG_CMD(0) |
235	     TEXPIPE_COLOR |
236	     TEXBLEND_ARG1 |
237	     TEXBLENDARG_MODIFY_PARMS |
238	     TEXBLENDARG_DIFFUSE);
239   OUT_BATCH(_3DSTATE_MAP_BLEND_ARG_CMD(0) |
240	     TEXPIPE_ALPHA |
241	     TEXBLEND_ARG1 |
242	     TEXBLENDARG_MODIFY_PARMS |
243	     TEXBLENDARG_DIFFUSE);
244
245   OUT_BATCH(_3DSTATE_AA_CMD |
246	     AA_LINE_ECAAR_WIDTH_ENABLE |
247	     AA_LINE_ECAAR_WIDTH_1_0 |
248	     AA_LINE_REGION_WIDTH_ENABLE |
249	     AA_LINE_REGION_WIDTH_1_0 |
250	     AA_LINE_DISABLE);
251
252   ADVANCE_BATCH();
253}
254