vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
Device.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/vk/DeviceExtensions.h>
16#include <vsg/vk/DeviceFeatures.h>
17#include <vsg/vk/Queue.h>
18
19#include <list>
20
21namespace vsg
22{
23
24 // forward declare
25 class WindowTraits;
26
28 {
29 int queueFamilyIndex = -1;
30 std::vector<float> queuePiorities;
31 };
32
33 using QueueSettings = std::vector<QueueSetting>;
34
36 class VSG_DECLSPEC Device : public Inherit<Object, Device>
37 {
38 public:
39 Device(PhysicalDevice* physicalDevice, const QueueSettings& queueSettings, Names layers, Names deviceExtensions, const DeviceFeatures* deviceFeatures = nullptr, AllocationCallbacks* allocator = nullptr);
40
41 operator VkDevice() const { return _device; }
42 VkDevice vk() const { return _device; }
43
44 static uint32_t maxNumDevices();
45 const uint32_t deviceID = 0;
46
47 Instance* getInstance() { return _instance.get(); }
48 const Instance* getInstance() const { return _instance.get(); }
49
50 PhysicalDevice* getPhysicalDevice() { return _physicalDevice.get(); }
51 const PhysicalDevice* getPhysicalDevice() const { return _physicalDevice.get(); }
52
53 AllocationCallbacks* getAllocationCallbacks() { return _allocator.get(); }
54 const AllocationCallbacks* getAllocationCallbacks() const { return _allocator.get(); }
55
56 const Queues& getQueues() const { return _queues; }
57
58 ref_ptr<Queue> getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex = 0);
59
61 const DeviceExtensions* getExtensions() const { return _extensions.get(); }
62
66 template<typename T>
67 bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
68 {
69 procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pName));
70 if (procAddress) return true;
71
72 if (pNameFallback) procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pNameFallback));
73 return (procAddress);
74 }
75
77 bool supportsApiVersion(uint32_t version) const;
78
80 const Names enabledExtensions;
81
83 bool supportsDeviceExtension(const char* extensionName) const;
84
85 protected:
86 virtual ~Device();
87
88 VkDevice _device;
89
90 ref_ptr<Instance> _instance;
91 ref_ptr<PhysicalDevice> _physicalDevice;
93 ref_ptr<DeviceExtensions> _extensions;
94
95 Queues _queues;
96 };
97 VSG_type_name(vsg::Device);
98
99} // namespace vsg
Adapter class that provides a means of managing the lifetime of VkAllocationCallbacks.
Definition AllocationCallbacks.h:24
Definition DeviceExtensions.h:24
Definition DeviceFeatures.h:24
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:37
bool getProcAddr(T &procAddress, const char *pName, const char *pNameFallback=nullptr) const
Definition Device.h:67
bool supportsDeviceExtension(const char *extensionName) const
return true if Device was created with specified extension
const DeviceExtensions * getExtensions() const
get the extensions structure that holds a range of function pointers to vkInstance extensions
Definition Device.h:61
bool supportsApiVersion(uint32_t version) const
device-level core functionality can be used if both VkInstance and VkPhysicalDevice support the Vulka...
const Names enabledExtensions
list of enabled extensions when the Device was created
Definition Device.h:80
Definition Inherit.h:28
Instance encapsulates the VkInstance.
Definition Instance.h:46
Definition PhysicalDevice.h:23
Definition ref_ptr.h:22
Definition Device.h:28