From b342ff7b7f70a4b3f2cfc53215af8fa20adc3d86 Mon Sep 17 00:00:00 2001 From: Ofir Cohen Date: Thu, 26 Apr 2018 17:44:05 +0300 Subject: [PATCH] Fix vendors enumeration on 32-bit Windows OS (#28) When running 32-bit OpenCL applications on a 32-bit OS, we need to use the registry keys without the "Wow" suffix. On 64-bit OSes and 32-bit applications, OTOH, we must use the Wow suffix. --- icd_windows_hkr.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/icd_windows_hkr.c b/icd_windows_hkr.c index 076b60f..1e1f766 100644 --- a/icd_windows_hkr.c +++ b/icd_windows_hkr.c @@ -63,11 +63,30 @@ typedef enum mem = NULL; \ } while (0) -#ifdef _WIN64 static const char OPENCL_REG_SUB_KEY[] = "OpenCLDriverName"; + +#ifndef _WIN64 +static const char OPENCL_REG_SUB_KEY_WOW[] = "OpenCLDriverNameWow"; +#endif + +// Do not free the memory returned by this function. +static const char* GetOpenCLRegKeyName(void) +{ +#ifdef _WIN64 + return OPENCL_REG_SUB_KEY; #else -static const char OPENCL_REG_SUB_KEY[] = "OpenCLDriverNameWow"; + // The suffix/substring "WoW" is meaningful only when a 32-bit + // application is running on a 64-bit Windows OS. A 32-bit application + // running on a 32-bit OS uses non-WoW names. + BOOL is_wow64; + if (IsWow64Process(GetCurrentProcess(), &is_wow64) && is_wow64) + { + return OPENCL_REG_SUB_KEY_WOW; + } + + return OPENCL_REG_SUB_KEY; #endif +} static bool ReadOpenCLKey(DEVINST dnDevNode) { @@ -96,7 +115,7 @@ static bool ReadOpenCLKey(DEVINST dnDevNode) { result = RegQueryValueExA( hkey, - OPENCL_REG_SUB_KEY, + GetOpenCLRegKeyName(), NULL, &dwLibraryNameType, NULL, @@ -168,7 +187,6 @@ static DeviceProbeResult ProbeDevice(DEVINST devnode) devnode, 0); - // TODO: consider extracting warning messages out of this function if (CR_SUCCESS != ret) { KHR_ICD_TRACE(" WARNING: failed to probe the status of the device 0x%x\n", ret); @@ -341,8 +359,6 @@ bool khrIcdOsVendorsEnumerateHKR(void) &szGuid, 0); - KHR_ICD_ASSERT(devpropType == DEVPROP_TYPE_GUID); - if (CR_SUCCESS != ret || !IsEqualGUID(&OCL_GUID_DEVCLASS_SOFTWARECOMPONENT, &guid)) { -- 2.7.4