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 Auxiliary 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 } // namespace vk 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, 57 std::unique_ptr<vk::DebugReportRecorder> &recorder); 58 #else 59 CustomInstance(Context &context, vk::Move<vk::VkInstance> instance); 60 #endif // CTS_USES_VULKANSC 61 CustomInstance(CustomInstance &&other); 62 ~CustomInstance(); 63 CustomInstance &operator=(CustomInstance &&other); 64 operator vk::VkInstance() const; 65 void swap(CustomInstance &other); 66 const vk::InstanceDriver &getDriver() const; 67 void collectMessages(); 68 69 CustomInstance(const CustomInstance &other) = delete; 70 CustomInstance &operator=(const CustomInstance &other) = delete; 71 72 private: 73 Context *m_context; 74 #ifndef CTS_USES_VULKANSC 75 std::unique_ptr<vk::DebugReportRecorder> m_recorder; 76 #endif // CTS_USES_VULKANSC 77 vk::Move<vk::VkInstance> m_instance; 78 #ifndef CTS_USES_VULKANSC 79 std::unique_ptr<vk::InstanceDriver> m_driver; 80 vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 81 #else 82 std::unique_ptr<vk::InstanceDriverSC> m_driver; 83 #endif // CTS_USES_VULKANSC 84 }; 85 86 class UncheckedInstance 87 { 88 public: 89 UncheckedInstance(); 90 #ifndef CTS_USES_VULKANSC 91 UncheckedInstance(Context &context, vk::VkInstance instance, const vk::VkAllocationCallbacks *pAllocator, 92 std::unique_ptr<vk::DebugReportRecorder> &recorder); 93 #else 94 UncheckedInstance(Context &context, vk::VkInstance instance, const vk::VkAllocationCallbacks *pAllocator); 95 #endif // CTS_USES_VULKANSC 96 UncheckedInstance(UncheckedInstance &&other); 97 ~UncheckedInstance(); 98 UncheckedInstance &operator=(UncheckedInstance &&other); 99 operator vk::VkInstance() const; 100 operator bool() const; 101 void swap(UncheckedInstance &other); 102 103 UncheckedInstance(const UncheckedInstance &other) = delete; 104 UncheckedInstance &operator=(const UncheckedInstance &other) = delete; 105 106 private: 107 Context *m_context; 108 #ifndef CTS_USES_VULKANSC 109 std::unique_ptr<vk::DebugReportRecorder> m_recorder; 110 #endif // CTS_USES_VULKANSC 111 const vk::VkAllocationCallbacks *m_allocator; 112 vk::VkInstance m_instance; 113 #ifndef CTS_USES_VULKANSC 114 std::unique_ptr<vk::InstanceDriver> m_driver; 115 vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 116 #else 117 std::unique_ptr<vk::InstanceDriverSC> m_driver; 118 #endif // CTS_USES_VULKANSC 119 }; 120 121 // Custom instances. 122 123 CustomInstance createCustomInstanceWithExtensions(Context &context, const std::vector<std::string> &extension, 124 const vk::VkAllocationCallbacks *pAllocator = DE_NULL, 125 bool allowLayers = true); 126 127 CustomInstance createCustomInstanceWithExtension(Context &context, const std::string &extension, 128 const vk::VkAllocationCallbacks *pAllocator = DE_NULL, 129 bool allowLayers = true); 130 131 CustomInstance createCustomInstanceFromContext(Context &context, const vk::VkAllocationCallbacks *pAllocator = DE_NULL, 132 bool allowLayers = true); 133 134 CustomInstance createCustomInstanceFromInfo(Context &context, const vk::VkInstanceCreateInfo *instanceCreateInfo, 135 const vk::VkAllocationCallbacks *pAllocator = DE_NULL, 136 bool allowLayers = true); 137 138 // Unchecked instance: creation allowed to fail. 139 140 vk::VkResult createUncheckedInstance(Context &context, const vk::VkInstanceCreateInfo *instanceCreateInfo, 141 const vk::VkAllocationCallbacks *pAllocator, UncheckedInstance *instance, 142 bool allowLayers = true); 143 144 // Custom devices. 145 146 vk::Move<vk::VkDevice> createCustomDevice(bool validationEnabled, const vk::PlatformInterface &vkp, 147 vk::VkInstance instance, const vk::InstanceInterface &vki, 148 vk::VkPhysicalDevice physicalDevice, 149 const vk::VkDeviceCreateInfo *pCreateInfo, 150 const vk::VkAllocationCallbacks *pAllocator = DE_NULL); 151 152 // Unchecked device: creation allowed to fail. 153 154 vk::VkResult createUncheckedDevice(bool validationEnabled, const vk::InstanceInterface &vki, 155 vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo *pCreateInfo, 156 const vk::VkAllocationCallbacks *pAllocator, vk::VkDevice *pDevice); 157 158 class CustomInstanceWrapper 159 { 160 public: 161 CustomInstanceWrapper(Context &context); 162 CustomInstanceWrapper(Context &context, const std::vector<std::string> extensions); 163 vkt::CustomInstance instance; 164 }; 165 166 class VideoDevice 167 { 168 public: 169 #ifndef CTS_USES_VULKANSC 170 typedef vk::VkVideoCodecOperationFlagsKHR VideoCodecOperationFlags; 171 #else 172 typedef uint32_t VideoCodecOperationFlags; 173 #endif // CTS_USES_VULKANSC 174 175 enum VideoDeviceFlagBits 176 { 177 VIDEO_DEVICE_FLAG_NONE = 0, 178 VIDEO_DEVICE_FLAG_QUERY_WITH_STATUS_FOR_DECODE_SUPPORT = 0x00000001, 179 VIDEO_DEVICE_FLAG_REQUIRE_YCBCR_OR_NOT_SUPPORTED = 0x00000002, 180 VIDEO_DEVICE_FLAG_REQUIRE_SYNC2_OR_NOT_SUPPORTED = 0x00000004, 181 VIDEO_DEVICE_FLAG_REQUIRE_TIMELINE_OR_NOT_SUPPORTED = 0x00000008, 182 VIDEO_DEVICE_FLAG_QUERY_WITH_STATUS_FOR_ENCODE_SUPPORT = 0x00000010, 183 VIDEO_DEVICE_FLAG_REQUIRE_MAINTENANCE_1 = 0x00000020, 184 }; 185 186 typedef uint32_t VideoDeviceFlags; 187 188 static void checkSupport(Context &context, const VideoCodecOperationFlags videoCodecOperation); 189 static vk::VkQueueFlags getQueueFlags(const VideoCodecOperationFlags videoCodecOperationFlags); 190 191 static void addVideoDeviceExtensions(std::vector<const char *> &deviceExtensions, const uint32_t apiVersion, 192 const vk::VkQueueFlags queueFlagsRequired, 193 const VideoCodecOperationFlags videoCodecOperationFlags); 194 static bool isVideoEncodeOperation(const VideoCodecOperationFlags videoCodecOperationFlags); 195 static bool isVideoDecodeOperation(const VideoCodecOperationFlags videoCodecOperationFlags); 196 static bool isVideoOperation(const VideoCodecOperationFlags videoCodecOperationFlags); 197 198 VideoDevice(Context &context); 199 VideoDevice(Context &context, const VideoCodecOperationFlags videoCodecOperation, 200 const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 201 virtual ~VideoDevice(void); 202 203 vk::VkDevice getDeviceSupportingQueue(const vk::VkQueueFlags queueFlagsRequired = 0, 204 const VideoCodecOperationFlags videoCodecOperationFlags = 0, 205 const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 206 bool createDeviceSupportingQueue(const vk::VkQueueFlags queueFlagsRequired, 207 const VideoCodecOperationFlags videoCodecOperationFlags, 208 const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 209 const vk::DeviceDriver &getDeviceDriver(void); 210 uint32_t getQueueFamilyIndexTransfer(void) const; 211 uint32_t getQueueFamilyIndexDecode(void) const; 212 uint32_t getQueueFamilyIndexEncode(void) const; 213 uint32_t getQueueFamilyVideo(void) const; 214 vk::Allocator &getAllocator(void); 215 216 protected: 217 Context &m_context; 218 219 vk::Move<vk::VkDevice> m_logicalDevice; 220 de::MovePtr<vk::DeviceDriver> m_deviceDriver; 221 de::MovePtr<vk::Allocator> m_allocator; 222 uint32_t m_queueFamilyTransfer; 223 uint32_t m_queueFamilyDecode; 224 uint32_t m_queueFamilyEncode; 225 VideoCodecOperationFlags m_videoCodecOperation; 226 }; 227 228 } // namespace vkt 229 230 #endif // _VKTCUSTOMINSTANCESDEVICES_HPP 231