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
32namespace vk
33{
34
35bool						isFloatFormat				(VkFormat format);
36bool						isUnormFormat				(VkFormat format);
37bool						isSnormFormat				(VkFormat format);
38bool						isIntFormat					(VkFormat format);
39bool						isUintFormat				(VkFormat format);
40bool						isDepthStencilFormat		(VkFormat format);
41bool						isCompressedFormat			(VkFormat format);
42bool						isSrgbFormat				(VkFormat format);
43
44bool						isSupportedByFramework		(VkFormat format);
45
46tcu::TextureFormat			mapVkFormat					(VkFormat format);
47tcu::CompressedTexFormat	mapVkCompressedFormat		(VkFormat format);
48tcu::TextureFormat			getDepthCopyFormat			(VkFormat combinedFormat);
49tcu::TextureFormat			getStencilCopyFormat		(VkFormat combinedFormat);
50
51tcu::Sampler				mapVkSampler				(const VkSamplerCreateInfo& samplerCreateInfo);
52tcu::Sampler::CompareMode	mapVkSamplerCompareOp		(VkCompareOp compareOp);
53tcu::Sampler::WrapMode		mapVkSamplerAddressMode		(VkSamplerAddressMode addressMode);
54tcu::Sampler::FilterMode	mapVkMinTexFilter			(VkFilter filter, VkSamplerMipmapMode mipMode);
55tcu::Sampler::FilterMode	mapVkMagTexFilter			(VkFilter filter);
56
57VkFilter					mapFilterMode				(tcu::Sampler::FilterMode filterMode);
58VkSamplerMipmapMode			mapMipmapMode				(tcu::Sampler::FilterMode filterMode);
59VkSamplerAddressMode		mapWrapMode					(tcu::Sampler::WrapMode wrapMode);
60VkCompareOp					mapCompareMode				(tcu::Sampler::CompareMode mode);
61VkFormat					mapTextureFormat			(const tcu::TextureFormat& format);
62VkSamplerCreateInfo			mapSampler					(const tcu::Sampler& sampler, const tcu::TextureFormat& format, float minLod = 0.0f, float maxLod = 1000.0f);
63
64void						imageUtilSelfTest			(void);
65
66// \todo [2017-05-18 pyry] Consider moving this to tcu
67struct 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
104	inline bool hasChannelNdx (deUint32 ndx) const
105	{
106		DE_ASSERT(de::inBounds(ndx, 0u, 4u));
107		return (presentChannels & (1u<<ndx)) != 0;
108	}
109};
110
111bool							isYCbCrFormat					(VkFormat format);
112PlanarFormatDescription			getPlanarFormatDescription		(VkFormat format);
113const PlanarFormatDescription&	getYCbCrPlanarFormatDescription	(VkFormat format);
114int								getPlaneCount					(VkFormat format);
115VkImageAspectFlagBits			getPlaneAspect					(deUint32 planeNdx);
116deUint32						getAspectPlaneNdx				(VkImageAspectFlagBits planeAspect);
117bool							isChromaSubsampled				(VkFormat format);
118
119tcu::PixelBufferAccess			getChannelAccess				(const PlanarFormatDescription&	formatInfo,
120																 const tcu::UVec2&				size,
121																 const deUint32*				planeRowPitches,
122																 void* const*					planePtrs,
123																 deUint32						channelNdx);
124tcu::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