Skip to content

Commit 4aa6837

Browse files
jenatalibashbaug
andauthored
Rewrite CLOn12 loader in C (#179)
* Rewrite CLOn12 loader in C * Remove additional now-unneeded extern "C" guards for khrEnableTrace * Fix trace message Co-authored-by: Ben Ashbaugh <[email protected]> Co-authored-by: Ben Ashbaugh <[email protected]>
1 parent 7305673 commit 4aa6837

File tree

5 files changed

+101
-188
lines changed

5 files changed

+101
-188
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ set (OPENCL_ICD_LOADER_SOURCES
6969
loader/icd_platform.h)
7070

7171
if (WIN32)
72-
enable_language (CXX)
7372
list (APPEND OPENCL_ICD_LOADER_SOURCES
7473
loader/windows/adapter.h
7574
loader/windows/icd_windows.c
@@ -79,7 +78,7 @@ if (WIN32)
7978
loader/windows/icd_windows_envvars.c
8079
loader/windows/icd_windows_hkr.c
8180
loader/windows/icd_windows_hkr.h
82-
loader/windows/icd_windows_apppackage.cpp
81+
loader/windows/icd_windows_apppackage.c
8382
loader/windows/icd_windows_apppackage.h
8483
loader/windows/OpenCL.def
8584
loader/windows/OpenCL.rc)

loader/icd.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,7 @@ struct KHRicdVendorRec
8585
// the global state
8686
extern KHRicdVendor * khrIcdVendors;
8787

88-
#ifdef __cplusplus
89-
extern "C" {
90-
#endif
91-
extern int khrEnableTrace;
92-
#ifdef __cplusplus
93-
}
94-
#endif
88+
extern int khrEnableTrace;
9589

9690
#if defined(CL_ENABLE_LAYERS)
9791
/*
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2017-2019 The Khronos Group Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* OpenCL is a trademark of Apple Inc. used under license by Khronos.
17+
*/
18+
19+
#include <icd.h>
20+
#include "icd_windows_apppackage.h"
21+
22+
#ifdef OPENCL_ICD_LOADER_DISABLE_OPENCLON12
23+
24+
bool khrIcdOsVendorsEnumerateAppPackage(void)
25+
{
26+
KHR_ICD_TRACE("OpenCLOn12 is disabled\n");
27+
return false;
28+
}
29+
30+
#else
31+
32+
#include <AppModel.h>
33+
34+
bool khrIcdOsVendorsEnumerateAppPackage(void)
35+
{
36+
UINT32 numPackages = 0, bufferLength = 0;
37+
PCWSTR familyName = L"Microsoft.D3DMappingLayers_8wekyb3d8bbwe";
38+
if (ERROR_INSUFFICIENT_BUFFER != GetPackagesByPackageFamily(familyName,
39+
&numPackages, NULL,
40+
&bufferLength, NULL) ||
41+
numPackages == 0 || bufferLength == 0)
42+
{
43+
KHR_ICD_TRACE("Failed to find mapping layers packages by family name\n");
44+
return false;
45+
}
46+
47+
bool ret = false;
48+
WCHAR *buffer = malloc(sizeof(WCHAR) * bufferLength);
49+
PWSTR *packages = malloc(sizeof(PWSTR) * numPackages);
50+
if (!buffer || !packages)
51+
{
52+
KHR_ICD_TRACE("Failed to allocate memory for package names\n");
53+
goto cleanup;
54+
}
55+
56+
if (ERROR_SUCCESS != GetPackagesByPackageFamily(familyName,
57+
&numPackages, packages,
58+
&bufferLength, buffer))
59+
{
60+
KHR_ICD_TRACE("Failed to get mapping layers package full names\n");
61+
goto cleanup;
62+
}
63+
64+
UINT32 pathLength = 0;
65+
WCHAR path[MAX_PATH];
66+
if (ERROR_INSUFFICIENT_BUFFER != GetPackagePathByFullName(packages[0], &pathLength, NULL) ||
67+
pathLength > MAX_PATH ||
68+
ERROR_SUCCESS != GetPackagePathByFullName(packages[0], &pathLength, path))
69+
{
70+
KHR_ICD_TRACE("Failed to get mapping layers package path length\n");
71+
goto cleanup;
72+
}
73+
74+
#if defined(_M_AMD64)
75+
#define PLATFORM_PATH L"x64"
76+
#elif defined(_M_ARM)
77+
#define PLATFORM_PATH L"arm"
78+
#elif defined(_M_ARM64)
79+
#define PLATFORM_PATH L"arm64"
80+
#elif defined(_M_IX86)
81+
#define PLATFORM_PATH L"x86"
82+
#endif
83+
84+
wchar_t dllPath[MAX_PATH];
85+
wcscpy_s(dllPath, MAX_PATH, path);
86+
wcscat_s(dllPath, MAX_PATH, L"\\" PLATFORM_PATH L"\\OpenCLOn12.dll");
87+
88+
char narrowDllPath[MAX_PATH];
89+
WideCharToMultiByte(CP_ACP, 0, dllPath, -1, narrowDllPath, MAX_PATH, NULL, NULL);
90+
91+
ret = adapterAdd(narrowDllPath, ZeroLuid);
92+
93+
cleanup:
94+
free(buffer);
95+
free(packages);
96+
return ret;
97+
}
98+
99+
#endif

loader/windows/icd_windows_apppackage.cpp

Lines changed: 0 additions & 176 deletions
This file was deleted.

loader/windows/icd_windows_apppackage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@
1919
#include <stdbool.h>
2020
#include "icd_windows.h"
2121

22-
#ifdef __cplusplus
23-
extern "C"
24-
#endif
2522
bool khrIcdOsVendorsEnumerateAppPackage(void);

0 commit comments

Comments
 (0)