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