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