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.

intel_screen.c 39KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /**************************************************************************
  2. *
  3. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include <errno.h>
  28. #include <time.h>
  29. #include "main/glheader.h"
  30. #include "main/context.h"
  31. #include "main/framebuffer.h"
  32. #include "main/renderbuffer.h"
  33. #include "main/texobj.h"
  34. #include "main/hash.h"
  35. #include "main/fbobject.h"
  36. #include "main/version.h"
  37. #include "swrast/s_renderbuffer.h"
  38. #include "utils.h"
  39. #include "xmlpool.h"
  40. PUBLIC const char __driConfigOptions[] =
  41. DRI_CONF_BEGIN
  42. DRI_CONF_SECTION_PERFORMANCE
  43. DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
  44. /* Options correspond to DRI_CONF_BO_REUSE_DISABLED,
  45. * DRI_CONF_BO_REUSE_ALL
  46. */
  47. DRI_CONF_OPT_BEGIN_V(bo_reuse, enum, 1, "0:1")
  48. DRI_CONF_DESC_BEGIN(en, "Buffer object reuse")
  49. DRI_CONF_ENUM(0, "Disable buffer object reuse")
  50. DRI_CONF_ENUM(1, "Enable reuse of all sizes of buffer objects")
  51. DRI_CONF_DESC_END
  52. DRI_CONF_OPT_END
  53. DRI_CONF_OPT_BEGIN_B(hiz, "true")
  54. DRI_CONF_DESC(en, "Enable Hierarchical Z on gen6+")
  55. DRI_CONF_OPT_END
  56. DRI_CONF_SECTION_END
  57. DRI_CONF_SECTION_QUALITY
  58. DRI_CONF_FORCE_S3TC_ENABLE("false")
  59. DRI_CONF_SECTION_END
  60. DRI_CONF_SECTION_DEBUG
  61. DRI_CONF_NO_RAST("false")
  62. DRI_CONF_ALWAYS_FLUSH_BATCH("false")
  63. DRI_CONF_ALWAYS_FLUSH_CACHE("false")
  64. DRI_CONF_DISABLE_THROTTLING("false")
  65. DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false")
  66. DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false")
  67. DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false")
  68. DRI_CONF_OPT_BEGIN_B(shader_precompile, "true")
  69. DRI_CONF_DESC(en, "Perform code generation at shader link time.")
  70. DRI_CONF_OPT_END
  71. DRI_CONF_SECTION_END
  72. DRI_CONF_END;
  73. const GLuint __driNConfigOptions = 12;
  74. #include "intel_batchbuffer.h"
  75. #include "intel_buffers.h"
  76. #include "intel_bufmgr.h"
  77. #include "intel_chipset.h"
  78. #include "intel_fbo.h"
  79. #include "intel_mipmap_tree.h"
  80. #include "intel_screen.h"
  81. #include "intel_tex.h"
  82. #include "intel_regions.h"
  83. #include "brw_context.h"
  84. #include "i915_drm.h"
  85. #ifdef USE_NEW_INTERFACE
  86. static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
  87. #endif /*USE_NEW_INTERFACE */
  88. /**
  89. * For debugging purposes, this returns a time in seconds.
  90. */
  91. double
  92. get_time(void)
  93. {
  94. struct timespec tp;
  95. clock_gettime(CLOCK_MONOTONIC, &tp);
  96. return tp.tv_sec + tp.tv_nsec / 1000000000.0;
  97. }
  98. void
  99. aub_dump_bmp(struct gl_context *ctx)
  100. {
  101. struct gl_framebuffer *fb = ctx->DrawBuffer;
  102. for (int i = 0; i < fb->_NumColorDrawBuffers; i++) {
  103. struct intel_renderbuffer *irb =
  104. intel_renderbuffer(fb->_ColorDrawBuffers[i]);
  105. if (irb && irb->mt) {
  106. enum aub_dump_bmp_format format;
  107. switch (irb->Base.Base.Format) {
  108. case MESA_FORMAT_ARGB8888:
  109. case MESA_FORMAT_XRGB8888:
  110. format = AUB_DUMP_BMP_FORMAT_ARGB_8888;
  111. break;
  112. default:
  113. continue;
  114. }
  115. assert(irb->mt->region->pitch % irb->mt->region->cpp == 0);
  116. drm_intel_gem_bo_aub_dump_bmp(irb->mt->region->bo,
  117. irb->draw_x,
  118. irb->draw_y,
  119. irb->Base.Base.Width,
  120. irb->Base.Base.Height,
  121. format,
  122. irb->mt->region->pitch,
  123. 0);
  124. }
  125. }
  126. }
  127. static const __DRItexBufferExtension intelTexBufferExtension = {
  128. .base = { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
  129. .setTexBuffer = intelSetTexBuffer,
  130. .setTexBuffer2 = intelSetTexBuffer2,
  131. .releaseTexBuffer = NULL,
  132. };
  133. static void
  134. intelDRI2Flush(__DRIdrawable *drawable)
  135. {
  136. GET_CURRENT_CONTEXT(ctx);
  137. struct brw_context *brw = brw_context(ctx);
  138. if (brw == NULL)
  139. return;
  140. intel_resolve_for_dri2_flush(brw, drawable);
  141. brw->need_throttle = true;
  142. if (brw->batch.used)
  143. intel_batchbuffer_flush(brw);
  144. if (INTEL_DEBUG & DEBUG_AUB) {
  145. aub_dump_bmp(ctx);
  146. }
  147. }
  148. static const struct __DRI2flushExtensionRec intelFlushExtension = {
  149. .base = { __DRI2_FLUSH, 3 },
  150. .flush = intelDRI2Flush,
  151. .invalidate = dri2InvalidateDrawable,
  152. };
  153. static struct intel_image_format intel_image_formats[] = {
  154. { __DRI_IMAGE_FOURCC_ARGB8888, __DRI_IMAGE_COMPONENTS_RGBA, 1,
  155. { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } },
  156. { __DRI_IMAGE_FOURCC_XRGB8888, __DRI_IMAGE_COMPONENTS_RGB, 1,
  157. { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } },
  158. { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
  159. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  160. { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
  161. { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
  162. { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
  163. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  164. { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  165. { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
  166. { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
  167. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  168. { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
  169. { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
  170. { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
  171. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  172. { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  173. { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
  174. { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
  175. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  176. { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  177. { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
  178. { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
  179. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  180. { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } },
  181. { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
  182. { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
  183. { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
  184. /* For YUYV buffers, we set up two overlapping DRI images and treat
  185. * them as planar buffers in the compositors. Plane 0 is GR88 and
  186. * samples YU or YV pairs and places Y into the R component, while
  187. * plane 1 is ARGB and samples YUYV clusters and places pairs and
  188. * places U into the G component and V into A. This lets the
  189. * texture sampler interpolate the Y components correctly when
  190. * sampling from plane 0, and interpolate U and V correctly when
  191. * sampling from plane 1. */
  192. { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  193. { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
  194. { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
  195. };
  196. static struct intel_image_format *
  197. intel_image_format_lookup(int fourcc)
  198. {
  199. struct intel_image_format *f = NULL;
  200. for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
  201. if (intel_image_formats[i].fourcc == fourcc) {
  202. f = &intel_image_formats[i];
  203. break;
  204. }
  205. }
  206. return f;
  207. }
  208. static __DRIimage *
  209. intel_allocate_image(int dri_format, void *loaderPrivate)
  210. {
  211. __DRIimage *image;
  212. image = calloc(1, sizeof *image);
  213. if (image == NULL)
  214. return NULL;
  215. image->dri_format = dri_format;
  216. image->offset = 0;
  217. switch (dri_format) {
  218. case __DRI_IMAGE_FORMAT_RGB565:
  219. image->format = MESA_FORMAT_RGB565;
  220. break;
  221. case __DRI_IMAGE_FORMAT_XRGB8888:
  222. image->format = MESA_FORMAT_XRGB8888;
  223. break;
  224. case __DRI_IMAGE_FORMAT_ARGB8888:
  225. image->format = MESA_FORMAT_ARGB8888;
  226. break;
  227. case __DRI_IMAGE_FORMAT_ABGR8888:
  228. image->format = MESA_FORMAT_RGBA8888_REV;
  229. break;
  230. case __DRI_IMAGE_FORMAT_XBGR8888:
  231. image->format = MESA_FORMAT_RGBX8888_REV;
  232. break;
  233. case __DRI_IMAGE_FORMAT_R8:
  234. image->format = MESA_FORMAT_R8;
  235. break;
  236. case __DRI_IMAGE_FORMAT_GR88:
  237. image->format = MESA_FORMAT_GR88;
  238. break;
  239. case __DRI_IMAGE_FORMAT_NONE:
  240. image->format = MESA_FORMAT_NONE;
  241. break;
  242. default:
  243. free(image);
  244. return NULL;
  245. }
  246. image->internal_format = _mesa_get_format_base_format(image->format);
  247. image->data = loaderPrivate;
  248. return image;
  249. }
  250. /**
  251. * Sets up a DRIImage structure to point to our shared image in a region
  252. */
  253. static void
  254. intel_setup_image_from_mipmap_tree(struct brw_context *brw, __DRIimage *image,
  255. struct intel_mipmap_tree *mt, GLuint level,
  256. GLuint zoffset)
  257. {
  258. unsigned int draw_x, draw_y;
  259. uint32_t mask_x, mask_y;
  260. intel_miptree_make_shareable(brw, mt);
  261. intel_miptree_check_level_layer(mt, level, zoffset);
  262. intel_region_get_tile_masks(mt->region, &mask_x, &mask_y, false);
  263. intel_miptree_get_image_offset(mt, level, zoffset, &draw_x, &draw_y);
  264. image->width = mt->level[level].width;
  265. image->height = mt->level[level].height;
  266. image->tile_x = draw_x & mask_x;
  267. image->tile_y = draw_y & mask_y;
  268. image->offset = intel_region_get_aligned_offset(mt->region,
  269. draw_x & ~mask_x,
  270. draw_y & ~mask_y,
  271. false);
  272. intel_region_reference(&image->region, mt->region);
  273. }
  274. static void
  275. intel_setup_image_from_dimensions(__DRIimage *image)
  276. {
  277. image->width = image->region->width;
  278. image->height = image->region->height;
  279. image->tile_x = 0;
  280. image->tile_y = 0;
  281. image->has_depthstencil = false;
  282. }
  283. static inline uint32_t
  284. intel_dri_format(GLuint format)
  285. {
  286. switch (format) {
  287. case MESA_FORMAT_RGB565:
  288. return __DRI_IMAGE_FORMAT_RGB565;
  289. case MESA_FORMAT_XRGB8888:
  290. return __DRI_IMAGE_FORMAT_XRGB8888;
  291. case MESA_FORMAT_ARGB8888:
  292. return __DRI_IMAGE_FORMAT_ARGB8888;
  293. case MESA_FORMAT_RGBA8888_REV:
  294. return __DRI_IMAGE_FORMAT_ABGR8888;
  295. case MESA_FORMAT_R8:
  296. return __DRI_IMAGE_FORMAT_R8;
  297. case MESA_FORMAT_RG88:
  298. return __DRI_IMAGE_FORMAT_GR88;
  299. }
  300. return MESA_FORMAT_NONE;
  301. }
  302. static __DRIimage *
  303. intel_create_image_from_name(__DRIscreen *screen,
  304. int width, int height, int format,
  305. int name, int pitch, void *loaderPrivate)
  306. {
  307. struct intel_screen *intelScreen = screen->driverPrivate;
  308. __DRIimage *image;
  309. int cpp;
  310. image = intel_allocate_image(format, loaderPrivate);
  311. if (image == NULL)
  312. return NULL;
  313. if (image->format == MESA_FORMAT_NONE)
  314. cpp = 1;
  315. else
  316. cpp = _mesa_get_format_bytes(image->format);
  317. image->region = intel_region_alloc_for_handle(intelScreen,
  318. cpp, width, height,
  319. pitch * cpp, name, "image");
  320. if (image->region == NULL) {
  321. free(image);
  322. return NULL;
  323. }
  324. intel_setup_image_from_dimensions(image);
  325. return image;
  326. }
  327. static __DRIimage *
  328. intel_create_image_from_renderbuffer(__DRIcontext *context,
  329. int renderbuffer, void *loaderPrivate)
  330. {
  331. __DRIimage *image;
  332. struct brw_context *brw = context->driverPrivate;
  333. struct gl_context *ctx = &brw->ctx;
  334. struct gl_renderbuffer *rb;
  335. struct intel_renderbuffer *irb;
  336. rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
  337. if (!rb) {
  338. _mesa_error(ctx, GL_INVALID_OPERATION, "glRenderbufferExternalMESA");
  339. return NULL;
  340. }
  341. irb = intel_renderbuffer(rb);
  342. intel_miptree_make_shareable(brw, irb->mt);
  343. image = calloc(1, sizeof *image);
  344. if (image == NULL)
  345. return NULL;
  346. image->internal_format = rb->InternalFormat;
  347. image->format = rb->Format;
  348. image->offset = 0;
  349. image->data = loaderPrivate;
  350. intel_region_reference(&image->region, irb->mt->region);
  351. intel_setup_image_from_dimensions(image);
  352. image->dri_format = intel_dri_format(image->format);
  353. image->has_depthstencil = irb->mt->stencil_mt? true : false;
  354. rb->NeedsFinishRenderTexture = true;
  355. return image;
  356. }
  357. static __DRIimage *
  358. intel_create_image_from_texture(__DRIcontext *context, int target,
  359. unsigned texture, int zoffset,
  360. int level,
  361. unsigned *error,
  362. void *loaderPrivate)
  363. {
  364. __DRIimage *image;
  365. struct brw_context *brw = context->driverPrivate;
  366. struct gl_texture_object *obj;
  367. struct intel_texture_object *iobj;
  368. GLuint face = 0;
  369. obj = _mesa_lookup_texture(&brw->ctx, texture);
  370. if (!obj || obj->Target != target) {
  371. *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
  372. return NULL;
  373. }
  374. if (target == GL_TEXTURE_CUBE_MAP)
  375. face = zoffset;
  376. _mesa_test_texobj_completeness(&brw->ctx, obj);
  377. iobj = intel_texture_object(obj);
  378. if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
  379. *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
  380. return NULL;
  381. }
  382. if (level < obj->BaseLevel || level > obj->_MaxLevel) {
  383. *error = __DRI_IMAGE_ERROR_BAD_MATCH;
  384. return NULL;
  385. }
  386. if (target == GL_TEXTURE_3D && obj->Image[face][level]->Depth < zoffset) {
  387. *error = __DRI_IMAGE_ERROR_BAD_MATCH;
  388. return NULL;
  389. }
  390. image = calloc(1, sizeof *image);
  391. if (image == NULL) {
  392. *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
  393. return NULL;
  394. }
  395. image->internal_format = obj->Image[face][level]->InternalFormat;
  396. image->format = obj->Image[face][level]->TexFormat;
  397. image->data = loaderPrivate;
  398. intel_setup_image_from_mipmap_tree(brw, image, iobj->mt, level, zoffset);
  399. image->dri_format = intel_dri_format(image->format);
  400. image->has_depthstencil = iobj->mt->stencil_mt? true : false;
  401. if (image->dri_format == MESA_FORMAT_NONE) {
  402. *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
  403. free(image);
  404. return NULL;
  405. }
  406. *error = __DRI_IMAGE_ERROR_SUCCESS;
  407. return image;
  408. }
  409. static void
  410. intel_destroy_image(__DRIimage *image)
  411. {
  412. intel_region_release(&image->region);
  413. free(image);
  414. }
  415. static __DRIimage *
  416. intel_create_image(__DRIscreen *screen,
  417. int width, int height, int format,
  418. unsigned int use,
  419. void *loaderPrivate)
  420. {
  421. __DRIimage *image;
  422. struct intel_screen *intelScreen = screen->driverPrivate;
  423. uint32_t tiling;
  424. int cpp;
  425. tiling = I915_TILING_X;
  426. if (use & __DRI_IMAGE_USE_CURSOR) {
  427. if (width != 64 || height != 64)
  428. return NULL;
  429. tiling = I915_TILING_NONE;
  430. }
  431. image = intel_allocate_image(format, loaderPrivate);
  432. if (image == NULL)
  433. return NULL;
  434. cpp = _mesa_get_format_bytes(image->format);
  435. image->region =
  436. intel_region_alloc(intelScreen, tiling, cpp, width, height, true);
  437. if (image->region == NULL) {
  438. free(image);
  439. return NULL;
  440. }
  441. intel_setup_image_from_dimensions(image);
  442. return image;
  443. }
  444. static GLboolean
  445. intel_query_image(__DRIimage *image, int attrib, int *value)
  446. {
  447. switch (attrib) {
  448. case __DRI_IMAGE_ATTRIB_STRIDE:
  449. *value = image->region->pitch;
  450. return true;
  451. case __DRI_IMAGE_ATTRIB_HANDLE:
  452. *value = image->region->bo->handle;
  453. return true;
  454. case __DRI_IMAGE_ATTRIB_NAME:
  455. return intel_region_flink(image->region, (uint32_t *) value);
  456. case __DRI_IMAGE_ATTRIB_FORMAT:
  457. *value = image->dri_format;
  458. return true;
  459. case __DRI_IMAGE_ATTRIB_WIDTH:
  460. *value = image->region->width;
  461. return true;
  462. case __DRI_IMAGE_ATTRIB_HEIGHT:
  463. *value = image->region->height;
  464. return true;
  465. case __DRI_IMAGE_ATTRIB_COMPONENTS:
  466. if (image->planar_format == NULL)
  467. return false;
  468. *value = image->planar_format->components;
  469. return true;
  470. case __DRI_IMAGE_ATTRIB_FD:
  471. if (drm_intel_bo_gem_export_to_prime(image->region->bo, value) == 0)
  472. return true;
  473. return false;
  474. default:
  475. return false;
  476. }
  477. }
  478. static __DRIimage *
  479. intel_dup_image(__DRIimage *orig_image, void *loaderPrivate)
  480. {
  481. __DRIimage *image;
  482. image = calloc(1, sizeof *image);
  483. if (image == NULL)
  484. return NULL;
  485. intel_region_reference(&image->region, orig_image->region);
  486. if (image->region == NULL) {
  487. free(image);
  488. return NULL;
  489. }
  490. image->internal_format = orig_image->internal_format;
  491. image->planar_format = orig_image->planar_format;
  492. image->dri_format = orig_image->dri_format;
  493. image->format = orig_image->format;
  494. image->offset = orig_image->offset;
  495. image->width = orig_image->width;
  496. image->height = orig_image->height;
  497. image->tile_x = orig_image->tile_x;
  498. image->tile_y = orig_image->tile_y;
  499. image->has_depthstencil = orig_image->has_depthstencil;
  500. image->data = loaderPrivate;
  501. memcpy(image->strides, orig_image->strides, sizeof(image->strides));
  502. memcpy(image->offsets, orig_image->offsets, sizeof(image->offsets));
  503. return image;
  504. }
  505. static GLboolean
  506. intel_validate_usage(__DRIimage *image, unsigned int use)
  507. {
  508. if (use & __DRI_IMAGE_USE_CURSOR) {
  509. if (image->region->width != 64 || image->region->height != 64)
  510. return GL_FALSE;
  511. }
  512. return GL_TRUE;
  513. }
  514. static __DRIimage *
  515. intel_create_image_from_names(__DRIscreen *screen,
  516. int width, int height, int fourcc,
  517. int *names, int num_names,
  518. int *strides, int *offsets,
  519. void *loaderPrivate)
  520. {
  521. struct intel_image_format *f = NULL;
  522. __DRIimage *image;
  523. int i, index;
  524. if (screen == NULL || names == NULL || num_names != 1)
  525. return NULL;
  526. f = intel_image_format_lookup(fourcc);
  527. if (f == NULL)
  528. return NULL;
  529. image = intel_create_image_from_name(screen, width, height,
  530. __DRI_IMAGE_FORMAT_NONE,
  531. names[0], strides[0],
  532. loaderPrivate);
  533. if (image == NULL)
  534. return NULL;
  535. image->planar_format = f;
  536. for (i = 0; i < f->nplanes; i++) {
  537. index = f->planes[i].buffer_index;
  538. image->offsets[index] = offsets[index];
  539. image->strides[index] = strides[index];
  540. }
  541. return image;
  542. }
  543. static __DRIimage *
  544. intel_create_image_from_fds(__DRIscreen *screen,
  545. int width, int height, int fourcc,
  546. int *fds, int num_fds, int *strides, int *offsets,
  547. void *loaderPrivate)
  548. {
  549. struct intel_screen *intelScreen = screen->driverPrivate;
  550. struct intel_image_format *f;
  551. __DRIimage *image;
  552. int i, index;
  553. if (fds == NULL || num_fds != 1)
  554. return NULL;
  555. f = intel_image_format_lookup(fourcc);
  556. if (f == NULL)
  557. return NULL;
  558. if (f->nplanes == 1)
  559. image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate);
  560. else
  561. image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
  562. if (image == NULL)
  563. return NULL;
  564. image->region = intel_region_alloc_for_fd(intelScreen,
  565. 1, width, height,
  566. strides[0], fds[0], "image");
  567. if (image->region == NULL) {
  568. free(image);
  569. return NULL;
  570. }
  571. image->planar_format = f;
  572. for (i = 0; i < f->nplanes; i++) {
  573. index = f->planes[i].buffer_index;
  574. image->offsets[index] = offsets[index];
  575. image->strides[index] = strides[index];
  576. }
  577. intel_setup_image_from_dimensions(image);
  578. return image;
  579. }
  580. static __DRIimage *
  581. intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
  582. {
  583. int width, height, offset, stride, dri_format, index;
  584. struct intel_image_format *f;
  585. uint32_t mask_x, mask_y;
  586. __DRIimage *image;
  587. if (parent == NULL || parent->planar_format == NULL)
  588. return NULL;
  589. f = parent->planar_format;
  590. if (plane >= f->nplanes)
  591. return NULL;
  592. width = parent->region->width >> f->planes[plane].width_shift;
  593. height = parent->region->height >> f->planes[plane].height_shift;
  594. dri_format = f->planes[plane].dri_format;
  595. index = f->planes[plane].buffer_index;
  596. offset = parent->offsets[index];
  597. stride = parent->strides[index];
  598. image = intel_allocate_image(dri_format, loaderPrivate);
  599. if (image == NULL)
  600. return NULL;
  601. if (offset + height * stride > parent->region->bo->size) {
  602. _mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds");
  603. free(image);
  604. return NULL;
  605. }
  606. image->region = calloc(sizeof(*image->region), 1);
  607. if (image->region == NULL) {
  608. free(image);
  609. return NULL;
  610. }
  611. image->region->cpp = _mesa_get_format_bytes(image->format);
  612. image->region->width = width;
  613. image->region->height = height;
  614. image->region->pitch = stride;
  615. image->region->refcount = 1;
  616. image->region->bo = parent->region->bo;
  617. drm_intel_bo_reference(image->region->bo);
  618. image->region->tiling = parent->region->tiling;
  619. image->offset = offset;
  620. intel_setup_image_from_dimensions(image);
  621. intel_region_get_tile_masks(image->region, &mask_x, &mask_y, false);
  622. if (offset & mask_x)
  623. _mesa_warning(NULL,
  624. "intel_create_sub_image: offset not on tile boundary");
  625. return image;
  626. }
  627. static struct __DRIimageExtensionRec intelImageExtension = {
  628. .base = { __DRI_IMAGE, 7 },
  629. .createImageFromName = intel_create_image_from_name,
  630. .createImageFromRenderbuffer = intel_create_image_from_renderbuffer,
  631. .destroyImage = intel_destroy_image,
  632. .createImage = intel_create_image,
  633. .queryImage = intel_query_image,
  634. .dupImage = intel_dup_image,
  635. .validateUsage = intel_validate_usage,
  636. .createImageFromNames = intel_create_image_from_names,
  637. .fromPlanar = intel_from_planar,
  638. .createImageFromTexture = intel_create_image_from_texture,
  639. .createImageFromFds = intel_create_image_from_fds
  640. };
  641. static const __DRIextension *intelScreenExtensions[] = {
  642. &intelTexBufferExtension.base,
  643. &intelFlushExtension.base,
  644. &intelImageExtension.base,
  645. &dri2ConfigQueryExtension.base,
  646. NULL
  647. };
  648. static bool
  649. intel_get_param(__DRIscreen *psp, int param, int *value)
  650. {
  651. int ret;
  652. struct drm_i915_getparam gp;
  653. memset(&gp, 0, sizeof(gp));
  654. gp.param = param;
  655. gp.value = value;
  656. ret = drmCommandWriteRead(psp->fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
  657. if (ret) {
  658. if (ret != -EINVAL)
  659. _mesa_warning(NULL, "drm_i915_getparam: %d", ret);
  660. return false;
  661. }
  662. return true;
  663. }
  664. static bool
  665. intel_get_boolean(__DRIscreen *psp, int param)
  666. {
  667. int value = 0;
  668. return intel_get_param(psp, param, &value) && value;
  669. }
  670. static void
  671. intelDestroyScreen(__DRIscreen * sPriv)
  672. {
  673. struct intel_screen *intelScreen = sPriv->driverPrivate;
  674. dri_bufmgr_destroy(intelScreen->bufmgr);
  675. driDestroyOptionInfo(&intelScreen->optionCache);
  676. free(intelScreen);
  677. sPriv->driverPrivate = NULL;
  678. }
  679. /**
  680. * This is called when we need to set up GL rendering to a new X window.
  681. */
  682. static GLboolean
  683. intelCreateBuffer(__DRIscreen * driScrnPriv,
  684. __DRIdrawable * driDrawPriv,
  685. const struct gl_config * mesaVis, GLboolean isPixmap)
  686. {
  687. struct intel_renderbuffer *rb;
  688. struct intel_screen *screen = (struct intel_screen*) driScrnPriv->driverPrivate;
  689. gl_format rgbFormat;
  690. unsigned num_samples = intel_quantize_num_samples(screen, mesaVis->samples);
  691. struct gl_framebuffer *fb;
  692. if (isPixmap)
  693. return false;
  694. fb = CALLOC_STRUCT(gl_framebuffer);
  695. if (!fb)
  696. return false;
  697. _mesa_initialize_window_framebuffer(fb, mesaVis);
  698. if (mesaVis->redBits == 5)
  699. rgbFormat = MESA_FORMAT_RGB565;
  700. else if (mesaVis->sRGBCapable)
  701. rgbFormat = MESA_FORMAT_SARGB8;
  702. else if (mesaVis->alphaBits == 0)
  703. rgbFormat = MESA_FORMAT_XRGB8888;
  704. else {
  705. rgbFormat = MESA_FORMAT_SARGB8;
  706. fb->Visual.sRGBCapable = true;
  707. }
  708. /* setup the hardware-based renderbuffers */
  709. rb = intel_create_renderbuffer(rgbFormat, num_samples);
  710. _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &rb->Base.Base);
  711. if (mesaVis->doubleBufferMode) {
  712. rb = intel_create_renderbuffer(rgbFormat, num_samples);
  713. _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &rb->Base.Base);
  714. }
  715. /*
  716. * Assert here that the gl_config has an expected depth/stencil bit
  717. * combination: one of d24/s8, d16/s0, d0/s0. (See intelInitScreen2(),
  718. * which constructs the advertised configs.)
  719. */
  720. if (mesaVis->depthBits == 24) {
  721. assert(mesaVis->stencilBits == 8);
  722. if (screen->hw_has_separate_stencil) {
  723. rb = intel_create_private_renderbuffer(MESA_FORMAT_X8_Z24,
  724. num_samples);
  725. _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
  726. rb = intel_create_private_renderbuffer(MESA_FORMAT_S8,
  727. num_samples);
  728. _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
  729. } else {
  730. /*
  731. * Use combined depth/stencil. Note that the renderbuffer is
  732. * attached to two attachment points.
  733. */
  734. rb = intel_create_private_renderbuffer(MESA_FORMAT_S8_Z24,
  735. num_samples);
  736. _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
  737. _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &rb->Base.Base);
  738. }
  739. }
  740. else if (mesaVis->depthBits == 16) {
  741. assert(mesaVis->stencilBits == 0);
  742. rb = intel_create_private_renderbuffer(MESA_FORMAT_Z16,
  743. num_samples);
  744. _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &rb->Base.Base);
  745. }
  746. else {
  747. assert(mesaVis->depthBits == 0);
  748. assert(mesaVis->stencilBits == 0);
  749. }
  750. /* now add any/all software-based renderbuffers we may need */
  751. _swrast_add_soft_renderbuffers(fb,
  752. false, /* never sw color */
  753. false, /* never sw depth */
  754. false, /* never sw stencil */
  755. mesaVis->accumRedBits > 0,
  756. false, /* never sw alpha */
  757. false /* never sw aux */ );
  758. driDrawPriv->driverPrivate = fb;
  759. return true;
  760. }
  761. static void
  762. intelDestroyBuffer(__DRIdrawable * driDrawPriv)
  763. {
  764. struct gl_framebuffer *fb = driDrawPriv->driverPrivate;
  765. _mesa_reference_framebuffer(&fb, NULL);
  766. }
  767. static GLboolean
  768. intelCreateContext(gl_api api,
  769. const struct gl_config * mesaVis,
  770. __DRIcontext * driContextPriv,
  771. unsigned major_version,
  772. unsigned minor_version,
  773. uint32_t flags,
  774. unsigned *error,
  775. void *sharedContextPrivate)
  776. {
  777. bool success = false;
  778. success = brwCreateContext(api, mesaVis,
  779. driContextPriv,
  780. major_version, minor_version, flags,
  781. error, sharedContextPrivate);
  782. if (success)
  783. return true;
  784. if (driContextPriv->driverPrivate != NULL)
  785. intelDestroyContext(driContextPriv);
  786. return false;
  787. }
  788. static bool
  789. intel_init_bufmgr(struct intel_screen *intelScreen)
  790. {
  791. __DRIscreen *spriv = intelScreen->driScrnPriv;
  792. intelScreen->no_hw = getenv("INTEL_NO_HW") != NULL;
  793. intelScreen->bufmgr = intel_bufmgr_gem_init(spriv->fd, BATCH_SZ);
  794. if (intelScreen->bufmgr == NULL) {
  795. fprintf(stderr, "[%s:%u] Error initializing buffer manager.\n",
  796. __func__, __LINE__);
  797. return false;
  798. }
  799. drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
  800. if (!intel_get_boolean(spriv, I915_PARAM_HAS_RELAXED_DELTA)) {
  801. fprintf(stderr, "[%s: %u] Kernel 2.6.39 required.\n", __func__, __LINE__);
  802. return false;
  803. }
  804. return true;
  805. }
  806. /**
  807. * Override intel_screen.hw_has_separate_stencil with environment variable
  808. * INTEL_SEPARATE_STENCIL.
  809. *
  810. * Valid values for INTEL_SEPARATE_STENCIL are "0" and "1". If an invalid
  811. * valid value is encountered, a warning is emitted and INTEL_SEPARATE_STENCIL
  812. * is ignored.
  813. */
  814. static void
  815. intel_override_separate_stencil(struct intel_screen *screen)
  816. {
  817. const char *s = getenv("INTEL_SEPARATE_STENCIL");
  818. if (!s) {
  819. return;
  820. } else if (!strncmp("0", s, 2)) {
  821. screen->hw_has_separate_stencil = false;
  822. } else if (!strncmp("1", s, 2)) {
  823. screen->hw_has_separate_stencil = true;
  824. } else {
  825. fprintf(stderr,
  826. "warning: env variable INTEL_SEPARATE_STENCIL=\"%s\" has "
  827. "invalid value and is ignored", s);
  828. }
  829. }
  830. static bool
  831. intel_detect_swizzling(struct intel_screen *screen)
  832. {
  833. drm_intel_bo *buffer;
  834. unsigned long flags = 0;
  835. unsigned long aligned_pitch;
  836. uint32_t tiling = I915_TILING_X;
  837. uint32_t swizzle_mode = 0;
  838. buffer = drm_intel_bo_alloc_tiled(screen->bufmgr, "swizzle test",
  839. 64, 64, 4,
  840. &tiling, &aligned_pitch, flags);
  841. if (buffer == NULL)
  842. return false;
  843. drm_intel_bo_get_tiling(buffer, &tiling, &swizzle_mode);
  844. drm_intel_bo_unreference(buffer);
  845. if (swizzle_mode == I915_BIT_6_SWIZZLE_NONE)
  846. return false;
  847. else
  848. return true;
  849. }
  850. static __DRIconfig**
  851. intel_screen_make_configs(__DRIscreen *dri_screen)
  852. {
  853. static const gl_format formats[] = {
  854. MESA_FORMAT_RGB565,
  855. MESA_FORMAT_ARGB8888
  856. };
  857. /* GLX_SWAP_COPY_OML is not supported due to page flipping. */
  858. static const GLenum back_buffer_modes[] = {
  859. GLX_SWAP_UNDEFINED_OML, GLX_NONE,
  860. };
  861. static const uint8_t singlesample_samples[1] = {0};
  862. static const uint8_t multisample_samples[2] = {4, 8};
  863. struct intel_screen *screen = dri_screen->driverPrivate;
  864. uint8_t depth_bits[4], stencil_bits[4];
  865. __DRIconfig **configs = NULL;
  866. /* Generate singlesample configs without accumulation buffer. */
  867. for (int i = 0; i < ARRAY_SIZE(formats); i++) {
  868. __DRIconfig **new_configs;
  869. int num_depth_stencil_bits = 2;
  870. /* Starting with DRI2 protocol version 1.1 we can request a depth/stencil
  871. * buffer that has a different number of bits per pixel than the color
  872. * buffer, gen >= 6 supports this.
  873. */
  874. depth_bits[0] = 0;
  875. stencil_bits[0] = 0;
  876. if (formats[i] == MESA_FORMAT_RGB565) {
  877. depth_bits[1] = 16;
  878. stencil_bits[1] = 0;
  879. if (screen->gen >= 6) {
  880. depth_bits[2] = 24;
  881. stencil_bits[2] = 8;
  882. num_depth_stencil_bits = 3;
  883. }
  884. } else {
  885. depth_bits[1] = 24;
  886. stencil_bits[1] = 8;
  887. }
  888. new_configs = driCreateConfigs(formats[i],
  889. depth_bits,
  890. stencil_bits,
  891. num_depth_stencil_bits,
  892. back_buffer_modes, 2,
  893. singlesample_samples, 1,
  894. false);
  895. configs = driConcatConfigs(configs, new_configs);
  896. }
  897. /* Generate the minimum possible set of configs that include an
  898. * accumulation buffer.
  899. */
  900. for (int i = 0; i < ARRAY_SIZE(formats); i++) {
  901. __DRIconfig **new_configs;
  902. if (formats[i] == MESA_FORMAT_RGB565) {
  903. depth_bits[0] = 16;
  904. stencil_bits[0] = 0;
  905. } else {
  906. depth_bits[0] = 24;
  907. stencil_bits[0] = 8;
  908. }
  909. new_configs = driCreateConfigs(formats[i],
  910. depth_bits, stencil_bits, 1,
  911. back_buffer_modes, 1,
  912. singlesample_samples, 1,
  913. true);
  914. configs = driConcatConfigs(configs, new_configs);
  915. }
  916. /* Generate multisample configs.
  917. *
  918. * This loop breaks early, and hence is a no-op, on gen < 6.
  919. *
  920. * Multisample configs must follow the singlesample configs in order to
  921. * work around an X server bug present in 1.12. The X server chooses to
  922. * associate the first listed RGBA888-Z24S8 config, regardless of its
  923. * sample count, with the 32-bit depth visual used for compositing.
  924. *
  925. * Only doublebuffer configs with GLX_SWAP_UNDEFINED_OML behavior are
  926. * supported. Singlebuffer configs are not supported because no one wants
  927. * them.
  928. */
  929. for (int i = 0; i < ARRAY_SIZE(formats); i++) {
  930. if (screen->gen < 6)
  931. break;
  932. __DRIconfig **new_configs;
  933. const int num_depth_stencil_bits = 2;
  934. int num_msaa_modes = 0;
  935. depth_bits[0] = 0;
  936. stencil_bits[0] = 0;
  937. if (formats[i] == MESA_FORMAT_RGB565) {
  938. depth_bits[1] = 16;
  939. stencil_bits[1] = 0;
  940. } else {
  941. depth_bits[1] = 24;
  942. stencil_bits[1] = 8;
  943. }
  944. if (screen->gen >= 7)
  945. num_msaa_modes = 2;
  946. else if (screen->gen == 6)
  947. num_msaa_modes = 1;
  948. new_configs = driCreateConfigs(formats[i],
  949. depth_bits,
  950. stencil_bits,
  951. num_depth_stencil_bits,
  952. back_buffer_modes, 1,
  953. multisample_samples,
  954. num_msaa_modes,
  955. false);
  956. configs = driConcatConfigs(configs, new_configs);
  957. }
  958. if (configs == NULL) {
  959. fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
  960. __LINE__);
  961. return NULL;
  962. }
  963. return configs;
  964. }
  965. static void
  966. set_max_gl_versions(struct intel_screen *screen)
  967. {
  968. int gl_version_override = _mesa_get_gl_version_override();
  969. switch (screen->gen) {
  970. case 7:
  971. screen->max_gl_core_version = 31;
  972. screen->max_gl_compat_version = 30;
  973. screen->max_gl_es1_version = 11;
  974. screen->max_gl_es2_version = 30;
  975. break;
  976. case 6:
  977. screen->max_gl_core_version = 31;
  978. screen->max_gl_compat_version = 30;
  979. screen->max_gl_es1_version = 11;
  980. screen->max_gl_es2_version = 30;
  981. break;
  982. case 5:
  983. case 4:
  984. screen->max_gl_core_version = 0;
  985. screen->max_gl_compat_version = 21;
  986. screen->max_gl_es1_version = 11;
  987. screen->max_gl_es2_version = 20;
  988. break;
  989. default:
  990. assert(!"unrecognized intel_screen::gen");
  991. break;
  992. }
  993. if (gl_version_override >= 31) {
  994. screen->max_gl_core_version = MAX2(screen->max_gl_core_version,
  995. gl_version_override);
  996. } else {
  997. screen->max_gl_compat_version = MAX2(screen->max_gl_compat_version,
  998. gl_version_override);
  999. }
  1000. #ifndef FEATURE_ES1
  1001. screen->max_gl_es1_version = 0;
  1002. #endif
  1003. #ifndef FEATURE_ES2
  1004. screen->max_gl_es2_version = 0;
  1005. #endif
  1006. }
  1007. /**
  1008. * This is the driver specific part of the createNewScreen entry point.
  1009. * Called when using DRI2.
  1010. *
  1011. * \return the struct gl_config supported by this driver
  1012. */
  1013. static const
  1014. __DRIconfig **intelInitScreen2(__DRIscreen *psp)
  1015. {
  1016. struct intel_screen *intelScreen;
  1017. if (psp->dri2.loader->base.version <= 2 ||
  1018. psp->dri2.loader->getBuffersWithFormat == NULL) {
  1019. fprintf(stderr,
  1020. "\nERROR! DRI2 loader with getBuffersWithFormat() "
  1021. "support required\n");
  1022. return false;
  1023. }
  1024. /* Allocate the private area */
  1025. intelScreen = calloc(1, sizeof *intelScreen);
  1026. if (!intelScreen) {
  1027. fprintf(stderr, "\nERROR! Allocating private area failed\n");
  1028. return false;
  1029. }
  1030. /* parse information in __driConfigOptions */
  1031. driParseOptionInfo(&intelScreen->optionCache,
  1032. __driConfigOptions, __driNConfigOptions);
  1033. intelScreen->driScrnPriv = psp;
  1034. psp->driverPrivate = (void *) intelScreen;
  1035. if (!intel_init_bufmgr(intelScreen))
  1036. return false;
  1037. intelScreen->deviceID = drm_intel_bufmgr_gem_get_devid(intelScreen->bufmgr);
  1038. if (IS_GEN7(intelScreen->deviceID)) {
  1039. intelScreen->gen = 7;
  1040. } else if (IS_GEN6(intelScreen->deviceID)) {
  1041. intelScreen->gen = 6;
  1042. } else if (IS_GEN5(intelScreen->deviceID)) {
  1043. intelScreen->gen = 5;
  1044. } else {
  1045. intelScreen->gen = 4;
  1046. }
  1047. intelScreen->hw_has_separate_stencil = intelScreen->gen >= 6;
  1048. intelScreen->hw_must_use_separate_stencil = intelScreen->gen >= 7;
  1049. int has_llc = 0;
  1050. bool success = intel_get_param(intelScreen->driScrnPriv, I915_PARAM_HAS_LLC,
  1051. &has_llc);
  1052. if (success && has_llc)
  1053. intelScreen->hw_has_llc = true;
  1054. else if (!success && intelScreen->gen >= 6)
  1055. intelScreen->hw_has_llc = true;
  1056. intel_override_separate_stencil(intelScreen);
  1057. intelScreen->hw_has_swizzling = intel_detect_swizzling(intelScreen);
  1058. set_max_gl_versions(intelScreen);
  1059. psp->api_mask = (1 << __DRI_API_OPENGL);
  1060. if (intelScreen->max_gl_core_version > 0)
  1061. psp->api_mask |= (1 << __DRI_API_OPENGL_CORE);
  1062. if (intelScreen->max_gl_es1_version > 0)
  1063. psp->api_mask |= (1 << __DRI_API_GLES);
  1064. if (intelScreen->max_gl_es2_version > 0)
  1065. psp->api_mask |= (1 << __DRI_API_GLES2);
  1066. if (intelScreen->max_gl_es2_version >= 30)
  1067. psp->api_mask |= (1 << __DRI_API_GLES3);
  1068. psp->extensions = intelScreenExtensions;
  1069. return (const __DRIconfig**) intel_screen_make_configs(psp);
  1070. }
  1071. struct intel_buffer {
  1072. __DRIbuffer base;
  1073. struct intel_region *region;
  1074. };
  1075. static __DRIbuffer *
  1076. intelAllocateBuffer(__DRIscreen *screen,
  1077. unsigned attachment, unsigned format,
  1078. int width, int height)
  1079. {
  1080. struct intel_buffer *intelBuffer;
  1081. struct intel_screen *intelScreen = screen->driverPrivate;
  1082. assert(attachment == __DRI_BUFFER_FRONT_LEFT ||
  1083. attachment == __DRI_BUFFER_BACK_LEFT);
  1084. intelBuffer = calloc(1, sizeof *intelBuffer);
  1085. if (intelBuffer == NULL)
  1086. return NULL;
  1087. /* The front and back buffers are color buffers, which are X tiled. */
  1088. intelBuffer->region = intel_region_alloc(intelScreen,
  1089. I915_TILING_X,
  1090. format / 8,
  1091. width,
  1092. height,
  1093. true);
  1094. if (intelBuffer->region == NULL) {
  1095. free(intelBuffer);
  1096. return NULL;
  1097. }
  1098. intel_region_flink(intelBuffer->region, &intelBuffer->base.name);
  1099. intelBuffer->base.attachment = attachment;
  1100. intelBuffer->base.cpp = intelBuffer->region->cpp;
  1101. intelBuffer->base.pitch = intelBuffer->region->pitch;
  1102. return &intelBuffer->base;
  1103. }
  1104. static void
  1105. intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
  1106. {
  1107. struct intel_buffer *intelBuffer = (struct intel_buffer *) buffer;
  1108. intel_region_release(&intelBuffer->region);
  1109. free(intelBuffer);
  1110. }
  1111. const struct __DriverAPIRec driDriverAPI = {
  1112. .InitScreen = intelInitScreen2,
  1113. .DestroyScreen = intelDestroyScreen,
  1114. .CreateContext = intelCreateContext,
  1115. .DestroyContext = intelDestroyContext,
  1116. .CreateBuffer = intelCreateBuffer,
  1117. .DestroyBuffer = intelDestroyBuffer,
  1118. .MakeCurrent = intelMakeCurrent,
  1119. .UnbindContext = intelUnbindContext,
  1120. .AllocateBuffer = intelAllocateBuffer,
  1121. .ReleaseBuffer = intelReleaseBuffer
  1122. };
  1123. /* This is the table of extensions that the loader will dlsym() for. */
  1124. PUBLIC const __DRIextension *__driDriverExtensions[] = {
  1125. &driCoreExtension.base,
  1126. &driDRI2Extension.base,
  1127. NULL
  1128. };