1 #ifndef _VKTYCBCRUTIL_HPP 2 #define _VKTYCBCRUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2017 Google 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 YCbCr Test Utilities 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 28 #include "vktTestCase.hpp" 29 30 #include "vkImageUtil.hpp" 31 #include "vkMemUtil.hpp" 32 #include "vkRef.hpp" 33 34 #include "deSharedPtr.hpp" 35 #include "deRandom.hpp" 36 37 namespace vkt 38 { 39 namespace ycbcr 40 { 41 42 #define VK_YCBCR_FORMAT_FIRST VK_FORMAT_G8B8G8R8_422_UNORM_KHR 43 #define VK_YCBCR_FORMAT_LAST ((vk::VkFormat)(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR+1)) 44 45 class MultiPlaneImageData 46 { 47 public: 48 MultiPlaneImageData (vk::VkFormat format, const tcu::UVec2& size); 49 MultiPlaneImageData (const MultiPlaneImageData&); 50 ~MultiPlaneImageData (void); 51 getFormat(void) const52 vk::VkFormat getFormat (void) const { return m_format; } getDescription(void) const53 const vk::PlanarFormatDescription& getDescription (void) const { return m_description; } getSize(void) const54 const tcu::UVec2& getSize (void) const { return m_size; } 55 getPlaneSize(deUint32 planeNdx) const56 size_t getPlaneSize (deUint32 planeNdx) const { return m_planeData[planeNdx].size(); } getPlanePtr(deUint32 planeNdx)57 void* getPlanePtr (deUint32 planeNdx) { return &m_planeData[planeNdx][0]; } getPlanePtr(deUint32 planeNdx) const58 const void* getPlanePtr (deUint32 planeNdx) const { return &m_planeData[planeNdx][0]; } 59 60 tcu::PixelBufferAccess getChannelAccess (deUint32 channelNdx); 61 tcu::ConstPixelBufferAccess getChannelAccess (deUint32 channelNdx) const; 62 63 private: 64 MultiPlaneImageData& operator= (const MultiPlaneImageData&); 65 66 const vk::VkFormat m_format; 67 const vk::PlanarFormatDescription m_description; 68 const tcu::UVec2 m_size; 69 70 std::vector<deUint8> m_planeData[vk::PlanarFormatDescription::MAX_PLANES]; 71 }; 72 73 void checkImageSupport (Context& context, vk::VkFormat format, vk::VkImageCreateFlags createFlags, vk::VkImageTiling tiling = vk::VK_IMAGE_TILING_OPTIMAL); 74 75 void fillRandom (de::Random* randomGen, MultiPlaneImageData* imageData); 76 void fillGradient (MultiPlaneImageData* imageData, const tcu::Vec4& minVal, const tcu::Vec4& maxVal); 77 78 std::vector<de::SharedPtr<vk::Allocation> > allocateAndBindImageMemory (const vk::DeviceInterface& vkd, 79 vk::VkDevice device, 80 vk::Allocator& allocator, 81 vk::VkImage image, 82 vk::VkFormat format, 83 vk::VkImageCreateFlags createFlags, 84 vk::MemoryRequirement requirement = vk::MemoryRequirement::Any); 85 86 void uploadImage (const vk::DeviceInterface& vkd, 87 vk::VkDevice device, 88 deUint32 queueFamilyNdx, 89 vk::Allocator& allocator, 90 vk::VkImage image, 91 const MultiPlaneImageData& imageData, 92 vk::VkAccessFlags nextAccess, 93 vk::VkImageLayout finalLayout); 94 95 void fillImageMemory (const vk::DeviceInterface& vkd, 96 vk::VkDevice device, 97 deUint32 queueFamilyNdx, 98 vk::VkImage image, 99 const std::vector<de::SharedPtr<vk::Allocation> >& memory, 100 const MultiPlaneImageData& imageData, 101 vk::VkAccessFlags nextAccess, 102 vk::VkImageLayout finalLayout); 103 104 void downloadImage (const vk::DeviceInterface& vkd, 105 vk::VkDevice device, 106 deUint32 queueFamilyNdx, 107 vk::Allocator& allocator, 108 vk::VkImage image, 109 MultiPlaneImageData* imageData, 110 vk::VkAccessFlags prevAccess, 111 vk::VkImageLayout initialLayout); 112 113 void readImageMemory (const vk::DeviceInterface& vkd, 114 vk::VkDevice device, 115 deUint32 queueFamilyNdx, 116 vk::VkImage image, 117 const std::vector<de::SharedPtr<vk::Allocation> >& memory, 118 MultiPlaneImageData* imageData, 119 vk::VkAccessFlags prevAccess, 120 vk::VkImageLayout initialLayout); 121 122 } // ycbcr 123 } // vkt 124 125 #endif // _VKTYCBCRUTIL_HPP 126