vsg: include/vsg/vk/Instance.h Source File

vsg 1.1.9 VulkanSceneGraph library |

Loading...
Searching...
No Matches
Instance.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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/ref_ptr.h>
16#include <vsg/vk/AllocationCallbacks.h>
17#include <vsg/vk/InstanceExtensions.h>
18
19#include <vector>
20
21namespace vsg
22{
23 // forward declare
24 class PhysicalDevice;
25 class Surface;
26
27 using Names = std::vector<const char*>;
28 using ExtensionProperties = std::vector<VkExtensionProperties>;
29 using PhysicalDeviceTypes = std::vector<VkPhysicalDeviceType>;
30 using InstanceLayerProperties = std::vector<VkLayerProperties>;
31
33 extern VSG_DECLSPEC ExtensionProperties enumerateInstanceExtensionProperties(const char* pLayerName = nullptr);
34
36 extern VSG_DECLSPEC bool isExtensionSupported(const char* extensionName, const char* pLayerName = nullptr);
37
39 extern VSG_DECLSPEC InstanceLayerProperties enumerateInstanceLayerProperties();
40
42 extern VSG_DECLSPEC Names validateInstancelayerNames(const Names& names);
43
45 class VSG_DECLSPEC Instance : public Inherit<Object, Instance>
46 {
47 public:
48 Instance(Names instanceExtensions, Names layers, uint32_t vulkanApiVersion = VK_API_VERSION_1_0, AllocationCallbacks* allocator = nullptr);
49
51 const uint32_t apiVersion = VK_API_VERSION_1_0;
52
53 operator VkInstance() const { return _instance; }
54 VkInstance vk() const { return _instance; }
55
56 AllocationCallbacks* getAllocationCallbacks() { return _allocator.get(); }
57 const AllocationCallbacks* getAllocationCallbacks() const { return _allocator.get(); }
58
59 using PhysicalDevices = std::vector<ref_ptr<PhysicalDevice>>;
60 PhysicalDevices& getPhysicalDevices() { return _physicalDevices; }
61 const PhysicalDevices& getPhysicalDevices() const { return _physicalDevices; }
62
64 ref_ptr<PhysicalDevice> getPhysicalDevice(VkQueueFlags queueFlags, const PhysicalDeviceTypes& deviceTypePreferences = {}) const;
65
67 ref_ptr<PhysicalDevice> getPhysicalDevice(VkQueueFlags queueFlags, Surface* surface, const PhysicalDeviceTypes& deviceTypePreferences = {}) const;
68
70 std::pair<ref_ptr<PhysicalDevice>, int> getPhysicalDeviceAndQueueFamily(VkQueueFlags queueFlags, const PhysicalDeviceTypes& deviceTypePreferences = {}) const;
71
73 std::tuple<ref_ptr<PhysicalDevice>, int, int> getPhysicalDeviceAndQueueFamily(VkQueueFlags queueFlags, Surface* surface, const PhysicalDeviceTypes& deviceTypePreferences = {}) const;
74
76 const InstanceExtensions* getExtensions() const { return _extensions.get(); }
77
79 template<typename T>
80 bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
81 {
82 procAddress = reinterpret_cast<T>(vkGetInstanceProcAddr(_instance, pName));
83 if (procAddress) return true;
84
85 if (pNameFallback) procAddress = reinterpret_cast<T>(vkGetInstanceProcAddr(_instance, pNameFallback));
86 return (procAddress);
87 }
88
89 protected:
90 virtual ~Instance();
91
92 VkInstance _instance;
93 ref_ptr<AllocationCallbacks> _allocator;
94
95 PhysicalDevices _physicalDevices;
96
97 ref_ptr<InstanceExtensions> _extensions;
98
99 VkDebugUtilsMessengerEXT _debugUtilsMessenger = VK_NULL_HANDLE;
100 };
101 VSG_type_name(vsg::Instance);
102
103} // namespace vsg
vsg::AllocationCallbacks
Adapter class that provides a means of managing the lifetime of VkAllocationCallbacks.
Definition AllocationCallbacks.h:24
vsg::InstanceExtensions
Definition InstanceExtensions.h:24
vsg::Instance
Instance encapsulates the VkInstance.
Definition Instance.h:46
vsg::Instance::getProcAddr
bool getProcAddr(T &procAddress, const char *pName, const char *pNameFallback=nullptr) const
get the address of specified function using vkGetInstanceProcAddr.
Definition Instance.h:80
vsg::Instance::getPhysicalDevice
ref_ptr< PhysicalDevice > getPhysicalDevice(VkQueueFlags queueFlags, const PhysicalDeviceTypes &deviceTypePreferences={}) const
get a PhysicalDevice that supports the specified queueFlags, and presentation of specified surface if...
vsg::Instance::getPhysicalDevice
ref_ptr< PhysicalDevice > getPhysicalDevice(VkQueueFlags queueFlags, Surface *surface, const PhysicalDeviceTypes &deviceTypePreferences={}) const
get a PhysicalDevice that supports the specified queueFlags, and presentation of specified surface if...
vsg::Instance::getExtensions
const InstanceExtensions * getExtensions() const
get the extensions structure that holds a range of function pointers to vkInstance extensions
Definition Instance.h:76
vsg::Instance::getPhysicalDeviceAndQueueFamily
std::pair< ref_ptr< PhysicalDevice >, int > getPhysicalDeviceAndQueueFamily(VkQueueFlags queueFlags, const PhysicalDeviceTypes &deviceTypePreferences={}) const
get a PhysicalDevice and queue family index that supports the specified queueFlags,...
vsg::Instance::apiVersion
const uint32_t apiVersion
Vulkan apiVersion used when creating the VkInstance.
Definition Instance.h:51
vsg::Instance::getPhysicalDeviceAndQueueFamily
std::tuple< ref_ptr< PhysicalDevice >, int, int > getPhysicalDeviceAndQueueFamily(VkQueueFlags queueFlags, Surface *surface, const PhysicalDeviceTypes &deviceTypePreferences={}) const
get a PhysicalDevice and queue family index that supports the specified queueFlags,...
vsg::PhysicalDevice
Definition PhysicalDevice.h:23
vsg::Surface
Surface encapsulates VkSurfaceKHR.
Definition Surface.h:22
vsg::ref_ptr
Definition ref_ptr.h:22