Skip to content

Conversation

@water-chika
Copy link
Contributor

@water-chika water-chika commented Apr 9, 2025

Organize platform info to an array to reduce macro usage.

@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

@water-chika water-chika changed the title VkCube.cpp: use constexpr and map to reduce macro usage frequency VkCube.cpp: Organize platform info to an array to reduce macro usage frequency Apr 9, 2025
@water-chika water-chika changed the title VkCube.cpp: Organize platform info to an array to reduce macro usage frequency VkCube.cpp: Organize platform info to an array to reduce macro usage Apr 9, 2025
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

constexpr auto platform_data = construct_array(platform_data_);

WsiPlatform wsi_from_string(std::string const &str) {
auto ite = std::find_if(platform_data.begin(), platform_data.end(), [&str](auto &data) { return data.name == str; });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a constexpr version of map can reduce find_if because platform_data is constexpr.

#endif
default:
return "unknown";
auto ite = std::find_if(platform_data.begin(), platform_data.end(), [&wsi_platform](auto &data) { return data.platform == wsi_platform; });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is constexpr version of map, this time consumption can be O(1).

wsi_platforms.append("fuchsia_scenic");
#endif

wsi_platforms.append(platform_data[0].name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, wsi_platforms can be constexpr because platform_data is constexpr

enabled_instance_extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
} else {
auto ite = std::find_if(platform_data.begin(), platform_data.end(), [platform = wsi_platform, &extension](auto &info) {
return !strcmp(info.surface_extension_name, extension.extensionName) && (platform == WsiPlatform::auto_ || platform == info.platform);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with previous find_if, if there exists constexpr map, this search can be O(1) rather than O(n).

"Vulkan installable client driver (ICD) installed?\nPlease "
"look at the Getting Started guide for additional "
"information.\n",
auto ite = std::find_if(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With constexpr map, this also can be O(1).

constexpr auto platform_run_from_main = get_platform_run_from_main();

template<size_t i=0>
auto construct_dispatcher(std::map<WsiPlatform, std::function<void()>>& map, Demo& demo) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every construct_dispatcher emplace an element of dispatcher.
If there exists a constexpr version of map, this construct_dispatcher also can be constexpr.

}

template<WsiPlatform platform>
auto get_dispatcher_element(Demo& demo) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

construct pair for a map. This pair map platform to a function.

@water-chika water-chika marked this pull request as ready for review April 10, 2025 02:39
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg
Copy link

Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants