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.
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_VIRGL
37#include "virgl/virgl_public.h"
38#include "virgl/vtest/virgl_vtest_public.h"
39#endif
40
41static inline struct pipe_screen *
42sw_screen_create_named(struct sw_winsys *winsys, const struct pipe_screen_config *config, const char *driver)
43{
44   struct pipe_screen *screen = NULL;
45
46#if defined(GALLIUM_LLVMPIPE)
47   if (screen == NULL && strcmp(driver, "llvmpipe") == 0)
48      screen = llvmpipe_create_screen(winsys);
49#endif
50
51#if defined(GALLIUM_VIRGL)
52   if (screen == NULL && strcmp(driver, "virpipe") == 0) {
53      struct virgl_winsys *vws;
54      vws = virgl_vtest_winsys_wrap(winsys);
55      screen = virgl_create_screen(vws, NULL);
56   }
57#endif
58
59#if defined(GALLIUM_SOFTPIPE)
60   if (screen == NULL && strcmp(driver, "softpipe") == 0)
61      screen = softpipe_create_screen(winsys);
62#endif
63
64#if defined(GALLIUM_ZINK)
65   if (screen == NULL && strcmp(driver, "zink") == 0)
66      screen = zink_create_screen(winsys, config);
67#endif
68
69#if defined(GALLIUM_D3D12)
70   if (screen == NULL && strcmp(driver, "d3d12") == 0)
71      screen = d3d12_create_dxcore_screen(winsys, NULL);
72#endif
73
74#if defined(GALLIUM_ASAHI)
75   if (screen == NULL && strcmp(driver, "asahi") == 0)
76      screen = agx_screen_create(winsys);
77#endif
78
79   return screen;
80}
81
82struct pipe_screen *
83sw_screen_create_vk(struct sw_winsys *winsys, const struct pipe_screen_config *config, bool sw_vk)
84{
85   UNUSED bool only_sw = env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
86   const char *drivers[] = {
87      (sw_vk ? "" : debug_get_option("GALLIUM_DRIVER", "")),
88#if defined(GALLIUM_D3D12)
89      (sw_vk || only_sw) ? "" : "d3d12",
90#endif
91#if defined(GALLIUM_ASAHI)
92      (sw_vk || only_sw) ? "" : "asahi",
93#endif
94#if defined(GALLIUM_LLVMPIPE)
95      "llvmpipe",
96#endif
97#if defined(GALLIUM_SOFTPIPE)
98      sw_vk ? "" : "softpipe",
99#endif
100   };
101
102   for (unsigned i = 0; i < ARRAY_SIZE(drivers); i++) {
103      struct pipe_screen *screen = sw_screen_create_named(winsys, config, drivers[i]);
104      if (screen)
105         return screen;
106      /* If the env var is set, don't keep trying things */
107      else if (i == 0 && drivers[i][0] != '\0')
108         return NULL;
109   }
110   return NULL;
111}
112
113struct pipe_screen *
114sw_screen_create_zink(struct sw_winsys *winsys, const struct pipe_screen_config *config, bool whatever)
115{
116#if defined(GALLIUM_ZINK)
117   return zink_create_screen(winsys, config);
118#else
119   return NULL;
120#endif
121}
122
123struct pipe_screen *
124sw_screen_create(struct sw_winsys *winsys)
125{
126   return sw_screen_create_vk(winsys, NULL, false);
127}
128#endif
129