-
Notifications
You must be signed in to change notification settings - Fork 179
VkCube.cpp: Organize platform info to an array to reduce macro usage #1108
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
base: main
Are you sure you want to change the base?
Conversation
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
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; }); |
There was a problem hiding this comment.
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; }); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author water-chika not on autobuild list. Waiting for curator authorization before starting CI build. |
Organize platform info to an array to reduce macro usage.