Vulkan-Hpp
EnumerateDevicesAdvanced.cpp
Go to the documentation of this file.
1 // Copyright(c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // VulkanHpp Samples : EnumerateDevicesAdvanced
16 // Enumerate physical devices
17 
18 #include "../utils/utils.hpp"
19 
20 #include <iomanip>
21 #include <iostream>
23 
24 static char const * AppName = "EnumerateDevicesAdvanced";
25 static char const * EngineName = "Vulkan.hpp";
26 
27 int main( int /*argc*/, char ** /*argv*/ )
28 {
29  try
30  {
31  vk::Instance instance = vk::su::createInstance( AppName, EngineName );
32 #if !defined( NDEBUG )
34 #endif
35 
36  /* VULKAN_HPP_KEY_START */
37 
38  // enumerate the physicalDevices
39  std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
40 
41  for ( auto const & physicalDevice : physicalDevices )
42  {
43  vk::PhysicalDeviceProperties properties = physicalDevice.getProperties();
44 
45  std::cout << "apiVersion: ";
46  std::cout << ( ( properties.apiVersion >> 22 ) & 0xfff ) << '.'; // Major.
47  std::cout << ( ( properties.apiVersion >> 12 ) & 0x3ff ) << '.'; // Minor.
48  std::cout << ( properties.apiVersion & 0xfff ); // Patch.
49  std::cout << '\n';
50 
51  std::cout << "driverVersion: " << properties.driverVersion << '\n';
52 
53  std::cout << std::showbase << std::internal << std::setfill( '0' ) << std::hex;
54  std::cout << "vendorId: " << std::setw( 6 ) << properties.vendorID << '\n';
55  std::cout << "deviceId: " << std::setw( 6 ) << properties.deviceID << '\n';
56  std::cout << std::noshowbase << std::right << std::setfill( ' ' ) << std::dec;
57 
58  std::cout << "deviceType: " << vk::to_string( properties.deviceType ) << "\n";
59 
60  std::cout << "deviceName: " << properties.deviceName << '\n';
61 
62  std::cout << "pipelineCacheUUID: " << vk::su::UUID( properties.pipelineCacheUUID ) << "\n\n";
63  }
64 
65  /* VULKAN_HPP_KEY_END */
66 
67 #if !defined( NDEBUG )
68  instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
69 #endif
70  instance.destroy();
71  }
72  catch ( vk::SystemError & err )
73  {
74  std::cout << "vk::SystemError: " << err.what() << std::endl;
75  exit( -1 );
76  }
77  catch ( std::exception & err )
78  {
79  std::cout << "std::exception: " << err.what() << std::endl;
80  exit( -1 );
81  }
82  catch ( ... )
83  {
84  std::cout << "unknown error\n";
85  exit( -1 );
86  }
87  return 0;
88 }
int main(int, char **)
void cout(vk::SurfaceCapabilitiesKHR const &surfaceCapabilities)
VULKAN_HPP_NODISCARD Result createDebugUtilsMessengerEXT(const vk::DebugUtilsMessengerCreateInfoEXT *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::DebugUtilsMessengerEXT *pMessenger, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroy(const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result enumeratePhysicalDevices(uint32_t *pPhysicalDeviceCount, vk::PhysicalDevice *pPhysicalDevices, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroyDebugUtilsMessengerEXT(vk::DebugUtilsMessengerEXT messenger, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
virtual const char * what() const VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6206
vk::DebugUtilsMessengerCreateInfoEXT makeDebugUtilsMessengerCreateInfoEXT()
Definition: utils.cpp:1025
vk::Instance createInstance(std::string const &appName, std::string const &engineName, std::vector< std::string > const &layers, std::vector< std::string > const &extensions, uint32_t apiVersion)
Definition: utils.cpp:279
VULKAN_HPP_INLINE std::string to_string(FormatFeatureFlags value)
vk::PhysicalDeviceType deviceType
vk::ArrayWrapper1D< uint8_t, VK_UUID_SIZE > pipelineCacheUUID
vk::ArrayWrapper1D< char, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE > deviceName