• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #ifndef SW_HELPER_H
3 #define SW_HELPER_H
4 
5 #include "pipe/p_compiler.h"
6 #include "util/u_debug.h"
7 #include "util/debug.h"
8 #include "target-helpers/sw_helper_public.h"
9 #include "frontend/sw_winsys.h"
10 
11 
12 /* Helper function to choose and instantiate one of the software rasterizers:
13  * llvmpipe, softpipe, swr.
14  */
15 
16 #ifdef GALLIUM_ZINK
17 #include "zink/zink_public.h"
18 #endif
19 
20 #ifdef GALLIUM_D3D12
21 #include "d3d12/d3d12_public.h"
22 #endif
23 
24 #ifdef GALLIUM_ASAHI
25 #include "asahi/agx_public.h"
26 #endif
27 
28 #ifdef GALLIUM_SOFTPIPE
29 #include "softpipe/sp_public.h"
30 #endif
31 
32 #ifdef GALLIUM_LLVMPIPE
33 #include "llvmpipe/lp_public.h"
34 #endif
35 
36 #ifdef GALLIUM_SWR
37 #include "swr/swr_public.h"
38 #endif
39 
40 #ifdef GALLIUM_VIRGL
41 #include "virgl/virgl_public.h"
42 #include "virgl/vtest/virgl_vtest_public.h"
43 #endif
44 
45 static inline struct pipe_screen *
sw_screen_create_named(struct sw_winsys * winsys,const char * driver)46 sw_screen_create_named(struct sw_winsys *winsys, const char *driver)
47 {
48    struct pipe_screen *screen = NULL;
49 
50 #if defined(GALLIUM_LLVMPIPE)
51    if (screen == NULL && strcmp(driver, "llvmpipe") == 0)
52       screen = llvmpipe_create_screen(winsys);
53 #endif
54 
55 #if defined(GALLIUM_VIRGL)
56    if (screen == NULL && strcmp(driver, "virpipe") == 0) {
57       struct virgl_winsys *vws;
58       vws = virgl_vtest_winsys_wrap(winsys);
59       screen = virgl_create_screen(vws, NULL);
60    }
61 #endif
62 
63 #if defined(GALLIUM_SOFTPIPE)
64    if (screen == NULL && strcmp(driver, "softpipe") == 0)
65       screen = softpipe_create_screen(winsys);
66 #endif
67 
68 #if defined(GALLIUM_SWR)
69    if (screen == NULL && strcmp(driver, "swr") == 0)
70       screen = swr_create_screen(winsys);
71 #endif
72 
73 #if defined(GALLIUM_ZINK)
74    if (screen == NULL && strcmp(driver, "zink") == 0)
75       screen = zink_create_screen(winsys);
76 #endif
77 
78 #if defined(GALLIUM_D3D12)
79    if (screen == NULL && strcmp(driver, "d3d12") == 0)
80       screen = d3d12_create_dxcore_screen(winsys, NULL);
81 #endif
82 
83 #if defined(GALLIUM_ASAHI)
84    if (screen == NULL && strcmp(driver, "asahi") == 0)
85       screen = agx_screen_create(winsys);
86 #endif
87 
88    return screen;
89 }
90 
91 struct pipe_screen *
sw_screen_create_vk(struct sw_winsys * winsys,bool sw_vk)92 sw_screen_create_vk(struct sw_winsys *winsys, bool sw_vk)
93 {
94    UNUSED bool only_sw = env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
95    const char *drivers[] = {
96       (sw_vk ? "" : debug_get_option("GALLIUM_DRIVER", "")),
97 #if defined(GALLIUM_D3D12)
98       (sw_vk || only_sw) ? "" : "d3d12",
99 #endif
100 #if defined(GALLIUM_ASAHI)
101       (sw_vk || only_sw) ? "" : "asahi",
102 #endif
103 #if defined(GALLIUM_LLVMPIPE)
104       "llvmpipe",
105 #endif
106 #if defined(GALLIUM_SOFTPIPE)
107       sw_vk ? "" : "softpipe",
108 #endif
109 #if defined(GALLIUM_SWR)
110       sw_vk ? "" : "swr",
111 #endif
112 #if defined(GALLIUM_ZINK)
113       (sw_vk || only_sw) ? "" : "zink",
114 #endif
115    };
116 
117    for (unsigned i = 0; i < ARRAY_SIZE(drivers); i++) {
118       struct pipe_screen *screen = sw_screen_create_named(winsys, drivers[i]);
119       if (screen)
120          return screen;
121       /* If the env var is set, don't keep trying things */
122       else if (i == 0 && drivers[i][0] != '\0')
123          return NULL;
124    }
125    return NULL;
126 }
127 
128 struct pipe_screen *
sw_screen_create(struct sw_winsys * winsys)129 sw_screen_create(struct sw_winsys *winsys)
130 {
131    return sw_screen_create_vk(winsys, false);
132 }
133 #endif
134