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,
48 
49  count,
50 };
51 
52 /// A enum of common instance layers. These can be used in lieu of passing
53 /// the names themselves into functions, making it a bit hard
54 /// to make typos and a bit easier to remember what layers exist.
55 ///
56 /// To map from layer name to enum member, just remove the VK_LAYER
57 /// prefix from the the layer name and lower case the rest.
58 /// For example:
59 /// VK_LAYER_LUNARG_standard_validation -> lunarg_standard_validation
60 enum class VE_InstanceLayer {
63 
64  count,
65 };
66 
67 /// Low level wrapper around a VkInstance.
68 /// Users must be explicit call destroy() when done with this.
70 {
71  UT_ArrayStringSet myEnabledExtensions;
72  VE_VulkanAPIVersion myApiVersion;
73  VkInstance myHandle;
74 
76  VkInstance inst,
78  UT_ArrayStringSet ext_names)
79  : myHandle(inst)
80  , myApiVersion(version)
81  , myEnabledExtensions(ext_names)
82  {}
83 
84 public:
85  static VE_Result<VE_Instance> create(
86  VE_VulkanAPIVersion version,
87  uint32_t extension_count = 0,
88  const char *const extension_names[] = nullptr);
89  static VE_Result<VE_Instance> create(
90  VE_VulkanAPIVersion version,
91  uint32_t extension_count,
92  const VE_InstanceExtension extensions[]);
93 
94  VE_Instance() = default;
95  /// Destroys the underlying vulkan instance. Must not be called until all
96  /// VkDevice objects that this was used to create have been destroyed.
97  void destroy();
98 
99  VkInstance handle() const { return myHandle; }
100 
101  VE_VulkanAPIVersion apiVersion() const { return myApiVersion; }
102  /// The more opaque form of the api version that is used for Vulkan API calls.
103  uint32_t apiVersionNumber() const;
104 
105  bool extensionEnabled(VE_InstanceExtension ext) const;
106 
107  bool extensionEnabled(const char *ext) const { return myEnabledExtensions.contains(ext); }
108 
109  const UT_ArrayStringSet &enabledExtensions() const { return myEnabledExtensions; }
110 
111  /// Returns a list of physical devices (such as GPUs) avaiable to the
112  /// instance. The list can be scanned for a suitable physical device, which
113  /// can then be used to create logical device objects.
114  VE_Result<UT_Array<VE_PhysicalDevice>> physicalDevices() const;
115 
116 };
117 
118 /// NOTE: These are low-level calls and it is recommended to use a higher-level
119 /// interface to Vulkan if possible.
120 ///
121 /// Create a Vulkan instance object, which is the primary handle into the Vulkan
122 /// loader. The instance object is mainly used to query for and inspect
123 /// available system drivers and physical devices, and create VkDevice
124 /// objects from particular physical devices.
125 ///
126 /// It is the caller's responsibily to pass the returned VkInstance to
127 /// ve_destroyVulkanInstance once it is no longer needed.
128 VE_API
131  uint32_t extension_count,
132  const char *const extension_names[],
133  uint32_t layer_count,
134  const char *const layer_names[]);
135 VE_API
138  uint32_t extension_count,
139  VE_InstanceExtension extensions[],
140  uint32_t layer_count,
141  VE_InstanceLayer layers[]);
142 /// This version of the call will automatically enabled the validation layers in
143 /// debug mode.
144 VE_API
147  uint32_t extension_count,
148  const char *const extension_names[]);
149 
150 /// Query Support of the Instance Layer in the Vulkan Instance
151 VE_API
153 VE_API
154 bool VEsupportsInstanceLayer(const char* extension);
155 
156 /// Query Support of the Instance Extension in the Vulkan Instance
157 VE_API
159 VE_API
160 bool VEsupportsInstanceExtension(const char* extension);
161 
162 /// Clean up the instance resource. This likely will simply call
163 /// vkDestroyInstance.
164 VE_API
165 void VEdestroyVulkanInstance(VkInstance);
166 
167 
168 /// Return the Vulkan major, minor, and patch version bit-crammed into the
169 /// unsigned int.
170 VE_API
171 uint32_t VEgetInstanceVersion();
172 
173 #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:109
bool extensionEnabled(const char *ext) const
Definition: VE_Instance.h:107
VE_API uint32_t VEgetInstanceVersion()
VE_VulkanAPIVersion
Definition: VE_Instance.h:21
VE_VulkanAPIVersion apiVersion() const
Definition: VE_Instance.h:101
#define VE_API
Definition: VE_API.h:20
VE_InstanceLayer
Definition: VE_Instance.h:60
GT_API const UT_StringHolder version
VE_InstanceExtension
Definition: VE_Instance.h:37
VkInstance handle() const
Definition: VE_Instance.h:99
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.