HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VE_PhysicalDevice.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_PhysicalDevice.h ( VE Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __VE_PHYSICAL_DEVICE_H__
13 #define __VE_PHYSICAL_DEVICE_H__
14 
15 #include "VE_VK.h"
16 
17 #include "VE_API.h"
18 #include "VE_Result.h"
20 
21 #include <UT/UT_Array.h>
22 #include <UT/UT_ArrayStringSet.h>
23 #include <UT/UT_Optional.h>
24 
25 constexpr uint32_t VE_SWIFT_SHADER_DEVICE_ID = 0xC0DE;
26 
27 /// A enum of common device extensions. These can be used in lieu of passing
28 /// the names themselves into functions, making it a bit hard
29 /// to make typos and a bit easier to remember what extensions exist.
30 ///
31 /// To map from extension name to enum member, just remove the capitalized
32 /// prefix from the the extension name.
33 /// For example
34 /// VK_KHR_external_fence_capabilities -> external_fence_capabilities
35 enum class VE_DeviceExtension {
46  ray_query,
48 #ifdef VULKAN_PRESENTATION
49  swapchain,
50 #endif
52 
53  count, // used to mark the size of this enum
54 };
55 
56 /// This class maintains the actual Vulkan API structures used to inspect and
57 /// enable various possible device features.
59 {
60 public:
62 
64  VE_PhysicalDeviceFeatureChain(VkPhysicalDevice dev,
65  const UT_ArrayStringSet &deviceextensions);
66 
67  /// Returns a linked list of Vulkan structures, chained through pNext
68  /// members, that can be passed into various API calls.
69  /// This pointer must not outlive the VE_PhysicalDeviceFeatureChain instance
70  /// it was returned from.
71  const VkPhysicalDeviceFeatures2 *pFeatures() const { return &my0; }
72 
73  bool containsAll(
74  const VE_PhysicalDeviceFeatures &features,
75  UT_WorkBuffer *feature_list = nullptr) const;
76 
78  { return my2.bufferDeviceAddress; }
79 
81  { return my1.multiviewTessellationShader; }
82 
84  { return my6.accelerationStructure; }
85 
86  bool hasRayQuery() const
87  { return my4.rayQuery; }
88 
89 private:
90  void linkMembers();
91 
99 };
100 
101 /// A wrapper around a VkPhysicalDevice object that also contains useful
102 /// information about that physical device.
103 /// Due to caching information from the driver, this object is rather hefty.
104 /// Consider allocating it on the heap.
106 {
107 public:
108  static VE_Result<VE_PhysicalDevice> create(VkPhysicalDevice);
109 
110  static VE_Result<UT_Array<VE_PhysicalDevice>> findAll(VkInstance instance);
111 
112  VkPhysicalDevice getVkPhysicalDevice() const { return myHandle; }
113 
115  {
116  return myProperties.properties;
117  }
118 
120  {
121  return myIdProperties;
122  }
123 
125  {
126  UT_ASSERT(VK_API_VERSION_MINOR(properties().apiVersion) >= 2);
127  return myProperties11;
128  }
129 
131  {
132  UT_ASSERT(VK_API_VERSION_MINOR(properties().apiVersion) >= 2);
133  return myProperties12;
134  }
135 
137  {
138  return myAccelStructProperties;
139  }
140 
141  const VE_PhysicalDeviceFeatureChain &features() const { return myFeatures; }
142 
143  bool extensionAvailable(const char *name) const;
144  bool extensionAvailable(VE_DeviceExtension ext) const;
145 
147  {
148  return myQueueFamilyProperties;
149  }
150 
152  {
153  return myMemoryProperties;
154  }
155 
156  // Print out device information. Mainly for debugging.
157  void printInfo() const;
158 
159  /// Methods for retrieving a memory type index.
160  ///
161  /// Vulkan resources can be created before any memory is actually allocated for
162  /// them. This memory-less resource handle acts as a kind of meta-data object. One
163  /// of the reasons for this is so the memory requirements for the resource can be
164  /// queried before the resource is actually allocated, allowing us to merge the
165  /// resources requirements with the applications needs and preferences.
166  ///
167  /// The resource's requirements are expressed as memory type bits. The
168  /// applications requirements or preferences are expressed as
169  /// VkMemoryPropertyFlags. You can pass both of these to these new methods to
170  /// retrieve the actually memory type index, which is all you need to actually
171  /// allocate the memory.
172  ///
173  /// Usage:
174  ///
175  /// VkMemoryRequirements reqs;
176  ///
177  /// vkGetBufferMemoryRequirements(device, buffer, &reqs);
178  ///
179  /// uint32_t memory_type_index;
180  ///
181  /// auto r = physical_device.findMemoryTypeIndex(reqs.memoryTypeBits,
182  /// preferred_flags | required_flags);
183  /// if (!r)
184  /// r = physical_device.findMemoryTypeIndex(reqs.memoryTypeBits,
185  /// required_flags);
186  ///
187  /// memory_type_index = *r;
188  ///
189  UT_Optional<uint32_t> findMemoryTypeIndex(uint32_t memory_type_bits, VkMemoryPropertyFlags required_properties) const;
190 
191  /// Returns the memory type index satisfying the given flags, or none. This
192  /// is equivalent to the above call with memory_type_bits == 0xFFFFFFFF
193  UT_Optional<uint32_t> findMemoryTypeIndex(VkMemoryPropertyFlags flags) const;
194 
195  // TODO extensions do not get enabled on the physical device but the logical
196  // one. these methods should there for be on the logical device object
198  {
199  return myAvailableExtensions;
200  }
201 
203  findQueueFamilyIndex(VkQueueFlags flags) const;
204 
205  VkFormatProperties formatProperties(const VkFormat format) const;
206 
207  VE_Result<VkImageFormatProperties2> imageFormatProperties(const VkImageCreateInfo &info) const;
208 
209  VE_PhysicalDevice() = default;
210 
211 private:
212  VkPhysicalDevice myHandle;
213  VkPhysicalDeviceProperties2 myProperties;
214  VkPhysicalDeviceIDProperties myIdProperties;
215  VkPhysicalDeviceVulkan11Properties myProperties11;
216  VkPhysicalDeviceVulkan12Properties myProperties12;
218  VkPhysicalDeviceMemoryProperties myMemoryProperties;
220  UT_Array<VkQueueFamilyProperties> myQueueFamilyProperties;
221 
222  UT_ArrayStringSet myAvailableExtensions;
223 
224  VE_PhysicalDevice(VkPhysicalDevice);
225 };
226 
228 VEextensionNamesToStrings(uint32_t count, const VE_DeviceExtension extensions[]);
229 
230 uint32_t VE_API VEgetPhysicalDeviceVersion(VkPhysicalDevice phy_dev);
231 
232 #endif
GLbitfield flags
Definition: glcorearb.h:1596
const VkPhysicalDeviceVulkan12Properties & vulkan12Properties() const
bool hasMultiviewTessellationShader() const
const VkPhysicalDeviceMemoryProperties & memoryProperties() const
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
constexpr uint32_t VE_SWIFT_SHADER_DEVICE_ID
#define VK_API_VERSION_MINOR(version)
Definition: vulkan_core.h:91
VE_DeviceExtension
const VkPhysicalDeviceAccelerationStructurePropertiesKHR & accelStructProperties() const
#define VE_API
Definition: VE_API.h:20
const VkPhysicalDeviceVulkan11Properties & vulkan11Properties() const
const VkPhysicalDeviceIDProperties & idProperties() const
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
GLuint const GLchar * name
Definition: glcorearb.h:786
const UT_ArrayStringSet & availableExtensions() const
VkPhysicalDevice getVkPhysicalDevice() const
const VE_PhysicalDeviceFeatureChain & features() const
const UT_Array< VkQueueFamilyProperties > & queueFamiltyProperties() const
const VkPhysicalDeviceFeatures2 * pFeatures() const
UT_Array< const char * > VE_API VEextensionNamesToStrings(uint32_t count, const VE_DeviceExtension extensions[])
VkFormat
Definition: vulkan_core.h:1386
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
VkFlags VkQueueFlags
Definition: vulkan_core.h:2356
VkFlags VkMemoryPropertyFlags
Definition: vulkan_core.h:2339
const VkPhysicalDeviceProperties & properties() const
GLint GLsizei count
Definition: glcorearb.h:405
uint32_t VE_API VEgetPhysicalDeviceVersion(VkPhysicalDevice phy_dev)