1 // 2 // Copyright 2020 Pixar 3 // 4 // Licensed under the Apache License, Version 2.0 (the "Apache License") 5 // with the following modification; you may not use this file except in 6 // compliance with the Apache License and the following modification to it: 7 // Section 6. Trademarks. is deleted and replaced with: 8 // 9 // 6. Trademarks. This License does not grant permission to use the trade 10 // names, trademarks, service marks, or product names of the Licensor 11 // and its affiliates, except as required to comply with Section 4(c) of 12 // the License and to reproduce the content of the NOTICE file. 13 // 14 // You may obtain a copy of the Apache License at 15 // 16 // http://www.apache.org/licenses/LICENSE-2.0 17 // 18 // Unless required by applicable law or agreed to in writing, software 19 // distributed under the Apache License with the above modification is 20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 // KIND, either express or implied. See the Apache License for the specific 22 // language governing permissions and limitations under the Apache License. 23 // 24 #ifndef PXR_IMAGING_HGIVULKAN_DEVICE_H 25 #define PXR_IMAGING_HGIVULKAN_DEVICE_H 26 27 #include "pxr/pxr.h" 28 29 #include "pxr/imaging/hgiVulkan/api.h" 30 #include "pxr/imaging/hgiVulkan/vulkan.h" 31 32 #include <vector> 33 34 PXR_NAMESPACE_OPEN_SCOPE 35 36 class HgiVulkanCapabilities; 37 class HgiVulkanCommandQueue; 38 class HgiVulkanInstance; 39 class HgiVulkanPipelineCache; 40 41 42 /// \class HgiVulkanDevice 43 /// 44 /// Vulkan implementation of GPU device. 45 /// 46 class HgiVulkanDevice final 47 { 48 public: 49 HGIVULKAN_API 50 HgiVulkanDevice(HgiVulkanInstance* instance); 51 52 HGIVULKAN_API 53 ~HgiVulkanDevice(); 54 55 /// Returns the vulkan device 56 HGIVULKAN_API 57 VkDevice GetVulkanDevice() const; 58 59 /// Returns the vulkan memory allocator. 60 HGIVULKAN_API 61 VmaAllocator GetVulkanMemoryAllocator() const; 62 63 /// Returns the command queue which manages command buffers submission. 64 HGIVULKAN_API 65 HgiVulkanCommandQueue* GetCommandQueue() const; 66 67 /// Returns the device capablities / features it supports. 68 HGIVULKAN_API 69 HgiVulkanCapabilities const& GetDeviceCapabilities() const; 70 71 /// Returns the type (or family index) for the graphics queue. 72 HGIVULKAN_API 73 uint32_t GetGfxQueueFamilyIndex() const; 74 75 /// Returns vulkan physical device 76 HGIVULKAN_API 77 VkPhysicalDevice GetVulkanPhysicalDevice() const; 78 79 /// Returns the pipeline cache. 80 HGIVULKAN_API 81 HgiVulkanPipelineCache* GetPipelineCache() const; 82 83 /// Wait for all queued up commands to have been processed on device. 84 /// This should ideally never be used as it creates very big stalls, but 85 /// is useful for unit testing. 86 HGIVULKAN_API 87 void WaitForIdle(); 88 89 /// Device extension function pointers 90 PFN_vkCreateRenderPass2KHR vkCreateRenderPass2KHR = 0; 91 PFN_vkCmdBeginDebugUtilsLabelEXT vkCmdBeginDebugUtilsLabelEXT = 0; 92 PFN_vkCmdEndDebugUtilsLabelEXT vkCmdEndDebugUtilsLabelEXT = 0; 93 PFN_vkCmdInsertDebugUtilsLabelEXT vkCmdInsertDebugUtilsLabelEXT = 0; 94 PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT = 0; 95 PFN_vkQueueBeginDebugUtilsLabelEXT vkQueueBeginDebugUtilsLabelEXT = 0; 96 PFN_vkQueueEndDebugUtilsLabelEXT vkQueueEndDebugUtilsLabelEXT = 0; 97 98 private: 99 HgiVulkanDevice() = delete; 100 HgiVulkanDevice & operator=(const HgiVulkanDevice&) = delete; 101 HgiVulkanDevice(const HgiVulkanDevice&) = delete; 102 103 // Returns true if the provided extension is supported by the device 104 bool _IsSupportedExtension(const char* extensionName) const; 105 106 // Vulkan device objects 107 VkPhysicalDevice _vkPhysicalDevice; 108 VkDevice _vkDevice; 109 std::vector<VkExtensionProperties> _vkExtensions; 110 VmaAllocator _vmaAllocator; 111 uint32_t _vkGfxsQueueFamilyIndex; 112 HgiVulkanCommandQueue* _commandQueue; 113 HgiVulkanCapabilities* _capabilities; 114 HgiVulkanPipelineCache* _pipelineCache; 115 }; 116 117 118 PXR_NAMESPACE_CLOSE_SCOPE 119 120 #endif 121