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

vsg 1.1.10 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 class MemoryBufferPools;
27 class DescriptorPools;
28
29 struct QueueSetting
30 {
31 int queueFamilyIndex = -1;
32 std::vector<float> queuePiorities;
33 };
34
35 using QueueSettings = std::vector<QueueSetting>;
36
38 class VSG_DECLSPEC Device : public Inherit<Object, Device>
39 {
40 public:
41 Device(PhysicalDevice* physicalDevice, const QueueSettings& queueSettings, Names layers, Names deviceExtensions, const DeviceFeatures* deviceFeatures = nullptr, AllocationCallbacks* allocator = nullptr);
42
43 operator VkDevice() const { return _device; }
44 VkDevice vk() const { return _device; }
45
46 static uint32_t maxNumDevices();
47 const uint32_t deviceID = 0;
48
49 Instance* getInstance() { return _instance.get(); }
50 const Instance* getInstance() const { return _instance.get(); }
51
52 PhysicalDevice* getPhysicalDevice() { return _physicalDevice.get(); }
53 const PhysicalDevice* getPhysicalDevice() const { return _physicalDevice.get(); }
54
55 AllocationCallbacks* getAllocationCallbacks() { return _allocator.get(); }
56 const AllocationCallbacks* getAllocationCallbacks() const { return _allocator.get(); }
57
58 const Queues& getQueues() const { return _queues; }
59
60 ref_ptr<Queue> getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex = 0);
61
63 const DeviceExtensions* getExtensions() const { return _extensions.get(); }
64
68 template<typename T>
69 bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
70 {
71 procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pName));
72 if (procAddress) return true;
73
74 if (pNameFallback) procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pNameFallback));
75 return (procAddress);
76 }
77
79 bool supportsApiVersion(uint32_t version) const;
80
82 const Names enabledExtensions;
83
85 bool supportsDeviceExtension(const char* extensionName) const;
86
87 // provide observer_ptr to memory buffer and descriptor pools so that these can be accessed when required
88 observer_ptr<MemoryBufferPools> deviceMemoryBufferPools;
89 observer_ptr<MemoryBufferPools> stagingMemoryBufferPools;
90 observer_ptr<DescriptorPools> descriptorPools;
91
92 protected:
93 virtual ~Device();
94
95 VkDevice _device;
96
97 ref_ptr<Instance> _instance;
98 ref_ptr<PhysicalDevice> _physicalDevice;
99 ref_ptr<AllocationCallbacks> _allocator;
100 ref_ptr<DeviceExtensions> _extensions;
101
102 Queues _queues;
103 };
104 VSG_type_name(vsg::Device);
105
106} // namespace vsg
vsg::AllocationCallbacks
Adapter class that provides a means of managing the lifetime of VkAllocationCallbacks.
Definition AllocationCallbacks.h:24
vsg::DescriptorPools
Container for DescriptorPools.
Definition DescriptorPools.h:24
vsg::DeviceExtensions
Definition DeviceExtensions.h:24
vsg::DeviceFeatures
Definition DeviceFeatures.h:25
vsg::Device
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:39
vsg::Device::getProcAddr
bool getProcAddr(T &procAddress, const char *pName, const char *pNameFallback=nullptr) const
Definition Device.h:69
vsg::Device::supportsDeviceExtension
bool supportsDeviceExtension(const char *extensionName) const
return true if Device was created with specified extension
vsg::Device::getExtensions
const DeviceExtensions * getExtensions() const
get the extensions structure that holds a range of function pointers to vkInstance extensions
Definition Device.h:63
vsg::Device::supportsApiVersion
bool supportsApiVersion(uint32_t version) const
device-level core functionality can be used if both VkInstance and VkPhysicalDevice support the Vulka...
vsg::Device::enabledExtensions
const Names enabledExtensions
list of enabled extensions when the Device was created
Definition Device.h:82
vsg::Instance
Instance encapsulates the VkInstance.
Definition Instance.h:46
vsg::MemoryBufferPools
Definition MemoryBufferPools.h:28
vsg::PhysicalDevice
Definition PhysicalDevice.h:23
vsg::WindowTraits
WindowTraits specifies the settings required when creating windows/vulkan instance/device.
Definition WindowTraits.h:27
vsg::observer_ptr
Definition observer_ptr.h:24
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::QueueSetting
Definition Device.h:30