tgsi/ureg: remove index parameter from ureg_DECL_system_value
[mesa.git] / src / gallium / auxiliary / pipe-loader / pipe_loader_sw.c
1 /**************************************************************************
2 *
3 * Copyright 2012 Francisco Jerez
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 #include "pipe_loader_priv.h"
29
30 #include "util/u_memory.h"
31 #include "util/u_dl.h"
32 #include "sw/dri/dri_sw_winsys.h"
33 #include "sw/kms-dri/kms_dri_sw_winsys.h"
34 #include "sw/null/null_sw_winsys.h"
35 #include "sw/wrapper/wrapper_sw_winsys.h"
36 #include "target-helpers/sw_helper_public.h"
37 #include "state_tracker/drisw_api.h"
38 #include "state_tracker/sw_driver.h"
39 #include "state_tracker/sw_winsys.h"
40
41 struct pipe_loader_sw_device {
42 struct pipe_loader_device base;
43 const struct sw_driver_descriptor *dd;
44 #ifndef GALLIUM_STATIC_TARGETS
45 struct util_dl_library *lib;
46 #endif
47 struct sw_winsys *ws;
48 };
49
50 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
51
52 static const struct pipe_loader_ops pipe_loader_sw_ops;
53
54 #ifdef GALLIUM_STATIC_TARGETS
55 static const struct sw_driver_descriptor driver_descriptors = {
56 .create_screen = sw_screen_create,
57 .winsys = {
58 #ifdef HAVE_PIPE_LOADER_DRI
59 {
60 .name = "dri",
61 .create_winsys = dri_create_sw_winsys,
62 },
63 #endif
64 #ifdef HAVE_PIPE_LOADER_KMS
65 {
66 .name = "kms_dri",
67 .create_winsys = kms_dri_create_winsys,
68 },
69 #endif
70 /**
71 * XXX: Do not include these two for non autotools builds.
72 * They don't have neither opencl nor nine, where these are used.
73 */
74 #ifndef DROP_PIPE_LOADER_MISC
75 {
76 .name = "null",
77 .create_winsys = null_sw_create,
78 },
79 {
80 .name = "wrapped",
81 .create_winsys = wrapper_sw_winsys_wrap_pipe_screen,
82 },
83 #endif
84 { 0 },
85 }
86 };
87 #endif
88
89 static bool
90 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device *sdev)
91 {
92 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
93 sdev->base.driver_name = "swrast";
94 sdev->base.ops = &pipe_loader_sw_ops;
95
96 #ifdef GALLIUM_STATIC_TARGETS
97 sdev->dd = &driver_descriptors;
98 if (!sdev->dd)
99 return false;
100 #else
101 sdev->lib = pipe_loader_find_module(&sdev->base, PIPE_SEARCH_DIR);
102 if (!sdev->lib)
103 return false;
104
105 sdev->dd = (const struct sw_driver_descriptor *)
106 util_dl_get_proc_address(sdev->lib, "swrast_driver_descriptor");
107
108 if (!sdev->dd){
109 util_dl_close(sdev->lib);
110 sdev->lib = NULL;
111 return false;
112 }
113 #endif
114
115 return true;
116 }
117
118 static void
119 pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device *sdev)
120 {
121 #ifndef GALLIUM_STATIC_TARGETS
122 if (sdev->lib)
123 util_dl_close(sdev->lib);
124 #endif
125 }
126
127 #ifdef HAVE_PIPE_LOADER_DRI
128 bool
129 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
130 {
131 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
132 int i;
133
134 if (!sdev)
135 return false;
136
137 if (!pipe_loader_sw_probe_init_common(sdev))
138 goto fail;
139
140 for (i = 0; sdev->dd->winsys[i].name; i++) {
141 if (strcmp(sdev->dd->winsys[i].name, "dri") == 0) {
142 sdev->ws = sdev->dd->winsys[i].create_winsys(drisw_lf);
143 break;
144 }
145 }
146 if (!sdev->ws)
147 goto fail;
148
149 *devs = &sdev->base;
150 return true;
151
152 fail:
153 pipe_loader_sw_probe_teardown_common(sdev);
154 FREE(sdev);
155 return false;
156 }
157 #endif
158
159 #ifdef HAVE_PIPE_LOADER_KMS
160 bool
161 pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
162 {
163 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
164 int i;
165
166 if (!sdev)
167 return false;
168
169 if (!pipe_loader_sw_probe_init_common(sdev))
170 goto fail;
171
172 for (i = 0; sdev->dd->winsys[i].name; i++) {
173 if (strcmp(sdev->dd->winsys[i].name, "kms_dri") == 0) {
174 sdev->ws = sdev->dd->winsys[i].create_winsys(fd);
175 break;
176 }
177 }
178 if (!sdev->ws)
179 goto fail;
180
181 *devs = &sdev->base;
182 return true;
183
184 fail:
185 pipe_loader_sw_probe_teardown_common(sdev);
186 FREE(sdev);
187 return false;
188 }
189 #endif
190
191 bool
192 pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
193 {
194 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
195 int i;
196
197 if (!sdev)
198 return false;
199
200 if (!pipe_loader_sw_probe_init_common(sdev))
201 goto fail;
202
203 for (i = 0; sdev->dd->winsys[i].name; i++) {
204 if (strcmp(sdev->dd->winsys[i].name, "null") == 0) {
205 sdev->ws = sdev->dd->winsys[i].create_winsys();
206 break;
207 }
208 }
209 if (!sdev->ws)
210 goto fail;
211
212 *devs = &sdev->base;
213 return true;
214
215 fail:
216 pipe_loader_sw_probe_teardown_common(sdev);
217 FREE(sdev);
218 return false;
219 }
220
221 int
222 pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
223 {
224 int i = 1;
225
226 if (i <= ndev) {
227 if (!pipe_loader_sw_probe_null(devs)) {
228 i--;
229 }
230 }
231
232 return i;
233 }
234
235 boolean
236 pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
237 struct pipe_screen *screen)
238 {
239 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
240 int i;
241
242 if (!sdev)
243 return false;
244
245 if (!pipe_loader_sw_probe_init_common(sdev))
246 goto fail;
247
248 for (i = 0; sdev->dd->winsys[i].name; i++) {
249 if (strcmp(sdev->dd->winsys[i].name, "wrapped") == 0) {
250 sdev->ws = sdev->dd->winsys[i].create_winsys(screen);
251 break;
252 }
253 }
254 if (!sdev->ws)
255 goto fail;
256
257 *dev = &sdev->base;
258 return true;
259
260 fail:
261 pipe_loader_sw_probe_teardown_common(sdev);
262 FREE(sdev);
263 return false;
264 }
265
266 static void
267 pipe_loader_sw_release(struct pipe_loader_device **dev)
268 {
269 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
270
271 #ifndef GALLIUM_STATIC_TARGETS
272 if (sdev->lib)
273 util_dl_close(sdev->lib);
274 #endif
275
276 FREE(sdev);
277 *dev = NULL;
278 }
279
280 static const struct drm_conf_ret *
281 pipe_loader_sw_configuration(struct pipe_loader_device *dev,
282 enum drm_conf conf)
283 {
284 return NULL;
285 }
286
287 static struct pipe_screen *
288 pipe_loader_sw_create_screen(struct pipe_loader_device *dev)
289 {
290 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
291 struct pipe_screen *screen;
292
293 screen = sdev->dd->create_screen(sdev->ws);
294 if (!screen)
295 sdev->ws->destroy(sdev->ws);
296
297 return screen;
298 }
299
300 static const struct pipe_loader_ops pipe_loader_sw_ops = {
301 .create_screen = pipe_loader_sw_create_screen,
302 .configuration = pipe_loader_sw_configuration,
303 .release = pipe_loader_sw_release
304 };