1e5c31af7Sopenharmony_ci#ifndef _VKTCUSTOMINSTANCESDEVICES_HPP 2e5c31af7Sopenharmony_ci#define _VKTCUSTOMINSTANCESDEVICES_HPP 3e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci * Vulkan Conformance Tests 5e5c31af7Sopenharmony_ci * ------------------------ 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Copyright (c) 2019 The Khronos Group Inc. 8e5c31af7Sopenharmony_ci * Copyright (c) 2019 Valve Corporation. 9e5c31af7Sopenharmony_ci * 10e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 11e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 12e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 13e5c31af7Sopenharmony_ci * 14e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 15e5c31af7Sopenharmony_ci * 16e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 17e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 18e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 20e5c31af7Sopenharmony_ci * limitations under the License. 21e5c31af7Sopenharmony_ci * 22e5c31af7Sopenharmony_ci *//*! 23e5c31af7Sopenharmony_ci * \file 24e5c31af7Sopenharmony_ci * \brief Auxiliar functions to help create custom devices and instances. 25e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 26e5c31af7Sopenharmony_ci 27e5c31af7Sopenharmony_ci#include "vkDefs.hpp" 28e5c31af7Sopenharmony_ci#include "vktTestCase.hpp" 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ci#include <vector> 31e5c31af7Sopenharmony_ci#include <memory> 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_cinamespace vk 34e5c31af7Sopenharmony_ci{ 35e5c31af7Sopenharmony_ci class PlatformInterface; 36e5c31af7Sopenharmony_ci class InstanceInterface; 37e5c31af7Sopenharmony_ci} 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_cinamespace tcu 40e5c31af7Sopenharmony_ci{ 41e5c31af7Sopenharmony_ci class CommandLine; 42e5c31af7Sopenharmony_ci} 43e5c31af7Sopenharmony_ci 44e5c31af7Sopenharmony_cinamespace vkt 45e5c31af7Sopenharmony_ci{ 46e5c31af7Sopenharmony_ci 47e5c31af7Sopenharmony_cistd::vector<const char*> getValidationLayers (const vk::PlatformInterface& vkp); 48e5c31af7Sopenharmony_ci 49e5c31af7Sopenharmony_cistd::vector<const char*> getValidationLayers (const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice); 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_ciclass CustomInstance 52e5c31af7Sopenharmony_ci{ 53e5c31af7Sopenharmony_cipublic: 54e5c31af7Sopenharmony_ci CustomInstance (); 55e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 56e5c31af7Sopenharmony_ci CustomInstance (Context& context, vk::Move<vk::VkInstance> instance, std::unique_ptr<vk::DebugReportRecorder>& recorder); 57e5c31af7Sopenharmony_ci#else 58e5c31af7Sopenharmony_ci CustomInstance (Context& context, vk::Move<vk::VkInstance> instance); 59e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 60e5c31af7Sopenharmony_ci CustomInstance (CustomInstance&& other); 61e5c31af7Sopenharmony_ci ~CustomInstance (); 62e5c31af7Sopenharmony_ci CustomInstance& operator= (CustomInstance&& other); 63e5c31af7Sopenharmony_ci operator vk::VkInstance () const; 64e5c31af7Sopenharmony_ci void swap (CustomInstance& other); 65e5c31af7Sopenharmony_ci const vk::InstanceDriver& getDriver () const; 66e5c31af7Sopenharmony_ci void collectMessages (); 67e5c31af7Sopenharmony_ci 68e5c31af7Sopenharmony_ci CustomInstance (const CustomInstance& other) = delete; 69e5c31af7Sopenharmony_ci CustomInstance& operator= (const CustomInstance& other) = delete; 70e5c31af7Sopenharmony_ciprivate: 71e5c31af7Sopenharmony_ci Context* m_context; 72e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 73e5c31af7Sopenharmony_ci std::unique_ptr<vk::DebugReportRecorder> m_recorder; 74e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 75e5c31af7Sopenharmony_ci vk::Move<vk::VkInstance> m_instance; 76e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 77e5c31af7Sopenharmony_ci std::unique_ptr<vk::InstanceDriver> m_driver; 78e5c31af7Sopenharmony_ci vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 79e5c31af7Sopenharmony_ci#else 80e5c31af7Sopenharmony_ci std::unique_ptr<vk::InstanceDriverSC> m_driver; 81e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 82e5c31af7Sopenharmony_ci}; 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ciclass UncheckedInstance 85e5c31af7Sopenharmony_ci{ 86e5c31af7Sopenharmony_cipublic: 87e5c31af7Sopenharmony_ci UncheckedInstance (); 88e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 89e5c31af7Sopenharmony_ci UncheckedInstance (Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator, std::unique_ptr<vk::DebugReportRecorder>& recorder); 90e5c31af7Sopenharmony_ci#else 91e5c31af7Sopenharmony_ci UncheckedInstance (Context& context, vk::VkInstance instance, const vk::VkAllocationCallbacks* pAllocator); 92e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 93e5c31af7Sopenharmony_ci UncheckedInstance (UncheckedInstance&& other); 94e5c31af7Sopenharmony_ci ~UncheckedInstance (); 95e5c31af7Sopenharmony_ci UncheckedInstance& operator= (UncheckedInstance&& other); 96e5c31af7Sopenharmony_ci operator vk::VkInstance () const; 97e5c31af7Sopenharmony_ci operator bool () const; 98e5c31af7Sopenharmony_ci void swap (UncheckedInstance& other); 99e5c31af7Sopenharmony_ci 100e5c31af7Sopenharmony_ci UncheckedInstance (const UncheckedInstance& other) = delete; 101e5c31af7Sopenharmony_ci UncheckedInstance& operator= (const UncheckedInstance& other) = delete; 102e5c31af7Sopenharmony_ciprivate: 103e5c31af7Sopenharmony_ci Context* m_context; 104e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 105e5c31af7Sopenharmony_ci std::unique_ptr<vk::DebugReportRecorder> m_recorder; 106e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 107e5c31af7Sopenharmony_ci const vk::VkAllocationCallbacks* m_allocator; 108e5c31af7Sopenharmony_ci vk::VkInstance m_instance; 109e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 110e5c31af7Sopenharmony_ci std::unique_ptr<vk::InstanceDriver> m_driver; 111e5c31af7Sopenharmony_ci vk::Move<vk::VkDebugReportCallbackEXT> m_callback; 112e5c31af7Sopenharmony_ci#else 113e5c31af7Sopenharmony_ci std::unique_ptr<vk::InstanceDriverSC> m_driver; 114e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 115e5c31af7Sopenharmony_ci}; 116e5c31af7Sopenharmony_ci 117e5c31af7Sopenharmony_ci// Custom instances. 118e5c31af7Sopenharmony_ci 119e5c31af7Sopenharmony_ciCustomInstance createCustomInstanceWithExtensions (Context& context, const std::vector<std::string>& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 120e5c31af7Sopenharmony_ci 121e5c31af7Sopenharmony_ciCustomInstance createCustomInstanceWithExtension (Context& context, const std::string& extension, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 122e5c31af7Sopenharmony_ci 123e5c31af7Sopenharmony_ciCustomInstance createCustomInstanceFromContext (Context& context, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 124e5c31af7Sopenharmony_ci 125e5c31af7Sopenharmony_ciCustomInstance createCustomInstanceFromInfo (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator = DE_NULL, bool allowLayers = true); 126e5c31af7Sopenharmony_ci 127e5c31af7Sopenharmony_ci// Unchecked instance: creation allowed to fail. 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_civk::VkResult createUncheckedInstance (Context& context, const vk::VkInstanceCreateInfo* instanceCreateInfo, const vk::VkAllocationCallbacks* pAllocator, UncheckedInstance* instance, bool allowLayers = true); 130e5c31af7Sopenharmony_ci 131e5c31af7Sopenharmony_ci// Custom devices. 132e5c31af7Sopenharmony_ci 133e5c31af7Sopenharmony_civk::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); 134e5c31af7Sopenharmony_ci 135e5c31af7Sopenharmony_ci// Unchecked device: creation allowed to fail. 136e5c31af7Sopenharmony_ci 137e5c31af7Sopenharmony_civk::VkResult createUncheckedDevice (bool validationEnabled, const vk::InstanceInterface& vki, vk::VkPhysicalDevice physicalDevice, const vk::VkDeviceCreateInfo* pCreateInfo, const vk::VkAllocationCallbacks* pAllocator, vk::VkDevice* pDevice); 138e5c31af7Sopenharmony_ci 139e5c31af7Sopenharmony_ciclass CustomInstanceWrapper 140e5c31af7Sopenharmony_ci{ 141e5c31af7Sopenharmony_cipublic: 142e5c31af7Sopenharmony_ci CustomInstanceWrapper(Context& context); 143e5c31af7Sopenharmony_ci CustomInstanceWrapper(Context& context, const std::vector<std::string> extensions); 144e5c31af7Sopenharmony_ci vkt::CustomInstance instance; 145e5c31af7Sopenharmony_ci}; 146e5c31af7Sopenharmony_ci 147e5c31af7Sopenharmony_ciclass VideoDevice 148e5c31af7Sopenharmony_ci{ 149e5c31af7Sopenharmony_cipublic: 150e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 151e5c31af7Sopenharmony_ci typedef vk::VkVideoCodecOperationFlagsKHR VideoCodecOperationFlags; 152e5c31af7Sopenharmony_ci#else 153e5c31af7Sopenharmony_ci typedef uint32_t VideoCodecOperationFlags; 154e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 155e5c31af7Sopenharmony_ci 156e5c31af7Sopenharmony_ci enum VideoDeviceFlagBits 157e5c31af7Sopenharmony_ci { 158e5c31af7Sopenharmony_ci VIDEO_DEVICE_FLAG_NONE = 0, 159e5c31af7Sopenharmony_ci VIDEO_DEVICE_FLAG_QUERY_WITH_STATUS_FOR_DECODE_SUPPORT = 0x00000001, 160e5c31af7Sopenharmony_ci VIDEO_DEVICE_FLAG_REQUIRE_YCBCR_OR_NOT_SUPPORTED = 0x00000002, 161e5c31af7Sopenharmony_ci VIDEO_DEVICE_FLAG_REQUIRE_SYNC2_OR_NOT_SUPPORTED = 0x00000004 162e5c31af7Sopenharmony_ci }; 163e5c31af7Sopenharmony_ci typedef uint32_t VideoDeviceFlags; 164e5c31af7Sopenharmony_ci 165e5c31af7Sopenharmony_ci static void checkSupport (Context& context, 166e5c31af7Sopenharmony_ci const VideoCodecOperationFlags videoCodecOperation); 167e5c31af7Sopenharmony_ci static vk::VkQueueFlags getQueueFlags (const VideoCodecOperationFlags videoCodecOperationFlags); 168e5c31af7Sopenharmony_ci 169e5c31af7Sopenharmony_ci static void addVideoDeviceExtensions (std::vector<const char*>& deviceExtensions, 170e5c31af7Sopenharmony_ci const uint32_t apiVersion, 171e5c31af7Sopenharmony_ci const vk::VkQueueFlags queueFlagsRequired, 172e5c31af7Sopenharmony_ci const VideoCodecOperationFlags videoCodecOperationFlags); 173e5c31af7Sopenharmony_ci static bool isVideoEncodeOperation (const VideoCodecOperationFlags videoCodecOperationFlags); 174e5c31af7Sopenharmony_ci static bool isVideoDecodeOperation (const VideoCodecOperationFlags videoCodecOperationFlags); 175e5c31af7Sopenharmony_ci static bool isVideoOperation (const VideoCodecOperationFlags videoCodecOperationFlags); 176e5c31af7Sopenharmony_ci 177e5c31af7Sopenharmony_ci VideoDevice (Context& context); 178e5c31af7Sopenharmony_ci VideoDevice (Context& context, 179e5c31af7Sopenharmony_ci const VideoCodecOperationFlags videoCodecOperation, 180e5c31af7Sopenharmony_ci const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 181e5c31af7Sopenharmony_ci virtual ~VideoDevice (void); 182e5c31af7Sopenharmony_ci 183e5c31af7Sopenharmony_ci vk::VkDevice getDeviceSupportingQueue (const vk::VkQueueFlags queueFlagsRequired = 0, 184e5c31af7Sopenharmony_ci const VideoCodecOperationFlags videoCodecOperationFlags = 0, 185e5c31af7Sopenharmony_ci const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 186e5c31af7Sopenharmony_ci bool createDeviceSupportingQueue (const vk::VkQueueFlags queueFlagsRequired, 187e5c31af7Sopenharmony_ci const VideoCodecOperationFlags videoCodecOperationFlags, 188e5c31af7Sopenharmony_ci const VideoDeviceFlags videoDeviceFlags = VIDEO_DEVICE_FLAG_NONE); 189e5c31af7Sopenharmony_ci const vk::DeviceDriver& getDeviceDriver (void); 190e5c31af7Sopenharmony_ci const deUint32& getQueueFamilyIndexTransfer (void); 191e5c31af7Sopenharmony_ci const deUint32& getQueueFamilyIndexDecode (void); 192e5c31af7Sopenharmony_ci const deUint32& getQueueFamilyIndexEncode (void); 193e5c31af7Sopenharmony_ci const deUint32& getQueueFamilyVideo (void); 194e5c31af7Sopenharmony_ci vk::Allocator& getAllocator (void); 195e5c31af7Sopenharmony_ci 196e5c31af7Sopenharmony_ciprotected: 197e5c31af7Sopenharmony_ci Context& m_context; 198e5c31af7Sopenharmony_ci 199e5c31af7Sopenharmony_ci vk::Move<vk::VkDevice> m_logicalDevice; 200e5c31af7Sopenharmony_ci de::MovePtr<vk::DeviceDriver> m_deviceDriver; 201e5c31af7Sopenharmony_ci de::MovePtr<vk::Allocator> m_allocator; 202e5c31af7Sopenharmony_ci deUint32 m_queueFamilyTransfer; 203e5c31af7Sopenharmony_ci deUint32 m_queueFamilyDecode; 204e5c31af7Sopenharmony_ci deUint32 m_queueFamilyEncode; 205e5c31af7Sopenharmony_ci VideoCodecOperationFlags m_videoCodecOperation; 206e5c31af7Sopenharmony_ci}; 207e5c31af7Sopenharmony_ci 208e5c31af7Sopenharmony_ci} 209e5c31af7Sopenharmony_ci 210e5c31af7Sopenharmony_ci#endif // _VKTCUSTOMINSTANCESDEVICES_HPP 211