Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_context.c
1 /*
2 * Author: Max Lingua <sunmax@libero.it>
3 */
4
5 #include "s3v_context.h"
6
7 #include "swrast/swrast.h"
8 #include "swrast_setup/swrast_setup.h"
9 #include "vbo/vbo.h"
10
11 #include "tnl/tnl.h"
12 #include "tnl/t_pipeline.h"
13
14 #include "context.h"
15 #include "simple_list.h"
16 #include "matrix.h"
17 #include "extensions.h"
18 #if defined(USE_X86_ASM)
19 #include "x86/common_x86_asm.h"
20 #endif
21 #include "simple_list.h"
22 #include "mm.h"
23
24 #include "drivers/common/driverfuncs.h"
25 #include "s3v_vb.h"
26 #include "s3v_tris.h"
27
28 #if 0
29 extern const struct tnl_pipeline_stage _s3v_render_stage;
30
31 static const struct tnl_pipeline_stage *s3v_pipeline[] = {
32 &_tnl_vertex_transform_stage,
33 &_tnl_normal_transform_stage,
34 &_tnl_lighting_stage,
35 &_tnl_fog_coordinate_stage,
36 &_tnl_texgen_stage,
37 &_tnl_texture_transform_stage,
38 /* REMOVE: point attenuation stage */
39 #if 1
40 &_s3v_render_stage, /* ADD: unclipped rastersetup-to-dma */
41 #endif
42 &_tnl_render_stage,
43 0,
44 };
45 #endif
46
47 GLboolean s3vCreateContext(const __GLcontextModes *glVisual,
48 __DRIcontextPrivate *driContextPriv,
49 void *sharedContextPrivate)
50 {
51 GLcontext *ctx, *shareCtx;
52 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
53 s3vContextPtr vmesa;
54 s3vScreenPtr s3vScrn;
55 S3VSAREAPtr saPriv=(S3VSAREAPtr)(((char*)sPriv->pSAREA) +
56 sizeof(drm_sarea_t));
57 struct dd_function_table functions;
58
59 DEBUG_WHERE(("*** s3vCreateContext ***\n"));
60
61 vmesa = (s3vContextPtr) CALLOC( sizeof(*vmesa) );
62 if ( !vmesa ) return GL_FALSE;
63
64 /* Allocate the Mesa context */
65 if (sharedContextPrivate)
66 shareCtx = ((s3vContextPtr) sharedContextPrivate)->glCtx;
67 else
68 shareCtx = NULL;
69
70 _mesa_init_driver_functions(&functions);
71
72 vmesa->glCtx = _mesa_create_context(glVisual, shareCtx, &functions,
73 (void *)vmesa);
74 if (!vmesa->glCtx) {
75 FREE(vmesa);
76 return GL_FALSE;
77 }
78
79 vmesa->driContext = driContextPriv;
80 vmesa->driScreen = sPriv;
81 vmesa->driDrawable = NULL; /* Set by XMesaMakeCurrent */
82
83 vmesa->hHWContext = driContextPriv->hHWContext;
84 vmesa->driHwLock = (drmLock *)&sPriv->pSAREA->lock;
85 vmesa->driFd = sPriv->fd;
86 vmesa->sarea = saPriv;
87
88 s3vScrn = vmesa->s3vScreen = (s3vScreenPtr)(sPriv->private);
89
90 ctx = vmesa->glCtx;
91
92 ctx->Const.MaxTextureLevels = 11; /* it is (11-1) -> 1024 * 1024 FIXME */
93
94 ctx->Const.MaxTextureUnits = 1; /* FIXME: or 2 ? */
95
96 /* No wide points.
97 */
98 ctx->Const.MinPointSize = 1.0;
99 ctx->Const.MinPointSizeAA = 1.0;
100 ctx->Const.MaxPointSize = 1.0;
101 ctx->Const.MaxPointSizeAA = 1.0;
102
103 /* No wide lines.
104 */
105 ctx->Const.MinLineWidth = 1.0;
106 ctx->Const.MinLineWidthAA = 1.0;
107 ctx->Const.MaxLineWidth = 1.0;
108 ctx->Const.MaxLineWidthAA = 1.0;
109 ctx->Const.LineWidthGranularity = 1.0;
110
111 vmesa->texHeap = mmInit( 0, vmesa->s3vScreen->textureSize );
112 DEBUG(("vmesa->s3vScreen->textureSize = 0x%x\n",
113 vmesa->s3vScreen->textureSize));
114
115 /* NOTE */
116 /* mmInit(offset, size); */
117
118 /* allocates a structure like this:
119
120 struct mem_block_t {
121 struct mem_block_t *next;
122 struct mem_block_t *heap;
123 int ofs,size;
124 int align;
125 int free:1;
126 int reserved:1;
127 };
128
129 */
130
131 make_empty_list(&vmesa->TexObjList);
132 make_empty_list(&vmesa->SwappedOut);
133
134 vmesa->CurrentTexObj[0] = 0;
135 vmesa->CurrentTexObj[1] = 0; /* FIXME */
136
137 vmesa->RenderIndex = ~0;
138
139 /* Initialize the software rasterizer and helper modules.
140 */
141 _swrast_CreateContext( ctx );
142 _vbo_CreateContext( ctx );
143 _tnl_CreateContext( ctx );
144 _swsetup_CreateContext( ctx );
145
146 /* Install the customized pipeline:
147 */
148 #if 0
149 _tnl_destroy_pipeline( ctx );
150 _tnl_install_pipeline( ctx, s3v_pipeline );
151 #endif
152 /* Configure swrast to match hardware characteristics:
153 */
154 #if 0
155 _swrast_allow_pixel_fog( ctx, GL_FALSE );
156 _swrast_allow_vertex_fog( ctx, GL_TRUE );
157 #endif
158 vmesa->_3d_mode = 0;
159
160 /* 3D lines / gouraud tris */
161 vmesa->CMD = ( AUTO_EXEC_ON | HW_CLIP_ON | DEST_COL_1555
162 | FOG_OFF | ALPHA_OFF | Z_OFF | Z_UPDATE_OFF
163 | Z_LESS | TEX_WRAP_ON | TEX_MODULATE | LINEAR
164 | TEX_COL_ARGB1555 | CMD_3D );
165
166 vmesa->_alpha[0] = vmesa->_alpha[1] = ALPHA_OFF;
167 vmesa->alpha_cmd = vmesa->_alpha[0];
168 vmesa->_tri[0] = DO_GOURAUD_TRI;
169 vmesa->_tri[1] = DO_TEX_LIT_TRI;
170 vmesa->prim_cmd = vmesa->_tri[0];
171
172 /* printf("first vmesa->CMD = 0x%x\n", vmesa->CMD); */
173
174 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
175
176 s3vInitVB( ctx );
177 s3vInitExtensions( ctx );
178 s3vInitDriverFuncs( ctx );
179 s3vInitStateFuncs( ctx );
180 s3vInitSpanFuncs( ctx );
181 s3vInitTextureFuncs( ctx );
182 s3vInitTriFuncs( ctx );
183 s3vInitState( vmesa );
184
185 driContextPriv->driverPrivate = (void *)vmesa;
186
187 /* HACK */
188 vmesa->bufSize = S3V_DMA_BUF_SZ;
189
190 DEBUG(("vmesa->bufSize = %i\n", vmesa->bufSize));
191 DEBUG(("vmesa->bufCount = %i\n", vmesa->bufCount));
192
193
194 /* dma init */
195 DEBUG_BUFS(("GET_FIRST_DMA\n"));
196
197 vmesa->_bufNum = 0;
198
199 GET_FIRST_DMA(vmesa->driFd, vmesa->hHWContext,
200 1, &(vmesa->bufIndex[0]), &(vmesa->bufSize),
201 &vmesa->_buf[0], &vmesa->bufCount, s3vScrn);
202
203 GET_FIRST_DMA(vmesa->driFd, vmesa->hHWContext,
204 1, &(vmesa->bufIndex[1]), &(vmesa->bufSize),
205 &vmesa->_buf[1], &vmesa->bufCount, s3vScrn);
206
207 vmesa->buf = vmesa->_buf[vmesa->_bufNum];
208
209 /*
210 vmesa->CMD = (AUTO_EXEC_ON | HW_CLIP_ON | DEST_COL_1555
211 | FOG_OFF | ALPHA_OFF | Z_OFF | Z_UPDATE_OFF
212 | DO_GOURAUD_TRI | CMD_3D);
213
214 vmesa->TexOffset = vmesa->s3vScreen->texOffset;
215 */
216
217 /* ... but we should support only 15 bit in virge (out of 8/15/24)... */
218
219 DEBUG(("glVisual->depthBits = %i\n", glVisual->depthBits));
220
221 switch (glVisual->depthBits) {
222 case 8:
223 break;
224
225 case 15:
226 case 16:
227 vmesa->depth_scale = 1.0f / 0xffff;
228 break;
229 case 24:
230 vmesa->depth_scale = 1.0f / 0xffffff;
231 break;
232 default:
233 break;
234 }
235
236 vmesa->cull_zero = 0.0f;
237
238 vmesa->DepthSize = glVisual->depthBits;
239 vmesa->Flags = S3V_FRONT_BUFFER;
240 vmesa->Flags |= (glVisual->doubleBufferMode ? S3V_BACK_BUFFER : 0);
241 vmesa->Flags |= (vmesa->DepthSize > 0 ? S3V_DEPTH_BUFFER : 0);
242
243 vmesa->EnabledFlags = S3V_FRONT_BUFFER;
244 vmesa->EnabledFlags |= (glVisual->doubleBufferMode ? S3V_BACK_BUFFER : 0);
245
246
247 if (vmesa->Flags & S3V_BACK_BUFFER) {
248 vmesa->readOffset = vmesa->drawOffset = vmesa->s3vScreen->backOffset;
249 } else {
250 vmesa->readOffset = vmesa->drawOffset = 0;
251 }
252
253 s3vInitHW( vmesa );
254
255 driContextPriv->driverPrivate = (void *)vmesa;
256
257 return GL_TRUE;
258 }