Diligent Engine  v.2.4.g
VulkanInstance.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 #include <vector>
31 #include <memory>
32 #include "VulkanHeaders.h"
33 
34 namespace VulkanUtilities
35 {
36 
37 class VulkanInstance : public std::enable_shared_from_this<VulkanInstance>
38 {
39 public:
40  // clang-format off
41  VulkanInstance (const VulkanInstance&) = delete;
42  VulkanInstance ( VulkanInstance&&) = delete;
43  VulkanInstance& operator = (const VulkanInstance&) = delete;
45  // clang-format on
46 
47  static std::shared_ptr<VulkanInstance> Create(uint32_t ApiVersion,
48  bool EnableValidation,
49  uint32_t GlobalExtensionCount,
50  const char* const* ppGlobalExtensionNames,
51  VkAllocationCallbacks* pVkAllocator);
53 
54  std::shared_ptr<VulkanInstance> GetSharedPtr()
55  {
56  return shared_from_this();
57  }
58 
59  std::shared_ptr<const VulkanInstance> GetSharedPtr() const
60  {
61  return shared_from_this();
62  }
63 
64  // clang-format off
65  bool IsLayerAvailable (const char* LayerName, uint32_t& Version) const;
66  bool IsExtensionAvailable(const char* ExtensionName)const;
67  bool IsExtensionEnabled (const char* ExtensionName)const;
68 
69  VkPhysicalDevice SelectPhysicalDevice(uint32_t AdapterId)const;
70 
71  VkAllocationCallbacks* GetVkAllocator() const {return m_pVkAllocator;}
72  VkInstance GetVkInstance() const {return m_VkInstance; }
73  uint32_t GetVersion() const {return m_VkVersion; } // Warning: instance version may be greater than physical device version
74  // clang-format on
75 
76 private:
77  VulkanInstance(uint32_t ApiVersion,
78  bool EnableValidation,
79  uint32_t GlobalExtensionCount,
80  const char* const* ppGlobalExtensionNames,
81  VkAllocationCallbacks* pVkAllocator);
82 
83  bool m_DebugUtilsEnabled = false;
84  VkAllocationCallbacks* const m_pVkAllocator;
85  VkInstance m_VkInstance = VK_NULL_HANDLE;
86  uint32_t m_VkVersion = VK_API_VERSION_1_0;
87 
88  std::vector<VkLayerProperties> m_Layers;
89  std::vector<VkExtensionProperties> m_Extensions;
90  std::vector<const char*> m_EnabledExtensions;
91  std::vector<VkPhysicalDevice> m_PhysicalDevices;
92 };
93 
94 } // namespace VulkanUtilities
VulkanHeaders.h
VulkanUtilities::VulkanInstance::SelectPhysicalDevice
VkPhysicalDevice SelectPhysicalDevice(uint32_t AdapterId) const
Definition: VulkanInstance.cpp:315
VulkanUtilities::VulkanInstance::GetSharedPtr
std::shared_ptr< VulkanInstance > GetSharedPtr()
Definition: VulkanInstance.hpp:54
VulkanUtilities::VulkanInstance::IsLayerAvailable
bool IsLayerAvailable(const char *LayerName, uint32_t &Version) const
Definition: VulkanInstance.cpp:51
VulkanUtilities::VulkanInstance::GetVkInstance
VkInstance GetVkInstance() const
Definition: VulkanInstance.hpp:72
VulkanUtilities::VulkanInstance::operator=
VulkanInstance & operator=(const VulkanInstance &)=delete
VulkanUtilities::VulkanInstance::GetVersion
uint32_t GetVersion() const
Definition: VulkanInstance.hpp:73
VulkanUtilities::VulkanInstance::IsExtensionEnabled
bool IsExtensionEnabled(const char *ExtensionName) const
Definition: VulkanInstance.cpp:73
VulkanUtilities::VulkanInstance::IsExtensionAvailable
bool IsExtensionAvailable(const char *ExtensionName) const
Definition: VulkanInstance.cpp:64
VulkanUtilities::VulkanInstance::GetVkAllocator
VkAllocationCallbacks * GetVkAllocator() const
Definition: VulkanInstance.hpp:71
VulkanUtilities::VulkanInstance::VulkanInstance
VulkanInstance(const VulkanInstance &)=delete
VulkanUtilities::VulkanInstance::~VulkanInstance
~VulkanInstance()
Definition: VulkanInstance.cpp:302
VulkanUtilities
Definition: VulkanCommandBuffer.hpp:33
VulkanUtilities::VulkanInstance::Create
static std::shared_ptr< VulkanInstance > Create(uint32_t ApiVersion, bool EnableValidation, uint32_t GlobalExtensionCount, const char *const *ppGlobalExtensionNames, VkAllocationCallbacks *pVkAllocator)
Definition: VulkanInstance.cpp:82
VulkanUtilities::VulkanInstance
Definition: VulkanInstance.hpp:37
VulkanUtilities::VulkanInstance::GetSharedPtr
std::shared_ptr< const VulkanInstance > GetSharedPtr() const
Definition: VulkanInstance.hpp:59