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