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 
49  count, // used to mark the size of this enum
50 };
51 
52 /// This class maintains the actual Vulkan API structures used to inspect and
53 /// enable various possible device features.
55 {
56 public:
58 
60  VE_PhysicalDeviceFeatureChain(VkPhysicalDevice dev,
61  const UT_ArrayStringSet &deviceextensions);
62 
63  /// Returns a linked list of Vulkan structures, chained through pNext
64  /// members, that can be passed into various API calls.
65  /// This pointer must not outlive the VE_PhysicalDeviceFeatureChain instance
66  /// it was returned from.
67  const VkPhysicalDeviceFeatures2 *pFeatures() const { return &my0; }
68 
69  bool containsAll(
70  const VE_PhysicalDeviceFeatures &features,
71  UT_WorkBuffer *feature_list = nullptr) const;
72 
74  { return my1.multiviewTessellationShader; }
75 
76 private:
77  void linkMembers();
78 
86 };
87 
88 /// A wrapper around a VkPhysicalDevice object that also contains useful
89 /// information about that physical device.
90 /// Due to caching information from the driver, this object is rather hefty.
91 /// Consider allocating it on the heap.
93 {
94 public:
95  static VE_Result<VE_PhysicalDevice> create(VkPhysicalDevice);
96 
97  static VE_Result<UT_Array<VE_PhysicalDevice>> findAll(VkInstance instance);
98 
99  VkPhysicalDevice getVkPhysicalDevice() const { return myHandle; }
100 
102  {
103  return myProperties.properties;
104  }
105 
107  {
108  return myIdProperties;
109  }
110 
111  const VE_PhysicalDeviceFeatureChain &features() const { return myFeatures; }
112 
113  bool extensionAvailable(const char *name) const;
114  bool extensionAvailable(VE_DeviceExtension ext) const;
115 
117  {
118  return myQueueFamilyProperties;
119  }
120 
122  {
123  return myMemoryProperties;
124  }
125 
126  // Print out device information. Mainly for debugging.
127  void printInfo() const;
128 
129  /// Methods for retrieving a memory type index.
130  ///
131  /// Vulkan resources can be created before any memory is actually allocated for
132  /// them. This memory-less resource handle acts as a kind of meta-data object. One
133  /// of the reasons for this is so the memory requirements for the resource can be
134  /// queried before the resource is actually allocated, allowing us to merge the
135  /// resources requirements with the applications needs and preferences.
136  ///
137  /// The resource's requirements are expressed as memory type bits. The
138  /// applications requirements or preferences are expressed as
139  /// VkMemoryPropertyFlags. You can pass both of these to these new methods to
140  /// retrieve the actually memory type index, which is all you need to actually
141  /// allocate the memory.
142  ///
143  /// Usage:
144  ///
145  /// VkMemoryRequirements reqs;
146  ///
147  /// vkGetBufferMemoryRequirements(device, buffer, &reqs);
148  ///
149  /// uint32_t memory_type_index;
150  ///
151  /// auto r = physical_device.findMemoryTypeIndex(reqs.memoryTypeBits,
152  /// preferred_flags | required_flags);
153  /// if (!r)
154  /// r = physical_device.findMemoryTypeIndex(reqs.memoryTypeBits,
155  /// required_flags);
156  ///
157  /// memory_type_index = *r;
158  ///
159  UT_Optional<uint32_t> findMemoryTypeIndex(uint32_t memory_type_bits, VkMemoryPropertyFlags required_properties) const;
160 
161  /// Returns the memory type index satisfying the given flags, or none. This
162  /// is equivalent to the above call with memory_type_bits == 0xFFFFFFFF
163  UT_Optional<uint32_t> findMemoryTypeIndex(VkMemoryPropertyFlags flags) const;
164 
165  // TODO extensions do not get enabled on the physical device but the logical
166  // one. these methods should there for be on the logical device object
168  {
169  return myAvailableExtensions;
170  }
171 
173  findQueueFamilyIndex(VkQueueFlags flags) const;
174 
175  VkFormatProperties formatProperties(const VkFormat format) const;
176 
177  VE_Result<VkImageFormatProperties2> imageFormatProperties(const VkImageCreateInfo &info) const;
178 
179  VE_PhysicalDevice() = default;
180 
181 private:
182  VkPhysicalDevice myHandle;
183  VkPhysicalDeviceProperties2 myProperties;
184  VkPhysicalDeviceIDProperties myIdProperties;
185  VkPhysicalDeviceMemoryProperties myMemoryProperties;
187  UT_Array<VkQueueFamilyProperties> myQueueFamilyProperties;
188 
189  UT_ArrayStringSet myAvailableExtensions;
190 
191  VE_PhysicalDevice(VkPhysicalDevice);
192 };
193 
195 VEextensionNamesToStrings(uint32_t count, const VE_DeviceExtension extensions[]);
196 
197 uint32_t VE_API VEgetPhysicalDeviceVersion(VkPhysicalDevice phy_dev);
198 
199 #endif
GLbitfield flags
Definition: glcorearb.h:1596
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
VE_DeviceExtension
#define VE_API
Definition: VE_API.h:20
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
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)