1 #ifndef _VKTVIDEOTESTUTILS_HPP 2 #define _VKTVIDEOTESTUTILS_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2021 The Khronos Group Inc. 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Video Encoding and Decoding Utility Functions 24 *//*--------------------------------------------------------------------*/ 25 26 #include "vktVideoTestUtils.hpp" 27 28 #include "vkDefs.hpp" 29 #include "vkRefUtil.hpp" 30 #include "vkMemUtil.hpp" 31 #include "vkPlatform.hpp" 32 #include "vktTestCase.hpp" 33 #include "vktCustomInstancesDevices.hpp" 34 35 namespace vkt 36 { 37 namespace video 38 { 39 40 using namespace vk; 41 using namespace std; 42 43 typedef de::MovePtr<Allocation> AllocationPtr; 44 45 VkVideoDecodeH264ProfileInfoKHR getProfileOperationH264D (StdVideoH264ProfileIdc stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_MAIN, 46 VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout = VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_INTERLACED_INTERLEAVED_LINES_BIT_KHR); 47 VkVideoEncodeH264ProfileInfoEXT getProfileOperationH264E (StdVideoH264ProfileIdc stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_MAIN); 48 VkVideoDecodeH265ProfileInfoKHR getProfileOperationH265D (StdVideoH265ProfileIdc stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN); 49 VkVideoEncodeH265ProfileInfoEXT getProfileOperationH265E (StdVideoH265ProfileIdc stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN); 50 51 de::MovePtr<VkVideoDecodeCapabilitiesKHR> getVideoDecodeCapabilities (void* pNext); 52 53 de::MovePtr<VkVideoDecodeH264CapabilitiesKHR> getVideoCapabilitiesExtensionH264D (void); 54 de::MovePtr<VkVideoEncodeH264CapabilitiesEXT> getVideoCapabilitiesExtensionH264E (void); 55 de::MovePtr<VkVideoDecodeH265CapabilitiesKHR> getVideoCapabilitiesExtensionH265D (void); 56 de::MovePtr<VkVideoEncodeH265CapabilitiesEXT> getVideoCapabilitiesExtensionH265E (void); 57 de::MovePtr<VkVideoCapabilitiesKHR> getVideoCapabilities (const InstanceInterface& vk, 58 VkPhysicalDevice physicalDevice, 59 const VkVideoProfileInfoKHR* videoProfile, 60 void* pNext); 61 62 de::MovePtr<VkVideoDecodeH264ProfileInfoKHR> getVideoProfileExtensionH264D (StdVideoH264ProfileIdc stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_MAIN, 63 VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout = VK_VIDEO_DECODE_H264_PICTURE_LAYOUT_INTERLACED_INTERLEAVED_LINES_BIT_KHR); 64 de::MovePtr<VkVideoEncodeH264ProfileInfoEXT> getVideoProfileExtensionH264E (StdVideoH264ProfileIdc stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_MAIN); 65 de::MovePtr<VkVideoDecodeH265ProfileInfoKHR> getVideoProfileExtensionH265D (StdVideoH265ProfileIdc stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN); 66 de::MovePtr<VkVideoEncodeH265ProfileInfoEXT> getVideoProfileExtensionH265E (StdVideoH265ProfileIdc stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN); 67 de::MovePtr<VkVideoProfileInfoKHR> getVideoProfile (VkVideoCodecOperationFlagBitsKHR videoCodecOperation, 68 void* pNext, 69 VkVideoChromaSubsamplingFlagsKHR chromaSubsampling = VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR, 70 VkVideoComponentBitDepthFlagsKHR lumaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR, 71 VkVideoComponentBitDepthFlagsKHR chromaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR); 72 de::MovePtr<VkVideoProfileListInfoKHR> getVideoProfileList (const VkVideoProfileInfoKHR* videoProfile); 73 74 const VkExtensionProperties* getVideoExtensionProperties (const VkVideoCodecOperationFlagBitsKHR codecOperation); 75 de::MovePtr<VkVideoSessionCreateInfoKHR> getVideoSessionCreateInfo (deUint32 queueFamilyIndex, 76 const VkVideoProfileInfoKHR* videoProfile, 77 const VkExtent2D& codedExtent = { 1920, 1080 }, 78 VkFormat pictureFormat = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, 79 VkFormat referencePicturesFormat = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, 80 deUint32 maxReferencePicturesSlotsCount = 2u, 81 deUint32 maxReferencePicturesActiveCount = 2u); 82 83 vector<AllocationPtr> getAndBindVideoSessionMemory (const DeviceInterface& vkd, 84 const VkDevice device, 85 VkVideoSessionKHR videoSession, 86 Allocator& allocator); 87 88 de::MovePtr<vector<VkFormat>> getSupportedFormats (const InstanceInterface& vk, 89 const VkPhysicalDevice physicalDevice, 90 const VkImageUsageFlags imageUsageFlags, 91 const VkVideoProfileListInfoKHR* videoProfileList); 92 93 VkVideoFormatPropertiesKHR getSupportedFormatProperties (const InstanceInterface& vk, 94 const VkPhysicalDevice physicalDevice, 95 const VkImageUsageFlags imageUsageFlags, 96 const VkVideoProfileListInfoKHR* videoProfileList, 97 const VkFormat format); 98 bool validateVideoExtent (const VkExtent2D& codedExtent, 99 const VkVideoCapabilitiesKHR& videoCapabilities); 100 bool validateFormatSupport (const InstanceInterface& vk, 101 VkPhysicalDevice physicalDevice, 102 const VkImageUsageFlags imageUsageFlags, 103 const VkVideoProfileListInfoKHR* videoProfileList, 104 const VkFormat format, 105 const bool throwException = true); 106 107 bool validateVideoProfileList (const InstanceInterface& vk, 108 VkPhysicalDevice physicalDevice, 109 const VkVideoProfileListInfoKHR* videoProfileList, 110 const VkFormat format, 111 const VkImageUsageFlags usage); 112 113 VkImageCreateInfo makeImageCreateInfo (VkFormat format, 114 const VkExtent2D& extent, 115 const deUint32* queueFamilyIndex, 116 const VkImageUsageFlags usage, 117 void* pNext, 118 const deUint32 arrayLayers = 1); 119 120 de::MovePtr<StdVideoH264SequenceParameterSet> getStdVideoH264SequenceParameterSet (uint32_t width, 121 uint32_t height, 122 StdVideoH264SequenceParameterSetVui* stdVideoH264SequenceParameterSetVui); 123 de::MovePtr<StdVideoH264PictureParameterSet> getStdVideoH264PictureParameterSet (void); 124 125 void cmdPipelineImageMemoryBarrier2 (const DeviceInterface& vk, 126 const VkCommandBuffer commandBuffer, 127 const VkImageMemoryBarrier2KHR* pImageMemoryBarriers, 128 const size_t imageMemoryBarrierCount = 1u, 129 const VkDependencyFlags dependencyFlags = 0); 130 131 class VideoBaseTestInstance : public TestInstance 132 { 133 public: 134 VideoBaseTestInstance (Context& context); 135 virtual ~VideoBaseTestInstance (void); 136 137 VkDevice getDeviceSupportingQueue (const VkQueueFlags queueFlagsRequired = 0, 138 const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags = 0, 139 const VideoDevice::VideoDeviceFlags videoDeviceFlags = VideoDevice::VIDEO_DEVICE_FLAG_NONE); 140 bool createDeviceSupportingQueue (const VkQueueFlags queueFlagsRequired, 141 const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags, 142 const VideoDevice::VideoDeviceFlags videoDeviceFlags = VideoDevice::VIDEO_DEVICE_FLAG_NONE); 143 const DeviceDriver& getDeviceDriver (void); 144 const deUint32& getQueueFamilyIndexTransfer (void); 145 const deUint32& getQueueFamilyIndexDecode (void); 146 const deUint32& getQueueFamilyIndexEncode (void); 147 Allocator& getAllocator (void); 148 149 de::MovePtr<vector<deUint8>> loadVideoDataClipA (void); 150 de::MovePtr<vector<deUint8>> loadVideoDataClipB (void); 151 de::MovePtr<vector<deUint8>> loadVideoDataClipC (void); 152 de::MovePtr<vector<deUint8>> loadVideoDataClipD (void); 153 de::MovePtr<vector<deUint8>> loadVideoDataClipH264G13 (void); 154 de::MovePtr<vector<deUint8>> loadVideoDataClipH265G13 (void); 155 156 protected: 157 de::MovePtr<vector<deUint8>> loadVideoData (const string& filename); 158 159 VideoDevice m_videoDevice; 160 }; 161 162 } // video 163 } // vkt 164 165 #endif // _VKTVIDEOTESTUTILS_HPP 166