📄 sis_context.c
字号:
/**************************************************************************Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.Copyright 2003 Eric AnholtAll Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ *//* * Authors: * Sung-Ching Lin <sclin@sis.com.tw> * Eric Anholt <anholt@FreeBSD.org> */#include "sis_dri.h"#include "sis_context.h"#include "sis_state.h"#include "sis_dd.h"#include "sis_span.h"#include "sis_stencil.h"#include "sis_tex.h"#include "sis_tris.h"#include "sis_alloc.h"#include "imports.h"#include "matrix.h"#include "extensions.h"#include "utils.h"#include "framebuffer.h"#include "drivers/common/driverfuncs.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "vbo/vbo.h"#include "tnl/tnl.h"#include "tnl/t_pipeline.h"#define need_GL_ARB_multisample#define need_GL_ARB_texture_compression#define need_GL_ARB_vertex_buffer_object#define need_GL_EXT_fog_coord#define need_GL_EXT_secondary_color#include "extension_helper.h"#ifndef SIS_DEBUGint SIS_DEBUG = 0;#endifint GlobalCurrentHwcx = -1;int GlobalHwcxCountBase = 1;int GlobalCmdQueueLen = 0;struct dri_extension card_extensions[] ={ { "GL_ARB_multisample", GL_ARB_multisample_functions }, { "GL_ARB_multitexture", NULL }, { "GL_ARB_texture_border_clamp", NULL }, { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, { "GL_ARB_texture_mirrored_repeat", NULL }, { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions }, /*{ "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },*/ { "GL_EXT_texture_lod_bias", NULL }, { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions }, { "GL_EXT_stencil_wrap", NULL }, { "GL_MESA_ycbcr_texture", NULL }, { "GL_NV_blend_square", NULL }, { NULL, NULL }};struct dri_extension card_extensions_6326[] ={ { "GL_ARB_multisample", GL_ARB_multisample_functions }, /*{ "GL_ARB_texture_border_clamp", NULL },*/ { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, /*{ "GL_ARB_texture_mirrored_repeat", NULL },*/ /*{ "GL_MESA_ycbcr_texture", NULL },*/ { NULL, NULL }};static const struct dri_debug_control debug_control[] ={ { "fall", DEBUG_FALLBACKS }, { NULL, 0 }};voidWaitEngIdle (sisContextPtr smesa){ GLuint engineState; if (smesa->is6326) { do { engineState = MMIO_READ(REG_3D_EngineFire); /* XXX right reg? */ } while ((engineState & ENG_3DIDLEQE) != 0); } else { do { engineState = MMIO_READ(REG_CommandQueue); } while ((engineState & SiS_EngIdle) != SiS_EngIdle); }}voidWait2DEngIdle (sisContextPtr smesa){ GLuint engineState; if (smesa->is6326) { do { engineState = MMIO_READ(REG_6326_BitBlt_Cmd); } while ((engineState & BLT_BUSY) != 0); } else { do { engineState = MMIO_READ(REG_CommandQueue); } while ((engineState & SiS_EngIdle2d) != SiS_EngIdle2d); }}/* To be called from mWait3DCmdQueue. Separate function for profiling * purposes, and speed doesn't matter because we're spinning anyway. */voidWaitingFor3dIdle(sisContextPtr smesa, int wLen){ if (smesa->is6326) { while (*(smesa->CurrentQueueLenPtr) < wLen) { *(smesa->CurrentQueueLenPtr) = ((GLuint)MMIO_READ(REG_3D_EngineFire) >> 16) * 2; } } else { while (*(smesa->CurrentQueueLenPtr) < wLen) { *(smesa->CurrentQueueLenPtr) = (MMIO_READ(REG_CommandQueue) & MASK_QueueLen) - 20; } }}void sisReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer, GLuint width, GLuint height){ sisContextPtr smesa = SIS_CONTEXT(ctx); sisUpdateBufferSize(smesa); _mesa_resize_framebuffer(ctx, drawbuffer, width, height);}GLbooleansisCreateContext( const __GLcontextModes *glVisual, __DRIcontextPrivate *driContextPriv, void *sharedContextPrivate ){ GLcontext *ctx, *shareCtx; __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; sisContextPtr smesa; sisScreenPtr sisScreen; int i; struct dd_function_table functions; smesa = (sisContextPtr)CALLOC( sizeof(*smesa) ); if (smesa == NULL) return GL_FALSE; /* Init default driver functions then plug in our SIS-specific functions * (the texture functions are especially important) */ _mesa_init_driver_functions(&functions); sisInitDriverFuncs(&functions); sisInitTextureFuncs(&functions); /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx; else shareCtx = NULL; smesa->glCtx = _mesa_create_context( glVisual, shareCtx, &functions, (void *) smesa); if (!smesa->glCtx) { FREE(smesa); return GL_FALSE; } driContextPriv->driverPrivate = smesa; ctx = smesa->glCtx; sisScreen = smesa->sisScreen = (sisScreenPtr)(sPriv->private); smesa->is6326 = GL_FALSE; /* XXX */ smesa->driContext = driContextPriv; smesa->driScreen = sPriv; smesa->driDrawable = NULL; smesa->hHWContext = driContextPriv->hHWContext; smesa->driHwLock = &sPriv->pSAREA->lock; smesa->driFd = sPriv->fd; smesa->virtualX = sisScreen->screenX; smesa->virtualY = sisScreen->screenY; smesa->bytesPerPixel = sisScreen->cpp; smesa->IOBase = sisScreen->mmio.map; smesa->Chipset = sisScreen->deviceID; smesa->FbBase = sPriv->pFB; smesa->displayWidth = sPriv->fbWidth; smesa->front.pitch = sPriv->fbStride; smesa->sarea = (SISSAREAPriv *)((char *)sPriv->pSAREA + sisScreen->sarea_priv_offset); /* support ARGB8888 and RGB565 */ switch (smesa->bytesPerPixel) { case 4: smesa->redMask = 0x00ff0000; smesa->greenMask = 0x0000ff00; smesa->blueMask = 0x000000ff; smesa->alphaMask = 0xff000000; smesa->colorFormat = DST_FORMAT_ARGB_8888; break; case 2: smesa->redMask = 0xf800; smesa->greenMask = 0x07e0; smesa->blueMask = 0x001f; smesa->alphaMask = 0; smesa->colorFormat = DST_FORMAT_RGB_565; break; default: sis_fatal_error("Bad bytesPerPixel %d.\n", smesa->bytesPerPixel); } if (smesa->is6326) { ctx->Const.MaxTextureUnits = 1; ctx->Const.MaxTextureLevels = 9; } else { ctx->Const.MaxTextureUnits = 2; ctx->Const.MaxTextureLevels = 11; } ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits; ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits; /* Parse configuration files */ driParseConfigFiles (&smesa->optionCache, &sisScreen->optionCache, sisScreen->driScreen->myNum, "sis");#if DO_DEBUG SIS_DEBUG = driParseDebugString(getenv("SIS_DEBUG"), debug_control);#endif /* TODO: index mode */ smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength); smesa->FrameCountPtr = &(smesa->sarea->FrameCount); /* set AGP */ smesa->AGPSize = sisScreen->agp.size; smesa->AGPBase = sisScreen->agp.map; smesa->AGPAddr = sisScreen->agpBaseOffset; /* Create AGP command buffer */ if (smesa->AGPSize != 0 && !driQueryOptionb(&smesa->optionCache, "agp_disable")) { smesa->vb = sisAllocAGP(smesa, 64 * 1024, &smesa->vb_agp_handle); if (smesa->vb != NULL) { smesa->using_agp = GL_TRUE; smesa->vb_cur = smesa->vb; smesa->vb_last = smesa->vb; smesa->vb_end = smesa->vb + 64 * 1024; smesa->vb_agp_offset = ((long)smesa->vb - (long)smesa->AGPBase + (long)smesa->AGPAddr); } } if (!smesa->using_agp) { smesa->vb = malloc(64 * 1024); if (smesa->vb == NULL) { FREE(smesa); return GL_FALSE; } smesa->vb_cur = smesa->vb; smesa->vb_last = smesa->vb; smesa->vb_end = smesa->vb + 64 * 1024; } smesa->GlobalFlag = 0L; smesa->Fallback = 0; /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext( ctx ); _vbo_CreateContext( ctx ); _tnl_CreateContext( ctx ); _swsetup_CreateContext( ctx ); _swrast_allow_pixel_fog( ctx, GL_TRUE ); _swrast_allow_vertex_fog( ctx, GL_FALSE ); _tnl_allow_pixel_fog( ctx, GL_TRUE ); _tnl_allow_vertex_fog( ctx, GL_FALSE ); /* XXX these should really go right after _mesa_init_driver_functions() */ if (smesa->is6326) { sis6326DDInitStateFuncs( ctx ); sis6326DDInitState( smesa ); /* Initializes smesa->zFormat, important */ } else { sisDDInitStateFuncs( ctx ); sisDDInitState( smesa ); /* Initializes smesa->zFormat, important */ sisDDInitStencilFuncs( ctx ); } sisInitTriFuncs( ctx ); sisDDInitSpanFuncs( ctx ); driInitExtensions( ctx, card_extensions, GL_FALSE ); for (i = 0; i < SIS_MAX_TEXTURES; i++) { smesa->TexStates[i] = 0; smesa->PrevTexFormat[i] = 0; } if (driQueryOptionb(&smesa->optionCache, "no_rast")) { fprintf(stderr, "disabling 3D acceleration\n"); FALLBACK(smesa, SIS_FALLBACK_DISABLE, 1); } smesa->texture_depth = driQueryOptioni(&smesa->optionCache, "texture_depth"); return GL_TRUE;}voidsisDestroyContext ( __DRIcontextPrivate *driContextPriv ){ sisContextPtr smesa = (sisContextPtr)driContextPriv->driverPrivate; assert( smesa != NULL ); if ( smesa != NULL ) { _swsetup_DestroyContext( smesa->glCtx ); _tnl_DestroyContext( smesa->glCtx ); _vbo_DestroyContext( smesa->glCtx ); _swrast_DestroyContext( smesa->glCtx ); if (smesa->using_agp) sisFreeAGP(smesa, smesa->vb_agp_handle); /* free the Mesa context */ /* XXX: Is the next line needed? The DriverCtx (smesa) reference is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -