Path: blob/21.2-virgl/src/gallium/drivers/swr/swr_loader.cpp
4570 views
/****************************************************************************1* Copyright (C) 2016 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21***************************************************************************/2223#include "memory/InitMemory.h"24#include "util/u_cpu_detect.h"25#include "util/u_dl.h"26#include "swr_public.h"27#include "swr_screen.h"2829#include <stdio.h>3031// Helper function to resolve the backend filename based on architecture32static bool33swr_initialize_screen_interface(struct swr_screen *screen, const char arch[])34{35#ifdef HAVE_SWR_BUILTIN36screen->pLibrary = NULL;37screen->pfnSwrGetInterface = SwrGetInterface;38screen->pfnSwrGetTileInterface = SwrGetTileIterface;39InitTilesTable();40swr_print_info("(using: builtin).\n");41#else42char filename[256] = { 0 };43sprintf(filename, "%sswr%s%s", UTIL_DL_PREFIX, arch, UTIL_DL_EXT);4445screen->pLibrary = util_dl_open(filename);46if (!screen->pLibrary) {47fprintf(stderr, "(skipping: %s).\n", util_dl_error());48return false;49}5051util_dl_proc pApiProc = util_dl_get_proc_address(screen->pLibrary,52"SwrGetInterface");53util_dl_proc pTileApiProc = util_dl_get_proc_address(screen->pLibrary,54"SwrGetTileIterface");55util_dl_proc pInitFunc = util_dl_get_proc_address(screen->pLibrary,56"InitTilesTable");57if (!pApiProc || !pInitFunc || !pTileApiProc) {58fprintf(stderr, "(skipping: %s).\n", util_dl_error());59util_dl_close(screen->pLibrary);60screen->pLibrary = NULL;61return false;62}6364screen->pfnSwrGetInterface = (PFNSwrGetInterface)pApiProc;65screen->pfnSwrGetTileInterface = (PFNSwrGetTileInterface)pTileApiProc;6667SWR_ASSERT(screen->pfnSwrGetInterface != nullptr);68SWR_ASSERT(screen->pfnSwrGetTileInterface != nullptr);69SWR_ASSERT(pInitFunc != nullptr);7071pInitFunc();7273swr_print_info("(using: %s).\n", filename);74#endif7576return true;77}787980struct pipe_screen *81swr_create_screen(struct sw_winsys *winsys)82{83struct pipe_screen *p_screen = swr_create_screen_internal(winsys);84if (!p_screen) {85return NULL;86}8788struct swr_screen *screen = swr_screen(p_screen);89screen->is_knl = false;9091util_cpu_detect();9293if (util_get_cpu_caps()->has_avx512f && util_get_cpu_caps()->has_avx512er) {94swr_print_info("SWR detected KNL instruction support ");95#ifndef HAVE_SWR_KNL96swr_print_info("(skipping: not built).\n");97#else98if (swr_initialize_screen_interface(screen, "KNL")) {99screen->is_knl = true;100return p_screen;101}102#endif103}104105if (util_get_cpu_caps()->has_avx512f && util_get_cpu_caps()->has_avx512bw) {106swr_print_info("SWR detected SKX instruction support ");107#ifndef HAVE_SWR_SKX108swr_print_info("(skipping not built).\n");109#else110if (swr_initialize_screen_interface(screen, "SKX"))111return p_screen;112#endif113}114115if (util_get_cpu_caps()->has_avx2) {116swr_print_info("SWR detected AVX2 instruction support ");117#ifndef HAVE_SWR_AVX2118swr_print_info("(skipping not built).\n");119#else120if (swr_initialize_screen_interface(screen, "AVX2"))121return p_screen;122#endif123}124125if (util_get_cpu_caps()->has_avx) {126swr_print_info("SWR detected AVX instruction support ");127#ifndef HAVE_SWR_AVX128swr_print_info("(skipping not built).\n");129#else130if (swr_initialize_screen_interface(screen, "AVX"))131return p_screen;132#endif133}134135fprintf(stderr, "SWR could not initialize a supported CPU architecture.\n");136swr_destroy_screen_internal(&screen);137138return NULL;139}140141142#ifdef _WIN32143// swap function called from libl_gdi.c144145void146swr_gdi_swap(struct pipe_screen *screen,147struct pipe_context *ctx,148struct pipe_resource *res,149void *hDC)150{151screen->flush_frontbuffer(screen,152ctx,153res,1540, 0,155hDC,156NULL);157}158159#endif /* _WIN32 */160161162