Add tests for VK_KHR_sampler_ycbcr_conversion
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkImageUtil.hpp
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 VkFormat                                        mapCompressedTextureFormat      (const tcu::CompressedTexFormat format);
63 VkSamplerCreateInfo                     mapSampler                                      (const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod = 0.0f, float maxLod = 1000.0f);
64
65 void                                            imageUtilSelfTest                       (void);
66
67 // \todo [2017-05-18 pyry] Consider moving this to tcu
68 struct PlanarFormatDescription
69 {
70         enum
71         {
72                 MAX_CHANNELS    = 4,
73                 MAX_PLANES              = 3
74         };
75
76         enum ChannelFlags
77         {
78                 CHANNEL_R       = (1u<<0),      // Has "R" (0) channel
79                 CHANNEL_G       = (1u<<1),      // Has "G" (1) channel
80                 CHANNEL_B       = (1u<<2),      // Has "B" (2) channel
81                 CHANNEL_A       = (1u<<3),      // Has "A" (3) channel
82         };
83
84         struct Plane
85         {
86                 deUint8         elementSizeBytes;
87                 deUint8         widthDivisor;
88                 deUint8         heightDivisor;
89         };
90
91         struct Channel
92         {
93                 deUint8         planeNdx;
94                 deUint8         type;                           // tcu::TextureChannelClass value
95                 deUint8         offsetBits;                     // Offset in element in bits
96                 deUint8         sizeBits;                       // Value size in bits
97                 deUint8         strideBytes;            // Pixel stride (in bytes), usually plane elementSize
98         };
99
100         deUint8         numPlanes;
101         deUint8         presentChannels;
102         Plane           planes[MAX_PLANES];
103         Channel         channels[MAX_CHANNELS];
104
105         inline bool hasChannelNdx (deUint32 ndx) const
106         {
107                 DE_ASSERT(de::inBounds(ndx, 0u, 4u));
108                 return (presentChannels & (1u<<ndx)) != 0;
109         }
110 };
111
112 bool                                                    isYCbCrFormat                                   (VkFormat format);
113 PlanarFormatDescription                 getPlanarFormatDescription              (VkFormat format);
114 const PlanarFormatDescription&  getYCbCrPlanarFormatDescription (VkFormat format);
115 int                                                             getPlaneCount                                   (VkFormat format);
116 VkImageAspectFlagBits                   getPlaneAspect                                  (deUint32 planeNdx);
117 deUint32                                                getAspectPlaneNdx                               (VkImageAspectFlagBits planeAspect);
118 bool                                                    isChromaSubsampled                              (VkFormat format);
119
120 tcu::PixelBufferAccess                  getChannelAccess                                (const PlanarFormatDescription& formatInfo,
121                                                                                                                                  const tcu::UVec2&                              size,
122                                                                                                                                  const deUint32*                                planeRowPitches,
123                                                                                                                                  void* const*                                   planePtrs,
124                                                                                                                                  deUint32                                               channelNdx);
125 tcu::ConstPixelBufferAccess             getChannelAccess                                (const PlanarFormatDescription& formatInfo,
126                                                                                                                                  const tcu::UVec2&                              size,
127                                                                                                                                  const deUint32*                                planeRowPitches,
128                                                                                                                                  const void* const*                             planePtrs,
129                                                                                                                                  deUint32                                               channelNdx);
130
131 } // vk
132
133 #endif // _VKIMAGEUTIL_HPP