HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_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: RV_Instance.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * Main interface to Vulkan
10  */
11 #ifndef RV_Instance_h
12 #define RV_Instance_h
13 
14 #include "RV_API.h"
15 
16 #include "RV_Type.h"
17 
18 #include <VE/VE_VK.h>
19 
20 #include <UT/UT_Array.h>
21 #include <UT/UT_UniquePtr.h>
22 
24 
25 class rv_InstanceData;
26 
28 class RV_Render;
29 class RV_VKQueue;
30 class RV_VKCommandPool;
31 class RV_VKCommandBuffer;
32 class RV_VKCommandBufferAllocator;
33 class RV_VKExt;
34 class RV_VKMemAllocator;
35 class UT_WorkBuffer;
36 
37 /// Handle to the main interface of Vulkan
39 {
40 public:
41  /// The global vulkan instance, creating it if it hasn't been created yet.
42  static RV_Instance* getInstance();
43  /// Returns whether the global vulkan instance exists
44  static bool hasInstance();
45  /// Destroy the global instance. For system exit.
46  static void destroyInstance();
47  /// The exit callback that's called when the vulkan instance is about to be
48  /// destroyed.
49  static void exitCallback(void*);
50 
51  /// Create the global vulkan instance. Used only at startup.
52  static RV_Instance* create();
53 
54  ~RV_Instance();
55 
56  /// Set up Vulkan once the instance is created
57  bool initializeDevice();
58 
59  /// Get the raw vulkan device assocated with this instance.
60  VkDevice getDevice();
61  /// Get the raw vulkan physical device assocated with this instance.
62  VkPhysicalDevice getPhysicalDevice();
63  /// Get the raw vulkan instance.
64  VkInstance getVkInst();
65 
66  /// Raw Vulkan memory properties of the physical device
67  const VkPhysicalDeviceMemoryProperties* getMemoryProps() const;
68 
69  /// Main Queue supporting graphics, compute and transfer
70  RV_VKQueue& getGraphicsQueue() { return *myGraphicsQueue; }
71  /// Our Vulkan memory allocator implementation
72  RV_VKMemAllocator& getMemAllocator() { return *myAllocator; }
73  /// Our Vulkan descriptor set allocator
74  RV_DescriptorAllocator& getDescAllocator(){return *myDescriptorAllocator;}
75 
76  /// Get text information about the current driver and device
77  void fetchDriverInfo(UT_WorkBuffer &info);
78 
79  static uint32_t getInstanceVersion();
80 
81  /// The Vulkan version as implemented by the device driver
82  uint32_t getDeviceVersion();
83  /// The vendor of the device (AMD, Intel, NVidia, MoltenVK)
84  RV_GraphicsDevice getDeviceVendor() const;
85 
86  /// True if the debug validation layers are active
87  static bool usingDebugValidation();
88 
89  /// True if Vulkan multithreading env var is set to true
90  static bool usingVulkanMultithreading();
91 
92  /// Maximum supported number of color samples in a multisample framebuffer
93  int getMaxColorSamples() const;
94 
95  /// Maximum supported number of depth samples in a multisample framebuffer
96  int getMaxDepthSamples() const;
97 
98  /// Maximum size of 2D texture
99  int getMaxTextureSize2D() const;
100 
101  /// Maximum size of 3D texture
102  int getMaxTextureSize3D() const;
103 
104  /// Granularity of Line width setting
105  float getLineWidthGranularity() const;
106 
107  /// Object containing function pointers to Vulkan extensions
108  RV_VKExt* getExt() { return myExtensions.get(); }
109 
110  /// Query if the given Vulkan extension is enabled in the device
111  bool extEnabled( const char* vk_ext_name ) const;
112 
113  /// Block until the device has finished all commands (Call with care!)
114  void waitDeviceIdle();
115 
116  /// Returns the physical device features that have been enabled on our
117  /// device
118  const VE_PhysicalDeviceFeatures &getPhysicalDeviceFeatures() const;
119 
120 private:
121  RV_Instance();
122 
123 
126  UT_UniquePtr<RV_DescriptorAllocator> myDescriptorAllocator;
127  UT_UniquePtr<RV_VKQueue> myGraphicsQueue;
128 
129  UT_UniquePtr<RV_VKExt> myExtensions;
130 
131  VE_PhysicalDeviceFeatures myEnabledDeviceFeatures;
132  UT_Array<const char*> myEnabledDevExtensions;
133  UT_Array<const char*> myEnabledInstExtensions;
134 };
135 
136 #endif
RV_VKMemAllocator & getMemAllocator()
Our Vulkan memory allocator implementation.
Definition: RV_Instance.h:72
RV_VKQueue & getGraphicsQueue()
Main Queue supporting graphics, compute and transfer.
Definition: RV_Instance.h:70
RV_DescriptorAllocator & getDescAllocator()
Our Vulkan descriptor set allocator.
Definition: RV_Instance.h:74
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
RV_GraphicsDevice
Definition: RV_Type.h:70
#define RV_API
Definition: RV_API.h:10
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:38
RV_VKExt * getExt()
Object containing function pointers to Vulkan extensions.
Definition: RV_Instance.h:108