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 CustomInstance (Context& context, vk::Move<vk::VkInstance> instance, std::unique_ptr<vk::DebugReportRecorder>& recorder); 56 CustomInstance (CustomInstance&& other); 57 ~CustomInstance (); 58 CustomInstance& operator= (CustomInstance&& other); 59 operator vk::VkInstance () const; 60 void swap (CustomInstance& other); 61 const vk::InstanceDriver& getDriver () const; 62 void collectMessages (); 63 64 CustomInstance (const CustomInstance& other) = delete; 65 CustomInstance& operator= (const CustomInstance& other) = delete; 66 private: 67 Context* m_context; 68 std::unique_ptr<vk::DebugReportRecorder> m_recorder; 69 vk::Move<vk::VkInstance> m_instance; 70 std::unique_ptr<vk::InstanceDriver> m_driver; 71 vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 72 }; 73 74 class UncheckedInstance 75 { 76 public: 77 UncheckedInstance (); 78 UncheckedInstance (Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator, std::unique_ptr<vk::DebugReportRecorder>& recorder); 79 UncheckedInstance (UncheckedInstance&& other); 80 ~UncheckedInstance (); 81 UncheckedInstance& operator= (UncheckedInstance&& other); 82 operator vk::VkInstance () const; 83 operator bool () const; 84 void swap (UncheckedInstance& other); 85 86 UncheckedInstance (const UncheckedInstance& other) = delete; 87 UncheckedInstance& operator= (const UncheckedInstance& other) = delete; 88 private: 89 Context* m_context; 90 std::unique_ptr<vk::DebugReportRecorder> m_recorder; 91 const vk::VkAllocationCallbacks* m_allocator; 92 vk::VkInstance m_instance; 93 std::unique_ptr<vk::InstanceDriver> m_driver; 94 vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 95 }; 96 97 // Custom instances. 98 99 CustomInstance createCustomInstanceWithExtensions (Context& context, const std::vector<std::string>& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 100 101 CustomInstance createCustomInstanceWithExtension (Context& context, const std::string& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 102 103 CustomInstance createCustomInstanceFromContext (Context& context, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 104 105 CustomInstance createCustomInstanceFromInfo (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 106 107 // Unchecked instance: creation allowed to fail. 108 109 vk::VkResult createUncheckedInstance (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator, UncheckedInstance* instance, bool allowLayers = true); 110 111 // Custom devices. 112 113 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); 114 115 // Unchecked device: creation allowed to fail. 116 117 vk::VkResult createUncheckedDevice (bool validationEnabled, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator, vk::VkDevice* pDevice); 118 119 } 120 121 #endif // _VKTCUSTOMINSTANCESDEVICES_HPP 122