vOOlkan
An object oriented approach to Vulkan
PhysicalDevice.h
Go to the documentation of this file.
1#ifndef VULKAN_PHYSICALDEVICE
2#define VULKAN_PHYSICALDEVICE
3
4#include <vulkan/vulkan.h>
5#include <vector>
6#include <map>
7#include <set>
8#include <functional>
9
10
11namespace Vulkan { class PhysicalDevice; class Instance; class WindowSurface; enum class QueueFamily; }
12
13
18 public:
19 PhysicalDevice(const Instance& vulkanInstance, const WindowSurface& surface);
20
21
26 const VkPhysicalDevice& operator+() const;
27
28
33 std::map<QueueFamily, int> getQueueFamiliesIndices() const;
34
40 std::vector<const char*> getRequiredDeviceExtensions() const;
41
42
43 VkPhysicalDeviceProperties getProperties() const {
44 VkPhysicalDeviceProperties limits;
45 vkGetPhysicalDeviceProperties(gpu, &limits);
46 return limits;
47 }
48
49
50 private:
51 //constructor only used to pass around PhysicalDevices to functions which require a PhysicalDevice instead of a VkPhysicalDevice
52 PhysicalDevice(const VkPhysicalDevice& underlyingGpu);
53
54
55 void pickBestDevice(const Instance& vulkanInstance, const WindowSurface& surface);
56
57 //given a gpu tell me if it supports all the required features
58 static bool isGpuSuitable(const PhysicalDevice& gpu, const WindowSurface& surface, const std::vector<const char*> requiredDeviceExtensions);
59
60
61 //Returns the index of the graphics and presentation families if supported by the GPU, else it will throw.
62 static std::map<QueueFamily, int> queueFamiliesSupport(const PhysicalDevice& gpu, const WindowSurface& surface);
63
64
65 //Checks whether all of the required extensions are supported. If not it will throw.
66 static void extensionsSupport(const PhysicalDevice& gpu, const std::vector<const char*>& requiredDeviceExtensions);
67
68
69 //given a tuple of vectors containing ints, choose one int from each vector, trying to choose as many elements in common among the vectors as possible
70 static std::map<QueueFamily, int> chooseFewestPossible(std::map<QueueFamily, std::vector<int>> families);
71
72
73 VkPhysicalDevice gpu = VK_NULL_HANDLE;
74 std::map<QueueFamily, int> queueFamiliesIndices; //the indices of the graphics and presentation families (they can be the same)
75 const std::vector<const char*> requiredDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; //list of required extensions for the device
76};
77
78#endif
Definition: Instance.h:15
Represents the GPU (or any other device) that will be used with Vulkan to perform computer graphics.
Definition: PhysicalDevice.h:17
const VkPhysicalDevice & operator+() const
Returns the underlying VkPhyisicalDevice object.
Definition: PhysicalDevice.cpp:18
std::vector< const char * > getRequiredDeviceExtensions() const
Definition: PhysicalDevice.cpp:30
std::map< QueueFamily, int > getQueueFamiliesIndices() const
Returns the indices of the graphics and presentation queue families (they can be the same family).
Definition: PhysicalDevice.cpp:24
PhysicalDevice(const Instance &vulkanInstance, const WindowSurface &surface)
Definition: PhysicalDevice.cpp:11
VkPhysicalDeviceProperties getProperties() const
Definition: PhysicalDevice.h:43
A window surface is the connection between Vulkan and the OS windows environment.
Definition: WindowSurface.h:13
Types of queue families.
Definition: Animations.h:17
QueueFamily
Definition: QueueFamily.h:8