vsg  1.1.0
VulkanSceneGraph library
PhysicalDevice.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/core/observer_ptr.h>
16 #include <vsg/vk/Surface.h>
17 
18 namespace vsg
19 {
22  class VSG_DECLSPEC PhysicalDevice : public Inherit<Object, PhysicalDevice>
23  {
24  public:
25  observer_ptr<Instance> getInstance() { return _instance; }
26 
27  operator VkPhysicalDevice() const { return _device; }
28  VkPhysicalDevice vk() const { return _device; }
29 
30  int getQueueFamily(VkQueueFlags queueFlags) const;
31  std::pair<int, int> getQueueFamily(VkQueueFlags queueFlags, Surface* surface) const;
32 
33  using QueueFamilyProperties = std::vector<VkQueueFamilyProperties>;
34  const QueueFamilyProperties& getQueueFamilyProperties() const { return _queueFamilies; }
35 
36  const VkPhysicalDeviceFeatures& getFeatures() const { return _features; }
37  const VkPhysicalDeviceProperties& getProperties() const { return _properties; }
38 
39  template<typename FeatureStruct, VkStructureType type>
40  FeatureStruct getFeatures() const
41  {
42  FeatureStruct features = {};
43  features.sType = type;
44 
45  if (_vkGetPhysicalDeviceFeatures2)
46  {
47  VkPhysicalDeviceFeatures2 features2 = {};
48  features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
49  features2.pNext = &features;
50 
51  _vkGetPhysicalDeviceFeatures2(_device, &features2);
52  }
53 
54  return features;
55  }
56 
57  template<typename PropertiesStruct, VkStructureType type>
58  PropertiesStruct getProperties() const
59  {
60  PropertiesStruct properties = {};
61  properties.sType = type;
62 
63  if (_vkGetPhysicalDeviceProperties2)
64  {
65  VkPhysicalDeviceProperties2 properties2 = {};
66  properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
67  properties2.pNext = &properties;
68 
69  _vkGetPhysicalDeviceProperties2(_device, &properties2);
70  }
71 
72  return properties;
73  }
74 
76  std::vector<VkExtensionProperties> enumerateDeviceExtensionProperties(const char* pLayerName = nullptr);
77 
79  bool supportsDeviceExtension(const char* extensionName);
80 
81  protected:
82  // use Instance::getDevice(..) to create PhysicalDevice
83  PhysicalDevice(Instance* instance, VkPhysicalDevice device);
84 
85  virtual ~PhysicalDevice();
86 
87  friend class Instance;
88 
89  VkPhysicalDevice _device;
90 
91  VkPhysicalDeviceFeatures _features;
92  VkPhysicalDeviceProperties _properties;
93  QueueFamilyProperties _queueFamilies;
94 
95  PFN_vkGetPhysicalDeviceFeatures2 _vkGetPhysicalDeviceFeatures2 = nullptr;
96  PFN_vkGetPhysicalDeviceProperties2 _vkGetPhysicalDeviceProperties2 = nullptr;
97 
99  };
100  VSG_type_name(vsg::PhysicalDevice);
101 
102 } // namespace vsg
Definition: Inherit.h:28
Instance encapsulates the VkInstance.
Definition: Instance.h:43
Definition: PhysicalDevice.h:23
std::vector< VkExtensionProperties > enumerateDeviceExtensionProperties(const char *pLayerName=nullptr)
Call vkEnumerateDeviceExtensionProperties to enumerate extension properties.
bool supportsDeviceExtension(const char *extensionName)
return true if the extension is supported by physicalDevice
Surface encapsulates VkSurfaceKHR.
Definition: Surface.h:22
Definition: observer_ptr.h:24