1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2021 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Video Encoding and Decoding Utility Functions
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktVideoTestUtils.hpp"
25
26 #include "vkDefs.hpp"
27 #include "vkMemUtil.hpp"
28 #include "vkRefUtil.hpp"
29 #include "vkTypeUtil.hpp"
30 #include "vkQueryUtil.hpp"
31 #include "vkDeviceUtil.hpp"
32 #include "tcuCommandLine.hpp"
33 #include "tcuResource.hpp"
34
35 #include "vktCustomInstancesDevices.hpp"
36 #include "vktTestCase.hpp"
37
38 #include "vktVideoDecodeTests.hpp"
39
40 using namespace vk;
41 using namespace std;
42
43 namespace vkt
44 {
45 namespace video
46 {
47
48 using namespace vk;
49 using namespace std;
50
51
52
cmdPipelineImageMemoryBarrier2(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkImageMemoryBarrier2KHR * pImageMemoryBarriers,const size_t imageMemoryBarrierCount,const VkDependencyFlags dependencyFlags)53 void cmdPipelineImageMemoryBarrier2 (const DeviceInterface& vk,
54 const VkCommandBuffer commandBuffer,
55 const VkImageMemoryBarrier2KHR* pImageMemoryBarriers,
56 const size_t imageMemoryBarrierCount,
57 const VkDependencyFlags dependencyFlags)
58 {
59 const deUint32 imageMemoryBarrierCount32 = static_cast<deUint32>(imageMemoryBarrierCount);
60 const VkDependencyInfo dependencyInfoKHR =
61 {
62 vk::VK_STRUCTURE_TYPE_DEPENDENCY_INFO, // VkStructureType sType;
63 DE_NULL, // const void* pNext;
64 dependencyFlags, // VkDependencyFlags dependencyFlags;
65 0u, // deUint32 memoryBarrierCount;
66 DE_NULL, // const VkMemoryBarrier2KHR* pMemoryBarriers;
67 0u, // deUint32 bufferMemoryBarrierCount;
68 DE_NULL, // const VkBufferMemoryBarrier2KHR* pBufferMemoryBarriers;
69 imageMemoryBarrierCount32, // deUint32 imageMemoryBarrierCount;
70 pImageMemoryBarriers, // const VkImageMemoryBarrier2KHR* pImageMemoryBarriers;
71 };
72
73 DE_ASSERT(imageMemoryBarrierCount == imageMemoryBarrierCount32);
74
75 vk.cmdPipelineBarrier2(commandBuffer, &dependencyInfoKHR);
76 }
77
makeExtensionProperties(const char * extensionName,deUint32 specVersion)78 static VkExtensionProperties makeExtensionProperties(const char* extensionName, deUint32 specVersion)
79 {
80 const deUint32 extensionNameLen = static_cast<deUint32>(deStrnlen(extensionName, VK_MAX_EXTENSION_NAME_SIZE));
81 VkExtensionProperties result;
82
83 deMemset(&result, 0, sizeof(result));
84
85 deMemcpy(&result.extensionName, extensionName, extensionNameLen);
86
87 result.specVersion = specVersion;
88
89 return result;
90 }
91
92 static const VkExtensionProperties EXTENSION_PROPERTIES_H264_DECODE = makeExtensionProperties(VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME, VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION);
93 static const VkExtensionProperties EXTENSION_PROPERTIES_H264_ENCODE = makeExtensionProperties(VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_EXTENSION_NAME, VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_SPEC_VERSION);
94 static const VkExtensionProperties EXTENSION_PROPERTIES_H265_DECODE = makeExtensionProperties(VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME, VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION);
95 static const VkExtensionProperties EXTENSION_PROPERTIES_H265_ENCODE = makeExtensionProperties(VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_EXTENSION_NAME, VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_SPEC_VERSION);
96
VideoBaseTestInstance(Context & context)97 VideoBaseTestInstance::VideoBaseTestInstance (Context& context)
98 : TestInstance (context)
99 , m_videoDevice (context)
100 {
101 }
102
~VideoBaseTestInstance(void)103 VideoBaseTestInstance::~VideoBaseTestInstance (void)
104 {
105 }
106
createDeviceSupportingQueue(const VkQueueFlags queueFlagsRequired,const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags,const VideoDevice::VideoDeviceFlags videoDeviceFlags)107 bool VideoBaseTestInstance::createDeviceSupportingQueue (const VkQueueFlags queueFlagsRequired, const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags, const VideoDevice::VideoDeviceFlags videoDeviceFlags)
108 {
109 return m_videoDevice.createDeviceSupportingQueue(queueFlagsRequired, videoCodecOperationFlags, videoDeviceFlags);
110 }
111
getDeviceSupportingQueue(const VkQueueFlags queueFlagsRequired,const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags,const VideoDevice::VideoDeviceFlags videoDeviceFlags)112 VkDevice VideoBaseTestInstance::getDeviceSupportingQueue (const VkQueueFlags queueFlagsRequired, const VkVideoCodecOperationFlagsKHR videoCodecOperationFlags, const VideoDevice::VideoDeviceFlags videoDeviceFlags)
113 {
114 return m_videoDevice.getDeviceSupportingQueue(queueFlagsRequired, videoCodecOperationFlags, videoDeviceFlags);
115 }
116
getDeviceDriver(void)117 const DeviceDriver& VideoBaseTestInstance::getDeviceDriver (void)
118 {
119 return m_videoDevice.getDeviceDriver();
120 }
121
getQueueFamilyIndexTransfer(void)122 const deUint32& VideoBaseTestInstance::getQueueFamilyIndexTransfer (void)
123 {
124 return m_videoDevice.getQueueFamilyIndexTransfer();
125 }
126
getQueueFamilyIndexDecode(void)127 const deUint32& VideoBaseTestInstance::getQueueFamilyIndexDecode (void)
128 {
129 return m_videoDevice.getQueueFamilyIndexDecode();
130 }
131
getQueueFamilyIndexEncode(void)132 const deUint32& VideoBaseTestInstance::getQueueFamilyIndexEncode (void)
133 {
134 return m_videoDevice.getQueueFamilyIndexEncode();
135 }
136
getAllocator(void)137 Allocator& VideoBaseTestInstance::getAllocator (void)
138 {
139 return m_videoDevice.getAllocator();
140 }
141
loadVideoData(const string & filename)142 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoData (const string& filename)
143 {
144 tcu::Archive& archive = m_context.getTestContext().getArchive();
145 de::UniquePtr<tcu::Resource> resource (archive.getResource(filename.c_str()));
146 const int resourceSize = resource->getSize();
147 de::MovePtr<vector<deUint8>> result (new vector<deUint8>(resourceSize));
148
149 resource->read(result->data(), resource->getSize());
150
151 return result;
152 }
153
loadVideoDataClipA(void)154 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipA (void)
155 {
156 return loadVideoData("vulkan/video/clip-a.h264");
157 }
158
loadVideoDataClipB(void)159 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipB (void)
160 {
161 return loadVideoData("vulkan/video/clip-b.h264");
162 }
163
loadVideoDataClipC(void)164 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipC (void)
165 {
166 return loadVideoData("vulkan/video/clip-c.h264");
167 }
168
loadVideoDataClipD(void)169 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipD (void)
170 {
171 return loadVideoData("vulkan/video/clip-d.h265");
172 }
173
loadVideoDataClipH264G13(void)174 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipH264G13 (void)
175 {
176 return loadVideoData("vulkan/video/jellyfish-250-mbps-4k-uhd-GOB-IPB13.h264");
177 }
178
loadVideoDataClipH265G13(void)179 de::MovePtr<vector<deUint8>> VideoBaseTestInstance::loadVideoDataClipH265G13 (void)
180 {
181 return loadVideoData("vulkan/video/jellyfish-250-mbps-4k-uhd-GOB-IPB13.h265");
182 }
183
getVideoDecodeCapabilities(void * pNext)184 de::MovePtr<VkVideoDecodeCapabilitiesKHR> getVideoDecodeCapabilities (void* pNext)
185 {
186 const VkVideoDecodeCapabilitiesKHR videoDecodeCapabilities =
187 {
188 vk::VK_STRUCTURE_TYPE_VIDEO_DECODE_CAPABILITIES_KHR, // VkStructureType sType;
189 pNext, // void* pNext;
190 0, // VkVideoDecodeCapabilityFlagsKHR Flags;
191 };
192
193 return de::MovePtr<VkVideoDecodeCapabilitiesKHR>(new VkVideoDecodeCapabilitiesKHR(videoDecodeCapabilities));
194 }
195
getVideoCapabilitiesExtensionH264D(void)196 de::MovePtr<VkVideoDecodeH264CapabilitiesKHR> getVideoCapabilitiesExtensionH264D (void)
197 {
198 const VkVideoDecodeH264CapabilitiesKHR videoCapabilitiesExtension =
199 {
200 vk::VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_CAPABILITIES_KHR, // VkStructureType sType;
201 DE_NULL, // void* pNext;
202 STD_VIDEO_H264_LEVEL_IDC_1_0, // StdVideoH264Level maxLevel;
203 {0, 0}, // VkOffset2D fieldOffsetGranularity;
204 };
205
206 return de::MovePtr<VkVideoDecodeH264CapabilitiesKHR>(new VkVideoDecodeH264CapabilitiesKHR(videoCapabilitiesExtension));
207 }
208
getVideoCapabilitiesExtensionH264E(void)209 de::MovePtr <VkVideoEncodeH264CapabilitiesEXT> getVideoCapabilitiesExtensionH264E (void)
210 {
211 const VkVideoEncodeH264CapabilitiesEXT videoCapabilitiesExtension =
212 {
213 vk::VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_CAPABILITIES_EXT, // VkStructureType sType;
214 DE_NULL, // const void* pNext;
215 0u, // VkVideoEncodeH264CapabilityFlagsEXT flags;
216 0u, // VkVideoEncodeH264InputModeFlagsEXT inputModeFlags;
217 0u, // VkVideoEncodeH264OutputModeFlagsEXT outputModeFlags;
218 0u, // uint8_t maxPPictureL0ReferenceCount;
219 0u, // uint8_t maxBPictureL0ReferenceCount;
220 0u, // uint8_t maxL1ReferenceCount;
221 DE_FALSE, // VkBool32 motionVectorsOverPicBoundariesFlag;
222 0u, // uint32_t maxBytesPerPicDenom;
223 0u, // uint32_t maxBitsPerMbDenom;
224 0u, // uint32_t log2MaxMvLengthHorizontal;
225 0u, // uint32_t log2MaxMvLengthVertical;
226 };
227
228 return de::MovePtr<VkVideoEncodeH264CapabilitiesEXT>(new VkVideoEncodeH264CapabilitiesEXT(videoCapabilitiesExtension));
229 }
230
getVideoCapabilitiesExtensionH265D(void)231 de::MovePtr<VkVideoDecodeH265CapabilitiesKHR> getVideoCapabilitiesExtensionH265D (void)
232 {
233 const VkVideoDecodeH265CapabilitiesKHR videoCapabilitiesExtension =
234 {
235 VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_CAPABILITIES_KHR, // VkStructureType sType;
236 DE_NULL, // void* pNext;
237 STD_VIDEO_H265_LEVEL_IDC_1_0, // StdVideoH265Level maxLevel;
238 };
239
240 return de::MovePtr<VkVideoDecodeH265CapabilitiesKHR>(new VkVideoDecodeH265CapabilitiesKHR(videoCapabilitiesExtension));
241 }
242
getVideoCapabilitiesExtensionH265E(void)243 de::MovePtr <VkVideoEncodeH265CapabilitiesEXT> getVideoCapabilitiesExtensionH265E (void)
244 {
245 const VkVideoEncodeH265CapabilitiesEXT videoCapabilitiesExtension =
246 {
247 VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_CAPABILITIES_EXT, // VkStructureType sType;
248 DE_NULL, // const void* pNext;
249 0u, // VkVideoEncodeH265CapabilityFlagsEXT flags;
250 0u, // VkVideoEncodeH265InputModeFlagsEXT inputModeFlags;
251 0u, // VkVideoEncodeH265OutputModeFlagsEXT outputModeFlags;
252 0u, // VkVideoEncodeH265CtbSizeFlagsEXT ctbSizes;
253 0u, // VkVideoEncodeH265TransformBlockSizeFlagsEXT transformBlockSizes;
254 0u, // uint8_t maxPPictureL0ReferenceCount;
255 0u, // uint8_t maxBPictureL0ReferenceCount;
256 0u, // uint8_t maxL1ReferenceCount;
257 0u, // uint8_t maxSubLayersCount;
258 0u, // uint8_t minLog2MinLumaCodingBlockSizeMinus3;
259 0u, // uint8_t maxLog2MinLumaCodingBlockSizeMinus3;
260 0u, // uint8_t minLog2MinLumaTransformBlockSizeMinus2;
261 0u, // uint8_t maxLog2MinLumaTransformBlockSizeMinus2;
262 0u, // uint8_t minMaxTransformHierarchyDepthInter;
263 0u, // uint8_t maxMaxTransformHierarchyDepthInter;
264 0u, // uint8_t minMaxTransformHierarchyDepthIntra;
265 0u, // uint8_t maxMaxTransformHierarchyDepthIntra;
266 0u, // uint8_t maxDiffCuQpDeltaDepth;
267 0u, // uint8_t minMaxNumMergeCand;
268 0u, // uint8_t maxMaxNumMergeCand;
269 };
270
271 return de::MovePtr<VkVideoEncodeH265CapabilitiesEXT>(new VkVideoEncodeH265CapabilitiesEXT(videoCapabilitiesExtension));
272 }
273
getVideoCapabilities(const InstanceInterface & vk,VkPhysicalDevice physicalDevice,const VkVideoProfileInfoKHR * videoProfile,void * pNext)274 de::MovePtr<VkVideoCapabilitiesKHR> getVideoCapabilities (const InstanceInterface& vk,
275 VkPhysicalDevice physicalDevice,
276 const VkVideoProfileInfoKHR* videoProfile,
277 void* pNext)
278 {
279 VkVideoCapabilitiesKHR* videoCapabilities = new VkVideoCapabilitiesKHR
280 {
281 VK_STRUCTURE_TYPE_VIDEO_CAPABILITIES_KHR, // VkStructureType sType;
282 pNext, // void* pNext;
283 0, // VkVideoCapabilityFlagsKHR capabilityFlags;
284 0, // VkDeviceSize minBitstreamBufferOffsetAlignment;
285 0, // VkDeviceSize minBitstreamBufferSizeAlignment;
286 {0, 0}, // VkExtent2D videoPictureExtentGranularity;
287 {0, 0}, // VkExtent2D minExtent;
288 {0, 0}, // VkExtent2D maxExtent;
289 0, // uint32_t maxReferencePicturesSlotsCount;
290 0, // uint32_t maxReferencePicturesActiveCount;
291 { { 0 }, 0 }, // VkExtensionProperties stdHeaderVersion;
292 };
293 de::MovePtr<VkVideoCapabilitiesKHR> result = de::MovePtr<VkVideoCapabilitiesKHR>(videoCapabilities);
294
295 VK_CHECK(vk.getPhysicalDeviceVideoCapabilitiesKHR(physicalDevice, videoProfile, videoCapabilities));
296
297 return result;
298 }
299
getVideoProfileExtensionH264D(StdVideoH264ProfileIdc stdProfileIdc,VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout)300 de::MovePtr<VkVideoDecodeH264ProfileInfoKHR> getVideoProfileExtensionH264D (StdVideoH264ProfileIdc stdProfileIdc, VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout)
301 {
302 VkVideoDecodeH264ProfileInfoKHR* videoCodecOperation = new VkVideoDecodeH264ProfileInfoKHR(getProfileOperationH264D(stdProfileIdc, pictureLayout));
303 de::MovePtr<VkVideoDecodeH264ProfileInfoKHR> result = de::MovePtr<VkVideoDecodeH264ProfileInfoKHR>(videoCodecOperation);
304
305 return result;
306 }
307
getVideoProfileExtensionH264E(StdVideoH264ProfileIdc stdProfileIdc)308 de::MovePtr<VkVideoEncodeH264ProfileInfoEXT> getVideoProfileExtensionH264E (StdVideoH264ProfileIdc stdProfileIdc)
309 {
310 VkVideoEncodeH264ProfileInfoEXT* videoCodecOperation = new VkVideoEncodeH264ProfileInfoEXT(getProfileOperationH264E(stdProfileIdc));
311 de::MovePtr<VkVideoEncodeH264ProfileInfoEXT> result = de::MovePtr<VkVideoEncodeH264ProfileInfoEXT>(videoCodecOperation);
312
313 return result;
314 }
315
getVideoProfileExtensionH265D(StdVideoH265ProfileIdc stdProfileIdc)316 de::MovePtr<VkVideoDecodeH265ProfileInfoKHR> getVideoProfileExtensionH265D (StdVideoH265ProfileIdc stdProfileIdc)
317 {
318 VkVideoDecodeH265ProfileInfoKHR* videoCodecOperation = new VkVideoDecodeH265ProfileInfoKHR(getProfileOperationH265D(stdProfileIdc));
319 de::MovePtr<VkVideoDecodeH265ProfileInfoKHR> result = de::MovePtr<VkVideoDecodeH265ProfileInfoKHR>(videoCodecOperation);
320
321 return result;
322 }
323
getVideoProfileExtensionH265E(StdVideoH265ProfileIdc stdProfileIdc)324 de::MovePtr<VkVideoEncodeH265ProfileInfoEXT> getVideoProfileExtensionH265E (StdVideoH265ProfileIdc stdProfileIdc)
325 {
326 VkVideoEncodeH265ProfileInfoEXT* videoCodecOperation = new VkVideoEncodeH265ProfileInfoEXT(getProfileOperationH265E(stdProfileIdc));
327 de::MovePtr<VkVideoEncodeH265ProfileInfoEXT> result = de::MovePtr<VkVideoEncodeH265ProfileInfoEXT>(videoCodecOperation);
328
329 return result;
330 }
331
getVideoProfile(VkVideoCodecOperationFlagBitsKHR videoCodecOperation,void * pNext,VkVideoChromaSubsamplingFlagsKHR chromaSubsampling,VkVideoComponentBitDepthFlagsKHR lumaBitDepth,VkVideoComponentBitDepthFlagsKHR chromaBitDepth)332 de::MovePtr<VkVideoProfileInfoKHR> getVideoProfile (VkVideoCodecOperationFlagBitsKHR videoCodecOperation,
333 void* pNext,
334 VkVideoChromaSubsamplingFlagsKHR chromaSubsampling,
335 VkVideoComponentBitDepthFlagsKHR lumaBitDepth,
336 VkVideoComponentBitDepthFlagsKHR chromaBitDepth)
337 {
338 VkVideoProfileInfoKHR* videoProfile = new VkVideoProfileInfoKHR
339 {
340 VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR, // VkStructureType sType;
341 pNext, // void* pNext;
342 videoCodecOperation, // VkVideoCodecOperationFlagBitsKHR videoCodecOperation;
343 chromaSubsampling, // VkVideoChromaSubsamplingFlagsKHR chromaSubsampling;
344 lumaBitDepth, // VkVideoComponentBitDepthFlagsKHR lumaBitDepth;
345 chromaBitDepth, // VkVideoComponentBitDepthFlagsKHR chromaBitDepth;
346 };
347 de::MovePtr<VkVideoProfileInfoKHR> result = de::MovePtr<VkVideoProfileInfoKHR>(videoProfile);
348
349 return result;
350 }
351
getVideoProfileList(const VkVideoProfileInfoKHR * videoProfile)352 de::MovePtr<VkVideoProfileListInfoKHR> getVideoProfileList (const VkVideoProfileInfoKHR* videoProfile)
353 {
354 VkVideoProfileListInfoKHR* videoProfileList = new VkVideoProfileListInfoKHR
355 {
356 VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR, // VkStructureType sType;
357 DE_NULL, // const void* pNext;
358 1, // uint32_t profileCount;
359 videoProfile, // const VkVideoProfileInfoKHR* pProfiles;
360 };
361
362 de::MovePtr<VkVideoProfileListInfoKHR> result = de::MovePtr<VkVideoProfileListInfoKHR>(videoProfileList);
363
364 return result;
365 }
366
367
getVideoExtensionProperties(const VkVideoCodecOperationFlagBitsKHR codecOperation)368 const VkExtensionProperties* getVideoExtensionProperties (const VkVideoCodecOperationFlagBitsKHR codecOperation)
369 {
370 switch (codecOperation)
371 {
372 case VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT: return &EXTENSION_PROPERTIES_H264_ENCODE;
373 case VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_EXT: return &EXTENSION_PROPERTIES_H265_ENCODE;
374 case VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR: return &EXTENSION_PROPERTIES_H264_DECODE;
375 case VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR: return &EXTENSION_PROPERTIES_H265_DECODE;
376 default: TCU_THROW(InternalError, "Unkown codec operation");
377 }
378 }
379
getVideoSessionCreateInfo(deUint32 queueFamilyIndex,const VkVideoProfileInfoKHR * videoProfile,const VkExtent2D & codedExtent,VkFormat pictureFormat,VkFormat referencePicturesFormat,deUint32 maxReferencePicturesSlotsCount,deUint32 maxReferencePicturesActiveCount)380 de::MovePtr<VkVideoSessionCreateInfoKHR> getVideoSessionCreateInfo (deUint32 queueFamilyIndex,
381 const VkVideoProfileInfoKHR* videoProfile,
382 const VkExtent2D& codedExtent,
383 VkFormat pictureFormat,
384 VkFormat referencePicturesFormat,
385 deUint32 maxReferencePicturesSlotsCount,
386 deUint32 maxReferencePicturesActiveCount)
387 {
388
389 //FIXME: last spec version accepted by the parser function
390 //const VkExtensionProperties* extensionProperties = getVideoExtensionProperties(videoProfile->videoCodecOperation);
391
392 static const vk::VkExtensionProperties h264StdExtensionVersion = { VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME, VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) };
393 static const vk::VkExtensionProperties h265StdExtensionVersion = { VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME, VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) };
394
395 VkVideoSessionCreateInfoKHR* videoSessionCreateInfo = new VkVideoSessionCreateInfoKHR
396 {
397 VK_STRUCTURE_TYPE_VIDEO_SESSION_CREATE_INFO_KHR, // VkStructureType sType;
398 DE_NULL, // const void* pNext;
399 queueFamilyIndex, // uint32_t queueFamilyIndex;
400 static_cast<VkVideoSessionCreateFlagsKHR>(0), // VkVideoSessionCreateFlagsKHR flags;
401 videoProfile, // const VkVideoProfileInfoKHR* pVideoProfile;
402 pictureFormat, // VkFormat pictureFormat;
403 codedExtent, // VkExtent2D maxCodedExtent;
404 referencePicturesFormat, // VkFormat referencePicturesFormat;
405 maxReferencePicturesSlotsCount, // uint32_t maxReferencePicturesSlotsCount;
406 maxReferencePicturesActiveCount, // uint32_t maxReferencePicturesActiveCount;
407 videoProfile->videoCodecOperation == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR ? &h264StdExtensionVersion : &h265StdExtensionVersion, // const VkExtensionProperties* pStdHeaderVersion;
408 };
409
410 de::MovePtr<VkVideoSessionCreateInfoKHR> result = de::MovePtr<VkVideoSessionCreateInfoKHR>(videoSessionCreateInfo);
411
412 return result;
413 }
414
getAndBindVideoSessionMemory(const DeviceInterface & vkd,const VkDevice device,VkVideoSessionKHR videoSession,Allocator & allocator)415 vector<AllocationPtr> getAndBindVideoSessionMemory (const DeviceInterface& vkd,
416 const VkDevice device,
417 VkVideoSessionKHR videoSession,
418 Allocator& allocator)
419 {
420 deUint32 videoSessionMemoryRequirementsCount = 0;
421
422 DE_ASSERT(videoSession != DE_NULL);
423
424 VK_CHECK(vkd.getVideoSessionMemoryRequirementsKHR(device, videoSession, &videoSessionMemoryRequirementsCount, DE_NULL));
425
426 const VkVideoSessionMemoryRequirementsKHR videoGetMemoryPropertiesKHR =
427 {
428 VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR, // VkStructureType sType;
429 DE_NULL, // const void* pNext;
430 0u, // deUint32 memoryBindIndex;
431 {0ull, 0ull, 0u}, // VkMemoryRequirements memoryRequirements;
432 };
433
434 vector<VkVideoSessionMemoryRequirementsKHR> videoSessionMemoryRequirements (videoSessionMemoryRequirementsCount, videoGetMemoryPropertiesKHR);
435
436 for (size_t ndx = 0; ndx < videoSessionMemoryRequirements.size(); ++ndx)
437 videoSessionMemoryRequirements[ndx].sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_MEMORY_REQUIREMENTS_KHR;
438
439 VK_CHECK(vkd.getVideoSessionMemoryRequirementsKHR(device, videoSession, &videoSessionMemoryRequirementsCount, videoSessionMemoryRequirements.data()));
440
441 vector<AllocationPtr> allocations (videoSessionMemoryRequirements.size());
442 vector<VkBindVideoSessionMemoryInfoKHR> videoBindsMemoryKHR (videoSessionMemoryRequirements.size());
443
444 for (size_t ndx = 0; ndx < allocations.size(); ++ndx)
445 {
446 const VkMemoryRequirements& requirements = videoSessionMemoryRequirements[ndx].memoryRequirements;
447 const deUint32 memoryBindIndex = videoSessionMemoryRequirements[ndx].memoryBindIndex;
448 de::MovePtr<Allocation> alloc = allocator.allocate(requirements, MemoryRequirement::Any);
449
450 const VkBindVideoSessionMemoryInfoKHR videoBindMemoryKHR =
451 {
452 VK_STRUCTURE_TYPE_BIND_VIDEO_SESSION_MEMORY_INFO_KHR, // VkStructureType sType;
453 DE_NULL, // const void* pNext;
454 memoryBindIndex, // deUint32 memoryBindIndex;
455 alloc->getMemory(), // VkDeviceMemory memory;
456 alloc->getOffset(), // VkDeviceSize memoryOffset;
457 requirements.size, // VkDeviceSize memorySize;
458 };
459
460 allocations[ndx] = alloc;
461
462 videoBindsMemoryKHR[ndx] = videoBindMemoryKHR;
463 }
464
465 VK_CHECK(vkd.bindVideoSessionMemoryKHR(device, videoSession, static_cast<deUint32>(videoBindsMemoryKHR.size()), videoBindsMemoryKHR.data()));
466
467 return allocations;
468 }
469
470
getSupportedFormats(const InstanceInterface & vk,const VkPhysicalDevice physicalDevice,const VkImageUsageFlags imageUsageFlags,const VkVideoProfileListInfoKHR * videoProfileList)471 de::MovePtr<vector<VkFormat>> getSupportedFormats (const InstanceInterface& vk,
472 const VkPhysicalDevice physicalDevice,
473 const VkImageUsageFlags imageUsageFlags,
474 const VkVideoProfileListInfoKHR* videoProfileList)
475
476 {
477 deUint32 videoFormatPropertiesCount = 0u;
478
479 const VkPhysicalDeviceVideoFormatInfoKHR videoFormatInfo =
480 {
481 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_FORMAT_INFO_KHR, // VkStructureType sType;
482 videoProfileList, // const void* pNext;
483 imageUsageFlags, // VkImageUsageFlags imageUsage;
484 };
485
486 VkVideoFormatPropertiesKHR videoFormatPropertiesKHR = {};
487 videoFormatPropertiesKHR.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_PROPERTIES_KHR;
488 videoFormatPropertiesKHR.pNext = DE_NULL;
489
490
491 vector<VkVideoFormatPropertiesKHR> videoFormatProperties;
492 de::MovePtr<vector<VkFormat>> result;
493
494 const VkResult res = vk.getPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &videoFormatInfo, &videoFormatPropertiesCount, DE_NULL);
495
496 if (res == VK_ERROR_FORMAT_NOT_SUPPORTED)
497 return de::MovePtr<vector<VkFormat>>(DE_NULL);
498 else
499 VK_CHECK(res);
500
501 videoFormatProperties.resize(videoFormatPropertiesCount, videoFormatPropertiesKHR);
502
503 VK_CHECK(vk.getPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &videoFormatInfo, &videoFormatPropertiesCount, videoFormatProperties.data()));
504
505 DE_ASSERT(videoFormatPropertiesCount == videoFormatProperties.size());
506
507 result = de::MovePtr<vector<VkFormat>>(new vector<VkFormat>);
508
509 result->reserve(videoFormatProperties.size());
510
511 for (const auto& videoFormatProperty : videoFormatProperties)
512 result->push_back(videoFormatProperty.format);
513
514 return result;
515 }
516
getSupportedFormatProperties(const InstanceInterface & vk,const VkPhysicalDevice physicalDevice,const VkImageUsageFlags imageUsageFlags,void * pNext,const VkFormat format)517 VkVideoFormatPropertiesKHR getSupportedFormatProperties (const InstanceInterface& vk,
518 const VkPhysicalDevice physicalDevice,
519 const VkImageUsageFlags imageUsageFlags,
520 void* pNext,
521 const VkFormat format)
522
523 {
524 if (format == VK_FORMAT_UNDEFINED)
525 return VkVideoFormatPropertiesKHR();
526
527 deUint32 videoFormatPropertiesCount = 0u;
528
529 const VkPhysicalDeviceVideoFormatInfoKHR videoFormatInfo =
530 {
531 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_FORMAT_INFO_KHR, // VkStructureType sType;
532 pNext, // const void* pNext;
533 imageUsageFlags, // VkImageUsageFlags imageUsage;
534 };
535
536 VkVideoFormatPropertiesKHR videoFormatPropertiesKHR = {};
537 videoFormatPropertiesKHR.sType = VK_STRUCTURE_TYPE_VIDEO_FORMAT_PROPERTIES_KHR;
538 videoFormatPropertiesKHR.pNext = DE_NULL;
539
540 vector<VkVideoFormatPropertiesKHR> videoFormatProperties;
541
542 const VkResult res = vk.getPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &videoFormatInfo, &videoFormatPropertiesCount, DE_NULL);
543
544 if (res == VK_ERROR_FORMAT_NOT_SUPPORTED)
545 return VkVideoFormatPropertiesKHR();
546 else
547 VK_CHECK(res);
548
549 videoFormatProperties.resize(videoFormatPropertiesCount, videoFormatPropertiesKHR);
550
551 VK_CHECK(vk.getPhysicalDeviceVideoFormatPropertiesKHR(physicalDevice, &videoFormatInfo, &videoFormatPropertiesCount, videoFormatProperties.data()));
552
553 DE_ASSERT(videoFormatPropertiesCount == videoFormatProperties.size());
554
555 for (const auto& videoFormatProperty : videoFormatProperties)
556 {
557 if (videoFormatProperty.format == format)
558 return videoFormatProperty;
559 };
560
561 TCU_THROW(NotSupportedError, "Video format not found in properties list");
562 }
563
564
validateVideoExtent(const VkExtent2D & codedExtent,const VkVideoCapabilitiesKHR & videoCapabilities)565 bool validateVideoExtent (const VkExtent2D& codedExtent, const VkVideoCapabilitiesKHR& videoCapabilities)
566 {
567 if (!de::inRange(codedExtent.width, videoCapabilities.minCodedExtent.width, videoCapabilities.maxCodedExtent.width))
568 TCU_THROW(NotSupportedError, "Video width does not fit capabilities");
569
570 if (!de::inRange(codedExtent.height, videoCapabilities.minCodedExtent.height, videoCapabilities.maxCodedExtent.height))
571 TCU_THROW(NotSupportedError, "Video height does not fit capabilities");
572
573 return true;
574 }
575
validateFormatSupport(const InstanceInterface & vk,VkPhysicalDevice physicalDevice,const VkImageUsageFlags imageUsageFlags,const VkVideoProfileListInfoKHR * videoProfileList,const VkFormat format,bool throwException)576 bool validateFormatSupport (const InstanceInterface& vk,
577 VkPhysicalDevice physicalDevice,
578 const VkImageUsageFlags imageUsageFlags,
579 const VkVideoProfileListInfoKHR* videoProfileList,
580 const VkFormat format,
581 bool throwException)
582 {
583 de::MovePtr<vector<VkFormat>> supportedVideoFormats = getSupportedFormats(vk, physicalDevice, imageUsageFlags, videoProfileList);
584
585 if (supportedVideoFormats != DE_NULL)
586 {
587 if (supportedVideoFormats->size() == 0)
588 if (throwException)
589 TCU_THROW(NotSupportedError, "Supported video formats count is 0");
590
591 for (const auto& supportedVideoFormat : *supportedVideoFormats)
592 {
593 if (supportedVideoFormat == format)
594 return true;
595 }
596
597 if (throwException)
598 TCU_THROW(NotSupportedError, "Required format is not supported for video");
599 }
600 else
601 {
602 if (throwException)
603 TCU_THROW(NotSupportedError, "Separate DPB and DST buffers expected");
604 }
605
606 return false;
607 }
608
validateVideoProfileList(const InstanceInterface & vk,VkPhysicalDevice physicalDevice,const VkVideoProfileListInfoKHR * videoProfileList,const VkFormat format,const VkImageUsageFlags usage)609 bool validateVideoProfileList (const InstanceInterface& vk,
610 VkPhysicalDevice physicalDevice,
611 const VkVideoProfileListInfoKHR* videoProfileList,
612 const VkFormat format,
613 const VkImageUsageFlags usage)
614 {
615 VkPhysicalDeviceImageFormatInfo2 imageFormatInfo = {};
616 imageFormatInfo.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2;
617 imageFormatInfo.pNext = videoProfileList;
618 imageFormatInfo.format = format;
619 imageFormatInfo.usage = usage;
620
621
622 VkImageFormatProperties2 imageFormatProperties = {};
623 imageFormatProperties.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2;
624 imageFormatProperties.pNext = DE_NULL;
625
626 const VkResult res = vk.getPhysicalDeviceImageFormatProperties2(physicalDevice, &imageFormatInfo, &imageFormatProperties);
627
628 if (res != VK_SUCCESS)
629 return false;
630 else
631 return true;
632
633 }
634
getProfileOperationH264D(StdVideoH264ProfileIdc stdProfileIdc,VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout)635 VkVideoDecodeH264ProfileInfoKHR getProfileOperationH264D (StdVideoH264ProfileIdc stdProfileIdc, VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout)
636 {
637 const VkVideoDecodeH264ProfileInfoKHR videoProfileOperation =
638 {
639 VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_PROFILE_INFO_KHR, // VkStructureType sType;
640 DE_NULL, // const void* pNext;
641 stdProfileIdc, // StdVideoH264ProfileIdc stdProfileIdc;
642 pictureLayout, // VkVideoDecodeH264PictureLayoutFlagBitsKHR pictureLayout;
643 };
644
645 return videoProfileOperation;
646 }
647
getProfileOperationH264E(StdVideoH264ProfileIdc stdProfileIdc)648 VkVideoEncodeH264ProfileInfoEXT getProfileOperationH264E (StdVideoH264ProfileIdc stdProfileIdc)
649 {
650 const VkVideoEncodeH264ProfileInfoEXT videoProfileOperation =
651 {
652 VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_PROFILE_INFO_EXT, // VkStructureType sType;
653 DE_NULL, // const void* pNext;
654 stdProfileIdc, // StdVideoH264ProfileIdc stdProfileIdc;
655 };
656
657 return videoProfileOperation;
658 }
659
getProfileOperationH265D(StdVideoH265ProfileIdc stdProfileIdc)660 VkVideoDecodeH265ProfileInfoKHR getProfileOperationH265D (StdVideoH265ProfileIdc stdProfileIdc)
661 {
662 const VkVideoDecodeH265ProfileInfoKHR videoProfileOperation =
663 {
664 VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_PROFILE_INFO_KHR, // VkStructureType sType;
665 DE_NULL, // const void* pNext;
666 stdProfileIdc, // StdVideoH265ProfileIdc stdProfileIdc;
667 };
668
669 return videoProfileOperation;
670 }
671
getProfileOperationH265E(StdVideoH265ProfileIdc stdProfileIdc)672 VkVideoEncodeH265ProfileInfoEXT getProfileOperationH265E (StdVideoH265ProfileIdc stdProfileIdc)
673 {
674 const VkVideoEncodeH265ProfileInfoEXT videoProfileOperation =
675 {
676 VK_STRUCTURE_TYPE_VIDEO_ENCODE_H265_PROFILE_INFO_EXT, // VkStructureType sType;
677 DE_NULL, // const void* pNext;
678 stdProfileIdc, // StdVideoH265ProfileIdc stdProfileIdc;
679 };
680
681 return videoProfileOperation;
682 }
683
makeImageCreateInfo(VkFormat format,const VkExtent2D & extent,const deUint32 * queueFamilyIndex,const VkImageUsageFlags usage,void * pNext,const deUint32 arrayLayers)684 VkImageCreateInfo makeImageCreateInfo (VkFormat format,
685 const VkExtent2D& extent,
686 const deUint32* queueFamilyIndex,
687 const VkImageUsageFlags usage,
688 void* pNext,
689 const deUint32 arrayLayers)
690 {
691
692
693 const VkExtent3D extent3D = makeExtent3D(extent.width, extent.height, 1u);
694
695
696 const VkImageCreateInfo imageCreateInfo =
697 {
698 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
699 pNext, // const void* pNext;
700 (VkImageCreateFlags)0u, // VkImageCreateFlags flags;
701 VK_IMAGE_TYPE_2D, // VkImageType imageType;
702 format, // VkFormat format;
703 extent3D, // VkExtent3D extent;
704 1, // deUint32 mipLevels;
705 arrayLayers, // deUint32 arrayLayers;
706 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
707 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
708 usage, // VkImageUsageFlags usage;
709 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
710 1u, // deUint32 queueFamilyIndexCount;
711 queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
712 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
713 };
714
715 return imageCreateInfo;
716 }
717
getStdVideoH264SequenceParameterSet(uint32_t width,uint32_t height,StdVideoH264SequenceParameterSetVui * stdVideoH264SequenceParameterSetVui)718 de::MovePtr<StdVideoH264SequenceParameterSet> getStdVideoH264SequenceParameterSet (uint32_t width,
719 uint32_t height,
720 StdVideoH264SequenceParameterSetVui* stdVideoH264SequenceParameterSetVui)
721 {
722 const StdVideoH264SpsFlags stdVideoH264SpsFlags =
723 {
724 0u, // uint32_t constraint_set0_flag:1;
725 0u, // uint32_t constraint_set1_flag:1;
726 0u, // uint32_t constraint_set2_flag:1;
727 0u, // uint32_t constraint_set3_flag:1;
728 0u, // uint32_t constraint_set4_flag:1;
729 0u, // uint32_t constraint_set5_flag:1;
730 1u, // uint32_t direct_8x8_inference_flag:1;
731 0u, // uint32_t mb_adaptive_frame_field_flag:1;
732 1u, // uint32_t frame_mbs_only_flag:1;
733 0u, // uint32_t delta_pic_order_always_zero_flag:1;
734 0u, // uint32_t separate_colour_plane_flag:1;
735 0u, // uint32_t gaps_in_frame_num_value_allowed_flag:1;
736 0u, // uint32_t qpprime_y_zero_transform_bypass_flag:1;
737 0u, // uint32_t frame_cropping_flag:1;
738 0u, // uint32_t seq_scaling_matrix_present_flag:1;
739 0u, // uint32_t vui_parameters_present_flag:1;
740 };
741
742 const StdVideoH264SequenceParameterSet stdVideoH264SequenceParameterSet =
743 {
744 stdVideoH264SpsFlags, // StdVideoH264SpsFlags flags;
745 STD_VIDEO_H264_PROFILE_IDC_BASELINE, // StdVideoH264ProfileIdc profile_idc;
746 STD_VIDEO_H264_LEVEL_IDC_4_1, // StdVideoH264Level level_idc;
747 STD_VIDEO_H264_CHROMA_FORMAT_IDC_420, // StdVideoH264ChromaFormatIdc chroma_format_idc;
748 0u, // uint8_t seq_parameter_set_id;
749 0u, // uint8_t bit_depth_luma_minus8;
750 0u, // uint8_t bit_depth_chroma_minus8;
751 0u, // uint8_t log2_max_frame_num_minus4;
752 STD_VIDEO_H264_POC_TYPE_2, // StdVideoH264PocType pic_order_cnt_type;
753 0, // int32_t offset_for_non_ref_pic;
754 0, // int32_t offset_for_top_to_bottom_field;
755 0u, // uint8_t log2_max_pic_order_cnt_lsb_minus4;
756 0u, // uint8_t num_ref_frames_in_pic_order_cnt_cycle;
757 3u, // uint8_t max_num_ref_frames;
758 0u, // uint8_t reserved1;
759 (width + 15) / 16 - 1, // uint32_t pic_width_in_mbs_minus1;
760 (height + 15) / 16 - 1, // uint32_t pic_height_in_map_units_minus1;
761 0u, // uint32_t frame_crop_left_offset;
762 0u, // uint32_t frame_crop_right_offset;
763 0u, // uint32_t frame_crop_top_offset;
764 0u, // uint32_t frame_crop_bottom_offset;
765 0u, // uint32_t reserved2;
766 DE_NULL, // const int32_t* pOffsetForRefFrame;
767 DE_NULL, // const StdVideoH264ScalingLists* pScalingLists;
768 stdVideoH264SequenceParameterSetVui, // const StdVideoH264SequenceParameterSetVui* pSequenceParameterSetVui;
769 };
770
771 return de::MovePtr<StdVideoH264SequenceParameterSet>(new StdVideoH264SequenceParameterSet(stdVideoH264SequenceParameterSet));
772 }
773
getStdVideoH264PictureParameterSet(void)774 de::MovePtr<StdVideoH264PictureParameterSet> getStdVideoH264PictureParameterSet (void)
775 {
776 const StdVideoH264PpsFlags stdVideoH264PpsFlags =
777 {
778 1u, // uint32_t transform_8x8_mode_flag:1;
779 0u, // uint32_t redundant_pic_cnt_present_flag:1;
780 0u, // uint32_t constrained_intra_pred_flag:1;
781 1u, // uint32_t deblocking_filter_control_present_flag:1;
782 0u, // uint32_t weighted_pred_flag:1;
783 0u, // uint32_4 bottom_field_pic_order_in_frame_present_flag:1;
784 1u, // uint32_t entropy_coding_mode_flag:1;
785 0u, // uint32_t pic_scaling_matrix_present_flag;
786 };
787
788 const StdVideoH264PictureParameterSet stdVideoH264PictureParameterSet =
789 {
790 stdVideoH264PpsFlags, // StdVideoH264PpsFlags flags;
791 0u, // uint8_t seq_parameter_set_id;
792 0u, // uint8_t pic_parameter_set_id;
793 2u, // uint8_t num_ref_idx_l0_default_active_minus1;
794 0u, // uint8_t num_ref_idx_l1_default_active_minus1;
795 STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_DEFAULT, // StdVideoH264WeightedBipredIdc weighted_bipred_idc;
796 -16, // int8_t pic_init_qp_minus26;
797 0, // int8_t pic_init_qs_minus26;
798 -2, // int8_t chroma_qp_index_offset;
799 -2, // int8_t second_chroma_qp_index_offset;
800 DE_NULL, // const StdVideoH264ScalingLists* pScalingLists;
801 };
802
803 return de::MovePtr<StdVideoH264PictureParameterSet>(new StdVideoH264PictureParameterSet(stdVideoH264PictureParameterSet));
804 }
805
806 } // video
807 } // vkt
808