|
| 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 |
0 commit comments