📄 savage_xmesa.c
字号:
/* * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sub license, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */#include <X11/Xlibint.h>#include <stdio.h>#include "savagecontext.h"#include "context.h"#include "matrix.h"#include "framebuffer.h"#include "renderbuffer.h"#include "simple_list.h"#include "utils.h"#include "extensions.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "vbo/vbo.h"#include "tnl/t_pipeline.h"#include "drivers/common/driverfuncs.h"#include "savagedd.h"#include "savagestate.h"#include "savagetex.h"#include "savagespan.h"#include "savagetris.h"#include "savageioctl.h"#include "savage_bci.h"#include "savage_dri.h"#include "drirenderbuffer.h"#include "texmem.h"#define need_GL_ARB_multisample#define need_GL_ARB_texture_compression#define need_GL_ARB_vertex_buffer_object#define need_GL_EXT_secondary_color#include "extension_helper.h"#include "xmlpool.h"/* Driver-specific options */#define SAVAGE_ENABLE_VDMA(def) \DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \ DRI_CONF_DESC(en,"Use DMA for vertex transfers") \ DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \DRI_CONF_OPT_END#define SAVAGE_ENABLE_FASTPATH(def) \DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \ DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \ DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \DRI_CONF_OPT_END#define SAVAGE_SYNC_FRAMES(def) \DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \ DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \ DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \DRI_CONF_OPT_END/* Configuration */PUBLIC const char __driConfigOptions[] =DRI_CONF_BEGIN DRI_CONF_SECTION_QUALITY DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB) DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER) DRI_CONF_FLOAT_DEPTH(false) DRI_CONF_SECTION_END DRI_CONF_SECTION_PERFORMANCE SAVAGE_ENABLE_VDMA(true) SAVAGE_ENABLE_FASTPATH(true) SAVAGE_SYNC_FRAMES(false) DRI_CONF_MAX_TEXTURE_UNITS(2,1,2) DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL) DRI_CONF_FORCE_S3TC_ENABLE(false) DRI_CONF_SECTION_END DRI_CONF_SECTION_DEBUG DRI_CONF_NO_RAST(false) DRI_CONF_SECTION_ENDDRI_CONF_END;static const GLuint __driNConfigOptions = 10;static const struct dri_debug_control debug_control[] ={ { "fall", DEBUG_FALLBACKS }, { "api", DEBUG_VERBOSE_API }, { "tex", DEBUG_VERBOSE_TEX }, { "verb", DEBUG_VERBOSE_MSG }, { "dma", DEBUG_DMA }, { "state", DEBUG_STATE }, { NULL, 0 }};#ifndef SAVAGE_DEBUGint SAVAGE_DEBUG = 0;#endif/*For time caculating test*/#if defined(DEBUG_TIME) && DEBUG_TIMEstruct timeval tv_s,tv_f;unsigned long time_sum=0;struct timeval tv_s1,tv_f1;#endifstatic const struct dri_extension card_extensions[] ={ { "GL_ARB_multisample", GL_ARB_multisample_functions }, { "GL_ARB_multitexture", NULL }, { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions }, { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions }, { "GL_EXT_stencil_wrap", NULL }, { "GL_EXT_texture_lod_bias", NULL }, { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions }, { NULL, NULL }};static const struct dri_extension s4_extensions[] ={ { "GL_ARB_texture_env_add", NULL }, { "GL_ARB_texture_mirrored_repeat", NULL }, { NULL, NULL }};extern struct tnl_pipeline_stage _savage_texnorm_stage;extern struct tnl_pipeline_stage _savage_render_stage;static const struct tnl_pipeline_stage *savage_pipeline[] = { &_tnl_vertex_transform_stage, &_tnl_normal_transform_stage, &_tnl_lighting_stage, &_tnl_fog_coordinate_stage, &_tnl_texgen_stage, &_tnl_texture_transform_stage, &_savage_texnorm_stage, &_savage_render_stage, &_tnl_render_stage, 0,};PUBLIC const __DRIextension *savageScreenExtensions[] = { &driCoreExtension.base, &driLegacyExtension.base, &driReadDrawableExtension,};static GLbooleansavageInitDriver(__DRIscreenPrivate *sPriv){ savageScreenPrivate *savageScreen; SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv; if (sPriv->devPrivSize != sizeof(SAVAGEDRIRec)) { fprintf(stderr,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n"); return GL_FALSE; } /* Allocate the private area */ savageScreen = (savageScreenPrivate *)Xmalloc(sizeof(savageScreenPrivate)); if (!savageScreen) return GL_FALSE; savageScreen->driScrnPriv = sPriv; sPriv->private = (void *)savageScreen; savageScreen->chipset=gDRIPriv->chipset; savageScreen->width=gDRIPriv->width; savageScreen->height=gDRIPriv->height; savageScreen->mem=gDRIPriv->mem; savageScreen->cpp=gDRIPriv->cpp; savageScreen->zpp=gDRIPriv->zpp; savageScreen->agpMode=gDRIPriv->agpMode; savageScreen->bufferSize=gDRIPriv->bufferSize; if (gDRIPriv->cpp == 4) savageScreen->frontFormat = DV_PF_8888; else savageScreen->frontFormat = DV_PF_565; savageScreen->frontOffset=gDRIPriv->frontOffset; savageScreen->backOffset = gDRIPriv->backOffset; savageScreen->depthOffset=gDRIPriv->depthOffset; savageScreen->textureOffset[SAVAGE_CARD_HEAP] = gDRIPriv->textureOffset; savageScreen->textureSize[SAVAGE_CARD_HEAP] = gDRIPriv->textureSize; savageScreen->logTextureGranularity[SAVAGE_CARD_HEAP] = gDRIPriv->logTextureGranularity; savageScreen->textureOffset[SAVAGE_AGP_HEAP] = gDRIPriv->agpTextureHandle; savageScreen->textureSize[SAVAGE_AGP_HEAP] = gDRIPriv->agpTextureSize; savageScreen->logTextureGranularity[SAVAGE_AGP_HEAP] = gDRIPriv->logAgpTextureGranularity; savageScreen->agpTextures.handle = gDRIPriv->agpTextureHandle; savageScreen->agpTextures.size = gDRIPriv->agpTextureSize; if (gDRIPriv->agpTextureSize) { if (drmMap(sPriv->fd, savageScreen->agpTextures.handle, savageScreen->agpTextures.size, (drmAddress *)&(savageScreen->agpTextures.map)) != 0) { Xfree(savageScreen); sPriv->private = NULL; return GL_FALSE; } } else savageScreen->agpTextures.map = NULL; savageScreen->texVirtual[SAVAGE_CARD_HEAP] = (drmAddress)(((GLubyte *)sPriv->pFB)+gDRIPriv->textureOffset); savageScreen->texVirtual[SAVAGE_AGP_HEAP] = (drmAddress)(savageScreen->agpTextures.map); savageScreen->aperture.handle = gDRIPriv->apertureHandle; savageScreen->aperture.size = gDRIPriv->apertureSize; savageScreen->aperturePitch = gDRIPriv->aperturePitch; if (drmMap(sPriv->fd, savageScreen->aperture.handle, savageScreen->aperture.size, (drmAddress *)&savageScreen->aperture.map) != 0) { Xfree(savageScreen); sPriv->private = NULL; return GL_FALSE; } savageScreen->bufs = drmMapBufs(sPriv->fd); savageScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset; /* parse information in __driConfigOptions */ driParseOptionInfo (&savageScreen->optionCache, __driConfigOptions, __driNConfigOptions); sPriv->extensions = savageScreenExtensions;#if 0 savageDDFastPathInit(); savageDDTrifuncInit(); savageDDSetupInit();#endif return GL_TRUE;}/* Accessed by dlsym from dri_mesa_init.c */static voidsavageDestroyScreen(__DRIscreenPrivate *sPriv){ savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private; if (savageScreen->bufs) drmUnmapBufs(savageScreen->bufs); /* free all option information */ driDestroyOptionInfo (&savageScreen->optionCache); Xfree(savageScreen); sPriv->private = NULL;}static GLbooleansavageCreateContext( const __GLcontextModes *mesaVis, __DRIcontextPrivate *driContextPriv, void *sharedContextPrivate ){ GLcontext *ctx, *shareCtx; savageContextPtr imesa; __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv; struct dd_function_table functions; savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private; drm_savage_sarea_t *saPriv=(drm_savage_sarea_t *)(((char*)sPriv->pSAREA)+ savageScreen->sarea_priv_offset); int textureSize[SAVAGE_NR_TEX_HEAPS]; int i; imesa = (savageContextPtr)Xcalloc(sizeof(savageContext), 1); if (!imesa) { return GL_FALSE; } /* Init default driver functions then plug in savage-specific texture * functions that are needed as early as during context creation. */ _mesa_init_driver_functions( &functions ); savageDDInitTextureFuncs( &functions ); /* Allocate the Mesa context */ if (sharedContextPrivate) shareCtx = ((savageContextPtr) sharedContextPrivate)->glCtx; else shareCtx = NULL; ctx = _mesa_create_context(mesaVis, shareCtx, &functions, imesa); if (!ctx) { Xfree(imesa); return GL_FALSE; } driContextPriv->driverPrivate = imesa; imesa->cmdBuf.size = SAVAGE_CMDBUF_SIZE; imesa->cmdBuf.base = imesa->cmdBuf.write = malloc(SAVAGE_CMDBUF_SIZE * sizeof(drm_savage_cmd_header_t)); if (!imesa->cmdBuf.base) return GL_FALSE; /* Parse configuration files */ driParseConfigFiles (&imesa->optionCache, &savageScreen->optionCache, sPriv->myNum, "savage");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -