1 /**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
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 VMWARE 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 * Author: Keith Whitwell <[email protected]>
29 * Author: Jakob Bornecrantz <[email protected]>
30 */
31
32 #include "dri_screen.h"
33 #include "dri_context.h"
34 #include "dri_helpers.h"
35
36 #include "util/u_inlines.h"
37 #include "pipe/p_screen.h"
38 #include "util/format/u_formats.h"
39 #include "pipe-loader/pipe_loader.h"
40 #include "frontend/drm_driver.h"
41
42 #include "util/u_debug.h"
43 #include "util/u_driconf.h"
44 #include "util/format/u_format_s3tc.h"
45
46 #include "state_tracker/st_context.h"
47 #include "driver_trace/tr_screen.h"
48
49 #ifdef HAVE_LIBDRM
50 #include <xf86drm.h>
51 #endif
52 #define MSAA_VISUAL_MAX_SAMPLES 32
53
54 #undef false
55
56 const __DRIconfigOptionsExtension gallium_config_options = {
57 .base = { __DRI_CONFIG_OPTIONS, 2 },
58 .getXml = pipe_loader_get_driinfo_xml
59 };
60
61 #define false 0
62
63 void
dri_init_options(struct dri_screen * screen)64 dri_init_options(struct dri_screen *screen)
65 {
66 pipe_loader_config_options(screen->dev);
67
68 struct st_config_options *options = &screen->options;
69 const struct driOptionCache *optionCache = &screen->dev->option_cache;
70
71 u_driconf_fill_st_options(options, optionCache);
72 }
73
74 static unsigned
dri_loader_get_cap(struct dri_screen * screen,enum dri_loader_cap cap)75 dri_loader_get_cap(struct dri_screen *screen, enum dri_loader_cap cap)
76 {
77 const __DRIdri2LoaderExtension *dri2_loader = screen->dri2.loader;
78 const __DRIimageLoaderExtension *image_loader = screen->image.loader;
79
80 if (dri2_loader && dri2_loader->base.version >= 4 &&
81 dri2_loader->getCapability)
82 return dri2_loader->getCapability(screen->loaderPrivate, cap);
83
84 if (image_loader && image_loader->base.version >= 2 &&
85 image_loader->getCapability)
86 return image_loader->getCapability(screen->loaderPrivate, cap);
87
88 return 0;
89 }
90
91 /**
92 * Creates a set of \c struct gl_config that a driver will expose.
93 *
94 * A set of \c struct gl_config will be created based on the supplied
95 * parameters. The number of modes processed will be 2 *
96 * \c num_depth_stencil_bits * \c num_db_modes.
97 *
98 * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
99 * \c db_modes, and \c visType into each \c struct gl_config element.
100 * However, the meanings of \c fb_format and \c fb_type require further
101 * explanation. The \c fb_format specifies which color components are in
102 * each pixel and what the default order is. For example, \c GL_RGB specifies
103 * that red, green, blue are available and red is in the "most significant"
104 * position and blue is in the "least significant". The \c fb_type specifies
105 * the bit sizes of each component and the actual ordering. For example, if
106 * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
107 * are the blue value, bits [10:5] are the green value, and bits [4:0] are
108 * the red value.
109 *
110 * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
111 * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
112 * \c struct gl_config structure is \b identical to the \c GL_RGBA or
113 * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
114 * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
115 * still uses 32-bits.
116 *
117 * If in doubt, look at the tables used in the function.
118 *
119 * \param ptr_to_modes Pointer to a pointer to a linked list of
120 * \c struct gl_config. Upon completion, a pointer to
121 * the next element to be process will be stored here.
122 * If the function fails and returns \c GL_FALSE, this
123 * value will be unmodified, but some elements in the
124 * linked list may be modified.
125 * \param format Mesa mesa_format enum describing the pixel format
126 * \param zs_formats Array of depth/stencil formats to expose
127 * \param num_zs_formats Number of entries in \c depth_stencil_formats.
128 * \param db_modes Array of buffer swap modes.
129 * \param num_db_modes Number of entries in \c db_modes.
130 * \param msaa_samples Array of msaa sample count. 0 represents a visual
131 * without a multisample buffer.
132 * \param num_msaa_modes Number of entries in \c msaa_samples.
133 * \param enable_accum Add an accum buffer to the configs
134 * \param color_depth_match Whether the color depth must match the zs depth
135 * This forces 32-bit color to have 24-bit depth, and
136 * 16-bit color to have 16-bit depth.
137 *
138 * \returns
139 * Pointer to any array of pointers to the \c __DRIconfig structures created
140 * for the specified formats. If there is an error, \c NULL is returned.
141 * Currently the only cause of failure is a bad parameter (i.e., unsupported
142 * \c format).
143 */
144 static __DRIconfig **
driCreateConfigs(enum pipe_format format,enum pipe_format * zs_formats,unsigned num_zs_formats,const bool * db_modes,unsigned num_db_modes,const uint8_t * msaa_samples,unsigned num_msaa_modes,GLboolean enable_accum,GLboolean color_depth_match)145 driCreateConfigs(enum pipe_format format,
146 enum pipe_format *zs_formats, unsigned num_zs_formats,
147 const bool *db_modes, unsigned num_db_modes,
148 const uint8_t * msaa_samples, unsigned num_msaa_modes,
149 GLboolean enable_accum, GLboolean color_depth_match)
150 {
151 uint32_t masks[4];
152 int shifts[4];
153 int color_bits[4];
154 __DRIconfig **configs, **c;
155 struct gl_config *modes;
156 unsigned i, j, k, h;
157 unsigned num_modes;
158 unsigned num_accum_bits = (enable_accum) ? 2 : 1;
159 bool is_srgb;
160 bool is_float;
161
162 is_srgb = util_format_is_srgb(format);
163 is_float = util_format_is_float(format);
164
165 for (i = 0; i < 4; i++) {
166 color_bits[i] =
167 util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, i);
168
169 if (color_bits[i] > 0) {
170 shifts[i] =
171 util_format_get_component_shift(format, UTIL_FORMAT_COLORSPACE_RGB, i);
172 } else {
173 shifts[i] = -1;
174 }
175
176 if (is_float || color_bits[i] == 0)
177 masks[i] = 0;
178 else
179 masks[i] = ((1u << color_bits[i]) - 1) << shifts[i];
180 }
181
182 num_modes = num_zs_formats * num_db_modes * num_accum_bits * num_msaa_modes;
183 configs = calloc(num_modes + 1, sizeof *configs);
184 if (configs == NULL)
185 return NULL;
186
187 c = configs;
188 for ( k = 0 ; k < num_zs_formats ; k++ ) {
189 unsigned depth_bits, stencil_bits;
190
191 if (zs_formats[k] != PIPE_FORMAT_NONE) {
192 depth_bits =
193 util_format_get_component_bits(zs_formats[k],
194 UTIL_FORMAT_COLORSPACE_ZS, 0);
195 stencil_bits =
196 util_format_get_component_bits(zs_formats[k],
197 UTIL_FORMAT_COLORSPACE_ZS, 1);
198 } else {
199 depth_bits = 0;
200 stencil_bits = 0;
201 }
202
203 for ( i = 0 ; i < num_db_modes ; i++ ) {
204 for ( h = 0 ; h < num_msaa_modes; h++ ) {
205 for ( j = 0 ; j < num_accum_bits ; j++ ) {
206 if (color_depth_match &&
207 (depth_bits || stencil_bits)) {
208 /* Depth can really only be 0, 16, 24, or 32. A 32-bit
209 * color format still matches 24-bit depth, as there
210 * is an implicit 8-bit stencil. So really we just
211 * need to make sure that color/depth are both 16 or
212 * both non-16.
213 */
214 if ((depth_bits + stencil_bits == 16) !=
215 (color_bits[0] + color_bits[1] +
216 color_bits[2] + color_bits[3] == 16))
217 continue;
218 }
219
220 *c = malloc (sizeof **c);
221 modes = &(*c)->modes;
222 c++;
223
224 memset(modes, 0, sizeof *modes);
225 modes->color_format = format;
226 modes->zs_format = zs_formats[k];
227 if (j > 0)
228 modes->accum_format = PIPE_FORMAT_R16G16B16A16_SNORM;
229 else
230 modes->accum_format = PIPE_FORMAT_NONE;
231
232 modes->floatMode = is_float;
233 modes->redBits = color_bits[0];
234 modes->redShift = shifts[0];
235 modes->redMask = masks[0];
236 modes->greenBits = color_bits[1];
237 modes->greenShift = shifts[1];
238 modes->greenMask = masks[1];
239 modes->blueBits = color_bits[2];
240 modes->blueShift = shifts[2];
241 modes->blueMask = masks[2];
242 modes->alphaBits = color_bits[3];
243 modes->alphaMask = masks[3];
244 modes->alphaShift = shifts[3];
245 modes->rgbBits = modes->redBits + modes->greenBits
246 + modes->blueBits + modes->alphaBits;
247
248 modes->accumRedBits = 16 * j;
249 modes->accumGreenBits = 16 * j;
250 modes->accumBlueBits = 16 * j;
251 modes->accumAlphaBits = 16 * j;
252
253 modes->stencilBits = stencil_bits;
254 modes->depthBits = depth_bits;
255
256 modes->doubleBufferMode = db_modes[i];
257
258 modes->samples = msaa_samples[h];
259
260 modes->sRGBCapable = is_srgb;
261 }
262 }
263 }
264 }
265 *c = NULL;
266
267 return configs;
268 }
269
270 static __DRIconfig **
driConcatConfigs(__DRIconfig ** a,__DRIconfig ** b)271 driConcatConfigs(__DRIconfig **a, __DRIconfig **b)
272 {
273 __DRIconfig **all;
274 int i, j, index;
275
276 if (a == NULL || a[0] == NULL)
277 return b;
278 else if (b == NULL || b[0] == NULL)
279 return a;
280
281 i = 0;
282 while (a[i] != NULL)
283 i++;
284 j = 0;
285 while (b[j] != NULL)
286 j++;
287
288 all = malloc((i + j + 1) * sizeof *all);
289 index = 0;
290 for (i = 0; a[i] != NULL; i++)
291 all[index++] = a[i];
292 for (j = 0; b[j] != NULL; j++)
293 all[index++] = b[j];
294 all[index++] = NULL;
295
296 free(a);
297 free(b);
298
299 return all;
300 }
301
302
303 static const __DRIconfig **
dri_fill_in_modes(struct dri_screen * screen)304 dri_fill_in_modes(struct dri_screen *screen)
305 {
306 /* The 32-bit RGBA format must not precede the 32-bit BGRA format.
307 * Likewise for RGBX and BGRX. Otherwise, the GLX client and the GLX
308 * server may disagree on which format the GLXFBConfig represents,
309 * resulting in swapped color channels.
310 *
311 * The problem, as of 2017-05-30:
312 * When matching a GLXFBConfig to a __DRIconfig, GLX ignores the channel
313 * order and chooses the first __DRIconfig with the expected channel
314 * sizes. Specifically, GLX compares the GLXFBConfig's and __DRIconfig's
315 * __DRI_ATTRIB_{CHANNEL}_SIZE but ignores __DRI_ATTRIB_{CHANNEL}_MASK.
316 *
317 * EGL does not suffer from this problem. It correctly compares the
318 * channel masks when matching EGLConfig to __DRIconfig.
319 */
320 static const enum pipe_format pipe_formats[] = {
321 PIPE_FORMAT_B10G10R10A2_UNORM,
322 PIPE_FORMAT_B10G10R10X2_UNORM,
323 PIPE_FORMAT_R10G10B10A2_UNORM,
324 PIPE_FORMAT_R10G10B10X2_UNORM,
325 PIPE_FORMAT_BGRA8888_UNORM,
326 PIPE_FORMAT_BGRX8888_UNORM,
327 PIPE_FORMAT_BGRA8888_SRGB,
328 PIPE_FORMAT_BGRX8888_SRGB,
329 PIPE_FORMAT_B5G6R5_UNORM,
330 PIPE_FORMAT_R16G16B16A16_FLOAT,
331 PIPE_FORMAT_R16G16B16X16_FLOAT,
332 PIPE_FORMAT_RGBA8888_UNORM,
333 PIPE_FORMAT_RGBX8888_UNORM,
334 PIPE_FORMAT_RGBA8888_SRGB,
335 PIPE_FORMAT_RGBX8888_SRGB,
336 PIPE_FORMAT_B5G5R5A1_UNORM,
337 PIPE_FORMAT_R5G5B5A1_UNORM,
338 PIPE_FORMAT_B4G4R4A4_UNORM,
339 PIPE_FORMAT_R4G4B4A4_UNORM,
340 };
341 __DRIconfig **configs = NULL;
342 enum pipe_format zs_formats[5];
343 unsigned num_zs_formats = 0;
344 unsigned i;
345 struct pipe_screen *p_screen = screen->base.screen;
346 bool mixed_color_depth;
347 bool allow_rgba_ordering;
348 bool allow_rgb10;
349 bool allow_fp16;
350
351 static const bool db_modes[] = { false, true };
352
353 if (!driQueryOptionb(&screen->dev->option_cache, "always_have_depth_buffer"))
354 zs_formats[num_zs_formats++] = PIPE_FORMAT_NONE;
355
356 allow_rgba_ordering = dri_loader_get_cap(screen, DRI_LOADER_CAP_RGBA_ORDERING);
357 allow_rgb10 = driQueryOptionb(&screen->dev->option_cache, "allow_rgb10_configs");
358 allow_fp16 = dri_loader_get_cap(screen, DRI_LOADER_CAP_FP16);
359
360 #define HAS_ZS(fmt) \
361 p_screen->is_format_supported(p_screen, PIPE_FORMAT_##fmt, \
362 PIPE_TEXTURE_2D, 0, 0, \
363 PIPE_BIND_DEPTH_STENCIL)
364
365 if (HAS_ZS(Z16_UNORM))
366 zs_formats[num_zs_formats++] = PIPE_FORMAT_Z16_UNORM;
367
368 if (HAS_ZS(Z24X8_UNORM))
369 zs_formats[num_zs_formats++] = PIPE_FORMAT_Z24X8_UNORM;
370 else if (HAS_ZS(X8Z24_UNORM))
371 zs_formats[num_zs_formats++] = PIPE_FORMAT_X8Z24_UNORM;
372
373 if (HAS_ZS(Z24_UNORM_S8_UINT))
374 zs_formats[num_zs_formats++] = PIPE_FORMAT_Z24_UNORM_S8_UINT;
375 else if (HAS_ZS(S8_UINT_Z24_UNORM))
376 zs_formats[num_zs_formats++] = PIPE_FORMAT_S8_UINT_Z24_UNORM;
377
378 if (HAS_ZS(Z32_UNORM))
379 zs_formats[num_zs_formats++] = PIPE_FORMAT_Z32_UNORM;
380
381 #undef HAS_ZS
382
383 mixed_color_depth =
384 p_screen->get_param(p_screen, PIPE_CAP_MIXED_COLOR_DEPTH_BITS);
385
386 /* Add configs. */
387 for (unsigned f = 0; f < ARRAY_SIZE(pipe_formats); f++) {
388 __DRIconfig **new_configs = NULL;
389 unsigned num_msaa_modes = 0; /* includes a single-sample mode */
390 uint8_t msaa_modes[MSAA_VISUAL_MAX_SAMPLES];
391
392 /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
393 if (!allow_rgba_ordering &&
394 (pipe_formats[f] == PIPE_FORMAT_RGBA8888_UNORM ||
395 pipe_formats[f] == PIPE_FORMAT_RGBX8888_UNORM ||
396 pipe_formats[f] == PIPE_FORMAT_RGBA8888_SRGB ||
397 pipe_formats[f] == PIPE_FORMAT_RGBX8888_SRGB ||
398 pipe_formats[f] == PIPE_FORMAT_R5G5B5A1_UNORM ||
399 pipe_formats[f] == PIPE_FORMAT_R5G5B5X1_UNORM ||
400 pipe_formats[f] == PIPE_FORMAT_R4G4B4A4_UNORM ||
401 pipe_formats[f] == PIPE_FORMAT_R4G4B4X4_UNORM))
402 continue;
403
404 if (!allow_rgb10 &&
405 util_format_get_component_bits(pipe_formats[f],
406 UTIL_FORMAT_COLORSPACE_RGB, 0) == 10 &&
407 util_format_get_component_bits(pipe_formats[f],
408 UTIL_FORMAT_COLORSPACE_RGB, 1) == 10 &&
409 util_format_get_component_bits(pipe_formats[f],
410 UTIL_FORMAT_COLORSPACE_RGB, 2) == 10)
411 continue;
412
413 if (!allow_fp16 && util_format_is_float(pipe_formats[f]))
414 continue;
415
416 if (!p_screen->is_format_supported(p_screen, pipe_formats[f],
417 PIPE_TEXTURE_2D, 0, 0,
418 PIPE_BIND_RENDER_TARGET |
419 PIPE_BIND_DISPLAY_TARGET))
420 continue;
421
422 for (i = 1; i <= MSAA_VISUAL_MAX_SAMPLES; i++) {
423 int samples = i > 1 ? i : 0;
424
425 if (p_screen->is_format_supported(p_screen, pipe_formats[f],
426 PIPE_TEXTURE_2D, samples, samples,
427 PIPE_BIND_RENDER_TARGET)) {
428 msaa_modes[num_msaa_modes++] = samples;
429 }
430 }
431
432 if (num_msaa_modes) {
433 /* Single-sample configs with an accumulation buffer. */
434 new_configs = driCreateConfigs(pipe_formats[f],
435 zs_formats, num_zs_formats,
436 db_modes, ARRAY_SIZE(db_modes),
437 msaa_modes, 1,
438 GL_TRUE, !mixed_color_depth);
439 configs = driConcatConfigs(configs, new_configs);
440
441 /* Multi-sample configs without an accumulation buffer. */
442 if (num_msaa_modes > 1) {
443 new_configs = driCreateConfigs(pipe_formats[f],
444 zs_formats, num_zs_formats,
445 db_modes, ARRAY_SIZE(db_modes),
446 msaa_modes+1, num_msaa_modes-1,
447 GL_FALSE, !mixed_color_depth);
448 configs = driConcatConfigs(configs, new_configs);
449 }
450 }
451 }
452
453 if (configs == NULL) {
454 debug_printf("%s: driCreateConfigs failed\n", __func__);
455 return NULL;
456 }
457
458 return (const __DRIconfig **)configs;
459 }
460
461 /**
462 * Roughly the converse of dri_fill_in_modes.
463 */
464 void
dri_fill_st_visual(struct st_visual * stvis,const struct dri_screen * screen,const struct gl_config * mode)465 dri_fill_st_visual(struct st_visual *stvis,
466 const struct dri_screen *screen,
467 const struct gl_config *mode)
468 {
469 memset(stvis, 0, sizeof(*stvis));
470
471 if (!mode)
472 return;
473
474 assert(mode->color_format != PIPE_FORMAT_NONE);
475 stvis->color_format = mode->color_format;
476 stvis->accum_format = mode->accum_format;
477 stvis->depth_stencil_format = mode->zs_format;
478
479 if (mode->samples > 0) {
480 if (debug_get_bool_option("DRI_NO_MSAA", false))
481 stvis->samples = 0;
482 else
483 stvis->samples = mode->samples;
484 }
485
486 stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK;
487 if (mode->doubleBufferMode) {
488 stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
489 }
490 if (mode->stereoMode) {
491 stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
492 if (mode->doubleBufferMode)
493 stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
494 }
495
496 if (mode->depthBits > 0 || mode->stencilBits > 0)
497 stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK;
498 /* let the gallium frontend allocate the accum buffer */
499 }
500
501 static bool
dri_get_egl_image(struct pipe_frontend_screen * fscreen,void * egl_image,struct st_egl_image * stimg)502 dri_get_egl_image(struct pipe_frontend_screen *fscreen,
503 void *egl_image,
504 struct st_egl_image *stimg)
505 {
506 struct dri_screen *screen = (struct dri_screen *)fscreen;
507 const __DRIimageLookupExtension *loader = screen->dri2.image;
508 __DRIimage *img = NULL;
509 const struct dri2_format_mapping *map;
510
511 img = loader->lookupEGLImageValidated(egl_image, screen->loaderPrivate);
512
513 if (!img)
514 return false;
515
516 stimg->texture = NULL;
517 pipe_resource_reference(&stimg->texture, img->texture);
518 map = dri2_get_mapping_by_fourcc(img->dri_fourcc);
519 stimg->format = map ? map->pipe_format : img->texture->format;
520 stimg->level = img->level;
521 stimg->layer = img->layer;
522 stimg->imported_dmabuf = img->imported_dmabuf;
523
524 if (img->imported_dmabuf && map) {
525 /* Guess sized internal format for dma-bufs. Could be used
526 * by EXT_EGL_image_storage.
527 */
528 stimg->internalformat = driImageFormatToSizedInternalGLFormat(map->dri_format);
529 } else {
530 stimg->internalformat = img->internal_format;
531 }
532
533 stimg->yuv_color_space = img->yuv_color_space;
534 stimg->yuv_range = img->sample_range;
535
536 return true;
537 }
538
539 static bool
dri_validate_egl_image(struct pipe_frontend_screen * fscreen,void * egl_image)540 dri_validate_egl_image(struct pipe_frontend_screen *fscreen,
541 void *egl_image)
542 {
543 struct dri_screen *screen = (struct dri_screen *)fscreen;
544 const __DRIimageLookupExtension *loader = screen->dri2.image;
545
546 if (loader)
547 return loader->validateEGLImage(egl_image, screen->loaderPrivate);
548 else
549 return true;
550 }
551
552 static int
dri_get_param(struct pipe_frontend_screen * fscreen,enum st_manager_param param)553 dri_get_param(struct pipe_frontend_screen *fscreen,
554 enum st_manager_param param)
555 {
556 return 0;
557 }
558
559 void
dri_release_screen(struct dri_screen * screen)560 dri_release_screen(struct dri_screen * screen)
561 {
562 st_screen_destroy(&screen->base);
563
564 if (screen->base.screen) {
565 screen->base.screen->destroy(screen->base.screen);
566 screen->base.screen = NULL;
567 }
568
569 if (screen->dev) {
570 pipe_loader_release(&screen->dev, 1);
571 screen->dev = NULL;
572 }
573
574 mtx_destroy(&screen->opencl_func_mutex);
575 }
576
577 void
dri_destroy_screen(struct dri_screen * screen)578 dri_destroy_screen(struct dri_screen *screen)
579 {
580 dri_release_screen(screen);
581
582 free(screen->options.force_gl_vendor);
583 free(screen->options.force_gl_renderer);
584 free(screen->options.mesa_extension_override);
585
586 driDestroyOptionCache(&screen->optionCache);
587 driDestroyOptionInfo(&screen->optionInfo);
588
589 /* The caller in dri_util preserves the fd ownership */
590 free(screen);
591 }
592
593 static void
dri_postprocessing_init(struct dri_screen * screen)594 dri_postprocessing_init(struct dri_screen *screen)
595 {
596 unsigned i;
597
598 for (i = 0; i < PP_FILTERS; i++) {
599 screen->pp_enabled[i] = driQueryOptioni(&screen->dev->option_cache,
600 pp_filters[i].name);
601 }
602 }
603
604 static void
dri_set_background_context(struct st_context * st,struct util_queue_monitoring * queue_info)605 dri_set_background_context(struct st_context *st,
606 struct util_queue_monitoring *queue_info)
607 {
608 struct dri_context *ctx = (struct dri_context *)st->frontend_context;
609 const __DRIbackgroundCallableExtension *backgroundCallable =
610 ctx->screen->dri2.backgroundCallable;
611
612 if (backgroundCallable)
613 backgroundCallable->setBackgroundContext(ctx->loaderPrivate);
614
615 if (ctx->hud)
616 hud_add_queue_for_monitoring(ctx->hud, queue_info);
617 }
618
619 const __DRIconfig **
dri_init_screen(struct dri_screen * screen,struct pipe_screen * pscreen,bool has_multibuffer)620 dri_init_screen(struct dri_screen *screen,
621 struct pipe_screen *pscreen,
622 bool has_multibuffer)
623 {
624 screen->base.screen = pscreen;
625 screen->base.get_egl_image = dri_get_egl_image;
626 screen->base.get_param = dri_get_param;
627 screen->base.set_background_context = dri_set_background_context;
628 screen->base.validate_egl_image = dri_validate_egl_image;
629
630 if (pscreen->get_param(pscreen, PIPE_CAP_NPOT_TEXTURES))
631 screen->target = PIPE_TEXTURE_2D;
632 else
633 screen->target = PIPE_TEXTURE_RECT;
634
635 dri_init_options(screen);
636 dri_postprocessing_init(screen);
637
638 st_api_query_versions(&screen->base,
639 &screen->options,
640 &screen->max_gl_core_version,
641 &screen->max_gl_compat_version,
642 &screen->max_gl_es1_version,
643 &screen->max_gl_es2_version);
644
645 screen->throttle = pscreen->get_param(pscreen, PIPE_CAP_THROTTLE);
646 if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_PROTECTED_CONTEXT))
647 screen->has_protected_context = true;
648 screen->has_reset_status_query = pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY);
649
650
651 #ifdef HAVE_LIBDRM
652 if (has_multibuffer) {
653 int dmabuf_caps = pscreen->get_param(pscreen, PIPE_CAP_DMABUF);
654 if (dmabuf_caps & DRM_PRIME_CAP_IMPORT)
655 screen->dmabuf_import = true;
656 if (screen->dmabuf_import && dmabuf_caps & DRM_PRIME_CAP_EXPORT)
657 screen->has_dmabuf = true;
658 }
659 #endif
660
661 return dri_fill_in_modes(screen);
662 }
663
664 /* vim: set sw=3 ts=8 sts=3 expandtab: */
665