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 #include "tcuTextureUtil.hpp" 38 #include "tcuFloatFormat.hpp" 39 #include "tcuFloat.hpp" 40 #include "tcuInterval.hpp" 41 #include "tcuFloatFormat.hpp" 42 #include "tcuFloat.hpp" 43 44 #include <vector> 45 46 namespace vkt 47 { 48 namespace ycbcr 49 { 50 51 #define VK_YCBCR_FORMAT_FIRST VK_FORMAT_G8B8G8R8_422_UNORM 52 #define VK_YCBCR_FORMAT_LAST ((vk::VkFormat)(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM+1)) 53 54 class MultiPlaneImageData 55 { 56 public: 57 MultiPlaneImageData (vk::VkFormat format, const tcu::UVec2& size); 58 MultiPlaneImageData (const MultiPlaneImageData&); 59 ~MultiPlaneImageData (void); 60 getFormat(void) const61 vk::VkFormat getFormat (void) const { return m_format; } getDescription(void) const62 const vk::PlanarFormatDescription& getDescription (void) const { return m_description; } getSize(void) const63 const tcu::UVec2& getSize (void) const { return m_size; } 64 getPlaneSize(deUint32 planeNdx) const65 size_t getPlaneSize (deUint32 planeNdx) const { return m_planeData[planeNdx].size(); } getPlanePtr(deUint32 planeNdx)66 void* getPlanePtr (deUint32 planeNdx) { return &m_planeData[planeNdx][0]; } getPlanePtr(deUint32 planeNdx) const67 const void* getPlanePtr (deUint32 planeNdx) const { return &m_planeData[planeNdx][0]; } 68 69 tcu::PixelBufferAccess getChannelAccess (deUint32 channelNdx); 70 tcu::ConstPixelBufferAccess getChannelAccess (deUint32 channelNdx) const; 71 72 private: 73 MultiPlaneImageData& operator= (const MultiPlaneImageData&); 74 75 const vk::VkFormat m_format; 76 const vk::PlanarFormatDescription m_description; 77 const tcu::UVec2 m_size; 78 79 std::vector<deUint8> m_planeData[vk::PlanarFormatDescription::MAX_PLANES]; 80 }; 81 82 void checkImageSupport (Context& context, vk::VkFormat format, vk::VkImageCreateFlags createFlags, vk::VkImageTiling tiling = vk::VK_IMAGE_TILING_OPTIMAL); 83 84 void fillRandom (de::Random* randomGen, MultiPlaneImageData* imageData); 85 void fillGradient (MultiPlaneImageData* imageData, const tcu::Vec4& minVal, const tcu::Vec4& maxVal); 86 87 std::vector<de::SharedPtr<vk::Allocation> > allocateAndBindImageMemory (const vk::DeviceInterface& vkd, 88 vk::VkDevice device, 89 vk::Allocator& allocator, 90 vk::VkImage image, 91 vk::VkFormat format, 92 vk::VkImageCreateFlags createFlags, 93 vk::MemoryRequirement requirement = vk::MemoryRequirement::Any); 94 95 void uploadImage (const vk::DeviceInterface& vkd, 96 vk::VkDevice device, 97 deUint32 queueFamilyNdx, 98 vk::Allocator& allocator, 99 vk::VkImage image, 100 const MultiPlaneImageData& imageData, 101 vk::VkAccessFlags nextAccess, 102 vk::VkImageLayout finalLayout); 103 104 void fillImageMemory (const vk::DeviceInterface& vkd, 105 vk::VkDevice device, 106 deUint32 queueFamilyNdx, 107 vk::VkImage image, 108 const std::vector<de::SharedPtr<vk::Allocation> >& memory, 109 const MultiPlaneImageData& imageData, 110 vk::VkAccessFlags nextAccess, 111 vk::VkImageLayout finalLayout); 112 113 void downloadImage (const vk::DeviceInterface& vkd, 114 vk::VkDevice device, 115 deUint32 queueFamilyNdx, 116 vk::Allocator& allocator, 117 vk::VkImage image, 118 MultiPlaneImageData* imageData, 119 vk::VkAccessFlags prevAccess, 120 vk::VkImageLayout initialLayout); 121 122 void readImageMemory (const vk::DeviceInterface& vkd, 123 vk::VkDevice device, 124 deUint32 queueFamilyNdx, 125 vk::VkImage image, 126 const std::vector<de::SharedPtr<vk::Allocation> >& memory, 127 MultiPlaneImageData* imageData, 128 vk::VkAccessFlags prevAccess, 129 vk::VkImageLayout initialLayout); 130 131 class ChannelAccess 132 { 133 public: 134 ChannelAccess (tcu::TextureChannelClass channelClass, 135 deUint8 channelSize, 136 const tcu::IVec3& size, 137 const tcu::IVec3& bitPitch, 138 void* data, 139 deUint32 bitOffset); 140 getSize(void) const141 const tcu::IVec3& getSize (void) const { return m_size; } getBitPitch(void) const142 const tcu::IVec3& getBitPitch (void) const { return m_bitPitch; } getDataPtr(void) const143 void* getDataPtr (void) const { return m_data; } 144 145 tcu::Interval getChannel (const tcu::FloatFormat& conversionFormat, 146 const tcu::IVec3& pos) const; 147 deUint32 getChannelUint (const tcu::IVec3& pos) const; 148 float getChannel (const tcu::IVec3& pos) const; 149 void setChannel (const tcu::IVec3& pos, 150 deUint32 x); 151 void setChannel (const tcu::IVec3& pos, 152 float x); 153 154 private: 155 const tcu::TextureChannelClass m_channelClass; 156 const deUint8 m_channelSize; 157 const tcu::IVec3 m_size; 158 const tcu::IVec3 m_bitPitch; 159 void* const m_data; 160 const deInt32 m_bitOffset; 161 }; 162 163 ChannelAccess getChannelAccess (ycbcr::MultiPlaneImageData& data, 164 const vk::PlanarFormatDescription& formatInfo, 165 const tcu::UVec2& size, 166 int channelNdx); 167 bool isYChromaSubsampled (vk::VkFormat format); 168 bool isXChromaSubsampled (vk::VkFormat format); 169 bool areLsb6BitsDontCare (vk::VkFormat srcFormat, 170 vk::VkFormat dstFormat); 171 bool areLsb4BitsDontCare (vk::VkFormat srcFormat, 172 vk::VkFormat dstFormat); 173 174 tcu::UVec4 getYCbCrBitDepth (vk::VkFormat format); 175 tcu::FloatFormat getYCbCrFilteringPrecision (vk::VkFormat format); 176 tcu::FloatFormat getYCbCrConversionPrecision (vk::VkFormat format); 177 deUint32 getYCbCrFormatChannelCount (vk::VkFormat format); 178 179 int wrap (vk::VkSamplerAddressMode addressMode, int coord, int size); 180 int divFloor (int a, int b); 181 182 void calculateBounds (const ChannelAccess& rPlane, 183 const ChannelAccess& gPlane, 184 const ChannelAccess& bPlane, 185 const ChannelAccess& aPlane, 186 const tcu::UVec4& bitDepth, 187 const std::vector<tcu::Vec2>& sts, 188 const tcu::FloatFormat& filteringFormat, 189 const tcu::FloatFormat& conversionFormat, 190 const deUint32 subTexelPrecisionBits, 191 vk::VkFilter filter, 192 vk::VkSamplerYcbcrModelConversion colorModel, 193 vk::VkSamplerYcbcrRange range, 194 vk::VkFilter chromaFilter, 195 vk::VkChromaLocation xChromaOffset, 196 vk::VkChromaLocation yChromaOffset, 197 const vk::VkComponentMapping& componentMapping, 198 bool explicitReconstruction, 199 vk::VkSamplerAddressMode addressModeU, 200 vk::VkSamplerAddressMode addressModeV, 201 std::vector<tcu::Vec4>& minBounds, 202 std::vector<tcu::Vec4>& maxBounds, 203 std::vector<tcu::Vec4>& uvBounds, 204 std::vector<tcu::IVec4>& ijBounds); 205 206 } // ycbcr 207 } // vkt 208 209 #endif // _VKTYCBCRUTIL_HPP 210