-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathDevice.h
More file actions
111 lines (78 loc) · 5.09 KB
/
Device.h
File metadata and controls
111 lines (78 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
/* <editor-fold desc="MIT License">
Copyright(c) 2018 Robert Osfield
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
</editor-fold> */
#include <vsg/vk/DeviceExtensions.h>
#include <vsg/vk/DeviceFeatures.h>
#include <vsg/vk/Queue.h>
#include <list>
namespace vsg
{
// forward declare
class WindowTraits;
class MemoryBufferPools;
class DescriptorPools;
class TransferTask;
struct QueueSetting
{
int queueFamilyIndex = -1;
std::vector<float> queuePriorities;
};
using QueueSettings = std::vector<QueueSetting>;
/// Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified during construction.
class VSG_DECLSPEC Device : public Inherit<Object, Device>
{
public:
Device(PhysicalDevice* physicalDevice, const QueueSettings& queueSettings, Names layers, Names deviceExtensions, const DeviceFeatures* deviceFeatures = nullptr, AllocationCallbacks* allocator = nullptr);
operator VkDevice() const { return _device; }
VkDevice vk() const { return _device; }
static uint32_t maxNumDevices();
const uint32_t deviceID = 0;
Instance* getInstance() { return _instance.get(); }
const Instance* getInstance() const { return _instance.get(); }
PhysicalDevice* getPhysicalDevice() { return _physicalDevice.get(); }
const PhysicalDevice* getPhysicalDevice() const { return _physicalDevice.get(); }
AllocationCallbacks* getAllocationCallbacks() { return _allocator.get(); }
const AllocationCallbacks* getAllocationCallbacks() const { return _allocator.get(); }
const Queues& getQueues() const { return _queues; }
ref_ptr<Queue> getQueue(uint32_t queueFamilyIndex, uint32_t queueIndex = 0);
/// get the extensions structure that holds a range of function pointers to vkInstance extensions
const DeviceExtensions* getExtensions() const { return _extensions.get(); }
/// get the address of specified function using vkGetDeviceProcAddr
/// for core commands beyond the apiVersion specified in vsg::Instance creation, vkGetDeviceProcAddr may return a non-nullptr function pointer, though the function pointer must not be called.
/// for extension commands, vkGetDeviceProcAddr will always return nullptr if the extension is not enabled in vsg::Device creation.
template<typename T>
bool getProcAddr(T& procAddress, const char* pName, const char* pNameFallback = nullptr) const
{
procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pName));
if (procAddress) return true;
if (pNameFallback) procAddress = reinterpret_cast<T>(vkGetDeviceProcAddr(_device, pNameFallback));
return (procAddress);
}
/// device-level core functionality can be used if both VkInstance and VkPhysicalDevice support the Vulkan version that provides it.
bool supportsApiVersion(uint32_t version) const;
/// list of enabled extensions when the Device was created
const Names enabledExtensions;
/// return true if Device was created with specified extension
bool supportsDeviceExtension(const char* extensionName) const;
/// return the amount of remaining memory, compatible with specified flags, available that can be allocated.
VkDeviceSize availableMemory(VkMemoryPropertyFlags memoryPropertiesFlags, double allocatedMemoryLimit = 1.0) const;
// provide observer_ptr to memory buffer, descriptor pools and transferTask so that these can be accessed when required
observer_ptr<MemoryBufferPools> deviceMemoryBufferPools;
observer_ptr<MemoryBufferPools> stagingMemoryBufferPools;
observer_ptr<DescriptorPools> descriptorPools;
observer_ptr<TransferTask> transferTask;
protected:
virtual ~Device();
VkDevice _device;
ref_ptr<Instance> _instance;
ref_ptr<PhysicalDevice> _physicalDevice;
ref_ptr<AllocationCallbacks> _allocator;
ref_ptr<DeviceExtensions> _extensions;
Queues _queues;
};
VSG_type_name(vsg::Device);
} // namespace vsg