1 /****************************************************************************
2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ***************************************************************************/
24 #include "memory/InitMemory.h"
25 #include "util/u_cpu_detect.h"
26 #include "util/u_dl.h"
27 #include "swr_public.h"
28 #include "swr_screen.h"
32 // Helper function to resolve the backend filename based on architecture
34 swr_initialize_screen_interface(struct swr_screen
*screen
, const char arch
[])
36 #ifdef HAVE_SWR_BUILTIN
37 screen
->pLibrary
= NULL
;
38 screen
->pfnSwrGetInterface
= SwrGetInterface
;
40 fprintf(stderr
, "(using: builtin).\n");
42 char filename
[256] = { 0 };
43 sprintf(filename
, "%sswr%s%s", UTIL_DL_PREFIX
, arch
, UTIL_DL_EXT
);
45 screen
->pLibrary
= util_dl_open(filename
);
46 if (!screen
->pLibrary
) {
47 fprintf(stderr
, "(skipping: %s).\n", util_dl_error());
51 util_dl_proc pApiProc
= util_dl_get_proc_address(screen
->pLibrary
,
53 util_dl_proc pInitFunc
= util_dl_get_proc_address(screen
->pLibrary
,
55 if (!pApiProc
|| !pInitFunc
) {
56 fprintf(stderr
, "(skipping: %s).\n", util_dl_error());
57 util_dl_close(screen
->pLibrary
);
58 screen
->pLibrary
= NULL
;
62 screen
->pfnSwrGetInterface
= (PFNSwrGetInterface
)pApiProc
;
65 fprintf(stderr
, "(using: %s).\n", filename
);
72 swr_create_screen(struct sw_winsys
*winsys
)
74 struct pipe_screen
*p_screen
= swr_create_screen_internal(winsys
);
79 struct swr_screen
*screen
= swr_screen(p_screen
);
80 screen
->is_knl
= false;
84 if (util_cpu_caps
.has_avx512f
&& util_cpu_caps
.has_avx512er
) {
85 fprintf(stderr
, "SWR detected KNL instruction support ");
87 fprintf(stderr
, "(skipping: not built).\n");
89 if (swr_initialize_screen_interface(screen
, "KNL")) {
90 screen
->is_knl
= true;
96 if (util_cpu_caps
.has_avx512f
&& util_cpu_caps
.has_avx512bw
) {
97 fprintf(stderr
, "SWR detected SKX instruction support ");
99 fprintf(stderr
, "(skipping not built).\n");
101 if (swr_initialize_screen_interface(screen
, "SKX"))
106 if (util_cpu_caps
.has_avx2
) {
107 fprintf(stderr
, "SWR detected AVX2 instruction support ");
108 #ifndef HAVE_SWR_AVX2
109 fprintf(stderr
, "(skipping not built).\n");
111 if (swr_initialize_screen_interface(screen
, "AVX2"))
116 if (util_cpu_caps
.has_avx
) {
117 fprintf(stderr
, "SWR detected AVX instruction support ");
119 fprintf(stderr
, "(skipping not built).\n");
121 if (swr_initialize_screen_interface(screen
, "AVX"))
126 fprintf(stderr
, "SWR could not initialize a supported CPU architecture.\n");
127 swr_destroy_screen_internal(&screen
);
134 // swap function called from libl_gdi.c
137 swr_gdi_swap(struct pipe_screen
*screen
,
138 struct pipe_resource
*res
,
141 screen
->flush_frontbuffer(screen
,