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