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