Vulkan-Hpp
PhysicalDeviceGroups.cpp
Go to the documentation of this file.
1 // Copyright(c) 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 : PhysicalDeviceGroups
16 // Get the PhysicalDeviceGroups.
17 
18 #include "../utils/utils.hpp"
19 
20 #include <vector>
21 
22 static char const * AppName = "PhysicalDeviceGroups";
23 static char const * EngineName = "Vulkan.hpp";
24 
25 int main( int /*argc*/, char ** /*argv*/ )
26 {
27  try
28  {
29  vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, {}, VK_API_VERSION_1_1 );
30 #if !defined( NDEBUG )
32 #endif
33 
34  /* VULKAN_KEY_START */
35 
36  std::vector<vk::PhysicalDeviceGroupProperties> groupProperties = instance.enumeratePhysicalDeviceGroups();
37 
38  std::cout << std::boolalpha;
39  for ( size_t i = 0; i < groupProperties.size(); i++ )
40  {
41  std::cout << "Group Properties " << i << "\n";
42  std::cout << "\t"
43  << "physicalDeviceCount = " << groupProperties[i].physicalDeviceCount << "\n";
44  std::cout << "\t"
45  << "physicalDevices:\n";
46  for ( size_t j = 0; j < groupProperties[i].physicalDeviceCount; j++ )
47  {
48  std::cout << "\t\t" << j << " : " << groupProperties[i].physicalDevices[j].getProperties().deviceName << "\n";
49  }
50  std::cout << "\t"
51  << "subsetAllocation = " << !!groupProperties[i].subsetAllocation << "\n";
52  std::cout << "\n";
53 
54  if ( 0 < groupProperties[i].physicalDeviceCount )
55  {
56  vk::PhysicalDevice physicalDevice = groupProperties[i].physicalDevices[0];
57 
58  // get the QueueFamilyProperties of the first PhysicalDevice
59  std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
60 
61  // get the first index into queueFamiliyProperties which supports graphics
62  auto propertyIterator = std::find_if( queueFamilyProperties.begin(),
63  queueFamilyProperties.end(),
64  []( vk::QueueFamilyProperties const & qfp ) { return qfp.queueFlags & vk::QueueFlagBits::eGraphics; } );
65  size_t graphicsQueueFamilyIndex = std::distance( queueFamilyProperties.begin(), propertyIterator );
66  assert( graphicsQueueFamilyIndex < queueFamilyProperties.size() );
67 
68  // create a Device
69  float queuePriority = 0.0f;
70  vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
72  { {}, deviceQueueCreateInfo }, { groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices } );
73 
74  vk::Device device = physicalDevice.createDevice( deviceCreateInfoChain.get<vk::DeviceCreateInfo>() );
75 
76  // ... and destroy it again
77  device.destroy();
78  }
79  }
80 
81  /* VULKAN_KEY_END */
82 
83 #if !defined( NDEBUG )
84  instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
85 #endif
86  instance.destroy();
87  }
88  catch ( vk::SystemError & err )
89  {
90  std::cout << "vk::SystemError: " << err.what() << std::endl;
91  exit( -1 );
92  }
93  catch ( std::exception & err )
94  {
95  std::cout << "std::exception: " << err.what() << std::endl;
96  exit( -1 );
97  }
98  catch ( ... )
99  {
100  std::cout << "unknown error\n";
101  exit( -1 );
102  }
103  return 0;
104 }
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
VULKAN_HPP_NODISCARD Result enumeratePhysicalDeviceGroups(uint32_t *pPhysicalDeviceGroupCount, vk::PhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties, 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
void destroyDebugUtilsMessengerEXT(vk::DebugUtilsMessengerEXT messenger, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void getQueueFamilyProperties(uint32_t *pQueueFamilyPropertyCount, vk::QueueFamilyProperties *pQueueFamilyProperties, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result createDevice(const vk::DeviceCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::Device *pDevice, 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
#define VK_API_VERSION_1_1
Definition: vulkan_core.h:4854