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
;
39 screen
->pfnSwrGetInterface
= SwrGetTileInterface
;
41 fprintf(stderr
, "(using: builtin).\n");
43 char filename
[256] = { 0 };
44 sprintf(filename
, "%sswr%s%s", UTIL_DL_PREFIX
, arch
, UTIL_DL_EXT
);
46 screen
->pLibrary
= util_dl_open(filename
);
47 if (!screen
->pLibrary
) {
48 fprintf(stderr
, "(skipping: %s).\n", util_dl_error());
52 util_dl_proc pApiProc
= util_dl_get_proc_address(screen
->pLibrary
,
54 util_dl_proc pTileApiProc
= util_dl_get_proc_address(screen
->pLibrary
,
55 "SwrGetTileIterface");
56 util_dl_proc pInitFunc
= util_dl_get_proc_address(screen
->pLibrary
,
58 if (!pApiProc
|| !pInitFunc
|| !pTileApiProc
) {
59 fprintf(stderr
, "(skipping: %s).\n", util_dl_error());
60 util_dl_close(screen
->pLibrary
);
61 screen
->pLibrary
= NULL
;
65 screen
->pfnSwrGetInterface
= (PFNSwrGetInterface
)pApiProc
;
66 screen
->pfnSwrGetTileInterface
= (PFNSwrGetTileInterface
)pTileApiProc
;
68 SWR_ASSERT(screen
->pfnSwrGetInterface
!= nullptr);
69 SWR_ASSERT(screen
->pfnSwrGetTileInterface
!= nullptr);
70 SWR_ASSERT(pInitFunc
!= nullptr);
74 fprintf(stderr
, "(using: %s).\n", filename
);
81 swr_create_screen(struct sw_winsys
*winsys
)
83 struct pipe_screen
*p_screen
= swr_create_screen_internal(winsys
);
88 struct swr_screen
*screen
= swr_screen(p_screen
);
89 screen
->is_knl
= false;
93 if (util_cpu_caps
.has_avx512f
&& util_cpu_caps
.has_avx512er
) {
94 fprintf(stderr
, "SWR detected KNL instruction support ");
96 fprintf(stderr
, "(skipping: not built).\n");
98 if (swr_initialize_screen_interface(screen
, "KNL")) {
99 screen
->is_knl
= true;
105 if (util_cpu_caps
.has_avx512f
&& util_cpu_caps
.has_avx512bw
) {
106 fprintf(stderr
, "SWR detected SKX instruction support ");
108 fprintf(stderr
, "(skipping not built).\n");
110 if (swr_initialize_screen_interface(screen
, "SKX"))
115 if (util_cpu_caps
.has_avx2
) {
116 fprintf(stderr
, "SWR detected AVX2 instruction support ");
117 #ifndef HAVE_SWR_AVX2
118 fprintf(stderr
, "(skipping not built).\n");
120 if (swr_initialize_screen_interface(screen
, "AVX2"))
125 if (util_cpu_caps
.has_avx
) {
126 fprintf(stderr
, "SWR detected AVX instruction support ");
128 fprintf(stderr
, "(skipping not built).\n");
130 if (swr_initialize_screen_interface(screen
, "AVX"))
135 fprintf(stderr
, "SWR could not initialize a supported CPU architecture.\n");
136 swr_destroy_screen_internal(&screen
);
143 // swap function called from libl_gdi.c
146 swr_gdi_swap(struct pipe_screen
*screen
,
147 struct pipe_resource
*res
,
150 screen
->flush_frontbuffer(screen
,