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