c0500491bc281b65bfedbc9a01378944c7c94d3d
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktCustomInstancesDevices.hpp
1 #ifndef _VKTCUSTOMINSTANCESDEVICES_HPP
2 #define _VKTCUSTOMINSTANCESDEVICES_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2019 The Khronos Group Inc.
8  * Copyright (c) 2019 Valve Corporation.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Auxiliar functions to help create custom devices and instances.
25  *//*--------------------------------------------------------------------*/
26
27 #include "vkDefs.hpp"
28 #include "vktTestCase.hpp"
29
30 #include <vector>
31 #include <memory>
32
33 namespace vk
34 {
35         class PlatformInterface;
36         class InstanceInterface;
37 }
38
39 namespace tcu
40 {
41         class CommandLine;
42 }
43
44 namespace vkt
45 {
46
47 std::vector<const char*> getValidationLayers (const vk::PlatformInterface& vkp);
48
49 std::vector<const char*> getValidationLayers (const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice);
50
51 class CustomInstance
52 {
53 public:
54                                                                 CustomInstance                  ();
55 #ifndef CTS_USES_VULKANSC
56                                                                 CustomInstance                  (Context& context, vk::Move<vk::VkInstance> instance, std::unique_ptr<vk::DebugReportRecorder>& recorder);
57 #else
58                                                                 CustomInstance                  (Context& context, vk::Move<vk::VkInstance> instance);
59 #endif // CTS_USES_VULKANSC
60                                                                 CustomInstance                  (CustomInstance&& other);
61                                                                 ~CustomInstance                 ();
62         CustomInstance&                         operator=                               (CustomInstance&& other);
63                                                                 operator vk::VkInstance () const;
64         void                                            swap                                    (CustomInstance& other);
65         const vk::InstanceDriver&       getDriver                               () const;
66         void                                            collectMessages                 ();
67
68                                                                 CustomInstance                  (const CustomInstance& other) = delete;
69         CustomInstance&                         operator=                               (const CustomInstance& other) = delete;
70 private:
71         Context*                                                                        m_context;
72 #ifndef CTS_USES_VULKANSC
73         std::unique_ptr<vk::DebugReportRecorder>        m_recorder;
74 #endif // CTS_USES_VULKANSC
75         vk::Move<vk::VkInstance>                                        m_instance;
76 #ifndef CTS_USES_VULKANSC
77         std::unique_ptr<vk::InstanceDriver>                     m_driver;
78         vk::Move<vk::VkDebugReportCallbackEXT>          m_callback;
79 #else
80         std::unique_ptr<vk::InstanceDriverSC>           m_driver;
81 #endif // CTS_USES_VULKANSC
82 };
83
84 class UncheckedInstance
85 {
86 public:
87                                                 UncheckedInstance               ();
88 #ifndef CTS_USES_VULKANSC
89                                                 UncheckedInstance               (Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator, std::unique_ptr<vk::DebugReportRecorder>& recorder);
90 #else
91                                                 UncheckedInstance               (Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator);
92 #endif // CTS_USES_VULKANSC
93                                                 UncheckedInstance               (UncheckedInstance&& other);
94                                                 ~UncheckedInstance              ();
95         UncheckedInstance&      operator=                               (UncheckedInstance&& other);
96                                                 operator vk::VkInstance () const;
97                                                 operator bool                   () const;
98         void                            swap                                    (UncheckedInstance& other);
99
100                                                 UncheckedInstance               (const UncheckedInstance& other) = delete;
101         UncheckedInstance&      operator=                               (const UncheckedInstance& other) = delete;
102 private:
103         Context*                                                                        m_context;
104 #ifndef CTS_USES_VULKANSC
105         std::unique_ptr<vk::DebugReportRecorder>        m_recorder;
106 #endif // CTS_USES_VULKANSC
107         const vk::VkAllocationCallbacks*                        m_allocator;
108         vk::VkInstance                                                          m_instance;
109 #ifndef CTS_USES_VULKANSC
110         std::unique_ptr<vk::InstanceDriver>                     m_driver;
111         vk::Move<vk::VkDebugReportCallbackEXT>          m_callback;
112 #else
113         std::unique_ptr<vk::InstanceDriverSC>           m_driver;
114 #endif // CTS_USES_VULKANSC
115 };
116
117 // Custom instances.
118
119 CustomInstance createCustomInstanceWithExtensions (Context& context, const std::vector<std::string>& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
120
121 CustomInstance createCustomInstanceWithExtension (Context& context, const std::string& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
122
123 CustomInstance createCustomInstanceFromContext (Context& context, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
124
125 CustomInstance createCustomInstanceFromInfo (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true);
126
127 // Unchecked instance: creation allowed to fail.
128
129 vk::VkResult createUncheckedInstance (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator, UncheckedInstance* instance, bool allowLayers = true);
130
131 // Custom devices.
132
133 vk::Move<vk::VkDevice> createCustomDevice (bool validationEnabled, const vk::PlatformInterface& vkp, vk::VkInstance instance, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL);
134
135 // Unchecked device: creation allowed to fail.
136
137 vk::VkResult createUncheckedDevice (bool validationEnabled, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator, vk::VkDevice* pDevice);
138
139 class CustomInstanceWrapper
140 {
141 public:
142         CustomInstanceWrapper(Context& context);
143         CustomInstanceWrapper(Context& context, const std::vector<std::string> extensions);
144         vkt::CustomInstance instance;
145 };
146
147 }
148
149 #endif // _VKTCUSTOMINSTANCESDEVICES_HPP