HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VE_Instance.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VE_Instance.h ( VE Library, C++)
7  *
8  */
9 
10 #ifndef __VE_INSTANCE_H__
11 #define __VE_INSTANCE_H__
12 
13 #include "VE_API.h"
14 #include "VE_PhysicalDevice.h"
15 #include "VE_Result.h"
16 #include "VE_PhysicalDevice.h"
17 
18 #include <UT/UT_Array.h>
19 #include <UT/UT_ArrayStringSet.h>
20 
22 {
27 };
28 
29 /// A enum of common instance extensions. These can be used in lieu of passing
30 /// the names themselves into functions, making it a bit hard
31 /// to make typos and a bit easier to remember what extensions exist.
32 ///
33 /// To map from extension name to enum member, just remove the capitalized
34 /// prefix from the the extension name.
35 /// For example
36 /// VK_KHR_external_fence_capabilities -> external_fence_capabilities
41  surface,
47 
48  count,
49 };
50 
51 /// A enum of common instance layers. These can be used in lieu of passing
52 /// the names themselves into functions, making it a bit hard
53 /// to make typos and a bit easier to remember what layers exist.
54 ///
55 /// To map from layer name to enum member, just remove the VK_LAYER
56 /// prefix from the the layer name and lower case the rest.
57 /// For example:
58 /// VK_LAYER_LUNARG_standard_validation -> lunarg_standard_validation
59 enum class VE_InstanceLayer {
62 
63  count,
64 };
65 
66 /// Low level wrapper around a VkInstance.
67 /// Users must be explicit call destroy() when done with this.
69 {
70  UT_ArrayStringSet myEnabledExtensions;
71  VE_VulkanAPIVersion myApiVersion;
72  VkInstance myHandle;
73 
75  VkInstance inst,
77  UT_ArrayStringSet ext_names)
78  : myHandle(inst)
79  , myApiVersion(version)
80  , myEnabledExtensions(ext_names)
81  {}
82 
83 public:
84  static VE_Result<VE_Instance> create(
85  VE_VulkanAPIVersion version,
86  uint32_t extension_count = 0,
87  const char *const extension_names[] = nullptr);
88  static VE_Result<VE_Instance> create(
89  VE_VulkanAPIVersion version,
90  uint32_t extension_count,
91  const VE_InstanceExtension extensions[]);
92 
93  VE_Instance() = default;
94  /// Destroys the underlying vulkan instance. Must not be called until all
95  /// VkDevice objects that this was used to create have been destroyed.
96  void destroy();
97 
98  VkInstance handle() const { return myHandle; }
99 
100  VE_VulkanAPIVersion apiVersion() const { return myApiVersion; }
101  /// The more opaque form of the api version that is used for Vulkan API calls.
102  uint32_t apiVersionNumber() const;
103 
104  bool extensionEnabled(VE_InstanceExtension ext) const;
105 
106  bool extensionEnabled(const char *ext) const { return myEnabledExtensions.contains(ext); }
107 
108  const UT_ArrayStringSet &enabledExtensions() const { return myEnabledExtensions; }
109 
110  /// Returns a list of physical devices (such as GPUs) avaiable to the
111  /// instance. The list can be scanned for a suitable physical device, which
112  /// can then be used to create logical device objects.
113  VE_Result<UT_Array<VE_PhysicalDevice>> physicalDevices() const;
114 
115 };
116 
117 /// NOTE: These are low-level calls and it is recommended to use a higher-level
118 /// interface to Vulkan if possible.
119 ///
120 /// Create a Vulkan instance object, which is the primary handle into the Vulkan
121 /// loader. The instance object is mainly used to query for and inspect
122 /// available system drivers and physical devices, and create VkDevice
123 /// objects from particular physical devices.
124 ///
125 /// It is the caller's responsibily to pass the returned VkInstance to
126 /// ve_destroyVulkanInstance once it is no longer needed.
127 VE_API
130  uint32_t extension_count,
131  const char *const extension_names[],
132  uint32_t layer_count,
133  const char *const layer_names[]);
134 VE_API
137  uint32_t extension_count,
138  VE_InstanceExtension extensions[],
139  uint32_t layer_count,
140  VE_InstanceLayer layers[]);
141 /// This version of the call will automatically enabled the validation layers in
142 /// debug mode.
143 VE_API
146  uint32_t extension_count,
147  const char *const extension_names[]);
148 
149 /// Query Support of the Instance Layer in the Vulkan Instance
150 VE_API
152 VE_API
153 bool VEsupportsInstanceLayer(const char* extension);
154 
155 /// Query Support of the Instance Extension in the Vulkan Instance
156 VE_API
158 VE_API
159 bool VEsupportsInstanceExtension(const char* extension);
160 
161 /// Clean up the instance resource. This likely will simply call
162 /// vkDestroyInstance.
163 VE_API
164 void VEdestroyVulkanInstance(VkInstance);
165 
166 
167 /// Return the Vulkan major, minor, and patch version bit-crammed into the
168 /// unsigned int.
169 VE_API
170 uint32_t VEgetInstanceVersion();
171 
172 #endif
VE_API void VEdestroyVulkanInstance(VkInstance)
VE_API bool VEsupportsInstanceExtension(VE_InstanceExtension extension)
Query Support of the Instance Extension in the Vulkan Instance.
VE_API VE_Result< VkInstance > VEcreateVulkanInstance(VE_VulkanAPIVersion version, uint32_t extension_count, const char *const extension_names[], uint32_t layer_count, const char *const layer_names[])
const UT_ArrayStringSet & enabledExtensions() const
Definition: VE_Instance.h:108
bool extensionEnabled(const char *ext) const
Definition: VE_Instance.h:106
VE_API uint32_t VEgetInstanceVersion()
VE_VulkanAPIVersion
Definition: VE_Instance.h:21
VE_VulkanAPIVersion apiVersion() const
Definition: VE_Instance.h:100
#define VE_API
Definition: VE_API.h:20
VE_InstanceLayer
Definition: VE_Instance.h:59
GT_API const UT_StringHolder version
VE_InstanceExtension
Definition: VE_Instance.h:37
VkInstance handle() const
Definition: VE_Instance.h:98
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
VE_API bool VEsupportsInstanceLayer(VE_InstanceLayer extension)
Query Support of the Instance Layer in the Vulkan Instance.