API Documentation
Loading...
Searching...
No Matches
VulkanInstance.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Graphics
28File: VulkanInstance
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "VulkanDefines.h"
34#include "VulkanDefines.h"
35#include "Base/Headers/RWLock.h"
36#include "Base/Headers/String.h"
39#include "Base/Headers/Time.h"
40#include "Base/Headers/UUID.h"
42#include <vulkan/vulkan.h>
43
44#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
45#if !defined(DEFINE_NON_DISPATCHABLE_HANDLE)
46 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
47 #define DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
48 #else
49 #define DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
50 #endif
51#endif
52
53
54VK_DEFINE_HANDLE(VkInstance)
55VK_DEFINE_HANDLE(VkPhysicalDevice)
56VK_DEFINE_HANDLE(VkDevice)
57VK_DEFINE_HANDLE(VkQueue)
58VK_DEFINE_HANDLE(VkCommandBuffer)
59
60DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT);
61
65struct VkApplicationInfo;
66namespace NDEVR
67{
68 struct SwapChainSupportDetails;
69 class File;
70 class Log;
71 class WindowInstance;
72 struct Module;
73 extern VkResult vkExecute(VkResult result, const char* error_message);
74
76 {
77 public:
79 VulkanInstance(VulkanInstance&& instance) noexcept;
80 static void setupModule(Module& module);
81 static Module VulkanBackupModule();
82 void setDeviceLost();
83 virtual ~VulkanInstance();
84 bool isValid() const;
85 virtual void init();
86 void setLog(ProgressInfo* log);
87 ProgressInfo* log() { return m_log; }
88
89 void cleanup();
90 const String& surfaceType() const;
91
92 VkInstance vkInstance() const { lib_assert(m_vk_instance, "Instance not yet created, but access is attempted"); return m_vk_instance; }
93
94 static DynamicPointer<VulkanInstance>& DefaultVulkanInstance();
95 bool supportsKHRSwapchain() const;
96 bool supportsTriangleFan() const;
97 bool supportsValidation() const { return m_supports_validation; };
98 const Buffer<String>& validationLayers() const { return m_validation_layers; };
99 const Buffer<VkPhysicalDevice>& physicalDevices() const { return m_available_physical_devices; };
100 virtual uint04 deviceSuitableScore(VkPhysicalDevice device);//0 = not suitable
101 bool isSoftwareRendered() const;
102 protected:
103 virtual VkResult createVkInstance(const VkInstanceCreateInfo& create_info);
104 virtual VkInstanceCreateInfo createInfo();
105 virtual VkApplicationInfo applicationInfo(const String& app_name);
106 virtual uint04 setupExtensions(const char**& extensions);
107 virtual uint04 setupLayers(const char**& layers);
108 void initializeAll();
109 public:
110 static String HardwareRenderedVulkanLib();
111 static String SoftwareRenderedVulkanLib();
113 protected:
114 bool checkLayerSupport(const String& layer);
115 bool checkExtensionSupport(const String& layer);
116 bool checkValidationSupport();
117 virtual void setAvailablePhysicalDevices();
118 virtual void setupInstance();
119 virtual void setAvailableExtensionInfo();
120 virtual void setAvailableLayerInfo();
121 virtual void setupDebug();
122
123
124 virtual VkSurfaceFormatKHR chooseSwapSurfaceFormat(const Buffer<VkSurfaceFormatKHR, uint04, ObjectAllocator<true>>& availableFormats);
126 public:
128 protected:
129 VkInstance m_vk_instance;
131 VkDebugReportCallbackEXT m_debug_callback;
132
136
140 bool m_is_init = false;
141 bool m_is_software_rendered = false;
145 };
146
147
148}
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
#define VK_DEFINE_HANDLE(object)
Definition VulkanInstance.h:44
#define DEFINE_NON_DISPATCHABLE_HANDLE(object)
Definition VulkanInstance.h:49
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Pointer.hpp:303
Definition MemoryManager.h:283
Definition ProgressInfo.hpp:43
Definition String.h:40
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition VulkanInstance.h:76
const Buffer< String > & validationLayers() const
Definition VulkanInstance.h:98
VkInstance vkInstance() const
Definition VulkanInstance.h:92
Buffer< VkLayerProperties, uint04, ObjectAllocator< true > > m_available_layer_info
Definition VulkanInstance.h:134
String vulkanLibUsed() const
Buffer< String > m_validation_layers
Definition VulkanInstance.h:138
ProgressInfo * log()
Definition VulkanInstance.h:87
const Buffer< VkPhysicalDevice > & physicalDevices() const
Definition VulkanInstance.h:99
Buffer< VkPhysicalDevice > m_available_physical_devices
Definition VulkanInstance.h:135
ProgressInfo * m_log
Definition VulkanInstance.h:130
bool supportsValidation() const
Definition VulkanInstance.h:97
String m_surface_type
Definition VulkanInstance.h:143
bool m_supports_validation
Definition VulkanInstance.h:139
Buffer< String > m_extensions
Definition VulkanInstance.h:137
bool m_supports_tri_fan
Definition VulkanInstance.h:142
Buffer< VkExtensionProperties, uint04, ObjectAllocator< true > > m_available_extension_info
Definition VulkanInstance.h:133
VkDebugReportCallbackEXT m_debug_callback
Definition VulkanInstance.h:131
Time m_creation_time
Definition VulkanInstance.h:144
static Buffer< VulkanInstance * > s_instances
Definition VulkanInstance.h:127
Time creationTime() const
Definition VulkanInstance.h:125
VkInstance m_vk_instance
Definition VulkanInstance.h:129
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
m_creation_time(Time::SystemTime())
Definition VulkanInstance.cpp:132
Definition ModuleManager.h:54