-
Notifications
You must be signed in to change notification settings - Fork 194
IGCL Version Check Update #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
257 changes: 257 additions & 0 deletions
257
IntelPresentMon/ControlLib/igcl/IgclControlLibCompatibility.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,257 @@ | ||
| // Copyright (C) 2026 Intel Corporation | ||
| // SPDX-License-Identifier: MIT | ||
| #include "IgclControlLibCompatibility.h" | ||
|
|
||
| #include "../Logging.h" | ||
|
|
||
| // Per-GPU ControlApiPath values are read from each present DISPLAY adapter | ||
| // driver registry key (SetupDi DIREG_DRV), analogous to indexed | ||
| // IDeviceConfigFactory GPU enumeration in the shared C# helper. | ||
|
|
||
| #include <Windows.h> | ||
| #include <SetupAPI.h> | ||
| #include <devguid.h> | ||
|
|
||
| #include <cstddef> | ||
| #include <filesystem> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #pragma comment(lib, "setupapi.lib") | ||
| #pragma comment(lib, "version.lib") | ||
|
|
||
| namespace pmon::tel::igcl | ||
| { | ||
| namespace | ||
| { | ||
| constexpr wchar_t kControlApiPathValueName[] = L"ControlApiPath"; | ||
|
|
||
| bool IsPreHotfixControlLibVersion_(ControlLibFileVersion version) noexcept | ||
| { | ||
| if (version.major < 1) { | ||
| return true; | ||
| } | ||
| if (version.major > 1) { | ||
| return false; | ||
| } | ||
|
|
||
| if (version.minor < 2) { | ||
| return true; | ||
| } | ||
| if (version.minor > 2) { | ||
| return false; | ||
| } | ||
|
|
||
| if (version.build > 269) { | ||
| return false; | ||
| } | ||
| if (version.build < 269) { | ||
| return true; | ||
| } | ||
| return version.privatePart < 269; | ||
| } | ||
|
|
||
| bool IsZesInitOnlyControlLibVersion_(ControlLibFileVersion version) noexcept | ||
| { | ||
| if (version.major > 1) { | ||
| return true; | ||
| } | ||
| return version.major == 1 && version.minor >= 3; | ||
| } | ||
|
|
||
| std::optional<std::wstring> ReadRegistryStringValue_(HKEY key, const wchar_t* valueName) | ||
| { | ||
| DWORD valueType = 0; | ||
| DWORD bufferBytes = 0; | ||
| const LSTATUS sizeStatus = RegQueryValueExW( | ||
| key, | ||
| valueName, | ||
| nullptr, | ||
| &valueType, | ||
| nullptr, | ||
| &bufferBytes); | ||
| if (sizeStatus != ERROR_SUCCESS || bufferBytes == 0) { | ||
| return std::nullopt; | ||
| } | ||
| if (valueType != REG_SZ && valueType != REG_EXPAND_SZ) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::wstring value; | ||
| value.resize((size_t)bufferBytes / sizeof(wchar_t)); | ||
| const LSTATUS readStatus = RegQueryValueExW( | ||
| key, | ||
| valueName, | ||
| nullptr, | ||
| &valueType, | ||
| reinterpret_cast<LPBYTE>(value.data()), | ||
| &bufferBytes); | ||
| if (readStatus != ERROR_SUCCESS) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| while (!value.empty() && value.back() == L'\0') { | ||
| value.pop_back(); | ||
| } | ||
| if (value.empty()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| if (valueType == REG_EXPAND_SZ) { | ||
| const DWORD expandedChars = ExpandEnvironmentStringsW(value.c_str(), nullptr, 0); | ||
| if (expandedChars == 0) { | ||
| return std::nullopt; | ||
| } | ||
| std::wstring expanded; | ||
| expanded.resize((size_t)expandedChars); | ||
| if (ExpandEnvironmentStringsW(value.c_str(), expanded.data(), expandedChars) == 0) { | ||
| return std::nullopt; | ||
| } | ||
| while (!expanded.empty() && expanded.back() == L'\0') { | ||
| expanded.pop_back(); | ||
| } | ||
| value = std::move(expanded); | ||
| } | ||
|
|
||
| return value; | ||
| } | ||
|
|
||
| std::optional<ControlLibFileVersion> TryReadPeFileVersion_(const std::wstring& path) | ||
| { | ||
| DWORD handle = 0; | ||
| const DWORD infoSize = GetFileVersionInfoSizeW(path.c_str(), &handle); | ||
| if (infoSize == 0) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::vector<std::byte> infoBuffer((size_t)infoSize); | ||
| if (!GetFileVersionInfoW(path.c_str(), 0, infoSize, infoBuffer.data())) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| VS_FIXEDFILEINFO* pFileInfo = nullptr; | ||
| UINT fileInfoLength = 0; | ||
| if (!VerQueryValueW( | ||
| infoBuffer.data(), | ||
| L"\\", | ||
| reinterpret_cast<LPVOID*>(&pFileInfo), | ||
| &fileInfoLength) | ||
| || pFileInfo == nullptr) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| ControlLibFileVersion version{}; | ||
| version.major = HIWORD(pFileInfo->dwFileVersionMS); | ||
| version.minor = LOWORD(pFileInfo->dwFileVersionMS); | ||
| version.build = HIWORD(pFileInfo->dwFileVersionLS); | ||
| version.privatePart = LOWORD(pFileInfo->dwFileVersionLS); | ||
| return version; | ||
| } | ||
|
|
||
| std::optional<std::vector<ControlLibFileVersion>> CollectControlLibFileVersionsFromRegistry_() | ||
| { | ||
| std::vector<ControlLibFileVersion> versions; | ||
|
|
||
| const HDEVINFO deviceInfoSet = SetupDiGetClassDevsW( | ||
| &GUID_DEVCLASS_DISPLAY, | ||
| nullptr, | ||
| nullptr, | ||
| DIGCF_PRESENT); | ||
| if (deviceInfoSet == INVALID_HANDLE_VALUE) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| SP_DEVINFO_DATA deviceInfoData{}; | ||
| deviceInfoData.cbSize = sizeof(deviceInfoData); | ||
|
|
||
| for (DWORD deviceIndex = 0;; ++deviceIndex) { | ||
| if (!SetupDiEnumDeviceInfo(deviceInfoSet, deviceIndex, &deviceInfoData)) { | ||
| if (GetLastError() == ERROR_NO_MORE_ITEMS) { | ||
| break; | ||
| } | ||
| SetupDiDestroyDeviceInfoList(deviceInfoSet); | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| const HKEY driverKey = SetupDiOpenDevRegKey( | ||
| deviceInfoSet, | ||
| &deviceInfoData, | ||
| DICS_FLAG_GLOBAL, | ||
| 0, | ||
| DIREG_DRV, | ||
| KEY_READ); | ||
| if (driverKey == INVALID_HANDLE_VALUE) { | ||
| continue; | ||
| } | ||
|
|
||
| const auto controlApiPath = ReadRegistryStringValue_(driverKey, kControlApiPathValueName); | ||
| RegCloseKey(driverKey); | ||
| if (!controlApiPath.has_value()) { | ||
| continue; | ||
| } | ||
|
|
||
| std::error_code fsError; | ||
| if (!std::filesystem::exists(*controlApiPath, fsError)) { | ||
| continue; | ||
| } | ||
|
|
||
| const auto fileVersion = TryReadPeFileVersion_(*controlApiPath); | ||
| if (fileVersion.has_value()) { | ||
| versions.push_back(*fileVersion); | ||
| } | ||
| } | ||
|
|
||
| SetupDiDestroyDeviceInfoList(deviceInfoSet); | ||
| return versions; | ||
| } | ||
| } | ||
|
|
||
| bool IsPreHotfixControlLibVersion(ControlLibFileVersion version) noexcept | ||
| { | ||
| return IsPreHotfixControlLibVersion_(version); | ||
| } | ||
|
|
||
| bool IsZesInitOnlyControlLibVersion(ControlLibFileVersion version) noexcept | ||
| { | ||
| return IsZesInitOnlyControlLibVersion_(version); | ||
| } | ||
|
|
||
| bool IsControlLibVersionMismatch(std::span<const ControlLibFileVersion> versions) noexcept | ||
| { | ||
| bool hasPreHotfix = false; | ||
| bool hasZesInitOnly = false; | ||
| for (const ControlLibFileVersion& version : versions) { | ||
| if (IsPreHotfixControlLibVersion_(version)) { | ||
| hasPreHotfix = true; | ||
| } | ||
| if (IsZesInitOnlyControlLibVersion_(version)) { | ||
| hasZesInitOnly = true; | ||
| } | ||
| if (hasPreHotfix && hasZesInitOnly) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool AreIgclControlLibsMismatched() noexcept | ||
| { | ||
| try { | ||
| const auto versions = CollectControlLibFileVersionsFromRegistry_(); | ||
| if (!versions.has_value()) { | ||
| pmlog_warn("IGCL control library compatibility check could not enumerate display adapters; skipping ctlInit"); | ||
| return true; | ||
| } | ||
| if (IsControlLibVersionMismatch(*versions)) { | ||
| pmlog_warn("Mixed IGCL control library versions detected across GPUs; skipping ctlInit"); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| catch (...) { | ||
| pmlog_warn("IGCL control library compatibility check failed; skipping ctlInit"); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
IntelPresentMon/ControlLib/igcl/IgclControlLibCompatibility.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (C) 2026 Intel Corporation | ||
| // SPDX-License-Identifier: MIT | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <span> | ||
| #include <vector> | ||
|
|
||
| namespace pmon::tel::igcl | ||
| { | ||
| struct ControlLibFileVersion | ||
| { | ||
| uint16_t major = 0; | ||
| uint16_t minor = 0; | ||
| uint16_t build = 0; | ||
| uint16_t privatePart = 0; | ||
| }; | ||
|
|
||
| bool IsPreHotfixControlLibVersion(ControlLibFileVersion version) noexcept; | ||
| bool IsZesInitOnlyControlLibVersion(ControlLibFileVersion version) noexcept; | ||
|
|
||
| // True when collected versions include both pre-hotfix (< 1.2.269.269) and 1.3+ builds. | ||
| bool IsControlLibVersionMismatch(std::span<const ControlLibFileVersion> versions) noexcept; | ||
|
|
||
| // Enumerates per-GPU ControlApiPath registry entries and compares file versions. | ||
| // Returns true when versions are mismatched OR when the compatibility check cannot be completed. | ||
| // Caller must not invoke ctlInit when true. | ||
| bool AreIgclControlLibsMismatched() noexcept; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
IntelPresentMon/UnitTests/IgclControlLibCompatibilityTests.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (C) 2026 Intel Corporation | ||
| // SPDX-License-Identifier: MIT | ||
| #include <CppUnitTest.h> | ||
| #include <ControlLib/igcl/IgclControlLibCompatibility.h> | ||
| #include <array> | ||
| #include <span> | ||
|
|
||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||
|
|
||
| namespace IgclControlLibCompatibilityTests | ||
| { | ||
| using pmon::tel::igcl::ControlLibFileVersion; | ||
| using pmon::tel::igcl::IsControlLibVersionMismatch; | ||
| using pmon::tel::igcl::IsPreHotfixControlLibVersion; | ||
| using pmon::tel::igcl::IsZesInitOnlyControlLibVersion; | ||
|
|
||
| TEST_CLASS(ControlLibVersionPredicateTests) | ||
| { | ||
| public: | ||
| TEST_METHOD(PreHotfixBelowOneTwoTwoSixNine) | ||
| { | ||
| Assert::IsTrue(IsPreHotfixControlLibVersion({ 1, 2, 268, 999 })); | ||
| Assert::IsFalse(IsPreHotfixControlLibVersion({ 1, 2, 269, 269 })); | ||
| Assert::IsFalse(IsPreHotfixControlLibVersion({ 1, 2, 270, 0 })); | ||
| } | ||
|
|
||
| TEST_METHOD(ZesInitOnlyAtOneThree) | ||
| { | ||
| Assert::IsTrue(IsZesInitOnlyControlLibVersion({ 1, 3, 0, 0 })); | ||
| Assert::IsFalse(IsZesInitOnlyControlLibVersion({ 1, 2, 999, 999 })); | ||
| } | ||
|
|
||
| TEST_METHOD(MismatchRequiresBothBuckets) | ||
| { | ||
| const ControlLibFileVersion preHotfix{ 1, 2, 100, 0 }; | ||
| const ControlLibFileVersion zesInit{ 1, 3, 0, 0 }; | ||
| const ControlLibFileVersion hotfixNeutral{ 1, 2, 269, 269 }; | ||
|
|
||
| Assert::IsTrue(IsControlLibVersionMismatch(std::array{ preHotfix, zesInit })); | ||
| Assert::IsFalse(IsControlLibVersionMismatch(std::array{ preHotfix, hotfixNeutral })); | ||
| Assert::IsFalse(IsControlLibVersionMismatch(std::array{ zesInit, hotfixNeutral })); | ||
| Assert::IsFalse(IsControlLibVersionMismatch(std::span<const ControlLibFileVersion>{})); | ||
| } | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.