1 #include "dri_query_renderer.h"
2
3 #include "util/u_inlines.h"
4 #include "frontend/drm_driver.h"
5
6 #include "dri_screen.h"
7 #include "dri_query_renderer.h"
8 #include "pipe-loader/pipe_loader.h"
9
10 /**
11 * Implement queries for values that are common across all Mesa drivers
12 *
13 * Currently only the following queries are supported by this function:
14 *
15 * - \c __DRI2_RENDERER_VERSION
16 * - \c __DRI2_RENDERER_PREFERRED_PROFILE
17 * - \c __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION
18 * - \c __DRI2_RENDERER_OPENGL_COMPATIBLITY_PROFILE_VERSION
19 * - \c __DRI2_RENDERER_ES_PROFILE_VERSION
20 * - \c __DRI2_RENDERER_ES2_PROFILE_VERSION
21 * - \c __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT
22 *
23 * \returns
24 * Zero if a recognized value of \c param is supplied, -1 otherwise.
25 */
26 static int
driQueryRendererIntegerCommon(__DRIscreen * psp,int param,unsigned int * value)27 driQueryRendererIntegerCommon(__DRIscreen *psp, int param, unsigned int *value)
28 {
29 switch (param) {
30 case __DRI2_RENDERER_VERSION: {
31 static const char *const ver = PACKAGE_VERSION;
32 char *endptr;
33 int v[3];
34
35 v[0] = strtol(ver, &endptr, 10);
36 assert(endptr[0] == '.');
37 if (endptr[0] != '.')
38 return -1;
39
40 v[1] = strtol(endptr + 1, &endptr, 10);
41 assert(endptr[0] == '.');
42 if (endptr[0] != '.')
43 return -1;
44
45 v[2] = strtol(endptr + 1, &endptr, 10);
46
47 value[0] = v[0];
48 value[1] = v[1];
49 value[2] = v[2];
50 return 0;
51 }
52 case __DRI2_RENDERER_PREFERRED_PROFILE:
53 value[0] = (psp->max_gl_core_version != 0)
54 ? (1U << __DRI_API_OPENGL_CORE) : (1U << __DRI_API_OPENGL);
55 return 0;
56 case __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION:
57 value[0] = psp->max_gl_core_version / 10;
58 value[1] = psp->max_gl_core_version % 10;
59 return 0;
60 case __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION:
61 value[0] = psp->max_gl_compat_version / 10;
62 value[1] = psp->max_gl_compat_version % 10;
63 return 0;
64 case __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION:
65 value[0] = psp->max_gl_es1_version / 10;
66 value[1] = psp->max_gl_es1_version % 10;
67 return 0;
68 case __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION:
69 value[0] = psp->max_gl_es2_version / 10;
70 value[1] = psp->max_gl_es2_version % 10;
71 return 0;
72 case __DRI2_RENDERER_HAS_NO_ERROR_CONTEXT:
73 value[0] = GL_TRUE;
74 return 0;
75 default:
76 break;
77 }
78
79 return -1;
80 }
81
82 static int
dri2_query_renderer_integer(__DRIscreen * _screen,int param,unsigned int * value)83 dri2_query_renderer_integer(__DRIscreen *_screen, int param,
84 unsigned int *value)
85 {
86 struct dri_screen *screen = dri_screen(_screen);
87
88 switch (param) {
89 case __DRI2_RENDERER_VENDOR_ID:
90 value[0] =
91 (unsigned int)screen->base.screen->get_param(screen->base.screen,
92 PIPE_CAP_VENDOR_ID);
93 return 0;
94 case __DRI2_RENDERER_DEVICE_ID:
95 value[0] =
96 (unsigned int)screen->base.screen->get_param(screen->base.screen,
97 PIPE_CAP_DEVICE_ID);
98 return 0;
99 case __DRI2_RENDERER_ACCELERATED:
100 value[0] =
101 (unsigned int)!!screen->base.screen->get_param(screen->base.screen,
102 PIPE_CAP_ACCELERATED);
103 return 0;
104
105 case __DRI2_RENDERER_VIDEO_MEMORY: {
106 int ov = driQueryOptioni(&screen->dev->option_cache, "override_vram_size");
107 value[0] =
108 (unsigned int)screen->base.screen->get_param(screen->base.screen,
109 PIPE_CAP_VIDEO_MEMORY);
110 if (ov >= 0)
111 value[0] = MIN2(ov, value[0]);
112 return 0;
113 }
114
115 case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
116 value[0] =
117 (unsigned int)screen->base.screen->get_param(screen->base.screen,
118 PIPE_CAP_UMA);
119 return 0;
120
121 case __DRI2_RENDERER_HAS_TEXTURE_3D:
122 value[0] =
123 screen->base.screen->get_param(screen->base.screen,
124 PIPE_CAP_MAX_TEXTURE_3D_LEVELS) != 0;
125 return 0;
126
127 case __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB:
128 value[0] =
129 screen->base.screen->is_format_supported(screen->base.screen,
130 PIPE_FORMAT_B8G8R8A8_SRGB,
131 PIPE_TEXTURE_2D, 0, 0,
132 PIPE_BIND_RENDER_TARGET);
133 return 0;
134 case __DRI2_RENDERER_HAS_CONTEXT_PRIORITY:
135 value[0] =
136 screen->base.screen->get_param(screen->base.screen,
137 PIPE_CAP_CONTEXT_PRIORITY_MASK);
138 if (!value[0])
139 return -1;
140 return 0;
141 case __DRI2_RENDERER_HAS_PROTECTED_CONTENT:
142 value[0] =
143 screen->base.screen->get_param(screen->base.screen,
144 PIPE_CAP_DEVICE_PROTECTED_CONTENT);
145 if (!value[0])
146 return -1;
147 return 0;
148 case __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE:
149 value[0] =
150 screen->base.screen->get_param(screen->base.screen,
151 PIPE_CAP_PREFER_BACK_BUFFER_REUSE);
152 return 0;
153 default:
154 return driQueryRendererIntegerCommon(_screen, param, value);
155 }
156 }
157
158 static int
dri2_query_renderer_string(__DRIscreen * _screen,int param,const char ** value)159 dri2_query_renderer_string(__DRIscreen *_screen, int param,
160 const char **value)
161 {
162 struct dri_screen *screen = dri_screen(_screen);
163
164 switch (param) {
165 case __DRI2_RENDERER_VENDOR_ID:
166 value[0] = screen->base.screen->get_vendor(screen->base.screen);
167 return 0;
168 case __DRI2_RENDERER_DEVICE_ID:
169 value[0] = screen->base.screen->get_name(screen->base.screen);
170 return 0;
171 default:
172 return -1;
173 }
174 }
175
176 const __DRI2rendererQueryExtension dri2RendererQueryExtension = {
177 .base = { __DRI2_RENDERER_QUERY, 1 },
178
179 .queryInteger = dri2_query_renderer_integer,
180 .queryString = dri2_query_renderer_string
181 };
182