b21df0a61ea9212b1d6adba1040b68dfd3a4c613
[mesa.git] / src / mesa / drivers / dri / sis / sis_context.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_dri.h"
36
37 #include "sis_context.h"
38 #include "sis_state.h"
39 #include "sis_dd.h"
40 #include "sis_span.h"
41 #include "sis_stencil.h"
42 #include "sis_tex.h"
43 #include "sis_tris.h"
44 #include "sis_alloc.h"
45
46 #include "imports.h"
47 #include "matrix.h"
48 #include "extensions.h"
49 #include "utils.h"
50 #include "framebuffer.h"
51
52 #include "drivers/common/driverfuncs.h"
53
54 #include "swrast/swrast.h"
55 #include "swrast_setup/swrast_setup.h"
56 #include "vbo/vbo.h"
57
58 #include "tnl/tnl.h"
59 #include "tnl/t_pipeline.h"
60
61 #define need_GL_ARB_multisample
62 #define need_GL_ARB_texture_compression
63 #define need_GL_ARB_vertex_buffer_object
64 #define need_GL_EXT_fog_coord
65 #define need_GL_EXT_secondary_color
66 #include "extension_helper.h"
67
68 #ifndef SIS_DEBUG
69 int SIS_DEBUG = 0;
70 #endif
71
72 int GlobalCurrentHwcx = -1;
73 int GlobalHwcxCountBase = 1;
74 int GlobalCmdQueueLen = 0;
75
76 struct dri_extension card_extensions[] =
77 {
78 { "GL_ARB_multisample", GL_ARB_multisample_functions },
79 { "GL_ARB_multitexture", NULL },
80 { "GL_ARB_texture_border_clamp", NULL },
81 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
82 { "GL_ARB_texture_mirrored_repeat", NULL },
83 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
84 /*{ "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },*/
85 { "GL_EXT_texture_lod_bias", NULL },
86 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
87 { "GL_EXT_stencil_wrap", NULL },
88 { "GL_MESA_ycbcr_texture", NULL },
89 { "GL_NV_blend_square", NULL },
90 { NULL, NULL }
91 };
92
93 struct dri_extension card_extensions_6326[] =
94 {
95 { "GL_ARB_multisample", GL_ARB_multisample_functions },
96 /*{ "GL_ARB_texture_border_clamp", NULL },*/
97 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
98 /*{ "GL_ARB_texture_mirrored_repeat", NULL },*/
99 /*{ "GL_MESA_ycbcr_texture", NULL },*/
100 { NULL, NULL }
101 };
102
103 static const struct dri_debug_control debug_control[] =
104 {
105 { "fall", DEBUG_FALLBACKS },
106 { NULL, 0 }
107 };
108
109 void
110 WaitEngIdle (sisContextPtr smesa)
111 {
112 GLuint engineState;
113
114 if (smesa->is6326) {
115 do {
116 engineState = MMIO_READ(REG_3D_EngineFire); /* XXX right reg? */
117 } while ((engineState & ENG_3DIDLEQE) != 0);
118 } else {
119 do {
120 engineState = MMIO_READ(REG_CommandQueue);
121 } while ((engineState & SiS_EngIdle) != SiS_EngIdle);
122 }
123 }
124
125 void
126 Wait2DEngIdle (sisContextPtr smesa)
127 {
128 GLuint engineState;
129
130 if (smesa->is6326) {
131 do {
132 engineState = MMIO_READ(REG_6326_BitBlt_Cmd);
133 } while ((engineState & BLT_BUSY) != 0);
134 } else {
135 do {
136 engineState = MMIO_READ(REG_CommandQueue);
137 } while ((engineState & SiS_EngIdle2d) != SiS_EngIdle2d);
138 }
139 }
140
141 /* To be called from mWait3DCmdQueue. Separate function for profiling
142 * purposes, and speed doesn't matter because we're spinning anyway.
143 */
144 void
145 WaitingFor3dIdle(sisContextPtr smesa, int wLen)
146 {
147 if (smesa->is6326) {
148 while (*(smesa->CurrentQueueLenPtr) < wLen) {
149 *(smesa->CurrentQueueLenPtr) =
150 ((GLuint)MMIO_READ(REG_3D_EngineFire) >> 16) * 2;
151 }
152 } else {
153 while (*(smesa->CurrentQueueLenPtr) < wLen) {
154 *(smesa->CurrentQueueLenPtr) =
155 (MMIO_READ(REG_CommandQueue) & MASK_QueueLen) - 20;
156 }
157 }
158 }
159
160 void sisReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer,
161 GLuint width, GLuint height)
162 {
163 sisContextPtr smesa = SIS_CONTEXT(ctx);
164
165 sisUpdateBufferSize(smesa);
166
167 _mesa_resize_framebuffer(ctx, drawbuffer, width, height);
168 }
169
170 GLboolean
171 sisCreateContext( const __GLcontextModes *glVisual,
172 __DRIcontextPrivate *driContextPriv,
173 void *sharedContextPrivate )
174 {
175 GLcontext *ctx, *shareCtx;
176 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
177 sisContextPtr smesa;
178 sisScreenPtr sisScreen;
179 int i;
180 struct dd_function_table functions;
181
182 smesa = (sisContextPtr)CALLOC( sizeof(*smesa) );
183 if (smesa == NULL)
184 return GL_FALSE;
185
186 /* Init default driver functions then plug in our SIS-specific functions
187 * (the texture functions are especially important)
188 */
189 _mesa_init_driver_functions(&functions);
190 sisInitDriverFuncs(&functions);
191 sisInitTextureFuncs(&functions);
192
193 /* Allocate the Mesa context */
194 if (sharedContextPrivate)
195 shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx;
196 else
197 shareCtx = NULL;
198 smesa->glCtx = _mesa_create_context( glVisual, shareCtx,
199 &functions, (void *) smesa);
200 if (!smesa->glCtx) {
201 FREE(smesa);
202 return GL_FALSE;
203 }
204 driContextPriv->driverPrivate = smesa;
205 ctx = smesa->glCtx;
206
207 sisScreen = smesa->sisScreen = (sisScreenPtr)(sPriv->private);
208
209 smesa->is6326 = GL_FALSE; /* XXX */
210 smesa->driContext = driContextPriv;
211 smesa->driScreen = sPriv;
212 smesa->driDrawable = NULL;
213 smesa->hHWContext = driContextPriv->hHWContext;
214 smesa->driHwLock = &sPriv->pSAREA->lock;
215 smesa->driFd = sPriv->fd;
216
217 smesa->virtualX = sisScreen->screenX;
218 smesa->virtualY = sisScreen->screenY;
219 smesa->bytesPerPixel = sisScreen->cpp;
220 smesa->IOBase = sisScreen->mmio.map;
221 smesa->Chipset = sisScreen->deviceID;
222
223 smesa->FbBase = sPriv->pFB;
224 smesa->displayWidth = sPriv->fbWidth;
225 smesa->front.pitch = sPriv->fbStride;
226
227 smesa->sarea = (SISSAREAPriv *)((char *)sPriv->pSAREA +
228 sisScreen->sarea_priv_offset);
229
230 /* support ARGB8888 and RGB565 */
231 switch (smesa->bytesPerPixel)
232 {
233 case 4:
234 smesa->redMask = 0x00ff0000;
235 smesa->greenMask = 0x0000ff00;
236 smesa->blueMask = 0x000000ff;
237 smesa->alphaMask = 0xff000000;
238 smesa->colorFormat = DST_FORMAT_ARGB_8888;
239 break;
240 case 2:
241 smesa->redMask = 0xf800;
242 smesa->greenMask = 0x07e0;
243 smesa->blueMask = 0x001f;
244 smesa->alphaMask = 0;
245 smesa->colorFormat = DST_FORMAT_RGB_565;
246 break;
247 default:
248 sis_fatal_error("Bad bytesPerPixel %d.\n", smesa->bytesPerPixel);
249 }
250
251 if (smesa->is6326) {
252 ctx->Const.MaxTextureUnits = 1;
253 ctx->Const.MaxTextureLevels = 9;
254 } else {
255 ctx->Const.MaxTextureUnits = 2;
256 ctx->Const.MaxTextureLevels = 11;
257 }
258 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
259 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
260
261 /* Parse configuration files */
262 driParseConfigFiles (&smesa->optionCache, &sisScreen->optionCache,
263 sisScreen->driScreen->myNum, "sis");
264
265 #if DO_DEBUG
266 SIS_DEBUG = driParseDebugString(getenv("SIS_DEBUG"), debug_control);
267 #endif
268
269 /* TODO: index mode */
270
271 smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength);
272 smesa->FrameCountPtr = &(smesa->sarea->FrameCount);
273
274 /* set AGP */
275 smesa->AGPSize = sisScreen->agp.size;
276 smesa->AGPBase = sisScreen->agp.map;
277 smesa->AGPAddr = sisScreen->agpBaseOffset;
278
279 /* Create AGP command buffer */
280 if (smesa->AGPSize != 0 &&
281 !driQueryOptionb(&smesa->optionCache, "agp_disable"))
282 {
283 smesa->vb = sisAllocAGP(smesa, 64 * 1024, &smesa->vb_agp_handle);
284 if (smesa->vb != NULL) {
285 smesa->using_agp = GL_TRUE;
286 smesa->vb_cur = smesa->vb;
287 smesa->vb_last = smesa->vb;
288 smesa->vb_end = smesa->vb + 64 * 1024;
289 smesa->vb_agp_offset = ((long)smesa->vb - (long)smesa->AGPBase +
290 (long)smesa->AGPAddr);
291 }
292 }
293 if (!smesa->using_agp) {
294 smesa->vb = malloc(64 * 1024);
295 if (smesa->vb == NULL) {
296 FREE(smesa);
297 return GL_FALSE;
298 }
299 smesa->vb_cur = smesa->vb;
300 smesa->vb_last = smesa->vb;
301 smesa->vb_end = smesa->vb + 64 * 1024;
302 }
303
304 smesa->GlobalFlag = 0L;
305
306 smesa->Fallback = 0;
307
308 /* Initialize the software rasterizer and helper modules.
309 */
310 _swrast_CreateContext( ctx );
311 _vbo_CreateContext( ctx );
312 _tnl_CreateContext( ctx );
313 _swsetup_CreateContext( ctx );
314
315 _swrast_allow_pixel_fog( ctx, GL_TRUE );
316 _swrast_allow_vertex_fog( ctx, GL_FALSE );
317 _tnl_allow_pixel_fog( ctx, GL_TRUE );
318 _tnl_allow_vertex_fog( ctx, GL_FALSE );
319
320 /* XXX these should really go right after _mesa_init_driver_functions() */
321 if (smesa->is6326) {
322 sis6326DDInitStateFuncs( ctx );
323 sis6326DDInitState( smesa ); /* Initializes smesa->zFormat, important */
324 } else {
325 sisDDInitStateFuncs( ctx );
326 sisDDInitState( smesa ); /* Initializes smesa->zFormat, important */
327 sisDDInitStencilFuncs( ctx );
328 }
329 sisInitTriFuncs( ctx );
330 sisDDInitSpanFuncs( ctx );
331
332 driInitExtensions( ctx, card_extensions, GL_FALSE );
333
334 for (i = 0; i < SIS_MAX_TEXTURES; i++) {
335 smesa->TexStates[i] = 0;
336 smesa->PrevTexFormat[i] = 0;
337 }
338
339 if (driQueryOptionb(&smesa->optionCache, "no_rast")) {
340 fprintf(stderr, "disabling 3D acceleration\n");
341 FALLBACK(smesa, SIS_FALLBACK_DISABLE, 1);
342 }
343 smesa->texture_depth = driQueryOptioni(&smesa->optionCache, "texture_depth");
344
345 return GL_TRUE;
346 }
347
348 void
349 sisDestroyContext ( __DRIcontextPrivate *driContextPriv )
350 {
351 sisContextPtr smesa = (sisContextPtr)driContextPriv->driverPrivate;
352
353 assert( smesa != NULL );
354
355 if ( smesa != NULL ) {
356 _swsetup_DestroyContext( smesa->glCtx );
357 _tnl_DestroyContext( smesa->glCtx );
358 _vbo_DestroyContext( smesa->glCtx );
359 _swrast_DestroyContext( smesa->glCtx );
360
361 if (smesa->using_agp)
362 sisFreeAGP(smesa, smesa->vb_agp_handle);
363
364 /* free the Mesa context */
365 /* XXX: Is the next line needed? The DriverCtx (smesa) reference is
366 * needed for sisDDDeleteTexture, since it needs to call the FB/AGP free
367 * function.
368 */
369 /* smesa->glCtx->DriverCtx = NULL; */
370 _mesa_destroy_context(smesa->glCtx);
371 }
372
373 FREE( smesa );
374 }
375
376 GLboolean
377 sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
378 __DRIdrawablePrivate *driDrawPriv,
379 __DRIdrawablePrivate *driReadPriv )
380 {
381 if ( driContextPriv ) {
382 GET_CURRENT_CONTEXT(ctx);
383 sisContextPtr oldSisCtx = ctx ? SIS_CONTEXT(ctx) : NULL;
384 sisContextPtr newSisCtx = (sisContextPtr) driContextPriv->driverPrivate;
385 struct gl_framebuffer *drawBuffer, *readBuffer;
386
387 if ( newSisCtx != oldSisCtx) {
388 newSisCtx->GlobalFlag = GFLAG_ALL;
389 }
390
391 newSisCtx->driDrawable = driDrawPriv;
392
393 drawBuffer = (GLframebuffer *)driDrawPriv->driverPrivate;
394 readBuffer = (GLframebuffer *)driReadPriv->driverPrivate;
395
396 _mesa_make_current( newSisCtx->glCtx, drawBuffer, readBuffer );
397
398 sisUpdateBufferSize( newSisCtx );
399 sisUpdateClipping( newSisCtx->glCtx );
400 } else {
401 _mesa_make_current( NULL, NULL, NULL );
402 }
403
404 return GL_TRUE;
405 }
406
407 GLboolean
408 sisUnbindContext( __DRIcontextPrivate *driContextPriv )
409 {
410 return GL_TRUE;
411 }
412
413 void
414 sis_update_render_state( sisContextPtr smesa )
415 {
416 __GLSiSHardware *prev = &smesa->prev;
417
418 mWait3DCmdQueue (45);
419
420 if (smesa->GlobalFlag & GFLAG_ENABLESETTING) {
421 if (!smesa->clearTexCache) {
422 MMIO(REG_3D_TEnable, prev->hwCapEnable);
423 } else {
424 MMIO(REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear);
425 MMIO(REG_3D_TEnable, prev->hwCapEnable);
426 smesa->clearTexCache = GL_FALSE;
427 }
428 }
429
430 if (smesa->GlobalFlag & GFLAG_ENABLESETTING2)
431 MMIO(REG_3D_TEnable2, prev->hwCapEnable2);
432
433 /* Z Setting */
434 if (smesa->GlobalFlag & GFLAG_ZSETTING)
435 {
436 MMIO(REG_3D_ZSet, prev->hwZ);
437 MMIO(REG_3D_ZStWriteMask, prev->hwZMask);
438 MMIO(REG_3D_ZAddress, prev->hwOffsetZ);
439 }
440
441 /* Alpha Setting */
442 if (smesa->GlobalFlag & GFLAG_ALPHASETTING)
443 MMIO(REG_3D_AlphaSet, prev->hwAlpha);
444
445 if (smesa->GlobalFlag & GFLAG_DESTSETTING) {
446 MMIO(REG_3D_DstSet, prev->hwDstSet);
447 MMIO(REG_3D_DstAlphaWriteMask, prev->hwDstMask);
448 MMIO(REG_3D_DstAddress, prev->hwOffsetDest);
449 }
450
451 /* Line Setting */
452 #if 0
453 if (smesa->GlobalFlag & GFLAG_LINESETTING)
454 MMIO(REG_3D_LinePattern, prev->hwLinePattern);
455 #endif
456
457 /* Fog Setting */
458 if (smesa->GlobalFlag & GFLAG_FOGSETTING)
459 {
460 MMIO(REG_3D_FogSet, prev->hwFog);
461 MMIO(REG_3D_FogInverseDistance, prev->hwFogInverse);
462 MMIO(REG_3D_FogFarDistance, prev->hwFogFar);
463 MMIO(REG_3D_FogFactorDensity, prev->hwFogDensity);
464 }
465
466 /* Stencil Setting */
467 if (smesa->GlobalFlag & GFLAG_STENCILSETTING) {
468 MMIO(REG_3D_StencilSet, prev->hwStSetting);
469 MMIO(REG_3D_StencilSet2, prev->hwStSetting2);
470 }
471
472 /* Miscellaneous Setting */
473 if (smesa->GlobalFlag & GFLAG_DSTBLEND)
474 MMIO(REG_3D_DstBlendMode, prev->hwDstSrcBlend);
475 if (smesa->GlobalFlag & GFLAG_CLIPPING) {
476 MMIO(REG_3D_ClipTopBottom, prev->clipTopBottom);
477 MMIO(REG_3D_ClipLeftRight, prev->clipLeftRight);
478 }
479
480 smesa->GlobalFlag &= ~GFLAG_RENDER_STATES;
481 }
482
483 void
484 sis_update_texture_state (sisContextPtr smesa)
485 {
486 __GLSiSHardware *prev = &smesa->prev;
487
488 mWait3DCmdQueue (55);
489 if (smesa->clearTexCache || (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS)) {
490 MMIO(REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear);
491 MMIO(REG_3D_TEnable, prev->hwCapEnable);
492 smesa->clearTexCache = GL_FALSE;
493 }
494
495 /* Texture Setting */
496 if (smesa->GlobalFlag & CFLAG_TEXTURERESET)
497 MMIO(REG_3D_TextureSet, prev->texture[0].hwTextureSet);
498
499 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP)
500 MMIO(REG_3D_TextureMip, prev->texture[0].hwTextureMip);
501
502 /*
503 MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh);
504 MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow);
505 */
506
507 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR)
508 MMIO(REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor);
509
510 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS) {
511 switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8)
512 {
513 case 11:
514 MMIO(REG_3D_TextureAddress11, prev->texture[0].texOffset11);
515 case 10:
516 MMIO(REG_3D_TextureAddress10, prev->texture[0].texOffset10);
517 MMIO(REG_3D_TexturePitch10, prev->texture[0].texPitch10);
518 case 9:
519 MMIO(REG_3D_TextureAddress9, prev->texture[0].texOffset9);
520 case 8:
521 MMIO(REG_3D_TextureAddress8, prev->texture[0].texOffset8);
522 MMIO(REG_3D_TexturePitch8, prev->texture[0].texPitch89);
523 case 7:
524 MMIO(REG_3D_TextureAddress7, prev->texture[0].texOffset7);
525 case 6:
526 MMIO(REG_3D_TextureAddress6, prev->texture[0].texOffset6);
527 MMIO(REG_3D_TexturePitch6, prev->texture[0].texPitch67);
528 case 5:
529 MMIO(REG_3D_TextureAddress5, prev->texture[0].texOffset5);
530 case 4:
531 MMIO(REG_3D_TextureAddress4, prev->texture[0].texOffset4);
532 MMIO(REG_3D_TexturePitch4, prev->texture[0].texPitch45);
533 case 3:
534 MMIO(REG_3D_TextureAddress3, prev->texture[0].texOffset3);
535 case 2:
536 MMIO(REG_3D_TextureAddress2, prev->texture[0].texOffset2);
537 MMIO(REG_3D_TexturePitch2, prev->texture[0].texPitch23);
538 case 1:
539 MMIO(REG_3D_TextureAddress1, prev->texture[0].texOffset1);
540 case 0:
541 MMIO(REG_3D_TextureAddress0, prev->texture[0].texOffset0);
542 MMIO(REG_3D_TexturePitch0, prev->texture[0].texPitch01);
543 }
544 }
545 if (smesa->GlobalFlag & CFLAG_TEXTURERESET_1)
546 MMIO(REG_3D_Texture1Set, prev->texture[1].hwTextureSet);
547 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP_1)
548 MMIO(REG_3D_Texture1Mip, prev->texture[1].hwTextureMip);
549
550 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR_1) {
551 MMIO(REG_3D_Texture1BorderColor,
552 prev->texture[1].hwTextureBorderColor);
553 }
554 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS_1) {
555 switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8)
556 {
557 case 11:
558 MMIO(REG_3D_Texture1Address11, prev->texture[1].texOffset11);
559 case 10:
560 MMIO(REG_3D_Texture1Address10, prev->texture[1].texOffset10);
561 MMIO(REG_3D_Texture1Pitch10, prev->texture[1].texPitch10);
562 case 9:
563 MMIO(REG_3D_Texture1Address9, prev->texture[1].texOffset9);
564 case 8:
565 MMIO(REG_3D_Texture1Address8, prev->texture[1].texOffset8);
566 MMIO(REG_3D_Texture1Pitch8, prev->texture[1].texPitch89);
567 case 7:
568 MMIO(REG_3D_Texture1Address7, prev->texture[1].texOffset7);
569 case 6:
570 MMIO(REG_3D_Texture1Address6, prev->texture[1].texOffset6);
571 MMIO(REG_3D_Texture1Pitch6, prev->texture[1].texPitch67);
572 case 5:
573 MMIO(REG_3D_Texture1Address5, prev->texture[1].texOffset5);
574 case 4:
575 MMIO(REG_3D_Texture1Address4, prev->texture[1].texOffset4);
576 MMIO(REG_3D_Texture1Pitch4, prev->texture[1].texPitch45);
577 case 3:
578 MMIO(REG_3D_Texture1Address3, prev->texture[1].texOffset3);
579 case 2:
580 MMIO(REG_3D_Texture1Address2, prev->texture[1].texOffset2);
581 MMIO(REG_3D_Texture1Pitch2, prev->texture[1].texPitch23);
582 case 1:
583 MMIO(REG_3D_Texture1Address1, prev->texture[1].texOffset1);
584 case 0:
585 MMIO(REG_3D_Texture1Address0, prev->texture[1].texOffset0);
586 MMIO(REG_3D_Texture1Pitch0, prev->texture[1].texPitch01);
587 }
588 }
589
590 /* texture environment */
591 if (smesa->GlobalFlag & GFLAG_TEXTUREENV) {
592 MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
593 MMIO(REG_3D_TextureColorBlendSet0, prev->hwTexBlendColor0);
594 MMIO(REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0);
595 }
596 if (smesa->GlobalFlag & GFLAG_TEXTUREENV_1) {
597 MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
598 MMIO(REG_3D_TextureColorBlendSet1, prev->hwTexBlendColor1);
599 MMIO(REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1);
600 }
601
602 smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES;
603 }
604
605 void
606 sis6326_update_render_state( sisContextPtr smesa )
607 {
608 __GLSiSHardware *prev = &smesa->prev;
609
610 mWait3DCmdQueue (45);
611
612 if (smesa->GlobalFlag & GFLAG_ENABLESETTING) {
613 if (!smesa->clearTexCache) {
614 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
615 } else {
616 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable & ~S_ENABLE_TextureCache);
617 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
618 smesa->clearTexCache = GL_FALSE;
619 }
620 }
621
622 /* Z Setting */
623 if (smesa->GlobalFlag & GFLAG_ZSETTING) {
624 MMIO(REG_6326_3D_ZSet, prev->hwZ);
625 MMIO(REG_6326_3D_ZAddress, prev->hwOffsetZ);
626 }
627
628 /* Alpha Setting */
629 if (smesa->GlobalFlag & GFLAG_ALPHASETTING)
630 MMIO(REG_6326_3D_AlphaSet, prev->hwAlpha);
631
632 if (smesa->GlobalFlag & GFLAG_DESTSETTING) {
633 MMIO(REG_6326_3D_DstSet, prev->hwDstSet);
634 MMIO(REG_6326_3D_DstAddress, prev->hwOffsetDest);
635 }
636
637 /* Fog Setting */
638 if (smesa->GlobalFlag & GFLAG_FOGSETTING) {
639 MMIO(REG_6326_3D_FogSet, prev->hwFog);
640 }
641
642 /* Miscellaneous Setting */
643 if (smesa->GlobalFlag & GFLAG_DSTBLEND)
644 MMIO(REG_6326_3D_DstSrcBlendMode, prev->hwDstSrcBlend);
645
646 if (smesa->GlobalFlag & GFLAG_CLIPPING) {
647 MMIO(REG_6326_3D_ClipTopBottom, prev->clipTopBottom);
648 MMIO(REG_6326_3D_ClipLeftRight, prev->clipLeftRight);
649 }
650
651 smesa->GlobalFlag &= ~GFLAG_RENDER_STATES;
652 }
653
654 void
655 sis6326_update_texture_state (sisContextPtr smesa)
656 {
657 __GLSiSHardware *prev = &smesa->prev;
658
659 mWait3DCmdQueue (55);
660 if (smesa->clearTexCache || (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS)) {
661 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable & ~S_ENABLE_TextureCache);
662 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
663 smesa->clearTexCache = GL_FALSE;
664 }
665
666 /* Texture Setting */
667 if (smesa->GlobalFlag & CFLAG_TEXTURERESET)
668 MMIO(REG_6326_3D_TextureSet, prev->texture[0].hwTextureSet);
669
670 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP)
671 MMIO(REG_6326_3D_TextureWidthHeight, prev->texture[0].hwTexWidthHeight);
672
673 /*
674 MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh);
675 MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow);
676 */
677
678 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR)
679 MMIO(REG_6326_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor);
680
681 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS) {
682 switch ((prev->texture[0].hwTextureSet & MASK_6326_TextureLevel) >> 8)
683 {
684 case 9:
685 MMIO(REG_6326_3D_TextureAddress9, prev->texture[0].texOffset9);
686 /* FALLTHROUGH */
687 case 8:
688 MMIO(REG_6326_3D_TextureAddress8, prev->texture[0].texOffset8);
689 MMIO(REG_6326_3D_TexturePitch89, prev->texture[0].texPitch89);
690 /* FALLTHROUGH */
691 case 7:
692 MMIO(REG_6326_3D_TextureAddress7, prev->texture[0].texOffset7);
693 /* FALLTHROUGH */
694 case 6:
695 MMIO(REG_6326_3D_TextureAddress6, prev->texture[0].texOffset6);
696 MMIO(REG_6326_3D_TexturePitch67, prev->texture[0].texPitch67);
697 /* FALLTHROUGH */
698 case 5:
699 MMIO(REG_6326_3D_TextureAddress5, prev->texture[0].texOffset5);
700 /* FALLTHROUGH */
701 case 4:
702 MMIO(REG_6326_3D_TextureAddress4, prev->texture[0].texOffset4);
703 MMIO(REG_6326_3D_TexturePitch45, prev->texture[0].texPitch45);
704 /* FALLTHROUGH */
705 case 3:
706 MMIO(REG_6326_3D_TextureAddress3, prev->texture[0].texOffset3);
707 /* FALLTHROUGH */
708 case 2:
709 MMIO(REG_6326_3D_TextureAddress2, prev->texture[0].texOffset2);
710 MMIO(REG_6326_3D_TexturePitch23, prev->texture[0].texPitch23);
711 /* FALLTHROUGH */
712 case 1:
713 MMIO(REG_6326_3D_TextureAddress1, prev->texture[0].texOffset1);
714 /* FALLTHROUGH */
715 case 0:
716 MMIO(REG_6326_3D_TextureAddress0, prev->texture[0].texOffset0);
717 MMIO(REG_6326_3D_TexturePitch01, prev->texture[0].texPitch01);
718 break;
719 }
720 }
721
722 /* texture environment */
723 if (smesa->GlobalFlag & GFLAG_TEXTUREENV) {
724 MMIO(REG_6326_3D_TextureBlendSet, prev->hwTexBlendSet);
725 }
726
727 smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES;
728 }