NDEVR
API Documentation
VulkanInstance.h
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 <NDEVR/RWLock.h>
35#include <NDEVR/String.h>
36#include <NDEVR/DynamicPointer.h>
37#include <NDEVR/Buffer.h>
38#include <NDEVR/Time.h>
39#include <NDEVR/UUID.h>
40#include <NDEVR/ApplicationOptions.h>
41#include <vulkan/vulkan.h>
42
43#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
44#if !defined(DEFINE_NON_DISPATCHABLE_HANDLE)
45 #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
46 #define DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
47 #else
48 #define DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
49 #endif
50#endif
51
52
53VK_DEFINE_HANDLE(VkInstance)
54VK_DEFINE_HANDLE(VkPhysicalDevice)
55VK_DEFINE_HANDLE(VkDevice)
56VK_DEFINE_HANDLE(VkQueue)
57VK_DEFINE_HANDLE(VkCommandBuffer)
58
59DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT);
60
61DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR);
62DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool);
63DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView);
64struct VkApplicationInfo;
65namespace NDEVR
66{
67 struct SwapChainSupportDetails;
68 class File;
69 class Log;
70 class WindowInstance;
71 struct Module;
76 extern VkResult vkExecute(VkResult result, const char* error_message);
77
84 class VulkanInstance
85 {
86 public:
87 VulkanInstance();
88 VulkanInstance(VulkanInstance&& instance) noexcept;
89 static void setupModule(Module& module);
90 static Module VulkanBackupModule();
91 void setDeviceLost();
92 virtual ~VulkanInstance();
93 bool isValid() const;
94 virtual void init();
95 void setLog(LogPtr log);
96 LogPtr log() { return m_log; }
97
98 void cleanup();
99 const String& surfaceType() const;
100
101 VkInstance vkInstance() const { lib_assert(m_vk_instance, "Instance not yet created, but access is attempted"); return m_vk_instance; }
102
103 static DynamicPointer<VulkanInstance>& DefaultVulkanInstance();
104 bool supportsKHRSwapchain() const;
105 bool supportsTriangleFan() const;
106 bool supportsValidation() const { return m_supports_validation; };
107 const Buffer<String>& validationLayers() const { return m_validation_layers; };
109 virtual uint04 deviceSuitableScore(VkPhysicalDevice device);//0 = not suitable
110 bool isSoftwareRendered() const;
111 protected:
112 virtual VkResult createVkInstance(const VkInstanceCreateInfo& create_info);
113 virtual VkInstanceCreateInfo createInfo();
114 virtual VkApplicationInfo applicationInfo(const String& app_name);
115 virtual uint04 setupExtensions(const char**& extensions);
116 virtual uint04 setupLayers(const char**& layers);
117 void initializeAll();
118 public:
119 static String HardwareRenderedVulkanLib();
120 static String SoftwareRenderedVulkanLib();
121 String vulkanLibUsed() const;
122 protected:
123 bool checkLayerSupport(const String& layer);
124 bool checkExtensionSupport(const String& layer);
125 bool checkValidationSupport();
126 virtual void setAvailablePhysicalDevices();
127 virtual void setupInstance();
128 virtual void setAvailableExtensionInfo();
129 virtual void setAvailableLayerInfo();
130 virtual void setupDebug();
131
132
133 virtual VkSurfaceFormatKHR chooseSwapSurfaceFormat(const Buffer<VkSurfaceFormatKHR>& availableFormats);
134 Time creationTime() const { return m_creation_time; }
135 public:
137 protected:
138 VkInstance m_vk_instance;
140 VkDebugReportCallbackEXT m_debug_callback;
141
145
149 bool m_is_init = false;
154 };
155
156
157}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Definition Log.h:50
The core String class for the NDEVR API.
Definition String.h:95
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Buffer< String > m_extensions
Enabled instance extensions.
bool m_supports_validation
Whether validation layers are available.
bool m_is_init
Whether the instance has been initialized.
Buffer< VkPhysicalDevice, BufferAllocator< VkPhysicalDevice, 64, true > > m_available_physical_devices
Physical devices found at init.
Buffer< VkExtensionProperties, BufferAllocator< VkExtensionProperties, 64, true > > m_available_extension_info
Available Vulkan extensions.
bool m_supports_tri_fan
Whether the driver supports triangle fan topology.
VkInstance m_vk_instance
The native Vulkan instance handle.
VkDebugReportCallbackEXT m_debug_callback
Debug report callback handle.
Time m_creation_time
The time this instance was created.
static Buffer< VulkanInstance * > s_instances
Global list of all active Vulkan instances.
bool m_is_software_rendered
Whether using software-rendered Vulkan.
Buffer< VkLayerProperties, BufferAllocator< VkLayerProperties, 64, true > > m_available_layer_info
Available Vulkan layers.
Buffer< String > m_validation_layers
Enabled validation layers.
String m_surface_type
The type of surface this instance uses.
LogPtr m_log
Log for instance messages.
Contains core information about a Viewport.
The primary namespace for the NDEVR SDK.
VkResult vkExecute(VkResult result, const char *error_message)
Executes a Vulkan command and handles the results, throwing an exception if necessary.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Base class for extensions, typically added as external DLL's that can modify or enhance the behavior ...