* IN THE SOFTWARE.
***************************************************************************/
+#include "memory/InitMemory.h"
#include "util/u_cpu_detect.h"
#include "util/u_dl.h"
#include "swr_public.h"
#include <stdio.h>
+// Helper function to resolve the backend filename based on architecture
+static bool
+swr_initialize_screen_interface(struct swr_screen *screen, const char arch[])
+{
+#ifdef HAVE_SWR_BUILTIN
+ screen->pLibrary = NULL;
+ screen->pfnSwrGetInterface = SwrGetInterface;
+ screen->pfnSwrGetTileInterface = SwrGetTileIterface;
+ InitTilesTable();
+ swr_print_info("(using: builtin).\n");
+#else
+ char filename[256] = { 0 };
+ sprintf(filename, "%sswr%s%s", UTIL_DL_PREFIX, arch, UTIL_DL_EXT);
+
+ screen->pLibrary = util_dl_open(filename);
+ if (!screen->pLibrary) {
+ fprintf(stderr, "(skipping: %s).\n", util_dl_error());
+ return false;
+ }
+
+ util_dl_proc pApiProc = util_dl_get_proc_address(screen->pLibrary,
+ "SwrGetInterface");
+ util_dl_proc pTileApiProc = util_dl_get_proc_address(screen->pLibrary,
+ "SwrGetTileIterface");
+ util_dl_proc pInitFunc = util_dl_get_proc_address(screen->pLibrary,
+ "InitTilesTable");
+ if (!pApiProc || !pInitFunc || !pTileApiProc) {
+ fprintf(stderr, "(skipping: %s).\n", util_dl_error());
+ util_dl_close(screen->pLibrary);
+ screen->pLibrary = NULL;
+ return false;
+ }
+
+ screen->pfnSwrGetInterface = (PFNSwrGetInterface)pApiProc;
+ screen->pfnSwrGetTileInterface = (PFNSwrGetTileInterface)pTileApiProc;
+
+ SWR_ASSERT(screen->pfnSwrGetInterface != nullptr);
+ SWR_ASSERT(screen->pfnSwrGetTileInterface != nullptr);
+ SWR_ASSERT(pInitFunc != nullptr);
+
+ pInitFunc();
+
+ swr_print_info("(using: %s).\n", filename);
+#endif
+
+ return true;
+}
+
+
struct pipe_screen *
swr_create_screen(struct sw_winsys *winsys)
{
- char filename[256] = { 0 };
- fprintf(stderr, "SWR detected ");
+ struct pipe_screen *p_screen = swr_create_screen_internal(winsys);
+ if (!p_screen) {
+ return NULL;
+ }
- util_dl_library *pLibrary = nullptr;
+ struct swr_screen *screen = swr_screen(p_screen);
+ screen->is_knl = false;
util_cpu_detect();
- if (!strlen(filename) &&
- util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512er) {
-#if HAVE_SWR_KNL
- fprintf(stderr, "KNL ");
- sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrKNL", UTIL_DL_EXT);
+ if (util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512er) {
+ swr_print_info("SWR detected KNL instruction support ");
+#ifndef HAVE_SWR_KNL
+ swr_print_info("(skipping: not built).\n");
#else
- fprintf(stderr, "KNL (not built) ");
+ if (swr_initialize_screen_interface(screen, "KNL")) {
+ screen->is_knl = true;
+ return p_screen;
+ }
#endif
}
- if (!strlen(filename) &&
- util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512bw) {
-#if HAVE_SWR_SKX
- fprintf(stderr, "SKX ");
- sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrSKX", UTIL_DL_EXT);
+ if (util_cpu_caps.has_avx512f && util_cpu_caps.has_avx512bw) {
+ swr_print_info("SWR detected SKX instruction support ");
+#ifndef HAVE_SWR_SKX
+ swr_print_info("(skipping not built).\n");
#else
- fprintf(stderr, "SKX (not built) ");
+ if (swr_initialize_screen_interface(screen, "SKX"))
+ return p_screen;
#endif
}
- if (!strlen(filename) && util_cpu_caps.has_avx2) {
-#if HAVE_SWR_AVX2
- fprintf(stderr, "AVX2 ");
- sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX2", UTIL_DL_EXT);
+ if (util_cpu_caps.has_avx2) {
+ swr_print_info("SWR detected AVX2 instruction support ");
+#ifndef HAVE_SWR_AVX2
+ swr_print_info("(skipping not built).\n");
#else
- fprintf(stderr, "AVX2 (not built) ");
+ if (swr_initialize_screen_interface(screen, "AVX2"))
+ return p_screen;
#endif
}
- if (!strlen(filename) && util_cpu_caps.has_avx) {
-#if HAVE_SWR_AVX
- fprintf(stderr, "AVX ");
- sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX", UTIL_DL_EXT);
+ if (util_cpu_caps.has_avx) {
+ swr_print_info("SWR detected AVX instruction support ");
+#ifndef HAVE_SWR_AVX
+ swr_print_info("(skipping not built).\n");
#else
- fprintf(stderr, "AVX (not built) ");
+ if (swr_initialize_screen_interface(screen, "AVX"))
+ return p_screen;
#endif
}
- if (!strlen(filename)) {
- fprintf(stderr, "- no appropriate swr architecture library. Aborting!\n");
- exit(-1);
- } else {
- fprintf(stderr, "\n");
- }
-
- pLibrary = util_dl_open(filename);
-
- if (!pLibrary) {
- fprintf(stderr, "SWR library load failure: %s\n", util_dl_error());
- exit(-1);
- }
-
- util_dl_proc pApiProc = util_dl_get_proc_address(pLibrary, "SwrGetInterface");
-
- if (!pApiProc) {
- fprintf(stderr, "SWR library search failure: %s\n", util_dl_error());
- exit(-1);
- }
-
- struct pipe_screen *screen = swr_create_screen_internal(winsys);
- swr_screen(screen)->pfnSwrGetInterface = (PFNSwrGetInterface)pApiProc;
+ fprintf(stderr, "SWR could not initialize a supported CPU architecture.\n");
+ swr_destroy_screen_internal(&screen);
- return screen;
+ return NULL;
}