Skip to content

Commit

Permalink
vkconfig: Add Vulkan SDK release detection
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Feb 17, 2025
1 parent 0ed717a commit b78af53
Show file tree
Hide file tree
Showing 17 changed files with 512 additions and 70 deletions.
2 changes: 2 additions & 0 deletions vkconfig_core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ bool Configurator::Load() {
const QJsonObject& json_object = json_interface_object.value(GetToken(TAB_PREFERENCES)).toObject();

this->use_layer_dev_mode = json_object.value("use_layer_dev_mode").toBool();
this->latest_sdk_version = Version(json_object.value("latest_sdk_version").toString().toStdString().c_str());
this->use_system_tray = json_object.value("use_system_tray").toBool();
::SetHomePath(json_object.value("VK_HOME").toString().toStdString());
}
Expand Down Expand Up @@ -873,6 +874,7 @@ bool Configurator::Save() const {
QJsonObject json_object;
json_object.insert("use_system_tray", this->use_system_tray);
json_object.insert("use_layer_dev_mode", this->use_layer_dev_mode);
json_object.insert("latest_sdk_version", this->latest_sdk_version.str().c_str());
json_object.insert("VK_HOME", ::Path(Path::HOME).RelativePath().c_str());
json_interface_object.insert(GetToken(TAB_PREFERENCES), json_object);
}
Expand Down
2 changes: 2 additions & 0 deletions vkconfig_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class Configurator {
TabType active_tab = TAB_CONFIGURATIONS;
bool advanced = true;
Path last_path_status = Path(Path::HOME).RelativePath() + "/vkconfig.txt";
Version latest_sdk_version = Version::VKHEADER;
Version online_sdk_version = Version::NONE;

private:
int hide_message_boxes_flags = 0;
Expand Down
145 changes: 138 additions & 7 deletions vkconfig_core/test/test_version.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020-2021 Valve Corporation
* Copyright (c) 2020-2021 LunarG, Inc.
* Copyright (c) 2020-2025 Valve Corporation
* Copyright (c) 2020-2025 LunarG, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -27,17 +27,148 @@
TEST(test_version, string) {
const std::string version_a("1.1.130");
const std::string version_b("1.2.145");
const std::string version_c("1.3.298.0");
const std::string version_d("1.4");

EXPECT_EQ(version_a, Version(version_a.c_str()).str());
EXPECT_EQ(version_b, Version(version_b.c_str()).str());
EXPECT_EQ(version_c, Version(version_c.c_str()).str());
EXPECT_EQ(version_d, Version(version_d.c_str()).str());
}

TEST(test_version, string_ctr) { EXPECT_EQ(Version(1, 1, 130), Version("1.1.130")); }
TEST(test_version, string_ctr) {
EXPECT_EQ(Version(2, 0), Version("2"));
EXPECT_EQ(Version(1, 4), Version("1.4"));
EXPECT_EQ(Version(1, 1, 130), Version("1.1.130"));
EXPECT_EQ(Version(1, 4, 304, 1), Version("1.4.304.1"));
}

TEST(test_version, compare) {
const std::string version_a("1.1.130");
const std::string version_b("1.2.135");
const std::string version_c("1.2.145");
TEST(test_version, compare_2) {
const Version version_a("1.1");
const Version version_b("1.2");
const Version version_c("2.0");
const Version version_d("2.1");

EXPECT_TRUE(version_a == version_a);
EXPECT_TRUE(version_b == version_b);
EXPECT_TRUE(version_c == version_c);

EXPECT_TRUE(version_a != version_b);
EXPECT_TRUE(version_b != version_c);
EXPECT_TRUE(version_a != version_c);
EXPECT_TRUE(version_a != version_d);

EXPECT_TRUE(version_a < version_b);
EXPECT_TRUE(version_b < version_c);
EXPECT_TRUE(version_a < version_c);
EXPECT_TRUE(version_a < version_d);

EXPECT_TRUE(version_a <= version_a);
EXPECT_TRUE(version_b <= version_b);
EXPECT_TRUE(version_c <= version_c);
EXPECT_TRUE(version_d <= version_d);

EXPECT_TRUE(version_a <= version_b);
EXPECT_TRUE(version_b <= version_c);
EXPECT_TRUE(version_b <= version_d);
EXPECT_TRUE(version_c <= version_d);

EXPECT_TRUE(version_b > version_a);
EXPECT_TRUE(version_c > version_b);
EXPECT_TRUE(version_c > version_a);
EXPECT_TRUE(version_d > version_b);

EXPECT_TRUE(version_a >= version_a);
EXPECT_TRUE(version_b >= version_b);
EXPECT_TRUE(version_c >= version_c);
EXPECT_TRUE(version_d >= version_d);

EXPECT_TRUE(version_b >= version_a);
EXPECT_TRUE(version_c >= version_b);
EXPECT_TRUE(version_c >= version_a);
EXPECT_TRUE(version_d >= version_b);
}

TEST(test_version, compare_3) {
const Version version_a("1.1.130");
const Version version_b("1.2.135");
const Version version_c("1.2.145");

EXPECT_TRUE(version_a == version_a);
EXPECT_TRUE(version_b == version_b);
EXPECT_TRUE(version_c == version_c);

EXPECT_TRUE(version_a != version_b);
EXPECT_TRUE(version_b != version_c);
EXPECT_TRUE(version_a != version_c);

EXPECT_TRUE(version_a < version_b);
EXPECT_TRUE(version_b < version_c);
EXPECT_TRUE(version_a < version_c);

EXPECT_TRUE(version_a <= version_a);
EXPECT_TRUE(version_b <= version_b);
EXPECT_TRUE(version_c <= version_c);

EXPECT_TRUE(version_a <= version_b);
EXPECT_TRUE(version_b <= version_c);
EXPECT_TRUE(version_a <= version_c);

EXPECT_TRUE(version_b > version_a);
EXPECT_TRUE(version_c > version_b);
EXPECT_TRUE(version_c > version_a);

EXPECT_TRUE(version_a >= version_a);
EXPECT_TRUE(version_b >= version_b);
EXPECT_TRUE(version_c >= version_c);

EXPECT_TRUE(version_b >= version_a);
EXPECT_TRUE(version_c >= version_b);
EXPECT_TRUE(version_c >= version_a);
}

TEST(test_version, compare_4) {
const Version version_a("1.2.135.1");
const Version version_b("1.2.145.0");
const Version version_c("1.2.145.1");

EXPECT_TRUE(version_a == version_a);
EXPECT_TRUE(version_b == version_b);
EXPECT_TRUE(version_c == version_c);

EXPECT_TRUE(version_a != version_b);
EXPECT_TRUE(version_b != version_c);
EXPECT_TRUE(version_a != version_c);

EXPECT_TRUE(version_a < version_b);
EXPECT_TRUE(version_b < version_c);
EXPECT_TRUE(version_a < version_c);

EXPECT_TRUE(version_a <= version_a);
EXPECT_TRUE(version_b <= version_b);
EXPECT_TRUE(version_c <= version_c);

EXPECT_TRUE(version_a <= version_b);
EXPECT_TRUE(version_b <= version_c);
EXPECT_TRUE(version_a <= version_c);

EXPECT_TRUE(version_b > version_a);
EXPECT_TRUE(version_c > version_b);
EXPECT_TRUE(version_c > version_a);

EXPECT_TRUE(version_a >= version_a);
EXPECT_TRUE(version_b >= version_b);
EXPECT_TRUE(version_c >= version_c);

EXPECT_TRUE(version_b >= version_a);
EXPECT_TRUE(version_c >= version_b);
EXPECT_TRUE(version_c >= version_a);
}

TEST(test_version, compare_mix) {
const Version version_a("1.1");
const Version version_b("1.1.135");
const Version version_c("1.1.135.1");

EXPECT_TRUE(version_a == version_a);
EXPECT_TRUE(version_b == version_b);
Expand Down
18 changes: 18 additions & 0 deletions vkconfig_core/type_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ std::vector<std::string> GetPlatformTokens(int platform_flags) {
return result;
}

bool IsDesktop(PlatformType type) { return type >= PLATFORM_DESKTOP_FIRST && type <= PLATFORM_DESKTOP_LAST; }

bool IsPlatformSupported(int platform_flags) { return platform_flags & (1 << VKC_PLATFORM); }

const char* GetLabel(PlatformType type) {
Expand All @@ -84,3 +86,19 @@ const char* GetLabel(PlatformType type) {

return TABLE[type];
}

const char* GetLatestSDK(PlatformType type) {
assert(IsDesktop(type));

static const char* TABLE[] = {
"https://vulkan.lunarg.com/sdk/latest/windows.txt", // PLATFORM_WINDOWS_X86
"https://vulkan.lunarg.com/sdk/latest/warm.txt", // PLATFORM_WINDOWS_ARM
"https://vulkan.lunarg.com/sdk/latest/linux.txt", // PLATFORM_LINUX
"https://vulkan.lunarg.com/sdk/latest/mac.txt", // PLATFORM_MACOS
"N/A", // PLATFORM_ANDROID
"N/A", // PLATFORM_IOS
};
static_assert(std::size(TABLE) == PLATFORM_COUNT, "The tranlation table size doesn't match the enum number of elements");

return TABLE[type];
}
9 changes: 8 additions & 1 deletion vkconfig_core/type_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ enum PlatformType {
PLATFORM_IOS = 5,

PLATFORM_FIRST = PLATFORM_WINDOWS_X86,
PLATFORM_LAST = PLATFORM_IOS
PLATFORM_LAST = PLATFORM_IOS,

PLATFORM_DESKTOP_FIRST = PLATFORM_WINDOWS_X86,
PLATFORM_DESKTOP_LAST = PLATFORM_MACOS
};

enum { PLATFORM_COUNT = PLATFORM_LAST - PLATFORM_FIRST + 1 };
Expand Down Expand Up @@ -88,6 +91,10 @@ std::vector<std::string> GetPlatformTokens(int platform_flags);
#error "Unknown platform"
#endif

bool IsDesktop(PlatformType type);

bool IsPlatformSupported(int platform_flags);

const char* GetLabel(PlatformType type);

const char* GetLatestSDK(PlatformType type);
12 changes: 12 additions & 0 deletions vkconfig_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ bool IsFloat(const std::string& s) {
return std::regex_search(s, FRAME_REGEX);
}

std::size_t CountChar(const std::string& value, char c) {
std::size_t count = 0;

for (std::size_t i = 0, n = value.size(); i < n; ++i) {
if (value[i] == c) {
++count;
}
}

return count;
}

void RemoveString(std::vector<std::string>& list, const std::string& value) {
std::vector<std::string> new_list;
new_list.reserve(list.size());
Expand Down
2 changes: 2 additions & 0 deletions vkconfig_core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ bool IsNumber(const std::string& s);

bool IsFloat(const std::string& s);

std::size_t CountChar(const std::string& value, char c);

// Remove a value if it's present
void RemoveString(std::vector<std::string>& list, const std::string& value);

Expand Down
71 changes: 52 additions & 19 deletions vkconfig_core/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,42 @@ static Version GetVersionData(const char *version) {
uint32_t version_major = 0;
uint32_t version_minor = 0;
uint32_t version_patch = 0;

std::sscanf(version, "%d.%d.%d", &version_major, &version_minor, &version_patch);

return Version(version_major, version_minor, version_patch);
uint32_t version_revision = 0;

std::size_t count = CountChar(version, '.');

switch (count) {
default:
assert(0);
return Version::NONE;
case 0:
std::sscanf(version, "%d", &version_major);
return Version(version_major, version_minor);
case 1:
std::sscanf(version, "%d.%d", &version_major, &version_minor);
return Version(version_major, version_minor);
case 2:
std::sscanf(version, "%d.%d.%d", &version_major, &version_minor, &version_patch);
return Version(version_major, version_minor, version_patch);
case 3:
std::sscanf(version, "%d.%d.%d.%d", &version_major, &version_minor, &version_patch, &version_revision);
return Version(version_major, version_minor, version_patch, version_revision);
}
}

Version::Version(uint32_t version_complete)
: _major(VK_VERSION_MAJOR(version_complete)),
_minor(VK_VERSION_MINOR(version_complete)),
_patch(VK_VERSION_PATCH(version_complete)) {}
_patch(VK_VERSION_PATCH(version_complete)),
_revision(VK_API_VERSION_VARIANT(version_complete)) {}

Version::Version(uint32_t version_major, uint32_t version_minor) : _major(version_major), _minor(version_minor), type(WITH_MINOR) {}

Version::Version(uint32_t version_major, uint32_t version_minor, uint32_t version_patch)
: _major(version_major), _minor(version_minor), _patch(version_patch) {}
: _major(version_major), _minor(version_minor), _patch(version_patch), type(WITH_PATCH) {}

Version::Version(uint32_t version_major, uint32_t version_minor, uint32_t version_patch, uint32_t version_revision)
: _major(version_major), _minor(version_minor), _patch(version_patch), _revision(version_revision), type(WITH_REVISION) {}

Version::Version(const char *version) : Version(GetVersionData(version)) {}

Expand All @@ -63,36 +86,46 @@ std::string Version::str() const {
if (*this == LATEST) {
return "Latest";
} else {
return format("%d.%d.%d", _major, _minor, _patch);
switch (this->type) {
case WITH_MAJOR:
return format("%d", _major);
case WITH_MINOR:
return format("%d.%d", _major, _minor);
default:
case WITH_PATCH:
return format("%d.%d.%d", _major, _minor, _patch);
case WITH_REVISION:
return format("%d.%d.%d.%d", _major, _minor, _patch, _revision);
}
}
}

bool Version::operator!=(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) !=
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) !=
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}

bool Version::operator==(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) ==
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) ==
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}

bool Version::operator<(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) <
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) <
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}

bool Version::operator>=(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) >=
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) >=
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}

bool Version::operator>(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) >
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) >
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}

bool Version::operator<=(const Version &other_version) const {
return VK_MAKE_VERSION(_major, _minor, _patch) <=
VK_MAKE_VERSION(other_version._major, other_version._minor, other_version._patch);
return VK_MAKE_API_VERSION(this->_major, this->_minor, this->_patch, this->_revision) <=
VK_MAKE_API_VERSION(other_version._major, other_version._minor, other_version._patch, other_version._revision);
}
Loading

0 comments on commit b78af53

Please sign in to comment.