• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 typedef de::SharedPtr<vk::Allocation>				AllocationSp;
55 typedef de::SharedPtr<vk::Unique<vk::VkBuffer> >	VkBufferSp;
56 
57 class MultiPlaneImageData
58 {
59 public:
60 										MultiPlaneImageData		(vk::VkFormat format, const tcu::UVec2& size);
61 										MultiPlaneImageData		(const MultiPlaneImageData&);
62 										~MultiPlaneImageData	(void);
63 
getFormat(void) const64 	vk::VkFormat						getFormat				(void) const				{ return m_format;						}
getDescription(void) const65 	const vk::PlanarFormatDescription&	getDescription			(void) const				{ return m_description;					}
getSize(void) const66 	const tcu::UVec2&					getSize					(void) const				{ return m_size;						}
67 
getPlaneSize(deUint32 planeNdx) const68 	size_t								getPlaneSize			(deUint32 planeNdx) const	{ return m_planeData[planeNdx].size();	}
getPlanePtr(deUint32 planeNdx)69 	void*								getPlanePtr				(deUint32 planeNdx)			{ return &m_planeData[planeNdx][0];		}
getPlanePtr(deUint32 planeNdx) const70 	const void*							getPlanePtr				(deUint32 planeNdx) const	{ return &m_planeData[planeNdx][0];		}
71 
72 	tcu::PixelBufferAccess				getChannelAccess		(deUint32 channelNdx);
73 	tcu::ConstPixelBufferAccess			getChannelAccess		(deUint32 channelNdx) const;
74 
75 private:
76 	MultiPlaneImageData&				operator=				(const MultiPlaneImageData&);
77 
78 	const vk::VkFormat					m_format;
79 	const vk::PlanarFormatDescription	m_description;
80 	const tcu::UVec2					m_size;
81 
82 	std::vector<deUint8>				m_planeData[vk::PlanarFormatDescription::MAX_PLANES];
83 };
84 
85 void										checkImageSupport			(Context& context, vk::VkFormat format, vk::VkImageCreateFlags createFlags, vk::VkImageTiling tiling = vk::VK_IMAGE_TILING_OPTIMAL);
86 
87 void										fillRandom					(de::Random* randomGen, MultiPlaneImageData* imageData, const vk::VkFormat format = vk::VK_FORMAT_UNDEFINED, bool noNan = false);
88 void										fillGradient				(MultiPlaneImageData* imageData, const tcu::Vec4& minVal, const tcu::Vec4& maxVal);
89 void										fillZero					(MultiPlaneImageData* imageData);
90 
91 std::vector<de::SharedPtr<vk::Allocation> >	allocateAndBindImageMemory	(const vk::DeviceInterface&	vkd,
92 																		 vk::VkDevice				device,
93 																		 vk::Allocator&				allocator,
94 																		 vk::VkImage				image,
95 																		 vk::VkFormat				format,
96 																		 vk::VkImageCreateFlags		createFlags,
97 																		 vk::MemoryRequirement		requirement = vk::MemoryRequirement::Any);
98 
99 void										uploadImage					(const vk::DeviceInterface&	vkd,
100 																		 vk::VkDevice				device,
101 																		 deUint32					queueFamilyNdx,
102 																		 vk::Allocator&				allocator,
103 																		 vk::VkImage				image,
104 																		 const MultiPlaneImageData&	imageData,
105 																		 vk::VkAccessFlags			nextAccess,
106 																		 vk::VkImageLayout			finalLayout,
107 																		 deUint32					arrayLayer = 0u);
108 
109 void										fillImageMemory				(const vk::DeviceInterface&							vkd,
110 																		 vk::VkDevice										device,
111 																		 deUint32											queueFamilyNdx,
112 																		 vk::VkImage										image,
113 																		 const std::vector<de::SharedPtr<vk::Allocation> >&	memory,
114 																		 const MultiPlaneImageData&							imageData,
115 																		 vk::VkAccessFlags									nextAccess,
116 																		 vk::VkImageLayout									finalLayout,
117 																		 deUint32											arrayLayer = 0u);
118 
119 void										downloadImage				(const vk::DeviceInterface&	vkd,
120 																		 vk::VkDevice				device,
121 																		 deUint32					queueFamilyNdx,
122 																		 vk::Allocator&				allocator,
123 																		 vk::VkImage				image,
124 																		 MultiPlaneImageData*		imageData,
125 																		 vk::VkAccessFlags			prevAccess,
126 																		 vk::VkImageLayout			initialLayout);
127 
128 void										readImageMemory				(const vk::DeviceInterface&							vkd,
129 																		 vk::VkDevice										device,
130 																		 deUint32											queueFamilyNdx,
131 																		 vk::VkImage										image,
132 																		 const std::vector<de::SharedPtr<vk::Allocation> >&	memory,
133 																		 MultiPlaneImageData*								imageData,
134 																		 vk::VkAccessFlags									prevAccess,
135 																		 vk::VkImageLayout									initialLayout);
136 
137 class ChannelAccess
138 {
139 public:
140 						ChannelAccess	(tcu::TextureChannelClass	channelClass,
141 										 deUint8					channelSize,
142 										 const tcu::IVec3&			size,
143 										 const tcu::IVec3&			bitPitch,
144 										 void*						data,
145 										 deUint32					bitOffset);
146 
getSize(void) const147 	const tcu::IVec3&	getSize			(void) const { return m_size; }
getBitPitch(void) const148 	const tcu::IVec3&	getBitPitch		(void) const { return m_bitPitch; }
getDataPtr(void) const149 	void*				getDataPtr		(void) const { return m_data; }
150 
151 	tcu::Interval		getChannel		(const tcu::FloatFormat&	conversionFormat,
152 										 const tcu::IVec3&			pos) const;
153 	deUint32			getChannelUint	(const tcu::IVec3&			pos) const;
154 	float				getChannel		(const tcu::IVec3&			pos) const;
155 	void				setChannel		(const tcu::IVec3&			pos,
156 										 deUint32					x);
157 	void				setChannel		(const tcu::IVec3&			pos,
158 										 float						x);
159 
160 private:
161 	const tcu::TextureChannelClass	m_channelClass;
162 	const deUint8					m_channelSize;
163 	const tcu::IVec3				m_size;
164 	const tcu::IVec3				m_bitPitch;
165 	void* const						m_data;
166 	const deInt32					m_bitOffset;
167 };
168 
169 ChannelAccess					getChannelAccess			(ycbcr::MultiPlaneImageData&			data,
170 															 const vk::PlanarFormatDescription&		formatInfo,
171 															 const tcu::UVec2&						size,
172 															 int									channelNdx);
173 
174 bool							isYChromaSubsampled			(vk::VkFormat							format);
175 
176 bool							isXChromaSubsampled			(vk::VkFormat							format);
177 
178 bool							areLsb6BitsDontCare			(vk::VkFormat							srcFormat,
179 															 vk::VkFormat							dstFormat);
180 
181 bool							areLsb4BitsDontCare			(vk::VkFormat							srcFormat,
182 															 vk::VkFormat							dstFormat);
183 
184 tcu::UVec4						getYCbCrBitDepth			(vk::VkFormat							format);
185 
186 std::vector<tcu::FloatFormat>	getPrecision				(vk::VkFormat							format);
187 
188 deUint32						getYCbCrFormatChannelCount	(vk::VkFormat							format);
189 
190 int								wrap						(vk::VkSamplerAddressMode				addressMode,
191 															 int									coord,
192 															 int									size);
193 
194 int								divFloor					(int									a,
195 															 int									b);
196 
197 void							calculateBounds				(const ChannelAccess&					rPlane,
198 															 const ChannelAccess&					gPlane,
199 															 const ChannelAccess&					bPlane,
200 															 const ChannelAccess&					aPlane,
201 															 const tcu::UVec4&						bitDepth,
202 															 const std::vector<tcu::Vec2>&			sts,
203 															 const std::vector<tcu::FloatFormat>&	filteringFormat,
204 															 const std::vector<tcu::FloatFormat>&	conversionFormat,
205 															 const deUint32							subTexelPrecisionBits,
206 															 vk::VkFilter							filter,
207 															 vk::VkSamplerYcbcrModelConversion		colorModel,
208 															 vk::VkSamplerYcbcrRange				range,
209 															 vk::VkFilter							chromaFilter,
210 															 vk::VkChromaLocation					xChromaOffset,
211 															 vk::VkChromaLocation					yChromaOffset,
212 															 const vk::VkComponentMapping&			componentMapping,
213 															 bool									explicitReconstruction,
214 															 vk::VkSamplerAddressMode				addressModeU,
215 															 vk::VkSamplerAddressMode				addressModeV,
216 															 std::vector<tcu::Vec4>&				minBounds,
217 															 std::vector<tcu::Vec4>&				maxBounds,
218 															 std::vector<tcu::Vec4>&				uvBounds,
219 															 std::vector<tcu::IVec4>&				ijBounds);
220 
221 } // ycbcr
222 } // vkt
223 
224 #endif // _VKTYCBCRUTIL_HPP
225