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