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