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