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