Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

savage_xmesa.c 32KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /*
  2. * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial portions
  14. * of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include "main/context.h"
  26. #include "main/framebuffer.h"
  27. #include "main/renderbuffer.h"
  28. #include "main/simple_list.h"
  29. #include "utils.h"
  30. #include "main/extensions.h"
  31. #include "swrast/swrast.h"
  32. #include "swrast_setup/swrast_setup.h"
  33. #include "tnl/tnl.h"
  34. #include "vbo/vbo.h"
  35. #include "tnl/t_pipeline.h"
  36. #include "drivers/common/driverfuncs.h"
  37. #include "drivers/common/meta.h"
  38. #include "savagedd.h"
  39. #include "savagestate.h"
  40. #include "savagetex.h"
  41. #include "savagespan.h"
  42. #include "savagetris.h"
  43. #include "savageioctl.h"
  44. #include "savage_dri.h"
  45. #include "drirenderbuffer.h"
  46. #include "texmem.h"
  47. #define need_GL_EXT_secondary_color
  48. #include "main/remap_helper.h"
  49. #include "xmlpool.h"
  50. /* Driver-specific options
  51. */
  52. #define SAVAGE_ENABLE_VDMA(def) \
  53. DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
  54. DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
  55. DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
  56. DRI_CONF_OPT_END
  57. #define SAVAGE_ENABLE_FASTPATH(def) \
  58. DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
  59. DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
  60. DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
  61. DRI_CONF_OPT_END
  62. #define SAVAGE_SYNC_FRAMES(def) \
  63. DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
  64. DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
  65. DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
  66. DRI_CONF_OPT_END
  67. /* Configuration
  68. */
  69. PUBLIC const char __driConfigOptions[] =
  70. DRI_CONF_BEGIN
  71. DRI_CONF_SECTION_QUALITY
  72. DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
  73. DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
  74. DRI_CONF_FLOAT_DEPTH(false)
  75. DRI_CONF_SECTION_END
  76. DRI_CONF_SECTION_PERFORMANCE
  77. SAVAGE_ENABLE_VDMA(true)
  78. SAVAGE_ENABLE_FASTPATH(true)
  79. SAVAGE_SYNC_FRAMES(false)
  80. DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
  81. DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL)
  82. DRI_CONF_FORCE_S3TC_ENABLE(false)
  83. DRI_CONF_SECTION_END
  84. DRI_CONF_SECTION_DEBUG
  85. DRI_CONF_NO_RAST(false)
  86. DRI_CONF_SECTION_END
  87. DRI_CONF_END;
  88. static const GLuint __driNConfigOptions = 10;
  89. static const struct dri_debug_control debug_control[] =
  90. {
  91. { "fall", DEBUG_FALLBACKS },
  92. { "api", DEBUG_VERBOSE_API },
  93. { "tex", DEBUG_VERBOSE_TEX },
  94. { "verb", DEBUG_VERBOSE_MSG },
  95. { "dma", DEBUG_DMA },
  96. { "state", DEBUG_STATE },
  97. { NULL, 0 }
  98. };
  99. #ifndef SAVAGE_DEBUG
  100. int SAVAGE_DEBUG = 0;
  101. #endif
  102. /*For time caculating test*/
  103. #if defined(DEBUG_TIME) && DEBUG_TIME
  104. struct timeval tv_s,tv_f;
  105. unsigned long time_sum=0;
  106. struct timeval tv_s1,tv_f1;
  107. #endif
  108. static const struct dri_extension card_extensions[] =
  109. {
  110. { "GL_ARB_multitexture", NULL },
  111. { "GL_EXT_stencil_wrap", NULL },
  112. { "GL_EXT_texture_lod_bias", NULL },
  113. { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
  114. { NULL, NULL }
  115. };
  116. static const struct dri_extension s4_extensions[] =
  117. {
  118. { "GL_ARB_texture_env_add", NULL },
  119. { "GL_ARB_texture_mirrored_repeat", NULL },
  120. { NULL, NULL }
  121. };
  122. extern struct tnl_pipeline_stage _savage_texnorm_stage;
  123. extern struct tnl_pipeline_stage _savage_render_stage;
  124. static const struct tnl_pipeline_stage *savage_pipeline[] = {
  125. &_tnl_vertex_transform_stage,
  126. &_tnl_normal_transform_stage,
  127. &_tnl_lighting_stage,
  128. &_tnl_fog_coordinate_stage,
  129. &_tnl_texgen_stage,
  130. &_tnl_texture_transform_stage,
  131. &_savage_texnorm_stage,
  132. &_savage_render_stage,
  133. &_tnl_render_stage,
  134. 0,
  135. };
  136. PUBLIC const __DRIextension *savageScreenExtensions[] = {
  137. &driCoreExtension.base,
  138. &driLegacyExtension.base,
  139. &driReadDrawableExtension,
  140. };
  141. static GLboolean
  142. savageInitDriver(__DRIscreen *sPriv)
  143. {
  144. savageScreenPrivate *savageScreen;
  145. SAVAGEDRIPtr gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
  146. if (sPriv->devPrivSize != sizeof(SAVAGEDRIRec)) {
  147. fprintf(stderr,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
  148. return GL_FALSE;
  149. }
  150. /* Allocate the private area */
  151. savageScreen = (savageScreenPrivate *)malloc(sizeof(savageScreenPrivate));
  152. if (!savageScreen)
  153. return GL_FALSE;
  154. savageScreen->driScrnPriv = sPriv;
  155. sPriv->private = (void *)savageScreen;
  156. savageScreen->chipset=gDRIPriv->chipset;
  157. savageScreen->width=gDRIPriv->width;
  158. savageScreen->height=gDRIPriv->height;
  159. savageScreen->mem=gDRIPriv->mem;
  160. savageScreen->cpp=gDRIPriv->cpp;
  161. savageScreen->zpp=gDRIPriv->zpp;
  162. savageScreen->agpMode=gDRIPriv->agpMode;
  163. savageScreen->bufferSize=gDRIPriv->bufferSize;
  164. if (gDRIPriv->cpp == 4)
  165. savageScreen->frontFormat = DV_PF_8888;
  166. else
  167. savageScreen->frontFormat = DV_PF_565;
  168. savageScreen->frontOffset=gDRIPriv->frontOffset;
  169. savageScreen->backOffset = gDRIPriv->backOffset;
  170. savageScreen->depthOffset=gDRIPriv->depthOffset;
  171. savageScreen->textureOffset[SAVAGE_CARD_HEAP] =
  172. gDRIPriv->textureOffset;
  173. savageScreen->textureSize[SAVAGE_CARD_HEAP] =
  174. gDRIPriv->textureSize;
  175. savageScreen->logTextureGranularity[SAVAGE_CARD_HEAP] =
  176. gDRIPriv->logTextureGranularity;
  177. savageScreen->textureOffset[SAVAGE_AGP_HEAP] =
  178. gDRIPriv->agpTextureHandle;
  179. savageScreen->textureSize[SAVAGE_AGP_HEAP] =
  180. gDRIPriv->agpTextureSize;
  181. savageScreen->logTextureGranularity[SAVAGE_AGP_HEAP] =
  182. gDRIPriv->logAgpTextureGranularity;
  183. savageScreen->agpTextures.handle = gDRIPriv->agpTextureHandle;
  184. savageScreen->agpTextures.size = gDRIPriv->agpTextureSize;
  185. if (gDRIPriv->agpTextureSize) {
  186. if (drmMap(sPriv->fd,
  187. savageScreen->agpTextures.handle,
  188. savageScreen->agpTextures.size,
  189. (drmAddress *)&(savageScreen->agpTextures.map)) != 0) {
  190. free(savageScreen);
  191. sPriv->private = NULL;
  192. return GL_FALSE;
  193. }
  194. } else
  195. savageScreen->agpTextures.map = NULL;
  196. savageScreen->texVirtual[SAVAGE_CARD_HEAP] =
  197. (drmAddress)(((GLubyte *)sPriv->pFB)+gDRIPriv->textureOffset);
  198. savageScreen->texVirtual[SAVAGE_AGP_HEAP] =
  199. (drmAddress)(savageScreen->agpTextures.map);
  200. savageScreen->aperture.handle = gDRIPriv->apertureHandle;
  201. savageScreen->aperture.size = gDRIPriv->apertureSize;
  202. savageScreen->aperturePitch = gDRIPriv->aperturePitch;
  203. if (drmMap(sPriv->fd,
  204. savageScreen->aperture.handle,
  205. savageScreen->aperture.size,
  206. (drmAddress *)&savageScreen->aperture.map) != 0)
  207. {
  208. free(savageScreen);
  209. sPriv->private = NULL;
  210. return GL_FALSE;
  211. }
  212. savageScreen->bufs = drmMapBufs(sPriv->fd);
  213. savageScreen->sarea_priv_offset = gDRIPriv->sarea_priv_offset;
  214. /* parse information in __driConfigOptions */
  215. driParseOptionInfo (&savageScreen->optionCache,
  216. __driConfigOptions, __driNConfigOptions);
  217. sPriv->extensions = savageScreenExtensions;
  218. #if 0
  219. savageDDFastPathInit();
  220. savageDDTrifuncInit();
  221. savageDDSetupInit();
  222. #endif
  223. return GL_TRUE;
  224. }
  225. /* Accessed by dlsym from dri_mesa_init.c
  226. */
  227. static void
  228. savageDestroyScreen(__DRIscreen *sPriv)
  229. {
  230. savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
  231. if (savageScreen->bufs)
  232. drmUnmapBufs(savageScreen->bufs);
  233. /* free all option information */
  234. driDestroyOptionInfo (&savageScreen->optionCache);
  235. free(savageScreen);
  236. sPriv->private = NULL;
  237. }
  238. static GLboolean
  239. savageCreateContext( gl_api api,
  240. const struct gl_config *mesaVis,
  241. __DRIcontext *driContextPriv,
  242. void *sharedContextPrivate )
  243. {
  244. struct gl_context *ctx, *shareCtx;
  245. savageContextPtr imesa;
  246. __DRIscreen *sPriv = driContextPriv->driScreenPriv;
  247. struct dd_function_table functions;
  248. savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
  249. drm_savage_sarea_t *saPriv=(drm_savage_sarea_t *)(((char*)sPriv->pSAREA)+
  250. savageScreen->sarea_priv_offset);
  251. int textureSize[SAVAGE_NR_TEX_HEAPS];
  252. int i;
  253. imesa = (savageContextPtr)calloc(1, sizeof(savageContext));
  254. if (!imesa) {
  255. return GL_FALSE;
  256. }
  257. /* Init default driver functions then plug in savage-specific texture
  258. * functions that are needed as early as during context creation. */
  259. _mesa_init_driver_functions( &functions );
  260. savageDDInitTextureFuncs( &functions );
  261. /* Allocate the Mesa context */
  262. if (sharedContextPrivate)
  263. shareCtx = ((savageContextPtr) sharedContextPrivate)->glCtx;
  264. else
  265. shareCtx = NULL;
  266. ctx = _mesa_create_context(api, mesaVis, shareCtx, &functions, imesa);
  267. if (!ctx) {
  268. free(imesa);
  269. return GL_FALSE;
  270. }
  271. driContextPriv->driverPrivate = imesa;
  272. imesa->cmdBuf.size = SAVAGE_CMDBUF_SIZE;
  273. imesa->cmdBuf.base = imesa->cmdBuf.write =
  274. malloc(SAVAGE_CMDBUF_SIZE * sizeof(drm_savage_cmd_header_t));
  275. if (!imesa->cmdBuf.base)
  276. return GL_FALSE;
  277. /* Parse configuration files */
  278. driParseConfigFiles (&imesa->optionCache, &savageScreen->optionCache,
  279. sPriv->myNum, "savage");
  280. imesa->float_depth = driQueryOptionb(&imesa->optionCache, "float_depth") &&
  281. savageScreen->chipset >= S3_SAVAGE4;
  282. imesa->no_rast = driQueryOptionb(&imesa->optionCache, "no_rast");
  283. #if 0
  284. ctx->Const.MinLineWidth = 1.0;
  285. ctx->Const.MinLineWidthAA = 1.0;
  286. ctx->Const.MaxLineWidth = 3.0;
  287. ctx->Const.MaxLineWidthAA = 3.0;
  288. ctx->Const.LineWidthGranularity = 1.0;
  289. #endif
  290. ctx->Const.MaxDrawBuffers = 1;
  291. /* Dri stuff
  292. */
  293. imesa->hHWContext = driContextPriv->hHWContext;
  294. imesa->driFd = sPriv->fd;
  295. imesa->driHwLock = &sPriv->pSAREA->lock;
  296. imesa->savageScreen = savageScreen;
  297. imesa->driScreen = sPriv;
  298. imesa->sarea = saPriv;
  299. imesa->glBuffer = NULL;
  300. /* DMA buffer */
  301. for(i=0;i<5;i++)
  302. {
  303. imesa->apertureBase[i] = (GLubyte *)savageScreen->aperture.map +
  304. 0x01000000 * i;
  305. }
  306. imesa->aperturePitch = savageScreen->aperturePitch;
  307. /* change texHeap initialize to support two kind of texture heap*/
  308. /* here is some parts of initialization, others in InitDriver() */
  309. (void) memset( imesa->textureHeaps, 0, sizeof( imesa->textureHeaps ) );
  310. make_empty_list( & imesa->swapped );
  311. textureSize[SAVAGE_CARD_HEAP] = savageScreen->textureSize[SAVAGE_CARD_HEAP];
  312. textureSize[SAVAGE_AGP_HEAP] = savageScreen->textureSize[SAVAGE_AGP_HEAP];
  313. imesa->lastTexHeap = savageScreen->texVirtual[SAVAGE_AGP_HEAP] ? 2 : 1;
  314. switch(driQueryOptioni (&imesa->optionCache, "texture_heaps")) {
  315. case DRI_CONF_TEXTURE_HEAPS_CARD: /* only use card memory, if available */
  316. if (textureSize[SAVAGE_CARD_HEAP])
  317. imesa->lastTexHeap = 1;
  318. break;
  319. case DRI_CONF_TEXTURE_HEAPS_GART: /* only use gart memory, if available */
  320. if (imesa->lastTexHeap == 2 && textureSize[SAVAGE_AGP_HEAP])
  321. textureSize[SAVAGE_CARD_HEAP] = 0;
  322. break;
  323. /*default: Nothing to do, use all available memory. */
  324. }
  325. for (i = 0; i < imesa->lastTexHeap; i++) {
  326. imesa->textureHeaps[i] = driCreateTextureHeap(
  327. i, imesa,
  328. textureSize[i],
  329. 11, /* 2^11 = 2k alignment */
  330. SAVAGE_NR_TEX_REGIONS,
  331. (drmTextureRegionPtr)imesa->sarea->texList[i],
  332. &imesa->sarea->texAge[i],
  333. &imesa->swapped,
  334. sizeof( savageTexObj ),
  335. (destroy_texture_object_t *) savageDestroyTexObj );
  336. /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
  337. * if there is not enough card memory for a card texture heap. */
  338. if (imesa->textureHeaps[i])
  339. driSetTextureSwapCounterLocation( imesa->textureHeaps[i],
  340. & imesa->c_textureSwaps );
  341. }
  342. imesa->texture_depth = driQueryOptioni (&imesa->optionCache,
  343. "texture_depth");
  344. if (imesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
  345. imesa->texture_depth = ( savageScreen->cpp == 4 ) ?
  346. DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
  347. if (savageScreen->chipset >= S3_SAVAGE4)
  348. ctx->Const.MaxTextureUnits = 2;
  349. else
  350. ctx->Const.MaxTextureUnits = 1;
  351. if (driQueryOptioni(&imesa->optionCache, "texture_units") <
  352. ctx->Const.MaxTextureUnits)
  353. ctx->Const.MaxTextureUnits =
  354. driQueryOptioni(&imesa->optionCache, "texture_units");
  355. ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
  356. ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
  357. driCalculateMaxTextureLevels( imesa->textureHeaps,
  358. imesa->lastTexHeap,
  359. & ctx->Const,
  360. 4,
  361. 11, /* max 2D texture size is 2048x2048 */
  362. 0, /* 3D textures unsupported. */
  363. 0, /* cube textures unsupported. */
  364. 0, /* texture rectangles unsupported. */
  365. 12,
  366. GL_FALSE,
  367. 0 );
  368. if (ctx->Const.MaxTextureLevels <= 6) { /*spec requires at least 64x64*/
  369. __driUtilMessage("Not enough texture memory. "
  370. "Falling back to indirect rendering.");
  371. free(imesa);
  372. return GL_FALSE;
  373. }
  374. imesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
  375. imesa->depth_scale = (imesa->savageScreen->zpp == 2) ?
  376. (1.0F/0xffff):(1.0F/0xffffff);
  377. imesa->bufferSize = savageScreen->bufferSize;
  378. imesa->dmaVtxBuf.total = 0;
  379. imesa->dmaVtxBuf.used = 0;
  380. imesa->dmaVtxBuf.flushed = 0;
  381. imesa->clientVtxBuf.total = imesa->bufferSize / 4;
  382. imesa->clientVtxBuf.used = 0;
  383. imesa->clientVtxBuf.flushed = 0;
  384. imesa->clientVtxBuf.buf = (uint32_t *)malloc(imesa->bufferSize);
  385. imesa->vtxBuf = &imesa->clientVtxBuf;
  386. imesa->firstElt = -1;
  387. /* Uninitialized vertex format. Force setting the vertex state in
  388. * savageRenderStart.
  389. */
  390. imesa->vertex_size = 0;
  391. /* Utah stuff
  392. */
  393. imesa->new_state = ~0;
  394. imesa->new_gl_state = ~0;
  395. imesa->RenderIndex = ~0;
  396. imesa->dirty = ~0;
  397. imesa->lostContext = GL_TRUE;
  398. imesa->CurrentTexObj[0] = 0;
  399. imesa->CurrentTexObj[1] = 0;
  400. _mesa_meta_init( ctx );
  401. /* Initialize the software rasterizer and helper modules.
  402. */
  403. _swrast_CreateContext( ctx );
  404. _vbo_CreateContext( ctx );
  405. _tnl_CreateContext( ctx );
  406. _swsetup_CreateContext( ctx );
  407. /* Install the customized pipeline:
  408. */
  409. _tnl_destroy_pipeline( ctx );
  410. _tnl_install_pipeline( ctx, savage_pipeline );
  411. imesa->enable_fastpath = driQueryOptionb(&imesa->optionCache,
  412. "enable_fastpath");
  413. /* DRM versions before 2.1.3 would only render triangle lists. ELTS
  414. * support was added in 2.2.0. */
  415. if (imesa->enable_fastpath && sPriv->drm_version.minor < 2) {
  416. fprintf (stderr,
  417. "*** Disabling fast path because your DRM version is buggy "
  418. "or doesn't\n*** support ELTS. You need at least Savage DRM "
  419. "version 2.2.\n");
  420. imesa->enable_fastpath = GL_FALSE;
  421. }
  422. if (!savageScreen->bufs || savageScreen->chipset == S3_SUPERSAVAGE)
  423. imesa->enable_vdma = GL_FALSE;
  424. else
  425. imesa->enable_vdma = driQueryOptionb(&imesa->optionCache, "enable_vdma");
  426. imesa->sync_frames = driQueryOptionb(&imesa->optionCache, "sync_frames");
  427. /* Configure swrast to match hardware characteristics:
  428. */
  429. _tnl_allow_pixel_fog( ctx, GL_FALSE );
  430. _tnl_allow_vertex_fog( ctx, GL_TRUE );
  431. _swrast_allow_pixel_fog( ctx, GL_FALSE );
  432. _swrast_allow_vertex_fog( ctx, GL_TRUE );
  433. ctx->DriverCtx = (void *) imesa;
  434. imesa->glCtx = ctx;
  435. #ifndef SAVAGE_DEBUG
  436. SAVAGE_DEBUG = driParseDebugString( getenv( "SAVAGE_DEBUG" ),
  437. debug_control );
  438. #endif
  439. driInitExtensions( ctx, card_extensions, GL_TRUE );
  440. if (savageScreen->chipset >= S3_SAVAGE4)
  441. driInitExtensions( ctx, s4_extensions, GL_FALSE );
  442. if (ctx->Mesa_DXTn ||
  443. driQueryOptionb (&imesa->optionCache, "force_s3tc_enable")) {
  444. _mesa_enable_extension( ctx, "GL_S3_s3tc" );
  445. if (savageScreen->chipset >= S3_SAVAGE4)
  446. /* This extension needs DXT3 and DTX5 support in hardware.
  447. * Not available on Savage3D/MX/IX. */
  448. _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
  449. }
  450. savageDDInitStateFuncs( ctx );
  451. savageDDInitSpanFuncs( ctx );
  452. savageDDInitDriverFuncs( ctx );
  453. savageDDInitIoctlFuncs( ctx );
  454. savageInitTriFuncs( ctx );
  455. savageDDInitState( imesa );
  456. driContextPriv->driverPrivate = (void *) imesa;
  457. return GL_TRUE;
  458. }
  459. static void
  460. savageDestroyContext(__DRIcontext *driContextPriv)
  461. {
  462. savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
  463. GLuint i;
  464. assert (imesa); /* should never be NULL */
  465. if (imesa) {
  466. savageFlushVertices(imesa);
  467. savageReleaseIndexedVerts(imesa);
  468. savageFlushCmdBuf(imesa, GL_TRUE); /* release DMA buffer */
  469. WAIT_IDLE_EMPTY(imesa);
  470. for (i = 0; i < imesa->lastTexHeap; i++)
  471. driDestroyTextureHeap(imesa->textureHeaps[i]);
  472. free(imesa->cmdBuf.base);
  473. free(imesa->clientVtxBuf.buf);
  474. _mesa_meta_free( imesa->glCtx );
  475. _swsetup_DestroyContext(imesa->glCtx );
  476. _tnl_DestroyContext( imesa->glCtx );
  477. _vbo_DestroyContext( imesa->glCtx );
  478. _swrast_DestroyContext( imesa->glCtx );
  479. /* free the Mesa context */
  480. imesa->glCtx->DriverCtx = NULL;
  481. _mesa_destroy_context(imesa->glCtx);
  482. /* no longer use vertex_dma_buf*/
  483. free(imesa);
  484. }
  485. }
  486. static GLboolean
  487. savageCreateBuffer( __DRIscreen *driScrnPriv,
  488. __DRIdrawable *driDrawPriv,
  489. const struct gl_config *mesaVis,
  490. GLboolean isPixmap)
  491. {
  492. savageScreenPrivate *screen = (savageScreenPrivate *) driScrnPriv->private;
  493. if (isPixmap) {
  494. return GL_FALSE; /* not implemented */
  495. }
  496. else {
  497. GLboolean swStencil = mesaVis->stencilBits > 0 && mesaVis->depthBits != 24;
  498. struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
  499. /*
  500. * XXX: this value needs to be set according to the config file
  501. * setting. But we don't get that until we create a rendering
  502. * context!!!!
  503. */
  504. GLboolean float_depth = GL_FALSE;
  505. {
  506. driRenderbuffer *frontRb
  507. = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
  508. (GLubyte *) screen->aperture.map
  509. + 0x01000000 * TARGET_FRONT,
  510. screen->cpp,
  511. screen->frontOffset, screen->aperturePitch,
  512. driDrawPriv);
  513. savageSetSpanFunctions(frontRb, mesaVis, float_depth);
  514. assert(frontRb->Base.Data);
  515. _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
  516. }
  517. if (mesaVis->doubleBufferMode) {
  518. driRenderbuffer *backRb
  519. = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
  520. (GLubyte *) screen->aperture.map
  521. + 0x01000000 * TARGET_BACK,
  522. screen->cpp,
  523. screen->backOffset, screen->aperturePitch,
  524. driDrawPriv);
  525. savageSetSpanFunctions(backRb, mesaVis, float_depth);
  526. assert(backRb->Base.Data);
  527. _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
  528. }
  529. if (mesaVis->depthBits == 16) {
  530. driRenderbuffer *depthRb
  531. = driNewRenderbuffer(MESA_FORMAT_Z16,
  532. (GLubyte *) screen->aperture.map
  533. + 0x01000000 * TARGET_DEPTH,
  534. screen->zpp,
  535. screen->depthOffset, screen->aperturePitch,
  536. driDrawPriv);
  537. savageSetSpanFunctions(depthRb, mesaVis, float_depth);
  538. _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
  539. }
  540. else if (mesaVis->depthBits == 24) {
  541. driRenderbuffer *depthRb
  542. = driNewRenderbuffer(MESA_FORMAT_S8_Z24,
  543. (GLubyte *) screen->aperture.map
  544. + 0x01000000 * TARGET_DEPTH,
  545. screen->zpp,
  546. screen->depthOffset, screen->aperturePitch,
  547. driDrawPriv);
  548. savageSetSpanFunctions(depthRb, mesaVis, float_depth);
  549. _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
  550. }
  551. if (mesaVis->stencilBits > 0 && !swStencil) {
  552. driRenderbuffer *stencilRb
  553. = driNewRenderbuffer(MESA_FORMAT_S8,
  554. (GLubyte *) screen->aperture.map
  555. + 0x01000000 * TARGET_DEPTH,
  556. screen->zpp,
  557. screen->depthOffset, screen->aperturePitch,
  558. driDrawPriv);
  559. savageSetSpanFunctions(stencilRb, mesaVis, float_depth);
  560. _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
  561. }
  562. _mesa_add_soft_renderbuffers(fb,
  563. GL_FALSE, /* color */
  564. GL_FALSE, /* depth */
  565. swStencil,
  566. mesaVis->accumRedBits > 0,
  567. GL_FALSE, /* alpha */
  568. GL_FALSE /* aux */);
  569. driDrawPriv->driverPrivate = (void *) fb;
  570. return (driDrawPriv->driverPrivate != NULL);
  571. }
  572. }
  573. static void
  574. savageDestroyBuffer(__DRIdrawable *driDrawPriv)
  575. {
  576. _mesa_reference_framebuffer((struct gl_framebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
  577. }
  578. #if 0
  579. void XMesaSwapBuffers(__DRIdrawable *driDrawPriv)
  580. {
  581. /* XXX should do swap according to the buffer, not the context! */
  582. savageContextPtr imesa = savageCtx;
  583. FLUSH_VB( imesa->glCtx, "swap buffers" );
  584. savageSwapBuffers(imesa);
  585. }
  586. #endif
  587. void savageXMesaSetClipRects(savageContextPtr imesa)
  588. {
  589. __DRIdrawable *dPriv = imesa->driDrawable;
  590. if ((dPriv->numBackClipRects == 0)
  591. || (imesa->glCtx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT)) {
  592. imesa->numClipRects = dPriv->numClipRects;
  593. imesa->pClipRects = dPriv->pClipRects;
  594. imesa->drawX = dPriv->x;
  595. imesa->drawY = dPriv->y;
  596. } else {
  597. imesa->numClipRects = dPriv->numBackClipRects;
  598. imesa->pClipRects = dPriv->pBackClipRects;
  599. imesa->drawX = dPriv->backX;
  600. imesa->drawY = dPriv->backY;
  601. }
  602. savageCalcViewport( imesa->glCtx );
  603. }
  604. static void savageXMesaWindowMoved( savageContextPtr imesa )
  605. {
  606. __DRIdrawable *const drawable = imesa->driDrawable;
  607. __DRIdrawable *const readable = imesa->driReadable;
  608. if (0)
  609. fprintf(stderr, "savageXMesaWindowMoved\n\n");
  610. savageXMesaSetClipRects(imesa);
  611. driUpdateFramebufferSize(imesa->glCtx, drawable);
  612. if (drawable != readable) {
  613. driUpdateFramebufferSize(imesa->glCtx, readable);
  614. }
  615. }
  616. static GLboolean
  617. savageUnbindContext(__DRIcontext *driContextPriv)
  618. {
  619. savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
  620. if (savage)
  621. savage->dirty = ~0;
  622. return GL_TRUE;
  623. }
  624. #if 0
  625. static GLboolean
  626. savageOpenFullScreen(__DRIcontext *driContextPriv)
  627. {
  628. if (driContextPriv) {
  629. savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
  630. imesa->IsFullScreen = GL_TRUE;
  631. imesa->backup_frontOffset = imesa->savageScreen->frontOffset;
  632. imesa->backup_backOffset = imesa->savageScreen->backOffset;
  633. imesa->backup_frontBitmapDesc = imesa->savageScreen->frontBitmapDesc;
  634. imesa->savageScreen->frontBitmapDesc = imesa->savageScreen->backBitmapDesc;
  635. imesa->toggle = TARGET_BACK;
  636. }
  637. return GL_TRUE;
  638. }
  639. static GLboolean
  640. savageCloseFullScreen(__DRIcontext *driContextPriv)
  641. {
  642. if (driContextPriv) {
  643. savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
  644. WAIT_IDLE_EMPTY(imesa);
  645. imesa->IsFullScreen = GL_FALSE;
  646. imesa->savageScreen->frontOffset = imesa->backup_frontOffset;
  647. imesa->savageScreen->backOffset = imesa->backup_backOffset;
  648. imesa->savageScreen->frontBitmapDesc = imesa->backup_frontBitmapDesc;
  649. }
  650. return GL_TRUE;
  651. }
  652. #endif
  653. static GLboolean
  654. savageMakeCurrent(__DRIcontext *driContextPriv,
  655. __DRIdrawable *driDrawPriv,
  656. __DRIdrawable *driReadPriv)
  657. {
  658. if (driContextPriv) {
  659. savageContextPtr imesa
  660. = (savageContextPtr) driContextPriv->driverPrivate;
  661. struct gl_framebuffer *drawBuffer
  662. = (struct gl_framebuffer *) driDrawPriv->driverPrivate;
  663. struct gl_framebuffer *readBuffer
  664. = (struct gl_framebuffer *) driReadPriv->driverPrivate;
  665. driRenderbuffer *frontRb = (driRenderbuffer *)
  666. drawBuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
  667. driRenderbuffer *backRb = (driRenderbuffer *)
  668. drawBuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer;
  669. assert(frontRb->Base.Data);
  670. if (imesa->glCtx->Visual.doubleBufferMode) {
  671. assert(backRb->Base.Data);
  672. }
  673. imesa->driReadable = driReadPriv;
  674. imesa->driDrawable = driDrawPriv;
  675. imesa->dirty = ~0;
  676. _mesa_make_current(imesa->glCtx, drawBuffer, readBuffer);
  677. savageXMesaWindowMoved( imesa );
  678. }
  679. else
  680. {
  681. _mesa_make_current(NULL, NULL, NULL);
  682. }
  683. return GL_TRUE;
  684. }
  685. void savageGetLock( savageContextPtr imesa, GLuint flags )
  686. {
  687. __DRIdrawable *const drawable = imesa->driDrawable;
  688. __DRIdrawable *const readable = imesa->driReadable;
  689. __DRIscreen *sPriv = imesa->driScreen;
  690. drm_savage_sarea_t *sarea = imesa->sarea;
  691. int me = imesa->hHWContext;
  692. int stamp = drawable->lastStamp;
  693. int heap;
  694. unsigned int timestamp = 0;
  695. /* We know there has been contention.
  696. */
  697. drmGetLock(imesa->driFd, imesa->hHWContext, flags);
  698. /* Note contention for throttling hint
  699. */
  700. imesa->any_contend = 1;
  701. /* If the window moved, may need to set a new cliprect now.
  702. *
  703. * NOTE: This releases and regains the hw lock, so all state
  704. * checking must be done *after* this call:
  705. */
  706. DRI_VALIDATE_DRAWABLE_INFO(sPriv, drawable);
  707. if (drawable != readable) {
  708. DRI_VALIDATE_DRAWABLE_INFO(sPriv, readable);
  709. }
  710. /* If we lost context, need to dump all registers to hardware.
  711. * Note that we don't care about 2d contexts, even if they perform
  712. * accelerated commands, so the DRI locking in the X server is even
  713. * more broken than usual.
  714. */
  715. if (sarea->ctxOwner != me) {
  716. imesa->dirty |= (SAVAGE_UPLOAD_LOCAL |
  717. SAVAGE_UPLOAD_GLOBAL |
  718. SAVAGE_UPLOAD_FOGTBL |
  719. SAVAGE_UPLOAD_TEX0 |
  720. SAVAGE_UPLOAD_TEX1 |
  721. SAVAGE_UPLOAD_TEXGLOBAL);
  722. imesa->lostContext = GL_TRUE;
  723. sarea->ctxOwner = me;
  724. }
  725. for (heap = 0; heap < imesa->lastTexHeap; ++heap) {
  726. /* If a heap was changed, update its timestamp. Do this before
  727. * DRI_AGE_TEXTURES updates the local_age. */
  728. if (imesa->textureHeaps[heap] &&
  729. imesa->textureHeaps[heap]->global_age[0] >
  730. imesa->textureHeaps[heap]->local_age) {
  731. if (timestamp == 0)
  732. timestamp = savageEmitEventLocked(imesa, 0);
  733. imesa->textureHeaps[heap]->timestamp = timestamp;
  734. }
  735. DRI_AGE_TEXTURES( imesa->textureHeaps[heap] );
  736. }
  737. if (drawable->lastStamp != stamp) {
  738. driUpdateFramebufferSize(imesa->glCtx, drawable);
  739. savageXMesaWindowMoved( imesa );
  740. }
  741. }
  742. static const __DRIconfig **
  743. savageFillInModes( __DRIscreen *psp,
  744. unsigned pixel_bits, unsigned depth_bits,
  745. unsigned stencil_bits, GLboolean have_back_buffer )
  746. {
  747. __DRIconfig **configs;
  748. struct gl_config * m;
  749. unsigned depth_buffer_factor;
  750. unsigned back_buffer_factor;
  751. GLenum fb_format;
  752. GLenum fb_type;
  753. int i;
  754. /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
  755. * enough to add support. Basically, if a context is created with an
  756. * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
  757. * will never be used.
  758. *
  759. * FK: What about drivers that don't use page flipping? Could they
  760. * just expose GLX_SWAP_COPY_OML?
  761. */
  762. static const GLenum back_buffer_modes[] = {
  763. GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
  764. };
  765. uint8_t depth_bits_array[2];
  766. uint8_t stencil_bits_array[2];
  767. uint8_t msaa_samples_array[1];
  768. depth_bits_array[0] = depth_bits;
  769. depth_bits_array[1] = depth_bits;
  770. /* Just like with the accumulation buffer, always provide some modes
  771. * with a stencil buffer. It will be a sw fallback, but some apps won't
  772. * care about that.
  773. */
  774. stencil_bits_array[0] = 0;
  775. stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
  776. msaa_samples_array[0] = 0;
  777. depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
  778. back_buffer_factor = (have_back_buffer) ? 2 : 1;
  779. if ( pixel_bits == 16 ) {
  780. fb_format = GL_RGB;
  781. fb_type = GL_UNSIGNED_SHORT_5_6_5;
  782. }
  783. else {
  784. fb_format = GL_BGR;
  785. fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
  786. }
  787. configs = driCreateConfigs(fb_format, fb_type,
  788. depth_bits_array, stencil_bits_array,
  789. depth_buffer_factor,
  790. back_buffer_modes, back_buffer_factor,
  791. msaa_samples_array, 1, GL_TRUE);
  792. if (configs == NULL) {
  793. fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
  794. __func__, __LINE__ );
  795. return NULL;
  796. }
  797. /* Mark the visual as slow if there are "fake" stencil bits.
  798. */
  799. for (i = 0; configs[i]; i++) {
  800. m = &configs[i]->modes;
  801. if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
  802. m->visualRating = GLX_SLOW_CONFIG;
  803. }
  804. }
  805. return (const __DRIconfig **) configs;
  806. }
  807. /**
  808. * This is the driver specific part of the createNewScreen entry point.
  809. *
  810. * \todo maybe fold this into intelInitDriver
  811. *
  812. * \return the struct gl_config supported by this driver
  813. */
  814. static const __DRIconfig **
  815. savageInitScreen(__DRIscreen *psp)
  816. {
  817. static const __DRIversion ddx_expected = { 2, 0, 0 };
  818. static const __DRIversion dri_expected = { 4, 0, 0 };
  819. static const __DRIversion drm_expected = { 2, 1, 0 };
  820. SAVAGEDRIPtr dri_priv = (SAVAGEDRIPtr)psp->pDevPriv;
  821. if ( ! driCheckDriDdxDrmVersions2( "Savage",
  822. &psp->dri_version, & dri_expected,
  823. &psp->ddx_version, & ddx_expected,
  824. &psp->drm_version, & drm_expected ) )
  825. return NULL;
  826. if (!savageInitDriver(psp))
  827. return NULL;
  828. return savageFillInModes( psp,
  829. dri_priv->cpp*8,
  830. (dri_priv->cpp == 2) ? 16 : 24,
  831. (dri_priv->cpp == 2) ? 0 : 8,
  832. (dri_priv->backOffset != dri_priv->depthOffset) );
  833. }
  834. const struct __DriverAPIRec driDriverAPI = {
  835. savageInitScreen,
  836. savageDestroyScreen,
  837. savageCreateContext,
  838. savageDestroyContext,
  839. savageCreateBuffer,
  840. savageDestroyBuffer,
  841. savageSwapBuffers,
  842. savageMakeCurrent,
  843. savageUnbindContext
  844. };
  845. /* This is the table of extensions that the loader will dlsym() for. */
  846. PUBLIC const __DRIextension *__driDriverExtensions[] = {
  847. &driCoreExtension.base,
  848. &driLegacyExtension.base,
  849. NULL
  850. };