1 #ifndef _VKIMAGEUTIL_HPP 2 #define _VKIMAGEUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2015 The Khronos Group Inc. 8 * Copyright (c) 2015 Imagination Technologies Ltd. 9 * Copyright (c) 2015 Google Inc. 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); 12 * you may not use this file except in compliance with the License. 13 * You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an "AS IS" BASIS, 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * 23 *//*! 24 * \file 25 * \brief Utilities for images. 26 *//*--------------------------------------------------------------------*/ 27 28 #include "vkDefs.hpp" 29 #include "tcuTexture.hpp" 30 #include "tcuCompressedTexture.hpp" 31 32 namespace vk 33 { 34 35 bool isFloatFormat (VkFormat format); 36 bool isUnormFormat (VkFormat format); 37 bool isSnormFormat (VkFormat format); 38 bool isIntFormat (VkFormat format); 39 bool isUintFormat (VkFormat format); 40 bool isDepthStencilFormat (VkFormat format); 41 bool isCompressedFormat (VkFormat format); 42 bool isSrgbFormat (VkFormat format); 43 44 bool isSupportedByFramework (VkFormat format); 45 46 tcu::TextureFormat mapVkFormat (VkFormat format); 47 tcu::CompressedTexFormat mapVkCompressedFormat (VkFormat format); 48 tcu::TextureFormat getDepthCopyFormat (VkFormat combinedFormat); 49 tcu::TextureFormat getStencilCopyFormat (VkFormat combinedFormat); 50 51 tcu::Sampler mapVkSampler (const VkSamplerCreateInfo& samplerCreateInfo); 52 tcu::Sampler::CompareMode mapVkSamplerCompareOp (VkCompareOp compareOp); 53 tcu::Sampler::WrapMode mapVkSamplerAddressMode (VkSamplerAddressMode addressMode); 54 tcu::Sampler::FilterMode mapVkMinTexFilter (VkFilter filter, VkSamplerMipmapMode mipMode); 55 tcu::Sampler::FilterMode mapVkMagTexFilter (VkFilter filter); 56 57 VkFilter mapFilterMode (tcu::Sampler::FilterMode filterMode); 58 VkSamplerMipmapMode mapMipmapMode (tcu::Sampler::FilterMode filterMode); 59 VkSamplerAddressMode mapWrapMode (tcu::Sampler::WrapMode wrapMode); 60 VkCompareOp mapCompareMode (tcu::Sampler::CompareMode mode); 61 VkFormat mapTextureFormat (const tcu::TextureFormat& format); 62 VkSamplerCreateInfo mapSampler (const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod = 0.0f, float maxLod = 1000.0f); 63 64 void imageUtilSelfTest (void); 65 66 // \todo [2017-05-18 pyry] Consider moving this to tcu 67 struct PlanarFormatDescription 68 { 69 enum 70 { 71 MAX_CHANNELS = 4, 72 MAX_PLANES = 3 73 }; 74 75 enum ChannelFlags 76 { 77 CHANNEL_R = (1u<<0), // Has "R" (0) channel 78 CHANNEL_G = (1u<<1), // Has "G" (1) channel 79 CHANNEL_B = (1u<<2), // Has "B" (2) channel 80 CHANNEL_A = (1u<<3), // Has "A" (3) channel 81 }; 82 83 struct Plane 84 { 85 deUint8 elementSizeBytes; 86 deUint8 widthDivisor; 87 deUint8 heightDivisor; 88 }; 89 90 struct Channel 91 { 92 deUint8 planeNdx; 93 deUint8 type; // tcu::TextureChannelClass value 94 deUint8 offsetBits; // Offset in element in bits 95 deUint8 sizeBits; // Value size in bits 96 deUint8 strideBytes; // Pixel stride (in bytes), usually plane elementSize 97 }; 98 99 deUint8 numPlanes; 100 deUint8 presentChannels; 101 Plane planes[MAX_PLANES]; 102 Channel channels[MAX_CHANNELS]; 103 hasChannelNdxvk::PlanarFormatDescription104 inline bool hasChannelNdx (deUint32 ndx) const 105 { 106 DE_ASSERT(de::inBounds(ndx, 0u, 4u)); 107 return (presentChannels & (1u<<ndx)) != 0; 108 } 109 }; 110 111 bool isYCbCrFormat (VkFormat format); 112 PlanarFormatDescription getPlanarFormatDescription (VkFormat format); 113 const PlanarFormatDescription& getYCbCrPlanarFormatDescription (VkFormat format); 114 int getPlaneCount (VkFormat format); 115 VkImageAspectFlagBits getPlaneAspect (deUint32 planeNdx); 116 deUint32 getAspectPlaneNdx (VkImageAspectFlagBits planeAspect); 117 bool isChromaSubsampled (VkFormat format); 118 119 tcu::PixelBufferAccess getChannelAccess (const PlanarFormatDescription& formatInfo, 120 const tcu::UVec2& size, 121 const deUint32* planeRowPitches, 122 void* const* planePtrs, 123 deUint32 channelNdx); 124 tcu::ConstPixelBufferAccess getChannelAccess (const PlanarFormatDescription& formatInfo, 125 const tcu::UVec2& size, 126 const deUint32* planeRowPitches, 127 const void* const* planePtrs, 128 deUint32 channelNdx); 129 130 } // vk 131 132 #endif // _VKIMAGEUTIL_HPP 133